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));
3b4bb19e
 
840fb7a7
     return 0;
 }
 
c6610a21
 AVOutputFormat ff_crc_muxer = {
dfc2c4d9
     .name              = "crc",
6774247a
     .long_name         = NULL_IF_CONFIG_SMALL("CRC testing"),
dfc2c4d9
     .priv_data_size    = sizeof(CRCState),
36ef5369
     .audio_codec       = AV_CODEC_ID_PCM_S16LE,
     .video_codec       = AV_CODEC_ID_RAWVIDEO,
dfc2c4d9
     .write_header      = crc_write_header,
     .write_packet      = crc_write_packet,
     .write_trailer     = crc_write_trailer,
0844b57c
     .flags             = AVFMT_NOTIMESTAMPS,
1c098b2f
 };