67 #if CONFIG_H264_MEDIACODEC_DECODER || CONFIG_HEVC_MEDIACODEC_DECODER
73 static const uint8_t nalu_header[] = { 0x00, 0x00, 0x00, 0x01 };
75 if (!out || !out_size) {
79 p =
av_malloc(
sizeof(nalu_header) + src_size);
85 *out_size =
sizeof(nalu_header) + src_size;
87 memcpy(p, nalu_header,
sizeof(nalu_header));
88 memcpy(p +
sizeof(nalu_header), src, src_size);
92 if (i < *out_size - 3 &&
107 memmove(p + i + 1, p + i, *out_size - (i + 1));
121 #if CONFIG_H264_MEDIACODEC_DECODER
131 int nal_length_size = 0;
133 memset(&ps, 0,
sizeof(ps));
136 &ps, &is_avc, &nal_length_size, 0, avctx);
158 if ((ret = h2645_ps_to_nalu(sps->
data, sps->
data_size, &data, &data_size)) < 0) {
164 if ((ret = h2645_ps_to_nalu(pps->
data, pps->
data_size, &data, &data_size)) < 0) {
181 #if CONFIG_HEVC_MEDIACODEC_DECODER
193 int nal_length_size = 0;
198 int vps_data_size = 0;
199 int sps_data_size = 0;
200 int pps_data_size = 0;
202 memset(&ps, 0,
sizeof(ps));
205 &ps, &is_nalff, &nal_length_size, 0, avctx);
230 if (vps && pps && sps) {
234 if ((ret = h2645_ps_to_nalu(vps->
data, vps->
data_size, &vps_data, &vps_data_size)) < 0 ||
235 (ret = h2645_ps_to_nalu(sps->
data, sps->
data_size, &sps_data, &sps_data_size)) < 0 ||
236 (ret = h2645_ps_to_nalu(pps->
data, pps->
data_size, &pps_data, &pps_data_size)) < 0) {
240 data_size = vps_data_size + sps_data_size + pps_data_size;
247 memcpy(data , vps_data, vps_data_size);
248 memcpy(data + vps_data_size , sps_data, sps_data_size);
249 memcpy(data + vps_data_size + sps_data_size, pps_data, pps_data_size);
268 #if CONFIG_MPEG4_MEDIACODEC_DECODER
281 #if CONFIG_VP8_MEDIACODEC_DECODER || CONFIG_VP9_MEDIACODEC_DECODER
298 const char *codec_mime =
NULL;
300 const char *bsf_name =
NULL;
314 #if CONFIG_H264_MEDIACODEC_DECODER
316 codec_mime =
"video/avc";
317 bsf_name =
"h264_mp4toannexb";
319 ret = h264_set_extradata(avctx, format);
324 #if CONFIG_HEVC_MEDIACODEC_DECODER
326 codec_mime =
"video/hevc";
327 bsf_name =
"hevc_mp4toannexb";
329 ret = hevc_set_extradata(avctx, format);
334 #if CONFIG_MPEG4_MEDIACODEC_DECODER
336 codec_mime =
"video/mp4v-es",
338 ret = mpeg4_set_extradata(avctx, format);
343 #if CONFIG_VP8_MEDIACODEC_DECODER
345 codec_mime =
"video/x-vnd.on2.vp8";
347 ret = vpx_set_extradata(avctx, format);
352 #if CONFIG_VP9_MEDIACODEC_DECODER
354 codec_mime =
"video/x-vnd.on2.vp9";
356 ret = vpx_set_extradata(avctx, format);
480 while (!*got_frame) {
544 #if CONFIG_H264_MEDIACODEC_DECODER
545 AVCodec ff_h264_mediacodec_decoder = {
546 .
name =
"h264_mediacodec",
560 #if CONFIG_HEVC_MEDIACODEC_DECODER
561 AVCodec ff_hevc_mediacodec_decoder = {
562 .
name =
"hevc_mediacodec",
576 #if CONFIG_MPEG4_MEDIACODEC_DECODER
577 AVCodec ff_mpeg4_mediacodec_decoder = {
578 .
name =
"mpeg4_mediacodec",
592 #if CONFIG_VP8_MEDIACODEC_DECODER
593 AVCodec ff_vp8_mediacodec_decoder = {
594 .
name =
"vp8_mediacodec",
608 #if CONFIG_VP9_MEDIACODEC_DECODER
609 AVCodec ff_vp9_mediacodec_decoder = {
610 .
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.
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
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...
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.
#define HEVC_MAX_VPS_COUNT
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.
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_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.
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 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.
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
#define HEVC_MAX_PPS_COUNT
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.