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/mem.h"
34 #include "libavutil/samplefmt.h"
35 
36 #include "audio.h"
37 #include "avfilter.h"
38 #include "internal.h"
39 
40 typedef struct AShowInfoContext {
44  uint32_t *plane_checksums;
45 
49  uint64_t frame;
51 
52 static int config_input(AVFilterLink *inlink)
53 {
54  AShowInfoContext *s = inlink->dst->priv;
55  int channels = av_get_channel_layout_nb_channels(inlink->channel_layout);
56  s->plane_checksums = av_malloc(channels * sizeof(*s->plane_checksums));
57  if (!s->plane_checksums)
58  return AVERROR(ENOMEM);
59 
60  return 0;
61 }
62 
63 static av_cold void uninit(AVFilterContext *ctx)
64 {
65  AShowInfoContext *s = ctx->priv;
67 }
68 
69 static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
70 {
71  AVFilterContext *ctx = inlink->dst;
72  AShowInfoContext *s = ctx->priv;
73  char chlayout_str[128];
74  uint32_t checksum = 0;
76  int planar = av_sample_fmt_is_planar(buf->format);
77  int block_align = av_get_bytes_per_sample(buf->format) * (planar ? 1 : channels);
78  int data_size = buf->nb_samples * block_align;
79  int planes = planar ? channels : 1;
80  int i;
81 
82  for (i = 0; i < planes; i++) {
83  uint8_t *data = buf->extended_data[i];
84 
85  s->plane_checksums[i] = av_adler32_update(0, data, data_size);
86  checksum = i ? av_adler32_update(checksum, data, data_size) :
87  s->plane_checksums[0];
88  }
89 
90  av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), -1,
91  buf->channel_layout);
92 
93  av_log(ctx, AV_LOG_INFO,
94  "n:%"PRIu64" pts:%"PRId64" pts_time:%f "
95  "fmt:%s chlayout:%s rate:%d nb_samples:%d "
96  "checksum:%08X ",
97  s->frame, buf->pts, buf->pts * av_q2d(inlink->time_base),
98  av_get_sample_fmt_name(buf->format), chlayout_str,
99  buf->sample_rate, buf->nb_samples,
100  checksum);
101 
102  av_log(ctx, AV_LOG_INFO, "plane_checksums: [ ");
103  for (i = 0; i < planes; i++)
104  av_log(ctx, AV_LOG_INFO, "%08X ", s->plane_checksums[i]);
105  av_log(ctx, AV_LOG_INFO, "]\n");
106 
107  s->frame++;
108  return ff_filter_frame(inlink->dst->outputs[0], buf);
109 }
110 
111 static const AVFilterPad inputs[] = {
112  {
113  .name = "default",
114  .type = AVMEDIA_TYPE_AUDIO,
115  .get_audio_buffer = ff_null_get_audio_buffer,
116  .config_props = config_input,
117  .filter_frame = filter_frame,
118  },
119  { NULL },
120 };
121 
122 static const AVFilterPad outputs[] = {
123  {
124  .name = "default",
125  .type = AVMEDIA_TYPE_AUDIO,
126  },
127  { NULL },
128 };
129 
131  .name = "ashowinfo",
132  .description = NULL_IF_CONFIG_SMALL("Show textual information for each audio frame."),
133  .priv_size = sizeof(AShowInfoContext),
134  .uninit = uninit,
135  .inputs = inputs,
136  .outputs = outputs,
137 };