author | llornkcor <llornkcor> | 2003-04-08 02:56:00 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2003-04-08 02:56:00 (UTC) |
commit | 4e998346fbe802e534db9f04f63fd04e96ba9501 (patch) (unidiff) | |
tree | c969faf216b7f75613c4cabece3b1d3441fc39a7 /core/multimedia/opieplayer/vorbis/libtremorplugin.cpp | |
parent | eee5531d24fdb17011debaa7acd42683330e55b6 (diff) | |
download | opie-4e998346fbe802e534db9f04f63fd04e96ba9501.zip opie-4e998346fbe802e534db9f04f63fd04e96ba9501.tar.gz opie-4e998346fbe802e534db9f04f63fd04e96ba9501.tar.bz2 |
vorbis lib and plugin for opieplayer1
Diffstat (limited to 'core/multimedia/opieplayer/vorbis/libtremorplugin.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/vorbis/libtremorplugin.cpp | 274 |
1 files changed, 274 insertions, 0 deletions
diff --git a/core/multimedia/opieplayer/vorbis/libtremorplugin.cpp b/core/multimedia/opieplayer/vorbis/libtremorplugin.cpp new file mode 100644 index 0000000..c1e1a23 --- a/dev/null +++ b/core/multimedia/opieplayer/vorbis/libtremorplugin.cpp | |||
@@ -0,0 +1,274 @@ | |||
1 | /**************************************************************************** | ||
2 | * libtremorplugin.cpp | ||
3 | * | ||
4 | * Copyright (C) 2002 Latchesar Ionkov <lucho@ionkov.net> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | ****************************************************************************/ | ||
20 | // fixed and adapted for opieplayer 2003 ljp <llornkcor@handhelds.org> | ||
21 | |||
22 | #include <stdio.h> | ||
23 | #include <stdarg.h> | ||
24 | #include <stdlib.h> | ||
25 | #include <sys/types.h> | ||
26 | #include <sys/stat.h> | ||
27 | #include <fcntl.h> | ||
28 | #include <unistd.h> | ||
29 | #include <string.h> | ||
30 | #include <errno.h> | ||
31 | #include <time.h> | ||
32 | #include <locale.h> | ||
33 | #include <math.h> | ||
34 | #include <assert.h> | ||
35 | |||
36 | #include <qmap.h> | ||
37 | |||
38 | #include "libtremorplugin.h" | ||
39 | |||
40 | |||
41 | extern "C" { | ||
42 | #include "tremor/ivorbiscodec.h" | ||
43 | #include "tremor/ivorbisfile.h" | ||
44 | } | ||
45 | |||
46 | |||
47 | #define MPEG_BUFFER_SIZE 65536 | ||
48 | //#define debugMsg(a) qDebug(a) | ||
49 | #define debugMsg(a) | ||
50 | |||
51 | |||
52 | class LibTremorPluginData { | ||
53 | public: | ||
54 | char* filename; | ||
55 | FILE* f; | ||
56 | OggVorbis_File vf; | ||
57 | vorbis_info* vi; | ||
58 | vorbis_comment* vc; | ||
59 | bool bos; | ||
60 | int csection; | ||
61 | QString finfo; | ||
62 | }; | ||
63 | |||
64 | |||
65 | LibTremorPlugin::LibTremorPlugin() { | ||
66 | qDebug("<<<<<<<<<<<<<TREMOR!!!!!>>>>>>>>>>>>>>>>>>"); | ||
67 | d = new LibTremorPluginData; | ||
68 | d->f = 0; | ||
69 | d->vi = 0; | ||
70 | d->vc = 0; | ||
71 | d->bos = 0; | ||
72 | d->csection = 0; | ||
73 | d->finfo = ""; | ||
74 | } | ||
75 | |||
76 | |||
77 | LibTremorPlugin::~LibTremorPlugin() { | ||
78 | close(); | ||
79 | delete d; | ||
80 | } | ||
81 | |||
82 | |||
83 | bool LibTremorPlugin::isFileSupported( const QString& path ) { | ||
84 | debugMsg( "LibTremorPlugin::isFileSupported" ); | ||
85 | |||
86 | // Mpeg file extensions | ||
87 | // "mp2","mp3","m1v","m2v","m2s","mpg","vob","mpeg",ac3" | ||
88 | // Other media extensions | ||
89 | // "wav","mid","mod","s3m","ogg","avi","mov","sid" | ||
90 | |||
91 | char *ext = strrchr( path.latin1(), '.' ); | ||
92 | |||
93 | // Test file extension | ||
94 | if ( ext ) { | ||
95 | if ( strncasecmp(ext, ".ogg", 4) == 0 ) | ||
96 | return TRUE; | ||
97 | } | ||
98 | |||
99 | return FALSE; | ||
100 | } | ||
101 | |||
102 | |||
103 | bool LibTremorPlugin::open( const QString& path ) { | ||
104 | debugMsg( "LibTremorPlugin::open" ); | ||
105 | |||
106 | d->filename = (char*) path.latin1(); | ||
107 | d->f = fopen( d->filename, "r" ); | ||
108 | if (d->f == 0) { | ||
109 | qDebug("error opening %s", d->filename ); | ||
110 | return FALSE; | ||
111 | } | ||
112 | |||
113 | if (ov_open(d->f, &d->vf, NULL, 0) < 0) { | ||
114 | qDebug("error opening %s", d->filename); | ||
115 | return FALSE; | ||
116 | } | ||
117 | |||
118 | d->vc = ov_comment(&d->vf, -1); | ||
119 | d->vi = ov_info(&d->vf, -1); | ||
120 | d->bos = false; | ||
121 | |||
122 | QString comments[] = { "title", "artist", "album", "year", "tracknumber", "" }; | ||
123 | QString cdescr[] = { "Title", "Artist", "Album", "Year", "Track", "" }; | ||
124 | |||
125 | |||
126 | QMap<QString, QString> cmap; | ||
127 | char** cptr = d->vc->user_comments; | ||
128 | |||
129 | while (*cptr != 0) { | ||
130 | QString s(*cptr); | ||
131 | int n = s.find('='); | ||
132 | |||
133 | if (n < 0) { | ||
134 | continue; | ||
135 | } | ||
136 | |||
137 | QString key = s.left(n).lower(); | ||
138 | QString value = s.mid(n+1); | ||
139 | |||
140 | cmap[key] = value; | ||
141 | cptr++; | ||
142 | } | ||
143 | |||
144 | d->finfo = ""; | ||
145 | for(int i = 0; !comments[i].isEmpty(); i++) { | ||
146 | QString v = cmap[comments[i].lower()]; | ||
147 | |||
148 | if (!v.isEmpty()) { | ||
149 | if (!d->finfo.isEmpty()) { | ||
150 | d->finfo += ", "; | ||
151 | } | ||
152 | |||
153 | d->finfo += cdescr[i] + ": " + v; | ||
154 | } | ||
155 | } | ||
156 | |||
157 | qDebug("finfo: " + d->finfo); | ||
158 | |||
159 | return TRUE; | ||
160 | } | ||
161 | |||
162 | |||
163 | bool LibTremorPlugin::close() { | ||
164 | debugMsg( "LibTremorPlugin::close" ); | ||
165 | |||
166 | int result = TRUE; | ||
167 | |||
168 | if (fclose(d->f) == -1) { | ||
169 | qDebug("error closing file %s", d->filename); | ||
170 | result = FALSE; | ||
171 | } | ||
172 | |||
173 | d->f = 0; | ||
174 | d->finfo = ""; | ||
175 | |||
176 | return result; | ||
177 | } | ||
178 | |||
179 | |||
180 | bool LibTremorPlugin::isOpen() { | ||
181 | debugMsg( "LibTremorPlugin::isOpen" ); | ||
182 | return ( d->f != 0 ); | ||
183 | } | ||
184 | |||
185 | |||
186 | const QString &LibTremorPlugin::fileInfo() { | ||
187 | return d->finfo; | ||
188 | } | ||
189 | |||
190 | int LibTremorPlugin::audioStreams() { | ||
191 | debugMsg( "LibTremorPlugin::audioStreams" ); | ||
192 | return 1; | ||
193 | } | ||
194 | |||
195 | |||
196 | int LibTremorPlugin::audioChannels( int ) { | ||
197 | qDebug( "LibTremorPlugin::audioChannels: %i", d->vi->channels ); | ||
198 | return d->vi->channels; | ||
199 | } | ||
200 | |||
201 | |||
202 | int LibTremorPlugin::audioFrequency( int ) { | ||
203 | qDebug( "LibTremorPlugin::audioFrequency: %ld", d->vi->rate ); | ||
204 | return d->vi->rate; | ||
205 | } | ||
206 | |||
207 | |||
208 | int LibTremorPlugin::audioSamples( int ) { | ||
209 | debugMsg( "LibTremorPlugin::audioSamples" ); | ||
210 | return (int) ov_pcm_total(&d->vf,-1); | ||
211 | } | ||
212 | |||
213 | |||
214 | bool LibTremorPlugin::audioSetSample( long, int ) { | ||
215 | debugMsg( "LibTremorPlugin::audioSetSample" ); | ||
216 | return FALSE; | ||
217 | } | ||
218 | |||
219 | |||
220 | long LibTremorPlugin::audioGetSample( int ) { | ||
221 | debugMsg( "LibTremorPlugin::audioGetSample" ); | ||
222 | return 0; | ||
223 | } | ||
224 | |||
225 | |||
226 | bool LibTremorPlugin::audioReadSamples( short *output, int, long samples, long& samplesMade, int ) { | ||
227 | // qDebug( "<<<<<<<<<<<<LibTremorPlugin::audioReadStereoSamples %d", samples ); | ||
228 | |||
229 | int old_section = d->csection; | ||
230 | |||
231 | char* buf = (char*) output; | ||
232 | int length = samples * 4; | ||
233 | |||
234 | if ( samples == 0 ) | ||
235 | return false; | ||
236 | |||
237 | while (length > 0) { | ||
238 | if (d->bos) { | ||
239 | d->vi = ov_info(&d->vf, -1); | ||
240 | d->vc = ov_comment(&d->vf, -1); | ||
241 | } | ||
242 | |||
243 | int n = 4096; | ||
244 | if (length < n) { | ||
245 | n = length; | ||
246 | } | ||
247 | |||
248 | long ret = ov_read(&d->vf, buf, n, &d->csection); | ||
249 | // qDebug("%d", ret); | ||
250 | if (ret == 0) { | ||
251 | break; | ||
252 | } else if (ret < 0) { | ||
253 | return true; | ||
254 | } | ||
255 | |||
256 | if (old_section != d->csection) { | ||
257 | d->bos = true; | ||
258 | } | ||
259 | |||
260 | buf += ret; | ||
261 | length -= ret; | ||
262 | |||
263 | } | ||
264 | |||
265 | samplesMade = samples; | ||
266 | |||
267 | return true; | ||
268 | } | ||
269 | |||
270 | double LibTremorPlugin::getTime() { | ||
271 | debugMsg( "LibTremorPlugin::getTime" ); | ||
272 | return 0.0; | ||
273 | } | ||
274 | |||