annotate ffmpeg/libavfilter/af_ashowinfo.c @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents 6840f77b83aa
children
rev   line source
yading@10 1 /*
yading@10 2 * Copyright (c) 2011 Stefano Sabatini
yading@10 3 *
yading@10 4 * This file is part of FFmpeg.
yading@10 5 *
yading@10 6 * FFmpeg is free software; you can redistribute it and/or
yading@10 7 * modify it under the terms of the GNU Lesser General Public
yading@10 8 * License as published by the Free Software Foundation; either
yading@10 9 * version 2.1 of the License, or (at your option) any later version.
yading@10 10 *
yading@10 11 * FFmpeg is distributed in the hope that it will be useful,
yading@10 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@10 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@10 14 * Lesser General Public License for more details.
yading@10 15 *
yading@10 16 * You should have received a copy of the GNU Lesser General Public
yading@10 17 * License along with FFmpeg; if not, write to the Free Software
yading@10 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@10 19 */
yading@10 20
yading@10 21 /**
yading@10 22 * @file
yading@10 23 * filter for showing textual audio frame information
yading@10 24 */
yading@10 25
yading@10 26 #include <inttypes.h>
yading@10 27 #include <stddef.h>
yading@10 28
yading@10 29 #include "libavutil/adler32.h"
yading@10 30 #include "libavutil/channel_layout.h"
yading@10 31 #include "libavutil/common.h"
yading@10 32 #include "libavutil/mem.h"
yading@10 33 #include "libavutil/timestamp.h"
yading@10 34 #include "libavutil/samplefmt.h"
yading@10 35
yading@10 36 #include "audio.h"
yading@10 37 #include "avfilter.h"
yading@10 38 #include "internal.h"
yading@10 39
yading@10 40 typedef struct AShowInfoContext {
yading@10 41 /**
yading@10 42 * Scratch space for individual plane checksums for planar audio
yading@10 43 */
yading@10 44 uint32_t *plane_checksums;
yading@10 45
yading@10 46 /**
yading@10 47 * Frame counter
yading@10 48 */
yading@10 49 uint64_t frame;
yading@10 50 } AShowInfoContext;
yading@10 51
yading@10 52 static void uninit(AVFilterContext *ctx)
yading@10 53 {
yading@10 54 AShowInfoContext *s = ctx->priv;
yading@10 55 av_freep(&s->plane_checksums);
yading@10 56 }
yading@10 57
yading@10 58 static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
yading@10 59 {
yading@10 60 AVFilterContext *ctx = inlink->dst;
yading@10 61 AShowInfoContext *s = ctx->priv;
yading@10 62 char chlayout_str[128];
yading@10 63 uint32_t checksum = 0;
yading@10 64 int channels = av_get_channel_layout_nb_channels(buf->channel_layout);
yading@10 65 int planar = av_sample_fmt_is_planar(buf->format);
yading@10 66 int block_align = av_get_bytes_per_sample(buf->format) * (planar ? 1 : channels);
yading@10 67 int data_size = buf->nb_samples * block_align;
yading@10 68 int planes = planar ? channels : 1;
yading@10 69 int i;
yading@10 70 void *tmp_ptr = av_realloc(s->plane_checksums, channels * sizeof(*s->plane_checksums));
yading@10 71
yading@10 72 if (!tmp_ptr)
yading@10 73 return AVERROR(ENOMEM);
yading@10 74 s->plane_checksums = tmp_ptr;
yading@10 75
yading@10 76 for (i = 0; i < planes; i++) {
yading@10 77 uint8_t *data = buf->extended_data[i];
yading@10 78
yading@10 79 s->plane_checksums[i] = av_adler32_update(0, data, data_size);
yading@10 80 checksum = i ? av_adler32_update(checksum, data, data_size) :
yading@10 81 s->plane_checksums[0];
yading@10 82 }
yading@10 83
yading@10 84 av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), -1,
yading@10 85 buf->channel_layout);
yading@10 86
yading@10 87 av_log(ctx, AV_LOG_INFO,
yading@10 88 "n:%"PRIu64" pts:%s pts_time:%s pos:%"PRId64" "
yading@10 89 "fmt:%s channels:%d chlayout:%s rate:%d nb_samples:%d "
yading@10 90 "checksum:%08X ",
yading@10 91 s->frame,
yading@10 92 av_ts2str(buf->pts), av_ts2timestr(buf->pts, &inlink->time_base),
yading@10 93 av_frame_get_pkt_pos(buf),
yading@10 94 av_get_sample_fmt_name(buf->format), av_frame_get_channels(buf), chlayout_str,
yading@10 95 buf->sample_rate, buf->nb_samples,
yading@10 96 checksum);
yading@10 97
yading@10 98 av_log(ctx, AV_LOG_INFO, "plane_checksums: [ ");
yading@10 99 for (i = 0; i < planes; i++)
yading@10 100 av_log(ctx, AV_LOG_INFO, "%08X ", s->plane_checksums[i]);
yading@10 101 av_log(ctx, AV_LOG_INFO, "]\n");
yading@10 102
yading@10 103 s->frame++;
yading@10 104 return ff_filter_frame(inlink->dst->outputs[0], buf);
yading@10 105 }
yading@10 106
yading@10 107 static const AVFilterPad inputs[] = {
yading@10 108 {
yading@10 109 .name = "default",
yading@10 110 .type = AVMEDIA_TYPE_AUDIO,
yading@10 111 .get_audio_buffer = ff_null_get_audio_buffer,
yading@10 112 .filter_frame = filter_frame,
yading@10 113 },
yading@10 114 { NULL },
yading@10 115 };
yading@10 116
yading@10 117 static const AVFilterPad outputs[] = {
yading@10 118 {
yading@10 119 .name = "default",
yading@10 120 .type = AVMEDIA_TYPE_AUDIO,
yading@10 121 },
yading@10 122 { NULL },
yading@10 123 };
yading@10 124
yading@10 125 AVFilter avfilter_af_ashowinfo = {
yading@10 126 .name = "ashowinfo",
yading@10 127 .description = NULL_IF_CONFIG_SMALL("Show textual information for each audio frame."),
yading@10 128 .priv_size = sizeof(AShowInfoContext),
yading@10 129 .uninit = uninit,
yading@10 130 .inputs = inputs,
yading@10 131 .outputs = outputs,
yading@10 132 };