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));
120 #if CONFIG_H264_MEDIACODEC_DECODER
130 int nal_length_size = 0;
132 memset(&ps, 0,
sizeof(ps));
135 &ps, &is_avc, &nal_length_size, 0, avctx);
180 #if CONFIG_HEVC_MEDIACODEC_DECODER
192 int nal_length_size = 0;
197 int vps_data_size = 0;
198 int sps_data_size = 0;
199 int pps_data_size = 0;
201 memset(&ps, 0,
sizeof(ps));
204 &ps, &is_nalff, &nal_length_size, 0, avctx);
229 if (vps && pps && sps) {
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);
271 const char *codec_mime =
NULL;
273 const char *bsf_name =
NULL;
287 #if CONFIG_H264_MEDIACODEC_DECODER
289 codec_mime =
"video/avc";
290 bsf_name =
"h264_mp4toannexb";
292 ret = h264_set_extradata(avctx, format);
297 #if CONFIG_HEVC_MEDIACODEC_DECODER
299 codec_mime =
"video/hevc";
300 bsf_name =
"hevc_mp4toannexb";
302 ret = hevc_set_extradata(avctx, format);
424 while (!*got_frame) {
484 #if CONFIG_H264_MEDIACODEC_DECODER
485 AVCodec ff_h264_mediacodec_decoder = {
486 .
name =
"h264_mediacodec",
500 #if CONFIG_HEVC_MEDIACODEC_DECODER
501 AVCodec ff_hevc_mediacodec_decoder = {
502 .
name =
"hevc_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)
#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]