Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
* Copyright (c) 2011 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 |
|
|
* filter for showing textual audio frame information |
24 |
|
|
*/ |
25 |
|
|
|
26 |
|
|
#include <inttypes.h> |
27 |
|
|
|
28 |
|
|
#include "libavutil/adler32.h" |
29 |
|
|
#include "libavutil/attributes.h" |
30 |
|
|
#include "libavutil/channel_layout.h" |
31 |
|
|
#include "libavutil/downmix_info.h" |
32 |
|
|
#include "libavutil/mem.h" |
33 |
|
|
#include "libavutil/replaygain.h" |
34 |
|
|
#include "libavutil/timestamp.h" |
35 |
|
|
#include "libavutil/samplefmt.h" |
36 |
|
|
|
37 |
|
|
#include "libavcodec/defs.h" |
38 |
|
|
|
39 |
|
|
#include "audio.h" |
40 |
|
|
#include "avfilter.h" |
41 |
|
|
#include "filters.h" |
42 |
|
|
|
43 |
|
|
typedef struct AShowInfoContext { |
44 |
|
|
/** |
45 |
|
|
* Scratch space for individual plane checksums for planar audio |
46 |
|
|
*/ |
47 |
|
|
uint32_t *plane_checksums; |
48 |
|
|
} AShowInfoContext; |
49 |
|
|
|
50 |
|
✗ |
static av_cold void uninit(AVFilterContext *ctx) |
51 |
|
|
{ |
52 |
|
✗ |
AShowInfoContext *s = ctx->priv; |
53 |
|
✗ |
av_freep(&s->plane_checksums); |
54 |
|
✗ |
} |
55 |
|
|
|
56 |
|
✗ |
static void dump_matrixenc(AVFilterContext *ctx, AVFrameSideData *sd) |
57 |
|
|
{ |
58 |
|
|
enum AVMatrixEncoding enc; |
59 |
|
|
|
60 |
|
✗ |
av_log(ctx, AV_LOG_INFO, "matrix encoding: "); |
61 |
|
|
|
62 |
|
✗ |
if (sd->size < sizeof(enum AVMatrixEncoding)) { |
63 |
|
✗ |
av_log(ctx, AV_LOG_INFO, "invalid data"); |
64 |
|
✗ |
return; |
65 |
|
|
} |
66 |
|
|
|
67 |
|
✗ |
enc = *(enum AVMatrixEncoding *)sd->data; |
68 |
|
✗ |
switch (enc) { |
69 |
|
✗ |
case AV_MATRIX_ENCODING_NONE: av_log(ctx, AV_LOG_INFO, "none"); break; |
70 |
|
✗ |
case AV_MATRIX_ENCODING_DOLBY: av_log(ctx, AV_LOG_INFO, "Dolby Surround"); break; |
71 |
|
✗ |
case AV_MATRIX_ENCODING_DPLII: av_log(ctx, AV_LOG_INFO, "Dolby Pro Logic II"); break; |
72 |
|
✗ |
case AV_MATRIX_ENCODING_DPLIIX: av_log(ctx, AV_LOG_INFO, "Dolby Pro Logic IIx"); break; |
73 |
|
✗ |
case AV_MATRIX_ENCODING_DPLIIZ: av_log(ctx, AV_LOG_INFO, "Dolby Pro Logic IIz"); break; |
74 |
|
✗ |
case AV_MATRIX_ENCODING_DOLBYEX: av_log(ctx, AV_LOG_INFO, "Dolby EX"); break; |
75 |
|
✗ |
case AV_MATRIX_ENCODING_DOLBYHEADPHONE: av_log(ctx, AV_LOG_INFO, "Dolby Headphone"); break; |
76 |
|
✗ |
default: av_log(ctx, AV_LOG_WARNING, "unknown"); break; |
77 |
|
|
} |
78 |
|
|
} |
79 |
|
|
|
80 |
|
✗ |
static void dump_downmix(AVFilterContext *ctx, AVFrameSideData *sd) |
81 |
|
|
{ |
82 |
|
|
AVDownmixInfo *di; |
83 |
|
|
|
84 |
|
✗ |
av_log(ctx, AV_LOG_INFO, "downmix: "); |
85 |
|
✗ |
if (sd->size < sizeof(*di)) { |
86 |
|
✗ |
av_log(ctx, AV_LOG_INFO, "invalid data"); |
87 |
|
✗ |
return; |
88 |
|
|
} |
89 |
|
|
|
90 |
|
✗ |
di = (AVDownmixInfo *)sd->data; |
91 |
|
|
|
92 |
|
✗ |
av_log(ctx, AV_LOG_INFO, "preferred downmix type - "); |
93 |
|
✗ |
switch (di->preferred_downmix_type) { |
94 |
|
✗ |
case AV_DOWNMIX_TYPE_LORO: av_log(ctx, AV_LOG_INFO, "Lo/Ro"); break; |
95 |
|
✗ |
case AV_DOWNMIX_TYPE_LTRT: av_log(ctx, AV_LOG_INFO, "Lt/Rt"); break; |
96 |
|
✗ |
case AV_DOWNMIX_TYPE_DPLII: av_log(ctx, AV_LOG_INFO, "Dolby Pro Logic II"); break; |
97 |
|
✗ |
default: av_log(ctx, AV_LOG_WARNING, "unknown"); break; |
98 |
|
|
} |
99 |
|
|
|
100 |
|
✗ |
av_log(ctx, AV_LOG_INFO, " Mix levels: center %f (%f ltrt) - " |
101 |
|
|
"surround %f (%f ltrt) - lfe %f", |
102 |
|
|
di->center_mix_level, di->center_mix_level_ltrt, |
103 |
|
|
di->surround_mix_level, di->surround_mix_level_ltrt, |
104 |
|
|
di->lfe_mix_level); |
105 |
|
|
} |
106 |
|
|
|
107 |
|
✗ |
static void print_gain(AVFilterContext *ctx, const char *str, int32_t gain) |
108 |
|
|
{ |
109 |
|
✗ |
av_log(ctx, AV_LOG_INFO, "%s - ", str); |
110 |
|
✗ |
if (gain == INT32_MIN) |
111 |
|
✗ |
av_log(ctx, AV_LOG_INFO, "unknown"); |
112 |
|
|
else |
113 |
|
✗ |
av_log(ctx, AV_LOG_INFO, "%f", gain / 100000.0f); |
114 |
|
✗ |
av_log(ctx, AV_LOG_INFO, ", "); |
115 |
|
✗ |
} |
116 |
|
|
|
117 |
|
✗ |
static void print_peak(AVFilterContext *ctx, const char *str, uint32_t peak) |
118 |
|
|
{ |
119 |
|
✗ |
av_log(ctx, AV_LOG_INFO, "%s - ", str); |
120 |
|
✗ |
if (!peak) |
121 |
|
✗ |
av_log(ctx, AV_LOG_INFO, "unknown"); |
122 |
|
|
else |
123 |
|
✗ |
av_log(ctx, AV_LOG_INFO, "%f", (float)peak / UINT32_MAX); |
124 |
|
✗ |
av_log(ctx, AV_LOG_INFO, ", "); |
125 |
|
✗ |
} |
126 |
|
|
|
127 |
|
✗ |
static void dump_replaygain(AVFilterContext *ctx, AVFrameSideData *sd) |
128 |
|
|
{ |
129 |
|
|
AVReplayGain *rg; |
130 |
|
|
|
131 |
|
✗ |
av_log(ctx, AV_LOG_INFO, "replaygain: "); |
132 |
|
✗ |
if (sd->size < sizeof(*rg)) { |
133 |
|
✗ |
av_log(ctx, AV_LOG_INFO, "invalid data"); |
134 |
|
✗ |
return; |
135 |
|
|
} |
136 |
|
✗ |
rg = (AVReplayGain*)sd->data; |
137 |
|
|
|
138 |
|
✗ |
print_gain(ctx, "track gain", rg->track_gain); |
139 |
|
✗ |
print_peak(ctx, "track peak", rg->track_peak); |
140 |
|
✗ |
print_gain(ctx, "album gain", rg->album_gain); |
141 |
|
✗ |
print_peak(ctx, "album peak", rg->album_peak); |
142 |
|
|
} |
143 |
|
|
|
144 |
|
✗ |
static void dump_audio_service_type(AVFilterContext *ctx, AVFrameSideData *sd) |
145 |
|
|
{ |
146 |
|
|
enum AVAudioServiceType *ast; |
147 |
|
|
|
148 |
|
✗ |
av_log(ctx, AV_LOG_INFO, "audio service type: "); |
149 |
|
✗ |
if (sd->size < sizeof(*ast)) { |
150 |
|
✗ |
av_log(ctx, AV_LOG_INFO, "invalid data"); |
151 |
|
✗ |
return; |
152 |
|
|
} |
153 |
|
✗ |
ast = (enum AVAudioServiceType*)sd->data; |
154 |
|
✗ |
switch (*ast) { |
155 |
|
✗ |
case AV_AUDIO_SERVICE_TYPE_MAIN: av_log(ctx, AV_LOG_INFO, "Main Audio Service"); break; |
156 |
|
✗ |
case AV_AUDIO_SERVICE_TYPE_EFFECTS: av_log(ctx, AV_LOG_INFO, "Effects"); break; |
157 |
|
✗ |
case AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED: av_log(ctx, AV_LOG_INFO, "Visually Impaired"); break; |
158 |
|
✗ |
case AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED: av_log(ctx, AV_LOG_INFO, "Hearing Impaired"); break; |
159 |
|
✗ |
case AV_AUDIO_SERVICE_TYPE_DIALOGUE: av_log(ctx, AV_LOG_INFO, "Dialogue"); break; |
160 |
|
✗ |
case AV_AUDIO_SERVICE_TYPE_COMMENTARY: av_log(ctx, AV_LOG_INFO, "Commentary"); break; |
161 |
|
✗ |
case AV_AUDIO_SERVICE_TYPE_EMERGENCY: av_log(ctx, AV_LOG_INFO, "Emergency"); break; |
162 |
|
✗ |
case AV_AUDIO_SERVICE_TYPE_VOICE_OVER: av_log(ctx, AV_LOG_INFO, "Voice Over"); break; |
163 |
|
✗ |
case AV_AUDIO_SERVICE_TYPE_KARAOKE: av_log(ctx, AV_LOG_INFO, "Karaoke"); break; |
164 |
|
✗ |
default: av_log(ctx, AV_LOG_INFO, "unknown"); break; |
165 |
|
|
} |
166 |
|
|
} |
167 |
|
|
|
168 |
|
✗ |
static void dump_unknown(AVFilterContext *ctx, AVFrameSideData *sd) |
169 |
|
|
{ |
170 |
|
✗ |
av_log(ctx, AV_LOG_INFO, "unknown side data type: %d, size " |
171 |
|
✗ |
"%"SIZE_SPECIFIER" bytes", sd->type, sd->size); |
172 |
|
✗ |
} |
173 |
|
|
|
174 |
|
✗ |
static int filter_frame(AVFilterLink *inlink, AVFrame *buf) |
175 |
|
|
{ |
176 |
|
✗ |
FilterLink *inl = ff_filter_link(inlink); |
177 |
|
✗ |
AVFilterContext *ctx = inlink->dst; |
178 |
|
✗ |
AShowInfoContext *s = ctx->priv; |
179 |
|
|
char chlayout_str[128]; |
180 |
|
✗ |
uint32_t checksum = 0; |
181 |
|
✗ |
int channels = inlink->ch_layout.nb_channels; |
182 |
|
✗ |
int planar = av_sample_fmt_is_planar(buf->format); |
183 |
|
✗ |
int block_align = av_get_bytes_per_sample(buf->format) * (planar ? 1 : channels); |
184 |
|
✗ |
int data_size = buf->nb_samples * block_align; |
185 |
|
✗ |
int planes = planar ? channels : 1; |
186 |
|
|
int i; |
187 |
|
✗ |
void *tmp_ptr = av_realloc_array(s->plane_checksums, channels, sizeof(*s->plane_checksums)); |
188 |
|
|
|
189 |
|
✗ |
if (!tmp_ptr) |
190 |
|
✗ |
return AVERROR(ENOMEM); |
191 |
|
✗ |
s->plane_checksums = tmp_ptr; |
192 |
|
|
|
193 |
|
✗ |
for (i = 0; i < planes; i++) { |
194 |
|
✗ |
uint8_t *data = buf->extended_data[i]; |
195 |
|
|
|
196 |
|
✗ |
s->plane_checksums[i] = av_adler32_update(0, data, data_size); |
197 |
|
✗ |
checksum = i ? av_adler32_update(checksum, data, data_size) : |
198 |
|
✗ |
s->plane_checksums[0]; |
199 |
|
|
} |
200 |
|
|
|
201 |
|
✗ |
av_channel_layout_describe(&buf->ch_layout, chlayout_str, sizeof(chlayout_str)); |
202 |
|
|
|
203 |
|
✗ |
av_log(ctx, AV_LOG_INFO, |
204 |
|
|
"n:%"PRId64" pts:%s pts_time:%s " |
205 |
|
|
"fmt:%s channels:%d chlayout:%s rate:%d nb_samples:%d " |
206 |
|
|
"checksum:%08"PRIX32" ", |
207 |
|
|
inl->frame_count_out, |
208 |
|
✗ |
av_ts2str(buf->pts), av_ts2timestr(buf->pts, &inlink->time_base), |
209 |
|
✗ |
av_get_sample_fmt_name(buf->format), buf->ch_layout.nb_channels, chlayout_str, |
210 |
|
|
buf->sample_rate, buf->nb_samples, |
211 |
|
|
checksum); |
212 |
|
|
|
213 |
|
✗ |
av_log(ctx, AV_LOG_INFO, "plane_checksums: [ "); |
214 |
|
✗ |
for (i = 0; i < planes; i++) |
215 |
|
✗ |
av_log(ctx, AV_LOG_INFO, "%08"PRIX32" ", s->plane_checksums[i]); |
216 |
|
✗ |
av_log(ctx, AV_LOG_INFO, "]\n"); |
217 |
|
|
|
218 |
|
✗ |
for (i = 0; i < buf->nb_side_data; i++) { |
219 |
|
✗ |
AVFrameSideData *sd = buf->side_data[i]; |
220 |
|
|
|
221 |
|
✗ |
av_log(ctx, AV_LOG_INFO, " side data - "); |
222 |
|
✗ |
switch (sd->type) { |
223 |
|
✗ |
case AV_FRAME_DATA_MATRIXENCODING: dump_matrixenc (ctx, sd); break; |
224 |
|
✗ |
case AV_FRAME_DATA_DOWNMIX_INFO: dump_downmix (ctx, sd); break; |
225 |
|
✗ |
case AV_FRAME_DATA_REPLAYGAIN: dump_replaygain(ctx, sd); break; |
226 |
|
✗ |
case AV_FRAME_DATA_AUDIO_SERVICE_TYPE: dump_audio_service_type(ctx, sd); break; |
227 |
|
✗ |
default: dump_unknown (ctx, sd); break; |
228 |
|
|
} |
229 |
|
|
|
230 |
|
✗ |
av_log(ctx, AV_LOG_INFO, "\n"); |
231 |
|
|
} |
232 |
|
|
|
233 |
|
✗ |
return ff_filter_frame(inlink->dst->outputs[0], buf); |
234 |
|
|
} |
235 |
|
|
|
236 |
|
|
static const AVFilterPad inputs[] = { |
237 |
|
|
{ |
238 |
|
|
.name = "default", |
239 |
|
|
.type = AVMEDIA_TYPE_AUDIO, |
240 |
|
|
.filter_frame = filter_frame, |
241 |
|
|
}, |
242 |
|
|
}; |
243 |
|
|
|
244 |
|
|
const AVFilter ff_af_ashowinfo = { |
245 |
|
|
.name = "ashowinfo", |
246 |
|
|
.description = NULL_IF_CONFIG_SMALL("Show textual information for each audio frame."), |
247 |
|
|
.priv_size = sizeof(AShowInfoContext), |
248 |
|
|
.uninit = uninit, |
249 |
|
|
.flags = AVFILTER_FLAG_METADATA_ONLY, |
250 |
|
|
FILTER_INPUTS(inputs), |
251 |
|
|
FILTER_OUTPUTS(ff_audio_default_filterpad), |
252 |
|
|
}; |
253 |
|
|
|