summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/vorbis/libtremorplugin.cpp
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/vorbis/libtremorplugin.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/vorbis/libtremorplugin.cpp274
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
41extern "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
52class LibTremorPluginData {
53public:
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
65LibTremorPlugin::LibTremorPlugin() {
66qDebug("<<<<<<<<<<<<<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
77LibTremorPlugin::~LibTremorPlugin() {
78 close();
79 delete d;
80}
81
82
83bool 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
103bool 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
163bool 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
180bool LibTremorPlugin::isOpen() {
181 debugMsg( "LibTremorPlugin::isOpen" );
182 return ( d->f != 0 );
183}
184
185
186const QString &LibTremorPlugin::fileInfo() {
187 return d->finfo;
188}
189
190int LibTremorPlugin::audioStreams() {
191 debugMsg( "LibTremorPlugin::audioStreams" );
192 return 1;
193}
194
195
196int LibTremorPlugin::audioChannels( int ) {
197 qDebug( "LibTremorPlugin::audioChannels: %i", d->vi->channels );
198 return d->vi->channels;
199}
200
201
202int LibTremorPlugin::audioFrequency( int ) {
203 qDebug( "LibTremorPlugin::audioFrequency: %ld", d->vi->rate );
204 return d->vi->rate;
205}
206
207
208int LibTremorPlugin::audioSamples( int ) {
209 debugMsg( "LibTremorPlugin::audioSamples" );
210 return (int) ov_pcm_total(&d->vf,-1);
211}
212
213
214bool LibTremorPlugin::audioSetSample( long, int ) {
215 debugMsg( "LibTremorPlugin::audioSetSample" );
216 return FALSE;
217}
218
219
220long LibTremorPlugin::audioGetSample( int ) {
221 debugMsg( "LibTremorPlugin::audioGetSample" );
222 return 0;
223}
224
225
226bool 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
270double LibTremorPlugin::getTime() {
271 debugMsg( "LibTremorPlugin::getTime" );
272 return 0.0;
273}
274