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.

99 lines
2.4KB

  1. /*
  2. * CRC decoder (for codec/format testing)
  3. * Copyright (c) 2002 Fabrice Bellard.
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "avformat.h"
  22. #include "adler32.h"
  23. #ifdef CONFIG_CRC_MUXER
  24. typedef struct CRCState {
  25. uint32_t crcval;
  26. } CRCState;
  27. static int crc_write_header(struct AVFormatContext *s)
  28. {
  29. CRCState *crc = s->priv_data;
  30. /* init CRC */
  31. crc->crcval = 1;
  32. return 0;
  33. }
  34. static int crc_write_packet(struct AVFormatContext *s, AVPacket *pkt)
  35. {
  36. CRCState *crc = s->priv_data;
  37. crc->crcval = av_adler32_update(crc->crcval, pkt->data, pkt->size);
  38. return 0;
  39. }
  40. static int crc_write_trailer(struct AVFormatContext *s)
  41. {
  42. CRCState *crc = s->priv_data;
  43. char buf[64];
  44. snprintf(buf, sizeof(buf), "CRC=0x%08x\n", crc->crcval);
  45. put_buffer(&s->pb, buf, strlen(buf));
  46. put_flush_packet(&s->pb);
  47. return 0;
  48. }
  49. #endif
  50. #ifdef CONFIG_FRAMECRC_MUXER
  51. static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt)
  52. {
  53. uint32_t crc = av_adler32_update(0, pkt->data, pkt->size);
  54. char buf[256];
  55. snprintf(buf, sizeof(buf), "%d, %"PRId64", %d, 0x%08x\n", pkt->stream_index, pkt->dts, pkt->size, crc);
  56. put_buffer(&s->pb, buf, strlen(buf));
  57. put_flush_packet(&s->pb);
  58. return 0;
  59. }
  60. #endif
  61. #ifdef CONFIG_CRC_MUXER
  62. AVOutputFormat crc_muxer = {
  63. "crc",
  64. "crc testing format",
  65. NULL,
  66. "",
  67. sizeof(CRCState),
  68. CODEC_ID_PCM_S16LE,
  69. CODEC_ID_RAWVIDEO,
  70. crc_write_header,
  71. crc_write_packet,
  72. crc_write_trailer,
  73. };
  74. #endif
  75. #ifdef CONFIG_FRAMECRC_MUXER
  76. AVOutputFormat framecrc_muxer = {
  77. "framecrc",
  78. "framecrc testing format",
  79. NULL,
  80. "",
  81. 0,
  82. CODEC_ID_PCM_S16LE,
  83. CODEC_ID_RAWVIDEO,
  84. NULL,
  85. framecrc_write_packet,
  86. NULL,
  87. };
  88. #endif