annotate crc.c @ 168:808dabf5a88e libavformat

* First round of AV sync fixes. * -r now does the right thing. * frame rate and frame sizes now share same abbv. table and you can do -r ntsc as well as -s ntsc
author romansh
date Sat, 12 Jul 2003 07:37:05 +0000
parents a58a8a53eb46
children 3d92f793fd67
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
36 static uint32_t adler32(uint32_t adler, 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 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60 typedef struct CRCState {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
61 uint32_t crcval;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62 } CRCState;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64 static int crc_write_header(struct AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
65 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
66 CRCState *crc = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68 /* init CRC */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 crc->crcval = adler32(0, NULL, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
73
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74 static int crc_write_packet(struct AVFormatContext *s,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75 int stream_index,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76 unsigned char *buf, int size, int force_pts)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
78 CRCState *crc = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 crc->crcval = adler32(crc->crcval, buf, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 static int crc_write_trailer(struct AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85 CRCState *crc = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 char buf[64];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 snprintf(buf, sizeof(buf), "CRC=%08x\n", crc->crcval);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 put_buffer(&s->pb, buf, strlen(buf));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90 put_flush_packet(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
91 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
93
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94 static AVOutputFormat crc_format = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 "crc",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96 "crc testing format",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97 NULL,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98 "",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99 sizeof(CRCState),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100 CODEC_ID_PCM_S16LE,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101 CODEC_ID_RAWVIDEO,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102 crc_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103 crc_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104 crc_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107 int crc_init(void)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109 av_register_output_format(&crc_format);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111 }