Libav
af_ashowinfo.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Stefano Sabatini
3  *
4  * This file is part of Libav.
5  *
6  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
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/samplefmt.h"
38 
39 #include "audio.h"
40 #include "avfilter.h"
41 #include "internal.h"
42 
43 typedef struct AShowInfoContext {
47  uint32_t *plane_checksums;
48 
52  uint64_t frame;
54 
55 static int config_input(AVFilterLink *inlink)
56 {
57  AShowInfoContext *s = inlink->dst->priv;
58  int channels = av_get_channel_layout_nb_channels(inlink->channel_layout);
59  s->plane_checksums = av_malloc(channels * sizeof(*s->plane_checksums));
60  if (!s->plane_checksums)
61  return AVERROR(ENOMEM);
62 
63  return 0;
64 }
65 
66 static av_cold void uninit(AVFilterContext *ctx)
67 {
68  AShowInfoContext *s = ctx->priv;
70 }
71 
73 {
74  enum AVMatrixEncoding enc;
75 
76  av_log(ctx, AV_LOG_INFO, "matrix encoding: ");
77 
78  if (sd->size < sizeof(enum AVMatrixEncoding)) {
79  av_log(ctx, AV_LOG_INFO, "invalid data");
80  return;
81  }
82 
83  enc = *(enum AVMatrixEncoding *)sd->data;
84  switch (enc) {
85  case AV_MATRIX_ENCODING_NONE: av_log(ctx, AV_LOG_INFO, "none"); break;
86  case AV_MATRIX_ENCODING_DOLBY: av_log(ctx, AV_LOG_INFO, "Dolby Surround"); break;
87  case AV_MATRIX_ENCODING_DPLII: av_log(ctx, AV_LOG_INFO, "Dolby Pro Logic II"); break;
88  case AV_MATRIX_ENCODING_DPLIIX: av_log(ctx, AV_LOG_INFO, "Dolby Pro Logic IIx"); break;
89  case AV_MATRIX_ENCODING_DPLIIZ: av_log(ctx, AV_LOG_INFO, "Dolby Pro Logic IIz"); break;
90  case AV_MATRIX_ENCODING_DOLBYEX: av_log(ctx, AV_LOG_INFO, "Dolby EX"); break;
91  case AV_MATRIX_ENCODING_DOLBYHEADPHONE: av_log(ctx, AV_LOG_INFO, "Dolby Headphone"); break;
92  default: av_log(ctx, AV_LOG_WARNING, "unknown"); break;
93  }
94 }
95 
97 {
98  AVDownmixInfo *di;
99 
100  av_log(ctx, AV_LOG_INFO, "downmix: ");
101  if (sd->size < sizeof(*di)) {
102  av_log(ctx, AV_LOG_INFO, "invalid data");
103  return;
104  }
105 
106  di = (AVDownmixInfo *)sd->data;
107 
108  av_log(ctx, AV_LOG_INFO, "preferred downmix type - ");
109  switch (di->preferred_downmix_type) {
110  case AV_DOWNMIX_TYPE_LORO: av_log(ctx, AV_LOG_INFO, "Lo/Ro"); break;
111  case AV_DOWNMIX_TYPE_LTRT: av_log(ctx, AV_LOG_INFO, "Lt/Rt"); break;
112  case AV_DOWNMIX_TYPE_DPLII: av_log(ctx, AV_LOG_INFO, "Dolby Pro Logic II"); break;
113  default: av_log(ctx, AV_LOG_WARNING, "unknown"); break;
114  }
115 
116  av_log(ctx, AV_LOG_INFO, " Mix levels: center %f (%f ltrt) - "
117  "surround %f (%f ltrt) - lfe %f",
120  di->lfe_mix_level);
121 }
122 
123 static void print_gain(AVFilterContext *ctx, const char *str, int32_t gain)
124 {
125  av_log(ctx, AV_LOG_INFO, "%s - ", str);
126  if (gain == INT32_MIN)
127  av_log(ctx, AV_LOG_INFO, "unknown");
128  else
129  av_log(ctx, AV_LOG_INFO, "%f", gain / 100000.0f);
130  av_log(ctx, AV_LOG_INFO, ", ");
131 }
132 
133 static void print_peak(AVFilterContext *ctx, const char *str, uint32_t peak)
134 {
135  av_log(ctx, AV_LOG_INFO, "%s - ", str);
136  if (!peak)
137  av_log(ctx, AV_LOG_INFO, "unknown");
138  else
139  av_log(ctx, AV_LOG_INFO, "%f", (float)peak / UINT32_MAX);
140  av_log(ctx, AV_LOG_INFO, ", ");
141 }
142 
144 {
145  AVReplayGain *rg;
146 
147  av_log(ctx, AV_LOG_INFO, "replaygain: ");
148  if (sd->size < sizeof(*rg)) {
149  av_log(ctx, AV_LOG_INFO, "invalid data");
150  return;
151  }
152  rg = (AVReplayGain*)sd->data;
153 
154  print_gain(ctx, "track gain", rg->track_gain);
155  print_peak(ctx, "track peak", rg->track_peak);
156  print_gain(ctx, "album gain", rg->album_gain);
157  print_peak(ctx, "album peak", rg->album_peak);
158 }
159 
161 {
162  av_log(ctx, AV_LOG_INFO, "unknown side data type: %d, size %d bytes", sd->type, sd->size);
163 }
164 
165 static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
166 {
167  AVFilterContext *ctx = inlink->dst;
168  AShowInfoContext *s = ctx->priv;
169  char chlayout_str[128];
170  uint32_t checksum = 0;
172  int planar = av_sample_fmt_is_planar(buf->format);
173  int block_align = av_get_bytes_per_sample(buf->format) * (planar ? 1 : channels);
174  int data_size = buf->nb_samples * block_align;
175  int planes = planar ? channels : 1;
176  int i;
177 
178  for (i = 0; i < planes; i++) {
179  uint8_t *data = buf->extended_data[i];
180 
181  s->plane_checksums[i] = av_adler32_update(0, data, data_size);
182  checksum = i ? av_adler32_update(checksum, data, data_size) :
183  s->plane_checksums[0];
184  }
185 
186  av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), -1,
187  buf->channel_layout);
188 
189  av_log(ctx, AV_LOG_INFO,
190  "n:%"PRIu64" pts:%"PRId64" pts_time:%f "
191  "fmt:%s chlayout:%s rate:%d nb_samples:%d "
192  "checksum:%08"PRIX32" ",
193  s->frame, buf->pts, buf->pts * av_q2d(inlink->time_base),
194  av_get_sample_fmt_name(buf->format), chlayout_str,
195  buf->sample_rate, buf->nb_samples,
196  checksum);
197 
198  av_log(ctx, AV_LOG_INFO, "plane_checksums: [ ");
199  for (i = 0; i < planes; i++)
200  av_log(ctx, AV_LOG_INFO, "%08"PRIX32" ", s->plane_checksums[i]);
201  av_log(ctx, AV_LOG_INFO, "]\n");
202 
203  for (i = 0; i < buf->nb_side_data; i++) {
204  AVFrameSideData *sd = buf->side_data[i];
205 
206  av_log(ctx, AV_LOG_INFO, " side data - ");
207  switch (sd->type) {
208  case AV_FRAME_DATA_MATRIXENCODING: dump_matrixenc (ctx, sd); break;
209  case AV_FRAME_DATA_DOWNMIX_INFO: dump_downmix (ctx, sd); break;
210  case AV_FRAME_DATA_REPLAYGAIN: dump_replaygain(ctx, sd); break;
211  default: dump_unknown (ctx, sd); break;
212  }
213 
214  av_log(ctx, AV_LOG_INFO, "\n");
215  }
216 
217  s->frame++;
218  return ff_filter_frame(inlink->dst->outputs[0], buf);
219 }
220 
221 static const AVFilterPad inputs[] = {
222  {
223  .name = "default",
224  .type = AVMEDIA_TYPE_AUDIO,
225  .get_audio_buffer = ff_null_get_audio_buffer,
226  .config_props = config_input,
227  .filter_frame = filter_frame,
228  },
229  { NULL },
230 };
231 
232 static const AVFilterPad outputs[] = {
233  {
234  .name = "default",
235  .type = AVMEDIA_TYPE_AUDIO,
236  },
237  { NULL },
238 };
239 
241  .name = "ashowinfo",
242  .description = NULL_IF_CONFIG_SMALL("Show textual information for each audio frame."),
243  .priv_size = sizeof(AShowInfoContext),
244  .uninit = uninit,
245  .inputs = inputs,
246  .outputs = outputs,
247 };
audio downmix medatata
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
This structure describes decoded (raw) audio or video data.
Definition: frame.h:135
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:129
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:232
Main libavfilter public API header.
memory handling functions
static void dump_replaygain(AVFilterContext *ctx, AVFrameSideData *sd)
Definition: af_ashowinfo.c:143
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.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
const char * name
Pad name.
Definition: internal.h:42
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:733
uint8_t
#define av_cold
Definition: attributes.h:66
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:42
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:211
const char data[16]
Definition: mxf.c:70
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
Definition: af_ashowinfo.c:165
static double av_q2d(AVRational a)
Convert rational to double.
Definition: rational.h:69
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:414
int32_t album_gain
Same as track_gain, but for the whole album.
Definition: replaygain.h:44
AVFrameSideData ** side_data
Definition: frame.h:413
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:101
A filter pad used for either input or output.
Definition: internal.h:36
static void print_gain(AVFilterContext *ctx, const char *str, int32_t gain)
Definition: af_ashowinfo.c:123
This structure describes optional metadata relevant to a downmix procedure.
Definition: downmix_info.h:58
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:150
void * priv
private data for use by the filter
Definition: avfilter.h:584
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:169
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:381
static int config_input(AVFilterLink *inlink)
Definition: af_ashowinfo.c:55
audio channel layout utility functions
AVFilter ff_af_ashowinfo
Definition: af_ashowinfo.c:240
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:96
static void print_peak(AVFilterContext *ctx, const char *str, uint32_t peak)
Definition: af_ashowinfo.c:133
int32_t
Lo/Ro 2-channel downmix (Stereo).
Definition: downmix_info.h:46
uint64_t frame
Frame counter.
Definition: af_ashowinfo.c:52
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_ashowinfo.c:66
AVFrame * ff_null_get_audio_buffer(AVFilterLink *link, int nb_samples)
get_audio_buffer() handler for filters which simply pass audio along
Definition: audio.c:26
static void dump_matrixenc(AVFilterContext *ctx, AVFrameSideData *sd)
Definition: af_ashowinfo.c:72
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:186
uint32_t * plane_checksums
Scratch space for individual plane checksums for planar audio.
Definition: af_ashowinfo.c:47
NULL
Definition: eval.c:55
#define AV_LOG_INFO
Standard information.
Definition: log.h:134
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:104
int sample_rate
Sample rate of the audio data.
Definition: frame.h:376
Filter definition.
Definition: avfilter.h:421
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:221
const char * name
Filter name.
Definition: avfilter.h:425
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:578
enum AVFrameSideDataType type
Definition: frame.h:103
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:95
common internal and external API header
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
An instance of a filter.
Definition: avfilter.h:563
static void dump_unknown(AVFilterContext *ctx, AVFrameSideData *sd)
Definition: af_ashowinfo.c:160
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:169
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:179
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
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.