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)
145 #define SHOW_OPTIONAL_FIELDS_AUTO -1
146 #define SHOW_OPTIONAL_FIELDS_NEVER 0
147 #define SHOW_OPTIONAL_FIELDS_ALWAYS 1
169 #define SECTION_MAX_NB_CHILDREN 11
245 #define SECTION_FLAG_IS_WRAPPER 1
246 #define SECTION_FLAG_IS_ARRAY 2
247 #define SECTION_FLAG_HAS_VARIABLE_FIELDS 4
249 #define SECTION_FLAG_HAS_TYPE 8
256 const char *(* get_type)(
const void *
data);
365 static const struct {
371 { 1.0, 1.0,
"",
"" },
372 { 1.024e3, 1e3,
"Ki",
"K" },
373 { 1.048576e6, 1e6,
"Mi",
"M" },
374 { 1.073741824e9, 1e9,
"Gi",
"G" },
375 { 1.099511627776e12, 1e12,
"Ti",
"T" },
376 { 1.125899906842624e15, 1e15,
"Pi",
"P" },
409 static int print_prefix = 1;
410 void *new_log_buffer;
421 if (new_log_buffer) {
434 for (
i=strlen(msg) - 1;
i>=0 && msg[
i] ==
'\n';
i--) {
440 if (parent && *parent) {
443 (*parent)->get_category ? (*parent)->get_category(parent) :(*parent)->category;
468 vald = vali = uv.
val.
i;
475 mins = (int)secs / 60;
476 secs = secs - mins * 60;
479 snprintf(buf, buf_size,
"%d:%02d:%09.6f", hours, mins, secs);
481 const char *prefix_string =
"";
501 snprintf(buf, buf_size,
"%f", vald);
503 snprintf(buf, buf_size,
"%"PRId64, vali);
515 #define WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS 1
516 #define WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER 2
541 #define SECTION_MAX_NB_LEVELS 12
583 #define OFFSET(x) offsetof(WriterContext, x)
586 {
"string_validation",
"set string validation mode",
588 {
"sv",
"set string validation mode",
593 {
"string_validation_replacement",
"set string validation replacement string",
OFFSET(string_validation_replacement),
AV_OPT_TYPE_STRING, {.str=
""}},
594 {
"svr",
"set string validation replacement string",
OFFSET(string_validation_replacement),
AV_OPT_TYPE_STRING, {.str=
"\xEF\xBF\xBD"}},
601 if (!prev &&
ctx->writer &&
ctx->writer->priv_class &&
ctx->priv)
622 if ((*wctx)->writer->uninit)
623 (*wctx)->writer->uninit(*wctx);
626 if ((*wctx)->writer->priv_class)
638 static void bprint_bytes(AVBPrint *bp,
const uint8_t *ubuf,
size_t ubuf_size)
642 for (
i = 0;
i < ubuf_size;
i++)
700 (*wctx)->writer = writer;
703 (*wctx)->nb_sections = nb_sections;
708 void *priv_ctx = (*wctx)->priv;
719 av_log(*wctx,
AV_LOG_ERROR,
"Failed to parse option string '%s' provided to writer context\n", args);
726 av_log(*wctx,
AV_LOG_ERROR,
"Failed to set option '%s' with value '%s' provided to writer context\n",
738 const uint8_t *p = (*wctx)->string_validation_replacement;
739 const uint8_t *endp = p + strlen(p);
741 const uint8_t *p0 = p;
749 "Invalid UTF8 sequence %s found in string validation replace '%s'\n",
750 bp.str, (*wctx)->string_validation_replacement);
774 if ((*wctx)->writer->init)
775 ret = (*wctx)->writer->init(*wctx);
790 int parent_section_id;
793 parent_section_id = wctx->
level ?
814 int parent_section_id = wctx->
level ?
841 const uint8_t *p, *endp;
843 int invalid_chars_nb = 0,
ret = 0;
851 const uint8_t *p0 = p;
858 "Invalid UTF-8 sequence %s found in string '%s'\n", bp.str,
src);
868 "Invalid UTF-8 sequence found in string '%s'\n",
src);
885 "%d invalid UTF-8 sequence(s) found in string '%s', replaced with '%s'\n",
894 #define PRINT_STRING_OPT 1
895 #define PRINT_STRING_VALIDATE 2
913 if (
ret < 0)
goto end;
915 if (
ret < 0)
goto end;
920 "Invalid key=value string combination %s=%s in section %s\n",
949 if ((!is_duration && ts ==
AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
952 double d = ts *
av_q2d(*time_base);
963 if ((!is_duration && ts ==
AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
981 for (
i = 0;
i < l;
i++) {
987 for (
i = 0;
i < l;
i++)
1008 p = buf + strlen(buf);
1015 int columns,
int bytes,
int offset_add)
1025 for (
i = 0;
i < l;
i++) {
1039 #define writer_w8(wctx_, b_) (wctx_)->writer_w8(wctx_, b_)
1040 #define writer_put_str(wctx_, str_) (wctx_)->writer_put_str(wctx_, str_)
1041 #define writer_printf(wctx_, fmt_, ...) (wctx_)->writer_printf(wctx_, fmt_, __VA_ARGS__)
1043 #define MAX_REGISTERED_WRITERS_NB 64
1049 static int next_registered_writer_idx = 0;
1072 #define DEFINE_WRITER_CLASS(name) \
1073 static const char *name##_get_name(void *ctx) \
1077 static const AVClass name##_class = { \
1078 .class_name = #name, \
1079 .item_name = name##_get_name, \
1080 .option = name##_options \
1093 #define OFFSET(x) offsetof(DefaultContext, x)
1096 {
"noprint_wrappers",
"do not print headers and footers",
OFFSET(noprint_wrappers),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1097 {
"nw",
"do not print headers and footers",
OFFSET(noprint_wrappers),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1109 for (
i = 0;
src[
i] &&
i < dst_size-1;
i++)
1124 if (parent_section &&
1179 .priv_class = &default_class,
1191 for (p =
src; *p; p++) {
1212 char meta_chars[] = { sep,
'"',
'\n',
'\r',
'\0' };
1213 int needs_quoting = !!
src[strcspn(
src, meta_chars)];
1240 const char * (*escape_str)(AVBPrint *
dst,
const char *
src,
const char sep,
void *log_ctx);
1247 #define OFFSET(x) offsetof(CompactContext, x)
1268 av_log(wctx,
AV_LOG_ERROR,
"Item separator '%s' specified, but must contain a single character\n",
1295 if (parent_section &&
1318 (*p >=
'0' && *p <=
'9') ||
1319 (*p >=
'a' && *p <=
'z') ||
1320 (*p >=
'A' && *p <=
'Z') ?
av_tolower(*p) :
'_';
1353 if (!compact->
nokey)
1365 if (!compact->
nokey)
1379 .priv_class = &compact_class,
1385 #define OFFSET(x) offsetof(CompactContext, x)
1410 .priv_class = &csv_class,
1423 #define OFFSET(x) offsetof(FlatContext, x)
1428 {
"hierarchical",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1429 {
"h",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1439 if (strlen(
flat->sep_str) != 1) {
1440 av_log(wctx,
AV_LOG_ERROR,
"Item separator '%s' specified, but must contain a single character\n",
1453 for (p =
src; *p; p++) {
1454 if (!((*p >=
'0' && *p <=
'9') ||
1455 (*p >=
'a' && *p <=
'z') ||
1456 (*p >=
'A' && *p <=
'Z')))
1468 for (p =
src; *p; p++) {
1492 if (!parent_section)
1496 if (
flat->hierarchical ||
1534 .priv_class = &flat_class,
1545 #define OFFSET(x) offsetof(INIContext, x)
1548 {
"hierarchical",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1549 {
"h",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1560 while (
c =
src[
i++]) {
1572 if ((
unsigned char)
c < 32)
1591 if (!parent_section) {
1638 .priv_class = &ini_class,
1651 #define OFFSET(x) offsetof(JSONContext, x)
1673 static const char json_escape[] = {
'"',
'\\',
'\b',
'\f',
'\n',
'\r',
'\t', 0};
1674 static const char json_subst[] = {
'"',
'\\',
'b',
'f',
'n',
'r',
't', 0};
1677 for (p =
src; *p; p++) {
1678 char *
s = strchr(json_escape, *p);
1682 }
else if ((
unsigned char)*p < 32) {
1691 #define JSON_INDENT() writer_printf(wctx, "%*c", json->indent_level * 4, ' ')
1737 if (wctx->
level == 0) {
1755 const char *
key,
const char *
value)
1805 .priv_class = &json_class,
1819 #define OFFSET(x) offsetof(XMLContext, x)
1822 {
"fully_qualified",
"specify if the output should be fully qualified",
OFFSET(fully_qualified),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1823 {
"q",
"specify if the output should be fully qualified",
OFFSET(fully_qualified),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1824 {
"xsd_strict",
"ensure that the output is XSD compliant",
OFFSET(xsd_strict),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1837 #define CHECK_COMPLIANCE(opt, opt_name) \
1839 av_log(wctx, AV_LOG_ERROR, \
1840 "XSD-compliant output selected but option '%s' was selected, XML output may be non-compliant.\n" \
1841 "You need to disable such option with '-no%s'\n", opt_name, opt_name); \
1842 return AVERROR(EINVAL); \
1852 #define XML_INDENT() writer_printf(wctx, "%*c", xml->indent_level * 4, ' ')
1861 if (wctx->
level == 0) {
1862 const char *qual =
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
1863 "xmlns:ffprobe=\"http://www.ffmpeg.org/schema/ffprobe\" "
1864 "xsi:schemaLocation=\"http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd\"";
1866 writer_put_str(wctx,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1905 if (wctx->
level == 0) {
1918 const char *str,
int64_t num,
const int is_int)
1977 .priv_class = &xml_class,
1997 #define print_fmt(k, f, ...) do { \
1998 av_bprint_clear(&pbuf); \
1999 av_bprintf(&pbuf, f, __VA_ARGS__); \
2000 writer_print_string(w, k, pbuf.str, 0); \
2003 #define print_list_fmt(k, f, n, m, ...) do { \
2004 av_bprint_clear(&pbuf); \
2005 for (int idx = 0; idx < n; idx++) { \
2006 for (int idx2 = 0; idx2 < m; idx2++) { \
2007 if (idx > 0 || idx2 > 0) \
2008 av_bprint_chars(&pbuf, ' ', 1); \
2009 av_bprintf(&pbuf, f, __VA_ARGS__); \
2012 writer_print_string(w, k, pbuf.str, 0); \
2015 #define print_int(k, v) writer_print_integer(w, k, v)
2016 #define print_q(k, v, s) writer_print_rational(w, k, v, s)
2017 #define print_str(k, v) writer_print_string(w, k, v, 0)
2018 #define print_str_opt(k, v) writer_print_string(w, k, v, PRINT_STRING_OPT)
2019 #define print_str_validate(k, v) writer_print_string(w, k, v, PRINT_STRING_VALIDATE)
2020 #define print_time(k, v, tb) writer_print_time(w, k, v, tb, 0)
2021 #define print_ts(k, v) writer_print_ts(w, k, v, 0)
2022 #define print_duration_time(k, v, tb) writer_print_time(w, k, v, tb, 1)
2023 #define print_duration_ts(k, v) writer_print_ts(w, k, v, 1)
2024 #define print_val(k, v, u) do { \
2025 struct unit_value uv; \
2028 writer_print_string(w, k, value_string(val_str, sizeof(val_str), uv), 0); \
2031 #define print_section_header(s) writer_print_section_header(w, NULL, s)
2032 #define print_section_header_data(s, d) writer_print_section_header(w, d, s)
2033 #define print_section_footer(s) writer_print_section_footer(w, s)
2035 #define REALLOCZ_ARRAY_STREAM(ptr, cur_n, new_n) \
2037 ret = av_reallocp_array(&(ptr), (new_n), sizeof(*(ptr))); \
2040 memset( (ptr) + (cur_n), 0, ((new_n) - (cur_n)) * sizeof(*(ptr)) ); \
2079 print_int(
"chroma_resampling_explicit_filter_flag",
2088 print_int(
"spatial_resampling_filter_flag",
2090 print_int(
"el_spatial_resampling_filter_flag",
2103 print_str(
"nlq_method_idc_name",
"none");
2106 print_str(
"nlq_method_idc_name",
"linear_dz");
2109 print_str(
"nlq_method_idc_name",
"unknown");
2118 for (
int c = 0;
c < 3;
c++) {
2146 print_str(
"mapping_idc_name",
"polynomial");
2161 print_str(
"mapping_idc_name",
"unknown");
2197 color->ycc_to_rgb_matrix[idx].num,
2198 color->ycc_to_rgb_matrix[idx].den);
2201 color->ycc_to_rgb_offset[idx].num,
2202 color->ycc_to_rgb_offset[idx].den);
2205 color->rgb_to_lms_matrix[idx].num,
2206 color->rgb_to_lms_matrix[idx].den);
2214 print_int(
"signal_full_range_flag",
color->signal_full_range_flag);
2231 print_q(
"window_upper_left_corner_x",
2233 print_q(
"window_upper_left_corner_y",
2235 print_q(
"window_lower_right_corner_x",
2237 print_q(
"window_lower_right_corner_y",
2239 print_q(
"window_upper_left_corner_x",
2241 print_q(
"window_upper_left_corner_y",
2249 print_int(
"semimajor_axis_internal_ellipse",
2251 print_int(
"semimajor_axis_external_ellipse",
2253 print_int(
"semiminor_axis_external_ellipse",
2258 print_q(
"targeted_system_display_maximum_luminance",
2261 print_int(
"num_rows_targeted_system_display_actual_peak_luminance",
2263 print_int(
"num_cols_targeted_system_display_actual_peak_luminance",
2267 print_q(
"targeted_system_display_actual_peak_luminance",
2274 for (
int i = 0;
i < 3;
i++) {
2279 print_int(
"num_distribution_maxrgb_percentiles",
2282 print_int(
"distribution_maxrgb_percentage",
2284 print_q(
"distribution_maxrgb_percentile",
2287 print_q(
"fraction_bright_pixels",
2291 print_int(
"num_rows_mastering_display_actual_peak_luminance",
2293 print_int(
"num_cols_mastering_display_actual_peak_luminance",
2297 print_q(
"mastering_display_actual_peak_luminance",
2311 print_q(
"bezier_curve_anchors",
2316 print_q(
"color_saturation_weight",
2347 print_q(
"targeted_system_display_maximum_luminance",
2360 print_int(
"base_param_Delta_enable_mode",
2407 const char *
const film_grain_type_names[] = {
2431 print_str(
"color_trc", color_trc ? color_trc :
"unknown");
2432 print_str(
"color_space", color_space ? color_space :
"unknown");
2434 switch (fgp->
type) {
2440 const int num_ar_coeffs_uv = num_ar_coeffs_y + !!aom->
num_y_points;
2463 for (
int uv = 0; uv < 2; uv++) {
2493 for (
int c = 0;
c < 3;
c++) {
2539 if (
isnan(rotation))
2606 const char *
comp =
"unknown";
2797 const uint8_t *side_metadata;
2851 for (
int i = 0;
i <
frame->nb_side_data;
i++) {
2860 if (
isnan(rotation))
2871 uint32_t *tc = (uint32_t*)sd->
data;
2872 int m =
FFMIN(tc[0],3);
2874 for (
int j = 1; j <= m ; j++) {
2952 print_ts (
"best_effort_timestamp",
frame->best_effort_timestamp);
2976 print_q(
"sample_aspect_ratio", sar,
':');
3009 if (
frame->nb_side_data)
3027 int ret = 0, got_frame = 0;
3078 return got_frame || *packet_new;
3083 av_log(log_ctx, log_level,
"id:%d", interval->
id);
3089 av_log(log_ctx, log_level,
" start:N/A");
3095 av_log(log_ctx, log_level,
"#%"PRId64, interval->
end);
3099 av_log(log_ctx, log_level,
" end:N/A");
3102 av_log(log_ctx, log_level,
"\n");
3111 int ret = 0,
i = 0, frame_count = 0;
3112 int64_t start = -INT64_MAX, end = interval->
end;
3123 "Could not seek to relative position since current "
3124 "timestamp is not defined\n");
3128 target = *cur_ts + interval->
start;
3130 target = interval->
start;
3172 end = start + interval->
end;
3177 if (frame_count >= interval->
end)
3179 }
else if (has_end && *cur_ts !=
AV_NOPTS_VALUE && *cur_ts >= end) {
3251 for (
int i = 0;
i <
sizeof(disposition) * CHAR_BIT;
i++) {
3254 if (disposition_str)
3255 print_int(disposition_str, !!(disposition & (1
U <<
i)));
3260 #define IN_PROGRAM 1
3261 #define IN_STREAM_GROUP 2
3278 const SectionID section_disposition[] = {
3318 char profile_num[12];
3346 print_q(
"sample_aspect_ratio", sar,
':');
3351 print_q(
"display_aspect_ratio", dar,
':');
3368 print_str(
"field_order",
"progressive");
3517 for (
i = 0;
i <
program->nb_stream_indexes;
i++) {
3575 SectionID subsection_id, parameter_section_id;
3592 switch(param->
type) {
3596 print_int(
"subblock_duration",
mix->subblock_duration);
3598 print_q(
"start_point_value",
mix->start_point_value,
'/');
3599 print_q(
"end_point_value",
mix->end_point_value,
'/');
3600 print_q(
"control_point_value",
mix->control_point_value,
'/');
3601 print_q(
"control_point_relative_time",
mix->control_point_relative_time,
'/');
3694 print_q(
"integrated_loudness",
layout->integrated_loudness,
'/');
3697 print_q(
"dialogue_anchored_loudness",
layout->dialogue_anchored_loudness,
'/');
3698 print_q(
"album_anchored_loudness",
layout->album_anchored_loudness,
'/');