Go to the documentation of this file.
32 int is_ref,
int in_dpb,
int prev)
112 if (current_depth ==
ctx->max_b_depth || start->
next->
next == end) {
113 for (pic = start->
next; pic; pic = pic->
next) {
132 for (pic = start->
next; pic != end; pic = pic->
next)
134 for (pic = start->
next,
i = 1; 2 * i < len; pic = pic->next,
i++);
151 current_depth + 1, &next);
156 current_depth + 1, last);
169 for (
i = 0;
i <
ctx->nb_next_prev;
i++) {
170 --
ctx->next_prev[
i]->ref_count[0];
173 ctx->next_prev[0] = pic;
175 ctx->nb_next_prev = 1;
181 ctx->next_prev[
ctx->nb_next_prev++] = pic;
184 --
ctx->next_prev[0]->ref_count[0];
186 ctx->next_prev[
i] =
ctx->next_prev[
i + 1];
187 ctx->next_prev[
i] = pic;
197 int i, b_counter, closed_gop_end;
202 for (pic =
ctx->pic_start; pic; pic = pic->
next) {
224 "encode next.\n", pic->
b_depth);
233 closed_gop_end =
ctx->closed_gop ||
234 ctx->idr_counter ==
ctx->gop_per_idr;
235 for (pic =
ctx->pic_start; pic; pic = next) {
245 if (b_counter ==
ctx->b_per_p)
249 if (
ctx->gop_counter + b_counter + closed_gop_end >=
ctx->gop_size)
253 if (next && next->force_idr)
259 if (!pic &&
ctx->end_of_stream) {
270 "need more input for reference pictures.\n");
273 if (
ctx->input_order <=
ctx->decode_delay && !
ctx->end_of_stream) {
275 "need more input for timestamps.\n");
283 ctx->idr_counter = 1;
284 ctx->gop_counter = 1;
286 }
else if (
ctx->gop_counter + b_counter >=
ctx->gop_size) {
287 if (
ctx->idr_counter ==
ctx->gop_per_idr) {
291 ctx->idr_counter = 1;
298 ctx->gop_counter = 1;
301 if (
ctx->gop_counter + b_counter + closed_gop_end ==
ctx->gop_size) {
310 ctx->gop_counter += 1 + b_counter;
321 for (
i = 0;
i <
ctx->nb_next_prev;
i++)
351 for (pic =
ctx->pic_start; pic; pic = pic->
next) {
357 for (pic =
ctx->pic_start; pic; pic = pic->
next) {
364 for (pic =
ctx->pic_start; pic; pic = next) {
371 ctx->pic_start = next;
372 ctx->op->free(avctx, pic);
385 frame->crop_left ||
frame->crop_right) && !
ctx->crop_warned) {
387 "frames ignored due to lack of API support.\n");
388 ctx->crop_warned = 1;
391 if (!
ctx->roi_allowed) {
395 if (sd && !
ctx->roi_warned) {
397 "frames ignored due to lack of driver support.\n");
451 if (
ctx->input_order == 0)
452 ctx->first_pts = pic->
pts;
453 if (
ctx->input_order ==
ctx->decode_delay)
454 ctx->dts_pts_diff = pic->
pts -
ctx->first_pts;
455 if (
ctx->output_delay > 0)
456 ctx->ts_ring[
ctx->input_order %
457 (3 *
ctx->output_delay +
ctx->async_depth)] = pic->
pts;
462 if (
ctx->pic_start) {
463 ctx->pic_end->next = pic;
466 ctx->pic_start = pic;
471 ctx->end_of_stream = 1;
475 if (
ctx->input_order <=
ctx->decode_delay)
476 ctx->dts_pts_diff =
ctx->pic_end->pts -
ctx->first_pts;
482 ctx->op->free(avctx, pic);
510 if (
ctx->output_delay == 0) {
519 (3 *
ctx->output_delay +
ctx->async_depth)];
533 ctx->op->output &&
ctx->op->free);
537 if (
ctx->tail_pkt->size) {
541 else if (!
tmp->next) {
558 if (!
ctx->pic_start) {
559 if (
ctx->end_of_stream)
565 if (
ctx->async_encode) {
572 err =
ctx->op->issue(avctx, pic);
599 err =
ctx->op->issue(avctx, pic);
608 err =
ctx->op->output(avctx, pic,
pkt);
630 uint32_t ref_l0, uint32_t ref_l1,
631 int flags,
int prediction_pre_only)
636 }
else if (ref_l0 < 1) {
638 "reference frames.\n");
644 "(supported references: %d / %d).\n",
648 "(supported references: %d / %d).\n", ref_l0, ref_l1);
650 ctx->p_per_i = INT_MAX;
655 "(supported references: %d / %d).\n",
659 "(supported references: %d / %d).\n", ref_l0, ref_l1);
661 ctx->p_per_i = INT_MAX;
667 ctx->max_b_depth = 1;
673 ctx->gop_per_idr =
ctx->idr_interval + 1;
676 ctx->gop_per_idr = 1;
702 if (
ctx->input_frames->sw_format ==
704 recon_format =
ctx->input_frames->sw_format;
715 recon_format =
ctx->input_frames->sw_format;
725 "size %dx%d (constraints: width %d-%d height %d-%d).\n",
726 ctx->surface_width,
ctx->surface_height,
753 ctx->log_ctx = (
void *)avctx;
761 "required to associate the encoding device.\n");
766 if (!
ctx->input_frames_ref)
772 if (!
ctx->device_ref)
#define AV_LOG_WARNING
Something somehow does not look correct.
AVPixelFormat
Pixel format.
size_t av_fifo_can_write(const AVFifo *f)
struct FFHWBaseEncodePicture * next
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
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
#define AVERROR_EOF
End of file.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
int capabilities
Codec capabilities.
int ff_hw_base_encode_init(AVCodecContext *avctx, FFHWBaseEncodeContext *ctx)
#define AV_LOG_VERBOSE
Detailed information.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
static void hw_base_encode_add_ref(FFHWBaseEncodePicture *pic, FFHWBaseEncodePicture *target, int is_ref, int in_dpb, int prev)
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
AVHWFramesConstraints * av_hwdevice_get_hwframe_constraints(AVBufferRef *ref, const void *hwconfig)
Get the constraints on HW frames given a device and the HW-specific configuration to be used with tha...
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
#define AV_CODEC_FLAG_COPY_OPAQUE
const struct AVCodec * codec
AVBufferRef * opaque_ref
AVBufferRef for free use by the API user.
int ff_hw_base_encode_close(FFHWBaseEncodeContext *ctx)
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
int min_width
The minimum size of frames in this hw_frames_ctx.
int flags
AV_CODEC_FLAG_*.
int ff_hw_base_init_gop_structure(FFHWBaseEncodeContext *ctx, AVCodecContext *avctx, uint32_t ref_l0, uint32_t ref_l1, int flags, int prediction_pre_only)
struct FFHWBaseEncodePicture * prev
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
int ff_hw_base_get_recon_format(FFHWBaseEncodeContext *ctx, const void *hwconfig, enum AVPixelFormat *fmt)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int hw_base_encode_clear_old(AVCodecContext *avctx, FFHWBaseEncodeContext *ctx)
int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
enum AVPixelFormat * valid_sw_formats
A list of possible values for sw_format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
void av_hwframe_constraints_free(AVHWFramesConstraints **constraints)
Free an AVHWFrameConstraints structure.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static void hw_base_encode_set_b_pictures(FFHWBaseEncodeContext *ctx, FFHWBaseEncodePicture *start, FFHWBaseEncodePicture *end, FFHWBaseEncodePicture *prev, int current_depth, FFHWBaseEncodePicture **last)
void * opaque
for some private data of the user
struct FFHWBaseEncodePicture * dpb[MAX_DPB_SIZE]
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
@ AV_PICTURE_TYPE_I
Intra.
size_t av_fifo_can_read(const AVFifo *f)
@ FF_HW_FLAG_B_PICTURE_REFERENCES
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
int ff_hw_base_encode_set_output_property(FFHWBaseEncodeContext *ctx, AVCodecContext *avctx, FFHWBaseEncodePicture *pic, AVPacket *pkt, int flag_no_delay)
static int hw_base_encode_check_frame(FFHWBaseEncodeContext *ctx, const AVFrame *frame)
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
int nb_refs[MAX_REFERENCE_LIST_NUM]
int ff_hw_base_encode_receive_packet(FFHWBaseEncodeContext *ctx, AVCodecContext *avctx, AVPacket *pkt)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
int max_width
The maximum size of frames in this hw_frames_ctx.
int flags
A combination of AV_PKT_FLAG values.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
struct FFHWBaseEncodePicture * refs[MAX_REFERENCE_LIST_NUM][MAX_PICTURE_REFERENCES]
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
int ff_hw_base_encode_free(FFHWBaseEncodePicture *pic)
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames.
This struct describes a set or pool of "hardware" frames (i.e.
static void hw_base_encode_add_next_prev(FFHWBaseEncodeContext *ctx, FFHWBaseEncodePicture *pic)
#define AV_CODEC_FLAG_CLOSED_GOP
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
main external API structure.
static int hw_base_encode_pick_next(AVCodecContext *avctx, FFHWBaseEncodeContext *ctx, FFHWBaseEncodePicture **pic_out)
static void hw_base_encode_remove_refs(FFHWBaseEncodePicture *pic, int level)
static int ref[MAX_W *MAX_W]
static int hw_base_encode_send_frame(AVCodecContext *avctx, FFHWBaseEncodeContext *ctx, AVFrame *frame)
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
int max_b_frames
maximum number of B-frames between non-B-frames Note: The output will be delayed by max_b_frames+1 re...
int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame)
Called by encoders to get the next frame for encoding.
Structure to hold side data for an AVFrame.
This structure stores compressed data.
@ AV_FRAME_DATA_REGIONS_OF_INTEREST
Regions Of Interest, the data is an array of AVRegionOfInterest type, the number of array element is ...
#define flags(name, subs,...)
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
@ FF_HW_FLAG_NON_IDR_KEY_PICTURES
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
#define MAX_PICTURE_REFERENCES