68 #if CONFIG_H264_MEDIACODEC_DECODER || CONFIG_HEVC_MEDIACODEC_DECODER
74 static const uint8_t nalu_header[] = { 0x00, 0x00, 0x00, 0x01 };
76 if (!out || !out_size) {
80 p =
av_malloc(
sizeof(nalu_header) + src_size);
86 *out_size =
sizeof(nalu_header) + src_size;
88 memcpy(p, nalu_header,
sizeof(nalu_header));
89 memcpy(p +
sizeof(nalu_header), src, src_size);
93 if (i < *out_size - 3 &&
108 memmove(p + i + 1, p + i, *out_size - (i + 1));
122 #if CONFIG_H264_MEDIACODEC_DECODER
132 int nal_length_size = 0;
134 memset(&ps, 0,
sizeof(ps));
137 &ps, &is_avc, &nal_length_size, 0, avctx);
159 if ((ret = h2645_ps_to_nalu(sps->
data, sps->
data_size, &data, &data_size)) < 0) {
165 if ((ret = h2645_ps_to_nalu(pps->
data, pps->
data_size, &data, &data_size)) < 0) {
182 #if CONFIG_HEVC_MEDIACODEC_DECODER
194 int nal_length_size = 0;
199 int vps_data_size = 0;
200 int sps_data_size = 0;
201 int pps_data_size = 0;
203 memset(&ps, 0,
sizeof(ps));
206 &ps, &is_nalff, &nal_length_size, 0, avctx);
231 if (vps && pps && sps) {
235 if ((ret = h2645_ps_to_nalu(vps->
data, vps->
data_size, &vps_data, &vps_data_size)) < 0 ||
236 (ret = h2645_ps_to_nalu(sps->
data, sps->
data_size, &sps_data, &sps_data_size)) < 0 ||
237 (ret = h2645_ps_to_nalu(pps->
data, pps->
data_size, &pps_data, &pps_data_size)) < 0) {
241 data_size = vps_data_size + sps_data_size + pps_data_size;
248 memcpy(data , vps_data, vps_data_size);
249 memcpy(data + vps_data_size , sps_data, sps_data_size);
250 memcpy(data + vps_data_size + sps_data_size, pps_data, pps_data_size);
269 #if CONFIG_MPEG4_MEDIACODEC_DECODER
282 #if CONFIG_VP8_MEDIACODEC_DECODER || CONFIG_VP9_MEDIACODEC_DECODER
299 const char *codec_mime =
NULL;
301 const char *bsf_name =
NULL;
315 #if CONFIG_H264_MEDIACODEC_DECODER
317 codec_mime =
"video/avc";
318 bsf_name =
"h264_mp4toannexb";
320 ret = h264_set_extradata(avctx, format);
325 #if CONFIG_HEVC_MEDIACODEC_DECODER
327 codec_mime =
"video/hevc";
328 bsf_name =
"hevc_mp4toannexb";
330 ret = hevc_set_extradata(avctx, format);
335 #if CONFIG_MPEG4_MEDIACODEC_DECODER
337 codec_mime =
"video/mp4v-es",
339 ret = mpeg4_set_extradata(avctx, format);
344 #if CONFIG_VP8_MEDIACODEC_DECODER
346 codec_mime =
"video/x-vnd.on2.vp8";
348 ret = vpx_set_extradata(avctx, format);
353 #if CONFIG_VP9_MEDIACODEC_DECODER
355 codec_mime =
"video/x-vnd.on2.vp9";
357 ret = vpx_set_extradata(avctx, format);
481 while (!*got_frame) {
545 #if CONFIG_H264_MEDIACODEC_DECODER
546 AVCodec ff_h264_mediacodec_decoder = {
547 .
name =
"h264_mediacodec",
561 #if CONFIG_HEVC_MEDIACODEC_DECODER
562 AVCodec ff_hevc_mediacodec_decoder = {
563 .
name =
"hevc_mediacodec",
577 #if CONFIG_MPEG4_MEDIACODEC_DECODER
578 AVCodec ff_mpeg4_mediacodec_decoder = {
579 .
name =
"mpeg4_mediacodec",
593 #if CONFIG_VP8_MEDIACODEC_DECODER
594 AVCodec ff_vp8_mediacodec_decoder = {
595 .
name =
"vp8_mediacodec",
609 #if CONFIG_VP9_MEDIACODEC_DECODER
610 AVCodec ff_vp9_mediacodec_decoder = {
611 .
name =
"vp9_mediacodec",
void av_bsf_free(AVBSFContext **ctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
#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.
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
The bitstream filter state.
const AVBitStreamFilter * av_bsf_get_by_name(const char *name)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
AVBufferRef * vps_list[MAX_VPS_COUNT]
int av_bsf_init(AVBSFContext *ctx)
Prepare the filter for use, after all the parameters and options have been set.
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.
int av_bsf_alloc(const AVBitStreamFilter *filter, AVBSFContext **ctx)
Allocate a context for a given bitstream filter.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
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_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
#define AVERROR_EOF
End of file.
void av_fifo_free(AVFifoBuffer *f)
Free an AVFifoBuffer.
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 CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#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 ff_hevc_decode_extradata(const uint8_t *data, int size, HEVCParamSets *ps, int *is_nalff, int *nal_length_size, int err_recognition, void *logctx)
int width
picture width / height.
AVBufferRef * pps_list[MAX_PPS_COUNT]
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
#define AVERROR_BSF_NOT_FOUND
Bitstream filter not found.
#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
int avcodec_parameters_from_context(AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
#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
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
void ff_h264_ps_uninit(H264ParamSets *ps)
Uninit H264 param sets structure.
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
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.
AVCodecParameters * par_in
Parameters of the input stream.
AVBufferRef * sps_list[MAX_SPS_COUNT]