29#define START_CODE 0x000001
30#define IS_IDR(nut) (nut == VVC_IDR_W_RADL || nut == VVC_IDR_N_LP)
31#define IS_H266_SLICE(nut) (nut <= VVC_RASL_NUT || (nut >= VVC_IDR_W_RADL && nut <= VVC_GDR_NUT))
88 switch (
sps->sps_bitdepth_minus8) {
114 for (
i = 0;
i < buf_size;
i++) {
122 code_len = ((pc->
state64 >> 3 * 8) & 0xFFFFFFFF) == 0x01 ? 4 : 3;
124 nut = (pc->
state64 >> (8 + 3)) & 0x1F;
133 return i - (code_len + 2);
136 int sh_picture_header_in_slice_header_flag = buf[
i] >> 7;
138 if (nut ==
VVC_PH_NUT || sh_picture_header_in_slice_header_flag) {
143 return i - (code_len + 2);
173 static const uint8_t h266_sub_width_c[] = {
176 static const uint8_t h266_sub_height_c[] = {
192 s->coded_width =
pps->pps_pic_width_in_luma_samples;
193 s->coded_height =
pps->pps_pic_height_in_luma_samples;
194 s->width =
pps->pps_pic_width_in_luma_samples -
195 (
pps->pps_conf_win_left_offset +
pps->pps_conf_win_right_offset) *
196 h266_sub_width_c[
sps->sps_chroma_format_idc];
197 s->height =
pps->pps_pic_height_in_luma_samples -
198 (
pps->pps_conf_win_top_offset +
pps->pps_conf_win_bottom_offset) *
199 h266_sub_height_c[
sps->sps_chroma_format_idc];
201 avctx->
profile =
sps->profile_tier_level.general_profile_idc;
202 avctx->
level =
sps->profile_tier_level.general_level_idc;
210 if (
sps->sps_ptl_dpb_hrd_params_present_flag &&
211 sps->sps_timing_hrd_params_present_flag) {
212 uint32_t
num =
sps->sps_general_timing_hrd_parameters.num_units_in_tick;
213 uint32_t den =
sps->sps_general_timing_hrd_parameters.time_scale;
215 if (
num != 0 && den != 0)
229 int poc_msb, max_poc_lsb, poc_lsb;
231 max_poc_lsb = 1 << (
sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4);
232 poc_lsb =
ph->ph_pic_order_cnt_lsb;
234 if (
ph->ph_poc_msb_cycle_present_flag)
235 poc_msb =
ph->ph_poc_msb_cycle_val * max_poc_lsb;
240 int prev_poc_lsb = prev_poc & (max_poc_lsb - 1);
241 int prev_poc_msb = prev_poc - prev_poc_lsb;
242 if (
ph->ph_poc_msb_cycle_present_flag) {
243 poc_msb =
ph->ph_poc_msb_cycle_val * max_poc_lsb;
245 if ((poc_lsb < prev_poc_lsb) && ((prev_poc_lsb - poc_lsb) >=
247 poc_msb = prev_poc_msb + (unsigned)max_poc_lsb;
248 else if ((poc_lsb > prev_poc_lsb) && ((poc_lsb - prev_poc_lsb) >
250 poc_msb = prev_poc_msb - (unsigned)max_poc_lsb;
252 poc_msb = prev_poc_msb;
256 *poc = poc_msb + poc_lsb;
280 nut =
nal->nal_unit_type;
283 if (
nal->nuh_temporal_id_plus1 == 1 &&
297 memset(info, 0,
sizeof(*info));
304 info->
ph = &
ph->ph_picture_header;
311 "can't find picture header in picture unit.\n");
340 memset(info, 0,
sizeof(*info));
350 memcpy(
pkt->data +
offset, buf, buf_size);
382 if ((
ret = ff_cbs_read(
ctx->cbc, pu,
NULL, buf, buf_size)) < 0) {
399 ff_cbs_fragment_reset(pu);
413 const uint8_t **buf,
int *buf_size)
418 ctx->cbc->log_ctx = avctx;
423 if (
ctx->last_au.size) {
424 *buf =
ctx->last_au.data;
425 *buf_size =
ctx->last_au.size;
435 const uint8_t **poutbuf,
int *poutbuf_size,
436 const uint8_t *buf,
int buf_size)
443 int is_dummy_buf = !buf_size;
444 int flush = !buf_size;
445 const uint8_t *dummy_buf = buf;
451 ctx->parsed_extradata = 1;
453 ret = ff_cbs_read_extradata_from_codec(
ctx->cbc, pu, avctx);
457 ff_cbs_fragment_reset(pu);
468 is_dummy_buf &= (dummy_buf == buf);
481 *poutbuf_size = buf_size;
524 ff_cbs_fragment_free(&
ctx->picture_unit);
526 ff_cbs_close(&
ctx->cbc);
static AVFormatContext * ctx
static int parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
static const CodedBitstreamUnitType decompose_unit_types[]
static enum AVPixelFormat pix_fmts_12bit[2][2]
static enum AVPixelFormat pix_fmts_8bit[2][2]
static enum AVPixelFormat pix_fmts_10bit[2][2]
#define PARSER_FLAG_COMPLETE_FRAMES
#define i(width, name, range_min, range_max)
static int FUNC sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
static int FUNC ph(CodedBitstreamContext *ctx, RWContext *rw, H266RawPH *current)
static int FUNC nal(CodedBitstreamContext *ctx, RWContext *rw, LCEVCRawNAL *current, int nal_unit_type)
void(* flush)(AVBSFContext *ctx)
int(* init)(AVBSFContext *ctx)
static enum AVPixelFormat pix_fmts_16bit[NUM_CHROMA_FORMATS]
static enum AVPixelFormat pix_fmts_14bit[NUM_CHROMA_FORMATS]
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
int av_grow_packet(AVPacket *pkt, int grow_by)
Increase packet size, correctly zeroing padding.
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
@ AV_PICTURE_STRUCTURE_FRAME
coded as frame
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
av_cold void CBS_FUNC close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
uint32_t CodedBitstreamUnitType
The codec-specific type of a bitstream unit.
Memory handling functions.
int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_size)
Combine the (truncated) bitstream to a complete frame.
#define PARSER_CODEC_LIST(...)
const FFCodecParser ff_vvc_parser
#define AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV420P10
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AVCOL_RANGE_JPEG
Full range content.
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_YUV420P14
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
#define AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_GRAY16
AVColorPrimaries
Chromaticity coordinates of the source primaries.
AVColorTransferCharacteristic
Color Transfer Characteristic.
#define AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P10
AVColorSpace
YUV colorspace type.
#define FF_ARRAY_ELEMS(a)
main external API structure.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
int level
Encoding level descriptor.
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
This structure stores compressed data.
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.
H266RawSPS * sps[VVC_MAX_SPS_COUNT]
RefStruct references.
H266RawPPS * pps[VVC_MAX_PPS_COUNT]
RefStruct references.
Coded bitstream unit structure.
void * content
Pointer to the decomposed form of this unit.
CodedBitstreamUnitType type
Codec-specific type of this unit.
uint8_t pps_seq_parameter_set_id
H266RawSliceHeader header
uint64_t state64
contains the last 8 bytes in MSB order
const H266RawPictureHeader * ph
const H266RawSlice * slice
CodedBitstreamFragment picture_unit
CodedBitstreamContext * cbc
static void error(const char *err)
static int get_pu_info(PuInfo *info, const CodedBitstreamH266Context *h266, const CodedBitstreamFragment *pu, void *logctx)
static void au_detector_init(AuDetector *d)
static av_cold void vvc_parser_close(AVCodecParserContext *s)
static av_cold int vvc_parser_init(AVCodecParserContext *s)
static int append_au(AVPacket *pkt, const uint8_t *buf, int buf_size)
static int get_pict_type(const CodedBitstreamFragment *pu)
static void set_parser_ctx(AVCodecParserContext *s, AVCodecContext *avctx, const PuInfo *pu)
static int find_frame_end(AVCodecParserContext *s, const uint8_t *buf, int buf_size)
Find the end of the current frame in the bitstream.
static int is_au_start(VVCParserContext *s, const PuInfo *pu, void *log_ctx)
static void get_slice_poc(VVCParserContext *s, int *poc, const H266RawSPS *sps, const H266RawPictureHeader *ph, const H266RawSliceHeader *slice, void *log_ctx)
#define IS_H266_SLICE(nut)
static int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf, int buf_size, AVCodecContext *avctx)
Parse NAL units of found picture and decode some basic information.
static int combine_au(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **buf, int *buf_size)
Combine PU to AU.
static int vvc_parser_parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
static int get_format(const H266RawSPS *sps)