[0.6.289] Fix not-linked error during prepare
[platform/core/multimedia/libmm-player.git] / src / mm_player_priv.c
index b4d944a..1004e50 100644 (file)
@@ -43,7 +43,6 @@
 
 #include "mm_player_priv.h"
 #include "mm_player_ini.h"
-#include "mm_player_attrs.h"
 #include "mm_player_capture.h"
 #include "mm_player_utils.h"
 #include "mm_player_tracks.h"
@@ -84,7 +83,7 @@
 #define MM_VOLUME_FACTOR_MAX                   1.0
 
 /* Don't need to sleep for sound fadeout
- * fadeout related fucntion will be deleted(Deprecated)
+ * fadeout related function will be deleted(Deprecated)
  */
 #define MM_PLAYER_FADEOUT_TIME_DEFAULT 0
 
 #define DEFAULT_PCM_OUT_SAMPLERATE     44100
 #define DEFAULT_PCM_OUT_CHANNEL        2
 
+#define MQ_UNLINKED_CACHE_TIME         (500 * GST_MSECOND)
+
 /*---------------------------------------------------------------------------
 |    LOCAL CONSTANT DEFINITIONS:                                                                                       |
 ---------------------------------------------------------------------------*/
@@ -141,17 +142,10 @@ static int                __mmplayer_gst_create_text_pipeline(mmplayer_t *player);
 static int             __mmplayer_gst_create_video_sink_bin(mmplayer_t *player, GstCaps *caps, MMDisplaySurfaceType surface_type);
 static int             __mmplayer_gst_create_audio_sink_bin(mmplayer_t *player);
 static int             __mmplayer_gst_create_text_sink_bin(mmplayer_t *player);
-
-static void            __mmplayer_gst_decode_no_more_pads(GstElement *elem, gpointer data);
-static void            __mmplayer_gst_create_sinkbin(GstElement *decodebin, GstPad *pad, gpointer data);
-static void            __mmplayer_gst_decode_unknown_type(GstElement *elem,  GstPad *pad, GstCaps *caps, gpointer data);
-static gboolean __mmplayer_gst_decode_autoplug_continue(GstElement *bin,  GstPad *pad, GstCaps *caps,  gpointer data);
-static void __mmplayer_gst_decode_pad_removed(GstElement *elem,  GstPad *new_pad, gpointer data);
-static void __mmplayer_gst_decode_drained(GstElement *bin, gpointer data);
-static void    __mmplayer_pipeline_complete(GstElement *decodebin,  gpointer data);
+static void            __mmplayer_gst_create_sink_bin(GstElement *decodebin, GstPad *pad, GstCaps *ref_caps, gpointer data);
+static gboolean __mmplayer_create_sink_path(mmplayer_t *player, GstElement *combiner, mmplayer_track_type_e type, GstCaps *caps);
 static gboolean __mmplayer_is_midi_type(gchar *str_caps);
 static gboolean __mmplayer_is_only_mp3_type(gchar *str_caps);
-static void    __mmplayer_set_audio_attrs(mmplayer_t *player, GstCaps *caps);
 
 static gboolean        __mmplayer_update_subtitle(GstElement *object, GstBuffer *buffer, GstPad *pad, gpointer data);
 static void            __mmplayer_release_misc(mmplayer_t *player);
@@ -164,8 +158,7 @@ static int __mmplayer_change_selector_pad(mmplayer_t *player, mmplayer_track_typ
 
 static gboolean __mmplayer_check_subtitle(mmplayer_t *player);
 static int             __mmplayer_handle_missed_plugin(mmplayer_t *player);
-static int             __mmplayer_check_not_supported_codec(mmplayer_t *player, const gchar *factory_class, const gchar *mime);
-static void            __mmplayer_add_sink(mmplayer_t *player, GstElement *sink);
+static void            __mmplayer_add_sink(mmplayer_t *player, GstElement *sink, gboolean first);
 static void            __mmplayer_del_sink(mmplayer_t *player, GstElement *sink);
 static void            __mmplayer_release_signal_connection(mmplayer_t *player, mmplayer_signal_type_e type);
 static gpointer __mmplayer_gapless_play_thread(gpointer data);
@@ -179,8 +172,9 @@ static int          __mmplayer_gst_set_message_callback(mmplayer_t *player, MMMessageCal
 
 /* util */
 static gboolean __mmplayer_verify_gapless_play_path(mmplayer_t *player);
-static void __mmplayer_check_pipeline(mmplayer_t *player);
+static void __mmplayer_check_pipeline_reconfigure_state(mmplayer_t *player);
 static gboolean __mmplayer_deactivate_selector(mmplayer_t *player, mmplayer_track_type_e type);
+static gboolean __mmplayer_deactivate_combiner(mmplayer_t *player, mmplayer_track_type_e type);
 static void __mmplayer_deactivate_old_path(mmplayer_t *player);
 static int __mmplayer_gst_create_plain_text_elements(mmplayer_t *player);
 static guint32 _mmplayer_convert_fourcc_string_to_value(const gchar *format_name);
@@ -203,6 +197,7 @@ static gboolean __mmplayer_swcodec_set_bo(mmplayer_t *player, mmplayer_video_dec
 
 static void __mmplayer_set_pause_state(mmplayer_t *player);
 static void __mmplayer_set_playing_state(mmplayer_t *player);
+static int __mmplayer_switch_stream(mmplayer_t *player, mmplayer_track_type_e type, int index);
 /*===========================================================================================
 |                                                                                                                                                                                      |
 |  FUNCTION DEFINITIONS                                                                                                                                                |
@@ -317,7 +312,7 @@ _mmplayer_get_stream_service_type(mmplayer_t *player)
 }
 
 /* this function sets the player state and also report
- * it to applicaton by calling callback function
+ * it to application by calling callback function
  */
 void
 _mmplayer_set_state(mmplayer_t *player, int state)
@@ -397,7 +392,7 @@ _mmplayer_check_state(mmplayer_t *player, mmplayer_command_state_e command)
 
        MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 #ifdef __DEBUG__
-       LOGD("incomming command : %d ", command);
+       LOGD("incoming command : %d ", command);
 #endif
        current_state = MMPLAYER_CURRENT_STATE(player);
        pending_state = MMPLAYER_PENDING_STATE(player);
@@ -498,7 +493,7 @@ _mmplayer_check_state(mmplayer_t *player, mmplayer_command_state_e command)
                if (pending_state == MM_PLAYER_STATE_NONE) {
                        if (current_state == MM_PLAYER_STATE_PAUSED)
                                goto NO_OP;
-                       else if (current_state != MM_PLAYER_STATE_PLAYING && current_state != MM_PLAYER_STATE_READY) // support loading state of broswer
+                       else if (current_state != MM_PLAYER_STATE_PLAYING && current_state != MM_PLAYER_STATE_READY) // support loading state of browser
                                goto INVALID_STATE;
                } else if (pending_state == MM_PLAYER_STATE_PAUSED) {
                        goto ALREADY_GOING;
@@ -558,7 +553,7 @@ ALREADY_GOING:
        return MM_ERROR_PLAYER_NO_OP;
 }
 
-static int __mmplayer_acquire_hw_resource(mmplayer_t *player, mmplayer_resource_type_e type)
+int _mmplayer_acquire_hw_resource(mmplayer_t *player, mmplayer_resource_type_e type)
 {
        int rm_ret = MM_RESOURCE_MANAGER_ERROR_NONE;
        mm_resource_manager_res_type_e rm_res_type = MM_RESOURCE_MANAGER_RES_TYPE_MAX;
@@ -591,6 +586,7 @@ static int __mmplayer_acquire_hw_resource(mmplayer_t *player, mmplayer_resource_
                return MM_ERROR_PLAYER_INTERNAL;
        }
 
+       LOGD("commit [%d type] resource", type);
        rm_ret = mm_resource_manager_commit(player->resource_manager);
        if (rm_ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
                LOGE("failed to commit of resource, ret(0x%x)", rm_ret);
@@ -601,6 +597,36 @@ static int __mmplayer_acquire_hw_resource(mmplayer_t *player, mmplayer_resource_
        return MM_ERROR_NONE;
 }
 
+static void __mmplayer_destroy_hw_resource(mmplayer_t *player)
+{
+       int rm_ret = MM_RESOURCE_MANAGER_ERROR_NONE;
+
+       MMPLAYER_RETURN_IF_FAIL(player);
+       MMPLAYER_RETURN_IF_FAIL(player->resource_manager);
+
+       rm_ret = mm_resource_manager_mark_all_for_release(player->resource_manager);
+       if (rm_ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
+               LOGW("failed to mark all for release of resource, ret(0x%x)", rm_ret);
+               goto rm_destroy;
+       }
+
+       rm_ret = mm_resource_manager_commit(player->resource_manager);
+       if (rm_ret != MM_RESOURCE_MANAGER_ERROR_NONE)
+               LOGW("failed to commit resource, ret(0x%x)", rm_ret);
+
+rm_destroy:
+       /* de-initialize resource manager */
+       rm_ret = mm_resource_manager_destroy(player->resource_manager);
+       if (rm_ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
+               LOGW("failed to destroy resource manager, ret(0x%x)", rm_ret);
+               return;
+       }
+
+       player->resource_manager = NULL;
+
+       LOGD("resource manager is destroyed");
+}
+
 static int __mmplayer_release_hw_resource(mmplayer_t *player, mmplayer_resource_type_e type)
 {
        int rm_ret = MM_RESOURCE_MANAGER_ERROR_NONE;
@@ -621,9 +647,10 @@ static int __mmplayer_release_hw_resource(mmplayer_t *player, mmplayer_resource_
 
        player->hw_resource[type] = NULL;
 
+       LOGD("commit [%d type] resource", type);
        rm_ret = mm_resource_manager_commit(player->resource_manager);
        if (rm_ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
-               LOGE("failed to commit of resource, ret(0x%x)", rm_ret);
+               LOGE("failed to commit resource, ret(0x%x)", rm_ret);
                return MM_ERROR_PLAYER_INTERNAL;
        }
 
@@ -677,12 +704,7 @@ __mmplayer_initialize_gapless_play(mmplayer_t *player)
 
        /* clean found audio decoders */
        if (player->audio_decoders) {
-               GList *a_dec = player->audio_decoders;
-               for (; a_dec; a_dec = g_list_next(a_dec)) {
-                       gchar *name = a_dec->data;
-                       MMPLAYER_FREEIF(name);
-               }
-               g_list_free(player->audio_decoders);
+               g_list_free_full(player->audio_decoders, (GDestroyNotify)g_free);
                player->audio_decoders = NULL;
        }
 
@@ -691,6 +713,16 @@ __mmplayer_initialize_gapless_play(mmplayer_t *player)
        MMPLAYER_FLEAVE();
 }
 
+void _mmplayer_set_reconfigure_state(mmplayer_t *player, gboolean state)
+{
+       LOGI("set pipeline reconfigure state %d", state);
+       MMPLAYER_RECONFIGURE_LOCK(player);
+       player->gapless.reconfigure = state;
+       if (!state) /* wake up the waiting job */
+               MMPLAYER_RECONFIGURE_SIGNAL(player);
+       MMPLAYER_RECONFIGURE_UNLOCK(player);
+}
+
 static gpointer
 __mmplayer_gapless_play_thread(gpointer data)
 {
@@ -707,21 +739,23 @@ __mmplayer_gapless_play_thread(gpointer data)
                LOGD("reconfigure pipeline for gapless play.");
 
                if (player->gapless_play_thread_exit) {
-                       if (player->gapless.reconfigure) {
-                               player->gapless.reconfigure = false;
-                               MMPLAYER_PLAYBACK_UNLOCK(player);
-                       }
+                       _mmplayer_set_reconfigure_state(player, FALSE);
                        LOGD("exiting gapless play thread");
                        break;
                }
 
                mainbin = player->pipeline->mainbin;
 
-               MMPLAYER_RELEASE_ELEMENT(player, mainbin, MMPLAYER_M_MUXED_S_BUFFER);
-               MMPLAYER_RELEASE_ELEMENT(player, mainbin, MMPLAYER_M_ID3DEMUX);
-               MMPLAYER_RELEASE_ELEMENT(player, mainbin, MMPLAYER_M_AUTOPLUG);
-               MMPLAYER_RELEASE_ELEMENT(player, mainbin, MMPLAYER_M_TYPEFIND);
-               MMPLAYER_RELEASE_ELEMENT(player, mainbin, MMPLAYER_M_SRC);
+               if (MMPLAYER_USE_DECODEBIN(player)) {
+                       MMPLAYER_RELEASE_ELEMENT(player, mainbin, MMPLAYER_M_MUXED_S_BUFFER);
+                       MMPLAYER_RELEASE_ELEMENT(player, mainbin, MMPLAYER_M_AUTOPLUG); /* decodebin */
+                       MMPLAYER_RELEASE_ELEMENT(player, mainbin, MMPLAYER_M_TYPEFIND);
+                       MMPLAYER_RELEASE_ELEMENT(player, mainbin, MMPLAYER_M_SRC);
+               } else {
+                       MMPLAYER_RELEASE_ELEMENT(player, mainbin, MMPLAYER_M_AUTOPLUG); /* uridecodebin */
+                       mainbin[MMPLAYER_M_MUXED_S_BUFFER].gst = NULL;
+                       mainbin[MMPLAYER_M_SRC].gst = NULL;
+               }
 
                /* Initialize Player values */
                __mmplayer_initialize_gapless_play(player);
@@ -750,6 +784,46 @@ __mmplayer_remove_g_source_from_context(GMainContext *context, guint source_id)
 }
 
 void
+_mmplayer_watcher_removed_notify(gpointer data)
+{
+       mmplayer_t *player = (mmplayer_t *)data;
+       MMPLAYER_RETURN_IF_FAIL(player);
+
+       MMPLAYER_BUS_WATCHER_LOCK(player);
+       player->bus_watcher = 0;
+       MMPLAYER_BUS_WATCHER_SIGNAL(player);
+       MMPLAYER_BUS_WATCHER_UNLOCK(player);
+}
+
+void
+_mmplayer_bus_watcher_remove(MMHandleType hplayer)
+{
+       mmplayer_t *player = (mmplayer_t *)hplayer;
+       gint64 end_time = 0;
+       MMPLAYER_FENTER();
+       MMPLAYER_RETURN_IF_FAIL(player);
+
+       /* disconnecting bus watch */
+       if (player->bus_watcher > 0) {
+               __mmplayer_remove_g_source_from_context(player->context.thread_default, player->bus_watcher);
+               MMPLAYER_BUS_WATCHER_LOCK(player);
+               end_time = g_get_monotonic_time () + 2 * G_TIME_SPAN_SECOND;
+               while (player->bus_watcher > 0) {
+                       if (!MMPLAYER_BUS_WATCHER_WAIT_UNTIL(player, end_time)) {
+                               LOGW("MMPLAYER_BUS_WATCHER_WAIT_UNTIL() timeout has passed - bus_watcher (%d)",
+                                               player->bus_watcher);
+                               break;
+                       }
+               }
+               MMPLAYER_BUS_WATCHER_UNLOCK(player);
+               g_mutex_clear(&player->bus_watcher_mutex);
+               g_cond_clear(&player->bus_watcher_cond);
+       }
+
+       MMPLAYER_FLEAVE();
+}
+
+void
 _mmplayer_bus_msg_thread_destroy(MMHandleType hplayer)
 {
        mmplayer_t *player = (mmplayer_t *)hplayer;
@@ -759,11 +833,6 @@ _mmplayer_bus_msg_thread_destroy(MMHandleType hplayer)
        MMPLAYER_FENTER();
        MMPLAYER_RETURN_IF_FAIL(player);
 
-       /* disconnecting bus watch */
-       if (player->bus_watcher)
-               __mmplayer_remove_g_source_from_context(player->context.thread_default, player->bus_watcher);
-       player->bus_watcher = 0;
-
        /* destroy the gst bus msg thread */
        if (player->bus_msg_thread) {
                MMPLAYER_BUS_MSG_THREAD_LOCK(player);
@@ -816,7 +885,7 @@ _mmplayer_gst_remove_fakesink(mmplayer_t *player, mmplayer_gst_element_t *fakesi
        gst_element_set_locked_state(fakesink->gst, TRUE);
 
        /* setting the state to NULL never returns async
-        * so no need to wait for completion of state transiton
+        * so no need to wait for completion of state transition
         */
        if (GST_STATE_CHANGE_FAILURE == gst_element_set_state(fakesink->gst, GST_STATE_NULL))
                LOGE("fakesink state change failure!");
@@ -850,7 +919,7 @@ ERROR:
 }
 
 static GstPadProbeReturn
-__mmplayer_gst_selector_blocked(GstPad *pad, GstPadProbeInfo *info, gpointer data)
+__mmplayer_gst_combiner_blocked(GstPad *pad, GstPadProbeInfo *info, gpointer data)
 {
        LOGD("pad(%s:%s) is blocked", GST_DEBUG_PAD_NAME(pad));
        return GST_PAD_PROBE_OK;
@@ -866,7 +935,7 @@ __mmplayer_gst_selector_update_start_time(mmplayer_t *player, mmplayer_track_typ
 
        for (idx = MM_PLAYER_TRACK_TYPE_AUDIO; idx < MM_PLAYER_TRACK_TYPE_TEXT; idx++) {
                if ((player->gapless.update_segment[idx] == TRUE) ||
-                       !(player->selector[idx].event_probe_id)) {
+                       !(player->track[idx].event_probe_id)) {
 #ifdef __DEBUG__
                        LOGW("[%d] skip", idx);
 #endif
@@ -919,7 +988,7 @@ __mmplayer_gst_selector_update_start_time(mmplayer_t *player, mmplayer_track_typ
 }
 
 static GstPadProbeReturn
-__mmplayer_gst_selector_event_probe(GstPad *pad, GstPadProbeInfo *info, gpointer data)
+__mmplayer_gst_combiner_event_probe(GstPad *pad, GstPadProbeInfo *info, gpointer data)
 {
        GstPadProbeReturn ret = GST_PAD_PROBE_OK;
        GstEvent *event = GST_PAD_PROBE_INFO_DATA(info);
@@ -937,8 +1006,24 @@ __mmplayer_gst_selector_event_probe(GstPad *pad, GstPadProbeInfo *info, gpointer
                GST_EVENT_TYPE(event) != GST_EVENT_QOS)
                return ret;
 
-       MMPLAYER_GST_GET_CAPS_INFO(pad, caps, str, name, caps_ret);
-       if (!caps_ret)
+       MMPLAYER_GST_GET_CAPS_INFO_FROM_PAD(pad, caps, str, name, caps_ret);
+       if (!caps_ret) {
+               GstStream *stream = NULL;
+
+               if (GST_EVENT_TYPE(event) != GST_EVENT_STREAM_START)
+                       goto ERROR;
+
+               gst_event_parse_stream (event, &stream);
+               if (stream == NULL) {
+                       LOGW ("Got a STREAM_START event without a GstStream");
+                       goto ERROR;
+               }
+
+               name = gst_stream_type_get_name(gst_stream_get_stream_type(stream));
+               gst_object_unref (stream);
+       }
+
+       if (!name)
                goto ERROR;
 
        if (strstr(name, "audio")) {
@@ -1064,7 +1149,7 @@ ERROR:
        return ret;
 }
 
-/* create fakesink for audio or video path witout audiobin or videobin */
+/* create fakesink for audio or video path without audiobin or videobin */
 static void
 __mmplayer_gst_make_fakesink(mmplayer_t *player, GstPad *pad, const gchar *name)
 {
@@ -1081,13 +1166,13 @@ __mmplayer_gst_make_fakesink(mmplayer_t *player, GstPad *pad, const gchar *name)
        fakesink = gst_element_factory_make("fakesink", NULL);
        if (fakesink == NULL) {
                LOGE("failed to create fakesink");
-               goto EXIT;
+               return;
        }
 
-       /* store it as it's sink element */
-       __mmplayer_add_sink(player, fakesink);
-
-       gst_bin_add(GST_BIN(pipeline), fakesink);
+       if (!gst_bin_add(GST_BIN(pipeline), fakesink)) {
+               LOGE("failed to add fakesink to pipeline");
+               goto ERROR;
+       }
 
        /* link */
        sinkpad = gst_element_get_static_pad(fakesink, "sink");
@@ -1096,8 +1181,7 @@ __mmplayer_gst_make_fakesink(mmplayer_t *player, GstPad *pad, const gchar *name)
 
        if (gst_pad_link(pad, sinkpad) != GST_PAD_LINK_OK) {
                LOGE("failed to link fakesink");
-               gst_object_unref(GST_OBJECT(fakesink));
-               goto EXIT;
+               goto ERROR;
        }
 
        if (strstr(name, "video")) {
@@ -1112,12 +1196,71 @@ __mmplayer_gst_make_fakesink(mmplayer_t *player, GstPad *pad, const gchar *name)
        g_object_set(G_OBJECT(fakesink), "sync", TRUE, NULL);
        gst_element_set_state(fakesink, GST_STATE_PAUSED);
 
-EXIT:
+       /* store it as it's sink element */
+       __mmplayer_add_sink(player, fakesink, FALSE);
+
        if (sinkpad)
                gst_object_unref(GST_OBJECT(sinkpad));
 
        MMPLAYER_FLEAVE();
        return;
+
+ERROR:
+
+       if (sinkpad)
+               gst_object_unref(GST_OBJECT(sinkpad));
+
+       if (fakesink) {
+               gst_element_set_state(fakesink, GST_STATE_NULL);
+
+               if (!gst_bin_remove(GST_BIN(pipeline), fakesink))
+                       gst_object_unref(GST_OBJECT(fakesink));
+       }
+
+       return;
+}
+
+static GstElement *
+__mmplayer_gst_make_concat(mmplayer_t *player, main_element_id_e elem_idx, mmplayer_track_type_e stream_type)
+{
+       GstElement *pipeline = NULL;
+       g_autoptr(GstElement) concat = NULL;
+       g_autoptr(GstPad) srcpad = NULL;
+
+       MMPLAYER_FENTER();
+       MMPLAYER_RETURN_VAL_IF_FAIL(player && player->pipeline && player->pipeline->mainbin, NULL);
+
+       concat = gst_element_factory_make("concat", NULL);
+       if (!concat) {
+               LOGE("failed to create concat");
+               return NULL;
+       }
+
+       srcpad = gst_element_get_static_pad(concat, "src");
+
+       LOGD("blocking %s:%s", GST_DEBUG_PAD_NAME(srcpad));
+       player->track[stream_type].block_id = gst_pad_add_probe(srcpad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM,
+                       __mmplayer_gst_combiner_blocked, NULL, NULL);
+       player->track[stream_type].event_probe_id = gst_pad_add_probe(srcpad, GST_PAD_PROBE_TYPE_EVENT_BOTH|GST_PAD_PROBE_TYPE_EVENT_FLUSH,
+                       __mmplayer_gst_combiner_event_probe, player, NULL);
+
+
+       gst_element_set_state(concat, GST_STATE_PAUSED);
+
+       pipeline = player->pipeline->mainbin[MMPLAYER_M_PIPE].gst;
+       if (!gst_bin_add(GST_BIN(pipeline), concat)) {
+               LOGE("failed to add concat to pipeline");
+               gst_element_set_state(concat, GST_STATE_NULL);
+               return NULL;
+       }
+
+       LOGD("Create concat [%d] element", elem_idx);
+
+       player->pipeline->mainbin[elem_idx].id = elem_idx;
+       player->pipeline->mainbin[elem_idx].gst = concat;
+
+       MMPLAYER_FLEAVE();
+       return g_steal_pointer(&concat);
 }
 
 static GstElement *
@@ -1137,26 +1280,40 @@ __mmplayer_gst_make_selector(mmplayer_t *player, main_element_id_e elem_idx, mmp
        }
        g_object_set(selector, "sync-streams", TRUE, NULL);
 
-       player->pipeline->mainbin[elem_idx].id = elem_idx;
-       player->pipeline->mainbin[elem_idx].gst = selector;
-
-       /* player->selector[stream_type].active_pad_index = DEFAULT_TRACK; */
-
        srcpad = gst_element_get_static_pad(selector, "src");
 
        LOGD("blocking %s:%s", GST_DEBUG_PAD_NAME(srcpad));
-       player->selector[stream_type].block_id = gst_pad_add_probe(srcpad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM,
-               __mmplayer_gst_selector_blocked, NULL, NULL);
-       player->selector[stream_type].event_probe_id = gst_pad_add_probe(srcpad, GST_PAD_PROBE_TYPE_EVENT_BOTH|GST_PAD_PROBE_TYPE_EVENT_FLUSH,
-               __mmplayer_gst_selector_event_probe, player, NULL);
+       player->track[stream_type].block_id = gst_pad_add_probe(srcpad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM,
+               __mmplayer_gst_combiner_blocked, NULL, NULL);
+       player->track[stream_type].event_probe_id = gst_pad_add_probe(srcpad, GST_PAD_PROBE_TYPE_EVENT_BOTH|GST_PAD_PROBE_TYPE_EVENT_FLUSH,
+               __mmplayer_gst_combiner_event_probe, player, NULL);
 
        gst_element_set_state(selector, GST_STATE_PAUSED);
 
        pipeline = player->pipeline->mainbin[MMPLAYER_M_PIPE].gst;
-       gst_bin_add(GST_BIN(pipeline), selector);
+       if (!gst_bin_add(GST_BIN(pipeline), selector)) {
+               LOGE("failed to add selector to pipeline");
+
+               if (player->track[stream_type].block_id != 0)
+                 gst_pad_remove_probe (srcpad, player->track[stream_type].block_id);
+               player->track[stream_type].block_id = 0;
+
+               if (player->track[stream_type].event_probe_id != 0)
+                 gst_pad_remove_probe (srcpad, player->track[stream_type].event_probe_id);
+               player->track[stream_type].event_probe_id = 0;
+
+               gst_object_unref(GST_OBJECT(srcpad));
+
+               gst_element_set_state(selector, GST_STATE_NULL);
+               gst_object_unref(GST_OBJECT(selector));
+               return NULL;
+       }
 
        gst_object_unref(GST_OBJECT(srcpad));
 
+       player->pipeline->mainbin[elem_idx].id = elem_idx;
+       player->pipeline->mainbin[elem_idx].gst = selector;
+
        MMPLAYER_FLEAVE();
        return selector;
 }
@@ -1165,7 +1322,7 @@ void
 _mmplayer_gst_decode_pad_added(GstElement *elem, GstPad *pad, gpointer data)
 {
        mmplayer_t *player = (mmplayer_t *)data;
-       GstElement *selector = NULL;
+       GstElement *combiner = NULL;
        GstCaps *caps = NULL;
        GstStructure *str = NULL;
        const gchar *name = NULL;
@@ -1183,7 +1340,7 @@ _mmplayer_gst_decode_pad_added(GstElement *elem, GstPad *pad, gpointer data)
        LOGD("pad-added signal handling");
 
        /* get mimetype from caps */
-       MMPLAYER_GST_GET_CAPS_INFO(pad, caps, str, name, caps_ret);
+       MMPLAYER_GST_GET_CAPS_INFO_FROM_PAD(pad, caps, str, name, caps_ret);
        if (!caps_ret)
                goto ERROR;
 
@@ -1209,7 +1366,7 @@ _mmplayer_gst_decode_pad_added(GstElement *elem, GstPad *pad, gpointer data)
                LOGD("surface type : %d", stype);
 
                if (MMPLAYER_IS_MS_BUFF_SRC(player)) {
-                       __mmplayer_gst_create_sinkbin(elem, pad, player);
+                       __mmplayer_gst_create_sink_bin(elem, pad, caps, player);
                        goto DONE;
                }
 
@@ -1220,8 +1377,13 @@ _mmplayer_gst_decode_pad_added(GstElement *elem, GstPad *pad, gpointer data)
                        goto DONE;
                }
 
-               LOGD("video selector is required");
-               elem_idx = MMPLAYER_M_V_INPUT_SELECTOR;
+               if (MMPLAYER_USE_DECODEBIN(player)) {
+                       LOGD("video selector is required");
+                       elem_idx = MMPLAYER_M_V_INPUT_SELECTOR;
+               } else {
+                       LOGD("video concat is required");
+                       elem_idx = MMPLAYER_M_V_CONCAT;
+               }
                stream_type = MM_PLAYER_TRACK_TYPE_VIDEO;
        } else if (strstr(name, "audio")) {
                gint samplerate = 0;
@@ -1230,7 +1392,7 @@ _mmplayer_gst_decode_pad_added(GstElement *elem, GstPad *pad, gpointer data)
                if (MMPLAYER_IS_MS_BUFF_SRC(player) || player->build_audio_offload) {
                        if (player->build_audio_offload)
                                player->no_more_pad = TRUE; /* remove state holder */
-                       __mmplayer_gst_create_sinkbin(elem, pad, player);
+                       __mmplayer_gst_create_sink_bin(elem, pad, caps, player);
                        goto DONE;
                }
 
@@ -1241,14 +1403,23 @@ _mmplayer_gst_decode_pad_added(GstElement *elem, GstPad *pad, gpointer data)
                        __mmplayer_gst_make_fakesink(player, pad, name);
                        goto DONE;
                }
-
-               LOGD("audio selector is required");
-               elem_idx = MMPLAYER_M_A_INPUT_SELECTOR;
+               if (MMPLAYER_USE_DECODEBIN(player)) {
+                       LOGD("audio selector is required");
+                       elem_idx = MMPLAYER_M_A_INPUT_SELECTOR;
+               } else {
+                       LOGD("audio concat is required");
+                       elem_idx = MMPLAYER_M_A_CONCAT;
+               }
                stream_type = MM_PLAYER_TRACK_TYPE_AUDIO;
 
        } else if (strstr(name, "text")) {
-               LOGD("text selector is required");
-               elem_idx = MMPLAYER_M_T_INPUT_SELECTOR;
+               if (MMPLAYER_USE_DECODEBIN(player)) {
+                       LOGD("text selector is required");
+                       elem_idx = MMPLAYER_M_T_INPUT_SELECTOR;
+               } else {
+                       LOGD("text concat is required");
+                       elem_idx = MMPLAYER_M_T_CONCAT;
+               }
                stream_type = MM_PLAYER_TRACK_TYPE_TEXT;
        } else {
                LOGE("invalid caps info");
@@ -1256,32 +1427,47 @@ _mmplayer_gst_decode_pad_added(GstElement *elem, GstPad *pad, gpointer data)
        }
 
        /* check selector and create it */
-       if (!(selector = player->pipeline->mainbin[elem_idx].gst)) {
-               selector = __mmplayer_gst_make_selector(player, elem_idx, stream_type);
-               if (!selector)
+       if (!(combiner = player->pipeline->mainbin[elem_idx].gst)) {
+               if (MMPLAYER_USE_DECODEBIN(player))
+                       combiner = __mmplayer_gst_make_selector(player, elem_idx, stream_type);
+               else
+                       combiner = __mmplayer_gst_make_concat(player, elem_idx, stream_type);
+
+               if (!combiner)
                        goto ERROR;
                first_track = TRUE;
        } else {
-               LOGD("input-selector is already created.");
+               LOGD("Combiner element is already created.");
        }
 
        /* link */
-       sinkpad = gst_element_get_request_pad(selector, "sink_%u");
+       sinkpad = gst_element_request_pad_simple(combiner, "sink_%u");
 
        LOGD("pad link: %s:%s - %s:%s", GST_DEBUG_PAD_NAME(pad), GST_DEBUG_PAD_NAME(sinkpad));
 
        if (gst_pad_link(pad, sinkpad) != GST_PAD_LINK_OK) {
-               LOGE("failed to link selector");
-               gst_object_unref(GST_OBJECT(selector));
+               LOGE("failed to link combiner");
+               gst_object_unref(GST_OBJECT(combiner));
                goto ERROR;
        }
 
        if (first_track) {
-               LOGD("this track will be activated");
-               g_object_set(selector, "active-pad", sinkpad, NULL);
+               if (MMPLAYER_USE_DECODEBIN(player)) {
+                       LOGD("this track will be activated");
+                       g_object_set(combiner, "active-pad", sinkpad, NULL);
+               }
        }
 
-       _mmplayer_track_update_selector_info(player, stream_type, sinkpad);
+       if (MMPLAYER_USE_DECODEBIN(player)) {
+               _mmplayer_track_update_stream(player, stream_type, sinkpad);
+       } else {
+               /* apply the text track information */
+               if (stream_type == MM_PLAYER_TRACK_TYPE_TEXT)
+                       mm_player_set_attribute((MMHandleType)player, NULL,
+                                       "content_text_track_num", player->track[stream_type].total_track_num,
+                                       "current_text_track_index", player->track[stream_type].active_track_index, NULL);
+               __mmplayer_create_sink_path(player, combiner, stream_type, caps);
+       }
 
 DONE:
 ERROR:
@@ -1294,11 +1480,12 @@ ERROR:
                sinkpad = NULL;
        }
 
+       MMPLAYER_GENERATE_DOT_IF_ENABLED(player, "pipeline-pad-added");
        return;
 }
 
 static gboolean
-__mmplayer_create_sink_path(mmplayer_t *player, GstElement *selector, mmplayer_track_type_e type)
+__mmplayer_create_sink_path(mmplayer_t *player, GstElement *combiner, mmplayer_track_type_e type, GstCaps *caps)
 {
        GstPad *srcpad = NULL;
 
@@ -1307,25 +1494,25 @@ __mmplayer_create_sink_path(mmplayer_t *player, GstElement *selector, mmplayer_t
 
        LOGD("type %d", type);
 
-       if (!selector) {
+       if (!combiner) {
                LOGD("there is no %d track", type);
                return TRUE;
        }
 
-       srcpad = gst_element_get_static_pad(selector, "src");
+       srcpad = gst_element_get_static_pad(combiner, "src");
        if (!srcpad) {
-               LOGE("failed to get srcpad from selector");
+               LOGE("failed to get srcpad from combiner");
                return FALSE;
        }
 
-       LOGD("got pad %s:%s from selector", GST_DEBUG_PAD_NAME(srcpad));
+       LOGD("got pad %s:%s from combiner", GST_DEBUG_PAD_NAME(srcpad));
 
-       __mmplayer_gst_create_sinkbin(selector, srcpad, player);
+       __mmplayer_gst_create_sink_bin(combiner, srcpad, caps, player);
 
        LOGD("unblocking %s:%s", GST_DEBUG_PAD_NAME(srcpad));
-       if (player->selector[type].block_id) {
-               gst_pad_remove_probe(srcpad, player->selector[type].block_id);
-               player->selector[type].block_id = 0;
+       if (player->track[type].block_id) {
+               gst_pad_remove_probe(srcpad, player->track[type].block_id);
+               player->track[type].block_id = 0;
        }
 
        if (srcpad) {
@@ -1345,21 +1532,21 @@ __mmplayer_set_decode_track_info(mmplayer_t *player, mmplayer_track_type_e type)
        MMPLAYER_FENTER();
        MMPLAYER_RETURN_IF_FAIL(player);
 
-       LOGD("type: %d, the num of track: %d", type, player->selector[type].total_track_num);
+       LOGD("type: %d, the num of track: %d", type, player->track[type].total_track_num);
 
        /* change track to active pad */
-       active_index = player->selector[type].active_pad_index;
-       if ((active_index != DEFAULT_TRACK) &&
+       active_index = player->track[type].active_track_index;
+       if ((active_index != DEFAULT_TRACK_INDEX) &&
                (__mmplayer_change_selector_pad(player, type, active_index) != MM_ERROR_NONE)) {
                LOGW("failed to change %d type track to %d", type, active_index);
-               player->selector[type].active_pad_index = DEFAULT_TRACK;
+               player->track[type].active_track_index = DEFAULT_TRACK_INDEX;
                return;
        }
 
        if (type == MM_PLAYER_TRACK_TYPE_TEXT)
                mm_player_set_attribute((MMHandleType)player, NULL,
-                               "content_text_track_num", player->selector[type].total_track_num,
-                               "current_text_track_index", player->selector[type].active_pad_index, NULL);
+                               "content_text_track_num", player->track[type].total_track_num,
+                               "current_text_track_index", player->track[type].active_track_index, NULL);
 
        MMPLAYER_FLEAVE();
        return;
@@ -1386,16 +1573,17 @@ __mmplayer_create_audio_sink_path(mmplayer_t *player, GstElement *audio_selector
                }
 
                if (player->num_dynamic_pad == 0) /* FIXME: num_dynamic_pad is only for rtsp? */
-                       __mmplayer_pipeline_complete(NULL, player);
+                       _mmplayer_pipeline_complete(NULL, player);
 
                return TRUE;
        }
 
        /* apply the audio track information */
-       __mmplayer_set_decode_track_info(player, MM_PLAYER_TRACK_TYPE_AUDIO);
+       if (MMPLAYER_USE_DECODEBIN(player))
+               __mmplayer_set_decode_track_info(player, MM_PLAYER_TRACK_TYPE_AUDIO);
 
        /* create audio sink path */
-       if (!__mmplayer_create_sink_path(player, audio_selector, MM_PLAYER_TRACK_TYPE_AUDIO)) {
+       if (!__mmplayer_create_sink_path(player, audio_selector, MM_PLAYER_TRACK_TYPE_AUDIO, NULL)) {
                LOGE("failed to create audio sink path");
                return FALSE;
        }
@@ -1411,20 +1599,20 @@ __mmplayer_create_text_sink_path(mmplayer_t *player, GstElement *text_selector)
        MMPLAYER_RETURN_VAL_IF_FAIL(player && text_selector, FALSE);
 
        if (MMPLAYER_IS_MS_BUFF_SRC(player)) {
-               LOGD("text path is not supproted");
+               LOGD("text path is not supported");
                return TRUE;
        }
 
        /* apply the text track information */
        __mmplayer_set_decode_track_info(player, MM_PLAYER_TRACK_TYPE_TEXT);
 
-       if (player->selector[MM_PLAYER_TRACK_TYPE_TEXT].total_track_num > 0)
+       if (player->track[MM_PLAYER_TRACK_TYPE_TEXT].total_track_num > 0)
                player->has_closed_caption = TRUE;
 
        /* create text decode path */
        player->no_more_pad = TRUE;
 
-       if (!__mmplayer_create_sink_path(player, text_selector, MM_PLAYER_TRACK_TYPE_TEXT)) {
+       if (!__mmplayer_create_sink_path(player, text_selector, MM_PLAYER_TRACK_TYPE_TEXT, NULL)) {
                LOGE("failed to create text sink path");
                return FALSE;
        }
@@ -1457,8 +1645,8 @@ __mmplayer_gst_set_queue2_buffering(mmplayer_t *player)
        return TRUE;
 }
 
-static void
-__mmplayer_gst_decode_no_more_pads(GstElement *elem, gpointer data)
+void
+_mmplayer_gst_decode_no_more_pads(GstElement *elem, gpointer data)
 {
        mmplayer_t *player = NULL;
        GstElement *video_selector = NULL;
@@ -1499,7 +1687,7 @@ __mmplayer_gst_decode_no_more_pads(GstElement *elem, gpointer data)
        if (video_selector && !audio_selector && !text_selector)
                player->no_more_pad = TRUE;
 
-       if (!__mmplayer_create_sink_path(player, video_selector, MM_PLAYER_TRACK_TYPE_VIDEO))
+       if (!__mmplayer_create_sink_path(player, video_selector, MM_PLAYER_TRACK_TYPE_VIDEO, NULL))
                goto EXIT;
 
        /* create audio path followed by audio-select */
@@ -1513,11 +1701,7 @@ __mmplayer_gst_decode_no_more_pads(GstElement *elem, gpointer data)
        __mmplayer_create_text_sink_path(player, text_selector);
 
 EXIT:
-       if (player->gapless.reconfigure) {
-               player->gapless.reconfigure = FALSE;
-               MMPLAYER_PLAYBACK_UNLOCK(player);
-       }
-
+       _mmplayer_set_reconfigure_state(player, FALSE);
        MMPLAYER_FLEAVE();
 }
 
@@ -1584,7 +1768,7 @@ EXIT:
 }
 
 static void
-__mmplayer_gst_create_sinkbin(GstElement *elem, GstPad *pad, gpointer data)
+__mmplayer_gst_create_sink_bin(GstElement *elem, GstPad *pad, GstCaps *ref_caps, gpointer data)
 {
        mmplayer_t *player = NULL;
        GstCaps *caps = NULL;
@@ -1602,10 +1786,15 @@ __mmplayer_gst_create_sinkbin(GstElement *elem, GstPad *pad, gpointer data)
        MMPLAYER_FENTER();
        MMPLAYER_RETURN_IF_FAIL(elem && pad);
        MMPLAYER_RETURN_IF_FAIL(player && player->pipeline && MMPLAYER_GET_ATTRS(player));
-
-       MMPLAYER_GST_GET_CAPS_INFO(pad, caps, str, name, caps_ret);
-       if (!caps_ret)
-               goto ERROR;
+       MMPLAYER_GST_GET_CAPS_INFO_FROM_PAD(pad, caps, str, name, caps_ret);
+       if (!caps_ret) {
+               MMPLAYER_GST_GET_CAPS_INFO(ref_caps, str, name, caps_ret);
+               if (!caps_ret)
+                       goto ERROR;
+               if (caps)
+                       gst_caps_unref(caps);
+               caps = gst_caps_ref(ref_caps);
+       }
 
        caps_str = gst_caps_to_string(caps);
 #ifdef __DEBUG__
@@ -1642,8 +1831,8 @@ __mmplayer_gst_create_sinkbin(GstElement *elem, GstPad *pad, gpointer data)
                        mm_attrs_get_int_by_name(player->attrs, "display_surface_type", &surface_type);
                        LOGD("display_surface_type (%d)", surface_type);
 
-                       if ((surface_type == MM_DISPLAY_SURFACE_OVERLAY) &&
-                               (__mmplayer_acquire_hw_resource(player, MMPLAYER_RESOURCE_TYPE_VIDEO_OVERLAY) != MM_ERROR_NONE)) {
+                       if ((surface_type == MM_DISPLAY_SURFACE_OVERLAY || surface_type == MM_DISPLAY_SURFACE_OVERLAY_SYNC_UI) &&
+                               (_mmplayer_acquire_hw_resource(player, MMPLAYER_RESOURCE_TYPE_VIDEO_OVERLAY) != MM_ERROR_NONE)) {
                                LOGE("failed to acquire video overlay resource");
                                goto ERROR;
                        }
@@ -1681,7 +1870,7 @@ __mmplayer_gst_create_sinkbin(GstElement *elem, GstPad *pad, gpointer data)
                                player->textsink_linked  = 1;
                        } else {
                                /* linked textbin exist which means that the external subtitle path exist already */
-                               LOGW("ignoring internal subtutle since external subtitle is available");
+                               LOGW("ignoring internal subtitle since external subtitle is available");
                        }
                }
                sink_pad_name = "text_sink";
@@ -1706,7 +1895,7 @@ __mmplayer_gst_create_sinkbin(GstElement *elem, GstPad *pad, gpointer data)
        LOGD("no more pads: %d, stream count dec : %d(num of dynamic pad)", player->no_more_pad, player->num_dynamic_pad);
 
        if ((player->no_more_pad) && (player->num_dynamic_pad == 0))
-               __mmplayer_pipeline_complete(NULL, player);
+               _mmplayer_pipeline_complete(NULL, player);
 
 ERROR:
 
@@ -1747,7 +1936,7 @@ __mmplayer_get_property_value_for_rotation(mmplayer_t *player, int display_angle
        if (rotation_angle >= 360)
                rotation_angle -= 360;
 
-       /* chech if supported or not */
+       /* check if supported or not */
        if (rotation_angle % 90) {
                LOGD("not supported rotation angle = %d", rotation_angle);
                return FALSE;
@@ -1786,7 +1975,7 @@ _mmplayer_get_video_angle(mmplayer_t *player, int *display_angle, int *orientati
        }
 
        if (display_angle) {
-               /* update user roation */
+               /* update user rotation */
                mm_attrs_get_int_by_name(attrs, "display_rotation", &display_rotation);
 
                /* Counter clockwise */
@@ -1859,7 +2048,8 @@ static void __mmplayer_video_param_set_display_visible(mmplayer_t *player)
        MMPLAYER_FENTER();
 
        /* check video sinkbin is created */
-       if (!_mmplayer_is_videosink_ready(player, MM_DISPLAY_SURFACE_OVERLAY))
+       if (!(_mmplayer_is_videosink_ready(player, MM_DISPLAY_SURFACE_OVERLAY) ||
+               _mmplayer_is_videosink_ready(player, MM_DISPLAY_SURFACE_OVERLAY_SYNC_UI)))
                return;
 
        attrs = MMPLAYER_GET_ATTRS(player);
@@ -1947,6 +2137,28 @@ static void __mmplayer_video_param_set_roi_area(mmplayer_t *player)
                win_roi_x, win_roi_y, win_roi_width, win_roi_height);
 }
 
+static void __mmplayer_video_param_set_display_overlay_sync_ui(mmplayer_t *player)
+{
+       MMHandleType attrs = 0;
+       gchar *handle = NULL;
+
+       /* check video sinkbin is created */
+       if (!_mmplayer_is_videosink_ready(player, MM_DISPLAY_SURFACE_OVERLAY_SYNC_UI))
+               return;
+
+       attrs = MMPLAYER_GET_ATTRS(player);
+       MMPLAYER_RETURN_IF_FAIL(attrs);
+
+       /* common case if using overlay surface */
+       mm_attrs_get_string_by_name(attrs, "exported_shell_handle", &handle);
+       MMPLAYER_RETURN_IF_FAIL(handle);
+
+       gst_video_overlay_set_wl_window_exported_shell_handle(
+                       GST_VIDEO_OVERLAY(player->pipeline->videobin[MMPLAYER_V_SINK].gst),
+                       handle);
+       LOGD("set video param: exported_shell_handle (%s)", handle);
+}
+
 static void __mmplayer_video_param_set_display_overlay(mmplayer_t *player)
 {
        MMHandleType attrs = 0;
@@ -1967,21 +2179,31 @@ static void __mmplayer_video_param_set_display_overlay(mmplayer_t *player)
        LOGD("set video param : wl_surface_id %d", handle);
        gst_video_overlay_set_wl_window_wl_surface_id(
                        GST_VIDEO_OVERLAY(player->pipeline->videobin[MMPLAYER_V_SINK].gst),
-                       (guintptr)handle);
+                       handle);
 }
 
 int
 _mmplayer_update_video_overlay_param(mmplayer_t *player, const char *param_name)
 {
        gboolean update_all_param = FALSE;
+       int curr_type = MM_DISPLAY_SURFACE_NUM;
 
        MMPLAYER_FENTER();
 
-       if (!_mmplayer_is_videosink_ready(player, MM_DISPLAY_SURFACE_OVERLAY)) {
+       if (!player || !player->pipeline || !player->pipeline->mainbin || !player->pipeline->videobin ||
+               !player->pipeline->videobin[MMPLAYER_V_BIN].gst ||
+               !player->pipeline->videobin[MMPLAYER_V_SINK].gst) {
                LOGW("videosink is not ready yet");
                return MM_ERROR_PLAYER_NOT_INITIALIZED;
        }
 
+       mm_attrs_get_int_by_name(player->attrs, "display_surface_type", &curr_type);
+
+       if (curr_type != MM_DISPLAY_SURFACE_OVERLAY && curr_type != MM_DISPLAY_SURFACE_OVERLAY_SYNC_UI) {
+               LOGE("current type(%d) is wrong", curr_type);
+               return MM_ERROR_PLAYER_INTERNAL;
+       }
+
        if (strcmp(player->ini.videosink_element_overlay, "tizenwlsink")) {
                LOGE("invalid videosink [%s]", player->ini.videosink_element_overlay);
                return MM_ERROR_PLAYER_INTERNAL;
@@ -1991,6 +2213,11 @@ _mmplayer_update_video_overlay_param(mmplayer_t *player, const char *param_name)
        if (!g_strcmp0(param_name, "update_all_param"))
                update_all_param = TRUE;
 
+       if (curr_type == MM_DISPLAY_SURFACE_OVERLAY_SYNC_UI) {
+               __mmplayer_video_param_set_display_overlay_sync_ui(player);
+               MMPLAYER_FLEAVE();
+               return MM_ERROR_NONE;
+       }
        if (update_all_param || !g_strcmp0(param_name, "display_overlay"))
                __mmplayer_video_param_set_display_overlay(player);
        if (update_all_param || !g_strcmp0(param_name, "display_method"))
@@ -2004,19 +2231,15 @@ _mmplayer_update_video_overlay_param(mmplayer_t *player, const char *param_name)
        if (update_all_param)
                __mmplayer_video_param_set_video_roi_area(player);
 
-
        MMPLAYER_FLEAVE();
        return MM_ERROR_NONE;
 }
 
-int
-_mmplayer_set_audio_only(MMHandleType hplayer, bool audio_only)
+static int __mmplayer_set_disable_overlay_option(mmplayer_t *player, bool disable)
 {
        gboolean disable_overlay = FALSE;
-       mmplayer_t *player = (mmplayer_t *)hplayer;
 
        MMPLAYER_FENTER();
-       MMPLAYER_RETURN_VAL_IF_FAIL(player && player->pipeline, MM_ERROR_PLAYER_NOT_INITIALIZED);
        MMPLAYER_RETURN_VAL_IF_FAIL(player->pipeline->videobin &&
                                                                player->pipeline->videobin[MMPLAYER_V_SINK].gst,
                                                                MM_ERROR_PLAYER_NO_OP); /* invalid op */
@@ -2028,65 +2251,75 @@ _mmplayer_set_audio_only(MMHandleType hplayer, bool audio_only)
 
        g_object_get(player->pipeline->videobin[MMPLAYER_V_SINK].gst, "disable-overlay", &disable_overlay, NULL);
 
-       if (audio_only == (bool)disable_overlay) {
-               LOGE("It's the same with current setting: (%d)", audio_only);
+       if (disable == (bool)disable_overlay) {
+               LOGE("It's the same with current setting: (%d)", disable);
                return MM_ERROR_NONE;
        }
 
-       if (audio_only) {
+       if (disable) {
                LOGE("disable overlay");
                g_object_set(player->pipeline->videobin[MMPLAYER_V_SINK].gst, "disable-overlay", TRUE, NULL);
 
                /* release overlay resource */
                if (__mmplayer_release_hw_resource(player, MMPLAYER_RESOURCE_TYPE_VIDEO_OVERLAY) != MM_ERROR_NONE) {
                        LOGE("failed to release overlay resource");
-                       goto ERROR;
+                       return MM_ERROR_PLAYER_INTERNAL;
                }
        } else {
-               if (__mmplayer_acquire_hw_resource(player, MMPLAYER_RESOURCE_TYPE_VIDEO_OVERLAY) != MM_ERROR_NONE) {
+               if (_mmplayer_acquire_hw_resource(player, MMPLAYER_RESOURCE_TYPE_VIDEO_OVERLAY) != MM_ERROR_NONE) {
                        LOGE("failed to acquire video overlay resource");
-                       goto ERROR;
+                       return MM_ERROR_PLAYER_INTERNAL;
                }
                player->interrupted_by_resource = FALSE;
 
                LOGD("enable overlay");
                __mmplayer_video_param_set_display_overlay(player);
+               __mmplayer_video_param_set_display_overlay_sync_ui(player);
                g_object_set(player->pipeline->videobin[MMPLAYER_V_SINK].gst, "disable-overlay", FALSE, NULL);
        }
 
-ERROR:
        MMPLAYER_FLEAVE();
        return MM_ERROR_NONE;
 }
 
 int
-_mmplayer_get_audio_only(MMHandleType hplayer, bool *paudio_only)
+_mmplayer_set_audio_only(MMHandleType hplayer, bool audio_only)
 {
+       int ret = MM_ERROR_NONE;
        mmplayer_t *player = (mmplayer_t *)hplayer;
-       gboolean disable_overlay = FALSE;
 
        MMPLAYER_FENTER();
-
        MMPLAYER_RETURN_VAL_IF_FAIL(player && player->pipeline, MM_ERROR_PLAYER_NOT_INITIALIZED);
-       MMPLAYER_RETURN_VAL_IF_FAIL(paudio_only, MM_ERROR_INVALID_ARGUMENT);
-       MMPLAYER_RETURN_VAL_IF_FAIL(player->pipeline->videobin &&
-                                                               player->pipeline->videobin[MMPLAYER_V_SINK].gst,
-                                                               MM_ERROR_PLAYER_NO_OP); /* invalid op */
 
-       if (!g_object_class_find_property(G_OBJECT_GET_CLASS(player->pipeline->videobin[MMPLAYER_V_SINK].gst), "disable-overlay")) {
-               LOGW("Display control is not supported");
-               return MM_ERROR_PLAYER_INTERNAL;
+       if (MMPLAYER_USE_DECODEBIN(player)) {
+               ret = __mmplayer_set_disable_overlay_option(player, audio_only);
+               goto EXIT;
        }
 
-       g_object_get(player->pipeline->videobin[MMPLAYER_V_SINK].gst, "disable-overlay", &disable_overlay, NULL);
+       if (audio_only) {
+               MMPLAYER_RETURN_VAL_IF_FAIL(player->pipeline->videobin &&
+                                                                       player->pipeline->videobin[MMPLAYER_V_SINK].gst,
+                                                                       MM_ERROR_PLAYER_NO_OP); /* invalid op */
 
-       *paudio_only = (bool)disable_overlay;
+               __mmplayer_del_sink(player, player->pipeline->videobin[MMPLAYER_V_SINK].gst);
 
-       LOGD("audio_only : %d", *paudio_only);
+               __mmplayer_switch_stream(player, MM_PLAYER_TRACK_TYPE_VIDEO, INVALID_TRACK_INDEX);
 
-       MMPLAYER_FLEAVE();
+               /* release decoder resource */
+               if (__mmplayer_release_hw_resource(player, MMPLAYER_RESOURCE_TYPE_VIDEO_DECODER) != MM_ERROR_NONE) {
+                       LOGE("failed to release video decoder resources");
+                       return MM_ERROR_PLAYER_INTERNAL;
+               }
+               player->can_support_codec &= ~FOUND_PLUGIN_VIDEO;
+       } else {
+               __mmplayer_switch_stream(player, MM_PLAYER_TRACK_TYPE_VIDEO, DEFAULT_TRACK_INDEX);
+       }
 
-       return MM_ERROR_NONE;
+EXIT:
+       mm_player_set_attribute(hplayer, NULL, MM_PLAYER_AUDIO_ONLY, (int)audio_only, (char *)NULL);
+
+       MMPLAYER_FLEAVE();
+       return ret;
 }
 
 int
@@ -2192,11 +2425,7 @@ __mmplayer_gst_caps_notify_cb(GstPad *pad, GParamSpec *unused, gpointer data)
        MMPLAYER_RETURN_IF_FAIL(unused);
        MMPLAYER_RETURN_IF_FAIL(data);
 
-       caps = gst_pad_get_current_caps(pad);
-       if (!caps)
-               return;
-
-       MMPLAYER_GST_GET_CAPS_INFO(pad, caps, str, name, caps_ret);
+       MMPLAYER_GST_GET_CAPS_INFO_FROM_PAD(pad, caps, str, name, caps_ret);
        if (!caps_ret)
                goto ERROR;
 
@@ -2265,8 +2494,6 @@ __mmplayer_audio_stream_send_data(mmplayer_t *player, mmplayer_audio_stream_buff
 
        audio_stream.bitrate = a_buffer->bitrate;
        audio_stream.channel = a_buffer->channel;
-       audio_stream.depth = a_buffer->depth;
-       audio_stream.is_little_endian = a_buffer->is_little_endian;
        audio_stream.channel_mask = a_buffer->channel_mask;
        audio_stream.data_size = a_buffer->data_size;
        audio_stream.data = a_buffer->pcm_data;
@@ -2286,8 +2513,6 @@ __mmplayer_audio_stream_decoded_render_cb(GstElement *object, GstBuffer *buffer,
        const gchar *pcm_format = NULL;
        gint channel = 0;
        gint rate = 0;
-       gint depth = 0;
-       gint endianness = 0;
        guint64 channel_mask = 0;
        void *a_data = NULL;
        gint a_size = 0;
@@ -2310,8 +2535,6 @@ __mmplayer_audio_stream_decoded_render_cb(GstElement *object, GstBuffer *buffer,
        pcm_format = gst_structure_get_string(structure, "format");
        gst_structure_get_int(structure, "rate", &rate);
        gst_structure_get_int(structure, "channels", &channel);
-       gst_structure_get_int(structure, "depth", &depth);
-       gst_structure_get_int(structure, "endianness", &endianness);
        gst_structure_get(structure, "channel-mask", GST_TYPE_BITMASK, &channel_mask, NULL);
        gst_caps_unref(GST_CAPS(caps));
 
@@ -2362,8 +2585,6 @@ __mmplayer_audio_stream_decoded_render_cb(GstElement *object, GstBuffer *buffer,
        }
        a_buffer->bitrate = rate;
        a_buffer->channel = channel;
-       a_buffer->depth = depth;
-       a_buffer->is_little_endian = (endianness == 1234 ? true : false);
        a_buffer->channel_mask = channel_mask;
        a_buffer->data_size = a_size;
        a_buffer->pcm_format = _mmplayer_convert_audio_pcm_str_to_media_format_mime(pcm_format);
@@ -2452,7 +2673,7 @@ __mmplayer_gst_audio_deinterleave_pad_added(GstElement *elem, GstPad *pad, gpoin
                G_CALLBACK(__mmplayer_audio_stream_decoded_render_cb),
                (gpointer)player);
 
-       __mmplayer_add_sink(player, sink);
+       __mmplayer_add_sink(player, sink, FALSE);
 
        if (gst_element_sync_state_with_parent(queue) == GST_STATE_CHANGE_FAILURE) {
                LOGE("failed to sync state");
@@ -2494,7 +2715,7 @@ __mmplayer_gst_audio_deinterleave_no_more_pads(GstElement* object, gpointer data
        MMPLAYER_RETURN_IF_FAIL(player && player->pipeline && player->pipeline->mainbin);
 
        player->no_more_pad = TRUE;
-       __mmplayer_pipeline_complete(NULL, player);
+       _mmplayer_pipeline_complete(NULL, player);
 
        MMPLAYER_FLEAVE();
        return;
@@ -2547,13 +2768,16 @@ __mmplayer_gst_set_pulsesink_property(mmplayer_t *player)
 
        switch (latency_mode) {
        case AUDIO_LATENCY_MODE_LOW:
-               latency = g_strndup("low", 3);
+               latency = g_strdup("low");
                break;
        case AUDIO_LATENCY_MODE_MID:
-               latency = g_strndup("mid", 3);
+               latency = g_strdup("mid");
                break;
        case AUDIO_LATENCY_MODE_HIGH:
-               latency = g_strndup("high", 4);
+               latency = g_strdup("high");
+               break;
+       default:
+               latency = g_strdup("mid");
                break;
        };
 
@@ -2566,18 +2790,23 @@ __mmplayer_gst_set_pulsesink_property(mmplayer_t *player)
        MMPLAYER_FLEAVE();
 }
 
-void
+int
 __mmplayer_gst_set_openalsink_property(mmplayer_t *player)
 {
        mmplayer_gst_element_t *audiobin = NULL;
 
        MMPLAYER_FENTER();
-       MMPLAYER_RETURN_IF_FAIL(player && player->pipeline && player->pipeline->audiobin);
+       MMPLAYER_RETURN_VAL_IF_FAIL(player && player->pipeline &&
+                               player->pipeline->audiobin, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        audiobin = player->pipeline->audiobin;
 
        g_object_set(G_OBJECT(audiobin[MMPLAYER_A_SINK].gst), "source-ambisonics-type", 1, NULL);
-       sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, NULL, NULL, &stream_info);
+       if (sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, NULL, NULL, &stream_info)) {
+               LOGE("failed to create media stream info");
+               return MM_ERROR_PLAYER_INTERNAL;
+       }
+
        g_object_set(G_OBJECT(audiobin[MMPLAYER_A_SINK].gst), "stream-info", stream_info, NULL);
 
        if (player->video360_yaw_radians <= M_PI &&
@@ -2594,6 +2823,7 @@ __mmplayer_gst_set_openalsink_property(mmplayer_t *player)
        }
 
        MMPLAYER_FLEAVE();
+       return MM_ERROR_NONE;
 }
 
 static int
@@ -2731,10 +2961,12 @@ __mmplayer_gst_make_audio_playback_sink(mmplayer_t *player, GList **bucket)
                g_object_set(G_OBJECT(audiobin[MMPLAYER_A_SINK].gst), "provide-clock", FALSE,  NULL);
        }
 
-       if (g_strrstr(player->ini.audiosink_element, "pulsesink"))
+       if (g_strrstr(player->ini.audiosink_element, "pulsesink")) {
                __mmplayer_gst_set_pulsesink_property(player);
-       else if (g_strrstr(player->ini.audiosink_element, "openalsink"))
-               __mmplayer_gst_set_openalsink_property(player);
+       } else if (g_strrstr(player->ini.audiosink_element, "openalsink")) {
+               if (__mmplayer_gst_set_openalsink_property(player) != MM_ERROR_NONE)
+                       goto ERROR;
+       }
 
        /* qos on */
        g_object_set(G_OBJECT(audiobin[MMPLAYER_A_SINK].gst), "qos", TRUE, NULL);       /* qos on */
@@ -2745,7 +2977,7 @@ __mmplayer_gst_make_audio_playback_sink(mmplayer_t *player, GList **bucket)
                                "notify::caps", G_CALLBACK(__mmplayer_gst_caps_notify_cb), (gpointer)player);
        gst_object_unref(GST_OBJECT(sink_pad));
 
-       __mmplayer_add_sink(player, audiobin[MMPLAYER_A_SINK].gst);
+       __mmplayer_add_sink(player, audiobin[MMPLAYER_A_SINK].gst, FALSE);
 
        MMPLAYER_FLEAVE();
        return MM_ERROR_NONE;
@@ -2887,7 +3119,7 @@ __mmplayer_gst_make_audio_extract_sink(mmplayer_t *player, GList **bucket)
                                MM_PLAYER_SIGNAL_TYPE_AUTOPLUG, "no-more-pads", G_CALLBACK(__mmplayer_gst_audio_deinterleave_no_more_pads), (gpointer)player);
                player->no_more_pad = FALSE;
        } else {
-       /* 4-2. create fakesink to extract interlevaed pcm */
+       /* 4-2. create fakesink to extract interleaved pcm */
                LOGD("add audio fakesink for interleaved audio");
                MMPLAYER_CREATE_ELEMENT(audiobin, extract_sink_id, "fakesink", "fakeaudiosink", *bucket, player);
                if (!(player->audio_extract_opt & MM_PLAYER_AUDIO_EXTRACT_NO_SYNC_WITH_CLOCK))
@@ -2901,7 +3133,7 @@ __mmplayer_gst_make_audio_extract_sink(mmplayer_t *player, GList **bucket)
                        G_CALLBACK(__mmplayer_audio_stream_decoded_render_cb),
                        (gpointer)player);
 
-               __mmplayer_add_sink(player, audiobin[extract_sink_id].gst);
+               __mmplayer_add_sink(player, audiobin[extract_sink_id].gst, FALSE);
        }
 
        MMPLAYER_FLEAVE();
@@ -2932,7 +3164,7 @@ __mmplayer_gst_make_audio_bin_element(mmplayer_t *player, GList **bucket)
                g_object_set(G_OBJECT(audiobin[MMPLAYER_A_SINK].gst), "sync", TRUE,
                                "volume", player->sound.volume, "mute", player->sound.mute, NULL);
 
-               __mmplayer_add_sink(player, audiobin[MMPLAYER_A_SINK].gst);
+               __mmplayer_add_sink(player, audiobin[MMPLAYER_A_SINK].gst, FALSE);
                goto DONE;
        }
 
@@ -3063,7 +3295,7 @@ ERROR:
                }
        }
 
-       /* release audiobin with it's childs */
+       /* release audiobin with it's children */
        if (audiobin[MMPLAYER_A_BIN].gst)
                gst_object_unref(GST_OBJECT(audiobin[MMPLAYER_A_BIN].gst));
 
@@ -3111,27 +3343,27 @@ _mmplayer_video_stream_release_bo(mmplayer_t *player, void *bo)
        LOGW("failed to find bo %p", bo);
        return ret;
 }
+static void
+__mmplayer_video_stream_bo_list_free(mmplayer_video_bo_info_t *tmp)
+{
+       if (!tmp)
+               return;
+
+       if (tmp->bo)
+               tbm_bo_unref(tmp->bo);
+       g_free(tmp);
+}
 
 static void
 __mmplayer_video_stream_destroy_bo_list(mmplayer_t *player)
 {
-       GList *l = NULL;
-
        MMPLAYER_FENTER();
        MMPLAYER_RETURN_IF_FAIL(player);
 
        MMPLAYER_VIDEO_BO_LOCK(player);
        if (player->video_bo_list) {
                LOGD("destroy video_bo_list : %d", g_list_length(player->video_bo_list));
-               for (l = g_list_first(player->video_bo_list); l; l = g_list_next(l)) {
-                       mmplayer_video_bo_info_t *tmp = (mmplayer_video_bo_info_t *)l->data;
-                       if (tmp) {
-                               if (tmp->bo)
-                                       tbm_bo_unref(tmp->bo);
-                               g_free(tmp);
-                       }
-               }
-               g_list_free(player->video_bo_list);
+               g_list_free_full(player->video_bo_list, (GDestroyNotify)__mmplayer_video_stream_bo_list_free);
                player->video_bo_list = NULL;
        }
        player->video_bo_size = 0;
@@ -3147,6 +3379,7 @@ __mmplayer_video_stream_get_bo(mmplayer_t *player, int size)
        GList *l = NULL;
        MMPLAYER_RETURN_VAL_IF_FAIL(player, NULL);
        gboolean ret = TRUE;
+       gint64 end_time = 0;
 
        /* check DRC, if it is, destroy the prev bo list to create again */
        if (player->video_bo_size != size) {
@@ -3199,6 +3432,9 @@ __mmplayer_video_stream_get_bo(mmplayer_t *player, int size)
                }
        }
 
+       if (player->ini.video_bo_timeout > 0)
+               end_time = g_get_monotonic_time() + player->ini.video_bo_timeout * G_TIME_SPAN_SECOND;
+
        while (TRUE) {
                /* get bo from list*/
                for (l = g_list_first(player->video_bo_list); l; l = g_list_next(l)) {
@@ -3210,20 +3446,20 @@ __mmplayer_video_stream_get_bo(mmplayer_t *player, int size)
                                return tbm_bo_ref(tmp->bo);
                        }
                }
-               if (!ret) {
-                       LOGE("failed to get bo in %d timeout", player->ini.video_bo_timeout);
-                       MMPLAYER_VIDEO_BO_UNLOCK(player);
-                       return NULL;
-               }
 
                if (player->ini.video_bo_timeout <= 0) {
                        MMPLAYER_VIDEO_BO_WAIT(player);
                } else {
-                       gint64 timeout = g_get_monotonic_time() + player->ini.video_bo_timeout * G_TIME_SPAN_SECOND;
-                       ret = MMPLAYER_VIDEO_BO_WAIT_UNTIL(player, timeout);
+                       ret = MMPLAYER_VIDEO_BO_WAIT_UNTIL(player, end_time);
+                       if (!ret) {
+                               LOGE("failed to get bo in %d timeout", player->ini.video_bo_timeout);
+                               break;
+                       }
                }
-               continue;
        }
+
+       MMPLAYER_VIDEO_BO_UNLOCK(player);
+       return NULL;
 }
 
 static void
@@ -3271,7 +3507,7 @@ __mmplayer_video_stream_decoded_render_cb(GstElement *object, GstBuffer *buffer,
        /* set size and timestamp */
        mem = gst_buffer_peek_memory(buffer, 0);
        stream->length_total = gst_memory_get_sizes(mem, NULL, NULL);
-       stream->timestamp = (unsigned int)(GST_TIME_AS_MSECONDS(GST_BUFFER_PTS(buffer))); /* nano sec -> mili sec */
+       stream->timestamp = (unsigned int)(GST_TIME_AS_MSECONDS(GST_BUFFER_PTS(buffer))); /* nano sec -> milli sec */
 
        /* check zero-copy */
        if (player->set_mode.video_zc &&
@@ -3394,7 +3630,9 @@ __mmplayer_gst_create_video_filters(mmplayer_t *player, MMDisplaySurfaceType sur
                goto EXIT;
        }
 
-       if (surface_type != MM_DISPLAY_SURFACE_OVERLAY || player->set_mode.video_zc) {
+       if ((surface_type != MM_DISPLAY_SURFACE_OVERLAY &&
+               surface_type != MM_DISPLAY_SURFACE_OVERLAY_SYNC_UI) ||
+               player->set_mode.video_zc) {
                LOGD("skip creating the videoconv and rotator");
                return MM_ERROR_NONE;
        }
@@ -3424,10 +3662,13 @@ __mmplayer_get_videosink_factory_name(mmplayer_t *player, MMDisplaySurfaceType s
 
        switch (surface_type) {
        case MM_DISPLAY_SURFACE_OVERLAY:
+       /* fall through */
+       case MM_DISPLAY_SURFACE_OVERLAY_SYNC_UI:
                if (strlen(player->ini.videosink_element_overlay) > 0)
                        factory_name = player->ini.videosink_element_overlay;
                break;
        case MM_DISPLAY_SURFACE_REMOTE:
+       /* fall through */
        case MM_DISPLAY_SURFACE_NULL:
                if (strlen(player->ini.videosink_element_fake) > 0)
                        factory_name = player->ini.videosink_element_fake;
@@ -3461,19 +3702,18 @@ __mmplayer_gst_set_videosink_property(mmplayer_t *player, MMDisplaySurfaceType s
                return MM_ERROR_PLAYER_INTERNAL;
        }
 
-       LOGD("surface type %d, videosink factory name is %s", surface_type, factory_name);
-       if (surface_type == MM_DISPLAY_SURFACE_OVERLAY) {
+       if (surface_type == MM_DISPLAY_SURFACE_OVERLAY || surface_type == MM_DISPLAY_SURFACE_OVERLAY_SYNC_UI) {
                bool use_tbm = (player->set_mode.video_zc || (player->is_360_feature_enabled && player->is_content_spherical));
-               if (!use_tbm) {
-                       /* support shard memory with S/W codec on HawkP */
-                       if (strncmp(factory_name, "tizenwlsink", strlen(factory_name)) == 0) {
-                               g_object_set(player->pipeline->videobin[MMPLAYER_V_SINK].gst,
-                                       "use-tbm", use_tbm, NULL);
-                       }
+               if (strncmp(factory_name, "tizenwlsink", strlen(factory_name)) == 0) {
+                       g_object_set(player->pipeline->videobin[MMPLAYER_V_SINK].gst,
+                               "use-tbm", use_tbm, NULL);
                }
 
                if (_mmplayer_update_video_overlay_param(player, "update_all_param") != MM_ERROR_NONE)
                        return MM_ERROR_PLAYER_INTERNAL;
+
+               LOGI("videosink factory name is %s use-tbm : %d", factory_name, use_tbm);
+
        } else {
                g_object_set(G_OBJECT(player->pipeline->videobin[MMPLAYER_V_SINK].gst),
                                                                                "sync", TRUE, "max-lateness", FAKE_SINK_MAX_LATENESS, NULL);
@@ -3565,7 +3805,7 @@ __mmplayer_gst_create_video_sink_bin(mmplayer_t *player, GstCaps *caps, MMDispla
        }
 
        /* store it as it's sink element */
-       __mmplayer_add_sink(player, videobin[MMPLAYER_V_SINK].gst);
+       __mmplayer_add_sink(player, videobin[MMPLAYER_V_SINK].gst, TRUE);
 
        /* adding created elements to bin */
        if (!_mmplayer_gst_element_add_bucket_to_bin(GST_BIN(videobin[MMPLAYER_V_BIN].gst), element_bucket)) {
@@ -3614,7 +3854,7 @@ ERROR:
        if (pad)
                gst_object_unref(GST_OBJECT(pad));
 
-       /* release videobin with it's childs */
+       /* release videobin with it's children */
        if (videobin[MMPLAYER_V_BIN].gst)
                gst_object_unref(GST_OBJECT(videobin[MMPLAYER_V_BIN].gst));
 
@@ -3649,7 +3889,7 @@ __mmplayer_gst_create_plain_text_elements(mmplayer_t *player)
 
        if (!player->play_subtitle) {
                LOGD("add textbin sink as sink element of whole pipeline.");
-               __mmplayer_add_sink(player, GST_ELEMENT(textbin[MMPLAYER_T_FAKE_SINK].gst));
+               __mmplayer_add_sink(player, GST_ELEMENT(textbin[MMPLAYER_T_FAKE_SINK].gst), FALSE);
        }
 
        /* adding created elements to bin */
@@ -3670,9 +3910,6 @@ __mmplayer_gst_create_plain_text_elements(mmplayer_t *player)
                goto ERROR;
        }
 
-       /* done. free allocated variables */
-       g_list_free(element_bucket);
-
        if (textbin[MMPLAYER_T_QUEUE].gst) {
                GstPad *pad = NULL;
                GstPad *ghostpad = NULL;
@@ -3698,9 +3935,12 @@ __mmplayer_gst_create_plain_text_elements(mmplayer_t *player)
                }
        }
 
+       g_list_free(element_bucket);
+
        return MM_ERROR_NONE;
 
 ERROR:
+
        g_list_free(element_bucket);
 
        if (!player->play_subtitle && textbin[MMPLAYER_T_FAKE_SINK].gst) {
@@ -3716,7 +3956,6 @@ static int
 __mmplayer_gst_create_text_sink_bin(mmplayer_t *player)
 {
        mmplayer_gst_element_t *textbin = NULL;
-       GList *element_bucket = NULL;
        int surface_type = 0;
        gint i = 0;
 
@@ -3767,8 +4006,6 @@ ERROR:
 
        LOGD("ERROR : releasing textbin");
 
-       g_list_free(element_bucket);
-
        /* release signal */
        __mmplayer_release_signal_connection(player, MM_PLAYER_SIGNAL_TYPE_TEXTBIN);
 
@@ -3788,11 +4025,11 @@ ERROR:
                }
        }
 
-       /* release textbin with it's childs */
+       /* release textbin with it's children */
        if (textbin[MMPLAYER_T_BIN].gst)
                gst_object_unref(GST_OBJECT(textbin[MMPLAYER_T_BIN].gst));
 
-       MMPLAYER_FREEIF(player->pipeline->textbin);
+       MMPLAYER_FREEIF(textbin);
        player->pipeline->textbin = NULL;
 
        MMPLAYER_FLEAVE();
@@ -3910,7 +4147,7 @@ __mmplayer_gst_create_text_pipeline(mmplayer_t *player)
                        /* release signal */
                        __mmplayer_release_signal_connection(player, MM_PLAYER_SIGNAL_TYPE_TEXTBIN);
 
-                       /* release textbin with it's childs */
+                       /* release textbin with it's children */
                        gst_object_unref(GST_OBJECT(textbin[MMPLAYER_T_BIN].gst));
                        MMPLAYER_FREEIF(player->pipeline->textbin);
                        player->pipeline->textbin = textbin = NULL;
@@ -3961,7 +4198,7 @@ ERROR:
        if (player->pipeline->textbin) {
                LOGE("remove textbin");
 
-               /* release textbin with it's childs */
+               /* release textbin with it's children */
                MMPLAYER_RELEASE_ELEMENT(player, player->pipeline->textbin, MMPLAYER_T_BIN);
                MMPLAYER_FREEIF(player->pipeline->textbin);
                player->pipeline->textbin = NULL;
@@ -4086,7 +4323,7 @@ __mmplayer_gst_adjust_subtitle_position(mmplayer_t *player, int position)
                return MM_ERROR_NONE;
        }
 
-       /* check current postion */
+       /* check current position */
        player->adjust_subtitle_pos = position;
 
        LOGD("save adjust_subtitle_pos in player");
@@ -4129,8 +4366,6 @@ __mmplayer_gst_create_pipeline(mmplayer_t *player)
        }
 
        player->pipeline = (mmplayer_pipeline_info_t *)g_malloc0(sizeof(mmplayer_pipeline_info_t));
-       if (player->pipeline == NULL)
-               goto INIT_ERROR;
 
        /* create mainbin */
        mainbin = (mmplayer_gst_element_t *)g_try_malloc0(sizeof(mmplayer_gst_element_t) * MMPLAYER_M_NUM);
@@ -4149,17 +4384,21 @@ __mmplayer_gst_create_pipeline(mmplayer_t *player)
        player->pipeline->mainbin = mainbin;
 
        /* create the source and decoder elements */
-       if (MMPLAYER_IS_MS_BUFF_SRC(player))
+       if (MMPLAYER_IS_MS_BUFF_SRC(player)) {
                ret = _mmplayer_gst_build_es_pipeline(player);
-       else
-               ret = _mmplayer_gst_build_pipeline(player);
+       } else {
+               if (MMPLAYER_USE_DECODEBIN(player))
+                       ret = _mmplayer_gst_build_pipeline(player); /* TEMP: previous pipeline, will be removed.*/
+               else
+                       ret = _mmplayer_gst_build_pipeline_with_src(player);
+       }
 
        if (ret != MM_ERROR_NONE) {
                LOGE("failed to create some elements");
                goto INIT_ERROR;
        }
 
-       /* Note : check whether subtitle atrribute uri is set. If uri is set, then try to play subtitle file */
+       /* Note : check whether subtitle attribute uri is set. If uri is set, then try to play subtitle file */
        if (__mmplayer_check_subtitle(player)
                && (__mmplayer_gst_create_text_pipeline(player) != MM_ERROR_NONE))
                LOGE("failed to create text pipeline");
@@ -4175,6 +4414,7 @@ __mmplayer_gst_create_pipeline(mmplayer_t *player)
        return MM_ERROR_NONE;
 
 INIT_ERROR:
+       _mmplayer_bus_watcher_remove(player);
        __mmplayer_gst_destroy_pipeline(player);
        return MM_ERROR_PLAYER_INTERNAL;
 }
@@ -4205,16 +4445,17 @@ __mmplayer_gst_destroy_pipeline(mmplayer_t *player)
        MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_INVALID_HANDLE);
 
        /* cleanup stuffs */
-       MMPLAYER_FREEIF(player->type);
+       MMPLAYER_FREEIF(player->type_caps_str);
        player->no_more_pad = FALSE;
        player->num_dynamic_pad = 0;
-       player->demux_pad_index = 0;
 
        MMPLAYER_SUBTITLE_INFO_LOCK(player);
        player->subtitle_language_list = NULL;
        MMPLAYER_SUBTITLE_INFO_UNLOCK(player);
 
+       MMPLAYER_RECONFIGURE_LOCK(player);
        __mmplayer_reset_gapless_state(player);
+       MMPLAYER_RECONFIGURE_UNLOCK(player);
 
        if (player->streamer) {
                _mm_player_streaming_initialize(player->streamer, FALSE);
@@ -4239,9 +4480,6 @@ __mmplayer_gst_destroy_pipeline(mmplayer_t *player)
                __mmplayer_release_signal_connection(player, MM_PLAYER_SIGNAL_TYPE_ALL);
 
                if (mainbin) {
-                       mmplayer_gst_element_t *audiobin = player->pipeline->audiobin;
-                       mmplayer_gst_element_t *videobin = player->pipeline->videobin;
-                       mmplayer_gst_element_t *textbin = player->pipeline->textbin;
                        GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(mainbin[MMPLAYER_M_PIPE].gst));
                        gst_bus_set_sync_handler(bus, NULL, NULL, NULL);
                        gst_object_unref(bus);
@@ -4261,13 +4499,9 @@ __mmplayer_gst_destroy_pipeline(mmplayer_t *player)
                        if (mainbin[MMPLAYER_M_SRC_FAKESINK].gst)
                                gst_object_unref(GST_OBJECT(mainbin[MMPLAYER_M_SRC_FAKESINK].gst));
 
-                       /* free avsysaudiosink
-                          avsysaudiosink should be unref when destory pipeline just after start play with BT.
-                          Because audiosink is created but never added to bin, and therefore it will not be unref when pipeline is destroyed.
-                       */
-                       MMPLAYER_FREEIF(audiobin);
-                       MMPLAYER_FREEIF(videobin);
-                       MMPLAYER_FREEIF(textbin);
+                       MMPLAYER_FREEIF(player->pipeline->audiobin);
+                       MMPLAYER_FREEIF(player->pipeline->videobin);
+                       MMPLAYER_FREEIF(player->pipeline->textbin);
                        MMPLAYER_FREEIF(mainbin);
                }
 
@@ -4368,7 +4602,7 @@ __mmplayer_gst_unrealize(mmplayer_t *player)
        /* destroy pipeline */
        ret = __mmplayer_gst_destroy_pipeline(player);
        if (ret != MM_ERROR_NONE) {
-               LOGE("failed to destory pipeline");
+               LOGE("failed to destroy pipeline");
                return ret;
        }
 
@@ -4452,55 +4686,6 @@ _mmplayer_parse_profile(const char *uri, void *param, mmplayer_parse_profile_t *
        return ret;
 }
 
-static gboolean
-__mmplayer_can_do_interrupt(mmplayer_t *player)
-{
-       if (!player || !player->pipeline || !player->attrs) {
-               LOGW("not initialized");
-               goto FAILED;
-       }
-
-       if (player->audio_decoded_cb) {
-               LOGW("not support in pcm extraction mode");
-               goto FAILED;
-       }
-
-       /* check if seeking */
-       if (player->seek_state != MMPLAYER_SEEK_NONE) {
-               MMMessageParamType msg_param;
-               memset(&msg_param, 0, sizeof(MMMessageParamType));
-               msg_param.code = MM_ERROR_PLAYER_SEEK;
-               player->seek_state = MMPLAYER_SEEK_NONE;
-               MMPLAYER_POST_MSG(player, MM_MESSAGE_ERROR, &msg_param);
-               goto FAILED;
-       }
-
-       /* check other thread */
-       if (!MMPLAYER_CMD_TRYLOCK(player)) {
-               LOGW("locked already, cmd state : %d", player->cmd);
-
-               /* check application command */
-               if (player->cmd == MMPLAYER_COMMAND_START || player->cmd == MMPLAYER_COMMAND_RESUME) {
-                       LOGW("playing.. should wait cmd lock then, will be interrupted");
-
-                       /* lock will be released at mrp_resource_release_cb() */
-                       MMPLAYER_CMD_LOCK(player);
-                       goto INTERRUPT;
-               }
-               LOGW("nothing to do");
-               goto FAILED;
-       } else {
-               LOGW("can interrupt immediately");
-               goto INTERRUPT;
-       }
-
-FAILED:    /* with CMD UNLOCKED */
-       return FALSE;
-
-INTERRUPT: /* with CMD LOCKED, will do UNLOCK at __resource_release_cb() */
-       return TRUE;
-}
-
 static int
 __resource_release_cb(mm_resource_manager_h rm, mm_resource_manager_res_h res,
                void *user_data)
@@ -4514,18 +4699,31 @@ __resource_release_cb(mm_resource_manager_h rm, mm_resource_manager_res_h res,
 
        if (!user_data) {
                LOGE("user_data is null");
-               return FALSE;
+               return TRUE;
        }
+
        player = (mmplayer_t *)user_data;
 
-       if (!__mmplayer_can_do_interrupt(player)) {
-               LOGW("no need to interrupt, so leave");
-               /* FIXME: there is no way to avoid releasing resource. */
-               return FALSE;
+       if (!player->pipeline || !player->attrs) {
+               LOGW("not initialized");
+               return TRUE;
+       }
+
+       LOGD("cmd lock player, cmd state : %d", player->cmd);
+       MMPLAYER_CMD_LOCK(player);
+       LOGD("cmd locked player");
+
+       if (MMPLAYER_CURRENT_STATE(player) == MM_PLAYER_STATE_NULL
+               || MMPLAYER_CURRENT_STATE(player) == MM_PLAYER_STATE_NONE) {
+               LOGW("player already destroyed");
+               MMPLAYER_CMD_UNLOCK(player);
+               return TRUE;
        }
 
        player->interrupted_by_resource = TRUE;
 
+       MMPLAYER_POST_MSG(player, MM_MESSAGE_INTERRUPT_STARTED, NULL);
+
        /* get last play position */
        if (_mmplayer_gst_get_position(player, &pos) == MM_ERROR_NONE) {
                msg.union_type = MM_MSG_UNION_TIME;
@@ -4539,7 +4737,6 @@ __resource_release_cb(mm_resource_manager_h rm, mm_resource_manager_res_h res,
        if (_mmplayer_unrealize((MMHandleType)player) != MM_ERROR_NONE)
                LOGE("failed to unrealize");
 
-       /* lock is called in __mmplayer_can_do_interrupt() */
        MMPLAYER_CMD_UNLOCK(player);
 
        for (res_idx = MMPLAYER_RESOURCE_TYPE_VIDEO_DECODER; res_idx < MMPLAYER_RESOURCE_TYPE_MAX; res_idx++) {
@@ -4627,15 +4824,15 @@ _mmplayer_create_player(MMHandleType handle)
 
        ret = _mmplayer_initialize_video_capture(player);
        if (ret != MM_ERROR_NONE) {
-               LOGE("failed to initialize video capture");
-               goto ERROR;
+               LOGW("video capture is not supported");
+               /* do not handle as error for headless profile */
        }
 
        /* initialize resource manager */
        if (mm_resource_manager_create(MM_RESOURCE_MANAGER_APP_CLASS_MEDIA,
                __resource_release_cb, player, &player->resource_manager)
                != MM_RESOURCE_MANAGER_ERROR_NONE) {
-               LOGE("failed to initialize resource manager");
+               LOGE("failed to create resource manager");
                ret = MM_ERROR_PLAYER_INTERNAL;
                goto ERROR;
        }
@@ -4902,7 +5099,7 @@ _mmplayer_destroy(MMHandleType handle)
                MMPLAYER_GAPLESS_PLAY_THREAD_SIGNAL(player);
                MMPLAYER_GAPLESS_PLAY_THREAD_UNLOCK(player);
 
-               LOGD("waitting for gapless play thread exit");
+               LOGD("waiting for gapless play thread exit");
                g_thread_join(player->gapless_play_thread);
                g_mutex_clear(&player->gapless_play_thread_mutex);
                g_cond_clear(&player->gapless_play_thread_cond);
@@ -4911,17 +5108,17 @@ _mmplayer_destroy(MMHandleType handle)
 
        _mmplayer_release_video_capture(player);
 
-       /* de-initialize resource manager */
-       if (MM_RESOURCE_MANAGER_ERROR_NONE != mm_resource_manager_destroy(
-                       player->resource_manager))
-               LOGE("failed to deinitialize resource manager");
+       /* release miscellaneous information */
+       __mmplayer_release_misc(player);
 
        /* release pipeline */
-       if (MM_ERROR_NONE != __mmplayer_gst_destroy_pipeline(player)) {
-               LOGE("failed to destory pipeline");
+       if (__mmplayer_gst_destroy_pipeline(player) != MM_ERROR_NONE) {
+               LOGE("failed to destroy pipeline");
                return MM_ERROR_PLAYER_INTERNAL;
        }
 
+       __mmplayer_destroy_hw_resource(player);
+
        g_queue_free(player->bus_msg_q);
 
        /* release subtitle info lock and cond */
@@ -4930,9 +5127,6 @@ _mmplayer_destroy(MMHandleType handle)
 
        __mmplayer_release_dump_list(player->dump_list);
 
-       /* release miscellaneous information */
-       __mmplayer_release_misc(player);
-
        /* release miscellaneous information.
           these info needs to be released after pipeline is destroyed. */
        __mmplayer_release_misc_post(player);
@@ -4940,6 +5134,11 @@ _mmplayer_destroy(MMHandleType handle)
        /* release attributes */
        _mmplayer_deconstruct_attribute(handle);
 
+       if (player->uri_info.uri_list) {
+               g_list_free_full(player->uri_info.uri_list, (GDestroyNotify)g_free);
+               player->uri_info.uri_list = NULL;
+       }
+
        /* release lock */
        g_mutex_clear(&player->fsink_lock);
 
@@ -4959,10 +5158,10 @@ int
 _mmplayer_realize(MMHandleType hplayer)
 {
        mmplayer_t *player = (mmplayer_t *)hplayer;
+       int ret = MM_ERROR_NONE;
        char *uri = NULL;
        void *param = NULL;
        MMHandleType attrs = 0;
-       int ret = MM_ERROR_NONE;
 
        MMPLAYER_FENTER();
 
@@ -5015,7 +5214,6 @@ _mmplayer_realize(MMHandleType hplayer)
        player->is_subtitle_off = FALSE; /* set the subtitle ON default */
        player->video360_metadata.is_spherical = -1;
        player->is_openal_plugin_used = FALSE;
-       player->demux_pad_index = 0;
        player->subtitle_language_list = NULL;
        player->is_subtitle_force_drop = FALSE;
 
@@ -5064,12 +5262,15 @@ _mmplayer_unrealize(MMHandleType hplayer)
 {
        mmplayer_t *player = (mmplayer_t *)hplayer;
        int ret = MM_ERROR_NONE;
+       int rm_ret = MM_ERROR_NONE;
+       mmplayer_resource_type_e res_idx = MMPLAYER_RESOURCE_TYPE_MAX;
 
        MMPLAYER_FENTER();
 
        MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        MMPLAYER_CMD_UNLOCK(player);
+       _mmplayer_bus_watcher_remove(player);
        /* destroy the gst bus msg thread which is created during realize.
           this funct have to be called before getting cmd lock. */
        _mmplayer_bus_msg_thread_destroy(player);
@@ -5084,17 +5285,14 @@ _mmplayer_unrealize(MMHandleType hplayer)
        /* unrealize pipeline */
        ret = __mmplayer_gst_unrealize(player);
 
-       if (!player->interrupted_by_resource) {
-               int rm_ret = MM_ERROR_NONE;
-               mmplayer_resource_type_e res_idx = MMPLAYER_RESOURCE_TYPE_MAX;
-
-               for (res_idx = MMPLAYER_RESOURCE_TYPE_VIDEO_DECODER; res_idx < MMPLAYER_RESOURCE_TYPE_MAX; res_idx++) {
-                       rm_ret = __mmplayer_release_hw_resource(player, res_idx);
-                       if (rm_ret != MM_ERROR_NONE)
-                               LOGE("failed to release [%d] resources", res_idx);
-               }
+       for (res_idx = MMPLAYER_RESOURCE_TYPE_VIDEO_DECODER; res_idx < MMPLAYER_RESOURCE_TYPE_MAX; res_idx++) {
+               rm_ret = __mmplayer_release_hw_resource(player, res_idx);
+               if (rm_ret != MM_ERROR_NONE)
+                       LOGE("failed to release [%d] resources", res_idx);
        }
 
+       player->interrupted_by_resource = FALSE;
+
        MMPLAYER_FLEAVE();
        return ret;
 }
@@ -5422,28 +5620,32 @@ __mmplayer_handle_missed_plugin(mmplayer_t *player)
        return MM_ERROR_NONE;
 }
 
-static void
-__mmplayer_check_pipeline(mmplayer_t *player)
+static void __mmplayer_check_pipeline_reconfigure_state(mmplayer_t *player)
 {
        GstState element_state = GST_STATE_VOID_PENDING;
        GstState element_pending_state = GST_STATE_VOID_PENDING;
-       gint timeout = 0;
-       int ret = MM_ERROR_NONE;
+       GstStateChangeReturn result = GST_STATE_CHANGE_FAILURE;
+       gint timeout = MMPLAYER_STATE_CHANGE_TIMEOUT(player);
 
-       if (!player->gapless.reconfigure)
-               return;
+       MMPLAYER_RETURN_IF_FAIL(player && player->pipeline);
 
-       LOGW("pipeline is under construction.");
+       MMPLAYER_RECONFIGURE_LOCK(player);
+       if (!player->gapless.reconfigure) {
+               MMPLAYER_RECONFIGURE_UNLOCK(player);
+               return;
+       }
 
-       MMPLAYER_PLAYBACK_LOCK(player);
-       MMPLAYER_PLAYBACK_UNLOCK(player);
+       LOGI("reconfigure is under process");
+       MMPLAYER_RECONFIGURE_WAIT(player);
+       MMPLAYER_RECONFIGURE_UNLOCK(player);
+       LOGI("reconfigure is completed.");
 
-       timeout = MMPLAYER_STATE_CHANGE_TIMEOUT(player);
+       result = gst_element_get_state(player->pipeline->mainbin[MMPLAYER_M_PIPE].gst,
+                               &element_state, &element_pending_state, timeout * GST_SECOND);
+       if (result == GST_STATE_CHANGE_FAILURE)
+               LOGW("failed to get pipeline state in %d sec", timeout);
 
-       /* wait for state transition */
-       ret = gst_element_get_state(player->pipeline->mainbin[MMPLAYER_M_PIPE].gst, &element_state, &element_pending_state, timeout * GST_SECOND);
-       if (ret == GST_STATE_CHANGE_FAILURE)
-               LOGE("failed to change pipeline state within %d sec", timeout);
+       return;
 }
 
 /* NOTE : it should be able to call 'stop' anytime*/
@@ -5460,9 +5662,11 @@ _mmplayer_stop(MMHandleType hplayer)
        /* check current state */
        MMPLAYER_CHECK_STATE(player, MMPLAYER_COMMAND_STOP);
 
-       /* check pipline building state */
-       __mmplayer_check_pipeline(player);
+       /* need to wait till the rebuilding pipeline is completed */
+       __mmplayer_check_pipeline_reconfigure_state(player);
+       MMPLAYER_RECONFIGURE_LOCK(player);
        __mmplayer_reset_gapless_state(player);
+       MMPLAYER_RECONFIGURE_UNLOCK(player);
 
        /* NOTE : application should not wait for EOS after calling STOP */
        _mmplayer_cancel_eos_timer(player);
@@ -5496,14 +5700,14 @@ _mmplayer_pause(MMHandleType hplayer)
        /* check current state */
        MMPLAYER_CHECK_STATE(player, MMPLAYER_COMMAND_PAUSE);
 
-       /* check pipline building state */
-       __mmplayer_check_pipeline(player);
+       /* check pipeline reconfigure state */
+       __mmplayer_check_pipeline_reconfigure_state(player);
 
        switch (MMPLAYER_CURRENT_STATE(player)) {
        case MM_PLAYER_STATE_READY:
                {
                        /* check prepare async or not.
-                        * In the case of streaming playback, it's recommned to avoid blocking wait.
+                        * In the case of streaming playback, it's recommended to avoid blocking wait.
                         */
                        mm_attrs_get_int_by_name(player->attrs, "profile_prepare_async", &async);
                        LOGD("prepare working mode : %s", (async ? "async" : "sync"));
@@ -5546,9 +5750,11 @@ _mmplayer_pause(MMHandleType hplayer)
 
        /* pause pipeline */
        ret = _mmplayer_gst_pause(player, async);
-
-       if (ret != MM_ERROR_NONE)
+       if (ret != MM_ERROR_NONE) {
                LOGE("failed to pause player. ret : 0x%x", ret);
+               MMPLAYER_GENERATE_DOT_IF_ENABLED(player, "pipeline-pause-err");
+               return ret;
+       }
 
        if (MMPLAYER_PREV_STATE(player) == MM_PLAYER_STATE_READY && MMPLAYER_CURRENT_STATE(player) == MM_PLAYER_STATE_PAUSED) {
                if (_mmplayer_update_video_overlay_param(player, "display_rotation") != MM_ERROR_NONE)
@@ -5556,8 +5762,7 @@ _mmplayer_pause(MMHandleType hplayer)
        }
 
        MMPLAYER_FLEAVE();
-
-       return ret;
+       return MM_ERROR_NONE;
 }
 
 /* in case of streaming, pause could take long time.*/
@@ -5574,11 +5779,24 @@ _mmplayer_abort_pause(MMHandleType hplayer)
                                                player->pipeline->mainbin,
                                                MM_ERROR_PLAYER_NOT_INITIALIZED);
 
-       LOGD("set the pipeline state to READY");
+       if (player->pipeline->videobin && player->pipeline->videobin[MMPLAYER_V_BIN].gst) {
+               LOGD("set the videobin state to READY");
+               ret = _mmplayer_gst_set_state(player, player->pipeline->videobin[MMPLAYER_V_BIN].gst,
+                                                       GST_STATE_READY, TRUE, MMPLAYER_STATE_CHANGE_TIMEOUT(player));
 
-       /* set state to READY */
+       }
+
+       if (player->pipeline->audiobin && player->pipeline->audiobin[MMPLAYER_A_BIN].gst) {
+               LOGD("set the audiobin state to READY");
+               ret = _mmplayer_gst_set_state(player, player->pipeline->audiobin[MMPLAYER_A_BIN].gst,
+                                                       GST_STATE_READY, TRUE, MMPLAYER_STATE_CHANGE_TIMEOUT(player));
+
+       }
+
+       LOGD("set the pipeline state to READY");
        ret = _mmplayer_gst_set_state(player, player->pipeline->mainbin[MMPLAYER_M_PIPE].gst,
                                                GST_STATE_READY, FALSE, MMPLAYER_STATE_CHANGE_TIMEOUT(player));
+
        if (ret != MM_ERROR_NONE) {
                LOGE("fail to change state to READY");
                return MM_ERROR_PLAYER_INTERNAL;
@@ -5704,8 +5922,8 @@ _mmplayer_set_position(MMHandleType hplayer, gint64 position)
 
        MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
-       /* check pipline building state */
-       __mmplayer_check_pipeline(player);
+       /* check pipeline reconfigure state */
+       __mmplayer_check_pipeline_reconfigure_state(player);
 
        ret = _mmplayer_gst_set_position(player, position, FALSE);
 
@@ -5723,7 +5941,7 @@ _mmplayer_get_duration(MMHandleType hplayer, gint64 *duration)
        MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
        MMPLAYER_RETURN_VAL_IF_FAIL(duration, MM_ERROR_COMMON_INVALID_ARGUMENT);
 
-       if (g_strrstr(player->type, "video/mpegts"))
+       if (g_strrstr(player->type_caps_str, "video/mpegts"))
                __mmplayer_update_duration_value(player);
 
        *duration = player->duration;
@@ -5744,7 +5962,7 @@ _mmplayer_get_buffer_position(MMHandleType hplayer, int *start_pos, int *end_pos
 }
 
 int
-_mmplayer_adjust_subtitle_postion(MMHandleType hplayer, int position)
+_mmplayer_adjust_subtitle_position(MMHandleType hplayer, int position)
 {
        mmplayer_t *player = (mmplayer_t *)hplayer;
        int ret = MM_ERROR_NONE;
@@ -5786,8 +6004,8 @@ __mmplayer_is_only_mp3_type(gchar *str_caps)
        return FALSE;
 }
 
-static void
-__mmplayer_set_audio_attrs(mmplayer_t *player, GstCaps *caps)
+void
+_mmplayer_set_audio_attrs(mmplayer_t *player, GstCaps *caps)
 {
        GstStructure *caps_structure = NULL;
        gint samplerate = 0;
@@ -5813,9 +6031,9 @@ static void
 __mmplayer_update_content_type_info(mmplayer_t *player)
 {
        MMPLAYER_FENTER();
-       MMPLAYER_RETURN_IF_FAIL(player && player->type);
+       MMPLAYER_RETURN_IF_FAIL(player && player->type_caps_str);
 
-       if (__mmplayer_is_midi_type(player->type)) {
+       if (__mmplayer_is_midi_type(player->type_caps_str)) {
                player->bypass_audio_effect = TRUE;
                return;
        }
@@ -5825,19 +6043,19 @@ __mmplayer_update_content_type_info(mmplayer_t *player)
                return;
        }
 
-       if (g_strrstr(player->type, "application/x-hls")) {
+       if (g_strrstr(player->type_caps_str, "application/x-hls")) {
                /* If it can't know exact type when it parses uri because of redirection case,
                 * it will be fixed by typefinder or when doing autoplugging.
                 */
                player->profile.uri_type = MM_PLAYER_URI_TYPE_HLS;
                player->streamer->is_adaptive_streaming = TRUE;
-       } else if (g_strrstr(player->type, "application/dash+xml")) {
+       } else if (g_strrstr(player->type_caps_str, "application/dash+xml")) {
                player->profile.uri_type = MM_PLAYER_URI_TYPE_DASH;
                player->streamer->is_adaptive_streaming = TRUE;
        }
 
        /* in case of TS, fixed buffering mode should be used because player can not get exact duration time */
-       if ((player->streamer->is_adaptive_streaming) || (g_strrstr(player->type, "video/mpegts"))) {
+       if ((player->streamer->is_adaptive_streaming) || (g_strrstr(player->type_caps_str, "video/mpegts"))) {
                player->streamer->buffering_req.mode = MM_PLAYER_BUFFERING_MODE_FIXED;
 
                if (player->streamer->buffering_req.rebuffer_time <= MIN_BUFFERING_TIME) { /* if user did not set the rebuffer value */
@@ -5857,21 +6075,18 @@ _mmplayer_typefind_have_type(GstElement *tf, guint probability,
        GstCaps *caps, gpointer data)
 {
        mmplayer_t *player = (mmplayer_t *)data;
-       GstPad *pad = NULL;
 
        MMPLAYER_FENTER();
 
        MMPLAYER_RETURN_IF_FAIL(player && tf && caps);
 
-       /* store type string */
-       MMPLAYER_FREEIF(player->type);
-       player->type = gst_caps_to_string(caps);
-       if (player->type)
-               LOGD("[handle: %p] media type %s found, probability %d%% / %d",
-                               player, player->type, probability, gst_caps_get_size(caps));
+       MMPLAYER_FREEIF(player->type_caps_str);
+       player->type_caps_str = gst_caps_to_string(caps);
+       LOGD("[handle: %p] media type %s found, probability %d%% / %d",
+                       player, player->type_caps_str, probability, gst_caps_get_size(caps));
 
        if ((!MMPLAYER_IS_RTSP_STREAMING(player)) &&
-               (g_strrstr(player->type, "audio/x-raw-int"))) {
+               (g_strrstr(player->type_caps_str, "audio/x-raw-int"))) {
                LOGE("not support media format");
 
                if (player->msg_posted == FALSE) {
@@ -5889,27 +6104,27 @@ _mmplayer_typefind_have_type(GstElement *tf, guint probability,
 
        __mmplayer_update_content_type_info(player);
 
-       pad = gst_element_get_static_pad(tf, "src");
-       if (!pad) {
-               LOGE("fail to get typefind src pad.");
-               return;
-       }
+       if (!player->pipeline->mainbin[MMPLAYER_M_AUTOPLUG].gst) {
+               GstPad *pad = NULL;
 
-       if (!_mmplayer_gst_create_decoder(player, pad, caps)) {
-               gboolean async = FALSE;
-               LOGE("failed to autoplug %s", player->type);
+               pad = gst_element_get_static_pad(tf, "src");
+               if (!pad) {
+                       LOGE("fail to get typefind src pad.");
+                       return;
+               }
 
-               mm_attrs_get_int_by_name(player->attrs, "profile_prepare_async", &async);
+               if (!_mmplayer_gst_create_decoder(player, pad, caps)) {
+                       gboolean async = FALSE;
+                       LOGE("failed to autoplug %s", player->type_caps_str);
 
-               if (async && player->msg_posted == FALSE)
-                       __mmplayer_handle_missed_plugin(player);
+                       mm_attrs_get_int_by_name(player->attrs, "profile_prepare_async", &async);
 
+                       if (async && player->msg_posted == FALSE)
+                               __mmplayer_handle_missed_plugin(player);
+               }
+               gst_object_unref(GST_OBJECT(pad));
        }
-
-       gst_object_unref(GST_OBJECT(pad));
-
        MMPLAYER_FLEAVE();
-
        return;
 }
 
@@ -5934,20 +6149,24 @@ _mmplayer_gst_make_decodebin(mmplayer_t *player)
 
        /* no-more-pad pad handling signal */
        _mmplayer_add_signal_connection(player, G_OBJECT(decodebin), MM_PLAYER_SIGNAL_TYPE_AUTOPLUG, "no-more-pads",
-                                               G_CALLBACK(__mmplayer_gst_decode_no_more_pads), (gpointer)player);
+                                               G_CALLBACK(_mmplayer_gst_decode_no_more_pads), (gpointer)player);
 
        _mmplayer_add_signal_connection(player, G_OBJECT(decodebin), MM_PLAYER_SIGNAL_TYPE_AUTOPLUG, "pad-removed",
-                                               G_CALLBACK(__mmplayer_gst_decode_pad_removed), (gpointer)player);
+                                               G_CALLBACK(_mmplayer_gst_decode_pad_removed), (gpointer)player);
 
        /* This signal is emitted when a pad for which there is no further possible
           decoding is added to the decodebin.*/
        _mmplayer_add_signal_connection(player, G_OBJECT(decodebin), MM_PLAYER_SIGNAL_TYPE_AUTOPLUG, "unknown-type",
-                                               G_CALLBACK(__mmplayer_gst_decode_unknown_type), (gpointer)player);
+                                               G_CALLBACK(_mmplayer_gst_decode_unknown_type), (gpointer)player);
 
        /* This signal is emitted whenever decodebin finds a new stream. It is emitted
           before looking for any elements that can handle that stream.*/
        _mmplayer_add_signal_connection(player, G_OBJECT(decodebin), MM_PLAYER_SIGNAL_TYPE_AUTOPLUG, "autoplug-continue",
-                                               G_CALLBACK(__mmplayer_gst_decode_autoplug_continue), (gpointer)player);
+                                               G_CALLBACK(_mmplayer_gst_decode_autoplug_continue), (gpointer)player);
+
+       if (player->need_video_dec_sorting || player->need_audio_dec_sorting)
+               _mmplayer_add_signal_connection(player, G_OBJECT(decodebin), MM_PLAYER_SIGNAL_TYPE_AUTOPLUG, "autoplug-sort",
+                                                       G_CALLBACK(_mmplayer_gst_decode_autoplug_sort), (gpointer)player);
 
        /* This signal is emitted whenever decodebin finds a new stream. It is emitted
           before looking for any elements that can handle that stream.*/
@@ -5956,7 +6175,7 @@ _mmplayer_gst_make_decodebin(mmplayer_t *player)
 
        /* This signal is emitted once decodebin has finished decoding all the data.*/
        _mmplayer_add_signal_connection(player, G_OBJECT(decodebin), MM_PLAYER_SIGNAL_TYPE_AUTOPLUG, "drained",
-                                               G_CALLBACK(__mmplayer_gst_decode_drained), (gpointer)player);
+                                               G_CALLBACK(_mmplayer_gst_decode_drained), (gpointer)player);
 
        /* This signal is emitted when a element is added to the bin.*/
        _mmplayer_add_signal_connection(player, G_OBJECT(decodebin), MM_PLAYER_SIGNAL_TYPE_AUTOPLUG, "element-added",
@@ -5993,7 +6212,7 @@ __mmplayer_gst_make_queue2(mmplayer_t *player)
        /* NOTE : in case of ts streaming, player could not get the correct duration info *
         *                skip the pull mode(file or ring buffering) setting. */
        if (dur_bytes > 0) {
-               if (!g_strrstr(player->type, "video/mpegts")) {
+               if (!g_strrstr(player->type_caps_str, "video/mpegts")) {
                        type = MUXED_BUFFER_TYPE_MEM_RING_BUFFER;
                        player->streamer->ring_buffer_size = player->ini.http_ring_buffer_size;
                }
@@ -6145,8 +6364,10 @@ ERROR:
                /* And, it still has a parent "player".
                 * You need to let the parent manage the object instead of unreffing the object directly.
                 */
-               gst_bin_remove(GST_BIN(mainbin[MMPLAYER_M_PIPE].gst), queue2);
-               gst_object_unref(queue2);
+               if (!gst_bin_remove(GST_BIN(mainbin[MMPLAYER_M_PIPE].gst), queue2)) {
+                       LOGE("failed to remove queue2");
+                       gst_object_unref(queue2);
+               }
                queue2 = NULL;
        }
 
@@ -6161,16 +6382,18 @@ ERROR:
                 * You need to let the parent manage the object instead of unreffing the object directly.
                 */
 
-               gst_bin_remove(GST_BIN(mainbin[MMPLAYER_M_PIPE].gst), decodebin);
-               gst_object_unref(decodebin);
+               if (!gst_bin_remove(GST_BIN(mainbin[MMPLAYER_M_PIPE].gst), decodebin)) {
+                       LOGE("failed to remove decodebin");
+                       gst_object_unref(decodebin);
+               }
                decodebin = NULL;
        }
 
        return FALSE;
 }
 
-static int
-__mmplayer_check_not_supported_codec(mmplayer_t *player, const gchar *factory_class, const gchar *mime)
+int
+_mmplayer_update_not_supported_codec_info(mmplayer_t *player, const gchar *factory_class, const gchar *mime)
 {
        MMPLAYER_FENTER();
 
@@ -6224,8 +6447,8 @@ DONE:
        return MM_ERROR_NONE;
 }
 
-static void
-__mmplayer_pipeline_complete(GstElement *decodebin,  gpointer data)
+void
+_mmplayer_pipeline_complete(GstElement *decodebin, gpointer data)
 {
        mmplayer_t *player = (mmplayer_t *)data;
 
@@ -6236,7 +6459,7 @@ __mmplayer_pipeline_complete(GstElement *decodebin,  gpointer data)
        /* remove fakesink. */
        if (!_mmplayer_gst_remove_fakesink(player,
                                &player->pipeline->mainbin[MMPLAYER_M_SRC_FAKESINK])) {
-               /* NOTE : __mmplayer_pipeline_complete() can be called several time. because
+               /* NOTE : _mmplayer_pipeline_complete() can be called several time. because
                 * signaling mechanism(pad-added, no-more-pad, new-decoded-pad) from various
                 * source element are not same. To overcome this situation, this function will called
                 * several places and several times. Therefore, this is not an error case.
@@ -6246,8 +6469,7 @@ __mmplayer_pipeline_complete(GstElement *decodebin,  gpointer data)
 
        LOGD("[handle: %p] pipeline has completely constructed", player);
 
-       if ((player->ini.async_start) &&
-               (player->msg_posted == FALSE) &&
+       if ((player->msg_posted == FALSE) &&
                (player->cmd >= MMPLAYER_COMMAND_START))
                __mmplayer_handle_missed_plugin(player);
 
@@ -6324,6 +6546,12 @@ __mmplayer_get_next_uri(mmplayer_t *player)
                return FALSE;
        }
 
+       if (!MMPLAYER_USE_DECODEBIN(player)) {
+               if (player->pipeline->mainbin[MMPLAYER_M_AUTOPLUG].gst)
+                       g_object_set(G_OBJECT(player->pipeline->mainbin[MMPLAYER_M_AUTOPLUG].gst),
+                               "uri", profile.uri, NULL);
+       }
+
        SECURE_LOGD("next playback uri: %s", uri);
        return TRUE;
 }
@@ -6382,6 +6610,8 @@ __mmplayer_verify_gapless_play_path(mmplayer_t *player)
        }
 
        num_of_uri = g_list_length(player->uri_info.uri_list);
+       if (!MMPLAYER_USE_DECODEBIN(player))
+               player->gapless.running = TRUE;
 
        LOGD("repeat count = %d, num_of_list = %d", count, num_of_uri);
 
@@ -6396,6 +6626,13 @@ __mmplayer_verify_gapless_play_path(mmplayer_t *player)
                        LOGD("there is no next uri and no repeat");
                        goto ERROR;
                }
+
+               if (!MMPLAYER_USE_DECODEBIN(player)) {
+                       if (player->pipeline->mainbin[MMPLAYER_M_AUTOPLUG].gst)
+                               g_object_set(G_OBJECT(player->pipeline->mainbin[MMPLAYER_M_AUTOPLUG].gst),
+                                       "uri", player->profile.uri, NULL);
+               }
+
                LOGD("looping cnt %d", count);
        } else {
                /* gapless playback path */
@@ -6411,10 +6648,96 @@ ERROR:
        return FALSE;
 }
 
+static void
+__mmplayer_remove_sinkpad (const GValue *item, gpointer user_data)
+{
+       GstPad *sinkpad = g_value_get_object (item);
+       GstElement *element = GST_ELEMENT(user_data);
+       if (!sinkpad || !element) {
+               LOGE("invalid parameter");
+               return;
+       }
+
+       LOGD("(%s)element release request pad(%s)", GST_ELEMENT_NAME(element), GST_PAD_NAME(sinkpad));
+       gst_element_release_request_pad(element, GST_PAD(sinkpad));
+}
+
+static gboolean
+__mmplayer_deactivate_combiner(mmplayer_t *player, mmplayer_track_type_e type)
+{
+       mmplayer_gst_element_t *sinkbin = NULL;
+       main_element_id_e concatId = MMPLAYER_M_NUM;
+       main_element_id_e sinkId = MMPLAYER_M_NUM;
+       gboolean send_notice = FALSE;
+       GstElement *element;
+       GstIterator *iter;
+
+       MMPLAYER_FENTER();
+       MMPLAYER_RETURN_VAL_IF_FAIL(player, FALSE);
+
+       LOGD("type %d", type);
+
+       switch (type) {
+       case MM_PLAYER_TRACK_TYPE_AUDIO:
+               concatId = MMPLAYER_M_A_CONCAT;
+               sinkId = MMPLAYER_A_BIN;
+               sinkbin = player->pipeline->audiobin;
+               break;
+       case MM_PLAYER_TRACK_TYPE_VIDEO:
+               concatId = MMPLAYER_M_V_CONCAT;
+               sinkId = MMPLAYER_V_BIN;
+               sinkbin = player->pipeline->videobin;
+               send_notice = TRUE;
+               break;
+       case MM_PLAYER_TRACK_TYPE_TEXT:
+               concatId = MMPLAYER_M_T_CONCAT;
+               sinkId = MMPLAYER_T_BIN;
+               sinkbin = player->pipeline->textbin;
+               break;
+       default:
+               LOGE("requested type is not supportable");
+               return FALSE;
+               break;
+       }
+
+       element = player->pipeline->mainbin[concatId].gst;
+       if (!element)
+               return TRUE;
+
+       if ((sinkbin) && (sinkbin[sinkId].gst)) {
+               GstPad *srcpad = gst_element_get_static_pad(element, "src");
+               GstPad *sinkpad = gst_element_get_static_pad(sinkbin[sinkId].gst, "sink");
+               if (srcpad && sinkpad) {
+                       /* after getting drained signal there is no data flows, so no need to do pad_block */
+                       LOGD("unlink %s:%s, %s:%s", GST_DEBUG_PAD_NAME(srcpad), GST_DEBUG_PAD_NAME(sinkpad));
+                       gst_pad_unlink(srcpad, sinkpad);
+
+                       /* send custom event to sink pad to handle it at video sink */
+                       if (send_notice) {
+                               LOGD("send custom event to sinkpad");
+                               GstStructure *s = gst_structure_new_empty("tizen/flush-buffer");
+                               GstEvent *event = gst_event_new_custom(GST_EVENT_CUSTOM_DOWNSTREAM, s);
+                               gst_pad_send_event(sinkpad, event);
+                       }
+               }
+               gst_object_unref(srcpad);
+               gst_object_unref(sinkpad);
+       }
+
+       LOGD("release concat request pad");
+       /* release and unref requests pad from the selector */
+       iter = gst_element_iterate_sink_pads(element);
+       while (gst_iterator_foreach(iter, __mmplayer_remove_sinkpad, element) == GST_ITERATOR_RESYNC)
+               gst_iterator_resync(iter);
+       gst_iterator_free(iter);
+
+       return TRUE;
+}
+
 static gboolean
 __mmplayer_deactivate_selector(mmplayer_t *player, mmplayer_track_type_e type)
 {
-       mmplayer_selector_t *selector = &player->selector[type];
+       mmplayer_track_t *selector = &player->track[type];
        mmplayer_gst_element_t *sinkbin = NULL;
        main_element_id_e selectorId = MMPLAYER_M_NUM;
        main_element_id_e sinkId = MMPLAYER_M_NUM;
@@ -6485,14 +6808,19 @@ __mmplayer_deactivate_selector(mmplayer_t *player, mmplayer_track_type_e type)
                LOGD("selector release");
 
                /* release and unref requests pad from the selector */
-               for (n = 0; n < selector->channels->len; n++) {
-                       GstPad *sinkpad = g_ptr_array_index(selector->channels, n);
+               for (n = 0; n < selector->streams->len; n++) {
+                       GstPad *sinkpad = g_ptr_array_index(selector->streams, n);
                        gst_element_release_request_pad((player->pipeline->mainbin[selectorId].gst), sinkpad);
                }
-               g_ptr_array_set_size(selector->channels, 0);
+
+               g_ptr_array_set_size(selector->streams, 0);
 
                gst_element_set_state(player->pipeline->mainbin[selectorId].gst, GST_STATE_NULL);
-               gst_bin_remove(GST_BIN_CAST(player->pipeline->mainbin[MMPLAYER_M_PIPE].gst), player->pipeline->mainbin[selectorId].gst);
+               if (!gst_bin_remove(GST_BIN_CAST(player->pipeline->mainbin[MMPLAYER_M_PIPE].gst),
+                                                       player->pipeline->mainbin[selectorId].gst)) {
+                       LOGE("failed to remove selector");
+                       gst_object_unref(player->pipeline->mainbin[selectorId].gst);
+               }
 
                player->pipeline->mainbin[selectorId].gst = NULL;
                selector = NULL;
@@ -6507,11 +6835,20 @@ __mmplayer_deactivate_old_path(mmplayer_t *player)
        MMPLAYER_FENTER();
        MMPLAYER_RETURN_IF_FAIL(player);
 
-       if ((!__mmplayer_deactivate_selector(player, MM_PLAYER_TRACK_TYPE_AUDIO)) ||
-               (!__mmplayer_deactivate_selector(player, MM_PLAYER_TRACK_TYPE_VIDEO)) ||
-               (!__mmplayer_deactivate_selector(player, MM_PLAYER_TRACK_TYPE_TEXT))) {
-               LOGE("deactivate selector error");
-               goto ERROR;
+       if (MMPLAYER_USE_DECODEBIN(player)) {
+               if ((!__mmplayer_deactivate_selector(player, MM_PLAYER_TRACK_TYPE_AUDIO)) ||
+                       (!__mmplayer_deactivate_selector(player, MM_PLAYER_TRACK_TYPE_VIDEO)) ||
+                       (!__mmplayer_deactivate_selector(player, MM_PLAYER_TRACK_TYPE_TEXT))) {
+                       LOGE("deactivate selector error");
+                       goto ERROR;
+               }
+       } else {
+               if ((!__mmplayer_deactivate_combiner(player, MM_PLAYER_TRACK_TYPE_AUDIO)) ||
+                       (!__mmplayer_deactivate_combiner(player, MM_PLAYER_TRACK_TYPE_VIDEO)) ||
+                       (!__mmplayer_deactivate_combiner(player, MM_PLAYER_TRACK_TYPE_TEXT))) {
+                       LOGE("deactivate concat error");
+                       goto ERROR;
+               }
        }
 
        _mmplayer_track_destroy(player);
@@ -6523,9 +6860,7 @@ __mmplayer_deactivate_old_path(mmplayer_t *player)
                player->streamer = NULL;
        }
 
-       MMPLAYER_PLAYBACK_LOCK(player);
        MMPLAYER_GAPLESS_PLAY_THREAD_SIGNAL(player);
-
        MMPLAYER_FLEAVE();
        return;
 
@@ -6590,9 +6925,9 @@ _mmplayer_set_next_uri(MMHandleType hplayer, const char *uri, bool is_first_path
                        player->uri_info.uri_list = g_list_append(player->uri_info.uri_list, g_strdup(uri));
                        SECURE_LOGD("add original path : %s", uri);
                } else {
-                       player->uri_info.uri_list = g_list_delete_link(player->uri_info.uri_list, g_list_nth(player->uri_info.uri_list, 0));
-                       player->uri_info.uri_list = g_list_insert(player->uri_info.uri_list, g_strdup(uri), 0);
-
+                       g_free(g_list_nth_data(player->uri_info.uri_list, 0));
+                       player->uri_info.uri_list = g_list_prepend(
+                               g_list_delete_link(player->uri_info.uri_list, player->uri_info.uri_list), g_strdup(uri));
                        SECURE_LOGD("change original path : %s", uri);
                }
        } else {
@@ -6640,7 +6975,7 @@ _mmplayer_get_next_uri(MMHandleType hplayer, char **uri)
        if (num_of_list > 0) {
                gint uri_idx = player->uri_info.uri_idx;
 
-               if (uri_idx < num_of_list-1)
+               if (uri_idx < num_of_list - 1)
                        uri_idx++;
                else
                        uri_idx = 0;
@@ -6655,8 +6990,8 @@ _mmplayer_get_next_uri(MMHandleType hplayer, char **uri)
        return MM_ERROR_NONE;
 }
 
-static void
-__mmplayer_gst_decode_unknown_type(GstElement *elem,  GstPad *pad,
+void
+_mmplayer_gst_decode_unknown_type(GstElement *elem, GstPad *pad,
        GstCaps *caps, gpointer data)
 {
        mmplayer_t *player = (mmplayer_t *)data;
@@ -6674,12 +7009,12 @@ __mmplayer_gst_decode_unknown_type(GstElement *elem,  GstPad *pad,
        MMPLAYER_FREEIF(caps_str);
 
        /* There is no available codec. */
-       __mmplayer_check_not_supported_codec(player, klass, mime);
+       _mmplayer_update_not_supported_codec_info(player, klass, mime);
 }
 
-static gboolean
-__mmplayer_gst_decode_autoplug_continue(GstElement *bin,  GstPad *pad,
-       GstCaps *caps,  gpointer data)
+gboolean
+_mmplayer_gst_decode_autoplug_continue(GstElement *bin, GstPad *pad,
+       GstCaps *caps, gpointer data)
 {
        mmplayer_t *player = (mmplayer_t *)data;
        const char *mime = NULL;
@@ -6710,16 +7045,14 @@ __mmplayer_gst_decode_autoplug_continue(GstElement *bin,  GstPad *pad,
                                        "content_audio_codec", "mobile-xmf", strlen("mobile-xmf"), NULL);
 
                MMPLAYER_FREEIF(caps_str);
-       } else if (g_str_has_prefix(mime, "video") && !player->ini.video_playback_supported) {
-               MMMessageParamType msg_param;
-               memset(&msg_param, 0, sizeof(MMMessageParamType));
-               msg_param.code = MM_ERROR_NOT_SUPPORT_API;
-               MMPLAYER_POST_MSG(player, MM_MESSAGE_ERROR, &msg_param);
-               LOGD("video file is not supported on this device");
-               ret = FALSE;
        } else if (g_str_has_prefix(mime, "video") && player->videodec_linked) {
-               LOGD("already video linked");
-               ret = FALSE;
+               if((MMPLAYER_IS_HTTP_LIVE_STREAMING(player)) || (MMPLAYER_IS_DASH_STREAMING(player))) {
+                       LOGD("video is already linked, allow the stream switch");
+                       ret = TRUE;
+               } else {
+                       LOGD("video is already linked");
+                       ret = FALSE;
+               }
        } else {
                LOGD("found new stream");
        }
@@ -6730,7 +7063,7 @@ __mmplayer_gst_decode_autoplug_continue(GstElement *bin,  GstPad *pad,
 static gboolean
 __mmplayer_is_audio_offload_device_type(mmplayer_t *player)
 {
-       gboolean ret = TRUE;
+       gboolean ret = FALSE;
        GDBusConnection *conn = NULL;
        GError *err = NULL;
        GVariant *result = NULL;
@@ -6740,9 +7073,8 @@ __mmplayer_is_audio_offload_device_type(mmplayer_t *player)
 
        conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
        if (!conn || err) {
-               LOGE("failed g_bus_get_sync() (%s)", err ? err->message : NULL);
+               LOGE("failed g_bus_get_sync() (%s)", (err ? err->message : "null"));
                g_error_free(err);
-               ret = FALSE;
                goto DONE;
        }
 
@@ -6758,9 +7090,8 @@ __mmplayer_is_audio_offload_device_type(mmplayer_t *player)
                                        NULL,
                                        &err);
        if (!result || err) {
-               LOGE("failed g_dbus_connection_call_sync() (%s)", err ? err->message : NULL);
+               LOGE("failed g_dbus_connection_call_sync() (%s)", (err ? err->message : "null"));
                g_error_free(err);
-               ret = FALSE;
                goto DONE;
        }
 
@@ -6768,10 +7099,8 @@ __mmplayer_is_audio_offload_device_type(mmplayer_t *player)
        g_variant_get(result, "(&s&s)", &dbus_device_type, &dbus_ret);
 
        LOGI("g_dbus_connection_call_sync() success (%s, %s)", dbus_device_type, dbus_ret);
-       if (strncmp("STREAM_MANAGER_RETURN_OK", dbus_ret, strlen(dbus_ret))) {
-               ret = FALSE;
+       if (strncmp("STREAM_MANAGER_RETURN_OK", dbus_ret, strlen(dbus_ret)))
                goto DONE;
-       }
 
        /* the device type is listed in ini file among audio-jack, bt-a2dp, usb-audio, builtin-speaker */
        for (idx = 0; player->ini.audio_offload_device_type[idx][0] != '\0'; idx++) {
@@ -6783,11 +7112,11 @@ __mmplayer_is_audio_offload_device_type(mmplayer_t *player)
        }
 
        LOGD("audio offload is not supportable");
-       ret = FALSE;
 
 DONE:
        g_variant_unref(result);
-       g_object_unref(conn);
+       if (conn)
+               g_object_unref(conn);
 
        return ret;
 }
@@ -6877,6 +7206,37 @@ __mmplayer_add_audio_device_connected_cb(mmplayer_t *player)
        return TRUE;
 }
 
+int _mmplayer_audio_offload_is_activated(MMHandleType hplayer, bool *activated)
+{
+       mmplayer_t *player = (mmplayer_t *)hplayer;
+
+       MMPLAYER_FENTER();
+       MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+       MMPLAYER_RETURN_VAL_IF_FAIL(activated, MM_ERROR_INVALID_ARGUMENT);
+
+       *activated = player->build_audio_offload;
+
+       LOGD("offload activated : %d", (int)*activated);
+
+       MMPLAYER_FLEAVE();
+       return MM_ERROR_NONE;
+}
+
+static gboolean
+__mmplayer_is_offload_supported_type(mmplayer_t *player)
+{
+       /* NOTE :
+          this function need to be updated according to the supported media format
+          @see player->ini.audio_offload_media_format */
+
+       if (__mmplayer_is_only_mp3_type(player->type_caps_str)) {
+               LOGD("offload supportable media format type");
+               return TRUE;
+       }
+
+       return FALSE;
+}
+
 static gboolean
 __mmplayer_can_build_audio_offload_path(mmplayer_t *player)
 {
@@ -6886,8 +7246,8 @@ __mmplayer_can_build_audio_offload_path(mmplayer_t *player)
        MMPLAYER_FENTER();
        MMPLAYER_RETURN_VAL_IF_FAIL(player && player->attrs, FALSE);
 
-       LOGD("current stream : %s, sink: %s", player->type, player->ini.audio_offload_sink_element);
-       if (!__mmplayer_is_only_mp3_type(player->type))
+       LOGD("current stream : %s, sink: %s", player->type_caps_str, player->ini.audio_offload_sink_element);
+       if (!__mmplayer_is_offload_supported_type(player))
                goto DONE;
 
        if (!strcmp(player->ini.audio_offload_sink_element, "")) {
@@ -6907,7 +7267,7 @@ __mmplayer_can_build_audio_offload_path(mmplayer_t *player)
        }
        gst_object_unref(factory);
 
-       if (__mmplayer_acquire_hw_resource(player,
+       if (_mmplayer_acquire_hw_resource(player,
                        MMPLAYER_RESOURCE_TYPE_AUDIO_OFFLOAD) != MM_ERROR_NONE) {
                LOGE("failed to acquire audio offload decoder resource");
                goto DONE;
@@ -6934,8 +7294,6 @@ static GstAutoplugSelectResult
 __mmplayer_check_codec_info(mmplayer_t *player, const char *klass, GstCaps *caps, char *factory_name)
 {
        GstAutoplugSelectResult ret = GST_AUTOPLUG_SELECT_TRY;
-       int idx = 0;
-       int codec_type = MM_PLAYER_CODEC_TYPE_DEFAULT;
        int audio_offload = 0;
 
        if ((g_strrstr(klass, "Codec/Decoder/Audio"))) {
@@ -6953,31 +7311,13 @@ __mmplayer_check_codec_info(mmplayer_t *player, const char *klass, GstCaps *caps
                        goto DONE;
                }
 
-               mm_attrs_get_int_by_name(player->attrs, "audio_codec_type", &codec_type);
-
-               LOGD("audio codec type: %d", codec_type);
-               if (codec_type == MM_PLAYER_CODEC_TYPE_HW) {
-                       /* sw codec will be skipped */
-                       for (idx = 0; player->ini.audiocodec_element_sw[idx][0] != '\0'; idx++) {
-                               if (strstr(factory_name, player->ini.audiocodec_element_sw[idx])) {
-                                       LOGW("skipping sw acodec:[%s] by codec type", factory_name);
-                                       ret = GST_AUTOPLUG_SELECT_SKIP;
-                                       goto DONE;
-                               }
-                       }
-               } else if (codec_type == MM_PLAYER_CODEC_TYPE_SW) {
-                       /* hw codec will be skipped */
-                       if (strcmp(player->ini.audiocodec_element_hw, "") &&
-                           g_strrstr(factory_name, player->ini.audiocodec_element_hw)) {
-                               LOGW("skipping hw acodec:[%s] by codec type", factory_name);
-                               ret = GST_AUTOPLUG_SELECT_SKIP;
-                               goto DONE;
-                       }
-               }
+               /* FIXME: If HW audio decoder is selected, related resource have to be acquired here.
+                                 And need to consider the multi-track audio content.
+                         There is no HW audio decoder in public. */
 
                /* set stream information */
                if (!player->audiodec_linked)
-                       __mmplayer_set_audio_attrs(player, caps);
+                       _mmplayer_set_audio_attrs(player, caps);
 
                /* update codec info */
                player->not_supported_codec &= MISSING_PLUGIN_VIDEO;
@@ -6986,27 +7326,6 @@ __mmplayer_check_codec_info(mmplayer_t *player, const char *klass, GstCaps *caps
 
        } else if (g_strrstr(klass, "Codec/Decoder/Video")) {
 
-               mm_attrs_get_int_by_name(player->attrs, "video_codec_type", &codec_type);
-
-               LOGD("video codec type: %d", codec_type);
-               if (codec_type == MM_PLAYER_CODEC_TYPE_HW) {
-                       /* sw codec is skipped */
-                       for (idx = 0; player->ini.videocodec_element_sw[idx][0] != '\0'; idx++) {
-                               if (strstr(factory_name, player->ini.videocodec_element_sw[idx])) {
-                                       LOGW("skipping sw vcodec:[%s] by codec type", factory_name);
-                                       ret = GST_AUTOPLUG_SELECT_SKIP;
-                                       goto DONE;
-                               }
-                       }
-               } else if (codec_type == MM_PLAYER_CODEC_TYPE_SW) {
-                       /* hw codec is skipped */
-                       if (g_strrstr(factory_name, player->ini.videocodec_element_hw)) {
-                               LOGW("skipping hw vcodec:[%s] by codec type", factory_name);
-                               ret = GST_AUTOPLUG_SELECT_SKIP;
-                               goto DONE;
-                       }
-               }
-
                if ((strlen(player->ini.videocodec_element_hw) > 0) &&
                        (g_strrstr(factory_name, player->ini.videocodec_element_hw))) {
 
@@ -7017,7 +7336,7 @@ __mmplayer_check_codec_info(mmplayer_t *player, const char *klass, GstCaps *caps
                                goto DONE;
                        }
 
-                       if (__mmplayer_acquire_hw_resource(player, MMPLAYER_RESOURCE_TYPE_VIDEO_DECODER) != MM_ERROR_NONE) {
+                       if (_mmplayer_acquire_hw_resource(player, MMPLAYER_RESOURCE_TYPE_VIDEO_DECODER) != MM_ERROR_NONE) {
                                LOGE("failed to acquire video decoder resource");
                                ret = GST_AUTOPLUG_SELECT_SKIP;
                                goto DONE;
@@ -7035,6 +7354,130 @@ DONE:
        return ret;
 }
 
+GValueArray *
+_mmplayer_gst_decode_autoplug_sort(GstElement *bin,
+               GstPad *pad, GstCaps *caps, GValueArray *factories, gpointer data)
+{
+#define DEFAULT_IDX 0xFFFF
+#define MIN_FACTORY_NUM 2
+       mmplayer_t *player = (mmplayer_t *)data;
+       GValueArray *new_factories = NULL;
+       GValue val = { 0, };
+       GstElementFactory *factory = NULL;
+       const gchar *klass = NULL;
+       gchar *factory_name = NULL;
+       guint hw_dec_idx = DEFAULT_IDX;
+       guint first_sw_dec_idx = DEFAULT_IDX;
+       guint last_sw_dec_idx = DEFAULT_IDX;
+       guint new_pos = DEFAULT_IDX;
+       guint rm_pos = DEFAULT_IDX;
+       int audio_codec_type;
+       int video_codec_type;
+       mmplayer_codec_type_e codec_type = MM_PLAYER_CODEC_TYPE_DEFAULT;
+
+       if (factories->n_values < MIN_FACTORY_NUM)
+               return NULL;
+
+       mm_attrs_get_int_by_name(player->attrs, MM_PLAYER_VIDEO_CODEC_TYPE, &video_codec_type);
+       mm_attrs_get_int_by_name(player->attrs, MM_PLAYER_AUDIO_CODEC_TYPE, &audio_codec_type);
+
+#ifdef __DEBUG__
+       LOGD("num of factory : %d, codec type %d, %d", factories->n_values, video_codec_type, audio_codec_type);
+#endif
+       for (int i = 0 ; i < factories->n_values ; i++) {
+               gchar *hw_dec_info = NULL;
+               gchar (*sw_dec_info)[PLAYER_INI_MAX_STRLEN] = {NULL, };
+
+               factory = g_value_get_object(g_value_array_get_nth(factories, i));
+               if (!factory) {
+                       LOGW("failed to get factory object");
+                       continue;
+               }
+               klass = gst_element_factory_get_klass(factory);
+               factory_name = GST_OBJECT_NAME(factory);
+
+#ifdef __DEBUG__
+               LOGD("Klass [%s] Factory [%s]", klass, factory_name);
+#endif
+               if (g_strrstr(klass, "Codec/Decoder/Audio")) {
+                       if (!player->need_audio_dec_sorting) {
+                               LOGD("sorting is not required");
+                               return NULL;
+                       }
+                       codec_type = audio_codec_type;
+                       hw_dec_info = player->ini.audiocodec_element_hw;
+                       sw_dec_info = player->ini.audiocodec_element_sw;
+               } else if (g_strrstr(klass, "Codec/Decoder/Video")) {
+                       if (!player->need_video_dec_sorting) {
+                               LOGD("sorting is not required");
+                               return NULL;
+                       }
+                       codec_type = video_codec_type;
+                       hw_dec_info = player->ini.videocodec_element_hw;
+                       sw_dec_info = player->ini.videocodec_element_sw;
+               } else {
+                       continue;
+               }
+
+               if (g_strrstr(factory_name, hw_dec_info)) {
+                       hw_dec_idx = i;
+               } else {
+                       for (int j = 0; sw_dec_info[j][0] != '\0'; j++) {
+                               if (strstr(factory_name, sw_dec_info[j])) {
+                                       last_sw_dec_idx = i;
+                                       if (first_sw_dec_idx == DEFAULT_IDX) {
+                                               first_sw_dec_idx = i;
+                                       }
+                               }
+                       }
+
+                       if (first_sw_dec_idx == DEFAULT_IDX)
+                               LOGW("unknown codec %s", factory_name);
+               }
+       }
+
+       if (hw_dec_idx == DEFAULT_IDX || first_sw_dec_idx == DEFAULT_IDX)
+               return NULL;
+
+       if (codec_type == MM_PLAYER_CODEC_TYPE_HW) {
+               if (hw_dec_idx < first_sw_dec_idx)
+                       return NULL;
+               new_pos = first_sw_dec_idx;
+               rm_pos = hw_dec_idx + 1;
+       } else if (codec_type == MM_PLAYER_CODEC_TYPE_SW) {
+               if (last_sw_dec_idx < hw_dec_idx)
+                       return NULL;
+               new_pos = last_sw_dec_idx + 1;
+               rm_pos = hw_dec_idx;
+       } else {
+               return NULL;
+       }
+
+       /* change position - insert H/W decoder according to the new position */
+       factory = g_value_get_object(g_value_array_get_nth(factories, hw_dec_idx));
+       if (!factory) {
+               LOGW("failed to get factory object");
+               return NULL;
+       }
+       new_factories = g_value_array_copy(factories);
+       g_value_init (&val, G_TYPE_OBJECT);
+       g_value_set_object (&val, factory);
+       g_value_array_insert(new_factories, new_pos, &val);
+       g_value_unset (&val);
+       g_value_array_remove(new_factories, rm_pos);    /* remove previous H/W element */
+
+       for (int i = 0 ; i < new_factories->n_values ; i++) {
+               factory = g_value_get_object(g_value_array_get_nth(new_factories, i));
+               if (factory)
+                       LOGD("[Re-arranged] Klass [%s] Factory [%s]",
+                               gst_element_factory_get_klass(factory), GST_OBJECT_NAME (factory));
+               else
+                       LOGE("[Re-arranged] failed to get factory object");
+       }
+
+       return new_factories;
+}
+
 gint
 _mmplayer_gst_decode_autoplug_select(GstElement *bin,  GstPad *pad,
        GstCaps *caps, GstElementFactory *factory, gpointer data)
@@ -7054,15 +7497,15 @@ _mmplayer_gst_decode_autoplug_select(GstElement *bin,  GstPad *pad,
        LOGD("[handle: %p] found new element [%s] to link", player, factory_name);
 
        /* store type string */
-       if (player->type == NULL) {
-               player->type = gst_caps_to_string(caps);
+       if (player->type_caps_str == NULL) {
+               player->type_caps_str = gst_caps_to_string(caps);
                __mmplayer_update_content_type_info(player);
        }
 
        /* filtering exclude keyword */
        for (idx = 0; player->ini.exclude_element_keyword[idx][0] != '\0'; idx++) {
                if (strstr(factory_name, player->ini.exclude_element_keyword[idx])) {
-                       LOGW("skipping [%s] by exculde keyword [%s]",
+                       LOGW("skipping [%s] by exclude keyword [%s]",
                                        factory_name, player->ini.exclude_element_keyword[idx]);
 
                        result = GST_AUTOPLUG_SELECT_SKIP;
@@ -7124,14 +7567,19 @@ _mmplayer_gst_decode_autoplug_select(GstElement *bin,  GstPad *pad,
                gint stype = 0;
                gint width = 0;
                GstStructure *str = NULL;
-               mm_attrs_get_int_by_name(player->attrs, "display_surface_type", &stype);
 
-               /* don't make video because of not required */
-               if ((stype == MM_DISPLAY_SURFACE_NULL) &&
-                       (!player->set_mode.video_export)) {
-                       LOGD("no need video decoding, expose pad");
-                       result = GST_AUTOPLUG_SELECT_EXPOSE;
-                       goto DONE;
+               /* parsebin in adaptivedemux get error if there is no parser */
+               if ((!g_strrstr(GST_ELEMENT_NAME(bin), "parsebin")) ||
+                       ((!MMPLAYER_IS_HTTP_LIVE_STREAMING(player)) && (!MMPLAYER_IS_DASH_STREAMING(player)))) {
+                       mm_attrs_get_int_by_name(player->attrs, "display_surface_type", &stype);
+
+                       /* don't make video because of not required */
+                       if ((stype == MM_DISPLAY_SURFACE_NULL) &&
+                               (!player->set_mode.video_export)) {
+                               LOGD("no need video decoding, expose pad");
+                               result = GST_AUTOPLUG_SELECT_EXPOSE;
+                               goto DONE;
+                       }
                }
 
                /* get w/h for omx state-tune */
@@ -7165,32 +7613,110 @@ DONE:
        return result;
 }
 
-static void
-__mmplayer_gst_decode_pad_removed(GstElement *elem,  GstPad *new_pad,
+void
+_mmplayer_gst_decode_pad_removed(GstElement *elem, GstPad *pad,
        gpointer data)
 {
-       //mmplayer_t *player = (mmplayer_t *)data;
-       GstCaps *caps = NULL;
+       int ret = MM_ERROR_NONE;
+       mmplayer_t *player = (mmplayer_t *)data;
+       mmplayer_gst_element_t *mainbin = player->pipeline->mainbin;
+       mmplayer_gst_element_t *videobin = player->pipeline->videobin;
+       gint timeout = MMPLAYER_STATE_CHANGE_TIMEOUT(player);
 
-       LOGD("[Decodebin2] pad-removed signal");
+       MMPLAYER_FENTER();
+       MMPLAYER_RETURN_IF_FAIL(player && player->pipeline && mainbin);
 
-       caps = gst_pad_query_caps(new_pad, NULL);
-       if (!caps) {
-               LOGW("query caps is NULL");
+       LOGD("decoded pad %s:%s removed", GST_DEBUG_PAD_NAME(pad));
+
+       if (MMPLAYER_USE_DECODEBIN(player))
+               return;
+
+       if (!videobin || !g_str_has_prefix(GST_PAD_NAME (pad), "video"))
+               return;
+
+       __mmplayer_release_signal_connection(player, MM_PLAYER_SIGNAL_TYPE_VIDEOBIN);
+
+       __mmplayer_del_sink(player, videobin[MMPLAYER_V_SINK].gst);
+
+       LOGD("remove videobin");
+       ret = _mmplayer_gst_set_state(player, videobin[MMPLAYER_V_BIN].gst,
+                               GST_STATE_NULL, FALSE, timeout);
+       if (ret != MM_ERROR_NONE) {
+               LOGE("fail to change state of videobin to NULL");
                return;
        }
 
-       gchar *caps_str = NULL;
-       caps_str = gst_caps_to_string(caps);
+       if (!gst_bin_remove(GST_BIN_CAST(mainbin[MMPLAYER_M_PIPE].gst), videobin[MMPLAYER_V_BIN].gst)) {
+               LOGE("failed to remove videobin");
+               gst_object_unref(GST_OBJECT(videobin[MMPLAYER_V_BIN].gst));
+       }
 
-       LOGD("pad removed caps : %s from %s", caps_str, GST_ELEMENT_NAME(elem));
+       LOGD("remove concat");
+       ret = _mmplayer_gst_set_state(player, mainbin[MMPLAYER_M_V_CONCAT].gst,
+                               GST_STATE_NULL, FALSE, timeout);
+       if (ret != MM_ERROR_NONE) {
+               LOGE("fail to change state of concat to NULL");
+               return;
+       }
 
-       MMPLAYER_FREEIF(caps_str);
-       gst_caps_unref(caps);
+       if (!gst_bin_remove(GST_BIN_CAST(mainbin[MMPLAYER_M_PIPE].gst), mainbin[MMPLAYER_M_V_CONCAT].gst)) {
+               LOGE("failed to remove video concat");
+               gst_object_unref(GST_OBJECT(mainbin[MMPLAYER_M_V_CONCAT].gst));
+       }
+
+       mainbin[MMPLAYER_M_V_CONCAT].gst = NULL;
+       mainbin[MMPLAYER_M_V_CONCAT].id = 0;
+       MMPLAYER_FREEIF(player->pipeline->videobin);
+
+       ret = __mmplayer_release_hw_resource(player, MMPLAYER_RESOURCE_TYPE_VIDEO_OVERLAY);
+       if (ret != MM_ERROR_NONE)
+               LOGE("failed to release overlay resources");
+
+       player->videodec_linked = 0;
+
+       MMPLAYER_GENERATE_DOT_IF_ENABLED(player, "pipeline-pad-removed");
+       MMPLAYER_FLEAVE();
 }
 
-static void
-__mmplayer_gst_decode_drained(GstElement *bin, gpointer data)
+void
+_mmplayer_gst_about_to_finish(GstElement *bin, gpointer data)
+{
+       mmplayer_t *player = (mmplayer_t *)data;
+
+       MMPLAYER_FENTER();
+       MMPLAYER_RETURN_IF_FAIL(player);
+
+       LOGD("got about to finish signal");
+
+       if (!MMPLAYER_CMD_TRYLOCK(player)) {
+               LOGW("Fail to get cmd lock");
+               return;
+       }
+
+       if (!__mmplayer_verify_gapless_play_path(player)) {
+               LOGD("decoding is finished.");
+               if (MMPLAYER_USE_DECODEBIN(player)) {
+                       MMPLAYER_CMD_UNLOCK(player);
+                       return;
+               }
+       }
+
+       if (MMPLAYER_USE_DECODEBIN(player)) {
+               _mmplayer_set_reconfigure_state(player, TRUE);
+               MMPLAYER_CMD_UNLOCK(player);
+               MMPLAYER_POST_MSG(player, MM_MESSAGE_FLUSH_BUFFER, NULL);
+               __mmplayer_deactivate_old_path(player);
+       } else {
+               player->gapless.update_segment[MM_PLAYER_TRACK_TYPE_AUDIO] = FALSE;
+               player->gapless.update_segment[MM_PLAYER_TRACK_TYPE_VIDEO] = FALSE;
+               MMPLAYER_CMD_UNLOCK(player);
+       }
+
+       MMPLAYER_FLEAVE();
+}
+
+void
+_mmplayer_gst_decode_drained(GstElement *bin, gpointer data)
 {
        mmplayer_t *player = (mmplayer_t *)data;
        GstIterator *iter = NULL;
@@ -7202,22 +7728,21 @@ __mmplayer_gst_decode_drained(GstElement *bin, gpointer data)
        MMPLAYER_FENTER();
        MMPLAYER_RETURN_IF_FAIL(player);
 
-       LOGD("__mmplayer_gst_decode_drained");
+       LOGD("got drained signal");
 
        if (!MMPLAYER_CMD_TRYLOCK(player)) {
                LOGW("Fail to get cmd lock");
                return;
        }
 
-       if (!player->gapless.reconfigure && /* If it is already checked, skip verify. */
-               !__mmplayer_verify_gapless_play_path(player)) {
+       if (!__mmplayer_verify_gapless_play_path(player)) {
                LOGD("decoding is finished.");
-               __mmplayer_reset_gapless_state(player);
                MMPLAYER_CMD_UNLOCK(player);
                return;
        }
 
-       player->gapless.reconfigure = TRUE;
+       _mmplayer_set_reconfigure_state(player, TRUE);
+       MMPLAYER_CMD_UNLOCK(player);
 
        /* check decodebin src pads whether they received EOS or not */
        iter = gst_element_iterate_src_pads(player->pipeline->mainbin[MMPLAYER_M_AUTOPLUG].gst);
@@ -7247,7 +7772,6 @@ __mmplayer_gst_decode_drained(GstElement *bin, gpointer data)
 
        if (!is_all_drained) {
                LOGD("Wait util the all pads get EOS.");
-               MMPLAYER_CMD_UNLOCK(player);
                MMPLAYER_FLEAVE();
                return;
        }
@@ -7256,15 +7780,14 @@ __mmplayer_gst_decode_drained(GstElement *bin, gpointer data)
        player->gapless.update_segment[MM_PLAYER_TRACK_TYPE_VIDEO] = FALSE;
 
        /* deactivate pipeline except sinkbins to set up the new pipeline of next uri*/
-       MMPLAYER_POST_MSG(player, MM_MESSAGE_GAPLESS_CONSTRUCTION, NULL); /* post message for gapless */
+       MMPLAYER_POST_MSG(player, MM_MESSAGE_FLUSH_BUFFER, NULL); /* post message for gapless */
        __mmplayer_deactivate_old_path(player);
-       MMPLAYER_CMD_UNLOCK(player);
 
        MMPLAYER_FLEAVE();
 }
 
 void
-_mmplayer_gst_element_added(GstElement *bin, GstElement *element, gpointer data)
+_mmplayer_gst_element_added(GstBin *bin, GstElement *element, gpointer data)
 {
        mmplayer_t *player = (mmplayer_t *)data;
        const gchar *klass = NULL;
@@ -7278,70 +7801,115 @@ _mmplayer_gst_element_added(GstElement *bin, GstElement *element, gpointer data)
        if (__mmplayer_add_dump_buffer_probe(player, element))
                LOGD("add buffer probe");
 
-       if (g_strrstr(klass, "Codec/Decoder/Audio")) {
-               gchar *selected = NULL;
-               selected = g_strdup(GST_ELEMENT_NAME(element));
-               player->audio_decoders = g_list_append(player->audio_decoders, selected);
-       }
-
-       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);
+       if (g_strrstr(klass, "Decoder")) {
+               if (g_strrstr(klass, "Audio")) {
+                       player->audio_decoders = g_list_append(player->audio_decoders,
+                                                                                                                                       g_strdup(GST_ELEMENT_NAME(element)));
 
+                       /* update codec info */
+                       player->not_supported_codec &= MISSING_PLUGIN_VIDEO;
+                       player->can_support_codec |= FOUND_PLUGIN_AUDIO;
+                       player->audiodec_linked = 1;
+               } else if (g_strrstr(klass, "Video")) {
+                       GstElement *video_parse = player->pipeline->mainbin[MMPLAYER_M_V_PARSE].gst;
+                       /* update codec info */
+                       player->not_supported_codec &= MISSING_PLUGIN_AUDIO;
+                       player->can_support_codec |= FOUND_PLUGIN_VIDEO;
+                       player->videodec_linked = 1;
+
+                       if (video_parse) {
+                               GstPad *srcpad = gst_element_get_static_pad (video_parse, "src");
+                               if (srcpad) {
+                                       GstCaps *caps = NULL;
+                                       GstStructure *str = NULL;
+                                       const gchar *name = NULL;
+                                       gboolean caps_ret = TRUE;
+
+                                       MMPLAYER_GST_GET_CAPS_INFO_FROM_PAD (srcpad, caps, str, name, caps_ret);
+                                       if (caps_ret && str) {
+                                               const gchar *stream_format = gst_structure_get_string (str, "stream-format");
+                                               if (stream_format && g_strrstr(stream_format, "byte-stream")) {
+                                                       if ((g_object_class_find_property(G_OBJECT_GET_CLASS(video_parse), "config-interval"))) {
+                                                               g_object_set(G_OBJECT(video_parse), "config-interval", -1, NULL);
+                                                               LOGD("Send SPS and PPS Insertion every IDR frame");
+                                                       }
+                                               }
+                                       }
+                                       gst_object_unref(GST_OBJECT(srcpad));
+                               }
+                       }
+               }
        } else if (g_strrstr(klass, "Demuxer")) {
+               if (g_strrstr(klass, "Adaptive")) {
+                       player->pipeline->mainbin[MMPLAYER_M_ADAPTIVE_DEMUX].id = MMPLAYER_M_ADAPTIVE_DEMUX;
+                       player->pipeline->mainbin[MMPLAYER_M_ADAPTIVE_DEMUX].gst = element;
+
+                       MMPLAYER_FREEIF(player->type_caps_str);
+
+                       if (g_strrstr(factory_name, "hlsdemux")) {
+                               player->type_caps_str = g_strdup("application/x-hls");
+                               player->profile.uri_type = MM_PLAYER_URI_TYPE_HLS;
+                       } else if (g_strrstr(factory_name, "dashdemux")) {
+                               player->type_caps_str = g_strdup("application/dash+xml");
+                               player->profile.uri_type = MM_PLAYER_URI_TYPE_DASH;
+                       } else {
+                               LOGE("not supported type");
+                               return;
+                       }
+                       player->streamer->is_adaptive_streaming = TRUE;
+
+                       if (player->streamer->buffering_req.prebuffer_time <= MIN_BUFFERING_TIME)
+                               player->streamer->buffering_req.prebuffer_time = DEFAULT_PREBUFFERING_TIME;
+
+                       LOGD("max variant limit: %d, %d, %d, prebuffer time: %d ms",
+                               player->adaptive_info.limit.bandwidth,
+                               player->adaptive_info.limit.width,
+                               player->adaptive_info.limit.height,
+                               player->streamer->buffering_req.prebuffer_time);
+
+                       g_object_set(player->pipeline->mainbin[MMPLAYER_M_ADAPTIVE_DEMUX].gst,
+                               "max-bitrate", player->adaptive_info.limit.bandwidth,
+                               "max-video-width", player->adaptive_info.limit.width,
+                               "max-video-height", player->adaptive_info.limit.height,
+                               "low-watermark-time", (guint64)(player->streamer->buffering_req.prebuffer_time * GST_MSECOND),
+                               NULL);
+               } else {
 #ifdef __DEBUG__
-               LOGD("plugged element is demuxer. take it");
+                       LOGD("plugged element is demuxer. take it");
 #endif
-               player->pipeline->mainbin[MMPLAYER_M_DEMUX].id = MMPLAYER_M_DEMUX;
-               player->pipeline->mainbin[MMPLAYER_M_DEMUX].gst = element;
-       }
-
-       if (g_strrstr(factory_name, "asfdemux") || g_strrstr(factory_name, "qtdemux") || g_strrstr(factory_name, "avidemux")) {
-               int surface_type = 0;
-
-               mm_attrs_get_int_by_name(player->attrs, "display_surface_type", &surface_type);
+                       player->pipeline->mainbin[MMPLAYER_M_DEMUX].id = MMPLAYER_M_DEMUX;
+                       player->pipeline->mainbin[MMPLAYER_M_DEMUX].gst = element;
+               }
+       } else if (g_strrstr(klass, "Parser") && (g_strrstr(klass, "Video"))) {
+               player->pipeline->mainbin[MMPLAYER_M_V_PARSE].id = MMPLAYER_M_V_PARSE;
+               player->pipeline->mainbin[MMPLAYER_M_V_PARSE].gst = element;
        }
 
-       // to support trust-zone only
-       if (g_strrstr(factory_name, "asfdemux")) {
-               LOGD("set file-location %s", player->profile.uri);
-               g_object_set(G_OBJECT(element), "file-location", player->profile.uri, NULL);
-       } else if (g_strrstr(factory_name, "legacyh264parse")) {
-               LOGD("[%s] output-format to legacyh264parse", "mssdemux");
-               g_object_set(G_OBJECT(element), "output-format", 1, NULL); /* NALU/Byte Stream format */
-       } else if (g_strrstr(factory_name, "mpegaudioparse")) {
+       if (g_strrstr(factory_name, "mpegaudioparse")) {
                if ((MMPLAYER_IS_HTTP_STREAMING(player)) &&
-                       (__mmplayer_is_only_mp3_type(player->type))) {
+                       (__mmplayer_is_only_mp3_type(player->type_caps_str))) {
                        LOGD("[mpegaudioparse] set streaming pull mode.");
                        g_object_set(G_OBJECT(element), "http-pull-mp3dec", TRUE, NULL);
                }
-       } else if (g_strrstr(factory_name, player->ini.videocodec_element_hw)) {
-               player->pipeline->mainbin[MMPLAYER_M_DEC1].gst = element;
-       }
-
-       if ((player->pipeline->mainbin[MMPLAYER_M_DEMUX].gst) &&
+       } else if ((player->pipeline->mainbin[MMPLAYER_M_DEMUX].gst) &&
                (g_strrstr(GST_ELEMENT_NAME(element), "multiqueue"))) {
+
                LOGD("plugged element is multiqueue. take it %s", GST_ELEMENT_NAME(element));
 
+               /* set mq unlinked cache size to avoid not-linked error */
+               gboolean sync_by_running_time = FALSE;
+               g_object_get(G_OBJECT(element), "sync-by-running-time", &sync_by_running_time, NULL);
+               if (sync_by_running_time)
+                       g_object_set(G_OBJECT(element), "unlinked-cache-time", MQ_UNLINKED_CACHE_TIME, NULL);
+
                player->pipeline->mainbin[MMPLAYER_M_DEMUXED_S_BUFFER].id = MMPLAYER_M_DEMUXED_S_BUFFER;
                player->pipeline->mainbin[MMPLAYER_M_DEMUXED_S_BUFFER].gst = element;
 
-               if ((MMPLAYER_IS_HTTP_STREAMING(player)) ||
-                       (MMPLAYER_IS_HTTP_LIVE_STREAMING(player)) ||
-                       (MMPLAYER_IS_DASH_STREAMING(player))) {
+               if (MMPLAYER_IS_HTTP_STREAMING(player)) {
                        /* in case of multiqueue, max bytes size is defined with fixed value in mm_player_streaming.h*/
                        _mm_player_streaming_set_multiqueue(player->streamer, element);
                        _mm_player_streaming_sync_property(player->streamer, player->pipeline->mainbin[MMPLAYER_M_AUTOPLUG].gst);
                }
-
        }
 
        return;
@@ -7356,17 +7924,6 @@ __mmplayer_release_misc(mmplayer_t *player)
 
        MMPLAYER_RETURN_IF_FAIL(player);
 
-       player->video_decoded_cb = NULL;
-       player->video_decoded_cb_user_param = NULL;
-       player->video_stream_prerolled = false;
-
-       player->audio_decoded_cb = NULL;
-       player->audio_decoded_cb_user_param = NULL;
-       player->audio_extract_opt = MM_PLAYER_AUDIO_EXTRACT_DEFAULT;
-
-       player->audio_stream_changed_cb = NULL;
-       player->audio_stream_changed_cb_user_param = NULL;
-
        player->sent_bos = FALSE;
        player->playback_rate = DEFAULT_PLAYBACK_RATE;
 
@@ -7443,43 +8000,45 @@ __mmplayer_release_misc(mmplayer_t *player)
 static void
 __mmplayer_release_misc_post(mmplayer_t *player)
 {
-       char *original_uri = NULL;
+       gchar *original_uri = NULL;
        MMPLAYER_FENTER();
 
        /* player->pipeline is already released before. */
-
        MMPLAYER_RETURN_IF_FAIL(player);
 
-       mm_player_set_attribute((MMHandleType)player, NULL, "content_video_found", 0, NULL);
+       player->video_decoded_cb = NULL;
+       player->video_decoded_cb_user_param = NULL;
+       player->video_stream_prerolled = false;
+
+       player->audio_decoded_cb = NULL;
+       player->audio_decoded_cb_user_param = NULL;
+       player->audio_extract_opt = MM_PLAYER_AUDIO_EXTRACT_DEFAULT;
+
+       player->audio_stream_changed_cb = NULL;
+       player->audio_stream_changed_cb_user_param = NULL;
+
+       mm_player_set_attribute((MMHandleType)player, NULL,
+               "content_video_found", 0, MM_PLAYER_AUDIO_ONLY, 0, NULL);
 
        /* clean found audio decoders */
        if (player->audio_decoders) {
-               GList *a_dec = player->audio_decoders;
-               for (; a_dec; a_dec = g_list_next(a_dec)) {
-                       gchar *name = a_dec->data;
-                       MMPLAYER_FREEIF(name);
-               }
-               g_list_free(player->audio_decoders);
+               g_list_free_full(player->audio_decoders, (GDestroyNotify)g_free);
                player->audio_decoders = NULL;
        }
 
        /* clean the uri list except original uri */
-       if (player->uri_info.uri_list) {
+       if (player->uri_info.uri_list && g_list_length(player->uri_info.uri_list) > 1) {
+               GList *tmp = NULL;
                original_uri = g_list_nth_data(player->uri_info.uri_list, 0);
+               tmp = g_list_remove_link(player->uri_info.uri_list, player->uri_info.uri_list);
+               g_list_free_full(tmp, (GDestroyNotify)g_free);
 
                if (!original_uri)
                        LOGW("failed to get original uri info");
 
                mm_player_set_attribute((MMHandleType)player, NULL, "profile_uri",
                                original_uri, (original_uri) ? strlen(original_uri) : (0), NULL);
-
-               GList *uri_list = player->uri_info.uri_list;
-               for (; uri_list; uri_list = g_list_next(uri_list)) {
-                       gchar *uri = uri_list->data;
-                       MMPLAYER_FREEIF(uri);
-               }
-               g_list_free(player->uri_info.uri_list);
-               player->uri_info.uri_list = NULL;
+               MMPLAYER_FREEIF(original_uri);
        }
 
        /* clear the audio stream buffer list */
@@ -7542,14 +8101,17 @@ _mmplayer_cancel_eos_timer(mmplayer_t *player)
 }
 
 static void
-__mmplayer_add_sink(mmplayer_t *player, GstElement *sink)
+__mmplayer_add_sink(mmplayer_t *player, GstElement *sink, gboolean first)
 {
        MMPLAYER_FENTER();
 
        MMPLAYER_RETURN_IF_FAIL(player);
        MMPLAYER_RETURN_IF_FAIL(sink);
 
-       player->sink_elements = g_list_append(player->sink_elements, sink);
+       if (first)
+               player->sink_elements = g_list_prepend(player->sink_elements, sink);
+       else
+               player->sink_elements = g_list_append(player->sink_elements, sink);
 
        MMPLAYER_FLEAVE();
 }
@@ -7638,7 +8200,7 @@ __mmplayer_release_signal_connection(mmplayer_t *player, mmplayer_signal_type_e
        for (; sig_list; sig_list = sig_list->next) {
                item = sig_list->data;
 
-               if (item && item->obj && GST_IS_ELEMENT(item->obj)) {
+               if (item && item->obj) {
                        if (g_signal_handler_is_connected(item->obj, item->sig))
                                g_signal_handler_disconnect(item->obj, item->sig);
                }
@@ -7655,7 +8217,7 @@ __mmplayer_release_signal_connection(mmplayer_t *player, mmplayer_signal_type_e
 }
 
 int
-_mmplayer_change_videosink(MMHandleType handle, MMDisplaySurfaceType surface_type, unsigned int wl_surface_id)
+_mmplayer_change_videosink(MMHandleType handle, MMDisplaySurfaceType surface_type, int wl_surface_id)
 {
        mmplayer_t *player = 0;
        int prev_display_surface_type = 0;
@@ -7698,7 +8260,7 @@ _mmplayer_change_videosink(MMHandleType handle, MMDisplaySurfaceType surface_typ
        /* videobin is not created yet, so we just set attributes related to display surface */
        LOGD("store display attribute for given surface type(%d)", surface_type);
        mm_player_set_attribute(handle, NULL, "display_surface_type", surface_type,
-                       "display_overlay", (int)wl_surface_id, NULL);
+                       "display_overlay", wl_surface_id, NULL);
 
        MMPLAYER_FLEAVE();
        return MM_ERROR_NONE;
@@ -7755,7 +8317,7 @@ _mmplayer_sync_subtitle_pipeline(mmplayer_t *player)
        current_state = GST_STATE(mainbin[MMPLAYER_M_PIPE].gst);
 
        // sync clock with current pipeline
-       curr_clock = GST_ELEMENT_CLOCK(player->pipeline->mainbin[MMPLAYER_M_PIPE].gst);
+       curr_clock = gst_element_get_clock(player->pipeline->mainbin[MMPLAYER_M_PIPE].gst);
        curr_time = gst_clock_get_time(curr_clock);
 
        base_time = gst_element_get_base_time(GST_ELEMENT_CAST(player->pipeline->mainbin[MMPLAYER_M_PIPE].gst));
@@ -7774,6 +8336,8 @@ _mmplayer_sync_subtitle_pipeline(mmplayer_t *player)
                if (GST_STATE_CHANGE_FAILURE == ret) {
                        LOGE("fail to state change.");
                        result = MM_ERROR_PLAYER_INTERNAL;
+                       if (curr_clock)
+                               gst_object_unref(curr_clock);
                        goto ERROR;
                }
        }
@@ -7816,7 +8380,7 @@ ERROR:
        /* release signal */
        __mmplayer_release_signal_connection(player, MM_PLAYER_SIGNAL_TYPE_TEXTBIN);
 
-       /* release textbin with it's childs */
+       /* release textbin with it's children */
        MMPLAYER_RELEASE_ELEMENT(player, player->pipeline->textbin, MMPLAYER_T_BIN);
        MMPLAYER_FREEIF(player->pipeline->textbin);
        player->pipeline->textbin = NULL;
@@ -8011,6 +8575,69 @@ _mmplayer_set_external_subtitle_path(MMHandleType hplayer, const char *filepath)
 }
 
 static int
+__mmplayer_switch_stream(mmplayer_t *player, mmplayer_track_type_e type, int index)
+{
+       guint active_idx = 0;
+       GstStream *stream = NULL;
+       GList *streams = NULL;
+       GstCaps *caps = NULL;
+
+       MMPLAYER_FENTER();
+       LOGD("Switching Streams... type: %d, index: %d", type, index);
+
+       player->track[type].active_track_index = index;
+
+       for (int i = 0; i < MM_PLAYER_TRACK_TYPE_MAX; i++) {
+               /* FIXME: need to consider the non display type or audio only in case of MM_PLAYER_TRACK_TYPE_VIDEO */
+               LOGD("track type:%d, total: %d, active: %d", i,
+                               player->track[i].total_track_num, player->track[i].active_track_index);
+               if (player->track[i].total_track_num > 0 &&
+                       player->track[i].active_track_index > INVALID_TRACK_INDEX) {
+                       active_idx = player->track[i].active_track_index;
+                       stream = g_ptr_array_index(player->track[i].streams, active_idx);
+                       streams = g_list_append (streams, (gchar *)gst_stream_get_stream_id(stream));
+                       LOGD("Selecting %d type stream : %s\n", i, gst_stream_get_stream_id(stream));
+
+                       if (i == MM_PLAYER_TRACK_TYPE_AUDIO) {
+                               caps = gst_stream_get_caps(stream);
+                               if (caps) {
+                                       _mmplayer_set_audio_attrs(player, caps);
+                                       gst_caps_unref(caps);
+                               }
+                       }
+               }
+       }
+
+       if (streams) {
+               LOGD("send select stream event");
+               gst_element_send_event(player->pipeline->mainbin[MMPLAYER_M_AUTOPLUG].gst,
+                               gst_event_new_select_streams(streams));
+               g_list_free(streams);
+       }
+
+       /* in paused state, seek to current pos to flush mq buffer and release waiting task */
+       if (MMPLAYER_CURRENT_STATE(player) == MM_PLAYER_STATE_PAUSED) {
+               gint64 pos_nsec = GST_CLOCK_TIME_NONE;
+
+               if (!gst_element_query_position(player->pipeline->mainbin[MMPLAYER_M_PIPE].gst, GST_FORMAT_TIME, &pos_nsec))
+                       pos_nsec = player->last_position;
+
+               LOGD("current pos %" GST_TIME_FORMAT ", rate = %f", GST_TIME_ARGS(pos_nsec), player->playback_rate);
+
+               if (!_mmplayer_gst_seek(player, player->pipeline->mainbin[MMPLAYER_M_PIPE].gst,
+                                       player->playback_rate, GST_FORMAT_TIME,
+                                       (GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE),
+                                       GST_SEEK_TYPE_SET, pos_nsec, GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE)) {
+                       LOGW("failed to seek");
+                       return MM_ERROR_PLAYER_INTERNAL;
+               }
+       }
+
+       MMPLAYER_FLEAVE();
+       return MM_ERROR_NONE;
+}
+
+static int
 __mmplayer_change_selector_pad(mmplayer_t *player, mmplayer_track_type_e type, int index)
 {
        int result = MM_ERROR_NONE;
@@ -8046,7 +8673,7 @@ __mmplayer_change_selector_pad(mmplayer_t *player, mmplayer_track_type_e type, i
                goto EXIT;
        }
 
-       total_track_num = player->selector[type].total_track_num;
+       total_track_num = player->track[type].total_track_num;
        if (total_track_num <= 0) {
                result = MM_ERROR_PLAYER_NO_OP;
                LOGD("Language list is not available");
@@ -8086,7 +8713,10 @@ __mmplayer_change_selector_pad(mmplayer_t *player, mmplayer_track_type_e type, i
                gst_object_unref(sinkpad);
 
        if (type == MM_PLAYER_TRACK_TYPE_AUDIO)
-               __mmplayer_set_audio_attrs(player, caps);
+               _mmplayer_set_audio_attrs(player, caps);
+
+       if (caps)
+               gst_caps_unref(caps);
 
 EXIT:
        MMPLAYER_FREEIF(change_pad_name);
@@ -8103,24 +8733,24 @@ _mmplayer_change_track_language(MMHandleType hplayer, mmplayer_track_type_e type
        gint current_active_index = 0;
 
        GstState current_state = GST_STATE_VOID_PENDING;
-       GstEvent *event = NULL;
        gint64 time = 0;
 
        MMPLAYER_FENTER();
 
        player = (mmplayer_t *)hplayer;
        MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+       MMPLAYER_RETURN_VAL_IF_FAIL(type < MM_PLAYER_TRACK_TYPE_MAX, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        if (!player->pipeline) {
                LOGE("Track %d pre setting -> %d", type, index);
 
-               player->selector[type].active_pad_index = index;
+               player->track[type].active_track_index = index;
                goto EXIT;
        }
 
        mainbin = player->pipeline->mainbin;
 
-       current_active_index = player->selector[type].active_pad_index;
+       current_active_index = player->track[type].active_track_index;
 
        /*If index is same as running index no need to change the pad*/
        if (current_active_index == index)
@@ -8134,27 +8764,34 @@ _mmplayer_change_track_language(MMHandleType hplayer, mmplayer_track_type_e type
        current_state = GST_STATE(mainbin[MMPLAYER_M_PIPE].gst);
        if (current_state < GST_STATE_PAUSED) {
                result = MM_ERROR_PLAYER_INVALID_STATE;
-               LOGW("Pipeline not in porper state");
+               LOGW("Pipeline not in proper state");
                goto EXIT;
        }
 
-       result = __mmplayer_change_selector_pad(player, type, index);
+       if (MMPLAYER_USE_DECODEBIN(player))
+               result = __mmplayer_change_selector_pad(player, type, index);
+       else
+               result = __mmplayer_switch_stream(player, type, index);
+
        if (result != MM_ERROR_NONE) {
-               LOGE("change selector pad error");
+               LOGE("failed to change track");
                goto EXIT;
        }
 
-       player->selector[type].active_pad_index = index;
+       player->track[type].active_track_index = index;
 
-       if (current_state == GST_STATE_PLAYING) {
-               event = gst_event_new_seek(player->playback_rate, GST_FORMAT_TIME,
-                       (GstSeekFlags)(GST_SEEK_FLAG_SEGMENT | GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_SKIP),
-                       GST_SEEK_TYPE_SET, time, GST_SEEK_TYPE_NONE, -1);
-               if (event) {
-                       _mmplayer_gst_send_event_to_sink(player, event);
-               } else {
-                       result = MM_ERROR_PLAYER_INTERNAL;
-                       goto EXIT;
+       if (MMPLAYER_USE_DECODEBIN(player)) {
+               GstEvent *event = NULL;
+               if (current_state == GST_STATE_PLAYING) {
+                       event = gst_event_new_seek(player->playback_rate, GST_FORMAT_TIME,
+                               (GstSeekFlags)(GST_SEEK_FLAG_SEGMENT | GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_SKIP),
+                               GST_SEEK_TYPE_SET, time, GST_SEEK_TYPE_NONE, -1);
+                       if (event) {
+                               _mmplayer_gst_send_event_to_sink(player, event);
+                       } else {
+                               result = MM_ERROR_PLAYER_INTERNAL;
+                               goto EXIT;
+                       }
                }
        }
 
@@ -8360,7 +8997,7 @@ _mmplayer_manage_external_storage_state(MMHandleType hplayer, int id, int state)
        if (state != STORAGE_STATE_UNMOUNTABLE && state != STORAGE_STATE_REMOVED)
                return MM_ERROR_NONE;
 
-       /* FIXME: text path should be handled seperately. */
+       /* FIXME: text path should be handled separately. */
        if (((player->storage_info[MMPLAYER_PATH_VOD].type == STORAGE_TYPE_EXTERNAL)
                && (player->storage_info[MMPLAYER_PATH_VOD].id == id)) ||
                ((player->storage_info[MMPLAYER_PATH_TEXT].type == STORAGE_TYPE_EXTERNAL)
@@ -8445,7 +9082,7 @@ _mmplayer_set_max_adaptive_variant_limit(MMHandleType hplayer, int bandwidth, in
        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);
+                                               "max-bitrate", bandwidth, "max-video-width", width, "max-video-height", height, NULL);
 
                /* FIXME: seek to current position for applying new variant limitation */
        }
@@ -8500,48 +9137,66 @@ _mmplayer_get_streaming_buffering_time(MMHandleType hplayer, int *prebuffer_ms,
 }
 
 int
-_mmplayer_set_codec_type(MMHandleType hplayer, mmplayer_stream_type_e stream_type, mmplayer_video_codec_type_e codec_type)
+_mmplayer_set_codec_type(MMHandleType hplayer, mmplayer_stream_type_e stream_type, mmplayer_codec_type_e codec_type)
 {
 #define IDX_FIRST_SW_CODEC 0
        mmplayer_t *player = (mmplayer_t *)hplayer;
-       const char *attr_name = (stream_type == MM_PLAYER_STREAM_TYPE_AUDIO) ? (MM_PLAYER_AUDIO_CODEC_TYPE) : (MM_PLAYER_VIDEO_CODEC_TYPE);
+       int default_codec_type = MM_PLAYER_CODEC_TYPE_DEFAULT;
+       const char *attr_name = NULL;
+       const char *default_type = NULL;
+       const char *element_hw = NULL;
+       const char *element_sw = NULL;
 
        MMPLAYER_FENTER();
        MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
-       LOGD("ini setting : [a][h:%s][s:%s] / [v][h:%s][s:%s]",
-               player->ini.audiocodec_element_hw, player->ini.audiocodec_element_sw[IDX_FIRST_SW_CODEC],
-               player->ini.videocodec_element_hw, player->ini.videocodec_element_sw[IDX_FIRST_SW_CODEC]);
+       LOGD("stream type: %d, codec_type: %d", stream_type, codec_type);
 
+       /* FIXME: player need to know whether the decoder exist or not about required codec type since 6.0*/
        switch (stream_type) {
        case MM_PLAYER_STREAM_TYPE_AUDIO:
-       /* to support audio codec selection, codec info have to be added in ini file as below.
-          audio codec element hw = xxxx
-          audio codec element sw = avdec */
-               if (((codec_type == MM_PLAYER_CODEC_TYPE_HW) &&
-                        (!strcmp(player->ini.audiocodec_element_hw, ""))) ||
-                       ((codec_type == MM_PLAYER_CODEC_TYPE_SW) &&
-                        (!strcmp(player->ini.audiocodec_element_sw[IDX_FIRST_SW_CODEC], "")))) {
-                       LOGE("There is no audio codec info for codec_type %d", codec_type);
-                       return MM_ERROR_PLAYER_NO_OP;
-               }
-       break;
+               attr_name = MM_PLAYER_AUDIO_CODEC_TYPE;
+               default_type = player->ini.audiocodec_default_type;
+               element_hw = player->ini.audiocodec_element_hw;
+               element_sw = player->ini.audiocodec_element_sw[IDX_FIRST_SW_CODEC];
+               break;
        case MM_PLAYER_STREAM_TYPE_VIDEO:
-       /* to support video codec selection, codec info have to be added in ini file as below.
-          video codec element hw = omx
-          video codec element sw = avdec */
-               if (((codec_type == MM_PLAYER_CODEC_TYPE_HW) &&
-                        (!strcmp(player->ini.videocodec_element_hw, ""))) ||
-                       ((codec_type == MM_PLAYER_CODEC_TYPE_SW) &&
-                        (!strcmp(player->ini.videocodec_element_sw[IDX_FIRST_SW_CODEC], "")))) {
-                       LOGE("There is no video codec info for codec_type %d", codec_type);
-                       return MM_ERROR_PLAYER_NO_OP;
-               }
-       break;
+               attr_name = MM_PLAYER_VIDEO_CODEC_TYPE;
+               default_type = player->ini.videocodec_default_type;
+               element_hw = player->ini.videocodec_element_hw;
+               element_sw = player->ini.videocodec_element_sw[IDX_FIRST_SW_CODEC];
+               break;
        default:
                LOGE("Invalid stream type %s", MMPLAYER_STREAM_TYPE_GET_NAME(stream_type));
                return MM_ERROR_COMMON_INVALID_ARGUMENT;
-       break;
+               break;
+       }
+
+       LOGD("default setting: [%s][%s][h:%s][s:%s]", attr_name, default_type, element_hw, element_sw);
+
+       if (!strcmp(default_type, "sw"))
+               default_codec_type = MM_PLAYER_CODEC_TYPE_SW;
+       else
+               default_codec_type = MM_PLAYER_CODEC_TYPE_HW;
+
+       if (codec_type == MM_PLAYER_CODEC_TYPE_DEFAULT)
+               codec_type = default_codec_type;
+
+       /* to support codec selection, codec info have to be added in ini file.
+          in case of hw codec is selected, filter elements should be applied
+          depending on the hw capabilities. */
+       if (codec_type != default_codec_type) {
+               if (((codec_type == MM_PLAYER_CODEC_TYPE_HW) && (!strcmp(element_hw, ""))) ||
+                       ((codec_type == MM_PLAYER_CODEC_TYPE_SW) && (!strcmp(element_sw, "")))) {
+                       LOGE("There is no codec for type %d", codec_type);
+                       return MM_ERROR_PLAYER_NO_OP;
+               }
+
+               LOGD("sorting is required");
+               if (stream_type == MM_PLAYER_STREAM_TYPE_AUDIO)
+                       player->need_audio_dec_sorting = TRUE;
+               else
+                       player->need_video_dec_sorting = TRUE;
        }
 
        LOGD("update %s codec_type to %d", attr_name, codec_type);
@@ -8688,7 +9343,7 @@ _mmplayer_get_video_roi_area(MMHandleType hplayer, double *scale_x, double *scal
 int
 _mmplayer_set_client_pid(MMHandleType hplayer, int pid)
 {
-       mmplayer_t* player = (mmplayer_t*)hplayer;
+       mmplayer_t *player = (mmplayer_t *)hplayer;
 
        MMPLAYER_FENTER();
 
@@ -8703,6 +9358,75 @@ _mmplayer_set_client_pid(MMHandleType hplayer, int pid)
        return MM_ERROR_NONE;
 }
 
+int
+_mmplayer_is_audio_control_available(MMHandleType hplayer, mmplayer_audio_control_opt_e opt, bool *available)
+{
+       mmplayer_t *player = (mmplayer_t *)hplayer;
+       mmplayer_codec_type_e codec_type = MM_PLAYER_CODEC_TYPE_DEFAULT;
+       enum audio_element_id elem_id = MMPLAYER_A_NUM;
+
+       MMPLAYER_FENTER();
+
+       MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+       MMPLAYER_RETURN_VAL_IF_FAIL(available, MM_ERROR_INVALID_ARGUMENT);
+
+       *available = true;
+       mm_attrs_get_int_by_name(player->attrs, MM_PLAYER_AUDIO_CODEC_TYPE, (int *)&codec_type);
+
+       LOGD("current state %d, codec_type %d", MMPLAYER_CURRENT_STATE(player), codec_type);
+
+       if (codec_type == MM_PLAYER_CODEC_TYPE_SW)
+               return MM_ERROR_NONE;
+
+       /* in case of audio codec default type is HW */
+       switch(opt) {
+               case MM_PLAYER_AUDIO_CONTROL_OPT_EFFECT:
+                       if (player->ini.support_audio_effect)
+                               return MM_ERROR_NONE;
+                       elem_id = MMPLAYER_A_FILTER;
+               break;
+               case MM_PLAYER_AUDIO_CONTROL_OPT_REPLAYGAIN:
+                       if (player->ini.support_replaygain_control)
+                               return MM_ERROR_NONE;
+                       elem_id = MMPLAYER_A_RGVOL;
+               break;
+               case MM_PLAYER_AUDIO_CONTROL_OPT_PITCH:
+                       if (player->ini.support_pitch_control)
+                               return MM_ERROR_NONE;
+                       elem_id = MMPLAYER_A_PITCH;
+               break;
+               case MM_PLAYER_AUDIO_CONTROL_OPT_PCM_EXPORTING:
+                       if (player->ini.support_audio_effect)
+                               return MM_ERROR_NONE;
+               break;
+               /* default case handling is not required */
+       }
+
+       if (MMPLAYER_CURRENT_STATE(player) < MM_PLAYER_STATE_READY) {
+               LOGW("audio control option [%d] is not available", opt);
+               *available = false;
+       } else {
+               /* setting pcm exporting option is allowed before READY state */
+               if (opt == MM_PLAYER_AUDIO_CONTROL_OPT_PCM_EXPORTING)
+                       return MM_ERROR_PLAYER_INVALID_STATE;
+
+               /* check whether the audio filter exist or not after READY state,
+                  because the sw codec could be added during auto-plugging in some cases */
+               if (!player->pipeline ||
+                       !player->pipeline->audiobin ||
+                       !player->pipeline->audiobin[elem_id].gst) {
+                       LOGW("there is no audio elem [%d]", elem_id);
+                       *available = false;
+               }
+       }
+
+       LOGD("audio control opt %d, available %d", opt, *available);
+
+       MMPLAYER_FLEAVE();
+
+       return MM_ERROR_NONE;
+}
+
 static gboolean
 __mmplayer_update_duration_value(mmplayer_t *player)
 {
@@ -8773,9 +9497,6 @@ __mmplayer_update_audio_attrs(mmplayer_t *player, MMHandleType attrs)
        }
 
        p = gst_caps_get_structure(caps_a, 0);
-
-       mm_attrs_get_int_by_name(attrs, "content_audio_samplerate", &samplerate);
-
        gst_structure_get_int(p, "rate", &samplerate);
        gst_structure_get_int(p, "channels", &channels);
 
@@ -8819,7 +9540,7 @@ __mmplayer_update_video_attrs(mmplayer_t *player, MMHandleType attrs)
        }
 
        if (!caps_v) {
-               LOGD("no negitiated caps from videosink");
+               LOGD("no negotiated caps from videosink");
                gst_object_unref(pad);
                return FALSE;
        }
@@ -8855,7 +9576,7 @@ __mmplayer_update_bitrate_attrs(mmplayer_t *player, MMHandleType attrs)
        gchar *path = NULL;
        struct stat sb;
 
-       /* FIXIT : please make it clear the dependancy with duration/codec/uritype */
+       /* FIXIT : please make it clear the dependency with duration/codec/uritype */
        if (!player->duration)
                return FALSE;
 
@@ -9000,11 +9721,12 @@ __mmplayer_set_file_uri(mmplayer_parse_profile_t *data, const char *uri)
 
        /* if no protocol prefix exist. check file existence and then give file:// as it's prefix */
        if (ret == MM_ERROR_NONE) {
-               g_snprintf(data->uri,  MM_MAX_URL_LEN, "file://%s", path);
                if (_mmplayer_is_sdp_file(path)) {
                        LOGD("uri is actually a file but it's sdp file. giving it to rtspsrc");
+                       g_snprintf(data->uri,  MM_MAX_URL_LEN, "rtsp-sdp://%s", path);
                        data->uri_type = MM_PLAYER_URI_TYPE_URL_RTSP;
                } else {
+                       g_snprintf(data->uri,  MM_MAX_URL_LEN, "file://%s", path);
                        data->uri_type = MM_PLAYER_URI_TYPE_FILE;
                }
        } else if (ret == MM_ERROR_PLAYER_PERMISSION_DENIED) {
@@ -9248,7 +9970,7 @@ __mmplayer_set_playing_state(mmplayer_t *player)
        /* try to get content metadata */
 
        /* NOTE : giving ATTR_MISSING_ONLY may have dependency with
-        * c-api since c-api doesn't use _start() anymore. It may not work propery with
+        * c-api since c-api doesn't use _start() anymore. It may not work properly with
         * legacy mmfw-player api
         */
        _mmplayer_update_content_attrs(player, ATTR_MISSING_ONLY);
@@ -9268,12 +9990,12 @@ __mmplayer_set_playing_state(mmplayer_t *player)
         * So, if it's not set yet, fill it with found data.
         */
        if (!audio_codec) {
-               if (g_strrstr(player->type, "audio/midi"))
+               if (g_strrstr(player->type_caps_str, "audio/midi"))
                        audio_codec = "MIDI";
-               else if (g_strrstr(player->type, "audio/x-amr"))
+               else if (g_strrstr(player->type_caps_str, "audio/x-amr"))
                        audio_codec = "AMR";
-               else if (g_strrstr(player->type, "audio/mpeg")
-                               && !g_strrstr(player->type, "mpegversion=(int)1"))
+               else if (g_strrstr(player->type_caps_str, "audio/mpeg")
+                               && !g_strrstr(player->type_caps_str, "mpegversion=(int)1"))
                        audio_codec = "AAC";
                else
                        audio_codec = "unknown";