Go to the documentation of this file.
34 #include "startcode.h"
58 for (
size_t i = 0;
i <
len;
i++)
66 static const int metadata_obu_types[] = {
83 static const int extradata_obu_types[] = {
102 int extradata_size = 0, filtered_size = 0;
103 int i, has_seq = 0,
ret = 0;
109 for (
i = 0;
i <
s->av1_pkt.nb_obus;
i++) {
120 if (extradata_size && has_seq) {
140 *
size = extradata_size;
146 for (
i = 0;
i <
s->av1_pkt.nb_obus;
i++) {
150 }
else if (
s->remove) {
169 static const int extradata_nal_types_vvc[] = {
172 static const int extradata_nal_types_hevc[] = {
175 static const int extradata_nal_types_h264[] = {
181 int extradata_size = 0, filtered_size = 0;
182 const int *extradata_nal_types;
183 size_t nb_extradata_nal_types;
184 int filtered_nb_nals = 0;
185 int i, has_sps = 0, has_vps = 0,
ret = 0;
188 extradata_nal_types = extradata_nal_types_vvc;
191 extradata_nal_types = extradata_nal_types_hevc;
192 nb_extradata_nal_types =
FF_ARRAY_ELEMS(extradata_nal_types_hevc);
194 extradata_nal_types = extradata_nal_types_h264;
195 nb_extradata_nal_types =
FF_ARRAY_ELEMS(extradata_nal_types_h264);
203 for (
i = 0;
i <
s->h2645_pkt.nb_nals;
i++) {
205 if (
val_in_array(extradata_nal_types, nb_extradata_nal_types,
nal->type)) {
206 extradata_size +=
nal->raw_size + 4;
217 filtered_size +=
nal->raw_size + 3 +
222 if (extradata_size &&
245 *
size = extradata_size;
251 filtered_nb_nals = 0;
252 for (
i = 0;
i <
s->h2645_pkt.nb_nals;
i++) {
254 if (
val_in_array(extradata_nal_types, nb_extradata_nal_types,
256 bytestream2_put_be32u(&pb_extradata, 1);
258 }
else if (
s->remove) {
260 bytestream2_put_byteu(&pb_filtered_data, 0);
261 bytestream2_put_be24u(&pb_filtered_data, 1);
284 int *extradata_sizep,
int *data_sizep,
const H2645NAL *
nal)
288 int skipped_byte_pos = 0;
289 int extradata_size = 0, data_size = 0;
297 unsigned nalu_header = bytestream2_get_be16u(&gbc);
300 bytestream2_put_be16u(
data, nalu_header);
306 int payload_size_type, payload_type;
307 uint64_t payload_size;
308 int block_size, raw_block_size, block_end;
313 payload_size_type =
get_bits(&gb, 3);
315 payload_size = payload_size_type;
316 if (payload_size_type == 6)
318 if (payload_size_type == 7)
319 payload_size =
get_mb(&gb);
324 block_size = raw_block_size = payload_size + (
get_bits_count(&gb) >> 3);
331 for (; skipped_byte_pos <
nal->skipped_bytes; skipped_byte_pos++) {
332 if (
nal->skipped_bytes_pos[skipped_byte_pos] >= block_end)
339 switch (payload_type) {
343 if (!extradata_size) {
346 bytestream2_put_be16u(extradata, nalu_header);
350 extradata_size += raw_block_size;
357 data_size += raw_block_size;
366 *data_sizep = data_size;
368 bytestream2_put_byteu(
data, 0x80);
369 if (extradata_size > 0) {
375 bytestream2_put_byteu(extradata, 0x80);
377 *extradata_sizep = extradata_size;
386 static const int extradata_nal_types[] = {
391 unsigned extradata_size = 0, filtered_size = 0;
392 size_t nb_extradata_nal_types =
FF_ARRAY_ELEMS(extradata_nal_types);
400 for (
i = 0;
i <
s->h2645_pkt.nb_nals;
i++) {
402 unsigned start_code_size = 3 + !filtered_size;
404 if (
val_in_array(extradata_nal_types, nb_extradata_nal_types,
nal->type)) {
405 int extra_size, data_size;
410 unsigned extra_start_code_size = 3 + !extradata_size;
411 extradata_size += extra_start_code_size + extra_size;
415 filtered_size += start_code_size + data_size;
417 filtered_size += start_code_size +
nal->raw_size;
422 if (extradata_size) {
435 bytestream2_put_byteu(&pb_filtered_data, 0x00);
445 *
size = extradata_size;
453 bytestream2_put_be32u(&pb_extradata, 0x00000001);
455 for (
i = 0;
i <
s->h2645_pkt.nb_nals;
i++) {
458 bytestream2_put_be24u(&pb_filtered_data, 0x000001);
459 if (
val_in_array(extradata_nal_types, nb_extradata_nal_types,
469 bytestream2_put_be24u(&pb_extradata, 0x000001);
472 }
else if (
s->remove) {
496 uint32_t
state = UINT32_MAX;
497 int has_extradata = 0, extradata_size = 0;
504 extradata_size = ptr - 4 -
pkt->
data;
509 if (extradata_size) {
515 *
size = extradata_size;
530 uint32_t
state = UINT32_MAX;
537 else if (found &&
state != 0x1B5 && state < 0x200 && state >= 0x100) {
560 uint32_t
state = UINT32_MAX;
584 static const struct {
623 uint8_t *extradata =
NULL;
631 ret =
s->extract(
ctx,
pkt, &extradata, &extradata_size);
638 extradata, extradata_size);
675 #define OFFSET(x) offsetof(ExtractExtradataContext, x)
676 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM)
679 { .i64 = 0 }, 0, 1,
FLAGS },
691 .
p.
name =
"extract_extradata",
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
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
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
static av_always_inline int bytestream2_tell(const GetByteContext *g)
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
uint8_t * data
The data buffer.
@ LCEVC_PAYLOAD_TYPE_ADDITIONAL_INFO
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length, void *logctx, int nal_length_size, enum AVCodecID codec_id, int flags)
Split an input packet into NAL units.
static int get_bits_count(const GetBitContext *s)
void(* filter)(uint8_t *src, int stride, int qscale)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static uint64_t get_mb(GetBitContext *s)
The bitstream filter state.
int ff_av1_packet_split(AV1Packet *pkt, const uint8_t *buf, int length, void *logctx)
Split an input packet into OBUs.
static av_cold void close(AVCodecParserContext *s)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type, uint8_t *data, size_t size)
Wrap an existing array as a packet side data.
An input packet split into OBUs.
static double val(void *priv, double ch)
void ff_h2645_packet_uninit(H2645Packet *pkt)
Free all the allocated memory in the packet.
#define FF_ARRAY_ELEMS(a)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
static av_always_inline int bytestream2_tell_p(const PutByteContext *p)
static AVFormatContext * ctx
@ AV1_METADATA_TYPE_HDR_MDCV
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
static unsigned get_leb(GetBitContext *s)
Read a unsigned integer coded as a variable number of up to eight little-endian bytes,...
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
const char * av_default_item_name(void *ptr)
Return the context name.
const uint8_t * avpriv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state)
AVCodecID
Identify the syntax and semantics of the bitstream.
AVBitStreamFilter p
The public AVBitStreamFilter.
int(* init)(AVBSFContext *ctx)
#define i(width, name, range_min, range_max)
@ AV1_OBU_SEQUENCE_HEADER
int raw_size
Size of entire OBU, including header.
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
int size_bits
Size, in bits, of just the data, excluding the trailing_one_bit and any trailing padding.
@ H2645_FLAG_SMALL_PADDING
static int FUNC() nal(CodedBitstreamContext *ctx, RWContext *rw, LCEVCRawNAL *current, int nal_unit_type)
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
@ AV1_METADATA_TYPE_HDR_CLL
void ff_av1_packet_uninit(AV1Packet *pkt)
Free all the allocated memory in the packet.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
void * av_malloc(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
#define AV_INPUT_BUFFER_PADDING_SIZE
@ LCEVC_PAYLOAD_TYPE_SEQUENCE_CONFIG
@ AV_OPT_TYPE_INT
Underlying C type is int.
int av_buffer_realloc(AVBufferRef **pbuf, size_t size)
Reallocate a given buffer.
A reference to a data buffer.
static av_always_inline unsigned int bytestream2_put_bufferu(PutByteContext *p, const uint8_t *src, unsigned int size)
This structure stores compressed data.
int ff_h2645_unit_requires_zero_byte(enum AVCodecID codec_id, unsigned int type, int nal_unit_index)
@ LCEVC_PAYLOAD_TYPE_GLOBAL_CONFIG
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt)
Called by bitstream filters to get packet for filtering.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
void * priv_data
Format private data.