You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-10 06:10:52 +02:00
avcodec/cbs: allow fine tunning selection of features
Core framework and AV1 only for now. This will be useful in an upcoming commit, where CBS will be utilized by a module outside libavcodec. Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
142
libavcodec/cbs.c
142
libavcodec/cbs.c
@@ -18,8 +18,6 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include "libavutil/avassert.h"
|
#include "libavutil/avassert.h"
|
||||||
#include "libavutil/buffer.h"
|
#include "libavutil/buffer.h"
|
||||||
#include "libavutil/common.h"
|
#include "libavutil/common.h"
|
||||||
@@ -33,61 +31,61 @@
|
|||||||
|
|
||||||
|
|
||||||
static const CodedBitstreamType *const cbs_type_table[] = {
|
static const CodedBitstreamType *const cbs_type_table[] = {
|
||||||
#if CONFIG_CBS_AV1
|
#if CBS_AV1
|
||||||
&ff_cbs_type_av1,
|
&CBS_FUNC(type_av1),
|
||||||
#endif
|
#endif
|
||||||
#if CONFIG_CBS_H264
|
#if CBS_H264
|
||||||
&ff_cbs_type_h264,
|
&CBS_FUNC(type_h264),
|
||||||
#endif
|
#endif
|
||||||
#if CONFIG_CBS_H265
|
#if CBS_H265
|
||||||
&ff_cbs_type_h265,
|
&CBS_FUNC(type_h265),
|
||||||
#endif
|
#endif
|
||||||
#if CONFIG_CBS_H266
|
#if CBS_H266
|
||||||
&ff_cbs_type_h266,
|
&CBS_FUNC(type_h266),
|
||||||
#endif
|
#endif
|
||||||
#if CONFIG_CBS_JPEG
|
#if CBS_JPEG
|
||||||
&ff_cbs_type_jpeg,
|
&CBS_FUNC(type_jpeg),
|
||||||
#endif
|
#endif
|
||||||
#if CONFIG_CBS_MPEG2
|
#if CBS_MPEG2
|
||||||
&ff_cbs_type_mpeg2,
|
&CBS_FUNC(type_mpeg2),
|
||||||
#endif
|
#endif
|
||||||
#if CONFIG_CBS_VP8
|
#if CBS_VP8
|
||||||
&ff_cbs_type_vp8,
|
&CBS_FUNC(type_vp8),
|
||||||
#endif
|
#endif
|
||||||
#if CONFIG_CBS_VP9
|
#if CBS_VP9
|
||||||
&ff_cbs_type_vp9,
|
&CBS_FUNC(type_vp9),
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
const enum AVCodecID ff_cbs_all_codec_ids[] = {
|
const enum AVCodecID CBS_FUNC(all_codec_ids)[] = {
|
||||||
#if CONFIG_CBS_AV1
|
#if CBS_AV1
|
||||||
AV_CODEC_ID_AV1,
|
AV_CODEC_ID_AV1,
|
||||||
#endif
|
#endif
|
||||||
#if CONFIG_CBS_H264
|
#if CBS_H264
|
||||||
AV_CODEC_ID_H264,
|
AV_CODEC_ID_H264,
|
||||||
#endif
|
#endif
|
||||||
#if CONFIG_CBS_H265
|
#if CBS_H265
|
||||||
AV_CODEC_ID_H265,
|
AV_CODEC_ID_H265,
|
||||||
#endif
|
#endif
|
||||||
#if CONFIG_CBS_H266
|
#if CBS_H266
|
||||||
AV_CODEC_ID_H266,
|
AV_CODEC_ID_H266,
|
||||||
#endif
|
#endif
|
||||||
#if CONFIG_CBS_JPEG
|
#if CBS_JPEG
|
||||||
AV_CODEC_ID_MJPEG,
|
AV_CODEC_ID_MJPEG,
|
||||||
#endif
|
#endif
|
||||||
#if CONFIG_CBS_MPEG2
|
#if CBS_MPEG2
|
||||||
AV_CODEC_ID_MPEG2VIDEO,
|
AV_CODEC_ID_MPEG2VIDEO,
|
||||||
#endif
|
#endif
|
||||||
#if CONFIG_CBS_VP8
|
#if CBS_VP8
|
||||||
AV_CODEC_ID_VP8,
|
AV_CODEC_ID_VP8,
|
||||||
#endif
|
#endif
|
||||||
#if CONFIG_CBS_VP9
|
#if CBS_VP9
|
||||||
AV_CODEC_ID_VP9,
|
AV_CODEC_ID_VP9,
|
||||||
#endif
|
#endif
|
||||||
AV_CODEC_ID_NONE
|
AV_CODEC_ID_NONE
|
||||||
};
|
};
|
||||||
|
|
||||||
av_cold int ff_cbs_init(CodedBitstreamContext **ctx_ptr,
|
av_cold int CBS_FUNC(init)(CodedBitstreamContext **ctx_ptr,
|
||||||
enum AVCodecID codec_id, void *log_ctx)
|
enum AVCodecID codec_id, void *log_ctx)
|
||||||
{
|
{
|
||||||
CodedBitstreamContext *ctx;
|
CodedBitstreamContext *ctx;
|
||||||
@@ -133,13 +131,13 @@ av_cold int ff_cbs_init(CodedBitstreamContext **ctx_ptr,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
av_cold void ff_cbs_flush(CodedBitstreamContext *ctx)
|
av_cold void CBS_FUNC(flush)(CodedBitstreamContext *ctx)
|
||||||
{
|
{
|
||||||
if (ctx->codec->flush)
|
if (ctx->codec->flush)
|
||||||
ctx->codec->flush(ctx);
|
ctx->codec->flush(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
av_cold void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
|
av_cold void CBS_FUNC(close)(CodedBitstreamContext **ctx_ptr)
|
||||||
{
|
{
|
||||||
CodedBitstreamContext *ctx = *ctx_ptr;
|
CodedBitstreamContext *ctx = *ctx_ptr;
|
||||||
|
|
||||||
@@ -169,7 +167,7 @@ static void cbs_unit_uninit(CodedBitstreamUnit *unit)
|
|||||||
unit->data_bit_padding = 0;
|
unit->data_bit_padding = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ff_cbs_fragment_reset(CodedBitstreamFragment *frag)
|
void CBS_FUNC(fragment_reset)(CodedBitstreamFragment *frag)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@@ -183,14 +181,15 @@ void ff_cbs_fragment_reset(CodedBitstreamFragment *frag)
|
|||||||
frag->data_bit_padding = 0;
|
frag->data_bit_padding = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
av_cold void ff_cbs_fragment_free(CodedBitstreamFragment *frag)
|
av_cold void CBS_FUNC(fragment_free)(CodedBitstreamFragment *frag)
|
||||||
{
|
{
|
||||||
ff_cbs_fragment_reset(frag);
|
CBS_FUNC(fragment_reset)(frag);
|
||||||
|
|
||||||
av_freep(&frag->units);
|
av_freep(&frag->units);
|
||||||
frag->nb_units_allocated = 0;
|
frag->nb_units_allocated = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CBS_READ
|
||||||
static int cbs_read_fragment_content(CodedBitstreamContext *ctx,
|
static int cbs_read_fragment_content(CodedBitstreamContext *ctx,
|
||||||
CodedBitstreamFragment *frag)
|
CodedBitstreamFragment *frag)
|
||||||
{
|
{
|
||||||
@@ -283,7 +282,7 @@ static int cbs_read_data(CodedBitstreamContext *ctx,
|
|||||||
return cbs_read_fragment_content(ctx, frag);
|
return cbs_read_fragment_content(ctx, frag);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ff_cbs_read_extradata(CodedBitstreamContext *ctx,
|
int CBS_FUNC(read_extradata)(CodedBitstreamContext *ctx,
|
||||||
CodedBitstreamFragment *frag,
|
CodedBitstreamFragment *frag,
|
||||||
const AVCodecParameters *par)
|
const AVCodecParameters *par)
|
||||||
{
|
{
|
||||||
@@ -292,7 +291,7 @@ int ff_cbs_read_extradata(CodedBitstreamContext *ctx,
|
|||||||
par->extradata_size, 1);
|
par->extradata_size, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ff_cbs_read_extradata_from_codec(CodedBitstreamContext *ctx,
|
int CBS_FUNC(read_extradata_from_codec)(CodedBitstreamContext *ctx,
|
||||||
CodedBitstreamFragment *frag,
|
CodedBitstreamFragment *frag,
|
||||||
const AVCodecContext *avctx)
|
const AVCodecContext *avctx)
|
||||||
{
|
{
|
||||||
@@ -301,7 +300,7 @@ int ff_cbs_read_extradata_from_codec(CodedBitstreamContext *ctx,
|
|||||||
avctx->extradata_size, 1);
|
avctx->extradata_size, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ff_cbs_read_packet(CodedBitstreamContext *ctx,
|
int CBS_FUNC(read_packet)(CodedBitstreamContext *ctx,
|
||||||
CodedBitstreamFragment *frag,
|
CodedBitstreamFragment *frag,
|
||||||
const AVPacket *pkt)
|
const AVPacket *pkt)
|
||||||
{
|
{
|
||||||
@@ -309,7 +308,7 @@ int ff_cbs_read_packet(CodedBitstreamContext *ctx,
|
|||||||
pkt->data, pkt->size, 0);
|
pkt->data, pkt->size, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ff_cbs_read_packet_side_data(CodedBitstreamContext *ctx,
|
int CBS_FUNC(read_packet_side_data)(CodedBitstreamContext *ctx,
|
||||||
CodedBitstreamFragment *frag,
|
CodedBitstreamFragment *frag,
|
||||||
const AVPacket *pkt)
|
const AVPacket *pkt)
|
||||||
{
|
{
|
||||||
@@ -322,14 +321,16 @@ int ff_cbs_read_packet_side_data(CodedBitstreamContext *ctx,
|
|||||||
side_data, side_data_size, 1);
|
side_data, side_data_size, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ff_cbs_read(CodedBitstreamContext *ctx,
|
int CBS_FUNC(read)(CodedBitstreamContext *ctx,
|
||||||
CodedBitstreamFragment *frag,
|
CodedBitstreamFragment *frag,
|
||||||
const uint8_t *data, size_t size)
|
const uint8_t *data, size_t size)
|
||||||
{
|
{
|
||||||
return cbs_read_data(ctx, frag, NULL,
|
return cbs_read_data(ctx, frag, NULL,
|
||||||
data, size, 0);
|
data, size, 0);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if CBS_WRITE
|
||||||
/**
|
/**
|
||||||
* Allocate a new internal data buffer of the given size in the unit.
|
* Allocate a new internal data buffer of the given size in the unit.
|
||||||
*
|
*
|
||||||
@@ -406,7 +407,7 @@ static int cbs_write_unit_data(CodedBitstreamContext *ctx,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx,
|
int CBS_FUNC(write_fragment_data)(CodedBitstreamContext *ctx,
|
||||||
CodedBitstreamFragment *frag)
|
CodedBitstreamFragment *frag)
|
||||||
{
|
{
|
||||||
int err, i;
|
int err, i;
|
||||||
@@ -442,13 +443,13 @@ int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ff_cbs_write_extradata(CodedBitstreamContext *ctx,
|
int CBS_FUNC(write_extradata)(CodedBitstreamContext *ctx,
|
||||||
AVCodecParameters *par,
|
AVCodecParameters *par,
|
||||||
CodedBitstreamFragment *frag)
|
CodedBitstreamFragment *frag)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = ff_cbs_write_fragment_data(ctx, frag);
|
err = CBS_FUNC(write_fragment_data)(ctx, frag);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
@@ -471,14 +472,14 @@ int ff_cbs_write_extradata(CodedBitstreamContext *ctx,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ff_cbs_write_packet(CodedBitstreamContext *ctx,
|
int CBS_FUNC(write_packet)(CodedBitstreamContext *ctx,
|
||||||
AVPacket *pkt,
|
AVPacket *pkt,
|
||||||
CodedBitstreamFragment *frag)
|
CodedBitstreamFragment *frag)
|
||||||
{
|
{
|
||||||
AVBufferRef *buf;
|
AVBufferRef *buf;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = ff_cbs_write_fragment_data(ctx, frag);
|
err = CBS_FUNC(write_fragment_data)(ctx, frag);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
@@ -494,22 +495,26 @@ int ff_cbs_write_packet(CodedBitstreamContext *ctx,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void ff_cbs_trace_header(CodedBitstreamContext *ctx,
|
void CBS_FUNC(trace_header)(CodedBitstreamContext *ctx,
|
||||||
const char *name)
|
const char *name)
|
||||||
{
|
{
|
||||||
|
#if CBS_TRACE
|
||||||
if (!ctx->trace_enable)
|
if (!ctx->trace_enable)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
av_log(ctx->log_ctx, ctx->trace_level, "%s\n", name);
|
av_log(ctx->log_ctx, ctx->trace_level, "%s\n", name);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ff_cbs_trace_read_log(void *trace_context,
|
void CBS_FUNC(trace_read_log)(void *trace_context,
|
||||||
GetBitContext *gbc, int length,
|
GetBitContext *gbc, int length,
|
||||||
const char *str, const int *subscripts,
|
const char *str, const int *subscripts,
|
||||||
int64_t value)
|
int64_t value)
|
||||||
{
|
{
|
||||||
|
#if CBS_TRACE
|
||||||
CodedBitstreamContext *ctx = trace_context;
|
CodedBitstreamContext *ctx = trace_context;
|
||||||
char name[256];
|
char name[256];
|
||||||
char bits[256];
|
char bits[256];
|
||||||
@@ -561,13 +566,15 @@ void ff_cbs_trace_read_log(void *trace_context,
|
|||||||
|
|
||||||
av_log(ctx->log_ctx, ctx->trace_level, "%-10d %s%*s = %"PRId64"\n",
|
av_log(ctx->log_ctx, ctx->trace_level, "%-10d %s%*s = %"PRId64"\n",
|
||||||
position, name, pad, bits, value);
|
position, name, pad, bits, value);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ff_cbs_trace_write_log(void *trace_context,
|
void CBS_FUNC(trace_write_log)(void *trace_context,
|
||||||
PutBitContext *pbc, int length,
|
PutBitContext *pbc, int length,
|
||||||
const char *str, const int *subscripts,
|
const char *str, const int *subscripts,
|
||||||
int64_t value)
|
int64_t value)
|
||||||
{
|
{
|
||||||
|
#if CBS_TRACE
|
||||||
CodedBitstreamContext *ctx = trace_context;
|
CodedBitstreamContext *ctx = trace_context;
|
||||||
|
|
||||||
// Ensure that the syntax element is written to the output buffer,
|
// Ensure that the syntax element is written to the output buffer,
|
||||||
@@ -590,9 +597,11 @@ void ff_cbs_trace_write_log(void *trace_context,
|
|||||||
|
|
||||||
skip_bits_long(&gbc, position - length);
|
skip_bits_long(&gbc, position - length);
|
||||||
|
|
||||||
ff_cbs_trace_read_log(ctx, &gbc, length, str, subscripts, value);
|
CBS_FUNC(trace_read_log)(ctx, &gbc, length, str, subscripts, value);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CBS_READ
|
||||||
static av_always_inline int cbs_read_unsigned(CodedBitstreamContext *ctx,
|
static av_always_inline int cbs_read_unsigned(CodedBitstreamContext *ctx,
|
||||||
GetBitContext *gbc,
|
GetBitContext *gbc,
|
||||||
int width, const char *name,
|
int width, const char *name,
|
||||||
@@ -628,7 +637,7 @@ static av_always_inline int cbs_read_unsigned(CodedBitstreamContext *ctx,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
int CBS_FUNC(read_unsigned)(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
||||||
int width, const char *name,
|
int width, const char *name,
|
||||||
const int *subscripts, uint32_t *write_to,
|
const int *subscripts, uint32_t *write_to,
|
||||||
uint32_t range_min, uint32_t range_max)
|
uint32_t range_min, uint32_t range_max)
|
||||||
@@ -637,14 +646,16 @@ int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
|||||||
write_to, range_min, range_max);
|
write_to, range_min, range_max);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ff_cbs_read_simple_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
int CBS_FUNC(read_simple_unsigned)(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
||||||
int width, const char *name, uint32_t *write_to)
|
int width, const char *name, uint32_t *write_to)
|
||||||
{
|
{
|
||||||
return cbs_read_unsigned(ctx, gbc, width, name, NULL,
|
return cbs_read_unsigned(ctx, gbc, width, name, NULL,
|
||||||
write_to, 0, UINT32_MAX);
|
write_to, 0, UINT32_MAX);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
#if CBS_WRITE
|
||||||
|
int CBS_FUNC(write_unsigned)(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
||||||
int width, const char *name,
|
int width, const char *name,
|
||||||
const int *subscripts, uint32_t value,
|
const int *subscripts, uint32_t value,
|
||||||
uint32_t range_min, uint32_t range_max)
|
uint32_t range_min, uint32_t range_max)
|
||||||
@@ -673,14 +684,16 @@ int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ff_cbs_write_simple_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
int CBS_FUNC(write_simple_unsigned)(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
||||||
int width, const char *name, uint32_t value)
|
int width, const char *name, uint32_t value)
|
||||||
{
|
{
|
||||||
return ff_cbs_write_unsigned(ctx, pbc, width, name, NULL,
|
return CBS_FUNC(write_unsigned)(ctx, pbc, width, name, NULL,
|
||||||
value, 0, MAX_UINT_BITS(width));
|
value, 0, MAX_UINT_BITS(width));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int ff_cbs_read_signed(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
#if CBS_READ
|
||||||
|
int CBS_FUNC(read_signed)(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
||||||
int width, const char *name,
|
int width, const char *name,
|
||||||
const int *subscripts, int32_t *write_to,
|
const int *subscripts, int32_t *write_to,
|
||||||
int32_t range_min, int32_t range_max)
|
int32_t range_min, int32_t range_max)
|
||||||
@@ -711,8 +724,10 @@ int ff_cbs_read_signed(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
|||||||
*write_to = value;
|
*write_to = value;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
#if CBS_WRITE
|
||||||
|
int CBS_FUNC(write_signed)(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
||||||
int width, const char *name,
|
int width, const char *name,
|
||||||
const int *subscripts, int32_t value,
|
const int *subscripts, int32_t value,
|
||||||
int32_t range_min, int32_t range_max)
|
int32_t range_min, int32_t range_max)
|
||||||
@@ -740,6 +755,7 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static int cbs_insert_unit(CodedBitstreamFragment *frag,
|
static int cbs_insert_unit(CodedBitstreamFragment *frag,
|
||||||
@@ -780,7 +796,7 @@ static int cbs_insert_unit(CodedBitstreamFragment *frag,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag,
|
int CBS_FUNC(insert_unit_content)(CodedBitstreamFragment *frag,
|
||||||
int position,
|
int position,
|
||||||
CodedBitstreamUnitType type,
|
CodedBitstreamUnitType type,
|
||||||
void *content,
|
void *content,
|
||||||
@@ -847,7 +863,7 @@ static int cbs_insert_unit_data(CodedBitstreamFragment *frag,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ff_cbs_append_unit_data(CodedBitstreamFragment *frag,
|
int CBS_FUNC(append_unit_data)(CodedBitstreamFragment *frag,
|
||||||
CodedBitstreamUnitType type,
|
CodedBitstreamUnitType type,
|
||||||
uint8_t *data, size_t data_size,
|
uint8_t *data, size_t data_size,
|
||||||
AVBufferRef *data_buf)
|
AVBufferRef *data_buf)
|
||||||
@@ -857,7 +873,7 @@ int ff_cbs_append_unit_data(CodedBitstreamFragment *frag,
|
|||||||
frag->nb_units);
|
frag->nb_units);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ff_cbs_delete_unit(CodedBitstreamFragment *frag,
|
void CBS_FUNC(delete_unit)(CodedBitstreamFragment *frag,
|
||||||
int position)
|
int position)
|
||||||
{
|
{
|
||||||
av_assert0(0 <= position && position < frag->nb_units
|
av_assert0(0 <= position && position < frag->nb_units
|
||||||
@@ -920,7 +936,7 @@ static void *cbs_alloc_content(const CodedBitstreamUnitTypeDescriptor *desc)
|
|||||||
: cbs_default_free_unit_content);
|
: cbs_default_free_unit_content);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx,
|
int CBS_FUNC(alloc_unit_content)(CodedBitstreamContext *ctx,
|
||||||
CodedBitstreamUnit *unit)
|
CodedBitstreamUnit *unit)
|
||||||
{
|
{
|
||||||
const CodedBitstreamUnitTypeDescriptor *desc;
|
const CodedBitstreamUnitTypeDescriptor *desc;
|
||||||
@@ -1032,7 +1048,7 @@ static int cbs_clone_unit_content(CodedBitstreamContext *ctx,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ff_cbs_make_unit_refcounted(CodedBitstreamContext *ctx,
|
int CBS_FUNC(make_unit_refcounted)(CodedBitstreamContext *ctx,
|
||||||
CodedBitstreamUnit *unit)
|
CodedBitstreamUnit *unit)
|
||||||
{
|
{
|
||||||
av_assert0(unit->content);
|
av_assert0(unit->content);
|
||||||
@@ -1041,7 +1057,7 @@ int ff_cbs_make_unit_refcounted(CodedBitstreamContext *ctx,
|
|||||||
return cbs_clone_unit_content(ctx, unit);
|
return cbs_clone_unit_content(ctx, unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx,
|
int CBS_FUNC(make_unit_writable)(CodedBitstreamContext *ctx,
|
||||||
CodedBitstreamUnit *unit)
|
CodedBitstreamUnit *unit)
|
||||||
{
|
{
|
||||||
void *ref = unit->content_ref;
|
void *ref = unit->content_ref;
|
||||||
@@ -1058,7 +1074,7 @@ int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ff_cbs_discard_units(CodedBitstreamContext *ctx,
|
void CBS_FUNC(discard_units)(CodedBitstreamContext *ctx,
|
||||||
CodedBitstreamFragment *frag,
|
CodedBitstreamFragment *frag,
|
||||||
enum AVDiscard skip,
|
enum AVDiscard skip,
|
||||||
int flags)
|
int flags)
|
||||||
@@ -1070,11 +1086,11 @@ void ff_cbs_discard_units(CodedBitstreamContext *ctx,
|
|||||||
if (ctx->codec->discarded_unit(ctx, &frag->units[i], skip)) {
|
if (ctx->codec->discarded_unit(ctx, &frag->units[i], skip)) {
|
||||||
// discard all units
|
// discard all units
|
||||||
if (!(flags & DISCARD_FLAG_KEEP_NON_VCL)) {
|
if (!(flags & DISCARD_FLAG_KEEP_NON_VCL)) {
|
||||||
ff_cbs_fragment_free(frag);
|
CBS_FUNC(fragment_free)(frag);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ff_cbs_delete_unit(frag, i);
|
CBS_FUNC(delete_unit)(frag, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -29,6 +29,13 @@
|
|||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
#include "packet.h"
|
#include "packet.h"
|
||||||
|
|
||||||
|
#ifndef CBS_PREFIX
|
||||||
|
#define CBS_PREFIX cbs
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define CBS_FUNC_PREFIX_NAME(prefix, name) ff_ ## prefix ## _ ## name
|
||||||
|
#define CBS_FUNC_NAME(prefix, name) CBS_FUNC_PREFIX_NAME(prefix, name)
|
||||||
|
#define CBS_FUNC(name) CBS_FUNC_NAME(CBS_PREFIX, name)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This defines a framework for converting between a coded bitstream
|
* This defines a framework for converting between a coded bitstream
|
||||||
@@ -294,24 +301,24 @@ typedef struct CodedBitstreamContext {
|
|||||||
*
|
*
|
||||||
* Terminated by AV_CODEC_ID_NONE.
|
* Terminated by AV_CODEC_ID_NONE.
|
||||||
*/
|
*/
|
||||||
extern const enum AVCodecID ff_cbs_all_codec_ids[];
|
extern const enum AVCodecID CBS_FUNC(all_codec_ids)[];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create and initialise a new context for the given codec.
|
* Create and initialise a new context for the given codec.
|
||||||
*/
|
*/
|
||||||
int ff_cbs_init(CodedBitstreamContext **ctx,
|
int CBS_FUNC(init)(CodedBitstreamContext **ctx,
|
||||||
enum AVCodecID codec_id, void *log_ctx);
|
enum AVCodecID codec_id, void *log_ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset all internal state in a context.
|
* Reset all internal state in a context.
|
||||||
*/
|
*/
|
||||||
void ff_cbs_flush(CodedBitstreamContext *ctx);
|
void CBS_FUNC(flush)(CodedBitstreamContext *ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close a context and free all internal state.
|
* Close a context and free all internal state.
|
||||||
*/
|
*/
|
||||||
void ff_cbs_close(CodedBitstreamContext **ctx);
|
void CBS_FUNC(close)(CodedBitstreamContext **ctx);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -325,7 +332,7 @@ void ff_cbs_close(CodedBitstreamContext **ctx);
|
|||||||
* The fragment must have been zeroed or reset via ff_cbs_fragment_reset
|
* The fragment must have been zeroed or reset via ff_cbs_fragment_reset
|
||||||
* before use.
|
* before use.
|
||||||
*/
|
*/
|
||||||
int ff_cbs_read_extradata(CodedBitstreamContext *ctx,
|
int CBS_FUNC(read_extradata)(CodedBitstreamContext *ctx,
|
||||||
CodedBitstreamFragment *frag,
|
CodedBitstreamFragment *frag,
|
||||||
const AVCodecParameters *par);
|
const AVCodecParameters *par);
|
||||||
|
|
||||||
@@ -336,11 +343,11 @@ int ff_cbs_read_extradata(CodedBitstreamContext *ctx,
|
|||||||
* This acts identical to ff_cbs_read_extradata() for the case where
|
* This acts identical to ff_cbs_read_extradata() for the case where
|
||||||
* you already have a codec context.
|
* you already have a codec context.
|
||||||
*/
|
*/
|
||||||
int ff_cbs_read_extradata_from_codec(CodedBitstreamContext *ctx,
|
int CBS_FUNC(read_extradata_from_codec)(CodedBitstreamContext *ctx,
|
||||||
CodedBitstreamFragment *frag,
|
CodedBitstreamFragment *frag,
|
||||||
const struct AVCodecContext *avctx);
|
const struct AVCodecContext *avctx);
|
||||||
|
|
||||||
int ff_cbs_read_packet_side_data(CodedBitstreamContext *ctx,
|
int CBS_FUNC(read_packet_side_data)(CodedBitstreamContext *ctx,
|
||||||
CodedBitstreamFragment *frag,
|
CodedBitstreamFragment *frag,
|
||||||
const AVPacket *pkt);
|
const AVPacket *pkt);
|
||||||
|
|
||||||
@@ -355,7 +362,7 @@ int ff_cbs_read_packet_side_data(CodedBitstreamContext *ctx,
|
|||||||
* The fragment must have been zeroed or reset via ff_cbs_fragment_reset
|
* The fragment must have been zeroed or reset via ff_cbs_fragment_reset
|
||||||
* before use.
|
* before use.
|
||||||
*/
|
*/
|
||||||
int ff_cbs_read_packet(CodedBitstreamContext *ctx,
|
int CBS_FUNC(read_packet)(CodedBitstreamContext *ctx,
|
||||||
CodedBitstreamFragment *frag,
|
CodedBitstreamFragment *frag,
|
||||||
const AVPacket *pkt);
|
const AVPacket *pkt);
|
||||||
|
|
||||||
@@ -370,7 +377,7 @@ int ff_cbs_read_packet(CodedBitstreamContext *ctx,
|
|||||||
* The fragment must have been zeroed or reset via ff_cbs_fragment_reset
|
* The fragment must have been zeroed or reset via ff_cbs_fragment_reset
|
||||||
* before use.
|
* before use.
|
||||||
*/
|
*/
|
||||||
int ff_cbs_read(CodedBitstreamContext *ctx,
|
int CBS_FUNC(read)(CodedBitstreamContext *ctx,
|
||||||
CodedBitstreamFragment *frag,
|
CodedBitstreamFragment *frag,
|
||||||
const uint8_t *data, size_t size);
|
const uint8_t *data, size_t size);
|
||||||
|
|
||||||
@@ -387,7 +394,7 @@ int ff_cbs_read(CodedBitstreamContext *ctx,
|
|||||||
* with any persistent data from the fragment which may be required to
|
* with any persistent data from the fragment which may be required to
|
||||||
* write following fragments (e.g. parameter sets).
|
* write following fragments (e.g. parameter sets).
|
||||||
*/
|
*/
|
||||||
int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx,
|
int CBS_FUNC(write_fragment_data)(CodedBitstreamContext *ctx,
|
||||||
CodedBitstreamFragment *frag);
|
CodedBitstreamFragment *frag);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -396,7 +403,7 @@ int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx,
|
|||||||
* Modifies context and fragment as ff_cbs_write_fragment_data does and
|
* Modifies context and fragment as ff_cbs_write_fragment_data does and
|
||||||
* replaces any existing extradata in the structure.
|
* replaces any existing extradata in the structure.
|
||||||
*/
|
*/
|
||||||
int ff_cbs_write_extradata(CodedBitstreamContext *ctx,
|
int CBS_FUNC(write_extradata)(CodedBitstreamContext *ctx,
|
||||||
AVCodecParameters *par,
|
AVCodecParameters *par,
|
||||||
CodedBitstreamFragment *frag);
|
CodedBitstreamFragment *frag);
|
||||||
|
|
||||||
@@ -410,7 +417,7 @@ int ff_cbs_write_extradata(CodedBitstreamContext *ctx,
|
|||||||
* fragment; other fields are not touched. On failure, the packet is not
|
* fragment; other fields are not touched. On failure, the packet is not
|
||||||
* touched at all.
|
* touched at all.
|
||||||
*/
|
*/
|
||||||
int ff_cbs_write_packet(CodedBitstreamContext *ctx,
|
int CBS_FUNC(write_packet)(CodedBitstreamContext *ctx,
|
||||||
AVPacket *pkt,
|
AVPacket *pkt,
|
||||||
CodedBitstreamFragment *frag);
|
CodedBitstreamFragment *frag);
|
||||||
|
|
||||||
@@ -419,20 +426,20 @@ int ff_cbs_write_packet(CodedBitstreamContext *ctx,
|
|||||||
* Free the units contained in a fragment as well as the fragment's
|
* Free the units contained in a fragment as well as the fragment's
|
||||||
* own data buffer, but not the units array itself.
|
* own data buffer, but not the units array itself.
|
||||||
*/
|
*/
|
||||||
void ff_cbs_fragment_reset(CodedBitstreamFragment *frag);
|
void CBS_FUNC(fragment_reset)(CodedBitstreamFragment *frag);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free the units array of a fragment in addition to what
|
* Free the units array of a fragment in addition to what
|
||||||
* ff_cbs_fragment_reset does.
|
* ff_cbs_fragment_reset does.
|
||||||
*/
|
*/
|
||||||
void ff_cbs_fragment_free(CodedBitstreamFragment *frag);
|
void CBS_FUNC(fragment_free)(CodedBitstreamFragment *frag);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocate a new internal content buffer matching the type of the unit.
|
* Allocate a new internal content buffer matching the type of the unit.
|
||||||
*
|
*
|
||||||
* The content will be zeroed.
|
* The content will be zeroed.
|
||||||
*/
|
*/
|
||||||
int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx,
|
int CBS_FUNC(alloc_unit_content)(CodedBitstreamContext *ctx,
|
||||||
CodedBitstreamUnit *unit);
|
CodedBitstreamUnit *unit);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -443,7 +450,7 @@ int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx,
|
|||||||
* The content structure continues to be owned by the caller if
|
* The content structure continues to be owned by the caller if
|
||||||
* content_ref is not supplied.
|
* content_ref is not supplied.
|
||||||
*/
|
*/
|
||||||
int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag,
|
int CBS_FUNC(insert_unit_content)(CodedBitstreamFragment *frag,
|
||||||
int position,
|
int position,
|
||||||
CodedBitstreamUnitType type,
|
CodedBitstreamUnitType type,
|
||||||
void *content,
|
void *content,
|
||||||
@@ -456,7 +463,7 @@ int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag,
|
|||||||
* av_malloc() and will on success become owned by the unit after this
|
* av_malloc() and will on success become owned by the unit after this
|
||||||
* call or freed on error.
|
* call or freed on error.
|
||||||
*/
|
*/
|
||||||
int ff_cbs_append_unit_data(CodedBitstreamFragment *frag,
|
int CBS_FUNC(append_unit_data)(CodedBitstreamFragment *frag,
|
||||||
CodedBitstreamUnitType type,
|
CodedBitstreamUnitType type,
|
||||||
uint8_t *data, size_t data_size,
|
uint8_t *data, size_t data_size,
|
||||||
AVBufferRef *data_buf);
|
AVBufferRef *data_buf);
|
||||||
@@ -466,7 +473,7 @@ int ff_cbs_append_unit_data(CodedBitstreamFragment *frag,
|
|||||||
*
|
*
|
||||||
* Requires position to be >= 0 and < frag->nb_units.
|
* Requires position to be >= 0 and < frag->nb_units.
|
||||||
*/
|
*/
|
||||||
void ff_cbs_delete_unit(CodedBitstreamFragment *frag,
|
void CBS_FUNC(delete_unit)(CodedBitstreamFragment *frag,
|
||||||
int position);
|
int position);
|
||||||
|
|
||||||
|
|
||||||
@@ -479,7 +486,7 @@ void ff_cbs_delete_unit(CodedBitstreamFragment *frag,
|
|||||||
* It is not valid to call this function on a unit which does not have
|
* It is not valid to call this function on a unit which does not have
|
||||||
* decomposed content.
|
* decomposed content.
|
||||||
*/
|
*/
|
||||||
int ff_cbs_make_unit_refcounted(CodedBitstreamContext *ctx,
|
int CBS_FUNC(make_unit_refcounted)(CodedBitstreamContext *ctx,
|
||||||
CodedBitstreamUnit *unit);
|
CodedBitstreamUnit *unit);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -495,7 +502,7 @@ int ff_cbs_make_unit_refcounted(CodedBitstreamContext *ctx,
|
|||||||
* It is not valid to call this function on a unit which does not have
|
* It is not valid to call this function on a unit which does not have
|
||||||
* decomposed content.
|
* decomposed content.
|
||||||
*/
|
*/
|
||||||
int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx,
|
int CBS_FUNC(make_unit_writable)(CodedBitstreamContext *ctx,
|
||||||
CodedBitstreamUnit *unit);
|
CodedBitstreamUnit *unit);
|
||||||
|
|
||||||
enum CbsDiscardFlags {
|
enum CbsDiscardFlags {
|
||||||
@@ -510,7 +517,7 @@ enum CbsDiscardFlags {
|
|||||||
/**
|
/**
|
||||||
* Discard units accroding to 'skip'.
|
* Discard units accroding to 'skip'.
|
||||||
*/
|
*/
|
||||||
void ff_cbs_discard_units(CodedBitstreamContext *ctx,
|
void CBS_FUNC(discard_units)(CodedBitstreamContext *ctx,
|
||||||
CodedBitstreamFragment *frag,
|
CodedBitstreamFragment *frag,
|
||||||
enum AVDiscard skip,
|
enum AVDiscard skip,
|
||||||
int flags);
|
int flags);
|
||||||
@@ -522,7 +529,7 @@ void ff_cbs_discard_units(CodedBitstreamContext *ctx,
|
|||||||
*
|
*
|
||||||
* Trace context should be set to the CodedBitstreamContext.
|
* Trace context should be set to the CodedBitstreamContext.
|
||||||
*/
|
*/
|
||||||
void ff_cbs_trace_read_log(void *trace_context,
|
void CBS_FUNC(trace_read_log)(void *trace_context,
|
||||||
struct GetBitContext *gbc, int length,
|
struct GetBitContext *gbc, int length,
|
||||||
const char *str, const int *subscripts,
|
const char *str, const int *subscripts,
|
||||||
int64_t value);
|
int64_t value);
|
||||||
@@ -533,7 +540,7 @@ void ff_cbs_trace_read_log(void *trace_context,
|
|||||||
*
|
*
|
||||||
* Trace context should be set to the CodedBitstreamContext.
|
* Trace context should be set to the CodedBitstreamContext.
|
||||||
*/
|
*/
|
||||||
void ff_cbs_trace_write_log(void *trace_context,
|
void CBS_FUNC(trace_write_log)(void *trace_context,
|
||||||
struct PutBitContext *pbc, int length,
|
struct PutBitContext *pbc, int length,
|
||||||
const char *str, const int *subscripts,
|
const char *str, const int *subscripts,
|
||||||
int64_t value);
|
int64_t value);
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
#include "libavutil/refstruct.h"
|
#include "libavutil/refstruct.h"
|
||||||
|
|
||||||
|
|
||||||
|
#if CBS_READ
|
||||||
static int cbs_av1_read_uvlc(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
static int cbs_av1_read_uvlc(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
||||||
const char *name, uint32_t *write_to,
|
const char *name, uint32_t *write_to,
|
||||||
uint32_t range_min, uint32_t range_max)
|
uint32_t range_min, uint32_t range_max)
|
||||||
@@ -84,7 +85,9 @@ static int cbs_av1_read_uvlc(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
|||||||
*write_to = value;
|
*write_to = value;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if CBS_WRITE
|
||||||
static int cbs_av1_write_uvlc(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
static int cbs_av1_write_uvlc(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
||||||
const char *name, uint32_t value,
|
const char *name, uint32_t value,
|
||||||
uint32_t range_min, uint32_t range_max)
|
uint32_t range_min, uint32_t range_max)
|
||||||
@@ -115,7 +118,9 @@ static int cbs_av1_write_uvlc(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if CBS_READ
|
||||||
static int cbs_av1_read_leb128(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
static int cbs_av1_read_leb128(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
||||||
const char *name, uint64_t *write_to)
|
const char *name, uint64_t *write_to)
|
||||||
{
|
{
|
||||||
@@ -146,7 +151,9 @@ static int cbs_av1_read_leb128(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
|||||||
*write_to = value;
|
*write_to = value;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if CBS_WRITE
|
||||||
static int cbs_av1_write_leb128(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
static int cbs_av1_write_leb128(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
||||||
const char *name, uint64_t value, int fixed_length)
|
const char *name, uint64_t value, int fixed_length)
|
||||||
{
|
{
|
||||||
@@ -182,7 +189,9 @@ static int cbs_av1_write_leb128(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if CBS_READ
|
||||||
static int cbs_av1_read_ns(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
static int cbs_av1_read_ns(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
||||||
uint32_t n, const char *name,
|
uint32_t n, const char *name,
|
||||||
const int *subscripts, uint32_t *write_to)
|
const int *subscripts, uint32_t *write_to)
|
||||||
@@ -220,7 +229,9 @@ static int cbs_av1_read_ns(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
|||||||
*write_to = value;
|
*write_to = value;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if CBS_WRITE
|
||||||
static int cbs_av1_write_ns(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
static int cbs_av1_write_ns(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
||||||
uint32_t n, const char *name,
|
uint32_t n, const char *name,
|
||||||
const int *subscripts, uint32_t value)
|
const int *subscripts, uint32_t value)
|
||||||
@@ -256,7 +267,9 @@ static int cbs_av1_write_ns(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if CBS_READ
|
||||||
static int cbs_av1_read_increment(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
static int cbs_av1_read_increment(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
||||||
uint32_t range_min, uint32_t range_max,
|
uint32_t range_min, uint32_t range_max,
|
||||||
const char *name, uint32_t *write_to)
|
const char *name, uint32_t *write_to)
|
||||||
@@ -284,7 +297,9 @@ static int cbs_av1_read_increment(CodedBitstreamContext *ctx, GetBitContext *gbc
|
|||||||
*write_to = value;
|
*write_to = value;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if CBS_WRITE
|
||||||
static int cbs_av1_write_increment(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
static int cbs_av1_write_increment(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
||||||
uint32_t range_min, uint32_t range_max,
|
uint32_t range_min, uint32_t range_max,
|
||||||
const char *name, uint32_t value)
|
const char *name, uint32_t value)
|
||||||
@@ -315,7 +330,9 @@ static int cbs_av1_write_increment(CodedBitstreamContext *ctx, PutBitContext *pb
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if CBS_READ
|
||||||
static int cbs_av1_read_subexp(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
static int cbs_av1_read_subexp(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
||||||
uint32_t range_max, const char *name,
|
uint32_t range_max, const char *name,
|
||||||
const int *subscripts, uint32_t *write_to)
|
const int *subscripts, uint32_t *write_to)
|
||||||
@@ -342,7 +359,7 @@ static int cbs_av1_read_subexp(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (len < max_len) {
|
if (len < max_len) {
|
||||||
err = ff_cbs_read_simple_unsigned(ctx, gbc, range_bits,
|
err = CBS_FUNC(read_simple_unsigned)(ctx, gbc, range_bits,
|
||||||
"subexp_bits", &value);
|
"subexp_bits", &value);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
@@ -360,7 +377,9 @@ static int cbs_av1_read_subexp(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
|||||||
*write_to = value;
|
*write_to = value;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if CBS_WRITE
|
||||||
static int cbs_av1_write_subexp(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
static int cbs_av1_write_subexp(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
||||||
uint32_t range_max, const char *name,
|
uint32_t range_max, const char *name,
|
||||||
const int *subscripts, uint32_t value)
|
const int *subscripts, uint32_t value)
|
||||||
@@ -402,7 +421,7 @@ static int cbs_av1_write_subexp(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
|||||||
return err;
|
return err;
|
||||||
|
|
||||||
if (len < max_len) {
|
if (len < max_len) {
|
||||||
err = ff_cbs_write_simple_unsigned(ctx, pbc, range_bits,
|
err = CBS_FUNC(write_simple_unsigned)(ctx, pbc, range_bits,
|
||||||
"subexp_bits",
|
"subexp_bits",
|
||||||
value - range_offset);
|
value - range_offset);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
@@ -420,6 +439,7 @@ static int cbs_av1_write_subexp(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
|||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static int cbs_av1_tile_log2(int blksize, int target)
|
static int cbs_av1_tile_log2(int blksize, int target)
|
||||||
@@ -441,7 +461,7 @@ static int cbs_av1_get_relative_dist(const AV1RawSequenceHeader *seq,
|
|||||||
return diff;
|
return diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
|
static av_unused size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
|
||||||
{
|
{
|
||||||
GetBitContext tmp = *gbc;
|
GetBitContext tmp = *gbc;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
@@ -454,7 +474,7 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
|
|||||||
|
|
||||||
|
|
||||||
#define HEADER(name) do { \
|
#define HEADER(name) do { \
|
||||||
ff_cbs_trace_header(ctx, name); \
|
CBS_FUNC(trace_header)(ctx, name); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define CHECK(call) do { \
|
#define CHECK(call) do { \
|
||||||
@@ -469,6 +489,7 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
|
|||||||
|
|
||||||
#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
|
#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
|
||||||
|
|
||||||
|
#if CBS_READ
|
||||||
#define fc(width, name, range_min, range_max) \
|
#define fc(width, name, range_min, range_max) \
|
||||||
xf(width, name, current->name, range_min, range_max, 0, )
|
xf(width, name, current->name, range_min, range_max, 0, )
|
||||||
#define flag(name) fb(1, name)
|
#define flag(name) fb(1, name)
|
||||||
@@ -496,14 +517,14 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
|
|||||||
|
|
||||||
#define fb(width, name) do { \
|
#define fb(width, name) do { \
|
||||||
uint32_t value; \
|
uint32_t value; \
|
||||||
CHECK(ff_cbs_read_simple_unsigned(ctx, rw, width, \
|
CHECK(CBS_FUNC(read_simple_unsigned)(ctx, rw, width, \
|
||||||
#name, &value)); \
|
#name, &value)); \
|
||||||
current->name = value; \
|
current->name = value; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define xf(width, name, var, range_min, range_max, subs, ...) do { \
|
#define xf(width, name, var, range_min, range_max, subs, ...) do { \
|
||||||
uint32_t value; \
|
uint32_t value; \
|
||||||
CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
|
CHECK(CBS_FUNC(read_unsigned)(ctx, rw, width, #name, \
|
||||||
SUBSCRIPTS(subs, __VA_ARGS__), \
|
SUBSCRIPTS(subs, __VA_ARGS__), \
|
||||||
&value, range_min, range_max)); \
|
&value, range_min, range_max)); \
|
||||||
var = value; \
|
var = value; \
|
||||||
@@ -511,7 +532,7 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
|
|||||||
|
|
||||||
#define xsu(width, name, var, subs, ...) do { \
|
#define xsu(width, name, var, subs, ...) do { \
|
||||||
int32_t value; \
|
int32_t value; \
|
||||||
CHECK(ff_cbs_read_signed(ctx, rw, width, #name, \
|
CHECK(CBS_FUNC(read_signed)(ctx, rw, width, #name, \
|
||||||
SUBSCRIPTS(subs, __VA_ARGS__), &value, \
|
SUBSCRIPTS(subs, __VA_ARGS__), &value, \
|
||||||
MIN_INT_BITS(width), \
|
MIN_INT_BITS(width), \
|
||||||
MAX_INT_BITS(width))); \
|
MAX_INT_BITS(width))); \
|
||||||
@@ -584,25 +605,27 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
|
|||||||
#undef leb128
|
#undef leb128
|
||||||
#undef infer
|
#undef infer
|
||||||
#undef byte_alignment
|
#undef byte_alignment
|
||||||
|
#endif // CBS_READ
|
||||||
|
|
||||||
|
|
||||||
|
#if CBS_WRITE
|
||||||
#define WRITE
|
#define WRITE
|
||||||
#define READWRITE write
|
#define READWRITE write
|
||||||
#define RWContext PutBitContext
|
#define RWContext PutBitContext
|
||||||
|
|
||||||
#define fb(width, name) do { \
|
#define fb(width, name) do { \
|
||||||
CHECK(ff_cbs_write_simple_unsigned(ctx, rw, width, #name, \
|
CHECK(CBS_FUNC(write_simple_unsigned)(ctx, rw, width, #name, \
|
||||||
current->name)); \
|
current->name)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define xf(width, name, var, range_min, range_max, subs, ...) do { \
|
#define xf(width, name, var, range_min, range_max, subs, ...) do { \
|
||||||
CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
|
CHECK(CBS_FUNC(write_unsigned)(ctx, rw, width, #name, \
|
||||||
SUBSCRIPTS(subs, __VA_ARGS__), \
|
SUBSCRIPTS(subs, __VA_ARGS__), \
|
||||||
var, range_min, range_max)); \
|
var, range_min, range_max)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define xsu(width, name, var, subs, ...) do { \
|
#define xsu(width, name, var, subs, ...) do { \
|
||||||
CHECK(ff_cbs_write_signed(ctx, rw, width, #name, \
|
CHECK(CBS_FUNC(write_signed)(ctx, rw, width, #name, \
|
||||||
SUBSCRIPTS(subs, __VA_ARGS__), var, \
|
SUBSCRIPTS(subs, __VA_ARGS__), var, \
|
||||||
MIN_INT_BITS(width), \
|
MIN_INT_BITS(width), \
|
||||||
MAX_INT_BITS(width))); \
|
MAX_INT_BITS(width))); \
|
||||||
@@ -668,12 +691,13 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
|
|||||||
#undef leb128
|
#undef leb128
|
||||||
#undef infer
|
#undef infer
|
||||||
#undef byte_alignment
|
#undef byte_alignment
|
||||||
|
#endif // CBS_WRITE
|
||||||
|
|
||||||
static int cbs_av1_split_fragment(CodedBitstreamContext *ctx,
|
static int cbs_av1_split_fragment(CodedBitstreamContext *ctx,
|
||||||
CodedBitstreamFragment *frag,
|
CodedBitstreamFragment *frag,
|
||||||
int header)
|
int header)
|
||||||
{
|
{
|
||||||
|
#if CBS_READ
|
||||||
GetBitContext gbc;
|
GetBitContext gbc;
|
||||||
uint8_t *data;
|
uint8_t *data;
|
||||||
size_t size;
|
size_t size;
|
||||||
@@ -763,7 +787,7 @@ static int cbs_av1_split_fragment(CodedBitstreamContext *ctx,
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ff_cbs_append_unit_data(frag, obu_header.obu_type,
|
err = CBS_FUNC(append_unit_data)(frag, obu_header.obu_type,
|
||||||
data, obu_length, frag->data_ref);
|
data, obu_length, frag->data_ref);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
@@ -777,8 +801,12 @@ success:
|
|||||||
fail:
|
fail:
|
||||||
ctx->trace_enable = trace;
|
ctx->trace_enable = trace;
|
||||||
return err;
|
return err;
|
||||||
|
#else
|
||||||
|
return AVERROR(ENOSYS);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CBS_READ
|
||||||
static int cbs_av1_ref_tile_data(CodedBitstreamContext *ctx,
|
static int cbs_av1_ref_tile_data(CodedBitstreamContext *ctx,
|
||||||
CodedBitstreamUnit *unit,
|
CodedBitstreamUnit *unit,
|
||||||
GetBitContext *gbc,
|
GetBitContext *gbc,
|
||||||
@@ -805,16 +833,18 @@ static int cbs_av1_ref_tile_data(CodedBitstreamContext *ctx,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static int cbs_av1_read_unit(CodedBitstreamContext *ctx,
|
static int cbs_av1_read_unit(CodedBitstreamContext *ctx,
|
||||||
CodedBitstreamUnit *unit)
|
CodedBitstreamUnit *unit)
|
||||||
{
|
{
|
||||||
|
#if CBS_READ
|
||||||
CodedBitstreamAV1Context *priv = ctx->priv_data;
|
CodedBitstreamAV1Context *priv = ctx->priv_data;
|
||||||
AV1RawOBU *obu;
|
AV1RawOBU *obu;
|
||||||
GetBitContext gbc;
|
GetBitContext gbc;
|
||||||
int err, start_pos, end_pos;
|
int err, start_pos, end_pos;
|
||||||
|
|
||||||
err = ff_cbs_alloc_unit_content(ctx, unit);
|
err = CBS_FUNC(alloc_unit_content)(ctx, unit);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
obu = unit->content;
|
obu = unit->content;
|
||||||
@@ -931,6 +961,7 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx,
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#if CBS_AV1_OBU_TILE_LIST
|
||||||
case AV1_OBU_TILE_LIST:
|
case AV1_OBU_TILE_LIST:
|
||||||
{
|
{
|
||||||
err = cbs_av1_read_tile_list_obu(ctx, &gbc,
|
err = cbs_av1_read_tile_list_obu(ctx, &gbc,
|
||||||
@@ -946,6 +977,8 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx,
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
#if CBS_AV1_OBU_METADATA
|
||||||
case AV1_OBU_METADATA:
|
case AV1_OBU_METADATA:
|
||||||
{
|
{
|
||||||
err = cbs_av1_read_metadata_obu(ctx, &gbc, &obu->obu.metadata);
|
err = cbs_av1_read_metadata_obu(ctx, &gbc, &obu->obu.metadata);
|
||||||
@@ -953,6 +986,8 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx,
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
#if CBS_AV1_OBU_PADDING
|
||||||
case AV1_OBU_PADDING:
|
case AV1_OBU_PADDING:
|
||||||
{
|
{
|
||||||
err = cbs_av1_read_padding_obu(ctx, &gbc, &obu->obu.padding);
|
err = cbs_av1_read_padding_obu(ctx, &gbc, &obu->obu.padding);
|
||||||
@@ -960,6 +995,7 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx,
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
return AVERROR(ENOSYS);
|
return AVERROR(ENOSYS);
|
||||||
}
|
}
|
||||||
@@ -982,12 +1018,16 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
#else
|
||||||
|
return AVERROR(ENOSYS);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cbs_av1_write_obu(CodedBitstreamContext *ctx,
|
static int cbs_av1_write_obu(CodedBitstreamContext *ctx,
|
||||||
CodedBitstreamUnit *unit,
|
CodedBitstreamUnit *unit,
|
||||||
PutBitContext *pbc)
|
PutBitContext *pbc)
|
||||||
{
|
{
|
||||||
|
#if CBS_WRITE
|
||||||
CodedBitstreamAV1Context *priv = ctx->priv_data;
|
CodedBitstreamAV1Context *priv = ctx->priv_data;
|
||||||
AV1RawOBU *obu = unit->content;
|
AV1RawOBU *obu = unit->content;
|
||||||
PutBitContext pbc_tmp;
|
PutBitContext pbc_tmp;
|
||||||
@@ -1044,7 +1084,7 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx,
|
|||||||
av_refstruct_unref(&priv->sequence_header_ref);
|
av_refstruct_unref(&priv->sequence_header_ref);
|
||||||
priv->sequence_header = NULL;
|
priv->sequence_header = NULL;
|
||||||
|
|
||||||
err = ff_cbs_make_unit_refcounted(ctx, unit);
|
err = CBS_FUNC(make_unit_refcounted)(ctx, unit);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
@@ -1087,6 +1127,7 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx,
|
|||||||
td = &tile_group->tile_data;
|
td = &tile_group->tile_data;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#if CBS_AV1_OBU_TILE_LIST
|
||||||
case AV1_OBU_TILE_LIST:
|
case AV1_OBU_TILE_LIST:
|
||||||
{
|
{
|
||||||
err = cbs_av1_write_tile_list_obu(ctx, pbc, &obu->obu.tile_list);
|
err = cbs_av1_write_tile_list_obu(ctx, pbc, &obu->obu.tile_list);
|
||||||
@@ -1096,6 +1137,8 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx,
|
|||||||
td = &obu->obu.tile_list.tile_data;
|
td = &obu->obu.tile_list.tile_data;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
#if CBS_AV1_OBU_METADATA
|
||||||
case AV1_OBU_METADATA:
|
case AV1_OBU_METADATA:
|
||||||
{
|
{
|
||||||
err = cbs_av1_write_metadata_obu(ctx, pbc, &obu->obu.metadata);
|
err = cbs_av1_write_metadata_obu(ctx, pbc, &obu->obu.metadata);
|
||||||
@@ -1103,6 +1146,8 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
#if CBS_AV1_OBU_PADDING
|
||||||
case AV1_OBU_PADDING:
|
case AV1_OBU_PADDING:
|
||||||
{
|
{
|
||||||
err = cbs_av1_write_padding_obu(ctx, pbc, &obu->obu.padding);
|
err = cbs_av1_write_padding_obu(ctx, pbc, &obu->obu.padding);
|
||||||
@@ -1110,6 +1155,7 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
err = AVERROR(ENOSYS);
|
err = AVERROR(ENOSYS);
|
||||||
goto error;
|
goto error;
|
||||||
@@ -1182,11 +1228,15 @@ error:
|
|||||||
av_buffer_unref(&av1ctx.frame_header_ref);
|
av_buffer_unref(&av1ctx.frame_header_ref);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
|
#else
|
||||||
|
return AVERROR(ENOSYS);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cbs_av1_assemble_fragment(CodedBitstreamContext *ctx,
|
static int cbs_av1_assemble_fragment(CodedBitstreamContext *ctx,
|
||||||
CodedBitstreamFragment *frag)
|
CodedBitstreamFragment *frag)
|
||||||
{
|
{
|
||||||
|
#if CBS_WRITE
|
||||||
size_t size, pos;
|
size_t size, pos;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@@ -1210,6 +1260,9 @@ static int cbs_av1_assemble_fragment(CodedBitstreamContext *ctx,
|
|||||||
frag->data_size = size;
|
frag->data_size = size;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
#else
|
||||||
|
return AVERROR(ENOSYS);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cbs_av1_flush(CodedBitstreamContext *ctx)
|
static void cbs_av1_flush(CodedBitstreamContext *ctx)
|
||||||
@@ -1234,6 +1287,7 @@ static void cbs_av1_close(CodedBitstreamContext *ctx)
|
|||||||
av_buffer_unref(&priv->frame_header_ref);
|
av_buffer_unref(&priv->frame_header_ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CBS_AV1_OBU_METADATA
|
||||||
static void cbs_av1_free_metadata(AVRefStructOpaque unused, void *content)
|
static void cbs_av1_free_metadata(AVRefStructOpaque unused, void *content)
|
||||||
{
|
{
|
||||||
AV1RawOBU *obu = content;
|
AV1RawOBU *obu = content;
|
||||||
@@ -1255,6 +1309,7 @@ static void cbs_av1_free_metadata(AVRefStructOpaque unused, void *content)
|
|||||||
av_buffer_unref(&md->metadata.unknown.payload_ref);
|
av_buffer_unref(&md->metadata.unknown.payload_ref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static const CodedBitstreamUnitTypeDescriptor cbs_av1_unit_types[] = {
|
static const CodedBitstreamUnitTypeDescriptor cbs_av1_unit_types[] = {
|
||||||
CBS_UNIT_TYPE_POD(AV1_OBU_SEQUENCE_HEADER, AV1RawOBU),
|
CBS_UNIT_TYPE_POD(AV1_OBU_SEQUENCE_HEADER, AV1RawOBU),
|
||||||
@@ -1284,13 +1339,19 @@ static const CodedBitstreamUnitTypeDescriptor cbs_av1_unit_types[] = {
|
|||||||
offsetof(AV1RawOBU, obu.frame.tile_group.tile_data.data) }
|
offsetof(AV1RawOBU, obu.frame.tile_group.tile_data.data) }
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
#if CBS_AV1_OBU_TILE_LIST
|
||||||
CBS_UNIT_TYPE_INTERNAL_REF(AV1_OBU_TILE_LIST, AV1RawOBU,
|
CBS_UNIT_TYPE_INTERNAL_REF(AV1_OBU_TILE_LIST, AV1RawOBU,
|
||||||
obu.tile_list.tile_data.data),
|
obu.tile_list.tile_data.data),
|
||||||
|
#endif
|
||||||
|
#if CBS_AV1_OBU_PADDING
|
||||||
CBS_UNIT_TYPE_INTERNAL_REF(AV1_OBU_PADDING, AV1RawOBU,
|
CBS_UNIT_TYPE_INTERNAL_REF(AV1_OBU_PADDING, AV1RawOBU,
|
||||||
obu.padding.payload),
|
obu.padding.payload),
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if CBS_AV1_OBU_METADATA
|
||||||
CBS_UNIT_TYPE_COMPLEX(AV1_OBU_METADATA, AV1RawOBU,
|
CBS_UNIT_TYPE_COMPLEX(AV1_OBU_METADATA, AV1RawOBU,
|
||||||
&cbs_av1_free_metadata),
|
&cbs_av1_free_metadata),
|
||||||
|
#endif
|
||||||
|
|
||||||
CBS_UNIT_TYPE_END_OF_LIST
|
CBS_UNIT_TYPE_END_OF_LIST
|
||||||
};
|
};
|
||||||
@@ -1311,7 +1372,7 @@ static const AVClass cbs_av1_class = {
|
|||||||
.version = LIBAVUTIL_VERSION_INT,
|
.version = LIBAVUTIL_VERSION_INT,
|
||||||
};
|
};
|
||||||
|
|
||||||
const CodedBitstreamType ff_cbs_type_av1 = {
|
const CodedBitstreamType CBS_FUNC(type_av1) = {
|
||||||
.codec_id = AV_CODEC_ID_AV1,
|
.codec_id = AV_CODEC_ID_AV1,
|
||||||
|
|
||||||
.priv_class = &cbs_av1_class,
|
.priv_class = &cbs_av1_class,
|
||||||
|
@@ -25,6 +25,15 @@
|
|||||||
#include "av1.h"
|
#include "av1.h"
|
||||||
#include "cbs.h"
|
#include "cbs.h"
|
||||||
|
|
||||||
|
#ifndef CBS_AV1_OBU_METADATA
|
||||||
|
#define CBS_AV1_OBU_METADATA 1
|
||||||
|
#endif
|
||||||
|
#ifndef CBS_AV1_OBU_TILE_LIST
|
||||||
|
#define CBS_AV1_OBU_TILE_LIST 1
|
||||||
|
#endif
|
||||||
|
#ifndef CBS_AV1_OBU_PADDING
|
||||||
|
#define CBS_AV1_OBU_PADDING 1
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct AV1RawOBUHeader {
|
typedef struct AV1RawOBUHeader {
|
||||||
uint8_t obu_forbidden_bit;
|
uint8_t obu_forbidden_bit;
|
||||||
@@ -411,9 +420,15 @@ typedef struct AV1RawOBU {
|
|||||||
AV1RawFrameHeader frame_header;
|
AV1RawFrameHeader frame_header;
|
||||||
AV1RawFrame frame;
|
AV1RawFrame frame;
|
||||||
AV1RawTileGroup tile_group;
|
AV1RawTileGroup tile_group;
|
||||||
|
#if CBS_AV1_OBU_TILE_LIST
|
||||||
AV1RawTileList tile_list;
|
AV1RawTileList tile_list;
|
||||||
|
#endif
|
||||||
|
#if CBS_AV1_OBU_METADATA
|
||||||
AV1RawMetadata metadata;
|
AV1RawMetadata metadata;
|
||||||
|
#endif
|
||||||
|
#if CBS_AV1_OBU_PADDING
|
||||||
AV1RawPadding padding;
|
AV1RawPadding padding;
|
||||||
|
#endif
|
||||||
} obu;
|
} obu;
|
||||||
} AV1RawOBU;
|
} AV1RawOBU;
|
||||||
|
|
||||||
|
@@ -1868,6 +1868,7 @@ static int FUNC(frame_obu)(CodedBitstreamContext *ctx, RWContext *rw,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CBS_AV1_OBU_TILE_LIST
|
||||||
static int FUNC(tile_list_obu)(CodedBitstreamContext *ctx, RWContext *rw,
|
static int FUNC(tile_list_obu)(CodedBitstreamContext *ctx, RWContext *rw,
|
||||||
AV1RawTileList *current)
|
AV1RawTileList *current)
|
||||||
{
|
{
|
||||||
@@ -1882,7 +1883,9 @@ static int FUNC(tile_list_obu)(CodedBitstreamContext *ctx, RWContext *rw,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if CBS_AV1_OBU_METADATA
|
||||||
static int FUNC(metadata_hdr_cll)(CodedBitstreamContext *ctx, RWContext *rw,
|
static int FUNC(metadata_hdr_cll)(CodedBitstreamContext *ctx, RWContext *rw,
|
||||||
AV1RawMetadataHDRCLL *current)
|
AV1RawMetadataHDRCLL *current)
|
||||||
{
|
{
|
||||||
@@ -2101,7 +2104,9 @@ static int FUNC(metadata_obu)(CodedBitstreamContext *ctx, RWContext *rw,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if CBS_AV1_OBU_PADDING
|
||||||
static int FUNC(padding_obu)(CodedBitstreamContext *ctx, RWContext *rw,
|
static int FUNC(padding_obu)(CodedBitstreamContext *ctx, RWContext *rw,
|
||||||
AV1RawPadding *current)
|
AV1RawPadding *current)
|
||||||
{
|
{
|
||||||
@@ -2125,3 +2130,4 @@ static int FUNC(padding_obu)(CodedBitstreamContext *ctx, RWContext *rw,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
@@ -22,6 +22,8 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "libavutil/log.h"
|
#include "libavutil/log.h"
|
||||||
|
|
||||||
#include "cbs.h"
|
#include "cbs.h"
|
||||||
@@ -30,6 +32,40 @@
|
|||||||
#include "put_bits.h"
|
#include "put_bits.h"
|
||||||
#include "libavutil/refstruct.h"
|
#include "libavutil/refstruct.h"
|
||||||
|
|
||||||
|
#ifndef CBS_READ
|
||||||
|
#define CBS_READ 1
|
||||||
|
#endif
|
||||||
|
#ifndef CBS_WRITE
|
||||||
|
#define CBS_WRITE 1
|
||||||
|
#endif
|
||||||
|
#ifndef CBS_TRACE
|
||||||
|
#define CBS_TRACE 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CBS_AV1
|
||||||
|
#define CBS_AV1 CONFIG_CBS_AV1
|
||||||
|
#endif
|
||||||
|
#ifndef CBS_H264
|
||||||
|
#define CBS_H264 CONFIG_CBS_H264
|
||||||
|
#endif
|
||||||
|
#ifndef CBS_H265
|
||||||
|
#define CBS_H265 CONFIG_CBS_H265
|
||||||
|
#endif
|
||||||
|
#ifndef CBS_H266
|
||||||
|
#define CBS_H266 CONFIG_CBS_H266
|
||||||
|
#endif
|
||||||
|
#ifndef CBS_JPEG
|
||||||
|
#define CBS_JPEG CONFIG_CBS_JPEG
|
||||||
|
#endif
|
||||||
|
#ifndef CBS_MPEG2
|
||||||
|
#define CBS_MPEG2 CONFIG_CBS_MPEG2
|
||||||
|
#endif
|
||||||
|
#ifndef CBS_VP8
|
||||||
|
#define CBS_VP8 CONFIG_CBS_VP8
|
||||||
|
#endif
|
||||||
|
#ifndef CBS_VP9
|
||||||
|
#define CBS_VP9 CONFIG_CBS_VP9
|
||||||
|
#endif
|
||||||
|
|
||||||
enum CBSContentType {
|
enum CBSContentType {
|
||||||
// Unit content may contain some references to other structures, but all
|
// Unit content may contain some references to other structures, but all
|
||||||
@@ -155,7 +191,7 @@ typedef struct CodedBitstreamType {
|
|||||||
|
|
||||||
// Helper functions for trace output.
|
// Helper functions for trace output.
|
||||||
|
|
||||||
void ff_cbs_trace_header(CodedBitstreamContext *ctx,
|
void CBS_FUNC(trace_header)(CodedBitstreamContext *ctx,
|
||||||
const char *name);
|
const char *name);
|
||||||
|
|
||||||
|
|
||||||
@@ -165,28 +201,28 @@ void ff_cbs_trace_header(CodedBitstreamContext *ctx,
|
|||||||
// (i.e. only limited by the amount of bits used) and they lack
|
// (i.e. only limited by the amount of bits used) and they lack
|
||||||
// the ability to use subscripts.
|
// the ability to use subscripts.
|
||||||
|
|
||||||
int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
int CBS_FUNC(read_unsigned)(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
||||||
int width, const char *name,
|
int width, const char *name,
|
||||||
const int *subscripts, uint32_t *write_to,
|
const int *subscripts, uint32_t *write_to,
|
||||||
uint32_t range_min, uint32_t range_max);
|
uint32_t range_min, uint32_t range_max);
|
||||||
|
|
||||||
int ff_cbs_read_simple_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
int CBS_FUNC(read_simple_unsigned)(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
||||||
int width, const char *name, uint32_t *write_to);
|
int width, const char *name, uint32_t *write_to);
|
||||||
|
|
||||||
int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
int CBS_FUNC(write_unsigned)(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
||||||
int width, const char *name,
|
int width, const char *name,
|
||||||
const int *subscripts, uint32_t value,
|
const int *subscripts, uint32_t value,
|
||||||
uint32_t range_min, uint32_t range_max);
|
uint32_t range_min, uint32_t range_max);
|
||||||
|
|
||||||
int ff_cbs_write_simple_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
int CBS_FUNC(write_simple_unsigned)(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
||||||
int width, const char *name, uint32_t value);
|
int width, const char *name, uint32_t value);
|
||||||
|
|
||||||
int ff_cbs_read_signed(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
int CBS_FUNC(read_signed)(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
||||||
int width, const char *name,
|
int width, const char *name,
|
||||||
const int *subscripts, int32_t *write_to,
|
const int *subscripts, int32_t *write_to,
|
||||||
int32_t range_min, int32_t range_max);
|
int32_t range_min, int32_t range_max);
|
||||||
|
|
||||||
int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
int CBS_FUNC(write_signed)(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
||||||
int width, const char *name,
|
int width, const char *name,
|
||||||
const int *subscripts, int32_t value,
|
const int *subscripts, int32_t value,
|
||||||
int32_t range_min, int32_t range_max);
|
int32_t range_min, int32_t range_max);
|
||||||
@@ -204,6 +240,7 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
|||||||
#define MIN_INT_BITS(length) (-(INT64_C(1) << ((length) - 1)))
|
#define MIN_INT_BITS(length) (-(INT64_C(1) << ((length) - 1)))
|
||||||
|
|
||||||
|
|
||||||
|
#if CBS_TRACE
|
||||||
// Start of a syntax element during read tracing.
|
// Start of a syntax element during read tracing.
|
||||||
#define CBS_TRACE_READ_START() \
|
#define CBS_TRACE_READ_START() \
|
||||||
GetBitContext trace_start; \
|
GetBitContext trace_start; \
|
||||||
@@ -284,6 +321,17 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
|||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#else // CBS_TRACE
|
||||||
|
#define CBS_TRACE_READ_START() do { } while (0)
|
||||||
|
#define CBS_TRACE_READ_END() do { } while (0)
|
||||||
|
#define CBS_TRACE_READ_END_NO_SUBSCRIPTS() do { } while (0)
|
||||||
|
#define CBS_TRACE_READ_END_VALUE_ONLY() do { } while (0)
|
||||||
|
#define CBS_TRACE_WRITE_START() do { } while (0)
|
||||||
|
#define CBS_TRACE_WRITE_END() do { } while (0)
|
||||||
|
#define CBS_TRACE_WRITE_END_NO_SUBSCRIPTS() do { } while (0)
|
||||||
|
#define CBS_TRACE_WRITE_END_VALUE_ONLY() do { } while (0)
|
||||||
|
#endif // CBS_TRACE
|
||||||
|
|
||||||
#define TYPE_LIST(...) { __VA_ARGS__ }
|
#define TYPE_LIST(...) { __VA_ARGS__ }
|
||||||
#define CBS_UNIT_TYPE_POD(type_, structure) { \
|
#define CBS_UNIT_TYPE_POD(type_, structure) { \
|
||||||
.nb_unit_types = 1, \
|
.nb_unit_types = 1, \
|
||||||
@@ -335,14 +383,14 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
|||||||
#define CBS_UNIT_TYPE_END_OF_LIST { .nb_unit_types = 0 }
|
#define CBS_UNIT_TYPE_END_OF_LIST { .nb_unit_types = 0 }
|
||||||
|
|
||||||
|
|
||||||
extern const CodedBitstreamType ff_cbs_type_av1;
|
extern const CodedBitstreamType CBS_FUNC(type_av1);
|
||||||
extern const CodedBitstreamType ff_cbs_type_h264;
|
extern const CodedBitstreamType CBS_FUNC(type_h264);
|
||||||
extern const CodedBitstreamType ff_cbs_type_h265;
|
extern const CodedBitstreamType CBS_FUNC(type_h265);
|
||||||
extern const CodedBitstreamType ff_cbs_type_h266;
|
extern const CodedBitstreamType CBS_FUNC(type_h266);
|
||||||
extern const CodedBitstreamType ff_cbs_type_jpeg;
|
extern const CodedBitstreamType CBS_FUNC(type_jpeg);
|
||||||
extern const CodedBitstreamType ff_cbs_type_mpeg2;
|
extern const CodedBitstreamType CBS_FUNC(type_mpeg2);
|
||||||
extern const CodedBitstreamType ff_cbs_type_vp8;
|
extern const CodedBitstreamType CBS_FUNC(type_vp8);
|
||||||
extern const CodedBitstreamType ff_cbs_type_vp9;
|
extern const CodedBitstreamType CBS_FUNC(type_vp9);
|
||||||
|
|
||||||
|
|
||||||
#endif /* AVCODEC_CBS_INTERNAL_H */
|
#endif /* AVCODEC_CBS_INTERNAL_H */
|
||||||
|
Reference in New Issue
Block a user