Add handling mutex codes for stream info handle created by internal API 77/56077/2
authorSangchul Lee <sc11.lee@samsung.com>
Mon, 4 Jan 2016 06:39:48 +0000 (15:39 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Mon, 4 Jan 2016 06:47:23 +0000 (15:47 +0900)
[Version] Release 0.3.38
[profile] Common
[Issue Type] Feature enhancement

Change-Id: Id62f64124ef0da2596e4266d54ba76618ca3a2fc

packaging/capi-media-sound-manager.spec
src/sound_manager_internal.c
test/sound_manager_test.c

index a6a21dde04335d6a82126543ce2d6c63839867c3..2ad3d1db1e8feaa1ae0059ea3518ac7c93d0403c 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       capi-media-sound-manager
 Summary:    Sound Manager library
-Version:    0.3.37
+Version:    0.3.38
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 4c0a12ae496a19db94a03fdbd6db1c3564884a48..a8c885957728cad4cd27e160b1ed48b784965e0a 100644 (file)
 #include <sound_manager_internal.h>
 #include <mm_sound.h>
 
+/* These variables will be removed when session features are deprecated. */
+extern int g_stream_info_count;
+extern pthread_mutex_t g_stream_info_count_mutex;
+
 int sound_manager_get_max_master_volume(int *max_level)
 {
        int ret = MM_ERROR_NONE;
@@ -71,6 +75,8 @@ int sound_manager_create_stream_information_internal(sound_stream_type_internal_
        SM_NULL_ARG_CHECK(stream_info);
        SM_NULL_ARG_CHECK(callback);
 
+       SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_stream_info_count_mutex, MM_ERROR_SOUND_INTERNAL);
+
        sound_stream_info_s *stream_h = malloc(sizeof(sound_stream_info_s));
        if (!stream_h) {
                ret = MM_ERROR_OUT_OF_MEMORY;
@@ -81,6 +87,7 @@ int sound_manager_create_stream_information_internal(sound_stream_type_internal_
                        ret = _make_pa_connection_and_register_focus(stream_h, callback, user_data);
                        if (!ret) {
                                *stream_info = (sound_stream_info_h)stream_h;
+                               SM_REF_FOR_STREAM_INFO(g_stream_info_count, ret);
                                LOGI("stream_h(%p), index(%u), user_cb(%p), ret(0x%x)", stream_h, stream_h->index, stream_h->user_cb, ret);
                        }
                }
@@ -88,6 +95,8 @@ int sound_manager_create_stream_information_internal(sound_stream_type_internal_
                        free(stream_h);
        }
 
+       SM_LEAVE_CRITICAL_SECTION(&g_stream_info_count_mutex);
+
        return _convert_sound_manager_error_code(__func__, ret);
 }
 
index 4104b8d74c35671cb133ff1020c88c72d7a0c99f..fb7f723d13c5053d53acbf675343a0bd9ba29423 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <sound_manager.h>
 #include <sound_manager_internal.h>
+#include <mm_sound.h>
 #include <pthread.h>
 #include <glib.h>
 
@@ -1494,16 +1495,33 @@ gboolean input(GIOChannel *channel)
        return TRUE;
 }
 
+/* it will be removed when session features are deprecated. */
+void signal_callback(mm_sound_signal_name_t signal, int value, void *user_data)
+{
+       g_print("*** signal callback is called: signal(%d), value(%d), user_data(%p)\n", signal, value, user_data);
+}
+
 int main(int argc, char *argv[])
 {
+       unsigned int subscribe_id = 0;
+       int ret = MM_ERROR_NONE;
        GIOChannel *stdin_channel;
        stdin_channel = g_io_channel_unix_new(0);
        g_io_channel_set_flags(stdin_channel, G_IO_FLAG_NONBLOCK, NULL);
        g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, NULL);
        g_loop = g_main_loop_new(NULL, 1);
 
+       /* subscribe a signal for convering session-focus */
+       /* it will be removed when session features are deprecated. */
+       if ((ret = mm_sound_subscribe_signal(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &subscribe_id, signal_callback, NULL)))
+               g_print("failed to subscribe signal, ret(0x%x)\n", ret);
+
        displaymenu();
        g_main_loop_run(g_loop);
 
+       /* it will be removed when session features are deprecated. */
+       if (subscribe_id)
+               mm_sound_unsubscribe_signal(subscribe_id);
+
        return 0;
 }