FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/fftools/ffprobe.c
Date: 2024-09-07 18:49:03
Exec Total Coverage
Lines: 1910 2573 74.2%
Functions: 112 150 74.7%
Branches: 1029 1605 64.1%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2007-2010 Stefano Sabatini
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /**
22 * @file
23 * simple media prober based on the FFmpeg libraries
24 */
25
26 #include "config.h"
27 #include "libavutil/ffversion.h"
28
29 #include <string.h>
30 #include <math.h>
31
32 #include "libavformat/avformat.h"
33 #include "libavformat/version.h"
34 #include "libavcodec/avcodec.h"
35 #include "libavcodec/version.h"
36 #include "libavutil/ambient_viewing_environment.h"
37 #include "libavutil/avassert.h"
38 #include "libavutil/avstring.h"
39 #include "libavutil/bprint.h"
40 #include "libavutil/channel_layout.h"
41 #include "libavutil/display.h"
42 #include "libavutil/film_grain_params.h"
43 #include "libavutil/hash.h"
44 #include "libavutil/hdr_dynamic_metadata.h"
45 #include "libavutil/iamf.h"
46 #include "libavutil/mastering_display_metadata.h"
47 #include "libavutil/hdr_dynamic_vivid_metadata.h"
48 #include "libavutil/dovi_meta.h"
49 #include "libavutil/mem.h"
50 #include "libavutil/opt.h"
51 #include "libavutil/pixdesc.h"
52 #include "libavutil/spherical.h"
53 #include "libavutil/stereo3d.h"
54 #include "libavutil/dict.h"
55 #include "libavutil/intreadwrite.h"
56 #include "libavutil/libm.h"
57 #include "libavutil/parseutils.h"
58 #include "libavutil/timecode.h"
59 #include "libavutil/timestamp.h"
60 #include "libavdevice/avdevice.h"
61 #include "libavdevice/version.h"
62 #include "libswscale/swscale.h"
63 #include "libswscale/version.h"
64 #include "libswresample/swresample.h"
65 #include "libswresample/version.h"
66 #include "libpostproc/postprocess.h"
67 #include "libpostproc/version.h"
68 #include "libavfilter/version.h"
69 #include "cmdutils.h"
70 #include "opt_common.h"
71
72 #include "libavutil/thread.h"
73
74 #if !HAVE_THREADS
75 # ifdef pthread_mutex_lock
76 # undef pthread_mutex_lock
77 # endif
78 # define pthread_mutex_lock(a) do{}while(0)
79 # ifdef pthread_mutex_unlock
80 # undef pthread_mutex_unlock
81 # endif
82 # define pthread_mutex_unlock(a) do{}while(0)
83 #endif
84
85 // attached as opaque_ref to packets/frames
86 typedef struct FrameData {
87 int64_t pkt_pos;
88 int pkt_size;
89 } FrameData;
90
91 typedef struct InputStream {
92 AVStream *st;
93
94 AVCodecContext *dec_ctx;
95 } InputStream;
96
97 typedef struct InputFile {
98 AVFormatContext *fmt_ctx;
99
100 InputStream *streams;
101 int nb_streams;
102 } InputFile;
103
104 const char program_name[] = "ffprobe";
105 const int program_birth_year = 2007;
106
107 static int do_bitexact = 0;
108 static int do_count_frames = 0;
109 static int do_count_packets = 0;
110 static int do_read_frames = 0;
111 static int do_read_packets = 0;
112 static int do_show_chapters = 0;
113 static int do_show_error = 0;
114 static int do_show_format = 0;
115 static int do_show_frames = 0;
116 static int do_show_packets = 0;
117 static int do_show_programs = 0;
118 static int do_show_stream_groups = 0;
119 static int do_show_stream_group_components = 0;
120 static int do_show_streams = 0;
121 static int do_show_stream_disposition = 0;
122 static int do_show_stream_group_disposition = 0;
123 static int do_show_data = 0;
124 static int do_show_program_version = 0;
125 static int do_show_library_versions = 0;
126 static int do_show_pixel_formats = 0;
127 static int do_show_pixel_format_flags = 0;
128 static int do_show_pixel_format_components = 0;
129 static int do_show_log = 0;
130
131 static int do_show_chapter_tags = 0;
132 static int do_show_format_tags = 0;
133 static int do_show_frame_tags = 0;
134 static int do_show_program_tags = 0;
135 static int do_show_stream_group_tags = 0;
136 static int do_show_stream_tags = 0;
137 static int do_show_packet_tags = 0;
138
139 static int show_value_unit = 0;
140 static int use_value_prefix = 0;
141 static int use_byte_value_binary_prefix = 0;
142 static int use_value_sexagesimal_format = 0;
143 static int show_private_data = 1;
144
145 #define SHOW_OPTIONAL_FIELDS_AUTO -1
146 #define SHOW_OPTIONAL_FIELDS_NEVER 0
147 #define SHOW_OPTIONAL_FIELDS_ALWAYS 1
148 static int show_optional_fields = SHOW_OPTIONAL_FIELDS_AUTO;
149
150 static char *output_format;
151 static char *stream_specifier;
152 static char *show_data_hash;
153
154 typedef struct ReadInterval {
155 int id; ///< identifier
156 int64_t start, end; ///< start, end in second/AV_TIME_BASE units
157 int has_start, has_end;
158 int start_is_offset, end_is_offset;
159 int duration_frames;
160 } ReadInterval;
161
162 static ReadInterval *read_intervals;
163 static int read_intervals_nb = 0;
164
165 static int find_stream_info = 1;
166
167 /* section structure definition */
168
169 #define SECTION_MAX_NB_CHILDREN 11
170
171 typedef enum {
172 SECTION_ID_NONE = -1,
173 SECTION_ID_CHAPTER,
174 SECTION_ID_CHAPTER_TAGS,
175 SECTION_ID_CHAPTERS,
176 SECTION_ID_ERROR,
177 SECTION_ID_FORMAT,
178 SECTION_ID_FORMAT_TAGS,
179 SECTION_ID_FRAME,
180 SECTION_ID_FRAMES,
181 SECTION_ID_FRAME_TAGS,
182 SECTION_ID_FRAME_SIDE_DATA_LIST,
183 SECTION_ID_FRAME_SIDE_DATA,
184 SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST,
185 SECTION_ID_FRAME_SIDE_DATA_TIMECODE,
186 SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST,
187 SECTION_ID_FRAME_SIDE_DATA_COMPONENT,
188 SECTION_ID_FRAME_SIDE_DATA_PIECE_LIST,
189 SECTION_ID_FRAME_SIDE_DATA_PIECE,
190 SECTION_ID_FRAME_LOG,
191 SECTION_ID_FRAME_LOGS,
192 SECTION_ID_LIBRARY_VERSION,
193 SECTION_ID_LIBRARY_VERSIONS,
194 SECTION_ID_PACKET,
195 SECTION_ID_PACKET_TAGS,
196 SECTION_ID_PACKETS,
197 SECTION_ID_PACKETS_AND_FRAMES,
198 SECTION_ID_PACKET_SIDE_DATA_LIST,
199 SECTION_ID_PACKET_SIDE_DATA,
200 SECTION_ID_PIXEL_FORMAT,
201 SECTION_ID_PIXEL_FORMAT_FLAGS,
202 SECTION_ID_PIXEL_FORMAT_COMPONENT,
203 SECTION_ID_PIXEL_FORMAT_COMPONENTS,
204 SECTION_ID_PIXEL_FORMATS,
205 SECTION_ID_PROGRAM_STREAM_DISPOSITION,
206 SECTION_ID_PROGRAM_STREAM_TAGS,
207 SECTION_ID_PROGRAM,
208 SECTION_ID_PROGRAM_STREAMS,
209 SECTION_ID_PROGRAM_STREAM,
210 SECTION_ID_PROGRAM_TAGS,
211 SECTION_ID_PROGRAM_VERSION,
212 SECTION_ID_PROGRAMS,
213 SECTION_ID_STREAM_GROUP_STREAM_DISPOSITION,
214 SECTION_ID_STREAM_GROUP_STREAM_TAGS,
215 SECTION_ID_STREAM_GROUP,
216 SECTION_ID_STREAM_GROUP_COMPONENTS,
217 SECTION_ID_STREAM_GROUP_COMPONENT,
218 SECTION_ID_STREAM_GROUP_SUBCOMPONENTS,
219 SECTION_ID_STREAM_GROUP_SUBCOMPONENT,
220 SECTION_ID_STREAM_GROUP_PIECES,
221 SECTION_ID_STREAM_GROUP_PIECE,
222 SECTION_ID_STREAM_GROUP_SUBPIECES,
223 SECTION_ID_STREAM_GROUP_SUBPIECE,
224 SECTION_ID_STREAM_GROUP_BLOCKS,
225 SECTION_ID_STREAM_GROUP_BLOCK,
226 SECTION_ID_STREAM_GROUP_STREAMS,
227 SECTION_ID_STREAM_GROUP_STREAM,
228 SECTION_ID_STREAM_GROUP_DISPOSITION,
229 SECTION_ID_STREAM_GROUP_TAGS,
230 SECTION_ID_STREAM_GROUPS,
231 SECTION_ID_ROOT,
232 SECTION_ID_STREAM,
233 SECTION_ID_STREAM_DISPOSITION,
234 SECTION_ID_STREAMS,
235 SECTION_ID_STREAM_TAGS,
236 SECTION_ID_STREAM_SIDE_DATA_LIST,
237 SECTION_ID_STREAM_SIDE_DATA,
238 SECTION_ID_SUBTITLE,
239 } SectionID;
240
241 struct section {
242 int id; ///< unique id identifying a section
243 const char *name;
244
245 #define SECTION_FLAG_IS_WRAPPER 1 ///< the section only contains other sections, but has no data at its own level
246 #define SECTION_FLAG_IS_ARRAY 2 ///< the section contains an array of elements of the same type
247 #define SECTION_FLAG_HAS_VARIABLE_FIELDS 4 ///< the section may contain a variable number of fields with variable keys.
248 /// For these sections the element_name field is mandatory.
249 #define SECTION_FLAG_HAS_TYPE 8 ///< the section contains a type to distinguish multiple nested elements
250
251 int flags;
252 const SectionID children_ids[SECTION_MAX_NB_CHILDREN+1]; ///< list of children section IDS, terminated by -1
253 const char *element_name; ///< name of the contained element, if provided
254 const char *unique_name; ///< unique section name, in case the name is ambiguous
255 AVDictionary *entries_to_show;
256 const char *(* get_type)(const void *data); ///< function returning a type if defined, must be defined when SECTION_FLAG_HAS_TYPE is defined
257 int show_all_entries;
258 };
259
260 717 static const char *get_packet_side_data_type(const void *data)
261 {
262 717 const AVPacketSideData *sd = (const AVPacketSideData *)data;
263 717 return av_x_if_null(av_packet_side_data_name(sd->type), "unknown");
264 }
265
266 150 static const char *get_frame_side_data_type(const void *data)
267 {
268 150 const AVFrameSideData *sd = (const AVFrameSideData *)data;
269 150 return av_x_if_null(av_frame_side_data_name(sd->type), "unknown");
270 }
271
272 static const char *get_raw_string_type(const void *data)
273 {
274 return data;
275 }
276
277 static const char *get_stream_group_type(const void *data)
278 {
279 const AVStreamGroup *stg = (const AVStreamGroup *)data;
280 return av_x_if_null(avformat_stream_group_name(stg->type), "unknown");
281 }
282
283 static struct section sections[] = {
284 [SECTION_ID_CHAPTERS] = { SECTION_ID_CHAPTERS, "chapters", SECTION_FLAG_IS_ARRAY, { SECTION_ID_CHAPTER, -1 } },
285 [SECTION_ID_CHAPTER] = { SECTION_ID_CHAPTER, "chapter", 0, { SECTION_ID_CHAPTER_TAGS, -1 } },
286 [SECTION_ID_CHAPTER_TAGS] = { SECTION_ID_CHAPTER_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "chapter_tags" },
287 [SECTION_ID_ERROR] = { SECTION_ID_ERROR, "error", 0, { -1 } },
288 [SECTION_ID_FORMAT] = { SECTION_ID_FORMAT, "format", 0, { SECTION_ID_FORMAT_TAGS, -1 } },
289 [SECTION_ID_FORMAT_TAGS] = { SECTION_ID_FORMAT_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "format_tags" },
290 [SECTION_ID_FRAMES] = { SECTION_ID_FRAMES, "frames", SECTION_FLAG_IS_ARRAY, { SECTION_ID_FRAME, SECTION_ID_SUBTITLE, -1 } },
291 [SECTION_ID_FRAME] = { SECTION_ID_FRAME, "frame", 0, { SECTION_ID_FRAME_TAGS, SECTION_ID_FRAME_SIDE_DATA_LIST, SECTION_ID_FRAME_LOGS, -1 } },
292 [SECTION_ID_FRAME_TAGS] = { SECTION_ID_FRAME_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "frame_tags" },
293 [SECTION_ID_FRAME_SIDE_DATA_LIST] ={ SECTION_ID_FRAME_SIDE_DATA_LIST, "side_data_list", SECTION_FLAG_IS_ARRAY, { SECTION_ID_FRAME_SIDE_DATA, -1 }, .element_name = "side_data", .unique_name = "frame_side_data_list" },
294 [SECTION_ID_FRAME_SIDE_DATA] = { SECTION_ID_FRAME_SIDE_DATA, "side_data", SECTION_FLAG_HAS_VARIABLE_FIELDS|SECTION_FLAG_HAS_TYPE, { SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST, SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST, -1 }, .unique_name = "frame_side_data", .element_name = "side_datum", .get_type = get_frame_side_data_type },
295 [SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST] = { SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST, "timecodes", SECTION_FLAG_IS_ARRAY, { SECTION_ID_FRAME_SIDE_DATA_TIMECODE, -1 } },
296 [SECTION_ID_FRAME_SIDE_DATA_TIMECODE] = { SECTION_ID_FRAME_SIDE_DATA_TIMECODE, "timecode", 0, { -1 } },
297 [SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST] = { SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST, "components", SECTION_FLAG_IS_ARRAY, { SECTION_ID_FRAME_SIDE_DATA_COMPONENT, -1 }, .element_name = "component", .unique_name = "frame_side_data_components" },
298 [SECTION_ID_FRAME_SIDE_DATA_COMPONENT] = { SECTION_ID_FRAME_SIDE_DATA_COMPONENT, "component", SECTION_FLAG_HAS_VARIABLE_FIELDS|SECTION_FLAG_HAS_TYPE, { SECTION_ID_FRAME_SIDE_DATA_PIECE_LIST, -1 }, .unique_name = "frame_side_data_component", .element_name = "component_entry", .get_type = get_raw_string_type },
299 [SECTION_ID_FRAME_SIDE_DATA_PIECE_LIST] = { SECTION_ID_FRAME_SIDE_DATA_PIECE_LIST, "pieces", SECTION_FLAG_IS_ARRAY, { SECTION_ID_FRAME_SIDE_DATA_PIECE, -1 }, .element_name = "piece", .unique_name = "frame_side_data_pieces" },
300 [SECTION_ID_FRAME_SIDE_DATA_PIECE] = { SECTION_ID_FRAME_SIDE_DATA_PIECE, "piece", SECTION_FLAG_HAS_VARIABLE_FIELDS|SECTION_FLAG_HAS_TYPE, { -1 }, .element_name = "piece_entry", .unique_name = "frame_side_data_piece", .get_type = get_raw_string_type },
301 [SECTION_ID_FRAME_LOGS] = { SECTION_ID_FRAME_LOGS, "logs", SECTION_FLAG_IS_ARRAY, { SECTION_ID_FRAME_LOG, -1 } },
302 [SECTION_ID_FRAME_LOG] = { SECTION_ID_FRAME_LOG, "log", 0, { -1 }, },
303 [SECTION_ID_LIBRARY_VERSIONS] = { SECTION_ID_LIBRARY_VERSIONS, "library_versions", SECTION_FLAG_IS_ARRAY, { SECTION_ID_LIBRARY_VERSION, -1 } },
304 [SECTION_ID_LIBRARY_VERSION] = { SECTION_ID_LIBRARY_VERSION, "library_version", 0, { -1 } },
305 [SECTION_ID_PACKETS] = { SECTION_ID_PACKETS, "packets", SECTION_FLAG_IS_ARRAY, { SECTION_ID_PACKET, -1} },
306 [SECTION_ID_PACKETS_AND_FRAMES] = { SECTION_ID_PACKETS_AND_FRAMES, "packets_and_frames", SECTION_FLAG_IS_ARRAY, { SECTION_ID_PACKET, -1} },
307 [SECTION_ID_PACKET] = { SECTION_ID_PACKET, "packet", 0, { SECTION_ID_PACKET_TAGS, SECTION_ID_PACKET_SIDE_DATA_LIST, -1 } },
308 [SECTION_ID_PACKET_TAGS] = { SECTION_ID_PACKET_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "packet_tags" },
309 [SECTION_ID_PACKET_SIDE_DATA_LIST] ={ SECTION_ID_PACKET_SIDE_DATA_LIST, "side_data_list", SECTION_FLAG_IS_ARRAY, { SECTION_ID_PACKET_SIDE_DATA, -1 }, .element_name = "side_data", .unique_name = "packet_side_data_list" },
310 [SECTION_ID_PACKET_SIDE_DATA] = { SECTION_ID_PACKET_SIDE_DATA, "side_data", SECTION_FLAG_HAS_VARIABLE_FIELDS|SECTION_FLAG_HAS_TYPE, { -1 }, .unique_name = "packet_side_data", .element_name = "side_datum", .get_type = get_packet_side_data_type },
311 [SECTION_ID_PIXEL_FORMATS] = { SECTION_ID_PIXEL_FORMATS, "pixel_formats", SECTION_FLAG_IS_ARRAY, { SECTION_ID_PIXEL_FORMAT, -1 } },
312 [SECTION_ID_PIXEL_FORMAT] = { SECTION_ID_PIXEL_FORMAT, "pixel_format", 0, { SECTION_ID_PIXEL_FORMAT_FLAGS, SECTION_ID_PIXEL_FORMAT_COMPONENTS, -1 } },
313 [SECTION_ID_PIXEL_FORMAT_FLAGS] = { SECTION_ID_PIXEL_FORMAT_FLAGS, "flags", 0, { -1 }, .unique_name = "pixel_format_flags" },
314 [SECTION_ID_PIXEL_FORMAT_COMPONENTS] = { SECTION_ID_PIXEL_FORMAT_COMPONENTS, "components", SECTION_FLAG_IS_ARRAY, {SECTION_ID_PIXEL_FORMAT_COMPONENT, -1 }, .unique_name = "pixel_format_components" },
315 [SECTION_ID_PIXEL_FORMAT_COMPONENT] = { SECTION_ID_PIXEL_FORMAT_COMPONENT, "component", 0, { -1 } },
316 [SECTION_ID_PROGRAM_STREAM_DISPOSITION] = { SECTION_ID_PROGRAM_STREAM_DISPOSITION, "disposition", 0, { -1 }, .unique_name = "program_stream_disposition" },
317 [SECTION_ID_PROGRAM_STREAM_TAGS] = { SECTION_ID_PROGRAM_STREAM_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "program_stream_tags" },
318 [SECTION_ID_PROGRAM] = { SECTION_ID_PROGRAM, "program", 0, { SECTION_ID_PROGRAM_TAGS, SECTION_ID_PROGRAM_STREAMS, -1 } },
319 [SECTION_ID_PROGRAM_STREAMS] = { SECTION_ID_PROGRAM_STREAMS, "streams", SECTION_FLAG_IS_ARRAY, { SECTION_ID_PROGRAM_STREAM, -1 }, .unique_name = "program_streams" },
320 [SECTION_ID_PROGRAM_STREAM] = { SECTION_ID_PROGRAM_STREAM, "stream", 0, { SECTION_ID_PROGRAM_STREAM_DISPOSITION, SECTION_ID_PROGRAM_STREAM_TAGS, -1 }, .unique_name = "program_stream" },
321 [SECTION_ID_PROGRAM_TAGS] = { SECTION_ID_PROGRAM_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "program_tags" },
322 [SECTION_ID_PROGRAM_VERSION] = { SECTION_ID_PROGRAM_VERSION, "program_version", 0, { -1 } },
323 [SECTION_ID_PROGRAMS] = { SECTION_ID_PROGRAMS, "programs", SECTION_FLAG_IS_ARRAY, { SECTION_ID_PROGRAM, -1 } },
324 [SECTION_ID_STREAM_GROUP_STREAM_DISPOSITION] = { SECTION_ID_STREAM_GROUP_STREAM_DISPOSITION, "disposition", 0, { -1 }, .unique_name = "stream_group_stream_disposition" },
325 [SECTION_ID_STREAM_GROUP_STREAM_TAGS] = { SECTION_ID_STREAM_GROUP_STREAM_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "stream_group_stream_tags" },
326 [SECTION_ID_STREAM_GROUP] = { SECTION_ID_STREAM_GROUP, "stream_group", 0, { SECTION_ID_STREAM_GROUP_TAGS, SECTION_ID_STREAM_GROUP_DISPOSITION, SECTION_ID_STREAM_GROUP_COMPONENTS, SECTION_ID_STREAM_GROUP_STREAMS, -1 } },
327 [SECTION_ID_STREAM_GROUP_COMPONENTS] = { SECTION_ID_STREAM_GROUP_COMPONENTS, "components", SECTION_FLAG_IS_ARRAY, { SECTION_ID_STREAM_GROUP_COMPONENT, -1 }, .element_name = "component", .unique_name = "stream_group_components" },
328 [SECTION_ID_STREAM_GROUP_COMPONENT] = { SECTION_ID_STREAM_GROUP_COMPONENT, "component", SECTION_FLAG_HAS_VARIABLE_FIELDS|SECTION_FLAG_HAS_TYPE, { SECTION_ID_STREAM_GROUP_SUBCOMPONENTS, -1 }, .unique_name = "stream_group_component", .element_name = "component_entry", .get_type = get_stream_group_type },
329 [SECTION_ID_STREAM_GROUP_SUBCOMPONENTS] = { SECTION_ID_STREAM_GROUP_SUBCOMPONENTS, "subcomponents", SECTION_FLAG_IS_ARRAY, { SECTION_ID_STREAM_GROUP_SUBCOMPONENT, -1 }, .element_name = "component" },
330 [SECTION_ID_STREAM_GROUP_SUBCOMPONENT] = { SECTION_ID_STREAM_GROUP_SUBCOMPONENT, "subcomponent", SECTION_FLAG_HAS_VARIABLE_FIELDS|SECTION_FLAG_HAS_TYPE, { SECTION_ID_STREAM_GROUP_PIECES, -1 }, .element_name = "subcomponent_entry", .get_type = get_raw_string_type },
331 [SECTION_ID_STREAM_GROUP_PIECES] = { SECTION_ID_STREAM_GROUP_PIECES, "pieces", SECTION_FLAG_IS_ARRAY, { SECTION_ID_STREAM_GROUP_PIECE, -1 }, .element_name = "piece", .unique_name = "stream_group_pieces" },
332 [SECTION_ID_STREAM_GROUP_PIECE] = { SECTION_ID_STREAM_GROUP_PIECE, "piece", SECTION_FLAG_HAS_VARIABLE_FIELDS|SECTION_FLAG_HAS_TYPE, { SECTION_ID_STREAM_GROUP_SUBPIECES, -1 }, .unique_name = "stream_group_piece", .element_name = "piece_entry", .get_type = get_raw_string_type },
333 [SECTION_ID_STREAM_GROUP_SUBPIECES] = { SECTION_ID_STREAM_GROUP_SUBPIECES, "subpieces", SECTION_FLAG_IS_ARRAY, { SECTION_ID_STREAM_GROUP_SUBPIECE, -1 }, .element_name = "subpiece" },
334 [SECTION_ID_STREAM_GROUP_SUBPIECE] = { SECTION_ID_STREAM_GROUP_SUBPIECE, "subpiece", SECTION_FLAG_HAS_VARIABLE_FIELDS|SECTION_FLAG_HAS_TYPE, { SECTION_ID_STREAM_GROUP_BLOCKS, -1 }, .element_name = "subpiece_entry", .get_type = get_raw_string_type },
335 [SECTION_ID_STREAM_GROUP_BLOCKS] = { SECTION_ID_STREAM_GROUP_BLOCKS, "blocks", SECTION_FLAG_IS_ARRAY, { SECTION_ID_STREAM_GROUP_BLOCK, -1 }, .element_name = "block" },
336 [SECTION_ID_STREAM_GROUP_BLOCK] = { SECTION_ID_STREAM_GROUP_BLOCK, "block", SECTION_FLAG_HAS_VARIABLE_FIELDS|SECTION_FLAG_HAS_TYPE, { -1 }, .element_name = "block_entry", .get_type = get_raw_string_type },
337 [SECTION_ID_STREAM_GROUP_STREAMS] = { SECTION_ID_STREAM_GROUP_STREAMS, "streams", SECTION_FLAG_IS_ARRAY, { SECTION_ID_STREAM_GROUP_STREAM, -1 }, .unique_name = "stream_group_streams" },
338 [SECTION_ID_STREAM_GROUP_STREAM] = { SECTION_ID_STREAM_GROUP_STREAM, "stream", 0, { SECTION_ID_STREAM_GROUP_STREAM_DISPOSITION, SECTION_ID_STREAM_GROUP_STREAM_TAGS, -1 }, .unique_name = "stream_group_stream" },
339 [SECTION_ID_STREAM_GROUP_DISPOSITION] = { SECTION_ID_STREAM_GROUP_DISPOSITION, "disposition", 0, { -1 }, .unique_name = "stream_group_disposition" },
340 [SECTION_ID_STREAM_GROUP_TAGS] = { SECTION_ID_STREAM_GROUP_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "stream_group_tags" },
341 [SECTION_ID_STREAM_GROUPS] = { SECTION_ID_STREAM_GROUPS, "stream_groups", SECTION_FLAG_IS_ARRAY, { SECTION_ID_STREAM_GROUP, -1 } },
342 [SECTION_ID_ROOT] = { SECTION_ID_ROOT, "root", SECTION_FLAG_IS_WRAPPER,
343 { SECTION_ID_CHAPTERS, SECTION_ID_FORMAT, SECTION_ID_FRAMES, SECTION_ID_PROGRAMS, SECTION_ID_STREAM_GROUPS, SECTION_ID_STREAMS,
344 SECTION_ID_PACKETS, SECTION_ID_ERROR, SECTION_ID_PROGRAM_VERSION, SECTION_ID_LIBRARY_VERSIONS,
345 SECTION_ID_PIXEL_FORMATS, -1} },
346 [SECTION_ID_STREAMS] = { SECTION_ID_STREAMS, "streams", SECTION_FLAG_IS_ARRAY, { SECTION_ID_STREAM, -1 } },
347 [SECTION_ID_STREAM] = { SECTION_ID_STREAM, "stream", 0, { SECTION_ID_STREAM_DISPOSITION, SECTION_ID_STREAM_TAGS, SECTION_ID_STREAM_SIDE_DATA_LIST, -1 } },
348 [SECTION_ID_STREAM_DISPOSITION] = { SECTION_ID_STREAM_DISPOSITION, "disposition", 0, { -1 }, .unique_name = "stream_disposition" },
349 [SECTION_ID_STREAM_TAGS] = { SECTION_ID_STREAM_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "stream_tags" },
350 [SECTION_ID_STREAM_SIDE_DATA_LIST] ={ SECTION_ID_STREAM_SIDE_DATA_LIST, "side_data_list", SECTION_FLAG_IS_ARRAY, { SECTION_ID_STREAM_SIDE_DATA, -1 }, .element_name = "side_data", .unique_name = "stream_side_data_list" },
351 [SECTION_ID_STREAM_SIDE_DATA] = { SECTION_ID_STREAM_SIDE_DATA, "side_data", SECTION_FLAG_HAS_TYPE|SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .unique_name = "stream_side_data", .element_name = "side_datum", .get_type = get_packet_side_data_type },
352 [SECTION_ID_SUBTITLE] = { SECTION_ID_SUBTITLE, "subtitle", 0, { -1 } },
353 };
354
355 static const OptionDef *options;
356
357 /* FFprobe context */
358 static const char *input_filename;
359 static const char *print_input_filename;
360 static const AVInputFormat *iformat = NULL;
361 static const char *output_filename = NULL;
362
363 static struct AVHashContext *hash;
364
365 static const struct {
366 double bin_val;
367 double dec_val;
368 const char *bin_str;
369 const char *dec_str;
370 } si_prefixes[] = {
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" },
377 };
378
379 static const char unit_second_str[] = "s" ;
380 static const char unit_hertz_str[] = "Hz" ;
381 static const char unit_byte_str[] = "byte" ;
382 static const char unit_bit_per_second_str[] = "bit/s";
383
384 static int nb_streams;
385 static uint64_t *nb_streams_packets;
386 static uint64_t *nb_streams_frames;
387 static int *selected_streams;
388
389 #if HAVE_THREADS
390 pthread_mutex_t log_mutex;
391 #endif
392 typedef struct LogBuffer {
393 char *context_name;
394 int log_level;
395 char *log_message;
396 AVClassCategory category;
397 char *parent_name;
398 AVClassCategory parent_category;
399 }LogBuffer;
400
401 static LogBuffer *log_buffer;
402 static int log_buffer_size;
403
404 static void log_callback(void *ptr, int level, const char *fmt, va_list vl)
405 {
406 AVClass* avc = ptr ? *(AVClass **) ptr : NULL;
407 va_list vl2;
408 char line[1024];
409 static int print_prefix = 1;
410 void *new_log_buffer;
411
412 va_copy(vl2, vl);
413 av_log_default_callback(ptr, level, fmt, vl);
414 av_log_format_line(ptr, level, fmt, vl2, line, sizeof(line), &print_prefix);
415 va_end(vl2);
416
417 #if HAVE_THREADS
418 pthread_mutex_lock(&log_mutex);
419
420 new_log_buffer = av_realloc_array(log_buffer, log_buffer_size + 1, sizeof(*log_buffer));
421 if (new_log_buffer) {
422 char *msg;
423 int i;
424
425 log_buffer = new_log_buffer;
426 memset(&log_buffer[log_buffer_size], 0, sizeof(log_buffer[log_buffer_size]));
427 log_buffer[log_buffer_size].context_name= avc ? av_strdup(avc->item_name(ptr)) : NULL;
428 if (avc) {
429 if (avc->get_category) log_buffer[log_buffer_size].category = avc->get_category(ptr);
430 else log_buffer[log_buffer_size].category = avc->category;
431 }
432 log_buffer[log_buffer_size].log_level = level;
433 msg = log_buffer[log_buffer_size].log_message = av_strdup(line);
434 for (i=strlen(msg) - 1; i>=0 && msg[i] == '\n'; i--) {
435 msg[i] = 0;
436 }
437 if (avc && avc->parent_log_context_offset) {
438 AVClass** parent = *(AVClass ***) (((uint8_t *) ptr) +
439 avc->parent_log_context_offset);
440 if (parent && *parent) {
441 log_buffer[log_buffer_size].parent_name = av_strdup((*parent)->item_name(parent));
442 log_buffer[log_buffer_size].parent_category =
443 (*parent)->get_category ? (*parent)->get_category(parent) :(*parent)->category;
444 }
445 }
446 log_buffer_size ++;
447 }
448
449 pthread_mutex_unlock(&log_mutex);
450 #endif
451 }
452
453 struct unit_value {
454 union { double d; int64_t i; } val;
455 const char *unit;
456 };
457
458 38794 static char *value_string(char *buf, int buf_size, struct unit_value uv)
459 {
460 double vald;
461 int64_t vali;
462 38794 int show_float = 0;
463
464
2/2
✓ Branch 0 taken 29633 times.
✓ Branch 1 taken 9161 times.
38794 if (uv.unit == unit_second_str) {
465 29633 vald = uv.val.d;
466 29633 show_float = 1;
467 } else {
468 9161 vald = vali = uv.val.i;
469 }
470
471
3/4
✓ Branch 0 taken 29633 times.
✓ Branch 1 taken 9161 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 29633 times.
38794 if (uv.unit == unit_second_str && use_value_sexagesimal_format) {
472 double secs;
473 int hours, mins;
474 secs = vald;
475 mins = (int)secs / 60;
476 secs = secs - mins * 60;
477 hours = mins / 60;
478 mins %= 60;
479 snprintf(buf, buf_size, "%d:%02d:%09.6f", hours, mins, secs);
480 } else {
481 38794 const char *prefix_string = "";
482
483
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 38794 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
38794 if (use_value_prefix && vald > 1) {
484 int64_t index;
485
486 if (uv.unit == unit_byte_str && use_byte_value_binary_prefix) {
487 index = (int64_t) (log2(vald)) / 10;
488 index = av_clip(index, 0, FF_ARRAY_ELEMS(si_prefixes) - 1);
489 vald /= si_prefixes[index].bin_val;
490 prefix_string = si_prefixes[index].bin_str;
491 } else {
492 index = (int64_t) (log10(vald)) / 3;
493 index = av_clip(index, 0, FF_ARRAY_ELEMS(si_prefixes) - 1);
494 vald /= si_prefixes[index].dec_val;
495 prefix_string = si_prefixes[index].dec_str;
496 }
497 vali = vald;
498 }
499
500
3/6
✓ Branch 0 taken 9161 times.
✓ Branch 1 taken 29633 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9161 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
38794 if (show_float || (use_value_prefix && vald != (int64_t)vald))
501 29633 snprintf(buf, buf_size, "%f", vald);
502 else
503 9161 snprintf(buf, buf_size, "%"PRId64, vali);
504
2/4
✓ Branch 0 taken 38794 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 38794 times.
38794 av_strlcatf(buf, buf_size, "%s%s%s", *prefix_string || show_value_unit ? " " : "",
505
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 38794 times.
38794 prefix_string, show_value_unit ? uv.unit : "");
506 }
507
508 38794 return buf;
509 }
510
511 /* WRITERS API */
512
513 typedef struct WriterContext WriterContext;
514
515 #define WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS 1
516 #define WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER 2
517
518 typedef enum {
519 WRITER_STRING_VALIDATION_FAIL,
520 WRITER_STRING_VALIDATION_REPLACE,
521 WRITER_STRING_VALIDATION_IGNORE,
522 WRITER_STRING_VALIDATION_NB
523 } StringValidation;
524
525 typedef struct Writer {
526 const AVClass *priv_class; ///< private class of the writer, if any
527 int priv_size; ///< private size for the writer context
528 const char *name;
529
530 int (*init) (WriterContext *wctx);
531 void (*uninit)(WriterContext *wctx);
532
533 void (*print_section_header)(WriterContext *wctx, const void *data);
534 void (*print_section_footer)(WriterContext *wctx);
535 void (*print_integer) (WriterContext *wctx, const char *, int64_t);
536 void (*print_rational) (WriterContext *wctx, AVRational *q, char *sep);
537 void (*print_string) (WriterContext *wctx, const char *, const char *);
538 int flags; ///< a combination or WRITER_FLAG_*
539 } Writer;
540
541 #define SECTION_MAX_NB_LEVELS 12
542
543 struct WriterContext {
544 const AVClass *class; ///< class of the writer
545 const Writer *writer; ///< the Writer of which this is an instance
546 AVIOContext *avio; ///< the I/O context used to write
547
548 void (* writer_w8)(WriterContext *wctx, int b);
549 void (* writer_put_str)(WriterContext *wctx, const char *str);
550 void (* writer_printf)(WriterContext *wctx, const char *fmt, ...);
551
552 char *name; ///< name of this writer instance
553 void *priv; ///< private data for use by the filter
554
555 const struct section *sections; ///< array containing all sections
556 int nb_sections; ///< number of sections
557
558 int level; ///< current level, starting from 0
559
560 /** number of the item printed in the given section, starting from 0 */
561 unsigned int nb_item[SECTION_MAX_NB_LEVELS];
562
563 /** section per each level */
564 const struct section *section[SECTION_MAX_NB_LEVELS];
565 AVBPrint section_pbuf[SECTION_MAX_NB_LEVELS]; ///< generic print buffer dedicated to each section,
566 /// used by various writers
567
568 unsigned int nb_section_packet; ///< number of the packet section in case we are in "packets_and_frames" section
569 unsigned int nb_section_frame; ///< number of the frame section in case we are in "packets_and_frames" section
570 unsigned int nb_section_packet_frame; ///< nb_section_packet or nb_section_frame according if is_packets_and_frames
571
572 int string_validation;
573 char *string_validation_replacement;
574 unsigned int string_validation_utf8_flags;
575 };
576
577 static const char *writer_get_name(void *p)
578 {
579 WriterContext *wctx = p;
580 return wctx->writer->name;
581 }
582
583 #define OFFSET(x) offsetof(WriterContext, x)
584
585 static const AVOption writer_options[] = {
586 { "string_validation", "set string validation mode",
587 OFFSET(string_validation), AV_OPT_TYPE_INT, {.i64=WRITER_STRING_VALIDATION_REPLACE}, 0, WRITER_STRING_VALIDATION_NB-1, .unit = "sv" },
588 { "sv", "set string validation mode",
589 OFFSET(string_validation), AV_OPT_TYPE_INT, {.i64=WRITER_STRING_VALIDATION_REPLACE}, 0, WRITER_STRING_VALIDATION_NB-1, .unit = "sv" },
590 { "ignore", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = WRITER_STRING_VALIDATION_IGNORE}, .unit = "sv" },
591 { "replace", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = WRITER_STRING_VALIDATION_REPLACE}, .unit = "sv" },
592 { "fail", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = WRITER_STRING_VALIDATION_FAIL}, .unit = "sv" },
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"}},
595 { NULL }
596 };
597
598 30 static void *writer_child_next(void *obj, void *prev)
599 {
600 30 WriterContext *ctx = obj;
601
4/8
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 30 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 30 times.
✗ Branch 7 not taken.
30 if (!prev && ctx->writer && ctx->writer->priv_class && ctx->priv)
602 30 return ctx->priv;
603 return NULL;
604 }
605
606 static const AVClass writer_class = {
607 .class_name = "Writer",
608 .item_name = writer_get_name,
609 .option = writer_options,
610 .version = LIBAVUTIL_VERSION_INT,
611 .child_next = writer_child_next,
612 };
613
614 152 static int writer_close(WriterContext **wctx)
615 {
616 int i;
617 152 int ret = 0;
618
619
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
152 if (!*wctx)
620 return -1;
621
622
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
152 if ((*wctx)->writer->uninit)
623 (*wctx)->writer->uninit(*wctx);
624
2/2
✓ Branch 0 taken 1824 times.
✓ Branch 1 taken 152 times.
1976 for (i = 0; i < SECTION_MAX_NB_LEVELS; i++)
625 1824 av_bprint_finalize(&(*wctx)->section_pbuf[i], NULL);
626
1/2
✓ Branch 0 taken 152 times.
✗ Branch 1 not taken.
152 if ((*wctx)->writer->priv_class)
627 152 av_opt_free((*wctx)->priv);
628 152 av_freep(&((*wctx)->priv));
629 152 av_opt_free(*wctx);
630
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
152 if ((*wctx)->avio) {
631 avio_flush((*wctx)->avio);
632 ret = avio_close((*wctx)->avio);
633 }
634 152 av_freep(wctx);
635 152 return ret;
636 }
637
638 static void bprint_bytes(AVBPrint *bp, const uint8_t *ubuf, size_t ubuf_size)
639 {
640 int i;
641 av_bprintf(bp, "0X");
642 for (i = 0; i < ubuf_size; i++)
643 av_bprintf(bp, "%02X", ubuf[i]);
644 }
645
646 static inline void writer_w8_avio(WriterContext *wctx, int b)
647 {
648 avio_w8(wctx->avio, b);
649 }
650
651 static inline void writer_put_str_avio(WriterContext *wctx, const char *str)
652 {
653 avio_write(wctx->avio, str, strlen(str));
654 }
655
656 static inline void writer_printf_avio(WriterContext *wctx, const char *fmt, ...)
657 {
658 va_list ap;
659
660 va_start(ap, fmt);
661 avio_vprintf(wctx->avio, fmt, ap);
662 va_end(ap);
663 }
664
665 60993 static inline void writer_w8_printf(WriterContext *wctx, int b)
666 {
667 60993 printf("%c", b);
668 60993 }
669
670 31462 static inline void writer_put_str_printf(WriterContext *wctx, const char *str)
671 {
672 31462 printf("%s", str);
673 31462 }
674
675 134825 static inline void writer_printf_printf(WriterContext *wctx, const char *fmt, ...)
676 {
677 va_list ap;
678
679 134825 va_start(ap, fmt);
680 134825 vprintf(fmt, ap);
681 134825 va_end(ap);
682 134825 }
683
684 152 static int writer_open(WriterContext **wctx, const Writer *writer, const char *args,
685 const struct section *sections, int nb_sections, const char *output)
686 {
687 152 int i, ret = 0;
688
689
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 152 times.
152 if (!(*wctx = av_mallocz(sizeof(WriterContext)))) {
690 ret = AVERROR(ENOMEM);
691 goto fail;
692 }
693
694
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 152 times.
152 if (!((*wctx)->priv = av_mallocz(writer->priv_size))) {
695 ret = AVERROR(ENOMEM);
696 goto fail;
697 }
698
699 152 (*wctx)->class = &writer_class;
700 152 (*wctx)->writer = writer;
701 152 (*wctx)->level = -1;
702 152 (*wctx)->sections = sections;
703 152 (*wctx)->nb_sections = nb_sections;
704
705 152 av_opt_set_defaults(*wctx);
706
707
1/2
✓ Branch 0 taken 152 times.
✗ Branch 1 not taken.
152 if (writer->priv_class) {
708 152 void *priv_ctx = (*wctx)->priv;
709 152 *((const AVClass **)priv_ctx) = writer->priv_class;
710 152 av_opt_set_defaults(priv_ctx);
711 }
712
713 /* convert options to dictionary */
714
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 130 times.
152 if (args) {
715 22 AVDictionary *opts = NULL;
716 22 const AVDictionaryEntry *opt = NULL;
717
718
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
22 if ((ret = av_dict_parse_string(&opts, args, "=", ":", 0)) < 0) {
719 av_log(*wctx, AV_LOG_ERROR, "Failed to parse option string '%s' provided to writer context\n", args);
720 av_dict_free(&opts);
721 goto fail;
722 }
723
724
2/2
✓ Branch 1 taken 30 times.
✓ Branch 2 taken 22 times.
52 while ((opt = av_dict_iterate(opts, opt))) {
725
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
30 if ((ret = av_opt_set(*wctx, opt->key, opt->value, AV_OPT_SEARCH_CHILDREN)) < 0) {
726 av_log(*wctx, AV_LOG_ERROR, "Failed to set option '%s' with value '%s' provided to writer context\n",
727 opt->key, opt->value);
728 av_dict_free(&opts);
729 goto fail;
730 }
731 }
732
733 22 av_dict_free(&opts);
734 }
735
736 /* validate replace string */
737 {
738 152 const uint8_t *p = (*wctx)->string_validation_replacement;
739 152 const uint8_t *endp = p + strlen(p);
740
2/2
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 152 times.
304 while (*p) {
741 152 const uint8_t *p0 = p;
742 int32_t code;
743 152 ret = av_utf8_decode(&code, &p, endp, (*wctx)->string_validation_utf8_flags);
744
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
152 if (ret < 0) {
745 AVBPrint bp;
746 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
747 bprint_bytes(&bp, p0, p-p0),
748 av_log(wctx, AV_LOG_ERROR,
749 "Invalid UTF8 sequence %s found in string validation replace '%s'\n",
750 bp.str, (*wctx)->string_validation_replacement);
751 return ret;
752 }
753 }
754 }
755
756
1/2
✓ Branch 0 taken 152 times.
✗ Branch 1 not taken.
152 if (!output_filename) {
757 152 (*wctx)->writer_w8 = writer_w8_printf;
758 152 (*wctx)->writer_put_str = writer_put_str_printf;
759 152 (*wctx)->writer_printf = writer_printf_printf;
760 } else {
761 if ((ret = avio_open(&(*wctx)->avio, output, AVIO_FLAG_WRITE)) < 0) {
762 av_log(*wctx, AV_LOG_ERROR,
763 "Failed to open output '%s' with error: %s\n", output, av_err2str(ret));
764 goto fail;
765 }
766 (*wctx)->writer_w8 = writer_w8_avio;
767 (*wctx)->writer_put_str = writer_put_str_avio;
768 (*wctx)->writer_printf = writer_printf_avio;
769 }
770
771
2/2
✓ Branch 0 taken 1824 times.
✓ Branch 1 taken 152 times.
1976 for (i = 0; i < SECTION_MAX_NB_LEVELS; i++)
772 1824 av_bprint_init(&(*wctx)->section_pbuf[i], 1, AV_BPRINT_SIZE_UNLIMITED);
773
774
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 104 times.
152 if ((*wctx)->writer->init)
775 48 ret = (*wctx)->writer->init(*wctx);
776
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
152 if (ret < 0)
777 goto fail;
778
779 152 return 0;
780
781 fail:
782 writer_close(wctx);
783 return ret;
784 }
785
786 13237 static inline void writer_print_section_header(WriterContext *wctx,
787 const void *data,
788 int section_id)
789 {
790 int parent_section_id;
791 13237 wctx->level++;
792
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13237 times.
13237 av_assert0(wctx->level < SECTION_MAX_NB_LEVELS);
793 26474 parent_section_id = wctx->level ?
794
2/2
✓ Branch 0 taken 13085 times.
✓ Branch 1 taken 152 times.
13237 (wctx->section[wctx->level-1])->id : SECTION_ID_NONE;
795
796 13237 wctx->nb_item[wctx->level] = 0;
797 13237 wctx->section[wctx->level] = &wctx->sections[section_id];
798
799
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 13232 times.
13237 if (section_id == SECTION_ID_PACKETS_AND_FRAMES) {
800 5 wctx->nb_section_packet = wctx->nb_section_frame =
801 5 wctx->nb_section_packet_frame = 0;
802
2/2
✓ Branch 0 taken 140 times.
✓ Branch 1 taken 13092 times.
13232 } else if (parent_section_id == SECTION_ID_PACKETS_AND_FRAMES) {
803 140 wctx->nb_section_packet_frame = section_id == SECTION_ID_PACKET ?
804
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 70 times.
140 wctx->nb_section_packet : wctx->nb_section_frame;
805 }
806
807
1/2
✓ Branch 0 taken 13237 times.
✗ Branch 1 not taken.
13237 if (wctx->writer->print_section_header)
808 13237 wctx->writer->print_section_header(wctx, data);
809 13237 }
810
811 13237 static inline void writer_print_section_footer(WriterContext *wctx)
812 {
813 13237 int section_id = wctx->section[wctx->level]->id;
814 26474 int parent_section_id = wctx->level ?
815
2/2
✓ Branch 0 taken 13085 times.
✓ Branch 1 taken 152 times.
13237 wctx->section[wctx->level-1]->id : SECTION_ID_NONE;
816
817
2/2
✓ Branch 0 taken 13085 times.
✓ Branch 1 taken 152 times.
13237 if (parent_section_id != SECTION_ID_NONE)
818 13085 wctx->nb_item[wctx->level-1]++;
819
2/2
✓ Branch 0 taken 140 times.
✓ Branch 1 taken 13097 times.
13237 if (parent_section_id == SECTION_ID_PACKETS_AND_FRAMES) {
820
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 70 times.
140 if (section_id == SECTION_ID_PACKET) wctx->nb_section_packet++;
821 70 else wctx->nb_section_frame++;
822 }
823
2/2
✓ Branch 0 taken 13147 times.
✓ Branch 1 taken 90 times.
13237 if (wctx->writer->print_section_footer)
824 13147 wctx->writer->print_section_footer(wctx);
825 13237 wctx->level--;
826 13237 }
827
828 60206 static inline void writer_print_integer(WriterContext *wctx,
829 const char *key, int64_t val)
830 {
831 60206 const struct section *section = wctx->section[wctx->level];
832
833
4/4
✓ Branch 0 taken 35948 times.
✓ Branch 1 taken 24258 times.
✓ Branch 3 taken 15272 times.
✓ Branch 4 taken 20676 times.
60206 if (section->show_all_entries || av_dict_get(section->entries_to_show, key, NULL, 0)) {
834 39530 wctx->writer->print_integer(wctx, key, val);
835 39530 wctx->nb_item[wctx->level]++;
836 }
837 60206 }
838
839 5904 static inline int validate_string(WriterContext *wctx, char **dstp, const char *src)
840 {
841 const uint8_t *p, *endp;
842 AVBPrint dstbuf;
843 5904 int invalid_chars_nb = 0, ret = 0;
844
845 5904 av_bprint_init(&dstbuf, 0, AV_BPRINT_SIZE_UNLIMITED);
846
847 5904 endp = src + strlen(src);
848
2/2
✓ Branch 0 taken 92819 times.
✓ Branch 1 taken 5904 times.
98723 for (p = src; *p;) {
849 uint32_t code;
850 92819 int invalid = 0;
851 92819 const uint8_t *p0 = p;
852
853
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 92819 times.
92819 if (av_utf8_decode(&code, &p, endp, wctx->string_validation_utf8_flags) < 0) {
854 AVBPrint bp;
855 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
856 bprint_bytes(&bp, p0, p-p0);
857 av_log(wctx, AV_LOG_DEBUG,
858 "Invalid UTF-8 sequence %s found in string '%s'\n", bp.str, src);
859 invalid = 1;
860 }
861
862
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92819 times.
92819 if (invalid) {
863 invalid_chars_nb++;
864
865 switch (wctx->string_validation) {
866 case WRITER_STRING_VALIDATION_FAIL:
867 av_log(wctx, AV_LOG_ERROR,
868 "Invalid UTF-8 sequence found in string '%s'\n", src);
869 ret = AVERROR_INVALIDDATA;
870 goto end;
871 break;
872
873 case WRITER_STRING_VALIDATION_REPLACE:
874 av_bprintf(&dstbuf, "%s", wctx->string_validation_replacement);
875 break;
876 }
877 }
878
879
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 92819 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
92819 if (!invalid || wctx->string_validation == WRITER_STRING_VALIDATION_IGNORE)
880 92819 av_bprint_append_data(&dstbuf, p0, p-p0);
881 }
882
883
1/4
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
5904 if (invalid_chars_nb && wctx->string_validation == WRITER_STRING_VALIDATION_REPLACE) {
884 av_log(wctx, AV_LOG_WARNING,
885 "%d invalid UTF-8 sequence(s) found in string '%s', replaced with '%s'\n",
886 invalid_chars_nb, src, wctx->string_validation_replacement);
887 }
888
889 5904 end:
890 5904 av_bprint_finalize(&dstbuf, dstp);
891 5904 return ret;
892 }
893
894 #define PRINT_STRING_OPT 1
895 #define PRINT_STRING_VALIDATE 2
896
897 86167 static inline int writer_print_string(WriterContext *wctx,
898 const char *key, const char *val, int flags)
899 {
900 86167 const struct section *section = wctx->section[wctx->level];
901 86167 int ret = 0;
902
903
1/2
✓ Branch 0 taken 86167 times.
✗ Branch 1 not taken.
86167 if (show_optional_fields == SHOW_OPTIONAL_FIELDS_NEVER ||
904
1/2
✓ Branch 0 taken 86167 times.
✗ Branch 1 not taken.
86167 (show_optional_fields == SHOW_OPTIONAL_FIELDS_AUTO
905
2/2
✓ Branch 0 taken 6075 times.
✓ Branch 1 taken 80092 times.
86167 && (flags & PRINT_STRING_OPT)
906
2/2
✓ Branch 0 taken 268 times.
✓ Branch 1 taken 5807 times.
6075 && !(wctx->writer->flags & WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS)))
907 268 return 0;
908
909
4/4
✓ Branch 0 taken 47611 times.
✓ Branch 1 taken 38288 times.
✓ Branch 3 taken 2305 times.
✓ Branch 4 taken 45306 times.
85899 if (section->show_all_entries || av_dict_get(section->entries_to_show, key, NULL, 0)) {
910
2/2
✓ Branch 0 taken 2952 times.
✓ Branch 1 taken 37641 times.
40593 if (flags & PRINT_STRING_VALIDATE) {
911 2952 char *key1 = NULL, *val1 = NULL;
912 2952 ret = validate_string(wctx, &key1, key);
913
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2952 times.
2952 if (ret < 0) goto end;
914 2952 ret = validate_string(wctx, &val1, val);
915
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2952 times.
2952 if (ret < 0) goto end;
916 2952 wctx->writer->print_string(wctx, key1, val1);
917 2952 end:
918
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2952 times.
2952 if (ret < 0) {
919 av_log(wctx, AV_LOG_ERROR,
920 "Invalid key=value string combination %s=%s in section %s\n",
921 key, val, section->unique_name);
922 }
923 2952 av_free(key1);
924 2952 av_free(val1);
925 } else {
926 37641 wctx->writer->print_string(wctx, key, val);
927 }
928
929 40593 wctx->nb_item[wctx->level]++;
930 }
931
932 85899 return ret;
933 }
934
935 2262 static inline void writer_print_rational(WriterContext *wctx,
936 const char *key, AVRational q, char sep)
937 {
938 AVBPrint buf;
939 2262 av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC);
940 2262 av_bprintf(&buf, "%d%c%d", q.num, sep, q.den);
941 2262 writer_print_string(wctx, key, buf.str, 0);
942 2262 }
943
944 30306 static void writer_print_time(WriterContext *wctx, const char *key,
945 int64_t ts, const AVRational *time_base, int is_duration)
946 {
947 char buf[128];
948
949
8/8
✓ Branch 0 taken 21494 times.
✓ Branch 1 taken 8812 times.
✓ Branch 2 taken 20824 times.
✓ Branch 3 taken 670 times.
✓ Branch 4 taken 8812 times.
✓ Branch 5 taken 20824 times.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 8809 times.
30306 if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
950 673 writer_print_string(wctx, key, "N/A", PRINT_STRING_OPT);
951 } else {
952 29633 double d = ts * av_q2d(*time_base);
953 struct unit_value uv;
954 29633 uv.val.d = d;
955 29633 uv.unit = unit_second_str;
956 29633 value_string(buf, sizeof(buf), uv);
957 29633 writer_print_string(wctx, key, buf, 0);
958 }
959 30306 }
960
961 30178 static void writer_print_ts(WriterContext *wctx, const char *key, int64_t ts, int is_duration)
962 {
963
8/8
✓ Branch 0 taken 21366 times.
✓ Branch 1 taken 8812 times.
✓ Branch 2 taken 20698 times.
✓ Branch 3 taken 668 times.
✓ Branch 4 taken 8812 times.
✓ Branch 5 taken 20698 times.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 8809 times.
30178 if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
964 671 writer_print_string(wctx, key, "N/A", PRINT_STRING_OPT);
965 } else {
966 29507 writer_print_integer(wctx, key, ts);
967 }
968 30178 }
969
970 static void writer_print_data(WriterContext *wctx, const char *name,
971 const uint8_t *data, int size)
972 {
973 AVBPrint bp;
974 int offset = 0, l, i;
975
976 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
977 av_bprintf(&bp, "\n");
978 while (size) {
979 av_bprintf(&bp, "%08x: ", offset);
980 l = FFMIN(size, 16);
981 for (i = 0; i < l; i++) {
982 av_bprintf(&bp, "%02x", data[i]);
983 if (i & 1)
984 av_bprintf(&bp, " ");
985 }
986 av_bprint_chars(&bp, ' ', 41 - 2 * i - i / 2);
987 for (i = 0; i < l; i++)
988 av_bprint_chars(&bp, data[i] - 32U < 95 ? data[i] : '.', 1);
989 av_bprintf(&bp, "\n");
990 offset += l;
991 data += l;
992 size -= l;
993 }
994 writer_print_string(wctx, name, bp.str, 0);
995 av_bprint_finalize(&bp, NULL);
996 }
997
998 5884 static void writer_print_data_hash(WriterContext *wctx, const char *name,
999 const uint8_t *data, int size)
1000 {
1001 5884 char *p, buf[AV_HASH_MAX_SIZE * 2 + 64] = { 0 };
1002
1003
2/2
✓ Branch 0 taken 3879 times.
✓ Branch 1 taken 2005 times.
5884 if (!hash)
1004 3879 return;
1005 2005 av_hash_init(hash);
1006 2005 av_hash_update(hash, data, size);
1007 2005 snprintf(buf, sizeof(buf), "%s:", av_hash_get_name(hash));
1008 2005 p = buf + strlen(buf);
1009 2005 av_hash_final_hex(hash, p, buf + sizeof(buf) - p);
1010 2005 writer_print_string(wctx, name, buf, 0);
1011 }
1012
1013 92 static void writer_print_integers(WriterContext *wctx, const char *name,
1014 uint8_t *data, int size, const char *format,
1015 int columns, int bytes, int offset_add)
1016 {
1017 AVBPrint bp;
1018 92 int offset = 0, l, i;
1019
1020 92 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
1021 92 av_bprintf(&bp, "\n");
1022
2/2
✓ Branch 0 taken 276 times.
✓ Branch 1 taken 92 times.
368 while (size) {
1023 276 av_bprintf(&bp, "%08x: ", offset);
1024 276 l = FFMIN(size, columns);
1025
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 276 times.
1104 for (i = 0; i < l; i++) {
1026
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 828 times.
828 if (bytes == 1) av_bprintf(&bp, format, *data);
1027
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 828 times.
828 else if (bytes == 2) av_bprintf(&bp, format, AV_RN16(data));
1028
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 else if (bytes == 4) av_bprintf(&bp, format, AV_RN32(data));
1029 828 data += bytes;
1030 828 size --;
1031 }
1032 276 av_bprintf(&bp, "\n");
1033 276 offset += offset_add;
1034 }
1035 92 writer_print_string(wctx, name, bp.str, 0);
1036 92 av_bprint_finalize(&bp, NULL);
1037 92 }
1038
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__)
1042
1043 #define MAX_REGISTERED_WRITERS_NB 64
1044
1045 static const Writer *registered_writers[MAX_REGISTERED_WRITERS_NB + 1];
1046
1047 1064 static int writer_register(const Writer *writer)
1048 {
1049 static int next_registered_writer_idx = 0;
1050
1051
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1064 times.
1064 if (next_registered_writer_idx == MAX_REGISTERED_WRITERS_NB)
1052 return AVERROR(ENOMEM);
1053
1054 1064 registered_writers[next_registered_writer_idx++] = writer;
1055 1064 return 0;
1056 }
1057
1058 152 static const Writer *writer_get_by_name(const char *name)
1059 {
1060 int i;
1061
1062
1/2
✓ Branch 0 taken 235 times.
✗ Branch 1 not taken.
235 for (i = 0; registered_writers[i]; i++)
1063
2/2
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 83 times.
235 if (!strcmp(registered_writers[i]->name, name))
1064 152 return registered_writers[i];
1065
1066 return NULL;
1067 }
1068
1069
1070 /* WRITERS */
1071
1072 #define DEFINE_WRITER_CLASS(name) \
1073 static const char *name##_get_name(void *ctx) \
1074 { \
1075 return #name ; \
1076 } \
1077 static const AVClass name##_class = { \
1078 .class_name = #name, \
1079 .item_name = name##_get_name, \
1080 .option = name##_options \
1081 }
1082
1083 /* Default output */
1084
1085 typedef struct DefaultContext {
1086 const AVClass *class;
1087 int nokey;
1088 int noprint_wrappers;
1089 int nested_section[SECTION_MAX_NB_LEVELS];
1090 } DefaultContext;
1091
1092 #undef OFFSET
1093 #define OFFSET(x) offsetof(DefaultContext, x)
1094
1095 static const AVOption default_options[] = {
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 },
1098 { "nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1099 { "nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1100 {NULL},
1101 };
1102
1103 DEFINE_WRITER_CLASS(default);
1104
1105 /* lame uppercasing routine, assumes the string is lower case ASCII */
1106 4595 static inline char *upcase_string(char *dst, size_t dst_size, const char *src)
1107 {
1108 int i;
1109
3/4
✓ Branch 0 taken 32109 times.
✓ Branch 1 taken 4595 times.
✓ Branch 2 taken 32109 times.
✗ Branch 3 not taken.
36704 for (i = 0; src[i] && i < dst_size-1; i++)
1110 32109 dst[i] = av_toupper(src[i]);
1111 4595 dst[i] = 0;
1112 4595 return dst;
1113 }
1114
1115 2996 static void default_print_section_header(WriterContext *wctx, const void *data)
1116 {
1117 2996 DefaultContext *def = wctx->priv;
1118 char buf[32];
1119 2996 const struct section *section = wctx->section[wctx->level];
1120 5992 const struct section *parent_section = wctx->level ?
1121
2/2
✓ Branch 0 taken 2893 times.
✓ Branch 1 taken 103 times.
2996 wctx->section[wctx->level-1] : NULL;
1122
1123 2996 av_bprint_clear(&wctx->section_pbuf[wctx->level]);
1124
2/2
✓ Branch 0 taken 2893 times.
✓ Branch 1 taken 103 times.
2996 if (parent_section &&
1125
2/2
✓ Branch 0 taken 811 times.
✓ Branch 1 taken 2082 times.
2893 !(parent_section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))) {
1126 811 def->nested_section[wctx->level] = 1;
1127 811 av_bprintf(&wctx->section_pbuf[wctx->level], "%s%s:",
1128 811 wctx->section_pbuf[wctx->level-1].str,
1129 upcase_string(buf, sizeof(buf),
1130 811 av_x_if_null(section->element_name, section->name)));
1131 }
1132
1133
4/4
✓ Branch 0 taken 2988 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 811 times.
✓ Branch 3 taken 2177 times.
2996 if (def->noprint_wrappers || def->nested_section[wctx->level])
1134 819 return;
1135
1136
2/2
✓ Branch 0 taken 1892 times.
✓ Branch 1 taken 285 times.
2177 if (!(section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY)))
1137 1892 writer_printf(wctx, "[%s]\n", upcase_string(buf, sizeof(buf), section->name));
1138 }
1139
1140 2996 static void default_print_section_footer(WriterContext *wctx)
1141 {
1142 2996 DefaultContext *def = wctx->priv;
1143 2996 const struct section *section = wctx->section[wctx->level];
1144 char buf[32];
1145
1146
4/4
✓ Branch 0 taken 2988 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 811 times.
✓ Branch 3 taken 2177 times.
2996 if (def->noprint_wrappers || def->nested_section[wctx->level])
1147 819 return;
1148
1149
2/2
✓ Branch 0 taken 1892 times.
✓ Branch 1 taken 285 times.
2177 if (!(section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY)))
1150 1892 writer_printf(wctx, "[/%s]\n", upcase_string(buf, sizeof(buf), section->name));
1151 }
1152
1153 8737 static void default_print_str(WriterContext *wctx, const char *key, const char *value)
1154 {
1155 8737 DefaultContext *def = wctx->priv;
1156
1157
2/2
✓ Branch 0 taken 8733 times.
✓ Branch 1 taken 4 times.
8737 if (!def->nokey)
1158 8733 writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
1159 8737 writer_printf(wctx, "%s\n", value);
1160 8737 }
1161
1162 8409 static void default_print_int(WriterContext *wctx, const char *key, int64_t value)
1163 {
1164 8409 DefaultContext *def = wctx->priv;
1165
1166
1/2
✓ Branch 0 taken 8409 times.
✗ Branch 1 not taken.
8409 if (!def->nokey)
1167 8409 writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
1168 8409 writer_printf(wctx, "%"PRId64"\n", value);
1169 8409 }
1170
1171 static const Writer default_writer = {
1172 .name = "default",
1173 .priv_size = sizeof(DefaultContext),
1174 .print_section_header = default_print_section_header,
1175 .print_section_footer = default_print_section_footer,
1176 .print_integer = default_print_int,
1177 .print_string = default_print_str,
1178 .flags = WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS,
1179 .priv_class = &default_class,
1180 };
1181
1182 /* Compact output */
1183
1184 /**
1185 * Apply C-language-like string escaping.
1186 */
1187 29882 static const char *c_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
1188 {
1189 const char *p;
1190
1191
2/2
✓ Branch 0 taken 202959 times.
✓ Branch 1 taken 29882 times.
232841 for (p = src; *p; p++) {
1192
2/6
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 264 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 202695 times.
202959 switch (*p) {
1193 case '\b': av_bprintf(dst, "%s", "\\b"); break;
1194 case '\f': av_bprintf(dst, "%s", "\\f"); break;
1195 264 case '\n': av_bprintf(dst, "%s", "\\n"); break;
1196 case '\r': av_bprintf(dst, "%s", "\\r"); break;
1197 case '\\': av_bprintf(dst, "%s", "\\\\"); break;
1198 202695 default:
1199
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 202695 times.
202695 if (*p == sep)
1200 av_bprint_chars(dst, '\\', 1);
1201 202695 av_bprint_chars(dst, *p, 1);
1202 }
1203 }
1204 29882 return dst->str;
1205 }
1206
1207 /**
1208 * Quote fields containing special characters, check RFC4180.
1209 */
1210 362 static const char *csv_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
1211 {
1212 362 char meta_chars[] = { sep, '"', '\n', '\r', '\0' };
1213 362 int needs_quoting = !!src[strcspn(src, meta_chars)];
1214
1215
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 361 times.
362 if (needs_quoting)
1216 1 av_bprint_chars(dst, '"', 1);
1217
1218
2/2
✓ Branch 0 taken 2326 times.
✓ Branch 1 taken 362 times.
2688 for (; *src; src++) {
1219
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2324 times.
2326 if (*src == '"')
1220 2 av_bprint_chars(dst, '"', 1);
1221 2326 av_bprint_chars(dst, *src, 1);
1222 }
1223
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 361 times.
362 if (needs_quoting)
1224 1 av_bprint_chars(dst, '"', 1);
1225 362 return dst->str;
1226 }
1227
1228 static const char *none_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
1229 {
1230 return src;
1231 }
1232
1233 typedef struct CompactContext {
1234 const AVClass *class;
1235 char *item_sep_str;
1236 char item_sep;
1237 int nokey;
1238 int print_section;
1239 char *escape_mode_str;
1240 const char * (*escape_str)(AVBPrint *dst, const char *src, const char sep, void *log_ctx);
1241 int nested_section[SECTION_MAX_NB_LEVELS];
1242 int has_nested_elems[SECTION_MAX_NB_LEVELS];
1243 int terminate_line[SECTION_MAX_NB_LEVELS];
1244 } CompactContext;
1245
1246 #undef OFFSET
1247 #define OFFSET(x) offsetof(CompactContext, x)
1248
1249 static const AVOption compact_options[]= {
1250 {"item_sep", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str="|"}, 0, 0 },
1251 {"s", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str="|"}, 0, 0 },
1252 {"nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1253 {"nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1254 {"escape", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="c"}, 0, 0 },
1255 {"e", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="c"}, 0, 0 },
1256 {"print_section", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1257 {"p", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1258 {NULL},
1259 };
1260
1261 DEFINE_WRITER_CLASS(compact);
1262
1263 40 static av_cold int compact_init(WriterContext *wctx)
1264 {
1265 40 CompactContext *compact = wctx->priv;
1266
1267
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (strlen(compact->item_sep_str) != 1) {
1268 av_log(wctx, AV_LOG_ERROR, "Item separator '%s' specified, but must contain a single character\n",
1269 compact->item_sep_str);
1270 return AVERROR(EINVAL);
1271 }
1272 40 compact->item_sep = compact->item_sep_str[0];
1273
1274
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (!strcmp(compact->escape_mode_str, "none")) compact->escape_str = none_escape_str;
1275
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 1 times.
40 else if (!strcmp(compact->escape_mode_str, "c" )) compact->escape_str = c_escape_str;
1276
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 else if (!strcmp(compact->escape_mode_str, "csv" )) compact->escape_str = csv_escape_str;
1277 else {
1278 av_log(wctx, AV_LOG_ERROR, "Unknown escape mode '%s'\n", compact->escape_mode_str);
1279 return AVERROR(EINVAL);
1280 }
1281
1282 40 return 0;
1283 }
1284
1285 9997 static void compact_print_section_header(WriterContext *wctx, const void *data)
1286 {
1287 9997 CompactContext *compact = wctx->priv;
1288 9997 const struct section *section = wctx->section[wctx->level];
1289 19994 const struct section *parent_section = wctx->level ?
1290
2/2
✓ Branch 0 taken 9957 times.
✓ Branch 1 taken 40 times.
9997 wctx->section[wctx->level-1] : NULL;
1291 9997 compact->terminate_line[wctx->level] = 1;
1292 9997 compact->has_nested_elems[wctx->level] = 0;
1293
1294 9997 av_bprint_clear(&wctx->section_pbuf[wctx->level]);
1295
2/2
✓ Branch 0 taken 9957 times.
✓ Branch 1 taken 40 times.
9997 if (parent_section &&
1296
2/2
✓ Branch 0 taken 9090 times.
✓ Branch 1 taken 867 times.
9957 (section->flags & SECTION_FLAG_HAS_TYPE ||
1297
2/2
✓ Branch 0 taken 8211 times.
✓ Branch 1 taken 879 times.
9090 (!(section->flags & SECTION_FLAG_IS_ARRAY) &&
1298
2/2
✓ Branch 0 taken 495 times.
✓ Branch 1 taken 7716 times.
8211 !(parent_section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))))) {
1299
1300 /* define a prefix for elements not contained in an array or
1301 in a wrapper, or for array elements with a type */
1302 1362 const char *element_name = (char *)av_x_if_null(section->element_name, section->name);
1303 1362 AVBPrint *section_pbuf = &wctx->section_pbuf[wctx->level];
1304
1305 1362 compact->nested_section[wctx->level] = 1;
1306 1362 compact->has_nested_elems[wctx->level-1] = 1;
1307
1308 1362 av_bprintf(section_pbuf, "%s%s",
1309 1362 wctx->section_pbuf[wctx->level-1].str, element_name);
1310
1311
2/2
✓ Branch 0 taken 867 times.
✓ Branch 1 taken 495 times.
1362 if (section->flags & SECTION_FLAG_HAS_TYPE) {
1312 // add /TYPE to prefix
1313 867 av_bprint_chars(section_pbuf, '/', 1);
1314
1315 // normalize section type, replace special characters and lower case
1316
2/2
✓ Branch 1 taken 15654 times.
✓ Branch 2 taken 867 times.
16521 for (const char *p = section->get_type(data); *p; p++) {
1317 2005 char c =
1318
4/4
✓ Branch 0 taken 13783 times.
✓ Branch 1 taken 1871 times.
✓ Branch 2 taken 13385 times.
✓ Branch 3 taken 398 times.
15654 (*p >= '0' && *p <= '9') ||
1319
3/4
✓ Branch 0 taken 6643 times.
✓ Branch 1 taken 8613 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6643 times.
15256 (*p >= 'a' && *p <= 'z') ||
1320
4/4
✓ Branch 0 taken 6742 times.
✓ Branch 1 taken 1871 times.
✓ Branch 2 taken 6608 times.
✓ Branch 3 taken 134 times.
15654 (*p >= 'A' && *p <= 'Z') ? av_tolower(*p) : '_';
1321 15654 av_bprint_chars(section_pbuf, c, 1);
1322 }
1323 }
1324 1362 av_bprint_chars(section_pbuf, ':', 1);
1325
1326 1362 wctx->nb_item[wctx->level] = wctx->nb_item[wctx->level-1];
1327 } else {
1328
4/4
✓ Branch 0 taken 8595 times.
✓ Branch 1 taken 40 times.
✓ Branch 2 taken 801 times.
✓ Branch 3 taken 7794 times.
8635 if (parent_section && !(parent_section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY)) &&
1329
2/4
✓ Branch 0 taken 801 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 801 times.
✗ Branch 3 not taken.
801 wctx->level && wctx->nb_item[wctx->level-1])
1330 801 writer_w8(wctx, compact->item_sep);
1331
2/2
✓ Branch 0 taken 7470 times.
✓ Branch 1 taken 1165 times.
8635 if (compact->print_section &&
1332
2/2
✓ Branch 0 taken 6705 times.
✓ Branch 1 taken 765 times.
7470 !(section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY)))
1333 6705 writer_printf(wctx, "%s%c", section->name, compact->item_sep);
1334 }
1335 9997 }
1336
1337 9997 static void compact_print_section_footer(WriterContext *wctx)
1338 {
1339 9997 CompactContext *compact = wctx->priv;
1340
1341
2/2
✓ Branch 0 taken 8585 times.
✓ Branch 1 taken 1412 times.
9997 if (!compact->nested_section[wctx->level] &&
1342
1/2
✓ Branch 0 taken 8585 times.
✗ Branch 1 not taken.
8585 compact->terminate_line[wctx->level] &&
1343
2/2
✓ Branch 0 taken 7716 times.
✓ Branch 1 taken 869 times.
8585 !(wctx->section[wctx->level]->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY)))
1344 7716 writer_w8(wctx, '\n');
1345 9997 }
1346
1347 30244 static void compact_print_str(WriterContext *wctx, const char *key, const char *value)
1348 {
1349 30244 CompactContext *compact = wctx->priv;
1350 AVBPrint buf;
1351
1352
2/2
✓ Branch 0 taken 26427 times.
✓ Branch 1 taken 3817 times.
30244 if (wctx->nb_item[wctx->level]) writer_w8(wctx, compact->item_sep);
1353
2/2
✓ Branch 0 taken 27361 times.
✓ Branch 1 taken 2883 times.
30244 if (!compact->nokey)
1354 27361 writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
1355 30244 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1356 30244 writer_put_str(wctx, compact->escape_str(&buf, value, compact->item_sep, wctx));
1357 30244 av_bprint_finalize(&buf, NULL);
1358 30244 }
1359
1360 29507 static void compact_print_int(WriterContext *wctx, const char *key, int64_t value)
1361 {
1362 29507 CompactContext *compact = wctx->priv;
1363
1364
2/2
✓ Branch 0 taken 24830 times.
✓ Branch 1 taken 4677 times.
29507 if (wctx->nb_item[wctx->level]) writer_w8(wctx, compact->item_sep);
1365
2/2
✓ Branch 0 taken 27673 times.
✓ Branch 1 taken 1834 times.
29507 if (!compact->nokey)
1366 27673 writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
1367 29507 writer_printf(wctx, "%"PRId64, value);
1368 29507 }
1369
1370 static const Writer compact_writer = {
1371 .name = "compact",
1372 .priv_size = sizeof(CompactContext),
1373 .init = compact_init,
1374 .print_section_header = compact_print_section_header,
1375 .print_section_footer = compact_print_section_footer,
1376 .print_integer = compact_print_int,
1377 .print_string = compact_print_str,
1378 .flags = WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS,
1379 .priv_class = &compact_class,
1380 };
1381
1382 /* CSV output */
1383
1384 #undef OFFSET
1385 #define OFFSET(x) offsetof(CompactContext, x)
1386
1387 static const AVOption csv_options[] = {
1388 {"item_sep", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=","}, 0, 0 },
1389 {"s", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=","}, 0, 0 },
1390 {"nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1391 {"nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1392 {"escape", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="csv"}, 0, 0 },
1393 {"e", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="csv"}, 0, 0 },
1394 {"print_section", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1395 {"p", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1396 {NULL},
1397 };
1398
1399 DEFINE_WRITER_CLASS(csv);
1400
1401 static const Writer csv_writer = {
1402 .name = "csv",
1403 .priv_size = sizeof(CompactContext),
1404 .init = compact_init,
1405 .print_section_header = compact_print_section_header,
1406 .print_section_footer = compact_print_section_footer,
1407 .print_integer = compact_print_int,
1408 .print_string = compact_print_str,
1409 .flags = WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS,
1410 .priv_class = &csv_class,
1411 };
1412
1413 /* Flat output */
1414
1415 typedef struct FlatContext {
1416 const AVClass *class;
1417 const char *sep_str;
1418 char sep;
1419 int hierarchical;
1420 } FlatContext;
1421
1422 #undef OFFSET
1423 #define OFFSET(x) offsetof(FlatContext, x)
1424
1425 static const AVOption flat_options[]= {
1426 {"sep_char", "set separator", OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str="."}, 0, 0 },
1427 {"s", "set separator", OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str="."}, 0, 0 },
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 },
1430 {NULL},
1431 };
1432
1433 DEFINE_WRITER_CLASS(flat);
1434
1435 2 static av_cold int flat_init(WriterContext *wctx)
1436 {
1437 2 FlatContext *flat = wctx->priv;
1438
1439
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (strlen(flat->sep_str) != 1) {
1440 av_log(wctx, AV_LOG_ERROR, "Item separator '%s' specified, but must contain a single character\n",
1441 flat->sep_str);
1442 return AVERROR(EINVAL);
1443 }
1444 2 flat->sep = flat->sep_str[0];
1445
1446 2 return 0;
1447 }
1448
1449 374 static const char *flat_escape_key_str(AVBPrint *dst, const char *src, const char sep)
1450 {
1451 const char *p;
1452
1453
2/2
✓ Branch 0 taken 3931 times.
✓ Branch 1 taken 374 times.
4305 for (p = src; *p; p++) {
1454
3/4
✓ Branch 0 taken 3931 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3930 times.
✓ Branch 3 taken 1 times.
3931 if (!((*p >= '0' && *p <= '9') ||
1455
3/4
✓ Branch 0 taken 3535 times.
✓ Branch 1 taken 395 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3535 times.
3930 (*p >= 'a' && *p <= 'z') ||
1456
3/4
✓ Branch 0 taken 395 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 394 times.
✓ Branch 3 taken 1 times.
395 (*p >= 'A' && *p <= 'Z')))
1457 394 av_bprint_chars(dst, '_', 1);
1458 else
1459 3537 av_bprint_chars(dst, *p, 1);
1460 }
1461 374 return dst->str;
1462 }
1463
1464 374 static const char *flat_escape_value_str(AVBPrint *dst, const char *src)
1465 {
1466 const char *p;
1467
1468
2/2
✓ Branch 0 taken 2481 times.
✓ Branch 1 taken 374 times.
2855 for (p = src; *p; p++) {
1469
2/7
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 2479 times.
2481 switch (*p) {
1470 case '\n': av_bprintf(dst, "%s", "\\n"); break;
1471 case '\r': av_bprintf(dst, "%s", "\\r"); break;
1472 case '\\': av_bprintf(dst, "%s", "\\\\"); break;
1473 2 case '"': av_bprintf(dst, "%s", "\\\""); break;
1474 case '`': av_bprintf(dst, "%s", "\\`"); break;
1475 case '$': av_bprintf(dst, "%s", "\\$"); break;
1476 2479 default: av_bprint_chars(dst, *p, 1); break;
1477 }
1478 }
1479 374 return dst->str;
1480 }
1481
1482 48 static void flat_print_section_header(WriterContext *wctx, const void *data)
1483 {
1484 48 FlatContext *flat = wctx->priv;
1485 48 AVBPrint *buf = &wctx->section_pbuf[wctx->level];
1486 48 const struct section *section = wctx->section[wctx->level];
1487 96 const struct section *parent_section = wctx->level ?
1488
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 2 times.
48 wctx->section[wctx->level-1] : NULL;
1489
1490 /* build section header */
1491 48 av_bprint_clear(buf);
1492
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 46 times.
48 if (!parent_section)
1493 2 return;
1494 46 av_bprintf(buf, "%s", wctx->section_pbuf[wctx->level-1].str);
1495
1496
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if (flat->hierarchical ||
1497 !(section->flags & (SECTION_FLAG_IS_ARRAY|SECTION_FLAG_IS_WRAPPER))) {
1498 46 av_bprintf(buf, "%s%s", wctx->section[wctx->level]->name, flat->sep_str);
1499
1500
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 12 times.
46 if (parent_section->flags & SECTION_FLAG_IS_ARRAY) {
1501 68 int n = parent_section->id == SECTION_ID_PACKETS_AND_FRAMES ?
1502
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 6 times.
34 wctx->nb_section_packet_frame : wctx->nb_item[wctx->level-1];
1503 34 av_bprintf(buf, "%d%s", n, flat->sep_str);
1504 }
1505 }
1506 }
1507
1508 314 static void flat_print_int(WriterContext *wctx, const char *key, int64_t value)
1509 {
1510 314 writer_printf(wctx, "%s%s=%"PRId64"\n", wctx->section_pbuf[wctx->level].str, key, value);
1511 314 }
1512
1513 374 static void flat_print_str(WriterContext *wctx, const char *key, const char *value)
1514 {
1515 374 FlatContext *flat = wctx->priv;
1516 AVBPrint buf;
1517
1518 374 writer_put_str(wctx, wctx->section_pbuf[wctx->level].str);
1519 374 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1520 374 writer_printf(wctx, "%s=", flat_escape_key_str(&buf, key, flat->sep));
1521 374 av_bprint_clear(&buf);
1522 374 writer_printf(wctx, "\"%s\"\n", flat_escape_value_str(&buf, value));
1523 374 av_bprint_finalize(&buf, NULL);
1524 374 }
1525
1526 static const Writer flat_writer = {
1527 .name = "flat",
1528 .priv_size = sizeof(FlatContext),
1529 .init = flat_init,
1530 .print_section_header = flat_print_section_header,
1531 .print_integer = flat_print_int,
1532 .print_string = flat_print_str,
1533 .flags = WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS|WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER,
1534 .priv_class = &flat_class,
1535 };
1536
1537 /* INI format output */
1538
1539 typedef struct INIContext {
1540 const AVClass *class;
1541 int hierarchical;
1542 } INIContext;
1543
1544 #undef OFFSET
1545 #define OFFSET(x) offsetof(INIContext, x)
1546
1547 static const AVOption ini_options[] = {
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 },
1550 {NULL},
1551 };
1552
1553 DEFINE_WRITER_CLASS(ini);
1554
1555 724 static char *ini_escape_str(AVBPrint *dst, const char *src)
1556 {
1557 724 int i = 0;
1558 724 char c = 0;
1559
1560
2/2
✓ Branch 0 taken 6141 times.
✓ Branch 1 taken 724 times.
6865 while (c = src[i++]) {
1561
2/7
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 14 times.
✓ Branch 6 taken 6127 times.
6141 switch (c) {
1562 case '\b': av_bprintf(dst, "%s", "\\b"); break;
1563 case '\f': av_bprintf(dst, "%s", "\\f"); break;
1564 case '\n': av_bprintf(dst, "%s", "\\n"); break;
1565 case '\r': av_bprintf(dst, "%s", "\\r"); break;
1566 case '\t': av_bprintf(dst, "%s", "\\t"); break;
1567 14 case '\\':
1568 case '#' :
1569 case '=' :
1570 14 case ':' : av_bprint_chars(dst, '\\', 1);
1571 6141 default:
1572
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6141 times.
6141 if ((unsigned char)c < 32)
1573 av_bprintf(dst, "\\x00%02x", c & 0xff);
1574 else
1575 6141 av_bprint_chars(dst, c, 1);
1576 6141 break;
1577 }
1578 }
1579 724 return dst->str;
1580 }
1581
1582 42 static void ini_print_section_header(WriterContext *wctx, const void *data)
1583 {
1584 42 INIContext *ini = wctx->priv;
1585 42 AVBPrint *buf = &wctx->section_pbuf[wctx->level];
1586 42 const struct section *section = wctx->section[wctx->level];
1587 84 const struct section *parent_section = wctx->level ?
1588
2/2
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 1 times.
42 wctx->section[wctx->level-1] : NULL;
1589
1590 42 av_bprint_clear(buf);
1591
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 41 times.
42 if (!parent_section) {
1592 1 writer_put_str(wctx, "# ffprobe output\n\n");
1593 1 return;
1594 }
1595
1596
2/2
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 3 times.
41 if (wctx->nb_item[wctx->level-1])
1597 38 writer_w8(wctx, '\n');
1598
1599 41 av_bprintf(buf, "%s", wctx->section_pbuf[wctx->level-1].str);
1600
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
41 if (ini->hierarchical ||
1601 !(section->flags & (SECTION_FLAG_IS_ARRAY|SECTION_FLAG_IS_WRAPPER))) {
1602
2/2
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 3 times.
41 av_bprintf(buf, "%s%s", buf->str[0] ? "." : "", wctx->section[wctx->level]->name);
1603
1604
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 10 times.
41 if (parent_section->flags & SECTION_FLAG_IS_ARRAY) {
1605 62 int n = parent_section->id == SECTION_ID_PACKETS_AND_FRAMES ?
1606
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 3 times.
31 wctx->nb_section_packet_frame : wctx->nb_item[wctx->level-1];
1607 31 av_bprintf(buf, ".%d", n);
1608 }
1609 }
1610
1611
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 2 times.
41 if (!(section->flags & (SECTION_FLAG_IS_ARRAY|SECTION_FLAG_IS_WRAPPER)))
1612 39 writer_printf(wctx, "[%s]\n", buf->str);
1613 }
1614
1615 362 static void ini_print_str(WriterContext *wctx, const char *key, const char *value)
1616 {
1617 AVBPrint buf;
1618
1619 362 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1620 362 writer_printf(wctx, "%s=", ini_escape_str(&buf, key));
1621 362 av_bprint_clear(&buf);
1622 362 writer_printf(wctx, "%s\n", ini_escape_str(&buf, value));
1623 362 av_bprint_finalize(&buf, NULL);
1624 362 }
1625
1626 312 static void ini_print_int(WriterContext *wctx, const char *key, int64_t value)
1627 {
1628 312 writer_printf(wctx, "%s=%"PRId64"\n", key, value);
1629 312 }
1630
1631 static const Writer ini_writer = {
1632 .name = "ini",
1633 .priv_size = sizeof(INIContext),
1634 .print_section_header = ini_print_section_header,
1635 .print_integer = ini_print_int,
1636 .print_string = ini_print_str,
1637 .flags = WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS|WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER,
1638 .priv_class = &ini_class,
1639 };
1640
1641 /* JSON output */
1642
1643 typedef struct JSONContext {
1644 const AVClass *class;
1645 int indent_level;
1646 int compact;
1647 const char *item_sep, *item_start_end;
1648 } JSONContext;
1649
1650 #undef OFFSET
1651 #define OFFSET(x) offsetof(JSONContext, x)
1652
1653 static const AVOption json_options[]= {
1654 { "compact", "enable compact output", OFFSET(compact), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1655 { "c", "enable compact output", OFFSET(compact), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1656 { NULL }
1657 };
1658
1659 DEFINE_WRITER_CLASS(json);
1660
1661 4 static av_cold int json_init(WriterContext *wctx)
1662 {
1663 4 JSONContext *json = wctx->priv;
1664
1665
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 json->item_sep = json->compact ? ", " : ",\n";
1666
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 json->item_start_end = json->compact ? " " : "\n";
1667
1668 4 return 0;
1669 }
1670
1671 1062 static const char *json_escape_str(AVBPrint *dst, const char *src, void *log_ctx)
1672 {
1673 static const char json_escape[] = {'"', '\\', '\b', '\f', '\n', '\r', '\t', 0};
1674 static const char json_subst[] = {'"', '\\', 'b', 'f', 'n', 'r', 't', 0};
1675 const char *p;
1676
1677
2/2
✓ Branch 0 taken 8977 times.
✓ Branch 1 taken 1062 times.
10039 for (p = src; *p; p++) {
1678 8977 char *s = strchr(json_escape, *p);
1679
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8975 times.
8977 if (s) {
1680 2 av_bprint_chars(dst, '\\', 1);
1681 2 av_bprint_chars(dst, json_subst[s - json_escape], 1);
1682
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8975 times.
8975 } else if ((unsigned char)*p < 32) {
1683 av_bprintf(dst, "\\u00%02x", *p & 0xff);
1684 } else {
1685 8975 av_bprint_chars(dst, *p, 1);
1686 }
1687 }
1688 1062 return dst->str;
1689 }
1690
1691 #define JSON_INDENT() writer_printf(wctx, "%*c", json->indent_level * 4, ' ')
1692
1693 70 static void json_print_section_header(WriterContext *wctx, const void *data)
1694 {
1695 70 JSONContext *json = wctx->priv;
1696 AVBPrint buf;
1697 70 const struct section *section = wctx->section[wctx->level];
1698 140 const struct section *parent_section = wctx->level ?
1699
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 4 times.
70 wctx->section[wctx->level-1] : NULL;
1700
1701
4/4
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 53 times.
✓ Branch 3 taken 13 times.
70 if (wctx->level && wctx->nb_item[wctx->level-1])
1702 53 writer_put_str(wctx, ",\n");
1703
1704
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 66 times.
70 if (section->flags & SECTION_FLAG_IS_WRAPPER) {
1705 4 writer_put_str(wctx, "{\n");
1706 4 json->indent_level++;
1707 } else {
1708 66 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1709 66 json_escape_str(&buf, section->name, wctx);
1710 66 JSON_INDENT();
1711
1712 66 json->indent_level++;
1713
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 51 times.
66 if (section->flags & SECTION_FLAG_IS_ARRAY) {
1714 15 writer_printf(wctx, "\"%s\": [\n", buf.str);
1715
3/4
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 39 times.
51 } else if (parent_section && !(parent_section->flags & SECTION_FLAG_IS_ARRAY)) {
1716 12 writer_printf(wctx, "\"%s\": {%s", buf.str, json->item_start_end);
1717 } else {
1718 39 writer_printf(wctx, "{%s", json->item_start_end);
1719
1720 /* this is required so the parser can distinguish between packets and frames */
1721
3/4
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
✓ Branch 3 taken 11 times.
39 if (parent_section && parent_section->id == SECTION_ID_PACKETS_AND_FRAMES) {
1722
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 if (!json->compact)
1723 28 JSON_INDENT();
1724 28 writer_printf(wctx, "\"type\": \"%s\"", section->name);
1725 28 wctx->nb_item[wctx->level]++;
1726 }
1727 }
1728 66 av_bprint_finalize(&buf, NULL);
1729 }
1730 70 }
1731
1732 70 static void json_print_section_footer(WriterContext *wctx)
1733 {
1734 70 JSONContext *json = wctx->priv;
1735 70 const struct section *section = wctx->section[wctx->level];
1736
1737
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 66 times.
70 if (wctx->level == 0) {
1738 4 json->indent_level--;
1739 4 writer_put_str(wctx, "\n}\n");
1740
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 51 times.
66 } else if (section->flags & SECTION_FLAG_IS_ARRAY) {
1741 15 writer_w8(wctx, '\n');
1742 15 json->indent_level--;
1743 15 JSON_INDENT();
1744 15 writer_w8(wctx, ']');
1745 } else {
1746 51 writer_put_str(wctx, json->item_start_end);
1747 51 json->indent_level--;
1748
1/2
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
51 if (!json->compact)
1749 51 JSON_INDENT();
1750 51 writer_w8(wctx, '}');
1751 }
1752 70 }
1753
1754 316 static inline void json_print_item_str(WriterContext *wctx,
1755 const char *key, const char *value)
1756 {
1757 AVBPrint buf;
1758
1759 316 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1760 316 writer_printf(wctx, "\"%s\":", json_escape_str(&buf, key, wctx));
1761 316 av_bprint_clear(&buf);
1762 316 writer_printf(wctx, " \"%s\"", json_escape_str(&buf, value, wctx));
1763 316 av_bprint_finalize(&buf, NULL);
1764 316 }
1765
1766 316 static void json_print_str(WriterContext *wctx, const char *key, const char *value)
1767 {
1768 316 JSONContext *json = wctx->priv;
1769 632 const struct section *parent_section = wctx->level ?
1770
1/2
✓ Branch 0 taken 316 times.
✗ Branch 1 not taken.
316 wctx->section[wctx->level-1] : NULL;
1771
1772
4/6
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 307 times.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
316 if (wctx->nb_item[wctx->level] || (parent_section && parent_section->id == SECTION_ID_PACKETS_AND_FRAMES))
1773 307 writer_put_str(wctx, json->item_sep);
1774
1/2
✓ Branch 0 taken 316 times.
✗ Branch 1 not taken.
316 if (!json->compact)
1775 316 JSON_INDENT();
1776 316 json_print_item_str(wctx, key, value);
1777 316 }
1778
1779 364 static void json_print_int(WriterContext *wctx, const char *key, int64_t value)
1780 {
1781 364 JSONContext *json = wctx->priv;
1782 728 const struct section *parent_section = wctx->level ?
1783
1/2
✓ Branch 0 taken 364 times.
✗ Branch 1 not taken.
364 wctx->section[wctx->level-1] : NULL;
1784 AVBPrint buf;
1785
1786
4/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 352 times.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 12 times.
364 if (wctx->nb_item[wctx->level] || (parent_section && parent_section->id == SECTION_ID_PACKETS_AND_FRAMES))
1787 352 writer_put_str(wctx, json->item_sep);
1788
1/2
✓ Branch 0 taken 364 times.
✗ Branch 1 not taken.
364 if (!json->compact)
1789 364 JSON_INDENT();
1790
1791 364 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1792 364 writer_printf(wctx, "\"%s\": %"PRId64, json_escape_str(&buf, key, wctx), value);
1793 364 av_bprint_finalize(&buf, NULL);
1794 364 }
1795
1796 static const Writer json_writer = {
1797 .name = "json",
1798 .priv_size = sizeof(JSONContext),
1799 .init = json_init,
1800 .print_section_header = json_print_section_header,
1801 .print_section_footer = json_print_section_footer,
1802 .print_integer = json_print_int,
1803 .print_string = json_print_str,
1804 .flags = WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER,
1805 .priv_class = &json_class,
1806 };
1807
1808 /* XML output */
1809
1810 typedef struct XMLContext {
1811 const AVClass *class;
1812 int within_tag;
1813 int indent_level;
1814 int fully_qualified;
1815 int xsd_strict;
1816 } XMLContext;
1817
1818 #undef OFFSET
1819 #define OFFSET(x) offsetof(XMLContext, x)
1820
1821 static const AVOption xml_options[] = {
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 },
1825 {"x", "ensure that the output is XSD compliant", OFFSET(xsd_strict), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1826 {NULL},
1827 };
1828
1829 DEFINE_WRITER_CLASS(xml);
1830
1831 2 static av_cold int xml_init(WriterContext *wctx)
1832 {
1833 2 XMLContext *xml = wctx->priv;
1834
1835
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (xml->xsd_strict) {
1836 1 xml->fully_qualified = 1;
1837 #define CHECK_COMPLIANCE(opt, opt_name) \
1838 if (opt) { \
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); \
1843 }
1844
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 CHECK_COMPLIANCE(show_private_data, "private");
1845
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 CHECK_COMPLIANCE(show_value_unit, "unit");
1846
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 CHECK_COMPLIANCE(use_value_prefix, "prefix");
1847 }
1848
1849 2 return 0;
1850 }
1851
1852 #define XML_INDENT() writer_printf(wctx, "%*c", xml->indent_level * 4, ' ')
1853
1854 84 static void xml_print_section_header(WriterContext *wctx, const void *data)
1855 {
1856 84 XMLContext *xml = wctx->priv;
1857 84 const struct section *section = wctx->section[wctx->level];
1858 168 const struct section *parent_section = wctx->level ?
1859
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 2 times.
84 wctx->section[wctx->level-1] : NULL;
1860
1861
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 82 times.
84 if (wctx->level == 0) {
1862 2 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\"";
1865
1866 2 writer_put_str(wctx, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1867
4/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 writer_printf(wctx, "<%sffprobe%s>\n",
1868 xml->fully_qualified ? "ffprobe:" : "",
1869 xml->fully_qualified ? qual : "");
1870 2 return;
1871 }
1872
1873
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 74 times.
82 if (xml->within_tag) {
1874 8 xml->within_tag = 0;
1875 8 writer_put_str(wctx, ">\n");
1876 }
1877
1878
3/4
✓ Branch 0 taken 82 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 76 times.
82 if (parent_section && (parent_section->flags & SECTION_FLAG_IS_WRAPPER) &&
1879
3/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 2 times.
6 wctx->level && wctx->nb_item[wctx->level-1])
1880 4 writer_w8(wctx, '\n');
1881 82 xml->indent_level++;
1882
1883
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 70 times.
82 if (section->flags & (SECTION_FLAG_IS_ARRAY|SECTION_FLAG_HAS_VARIABLE_FIELDS)) {
1884 12 XML_INDENT(); writer_printf(wctx, "<%s", section->name);
1885
1886
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (section->flags & SECTION_FLAG_HAS_TYPE) {
1887 AVBPrint buf;
1888 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1889 av_bprint_escape(&buf, section->get_type(data), NULL,
1890 AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
1891 writer_printf(wctx, " type=\"%s\"", buf.str);
1892 }
1893 12 writer_printf(wctx, ">\n", section->name);
1894 } else {
1895 70 XML_INDENT(); writer_printf(wctx, "<%s ", section->name);
1896 70 xml->within_tag = 1;
1897 }
1898 }
1899
1900 84 static void xml_print_section_footer(WriterContext *wctx)
1901 {
1902 84 XMLContext *xml = wctx->priv;
1903 84 const struct section *section = wctx->section[wctx->level];
1904
1905
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 82 times.
84 if (wctx->level == 0) {
1906
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 writer_printf(wctx, "</%sffprobe>\n", xml->fully_qualified ? "ffprobe:" : "");
1907
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 20 times.
82 } else if (xml->within_tag) {
1908 62 xml->within_tag = 0;
1909 62 writer_put_str(wctx, "/>\n");
1910 62 xml->indent_level--;
1911 } else {
1912 20 XML_INDENT(); writer_printf(wctx, "</%s>\n", section->name);
1913 20 xml->indent_level--;
1914 }
1915 84 }
1916
1917 1184 static void xml_print_value(WriterContext *wctx, const char *key,
1918 const char *str, int64_t num, const int is_int)
1919 {
1920 AVBPrint buf;
1921 1184 XMLContext *xml = wctx->priv;
1922 1184 const struct section *section = wctx->section[wctx->level];
1923
1924 1184 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1925
1926
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 1166 times.
1184 if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) {
1927 18 xml->indent_level++;
1928 18 XML_INDENT();
1929 18 av_bprint_escape(&buf, key, NULL,
1930 AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
1931 18 writer_printf(wctx, "<%s key=\"%s\"",
1932 section->element_name, buf.str);
1933 18 av_bprint_clear(&buf);
1934
1935
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (is_int) {
1936 writer_printf(wctx, " value=\"%"PRId64"\"/>\n", num);
1937 } else {
1938 18 av_bprint_escape(&buf, str, NULL,
1939 AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
1940 18 writer_printf(wctx, " value=\"%s\"/>\n", buf.str);
1941 }
1942 18 xml->indent_level--;
1943 } else {
1944
2/2
✓ Branch 0 taken 1096 times.
✓ Branch 1 taken 70 times.
1166 if (wctx->nb_item[wctx->level])
1945 1096 writer_w8(wctx, ' ');
1946
1947
2/2
✓ Branch 0 taken 624 times.
✓ Branch 1 taken 542 times.
1166 if (is_int) {
1948 624 writer_printf(wctx, "%s=\"%"PRId64"\"", key, num);
1949 } else {
1950 542 av_bprint_escape(&buf, str, NULL,
1951 AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
1952 542 writer_printf(wctx, "%s=\"%s\"", key, buf.str);
1953 }
1954 }
1955
1956 1184 av_bprint_finalize(&buf, NULL);
1957 1184 }
1958
1959 560 static inline void xml_print_str(WriterContext *wctx, const char *key, const char *value) {
1960 560 xml_print_value(wctx, key, value, 0, 0);
1961 560 }
1962
1963 624 static void xml_print_int(WriterContext *wctx, const char *key, int64_t value)
1964 {
1965 624 xml_print_value(wctx, key, NULL, value, 1);
1966 624 }
1967
1968 static Writer xml_writer = {
1969 .name = "xml",
1970 .priv_size = sizeof(XMLContext),
1971 .init = xml_init,
1972 .print_section_header = xml_print_section_header,
1973 .print_section_footer = xml_print_section_footer,
1974 .print_integer = xml_print_int,
1975 .print_string = xml_print_str,
1976 .flags = WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER,
1977 .priv_class = &xml_class,
1978 };
1979
1980 152 static void writer_register_all(void)
1981 {
1982 static int initialized;
1983
1984
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
152 if (initialized)
1985 return;
1986 152 initialized = 1;
1987
1988 152 writer_register(&default_writer);
1989 152 writer_register(&compact_writer);
1990 152 writer_register(&csv_writer);
1991 152 writer_register(&flat_writer);
1992 152 writer_register(&ini_writer);
1993 152 writer_register(&json_writer);
1994 152 writer_register(&xml_writer);
1995 }
1996
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); \
2001 } while (0)
2002
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__); \
2010 } \
2011 } \
2012 writer_print_string(w, k, pbuf.str, 0); \
2013 } while (0)
2014
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; \
2026 uv.val.i = v; \
2027 uv.unit = u; \
2028 writer_print_string(w, k, value_string(val_str, sizeof(val_str), uv), 0); \
2029 } while (0)
2030
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)
2034
2035 #define REALLOCZ_ARRAY_STREAM(ptr, cur_n, new_n) \
2036 { \
2037 ret = av_reallocp_array(&(ptr), (new_n), sizeof(*(ptr))); \
2038 if (ret < 0) \
2039 goto end; \
2040 memset( (ptr) + (cur_n), 0, ((new_n) - (cur_n)) * sizeof(*(ptr)) ); \
2041 }
2042
2043 1399 static inline int show_tags(WriterContext *w, AVDictionary *tags, int section_id)
2044 {
2045 1399 const AVDictionaryEntry *tag = NULL;
2046 1399 int ret = 0;
2047
2048
2/2
✓ Branch 0 taken 693 times.
✓ Branch 1 taken 706 times.
1399 if (!tags)
2049 693 return 0;
2050 706 writer_print_section_header(w, NULL, section_id);
2051
2052
2/2
✓ Branch 1 taken 2944 times.
✓ Branch 2 taken 706 times.
3650 while ((tag = av_dict_iterate(tags, tag))) {
2053
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2944 times.
2944 if ((ret = print_str_validate(tag->key, tag->value)) < 0)
2054 break;
2055 }
2056 706 writer_print_section_footer(w);
2057
2058 706 return ret;
2059 }
2060
2061 2 static void print_dovi_metadata(WriterContext *w, const AVDOVIMetadata *dovi)
2062 {
2063
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!dovi)
2064 return;
2065
2066 {
2067 2 const AVDOVIRpuDataHeader *hdr = av_dovi_get_header(dovi);
2068 2 const AVDOVIDataMapping *mapping = av_dovi_get_mapping(dovi);
2069 2 const AVDOVIColorMetadata *color = av_dovi_get_color(dovi);
2070 AVBPrint pbuf;
2071
2072 2 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2073
2074 // header
2075 2 print_int("rpu_type", hdr->rpu_type);
2076 2 print_int("rpu_format", hdr->rpu_format);
2077 2 print_int("vdr_rpu_profile", hdr->vdr_rpu_profile);
2078 2 print_int("vdr_rpu_level", hdr->vdr_rpu_level);
2079 2 print_int("chroma_resampling_explicit_filter_flag",
2080 hdr->chroma_resampling_explicit_filter_flag);
2081 2 print_int("coef_data_type", hdr->coef_data_type);
2082 2 print_int("coef_log2_denom", hdr->coef_log2_denom);
2083 2 print_int("vdr_rpu_normalized_idc", hdr->vdr_rpu_normalized_idc);
2084 2 print_int("bl_video_full_range_flag", hdr->bl_video_full_range_flag);
2085 2 print_int("bl_bit_depth", hdr->bl_bit_depth);
2086 2 print_int("el_bit_depth", hdr->el_bit_depth);
2087 2 print_int("vdr_bit_depth", hdr->vdr_bit_depth);
2088 2 print_int("spatial_resampling_filter_flag",
2089 hdr->spatial_resampling_filter_flag);
2090 2 print_int("el_spatial_resampling_filter_flag",
2091 hdr->el_spatial_resampling_filter_flag);
2092 2 print_int("disable_residual_flag", hdr->disable_residual_flag);
2093
2094 // data mapping values
2095 2 print_int("vdr_rpu_id", mapping->vdr_rpu_id);
2096 2 print_int("mapping_color_space", mapping->mapping_color_space);
2097 2 print_int("mapping_chroma_format_idc",
2098 mapping->mapping_chroma_format_idc);
2099
2100 2 print_int("nlq_method_idc", mapping->nlq_method_idc);
2101
1/3
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
2 switch (mapping->nlq_method_idc) {
2102 2 case AV_DOVI_NLQ_NONE:
2103 2 print_str("nlq_method_idc_name", "none");
2104 2 break;
2105 case AV_DOVI_NLQ_LINEAR_DZ:
2106 print_str("nlq_method_idc_name", "linear_dz");
2107 break;
2108 default:
2109 print_str("nlq_method_idc_name", "unknown");
2110 break;
2111 }
2112
2113 2 print_int("num_x_partitions", mapping->num_x_partitions);
2114 2 print_int("num_y_partitions", mapping->num_y_partitions);
2115
2116 2 writer_print_section_header(w, NULL, SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST);
2117
2118
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 for (int c = 0; c < 3; c++) {
2119 6 const AVDOVIReshapingCurve *curve = &mapping->curves[c];
2120 6 writer_print_section_header(w, "Reshaping curve", SECTION_ID_FRAME_SIDE_DATA_COMPONENT);
2121
2122
7/8
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 26 times.
✓ Branch 8 taken 26 times.
✓ Branch 9 taken 26 times.
✓ Branch 10 taken 6 times.
58 print_list_fmt("pivots", "%"PRIu16, curve->num_pivots, 1, curve->pivots[idx]);
2123
2124 6 writer_print_section_header(w, NULL, SECTION_ID_FRAME_SIDE_DATA_PIECE_LIST);
2125
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 6 times.
26 for (int i = 0; i < curve->num_pivots - 1; i++) {
2126 AVBPrint piece_buf;
2127
2128 20 av_bprint_init(&piece_buf, 0, AV_BPRINT_SIZE_AUTOMATIC);
2129
2/3
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
20 switch (curve->mapping_idc[i]) {
2130 16 case AV_DOVI_MAPPING_POLYNOMIAL:
2131 16 av_bprintf(&piece_buf, "Polynomial");
2132 16 break;
2133 4 case AV_DOVI_MAPPING_MMR:
2134 4 av_bprintf(&piece_buf, "MMR");
2135 4 break;
2136 default:
2137 av_bprintf(&piece_buf, "Unknown");
2138 break;
2139 }
2140 20 av_bprintf(&piece_buf, " mapping");
2141
2142 20 writer_print_section_header(w, piece_buf.str, SECTION_ID_FRAME_SIDE_DATA_PIECE);
2143 20 print_int("mapping_idc", curve->mapping_idc[i]);
2144
2/3
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
20 switch (curve->mapping_idc[i]) {
2145 16 case AV_DOVI_MAPPING_POLYNOMIAL:
2146 16 print_str("mapping_idc_name", "polynomial");
2147 16 print_int("poly_order", curve->poly_order[i]);
2148
7/8
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✓ Branch 7 taken 48 times.
✓ Branch 8 taken 48 times.
✓ Branch 9 taken 48 times.
✓ Branch 10 taken 16 times.
112 print_list_fmt("poly_coef", "%"PRIi64,
2149 curve->poly_order[i] + 1, 1,
2150 curve->poly_coef[i][idx]);
2151 16 break;
2152 4 case AV_DOVI_MAPPING_MMR:
2153 4 print_str("mapping_idc_name", "mmr");
2154 4 print_int("mmr_order", curve->mmr_order[i]);
2155 4 print_int("mmr_constant", curve->mmr_constant[i]);
2156
8/8
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 56 times.
✓ Branch 3 taken 24 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 84 times.
✓ Branch 8 taken 12 times.
✓ Branch 9 taken 12 times.
✓ Branch 10 taken 4 times.
100 print_list_fmt("mmr_coef", "%"PRIi64,
2157 curve->mmr_order[i], 7,
2158 curve->mmr_coef[i][idx][idx2]);
2159 4 break;
2160 default:
2161 print_str("mapping_idc_name", "unknown");
2162 break;
2163 }
2164
2165 // SECTION_ID_FRAME_SIDE_DATA_PIECE
2166 20 writer_print_section_footer(w);
2167 }
2168
2169 // SECTION_ID_FRAME_SIDE_DATA_PIECE_LIST
2170 6 writer_print_section_footer(w);
2171
2172
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (mapping->nlq_method_idc != AV_DOVI_NLQ_NONE) {
2173 const AVDOVINLQParams *nlq = &mapping->nlq[c];
2174 print_int("nlq_offset", nlq->nlq_offset);
2175 print_int("vdr_in_max", nlq->vdr_in_max);
2176
2177 switch (mapping->nlq_method_idc) {
2178 case AV_DOVI_NLQ_LINEAR_DZ:
2179 print_int("linear_deadzone_slope", nlq->linear_deadzone_slope);
2180 print_int("linear_deadzone_threshold", nlq->linear_deadzone_threshold);
2181 break;
2182 }
2183 }
2184
2185 // SECTION_ID_FRAME_SIDE_DATA_COMPONENT
2186 6 writer_print_section_footer(w);
2187 }
2188
2189 // SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST
2190 2 writer_print_section_footer(w);
2191
2192 // color metadata
2193 2 print_int("dm_metadata_id", color->dm_metadata_id);
2194 2 print_int("scene_refresh_flag", color->scene_refresh_flag);
2195
7/8
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 18 times.
✓ Branch 8 taken 18 times.
✓ Branch 9 taken 18 times.
✓ Branch 10 taken 2 times.
38 print_list_fmt("ycc_to_rgb_matrix", "%d/%d",
2196 FF_ARRAY_ELEMS(color->ycc_to_rgb_matrix), 1,
2197 color->ycc_to_rgb_matrix[idx].num,
2198 color->ycc_to_rgb_matrix[idx].den);
2199
7/8
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 6 times.
✓ Branch 8 taken 6 times.
✓ Branch 9 taken 6 times.
✓ Branch 10 taken 2 times.
14 print_list_fmt("ycc_to_rgb_offset", "%d/%d",
2200 FF_ARRAY_ELEMS(color->ycc_to_rgb_offset), 1,
2201 color->ycc_to_rgb_offset[idx].num,
2202 color->ycc_to_rgb_offset[idx].den);
2203
7/8
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 18 times.
✓ Branch 8 taken 18 times.
✓ Branch 9 taken 18 times.
✓ Branch 10 taken 2 times.
38 print_list_fmt("rgb_to_lms_matrix", "%d/%d",
2204 FF_ARRAY_ELEMS(color->rgb_to_lms_matrix), 1,
2205 color->rgb_to_lms_matrix[idx].num,
2206 color->rgb_to_lms_matrix[idx].den);
2207 2 print_int("signal_eotf", color->signal_eotf);
2208 2 print_int("signal_eotf_param0", color->signal_eotf_param0);
2209 2 print_int("signal_eotf_param1", color->signal_eotf_param1);
2210 2 print_int("signal_eotf_param2", color->signal_eotf_param2);
2211 2 print_int("signal_bit_depth", color->signal_bit_depth);
2212 2 print_int("signal_color_space", color->signal_color_space);
2213 2 print_int("signal_chroma_format", color->signal_chroma_format);
2214 2 print_int("signal_full_range_flag", color->signal_full_range_flag);
2215 2 print_int("source_min_pq", color->source_min_pq);
2216 2 print_int("source_max_pq", color->source_max_pq);
2217 2 print_int("source_diagonal", color->source_diagonal);
2218
2219 2 av_bprint_finalize(&pbuf, NULL);
2220 }
2221 }
2222
2223 3 static void print_dynamic_hdr10_plus(WriterContext *w, const AVDynamicHDRPlus *metadata)
2224 {
2225
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!metadata)
2226 return;
2227 3 print_int("application version", metadata->application_version);
2228 3 print_int("num_windows", metadata->num_windows);
2229
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 for (int n = 1; n < metadata->num_windows; n++) {
2230 const AVHDRPlusColorTransformParams *params = &metadata->params[n];
2231 print_q("window_upper_left_corner_x",
2232 params->window_upper_left_corner_x,'/');
2233 print_q("window_upper_left_corner_y",
2234 params->window_upper_left_corner_y,'/');
2235 print_q("window_lower_right_corner_x",
2236 params->window_lower_right_corner_x,'/');
2237 print_q("window_lower_right_corner_y",
2238 params->window_lower_right_corner_y,'/');
2239 print_q("window_upper_left_corner_x",
2240 params->window_upper_left_corner_x,'/');
2241 print_q("window_upper_left_corner_y",
2242 params->window_upper_left_corner_y,'/');
2243 print_int("center_of_ellipse_x",
2244 params->center_of_ellipse_x ) ;
2245 print_int("center_of_ellipse_y",
2246 params->center_of_ellipse_y );
2247 print_int("rotation_angle",
2248 params->rotation_angle);
2249 print_int("semimajor_axis_internal_ellipse",
2250 params->semimajor_axis_internal_ellipse);
2251 print_int("semimajor_axis_external_ellipse",
2252 params->semimajor_axis_external_ellipse);
2253 print_int("semiminor_axis_external_ellipse",
2254 params->semiminor_axis_external_ellipse);
2255 print_int("overlap_process_option",
2256 params->overlap_process_option);
2257 }
2258 3 print_q("targeted_system_display_maximum_luminance",
2259 metadata->targeted_system_display_maximum_luminance,'/');
2260
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (metadata->targeted_system_display_actual_peak_luminance_flag) {
2261 print_int("num_rows_targeted_system_display_actual_peak_luminance",
2262 metadata->num_rows_targeted_system_display_actual_peak_luminance);
2263 print_int("num_cols_targeted_system_display_actual_peak_luminance",
2264 metadata->num_cols_targeted_system_display_actual_peak_luminance);
2265 for (int i = 0; i < metadata->num_rows_targeted_system_display_actual_peak_luminance; i++) {
2266 for (int j = 0; j < metadata->num_cols_targeted_system_display_actual_peak_luminance; j++) {
2267 print_q("targeted_system_display_actual_peak_luminance",
2268 metadata->targeted_system_display_actual_peak_luminance[i][j],'/');
2269 }
2270 }
2271 }
2272
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 for (int n = 0; n < metadata->num_windows; n++) {
2273 3 const AVHDRPlusColorTransformParams *params = &metadata->params[n];
2274
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
12 for (int i = 0; i < 3; i++) {
2275 9 print_q("maxscl",params->maxscl[i],'/');
2276 }
2277 3 print_q("average_maxrgb",
2278 params->average_maxrgb,'/');
2279 3 print_int("num_distribution_maxrgb_percentiles",
2280 params->num_distribution_maxrgb_percentiles);
2281
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 3 times.
30 for (int i = 0; i < params->num_distribution_maxrgb_percentiles; i++) {
2282 27 print_int("distribution_maxrgb_percentage",
2283 params->distribution_maxrgb[i].percentage);
2284 27 print_q("distribution_maxrgb_percentile",
2285 params->distribution_maxrgb[i].percentile,'/');
2286 }
2287 3 print_q("fraction_bright_pixels",
2288 params->fraction_bright_pixels,'/');
2289 }
2290
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (metadata->mastering_display_actual_peak_luminance_flag) {
2291 print_int("num_rows_mastering_display_actual_peak_luminance",
2292 metadata->num_rows_mastering_display_actual_peak_luminance);
2293 print_int("num_cols_mastering_display_actual_peak_luminance",
2294 metadata->num_cols_mastering_display_actual_peak_luminance);
2295 for (int i = 0; i < metadata->num_rows_mastering_display_actual_peak_luminance; i++) {
2296 for (int j = 0; j < metadata->num_cols_mastering_display_actual_peak_luminance; j++) {
2297 print_q("mastering_display_actual_peak_luminance",
2298 metadata->mastering_display_actual_peak_luminance[i][j],'/');
2299 }
2300 }
2301 }
2302
2303
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 for (int n = 0; n < metadata->num_windows; n++) {
2304 3 const AVHDRPlusColorTransformParams *params = &metadata->params[n];
2305
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (params->tone_mapping_flag) {
2306 3 print_q("knee_point_x", params->knee_point_x,'/');
2307 3 print_q("knee_point_y", params->knee_point_y,'/');
2308 3 print_int("num_bezier_curve_anchors",
2309 params->num_bezier_curve_anchors );
2310
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 3 times.
30 for (int i = 0; i < params->num_bezier_curve_anchors; i++) {
2311 27 print_q("bezier_curve_anchors",
2312 params->bezier_curve_anchors[i],'/');
2313 }
2314 }
2315
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (params->color_saturation_mapping_flag) {
2316 print_q("color_saturation_weight",
2317 params->color_saturation_weight,'/');
2318 }
2319 }
2320 }
2321
2322 1 static void print_dynamic_hdr_vivid(WriterContext *w, const AVDynamicHDRVivid *metadata)
2323 {
2324
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!metadata)
2325 return;
2326 1 print_int("system_start_code", metadata->system_start_code);
2327 1 print_int("num_windows", metadata->num_windows);
2328
2329
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 for (int n = 0; n < metadata->num_windows; n++) {
2330 1 const AVHDRVividColorTransformParams *params = &metadata->params[n];
2331
2332 1 print_q("minimum_maxrgb", params->minimum_maxrgb, '/');
2333 1 print_q("average_maxrgb", params->average_maxrgb, '/');
2334 1 print_q("variance_maxrgb", params->variance_maxrgb, '/');
2335 1 print_q("maximum_maxrgb", params->maximum_maxrgb, '/');
2336 }
2337
2338
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 for (int n = 0; n < metadata->num_windows; n++) {
2339 1 const AVHDRVividColorTransformParams *params = &metadata->params[n];
2340
2341 1 print_int("tone_mapping_mode_flag", params->tone_mapping_mode_flag);
2342
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (params->tone_mapping_mode_flag) {
2343 1 print_int("tone_mapping_param_num", params->tone_mapping_param_num);
2344
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 for (int i = 0; i < params->tone_mapping_param_num; i++) {
2345 2 const AVHDRVividColorToneMappingParams *tm_params = &params->tm_params[i];
2346
2347 2 print_q("targeted_system_display_maximum_luminance",
2348 tm_params->targeted_system_display_maximum_luminance, '/');
2349 2 print_int("base_enable_flag", tm_params->base_enable_flag);
2350
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (tm_params->base_enable_flag) {
2351 2 print_q("base_param_m_p", tm_params->base_param_m_p, '/');
2352 2 print_q("base_param_m_m", tm_params->base_param_m_m, '/');
2353 2 print_q("base_param_m_a", tm_params->base_param_m_a, '/');
2354 2 print_q("base_param_m_b", tm_params->base_param_m_b, '/');
2355 2 print_q("base_param_m_n", tm_params->base_param_m_n, '/');
2356
2357 2 print_int("base_param_k1", tm_params->base_param_k1);
2358 2 print_int("base_param_k2", tm_params->base_param_k2);
2359 2 print_int("base_param_k3", tm_params->base_param_k3);
2360 2 print_int("base_param_Delta_enable_mode",
2361 tm_params->base_param_Delta_enable_mode);
2362 2 print_q("base_param_Delta", tm_params->base_param_Delta, '/');
2363 }
2364 2 print_int("3Spline_enable_flag", tm_params->three_Spline_enable_flag);
2365
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (tm_params->three_Spline_enable_flag) {
2366 2 print_int("3Spline_num", tm_params->three_Spline_num);
2367
2368
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 for (int j = 0; j < tm_params->three_Spline_num; j++) {
2369 2 const AVHDRVivid3SplineParams *three_spline = &tm_params->three_spline[j];
2370 2 print_int("3Spline_TH_mode", three_spline->th_mode);
2371
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 if (three_spline->th_mode == 0 || three_spline->th_mode == 2)
2372 2 print_q("3Spline_TH_enable_MB", three_spline->th_enable_mb, '/');
2373 2 print_q("3Spline_TH_enable", three_spline->th_enable, '/');
2374 2 print_q("3Spline_TH_Delta1", three_spline->th_delta1, '/');
2375 2 print_q("3Spline_TH_Delta2", three_spline->th_delta2, '/');
2376 2 print_q("3Spline_enable_Strength", three_spline->enable_strength, '/');
2377 }
2378 }
2379 }
2380 }
2381
2382 1 print_int("color_saturation_mapping_flag", params->color_saturation_mapping_flag);
2383
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (params->color_saturation_mapping_flag) {
2384 1 print_int("color_saturation_num", params->color_saturation_num);
2385
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 for (int i = 0; i < params->color_saturation_num; i++) {
2386 2 print_q("color_saturation_gain", params->color_saturation_gain[i], '/');
2387 }
2388 }
2389 }
2390 }
2391
2392 4 static void print_ambient_viewing_environment(WriterContext *w,
2393 const AVAmbientViewingEnvironment *env)
2394 {
2395
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!env)
2396 return;
2397
2398 4 print_q("ambient_illuminance", env->ambient_illuminance, '/');
2399 4 print_q("ambient_light_x", env->ambient_light_x, '/');
2400 4 print_q("ambient_light_y", env->ambient_light_y, '/');
2401 }
2402
2403 static void print_film_grain_params(WriterContext *w,
2404 const AVFilmGrainParams *fgp)
2405 {
2406 const char *color_range, *color_primaries, *color_trc, *color_space;
2407 const char *const film_grain_type_names[] = {
2408 [AV_FILM_GRAIN_PARAMS_NONE] = "none",
2409 [AV_FILM_GRAIN_PARAMS_AV1] = "av1",
2410 [AV_FILM_GRAIN_PARAMS_H274] = "h274",
2411 };
2412
2413 AVBPrint pbuf;
2414 if (!fgp || fgp->type >= FF_ARRAY_ELEMS(film_grain_type_names))
2415 return;
2416
2417 color_range = av_color_range_name(fgp->color_range);
2418 color_primaries = av_color_primaries_name(fgp->color_primaries);
2419 color_trc = av_color_transfer_name(fgp->color_trc);
2420 color_space = av_color_space_name(fgp->color_space);
2421
2422 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2423 print_str("type", film_grain_type_names[fgp->type]);
2424 print_fmt("seed", "%"PRIu64, fgp->seed);
2425 print_int("width", fgp->width);
2426 print_int("height", fgp->height);
2427 print_int("subsampling_x", fgp->subsampling_x);
2428 print_int("subsampling_y", fgp->subsampling_y);
2429 print_str("color_range", color_range ? color_range : "unknown");
2430 print_str("color_primaries", color_primaries ? color_primaries : "unknown");
2431 print_str("color_trc", color_trc ? color_trc : "unknown");
2432 print_str("color_space", color_space ? color_space : "unknown");
2433
2434 switch (fgp->type) {
2435 case AV_FILM_GRAIN_PARAMS_NONE:
2436 break;
2437 case AV_FILM_GRAIN_PARAMS_AV1: {
2438 const AVFilmGrainAOMParams *aom = &fgp->codec.aom;
2439 const int num_ar_coeffs_y = 2 * aom->ar_coeff_lag * (aom->ar_coeff_lag + 1);
2440 const int num_ar_coeffs_uv = num_ar_coeffs_y + !!aom->num_y_points;
2441 print_int("chroma_scaling_from_luma", aom->chroma_scaling_from_luma);
2442 print_int("scaling_shift", aom->scaling_shift);
2443 print_int("ar_coeff_lag", aom->ar_coeff_lag);
2444 print_int("ar_coeff_shift", aom->ar_coeff_shift);
2445 print_int("grain_scale_shift", aom->grain_scale_shift);
2446 print_int("overlap_flag", aom->overlap_flag);
2447 print_int("limit_output_range", aom->limit_output_range);
2448
2449 writer_print_section_header(w, NULL, SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST);
2450
2451 if (aom->num_y_points) {
2452 writer_print_section_header(w, NULL, SECTION_ID_FRAME_SIDE_DATA_COMPONENT);
2453
2454 print_int("bit_depth_luma", fgp->bit_depth_luma);
2455 print_list_fmt("y_points_value", "%"PRIu8, aom->num_y_points, 1, aom->y_points[idx][0]);
2456 print_list_fmt("y_points_scaling", "%"PRIu8, aom->num_y_points, 1, aom->y_points[idx][1]);
2457 print_list_fmt("ar_coeffs_y", "%"PRId8, num_ar_coeffs_y, 1, aom->ar_coeffs_y[idx]);
2458
2459 // SECTION_ID_FRAME_SIDE_DATA_COMPONENT
2460 writer_print_section_footer(w);
2461 }
2462
2463 for (int uv = 0; uv < 2; uv++) {
2464 if (!aom->num_uv_points[uv] && !aom->chroma_scaling_from_luma)
2465 continue;
2466
2467 writer_print_section_header(w, NULL, SECTION_ID_FRAME_SIDE_DATA_COMPONENT);
2468
2469 print_int("bit_depth_chroma", fgp->bit_depth_chroma);
2470 print_list_fmt("uv_points_value", "%"PRIu8, aom->num_uv_points[uv], 1, aom->uv_points[uv][idx][0]);
2471 print_list_fmt("uv_points_scaling", "%"PRIu8, aom->num_uv_points[uv], 1, aom->uv_points[uv][idx][1]);
2472 print_list_fmt("ar_coeffs_uv", "%"PRId8, num_ar_coeffs_uv, 1, aom->ar_coeffs_uv[uv][idx]);
2473 print_int("uv_mult", aom->uv_mult[uv]);
2474 print_int("uv_mult_luma", aom->uv_mult_luma[uv]);
2475 print_int("uv_offset", aom->uv_offset[uv]);
2476
2477 // SECTION_ID_FRAME_SIDE_DATA_COMPONENT
2478 writer_print_section_footer(w);
2479 }
2480
2481 // SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST
2482 writer_print_section_footer(w);
2483 break;
2484 }
2485 case AV_FILM_GRAIN_PARAMS_H274: {
2486 const AVFilmGrainH274Params *h274 = &fgp->codec.h274;
2487 print_int("model_id", h274->model_id);
2488 print_int("blending_mode_id", h274->blending_mode_id);
2489 print_int("log2_scale_factor", h274->log2_scale_factor);
2490
2491 writer_print_section_header(w, NULL, SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST);
2492
2493 for (int c = 0; c < 3; c++) {
2494 if (!h274->component_model_present[c])
2495 continue;
2496
2497 writer_print_section_header(w, NULL, SECTION_ID_FRAME_SIDE_DATA_COMPONENT);
2498 print_int(c ? "bit_depth_chroma" : "bit_depth_luma", c ? fgp->bit_depth_chroma : fgp->bit_depth_luma);
2499
2500 writer_print_section_header(w, NULL, SECTION_ID_FRAME_SIDE_DATA_PIECE_LIST);
2501 for (int i = 0; i < h274->num_intensity_intervals[c]; i++) {
2502
2503 writer_print_section_header(w, NULL, SECTION_ID_FRAME_SIDE_DATA_PIECE);
2504 print_int("intensity_interval_lower_bound", h274->intensity_interval_lower_bound[c][i]);
2505 print_int("intensity_interval_upper_bound", h274->intensity_interval_upper_bound[c][i]);
2506 print_list_fmt("comp_model_value", "%"PRId16, h274->num_model_values[c], 1, h274->comp_model_value[c][i][idx]);
2507
2508 // SECTION_ID_FRAME_SIDE_DATA_PIECE
2509 writer_print_section_footer(w);
2510 }
2511
2512 // SECTION_ID_FRAME_SIDE_DATA_PIECE_LIST
2513 writer_print_section_footer(w);
2514
2515 // SECTION_ID_FRAME_SIDE_DATA_COMPONENT
2516 writer_print_section_footer(w);
2517 }
2518
2519 // SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST
2520 writer_print_section_footer(w);
2521 break;
2522 }
2523 }
2524
2525 av_bprint_finalize(&pbuf, NULL);
2526 }
2527
2528 884 static void print_pkt_side_data(WriterContext *w,
2529 AVCodecParameters *par,
2530 const AVPacketSideData *sd,
2531 SectionID id_data)
2532 {
2533 884 const char *name = av_packet_side_data_name(sd->type);
2534
2535 884 writer_print_section_header(w, sd, id_data);
2536
1/2
✓ Branch 0 taken 884 times.
✗ Branch 1 not taken.
884 print_str("side_data_type", name ? name : "unknown");
2537
3/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 879 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
889 if (sd->type == AV_PKT_DATA_DISPLAYMATRIX && sd->size >= 9*4) {
2538 5 double rotation = av_display_rotation_get((int32_t *)sd->data);
2539
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (isnan(rotation))
2540 rotation = 0;
2541 5 writer_print_integers(w, "displaymatrix", sd->data, 9, " %11d", 3, 4, 1);
2542 5 print_int("rotation", rotation);
2543
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 870 times.
879 } else if (sd->type == AV_PKT_DATA_STEREO3D) {
2544 9 const AVStereo3D *stereo = (AVStereo3D *)sd->data;
2545 9 print_str("type", av_stereo3d_type_name(stereo->type));
2546 9 print_int("inverted", !!(stereo->flags & AV_STEREO3D_FLAG_INVERT));
2547 9 print_str("view", av_stereo3d_view_name(stereo->view));
2548 9 print_str("primary_eye", av_stereo3d_primary_eye_name(stereo->primary_eye));
2549 9 print_int("baseline", stereo->baseline);
2550 9 print_q("horizontal_disparity_adjustment", stereo->horizontal_disparity_adjustment, '/');
2551 9 print_q("horizontal_field_of_view", stereo->horizontal_field_of_view, '/');
2552
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 866 times.
870 } else if (sd->type == AV_PKT_DATA_SPHERICAL) {
2553 4 const AVSphericalMapping *spherical = (AVSphericalMapping *)sd->data;
2554 4 print_str("projection", av_spherical_projection_name(spherical->projection));
2555
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (spherical->projection == AV_SPHERICAL_CUBEMAP) {
2556 print_int("padding", spherical->padding);
2557
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 } else if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR_TILE) {
2558 size_t l, t, r, b;
2559 4 av_spherical_tile_bounds(spherical, par->width, par->height,
2560 &l, &t, &r, &b);
2561 4 print_int("bound_left", l);
2562 4 print_int("bound_top", t);
2563 4 print_int("bound_right", r);
2564 4 print_int("bound_bottom", b);
2565 }
2566
2567 4 print_int("yaw", (double) spherical->yaw / (1 << 16));
2568 4 print_int("pitch", (double) spherical->pitch / (1 << 16));
2569 4 print_int("roll", (double) spherical->roll / (1 << 16));
2570
3/4
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 856 times.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
866 } else if (sd->type == AV_PKT_DATA_SKIP_SAMPLES && sd->size == 10) {
2571 10 print_int("skip_samples", AV_RL32(sd->data));
2572 10 print_int("discard_padding", AV_RL32(sd->data + 4));
2573 10 print_int("skip_reason", AV_RL8(sd->data + 8));
2574 10 print_int("discard_reason", AV_RL8(sd->data + 9));
2575
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 850 times.
856 } else if (sd->type == AV_PKT_DATA_MASTERING_DISPLAY_METADATA) {
2576 6 AVMasteringDisplayMetadata *metadata = (AVMasteringDisplayMetadata *)sd->data;
2577
2578
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (metadata->has_primaries) {
2579 6 print_q("red_x", metadata->display_primaries[0][0], '/');
2580 6 print_q("red_y", metadata->display_primaries[0][1], '/');
2581 6 print_q("green_x", metadata->display_primaries[1][0], '/');
2582 6 print_q("green_y", metadata->display_primaries[1][1], '/');
2583 6 print_q("blue_x", metadata->display_primaries[2][0], '/');
2584 6 print_q("blue_y", metadata->display_primaries[2][1], '/');
2585
2586 6 print_q("white_point_x", metadata->white_point[0], '/');
2587 6 print_q("white_point_y", metadata->white_point[1], '/');
2588 }
2589
2590
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (metadata->has_luminance) {
2591 6 print_q("min_luminance", metadata->min_luminance, '/');
2592 6 print_q("max_luminance", metadata->max_luminance, '/');
2593 }
2594
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 845 times.
850 } else if (sd->type == AV_PKT_DATA_CONTENT_LIGHT_LEVEL) {
2595 5 AVContentLightMetadata *metadata = (AVContentLightMetadata *)sd->data;
2596 5 print_int("max_content", metadata->MaxCLL);
2597 5 print_int("max_average", metadata->MaxFALL);
2598
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 843 times.
845 } else if (sd->type == AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT) {
2599 2 print_ambient_viewing_environment(
2600 2 w, (const AVAmbientViewingEnvironment *)sd->data);
2601
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 841 times.
843 } else if (sd->type == AV_PKT_DATA_DYNAMIC_HDR10_PLUS) {
2602 2 AVDynamicHDRPlus *metadata = (AVDynamicHDRPlus *)sd->data;
2603 2 print_dynamic_hdr10_plus(w, metadata);
2604
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 839 times.
841 } else if (sd->type == AV_PKT_DATA_DOVI_CONF) {
2605 2 AVDOVIDecoderConfigurationRecord *dovi = (AVDOVIDecoderConfigurationRecord *)sd->data;
2606 2 const char *comp = "unknown";
2607 2 print_int("dv_version_major", dovi->dv_version_major);
2608 2 print_int("dv_version_minor", dovi->dv_version_minor);
2609 2 print_int("dv_profile", dovi->dv_profile);
2610 2 print_int("dv_level", dovi->dv_level);
2611 2 print_int("rpu_present_flag", dovi->rpu_present_flag);
2612 2 print_int("el_present_flag", dovi->el_present_flag);
2613 2 print_int("bl_present_flag", dovi->bl_present_flag);
2614 2 print_int("dv_bl_signal_compatibility_id", dovi->dv_bl_signal_compatibility_id);
2615
1/5
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
2 switch (dovi->dv_md_compression)
2616 {
2617 2 case AV_DOVI_COMPRESSION_NONE: comp = "none"; break;
2618 case AV_DOVI_COMPRESSION_LIMITED: comp = "limited"; break;
2619 case AV_DOVI_COMPRESSION_RESERVED: comp = "reserved"; break;
2620 case AV_DOVI_COMPRESSION_EXTENDED: comp = "extended"; break;
2621 }
2622 2 print_str("dv_md_compression", comp);
2623
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 835 times.
839 } else if (sd->type == AV_PKT_DATA_AUDIO_SERVICE_TYPE) {
2624 4 enum AVAudioServiceType *t = (enum AVAudioServiceType *)sd->data;
2625 4 print_int("service_type", *t);
2626
2/2
✓ Branch 0 taken 669 times.
✓ Branch 1 taken 166 times.
835 } else if (sd->type == AV_PKT_DATA_MPEGTS_STREAM_ID) {
2627 669 print_int("id", *sd->data);
2628
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 157 times.
166 } else if (sd->type == AV_PKT_DATA_CPB_PROPERTIES) {
2629 9 const AVCPBProperties *prop = (AVCPBProperties *)sd->data;
2630 9 print_int("max_bitrate", prop->max_bitrate);
2631 9 print_int("min_bitrate", prop->min_bitrate);
2632 9 print_int("avg_bitrate", prop->avg_bitrate);
2633 9 print_int("buffer_size", prop->buffer_size);
2634 9 print_int("vbv_delay", prop->vbv_delay);
2635
2/2
✓ Branch 0 taken 149 times.
✓ Branch 1 taken 8 times.
157 } else if (sd->type == AV_PKT_DATA_WEBVTT_IDENTIFIER ||
2636
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 133 times.
149 sd->type == AV_PKT_DATA_WEBVTT_SETTINGS) {
2637
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (do_show_data)
2638 writer_print_data(w, "data", sd->data, sd->size);
2639 24 writer_print_data_hash(w, "data_hash", sd->data, sd->size);
2640
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 133 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
133 } else if (sd->type == AV_PKT_DATA_FRAME_CROPPING && sd->size >= sizeof(uint32_t) * 4) {
2641 print_int("crop_top", AV_RL32(sd->data));
2642 print_int("crop_bottom", AV_RL32(sd->data + 4));
2643 print_int("crop_left", AV_RL32(sd->data + 8));
2644 print_int("crop_right", AV_RL32(sd->data + 12));
2645
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 133 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
133 } else if (sd->type == AV_PKT_DATA_AFD && sd->size > 0) {
2646 print_int("active_format", *sd->data);
2647 }
2648 884 }
2649
2650 395 static void print_private_data(WriterContext *w, void *priv_data)
2651 {
2652 395 const AVOption *opt = NULL;
2653
2/2
✓ Branch 1 taken 3074 times.
✓ Branch 2 taken 395 times.
3469 while (opt = av_opt_next(priv_data, opt)) {
2654 uint8_t *str;
2655
2/2
✓ Branch 0 taken 2986 times.
✓ Branch 1 taken 88 times.
3074 if (!(opt->flags & AV_OPT_FLAG_EXPORT)) continue;
2656
1/2
✓ Branch 1 taken 88 times.
✗ Branch 2 not taken.
88 if (av_opt_get(priv_data, opt->name, 0, &str) >= 0) {
2657 88 print_str(opt->name, str);
2658 88 av_free(str);
2659 }
2660 }
2661 395 }
2662
2663 672 static void print_color_range(WriterContext *w, enum AVColorRange color_range)
2664 {
2665 672 const char *val = av_color_range_name(color_range);
2666
3/4
✓ Branch 0 taken 672 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✓ Branch 3 taken 256 times.
672 if (!val || color_range == AVCOL_RANGE_UNSPECIFIED) {
2667 416 print_str_opt("color_range", "unknown");
2668 } else {
2669 256 print_str("color_range", val);
2670 }
2671 672 }
2672
2673 672 static void print_color_space(WriterContext *w, enum AVColorSpace color_space)
2674 {
2675 672 const char *val = av_color_space_name(color_space);
2676
3/4
✓ Branch 0 taken 672 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 462 times.
✓ Branch 3 taken 210 times.
672 if (!val || color_space == AVCOL_SPC_UNSPECIFIED) {
2677 462 print_str_opt("color_space", "unknown");
2678 } else {
2679 210 print_str("color_space", val);
2680 }
2681 672 }
2682
2683 672 static void print_primaries(WriterContext *w, enum AVColorPrimaries color_primaries)
2684 {
2685 672 const char *val = av_color_primaries_name(color_primaries);
2686
3/4
✓ Branch 0 taken 672 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 469 times.
✓ Branch 3 taken 203 times.
672 if (!val || color_primaries == AVCOL_PRI_UNSPECIFIED) {
2687 469 print_str_opt("color_primaries", "unknown");
2688 } else {
2689 203 print_str("color_primaries", val);
2690 }
2691 672 }
2692
2693 672 static void print_color_trc(WriterContext *w, enum AVColorTransferCharacteristic color_trc)
2694 {
2695 672 const char *val = av_color_transfer_name(color_trc);
2696
3/4
✓ Branch 0 taken 672 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 468 times.
✓ Branch 3 taken 204 times.
672 if (!val || color_trc == AVCOL_TRC_UNSPECIFIED) {
2697 468 print_str_opt("color_transfer", "unknown");
2698 } else {
2699 204 print_str("color_transfer", val);
2700 }
2701 672 }
2702
2703 672 static void print_chroma_location(WriterContext *w, enum AVChromaLocation chroma_location)
2704 {
2705 672 const char *val = av_chroma_location_name(chroma_location);
2706
3/4
✓ Branch 0 taken 672 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 398 times.
✓ Branch 3 taken 274 times.
672 if (!val || chroma_location == AVCHROMA_LOC_UNSPECIFIED) {
2707 398 print_str_opt("chroma_location", "unspecified");
2708 } else {
2709 274 print_str("chroma_location", val);
2710 }
2711 672 }
2712
2713 6334 static void clear_log(int need_lock)
2714 {
2715 int i;
2716
2717
1/2
✓ Branch 0 taken 6334 times.
✗ Branch 1 not taken.
6334 if (need_lock)
2718 6334 pthread_mutex_lock(&log_mutex);
2719
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6334 times.
6334 for (i=0; i<log_buffer_size; i++) {
2720 av_freep(&log_buffer[i].context_name);
2721 av_freep(&log_buffer[i].parent_name);
2722 av_freep(&log_buffer[i].log_message);
2723 }
2724 6334 log_buffer_size = 0;
2725
1/2
✓ Branch 0 taken 6334 times.
✗ Branch 1 not taken.
6334 if(need_lock)
2726 6334 pthread_mutex_unlock(&log_mutex);
2727 6334 }
2728
2729 static int show_log(WriterContext *w, int section_ids, int section_id, int log_level)
2730 {
2731 int i;
2732 pthread_mutex_lock(&log_mutex);
2733 if (!log_buffer_size) {
2734 pthread_mutex_unlock(&log_mutex);
2735 return 0;
2736 }
2737 writer_print_section_header(w, NULL, section_ids);
2738
2739 for (i=0; i<log_buffer_size; i++) {
2740 if (log_buffer[i].log_level <= log_level) {
2741 writer_print_section_header(w, NULL, section_id);
2742 print_str("context", log_buffer[i].context_name);
2743 print_int("level", log_buffer[i].log_level);
2744 print_int("category", log_buffer[i].category);
2745 if (log_buffer[i].parent_name) {
2746 print_str("parent_context", log_buffer[i].parent_name);
2747 print_int("parent_category", log_buffer[i].parent_category);
2748 } else {
2749 print_str_opt("parent_context", "N/A");
2750 print_str_opt("parent_category", "N/A");
2751 }
2752 print_str("message", log_buffer[i].log_message);
2753 writer_print_section_footer(w);
2754 }
2755 }
2756 clear_log(0);
2757 pthread_mutex_unlock(&log_mutex);
2758
2759 writer_print_section_footer(w);
2760
2761 return 0;
2762 }
2763
2764 5662 static void show_packet(WriterContext *w, InputFile *ifile, AVPacket *pkt, int packet_idx)
2765 {
2766 char val_str[128];
2767 5662 AVStream *st = ifile->streams[pkt->stream_index].st;
2768 AVBPrint pbuf;
2769 const char *s;
2770
2771 5662 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2772
2773 5662 writer_print_section_header(w, NULL, SECTION_ID_PACKET);
2774
2775 5662 s = av_get_media_type_string(st->codecpar->codec_type);
2776
1/2
✓ Branch 0 taken 5662 times.
✗ Branch 1 not taken.
5662 if (s) print_str ("codec_type", s);
2777 else print_str_opt("codec_type", "unknown");
2778 5662 print_int("stream_index", pkt->stream_index);
2779 5662 print_ts ("pts", pkt->pts);
2780 5662 print_time("pts_time", pkt->pts, &st->time_base);
2781 5662 print_ts ("dts", pkt->dts);
2782 5662 print_time("dts_time", pkt->dts, &st->time_base);
2783 5662 print_duration_ts("duration", pkt->duration);
2784 5662 print_duration_time("duration_time", pkt->duration, &st->time_base);
2785 5662 print_val("size", pkt->size, unit_byte_str);
2786
2/2
✓ Branch 0 taken 5574 times.
✓ Branch 1 taken 88 times.
5662 if (pkt->pos != -1) print_fmt ("pos", "%"PRId64, pkt->pos);
2787 88 else print_str_opt("pos", "N/A");
2788
6/6
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 5657 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 5656 times.
✓ Branch 5 taken 4702 times.
✓ Branch 6 taken 960 times.
5662 print_fmt("flags", "%c%c%c", pkt->flags & AV_PKT_FLAG_KEY ? 'K' : '_',
2789 pkt->flags & AV_PKT_FLAG_DISCARD ? 'D' : '_',
2790 pkt->flags & AV_PKT_FLAG_CORRUPT ? 'C' : '_');
2791
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5662 times.
5662 if (do_show_data)
2792 writer_print_data(w, "data", pkt->data, pkt->size);
2793 5662 writer_print_data_hash(w, "data_hash", pkt->data, pkt->size);
2794
2795
2/2
✓ Branch 0 taken 838 times.
✓ Branch 1 taken 4824 times.
5662 if (pkt->side_data_elems) {
2796 size_t size;
2797 const uint8_t *side_metadata;
2798
2799 838 side_metadata = av_packet_get_side_data(pkt, AV_PKT_DATA_STRINGS_METADATA, &size);
2800
4/6
✓ Branch 0 taken 131 times.
✓ Branch 1 taken 707 times.
✓ Branch 2 taken 131 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 131 times.
✗ Branch 5 not taken.
838 if (side_metadata && size && do_show_packet_tags) {
2801 131 AVDictionary *dict = NULL;
2802
1/2
✓ Branch 1 taken 131 times.
✗ Branch 2 not taken.
131 if (av_packet_unpack_dictionary(side_metadata, size, &dict) >= 0)
2803 131 show_tags(w, dict, SECTION_ID_PACKET_TAGS);
2804 131 av_dict_free(&dict);
2805 }
2806
2807 838 writer_print_section_header(w, NULL, SECTION_ID_PACKET_SIDE_DATA_LIST);
2808
2/2
✓ Branch 0 taken 838 times.
✓ Branch 1 taken 838 times.
1676 for (int i = 0; i < pkt->side_data_elems; i++) {
2809 838 print_pkt_side_data(w, st->codecpar, &pkt->side_data[i],
2810 SECTION_ID_PACKET_SIDE_DATA);
2811 838 writer_print_section_footer(w);
2812 }
2813 838 writer_print_section_footer(w);
2814 }
2815
2816 5662 writer_print_section_footer(w);
2817
2818 5662 av_bprint_finalize(&pbuf, NULL);
2819 5662 fflush(stdout);
2820 5662 }
2821
2822 static void show_subtitle(WriterContext *w, AVSubtitle *sub, AVStream *stream,
2823 AVFormatContext *fmt_ctx)
2824 {
2825 AVBPrint pbuf;
2826
2827 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2828
2829 writer_print_section_header(w, NULL, SECTION_ID_SUBTITLE);
2830
2831 print_str ("media_type", "subtitle");
2832 print_ts ("pts", sub->pts);
2833 print_time("pts_time", sub->pts, &AV_TIME_BASE_Q);
2834 print_int ("format", sub->format);
2835 print_int ("start_display_time", sub->start_display_time);
2836 print_int ("end_display_time", sub->end_display_time);
2837 print_int ("num_rects", sub->num_rects);
2838
2839 writer_print_section_footer(w);
2840
2841 av_bprint_finalize(&pbuf, NULL);
2842 fflush(stdout);
2843 }
2844
2845 181 static void print_frame_side_data(WriterContext *w,
2846 const AVFrame *frame,
2847 const AVStream *stream)
2848 {
2849 181 writer_print_section_header(w, NULL, SECTION_ID_FRAME_SIDE_DATA_LIST);
2850
2851
2/2
✓ Branch 0 taken 322 times.
✓ Branch 1 taken 181 times.
503 for (int i = 0; i < frame->nb_side_data; i++) {
2852 322 const AVFrameSideData *sd = frame->side_data[i];
2853 const char *name;
2854
2855 322 writer_print_section_header(w, sd, SECTION_ID_FRAME_SIDE_DATA);
2856 322 name = av_frame_side_data_name(sd->type);
2857
1/2
✓ Branch 0 taken 322 times.
✗ Branch 1 not taken.
322 print_str("side_data_type", name ? name : "unknown");
2858
3/4
✓ Branch 0 taken 87 times.
✓ Branch 1 taken 235 times.
✓ Branch 2 taken 87 times.
✗ Branch 3 not taken.
409 if (sd->type == AV_FRAME_DATA_DISPLAYMATRIX && sd->size >= 9*4) {
2859 87 double rotation = av_display_rotation_get((int32_t *)sd->data);
2860
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 87 times.
87 if (isnan(rotation))
2861 rotation = 0;
2862 87 writer_print_integers(w, "displaymatrix", sd->data, 9, " %11d", 3, 4, 1);
2863 87 print_int("rotation", rotation);
2864
3/4
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 168 times.
✓ Branch 2 taken 67 times.
✗ Branch 3 not taken.
235 } else if (sd->type == AV_FRAME_DATA_AFD && sd->size > 0) {
2865 67 print_int("active_format", *sd->data);
2866
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 168 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
168 } else if (sd->type == AV_FRAME_DATA_GOP_TIMECODE && sd->size >= 8) {
2867 char tcbuf[AV_TIMECODE_STR_SIZE];
2868 av_timecode_make_mpeg_tc_string(tcbuf, *(int64_t *)(sd->data));
2869 print_str("timecode", tcbuf);
2870
3/4
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 147 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
189 } else if (sd->type == AV_FRAME_DATA_S12M_TIMECODE && sd->size == 16) {
2871 21 uint32_t *tc = (uint32_t*)sd->data;
2872 21 int m = FFMIN(tc[0],3);
2873 21 writer_print_section_header(w, NULL, SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST);
2874
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 21 times.
42 for (int j = 1; j <= m ; j++) {
2875 char tcbuf[AV_TIMECODE_STR_SIZE];
2876 21 av_timecode_make_smpte_tc_string2(tcbuf, stream->avg_frame_rate, tc[j], 0, 0);
2877 21 writer_print_section_header(w, NULL, SECTION_ID_FRAME_SIDE_DATA_TIMECODE);
2878 21 print_str("value", tcbuf);
2879 21 writer_print_section_footer(w);
2880 }
2881 21 writer_print_section_footer(w);
2882
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 124 times.
147 } else if (sd->type == AV_FRAME_DATA_MASTERING_DISPLAY_METADATA) {
2883 23 AVMasteringDisplayMetadata *metadata = (AVMasteringDisplayMetadata *)sd->data;
2884
2885
1/2
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
23 if (metadata->has_primaries) {
2886 23 print_q("red_x", metadata->display_primaries[0][0], '/');
2887 23 print_q("red_y", metadata->display_primaries[0][1], '/');
2888 23 print_q("green_x", metadata->display_primaries[1][0], '/');
2889 23 print_q("green_y", metadata->display_primaries[1][1], '/');
2890 23 print_q("blue_x", metadata->display_primaries[2][0], '/');
2891 23 print_q("blue_y", metadata->display_primaries[2][1], '/');
2892
2893 23 print_q("white_point_x", metadata->white_point[0], '/');
2894 23 print_q("white_point_y", metadata->white_point[1], '/');
2895 }
2896
2897
1/2
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
23 if (metadata->has_luminance) {
2898 23 print_q("min_luminance", metadata->min_luminance, '/');
2899 23 print_q("max_luminance", metadata->max_luminance, '/');
2900 }
2901
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 123 times.
124 } else if (sd->type == AV_FRAME_DATA_DYNAMIC_HDR_PLUS) {
2902 1 AVDynamicHDRPlus *metadata = (AVDynamicHDRPlus *)sd->data;
2903 1 print_dynamic_hdr10_plus(w, metadata);
2904
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 100 times.
123 } else if (sd->type == AV_FRAME_DATA_CONTENT_LIGHT_LEVEL) {
2905 23 AVContentLightMetadata *metadata = (AVContentLightMetadata *)sd->data;
2906 23 print_int("max_content", metadata->MaxCLL);
2907 23 print_int("max_average", metadata->MaxFALL);
2908
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 97 times.
100 } else if (sd->type == AV_FRAME_DATA_ICC_PROFILE) {
2909 3 const AVDictionaryEntry *tag = av_dict_get(sd->metadata, "name", NULL, AV_DICT_MATCH_CASE);
2910
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if (tag)
2911 2 print_str(tag->key, tag->value);
2912 3 print_int("size", sd->size);
2913
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 95 times.
97 } else if (sd->type == AV_FRAME_DATA_DOVI_METADATA) {
2914 2 print_dovi_metadata(w, (const AVDOVIMetadata *)sd->data);
2915
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 94 times.
95 } else if (sd->type == AV_FRAME_DATA_DYNAMIC_HDR_VIVID) {
2916 1 AVDynamicHDRVivid *metadata = (AVDynamicHDRVivid *)sd->data;
2917 1 print_dynamic_hdr_vivid(w, metadata);
2918
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 92 times.
94 } else if (sd->type == AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT) {
2919 2 print_ambient_viewing_environment(w, (const AVAmbientViewingEnvironment *)sd->data);
2920
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
92 } else if (sd->type == AV_FRAME_DATA_FILM_GRAIN_PARAMS) {
2921 AVFilmGrainParams *fgp = (AVFilmGrainParams *)sd->data;
2922 print_film_grain_params(w, fgp);
2923 }
2924 322 writer_print_section_footer(w);
2925 }
2926 181 writer_print_section_footer(w);
2927 181 }
2928
2929 3150 static void show_frame(WriterContext *w, AVFrame *frame, AVStream *stream,
2930 AVFormatContext *fmt_ctx)
2931 {
2932
1/2
✓ Branch 0 taken 3150 times.
✗ Branch 1 not taken.
3150 FrameData *fd = frame->opaque_ref ? (FrameData*)frame->opaque_ref->data : NULL;
2933 AVBPrint pbuf;
2934 char val_str[128];
2935 const char *s;
2936
2937 3150 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2938
2939 3150 writer_print_section_header(w, NULL, SECTION_ID_FRAME);
2940
2941 3150 s = av_get_media_type_string(stream->codecpar->codec_type);
2942
1/2
✓ Branch 0 taken 3150 times.
✗ Branch 1 not taken.
3150 if (s) print_str ("media_type", s);
2943 else print_str_opt("media_type", "unknown");
2944 3150 print_int("stream_index", stream->index);
2945 3150 print_int("key_frame", !!(frame->flags & AV_FRAME_FLAG_KEY));
2946 3150 print_ts ("pts", frame->pts);
2947 3150 print_time("pts_time", frame->pts, &stream->time_base);
2948 3150 print_ts ("pkt_dts", frame->pkt_dts);
2949 3150 print_time("pkt_dts_time", frame->pkt_dts, &stream->time_base);
2950 3150 print_ts ("best_effort_timestamp", frame->best_effort_timestamp);
2951 3150 print_time("best_effort_timestamp_time", frame->best_effort_timestamp, &stream->time_base);
2952 3150 print_duration_ts ("duration", frame->duration);
2953 3150 print_duration_time("duration_time", frame->duration, &stream->time_base);
2954
3/4
✓ Branch 0 taken 3150 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2848 times.
✓ Branch 3 taken 302 times.
3150 if (fd && fd->pkt_pos != -1) print_fmt ("pkt_pos", "%"PRId64, fd->pkt_pos);
2955 302 else print_str_opt("pkt_pos", "N/A");
2956
2/4
✓ Branch 0 taken 3150 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3150 times.
✗ Branch 3 not taken.
3150 if (fd && fd->pkt_size != -1) print_val ("pkt_size", fd->pkt_size, unit_byte_str);
2957 else print_str_opt("pkt_size", "N/A");
2958
2959
2/3
✓ Branch 0 taken 575 times.
✓ Branch 1 taken 2575 times.
✗ Branch 2 not taken.
3150 switch (stream->codecpar->codec_type) {
2960 AVRational sar;
2961
2962 575 case AVMEDIA_TYPE_VIDEO:
2963 575 print_int("width", frame->width);
2964 575 print_int("height", frame->height);
2965 575 print_int("crop_top", frame->crop_top);
2966 575 print_int("crop_bottom", frame->crop_bottom);
2967 575 print_int("crop_left", frame->crop_left);
2968 575 print_int("crop_right", frame->crop_right);
2969 575 s = av_get_pix_fmt_name(frame->format);
2970
1/2
✓ Branch 0 taken 575 times.
✗ Branch 1 not taken.
575 if (s) print_str ("pix_fmt", s);
2971 else print_str_opt("pix_fmt", "unknown");
2972 575 sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, frame);
2973
2/2
✓ Branch 0 taken 568 times.
✓ Branch 1 taken 7 times.
575 if (sar.num) {
2974 568 print_q("sample_aspect_ratio", sar, ':');
2975 } else {
2976 7 print_str_opt("sample_aspect_ratio", "N/A");
2977 }
2978 575 print_fmt("pict_type", "%c", av_get_picture_type_char(frame->pict_type));
2979 575 print_int("interlaced_frame", !!(frame->flags & AV_FRAME_FLAG_INTERLACED));
2980 575 print_int("top_field_first", !!(frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST));
2981 575 print_int("repeat_pict", frame->repeat_pict);
2982
2983 575 print_color_range(w, frame->color_range);
2984 575 print_color_space(w, frame->colorspace);
2985 575 print_primaries(w, frame->color_primaries);
2986 575 print_color_trc(w, frame->color_trc);
2987 575 print_chroma_location(w, frame->chroma_location);
2988 575 break;
2989
2990 2575 case AVMEDIA_TYPE_AUDIO:
2991 2575 s = av_get_sample_fmt_name(frame->format);
2992
1/2
✓ Branch 0 taken 2575 times.
✗ Branch 1 not taken.
2575 if (s) print_str ("sample_fmt", s);
2993 else print_str_opt("sample_fmt", "unknown");
2994 2575 print_int("nb_samples", frame->nb_samples);
2995 2575 print_int("channels", frame->ch_layout.nb_channels);
2996
2/2
✓ Branch 0 taken 2352 times.
✓ Branch 1 taken 223 times.
2575 if (frame->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
2997 2352 av_channel_layout_describe(&frame->ch_layout, val_str, sizeof(val_str));
2998 2352 print_str ("channel_layout", val_str);
2999 } else
3000 223 print_str_opt("channel_layout", "unknown");
3001 2575 break;
3002 }
3003
2/2
✓ Branch 0 taken 1102 times.
✓ Branch 1 taken 2048 times.
3150 if (do_show_frame_tags)
3004 1102 show_tags(w, frame->metadata, SECTION_ID_FRAME_TAGS);
3005
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3150 times.
3150 if (do_show_log)
3006 show_log(w, SECTION_ID_FRAME_LOGS, SECTION_ID_FRAME_LOG, do_show_log);
3007
2/2
✓ Branch 0 taken 181 times.
✓ Branch 1 taken 2969 times.
3150 if (frame->nb_side_data)
3008 181 print_frame_side_data(w, frame, stream);
3009
3010 3150 writer_print_section_footer(w);
3011
3012 3150 av_bprint_finalize(&pbuf, NULL);
3013 3150 fflush(stdout);
3014 3150 }
3015
3016 6334 static av_always_inline int process_frame(WriterContext *w,
3017 InputFile *ifile,
3018 AVFrame *frame, const AVPacket *pkt,
3019 int *packet_new)
3020 {
3021 6334 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
3022 6334 AVCodecContext *dec_ctx = ifile->streams[pkt->stream_index].dec_ctx;
3023 6334 AVCodecParameters *par = ifile->streams[pkt->stream_index].st->codecpar;
3024 AVSubtitle sub;
3025 6334 int ret = 0, got_frame = 0;
3026
3027 6334 clear_log(1);
3028
2/2
✓ Branch 0 taken 6328 times.
✓ Branch 1 taken 6 times.
6334 if (dec_ctx) {
3029
1/3
✓ Branch 0 taken 6328 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
6328 switch (par->codec_type) {
3030 6328 case AVMEDIA_TYPE_VIDEO:
3031 case AVMEDIA_TYPE_AUDIO:
3032
2/2
✓ Branch 0 taken 3199 times.
✓ Branch 1 taken 3129 times.
6328 if (*packet_new) {
3033 3199 ret = avcodec_send_packet(dec_ctx, pkt);
3034
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3199 times.
3199 if (ret == AVERROR(EAGAIN)) {
3035 ret = 0;
3036
4/4
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 3176 times.
✓ Branch 2 taken 21 times.
✓ Branch 3 taken 2 times.
3199 } else if (ret >= 0 || ret == AVERROR_EOF) {
3037 3197 ret = 0;
3038 3197 *packet_new = 0;
3039 }
3040 }
3041
2/2
✓ Branch 0 taken 6326 times.
✓ Branch 1 taken 2 times.
6328 if (ret >= 0) {
3042 6326 ret = avcodec_receive_frame(dec_ctx, frame);
3043
2/2
✓ Branch 0 taken 3150 times.
✓ Branch 1 taken 3176 times.
6326 if (ret >= 0) {
3044 3150 got_frame = 1;
3045
3/4
✓ Branch 0 taken 69 times.
✓ Branch 1 taken 3107 times.
✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
3176 } else if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
3046 3176 ret = 0;
3047 }
3048 }
3049 6328 break;
3050
3051 case AVMEDIA_TYPE_SUBTITLE:
3052 if (*packet_new)
3053 ret = avcodec_decode_subtitle2(dec_ctx, &sub, &got_frame, pkt);
3054 *packet_new = 0;
3055 break;
3056 default:
3057 *packet_new = 0;
3058 }
3059 } else {
3060 6 *packet_new = 0;
3061 }
3062
3063
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6332 times.
6334 if (ret < 0)
3064 2 return ret;
3065
2/2
✓ Branch 0 taken 3150 times.
✓ Branch 1 taken 3182 times.
6332 if (got_frame) {
3066 3150 int is_sub = (par->codec_type == AVMEDIA_TYPE_SUBTITLE);
3067 3150 nb_streams_frames[pkt->stream_index]++;
3068
1/2
✓ Branch 0 taken 3150 times.
✗ Branch 1 not taken.
3150 if (do_show_frames)
3069
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3150 times.
3150 if (is_sub)
3070 show_subtitle(w, &sub, ifile->streams[pkt->stream_index].st, fmt_ctx);
3071 else
3072 3150 show_frame(w, frame, ifile->streams[pkt->stream_index].st, fmt_ctx);
3073
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3150 times.
3150 if (is_sub)
3074 avsubtitle_free(&sub);
3075 }
3076
3/4
✓ Branch 0 taken 3182 times.
✓ Branch 1 taken 3150 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3182 times.
6332 return got_frame || *packet_new;
3077 }
3078
3079 83 static void log_read_interval(const ReadInterval *interval, void *log_ctx, int log_level)
3080 {
3081 83 av_log(log_ctx, log_level, "id:%d", interval->id);
3082
3083
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 83 times.
83 if (interval->has_start) {
3084 av_log(log_ctx, log_level, " start:%s%s", interval->start_is_offset ? "+" : "",
3085 av_ts2timestr(interval->start, &AV_TIME_BASE_Q));
3086 } else {
3087 83 av_log(log_ctx, log_level, " start:N/A");
3088 }
3089
3090
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 75 times.
83 if (interval->has_end) {
3091
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
8 av_log(log_ctx, log_level, " end:%s", interval->end_is_offset ? "+" : "");
3092
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
8 if (interval->duration_frames)
3093 2 av_log(log_ctx, log_level, "#%"PRId64, interval->end);
3094 else
3095 6 av_log(log_ctx, log_level, "%s", av_ts2timestr(interval->end, &AV_TIME_BASE_Q));
3096 } else {
3097 75 av_log(log_ctx, log_level, " end:N/A");
3098 }
3099
3100 83 av_log(log_ctx, log_level, "\n");
3101 83 }
3102
3103 79 static int read_interval_packets(WriterContext *w, InputFile *ifile,
3104 const ReadInterval *interval, int64_t *cur_ts)
3105 {
3106 79 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
3107 79 AVPacket *pkt = NULL;
3108 79 AVFrame *frame = NULL;
3109 79 int ret = 0, i = 0, frame_count = 0;
3110 79 int64_t start = -INT64_MAX, end = interval->end;
3111
4/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 75 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1 times.
79 int has_start = 0, has_end = interval->has_end && !interval->end_is_offset;
3112
3113 79 av_log(NULL, AV_LOG_VERBOSE, "Processing read interval ");
3114 79 log_read_interval(interval, NULL, AV_LOG_VERBOSE);
3115
3116
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 79 times.
79 if (interval->has_start) {
3117 int64_t target;
3118 if (interval->start_is_offset) {
3119 if (*cur_ts == AV_NOPTS_VALUE) {
3120 av_log(NULL, AV_LOG_ERROR,
3121 "Could not seek to relative position since current "
3122 "timestamp is not defined\n");
3123 ret = AVERROR(EINVAL);
3124 goto end;
3125 }
3126 target = *cur_ts + interval->start;
3127 } else {
3128 target = interval->start;
3129 }
3130
3131 av_log(NULL, AV_LOG_VERBOSE, "Seeking to read interval start point %s\n",
3132 av_ts2timestr(target, &AV_TIME_BASE_Q));
3133 if ((ret = avformat_seek_file(fmt_ctx, -1, -INT64_MAX, target, INT64_MAX, 0)) < 0) {
3134 av_log(NULL, AV_LOG_ERROR, "Could not seek to position %"PRId64": %s\n",
3135 interval->start, av_err2str(ret));
3136 goto end;
3137 }
3138 }
3139
3140 79 frame = av_frame_alloc();
3141
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 79 times.
79 if (!frame) {
3142 ret = AVERROR(ENOMEM);
3143 goto end;
3144 }
3145 79 pkt = av_packet_alloc();
3146
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 79 times.
79 if (!pkt) {
3147 ret = AVERROR(ENOMEM);
3148 goto end;
3149 }
3150
2/2
✓ Branch 1 taken 8552 times.
✓ Branch 2 taken 75 times.
8627 while (!av_read_frame(fmt_ctx, pkt)) {
3151
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8552 times.
8552 if (fmt_ctx->nb_streams > nb_streams) {
3152 REALLOCZ_ARRAY_STREAM(nb_streams_frames, nb_streams, fmt_ctx->nb_streams);
3153 REALLOCZ_ARRAY_STREAM(nb_streams_packets, nb_streams, fmt_ctx->nb_streams);
3154 REALLOCZ_ARRAY_STREAM(selected_streams, nb_streams, fmt_ctx->nb_streams);
3155 nb_streams = fmt_ctx->nb_streams;
3156 }
3157
2/2
✓ Branch 0 taken 8508 times.
✓ Branch 1 taken 44 times.
8552 if (selected_streams[pkt->stream_index]) {
3158 8508 AVRational tb = ifile->streams[pkt->stream_index].st->time_base;
3159
2/2
✓ Branch 0 taken 8415 times.
✓ Branch 1 taken 93 times.
8508 int64_t pts = pkt->pts != AV_NOPTS_VALUE ? pkt->pts : pkt->dts;
3160
3161
2/2
✓ Branch 0 taken 8415 times.
✓ Branch 1 taken 93 times.
8508 if (pts != AV_NOPTS_VALUE)
3162 8415 *cur_ts = av_rescale_q(pts, tb, AV_TIME_BASE_Q);
3163
3164
4/4
✓ Branch 0 taken 165 times.
✓ Branch 1 taken 8343 times.
✓ Branch 2 taken 73 times.
✓ Branch 3 taken 92 times.
8508 if (!has_start && *cur_ts != AV_NOPTS_VALUE) {
3165 73 start = *cur_ts;
3166 73 has_start = 1;
3167 }
3168
3169
6/6
✓ Branch 0 taken 8416 times.
✓ Branch 1 taken 92 times.
✓ Branch 2 taken 8400 times.
✓ Branch 3 taken 16 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 8399 times.
8508 if (has_start && !has_end && interval->end_is_offset) {
3170 1 end = start + interval->end;
3171 1 has_end = 1;
3172 }
3173
3174
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 8505 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
8508 if (interval->end_is_offset && interval->duration_frames) {
3175
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if (frame_count >= interval->end)
3176 4 break;
3177
5/6
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 8491 times.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 11 times.
8505 } else if (has_end && *cur_ts != AV_NOPTS_VALUE && *cur_ts >= end) {
3178 3 break;
3179 }
3180
3181 8504 frame_count++;
3182
2/2
✓ Branch 0 taken 5662 times.
✓ Branch 1 taken 2842 times.
8504 if (do_read_packets) {
3183
1/2
✓ Branch 0 taken 5662 times.
✗ Branch 1 not taken.
5662 if (do_show_packets)
3184 5662 show_packet(w, ifile, pkt, i++);
3185 5662 nb_streams_packets[pkt->stream_index]++;
3186 }
3187
2/2
✓ Branch 0 taken 3109 times.
✓ Branch 1 taken 5395 times.
8504 if (do_read_frames) {
3188 3109 int packet_new = 1;
3189 FrameData *fd;
3190
3191 3109 pkt->opaque_ref = av_buffer_allocz(sizeof(*fd));
3192
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3109 times.
3109 if (!pkt->opaque_ref) {
3193 ret = AVERROR(ENOMEM);
3194 goto end;
3195 }
3196 3109 fd = (FrameData*)pkt->opaque_ref->data;
3197 3109 fd->pkt_pos = pkt->pos;
3198 3109 fd->pkt_size = pkt->size;
3199
3200
2/2
✓ Branch 1 taken 3129 times.
✓ Branch 2 taken 3109 times.
6238 while (process_frame(w, ifile, frame, pkt, &packet_new) > 0);
3201 }
3202 }
3203 8548 av_packet_unref(pkt);
3204 }
3205 79 av_packet_unref(pkt);
3206 //Flush remaining frames that are cached in the decoder
3207
2/2
✓ Branch 0 taken 119 times.
✓ Branch 1 taken 79 times.
198 for (i = 0; i < ifile->nb_streams; i++) {
3208 119 pkt->stream_index = i;
3209
2/2
✓ Branch 0 taken 75 times.
✓ Branch 1 taken 44 times.
119 if (do_read_frames) {
3210
2/2
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 75 times.
96 while (process_frame(w, ifile, frame, pkt, &(int){1}) > 0);
3211
2/2
✓ Branch 0 taken 69 times.
✓ Branch 1 taken 6 times.
75 if (ifile->streams[i].dec_ctx)
3212 69 avcodec_flush_buffers(ifile->streams[i].dec_ctx);
3213 }
3214 }
3215
3216 79 end:
3217 79 av_frame_free(&frame);
3218 79 av_packet_free(&pkt);
3219
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 79 times.
79 if (ret < 0) {
3220 av_log(NULL, AV_LOG_ERROR, "Could not read packets in interval ");
3221 log_read_interval(interval, NULL, AV_LOG_ERROR);
3222 }
3223 79 return ret;
3224 }
3225
3226 79 static int read_packets(WriterContext *w, InputFile *ifile)
3227 {
3228 79 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
3229 79 int i, ret = 0;
3230 79 int64_t cur_ts = fmt_ctx->start_time;
3231
3232
2/2
✓ Branch 0 taken 75 times.
✓ Branch 1 taken 4 times.
79 if (read_intervals_nb == 0) {
3233 75 ReadInterval interval = (ReadInterval) { .has_start = 0, .has_end = 0 };
3234 75 ret = read_interval_packets(w, ifile, &interval, &cur_ts);
3235 } else {
3236
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 for (i = 0; i < read_intervals_nb; i++) {
3237 4 ret = read_interval_packets(w, ifile, &read_intervals[i], &cur_ts);
3238
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (ret < 0)
3239 break;
3240 }
3241 }
3242
3243 79 return ret;
3244 }
3245
3246 240 static void print_dispositions(WriterContext *w, uint32_t disposition, SectionID section_id)
3247 {
3248 240 writer_print_section_header(w, NULL, section_id);
3249
2/2
✓ Branch 0 taken 7680 times.
✓ Branch 1 taken 240 times.
7920 for (int i = 0; i < sizeof(disposition) * CHAR_BIT; i++) {
3250 7680 const char *disposition_str = av_disposition_to_string(1U << i);
3251
3252
2/2
✓ Branch 0 taken 4560 times.
✓ Branch 1 taken 3120 times.
7680 if (disposition_str)
3253 4560 print_int(disposition_str, !!(disposition & (1U << i)));
3254 }
3255 240 writer_print_section_footer(w);
3256 240 }
3257
3258 #define IN_PROGRAM 1
3259 #define IN_STREAM_GROUP 2
3260
3261 296 static int show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_idx, InputStream *ist, int container)
3262 {
3263 296 AVStream *stream = ist->st;
3264 AVCodecParameters *par;
3265 AVCodecContext *dec_ctx;
3266 char val_str[128];
3267 const char *s;
3268 AVRational sar, dar;
3269 AVBPrint pbuf;
3270 const AVCodecDescriptor *cd;
3271 296 const SectionID section_header[] = {
3272 SECTION_ID_STREAM,
3273 SECTION_ID_PROGRAM_STREAM,
3274 SECTION_ID_STREAM_GROUP_STREAM,
3275 };
3276 296 const SectionID section_disposition[] = {
3277 SECTION_ID_STREAM_DISPOSITION,
3278 SECTION_ID_PROGRAM_STREAM_DISPOSITION,
3279 SECTION_ID_STREAM_GROUP_STREAM_DISPOSITION,
3280 };
3281 296 const SectionID section_tags[] = {
3282 SECTION_ID_STREAM_TAGS,
3283 SECTION_ID_PROGRAM_STREAM_TAGS,
3284 SECTION_ID_STREAM_GROUP_STREAM_TAGS,
3285 };
3286 296 int ret = 0;
3287 296 const char *profile = NULL;
3288
3289
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 296 times.
296 av_assert0(container < FF_ARRAY_ELEMS(section_header));
3290
3291 296 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
3292
3293 296 writer_print_section_header(w, NULL, section_header[container]);
3294
3295 296 print_int("index", stream->index);
3296
3297 296 par = stream->codecpar;
3298 296 dec_ctx = ist->dec_ctx;
3299
2/2
✓ Branch 1 taken 293 times.
✓ Branch 2 taken 3 times.
296 if (cd = avcodec_descriptor_get(par->codec_id)) {
3300 293 print_str("codec_name", cd->name);
3301
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 283 times.
293 if (!do_bitexact) {
3302
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 print_str("codec_long_name",
3303 cd->long_name ? cd->long_name : "unknown");
3304 }
3305 } else {
3306 3 print_str_opt("codec_name", "unknown");
3307
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!do_bitexact) {
3308 print_str_opt("codec_long_name", "unknown");
3309 }
3310 }
3311
3312
4/4
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 286 times.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 1 times.
296 if (!do_bitexact && (profile = avcodec_profile_name(par->codec_id, par->profile)))
3313 9 print_str("profile", profile);
3314 else {
3315
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 221 times.
287 if (par->profile != AV_PROFILE_UNKNOWN) {
3316 char profile_num[12];
3317 66 snprintf(profile_num, sizeof(profile_num), "%d", par->profile);
3318 66 print_str("profile", profile_num);
3319 } else
3320 221 print_str_opt("profile", "unknown");
3321 }
3322
3323 296 s = av_get_media_type_string(par->codec_type);
3324
1/2
✓ Branch 0 taken 296 times.
✗ Branch 1 not taken.
296 if (s) print_str ("codec_type", s);
3325 else print_str_opt("codec_type", "unknown");
3326
3327 /* print AVI/FourCC tag */
3328 296 print_str("codec_tag_string", av_fourcc2str(par->codec_tag));
3329 296 print_fmt("codec_tag", "0x%04"PRIx32, par->codec_tag);
3330
3331
4/4
✓ Branch 0 taken 97 times.
✓ Branch 1 taken 185 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 7 times.
296 switch (par->codec_type) {
3332 97 case AVMEDIA_TYPE_VIDEO:
3333 97 print_int("width", par->width);
3334 97 print_int("height", par->height);
3335
1/2
✓ Branch 0 taken 97 times.
✗ Branch 1 not taken.
97 if (dec_ctx) {
3336 97 print_int("coded_width", dec_ctx->coded_width);
3337 97 print_int("coded_height", dec_ctx->coded_height);
3338 97 print_int("closed_captions", !!(dec_ctx->properties & FF_CODEC_PROPERTY_CLOSED_CAPTIONS));
3339 97 print_int("film_grain", !!(dec_ctx->properties & FF_CODEC_PROPERTY_FILM_GRAIN));
3340 }
3341 97 print_int("has_b_frames", par->video_delay);
3342 97 sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, NULL);
3343
2/2
✓ Branch 0 taken 73 times.
✓ Branch 1 taken 24 times.
97 if (sar.num) {
3344 73 print_q("sample_aspect_ratio", sar, ':');
3345 73 av_reduce(&dar.num, &dar.den,
3346 73 (int64_t) par->width * sar.num,
3347 73 (int64_t) par->height * sar.den,
3348 1024*1024);
3349 73 print_q("display_aspect_ratio", dar, ':');
3350 } else {
3351 24 print_str_opt("sample_aspect_ratio", "N/A");
3352 24 print_str_opt("display_aspect_ratio", "N/A");
3353 }
3354 97 s = av_get_pix_fmt_name(par->format);
3355
2/2
✓ Branch 0 taken 95 times.
✓ Branch 1 taken 2 times.
97 if (s) print_str ("pix_fmt", s);
3356 2 else print_str_opt("pix_fmt", "unknown");
3357 97 print_int("level", par->level);
3358
3359 97 print_color_range(w, par->color_range);
3360 97 print_color_space(w, par->color_space);
3361 97 print_color_trc(w, par->color_trc);
3362 97 print_primaries(w, par->color_primaries);
3363 97 print_chroma_location(w, par->chroma_location);
3364
3365
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 70 times.
97 if (par->field_order == AV_FIELD_PROGRESSIVE)
3366 27 print_str("field_order", "progressive");
3367
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 61 times.
70 else if (par->field_order == AV_FIELD_TT)
3368 9 print_str("field_order", "tt");
3369
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 60 times.
61 else if (par->field_order == AV_FIELD_BB)
3370 1 print_str("field_order", "bb");
3371
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60 times.
60 else if (par->field_order == AV_FIELD_TB)
3372 print_str("field_order", "tb");
3373
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60 times.
60 else if (par->field_order == AV_FIELD_BT)
3374 print_str("field_order", "bt");
3375 else
3376 60 print_str_opt("field_order", "unknown");
3377
3378
1/2
✓ Branch 0 taken 97 times.
✗ Branch 1 not taken.
97 if (dec_ctx)
3379 97 print_int("refs", dec_ctx->refs);
3380 97 break;
3381
3382 185 case AVMEDIA_TYPE_AUDIO:
3383 185 s = av_get_sample_fmt_name(par->format);
3384
1/2
✓ Branch 0 taken 185 times.
✗ Branch 1 not taken.
185 if (s) print_str ("sample_fmt", s);
3385 else print_str_opt("sample_fmt", "unknown");
3386 185 print_val("sample_rate", par->sample_rate, unit_hertz_str);
3387 185 print_int("channels", par->ch_layout.nb_channels);
3388
3389
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 25 times.
185 if (par->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
3390 160 av_channel_layout_describe(&par->ch_layout, val_str, sizeof(val_str));
3391 160 print_str ("channel_layout", val_str);
3392 } else {
3393 25 print_str_opt("channel_layout", "unknown");
3394 }
3395
3396 185 print_int("bits_per_sample", av_get_bits_per_sample(par->codec_id));
3397
3398 185 print_int("initial_padding", par->initial_padding);
3399 185 break;
3400
3401 7 case AVMEDIA_TYPE_SUBTITLE:
3402
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (par->width)
3403 print_int("width", par->width);
3404 else
3405 7 print_str_opt("width", "N/A");
3406
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (par->height)
3407 print_int("height", par->height);
3408 else
3409 7 print_str_opt("height", "N/A");
3410 7 break;
3411 }
3412
3413
2/2
✓ Branch 0 taken 293 times.
✓ Branch 1 taken 3 times.
296 if (show_private_data) {
3414
4/4
✓ Branch 0 taken 284 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 222 times.
✓ Branch 3 taken 62 times.
293 if (dec_ctx && dec_ctx->codec->priv_class)
3415 222 print_private_data(w, dec_ctx->priv_data);
3416
2/2
✓ Branch 0 taken 173 times.
✓ Branch 1 taken 120 times.
293 if (fmt_ctx->iformat->priv_class)
3417 173 print_private_data(w, fmt_ctx->priv_data);
3418 }
3419
3420
2/2
✓ Branch 0 taken 185 times.
✓ Branch 1 taken 111 times.
296 if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS) print_fmt ("id", "0x%x", stream->id);
3421 111 else print_str_opt("id", "N/A");
3422 296 print_q("r_frame_rate", stream->r_frame_rate, '/');
3423 296 print_q("avg_frame_rate", stream->avg_frame_rate, '/');
3424 296 print_q("time_base", stream->time_base, '/');
3425 296 print_ts ("start_pts", stream->start_time);
3426 296 print_time("start_time", stream->start_time, &stream->time_base);
3427 296 print_ts ("duration_ts", stream->duration);
3428 296 print_time("duration", stream->duration, &stream->time_base);
3429
2/2
✓ Branch 0 taken 81 times.
✓ Branch 1 taken 215 times.
296 if (par->bit_rate > 0) print_val ("bit_rate", par->bit_rate, unit_bit_per_second_str);
3430 215 else print_str_opt("bit_rate", "N/A");
3431
3/4
✓ Branch 0 taken 287 times.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 287 times.
296 if (dec_ctx && dec_ctx->rc_max_rate > 0)
3432 print_val ("max_bit_rate", dec_ctx->rc_max_rate, unit_bit_per_second_str);
3433 else
3434 296 print_str_opt("max_bit_rate", "N/A");
3435
4/4
✓ Branch 0 taken 287 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 142 times.
✓ Branch 3 taken 145 times.
296 if (dec_ctx && dec_ctx->bits_per_raw_sample > 0) print_fmt("bits_per_raw_sample", "%d", dec_ctx->bits_per_raw_sample);
3436 154 else print_str_opt("bits_per_raw_sample", "N/A");
3437
2/2
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 251 times.
296 if (stream->nb_frames) print_fmt ("nb_frames", "%"PRId64, stream->nb_frames);
3438 251 else print_str_opt("nb_frames", "N/A");
3439
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 263 times.
296 if (nb_streams_frames[stream_idx]) print_fmt ("nb_read_frames", "%"PRIu64, nb_streams_frames[stream_idx]);
3440 263 else print_str_opt("nb_read_frames", "N/A");
3441
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 234 times.
296 if (nb_streams_packets[stream_idx]) print_fmt ("nb_read_packets", "%"PRIu64, nb_streams_packets[stream_idx]);
3442 234 else print_str_opt("nb_read_packets", "N/A");
3443
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 296 times.
296 if (do_show_data)
3444 writer_print_data(w, "extradata", par->extradata,
3445 par->extradata_size);
3446
3447
2/2
✓ Branch 0 taken 198 times.
✓ Branch 1 taken 98 times.
296 if (par->extradata_size > 0) {
3448 198 print_int("extradata_size", par->extradata_size);
3449 198 writer_print_data_hash(w, "extradata_hash", par->extradata,
3450 par->extradata_size);
3451 }
3452
3453 /* Print disposition information */
3454
2/2
✓ Branch 0 taken 227 times.
✓ Branch 1 taken 69 times.
296 if (do_show_stream_disposition) {
3455
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 227 times.
227 av_assert0(container < FF_ARRAY_ELEMS(section_disposition));
3456 227 print_dispositions(w, stream->disposition, section_disposition[container]);
3457 }
3458
3459
2/2
✓ Branch 0 taken 97 times.
✓ Branch 1 taken 199 times.
296 if (do_show_stream_tags) {
3460
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 97 times.
97 av_assert0(container < FF_ARRAY_ELEMS(section_tags));
3461 97 ret = show_tags(w, stream->metadata, section_tags[container]);
3462 }
3463
3464
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 262 times.
296 if (stream->codecpar->nb_coded_side_data) {
3465 34 writer_print_section_header(w, NULL, SECTION_ID_STREAM_SIDE_DATA_LIST);
3466
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 34 times.
80 for (int i = 0; i < stream->codecpar->nb_coded_side_data; i++) {
3467 46 print_pkt_side_data(w, stream->codecpar, &stream->codecpar->coded_side_data[i],
3468 SECTION_ID_STREAM_SIDE_DATA);
3469 46 writer_print_section_footer(w);
3470 }
3471 34 writer_print_section_footer(w);
3472 }
3473
3474 296 writer_print_section_footer(w);
3475 296 av_bprint_finalize(&pbuf, NULL);
3476 296 fflush(stdout);
3477
3478 296 return ret;
3479 }
3480
3481 87 static int show_streams(WriterContext *w, InputFile *ifile)
3482 {
3483 87 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
3484 87 int i, ret = 0;
3485
3486 87 writer_print_section_header(w, NULL, SECTION_ID_STREAMS);
3487
2/2
✓ Branch 0 taken 187 times.
✓ Branch 1 taken 87 times.
274 for (i = 0; i < ifile->nb_streams; i++)
3488
2/2
✓ Branch 0 taken 177 times.
✓ Branch 1 taken 10 times.
187 if (selected_streams[i]) {
3489 177 ret = show_stream(w, fmt_ctx, i, &ifile->streams[i], 0);
3490
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 177 times.
177 if (ret < 0)
3491 break;
3492 }
3493 87 writer_print_section_footer(w);
3494
3495 87 return ret;
3496 }
3497
3498 3 static int show_program(WriterContext *w, InputFile *ifile, AVProgram *program)
3499 {
3500 3 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
3501 3 int i, ret = 0;
3502
3503 3 writer_print_section_header(w, NULL, SECTION_ID_PROGRAM);
3504 3 print_int("program_id", program->id);
3505 3 print_int("program_num", program->program_num);
3506 3 print_int("nb_streams", program->nb_stream_indexes);
3507 3 print_int("pmt_pid", program->pmt_pid);
3508 3 print_int("pcr_pid", program->pcr_pid);
3509
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (do_show_program_tags)
3510 ret = show_tags(w, program->metadata, SECTION_ID_PROGRAM_TAGS);
3511
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (ret < 0)
3512 goto end;
3513
3514 3 writer_print_section_header(w, NULL, SECTION_ID_PROGRAM_STREAMS);
3515
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
12 for (i = 0; i < program->nb_stream_indexes; i++) {
3516
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 if (selected_streams[program->stream_index[i]]) {
3517 8 ret = show_stream(w, fmt_ctx, program->stream_index[i], &ifile->streams[program->stream_index[i]], IN_PROGRAM);
3518
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (ret < 0)
3519 break;
3520 }
3521 }
3522 3 writer_print_section_footer(w);
3523
3524 3 end:
3525 3 writer_print_section_footer(w);
3526 3 return ret;
3527 }
3528
3529 51 static int show_programs(WriterContext *w, InputFile *ifile)
3530 {
3531 51 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
3532 51 int i, ret = 0;
3533
3534 51 writer_print_section_header(w, NULL, SECTION_ID_PROGRAMS);
3535
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 51 times.
54 for (i = 0; i < fmt_ctx->nb_programs; i++) {
3536 3 AVProgram *program = fmt_ctx->programs[i];
3537
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!program)
3538 continue;
3539 3 ret = show_program(w, ifile, program);
3540
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (ret < 0)
3541 break;
3542 }
3543 51 writer_print_section_footer(w);
3544 51 return ret;
3545 }
3546
3547 3 static void print_tile_grid_params(WriterContext *w, const AVStreamGroup *stg,
3548 const AVStreamGroupTileGrid *tile_grid)
3549 {
3550 3 writer_print_section_header(w, stg, SECTION_ID_STREAM_GROUP_COMPONENT);
3551 3 print_int("nb_tiles", tile_grid->nb_tiles);
3552 3 print_int("coded_width", tile_grid->coded_width);
3553 3 print_int("coded_height", tile_grid->coded_height);
3554 3 print_int("horizontal_offset", tile_grid->horizontal_offset);
3555 3 print_int("vertical_offset", tile_grid->vertical_offset);
3556 3 print_int("width", tile_grid->width);
3557 3 print_int("height", tile_grid->height);
3558 3 writer_print_section_header(w, NULL, SECTION_ID_STREAM_GROUP_SUBCOMPONENTS);
3559
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 3 times.
11 for (int i = 0; i < tile_grid->nb_tiles; i++) {
3560 8 writer_print_section_header(w, "tile_offset", SECTION_ID_STREAM_GROUP_SUBCOMPONENT);
3561 8 print_int("stream_index", tile_grid->offsets[i].idx);
3562 8 print_int("tile_horizontal_offset", tile_grid->offsets[i].horizontal);
3563 8 print_int("tile_vertical_offset", tile_grid->offsets[i].vertical);
3564 8 writer_print_section_footer(w);
3565 }
3566 3 writer_print_section_footer(w);
3567 3 writer_print_section_footer(w);
3568 3 }
3569
3570 37 static void print_iamf_param_definition(WriterContext *w, const char *name,
3571 const AVIAMFParamDefinition *param, SectionID section_id)
3572 {
3573 SectionID subsection_id, parameter_section_id;
3574 37 subsection_id = sections[section_id].children_ids[0];
3575
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37 times.
37 av_assert0(subsection_id != -1);
3576 37 parameter_section_id = sections[subsection_id].children_ids[0];
3577
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37 times.
37 av_assert0(parameter_section_id != -1);
3578 37 writer_print_section_header(w, "IAMF Param Definition", section_id);
3579 37 print_str("name", name);
3580 37 print_int("nb_subblocks", param->nb_subblocks);
3581 37 print_int("type", param->type);
3582 37 print_int("parameter_id", param->parameter_id);
3583 37 print_int("parameter_rate", param->parameter_rate);
3584 37 print_int("duration", param->duration);
3585 37 print_int("constant_subblock_duration", param->constant_subblock_duration);
3586
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 28 times.
37 if (param->nb_subblocks > 0)
3587 9 writer_print_section_header(w, NULL, subsection_id);
3588
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 37 times.
46 for (int i = 0; i < param->nb_subblocks; i++) {
3589 9 const void *subblock = av_iamf_param_definition_get_subblock(param, i);
3590
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
9 switch(param->type) {
3591 case AV_IAMF_PARAMETER_DEFINITION_MIX_GAIN: {
3592 const AVIAMFMixGain *mix = subblock;
3593 writer_print_section_header(w, "IAMF Mix Gain Parameters", parameter_section_id);
3594 print_int("subblock_duration", mix->subblock_duration);
3595 print_int("animation_type", mix->animation_type);
3596 print_q("start_point_value", mix->start_point_value, '/');
3597 print_q("end_point_value", mix->end_point_value, '/');
3598 print_q("control_point_value", mix->control_point_value, '/');
3599 print_q("control_point_relative_time", mix->control_point_relative_time, '/');
3600 writer_print_section_footer(w); // parameter_section_id
3601 break;
3602 }
3603 7 case AV_IAMF_PARAMETER_DEFINITION_DEMIXING: {
3604 7 const AVIAMFDemixingInfo *demix = subblock;
3605 7 writer_print_section_header(w, "IAMF Demixing Info", parameter_section_id);
3606 7 print_int("subblock_duration", demix->subblock_duration);
3607 7 print_int("dmixp_mode", demix->dmixp_mode);
3608 7 writer_print_section_footer(w); // parameter_section_id
3609 7 break;
3610 }
3611 2 case AV_IAMF_PARAMETER_DEFINITION_RECON_GAIN: {
3612 2 const AVIAMFReconGain *recon = subblock;
3613 2 writer_print_section_header(w, "IAMF Recon Gain", parameter_section_id);
3614 2 print_int("subblock_duration", recon->subblock_duration);
3615 2 writer_print_section_footer(w); // parameter_section_id
3616 2 break;
3617 }
3618 }
3619 }
3620
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 28 times.
37 if (param->nb_subblocks > 0)
3621 9 writer_print_section_footer(w); // subsection_id
3622 37 writer_print_section_footer(w); // section_id
3623 37 }
3624
3625 12 static void print_iamf_audio_element_params(WriterContext *w, const AVStreamGroup *stg,
3626 const AVIAMFAudioElement *audio_element)
3627 {
3628 12 writer_print_section_header(w, stg, SECTION_ID_STREAM_GROUP_COMPONENT);
3629 12 print_int("nb_layers", audio_element->nb_layers);
3630 12 print_int("audio_element_type", audio_element->audio_element_type);
3631 12 print_int("default_w", audio_element->default_w);
3632 12 writer_print_section_header(w, NULL, SECTION_ID_STREAM_GROUP_SUBCOMPONENTS);
3633
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 12 times.
41 for (int i = 0; i < audio_element->nb_layers; i++) {
3634 29 const AVIAMFLayer *layer = audio_element->layers[i];
3635 char val_str[128];
3636 29 writer_print_section_header(w, "IAMF Audio Layer", SECTION_ID_STREAM_GROUP_SUBCOMPONENT);
3637 29 av_channel_layout_describe(&layer->ch_layout, val_str, sizeof(val_str));
3638 29 print_str("channel_layout", val_str);
3639
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 2 times.
29 if (audio_element->audio_element_type == AV_IAMF_AUDIO_ELEMENT_TYPE_CHANNEL) {
3640 27 print_int("output_gain_flags", layer->output_gain_flags);
3641 27 print_q("output_gain", layer->output_gain, '/');
3642
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 } else if (audio_element->audio_element_type == AV_IAMF_AUDIO_ELEMENT_TYPE_SCENE)
3643 2 print_int("ambisonics_mode", layer->ambisonics_mode);
3644 29 writer_print_section_footer(w); // SECTION_ID_STREAM_GROUP_SUBCOMPONENT
3645 }
3646
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 5 times.
12 if (audio_element->demixing_info)
3647 7 print_iamf_param_definition(w, "demixing_info", audio_element->demixing_info,
3648 SECTION_ID_STREAM_GROUP_SUBCOMPONENT);
3649
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10 times.
12 if (audio_element->recon_gain_info)
3650 2 print_iamf_param_definition(w, "recon_gain_info", audio_element->recon_gain_info,
3651 SECTION_ID_STREAM_GROUP_SUBCOMPONENT);
3652 12 writer_print_section_footer(w); // SECTION_ID_STREAM_GROUP_SUBCOMPONENTS
3653 12 writer_print_section_footer(w); // SECTION_ID_STREAM_GROUP_COMPONENT
3654 12 }
3655
3656 14 static void print_iamf_submix_params(WriterContext *w, const AVIAMFSubmix *submix)
3657 {
3658 14 writer_print_section_header(w, "IAMF Submix", SECTION_ID_STREAM_GROUP_SUBCOMPONENT);
3659 14 print_int("nb_elements", submix->nb_elements);
3660 14 print_int("nb_layouts", submix->nb_layouts);
3661 14 print_q("default_mix_gain", submix->default_mix_gain, '/');
3662 14 writer_print_section_header(w, NULL, SECTION_ID_STREAM_GROUP_PIECES);
3663
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 14 times.
28 for (int i = 0; i < submix->nb_elements; i++) {
3664 14 const AVIAMFSubmixElement *element = submix->elements[i];
3665 14 writer_print_section_header(w, "IAMF Submix Element", SECTION_ID_STREAM_GROUP_PIECE);
3666 14 print_int("stream_id", element->audio_element_id);
3667 14 print_q("default_mix_gain", element->default_mix_gain, '/');
3668 14 print_int("headphones_rendering_mode", element->headphones_rendering_mode);
3669 14 writer_print_section_header(w, NULL, SECTION_ID_STREAM_GROUP_SUBPIECES);
3670
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if (element->annotations) {
3671 14 const AVDictionaryEntry *annotation = NULL;
3672 14 writer_print_section_header(w, "IAMF Annotations", SECTION_ID_STREAM_GROUP_SUBPIECE);
3673
2/2
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 14 times.
28 while (annotation = av_dict_iterate(element->annotations, annotation))
3674 14 print_str(annotation->key, annotation->value);
3675 14 writer_print_section_footer(w); // SECTION_ID_STREAM_GROUP_SUBPIECE
3676 }
3677
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if (element->element_mix_config)
3678 14 print_iamf_param_definition(w, "element_mix_config", element->element_mix_config,
3679 SECTION_ID_STREAM_GROUP_SUBPIECE);
3680 14 writer_print_section_footer(w); // SECTION_ID_STREAM_GROUP_SUBPIECES
3681 14 writer_print_section_footer(w); // SECTION_ID_STREAM_GROUP_PIECE
3682 }
3683
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if (submix->output_mix_config)
3684 14 print_iamf_param_definition(w, "output_mix_config", submix->output_mix_config,
3685 SECTION_ID_STREAM_GROUP_PIECE);
3686
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 14 times.
45 for (int i = 0; i < submix->nb_layouts; i++) {
3687 31 const AVIAMFSubmixLayout *layout = submix->layouts[i];
3688 char val_str[128];
3689 31 writer_print_section_header(w, "IAMF Submix Layout", SECTION_ID_STREAM_GROUP_PIECE);
3690 31 av_channel_layout_describe(&layout->sound_system, val_str, sizeof(val_str));
3691 31 print_str("sound_system", val_str);
3692 31 print_q("integrated_loudness", layout->integrated_loudness, '/');
3693 31 print_q("digital_peak", layout->digital_peak, '/');
3694 31 print_q("true_peak", layout->true_peak, '/');
3695 31 print_q("dialogue_anchored_loudness", layout->dialogue_anchored_loudness, '/');
3696 31 print_q("album_anchored_loudness", layout->album_anchored_loudness, '/');
3697 31 writer_print_section_footer(w); // SECTION_ID_STREAM_GROUP_PIECE
3698 }
3699 14 writer_print_section_footer(w); // SECTION_ID_STREAM_GROUP_PIECES
3700 14 writer_print_section_footer(w); // SECTION_ID_STREAM_GROUP_SUBCOMPONENT
3701 14 }
3702
3703 12 static void print_iamf_mix_presentation_params(WriterContext *w, const AVStreamGroup *stg,
3704 const AVIAMFMixPresentation *mix_presentation)
3705 {
3706 12 writer_print_section_header(w, stg, SECTION_ID_STREAM_GROUP_COMPONENT);
3707 12 print_int("nb_submixes", mix_presentation->nb_submixes);
3708 12 writer_print_section_header(w, NULL, SECTION_ID_STREAM_GROUP_SUBCOMPONENTS);
3709
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (mix_presentation->annotations) {
3710 12 const AVDictionaryEntry *annotation = NULL;
3711 12 writer_print_section_header(w, "IAMF Annotations", SECTION_ID_STREAM_GROUP_SUBCOMPONENT);
3712
2/2
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 12 times.
24 while (annotation = av_dict_iterate(mix_presentation->annotations, annotation))
3713 12 print_str(annotation->key, annotation->value);
3714 12 writer_print_section_footer(w); // SECTION_ID_STREAM_GROUP_SUBCOMPONENT
3715 }
3716
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 12 times.
26 for (int i = 0; i < mix_presentation->nb_submixes; i++)
3717 14 print_iamf_submix_params(w, mix_presentation->submixes[i]);
3718 12 writer_print_section_footer(w); // SECTION_ID_STREAM_GROUP_SUBCOMPONENTS
3719 12 writer_print_section_footer(w); // SECTION_ID_STREAM_GROUP_COMPONENT
3720 12 }
3721
3722 27 static void print_stream_group_params(WriterContext *w, AVStreamGroup *stg)
3723 {
3724 27 writer_print_section_header(w, NULL, SECTION_ID_STREAM_GROUP_COMPONENTS);
3725
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 24 times.
27 if (stg->type == AV_STREAM_GROUP_PARAMS_TILE_GRID)
3726 3 print_tile_grid_params(w, stg, stg->params.tile_grid);
3727
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 else if (stg->type == AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT)
3728 12 print_iamf_audio_element_params(w, stg, stg->params.iamf_audio_element);
3729
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 else if (stg->type == AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION)
3730 12 print_iamf_mix_presentation_params(w, stg, stg->params.iamf_mix_presentation);
3731 27 writer_print_section_footer(w); // SECTION_ID_STREAM_GROUP_COMPONENTS
3732 27 }
3733
3734 27 static int show_stream_group(WriterContext *w, InputFile *ifile, AVStreamGroup *stg)
3735 {
3736 27 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
3737 AVBPrint pbuf;
3738 27 int i, ret = 0;
3739
3740 27 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
3741 27 writer_print_section_header(w, NULL, SECTION_ID_STREAM_GROUP);
3742 27 print_int("index", stg->index);
3743
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS) print_fmt ("id", "0x%"PRIx64, stg->id);
3744 else print_str_opt("id", "N/A");
3745 27 print_int("nb_streams", stg->nb_streams);
3746
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 if (stg->type != AV_STREAM_GROUP_PARAMS_NONE)
3747 27 print_str("type", av_x_if_null(avformat_stream_group_name(stg->type), "unknown"));
3748 else
3749 print_str_opt("type", "unknown");
3750
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 if (do_show_stream_group_components)
3751 27 print_stream_group_params(w, stg);
3752
3753 /* Print disposition information */
3754
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 14 times.
27 if (do_show_stream_group_disposition)
3755 13 print_dispositions(w, stg->disposition, SECTION_ID_STREAM_GROUP_DISPOSITION);
3756
3757
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 14 times.
27 if (do_show_stream_group_tags)
3758 13 ret = show_tags(w, stg->metadata, SECTION_ID_STREAM_GROUP_TAGS);
3759
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 if (ret < 0)
3760 goto end;
3761
3762 27 writer_print_section_header(w, NULL, SECTION_ID_STREAM_GROUP_STREAMS);
3763
2/2
✓ Branch 0 taken 111 times.
✓ Branch 1 taken 27 times.
138 for (i = 0; i < stg->nb_streams; i++) {
3764
1/2
✓ Branch 0 taken 111 times.
✗ Branch 1 not taken.
111 if (selected_streams[stg->streams[i]->index]) {
3765 111 ret = show_stream(w, fmt_ctx, stg->streams[i]->index, &ifile->streams[stg->streams[i]->index], IN_STREAM_GROUP);
3766
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 111 times.
111 if (ret < 0)
3767 break;
3768 }
3769 }
3770 27 writer_print_section_footer(w);
3771
3772 27 end:
3773 27 av_bprint_finalize(&pbuf, NULL);
3774 27 writer_print_section_footer(w);
3775 27 return ret;
3776 }
3777
3778 64 static int show_stream_groups(WriterContext *w, InputFile *ifile)
3779 {
3780 64 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
3781 64 int i, ret = 0;
3782
3783 64 writer_print_section_header(w, NULL, SECTION_ID_STREAM_GROUPS);
3784
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 64 times.
91 for (i = 0; i < fmt_ctx->nb_stream_groups; i++) {
3785 27 AVStreamGroup *stg = fmt_ctx->stream_groups[i];
3786
3787 27 ret = show_stream_group(w, ifile, stg);
3788
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 if (ret < 0)
3789 break;
3790 }
3791 64 writer_print_section_footer(w);
3792 64 return ret;
3793 }
3794
3795 5 static int show_chapters(WriterContext *w, InputFile *ifile)
3796 {
3797 5 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
3798 5 int i, ret = 0;
3799
3800 5 writer_print_section_header(w, NULL, SECTION_ID_CHAPTERS);
3801
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 5 times.
27 for (i = 0; i < fmt_ctx->nb_chapters; i++) {
3802 22 AVChapter *chapter = fmt_ctx->chapters[i];
3803
3804 22 writer_print_section_header(w, NULL, SECTION_ID_CHAPTER);
3805 22 print_int("id", chapter->id);
3806 22 print_q ("time_base", chapter->time_base, '/');
3807 22 print_int("start", chapter->start);
3808 22 print_time("start_time", chapter->start, &chapter->time_base);
3809 22 print_int("end", chapter->end);
3810 22 print_time("end_time", chapter->end, &chapter->time_base);
3811
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if (do_show_chapter_tags)
3812 22 ret = show_tags(w, chapter->metadata, SECTION_ID_CHAPTER_TAGS);
3813 22 writer_print_section_footer(w);
3814 }
3815 5 writer_print_section_footer(w);
3816
3817 5 return ret;
3818 }
3819
3820 42 static int show_format(WriterContext *w, InputFile *ifile)
3821 {
3822 42 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
3823 char val_str[128];
3824
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 int64_t size = fmt_ctx->pb ? avio_size(fmt_ctx->pb) : -1;
3825 42 int ret = 0;
3826
3827 42 writer_print_section_header(w, NULL, SECTION_ID_FORMAT);
3828 42 print_str_validate("filename", fmt_ctx->url);
3829 42 print_int("nb_streams", fmt_ctx->nb_streams);
3830 42 print_int("nb_programs", fmt_ctx->nb_programs);
3831 42 print_int("nb_stream_groups", fmt_ctx->nb_stream_groups);
3832 42 print_str("format_name", fmt_ctx->iformat->name);
3833
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
42 if (!do_bitexact) {
3834 if (fmt_ctx->iformat->long_name) print_str ("format_long_name", fmt_ctx->iformat->long_name);
3835 else print_str_opt("format_long_name", "unknown");
3836 }
3837 42 print_time("start_time", fmt_ctx->start_time, &AV_TIME_BASE_Q);
3838 42 print_time("duration", fmt_ctx->duration, &AV_TIME_BASE_Q);
3839
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 if (size >= 0) print_val ("size", size, unit_byte_str);
3840 else print_str_opt("size", "N/A");
3841
2/2
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 1 times.
42 if (fmt_ctx->bit_rate > 0) print_val ("bit_rate", fmt_ctx->bit_rate, unit_bit_per_second_str);
3842 1 else print_str_opt("bit_rate", "N/A");
3843 42 print_int("probe_score", fmt_ctx->probe_score);
3844
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 8 times.
42 if (do_show_format_tags)
3845 34 ret = show_tags(w, fmt_ctx->metadata, SECTION_ID_FORMAT_TAGS);
3846
3847 42 writer_print_section_footer(w);
3848 42 fflush(stdout);
3849 42 return ret;
3850 }
3851
3852 static void show_error(WriterContext *w, int err)
3853 {
3854 writer_print_section_header(w, NULL, SECTION_ID_ERROR);
3855 print_int("code", err);
3856 print_str("string", av_err2str(err));
3857 writer_print_section_footer(w);
3858 }
3859
3860 152 static int open_input_file(InputFile *ifile, const char *filename,
3861 const char *print_filename)
3862 {
3863 int err, i;
3864 152 AVFormatContext *fmt_ctx = NULL;
3865 152 const AVDictionaryEntry *t = NULL;
3866 152 int scan_all_pmts_set = 0;
3867
3868 152 fmt_ctx = avformat_alloc_context();
3869
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
152 if (!fmt_ctx)
3870 return AVERROR(ENOMEM);
3871
3872
1/2
✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
152 if (!av_dict_get(format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
3873 152 av_dict_set(&format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
3874 152 scan_all_pmts_set = 1;
3875 }
3876
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 152 times.
152 if ((err = avformat_open_input(&fmt_ctx, filename,
3877 iformat, &format_opts)) < 0) {
3878 print_error(filename, err);
3879 return err;
3880 }
3881
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 136 times.
152 if (print_filename) {
3882 16 av_freep(&fmt_ctx->url);
3883 16 fmt_ctx->url = av_strdup(print_filename);
3884 }
3885 152 ifile->fmt_ctx = fmt_ctx;
3886
1/2
✓ Branch 0 taken 152 times.
✗ Branch 1 not taken.
152 if (scan_all_pmts_set)
3887 152 av_dict_set(&format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
3888
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 152 times.
152 while ((t = av_dict_iterate(format_opts, t)))
3889 av_log(NULL, AV_LOG_WARNING, "Option %s skipped - not known to demuxer.\n", t->key);
3890
3891
1/2
✓ Branch 0 taken 152 times.
✗ Branch 1 not taken.
152 if (find_stream_info) {
3892 AVDictionary **opts;
3893 152 int orig_nb_streams = fmt_ctx->nb_streams;
3894
3895 152 err = setup_find_stream_info_opts(fmt_ctx, codec_opts, &opts);
3896
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
152 if (err < 0)
3897 return err;
3898
3899 152 err = avformat_find_stream_info(fmt_ctx, opts);
3900
3901
2/2
✓ Branch 0 taken 285 times.
✓ Branch 1 taken 152 times.
437 for (i = 0; i < orig_nb_streams; i++)
3902 285 av_dict_free(&opts[i]);
3903 152 av_freep(&opts);
3904
3905
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
152 if (err < 0) {
3906 print_error(filename, err);
3907 return err;
3908 }
3909 }
3910
3911 152 av_dump_format(fmt_ctx, 0, filename, 0);
3912
3913 152 ifile->streams = av_calloc(fmt_ctx->nb_streams, sizeof(*ifile->streams));
3914
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
152 if (!ifile->streams)
3915 exit(1);
3916 152 ifile->nb_streams = fmt_ctx->nb_streams;
3917
3918 /* bind a decoder to each input stream */
3919
2/2
✓ Branch 0 taken 296 times.
✓ Branch 1 taken 152 times.
448 for (i = 0; i < fmt_ctx->nb_streams; i++) {
3920 296 InputStream *ist = &ifile->streams[i];
3921 296 AVStream *stream = fmt_ctx->streams[i];
3922 const AVCodec *codec;
3923
3924 296 ist->st = stream;
3925
3926
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 296 times.
296 if (stream->codecpar->codec_id == AV_CODEC_ID_PROBE) {
3927 av_log(NULL, AV_LOG_WARNING,
3928 "Failed to probe codec for input stream %d\n",
3929 stream->index);
3930 continue;
3931 }
3932
3933 296 codec = avcodec_find_decoder(stream->codecpar->codec_id);
3934
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 279 times.
296 if (!codec) {
3935 17 av_log(NULL, AV_LOG_WARNING,
3936 "Unsupported codec with id %d for input stream %d\n",
3937 17 stream->codecpar->codec_id, stream->index);
3938 17 continue;
3939 }
3940 {
3941 AVDictionary *opts;
3942
3943 279 err = filter_codec_opts(codec_opts, stream->codecpar->codec_id,
3944 fmt_ctx, stream, codec, &opts, NULL);
3945
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 279 times.
279 if (err < 0)
3946 exit(1);
3947
3948 279 ist->dec_ctx = avcodec_alloc_context3(codec);
3949
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 279 times.
279 if (!ist->dec_ctx)
3950 exit(1);
3951
3952 279 err = avcodec_parameters_to_context(ist->dec_ctx, stream->codecpar);
3953
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 279 times.
279 if (err < 0)
3954 exit(1);
3955
3956
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 279 times.
279 if (do_show_log) {
3957 // For loging it is needed to disable at least frame threads as otherwise
3958 // the log information would need to be reordered and matches up to contexts and frames
3959 // That is in fact possible but not trivial
3960 av_dict_set(&codec_opts, "threads", "1", 0);
3961 }
3962
3963 279 av_dict_set(&opts, "flags", "+copy_opaque", AV_DICT_MULTIKEY);
3964
3965 279 ist->dec_ctx->pkt_timebase = stream->time_base;
3966
3967
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 279 times.
279 if (avcodec_open2(ist->dec_ctx, codec, &opts) < 0) {
3968 av_log(NULL, AV_LOG_WARNING, "Could not open codec for input stream %d\n",
3969 stream->index);
3970 exit(1);
3971 }
3972
3973
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 279 times.
279 if ((t = av_dict_iterate(opts, NULL))) {
3974 av_log(NULL, AV_LOG_ERROR, "Option %s for input stream %d not found\n",
3975 t->key, stream->index);
3976 return AVERROR_OPTION_NOT_FOUND;
3977 }
3978 }
3979 }
3980
3981 152 ifile->fmt_ctx = fmt_ctx;
3982 152 return 0;
3983 }
3984
3985 152 static void close_input_file(InputFile *ifile)
3986 {
3987 int i;
3988
3989 /* close decoder for each stream */
3990
2/2
✓ Branch 0 taken 296 times.
✓ Branch 1 taken 152 times.
448 for (i = 0; i < ifile->nb_streams; i++)
3991 296 avcodec_free_context(&ifile->streams[i].dec_ctx);
3992
3993 152 av_freep(&ifile->streams);
3994 152 ifile->nb_streams = 0;
3995
3996 152 avformat_close_input(&ifile->fmt_ctx);
3997 152 }
3998
3999 152 static int probe_file(WriterContext *wctx, const char *filename,
4000 const char *print_filename)
4001 {
4002 152 InputFile ifile = { 0 };
4003 int ret, i;
4004 int section_id;
4005
4006
3/4
✓ Branch 0 taken 103 times.
✓ Branch 1 taken 49 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 103 times.
152 do_read_frames = do_show_frames || do_count_frames;
4007
3/4
✓ Branch 0 taken 111 times.
✓ Branch 1 taken 41 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 111 times.
152 do_read_packets = do_show_packets || do_count_packets;
4008
4009 152 ret = open_input_file(&ifile, filename, print_filename);
4010
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
152 if (ret < 0)
4011 goto end;
4012
4013 #define CHECK_END if (ret < 0) goto end
4014
4015 152 nb_streams = ifile.fmt_ctx->nb_streams;
4016
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 152 times.
152 REALLOCZ_ARRAY_STREAM(nb_streams_frames,0,ifile.fmt_ctx->nb_streams);
4017
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 152 times.
152 REALLOCZ_ARRAY_STREAM(nb_streams_packets,0,ifile.fmt_ctx->nb_streams);
4018
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 152 times.
152 REALLOCZ_ARRAY_STREAM(selected_streams,0,ifile.fmt_ctx->nb_streams);
4019
4020
2/2
✓ Branch 0 taken 296 times.
✓ Branch 1 taken 152 times.
448 for (i = 0; i < ifile.fmt_ctx->nb_streams; i++) {
4021
2/2
✓ Branch 0 taken 47 times.
✓ Branch 1 taken 249 times.
296 if (stream_specifier) {
4022 47 ret = avformat_match_stream_specifier(ifile.fmt_ctx,
4023 47 ifile.fmt_ctx->streams[i],
4024 stream_specifier);
4025
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
47 CHECK_END;
4026 else
4027 47 selected_streams[i] = ret;
4028 47 ret = 0;
4029 } else {
4030 249 selected_streams[i] = 1;
4031 }
4032
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 279 times.
296 if (!selected_streams[i])
4033 17 ifile.fmt_ctx->streams[i]->discard = AVDISCARD_ALL;
4034 }
4035
4036
4/4
✓ Branch 0 taken 103 times.
✓ Branch 1 taken 49 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 73 times.
152 if (do_read_frames || do_read_packets) {
4037
4/4
✓ Branch 0 taken 49 times.
✓ Branch 1 taken 30 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 38 times.
79 if (do_show_frames && do_show_packets &&
4038
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 6 times.
11 wctx->writer->flags & WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER)
4039 5 section_id = SECTION_ID_PACKETS_AND_FRAMES;
4040
4/4
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 38 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 6 times.
74 else if (do_show_packets && !do_show_frames)
4041 30 section_id = SECTION_ID_PACKETS;
4042 else // (!do_show_packets && do_show_frames)
4043 44 section_id = SECTION_ID_FRAMES;
4044
3/4
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 49 times.
✓ Branch 2 taken 30 times.
✗ Branch 3 not taken.
79 if (do_show_frames || do_show_packets)
4045 79 writer_print_section_header(wctx, NULL, section_id);
4046 79 ret = read_packets(wctx, &ifile);
4047
3/4
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 49 times.
✓ Branch 2 taken 30 times.
✗ Branch 3 not taken.
79 if (do_show_frames || do_show_packets)
4048 79 writer_print_section_footer(wctx);
4049
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 79 times.
79 CHECK_END;
4050 }
4051
4052
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 101 times.
152 if (do_show_programs) {
4053 51 ret = show_programs(wctx, &ifile);
4054
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
51 CHECK_END;
4055 }
4056
4057
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 88 times.
152 if (do_show_stream_groups) {
4058 64 ret = show_stream_groups(wctx, &ifile);
4059
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 64 times.
64 CHECK_END;
4060 }
4061
4062
2/2
✓ Branch 0 taken 87 times.
✓ Branch 1 taken 65 times.
152 if (do_show_streams) {
4063 87 ret = show_streams(wctx, &ifile);
4064
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 87 times.
87 CHECK_END;
4065 }
4066
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 147 times.
152 if (do_show_chapters) {
4067 5 ret = show_chapters(wctx, &ifile);
4068
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 CHECK_END;
4069 }
4070
2/2
✓ Branch 0 taken 110 times.
✓ Branch 1 taken 42 times.
152 if (do_show_format) {
4071 42 ret = show_format(wctx, &ifile);
4072
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 CHECK_END;
4073 }
4074
4075 152 end:
4076
1/2
✓ Branch 0 taken 152 times.
✗ Branch 1 not taken.
152 if (ifile.fmt_ctx)
4077 152 close_input_file(&ifile);
4078 152 av_freep(&nb_streams_frames);
4079 152 av_freep(&nb_streams_packets);
4080 152 av_freep(&selected_streams);
4081
4082 152 return ret;
4083 }
4084
4085 static void show_usage(void)
4086 {
4087 av_log(NULL, AV_LOG_INFO, "Simple multimedia streams analyzer\n");
4088 av_log(NULL, AV_LOG_INFO, "usage: %s [OPTIONS] INPUT_FILE\n", program_name);
4089 av_log(NULL, AV_LOG_INFO, "\n");
4090 }
4091
4092 static void ffprobe_show_program_version(WriterContext *w)
4093 {
4094 AVBPrint pbuf;
4095 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
4096
4097 writer_print_section_header(w, NULL, SECTION_ID_PROGRAM_VERSION);
4098 print_str("version", FFMPEG_VERSION);
4099 print_fmt("copyright", "Copyright (c) %d-%d the FFmpeg developers",
4100 program_birth_year, CONFIG_THIS_YEAR);
4101 print_str("compiler_ident", CC_IDENT);
4102 print_str("configuration", FFMPEG_CONFIGURATION);
4103 writer_print_section_footer(w);
4104
4105 av_bprint_finalize(&pbuf, NULL);
4106 }
4107
4108 #define SHOW_LIB_VERSION(libname, LIBNAME) \
4109 do { \
4110 if (CONFIG_##LIBNAME) { \
4111 unsigned int version = libname##_version(); \
4112 writer_print_section_header(w, NULL, SECTION_ID_LIBRARY_VERSION); \
4113 print_str("name", "lib" #libname); \
4114 print_int("major", LIB##LIBNAME##_VERSION_MAJOR); \
4115 print_int("minor", LIB##LIBNAME##_VERSION_MINOR); \
4116 print_int("micro", LIB##LIBNAME##_VERSION_MICRO); \
4117 print_int("version", version); \
4118 print_str("ident", LIB##LIBNAME##_IDENT); \
4119 writer_print_section_footer(w); \
4120 } \
4121 } while (0)
4122
4123 static void ffprobe_show_library_versions(WriterContext *w)
4124 {
4125 writer_print_section_header(w, NULL, SECTION_ID_LIBRARY_VERSIONS);
4126 SHOW_LIB_VERSION(avutil, AVUTIL);
4127 SHOW_LIB_VERSION(avcodec, AVCODEC);
4128 SHOW_LIB_VERSION(avformat, AVFORMAT);
4129 SHOW_LIB_VERSION(avdevice, AVDEVICE);
4130 SHOW_LIB_VERSION(avfilter, AVFILTER);
4131 SHOW_LIB_VERSION(swscale, SWSCALE);
4132 SHOW_LIB_VERSION(swresample, SWRESAMPLE);
4133 SHOW_LIB_VERSION(postproc, POSTPROC);
4134 writer_print_section_footer(w);
4135 }
4136
4137 #define PRINT_PIX_FMT_FLAG(flagname, name) \
4138 do { \
4139 print_int(name, !!(pixdesc->flags & AV_PIX_FMT_FLAG_##flagname)); \
4140 } while (0)
4141
4142 static void ffprobe_show_pixel_formats(WriterContext *w)
4143 {
4144 const AVPixFmtDescriptor *pixdesc = NULL;
4145 int i, n;
4146
4147 writer_print_section_header(w, NULL, SECTION_ID_PIXEL_FORMATS);
4148 while (pixdesc = av_pix_fmt_desc_next(pixdesc)) {
4149 writer_print_section_header(w, NULL, SECTION_ID_PIXEL_FORMAT);
4150 print_str("name", pixdesc->name);
4151 print_int("nb_components", pixdesc->nb_components);
4152 if ((pixdesc->nb_components >= 3) && !(pixdesc->flags & AV_PIX_FMT_FLAG_RGB)) {
4153 print_int ("log2_chroma_w", pixdesc->log2_chroma_w);
4154 print_int ("log2_chroma_h", pixdesc->log2_chroma_h);
4155 } else {
4156 print_str_opt("log2_chroma_w", "N/A");
4157 print_str_opt("log2_chroma_h", "N/A");
4158 }
4159 n = av_get_bits_per_pixel(pixdesc);
4160 if (n) print_int ("bits_per_pixel", n);
4161 else print_str_opt("bits_per_pixel", "N/A");
4162 if (do_show_pixel_format_flags) {
4163 writer_print_section_header(w, NULL, SECTION_ID_PIXEL_FORMAT_FLAGS);
4164 PRINT_PIX_FMT_FLAG(BE, "big_endian");
4165 PRINT_PIX_FMT_FLAG(PAL, "palette");
4166 PRINT_PIX_FMT_FLAG(BITSTREAM, "bitstream");
4167 PRINT_PIX_FMT_FLAG(HWACCEL, "hwaccel");
4168 PRINT_PIX_FMT_FLAG(PLANAR, "planar");
4169 PRINT_PIX_FMT_FLAG(RGB, "rgb");
4170 PRINT_PIX_FMT_FLAG(ALPHA, "alpha");
4171 writer_print_section_footer(w);
4172 }
4173 if (do_show_pixel_format_components && (pixdesc->nb_components > 0)) {
4174 writer_print_section_header(w, NULL, SECTION_ID_PIXEL_FORMAT_COMPONENTS);
4175 for (i = 0; i < pixdesc->nb_components; i++) {
4176 writer_print_section_header(w, NULL, SECTION_ID_PIXEL_FORMAT_COMPONENT);
4177 print_int("index", i + 1);
4178 print_int("bit_depth", pixdesc->comp[i].depth);
4179 writer_print_section_footer(w);
4180 }
4181 writer_print_section_footer(w);
4182 }
4183 writer_print_section_footer(w);
4184 }
4185 writer_print_section_footer(w);
4186 }
4187
4188 static int opt_show_optional_fields(void *optctx, const char *opt, const char *arg)
4189 {
4190 if (!av_strcasecmp(arg, "always")) show_optional_fields = SHOW_OPTIONAL_FIELDS_ALWAYS;
4191 else if (!av_strcasecmp(arg, "never")) show_optional_fields = SHOW_OPTIONAL_FIELDS_NEVER;
4192 else if (!av_strcasecmp(arg, "auto")) show_optional_fields = SHOW_OPTIONAL_FIELDS_AUTO;
4193
4194 if (show_optional_fields == SHOW_OPTIONAL_FIELDS_AUTO && av_strcasecmp(arg, "auto")) {
4195 double num;
4196 int ret = parse_number("show_optional_fields", arg, OPT_TYPE_INT,
4197 SHOW_OPTIONAL_FIELDS_AUTO, SHOW_OPTIONAL_FIELDS_ALWAYS, &num);
4198 if (ret < 0)
4199 return ret;
4200 show_optional_fields = num;
4201 }
4202 return 0;
4203 }
4204
4205 14 static int opt_format(void *optctx, const char *opt, const char *arg)
4206 {
4207 14 iformat = av_find_input_format(arg);
4208
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if (!iformat) {
4209 av_log(NULL, AV_LOG_ERROR, "Unknown input format: %s\n", arg);
4210 return AVERROR(EINVAL);
4211 }
4212 14 return 0;
4213 }
4214
4215 1333 static inline void mark_section_show_entries(SectionID section_id,
4216 int show_all_entries, AVDictionary *entries)
4217 {
4218 1333 struct section *section = &sections[section_id];
4219
4220 1333 section->show_all_entries = show_all_entries;
4221
2/2
✓ Branch 0 taken 1111 times.
✓ Branch 1 taken 222 times.
1333 if (show_all_entries) {
4222
2/2
✓ Branch 0 taken 870 times.
✓ Branch 1 taken 1111 times.
1981 for (const SectionID *id = section->children_ids; *id != -1; id++)
4223 870 mark_section_show_entries(*id, show_all_entries, entries);
4224 } else {
4225 222 av_dict_copy(&section->entries_to_show, entries, 0);
4226 }
4227 1333 }
4228
4229 253 static int match_section(const char *section_name,
4230 int show_all_entries, AVDictionary *entries)
4231 {
4232 253 int i, ret = 0;
4233
4234
2/2
✓ Branch 0 taken 16698 times.
✓ Branch 1 taken 253 times.
16951 for (i = 0; i < FF_ARRAY_ELEMS(sections); i++) {
4235 16698 const struct section *section = &sections[i];
4236
2/2
✓ Branch 0 taken 16478 times.
✓ Branch 1 taken 220 times.
16698 if (!strcmp(section_name, section->name) ||
4237
4/4
✓ Branch 0 taken 8244 times.
✓ Branch 1 taken 8234 times.
✓ Branch 2 taken 137 times.
✓ Branch 3 taken 8107 times.
16478 (section->unique_name && !strcmp(section_name, section->unique_name))) {
4238 357 av_log(NULL, AV_LOG_DEBUG,
4239 "'%s' matches section with unique name '%s'\n", section_name,
4240 357 (char *)av_x_if_null(section->unique_name, section->name));
4241 357 ret++;
4242 357 mark_section_show_entries(section->id, show_all_entries, entries);
4243 }
4244 }
4245 253 return ret;
4246 }
4247
4248 110 static int opt_show_entries(void *optctx, const char *opt, const char *arg)
4249 {
4250 110 const char *p = arg;
4251 110 int ret = 0;
4252
4253
2/2
✓ Branch 0 taken 253 times.
✓ Branch 1 taken 110 times.
363 while (*p) {
4254 253 AVDictionary *entries = NULL;
4255 253 char *section_name = av_get_token(&p, "=:");
4256 253 int show_all_entries = 0;
4257
4258
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 253 times.
253 if (!section_name) {
4259 av_log(NULL, AV_LOG_ERROR,
4260 "Missing section name for option '%s'\n", opt);
4261 return AVERROR(EINVAL);
4262 }
4263
4264
2/2
✓ Branch 0 taken 130 times.
✓ Branch 1 taken 123 times.
253 if (*p == '=') {
4265 130 p++;
4266
4/4
✓ Branch 0 taken 382 times.
✓ Branch 1 taken 50 times.
✓ Branch 2 taken 302 times.
✓ Branch 3 taken 80 times.
562 while (*p && *p != ':') {
4267 302 char *entry = av_get_token(&p, ",:");
4268
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 302 times.
302 if (!entry)
4269 break;
4270 302 av_log(NULL, AV_LOG_VERBOSE,
4271 "Adding '%s' to the entries to show in section '%s'\n",
4272 entry, section_name);
4273 302 av_dict_set(&entries, entry, "", AV_DICT_DONT_STRDUP_KEY);
4274
2/2
✓ Branch 0 taken 130 times.
✓ Branch 1 taken 172 times.
302 if (*p == ',')
4275 172 p++;
4276 }
4277 } else {
4278 123 show_all_entries = 1;
4279 }
4280
4281 253 ret = match_section(section_name, show_all_entries, entries);
4282
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 253 times.
253 if (ret == 0) {
4283 av_log(NULL, AV_LOG_ERROR, "No match for section '%s'\n", section_name);
4284 ret = AVERROR(EINVAL);
4285 }
4286 253 av_dict_free(&entries);
4287 253 av_free(section_name);
4288
4289
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 253 times.
253 if (ret <= 0)
4290 break;
4291
2/2
✓ Branch 0 taken 143 times.
✓ Branch 1 taken 110 times.
253 if (*p)
4292 143 p++;
4293 }
4294
4295 110 return ret;
4296 }
4297
4298 152 static int opt_input_file(void *optctx, const char *arg)
4299 {
4300
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
152 if (input_filename) {
4301 av_log(NULL, AV_LOG_ERROR,
4302 "Argument '%s' provided as input filename, but '%s' was already specified.\n",
4303 arg, input_filename);
4304 return AVERROR(EINVAL);
4305 }
4306
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
152 if (!strcmp(arg, "-"))
4307 arg = "fd:";
4308 152 input_filename = av_strdup(arg);
4309
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
152 if (!input_filename)
4310 return AVERROR(ENOMEM);
4311
4312 152 return 0;
4313 }
4314
4315 10 static int opt_input_file_i(void *optctx, const char *opt, const char *arg)
4316 {
4317 10 opt_input_file(optctx, arg);
4318 10 return 0;
4319 }
4320
4321 static int opt_output_file_o(void *optctx, const char *opt, const char *arg)
4322 {
4323 if (output_filename) {
4324 av_log(NULL, AV_LOG_ERROR,
4325 "Argument '%s' provided as output filename, but '%s' was already specified.\n",
4326 arg, output_filename);
4327 return AVERROR(EINVAL);
4328 }
4329 if (!strcmp(arg, "-"))
4330 arg = "fd:";
4331 output_filename = av_strdup(arg);
4332 if (!output_filename)
4333 return AVERROR(ENOMEM);
4334
4335 return 0;
4336 }
4337
4338 16 static int opt_print_filename(void *optctx, const char *opt, const char *arg)
4339 {
4340 16 av_freep(&print_input_filename);
4341 16 print_input_filename = av_strdup(arg);
4342
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 return print_input_filename ? 0 : AVERROR(ENOMEM);
4343 }
4344
4345 void show_help_default(const char *opt, const char *arg)
4346 {
4347 av_log_set_callback(log_callback_help);
4348 show_usage();
4349 show_help_options(options, "Main options:", 0, 0);
4350 printf("\n");
4351
4352 show_help_children(avformat_get_class(), AV_OPT_FLAG_DECODING_PARAM);
4353 show_help_children(avcodec_get_class(), AV_OPT_FLAG_DECODING_PARAM);
4354 }
4355
4356 /**
4357 * Parse interval specification, according to the format:
4358 * INTERVAL ::= [START|+START_OFFSET][%[END|+END_OFFSET]]
4359 * INTERVALS ::= INTERVAL[,INTERVALS]
4360 */
4361 4 static int parse_read_interval(const char *interval_spec,
4362 ReadInterval *interval)
4363 {
4364 4 int ret = 0;
4365 4 char *next, *p, *spec = av_strdup(interval_spec);
4366
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!spec)
4367 return AVERROR(ENOMEM);
4368
4369
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!*spec) {
4370 av_log(NULL, AV_LOG_ERROR, "Invalid empty interval specification\n");
4371 ret = AVERROR(EINVAL);
4372 goto end;
4373 }
4374
4375 4 p = spec;
4376 4 next = strchr(spec, '%');
4377
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (next)
4378 4 *next++ = 0;
4379
4380 /* parse first part */
4381
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (*p) {
4382 interval->has_start = 1;
4383
4384 if (*p == '+') {
4385 interval->start_is_offset = 1;
4386 p++;
4387 } else {
4388 interval->start_is_offset = 0;
4389 }
4390
4391 ret = av_parse_time(&interval->start, p, 1);
4392 if (ret < 0) {
4393 av_log(NULL, AV_LOG_ERROR, "Invalid interval start specification '%s'\n", p);
4394 goto end;
4395 }
4396 } else {
4397 4 interval->has_start = 0;
4398 }
4399
4400 /* parse second part */
4401 4 p = next;
4402
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
8 if (p && *p) {
4403 int64_t us;
4404 4 interval->has_end = 1;
4405
4406
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 if (*p == '+') {
4407 1 interval->end_is_offset = 1;
4408 1 p++;
4409 } else {
4410 3 interval->end_is_offset = 0;
4411 }
4412
4413
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
4 if (interval->end_is_offset && *p == '#') {
4414 long long int lli;
4415 char *tail;
4416 1 interval->duration_frames = 1;
4417 1 p++;
4418 1 lli = strtoll(p, &tail, 10);
4419
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if (*tail || lli < 0) {
4420 av_log(NULL, AV_LOG_ERROR,
4421 "Invalid or negative value '%s' for duration number of frames\n", p);
4422 goto end;
4423 }
4424 1 interval->end = lli;
4425 } else {
4426 3 interval->duration_frames = 0;
4427 3 ret = av_parse_time(&us, p, 1);
4428
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (ret < 0) {
4429 av_log(NULL, AV_LOG_ERROR, "Invalid interval end/duration specification '%s'\n", p);
4430 goto end;
4431 }
4432 3 interval->end = us;
4433 }
4434 } else {
4435 interval->has_end = 0;
4436 }
4437
4438 4 end:
4439 4 av_free(spec);
4440 4 return ret;
4441 }
4442
4443 4 static int parse_read_intervals(const char *intervals_spec)
4444 {
4445 int ret, n, i;
4446 4 char *p, *spec = av_strdup(intervals_spec);
4447
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!spec)
4448 return AVERROR(ENOMEM);
4449
4450 /* preparse specification, get number of intervals */
4451
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 4 times.
23 for (n = 0, p = spec; *p; p++)
4452
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
19 if (*p == ',')
4453 n++;
4454 4 n++;
4455
4456 4 read_intervals = av_malloc_array(n, sizeof(*read_intervals));
4457
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!read_intervals) {
4458 ret = AVERROR(ENOMEM);
4459 goto end;
4460 }
4461 4 read_intervals_nb = n;
4462
4463 /* parse intervals */
4464 4 p = spec;
4465
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 for (i = 0; p; i++) {
4466 char *next;
4467
4468
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 av_assert0(i < read_intervals_nb);
4469 4 next = strchr(p, ',');
4470
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (next)
4471 *next++ = 0;
4472
4473 4 read_intervals[i].id = i;
4474 4 ret = parse_read_interval(p, &read_intervals[i]);
4475
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (ret < 0) {
4476 av_log(NULL, AV_LOG_ERROR, "Error parsing read interval #%d '%s'\n",
4477 i, p);
4478 goto end;
4479 }
4480 4 av_log(NULL, AV_LOG_VERBOSE, "Parsed log interval ");
4481 4 log_read_interval(&read_intervals[i], NULL, AV_LOG_VERBOSE);
4482 4 p = next;
4483 }
4484
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 av_assert0(i == read_intervals_nb);
4485
4486 4 end:
4487 4 av_free(spec);
4488 4 return ret;
4489 }
4490
4491 4 static int opt_read_intervals(void *optctx, const char *opt, const char *arg)
4492 {
4493 4 return parse_read_intervals(arg);
4494 }
4495
4496 static int opt_pretty(void *optctx, const char *opt, const char *arg)
4497 {
4498 show_value_unit = 1;
4499 use_value_prefix = 1;
4500 use_byte_value_binary_prefix = 1;
4501 use_value_sexagesimal_format = 1;
4502 return 0;
4503 }
4504
4505 static void print_section(SectionID id, int level)
4506 {
4507 const SectionID *pid;
4508 const struct section *section = &sections[id];
4509 printf("%c%c%c%c",
4510 section->flags & SECTION_FLAG_IS_WRAPPER ? 'W' : '.',
4511 section->flags & SECTION_FLAG_IS_ARRAY ? 'A' : '.',
4512 section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS ? 'V' : '.',
4513 section->flags & SECTION_FLAG_HAS_TYPE ? 'T' : '.');
4514 printf("%*c %s", level * 4, ' ', section->name);
4515 if (section->unique_name)
4516 printf("/%s", section->unique_name);
4517 printf("\n");
4518
4519 for (pid = section->children_ids; *pid != -1; pid++)
4520 print_section(*pid, level+1);
4521 }
4522
4523 static int opt_sections(void *optctx, const char *opt, const char *arg)
4524 {
4525 printf("Sections:\n"
4526 "W... = Section is a wrapper (contains other sections, no local entries)\n"
4527 ".A.. = Section contains an array of elements of the same type\n"
4528 "..V. = Section may contain a variable number of fields with variable keys\n"
4529 "...T = Section contain a unique type\n"
4530 "FLAGS NAME/UNIQUE_NAME\n"
4531 "----\n");
4532 print_section(SECTION_ID_ROOT, 0);
4533 return 0;
4534 }
4535
4536 static int opt_show_versions(void *optctx, const char *opt, const char *arg)
4537 {
4538 mark_section_show_entries(SECTION_ID_PROGRAM_VERSION, 1, NULL);
4539 mark_section_show_entries(SECTION_ID_LIBRARY_VERSION, 1, NULL);
4540 return 0;
4541 }
4542
4543 #define DEFINE_OPT_SHOW_SECTION(section, target_section_id) \
4544 static int opt_show_##section(void *optctx, const char *opt, const char *arg) \
4545 { \
4546 mark_section_show_entries(SECTION_ID_##target_section_id, 1, NULL); \
4547 return 0; \
4548 }
4549
4550 4 DEFINE_OPT_SHOW_SECTION(chapters, CHAPTERS)
4551 DEFINE_OPT_SHOW_SECTION(error, ERROR)
4552 16 DEFINE_OPT_SHOW_SECTION(format, FORMAT)
4553 27 DEFINE_OPT_SHOW_SECTION(frames, FRAMES)
4554 DEFINE_OPT_SHOW_SECTION(library_versions, LIBRARY_VERSIONS)
4555 33 DEFINE_OPT_SHOW_SECTION(packets, PACKETS)
4556 DEFINE_OPT_SHOW_SECTION(pixel_formats, PIXEL_FORMATS)
4557 DEFINE_OPT_SHOW_SECTION(program_version, PROGRAM_VERSION)
4558 26 DEFINE_OPT_SHOW_SECTION(streams, STREAMS)
4559 DEFINE_OPT_SHOW_SECTION(programs, PROGRAMS)
4560 DEFINE_OPT_SHOW_SECTION(stream_groups, STREAM_GROUPS)
4561
4562 static const OptionDef real_options[] = {
4563 CMDUTILS_COMMON_OPTIONS
4564 { "f", OPT_TYPE_FUNC, OPT_FUNC_ARG, {.func_arg = opt_format}, "force format", "format" },
4565 { "unit", OPT_TYPE_BOOL, 0, {&show_value_unit}, "show unit of the displayed values" },
4566 { "prefix", OPT_TYPE_BOOL, 0, {&use_value_prefix}, "use SI prefixes for the displayed values" },
4567 { "byte_binary_prefix", OPT_TYPE_BOOL, 0, {&use_byte_value_binary_prefix},
4568 "use binary prefixes for byte units" },
4569 { "sexagesimal", OPT_TYPE_BOOL, 0, {&use_value_sexagesimal_format},
4570 "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
4571 { "pretty", OPT_TYPE_FUNC, 0, {.func_arg = opt_pretty},
4572 "prettify the format of displayed values, make it more human readable" },
4573 { "output_format", OPT_TYPE_STRING, 0, { &output_format },
4574 "set the output printing format (available formats are: default, compact, csv, flat, ini, json, xml)", "format" },
4575 { "print_format", OPT_TYPE_STRING, 0, { &output_format }, "alias for -output_format (deprecated)" },
4576 { "of", OPT_TYPE_STRING, 0, { &output_format }, "alias for -output_format", "format" },
4577 { "select_streams", OPT_TYPE_STRING, 0, { &stream_specifier }, "select the specified streams", "stream_specifier" },
4578 { "sections", OPT_TYPE_FUNC, OPT_EXIT, {.func_arg = opt_sections}, "print sections structure and section information, and exit" },
4579 { "show_data", OPT_TYPE_BOOL, 0, { &do_show_data }, "show packets data" },
4580 { "show_data_hash", OPT_TYPE_STRING, 0, { &show_data_hash }, "show packets data hash" },
4581 { "show_error", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_error }, "show probing error" },
4582 { "show_format", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_format }, "show format/container info" },
4583 { "show_frames", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_frames }, "show frames info" },
4584 { "show_entries", OPT_TYPE_FUNC, OPT_FUNC_ARG, {.func_arg = opt_show_entries},
4585 "show a set of specified entries", "entry_list" },
4586 #if HAVE_THREADS
4587 { "show_log", OPT_TYPE_INT, 0, { &do_show_log }, "show log" },
4588 #endif
4589 { "show_packets", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_packets }, "show packets info" },
4590 { "show_programs", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_programs }, "show programs info" },
4591 { "show_stream_groups", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_stream_groups }, "show stream groups info" },
4592 { "show_streams", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_streams }, "show streams info" },
4593 { "show_chapters", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_chapters }, "show chapters info" },
4594 { "count_frames", OPT_TYPE_BOOL, 0, { &do_count_frames }, "count the number of frames per stream" },
4595 { "count_packets", OPT_TYPE_BOOL, 0, { &do_count_packets }, "count the number of packets per stream" },
4596 { "show_program_version", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_program_version }, "show ffprobe version" },
4597 { "show_library_versions", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_library_versions }, "show library versions" },
4598 { "show_versions", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_versions }, "show program and library versions" },
4599 { "show_pixel_formats", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_pixel_formats }, "show pixel format descriptions" },
4600 { "show_optional_fields", OPT_TYPE_FUNC, OPT_FUNC_ARG, { .func_arg = &opt_show_optional_fields }, "show optional fields" },
4601 { "show_private_data", OPT_TYPE_BOOL, 0, { &show_private_data }, "show private data" },
4602 { "private", OPT_TYPE_BOOL, 0, { &show_private_data }, "same as show_private_data" },
4603 { "bitexact", OPT_TYPE_BOOL, 0, {&do_bitexact}, "force bitexact output" },
4604 { "read_intervals", OPT_TYPE_FUNC, OPT_FUNC_ARG, {.func_arg = opt_read_intervals}, "set read intervals", "read_intervals" },
4605 { "i", OPT_TYPE_FUNC, OPT_FUNC_ARG, {.func_arg = opt_input_file_i}, "read specified file", "input_file"},
4606 { "o", OPT_TYPE_FUNC, OPT_FUNC_ARG, {.func_arg = opt_output_file_o}, "write to specified output", "output_file"},
4607 { "print_filename", OPT_TYPE_FUNC, OPT_FUNC_ARG, {.func_arg = opt_print_filename}, "override the printed input filename", "print_file"},
4608 { "find_stream_info", OPT_TYPE_BOOL, OPT_INPUT | OPT_EXPERT, { &find_stream_info },
4609 "read and decode the streams to fill missing information with heuristics" },
4610 { NULL, },
4611 };
4612
4613 11944 static inline int check_section_show_entries(int section_id)
4614 {
4615 11944 struct section *section = &sections[section_id];
4616
4/4
✓ Branch 0 taken 11536 times.
✓ Branch 1 taken 408 times.
✓ Branch 2 taken 196 times.
✓ Branch 3 taken 11340 times.
11944 if (sections[section_id].show_all_entries || sections[section_id].entries_to_show)
4617 604 return 1;
4618
2/2
✓ Branch 0 taken 7840 times.
✓ Branch 1 taken 10918 times.
18758 for (const SectionID *id = section->children_ids; *id != -1; id++)
4619
2/2
✓ Branch 1 taken 422 times.
✓ Branch 2 taken 7418 times.
7840 if (check_section_show_entries(*id))
4620 422 return 1;
4621 10918 return 0;
4622 }
4623
4624 #define SET_DO_SHOW(id, varname) do { \
4625 if (check_section_show_entries(SECTION_ID_##id)) \
4626 do_show_##varname = 1; \
4627 } while (0)
4628
4629 152 int main(int argc, char **argv)
4630 {
4631 const Writer *w;
4632 WriterContext *wctx;
4633 char *buf;
4634 152 char *w_name = NULL, *w_args = NULL;
4635 int ret, input_ret, i;
4636
4637 152 init_dynload();
4638
4639 #if HAVE_THREADS
4640 152 ret = pthread_mutex_init(&log_mutex, NULL);
4641
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
152 if (ret != 0) {
4642 goto end;
4643 }
4644 #endif
4645 152 av_log_set_flags(AV_LOG_SKIP_REPEATED);
4646
4647 152 options = real_options;
4648 152 parse_loglevel(argc, argv, options);
4649 152 avformat_network_init();
4650 #if CONFIG_AVDEVICE
4651 152 avdevice_register_all();
4652 #endif
4653
4654 152 show_banner(argc, argv, options);
4655 152 ret = parse_options(NULL, argc, argv, options, opt_input_file);
4656
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
152 if (ret < 0) {
4657 ret = (ret == AVERROR_EXIT) ? 0 : ret;
4658 goto end;
4659 }
4660
4661
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
152 if (do_show_log)
4662 av_log_set_callback(log_callback);
4663
4664 /* mark things to show, based on -show_entries */
4665
2/2
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 147 times.
152 SET_DO_SHOW(CHAPTERS, chapters);
4666
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 152 times.
152 SET_DO_SHOW(ERROR, error);
4667
2/2
✓ Branch 1 taken 42 times.
✓ Branch 2 taken 110 times.
152 SET_DO_SHOW(FORMAT, format);
4668
2/2
✓ Branch 1 taken 49 times.
✓ Branch 2 taken 103 times.
152 SET_DO_SHOW(FRAMES, frames);
4669
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 152 times.
152 SET_DO_SHOW(LIBRARY_VERSIONS, library_versions);
4670
2/2
✓ Branch 1 taken 41 times.
✓ Branch 2 taken 111 times.
152 SET_DO_SHOW(PACKETS, packets);
4671
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 152 times.
152 SET_DO_SHOW(PIXEL_FORMATS, pixel_formats);
4672
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 152 times.
152 SET_DO_SHOW(PIXEL_FORMAT_FLAGS, pixel_format_flags);
4673
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 152 times.
152 SET_DO_SHOW(PIXEL_FORMAT_COMPONENTS, pixel_format_components);
4674
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 152 times.
152 SET_DO_SHOW(PROGRAM_VERSION, program_version);
4675
2/2
✓ Branch 1 taken 51 times.
✓ Branch 2 taken 101 times.
152 SET_DO_SHOW(PROGRAMS, programs);
4676
2/2
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 144 times.
152 SET_DO_SHOW(STREAM_GROUP_DISPOSITION, stream_group_disposition);
4677
2/2
✓ Branch 1 taken 64 times.
✓ Branch 2 taken 88 times.
152 SET_DO_SHOW(STREAM_GROUPS, stream_groups);
4678
2/2
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 137 times.
152 SET_DO_SHOW(STREAM_GROUP_COMPONENTS, stream_group_components);
4679
2/2
✓ Branch 1 taken 87 times.
✓ Branch 2 taken 65 times.
152 SET_DO_SHOW(STREAMS, streams);
4680
2/2
✓ Branch 1 taken 42 times.
✓ Branch 2 taken 110 times.
152 SET_DO_SHOW(STREAM_DISPOSITION, stream_disposition);
4681
2/2
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 147 times.
152 SET_DO_SHOW(PROGRAM_STREAM_DISPOSITION, stream_disposition);
4682
2/2
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 132 times.
152 SET_DO_SHOW(STREAM_GROUP_STREAM_DISPOSITION, stream_disposition);
4683
4684
2/2
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 147 times.
152 SET_DO_SHOW(CHAPTER_TAGS, chapter_tags);
4685
2/2
✓ Branch 1 taken 34 times.
✓ Branch 2 taken 118 times.
152 SET_DO_SHOW(FORMAT_TAGS, format_tags);
4686
2/2
✓ Branch 1 taken 42 times.
✓ Branch 2 taken 110 times.
152 SET_DO_SHOW(FRAME_TAGS, frame_tags);
4687
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 152 times.
152 SET_DO_SHOW(PROGRAM_TAGS, program_tags);
4688
2/2
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 144 times.
152 SET_DO_SHOW(STREAM_GROUP_TAGS, stream_group_tags);
4689
2/2
✓ Branch 1 taken 41 times.
✓ Branch 2 taken 111 times.
152 SET_DO_SHOW(STREAM_TAGS, stream_tags);
4690
2/2
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 147 times.
152 SET_DO_SHOW(PROGRAM_STREAM_TAGS, stream_tags);
4691
2/2
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 147 times.
152 SET_DO_SHOW(STREAM_GROUP_STREAM_TAGS, stream_tags);
4692
2/2
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 117 times.
152 SET_DO_SHOW(PACKET_TAGS, packet_tags);
4693
4694
4/6
✓ Branch 0 taken 136 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 136 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 136 times.
152 if (do_bitexact && (do_show_program_version || do_show_library_versions)) {
4695 av_log(NULL, AV_LOG_ERROR,
4696 "-bitexact and -show_program_version or -show_library_versions "
4697 "options are incompatible\n");
4698 ret = AVERROR(EINVAL);
4699 goto end;
4700 }
4701
4702 152 writer_register_all();
4703
4704
2/2
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 62 times.
152 if (!output_format)
4705 90 output_format = av_strdup("default");
4706
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
152 if (!output_format) {
4707 ret = AVERROR(ENOMEM);
4708 goto end;
4709 }
4710 152 w_name = av_strtok(output_format, "=", &buf);
4711
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
152 if (!w_name) {
4712 av_log(NULL, AV_LOG_ERROR,
4713 "No name specified for the output format\n");
4714 ret = AVERROR(EINVAL);
4715 goto end;
4716 }
4717 152 w_args = buf;
4718
4719
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 141 times.
152 if (show_data_hash) {
4720
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
11 if ((ret = av_hash_alloc(&hash, show_data_hash)) < 0) {
4721 if (ret == AVERROR(EINVAL)) {
4722 const char *n;
4723 av_log(NULL, AV_LOG_ERROR,
4724 "Unknown hash algorithm '%s'\nKnown algorithms:",
4725 show_data_hash);
4726 for (i = 0; (n = av_hash_names(i)); i++)
4727 av_log(NULL, AV_LOG_ERROR, " %s", n);
4728 av_log(NULL, AV_LOG_ERROR, "\n");
4729 }
4730 goto end;
4731 }
4732 }
4733
4734 152 w = writer_get_by_name(w_name);
4735
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
152 if (!w) {
4736 av_log(NULL, AV_LOG_ERROR, "Unknown output format with name '%s'\n", w_name);
4737 ret = AVERROR(EINVAL);
4738 goto end;
4739 }
4740
4741
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 152 times.
152 if ((ret = writer_open(&wctx, w, w_args,
4742 sections, FF_ARRAY_ELEMS(sections), output_filename)) >= 0) {
4743
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 150 times.
152 if (w == &xml_writer)
4744 2 wctx->string_validation_utf8_flags |= AV_UTF8_FLAG_EXCLUDE_XML_INVALID_CONTROL_CODES;
4745
4746 152 writer_print_section_header(wctx, NULL, SECTION_ID_ROOT);
4747
4748
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
152 if (do_show_program_version)
4749 ffprobe_show_program_version(wctx);
4750
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
152 if (do_show_library_versions)
4751 ffprobe_show_library_versions(wctx);
4752
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
152 if (do_show_pixel_formats)
4753 ffprobe_show_pixel_formats(wctx);
4754
4755
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
152 if (!input_filename &&
4756 ((do_show_format || do_show_programs || do_show_stream_groups || do_show_streams || do_show_chapters || do_show_packets || do_show_error) ||
4757 (!do_show_program_version && !do_show_library_versions && !do_show_pixel_formats))) {
4758 show_usage();
4759 av_log(NULL, AV_LOG_ERROR, "You have to specify one input file.\n");
4760 av_log(NULL, AV_LOG_ERROR, "Use -h to get full help or, even better, run 'man %s'.\n", program_name);
4761 ret = AVERROR(EINVAL);
4762
1/2
✓ Branch 0 taken 152 times.
✗ Branch 1 not taken.
152 } else if (input_filename) {
4763 152 ret = probe_file(wctx, input_filename, print_input_filename);
4764
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
152 if (ret < 0 && do_show_error)
4765 show_error(wctx, ret);
4766 }
4767
4768 152 input_ret = ret;
4769
4770 152 writer_print_section_footer(wctx);
4771 152 ret = writer_close(&wctx);
4772
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
152 if (ret < 0)
4773 av_log(NULL, AV_LOG_ERROR, "Writing output failed: %s\n", av_err2str(ret));
4774
4775 152 ret = FFMIN(ret, input_ret);
4776 }
4777
4778 end:
4779 152 av_freep(&output_format);
4780 152 av_freep(&output_filename);
4781 152 av_freep(&input_filename);
4782 152 av_freep(&print_input_filename);
4783 152 av_freep(&read_intervals);
4784 152 av_hash_freep(&hash);
4785
4786 152 uninit_opts();
4787
2/2
✓ Branch 0 taken 10032 times.
✓ Branch 1 taken 152 times.
10184 for (i = 0; i < FF_ARRAY_ELEMS(sections); i++)
4788 10032 av_dict_free(&(sections[i].entries_to_show));
4789
4790 152 avformat_network_deinit();
4791
4792 #if HAVE_THREADS
4793 152 pthread_mutex_destroy(&log_mutex);
4794 #endif
4795
4796 152 return ret < 0;
4797 }
4798