[ACR-1370] add new API to support audio pitch control 30/201230/11 accepted/tizen/unified/20190327.025134 submit/tizen/20190326.032955
authorEunhye Choi <eunhae1.choi@samsung.com>
Mon, 11 Mar 2019 11:20:45 +0000 (20:20 +0900)
committerEunhye Choi <eunhae1.choi@samsung.com>
Tue, 26 Mar 2019 02:16:15 +0000 (11:16 +0900)
Change-Id: I2300df2d26b9cb8fbd519bb391001f42d9e4ab8d

include/player.h
src/player.c
test/player_test.c

index 38e7426..b5c1e54 100644 (file)
@@ -2337,6 +2337,80 @@ int player_set_video_roi_area(player_h player, double x_scale, double y_scale, d
 int player_get_video_roi_area(player_h player, double *x_scale, double *y_scale, double *w_scale, double *h_scale);
 
 /**
+ * @brief Sets the audio pitch control status.
+ * @since_tizen 5.5
+ * @remarks This function is used for audio content only.
+ * @remarks Enabling pitch control could increase the CPU usage on some devices.
+ * @param[in] player   The handle to the media player
+ * @param[in] enabled  The new audio pitch control status (default: false)
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #PLAYER_ERROR_NONE Successful
+ * @retval #PLAYER_ERROR_INVALID_STATE Invalid player state
+ * @retval #PLAYER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PLAYER_ERROR_INVALID_OPERATION Invalid operation
+ * @pre The player state must be #PLAYER_STATE_IDLE.
+ * @see player_pitch_is_enabled()
+ * @see player_pitch_set_value()
+ * @see player_pitch_get_value()
+ */
+int player_pitch_set_enabled(player_h player, bool enabled);
+
+/**
+ * @brief Gets the audio pitch control status.
+ * @since_tizen 5.5
+ * @remarks This function is used for audio content only.
+ * @param[in]   player   The handle to the media player
+ * @param[out]  enabled  The audio pitch control status (default: false)
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #PLAYER_ERROR_NONE Successful
+ * @retval #PLAYER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PLAYER_ERROR_INVALID_OPERATION Invalid operation
+ * @see player_pitch_set_enabled()
+ * @see player_pitch_set_value()
+ * @see player_pitch_get_value()
+ */
+int player_pitch_is_enabled(player_h player, bool *enabled);
+
+/**
+ * @brief Sets the audio pitch value.
+ * @since_tizen 5.5
+ * @remarks This function is used for audio content only.
+ * @param[in] player The handle to the media player
+ * @param[in] value  The audio stream pitch value  \n
+ *                   Valid range is 0.5~2. Default value is 1.
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #PLAYER_ERROR_NONE Successful
+ * @retval #PLAYER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PLAYER_ERROR_INVALID_OPERATION Invalid operation
+ * @pre The pitch control must be enabled by calling player_pitch_set_enabled() function.
+ * @see player_pitch_set_enabled()
+ * @see player_pitch_is_enabled()
+ * @see player_pitch_get_value()
+ */
+int player_pitch_set_value(player_h player, float value);
+
+/**
+ * @brief Gets the audio pitch value.
+ * @since_tizen 5.5
+ * @remarks This function is used for audio content only.
+ * @param[in]  player The handle to the media player
+ * @param[out] value  The audio stream pitch value \n
+ *                    Valid range is 0.5~2. Default value is 1.
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #PLAYER_ERROR_NONE Successful
+ * @retval #PLAYER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PLAYER_ERROR_INVALID_OPERATION Invalid operation
+ * @see player_pitch_set_enabled()
+ * @see player_pitch_is_enabled()
+ * @see player_pitch_set_value()
+ */
+int player_pitch_get_value(player_h player, float *value);
+
+/**
  * @}
  */
 
index 7edc018..d642b61 100644 (file)
@@ -5009,7 +5009,6 @@ int player_360_get_zoom(player_h player, float *level)
 
        LOGD("LEAVE 0x%X", ret);
        return ret;
-
 }
 
 int player_360_set_field_of_view(player_h player, int horizontal_degrees, int vertical_degrees)
@@ -5140,3 +5139,89 @@ int player_is_replaygain_enabled(player_h player, bool *enabled)
        g_free(ret_buf);
        return ret;
 }
+
+int player_pitch_set_enabled(player_h player, bool enabled)
+{
+       PLAYER_INSTANCE_CHECK(player);
+       int ret = PLAYER_ERROR_NONE;
+       muse_player_api_e api = MUSE_PLAYER_API_PITCH_SET_ENABLED;
+       player_cli_s *pc = (player_cli_s *)player;
+       char *ret_buf = NULL;
+       int val = (int)enabled;
+
+       LOGD("ENTER");
+
+       PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "val", val);
+       g_free(ret_buf);
+       return ret;
+}
+
+int player_pitch_is_enabled(player_h player, bool *enabled)
+{
+       PLAYER_INSTANCE_CHECK(player);
+       PLAYER_NULL_ARG_CHECK(enabled);
+       int ret = PLAYER_ERROR_NONE;
+       muse_player_api_e api = MUSE_PLAYER_API_PITCH_IS_ENABLED;
+       player_cli_s *pc = (player_cli_s *)player;
+       char *ret_buf = NULL;
+       int val = -1;
+
+       LOGD("ENTER");
+
+       PLAYER_SEND_MSG(api, pc, ret_buf, ret);
+       if (ret == PLAYER_ERROR_NONE) {
+               player_msg_get(val, ret_buf);
+               *enabled = (bool)val;
+       }
+
+       g_free(ret_buf);
+       return ret;
+}
+
+int player_pitch_set_value(player_h player, float value)
+{
+       PLAYER_INSTANCE_CHECK(player);
+       PLAYER_CHECK_CONDITION(value >= 0.5 && value <= 2.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
+
+       int ret = PLAYER_ERROR_NONE;
+       muse_player_api_e api = MUSE_PLAYER_API_PITCH_SET_VALUE;
+       player_cli_s *pc = (player_cli_s *)player;
+       char *ret_buf = NULL;
+
+       LOGD("ENTER %1.3f", value);
+
+       PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_DOUBLE, "pitch", (double)value);
+       g_free(ret_buf);
+
+       LOGD("LEAVE 0x%X", ret);
+       return ret;
+}
+
+int player_pitch_get_value(player_h player, float *value)
+{
+       PLAYER_INSTANCE_CHECK(player);
+       PLAYER_NULL_ARG_CHECK(value);
+       int ret = PLAYER_ERROR_NONE;
+       muse_player_api_e api = MUSE_PLAYER_API_PITCH_GET_VALUE;
+       player_cli_s *pc = (player_cli_s *)player;
+       double pitch = 0.0;
+       char *ret_buf = NULL;
+
+       LOGD("ENTER");
+
+       PLAYER_SEND_MSG(api, pc, ret_buf, ret);
+
+       if (ret == PLAYER_ERROR_NONE) {
+               if (player_msg_get_type(pitch, ret_buf, DOUBLE)) {
+                       *value = (float)pitch;
+               } else {
+                       LOGE("failed to get pitch value");
+                       ret = PLAYER_ERROR_INVALID_OPERATION;
+               }
+       }
+
+       g_free(ret_buf);
+
+       LOGD("LEAVE 0x%X", ret);
+       return ret;
+}
index 5154081..b47048b 100644 (file)
@@ -172,6 +172,8 @@ enum {
        CURRENT_STATUS_VIDEO_CODEC_TYPE,
        CURRENT_STATUS_REPLAYGAIN_ENABLE,
        CURRENT_STATUS_AUDIO_OFFLOAD,
+       CURRENT_STATUS_PITCH_CONTROL,
+       CURRENT_STATUS_PITCH_VALUE,
 };
 
 #define MAX_HANDLE 20
@@ -1794,6 +1796,7 @@ static void input_subtitle_filename(char *subtitle_filename)
        strncpy(g_subtitle_uri, subtitle_filename, len);
        g_print("subtitle uri is set to %s\n", g_subtitle_uri);
        player_set_subtitle_path(g_player[0], g_subtitle_uri);
+       player_set_subtitle_updated_cb(g_player[0], subtitle_updated_cb, (void *)g_player[0]);
 }
 
 static void set_track(int type, int index)
@@ -2059,6 +2062,26 @@ static void set_audio_offload_enabled(bool enabled)
                g_print("failed to set audio offload\n");
 }
 
+static void pitch_set_enabled(bool enabled)
+{
+       bool is_enabled = false;
+       player_pitch_is_enabled(g_player[0], &is_enabled);
+
+       g_print("pitch enabled %d -> %d \n", is_enabled, enabled);
+       if (player_pitch_set_enabled(g_player[0], enabled) != PLAYER_ERROR_NONE)
+               g_print("failed to pitch_set_enabled\n");
+}
+
+static void pitch_set_value(float level)
+{
+       float curr = 0.0;
+       player_pitch_get_value(g_player[0], &curr);
+
+       g_print("pitch level %1.3f -> %1.3f \n", curr, level);
+       if (player_pitch_set_value(g_player[0], level) != PLAYER_ERROR_NONE)
+               g_print("failed to set pitch value\n");
+}
+
 #ifdef USE_EVENT_HANDLER
 static void event_handler_cb(enum libinput_event_type ev_t, int x, int y, void *data, float e[3])
 {
@@ -2280,6 +2303,10 @@ void _interpret_main_menu(char *cmd)
                        get_buffering_position();
                } else if (strncmp(cmd, "ol", 2) == 0) {
                        g_menu_state = CURRENT_STATUS_AUDIO_OFFLOAD;
+               } else if (strncmp(cmd, "pc", 2) == 0) {
+                       g_menu_state = CURRENT_STATUS_PITCH_CONTROL;
+               } else if (strncmp(cmd, "pv", 2) == 0) {
+                       g_menu_state = CURRENT_STATUS_PITCH_VALUE;
                } else {
                        g_print("unknown menu \n");
                }
@@ -2366,6 +2393,8 @@ void display_sub_basic()
        g_print("[Replaygain] rgs. Set Replaygain\t\t");
        g_print("rgg. Get replaygain\n");
        g_print("[Offload] ol. Set audio offload\n");
+       g_print("[pitch] pc. enable pitch control\t");
+       g_print("pv. Set pitch value\n");
        g_print("[etc] sp. Set Progressive Download\t");
        g_print("gp. Get Progressive Download status\t");
        g_print("mp. memory playback\n");
@@ -2459,6 +2488,10 @@ static void displaymenu()
                g_print("*** input replaygain value.(0:disable, 1: enable) \n");
        } else if (g_menu_state == CURRENT_STATUS_AUDIO_OFFLOAD) {
                g_print("*** input audio offload value.(0:disable, 1: enable) \n");
+       } else if (g_menu_state == CURRENT_STATUS_PITCH_CONTROL) {
+               g_print("*** input pitch control value.(0:disable, 1: enable) \n");
+       } else if (g_menu_state == CURRENT_STATUS_PITCH_VALUE) {
+               g_print("*** input pitch value.(0.5 ~ 2) \n");
        } else {
                g_print("*** unknown status.\n");
                quit_program();
@@ -2811,6 +2844,20 @@ static void interpret(char *cmd)
                        reset_menu_state();
                }
                break;
+       case CURRENT_STATUS_PITCH_CONTROL:
+               {
+                       value1 = atoi(cmd);
+                       pitch_set_enabled(value1);
+                       reset_menu_state();
+               }
+               break;
+       case CURRENT_STATUS_PITCH_VALUE:
+               {
+                       fval = atof(cmd);
+                       pitch_set_value(fval);
+                       reset_menu_state();
+               }
+               break;
        }
 
        g_timeout_add(100, timeout_menu_display, 0);