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)
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 ||
ctx->get_recon_frame) {
451 if (
ctx->get_recon_frame)
484 if (
ctx->input_order == 0)
485 ctx->first_pts = pic->
pts;
486 if (
ctx->input_order ==
ctx->decode_delay)
487 ctx->dts_pts_diff = pic->
pts -
ctx->first_pts;
488 if (
ctx->output_delay > 0)
489 ctx->ts_ring[
ctx->input_order %
490 (3 *
ctx->output_delay +
ctx->async_depth)] = pic->
pts;
495 if (
ctx->pic_start) {
496 ctx->pic_end->next = pic;
499 ctx->pic_start = pic;
503 err =
ctx->op->init(avctx, pic);
507 ctx->end_of_stream = 1;
511 if (
ctx->input_order <=
ctx->decode_delay)
512 ctx->dts_pts_diff =
ctx->pic_end->pts -
ctx->first_pts;
518 ctx->op->free(avctx, pic);
547 if (
ctx->output_delay == 0) {
551 pkt->dts = INT64_MIN;
556 (3 *
ctx->output_delay +
ctx->async_depth)];
570 ctx->op->output &&
ctx->op->free);
574 if (
ctx->tail_pkt->size) {
578 else if (!
tmp->next) {
595 if (!
ctx->pic_start) {
596 if (
ctx->end_of_stream)
602 if (
ctx->async_encode) {
609 err =
ctx->op->issue(avctx, pic);
636 err =
ctx->op->issue(avctx, pic);
645 err =
ctx->op->output(avctx, pic,
pkt);
655 if (
ctx->end_of_stream && !
pkt->size)
661 "size %d bytes.\n",
pkt->pts,
pkt->dts,
pkt->size);
667 uint32_t ref_l0, uint32_t ref_l1,
668 int flags,
int prediction_pre_only)
673 if (avctx->
refs > 0) {
681 }
else if (ref_l0 < 1) {
683 "reference frames.\n");
689 "(supported references: %d / %d).\n",
693 "(supported references: %d / %d).\n", ref_l0, ref_l1);
695 ctx->p_per_i = INT_MAX;
700 "(supported references: %d / %d).\n",
704 "(supported references: %d / %d).\n", ref_l0, ref_l1);
706 ctx->p_per_i = INT_MAX;
712 ctx->max_b_depth = 1;
718 ctx->gop_per_idr =
ctx->idr_interval + 1;
721 ctx->gop_per_idr = 1;
747 if (
ctx->input_frames->sw_format ==
749 recon_format =
ctx->input_frames->sw_format;
760 recon_format =
ctx->input_frames->sw_format;
770 "size %dx%d (constraints: width %d-%d height %d-%d).\n",
771 ctx->surface_width,
ctx->surface_height,
787 ctx->log_ctx = (
void *)avctx;
795 "required to associate the encoding device.\n");
800 if (!
ctx->input_frames_ref)
806 if (!
ctx->device_ref)
821 next_pic = pic->next;
static AVFormatContext * ctx
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
common internal and external API header
int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame)
Called by encoders to get the next frame for encoding.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define AV_CODEC_FLAG_CLOSED_GOP
#define AV_CODEC_FLAG_COPY_OPAQUE
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
#define AVERROR_EOF
End of file.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
size_t av_fifo_can_write(const AVFifo *f)
size_t av_fifo_can_read(const AVFifo *f)
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
@ AV_FRAME_DATA_REGIONS_OF_INTEREST
Regions Of Interest, the data is an array of AVRegionOfInterest type, the number of array element is ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AV_PICTURE_TYPE_I
Intra.
static void hw_base_encode_add_ref(FFHWBaseEncodePicture *pic, FFHWBaseEncodePicture *target, int is_ref, int in_dpb, int prev)
static void hw_base_encode_remove_refs(FFHWBaseEncodePicture *pic, int level)
int ff_hw_base_encode_receive_packet(FFHWBaseEncodeContext *ctx, AVCodecContext *avctx, AVPacket *pkt)
int ff_hw_base_encode_set_output_property(FFHWBaseEncodeContext *ctx, AVCodecContext *avctx, FFHWBaseEncodePicture *pic, AVPacket *pkt, int flag_no_delay)
static void hw_base_encode_add_next_prev(FFHWBaseEncodeContext *ctx, FFHWBaseEncodePicture *pic)
int ff_hw_base_encode_init(AVCodecContext *avctx, FFHWBaseEncodeContext *ctx)
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)
static int hw_base_encode_send_frame(AVCodecContext *avctx, FFHWBaseEncodeContext *ctx, AVFrame *frame)
int ff_hw_base_get_recon_format(FFHWBaseEncodeContext *ctx, const void *hwconfig, enum AVPixelFormat *fmt)
static int hw_base_encode_check_frame(FFHWBaseEncodeContext *ctx, const AVFrame *frame)
static void hw_base_encode_set_b_pictures(FFHWBaseEncodeContext *ctx, FFHWBaseEncodePicture *start, FFHWBaseEncodePicture *end, FFHWBaseEncodePicture *prev, int current_depth, FFHWBaseEncodePicture **last)
static int hw_base_encode_pick_next(AVCodecContext *avctx, FFHWBaseEncodeContext *ctx, FFHWBaseEncodePicture **pic_out)
static int hw_base_encode_clear_old(AVCodecContext *avctx, FFHWBaseEncodeContext *ctx)
static int base_encode_pic_free(FFHWBaseEncodePicture *pic)
int ff_hw_base_encode_close(FFHWBaseEncodeContext *ctx)
#define MAX_PICTURE_REFERENCES
@ FF_HW_FLAG_NON_IDR_KEY_PICTURES
@ FF_HW_FLAG_B_PICTURE_REFERENCES
void av_hwframe_constraints_free(AVHWFramesConstraints **constraints)
Free an AVHWFrameConstraints structure.
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...
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
common internal API header
Memory handling functions.
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.
AVPixelFormat
Pixel format.
main external API structure.
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames.
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...
const struct AVCodec * codec
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
int refs
number of reference frames
int flags
AV_CODEC_FLAG_*.
int capabilities
Codec capabilities.
Structure to hold side data for an AVFrame.
This structure describes decoded (raw) audio or video data.
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
int max_width
The maximum size of frames in this hw_frames_ctx.
enum AVPixelFormat * valid_sw_formats
A list of possible values for sw_format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
int min_width
The minimum size of frames in this hw_frames_ctx.
This struct describes a set or pool of "hardware" frames (i.e.
This structure stores compressed data.
struct FFHWBaseEncodePicture * dpb[MAX_DPB_SIZE]
struct FFHWBaseEncodePicture * prev
struct FFHWBaseEncodePicture * next
int nb_refs[MAX_REFERENCE_LIST_NUM]
struct FFHWBaseEncodePicture * refs[MAX_REFERENCE_LIST_NUM][MAX_PICTURE_REFERENCES]
static int ref[MAX_W *MAX_W]