Go to the documentation of this file.
46 int is_ref,
int in_dpb,
int prev)
126 if (current_depth ==
ctx->max_b_depth || start->
next->
next == end) {
127 for (pic = start->
next; pic; pic = pic->
next) {
146 for (pic = start->
next; pic != end; pic = pic->
next)
148 for (pic = start->
next,
i = 1; 2 * i < len; pic = pic->next,
i++);
165 current_depth + 1, &next);
170 current_depth + 1, last);
183 for (
i = 0;
i <
ctx->nb_next_prev;
i++) {
184 --
ctx->next_prev[
i]->ref_count[0];
187 ctx->next_prev[0] = pic;
189 ctx->nb_next_prev = 1;
194 if (
ctx->nb_next_prev <
ctx->ref_l0) {
195 ctx->next_prev[
ctx->nb_next_prev++] = pic;
198 --
ctx->next_prev[0]->ref_count[0];
199 for (
i = 0;
i <
ctx->ref_l0 - 1;
i++)
200 ctx->next_prev[
i] =
ctx->next_prev[
i + 1];
201 ctx->next_prev[
i] = pic;
211 int i, b_counter, closed_gop_end;
216 for (pic =
ctx->pic_start; pic; pic = pic->
next) {
238 "encode next.\n", pic->
b_depth);
247 closed_gop_end =
ctx->closed_gop ||
248 ctx->idr_counter ==
ctx->gop_per_idr;
249 for (pic =
ctx->pic_start; pic; pic = next) {
259 if (b_counter ==
ctx->b_per_p)
263 if (
ctx->gop_counter + b_counter + closed_gop_end >=
ctx->gop_size)
267 if (next && next->force_idr)
273 if (!pic &&
ctx->end_of_stream) {
284 "need more input for reference pictures.\n");
287 if (
ctx->input_order <=
ctx->decode_delay && !
ctx->end_of_stream) {
289 "need more input for timestamps.\n");
297 ctx->idr_counter = 1;
298 ctx->gop_counter = 1;
300 }
else if (
ctx->gop_counter + b_counter >=
ctx->gop_size) {
301 if (
ctx->idr_counter ==
ctx->gop_per_idr) {
305 ctx->idr_counter = 1;
312 ctx->gop_counter = 1;
315 if (
ctx->gop_counter + b_counter + closed_gop_end ==
ctx->gop_size) {
324 ctx->gop_counter += 1 + b_counter;
335 for (
i = 0;
i <
ctx->nb_next_prev;
i++)
365 for (pic =
ctx->pic_start; pic; pic = pic->
next) {
371 for (pic =
ctx->pic_start; pic; pic = pic->
next) {
378 for (pic =
ctx->pic_start; pic; pic = next) {
385 ctx->pic_start = next;
386 ctx->op->free(avctx, pic);
400 frame->crop_left ||
frame->crop_right) && !
ctx->crop_warned) {
402 "frames ignored due to lack of API support.\n");
403 ctx->crop_warned = 1;
406 if (!
ctx->roi_allowed) {
410 if (sd && !
ctx->roi_warned) {
412 "frames ignored due to lack of driver support.\n");
444 if (
ctx->recon_frames_ref) {
480 if (
ctx->input_order == 0)
481 ctx->first_pts = pic->
pts;
482 if (
ctx->input_order ==
ctx->decode_delay)
483 ctx->dts_pts_diff = pic->
pts -
ctx->first_pts;
484 if (
ctx->output_delay > 0)
485 ctx->ts_ring[
ctx->input_order %
486 (3 *
ctx->output_delay +
ctx->async_depth)] = pic->
pts;
491 if (
ctx->pic_start) {
492 ctx->pic_end->next = pic;
495 ctx->pic_start = pic;
499 err =
ctx->op->init(avctx, pic);
503 ctx->end_of_stream = 1;
507 if (
ctx->input_order <=
ctx->decode_delay)
508 ctx->dts_pts_diff =
ctx->pic_end->pts -
ctx->first_pts;
514 ctx->op->free(avctx, pic);
543 if (
ctx->output_delay == 0) {
552 (3 *
ctx->output_delay +
ctx->async_depth)];
566 ctx->op->output &&
ctx->op->free);
570 if (
ctx->tail_pkt->size) {
574 else if (!
tmp->next) {
591 if (!
ctx->pic_start) {
592 if (
ctx->end_of_stream)
598 if (
ctx->async_encode) {
605 err =
ctx->op->issue(avctx, pic);
632 err =
ctx->op->issue(avctx, pic);
641 err =
ctx->op->output(avctx, pic,
pkt);
663 uint32_t ref_l0, uint32_t ref_l1,
664 int flags,
int prediction_pre_only)
672 }
else if (ref_l0 < 1) {
674 "reference frames.\n");
680 "(supported references: %d / %d).\n",
684 "(supported references: %d / %d).\n", ref_l0, ref_l1);
686 ctx->p_per_i = INT_MAX;
691 "(supported references: %d / %d).\n",
695 "(supported references: %d / %d).\n", ref_l0, ref_l1);
697 ctx->p_per_i = INT_MAX;
703 ctx->max_b_depth = 1;
709 ctx->gop_per_idr =
ctx->idr_interval + 1;
712 ctx->gop_per_idr = 1;
738 if (
ctx->input_frames->sw_format ==
740 recon_format =
ctx->input_frames->sw_format;
751 recon_format =
ctx->input_frames->sw_format;
761 "size %dx%d (constraints: width %d-%d height %d-%d).\n",
762 ctx->surface_width,
ctx->surface_height,
778 ctx->log_ctx = (
void *)avctx;
786 "required to associate the encoding device.\n");
791 if (!
ctx->input_frames_ref)
797 if (!
ctx->device_ref)
812 next_pic = pic->next;
#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.
@ FF_HW_FLAG_B_PICTURE_REFERENCES
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)
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]
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
@ FF_HW_FLAG_NON_IDR_KEY_PICTURES
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]
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
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
static int base_encode_pic_free(FFHWBaseEncodePicture *pic)
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.
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
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