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.

97 lines
2.4KB

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