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

fftools/textformat: Introduce AVTextFormatOptions for avtext_context_open()

This allows future addition of options without
changes to the signature of avtext_context_open().

Reviewed-by: Stefano Sabatini <stefasab@gmail.com>
Signed-off-by: softworkz <softworkz@hotmail.com>
This commit is contained in:
softworkz
2025-04-24 01:31:52 +02:00
parent 4ff90f05c7
commit e4830b8c5e
3 changed files with 24 additions and 23 deletions

View File

@ -3167,10 +3167,15 @@ int main(int argc, char **argv)
if (ret < 0) if (ret < 0)
goto end; goto end;
if ((ret = avtext_context_open(&tctx, f, wctx, f_args, AVTextFormatOptions tf_options = {
sections, FF_ARRAY_ELEMS(sections), show_value_unit, .show_optional_fields = show_optional_fields,
use_value_prefix, use_byte_value_binary_prefix, use_value_sexagesimal_format, .show_value_unit = show_value_unit,
show_optional_fields, show_data_hash)) >= 0) { .use_value_prefix = use_value_prefix,
.use_byte_value_binary_prefix = use_byte_value_binary_prefix,
.use_value_sexagesimal_format = use_value_sexagesimal_format,
};
if ((ret = avtext_context_open(&tctx, f, wctx, f_args, sections, FF_ARRAY_ELEMS(sections), tf_options, show_data_hash)) >= 0) {
if (f == &avtextformatter_xml) if (f == &avtextformatter_xml)
tctx->string_validation_utf8_flags |= AV_UTF8_FLAG_EXCLUDE_XML_INVALID_CONTROL_CODES; tctx->string_validation_utf8_flags |= AV_UTF8_FLAG_EXCLUDE_XML_INVALID_CONTROL_CODES;

View File

@ -125,13 +125,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 AVTextFormatSection *sections, int nb_sections, const AVTextFormatSection *sections, int nb_sections, AVTextFormatOptions options, char *show_data_hash)
int show_value_unit,
int use_value_prefix,
int use_byte_value_binary_prefix,
int use_value_sexagesimal_format,
int show_optional_fields,
char *show_data_hash)
{ {
AVTextFormatContext *tctx; AVTextFormatContext *tctx;
int i, ret = 0; int i, ret = 0;
@ -154,11 +148,11 @@ int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *form
goto fail; goto fail;
} }
tctx->show_value_unit = show_value_unit; tctx->show_value_unit = options.show_value_unit;
tctx->use_value_prefix = use_value_prefix; tctx->use_value_prefix = options.use_value_prefix;
tctx->use_byte_value_binary_prefix = use_byte_value_binary_prefix; tctx->use_byte_value_binary_prefix = options.use_byte_value_binary_prefix;
tctx->use_value_sexagesimal_format = use_value_sexagesimal_format; tctx->use_value_sexagesimal_format = options.use_value_sexagesimal_format;
tctx->show_optional_fields = show_optional_fields; tctx->show_optional_fields = options.show_optional_fields;
if (nb_sections > SECTION_MAX_NB_SECTIONS) { if (nb_sections > SECTION_MAX_NB_SECTIONS) {
av_log(tctx, AV_LOG_ERROR, "The number of section definitions (%d) is larger than the maximum allowed (%d)\n", nb_sections, SECTION_MAX_NB_SECTIONS); av_log(tctx, AV_LOG_ERROR, "The number of section definitions (%d) is larger than the maximum allowed (%d)\n", nb_sections, SECTION_MAX_NB_SECTIONS);

View File

@ -117,17 +117,19 @@ struct AVTextFormatContext {
unsigned int string_validation_utf8_flags; unsigned int string_validation_utf8_flags;
}; };
typedef struct AVTextFormatOptions {
int show_optional_fields;
int show_value_unit;
int use_value_prefix;
int use_byte_value_binary_prefix;
int use_value_sexagesimal_format;
} AVTextFormatOptions;
#define AV_TEXTFORMAT_PRINT_STRING_OPTIONAL 1 #define AV_TEXTFORMAT_PRINT_STRING_OPTIONAL 1
#define AV_TEXTFORMAT_PRINT_STRING_VALIDATE 2 #define AV_TEXTFORMAT_PRINT_STRING_VALIDATE 2
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 AVTextFormatSection *sections, int nb_sections, const AVTextFormatSection *sections, int nb_sections, AVTextFormatOptions options, char *show_data_hash);
int show_value_unit,
int use_value_prefix,
int use_byte_value_binary_prefix,
int use_value_sexagesimal_format,
int show_optional_fields,
char *show_data_hash);
void avtext_context_close(AVTextFormatContext **tctx); void avtext_context_close(AVTextFormatContext **tctx);