lavfi: move tracing utilities definition from video.c to avfilter.c
[ffmpeg.git] / libavfilter / af_ashowinfo.c
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 "libavutil/adler32.h"
27 #include "libavutil/audioconvert.h"
28 #include "libavutil/timestamp.h"
29 #include "audio.h"
30 #include "avfilter.h"
31
32 typedef struct {
33     unsigned int frame;
34 } ShowInfoContext;
35
36 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
37 {
38     ShowInfoContext *showinfo = ctx->priv;
39     showinfo->frame = 0;
40     return 0;
41 }
42
43 static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
44 {
45     AVFilterContext *ctx = inlink->dst;
46     ShowInfoContext *showinfo = ctx->priv;
47     uint32_t plane_checksum[8] = {0}, checksum = 0;
48     char chlayout_str[128];
49     int plane;
50     int linesize =
51         samplesref->audio->nb_samples *
52         av_get_bytes_per_sample(samplesref->format);
53     if (!av_sample_fmt_is_planar(samplesref->format))
54         linesize *= av_get_channel_layout_nb_channels(samplesref->audio->channel_layout);
55
56     for (plane = 0; samplesref->data[plane] && plane < 8; plane++) {
57         uint8_t *data = samplesref->data[plane];
58
59         plane_checksum[plane] = av_adler32_update(plane_checksum[plane],
60                                                   data, linesize);
61         checksum = av_adler32_update(checksum, data, linesize);
62     }
63
64     av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), -1,
65                                  samplesref->audio->channel_layout);
66
67     av_log(ctx, AV_LOG_INFO,
68            "n:%d pts:%s pts_time:%s pos:%"PRId64" "
69            "fmt:%s chlayout:%s nb_samples:%d rate:%d "
70            "checksum:%08X plane_checksum[%08X",
71            showinfo->frame,
72            av_ts2str(samplesref->pts), av_ts2timestr(samplesref->pts, &inlink->time_base),
73            samplesref->pos,
74            av_get_sample_fmt_name(samplesref->format),
75            chlayout_str,
76            samplesref->audio->nb_samples,
77            samplesref->audio->sample_rate,
78            checksum,
79            plane_checksum[0]);
80
81     for (plane = 1; samplesref->data[plane] && plane < 8; plane++)
82         av_log(ctx, AV_LOG_INFO, " %08X", plane_checksum[plane]);
83     av_log(ctx, AV_LOG_INFO, "]\n");
84
85     showinfo->frame++;
86     ff_filter_samples(inlink->dst->outputs[0], samplesref);
87 }
88
89 AVFilter avfilter_af_ashowinfo = {
90     .name        = "ashowinfo",
91     .description = NULL_IF_CONFIG_SMALL("Show textual information for each audio frame."),
92
93     .priv_size = sizeof(ShowInfoContext),
94     .init      = init,
95
96     .inputs    = (const AVFilterPad[]) {{ .name       = "default",
97                                     .type             = AVMEDIA_TYPE_AUDIO,
98                                     .get_audio_buffer = ff_null_get_audio_buffer,
99                                     .filter_samples   = filter_samples,
100                                     .min_perms        = AV_PERM_READ, },
101                                   { .name = NULL}},
102
103     .outputs   = (const AVFilterPad[]) {{ .name       = "default",
104                                     .type             = AVMEDIA_TYPE_AUDIO },
105                                   { .name = NULL}},
106 };