reuse tbm surface when player send decoded video frame 49/74549/2
authorEunhae Choi <eunhae1.choi@samsung.com>
Tue, 14 Jun 2016 12:36:26 +0000 (21:36 +0900)
committerEunhae Choi <eunhae1.choi@samsung.com>
Wed, 15 Jun 2016 02:23:21 +0000 (11:23 +0900)
1. add api to get video frame pool size
2. add tbm surface list to reuse it
3. apply tizen coding rule

Change-Id: I4e6512bb2f82e46c7c25bc20502ba8fc054dd133

include/common/player_internal.h
include/player_msg.h
include/player_private.h
include/wearable/player_internal.h
packaging/capi-media-player.spec
src/player.c
src/player_internal.c

index b1e7c61..cfc73c0 100644 (file)
@@ -381,7 +381,7 @@ int player_set_buffer_need_audio_data_cb(player_h player, player_buffer_need_dat
  * @post player_resourceconflict_cb() will be invoked.
  * @see player_unset_resourceconflict_cb()
  */
-int player_set_resourceconflict_cb (player_h player, player_resourceconflict_cb callback, void *user_data);
+int player_set_resourceconflict_cb(player_h player, player_resourceconflict_cb callback, void *user_data);
 
 /**
  * @brief Unregisters the callback function.
@@ -393,7 +393,7 @@ int player_set_resourceconflict_cb (player_h player, player_resourceconflict_cb
  * @retval #PLAYER_ERROR_INVALID_PARAMETER Invalid parameter
  * @see player_set_resourceconflict_cb()
  */
-int player_unset_resourceconflict_cb (player_h player);
+int player_unset_resourceconflict_cb(player_h player);
 
 /**
  * @brief Display the first video frame at the player_prepare() function to improve the playback performance.
@@ -416,19 +416,19 @@ int player_display_video_at_paused_state(player_h player, bool visible);
  */
 int player_set_display_parent_win_id(player_h player, int win_id);
 
-#else
+#else /* TIZEN_TV */
 
 /**
  * @brief Sets the data source (http or local file) to transite.
  * @since_tizen 3.0
  *
  * @details Player will transite the media source as seamlessly as possible after finishing current playback.
- *             If the function call is successful, the uri will be added at the end of uri list.
- *               You can add several uris and the set of uris will be played repeatedly if you call the player_set_looping().
- *               The first uri in the list is the original uri which is set by player_set_uri().
+ *          If the function call is successful, the uri will be added at the end of uri list.
+ *          You can add several uris and the set of uris will be played repeatedly if you call the player_set_looping().
+ *          The first uri in the list is the original uri which is set by player_set_uri().
  *
- * @remarks  Uri list will be cleared except first one when the player_unprepare() is called.
- *                     If you call the player_set_uri(), you can change the first uri too.
+ * @remarks Uri list will be cleared except first one when the player_unprepare() is called.
+ *          If you call the player_set_uri(), you can change the first uri too.
  *
  * @param[in]   player The handle to the media player
  * @param[in]   uri Specifies the data location.
@@ -443,7 +443,7 @@ int player_set_display_parent_win_id(player_h player, int win_id);
  * @pre The player state must be one of these: #PLAYER_STATE_IDLE, #PLAYER_STATE_READY, #PLAYER_STATE_PLAYING, or #PLAYER_STATE_PAUSED.
  * @see player_set_uri(), player_set_looping()
  */
-int player_set_next_uri (player_h player, const char *uri);
+int player_set_next_uri(player_h player, const char *uri);
 
 /**
  * @brief Gets the data source path.
@@ -461,7 +461,7 @@ int player_set_next_uri (player_h player, const char *uri);
  * @pre The player state must be one of these: #PLAYER_STATE_IDLE, #PLAYER_STATE_READY, #PLAYER_STATE_PLAYING, or #PLAYER_STATE_PAUSED.
  * @see player_set_uri()
  */
-int player_get_next_uri (player_h player, char **uri);
+int player_get_next_uri(player_h player, char **uri);
 
 /**
  * @brief Sets the gapless playback status
@@ -498,7 +498,24 @@ int player_set_gapless(player_h player, bool gapless);
  */
 int player_is_gapless(player_h player, bool *gapless);
 
-#endif
+/**
+ * @brief Gets the size of video frame pool.
+ * @since_tizen 3.0
+ * @details App gets the video frame pool size which will be reused during playback.
+ * @param[in] player The handle to the media player
+ * @param[out] size The size of surface pool
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #PLAYER_ERROR_NONE Successful
+ * @retval #PLAYER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PLAYER_ERROR_INVALID_OPERATION Invalid operation
+ * @retval #PLAYER_ERROR_INVALID_STATE Invalid player state
+ * @pre The player state must be one of these: #PLAYER_STATE_READY, #PLAYER_STATE_PLAYING, or #PLAYER_STATE_PAUSED
+ * @see player_set_media_packet_video_frame_decoded_cb()
+ */
+int player_get_media_packet_video_frame_pool_size(player_h player, int *size);
+
+#endif /* TIZEN_TV */
 
 /**
  * @}
index ecbd4ca..5ef2d98 100644 (file)
@@ -53,13 +53,13 @@ extern "C" {
  * @param[out] ret The return value from server.
  */
 #define player_msg_send(api, player, retbuf, ret) \
-       do    \
+       do {    \
                char *__sndMsg__; \
                int __len__; \
                int __fd__; \
                int __timeout__ = client_get_api_timeout(player, api); \
-               if(CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
-               else {ret = PLAYER_ERROR_INVALID_STATE;break;} \
+               if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
+               else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
                __sndMsg__ = muse_core_msg_json_factory_new(api, \
                                0); \
                __len__ = muse_core_ipc_send_msg(__fd__, __sndMsg__); \
@@ -69,7 +69,7 @@ extern "C" {
                } else \
                        ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), &retbuf, __timeout__); \
                muse_core_msg_json_factory_free(__sndMsg__); \
-       }while(0)
+       } while (0)
 
 /**
  * @brief Create and send message. Wait for server result.
@@ -82,14 +82,14 @@ extern "C" {
  * @param[in] param the name of param is key, must be local variable. never be pointer.
  */
 #define player_msg_send1(api, player, retbuf, ret, type, param) \
-       do    \
+       do {    \
                char *__sndMsg__; \
                int __len__; \
                int __fd__; \
                int __timeout__ = client_get_api_timeout(player, api); \
                type __value__ = (type)param; \
-               if(CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
-               else {ret = PLAYER_ERROR_INVALID_STATE;break;} \
+               if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
+               else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
                __sndMsg__ = muse_core_msg_json_factory_new(api, \
                                MUSE_TYPE_##type, #param, __value__, \
                                0); \
@@ -100,7 +100,7 @@ extern "C" {
                } else \
                        ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), &retbuf, __timeout__); \
                muse_core_msg_json_factory_free(__sndMsg__); \
-       }while(0)
+       } while (0)
 
 /**
  * @brief Create and send message. Wait for server result.
@@ -113,15 +113,15 @@ extern "C" {
  * @param[in] param# the name of param is key, must be local variable. never be pointer.
  */
 #define player_msg_send2(api, player, retbuf, ret, type1, param1, type2, param2) \
-       do    \
+       do {    \
                char *__sndMsg__; \
                int __len__; \
                int __fd__; \
                int __timeout__ = client_get_api_timeout(player, api); \
                type1 __value1__ = (type1)param1; \
                type2 __value2__ = (type2)param2; \
-               if(CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
-               else {ret = PLAYER_ERROR_INVALID_STATE;break;} \
+               if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
+               else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
                __sndMsg__ = muse_core_msg_json_factory_new(api, \
                                MUSE_TYPE_##type1, #param1, __value1__, \
                                MUSE_TYPE_##type2, #param2, __value2__, \
@@ -133,7 +133,7 @@ extern "C" {
                } else \
                        ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), &retbuf, __timeout__); \
                muse_core_msg_json_factory_free(__sndMsg__); \
-       }while(0)
+       } while (0)
 
 /**
  * @brief Create and send message. Wait for server result.
@@ -146,7 +146,7 @@ extern "C" {
  * @param[in] param# the name of param is key, must be local variable. never be pointer.
  */
 #define player_msg_send3(api, player, retbuf, ret, type1, param1, type2, param2, type3, param3) \
-       do    \
+       do {    \
                char *__sndMsg__; \
                int __len__; \
                int __fd__; \
@@ -154,8 +154,8 @@ extern "C" {
                type1 __value1__ = (type1)param1; \
                type2 __value2__ = (type2)param2; \
                type3 __value3__ = (type3)param3; \
-               if(CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
-               else {ret = PLAYER_ERROR_INVALID_STATE;break;} \
+               if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
+               else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
                __sndMsg__ = muse_core_msg_json_factory_new(api, \
                                MUSE_TYPE_##type1, #param1, __value1__, \
                                MUSE_TYPE_##type2, #param2, __value2__, \
@@ -168,7 +168,7 @@ extern "C" {
                } else \
                        ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), &retbuf, __timeout__); \
                muse_core_msg_json_factory_free(__sndMsg__); \
-       }while(0)
+       } while (0)
 
 /**
  * @brief Create and send message. Wait for server result.
@@ -181,7 +181,7 @@ extern "C" {
  * @param[in] param# the name of param is key, must be local variable. never be pointer.
  */
 #define player_msg_send4(api, player, retbuf, ret, type1, param1, type2, param2, type3, param3, type4, param4) \
-       do    \
+       do {    \
                char *__sndMsg__; \
                int __len__; \
                int __fd__; \
@@ -190,8 +190,8 @@ extern "C" {
                type2 __value2__ = (type2)param2; \
                type3 __value3__ = (type3)param3; \
                type4 __value4__ = (type4)param4; \
-               if(CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
-               else {ret = PLAYER_ERROR_INVALID_STATE;break;} \
+               if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
+               else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
                __sndMsg__ = muse_core_msg_json_factory_new(api, \
                                MUSE_TYPE_##type1, #param1, __value1__, \
                                MUSE_TYPE_##type2, #param2, __value2__, \
@@ -205,7 +205,7 @@ extern "C" {
                } else \
                        ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), &retbuf, __timeout__); \
                muse_core_msg_json_factory_free(__sndMsg__); \
-       }while(0)
+       } while (0)
 
 /**
  * @brief Create and send message. Wait for server result.
@@ -218,33 +218,33 @@ extern "C" {
  * @param[in] param# the name of param is key, must be local variable. never be pointer.
  */
 #define player_msg_send5(api, player, retbuf, ret, type1, param1, type2, param2, type3, param3, type4, param4, type5, param5) \
-    do{ \
-      char *__sndMsg__; \
-      int __len__; \
-      int __fd__; \
-      int __timeout__ = client_get_api_timeout(player, api); \
-      type1 __value1__ = (type1)param1; \
-      type2 __value2__ = (type2)param2; \
-      type3 __value3__ = (type3)param3; \
-      type4 __value4__ = (type4)param4; \
-      type5 __value5__ = (type5)param5; \
-      if(CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
-      else {ret = PLAYER_ERROR_INVALID_STATE;break;} \
-      __sndMsg__ = muse_core_msg_json_factory_new(api, \
-          MUSE_TYPE_##type1, #param1, __value1__, \
-          MUSE_TYPE_##type2, #param2, __value2__, \
-          MUSE_TYPE_##type3, #param3, __value3__, \
-          MUSE_TYPE_##type4, #param4, __value4__, \
-          MUSE_TYPE_##type5, #param5, __value5__, \
-          0); \
-      __len__ = muse_core_ipc_send_msg(__fd__, __sndMsg__); \
-      if (__len__ <= 0) { \
-        LOGE("sending message failed"); \
-        ret = PLAYER_ERROR_INVALID_OPERATION; \
-      } else \
-        ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), &retbuf, __timeout__); \
-      muse_core_msg_json_factory_free(__sndMsg__); \
-    }while(0)
+       do { \
+               char *__sndMsg__; \
+               int __len__; \
+               int __fd__; \
+               int __timeout__ = client_get_api_timeout(player, api); \
+               type1 __value1__ = (type1)param1; \
+               type2 __value2__ = (type2)param2; \
+               type3 __value3__ = (type3)param3; \
+               type4 __value4__ = (type4)param4; \
+               type5 __value5__ = (type5)param5; \
+               if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
+               else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
+               __sndMsg__ = muse_core_msg_json_factory_new(api, \
+                       MUSE_TYPE_##type1, #param1, __value1__, \
+                       MUSE_TYPE_##type2, #param2, __value2__, \
+                       MUSE_TYPE_##type3, #param3, __value3__, \
+                       MUSE_TYPE_##type4, #param4, __value4__, \
+                       MUSE_TYPE_##type5, #param5, __value5__, \
+                       0); \
+               __len__ = muse_core_ipc_send_msg(__fd__, __sndMsg__); \
+               if (__len__ <= 0) { \
+                       LOGE("sending message failed"); \
+                       ret = PLAYER_ERROR_INVALID_OPERATION; \
+               } else \
+                       ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), &retbuf, __timeout__); \
+               muse_core_msg_json_factory_free(__sndMsg__); \
+       } while (0)
 
 /**
  * @brief Create and send message. Wait for server result.
@@ -257,7 +257,7 @@ extern "C" {
  * @param[in] param# the name of param is key, must be local variable. never be pointer.
  */
 #define player_msg_send6(api, player, retbuf, ret, type1, param1, type2, param2, type3, param3, type4, param4, type5, param5, type6, param6) \
-       do    \
+       do {    \
                char *__sndMsg__; \
                int __len__; \
                int __fd__; \
@@ -268,8 +268,8 @@ extern "C" {
                type4 __value4__ = (type4)param4; \
                type5 __value5__ = (type5)param5; \
                type6 __value6__ = (type6)param6; \
-               if(CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
-               else {ret = PLAYER_ERROR_INVALID_STATE;break;} \
+               if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
+               else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
                __sndMsg__ = muse_core_msg_json_factory_new(api, \
                                MUSE_TYPE_##type1, #param1, __value1__, \
                                MUSE_TYPE_##type2, #param2, __value2__, \
@@ -285,7 +285,7 @@ extern "C" {
                } else \
                        ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), &retbuf, __timeout__); \
                muse_core_msg_json_factory_free(__sndMsg__); \
-       }while(0)
+       } while (0)
 
 /**
  * @brief Create and send message. Wait for server result.
@@ -299,19 +299,19 @@ extern "C" {
  * @param[in] datum_size The size of a array's datum.
  */
 #define player_msg_send_array(api, player, retbuf, ret, param, length, datum_size) \
-       do    \
+       do {    \
                char *__sndMsg__; \
                int __len__; \
                int __fd__; \
                int __timeout__ = client_get_api_timeout(player, api); \
                int *__value__ = (int *)param; \
-               if(CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
-               else {ret = PLAYER_ERROR_INVALID_STATE;break;} \
+               if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
+               else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
                __sndMsg__ = muse_core_msg_json_factory_new(api, \
                                MUSE_TYPE_INT, #length, length, \
                                MUSE_TYPE_ARRAY, #param, \
-                                       datum_size == sizeof(int)? length :  \
-                                       length / sizeof(int) + (length % sizeof(int)?1:0), \
+                                       datum_size == sizeof(int) ? length :  \
+                                       length / sizeof(int) + (length % sizeof(int) ? 1 : 0), \
                                        __value__, \
                                0); \
                __len__ = muse_core_ipc_send_msg(__fd__, __sndMsg__); \
@@ -321,7 +321,7 @@ extern "C" {
                } else \
                        ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), &retbuf, __timeout__); \
                muse_core_msg_json_factory_free(__sndMsg__); \
-       }while(0)
+       } while (0)
 
 /**
  * @brief Create and send message. Wait for server result.
@@ -335,25 +335,25 @@ extern "C" {
  * @param[in] datum_size# The size of a array's datum.
  */
 #define player_msg_send_array2(api, player, retbuf, ret, param1, length1, datum_size1, param2, length2, datum_size2) \
-       do    \
+       do {    \
                char *__sndMsg__; \
                int __len__; \
                int __fd__; \
                int __timeout__ = client_get_api_timeout(player, api); \
                int *__value1__ = (int *)param1; \
                int *__value2__ = (int *)param2; \
-               if(CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
-               else {ret = PLAYER_ERROR_INVALID_STATE;break;} \
+               if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
+               else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
                __sndMsg__ = muse_core_msg_json_factory_new(api, \
                                MUSE_TYPE_INT, #length1, length1, \
                                MUSE_TYPE_ARRAY, #param1, \
-                                       datum_size1 == sizeof(int)? length1 :  \
-                                       length1 / sizeof(int) + (length1 % sizeof(int)?1:0), \
+                                       datum_size1 == sizeof(int) ? length1 :  \
+                                       length1 / sizeof(int) + (length1 % sizeof(int) ? 1 : 0), \
                                        __value1__, \
                                MUSE_TYPE_INT, #length2, length2, \
                                MUSE_TYPE_ARRAY, #param2, \
-                                       datum_size2 == sizeof(int)? length2 :  \
-                                       length2 / sizeof(int) + (length2 % sizeof(int)?1:0), \
+                                       datum_size2 == sizeof(int) ? length2 :  \
+                                       length2 / sizeof(int) + (length2 % sizeof(int) ? 1 : 0), \
                                        __value2__, \
                                0); \
                __len__ = muse_core_ipc_send_msg(__fd__, __sndMsg__); \
@@ -363,7 +363,7 @@ extern "C" {
                } else \
                        ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), &retbuf, __timeout__); \
                muse_core_msg_json_factory_free(__sndMsg__); \
-       }while(0)
+       } while (0)
 
 /**
  * @brief Create and send message. Wait for server result.
@@ -377,37 +377,37 @@ extern "C" {
  * @param[in] datum_size# The size of a array's datum.
  */
 #define player_msg_send1_array2(api, player, retbuf, ret, type1, param1, param2, length2, datum_size2, param3, length3, datum_size3) \
-    do{ \
-        char *__sndMsg__; \
-        int __len__; \
-        int __fd__; \
-        int __timeout__ = client_get_api_timeout(player, api); \
-        type1 __value1__ = (type1)param1; \
-        int *__value2__ = (int *)param2; \
-        int *__value3__ = (int *)param3; \
-        if(CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
-        else {ret = PLAYER_ERROR_INVALID_STATE;break;} \
-        __sndMsg__ = muse_core_msg_json_factory_new(api, \
-                MUSE_TYPE_##type1, #param1, __value1__, \
-                MUSE_TYPE_INT, #length2, length2, \
-                MUSE_TYPE_ARRAY, #param2, \
-                    datum_size2 == sizeof(int)? length2 :  \
-                    length2 / sizeof(int) + (length2 % sizeof(int)?1:0), \
-                    __value2__, \
-                MUSE_TYPE_INT, #length3, length3, \
-                MUSE_TYPE_ARRAY, #param3, \
-                    datum_size3 == sizeof(int)? length3 :  \
-                    length3 / sizeof(int) + (length3 % sizeof(int)?1:0), \
-                    __value3__, \
-                0); \
-        __len__ = muse_core_ipc_send_msg(__fd__, __sndMsg__); \
-        if (__len__ <= 0) { \
-            LOGE("sending message failed"); \
-            ret = PLAYER_ERROR_INVALID_OPERATION; \
-        } else \
-            ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), &retbuf, __timeout__); \
-        muse_core_msg_json_factory_free(__sndMsg__); \
-    }while(0)
+       do { \
+               char *__sndMsg__; \
+               int __len__; \
+               int __fd__; \
+               int __timeout__ = client_get_api_timeout(player, api); \
+               type1 __value1__ = (type1)param1; \
+               int *__value2__ = (int *)param2; \
+               int *__value3__ = (int *)param3; \
+               if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
+               else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
+               __sndMsg__ = muse_core_msg_json_factory_new(api, \
+                       MUSE_TYPE_##type1, #param1, __value1__, \
+                       MUSE_TYPE_INT, #length2, length2, \
+                       MUSE_TYPE_ARRAY, #param2, \
+                               datum_size2 == sizeof(int) ? length2 :  \
+                               length2 / sizeof(int) + (length2 % sizeof(int) ? 1 : 0), \
+                               __value2__, \
+                       MUSE_TYPE_INT, #length3, length3, \
+                       MUSE_TYPE_ARRAY, #param3, \
+                               datum_size3 == sizeof(int) ? length3 :  \
+                               length3 / sizeof(int) + (length3 % sizeof(int) ? 1 : 0), \
+                               __value3__, \
+                       0); \
+           __len__ = muse_core_ipc_send_msg(__fd__, __sndMsg__); \
+               if (__len__ <= 0) { \
+                       LOGE("sending message failed"); \
+                       ret = PLAYER_ERROR_INVALID_OPERATION; \
+               } else \
+                       ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), &retbuf, __timeout__); \
+               muse_core_msg_json_factory_free(__sndMsg__); \
+       } while (0)
 
 /**
  * @brief Create and send message. Wait for server result.
@@ -422,23 +422,23 @@ extern "C" {
  * @param[in] datum_size# The size of a array's datum.
  */
 #define player_msg_send2_array(api, player, retbuf, ret, type1, param1, type2, param2, param_arr, length, datum_size) \
-       do    \
+       do {    \
                char *__sndMsg__; \
                int __len__; \
                int __fd__; \
                int __timeout__ = client_get_api_timeout(player, api); \
                type1 __value1__ = (type1)param1; \
                type2 __value2__ = (type2)param2; \
-        int *__value_arr__ = (int *)param_arr; \
-               if(CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
-               else {ret = PLAYER_ERROR_INVALID_STATE;break;} \
+               int *__value_arr__ = (int *)param_arr; \
+               if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
+               else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
                __sndMsg__ = muse_core_msg_json_factory_new(api, \
                                MUSE_TYPE_##type1, #param1, __value1__, \
                                MUSE_TYPE_##type2, #param2, __value2__, \
-                MUSE_TYPE_INT, #length, length, \
+                               MUSE_TYPE_INT, #length, length, \
                                MUSE_TYPE_ARRAY, #param_arr, \
-                                       datum_size == sizeof(int)? length :  \
-                                       length / sizeof(int) + (length % sizeof(int)?1:0), \
+                                       datum_size == sizeof(int) ? length :  \
+                                       length / sizeof(int) + (length % sizeof(int) ? 1 : 0), \
                                        __value_arr__, \
                                0); \
                __len__ = muse_core_ipc_send_msg(__fd__, __sndMsg__); \
@@ -448,7 +448,7 @@ extern "C" {
                } else \
                        ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), &retbuf, __timeout__); \
                muse_core_msg_json_factory_free(__sndMsg__); \
-       }while(0)
+       } while (0)
 
 /**
  * @brief Create and send message. Wait for server result.
@@ -463,41 +463,41 @@ extern "C" {
  * @param[in] datum_size# The size of a array's datum.
  */
 #define player_msg_send3_array2(api, player, retbuf, ret, type1, param1, type2, param2, type3, param3, param4, length4, datum_size4, param5, length5, datum_size5) \
-            do{ \
-                char *__sndMsg__; \
-                int __len__; \
-                int __fd__; \
-                int __timeout__ = client_get_api_timeout(player, api); \
-                type1 __value1__ = (type1)param1; \
-                type2 __value2__ = (type2)param2; \
-                type3 __value3__ = (type3)param3; \
-                int *__value4__ = (int *)param4; \
-                int *__value5__ = (int *)param5; \
-                if(CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
-                else {ret = PLAYER_ERROR_INVALID_STATE;break;} \
-                __sndMsg__ = muse_core_msg_json_factory_new(api, \
-                        MUSE_TYPE_##type1, #param1, __value1__, \
-                        MUSE_TYPE_##type2, #param2, __value2__, \
-                        MUSE_TYPE_##type3, #param3, __value3__, \
-                        MUSE_TYPE_INT, #length4, length4, \
-                        MUSE_TYPE_ARRAY, #param4, \
-                            datum_size4 == sizeof(int)? length4 :  \
-                            length4 / sizeof(int) + (length4 % sizeof(int)?1:0), \
-                            __value4__, \
-                        MUSE_TYPE_INT, #length5, length5, \
-                        MUSE_TYPE_ARRAY, #param5, \
-                            datum_size5 == sizeof(int)? length5 :  \
-                            length5 / sizeof(int) + (length5 % sizeof(int)?1:0), \
-                            __value5__, \
-                        0); \
-                __len__ = muse_core_ipc_send_msg(__fd__, __sndMsg__); \
-                if (__len__ <= 0) { \
-                    LOGE("sending message failed"); \
-                    ret = PLAYER_ERROR_INVALID_OPERATION; \
-                } else \
-                    ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), &retbuf, __timeout__); \
-                muse_core_msg_json_factory_free(__sndMsg__); \
-            }while(0)
+       do { \
+               char *__sndMsg__; \
+               int __len__; \
+               int __fd__; \
+               int __timeout__ = client_get_api_timeout(player, api); \
+               type1 __value1__ = (type1)param1; \
+               type2 __value2__ = (type2)param2; \
+               type3 __value3__ = (type3)param3; \
+               int *__value4__ = (int *)param4; \
+               int *__value5__ = (int *)param5; \
+               if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
+               else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
+               __sndMsg__ = muse_core_msg_json_factory_new(api, \
+                               MUSE_TYPE_##type1, #param1, __value1__, \
+                               MUSE_TYPE_##type2, #param2, __value2__, \
+                               MUSE_TYPE_##type3, #param3, __value3__, \
+                               MUSE_TYPE_INT, #length4, length4, \
+                               MUSE_TYPE_ARRAY, #param4, \
+                                       datum_size4 == sizeof(int) ? length4 :  \
+                                       length4 / sizeof(int) + (length4 % sizeof(int) ? 1 : 0), \
+                                       __value4__, \
+                               MUSE_TYPE_INT, #length5, length5, \
+                               MUSE_TYPE_ARRAY, #param5, \
+                                       datum_size5 == sizeof(int) ? length5 :  \
+                                       length5 / sizeof(int) + (length5 % sizeof(int) ? 1 : 0), \
+                                       __value5__, \
+                               0); \
+               __len__ = muse_core_ipc_send_msg(__fd__, __sndMsg__); \
+               if (__len__ <= 0) { \
+                       LOGE("sending message failed"); \
+                       ret = PLAYER_ERROR_INVALID_OPERATION; \
+               } else \
+                       ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), &retbuf, __timeout__); \
+               muse_core_msg_json_factory_free(__sndMsg__); \
+       } while (0)
 
 /**
  * @brief Create and send message. Does not wait server result.
@@ -508,13 +508,13 @@ extern "C" {
  * @param[in] param the name of param is key, must be local variable. never be pointer.
  */
 #define player_msg_send1_async(api, player, type, param) \
-       do    \
+       do {    \
                char *__sndMsg__; \
                int __len__; \
                int __fd__; \
                type __value__ = (type)param; \
-               if(CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
-               else {ret = PLAYER_ERROR_INVALID_STATE;break;} \
+               if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
+               else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
                __sndMsg__ = muse_core_msg_json_factory_new(api, \
                                MUSE_TYPE_##type, #param, __value__, \
                                0); \
@@ -524,7 +524,7 @@ extern "C" {
                        LOGE("sending message failed"); \
                        return PLAYER_ERROR_INVALID_OPERATION; \
                } \
-       }while(0)
+       } while (0)
 
 /**
  * @brief Create and send message. Does not wait server result.
@@ -535,7 +535,7 @@ extern "C" {
  * @param[in] param the name of param is key, must be local variable. never be pointer.
  */
 #define player_msg_send1_no_return(api, fd, type, param) \
-       do{ \
+       do { \
                char *__sndMsg__; \
                int __len__; \
                type __value__ = (type)param; \
@@ -547,7 +547,7 @@ extern "C" {
                if (__len__ <= 0) { \
                        LOGE("sending message failed"); \
                } \
-       }while(0)
+       } while (0)
 
 /**
  * @brief Create and send message. Does not wait server result.
@@ -559,7 +559,7 @@ extern "C" {
  * @param[in] param the name of param is key, must be local variable. never be pointer.
  */
 #define player_msg_create_handle(api, fd, type1, param1, type2, param2) \
-       do    \
+       do {    \
                char *__sndMsg__; \
                int __len__; \
                type1 __value1__ = (type1)param1; \
@@ -574,7 +574,7 @@ extern "C" {
                        LOGE("sending message failed"); \
                        return PLAYER_ERROR_INVALID_OPERATION; \
                } \
-       }while(0)
+       } while (0)
 
 
 /**
@@ -587,14 +587,14 @@ extern "C" {
  * @param[in] set 1 is set the user callback, 0 is unset the user callback.
  */
 #define player_msg_set_callback(api, player, ret, event_type, set) \
-       do    \
+       do {    \
                char *__sndMsg__; \
                int __len__; \
                int __fd__; \
                int __value1__ = (int)event_type; \
                int __value2__ = (int)set; \
-               if(CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
-               else {ret = PLAYER_ERROR_INVALID_STATE;break;} \
+               if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
+               else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
                __sndMsg__ = muse_core_msg_json_factory_new(api, \
                                MUSE_TYPE_INT, #event_type, __value1__, \
                                MUSE_TYPE_INT, #set, __value2__, \
@@ -605,7 +605,7 @@ extern "C" {
                        LOGE("sending message failed"); \
                        ret = PLAYER_ERROR_INVALID_OPERATION; \
                } \
-       }while(0)
+       } while (0)
 
 /**
  * @brief Get value from Message.
@@ -622,18 +622,18 @@ extern "C" {
                void *__jobj__ = muse_core_msg_json_object_new(buf, NULL, NULL); \
                if (!muse_core_msg_json_object_get_value(#param1, __jobj__, &param1, MUSE_TYPE_##type1)) { \
                        LOGE("failed to get value(%s)", #param1); \
-                       ret=FALSE; \
+                       ret = FALSE; \
                } \
                if (ret && !muse_core_msg_json_object_get_value(#param2, __jobj__, &param2, MUSE_TYPE_##type2)) { \
                        LOGE("failed to get %s value", #param2); \
-                       ret=FALSE; \
+                       ret = FALSE; \
                } \
                if (ret && !muse_core_msg_json_object_get_value(#arr_param, __jobj__, arr_param, MUSE_TYPE_ANY)) { \
                        LOGE("failed to get %s value", #arr_param); \
-                       ret=FALSE; \
+                       ret = FALSE; \
                } \
                muse_core_msg_json_object_free(__jobj__); \
-       } while(0)
+       } while (0)
 
 /**
  * @brief Get value from Message.
@@ -660,6 +660,6 @@ extern "C" {
                        } \
                        muse_core_msg_json_object_free(__jobj__); \
                } \
-       } while(0)
+       } while (0)
 
 #endif /* __TIZEN_MEDIA_PLAYER_MSG_PRIVATE_H__ */
index aac2656..78adcd8 100644 (file)
@@ -76,6 +76,11 @@ typedef struct {
        gboolean running;
 } player_event_queue;
 
+typedef struct {
+       tbm_key key;
+       tbm_surface_h tsurf;
+} player_tsurf_info_t;
+
 typedef struct _callback_cb_info {
        GThread *thread;
        gint running;
@@ -86,7 +91,7 @@ typedef struct _callback_cb_info {
        GMutex player_mutex;
        GCond player_cond[MUSE_PLAYER_API_MAX];
        GList *packet_list;
-       GMutex packet_list_mutex;
+       GMutex data_mutex;
        gboolean block_seek_cb;
        GMutex seek_cb_mutex;
        msg_buff_s buff;
@@ -94,6 +99,8 @@ typedef struct _callback_cb_info {
        media_format_h pkt_fmt;
        void *evas_info;
        tbm_bufmgr bufmgr;
+       GList *tsurf_list; /* player_tsurf_info_t */
+       int video_frame_pool_size;
 } callback_cb_info_s;
 
 typedef struct {
index 395abfb..632d905 100644 (file)
@@ -177,12 +177,12 @@ int player_set_media_stream_dynamic_resolution(player_h player, bool drc);
  * @since_tizen 3.0
  *
  * @details Player will transite the media source as seamlessly as possible after finishing current playback.
- *             If the function call is successful, the uri will be added at the end of uri list.
- *               You can add several uris and the set of uris will be played repeatedly if you call the player_set_looping().
- *               The first uri in the list is the original uri which is set by player_set_uri().
+ *          If the function call is successful, the uri will be added at the end of uri list.
+ *          You can add several uris and the set of uris will be played repeatedly if you call the player_set_looping().
+ *          The first uri in the list is the original uri which is set by player_set_uri().
  *
- * @remarks  Uri list will be cleared except first one when the player_unprepare() is called.
- *                     If you call the player_set_uri(), you can change the first uri too.
+ * @remarks Uri list will be cleared except first one when the player_unprepare() is called.
+ *          If you call the player_set_uri(), you can change the first uri too.
  *
  * @param[in]   player The handle to the media player
  * @param[in]   uri Specifies the data location.
@@ -197,7 +197,7 @@ int player_set_media_stream_dynamic_resolution(player_h player, bool drc);
  * @pre The player state must be one of these: #PLAYER_STATE_IDLE, #PLAYER_STATE_READY, #PLAYER_STATE_PLAYING, or #PLAYER_STATE_PAUSED.
  * @see player_set_uri(), player_set_looping()
  */
-int player_set_next_uri (player_h player, const char *uri);
+int player_set_next_uri(player_h player, const char *uri);
 
 /**
  * @brief Gets the data source path.
@@ -215,7 +215,7 @@ int player_set_next_uri (player_h player, const char *uri);
  * @pre The player state must be one of these: #PLAYER_STATE_IDLE, #PLAYER_STATE_READY, #PLAYER_STATE_PLAYING, or #PLAYER_STATE_PAUSED.
  * @see player_set_uri()
  */
-int player_get_next_uri (player_h player, char **uri);
+int player_get_next_uri(player_h player, char **uri);
 
 /**
  * @brief Sets the gapless playback status
@@ -274,7 +274,22 @@ int player_is_gapless(player_h player, bool *gapless);
  */
 int player_set_ecore_wl_display(player_h player, player_display_type_e type, Ecore_Wl_Window *ecore_wl_window, int x, int y, int  width, int height);
 
-
+/**
+ * @brief Gets the size of video frame pool.
+ * @since_tizen 3.0
+ * @details App gets the video frame pool size which will be reused during playback.
+ * @param[in] player The handle to the media player
+ * @param[out] size The size of surface pool
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #PLAYER_ERROR_NONE Successful
+ * @retval #PLAYER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PLAYER_ERROR_INVALID_OPERATION Invalid operation
+ * @retval #PLAYER_ERROR_INVALID_STATE Invalid player state
+ * @pre The player state must be one of these: #PLAYER_STATE_READY, #PLAYER_STATE_PLAYING, or #PLAYER_STATE_PAUSED
+ * @see player_set_media_packet_video_frame_decoded_cb()
+ */
+int player_get_media_packet_video_frame_pool_size(player_h player, int *size);
 
 /**
  * @}
index 34be4cc..52a3282 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-player
 Summary:    A Media Player API
-Version:    0.3.11
+Version:    0.3.12
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 26ff5f7..f97a41d 100644 (file)
@@ -68,7 +68,6 @@ static int _player_deinit_memory_buffer(player_cli_s * pc);
 int _player_media_packet_finalize(media_packet_h pkt, int error_code, void *user_data)
 {
        int ret = MEDIA_PACKET_FINALIZE;
-       tbm_surface_h tsurf = NULL;
        muse_player_api_e api = MUSE_PLAYER_API_MEDIA_PACKET_FINALIZE_CB;
        _media_pkt_fin_data *fin_data = (_media_pkt_fin_data *) user_data;
        intptr_t packet;
@@ -80,23 +79,15 @@ int _player_media_packet_finalize(media_packet_h pkt, int error_code, void *user
                return ret;
        }
 
-       ret = media_packet_get_tbm_surface(pkt, &tsurf);
-       if (ret != MEDIA_PACKET_ERROR_NONE) {
-               LOGE("media_packet_get_tbm_surface failed 0x%x", ret);
-               goto EXIT;
-       }
-
-       if (tsurf) {
-               tbm_surface_destroy(tsurf);
-               tsurf = NULL;
-       }
-
        if (!fin_data || fin_data->fd <= INVALID_SOCKET) {
                LOGE("invalid parameter, fd: %d", (fin_data) ? (fin_data->fd) : (-1));
                goto EXIT;
        }
 
-#if 1 /* FIXME : after applying media_packet_pool, no need to check packet_list manully. */
+       /* Do not destroy tbm surface here to reuse during playback          *
+        * they will be destroyed at player_unprepare() or player_destroy(). *
+        * ref: __player_remove_tsurf_list()                                 */
+
        packet = fin_data->remote_pkt;
        snd_msg = muse_core_msg_json_factory_new(api, MUSE_TYPE_POINTER, "packet", packet, 0);
        snd_len = muse_core_ipc_send_msg(fin_data->fd, snd_msg);
@@ -105,22 +96,19 @@ int _player_media_packet_finalize(media_packet_h pkt, int error_code, void *user
        if (snd_len > 0) {
                /* player handle is available. remove packet from the list */
                if (fin_data->cb_info->packet_list) {
-                       g_mutex_lock(&fin_data->cb_info->packet_list_mutex);
+                       g_mutex_lock(&fin_data->cb_info->data_mutex);
                        if (g_list_find(fin_data->cb_info->packet_list, pkt)) {
                                fin_data->cb_info->packet_list = g_list_remove(fin_data->cb_info->packet_list, pkt);
                        } else {
                                LOGW("there is no packet(%p) in exported list.", pkt);
                        }
-                       g_mutex_unlock(&fin_data->cb_info->packet_list_mutex);
+                       g_mutex_unlock(&fin_data->cb_info->data_mutex);
                } else {
                        LOGW("there is no packet list.", pkt);
                }
        } else {
                LOGE("fail to send msg.");
        }
-#else
-       player_msg_send1_no_return(api, fin_data->cb_info->fd, POINTER, packet);
-#endif
 
 EXIT:
        if (fin_data) {
@@ -531,6 +519,51 @@ static void __seek_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
        g_mutex_unlock(&cb_info->seek_cb_mutex);
 }
 
+static void __player_remove_tsurf_list(player_cli_s * pc)
+{
+       GList *l = NULL;
+
+       g_mutex_lock(&pc->cb_info->data_mutex);
+       if (pc->cb_info->tsurf_list) {
+               LOGD("total num of tsurf list = %d", g_list_length(pc->cb_info->tsurf_list));
+
+               for (l = g_list_first(pc->cb_info->tsurf_list); l; l = g_list_next(l)) {
+                       player_tsurf_info_t* tmp = (player_tsurf_info_t *)l->data;
+
+                       LOGD("%p will be removed", tmp);
+                       if (tmp) {
+                               if (tmp->tsurf) {
+                                       tbm_surface_destroy(tmp->tsurf);
+                                       tmp->tsurf = NULL;
+                               }
+                               g_free(tmp);
+                       }
+               }
+               g_list_free(pc->cb_info->tsurf_list);
+               pc->cb_info->tsurf_list = NULL;
+       }
+       g_mutex_unlock(&pc->cb_info->data_mutex);
+       return;
+}
+
+static player_tsurf_info_t* __player_get_tsurf_from_list(callback_cb_info_s * cb_info, tbm_key key)
+{
+       GList *l = NULL;
+
+       g_mutex_lock(&cb_info->data_mutex);
+       for (l = g_list_first(cb_info->tsurf_list); l; l = g_list_next(l)) {
+               player_tsurf_info_t *tmp = (player_tsurf_info_t *)l->data;
+               if (tmp && (tmp->key == key)) {
+                       LOGD("found tsurf_data of tbm_key %d", key);
+                       g_mutex_unlock(&cb_info->data_mutex);
+                       return tmp;
+               }
+       }
+       g_mutex_unlock(&cb_info->data_mutex);
+       LOGD("there is no tsurf_data for tbm_key:%d", key);
+       return NULL;
+}
+
 static void __media_packet_video_frame_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
 {
        tbm_bo bo[4] = { NULL, };
@@ -539,11 +572,12 @@ static void __media_packet_video_frame_cb_handler(callback_cb_info_s * cb_info,
        char *surface_info = (char *)&sinfo;
        media_packet_h pkt = NULL;
        tbm_surface_h tsurf = NULL;
+       player_tsurf_info_t *tsurf_data = NULL;
        int bo_num = 0;
        media_format_mimetype_e mimetype = MEDIA_FORMAT_NV12;
        bool make_pkt_fmt = false;
-       int ret;
-       _media_pkt_fin_data *fin_data;
+       int ret = MEDIA_FORMAT_ERROR_NONE;
+       _media_pkt_fin_data *fin_data = NULL;
        intptr_t packet;
        uint64_t pts = 0;
        int i = 0;
@@ -588,74 +622,120 @@ static void __media_packet_video_frame_cb_handler(callback_cb_info_s * cb_info,
                }
        }
 
-       tsurf = tbm_surface_internal_create_with_bos(&sinfo, bo, bo_num);
-       if (tsurf) {
-               /* check media packet format */
-               if (cb_info->pkt_fmt) {
-                       int pkt_fmt_width = 0;
-                       int pkt_fmt_height = 0;
-                       media_format_mimetype_e pkt_fmt_mimetype = MEDIA_FORMAT_NV12;
-
-                       media_format_get_video_info(cb_info->pkt_fmt, &pkt_fmt_mimetype, &pkt_fmt_width, &pkt_fmt_height, NULL, NULL);
-                       if (pkt_fmt_mimetype != mimetype || pkt_fmt_width != sinfo.width || pkt_fmt_height != sinfo.height) {
-                               LOGW("different format. current 0x%x, %dx%d, new 0x%x, %dx%d", pkt_fmt_mimetype, pkt_fmt_width, pkt_fmt_height, mimetype, sinfo.width, sinfo.height);
-                               media_format_unref(cb_info->pkt_fmt);
-                               cb_info->pkt_fmt = NULL;
-                               make_pkt_fmt = true;
-                       }
-               } else {
-                       make_pkt_fmt = true;
-               }
-               /* create packet format */
-               if (make_pkt_fmt) {
-                       LOGI("make new pkt_fmt - mimetype 0x%x, %dx%d", mimetype, sinfo.width, sinfo.height);
-                       ret = media_format_create(&cb_info->pkt_fmt);
-                       if (ret == MEDIA_FORMAT_ERROR_NONE) {
-                               ret = media_format_set_video_mime(cb_info->pkt_fmt, mimetype);
-                               ret |= media_format_set_video_width(cb_info->pkt_fmt, sinfo.width);
-                               ret |= media_format_set_video_height(cb_info->pkt_fmt, sinfo.height);
-                               LOGI("media_format_set_video_mime,width,height ret : 0x%x", ret);
-                       } else {
-                               LOGE("media_format_create failed");
-                       }
+       tsurf_data = __player_get_tsurf_from_list(cb_info, key[0]);
+       if (!tsurf_data) {
+               tsurf_data = g_new(player_tsurf_info_t, 1);
+               if (!tsurf_data) {
+                       LOGE("failed to alloc tsurf info");
+                       goto ERROR;
                }
 
-               fin_data = g_new(_media_pkt_fin_data, 1);
-               fin_data->remote_pkt = packet;
-               fin_data->cb_info = cb_info;
-               fin_data->fd = cb_info->fd;
-               ret = media_packet_create_from_tbm_surface(cb_info->pkt_fmt, tsurf, (media_packet_finalize_cb) _player_media_packet_finalize, (void *)fin_data, &pkt);
-               if (ret != MEDIA_PACKET_ERROR_NONE) {
-                       LOGE("media_packet_create_from_tbm_surface failed");
-                       tbm_surface_destroy(tsurf);
-                       tsurf = NULL;
+               tsurf = tbm_surface_internal_create_with_bos(&sinfo, bo, bo_num);
+               if (!tsurf) {
+                       LOGE("failed to create tbm surface");
+                       g_free(tsurf_data);
+                       goto ERROR;
+               }
+               tsurf_data->key = key[0];
+               tsurf_data->tsurf = tsurf;
+               g_mutex_lock(&cb_info->data_mutex);
+               cb_info->tsurf_list = g_list_append(cb_info->tsurf_list, tsurf_data);
+               LOGD("key %d is added to the pool", key[0]);
+               if (cb_info->video_frame_pool_size < g_list_length(cb_info->tsurf_list)) {
+                       LOGE("need to check the pool size: %d < %d", cb_info->video_frame_pool_size, g_list_length(cb_info->tsurf_list));
+               }
+               g_mutex_unlock(&cb_info->data_mutex);
+       } else {
+               if (tsurf_data->tsurf) {
+                       tsurf = tsurf_data->tsurf;
+               } else {
+                       LOGE("tsurf_data->tsurf is null (never enter here)");
+                       goto ERROR;
                }
-
-               /* keep the media packet to avoid mem leak. */
-               g_mutex_lock(&cb_info->packet_list_mutex);
-               cb_info->packet_list = g_list_append(cb_info->packet_list, pkt);
-               g_mutex_unlock(&cb_info->packet_list_mutex);
        }
 
-       if (pkt) {
-               if (pts != 0) {
-                       ret = media_packet_set_pts(pkt, (uint64_t) pts);
-                       if (ret != MEDIA_PACKET_ERROR_NONE)
-                               LOGE("media_packet_set_pts failed");
+       /* check media packet format */
+       if (cb_info->pkt_fmt) {
+               int pkt_fmt_width = 0;
+               int pkt_fmt_height = 0;
+               media_format_mimetype_e pkt_fmt_mimetype = MEDIA_FORMAT_NV12;
+
+               media_format_get_video_info(cb_info->pkt_fmt, &pkt_fmt_mimetype, &pkt_fmt_width, &pkt_fmt_height, NULL, NULL);
+               if (pkt_fmt_mimetype != mimetype || pkt_fmt_width != sinfo.width || pkt_fmt_height != sinfo.height) {
+                       LOGW("different format. current 0x%x, %dx%d, new 0x%x, %dx%d", pkt_fmt_mimetype, pkt_fmt_width, pkt_fmt_height, mimetype, sinfo.width, sinfo.height);
+                       media_format_unref(cb_info->pkt_fmt);
+                       cb_info->pkt_fmt = NULL;
+                       make_pkt_fmt = true;
                }
-               if (cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) {
-                       /* call media packet callback */
-                       ((player_media_packet_video_decoded_cb) cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) (pkt, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]);
+       } else {
+               make_pkt_fmt = true;
+       }
+       /* create packet format */
+       if (make_pkt_fmt) {
+               LOGI("make new pkt_fmt - mimetype 0x%x, %dx%d", mimetype, sinfo.width, sinfo.height);
+               ret = media_format_create(&cb_info->pkt_fmt);
+               if (ret == MEDIA_FORMAT_ERROR_NONE) {
+                       ret = media_format_set_video_mime(cb_info->pkt_fmt, mimetype);
+                       ret |= media_format_set_video_width(cb_info->pkt_fmt, sinfo.width);
+                       ret |= media_format_set_video_height(cb_info->pkt_fmt, sinfo.height);
+                       LOGI("media_format_set_video_mime,width,height ret : 0x%x", ret);
                } else {
-                       LOGE("_video_decoded_cb is not set");
-                       media_packet_destroy(pkt);
+                       LOGE("media_format_create failed");
                }
        }
 
+       fin_data = g_new(_media_pkt_fin_data, 1);
+       if (!fin_data) {
+               LOGE("failed to alloc fin_data");
+               goto ERROR;
+       }
+       fin_data->remote_pkt = packet;
+       fin_data->cb_info = cb_info;
+       fin_data->fd = cb_info->fd;
+       ret = media_packet_create_from_tbm_surface(cb_info->pkt_fmt, tsurf, (media_packet_finalize_cb) _player_media_packet_finalize, (void *)fin_data, &pkt);
+       if (ret != MEDIA_PACKET_ERROR_NONE || !pkt) {
+               LOGE("media_packet_create_from_tbm_surface failed %d %p", ret, pkt);
+               goto ERROR;
+       }
+
+       /* keep the media packet to avoid mem leak. */
+       g_mutex_lock(&cb_info->data_mutex);
+       cb_info->packet_list = g_list_append(cb_info->packet_list, pkt);
+       g_mutex_unlock(&cb_info->data_mutex);
+
+       if (pts != 0) {
+               ret = media_packet_set_pts(pkt, (uint64_t) pts);
+               if (ret != MEDIA_PACKET_ERROR_NONE)
+                       LOGE("media_packet_set_pts failed");
+       }
+       if (cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) {
+               /* call media packet callback */
+               ((player_media_packet_video_decoded_cb) cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]) (pkt, cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]);
+       } else {
+               LOGE("_video_decoded_cb is not set");
+               media_packet_destroy(pkt);
+       }
+
+       for (i = 0; i < bo_num; i++) {
+               if (bo[i])
+                       tbm_bo_unref(bo[i]);
+       }
+       return;
+
+ERROR:
+       if (pkt)
+               media_packet_destroy(pkt);
+
+       if (fin_data)
+               g_free(fin_data);
+
        for (i = 0; i < bo_num; i++) {
                if (bo[i])
                        tbm_bo_unref(bo[i]);
        }
+
+       player_msg_send1_no_return(MUSE_PLAYER_API_MEDIA_PACKET_FINALIZE_CB, cb_info->fd, POINTER, packet);
+       return;
 }
 
 static void __audio_frame_cb_handler(callback_cb_info_s * cb_info, char *recvMsg)
@@ -1131,7 +1211,7 @@ static callback_cb_info_s *callback_new(gint sockfd)
        for (i = 0; i < MUSE_PLAYER_API_MAX; i++)
                g_cond_init(&cb_info->player_cond[i]);
 
-       g_mutex_init(&cb_info->packet_list_mutex);
+       g_mutex_init(&cb_info->data_mutex);
        g_mutex_init(&cb_info->seek_cb_mutex);
 
        buff = &cb_info->buff;
@@ -1169,7 +1249,7 @@ static void callback_destroy(callback_cb_info_s * cb_info)
        for (i = 0; i < MUSE_PLAYER_API_MAX; i++)
                g_cond_clear(&cb_info->player_cond[i]);
 
-       g_mutex_clear(&cb_info->packet_list_mutex);
+       g_mutex_clear(&cb_info->data_mutex);
        g_mutex_clear(&cb_info->seek_cb_mutex);
 
        g_free(cb_info->buff.recvMsg);
@@ -1333,18 +1413,19 @@ int player_destroy(player_h player)
        }
 #endif
        if (pc->cb_info && pc->cb_info->packet_list) {
-               g_mutex_lock(&pc->cb_info->packet_list_mutex);
+               g_mutex_lock(&pc->cb_info->data_mutex);
                LOGW("num of remained packets : %d !!", g_list_length(pc->cb_info->packet_list));
                /* each media packet have to destroyed in application. */
                g_list_free(pc->cb_info->packet_list);
                pc->cb_info->packet_list = NULL;
-               g_mutex_unlock(&pc->cb_info->packet_list_mutex);
+               g_mutex_unlock(&pc->cb_info->data_mutex);
        }
 
        if (player_unset_evas_object_cb(player) != MM_ERROR_NONE)
                LOGW("fail to unset evas object callback");
 
        if (CALLBACK_INFO(pc)) {
+               __player_remove_tsurf_list(pc);
                _player_event_queue_destroy(CALLBACK_INFO(pc));
                tbm_bufmgr_deinit(TBM_BUFMGR(pc));
 
@@ -1438,6 +1519,9 @@ int player_unprepare(player_h player)
                _player_deinit_memory_buffer(pc);
        }
 
+       pc->cb_info->video_frame_pool_size = 0;
+       __player_remove_tsurf_list(pc);
+
        g_free(ret_buf);
        return ret;
 }
@@ -2004,8 +2088,7 @@ int player_set_display(player_h player, player_display_type_e type, player_displ
                                return PLAYER_ERROR_INVALID_PARAMETER;
                } else
                        return PLAYER_ERROR_INVALID_PARAMETER;
-       }
-       else {  /* PLAYER_DISPLAY_TYPE_NONE */
+       } else {        /* PLAYER_DISPLAY_TYPE_NONE */
                LOGI("Wayland surface type is NONE");
                wl_win.type = type;
                wl_win.wl_window_x = 0;
index b306764..3c90401 100644 (file)
@@ -358,7 +358,7 @@ int player_set_next_uri(player_h player, const char *uri)
        return ret;
 }
 
-int player_get_next_uri (player_h player, char **uri)
+int player_get_next_uri(player_h player, char **uri)
 {
        PLAYER_INSTANCE_CHECK(player);
        PLAYER_NULL_ARG_CHECK(uri);
@@ -414,4 +414,28 @@ int player_is_gapless(player_h player, bool *gapless)
        g_free(ret_buf);
        return ret;
 }
+
+int player_get_media_packet_video_frame_pool_size(player_h player, int *size)
+{
+       PLAYER_INSTANCE_CHECK(player);
+       PLAYER_NULL_ARG_CHECK(size);
+
+       int ret = PLAYER_ERROR_NONE;
+       muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_PACKET_VIDEO_FRAME_POOL_SIZE;
+       player_cli_s *pc = (player_cli_s *) player;
+       char *ret_buf = NULL;
+       int value = 0;
+
+       LOGD("ENTER");
+
+       player_msg_send(api, pc, ret_buf, ret);
+       if (ret == PLAYER_ERROR_NONE) {
+               player_msg_get(value, ret_buf);
+               *size = value;
+               pc->cb_info->video_frame_pool_size = value;
+               LOGD("packet pool size : %d", *size);
+       }
+       g_free(ret_buf);
+       return ret;
+}
 #endif