update mediatool for tizen_3.0 36/40236/3 accepted/tizen/mobile/20150608.002057 accepted/tizen/tv/20150608.002039 accepted/tizen/wearable/20150608.002105 submit/tizen/20150605.074530
authorjihae.yi <jihae.yi@samsung.com>
Mon, 1 Jun 2015 09:41:47 +0000 (18:41 +0900)
committerjihae.yi <jihae.yi@samsung.com>
Thu, 4 Jun 2015 00:45:55 +0000 (09:45 +0900)
Change-Id: I6a40060fd904b40a162f374cf6cb0574e62318dc

include/media_format.h [changed mode: 0644->0755]
include/media_format_private.h [changed mode: 0644->0755]
include/media_packet.h [changed mode: 0644->0755]
include/media_packet_internal.h [new file with mode: 0755]
include/media_packet_private.h [changed mode: 0644->0755]
packaging/capi-media-tool.spec [changed mode: 0644->0755]
src/media_format.c [changed mode: 0644->0755]
src/media_packet.c [changed mode: 0644->0755]
src/media_packet_internal.c [new file with mode: 0755]
test/CMakeLists.txt [changed mode: 0644->0755]
test/media_packet_test.c [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 11d7f05..bfcabb0
@@ -60,11 +60,12 @@ typedef enum
  * @since_tizen 2.3
  */
 typedef enum {
-    MEDIA_FORMAT_NONE    = 0x00000000,          /**< media format type is NONE */
-    MEDIA_FORMAT_AUDIO   = 0x01000000,          /**< media format type is AUDIO */
-    MEDIA_FORMAT_VIDEO   = 0x02000000,          /**< media format type is VIDEO */
-    MEDIA_FORMAT_TEXT    = 0x03000000,          /**< media format type is TEXT */
-    MEDIA_FORMAT_UNKNOWN = 0x0a000000,          /**< media format type is UNKNOWN */
+    MEDIA_FORMAT_NONE         = 0x00000000,          /**< media format type is NONE */
+    MEDIA_FORMAT_AUDIO        = 0x00100000,          /**< media format type is AUDIO */
+    MEDIA_FORMAT_VIDEO        = 0x00200000,          /**< media format type is VIDEO */
+    MEDIA_FORMAT_CONTAINER    = 0x00400000,          /**< media format type is CONTAINER */
+    MEDIA_FORMAT_TEXT         = 0x00800000,          /**< media format type is TEXT */
+    MEDIA_FORMAT_UNKNOWN      = 0x08000000,          /**< media format type is UNKNOWN */
 } media_format_type_e;
 
 /**
@@ -87,46 +88,79 @@ typedef enum {
 */
 typedef enum {
     /* Audio */
-    MEDIA_FORMAT_L16 = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1010),          /**< media format mime type is L16, AUDIO*/
+    MEDIA_FORMAT_L16 = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1010),           /**< media format mime type is L16, AUDIO*/
     MEDIA_FORMAT_ALAW = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1020),          /**< media format mime type is ALAW, AUDIO*/
     MEDIA_FORMAT_ULAW = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1030),          /**< media format mime type is ULAW,  AUDIO */
-    MEDIA_FORMAT_AMR = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1040),          /**< media format mime type is AMR,  AUDIO */
+    MEDIA_FORMAT_AMR = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1040),           /**< media format mime type is AMR,  AUDIO,  indicates MEDIA_FORMAT_AMR_NB (Since tizen 2.4) */
+    MEDIA_FORMAT_AMR_NB = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1040),        /**< media format mime type is AMR_NB,  AUDIO , (Since tizen 2.4) */
+    MEDIA_FORMAT_AMR_WB = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1041),        /**< media format mime type is AMR_WB,  AUDIO, (Since tizen 2.4) */
     MEDIA_FORMAT_G729 = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1050),          /**< media format mime type is G729,  AUDIO*/
-    MEDIA_FORMAT_AAC = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1060),          /**< media format mime type is AAC,  AUDIO*/
-    MEDIA_FORMAT_MP3 = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1070),          /**< media format mime type is MP3,  AUDIO*/
+    MEDIA_FORMAT_AAC = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1060),           /**< media format mime type is AAC,  AUDIO, indicates MEDIA_FORMAT_AAC_LC (Since tizen 2.4) */
+    MEDIA_FORMAT_AAC_LC = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1060),        /**< media format mime type is AAC_LC,  AUDIO, (Since tizen 2.4) */
+    MEDIA_FORMAT_AAC_HE = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1061),        /**< media format mime type is AAC_HE,  AUDIO, (Since tizen 2.4) */
+    MEDIA_FORMAT_AAC_HE_PS = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1062),     /**< media format mime type is AAC_HE_PS,  AUDIO, (Since tizen 2.4) */
+    MEDIA_FORMAT_MP3 = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1070),           /**< media format mime type is MP3,  AUDIO*/
+    MEDIA_FORMAT_VORBIS = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1080),        /**< media format mime type is VORBIS,  AUDIO, (Since tizen 2.4) */
+    MEDIA_FORMAT_FLAC = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1090),          /**< media format mime type is FLAC,  AUDIO, (Since tizen 2.4) */
+    MEDIA_FORMAT_WMAV1 = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x10A0),         /**< media format mime type is WMAV1,  AUDIO, (Since tizen 2.4) */
+    MEDIA_FORMAT_WMAV2 = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x10A1),         /**< media format mime type is WMAV2,  AUDIO, (Since tizen 2.4) */
+    MEDIA_FORMAT_WMAPRO = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x10A2),        /**< media format mime type is WMAVPRO,  AUDIO, (Since tizen 2.4) */
+    MEDIA_FORMAT_WMALSL = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x10A3),        /**< media format mime type is WMAVLSL,  AUDIO, (Since tizen 2.4) */
+
+    MEDIA_FORMAT_PCM = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_RAW | 0x1510),               /**< media format mime type is PCM, AUDIO*/
+    MEDIA_FORMAT_PCMA = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_RAW | 0x1520),              /**< media format mime type is PCM A-law, AUDIO*/
+    MEDIA_FORMAT_PCMU = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_RAW | 0x1530),              /**< media format mime type is PCM U-law, AUDIO */
 
-    MEDIA_FORMAT_PCM = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_RAW | 0x1510),          /**< media format mime type is PCM, AUDIO*/
-    MEDIA_FORMAT_PCMA = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_RAW | 0x1520),          /**< media format mime type is PCM A-law, AUDIO*/
-    MEDIA_FORMAT_PCMU = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_RAW | 0x1530),          /**< media format mime type is PCM U-law, AUDIO */
 
     /* Video */
     MEDIA_FORMAT_H261 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2010),          /**< media format mime type is H261, VIDEO */
     MEDIA_FORMAT_H263 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2020),          /**< media format mime type is H263, VIDEO */
-    MEDIA_FORMAT_H263P = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2021),          /**< media format mime type is H263P, VIDEO */
-    MEDIA_FORMAT_H264_SP = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2030),          /**< media format mime type is H264_SP, VIDEO */
-    MEDIA_FORMAT_H264_MP = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2031),          /**< media format mime type is H264_MP, VIDEO */
-    MEDIA_FORMAT_H264_HP = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2032),          /**< media format mime type is H264_HP, VIDEO */
-    MEDIA_FORMAT_MJPEG = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2040),          /**< media format mime type is MJPEG, VIDEO */
-    MEDIA_FORMAT_MPEG1 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2050),          /**< media format mime type is MPEG1, VIDEO */
-    MEDIA_FORMAT_MPEG2_SP = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2060),          /**< media format mime type is MPEG2_SP, VIDEO */
-    MEDIA_FORMAT_MPEG2_MP = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2061),          /**< media format mime type is MPEG2_MP, VIDEO */
-    MEDIA_FORMAT_MPEG2_HP = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2062),          /**< media format mime type is MPEG2_HP, VIDEO */
-    MEDIA_FORMAT_MPEG4_SP = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2070),          /**< media format mime type is MPEG4_SP, VIDEO */
-    MEDIA_FORMAT_MPEG4_ASP = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2071),          /**< media format mime type is MPEG4_ASP, VIDEO */
-
-    MEDIA_FORMAT_I420 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x2510),          /**< media format mime type is I420, VIDEO */
-    MEDIA_FORMAT_NV12 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x2520),          /**< media format mime type is NV12, VIDEO */
-    MEDIA_FORMAT_NV12T = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x2530),          /**< media format mime type is NV12T, VIDEO */
-    MEDIA_FORMAT_YV12 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x2540),          /**< media format mime type is YV12, VIDEO */
-    MEDIA_FORMAT_NV21 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x2550),          /**< media format mime type is NV21, VIDEO */
-    MEDIA_FORMAT_NV16 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x2560),          /**< media format mime type is NV16, VIDEO */
-    MEDIA_FORMAT_YUYV = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x2570),          /**< media format mime type is YUYV, VIDEO */
-    MEDIA_FORMAT_UYVY = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x2580),          /**< media format mime type is UYVY, VIDEO */
-    MEDIA_FORMAT_422P = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x2590),          /**< media format mime type is 422P, VIDEO */
-    MEDIA_FORMAT_RGB565 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x25a0),          /**< media format mime type is RGB565, VIDEO */
-    MEDIA_FORMAT_RGB888 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x25b0),          /**< media format mime type is RGB888, VIDEO */
-    MEDIA_FORMAT_RGBA = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x25c0),          /**< media format mime type is RGBA, VIDEO */
-    MEDIA_FORMAT_ARGB = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x25d0),          /**< media format mime type is ARGB, VIDEO */
+    MEDIA_FORMAT_H263P = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2021),         /**< media format mime type is H263P, VIDEO */
+    MEDIA_FORMAT_H264_SP = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2030),       /**< media format mime type is H264_SP, VIDEO */
+    MEDIA_FORMAT_H264_MP = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2031),       /**< media format mime type is H264_MP, VIDEO */
+    MEDIA_FORMAT_H264_HP = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2032),       /**< media format mime type is H264_HP, VIDEO */
+    MEDIA_FORMAT_MJPEG = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2040),         /**< media format mime type is MJPEG, VIDEO */
+    MEDIA_FORMAT_MPEG1 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2050),         /**< media format mime type is MPEG1, VIDEO */
+    MEDIA_FORMAT_MPEG2_SP = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2060),      /**< media format mime type is MPEG2_SP, VIDEO */
+    MEDIA_FORMAT_MPEG2_MP = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2061),      /**< media format mime type is MPEG2_MP, VIDEO */
+    MEDIA_FORMAT_MPEG2_HP = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2062),      /**< media format mime type is MPEG2_HP, VIDEO */
+    MEDIA_FORMAT_MPEG4_SP = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2070),      /**< media format mime type is MPEG4_SP, VIDEO */
+    MEDIA_FORMAT_MPEG4_ASP = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2071),     /**< media format mime type is MPEG4_ASP, VIDEO */
+    MEDIA_FORMAT_HEVC = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2080),          /**< media format mime type is HEVC, VIDEO, (Since tizen 2.4) */
+    MEDIA_FORMAT_VP8 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2090),           /**< media format mime type is VP8, VIDEO, (Since tizen 2.4) */
+    MEDIA_FORMAT_VP9 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x20A0),           /**< media format mime type is VP9, VIDEO, (Since tizen 2.4) */
+    MEDIA_FORMAT_VC1 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x20B0),           /**< media format mime type is VC1, VIDEO, (Since tizen 2.4) */
+
+    MEDIA_FORMAT_I420 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x2510),              /**< media format mime type is I420, VIDEO */
+    MEDIA_FORMAT_NV12 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x2520),              /**< media format mime type is NV12, VIDEO */
+    MEDIA_FORMAT_NV12T = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x2530),             /**< media format mime type is NV12T, VIDEO */
+    MEDIA_FORMAT_YV12 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x2540),              /**< media format mime type is YV12, VIDEO */
+    MEDIA_FORMAT_NV21 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x2550),              /**< media format mime type is NV21, VIDEO */
+    MEDIA_FORMAT_NV16 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x2560),              /**< media format mime type is NV16, VIDEO */
+    MEDIA_FORMAT_YUYV = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x2570),              /**< media format mime type is YUYV, VIDEO */
+    MEDIA_FORMAT_UYVY = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x2580),              /**< media format mime type is UYVY, VIDEO */
+    MEDIA_FORMAT_422P = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x2590),              /**< media format mime type is 422P, VIDEO */
+    MEDIA_FORMAT_RGB565 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x25a0),            /**< media format mime type is RGB565, VIDEO */
+    MEDIA_FORMAT_RGB888 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x25b0),            /**< media format mime type is RGB888, VIDEO */
+    MEDIA_FORMAT_RGBA = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x25c0),              /**< media format mime type is RGBA, VIDEO */
+    MEDIA_FORMAT_ARGB = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x25d0),              /**< media format mime type is ARGB, VIDEO */
+
+    /* CONTAINER VIDEO */
+    MEDIA_FORMAT_CONTAINER_MP4 = (MEDIA_FORMAT_CONTAINER | 0x3010),
+    MEDIA_FORMAT_CONTAINER_AVI = (MEDIA_FORMAT_CONTAINER | 0x3020),
+    MEDIA_FORMAT_CONTAINER_MPEG2TS = (MEDIA_FORMAT_CONTAINER | 0x3030),
+    MEDIA_FORMAT_CONTAINER_MPEG2PS = (MEDIA_FORMAT_CONTAINER | 0x3040),
+    MEDIA_FORMAT_CONTAINER_MATROSKA = (MEDIA_FORMAT_CONTAINER | 0x3050),
+    MEDIA_FORMAT_CONTAINER_WEBM = (MEDIA_FORMAT_CONTAINER | 0x3060),
+    MEDIA_FORMAT_CONTAINER_3GP = (MEDIA_FORMAT_CONTAINER | 0x3070),
+
+    /*CONTAINER AUDIO */
+    MEDIA_FORMAT_CONTAINER_WAV = (MEDIA_FORMAT_CONTAINER | 0x4010),
+    MEDIA_FORMAT_CONTAINER_OGG = (MEDIA_FORMAT_CONTAINER | 0x4020),
+    MEDIA_FORMAT_CONTAINER_AAC_ADTS = (MEDIA_FORMAT_CONTAINER | 0x4030),
+
+
+    MEDIA_FORMAT_NATIVE_VIDEO = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x7000),      /**< media format mime type is HW dependent , VIDEO, (Since tizen 2.4) */
 
     MEDIA_FORMAT_MAX          /**< media format mime type is MEDIA_FORMAT_MAX, Do not use */
 } media_format_mimetype_e;
@@ -148,6 +182,9 @@ typedef enum {
  * @details    It creates media format. and reference count will be set to 1
                     For destroying media_format_h handle, use media_format_unref()
  * @param[out] fmt allocated media_format_h
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_FORMAT_ERROR_NONE Successful
  * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_FORMAT_ERROR_OUT_OF_MEMORY Out of memory
@@ -157,6 +194,36 @@ typedef enum {
  */
 int media_format_create(media_format_h* fmt);
 
+/**
+ * @brief Gets format type of media format
+ * @since_tizen mmfw_internal
+ * @details   Gets format type
+ * @param[in] fmt media_format_h to get container mime type
+ * @param[out] formattype media_format_type_e, ex) MEDIA_FORMAT_AUDIO
+ * @retval #MEDIA_FORMAT_ERROR_NONE Successful
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
+ */
+int media_format_get_mime_format_type(media_format_h fmt, media_format_type_e* formattype);
+
+/**
+ * @brief Gets container MIME type of media format
+ * @since_tizen mmfw_internal
+ * @details   Gets MIME type
+ * @param[in] fmt media_format_h to get container mime type
+ * @param[out] mimetype media_format_mimetype_e, ex) MEDIA_FORMAT_MP4
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #MEDIA_FORMAT_ERROR_NONE Successful
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see media_format_set_container_mime()
+ */
+int media_format_get_container_mime(media_format_h fmt, media_format_mimetype_e* mimetype);
+
 /**
  * @brief Gets video information of media format
  * @since_tizen 2.3
@@ -167,6 +234,9 @@ int media_format_create(media_format_h* fmt);
  * @param[out] height height of the video
  * @param[out] avg_bps average bps of the video
  * @param[out] max_bps max bps of the video
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_FORMAT_ERROR_NONE Successful
  * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
@@ -188,6 +258,9 @@ int media_format_get_video_info(media_format_h fmt, media_format_mimetype_e* mim
  * @param[out] samplerate sampling rate of the audio
  * @param[out] bit bit resolution of the audio
  * @param[out] avg_bps average bps of the audio
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_FORMAT_ERROR_NONE Successful
  * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
@@ -199,12 +272,61 @@ int media_format_get_video_info(media_format_h fmt, media_format_mimetype_e* mim
  */
 int media_format_get_audio_info(media_format_h fmt, media_format_mimetype_e* mimetype, int* channel, int* samplerate, int* bit, int* avg_bps);
 
+/**
+ * @brief Gets audio aac type of media format
+ * @since_tizen 2.4
+ * @param[in] fmt media_format_h to get audio information
+ * @param[out] is_adts aac adts flag of the audio
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #MEDIA_FORMAT_ERROR_NONE Successful
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
+ * @see media_format_set_audio_aac_type()
+ */
+int media_format_get_audio_aac_type(media_format_h fmt, bool* is_adts);
+
+/**
+ * @brief Gets video frame_rate of media format
+ * @since_tizen mmfw_internal
+ * @details   Gets frame_rate
+ * @param[in] fmt media_format_h to get
+ * @param[out] frame_rate frame rate of the video
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #MEDIA_FORMAT_ERROR_NONE Successful
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
+ */
+int media_format_get_video_frame_rate(media_format_h fmt, int* frame_rate);
+
+/**
+ * @brief Sets container MIME type of media format
+ * @since_tizen mmfw_internal
+ * @details   Sets container MIME type
+ * @param[in] fmt media_format_h to set
+ * @param[in] mimetype media_format_mimetype_e, ex) MEDIA_FORMAT_MP4
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #MEDIA_FORMAT_ERROR_NONE Successful
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
+ * @see media_format_get_container_mime()
+ */
+int media_format_set_container_mime(media_format_h fmt, media_format_mimetype_e mimetype);
+
 /**
  * @brief Sets video MIME type of media format
  * @since_tizen 2.3
  * @details   Sets MIME type
  * @param[in] fmt media_format_h to set
  * @param[in] mimetype media_format_mimetype_e , ex) MEDIA_FORMAT_H264_HP
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_FORMAT_ERROR_NONE Successful
  * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
@@ -219,6 +341,9 @@ int media_format_set_video_mime(media_format_h fmt, media_format_mimetype_e mime
  * @param[in] fmt media_format_h to set
  * @param[in] width width of the video
  * @pre must set video MIME type by media_format_set_video_mime()
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_FORMAT_ERROR_NONE Successful
  * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
@@ -234,6 +359,9 @@ int media_format_set_video_width(media_format_h fmt, int width);
  * @param[in] fmt media_format_h to set
  * @param[in] height height of the video
  * @pre must set video MIME type by media_format_set_video_mime()
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_FORMAT_ERROR_NONE Successful
  * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
@@ -248,6 +376,9 @@ int media_format_set_video_height(media_format_h fmt, int height);
  * @param[in] fmt media_format_h to set
  * @param[in] avg_bps average bps of the video
  * @pre must set video MIME type by media_format_set_video_mime()
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_FORMAT_ERROR_NONE Successful
  * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
@@ -262,6 +393,9 @@ int media_format_set_video_avg_bps(media_format_h fmt, int avg_bps);
  * @param[in] fmt media_format_h to set
  * @param[in] max_bps max bps of the video
  * @pre must set video MIME type by media_format_set_video_mime()
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_FORMAT_ERROR_NONE Successful
  * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
@@ -269,12 +403,31 @@ int media_format_set_video_avg_bps(media_format_h fmt, int avg_bps);
  */
 int media_format_set_video_max_bps(media_format_h fmt, int max_bps);
 
+/**
+ * @brief Sets video frame_rate of media format
+ * @since_tizen mmfw_internal
+ * @details   Sets frame_rate
+ * @param[in] fmt media_format_h to set
+ * @param[in] frame_rate frame rate of the video
+ * @pre must set video MIME type by media_format_set_video_mime()
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #MEDIA_FORMAT_ERROR_NONE Successful
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
+ */
+int media_format_set_video_frame_rate(media_format_h fmt, int frame_rate);
+
 /**
  * @brief Sets audio MIME type of media format
  * @since_tizen 2.3
  * @details   Sets MIME type
  * @param[in] fmt media_format_h to set audio information
  * @param[in] mimetype media_format_mimetype_e , ex) MEDIA_FORMAT_PCM
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_FORMAT_ERROR_NONE Successful
  * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
@@ -289,6 +442,9 @@ int media_format_set_audio_mime(media_format_h fmt, media_format_mimetype_e mime
  * @param[in] fmt media_format_h to set audio information
  * @param[in] channel channel of the audio
  * @pre must set audio MIME type by media_format_set_audio_mime()
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_FORMAT_ERROR_NONE Successful
  * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
@@ -303,6 +459,9 @@ int media_format_set_audio_channel(media_format_h fmt, int channel);
  * @param[in] fmt media_format_h to set
  * @param[in] samplerate sampling rate of the audio
  * @pre must set audio MIME type by media_format_set_audio_mime()
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_FORMAT_ERROR_NONE Successful
  * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
@@ -317,6 +476,9 @@ int media_format_set_audio_samplerate(media_format_h fmt, int samplerate);
  * @param[in] fmt media_format_h to set
  * @param[in] bit bit of the audio
  * @pre must set audio MIME type by media_format_set_audio_mime()
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_FORMAT_ERROR_NONE Successful
  * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
@@ -331,6 +493,9 @@ int media_format_set_audio_bit(media_format_h fmt, int bit);
  * @param[in] fmt media_format_h to set
  * @param[in] avg_bps avg_bps of the audio
  * @pre must set audio MIME type by media_format_set_audio_mime()
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_FORMAT_ERROR_NONE Successful
  * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
@@ -338,11 +503,31 @@ int media_format_set_audio_bit(media_format_h fmt, int bit);
  */
 int media_format_set_audio_avg_bps(media_format_h fmt, int avg_bps);
 
+ /**
+ * @brief Sets audio aac type of media format
+ * @since_tizen 2.4
+ * @details   Sets audio aac data type of this media format
+ * @param[in] fmt media_format_h to set
+ * @param[in] is_adts aac adts flag of the audio
+ * @pre must set audio MIME type by media_format_set_audio_mime()
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #MEDIA_FORMAT_ERROR_NONE Successful
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
+ * @see media_format_get_audio_aac_type()
+ */
+int media_format_set_audio_aac_type(media_format_h fmt, bool is_adts);
+
 /**
  * @brief Increase reference count of media_format_h object
  * @since_tizen 2.3
  * @details    increase ref_count of media_format_h
  * @param[in] fmt exist media_format_h
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_FORMAT_ERROR_NONE Successful
  * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_FORMAT_ERROR_OUT_OF_MEMORY Out of memory
@@ -356,6 +541,9 @@ int media_format_ref(media_format_h fmt);
  * @since_tizen 2.3
  * @details    decrease ref_count of media_format_h
  * @param[in] fmt exist media_format_h
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_FORMAT_ERROR_NONE Successful
  * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_FORMAT_ERROR_OUT_OF_MEMORY Out of memory
@@ -370,6 +558,9 @@ int media_format_unref(media_format_h fmt);
  * @details    Check the number of media_format's ref_count
  * @param[in] fmt exist media_format_h
  * @param[out] is_writable if ref_count is 1, return true. if not, return false
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_FORMAT_ERROR_NONE Successful
  * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_FORMAT_ERROR_OUT_OF_MEMORY Out of memory
@@ -386,8 +577,11 @@ int media_format_is_writable(media_format_h fmt, bool* is_writable);
  *              The caller will own a reference to the returned object.
  *              In a nutshell, this function unrefs the fmt and refs the out_fmt returned.
  *              Don't access fmt after calling this function.
- * @param[in] fmt exist media_format_h , don't access it after calling this function.
- * @param[out] out_fmt new copied media_format_h, the caller is owner of this object.
+ * @param[in] fmt exist media_format_h , don't access it after calling this function
+ * @param[out] out_fmt new copied media_format_h, the caller is owner of this object
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_FORMAT_ERROR_NONE Successful
  * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_FORMAT_ERROR_OUT_OF_MEMORY Out of memory
old mode 100644 (file)
new mode 100755 (executable)
index 2b6f392..2195d16
@@ -114,6 +114,7 @@ typedef struct _media_format_video_spec_s {
     int height;          /**< media format video height */
     int avg_bps;          /**< media format video average bps */
     int max_bps;          /**< media format video max bps */
+    int frame_rate;          /**< media format video frame rate (@since_tizen mmfw_internal) */
 } media_format_video_spec_s;
 
 /**
@@ -125,6 +126,7 @@ typedef struct _media_fomat_audio_spec_s {
     int samplerate;          /**< media format audio sampling rate */
     int bit;                /**< media format audio's the bit resolution */
     int avg_bps;          /**< media format audio max bps */
+    bool is_adts;          /**< media format audio aac adts flag */
 } media_format_audio_spec_s;
 
 /**
old mode 100644 (file)
new mode 100755 (executable)
index e60a3ae..e0d5f72
@@ -109,23 +109,26 @@ typedef int (*media_packet_finalize_cb)(media_packet_h packet, int error_code, v
  *
  * @since_tizen 2.3
  *
+ * @remarks The @c packet must be released by using media_packet_destroy().
  * @param[in]  fmt       The allocated #media_format_h by caller
  * @param[in]  fcb       The media_packet_finalize_cb() to register
  * @param[in]  fcb_data  The user data to be passed to the media_packet_finalize_cb() function
  * @param[out] packet    A new handle for media packet
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_OUT_OF_MEMORY     Out of memory
  * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
  *
- * @pre must have media_format_h instance by media_format_create()
- * @post must do media_format_unref()
+ * @pre Must have media_format_h instance by media_format_create()
+ * @post Must do media_format_unref()
  *
  * @see media_packet_destroy()
  * @see media_packet_finalize_cb()
  * @see media_format_unref()
 * @par Example
+ * @par Example
    @code
    #include <media_packet.h>
 
@@ -134,12 +137,17 @@ typedef int (*media_packet_finalize_cb)(media_packet_h packet, int error_code, v
    media_packet_h packet;
 
    media_format_create(&fmt);
-   media_format_set_video_info(fmt, MEDIA_FORMAT_H264_HP, 480, 640, 10000000, 15000000);
+   media_format_set_video_mime(fmt, MEDIA_FORMAT_H264_HP);
+   media_format_set_video_width(fmt, 640);
+   media_format_set_video_height(fmt, 480);
+   media_format_set_video_avg_bps(fmt, 10000000);
+   media_format_set_video_max_bps(fmt, 15000000);
 
    media_packet_create_alloc (fmt, _finalize_callback, fcb_data, &packet);
    media_format_unref(fmt);
 
    ...
+   media_packet_destroy(packet);
    }
 
    int _finalize_callback(media_packet_h packet, int err, void* userdata)
@@ -158,23 +166,26 @@ int media_packet_create_alloc(media_format_h fmt, media_packet_finalize_cb fcb,
  *
  * @since_tizen 2.3
  *
+ * @remarks The @c packet must be released by using media_packet_destroy().
  * @param[in] fmt       The allocated #media_format_h by caller
  * @param[in] fcb       The media_packet_finalize_cb() to register
  * @param[in] fcb_data  The user data to be passed to the media_packet_finalize_cb() function
  * @param[out] packet   A new handle for media packet
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_OUT_OF_MEMORY     Out of memory
  * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
  *
- * @pre must have media_format_h instance by media_format_create()
- * @post must do media_format_unref()
+ * @pre Must have media_format_h instance by media_format_create()
+ * @post Must do media_format_unref()
  *
  * @see media_packet_destroy()
  * @see media_packet_finalize_cb()
  * @see media_format_unref()
 * @par Example
+ * @par Example
    @code
    #include <media_packet.h>
 
@@ -183,12 +194,17 @@ int media_packet_create_alloc(media_format_h fmt, media_packet_finalize_cb fcb,
    media_packet_h packet;
 
    media_format_create(&fmt);
-   media_format_set_video_info(fmt, MEDIA_FORMAT_H264_HP, 480, 640, 10000000, 15000000);
+   media_format_set_video_mime(fmt, MEDIA_FORMAT_H264_HP);
+   media_format_set_video_width(fmt, 640);
+   media_format_set_video_height(fmt, 480);
+   media_format_set_video_avg_bps(fmt, 10000000);
+   media_format_set_video_max_bps(fmt, 15000000);
 
    media_packet_create (fmt, _finalize_callback, fcb_data, &packet);
    media_format_unref(fmt);
 
    ...
+   media_packet_destroy(packet);
    }
 
    int _finalize_callback(media_packet_h packet, int err, void* userdata)
@@ -207,11 +223,14 @@ int media_packet_create(media_format_h fmt, media_packet_finalize_cb fcb, void *
  *
  * @since_tizen 2.3
  *
+ * @remarks The @c new_packet must be released by using media_packet_destroy().
  * @param[in]   org_packet   The existing media packet handle
  * @param[in]   fcb          The media_packet_finalize_cb() to register
  * @param[in]   fcb_data     The user data to be passed to the media_packet_finalize_cb() function
  * @param[out]  new_packet   A new handle for media packet
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_OUT_OF_MEMORY     Out of memory
@@ -230,6 +249,8 @@ int media_packet_copy(media_packet_h org_packet, media_packet_finalize_cb fcb, v
  *
  * @param[in] packet   The existing media packet handle
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_OUT_OF_MEMORY     Out of memory
@@ -245,23 +266,27 @@ int media_packet_alloc(media_packet_h packet);
  *
  * @since_tizen 2.3
  *
+ * @remarks The @c packet must be released by using media_packet_destroy().
  * @param[in]   fmt       The allocated #media_format_h by caller
  * @param[in]   surface   The #tbm_surface_h by caller
  * @param[in]   fcb       The media_packet_finalize_cb() to register
  * @param[in]   fcb_data  The user data to be passed to the media_packet_finalize_cb() function
  * @param[out]  packet  A new handle for media packet
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_OUT_OF_MEMORY     Out of memory
  * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
  *
- * @pre must have media_format_h instance by media_format_create()
- * @post must do media_format_unref()
+ * @pre Must have media_format_h instance by media_format_create()
+ * @post Must do media_format_unref()
  *
  * @see media_packet_destroy()
  * @see media_packet_finalize_cb()
  * @see media_format_unref()
 * @par Example
+ * @par Example
    @code
    #include <media_packet.h>
 
@@ -270,12 +295,17 @@ int media_packet_alloc(media_packet_h packet);
    media_packet_h packet;
 
    media_format_create(&fmt);
-   media_format_set_video_info(fmt, MEDIA_FORMAT_RGBA, 128, 128, 2000000, 15000000);
+   media_format_set_video_mime(fmt, MEDIA_FORMAT_H264_HP);
+   media_format_set_video_width(fmt, 640);
+   media_format_set_video_height(fmt, 480);
+   media_format_set_video_avg_bps(fmt, 10000000);
+   media_format_set_video_max_bps(fmt, 15000000);
 
    media_packet_create_from_tbm_surface (fmt, surface, _finalize_callback, fcb_data, &packet);
    media_format_unref(fmt);
 
    ...
+   media_pacekt_destory(packet);
    }
 
    int _finalize_callback(media_packet_h packet, int err, void* userdata)
@@ -288,6 +318,64 @@ int media_packet_alloc(media_packet_h packet);
  */
 int media_packet_create_from_tbm_surface(media_format_h fmt, tbm_surface_h surface, media_packet_finalize_cb fcb, void *fcb_data, media_packet_h *packet);
 
+/**
+ * @brief    Creates media packet handle with already allocated external buffer.
+ * @details It does not support video's #MEDIA_FORMAT_RAW type.
+ *
+ * @since_tizen 2.4
+ *
+ * @remarks The @c packet must be released by using media_packet_destroy().
+ * @param[in]   fmt       The allocated #media_format_h by caller
+ * @param[in]   mem_ptr   The memory pointer which is created by external module
+ * @param[in]   fcb       The media_packet_finalize_cb() to register
+ * @param[in]   fcb_data  The user data to be passed to the media_packet_finalize_cb() function
+ * @param[out]  packet  A new handle for media packet
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #MEDIA_PACKET_ERROR_NONE              Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_OUT_OF_MEMORY     Out of memory
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ *
+ * @pre Must have media_format_h instance by media_format_create()
+ * @post Must do media_format_unref()
+ *
+ * @see media_packet_destroy()
+ * @see media_packet_finalize_cb()
+ * @see media_format_unref()
+ * @par Example
+   @code
+   #include <media_packet.h>
+
+   {
+   media_format_h fmt;
+   media_packet_h packet;
+
+   media_format_create(&fmt);
+   media_format_set_video_mime(fmt, MEDIA_FORMAT_H264_HP);
+   media_format_set_video_width(fmt, 640);
+   media_format_set_video_height(fmt, 480);
+   media_format_set_video_avg_bps(fmt, 10000000);
+   media_format_set_video_max_bps(fmt, 15000000);
+
+   media_packet_create_from_external_memory (fmt, mem_ptr, size,  _finalize_callback, fcb_data, &packet);
+   media_format_unref(fmt);
+
+   ...
+   media_packet_destroy(packet);
+   }
+
+   int _finalize_callback(media_packet_h packet, int err, void* userdata)
+   {
+       ...
+       return MEDIA_PACKET_FINALIZE;
+   }
+
+   @endcode
+ */
+int media_packet_create_from_external_memory(media_format_h fmt, void *mem_ptr, uint64_t size, media_packet_finalize_cb fcb, void *fcb_data, media_packet_h *packet);
+
 /**
  * @brief Gets #media_format_h of media packet
  * @since_tizen 2.3
@@ -295,11 +383,13 @@ int media_packet_create_from_tbm_surface(media_format_h fmt, tbm_surface_h surfa
  * @param[in]  packet   The media packet handle
  * @param[out] fmt      The media format of media packet
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  *
  * @see media_format_unref()
 * @par Example
+ * @par Example
    @code
    #include <media_packet.h>
 
@@ -324,11 +414,13 @@ int media_packet_get_format(media_packet_h packet, media_format_h *fmt);
  * @param[in] packet   The media packet handle
  * @param[in] fmt      The #media_format_h to set
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  *
  * @see media_format_unref()
 * @par Example
+ * @par Example
    @code
    #include <media_packet.h>
 
@@ -353,6 +445,8 @@ int media_packet_set_format(media_packet_h packet, media_format_h fmt);
  * @param[in] packet   The media packet handle
  * @param[in] pts      The PTS value to set
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
@@ -366,6 +460,8 @@ int media_packet_set_pts(media_packet_h packet, uint64_t pts);
  * @param[in]  packet   The media packet handle
  * @param[in]  dts      The DTS value to set
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
@@ -379,6 +475,8 @@ int media_packet_set_dts(media_packet_h packet, uint64_t dts);
  * @param[in] packet    The media packet handle
  * @param[in] duration  The duration value to set
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
@@ -392,6 +490,8 @@ int media_packet_set_duration(media_packet_h packet, uint64_t duration);
  * @param[in]  packet   The media packet handle
  * @param[out] size     The buffer size value to set
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
@@ -405,6 +505,8 @@ int media_packet_set_buffer_size(media_packet_h packet, uint64_t size);
  * @param[in]  packet   The media packet handle
  * @param[out] pts      The PTS value to get
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
@@ -418,6 +520,8 @@ int media_packet_get_pts(media_packet_h packet, uint64_t *pts);
  * @param[in]  packet   The media packet handle
  * @param[out] dts      The DTS value to get
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
@@ -431,6 +535,8 @@ int media_packet_get_dts(media_packet_h packet, uint64_t *dts);
  * @param[in]  packet    The media packet handle
  * @param[out] duration  The duration value to get
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
@@ -444,6 +550,8 @@ int media_packet_get_duration(media_packet_h packet, uint64_t *duration);
  * @param[in]  packet   The media packet handle
  * @param[out] size     The buffer size value to get
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
@@ -457,6 +565,8 @@ int media_packet_get_buffer_size(media_packet_h packet, uint64_t *size);
  * @param[in]  packet   The media packet handle
  * @param[out] data     The allocated buffer data pointer
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
@@ -470,6 +580,8 @@ int media_packet_get_buffer_data_ptr(media_packet_h packet, void **data);
  * @param[in]  packet   The media packet handle
  * @param[out] surface  The tbm_surface data pointer
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
@@ -483,6 +595,8 @@ int media_packet_get_tbm_surface(media_packet_h packet, tbm_surface_h *surface);
  * @param[in] packet   The media packet handle
  * @param[in] extra    The extra data to set
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
@@ -496,6 +610,8 @@ int media_packet_set_extra(media_packet_h packet, void *extra);
  * @param[in]  packet   The media packet handle
  * @param[out] extra    The extra data to get
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
@@ -510,6 +626,8 @@ int media_packet_get_extra(media_packet_h packet, void **extra);
  * @param[out] is_video @c true if the given media packet is for video,
  *                      otherwise @c false if the given media packet is not for video
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
@@ -527,6 +645,8 @@ int media_packet_is_video(media_packet_h packet, bool *is_video);
  * @param[out] is_audio  @c true if the given media packet is for audio,
  *                       otherwise @c false if the given media packet is not for audio
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
@@ -543,6 +663,8 @@ int media_packet_is_audio(media_packet_h packet, bool *is_audio);
  * @param[out] is_encoded  @c true if the given media packet is encoded,
  *                         otherwise @c false if the given media packet is not encoded
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
@@ -560,6 +682,8 @@ int media_packet_is_encoded(media_packet_h packet, bool *is_encoded);
  * @param[out] is_raw   @c true if the given media packet is for raw video,
  *                      otherwise @c false if the given media packet is not for raw video
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
@@ -569,6 +693,24 @@ int media_packet_is_encoded(media_packet_h packet, bool *is_encoded);
  */
 int media_packet_is_raw(media_packet_h packet, bool *is_raw);
 
+/**
+ * @brief Gets #media_buffer_flags_e of media packet.
+ * @since_tizen
+ *
+ * @param[in] packet    The media packet handle
+ * @param[out] flags    The media_buffer_flags_e of media packet to get
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #MEDIA_PACKET_ERROR_NONE              Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ *
+ * @see media_buffer_flags_e
+ * @see media_packet_unset_flags()
+ */
+int media_packet_get_flags(media_packet_h packet, media_buffer_flags_e *flags);
+
 /**
  * @brief Sets #media_buffer_flags_e of media packet.
  * @since_tizen 2.3
@@ -576,6 +718,8 @@ int media_packet_is_raw(media_packet_h packet, bool *is_raw);
  * @param[in] packet    The media packet handle
  * @param[in] flags    The media_buffer_flags_e of media packet to set
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
@@ -592,6 +736,8 @@ int media_packet_set_flags(media_packet_h packet, media_buffer_flags_e flags);
  * @param[in] packet   The media packet handle
  * @param[in] flags    The media_buffer_flags_e of media packet to unset
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
@@ -609,6 +755,8 @@ int media_packet_unset_flags(media_packet_h packet, media_buffer_flags_e flags);
  * @param[out] is_codec_config  @c true if the given media packet is for codec data,
  *                              otherwise @c false if the given media packet is not for codec data
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
@@ -626,6 +774,8 @@ int media_packet_is_codec_config(media_packet_h packet, bool *is_codec_config);
  * @param[out] is_eos  @c true if the given media packet is for eos,
  *                     otherwise @c false if the given media packet is not for eos
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
@@ -643,6 +793,8 @@ int media_packet_is_end_of_stream(media_packet_h packet, bool *is_eos);
  * @param[out] is_sync  @c true if the given media packet is for sync frame,
  *                      otherwise @c false if the given media packet is not for sync frame
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
@@ -660,12 +812,110 @@ int media_packet_is_sync_frame(media_packet_h packet, bool *is_sync);
  * @param[out] has_tbm_surface  @c true if the given media packet's allocated buffer is tbm surface,
  *                      otherwise @c false if the given media packet's allocated buffer is not tbm surface
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
  */
 int media_packet_has_tbm_surface_buffer(media_packet_h packet, bool* has_tbm_surface);
 
+/**
+ * @brief Gets the number of planes from tbm surface in the given media packet.
+ * @details Use only if the media_format_h is #MEDIA_FORMAT_RAW and #MEDIA_FORMAT_VIDEO.
+ *          It means that media_packet_h's buffer is allocated on tbm_surface.
+ *          If not sure of that, use media_packet_is_video() and media_packet_is_raw() or media_packet_has_tbm_surface_buffer().
+ *
+ * @since_tizen 2.4
+ *
+ * @param[in]  packet   The media packet handle
+ * @param[out] num  The number of planes from tbm_surface
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #MEDIA_PACKET_ERROR_NONE              Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ */
+int media_packet_get_number_of_video_planes(media_packet_h packet, uint32_t* num);
+
+/**
+ * @brief Gets stride width from tbm surface in the given media packet.
+ * @details Use only if the media_format_h is #MEDIA_FORMAT_RAW and #MEDIA_FORMAT_VIDEO.
+ *          It means that media_packet_h's buffer is allocated on tbm_surface.
+ *          If not sure of that, use media_packet_is_video() and media_packet_is_raw() or media_packet_has_tbm_surface_buffer().
+ *
+ * @since_tizen 2.4
+ *
+ * @param[in]  packet   The media packet handle
+ * @param[in]  plane_idx   The plane index value
+ * @param[out] stride_w  the stride value from tbm_surface
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #MEDIA_PACKET_ERROR_NONE              Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ */
+int media_packet_get_video_stride_width(media_packet_h packet, int plane_idx, int *stride_width);
+
+/**
+ * @brief Gets stride height from tbm surface in the given media packet.
+ * @details Use only if the media_format_h is #MEDIA_FORMAT_RAW and #MEDIA_FORMAT_VIDEO.
+ *          It means that media_packet_h's buffer is allocated on tbm_surface.
+ *          If not sure of that, use media_packet_is_video() and media_packet_is_raw() or media_packet_has_tbm_surface_buffer().
+ *
+ * @since_tizen 2.4
+ *
+ * @param[in]  packet   The media packet handle
+ * @param[in]  plane_idx   The plane index value
+ * @param[out] stride_h  The stride height value from tbm_surface
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #MEDIA_PACKET_ERROR_NONE              Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ */
+int media_packet_get_video_stride_height(media_packet_h packet, int plane_idx, int *stride_height);
+
+/**
+ * @brief Gets plane data pointer from tbm surface in the given media packet.
+ * @details Use only if the media_format_h is #MEDIA_FORMAT_RAW and #MEDIA_FORMAT_VIDEO.
+ *          It means that media_packet_h's buffer is allocated on tbm_surface.
+ *          If not sure of that, use media_packet_is_video() and media_packet_is_raw() or media_packet_has_tbm_surface_buffer().
+ *
+ * @since_tizen 2.4
+ *
+ * @remarks The @c plane_data_ptr must not be released by using free(). Note that It is released by media_packet_destory() or tbm_surface_destroy().
+ * @param[in]  packet   The media packet handle
+ * @param[in]  plane_idx   The plane index value
+ * @param[out] plane_data_ptr  The plane data pointer from tbm_surface
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #MEDIA_PACKET_ERROR_NONE              Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ */
+int media_packet_get_video_plane_data_ptr(media_packet_h packet, int plane_idx, void **plane_data_ptr);
+
+/**
+ * @brief Gets codec data and the codec data size of media packet.
+ * @since_tizen 2.4
+ *
+ * @param[in] packet   The media packet handle
+ * @param[out] codec_data    The codec data to get
+ * @param[out] codec_data_size    The codec data size to get
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #MEDIA_PACKET_ERROR_NONE              Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ */
+int media_packet_get_codec_data(media_packet_h packet, void** codec_data, unsigned int* codec_data_size);
+
 /**
  * @brief Destroys the media packet handle.
  * @details  The registered finalize_callback() function will be invoked to destroy the media packet handle.
@@ -673,6 +923,8 @@ int media_packet_has_tbm_surface_buffer(media_packet_h packet, bool* has_tbm_sur
  *
  * @param[in] packet  The handle to media packet to be destroyed
  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  * @retval #MEDIA_PACKET_ERROR_NONE              Successful
  * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
@@ -681,6 +933,7 @@ int media_packet_has_tbm_surface_buffer(media_packet_h packet, bool* has_tbm_sur
  * @see media_packet_create()
  * @see media_packet_copy()
  * @see media_packet_create_from_tbm_surface()
+ * @see media_packet_create_from_external_memory()
  */
 int media_packet_destroy(media_packet_h packet);
 
diff --git a/include/media_packet_internal.h b/include/media_packet_internal.h
new file mode 100755 (executable)
index 0000000..65ab7e6
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#ifndef __TIZEN_MEDIA_PACKET_INTERNAL_H__
+#define __TIZEN_MEDIA_PACKET_INTERNAL_H__
+
+#include <media_packet.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file media_packet_internal.h
+ * @brief This file contains the capi media tool internal API.
+ */
+
+/**
+ * @addtogroup CAPI_MEDIA_TOOL_MODULE
+ * @{
+ */
+
+
+/**
+ * @internal
+ * @brief Sets codec data and the codec data size of media packet.
+ * @since_tizen 2.4
+ *
+ * @param[in] packet   The media packet handle
+ * @param[in] codec_data    The codec data to set
+ * @param[in] codec_data_size    The codec data size to set
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #MEDIA_PACKET_ERROR_NONE              Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ */
+int media_packet_set_codec_data(media_packet_h packet, void* codec_data, unsigned int codec_data_size);
+
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_MEDIA_PACKET_INTERNAL_H__ */
old mode 100644 (file)
new mode 100755 (executable)
index 1db941d..332a571
@@ -105,6 +105,7 @@ typedef enum {
     MEDIA_BUFFER_TYPE_EXTERNAL_TBM_SURFACE,
     MEDIA_BUFFER_TYPE_NORMAL,
     MEDIA_BUFFER_TYPE_AUTO,
+    MEDIA_BUFFER_TYPE_EXTERNAL_MEMORY,
     MEDIA_BUFFER_TYPE_MAX
 } media_buffer_type_e;
 
@@ -119,7 +120,9 @@ typedef struct _media_packet_s{
     media_packet_finalize_cb finalizecb_func;
     void* userdata;
     bool is_allocated;
-    void *extradata;
+    void* extradata;
+    void* codec_data;
+    unsigned int codec_data_size;
 
     media_format_s* format;
     media_buffer_type_e type;
old mode 100644 (file)
new mode 100755 (executable)
index 05e39f9..dd3df5b
@@ -1,7 +1,7 @@
 Name:       capi-media-tool
 Summary:    A Core API media tool library in Tizen Native API
 Version:    0.1.1
-Release:    1
+Release:    2
 Group:      Multimedia/API
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
old mode 100644 (file)
new mode 100755 (executable)
index 7586c08..ad92343
@@ -43,6 +43,8 @@ int media_format_create(media_format_h* fmt)
 
     *fmt = (media_format_h)fmt_handle;
 
+    LOGI("The new format handle: %p \n", *fmt);
+
     return ret;
 }
 
@@ -54,6 +56,54 @@ static void _media_format_destroy(media_format_s* fmt)
     fmt = NULL;
 }
 
+int media_format_get_mime_format_type(media_format_h fmt, media_format_type_e* formattype)
+{
+    int ret = MEDIA_FORMAT_ERROR_NONE;
+    MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+
+    media_format_s* fmt_handle;
+    fmt_handle = (media_format_s*)fmt;
+
+    if (!formattype)
+        return MEDIA_FORMAT_ERROR_INVALID_PARAMETER;
+
+    if (fmt_handle->mimetype & MEDIA_FORMAT_AUDIO)
+        *formattype = MEDIA_FORMAT_AUDIO;
+    else if (fmt_handle->mimetype & MEDIA_FORMAT_VIDEO)
+        *formattype = MEDIA_FORMAT_VIDEO;
+    else if (fmt_handle->mimetype & MEDIA_FORMAT_CONTAINER)
+        *formattype = MEDIA_FORMAT_CONTAINER;
+    else if (fmt_handle->mimetype & MEDIA_FORMAT_TEXT)
+        *formattype = MEDIA_FORMAT_TEXT;
+    else
+    {
+        LOGE("The format handle is not for AUDIO / VIDEO / CONTAINER / TEXT..\n");
+        return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
+    }
+
+    return ret;
+}
+
+int media_format_get_container_mime(media_format_h fmt, media_format_mimetype_e* mimetype)
+{
+    int ret = MEDIA_FORMAT_ERROR_NONE;
+    MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+
+    media_format_s* fmt_handle;
+    fmt_handle = (media_format_s*)fmt;
+
+    if (!(fmt_handle->mimetype & MEDIA_FORMAT_CONTAINER))
+    {
+        LOGE("The format handle is not for MEDIA_FORMAT_CONTAINER..\n");
+        return MEDIA_FORMAT_ERROR_INVALID_PARAMETER;
+    }
+
+    if (mimetype)
+        *mimetype = fmt_handle->mimetype;
+
+    return ret;
+}
+
 int media_format_get_video_info(media_format_h fmt, media_format_mimetype_e* mimetype, int* width, int* height, int* avg_bps, int* max_bps)
 {
     int ret = MEDIA_FORMAT_ERROR_NONE;
@@ -64,6 +114,7 @@ int media_format_get_video_info(media_format_h fmt, media_format_mimetype_e* mim
 
     if (!(fmt_handle->mimetype & MEDIA_FORMAT_VIDEO))
     {
+        LOGE("The format handle is not for MEDIA_FORMAT_VIDEO..\n");
         return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
     }
 
@@ -91,14 +142,83 @@ int media_format_get_audio_info(media_format_h fmt, media_format_mimetype_e* mim
 
     if (!(fmt_handle->mimetype & MEDIA_FORMAT_AUDIO))
     {
+        LOGE("The format handle is not for MEDIA_FORMAT_AUDIO..\n");
+        return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
+    }
+    if (mimetype)
+        *mimetype = fmt_handle->mimetype;
+    if (channel)
+        *channel = fmt_handle->detail.audio.channel;
+    if (samplerate)
+        *samplerate = fmt_handle->detail.audio.samplerate;
+    if (bit)
+        *bit = fmt_handle->detail.audio.bit;
+    if (avg_bps)
+        *avg_bps = fmt_handle->detail.audio.avg_bps;
+
+    return ret;
+}
+
+int media_format_get_audio_aac_type(media_format_h fmt, bool* is_adts)
+{
+    int ret = MEDIA_FORMAT_ERROR_NONE;
+    MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+
+    media_format_s* fmt_handle;
+    fmt_handle = (media_format_s*)fmt;
+
+    if (!(fmt_handle->mimetype == MEDIA_FORMAT_AAC_LC || fmt_handle->mimetype == MEDIA_FORMAT_AAC_HE || fmt_handle->mimetype == MEDIA_FORMAT_AAC_HE_PS))
+    {
+        LOGE("The format handle is not aac format..\n");
+        return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
+    }
+
+    if (is_adts)
+        *is_adts = fmt_handle->detail.audio.is_adts;
+
+    return ret;
+}
+
+int media_format_get_video_frame_rate(media_format_h fmt, int* frame_rate)
+{
+    int ret = MEDIA_FORMAT_ERROR_NONE;
+    MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+
+    media_format_s* fmt_handle;
+    fmt_handle = (media_format_s*)fmt;
+
+    if (!(fmt_handle->mimetype & MEDIA_FORMAT_VIDEO))
+    {
+        LOGE("The format handle is not for MEDIA_FORMAT_VIDEO..\n");
+        return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
+    }
+
+    if (frame_rate)
+        *frame_rate = fmt_handle->detail.video.frame_rate;
+
+    return ret;
+}
+
+int media_format_set_container_mime(media_format_h fmt, media_format_mimetype_e mimetype)
+{
+    int ret = MEDIA_FORMAT_ERROR_NONE;
+    MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+
+    if (!MEDIA_FORMAT_IS_WRITABLE(fmt))
+    {
+        LOGE("The format can not be changed..\n", __FUNCTION__);
         return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
     }
 
-    *mimetype = fmt_handle->mimetype;
-    *channel = fmt_handle->detail.audio.channel;
-    *samplerate = fmt_handle->detail.audio.samplerate;
-    *bit = fmt_handle->detail.audio.bit;
-    *avg_bps = fmt_handle->detail.audio.avg_bps;
+    media_format_s* fmt_handle;
+    fmt_handle = (media_format_s*)fmt;
+
+    if (!(mimetype & MEDIA_FORMAT_CONTAINER))
+    {
+        return MEDIA_FORMAT_ERROR_INVALID_PARAMETER;
+    }
+
+    fmt_handle->mimetype = mimetype;
 
     return ret;
 }
@@ -110,7 +230,7 @@ int media_format_set_video_mime(media_format_h fmt, media_format_mimetype_e mime
 
     if (!MEDIA_FORMAT_IS_WRITABLE(fmt))
     {
-        LOGE("the format can not be changed..", __FUNCTION__);
+        LOGE("The format can not be changed..\n", __FUNCTION__);
         return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
     }
 
@@ -134,7 +254,7 @@ int media_format_set_video_width(media_format_h fmt, int width)
 
     if (!MEDIA_FORMAT_IS_WRITABLE(fmt))
     {
-        LOGE("the format can not be changed..", __FUNCTION__);
+        LOGE("the format can not be changed..\n", __FUNCTION__);
         return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
     }
 
@@ -143,6 +263,7 @@ int media_format_set_video_width(media_format_h fmt, int width)
 
     if (!(fmt_handle->mimetype & MEDIA_FORMAT_VIDEO))
     {
+        LOGE("The format handle is not for MEDIA_FORMAT_VIDEO..\n");
         return MEDIA_FORMAT_ERROR_INVALID_PARAMETER;
     }
 
@@ -158,7 +279,7 @@ int media_format_set_video_height(media_format_h fmt, int height)
 
     if (!MEDIA_FORMAT_IS_WRITABLE(fmt))
     {
-        LOGE("the format can not be changed..", __FUNCTION__);
+        LOGE("The format can not be changed..\n", __FUNCTION__);
         return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
     }
 
@@ -167,6 +288,7 @@ int media_format_set_video_height(media_format_h fmt, int height)
 
     if (!(fmt_handle->mimetype & MEDIA_FORMAT_VIDEO))
     {
+        LOGE("The format handle is not for MEDIA_FORMAT_VIDEO..\n");
         return MEDIA_FORMAT_ERROR_INVALID_PARAMETER;
     }
 
@@ -182,7 +304,7 @@ int media_format_set_video_avg_bps(media_format_h fmt, int avg_bps)
 
     if (!MEDIA_FORMAT_IS_WRITABLE(fmt))
     {
-        LOGE("the format can not be changed..", __FUNCTION__);
+        LOGE("The format can not be changed..\n", __FUNCTION__);
         return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
     }
 
@@ -191,6 +313,7 @@ int media_format_set_video_avg_bps(media_format_h fmt, int avg_bps)
 
     if (!(fmt_handle->mimetype & MEDIA_FORMAT_VIDEO))
     {
+        LOGE("The format handle is not for MEDIA_FORMAT_VIDEO..\n");
         return MEDIA_FORMAT_ERROR_INVALID_PARAMETER;
     }
 
@@ -206,7 +329,7 @@ int media_format_set_video_max_bps(media_format_h fmt, int max_bps)
 
     if (!MEDIA_FORMAT_IS_WRITABLE(fmt))
     {
-        LOGE("the format can not be changed..", __FUNCTION__);
+        LOGE("The format can not be changed..\n", __FUNCTION__);
         return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
     }
 
@@ -215,6 +338,7 @@ int media_format_set_video_max_bps(media_format_h fmt, int max_bps)
 
     if (!(fmt_handle->mimetype & MEDIA_FORMAT_VIDEO))
     {
+        LOGE("The format handle is not for MEDIA_FORMAT_VIDEO..\n");
         return MEDIA_FORMAT_ERROR_INVALID_PARAMETER;
     }
 
@@ -223,6 +347,30 @@ int media_format_set_video_max_bps(media_format_h fmt, int max_bps)
     return ret;
 }
 
+int media_format_set_video_frame_rate(media_format_h fmt, int frame_rate)
+{
+    int ret = MEDIA_FORMAT_ERROR_NONE;
+    MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+
+    if (!MEDIA_FORMAT_IS_WRITABLE(fmt))
+    {
+        LOGE("The format can not be changed..\n", __FUNCTION__);
+        return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
+    }
+
+    media_format_s* fmt_handle;
+    fmt_handle = (media_format_s*)fmt;
+
+    if (!(fmt_handle->mimetype & MEDIA_FORMAT_VIDEO))
+    {
+        LOGE("The format handle is not for MEDIA_FORMAT_VIDEO..\n");
+        return MEDIA_FORMAT_ERROR_INVALID_PARAMETER;
+    }
+
+    fmt_handle->detail.video.frame_rate = frame_rate;
+
+    return ret;
+}
 
 int media_format_set_audio_mime(media_format_h fmt, media_format_mimetype_e mimetype)
 {
@@ -232,7 +380,7 @@ int media_format_set_audio_mime(media_format_h fmt, media_format_mimetype_e mime
 
     if (!MEDIA_FORMAT_IS_WRITABLE(fmt))
     {
-        LOGE("the format can not be changed..", __FUNCTION__);
+        LOGE("the format can not be changed..\n", __FUNCTION__);
         return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
     }
 
@@ -241,6 +389,7 @@ int media_format_set_audio_mime(media_format_h fmt, media_format_mimetype_e mime
 
     if (!(mimetype & MEDIA_FORMAT_AUDIO))
     {
+        LOGE("The format handle is not for MEDIA_FORMAT_AUDIO..\n");
         return MEDIA_FORMAT_ERROR_INVALID_PARAMETER;
     }
 
@@ -257,7 +406,7 @@ int media_format_set_audio_channel(media_format_h fmt, int channel)
 
     if (!MEDIA_FORMAT_IS_WRITABLE(fmt))
     {
-        LOGE("the format can not be changed..", __FUNCTION__);
+        LOGE("the format can not be changed..\n", __FUNCTION__);
         return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
     }
 
@@ -266,6 +415,7 @@ int media_format_set_audio_channel(media_format_h fmt, int channel)
 
     if (!(fmt_handle->mimetype & MEDIA_FORMAT_AUDIO))
     {
+        LOGE("The format handle is not for MEDIA_FORMAT_AUDIO..\n");
         return MEDIA_FORMAT_ERROR_INVALID_PARAMETER;
     }
 
@@ -282,7 +432,7 @@ int media_format_set_audio_samplerate(media_format_h fmt, int samplerate)
 
     if (!MEDIA_FORMAT_IS_WRITABLE(fmt))
     {
-        LOGE("the format can not be changed..", __FUNCTION__);
+        LOGE("the format can not be changed..\n", __FUNCTION__);
         return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
     }
 
@@ -291,6 +441,7 @@ int media_format_set_audio_samplerate(media_format_h fmt, int samplerate)
 
     if (!(fmt_handle->mimetype & MEDIA_FORMAT_AUDIO))
     {
+        LOGE("The format handle is not for MEDIA_FORMAT_AUDIO..\n");
         return MEDIA_FORMAT_ERROR_INVALID_PARAMETER;
     }
 
@@ -307,7 +458,7 @@ int media_format_set_audio_bit(media_format_h fmt, int bit)
 
     if (!MEDIA_FORMAT_IS_WRITABLE(fmt))
     {
-        LOGE("the format can not be changed..", __FUNCTION__);
+        LOGE("the format can not be changed..\n", __FUNCTION__);
         return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
     }
 
@@ -316,6 +467,7 @@ int media_format_set_audio_bit(media_format_h fmt, int bit)
 
     if (!(fmt_handle->mimetype & MEDIA_FORMAT_AUDIO))
     {
+        LOGE("The format handle is not for MEDIA_FORMAT_AUDIO..\n");
         return MEDIA_FORMAT_ERROR_INVALID_PARAMETER;
     }
 
@@ -332,7 +484,7 @@ int media_format_set_audio_avg_bps(media_format_h fmt, int avg_bps)
 
     if (!MEDIA_FORMAT_IS_WRITABLE(fmt))
     {
-        LOGE("the format can not be changed..", __FUNCTION__);
+        LOGE("the format can not be changed..\n", __FUNCTION__);
         return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
     }
 
@@ -341,6 +493,7 @@ int media_format_set_audio_avg_bps(media_format_h fmt, int avg_bps)
 
     if (!(fmt_handle->mimetype & MEDIA_FORMAT_AUDIO))
     {
+        LOGE("The format handle is not for MEDIA_FORMAT_AUDIO..\n");
         return MEDIA_FORMAT_ERROR_INVALID_PARAMETER;
     }
 
@@ -349,6 +502,32 @@ int media_format_set_audio_avg_bps(media_format_h fmt, int avg_bps)
     return ret;
 }
 
+int media_format_set_audio_aac_type(media_format_h fmt, bool is_adts)
+{
+
+    int ret = MEDIA_FORMAT_ERROR_NONE;
+    MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+
+    if (!MEDIA_FORMAT_IS_WRITABLE(fmt))
+    {
+        LOGE("the format can not be changed..\n", __FUNCTION__);
+        return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
+    }
+
+    media_format_s* fmt_handle;
+    fmt_handle = (media_format_s*)fmt;
+
+    if (!(fmt_handle->mimetype & MEDIA_FORMAT_AUDIO))
+    {
+        LOGE("The format handle is not for MEDIA_FORMAT_AUDIO..\n");
+        return MEDIA_FORMAT_ERROR_INVALID_PARAMETER;
+    }
+
+    fmt_handle->detail.audio.is_adts = is_adts;
+
+    return ret;
+}
+
 int media_format_ref(media_format_h fmt)
 {
     int ret = MEDIA_FORMAT_ERROR_NONE;
@@ -377,11 +556,15 @@ int media_format_unref(media_format_h fmt)
     fmt_handle = (media_format_s*)fmt;
 
     if (MEDIA_FORMAT_GET_REFCOUNT(fmt) <= 0)
+    {
+        LOGE("The format ref_count is less than 0..\n");
         return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
+    }
 
     is_zero = g_atomic_int_dec_and_test(&fmt_handle->ref_count);
     if (is_zero)
     {
+        LOGI("The format handle(%p) will be destroyed..\n", fmt);
         /* if reference count become 0 , free fmt. */
         _media_format_destroy(fmt_handle);
     }
@@ -393,15 +576,15 @@ int media_format_is_writable(media_format_h fmt, bool* is_writable)
 {
     int ret = MEDIA_FORMAT_ERROR_NONE;
     MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+    if (MEDIA_FORMAT_GET_REFCOUNT(fmt) <= 0)
+    {
+        LOGE("The format ref_count is less than 0..\n.");
+        ret = MEDIA_FORMAT_ERROR_INVALID_OPERATION;
+    }
 
     media_format_s* fmt_handle;
     fmt_handle = (media_format_s*)fmt;
 
-    if (g_atomic_int_get(&fmt_handle->ref_count) <= 0)
-    {
-        return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
-    }
-
     if (g_atomic_int_get(&fmt_handle->ref_count) == 1)
     {
         /* if reference count is 1, the caller must be owner. */
@@ -453,6 +636,7 @@ int media_format_make_writable(media_format_h fmt, media_format_h* out_fmt)
         }
 
         *out_fmt = (media_format_h)copy;
+        LOGI("the copied new format handle: %p\n", *out_fmt);
 
     }
 
old mode 100644 (file)
new mode 100755 (executable)
index f33da2a..29bcf50
@@ -31,15 +31,28 @@ static int _pkt_alloc_buffer(media_packet_s* pkt);
 static uint64_t _pkt_calculate_video_buffer_size(media_packet_s* pkt);
 static uint64_t _pkt_calculate_audio_buffer_size(media_packet_s* pkt);
 static uint32_t _convert_to_tbm_surface_format(media_format_mimetype_e format_type);
+static void* _aligned_malloc_normal_buffer_type (uint64_t size, int alignment);
+static void _aligned_free_normal_buffer_type (void* buffer_ptr);
+
 
 int media_packet_create_alloc(media_format_h fmt, media_packet_finalize_cb fcb, void *fcb_data, media_packet_h *packet)
 {
-    media_packet_s* handle;
+    media_packet_s* handle = NULL;
     int ret = MEDIA_PACKET_ERROR_NONE;
 
     MEDIA_PACKET_INSTANCE_CHECK(fmt);
     MEDIA_PACKET_NULL_ARG_CHECK(packet);
-    /* TODO : need more validation on fmt */
+    if (MEDIA_FORMAT_GET_REFCOUNT(fmt) < 1)
+    {
+        LOGE("The media format handle is corrupted or Not set media info");
+        return MEDIA_PACKET_ERROR_INVALID_PARAMETER;
+    }
+
+    if (!MEDIA_FORMAT_IS_VIDEO(fmt) && !MEDIA_FORMAT_IS_AUDIO(fmt))
+    {
+        LOGE("The media format handle is not specified. set video info or audio info...");
+        return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+    }
 
     handle = (media_packet_s*)malloc(sizeof(media_packet_s));
     if (handle != NULL)
@@ -47,7 +60,8 @@ int media_packet_create_alloc(media_format_h fmt, media_packet_finalize_cb fcb,
     else
     {
         LOGE("[%s] MEDIA_PACKET_ERROR_OUT_OF_MEMORY(0x%08x)" ,__FUNCTION__, MEDIA_PACKET_ERROR_OUT_OF_MEMORY);
-        return MEDIA_PACKET_ERROR_OUT_OF_MEMORY;
+        ret = MEDIA_PACKET_ERROR_OUT_OF_MEMORY;
+        goto fail;
     }
 
     /* TODO : need to consider to give application to select buffer type(tbm or heap) */
@@ -71,7 +85,7 @@ int media_packet_create_alloc(media_format_h fmt, media_packet_finalize_cb fcb,
     int err = _pkt_alloc_buffer(handle);
     if (err != MEDIA_PACKET_ERROR_NONE)
     {
-        LOGE("[%s] MEDIA_PACKET_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_PACKET_ERROR_OUT_OF_MEMORY);
+        LOGE("[%s] failed _pkt_alloc_buffer(), err = (0x%08x)", __FUNCTION__, err);
         ret = err;
         goto fail;
     }
@@ -105,11 +119,22 @@ fail:
 
 int media_packet_create(media_format_h fmt, media_packet_finalize_cb fcb, void *fcb_data, media_packet_h *packet)
 {
-    media_packet_s* handle;
+    media_packet_s* handle = NULL;
     int ret = MEDIA_PACKET_ERROR_NONE;
 
     MEDIA_PACKET_INSTANCE_CHECK(fmt);
     MEDIA_PACKET_NULL_ARG_CHECK(packet);
+    if (MEDIA_FORMAT_GET_REFCOUNT(fmt) < 1)
+    {
+        LOGE("The media format handle is corrupted or Not set media info");
+        return MEDIA_PACKET_ERROR_INVALID_PARAMETER;
+    }
+
+    if (!MEDIA_FORMAT_IS_VIDEO(fmt) && !MEDIA_FORMAT_IS_AUDIO(fmt))
+    {
+        LOGE("The media format handle is not specified. set video info or audio info...");
+        return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+    }
     /* TODO : need more validation on fmt */
 
     handle = (media_packet_s*)malloc(sizeof(media_packet_s));
@@ -260,7 +285,8 @@ int _pkt_alloc_buffer(media_packet_s* pkt)
         if (MEDIA_FORMAT_IS_VIDEO(pkt->format))
         {
             buffersize = _pkt_calculate_video_buffer_size(pkt);
-            pkt->data = (void*)malloc(buffersize);
+            // 16bytes aligned malloc
+            pkt->data = _aligned_malloc_normal_buffer_type(buffersize, 16);
             if (!pkt->data)
             {
                 return MEDIA_PACKET_ERROR_OUT_OF_MEMORY;
@@ -331,9 +357,11 @@ int _pkt_alloc_buffer(media_packet_s* pkt)
             {
                 pkt->data = surface_info.planes[0].ptr;
                 pkt->size = (uint64_t)surface_info.size;
+                LOGD("tbm_surface_created, pkt->size = %llu\n", pkt->size);
             }
             else
             {
+                LOGE("tbm_surface_get_info() is failed.. err = 0x%08x \n", err);
                 tbm_surface_destroy((tbm_surface_h)pkt->surface_data);
                 return MEDIA_PACKET_ERROR_INVALID_OPERATION;
             }
@@ -349,15 +377,14 @@ int _pkt_alloc_buffer(media_packet_s* pkt)
 }
 
 /* TODO : contact Kim Young Hun to make below api as a common */
-static uint64_t _pkt_calculate_video_buffer_size(media_packet_s* pkt)
-{
 /* TODO : rename below macro or make it able to use original from mm_transform */
-#define _ROUND_UP_4(num) (((num)+3)&~3)
+#define _ROUND_UP_16(num) (((num)+15)&~15)
 #define _GEN_MASK(x) ((1<<(x))-1)
 #define _ROUND_UP_X(v,x) (((v) + _GEN_MASK(x)) & ~_GEN_MASK(x))
 #define _DIV_ROUND_UP_X(v,x) (((v) + _GEN_MASK(x)) >> (x))
 #define MAX(a, b)  (((a) > (b)) ? (a) : (b))
-
+static uint64_t _pkt_calculate_video_buffer_size(media_packet_s* pkt)
+{
     unsigned char x_chroma_shift = 0;
     unsigned char y_chroma_shift = 0;
     int size, w2, h2, size2;
@@ -376,45 +403,40 @@ static uint64_t _pkt_calculate_video_buffer_size(media_packet_s* pkt)
     {
 
         case MEDIA_FORMAT_I420:
-        //case MM_UTIL_IMG_FMT_YUV420:
             x_chroma_shift = 1;
             y_chroma_shift = 1;
-            stride = _ROUND_UP_4 (width);
+            stride = _ROUND_UP_16 (width);
             h2 = _ROUND_UP_X (height, x_chroma_shift);
             size = stride * h2;
             w2 = _DIV_ROUND_UP_X (width, x_chroma_shift);
-            stride2 = _ROUND_UP_4 (w2);
+            stride2 = _ROUND_UP_16 (w2);
             h2 = _DIV_ROUND_UP_X (height, y_chroma_shift);
             size2 = stride2 * h2;
             buffersize = size + 2 * size2;
             break;
 
-        //case MM_UTIL_IMG_FMT_YUV422:
         case MEDIA_FORMAT_YUYV:
         case MEDIA_FORMAT_UYVY:
         case MEDIA_FORMAT_NV16:
-        //case MM_UTIL_IMG_FMT_NV61:
-            stride = _ROUND_UP_4 (width * 2);
+            stride = _ROUND_UP_16 (width * 2);
             size = stride * height;
             buffersize = size;
             break;
 
         case MEDIA_FORMAT_RGB565:
-            stride = _ROUND_UP_4 (width * 2);
+            stride = _ROUND_UP_16 (width * 2);
             size = stride * height;
             buffersize = size;
             break;
 
         case MEDIA_FORMAT_RGB888:
-            stride = _ROUND_UP_4 (width * 3);
+            stride = _ROUND_UP_16 (width * 3);
             size = stride * height;
             buffersize = size;
             break;
 
         case MEDIA_FORMAT_ARGB:
-        //case MM_UTIL_IMG_FMT_BGRA8888:
         case MEDIA_FORMAT_RGBA:
-        //case MM_UTIL_IMG_FMT_BGRX8888:
             stride = width * 4;
             size = stride * height;
             buffersize = size;
@@ -437,11 +459,11 @@ static uint64_t _pkt_calculate_video_buffer_size(media_packet_s* pkt)
         case MEDIA_FORMAT_MPEG4_ASP:
             x_chroma_shift = 1;
             y_chroma_shift = 1;
-            stride = _ROUND_UP_4 (width);
+            stride = _ROUND_UP_16 (width);
             h2 = _ROUND_UP_X (height, y_chroma_shift);
             size = stride * h2;
             w2 = 2 * _DIV_ROUND_UP_X (width, x_chroma_shift);
-            stride2 = _ROUND_UP_4 (w2);
+            stride2 = _ROUND_UP_16 (w2);
             h2 = _DIV_ROUND_UP_X (height, y_chroma_shift);
             size2 = stride2 * h2;
             buffersize = size + size2;
@@ -457,13 +479,22 @@ static uint64_t _pkt_calculate_video_buffer_size(media_packet_s* pkt)
 }
 
 /* TODO : written by joungkook seo for audio */
-static uint64_t _pkt_calculate_audio_buffer_size(media_packet_s* pkt)
-{
 /* TODO : rename below macro or make it able to use original from mm_transform */
-#define PCM_MIN_FRM_SIZE         (1024)
-#define AAC_MIN_FRM_SIZE         (1024)
-#define AAC_MIN_NCH                    (2)
+#define PCM_MAX_FRM_SIZE        (2048)
+#define PCM_MIN_FRM_SIZE          (1024)
+#define AAC_MAX_SAMPLE_SIZE   (1024)
+#define MP3_MAX_SAMPLE_SIZE   (1152)
+#define AMR_MAX_SAMPLE_SIZE    (320)       /* AMR-NB(160), WB (320) */
+#define OGG_MAX_SAMPLE_SIZE   (2048)
+
+#define MPEG_MAX_FRM_SIZE      (6144/4)      /* 1536 */
+#define AMR_MAX_FRM_SIZE             (96)       /* AMR-NB(32), WB (96) */
+#define OGG_MAX_FRM_SIZE   (2048)
 
+#define MPEG_MIN_NCH                  (2)
+
+static uint64_t _pkt_calculate_audio_buffer_size(media_packet_s* pkt)
+{
     int channel = 0;
     int bit = 0;
     uint64_t buffersize = 0;
@@ -473,14 +504,22 @@ static uint64_t _pkt_calculate_audio_buffer_size(media_packet_s* pkt)
         bit = pkt->format->detail.audio.bit;
     }
 
-    /* TODO : need to check type mapping again with mm_transform */
     switch (pkt->format->mimetype)
     {
         case MEDIA_FORMAT_PCM:
-            buffersize = (PCM_MIN_FRM_SIZE * channel) * (uint64_t)(bit /8);
+            buffersize = (PCM_MAX_FRM_SIZE * channel) * (uint64_t)(bit /8);
             break;
-        case MEDIA_FORMAT_AAC:
-            buffersize = (AAC_MIN_FRM_SIZE * AAC_MIN_NCH) * (uint64_t)(2);      /* 2 = (16bit/8)*/
+        case MEDIA_FORMAT_AAC_LC:
+        case MEDIA_FORMAT_AAC_HE:
+        case MEDIA_FORMAT_AAC_HE_PS:
+        case MEDIA_FORMAT_MP3:
+            buffersize = (MPEG_MAX_FRM_SIZE * MPEG_MIN_NCH) * (uint64_t)(2);      /* 2 = (16bit/8)*/
+        /* TODO : extenstion format */
+        case MEDIA_FORMAT_AMR_NB:
+        case MEDIA_FORMAT_AMR_WB:
+            buffersize = (AMR_MAX_FRM_SIZE * MPEG_MIN_NCH) * (uint64_t)(2);      /* 2 = (16bit/8)*/
+        case MEDIA_FORMAT_VORBIS:
+            buffersize = (OGG_MAX_FRM_SIZE * MPEG_MIN_NCH) * (uint64_t)(2);      /* 2 = (16bit/8)*/
             break;
         default:
             LOGE("Not supported format\n");
@@ -503,7 +542,11 @@ int media_packet_create_from_tbm_surface(media_format_h fmt, tbm_surface_h surfa
     MEDIA_PACKET_INSTANCE_CHECK(fmt);
     MEDIA_PACKET_INSTANCE_CHECK(surface);
     MEDIA_PACKET_NULL_ARG_CHECK(packet);
-    /* TODO : need more validation on fmt */
+    if (!MEDIA_FORMAT_IS_VIDEO(fmt) && !MEDIA_FORMAT_IS_AUDIO(fmt))
+    {
+        LOGE("The media format handle is not specified. set video info or audio info...");
+        return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+    }
 
     handle = (media_packet_s*)malloc( sizeof(media_packet_s));
     if (handle != NULL)
@@ -532,6 +575,7 @@ int media_packet_create_from_tbm_surface(media_format_h fmt, tbm_surface_h surfa
     }
     else
     {
+        LOGE("tbm_surface_get_info() is failed.. err =0x%08x", err);
         ret = MEDIA_PACKET_ERROR_INVALID_OPERATION;
         goto fail;
     }
@@ -563,6 +607,79 @@ fail:
     return ret;
 }
 
+int media_packet_create_from_external_memory(media_format_h fmt, void *mem_ptr, uint64_t size, media_packet_finalize_cb fcb, void *fcb_data, media_packet_h *packet)
+{
+    media_packet_s* handle;
+    int ret = MEDIA_PACKET_ERROR_NONE;
+
+    if (mem_ptr == NULL)
+        return MEDIA_PACKET_ERROR_INVALID_PARAMETER;
+
+    if (!(size > 0))
+        return MEDIA_PACKET_ERROR_INVALID_PARAMETER;
+
+    MEDIA_PACKET_INSTANCE_CHECK(fmt);
+    MEDIA_PACKET_NULL_ARG_CHECK(packet);
+
+    if (!MEDIA_FORMAT_IS_VIDEO(fmt) && !MEDIA_FORMAT_IS_AUDIO(fmt))
+    {
+        LOGE("The media format handle is not specified. set video info or audio info...");
+        return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+    }
+
+    if (MEDIA_FORMAT_IS_RAW(fmt) && MEDIA_FORMAT_IS_VIDEO(fmt))
+    {
+        LOGE("failed!. it supports only 'MEDIA_FORMAT_ENCODED' type.");
+        return MEDIA_PACKET_ERROR_INVALID_PARAMETER;
+    }
+
+    handle = (media_packet_s*)malloc( sizeof(media_packet_s));
+    if (handle != NULL)
+    {
+        memset(handle, 0 , sizeof(media_packet_s));
+    }
+    else
+    {
+        LOGE("[%s] MEDIA_PACKET_ERROR_OUT_OF_MEMORY(0x%08x)" ,__FUNCTION__,MEDIA_PACKET_ERROR_OUT_OF_MEMORY);
+        return MEDIA_PACKET_ERROR_OUT_OF_MEMORY;
+    }
+
+    handle->type = MEDIA_BUFFER_TYPE_EXTERNAL_MEMORY;
+
+    /* alloc handle->format */
+    handle->format = MEDIA_FORMAT_CAST(fmt);
+
+    /* set external allocated memory & external memory size */
+    handle->size = size;
+    handle->data = mem_ptr;
+
+    /* allocated buffer */
+    handle->is_allocated = true;
+
+    /* set finalized callback and user data */
+    handle->finalizecb_func = fcb;
+    handle->userdata = fcb_data;
+
+    /* increase format reference count */
+    ret = media_format_ref((media_format_h)handle->format);
+
+    /* take handle */
+    *packet = (media_packet_h)handle;
+    LOGI("[%s] new handle : %p", __FUNCTION__, *packet);
+    return ret;
+
+fail:
+
+    if (handle)
+    {
+        free(handle);
+        handle = NULL;
+    }
+
+    *packet = NULL;
+    return ret;
+}
+
 int media_packet_get_buffer_data_ptr(media_packet_h packet, void **data)
 {
     media_packet_s* handle;
@@ -625,6 +742,7 @@ int media_packet_set_format(media_packet_h packet, media_format_h fmt)
     /* if trying to set same format,  return*/
     if (handle->format == MEDIA_FORMAT_CAST(fmt))
     {
+        LOGE("The packet handle already refers the format handle..\n");
         return MEDIA_PACKET_ERROR_INVALID_OPERATION;
     }
 
@@ -858,6 +976,21 @@ int media_packet_is_raw(media_packet_h packet, bool *is_raw)
     return ret;
 }
 
+int media_packet_get_flags(media_packet_h packet, media_buffer_flags_e *flags)
+{
+    media_packet_s* handle;
+    int ret = MEDIA_PACKET_ERROR_NONE;
+
+    MEDIA_PACKET_INSTANCE_CHECK(packet);
+    MEDIA_PACKET_NULL_ARG_CHECK(flags);
+
+    handle = (media_packet_s*) packet;
+
+    *flags = handle->flags;
+
+    return ret;
+}
+
 int media_packet_set_flags(media_packet_h packet, media_buffer_flags_e flags)
 {
     media_packet_s* handle;
@@ -961,6 +1094,236 @@ int media_packet_has_tbm_surface_buffer(media_packet_h packet, bool* has_tbm_sur
     return ret;
 }
 
+int media_packet_get_number_of_video_planes(media_packet_h packet, uint32_t* num)
+{
+    media_packet_s* handle;
+    int ret = MEDIA_PACKET_ERROR_NONE;
+    bool has_tbm;
+
+    MEDIA_PACKET_INSTANCE_CHECK(packet);
+    MEDIA_PACKET_NULL_ARG_CHECK(num);
+
+    handle = (media_packet_s*) packet;
+
+    media_packet_has_tbm_surface_buffer(packet, &has_tbm);
+
+    if (has_tbm)
+    {
+        tbm_surface_info_s surface_info;
+        int err = tbm_surface_get_info((tbm_surface_h)handle->surface_data, &surface_info);
+        if (err == TBM_SURFACE_ERROR_NONE)
+        {
+            *num = surface_info.num_planes;
+            LOGD(" surface_info the number of planes = %d\n", (int)surface_info.num_planes);
+        }
+        else
+        {
+            *num = 0;
+            LOGE("tbm_surface_get_info() is failed.. 0x%08x \n", err);
+            ret = MEDIA_PACKET_ERROR_INVALID_OPERATION;
+        }
+    }
+    else
+    {
+        *num = 0;
+        LOGE("The packet handle doesn't have tbm_surface buffer type...\n");
+        ret = MEDIA_PACKET_ERROR_INVALID_OPERATION;
+
+    }
+
+    return ret;
+}
+
+int media_packet_get_video_stride_width(media_packet_h packet, int plane_idx, int *stride_width)
+{
+    media_packet_s* handle;
+    int ret = MEDIA_PACKET_ERROR_NONE;
+    bool has_tbm;
+
+    MEDIA_PACKET_INSTANCE_CHECK(packet);
+    MEDIA_PACKET_NULL_ARG_CHECK(stride_width);
+    if (plane_idx < 0)
+    {
+        LOGE("Invalid plane_idx : %d, must not be negative number\n", plane_idx);
+        return MEDIA_PACKET_ERROR_INVALID_PARAMETER;
+    }
+
+    handle = (media_packet_s*) packet;
+
+    media_packet_has_tbm_surface_buffer(packet, &has_tbm);
+
+    if (has_tbm)
+    {
+        tbm_surface_info_s surface_info;
+        int err = tbm_surface_get_info((tbm_surface_h)handle->surface_data, &surface_info);
+        if (err == TBM_SURFACE_ERROR_NONE)
+        {
+
+            if (surface_info.num_planes > plane_idx)
+            {
+                *stride_width = surface_info.planes[plane_idx].stride;
+            }
+            else
+            {
+                LOGE("the plane_idx is invalid, The number of planes = %lu\n", surface_info.num_planes);
+                *stride_width = 0;
+                ret = MEDIA_PACKET_ERROR_INVALID_PARAMETER;
+            }
+        }
+        else
+        {
+            *stride_width = 0;
+            LOGE("tbm_surface_get_info() is failed.. 0x%08x \n", err);
+            ret = MEDIA_PACKET_ERROR_INVALID_OPERATION;
+        }
+    }
+    else
+    {
+        LOGE("The packet handle doesn't have tbm_surface buffer type...\n");
+        *stride_width = 0;
+        ret = MEDIA_PACKET_ERROR_INVALID_OPERATION;
+    }
+
+    return ret;
+}
+
+int media_packet_get_video_stride_height(media_packet_h packet, int plane_idx, int *stride_height)
+{
+    media_packet_s* handle;
+    int ret = MEDIA_PACKET_ERROR_NONE;
+    bool has_tbm;
+
+    MEDIA_PACKET_INSTANCE_CHECK(packet);
+    MEDIA_PACKET_NULL_ARG_CHECK(stride_height);
+    if (plane_idx < 0)
+    {
+        LOGE("Invalid plane_idx : %d, must not be negative number\n", plane_idx);
+        return MEDIA_PACKET_ERROR_INVALID_PARAMETER;
+    }
+
+
+    handle = (media_packet_s*) packet;
+
+    media_packet_has_tbm_surface_buffer(packet, &has_tbm);
+
+    if (has_tbm)
+    {
+        tbm_surface_info_s surface_info;
+        int err = tbm_surface_get_info((tbm_surface_h)handle->surface_data, &surface_info);
+        if (err == TBM_SURFACE_ERROR_NONE)
+        {
+            if (surface_info.num_planes > plane_idx)
+            {
+                *stride_height = surface_info.planes[plane_idx].size/surface_info.planes[plane_idx].stride;
+            }
+            else
+            {
+                LOGE("the plane_idx is invalid, The number of planes = %lu\n", surface_info.num_planes);
+                *stride_height = 0;
+                ret = MEDIA_PACKET_ERROR_INVALID_PARAMETER;
+            }
+        }
+        else
+        {
+            *stride_height = 0;
+            LOGE("tbm_surface_get_info() is failed.. 0x%08x \n", err);
+            ret = MEDIA_PACKET_ERROR_INVALID_OPERATION;
+        }
+    }
+    else
+    {
+        LOGE("The packet handle doesn't have tbm_surface buffer type...\n");
+        *stride_height = 0;
+        ret = MEDIA_PACKET_ERROR_INVALID_OPERATION;
+    }
+
+    return ret;
+
+}
+
+int media_packet_get_video_plane_data_ptr(media_packet_h packet, int plane_idx, void **plane_data_ptr)
+{
+    media_packet_s* handle;
+    int ret = MEDIA_PACKET_ERROR_NONE;
+    bool has_tbm;
+
+    MEDIA_PACKET_INSTANCE_CHECK(packet);
+    MEDIA_PACKET_NULL_ARG_CHECK(plane_data_ptr);
+    if (plane_idx < 0)
+    {
+        LOGE("Invalid plane_idx : %d, must not be negative number\n", plane_idx);
+        return MEDIA_PACKET_ERROR_INVALID_PARAMETER;
+    }
+
+    handle = (media_packet_s*) packet;
+
+    media_packet_has_tbm_surface_buffer(packet, &has_tbm);
+
+    if (has_tbm)
+    {
+        tbm_surface_info_s surface_info;
+        int err = tbm_surface_get_info((tbm_surface_h)handle->surface_data, &surface_info);
+        if (err == TBM_SURFACE_ERROR_NONE)
+        {
+            if (surface_info.num_planes > plane_idx)
+            {
+                *plane_data_ptr = surface_info.planes[plane_idx].ptr;
+                LOGD("the tbm_surface_info.planes[%d].ptr = %p\n", plane_idx, surface_info.planes[plane_idx].ptr);
+            }
+            else
+            {
+                LOGE("the plane_idx is invalid, The number of planes = %lu\n", surface_info.num_planes);
+                *plane_data_ptr = NULL;
+                ret = MEDIA_PACKET_ERROR_INVALID_PARAMETER;
+            }
+        }
+        else
+        {
+            LOGE("tbm_surface_get_info() is failed.. 0x%08x \n", err);
+            *plane_data_ptr = NULL;
+            ret = MEDIA_PACKET_ERROR_INVALID_OPERATION;
+        }
+    }
+    else
+    {
+        LOGI("The packet handle doesn't have tbm_surface buffer type...\n");
+        *plane_data_ptr = NULL;
+        ret = MEDIA_PACKET_ERROR_INVALID_OPERATION;
+    }
+
+    return ret;
+}
+
+int media_packet_get_codec_data(media_packet_h packet, void** codec_data, unsigned int* codec_data_size)
+{
+    media_packet_s* handle;
+    int ret = MEDIA_PACKET_ERROR_NONE;
+
+    MEDIA_PACKET_INSTANCE_CHECK(packet);
+    MEDIA_PACKET_NULL_ARG_CHECK(codec_data);
+    MEDIA_PACKET_NULL_ARG_CHECK(codec_data_size);
+
+    handle = (media_packet_s*) packet;
+
+    LOGI("Get: codec data = %p, codec_data_size = %u\n", handle->codec_data, handle->codec_data_size);
+
+    if (handle->codec_data)
+    {
+        *codec_data_size = handle->codec_data_size;
+        *codec_data = handle->codec_data;
+    }
+    else
+    {
+        *codec_data = NULL;
+        *codec_data_size = 0;
+
+        LOGE("There is no codec data..\n");
+        ret = MEDIA_PACKET_ERROR_INVALID_OPERATION;
+    }
+
+    return ret;
+}
+
 int media_packet_destroy(media_packet_h packet)
 {
     media_packet_s* handle;
@@ -995,18 +1358,28 @@ int media_packet_destroy(media_packet_h packet)
     {
         if(handle->data)
         {
-            free(handle->data);
+            _aligned_free_normal_buffer_type(handle->data);
             handle->data = NULL;
         }
     }
-    else if (handle->type == MEDIA_BUFFER_TYPE_EXTERNAL_TBM_SURFACE)
+    else if (handle->type == MEDIA_BUFFER_TYPE_EXTERNAL_TBM_SURFACE || handle->type == MEDIA_BUFFER_TYPE_EXTERNAL_MEMORY)
     {
-        // there is nothing to do
+        // there is nothing to do, Do not free the buffer which is created by external module.
+    }
+
+    /* free codec_data if it is allocated */
+    if (handle->codec_data)
+    {
+        free(handle->codec_data);
+        handle->codec_data = NULL;
+        handle->codec_data_size = 0;
     }
 
     /* unreference media_format */
     media_format_unref(handle->format);
 
+    LOGI("The packet handle(%p) is will be destroyed..\n", handle);
+
     free(handle);
     handle = NULL;
 
@@ -1065,181 +1438,41 @@ static uint32_t _convert_to_tbm_surface_format(media_format_mimetype_e format_ty
 }
 
 
-#if 0
-int media_tool_create(mediatool_h *mediatool)
-{
-    MediaTool_s *handle;
-    int ret;
-    handle = (MediaTool_s*)malloc(sizeof(MediaTool_s));
-
-    if (handle != NULL)
-            memset(handle, 0, sizeof(MediaTool_s));
-    else
-            return MEDIA_TOOL_ERROR_OUT_OF_MEMORY;
-
-    //TODO : make _media_tool_create function
-    //ret = _media_tool_create(&handle->mediatool_handle);
-    if(ret != MEDIA_TOOL_ERROR_NONE)
-        {
-            free(handle);
-            handle = NULL;
-            return MEDIA_TOOL_ERROR_INVALID_OPERATION;
-        }
-    else
-        {
-            *mediatool = (mediatool_h*)handle;
-            handle->refcount = 1;
-            return MEDIA_TOOL_ERROR_NONE;
-        }
-}
-
-int media_tool_destroy(mediatool_h mediatool)
+static void* _aligned_malloc_normal_buffer_type (uint64_t size, int alignment)
 {
-    MediaTool_s* handle = (MediaTool_s *) mediatool;
-    int ret;
+    unsigned char* buffer_ptr;
+    unsigned char* temp_ptr;
 
-    if (handle == NULL)
-        return MEDIA_TOOL_ERROR_INVALID_PARAMETER;
+    if((temp_ptr = (void*)malloc(size + alignment)) != NULL)
+    {
+        buffer_ptr = (void*)((unsigned int)(temp_ptr + alignment - 1) & (~(unsigned int)(alignment -1)));
 
-    //TODO : make _media_tool_create function
-    ret = _media_tool_destroy(handle->mediatool_handle);
-    if (ret != MEDIA_TOOL_ERROR_NONE)
+        if(buffer_ptr == temp_ptr)
         {
-            return MEDIA_TOOL_ERROR_INVALID_OPERATION;
-        }
-    else
-        {
-            free(handle);
-            handle = NULL;
-            return MEDIA_TOOL_ERROR_NONE;
+            buffer_ptr += alignment;
         }
-}
-
-int media_tool_is_Iframe(mediatool_h mediatool, bool *isIFrame)
-{
-    MediaTool_s *handle = (MediaTool_s *) mediatool;
-    int ret;
-    if (handle == NULL)
-        return MEDIA_TOOL_ERROR_INVALID_PARAMETER;
-
-    *isIFrame  = handle->videocodecformat->isIFrame;
-
-    return MEDIA_TOOL_ERROR_NONE;
-}
-
-int media_tool_set_buffer(mediatool_h mediatool, MediaToolBufferPrivate_s* privBuffer)
-{
-    MediaTool_s *handle = (MediaTool_s *) mediatool;
-    int ret;
-    handle->bufferpriv = (MediaToolBufferPrivate_s *)malloc(sizeof(MediaToolBufferPrivate_s));
-
-    if (handle->bufferpriv != NULL)
-        memset(handle->bufferpriv, 0, sizeof(MediaToolBufferPrivate_s));
-    else
-        return MEDIA_TOOL_ERROR_OUT_OF_MEMORY;
 
-    return MEDIA_TOOL_ERROR_NONE;
-}
-
-int media_tool_get_buffer(mediatool_h mediatool, MediaToolBufferPrivate_s** privBuffer)
-{
-    MediaTool_s *handle = (MediaTool_s *) mediatool;
-    int ret;
-    if (handle->bufferpriv == NULL)
-        return MEDIA_TOOL_ERROR_INVALID_OPERATION;
-
-    memcpy(*privBuffer, handle->bufferpriv, sizeof(handle->bufferpriv));
-
-    return MEDIA_TOOL_ERROR_NONE;
-}
-
-int media_tool_set_video_codec_format(mediatool_h mediatool, VideoCodecFormat_s* videoCodecFormat)
-{
-    MediaTool_s *handle = (MediaTool_s *) mediatool;
-    int ret;
-    handle->videocodecformat = (VideoCodecFormat_s *)malloc(sizeof(VideoCodecFormat_s));
-
-    if (handle->videocodecformat != NULL)
-        memset(handle->videocodecformat, 0, sizeof(VideoCodecFormat_s));
-    else
-        return MEDIA_TOOL_ERROR_OUT_OF_MEMORY;
-
-    return MEDIA_TOOL_ERROR_NONE;
-}
-
-int media_tool_get_video_codec_format(mediatool_h mediatool, VideoCodecFormat_s** videoCodecFormat)
-{
-    MediaTool_s *handle = (MediaTool_s *) mediatool;
-    int ret;
-    if (handle->videocodecformat == NULL)
-        return MEDIA_TOOL_ERROR_INVALID_OPERATION;
-
-    memcpy(*videoCodecFormat, handle->videocodecformat, sizeof(handle->videocodecformat));
-
-    return MEDIA_TOOL_ERROR_NONE;
-}
-
-int media_tool_set_audio_codec_format(mediatool_h mediatool, AudioCodecFormat_s* audioCodecFormat)
-{
-    MediaTool_s *handle = (MediaTool_s *) mediatool;
-    int ret;
-    handle->audiocodecformat = (AudioCodecFormat_s *)malloc(sizeof(AudioCodecFormat_s));
-
-    if (handle->audiocodecformat != NULL)
-        memset(handle->audiocodecformat, 0, sizeof(AudioCodecFormat_s));
-    else
-        return MEDIA_TOOL_ERROR_OUT_OF_MEMORY;
-
-    return MEDIA_TOOL_ERROR_NONE;
-}
-
-int media_tool_get_audio_codec_format(mediatool_h mediatool, AudioCodecFormat_s** audioCodecFormat)
-{
-    MediaTool_s *handle = (MediaTool_s *) mediatool;
-    int ret;
-    if (handle->audiocodecformat == NULL)
-        return MEDIA_TOOL_ERROR_INVALID_OPERATION;
-
-    memcpy(*audioCodecFormat, handle->audiocodecformat, sizeof(handle->audiocodecformat));
-
-    return MEDIA_TOOL_ERROR_NONE;
-}
-
-int media_tool_ref(mediatool_h mediatool)
-{
-    MediaTool_s *handle = (MediaTool_s *) mediatool;
-
-    if (handle == NULL)
-        return MEDIA_TOOL_ERROR_INVALID_PARAMETER;
-
-    if (!(handle->refcount> 0))
-        return MEDIA_TOOL_ERROR_INVALID_OPERATION;
-
-    g_atomic_int_inc (&handle->refcount);
+        *(buffer_ptr - 1) = (unsigned int)(buffer_ptr - temp_ptr);
+        return (void*)buffer_ptr;
+    }
 
-    return MEDIA_TOOL_ERROR_NONE;
+    return NULL;
 }
 
-int media_tool_unref(mediatool_h mediatool)
+static void _aligned_free_normal_buffer_type (void* buffer_ptr)
 {
-    MediaTool_s *handle = (MediaTool_s *) mediatool;
+    unsigned char* ptr;
+    if (buffer_ptr == NULL)
+        return;
 
-    if (handle == NULL)
-        return MEDIA_TOOL_ERROR_INVALID_PARAMETER;
+    ptr = (unsigned char*)buffer_ptr;
 
-    if (!(handle->refcount> 0))
-        return MEDIA_TOOL_ERROR_INVALID_OPERATION;
+    // *(ptr - 1) holds the offset to the real allocated block
+    // we sub that offset os we free the real pointer
+    ptr -= *(ptr - 1);
 
-    int zero;
-
-    zero = g_atomic_int_dec_and_test (&handle->refcount);
-    if (zero)
-        {
-            free(handle);
-            handle = NULL;
-        }
-    return MEDIA_TOOL_ERROR_NONE;
+    // Free the memory
+    free(ptr);
+    ptr = NULL;
 }
 
-#endif
-
diff --git a/src/media_packet_internal.c b/src/media_packet_internal.c
new file mode 100755 (executable)
index 0000000..402e9d4
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <dlog.h>
+#include <media_format.h>
+#include <media_packet.h>
+#include <media_packet_internal.h>
+#include <media_packet_private.h>
+#include <media_format_private.h>
+
+int media_packet_set_codec_data(media_packet_h packet, void* codec_data, unsigned int codec_data_size)
+{
+    media_packet_s* handle;
+    int ret = MEDIA_PACKET_ERROR_NONE;
+
+    MEDIA_PACKET_INSTANCE_CHECK(packet);
+
+    handle = (media_packet_s*) packet;
+
+    LOGI("Set: codec data = %p, codec_data_size = %u\n", codec_data, codec_data_size);
+
+    handle->codec_data = (void*)malloc(codec_data_size);
+    if (handle->codec_data != NULL)
+    {
+        memset(handle->codec_data, 0 , codec_data_size);
+    }
+    else
+    {
+        LOGE("[%s] MEDIA_PACKET_ERROR_OUT_OF_MEMORY(0x%08x)" ,__FUNCTION__,MEDIA_PACKET_ERROR_OUT_OF_MEMORY);
+        return MEDIA_PACKET_ERROR_OUT_OF_MEMORY;
+    }
+
+    memcpy(handle->codec_data, codec_data, codec_data_size);
+    handle->codec_data_size = codec_data_size;
+
+    return ret;
+}
+
old mode 100644 (file)
new mode 100755 (executable)
index b59fff0..aed006f
@@ -10,7 +10,7 @@ FOREACH(flag ${${fw_test}_CFLAGS})
     SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
 
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -pie")
 
 aux_source_directory(. sources)
 FOREACH(src ${sources})
old mode 100644 (file)
new mode 100755 (executable)
index 5361ece..e460bff
 #include <media_packet_private.h>
 #include <media_format.h>
 #include <media_format_private.h>
-
+#include <media_packet_internal.h>
 
 #include <appcore-efl.h>
 
 #define PACKAGE "media_tool_test"
 #define MAX_STRING_LEN 2048
-#define MAX_HANDLE 20
+#define MAX_HANDLE 10
+#define MEDIA_FORMAT_MAX_HANDLE 3
 
 
 enum
 {
     CURRENT_STATUS_MAINMENU,
-    CURRENT_STATUS_SET_FORMAT,
+    CURRENT_STATUS_PACKET_SET_FORMAT,
     CURRENT_STATUS_DURATION,
+    CURRENT_STATUS_FORMAT_SET_VIDEO_MIME,
+    CURRENT_STATUS_FORMAT_SET_VIDEO_WIDTH,
+    CURRENT_STATUS_FORMAT_SET_VIDEO_HEIGHT,
+    CURRENT_STATUS_FORMAT_SET_VIDEO_AVG_BPS,
+    CURRENT_STATUS_FORMAT_SET_VIDEO_MAX_BPS,
+    CURRENT_STATUS_FORMAT_SET_AUDIO_MIME,
+    CURRENT_STATUS_FORMAT_SET_AUDIO_CHANNEL,
+    CURRENT_STATUS_FORMAT_SET_AUDIO_SAMPLERATE,
+    CURRENT_STATUS_FORMAT_SET_AUDIO_BIT,
+    CURRENT_STATUS_FORMAT_SET_AUDIO_AVG_BPS,
+    CURRENT_STATUS_FORMAT_SET_AUDIO_AAC_TYPE,
 };
 
 
@@ -41,57 +53,226 @@ char g_uri[MAX_STRING_LEN];
 int g_menu_state = CURRENT_STATUS_MAINMENU;
 int g_handle_num = 1;
 static media_packet_h g_media_packet[MAX_HANDLE] = {0};
-static media_format_h format[3] = {0};
+ media_format_h g_media_format[MEDIA_FORMAT_MAX_HANDLE] = {0};
+int media_format_idx = -1;
 bool is_only_created_handle;
 bool is_excute_create;
 
+unsigned char codec_data[0x04] = {0x00, 0x01, 0x02, 0x03};
+unsigned int codec_data_size = 4;
+unsigned char* codec_data_ptr = codec_data;
+
+
 /***********************************************/
 /***  Test API part
 /***********************************************/
-static void _create_format_480_640_es(void)
+static void _media_format_create(void)
 {
+    int ret;
 
-    if (media_format_create(&format[0]) == MEDIA_FORMAT_ERROR_NONE)
+    if (g_media_format[0] == NULL)
     {
-        g_print("media_format_create success! \n");
-
-        int ret = MEDIA_FORMAT_ERROR_NONE;
-        ret = media_format_set_video_mime(format[0], MEDIA_FORMAT_H264_HP);
-        ret = media_format_set_video_width(format[0], 480);
-        ret = media_format_set_video_height(format[0], 640);
-        ret = media_format_set_video_avg_bps(format[0], 10000000);
-        ret = media_format_set_video_max_bps(format[0], 15000000);
+        int ret = media_format_create(&g_media_format[0]);
         if (ret == MEDIA_FORMAT_ERROR_NONE)
+       {
+            g_print("media_format_h[0] is created successfully! \n");
+            media_format_idx = 0;
+            g_print("ref_count = %d\n", MEDIA_FORMAT_GET_REFCOUNT(g_media_format[0]));
+       }
+        else
         {
-            g_print("media_format_set_video_xxx success! w: 480, h: 640, MEDIA_FORMAT_H264_HP \n");
-            g_print("\t\t\t\t ====>> ref_count = %d", MEDIA_FORMAT_GET_REFCOUNT(format[0]));
+            g_print("media_format_create failed...\n");
+            g_print("==> ref_count = %d\n", MEDIA_FORMAT_GET_REFCOUNT(g_media_format[0]));
         }
-        else
-            g_print("media_format_set_video_xxx failed..\n");
     }
     else
     {
-        g_print("media_format_create failed..\n");
+        ret = MEDIA_FORMAT_ERROR_INVALID_OPERATION;
+        g_print("\n can not create media_format_h handle anymore...already exist.\n");
+    }
+
+
+}
+
+static void _media_format_set_video_mime(int num)
+{
+    int ret;
+    if (num == 0)
+    {
+        ret = media_format_set_video_mime(g_media_format[media_format_idx], MEDIA_FORMAT_H264_HP);
+    }
+    else if (num == 1)
+    {
+        ret = media_format_set_video_mime(g_media_format[media_format_idx], MEDIA_FORMAT_RGB888);
+    }
+    else if (num == 2)
+    {
+        ret = media_format_set_video_mime(g_media_format[media_format_idx], MEDIA_FORMAT_I420);
+    }
+    else
+    {
+        g_print("Invalid number...\n");
+    }
+
+    if (ret == MEDIA_FORMAT_ERROR_NONE)
+        g_print("media_format_set_video_mime is succeeded!!\n");
+    else
+        g_print("media_format_set_video_mime is failed...!!\n");
+
+}
+
+static void _media_format_set_video_width(int w)
+{
+    int ret;
+    ret = media_format_set_video_width(g_media_format[media_format_idx], w);
+
+    if (ret == MEDIA_FORMAT_ERROR_NONE)
+        g_print("media_format_set_video_width is succeeded!!\n");
+    else
+        g_print("media_format_set_video_width is failed...!!\n");
+}
+
+static void _media_format_set_video_height(int h)
+{
+    int ret;
+    ret = media_format_set_video_height(g_media_format[media_format_idx], h);
+
+    if (ret == MEDIA_FORMAT_ERROR_NONE)
+        g_print("media_format_set_video_height is succeeded!!\n");
+    else
+        g_print("media_format_set_video_height is failed...!!\n");
+
+
+}
+
+static void _media_format_set_video_avg_bps(int avg_bps)
+{
+    int ret;
+    ret = media_format_set_video_avg_bps(g_media_format[media_format_idx], avg_bps);
+
+    if (ret == MEDIA_FORMAT_ERROR_NONE)
+        g_print("media_format_set_video_avg_bps is succeeded!!\n");
+    else
+        g_print("media_format_set_video_avg_bps is failed...!!\n");
+}
+
+static void _media_format_set_video_max_bps(int max_bps)
+{
+    int ret;
+    ret = media_format_set_video_max_bps(g_media_format[media_format_idx], max_bps);
+
+    if (ret == MEDIA_FORMAT_ERROR_NONE)
+        g_print("media_format_set_video_max_bps is succeeded!!\n");
+    else
+        g_print("media_format_set_video_max_bps is failed...!!\n");
+}
+
+static void _media_format_set_audio_mime(int num)
+{
+    int ret;
+    if (num == 0)
+    {
+        ret = media_format_set_audio_mime(g_media_format[media_format_idx], MEDIA_FORMAT_AMR);
+    }
+    else if (num == 1)
+    {
+        ret = media_format_set_audio_mime(g_media_format[media_format_idx], MEDIA_FORMAT_PCM);
+    }
+    else if (num == 2)
+    {
+        ret = media_format_set_audio_mime(g_media_format[media_format_idx], MEDIA_FORMAT_AAC);
     }
+    else
+    {
+        g_print("Invalid number...\n");
+    }
+
+    if (ret == MEDIA_FORMAT_ERROR_NONE)
+        g_print("media_format_set_audio_mime is succeeded!!\n");
+    else
+        g_print("media_format_set_audio_mime is failed...!!\n");
 
 }
 
+static void _media_format_set_audio_channel(int channel)
+{
+    int ret;
+    ret = media_format_set_audio_channel(g_media_format[media_format_idx], channel);
+
+    if (ret == MEDIA_FORMAT_ERROR_NONE)
+        g_print("media_format_set_audio_channel is succeeded!!\n");
+    else
+        g_print("media_format_set_audio_channel is failed...!!\n");
+}
+
+static void _media_format_set_audio_samplerate(int samplerate)
+{
+    int ret;
+    ret = media_format_set_audio_samplerate(g_media_format[media_format_idx], samplerate);
+
+    if (ret == MEDIA_FORMAT_ERROR_NONE)
+        g_print("media_format_set_audio_samplerate is succeeded!!\n");
+    else
+        g_print("media_format_set_audio_samplerate is failed...!!\n");
+}
+
+static void _media_format_set_audio_bit(int bit)
+{
+    int ret;
+    ret = media_format_set_audio_bit(g_media_format[media_format_idx], bit);
+
+    if (ret == MEDIA_FORMAT_ERROR_NONE)
+        g_print("media_format_set_audio_bit is succeeded!!\n");
+    else
+        g_print("media_format_set_audio_bit is failed...!!\n");
+}
+
+static void _media_format_set_audio_avg_bps(int avg_bps)
+{
+    int ret;
+    ret = media_format_set_audio_avg_bps(g_media_format[media_format_idx], avg_bps);
+
+    if (ret == MEDIA_FORMAT_ERROR_NONE)
+        g_print("media_format_set_audio_avg_bps is succeeded!!\n");
+    else
+        g_print("media_format_set_audio_avg_bps is failed...!!\n");
+}
+
+static void _media_format_set_audio_aac_type(bool is_adts)
+{
+    int ret;
+    ret = media_format_set_audio_aac_type(g_media_format[media_format_idx], is_adts);
+
+    if (ret == MEDIA_FORMAT_ERROR_NONE)
+        g_print("media_format_set_audio_aac_type is succeeded!!\n");
+    else
+        g_print("media_format_set_audio_aac_type is failed...!!\n");
+}
+
 static void _create_format_320_240_es(void)
 {
 
-    if (media_format_create(&format[1]) == MEDIA_FORMAT_ERROR_NONE)
+    if (media_format_create(&g_media_format[1]) == MEDIA_FORMAT_ERROR_NONE)
     {
-        g_print("media_format_create success! \n");
+        g_print("media_format_create is succeeded! \n");
+        g_print("the media_format_h[1] is created..\n");
         int ret = MEDIA_FORMAT_ERROR_NONE;
-        ret = media_format_set_video_mime(format[1], MEDIA_FORMAT_H264_HP);
-        ret = media_format_set_video_width(format[1], 320);
-        ret = media_format_set_video_height(format[1], 240);
-        ret = media_format_set_video_avg_bps(format[1], 3000000);
-        ret = media_format_set_video_max_bps(format[1], 15000000);
+        media_format_idx = 1;
+
+        media_format_mimetype_e mime = MEDIA_FORMAT_H264_HP;
+        int w = 320;
+        int h = 240;
+        int avg_bps = 3000000;
+        int max_bps = 15000000;
+        ret = media_format_set_video_mime(g_media_format[1], MEDIA_FORMAT_H264_HP);
+        ret = media_format_set_video_width(g_media_format[1], 320);
+        ret = media_format_set_video_height(g_media_format[1], 240);
+        ret = media_format_set_video_avg_bps(g_media_format[1], 3000000);
+        ret = media_format_set_video_max_bps(g_media_format[1], 15000000);
         if (ret == MEDIA_FORMAT_ERROR_NONE)
         {
-            g_print("media_format_set_video_xxx success! w: 320, h: 240, MEDIA_FORMAT_H264_HP \n");
-            g_print("\t\t\t\t ====>> ref_count = %d", MEDIA_FORMAT_GET_REFCOUNT(format[1]));
+            g_print("media_format_set_video_xxx succeed! w:%d, h:%d, 0x%x, avg_bps: %d, max_bps: %d\n", w, h, mime, avg_bps, max_bps);
+            g_print("\t\t\t\t ====>> ref_count = %d\n", MEDIA_FORMAT_GET_REFCOUNT(g_media_format[1]));
         }
         else
             g_print("media_format_set_video_xxx failed..\n");
@@ -107,19 +288,25 @@ static void _create_format_320_240_es(void)
 static void _create_format_raw(void)
 {
 
-    if (media_format_create(&format[2]) == MEDIA_FORMAT_ERROR_NONE)
+    if (media_format_create(&g_media_format[2]) == MEDIA_FORMAT_ERROR_NONE)
     {
-        g_print("media_format_create success! \n");
+        g_print("media_format_create is succeeded! \n");
         int ret = MEDIA_FORMAT_ERROR_NONE;
-        ret = media_format_set_video_mime(format[2], MEDIA_FORMAT_RGB888);
-        ret = media_format_set_video_width(format[2], 128);
-        ret = media_format_set_video_height(format[2], 128);
-        ret = media_format_set_video_avg_bps(format[2], 2000000);
-        ret = media_format_set_video_max_bps(format[2], 15000000);
+
+        media_format_mimetype_e mime = MEDIA_FORMAT_I420;
+        int w = 128;
+        int h = 128;
+        int avg_bps = 2000000;
+        int max_bps = 15000000;
+        ret = media_format_set_video_mime(g_media_format[2], mime);
+        ret = media_format_set_video_width(g_media_format[2], w);
+        ret = media_format_set_video_height(g_media_format[2], h);
+        ret = media_format_set_video_avg_bps(g_media_format[2], avg_bps);
+        ret = media_format_set_video_max_bps(g_media_format[2], max_bps);
         if (ret == MEDIA_FORMAT_ERROR_NONE)
         {
-            g_print("media_format_set_video_xxx success! w:128, h:128, MEDIA_FORMAT_RGB888\n");
-            g_print("\t\t\t\t ====>> ref_count = %d", MEDIA_FORMAT_GET_REFCOUNT(format[2]));
+            g_print("media_format_set_video_xxx success! w:%d, h:%d, 0x%x, avg_bps: %d, max_bps: %d\n", w, h, mime, avg_bps, max_bps);
+            g_print("\t\t\t\t ====>> ref_count = %d\n", MEDIA_FORMAT_GET_REFCOUNT(g_media_format[2]));
         }
         else
             g_print("media_format_set_video_xxx failed..\n");
@@ -138,7 +325,7 @@ static int _finalize_callback(media_packet_h packet, int err, void* userdata)
     return MEDIA_PACKET_FINALIZE;
 }
 
-static void _create_and_alloc(void)
+static void _media_packet_create_alloc(void)
 {
     g_print("=== create_and_alloc!!\n");
     int i;
@@ -147,32 +334,40 @@ static void _create_and_alloc(void)
     {
         if(g_media_packet[i] != NULL)
         {
+            int ref_count = MEDIA_FORMAT_GET_REFCOUNT(g_media_format[media_format_idx]);
             media_packet_destroy(g_media_packet[i]);
+            if (ref_count == 1)
+            {
+                g_media_format[media_format_idx] = NULL;
+                g_print("media_format_h[%d] is destroyed...\n", media_format_idx);
+            }
             g_media_packet[i] = NULL;
         }
 
-        if(format[0] == NULL)
+        if(g_media_format[0] == NULL)
         {
             g_print("media_format_h is NULL!! create media_format_h handle \n");
             break;
         }
-        /* only ES format , if you want to another format, see _create_format_es() */
-        if (media_packet_create_alloc(format[0], _finalize_callback, NULL, &g_media_packet[i]) != MEDIA_PACKET_ERROR_NONE)
+
+        if (media_packet_create_alloc(g_media_format[0], _finalize_callback, NULL, &g_media_packet[i]) != MEDIA_PACKET_ERROR_NONE)
         {
             g_print("media_packet create is failed\n");
-            media_format_unref(format[0]);
         }
         else
         {
-            g_print("media_packet_create_alloc is sucess!!\n");
-            media_format_unref(format[0]);
+            media_format_idx = 0;
+            g_print("succeeded media_packet_create_alloc !!\n");
+            g_print(" ==> media_format_h[0] ref_count =%d\n", MEDIA_FORMAT_GET_REFCOUNT(g_media_format[0]));
+            media_format_unref(g_media_format[0]);
+            g_print(" ====> media_format_unref, media_format_h[0] ref_count = %d\n", MEDIA_FORMAT_GET_REFCOUNT(g_media_format[0]));
             is_excute_create = true;
         }
 
     }
 }
 
-static void _create(void)
+static void _media_packet_create(void)
 {
     g_print("=== create!!\n");
     is_only_created_handle = true;
@@ -182,31 +377,40 @@ static void _create(void)
     {
         if(g_media_packet[i] != NULL)
         {
+            int ref_count = MEDIA_FORMAT_GET_REFCOUNT(g_media_format[media_format_idx]);
             media_packet_destroy(g_media_packet[i]);
+            if (ref_count == 1)
+            {
+                g_media_format[media_format_idx] = NULL;
+                g_print("media_format_h[%d] is destroyed...\n", media_format_idx);
+            }
             g_media_packet[i] = NULL;
         }
 
-        if(format[0] == NULL)
+        if(g_media_format[0] == NULL)
         {
             g_print("media_format_h is NULL!! create media_format_h handle \n");
             break;
         }
 
         /* only ES format , if you want to another format, see _create_format_es() */
-        if (media_packet_create(format[0], _finalize_callback, NULL, &g_media_packet[i]) != MEDIA_PACKET_ERROR_NONE)
+        if (media_packet_create(g_media_format[0], _finalize_callback, NULL, &g_media_packet[i]) != MEDIA_PACKET_ERROR_NONE)
         {
             g_print("media_packet create is failed\n");
-            media_format_unref(format[0]);
         }
         else
         {
+            media_format_idx = 0;
             g_print("media_packet_create is sucess!!\n");
+            g_print(" ==> media_format_h[0] ref_count =%d\n", MEDIA_FORMAT_GET_REFCOUNT(g_media_format[0]));
+            media_format_unref(g_media_format[0]);
+            g_print(" ====> media_format_unref, media_format_h[0] ref_count = %d\n", MEDIA_FORMAT_GET_REFCOUNT(g_media_format[0]));
             is_excute_create = true;
         }
     }
 }
 
-static void _alloc(void)
+static void _media_packet_alloc(void)
 {
     g_print("=== alloc!!\n");
     if (is_only_created_handle)
@@ -222,12 +426,12 @@ static void _alloc(void)
     }
 }
 
-static void _create_from_tbm_surface(void)
+static void _media_packet_create_from_tbm_surface(void)
 {
     g_print("=== create_from_tbm_surface!!\n");
 
     tbm_surface_h surface;
-    surface = tbm_surface_create(128, 128, TBM_FORMAT_RGB888);
+    surface = tbm_surface_create(128, 128, TBM_FORMAT_YUV420);
 
     if (surface)
     {
@@ -237,25 +441,36 @@ static void _create_from_tbm_surface(void)
         {
             if(g_media_packet[i] != NULL)
             {
+                int ref_count = MEDIA_FORMAT_GET_REFCOUNT(g_media_format[media_format_idx]);
                 media_packet_destroy(g_media_packet[i]);
+
+                if (ref_count == 1 )
+                {
+                    g_media_format[media_format_idx] = NULL;
+                    g_print("media_format_h[%d] is destroyed...\n", media_format_idx);
+                }
+
                 g_media_packet[i] = NULL;
             }
 
-            if(format[2] == NULL)
+            if(g_media_format[2] == NULL)
             {
-                g_print("media_format_h is NULL!! create media_format_h handle \n");
-                break;
+                g_print("create raw video type media_format_h[2]... \n");
+                _create_format_raw();
             }
 
             /* only RAW format , if you want to another format, see _create_format_raw() */
-            if (media_packet_create_from_tbm_surface(format[2], surface, _finalize_callback, NULL, &g_media_packet[i]) != MEDIA_PACKET_ERROR_NONE)
+            if (media_packet_create_from_tbm_surface(g_media_format[2], surface, _finalize_callback, NULL, &g_media_packet[i]) != MEDIA_PACKET_ERROR_NONE)
             {
                 g_print("media_packet_create_from_tbm_surface is failed\n");
-                media_format_unref(format[2]);
             }
             else
             {
                 g_print("media_packet_create_from_tbm_surface is sucess!!\n");
+                g_print(" ==> media_format_h[2] ref_count =%d\n", MEDIA_FORMAT_GET_REFCOUNT(g_media_format[2]));
+                media_format_unref(g_media_format[2]);
+                g_print(" ====> media_format_unref, media_format_h[2] ref_count = %d\n", MEDIA_FORMAT_GET_REFCOUNT(g_media_format[2]));
+                media_format_idx = 2;
                 is_excute_create = true;
             }
         }
@@ -267,7 +482,7 @@ static void _create_from_tbm_surface(void)
     }
 }
 
-static void _copy(void)
+static void _media_packet_copy(void)
 {
     g_print("=== copy!!\n");
 
@@ -298,32 +513,49 @@ static void _copy(void)
 
 }
 
-static void _destroy()
+static void _media_packet_destroy()
 {
     g_print("=== destroy!!\n");
     int i;
     int ret;
+
+    int ref_count;
+
     for (i = 0; i < g_handle_num ; i++)
     {
         if(g_media_packet[i]!=NULL)
         {
+            ref_count = MEDIA_FORMAT_GET_REFCOUNT(g_media_format[media_format_idx]);
             ret = media_packet_destroy(g_media_packet[i]);
-            g_media_packet[i] = 0;
+            g_media_packet[i] = NULL;
+
+            if (ref_count == 1)
+            {
+                g_media_format[media_format_idx] = NULL;
+                g_print("media_format_h[%d] is destroyed...\n", media_format_idx);
+            }
+
             if (ret == MEDIA_PACKET_ERROR_NONE)
-                g_print("media_packet_destroy is sucess!!\n");
+            {
+                g_print("media_packet_destroy is succeeded!!\n");
+                if (g_media_format[media_format_idx] != NULL)
+                    g_print(" ==> media_format_h[%d] ref_count = %d\n", media_format_idx, MEDIA_FORMAT_GET_REFCOUNT(g_media_format[media_format_idx]));
+            }
             else
                 g_print("media_packet_destroy is failed...\n");
         }
+        else
+            g_print("There is nothing to destroy media_packet_h[%d] handle...\n", i);
     }
 }
 
-static void _get_size(void)
+static void _media_packet_get_buffer_size(void)
 {
     uint64_t size;
     if (media_packet_get_buffer_size(g_media_packet[0],&size) == MEDIA_PACKET_ERROR_NONE)
     {
         g_print("media_packet_get_buffer_size is sucess!!");
-        g_print("\t\t[media_packet]===> size = %llu", size);
+        g_print("\t\t[media_packet]===> size = %llu\n", size);
     }
     else
     {
@@ -331,14 +563,14 @@ static void _get_size(void)
     }
 }
 
-static void _get_duration(void)
+static void _media_packet_get_duration(void)
 {
     uint64_t duration;
 
     if (media_packet_get_duration(g_media_packet[0], &duration) == MEDIA_PACKET_ERROR_NONE)
     {
         g_print("media_packet_get_duration is sucess!!");
-        g_print("\t\t[media_packet]===> duration = %llu", duration);
+        g_print("\t\t[media_packet]===> duration = %llu\n", duration);
     }
     else
     {
@@ -346,7 +578,7 @@ static void _get_duration(void)
     }
 }
 
-static void _get_buffer_ptr(void)
+static void _media_packet_get_buffer_data_ptr(void)
 {
     void* ptr;
     media_packet_s* packet = g_media_packet[0];
@@ -360,7 +592,7 @@ static void _get_buffer_ptr(void)
     if (media_packet_get_buffer_data_ptr(g_media_packet[0], &ptr) == MEDIA_PACKET_ERROR_NONE)
     {
         g_print("media_packet_get_buffer_data_ptr is sucess!!");
-        g_print("\t\t[media_packet]===> buffer_data_ptr = %p", ptr);
+        g_print("\t\t[media_packet]===> buffer_data_ptr = %p\n", ptr);
     }
     else
     {
@@ -369,14 +601,14 @@ static void _get_buffer_ptr(void)
 
 }
 
-static void _get_tbm_surface()
+static void _media_packet_get_tbm_surface()
 {
     tbm_surface_h tbm_surface;
 
     if (media_packet_get_tbm_surface(g_media_packet[0], &tbm_surface) == MEDIA_PACKET_ERROR_NONE)
     {
         g_print("media_packet_get_tbm_surface is sucess!!");
-        g_print("\t\t[media_packet]===> tbm_surface = %p", (void*)tbm_surface);
+        g_print("\t\t[media_packet]===> tbm_surface = %p\n", (void*)tbm_surface);
     }
     else
     {
@@ -384,7 +616,105 @@ static void _get_tbm_surface()
     }
 }
 
-static void _set_duration(uint64_t duration)
+static void _media_packet_get_number_of_video_planes()
+{
+    uint32_t num = 0;
+    if (media_packet_get_number_of_video_planes(g_media_packet[0], &num)== MEDIA_PACKET_ERROR_NONE)
+    {
+        g_print("media_packet_get_number_of_video_planes is sucess!!\n");
+        g_print("\t\t[media_packet]===> number of planes = %ld\n", num);
+
+    }
+    else
+    {
+        g_print("media_packet_get_number_of_video_planes is failed...");
+    }
+}
+
+static void _media_packet_get_video_stride_width()
+{
+    int stride_w;
+    if (media_packet_get_video_stride_width(g_media_packet[0], 0, &stride_w)== MEDIA_PACKET_ERROR_NONE)
+    {
+        g_print("media_packet_get_video_stride_width is sucess!!\n");
+        g_print("\t\t[media_packet]===> stride width = %d\n", stride_w);
+
+    }
+    else
+    {
+        g_print("media_packet_get_video_stride_width is failed...");
+    }
+}
+
+static void _media_packet_get_video_stride_height()
+{
+    int stride_h;
+    if (media_packet_get_video_stride_height(g_media_packet[0], 0, &stride_h)== MEDIA_PACKET_ERROR_NONE)
+    {
+        g_print("media_packet_get_video_stride_height is sucess!!\n");
+        g_print("\t\t[media_packet]===> stride height = %d\n", stride_h);
+
+    }
+    else
+    {
+        g_print("media_packet_get_video_stride_height is failed...");
+    }
+}
+
+static void _media_packet_get_video_plane_data_ptr()
+{
+    void* ptr;
+    if (media_packet_get_video_plane_data_ptr(g_media_packet[0], 0, &ptr)== MEDIA_PACKET_ERROR_NONE)
+    {
+        g_print("media_packet_get_video_plane_data_ptr is sucess!!\n");
+        g_print("\t\t[media_packet]===> ptr = %p\n", ptr);
+
+    }
+    else
+    {
+        g_print("_media_packet_get_plane_data_ptr is failed...");
+    }
+}
+
+static void _media_packet_set_codec_data()
+{
+    if (media_packet_set_codec_data(g_media_packet[0], (void*)codec_data_ptr, codec_data_size) == MEDIA_PACKET_ERROR_NONE)
+    {
+        g_print("media_packet_set_codec_data is sucess..!\n");
+    }
+    else
+    {
+        g_print("media_packet_set_codec_data is failed...\n");
+    }
+}
+
+static void _media_packet_get_codec_data()
+{
+    unsigned char* get_codec_data;
+    unsigned int get_codec_data_size;
+
+    if (media_packet_get_codec_data(g_media_packet[0], &get_codec_data, &get_codec_data_size) == MEDIA_PACKET_ERROR_NONE)
+    {
+        g_print("media_packet_get_codec_data is sucess ... !\n");
+        g_print("codec_data_size = %u\n", get_codec_data_size);
+
+        if (get_codec_data_size == 0)
+            return;
+
+        int i;
+        for (i=0 ; i < get_codec_data_size; i++)
+        {
+            g_print("codec_data[%d] ", i);
+            g_print(" = 0x%x\n", get_codec_data[i]);
+        }
+    }
+    else
+    {
+        g_print("media_packet_get_codec_data is failed...\n");
+    }
+}
+
+static void _media_packet_set_duration(uint64_t duration)
 {
     if (media_packet_set_duration(g_media_packet[0], duration) == MEDIA_PACKET_ERROR_NONE)
     {
@@ -396,7 +726,7 @@ static void _set_duration(uint64_t duration)
     }
 }
 
-static void _is_video(void)
+static void _media_packet_is_video(void)
 {
     bool is_video;
     if (media_packet_is_video(g_media_packet[0], &is_video) == MEDIA_PACKET_ERROR_NONE)
@@ -410,7 +740,7 @@ static void _is_video(void)
     }
 }
 
-static void _is_audio(void)
+static void _media_packet_is_audio(void)
 {
     bool is_audio;
     if (media_packet_is_audio(g_media_packet[0], &is_audio) == MEDIA_PACKET_ERROR_NONE)
@@ -424,7 +754,7 @@ static void _is_audio(void)
     }
 }
 
-static void _is_encoded(void)
+static void _media_packet_is_encoded(void)
 {
     bool is_encoded;
     if (media_packet_is_encoded(g_media_packet[0], &is_encoded) == MEDIA_PACKET_ERROR_NONE)
@@ -438,7 +768,7 @@ static void _is_encoded(void)
     }
 
 }
-static void _is_raw(void)
+static void _media_packet_is_raw(void)
 {
     bool is_raw;
     if (media_packet_is_raw(g_media_packet[0], &is_raw) == MEDIA_PACKET_ERROR_NONE)
@@ -453,7 +783,7 @@ static void _is_raw(void)
 
 }
 
-static void _get_format(void)
+static void _media_packet_get_format(void)
 {
     media_format_h fmt;
     if (media_packet_get_format(g_media_packet[0], &fmt) == MEDIA_PACKET_ERROR_NONE)
@@ -461,15 +791,36 @@ static void _get_format(void)
         int w;
         int h;
 
-        g_print("media_packet_get_format is sucess!\n");
-        if (media_format_get_video_info(fmt, NULL, &w, &h, NULL, NULL) == MEDIA_PACKET_ERROR_NONE)
+        int channel;
+        int samplerate;
+        int bit;
+        int audio_avg_bps;
+
+        g_print("media_packet_get_format is sucess! %p \n", fmt);
+
+        if (MEDIA_FORMAT_IS_VIDEO(fmt))
         {
-            g_print("\t\t [media_format] width = %d, height =%d", w, h);
+            if (media_format_get_video_info(fmt, NULL, &w, &h, NULL, NULL) == MEDIA_PACKET_ERROR_NONE)
+            {
+                g_print("\t\t [media_format] width = %d, height =%d", w, h);
+            }
+            else
+            {
+                g_print("media_format_get_video is failed...");
+            }
         }
-        else
+        else if (MEDIA_FORMAT_IS_AUDIO(fmt))
         {
-            g_print("media_format_get_video is failed...");
+             if (media_format_get_audio_info(fmt, NULL, &channel, &samplerate, &bit, &audio_avg_bps) == MEDIA_PACKET_ERROR_NONE)
+            {
+                g_print("\t\t [media_format] channel = %d, samplerate = %d, bit = %d, avg_bps = %d", channel, samplerate, bit, audio_avg_bps);
+            }
+            else
+            {
+                g_print("media_format_get_video is failed...");
+            }
         }
+
     }
     else
     {
@@ -479,10 +830,11 @@ static void _get_format(void)
 }
 
 
-static void _set_format(media_format_h fmt)
+static void _media_packet_set_format(media_format_h fmt)
 {
     if (media_packet_set_format(g_media_packet[0], fmt) == MEDIA_PACKET_ERROR_NONE)
     {
+        media_format_unref(fmt);
         g_print("media_packet_set_format is sucess!\n");
     }
     else
@@ -492,7 +844,7 @@ static void _set_format(media_format_h fmt)
 
 }
 
-static void _set_extra(void)
+static void _media_packet_set_extra(void)
 {
     char* extra = "extra";
 
@@ -507,7 +859,7 @@ static void _set_extra(void)
 
 }
 
-static void _get_extra(void)
+static void _media_packet_get_extra(void)
 {
     void* extra;
 
@@ -523,7 +875,7 @@ static void _get_extra(void)
 
 }
 
-static void _has_tbm_surface_buffer(void)
+static void _media_packet_has_tbm_surface_buffer(void)
 {
     bool has_tbm;
 
@@ -538,20 +890,19 @@ static void _has_tbm_surface_buffer(void)
     }
 }
 
-static void _format_get_video(void)
+static void _media_format_get_video_info(void)
 {
     media_format_mimetype_e mime;
-    int w;
-    int h;
-
-    media_packet_s* packet;
-    packet = (media_packet_s*)g_media_packet[0];
+    int w = 0;
+    int h = 0;
+    int avg_bps = 0;
+    int max_bps = 0;
 
-    if (media_format_get_video_info(packet->format, &mime, &w, &h, NULL, NULL) == MEDIA_FORMAT_ERROR_NONE)
+    if (media_format_get_video_info(g_media_format[0], &mime, &w, &h, &avg_bps, &max_bps) == MEDIA_FORMAT_ERROR_NONE)
     {
         g_print("media_format_get_video is sucess!\n");
         g_print("\t\t[media_format_get_video]mime:0x%x, width :%d, height :%d\n", mime, w, h);
-        g_print("packet format ref_count: %d", MEDIA_FORMAT_GET_REFCOUNT(packet->format));
+        g_print("packet format ref_count: %d", MEDIA_FORMAT_GET_REFCOUNT(g_media_format[0]));
     }
     else
     {
@@ -559,22 +910,19 @@ static void _format_get_video(void)
     }
 }
 
-static void _format_get_audio(void)
+static void _media_format_get_audio_info(void)
 {
     media_format_mimetype_e mime;
-    int channel;
-    int samplerate;
-    int bit;
-    int avg_bps;
+    int channel = 0;
+    int samplerate = 0;
+    int bit = 0;
+    int avg_bps = 0;
 
-    media_packet_s* packet;
-    packet = (media_packet_s*)g_media_packet[0];
-
-    if (media_format_get_audio_info(packet->format, &mime, &channel, &samplerate, &bit, &avg_bps)== MEDIA_FORMAT_ERROR_NONE)
+    if (media_format_get_audio_info(g_media_format[0], &mime, &channel, &samplerate, &bit, &avg_bps)== MEDIA_FORMAT_ERROR_NONE)
     {
         g_print("media_format_get_audio_info is sucess!\n");
-        g_print("\t\t[media_format_get_audio_info]mime:0x%x, channel :%d, samplerate :%d, bit: %d, avg_bps:%d \n", mime, channel, samplerate, bit, avg_bps);
-        g_print("packet format ref_count: %d", MEDIA_FORMAT_GET_REFCOUNT(packet->format));
+        g_print("\t\t[media_format_get_audio_info]mime:0x%x, channel :%d, samplerate :%d, bit: %d, avg_bps:%d, is_adts:%d \n", mime, channel, samplerate, bit, avg_bps);
+        g_print("packet format ref_count: %d", MEDIA_FORMAT_GET_REFCOUNT(g_media_format[0]));
     }
     else
     {
@@ -612,15 +960,54 @@ void reset_menu_state()
 void quit_program(void)
 {
     int i = 0;
+    int ref_count;
 
     for (i = 0; i < g_handle_num; i++)
     {
-        if(g_media_packet[i]!=NULL)
+        if(g_media_packet[i] != NULL)
         {
+            ref_count = MEDIA_FORMAT_GET_REFCOUNT(g_media_format[media_format_idx]);
             media_packet_destroy(g_media_packet[i]);
             g_media_packet[i] = NULL;
+            if (ref_count == 1)
+            {
+                g_media_format[media_format_idx] = NULL;
+                g_print("media_format_h[%d] is destroyed...\n", media_format_idx);
+            }
         }
     }
+
+
+    for (i = 0; i < MEDIA_FORMAT_MAX_HANDLE; i++)
+    {
+        if (g_media_format[i] != NULL)
+        {
+            int ref_count = MEDIA_FORMAT_GET_REFCOUNT(g_media_format[i]);
+            g_print("media_format_h[%d] ref_count:%d. excute media_format_unref().\n", i, ref_count);
+
+            if (ref_count == 1)
+            {
+                media_format_unref(g_media_format[i]);
+                g_media_format[i] = NULL;
+                g_print("media_format_h[%d] is destroyed...\n", i);
+            }
+            else
+            {
+
+                int j = 1;
+                for (j = 1; j <= ref_count; j++)
+                {
+                    g_print("(%d) media_format_unref\n", j);
+                    media_format_unref(g_media_format[i]);
+
+                }
+                g_media_format[i] = NULL;
+                g_print("media_format_h[%d] is destroyed...\n", i);
+            }
+
+        }
+    }
+
     elm_exit();
 }
 
@@ -628,118 +1015,191 @@ void _interpret_main_menu(char *cmd)
 {
     int len =  strlen(cmd);
     if (len == 1)
+    {
+        if (strncmp(cmd, "a", 1) == 0)
         {
-            if (strncmp(cmd, "a", 1) == 0)
-            {
-                _create_and_alloc();
-            }
-            else if (strncmp(cmd, "d", 1) == 0)
-            {
-                _destroy();
-            }
-            else if (strncmp(cmd, "b", 1) == 0)
-            {
-                _create_from_tbm_surface();
-            }
-            else if (strncmp(cmd, "c", 1) == 0)
-            {
-                _copy();
-            }
-            else if (strncmp(cmd, "q", 1) == 0)
-            {
-                quit_program();
-            }
+            _media_packet_create_alloc();
+        }
+        else if (strncmp(cmd, "d", 1) == 0)
+        {
+            _media_packet_destroy();
+        }
+        else if (strncmp(cmd, "b", 1) == 0)
+        {
+            _media_packet_create_from_tbm_surface();
+        }
+        else if (strncmp(cmd, "c", 1) == 0)
+        {
+            _media_packet_copy();
         }
+        else if (strncmp(cmd, "q", 1) == 0)
+        {
+            quit_program();
+        }
+    }
     else if (len == 2)
+    {
+        if (strncmp(cmd, "aa", 2) == 0)
         {
-            if (strncmp(cmd, "aa", 2) == 0)
-                {
-                    _create();
-                }
-            else if (strncmp(cmd, "ab", 2) == 0)
-                {
-                    _alloc();
-                }
-            else if (strncmp(cmd, "iv", 2) == 0)
-                {
-                    _is_video();
-                }
-            else if (strncmp(cmd, "ia", 2) == 0)
-                {
-                    _is_audio();
-                }
-            else if (strncmp(cmd, "ie", 2) == 0)
-                {
-                    _is_encoded();
-                }
-            else if (strncmp(cmd, "ir", 2) == 0)
-                {
-                    _is_raw();
-                }
-            else if (strncmp(cmd, "gd", 2) == 0)
-                {
-                    _get_duration();
-                }
-            else if (strncmp(cmd, "sd", 2) == 0)
-                {
-                    g_menu_state = CURRENT_STATUS_DURATION;
-                }
-            else if (strncmp(cmd, "gf", 2) == 0)
-                {
-                    _get_format();
-                }
-            else if (strncmp(cmd, "gs", 2) == 0)
-                {
-                    _get_size();
-                }
-            else if (strncmp(cmd, "sf", 2) == 0)
-                {
-                    g_menu_state = CURRENT_STATUS_SET_FORMAT;
-                }
-            else if (strncmp(cmd, "se", 2) == 0)
-                {
-                    _set_extra();
-                }
-            else if (strncmp(cmd, "ge", 2) == 0)
-                {
-                    _get_extra();
-                }
-            else if (strncmp(cmd, "ht", 2) == 0)
-                {
-                    _has_tbm_surface_buffer();
-                }
-
+            _media_packet_create();
+        }
+        else if (strncmp(cmd, "ab", 2) == 0)
+        {
+            _media_packet_alloc();
+        }
+        else if (strncmp(cmd, "iv", 2) == 0)
+        {
+            _media_packet_is_video();
+        }
+        else if (strncmp(cmd, "ia", 2) == 0)
+        {
+            _media_packet_is_audio();
+        }
+        else if (strncmp(cmd, "ie", 2) == 0)
+        {
+            _media_packet_is_encoded();
+        }
+        else if (strncmp(cmd, "ir", 2) == 0)
+        {
+            _media_packet_is_raw();
+        }
+        else if (strncmp(cmd, "gd", 2) == 0)
+        {
+            _media_packet_get_duration();
+        }
+        else if (strncmp(cmd, "sd", 2) == 0)
+        {
+            g_menu_state = CURRENT_STATUS_DURATION;
+        }
+        else if (strncmp(cmd, "gf", 2) == 0)
+        {
+            _media_packet_get_format();
         }
+        else if (strncmp(cmd, "gs", 2) == 0)
+        {
+            _media_packet_get_buffer_size();
+        }
+        else if (strncmp(cmd, "sf", 2) == 0)
+        {
+            g_menu_state = CURRENT_STATUS_PACKET_SET_FORMAT;
+        }
+        else if (strncmp(cmd, "se", 2) == 0)
+        {
+            _media_packet_set_extra();
+        }
+        else if (strncmp(cmd, "ge", 2) == 0)
+        {
+            _media_packet_get_extra();
+        }
+        else if (strncmp(cmd, "ht", 2) == 0)
+        {
+            _media_packet_has_tbm_surface_buffer();
+        }
+        else if (strncmp(cmd, "cf", 2) == 0)
+        {
+            _media_format_create();
+        }
+
+    }
     else if (len == 3)
+    {
+        if (strncmp(cmd, "gbp", 3) == 0)
         {
-            if (strncmp(cmd, "gbp", 3) == 0)
-                {
-                    _get_buffer_ptr();
-                }
-            else if (strncmp(cmd, "gts", 3) == 0)
-                {
-                    _get_tbm_surface();
-                }
-            else if (strncmp(cmd, "fes", 3) == 0)
-                {
-                    _create_format_480_640_es();
-                }
-            else if (strncmp(cmd, "fgv", 3) == 0)
-                {
-                    _format_get_video();
-                }
+            _media_packet_get_buffer_data_ptr();
+        }
+        else if (strncmp(cmd, "gts", 3) == 0)
+        {
+            _media_packet_get_tbm_surface();
+        }
+        else if (strncmp(cmd, "fgv", 3) == 0)
+        {
+            _media_format_get_video_info();
+        }
+        else if (strncmp(cmd, "fga", 3) == 0)
+        {
+            _media_format_get_audio_info();
         }
+        else if (strncmp(cmd, "svm", 3) == 0)
+        {
+            g_menu_state = CURRENT_STATUS_FORMAT_SET_VIDEO_MIME;
+        }
+        else if (strncmp(cmd, "svw", 3) == 0)
+        {
+            g_menu_state = CURRENT_STATUS_FORMAT_SET_VIDEO_WIDTH;
+        }
+        else if (strncmp(cmd, "svh", 3) == 0)
+        {
+            g_menu_state = CURRENT_STATUS_FORMAT_SET_VIDEO_HEIGHT;
+        }
+        else if (strncmp(cmd, "sam", 3) == 0)
+        {
+            g_menu_state = CURRENT_STATUS_FORMAT_SET_AUDIO_MIME;
+        }
+        else if (strncmp(cmd, "sac", 3) == 0)
+        {
+            g_menu_state = CURRENT_STATUS_FORMAT_SET_AUDIO_CHANNEL;
+        }
+        else if (strncmp(cmd, "sas", 3) == 0)
+        {
+            g_menu_state = CURRENT_STATUS_FORMAT_SET_AUDIO_SAMPLERATE;
+        }
+        else if (strncmp(cmd, "sab", 3) == 0)
+        {
+            g_menu_state = CURRENT_STATUS_FORMAT_SET_AUDIO_BIT;
+        }
+        else if (strncmp(cmd, "gnp", 3) == 0)
+        {
+            _media_packet_get_number_of_video_planes();
+        }
+        else if (strncmp(cmd, "gsw", 3) == 0)
+        {
+            _media_packet_get_video_stride_width();
+        }
+        else if (strncmp(cmd, "gsh", 3) == 0)
+        {
+            _media_packet_get_video_stride_height();
+        }
+        else if (strncmp(cmd, "gpp", 3) == 0)
+        {
+            _media_packet_get_video_plane_data_ptr();
+        }
+        else if (strncmp(cmd, "scd", 3) == 0)
+        {
+            _media_packet_set_codec_data();
+        }
+        else if (strncmp(cmd, "gcd", 3) == 0)
+        {
+            _media_packet_get_codec_data();
+        }
+
+    }
     else if (len == 4)
+    {
+        if (strncmp(cmd, "fraw", 4) == 0)
         {
-            if (strncmp(cmd, "fraw", 4) == 0)
-                {
-                    _create_format_raw();
-                }
-            else if (strncmp(cmd, "fes2", 4) == 0)
-                {
-                    _create_format_320_240_es();
-                }
+            _create_format_raw();
+        }
+        else if (strncmp(cmd, "fes2", 4) == 0)
+        {
+            _create_format_320_240_es();
+        }
+        else if (strncmp(cmd, "svab", 4) == 0)
+        {
+            g_menu_state = CURRENT_STATUS_FORMAT_SET_VIDEO_AVG_BPS;
+        }
+        else if (strncmp(cmd, "svmb", 4) == 0)
+        {
+            g_menu_state = CURRENT_STATUS_FORMAT_SET_VIDEO_MAX_BPS;
+        }
+        else if (strncmp(cmd, "saab", 4) == 0)
+        {
+            g_menu_state = CURRENT_STATUS_FORMAT_SET_AUDIO_AVG_BPS;
+        }
+        else if (strncmp(cmd, "saat", 4) == 0)
+        {
+            g_menu_state = CURRENT_STATUS_FORMAT_SET_AUDIO_AAC_TYPE;
         }
+    }
 
 
 }
@@ -747,25 +1207,74 @@ void _interpret_main_menu(char *cmd)
 static void displaymenu(void)
 {
     if (g_menu_state == CURRENT_STATUS_MAINMENU)
-        {
-            display_sub_basic();
-        }
-    else if (g_menu_state == CURRENT_STATUS_SET_FORMAT)
-        {
-            g_print("*** choose format.\n");
-            g_print("0. 640x480 , MEDIA_FORMAT_H264_HP\n");
-            g_print("1. 320x240 , MEDIA_FORMAT_H264_HP\n");
-            g_print("2. 128x128 , MEDIA_FORMAT_RGB888\n");
-        }
+    {
+        display_sub_basic();
+    }
+    else if (g_menu_state == CURRENT_STATUS_PACKET_SET_FORMAT)
+    {
+        g_print("*** choose format.\n");
+        g_print("1. 320x240 , MEDIA_FORMAT_H264_HP\n");
+        g_print("2. 128x128 , MEDIA_FORMAT_I420\n");
+    }
     else if (g_menu_state == CURRENT_STATUS_DURATION)
-        {
-            g_print("*** input duration \n");
-        }
+    {
+        g_print("*** input duration: \n");
+    }
+    else if (g_menu_state == CURRENT_STATUS_FORMAT_SET_VIDEO_MIME)
+    {
+        g_print("choose video media format mime type\n");
+        g_print("0. MEDIA_FORMAT_H264_HP\n");
+        g_print("1. MEDIA_FORMAT_RGB888\n");
+        g_print("2. MEDIA_FORMAT_I420\n");
+    }
+    else if (g_menu_state == CURRENT_STATUS_FORMAT_SET_VIDEO_WIDTH)
+    {
+        g_print("input video width:\n");
+    }
+    else if (g_menu_state == CURRENT_STATUS_FORMAT_SET_VIDEO_HEIGHT)
+    {
+        g_print("input video height:\n");
+    }
+    else if (g_menu_state == CURRENT_STATUS_FORMAT_SET_VIDEO_AVG_BPS)
+    {
+        g_print("input video avg_bps:\n");
+    }
+    else if (g_menu_state == CURRENT_STATUS_FORMAT_SET_VIDEO_MAX_BPS)
+    {
+        g_print("input video max_bps:\n");
+    }
+    else if (g_menu_state == CURRENT_STATUS_FORMAT_SET_AUDIO_MIME)
+    {
+        g_print("choose audio media format mime type\n");
+        g_print("0. MEDIA_FORMAT_AMR\n");
+        g_print("1. MEDIA_FORMAT_PCM\n");
+        g_print("2. MEDIA_FORMAT_AAC\n");
+    }
+    else if (g_menu_state == CURRENT_STATUS_FORMAT_SET_AUDIO_CHANNEL)
+    {
+        g_print("input audio channel:\n");
+    }
+    else if (g_menu_state == CURRENT_STATUS_FORMAT_SET_AUDIO_SAMPLERATE)
+    {
+       g_print("input audio sample rate:\n");
+    }
+    else if (g_menu_state == CURRENT_STATUS_FORMAT_SET_AUDIO_BIT)
+    {
+        g_print("input audio bit:\n");
+    }
+    else if (g_menu_state == CURRENT_STATUS_FORMAT_SET_AUDIO_AVG_BPS)
+    {
+        g_print("input audio average bps:\n");
+    }
+    else if (g_menu_state == CURRENT_STATUS_FORMAT_SET_AUDIO_AAC_TYPE)
+    {
+        g_print("input audio aac type (0 or 1):\n");
+    }
     else
-        {
-            g_print("*** unknown status.\n");
-            quit_program();
-        }
+    {
+        g_print("*** unknown status.\n");
+        quit_program();
+    }
     g_print(" >>> ");
 }
 
@@ -785,42 +1294,31 @@ static void interpret (char *cmd)
                 _interpret_main_menu(cmd);
             }
             break;
-        case CURRENT_STATUS_SET_FORMAT:
+        case CURRENT_STATUS_PACKET_SET_FORMAT:
             {
                 int num = atoi(cmd);
                 switch (num)
                  {
-                    case 0:
-                        if (format[0])
-                        {
-                            _set_format(format[0]);
-                        }
-                        else
-                        {
-                            _create_format_480_640_es();
-                            _set_format(format[0]);
-                        }
-                        break;
                     case 1:
-                        if(format[1])
+                        if(g_media_format[1])
                         {
-                            _set_format(format[1]);
+                            _media_packet_set_format(g_media_format[1]);
                         }
                         else
                         {
                             _create_format_320_240_es();
-                            _set_format(format[1]);
+                            _media_packet_set_format(g_media_format[1]);
                         }
                         break;
                     case 2:
-                        if(format[2])
+                        if(g_media_format[2])
                         {
-                            _set_format(format[2]);
+                            _media_packet_set_format(g_media_format[2]);
                         }
                         else
                         {
                             _create_format_raw();
-                            _set_format(format[2]);
+                            _media_packet_set_format(g_media_format[2]);
                         }
                         break;
                     default:
@@ -831,10 +1329,87 @@ static void interpret (char *cmd)
                 reset_menu_state();
             }
             break;
+        case CURRENT_STATUS_FORMAT_SET_VIDEO_MIME:
+            {
+                int video_mime_idx = atoi(cmd);
+                _media_format_set_video_mime(video_mime_idx);
+                reset_menu_state();
+            }
+            break;
+        case CURRENT_STATUS_FORMAT_SET_VIDEO_WIDTH:
+            {
+                int width = atoi(cmd);
+                _media_format_set_video_width(width);
+                reset_menu_state();
+            }
+            break;
+        case CURRENT_STATUS_FORMAT_SET_VIDEO_HEIGHT:
+            {
+                int height = atoi(cmd);
+                _media_format_set_video_height(height);
+                reset_menu_state();
+            }
+            break;
+        case CURRENT_STATUS_FORMAT_SET_VIDEO_AVG_BPS:
+            {
+                int video_avg_bps = atoi(cmd);
+                _media_format_set_video_avg_bps(video_avg_bps);
+                reset_menu_state();
+            }
+            break;
+        case CURRENT_STATUS_FORMAT_SET_VIDEO_MAX_BPS:
+            {
+                int max_bps = atoi(cmd);
+                _media_format_set_video_max_bps(max_bps);
+                reset_menu_state();
+            }
+            break;
+        case CURRENT_STATUS_FORMAT_SET_AUDIO_MIME:
+            {
+                int audio_mime_idx = atoi(cmd);
+                _media_format_set_audio_mime(audio_mime_idx);
+                reset_menu_state();
+            }
+            break;
+        case CURRENT_STATUS_FORMAT_SET_AUDIO_CHANNEL:
+            {
+                int channel = atoi(cmd);
+                _media_format_set_audio_channel(channel);
+                reset_menu_state();
+            }
+            break;
+        case CURRENT_STATUS_FORMAT_SET_AUDIO_SAMPLERATE:
+            {
+                int samplerate = atoi(cmd);
+                _media_format_set_audio_samplerate(samplerate);
+                reset_menu_state();
+            }
+            break;
+        case CURRENT_STATUS_FORMAT_SET_AUDIO_BIT:
+            {
+                int bit = atoi(cmd);
+                _media_format_set_audio_bit(bit);
+                reset_menu_state();
+            }
+            break;
+        case CURRENT_STATUS_FORMAT_SET_AUDIO_AVG_BPS:
+            {
+                int audio_avg_bps = atoi(cmd);
+                _media_format_set_audio_avg_bps(audio_avg_bps);
+                reset_menu_state();
+            }
+            break;
+        case CURRENT_STATUS_FORMAT_SET_AUDIO_AAC_TYPE:
+            {
+                bool is_ats = atoi(cmd);
+                _media_format_set_audio_aac_type(is_ats);
+                reset_menu_state();
+            }
+            break;
         case CURRENT_STATUS_DURATION:
             {
                 uint64_t duration = atoi(cmd);
-                _set_duration(duration);
+                _media_packet_set_duration(duration);
                 reset_menu_state();
             }
     }
@@ -848,38 +1423,67 @@ void display_sub_basic()
     g_print("=========================================================================================\n");
     g_print("                                    media tool test\n");
     g_print("-----------------------------------------------------------------------------------------\n");
-    g_print("fes. create format for es 480x640\t\t");
-    g_print("fes2. create format for es 320x240\t\t");
-    g_print("fraw. create format for raw 128x128 \t\t");
+    g_print(" *** How to use ***\n");
+    g_print(" : You can create 1 media_format_h handle by 'cf' and 1 media_packet_handle \n");
+    g_print(" : ex) cf > svm > svw > svh > svab > svmb >fgv > > a > iv > ir ...> d\n");
+    g_print(" : media_format_create is set to 'media_format_h[0]' \n");
+    g_print(" : media_packet_create_alloc & media_packet_create use 'media_format_h[0]' \n");
+    g_print(" : media_packet_create_from_tbm_surface use 'media_format_h[2]' \n");
     g_print("\n");
-    g_print("a. Create_and _Alloc \t");
-    g_print("aa. Create \t");
-    g_print("ab. Alloc \t");
-    g_print("c. Copy \t");
-    g_print("b. Create from tbm_surface \n");
-    g_print("iv. is_video \t\t");
-    g_print("ia. is_audio \t\t");
-    g_print("ie. is_encoded \t\t");
-    g_print("ir. is_raw \t\t");
-    g_print("ht. has_tbm_surface \t\t");
+    g_print("cf. media_format_create\t\t");
     g_print("\n");
-    g_print("sd. set duration \t\t");
-    g_print("sf. set format \t\t");
-    g_print("se. set extra \t\t");
+    g_print("svm. media_format_set_video_mime\t");
+    g_print("svw. media_format_set_video_width\t");
+    g_print("svh. media_format_set_video_height\t");
+    g_print("svab. media_format_set_video_avg_bps\t");
+    g_print("svmb. media_format_set_video_max_bps\t");
     g_print("\n");
-    g_print("gd. get duration \t\t");
-    g_print("gbp. get buffer data ptr \t\t");
-    g_print("gts. get tbm surface \t\t");
-    g_print("gf. get format \t\t");
-    g_print("ge. get extra \t\t");
+    g_print("sam. media_format_set_audio_mime\t");
+    g_print("sac. media_format_set_audio_channel\t");
+    g_print("sas. media_format_set_audio_samplerate\t");
+    g_print("sab. media_format_set_audio_bit \t");
+    g_print("saab. media_format_set_audio_avg_bps\t");
+    g_print("saat. media_format_set_audio_aac_type\t");
     g_print("\n");
-    g_print("fgv. media_format_get_video_info \t\t");
+    g_print("fgv. media_format_get_video_info \t");
     g_print("fga. media_format_get_audio_info \t\t");
     g_print("\n");
-    g_print("gs. get size\t\t");
     g_print("\n");
-    g_print("d. Destroy \n");
-    g_print("q. quit test suite");
+    g_print("a. media_packet_create_alloc(+media_format_unref)  \t");
+    g_print("aa. media_packet_create(+media_format_unref) \t");
+    g_print("b. media_packet_create_from_tbm_surface(+media_format_unref) \n");
+    g_print("ab. media_packet_alloc \t\t");
+    g_print("c. media_packet_copy  \t");
+    g_print("\n");
+    g_print("\n");
+    g_print("iv. media_packet_is_video \t");
+    g_print("ia. media_packet_is_audio \t");
+    g_print("ie. media_packet_is_encoded \t");
+    g_print("ir. media_packet_is_raw \t");
+    g_print("ht. media_packet_has_tbm_surface_buffer \t");
+    g_print("\n");
+    g_print("sd. media_packet_set_duration \t");
+    g_print("sf. media_packet_set_format(+media_format_unref) \t");
+    g_print("se. media_packet_set_extra \t");
+    g_print("\n");
+    g_print("gd. media_packet_get_duration \t");
+    g_print("gbp. media_packet_get_buffer_data_ptr \t");
+    g_print("gts. media_packet_get_tbm_surface \t");
+    g_print("gf. media_packet_get_format \t");
+    g_print("ge. media_packet_get_extra \t");
+    g_print("\n");
+    g_print("gs. media_packet_get_buffer_size\t");
+    g_print("\n");
+    g_print("gnp. media_packet_get_number_of_video_planes\t");
+    g_print("gsw. media_packet_get_video_stride_width\t");
+    g_print("gsh. media_packet_get_video_stride_height\t");
+    g_print("gpp. media_packet_get_video_plane_data_ptr\t");
+    g_print("\n");
+    g_print("scd. media_packet_set_codec_data\t");
+    g_print("gcd. media_packet_get_codec_data\t");
+    g_print("\n");
+    g_print("d. media_packet_destroy \n");
+    g_print("q. quit test suite(if exist alive media_format, do media_format_unref)");
     g_print("\n");
     g_print("=========================================================================================\n");
 }