~ubuntu-branches/ubuntu/jaunty/xvidcap/jaunty-proposed

« back to all changes in this revision

Viewing changes to ffmpeg/libavformat/crc.c

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2008-02-25 15:47:12 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080225154712-qvr11ekcea4c9ry8
Tags: 1.1.6-0.1ubuntu1
* Merge from debian-multimedia (LP: #120003), Ubuntu Changes:
 - For ffmpeg-related build-deps, remove cvs from package names.
 - Standards-Version 3.7.3
 - Maintainer Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
 
1
/*
2
2
 * CRC decoder (for codec/format testing)
3
3
 * Copyright (c) 2002 Fabrice Bellard.
4
4
 *
5
 
 * This library is free software; you can redistribute it and/or
 
5
 * This file is part of FFmpeg.
 
6
 *
 
7
 * FFmpeg is free software; you can redistribute it and/or
6
8
 * modify it under the terms of the GNU Lesser General Public
7
9
 * License as published by the Free Software Foundation; either
8
 
 * version 2 of the License, or (at your option) any later version.
 
10
 * version 2.1 of the License, or (at your option) any later version.
9
11
 *
10
 
 * This library is distributed in the hope that it will be useful,
 
12
 * FFmpeg is distributed in the hope that it will be useful,
11
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
15
 * Lesser General Public License for more details.
14
16
 *
15
17
 * 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
17
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 * License along with FFmpeg; if not, write to the Free Software
 
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
20
 */
19
21
#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
 
 
36
 
static uint32_t adler32(uint32_t adler, const uint8_t *buf, unsigned int len)
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
 
 
 
22
#include "adler32.h"
 
23
 
 
24
#ifdef CONFIG_CRC_MUXER
60
25
typedef struct CRCState {
61
26
    uint32_t crcval;
62
27
} CRCState;
66
31
    CRCState *crc = s->priv_data;
67
32
 
68
33
    /* init CRC */
69
 
    crc->crcval = adler32(0, NULL, 0);
 
34
    crc->crcval = 1;
70
35
 
71
36
    return 0;
72
37
}
73
38
 
74
 
static int crc_write_packet(struct AVFormatContext *s, 
75
 
                            int stream_index,
76
 
                            const uint8_t *buf, int size, int64_t pts)
 
39
static int crc_write_packet(struct AVFormatContext *s, AVPacket *pkt)
77
40
{
78
41
    CRCState *crc = s->priv_data;
79
 
    crc->crcval = adler32(crc->crcval, buf, size);
 
42
    crc->crcval = av_adler32_update(crc->crcval, pkt->data, pkt->size);
80
43
    return 0;
81
44
}
82
45
 
85
48
    CRCState *crc = s->priv_data;
86
49
    char buf[64];
87
50
 
88
 
    snprintf(buf, sizeof(buf), "CRC=%08x\n", crc->crcval);
89
 
    put_buffer(&s->pb, buf, strlen(buf));
90
 
    put_flush_packet(&s->pb);
91
 
    return 0;
92
 
}
93
 
 
94
 
static AVOutputFormat crc_format = {
 
51
    snprintf(buf, sizeof(buf), "CRC=0x%08x\n", crc->crcval);
 
52
    put_buffer(&s->pb, buf, strlen(buf));
 
53
    put_flush_packet(&s->pb);
 
54
    return 0;
 
55
}
 
56
#endif
 
57
 
 
58
#ifdef CONFIG_FRAMECRC_MUXER
 
59
static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt)
 
60
{
 
61
    uint32_t crc = av_adler32_update(0, pkt->data, pkt->size);
 
62
    char buf[256];
 
63
 
 
64
    snprintf(buf, sizeof(buf), "%d, %"PRId64", %d, 0x%08x\n", pkt->stream_index, pkt->dts, pkt->size, crc);
 
65
    put_buffer(&s->pb, buf, strlen(buf));
 
66
    put_flush_packet(&s->pb);
 
67
    return 0;
 
68
}
 
69
#endif
 
70
 
 
71
#ifdef CONFIG_CRC_MUXER
 
72
AVOutputFormat crc_muxer = {
95
73
    "crc",
96
74
    "crc testing format",
97
75
    NULL,
103
81
    crc_write_packet,
104
82
    crc_write_trailer,
105
83
};
106
 
 
107
 
int crc_init(void)
108
 
{
109
 
    av_register_output_format(&crc_format);
110
 
    return 0;
111
 
}
 
84
#endif
 
85
#ifdef CONFIG_FRAMECRC_MUXER
 
86
AVOutputFormat framecrc_muxer = {
 
87
    "framecrc",
 
88
    "framecrc testing format",
 
89
    NULL,
 
90
    "",
 
91
    0,
 
92
    CODEC_ID_PCM_S16LE,
 
93
    CODEC_ID_RAWVIDEO,
 
94
    NULL,
 
95
    framecrc_write_packet,
 
96
    NULL,
 
97
};
 
98
#endif