Add sound_manager_get_changed_focus_state() to get changed focus related information... 18/94518/4 accepted/tizen/common/20161109.140234 accepted/tizen/ivi/20161109.002822 accepted/tizen/mobile/20161109.002443 accepted/tizen/tv/20161109.002645 accepted/tizen/wearable/20161109.002738 submit/tizen/20161108.054351
authorSangchul Lee <sc11.lee@samsung.com>
Mon, 31 Oct 2016 08:47:06 +0000 (17:47 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Mon, 7 Nov 2016 01:23:49 +0000 (10:23 +0900)
[Version] 0.3.74
[Profile] Common
[Issue Type] Feature enhancement

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

index b589800..0eb46d8 100644 (file)
@@ -382,6 +382,7 @@ typedef void (*sound_manager_volume_changed_cb) (sound_type_e type, unsigned int
  * @see sound_manager_create_stream_information()
  * @see sound_manager_destroy_stream_information()
  * @see sound_manager_get_focus_state()
+ * @see sound_manager_get_changed_focus_state()
  * @see sound_manager_focus_get_requested_behavior()
  */
 typedef void (*sound_stream_focus_state_changed_cb) (sound_stream_info_h stream_info, sound_stream_focus_change_reason_e reason, const char *extra_info, void *user_data);
@@ -803,10 +804,35 @@ int sound_manager_release_focus(sound_stream_info_h stream_info, sound_stream_fo
  * @see sound_manager_destroy_stream_information()
  * @see sound_manager_acquire_focus()
  * @see sound_manager_release_focus()
+ * @see sound_manager_get_changed_focus_state()
  */
 int sound_manager_get_focus_state(sound_stream_info_h stream_info, sound_stream_focus_state_e *state_for_playback, sound_stream_focus_state_e *state_for_recording);
 
 /**
+ * @brief Gets the changed focus mask and state.
+ * @since_tizen 3.0
+ *
+ * @remarks    The changed focus mask and state can be obtained from this function within sound_stream_focus_state_changed_cb().\n
+ *     This function differs from sound_manager_get_focus_state() in that it only gets the changed focus mask and state.\n
+ *     Note that this function should be called within sound_stream_focus_state_changed_cb().
+ *
+ * @param[in]  stream_info     The handle of stream information
+ * @param[out] focus_mask      The changed focus mask
+ * @param[out] focus_state     The changed focus state
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #SOUND_MANAGER_ERROR_NONE Success
+ * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SOUND_MANAGER_ERROR_INVALID_OPERATION Invalid operation
+ * @pre Called sound_stream_focus_state_changed_cb() before calling this function.
+ * @see sound_manager_create_stream_information()
+ * @see sound_manager_acquire_focus()
+ * @see sound_manager_release_focus()
+ * @see sound_manager_get_focus_state()
+ */
+int sound_manager_get_changed_focus_state(sound_stream_info_h stream_info, sound_stream_focus_mask_e *focus_mask, sound_stream_focus_state_e *focus_state);
+
+/**
  * @brief Sets auto focus reacquisition property.
  * @since_tizen 3.0
  *
index c494612..85e5fe8 100644 (file)
@@ -159,6 +159,8 @@ typedef struct _sound_stream_info_s {
        pa_context *pa_context;
        stream_conf_info_s stream_conf_info;
        unsigned int acquired_focus;
+       mm_sound_focus_type_e changed_focus_type;
+       mm_sound_focus_state_e changed_focus_state;
        int requesting_flags;
        int requested_flags;
        sound_stream_focus_state_changed_cb user_cb;
index ec24c42..4804054 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       capi-media-sound-manager
 Summary:    Sound Manager library
-Version:    0.3.73
+Version:    0.3.74
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 37e8efc..36affde 100644 (file)
@@ -399,6 +399,37 @@ LEAVE:
        return _convert_sound_manager_error_code(__func__, ret);
 }
 
+int sound_manager_get_changed_focus_state(sound_stream_info_h stream_info, sound_stream_focus_mask_e *focus_mask, sound_stream_focus_state_e *focus_state)
+{
+       int ret = MM_ERROR_NONE;
+       sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
+       bool is_focus_cb_thread = false;
+
+       LOGI(">> enter");
+
+       SM_INSTANCE_CHECK(stream_h);
+       SM_NULL_ARG_CHECK(focus_mask);
+       SM_NULL_ARG_CHECK(focus_state);
+
+       if ((ret = mm_sound_focus_is_cb_thread(&is_focus_cb_thread)))
+               return _convert_sound_manager_error_code(__func__, ret);
+
+       if (!is_focus_cb_thread) {
+               LOGE("this API should be called in focus state changed callback");
+               return SOUND_MANAGER_ERROR_INVALID_OPERATION;
+       }
+
+       if (stream_h->changed_focus_type == FOCUS_NONE)
+               return SOUND_MANAGER_ERROR_INVALID_OPERATION;
+
+       *focus_mask = (sound_stream_focus_mask_e)stream_h->changed_focus_type;
+       *focus_state = (sound_stream_focus_state_e)stream_h->changed_focus_state;
+
+       LOGI("changed focus(mask:0x%x, state:%d)", *focus_mask, *focus_state);
+
+       return _convert_sound_manager_error_code(__func__, ret);
+}
+
 int sound_manager_focus_set_requesting_behavior(sound_stream_info_h stream_info, int flags)
 {
        sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
@@ -445,7 +476,7 @@ int sound_manager_focus_get_requested_behavior(sound_stream_info_h stream_info,
        SM_NULL_ARG_CHECK(flags);
 
        if ((ret = mm_sound_focus_is_cb_thread(&is_focus_cb_thread)))
-               _convert_sound_manager_error_code(__func__, ret);
+               return _convert_sound_manager_error_code(__func__, ret);
 
        if (!is_focus_cb_thread) {
                LOGE("this API should be called in focus state changed callback");
@@ -473,7 +504,7 @@ int sound_manager_get_current_playback_focus(sound_stream_focus_change_reason_e
        SM_NULL_ARG_CHECK(flags);
 
        if ((ret = mm_sound_focus_is_cb_thread(&is_focus_cb_thread)))
-               _convert_sound_manager_error_code(__func__, ret);
+               return _convert_sound_manager_error_code(__func__, ret);
 
        if (is_focus_cb_thread) {
                LOGE("this API should not be called in focus callback");
@@ -511,7 +542,7 @@ int sound_manager_get_current_recording_focus(sound_stream_focus_change_reason_e
        SM_NULL_ARG_CHECK(flags);
 
        if ((ret = mm_sound_focus_is_cb_thread(&is_focus_cb_thread)))
-               _convert_sound_manager_error_code(__func__, ret);
+               return _convert_sound_manager_error_code(__func__, ret);
 
        if (is_focus_cb_thread) {
                LOGE("this API should not be called in focus callback");
index 71579c5..c223443 100644 (file)
@@ -495,10 +495,17 @@ void _focus_state_change_callback(int index, mm_sound_focus_type_e focus_type, m
                        /* set flags for requested behavior */
                        sound_stream_info_arr[i]->requested_flags = option;
 
+                       /* set changed focus value */
+                       sound_stream_info_arr[i]->changed_focus_type = focus_type;
+                       sound_stream_info_arr[i]->changed_focus_state = state;
+
                        LOGI("[FOCUS USER CALLBACK(%p) START]", sound_stream_info_arr[i]->user_cb);
                        sound_stream_info_arr[i]->user_cb((sound_stream_info_h)sound_stream_info_arr[i], change_reason, extra_info, sound_stream_info_arr[i]->user_data);
                        LOGI("[FOCUS USER CALLBACK(%p) END]", sound_stream_info_arr[i]->user_cb);
 
+                       /* unset changed focus value */
+                       sound_stream_info_arr[i]->changed_focus_type = FOCUS_NONE;
+
                        /* unset flags for requested behavior */
                        sound_stream_info_arr[i]->requested_flags = 0;
                        break;
index 87def79..5301384 100644 (file)
@@ -112,6 +112,9 @@ void focus_callback(sound_stream_info_h stream_info, sound_stream_focus_change_r
        int ret = SOUND_MANAGER_ERROR_NONE;
        sound_stream_focus_state_e playback_focus_state;
        sound_stream_focus_state_e recording_focus_state;
+       sound_stream_focus_state_e changed_state;
+       sound_stream_focus_mask_e changed_mask;
+
        int flags = SOUND_BEHAVIOR_NONE;
 
        g_print("\n*** FOCUS callback is called, stream_info(%p) ***\n", stream_info);
@@ -119,6 +122,10 @@ void focus_callback(sound_stream_info_h stream_info, sound_stream_focus_change_r
        sound_manager_focus_get_requested_behavior(stream_info, &flags);
        g_print(" - change_reason(%d), behavior(0x%x), extra_info(%s), user_data(%p)\n", reason, flags, extra_info, user_data);
 
+       ret = sound_manager_get_changed_focus_state(stream_info, &changed_mask, &changed_state);
+       if (!ret)
+               g_print(" - changed focus: mask(%x), state(%d) (0:released, 1:acquired)\n", changed_mask, changed_state);
+
        ret = sound_manager_get_focus_state(stream_info, &playback_focus_state, &recording_focus_state);
        if (!ret)
                g_print(" - focus_state : PLAYBACK(%d), RECORDING(%d) (0:released, 1:acquired)\n", playback_focus_state, recording_focus_state);