27 #include "libavutil/ffversion.h"
75 # ifdef pthread_mutex_lock
76 # undef pthread_mutex_lock
78 # define pthread_mutex_lock(a) do{}while(0)
79 # ifdef pthread_mutex_unlock
80 # undef pthread_mutex_unlock
82 # define pthread_mutex_unlock(a) do{}while(0)
146 #define SHOW_OPTIONAL_FIELDS_AUTO -1
147 #define SHOW_OPTIONAL_FIELDS_NEVER 0
148 #define SHOW_OPTIONAL_FIELDS_ALWAYS 1
170 #define SECTION_MAX_NB_CHILDREN 11
246 #define SECTION_FLAG_IS_WRAPPER 1
247 #define SECTION_FLAG_IS_ARRAY 2
248 #define SECTION_FLAG_HAS_VARIABLE_FIELDS 4
250 #define SECTION_FLAG_HAS_TYPE 8
257 const char *(* get_type)(
const void *
data);
366 static const struct {
372 { 1.0, 1.0,
"",
"" },
373 { 1.024e3, 1e3,
"Ki",
"K" },
374 { 1.048576e6, 1e6,
"Mi",
"M" },
375 { 1.073741824e9, 1e9,
"Gi",
"G" },
376 { 1.099511627776e12, 1e12,
"Ti",
"T" },
377 { 1.125899906842624e15, 1e15,
"Pi",
"P" },
412 static int print_prefix = 1;
413 void *new_log_buffer;
424 if (new_log_buffer) {
437 for (
i=strlen(msg) - 1;
i>=0 && msg[
i] ==
'\n';
i--) {
443 if (parent && *parent) {
446 (*parent)->get_category ? (*parent)->get_category(parent) :(*parent)->category;
471 vald = vali = uv.
val.
i;
478 mins = (int)secs / 60;
479 secs = secs - mins * 60;
482 snprintf(buf, buf_size,
"%d:%02d:%09.6f", hours, mins, secs);
484 const char *prefix_string =
"";
504 snprintf(buf, buf_size,
"%f", vald);
506 snprintf(buf, buf_size,
"%"PRId64, vali);
518 #define WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS 1
519 #define WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER 2
544 #define SECTION_MAX_NB_LEVELS 12
586 #define OFFSET(x) offsetof(WriterContext, x)
589 {
"string_validation",
"set string validation mode",
591 {
"sv",
"set string validation mode",
596 {
"string_validation_replacement",
"set string validation replacement string",
OFFSET(string_validation_replacement),
AV_OPT_TYPE_STRING, {.str=
""}},
597 {
"svr",
"set string validation replacement string",
OFFSET(string_validation_replacement),
AV_OPT_TYPE_STRING, {.str=
"\xEF\xBF\xBD"}},
604 if (!prev &&
ctx->writer &&
ctx->writer->priv_class &&
ctx->priv)
625 if ((*wctx)->writer->uninit)
626 (*wctx)->writer->uninit(*wctx);
629 if ((*wctx)->writer->priv_class)
641 static void bprint_bytes(AVBPrint *bp,
const uint8_t *ubuf,
size_t ubuf_size)
645 for (
i = 0;
i < ubuf_size;
i++)
703 (*wctx)->writer = writer;
706 (*wctx)->nb_sections = nb_sections;
711 void *priv_ctx = (*wctx)->priv;
722 av_log(*wctx,
AV_LOG_ERROR,
"Failed to parse option string '%s' provided to writer context\n", args);
729 av_log(*wctx,
AV_LOG_ERROR,
"Failed to set option '%s' with value '%s' provided to writer context\n",
741 const uint8_t *p = (*wctx)->string_validation_replacement;
742 const uint8_t *endp = p + strlen(p);
744 const uint8_t *p0 = p;
752 "Invalid UTF8 sequence %s found in string validation replace '%s'\n",
753 bp.str, (*wctx)->string_validation_replacement);
777 if ((*wctx)->writer->init)
778 ret = (*wctx)->writer->init(*wctx);
793 int parent_section_id;
796 parent_section_id = wctx->
level ?
817 int parent_section_id = wctx->
level ?
844 const uint8_t *p, *endp;
846 int invalid_chars_nb = 0,
ret = 0;
854 const uint8_t *p0 = p;
861 "Invalid UTF-8 sequence %s found in string '%s'\n", bp.str,
src);
871 "Invalid UTF-8 sequence found in string '%s'\n",
src);
888 "%d invalid UTF-8 sequence(s) found in string '%s', replaced with '%s'\n",
897 #define PRINT_STRING_OPT 1
898 #define PRINT_STRING_VALIDATE 2
916 if (
ret < 0)
goto end;
918 if (
ret < 0)
goto end;
923 "Invalid key=value string combination %s=%s in section %s\n",
952 if ((!is_duration && ts ==
AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
955 double d = ts *
av_q2d(*time_base);
966 if ((!is_duration && ts ==
AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
984 for (
i = 0;
i < l;
i++) {
990 for (
i = 0;
i < l;
i++)
1011 p = buf + strlen(buf);
1018 int columns,
int bytes,
int offset_add)
1028 for (
i = 0;
i < l;
i++) {
1042 #define writer_w8(wctx_, b_) (wctx_)->writer_w8(wctx_, b_)
1043 #define writer_put_str(wctx_, str_) (wctx_)->writer_put_str(wctx_, str_)
1044 #define writer_printf(wctx_, fmt_, ...) (wctx_)->writer_printf(wctx_, fmt_, __VA_ARGS__)
1046 #define MAX_REGISTERED_WRITERS_NB 64
1052 static int next_registered_writer_idx = 0;
1075 #define DEFINE_WRITER_CLASS(name) \
1076 static const char *name##_get_name(void *ctx) \
1080 static const AVClass name##_class = { \
1081 .class_name = #name, \
1082 .item_name = name##_get_name, \
1083 .option = name##_options \
1096 #define OFFSET(x) offsetof(DefaultContext, x)
1099 {
"noprint_wrappers",
"do not print headers and footers",
OFFSET(noprint_wrappers),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1100 {
"nw",
"do not print headers and footers",
OFFSET(noprint_wrappers),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1112 for (
i = 0;
src[
i] &&
i < dst_size-1;
i++)
1127 if (parent_section &&
1182 .priv_class = &default_class,
1194 for (p =
src; *p; p++) {
1215 char meta_chars[] = { sep,
'"',
'\n',
'\r',
'\0' };
1216 int needs_quoting = !!
src[strcspn(
src, meta_chars)];
1243 const char * (*escape_str)(AVBPrint *
dst,
const char *
src,
const char sep,
void *log_ctx);
1250 #define OFFSET(x) offsetof(CompactContext, x)
1271 av_log(wctx,
AV_LOG_ERROR,
"Item separator '%s' specified, but must contain a single character\n",
1298 if (parent_section &&
1321 (*p >=
'0' && *p <=
'9') ||
1322 (*p >=
'a' && *p <=
'z') ||
1323 (*p >=
'A' && *p <=
'Z') ?
av_tolower(*p) :
'_';
1356 if (!compact->
nokey)
1368 if (!compact->
nokey)
1382 .priv_class = &compact_class,
1388 #define OFFSET(x) offsetof(CompactContext, x)
1413 .priv_class = &csv_class,
1426 #define OFFSET(x) offsetof(FlatContext, x)
1431 {
"hierarchical",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1432 {
"h",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1442 if (strlen(
flat->sep_str) != 1) {
1443 av_log(wctx,
AV_LOG_ERROR,
"Item separator '%s' specified, but must contain a single character\n",
1456 for (p =
src; *p; p++) {
1457 if (!((*p >=
'0' && *p <=
'9') ||
1458 (*p >=
'a' && *p <=
'z') ||
1459 (*p >=
'A' && *p <=
'Z')))
1471 for (p =
src; *p; p++) {
1495 if (!parent_section)
1499 if (
flat->hierarchical ||
1537 .priv_class = &flat_class,
1548 #define OFFSET(x) offsetof(INIContext, x)
1551 {
"hierarchical",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1552 {
"h",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1563 while (
c =
src[
i++]) {
1575 if ((
unsigned char)
c < 32)
1594 if (!parent_section) {
1641 .priv_class = &ini_class,
1654 #define OFFSET(x) offsetof(JSONContext, x)
1676 static const char json_escape[] = {
'"',
'\\',
'\b',
'\f',
'\n',
'\r',
'\t', 0};
1677 static const char json_subst[] = {
'"',
'\\',
'b',
'f',
'n',
'r',
't', 0};
1680 for (p =
src; *p; p++) {
1681 char *
s = strchr(json_escape, *p);
1685 }
else if ((
unsigned char)*p < 32) {
1694 #define JSON_INDENT() writer_printf(wctx, "%*c", json->indent_level * 4, ' ')
1740 if (wctx->
level == 0) {
1758 const char *
key,
const char *
value)
1808 .priv_class = &json_class,
1822 #define OFFSET(x) offsetof(XMLContext, x)
1825 {
"fully_qualified",
"specify if the output should be fully qualified",
OFFSET(fully_qualified),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1826 {
"q",
"specify if the output should be fully qualified",
OFFSET(fully_qualified),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1827 {
"xsd_strict",
"ensure that the output is XSD compliant",
OFFSET(xsd_strict),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1840 #define CHECK_COMPLIANCE(opt, opt_name) \
1842 av_log(wctx, AV_LOG_ERROR, \
1843 "XSD-compliant output selected but option '%s' was selected, XML output may be non-compliant.\n" \
1844 "You need to disable such option with '-no%s'\n", opt_name, opt_name); \
1845 return AVERROR(EINVAL); \
1855 #define XML_INDENT() writer_printf(wctx, "%*c", xml->indent_level * 4, ' ')
1864 if (wctx->
level == 0) {
1865 const char *qual =
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
1866 "xmlns:ffprobe=\"http://www.ffmpeg.org/schema/ffprobe\" "
1867 "xsi:schemaLocation=\"http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd\"";
1869 writer_put_str(wctx,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1908 if (wctx->
level == 0) {
1921 const char *str,
int64_t num,
const int is_int)
1980 .priv_class = &xml_class,
2000 #define print_fmt(k, f, ...) do { \
2001 av_bprint_clear(&pbuf); \
2002 av_bprintf(&pbuf, f, __VA_ARGS__); \
2003 writer_print_string(w, k, pbuf.str, 0); \
2006 #define print_list_fmt(k, f, n, m, ...) do { \
2007 av_bprint_clear(&pbuf); \
2008 for (int idx = 0; idx < n; idx++) { \
2009 for (int idx2 = 0; idx2 < m; idx2++) { \
2010 if (idx > 0 || idx2 > 0) \
2011 av_bprint_chars(&pbuf, ' ', 1); \
2012 av_bprintf(&pbuf, f, __VA_ARGS__); \
2015 writer_print_string(w, k, pbuf.str, 0); \
2018 #define print_int(k, v) writer_print_integer(w, k, v)
2019 #define print_q(k, v, s) writer_print_rational(w, k, v, s)
2020 #define print_str(k, v) writer_print_string(w, k, v, 0)
2021 #define print_str_opt(k, v) writer_print_string(w, k, v, PRINT_STRING_OPT)
2022 #define print_str_validate(k, v) writer_print_string(w, k, v, PRINT_STRING_VALIDATE)
2023 #define print_time(k, v, tb) writer_print_time(w, k, v, tb, 0)
2024 #define print_ts(k, v) writer_print_ts(w, k, v, 0)
2025 #define print_duration_time(k, v, tb) writer_print_time(w, k, v, tb, 1)
2026 #define print_duration_ts(k, v) writer_print_ts(w, k, v, 1)
2027 #define print_val(k, v, u) do { \
2028 struct unit_value uv; \
2031 writer_print_string(w, k, value_string(val_str, sizeof(val_str), uv), 0); \
2034 #define print_section_header(s) writer_print_section_header(w, NULL, s)
2035 #define print_section_header_data(s, d) writer_print_section_header(w, d, s)
2036 #define print_section_footer(s) writer_print_section_footer(w, s)
2038 #define REALLOCZ_ARRAY_STREAM(ptr, cur_n, new_n) \
2040 ret = av_reallocp_array(&(ptr), (new_n), sizeof(*(ptr))); \
2043 memset( (ptr) + (cur_n), 0, ((new_n) - (cur_n)) * sizeof(*(ptr)) ); \
2082 print_int(
"chroma_resampling_explicit_filter_flag",
2091 print_int(
"spatial_resampling_filter_flag",
2093 print_int(
"el_spatial_resampling_filter_flag",
2106 print_str(
"nlq_method_idc_name",
"none");
2109 print_str(
"nlq_method_idc_name",
"linear_dz");
2112 print_str(
"nlq_method_idc_name",
"unknown");
2121 for (
int c = 0;
c < 3;
c++) {
2149 print_str(
"mapping_idc_name",
"polynomial");
2164 print_str(
"mapping_idc_name",
"unknown");
2200 color->ycc_to_rgb_matrix[idx].num,
2201 color->ycc_to_rgb_matrix[idx].den);
2204 color->ycc_to_rgb_offset[idx].num,
2205 color->ycc_to_rgb_offset[idx].den);
2208 color->rgb_to_lms_matrix[idx].num,
2209 color->rgb_to_lms_matrix[idx].den);
2217 print_int(
"signal_full_range_flag",
color->signal_full_range_flag);
2234 print_q(
"window_upper_left_corner_x",
2236 print_q(
"window_upper_left_corner_y",
2238 print_q(
"window_lower_right_corner_x",
2240 print_q(
"window_lower_right_corner_y",
2242 print_q(
"window_upper_left_corner_x",
2244 print_q(
"window_upper_left_corner_y",
2252 print_int(
"semimajor_axis_internal_ellipse",
2254 print_int(
"semimajor_axis_external_ellipse",
2256 print_int(
"semiminor_axis_external_ellipse",
2261 print_q(
"targeted_system_display_maximum_luminance",
2264 print_int(
"num_rows_targeted_system_display_actual_peak_luminance",
2266 print_int(
"num_cols_targeted_system_display_actual_peak_luminance",
2270 print_q(
"targeted_system_display_actual_peak_luminance",
2277 for (
int i = 0;
i < 3;
i++) {
2282 print_int(
"num_distribution_maxrgb_percentiles",
2285 print_int(
"distribution_maxrgb_percentage",
2287 print_q(
"distribution_maxrgb_percentile",
2290 print_q(
"fraction_bright_pixels",
2294 print_int(
"num_rows_mastering_display_actual_peak_luminance",
2296 print_int(
"num_cols_mastering_display_actual_peak_luminance",
2300 print_q(
"mastering_display_actual_peak_luminance",
2314 print_q(
"bezier_curve_anchors",
2319 print_q(
"color_saturation_weight",
2350 print_q(
"targeted_system_display_maximum_luminance",
2363 print_int(
"base_param_Delta_enable_mode",
2410 const char *
const film_grain_type_names[] = {
2434 print_str(
"color_trc", color_trc ? color_trc :
"unknown");
2435 print_str(
"color_space", color_space ? color_space :
"unknown");
2437 switch (fgp->
type) {
2443 const int num_ar_coeffs_uv = num_ar_coeffs_y + !!aom->
num_y_points;
2466 for (
int uv = 0; uv < 2; uv++) {
2496 for (
int c = 0;
c < 3;
c++) {
2542 if (
isnan(rotation))
2609 const char *
comp =
"unknown";
2800 const uint8_t *side_metadata;
2854 for (
int i = 0;
i <
frame->nb_side_data;
i++) {
2863 if (
isnan(rotation))
2874 uint32_t *tc = (uint32_t*)sd->
data;
2875 int m =
FFMIN(tc[0],3);
2877 for (
int j = 1; j <= m ; j++) {
2955 print_ts (
"best_effort_timestamp",
frame->best_effort_timestamp);
2979 print_q(
"sample_aspect_ratio", sar,
':');
3013 if (
frame->nb_side_data)
3031 int ret = 0, got_frame = 0;
3081 for (
int i = 0;
i <
frame->nb_side_data;
i++) {
3092 return got_frame || *packet_new;
3097 av_log(log_ctx, log_level,
"id:%d", interval->
id);
3103 av_log(log_ctx, log_level,
" start:N/A");
3109 av_log(log_ctx, log_level,
"#%"PRId64, interval->
end);
3113 av_log(log_ctx, log_level,
" end:N/A");
3116 av_log(log_ctx, log_level,
"\n");
3125 int ret = 0,
i = 0, frame_count = 0;
3126 int64_t start = -INT64_MAX, end = interval->
end;
3137 "Could not seek to relative position since current "
3138 "timestamp is not defined\n");
3142 target = *cur_ts + interval->
start;
3144 target = interval->
start;
3188 end = start + interval->
end;
3193 if (frame_count >= interval->
end)
3195 }
else if (has_end && *cur_ts !=
AV_NOPTS_VALUE && *cur_ts >= end) {
3267 for (
int i = 0;
i <
sizeof(disposition) * CHAR_BIT;
i++) {
3270 if (disposition_str)
3271 print_int(disposition_str, !!(disposition & (1
U <<
i)));
3276 #define IN_PROGRAM 1
3277 #define IN_STREAM_GROUP 2
3294 const SectionID section_disposition[] = {
3334 char profile_num[12];
3365 print_q(
"sample_aspect_ratio", sar,
':');
3370 print_q(
"display_aspect_ratio", dar,
':');
3387 print_str(
"field_order",
"progressive");
3536 for (
i = 0;
i <
program->nb_stream_indexes;
i++) {
3594 SectionID subsection_id, parameter_section_id;
3611 switch(param->
type) {
3615 print_int(
"subblock_duration",
mix->subblock_duration);
3617 print_q(
"start_point_value",
mix->start_point_value,
'/');
3618 print_q(
"end_point_value",
mix->end_point_value,
'/');
3619 print_q(
"control_point_value",
mix->control_point_value,
'/');
3620 print_q(
"control_point_relative_time",
mix->control_point_relative_time,
'/');
3713 print_q(
"integrated_loudness",
layout->integrated_loudness,
'/');
3716 print_q(
"dialogue_anchored_loudness",
layout->dialogue_anchored_loudness,
'/');
3717 print_q(
"album_anchored_loudness",
layout->album_anchored_loudness,
'/');