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) {
157 pkt->buf = filtered_buf;
158 pkt->data = filtered_buf->
data;
159 pkt->size = filtered_size;
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);
268 pkt->buf = filtered_buf;
269 pkt->data = filtered_buf->
data;
270 pkt->size = filtered_size;
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) {
482 pkt->buf = filtered_buf;
483 pkt->data = filtered_buf->
data;
484 pkt->size = filtered_size;
495 const uint8_t *ptr =
pkt->data, *end =
pkt->data +
pkt->size;
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) {
514 memcpy(*
data,
pkt->data, extradata_size);
515 *
size = extradata_size;
518 pkt->data += extradata_size;
519 pkt->size -= extradata_size;
530 uint32_t
state = UINT32_MAX;
533 for (
i = 0;
i <
pkt->size;
i++) {
559 const uint8_t *ptr =
pkt->data, *end =
pkt->data +
pkt->size;
560 uint32_t
state = UINT32_MAX;
565 if (ptr -
pkt->data > 4) {
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 },
684 .class_name =
"extract_extradata",
691 .p.name =
"extract_extradata",
static enum AVCodecID codec_ids[]
static double val(void *priv, double ch)
static AVFormatContext * ctx
static av_cold void close(AVCodecParserContext *s)
void ff_av1_packet_uninit(AV1Packet *pkt)
Free all the allocated memory in the packet.
int ff_av1_packet_split(AV1Packet *pkt, const uint8_t *buf, int length, void *logctx)
Split an input packet into OBUs.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
const FFBitStreamFilter ff_extract_extradata_bsf
int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt)
Called by bitstream filters to get packet for filtering.
static av_always_inline int bytestream2_tell_p(const PutByteContext *p)
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static av_always_inline unsigned int bytestream2_put_bufferu(PutByteContext *p, const uint8_t *src, unsigned int size)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static av_always_inline int bytestream2_tell(const GetByteContext *g)
#define i(width, name, range_min, range_max)
static int FUNC nal(CodedBitstreamContext *ctx, RWContext *rw, LCEVCRawNAL *current, int nal_unit_type)
int(* init)(AVBSFContext *ctx)
static struct @346255127015250356166251341105367306144006377143 state
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static int get_bits_count(const GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
@ AV_OPT_TYPE_INT
Underlying C type is int.
AVCodecID
Identify the syntax and semantics of the bitstream.
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
@ 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...
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
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.
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_realloc(AVBufferRef **pbuf, size_t size)
Reallocate a given buffer.
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
const char * av_default_item_name(void *ptr)
Return the context name.
#define LIBAVUTIL_VERSION_INT
@ H2645_FLAG_SMALL_PADDING
H.264 common definitions.
static uint64_t get_mb(GetBitContext *s)
static unsigned get_leb(GetBitContext *s)
Read a unsigned integer coded as a variable number of up to eight little-endian bytes,...
@ AV1_METADATA_TYPE_HDR_MDCV
@ AV1_METADATA_TYPE_HDR_CLL
@ AV1_OBU_SEQUENCE_HEADER
void ff_h2645_packet_uninit(H2645Packet *pkt)
Free all the allocated memory in the packet.
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.
int ff_h2645_unit_requires_zero_byte(enum AVCodecID codec_id, unsigned int type, int nal_unit_index)
LCEVC common definitions.
@ LCEVC_PAYLOAD_TYPE_ADDITIONAL_INFO
@ LCEVC_PAYLOAD_TYPE_GLOBAL_CONFIG
@ LCEVC_PAYLOAD_TYPE_SEQUENCE_CONFIG
Memory handling functions.
#define FF_ARRAY_ELEMS(a)
Accelerated start code search function for start codes common to MPEG-1/2/4 video,...
const uint8_t * avpriv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state)
int size_bits
Size, in bits, of just the data, excluding the trailing_one_bit and any trailing padding.
int raw_size
Size of entire OBU, including header.
An input packet split into OBUs.
The bitstream filter state.
A reference to a data buffer.
uint8_t * data
The data buffer.
Describe the class of an AVClass context structure.
This structure stores compressed data.
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)