FFmpeg  2.6.3
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
af_ashowinfo.c
Go to the documentation of this file.
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 #include <stddef.h>
28 
29 #include "libavutil/adler32.h"
30 #include "libavutil/attributes.h"
32 #include "libavutil/common.h"
33 #include "libavutil/downmix_info.h"
34 #include "libavutil/intreadwrite.h"
35 #include "libavutil/mem.h"
36 #include "libavutil/replaygain.h"
37 #include "libavutil/timestamp.h"
38 #include "libavutil/samplefmt.h"
39 
40 #include "audio.h"
41 #include "avfilter.h"
42 #include "internal.h"
43 
44 typedef struct AShowInfoContext {
45  /**
46  * Scratch space for individual plane checksums for planar audio
47  */
48  uint32_t *plane_checksums;
50 
51 static av_cold void uninit(AVFilterContext *ctx)
52 {
53  AShowInfoContext *s = ctx->priv;
55 }
56 
58 {
59  enum AVMatrixEncoding enc;
60 
61  av_log(ctx, AV_LOG_INFO, "matrix encoding: ");
62 
63  if (sd->size < sizeof(enum AVMatrixEncoding)) {
64  av_log(ctx, AV_LOG_INFO, "invalid data");
65  return;
66  }
67 
68  enc = *(enum AVMatrixEncoding *)sd->data;
69  switch (enc) {
70  case AV_MATRIX_ENCODING_NONE: av_log(ctx, AV_LOG_INFO, "none"); break;
71  case AV_MATRIX_ENCODING_DOLBY: av_log(ctx, AV_LOG_INFO, "Dolby Surround"); break;
72  case AV_MATRIX_ENCODING_DPLII: av_log(ctx, AV_LOG_INFO, "Dolby Pro Logic II"); break;
73  case AV_MATRIX_ENCODING_DPLIIX: av_log(ctx, AV_LOG_INFO, "Dolby Pro Logic IIx"); break;
74  case AV_MATRIX_ENCODING_DPLIIZ: av_log(ctx, AV_LOG_INFO, "Dolby Pro Logic IIz"); break;
75  case AV_MATRIX_ENCODING_DOLBYEX: av_log(ctx, AV_LOG_INFO, "Dolby EX"); break;
76  case AV_MATRIX_ENCODING_DOLBYHEADPHONE: av_log(ctx, AV_LOG_INFO, "Dolby Headphone"); break;
77  default: av_log(ctx, AV_LOG_WARNING, "unknown"); break;
78  }
79 }
80 
82 {
83  AVDownmixInfo *di;
84 
85  av_log(ctx, AV_LOG_INFO, "downmix: ");
86  if (sd->size < sizeof(*di)) {
87  av_log(ctx, AV_LOG_INFO, "invalid data");
88  return;
89  }
90 
91  di = (AVDownmixInfo *)sd->data;
92 
93  av_log(ctx, AV_LOG_INFO, "preferred downmix type - ");
94  switch (di->preferred_downmix_type) {
95  case AV_DOWNMIX_TYPE_LORO: av_log(ctx, AV_LOG_INFO, "Lo/Ro"); break;
96  case AV_DOWNMIX_TYPE_LTRT: av_log(ctx, AV_LOG_INFO, "Lt/Rt"); break;
97  case AV_DOWNMIX_TYPE_DPLII: av_log(ctx, AV_LOG_INFO, "Dolby Pro Logic II"); break;
98  default: av_log(ctx, AV_LOG_WARNING, "unknown"); break;
99  }
100 
101  av_log(ctx, AV_LOG_INFO, " Mix levels: center %f (%f ltrt) - "
102  "surround %f (%f ltrt) - lfe %f",
105  di->lfe_mix_level);
106 }
107 
108 static void print_gain(AVFilterContext *ctx, const char *str, int32_t gain)
109 {
110  av_log(ctx, AV_LOG_INFO, "%s - ", str);
111  if (gain == INT32_MIN)
112  av_log(ctx, AV_LOG_INFO, "unknown");
113  else
114  av_log(ctx, AV_LOG_INFO, "%f", gain / 100000.0f);
115  av_log(ctx, AV_LOG_INFO, ", ");
116 }
117 
118 static void print_peak(AVFilterContext *ctx, const char *str, uint32_t peak)
119 {
120  av_log(ctx, AV_LOG_INFO, "%s - ", str);
121  if (!peak)
122  av_log(ctx, AV_LOG_INFO, "unknown");
123  else
124  av_log(ctx, AV_LOG_INFO, "%f", (float)peak / UINT32_MAX);
125  av_log(ctx, AV_LOG_INFO, ", ");
126 }
127 
129 {
130  AVReplayGain *rg;
131 
132  av_log(ctx, AV_LOG_INFO, "replaygain: ");
133  if (sd->size < sizeof(*rg)) {
134  av_log(ctx, AV_LOG_INFO, "invalid data");
135  return;
136  }
137  rg = (AVReplayGain*)sd->data;
138 
139  print_gain(ctx, "track gain", rg->track_gain);
140  print_peak(ctx, "track peak", rg->track_peak);
141  print_gain(ctx, "album gain", rg->album_gain);
142  print_peak(ctx, "album peak", rg->album_peak);
143 }
144 
146 {
147  enum AVAudioServiceType *ast;
148 
149  av_log(ctx, AV_LOG_INFO, "audio service type: ");
150  if (sd->size < sizeof(*ast)) {
151  av_log(ctx, AV_LOG_INFO, "invalid data");
152  return;
153  }
154  ast = (enum AVAudioServiceType*)sd->data;
155  switch (*ast) {
156  case AV_AUDIO_SERVICE_TYPE_MAIN: av_log(ctx, AV_LOG_INFO, "Main Audio Service"); break;
157  case AV_AUDIO_SERVICE_TYPE_EFFECTS: av_log(ctx, AV_LOG_INFO, "Effects"); break;
158  case AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED: av_log(ctx, AV_LOG_INFO, "Visually Impaired"); break;
159  case AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED: av_log(ctx, AV_LOG_INFO, "Hearing Impaired"); break;
160  case AV_AUDIO_SERVICE_TYPE_DIALOGUE: av_log(ctx, AV_LOG_INFO, "Dialogue"); break;
161  case AV_AUDIO_SERVICE_TYPE_COMMENTARY: av_log(ctx, AV_LOG_INFO, "Commentary"); break;
162  case AV_AUDIO_SERVICE_TYPE_EMERGENCY: av_log(ctx, AV_LOG_INFO, "Emergency"); break;
163  case AV_AUDIO_SERVICE_TYPE_VOICE_OVER: av_log(ctx, AV_LOG_INFO, "Voice Over"); break;
164  case AV_AUDIO_SERVICE_TYPE_KARAOKE: av_log(ctx, AV_LOG_INFO, "Karaoke"); break;
165  default: av_log(ctx, AV_LOG_INFO, "unknown"); break;
166  }
167 }
168 
170 {
171  av_log(ctx, AV_LOG_INFO, "unknown side data type: %d, size %d bytes", sd->type, sd->size);
172 }
173 
174 static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
175 {
176  AVFilterContext *ctx = inlink->dst;
177  AShowInfoContext *s = ctx->priv;
178  char chlayout_str[128];
179  uint32_t checksum = 0;
180  int channels = inlink->channels;
181  int planar = av_sample_fmt_is_planar(buf->format);
182  int block_align = av_get_bytes_per_sample(buf->format) * (planar ? 1 : channels);
183  int data_size = buf->nb_samples * block_align;
184  int planes = planar ? channels : 1;
185  int i;
186  void *tmp_ptr = av_realloc_array(s->plane_checksums, channels, sizeof(*s->plane_checksums));
187 
188  if (!tmp_ptr)
189  return AVERROR(ENOMEM);
190  s->plane_checksums = tmp_ptr;
191 
192  for (i = 0; i < planes; i++) {
193  uint8_t *data = buf->extended_data[i];
194 
195  s->plane_checksums[i] = av_adler32_update(0, data, data_size);
196  checksum = i ? av_adler32_update(checksum, data, data_size) :
197  s->plane_checksums[0];
198  }
199 
200  av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), -1,
201  buf->channel_layout);
202 
203  av_log(ctx, AV_LOG_INFO,
204  "n:%"PRId64" pts:%s pts_time:%s pos:%"PRId64" "
205  "fmt:%s channels:%d chlayout:%s rate:%d nb_samples:%d "
206  "checksum:%08"PRIX32" ",
207  inlink->frame_count,
208  av_ts2str(buf->pts), av_ts2timestr(buf->pts, &inlink->time_base),
210  av_get_sample_fmt_name(buf->format), av_frame_get_channels(buf), chlayout_str,
211  buf->sample_rate, buf->nb_samples,
212  checksum);
213 
214  av_log(ctx, AV_LOG_INFO, "plane_checksums: [ ");
215  for (i = 0; i < planes; i++)
216  av_log(ctx, AV_LOG_INFO, "%08"PRIX32" ", s->plane_checksums[i]);
217  av_log(ctx, AV_LOG_INFO, "]\n");
218 
219  for (i = 0; i < buf->nb_side_data; i++) {
220  AVFrameSideData *sd = buf->side_data[i];
221 
222  av_log(ctx, AV_LOG_INFO, " side data - ");
223  switch (sd->type) {
224  case AV_FRAME_DATA_MATRIXENCODING: dump_matrixenc (ctx, sd); break;
225  case AV_FRAME_DATA_DOWNMIX_INFO: dump_downmix (ctx, sd); break;
226  case AV_FRAME_DATA_REPLAYGAIN: dump_replaygain(ctx, sd); break;
228  default: dump_unknown (ctx, sd); break;
229  }
230 
231  av_log(ctx, AV_LOG_INFO, "\n");
232  }
233 
234  return ff_filter_frame(inlink->dst->outputs[0], buf);
235 }
236 
237 static const AVFilterPad inputs[] = {
238  {
239  .name = "default",
240  .type = AVMEDIA_TYPE_AUDIO,
241  .filter_frame = filter_frame,
242  },
243  { NULL }
244 };
245 
246 static const AVFilterPad outputs[] = {
247  {
248  .name = "default",
249  .type = AVMEDIA_TYPE_AUDIO,
250  },
251  { NULL }
252 };
253 
255  .name = "ashowinfo",
256  .description = NULL_IF_CONFIG_SMALL("Show textual information for each audio frame."),
257  .priv_size = sizeof(AShowInfoContext),
258  .uninit = uninit,
259  .inputs = inputs,
260  .outputs = outputs,
261 };
audio downmix medatata
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:669
This structure describes decoded (raw) audio or video data.
Definition: frame.h:163
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
This side data must be associated with an audio frame and corresponds to enum AVAudioServiceType defi...
Definition: frame.h:114
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:181
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:246
Main libavfilter public API header.
memory handling functions
static void dump_replaygain(AVFilterContext *ctx, AVFrameSideData *sd)
Definition: af_ashowinfo.c:128
double center_mix_level_ltrt
Absolute scale factor representing the nominal level of the center channel during an Lt/Rt compatible...
Definition: downmix_info.h:74
uint32_t track_peak
Peak track amplitude, with 100000 representing full scale (but values may overflow).
Definition: replaygain.h:40
Macro definitions for various function/variable attributes.
const char * name
Pad name.
Definition: internal.h:67
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1145
uint8_t
#define av_cold
Definition: attributes.h:74
timestamp utils, mostly useful for debugging/logging purposes
unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf, unsigned int len)
Calculate the Adler32 checksum of a buffer.
Definition: adler32.c:44
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:249
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
Definition: af_ashowinfo.c:174
double surround_mix_level_ltrt
Absolute scale factor representing the nominal level of the surround channels during an Lt/Rt compati...
Definition: downmix_info.h:86
Lt/Rt 2-channel downmix, Dolby Pro Logic II compatible.
Definition: downmix_info.h:48
Metadata relevant to a downmix procedure.
Definition: frame.h:72
int nb_side_data
Definition: frame.h:454
int32_t album_gain
Same as track_gain, but for the whole album.
Definition: replaygain.h:44
AVFrameSideData ** side_data
Definition: frame.h:453
#define av_log(a,...)
double lfe_mix_level
Absolute scale factor representing the level at which the LFE data is mixed into L/R channels during ...
Definition: downmix_info.h:92
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:110
A filter pad used for either input or output.
Definition: internal.h:61
static void print_gain(AVFilterContext *ctx, const char *str, int32_t gain)
Definition: af_ashowinfo.c:108
This structure describes optional metadata relevant to a downmix procedure.
Definition: downmix_info.h:58
AVAudioServiceType
Definition: avcodec.h:670
#define AVERROR(e)
Definition: error.h:43
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:76
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:180
void * priv
private data for use by the filter
Definition: avfilter.h:654
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
Definition: samplefmt.c:47
uint64_t channel_layout
Channel layout of the audio data.
Definition: frame.h:419
audio channel layout utility functions
AVFilter ff_af_ashowinfo
Definition: af_ashowinfo.c:254
Lt/Rt 2-channel downmix, Dolby Surround compatible.
Definition: downmix_info.h:47
static void dump_downmix(AVFilterContext *ctx, AVFrameSideData *sd)
Definition: af_ashowinfo.c:81
static void print_peak(AVFilterContext *ctx, const char *str, uint32_t peak)
Definition: af_ashowinfo.c:118
int32_t
static void dump_audio_service_type(AVFilterContext *ctx, AVFrameSideData *sd)
Definition: af_ashowinfo.c:145
Lo/Ro 2-channel downmix (Stereo).
Definition: downmix_info.h:46
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_ashowinfo.c:51
static void dump_matrixenc(AVFilterContext *ctx, AVFrameSideData *sd)
Definition: af_ashowinfo.c:57
void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout)
Return a description of a channel layout.
Public header for libavutil Adler32 hasher.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:224
uint32_t * plane_checksums
Scratch space for individual plane checksums for planar audio.
Definition: af_ashowinfo.c:48
#define AV_LOG_INFO
Standard information.
Definition: log.h:186
double surround_mix_level
Absolute scale factor representing the nominal level of the surround channels during a regular downmi...
Definition: downmix_info.h:80
uint8_t * data
Definition: frame.h:129
void * buf
Definition: avisynth_c.h:595
int sample_rate
Sample rate of the audio data.
Definition: frame.h:414
int av_frame_get_channels(const AVFrame *frame)
Filter definition.
Definition: avfilter.h:470
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:237
const char * name
Filter name.
Definition: avfilter.h:474
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:648
enum AVFrameSideDataType type
Definition: frame.h:128
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:104
common internal and external API header
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:206
uint32_t album_peak
Same as track_peak, but for the whole album,.
Definition: replaygain.h:48
double center_mix_level
Absolute scale factor representing the nominal level of the center channel during a regular downmix...
Definition: downmix_info.h:68
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:54
int64_t av_frame_get_pkt_pos(const AVFrame *frame)
An instance of a filter.
Definition: avfilter.h:633
#define av_freep(p)
static void dump_unknown(AVFilterContext *ctx, AVFrameSideData *sd)
Definition: af_ashowinfo.c:169
int32_t track_gain
Track replay gain in microbels (divide by 100000 to get the value in dB).
Definition: replaygain.h:35
AVMatrixEncoding
ReplayGain information in the form of the AVReplayGain struct.
Definition: frame.h:76
internal API functions
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:207
ReplayGain information (see http://wiki.hydrogenaudio.org/index.php?title=ReplayGain_1.0_specification).
Definition: replaygain.h:30
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:217
The data is the AVMatrixEncoding enum defined in libavutil/channel_layout.h.
Definition: frame.h:67
enum AVDownmixType preferred_downmix_type
Type of downmix preferred by the mastering engineer.
Definition: downmix_info.h:62