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.0KB

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