64 #if CONFIG_H264_MEDIACODEC_DECODER || CONFIG_HEVC_MEDIACODEC_DECODER
70 static const uint8_t nalu_header[] = { 0x00, 0x00, 0x00, 0x01 };
72 if (!out || !out_size) {
76 p =
av_malloc(
sizeof(nalu_header) + src_size);
82 *out_size =
sizeof(nalu_header) + src_size;
84 memcpy(p, nalu_header,
sizeof(nalu_header));
85 memcpy(p +
sizeof(nalu_header), src, src_size);
89 if (i < *out_size - 3 &&
104 memmove(p + i + 1, p + i, *out_size - (i + 1));
118 #if CONFIG_H264_MEDIACODEC_DECODER
128 int nal_length_size = 0;
130 memset(&ps, 0,
sizeof(ps));
133 &ps, &is_avc, &nal_length_size, 0, avctx);
155 if ((ret = h2645_ps_to_nalu(sps->
data, sps->
data_size, &data, &data_size)) < 0) {
161 if ((ret = h2645_ps_to_nalu(pps->
data, pps->
data_size, &data, &data_size)) < 0) {
178 #if CONFIG_HEVC_MEDIACODEC_DECODER
191 int nal_length_size = 0;
196 int vps_data_size = 0;
197 int sps_data_size = 0;
198 int pps_data_size = 0;
200 memset(&ps, 0,
sizeof(ps));
201 memset(&sei, 0,
sizeof(sei));
204 &ps, &sei, &is_nalff, &nal_length_size, 0, 1, avctx);
229 if (vps && pps && sps) {
233 if ((ret = h2645_ps_to_nalu(vps->
data, vps->
data_size, &vps_data, &vps_data_size)) < 0 ||
234 (ret = h2645_ps_to_nalu(sps->
data, sps->
data_size, &sps_data, &sps_data_size)) < 0 ||
235 (ret = h2645_ps_to_nalu(pps->
data, pps->
data_size, &pps_data, &pps_data_size)) < 0) {
239 data_size = vps_data_size + sps_data_size + pps_data_size;
246 memcpy(data , vps_data, vps_data_size);
247 memcpy(data + vps_data_size , sps_data, sps_data_size);
248 memcpy(data + vps_data_size + sps_data_size, pps_data, pps_data_size);
267 #if CONFIG_MPEG2_MEDIACODEC_DECODER
280 #if CONFIG_MPEG4_MEDIACODEC_DECODER
293 #if CONFIG_VP8_MEDIACODEC_DECODER || CONFIG_VP9_MEDIACODEC_DECODER
310 const char *codec_mime =
NULL;
323 #if CONFIG_H264_MEDIACODEC_DECODER
325 codec_mime =
"video/avc";
327 ret = h264_set_extradata(avctx, format);
332 #if CONFIG_HEVC_MEDIACODEC_DECODER
334 codec_mime =
"video/hevc";
336 ret = hevc_set_extradata(avctx, format);
341 #if CONFIG_MPEG2_MEDIACODEC_DECODER
343 codec_mime =
"video/mpeg2";
345 ret = mpeg2_set_extradata(avctx, format);
350 #if CONFIG_MPEG4_MEDIACODEC_DECODER
352 codec_mime =
"video/mp4v-es",
354 ret = mpeg4_set_extradata(avctx, format);
359 #if CONFIG_VP8_MEDIACODEC_DECODER
361 codec_mime =
"video/x-vnd.on2.vp8";
363 ret = vpx_set_extradata(avctx, format);
368 #if CONFIG_VP9_MEDIACODEC_DECODER
370 codec_mime =
"video/x-vnd.on2.vp9";
372 ret = vpx_set_extradata(avctx, format);
477 while (!*got_frame) {
518 #if CONFIG_H264_MEDIACODEC_DECODER
519 AVCodec ff_h264_mediacodec_decoder = {
520 .
name =
"h264_mediacodec",
531 .bsfs =
"h264_mp4toannexb",
535 #if CONFIG_HEVC_MEDIACODEC_DECODER
536 AVCodec ff_hevc_mediacodec_decoder = {
537 .
name =
"hevc_mediacodec",
548 .bsfs =
"hevc_mp4toannexb",
552 #if CONFIG_MPEG2_MEDIACODEC_DECODER
553 AVCodec ff_mpeg2_mediacodec_decoder = {
554 .
name =
"mpeg2_mediacodec",
568 #if CONFIG_MPEG4_MEDIACODEC_DECODER
569 AVCodec ff_mpeg4_mediacodec_decoder = {
570 .
name =
"mpeg4_mediacodec",
584 #if CONFIG_VP8_MEDIACODEC_DECODER
585 AVCodec ff_vp8_mediacodec_decoder = {
586 .
name =
"vp8_mediacodec",
600 #if CONFIG_VP9_MEDIACODEC_DECODER
601 AVCodec ff_vp9_mediacodec_decoder = {
602 .
name =
"vp9_mediacodec",
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
AVBufferRef * vps_list[HEVC_MAX_VPS_COUNT]
ptrdiff_t const GLvoid * data
static void flush(AVCodecContext *avctx)
AVBufferRef * sps_list[MAX_SPS_COUNT]
static av_cold int init(AVCodecContext *avctx)
MediaCodecDecContext * ctx
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int(*func)(void *, void *, int))
Feed data from a user-supplied callback to an AVFifoBuffer.
#define HEVC_MAX_VPS_COUNT
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
AVBufferRef * sps_list[HEVC_MAX_SPS_COUNT]
int av_fifo_space(const AVFifoBuffer *f)
Return the amount of space in bytes in the AVFifoBuffer, that is the amount of data you can write int...
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int ff_h264_decode_extradata(const uint8_t *data, int size, H264ParamSets *ps, int *is_avc, int *nal_length_size, int err_recognition, void *logctx)
void av_fifo_free(AVFifoBuffer *f)
Free an AVFifoBuffer.
AVBufferRef * pps_list[HEVC_MAX_PPS_COUNT]
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void(*func)(void *, void *, int))
Feed data from an AVFifoBuffer to a user-supplied callback.
simple assert() macros that are a bit more flexible than ISO C assert().
const char * name
Name of the codec implementation.
int width
picture width / height.
preferred ID for MPEG-1/2 video decoding
#define AV_LOG_INFO
Standard information.
Libavcodec external API header.
AVBufferRef * pps_list[MAX_PPS_COUNT]
int av_fifo_size(const AVFifoBuffer *f)
Return the amount of data in bytes in the AVFifoBuffer, that is the amount of data you can read from ...
int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)
Resize an AVFifoBuffer.
unsigned int sps_id
seq_parameter_set_id
main external API structure.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
uint8_t * data
The data buffer.
a very simple circular buffer FIFO implementation
static const char * format
#define FF_CODEC_CAP_SETS_PKT_DTS
Decoders marked with FF_CODEC_CAP_SETS_PKT_DTS want to set AVFrame.pkt_dts manually.
common internal api header.
common internal and external API header
#define HEVC_MAX_PPS_COUNT
void ff_h264_ps_uninit(H264ParamSets *ps)
Uninit H264 param sets structure.
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
#define AV_CODEC_CAP_AVOID_PROBING
Decoder is not a preferred choice for probing.
void av_fifo_reset(AVFifoBuffer *f)
Reset the AVFifoBuffer to the state right after av_fifo_alloc, in particular it is emptied...
H.264 decoder/parser shared code.
#define AVERROR_EXTERNAL
Generic error in an external library.
This structure stores compressed data.
int ff_hevc_decode_extradata(const uint8_t *data, int size, HEVCParamSets *ps, HEVCSEIContext *sei, int *is_nalff, int *nal_length_size, int err_recognition, int apply_defdispwin, void *logctx)