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.

114 lines
3.2KB

  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include <stdio.h>
  19. #include "libavutil/avstring.h"
  20. #include "libavutil/common.h"
  21. #include "libavutil/log.h"
  22. #include "bsf.h"
  23. #include "cbs.h"
  24. typedef struct TraceHeadersContext {
  25. CodedBitstreamContext *cbc;
  26. CodedBitstreamFragment fragment;
  27. } TraceHeadersContext;
  28. static int trace_headers_init(AVBSFContext *bsf)
  29. {
  30. TraceHeadersContext *ctx = bsf->priv_data;
  31. int err;
  32. err = ff_cbs_init(&ctx->cbc, bsf->par_in->codec_id, bsf);
  33. if (err < 0)
  34. return err;
  35. ctx->cbc->trace_enable = 1;
  36. ctx->cbc->trace_level = AV_LOG_INFO;
  37. if (bsf->par_in->extradata) {
  38. CodedBitstreamFragment *frag = &ctx->fragment;
  39. av_log(bsf, AV_LOG_INFO, "Extradata\n");
  40. err = ff_cbs_read_extradata(ctx->cbc, frag, bsf->par_in);
  41. ff_cbs_fragment_reset(ctx->cbc, frag);
  42. }
  43. return err;
  44. }
  45. static void trace_headers_close(AVBSFContext *bsf)
  46. {
  47. TraceHeadersContext *ctx = bsf->priv_data;
  48. ff_cbs_fragment_free(ctx->cbc, &ctx->fragment);
  49. ff_cbs_close(&ctx->cbc);
  50. }
  51. static int trace_headers(AVBSFContext *bsf, AVPacket *pkt)
  52. {
  53. TraceHeadersContext *ctx = bsf->priv_data;
  54. CodedBitstreamFragment *frag = &ctx->fragment;
  55. char tmp[256] = { 0 };
  56. int err;
  57. err = ff_bsf_get_packet_ref(bsf, pkt);
  58. if (err < 0)
  59. return err;
  60. if (pkt->flags & AV_PKT_FLAG_KEY)
  61. av_strlcat(tmp, ", key frame", sizeof(tmp));
  62. if (pkt->flags & AV_PKT_FLAG_CORRUPT)
  63. av_strlcat(tmp, ", corrupt", sizeof(tmp));
  64. if (pkt->pts != AV_NOPTS_VALUE)
  65. av_strlcatf(tmp, sizeof(tmp), ", pts %"PRId64, pkt->pts);
  66. else
  67. av_strlcat(tmp, ", no pts", sizeof(tmp));
  68. if (pkt->dts != AV_NOPTS_VALUE)
  69. av_strlcatf(tmp, sizeof(tmp), ", dts %"PRId64, pkt->dts);
  70. else
  71. av_strlcat(tmp, ", no dts", sizeof(tmp));
  72. if (pkt->duration > 0)
  73. av_strlcatf(tmp, sizeof(tmp), ", duration %"PRId64, pkt->duration);
  74. av_log(bsf, AV_LOG_INFO, "Packet: %d bytes%s.\n", pkt->size, tmp);
  75. err = ff_cbs_read_packet(ctx->cbc, frag, pkt);
  76. ff_cbs_fragment_reset(ctx->cbc, frag);
  77. if (err < 0)
  78. av_packet_unref(pkt);
  79. return err;
  80. }
  81. const AVBitStreamFilter ff_trace_headers_bsf = {
  82. .name = "trace_headers",
  83. .priv_data_size = sizeof(TraceHeadersContext),
  84. .init = &trace_headers_init,
  85. .close = &trace_headers_close,
  86. .filter = &trace_headers,
  87. .codec_ids = ff_cbs_all_codec_ids,
  88. };