Add APIs for media_packet_pool 91/64891/18 accepted/tizen/common/20160505.140913 accepted/tizen/ivi/20160506.035828 accepted/tizen/mobile/20160506.035307 accepted/tizen/tv/20160506.035606 accepted/tizen/wearable/20160506.035715 submit/tizen/20160504.093918
authorSejun Park <sejun79.park@samsung.com>
Wed, 6 Apr 2016 05:17:08 +0000 (14:17 +0900)
committerSejun Park <sejun79.park@samsung.com>
Tue, 3 May 2016 05:07:53 +0000 (14:07 +0900)
Change-Id: I0f6d1c7d6c7e69da7e711d953aa695017a5daf3b

CMakeLists.txt [changed mode: 0644->0755]
include/media_format.h
include/media_packet.h
include/media_packet_pool.h [new file with mode: 0755]
include/media_packet_pool_private.h [new file with mode: 0755]
include/media_packet_private.h
src/media_packet.c
src/media_packet_pool.c [new file with mode: 0755]
test/media_packet_test.c

old mode 100644 (file)
new mode 100755 (executable)
index d5916f4b945242087bc08fac72062e85d60ec8e6..9d05b3827f61665f344eee4baa50ee6a4f98e52a 100755 (executable)
@@ -37,13 +37,13 @@ extern "C" {
 
 /**
  * @brief Media Format handle type.
-  * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 typedef struct media_format_s *media_format_h;
 
 /**
  * @brief Enumerations of  media format error.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 typedef enum {
        MEDIA_FORMAT_ERROR_NONE = TIZEN_ERROR_NONE,                                     /**< Successful */
@@ -55,7 +55,7 @@ typedef enum {
 
 /**
  * @brief Enumeration for media format type.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 typedef enum {
        MEDIA_FORMAT_NONE = 0x00000000,                                  /**< media format type is NONE */
@@ -68,7 +68,7 @@ typedef enum {
 
 /**
  * @brief Enumeration for media format data type.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 typedef enum {
        MEDIA_FORMAT_ENCODED = 0x10000000,                      /**< media format data type is encoded type */
@@ -77,28 +77,28 @@ typedef enum {
 
 /**
  * @brief Enumeration for media format MIME type.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 typedef enum {
        /* 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,  indicates MEDIA_FORMAT_AMR_NB (Since 2.4) */
-       MEDIA_FORMAT_AMR_NB = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1040),                /**< media format mime type is AMR_NB,  AUDIO , (Since 2.4) */
-       MEDIA_FORMAT_AMR_WB = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1041),                /**< media format mime type is AMR_WB,  AUDIO, (Since 2.4) */
+       MEDIA_FORMAT_AMR = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1040),                   /**< media format mime type is AMR,  AUDIO,  indicates MEDIA_FORMAT_AMR_NB (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif) */
+       MEDIA_FORMAT_AMR_NB = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1040),                /**< media format mime type is AMR_NB,  AUDIO , (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif) */
+       MEDIA_FORMAT_AMR_WB = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1041),                /**< media format mime type is AMR_WB,  AUDIO, (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif) */
        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, indicates MEDIA_FORMAT_AAC_LC (Since 2.4) */
-       MEDIA_FORMAT_AAC_LC = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1060),                /**< media format mime type is AAC_LC,  AUDIO, (Since 2.4) */
-       MEDIA_FORMAT_AAC_HE = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1061),                /**< media format mime type is AAC_HE,  AUDIO, (Since 2.4) */
-       MEDIA_FORMAT_AAC_HE_PS = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1062),     /**< media format mime type is AAC_HE_PS,  AUDIO, (Since 2.4) */
+       MEDIA_FORMAT_AAC = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1060),                   /**< media format mime type is AAC,  AUDIO, indicates MEDIA_FORMAT_AAC_LC (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif) */
+       MEDIA_FORMAT_AAC_LC = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1060),                /**< media format mime type is AAC_LC,  AUDIO, (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif) */
+       MEDIA_FORMAT_AAC_HE = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1061),                /**< media format mime type is AAC_HE,  AUDIO, (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif) */
+       MEDIA_FORMAT_AAC_HE_PS = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1062),     /**< media format mime type is AAC_HE_PS,  AUDIO, (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif) */
        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 2.4) */
-       MEDIA_FORMAT_FLAC = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1090),                  /**< media format mime type is FLAC,  AUDIO, (Since 2.4) */
-       MEDIA_FORMAT_WMAV1 = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x10A0),                 /**< media format mime type is WMAV1,  AUDIO, (Since 2.4) */
-       MEDIA_FORMAT_WMAV2 = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x10A1),                 /**< media format mime type is WMAV2,  AUDIO, (Since 2.4) */
-       MEDIA_FORMAT_WMAPRO = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x10A2),                /**< media format mime type is WMAVPRO,  AUDIO, (Since 2.4) */
-       MEDIA_FORMAT_WMALSL = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x10A3),                /**< media format mime type is WMAVLSL,  AUDIO, (Since 2.4) */
+       MEDIA_FORMAT_VORBIS = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1080),                /**< media format mime type is VORBIS,  AUDIO, (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif) */
+       MEDIA_FORMAT_FLAC = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1090),                  /**< media format mime type is FLAC,  AUDIO, (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif) */
+       MEDIA_FORMAT_WMAV1 = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x10A0),                 /**< media format mime type is WMAV1,  AUDIO, (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif) */
+       MEDIA_FORMAT_WMAV2 = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x10A1),                 /**< media format mime type is WMAV2,  AUDIO, (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif) */
+       MEDIA_FORMAT_WMAPRO = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x10A2),                /**< media format mime type is WMAVPRO,  AUDIO, (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif) */
+       MEDIA_FORMAT_WMALSL = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x10A3),                /**< media format mime type is WMAVLSL,  AUDIO, (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif) */
 
        MEDIA_FORMAT_PCM = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_RAW | 0x1510),                       /**< media format mime type is PCM, AUDIO, indicates MEDIA_FORMAT_PCM_S16LE (Since 3.0) */
        MEDIA_FORMAT_PCM_S16LE = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_RAW | 0x1510),                 /**< media format mime type is PCM signed 16-bit little-endian, AUDIO, (Since 3.0) */
@@ -140,12 +140,12 @@ typedef enum {
        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 2.4) */
+       MEDIA_FORMAT_HEVC = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2080),                  /**< media format mime type is HEVC, VIDEO, (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif) */
        MEDIA_FORMAT_HEVC_MP = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2081),              /**< media format mime type is HEVC Main Profile, VIDEO, (Since 3.0) */
        MEDIA_FORMAT_HEVC_M10P = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2082),                  /**< media format mime type is HEVC Main10 Profile, VIDEO, (Since 3.0) */
-       MEDIA_FORMAT_VP8 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2090),                   /**< media format mime type is VP8, VIDEO, (Since 2.4) */
-       MEDIA_FORMAT_VP9 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x20A0),                   /**< media format mime type is VP9, VIDEO, (Since 2.4) */
-       MEDIA_FORMAT_VC1 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x20B0),                   /**< media format mime type is VC1, VIDEO, (Since 2.4) */
+       MEDIA_FORMAT_VP8 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2090),                   /**< media format mime type is VP8, VIDEO, (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif) */
+       MEDIA_FORMAT_VP9 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x20A0),                   /**< media format mime type is VP9, VIDEO, (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif) */
+       MEDIA_FORMAT_VC1 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x20B0),                   /**< media format mime type is VC1, VIDEO, (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif) */
 
        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 */
@@ -177,7 +177,7 @@ typedef enum {
        MEDIA_FORMAT_CONTAINER_AAC_ADTS = (MEDIA_FORMAT_CONTAINER | 0x4030),                       /**< media format mime type is AAC_ADTS container, AUDIO, (Since 3.0) */
        MEDIA_FORMAT_CONTAINER_AAC_ADIF = (MEDIA_FORMAT_CONTAINER | 0x4031),                       /**< media format mime type is AAC_ADIF container, AUDIO, (Since 3.0) */
 
-       MEDIA_FORMAT_NATIVE_VIDEO = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x7000),      /**< media format mime type is HW dependent, VIDEO, (Since 2.4) */
+       MEDIA_FORMAT_NATIVE_VIDEO = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x7000),      /**< media format mime type is HW dependent, VIDEO, (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif) */
        /* Text */
        MEDIA_FORMAT_TEXT_MP4 = (MEDIA_FORMAT_TEXT | MEDIA_FORMAT_ENCODED | 0x8010),            /**< media format mime type is MP4, TEXT, (Since 3.0) */
        MEDIA_FORMAT_TEXT_3GP = (MEDIA_FORMAT_TEXT | MEDIA_FORMAT_ENCODED | 0x8020),            /**< media format mime type is 3GP, TEXT, (Since 3.0) */
@@ -187,7 +187,7 @@ typedef enum {
 
 /**
  * @brief Enumeration for media color model.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 typedef enum {
        MEDIA_COLOR_MODEL_NONE,            /**< media format color model is NONE */
@@ -219,7 +219,7 @@ typedef enum {
 
 /**
  * @brief Creates a media format.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @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
@@ -282,7 +282,7 @@ int media_format_get_text_info(media_format_h fmt, media_format_mimetype_e * mim
 
 /**
  * @brief Gets video information of media format.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @details   returns mimetype, width, height, average bps, max bps of this media format.
  * @param[in] fmt media_format_h to get video information
  * @param[out] mimetype media_format_mimetype_e , ex) MEDIA_FORMAT_H264_HP
@@ -306,7 +306,7 @@ int media_format_get_video_info(media_format_h fmt, media_format_mimetype_e * mi
 
 /**
  * @brief Gets audio information of media format.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @details   returns mimetype, channels, height, samplerate bps, max bps of this media format.
  * @param[in] fmt media_format_h to get audio information
  * @param[out] mimetype media_format_mimetype_e , ex) MEDIA_FORMAT_PCM
@@ -330,7 +330,7 @@ int media_format_get_audio_info(media_format_h fmt, media_format_mimetype_e * mi
 
 /**
  * @brief Gets audio aac type of media format.
- * @since_tizen 2.4
+ * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
  * @param[in] fmt media_format_h to get audio information
  * @param[out] is_adts aac adts flag of the audio
  *
@@ -417,7 +417,7 @@ int media_format_set_text_type(media_format_h fmt, media_format_text_type_e type
 
 /**
  * @brief Sets video MIME type of media format.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @param[in] fmt media_format_h to set
  * @param[in] mimetype media_format_mimetype_e , ex) MEDIA_FORMAT_H264_HP
  *
@@ -432,7 +432,7 @@ int media_format_set_video_mime(media_format_h fmt, media_format_mimetype_e mime
 
 /**
  * @brief Sets video width of media format.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @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()
@@ -448,7 +448,7 @@ int media_format_set_video_width(media_format_h fmt, int width);
 
 /**
  * @brief Sets video height of media format.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @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()
@@ -464,7 +464,7 @@ int media_format_set_video_height(media_format_h fmt, int height);
 
 /**
  * @brief Sets video avg_bps of media format.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @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()
@@ -480,8 +480,7 @@ int media_format_set_video_avg_bps(media_format_h fmt, int avg_bps);
 
 /**
  * @brief Sets video max_bps of media format.
- * @since_tizen 2.3
-
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @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()
@@ -512,7 +511,7 @@ 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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @param[in] fmt media_format_h to set audio information
  * @param[in] mimetype media_format_mimetype_e , ex) MEDIA_FORMAT_PCM
  *
@@ -527,7 +526,7 @@ int media_format_set_audio_mime(media_format_h fmt, media_format_mimetype_e mime
 
 /**
  * @brief Sets audio channel of media format.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @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()
@@ -543,7 +542,7 @@ int media_format_set_audio_channel(media_format_h fmt, int channel);
 
 /**
  * @brief Sets audio samplerate of media format.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @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()
@@ -559,7 +558,7 @@ int media_format_set_audio_samplerate(media_format_h fmt, int samplerate);
 
  /**
  * @brief Sets audio bit of media format.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @details   Sets audio bit resolution of this media format
  * @param[in] fmt media_format_h to set
  * @param[in] bit bit of the audio
@@ -576,7 +575,7 @@ int media_format_set_audio_bit(media_format_h fmt, int bit);
 
  /**
  * @brief Sets audio avg_bps of media format.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @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()
@@ -592,7 +591,7 @@ 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
+ * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
  * @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
@@ -625,7 +624,7 @@ int media_format_set_audio_aac_header_type(media_format_h fmt, media_format_aac_
 
 /**
  * @brief Increase reference count of media_format_h object.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @details    increase ref_count of media_format_h
  * @param[in] fmt exist media_format_h
  *
@@ -641,7 +640,7 @@ int media_format_ref(media_format_h fmt);
 
 /**
  * @brief Decrease reference count of media_format_h object.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @param[in] fmt exist media_format_h
  *
  * @return @c 0 on success,
@@ -656,7 +655,7 @@ int media_format_unref(media_format_h fmt);
 
 /**
  * @brief Check whether the media_format_h is writable or not.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @param[in] fmt exist media_format_h
  * @param[out] is_writable if ref_count is 1, return true. if not, return false
  *
@@ -671,7 +670,7 @@ int media_format_is_writable(media_format_h fmt, bool * is_writable);
 
  /**
  * @brief Returns a writable copy of media_format_h.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @details If there is only one reference count on fmt, the caller must be the owner,
  *              and so this function will return the object unchanged.
  *              while, if there is more than one reference count on the object, a new object will be returned.
index 399f4273147269e037e21b90c4a86949f78f6465..85a6c7bd5b001648ac8cbf3ebdd69cb8631c4865 100755 (executable)
@@ -29,6 +29,9 @@
 extern "C" {
 #endif
 
+#ifndef TIZEN_ERROR_MEDIA_TOOL
+#define TIZEN_ERROR_MEDIA_TOOL  -0x000033333
+#endif
 /**
  * @file media_packet.h
  * @brief This file contains the capi media tool API.
@@ -41,13 +44,13 @@ extern "C" {
 
 /**
  * @brief  The Media Packet handle.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 typedef struct media_packet_s *media_packet_h;
 
 /**
  * @brief Enumeration for media packet error.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 typedef enum {
        MEDIA_PACKET_ERROR_NONE = TIZEN_ERROR_NONE,                                                                                     /**< Successful */
@@ -55,11 +58,12 @@ typedef enum {
        MEDIA_PACKET_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,                           /**< Invalid parameter */
        MEDIA_PACKET_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION,                           /**< Invalid operation */
        MEDIA_PACKET_ERROR_FILE_NO_SPACE_ON_DEVICE = TIZEN_ERROR_FILE_NO_SPACE_ON_DEVICE,       /**< No space left on device */
+       MEDIA_PACKET_ERROR_NO_AVAILABLE_PACKET = TIZEN_ERROR_MEDIA_TOOL | 0x01,                         /**< No Available packet, (Since 3.0) */
 } media_packet_error_e;
 
 /**
  * @brief Enumeration for media buffer flag.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 typedef enum {
        MEDIA_PACKET_CODEC_CONFIG = 0x1,   /**< The buffer marked as such contains codec initialization/codec specific data instead of media data */
@@ -69,7 +73,7 @@ typedef enum {
 
 /**
  * @brief Enumeration for the return values of media packet finalize call back functions.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @see media_packet_finalize_cb()
  */
 typedef enum _finalize_cb_ret {
@@ -81,7 +85,7 @@ typedef enum _finalize_cb_ret {
  * @brief   Called when the media packet is destroyed.
  * @details It will be invoked when media_packet_destroy() is called.
  *
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in] packet        The media packet handle
  * @param[in] error_code    The error code of #media_packet_error_e
@@ -104,7 +108,7 @@ typedef int (*media_packet_finalize_cb) (media_packet_h packet, int error_code,
  * @brief    Creates a media packet handle and allocates buffer.
  * @details  The buffer will be allocated to heap or tbm_surface.
  *
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @remarks The @c packet must be released by using media_packet_destroy().
  * @param[in]  fmt       The allocated #media_format_h by caller
@@ -161,7 +165,7 @@ int media_packet_create_alloc(media_format_h fmt, media_packet_finalize_cb fcb,
  * @brief    Creates a media packet handle.
  * @details  It creates only media packet handle without allocated buffer.
  *
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @remarks The @c packet must be released by using media_packet_destroy().
  * @param[in] fmt       The allocated #media_format_h by caller
@@ -218,7 +222,7 @@ int media_packet_create(media_format_h fmt, media_packet_finalize_cb fcb, void *
  * @brief    Copies a media packet handle.
  * @details  It re-creates only media packet handle with exist media packet handle.
  *
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @remarks The @c new_packet must be released by using media_packet_destroy().
  * @param[in]   org_packet   The existing media packet handle
@@ -242,7 +246,7 @@ int media_packet_copy(media_packet_h org_packet, media_packet_finalize_cb fcb, v
  * @brief    Allocates buffer with media packet handle.
  * @details  Before using media_packet_alloc(), media packet handle must be exist.
  *
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in] packet   The existing media packet handle
  *
@@ -261,7 +265,7 @@ int media_packet_alloc(media_packet_h packet);
 /**
  * @brief    Creates media packet handle and allocates buffer with #tbm_surface_h.
  *
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @remarks The @c packet must be released by using media_packet_destroy().
  * @param[in]   fmt       The allocated #media_format_h by caller
@@ -319,7 +323,7 @@ int media_packet_create_from_tbm_surface(media_format_h fmt, tbm_surface_h surfa
  * @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
+ * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
  *
  * @remarks The @c packet must be released by using media_packet_destroy().
  * @param[in]   fmt       The allocated #media_format_h by caller
@@ -375,7 +379,7 @@ int media_packet_create_from_external_memory(media_format_h fmt, void *mem_ptr,
 
 /**
  * @brief Gets #media_format_h of media packet
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in]  packet   The media packet handle
  * @param[out] fmt      The media format of media packet
@@ -406,7 +410,7 @@ int media_packet_get_format(media_packet_h packet, media_format_h * fmt);
 
 /**
  * @brief Sets #media_format_h of media packet
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in] packet   The media packet handle
  * @param[in] fmt      The #media_format_h to set
@@ -437,7 +441,7 @@ int media_packet_set_format(media_packet_h packet, media_format_h fmt);
 
 /**
  * @brief Sets PTS of media packet.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in] packet   The media packet handle
  * @param[in] pts      The PTS value to set
@@ -452,7 +456,7 @@ int media_packet_set_pts(media_packet_h packet, uint64_t pts);
 
 /**
  * @brief Sets DTS of media packet handle.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in]  packet   The media packet handle
  * @param[in]  dts      The DTS value to set
@@ -467,7 +471,7 @@ int media_packet_set_dts(media_packet_h packet, uint64_t dts);
 
 /**
  * @brief Sets PTS of media packet.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in] packet    The media packet handle
  * @param[in] duration  The duration value to set
@@ -482,7 +486,7 @@ int media_packet_set_duration(media_packet_h packet, uint64_t duration);
 
 /**
  * @brief Sets buffer size of media packet.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in]  packet   The media packet handle
  * @param[out] size     The buffer size value to set
@@ -497,7 +501,7 @@ int media_packet_set_buffer_size(media_packet_h packet, uint64_t size);
 
 /**
  * @brief Gets PTS of media packet.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in]  packet   The media packet handle
  * @param[out] pts      The PTS value to get
@@ -512,7 +516,7 @@ int media_packet_get_pts(media_packet_h packet, uint64_t * pts);
 
 /**
  * @brief Gets DTS of media packet
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in]  packet   The media packet handle
  * @param[out] dts      The DTS value to get
@@ -527,7 +531,7 @@ int media_packet_get_dts(media_packet_h packet, uint64_t * dts);
 
 /**
  * @brief Gets duration of media packet.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in]  packet    The media packet handle
  * @param[out] duration  The duration value to get
@@ -542,7 +546,7 @@ int media_packet_get_duration(media_packet_h packet, uint64_t * duration);
 
 /**
  * @brief Gets buffer size of media packet.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in]  packet   The media packet handle
  * @param[out] size     The buffer size value to get
@@ -557,7 +561,7 @@ int media_packet_get_buffer_size(media_packet_h packet, uint64_t * size);
 
 /**
  * @brief Gets buffer data pointer of media packet.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in]  packet   The media packet handle
  * @param[out] data     The allocated buffer data pointer
@@ -572,7 +576,7 @@ int media_packet_get_buffer_data_ptr(media_packet_h packet, void **data);
 
 /**
  * @brief Gets TBM surface data of media packet.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in]  packet   The media packet handle
  * @param[out] surface  The tbm_surface data pointer
@@ -587,7 +591,7 @@ int media_packet_get_tbm_surface(media_packet_h packet, tbm_surface_h * surface)
 
 /**
  * @brief Sets extra data of media packet.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in] packet   The media packet handle
  * @param[in] extra    The extra data to set
@@ -602,7 +606,7 @@ int media_packet_set_extra(media_packet_h packet, void *extra);
 
 /**
  * @brief Gets extra data of media packet.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in]  packet   The media packet handle
  * @param[out] extra    The extra data to get
@@ -617,7 +621,7 @@ int media_packet_get_extra(media_packet_h packet, void **extra);
 
 /**
  * @brief Checks whether the given media packet is for video.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in]  packet   The media packet handle
  * @param[out] is_video @c true if the given media packet is for video,
@@ -636,7 +640,7 @@ int media_packet_is_video(media_packet_h packet, bool * is_video);
 
 /**
  * @brief Checks whether the given media packet is for audio.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in]  packet    The media packet handle
  * @param[out] is_audio  @c true if the given media packet is for audio,
@@ -672,7 +676,7 @@ int media_packet_is_text(media_packet_h packet, bool * is_text);
 
 /**
  * @brief Checks whether the given media packet is encoded type.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in]  packet      The media packet handle
  * @param[out] is_encoded  @c true if the given media packet is encoded,
@@ -691,7 +695,7 @@ int media_packet_is_encoded(media_packet_h packet, bool * is_encoded);
 
 /**
  * @brief Checks whether the given media packet is raw type.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in]  packet   The media packet handle
  * @param[out] is_raw   @c true if the given media packet is for raw video,
@@ -728,7 +732,7 @@ 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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in] packet    The media packet handle
  * @param[in] flags    The media_buffer_flags_e of media packet to set
@@ -746,7 +750,7 @@ int media_packet_set_flags(media_packet_h packet, media_buffer_flags_e flags);
 
 /**
  * @brief Unsets media_buffer_flags_e of media packet
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in] packet   The media packet handle
  * @param[in] flags    The media_buffer_flags_e of media packet to unset
@@ -764,7 +768,7 @@ int media_packet_unset_flags(media_packet_h packet, media_buffer_flags_e flags);
 
 /**
  * @brief Checks whether the given media packet is codec data.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in] packet            The media packet handle
  * @param[out] is_codec_config  @c true if the given media packet is for codec data,
@@ -783,7 +787,7 @@ int media_packet_is_codec_config(media_packet_h packet, bool * is_codec_config);
 
 /**
  * @brief Checks whether the given media packet is eos.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in] packet   The media packet handle
  * @param[out] is_eos  @c true if the given media packet is for eos,
@@ -802,7 +806,7 @@ int media_packet_is_end_of_stream(media_packet_h packet, bool * is_eos);
 
 /**
  * @brief Checks whether the given media packet is sync frame.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in]  packet   The media packet handle
  * @param[out] is_sync  @c true if the given media packet is for sync frame,
@@ -821,7 +825,7 @@ int media_packet_is_sync_frame(media_packet_h packet, bool * is_sync);
 
 /**
  * @brief Checks whether the allocated buffer is tbm surface or not.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in]  packet   The media packet handle
  * @param[out] has_tbm_surface  @c true if the given media packet's allocated buffer is tbm surface,
@@ -841,7 +845,7 @@ int media_packet_has_tbm_surface_buffer(media_packet_h packet, bool * has_tbm_su
  *          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
+ * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
  *
  * @param[in]  packet   The media packet handle
  * @param[out] num  The number of planes from tbm_surface
@@ -860,7 +864,7 @@ int media_packet_get_number_of_video_planes(media_packet_h packet, uint32_t * nu
  *          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
+ * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
  *
  * @param[in]  packet   The media packet handle
  * @param[in]  plane_idx   The plane index value
@@ -880,7 +884,7 @@ int media_packet_get_video_stride_width(media_packet_h packet, int plane_idx, in
  *          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
+ * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
  *
  * @param[in]  packet   The media packet handle
  * @param[in]  plane_idx   The plane index value
@@ -900,7 +904,7 @@ int media_packet_get_video_stride_height(media_packet_h packet, int plane_idx, i
  *          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
+ * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
  *
  * @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
@@ -917,7 +921,8 @@ int media_packet_get_video_plane_data_ptr(media_packet_h packet, int plane_idx,
 
 /**
  * @brief Gets codec data and the codec data size of media packet.
- * @since_tizen 2.4
+ *
+ * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
  *
  * @param[in] packet   The media packet handle
  * @param[out] codec_data    The codec data to get
@@ -934,7 +939,8 @@ int media_packet_get_codec_data(media_packet_h packet, void **codec_data, unsign
 /**
  * @brief Destroys the media packet handle.
  * @details  The registered finalize_callback() function will be invoked to destroy the media packet handle.
- * @since_tizen 2.3
+ *
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in] packet  The handle to media packet to be destroyed
  *
diff --git a/include/media_packet_pool.h b/include/media_packet_pool.h
new file mode 100755 (executable)
index 0000000..a802976
--- /dev/null
@@ -0,0 +1,233 @@
+/*
+* Copyright (c) 2016 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_POOL_H__
+#define __TIZEN_MEDIA_PACKET_POOL_H__
+
+#include <media_format.h>
+#include <media_packet.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file media_packet_pool.h
+ * @brief This file contains the Media Packet Pool API.
+ */
+
+/**
+ * @addtogroup CAPI_MEDIA_TOOL_MODULE
+ * @{
+ */
+
+/**
+ * @brief  The Media Packet Pool Handle.
+ * @since_tizen 3.0
+ */
+typedef struct media_packet_pool_s *media_packet_pool_h;
+
+/**
+ * @brief      Creates a media packet pool to handle the media packets.
+ * @details    It creates a media packet pool instance
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks    The @a pool must be released by using packet_pool_destroy().
+ * @param[out] pool The media packet pool 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
+ *
+ */
+int media_packet_pool_create(media_packet_pool_h *pool);
+
+/**
+ * @brief      Sets the media format for the media packet pool.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in]  pool    The media packet pool handle
+ * @param[in]  fmt     The #media_format_h allocated by the caller
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @pre Must have media_format_h instance by media_format_create().
+ * @post Must do media_format_unref().
+ */
+int media_packet_pool_set_media_format(media_packet_pool_h pool, media_format_h fmt);
+
+/**
+ * @brief      Sets the media packet pool size.
+ * @details    Sets the number of packets to allocate with given parameters.
+ *          The media packet pool will be allocated with #min_buffers when media_pacet_pool_allocate() is called.
+ *          When there are no media packets available, it will be increased to #max_buffers of given parameter.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in]  pool The allocated pool handle
+ * @param[in]  min_buffers   The minimum number of buffers to allocate
+ * @param[in]  max_buffers   The maximum number of buffers to allocate
+ *
+ * @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
+ * @post After the pool has been configured, it can be allocated with media_packet_pool_allocate().
+ * @see media_packet_pool_get_size()
+ *
+ */
+int media_packet_pool_set_size(media_packet_pool_h pool, int min_buffers, int max_buffers);
+
+/**
+ * @brief      Gets the media packet pool size.
+ * @details    Gets the configuration values from the pool.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in]  pool    The allocated pool handle
+ * @param[out] min_buffers             The minimum number of buffers to allocate
+ * @param[out] max_buffers             The maximum number of buffers to allocate
+ * @param[out] curr_buffers    The current number of allocated buffers
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @post After the pool has been configured, it can be allocated with media_packet_pool_allocate().
+ * @see media_packet_pool_set_size()
+ */
+int media_packet_pool_get_size(media_packet_pool_h pool, int *min_buffers, int *max_buffers, int *curr_buffers);
+
+/**
+ * @brief      Allocates the media packet pool.
+ * @details It will allocate media packets with #min_buffers which given to media_packet_pool_set_size().
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in]  pool    The allocated pool 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
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION The user set the invalid format with media_packet_pool_set_format() or set the invalid size with media_packet_pool_set_size().\n
+ *             The user already allocate the pool.
+ * @pre media_packet_pool_set_media_format() and media_pool_set_size() should be called before calling media_packet_pool_allocate()
+ * @post The pool will be allocated. When the pool is allocated, media_packet_pool_acquire_packet() can be used to retrieve a packet from the pool.
+ * @see media_packet_pool_set_media_format()
+ * @see media_packet_pool_set_size()
+ *
+ */
+int media_packet_pool_allocate(media_packet_pool_h pool);
+
+/**
+ * @brief      Acquires a media packet from the media packet pool.
+ * @details    It will take a media packet from the queue and block until media packet is released into the pool agaian.
+ *                     When there are no media packets available, it will be increased to #max_buffers of given parameter.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in]  pool    The media packet pool handle
+ * @param[out] pkt             The media packet handle
+ * @param[in]   timeout It indicates the millisecond-timeouts to block
+ *                                             while waiting for one of acquired packet to be released.
+ *                                             If the value of timeout is -1, the pool blocks indefinitely until media packet into the pool.
+ *
+ * @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 The user does not allocate the pool.\n
+ *             The pool should be allocated with media_packet_pool_allocate() before acquiring media packet from the pool.
+ * @retval #MEDIA_PACKET_ERROR_NO_AVAILABLE_PACKET No available packet
+ * @see media_pakcet_pool_set_size()
+ * @see media_packet_pool_release_packet()
+ *
+ */
+int media_packet_pool_acquire_packet(media_packet_pool_h pool, media_packet_h *pkt, long timeout);
+
+/**
+ * @brief      Releases the media packet to pool.
+ * @details    Rlease a packet back in the pool. It will put the packet back in the queue.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in]  pool The media packet pool handle
+ * @param[in]  pkt The packet to release, the pkt should have previously been acquired from the pool with media_packet_pool_acquire_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 The user releases media packet which is not associated with a given pool.
+ * @see media_packet_pool_acquire_packet()
+ *
+ */
+int media_packet_pool_release_packet(media_packet_pool_h pool, media_packet_h pkt);
+
+/**
+ * @brief      Deallocates all the media packets.
+ * @details    Deallocates the packets allocated with media_packet_pool_allocate().
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in]  pool The media packet pool 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_INVALID_OPERATION The user does not release all media packets to the pool.
+ *
+ * @pre media packet should be released before calling media_packet_pool_deallocate().
+ * @post The pool will be deallocated. media_packet_pool_acquire_packet() calls will return an error.
+ * @see media_packet_pool_allocate()
+ */
+int media_packet_pool_deallocate(media_packet_pool_h pool);
+
+/**
+ * @brief      Destroys the media packet pool.
+ * @details    Destroys the media packet pool handle and releases all its resources.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in]   pool   The handle to media packet pool 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 The user does not create media packet pool instance, or not deallocate all media packets with media_packet_pool_deallocate().
+ *
+ * @see media_packet_pool_create()
+ */
+int media_packet_pool_destroy(media_packet_pool_h pool);
+
+/**
+ * @}
+ */
+#ifdef __cplusplus
+}
+#endif
+
+#endif   /*__TIZEN_MEDIA_PACKET_POOL_H__*/
diff --git a/include/media_packet_pool_private.h b/include/media_packet_pool_private.h
new file mode 100755 (executable)
index 0000000..e58a150
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+* Copyright (c) 2016 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_POOL_PRIVATE_H__
+#define __TIZEN_MEDIA_PACKET_POOL_PRIVATE_H__
+
+#include <media_format.h>
+#include <glib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief  The Media Packet Pool structure.
+ * @since_tizen 3.0
+ */
+typedef struct _media_packet_pool_s {
+       GMutex mutex;
+       GQueue *queue;
+       GCond queue_cond;
+       unsigned int curr_pool_size;
+       unsigned int min_pool_size;
+       unsigned int max_pool_size;
+       bool pool_created;
+       bool pool_allocated;
+       media_format_h fmt_h;
+} media_packet_pool_s;
+
+#ifdef __cplusplus
+}
+#endif
+#endif                                                 /* __TIZEN_MEDIA_PACKET_POOL_PRIVATE_H__ */
index 224ad4179ee4e8967b24a0b27ec04b65f5b4cbae..c77545d11f69cc4afe75b28e117a6d6a73cf4f86 100755 (executable)
@@ -119,6 +119,7 @@ typedef struct _media_packet_s {
        media_packet_finalize_cb finalizecb_func;
        void *userdata;
        bool is_allocated;
+       bool using_pool;
        void *extradata;
        void *codec_data;
        unsigned int codec_data_size;
@@ -129,6 +130,10 @@ typedef struct _media_packet_s {
 
 } media_packet_s;
 
+int _pkt_alloc_buffer(media_packet_s *pkt);
+int _pkt_reset_buffer(media_packet_h packet);
+void _aligned_free_normal_buffer_type(void *buffer_ptr);
+
 #ifdef __cplusplus
 }
 #endif
index 6fcdc6b017b616d0615d8465505b4cca06dd47ec..74317cb69272002c42bdf9ed5572318d1731dbf7 100755 (executable)
 /* NOTE : static internal functions does not check anything on incomming parameters
  * Caller should takecare it
  */
-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 uint64_t _pkt_calculate_text_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)
 {
@@ -338,6 +336,45 @@ int _pkt_alloc_buffer(media_packet_s *pkt)
        return MEDIA_PACKET_ERROR_NONE;
 }
 
+int _pkt_reset_buffer(media_packet_h packet)
+{
+       int i;
+       bool has_tbm;
+       media_packet_s *handle;
+       int ret = MEDIA_PACKET_ERROR_NONE;
+
+       MEDIA_PACKET_INSTANCE_CHECK(packet);
+       handle = (media_packet_s *)packet;
+
+       /* reset buffers */
+       if (handle->type == MEDIA_BUFFER_TYPE_TBM_SURFACE) {
+               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) {
+                               for (i = 0; i < surface_info.num_planes; i++) {
+                                       memset(surface_info.planes[i].ptr, 0x0, surface_info.planes[i].size);
+                               }
+                       }
+               } else {
+                       LOGE("tbm_surface_get_info() is failed.");
+                       return MEDIA_PACKET_ERROR_OUT_OF_MEMORY;
+               }
+       } else {
+               memset(handle->data, 0x0, handle->size);
+               handle->size = 0;
+       }
+
+       /* Clear buffer flags */
+       handle->flags &= ~MEDIA_PACKET_CODEC_CONFIG;
+       handle->flags &= ~MEDIA_PACKET_END_OF_STREAM;
+       handle->flags &= ~MEDIA_PACKET_SYNC_FRAME;
+
+       return ret;
+}
+
 #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))
@@ -1268,6 +1305,11 @@ int media_packet_destroy(media_packet_h packet)
 
        handle = (media_packet_s *)packet;
 
+       if (handle->using_pool) {
+               LOGE("packet is being used by pool, release can be done by pool only");
+               return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+       }
+
        /* finailize callback */
        if (handle->finalizecb_func) {
                int finalize_cb_ret;
@@ -1382,7 +1424,7 @@ static void *_aligned_malloc_normal_buffer_type(uint64_t size, int alignment)
        return NULL;
 }
 
-static void _aligned_free_normal_buffer_type(void *buffer_ptr)
+void _aligned_free_normal_buffer_type(void *buffer_ptr)
 {
        unsigned char *ptr;
        if (buffer_ptr == NULL)
diff --git a/src/media_packet_pool.c b/src/media_packet_pool.c
new file mode 100755 (executable)
index 0000000..19db6f8
--- /dev/null
@@ -0,0 +1,437 @@
+/*
+* Copyright (c) 2016 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_packet_pool.h>
+#include <media_format.h>
+#include <media_packet.h>
+#include <media_packet_private.h>
+#include <media_packet_pool_private.h>
+#include <media_format_private.h>
+
+int media_packet_pool_create(media_packet_pool_h * pool)
+{
+       int ret = MEDIA_PACKET_ERROR_NONE;
+       media_packet_pool_s *pool_handle = NULL;
+
+       MEDIA_PACKET_INSTANCE_CHECK(pool)
+
+       pool_handle = (media_packet_pool_s *) malloc(sizeof(media_packet_pool_s));
+       if (pool_handle != NULL)
+               memset(pool_handle, 0, sizeof(media_packet_pool_s));
+       else {
+               LOGE("out of memory");
+               ret = MEDIA_PACKET_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+       pool_handle->pool_created = TRUE;
+
+       /* create Gqueue */
+       pool_handle->queue = g_queue_new();
+       pool_handle->curr_pool_size = 0;
+       pool_handle->min_pool_size = 0;
+       pool_handle->max_pool_size = 0;
+       pool_handle->pool_allocated = false;
+       /* take memory packet pool handle */
+       *pool = (media_packet_pool_h) pool_handle;
+
+       LOGI("packet pool handle : %p", *pool);
+       return ret;
+
+}
+
+int media_packet_pool_set_media_format(media_packet_pool_h pool, media_format_h fmt)
+{
+       int ret = MEDIA_PACKET_ERROR_NONE;
+       media_packet_pool_s *pool_handle = NULL;
+
+       MEDIA_PACKET_INSTANCE_CHECK(pool);
+       MEDIA_PACKET_NULL_ARG_CHECK(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;
+       }
+
+       pool_handle = (media_packet_pool_s *) pool;
+
+       /* increase format reference count */
+       media_format_ref(fmt);
+
+       pool_handle->fmt_h = MEDIA_FORMAT_CAST(fmt);
+       return ret;
+}
+
+int media_packet_pool_set_size(media_packet_pool_h pool, int min_buffers, int max_buffers)
+{
+       int ret = MEDIA_PACKET_ERROR_NONE;
+       media_packet_pool_s *pool_handle = NULL;
+
+       MEDIA_PACKET_INSTANCE_CHECK(pool);
+       pool_handle = (media_packet_pool_s *) pool;
+
+       if (max_buffers < 0 || min_buffers < 0 || min_buffers > max_buffers)
+               return MEDIA_PACKET_ERROR_INVALID_PARAMETER;
+
+       pool_handle->min_pool_size = min_buffers;
+       pool_handle->max_pool_size = max_buffers;
+
+       return ret;
+}
+
+int media_packet_pool_get_size(media_packet_pool_h pool, int *min_size, int *max_size, int *curr_size)
+{
+       int ret = MEDIA_PACKET_ERROR_NONE;
+       media_packet_pool_s *pool_handle = NULL;
+
+       MEDIA_PACKET_INSTANCE_CHECK(pool);
+       pool_handle = (media_packet_pool_s *) pool;
+
+       *curr_size = pool_handle->curr_pool_size;
+       *min_size = pool_handle->min_pool_size;
+       *max_size = pool_handle->max_pool_size;
+       return ret;
+
+}
+
+int _allocate_pkt(media_packet_pool_h pool)
+{
+       int ret = MEDIA_PACKET_ERROR_NONE;
+       int i, num_pkts = 0;
+
+       media_packet_pool_s *pool_handle = NULL;
+       media_packet_s *pkt_handle = NULL;
+       media_format_s *fmt_handle = NULL;
+
+       MEDIA_PACKET_INSTANCE_CHECK(pool);
+       pool_handle = (media_packet_pool_s *) pool;
+       fmt_handle = (media_format_s *) pool_handle->fmt_h;
+       MEDIA_PACKET_NULL_ARG_CHECK(fmt_handle);
+
+       if (pool_handle->curr_pool_size >= pool_handle->max_pool_size) {
+               LOGE("The media packet pool is full..");
+               return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+
+       }
+
+       pkt_handle = (media_packet_s *) malloc(sizeof(media_packet_s));
+
+       if (pkt_handle != NULL)
+               memset(pkt_handle, 0, sizeof(media_packet_s));
+       else {
+               LOGE("out of memory");
+               ret = MEDIA_PACKET_ERROR_OUT_OF_MEMORY;
+               goto fail;
+       }
+
+       if (MEDIA_FORMAT_IS_VIDEO(fmt_handle) && MEDIA_FORMAT_IS_RAW(fmt_handle))
+               pkt_handle->type = MEDIA_BUFFER_TYPE_TBM_SURFACE;
+       else
+               pkt_handle->type = MEDIA_BUFFER_TYPE_NORMAL;
+
+       LOGI("The created packet handle(%p) is..", pkt_handle);
+
+       /* take fmt */
+       pkt_handle->format = MEDIA_FORMAT_CAST(fmt_handle);
+
+       /* alloc buffer */
+       int err = _pkt_alloc_buffer(pkt_handle);
+       if (err != MEDIA_PACKET_ERROR_NONE) {
+               LOGE("failed _pkt_alloc_buffer(), err = (0x%08x)", err);
+               ret = err;
+               goto fail;
+       }
+
+       /* allocated buffer */
+       pkt_handle->is_allocated = true;
+
+       /* set finalized callback and user data */
+       pkt_handle->finalizecb_func = NULL;
+       pkt_handle->userdata = NULL;
+
+       /* increase format reference count */
+       media_format_ref((media_format_h) pkt_handle->format);
+
+       pkt_handle->using_pool = true;
+       /* push the packet handle into queue */
+       g_queue_push_tail(pool_handle->queue, pkt_handle);
+       pool_handle->curr_pool_size++;
+
+       return ret;
+
+ fail:
+       if (pkt_handle) {
+               free(pkt_handle);
+               pkt_handle = NULL;
+       }
+
+       return ret;
+}
+
+int media_packet_pool_allocate(media_packet_pool_h pool)
+{
+       int ret = MEDIA_PACKET_ERROR_NONE;
+       int i, num_pkts = 0;
+
+       media_packet_pool_s *pool_handle = NULL;
+       media_packet_s *pkt_handle = NULL;
+       media_format_s *fmt_handle = NULL;
+
+       MEDIA_PACKET_INSTANCE_CHECK(pool);
+       pool_handle = (media_packet_pool_s *) pool;
+       fmt_handle = (media_format_s *) pool_handle->fmt_h;
+       MEDIA_PACKET_NULL_ARG_CHECK(fmt_handle);
+
+       if (!(pool_handle->pool_created)) {
+               LOGE("The media packet pool is not created..");
+               return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+
+       }
+
+       if (!(pool_handle->min_pool_size)) {
+               LOGE("The media packet pool size is not set. set pool size...");
+               return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+
+       }
+       if (pool_handle->curr_pool_size >= pool_handle->max_pool_size) {
+               LOGE("The media packet pool is full..");
+               return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+
+       }
+
+       if ((pool_handle->pool_allocated)) {
+               LOGE("The media packet is already allocated. set media format size...");
+               return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+
+       }
+       for (i = pool_handle->curr_pool_size; i < pool_handle->min_pool_size; i++) {
+               if (_allocate_pkt(pool_handle) != MEDIA_PACKET_ERROR_NONE) {
+                       LOGE("The media packet pool is full or out of memory...");
+                       return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+               }
+
+       }
+       pool_handle->pool_allocated = true;
+       return ret;
+
+ fail:
+       if (pkt_handle) {
+               free(pkt_handle);
+               pkt_handle = NULL;
+       }
+
+       while (!g_queue_is_empty(pool_handle->queue)) {
+
+               pkt_handle = g_queue_pop_head(pool_handle->queue);
+               if (pkt_handle) {
+                       free(pkt_handle);
+                       pkt_handle = NULL;
+               }
+       }
+       return ret;
+}
+
+int media_packet_pool_acquire_packet(media_packet_pool_h pool, media_packet_h * pkt, long timeout)
+{
+       int ret = MEDIA_PACKET_ERROR_NONE;
+       media_packet_pool_s *pool_handle = NULL;
+       media_packet_s *pkt_handle = NULL;
+       gint64 wait_until = -1;
+       MEDIA_PACKET_INSTANCE_CHECK(pool);
+       pool_handle = (media_packet_pool_s *) pool;
+
+       if (timeout != -1) {
+               gint64 add = timeout;
+               wait_until = g_get_monotonic_time() + add;
+       }
+
+       if (!(pool_handle->pool_allocated)) {
+               LOGE("The media packet pool is not allocated...");
+               return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+
+       }
+
+       if (!(pool_handle->curr_pool_size)) {
+               LOGE("The media packet pool size is not set. set pool size...");
+               return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+       }
+
+       g_mutex_lock(&pool_handle->mutex);
+       while (TRUE) {
+               pkt_handle = g_queue_pop_head(pool_handle->queue);
+
+               if (pkt_handle)
+                       break;
+
+               if (pool_handle->curr_pool_size < pool_handle->max_pool_size) {
+                       LOGI("no buffer, trying to allocate");
+
+                       if (_allocate_pkt(pool_handle) != MEDIA_PACKET_ERROR_NONE) {
+                               LOGE("failed in _allocate_pkt ");
+                               g_mutex_unlock(&pool_handle->mutex);
+                               return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+                       }
+                       pkt_handle = g_queue_pop_head(pool_handle->queue);
+                       break;
+               } else if (timeout == -1) {
+                       LOGE("Queue is empty, waiting for till release is done");
+                       g_cond_wait(&pool_handle->queue_cond, &pool_handle->mutex);
+                       pkt_handle = g_queue_pop_head(pool_handle->queue);
+                       break;
+
+               } else {
+                       g_cond_wait_until(&pool_handle->queue_cond, &pool_handle->mutex, wait_until);
+                       LOGI("Queue is Empty, waiting for timeout %" G_GSIZE_FORMAT "", wait_until);
+                       pkt_handle = g_queue_pop_head(pool_handle->queue);
+                       if (!pkt_handle) {
+                               LOGE("pkt is null");
+                               ret = MEDIA_PACKET_ERROR_NO_AVAILABLE_PACKET;
+                       }
+                       break;
+               }
+       }
+
+       *pkt = (media_packet_h) pkt_handle;
+       g_mutex_unlock(&pool_handle->mutex);
+       LOGI("The packet handle aquired from pool is  %p..", pkt_handle);
+       return ret;
+
+}
+
+
+int media_packet_pool_release_packet(media_packet_pool_h pool, media_packet_h pkt)
+{
+       int ret = MEDIA_PACKET_ERROR_NONE;
+       int num_pkts = 0;
+       media_packet_pool_s *pool_handle = NULL;
+       media_packet_s *pkt_handle = NULL;
+
+       MEDIA_PACKET_INSTANCE_CHECK(pool);
+       pool_handle = (media_packet_pool_s *) pool;
+       pkt_handle = (media_packet_s*) pkt;
+
+       ret = _pkt_reset_buffer(pkt);
+       if (ret != MEDIA_PACKET_ERROR_NONE) {
+               LOGE("[%s] failed _pkt_alloc_buffer(), err = (0x%08x)", __FUNCTION__, ret);
+               return ret;
+       }
+
+       g_mutex_lock(&pool_handle->mutex);
+       num_pkts = g_queue_get_length(pool_handle->queue);
+       g_mutex_unlock(&pool_handle->mutex);
+
+       if (num_pkts == pool_handle->curr_pool_size) {
+               LOGE("Queue is already full");
+               return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+       }
+
+       if (pkt_handle->using_pool) {
+               LOGI("The packet released to pool is  %p..\n", pkt_handle);
+               g_mutex_lock(&pool_handle->mutex);
+               g_queue_push_tail(pool_handle->queue, pkt_handle);
+               g_mutex_unlock(&pool_handle->mutex);
+               g_cond_signal(&pool_handle->queue_cond);
+       } else {
+               LOGE("packet is not aquired from pool");
+               return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+       }
+
+       return ret;
+}
+
+int media_packet_pool_deallocate(media_packet_pool_h pool)
+{
+       int ret = MEDIA_PACKET_ERROR_NONE;
+       int i, num_pkts = 0;
+       media_packet_pool_s *pool_handle = NULL;
+       media_packet_s *pkt_handle = NULL;
+
+       MEDIA_PACKET_INSTANCE_CHECK(pool);
+       pool_handle = (media_packet_pool_s *) pool;
+
+       if (!(pool_handle->pool_created))
+               return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+
+       g_mutex_lock(&pool_handle->mutex);
+       num_pkts = g_queue_get_length(pool_handle->queue);
+       g_mutex_unlock(&pool_handle->mutex);
+
+       if (num_pkts < pool_handle->curr_pool_size) {
+               LOGE("packet is being used, release the packet before deallocate");
+               return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+       }
+
+       g_mutex_lock(&pool_handle->mutex);
+       while (!g_queue_is_empty(pool_handle->queue)) {
+
+               pkt_handle = g_queue_pop_head(pool_handle->queue);
+               g_mutex_unlock(&pool_handle->mutex);
+               if (pkt_handle == NULL) {
+                       LOGE("Failed to get packet handle from Queue ");
+                       return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+               }
+               pkt_handle = (media_packet_h) pkt_handle;
+               pkt_handle->using_pool = false;
+               LOGI("The packet handle(%p) will be deallocated..", pkt_handle);
+               ret = media_packet_destroy(pkt_handle);
+               g_mutex_lock(&pool_handle->mutex);
+       }
+       g_mutex_unlock(&pool_handle->mutex);
+       return ret;
+}
+
+int media_packet_pool_destroy(media_packet_pool_h pool)
+{
+       int ret = MEDIA_PACKET_ERROR_NONE;;
+       int num_pkts = 0;
+
+       media_packet_pool_s *pool_handle = NULL;
+       media_packet_s *pkt_handle = NULL;
+
+       MEDIA_PACKET_INSTANCE_CHECK(pool);
+       pool_handle = (media_packet_pool_s *) pool;
+
+       if (!(pool_handle->pool_created))
+               return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+
+       g_mutex_lock(&pool_handle->mutex);
+       num_pkts = g_queue_get_length(pool_handle->queue);
+       g_mutex_unlock(&pool_handle->mutex);
+
+       if (num_pkts > 0) {
+               LOGE("The packet pool needs to deallocate first ");
+               return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+
+       }
+       /* unreference media_format */
+       media_format_unref(pool_handle->fmt_h);
+       g_queue_free(pool_handle->queue);
+       LOGI("The packet pool handle(%p) will be destroyed..", pool_handle);
+       free(pool_handle);
+       pool_handle = NULL;
+
+       return ret;
+
+}
+
index 28c9f4d384f91a38a64283b8026625c9d9a55c6f..422fb6b0e0a6e3a8e839d5847e31ca46f910575b 100755 (executable)
@@ -938,9 +938,9 @@ 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)
                        _media_packet_create_alloc();
-               else if (strncmp(cmd, "d", 1) == 0) {
+               else if (strncmp(cmd, "d", 1) == 0) {
                        _media_packet_destroy();
                } else if (strncmp(cmd, "b", 1) == 0) {
                        _media_packet_create_from_tbm_surface();
@@ -950,9 +950,9 @@ void _interpret_main_menu(char *cmd)
                        quit_program();
                }
        } else if (len == 2) {
-               if (strncmp(cmd, "aa", 2) == 0) {
+               if (strncmp(cmd, "aa", 2) == 0)
                        _media_packet_create();
-               else if (strncmp(cmd, "ab", 2) == 0) {
+               else if (strncmp(cmd, "ab", 2) == 0) {
                        _media_packet_alloc();
                } else if (strncmp(cmd, "iv", 2) == 0) {
                        _media_packet_is_video();
@@ -985,9 +985,9 @@ void _interpret_main_menu(char *cmd)
                }
 
        } else if (len == 3) {
-               if (strncmp(cmd, "gbp", 3) == 0) {
+               if (strncmp(cmd, "gbp", 3) == 0)
                        _media_packet_get_buffer_data_ptr();
-               else if (strncmp(cmd, "gts", 3) == 0) {
+               else if (strncmp(cmd, "gts", 3) == 0) {
                        _media_packet_get_tbm_surface();
                } else if (strncmp(cmd, "fgv", 3) == 0) {
                        _media_format_get_video_info();
@@ -1027,9 +1027,9 @@ void _interpret_main_menu(char *cmd)
                        _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) {
+               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;
@@ -1041,13 +1041,11 @@ void _interpret_main_menu(char *cmd)
                        g_menu_state = CURRENT_STATUS_FORMAT_SET_AUDIO_AAC_TYPE;
                }
        } else if (len == 5) {
-               if (strncmp(cmd, "saaht", 5) == 0) {
+               if (strncmp(cmd, "saaht", 5) == 0)
                        g_menu_state = CURRENT_STATUS_FORMAT_SET_AUDIO_AAC_HEADER_TYPE;
-               }
        } else if (len == 6) {
-               if (strncmp(cmd, "fgaaht", 6) == 0) {
+               if (strncmp(cmd, "fgaaht", 6) == 0)
                        _media_format_get_audio_aac_header_type();
-               }
        }
 }