crcenc.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * CRC encoder (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 "libavutil/adler32.h"
  22. #include "avformat.h"
  23. typedef struct CRCState {
  24. uint32_t crcval;
  25. } CRCState;
  26. static int crc_write_header(struct AVFormatContext *s)
  27. {
  28. CRCState *crc = s->priv_data;
  29. /* init CRC */
  30. crc->crcval = 1;
  31. return 0;
  32. }
  33. static int crc_write_packet(struct AVFormatContext *s, AVPacket *pkt)
  34. {
  35. CRCState *crc = s->priv_data;
  36. crc->crcval = av_adler32_update(crc->crcval, pkt->data, pkt->size);
  37. return 0;
  38. }
  39. static int crc_write_trailer(struct AVFormatContext *s)
  40. {
  41. CRCState *crc = s->priv_data;
  42. char buf[64];
  43. snprintf(buf, sizeof(buf), "CRC=0x%08x\n", crc->crcval);
  44. avio_write(s->pb, buf, strlen(buf));
  45. avio_flush(s->pb);
  46. return 0;
  47. }
  48. AVOutputFormat ff_crc_muxer = {
  49. "crc",
  50. NULL_IF_CONFIG_SMALL("CRC testing format"),
  51. NULL,
  52. "",
  53. sizeof(CRCState),
  54. CODEC_ID_PCM_S16LE,
  55. CODEC_ID_RAWVIDEO,
  56. crc_write_header,
  57. crc_write_packet,
  58. crc_write_trailer,
  59. };