af_ashowinfo.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. * @file
  22. * filter for showing textual audio frame information
  23. */
  24. #include <inttypes.h>
  25. #include <stddef.h>
  26. #include "libavutil/adler32.h"
  27. #include "libavutil/attributes.h"
  28. #include "libavutil/channel_layout.h"
  29. #include "libavutil/common.h"
  30. #include "libavutil/mem.h"
  31. #include "libavutil/timestamp.h"
  32. #include "libavutil/samplefmt.h"
  33. #include "audio.h"
  34. #include "avfilter.h"
  35. #include "internal.h"
  36. typedef struct AShowInfoContext {
  37. /**
  38. * Scratch space for individual plane checksums for planar audio
  39. */
  40. uint32_t *plane_checksums;
  41. } AShowInfoContext;
  42. static av_cold void uninit(AVFilterContext *ctx)
  43. {
  44. AShowInfoContext *s = ctx->priv;
  45. av_freep(&s->plane_checksums);
  46. }
  47. static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
  48. {
  49. AVFilterContext *ctx = inlink->dst;
  50. AShowInfoContext *s = ctx->priv;
  51. char chlayout_str[128];
  52. uint32_t checksum = 0;
  53. int channels = inlink->channels;
  54. int planar = av_sample_fmt_is_planar(buf->format);
  55. int block_align = av_get_bytes_per_sample(buf->format) * (planar ? 1 : channels);
  56. int data_size = buf->nb_samples * block_align;
  57. int planes = planar ? channels : 1;
  58. int i;
  59. void *tmp_ptr = av_realloc(s->plane_checksums, channels * sizeof(*s->plane_checksums));
  60. if (!tmp_ptr)
  61. return AVERROR(ENOMEM);
  62. s->plane_checksums = tmp_ptr;
  63. for (i = 0; i < planes; i++) {
  64. uint8_t *data = buf->extended_data[i];
  65. s->plane_checksums[i] = av_adler32_update(0, data, data_size);
  66. checksum = i ? av_adler32_update(checksum, data, data_size) :
  67. s->plane_checksums[0];
  68. }
  69. av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), -1,
  70. buf->channel_layout);
  71. av_log(ctx, AV_LOG_INFO,
  72. "n:%"PRId64" pts:%s pts_time:%s pos:%"PRId64" "
  73. "fmt:%s channels:%d chlayout:%s rate:%d nb_samples:%d "
  74. "checksum:%08X ",
  75. inlink->frame_count,
  76. av_ts2str(buf->pts), av_ts2timestr(buf->pts, &inlink->time_base),
  77. av_frame_get_pkt_pos(buf),
  78. av_get_sample_fmt_name(buf->format), av_frame_get_channels(buf), chlayout_str,
  79. buf->sample_rate, buf->nb_samples,
  80. checksum);
  81. av_log(ctx, AV_LOG_INFO, "plane_checksums: [ ");
  82. for (i = 0; i < planes; i++)
  83. av_log(ctx, AV_LOG_INFO, "%08X ", s->plane_checksums[i]);
  84. av_log(ctx, AV_LOG_INFO, "]\n");
  85. return ff_filter_frame(inlink->dst->outputs[0], buf);
  86. }
  87. static const AVFilterPad inputs[] = {
  88. {
  89. .name = "default",
  90. .type = AVMEDIA_TYPE_AUDIO,
  91. .filter_frame = filter_frame,
  92. },
  93. { NULL }
  94. };
  95. static const AVFilterPad outputs[] = {
  96. {
  97. .name = "default",
  98. .type = AVMEDIA_TYPE_AUDIO,
  99. },
  100. { NULL }
  101. };
  102. AVFilter ff_af_ashowinfo = {
  103. .name = "ashowinfo",
  104. .description = NULL_IF_CONFIG_SMALL("Show textual information for each audio frame."),
  105. .priv_size = sizeof(AShowInfoContext),
  106. .uninit = uninit,
  107. .inputs = inputs,
  108. .outputs = outputs,
  109. };