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.

138 lines
4.1KB

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