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