author | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
commit | 15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff) | |
tree | c2fa0399a2c47fda8e2cd0092c73a809d17f68eb /core/multimedia/opieplayer/libmad/stream.c | |
download | opie-15318cad33835e4e2dc620d033e43cd930676cdd.zip opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2 |
Initial revision
Diffstat (limited to 'core/multimedia/opieplayer/libmad/stream.c') (more/less context) (show whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/libmad/stream.c | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/core/multimedia/opieplayer/libmad/stream.c b/core/multimedia/opieplayer/libmad/stream.c new file mode 100644 index 0000000..dea7b8e --- a/dev/null +++ b/core/multimedia/opieplayer/libmad/stream.c | |||
@@ -0,0 +1,123 @@ | |||
1 | /* | ||
2 | * mad - MPEG audio decoder | ||
3 | * Copyright (C) 2000-2001 Robert Leslie | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program 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 | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | * | ||
19 | * $Id$ | ||
20 | */ | ||
21 | |||
22 | # ifdef HAVE_CONFIG_H | ||
23 | # include "libmad_config.h" | ||
24 | # endif | ||
25 | |||
26 | # include "libmad_global.h" | ||
27 | |||
28 | # include <stdlib.h> | ||
29 | |||
30 | # include "bit.h" | ||
31 | # include "stream.h" | ||
32 | |||
33 | /* | ||
34 | * NAME:stream->init() | ||
35 | * DESCRIPTION:initialize stream struct | ||
36 | */ | ||
37 | void mad_stream_init(struct mad_stream *stream) | ||
38 | { | ||
39 | stream->buffer = 0; | ||
40 | stream->bufend = 0; | ||
41 | stream->skiplen = 0; | ||
42 | |||
43 | stream->sync = 0; | ||
44 | stream->freerate = 0; | ||
45 | |||
46 | stream->this_frame = 0; | ||
47 | stream->next_frame = 0; | ||
48 | mad_bit_init(&stream->ptr, 0); | ||
49 | |||
50 | mad_bit_init(&stream->anc_ptr, 0); | ||
51 | stream->anc_bitlen = 0; | ||
52 | |||
53 | stream->main_data = 0; | ||
54 | stream->md_len = 0; | ||
55 | |||
56 | stream->options = 0; | ||
57 | stream->error = 0; | ||
58 | } | ||
59 | |||
60 | /* | ||
61 | * NAME:stream->finish() | ||
62 | * DESCRIPTION:deallocate any dynamic memory associated with stream | ||
63 | */ | ||
64 | void mad_stream_finish(struct mad_stream *stream) | ||
65 | { | ||
66 | if (stream->main_data) { | ||
67 | free(stream->main_data); | ||
68 | stream->main_data = 0; | ||
69 | } | ||
70 | |||
71 | mad_bit_finish(&stream->anc_ptr); | ||
72 | mad_bit_finish(&stream->ptr); | ||
73 | } | ||
74 | |||
75 | /* | ||
76 | * NAME:stream->buffer() | ||
77 | * DESCRIPTION:set stream buffer pointers | ||
78 | */ | ||
79 | void mad_stream_buffer(struct mad_stream *stream, | ||
80 | unsigned char const *buffer, unsigned long length) | ||
81 | { | ||
82 | stream->buffer = buffer; | ||
83 | stream->bufend = buffer + length; | ||
84 | |||
85 | stream->this_frame = buffer; | ||
86 | stream->next_frame = buffer; | ||
87 | |||
88 | stream->sync = 1; | ||
89 | |||
90 | mad_bit_init(&stream->ptr, buffer); | ||
91 | } | ||
92 | |||
93 | /* | ||
94 | * NAME:stream->skip() | ||
95 | * DESCRIPTION:arrange to skip bytes before the next frame | ||
96 | */ | ||
97 | void mad_stream_skip(struct mad_stream *stream, unsigned long length) | ||
98 | { | ||
99 | stream->skiplen += length; | ||
100 | } | ||
101 | |||
102 | /* | ||
103 | * NAME:stream->sync() | ||
104 | * DESCRIPTION:locate the next stream sync word | ||
105 | */ | ||
106 | int mad_stream_sync(struct mad_stream *stream) | ||
107 | { | ||
108 | register unsigned char const *ptr, *end; | ||
109 | |||
110 | ptr = mad_bit_nextbyte(&stream->ptr); | ||
111 | end = stream->bufend; | ||
112 | |||
113 | while (ptr < end - 1 && | ||
114 | !(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0)) | ||
115 | ++ptr; | ||
116 | |||
117 | if (end - ptr < MAD_BUFFER_GUARD) | ||
118 | return -1; | ||
119 | |||
120 | mad_bit_init(&stream->ptr, ptr); | ||
121 | |||
122 | return 0; | ||
123 | } | ||