/**
* @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 */
/**
* @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 */
/**
* @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 */
/**
* @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) */
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 */
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) */
/**
* @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 */
/**
* @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
/**
* @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
/**
* @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
/**
* @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
*
/**
* @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
*
/**
* @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()
/**
* @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()
/**
* @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()
/**
* @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()
/**
* @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
*
/**
* @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()
/**
* @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()
/**
* @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
/**
* @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()
/**
* @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
/**
* @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
*
/**
* @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,
/**
* @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
*
/**
* @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.
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.
/**
* @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 */
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 */
/**
* @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 {
* @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
* @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
* @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
* @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
* @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
*
/**
* @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
* @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
/**
* @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
/**
* @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
/**
* @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
/**
* @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
/**
* @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
/**
* @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
/**
* @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
/**
* @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
/**
* @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
/**
* @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
/**
* @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
/**
* @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
/**
* @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
/**
* @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
/**
* @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,
/**
* @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,
/**
* @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,
/**
* @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,
/**
* @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
/**
* @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
/**
* @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,
/**
* @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,
/**
* @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,
/**
* @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,
* 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
* 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
* 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
* 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
/**
* @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
/**
* @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
*
--- /dev/null
+/*
+* 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__*/
--- /dev/null
+/*
+* 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__ */
media_packet_finalize_cb finalizecb_func;
void *userdata;
bool is_allocated;
+ bool using_pool;
void *extradata;
void *codec_data;
unsigned int codec_data_size;
} 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
/* 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)
{
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))
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;
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)
--- /dev/null
+/*
+* 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;
+
+}
+
{
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();
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();
}
} 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();
_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;
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();
- }
}
}