Go to the documentation of this file.
28 #include <interface/mmal/mmal.h>
29 #include <interface/mmal/mmal_parameters_video.h>
30 #include <interface/mmal/util/mmal_util.h>
31 #include <interface/mmal/util/mmal_util_params.h>
32 #include <interface/mmal/util/mmal_default_components.h>
33 #include <interface/mmal/vc/mmal_vc_api.h>
34 #include <stdatomic.h>
102 #define MAX_DELAYED_FRAMES 16
108 mmal_pool_destroy(
ref->pool);
117 mmal_buffer_header_release(
ref->buffer);
126 MMAL_BUFFER_HEADER_T *
buffer)
138 if (!
frame->buf[0]) {
144 mmal_buffer_header_acquire(
buffer);
147 frame->data[3] = (uint8_t *)
ref->buffer;
155 MMAL_BUFFER_HEADER_T *
buffer;
157 mmal_port_disable(
decoder->input[0]);
158 mmal_port_disable(
decoder->output[0]);
159 mmal_port_disable(
decoder->control);
161 mmal_port_flush(
decoder->input[0]);
162 mmal_port_flush(
decoder->output[0]);
163 mmal_port_flush(
decoder->control);
165 while ((
buffer = mmal_queue_get(
ctx->queue_decoded_frames)))
166 mmal_buffer_header_release(
buffer);
168 while (
ctx->waiting_buffers) {
173 if (
buffer->
flags & MMAL_BUFFER_HEADER_FLAG_FRAME_END)
179 ctx->waiting_buffers_tail =
NULL;
183 ctx->frames_output =
ctx->eos_received =
ctx->eos_sent =
ctx->packets_sent =
ctx->extradata_sent = 0;
193 mmal_component_destroy(
ctx->decoder);
195 mmal_queue_destroy(
ctx->queue_decoded_frames);
196 mmal_pool_destroy(
ctx->pool_in);
212 if (entry->
flags & MMAL_BUFFER_HEADER_FLAG_FRAME_END)
216 mmal_buffer_header_release(
buffer);
224 mmal_queue_put(
ctx->queue_decoded_frames,
buffer);
232 if (
buffer->cmd == MMAL_EVENT_ERROR) {
240 mmal_buffer_header_release(
buffer);
247 MMAL_BUFFER_HEADER_T *
buffer;
253 while ((
buffer = mmal_queue_get(
ctx->pool_out->pool->queue))) {
254 if ((
status = mmal_port_send_buffer(
ctx->decoder->output[0],
buffer))) {
255 mmal_buffer_header_release(
buffer);
267 case MMAL_COLOR_SPACE_BT470_2_BG:
268 case MMAL_COLOR_SPACE_BT470_2_M:
283 MMAL_ES_FORMAT_T *format_out =
decoder->output[0]->format;
284 MMAL_PARAMETER_VIDEO_INTERLACE_TYPE_T interlace_type;
296 if ((
status = mmal_port_parameter_set_uint32(
decoder->output[0], MMAL_PARAMETER_EXTRA_BUFFERS,
ctx->extra_buffers)))
299 if ((
status = mmal_port_parameter_set_boolean(
decoder->output[0], MMAL_PARAMETER_VIDEO_INTERPOLATE_TIMESTAMPS, 0)))
303 format_out->encoding = MMAL_ENCODING_OPAQUE;
305 format_out->encoding_variant = format_out->encoding = MMAL_ENCODING_I420;
311 interlace_type.hdr.id = MMAL_PARAMETER_VIDEO_INTERLACE_TYPE;
312 interlace_type.hdr.size =
sizeof(MMAL_PARAMETER_VIDEO_INTERLACE_TYPE_T);
313 status = mmal_port_parameter_get(
decoder->output[0], &interlace_type.hdr);
314 if (
status != MMAL_SUCCESS) {
317 ctx->interlaced_frame = (interlace_type.eMode != MMAL_InterlaceProgressive);
318 ctx->top_field_first = (interlace_type.eMode == MMAL_InterlaceFieldsInterleavedUpperFirst);
322 format_out->es->video.crop.y + format_out->es->video.crop.height)) < 0)
325 if (format_out->es->video.par.num && format_out->es->video.par.den) {
329 if (format_out->es->video.frame_rate.num && format_out->es->video.frame_rate.den) {
330 avctx->
framerate.
num = format_out->es->video.frame_rate.num;
331 avctx->
framerate.
den = format_out->es->video.frame_rate.den;
336 decoder->output[0]->buffer_size =
338 decoder->output[0]->buffer_num =
339 FFMAX(
decoder->output[0]->buffer_num_min,
decoder->output[0]->buffer_num_recommended) +
ctx->extra_buffers;
340 ctx->pool_out->pool = mmal_pool_create(
decoder->output[0]->buffer_num,
341 decoder->output[0]->buffer_size);
342 if (!
ctx->pool_out->pool) {
357 MMAL_ES_FORMAT_T *format_in;
365 if (mmal_vc_init()) {
375 if ((
status = mmal_component_create(MMAL_COMPONENT_DEFAULT_VIDEO_DECODER, &
ctx->decoder)))
380 format_in =
decoder->input[0]->format;
381 format_in->type = MMAL_ES_TYPE_VIDEO;
384 format_in->encoding = MMAL_ENCODING_MP2V;
387 format_in->encoding = MMAL_ENCODING_MP4V;
390 format_in->encoding = MMAL_ENCODING_WVC1;
394 format_in->encoding = MMAL_ENCODING_H264;
399 format_in->es->video.crop.width = avctx->
width;
400 format_in->es->video.crop.height = avctx->
height;
401 format_in->es->video.frame_rate.num = 24000;
402 format_in->es->video.frame_rate.den = 1001;
405 format_in->flags = MMAL_ES_FORMAT_FLAG_FRAMED;
410 #if HAVE_MMAL_PARAMETER_VIDEO_MAX_NUM_CALLBACKS
411 if (mmal_port_parameter_set_uint32(
decoder->input[0], MMAL_PARAMETER_VIDEO_MAX_NUM_CALLBACKS,
412 -1 -
ctx->extra_decoder_buffers)) {
420 decoder->input[0]->buffer_num =
422 decoder->input[0]->buffer_size =
424 ctx->pool_in = mmal_pool_create(
decoder->input[0]->buffer_num, 0);
433 ctx->queue_decoded_frames = mmal_queue_create();
434 if (!
ctx->queue_decoded_frames)
437 decoder->input[0]->userdata = (
void*)avctx;
438 decoder->output[0]->userdata = (
void*)avctx;
439 decoder->control->userdata = (
void*)avctx;
491 uint8_t *
data = (uint8_t *)
"";
507 if (!
ctx->packets_sent) {
510 ctx->eos_received = 1;
531 buffer->
flags |= MMAL_BUFFER_HEADER_FLAG_FRAME_START;
540 buffer->
flags |= MMAL_BUFFER_HEADER_FLAG_FRAME_END;
559 if (!
ctx->waiting_buffers)
561 if (
ctx->waiting_buffers_tail)
562 ctx->waiting_buffers_tail->next =
buffer;
576 while (
ctx->waiting_buffers) {
577 MMAL_BUFFER_HEADER_T *mbuffer;
581 mbuffer = mmal_queue_get(
ctx->pool_in->queue);
587 mmal_buffer_header_reset(mbuffer);
590 mbuffer->dts =
buffer->dts;
593 mbuffer->length =
buffer->length;
594 mbuffer->user_data =
buffer;
595 mbuffer->alloc_size =
ctx->decoder->input[0]->buffer_size;
600 ctx->waiting_buffers_tail =
NULL;
602 if ((
status = mmal_port_send_buffer(
ctx->decoder->input[0], mbuffer))) {
603 mmal_buffer_header_release(mbuffer);
605 if (
buffer->
flags & MMAL_BUFFER_HEADER_FLAG_FRAME_END)
620 MMAL_BUFFER_HEADER_T *
buffer)
625 frame->interlaced_frame =
ctx->interlaced_frame;
626 frame->top_field_first =
ctx->top_field_first;
674 if (
ctx->eos_received)
690 (
ctx->packets_sent &&
ctx->eos_sent)) {
695 buffer = mmal_queue_timedwait(
ctx->queue_decoded_frames, 100);
702 buffer = mmal_queue_get(
ctx->queue_decoded_frames);
707 ctx->eos_received |= !!(
buffer->
flags & MMAL_BUFFER_HEADER_FLAG_EOS);
708 if (
ctx->eos_received)
711 if (
buffer->cmd == MMAL_EVENT_FORMAT_CHANGED) {
713 MMAL_EVENT_FORMAT_CHANGED_T *ev = mmal_event_format_changed_get(
buffer);
714 MMAL_BUFFER_HEADER_T *stale_buffer;
721 while ((stale_buffer = mmal_queue_get(
ctx->queue_decoded_frames)))
722 mmal_buffer_header_release(stale_buffer);
724 mmal_format_copy(
decoder->output[0]->format, ev->format);
738 mmal_buffer_header_release(
buffer);
744 }
else if (
buffer->length == 0) {
746 mmal_buffer_header_release(
buffer);
750 ctx->frames_output++;
761 mmal_buffer_header_release(
buffer);
777 ctx->extradata_sent = 1;
807 if (!got_frame &&
ret == 0)
820 {
"extra_decoder_buffers",
"extra MMAL internal buffered frames", offsetof(
MMALDecodeContext, extra_decoder_buffers),
AV_OPT_TYPE_INT, {.i64 = 10}, 0, 256, 0},
831 #define FFMMAL_DEC(NAME, ID) \
832 const FFCodec ff_##NAME##_mmal_decoder = { \
833 .p.name = #NAME "_mmal", \
834 .p.long_name = NULL_IF_CONFIG_SMALL(#NAME " (mmal)"), \
835 .p.type = AVMEDIA_TYPE_VIDEO, \
837 .priv_data_size = sizeof(MMALDecodeContext), \
838 .init = ffmmal_init_decoder, \
839 .close = ffmmal_close_decoder, \
840 FF_CODEC_RECEIVE_FRAME_CB(ffmmal_receive_frame), \
841 .flush = ffmmal_flush, \
842 .p.priv_class = &ffmmal_dec_class, \
843 .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE, \
844 .caps_internal = FF_CODEC_CAP_SETS_PKT_DTS, \
845 .p.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_MMAL, \
846 AV_PIX_FMT_YUV420P, \
848 .hw_configs = mmal_hw_configs, \
849 .p.wrapper_name = "mmal", \
#define FFMMAL_DEC(NAME, ID)
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
static int ffmmal_fill_input_port(AVCodecContext *avctx)
int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Called by decoders to get the next packet for decoding.
#define AV_LOG_WARNING
Something somehow does not look correct.
they must not be accessed directly The fifo field contains the frames that are queued in the input for processing by the filter The status_in and status_out fields contains the queued status(EOF or error) of the link
static int ffmmal_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
int extra_decoder_buffers
enum AVColorSpace colorspace
YUV colorspace type.
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
@ AV_PIX_FMT_MMAL
HW acceleration though MMAL, data[3] contains a pointer to the MMAL_BUFFER_HEADER_T structure.
MMAL_BUFFER_HEADER_T * buffer
enum AVPixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
MMAL_COMPONENT_T * decoder
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
static int ffmmal_fill_output_port(AVCodecContext *avctx)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
static const chunk_decoder decoder[8]
static void ffmmal_poolref_unref(FFPoolRef *ref)
const struct AVCodec * codec
static const AVCodecHWConfigInternal *const mmal_hw_configs[]
static const AVOption options[]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
struct FFBufferEntry * next
#define AV_BUFFER_FLAG_READONLY
Always treat the buffer as read-only, even when it has only one reference.
static void ffmmal_flush(AVCodecContext *avctx)
static enum AVColorSpace ffmmal_csp_to_av_csp(MMAL_FOURCC_T fourcc)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static int ffmmal_set_ref(AVFrame *frame, FFPoolRef *pool, MMAL_BUFFER_HEADER_T *buffer)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
MMAL_QUEUE_T * queue_decoded_frames
#define atomic_load(object)
#define MAX_DELAYED_FRAMES
static void control_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
static void output_callback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
static av_cold int ffmmal_init_decoder(AVCodecContext *avctx)
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
static int ffmal_copy_frame(AVCodecContext *avctx, AVFrame *frame, MMAL_BUFFER_HEADER_T *buffer)
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
struct AVCodecInternal * internal
Private context used for internal data.
const char * av_default_item_name(void *ptr)
Return the context name.
static av_cold int ffmmal_close_decoder(AVCodecContext *avctx)
static void ffmmal_stop_decoder(AVCodecContext *avctx)
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int av_image_fill_arrays(uint8_t *dst_data[4], int dst_linesize[4], const uint8_t *src, enum AVPixelFormat pix_fmt, int width, int height, int align)
Setup the data pointers and linesizes based on the specified image parameters and the provided array.
#define atomic_fetch_add_explicit(object, operand, order)
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define HW_CONFIG_INTERNAL(format)
static int ffmmal_read_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
FFBufferEntry * waiting_buffers_tail
int av_packet_make_refcounted(AVPacket *pkt)
Ensure the data described by a given packet is reference counted.
#define AV_LOG_INFO
Standard information.
@ AVCOL_SPC_SMPTE240M
derived from 170M primaries and D65 white point, 170M is derived from BT470 System M's primaries
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVColorSpace
YUV colorspace type.
AVPacket * in_pkt
This packet is used to hold the packet given to decoders implementing the .decode API; it is unused b...
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
static int ffmal_update_format(AVCodecContext *avctx)
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
Set various frame properties from the codec context / packet data.
main external API structure.
void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], const uint8_t *src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image in src_data to dst_data.
static void input_callback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
FFBufferEntry * waiting_buffers
#define atomic_fetch_add(object, operand)
@ AVCOL_SPC_FCC
FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
static int ref[MAX_W *MAX_W]
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
A reference to a data buffer.
atomic_int packets_buffered
This structure stores compressed data.
static void ffmmal_release_frame(void *opaque, uint8_t *data)
int width
picture width / height.
static int ffmmal_add_packet(AVCodecContext *avctx, AVPacket *avpkt, int is_extradata)
#define atomic_init(obj, value)
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
static const AVClass ffmmal_dec_class
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
#define av_fourcc2str(fourcc)