Libav 0.7.1
|
00001 /* 00002 * CRC encoder (for codec/format testing) 00003 * Copyright (c) 2002 Fabrice Bellard 00004 * 00005 * This file is part of Libav. 00006 * 00007 * Libav is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * Libav is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with Libav; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 00022 #include "libavutil/adler32.h" 00023 #include "avformat.h" 00024 00025 typedef struct CRCState { 00026 uint32_t crcval; 00027 } CRCState; 00028 00029 static int crc_write_header(struct AVFormatContext *s) 00030 { 00031 CRCState *crc = s->priv_data; 00032 00033 /* init CRC */ 00034 crc->crcval = 1; 00035 00036 return 0; 00037 } 00038 00039 static int crc_write_packet(struct AVFormatContext *s, AVPacket *pkt) 00040 { 00041 CRCState *crc = s->priv_data; 00042 crc->crcval = av_adler32_update(crc->crcval, pkt->data, pkt->size); 00043 return 0; 00044 } 00045 00046 static int crc_write_trailer(struct AVFormatContext *s) 00047 { 00048 CRCState *crc = s->priv_data; 00049 char buf[64]; 00050 00051 snprintf(buf, sizeof(buf), "CRC=0x%08x\n", crc->crcval); 00052 avio_write(s->pb, buf, strlen(buf)); 00053 avio_flush(s->pb); 00054 return 0; 00055 } 00056 00057 AVOutputFormat ff_crc_muxer = { 00058 "crc", 00059 NULL_IF_CONFIG_SMALL("CRC testing format"), 00060 NULL, 00061 "", 00062 sizeof(CRCState), 00063 CODEC_ID_PCM_S16LE, 00064 CODEC_ID_RAWVIDEO, 00065 crc_write_header, 00066 crc_write_packet, 00067 crc_write_trailer, 00068 };