diff --git a/codec/interfaces/include/codec_interface.h b/codec/interfaces/include/codec_interface.h index 5e9d141bf6d2c25c35b4d88c59eab37c560211ca..9e38beec2e49d93c4704843d6dd1d0e4d318c4d0 100755 --- a/codec/interfaces/include/codec_interface.h +++ b/codec/interfaces/include/codec_interface.h @@ -103,19 +103,38 @@ int32_t CodecEnumerateCapbility(uint32_t index, CodecCapbility *cap); int32_t CodecGetCapbility(AvCodecMime mime, CodecType type, uint32_t flags, CodecCapbility *cap); /** - * @brief Creates a specific codec component and returns the component context through a handle. + * @brief Creates a specific codec component by name and returns the component context through a handle. * * You can adjust the parameters required for creating a component based on service requirements. * * @param name Indicates the pointer to the unique name of the component, for example, * codec.avc.hardware.decoder. - * @param attr Indicates the pointer to the parameters in the array required for creating the component. - * @param len Indicates the number of elements in the parameter array. + * @param attr Indicates the pointer to the parameters in the array required for creating the component, No need to + * parse parameter attr if attr NULL or attrNum zero. + * @param attrNum Indicates the number of elements in the parameter array, No need to parse parameter attr if attr + * NULL or attrNum zero. * @param handle Indicates the pointer to the codec handle returned. * @return Returns 0 if the codec component is created and the handle is available; * returns a non-zero value otherwise. */ -int32_t CodecCreate(const char* name, const Param *attr, int len, CODEC_HANDLETYPE *handle); +int32_t CodecCreate(const char* name, const Param *attr, int attrNum, CODEC_HANDLETYPE *handle); + +/** + * @brief Creates a specific codec component by codec type and format, returns the component context through a handle. + * + * You can adjust the parameters required for creating a component based on service requirements. + * + * @param type Indicates the codec type, for example, VIDEO_DECODER. + * @param mime Indicates the codec format, for example, MEDIA_MIMETYPE_VIDEO_AVC. + * @param attr Indicates the pointer to the parameters in the array required for creating the component, No need to + * parse parameter attr if attr NULL or attrNum zero. + * @param attrNum Indicates the number of elements in the parameter array, No need to parse parameter attr if attr + * NULL or attrNum zero. + * @param handle Indicates the pointer to the codec handle returned. + * @return Returns 0 if the codec component is created and the handle is available; + * returns a non-zero value otherwise. + */ +int32_t CodecCreateByType(CodecType type, AvCodecMime mime, const Param *attr, int attrNum, CODEC_HANDLETYPE *handle); /** * @brief Destroys a codec component. @@ -134,11 +153,11 @@ int32_t CodecDestroy(CODEC_HANDLETYPE handle); * external buffer mode. If the current codec can use only the specific buffer mode, you do not need to set it. * * @param handle Indicates the handle of the codec component. - * @param type Specifies whether the buffer type is an input type or an output type. * @param mode Specifies whether to use an internal or external buffer mode. + * @param type Specifies the buffer memory type. * @return Returns 0 if the setting is successful; returns a non-zero value otherwise. */ -int32_t CodecSetPortMode(CODEC_HANDLETYPE handle, DirectionType type, BufferMode mode); +int32_t CodecSetPortMode(CODEC_HANDLETYPE handle, AllocateBufferMode mode, BufferType type); /** * @brief Sets parameters required by a codec component. diff --git a/codec/interfaces/include/codec_type.h b/codec/interfaces/include/codec_type.h index 571aa33aaf44f7cd0b09bcd4f8df606e2a4695bc..e1fc7a36f31a2e8598366d255217620bf741b31d 100755 --- a/codec/interfaces/include/codec_type.h +++ b/codec/interfaces/include/codec_type.h @@ -72,14 +72,13 @@ typedef enum { KEY_BUFFERSIZE, /**< Buffer size. The value type is uint32_t. */ KEY_LEFT_STREAM_FRAMES, /**< Number of frames in the remaining data streams. The value type is uint32_t. */ KEY_CODEC_TYPE, /**< Codec type. For the value type, see {@link CodecType}. */ - KEY_DIRECTION_TYPE, /**< Input/Output type. For the value type, see {@link DirectionType}. */ KEY_BITRATE = 0x500, /**< Bit rate. The value type is uint32_t. */ KEY_WIDTH = 0x1000, /**< Width. The value type is uint32_t. */ KEY_HEIGHT, /**< Hight. The value type is uint32_t. */ KEY_STRIDE, /**< Stride. The value type is uint32_t. */ KEY_VIDEO_FIELD, /**< Video field. For the value type, see {@link VideoField}. */ - KEY_PIXEL_FORMAT, /**< Pixel format. For the value type, see {@link PixelFormat}. */ + KEY_PIXEL_FORMAT, /**< Pixel format. For the value type, see {@link CodecPixelFormat}. */ KEY_VIDEO_RC_MODE, /**< Rate control mode. For the value type, see {@link VenCodeRcMode}. */ KEY_VIDEO_GOP_MODE, /**< GOP mode. For the value type, see {@link VenCodeGopMode}. */ KEY_VIDEO_PIC_SIZE, /**< Image resolution. For the value type, see {@link PicSize}. */ @@ -94,6 +93,7 @@ typedef enum { KEY_SOUND_MODE, /**< Audio channel mode. For the value type, see {@link AudioSoundMode}. */ KEY_POINT_NUM_PER_FRAME, /**< Number of sampling points per frame. The value type is uint32_t. */ KEY_DEVICE_ID, /**< Device ID. The value type is uint32_t. */ + KEY_AUDIO_SAMPLE_FORMAT, /**< Audio sample format. For value type, see {@link AudioSampleFormat}. */ } ParamKey; /** @@ -109,31 +109,6 @@ typedef enum { VENCOD_RC_FIXQP /**< Fixed quantization parameters */ } VenCodeRcMode; -/** - * @brief Enumerates resolutions. - */ -typedef enum { - RESOLUTION_CIF, /**< 352x288 */ - RESOLUTION_360P, /**< 640x360 */ - RESOLUTION_D1_PAL, /**< 720x576 */ - RESOLUTION_D1_NTSC, /**< 720x480 */ - RESOLUTION_720P, /**< 1280x720 */ - RESOLUTION_1080P, /**< 1920x1080 */ - RESOLUTION_2560X1440, /**< 2560x1440 */ - RESOLUTION_2592X1520, /**< 2592x1520 */ - RESOLUTION_2592X1536, /**< 2592x1536 */ - RESOLUTION_2592X1944, /**< 2592x1944 */ - RESOLUTION_2688X1536, /**< 2688x1536 */ - RESOLUTION_2716X1524, /**< 2716x1524 */ - RESOLUTION_3840X2160, /**< 3840x2160 */ - RESOLUTION_4096X2160, /**< 4096x2160 */ - RESOLUTION_3000X3000, /**< 3000x3000 */ - RESOLUTION_4000X3000, /**< 4000x3000 */ - RESOLUTION_7680X4320, /**< 7680x4320 */ - RESOLUTION_3840X8640, /**< 3840x8640 */ - RESOLUTION_INVALID /**< Invalid resolution */ -} PicSize; - /** * @brief Enumerates types of group of pictures (GOP). */ @@ -147,17 +122,12 @@ typedef enum { VENCOD_GOPMODE_INVALID, /**< Invalid type */ } VenCodeGopMode; -/** - * @brief Defines the pointer to the type of the dynamic parameter value. - */ -typedef void *ValueType; - /** * @brief Describes the dynamic parameter structure, which is mainly used * by {@link CodecCreate} and {@link CodecSetParameter}. */ typedef struct { - ParamKey key; /**< Parameter type index */ + ParamKey key; /**< Parameter type index */ void *val; /**< Pointer to the parameter value */ int size; /**< Parameter value size */ } Param; @@ -177,9 +147,22 @@ typedef enum { * @brief Enumerates pixel formats. */ typedef enum { - YVU_SEMIPLANAR_420 = 0, /**< YUV 420 SP */ - YVU_SEMIPLANAR_420_TILE, /**< YUV SP 420 TILE */ - PIX_FORMAT_INVALID /**< Invalid format */ + PIXEL_FORMAT_NONE, + PIXEL_FORMAT_YUV_422_I, /**< YUV422 interleaved format */ + PIXEL_FORMAT_YCBCR_422_SP, /**< YCBCR422 semi-planar format */ + PIXEL_FORMAT_YCRCB_422_SP, /**< YCRCB422 semi-planar format */ + PIXEL_FORMAT_YCBCR_420_SP, /**< YCBCR420 semi-planar format */ + PIXEL_FORMAT_YCRCB_420_SP, /**< YCRCB420 semi-planar format */ + PIXEL_FORMAT_YCBCR_422_P, /**< YCBCR422 planar format */ + PIXEL_FORMAT_YCRCB_422_P, /**< YCRCB422 planar format */ + PIXEL_FORMAT_YCBCR_420_P, /**< YCBCR420 planar format */ + PIXEL_FORMAT_YCRCB_420_P, /**< YCRCB420 planar format */ + PIXEL_FORMAT_YUYV_422_PKG, /**< YUYV422 packed format */ + PIXEL_FORMAT_UYVY_422_PKG, /**< UYVY422 packed format */ + PIXEL_FORMAT_YVYU_422_PKG, /**< YVYU422 packed format */ + PIXEL_FORMAT_VYUY_422_PKG, /**< VYUY422 packed format */ + PIXEL_FORMAT_VENDOR_MASK = 0x7F000000, /**< Reserved region for introducing vendor extensions */ + PIXEL_FORMAT_INVALID = 0x7FFFFFFF, /**< Invalid pixel format */ } CodecPixelFormat; /** @@ -210,27 +193,23 @@ typedef enum { } AudioSampleRate; /** - * @brief Enumerates audio bit rates. + * @brief Enumerates audio sample formats. + * For planar sample formats, each audio channel is in a seperate data plane. + * For packed sample formats, only the first data plane is used, and samples for each channel are interleaved. */ typedef enum { - AUD_BITRATE_8K = 8000, /**< 8 kbit/s */ - AUD_BITRATE_16K = 16000, /**< 16 kbit/s */ - AUD_BITRATE_22K = 22000, /**< 22 kbit/s */ - AUD_BITRATE_24K = 24000, /**< 24 kbit/s */ - AUD_BITRATE_32K = 32000, /**< 32 kbit/s */ - AUD_BITRATE_40K = 40000, /**< 40 kbit/s */ - AUD_BITRATE_48K = 48000, /**< 48 kbit/s */ - AUD_BITRATE_64K = 64000, /**< 64 kbit/s */ - AUD_BITRATE_96K = 96000, /**< 96 kbit/s */ - AUD_BITRATE_128K = 128000, /**< 128 kbit/s */ - AUD_BITRATE_132K = 132000, /**< 132 kbit/s */ - AUD_BITRATE_144K = 144000, /**< 144 kbit/s */ - AUD_BITRATE_192K = 192000, /**< 192 kbit/s */ - AUD_BITRATE_256K = 256000, /**< 256 kbit/s */ - AUD_BITRATE_265K = 265000, /**< 265 kbit/s */ - AUD_BITRATE_288K = 288000, /**< 288 kbit/s */ - AUD_BITRATE_320K = 320000, /**< 320 kbit/s */ -} AudioBitRate; + AUDIO_SAMPLE_FMT_U8, /**< Unsigned 8 bits, packed */ + AUDIO_SAMPLE_FMT_S16, /**< Signed 16 bits, packed */ + AUDIO_SAMPLE_FMT_S32, /**< Signed 32 bits, packed */ + AUDIO_SAMPLE_FMT_FLOAT, /**< Float, packed */ + AUDIO_SAMPLE_FMT_DOUBLE, /**< Double, packed */ + AUDIO_SAMPLE_FMT_U8P, /**< Unsigned 8 bits, planar */ + AUDIO_SAMPLE_FMT_S16P, /**< Signed 16 bits, planar */ + AUDIO_SAMPLE_FMT_S32P, /**< Signed 32 bits, planar */ + AUDIO_SAMPLE_FMT_FLOATP, /**< Float, planar */ + AUDIO_SAMPLE_FMT_DOUBLEP, /**< Double, planar */ + AUDIO_SAMPLE_FMT_INVALID, /**< Invalid sampling format */ +} AudioSampleFormat; /** * @brief Enumerates stream flags. @@ -243,78 +222,63 @@ typedef enum { STREAM_FLAG_END_OF_FRAME = 16, /**< End of frames, used in pair with STREAM_FLAG_PART_OF_FRAME */ } StreamFlagType; -/** - * @brief Defines the codec buffer handle type. The virtual address of a handle maps to its physical address. - */ -typedef struct { - uint8_t *virAddr; /**< Virtual address */ - uintptr_t handle; /**< Physical address */ -} CodecBufferHandle; - /** * @brief Enumerates buffer types. */ typedef enum { - BUFFER_TYPE_VIRTUAL = 0, /**< Virtual memory */ - BUFFER_TYPE_FD, /**< File descriptor, which can be used cross processes */ - BUFFER_TYPE_HANDLE, /**< Handle, which can be used cross processes */ + BUFFER_TYPE_VIRTUAL = 0, /**< Data described by this buffer */ + BUFFER_TYPE_FD, /**< Share mem file descriptor, which can be used cross processes */ + BUFFER_TYPE_HANDLE, /**< Video frame buffer handle, For details, see {@link BufferHandle} */ } BufferType; /** * @brief Describes buffer information. */ typedef struct { - BufferType type; /**< Buffer type */ - /** - * @brief Describes the buffer address. - */ - union { - uint8_t *addr; /**< Virtual address */ - int32_t fd; /**< File descriptor */ - CodecBufferHandle handle; /**< Data handle. For details, see {@link CodecBufferHandle} */ - }; - uint32_t offset; /**< Buffer offset */ - uint32_t length; /**< Length of valid data */ - uint32_t size; /**< Total size of buffer blocks*/ + BufferType type; /**< Buffer type */ + intptr_t buf; /**< A reference to a data buffer, Used with buffer type */ + uint32_t offset; /**< Buffer offset */ + uint32_t length; /**< Length of valid data */ + uint32_t capacity; /**< Total size of buffer blocks*/ } CodecBufferInfo; /** * @brief Describes input information. */ typedef struct { - uint32_t bufferCnt; /**< Number of buffers */ - CodecBufferInfo *buffers; /**< Pointer to the buffer description. For details, see {@link CodecBufferInfo}. */ - int64_t pts; /**< Input timestamp */ - int32_t flag; /**< Input flag. For details, see {@link StreamFlagType}. */ + int64_t timeStamp; /**< Input timestamp */ + uint32_t flag; /**< Input flag. For details, see {@link StreamFlagType}. */ + uint32_t bufferCnt; /**< Number of buffers */ + CodecBufferInfo buffer[0]; /**< Pointer to the buffer description. For details, see {@link CodecBufferInfo}. */ } InputInfo; /** * @brief Describes output information. */ typedef struct { - uint32_t bufferCnt; /**< Number of buffers */ - CodecBufferInfo *buffers; /**< Pointer to the buffer description. For details, see {@link CodecBufferInfo}. */ int64_t timeStamp; /**< Output timestamp */ uint32_t sequence; /**< Corresponding input sequence number */ uint32_t flag; /**< Output flag */ - CodecType type; /**< Codec type */ - void *vendorPrivate; /**< Private information about a device vendor */ + uint32_t bufferCnt; /**< Number of buffers */ + CodecBufferInfo buffer[0]; /**< Pointer to the buffer description. For details, see {@link CodecBufferInfo}. */ } OutputInfo; /** * @brief Enumerates MIME types. */ typedef enum { - MEDIA_MIMETYPE_IMAGE_JPEG = 0, /**< JPEG image */ - MEDIA_MIMETYPE_VIDEO_AVC, /**< H.264 video */ - MEDIA_MIMETYPE_VIDEO_HEVC, /**< H.265 video */ - MEDIA_MIMETYPE_AUDIO_AAC, /**< AAC audio */ - MEDIA_MIMETYPE_AUDIO_G711A, /**< G711A audio */ - MEDIA_MIMETYPE_AUDIO_G711U, /**< G711U audio */ - MEDIA_MIMETYPE_AUDIO_G726, /**< G726 audio */ - MEDIA_MIMETYPE_AUDIO_PCM, /**< PCM audio */ - MEDIA_MIMETYPE_AUDIO_MP3, /**< MP3 audio */ - MEDIA_MIMETYPE_INVALID, /**< Invalid MIME type */ + MEDIA_MIMETYPE_IMAGE_JPEG = 0, /**< JPEG image */ + MEDIA_MIMETYPE_VIDEO_AVC, /**< H.264 video */ + MEDIA_MIMETYPE_VIDEO_HEVC, /**< H.265 video */ + + MEDIA_MIMETYPE_AUDIO_FIRST = 0x10000, /**< Dummy id pointing at the start of audio codecs */ + MEDIA_MIMETYPE_AUDIO_AAC = 0x10000, /**< AAC audio */ + MEDIA_MIMETYPE_AUDIO_G711A, /**< G711A audio */ + MEDIA_MIMETYPE_AUDIO_G711U, /**< G711U audio */ + MEDIA_MIMETYPE_AUDIO_G726, /**< G726 audio */ + MEDIA_MIMETYPE_AUDIO_PCM, /**< PCM audio */ + MEDIA_MIMETYPE_AUDIO_MP3, /**< MP3 audio */ + MEDIA_MIMETYPE_INVALID, /**< Invalid MIME type */ } AvCodecMime; /** @@ -345,19 +309,6 @@ typedef enum { HEVC_LEVEL_MAIN_2, /**< H.265 Main level 2 */ } Level; -/** - * @brief Indicates the maximum number of reserved parameters in the array. - */ -#define ELEMENT_MAX_LEN 50 - -/** - * @brief Defines a variable-length queue. - */ -typedef struct { - uint32_t element[ELEMENT_MAX_LEN]; /**< Array of reserved parameters */ - uint32_t actualLen; /**< Number of actual parameters */ -} ResizableArray; - /** * @brief Defines the alignment. */ @@ -374,6 +325,14 @@ typedef struct { int32_t height; /**< Height */ } Rect; +/** + * @brief Defines a range. + */ +typedef struct { + int32_t min; /**< Lower end of the range */ + int32_t max; /**< Upper end of the range */ +} RangeValue; + /** * @brief Enumerates allocation modes of input and output buffers. */ @@ -390,26 +349,56 @@ typedef enum { typedef enum { ADAPTIVE_PLAYBACK = 0x1, /**< Adaptive playback */ SECURE_PLAYBACK = 0x2, /**< Secure playback */ + TUNNEL_PLAYBACK = 0x4, /**< Tunnel playback */ } CapsMask; +/** + * @brief Defines the video codec port capability. + */ +#define PIXEL_FMT_NUM 16 /**< Indicates the array size of supported pixel formats */ +#define LEVEL_NUM 8 /**< Indicates the array size of supported video codec level */ +typedef struct { + Rect minSize; /**< Minimum resolution supported */ + Rect maxSize; /**< Maximum resolution supported */ + Alginment whAlignment; /**< Value to align with the width and height */ + int32_t supportPixelFmts[PIXEL_FMT_NUM]; /**< Supported pixel formats, array is terminated by + PIXEL_FORMAT_INVALID */ + int32_t supportLevels[LEVEL_NUM]; /**< Supported levels, array is terminated by INVALID_LEVEL */ +} VideoPortCap; + +/** + * @brief Defines the audio codec port capability. + */ +#define SAMPLE_FMT_NUM 12 /**< Indicates the array size of supported audio sample formats */ +#define SAMPLE_RATE_NUM 16 /**< Indicates the array size of supported audio sample rate */ +#define CHANNEL_NUM 16 /**< Indicates the array size of supported audio channel count */ +typedef struct { + int32_t sampleFormats[SAMPLE_FMT_NUM]; /**< Supported audio sample formats, array is terminated by + AUDIO_SAMPLE_FMT_INVALID */ + int32_t sampleRate[SAMPLE_RATE_NUM]; /**< Supported audio sample rate, array is terminated by + AUD_SAMPLE_RATE_INVALID */ + int32_t channelCount[CHANNEL_NUM]; /**< Supported audio channel count, array is terminated by -1 */ +} AudioPortCap; + /** * @brief Defines the codec capability. */ +#define PROFILE_NUM 16 /**< Indicates the array size of supported profile */ typedef struct { - AvCodecMime mime; /**< MIME type */ - CodecType type; /**< Codec type */ - Alginment whAlignment; /**< Value to align with the width and height */ - Rect minSize; /**< Minimum resolution supported */ - Rect maxSize; /**< Maximum resolution supported */ - uint64_t minBitRate; /**< Minimum bit rate supported */ - uint64_t maxBitRate; /**< Maximum bit rate supported */ - ResizableArray supportProfiles; /**< Supported profiles */ - ResizableArray supportLevels; /**< Supported levels */ - ResizableArray supportPixelFormats; /**< Supported pixel formats */ - uint32_t minInputBufferNum; /**< Minimum number of input buffers required for running */ - uint32_t minOutputBufferNum; /**< Minimum number of output buffers required for running */ - uint32_t allocateMask; /**< Buffer allocation mode. For details, see {@link AllocateBufferMode}. */ - uint32_t capsMask; /**< Capability mask. For details, see {@link CapsMask}. */ + AvCodecMime mime; /**< MIME type */ + CodecType type; /**< Codec type */ + int32_t supportProfiles[PROFILE_NUM]; /**< Supported profiles, array is terminated by INVALID_PROFILE */ + bool isSoftwareCodec; /**< Software codec or hardware codec */ + uint32_t capsMask; /**< Capability mask. For details, see {@link CapsMask}. */ + uint32_t allocateMask; /**< Buffer allocation mode. For details, see {@link AllocateBufferMode}. */ + RangeValue inputBufferNum; /**< Range number of input buffers required for running */ + RangeValue outputBufferNum; /**< Range number of output buffers required for running */ + RangeValue bitRate; /**< Range bit rate supported */ + int32_t bufferSize; /**< Min size of external user buffer */ + union { + VideoPortCap video; + AudioPortCap audio; + } Port; } CodecCapbility; /** @@ -437,61 +426,40 @@ typedef struct { * * Reports event errors and output format changes. * - * @param hComponent Indicates the handle of the codec component. - * @param pAppData Indicates upper-layer data, which is generally + * @param userData Indicates upper-layer data, which is generally * an upper-layer instance passed when this callback is set. * @param EVENTTYPE Indicates the event type. - * @param nData1 Indicates the first value contained in the reported event. This parameter is optional. - * @param nData2 Indicates the second value contained in the reported event. This parameter is optional. - * @param pEventData Indicates the pointer to data contained in the reported event. This parameter is optional. + * @param length Indicates the the length of eventData array. This parameter is optional. + * @param eventData Indicates the pointer to data contained in the reported event. This parameter is optional. * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. */ - int (*OnEvent)(UINTPTR comp, UINTPTR appData, EventType event, - uint32_t data1, uint32_t data2, UINTPTR eventData); + int (*OnEvent)(UINTPTR userData, EventType event, uint32_t length, char eventData[]); /** * @brief Reports that the input data has been used. * * This callback is invoked in asynchronous mode. * - * @param hComponent Indicates the handle of the codec component. - * @param pAppData Indicates upper-layer data, which is generally + * @param userData Indicates upper-layer data, which is generally * an upper-layer instance passed when this callback is set. * @param pBuffer Indicates the pointer to the input data that has been used. * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. */ - int (*InputBufferAvailable)(UINTPTR comp, UINTPTR appData, InputInfo *inBuf); + int (*InputBufferAvailable)(UINTPTR userData, InputInfo *inBuf); /** * @brief Reports that the output is complete. * * This callback is invoked in asynchronous mode. * - * @param hComponent Indicates the handle of the codec component. - * @param pAppData Indicates upper-layer data, which is generally + * @param userData Indicates upper-layer data, which is generally * an upper-layer instance passed when this callback is registered. * @param pBuffer Indicates the pointer to the output data that has been generated. * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. */ - int (*OutputBufferAvailable)(UINTPTR comp, UINTPTR appData, OutputInfo *outBuf); + int (*OutputBufferAvailable)(UINTPTR userData, OutputInfo *outBuf); } CodecCallback; -/** - * @brief Enumerates input and output types. - */ -typedef enum { - INPUT_TYPE, /**< Input */ - OUTPUT_TYPE, /**< Output */ - ALL_TYPE, /**< Input and output */ -} DirectionType; - -/** - * @brief Enumerates allocation types. - */ -typedef enum { - INTERNAL, /**< Internal */ - EXTERNAL, /**< External */ -} BufferMode; /** * @brief Enumerates codec error types.