[0.6.56] add about adaptive streaming variant control 48/137548/2 accepted/tizen/unified/20170710.154324 submit/tizen/20170707.065345
authorEunhae Choi <eunhae1.choi@samsung.com>
Thu, 6 Jul 2017 09:19:58 +0000 (18:19 +0900)
committerEunhae Choi <eunhae1.choi@samsung.com>
Thu, 6 Jul 2017 09:22:29 +0000 (18:22 +0900)
- handle the element msg to share the adaptive streaming
  variant information
- add set/get max variant limit path of adaptivedemux

Change-Id: Iaf96dd345df0a51faf1cc4eb32ec2ff87ed74f1f

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

index 4e04055a9e4d2780771dd17ffd316652a6cd912d..4cb597433b3aeda8c776d92960400b41b72d997e 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-player
 Summary:    Multimedia Framework Player Library
-Version:    0.6.55
+Version:    0.6.56
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
index 787b42defbe03eb69082c29f336240a810f502c2..7c3944f0bb8025ae124bd14bd0bb12739ef79dba 100644 (file)
@@ -2342,6 +2342,12 @@ int mm_player_set_sound_stream_info(MMHandleType player, char *stream_type, int
  */
 int mm_player_manage_external_storage_state(MMHandleType player, int state);
 
+int mm_player_get_adaptive_variant_info(MMHandleType player, int *num, char **var_info);
+
+int mm_player_set_max_adaptive_variant_limit(MMHandleType player, int bandwidth, int width, int height);
+
+int mm_player_get_max_adaptive_variant_limit(MMHandleType player, int *bandwidth, int *width, int *height);
+
 /**
        @}
  */
index 3204604d39f3f599a4480ea9d4fceb8ef13a5707..62a06ba8099e2bebb9d5bb4cb3076538192dcba4 100644 (file)
@@ -187,6 +187,7 @@ enum MainElementID {
        MMPLAYER_M_MUXED_S_BUFFER,
        MMPLAYER_M_DEMUXED_S_BUFFER,
        MMPLAYER_M_ID3DEMUX,
+       MMPLAYER_M_ADAPTIVE_DEMUX,
 
        /* es buff src queue */
        MMPLAYER_M_V_BUFFER,
@@ -449,6 +450,17 @@ typedef struct {
        void* bo;
 } mm_player_video_bo_info_t;
 
+typedef struct {
+       gint bandwidth;
+       gint width;
+       gint height;
+} VariantData;
+
+typedef struct {
+       GList* var_list;
+       VariantData limit;
+} MMAdaptiveVariantInfo;
+
 typedef struct {
        /* STATE */
        int state;                                      // player current state
@@ -760,6 +772,8 @@ typedef struct {
 
        int pcm_samplerate;
        int pcm_channel;
+
+       MMAdaptiveVariantInfo adaptive_info;
 } mm_player_t;
 
 typedef struct {
@@ -887,6 +901,9 @@ int _mmplayer_sound_register_with_pid(MMHandleType hplayer, int pid);
 int _mmplayer_get_client_pid(MMHandleType hplayer, int* pid);
 int __mmplayer_get_video_angle(mm_player_t* player, int *user_angle, int *org_angle);
 int _mmplayer_video_stream_release_bo(mm_player_t* player, void* bo);
+int _mmplayer_get_adaptive_variant_info(MMHandleType hplayer, int *num, char **var_info);
+int _mmplayer_set_max_adaptive_variant_limit(MMHandleType hplayer, int bandwidth, int width, int height);
+int _mmplayer_get_max_adaptive_variant_limit(MMHandleType hplayer, int *bandwidth, int *width, int *height);
 
 #ifdef __cplusplus
        }
index dcac88c37725149ae3d2118580bce8f4fc06107a..f648d6796d350502aa8c888ae53e2a63152a4d8a 100644 (file)
@@ -1338,3 +1338,50 @@ int mm_player_manage_external_storage_state(MMHandleType player, int state)
 
        return result;
 }
+
+int mm_player_get_adaptive_variant_info(MMHandleType player, int *num, char **var_info)
+{
+       int result = MM_ERROR_NONE;
+
+       MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+       MMPLAYER_RETURN_VAL_IF_FAIL(num && var_info, MM_ERROR_COMMON_INVALID_ARGUMENT);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_get_adaptive_variant_info(player, num, var_info);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+
+int mm_player_set_max_adaptive_variant_limit(MMHandleType player, int bandwidth, int width, int height)
+{
+       int result = MM_ERROR_NONE;
+
+       MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_set_max_adaptive_variant_limit(player, bandwidth, width, height);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+
+int mm_player_get_max_adaptive_variant_limit(MMHandleType player, int *bandwidth, int *width, int *height)
+{
+       int result = MM_ERROR_NONE;
+
+       MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+       MMPLAYER_RETURN_VAL_IF_FAIL(bandwidth && width && height, MM_ERROR_COMMON_INVALID_ARGUMENT);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_get_max_adaptive_variant_limit(player, bandwidth, width, height);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
index 1e8ebe2b8670ac211c6c4f4663d84bbc31012e60..af55e5f9d6c1e3daed542b3225d790a981627619 100644 (file)
 
 #define PLAYER_DISPLAY_MODE_DST_ROI            5
 
+#define ADAPTIVE_VARIANT_DEFAULT_VALUE -1 /* auto */
+
 /*---------------------------------------------------------------------------
 |    LOCAL CONSTANT DEFINITIONS:                                                                                       |
 ---------------------------------------------------------------------------*/
@@ -1100,6 +1102,20 @@ __mmplayer_drop_subtitle(mm_player_t* player, gboolean is_drop)
        }
 }
 
+static VariantData *
+__mmplayer_adaptive_var_info(const VariantData *self, gpointer user_data)
+{
+       VariantData *var_info = NULL;
+       g_return_val_if_fail (self != NULL, NULL);
+
+       var_info = g_new0(VariantData, 1);
+       if (!var_info) return NULL;
+       var_info->bandwidth = self->bandwidth;
+       var_info->width = self->width;
+       var_info->height = self->height;
+       return var_info;
+}
+
 static gboolean
 __mmplayer_gst_callback(GstBus *bus, GstMessage *msg, gpointer data) // @
 {
@@ -1519,7 +1535,7 @@ __mmplayer_gst_callback(GstBus *bus, GstMessage *msg, gpointer data) // @
        case GST_MESSAGE_ELEMENT:
                        {
                                const gchar *structure_name;
-                               gint count = 0;
+                               gint count = 0, idx = 0;
                                MMHandleType attrs = 0;
 
                                attrs = MMPLAYER_GET_ATTRS(player);
@@ -1536,6 +1552,35 @@ __mmplayer_gst_callback(GstBus *bus, GstMessage *msg, gpointer data) // @
                                if (!structure_name)
                                        break;
 
+                               LOGD("GST_MESSAGE_ELEMENT %s from %s", structure_name, GST_OBJECT_NAME(GST_MESSAGE_SRC(msg)));
+
+                               if (!strcmp(structure_name, "adaptive-streaming-variant")) {
+                                       const GValue *var_info = NULL;
+
+                                       var_info = gst_structure_get_value(gst_message_get_structure(msg), "video-variant-info");
+                                       if (var_info != NULL) {
+                                               if (player->adaptive_info.var_list)
+                                                       g_list_free_full(player->adaptive_info.var_list, g_free);
+
+                                               /* share addr or copy the list */
+                                               player->adaptive_info.var_list =
+                                                       g_list_copy_deep((GList *)g_value_get_pointer(var_info), (GCopyFunc)__mmplayer_adaptive_var_info, NULL);
+
+                                               count = g_list_length(player->adaptive_info.var_list);
+                                               if (count > 0) {
+                                                       VariantData *temp = NULL;
+
+                                                       /* print out for debug */
+                                                       LOGD("num of variant_info %d", count);
+                                                       for (idx = 0; idx < count; idx++) {
+                                                               temp = g_list_nth_data(player->adaptive_info.var_list, idx);
+                                                               if (temp)
+                                                                       LOGD("variant(%d) [b]%d [w]%d [h]%d ", idx, temp->bandwidth, temp->width, temp->height);
+                                                       }
+                                               }
+                                       }
+                               }
+
                                if (!strcmp(structure_name, "prepare-decode-buffers")) {
                                        gint num_buffers = 0;
                                        gint extra_num_buffers = 0;
@@ -8495,6 +8540,10 @@ _mmplayer_create_player(MMHandleType handle) // @
        else
                player->ini.set_dump_element_flag = TRUE;
 
+       player->adaptive_info.limit.bandwidth = ADAPTIVE_VARIANT_DEFAULT_VALUE;
+       player->adaptive_info.limit.width = ADAPTIVE_VARIANT_DEFAULT_VALUE;
+       player->adaptive_info.limit.height = ADAPTIVE_VARIANT_DEFAULT_VALUE;
+
        /* set player state to null */
        MMPLAYER_STATE_CHANGE_TIMEOUT(player) = player->ini.localplayback_state_change_timeout;
        MMPLAYER_SET_STATE(player, MM_PLAYER_STATE_NULL);
@@ -12009,7 +12058,19 @@ __mmplayer_gst_element_added(GstElement *bin, GstElement *element, gpointer data
                player->parsers = g_list_append(player->parsers, selected);
        }
 
-       if ((g_strrstr(klass, "Demux") || g_strrstr(klass, "Parse")) && !(g_strrstr(klass, "Adaptive"))) {
+       if (g_strrstr(klass, "Demuxer/Adaptive")) {
+               player->pipeline->mainbin[MMPLAYER_M_ADAPTIVE_DEMUX].id = MMPLAYER_M_ADAPTIVE_DEMUX;
+               player->pipeline->mainbin[MMPLAYER_M_ADAPTIVE_DEMUX].gst = element;
+
+               LOGD("set max variant limit: %d, %d %d", player->adaptive_info.limit.bandwidth,
+                                               player->adaptive_info.limit.width, player->adaptive_info.limit.height);
+
+               g_object_set(player->pipeline->mainbin[MMPLAYER_M_ADAPTIVE_DEMUX].gst,
+                                               "max-bandwidth", player->adaptive_info.limit.bandwidth,
+                                               "max-video-width", player->adaptive_info.limit.width,
+                                               "max-video-height", player->adaptive_info.limit.height, NULL);
+
+       } else if (g_strrstr(klass, "Demux") || g_strrstr(klass, "Parse")) {
                /* FIXIT : first value will be overwritten if there's more
                 * than 1 demuxer/parser
                 */
@@ -12224,6 +12285,15 @@ __mmplayer_release_misc(mm_player_t* player)
                player->state_tune_caps = NULL;
        }
 
+       if (player->adaptive_info.var_list) {
+               g_list_free_full(player->adaptive_info.var_list, g_free);
+               player->adaptive_info.var_list = NULL;
+       }
+
+       player->adaptive_info.limit.bandwidth = ADAPTIVE_VARIANT_DEFAULT_VALUE;
+       player->adaptive_info.limit.width = ADAPTIVE_VARIANT_DEFAULT_VALUE;
+       player->adaptive_info.limit.height = ADAPTIVE_VARIANT_DEFAULT_VALUE;
+
        MMPLAYER_FLEAVE();
 }
 
@@ -15187,3 +15257,90 @@ int _mmplayer_manage_external_storage_state(MMHandleType hplayer, int state)
        return ret;
 }
 
+int _mmplayer_get_adaptive_variant_info(MMHandleType hplayer, int *num, char **var_info)
+{
+       int ret = MM_ERROR_NONE;
+       mm_player_t* player = (mm_player_t*) hplayer;
+       int idx = 0, total = 0;
+       gchar *result = NULL, *tmp = NULL;
+
+       MMPLAYER_FENTER();
+       MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+       MMPLAYER_RETURN_VAL_IF_FAIL(num && var_info, MM_ERROR_COMMON_INVALID_ARGUMENT);
+
+       total = *num = g_list_length(player->adaptive_info.var_list);
+       if (total <= 0) {
+               LOGW("There is no stream variant info.");
+               return ret;
+       }
+
+       result = g_strdup ("");
+       for (idx = 0 ; idx < total ; idx++) {
+               VariantData *v_data = NULL;
+               v_data = g_list_nth_data(player->adaptive_info.var_list, idx);
+
+               if (v_data) {
+                       gchar data[64]={0};
+                       snprintf(data, sizeof(data), "%d,%d,%d,", v_data->bandwidth, v_data->width, v_data->height);
+
+                       tmp = g_strconcat (result, data, NULL);
+                       g_free (result);
+                       result = tmp;
+               } else {
+                       LOGW("There is no variant data in %d", idx);
+                       (*num)--;
+               }
+       }
+
+       *var_info = (char *)result;
+
+       LOGD("variant info %d:%s", *num, *var_info);
+       MMPLAYER_FLEAVE();
+       return ret;
+}
+
+int _mmplayer_set_max_adaptive_variant_limit(MMHandleType hplayer, int bandwidth, int width, int height)
+{
+       int ret = MM_ERROR_NONE;
+       mm_player_t* player = (mm_player_t*) hplayer;
+
+       MMPLAYER_FENTER();
+       MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       LOGD("set limit to [b]%d, [w]%d, [h]%d", bandwidth, width, height);
+
+       player->adaptive_info.limit.bandwidth = (bandwidth >= ADAPTIVE_VARIANT_DEFAULT_VALUE)?(bandwidth):(ADAPTIVE_VARIANT_DEFAULT_VALUE);
+       player->adaptive_info.limit.width = (width >= ADAPTIVE_VARIANT_DEFAULT_VALUE)?(width):(ADAPTIVE_VARIANT_DEFAULT_VALUE);
+       player->adaptive_info.limit.height = (height >= ADAPTIVE_VARIANT_DEFAULT_VALUE)?(height):(ADAPTIVE_VARIANT_DEFAULT_VALUE);
+
+       if (player->pipeline && player->pipeline->mainbin && player->pipeline->mainbin[MMPLAYER_M_ADAPTIVE_DEMUX].gst) {
+               LOGD("update max limit of %s", GST_ELEMENT_NAME(player->pipeline->mainbin[MMPLAYER_M_ADAPTIVE_DEMUX].gst));
+               g_object_set(player->pipeline->mainbin[MMPLAYER_M_ADAPTIVE_DEMUX].gst,
+                                               "max-bandwidth", bandwidth, "max-video-width", width, "max-video-height", height, NULL);
+
+               /* FIXME: seek to current position for applying new variant limitation */
+       }
+
+       MMPLAYER_FLEAVE();
+       return ret;
+
+}
+
+int _mmplayer_get_max_adaptive_variant_limit(MMHandleType hplayer, int *bandwidth, int *width, int *height)
+{
+       int ret = MM_ERROR_NONE;
+       mm_player_t* player = (mm_player_t*) hplayer;
+
+       MMPLAYER_FENTER();
+       MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+       MMPLAYER_RETURN_VAL_IF_FAIL(bandwidth && width && height, MM_ERROR_COMMON_INVALID_ARGUMENT);
+
+       *bandwidth = player->adaptive_info.limit.bandwidth;
+       *width = player->adaptive_info.limit.width;
+       *height = player->adaptive_info.limit.height;
+
+       LOGD("get limit to [b]%d, [w]%d, [h]%d", *bandwidth, *width, *height);
+
+       MMPLAYER_FLEAVE();
+       return ret;
+}