Commit 300ef253 authored by Mark Thompson's avatar Mark Thompson

cbs: Add support for array subscripts in trace output

This makes the trace output for arrays significantly nicer.
parent 315cc8c0
......@@ -356,17 +356,43 @@ void ff_cbs_trace_header(CodedBitstreamContext *ctx,
}
void ff_cbs_trace_syntax_element(CodedBitstreamContext *ctx, int position,
const char *name, const char *bits,
int64_t value)
const char *str, const int *subscripts,
const char *bits, int64_t value)
{
char name[256];
size_t name_len, bits_len;
int pad;
int pad, subs, i, j, k, n;
if (!ctx->trace_enable)
return;
av_assert0(value >= INT_MIN && value <= UINT32_MAX);
subs = subscripts ? subscripts[0] : 0;
n = 0;
for (i = j = 0; str[i];) {
if (str[i] == '[') {
if (n < subs) {
++n;
k = snprintf(name + j, sizeof(name) - j, "[%d", subscripts[n]);
av_assert0(k > 0 && j + k < sizeof(name));
j += k;
for (++i; str[i] && str[i] != ']'; i++);
av_assert0(str[i] == ']');
} else {
while (str[i] && str[i] != ']')
name[j++] = str[i++];
av_assert0(str[i] == ']');
}
} else {
av_assert0(j + 1 < sizeof(name));
name[j++] = str[i++];
}
}
av_assert0(j + 1 < sizeof(name));
name[j] = 0;
av_assert0(n == subs);
name_len = strlen(name);
bits_len = strlen(bits);
......@@ -380,7 +406,8 @@ void ff_cbs_trace_syntax_element(CodedBitstreamContext *ctx, int position,
}
int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
int width, const char *name, uint32_t *write_to,
int width, const char *name,
const int *subscripts, uint32_t *write_to,
uint32_t range_min, uint32_t range_max)
{
uint32_t value;
......@@ -406,7 +433,8 @@ int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
bits[i] = value >> (width - i - 1) & 1 ? '1' : '0';
bits[i] = 0;
ff_cbs_trace_syntax_element(ctx, position, name, bits, value);
ff_cbs_trace_syntax_element(ctx, position, name, subscripts,
bits, value);
}
if (value < range_min || value > range_max) {
......@@ -421,7 +449,8 @@ int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
}
int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
int width, const char *name, uint32_t value,
int width, const char *name,
const int *subscripts, uint32_t value,
uint32_t range_min, uint32_t range_max)
{
av_assert0(width > 0 && width <= 32);
......@@ -443,7 +472,8 @@ int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
bits[i] = value >> (width - i - 1) & 1 ? '1' : '0';
bits[i] = 0;
ff_cbs_trace_syntax_element(ctx, put_bits_count(pbc), name, bits, value);
ff_cbs_trace_syntax_element(ctx, put_bits_count(pbc),
name, subscripts, bits, value);
}
if (width < 32)
......
......@@ -32,7 +32,8 @@
static int cbs_read_ue_golomb(CodedBitstreamContext *ctx, GetBitContext *gbc,
const char *name, uint32_t *write_to,
const char *name, const int *subscripts,
uint32_t *write_to,
uint32_t range_min, uint32_t range_max)
{
uint32_t value;
......@@ -68,7 +69,8 @@ static int cbs_read_ue_golomb(CodedBitstreamContext *ctx, GetBitContext *gbc,
--value;
if (ctx->trace_enable)
ff_cbs_trace_syntax_element(ctx, position, name, bits, value);
ff_cbs_trace_syntax_element(ctx, position, name, subscripts,
bits, value);
if (value < range_min || value > range_max) {
av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
......@@ -82,7 +84,8 @@ static int cbs_read_ue_golomb(CodedBitstreamContext *ctx, GetBitContext *gbc,
}
static int cbs_read_se_golomb(CodedBitstreamContext *ctx, GetBitContext *gbc,
const char *name, int32_t *write_to,
const char *name, const int *subscripts,
int32_t *write_to,
int32_t range_min, int32_t range_max)
{
int32_t value;
......@@ -122,7 +125,8 @@ static int cbs_read_se_golomb(CodedBitstreamContext *ctx, GetBitContext *gbc,
value = v / 2;
if (ctx->trace_enable)
ff_cbs_trace_syntax_element(ctx, position, name, bits, value);
ff_cbs_trace_syntax_element(ctx, position, name, subscripts,
bits, value);
if (value < range_min || value > range_max) {
av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
......@@ -136,7 +140,8 @@ static int cbs_read_se_golomb(CodedBitstreamContext *ctx, GetBitContext *gbc,
}
static int cbs_write_ue_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc,
const char *name, uint32_t value,
const char *name, const int *subscripts,
uint32_t value,
uint32_t range_min, uint32_t range_max)
{
int len;
......@@ -164,7 +169,8 @@ static int cbs_write_ue_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc,
bits[len + i + 1] = (value + 1) >> (len - i - 1) & 1 ? '1' : '0';
bits[len + len + 1] = 0;
ff_cbs_trace_syntax_element(ctx, put_bits_count(pbc), name, bits, value);
ff_cbs_trace_syntax_element(ctx, put_bits_count(pbc),
name, subscripts, bits, value);
}
put_bits(pbc, len, 0);
......@@ -177,7 +183,8 @@ static int cbs_write_ue_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc,
}
static int cbs_write_se_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc,
const char *name, int32_t value,
const char *name, const int *subscripts,
int32_t value,
int32_t range_min, int32_t range_max)
{
int len;
......@@ -213,7 +220,8 @@ static int cbs_write_se_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc,
bits[len + i + 1] = (uvalue + 1) >> (len - i - 1) & 1 ? '1' : '0';
bits[len + len + 1] = 0;
ff_cbs_trace_syntax_element(ctx, put_bits_count(pbc), name, bits, value);
ff_cbs_trace_syntax_element(ctx, put_bits_count(pbc),
name, subscripts, bits, value);
}
put_bits(pbc, len, 0);
......@@ -239,9 +247,28 @@ static int cbs_write_se_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc,
#define FUNC_H264(rw, name) FUNC_NAME(rw, h264, name)
#define FUNC_H265(rw, name) FUNC_NAME(rw, h265, name)
#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
#define u(width, name, range_min, range_max) \
xu(width, name, current->name, range_min, range_max, 0)
#define flag(name) u(1, name, 0, 1)
#define ue(name, range_min, range_max) \
xue(name, current->name, range_min, range_max, 0)
#define se(name, range_min, range_max) \
xse(name, current->name, range_min, range_max, 0)
#define us(width, name, range_min, range_max, subs, ...) \
xu(width, name, current->name, range_min, range_max, subs, __VA_ARGS__)
#define flags(name, subs, ...) \
xu(1, name, current->name, 0, 1, subs, __VA_ARGS__)
#define ues(name, range_min, range_max, subs, ...) \
xue(name, current->name, range_min, range_max, subs, __VA_ARGS__)
#define ses(name, range_min, range_max, subs, ...) \
xse(name, current->name, range_min, range_max, subs, __VA_ARGS__)
#define fixed(width, name, value) do { \
av_unused uint32_t fixed_value = value; \
xu(width, name, fixed_value, value, value); \
xu(width, name, fixed_value, value, value, 0); \
} while (0)
......@@ -249,34 +276,29 @@ static int cbs_write_se_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc,
#define READWRITE read
#define RWContext GetBitContext
#define xu(width, name, var, range_min, range_max) do { \
#define xu(width, name, var, range_min, range_max, subs, ...) do { \
uint32_t value = range_min; \
CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
SUBSCRIPTS(subs, __VA_ARGS__), \
&value, range_min, range_max)); \
var = value; \
} while (0)
#define xue(name, var, range_min, range_max) do { \
#define xue(name, var, range_min, range_max, subs, ...) do { \
uint32_t value = range_min; \
CHECK(cbs_read_ue_golomb(ctx, rw, #name, \
SUBSCRIPTS(subs, __VA_ARGS__), \
&value, range_min, range_max)); \
var = value; \
} while (0)
#define xse(name, var, range_min, range_max) do { \
#define xse(name, var, range_min, range_max, subs, ...) do { \
int32_t value = range_min; \
CHECK(cbs_read_se_golomb(ctx, rw, #name, \
SUBSCRIPTS(subs, __VA_ARGS__), \
&value, range_min, range_max)); \
var = value; \
} while (0)
#define u(width, name, range_min, range_max) \
xu(width, name, current->name, range_min, range_max)
#define flag(name) u(1, name, 0, 1)
#define ue(name, range_min, range_max) \
xue(name, current->name, range_min, range_max)
#define se(name, range_min, range_max) \
xse(name, current->name, range_min, range_max)
#define infer(name, value) do { \
current->name = value; \
} while (0)
......@@ -316,10 +338,6 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext *gbc)
#undef xu
#undef xue
#undef xse
#undef u
#undef flag
#undef ue
#undef se
#undef infer
#undef more_rbsp_data
#undef byte_alignment
......@@ -330,30 +348,25 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext *gbc)
#define READWRITE write
#define RWContext PutBitContext
#define xu(width, name, var, range_min, range_max) do { \
#define xu(width, name, var, range_min, range_max, subs, ...) do { \
uint32_t value = var; \
CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
SUBSCRIPTS(subs, __VA_ARGS__), \
value, range_min, range_max)); \
} while (0)
#define xue(name, var, range_min, range_max) do { \
#define xue(name, var, range_min, range_max, subs, ...) do { \
uint32_t value = var; \
CHECK(cbs_write_ue_golomb(ctx, rw, #name, \
SUBSCRIPTS(subs, __VA_ARGS__), \
value, range_min, range_max)); \
} while (0)
#define xse(name, var, range_min, range_max) do { \
#define xse(name, var, range_min, range_max, subs, ...) do { \
int32_t value = var; \
CHECK(cbs_write_se_golomb(ctx, rw, #name, \
SUBSCRIPTS(subs, __VA_ARGS__), \
value, range_min, range_max)); \
} while (0)
#define u(width, name, range_min, range_max) \
xu(width, name, current->name, range_min, range_max)
#define flag(name) u(1, name, 0, 1)
#define ue(name, range_min, range_max) \
xue(name, current->name, range_min, range_max)
#define se(name, range_min, range_max) \
xse(name, current->name, range_min, range_max)
#define infer(name, value) do { \
if (current->name != (value)) { \
av_log(ctx->log_ctx, AV_LOG_WARNING, "Warning: " \
......
This diff is collapsed.
This diff is collapsed.
......@@ -63,8 +63,8 @@ typedef struct CodedBitstreamType {
void ff_cbs_trace_header(CodedBitstreamContext *ctx,
const char *name);
void ff_cbs_trace_syntax_element(CodedBitstreamContext *ctx,
int position, const char *name,
void ff_cbs_trace_syntax_element(CodedBitstreamContext *ctx, int position,
const char *name, const int *subscripts,
const char *bitstring, int64_t value);
......@@ -72,11 +72,13 @@ void ff_cbs_trace_syntax_element(CodedBitstreamContext *ctx,
// generation of trace output.
int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
int width, const char *name, uint32_t *write_to,
int width, const char *name,
const int *subscripts, uint32_t *write_to,
uint32_t range_min, uint32_t range_max);
int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
int width, const char *name, uint32_t value,
int width, const char *name,
const int *subscripts, uint32_t value,
uint32_t range_min, uint32_t range_max);
// The largest value representable in N bits, suitable for use as
......
......@@ -38,24 +38,29 @@
#define FUNC_MPEG2(rw, name) FUNC_NAME(rw, mpeg2, name)
#define FUNC(name) FUNC_MPEG2(READWRITE, name)
#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
#define ui(width, name) \
xui(width, name, current->name, 0)
#define uis(width, name, subs, ...) \
xui(width, name, current->name, subs, __VA_ARGS__)
#define READ
#define READWRITE read
#define RWContext GetBitContext
#define xui(width, name, var) do { \
#define xui(width, name, var, subs, ...) do { \
uint32_t value = 0; \
CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
SUBSCRIPTS(subs, __VA_ARGS__), \
&value, 0, (1 << width) - 1)); \
var = value; \
} while (0)
#define ui(width, name) \
xui(width, name, current->name)
#define marker_bit() do { \
av_unused uint32_t one; \
CHECK(ff_cbs_read_unsigned(ctx, rw, 1, "marker_bit", &one, 1, 1)); \
CHECK(ff_cbs_read_unsigned(ctx, rw, 1, "marker_bit", NULL, &one, 1, 1)); \
} while (0)
#define nextbits(width, compare, var) \
......@@ -68,7 +73,6 @@
#undef READWRITE
#undef RWContext
#undef xui
#undef ui
#undef marker_bit
#undef nextbits
......@@ -77,16 +81,14 @@
#define READWRITE write
#define RWContext PutBitContext
#define xui(width, name, var) do { \
#define xui(width, name, var, subs, ...) do { \
CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
SUBSCRIPTS(subs, __VA_ARGS__), \
var, 0, (1 << width) - 1)); \
} while (0)
#define ui(width, name) \
xui(width, name, current->name)
#define marker_bit() do { \
CHECK(ff_cbs_write_unsigned(ctx, rw, 1, "marker_bit", 1, 1, 1)); \
CHECK(ff_cbs_write_unsigned(ctx, rw, 1, "marker_bit", NULL, 1, 1, 1)); \
} while (0)
#define nextbits(width, compare, var) (var)
......@@ -97,7 +99,6 @@
#undef READWRITE
#undef RWContext
#undef xui
#undef ui
#undef marker_bit
#undef nextbits
......
......@@ -44,13 +44,13 @@ static int FUNC(sequence_header)(CodedBitstreamContext *ctx, RWContext *rw,
ui(1, load_intra_quantiser_matrix);
if (current->load_intra_quantiser_matrix) {
for (i = 0; i < 64; i++)
ui(8, intra_quantiser_matrix[i]);
uis(8, intra_quantiser_matrix[i], 1, i);
}
ui(1, load_non_intra_quantiser_matrix);
if (current->load_non_intra_quantiser_matrix) {
for (i = 0; i < 64; i++)
ui(8, non_intra_quantiser_matrix[i]);
uis(8, non_intra_quantiser_matrix[i], 1, i);
}
return 0;
......@@ -79,7 +79,7 @@ static int FUNC(user_data)(CodedBitstreamContext *ctx, RWContext *rw,
#endif
for (k = 0; k < current->user_data_length; k++)
xui(8, user_data, current->user_data[k]);
xui(8, user_data, current->user_data[k], 0);
return 0;
}
......@@ -250,25 +250,25 @@ static int FUNC(quant_matrix_extension)(CodedBitstreamContext *ctx, RWContext *r
ui(1, load_intra_quantiser_matrix);
if (current->load_intra_quantiser_matrix) {
for (i = 0; i < 64; i++)
ui(8, intra_quantiser_matrix[i]);
uis(8, intra_quantiser_matrix[i], 1, i);
}
ui(1, load_non_intra_quantiser_matrix);
if (current->load_non_intra_quantiser_matrix) {
for (i = 0; i < 64; i++)
ui(8, non_intra_quantiser_matrix[i]);
uis(8, non_intra_quantiser_matrix[i], 1, i);
}
ui(1, load_chroma_intra_quantiser_matrix);
if (current->load_chroma_intra_quantiser_matrix) {
for (i = 0; i < 64; i++)
ui(8, intra_quantiser_matrix[i]);
uis(8, intra_quantiser_matrix[i], 1, i);
}
ui(1, load_chroma_non_intra_quantiser_matrix);
if (current->load_chroma_non_intra_quantiser_matrix) {
for (i = 0; i < 64; i++)
ui(8, chroma_non_intra_quantiser_matrix[i]);
uis(8, chroma_non_intra_quantiser_matrix[i], 1, i);
}
return 0;
......@@ -366,15 +366,16 @@ static int FUNC(slice_header)(CodedBitstreamContext *ctx, RWContext *rw,
if (!current->extra_information)
return AVERROR(ENOMEM);
for (k = 0; k < current->extra_information_length; k++) {
xui(1, extra_bit_slice, bit);
xui(8, extra_information_slice,
current->extra_information[k]);
xui(1, extra_bit_slice, bit, 0);
xui(8, extra_information_slice[k],
current->extra_information[k], 1, k);
}
}
#else
for (k = 0; k < current->extra_information_length; k++) {
xui(1, extra_bit_slice, 1);
xui(8, extra_information_slice, current->extra_information[k]);
xui(1, extra_bit_slice, 1, 0);
xui(8, extra_information_slice[k],
current->extra_information[k], 1, k);
}
#endif
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment