to resolve the Prevent issues
[platform/core/multimedia/libmm-player.git] / src / mm_player.c
old mode 100644 (file)
new mode 100755 (executable)
index e50fefb..277096c
@@ -3,7 +3,8 @@
  *
  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
  *
- * Contact: JongHyuk Choi <jhchoi.choi@samsung.com>, YeJin Cho <cho.yejin@samsung.com>, YoungHwan An <younghwan_.an@samsung.com>
+ * Contact: JongHyuk Choi <jhchoi.choi@samsung.com>, YeJin Cho <cho.yejin@samsung.com>,
+ * Seungbae Shin <seungbae.shin@samsung.com>, YoungHwan An <younghwan_.an@samsung.com>
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #include "mm_player_ini.h"
 #include "mm_debug.h"
 #include "mm_player_capture.h"
+#include "mm_player_tracks.h"
+#include "mm_player_es.h"
 
 int mm_player_create(MMHandleType *player)
 {
        int result = MM_ERROR_NONE;
        mm_player_t* new_player = NULL;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
-       if (!g_thread_supported ())
-       g_thread_init (NULL);
-
-       MMTA_INIT();
-
-       __ta__("mm_player_ini_load",
-       result = mm_player_ini_load();
-       )
-       if(result != MM_ERROR_NONE)
-               return result;
-
-       __ta__("mm_player_audio_effect_ini_load",
-       result = mm_player_audio_effect_ini_load();
-       )
-       if(result != MM_ERROR_NONE)
-               return result;
 
        /* alloc player structure */
        new_player = g_malloc(sizeof(mm_player_t));
        if ( ! new_player )
        {
-               debug_critical("Cannot allocate memory for player\n");
+               debug_error("Cannot allocate memory for player\n");
                goto ERROR;
        }
        memset(new_player, 0, sizeof(mm_player_t));
 
        /* create player lock */
-       new_player->cmd_lock = g_mutex_new();
+       g_mutex_init(&new_player->cmd_lock);
+
+       /* create player lock */
+       g_mutex_init(&new_player->playback_lock);
+
+
+       /* create msg callback lock */
+       g_mutex_init(&new_player->msg_cb_lock);
 
-       if ( ! new_player->cmd_lock )
+       /* load ini files */
+       result = mm_player_ini_load(&new_player->ini);
+       if(result != MM_ERROR_NONE)
        {
-               debug_critical("failed to create player lock\n");
+               debug_error("can't load ini");
                goto ERROR;
        }
 
-       /* create msg callback lock */
-       new_player->msg_cb_lock = g_mutex_new();
-
-       if ( ! new_player->msg_cb_lock )
+       result = mm_player_audio_effect_ini_load(&new_player->ini);
+       if(result != MM_ERROR_NONE)
        {
-               debug_critical("failed to create msg cb lock\n");
+               debug_error("can't load audio ini");
                goto ERROR;
        }
-       __ta__("[KPI] create media player service",
+
+
+       /* create player */
        result = _mmplayer_create_player((MMHandleType)new_player);
-       )
 
        if(result != MM_ERROR_NONE)
+       {
+               debug_error("failed to create player");
                goto ERROR;
+       }
 
        *player = (MMHandleType)new_player;
 
@@ -100,13 +96,10 @@ ERROR:
 
        if ( new_player )
        {
-               if (new_player->cmd_lock)
-               {
-                       g_mutex_free(new_player->cmd_lock);
-                       new_player->cmd_lock = NULL;
-               }
-
                _mmplayer_destroy( (MMHandleType)new_player );
+               g_mutex_clear(&new_player->cmd_lock);
+               g_mutex_clear(&new_player->playback_lock);
+
                MMPLAYER_FREEIF( new_player );
        }
 
@@ -118,83 +111,59 @@ int  mm_player_destroy(MMHandleType player)
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        MMPLAYER_CMD_LOCK( player );
 
-       __ta__("[KPI] destroy media player service",
        result = _mmplayer_destroy(player);
-       )
 
        MMPLAYER_CMD_UNLOCK( player );
 
-       if (((mm_player_t*)player)->cmd_lock)
-       {
-               g_mutex_free(((mm_player_t*)player)->cmd_lock);
-               ((mm_player_t*)player)->cmd_lock = NULL;
-       }
+       g_mutex_clear(&((mm_player_t*)player)->cmd_lock);
+       g_mutex_clear(&((mm_player_t*)player)->playback_lock);
 
        memset( (mm_player_t*)player, 0x00, sizeof(mm_player_t) );
 
        /* free player */
        g_free( (void*)player );
 
-       MMTA_ACUM_ITEM_SHOW_RESULT_TO(MMTA_SHOW_FILE);
-
-       MMTA_RELEASE();
-
        return result;
 }
 
-
 int mm_player_realize(MMHandleType player)
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        MMPLAYER_CMD_LOCK( player );
 
-       __ta__("[KPI] initialize media player service",
        result = _mmplayer_realize(player);
-       )
 
        MMPLAYER_CMD_UNLOCK( player );
 
        return result;
 }
 
-
 int mm_player_unrealize(MMHandleType player)
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        MMPLAYER_CMD_LOCK( player );
 
-       __ta__("[KPI] cleanup media player service",
        result = _mmplayer_unrealize(player);
-       )
 
        MMPLAYER_CMD_UNLOCK( player );
 
        return result;
 }
 
-
 int mm_player_set_message_callback(MMHandleType player, MMMessageCallback callback, void *user_param)
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        MMPLAYER_CMD_LOCK( player );
@@ -210,8 +179,6 @@ int mm_player_set_pd_message_callback(MMHandleType player, MMMessageCallback cal
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        result = _mm_player_set_pd_downloader_message_cb(player, callback, user_param);
@@ -223,8 +190,6 @@ int mm_player_set_audio_stream_callback(MMHandleType player, mm_player_audio_str
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        MMPLAYER_CMD_LOCK( player );
@@ -236,18 +201,15 @@ int mm_player_set_audio_stream_callback(MMHandleType player, mm_player_audio_str
        return result;
 }
 
-
-int mm_player_set_audio_buffer_callback(MMHandleType player, mm_player_audio_stream_callback callback, void *user_param)
+int mm_player_set_audio_stream_callback_ex(MMHandleType player, bool sync, mm_player_audio_stream_callback_ex callback, void *user_param)
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        MMPLAYER_CMD_LOCK( player );
 
-       result = _mmplayer_set_audiobuffer_cb(player, callback, user_param);
+       result = _mmplayer_set_audiostream_cb_ex(player, sync, callback, user_param);
 
        MMPLAYER_CMD_UNLOCK( player );
 
@@ -258,13 +220,11 @@ int mm_player_set_video_stream_callback(MMHandleType player, mm_player_video_str
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        MMPLAYER_CMD_LOCK( player );
 
-    result = _mmplayer_set_videostream_cb(player, callback, user_param);
+       result = _mmplayer_set_videostream_cb(player, callback, user_param);
 
        MMPLAYER_CMD_UNLOCK( player );
 
@@ -275,8 +235,6 @@ int mm_player_set_video_frame_render_error_callback(MMHandleType player, mm_play
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        MMPLAYER_CMD_LOCK( player );
@@ -292,8 +250,6 @@ int mm_player_do_video_capture(MMHandleType player)
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        MMPLAYER_CMD_LOCK( player );
@@ -305,66 +261,40 @@ int mm_player_do_video_capture(MMHandleType player)
        return result;
 }
 
-int mm_player_set_buffer_need_data_callback(MMHandleType player, mm_player_buffer_need_data_callback callback, void * user_param)
-{
-       int result = MM_ERROR_NONE;
-
-       debug_log("\n");
-
-       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
-
-       MMPLAYER_CMD_LOCK( player );
-
-    result = _mmplayer_set_buffer_need_data_cb(player, callback, user_param);
-
-       MMPLAYER_CMD_UNLOCK( player );
-
-       return result;
-}
-
-
-int mm_player_set_buffer_enough_data_callback(MMHandleType player, mm_player_buffer_enough_data_callback callback, void * user_param)
+int mm_player_set_prepare_buffering_time(MMHandleType player, int second)
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        MMPLAYER_CMD_LOCK( player );
 
-    result = _mmplayer_set_buffer_enough_data_cb(player, callback, user_param);
+       result = _mmplayer_set_prepare_buffering_time(player, second);
 
        MMPLAYER_CMD_UNLOCK( player );
 
        return result;
 }
 
-
-int mm_player_set_buffer_seek_data_callback(MMHandleType player, mm_player_buffer_seek_data_callback callback, void * user_param)
+int mm_player_set_runtime_buffering_mode(MMHandleType player, MMPlayerBufferingMode mode, int second)
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        MMPLAYER_CMD_LOCK( player );
 
-    result = _mmplayer_set_buffer_seek_data_cb(player, callback, user_param);
+       result = _mmplayer_set_runtime_buffering_mode(player, mode, second);
 
        MMPLAYER_CMD_UNLOCK( player );
 
        return result;
 }
 
-
 int mm_player_set_volume(MMHandleType player, MMPlayerVolumeType *volume)
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
        return_val_if_fail(volume, MM_ERROR_INVALID_ARGUMENT);
 
@@ -377,13 +307,10 @@ int mm_player_set_volume(MMHandleType player, MMPlayerVolumeType *volume)
        return result;
 }
 
-
 int mm_player_get_volume(MMHandleType player, MMPlayerVolumeType *volume)
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
        return_val_if_fail(volume, MM_ERROR_INVALID_ARGUMENT);
 
@@ -396,13 +323,10 @@ int mm_player_get_volume(MMHandleType player, MMPlayerVolumeType *volume)
        return result;
 }
 
-
 int mm_player_set_mute(MMHandleType player, int mute)
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        MMPLAYER_CMD_LOCK( player );
@@ -414,13 +338,10 @@ int mm_player_set_mute(MMHandleType player, int mute)
        return result;
 }
 
-
 int mm_player_get_mute(MMHandleType player, int *mute)
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
        return_val_if_fail(mute, MM_ERROR_INVALID_ARGUMENT);
 
@@ -433,13 +354,10 @@ int mm_player_get_mute(MMHandleType player, int *mute)
        return result;
 }
 
-
 int mm_player_get_state(MMHandleType player, MMPlayerStateType *state)
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
        return_val_if_fail(state, MM_ERROR_COMMON_INVALID_ARGUMENT);
 
@@ -450,29 +368,30 @@ int mm_player_get_state(MMHandleType player, MMPlayerStateType *state)
        return result;
 }
 
-/* NOTE : Not supported */
+/* NOTE : It does not support some use cases, eg using colorspace converter */
 int mm_player_change_videosink(MMHandleType player, MMDisplaySurfaceType display_surface_type, void *display_overlay)
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
-       return MM_ERROR_NOT_SUPPORT_API;
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_change_videosink(player, display_surface_type, display_overlay);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
 }
 
 int mm_player_push_buffer(MMHandleType player, unsigned char *buf, int size)
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        //MMPLAYER_CMD_LOCK( player );
 
-       //MMTA_ACUM_ITEM_BEGIN("[KPI] start media player service", false);
        result = _mmplayer_push_buffer(player, buf, size);
 
        //MMPLAYER_CMD_UNLOCK( player );
@@ -480,18 +399,14 @@ int mm_player_push_buffer(MMHandleType player, unsigned char *buf, int size)
        return result;
 }
 
-
 int mm_player_start(MMHandleType player)
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        MMPLAYER_CMD_LOCK( player );
 
-       MMTA_ACUM_ITEM_BEGIN("[KPI] start media player service", false);
        result = _mmplayer_start(player);
 
        MMPLAYER_CMD_UNLOCK( player );
@@ -499,67 +414,51 @@ int mm_player_start(MMHandleType player)
        return result;
 }
 
-
 int  mm_player_stop(MMHandleType player)
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        MMPLAYER_CMD_LOCK( player );
 
-       __ta__("[KPI] stop media player service",
        result = _mmplayer_stop(player);
-       )
 
        MMPLAYER_CMD_UNLOCK( player );
 
        return result;
 }
 
-
 int mm_player_pause(MMHandleType player)
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        MMPLAYER_CMD_LOCK( player );
 
-       __ta__("[KPI] pause media player service",
        result = _mmplayer_pause(player);
-       )
 
        MMPLAYER_CMD_UNLOCK( player );
 
        return result;
 }
 
-
 int mm_player_resume(MMHandleType player)
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        MMPLAYER_CMD_LOCK( player );
 
-       __ta__("[KPI] resume media player service",
        result = _mmplayer_resume(player);
-       )
 
        MMPLAYER_CMD_UNLOCK( player );
 
        return result;
 }
 
-
 int mm_player_activate_section_repeat(MMHandleType player, int start_pos, int end_pos)
 {
        int result = MM_ERROR_NONE;
@@ -575,7 +474,6 @@ int mm_player_activate_section_repeat(MMHandleType player, int start_pos, int en
        return result;
 }
 
-
 int mm_player_deactivate_section_repeat(MMHandleType player)
 {
        int result = MM_ERROR_NONE;
@@ -591,6 +489,18 @@ int mm_player_deactivate_section_repeat(MMHandleType player)
        return result;
 }
 
+int mm_player_gst_set_audio_channel(MMHandleType player, MMPlayerAudioChannel ch)
+{
+       int result = MM_ERROR_NONE;
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_gst_set_audio_channel(player, ch);
+
+       MMPLAYER_CMD_UNLOCK( player );
+       return result;
+}
 
 int mm_player_set_play_speed(MMHandleType player, float rate)
 {
@@ -607,13 +517,10 @@ int mm_player_set_play_speed(MMHandleType player, float rate)
        return result;
 }
 
-
 int mm_player_set_position(MMHandleType player, MMPlayerPosFormatType format, int pos)
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        if (format >= MM_PLAYER_POS_FORMAT_NUM)
@@ -631,13 +538,10 @@ int mm_player_set_position(MMHandleType player, MMPlayerPosFormatType format, in
        return result;
 }
 
-
 int mm_player_get_position(MMHandleType player, MMPlayerPosFormatType format, int *pos)
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
        return_val_if_fail(pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
 
@@ -660,8 +564,6 @@ int mm_player_get_buffer_position(MMHandleType player, MMPlayerPosFormatType for
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
        return_val_if_fail(start_pos && stop_pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
 
@@ -674,18 +576,30 @@ int mm_player_get_buffer_position(MMHandleType player, MMPlayerPosFormatType for
        return result;
 }
 
-int mm_player_adjust_subtitle_position(MMHandleType player, MMPlayerPosFormatType format, int pos)
+int mm_player_set_external_subtitle_path(MMHandleType player, const char* path)
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_set_external_subtitle_path(player, path);
+
+       MMPLAYER_CMD_UNLOCK( player );
+       return result;
+}
+
+int mm_player_adjust_subtitle_position(MMHandleType player, MMPlayerPosFormatType format, int pos)
+{
+       int result = MM_ERROR_NONE;
 
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        if (format >= MM_PLAYER_POS_FORMAT_NUM)
        {
-               debug_error("wrong format\n");
-               return MM_ERROR_COMMON_INVALID_ARGUMENT;
+               debug_error("wrong format(%d) \n", format);
+               return MM_ERROR_INVALID_ARGUMENT;
        }
 
        MMPLAYER_CMD_LOCK( player );
@@ -697,13 +611,23 @@ int mm_player_adjust_subtitle_position(MMHandleType player, MMPlayerPosFormatTyp
        return result;
 }
 
+int mm_player_adjust_video_position(MMHandleType player, int offset)
+{
+       int result = MM_ERROR_NONE;
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_adjust_video_postion(player, offset);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
 
 int mm_player_set_subtitle_silent(MMHandleType player, int silent)
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        MMPLAYER_CMD_LOCK( player );
@@ -715,13 +639,10 @@ int mm_player_set_subtitle_silent(MMHandleType player, int silent)
        return result;
 }
 
-
 int mm_player_get_subtitle_silent(MMHandleType player, int* silent)
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        MMPLAYER_CMD_LOCK( player );
@@ -733,14 +654,11 @@ int mm_player_get_subtitle_silent(MMHandleType player, int* silent)
        return result;
 }
 
-
 int mm_player_set_attribute(MMHandleType player,  char **err_attr_name, const char *first_attribute_name, ...)
 {
        int result = MM_ERROR_NONE;
        va_list var_args;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
        return_val_if_fail(first_attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
 
@@ -751,14 +669,11 @@ int mm_player_set_attribute(MMHandleType player,  char **err_attr_name, const ch
        return result;
 }
 
-
 int mm_player_get_attribute(MMHandleType player,  char **err_attr_name, const char *first_attribute_name, ...)
 {
        int result = MM_ERROR_NONE;
        va_list var_args;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
        return_val_if_fail(first_attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
 
@@ -769,11 +684,10 @@ int mm_player_get_attribute(MMHandleType player,  char **err_attr_name, const ch
        return result;
 }
 
-
 int mm_player_get_attribute_info(MMHandleType player,  const char *attribute_name, MMPlayerAttrsInfo *info)
 {
        int result = MM_ERROR_NONE;
-       debug_log("\n");
+
 
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
        return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
@@ -788,8 +702,6 @@ int mm_player_get_pd_status(MMHandleType player, guint64 *current_pos, guint64 *
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
        return_val_if_fail(current_pos, MM_ERROR_COMMON_INVALID_ARGUMENT);
        return_val_if_fail(total_size, MM_ERROR_COMMON_INVALID_ARGUMENT);
@@ -799,17 +711,555 @@ int mm_player_get_pd_status(MMHandleType player, guint64 *current_pos, guint64 *
        return result;
 }
 
-int mm_player_get_track_count(MMHandleType player,  MMPlayerTrackType track_type, int *count)
+int mm_player_get_track_count(MMHandleType player, MMPlayerTrackType type, int *count)
 {
        int result = MM_ERROR_NONE;
 
-       debug_log("\n");
-
        return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
        return_val_if_fail(count, MM_ERROR_COMMON_INVALID_ARGUMENT);
 
-       result = _mmplayer_get_track_count(player, track_type, count);
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_get_track_count(player, type, count);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+
+int mm_player_select_track(MMHandleType player, MMPlayerTrackType type, int index)
+{
+       int result = MM_ERROR_NONE;
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_select_track(player, type, index);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+#ifdef _MULTI_TRACK
+int mm_player_track_add_subtitle_language(MMHandleType player, int index)
+{
+       int result = MM_ERROR_NONE;
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_track_add_subtitle_language(player, index);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+
+int mm_player_track_remove_subtitle_language(MMHandleType player, int index)
+{
+       int result = MM_ERROR_NONE;
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_track_remove_subtitle_language(player, index);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+
+}
+#endif
+int mm_player_get_current_track(MMHandleType player, MMPlayerTrackType type, int *index)
+{
+       int result = MM_ERROR_NONE;
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+       return_val_if_fail(index, MM_ERROR_COMMON_INVALID_ARGUMENT);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_get_current_track(player, type, index);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+
+int mm_player_get_track_language_code(MMHandleType player,  MMPlayerTrackType type, int index, char **code)
+{
+       int result = MM_ERROR_NONE;
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_get_track_language_code(player, type, index, code);
+
+       MMPLAYER_CMD_UNLOCK( player );
 
        return result;
+}
+
+int mm_player_ignore_session(MMHandleType player)
+{
+       int result = MM_ERROR_NONE;
 
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       result = _mmplayer_asm_ignore_session(player);
+
+       return result;
 }
+
+int mm_player_set_display_zoom(MMHandleType player, float level, int x, int y)
+{
+       int result = MM_ERROR_NONE;
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_set_display_zoom(player, level, x, y);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+
+int mm_player_get_display_zoom(MMHandleType player, float *level, int *x, int *y)
+{
+       int result = MM_ERROR_NONE;
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+       return_val_if_fail(level, MM_ERROR_COMMON_INVALID_ARGUMENT);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_get_display_zoom(player, level, x, y);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+
+
+int mm_player_use_system_clock(MMHandleType player)
+{
+       int result = MM_ERROR_NONE;
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_use_system_clock(player);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+
+int mm_player_set_video_share_master_clock(MMHandleType player,
+                                               long long clock,
+                                               long long clock_delta,
+                                               long long video_time,
+                                               long long media_clock,
+                                               long long audio_time)
+{
+       int result = MM_ERROR_NONE;
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_set_video_share_master_clock(player, clock, clock_delta, video_time, media_clock, audio_time);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+
+int mm_player_get_video_share_master_clock(MMHandleType player,
+                                               long long *video_time,
+                                               long long *media_clock,
+                                               long long *audio_time)
+{
+       int result = MM_ERROR_NONE;
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+       return_val_if_fail(video_time, MM_ERROR_COMMON_INVALID_ARGUMENT);
+       return_val_if_fail(media_clock, MM_ERROR_COMMON_INVALID_ARGUMENT);
+       return_val_if_fail(audio_time, MM_ERROR_COMMON_INVALID_ARGUMENT);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_get_video_share_master_clock(player, video_time, media_clock, audio_time);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+
+int mm_player_get_video_rotate_angle(MMHandleType player, int *angle)
+{
+       int result = MM_ERROR_NONE;
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+       return_val_if_fail(angle, MM_ERROR_COMMON_INVALID_ARGUMENT);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_get_video_rotate_angle(player, angle);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+
+int mm_player_set_video_hub_download_mode(MMHandleType player, bool mode)
+{
+       int result = MM_ERROR_NONE;
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_set_video_hub_download_mode(player, mode);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+
+int mm_player_enable_sync_handler(MMHandleType player, bool enable)
+{
+       int result = MM_ERROR_NONE;
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_enable_sync_handler(player, enable);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+
+int mm_player_set_uri(MMHandleType player, const char *uri)
+{
+       int result = MM_ERROR_NONE;
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_set_uri(player, uri);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+
+}
+
+int mm_player_set_next_uri(MMHandleType player, const char *uri)
+{
+       int result = MM_ERROR_NONE;
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_set_next_uri(player, uri, FALSE);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+
+}
+
+int mm_player_get_next_uri(MMHandleType player, char **uri)
+{
+       int result = MM_ERROR_NONE;
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_get_next_uri(player, uri);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+
+}
+#ifdef _MULTI_TRACK
+int mm_player_track_foreach_selected_subtitle_language(MMHandleType player, mm_player_track_selected_subtitle_language_callback callback, void *user_param)
+{
+       int result = MM_ERROR_NONE;
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_track_foreach_selected_subtitle_language(player, callback, user_param);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+#endif
+
+int mm_player_has_closed_caption(MMHandleType player, bool *exist)
+{
+       int result = MM_ERROR_NONE;
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+       return_val_if_fail(exist, MM_ERROR_INVALID_ARGUMENT);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_has_closed_caption(player, exist);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+
+int mm_player_enable_media_packet_video_stream(MMHandleType player, bool enable)
+{
+       int result = MM_ERROR_NONE;
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+       return_val_if_fail(enable, MM_ERROR_INVALID_ARGUMENT);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_enable_media_packet_video_stream(player, enable);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+
+void * mm_player_media_packet_video_stream_internal_buffer_ref(void *buffer)
+{
+       void * result;
+       result = _mm_player_media_packet_video_stream_internal_buffer_ref(buffer);
+
+       return result;
+}
+
+void mm_player_media_packet_video_stream_internal_buffer_unref(void *buffer)
+{
+       _mm_player_media_packet_video_stream_internal_buffer_unref(buffer);
+}
+
+#ifdef TEST_ES
+int mm_player_submit_packet(MMHandleType player, media_packet_h packet)
+{
+
+       int result = MM_ERROR_NONE;
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       /* no lock here, otherwise callback for the "need-data" signal of appsrc will be blocking */
+       //MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_submit_packet(player, packet);
+
+       //MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+
+int mm_player_set_video_info (MMHandleType player, media_format_h format)
+{
+       int result = MM_ERROR_NONE;
+
+       debug_log("\n");
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_set_video_info(player, format);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+
+}
+
+int mm_player_set_audio_info (MMHandleType player, media_format_h format)
+{
+       int result = MM_ERROR_NONE;
+
+       debug_log("\n");
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_set_audio_info(player, format);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+
+int mm_player_set_subtitle_info (MMHandleType player, MMPlayerSubtitleStreamInfo *subtitle_stream_info)
+{
+       int result = MM_ERROR_NONE;
+
+       debug_log("\n");
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_set_subtitle_info(player, subtitle_stream_info);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+
+int mm_player_set_media_stream_buffer_max_size(MMHandleType player, MMPlayerStreamType type, unsigned long long max_size)
+{
+       int result = MM_ERROR_NONE;
+
+       debug_log("\n");
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_set_media_stream_max_size(player, type, max_size);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+
+int mm_player_get_media_stream_buffer_max_size(MMHandleType player, MMPlayerStreamType type, unsigned long long *max_size)
+{
+       int result = MM_ERROR_NONE;
+
+       debug_log("\n");
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+       return_val_if_fail(max_size, MM_ERROR_INVALID_ARGUMENT);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_get_media_stream_max_size(player, type, max_size);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+
+int mm_player_set_media_stream_buffer_min_percent(MMHandleType player, MMPlayerStreamType type, unsigned min_percent)
+{
+       int result = MM_ERROR_NONE;
+
+       debug_log("\n");
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_set_media_stream_min_percent(player, type, min_percent);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+
+int mm_player_get_media_stream_buffer_min_percent(MMHandleType player, MMPlayerStreamType type, unsigned int *min_percent)
+{
+       int result = MM_ERROR_NONE;
+
+       debug_log("\n");
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+       return_val_if_fail(min_percent, MM_ERROR_INVALID_ARGUMENT);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_get_media_stream_min_percent(player, type, min_percent);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+
+int mm_player_set_media_stream_buffer_status_callback(MMHandleType player, MMPlayerStreamType type, mm_player_media_stream_buffer_status_callback callback, void * user_param)
+{
+       int result = MM_ERROR_NONE;
+
+       debug_log("\n");
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_set_media_stream_buffer_status_cb(player, type, callback, user_param);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+
+int mm_player_set_media_stream_seek_data_callback(MMHandleType player, MMPlayerStreamType type, mm_player_media_stream_seek_data_callback callback, void * user_param)
+{
+       int result = MM_ERROR_NONE;
+
+       debug_log("\n");
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_set_media_stream_seek_data_cb(player, type, callback, user_param);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+
+int mm_player_set_audio_stream_changed_callback(MMHandleType player, mm_player_stream_changed_callback callback, void *user_param)
+{
+       int result = MM_ERROR_NONE;
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_set_audiostream_changed_cb(player, callback, user_param);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+
+int mm_player_set_video_stream_changed_callback(MMHandleType player, mm_player_stream_changed_callback callback, void *user_param)
+{
+       int result = MM_ERROR_NONE;
+
+       return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       MMPLAYER_CMD_LOCK( player );
+
+       result = _mmplayer_set_videostream_changed_cb(player, callback, user_param);
+
+       MMPLAYER_CMD_UNLOCK( player );
+
+       return result;
+}
+
+#endif