annotate crc.c @ 933:2b60e57286eb libavformat

typo
author diego
date Wed, 08 Feb 2006 11:43:47 +0000
parents 68bc3ca12e79
children d89d7ef290da
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 881
diff changeset
1 /*
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
2 * CRC decoder (for codec/format testing)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
3 * Copyright (c) 2002 Fabrice Bellard.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
18 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
19 #include "avformat.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21 /* adler32.c -- compute the Adler-32 checksum of a data stream
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22 * Copyright (C) 1995 Mark Adler
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
23 * For conditions of distribution and use, see copyright notice in zlib.h
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26 #define BASE 65521L /* largest prime smaller than 65536 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27 #define NMAX 5552
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30 #define DO1(buf) {s1 += *buf++; s2 += s1;}
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31 #define DO2(buf) DO1(buf); DO1(buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32 #define DO4(buf) DO2(buf); DO2(buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
33 #define DO8(buf) DO4(buf); DO4(buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
34 #define DO16(buf) DO8(buf); DO8(buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38 unsigned long s1 = adler & 0xffff;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39 unsigned long s2 = (adler >> 16) & 0xffff;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40 int k;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42 if (buf == NULL) return 1L;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44 while (len > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 k = len < NMAX ? len : NMAX;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46 len -= k;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47 while (k >= 16) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 DO16(buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 k -= 16;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51 if (k != 0) do {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52 DO1(buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53 } while (--k);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54 s1 %= BASE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55 s2 %= BASE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 return (s2 << 16) | s1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 }
903
68bc3ca12e79 Put muxer-specific code parts in #ifdef CONFIG_MUXERS.
diego
parents: 896
diff changeset
59 #ifdef CONFIG_MUXERS
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 typedef struct CRCState {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
62 uint32_t crcval;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63 } CRCState;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
65 static int crc_write_header(struct AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
66 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67 CRCState *crc = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
73 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 418
diff changeset
75 static int crc_write_packet(struct AVFormatContext *s, AVPacket *pkt)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77 CRCState *crc = s->priv_data;
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 418
diff changeset
78 crc->crcval = update_adler32(crc->crcval, pkt->data, pkt->size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82 static int crc_write_trailer(struct AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 CRCState *crc = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85 char buf[64];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86
870
16df90bf46fd per frame crc support
michael
parents: 468
diff changeset
87 snprintf(buf, sizeof(buf), "CRC=0x%08x\n", crc->crcval);
16df90bf46fd per frame crc support
michael
parents: 468
diff changeset
88 put_buffer(&s->pb, buf, strlen(buf));
16df90bf46fd per frame crc support
michael
parents: 468
diff changeset
89 put_flush_packet(&s->pb);
16df90bf46fd per frame crc support
michael
parents: 468
diff changeset
90 return 0;
16df90bf46fd per frame crc support
michael
parents: 468
diff changeset
91 }
16df90bf46fd per frame crc support
michael
parents: 468
diff changeset
92
16df90bf46fd per frame crc support
michael
parents: 468
diff changeset
93 static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt)
16df90bf46fd per frame crc support
michael
parents: 468
diff changeset
94 {
16df90bf46fd per frame crc support
michael
parents: 468
diff changeset
95 uint32_t crc = update_adler32(0, pkt->data, pkt->size);
16df90bf46fd per frame crc support
michael
parents: 468
diff changeset
96 char buf[256];
16df90bf46fd per frame crc support
michael
parents: 468
diff changeset
97
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 870
diff changeset
98 snprintf(buf, sizeof(buf), "%d, %"PRId64", %d, 0x%08x\n", pkt->stream_index, pkt->dts, pkt->size, crc);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99 put_buffer(&s->pb, buf, strlen(buf));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100 put_flush_packet(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104 static AVOutputFormat crc_format = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 "crc",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 "crc testing format",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107 NULL,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 "",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109 sizeof(CRCState),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110 CODEC_ID_PCM_S16LE,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111 CODEC_ID_RAWVIDEO,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
112 crc_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113 crc_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
114 crc_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
116
870
16df90bf46fd per frame crc support
michael
parents: 468
diff changeset
117 static AVOutputFormat framecrc_format = {
16df90bf46fd per frame crc support
michael
parents: 468
diff changeset
118 "framecrc",
16df90bf46fd per frame crc support
michael
parents: 468
diff changeset
119 "framecrc testing format",
16df90bf46fd per frame crc support
michael
parents: 468
diff changeset
120 NULL,
16df90bf46fd per frame crc support
michael
parents: 468
diff changeset
121 "",
16df90bf46fd per frame crc support
michael
parents: 468
diff changeset
122 0,
16df90bf46fd per frame crc support
michael
parents: 468
diff changeset
123 CODEC_ID_PCM_S16LE,
16df90bf46fd per frame crc support
michael
parents: 468
diff changeset
124 CODEC_ID_RAWVIDEO,
16df90bf46fd per frame crc support
michael
parents: 468
diff changeset
125 NULL,
16df90bf46fd per frame crc support
michael
parents: 468
diff changeset
126 framecrc_write_packet,
16df90bf46fd per frame crc support
michael
parents: 468
diff changeset
127 NULL,
16df90bf46fd per frame crc support
michael
parents: 468
diff changeset
128 };
16df90bf46fd per frame crc support
michael
parents: 468
diff changeset
129
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130 int crc_init(void)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132 av_register_output_format(&crc_format);
870
16df90bf46fd per frame crc support
michael
parents: 468
diff changeset
133 av_register_output_format(&framecrc_format);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
134 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
135 }
903
68bc3ca12e79 Put muxer-specific code parts in #ifdef CONFIG_MUXERS.
diego
parents: 896
diff changeset
136 #endif /* CONFIG_MUXERS */