Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gstreamer based audioplayers plugin #277

Merged
merged 16 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ jobs:

steps:
- uses: actions/checkout@v2

- name: Install dependencies
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
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

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DBUILD_OMXPLAYER_VIDEO_PLAYER_PLUGIN=On -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -GNinja
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

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

50 changes: 46 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ option(BUILD_TEXT_INPUT_PLUGIN "Include the text input plugin in the finished bi
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)
option(BUILD_TEST_PLUGIN "Include the test plugin in the finished binary. Allows testing platform channel communication." OFF)
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)
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)
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)
option(BUILD_GSTREAMER_AUDIO_PLAYER_PLUGIN "Include the gstreamer based audio plugins in the finished binary." ON)
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)
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)
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)
option(ENABLE_TSAN "True to build & link with -fsanitize=thread" OFF)
option(ENABLE_ASAN "True to build & link with -fsanitize=address" OFF)
Expand Down Expand Up @@ -130,7 +132,7 @@ target_link_libraries(flutter-pi
${GBM_LDFLAGS}
${EGL_LDFLAGS}
${GLESV2_LDFLAGS}
EGL
EGL
systemd #${LIBSYSTEMD_LDFLAGS}
input #${LIBINPUT_LDFLAGS}
xkbcommon #${LIBUDEV_LDFLAGS}
Expand All @@ -153,7 +155,7 @@ target_include_directories(flutter-pi PRIVATE
)

target_compile_options(flutter-pi PRIVATE
${DRM_CFLAGS}
${DRM_CFLAGS}
${GBM_CFLAGS}
${EGL_CFLAGS}
${GLESV2_CFLAGS}
Expand All @@ -166,7 +168,7 @@ target_compile_options(flutter-pi PRIVATE
$<$<CONFIG:Release>:-O2 -Wall -Wextra -Wno-unused-function -Wno-sign-compare -Wno-missing-field-initializers -ggdb>
)

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

# TODO: We actually don't need the compile definitions anymore, except for
Expand Down Expand Up @@ -219,26 +221,66 @@ if (BUILD_GSTREAMER_VIDEO_PLAYER_PLUGIN)
${LIBGSTREAMER_APP_LDFLAGS}
${LIBGSTREAMER_ALLOCATORS_LDFLAGS}
${LIBGSTREAMER_VIDEO_LDFLAGS}
${LIBGSTREAMER_AUDIO_LIBRARY_DIRS}
)
target_include_directories(flutter-pi PRIVATE
${LIBGSTREAMER_INCLUDE_DIRS}
${LIBGSTREAMER_PLUGINS_BASE_INCLUDE_DIRS}
${LIBGSTREAMER_APP_INCLUDE_DIRS}
${LIBGSTREAMER_ALLOCATORS_INCLUDE_DIRS}
${LIBGSTREAMER_VIDEO_INCLUDE_DIRS}
${LIBGSTREAMER_AUDIO_INCLUDE_DIRS}
)
target_compile_options(flutter-pi PRIVATE
${LIBGSTREAMER_CFLAGS}
${LIBGSTREAMER_PLUGINS_BASE_CFLAGS}
${LIBGSTREAMER_APP_CFLAGS}
${LIBGSTREAMER_ALLOCATORS_CFLAGS}
${LIBGSTREAMER_VIDEO_CFLAGS}
${LIBGSTREAMER_AUDIO_CFLAGS}
ardera marked this conversation as resolved.
Show resolved Hide resolved
)
else()
message(NOTICE "Couldn't find gstreamer libraries. Gstreamer video player plugin won't be build.")
endif()
endif()

if (BUILD_GSTREAMER_AUDIO_PLAYER_PLUGIN)
if (TRY_BUILD_GSTREAMER_AUDIO_PLAYER_PLUGIN)
pkg_check_modules(LIBGSTREAMER gstreamer-1.0)
pkg_check_modules(LIBGSTREAMER_APP gstreamer-app-1.0)
pkg_check_modules(LIBGSTREAMER_AUDIO gstreamer-audio-1.0)
else()
pkg_check_modules(LIBGSTREAMER REQUIRED gstreamer-1.0)
pkg_check_modules(LIBGSTREAMER_APP REQUIRED gstreamer-app-1.0)
pkg_check_modules(LIBGSTREAMER_AUDIO REQUIRED gstreamer-audio-1.0)
endif()

if (LIBGSTREAMER_FOUND AND LIBGSTREAMER_APP_FOUND AND LIBGSTREAMER_AUDIO_FOUND)
target_sources(flutter-pi PRIVATE
src/plugins/audioplayers/plugin.c
src/plugins/audioplayers/player.c
)
target_compile_definitions(flutter-pi PRIVATE "BUILD_GSTREAMER_AUDIO_PLAYER_PLUGIN")
target_link_libraries(flutter-pi
${LIBGSTREAMER_LDFLAGS}
${LIBGSTREAMER_APP_LDFLAGS}
${LIBGSTREAMER_AUDIO_LIBRARY_DIRS}
)
target_include_directories(flutter-pi PRIVATE
${LIBGSTREAMER_INCLUDE_DIRS}
${LIBGSTREAMER_APP_INCLUDE_DIRS}
${LIBGSTREAMER_AUDIO_INCLUDE_DIRS}
)
target_compile_options(flutter-pi PRIVATE
${LIBGSTREAMER_CFLAGS}
${LIBGSTREAMER_APP_CFLAGS}
${LIBGSTREAMER_AUDIO_CFLAGS}
)
else()
message(NOTICE "Couldn't find gstreamer libraries. Gstreamer audio player plugin won't be build.")
endif()
endif()

# Needed so dart VM can actually resolve symbols in the same
# executable.
target_link_options(flutter-pi PRIVATE
Expand Down
39 changes: 39 additions & 0 deletions include/plugins/audioplayers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef AUDIOPLAYERS_H_
#define AUDIOPLAYERS_H_

#include <stdbool.h>
#include <stdint.h>

struct audio_player;

struct audio_player *audio_player_new(char *playerId, char *channel);

// Instance function

int64_t audio_player_get_position(struct audio_player *self);

int64_t audio_player_get_duration(struct audio_player *self);

bool audio_player_get_looping(struct audio_player *self);

void audio_player_play(struct audio_player *self);

void audio_player_pause(struct audio_player *self);

void audio_player_resume(struct audio_player *self);

void audio_player_destroy(struct audio_player *self);

void audio_player_set_looping(struct audio_player *self, bool isLooping);

void audio_player_set_volume(struct audio_player *self, double volume);

void audio_player_set_playback_rate(struct audio_player *self, double rate);

void audio_player_set_position(struct audio_player *self, int64_t position);

void audio_player_set_source_url(struct audio_player *self, char *url);

bool audio_player_is_id(struct audio_player *self, char *id);

#endif // AUDIOPLAYERS_H_
Loading