28 #include <interface/mmal/mmal.h>
29 #include <interface/mmal/util/mmal_util.h>
30 #include <interface/mmal/util/mmal_util_params.h>
31 #include <interface/mmal/util/mmal_default_components.h>
32 #include <interface/mmal/vc/mmal_vc_api.h>
92 #define MAX_DELAYED_FRAMES 16
97 mmal_pool_destroy(ref->
pool);
106 mmal_buffer_header_release(ref->
buffer);
115 MMAL_BUFFER_HEADER_T *
buffer)
127 if (!frame->
buf[0]) {
133 mmal_buffer_header_acquire(buffer);
144 MMAL_BUFFER_HEADER_T *
buffer;
146 mmal_port_disable(decoder->input[0]);
147 mmal_port_disable(decoder->output[0]);
148 mmal_port_disable(decoder->control);
150 mmal_port_flush(decoder->input[0]);
151 mmal_port_flush(decoder->output[0]);
152 mmal_port_flush(decoder->control);
155 mmal_buffer_header_release(buffer);
177 mmal_component_destroy(ctx->
decoder);
180 mmal_pool_destroy(ctx->
pool_in);
197 mmal_buffer_header_release(buffer);
205 mmal_queue_put(ctx->queue_decoded_frames, buffer);
211 MMAL_STATUS_T status;
213 if (buffer->cmd == MMAL_EVENT_ERROR) {
214 status = *(uint32_t *)buffer->data;
222 mmal_buffer_header_release(buffer);
229 MMAL_BUFFER_HEADER_T *
buffer;
230 MMAL_STATUS_T status;
235 while ((buffer = mmal_queue_get(ctx->
pool_out->
pool->queue))) {
236 if ((status = mmal_port_send_buffer(ctx->
decoder->output[0], buffer))) {
237 mmal_buffer_header_release(buffer);
238 av_log(avctx,
AV_LOG_ERROR,
"MMAL error %d when sending output buffer.\n", (
int)status);
249 case MMAL_COLOR_SPACE_BT470_2_BG:
250 case MMAL_COLOR_SPACE_BT470_2_M:
262 MMAL_STATUS_T status;
265 MMAL_ES_FORMAT_T *format_out = decoder->output[0]->format;
277 if ((status = mmal_port_parameter_set_uint32(decoder->output[0], MMAL_PARAMETER_EXTRA_BUFFERS, ctx->
extra_buffers)))
281 format_out->encoding = MMAL_ENCODING_OPAQUE;
283 format_out->encoding_variant = format_out->encoding = MMAL_ENCODING_I420;
286 if ((status = mmal_port_format_commit(decoder->output[0])))
290 format_out->es->video.crop.y + format_out->es->video.crop.height)) < 0)
293 if (format_out->es->video.par.num && format_out->es->video.par.den) {
300 decoder->output[0]->buffer_size =
301 FFMAX(decoder->output[0]->buffer_size_min, decoder->output[0]->buffer_size_recommended);
302 decoder->output[0]->buffer_num =
303 FFMAX(decoder->output[0]->buffer_num_min, decoder->output[0]->buffer_num_recommended) + ctx->
extra_buffers;
304 ctx->
pool_out->
pool = mmal_pool_create(decoder->output[0]->buffer_num,
305 decoder->output[0]->buffer_size);
320 MMAL_STATUS_T status;
321 MMAL_ES_FORMAT_T *format_in;
327 if (mmal_vc_init()) {
337 if ((status = mmal_component_create(MMAL_COMPONENT_DEFAULT_VIDEO_DECODER, &ctx->
decoder)))
342 format_in = decoder->input[0]->format;
343 format_in->type = MMAL_ES_TYPE_VIDEO;
344 format_in->encoding = MMAL_ENCODING_H264;
347 format_in->es->video.crop.width = avctx->
width;
348 format_in->es->video.crop.height = avctx->
height;
349 format_in->es->video.frame_rate.num = 24000;
350 format_in->es->video.frame_rate.den = 1001;
353 format_in->flags = MMAL_ES_FORMAT_FLAG_FRAMED;
368 if ((status = mmal_format_extradata_alloc(format_in, avctx->
extradata_size)))
371 memcpy(format_in->extradata, avctx->
extradata, format_in->extradata_size);
374 if ((status = mmal_port_format_commit(decoder->input[0])))
377 decoder->input[0]->buffer_num =
378 FFMAX(decoder->input[0]->buffer_num_min, 20);
379 decoder->input[0]->buffer_size =
380 FFMAX(decoder->input[0]->buffer_size_min, 512 * 1024);
381 ctx->
pool_in = mmal_pool_create(decoder->input[0]->buffer_num, 0);
394 decoder->input[0]->userdata = (
void*)avctx;
395 decoder->output[0]->userdata = (
void*)avctx;
396 decoder->control->userdata = (
void*)avctx;
400 if ((status = mmal_port_enable(decoder->input[0],
input_callback)))
405 if ((status = mmal_component_enable(decoder)))
419 MMAL_STATUS_T status;
425 if ((status = mmal_port_enable(decoder->input[0],
input_callback)))
457 &tmp_data, &tmp_size,
492 buffer->
flags |= MMAL_BUFFER_HEADER_FLAG_FRAME_START;
501 buffer->
flags |= MMAL_BUFFER_HEADER_FLAG_FRAME_END;
504 buffer->
flags |= MMAL_BUFFER_HEADER_FLAG_EOS;
536 MMAL_BUFFER_HEADER_T *mbuffer;
538 MMAL_STATUS_T status;
540 mbuffer = mmal_queue_get(ctx->
pool_in->queue);
546 mmal_buffer_header_reset(mbuffer);
548 mbuffer->pts = buffer->
pts;
549 mbuffer->dts = buffer->
dts;
550 mbuffer->flags = buffer->
flags;
551 mbuffer->data = buffer->
data;
552 mbuffer->length = buffer->
length;
553 mbuffer->user_data = buffer->
ref;
554 mbuffer->alloc_size = ctx->
decoder->input[0]->buffer_size;
556 if ((status = mmal_port_send_buffer(ctx->
decoder->input[0], mbuffer))) {
557 mmal_buffer_header_release(mbuffer);
577 MMAL_BUFFER_HEADER_T *
buffer)
601 ptr = buffer->data + buffer->type->video.offset[0];
602 for (i = 0; i < avctx->
height; i++)
607 for (plane = 1; plane < 3; plane++) {
608 for (i = 0; i < avctx->
height / 2; i++)
609 memcpy(frame->
data[plane] + frame->
linesize[plane] * i, ptr + w / 2 * i, (avctx->
width + 1) / 2);
610 ptr += w / 2 * h / 2;
614 if (buffer->pts != MMAL_TIME_UNKNOWN) {
616 frame->
pts = buffer->pts;
628 MMAL_STATUS_T status = 0;
654 ctx->
eos_received |= !!(buffer->flags & MMAL_BUFFER_HEADER_FLAG_EOS);
658 if (buffer->cmd == MMAL_EVENT_FORMAT_CHANGED) {
660 MMAL_EVENT_FORMAT_CHANGED_T *ev = mmal_event_format_changed_get(buffer);
661 MMAL_BUFFER_HEADER_T *stale_buffer;
665 if ((status = mmal_port_disable(decoder->output[0])))
669 mmal_buffer_header_release(stale_buffer);
671 mmal_format_copy(decoder->output[0]->format, ev->format);
685 mmal_buffer_header_release(buffer);
687 }
else if (buffer->cmd) {
692 }
else if (buffer->length == 0) {
694 mmal_buffer_header_release(buffer);
709 mmal_buffer_header_release(buffer);
710 if (status && ret >= 0)
773 .priv_class = &ffmmaldec_class,
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
const struct AVCodec * codec
#define avpriv_atomic_int_add_and_fetch
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
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.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
static av_cold int init(AVCodecContext *avctx)
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 ...
AVHWAccel ff_h264_mmal_hwaccel
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static int ffmmal_fill_output_port(AVCodecContext *avctx)
size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
Put a string representing the codec tag codec_tag in buf.
static int ffmmal_fill_input_port(AVCodecContext *avctx)
static int ffmmal_decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
MMAL_BUFFER_HEADER_T * buffer
AVColorSpace
YUV colorspace type.
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
Set various frame properties from the codec context / packet data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
static void ffmmal_flush(AVCodecContext *avctx)
static av_cold int ffmmal_init_decoder(AVCodecContext *avctx)
static const AVOption options[]
static av_cold int ffmmal_close_decoder(AVCodecContext *avctx)
#define AV_BUFFER_FLAG_READONLY
Always treat the buffer as read-only, even when it has only one reference.
static int ffmmal_add_packet(AVCodecContext *avctx, AVPacket *avpkt)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static void output_callback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
static void ffmmal_poolref_unref(FFPoolRef *ref)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_bitstream_filter_close(AVBitStreamFilterContext *bsf)
Release bitstream filter context.
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
simple assert() macros that are a bit more flexible than ISO C assert().
static int ffmmal_set_ref(AVFrame *frame, FFPoolRef *pool, MMAL_BUFFER_HEADER_T *buffer)
FFBufferEntry * waiting_buffers_tail
const char * name
Name of the codec implementation.
AVBufferRef * av_buffer_create(uint8_t *data, int size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Libavcodec external API header.
static void control_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
int flags
A combination of AV_PKT_FLAG values.
static int ffmal_copy_frame(AVCodecContext *avctx, AVFrame *frame, MMAL_BUFFER_HEADER_T *buffer)
static enum AVColorSpace ffmmal_csp_to_av_csp(MMAL_FOURCC_T fourcc)
enum AVPixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
static const AVClass ffmmaldec_class
const char * name
Name of the hardware accelerated codec.
FFBufferEntry * waiting_buffers
static const chunk_decoder decoder[8]
int width
picture width / height.
AVBitStreamFilterContext * av_bitstream_filter_init(const char *name)
Create and initialize a bitstream filter context given a bitstream filter name.
#define MAX_DELAYED_FRAMES
AVCodec ff_h264_mmal_decoder
FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
static void ffmmal_stop_decoder(AVCodecContext *avctx)
MMAL_QUEUE_T * queue_decoded_frames
static void flush(AVCodecContext *avctx)
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
#define AV_LOG_INFO
Standard information.
int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int keyframe)
Filter bitstream.
struct FFBufferEntry * next
AVBufferRef * av_buffer_alloc(int size)
Allocate an AVBuffer of the given size using av_malloc().
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
uint8_t * data
The data buffer.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static void input_callback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
Describe the class of an AVClass context structure.
enum AVColorSpace colorspace
YUV colorspace type.
refcounted data buffer API
int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
int size
Size of data in bytes.
static int ffmmal_read_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
A reference to a data buffer.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
common internal and external API header
static int ffmal_update_format(AVCodecContext *avctx)
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
static void ffmmal_release_frame(void *opaque, uint8_t *data)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
AVBitStreamFilterContext * bsfc
HW acceleration though MMAL, data[3] contains a pointer to the MMAL_BUFFER_HEADER_T structure...
AVPixelFormat
Pixel format.
This structure stores compressed data.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
MMAL_COMPONENT_T * decoder
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_NOPTS_VALUE
Undefined timestamp value.