libavformat/crcenc.c
115329f1
 /*
6b6adf2b
  * CRC encoder (for codec/format testing)
406792e7
  * Copyright (c) 2002 Fabrice Bellard
1c098b2f
  *
b78e7197
  * This file is part of FFmpeg.
  *
  * FFmpeg is free software; you can redistribute it and/or
19720f15
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
b78e7197
  * version 2.1 of the License, or (at your option) any later version.
1c098b2f
  *
b78e7197
  * FFmpeg is distributed in the hope that it will be useful,
1c098b2f
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19720f15
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
1c098b2f
  *
19720f15
  * You should have received a copy of the GNU Lesser General Public
b78e7197
  * License along with FFmpeg; if not, write to the Free Software
5509bffa
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1c098b2f
  */
245976da
 
 #include "libavutil/adler32.h"
1c098b2f
 #include "avformat.h"
 
 typedef struct CRCState {
0c1a9eda
     uint32_t crcval;
1c098b2f
 } CRCState;
 
 static int crc_write_header(struct AVFormatContext *s)
 {
c9a65ca8
     CRCState *crc = s->priv_data;
 
1c098b2f
     /* init CRC */
1d94a662
     crc->crcval = 1;
1c098b2f
 
     return 0;
 }
 
e928649b
 static int crc_write_packet(struct AVFormatContext *s, AVPacket *pkt)
1c098b2f
 {
     CRCState *crc = s->priv_data;
b9a73d8d
     crc->crcval = av_adler32_update(crc->crcval, pkt->data, pkt->size);
1c098b2f
     return 0;
 }
 
 static int crc_write_trailer(struct AVFormatContext *s)
 {
     CRCState *crc = s->priv_data;
     char buf[64];
 
840fb7a7
     snprintf(buf, sizeof(buf), "CRC=0x%08x\n", crc->crcval);
77eb5504
     avio_write(s->pb, buf, strlen(buf));
b7f2fdde
     avio_flush(s->pb);
840fb7a7
     return 0;
 }
 
c6610a21
 AVOutputFormat ff_crc_muxer = {
1c098b2f
     "crc",
bde15e74
     NULL_IF_CONFIG_SMALL("CRC testing format"),
1c098b2f
     NULL,
     "",
c9a65ca8
     sizeof(CRCState),
1c098b2f
     CODEC_ID_PCM_S16LE,
     CODEC_ID_RAWVIDEO,
     crc_write_header,
     crc_write_packet,
     crc_write_trailer,
 };