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"
31 #include "libavutil/common.h"
32 #include "libavutil/mem.h"
33 #include "libavutil/timestamp.h"
34 #include "libavutil/samplefmt.h"
35 
36 #include "audio.h"
37 #include "avfilter.h"
38 #include "internal.h"
39 
40 typedef struct AShowInfoContext {
41  /**
42  * Scratch space for individual plane checksums for planar audio
43  */
44  uint32_t *plane_checksums;
45 
46  /**
47  * Frame counter
48  */
49  uint64_t frame;
51 
52 static void uninit(AVFilterContext *ctx)
53 {
54  AShowInfoContext *s = ctx->priv;
56 }
57 
58 static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
59 {
60  AVFilterContext *ctx = inlink->dst;
61  AShowInfoContext *s = ctx->priv;
62  char chlayout_str[128];
63  uint32_t checksum = 0;
65  int planar = av_sample_fmt_is_planar(buf->format);
66  int block_align = av_get_bytes_per_sample(buf->format) * (planar ? 1 : channels);
67  int data_size = buf->nb_samples * block_align;
68  int planes = planar ? channels : 1;
69  int i;
70  void *tmp_ptr = av_realloc(s->plane_checksums, channels * sizeof(*s->plane_checksums));
71 
72  if (!tmp_ptr)
73  return AVERROR(ENOMEM);
74  s->plane_checksums = tmp_ptr;
75 
76  for (i = 0; i < planes; i++) {
77  uint8_t *data = buf->extended_data[i];
78 
79  s->plane_checksums[i] = av_adler32_update(0, data, data_size);
80  checksum = i ? av_adler32_update(checksum, data, data_size) :
81  s->plane_checksums[0];
82  }
83 
84  av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), -1,
85  buf->channel_layout);
86 
87  av_log(ctx, AV_LOG_INFO,
88  "n:%"PRIu64" pts:%s pts_time:%s pos:%"PRId64" "
89  "fmt:%s channels:%d chlayout:%s rate:%d nb_samples:%d "
90  "checksum:%08X ",
91  s->frame,
92  av_ts2str(buf->pts), av_ts2timestr(buf->pts, &inlink->time_base),
94  av_get_sample_fmt_name(buf->format), av_frame_get_channels(buf), chlayout_str,
95  buf->sample_rate, buf->nb_samples,
96  checksum);
97 
98  av_log(ctx, AV_LOG_INFO, "plane_checksums: [ ");
99  for (i = 0; i < planes; i++)
100  av_log(ctx, AV_LOG_INFO, "%08X ", s->plane_checksums[i]);
101  av_log(ctx, AV_LOG_INFO, "]\n");
102 
103  s->frame++;
104  return ff_filter_frame(inlink->dst->outputs[0], buf);
105 }
106 
107 static const AVFilterPad inputs[] = {
108  {
109  .name = "default",
110  .type = AVMEDIA_TYPE_AUDIO,
111  .get_audio_buffer = ff_null_get_audio_buffer,
112  .filter_frame = filter_frame,
113  },
114  { NULL },
115 };
116 
117 static const AVFilterPad outputs[] = {
118  {
119  .name = "default",
120  .type = AVMEDIA_TYPE_AUDIO,
121  },
122  { NULL },
123 };
124 
126  .name = "ashowinfo",
127  .description = NULL_IF_CONFIG_SMALL("Show textual information for each audio frame."),
128  .priv_size = sizeof(AShowInfoContext),
129  .uninit = uninit,
130  .inputs = inputs,
131  .outputs = outputs,
132 };
const char * s
Definition: avisynth_c.h:668
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:117
external API header
memory handling functions
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
Definition: mem.c:141
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.
uint8_t
it can be given away to ff_start_frame *A reference passed to ff_filter_frame(or the deprecated ff_start_frame) is given away and must no longer be used.*A reference created with avfilter_ref_buffer belongs to the code that created it.*A reference obtained with ff_get_video_buffer or ff_get_audio_buffer belongs to the code that requested it.*A reference given as return value by the get_video_buffer or get_audio_buffer method is given away and must no longer be used.Link reference fields---------------------The AVFilterLink structure has a few AVFilterBufferRef fields.The cur_buf and out_buf were used with the deprecated start_frame/draw_slice/end_frame API and should no longer be used.src_buf
timestamp utils, mostly useful for debugging/logging purposes
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:159
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
Definition: af_ashowinfo.c:58
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:35
A filter pad used for either input or output.
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:72
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Spectrum Plot time data
void * priv
private data for use by the filter
Definition: avfilter.h:545
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:246
struct AShowInfoContext AShowInfoContext
uint64_t channel_layout
Channel layout of the audio data.
Definition: frame.h:331
audio channel layout utility functions
int av_frame_get_channels(const AVFrame *frame)
uint64_t frame
Frame counter.
Definition: af_ashowinfo.c:49
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
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:36
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:104
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:134
uint32_t * plane_checksums
Scratch space for individual plane checksums for planar audio.
Definition: af_ashowinfo.c:44
NULL
Definition: eval.c:55
void * buf
Definition: avisynth_c.h:594
int sample_rate
Sample rate of the audio data.
Definition: frame.h:326
Filter definition.
Definition: avfilter.h:436
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:107
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:118
synthesis window for stochastic i
const char * name
filter name
Definition: avfilter.h:437
AVFilter avfilter_af_ashowinfo
Definition: af_ashowinfo.c:125
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:539
static void uninit(AVFilterContext *ctx)
Definition: af_ashowinfo.c:52
common internal and external API header
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:50
int64_t av_frame_get_pkt_pos(const AVFrame *frame)
An instance of a filter.
Definition: avfilter.h:524
#define AV_LOG_INFO
Definition: log.h:156
internal API functions
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:117
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:127
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.