You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
avcodec/cbs: Add specialization for ff_cbs_(read|write)_unsigned()
These functions allow not only to read and write unsigned values, but also to check ranges and to emit trace output which can be beautified when processing arrays (indices like "[i]" are replaced by their actual numbers). Yet lots of callers actually only need something simpler: Their range is only implicitly restricted by the amount of bits used and they are not part of arrays, hence don't need this beautification. This commit adds specializations for these callers; this is very beneficial size-wise (it reduced the size of .text by 23312 bytes here), as a call is now cheaper. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
@@ -546,10 +546,13 @@ void ff_cbs_trace_syntax_element(CodedBitstreamContext *ctx, int position,
|
|||||||
position, name, pad, bits, value);
|
position, name, pad, bits, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
static av_always_inline int cbs_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 range_min, uint32_t range_max)
|
uint32_t *write_to,
|
||||||
|
uint32_t range_min,
|
||||||
|
uint32_t range_max)
|
||||||
{
|
{
|
||||||
uint32_t value;
|
uint32_t value;
|
||||||
int position;
|
int position;
|
||||||
@@ -589,6 +592,22 @@ int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
||||||
|
int width, const char *name,
|
||||||
|
const int *subscripts, uint32_t *write_to,
|
||||||
|
uint32_t range_min, uint32_t range_max)
|
||||||
|
{
|
||||||
|
return cbs_read_unsigned(ctx, gbc, width, name, subscripts,
|
||||||
|
write_to, range_min, range_max);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ff_cbs_read_simple_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
||||||
|
int width, const char *name, uint32_t *write_to)
|
||||||
|
{
|
||||||
|
return cbs_read_unsigned(ctx, gbc, width, name, NULL,
|
||||||
|
write_to, 0, UINT32_MAX);
|
||||||
|
}
|
||||||
|
|
||||||
int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
int ff_cbs_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,
|
||||||
@@ -625,6 +644,13 @@ int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ff_cbs_write_simple_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
||||||
|
int width, const char *name, uint32_t value)
|
||||||
|
{
|
||||||
|
return ff_cbs_write_unsigned(ctx, pbc, width, name, NULL,
|
||||||
|
value, 0, MAX_UINT_BITS(width));
|
||||||
|
}
|
||||||
|
|
||||||
int ff_cbs_read_signed(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
int ff_cbs_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,
|
||||||
|
@@ -412,9 +412,8 @@ static int cbs_av1_read_subexp(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (len < max_len) {
|
if (len < max_len) {
|
||||||
err = ff_cbs_read_unsigned(ctx, gbc, range_bits,
|
err = ff_cbs_read_simple_unsigned(ctx, gbc, range_bits,
|
||||||
"subexp_bits", NULL, &value,
|
"subexp_bits", &value);
|
||||||
0, MAX_UINT_BITS(range_bits));
|
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
@@ -476,10 +475,9 @@ 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_unsigned(ctx, pbc, range_bits,
|
err = ff_cbs_write_simple_unsigned(ctx, pbc, range_bits,
|
||||||
"subexp_bits", NULL,
|
"subexp_bits",
|
||||||
value - range_offset,
|
value - range_offset);
|
||||||
0, MAX_UINT_BITS(range_bits));
|
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
@@ -546,8 +544,6 @@ 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)
|
||||||
|
|
||||||
#define fb(width, name) \
|
|
||||||
xf(width, name, current->name, 0, MAX_UINT_BITS(width), 0, )
|
|
||||||
#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)
|
||||||
@@ -573,6 +569,13 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
|
|||||||
#define READWRITE read
|
#define READWRITE read
|
||||||
#define RWContext GetBitContext
|
#define RWContext GetBitContext
|
||||||
|
|
||||||
|
#define fb(width, name) do { \
|
||||||
|
uint32_t value; \
|
||||||
|
CHECK(ff_cbs_read_simple_unsigned(ctx, rw, width, \
|
||||||
|
#name, &value)); \
|
||||||
|
current->name = value; \
|
||||||
|
} 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(ff_cbs_read_unsigned(ctx, rw, width, #name, \
|
||||||
@@ -645,6 +648,7 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
|
|||||||
#undef READ
|
#undef READ
|
||||||
#undef READWRITE
|
#undef READWRITE
|
||||||
#undef RWContext
|
#undef RWContext
|
||||||
|
#undef fb
|
||||||
#undef xf
|
#undef xf
|
||||||
#undef xsu
|
#undef xsu
|
||||||
#undef uvlc
|
#undef uvlc
|
||||||
@@ -661,6 +665,11 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
|
|||||||
#define READWRITE write
|
#define READWRITE write
|
||||||
#define RWContext PutBitContext
|
#define RWContext PutBitContext
|
||||||
|
|
||||||
|
#define fb(width, name) do { \
|
||||||
|
CHECK(ff_cbs_write_simple_unsigned(ctx, rw, width, #name, \
|
||||||
|
current->name)); \
|
||||||
|
} 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(ff_cbs_write_unsigned(ctx, rw, width, #name, \
|
||||||
SUBSCRIPTS(subs, __VA_ARGS__), \
|
SUBSCRIPTS(subs, __VA_ARGS__), \
|
||||||
@@ -723,6 +732,7 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
|
|||||||
#undef WRITE
|
#undef WRITE
|
||||||
#undef READWRITE
|
#undef READWRITE
|
||||||
#undef RWContext
|
#undef RWContext
|
||||||
|
#undef fb
|
||||||
#undef xf
|
#undef xf
|
||||||
#undef xsu
|
#undef xsu
|
||||||
#undef uvlc
|
#undef uvlc
|
||||||
|
@@ -264,8 +264,6 @@ static int cbs_h265_payload_extension_present(GetBitContext *gbc, uint32_t paylo
|
|||||||
|
|
||||||
#define u(width, name, range_min, range_max) \
|
#define u(width, name, range_min, range_max) \
|
||||||
xu(width, name, current->name, range_min, range_max, 0, )
|
xu(width, name, current->name, range_min, range_max, 0, )
|
||||||
#define ub(width, name) \
|
|
||||||
xu(width, name, current->name, 0, MAX_UINT_BITS(width), 0, )
|
|
||||||
#define flag(name) ub(1, name)
|
#define flag(name) ub(1, name)
|
||||||
#define ue(name, range_min, range_max) \
|
#define ue(name, range_min, range_max) \
|
||||||
xue(name, current->name, range_min, range_max, 0, )
|
xue(name, current->name, range_min, range_max, 0, )
|
||||||
@@ -301,6 +299,12 @@ static int cbs_h265_payload_extension_present(GetBitContext *gbc, uint32_t paylo
|
|||||||
#define READWRITE read
|
#define READWRITE read
|
||||||
#define RWContext GetBitContext
|
#define RWContext GetBitContext
|
||||||
|
|
||||||
|
#define ub(width, name) do { \
|
||||||
|
uint32_t value; \
|
||||||
|
CHECK(ff_cbs_read_simple_unsigned(ctx, rw, width, #name, \
|
||||||
|
&value)); \
|
||||||
|
current->name = value; \
|
||||||
|
} while (0)
|
||||||
#define xu(width, name, var, range_min, range_max, subs, ...) do { \
|
#define xu(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(ff_cbs_read_unsigned(ctx, rw, width, #name, \
|
||||||
@@ -379,6 +383,7 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext *gbc)
|
|||||||
#undef READ
|
#undef READ
|
||||||
#undef READWRITE
|
#undef READWRITE
|
||||||
#undef RWContext
|
#undef RWContext
|
||||||
|
#undef ub
|
||||||
#undef xu
|
#undef xu
|
||||||
#undef xi
|
#undef xi
|
||||||
#undef xue
|
#undef xue
|
||||||
@@ -394,6 +399,11 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext *gbc)
|
|||||||
#define READWRITE write
|
#define READWRITE write
|
||||||
#define RWContext PutBitContext
|
#define RWContext PutBitContext
|
||||||
|
|
||||||
|
#define ub(width, name) do { \
|
||||||
|
uint32_t value = current->name; \
|
||||||
|
CHECK(ff_cbs_write_simple_unsigned(ctx, rw, width, #name, \
|
||||||
|
value)); \
|
||||||
|
} while (0)
|
||||||
#define xu(width, name, var, range_min, range_max, subs, ...) do { \
|
#define xu(width, name, var, range_min, range_max, subs, ...) do { \
|
||||||
uint32_t value = var; \
|
uint32_t value = var; \
|
||||||
CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
|
CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
|
||||||
@@ -461,6 +471,7 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext *gbc)
|
|||||||
#undef WRITE
|
#undef WRITE
|
||||||
#undef READWRITE
|
#undef READWRITE
|
||||||
#undef RWContext
|
#undef RWContext
|
||||||
|
#undef ub
|
||||||
#undef xu
|
#undef xu
|
||||||
#undef xi
|
#undef xi
|
||||||
#undef xue
|
#undef xue
|
||||||
|
@@ -163,18 +163,27 @@ void ff_cbs_trace_syntax_element(CodedBitstreamContext *ctx, int position,
|
|||||||
|
|
||||||
|
|
||||||
// Helper functions for read/write of common bitstream elements, including
|
// Helper functions for read/write of common bitstream elements, including
|
||||||
// generation of trace output.
|
// generation of trace output. The simple functions are equivalent to
|
||||||
|
// their non-simple counterparts except that their range is unrestricted
|
||||||
|
// (i.e. only limited by the amount of bits used) and they lack
|
||||||
|
// the ability to use subscripts.
|
||||||
|
|
||||||
int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
int ff_cbs_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 width, const char *name, uint32_t *write_to);
|
||||||
|
|
||||||
int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
int ff_cbs_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 width, const char *name, uint32_t value);
|
||||||
|
|
||||||
int ff_cbs_read_signed(CodedBitstreamContext *ctx, GetBitContext *gbc,
|
int ff_cbs_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,
|
||||||
|
@@ -40,8 +40,6 @@
|
|||||||
|
|
||||||
#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
|
#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
|
||||||
|
|
||||||
#define ui(width, name) \
|
|
||||||
xui(width, name, current->name, 0, MAX_UINT_BITS(width), 0, )
|
|
||||||
#define uir(width, name) \
|
#define uir(width, name) \
|
||||||
xui(width, name, current->name, 1, MAX_UINT_BITS(width), 0, )
|
xui(width, name, current->name, 1, MAX_UINT_BITS(width), 0, )
|
||||||
#define uis(width, name, subs, ...) \
|
#define uis(width, name, subs, ...) \
|
||||||
@@ -65,6 +63,12 @@
|
|||||||
#define READWRITE read
|
#define READWRITE read
|
||||||
#define RWContext GetBitContext
|
#define RWContext GetBitContext
|
||||||
|
|
||||||
|
#define ui(width, name) do { \
|
||||||
|
uint32_t value; \
|
||||||
|
CHECK(ff_cbs_read_simple_unsigned(ctx, rw, width, #name, \
|
||||||
|
&value)); \
|
||||||
|
current->name = value; \
|
||||||
|
} while (0)
|
||||||
#define xuia(width, string, var, range_min, range_max, subs, ...) do { \
|
#define xuia(width, string, var, range_min, range_max, subs, ...) do { \
|
||||||
uint32_t value; \
|
uint32_t value; \
|
||||||
CHECK(ff_cbs_read_unsigned(ctx, rw, width, string, \
|
CHECK(ff_cbs_read_unsigned(ctx, rw, width, string, \
|
||||||
@@ -95,6 +99,7 @@
|
|||||||
#undef READ
|
#undef READ
|
||||||
#undef READWRITE
|
#undef READWRITE
|
||||||
#undef RWContext
|
#undef RWContext
|
||||||
|
#undef ui
|
||||||
#undef xuia
|
#undef xuia
|
||||||
#undef xsi
|
#undef xsi
|
||||||
#undef nextbits
|
#undef nextbits
|
||||||
@@ -105,6 +110,11 @@
|
|||||||
#define READWRITE write
|
#define READWRITE write
|
||||||
#define RWContext PutBitContext
|
#define RWContext PutBitContext
|
||||||
|
|
||||||
|
#define ui(width, name) do { \
|
||||||
|
CHECK(ff_cbs_write_simple_unsigned(ctx, rw, width, #name, \
|
||||||
|
current->name)); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#define xuia(width, string, var, range_min, range_max, subs, ...) do { \
|
#define xuia(width, string, var, range_min, range_max, subs, ...) do { \
|
||||||
CHECK(ff_cbs_write_unsigned(ctx, rw, width, string, \
|
CHECK(ff_cbs_write_unsigned(ctx, rw, width, string, \
|
||||||
SUBSCRIPTS(subs, __VA_ARGS__), \
|
SUBSCRIPTS(subs, __VA_ARGS__), \
|
||||||
@@ -134,6 +144,7 @@
|
|||||||
#undef WRITE
|
#undef WRITE
|
||||||
#undef READWRITE
|
#undef READWRITE
|
||||||
#undef RWContext
|
#undef RWContext
|
||||||
|
#undef ui
|
||||||
#undef xuia
|
#undef xuia
|
||||||
#undef xsi
|
#undef xsi
|
||||||
#undef nextbits
|
#undef nextbits
|
||||||
|
@@ -251,8 +251,6 @@ static int cbs_vp9_write_le(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
|||||||
|
|
||||||
#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
|
#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
|
||||||
|
|
||||||
#define f(width, name) \
|
|
||||||
xf(width, name, current->name, 0, )
|
|
||||||
#define s(width, name) \
|
#define s(width, name) \
|
||||||
xs(width, name, current->name, 0, )
|
xs(width, name, current->name, 0, )
|
||||||
#define fs(width, name, subs, ...) \
|
#define fs(width, name, subs, ...) \
|
||||||
@@ -264,6 +262,12 @@ static int cbs_vp9_write_le(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
|||||||
#define READWRITE read
|
#define READWRITE read
|
||||||
#define RWContext GetBitContext
|
#define RWContext GetBitContext
|
||||||
|
|
||||||
|
#define f(width, name) do { \
|
||||||
|
uint32_t value; \
|
||||||
|
CHECK(ff_cbs_read_simple_unsigned(ctx, rw, width, #name, \
|
||||||
|
&value)); \
|
||||||
|
current->name = value; \
|
||||||
|
} while (0)
|
||||||
#define xf(width, name, var, subs, ...) do { \
|
#define xf(width, name, var, subs, ...) do { \
|
||||||
uint32_t value; \
|
uint32_t value; \
|
||||||
CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
|
CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
|
||||||
@@ -329,6 +333,7 @@ static int cbs_vp9_write_le(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
|||||||
#undef READ
|
#undef READ
|
||||||
#undef READWRITE
|
#undef READWRITE
|
||||||
#undef RWContext
|
#undef RWContext
|
||||||
|
#undef f
|
||||||
#undef xf
|
#undef xf
|
||||||
#undef xs
|
#undef xs
|
||||||
#undef increment
|
#undef increment
|
||||||
@@ -344,6 +349,10 @@ static int cbs_vp9_write_le(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
|||||||
#define READWRITE write
|
#define READWRITE write
|
||||||
#define RWContext PutBitContext
|
#define RWContext PutBitContext
|
||||||
|
|
||||||
|
#define f(width, name) do { \
|
||||||
|
CHECK(ff_cbs_write_simple_unsigned(ctx, rw, width, #name, \
|
||||||
|
current->name)); \
|
||||||
|
} while (0)
|
||||||
#define xf(width, name, var, subs, ...) do { \
|
#define xf(width, name, var, subs, ...) do { \
|
||||||
CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
|
CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
|
||||||
SUBSCRIPTS(subs, __VA_ARGS__), \
|
SUBSCRIPTS(subs, __VA_ARGS__), \
|
||||||
@@ -396,6 +405,7 @@ static int cbs_vp9_write_le(CodedBitstreamContext *ctx, PutBitContext *pbc,
|
|||||||
#undef WRITE
|
#undef WRITE
|
||||||
#undef READWRITE
|
#undef READWRITE
|
||||||
#undef RWContext
|
#undef RWContext
|
||||||
|
#undef f
|
||||||
#undef xf
|
#undef xf
|
||||||
#undef xs
|
#undef xs
|
||||||
#undef increment
|
#undef increment
|
||||||
|
Reference in New Issue
Block a user