Revise codes to comply with API changes of libmm-sound 46/182446/1 accepted/tizen/unified/20180702.062855 submit/tizen/20180626.044608
authorSangchul Lee <sc11.lee@samsung.com>
Mon, 18 Dec 2017 01:18:12 +0000 (10:18 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Mon, 25 Jun 2018 07:54:55 +0000 (16:54 +0900)
some functions of libmm-sound regarding focus was changed.

[Version] 0.5.6
[Issue Type] API changes of dependency module

Change-Id: Ifd561d5155b652abda2f4b412766b510c765074f
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
include/sound_manager_private.h
packaging/capi-media-sound-manager.spec
src/sound_manager.c
src/sound_manager_internal.c
src/sound_manager_private.c
test/sound_manager_test.c

index 2a44919..a5aee7c 100644 (file)
@@ -194,7 +194,8 @@ typedef struct _manual_route_info_s {
 } manual_route_info_s;
 
 typedef struct _sound_stream_info_s {
-       unsigned int index;
+       unsigned int pa_index;
+       int focus_id;
        char *stream_type;
        bool is_focus_unavailable;
        pa_threaded_mainloop *pa_mainloop;
index e75615e..b7d1330 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-sound-manager
 Summary:    Sound Manager library
-Version:    0.5.5
+Version:    0.5.6
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index c33de4c..e178d5b 100644 (file)
@@ -135,7 +135,8 @@ int sound_manager_create_stream_information(sound_stream_type_e stream_type, sou
                ret = _make_pa_connection_and_register_focus(stream_h, callback, user_data);
                if (ret == MM_ERROR_NONE) {
                        *stream_info = (sound_stream_info_h)stream_h;
-                       LOGI("stream_h(%p), index(%u), user_cb(%p), ret(0x%x)", stream_h, stream_h->index, stream_h->user_cb, ret);
+                       LOGI("stream_h(%p), pa_index(%u), focus_id(%d), user_cb(%p), ret(0x%x)",
+                               stream_h, stream_h->pa_index, stream_h->focus_id, stream_h->user_cb, ret);
                }
        }
 
@@ -244,7 +245,7 @@ int sound_manager_set_focus_reacquisition(sound_stream_info_h stream_info, bool
 
        SM_INSTANCE_CHECK(stream_h);
 
-       ret = mm_sound_set_focus_reacquisition(stream_h->index, enable);
+       ret = mm_sound_set_focus_reacquisition(stream_h->focus_id, enable);
 
        LOGI("enable(%d)", enable);
 
@@ -261,7 +262,7 @@ int sound_manager_get_focus_reacquisition(sound_stream_info_h stream_info, bool
        SM_INSTANCE_CHECK(stream_h);
        SM_NULL_ARG_CHECK(enabled);
 
-       ret = mm_sound_get_focus_reacquisition(stream_h->index, enabled);
+       ret = mm_sound_get_focus_reacquisition(stream_h->focus_id, enabled);
 
        LOGI("enabled(%d)", *enabled);
 
@@ -311,11 +312,11 @@ int sound_manager_acquire_focus(sound_stream_info_h stream_info, sound_stream_fo
                goto LEAVE;
        }
 
-       ret = mm_sound_acquire_focus_with_option(stream_h->index, (mm_sound_focus_type_e)focus_mask, sound_behavior, extra_info);
+       ret = mm_sound_acquire_focus_with_option(stream_h->focus_id, (mm_sound_focus_type_e)focus_mask, sound_behavior, extra_info);
        if (ret == MM_ERROR_NONE) {
                stream_h->acquired_focus |= focus_mask;
                stream_h->prev_acquired_focus |= focus_mask;
-               _update_focus_status(stream_h->index, (unsigned int)stream_h->acquired_focus);
+               _update_focus_status(stream_h->pa_index, (unsigned int)stream_h->acquired_focus);
        }
 
        LOGI("acquired_focus[0x%x], prev[0x%x]", stream_h->acquired_focus, stream_h->prev_acquired_focus);
@@ -361,11 +362,11 @@ int sound_manager_release_focus(sound_stream_info_h stream_info, sound_stream_fo
                goto LEAVE;
        }
 
-       ret = mm_sound_release_focus_with_option(stream_h->index, (mm_sound_focus_type_e)focus_mask, sound_behavior, extra_info);
+       ret = mm_sound_release_focus_with_option(stream_h->focus_id, (mm_sound_focus_type_e)focus_mask, sound_behavior, extra_info);
        if (ret == MM_ERROR_NONE) {
                stream_h->acquired_focus &= ~focus_mask;
                stream_h->prev_acquired_focus &= ~focus_mask;
-               _update_focus_status(stream_h->index, (unsigned int)stream_h->acquired_focus);
+               _update_focus_status(stream_h->pa_index, (unsigned int)stream_h->acquired_focus);
        }
 
        LOGI("acquired_focus[0x%x], prev[0x%x]", stream_h->acquired_focus, stream_h->prev_acquired_focus);
@@ -423,11 +424,11 @@ int sound_manager_acquire_focus_all(sound_stream_info_h stream_info, int sound_b
                goto LEAVE;
        }
 
-       ret = mm_sound_acquire_focus_with_option(stream_h->index, (mm_sound_focus_type_e)focus_mask, sound_behavior, extra_info);
+       ret = mm_sound_acquire_focus_with_option(stream_h->focus_id, (mm_sound_focus_type_e)focus_mask, sound_behavior, extra_info);
        if (ret == MM_ERROR_NONE) {
                stream_h->acquired_focus |= focus_mask;
                stream_h->prev_acquired_focus |= focus_mask;
-               _update_focus_status(stream_h->index, (unsigned int)stream_h->acquired_focus);
+               _update_focus_status(stream_h->pa_index, (unsigned int)stream_h->acquired_focus);
        }
 
 LEAVE:
@@ -471,11 +472,11 @@ int sound_manager_release_focus_all(sound_stream_info_h stream_info, int sound_b
                goto LEAVE;
        }
 
-       ret = mm_sound_release_focus_with_option(stream_h->index, (mm_sound_focus_type_e)stream_h->acquired_focus, sound_behavior, extra_info);
+       ret = mm_sound_release_focus_with_option(stream_h->focus_id, (mm_sound_focus_type_e)stream_h->acquired_focus, sound_behavior, extra_info);
        if (ret == MM_ERROR_NONE) {
                stream_h->acquired_focus = 0;
                stream_h->prev_acquired_focus = 0;
-               _update_focus_status(stream_h->index, (unsigned int)stream_h->acquired_focus);
+               _update_focus_status(stream_h->pa_index, (unsigned int)stream_h->acquired_focus);
        }
 
 LEAVE:
@@ -531,8 +532,8 @@ int sound_manager_deliver_focus(sound_stream_info_h source, sound_stream_info_h
                return SOUND_MANAGER_ERROR_INVALID_OPERATION;
        }
 
-       if (src_stream_h->index == dst_stream_h->index) {
-               LOGE("not allowed because both handles have same index(%u)", src_stream_h->index);
+       if (src_stream_h->focus_id == dst_stream_h->focus_id) {
+               LOGE("not allowed because both handles have same id(%u)", src_stream_h->focus_id);
                return SOUND_MANAGER_ERROR_INVALID_PARAMETER;
        }
 
@@ -553,7 +554,7 @@ int sound_manager_deliver_focus(sound_stream_info_h source, sound_stream_info_h
                return SOUND_MANAGER_ERROR_POLICY;
        }
 
-       ret = mm_sound_deliver_focus(src_stream_h->index, dst_stream_h->index, (mm_sound_focus_type_e)focus_mask);
+       ret = mm_sound_deliver_focus(src_stream_h->focus_id, dst_stream_h->focus_id, (mm_sound_focus_type_e)focus_mask);
        if (ret == MM_ERROR_NONE) {
                src_stream_h->acquired_focus &= ~focus_mask;
                src_stream_h->prev_acquired_focus &= ~focus_mask;
@@ -575,7 +576,7 @@ int sound_manager_is_stream_on_device(sound_stream_info_h stream_info, sound_dev
        SM_NULL_ARG_CHECK(device);
        SM_NULL_ARG_CHECK(is_on);
 
-       ret = mm_sound_is_stream_on_device(stream_h->index, device, is_on);
+       ret = mm_sound_is_stream_on_device(stream_h->pa_index, device, is_on);
 
        return _convert_sound_manager_error_code(__func__, ret);
 }
index 55589fb..7e9a09f 100644 (file)
@@ -85,7 +85,8 @@ 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;
-                       LOGI("stream_h(%p), index(%u), user_cb(%p), ret(0x%x)", stream_h, stream_h->index, stream_h->user_cb, ret);
+                       LOGI("stream_h(%p), pa_index(%u), focus_id(%d), user_cb(%p), ret(0x%x)",
+                               stream_h, stream_h->pa_index, stream_h->focus_id, stream_h->user_cb, ret);
                }
        }
 
@@ -106,7 +107,7 @@ int sound_manager_set_stream_routing_option(sound_stream_info_h stream_info, con
        SM_INSTANCE_CHECK(stream_h);
        SM_NULL_ARG_CHECK(name);
 
-       ret = _set_route_option(stream_h->index, name, value);
+       ret = _set_route_option(stream_h->pa_index, name, value);
 
        return _convert_sound_manager_error_code(__func__, ret);
 }
@@ -154,8 +155,8 @@ int sound_manager_get_index_from_stream_information(sound_stream_info_h stream_i
        SM_INSTANCE_CHECK(stream_h);
        SM_NULL_ARG_CHECK(index);
 
-       *index = stream_h->index;
-       LOGI("stream_index[%d]", stream_h->index);
+       *index = stream_h->pa_index;
+       LOGI("stream_index[%u]", stream_h->pa_index);
 
        return _convert_sound_manager_error_code(__func__, ret);
 }
index d828be4..73d43c8 100644 (file)
@@ -543,8 +543,8 @@ void _focus_state_change_callback(int index, mm_sound_focus_type_e focus_type, m
        }
 
        stream_info = (sound_stream_info_s *)user_data;
-       if (stream_info->index != index) {
-               LOGE("index is not valid, (%d, %d)", stream_info->index, index);
+       if (stream_info->focus_id != index) {
+               LOGE("index is not valid, (%d, %d)", stream_info->focus_id, index);
                goto LEAVE;
        }
 
@@ -561,7 +561,7 @@ void _focus_state_change_callback(int index, mm_sound_focus_type_e focus_type, m
                stream_info->acquired_focus |= focus_type;
 
        if (state == FOCUS_IS_ACQUIRED)
-               _update_focus_status(stream_info->index, (unsigned int)stream_info->acquired_focus);
+               _update_focus_status(stream_info->pa_index, (unsigned int)stream_info->acquired_focus);
 
        LOGI("[FOCUS USER CALLBACK(%p) START]", stream_info->user_cb);
        stream_info->user_cb((sound_stream_info_h)stream_info, focus_type, state, change_reason,
@@ -569,7 +569,7 @@ void _focus_state_change_callback(int index, mm_sound_focus_type_e focus_type, m
        LOGI("[FOCUS USER CALLBACK(%p) END]", stream_info->user_cb);
 
        if (state == FOCUS_IS_RELEASED)
-               _update_focus_status(stream_info->index, (unsigned int)stream_info->acquired_focus);
+               _update_focus_status(stream_info->pa_index, (unsigned int)stream_info->acquired_focus);
 
        if (state == FOCUS_IS_RELEASED)
                stream_info->prev_acquired_focus &= ~focus_type;
@@ -1259,13 +1259,13 @@ int _make_pa_connection_and_register_focus(sound_stream_info_s *stream_h, sound_
        }
 
        /* get index of this context */
-       stream_h->index = pa_context_get_index(stream_h->pa_context);
+       stream_h->pa_index = pa_context_get_index(stream_h->pa_context);
 
        pa_threaded_mainloop_unlock(stream_h->pa_mainloop);
 
        /* register focus */
        if (!stream_h->is_focus_unavailable) {
-               ret = mm_sound_register_focus(stream_h->index, stream_h->stream_type, _focus_state_change_callback, stream_h);
+               ret = mm_sound_register_focus(stream_h->stream_type, _focus_state_change_callback, stream_h, &stream_h->focus_id);
                if (ret == MM_ERROR_NONE) {
                        stream_h->user_cb = callback;
                        stream_h->user_data = user_data;
@@ -1335,7 +1335,7 @@ int _destroy_pa_connection_and_unregister_focus(sound_stream_info_s *stream_h)
 
        /* unregister focus */
        if (!stream_h->is_focus_unavailable) {
-               ret = mm_sound_unregister_focus(stream_h->index);
+               ret = mm_sound_unregister_focus(stream_h->focus_id);
                if (ret)
                        LOGE("failed to unregister focus, ret(0x%x)", ret);
        }
@@ -1640,7 +1640,7 @@ int _apply_stream_routing(sound_stream_info_s *stream_info)
        SM_INSTANCE_CHECK_FOR_PRIV(stream_info);
 
        if (stream_info->stream_conf_info.route_type != STREAM_ROUTE_TYPE_MANUAL &&
-           stream_info->stream_conf_info.route_type != STREAM_ROUTE_TYPE_MANUAL_EXT) {
+               stream_info->stream_conf_info.route_type != STREAM_ROUTE_TYPE_MANUAL_EXT) {
                LOGE("route type is not manual or manual-ext");
                /* Differ from others, it uses SOUND_INTERNAL error.
                 * ACR process is required prior to changing error value. */
@@ -1650,7 +1650,7 @@ int _apply_stream_routing(sound_stream_info_s *stream_info)
        for (i = 0; i < AVAIL_DEVICES_MAX; i++) {
                if (stream_info->manual_route_info.route_in_devices[i] ||
                    stream_info->manual_route_info.route_out_devices[i])
-                       return _set_manual_route_info(stream_info->index, &stream_info->manual_route_info);
+                       return _set_manual_route_info(stream_info->pa_index, &stream_info->manual_route_info);
        }
 
        return MM_ERROR_SOUND_INVALID_STATE;
@@ -1692,7 +1692,7 @@ int _create_virtual_stream(sound_stream_info_s *stream_info, virtual_sound_strea
        (*virtual_stream)->pa_context = stream_info->pa_context;
        (*virtual_stream)->pa_proplist = pa_proplist_new();
        pa_proplist_sets((*virtual_stream)->pa_proplist, PA_PROP_MEDIA_ROLE, (*virtual_stream)->stream_type);
-       pa_proplist_setf((*virtual_stream)->pa_proplist, PA_PROP_MEDIA_PARENT_ID, "%u", stream_info->index);
+       pa_proplist_setf((*virtual_stream)->pa_proplist, PA_PROP_MEDIA_PARENT_ID, "%u", stream_info->pa_index);
        (*virtual_stream)->state = _VSTREAM_STATE_READY;
        (*virtual_stream)->stream_info = stream_info;
 
index 3bb3ea3..f0b2caa 100644 (file)
@@ -124,6 +124,30 @@ void focus_callback(sound_stream_info_h stream_info,
 
        g_print("*** FOCUS callback is ended, stream_info(%p) ****\n\n", stream_info);
 
+#if 0 /* test for complicated scenario */
+       if (focus_state == SOUND_STREAM_FOCUS_STATE_RELEASED && recording_focus_state == SOUND_STREAM_FOCUS_STATE_ACQUIRED) {
+               g_print("### try to acquire playback focus now..\n");
+               ret = sound_manager_acquire_focus(stream_info, SOUND_STREAM_FOCUS_FOR_PLAYBACK, SOUND_BEHAVIOR_NONE, "in callback thread");
+               if (ret)
+                       g_print("failed to acquire focus..ret:0x%x\n", ret);
+               g_print("### try to release recording focus now..\n");
+               ret = sound_manager_release_focus(stream_info, SOUND_STREAM_FOCUS_FOR_RECORDING, SOUND_BEHAVIOR_NONE, "in callback thread");
+               if (ret)
+                       g_print("failed to release focus..ret:0x%x\n", ret);
+       }
+
+       if (focus_state == SOUND_STREAM_FOCUS_STATE_ACQUIRED && playback_focus_state == SOUND_STREAM_FOCUS_STATE_ACQUIRED) {
+               g_print("### try to release playback focus now..\n");
+               ret = sound_manager_release_focus(stream_info, SOUND_STREAM_FOCUS_FOR_PLAYBACK, SOUND_BEHAVIOR_NONE, "in callback thread");
+               if (ret)
+                       g_print("failed to release focus..ret:0x%x\n", ret);
+               g_print("### try to acquire recording focus now..\n");
+               ret = sound_manager_acquire_focus(stream_info, SOUND_STREAM_FOCUS_FOR_RECORDING, SOUND_BEHAVIOR_NONE, "in callback thread");
+               if (ret)
+                       g_print("failed to acquire focus..ret:0x%x\n", ret);
+       }
+#endif
+
        return;
 }