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