Skip to content

Commit fb8e61b

Browse files
DoumanAshardera
andauthored
Add gstreamer based audioplayers plugin (#277)
Co-authored-by: Hannes Winkler <[email protected]>
1 parent cf57b52 commit fb8e61b

File tree

5 files changed

+746
-9
lines changed

5 files changed

+746
-9
lines changed

.github/workflows/cmake.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ jobs:
2121

2222
steps:
2323
- uses: actions/checkout@v2
24-
24+
2525
- name: Install dependencies
26-
run: sudo apt-get install -y cmake libgl1-mesa-dev libgles2-mesa-dev libegl1-mesa-dev libdrm-dev libgbm-dev ttf-mscorefonts-installer fontconfig libsystemd-dev libinput-dev libudev-dev libxkbcommon-dev ninja-build
26+
run: sudo apt-get install -y cmake libgl1-mesa-dev libgles2-mesa-dev libegl1-mesa-dev libdrm-dev libgbm-dev ttf-mscorefonts-installer fontconfig libsystemd-dev libinput-dev libudev-dev libxkbcommon-dev ninja-build libgstreamer-plugins-base1.0-dev
2727

2828
- name: Configure CMake
2929
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
3030
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
31-
run: cmake -B ${{github.workspace}}/build -DBUILD_OMXPLAYER_VIDEO_PLAYER_PLUGIN=On -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -GNinja
31+
run: cmake -B ${{github.workspace}}/build -DBUILD_OMXPLAYER_VIDEO_PLAYER_PLUGIN=On -DBUILD_GSTREAMER_AUDIO_PLAYER_PLUGIN=On -DBUILD_GSTREAMER_VIDEO_PLAYER_PLUGIN=On -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -GNinja
3232

3333
- name: Build
3434
# Build your program with the given configuration
@@ -37,7 +37,7 @@ jobs:
3737
- name: Test
3838
if: false
3939
working-directory: ${{github.workspace}}/build
40-
# Execute tests defined by the CMake configuration.
40+
# Execute tests defined by the CMake configuration.
4141
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
4242
run: ctest -C ${{env.BUILD_TYPE}}
43-
43+

CMakeLists.txt

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ option(BUILD_TEXT_INPUT_PLUGIN "Include the text input plugin in the finished bi
4040
option(BUILD_RAW_KEYBOARD_PLUGIN "Include the raw keyboard plugin in the finished binary. Enables raw keycode listening in flutter via the flutter RawKeyboard interface." ON)
4141
option(BUILD_TEST_PLUGIN "Include the test plugin in the finished binary. Allows testing platform channel communication." OFF)
4242
option(BUILD_OMXPLAYER_VIDEO_PLAYER_PLUGIN "Include the omxplayer_video_player plugin in the finished binary. Allows for hardware accelerated video playback in flutter using omxplayer." ON)
43-
option(BUILD_GSTREAMER_VIDEO_PLAYER_PLUGIN "Include the gstreamer_video_player plugin in the finished binary. Allows for more stable, hardware accelerated video playback in flutter using gstreamer." ON)
43+
option(BUILD_GSTREAMER_VIDEO_PLAYER_PLUGIN "Include the gstreamer based video plugins in the finished binary. Allows for more stable, hardware accelerated video playback in flutter using gstreamer." ON)
44+
option(BUILD_GSTREAMER_AUDIO_PLAYER_PLUGIN "Include the gstreamer based audio plugins in the finished binary." ON)
4445
option(TRY_BUILD_GSTREAMER_VIDEO_PLAYER_PLUGIN "Don't throw an error if the gstreamer libs aren't found, instead just don't build the gstreamer video player plugin in that case." ON)
46+
option(TRY_BUILD_GSTREAMER_AUDIO_PLAYER_PLUGIN "Don't throw an error if the gstreamer libs aren't found, instead just don't build gstreamer audio plugin." ON)
4547
option(DUMP_ENGINE_LAYERS "True if flutter-pi should dump the list of rendering layers that the flutter engine sends to flutter-pi on each draw." OFF)
4648
option(ENABLE_TSAN "True to build & link with -fsanitize=thread" OFF)
4749
option(ENABLE_ASAN "True to build & link with -fsanitize=address" OFF)
@@ -130,7 +132,7 @@ target_link_libraries(flutter-pi
130132
${GBM_LDFLAGS}
131133
${EGL_LDFLAGS}
132134
${GLESV2_LDFLAGS}
133-
EGL
135+
EGL
134136
systemd #${LIBSYSTEMD_LDFLAGS}
135137
input #${LIBINPUT_LDFLAGS}
136138
xkbcommon #${LIBUDEV_LDFLAGS}
@@ -153,7 +155,7 @@ target_include_directories(flutter-pi PRIVATE
153155
)
154156

155157
target_compile_options(flutter-pi PRIVATE
156-
${DRM_CFLAGS}
158+
${DRM_CFLAGS}
157159
${GBM_CFLAGS}
158160
${EGL_CFLAGS}
159161
${GLESV2_CFLAGS}
@@ -166,7 +168,7 @@ target_compile_options(flutter-pi PRIVATE
166168
$<$<CONFIG:Release>:-O2 -Wall -Wextra -Wno-unused-function -Wno-sign-compare -Wno-missing-field-initializers -ggdb>
167169
)
168170

169-
# TODO: Just unconditionally define those, make them optional later
171+
# TODO: Just unconditionally define those, make them optional later
170172
target_compile_definitions(flutter-pi PRIVATE HAS_KMS HAS_EGL HAS_GBM HAS_FBDEV)
171173

172174
# TODO: We actually don't need the compile definitions anymore, except for
@@ -219,26 +221,66 @@ if (BUILD_GSTREAMER_VIDEO_PLAYER_PLUGIN)
219221
${LIBGSTREAMER_APP_LDFLAGS}
220222
${LIBGSTREAMER_ALLOCATORS_LDFLAGS}
221223
${LIBGSTREAMER_VIDEO_LDFLAGS}
224+
${LIBGSTREAMER_AUDIO_LIBRARY_DIRS}
222225
)
223226
target_include_directories(flutter-pi PRIVATE
224227
${LIBGSTREAMER_INCLUDE_DIRS}
225228
${LIBGSTREAMER_PLUGINS_BASE_INCLUDE_DIRS}
226229
${LIBGSTREAMER_APP_INCLUDE_DIRS}
227230
${LIBGSTREAMER_ALLOCATORS_INCLUDE_DIRS}
228231
${LIBGSTREAMER_VIDEO_INCLUDE_DIRS}
232+
${LIBGSTREAMER_AUDIO_INCLUDE_DIRS}
229233
)
230234
target_compile_options(flutter-pi PRIVATE
231235
${LIBGSTREAMER_CFLAGS}
232236
${LIBGSTREAMER_PLUGINS_BASE_CFLAGS}
233237
${LIBGSTREAMER_APP_CFLAGS}
234238
${LIBGSTREAMER_ALLOCATORS_CFLAGS}
235239
${LIBGSTREAMER_VIDEO_CFLAGS}
240+
${LIBGSTREAMER_AUDIO_CFLAGS}
236241
)
237242
else()
238243
message(NOTICE "Couldn't find gstreamer libraries. Gstreamer video player plugin won't be build.")
239244
endif()
240245
endif()
241246

247+
if (BUILD_GSTREAMER_AUDIO_PLAYER_PLUGIN)
248+
if (TRY_BUILD_GSTREAMER_AUDIO_PLAYER_PLUGIN)
249+
pkg_check_modules(LIBGSTREAMER gstreamer-1.0)
250+
pkg_check_modules(LIBGSTREAMER_APP gstreamer-app-1.0)
251+
pkg_check_modules(LIBGSTREAMER_AUDIO gstreamer-audio-1.0)
252+
else()
253+
pkg_check_modules(LIBGSTREAMER REQUIRED gstreamer-1.0)
254+
pkg_check_modules(LIBGSTREAMER_APP REQUIRED gstreamer-app-1.0)
255+
pkg_check_modules(LIBGSTREAMER_AUDIO REQUIRED gstreamer-audio-1.0)
256+
endif()
257+
258+
if (LIBGSTREAMER_FOUND AND LIBGSTREAMER_APP_FOUND AND LIBGSTREAMER_AUDIO_FOUND)
259+
target_sources(flutter-pi PRIVATE
260+
src/plugins/audioplayers/plugin.c
261+
src/plugins/audioplayers/player.c
262+
)
263+
target_compile_definitions(flutter-pi PRIVATE "BUILD_GSTREAMER_AUDIO_PLAYER_PLUGIN")
264+
target_link_libraries(flutter-pi
265+
${LIBGSTREAMER_LDFLAGS}
266+
${LIBGSTREAMER_APP_LDFLAGS}
267+
${LIBGSTREAMER_AUDIO_LIBRARY_DIRS}
268+
)
269+
target_include_directories(flutter-pi PRIVATE
270+
${LIBGSTREAMER_INCLUDE_DIRS}
271+
${LIBGSTREAMER_APP_INCLUDE_DIRS}
272+
${LIBGSTREAMER_AUDIO_INCLUDE_DIRS}
273+
)
274+
target_compile_options(flutter-pi PRIVATE
275+
${LIBGSTREAMER_CFLAGS}
276+
${LIBGSTREAMER_APP_CFLAGS}
277+
${LIBGSTREAMER_AUDIO_CFLAGS}
278+
)
279+
else()
280+
message(NOTICE "Couldn't find gstreamer libraries. Gstreamer audio player plugin won't be build.")
281+
endif()
282+
endif()
283+
242284
# Needed so dart VM can actually resolve symbols in the same
243285
# executable.
244286
target_link_options(flutter-pi PRIVATE

include/plugins/audioplayers.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef AUDIOPLAYERS_H_
2+
#define AUDIOPLAYERS_H_
3+
4+
#include <stdbool.h>
5+
#include <stdint.h>
6+
7+
struct audio_player;
8+
9+
struct audio_player *audio_player_new(char *playerId, char *channel);
10+
11+
// Instance function
12+
13+
int64_t audio_player_get_position(struct audio_player *self);
14+
15+
int64_t audio_player_get_duration(struct audio_player *self);
16+
17+
bool audio_player_get_looping(struct audio_player *self);
18+
19+
void audio_player_play(struct audio_player *self);
20+
21+
void audio_player_pause(struct audio_player *self);
22+
23+
void audio_player_resume(struct audio_player *self);
24+
25+
void audio_player_destroy(struct audio_player *self);
26+
27+
void audio_player_set_looping(struct audio_player *self, bool isLooping);
28+
29+
void audio_player_set_volume(struct audio_player *self, double volume);
30+
31+
void audio_player_set_playback_rate(struct audio_player *self, double rate);
32+
33+
void audio_player_set_position(struct audio_player *self, int64_t position);
34+
35+
void audio_player_set_source_url(struct audio_player *self, char *url);
36+
37+
bool audio_player_is_id(struct audio_player *self, char *id);
38+
39+
#endif // AUDIOPLAYERS_H_

0 commit comments

Comments
 (0)