annotate crc.c @ 663:570274d13064 libavformat

fix the patch to allow Sony PSP MP4 creation
author mmu_man
date Fri, 28 Jan 2005 08:08:42 +0000
parents 60f897e8dd2d
children 16df90bf46fd
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
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 }
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 */
418
41da3366d341 checksuming for nut & nice checksum API for libavformat
michael
parents: 241
diff changeset
69 crc->crcval = update_adler32(0, NULL, 0);
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
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 418
diff changeset
74 static int crc_write_packet(struct AVFormatContext *s, AVPacket *pkt)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76 CRCState *crc = s->priv_data;
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 418
diff changeset
77 crc->crcval = update_adler32(crc->crcval, pkt->data, pkt->size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
78 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 static int crc_write_trailer(struct AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 CRCState *crc = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 char buf[64];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 snprintf(buf, sizeof(buf), "CRC=%08x\n", crc->crcval);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87 put_buffer(&s->pb, buf, strlen(buf));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 put_flush_packet(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
91
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92 static AVOutputFormat crc_format = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
93 "crc",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94 "crc testing format",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 NULL,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96 "",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97 sizeof(CRCState),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98 CODEC_ID_PCM_S16LE,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99 CODEC_ID_RAWVIDEO,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100 crc_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101 crc_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102 crc_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 int crc_init(void)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107 av_register_output_format(&crc_format);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109 }