From: Seungbae Shin Date: Tue, 25 Oct 2022 12:11:27 +0000 (+0900) Subject: Use fd-passing to support container usage X-Git-Tag: accepted/tizen/unified/20221104.082300^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=69a51bb02faa4b0de7f0470eecdc85452f3bfcd5;p=platform%2Fcore%2Fapi%2Fwav-player.git Use fd-passing to support container usage [Version] 0.3.11 [Issue Type] Feature Change-Id: I7f61d11edc6612bf160b365db2179b18097ed4d9 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 69c84c0..dcec205 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ SET(service "media") SET(submodule "wav-player") # for package file -SET(dependents "dlog capi-base-common capi-media-sound-manager gio-2.0") +SET(dependents "dlog capi-base-common capi-media-sound-manager gio-2.0 gio-unix-2.0") SET(pc_dependents "capi-base-common capi-media-sound-manager") SET(fw_name "${project_prefix}-${service}-${submodule}") diff --git a/packaging/capi-media-wav-player.spec b/packaging/capi-media-wav-player.spec index f79046e..051b5c3 100755 --- a/packaging/capi-media-wav-player.spec +++ b/packaging/capi-media-wav-player.spec @@ -1,6 +1,6 @@ Name: capi-media-wav-player Summary: A wav player library in Tizen C API -Version: 0.3.10 +Version: 0.3.11 Release: 0 Group: Multimedia/API License: Apache-2.0 @@ -11,6 +11,7 @@ BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(capi-media-sound-manager) BuildRequires: pkgconfig(gio-2.0) +BuildRequires: pkgconfig(gio-unix-2.0) %description A wav player library in Tizen C API. diff --git a/src/wav_player_private.c b/src/wav_player_private.c index f06b8f8..ca131e6 100644 --- a/src/wav_player_private.c +++ b/src/wav_player_private.c @@ -27,6 +27,11 @@ #include #include "wav_player_private.h" +#include +#include +#include +#include + #define PA_BUS_NAME "org.pulseaudio.Server" #define PA_SOUND_PLAYER_OBJECT_PATH "/org/pulseaudio/SoundPlayer" #define PA_SOUND_PLAYER_INTERFACE "org.pulseaudio.SoundPlayer" @@ -128,6 +133,10 @@ int _wav_play_sound(const char *path, sound_stream_info_h stream_info, unsigned g_autoptr(GVariant) reply = NULL; dbus_cb_data_s *dbus_cb_data = NULL; + g_autoptr(GUnixFDList) fd_list = NULL; + int fd = -1; + int appended_index = -1; + if (path == NULL || stream_info == NULL) { LOGE("invalid params"); return WAV_PLAYER_ERROR_INVALID_PARAMETER; @@ -168,19 +177,38 @@ int _wav_play_sound(const char *path, sound_stream_info_h stream_info, unsigned if (!(conn = __get_dbus_connection())) return WAV_PLAYER_ERROR_INVALID_OPERATION; - reply = g_dbus_connection_call_sync(conn, PA_BUS_NAME, + fd = open(m_path, O_RDONLY); + if (fd == -1) { + LOGE("error opening(%s), errno(%d)", m_path, errno); + return WAV_PLAYER_ERROR_INVALID_OPERATION; + } + + LOGI("fd(%d) opened for fd-passing", fd); + + fd_list = g_unix_fd_list_new(); + appended_index = g_unix_fd_list_append(fd_list, fd, &err); + if (appended_index == -1) { + LOGE("failed, %s", err->message); + close(fd); + return WAV_PLAYER_ERROR_INVALID_OPERATION; + } + + /* Note: Sending appended index to fd-list is required + for receiving fd-passing using non-gdbus implementation */ + reply = g_dbus_connection_call_with_unix_fd_list_sync(conn, PA_BUS_NAME, PA_SOUND_PLAYER_OBJECT_PATH, PA_SOUND_PLAYER_INTERFACE, PA_SOUND_PLAYER_METHOD_NAME_SOUND_PLAY, - g_variant_new("(siisib)", m_path, loop_count == 0 ? -1 : loop_count, - getpid(), stream_type, stream_id, (gboolean)stop_others), - NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err); + g_variant_new("(siisibh)", m_path, loop_count == 0 ? -1 : loop_count, + getpid(), stream_type, stream_id, (gboolean)stop_others, appended_index), + NULL, G_DBUS_CALL_FLAGS_NONE, -1, fd_list, NULL, NULL, &err); if (!reply) { - LOGE("g_dbus_connection_call_sync error (%s)", err->message); - ret = __convert_dbus_error(err->message); - return ret; + LOGE("g_dbus_connection_call_with_unix_fd_list_sync error (%s)", err->message); + return __convert_dbus_error(err->message); } + close(fd); + g_variant_get(reply, "(i)", &handle); if (id) *id = handle;