Add api to use media_volume in radio_hal 03/101203/2 accepted/tizen/3.0/common/20161207.194416 accepted/tizen/3.0/ivi/20161207.011838 accepted/tizen/3.0/mobile/20161207.011334 accepted/tizen/3.0/wearable/20161207.011733 submit/tizen_3.0/20161206.052949
authorGilbok Lee <gilbok.lee@samsung.com>
Wed, 30 Nov 2016 11:28:17 +0000 (20:28 +0900)
committerGilbok Lee <gilbok.lee@samsung.com>
Wed, 30 Nov 2016 11:37:08 +0000 (20:37 +0900)
[Version] 0.2.15
[Profile] Mobile, Wearable
[Issue Type] Add features

Change-Id: I98d0848e503e09dfe3d1a278f77456c0fc0471b6

packaging/libmm-radio.spec
src/include/radio_hal_interface.h
src/include/tizen-radio.h
src/mm_radio_priv_hal.c
src/radio_hal_interface.c

index e2b8aed..c8527de 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       libmm-radio
 Summary:    Multimedia Framework Radio Library
-Version:    0.2.14
+Version:    0.2.15
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
index 3fdac71..7662e05 100644 (file)
@@ -53,6 +53,8 @@ int radio_hal_mute(mm_radio_hal_interface *radio_handle);
 int radio_hal_unmute(mm_radio_hal_interface *radio_handle);
 int radio_hal_set_volume(mm_radio_hal_interface *radio_handle, float volume);
 int radio_hal_get_volume(mm_radio_hal_interface *radio_handle, float *volume);
+int radio_hal_set_media_volume(mm_radio_hal_interface *radio_handle, uint32_t level);
+
 
 #ifdef __cplusplus
 }
index 1eedc30..db0b67c 100644 (file)
@@ -85,6 +85,7 @@ typedef struct radio_interface {
        radio_error_t (*get_signal_strength)(void *radio_handle, uint32_t *strength);
        radio_error_t (*get_volume)(void *radio_handle, float *volume);
        radio_error_t (*set_volume)(void *radio_handle, float volume);
+       radio_error_t (*set_media_volume)(void *radio_handle, uint32_t level);
 } radio_interface_t;
 
 /**
@@ -279,6 +280,19 @@ radio_error_t radio_get_volume(void *radio_handle, float *volume);
 radio_error_t radio_set_volume(void *radio_handle, float volume);
 
 /**
+ * @brief Sets the current media volume level(system media volume).
+ * @since_tizen 3.0
+ * @param[in] radio_handle The radio HAL handle
+ * @param[in] level The media volume level to set
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #RADIO_ERROR_NONE Successful
+ * @retval #RADIO_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #RADIO_ERROR_INVALID_OPERATION Invalid operation
+ */
+radio_error_t radio_set_media_volume(void *radio_handle, uint32_t level);
+
+
+/**
  * @}
  */
 
index a349c39..8d5cd0a 100644 (file)
@@ -135,7 +135,7 @@ static void __mmradio_sound_focus_watch_cb(int id, mm_sound_focus_type_e focus_t
 #endif
 
 static void __mmradio_volume_changed_cb(volume_type_t type, unsigned int volume, void *user_data);
-static int __mmradio_set_total_volume(mm_radio_t *radio);
+static int __mmradio_set_media_volume(mm_radio_t *radio, unsigned int level);
 
 int _mmradio_apply_region(mm_radio_t *radio, MMRadioRegionType region, bool update)
 {
@@ -548,15 +548,9 @@ int _mmradio_start(mm_radio_t *radio)
        if (ret != MM_ERROR_NONE)
                MMRADIO_LOG_WARNING("failed to get MEDIA_VOLUME");
 
-       MMRADIO_VOLUME_LOCK(radio);
-       radio->media_volume = volume;
-       MMRADIO_VOLUME_UNLOCK(radio);
-
-       ret = __mmradio_set_total_volume(radio);
-       if (ret == MM_ERROR_NOT_SUPPORT_API) {
-               MMRADIO_LOG_WARNING("radio_hal_set_volume is not supported");
-       } else if (ret) {
-               MMRADIO_LOG_ERROR("failed to radio_hal_set_volume\n");
+       ret = __mmradio_set_media_volume(radio, volume);
+       if (ret != MM_ERROR_NONE) {
+               MMRADIO_LOG_ERROR("failed to media volume");
                goto error1;
        }
 
@@ -1441,38 +1435,17 @@ static void __mmradio_sound_focus_watch_cb(int id, mm_sound_focus_type_e focus_t
 }
 #endif
 
-static int __mmradio_set_total_volume(mm_radio_t *radio)
-{
-       int ret = MM_ERROR_NONE;
-       float total_volume = 0.0f;
-
-       MMRADIO_CHECK_INSTANCE(radio);
-
-       MMRADIO_VOLUME_LOCK(radio);
-       if (radio->max_media_volume != 0)
-               total_volume = ((float)radio->media_volume / (float)radio->max_media_volume) * radio->local_volume;
-       else
-               MMRADIO_LOG_WARNING("max media voulme is zero");
-
-       ret = radio_hal_set_volume(radio->hal_inf, total_volume);
-       if (ret != MM_ERROR_NONE)
-               MMRADIO_LOG_ERROR("radio_hal_set_volume error");
-
-       MMRADIO_VOLUME_UNLOCK(radio);
-       return ret;
-
-}
-
 static void __mmradio_volume_changed_cb(volume_type_t type, unsigned int volume, void *user_data)
 {
        mm_radio_t *radio = (mm_radio_t *)user_data;
+       int ret = MM_ERROR_NONE;
        MMRADIO_CHECK_INSTANCE_RETURN_VOID(radio);
        if (type == VOLUME_TYPE_MEDIA) {
                MMRADIO_LOG_DEBUG("Change FM Radio volume to %d", volume);
-               MMRADIO_VOLUME_LOCK(radio);
-               radio->media_volume = volume;
-               MMRADIO_VOLUME_UNLOCK(radio);
-               __mmradio_set_total_volume(radio);
+               ret = __mmradio_set_media_volume(radio, volume);
+               if (ret != MM_ERROR_NONE)
+                       MMRADIO_LOG_ERROR("__mmradio_set_media_volume error");
+               return;
        }
 }
 
@@ -1534,17 +1507,18 @@ int _mmradio_set_volume(mm_radio_t *radio, float volume)
        radio->local_volume = volume;
        MMRADIO_VOLUME_UNLOCK(radio);
 
-       ret = __mmradio_set_total_volume(radio);
+       ret = radio_hal_set_volume(radio->hal_inf, volume);
+       if (ret != MM_ERROR_NONE)
+               MMRADIO_LOG_ERROR("radio_hal_set_volume error");
 
        MMRADIO_LOG_FLEAVE();
-       return ret;
 
+       return ret;
 }
 
 int _mmradio_get_volume(mm_radio_t *radio, float *pVolume)
 {
        int ret = MM_ERROR_NONE;
-       float total_volume = 0.0;
        float volume = 0.0;
        MMRADIO_LOG_FENTER();
 
@@ -1553,7 +1527,7 @@ int _mmradio_get_volume(mm_radio_t *radio, float *pVolume)
 
        return_val_if_fail(pVolume, MM_ERROR_INVALID_ARGUMENT);
 
-       ret = radio_hal_get_volume(radio->hal_inf, &total_volume);
+       ret = radio_hal_get_volume(radio->hal_inf, &volume);
        if (ret != MM_ERROR_NONE) {
                MMRADIO_LOG_ERROR("radio_hal_get_volume error");
                *pVolume = 0;
@@ -1561,20 +1535,34 @@ int _mmradio_get_volume(mm_radio_t *radio, float *pVolume)
        }
 
        MMRADIO_VOLUME_LOCK(radio);
+       radio->local_volume = volume;
+       *pVolume = (float)radio->local_volume;
+       MMRADIO_VOLUME_UNLOCK(radio);
 
-       if (radio->media_volume)
-               volume = total_volume * ((float)radio->max_media_volume / (float)radio->media_volume);
+       MMRADIO_LOG_FLEAVE();
 
-       MMRADIO_LOG_DEBUG("total_volume = %f, max_media_volue = %d, media_volume = %d, volume = %f",
-               total_volume, radio->max_media_volume, radio->media_volume, volume);
+       return ret;
+}
 
-       /* update volume in handle */
-       if (fabs(radio->local_volume - volume) >= FLT_EPSILON)
-               radio->local_volume = volume;
+static int __mmradio_set_media_volume(mm_radio_t *radio, unsigned int level)
+{
+       int ret = MM_ERROR_NONE;
 
-       *pVolume = (float)radio->local_volume;
+       MMRADIO_LOG_FENTER();
+
+       MMRADIO_CHECK_INSTANCE(radio);
+       MMRADIO_CHECK_STATE_RETURN_IF_FAIL(radio, MMRADIO_COMMAND_SET_VOLUME);
+
+       MMRADIO_LOG_DEBUG("Setting %d volume\n", level);
+
+       MMRADIO_VOLUME_LOCK(radio);
+       radio->media_volume = level;
        MMRADIO_VOLUME_UNLOCK(radio);
 
+       ret = radio_hal_set_media_volume(radio->hal_inf, level);
+       if (ret != MM_ERROR_NONE)
+               MMRADIO_LOG_ERROR("radio_hal_set_media_volume error");
+
        MMRADIO_LOG_FLEAVE();
 
        return ret;
index 8fb5cdd..e40d401 100644 (file)
@@ -111,6 +111,7 @@ int radio_hal_interface_init(mm_radio_hal_interface **handle)
                h->intf.get_signal_strength = dlsym(h->dl_handle, "radio_get_signal_strength");
                h->intf.get_volume = dlsym(h->dl_handle, "radio_get_volume");
                h->intf.set_volume = dlsym(h->dl_handle, "radio_set_volume");
+               h->intf.set_media_volume = dlsym(h->dl_handle, "radio_set_media_volume");
 
                if (h->intf.init == NULL || h->intf.deinit == NULL) {
                        MMRADIO_LOG_ERROR("could not get mandatory funtion");
@@ -126,7 +127,8 @@ int radio_hal_interface_init(mm_radio_hal_interface **handle)
                }
        } else {
                MMRADIO_LOG_ERROR("open radio hal_interface failed : %s", dlerror());
-               return MM_ERROR_RADIO_INTERNAL;
+               ret = MM_ERROR_RADIO_INTERNAL;
+               goto FAIL;
        }
 
        *handle = h;
@@ -381,6 +383,20 @@ int radio_hal_get_volume(mm_radio_hal_interface *radio_handle, float *volume)
 
 }
 
+int radio_hal_set_media_volume(mm_radio_hal_interface *radio_handle, uint32_t level)
+{
+       radio_error_t ret = RADIO_ERROR_NONE;
+       MMRADIO_CHECK_ARG(radio_handle);
+       if (radio_handle->intf.set_media_volume) {
+               ret = radio_handle->intf.set_media_volume(radio_handle->rh_handle, level);
+               if (ret != RADIO_ERROR_NONE)
+                       return __convert_error_code(ret, (char *)__FUNCTION__);
+       } else {
+               MMRADIO_LOG_WARNING("radio_hal set_media_volume is NULL");
+               return MM_ERROR_NOT_SUPPORT_API;
+       }
+       return MM_ERROR_NONE;
+}
 
 #ifdef __cplusplus
 }