47#define MAX_DAMAGED_FRAMES 32
122 ret = key1->
gop - node1->
gop;
129 int dec = *(
int *)opaque;
145 if (!*stalest || node->
serial < (*stalest)->serial)
152 int poc,
int poc_diff,
int gop)
156 for (
int i = 0;
i < poc_diff;
i++) {
170 if (ret && ret != poc_node) {
196 s->nb_frame = -(
ctx->par_in->video_delay << 1);
204 if (
header->nal_unit_header.nal_ref_idc == 0 ||
205 !
header->adaptive_ref_pic_marking_mode_flag)
209 if (
header->mmco[
i].memory_management_control_operation == 0)
211 else if (
header->mmco[
i].memory_management_control_operation == 5)
230 s->nb_frame -= poc_diff;
235 s->gop = (
s->gop + 1) %
s->fifo_size;
243 poc,
s->gop,
pkt->dts);
244 s->nb_frame += poc_diff;
253 s->nb_pending += poc_diff;
265 int output_picture_number = INT_MIN;
273 ret = ff_cbs_read_packet(
s->cbc, au, in);
282 switch (unit->
type) {
314 header->field_pic_flag +
header->bottom_field_flag : 3);
322 field_poc[0] = field_poc[1] = INT_MAX;
325 header->nal_unit_header.nal_ref_idc);
334 if (
header->nal_unit_header.nal_ref_idc != 0) {
342 if (output_picture_number != h264->
last_poc) {
346 if ((output_picture_number < 0) && !h264->
last_poc)
360 h264->
last_poc = output_picture_number;
374 if (output_picture_number == INT_MIN) {
382 ff_cbs_fragment_reset(au);
394 memset(&h264->
sps, 0,
sizeof(h264->
sps));
395 memset(&h264->
poc, 0,
sizeof(h264->
poc));
396 s->nb_frame = -(
ctx->par_in->video_delay << 1);
408 s->nb_frame = -
ctx->par_in->video_delay;
427 int latency =
vps->vps_max_num_reorder_pics[0];
428 if (
vps->vps_max_latency_increase_plus1[0])
429 latency +=
vps->vps_max_latency_increase_plus1[0] - 1;
431 s->nb_frame = poc - latency;
433 latency, poc,
s->nb_frame);
447 if (node->
gop ==
c->gop) {
449 c->tail->next = node;
464 if (hevc->
gop == -1) {
474 s->gop = (
s->gop + 1) %
s->fifo_size;
478 if (poc < s->nb_frame && hevc->
gop ==
s->gop) {
479 int dec =
s->nb_frame - poc;
497 if (
r &&
r != node) {
511 poc,
s->gop,
s->nb_frame,
pkt->dts);
523 s->nb_pending +=
frame.poc_diff;
541 ret = ff_cbs_read_packet(
s->cbc, au, in);
571 hevc->
gop = (hevc->
gop + 1) %
s->fifo_size;
573 unsigned log2_max_poc_lsb =
sps->log2_max_pic_order_cnt_lsb_minus4 + 4;
599 ff_cbs_fragment_reset(au);
646 ret = ff_cbs_init(&
s->cbc,
ctx->par_in->codec_id,
ctx);
656 if (!
ctx->par_in->extradata_size)
659 ret = ff_cbs_read_extradata(
s->cbc, au,
ctx->par_in);
663 ff_cbs_fragment_reset(au);
677 ret =
s->filter(
ctx);
691 s->nb_pending -=
frame.poc_diff;
699 if (!poc_node || poc_node->
poc !=
frame.poc)
702 if (poc_node && poc_node->
poc ==
frame.poc) {
710 if (!poc_node || poc_node->
dts != dts)
722 }
else if (
s->eof &&
frame.poc > INT_MIN) {
725 if (poc_node && poc_node->
poc == dup.
poc) {
736 "generated from POC %d, GOP %d, dts %"PRId64
", duration %"PRId64
"\n",
786 ff_cbs_fragment_reset(&
s->au);
788 ff_cbs_flush(
s->cbc);
799 ff_cbs_fragment_free(&
s->au);
800 ff_cbs_close(&
s->cbc);
static av_cold void close(AVCodecParserContext *s)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
const FFBitStreamFilter ff_dts2pts_bsf
int ff_bsf_get_packet(AVBSFContext *ctx, AVPacket **pkt)
Called by the bitstream filters to get the next packet for filtering.
#define i(width, name, range_min, range_max)
static int FUNC sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
static int FUNC vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static int h264_filter(AVBSFContext *ctx)
static int hevc_queue_frame(AVBSFContext *ctx, AVPacket *pkt, int poc, bool *queued)
void(* flush)(AVBSFContext *ctx)
static int cmp_find(const void *key, const void *node)
static enum AVCodecID dts2pts_codec_ids[]
static void hevc_flush(AVBSFContext *ctx)
static void dts2pts_close(AVBSFContext *ctx)
static int hevc_init_nb_frame(AVBSFContext *ctx, int poc)
static int dec_poc(void *opaque, void *elem)
static const CodedBitstreamUnitType h264_decompose_unit_types[]
static int h264_init(AVBSFContext *ctx)
static int get_mmco_reset(const H264RawSliceHeader *header)
static int cmp_insert(const void *key, const void *node)
static void h264_flush(AVBSFContext *ctx)
static int hevc_init(AVBSFContext *ctx)
static const struct @213162273235257122266207155164174051374107224106 func_tab[]
int(* init)(AVBSFContext *ctx)
static int free_node(void *opaque, void *elem)
static int dts2pts_init(AVBSFContext *ctx)
static int find_stalest(void *opaque, void *elem)
static int h264_queue_frame(AVBSFContext *ctx, AVPacket *pkt, int poc, int *queued)
static int alloc_and_insert_node(AVBSFContext *ctx, int64_t ts, int64_t duration, int poc, int poc_diff, int gop)
static int dts2pts_filter(AVBSFContext *ctx, AVPacket *out)
static void dts2pts_flush(AVBSFContext *ctx)
#define MAX_DAMAGED_FRAMES
static int collect_same_gop(void *opaque, void *elem)
static int hevc_filter(AVBSFContext *ctx)
AVCodecID
Identify the syntax and semantics of the bitstream.
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EOF
End of file.
AVFifo * av_fifo_alloc2(size_t nb_elems, size_t elem_size, unsigned int flags)
Allocate and initialize an AVFifo with a given element size.
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.
#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_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_NOPTS_VALUE
Undefined timestamp value.
void av_tree_enumerate(AVTreeNode *t, void *opaque, int(*cmp)(void *opaque, void *elem), int(*enu)(void *opaque, void *elem))
Apply enu(opaque, &elem) to all the elements in the tree in a given range.
void * av_tree_insert(AVTreeNode **tp, void *key, int(*cmp)(const void *key, const void *b), AVTreeNode **next)
Insert or remove an element.
void av_tree_destroy(AVTreeNode *t)
struct AVTreeNode * av_tree_node_alloc(void)
Allocate an AVTreeNode.
int ff_h264_init_poc(int pic_field_poc[2], int *pic_poc, const SPS *sps, H264POCContext *pc, int picture_structure, int nal_ref_idc)
H.264 decoder/parser shared code.
H.264 parameter set handling.
int ff_hevc_compute_poc2(unsigned log2_max_poc_lsb, int pocTid0, int poc_lsb, int nal_unit_type)
Compute POC of the current frame and return it.
uint32_t CodedBitstreamUnitType
The codec-specific type of a bitstream unit.
#define u(width, name, range_min, range_max)
Macro definitions for various function/variable attributes.
#define FFDIFFSIGN(x, y)
Comparator.
Memory handling functions.
AVRefStructPool * av_refstruct_pool_alloc(size_t size, unsigned flags)
Equivalent to av_refstruct_pool_alloc(size, flags, NULL, NULL, NULL, NULL, NULL)
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
void * av_refstruct_pool_get(AVRefStructPool *pool)
Get an object from the pool, reusing an old one from the pool when available.
static void av_refstruct_pool_uninit(AVRefStructPool **poolp)
Mark the pool as being available for freeing.
#define AV_REFSTRUCT_POOL_FLAG_NO_ZEROING
If this flag is not set, every object in the pool will be zeroed before the init callback is called o...
static const uint8_t header[24]
#define FF_ARRAY_ELEMS(a)
The bitstream filter state.
This structure stores compressed data.
AVRefStructPool is an API for a thread-safe pool of objects managed via the RefStruct API.
Context structure for coded bitstream operations.
Coded bitstream fragment structure, combining one or more units.
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
int nb_units
Number of units in this fragment.
const H264RawSPS * active_sps
const H265RawVPS * active_vps
const H265RawSPS * active_sps
Coded bitstream unit structure.
void * content
Pointer to the decomposed form of this unit.
CodedBitstreamUnitType type
Codec-specific type of this unit.
CodedBitstreamContext * cbc
AVRefStructPool * node_pool
CodedBitstreamFragment au
int(* init)(AVBSFContext *ctx)
void(* flush)(AVBSFContext *ctx)
int(* filter)(AVBSFContext *ctx)
struct DTS2PTSNode * next
int frame_num_offset
for POC type 2
int prev_frame_num_offset
for POC type 2
int prev_frame_num
frame_num of the last pic for POC type 1/2
int prev_poc_msb
poc_msb of the last reference pic for POC type 0
int prev_poc_lsb
poc_lsb of the last reference pic for POC type 0
H264RawSliceHeader header
int poc_cycle_length
num_ref_frames_in_pic_order_cnt_cycle
int log2_max_poc_lsb
log2_max_pic_order_cnt_lsb_minus4
int32_t offset_for_ref_frame[256]
int offset_for_top_to_bottom_field
int log2_max_frame_num
log2_max_frame_num_minus4 + 4
int offset_for_non_ref_pic
int poc_type
pic_order_cnt_type
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)
static AVFormatContext * ctx
void * av_tree_find(const AVTreeNode *t, void *key, int(*cmp)(const void *key, const void *b), void *next[2])
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)