You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
4.0KB

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