[0.6.173] support audio pitch control 28/201228/8
authorEunhye Choi <eunhae1.choi@samsung.com>
Mon, 11 Mar 2019 11:15:54 +0000 (20:15 +0900)
committerEunhye Choi <eunhae1.choi@samsung.com>
Thu, 14 Mar 2019 01:36:42 +0000 (10:36 +0900)
- add pitch element in audiobin
  if user enable the pitch control via API

Change-Id: I1f563ea00d2b036de00fa9702f55fbd0950df020

packaging/libmm-player.spec
src/include/mm_player.h
src/include/mm_player_priv.h
src/mm_player_attrs.c
src/mm_player_priv.c

index e80c2cc..10a31fc 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-player
 Summary:    Multimedia Framework Player Library
-Version:    0.6.172
+Version:    0.6.173
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
index e16c579..7a97387 100644 (file)
  */
 #define MM_PLAYER_AUDIO_OFFLOAD             "audio_offload"
 
+/**
+ * MM_PLAYER_PITCH_CONTROL (int)
+ */
+#define MM_PLAYER_PITCH_CONTROL             "pitch_control"
+
+/**
+ * MM_PLAYER_PITCH_VALUE (double)
+ */
+#define MM_PLAYER_PITCH_VALUE               "pitch_value"
+
+
 #define BUFFER_MAX_PLANE_NUM (4)
 
 typedef struct {
index 35d8f4c..beafbc0 100644 (file)
@@ -208,6 +208,8 @@ enum AudioElementID {
        MMPLAYER_A_RESAMPLER,
        MMPLAYER_A_DEINTERLEAVE,
        MMPLAYER_A_RGVOL,
+       MMPLAYER_A_CONV_PITCH,
+       MMPLAYER_A_PITCH,
        MMPLAYER_A_NUM
 };
 
index e8a1fea..f1c1691 100644 (file)
@@ -169,9 +169,27 @@ __mmplayer_apply_attribute(MMHandleType handle, const char *attribute_name)
        player = MM_PLAYER_CAST(handle);
        MMPlayerGstPipelineInfo *pipeline = player->pipeline;
 
+       /* before preparing, just keep the attr value */
+       MMPLAYER_RETURN_VAL_IF_FAIL(pipeline && pipeline->mainbin, MM_ERROR_NONE);
+
+       if (g_strrstr(attribute_name, MM_PLAYER_PITCH_VALUE)) {
+               int pitch_control = 0;
+               double pitch_value = 0;
+
+               mm_attrs_multiple_get(player->attrs, NULL,
+                                       MM_PLAYER_PITCH_CONTROL, &pitch_control,
+                                       MM_PLAYER_PITCH_VALUE, &pitch_value,
+                                       NULL);
+
+               if (!pitch_control || !pipeline->audiobin[MMPLAYER_A_PITCH].gst)
+                       return MM_ERROR_PLAYER_NO_OP;
+
+               LOGD("set pitch value to %1.3f", pitch_value);
+               g_object_set(pipeline->audiobin[MMPLAYER_A_PITCH].gst, "pitch", (gdouble)pitch_value, NULL);
+       }
+
        /* Currently, there are only display related implementation at below */
-       if (!pipeline ||
-               !pipeline->videobin ||
+       if (!pipeline->videobin ||
                !pipeline->videobin[MMPLAYER_V_SINK].gst) {
                /*
                 * The attribute should be committed even though videobin is not created yet.
@@ -745,6 +763,24 @@ _mmplayer_construct_attribute(MMHandleType handle)
                        FALSE,
                        TRUE
                },
+               {
+                       "pitch_control",        /* MM_PLAYER_PITCH_CONTROL */
+                       MM_ATTRS_TYPE_INT,
+                       MM_ATTRS_FLAG_RW,
+                       (void *)FALSE,
+                       MM_ATTRS_VALID_TYPE_INT_RANGE,
+                       FALSE,
+                       TRUE
+               },
+               {
+                       "pitch_value",          /* MM_PLAYER_PITCH_VALUE */
+                       MM_ATTRS_TYPE_DOUBLE,
+                       MM_ATTRS_FLAG_RW,
+                       (void *)1,
+                       MM_ATTRS_VALID_TYPE_DOUBLE_RANGE,
+                       0.5,
+                       2
+               },
        };
 
        num_of_attrs = ARRAY_SIZE(player_attrs);
index 72b4c9c..a4efccb 100644 (file)
@@ -2576,6 +2576,8 @@ __mmplayer_gst_fill_audio_bucket(mm_player_t *player, GList **bucket)
        GList *element_bucket = NULL;
        GstCaps *acaps = NULL;
        GstPad *sink_pad = NULL;
+       int pitch_control = 0;
+       double pitch_value = 1.0;
 
        MMPLAYER_FENTER();
        MMPLAYER_RETURN_VAL_IF_FAIL(player && player->pipeline &&
@@ -2592,6 +2594,31 @@ __mmplayer_gst_fill_audio_bucket(mm_player_t *player, GList **bucket)
                goto DONE;
        }
 
+       /* pitch */
+       mm_attrs_multiple_get(player->attrs, NULL,
+                               MM_PLAYER_PITCH_CONTROL, &pitch_control,
+                               MM_PLAYER_PITCH_VALUE, &pitch_value,
+                               NULL);
+
+       LOGD("pitch %d / %1.3f", pitch_control, pitch_value);
+       if (pitch_control && (player->videodec_linked == 0)) {
+               GstElementFactory *factory;
+
+               factory = gst_element_factory_find("pitch");
+               if (factory) {
+                       gst_object_unref(factory);
+
+                       /* converter */
+                       MMPLAYER_CREATE_ELEMENT(audiobin, MMPLAYER_A_CONV_PITCH, "audioconvert", "audio convert pitch", TRUE, player);
+
+                       /* pitch */
+                       MMPLAYER_CREATE_ELEMENT(audiobin, MMPLAYER_A_PITCH, "pitch", "audio pitch", TRUE, player);
+                       g_object_set(G_OBJECT(audiobin[MMPLAYER_A_PITCH].gst), "pitch", (gdouble)pitch_value, NULL);
+               } else {
+                       LOGW("there is no pitch element");
+               }
+       }
+
        /* converter */
        MMPLAYER_CREATE_ELEMENT(audiobin, MMPLAYER_A_CONV, "audioconvert", "audio converter", TRUE, player);