1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-04 22:03:09 +02:00

fftools/textformat: Apply formatting and whitespace changes

Reviewed-by: Stefano Sabatini <stefasab@gmail.com>
Signed-off-by: softworkz <softworkz@hotmail.com>
This commit is contained in:
softworkz
2025-04-14 05:28:45 +02:00
parent f51c385a8e
commit 8f42d90413
9 changed files with 172 additions and 156 deletions

View File

@ -34,9 +34,9 @@
#include "libavutil/opt.h" #include "libavutil/opt.h"
#include "avtextformat.h" #include "avtextformat.h"
#define SECTION_ID_NONE -1 #define SECTION_ID_NONE (-1)
#define SHOW_OPTIONAL_FIELDS_AUTO -1 #define SHOW_OPTIONAL_FIELDS_AUTO (-1)
#define SHOW_OPTIONAL_FIELDS_NEVER 0 #define SHOW_OPTIONAL_FIELDS_NEVER 0
#define SHOW_OPTIONAL_FIELDS_ALWAYS 1 #define SHOW_OPTIONAL_FIELDS_ALWAYS 1
@ -64,14 +64,14 @@ static const char *textcontext_get_formatter_name(void *p)
static const AVOption textcontext_options[] = { static const AVOption textcontext_options[] = {
{ "string_validation", "set string validation mode", { "string_validation", "set string validation mode",
OFFSET(string_validation), AV_OPT_TYPE_INT, {.i64=AV_TEXTFORMAT_STRING_VALIDATION_REPLACE}, 0, AV_TEXTFORMAT_STRING_VALIDATION_NB-1, .unit = "sv" }, OFFSET(string_validation), AV_OPT_TYPE_INT, { .i64 = AV_TEXTFORMAT_STRING_VALIDATION_REPLACE }, 0, AV_TEXTFORMAT_STRING_VALIDATION_NB - 1, .unit = "sv" },
{ "sv", "set string validation mode", { "sv", "set string validation mode",
OFFSET(string_validation), AV_OPT_TYPE_INT, {.i64=AV_TEXTFORMAT_STRING_VALIDATION_REPLACE}, 0, AV_TEXTFORMAT_STRING_VALIDATION_NB-1, .unit = "sv" }, OFFSET(string_validation), AV_OPT_TYPE_INT, { .i64 = AV_TEXTFORMAT_STRING_VALIDATION_REPLACE }, 0, AV_TEXTFORMAT_STRING_VALIDATION_NB - 1, .unit = "sv" },
{ "ignore", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AV_TEXTFORMAT_STRING_VALIDATION_IGNORE}, .unit = "sv" }, { "ignore", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_TEXTFORMAT_STRING_VALIDATION_IGNORE }, .unit = "sv" },
{ "replace", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AV_TEXTFORMAT_STRING_VALIDATION_REPLACE}, .unit = "sv" }, { "replace", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_TEXTFORMAT_STRING_VALIDATION_REPLACE }, .unit = "sv" },
{ "fail", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AV_TEXTFORMAT_STRING_VALIDATION_FAIL}, .unit = "sv" }, { "fail", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_TEXTFORMAT_STRING_VALIDATION_FAIL }, .unit = "sv" },
{ "string_validation_replacement", "set string validation replacement string", OFFSET(string_validation_replacement), AV_OPT_TYPE_STRING, {.str=""}}, { "string_validation_replacement", "set string validation replacement string", OFFSET(string_validation_replacement), AV_OPT_TYPE_STRING, { .str = "" } },
{ "svr", "set string validation replacement string", OFFSET(string_validation_replacement), AV_OPT_TYPE_STRING, {.str="\xEF\xBF\xBD"}}, { "svr", "set string validation replacement string", OFFSET(string_validation_replacement), AV_OPT_TYPE_STRING, { .str = "\xEF\xBF\xBD" } },
{ NULL } { NULL }
}; };
@ -126,7 +126,7 @@ void avtext_context_close(AVTextFormatContext **ptctx)
int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *formatter, AVTextWriterContext *writer_context, const char *args, int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *formatter, AVTextWriterContext *writer_context, const char *args,
const struct AVTextFormatSection *sections, int nb_sections, const AVTextFormatSection *sections, int nb_sections,
int show_value_unit, int show_value_unit,
int use_value_prefix, int use_value_prefix,
int use_byte_value_binary_prefix, int use_byte_value_binary_prefix,
@ -209,7 +209,7 @@ int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *form
av_log(NULL, AV_LOG_ERROR, " %s", n); av_log(NULL, AV_LOG_ERROR, " %s", n);
av_log(NULL, AV_LOG_ERROR, "\n"); av_log(NULL, AV_LOG_ERROR, "\n");
} }
return ret; goto fail;
} }
} }
@ -224,10 +224,10 @@ int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *form
if (ret < 0) { if (ret < 0) {
AVBPrint bp; AVBPrint bp;
av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC); av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
bprint_bytes(&bp, p0, p-p0), bprint_bytes(&bp, p0, p - p0);
av_log(tctx, AV_LOG_ERROR, av_log(tctx, AV_LOG_ERROR,
"Invalid UTF8 sequence %s found in string validation replace '%s'\n", "Invalid UTF8 sequence %s found in string validation replace '%s'\n",
bp.str, tctx->string_validation_replacement); bp.str, tctx->string_validation_replacement);
return ret; return ret;
} }
} }
@ -248,15 +248,13 @@ fail:
} }
/* Temporary definitions during refactoring */ /* Temporary definitions during refactoring */
static const char unit_second_str[] = "s" ; static const char unit_second_str[] = "s";
static const char unit_hertz_str[] = "Hz" ; static const char unit_hertz_str[] = "Hz";
static const char unit_byte_str[] = "byte" ; static const char unit_byte_str[] = "byte";
static const char unit_bit_per_second_str[] = "bit/s"; static const char unit_bit_per_second_str[] = "bit/s";
void avtext_print_section_header(AVTextFormatContext *tctx, void avtext_print_section_header(AVTextFormatContext *tctx, const void *data, int section_id)
const void *data,
int section_id)
{ {
tctx->level++; tctx->level++;
av_assert0(tctx->level < SECTION_MAX_NB_LEVELS); av_assert0(tctx->level < SECTION_MAX_NB_LEVELS);
@ -273,7 +271,7 @@ void avtext_print_section_footer(AVTextFormatContext *tctx)
{ {
int section_id = tctx->section[tctx->level]->id; int section_id = tctx->section[tctx->level]->id;
int parent_section_id = tctx->level ? int parent_section_id = tctx->level ?
tctx->section[tctx->level-1]->id : SECTION_ID_NONE; tctx->section[tctx->level - 1]->id : SECTION_ID_NONE;
if (parent_section_id != SECTION_ID_NONE) { if (parent_section_id != SECTION_ID_NONE) {
tctx->nb_item[tctx->level - 1]++; tctx->nb_item[tctx->level - 1]++;
@ -285,8 +283,7 @@ void avtext_print_section_footer(AVTextFormatContext *tctx)
tctx->level--; tctx->level--;
} }
void avtext_print_integer(AVTextFormatContext *tctx, void avtext_print_integer(AVTextFormatContext *tctx, const char *key, int64_t val)
const char *key, int64_t val)
{ {
const struct AVTextFormatSection *section = tctx->section[tctx->level]; const struct AVTextFormatSection *section = tctx->section[tctx->level];
@ -324,11 +321,9 @@ static inline int validate_string(AVTextFormatContext *tctx, char **dstp, const
switch (tctx->string_validation) { switch (tctx->string_validation) {
case AV_TEXTFORMAT_STRING_VALIDATION_FAIL: case AV_TEXTFORMAT_STRING_VALIDATION_FAIL:
av_log(tctx, AV_LOG_ERROR, av_log(tctx, AV_LOG_ERROR, "Invalid UTF-8 sequence found in string '%s'\n", src);
"Invalid UTF-8 sequence found in string '%s'\n", src);
ret = AVERROR_INVALIDDATA; ret = AVERROR_INVALIDDATA;
goto end; goto end;
break;
case AV_TEXTFORMAT_STRING_VALIDATION_REPLACE: case AV_TEXTFORMAT_STRING_VALIDATION_REPLACE:
av_bprintf(&dstbuf, "%s", tctx->string_validation_replacement); av_bprintf(&dstbuf, "%s", tctx->string_validation_replacement);
@ -340,11 +335,10 @@ static inline int validate_string(AVTextFormatContext *tctx, char **dstp, const
av_bprint_append_data(&dstbuf, p0, p-p0); av_bprint_append_data(&dstbuf, p0, p-p0);
} }
if (invalid_chars_nb && tctx->string_validation == AV_TEXTFORMAT_STRING_VALIDATION_REPLACE) { if (invalid_chars_nb && tctx->string_validation == AV_TEXTFORMAT_STRING_VALIDATION_REPLACE)
av_log(tctx, AV_LOG_WARNING, av_log(tctx, AV_LOG_WARNING,
"%d invalid UTF-8 sequence(s) found in string '%s', replaced with '%s'\n", "%d invalid UTF-8 sequence(s) found in string '%s', replaced with '%s'\n",
invalid_chars_nb, src, tctx->string_validation_replacement); invalid_chars_nb, src, tctx->string_validation_replacement);
}
end: end:
av_bprint_finalize(&dstbuf, dstp); av_bprint_finalize(&dstbuf, dstp);
@ -352,7 +346,11 @@ end:
} }
struct unit_value { struct unit_value {
union { double d; int64_t i; } val; union {
double d;
int64_t i;
} val;
const char *unit; const char *unit;
}; };
@ -402,8 +400,9 @@ static char *value_string(AVTextFormatContext *tctx, char *buf, int buf_size, st
snprintf(buf, buf_size, "%f", vald); snprintf(buf, buf_size, "%f", vald);
else else
snprintf(buf, buf_size, "%"PRId64, vali); snprintf(buf, buf_size, "%"PRId64, vali);
av_strlcatf(buf, buf_size, "%s%s%s", *prefix_string || tctx->show_value_unit ? " " : "", av_strlcatf(buf, buf_size, "%s%s%s", *prefix_string || tctx->show_value_unit ? " " : "",
prefix_string, tctx->show_value_unit ? uv.unit : ""); prefix_string, tctx->show_value_unit ? uv.unit : "");
} }
return buf; return buf;
@ -427,8 +426,8 @@ int avtext_print_string(AVTextFormatContext *tctx, const char *key, const char *
if (tctx->show_optional_fields == SHOW_OPTIONAL_FIELDS_NEVER || if (tctx->show_optional_fields == SHOW_OPTIONAL_FIELDS_NEVER ||
(tctx->show_optional_fields == SHOW_OPTIONAL_FIELDS_AUTO (tctx->show_optional_fields == SHOW_OPTIONAL_FIELDS_AUTO
&& (flags & AV_TEXTFORMAT_PRINT_STRING_OPTIONAL) && (flags & AV_TEXTFORMAT_PRINT_STRING_OPTIONAL)
&& !(tctx->formatter->flags & AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS))) && !(tctx->formatter->flags & AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS)))
return 0; return 0;
if (section->show_all_entries || av_dict_get(section->entries_to_show, key, NULL, 0)) { if (section->show_all_entries || av_dict_get(section->entries_to_show, key, NULL, 0)) {
@ -440,11 +439,10 @@ int avtext_print_string(AVTextFormatContext *tctx, const char *key, const char *
if (ret < 0) goto end; if (ret < 0) goto end;
tctx->formatter->print_string(tctx, key1, val1); tctx->formatter->print_string(tctx, key1, val1);
end: end:
if (ret < 0) { if (ret < 0)
av_log(tctx, AV_LOG_ERROR, av_log(tctx, AV_LOG_ERROR,
"Invalid key=value string combination %s=%s in section %s\n", "Invalid key=value string combination %s=%s in section %s\n",
key, val, section->unique_name); key, val, section->unique_name);
}
av_free(key1); av_free(key1);
av_free(val1); av_free(val1);
} else { } else {
@ -457,8 +455,7 @@ int avtext_print_string(AVTextFormatContext *tctx, const char *key, const char *
return ret; return ret;
} }
void avtext_print_rational(AVTextFormatContext *tctx, void avtext_print_rational(AVTextFormatContext *tctx, const char *key, AVRational q, char sep)
const char *key, AVRational q, char sep)
{ {
char buf[44]; char buf[44];
snprintf(buf, sizeof(buf), "%d%c%d", q.num, sep, q.den); snprintf(buf, sizeof(buf), "%d%c%d", q.num, sep, q.den);
@ -466,7 +463,7 @@ void avtext_print_rational(AVTextFormatContext *tctx,
} }
void avtext_print_time(AVTextFormatContext *tctx, const char *key, void avtext_print_time(AVTextFormatContext *tctx, const char *key,
int64_t ts, const AVRational *time_base, int is_duration) int64_t ts, const AVRational *time_base, int is_duration)
{ {
char buf[128]; char buf[128];
@ -484,15 +481,14 @@ void avtext_print_time(AVTextFormatContext *tctx, const char *key,
void avtext_print_ts(AVTextFormatContext *tctx, const char *key, int64_t ts, int is_duration) void avtext_print_ts(AVTextFormatContext *tctx, const char *key, int64_t ts, int is_duration)
{ {
if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) { if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0))
avtext_print_string(tctx, key, "N/A", AV_TEXTFORMAT_PRINT_STRING_OPTIONAL); avtext_print_string(tctx, key, "N/A", AV_TEXTFORMAT_PRINT_STRING_OPTIONAL);
} else { else
avtext_print_integer(tctx, key, ts); avtext_print_integer(tctx, key, ts);
}
} }
void avtext_print_data(AVTextFormatContext *tctx, const char *name, void avtext_print_data(AVTextFormatContext *tctx, const char *name,
const uint8_t *data, int size) const uint8_t *data, int size)
{ {
AVBPrint bp; AVBPrint bp;
int offset = 0, l, i; int offset = 0, l, i;
@ -520,12 +516,13 @@ void avtext_print_data(AVTextFormatContext *tctx, const char *name,
} }
void avtext_print_data_hash(AVTextFormatContext *tctx, const char *name, void avtext_print_data_hash(AVTextFormatContext *tctx, const char *name,
const uint8_t *data, int size) const uint8_t *data, int size)
{ {
char *p, buf[AV_HASH_MAX_SIZE * 2 + 64] = { 0 }; char *p, buf[AV_HASH_MAX_SIZE * 2 + 64] = { 0 };
if (!tctx->hash) if (!tctx->hash)
return; return;
av_hash_init(tctx->hash); av_hash_init(tctx->hash);
av_hash_update(tctx->hash, data, size); av_hash_update(tctx->hash, data, size);
snprintf(buf, sizeof(buf), "%s:", av_hash_get_name(tctx->hash)); snprintf(buf, sizeof(buf), "%s:", av_hash_get_name(tctx->hash));
@ -551,7 +548,7 @@ void avtext_print_integers(AVTextFormatContext *tctx, const char *name,
else if (bytes == 2) av_bprintf(&bp, format, AV_RN16(data)); else if (bytes == 2) av_bprintf(&bp, format, AV_RN16(data));
else if (bytes == 4) av_bprintf(&bp, format, AV_RN32(data)); else if (bytes == 4) av_bprintf(&bp, format, AV_RN32(data));
data += bytes; data += bytes;
size --; size--;
} }
av_bprintf(&bp, "\n"); av_bprintf(&bp, "\n");
offset += offset_add; offset += offset_add;
@ -641,7 +638,8 @@ fail:
return ret; return ret;
} }
static const AVTextFormatter *registered_formatters[7+1]; static const AVTextFormatter *registered_formatters[7 + 1];
static void formatters_register_all(void) static void formatters_register_all(void)
{ {
static int initialized; static int initialized;

View File

@ -46,11 +46,11 @@ typedef struct AVTextFormatSection {
#define AV_TEXTFORMAT_SECTION_FLAG_NUMBERING_BY_TYPE 16 ///< the items in this array section should be numbered individually by type #define AV_TEXTFORMAT_SECTION_FLAG_NUMBERING_BY_TYPE 16 ///< the items in this array section should be numbered individually by type
int flags; int flags;
const int children_ids[SECTION_MAX_NB_CHILDREN+1]; ///< list of children section IDS, terminated by -1 const int children_ids[SECTION_MAX_NB_CHILDREN + 1]; ///< list of children section IDS, terminated by -1
const char *element_name; ///< name of the contained element, if provided const char *element_name; ///< name of the contained element, if provided
const char *unique_name; ///< unique section name, in case the name is ambiguous const char *unique_name; ///< unique section name, in case the name is ambiguous
AVDictionary *entries_to_show; AVDictionary *entries_to_show;
const char *(* get_type)(const void *data); ///< function returning a type if defined, must be defined when SECTION_FLAG_HAS_TYPE is defined const char *(*get_type)(const void *data); ///< function returning a type if defined, must be defined when SECTION_FLAG_HAS_TYPE is defined
int show_all_entries; int show_all_entries;
} AVTextFormatSection; } AVTextFormatSection;
@ -86,17 +86,17 @@ typedef struct AVTextFormatter {
#define SECTION_MAX_NB_SECTIONS 100 #define SECTION_MAX_NB_SECTIONS 100
struct AVTextFormatContext { struct AVTextFormatContext {
const AVClass *class; ///< class of the formatter const AVClass *class; ///< class of the formatter
const AVTextFormatter *formatter; ///< the AVTextFormatter of which this is an instance const AVTextFormatter *formatter; ///< the AVTextFormatter of which this is an instance
AVTextWriterContext *writer; ///< the AVTextWriterContext AVTextWriterContext *writer; ///< the AVTextWriterContext
char *name; ///< name of this formatter instance char *name; ///< name of this formatter instance
void *priv; ///< private data for use by the filter void *priv; ///< private data for use by the filter
const struct AVTextFormatSection *sections; ///< array containing all sections const AVTextFormatSection *sections; ///< array containing all sections
int nb_sections; ///< number of sections int nb_sections; ///< number of sections
int level; ///< current level, starting from 0 int level; ///< current level, starting from 0
/** number of the item printed in the given section, starting from 0 */ /** number of the item printed in the given section, starting from 0 */
unsigned int nb_item[SECTION_MAX_NB_LEVELS]; unsigned int nb_item[SECTION_MAX_NB_LEVELS];

View File

@ -37,11 +37,11 @@ typedef struct AVTextWriter {
int priv_size; ///< private size for the writer private class int priv_size; ///< private size for the writer private class
const char *name; const char *name;
int (* init)(AVTextWriterContext *wctx); int (*init)(AVTextWriterContext *wctx);
void (* uninit)(AVTextWriterContext *wctx); void (*uninit)(AVTextWriterContext *wctx);
void (* writer_w8)(AVTextWriterContext *wctx, int b); void (*writer_w8)(AVTextWriterContext *wctx, int b);
void (* writer_put_str)(AVTextWriterContext *wctx, const char *str); void (*writer_put_str)(AVTextWriterContext *wctx, const char *str);
void (* writer_printf)(AVTextWriterContext *wctx, const char *fmt, ...); void (*writer_printf)(AVTextWriterContext *wctx, const char *fmt, ...);
} AVTextWriter; } AVTextWriter;
typedef struct AVTextWriterContext { typedef struct AVTextWriterContext {
@ -49,7 +49,6 @@ typedef struct AVTextWriterContext {
const AVTextWriter *writer; const AVTextWriter *writer;
const char *name; const char *name;
void *priv; ///< private data for use by the writer void *priv; ///< private data for use by the writer
} AVTextWriterContext; } AVTextWriterContext;

View File

@ -58,10 +58,10 @@ static const char *c_escape_str(AVBPrint *dst, const char *src, const char sep,
for (p = src; *p; p++) { for (p = src; *p; p++) {
switch (*p) { switch (*p) {
case '\b': av_bprintf(dst, "%s", "\\b"); break; case '\b': av_bprintf(dst, "%s", "\\b"); break;
case '\f': av_bprintf(dst, "%s", "\\f"); break; case '\f': av_bprintf(dst, "%s", "\\f"); break;
case '\n': av_bprintf(dst, "%s", "\\n"); break; case '\n': av_bprintf(dst, "%s", "\\n"); break;
case '\r': av_bprintf(dst, "%s", "\\r"); break; case '\r': av_bprintf(dst, "%s", "\\r"); break;
case '\\': av_bprintf(dst, "%s", "\\\\"); break; case '\\': av_bprintf(dst, "%s", "\\\\"); break;
default: default:
if (*p == sep) if (*p == sep)
@ -78,6 +78,7 @@ static const char *c_escape_str(AVBPrint *dst, const char *src, const char sep,
static const char *csv_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx) static const char *csv_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
{ {
char meta_chars[] = { sep, '"', '\n', '\r', '\0' }; char meta_chars[] = { sep, '"', '\n', '\r', '\0' };
int needs_quoting = !!src[strcspn(src, meta_chars)]; int needs_quoting = !!src[strcspn(src, meta_chars)];
if (needs_quoting) if (needs_quoting)
@ -114,16 +115,16 @@ typedef struct CompactContext {
#undef OFFSET #undef OFFSET
#define OFFSET(x) offsetof(CompactContext, x) #define OFFSET(x) offsetof(CompactContext, x)
static const AVOption compact_options[]= { static const AVOption compact_options[] = {
{"item_sep", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str="|"}, 0, 0 }, { "item_sep", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, { .str = "|" }, 0, 0 },
{"s", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str="|"}, 0, 0 }, { "s", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, { .str = "|" }, 0, 0 },
{"nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 }, { "nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
{"nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 }, { "nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
{"escape", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="c"}, 0, 0 }, { "escape", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, { .str = "c" }, 0, 0 },
{"e", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="c"}, 0, 0 }, { "e", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, { .str = "c" }, 0, 0 },
{"print_section", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 }, { "print_section", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1 },
{"p", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 }, { "p", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1 },
{NULL}, { NULL },
}; };
DEFINE_FORMATTER_CLASS(compact); DEFINE_FORMATTER_CLASS(compact);
@ -139,10 +140,13 @@ static av_cold int compact_init(AVTextFormatContext *wctx)
} }
compact->item_sep = compact->item_sep_str[0]; compact->item_sep = compact->item_sep_str[0];
if (!strcmp(compact->escape_mode_str, "none")) compact->escape_str = none_escape_str; if (!strcmp(compact->escape_mode_str, "none")) {
else if (!strcmp(compact->escape_mode_str, "c" )) compact->escape_str = c_escape_str; compact->escape_str = none_escape_str;
else if (!strcmp(compact->escape_mode_str, "csv" )) compact->escape_str = csv_escape_str; } else if (!strcmp(compact->escape_mode_str, "c" )) {
else { compact->escape_str = c_escape_str;
} else if (!strcmp(compact->escape_mode_str, "csv" )) {
compact->escape_str = csv_escape_str;
} else {
av_log(wctx, AV_LOG_ERROR, "Unknown escape mode '%s'\n", compact->escape_mode_str); av_log(wctx, AV_LOG_ERROR, "Unknown escape mode '%s'\n", compact->escape_mode_str);
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
@ -162,8 +166,8 @@ static void compact_print_section_header(AVTextFormatContext *wctx, const void *
av_bprint_clear(&wctx->section_pbuf[wctx->level]); av_bprint_clear(&wctx->section_pbuf[wctx->level]);
if (parent_section && if (parent_section &&
(section->flags & AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE || (section->flags & AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE ||
(!(section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY) && (!(section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY) &&
!(parent_section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER|AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY))))) { !(parent_section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY))))) {
/* define a prefix for elements not contained in an array or /* define a prefix for elements not contained in an array or
in a wrapper, or for array elements with a type */ in a wrapper, or for array elements with a type */
@ -171,10 +175,10 @@ static void compact_print_section_header(AVTextFormatContext *wctx, const void *
AVBPrint *section_pbuf = &wctx->section_pbuf[wctx->level]; AVBPrint *section_pbuf = &wctx->section_pbuf[wctx->level];
compact->nested_section[wctx->level] = 1; compact->nested_section[wctx->level] = 1;
compact->has_nested_elems[wctx->level-1] = 1; compact->has_nested_elems[wctx->level - 1] = 1;
av_bprintf(section_pbuf, "%s%s", av_bprintf(section_pbuf, "%s%s",
wctx->section_pbuf[wctx->level-1].str, element_name); wctx->section_pbuf[wctx->level - 1].str, element_name);
if (section->flags & AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE) { if (section->flags & AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE) {
// add /TYPE to prefix // add /TYPE to prefix
@ -191,24 +195,25 @@ static void compact_print_section_header(AVTextFormatContext *wctx, const void *
} }
av_bprint_chars(section_pbuf, ':', 1); av_bprint_chars(section_pbuf, ':', 1);
wctx->nb_item[wctx->level] = wctx->nb_item[wctx->level-1]; wctx->nb_item[wctx->level] = wctx->nb_item[wctx->level - 1];
} else { } else {
if (parent_section && !(parent_section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER|AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY)) && if (parent_section && !(parent_section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY)) &&
wctx->level && wctx->nb_item[wctx->level-1]) wctx->level && wctx->nb_item[wctx->level - 1])
writer_w8(wctx, compact->item_sep); writer_w8(wctx, compact->item_sep);
if (compact->print_section && if (compact->print_section &&
!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER|AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY))) !(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY)))
writer_printf(wctx, "%s%c", section->name, compact->item_sep); writer_printf(wctx, "%s%c", section->name, compact->item_sep);
} }
} }
static void compact_print_section_footer(AVTextFormatContext *wctx) static void compact_print_section_footer(AVTextFormatContext *wctx)
{ {
const struct AVTextFormatSection *section = wctx->section[wctx->level];
CompactContext *compact = wctx->priv; CompactContext *compact = wctx->priv;
if (!compact->nested_section[wctx->level] && if (!compact->nested_section[wctx->level] &&
compact->terminate_line[wctx->level] && compact->terminate_line[wctx->level] &&
!(wctx->section[wctx->level]->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER|AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY))) !(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY)))
writer_w8(wctx, '\n'); writer_w8(wctx, '\n');
} }
@ -217,9 +222,12 @@ static void compact_print_str(AVTextFormatContext *wctx, const char *key, const
CompactContext *compact = wctx->priv; CompactContext *compact = wctx->priv;
AVBPrint buf; AVBPrint buf;
if (wctx->nb_item[wctx->level]) writer_w8(wctx, compact->item_sep); if (wctx->nb_item[wctx->level])
writer_w8(wctx, compact->item_sep);
if (!compact->nokey) if (!compact->nokey)
writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key); writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED); av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
writer_put_str(wctx, compact->escape_str(&buf, value, compact->item_sep, wctx)); writer_put_str(wctx, compact->escape_str(&buf, value, compact->item_sep, wctx));
av_bprint_finalize(&buf, NULL); av_bprint_finalize(&buf, NULL);
@ -229,9 +237,12 @@ static void compact_print_int(AVTextFormatContext *wctx, const char *key, int64_
{ {
CompactContext *compact = wctx->priv; CompactContext *compact = wctx->priv;
if (wctx->nb_item[wctx->level]) writer_w8(wctx, compact->item_sep); if (wctx->nb_item[wctx->level])
writer_w8(wctx, compact->item_sep);
if (!compact->nokey) if (!compact->nokey)
writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key); writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
writer_printf(wctx, "%"PRId64, value); writer_printf(wctx, "%"PRId64, value);
} }
@ -253,15 +264,15 @@ const AVTextFormatter avtextformatter_compact = {
#define OFFSET(x) offsetof(CompactContext, x) #define OFFSET(x) offsetof(CompactContext, x)
static const AVOption csv_options[] = { static const AVOption csv_options[] = {
{"item_sep", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=","}, 0, 0 }, { "item_sep", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, { .str = "," }, 0, 0 },
{"s", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=","}, 0, 0 }, { "s", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, { .str = "," }, 0, 0 },
{"nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 }, { "nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1 },
{"nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 }, { "nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1 },
{"escape", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="csv"}, 0, 0 }, { "escape", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, { .str = "csv" }, 0, 0 },
{"e", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="csv"}, 0, 0 }, { "e", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, { .str = "csv" }, 0, 0 },
{"print_section", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 }, { "print_section", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1 },
{"p", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 }, { "p", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1 },
{NULL}, { NULL },
}; };
DEFINE_FORMATTER_CLASS(csv); DEFINE_FORMATTER_CLASS(csv);

View File

@ -56,11 +56,11 @@ typedef struct DefaultContext {
#define OFFSET(x) offsetof(DefaultContext, x) #define OFFSET(x) offsetof(DefaultContext, x)
static const AVOption default_options[] = { static const AVOption default_options[] = {
{ "noprint_wrappers", "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 }, { "noprint_wrappers", "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
{ "nw", "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 }, { "nw", "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
{ "nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 }, { "nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
{ "nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 }, { "nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
{NULL}, { NULL },
}; };
DEFINE_FORMATTER_CLASS(default); DEFINE_FORMATTER_CLASS(default);
@ -69,7 +69,7 @@ DEFINE_FORMATTER_CLASS(default);
static inline char *upcase_string(char *dst, size_t dst_size, const char *src) static inline char *upcase_string(char *dst, size_t dst_size, const char *src)
{ {
int i; int i;
for (i = 0; src[i] && i < dst_size-1; i++) for (i = 0; src[i] && i < dst_size - 1; i++)
dst[i] = av_toupper(src[i]); dst[i] = av_toupper(src[i]);
dst[i] = 0; dst[i] = 0;
return dst; return dst;
@ -85,10 +85,10 @@ static void default_print_section_header(AVTextFormatContext *wctx, const void *
av_bprint_clear(&wctx->section_pbuf[wctx->level]); av_bprint_clear(&wctx->section_pbuf[wctx->level]);
if (parent_section && if (parent_section &&
!(parent_section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER|AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY))) { !(parent_section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY))) {
def->nested_section[wctx->level] = 1; def->nested_section[wctx->level] = 1;
av_bprintf(&wctx->section_pbuf[wctx->level], "%s%s:", av_bprintf(&wctx->section_pbuf[wctx->level], "%s%s:",
wctx->section_pbuf[wctx->level-1].str, wctx->section_pbuf[wctx->level - 1].str,
upcase_string(buf, sizeof(buf), upcase_string(buf, sizeof(buf),
av_x_if_null(section->element_name, section->name))); av_x_if_null(section->element_name, section->name)));
} }
@ -96,7 +96,7 @@ static void default_print_section_header(AVTextFormatContext *wctx, const void *
if (def->noprint_wrappers || def->nested_section[wctx->level]) if (def->noprint_wrappers || def->nested_section[wctx->level])
return; return;
if (!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER|AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY))) if (!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY)))
writer_printf(wctx, "[%s]\n", upcase_string(buf, sizeof(buf), section->name)); writer_printf(wctx, "[%s]\n", upcase_string(buf, sizeof(buf), section->name));
} }
@ -109,7 +109,7 @@ static void default_print_section_footer(AVTextFormatContext *wctx)
if (def->noprint_wrappers || def->nested_section[wctx->level]) if (def->noprint_wrappers || def->nested_section[wctx->level])
return; return;
if (!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER|AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY))) if (!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY)))
writer_printf(wctx, "[/%s]\n", upcase_string(buf, sizeof(buf), section->name)); writer_printf(wctx, "[/%s]\n", upcase_string(buf, sizeof(buf), section->name));
} }

View File

@ -57,12 +57,12 @@ typedef struct FlatContext {
#undef OFFSET #undef OFFSET
#define OFFSET(x) offsetof(FlatContext, x) #define OFFSET(x) offsetof(FlatContext, x)
static const AVOption flat_options[]= { static const AVOption flat_options[] = {
{"sep_char", "set separator", OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str="."}, 0, 0 }, { "sep_char", "set separator", OFFSET(sep_str), AV_OPT_TYPE_STRING, { .str = "." }, 0, 0 },
{"s", "set separator", OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str="."}, 0, 0 }, { "s", "set separator", OFFSET(sep_str), AV_OPT_TYPE_STRING, { .str = "." }, 0, 0 },
{"hierarchical", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 }, { "hierarchical", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1 },
{"h", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 }, { "h", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1 },
{NULL}, { NULL },
}; };
DEFINE_FORMATTER_CLASS(flat); DEFINE_FORMATTER_CLASS(flat);
@ -126,16 +126,18 @@ static void flat_print_section_header(AVTextFormatContext *wctx, const void *dat
av_bprint_clear(buf); av_bprint_clear(buf);
if (!parent_section) if (!parent_section)
return; return;
av_bprintf(buf, "%s", wctx->section_pbuf[wctx->level-1].str);
av_bprintf(buf, "%s", wctx->section_pbuf[wctx->level - 1].str);
if (flat->hierarchical || if (flat->hierarchical ||
!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY|AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER))) { !(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY | AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER))) {
av_bprintf(buf, "%s%s", wctx->section[wctx->level]->name, flat->sep_str); av_bprintf(buf, "%s%s", wctx->section[wctx->level]->name, flat->sep_str);
if (parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY) { if (parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY) {
int n = parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_NUMBERING_BY_TYPE ? int n = parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_NUMBERING_BY_TYPE
wctx->nb_item_type[wctx->level-1][section->id] : ? wctx->nb_item_type[wctx->level - 1][section->id]
wctx->nb_item[wctx->level-1]; : wctx->nb_item[wctx->level - 1];
av_bprintf(buf, "%d%s", n, flat->sep_str); av_bprintf(buf, "%d%s", n, flat->sep_str);
} }
} }
@ -166,6 +168,6 @@ const AVTextFormatter avtextformatter_flat = {
.print_section_header = flat_print_section_header, .print_section_header = flat_print_section_header,
.print_integer = flat_print_int, .print_integer = flat_print_int,
.print_string = flat_print_str, .print_string = flat_print_str,
.flags = AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS|AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT, .flags = AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS | AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT,
.priv_class = &flat_class, .priv_class = &flat_class,
}; };

View File

@ -64,9 +64,9 @@ typedef struct INIContext {
#define OFFSET(x) offsetof(INIContext, x) #define OFFSET(x) offsetof(INIContext, x)
static const AVOption ini_options[] = { static const AVOption ini_options[] = {
{"hierarchical", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 }, { "hierarchical", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1 },
{"h", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 }, { "h", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1 },
{NULL}, { NULL },
}; };
DEFINE_FORMATTER_CLASS(ini); DEFINE_FORMATTER_CLASS(ini);
@ -74,9 +74,9 @@ DEFINE_FORMATTER_CLASS(ini);
static char *ini_escape_str(AVBPrint *dst, const char *src) static char *ini_escape_str(AVBPrint *dst, const char *src)
{ {
int i = 0; int i = 0;
char c = 0; char c;
while (c = src[i++]) { while ((c = src[i++])) {
switch (c) { switch (c) {
case '\b': av_bprintf(dst, "%s", "\\b"); break; case '\b': av_bprintf(dst, "%s", "\\b"); break;
case '\f': av_bprintf(dst, "%s", "\\f"); break; case '\f': av_bprintf(dst, "%s", "\\f"); break;
@ -84,9 +84,11 @@ static char *ini_escape_str(AVBPrint *dst, const char *src)
case '\r': av_bprintf(dst, "%s", "\\r"); break; case '\r': av_bprintf(dst, "%s", "\\r"); break;
case '\t': av_bprintf(dst, "%s", "\\t"); break; case '\t': av_bprintf(dst, "%s", "\\t"); break;
case '\\': case '\\':
case '#' : case '#':
case '=' : case '=':
case ':' : av_bprint_chars(dst, '\\', 1); case ':':
av_bprint_chars(dst, '\\', 1);
/* fallthrough */
default: default:
if ((unsigned char)c < 32) if ((unsigned char)c < 32)
av_bprintf(dst, "\\x00%02x", c & 0xff); av_bprintf(dst, "\\x00%02x", c & 0xff);
@ -112,23 +114,23 @@ static void ini_print_section_header(AVTextFormatContext *wctx, const void *data
return; return;
} }
if (wctx->nb_item[wctx->level-1]) if (wctx->nb_item[wctx->level - 1])
writer_w8(wctx, '\n'); writer_w8(wctx, '\n');
av_bprintf(buf, "%s", wctx->section_pbuf[wctx->level-1].str); av_bprintf(buf, "%s", wctx->section_pbuf[wctx->level - 1].str);
if (ini->hierarchical || if (ini->hierarchical ||
!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY|AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER))) { !(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY | AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER))) {
av_bprintf(buf, "%s%s", buf->str[0] ? "." : "", wctx->section[wctx->level]->name); av_bprintf(buf, "%s%s", buf->str[0] ? "." : "", wctx->section[wctx->level]->name);
if (parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY) { if (parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY) {
int n = parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_NUMBERING_BY_TYPE ? unsigned n = parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_NUMBERING_BY_TYPE
wctx->nb_item_type[wctx->level-1][section->id] : ? wctx->nb_item_type[wctx->level - 1][section->id]
wctx->nb_item[wctx->level-1]; : wctx->nb_item[wctx->level - 1];
av_bprintf(buf, ".%d", n); av_bprintf(buf, ".%u", n);
} }
} }
if (!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY|AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER))) if (!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY | AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER)))
writer_printf(wctx, "[%s]\n", buf->str); writer_printf(wctx, "[%s]\n", buf->str);
} }
@ -154,6 +156,6 @@ const AVTextFormatter avtextformatter_ini = {
.print_section_header = ini_print_section_header, .print_section_header = ini_print_section_header,
.print_integer = ini_print_int, .print_integer = ini_print_int,
.print_string = ini_print_str, .print_string = ini_print_str,
.flags = AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS|AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT, .flags = AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS | AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT,
.priv_class = &ini_class, .priv_class = &ini_class,
}; };

View File

@ -56,9 +56,9 @@ typedef struct JSONContext {
#undef OFFSET #undef OFFSET
#define OFFSET(x) offsetof(JSONContext, x) #define OFFSET(x) offsetof(JSONContext, x)
static const AVOption json_options[]= { static const AVOption json_options[] = {
{ "compact", "enable compact output", OFFSET(compact), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 }, { "compact", "enable compact output", OFFSET(compact), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
{ "c", "enable compact output", OFFSET(compact), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 }, { "c", "enable compact output", OFFSET(compact), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
{ NULL } { NULL }
}; };
@ -76,8 +76,8 @@ static av_cold int json_init(AVTextFormatContext *wctx)
static const char *json_escape_str(AVBPrint *dst, const char *src, void *log_ctx) static const char *json_escape_str(AVBPrint *dst, const char *src, void *log_ctx)
{ {
static const char json_escape[] = {'"', '\\', '\b', '\f', '\n', '\r', '\t', 0}; static const char json_escape[] = { '"', '\\', '\b', '\f', '\n', '\r', '\t', 0 };
static const char json_subst[] = {'"', '\\', 'b', 'f', 'n', 'r', 't', 0}; static const char json_subst[] = { '"', '\\', 'b', 'f', 'n', 'r', 't', 0 };
const char *p; const char *p;
for (p = src; *p; p++) { for (p = src; *p; p++) {

View File

@ -58,11 +58,11 @@ typedef struct XMLContext {
#define OFFSET(x) offsetof(XMLContext, x) #define OFFSET(x) offsetof(XMLContext, x)
static const AVOption xml_options[] = { static const AVOption xml_options[] = {
{"fully_qualified", "specify if the output should be fully qualified", OFFSET(fully_qualified), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 }, { "fully_qualified", "specify if the output should be fully qualified", OFFSET(fully_qualified), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
{"q", "specify if the output should be fully qualified", OFFSET(fully_qualified), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 }, { "q", "specify if the output should be fully qualified", OFFSET(fully_qualified), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
{"xsd_strict", "ensure that the output is XSD compliant", OFFSET(xsd_strict), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 }, { "xsd_strict", "ensure that the output is XSD compliant", OFFSET(xsd_strict), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
{"x", "ensure that the output is XSD compliant", OFFSET(xsd_strict), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 }, { "x", "ensure that the output is XSD compliant", OFFSET(xsd_strict), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
{NULL}, { NULL },
}; };
DEFINE_FORMATTER_CLASS(xml); DEFINE_FORMATTER_CLASS(xml);
@ -104,8 +104,8 @@ static void xml_print_section_header(AVTextFormatContext *wctx, const void *data
writer_put_str(wctx, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); writer_put_str(wctx, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
writer_printf(wctx, "<%sffprobe%s>\n", writer_printf(wctx, "<%sffprobe%s>\n",
xml->fully_qualified ? "ffprobe:" : "", xml->fully_qualified ? "ffprobe:" : "",
xml->fully_qualified ? qual : ""); xml->fully_qualified ? qual : "");
return; return;
} }
@ -115,12 +115,13 @@ static void xml_print_section_header(AVTextFormatContext *wctx, const void *data
} }
if (parent_section && (parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER) && if (parent_section && (parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER) &&
wctx->level && wctx->nb_item[wctx->level-1]) wctx->level && wctx->nb_item[wctx->level - 1])
writer_w8(wctx, '\n'); writer_w8(wctx, '\n');
xml->indent_level++; xml->indent_level++;
if (section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY|AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS)) { if (section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY | AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS)) {
XML_INDENT(); writer_printf(wctx, "<%s", section->name); XML_INDENT();
writer_printf(wctx, "<%s", section->name);
if (section->flags & AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE) { if (section->flags & AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE) {
AVBPrint buf; AVBPrint buf;
@ -131,7 +132,8 @@ static void xml_print_section_header(AVTextFormatContext *wctx, const void *data
} }
writer_printf(wctx, ">\n", section->name); writer_printf(wctx, ">\n", section->name);
} else { } else {
XML_INDENT(); writer_printf(wctx, "<%s ", section->name); XML_INDENT();
writer_printf(wctx, "<%s ", section->name);
xml->within_tag = 1; xml->within_tag = 1;
} }
} }
@ -148,7 +150,8 @@ static void xml_print_section_footer(AVTextFormatContext *wctx)
writer_put_str(wctx, "/>\n"); writer_put_str(wctx, "/>\n");
xml->indent_level--; xml->indent_level--;
} else { } else {
XML_INDENT(); writer_printf(wctx, "</%s>\n", section->name); XML_INDENT();
writer_printf(wctx, "</%s>\n", section->name);
xml->indent_level--; xml->indent_level--;
} }
} }
@ -195,7 +198,8 @@ static void xml_print_value(AVTextFormatContext *wctx, const char *key,
av_bprint_finalize(&buf, NULL); av_bprint_finalize(&buf, NULL);
} }
static inline void xml_print_str(AVTextFormatContext *wctx, const char *key, const char *value) { static inline void xml_print_str(AVTextFormatContext *wctx, const char *key, const char *value)
{
xml_print_value(wctx, key, value, 0, 0); xml_print_value(wctx, key, value, 0, 0);
} }