Use fd-passing to support container usage 83/283383/11 accepted/tizen/unified/20221104.082300
authorSeungbae Shin <seungbae.shin@samsung.com>
Tue, 25 Oct 2022 12:11:27 +0000 (21:11 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Thu, 3 Nov 2022 06:05:16 +0000 (15:05 +0900)
[Version] 0.3.11
[Issue Type] Feature

Change-Id: I7f61d11edc6612bf160b365db2179b18097ed4d9

CMakeLists.txt
packaging/capi-media-wav-player.spec
src/wav_player_private.c

index 69c84c0..dcec205 100644 (file)
@@ -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}")
index f79046e..051b5c3 100755 (executable)
@@ -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.
index f06b8f8..ca131e6 100644 (file)
 #include <glib.h>
 #include "wav_player_private.h"
 
+#include <gio/gunixfdlist.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+
 #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;