Mercurial > libavformat.hg
annotate crc.c @ 1169:d18cc9a1fd02 libavformat
allow individual selection of muxers and demuxers
author | mru |
---|---|
date | Mon, 10 Jul 2006 21:14:37 +0000 |
parents | d89d7ef290da |
children | bfea7dcd2698 |
rev | line source |
---|---|
885 | 1 /* |
0 | 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 | |
896
edbe5c3717f9
Update licensing information: The FSF changed postal address.
diego
parents:
885
diff
changeset
|
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 */ |
19 #include "avformat.h" | |
20 | |
21 /* adler32.c -- compute the Adler-32 checksum of a data stream | |
22 * Copyright (C) 1995 Mark Adler | |
23 * For conditions of distribution and use, see copyright notice in zlib.h | |
24 */ | |
25 | |
26 #define BASE 65521L /* largest prime smaller than 65536 */ | |
27 #define NMAX 5552 | |
28 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ | |
29 | |
30 #define DO1(buf) {s1 += *buf++; s2 += s1;} | |
31 #define DO2(buf) DO1(buf); DO1(buf); | |
32 #define DO4(buf) DO2(buf); DO2(buf); | |
33 #define DO8(buf) DO4(buf); DO4(buf); | |
34 #define DO16(buf) DO8(buf); DO8(buf); | |
35 | |
418
41da3366d341
checksuming for nut & nice checksum API for libavformat
michael
parents:
241
diff
changeset
|
36 unsigned long update_adler32(unsigned long adler, const uint8_t *buf, unsigned int len) |
0 | 37 { |
38 unsigned long s1 = adler & 0xffff; | |
39 unsigned long s2 = (adler >> 16) & 0xffff; | |
40 int k; | |
41 | |
42 if (buf == NULL) return 1L; | |
43 | |
44 while (len > 0) { | |
45 k = len < NMAX ? len : NMAX; | |
46 len -= k; | |
47 while (k >= 16) { | |
48 DO16(buf); | |
49 k -= 16; | |
50 } | |
51 if (k != 0) do { | |
52 DO1(buf); | |
53 } while (--k); | |
54 s1 %= BASE; | |
55 s2 %= BASE; | |
56 } | |
57 return (s2 << 16) | s1; | |
58 } | |
59 | |
1169 | 60 #ifdef CONFIG_CRC_MUXER |
0 | 61 typedef struct CRCState { |
65 | 62 uint32_t crcval; |
0 | 63 } CRCState; |
64 | |
65 static int crc_write_header(struct AVFormatContext *s) | |
66 { | |
67 CRCState *crc = s->priv_data; | |
68 | |
69 /* init CRC */ | |
418
41da3366d341
checksuming for nut & nice checksum API for libavformat
michael
parents:
241
diff
changeset
|
70 crc->crcval = update_adler32(0, NULL, 0); |
0 | 71 |
72 return 0; | |
73 } | |
74 | |
468 | 75 static int crc_write_packet(struct AVFormatContext *s, AVPacket *pkt) |
0 | 76 { |
77 CRCState *crc = s->priv_data; | |
468 | 78 crc->crcval = update_adler32(crc->crcval, pkt->data, pkt->size); |
0 | 79 return 0; |
80 } | |
81 | |
82 static int crc_write_trailer(struct AVFormatContext *s) | |
83 { | |
84 CRCState *crc = s->priv_data; | |
85 char buf[64]; | |
86 | |
870 | 87 snprintf(buf, sizeof(buf), "CRC=0x%08x\n", crc->crcval); |
88 put_buffer(&s->pb, buf, strlen(buf)); | |
89 put_flush_packet(&s->pb); | |
90 return 0; | |
91 } | |
1169 | 92 #endif |
870 | 93 |
1169 | 94 #ifdef CONFIG_FRAMECRC_MUXER |
870 | 95 static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt) |
96 { | |
97 uint32_t crc = update_adler32(0, pkt->data, pkt->size); | |
98 char buf[256]; | |
99 | |
881 | 100 snprintf(buf, sizeof(buf), "%d, %"PRId64", %d, 0x%08x\n", pkt->stream_index, pkt->dts, pkt->size, crc); |
0 | 101 put_buffer(&s->pb, buf, strlen(buf)); |
102 put_flush_packet(&s->pb); | |
103 return 0; | |
104 } | |
1169 | 105 #endif |
0 | 106 |
1169 | 107 #ifdef CONFIG_CRC_MUXER |
108 AVOutputFormat crc_muxer = { | |
0 | 109 "crc", |
110 "crc testing format", | |
111 NULL, | |
112 "", | |
113 sizeof(CRCState), | |
114 CODEC_ID_PCM_S16LE, | |
115 CODEC_ID_RAWVIDEO, | |
116 crc_write_header, | |
117 crc_write_packet, | |
118 crc_write_trailer, | |
119 }; | |
1169 | 120 #endif |
121 #ifdef CONFIG_FRAMECRC_MUXER | |
122 AVOutputFormat framecrc_muxer = { | |
870 | 123 "framecrc", |
124 "framecrc testing format", | |
125 NULL, | |
126 "", | |
127 0, | |
128 CODEC_ID_PCM_S16LE, | |
129 CODEC_ID_RAWVIDEO, | |
130 NULL, | |
131 framecrc_write_packet, | |
132 NULL, | |
133 }; | |
1169 | 134 #endif |