summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-02-25 05:10:32 (UTC)
committer llornkcor <llornkcor>2002-02-25 05:10:32 (UTC)
commit1bebd27631a6c9d1ab967cbb32dd4e796b3b0402 (patch) (unidiff)
tree8ce49800cba26f6f2c33de74a71d4efe0338843f
parentd948361c1b475fab4660b28fbf5ec21fd34d923f (diff)
downloadopie-1bebd27631a6c9d1ab967cbb32dd4e796b3b0402.zip
opie-1bebd27631a6c9d1ab967cbb32dd4e796b3b0402.tar.gz
opie-1bebd27631a6c9d1ab967cbb32dd4e796b3b0402.tar.bz2
fixed 2
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/Makefile.in30
-rw-r--r--core/multimedia/opieplayer/audiodevice.cpp155
-rw-r--r--core/multimedia/opieplayer/audiodevice.h10
-rw-r--r--core/multimedia/opieplayer/audiowidget.cpp126
-rw-r--r--core/multimedia/opieplayer/audiowidget.h4
-rw-r--r--core/multimedia/opieplayer/libmad/Makefile.in2
-rw-r--r--core/multimedia/opieplayer/libmad/libmad.pro18
-rw-r--r--core/multimedia/opieplayer/libmad/libmadplugin.cpp302
-rw-r--r--core/multimedia/opieplayer/libmad/libmadplugin.h4
-rw-r--r--core/multimedia/opieplayer/libmad/libmadpluginimpl.h4
-rw-r--r--core/multimedia/opieplayer/libmpeg3/Makefile.in6
-rw-r--r--core/multimedia/opieplayer/libmpeg3/libmpeg3.pro79
-rw-r--r--core/multimedia/opieplayer/libmpeg3/libmpeg3plugin.h4
-rw-r--r--core/multimedia/opieplayer/libmpeg3/libmpeg3pluginimpl.h3
-rw-r--r--core/multimedia/opieplayer/loopcontrol.cpp353
-rw-r--r--core/multimedia/opieplayer/loopcontrol.h8
-rw-r--r--core/multimedia/opieplayer/loopcontrol_threaded.cpp8
-rw-r--r--core/multimedia/opieplayer/loopcontrol_threaded.h6
-rw-r--r--core/multimedia/opieplayer/mediaplayerplugininterface.h9
-rw-r--r--core/multimedia/opieplayer/mediaplayerstate.cpp67
-rw-r--r--core/multimedia/opieplayer/mpegplayer.pro29
-rw-r--r--core/multimedia/opieplayer/playlistselection.cpp49
-rw-r--r--core/multimedia/opieplayer/playlistselection.h6
-rw-r--r--core/multimedia/opieplayer/playlistwidget.cpp510
-rw-r--r--core/multimedia/opieplayer/playlistwidget.h37
-rw-r--r--core/multimedia/opieplayer/videowidget.cpp363
-rw-r--r--core/multimedia/opieplayer/wavplugin/Makefile.in4
27 files changed, 1223 insertions, 973 deletions
diff --git a/core/multimedia/opieplayer/Makefile.in b/core/multimedia/opieplayer/Makefile.in
index 1d2ff5e..e8ccc34 100644
--- a/core/multimedia/opieplayer/Makefile.in
+++ b/core/multimedia/opieplayer/Makefile.in
@@ -91,183 +91,203 @@ OBJMOC = moc_loopcontrol.o \
91 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $< 91 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
92 92
93####### Build rules 93####### Build rules
94 94
95 95
96all: $(DESTDIR)$(TARGET) 96all: $(DESTDIR)$(TARGET)
97 97
98$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS) 98$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
99 $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS) 99 $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)
100 100
101moc: $(SRCMOC) 101moc: $(SRCMOC)
102 102
103tmake: 103tmake:
104 tmake mpegplayer.pro 104 tmake mpegplayer.pro
105 105
106clean: 106clean:
107 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS) 107 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
108 -rm -f *~ core 108 -rm -f *~ core
109 -rm -f allmoc.cpp 109 -rm -f allmoc.cpp
110 110
111####### Extension Modules 111####### Extension Modules
112 112
113listpromodules: 113listpromodules:
114 @echo 114 @echo
115 115
116listallmodules: 116listallmodules:
117 @echo 117 @echo
118 118
119listaddonpromodules: 119listaddonpromodules:
120 @echo 120 @echo
121 121
122listaddonentmodules: 122listaddonentmodules:
123 @echo 123 @echo
124 124
125 125
126REQUIRES= 126REQUIRES=
127 127
128####### Sub-libraries 128####### Sub-libraries
129 129
130 130
131###### Combined headers 131###### Combined headers
132 132
133 133
134 134
135####### Compile 135####### Compile
136 136
137main.o: main.cpp \ 137main.o: main.cpp \
138 $(OPIEDIR)/include/qpe/qpeapplication.h \ 138 $(OPIEDIR)/include/qpe/qpeapplication.h \
139 $(OPIEDIR)/include/qpedecoration_qws.h \
140 $(OPIEDIR)/include/timestring.h \
139 mediaplayerstate.h \ 141 mediaplayerstate.h \
140 playlistwidget.h \ 142 playlistwidget.h \
141 $(OPIEDIR)/include/qpe/applnk.h \ 143 $(OPIEDIR)/include/qpe/applnk.h \
142 audiowidget.h \ 144 audiowidget.h \
143 videowidget.h \ 145 videowidget.h \
144 loopcontrol.h \ 146 loopcontrol.h \
145 mediaplayer.h \ 147 mediaplayer.h \
146 $(OPIEDIR)/include/qpe/qlibrary.h \ 148 $(OPIEDIR)/include/qpe/qlibrary.h \
147 $(OPIEDIR)/include/qpe/qcom.h \ 149 $(OPIEDIR)/include/qpe/qcom.h \
148 $(OPIEDIR)/include/qpe/quuid.h 150 $(OPIEDIR)/include/qpe/quuid.h \
151 $(OPIEDIR)/include/qpe/mediaplayerplugininterface.h
149 152
150loopcontrol.o: loopcontrol.cpp \ 153loopcontrol.o: loopcontrol.cpp \
151 $(OPIEDIR)/include/qpe/qpeapplication.h \ 154 $(OPIEDIR)/include/qpe/qpeapplication.h \
152 $(OPIEDIR)/include/qpe/qcopenvelope_qws.h \ 155 $(OPIEDIR)/include/qpedecoration_qws.h \
156 $(OPIEDIR)/include/timestring.h \
153 loopcontrol.h \ 157 loopcontrol.h \
154 videowidget.h \ 158 videowidget.h \
155 audiodevice.h \ 159 audiodevice.h \
156 mediaplayerplugininterface.h \ 160 mediaplayerplugininterface.h \
157 $(OPIEDIR)/include/qpe/qcom.h \ 161 $(OPIEDIR)/include/qpe/qcom.h \
158 $(OPIEDIR)/include/qpe/quuid.h \ 162 $(OPIEDIR)/include/qpe/quuid.h \
159 mediaplayerstate.h 163 mediaplayerstate.h
160 164
161playlistselection.o: playlistselection.cpp \ 165playlistselection.o: playlistselection.cpp \
162 $(OPIEDIR)/include/qpe/applnk.h \ 166 $(OPIEDIR)/include/qpe/applnk.h \
163 $(OPIEDIR)/include/qpe/resource.h \ 167 $(OPIEDIR)/include/qpe/resource.h \
164 playlistselection.h 168 playlistselection.h
165 169
166mediaplayerstate.o: mediaplayerstate.cpp \ 170mediaplayerstate.o: mediaplayerstate.cpp \
167 $(OPIEDIR)/include/qpe/qpeapplication.h \ 171 $(OPIEDIR)/include/qpe/qpeapplication.h \
172 $(OPIEDIR)/include/qpedecoration_qws.h \
173 $(OPIEDIR)/include/timestring.h \
168 $(OPIEDIR)/include/qpe/qlibrary.h \ 174 $(OPIEDIR)/include/qpe/qlibrary.h \
169 $(OPIEDIR)/include/qpe/qcom.h \ 175 $(OPIEDIR)/include/qpe/qcom.h \
170 $(OPIEDIR)/include/qpe/quuid.h \ 176 $(OPIEDIR)/include/qpe/quuid.h \
171 $(OPIEDIR)/include/qpe/config.h \ 177 $(OPIEDIR)/include/qpe/config.h \
178 mediaplayerplugininterface.h \
172 mediaplayerstate.h \ 179 mediaplayerstate.h \
173 libmad/libmadpluginimpl.h \ 180 libmad/libmadpluginimpl.h \
174 libmpeg3/libmpeg3pluginimpl.h \ 181 libmpeg3/libmpeg3pluginimpl.h \
175 wavplugin/wavpluginimpl.h 182 wavplugin/wavpluginimpl.h
176 183
177videowidget.o: videowidget.cpp \ 184videowidget.o: videowidget.cpp \
178 $(OPIEDIR)/include/qpe/resource.h \ 185 $(OPIEDIR)/include/qpe/resource.h \
186 mediaplayerplugininterface.h \
187 $(OPIEDIR)/include/qpe/qcom.h \
188 $(OPIEDIR)/include/qpe/quuid.h \
179 videowidget.h \ 189 videowidget.h \
180 mediaplayerstate.h 190 mediaplayerstate.h
181 191
182audiowidget.o: audiowidget.cpp \ 192audiowidget.o: audiowidget.cpp \
183 $(OPIEDIR)/include/qpe/resource.h \ 193 $(OPIEDIR)/include/qpe/resource.h \
184 audiowidget.h \ 194 audiowidget.h \
185 mediaplayerstate.h 195 mediaplayerstate.h
186 196
187playlistwidget.o: playlistwidget.cpp \ 197playlistwidget.o: playlistwidget.cpp \
188 $(OPIEDIR)/include/qpe/qpemenubar.h \ 198 $(OPIEDIR)/include/qpe/qpemenubar.h \
189 $(OPIEDIR)/include/qpe/qpetoolbar.h \ 199 $(OPIEDIR)/include/qpe/qpetoolbar.h \
190 $(OPIEDIR)/include/qpe/fileselector.h \ 200 $(OPIEDIR)/include/qpe/fileselector.h \
201 $(OPIEDIR)/include/filemanager.h \
202 $(OPIEDIR)/include/applnk.h \
203 $(OPIEDIR)/include/qpe/qpeapplication.h \
204 $(OPIEDIR)/include/qpedecoration_qws.h \
205 $(OPIEDIR)/include/timestring.h \
191 $(OPIEDIR)/include/qpe/applnk.h \ 206 $(OPIEDIR)/include/qpe/applnk.h \
192 $(OPIEDIR)/include/qpe/config.h \ 207 $(OPIEDIR)/include/qpe/config.h \
193 $(OPIEDIR)/include/qpe/global.h \ 208 $(OPIEDIR)/include/qpe/global.h \
194 $(OPIEDIR)/include/qpe/resource.h \ 209 $(OPIEDIR)/include/qpe/resource.h \
195 playlistselection.h \ 210 playlistselection.h \
196 playlistwidget.h \ 211 playlistwidget.h \
197 mediaplayerstate.h 212 mediaplayerstate.h
198 213
199mediaplayer.o: mediaplayer.cpp \ 214mediaplayer.o: mediaplayer.cpp \
200 $(OPIEDIR)/include/qpe/qpeapplication.h \ 215 $(OPIEDIR)/include/qpe/qpeapplication.h \
216 $(OPIEDIR)/include/qpedecoration_qws.h \
217 $(OPIEDIR)/include/timestring.h \
201 $(OPIEDIR)/include/qpe/qlibrary.h \ 218 $(OPIEDIR)/include/qpe/qlibrary.h \
202 $(OPIEDIR)/include/qpe/qcom.h \ 219 $(OPIEDIR)/include/qpe/qcom.h \
203 $(OPIEDIR)/include/qpe/quuid.h \ 220 $(OPIEDIR)/include/qpe/quuid.h \
204 $(OPIEDIR)/include/qpe/resource.h \ 221 $(OPIEDIR)/include/qpe/resource.h \
205 $(OPIEDIR)/include/qpe/config.h \ 222 $(OPIEDIR)/include/qpe/config.h \
206 mediaplayer.h \ 223 mediaplayer.h \
224 $(OPIEDIR)/include/qpe/mediaplayerplugininterface.h \
207 playlistwidget.h \ 225 playlistwidget.h \
208 $(OPIEDIR)/include/qpe/applnk.h \ 226 $(OPIEDIR)/include/qpe/applnk.h \
209 audiowidget.h \ 227 audiowidget.h \
210 loopcontrol.h \ 228 loopcontrol.h \
211 audiodevice.h \ 229 audiodevice.h \
212 mediaplayerstate.h 230 mediaplayerstate.h
213 231
214audiodevice.o: audiodevice.cpp \ 232audiodevice.o: audiodevice.cpp \
215 $(OPIEDIR)/include/qpe/qpeapplication.h \ 233 $(OPIEDIR)/include/qpe/qpeapplication.h \
234 $(OPIEDIR)/include/qpedecoration_qws.h \
235 $(OPIEDIR)/include/timestring.h \
216 $(OPIEDIR)/include/qpe/config.h \ 236 $(OPIEDIR)/include/qpe/config.h \
217 audiodevice.h \ 237 audiodevice.h
218 $(OPIEDIR)/include/qpe/qcopenvelope_qws.h
219 238
220moc_loopcontrol.o: moc_loopcontrol.cpp \ 239moc_loopcontrol.o: moc_loopcontrol.cpp \
221 loopcontrol.h 240 loopcontrol.h
222 241
223moc_playlistselection.o: moc_playlistselection.cpp \ 242moc_playlistselection.o: moc_playlistselection.cpp \
224 playlistselection.h \ 243 playlistselection.h \
225 $(OPIEDIR)/include/qpe/applnk.h 244 $(OPIEDIR)/include/qpe/applnk.h
226 245
227moc_mediaplayerstate.o: moc_mediaplayerstate.cpp \ 246moc_mediaplayerstate.o: moc_mediaplayerstate.cpp \
228 mediaplayerstate.h 247 mediaplayerstate.h
229 248
230moc_videowidget.o: moc_videowidget.cpp \ 249moc_videowidget.o: moc_videowidget.cpp \
231 videowidget.h 250 videowidget.h
232 251
233moc_audiowidget.o: moc_audiowidget.cpp \ 252moc_audiowidget.o: moc_audiowidget.cpp \
234 audiowidget.h 253 audiowidget.h
235 254
236moc_playlistwidget.o: moc_playlistwidget.cpp \ 255moc_playlistwidget.o: moc_playlistwidget.cpp \
237 playlistwidget.h \ 256 playlistwidget.h \
238 $(OPIEDIR)/include/qpe/applnk.h 257 $(OPIEDIR)/include/qpe/applnk.h
239 258
240moc_mediaplayer.o: moc_mediaplayer.cpp \ 259moc_mediaplayer.o: moc_mediaplayer.cpp \
241 mediaplayer.h \ 260 mediaplayer.h \
242 $(OPIEDIR)/include/qpe/qlibrary.h \ 261 $(OPIEDIR)/include/qpe/qlibrary.h \
243 $(OPIEDIR)/include/qpe/qcom.h \ 262 $(OPIEDIR)/include/qpe/qcom.h \
244 $(OPIEDIR)/include/qpe/quuid.h 263 $(OPIEDIR)/include/qpe/quuid.h \
264 $(OPIEDIR)/include/qpe/mediaplayerplugininterface.h
245 265
246moc_audiodevice.o: moc_audiodevice.cpp \ 266moc_audiodevice.o: moc_audiodevice.cpp \
247 audiodevice.h 267 audiodevice.h
248 268
249moc_loopcontrol.cpp: loopcontrol.h 269moc_loopcontrol.cpp: loopcontrol.h
250 $(MOC) loopcontrol.h -o moc_loopcontrol.cpp 270 $(MOC) loopcontrol.h -o moc_loopcontrol.cpp
251 271
252moc_playlistselection.cpp: playlistselection.h 272moc_playlistselection.cpp: playlistselection.h
253 $(MOC) playlistselection.h -o moc_playlistselection.cpp 273 $(MOC) playlistselection.h -o moc_playlistselection.cpp
254 274
255moc_mediaplayerstate.cpp: mediaplayerstate.h 275moc_mediaplayerstate.cpp: mediaplayerstate.h
256 $(MOC) mediaplayerstate.h -o moc_mediaplayerstate.cpp 276 $(MOC) mediaplayerstate.h -o moc_mediaplayerstate.cpp
257 277
258moc_videowidget.cpp: videowidget.h 278moc_videowidget.cpp: videowidget.h
259 $(MOC) videowidget.h -o moc_videowidget.cpp 279 $(MOC) videowidget.h -o moc_videowidget.cpp
260 280
261moc_audiowidget.cpp: audiowidget.h 281moc_audiowidget.cpp: audiowidget.h
262 $(MOC) audiowidget.h -o moc_audiowidget.cpp 282 $(MOC) audiowidget.h -o moc_audiowidget.cpp
263 283
264moc_playlistwidget.cpp: playlistwidget.h 284moc_playlistwidget.cpp: playlistwidget.h
265 $(MOC) playlistwidget.h -o moc_playlistwidget.cpp 285 $(MOC) playlistwidget.h -o moc_playlistwidget.cpp
266 286
267moc_mediaplayer.cpp: mediaplayer.h 287moc_mediaplayer.cpp: mediaplayer.h
268 $(MOC) mediaplayer.h -o moc_mediaplayer.cpp 288 $(MOC) mediaplayer.h -o moc_mediaplayer.cpp
269 289
270moc_audiodevice.cpp: audiodevice.h 290moc_audiodevice.cpp: audiodevice.h
271 $(MOC) audiodevice.h -o moc_audiodevice.cpp 291 $(MOC) audiodevice.h -o moc_audiodevice.cpp
272 292
273 293
diff --git a/core/multimedia/opieplayer/audiodevice.cpp b/core/multimedia/opieplayer/audiodevice.cpp
index 7b3700a..9a10eb4 100644
--- a/core/multimedia/opieplayer/audiodevice.cpp
+++ b/core/multimedia/opieplayer/audiodevice.cpp
@@ -1,387 +1,370 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20// L.J.Potter added better error code Fri 02-15-2002 14:37:47
20 21
21#include <stdlib.h> 22#include <stdlib.h>
23#include <stdio.h>
22#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
23#include <qpe/config.h> 25#include <qpe/config.h>
24#include "audiodevice.h" 26#include "audiodevice.h"
25 27
26#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) 28#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
27#include "qpe/qcopenvelope_qws.h" 29#include "qpe/qcopenvelope_qws.h"
28#endif 30#endif
29 31
30#ifdef Q_WS_WIN 32#ifdef Q_WS_WIN
31#include <windows.h> 33#include <windows.h>
32#include <mmsystem.h> 34#include <mmsystem.h>
33#include <mmreg.h> 35#include <mmreg.h>
34#endif 36#endif
35 37
36#if defined(Q_WS_X11) || defined(Q_WS_QWS) 38#if defined(Q_WS_X11) || defined(Q_WS_QWS)
37#include <fcntl.h> 39#include <fcntl.h>
38#include <sys/ioctl.h> 40#include <sys/ioctl.h>
39#include <sys/soundcard.h> 41#include <sys/soundcard.h>
40#include <sys/stat.h> 42#include <sys/stat.h>
41#include <sys/time.h> 43#include <sys/time.h>
42#include <sys/types.h> 44#include <sys/types.h>
43#include <unistd.h> 45#include <unistd.h>
44#endif 46#endif
45 47
46#if defined(Q_OS_WIN32) 48#if defined(Q_OS_WIN32)
47static const int expectedBytesPerMilliSecond = 2 * 2 * 44000 / 1000; 49static const int expectedBytesPerMilliSecond = 2 * 2 * 44000 / 1000;
48static const int timerResolutionMilliSeconds = 30; 50static const int timerResolutionMilliSeconds = 30;
49static const int sound_fragment_bytes = timerResolutionMilliSeconds * expectedBytesPerMilliSecond; 51static const int sound_fragment_bytes = timerResolutionMilliSeconds * expectedBytesPerMilliSecond;
50#else 52#else
51# if defined(QT_QWS_IPAQ) 53# if defined(QT_QWS_IPAQ)
52static const int sound_fragment_shift = 14; 54static const int sound_fragment_shift = 14;
53# else 55# else
54static const int sound_fragment_shift = 16; 56static const int sound_fragment_shift = 16;
55# endif 57# endif
56static const int sound_fragment_bytes = (1<<sound_fragment_shift); 58static const int sound_fragment_bytes = (1<<sound_fragment_shift);
57#endif 59#endif
58 60
59 61
60class AudioDevicePrivate { 62class AudioDevicePrivate {
61public: 63public:
62 int handle; 64 int handle;
63 unsigned int frequency; 65 unsigned int frequency;
64 unsigned int channels; 66 unsigned int channels;
65 unsigned int bytesPerSample; 67 unsigned int bytesPerSample;
66 unsigned int bufferSize; 68 unsigned int bufferSize;
67#ifndef Q_OS_WIN32 69#ifndef Q_OS_WIN32
68 bool can_GETOSPACE; 70 bool can_GETOSPACE;
69 char* unwrittenBuffer; 71 char* unwrittenBuffer;
70 unsigned int unwritten; 72 unsigned int unwritten;
71#endif 73#endif
72 74
73 static int dspFd; 75 static int dspFd;
74 static bool muted; 76 static bool muted;
75 static unsigned int leftVolume; 77 static unsigned int leftVolume;
76 static unsigned int rightVolume; 78 static unsigned int rightVolume;
77}; 79};
78 80
79 81
80#ifdef Q_WS_QWS 82#ifdef Q_WS_QWS
81// This is for keeping the device open in-between playing files when 83// This is for keeping the device open in-between playing files when
82// the device makes clicks and it starts to drive you insane! :) 84// the device makes clicks and it starts to drive you insane! :)
83// Best to have the device not open when not using it though 85// Best to have the device not open when not using it though
84//#define KEEP_DEVICE_OPEN 86//#define KEEP_DEVICE_OPEN
85#endif 87#endif
86 88
87 89
88int AudioDevicePrivate::dspFd = 0; 90int AudioDevicePrivate::dspFd = 0;
89bool AudioDevicePrivate::muted = FALSE; 91bool AudioDevicePrivate::muted = FALSE;
90unsigned int AudioDevicePrivate::leftVolume = 0; 92unsigned int AudioDevicePrivate::leftVolume = 0;
91unsigned int AudioDevicePrivate::rightVolume = 0; 93unsigned int AudioDevicePrivate::rightVolume = 0;
92 94
93 95
94void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume, bool &muted ) { 96void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume, bool &muted ) {
95 muted = AudioDevicePrivate::muted; 97 muted = AudioDevicePrivate::muted;
96 unsigned int volume; 98 unsigned int volume;
97#ifdef Q_OS_WIN32 99#ifdef Q_OS_WIN32
98 HWAVEOUT handle; 100 HWAVEOUT handle;
99 WAVEFORMATEX formatData; 101 WAVEFORMATEX formatData;
100 formatData.cbSize = sizeof(WAVEFORMATEX); 102 formatData.cbSize = sizeof(WAVEFORMATEX);
101 formatData.wFormatTag = WAVE_FORMAT_PCM; 103 formatData.wFormatTag = WAVE_FORMAT_PCM;
102 formatData.nAvgBytesPerSec = 4 * 44000; 104 formatData.nAvgBytesPerSec = 4 * 44000;
103 formatData.nBlockAlign = 4; 105 formatData.nBlockAlign = 4;
104 formatData.nChannels = 2; 106 formatData.nChannels = 2;
105 formatData.nSamplesPerSec = 44000; 107 formatData.nSamplesPerSec = 44000;
106 formatData.wBitsPerSample = 16; 108 formatData.wBitsPerSample = 16;
107 waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); 109 waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL);
108 if ( waveOutGetVolume( handle, (LPDWORD)&volume ) ) 110 if ( waveOutGetVolume( handle, (LPDWORD)&volume ) )
109 qDebug( "get volume of audio device failed" ); 111// qDebug( "get volume of audio device failed" );
110 waveOutClose( handle ); 112 waveOutClose( handle );
111 leftVolume = volume & 0xFFFF; 113 leftVolume = volume & 0xFFFF;
112 rightVolume = volume >> 16; 114 rightVolume = volume >> 16;
113#else 115#else
114 int mixerHandle = open( "/dev/mixer", O_RDWR ); 116 int mixerHandle = open( "/dev/mixer", O_RDWR );
115 if ( mixerHandle >= 0 ) { 117 if ( mixerHandle >= 0 ) {
116 ioctl( mixerHandle, MIXER_READ(0), &volume ); 118 if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1)
119 perror("ioctl(\"MIXER_READ\")");
117 close( mixerHandle ); 120 close( mixerHandle );
118 } else 121 } else
119 qDebug( "get volume of audio device failed" ); 122 perror("open(\"/dev/mixer\")");
120 leftVolume = ((volume & 0x00FF) << 16) / 101; 123 leftVolume = ((volume & 0x00FF) << 16) / 101;
121 rightVolume = ((volume & 0xFF00) << 8) / 101; 124 rightVolume = ((volume & 0xFF00) << 8) / 101;
122#endif 125#endif
123} 126}
124 127
125 128
126void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) { 129void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) {
127 AudioDevicePrivate::muted = muted; 130 AudioDevicePrivate::muted = muted;
128 if ( muted ) { 131 if ( muted ) {
129 AudioDevicePrivate::leftVolume = leftVolume; 132 AudioDevicePrivate::leftVolume = leftVolume;
130 AudioDevicePrivate::rightVolume = rightVolume; 133 AudioDevicePrivate::rightVolume = rightVolume;
131 leftVolume = 0; 134 leftVolume = 0;
132 rightVolume = 0; 135 rightVolume = 0;
133 } else { 136 } else {
134 leftVolume = ( (int) leftVolume < 0 ) ? 0 : (( leftVolume > 0xFFFF ) ? 0xFFFF : leftVolume ); 137 leftVolume = ( (int) leftVolume < 0 ) ? 0 : (( leftVolume > 0xFFFF ) ? 0xFFFF : leftVolume );
135 rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume ); 138 rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume );
136 } 139 }
137#ifdef Q_OS_WIN32 140#ifdef Q_OS_WIN32
138 HWAVEOUT handle; 141 HWAVEOUT handle;
139 WAVEFORMATEX formatData; 142 WAVEFORMATEX formatData;
140 formatData.cbSize = sizeof(WAVEFORMATEX); 143 formatData.cbSize = sizeof(WAVEFORMATEX);
141 formatData.wFormatTag = WAVE_FORMAT_PCM; 144 formatData.wFormatTag = WAVE_FORMAT_PCM;
142 formatData.nAvgBytesPerSec = 4 * 44000; 145 formatData.nAvgBytesPerSec = 4 * 44000;
143 formatData.nBlockAlign = 4; 146 formatData.nBlockAlign = 4;
144 formatData.nChannels = 2; 147 formatData.nChannels = 2;
145 formatData.nSamplesPerSec = 44000; 148 formatData.nSamplesPerSec = 44000;
146 formatData.wBitsPerSample = 16; 149 formatData.wBitsPerSample = 16;
147 waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); 150 waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL);
148 unsigned int volume = (rightVolume << 16) | leftVolume; 151 unsigned int volume = (rightVolume << 16) | leftVolume;
149 if ( waveOutSetVolume( handle, volume ) ) 152 if ( waveOutSetVolume( handle, volume ) )
150 qDebug( "set volume of audio device failed" ); 153// qDebug( "set volume of audio device failed" );
151 waveOutClose( handle ); 154 waveOutClose( handle );
152#else 155#else
153 // Volume can be from 0 to 100 which is 101 distinct values 156 // Volume can be from 0 to 100 which is 101 distinct values
154 unsigned int rV = (rightVolume * 101) >> 16; 157 unsigned int rV = (rightVolume * 101) >> 16;
155 158
156# if 0 159# if 0
157 unsigned int lV = (leftVolume * 101) >> 16; 160 unsigned int lV = (leftVolume * 101) >> 16;
158 unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF); 161 unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF);
159 int mixerHandle = 0; 162 int mixerHandle = 0;
160 if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 163 if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
161 ioctl( mixerHandle, MIXER_WRITE(0), &volume ); 164 if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1)
165 perror("ioctl(\"MIXER_WRITE\")");
162 close( mixerHandle ); 166 close( mixerHandle );
163 } else 167 } else
164 qDebug( "set volume of audio device failed" ); 168 perror("open(\"/dev/mixer\")");
169
165# else 170# else
166 // This is the way this has to be done now I guess, doesn't allow for 171 // This is the way this has to be done now I guess, doesn't allow for
167 // independant right and left channel setting, or setting for different outputs 172 // independant right and left channel setting, or setting for different outputs
168 Config cfg("Sound"); 173 Config cfg("Sound");
169 cfg.setGroup("System"); 174 cfg.setGroup("System");
170 cfg.writeEntry("Volume",(int)rV); 175 cfg.writeEntry("Volume",(int)rV);
171# endif 176# endif
172 177
173#endif 178#endif
174// qDebug( "setting volume to: 0x%x", volume ); 179// qDebug( "setting volume to: 0x%x", volume );
175#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) 180#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
176 // Send notification that the volume has changed 181 // Send notification that the volume has changed
177 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; 182 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted;
178#endif 183#endif
179} 184}
180 185
181 186
182 187
183 188
184AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { 189AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
185 d = new AudioDevicePrivate; 190 d = new AudioDevicePrivate;
186 d->frequency = f; 191 d->frequency = f;
187 d->channels = chs; 192 d->channels = chs;
188 d->bytesPerSample = bps; 193 d->bytesPerSample = bps;
194// qDebug("%d",bps);
195 int format=0;
196 if( bps == 8) format = AFMT_U8;
197 else if( bps <= 0) format = AFMT_S16_LE;
198 else format = AFMT_S16_LE;
189 199
200// qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format);
190 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); 201 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) );
191 202
192#ifdef Q_OS_WIN32
193 UINT result;
194 WAVEFORMATEX formatData;
195 formatData.cbSize = sizeof(WAVEFORMATEX);
196/*
197 // Other possible formats windows supports
198 formatData.wFormatTag = WAVE_FORMAT_MPEG;
199 formatData.wFormatTag = WAVE_FORMAT_MPEGLAYER3;
200 formatData.wFormatTag = WAVE_FORMAT_ADPCM;
201*/
202 formatData.wFormatTag = WAVE_FORMAT_PCM;
203 formatData.nAvgBytesPerSec = bps * chs * f;
204 formatData.nBlockAlign = bps * chs;
205 formatData.nChannels = chs;
206 formatData.nSamplesPerSec = f;
207 formatData.wBitsPerSample = bps * 8;
208 // Open a waveform device for output
209 if (result = waveOutOpen((LPHWAVEOUT)&d->handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL)) {
210 QString errorMsg = "error opening audio device.\nReason: %i - ";
211 switch (result) {
212 case MMSYSERR_ALLOCATED:errorMsg += "Specified resource is already allocated."; break;
213 case MMSYSERR_BADDEVICEID:errorMsg += "Specified device identifier is out of range."; break;
214 case MMSYSERR_NODRIVER:errorMsg += "No device driver is present."; break;
215 case MMSYSERR_NOMEM:errorMsg += "Unable to allocate or lock memory."; break;
216 case WAVERR_BADFORMAT:errorMsg += "Attempted to open with an unsupported waveform-audio format."; break;
217 case WAVERR_SYNC: errorMsg += "The device is synchronous but waveOutOpen was called without using the WAVE_ALLOWSYNC flag."; break;
218 default: errorMsg += "Undefined error"; break;
219 }
220 qDebug( errorMsg, result );
221 }
222
223 d->bufferSize = sound_fragment_bytes;
224#else
225 203
226 int fragments = 0x10000 * 8 + sound_fragment_shift; 204 int fragments = 0x10000 * 8 + sound_fragment_shift;
227 int format = AFMT_S16_LE;
228 int capabilities = 0; 205 int capabilities = 0;
229 206
230#ifdef KEEP_DEVICE_OPEN 207#ifdef KEEP_DEVICE_OPEN
231 if ( AudioDevicePrivate::dspFd == 0 ) { 208 if ( AudioDevicePrivate::dspFd == 0 ) {
232#endif 209#endif
233 if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { 210 if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) {
234 qDebug( "error opening audio device /dev/dsp, sending data to /dev/null instead" ); 211 perror("open(\"/dev/dsp\") sending to /dev/null instead");
235 d->handle = ::open( "/dev/null", O_WRONLY ); 212 d->handle = ::open( "/dev/null", O_WRONLY );
236 } 213 }
237#ifdef KEEP_DEVICE_OPEN 214#ifdef KEEP_DEVICE_OPEN
238 AudioDevicePrivate::dspFd = d->handle; 215 AudioDevicePrivate::dspFd = d->handle;
239 } else { 216 } else {
240 d->handle = AudioDevicePrivate::dspFd; 217 d->handle = AudioDevicePrivate::dspFd;
241 } 218 }
242#endif 219#endif
243 220
244 ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities ); 221 if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1)
245 ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments ); 222 perror("ioctl(\"SNDCTL_DSP_GETCAPS\")");
246 ioctl( d->handle, SNDCTL_DSP_SETFMT, &format ); 223 if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1)
247 ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency ); 224 perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")");
225 if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1)
226 perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
227 qDebug("freq %d", d->frequency);
228 if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1)
229 perror("ioctl(\"SNDCTL_DSP_SPEED\")");
230 qDebug("channels %d",d->channels);
248 if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { 231 if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) {
249 d->channels = ( d->channels == 1 ) ? 2 : d->channels; 232 d->channels = ( d->channels == 1 ) ? 2 : d->channels;
250 ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ); 233 if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1)
234 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
251 } 235 }
252 236
253 d->bufferSize = sound_fragment_bytes; 237 d->bufferSize = sound_fragment_bytes;
254 d->unwrittenBuffer = new char[d->bufferSize]; 238 d->unwrittenBuffer = new char[d->bufferSize];
255 d->unwritten = 0; 239 d->unwritten = 0;
256 d->can_GETOSPACE = TRUE; // until we find otherwise 240 d->can_GETOSPACE = TRUE; // until we find otherwise
257 241
258 //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels ); 242 //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels );
259 //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency ); 243 //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency );
260 //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" ); 244 //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" );
261 //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); 245 //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" );
262 //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); 246 //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" );
263 //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); 247 //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" );
264#endif
265} 248}
266 249
267 250
268AudioDevice::~AudioDevice() { 251AudioDevice::~AudioDevice() {
269#ifdef Q_OS_WIN32 252#ifdef Q_OS_WIN32
270 waveOutClose( (HWAVEOUT)d->handle ); 253 waveOutClose( (HWAVEOUT)d->handle );
271#else 254#else
272# ifndef KEEP_DEVICE_OPEN 255# ifndef KEEP_DEVICE_OPEN
273 close( d->handle ); // Now it should be safe to shut the handle 256 close( d->handle ); // Now it should be safe to shut the handle
274# endif 257# endif
275 delete d->unwrittenBuffer; 258 delete d->unwrittenBuffer;
276 delete d; 259 delete d;
277#endif 260#endif
278} 261}
279 262
280 263
281void AudioDevice::volumeChanged( bool muted ) 264void AudioDevice::volumeChanged( bool muted )
282{ 265{
283 AudioDevicePrivate::muted = muted; 266 AudioDevicePrivate::muted = muted;
284} 267}
285 268
286 269
287void AudioDevice::write( char *buffer, unsigned int length ) 270void AudioDevice::write( char *buffer, unsigned int length )
288{ 271{
289#ifdef Q_OS_WIN32 272#ifdef Q_OS_WIN32
290 // returns immediately and (to be implemented) emits completedIO() when finished writing 273 // returns immediately and (to be implemented) emits completedIO() when finished writing
291 WAVEHDR *lpWaveHdr = (WAVEHDR *)malloc( sizeof(WAVEHDR) ); 274 WAVEHDR *lpWaveHdr = (WAVEHDR *)malloc( sizeof(WAVEHDR) );
292 // maybe the buffer should be copied so that this fool proof, but its a performance hit 275 // maybe the buffer should be copied so that this fool proof, but its a performance hit
293 lpWaveHdr->lpData = buffer; 276 lpWaveHdr->lpData = buffer;
294 lpWaveHdr->dwBufferLength = length; 277 lpWaveHdr->dwBufferLength = length;
295 lpWaveHdr->dwFlags = 0L; 278 lpWaveHdr->dwFlags = 0L;
296 lpWaveHdr->dwLoops = 0L; 279 lpWaveHdr->dwLoops = 0L;
297 waveOutPrepareHeader( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ); 280 waveOutPrepareHeader( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) );
298 // waveOutWrite returns immediately. the data is sent in the background. 281 // waveOutWrite returns immediately. the data is sent in the background.
299 if ( waveOutWrite( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ) ) 282 if ( waveOutWrite( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ) )
300 qDebug( "failed to write block to audio device" ); 283 qDebug( "failed to write block to audio device" );
301 // emit completedIO(); 284 // emit completedIO();
302#else 285#else
303 int t = ::write( d->handle, buffer, length ); 286 int t = ::write( d->handle, buffer, length );
304 if ( t<0 ) t = 0; 287 if ( t<0 ) t = 0;
305 if ( t != (int)length) { 288 if ( t != (int)length) {
306 qDebug("Ahhh!! memcpys 1"); 289 qDebug("Ahhh!! memcpys 1");
307 memcpy(d->unwrittenBuffer,buffer+t,length-t); 290 memcpy(d->unwrittenBuffer,buffer+t,length-t);
308 d->unwritten = length-t; 291 d->unwritten = length-t;
309 } 292 }
310#endif 293#endif
311} 294}
312 295
313 296
314unsigned int AudioDevice::channels() const 297unsigned int AudioDevice::channels() const
315{ 298{
316 return d->channels; 299 return d->channels;
317} 300}
318 301
319 302
320unsigned int AudioDevice::frequency() const 303unsigned int AudioDevice::frequency() const
321{ 304{
322 return d->frequency; 305 return d->frequency;
323} 306}
324 307
325 308
326unsigned int AudioDevice::bytesPerSample() const 309unsigned int AudioDevice::bytesPerSample() const
327{ 310{
328 return d->bytesPerSample; 311 return d->bytesPerSample;
329} 312}
330 313
331 314
332unsigned int AudioDevice::bufferSize() const 315unsigned int AudioDevice::bufferSize() const
333{ 316{
334 return d->bufferSize; 317 return d->bufferSize;
335} 318}
336 319
337unsigned int AudioDevice::canWrite() const 320unsigned int AudioDevice::canWrite() const
338{ 321{
339#ifdef Q_OS_WIN32 322#ifdef Q_OS_WIN32
340 return bufferSize(); // Any better? 323 return bufferSize(); // Any better?
341#else 324#else
342 audio_buf_info info; 325 audio_buf_info info;
343 if ( d->can_GETOSPACE && ioctl(d->handle,SNDCTL_DSP_GETOSPACE,&info) ) { 326 if ( d->can_GETOSPACE && ioctl(d->handle,SNDCTL_DSP_GETOSPACE,&info) ) {
344 d->can_GETOSPACE = FALSE; 327 d->can_GETOSPACE = FALSE;
345 fcntl( d->handle, F_SETFL, O_NONBLOCK ); 328 fcntl( d->handle, F_SETFL, O_NONBLOCK );
346 } 329 }
347 if ( d->can_GETOSPACE ) { 330 if ( d->can_GETOSPACE ) {
348 int t = info.fragments * sound_fragment_bytes; 331 int t = info.fragments * sound_fragment_bytes;
349 return QMIN(t,(int)bufferSize()); 332 return QMIN(t,(int)bufferSize());
350 } else { 333 } else {
351 if ( d->unwritten ) { 334 if ( d->unwritten ) {
352 int t = ::write( d->handle, d->unwrittenBuffer, d->unwritten ); 335 int t = ::write( d->handle, d->unwrittenBuffer, d->unwritten );
353 if ( t<0 ) t = 0; 336 if ( t<0 ) t = 0;
354 if ( (unsigned)t!=d->unwritten ) { 337 if ( (unsigned)t!=d->unwritten ) {
355 memcpy(d->unwrittenBuffer,d->unwrittenBuffer+t,d->unwritten-t); 338 memcpy(d->unwrittenBuffer,d->unwrittenBuffer+t,d->unwritten-t);
356 d->unwritten -= t; 339 d->unwritten -= t;
357 } else { 340 } else {
358 d->unwritten = 0; 341 d->unwritten = 0;
359 } 342 }
360 } 343 }
361 if ( d->unwritten ) 344 if ( d->unwritten )
362 return 0; 345 return 0;
363 else 346 else
364 return d->bufferSize; 347 return d->bufferSize;
365 } 348 }
366#endif 349#endif
367} 350}
368 351
369 352
370int AudioDevice::bytesWritten() { 353int AudioDevice::bytesWritten() {
371#ifdef Q_OS_WIN32 354#ifdef Q_OS_WIN32
372 MMTIME pmmt = { TIME_BYTES, 0 }; 355 MMTIME pmmt = { TIME_BYTES, 0 };
373 if ( ( waveOutGetPosition( (HWAVEOUT)d->handle, &pmmt, sizeof(MMTIME) ) != MMSYSERR_NOERROR ) || ( pmmt.wType != TIME_BYTES ) ) { 356 if ( ( waveOutGetPosition( (HWAVEOUT)d->handle, &pmmt, sizeof(MMTIME) ) != MMSYSERR_NOERROR ) || ( pmmt.wType != TIME_BYTES ) ) {
374 qDebug( "failed to get audio device position" ); 357 qDebug( "failed to get audio device position" );
375 return -1; 358 return -1;
376 } 359 }
377 return pmmt.u.cb; 360 return pmmt.u.cb;
378#else 361#else
379 int buffered = 0; 362 int buffered = 0;
380 if ( ioctl( d->handle, SNDCTL_DSP_GETODELAY, &buffered ) ) { 363 if ( ioctl( d->handle, SNDCTL_DSP_GETODELAY, &buffered ) ) {
381 qDebug( "failed to get audio device position" ); 364 qDebug( "failed to get audio device position" );
382 return -1; 365 return -1;
383 } 366 }
384 return buffered; 367 return buffered;
385#endif 368#endif
386} 369}
387 370
diff --git a/core/multimedia/opieplayer/audiodevice.h b/core/multimedia/opieplayer/audiodevice.h
index ec70788..d59c388 100644
--- a/core/multimedia/opieplayer/audiodevice.h
+++ b/core/multimedia/opieplayer/audiodevice.h
@@ -1,70 +1,74 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20// L.J.Potter added changes Fri 02-15-2002
21
20#ifndef AUDIODEVICE_H 22#ifndef AUDIODEVICE_H
21#define AUDIODEVICE_H 23#define AUDIODEVICE_H
22 24
25
23#include <qobject.h> 26#include <qobject.h>
27#include <sys/soundcard.h>
24 28
25 29
26class AudioDevicePrivate; 30class AudioDevicePrivate;
27 31
28 32
29class AudioDevice : public QObject { 33class AudioDevice : public QObject {
30 Q_OBJECT 34 Q_OBJECT
31public: 35public:
32 AudioDevice( unsigned int freq = 44000, unsigned int channels = 2, unsigned int bytesPerSample = 2 ); 36 AudioDevice( unsigned int freq = 44000, unsigned int channels = 2, unsigned int bytesPerSample = AFMT_S16_LE );
33 ~AudioDevice(); 37 ~AudioDevice();
34 38
35 unsigned int canWrite() const; 39 unsigned int canWrite() const;
36 void write( char *buffer, unsigned int length ); 40 void write( char *buffer, unsigned int length );
37 int bytesWritten(); 41 int bytesWritten();
38 42
39 unsigned int channels() const; 43 unsigned int channels() const;
40 unsigned int frequency() const; 44 unsigned int frequency() const;
41 unsigned int bytesPerSample() const; 45 unsigned int bytesPerSample() const;
42 unsigned int bufferSize() const; 46 unsigned int bufferSize() const;
43 47
44 // Each volume level is from 0 to 0xFFFF 48 // Each volume level is from 0 to 0xFFFF
45 static void getVolume( unsigned int& left, unsigned int& right, bool& muted ); 49 static void getVolume( unsigned int& left, unsigned int& right, bool& muted );
46 static void setVolume( unsigned int left, unsigned int right, bool muted ); 50 static void setVolume( unsigned int left, unsigned int right, bool muted );
47 51
48 static unsigned int leftVolume() { bool muted; unsigned int l, r; getVolume( l, r, muted ); return l; } 52 static unsigned int leftVolume() { bool muted; unsigned int l, r; getVolume( l, r, muted ); return l; }
49 static unsigned int rightVolume() { bool muted; unsigned int l, r; getVolume( l, r, muted ); return r; } 53 static unsigned int rightVolume() { bool muted; unsigned int l, r; getVolume( l, r, muted ); return r; }
50 static bool isMuted() { bool muted; unsigned int l, r; getVolume( l, r, muted ); return muted; } 54 static bool isMuted() { bool muted; unsigned int l, r; getVolume( l, r, muted ); return muted; }
51 55
52 static void increaseVolume() { setVolume( leftVolume() + 1968, rightVolume() + 1968, isMuted() ); } 56 static void increaseVolume() { setVolume( leftVolume() + 1968, rightVolume() + 1968, isMuted() ); }
53 static void decreaseVolume() { setVolume( leftVolume() - 1966, rightVolume() - 1966, isMuted() ); } 57 static void decreaseVolume() { setVolume( leftVolume() - 1966, rightVolume() - 1966, isMuted() ); }
54 58
55public slots: 59public slots:
56 // Convinence functions derived from above functions 60 // Convinence functions derived from above functions
57 void setVolume( unsigned int level ) { setVolume( level, level, isMuted() ); } 61 void setVolume( unsigned int level ) { setVolume( level, level, isMuted() ); }
58 void mute() { setVolume( leftVolume(), rightVolume(), TRUE ); } 62 void mute() { setVolume( leftVolume(), rightVolume(), TRUE ); }
59 void volumeChanged( bool muted ); 63 void volumeChanged( bool muted );
60 64
61signals: 65signals:
62 void completedIO(); 66 void completedIO();
63 67
64private: 68private:
65 AudioDevicePrivate *d; 69 AudioDevicePrivate *d;
66}; 70};
67 71
68 72
69#endif // AUDIODEVICE_H 73#endif // AUDIODEVICE_H
70 74
diff --git a/core/multimedia/opieplayer/audiowidget.cpp b/core/multimedia/opieplayer/audiowidget.cpp
index 1e0757f..582660c 100644
--- a/core/multimedia/opieplayer/audiowidget.cpp
+++ b/core/multimedia/opieplayer/audiowidget.cpp
@@ -1,276 +1,276 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include <qwidget.h> 20#include <qwidget.h>
21#include <qpixmap.h> 21#include <qpixmap.h>
22#include <qbutton.h> 22#include <qbutton.h>
23#include <qpainter.h> 23#include <qpainter.h>
24#include <qframe.h> 24#include <qframe.h>
25#include <qpe/resource.h> 25#include <qpe/resource.h>
26#include "audiowidget.h" 26#include "audiowidget.h"
27#include "mediaplayerstate.h" 27#include "mediaplayerstate.h"
28 28
29extern MediaPlayerState *mediaPlayerState; 29extern MediaPlayerState *mediaPlayerState;
30 30
31 31
32static const int xo = -2; // movable x offset 32static const int xo = -2; // movable x offset
33static const int yo = 22; // movable y offset 33static const int yo = 22; // movable y offset
34 34
35 35
36struct MediaButton { 36struct MediaButton {
37 int xPos, yPos; 37 int xPos, yPos;
38 int color; 38 int color;
39 bool isToggle, isBig, isHeld, isDown; 39 bool isToggle, isBig, isHeld, isDown;
40}; 40};
41 41
42 42
43// Layout information for the audioButtons (and if it is a toggle button or not) 43// Layout information for the audioButtons (and if it is a toggle button or not)
44MediaButton audioButtons[] = { 44MediaButton audioButtons[] = {
45 { 3*30-15+xo, 3*30-13+yo, 0, TRUE, TRUE, FALSE, FALSE }, // play 45 { 3*30-15+xo, 3*30-13+yo, 0, TRUE, TRUE, FALSE, FALSE }, // play
46 { 1*30+xo, 5*30+yo, 2, FALSE, FALSE, FALSE, FALSE }, // stop 46 { 1*30+xo, 5*30+yo, 2, FALSE, FALSE, FALSE, FALSE }, // stop
47 { 5*30+xo, 5*30+yo, 2, TRUE, FALSE, FALSE, FALSE }, // pause 47 { 5*30+xo, 5*30+yo, 2, TRUE, FALSE, FALSE, FALSE }, // pause
48 { 6*30-5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // next 48 { 6*30-5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // next
49 { 0*30+5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // previous 49 { 0*30+5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // previous
50 { 3*30+xo, 0*30+5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume up 50 { 3*30+xo, 0*30+5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume up
51 { 3*30+xo, 6*30-5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume down 51 { 3*30+xo, 6*30-5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume down
52 { 5*30+xo, 1*30+yo, 0, TRUE, FALSE, FALSE, FALSE }, // repeat/loop 52 { 5*30+xo, 1*30+yo, 0, TRUE, FALSE, FALSE, FALSE }, // repeat/loop
53 { 1*30+xo, 1*30+yo, 0, FALSE, FALSE, FALSE, FALSE } // playlist 53 { 1*30+xo, 1*30+yo, 0, FALSE, FALSE, FALSE, FALSE } // playlist
54}; 54};
55 55
56 56
57static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); 57static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton));
58 58
59 59
60AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : 60AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) :
61 QWidget( parent, name, f ) 61 QWidget( parent, name, f )
62{ 62{
63 setCaption( tr("MediaPlayer") ); 63 setCaption( tr("OpiePlayer") );
64 setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); 64 setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) );
65 pixmaps[0] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButtonsAll" ) ); 65 pixmaps[0] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButtonsAll" ) );
66 pixmaps[1] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButtonsBig" ) ); 66 pixmaps[1] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButtonsBig" ) );
67 pixmaps[2] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaControls" ) ); 67 pixmaps[2] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaControls" ) );
68 pixmaps[3] = new QPixmap( Resource::loadPixmap( "mpegplayer/animatedButton" ) ); 68 pixmaps[3] = new QPixmap( Resource::loadPixmap( "mpegplayer/animatedButton" ) );
69 69
70 songInfo = new Ticker( this ); 70 songInfo = new Ticker( this );
71 songInfo->setFocusPolicy( QWidget::NoFocus ); 71 songInfo->setFocusPolicy( QWidget::NoFocus );
72 songInfo->setGeometry( QRect( 7, 3, 220, 20 ) ); 72 songInfo->setGeometry( QRect( 7, 3, 220, 20 ) );
73 73
74 slider = new QSlider( Qt::Horizontal, this ); 74 slider = new QSlider( Qt::Horizontal, this );
75 slider->setFixedWidth( 220 ); 75 slider->setFixedWidth( 220 );
76 slider->setFixedHeight( 20 ); 76 slider->setFixedHeight( 20 );
77 slider->setMinValue( 0 ); 77 slider->setMinValue( 0 );
78 slider->setMaxValue( 1 ); 78 slider->setMaxValue( 1 );
79 slider->setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); 79 slider->setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) );
80 slider->setFocusPolicy( QWidget::NoFocus ); 80 slider->setFocusPolicy( QWidget::NoFocus );
81 slider->setGeometry( QRect( 7, 262, 220, 20 ) ); 81 slider->setGeometry( QRect( 7, 262, 220, 20 ) );
82 82
83 connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 83 connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
84 connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 84 connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
85 85
86 connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); 86 connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) );
87 connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 87 connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
88 connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 88 connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
89 connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); 89 connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) );
90 connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); 90 connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) );
91 connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); 91 connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) );
92 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); 92 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) );
93 93
94 // Intialise state 94 // Intialise state
95 setLength( mediaPlayerState->length() ); 95 setLength( mediaPlayerState->length() );
96 setPosition( mediaPlayerState->position() ); 96 setPosition( mediaPlayerState->position() );
97 setLooping( mediaPlayerState->fullscreen() ); 97 setLooping( mediaPlayerState->fullscreen() );
98 setPaused( mediaPlayerState->paused() ); 98 setPaused( mediaPlayerState->paused() );
99 setPlaying( mediaPlayerState->playing() ); 99 setPlaying( mediaPlayerState->playing() );
100 100
101} 101}
102 102
103 103
104AudioWidget::~AudioWidget() { 104AudioWidget::~AudioWidget() {
105 for ( int i = 0; i < 4; i++ ) 105 for ( int i = 0; i < 4; i++ )
106 delete pixmaps[i]; 106 delete pixmaps[i];
107} 107}
108 108
109 109
110static bool audioSliderBeingMoved = FALSE; 110static bool audioSliderBeingMoved = FALSE;
111 111
112 112
113void AudioWidget::sliderPressed() { 113void AudioWidget::sliderPressed() {
114 audioSliderBeingMoved = TRUE; 114 audioSliderBeingMoved = TRUE;
115} 115}
116 116
117 117
118void AudioWidget::sliderReleased() { 118void AudioWidget::sliderReleased() {
119 audioSliderBeingMoved = FALSE; 119 audioSliderBeingMoved = FALSE;
120 if ( slider->width() == 0 ) 120 if ( slider->width() == 0 )
121 return; 121 return;
122 long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); 122 long val = long((double)slider->value() * mediaPlayerState->length() / slider->width());
123 mediaPlayerState->setPosition( val ); 123 mediaPlayerState->setPosition( val );
124} 124}
125 125
126 126
127void AudioWidget::setPosition( long i ) { 127void AudioWidget::setPosition( long i ) {
128 updateSlider( i, mediaPlayerState->length() ); 128 updateSlider( i, mediaPlayerState->length() );
129} 129}
130 130
131 131
132void AudioWidget::setLength( long max ) { 132void AudioWidget::setLength( long max ) {
133 updateSlider( mediaPlayerState->position(), max ); 133 updateSlider( mediaPlayerState->position(), max );
134} 134}
135 135
136 136
137void AudioWidget::setView( char view ) { 137void AudioWidget::setView( char view ) {
138 if ( view == 'a' ) { 138 if ( view == 'a' ) {
139 startTimer( 150 ); 139 startTimer( 150 );
140 showMaximized(); 140 showMaximized();
141 } else { 141 } else {
142 killTimers(); 142 killTimers();
143 hide(); 143 hide();
144 } 144 }
145} 145}
146 146
147 147
148void AudioWidget::updateSlider( long i, long max ) { 148void AudioWidget::updateSlider( long i, long max ) {
149 if ( max == 0 ) 149 if ( max == 0 )
150 return; 150 return;
151 // Will flicker too much if we don't do this 151 // Will flicker too much if we don't do this
152 // Scale to something reasonable 152 // Scale to something reasonable
153 int width = slider->width(); 153 int width = slider->width();
154 int val = int((double)i * width / max); 154 int val = int((double)i * width / max);
155 if ( !audioSliderBeingMoved ) { 155 if ( !audioSliderBeingMoved ) {
156 if ( slider->value() != val ) 156 if ( slider->value() != val )
157 slider->setValue( val ); 157 slider->setValue( val );
158 if ( slider->maxValue() != width ) 158 if ( slider->maxValue() != width )
159 slider->setMaxValue( width ); 159 slider->setMaxValue( width );
160 } 160 }
161} 161}
162 162
163 163
164void AudioWidget::setToggleButton( int i, bool down ) { 164void AudioWidget::setToggleButton( int i, bool down ) {
165 if ( down != audioButtons[i].isDown ) 165 if ( down != audioButtons[i].isDown )
166 toggleButton( i ); 166 toggleButton( i );
167} 167}
168 168
169 169
170void AudioWidget::toggleButton( int i ) { 170void AudioWidget::toggleButton( int i ) {
171 audioButtons[i].isDown = !audioButtons[i].isDown; 171 audioButtons[i].isDown = !audioButtons[i].isDown;
172 QPainter p(this); 172 QPainter p(this);
173 paintButton ( &p, i ); 173 paintButton ( &p, i );
174} 174}
175 175
176 176
177void AudioWidget::paintButton( QPainter *p, int i ) { 177void AudioWidget::paintButton( QPainter *p, int i ) {
178 int x = audioButtons[i].xPos; 178 int x = audioButtons[i].xPos;
179 int y = audioButtons[i].yPos; 179 int y = audioButtons[i].yPos;
180 int offset = 22 + 14 * audioButtons[i].isBig + audioButtons[i].isDown; 180 int offset = 22 + 14 * audioButtons[i].isBig + audioButtons[i].isDown;
181 int buttonSize = 64 + audioButtons[i].isBig * (90 - 64); 181 int buttonSize = 64 + audioButtons[i].isBig * (90 - 64);
182 p->drawPixmap( x, y, *pixmaps[audioButtons[i].isBig], buttonSize * (audioButtons[i].isDown + 2 * audioButtons[i].color), 0, buttonSize, buttonSize ); 182 p->drawPixmap( x, y, *pixmaps[audioButtons[i].isBig], buttonSize * (audioButtons[i].isDown + 2 * audioButtons[i].color), 0, buttonSize, buttonSize );
183 p->drawPixmap( x + offset, y + offset, *pixmaps[2], 18 * i, 0, 18, 18 ); 183 p->drawPixmap( x + offset, y + offset, *pixmaps[2], 18 * i, 0, 18, 18 );
184} 184}
185 185
186 186
187void AudioWidget::timerEvent( QTimerEvent * ) { 187void AudioWidget::timerEvent( QTimerEvent * ) {
188 static int frame = 0; 188 static int frame = 0;
189 if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { 189 if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) {
190 frame = frame >= 7 ? 0 : frame + 1; 190 frame = frame >= 7 ? 0 : frame + 1;
191 int x = audioButtons[AudioPlay].xPos; 191 int x = audioButtons[AudioPlay].xPos;
192 int y = audioButtons[AudioPlay].yPos; 192 int y = audioButtons[AudioPlay].yPos;
193 QPainter p( this ); 193 QPainter p( this );
194 // Optimize to only draw the little bit of the changing images which is different 194 // Optimize to only draw the little bit of the changing images which is different
195 p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 ); 195 p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 );
196 p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 ); 196 p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 );
197 } 197 }
198} 198}
199 199
200 200
201void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { 201void AudioWidget::mouseMoveEvent( QMouseEvent *event ) {
202 for ( int i = 0; i < numButtons; i++ ) { 202 for ( int i = 0; i < numButtons; i++ ) {
203 int size = audioButtons[i].isBig; 203 int size = audioButtons[i].isBig;
204 int x = audioButtons[i].xPos; 204 int x = audioButtons[i].xPos;
205 int y = audioButtons[i].yPos; 205 int y = audioButtons[i].yPos;
206 if ( event->state() == QMouseEvent::LeftButton ) { 206 if ( event->state() == QMouseEvent::LeftButton ) {
207 // The test to see if the mouse click is inside the circular button or not 207 // The test to see if the mouse click is inside the circular button or not
208 // (compared with the radius squared to avoid a square-root of our distance) 208 // (compared with the radius squared to avoid a square-root of our distance)
209 int radius = 32 + 13 * size; 209 int radius = 32 + 13 * size;
210 QPoint center = QPoint( x + radius, y + radius ); 210 QPoint center = QPoint( x + radius, y + radius );
211 QPoint dXY = center - event->pos(); 211 QPoint dXY = center - event->pos();
212 int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); 212 int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y();
213 bool isOnButton = dist <= (radius * radius); 213 bool isOnButton = dist <= (radius * radius);
214 // QRect r( x, y, 64 + 22*size, 64 + 22*size ); 214// QRect r( x, y, 64 + 22*size, 64 + 22*size );
215 // bool isOnButton = r.contains( event->pos() ); // Rectangular Button code 215// bool isOnButton = r.contains( event->pos() ); // Rectangular Button code
216 if ( isOnButton && !audioButtons[i].isHeld ) { 216 if ( isOnButton && !audioButtons[i].isHeld ) {
217 audioButtons[i].isHeld = TRUE; 217 audioButtons[i].isHeld = TRUE;
218 toggleButton(i); 218 toggleButton(i);
219 switch (i) { 219 switch (i) {
220 case AudioVolumeUp: emit moreClicked(); return; 220 case AudioVolumeUp: emit moreClicked(); return;
221 case AudioVolumeDown: emit lessClicked(); return; 221 case AudioVolumeDown: emit lessClicked(); return;
222 } 222 }
223 } else if ( !isOnButton && audioButtons[i].isHeld ) { 223 } else if ( !isOnButton && audioButtons[i].isHeld ) {
224 audioButtons[i].isHeld = FALSE; 224 audioButtons[i].isHeld = FALSE;
225 toggleButton(i); 225 toggleButton(i);
226 } 226 }
227 } else { 227 } else {
228 if ( audioButtons[i].isHeld ) { 228 if ( audioButtons[i].isHeld ) {
229 audioButtons[i].isHeld = FALSE; 229 audioButtons[i].isHeld = FALSE;
230 if ( !audioButtons[i].isToggle ) 230 if ( !audioButtons[i].isToggle )
231 setToggleButton( i, FALSE ); 231 setToggleButton( i, FALSE );
232 switch (i) { 232 switch (i) {
233 case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; 233 case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return;
234 case AudioStop: mediaPlayerState->setPlaying(FALSE); return; 234 case AudioStop: mediaPlayerState->setPlaying(FALSE); return;
235 case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; 235 case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return;
236 case AudioNext: mediaPlayerState->setNext(); return; 236 case AudioNext: mediaPlayerState->setNext(); return;
237 case AudioPrevious: mediaPlayerState->setPrev(); return; 237 case AudioPrevious: mediaPlayerState->setPrev(); return;
238 case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; 238 case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return;
239 case AudioVolumeUp: emit moreReleased(); return; 239 case AudioVolumeUp: emit moreReleased(); return;
240 case AudioVolumeDown: emit lessReleased(); return; 240 case AudioVolumeDown: emit lessReleased(); return;
241 case AudioPlayList: mediaPlayerState->setList(); return; 241 case AudioPlayList: mediaPlayerState->setList(); return;
242 } 242 }
243 } 243 }
244 } 244 }
245 } 245 }
246} 246}
247 247
248 248
249void AudioWidget::mousePressEvent( QMouseEvent *event ) { 249void AudioWidget::mousePressEvent( QMouseEvent *event ) {
250 mouseMoveEvent( event ); 250 mouseMoveEvent( event );
251} 251}
252 252
253 253
254void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { 254void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) {
255 mouseMoveEvent( event ); 255 mouseMoveEvent( event );
256} 256}
257 257
258 258
259void AudioWidget::showEvent( QShowEvent* ) { 259void AudioWidget::showEvent( QShowEvent* ) {
260 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); 260 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 );
261 mouseMoveEvent( &event ); 261 mouseMoveEvent( &event );
262} 262}
263 263
264 264
265void AudioWidget::closeEvent( QCloseEvent* ) { 265void AudioWidget::closeEvent( QCloseEvent* ) {
266 mediaPlayerState->setList(); 266 mediaPlayerState->setList();
267} 267}
268 268
269 269
270void AudioWidget::paintEvent( QPaintEvent * ) { 270void AudioWidget::paintEvent( QPaintEvent * ) {
271 QPainter p( this ); 271 QPainter p( this );
272 for ( int i = 0; i < numButtons; i++ ) 272 for ( int i = 0; i < numButtons; i++ )
273 paintButton( &p, i ); 273 paintButton( &p, i );
274} 274}
275 275
276 276
diff --git a/core/multimedia/opieplayer/audiowidget.h b/core/multimedia/opieplayer/audiowidget.h
index 95f5322..53e84b3 100644
--- a/core/multimedia/opieplayer/audiowidget.h
+++ b/core/multimedia/opieplayer/audiowidget.h
@@ -1,52 +1,52 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef AUDIO_WIDGET_H 20#ifndef AUDIO_WIDGET_H
21#define AUDIO_WIDGET_H 21#define AUDIO_WIDGET_H
22 22
23#include <qwidget.h> 23#include <qwidget.h>
24#include <qpainter.h> 24#include <qpainter.h>
25#include <qdrawutil.h> 25#include <qdrawutil.h>
26#include <qpixmap.h> 26#include <qpixmap.h>
27#include <qstring.h> 27#include <qstring.h>
28#include <qslider.h> 28#include <qslider.h>
29#include <qframe.h> 29#include <qframe.h>
30 30
31 31
32class QPixmap; 32class QPixmap;
33 33
34 34
35enum AudioButtons { 35enum AudioButtons {
36 AudioPlay, 36 AudioPlay,
37 AudioStop, 37 AudioStop,
38 AudioPause, 38 AudioPause,
39 AudioNext, 39 AudioNext,
40 AudioPrevious, 40 AudioPrevious,
41 AudioVolumeUp, 41 AudioVolumeUp,
42 AudioVolumeDown, 42 AudioVolumeDown,
43 AudioLoop, 43 AudioLoop,
44 AudioPlayList 44 AudioPlayList
45}; 45};
46 46
47 47
48#define USE_DBLBUF 48#define USE_DBLBUF
49 49
50 50
51class Ticker : public QFrame { 51class Ticker : public QFrame {
52 Q_OBJECT 52 Q_OBJECT
diff --git a/core/multimedia/opieplayer/libmad/Makefile.in b/core/multimedia/opieplayer/libmad/Makefile.in
index e9f74e7..552043c 100644
--- a/core/multimedia/opieplayer/libmad/Makefile.in
+++ b/core/multimedia/opieplayer/libmad/Makefile.in
@@ -169,55 +169,57 @@ synth.o: synth.c \
169 libmad_global.h \ 169 libmad_global.h \
170 fixed.h \ 170 fixed.h \
171 frame.h \ 171 frame.h \
172 timer.h \ 172 timer.h \
173 stream.h \ 173 stream.h \
174 bit.h \ 174 bit.h \
175 synth.h \ 175 synth.h \
176 D.dat 176 D.dat
177 177
178decoder.o: decoder.c \ 178decoder.o: decoder.c \
179 libmad_global.h \ 179 libmad_global.h \
180 stream.h \ 180 stream.h \
181 bit.h \ 181 bit.h \
182 frame.h \ 182 frame.h \
183 fixed.h \ 183 fixed.h \
184 timer.h \ 184 timer.h \
185 synth.h \ 185 synth.h \
186 decoder.h 186 decoder.h
187 187
188layer12.o: layer12.c \ 188layer12.o: layer12.c \
189 libmad_global.h \ 189 libmad_global.h \
190 fixed.h \ 190 fixed.h \
191 bit.h \ 191 bit.h \
192 stream.h \ 192 stream.h \
193 frame.h \ 193 frame.h \
194 timer.h \ 194 timer.h \
195 layer12.h \ 195 layer12.h \
196 sf_table.dat \ 196 sf_table.dat \
197 qc_table.dat 197 qc_table.dat
198 198
199layer3.o: layer3.c \ 199layer3.o: layer3.c \
200 libmad_global.h \ 200 libmad_global.h \
201 fixed.h \ 201 fixed.h \
202 bit.h \ 202 bit.h \
203 stream.h \ 203 stream.h \
204 frame.h \ 204 frame.h \
205 timer.h \ 205 timer.h \
206 huffman.h \ 206 huffman.h \
207 layer3.h \ 207 layer3.h \
208 rq_table.dat \ 208 rq_table.dat \
209 imdct_s.dat 209 imdct_s.dat
210 210
211huffman.o: huffman.c \ 211huffman.o: huffman.c \
212 libmad_global.h \ 212 libmad_global.h \
213 huffman.h 213 huffman.h
214 214
215libmadplugin.o: libmadplugin.cpp \ 215libmadplugin.o: libmadplugin.cpp \
216 libmadplugin.h \ 216 libmadplugin.h \
217 ../mediaplayerplugininterface.h \
217 mad.h 218 mad.h
218 219
219libmadpluginimpl.o: libmadpluginimpl.cpp \ 220libmadpluginimpl.o: libmadpluginimpl.cpp \
220 libmadplugin.h \ 221 libmadplugin.h \
222 ../mediaplayerplugininterface.h \
221 libmadpluginimpl.h 223 libmadpluginimpl.h
222 224
223 225
diff --git a/core/multimedia/opieplayer/libmad/libmad.pro b/core/multimedia/opieplayer/libmad/libmad.pro
index 6c40a15..06e19e4 100644
--- a/core/multimedia/opieplayer/libmad/libmad.pro
+++ b/core/multimedia/opieplayer/libmad/libmad.pro
@@ -1,12 +1,12 @@
1 TEMPLATE= lib 1TEMPLATE = lib
2 CONFIG += qt warn_on release 2CONFIG += qt warn_on release
3 HEADERS = libmad_version.h fixed.h bit.h timer.h stream.h frame.h synth.h decoder.h \ 3HEADERS = libmad_version.h fixed.h bit.h timer.h stream.h frame.h synth.h decoder.h \
4 layer12.h layer3.h huffman.h libmad_global.h mad.h libmadplugin.h libmadpluginimpl.h 4 layer12.h layer3.h huffman.h libmad_global.h mad.h libmadplugin.h libmadpluginimpl.h
5 SOURCES = version.c fixed.c bit.c timer.c stream.c frame.c synth.c decoder.c \ 5SOURCES = version.c fixed.c bit.c timer.c stream.c frame.c synth.c decoder.c \
6 layer12.c layer3.c huffman.c libmadplugin.cpp libmadpluginimpl.cpp 6 layer12.c layer3.c huffman.c libmadplugin.cpp libmadpluginimpl.cpp
7 TARGET = madplugin 7TARGET = madplugin
8 DESTDIR = ../../plugins/codecs 8DESTDIR = ../../plugins/codecs
9INCLUDEPATH += $(OPIEDIR)/include .. 9INCLUDEPATH += $(OPIEDIR)/include ..
10DEPENDPATH += ../$(OPIEDIR)/include .. 10DEPENDPATH += ../$(OPIEDIR)/include ..
11LIBS += -lqpe -lm 11LIBS += -lqpe -lm
12 VERSION = 1.0.0 12VERSION = 1.0.0
diff --git a/core/multimedia/opieplayer/libmad/libmadplugin.cpp b/core/multimedia/opieplayer/libmad/libmadplugin.cpp
index 9d04f7e..9f8ba65 100644
--- a/core/multimedia/opieplayer/libmad/libmadplugin.cpp
+++ b/core/multimedia/opieplayer/libmad/libmadplugin.cpp
@@ -2,97 +2,97 @@
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include <stdio.h> 20#include <stdio.h>
21#include <stdarg.h> 21#include <stdarg.h>
22#include <stdlib.h> 22#include <stdlib.h>
23#include <sys/types.h> 23#include <sys/types.h>
24#include <sys/stat.h> 24#include <sys/stat.h>
25#include <fcntl.h> 25#include <fcntl.h>
26#include <unistd.h> 26#include <unistd.h>
27#include <string.h> 27#include <string.h>
28#include <ctype.h> 28#include <ctype.h>
29#include <errno.h> 29#include <errno.h>
30#include <time.h> 30#include <time.h>
31#include <locale.h> 31#include <locale.h>
32#include <math.h> 32#include <math.h>
33#include <assert.h> 33#include <assert.h>
34#include <qapplication.h> 34#include <qapplication.h>
35 35
36//#define HAVE_MMAP 36//#define HAVE_MMAP
37 37
38#if defined(HAVE_MMAP) 38#if defined(HAVE_MMAP)
39# include <sys/mman.h> 39# include <sys/mman.h>
40#endif 40#endif
41#include "libmadplugin.h" 41#include "libmadplugin.h"
42 42
43 43
44extern "C" { 44extern "C" {
45#include "mad.h" 45#include "mad.h"
46} 46}
47 47
48 48
49#define MPEG_BUFFER_SIZE 65536 49#define MPEG_BUFFER_SIZE 65536
50 //#define debugMsg(a) qDebug(a) 50//#define debugMsg(a) qDebug(a)
51#define debugMsg(a) 51#define debugMsg(a)
52 52
53 53
54class Input { 54class Input {
55public: 55public:
56 char const *path; 56 char const *path;
57 int fd; 57 int fd;
58#if defined(HAVE_MMAP) 58#if defined(HAVE_MMAP)
59 void *fdm; 59 void *fdm;
60#endif 60#endif
61 unsigned char *data; 61 unsigned char *data;
62 unsigned long length; 62 unsigned long length;
63 int eof; 63 int eof;
64}; 64};
65 65
66 66
67class Output { 67class Output {
68public: 68public:
69 mad_fixed_t attenuate; 69 mad_fixed_t attenuate;
70 struct filter *filters; 70 struct filter *filters;
71 unsigned int channels_in; 71 unsigned int channels_in;
72 unsigned int channels_out; 72 unsigned int channels_out;
73 unsigned int speed_in; 73 unsigned int speed_in;
74 unsigned int speed_out; 74 unsigned int speed_out;
75 const char *path; 75 const char *path;
76}; 76};
77 77
78 78
79# if defined(HAVE_MMAP) 79# if defined(HAVE_MMAP)
80static void *map_file(int fd, unsigned long *length) 80static void *map_file(int fd, unsigned long *length)
81{ 81{
82 void *fdm; 82 void *fdm;
83 83
84 *length += MAD_BUFFER_GUARD; 84 *length += MAD_BUFFER_GUARD;
85 85
86 fdm = mmap(0, *length, PROT_READ, MAP_SHARED, fd, 0); 86 fdm = mmap(0, *length, PROT_READ, MAP_SHARED, fd, 0);
87 if (fdm == MAP_FAILED) 87 if (fdm == MAP_FAILED)
88 return 0; 88 return 0;
89 89
90# if defined(HAVE_MADVISE) 90# if defined(HAVE_MADVISE)
91 madvise(fdm, *length, MADV_SEQUENTIAL); 91 madvise(fdm, *length, MADV_SEQUENTIAL);
92# endif 92# endif
93 93
94 return fdm; 94 return fdm;
95} 95}
96 96
97 97
98static int unmap_file(void *fdm, unsigned long length) 98static int unmap_file(void *fdm, unsigned long length)
@@ -100,479 +100,479 @@ static int unmap_file(void *fdm, unsigned long length)
100 if (munmap(fdm, length) == -1) 100 if (munmap(fdm, length) == -1)
101 return -1; 101 return -1;
102 102
103 return 0; 103 return 0;
104} 104}
105# endif 105# endif
106 106
107 107
108static inline QString tr( const char *str ) { 108static inline QString tr( const char *str ) {
109 // Apparently this is okay from a plugin as it runs in the process space of the owner of the plugin 109 // Apparently this is okay from a plugin as it runs in the process space of the owner of the plugin
110 return qApp->translate( "MediaPlayer", str, "libmad strings for mp3 file info" ); 110 return qApp->translate( "MediaPlayer", str, "libmad strings for mp3 file info" );
111} 111}
112 112
113 113
114class LibMadPluginData { 114class LibMadPluginData {
115public: 115public:
116 Input input; 116 Input input;
117 Output output; 117 Output output;
118 int bad_last_frame; 118 int bad_last_frame;
119 struct mad_stream stream; 119 struct mad_stream stream;
120 struct mad_frame frame; 120 struct mad_frame frame;
121 struct mad_synth synth; 121 struct mad_synth synth;
122 bool flush; 122 bool flush;
123}; 123};
124 124
125 125
126LibMadPlugin::LibMadPlugin() { 126LibMadPlugin::LibMadPlugin() {
127 d = new LibMadPluginData; 127 d = new LibMadPluginData;
128 d->input.fd = 0; 128 d->input.fd = 0;
129#if defined(HAVE_MMAP) 129#if defined(HAVE_MMAP)
130 d->input.fdm = 0; 130 d->input.fdm = 0;
131#endif 131#endif
132 d->input.data = 0; 132 d->input.data = 0;
133 d->flush = TRUE; 133 d->flush = TRUE;
134 info = tr( "No Song Open" ); 134 info = tr( "No Song Open" );
135} 135}
136 136
137 137
138LibMadPlugin::~LibMadPlugin() { 138LibMadPlugin::~LibMadPlugin() {
139 close(); 139 close();
140 delete d; 140 delete d;
141} 141}
142 142
143 143
144bool LibMadPlugin::isFileSupported( const QString& path ) { 144bool LibMadPlugin::isFileSupported( const QString& path ) {
145 debugMsg( "LibMadPlugin::isFileSupported" ); 145 debugMsg( "LibMadPlugin::isFileSupported" );
146 146
147 // Mpeg file extensions 147 // Mpeg file extensions
148 //"mp2","mp3","m1v","m2v","m2s","mpg","vob","mpeg","ac3" 148 // "mp2","mp3","m1v","m2v","m2s","mpg","vob","mpeg","ac3"
149 // Other media extensions 149 // Other media extensions
150 // "wav","mid","mod","s3m","ogg","avi","mov","sid" 150 // "wav","mid","mod","s3m","ogg","avi","mov","sid"
151 151
152 char *ext = strrchr( path.latin1(), '.' ); 152 char *ext = strrchr( path.latin1(), '.' );
153 153
154 // Test file extension 154 // Test file extension
155 if ( ext ) { 155 if ( ext ) {
156 if ( strncasecmp(ext, ".mp2", 4) == 0 ) 156 if ( strncasecmp(ext, ".mp2", 4) == 0 )
157 return TRUE; 157 return TRUE;
158 if ( strncasecmp(ext, ".mp3", 4) == 0 ) 158 if ( strncasecmp(ext, ".mp3", 4) == 0 )
159 return TRUE; 159 return TRUE;
160 } 160 }
161 161
162 return FALSE; 162 return FALSE;
163} 163}
164 164
165 165
166bool LibMadPlugin::open( const QString& path ) { 166bool LibMadPlugin::open( const QString& path ) {
167 debugMsg( "LibMadPlugin::open" ); 167 debugMsg( "LibMadPlugin::open" );
168 168
169 d->bad_last_frame = 0; 169 d->bad_last_frame = 0;
170 d->flush = TRUE; 170 d->flush = TRUE;
171 info = QString( "" ); 171 info = QString( "" );
172 172
173 //qDebug( "Opening %s", path.latin1() ); 173 //qDebug( "Opening %s", path.latin1() );
174 174
175 d->input.path = path.latin1(); 175 d->input.path = path.latin1();
176 d->input.fd = ::open( d->input.path, O_RDONLY ); 176 d->input.fd = ::open( d->input.path, O_RDONLY );
177 if (d->input.fd == -1) { 177 if (d->input.fd == -1) {
178 qDebug("error opening %s", d->input.path ); 178 qDebug("error opening %s", d->input.path );
179 return FALSE; 179 return FALSE;
180 } 180 }
181 181
182 printID3Tags(); 182 printID3Tags();
183 183
184#if defined(HAVE_MMAP) 184#if defined(HAVE_MMAP)
185 struct stat stat; 185 struct stat stat;
186 if (fstat(d->input.fd, &stat) == -1) { 186 if (fstat(d->input.fd, &stat) == -1) {
187 qDebug("error calling fstat"); return FALSE; 187 qDebug("error calling fstat"); return FALSE;
188 } 188 }
189 if (S_ISREG(stat.st_mode) && stat.st_size > 0) { 189 if (S_ISREG(stat.st_mode) && stat.st_size > 0) {
190 d->input.length = stat.st_size; 190 d->input.length = stat.st_size;
191 d->input.fdm = map_file(d->input.fd, &d->input.length); 191 d->input.fdm = map_file(d->input.fd, &d->input.length);
192 if (d->input.fdm == 0) { 192 if (d->input.fdm == 0) {
193 qDebug("error mmapping file"); return FALSE; 193 qDebug("error mmapping file"); return FALSE;
194 } 194 }
195 d->input.data = (unsigned char *)d->input.fdm; 195 d->input.data = (unsigned char *)d->input.fdm;
196 } 196 }
197#endif 197#endif
198 198
199 if (d->input.data == 0) { 199 if (d->input.data == 0) {
200 d->input.data = (unsigned char *)malloc(MPEG_BUFFER_SIZE); 200 d->input.data = (unsigned char *)malloc(MPEG_BUFFER_SIZE);
201 if (d->input.data == 0) { 201 if (d->input.data == 0) {
202 qDebug("error allocating input buffer"); 202 qDebug("error allocating input buffer");
203 return FALSE; 203 return FALSE;
204 } 204 }
205 d->input.length = 0; 205 d->input.length = 0;
206 } 206 }
207 207
208 d->input.eof = 0; 208 d->input.eof = 0;
209 209
210 mad_stream_init(&d->stream); 210 mad_stream_init(&d->stream);
211 mad_frame_init(&d->frame); 211 mad_frame_init(&d->frame);
212 mad_synth_init(&d->synth); 212 mad_synth_init(&d->synth);
213 213
214 return TRUE; 214 return TRUE;
215} 215}
216 216
217 217
218bool LibMadPlugin::close() { 218bool LibMadPlugin::close() {
219 debugMsg( "LibMadPlugin::close" ); 219 debugMsg( "LibMadPlugin::close" );
220 220
221 int result = TRUE; 221 int result = TRUE;
222 222
223 mad_synth_finish(&d->synth); 223 mad_synth_finish(&d->synth);
224 mad_frame_finish(&d->frame); 224 mad_frame_finish(&d->frame);
225 mad_stream_finish(&d->stream); 225 mad_stream_finish(&d->stream);
226 226
227#if defined(HAVE_MMAP) 227#if defined(HAVE_MMAP)
228 if (d->input.fdm) { 228 if (d->input.fdm) {
229 if (unmap_file(d->input.fdm, d->input.length) == -1) { 229 if (unmap_file(d->input.fdm, d->input.length) == -1) {
230 qDebug("error munmapping file"); 230 qDebug("error munmapping file");
231 result = FALSE; 231 result = FALSE;
232 } 232 }
233 d->input.fdm = 0; 233 d->input.fdm = 0;
234 d->input.data = 0; 234 d->input.data = 0;
235 } 235 }
236#endif 236#endif
237 237
238 if (d->input.data) { 238 if (d->input.data) {
239 free(d->input.data); 239 free(d->input.data);
240 d->input.data = 0; 240 d->input.data = 0;
241 } 241 }
242 242
243 if (::close(d->input.fd) == -1) { 243 if (::close(d->input.fd) == -1) {
244 qDebug("error closing file %s", d->input.path); 244 qDebug("error closing file %s", d->input.path);
245 result = FALSE; 245 result = FALSE;
246 } 246 }
247 247
248 d->input.fd = 0; 248 d->input.fd = 0;
249 249
250 return result; 250 return result;
251} 251}
252 252
253 253
254bool LibMadPlugin::isOpen() { 254bool LibMadPlugin::isOpen() {
255 debugMsg( "LibMadPlugin::isOpen" ); 255 debugMsg( "LibMadPlugin::isOpen" );
256 return ( d->input.fd != 0 ); 256 return ( d->input.fd != 0 );
257} 257}
258 258
259 259
260int LibMadPlugin::audioStreams() { 260int LibMadPlugin::audioStreams() {
261 debugMsg( "LibMadPlugin::audioStreams" ); 261 debugMsg( "LibMadPlugin::audioStreams" );
262 return 1; 262 return 1;
263} 263}
264 264
265 265
266int LibMadPlugin::audioChannels( int ) { 266int LibMadPlugin::audioChannels( int ) {
267 debugMsg( "LibMadPlugin::audioChannels" ); 267 debugMsg( "LibMadPlugin::audioChannels" );
268/* 268/*
269 long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); 269 long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 );
270 qDebug( "LibMadPlugin::audioChannels: %i", d->frame.header.mode > 0 ? 2 : 1 ); 270 qDebug( "LibMadPlugin::audioChannels: %i", d->frame.header.mode > 0 ? 2 : 1 );
271 return d->frame.header.mode > 0 ? 2 : 1; 271 return d->frame.header.mode > 0 ? 2 : 1;
272*/ 272*/
273 return 2; 273 return 2;
274} 274}
275 275
276 276
277int LibMadPlugin::audioFrequency( int ) { 277int LibMadPlugin::audioFrequency( int ) {
278 debugMsg( "LibMadPlugin::audioFrequency" ); 278 debugMsg( "LibMadPlugin::audioFrequency" );
279 long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); 279 long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 );
280 qDebug( "LibMadPlugin::audioFrequency: %i", d->frame.header.samplerate ); 280 qDebug( "LibMadPlugin::audioFrequency: %i", d->frame.header.samplerate );
281 return d->frame.header.samplerate; 281 return d->frame.header.samplerate;
282} 282}
283 283
284 284
285int LibMadPlugin::audioSamples( int ) { 285int LibMadPlugin::audioSamples( int ) {
286 debugMsg( "LibMadPlugin::audioSamples" ); 286 debugMsg( "LibMadPlugin::audioSamples" );
287/* 287/*
288 long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); 288 long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 );
289 mad_header_decode( (struct mad_header *)&d->frame.header, &d->stream ); 289 mad_header_decode( (struct mad_header *)&d->frame.header, &d->stream );
290 qDebug( "LibMadPlugin::audioSamples: %i*%i", d->frame.header.duration.seconds, d->frame.header.samplerate ); 290 qDebug( "LibMadPlugin::audioSamples: %i*%i", d->frame.header.duration.seconds, d->frame.header.samplerate );
291 return d->frame.header.duration.seconds * d->frame.header.samplerate; 291 return d->frame.header.duration.seconds * d->frame.header.samplerate;
292*/ 292*/
293 return 10000000; 293 return 10000000;
294} 294}
295 295
296 296
297bool LibMadPlugin::audioSetSample( long, int ) { 297bool LibMadPlugin::audioSetSample( long, int ) {
298 debugMsg( "LibMadPlugin::audioSetSample" ); 298 debugMsg( "LibMadPlugin::audioSetSample" );
299 return FALSE; 299 return FALSE;
300} 300}
301 301
302 302
303long LibMadPlugin::audioGetSample( int ) { 303long LibMadPlugin::audioGetSample( int ) {
304 debugMsg( "LibMadPlugin::audioGetSample" ); 304 debugMsg( "LibMadPlugin::audioGetSample" );
305 return 0; 305 return 0;
306} 306}
307 307
308/* 308/*
309bool LibMadPlugin::audioReadSamples( short *, int, long, int ) { 309bool LibMadPlugin::audioReadSamples( short *, int, long, int ) {
310 debugMsg( "LibMadPlugin::audioReadSamples" ); 310 debugMsg( "LibMadPlugin::audioReadSamples" );
311 return FALSE; 311 return FALSE;
312} 312}
313 313
314 314
315bool LibMadPlugin::audioReReadSamples( short *, int, long, int ) { 315bool LibMadPlugin::audioReReadSamples( short *, int, long, int ) {
316 debugMsg( "LibMadPlugin::audioReReadSamples" ); 316 debugMsg( "LibMadPlugin::audioReReadSamples" );
317 return FALSE; 317 return FALSE;
318} 318}
319*/ 319*/
320 320
321bool LibMadPlugin::read() { 321bool LibMadPlugin::read() {
322 debugMsg( "LibMadPlugin::read" ); 322 debugMsg( "LibMadPlugin::read" );
323 int len; 323 int len;
324 324
325 if (d->input.eof) 325 if (d->input.eof)
326 return FALSE; 326 return FALSE;
327 327
328#if defined(HAVE_MMAP) 328#if defined(HAVE_MMAP)
329 if (d->input.fdm) { 329 if (d->input.fdm) {
330 unsigned long skip = 0; 330 unsigned long skip = 0;
331 331
332 if (d->stream.next_frame) { 332 if (d->stream.next_frame) {
333 struct stat stat; 333 struct stat stat;
334 334
335 if (fstat(d->input.fd, &stat) == -1) 335 if (fstat(d->input.fd, &stat) == -1)
336 return FALSE; 336 return FALSE;
337 337
338 if (stat.st_size + MAD_BUFFER_GUARD <= (signed)d->input.length) 338 if (stat.st_size + MAD_BUFFER_GUARD <= (signed)d->input.length)
339 return FALSE; 339 return FALSE;
340 340
341 // file size changed; update memory map 341 // file size changed; update memory map
342 skip = d->stream.next_frame - d->input.data; 342 skip = d->stream.next_frame - d->input.data;
343 343
344 if (unmap_file(d->input.fdm, d->input.length) == -1) { 344 if (unmap_file(d->input.fdm, d->input.length) == -1) {
345 d->input.fdm = 0; 345 d->input.fdm = 0;
346 d->input.data = 0; 346 d->input.data = 0;
347 return FALSE; 347 return FALSE;
348 } 348 }
349 349
350 d->input.length = stat.st_size; 350 d->input.length = stat.st_size;
351 351
352 d->input.fdm = map_file(d->input.fd, &d->input.length); 352 d->input.fdm = map_file(d->input.fd, &d->input.length);
353 if (d->input.fdm == 0) { 353 if (d->input.fdm == 0) {
354 d->input.data = 0; 354 d->input.data = 0;
355 return FALSE; 355 return FALSE;
356 } 356 }
357 357
358 d->input.data = (unsigned char *)d->input.fdm; 358 d->input.data = (unsigned char *)d->input.fdm;
359 } 359 }
360 360
361 mad_stream_buffer(&d->stream, d->input.data + skip, d->input.length - skip); 361 mad_stream_buffer(&d->stream, d->input.data + skip, d->input.length - skip);
362 362
363 } else 363 } else
364#endif 364#endif
365 { 365 {
366 if (d->stream.next_frame) { 366 if (d->stream.next_frame) {
367 memmove(d->input.data, d->stream.next_frame, 367 memmove(d->input.data, d->stream.next_frame,
368 d->input.length = &d->input.data[d->input.length] - d->stream.next_frame); 368 d->input.length = &d->input.data[d->input.length] - d->stream.next_frame);
369 } 369 }
370 370
371 do { 371 do {
372 len = ::read(d->input.fd, d->input.data + d->input.length, MPEG_BUFFER_SIZE - d->input.length); 372 len = ::read(d->input.fd, d->input.data + d->input.length, MPEG_BUFFER_SIZE - d->input.length);
373 } 373 }
374 while (len == -1 && errno == EINTR); 374 while (len == -1 && errno == EINTR);
375 375
376 if (len == -1) { 376 if (len == -1) {
377 qDebug("error reading audio"); 377 qDebug("error reading audio");
378 return FALSE; 378 return FALSE;
379 } 379 }
380 else if (len == 0) { 380 else if (len == 0) {
381 d->input.eof = 1; 381 d->input.eof = 1;
382 382
383 assert(MPEG_BUFFER_SIZE - d->input.length >= MAD_BUFFER_GUARD); 383 assert(MPEG_BUFFER_SIZE - d->input.length >= MAD_BUFFER_GUARD);
384 384
385 while (len < MAD_BUFFER_GUARD) 385 while (len < MAD_BUFFER_GUARD)
386 d->input.data[d->input.length + len++] = 0; 386 d->input.data[d->input.length + len++] = 0;
387 } 387 }
388 388
389 mad_stream_buffer(&d->stream, d->input.data, d->input.length += len); 389 mad_stream_buffer(&d->stream, d->input.data, d->input.length += len);
390 } 390 }
391 391
392 return TRUE; 392 return TRUE;
393} 393}
394 394
395 395
396static mad_fixed_t left_err, right_err; 396static mad_fixed_t left_err, right_err;
397static const int bits = 16; 397static const int bits = 16;
398static const int shift = MAD_F_FRACBITS + 1 - bits; 398static const int shift = MAD_F_FRACBITS + 1 - bits;
399 399
400 400
401inline long audio_linear_dither( mad_fixed_t sample, mad_fixed_t& error ) 401inline long audio_linear_dither( mad_fixed_t sample, mad_fixed_t& error )
402{ 402{
403 sample += error; 403 sample += error;
404 mad_fixed_t quantized = (sample >= MAD_F_ONE) ? MAD_F_ONE - 1 : ( (sample < -MAD_F_ONE) ? -MAD_F_ONE : sample ); 404 mad_fixed_t quantized = (sample >= MAD_F_ONE) ? MAD_F_ONE - 1 : ( (sample < -MAD_F_ONE) ? -MAD_F_ONE : sample );
405 quantized &= ~((1L << shift) - 1); 405 quantized &= ~((1L << shift) - 1);
406 error = sample - quantized; 406 error = sample - quantized;
407 return quantized >> shift; 407 return quantized >> shift;
408} 408}
409 409
410 410
411inline void audio_pcm( short *data, unsigned int nsamples, mad_fixed_t *left, mad_fixed_t *right ) 411inline void audio_pcm( short *data, unsigned int nsamples, mad_fixed_t *left, mad_fixed_t *right )
412{ 412{
413 if ( right ) { 413 if ( right ) {
414 while (nsamples--) { 414 while (nsamples--) {
415 data[0] = audio_linear_dither( *left++, left_err ); 415 data[0] = audio_linear_dither( *left++, left_err );
416 data[1] = audio_linear_dither( *right++, right_err ); 416 data[1] = audio_linear_dither( *right++, right_err );
417 data += 2; 417 data += 2;
418 } 418 }
419 } else { 419 } else {
420 while (nsamples--) { 420 while (nsamples--) {
421 data[0] = data[1] = audio_linear_dither( *left++, left_err ); 421 data[0] = data[1] = audio_linear_dither( *left++, left_err );
422 data += 2; 422 data += 2;
423 } 423 }
424 } 424 }
425} 425}
426 426
427 427
428bool LibMadPlugin::decode( short *output, long samples, long& samplesMade ) { 428bool LibMadPlugin::decode( short *output, long samples, long& samplesMade ) {
429 debugMsg( "LibMadPlugin::decode" ); 429 debugMsg( "LibMadPlugin::decode" );
430 430
431 static int buffered = 0; 431 static int buffered = 0;
432 static mad_fixed_t buffer[2][65536 * 2]; 432 static mad_fixed_t buffer[2][65536 * 2];
433 int offset = buffered; 433 int offset = buffered;
434 samplesMade = 0; 434 samplesMade = 0;
435 435
436 static int maxBuffered = 8000; // 65536; 436 static int maxBuffered = 8000; // 65536;
437 437
438 if ( samples > maxBuffered ) 438 if ( samples > maxBuffered )
439 samples = maxBuffered; 439 samples = maxBuffered;
440 440
441 if ( d->flush ) { 441 if ( d->flush ) {
442 buffered = 0; 442 buffered = 0;
443 offset = 0; 443 offset = 0;
444 d->flush = FALSE; 444 d->flush = FALSE;
445 } 445 }
446 446
447 while ( buffered < maxBuffered ) { 447 while ( buffered < maxBuffered ) {
448 448
449 while (mad_frame_decode(&d->frame, &d->stream) == -1) { 449 while (mad_frame_decode(&d->frame, &d->stream) == -1) {
450 if (!MAD_RECOVERABLE(d->stream.error)) { 450 if (!MAD_RECOVERABLE(d->stream.error)) {
451 debugMsg( "feed me" ); 451 debugMsg( "feed me" );
452 return FALSE; // Feed me 452 return FALSE; // Feed me
453 } 453 }
454 if ( d->stream.error == MAD_ERROR_BADCRC ) { 454 if ( d->stream.error == MAD_ERROR_BADCRC ) {
455 mad_frame_mute(&d->frame); 455 mad_frame_mute(&d->frame);
456 qDebug( "error decoding, bad crc" ); 456 qDebug( "error decoding, bad crc" );
457 } 457 }
458 } 458 }
459 459
460 mad_synth_frame(&d->synth, &d->frame); 460 mad_synth_frame(&d->synth, &d->frame);
461 int decodedSamples = d->synth.pcm.length; 461 int decodedSamples = d->synth.pcm.length;
462 memcpy( &(buffer[0][offset]), d->synth.pcm.samples[0], decodedSamples * sizeof(mad_fixed_t) ); 462 memcpy( &(buffer[0][offset]), d->synth.pcm.samples[0], decodedSamples * sizeof(mad_fixed_t) );
463 if ( d->synth.pcm.channels == 2 ) 463 if ( d->synth.pcm.channels == 2 )
464 memcpy( &(buffer[1][offset]), d->synth.pcm.samples[1], decodedSamples * sizeof(mad_fixed_t) ); 464 memcpy( &(buffer[1][offset]), d->synth.pcm.samples[1], decodedSamples * sizeof(mad_fixed_t) );
465 offset += decodedSamples; 465 offset += decodedSamples;
466 buffered += decodedSamples; 466 buffered += decodedSamples;
467 } 467 }
468 468//qApp->processEvents();
469 audio_pcm( output, samples, buffer[0], (d->synth.pcm.channels == 2) ? buffer[1] : 0 ); 469 audio_pcm( output, samples, buffer[0], (d->synth.pcm.channels == 2) ? buffer[1] : 0 );
470// audio_pcm( output, samples, buffer[1], buffer[0] ); 470// audio_pcm( output, samples, buffer[1], buffer[0] );
471// audio_pcm( output, samples, buffer[0], buffer[1] ); 471// audio_pcm( output, samples, buffer[0], buffer[1] );
472 samplesMade = samples; 472 samplesMade = samples;
473 memmove( buffer[0], &(buffer[0][samples]), (buffered - samples) * sizeof(mad_fixed_t) ); 473 memmove( buffer[0], &(buffer[0][samples]), (buffered - samples) * sizeof(mad_fixed_t) );
474 if ( d->synth.pcm.channels == 2 ) 474 if ( d->synth.pcm.channels == 2 )
475 memmove( buffer[1], &(buffer[1][samples]), (buffered - samples) * sizeof(mad_fixed_t) ); 475 memmove( buffer[1], &(buffer[1][samples]), (buffered - samples) * sizeof(mad_fixed_t) );
476 buffered -= samples; 476 buffered -= samples;
477 477
478 return TRUE; 478 return TRUE;
479} 479}
480 480
481/* 481/*
482bool LibMadPlugin::audioReadMonoSamples( short *, long, long&, int ) { 482bool LibMadPlugin::audioReadMonoSamples( short *, long, long&, int ) {
483 debugMsg( "LibMadPlugin::audioReadMonoSamples" ); 483 debugMsg( "LibMadPlugin::audioReadMonoSamples" );
484 return FALSE; 484 return FALSE;
485} 485}
486 486
487 487
488bool LibMadPlugin::audioReadStereoSamples( short *output, long samples, long& samplesMade, int ) { 488bool LibMadPlugin::audioReadStereoSamples( short *output, long samples, long& samplesMade, int ) {
489*/ 489*/
490bool LibMadPlugin::audioReadSamples( short *output, int /*channels*/, long samples, long& samplesMade, int ) { 490bool LibMadPlugin::audioReadSamples( short *output, int /*channels*/, long samples, long& samplesMade, int ) {
491 debugMsg( "LibMadPlugin::audioReadStereoSamples" ); 491 debugMsg( "LibMadPlugin::audioReadStereoSamples" );
492 492
493 static bool needInput = TRUE; 493 static bool needInput = TRUE;
494 494
495 if ( samples == 0 ) 495 if ( samples == 0 )
496 return FALSE; 496 return FALSE;
497 497
498 do { 498 do {
499 if ( needInput ) 499 if ( needInput )
500 if ( !read() ) { 500 if ( !read() ) {
501 // if ( d->input.eof ) 501// if ( d->input.eof )
502 // needInput = FALSE; 502// needInput = FALSE;
503 // else 503// else
504 return FALSE; 504 return FALSE;
505 } 505 }
506 506
507 needInput = FALSE; 507 needInput = FALSE;
508 508
509 if ( decode( output, samples, samplesMade ) ) 509 if ( decode( output, samples, samplesMade ) )
510 return TRUE; 510 return TRUE;
511 else 511 else
512 needInput = TRUE; 512 needInput = TRUE;
513 } 513 }
514 while ( ( samplesMade < samples ) && ( !d->input.eof ) ); 514 while ( ( samplesMade < samples ) && ( !d->input.eof ) );
515/* 515/*
516 static bool firstTimeThru = TRUE; 516 static bool firstTimeThru = TRUE;
517 517
518 if ( firstTimeThru ) { 518 if ( firstTimeThru ) {
519 firstTimeThru = FALSE; 519 firstTimeThru = FALSE;
520 decode( output, samples, samplesMade ); 520 decode( output, samples, samplesMade );
521 return FALSE; 521 return FALSE;
522 } else 522 } else
523*/ 523*/
524 return FALSE; 524 return FALSE;
525} 525}
526 526
527 527
528double LibMadPlugin::getTime() { 528double LibMadPlugin::getTime() {
529 debugMsg( "LibMadPlugin::getTime" ); 529 debugMsg( "LibMadPlugin::getTime" );
530 return 0.0; 530 return 0.0;
531} 531}
532 532
533 533
534void LibMadPlugin::printID3Tags() { 534void LibMadPlugin::printID3Tags() {
535 debugMsg( "LibMadPlugin::printID3Tags" ); 535 debugMsg( "LibMadPlugin::printID3Tags" );
536 536
537 char id3v1[128 + 1]; 537 char id3v1[128 + 1];
538 538
539 if ( ::lseek( d->input.fd, -128, SEEK_END ) == -1 ) { 539 if ( ::lseek( d->input.fd, -128, SEEK_END ) == -1 ) {
540 qDebug( "error seeking to id3 tags" ); 540 qDebug( "error seeking to id3 tags" );
541 return; 541 return;
542 } 542 }
543 543
544 if ( ::read( d->input.fd, id3v1, 128 ) != 128 ) { 544 if ( ::read( d->input.fd, id3v1, 128 ) != 128 ) {
545 qDebug( "error reading in id3 tags" ); 545 qDebug( "error reading in id3 tags" );
546 return; 546 return;
547 } 547 }
548 548
549 if ( ::strncmp( (const char *)id3v1, "TAG", 3 ) != 0 ) { 549 if ( ::strncmp( (const char *)id3v1, "TAG", 3 ) != 0 ) {
550 debugMsg( "sorry, no id3 tags" ); 550 debugMsg( "sorry, no id3 tags" );
551 } else { 551 } else {
552 int len[5] = { 30, 30, 30, 4, 30 }; 552 int len[5] = { 30, 30, 30, 4, 30 };
553 QString label[5] = { tr( "Title" ), tr( "Artist" ), tr( "Album" ), tr( "Year" ), tr( "Comment" ) }; 553 QString label[5] = { tr( "Title" ), tr( "Artist" ), tr( "Album" ), tr( "Year" ), tr( "Comment" ) };
554 char *ptr = id3v1 + 3, *ptr2 = ptr + len[0]; 554 char *ptr = id3v1 + 3, *ptr2 = ptr + len[0];
555 qDebug( "ID3 tags in file:" ); 555 qDebug( "ID3 tags in file:" );
556 info = ""; 556 info = "";
557 for ( int i = 0; i < 5; ptr += len[i], i++, ptr2 += len[i] ) { 557 for ( int i = 0; i < 5; ptr += len[i], i++, ptr2 += len[i] ) {
558 char push = *ptr2; 558 char push = *ptr2;
559 *ptr2 = '\0'; 559 *ptr2 = '\0';
560 char *ptr3 = ptr2; 560 char *ptr3 = ptr2;
561 while ( ptr3-1 >= ptr && isspace(ptr3[-1]) ) ptr3--; 561 while ( ptr3-1 >= ptr && isspace(ptr3[-1]) ) ptr3--;
562 char push2 = *ptr3; *ptr3 = '\0'; 562 char push2 = *ptr3; *ptr3 = '\0';
563 if ( strcmp( ptr, "" ) ) 563 if ( strcmp( ptr, "" ) )
564 info += ( i != 0 ? ", " : "" ) + label[i] + ": " + ptr; 564 info += ( i != 0 ? ", " : "" ) + label[i] + ": " + ptr;
565 //qDebug( info.latin1() ); 565 //qDebug( info.latin1() );
566 *ptr3 = push2; 566 *ptr3 = push2;
567 *ptr2 = push; 567 *ptr2 = push;
568 } 568 }
569 if (id3v1[126] == 0 && id3v1[127] != 0) 569 if (id3v1[126] == 0 && id3v1[127] != 0)
570 info += tr( ", Track: " ) + id3v1[127]; 570 info += tr( ", Track: " ) + id3v1[127];
571 } 571 }
572 572
573 if ( ::lseek(d->input.fd, 0, SEEK_SET) == -1 ) { 573 if ( ::lseek(d->input.fd, 0, SEEK_SET) == -1 ) {
574 qDebug( "error seeking back to beginning" ); 574 qDebug( "error seeking back to beginning" );
575 return; 575 return;
576 } 576 }
577} 577}
578 578
diff --git a/core/multimedia/opieplayer/libmad/libmadplugin.h b/core/multimedia/opieplayer/libmad/libmadplugin.h
index d85e0d4..d163458 100644
--- a/core/multimedia/opieplayer/libmad/libmadplugin.h
+++ b/core/multimedia/opieplayer/libmad/libmadplugin.h
@@ -1,102 +1,104 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef LIBMAD_PLUGIN_H 20#ifndef LIBMAD_PLUGIN_H
21#define LIBMAD_PLUGIN_H 21#define LIBMAD_PLUGIN_H
22 22
23#include <qstring.h> 23#include <qstring.h>
24#include <qpe/mediaplayerplugininterface.h> 24//#include <qpe/mediaplayerplugininterface.h>
25#include "../mediaplayerplugininterface.h"
25 26
26 27
27// #define OLD_MEDIAPLAYER_API 28// #define OLD_MEDIAPLAYER_API
28 29
29 30
30class LibMadPluginData; 31class LibMadPluginData;
31 32
32 33
33class LibMadPlugin : public MediaPlayerDecoder { 34class LibMadPlugin : public MediaPlayerDecoder {
34 35
35public: 36public:
36 LibMadPlugin(); 37 LibMadPlugin();
37 ~LibMadPlugin(); 38 ~LibMadPlugin();
38 39
39 const char *pluginName() { return "LibMadPlugin"; } 40 const char *pluginName() { return "LibMadPlugin"; }
40 const char *pluginComment() { return "This is the libmad library that has been wrapped as a plugin"; } 41 const char *pluginComment() { return "This is the libmad library that has been wrapped as a plugin"; }
41 double pluginVersion() { return 1.0; } 42 double pluginVersion() { return 1.0; }
42 43
43 bool isFileSupported( const QString& ); 44 bool isFileSupported( const QString& );
44 bool open( const QString& ); 45 bool open( const QString& );
45 bool close(); 46 bool close();
46 bool isOpen(); 47 bool isOpen();
47 const QString &fileInfo() { return info; } 48 const QString &fileInfo() { return info; }
48 49
49 // If decoder doesn't support audio then return 0 here 50 // If decoder doesn't support audio then return 0 here
50 int audioStreams(); 51 int audioStreams();
51 int audioChannels( int stream ); 52 int audioChannels( int stream );
52 int audioFrequency( int stream ); 53 int audioFrequency( int stream );
53 int audioSamples( int stream ); 54 int audioSamples( int stream );
54 bool audioSetSample( long sample, int stream ); 55 bool audioSetSample( long sample, int stream );
56 int audioBitsPerSample(int) {return 0;}
55 long audioGetSample( int stream ); 57 long audioGetSample( int stream );
56#ifdef OLD_MEDIAPLAYER_API 58#ifdef OLD_MEDIAPLAYER_API
57 bool audioReadMonoSamples( short *output, long samples, long& samplesRead, int stream ); 59 bool audioReadMonoSamples( short *output, long samples, long& samplesRead, int stream );
58 bool audioReadStereoSamples( short *output, long samples, long& samplesRead, int stream ); 60 bool audioReadStereoSamples( short *output, long samples, long& samplesRead, int stream );
59 bool audioReadSamples( short *output, int channel, long samples, int stream ); 61 bool audioReadSamples( short *output, int channel, long samples, int stream );
60 bool audioReReadSamples( short *output, int channel, long samples, int stream ); 62 bool audioReReadSamples( short *output, int channel, long samples, int stream );
61#else 63#else
62 bool audioReadSamples( short *output, int channels, long samples, long& samplesRead, int stream ); 64 bool audioReadSamples( short *output, int channels, long samples, long& samplesRead, int stream );
63#endif 65#endif
64 66
65 67
66 bool read(); 68 bool read();
67 bool decode( short *output, long samples, long& samplesRead ); 69 bool decode( short *output, long samples, long& samplesRead );
68 void printID3Tags(); 70 void printID3Tags();
69 71
70 72
71 // If decoder doesn't support video then return 0 here 73 // If decoder doesn't support video then return 0 here
72 int videoStreams() { return 0; } 74 int videoStreams() { return 0; }
73 int videoWidth( int ) { return 0; } 75 int videoWidth( int ) { return 0; }
74 int videoHeight( int ) { return 0; } 76 int videoHeight( int ) { return 0; }
75 double videoFrameRate( int ) { return 0.0; } 77 double videoFrameRate( int ) { return 0.0; }
76 int videoFrames( int ) { return 0; } 78 int videoFrames( int ) { return 0; }
77 bool videoSetFrame( long, int ) { return FALSE; } 79 bool videoSetFrame( long, int ) { return FALSE; }
78 long videoGetFrame( int ) { return 0; } 80 long videoGetFrame( int ) { return 0; }
79 bool videoReadFrame( unsigned char **, int, int, int, int, ColorFormat, int ) { return FALSE; } 81 bool videoReadFrame( unsigned char **, int, int, int, int, ColorFormat, int ) { return FALSE; }
80 bool videoReadScaledFrame( unsigned char **, int, int, int, int, int, int, ColorFormat, int ) { return FALSE; } 82 bool videoReadScaledFrame( unsigned char **, int, int, int, int, int, int, ColorFormat, int ) { return FALSE; }
81 bool videoReadYUVFrame( char *, char *, char *, int, int, int, int, int ) { return FALSE; } 83 bool videoReadYUVFrame( char *, char *, char *, int, int, int, int, int ) { return FALSE; }
82 84
83 // Profiling 85 // Profiling
84 double getTime(); 86 double getTime();
85 87
86 // Ignore if these aren't supported 88 // Ignore if these aren't supported
87 bool setSMP( int ) { return FALSE; } 89 bool setSMP( int ) { return FALSE; }
88 bool setMMX( bool ) { return FALSE; } 90 bool setMMX( bool ) { return FALSE; }
89 91
90 // Capabilities 92 // Capabilities
91 bool supportsAudio() { return TRUE; } 93 bool supportsAudio() { return TRUE; }
92 bool supportsVideo() { return FALSE; } 94 bool supportsVideo() { return FALSE; }
93 bool supportsYUV() { return FALSE; } 95 bool supportsYUV() { return FALSE; }
94 bool supportsMMX() { return TRUE; } 96 bool supportsMMX() { return TRUE; }
95 bool supportsSMP() { return FALSE; } 97 bool supportsSMP() { return FALSE; }
96 bool supportsStereo() { return TRUE; } 98 bool supportsStereo() { return TRUE; }
97 bool supportsScaling() { return FALSE; } 99 bool supportsScaling() { return FALSE; }
98 100
99 long getPlayTime() { return -1; } 101 long getPlayTime() { return -1; }
100 102
101private: 103private:
102 LibMadPluginData *d; 104 LibMadPluginData *d;
diff --git a/core/multimedia/opieplayer/libmad/libmadpluginimpl.h b/core/multimedia/opieplayer/libmad/libmadpluginimpl.h
index 2c5ed3b..bc864ee 100644
--- a/core/multimedia/opieplayer/libmad/libmadpluginimpl.h
+++ b/core/multimedia/opieplayer/libmad/libmadpluginimpl.h
@@ -1,52 +1,52 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef LIBMAD_PLUGIN_IMPL_H 20#ifndef LIBMAD_PLUGIN_IMPL_H
21#define LIBMAD_PLUGIN_IMPL_H 21#define LIBMAD_PLUGIN_IMPL_H
22 22
23#include <qpe/mediaplayerplugininterface.h> 23//#include <qpe/mediaplayerplugininterface.h>
24#include "../mediaplayerplugininterface.h"
24 25
25 26
26class LibMadPlugin; 27class LibMadPlugin;
27 28
28 29
29class LibMadPluginImpl : public MediaPlayerPluginInterface 30class LibMadPluginImpl : public MediaPlayerPluginInterface
30{ 31{
31public: 32public:
32 LibMadPluginImpl(); 33 LibMadPluginImpl();
33 virtual ~LibMadPluginImpl(); 34 virtual ~LibMadPluginImpl();
34 35
35#ifndef QT_NO_COMPONENT 36#ifndef QT_NO_COMPONENT
36 37
37 QRESULT queryInterface( const QUuid&, QUnknownInterface** ); 38 QRESULT queryInterface( const QUuid&, QUnknownInterface** );
38 Q_REFCOUNT 39 Q_REFCOUNT
39 40
40#endif 41#endif
41 42
42 virtual MediaPlayerDecoder *decoder(); 43 virtual MediaPlayerDecoder *decoder();
43 virtual MediaPlayerEncoder *encoder(); 44 virtual MediaPlayerEncoder *encoder();
44
45private: 45private:
46 LibMadPlugin *libmadplugin; 46 LibMadPlugin *libmadplugin;
47 ulong ref; 47 ulong ref;
48}; 48};
49 49
50 50
51#endif 51#endif
52 52
diff --git a/core/multimedia/opieplayer/libmpeg3/Makefile.in b/core/multimedia/opieplayer/libmpeg3/Makefile.in
index 154f85d..d255e4f 100644
--- a/core/multimedia/opieplayer/libmpeg3/Makefile.in
+++ b/core/multimedia/opieplayer/libmpeg3/Makefile.in
@@ -131,112 +131,114 @@ moc: $(SRCMOC)
131 131
132tmake: 132tmake:
133 tmake libmpeg3.pro 133 tmake libmpeg3.pro
134 134
135clean: 135clean:
136 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS) 136 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
137 -rm -f *~ core 137 -rm -f *~ core
138 -rm -f allmoc.cpp 138 -rm -f allmoc.cpp
139 139
140####### Extension Modules 140####### Extension Modules
141 141
142listpromodules: 142listpromodules:
143 @echo 143 @echo
144 144
145listallmodules: 145listallmodules:
146 @echo 146 @echo
147 147
148listaddonpromodules: 148listaddonpromodules:
149 @echo 149 @echo
150 150
151listaddonentmodules: 151listaddonentmodules:
152 @echo 152 @echo
153 153
154 154
155REQUIRES= 155REQUIRES=
156 156
157####### Sub-libraries 157####### Sub-libraries
158 158
159 159
160###### Combined headers 160###### Combined headers
161 161
162 162
163 163
164####### Compile 164####### Compile
165 165
166libmpeg3plugin.o: libmpeg3plugin.cpp \ 166libmpeg3plugin.o: libmpeg3plugin.cpp \
167 libmpeg3plugin.h \ 167 libmpeg3plugin.h \
168 libmpeg3.h \ 168 libmpeg3.h \
169 mpeg3private.h \ 169 mpeg3private.h \
170 mpeg3atrack.h \ 170 mpeg3atrack.h \
171 mpeg3demux.h \ 171 mpeg3demux.h \
172 mpeg3title.h \ 172 mpeg3title.h \
173 mpeg3io.h \ 173 mpeg3io.h \
174 mpeg3css.h \ 174 mpeg3css.h \
175 mpeg3private.inc \ 175 mpeg3private.inc \
176 audio/mpeg3audio.h \ 176 audio/mpeg3audio.h \
177 mpeg3vtrack.h \ 177 mpeg3vtrack.h \
178 video/mpeg3video.h \ 178 video/mpeg3video.h \
179 mpeg3protos.h 179 mpeg3protos.h \
180 ../mediaplayerplugininterface.h
180 181
181libmpeg3pluginimpl.o: libmpeg3pluginimpl.cpp \ 182libmpeg3pluginimpl.o: libmpeg3pluginimpl.cpp \
182 libmpeg3plugin.h \ 183 libmpeg3plugin.h \
183 libmpeg3.h \ 184 libmpeg3.h \
184 mpeg3private.h \ 185 mpeg3private.h \
185 mpeg3atrack.h \ 186 mpeg3atrack.h \
186 mpeg3demux.h \ 187 mpeg3demux.h \
187 mpeg3title.h \ 188 mpeg3title.h \
188 mpeg3io.h \ 189 mpeg3io.h \
189 mpeg3css.h \ 190 mpeg3css.h \
190 mpeg3private.inc \ 191 mpeg3private.inc \
191 audio/mpeg3audio.h \ 192 audio/mpeg3audio.h \
192 mpeg3vtrack.h \ 193 mpeg3vtrack.h \
193 video/mpeg3video.h \ 194 video/mpeg3video.h \
194 mpeg3protos.h \ 195 mpeg3protos.h \
196 ../mediaplayerplugininterface.h \
195 libmpeg3pluginimpl.h 197 libmpeg3pluginimpl.h
196 198
197bitstream.o: bitstream.c \ 199bitstream.o: bitstream.c \
198 mpeg3private.h \ 200 mpeg3private.h \
199 mpeg3atrack.h \ 201 mpeg3atrack.h \
200 mpeg3demux.h \ 202 mpeg3demux.h \
201 mpeg3title.h \ 203 mpeg3title.h \
202 mpeg3io.h \ 204 mpeg3io.h \
203 mpeg3css.h \ 205 mpeg3css.h \
204 mpeg3private.inc \ 206 mpeg3private.inc \
205 audio/mpeg3audio.h \ 207 audio/mpeg3audio.h \
206 mpeg3vtrack.h \ 208 mpeg3vtrack.h \
207 video/mpeg3video.h \ 209 video/mpeg3video.h \
208 mpeg3protos.h 210 mpeg3protos.h
209 211
210libmpeg3.o: libmpeg3.c \ 212libmpeg3.o: libmpeg3.c \
211 libmpeg3.h \ 213 libmpeg3.h \
212 mpeg3private.h \ 214 mpeg3private.h \
213 mpeg3atrack.h \ 215 mpeg3atrack.h \
214 mpeg3demux.h \ 216 mpeg3demux.h \
215 mpeg3title.h \ 217 mpeg3title.h \
216 mpeg3io.h \ 218 mpeg3io.h \
217 mpeg3css.h \ 219 mpeg3css.h \
218 mpeg3private.inc \ 220 mpeg3private.inc \
219 audio/mpeg3audio.h \ 221 audio/mpeg3audio.h \
220 mpeg3vtrack.h \ 222 mpeg3vtrack.h \
221 video/mpeg3video.h \ 223 video/mpeg3video.h \
222 mpeg3protos.h 224 mpeg3protos.h
223 225
224mpeg3atrack.o: mpeg3atrack.c \ 226mpeg3atrack.o: mpeg3atrack.c \
225 libmpeg3.h \ 227 libmpeg3.h \
226 mpeg3private.h \ 228 mpeg3private.h \
227 mpeg3atrack.h \ 229 mpeg3atrack.h \
228 mpeg3demux.h \ 230 mpeg3demux.h \
229 mpeg3title.h \ 231 mpeg3title.h \
230 mpeg3io.h \ 232 mpeg3io.h \
231 mpeg3css.h \ 233 mpeg3css.h \
232 mpeg3private.inc \ 234 mpeg3private.inc \
233 audio/mpeg3audio.h \ 235 audio/mpeg3audio.h \
234 mpeg3vtrack.h \ 236 mpeg3vtrack.h \
235 video/mpeg3video.h \ 237 video/mpeg3video.h \
236 mpeg3protos.h 238 mpeg3protos.h
237 239
238mpeg3css.o: mpeg3css.c \ 240mpeg3css.o: mpeg3css.c \
239 mpeg3css.h \ 241 mpeg3css.h \
240 mpeg3private.h \ 242 mpeg3private.h \
241 mpeg3atrack.h \ 243 mpeg3atrack.h \
242 mpeg3demux.h \ 244 mpeg3demux.h \
@@ -369,97 +371,97 @@ audio/exponents.o: audio/exponents.c \
369 mpeg3private.inc \ 371 mpeg3private.inc \
370 audio/../libmpeg3.h \ 372 audio/../libmpeg3.h \
371 mpeg3private.h \ 373 mpeg3private.h \
372 mpeg3atrack.h \ 374 mpeg3atrack.h \
373 audio/mpeg3audio.h \ 375 audio/mpeg3audio.h \
374 mpeg3vtrack.h \ 376 mpeg3vtrack.h \
375 video/mpeg3video.h \ 377 video/mpeg3video.h \
376 audio/../mpeg3protos.h 378 audio/../mpeg3protos.h
377 379
378audio/header.o: audio/header.c \ 380audio/header.o: audio/header.c \
379 audio/mpeg3audio.h \ 381 audio/mpeg3audio.h \
380 audio/ac3.h \ 382 audio/ac3.h \
381 audio/mpeg3real.h \ 383 audio/mpeg3real.h \
382 audio/../bitstream.h \ 384 audio/../bitstream.h \
383 mpeg3demux.h \ 385 mpeg3demux.h \
384 mpeg3title.h \ 386 mpeg3title.h \
385 mpeg3io.h \ 387 mpeg3io.h \
386 mpeg3css.h \ 388 mpeg3css.h \
387 mpeg3private.inc \ 389 mpeg3private.inc \
388 audio/tables.h \ 390 audio/tables.h \
389 audio/../libmpeg3.h \ 391 audio/../libmpeg3.h \
390 mpeg3private.h \ 392 mpeg3private.h \
391 mpeg3atrack.h \ 393 mpeg3atrack.h \
392 audio/mpeg3audio.h \ 394 audio/mpeg3audio.h \
393 mpeg3vtrack.h \ 395 mpeg3vtrack.h \
394 video/mpeg3video.h \ 396 video/mpeg3video.h \
395 audio/../mpeg3protos.h 397 audio/../mpeg3protos.h
396 398
397audio/layer2.o: audio/layer2.c \ 399audio/layer2.o: audio/layer2.c \
398 audio/mpeg3audio.h \ 400 audio/mpeg3audio.h \
399 audio/ac3.h \ 401 audio/ac3.h \
400 audio/mpeg3real.h \ 402 audio/mpeg3real.h \
401 audio/../bitstream.h \ 403 audio/../bitstream.h \
402 mpeg3demux.h \ 404 mpeg3demux.h \
403 mpeg3title.h \ 405 mpeg3title.h \
404 mpeg3io.h \ 406 mpeg3io.h \
405 mpeg3css.h \ 407 mpeg3css.h \
406 mpeg3private.inc \ 408 mpeg3private.inc \
407 audio/../libmpeg3.h \ 409 audio/../libmpeg3.h \
408 mpeg3private.h \ 410 mpeg3private.h \
409 mpeg3atrack.h \ 411 mpeg3atrack.h \
410 audio/mpeg3audio.h \ 412 audio/mpeg3audio.h \
411 mpeg3vtrack.h \ 413 mpeg3vtrack.h \
412 video/mpeg3video.h \ 414 video/mpeg3video.h \
413 audio/../mpeg3protos.h \ 415 audio/../mpeg3protos.h \
414 audio/tables.h 416 audio/tables.h
415 417
416audio/layer3.o: audio/layer3.c \ 418audio/layer3.o: audio/layer3.c \
417 audio/huffman.h \ 419 huffman.h \
418 audio/mpeg3audio.h \ 420 audio/mpeg3audio.h \
419 audio/ac3.h \ 421 audio/ac3.h \
420 audio/mpeg3real.h \ 422 audio/mpeg3real.h \
421 audio/../bitstream.h \ 423 audio/../bitstream.h \
422 mpeg3demux.h \ 424 mpeg3demux.h \
423 mpeg3title.h \ 425 mpeg3title.h \
424 mpeg3io.h \ 426 mpeg3io.h \
425 mpeg3css.h \ 427 mpeg3css.h \
426 mpeg3private.inc \ 428 mpeg3private.inc \
427 audio/../libmpeg3.h \ 429 audio/../libmpeg3.h \
428 mpeg3private.h \ 430 mpeg3private.h \
429 mpeg3atrack.h \ 431 mpeg3atrack.h \
430 audio/mpeg3audio.h \ 432 audio/mpeg3audio.h \
431 mpeg3vtrack.h \ 433 mpeg3vtrack.h \
432 video/mpeg3video.h \ 434 video/mpeg3video.h \
433 audio/../mpeg3protos.h \ 435 audio/../mpeg3protos.h \
434 audio/tables.h 436 audio/tables.h
435 437
436audio/mantissa.o: audio/mantissa.c \ 438audio/mantissa.o: audio/mantissa.c \
437 audio/mpeg3audio.h \ 439 audio/mpeg3audio.h \
438 audio/ac3.h \ 440 audio/ac3.h \
439 audio/mpeg3real.h \ 441 audio/mpeg3real.h \
440 audio/../bitstream.h \ 442 audio/../bitstream.h \
441 mpeg3demux.h \ 443 mpeg3demux.h \
442 mpeg3title.h \ 444 mpeg3title.h \
443 mpeg3io.h \ 445 mpeg3io.h \
444 mpeg3css.h \ 446 mpeg3css.h \
445 mpeg3private.inc \ 447 mpeg3private.inc \
446 audio/../libmpeg3.h \ 448 audio/../libmpeg3.h \
447 mpeg3private.h \ 449 mpeg3private.h \
448 mpeg3atrack.h \ 450 mpeg3atrack.h \
449 audio/mpeg3audio.h \ 451 audio/mpeg3audio.h \
450 mpeg3vtrack.h \ 452 mpeg3vtrack.h \
451 video/mpeg3video.h \ 453 video/mpeg3video.h \
452 audio/../mpeg3protos.h 454 audio/../mpeg3protos.h
453 455
454audio/mpeg3audio.o: audio/mpeg3audio.c \ 456audio/mpeg3audio.o: audio/mpeg3audio.c \
455 audio/../libmpeg3.h \ 457 audio/../libmpeg3.h \
456 mpeg3private.h \ 458 mpeg3private.h \
457 mpeg3atrack.h \ 459 mpeg3atrack.h \
458 mpeg3demux.h \ 460 mpeg3demux.h \
459 mpeg3title.h \ 461 mpeg3title.h \
460 mpeg3io.h \ 462 mpeg3io.h \
461 mpeg3css.h \ 463 mpeg3css.h \
462 mpeg3private.inc \ 464 mpeg3private.inc \
463 audio/mpeg3audio.h \ 465 audio/mpeg3audio.h \
464 audio/ac3.h \ 466 audio/ac3.h \
465 audio/mpeg3real.h \ 467 audio/mpeg3real.h \
diff --git a/core/multimedia/opieplayer/libmpeg3/libmpeg3.pro b/core/multimedia/opieplayer/libmpeg3/libmpeg3.pro
index b1426d1..e50aa4e 100644
--- a/core/multimedia/opieplayer/libmpeg3/libmpeg3.pro
+++ b/core/multimedia/opieplayer/libmpeg3/libmpeg3.pro
@@ -1,42 +1,43 @@
1 TEMPLATE= lib 1TEMPLATE = lib
2 CONFIG += qt warn_on release 2CONFIG += qt warn_on release
3 HEADERS = libmpeg3plugin.h libmpeg3pluginimpl.h 3HEADERS = libmpeg3plugin.h libmpeg3pluginimpl.h
4 SOURCES = libmpeg3plugin.cpp libmpeg3pluginimpl.cpp \ 4SOURCES = libmpeg3plugin.cpp libmpeg3pluginimpl.cpp \
5 bitstream.c \ 5 bitstream.c \
6 libmpeg3.c \ 6 libmpeg3.c \
7 mpeg3atrack.c \ 7 mpeg3atrack.c \
8 mpeg3css.c \ 8 mpeg3css.c \
9 mpeg3demux.c \ 9 mpeg3demux.c \
10 mpeg3io.c \ 10 mpeg3io.c \
11 mpeg3title.c \ 11 mpeg3title.c \
12 mpeg3vtrack.c \ 12 mpeg3vtrack.c \
13 audio/ac3.c \ 13 audio/ac3.c \
14 audio/bit_allocation.c \ 14 audio/bit_allocation.c \
15 audio/dct.c \ 15 audio/dct.c \
16 audio/exponents.c \ 16 audio/exponents.c \
17 audio/header.c \ 17 audio/header.c \
18 audio/layer2.c \ 18 audio/layer2.c \
19 audio/layer3.c \ 19 audio/layer3.c \
20 audio/mantissa.c \ 20 audio/mantissa.c \
21 audio/mpeg3audio.c \ 21 audio/mpeg3audio.c \
22 audio/pcm.c \ 22 audio/pcm.c \
23 audio/synthesizers.c \ 23 audio/synthesizers.c \
24 audio/tables.c \ 24 audio/tables.c \
25 video/getpicture.c \ 25 video/getpicture.c \
26 video/headers.c \ 26 video/headers.c \
27 video/idct.c \ 27 video/idct.c \
28 video/macroblocks.c \ 28 video/macroblocks.c \
29 video/mmxtest.c \ 29 video/mmxtest.c \
30 video/motion.c \ 30 video/motion.c \
31 video/mpeg3video.c \ 31 video/mpeg3video.c \
32 video/output.c \ 32 video/output.c \
33 video/reconstruct.c \ 33 video/reconstruct.c \
34 video/seek.c \ 34 video/seek.c \
35 video/slice.c \ 35 video/slice.c \
36 video/vlc.c 36 video/vlc.c
37 TARGET = mpeg3plugin 37TARGET = mpeg3plugin
38 DESTDIR = ../../plugins/codecs 38TMAKE_CC=g++
39DESTDIR = ../../plugins/codecs
39INCLUDEPATH += $(OPIEDIR)/include .. 40INCLUDEPATH += $(OPIEDIR)/include ..
40DEPENDPATH += ../$(OPIEDIR)/include .. 41DEPENDPATH += ../$(OPIEDIR)/include ..
41LIBS += -lqpe -lpthread -lm 42LIBS += -lqpe -lpthread -lm
42 VERSION = 1.0.0 43VERSION = 1.0.0
diff --git a/core/multimedia/opieplayer/libmpeg3/libmpeg3plugin.h b/core/multimedia/opieplayer/libmpeg3/libmpeg3plugin.h
index e0eb930..bd31706 100644
--- a/core/multimedia/opieplayer/libmpeg3/libmpeg3plugin.h
+++ b/core/multimedia/opieplayer/libmpeg3/libmpeg3plugin.h
@@ -1,100 +1,102 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef LIBMPEG3_PLUGIN_H 20#ifndef LIBMPEG3_PLUGIN_H
21#define LIBMPEG3_PLUGIN_H 21#define LIBMPEG3_PLUGIN_H
22 22
23#include <qstring.h> 23#include <qstring.h>
24#include <qapplication.h> 24#include <qapplication.h>
25#include "libmpeg3.h" 25#include "libmpeg3.h"
26#include "mpeg3protos.h" 26#include "mpeg3protos.h"
27#include <qpe/mediaplayerplugininterface.h> 27//#include <qpe/mediaplayerplugininterface.h>
28#include "../mediaplayerplugininterface.h"
28 29
29 30
30// #define OLD_MEDIAPLAYER_API 31// #define OLD_MEDIAPLAYER_API
31 32
32 33
33class LibMpeg3Plugin : public MediaPlayerDecoder { 34class LibMpeg3Plugin : public MediaPlayerDecoder {
34 35
35public: 36public:
36 LibMpeg3Plugin() { file = NULL; } 37 LibMpeg3Plugin() { file = NULL; }
37 ~LibMpeg3Plugin() { close(); } 38 ~LibMpeg3Plugin() { close(); }
38 39
39 const char *pluginName() { return "LibMpeg3Plugin"; } 40 const char *pluginName() { return "LibMpeg3Plugin"; }
40 const char *pluginComment() { return "This is the libmpeg3 library writen by ... which has been modified by trolltech to use fixed point maths"; } 41 const char *pluginComment() { return "This is the libmpeg3 library writen by ... which has been modified by trolltech to use fixed point maths"; }
41 double pluginVersion() { return 1.0; } 42 double pluginVersion() { return 1.0; }
42 43
43 bool isFileSupported( const QString& fileName ) { return mpeg3_check_sig( (char *)fileName.latin1() ) == 1; } 44 bool isFileSupported( const QString& fileName ) { return mpeg3_check_sig( (char *)fileName.latin1() ) == 1; }
44 bool open( const QString& fileName ) { file = mpeg3_open( (char *)fileName.latin1() ); return file != NULL; } 45 bool open( const QString& fileName ) { file = mpeg3_open( (char *)fileName.latin1() ); return file != NULL; }
45 bool close() { if ( file ) { int r = mpeg3_close( file ); file = NULL; return r == 1; } return FALSE; } 46 bool close() { if ( file ) { int r = mpeg3_close( file ); file = NULL; return r == 1; } return FALSE; }
46 bool isOpen() { return file != NULL; } 47 bool isOpen() { return file != NULL; }
47 const QString &fileInfo() { return strInfo = ""; } 48 const QString &fileInfo() { return strInfo = ""; }
48 49
49 // If decoder doesn't support audio then return 0 here 50 // If decoder doesn't support audio then return 0 here
50 int audioStreams() { return file ? mpeg3_total_astreams( file ) : 0; } 51 int audioStreams() { return file ? mpeg3_total_astreams( file ) : 0; }
51 int audioChannels( int stream ) { return file ? mpeg3_audio_channels( file, stream ) : 0; } 52 int audioChannels( int stream ) { return file ? mpeg3_audio_channels( file, stream ) : 0; }
52 int audioFrequency( int stream ) { return file ? mpeg3_sample_rate( file, stream ) : 0; } 53 int audioFrequency( int stream ) { return file ? mpeg3_sample_rate( file, stream ) : 0; }
54 int audioBitsPerSample(int) { return 0;}
53 int audioSamples( int stream ) { return file ? mpeg3_audio_samples( file, stream ) : 0; } 55 int audioSamples( int stream ) { return file ? mpeg3_audio_samples( file, stream ) : 0; }
54 bool audioSetSample( long sample, int stream ) { return file ? mpeg3_set_sample( file, sample, stream) == 1 : FALSE; } 56 bool audioSetSample( long sample, int stream ) { return file ? mpeg3_set_sample( file, sample, stream) == 1 : FALSE; }
55 long audioGetSample( int stream ) { return file ? mpeg3_get_sample( file, stream ) : 0; } 57 long audioGetSample( int stream ) { return file ? mpeg3_get_sample( file, stream ) : 0; }
56#ifdef OLD_MEDIAPLAYER_API 58#ifdef OLD_MEDIAPLAYER_API
57 bool audioReadMonoSamples( short *output, long samples, long& samplesRead, int stream ); 59 bool audioReadMonoSamples( short *output, long samples, long& samplesRead, int stream );
58 bool audioReadStereoSamples( short *output, long samples, long& samplesRead, int stream ); 60 bool audioReadStereoSamples( short *output, long samples, long& samplesRead, int stream );
59 bool audioReadSamples( short *output, int channel, long samples, int stream ); 61 bool audioReadSamples( short *output, int channel, long samples, int stream );
60 bool audioReReadSamples( short *output, int channel, long samples, int stream ); 62 bool audioReReadSamples( short *output, int channel, long samples, int stream );
61#else 63#else
62 bool audioReadSamples( short *output, int channels, long samples, long& samplesRead, int stream ); 64 bool audioReadSamples( short *output, int channels, long samples, long& samplesRead, int stream );
63#endif 65#endif
64 66
65 // If decoder doesn't support video then return 0 here 67 // If decoder doesn't support video then return 0 here
66 int videoStreams() { return file ? mpeg3_total_vstreams( file ) : 0; } 68 int videoStreams() { return file ? mpeg3_total_vstreams( file ) : 0; }
67 int videoWidth( int stream ) { return file ? mpeg3_video_width( file, stream ) : 0; } 69 int videoWidth( int stream ) { return file ? mpeg3_video_width( file, stream ) : 0; }
68 int videoHeight( int stream ) { return file ? mpeg3_video_height( file, stream ) : 0; } 70 int videoHeight( int stream ) { return file ? mpeg3_video_height( file, stream ) : 0; }
69 double videoFrameRate( int stream ) { return file ? mpeg3_frame_rate( file, stream ) : 0.0; } 71 double videoFrameRate( int stream ) { return file ? mpeg3_frame_rate( file, stream ) : 0.0; }
70 int videoFrames( int stream ) 72 int videoFrames( int stream )
71{ return file ? mpeg3_video_frames( file, stream ) : 0; } 73{ return file ? mpeg3_video_frames( file, stream ) : 0; }
72/* 74/*
73{ 75{
74 if ( file ) { 76 if ( file ) {
75 int frames = mpeg3_video_frames( file, stream ); 77 int frames = mpeg3_video_frames( file, stream );
76 if ( frames == 1 ) { 78 if ( frames == 1 ) {
77 int res = mpeg3_seek_percentage( file, 0.99 ); 79 int res = mpeg3_seek_percentage( file, 0.99 );
78 printf("res: %i\n", res ); 80 printf("res: %i\n", res );
79 mpeg3video_seek( file->vtrack[stream]->video ); 81 mpeg3video_seek( file->vtrack[stream]->video );
80 frames = mpeg3_get_frame( file, stream ); 82 frames = mpeg3_get_frame( file, stream );
81 mpeg3_seek_percentage( file, 0.0 ); 83 mpeg3_seek_percentage( file, 0.0 );
82 } 84 }
83 return frames; 85 return frames;
84 } 86 }
85 return 0; 87 return 0;
86} 88}
87*/ 89*/
88 bool videoSetFrame( long frame, int stream ) { return file ? mpeg3_set_frame( file, frame, stream) == 1 : FALSE; } 90 bool videoSetFrame( long frame, int stream ) { return file ? mpeg3_set_frame( file, frame, stream) == 1 : FALSE; }
89 long videoGetFrame( int stream ) { return file ? mpeg3_get_frame( file, stream ) : 0; } 91 long videoGetFrame( int stream ) { return file ? mpeg3_get_frame( file, stream ) : 0; }
90 bool videoReadFrame( unsigned char **output_rows, int in_x, int in_y, int in_w, int in_h, ColorFormat color_model, int stream ); 92 bool videoReadFrame( unsigned char **output_rows, int in_x, int in_y, int in_w, int in_h, ColorFormat color_model, int stream );
91 bool videoReadScaledFrame( unsigned char **output_rows, int in_x, int in_y, int in_w, int in_h, int out_w, int out_h, ColorFormat color_model, int stream ); 93 bool videoReadScaledFrame( unsigned char **output_rows, int in_x, int in_y, int in_w, int in_h, int out_w, int out_h, ColorFormat color_model, int stream );
92 bool videoReadYUVFrame( char *y_output, char *u_output, char *v_output, int in_x, int in_y, int in_w, int in_h, int stream ); 94 bool videoReadYUVFrame( char *y_output, char *u_output, char *v_output, int in_x, int in_y, int in_w, int in_h, int stream );
93 95
94 // Profiling 96 // Profiling
95 double getTime() { return file ? mpeg3_get_time( file ) : 0.0; } 97 double getTime() { return file ? mpeg3_get_time( file ) : 0.0; }
96 98
97 // Ignore if these aren't supported 99 // Ignore if these aren't supported
98 bool setSMP( int cpus ) { return file ? mpeg3_set_cpus( file, cpus ) == 1 : FALSE; } 100 bool setSMP( int cpus ) { return file ? mpeg3_set_cpus( file, cpus ) == 1 : FALSE; }
99 bool setMMX( bool useMMX ) { return file ? mpeg3_set_mmx( file, useMMX ) == 1 : FALSE; } 101 bool setMMX( bool useMMX ) { return file ? mpeg3_set_mmx( file, useMMX ) == 1 : FALSE; }
100 102
diff --git a/core/multimedia/opieplayer/libmpeg3/libmpeg3pluginimpl.h b/core/multimedia/opieplayer/libmpeg3/libmpeg3pluginimpl.h
index e9926f4..a2f5211 100644
--- a/core/multimedia/opieplayer/libmpeg3/libmpeg3pluginimpl.h
+++ b/core/multimedia/opieplayer/libmpeg3/libmpeg3pluginimpl.h
@@ -1,52 +1,53 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef LIBMPEG3_PLUGIN_IMPL_H 20#ifndef LIBMPEG3_PLUGIN_IMPL_H
21#define LIBMPEG3_PLUGIN_IMPL_H 21#define LIBMPEG3_PLUGIN_IMPL_H
22 22
23#include <qpe/mediaplayerplugininterface.h> 23//#include <qpe/mediaplayerplugininterface.h>
24#include "../mediaplayerplugininterface.h"
24 25
25 26
26class LibMpeg3Plugin; 27class LibMpeg3Plugin;
27 28
28 29
29class LibMpeg3PluginImpl : public MediaPlayerPluginInterface 30class LibMpeg3PluginImpl : public MediaPlayerPluginInterface
30{ 31{
31public: 32public:
32 LibMpeg3PluginImpl(); 33 LibMpeg3PluginImpl();
33 virtual ~LibMpeg3PluginImpl(); 34 virtual ~LibMpeg3PluginImpl();
34 35
35#ifndef QT_NO_COMPONENT 36#ifndef QT_NO_COMPONENT
36 37
37 QRESULT queryInterface( const QUuid&, QUnknownInterface** ); 38 QRESULT queryInterface( const QUuid&, QUnknownInterface** );
38 Q_REFCOUNT 39 Q_REFCOUNT
39 40
40#endif 41#endif
41 42
42 virtual MediaPlayerDecoder *decoder(); 43 virtual MediaPlayerDecoder *decoder();
43 virtual MediaPlayerEncoder *encoder(); 44 virtual MediaPlayerEncoder *encoder();
44 45
45private: 46private:
46 LibMpeg3Plugin *libmpeg3plugin; 47 LibMpeg3Plugin *libmpeg3plugin;
47 ulong ref; 48 ulong ref;
48}; 49};
49 50
50 51
51#endif 52#endif
52 53
diff --git a/core/multimedia/opieplayer/loopcontrol.cpp b/core/multimedia/opieplayer/loopcontrol.cpp
index dd466ed..90a7cc6 100644
--- a/core/multimedia/opieplayer/loopcontrol.cpp
+++ b/core/multimedia/opieplayer/loopcontrol.cpp
@@ -1,470 +1,469 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20// L.J.Potter added changes Fri 02-15-2002
21
22
20#include <qpe/qpeapplication.h> 23#include <qpe/qpeapplication.h>
21#ifdef Q_WS_QWS
22 24
25#ifdef Q_WS_QWS
23#include <qpe/qcopenvelope_qws.h> 26#include <qpe/qcopenvelope_qws.h>
24#endif 27#endif
25#include <qpe/mediaplayerplugininterface.h>
26#include <stdio.h> 28#include <stdio.h>
27#include <stdlib.h> 29#include <stdlib.h>
28#include <string.h> 30#include <string.h>
29#include <pthread.h> 31#include <pthread.h>
30#include <errno.h> 32#include <errno.h>
31#include <unistd.h> 33#include <unistd.h>
32#include "loopcontrol.h" 34#include "loopcontrol.h"
33#include "videowidget.h" 35#include "videowidget.h"
34#include "audiodevice.h" 36#include "audiodevice.h"
37#include "mediaplayerplugininterface.h"
35#include "mediaplayerstate.h" 38#include "mediaplayerstate.h"
36 39
37 40
38extern VideoWidget *videoUI; // now only needed to tell it to play a frame 41extern VideoWidget *videoUI; // now only needed to tell it to play a frame
39extern MediaPlayerState *mediaPlayerState; 42extern MediaPlayerState *mediaPlayerState;
40 43
41 44
42//#define DecodeLoopDebug(x) qDebug x 45//#define DecodeLoopDebug(x) qDebug x
43#define DecodeLoopDebug(x) 46#define DecodeLoopDebug(x)
44 47
45 48
46 static char *audioBuffer = NULL; 49static char *audioBuffer = NULL;
47static AudioDevice *audioDevice = NULL; 50static AudioDevice *audioDevice = NULL;
48 static bool disabledSuspendScreenSaver = FALSE; 51static bool disabledSuspendScreenSaver = FALSE;
49 static bool previousSuspendMode = FALSE; 52static bool previousSuspendMode = FALSE;
50 53
51 54
52 pthread_taudio_tid; 55pthread_t audio_tid;
53pthread_attr_t audio_attr; 56pthread_attr_t audio_attr;
54bool threadOkToGo = FALSE; 57bool threadOkToGo = FALSE;
55 58
56 59
57class Mutex { 60class Mutex {
58public: 61public:
59 Mutex() { 62 Mutex() {
60 pthread_mutexattr_t attr; 63 pthread_mutexattr_t attr;
61 pthread_mutexattr_init( &attr ); 64 pthread_mutexattr_init( &attr );
62 pthread_mutex_init( &mutex, &attr ); 65 pthread_mutex_init( &mutex, &attr );
63 pthread_mutexattr_destroy( &attr ); 66 pthread_mutexattr_destroy( &attr );
64 } 67 }
65 68
66 ~Mutex() { 69 ~Mutex() {
67 pthread_mutex_destroy( &mutex ); 70 pthread_mutex_destroy( &mutex );
68 } 71 }
69 72
70 void lock() { 73 void lock() {
71 pthread_mutex_lock( &mutex ); 74 pthread_mutex_lock( &mutex );
72 } 75 }
73 76
74 void unlock() { 77 void unlock() {
75 pthread_mutex_unlock( &mutex ); 78 pthread_mutex_unlock( &mutex );
76 } 79 }
77private: 80private:
78 pthread_mutex_t mutex; 81 pthread_mutex_t mutex;
79}; 82};
80 83
81 84
82void *startAudioThread( void *ptr ) { 85void *startAudioThread( void *ptr ) {
83 LoopControl *mpegView = (LoopControl *)ptr; 86 LoopControl *mpegView = (LoopControl *)ptr;
84 while ( TRUE ) { 87 while ( TRUE ) {
85 if ( threadOkToGo && mpegView->moreAudio ) 88 if ( threadOkToGo && mpegView->moreAudio )
86 mpegView->startAudio(); 89 mpegView->startAudio();
87 else 90 else
88 usleep( 10000 ); // Semi-buzy-wait till we are playing again 91 usleep( 10000 ); // Semi-buzy-wait till we are playing again
89 } 92 }
90 return 0; 93 return 0;
91} 94}
92 95
93 96
94Mutex *audioMutex; 97Mutex *audioMutex;
95 98
96 99
97LoopControl::LoopControl( QObject *parent, const char *name ) 100LoopControl::LoopControl( QObject *parent, const char *name )
98 : QObject( parent, name ) { 101 : QObject( parent, name ) {
99 isMuted = FALSE; 102 isMuted = FALSE;
100 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) ); 103 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) );
101 104
102 audioMutex = new Mutex; 105 audioMutex = new Mutex;
103 106
104 pthread_attr_init(&audio_attr); 107 pthread_attr_init(&audio_attr);
105 108#define USE_REALTIME_AUDIO_THREAD
106 if ( getuid() == 0 ) { 109#ifdef USE_REALTIME_AUDIO_THREAD
107 printf("true, guid = %i\n", getuid()); 110 // Attempt to set it to real-time round robin
108 111 if ( pthread_attr_setschedpolicy( &audio_attr, SCHED_RR ) == 0 ) {
109 // Attempt to set it to real-time round robin 112 sched_param params;
110 if ( pthread_attr_setschedpolicy( &audio_attr, SCHED_RR ) == 0 ) { 113 params.sched_priority = 50;
111 sched_param params; 114 pthread_attr_setschedparam(&audio_attr,&params);
112 params.sched_priority = 50; 115 } else {
113 pthread_attr_setschedparam(&audio_attr,&params); 116 qDebug( "Error setting up a realtime thread, reverting to using a normal thread." );
114 } else { 117 pthread_attr_destroy(&audio_attr);
115 qDebug( "Error setting up a realtime thread, reverting to using a normal thread." ); 118 pthread_attr_init(&audio_attr);
116 pthread_attr_destroy(&audio_attr);
117 pthread_attr_init(&audio_attr);
118 }
119 } 119 }
120// printf("false, guid = %i\n", getuid()); 120#endif
121 usleep( 100 );
122
123 pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this); 121 pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this);
124} 122}
125 123
126 124
127LoopControl::~LoopControl() { 125LoopControl::~LoopControl() {
128 stop(); 126 stop();
129} 127}
130 128
131 129
132static long prev_frame = 0; 130static long prev_frame = 0;
133static int currentSample = 0; 131static int currentSample = 0;
134 132
135 133
136void LoopControl::timerEvent( QTimerEvent *te ) { 134void LoopControl::timerEvent( QTimerEvent *te ) {
137 135
138 if ( te->timerId() == videoId ) 136 if ( te->timerId() == videoId )
139 startVideo(); 137 startVideo();
140 138
141 if ( te->timerId() == sliderId ) { 139 if ( te->timerId() == sliderId ) {
142 if ( hasAudioChannel && !hasVideoChannel && moreAudio ) { 140 if ( hasAudioChannel && !hasVideoChannel && moreAudio ) {
143 mediaPlayerState->updatePosition( audioSampleCounter ); 141 mediaPlayerState->updatePosition( audioSampleCounter );
144 } else if ( hasVideoChannel && moreVideo ) { 142 } else if ( hasVideoChannel && moreVideo ) {
145 mediaPlayerState->updatePosition( current_frame ); 143 mediaPlayerState->updatePosition( current_frame );
146 } 144 }
147 } 145 }
148 146
149 if ( !moreVideo && !moreAudio ) { 147 if ( !moreVideo && !moreAudio ) {
150 mediaPlayerState->setPlaying( FALSE ); 148 mediaPlayerState->setPlaying( FALSE );
151 mediaPlayerState->setNext(); 149 mediaPlayerState->setNext();
152 } 150 }
153} 151}
154 152
155 153
156void LoopControl::setPosition( long pos ) { 154void LoopControl::setPosition( long pos ) {
157 audioMutex->lock(); 155 audioMutex->lock();
158 156
159 if ( hasVideoChannel && hasAudioChannel ) { 157 if ( hasVideoChannel && hasAudioChannel ) {
160 playtime.restart(); 158 playtime.restart();
161 playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); 159 playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) );
162 current_frame = pos + 1; 160 current_frame = pos + 1;
163 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); 161 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream );
164 prev_frame = current_frame - 1; 162 prev_frame = current_frame - 1;
165 currentSample = (int)( (double)current_frame * freq / framerate ); 163 currentSample = (int)( (double)current_frame * freq / framerate );
166 mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); 164 mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream );
167 audioSampleCounter = currentSample - 1; 165 audioSampleCounter = currentSample - 1;
168 } else if ( hasVideoChannel ) { 166 } else if ( hasVideoChannel ) {
169 playtime.restart(); 167 playtime.restart();
170 playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); 168 playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) );
171 current_frame = pos + 1; 169 current_frame = pos + 1;
172 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); 170 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream );
173 prev_frame = current_frame - 1; 171 prev_frame = current_frame - 1;
174 } else if ( hasAudioChannel ) { 172 } else if ( hasAudioChannel ) {
175 playtime.restart(); 173 playtime.restart();
176 playtime = playtime.addMSecs( long((double)-pos * 1000.0 / freq) ); 174 playtime = playtime.addMSecs( long((double)-pos * 1000.0 / freq) );
177 currentSample = pos + 1; 175 currentSample = pos + 1;
178 mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); 176 mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream );
179 audioSampleCounter = currentSample - 1; 177 audioSampleCounter = currentSample - 1;
180 } 178 }
181 179
182 audioMutex->unlock(); 180 audioMutex->unlock();
183} 181}
184 182
185 183
186void LoopControl::startVideo() { 184void LoopControl::startVideo() {
187 185
188 if ( moreVideo ) { 186 if ( moreVideo ) {
189 187
190 if ( mediaPlayerState->curDecoder() ) { 188 if ( mediaPlayerState->curDecoder() ) {
191 189
192 if ( hasAudioChannel && !isMuted ) { 190 if ( hasAudioChannel && !isMuted ) {
193 191
194 current_frame = long( playtime.elapsed() * framerate / 1000 ); 192 current_frame = long( playtime.elapsed() * framerate / 1000 );
195 193
196 if ( prev_frame != -1 && current_frame <= prev_frame ) 194 if ( prev_frame != -1 && current_frame <= prev_frame )
197 return; 195 return;
198 196
199 } else { 197 } else {
200 // Don't skip 198 // Don't skip
201 current_frame++; 199 current_frame++;
202 } 200 }
203 201
204 if ( prev_frame == -1 || current_frame > prev_frame ) { 202 if ( prev_frame == -1 || current_frame > prev_frame ) {
205 if ( current_frame > prev_frame + 1 ) { 203 if ( current_frame > prev_frame + 1 ) {
206 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); 204 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream );
207 } 205 }
208 moreVideo = videoUI->playVideo(); 206 moreVideo = videoUI->playVideo();
209 prev_frame = current_frame; 207 prev_frame = current_frame;
210 } 208 }
211 209
212 } else { 210 } else {
213 211
214 moreVideo = FALSE; 212 moreVideo = FALSE;
215 killTimer( videoId ); 213 killTimer( videoId );
216 214
217 } 215 }
218 216
219 } 217 }
220} 218}
221 219
222 220
223void LoopControl::startAudio() { 221void LoopControl::startAudio() {
224 222
225 audioMutex->lock(); 223 audioMutex->lock();
226 224
227 if ( moreAudio ) { 225 if ( moreAudio ) {
228 226
229 if ( !isMuted && mediaPlayerState->curDecoder() ) { 227 if ( !isMuted && mediaPlayerState->curDecoder() ) {
230 228
231 currentSample = audioSampleCounter + 1; 229 currentSample = audioSampleCounter + 1;
232 230
233 if ( currentSample != audioSampleCounter + 1 ) 231 if ( currentSample != audioSampleCounter + 1 )
234 qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); 232 qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter);
235 233
236 long samplesRead = 0; 234 long samplesRead = 0;
237 mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); 235 bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream );
238 long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; 236 long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000;
239 long sampleWaitTime = currentSample - sampleWeShouldBeAt; 237 long sampleWaitTime = currentSample - sampleWeShouldBeAt;
240 238
241 if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) { 239 if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) {
242 usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) ); 240 usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) );
243 } else if ( sampleWaitTime <= -5000 ) { 241 }
244 qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); 242 else if ( sampleWaitTime <= -5000 ) {
245 //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); 243 qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt );
246 currentSample = sampleWeShouldBeAt; 244 //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream );
247 } 245 currentSample = sampleWeShouldBeAt;
246 }
248 247
249 audioDevice->write( audioBuffer, samplesRead * 2 * channels ); 248 audioDevice->write( audioBuffer, samplesRead * 2 * channels );
250 audioSampleCounter = currentSample + samplesRead - 1; 249 audioSampleCounter = currentSample + samplesRead - 1;
251 250
252 moreAudio = audioSampleCounter <= total_audio_samples; 251 moreAudio = readOk && (audioSampleCounter <= total_audio_samples);
253 252
254 } else { 253 } else {
255 254
256 moreAudio = FALSE; 255 moreAudio = FALSE;
257 256
258 } 257 }
259 258
260 } 259 }
261 260
262 audioMutex->unlock(); 261 audioMutex->unlock();
263} 262}
264 263
265 264
266void LoopControl::killTimers() { 265void LoopControl::killTimers() {
267 266
268 audioMutex->lock(); 267 audioMutex->lock();
269 268
270 if ( hasVideoChannel ) 269 if ( hasVideoChannel )
271 killTimer( videoId ); 270 killTimer( videoId );
272 killTimer( sliderId ); 271 killTimer( sliderId );
273 threadOkToGo = FALSE; 272 threadOkToGo = FALSE;
274 273
275 audioMutex->unlock(); 274 audioMutex->unlock();
276} 275}
277 276
278 277
279void LoopControl::startTimers() { 278void LoopControl::startTimers() {
280 279
281 audioMutex->lock(); 280 audioMutex->lock();
282 281
283 moreVideo = FALSE; 282 moreVideo = FALSE;
284 moreAudio = FALSE; 283 moreAudio = FALSE;
285 284
286 if ( hasVideoChannel ) { 285 if ( hasVideoChannel ) {
287 moreVideo = TRUE; 286 moreVideo = TRUE;
288 int mSecsBetweenFrames = (int)(100 / framerate); // 10% of the real value 287 int mSecsBetweenFrames = (int)(100 / framerate); // 10% of the real value
289 videoId = startTimer( mSecsBetweenFrames ); 288 videoId = startTimer( mSecsBetweenFrames );
290 } 289 }
291 290
292 if ( hasAudioChannel ) { 291 if ( hasAudioChannel ) {
293 moreAudio = TRUE; 292 moreAudio = TRUE;
294 threadOkToGo = TRUE; 293 threadOkToGo = TRUE;
295 } 294 }
296 295
297 sliderId = startTimer( 300 ); // update slider every 1/3 second 296 sliderId = startTimer( 300 ); // update slider every 1/3 second
298 297
299 audioMutex->unlock(); 298 audioMutex->unlock();
300} 299}
301 300
302 301
303void LoopControl::setPaused( bool pause ) { 302void LoopControl::setPaused( bool pause ) {
304 303
305 if ( !mediaPlayerState->curDecoder() || !mediaPlayerState->curDecoder()->isOpen() ) 304 if ( !mediaPlayerState->curDecoder() || !mediaPlayerState->curDecoder()->isOpen() )
306 return; 305 return;
307 306
308 if ( pause ) { 307 if ( pause ) {
309 killTimers(); 308 killTimers();
310 } else { 309 } else {
311 // Force an update of the position 310 // Force an update of the position
312 mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); 311 mediaPlayerState->setPosition( mediaPlayerState->position() + 1 );
313 mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); 312 mediaPlayerState->setPosition( mediaPlayerState->position() - 1 );
314 // Just like we never stopped 313 // Just like we never stopped
315 startTimers(); 314 startTimers();
316 } 315 }
317} 316}
318 317
319 318
320void LoopControl::stop( bool willPlayAgainShortly ) { 319void LoopControl::stop( bool willPlayAgainShortly ) {
321 320
322#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 321#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
323 if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) { 322 if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) {
324 disabledSuspendScreenSaver = FALSE; 323 disabledSuspendScreenSaver = FALSE;
325 // Re-enable the suspend mode 324 // Re-enable the suspend mode
326 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 325 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
327 } 326 }
328#endif 327#endif
329 328
330 if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) { 329 if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) {
331 330
332 killTimers(); 331 killTimers();
333 332
334 audioMutex->lock(); 333 audioMutex->lock();
335 334
336 mediaPlayerState->curDecoder()->close(); 335 mediaPlayerState->curDecoder()->close();
337 336
338 if ( audioDevice ) { 337 if ( audioDevice ) {
339 delete audioDevice; 338 delete audioDevice;
340 delete audioBuffer; 339 delete audioBuffer;
341 audioDevice = 0; 340 audioDevice = 0;
342 audioBuffer = 0; 341 audioBuffer = 0;
343 } 342 }
344 343
345 audioMutex->unlock(); 344 audioMutex->unlock();
346 345
347 } 346 }
348} 347}
349 348
350 349
351bool LoopControl::init( const QString& filename ) { 350bool LoopControl::init( const QString& filename ) {
352 stop(); 351 stop();
353 352
354 audioMutex->lock(); 353 audioMutex->lock();
355 354
356 fileName = filename; 355 fileName = filename;
357 stream = 0; // only play stream 0 for now 356 stream = 0; // only play stream 0 for now
358 current_frame = total_video_frames = total_audio_samples = 0; 357 current_frame = total_video_frames = total_audio_samples = 0;
359 358
360 qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); 359 qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() );
361 360
362 // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin 361 // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin
363 if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { 362 if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) {
364 if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) { 363 if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) {
365 total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); 364 total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 );
366 mediaPlayerState->libMpeg3Decoder()->close(); 365 mediaPlayerState->libMpeg3Decoder()->close();
367 } 366 }
368 } 367 }
369 368
370 if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) { 369 if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) {
371 audioMutex->unlock(); 370 audioMutex->unlock();
372 return FALSE; 371 return FALSE;
373 } 372 }
374 373
375 hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0; 374 hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0;
376 hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0; 375 hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0;
377 376
378 if ( hasAudioChannel ) { 377 if ( hasAudioChannel ) {
379 int astream = 0; 378 int astream = 0;
380 379
381 channels = mediaPlayerState->curDecoder()->audioChannels( astream ); 380 channels = mediaPlayerState->curDecoder()->audioChannels( astream );
382 DecodeLoopDebug(( "channels = %d\n", channels )); 381 qDebug( "LC- channels = %d", channels );
383 382
384 if ( !total_audio_samples ) 383 if ( !total_audio_samples )
385 total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); 384 total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream );
386 385
387 total_audio_samples += 1000; 386// total_audio_samples += 1000;
388 387
389 mediaPlayerState->setLength( total_audio_samples ); 388 mediaPlayerState->setLength( total_audio_samples );
390 389
391 freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); 390 freq = mediaPlayerState->curDecoder()->audioFrequency( astream );
392 DecodeLoopDebug(( "frequency = %d\n", freq )); 391 qDebug( "LC- frequency = %d", freq );
393 392
394 audioSampleCounter = 0; 393 audioSampleCounter = 0;
395 394
396 static const int bytes_per_sample = 2; //16 bit 395 int bits_per_sample = mediaPlayerState->curDecoder()->audioBitsPerSample( astream);
397 396
398 audioDevice = new AudioDevice( freq, channels, bytes_per_sample ); 397 audioDevice = new AudioDevice( freq, channels, bits_per_sample);
399 audioBuffer = new char[ audioDevice->bufferSize() ]; 398 audioBuffer = new char[ audioDevice->bufferSize() ];
400 channels = audioDevice->channels(); 399 channels = audioDevice->channels();
401 400
402 //### must check which frequency is actually used. 401 //### must check which frequency is actually used.
403 static const int size = 1; 402 static const int size = 1;
404 short int buf[size]; 403 short int buf[size];
405 long samplesRead = 0; 404 long samplesRead = 0;
406 mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream ); 405 mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream );
407 } 406 }
408 407
409 if ( hasVideoChannel ) { 408 if ( hasVideoChannel ) {
410 total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream ); 409 total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream );
411 410
412 mediaPlayerState->setLength( total_video_frames ); 411 mediaPlayerState->setLength( total_video_frames );
413 412
414 framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream ); 413 framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream );
415 DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames )); 414 DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames ));
416 415
417 if ( framerate <= 1.0 ) { 416 if ( framerate <= 1.0 ) {
418 DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" )); 417 DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" ));
419 framerate = 25; 418 framerate = 25;
420 } 419 }
421 420
422 if ( total_video_frames == 1 ) { 421 if ( total_video_frames == 1 ) {
423 DecodeLoopDebug(( "Cannot seek to frame" )); 422 DecodeLoopDebug(( "Cannot seek to frame" ));
424 } 423 }
425 424
426 } 425 }
427 426
428 current_frame = 0; 427 current_frame = 0;
429 prev_frame = -1; 428 prev_frame = -1;
430 429
431 connect( mediaPlayerState, SIGNAL( positionChanged( long ) ), this, SLOT( setPosition( long ) ) ); 430 connect( mediaPlayerState, SIGNAL( positionChanged( long ) ), this, SLOT( setPosition( long ) ) );
432 connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( setPaused( bool ) ) ); 431 connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( setPaused( bool ) ) );
433 432
434 audioMutex->unlock(); 433 audioMutex->unlock();
435 434
436 return TRUE; 435 return TRUE;
437} 436}
438 437
439 438
440void LoopControl::play() { 439void LoopControl::play() {
441 440
442#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 441#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
443 if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) { 442 if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) {
444 disabledSuspendScreenSaver = TRUE; 443 disabledSuspendScreenSaver = TRUE;
445 previousSuspendMode = hasVideoChannel; 444 previousSuspendMode = hasVideoChannel;
446 // Stop the screen from blanking and power saving state 445 // Stop the screen from blanking and power saving state
447 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) 446 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" )
448 << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend ); 447 << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend );
449 } 448 }
450#endif 449#endif
451 450
452 playtime.start(); 451 playtime.start();
453 startTimers(); 452 startTimers();
454} 453}
455 454
456 455
457void LoopControl::setMute( bool on ) { 456void LoopControl::setMute( bool on ) {
458 if ( on != isMuted ) { 457 if ( on != isMuted ) {
459 isMuted = on; 458 isMuted = on;
460 if ( !on ) { 459 if ( !on ) {
461 // Force an update of the position 460 // Force an update of the position
462 mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); 461 mediaPlayerState->setPosition( mediaPlayerState->position() + 1 );
463 mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); 462 mediaPlayerState->setPosition( mediaPlayerState->position() - 1 );
464 // Resume playing audio 463 // Resume playing audio
465 moreAudio = TRUE; 464 moreAudio = TRUE;
466 } 465 }
467 } 466 }
468} 467}
469 468
470 469
diff --git a/core/multimedia/opieplayer/loopcontrol.h b/core/multimedia/opieplayer/loopcontrol.h
index 3191259..f4a7fcd 100644
--- a/core/multimedia/opieplayer/loopcontrol.h
+++ b/core/multimedia/opieplayer/loopcontrol.h
@@ -1,70 +1,74 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20// L.J.Potter added changes Fri 02-15-2002
21
22
20#ifndef MPEGVIEW_H 23#ifndef MPEGVIEW_H
21#define MPEGVIEW_H 24#define MPEGVIEW_H
22 25
26
23#include <qwidget.h> 27#include <qwidget.h>
24#include <qdatetime.h> 28#include <qdatetime.h>
25 29
26 30
27class LoopControl : public QObject { 31class LoopControl : public QObject {
28 Q_OBJECT 32 Q_OBJECT
29public: 33public:
30 LoopControl( QObject *parent, const char *name ); 34 LoopControl( QObject *parent, const char *name );
31 ~LoopControl(); 35 ~LoopControl();
32 36
33 bool init( const QString& filename ); 37 bool init( const QString& filename );
34 38
35 bool hasVideo() const { return hasVideoChannel; } 39 bool hasVideo() const { return hasVideoChannel; }
36 bool hasAudio() const { return hasAudioChannel; } 40 bool hasAudio() const { return hasAudioChannel; }
37 41
38 long totalPlaytime() { return (long)(hasVideoChannel ? total_video_frames / framerate : total_audio_samples / freq); } 42 long totalPlaytime() { return (long)(hasVideoChannel ? total_video_frames / framerate : total_audio_samples / freq); }
39 43
40 // These are public to run them from global functions needed to start threads 44 // These are public to run them from global functions needed to start threads
41 // Otherwise they would be private 45 // Otherwise they would be private
42 void startAudio(); 46 void startAudio();
43 void startVideo(); 47 void startVideo();
44 bool moreAudio; 48 bool moreAudio;
45 bool moreVideo; 49 bool moreVideo;
46public slots: 50public slots:
47 void play(); 51 void play();
48 void stop( bool willPlayAgainShortly = FALSE ); 52 void stop( bool willPlayAgainShortly = FALSE );
49 53
50 void setMute( bool ); 54 void setMute( bool );
51 void setPaused( bool ); 55 void setPaused( bool );
52 void setPosition( long ); 56 void setPosition( long );
53 57
54signals: 58signals:
55 void positionChanged( long, long ); 59 void positionChanged( long, long );
56 60
57protected: 61protected:
58 void timerEvent(QTimerEvent*); 62 void timerEvent(QTimerEvent*);
59 63
60private: 64private:
61 void startTimers(); 65 void startTimers();
62 void killTimers(); 66 void killTimers();
63 67
64 QTime playtime; 68 QTime playtime;
65 int videoId; 69 int videoId;
66 int sliderId; 70 int sliderId;
67 71
68 int audioSampleCounter; 72 int audioSampleCounter;
69 long current_frame; 73 long current_frame;
70 long total_video_frames; 74 long total_video_frames;
diff --git a/core/multimedia/opieplayer/loopcontrol_threaded.cpp b/core/multimedia/opieplayer/loopcontrol_threaded.cpp
index eb89b85..c7dc7a8 100644
--- a/core/multimedia/opieplayer/loopcontrol_threaded.cpp
+++ b/core/multimedia/opieplayer/loopcontrol_threaded.cpp
@@ -1,78 +1,76 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20
21#define _REENTRANT 20#define _REENTRANT
22 21
23
24#include <qpe/qpeapplication.h> 22#include <qpe/qpeapplication.h>
25#include <qimage.h> 23#include <qimage.h>
26#include <qpainter.h> 24#include <qpainter.h>
27#ifdef Q_WS_QWS 25#ifdef Q_WS_QWS
28#include <qpe/qcopenvelope_qws.h> 26#include <qpe/qcopenvelope_qws.h>
29#endif 27#endif
30#include <qpe/mediaplayerplugininterface.h> 28#include "mediaplayerplugininterface.h"
31#include <stdio.h> 29#include <stdio.h>
32#include <stdlib.h> 30#include <stdlib.h>
33#include <string.h> 31#include <string.h>
34#include <time.h> 32#include <time.h>
35#include <unistd.h> 33#include <unistd.h>
36#include <pthread.h> 34#include <pthread.h>
37#include "loopcontrol.h" 35#include "loopcontrol.h"
38#include "audiodevice.h" 36#include "audiodevice.h"
39#include "videowidget.h" 37#include "videowidget.h"
40#include "audiowidget.h" 38#include "audiowidget.h"
41#include "mediaplayerstate.h" 39#include "mediaplayerstate.h"
42 40
43 41
44#if defined(QT_QWS_CUSTOM) || defined(QT_QWS_IPAQ) 42#if defined(QT_QWS_CUSTOM) || defined(QT_QWS_IPAQ)
45#define USE_REALTIME_AUDIO_THREAD 43#define USE_REALTIME_AUDIO_THREAD
46#endif 44#endif
47 45
48 46
49extern VideoWidget *videoUI; // now only needed to tell it to play a frame 47extern VideoWidget *videoUI; // now only needed to tell it to play a frame
50extern MediaPlayerState *mediaPlayerState; 48extern MediaPlayerState *mediaPlayerState;
51 49
52 50
53#define DecodeLoopDebug(x) qDebug x 51#define DecodeLoopDebug(x) qDebug x
54//#define DecodeLoopDebug(x) 52//#define DecodeLoopDebug(x)
55 53
56 54
57 static char *audioBuffer = NULL; 55 static char *audioBuffer = NULL;
58static AudioDevice *audioDevice = NULL; 56static AudioDevice *audioDevice = NULL;
59 static bool disabledSuspendScreenSaver = FALSE; 57 static bool disabledSuspendScreenSaver = FALSE;
60 58
61 59
62 pthread_tvideo_tid; 60 pthread_tvideo_tid;
63pthread_attr_t video_attr; 61pthread_attr_t video_attr;
64 pthread_taudio_tid; 62 pthread_taudio_tid;
65pthread_attr_t audio_attr; 63pthread_attr_t audio_attr;
66 64
67 65
68bool emitPlayFinished = FALSE; 66bool emitPlayFinished = FALSE;
69bool emitChangePos = FALSE; 67bool emitChangePos = FALSE;
70 68
71 69
72class Mutex { 70class Mutex {
73public: 71public:
74 Mutex() { 72 Mutex() {
75 pthread_mutexattr_t attr; 73 pthread_mutexattr_t attr;
76 pthread_mutexattr_init( &attr ); 74 pthread_mutexattr_init( &attr );
77 pthread_mutex_init( &mutex, &attr ); 75 pthread_mutex_init( &mutex, &attr );
78 pthread_mutexattr_destroy( &attr ); 76 pthread_mutexattr_destroy( &attr );
diff --git a/core/multimedia/opieplayer/loopcontrol_threaded.h b/core/multimedia/opieplayer/loopcontrol_threaded.h
index ced6ac8..1031169 100644
--- a/core/multimedia/opieplayer/loopcontrol_threaded.h
+++ b/core/multimedia/opieplayer/loopcontrol_threaded.h
@@ -1,72 +1,70 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef MPEGVIEW_H 20#ifndef MPEGVIEW_H
21#define MPEGVIEW_H 21#define MPEGVIEW_H
22 22
23
24
25#include <qwidget.h> 23#include <qwidget.h>
26#include <qdatetime.h> 24#include <qdatetime.h>
27 25
28 26
29class LoopControl : public QObject { 27class LoopControl : public QObject {
30 Q_OBJECT 28 Q_OBJECT
31public: 29public:
32 LoopControl( QObject *parent, const char *name ); 30 LoopControl( QObject *parent, const char *name );
33 ~LoopControl(); 31 ~LoopControl();
34 32
35 bool init( const QString& filename ); 33 bool init( const QString& filename );
36 34
37 bool hasVideo() const { return hasVideoChannel; } 35 bool hasVideo() const { return hasVideoChannel; }
38 bool hasAudio() const { return hasAudioChannel; } 36 bool hasAudio() const { return hasAudioChannel; }
39 37
40 long totalPlaytime() { return (long)(hasVideoChannel ? total_video_frames / framerate : total_audio_samples / freq); } 38 long totalPlaytime() { return (long)(hasVideoChannel ? total_video_frames / framerate : total_audio_samples / freq); }
41 39
42 // These are public to run them from global functions needed to start threads 40 // These are public to run them from global functions needed to start threads
43 // Otherwise they would be private 41 // Otherwise they would be private
44 void startAudio(); 42 void startAudio();
45 void startVideo(); 43 void startVideo();
46public slots: 44public slots:
47 void play(); 45 void play();
48 void stop( bool willPlayAgainShortly = FALSE ); 46 void stop( bool willPlayAgainShortly = FALSE );
49 47
50 void setMute( bool ); 48 void setMute( bool );
51 void setPaused( bool ); 49 void setPaused( bool );
52 void setPosition( long ); 50 void setPosition( long );
53 51
54signals: 52signals:
55 void positionChanged( long, long ); 53 void positionChanged( long, long );
56 void playFinished(); 54 void playFinished();
57 55
58protected: 56protected:
59 void timerEvent(QTimerEvent*); 57 void timerEvent(QTimerEvent*);
60 58
61private: 59private:
62 void startTimers(); 60 void startTimers();
63 void killTimers(); 61 void killTimers();
64 62
65 63
66 QTime playtime; 64 QTime playtime;
67 int timerid; 65 int timerid;
68 int audioSampleCounter; 66 int audioSampleCounter;
69 long current_frame; 67 long current_frame;
70 long total_video_frames; 68 long total_video_frames;
71 long total_audio_samples; 69 long total_audio_samples;
72 70
diff --git a/core/multimedia/opieplayer/mediaplayerplugininterface.h b/core/multimedia/opieplayer/mediaplayerplugininterface.h
index aeeffde..339b2e4 100644
--- a/core/multimedia/opieplayer/mediaplayerplugininterface.h
+++ b/core/multimedia/opieplayer/mediaplayerplugininterface.h
@@ -1,114 +1,111 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef MEDIA_PLAYER_PLUGIN_INTERFACE_H 20#ifndef MEDIA_PLAYER_PLUGIN_INTERFACE_H
21#define MEDIA_PLAYER_PLUGIN_INTERFACE_H 21#define MEDIA_PLAYER_PLUGIN_INTERFACE_H
22 22
23
24#include <qpe/qcom.h> 23#include <qpe/qcom.h>
25 24
26#ifndef QT_NO_COMPONENT 25#ifndef QT_NO_COMPONENT
27// {c0093632-b44c-4cf7-a279-d82fe8a8890c} 26// {c0093632-b44c-4cf7-a279-d82fe8a8890c}
28# ifndef IID_MediaPlayerPlugin 27# ifndef IID_MediaPlayerPlugin
29# define IID_MediaPlayerPlugin QUuid( 0xc0093632, 0xb44c, 0x4cf7, 0xa2, 0x79, 0xd8, 0x2f, 0xe8, 0xa8, 0x89, 0x0c ) 28# define IID_MediaPlayerPlugin QUuid( 0xc0093632, 0xb44c, 0x4cf7, 0xa2, 0x79, 0xd8, 0x2f, 0xe8, 0xa8, 0x89, 0x0c )
30# endif 29# endif
31#endif 30#endif
32 31
33 32
34enum ColorFormat { 33enum ColorFormat {
35 RGB565, 34 RGB565,
36 BGR565, 35 BGR565,
37 RGBA8888, 36 RGBA8888,
38 BGRA8888 37 BGRA8888
39}; 38};
40 39
41 40
42class MediaPlayerDecoder { 41class MediaPlayerDecoder {
43 42
44public: 43public:
45 virtual ~MediaPlayerDecoder() { }; 44 virtual ~MediaPlayerDecoder() { };
46 45
47 // About Plugin 46 // About Plugin
48 virtual const char *pluginName() = 0; 47 virtual const char *pluginName() = 0;
49 virtual const char *pluginComment() = 0; 48 virtual const char *pluginComment() = 0;
50 virtual double pluginVersion() = 0; 49 virtual double pluginVersion() = 0;
51 50
52 virtual bool isFileSupported( const QString& file ) = 0; 51 virtual bool isFileSupported( const QString& file ) = 0;
53 virtual bool open( const QString& file ) = 0; 52 virtual bool open( const QString& file ) = 0;
54 virtual bool close() = 0; 53 virtual bool close() = 0;
55 virtual bool isOpen() = 0; 54 virtual bool isOpen() = 0;
56 virtual const QString &fileInfo() = 0; 55 virtual const QString &fileInfo() = 0;
57 56
58 // If decoder doesn't support audio then return 0 here 57 // If decoder doesn't support audio then return 0 here
59 virtual int audioStreams() = 0; 58 virtual int audioStreams() = 0;
60 virtual int audioChannels( int stream ) = 0; 59 virtual int audioChannels( int stream ) = 0;
61 virtual int audioFrequency( int stream ) = 0; 60 virtual int audioFrequency( int stream ) = 0;
62 virtual int audioSamples( int stream ) = 0; 61 virtual int audioSamples( int stream ) = 0;
63 virtual bool audioSetSample( long sample, int stream ) = 0; 62 virtual bool audioSetSample( long sample, int stream ) = 0;
64 virtual long audioGetSample( int stream ) = 0; 63 virtual long audioGetSample( int stream ) = 0;
65// virtual bool audioReadMonoSamples( short *samples, long samples, long& samplesRead, int stream ) = 0;
66// virtual bool audioReadStereoSamples( short *samples, long samples, long& samplesRead, int stream ) = 0;
67 virtual bool audioReadSamples( short *samples, int channels, long samples, long& samplesRead, int stream ) = 0; 64 virtual bool audioReadSamples( short *samples, int channels, long samples, long& samplesRead, int stream ) = 0;
68 // Libmpeg3 functions, perhaps good for reading an audio file with 5 channels or something!
69// virtual bool audioReadSamples( short *samples, int channel, long samples, int stream ) = 0;
70// virtual bool audioReReadSamples( short *samples, int channel, long samples, int stream ) = 0;
71 65
72 // If decoder doesn't support video then return 0 here 66 // If decoder doesn't support video then return 0 here
73 virtual int videoStreams() = 0; 67 virtual int videoStreams() = 0;
74 virtual int videoWidth( int stream ) = 0; 68 virtual int videoWidth( int stream ) = 0;
75 virtual int videoHeight( int stream ) = 0; 69 virtual int videoHeight( int stream ) = 0;
76 virtual double videoFrameRate( int stream ) = 0; // frames per second (this may change to frames/1000secs) 70 virtual double videoFrameRate( int stream ) = 0; // frames per second (this may change to frames/1000secs)
77 virtual int videoFrames( int stream ) = 0; 71 virtual int videoFrames( int stream ) = 0;
78 virtual bool videoSetFrame( long sample, int stream ) = 0; 72 virtual bool videoSetFrame( long sample, int stream ) = 0;
79 virtual long videoGetFrame( int stream ) = 0; 73 virtual long videoGetFrame( int stream ) = 0;
80 virtual bool videoReadFrame( unsigned char **output_rows, int in_x, int in_y, int in_w, int in_h, ColorFormat color_model, int stream ) = 0; 74 virtual bool videoReadFrame( unsigned char **output_rows, int in_x, int in_y, int in_w, int in_h, ColorFormat color_model, int stream ) = 0;
81 virtual bool videoReadScaledFrame( unsigned char **output_rows, int in_x, int in_y, int in_w, int in_h, int out_w, int out_h, ColorFormat color_model, int stream ) = 0; 75 virtual bool videoReadScaledFrame( unsigned char **output_rows, int in_x, int in_y, int in_w, int in_h, int out_w, int out_h, ColorFormat color_model, int stream ) = 0;
82 virtual bool videoReadYUVFrame( char *y_output, char *u_output, char *v_output, int in_x, int in_y, int in_w, int in_h, int stream ) = 0; 76 virtual bool videoReadYUVFrame( char *y_output, char *u_output, char *v_output, int in_x, int in_y, int in_w, int in_h, int stream ) = 0;
83 77
84 // Profiling 78 // Profiling
85 virtual double getTime() = 0; 79 virtual double getTime() = 0;
86 80
87 // Ignore if these aren't supported 81 // Ignore if these aren't supported
88 virtual bool setSMP( int cpus ) = 0; 82 virtual bool setSMP( int cpus ) = 0;
89 virtual bool setMMX( bool useMMX ) = 0; 83 virtual bool setMMX( bool useMMX ) = 0;
90 84
91 // Capabilities 85 // Capabilities
92 virtual bool supportsAudio() = 0; 86 virtual bool supportsAudio() = 0;
93 virtual bool supportsVideo() = 0; 87 virtual bool supportsVideo() = 0;
94 virtual bool supportsYUV() = 0; 88 virtual bool supportsYUV() = 0;
95 virtual bool supportsMMX() = 0; 89 virtual bool supportsMMX() = 0;
96 virtual bool supportsSMP() = 0; 90 virtual bool supportsSMP() = 0;
97 virtual bool supportsStereo() = 0; 91 virtual bool supportsStereo() = 0;
98 virtual bool supportsScaling() = 0; 92 virtual bool supportsScaling() = 0;
99 93
94 // File Properies
95 virtual long getPlayTime() { return -1; }
96 virtual int audioBitsPerSample( int stream ) = 0;
100}; 97};
101 98
102 99
103class MediaPlayerEncoder; 100class MediaPlayerEncoder;
104 101
105 102
106struct MediaPlayerPluginInterface : public QUnknownInterface 103struct MediaPlayerPluginInterface : public QUnknownInterface
107{ 104{
108 virtual MediaPlayerDecoder *decoder() = 0; 105 virtual MediaPlayerDecoder *decoder() = 0;
109 virtual MediaPlayerEncoder *encoder() = 0; 106 virtual MediaPlayerEncoder *encoder() = 0;
110}; 107};
111 108
112 109
113#endif 110#endif
114 111
diff --git a/core/multimedia/opieplayer/mediaplayerstate.cpp b/core/multimedia/opieplayer/mediaplayerstate.cpp
index 7e82166..13741f6 100644
--- a/core/multimedia/opieplayer/mediaplayerstate.cpp
+++ b/core/multimedia/opieplayer/mediaplayerstate.cpp
@@ -1,185 +1,190 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include <qpe/qpeapplication.h> 20#include <qpe/qpeapplication.h>
21#include <qpe/qlibrary.h> 21#include <qpe/qlibrary.h>
22#include <qpe/mediaplayerplugininterface.h>
23#include <qpe/config.h> 22#include <qpe/config.h>
24#include <qvaluelist.h> 23#include <qvaluelist.h>
25#include <qobject.h> 24#include <qobject.h>
26#include <qdir.h> 25#include <qdir.h>
26#include "mediaplayerplugininterface.h"
27#include "mediaplayerstate.h" 27#include "mediaplayerstate.h"
28 28
29
29#ifdef QT_NO_COMPONENT 30#ifdef QT_NO_COMPONENT
30// Plugins which are compiled in when no plugin architecture available 31// Plugins which are compiled in when no plugin architecture available
31#include "libmad/libmadpluginimpl.h" 32#include "libmad/libmadpluginimpl.h"
32#include "libmpeg3/libmpeg3pluginimpl.h" 33#include "libmpeg3/libmpeg3pluginimpl.h"
33#include "wavplugin/wavpluginimpl.h" 34#include "wavplugin/wavpluginimpl.h"
34#endif 35#endif
35 36
36 37
37 #define MediaPlayerDebug(x)qDebug x 38//#define MediaPlayerDebug(x) qDebug x
38//#define MediaPlayerDebug(x) 39#define MediaPlayerDebug(x)
39 40
40 41
41MediaPlayerState::MediaPlayerState( QObject *parent, const char *name ) 42MediaPlayerState::MediaPlayerState( QObject *parent, const char *name )
42 : QObject( parent, name ), decoder( NULL ), libmpeg3decoder( NULL ) { 43 : QObject( parent, name ), decoder( NULL ), libmpeg3decoder( NULL ) {
43 Config cfg( "MediaPlayer" ); 44 Config cfg( "MediaPlayer" );
44 readConfig( cfg ); 45 readConfig( cfg );
45 loadPlugins(); 46 loadPlugins();
46} 47}
47 48
48 49
49MediaPlayerState::~MediaPlayerState() { 50MediaPlayerState::~MediaPlayerState() {
50 Config cfg( "MediaPlayer" ); 51 Config cfg( "MediaPlayer" );
51 writeConfig( cfg ); 52 writeConfig( cfg );
52} 53}
53 54
54 55
55void MediaPlayerState::readConfig( Config& cfg ) { 56void MediaPlayerState::readConfig( Config& cfg ) {
56 cfg.setGroup("Options"); 57 cfg.setGroup("Options");
57 isFullscreen = cfg.readBoolEntry( "FullScreen" ); 58 isFullscreen = cfg.readBoolEntry( "FullScreen" );
58 isScaled = cfg.readBoolEntry( "Scaling" ); 59 isScaled = cfg.readBoolEntry( "Scaling" );
59 isLooping = cfg.readBoolEntry( "Looping" ); 60 isLooping = cfg.readBoolEntry( "Looping" );
60 isShuffled = cfg.readBoolEntry( "Shuffle" ); 61 isShuffled = cfg.readBoolEntry( "Shuffle" );
61 usePlaylist = cfg.readBoolEntry( "UsePlayList" ); 62 usePlaylist = cfg.readBoolEntry( "UsePlayList" );
62 isPlaying = FALSE; 63 isPlaying = FALSE;
63 isPaused = FALSE; 64 isPaused = FALSE;
64 curPosition = 0; 65 curPosition = 0;
65 curLength = 0; 66 curLength = 0;
66 curView = 'l'; 67 curView = 'l';
67} 68}
68 69
69 70
70void MediaPlayerState::writeConfig( Config& cfg ) const { 71void MediaPlayerState::writeConfig( Config& cfg ) const {
71 cfg.setGroup("Options"); 72 cfg.setGroup("Options");
72 cfg.writeEntry("FullScreen", isFullscreen ); 73 cfg.writeEntry("FullScreen", isFullscreen );
73 cfg.writeEntry("Scaling", isScaled ); 74 cfg.writeEntry("Scaling", isScaled );
74 cfg.writeEntry("Looping", isLooping ); 75 cfg.writeEntry("Looping", isLooping );
75 cfg.writeEntry("Shuffle", isShuffled ); 76 cfg.writeEntry("Shuffle", isShuffled );
76 cfg.writeEntry("UsePlayList", usePlaylist ); 77 cfg.writeEntry("UsePlayList", usePlaylist );
77} 78}
78 79
79 80
80struct MediaPlayerPlugin { 81struct MediaPlayerPlugin {
81#ifndef QT_NO_COMPONENT 82#ifndef QT_NO_COMPONENT
82 QLibrary *library; 83 QLibrary *library;
83#endif 84#endif
84 MediaPlayerPluginInterface *iface; 85 MediaPlayerPluginInterface *iface;
85 MediaPlayerDecoder *decoder; 86 MediaPlayerDecoder *decoder;
86 MediaPlayerEncoder *encoder; 87 MediaPlayerEncoder *encoder;
87}; 88};
88 89
89 90
90static QValueList<MediaPlayerPlugin> pluginList; 91static QValueList<MediaPlayerPlugin> pluginList;
91 92
92 93
93// Find the first decoder which supports this type of file 94// Find the first decoder which supports this type of file
94MediaPlayerDecoder *MediaPlayerState::newDecoder( const QString& file ) { 95MediaPlayerDecoder *MediaPlayerState::newDecoder( const QString& file ) {
95 MediaPlayerDecoder *tmpDecoder = NULL; 96 MediaPlayerDecoder *tmpDecoder = NULL;
96 QValueList<MediaPlayerPlugin>::Iterator it; 97 QValueList<MediaPlayerPlugin>::Iterator it;
97 for ( it = pluginList.begin(); it != pluginList.end(); ++it ) { 98 for ( it = pluginList.begin(); it != pluginList.end(); ++it ) {
98 if ( (*it).decoder->isFileSupported( file ) ) { 99 if ( (*it).decoder->isFileSupported( file ) ) {
99 tmpDecoder = (*it).decoder; 100 tmpDecoder = (*it).decoder;
100 break; 101 break;
101 } 102 }
102 } 103 }
103 return decoder = tmpDecoder; 104 return decoder = tmpDecoder;
104} 105}
105 106
106 107
107MediaPlayerDecoder *MediaPlayerState::curDecoder() { 108MediaPlayerDecoder *MediaPlayerState::curDecoder() {
108 return decoder; 109 return decoder;
109} 110}
110 111
111 112
112// ### hack to get true sample count 113// ### hack to get true sample count
113MediaPlayerDecoder *MediaPlayerState::libMpeg3Decoder() { 114MediaPlayerDecoder *MediaPlayerState::libMpeg3Decoder() {
114 return libmpeg3decoder; 115 return libmpeg3decoder;
115} 116}
116 117
118// ### hack to get true sample count
119// MediaPlayerDecoder *MediaPlayerState::libWavDecoder() {
120// return libwavdecoder;
121// }
117 122
118void MediaPlayerState::loadPlugins() { 123void MediaPlayerState::loadPlugins() {
119 124
120#ifndef QT_NO_COMPONENT 125#ifndef QT_NO_COMPONENT
121 QValueList<MediaPlayerPlugin>::Iterator mit; 126 QValueList<MediaPlayerPlugin>::Iterator mit;
122 for ( mit = pluginList.begin(); mit != pluginList.end(); ++mit ) { 127 for ( mit = pluginList.begin(); mit != pluginList.end(); ++mit ) {
123 (*mit).iface->release(); 128 (*mit).iface->release();
124 (*mit).library->unload(); 129 (*mit).library->unload();
125 delete (*mit).library; 130 delete (*mit).library;
126 } 131 }
127 pluginList.clear(); 132 pluginList.clear();
128 133
129 QString path = QPEApplication::qpeDir() + "/plugins/codecs"; 134 QString path = QPEApplication::qpeDir() + "/plugins/codecs";
130 QDir dir( path, "lib*.so" ); 135 QDir dir( path, "lib*.so" );
131 QStringList list = dir.entryList(); 136 QStringList list = dir.entryList();
132 QStringList::Iterator it; 137 QStringList::Iterator it;
133 for ( it = list.begin(); it != list.end(); ++it ) { 138 for ( it = list.begin(); it != list.end(); ++it ) {
134 MediaPlayerPluginInterface *iface = 0; 139 MediaPlayerPluginInterface *iface = 0;
135 QLibrary *lib = new QLibrary( path + "/" + *it ); 140 QLibrary *lib = new QLibrary( path + "/" + *it );
136 141
137 MediaPlayerDebug(( "querying: %s", QString( path + "/" + *it ).latin1() )); 142 MediaPlayerDebug(( "querying: %s", QString( path + "/" + *it ).latin1() ));
138 143
139 if ( lib->queryInterface( IID_MediaPlayerPlugin, (QUnknownInterface**)&iface ) == QS_OK ) { 144 if ( lib->queryInterface( IID_MediaPlayerPlugin, (QUnknownInterface**)&iface ) == QS_OK ) {
140 145
141 MediaPlayerDebug(( "loading: %s", QString( path + "/" + *it ).latin1() )); 146 MediaPlayerDebug(( "loading: %s", QString( path + "/" + *it ).latin1() ));
142 147
143 MediaPlayerPlugin plugin; 148 MediaPlayerPlugin plugin;
144 plugin.library = lib; 149 plugin.library = lib;
145 plugin.iface = iface; 150 plugin.iface = iface;
146 plugin.decoder = plugin.iface->decoder(); 151 plugin.decoder = plugin.iface->decoder();
147 plugin.encoder = plugin.iface->encoder(); 152 plugin.encoder = plugin.iface->encoder();
148 pluginList.append( plugin ); 153 pluginList.append( plugin );
149 154
150 // ### hack to get true sample count 155 // ### hack to get true sample count
151 if ( plugin.decoder->pluginName() == QString("LibMpeg3Plugin") ) 156 if ( plugin.decoder->pluginName() == QString("LibMpeg3Plugin") )
152 libmpeg3decoder = plugin.decoder; 157 libmpeg3decoder = plugin.decoder;
153 158
154 } else { 159 } else {
155 delete lib; 160 delete lib;
156 } 161 }
157 } 162 }
158#else 163#else
159 pluginList.clear(); 164 pluginList.clear();
160 165
161 MediaPlayerPlugin plugin0; 166 MediaPlayerPlugin plugin0;
162 plugin0.iface = new LibMpeg3PluginImpl; 167 plugin0.iface = new LibMpeg3PluginImpl;
163 plugin0.decoder = plugin0.iface->decoder(); 168 plugin0.decoder = plugin0.iface->decoder();
164 plugin0.encoder = plugin0.iface->encoder(); 169 plugin0.encoder = plugin0.iface->encoder();
165 pluginList.append( plugin0 ); 170 pluginList.append( plugin0 );
166 171
167 MediaPlayerPlugin plugin1; 172 MediaPlayerPlugin plugin1;
168 plugin1.iface = new LibMadPluginImpl; 173 plugin1.iface = new LibMadPluginImpl;
169 plugin1.decoder = plugin1.iface->decoder(); 174 plugin1.decoder = plugin1.iface->decoder();
170 plugin1.encoder = plugin1.iface->encoder(); 175 plugin1.encoder = plugin1.iface->encoder();
171 pluginList.append( plugin1 ); 176 pluginList.append( plugin1 );
172 177
173 MediaPlayerPlugin plugin2; 178 MediaPlayerPlugin plugin2;
174 plugin2.iface = new WavPluginImpl; 179 plugin2.iface = new WavPluginImpl;
175 plugin2.decoder = plugin2.iface->decoder(); 180 plugin2.decoder = plugin2.iface->decoder();
176 plugin2.encoder = plugin2.iface->encoder(); 181 plugin2.encoder = plugin2.iface->encoder();
177 pluginList.append( plugin2 ); 182 pluginList.append( plugin2 );
178#endif 183#endif
179 184
180 if ( pluginList.count() ) 185 if ( pluginList.count() )
181 MediaPlayerDebug(( "%i decoders found", pluginList.count() )); 186 MediaPlayerDebug(( "%i decoders found", pluginList.count() ));
182 else 187 else
183 MediaPlayerDebug(( "No decoders found" )); 188 MediaPlayerDebug(( "No decoders found" ));
184} 189}
185 190
diff --git a/core/multimedia/opieplayer/mpegplayer.pro b/core/multimedia/opieplayer/mpegplayer.pro
index 3b8d4b0..41f2de0 100644
--- a/core/multimedia/opieplayer/mpegplayer.pro
+++ b/core/multimedia/opieplayer/mpegplayer.pro
@@ -1,21 +1,22 @@
1 TEMPLATE= app 1TEMPLATE = app
2 CONFIG = qt warn_on release 2CONFIG = qt warn_on release
3 DESTDIR = $(OPIEDIR)/bin 3#release
4 HEADERS = loopcontrol.h mediaplayerplugininterface.h playlistselection.h mediaplayerstate.h \ 4DESTDIR = $(OPIEDIR)/bin
5 videowidget.h audiowidget.h playlistwidget.h mediaplayer.h audiodevice.h 5HEADERS = loopcontrol.h mediaplayerplugininterface.h playlistselection.h mediaplayerstate.h \
6 SOURCES = main.cpp \ 6 videowidget.h audiowidget.h playlistwidget.h mediaplayer.h audiodevice.h
7 loopcontrol.cpp playlistselection.cpp mediaplayerstate.cpp \ 7SOURCES = main.cpp \
8 videowidget.cpp audiowidget.cpp playlistwidget.cpp mediaplayer.cpp audiodevice.cpp 8 loopcontrol.cpp playlistselection.cpp mediaplayerstate.cpp \
9 TARGET = mpegplayer 9 videowidget.cpp audiowidget.cpp playlistwidget.cpp mediaplayer.cpp audiodevice.cpp
10 INCLUDEPATH+= $(OPIEDIR)/include 10TARGET = mpegplayer
11 DEPENDPATH+= $(OPIEDIR)/include 11INCLUDEPATH += $(OPIEDIR)/include
12DEPENDPATH += $(OPIEDIR)/include
12LIBS += -lqpe -lpthread 13LIBS += -lqpe -lpthread
13 14
14 # INTERFACES= 15# INTERFACES =
15# INCLUDEPATH += $(OPIEDIR)/include 16# INCLUDEPATH += $(OPIEDIR)/include
16# CONFIG+=static 17# CONFIG+=static
17# TMAKE_CXXFLAGS += -DQPIM_STANDALONE 18# TMAKE_CXXFLAGS += -DQPIM_STANDALONE
18 # LIBS += libmpeg3/libmpeg3.a -lpthread 19# LIBS += libmpeg3/libmpeg3.a -lpthread
19 # LIBS += $(OPIEDIR)/plugins/codecs/liblibmadplugin.so 20# LIBS += $(OPIEDIR)/plugins/codecs/liblibmadplugin.so
20 21
21TRANSLATIONS = ../i18n/de/mpegplayer.ts 22TRANSLATIONS = ../i18n/de/mpegplayer.ts
diff --git a/core/multimedia/opieplayer/playlistselection.cpp b/core/multimedia/opieplayer/playlistselection.cpp
index a82b594..2c62e86 100644
--- a/core/multimedia/opieplayer/playlistselection.cpp
+++ b/core/multimedia/opieplayer/playlistselection.cpp
@@ -1,178 +1,181 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include <qpe/applnk.h> 20#include <qpe/applnk.h>
21#include <qpe/resource.h> 21#include <qpe/resource.h>
22#include <qpainter.h> 22#include <qpainter.h>
23#include <qimage.h> 23#include <qimage.h>
24#include <qheader.h> 24#include <qheader.h>
25#include <qlistview.h> 25#include <qlistview.h>
26#include <qlist.h> 26#include <qlist.h>
27#include <qpixmap.h> 27#include <qpixmap.h>
28 28
29#include "playlistselection.h" 29#include "playlistselection.h"
30 30
31#include <stdlib.h> 31#include <stdlib.h>
32 32
33class PlayListSelectionItem : public QListViewItem { 33class PlayListSelectionItem : public QListViewItem {
34public: 34public:
35 PlayListSelectionItem( QListView *parent, const DocLnk *f ) : QListViewItem( parent ), fl( f ) { 35 PlayListSelectionItem( QListView *parent, const DocLnk *f ) : QListViewItem( parent ), fl( f ) {
36 setText( 0, f->name() ); 36 setText( 0, f->name() );
37 setPixmap( 0, f->pixmap() ); 37 setPixmap( 0, f->pixmap() );
38 } 38 }
39 39
40 ~PlayListSelectionItem() { 40 ~PlayListSelectionItem() {
41 }; 41 };
42 42
43 const DocLnk *file() const { return fl; } 43 const DocLnk *file() const { return fl; }
44 44
45private: 45private:
46 const DocLnk *fl; 46 const DocLnk *fl;
47}; 47};
48 48
49 49
50PlayListSelection::PlayListSelection( QWidget *parent, const char *name ) 50PlayListSelection::PlayListSelection( QWidget *parent, const char *name )
51 : QListView( parent, name ) 51 : QListView( parent, name )
52{ 52{
53#ifdef USE_PLAYLIST_BACKGROUND 53// #ifdef USE_PLAYLIST_BACKGROUND
54 setStaticBackground( TRUE ); 54 setStaticBackground( TRUE );
55 setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/background" ) ); 55// setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/background" ) );
56#endif 56 setBackgroundPixmap( Resource::loadPixmap( "opielogo" ) );
57// #endif
58 addColumn("Title",236);
57 setAllColumnsShowFocus( TRUE ); 59 setAllColumnsShowFocus( TRUE );
58 addColumn( tr( "Playlist Selection" ) ); 60 addColumn( tr( "Playlist Selection" ) );
59 header()->hide(); 61 header()->hide();
60 setSorting( -1, FALSE ); 62 setSorting( -1, FALSE );
61} 63}
62 64
63 65
64PlayListSelection::~PlayListSelection() { 66PlayListSelection::~PlayListSelection() {
65} 67}
66 68
67 69
68#ifdef USE_PLAYLIST_BACKGROUND 70// #ifdef USE_PLAYLIST_BACKGROUND
69void PlayListSelection::drawBackground( QPainter *p, const QRect &r ) { 71void PlayListSelection::drawBackground( QPainter *p, const QRect &r ) {
70 p->fillRect( r, QBrush( white ) ); 72 p->fillRect( r, QBrush( white ) );
71 QImage logo = Resource::loadImage( "mpegplayer/background" ); 73// QImage logo = Resource::loadImage( "mpegplayer/background" );
74 QImage logo = Resource::loadImage( "opielogo" );
72 if ( !logo.isNull() ) 75 if ( !logo.isNull() )
73 p->drawImage( (width() - logo.width()) / 2, (height() - logo.height()) / 2, logo ); 76 p->drawImage( (width() - logo.width()) / 2, (height() - logo.height()) / 2, logo );
74} 77}
75#endif 78// #endif
76 79
77 80
78void PlayListSelection::contentsMouseMoveEvent( QMouseEvent *event ) { 81void PlayListSelection::contentsMouseMoveEvent( QMouseEvent *event ) {
79 if ( event->state() == QMouseEvent::LeftButton ) { 82 if ( event->state() == QMouseEvent::LeftButton ) {
80 QListViewItem *currentItem = selectedItem(); 83 QListViewItem *currentItem = selectedItem();
81 QListViewItem *itemUnder = itemAt( QPoint( event->pos().x(), event->pos().y() - contentsY() ) ); 84 QListViewItem *itemUnder = itemAt( QPoint( event->pos().x(), event->pos().y() - contentsY() ) );
82 if ( currentItem && currentItem->itemAbove() == itemUnder ) 85 if ( currentItem && currentItem->itemAbove() == itemUnder )
83 moveSelectedUp(); 86 moveSelectedUp();
84 else if ( currentItem && currentItem->itemBelow() == itemUnder ) 87 else if ( currentItem && currentItem->itemBelow() == itemUnder )
85 moveSelectedDown(); 88 moveSelectedDown();
86 } 89 }
87} 90}
88 91
89 92
90const DocLnk *PlayListSelection::current() { 93const DocLnk *PlayListSelection::current() {
91 PlayListSelectionItem *item = (PlayListSelectionItem *)selectedItem(); 94 PlayListSelectionItem *item = (PlayListSelectionItem *)selectedItem();
92 if ( item ) 95 if ( item )
93 return item->file(); 96 return item->file();
94 return NULL; 97 return NULL;
95} 98}
96 99
97 100
98void PlayListSelection::addToSelection( const DocLnk &lnk ) { 101void PlayListSelection::addToSelection( const DocLnk &lnk ) {
99 PlayListSelectionItem *item = new PlayListSelectionItem( this, new DocLnk( lnk ) ); 102 PlayListSelectionItem *item = new PlayListSelectionItem( this, new DocLnk( lnk ) );
100 QListViewItem *current = selectedItem(); 103 QListViewItem *current = selectedItem();
101 if ( current ) 104 if ( current )
102 item->moveItem( current ); 105 item->moveItem( current );
103 setSelected( item, TRUE ); 106 setSelected( item, TRUE );
104 ensureItemVisible( selectedItem() ); 107 ensureItemVisible( selectedItem() );
105} 108}
106 109
107 110
108void PlayListSelection::removeSelected() { 111void PlayListSelection::removeSelected() {
109 QListViewItem *item = selectedItem(); 112 QListViewItem *item = selectedItem();
110 if ( item ) 113 if ( item )
111 delete item; 114 delete item;
112 setSelected( currentItem(), TRUE ); 115 setSelected( currentItem(), TRUE );
113 ensureItemVisible( selectedItem() ); 116 ensureItemVisible( selectedItem() );
114} 117}
115 118
116 119
117void PlayListSelection::moveSelectedUp() { 120void PlayListSelection::moveSelectedUp() {
118 QListViewItem *item = selectedItem(); 121 QListViewItem *item = selectedItem();
119 if ( item && item->itemAbove() ) 122 if ( item && item->itemAbove() )
120 item->itemAbove()->moveItem( item ); 123 item->itemAbove()->moveItem( item );
121 ensureItemVisible( selectedItem() ); 124 ensureItemVisible( selectedItem() );
122} 125}
123 126
124 127
125void PlayListSelection::moveSelectedDown() { 128void PlayListSelection::moveSelectedDown() {
126 QListViewItem *item = selectedItem(); 129 QListViewItem *item = selectedItem();
127 if ( item && item->itemBelow() ) 130 if ( item && item->itemBelow() )
128 item->moveItem( item->itemBelow() ); 131 item->moveItem( item->itemBelow() );
129 ensureItemVisible( selectedItem() ); 132 ensureItemVisible( selectedItem() );
130} 133}
131 134
132 135
133bool PlayListSelection::prev() { 136bool PlayListSelection::prev() {
134 QListViewItem *item = selectedItem(); 137 QListViewItem *item = selectedItem();
135 if ( item && item->itemAbove() ) 138 if ( item && item->itemAbove() )
136 setSelected( item->itemAbove(), TRUE ); 139 setSelected( item->itemAbove(), TRUE );
137 else 140 else
138 return FALSE; 141 return FALSE;
139 ensureItemVisible( selectedItem() ); 142 ensureItemVisible( selectedItem() );
140 return TRUE; 143 return TRUE;
141} 144}
142 145
143 146
144bool PlayListSelection::next() { 147bool PlayListSelection::next() {
145 QListViewItem *item = selectedItem(); 148 QListViewItem *item = selectedItem();
146 if ( item && item->itemBelow() ) 149 if ( item && item->itemBelow() )
147 setSelected( item->itemBelow(), TRUE ); 150 setSelected( item->itemBelow(), TRUE );
148 else 151 else
149 return FALSE; 152 return FALSE;
150 ensureItemVisible( selectedItem() ); 153 ensureItemVisible( selectedItem() );
151 return TRUE; 154 return TRUE;
152} 155}
153 156
154 157
155bool PlayListSelection::first() { 158bool PlayListSelection::first() {
156 QListViewItem *item = firstChild(); 159 QListViewItem *item = firstChild();
157 if ( item ) 160 if ( item )
158 setSelected( item, TRUE ); 161 setSelected( item, TRUE );
159 else 162 else
160 return FALSE; 163 return FALSE;
161 ensureItemVisible( selectedItem() ); 164 ensureItemVisible( selectedItem() );
162 return TRUE; 165 return TRUE;
163} 166}
164 167
165 168
166bool PlayListSelection::last() { 169bool PlayListSelection::last() {
167 QListViewItem *prevItem = NULL; 170 QListViewItem *prevItem = NULL;
168 QListViewItem *item = firstChild(); 171 QListViewItem *item = firstChild();
169 while ( ( item = item->nextSibling() ) ) 172 while ( ( item = item->nextSibling() ) )
170 prevItem = item; 173 prevItem = item;
171 if ( prevItem ) 174 if ( prevItem )
172 setSelected( prevItem, TRUE ); 175 setSelected( prevItem, TRUE );
173 else 176 else
174 return FALSE; 177 return FALSE;
175 ensureItemVisible( selectedItem() ); 178 ensureItemVisible( selectedItem() );
176 return TRUE; 179 return TRUE;
177} 180}
178 181
diff --git a/core/multimedia/opieplayer/playlistselection.h b/core/multimedia/opieplayer/playlistselection.h
index 22d3c74..57e10f1 100644
--- a/core/multimedia/opieplayer/playlistselection.h
+++ b/core/multimedia/opieplayer/playlistselection.h
@@ -1,63 +1,61 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef PLAY_LIST_SELECTION_H 20#ifndef PLAY_LIST_SELECTION_H
21#define PLAY_LIST_SELECTION_H 21#define PLAY_LIST_SELECTION_H
22 22
23
24
25#include <qlist.h> 23#include <qlist.h>
26#include <qlistview.h> 24#include <qlistview.h>
27#include <qpe/applnk.h> 25#include <qpe/applnk.h>
28 26
29 27
30class PlayListSelection : public QListView { 28class PlayListSelection : public QListView {
31 Q_OBJECT 29 Q_OBJECT
32public: 30public:
33 PlayListSelection( QWidget *parent, const char *name=0 ); 31 PlayListSelection( QWidget *parent, const char *name=0 );
34 ~PlayListSelection(); 32 ~PlayListSelection();
35 33
36 const DocLnk *current(); // retrieve the current playlist entry (media file link) 34 const DocLnk *current(); // retrieve the current playlist entry (media file link)
37 35
38public slots: 36public slots:
39 void addToSelection( const DocLnk & ); // Add a media file to the playlist 37 void addToSelection( const DocLnk & ); // Add a media file to the playlist
40 void removeSelected(); // Remove a media file from the playlist 38 void removeSelected(); // Remove a media file from the playlist
41 void moveSelectedUp(); // Move the media file up the playlist so it is played earlier 39 void moveSelectedUp(); // Move the media file up the playlist so it is played earlier
42 void moveSelectedDown(); // Move the media file down the playlist so it is played later 40 void moveSelectedDown(); // Move the media file down the playlist so it is played later
43 bool prev(); 41 bool prev();
44 bool next(); 42 bool next();
45 bool first(); 43 bool first();
46 bool last(); 44 bool last();
47 45
48protected: 46protected:
49 virtual void contentsMouseMoveEvent(QMouseEvent *); 47 virtual void contentsMouseMoveEvent(QMouseEvent *);
50#ifdef USE_PLAYLIST_BACKGROUND 48/* #ifdef USE_PLAYLIST_BACKGROUND */
51 virtual void drawBackground( QPainter *p, const QRect &r ); 49 virtual void drawBackground( QPainter *p, const QRect &r );
52 virtual void paintEmptyArea( QPainter *p, const QRect &r ) { drawBackground( p, r ); }; 50 virtual void paintEmptyArea( QPainter *p, const QRect &r ) { drawBackground( p, r ); };
53#endif 51/* #endif */
54 52
55private: 53private:
56 QList<DocLnk> selectedList; 54 QList<DocLnk> selectedList;
57 const DocLnk *lnk; 55 const DocLnk *lnk;
58}; 56};
59 57
60 58
61#endif // PLAY_LIST_SELECTION_H 59#endif // PLAY_LIST_SELECTION_H
62 60
63 61
diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp
index 0423e7a..202f351 100644
--- a/core/multimedia/opieplayer/playlistwidget.cpp
+++ b/core/multimedia/opieplayer/playlistwidget.cpp
@@ -1,449 +1,649 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include <qpe/qpemenubar.h> 21#include <qpe/qpemenubar.h>
22#include <qpe/qpetoolbar.h> 22#include <qpe/qpetoolbar.h>
23#include <qpe/fileselector.h> 23#include <qpe/fileselector.h>
24#include <qpe/qpeapplication.h>
25
24#include <qpe/applnk.h> 26#include <qpe/applnk.h>
25#include <qpe/config.h> 27#include <qpe/config.h>
26#include <qpe/global.h> 28#include <qpe/global.h>
27#include <qpe/resource.h> 29#include <qpe/resource.h>
28#include <qaction.h> 30#include <qaction.h>
29#include <qimage.h> 31#include <qimage.h>
30#include <qfile.h> 32#include <qfile.h>
31#include <qlayout.h> 33#include <qlayout.h>
32#include <qlabel.h> 34#include <qlabel.h>
33#include <qlist.h> 35#include <qlist.h>
34#include <qlistbox.h> 36#include <qlistbox.h>
35#include <qmainwindow.h> 37#include <qmainwindow.h>
36#include <qmessagebox.h> 38#include <qmessagebox.h>
37#include <qtoolbutton.h> 39#include <qtoolbutton.h>
40#include <qtabwidget.h>
41#include <qlistview.h>
42#include <qpoint.h>
43//#include <qtimer.h>
38 44
39#include "playlistselection.h" 45#include "playlistselection.h"
40#include "playlistwidget.h" 46#include "playlistwidget.h"
41#include "mediaplayerstate.h" 47#include "mediaplayerstate.h"
42 48
43#include <stdlib.h> 49#include <stdlib.h>
44 50
51#define BUTTONS_ON_TOOLBAR
52#define SIDE_BUTTONS
53#define CAN_SAVE_LOAD_PLAYLISTS
45 54
46extern MediaPlayerState *mediaPlayerState; 55extern MediaPlayerState *mediaPlayerState;
47 56
57// class myFileSelector {
48 58
59// };
49class PlayListWidgetPrivate { 60class PlayListWidgetPrivate {
50public: 61public:
51 QToolButton *tbPlay; 62 QToolButton *tbPlay, *tbFull, *tbLoop, *tbScale, *tbShuffle, *tbAddToList, *tbRemoveFromList, *tbMoveUp, *tbMoveDown, *tbRemove;
52 QToolButton *tbFull;
53 QToolButton *tbLoop;
54 QToolButton *tbScale;
55 QToolButton *tbShuffle;
56
57 QFrame *playListFrame; 63 QFrame *playListFrame;
58 FileSelector *files; 64 FileSelector *files;
59 PlayListSelection *selectedFiles; 65 PlayListSelection *selectedFiles;
60 bool setDocumentUsed; 66 bool setDocumentUsed;
61 DocLnk *current; 67 DocLnk *current;
62}; 68};
63 69
64 70
65class ToolButton : public QToolButton { 71class ToolButton : public QToolButton {
66public: 72public:
67 ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE ) 73 ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE )
68 : QToolButton( parent, name ) { 74 : QToolButton( parent, name ) {
69 setTextLabel( name ); 75 setTextLabel( name );
70 setPixmap( Resource::loadPixmap( icon ) ); 76 setPixmap( Resource::loadPixmap( icon ) );
71 setAutoRaise( TRUE ); 77 setAutoRaise( TRUE );
72 setFocusPolicy( QWidget::NoFocus ); 78 setFocusPolicy( QWidget::NoFocus );
73 setToggleButton( t ); 79 setToggleButton( t );
74 connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot ); 80 connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot );
75 QPEMenuToolFocusManager::manager()->addWidget( this ); 81 QPEMenuToolFocusManager::manager()->addWidget( this );
76 } 82 }
77}; 83};
78 84
79 85
80class MenuItem : public QAction { 86class MenuItem : public QAction {
81public: 87public:
82 MenuItem( QWidget *parent, const QString& text, QObject *handler, const QString& slot ) 88 MenuItem( QWidget *parent, const QString& text, QObject *handler, const QString& slot )
83 : QAction( text, QString::null, 0, 0 ) { 89 : QAction( text, QString::null, 0, 0 ) {
84 connect( this, SIGNAL( activated() ), handler, slot ); 90 connect( this, SIGNAL( activated() ), handler, slot );
85 addTo( parent ); 91 addTo( parent );
86 } 92 }
87}; 93};
88 94
89 95
90PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) 96PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl )
91 : QMainWindow( parent, name, fl ) { 97 : QMainWindow( parent, name, fl ) {
92 98
93 d = new PlayListWidgetPrivate; 99 d = new PlayListWidgetPrivate;
94 d->setDocumentUsed = FALSE; 100 d->setDocumentUsed = FALSE;
95 d->current = NULL; 101 d->current = NULL;
102// menuTimer = new QTimer( this ,"menu timer"),
103// connect( menuTimer, SIGNAL( timeout() ), SLOT( addSelected() ) );
96 104
97 setBackgroundMode( PaletteButton ); 105 setBackgroundMode( PaletteButton );
98 106
99 setCaption( tr("MediaPlayer") ); 107 setCaption( tr("OpiePlayer") );
100 setIcon( Resource::loadPixmap( "MPEGPlayer" ) ); 108 setIcon( Resource::loadPixmap( "MPEGPlayer" ) );
101 109
102 setToolBarsMovable( FALSE ); 110 setToolBarsMovable( FALSE );
103 111
104 // Create Toolbar 112 // Create Toolbar
105 QPEToolBar *toolbar = new QPEToolBar( this ); 113 QPEToolBar *toolbar = new QPEToolBar( this );
106 toolbar->setHorizontalStretchable( TRUE ); 114 toolbar->setHorizontalStretchable( TRUE );
107 115
108 // Create Menubar 116 // Create Menubar
109 QPEMenuBar *menu = new QPEMenuBar( toolbar ); 117 QPEMenuBar *menu = new QPEMenuBar( toolbar );
110 menu->setMargin( 0 ); 118 menu->setMargin( 0 );
111 119
112 QPEToolBar *bar = new QPEToolBar( this ); 120 QPEToolBar *bar = new QPEToolBar( this );
113 bar->setLabel( tr( "Play Operations" ) ); 121 bar->setLabel( tr( "Play Operations" ) );
114#ifdef BUTTONS_ON_TOOLBAR 122 d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ),"mpegplayer/add_to_playlist",this , SLOT(addSelected()) );
115 d->tbPlay = new ToolButton( bar, tr( "Play" ), "mpegplayer/play", mediaPlayerState, SLOT(setPlaying(bool)), TRUE ); 123 d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), "mpegplayer/remove_from_playlist", this , SLOT(removeSelected()) );
116 d->tbShuffle = new ToolButton( bar, tr( "Randomize" ), "mpegplayer/shuffle", mediaPlayerState, SLOT(setShuffled(bool)), TRUE ); 124 d->tbPlay = new ToolButton( bar, tr( "Play" ),"mpegplayer/play", mediaPlayerState, SLOT( setPlaying(bool)), TRUE );
117#endif 125 d->tbShuffle = new ToolButton( bar, tr( "Randomize" ), "mpegplayer/shuffle", mediaPlayerState, SLOT(setShuffled(bool)), TRUE );
118 d->tbLoop = new ToolButton( bar, tr( "Loop" ), "mpegplayer/loop", mediaPlayerState, SLOT(setLooping(bool)), TRUE ); 126 d->tbLoop = new ToolButton( bar, tr( "Loop" ),"mpegplayer/loop", mediaPlayerState, SLOT(setLooping(bool)), TRUE );
119 d->tbFull = new ToolButton( bar, tr( "Fullscreen" ), "fullscreen", mediaPlayerState, SLOT(setFullscreen(bool)), TRUE );
120 d->tbScale = new ToolButton( bar, tr( "Scale" ), "mpegplayer/scale", mediaPlayerState, SLOT(setScaled(bool)), TRUE );
121 127
122 QPopupMenu *pmPlayList = new QPopupMenu( this ); 128 QPopupMenu *pmPlayList = new QPopupMenu( this );
123 menu->insertItem( tr( "PlayList" ), pmPlayList ); 129 menu->insertItem( tr( "File" ), pmPlayList );
124 new MenuItem( pmPlayList, tr( "Toggle PlayList" ), mediaPlayerState, SLOT( togglePlaylist() ) );
125 new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); 130 new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) );
126 new MenuItem( pmPlayList, tr( "Add all music files" ), this, SLOT( addAllMusicToList() ) ); 131 new MenuItem( pmPlayList, tr( "Add all audio files" ), this, SLOT( addAllMusicToList() ) );
127 new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) ); 132 new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) );
128 new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) ); 133 new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) );
129#ifdef CAN_SAVE_LOAD_PLAYLISTS
130 new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) ); 134 new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) );
131 new MenuItem( pmPlayList, tr( "Load PlayList" ), this, SLOT( loadList() ) ); 135 new MenuItem( pmPlayList, tr( "Load PlayList" ), this, SLOT( loadList() ) );
132#endif 136
137 QPopupMenu *pmView = new QPopupMenu( this );
138 menu->insertItem( tr( "View" ), pmView );
139
140 fullScreenButton = new QAction(tr("Full Screen"), Resource::loadPixmap("fullscreen"), QString::null, 0, this, 0);
141 connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) );
142 fullScreenButton->addTo(pmView);
143 scaleButton = new QAction(tr("Scale"), Resource::loadPixmap("mpegplayer/scale"), QString::null, 0, this, 0);
144 connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) );
145 scaleButton->addTo(pmView);
133 146
134 QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton ); 147 QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton );
148 QVBox *vbox4 = new QVBox( vbox5 ); vbox4->setBackgroundMode( PaletteButton );
149
150 QHBox *hbox6 = new QHBox( vbox4 ); hbox6->setBackgroundMode( PaletteButton );
151
152 tabWidget = new QTabWidget( hbox6, "tabWidget" );
153 tabWidget->setTabShape(QTabWidget::Triangular);
154
155 QWidget *pTab;
156 pTab = new QWidget( tabWidget, "pTab" );
157 playlistView = new QListView( pTab, "Videoview" );
158 playlistView->setMinimumSize(236,260);
159 tabWidget->insertTab( pTab,"Playlist");
135 160
136 // Add the playlist area 161 // Add the playlist area
137 QVBox *vbox3 = new QVBox( vbox5 ); vbox3->setBackgroundMode( PaletteButton );
138 d->playListFrame = vbox3;
139 162
140 QLabel *plString = new QLabel( tr(" PlayList"), vbox3 ); 163 QVBox *vbox3 = new QVBox( pTab ); vbox3->setBackgroundMode( PaletteButton );
141 plString->setBackgroundMode( QButton::PaletteButton ); 164 d->playListFrame = vbox3;
142 plString->setFont( QFont( "Helvetica", 8, QFont::Bold ) ); 165 d->playListFrame ->setMinimumSize(235,260);
143 166
144 QHBox *hbox2 = new QHBox( vbox3 ); hbox2->setBackgroundMode( PaletteButton ); 167 QHBox *hbox2 = new QHBox( vbox3 ); hbox2->setBackgroundMode( PaletteButton );
145 d->selectedFiles = new PlayListSelection( hbox2 );
146 QVBox *vbox1 = new QVBox( hbox2 ); vbox1->setBackgroundMode( PaletteButton );
147 168
148#ifndef BUTTONS_ON_TOOLBAR 169 d->selectedFiles = new PlayListSelection( hbox2);
149 d->tbPlay = new ToolButton( vbox1, tr( "Play" ), "mpegplayer/play", mediaPlayerState, SLOT(setPlaying(bool)), TRUE ); 170 QVBox *vbox1 = new QVBox( hbox2 ); vbox1->setBackgroundMode( PaletteButton );
150 QVBox *stretch1 = new QVBox( vbox1 ); stretch1->setBackgroundMode( PaletteButton ); // add stretch
151#endif
152 new ToolButton( vbox1, tr( "Move Up" ), "mpegplayer/up", d->selectedFiles, SLOT(moveSelectedUp()) );
153 new ToolButton( vbox1, tr( "Remove" ), "mpegplayer/cut", d->selectedFiles, SLOT(removeSelected()) );
154 new ToolButton( vbox1, tr( "Move Down" ), "mpegplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) );
155 QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch
156#ifndef BUTTONS_ON_TOOLBAR
157 d->tbShuffle = new ToolButton( vbox1, tr( "Randomize" ), "mpegplayer/shuffle", mediaPlayerState, SLOT(setShuffled(bool)), TRUE );
158#endif
159 171
172 QVBox *stretch1 = new QVBox( vbox1 ); stretch1->setBackgroundMode( PaletteButton ); // add stretch
173 new ToolButton( vbox1, tr( "Move Up" ), "mpegplayer/up", d->selectedFiles, SLOT(moveSelectedUp()) );
174 new ToolButton( vbox1, tr( "Remove" ), "mpegplayer/cut", d->selectedFiles, SLOT(removeSelected()) );
175 new ToolButton( vbox1, tr( "Move Down" ), "mpegplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) );
176 QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch
177
178 QWidget *aTab;
179 aTab = new QWidget( tabWidget, "aTab" );
180 audioView = new QListView( aTab, "Audioview" );
181 audioView->setMinimumSize(233,260);
182 audioView->addColumn( "Title",150);
183 audioView->addColumn("Size", 45);
184 audioView->addColumn("Media",35);
185 audioView->setColumnAlignment(1, Qt::AlignRight);
186 audioView->setColumnAlignment(2, Qt::AlignRight);
187 tabWidget->insertTab(aTab,"Audio");
188// audioView
189 Global::findDocuments(&files, "audio/*");
190 QListIterator<DocLnk> dit( files.children() );
191 QString storage;
192 for ( ; dit.current(); ++dit ) {
193 QListViewItem * newItem;
194 if(dit.current()->file().find("/mnt/cf") != -1 ) storage="CF";
195 else if(dit.current()->file().find("/mnt/hda") != -1 ) storage="CF";
196 else if(dit.current()->file().find("/mnt/card") != -1 ) storage="SD";
197 else storage="RAM";
198 if ( QFile( dit.current()->file()).exists() ) {
199 newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), QString::number( QFile( dit.current()->file()).size() ), storage);
200 newItem->setPixmap(0, Resource::loadPixmap( "mpegplayer/musicfile" ));
201 }
202 }
203// videowidget
204
205 QWidget *vTab;
206 vTab = new QWidget( tabWidget, "vTab" );
207 videoView = new QListView( vTab, "Videoview" );
208 videoView->setMinimumSize(233,260);
209
210 videoView->addColumn("Title",150);
211 videoView->addColumn("Size",45);
212 videoView->addColumn("Media",35);
213 videoView->setColumnAlignment(1, Qt::AlignRight);
214 videoView->setColumnAlignment(2, Qt::AlignRight);
215
216 tabWidget->insertTab( vTab,"Video");
217
218 Global::findDocuments(&vFiles, "video/*");
219 QListIterator<DocLnk> Vdit( vFiles.children() );
220 for ( ; Vdit.current(); ++Vdit ) {
221 if( Vdit.current()->file().find("/mnt/cf") != -1 ) storage="CF";
222 else if( Vdit.current()->file().find("/mnt/hda") != -1 ) storage="CF";
223 else if( Vdit.current()->file().find("/mnt/card") != -1 ) storage="SD";
224 else storage="RAM";
225 QListViewItem * newItem;
226 if ( QFile( Vdit.current()->file()).exists() ) {
227 newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), QString::number( QFile( Vdit.current()->file()).size() ), storage);
228 newItem->setPixmap(0, Resource::loadPixmap( "mpegplayer/videofile" ));
229 }
230 }
160 // add the library area 231 // add the library area
161 QVBox *vbox4 = new QVBox( vbox5 ); vbox4->setBackgroundMode( PaletteButton ); 232 QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold );
162 233
163 QLabel *libString = new QLabel( tr(" Media Library"), vbox4 ); 234// connect( audioView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) );
164 libString->setBackgroundMode( QButton::PaletteButton ); 235// connect( videoView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) );
165 libString->setFont( QFont( "Helvetica", 8, QFont::Bold ) );
166 236
167 QHBox *hbox6 = new QHBox( vbox4 ); hbox6->setBackgroundMode( PaletteButton ); 237 connect( audioView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) );
168 d->files = new FileSelector( "video/*;audio/*", hbox6, "Find Media Files", FALSE, FALSE ); 238 connect( videoView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) );
169 d->files->setBackgroundMode( PaletteButton ); 239
170 QVBox *vbox7 = new QVBox( hbox6 ); vbox7->setBackgroundMode( PaletteButton ); 240 connect( audioView, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint&, int ) ),
241 this, SLOT( addToSelection( QListViewItem *, const QPoint&, int )) );
242 connect( videoView, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint&, int ) ),
243 this, SLOT( addToSelection( QListViewItem *, const QPoint&, int )) );
171 244
172#ifdef SIDE_BUTTONS
173 new ToolButton( vbox7, tr( "Add to Playlist" ), "mpegplayer/add_to_playlist", d->selectedFiles, SLOT(addSelected()) );
174 new ToolButton( vbox7, tr( "Remove from Playlist" ), "mpegplayer/remove_from_playlist", d->selectedFiles, SLOT(removeSelected()) );
175 QVBox *stretch3 = new QVBox( vbox1 ); stretch3->setBackgroundMode( PaletteButton ); // add stretch
176#endif
177 245
178 connect( d->files, SIGNAL( fileSelected( const DocLnk & ) ), this, SLOT( addToSelection( const DocLnk & ) ) ); 246 connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*)));
247 // connect( d->files, SIGNAL( fileSelected( const DocLnk & ) ), this, SLOT( addToSelection( const DocLnk & ) ) );
248 // connect( d->files, SIGNAL( fileSelected( const DocLnk & ) ), this, SLOT( addToSelection( const DocLnk & ) ) );
179 connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) ); 249 connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) );
180 connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) ); 250 connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) );
181 connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) ); 251 connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) );
182 connect( mediaPlayerState, SIGNAL( fullscreenToggled( bool ) ), d->tbFull, SLOT( setOn( bool ) ) ); 252
183 connect( mediaPlayerState, SIGNAL( scaledToggled( bool ) ), d->tbScale, SLOT( setOn( bool ) ) ); 253// connect( mediaPlayerState, SIGNAL( fullscreenToggled( bool ) ), fullScreenButton, SLOT( setOn( bool ) ) );
184 connect( mediaPlayerState, SIGNAL( fullscreenToggled( bool ) ), d->tbScale, SLOT( setEnabled( bool ) ) ); 254// connect( mediaPlayerState, SIGNAL( scaledToggled( bool ) ), scaleButton, SLOT( setEnabled( bool ) ) );
255// connect( mediaPlayerState, SIGNAL( fullscreenToggled( bool ) ), fullScreenButton, SLOT( setEnabled( bool ) ) );
256
185 connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) ); 257 connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) );
186 258
259 connect( d->selectedFiles, SIGNAL( clicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) );
260// connect( d->selectedFiles, SIGNAL( fileSelected( const DocLnk & ) ), this, SLOT( addToSelection( const DocLnk & ) ) );
261
187 setCentralWidget( vbox5 ); 262 setCentralWidget( vbox5 );
188 263
189 Config cfg( "MediaPlayer" ); 264 Config cfg( "MediaPlayer" );
190 readConfig( cfg ); 265 readConfig( cfg );
191 266
192 initializeStates(); 267 initializeStates();
193} 268}
194 269
195 270
196PlayListWidget::~PlayListWidget() { 271PlayListWidget::~PlayListWidget() {
197 Config cfg( "MediaPlayer" ); 272 Config cfg( "MediaPlayer" );
198 writeConfig( cfg ); 273 writeConfig( cfg );
199 274
200 if ( d->current ) 275 if ( d->current )
201 delete d->current; 276 delete d->current;
202 delete d; 277 delete d;
203} 278}
204 279
205 280
206void PlayListWidget::initializeStates() { 281void PlayListWidget::initializeStates() {
282
207 d->tbPlay->setOn( mediaPlayerState->playing() ); 283 d->tbPlay->setOn( mediaPlayerState->playing() );
208 d->tbLoop->setOn( mediaPlayerState->looping() ); 284 d->tbLoop->setOn( mediaPlayerState->looping() );
209 d->tbShuffle->setOn( mediaPlayerState->shuffled() ); 285 d->tbShuffle->setOn( mediaPlayerState->shuffled() );
210 d->tbFull->setOn( mediaPlayerState->fullscreen() ); 286// d->tbFull->setOn( mediaPlayerState->fullscreen() );
211 d->tbScale->setOn( mediaPlayerState->scaled() ); 287// d->tbScale->setOn( mediaPlayerState->scaled() );
212 d->tbScale->setEnabled( mediaPlayerState->fullscreen() ); 288// d->tbScale->setEnabled( mediaPlayerState->fullscreen() );
213 setPlaylist( mediaPlayerState->playlist() ); 289// setPlaylist( mediaPlayerState->playlist() );
214} 290}
215 291
216 292
217void PlayListWidget::readConfig( Config& cfg ) { 293void PlayListWidget::readConfig( Config& cfg ) {
218 cfg.setGroup("PlayList"); 294 cfg.setGroup("PlayList");
219 295
220 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 296 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
221 297
222 for ( int i = 0; i < noOfFiles; i++ ) { 298 for ( int i = 0; i < noOfFiles; i++ ) {
223 QString entryName; 299 QString entryName;
224 entryName.sprintf( "File%i", i + 1 ); 300 entryName.sprintf( "File%i", i + 1 );
225 QString linkFile = cfg.readEntry( entryName ); 301 QString linkFile = cfg.readEntry( entryName );
226 DocLnk lnk( linkFile ); 302 DocLnk lnk( linkFile );
227 if ( lnk.isValid() ) 303 if ( lnk.isValid() )
228 d->selectedFiles->addToSelection( lnk ); 304 d->selectedFiles->addToSelection( lnk );
229 305
230 } 306 }
231} 307}
232 308
233 309
234void PlayListWidget::writeConfig( Config& cfg ) const { 310void PlayListWidget::writeConfig( Config& cfg ) const {
235 cfg.setGroup("PlayList"); 311 cfg.setGroup("PlayList");
236 312
237 int noOfFiles = 0; 313 int noOfFiles = 0;
238 314
239 d->selectedFiles->first(); 315 d->selectedFiles->first();
240 do { 316 do {
241 const DocLnk *lnk = d->selectedFiles->current(); 317 const DocLnk *lnk = d->selectedFiles->current();
242 if ( lnk ) { 318 if ( lnk ) {
243 QString entryName; 319 QString entryName;
244 entryName.sprintf( "File%i", noOfFiles + 1 ); 320 entryName.sprintf( "File%i", noOfFiles + 1 );
245 cfg.writeEntry( entryName, lnk->linkFile() ); 321 cfg.writeEntry( entryName, lnk->linkFile() );
246 // if this link does exist, add it so we have the file 322 // if this link does exist, add it so we have the file
247 // next time... 323 // next time...
248 if ( !QFile::exists( lnk->linkFile() ) ) { 324 if ( !QFile::exists( lnk->linkFile() ) ) {
249 // the way writing lnks doesn't really check for out 325 // the way writing lnks doesn't really check for out
250 // of disk space, but check it anyway. 326 // of disk space, but check it anyway.
251 if ( !lnk->writeLink() ) { 327 if ( !lnk->writeLink() ) {
252 QMessageBox::critical( 0, tr("Out of space"), 328 QMessageBox::critical( 0, tr("Out of space"),
253 tr( "There was a problem saving " 329 tr( "There was a problem saving "
254 "the playlist.\n" 330 "the playlist.\n"
255 "Your playlist " 331 "Your playlist "
256 "may be missing some entries\n" 332 "may be missing some entries\n"
257 "the next time you start it." ) 333 "the next time you start it." )
258 ); 334 );
259 } 335 }
260 } 336 }
261 noOfFiles++; 337 noOfFiles++;
262 } 338 }
263 } while ( d->selectedFiles->next() ); 339 } while ( d->selectedFiles->next() );
264 340
265 cfg.writeEntry("NumberOfFiles", noOfFiles ); 341 cfg.writeEntry("NumberOfFiles", noOfFiles );
266} 342}
267 343
268 344
269void PlayListWidget::addToSelection( const DocLnk& lnk ) { 345void PlayListWidget::addToSelection( const DocLnk& lnk ) {
270 d->setDocumentUsed = FALSE; 346 d->setDocumentUsed = FALSE;
271 if ( mediaPlayerState->playlist() ) 347 if ( mediaPlayerState->playlist() )
272 d->selectedFiles->addToSelection( lnk ); 348 d->selectedFiles->addToSelection( lnk );
273 else 349 else
274 mediaPlayerState->setPlaying( TRUE ); 350 mediaPlayerState->setPlaying( TRUE );
351}
352
353
354void PlayListWidget::addToSelection( QListViewItem *it ,const QPoint & p, int index) {
355 qDebug("add");
356// d->selectedFiles->addToSelection( lnk );
357 // }
358// else
359// mediaPlayerState->setPlaying( TRUE );
360//
275} 361}
276 362
277 363
278void PlayListWidget::clearList() { 364void PlayListWidget::clearList() {
279 while ( first() ) 365 while ( first() )
280 d->selectedFiles->removeSelected(); 366 d->selectedFiles->removeSelected();
281} 367}
282 368
283 369
284void PlayListWidget::addAllToList() { 370void PlayListWidget::addAllToList() {
285 DocLnkSet files; 371 DocLnkSet files;
286 Global::findDocuments(&files, "video/*;audio/*"); 372 Global::findDocuments(&files, "video/*;audio/*");
287 QListIterator<DocLnk> dit( files.children() ); 373 QListIterator<DocLnk> dit( files.children() );
288 for ( ; dit.current(); ++dit ) 374 for ( ; dit.current(); ++dit )
289 d->selectedFiles->addToSelection( **dit ); 375 d->selectedFiles->addToSelection( **dit );
290} 376}
291 377
292 378
293void PlayListWidget::addAllMusicToList() { 379void PlayListWidget::addAllMusicToList() {
294 DocLnkSet files; 380 DocLnkSet files;
295 Global::findDocuments(&files, "audio/*"); 381 Global::findDocuments(&files, "audio/*");
296 QListIterator<DocLnk> dit( files.children() ); 382 QListIterator<DocLnk> dit( files.children() );
297 for ( ; dit.current(); ++dit ) 383 for ( ; dit.current(); ++dit )
298 d->selectedFiles->addToSelection( **dit ); 384 d->selectedFiles->addToSelection( **dit );
299} 385}
300 386
301 387
302void PlayListWidget::addAllVideoToList() { 388void PlayListWidget::addAllVideoToList() {
303 DocLnkSet files; 389 DocLnkSet files;
304 Global::findDocuments(&files, "video/*"); 390 Global::findDocuments(&files, "video/*");
305 QListIterator<DocLnk> dit( files.children() ); 391 QListIterator<DocLnk> dit( files.children() );
306 for ( ; dit.current(); ++dit ) 392 for ( ; dit.current(); ++dit )
307 d->selectedFiles->addToSelection( **dit ); 393 d->selectedFiles->addToSelection( **dit );
308} 394}
309 395
310 396
311void PlayListWidget::setDocument(const QString& fileref) { 397void PlayListWidget::setDocument(const QString& fileref) {
312 if ( fileref.isNull() ) { 398 if ( fileref.isNull() ) {
313 QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) ); 399 QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) );
314 return; 400 return;
315 } 401 }
316 if ( mediaPlayerState->playlist() ) 402 if ( mediaPlayerState->playlist() )
317 addToSelection( DocLnk( fileref ) ); 403 addToSelection( DocLnk( fileref ) );
318 else { 404 else {
319 d->setDocumentUsed = TRUE; 405 d->setDocumentUsed = TRUE;
320 if ( d->current ) 406 if ( d->current )
321 delete d->current; 407 delete d->current;
322 d->current = new DocLnk( fileref ); 408 d->current = new DocLnk( fileref );
323 } 409 }
324 mediaPlayerState->setPlaying( FALSE ); 410 mediaPlayerState->setPlaying( FALSE );
325 mediaPlayerState->setPlaying( TRUE ); 411 mediaPlayerState->setPlaying( TRUE );
326} 412}
327 413
328 414
329void PlayListWidget::setActiveWindow() { 415void PlayListWidget::setActiveWindow() {
330 // When we get raised we need to ensure that it switches views 416 // When we get raised we need to ensure that it switches views
331 char origView = mediaPlayerState->view(); 417 char origView = mediaPlayerState->view();
332 mediaPlayerState->setView( 'l' ); // invalidate 418 mediaPlayerState->setView( 'l' ); // invalidate
333 mediaPlayerState->setView( origView ); // now switch back 419 mediaPlayerState->setView( origView ); // now switch back
334} 420}
335 421
336 422
337void PlayListWidget::useSelectedDocument() { 423void PlayListWidget::useSelectedDocument() {
338 d->setDocumentUsed = FALSE; 424 d->setDocumentUsed = FALSE;
339} 425}
340 426
341 427
342const DocLnk *PlayListWidget::current() { 428const DocLnk *PlayListWidget::current() {
343 if ( mediaPlayerState->playlist() ) 429 if ( mediaPlayerState->playlist() )
344 return d->selectedFiles->current(); 430 return d->selectedFiles->current();
345 else if ( d->setDocumentUsed && d->current ) { 431 else if ( d->setDocumentUsed && d->current ) {
346 return d->current; 432 return d->current;
347 } else 433 } else
348 return d->files->selected(); 434 return d->files->selected();
349} 435}
350 436
351 437
352bool PlayListWidget::prev() { 438bool PlayListWidget::prev() {
353 if ( mediaPlayerState->playlist() ) { 439 if ( mediaPlayerState->playlist() ) {
354 if ( mediaPlayerState->shuffled() ) { 440 if ( mediaPlayerState->shuffled() ) {
355 const DocLnk *cur = current(); 441 const DocLnk *cur = current();
356 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); 442 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0));
357 for ( int i = 0; i < j; i++ ) { 443 for ( int i = 0; i < j; i++ ) {
358 if ( !d->selectedFiles->next() ) 444 if ( !d->selectedFiles->next() )
359 d->selectedFiles->first(); 445 d->selectedFiles->first();
360 } 446 }
361 if ( cur == current() ) 447 if ( cur == current() )
362 if ( !d->selectedFiles->next() ) 448 if ( !d->selectedFiles->next() )
363 d->selectedFiles->first(); 449 d->selectedFiles->first();
364 return TRUE; 450 return TRUE;
365 } else { 451 } else {
366 if ( !d->selectedFiles->prev() ) { 452 if ( !d->selectedFiles->prev() ) {
367 if ( mediaPlayerState->looping() ) { 453 if ( mediaPlayerState->looping() ) {
368 return d->selectedFiles->last(); 454 return d->selectedFiles->last();
369 } else { 455 } else {
370 return FALSE; 456 return FALSE;
371 } 457 }
372 } 458 }
373 return TRUE; 459 return TRUE;
374 } 460 }
375 } else { 461 } else {
376 return mediaPlayerState->looping(); 462 return mediaPlayerState->looping();
377 } 463 }
378} 464}
379 465
380 466
381bool PlayListWidget::next() { 467bool PlayListWidget::next() {
382 if ( mediaPlayerState->playlist() ) { 468 if ( mediaPlayerState->playlist() ) {
383 if ( mediaPlayerState->shuffled() ) { 469 if ( mediaPlayerState->shuffled() ) {
384 return prev(); 470 return prev();
385 } else { 471 } else {
386 if ( !d->selectedFiles->next() ) { 472 if ( !d->selectedFiles->next() ) {
387 if ( mediaPlayerState->looping() ) { 473 if ( mediaPlayerState->looping() ) {
388 return d->selectedFiles->first(); 474 return d->selectedFiles->first();
389 } else { 475 } else {
390 return FALSE; 476 return FALSE;
391 } 477 }
392 } 478 }
393 return TRUE; 479 return TRUE;
394 } 480 }
395 } else { 481 } else {
396 return mediaPlayerState->looping(); 482 return mediaPlayerState->looping();
397 } 483 }
398} 484}
399 485
400 486
401bool PlayListWidget::first() { 487bool PlayListWidget::first() {
402 if ( mediaPlayerState->playlist() ) 488 if ( mediaPlayerState->playlist() )
403 return d->selectedFiles->first(); 489 return d->selectedFiles->first();
404 else 490 else
405 return mediaPlayerState->looping(); 491 return mediaPlayerState->looping();
406} 492}
407 493
408 494
409bool PlayListWidget::last() { 495bool PlayListWidget::last() {
410 if ( mediaPlayerState->playlist() ) 496 if ( mediaPlayerState->playlist() )
411 return d->selectedFiles->last(); 497 return d->selectedFiles->last();
412 else 498 else
413 return mediaPlayerState->looping(); 499 return mediaPlayerState->looping();
414} 500}
415 501
416 502
417void PlayListWidget::saveList() { 503void PlayListWidget::saveList() {
418 QString filename; 504 QString filename;
419// pseudo code 505// pseudo code
420// filename = QLineEdit->getText(); 506// filename = QLineEdit->getText();
421 Config cfg( filename + ".playlist" ); 507 Config cfg( filename + ".playlist" );
422 writeConfig( cfg ); 508 writeConfig( cfg );
423} 509}
424 510
425 511
426void PlayListWidget::loadList() { 512void PlayListWidget::loadList() {
427 QString filename; 513 QString filename;
428// pseudo code 514// pseudo code
429// filename = FileSelector->openFile( "*.playlist" ); 515// filename = FileSelector->openFile( "*.playlist" );
430 Config cfg( filename + ".playlist" ); 516 Config cfg( filename + ".playlist" );
431 readConfig( cfg ); 517 readConfig( cfg );
432} 518}
433 519
434 520
435void PlayListWidget::setPlaylist( bool shown ) { 521void PlayListWidget::setPlaylist( bool shown ) {
436 if ( shown ) 522 if ( shown )
437 d->playListFrame->show(); 523 d->playListFrame->show();
438 else 524 else
439 d->playListFrame->hide(); 525 d->playListFrame->hide();
440} 526}
441 527
442 528
443void PlayListWidget::setView( char view ) { 529void PlayListWidget::setView( char view ) {
444 if ( view == 'l' ) 530 if ( view == 'l' )
445 showMaximized(); 531 showMaximized();
446 else 532 else
447 hide(); 533 hide();
534}
535
536void PlayListWidget::addSelected() {
537// QMessageBox::message("Note","Bozo the clown thinks\nthere's something actually here");
538 int tabPage=tabWidget->currentPageIndex();
539 switch (tabPage) {
540 case 0: //playlist
541 break;
542 case 1: { //audio
543 addToSelection( audioView->selectedItem() );
544 }
545 break;
546 case 2: { // video
547 addToSelection( videoView->selectedItem() );
548 }
549 break;
550 };
551}
552
553void PlayListWidget::removeSelected() {
554 d->selectedFiles->removeSelected( );
555}
556
557
558void PlayListWidget::playIt( QListViewItem *it) {
559// d->setDocumentUsed = FALSE;
560 mediaPlayerState->setPlaying(true);
561}
562
563void PlayListWidget::addToSelection( QListViewItem *it) {
564 d->setDocumentUsed = FALSE;
565
566 if(it) {
567 qDebug("add to selection");
568 int tabPage=tabWidget->currentPageIndex();
569 switch (tabPage) {
570 case 1: {
571 QListIterator<DocLnk> dit( files.children() );
572 for ( ; dit.current(); ++dit ) {
573 if( dit.current()->name() == it->text(0)) {
574 d->selectedFiles->addToSelection( **dit );
575 }
576 }
577 }
578 break;
579 case 2: {
580 QListIterator<DocLnk> dit( vFiles.children() );
581 for ( ; dit.current(); ++dit ) {
582 qDebug(dit.current()->name());
583 if( dit.current()->name() == it->text(0)) {
584 d->selectedFiles->addToSelection( **dit );
585 }
586 }
587 }
588 break;
589 case 0:
590 break;
591 };
592 tabWidget->setCurrentPage(0);
593// mediaPlayerState->setPlaying( TRUE );
594 }
595}
596
597void PlayListWidget::tabChanged(QWidget *widg) {
598
599 int tabPage=tabWidget->currentPageIndex();
600 switch (tabPage) {
601 case 0:
602 {
603 d->tbRemoveFromList->setEnabled(TRUE);
604 d->tbAddToList->setEnabled(FALSE);
605 }
606 break;
607 case 1:
608 {
609 d->tbRemoveFromList->setEnabled(FALSE);
610 d->tbAddToList->setEnabled(TRUE);
611 }
612 break;
613 case 2:
614 {
615 d->tbRemoveFromList->setEnabled(FALSE);
616 d->tbAddToList->setEnabled(TRUE);
617 }
618 break;
619 };
448} 620}
449 621
622// void PlayListWidget::cancelMenuTimer() {
623// if( menuTimer->isActive() )
624// menuTimer->stop();
625// }
626
627// void PlayListWidget::showFileMenu() {
628
629// }
630
631// void PlayListWidget::contentsMousePressEvent( QMouseEvent * e )
632// {
633// // QListView::contentsMousePressEvent( e );
634// menuTimer->start( 750, TRUE );
635// }
636
637
638// void PlayListWidget::contentsMouseReleaseEvent( QMouseEvent * e )
639// {
640// // QListView::contentsMouseReleaseEvent( e );
641// menuTimer->stop();
642// }
643// // void PlayListWidget::setFullScreen() {
644// mediaPlayerState->toggleFullscreen( );
645// }
646
647// void PlayListWidget::setScaled() {
648// mediaPlayerState->toggleScaled();
649// }
diff --git a/core/multimedia/opieplayer/playlistwidget.h b/core/multimedia/opieplayer/playlistwidget.h
index 819adb1..5b05f11 100644
--- a/core/multimedia/opieplayer/playlistwidget.h
+++ b/core/multimedia/opieplayer/playlistwidget.h
@@ -1,67 +1,96 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef PLAY_LIST_WIDGET_H 20#ifndef PLAY_LIST_WIDGET_H
21#define PLAY_LIST_WIDGET_H 21#define PLAY_LIST_WIDGET_H
22 22
23#include <qmainwindow.h> 23#include <qmainwindow.h>
24#include <qpe/applnk.h> 24#include <qpe/applnk.h>
25#include <qtabwidget.h>
26/* #include <qtimer.h> */
25 27
26 28
27class PlayListWidgetPrivate; 29class PlayListWidgetPrivate;
28class Config; 30class Config;
29 31class QListViewItem;
32class QListView;
33class QPoint;
34class QAction;
35class QLabel;
30 36
31class PlayListWidget : public QMainWindow { 37class PlayListWidget : public QMainWindow {
32 Q_OBJECT 38 Q_OBJECT
33public: 39public:
34 PlayListWidget( QWidget* parent=0, const char* name=0, WFlags fl=0 ); 40 PlayListWidget( QWidget* parent=0, const char* name=0, WFlags fl=0 );
35 ~PlayListWidget(); 41 ~PlayListWidget();
36 42 QTabWidget * tabWidget;
43 QAction *fullScreenButton, *scaleButton;
44 DocLnkSet files;
45 DocLnkSet vFiles;
46 QListView *audioView, *videoView, *playlistView;
47 QLabel *libString;
37 // retrieve the current playlist entry (media file link) 48 // retrieve the current playlist entry (media file link)
38 const DocLnk *current(); 49 const DocLnk *current();
39 void useSelectedDocument(); 50 void useSelectedDocument();
51/* QTimer * menuTimer; */
40 52
41public slots: 53public slots:
42 void setDocument( const QString& fileref ); 54 void setDocument( const QString& fileref );
43 void addToSelection( const DocLnk& ); // Add a media file to the playlist 55 void addToSelection( const DocLnk& ); // Add a media file to the playlist
56 void addToSelection( QListViewItem* ); // Add a media file to the playlist
57 void addToSelection( QListViewItem*, const QPoint&,int ); // Add a media file to the playlist
44 void setActiveWindow(); // need to handle this to show the right view 58 void setActiveWindow(); // need to handle this to show the right view
45 void setPlaylist( bool ); // Show/Hide the playlist 59 void setPlaylist( bool ); // Show/Hide the playlist
46 void setView( char ); 60 void setView( char );
47 void clearList(); 61 void clearList();
48 void addAllToList(); 62 void addAllToList();
49 void addAllMusicToList(); 63 void addAllMusicToList();
50 void addAllVideoToList(); 64 void addAllVideoToList();
51 void saveList(); // Save the playlist 65 void saveList(); // Save the playlist
52 void loadList(); // Load a playlist 66 void loadList(); // Load a playlist
67 void playIt( QListViewItem *);
53 bool first(); 68 bool first();
54 bool last(); 69 bool last();
55 bool next(); 70 bool next();
56 bool prev(); 71 bool prev();
72 void addSelected();
73 void removeSelected();
74 void tabChanged(QWidget*);
75/* void setFullScreen(); */
76/* void setScaled(); */
77protected:
78/* void contentsMousePressEvent( QMouseEvent * e ); */
79/* void contentsMouseReleaseEvent( QMouseEvent * e ); */
57 80
58private: 81private:
59 void initializeStates(); 82 void initializeStates();
60 void readConfig( Config& cfg ); 83 void readConfig( Config& cfg );
61 void writeConfig( Config& cfg ) const; 84 void writeConfig( Config& cfg ) const;
62 PlayListWidgetPrivate *d; // Private implementation data 85 PlayListWidgetPrivate *d; // Private implementation data
86
87protected slots:
88/* void cancelMenuTimer(); */
89/* void showFileMenu(); */
90
91
63}; 92};
64 93
65 94
66#endif // PLAY_LIST_WIDGET_H 95#endif // PLAY_LIST_WIDGET_H
67 96
diff --git a/core/multimedia/opieplayer/videowidget.cpp b/core/multimedia/opieplayer/videowidget.cpp
index 12ae4fd..1f128a4 100644
--- a/core/multimedia/opieplayer/videowidget.cpp
+++ b/core/multimedia/opieplayer/videowidget.cpp
@@ -1,424 +1,423 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20
21#include <qpe/resource.h> 20#include <qpe/resource.h>
22#include <qpe/mediaplayerplugininterface.h> 21#include "mediaplayerplugininterface.h"
23#include <qwidget.h> 22#include <qwidget.h>
24#include <qpainter.h> 23#include <qpainter.h>
25#include <qpixmap.h> 24#include <qpixmap.h>
26#include <qslider.h> 25#include <qslider.h>
27#include <qdrawutil.h> 26#include <qdrawutil.h>
28#include "videowidget.h" 27#include "videowidget.h"
29#include "mediaplayerstate.h" 28#include "mediaplayerstate.h"
30 29
31 30
32#ifdef Q_WS_QWS 31#ifdef Q_WS_QWS
33# define USE_DIRECT_PAINTER 32# define USE_DIRECT_PAINTER
34# include <qdirectpainter_qws.h> 33# include <qdirectpainter_qws.h>
35# include <qgfxraster_qws.h> 34# include <qgfxraster_qws.h>
36#endif 35#endif
37 36
38 37
39extern MediaPlayerState *mediaPlayerState; 38extern MediaPlayerState *mediaPlayerState;
40 39
41 40
42static const int xo = 2; // movable x offset 41static const int xo = 2; // movable x offset
43static const int yo = 0; // movable y offset 42static const int yo = 0; // movable y offset
44 43
45 44
46struct MediaButton { 45struct MediaButton {
47 int xPos, yPos; 46 int xPos, yPos;
48 bool isToggle, isHeld, isDown; 47 bool isToggle, isHeld, isDown;
49 int controlType; 48 int controlType;
50}; 49};
51 50
52 51
53// Layout information for the videoButtons (and if it is a toggle button or not) 52// Layout information for the videoButtons (and if it is a toggle button or not)
54MediaButton videoButtons[] = { 53MediaButton videoButtons[] = {
55 { 5+0*32+xo, 200+yo, FALSE, FALSE, FALSE, 4 }, // previous 54 { 5+0*32+xo, 200+yo, FALSE, FALSE, FALSE, 4 }, // previous
56 { 5+1*32+xo, 200+yo, FALSE, FALSE, FALSE, 1 }, // stop 55 { 5+1*32+xo, 200+yo, FALSE, FALSE, FALSE, 1 }, // stop
57 { 5+2*32+xo, 200+yo, TRUE, FALSE, FALSE, 0 }, // play 56 { 5+2*32+xo, 200+yo, TRUE, FALSE, FALSE, 0 }, // play
58 { 5+3*32+xo, 200+yo, TRUE, FALSE, FALSE, 2 }, // pause 57 { 5+3*32+xo, 200+yo, TRUE, FALSE, FALSE, 2 }, // pause
59 { 5+4*32+xo, 200+yo, FALSE, FALSE, FALSE, 3 }, // next 58 { 5+4*32+xo, 200+yo, FALSE, FALSE, FALSE, 3 }, // next
60 { 5+5*32+xo, 200+yo, FALSE, FALSE, FALSE, 8 }, // playlist 59 { 5+5*32+xo, 200+yo, FALSE, FALSE, FALSE, 8 }, // playlist
61 { 5+6*32+xo, 200+yo, TRUE, FALSE, FALSE, 9 } // fullscreen 60 { 5+6*32+xo, 200+yo, TRUE, FALSE, FALSE, 9 } // fullscreen
62}; 61};
63 62
64 63
65static const int numButtons = (sizeof(videoButtons)/sizeof(MediaButton)); 64static const int numButtons = (sizeof(videoButtons)/sizeof(MediaButton));
66 65
67 66
68VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) : 67VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) :
69 QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 ) { 68 QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 ) {
70 setCaption( tr("MediaPlayer") ); 69 setCaption( tr("OpiePlayer") );
71 setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); 70 setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) );
72 pixmaps[0] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButton0a" ) ); 71 pixmaps[0] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButton0a" ) );
73 pixmaps[1] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButton0b" ) ); 72 pixmaps[1] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButton0b" ) );
74 pixmaps[2] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaControls0" ) ); 73 pixmaps[2] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaControls0" ) );
75 currentFrame = new QImage( 220 + 2, 160, (QPixmap::defaultDepth() == 16) ? 16 : 32 ); 74 currentFrame = new QImage( 220 + 2, 160, (QPixmap::defaultDepth() == 16) ? 16 : 32 );
76 75
77 slider = new QSlider( Qt::Horizontal, this ); 76 slider = new QSlider( Qt::Horizontal, this );
78 slider->setMinValue( 0 ); 77 slider->setMinValue( 0 );
79 slider->setMaxValue( 1 ); 78 slider->setMaxValue( 1 );
80 slider->setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); 79 slider->setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) );
81 slider->setFocusPolicy( QWidget::NoFocus ); 80 slider->setFocusPolicy( QWidget::NoFocus );
82 slider->setGeometry( QRect( 7, 250, 220, 20 ) ); 81 slider->setGeometry( QRect( 7, 250, 220, 20 ) );
83 82
84 connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 83 connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
85 connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 84 connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
86 85
87 connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); 86 connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) );
88 connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 87 connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
89 connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 88 connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
90 connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); 89 connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) );
91 connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); 90 connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) );
92 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); 91 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) );
93 92
94 // Intialise state 93 // Intialise state
95 setLength( mediaPlayerState->length() ); 94 setLength( mediaPlayerState->length() );
96 setPosition( mediaPlayerState->position() ); 95 setPosition( mediaPlayerState->position() );
97 setFullscreen( mediaPlayerState->fullscreen() ); 96 setFullscreen( mediaPlayerState->fullscreen() );
98 setPaused( mediaPlayerState->paused() ); 97 setPaused( mediaPlayerState->paused() );
99 setPlaying( mediaPlayerState->playing() ); 98 setPlaying( mediaPlayerState->playing() );
100} 99}
101 100
102 101
103VideoWidget::~VideoWidget() { 102VideoWidget::~VideoWidget() {
104 for ( int i = 0; i < 3; i++ ) 103 for ( int i = 0; i < 3; i++ )
105 delete pixmaps[i]; 104 delete pixmaps[i];
106 delete currentFrame; 105 delete currentFrame;
107} 106}
108 107
109 108
110static bool videoSliderBeingMoved = FALSE; 109static bool videoSliderBeingMoved = FALSE;
111 110
112 111
113void VideoWidget::sliderPressed() { 112void VideoWidget::sliderPressed() {
114 videoSliderBeingMoved = TRUE; 113 videoSliderBeingMoved = TRUE;
115} 114}
116 115
117 116
118void VideoWidget::sliderReleased() { 117void VideoWidget::sliderReleased() {
119 videoSliderBeingMoved = FALSE; 118 videoSliderBeingMoved = FALSE;
120 if ( slider->width() == 0 ) 119 if ( slider->width() == 0 )
121 return; 120 return;
122 long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); 121 long val = long((double)slider->value() * mediaPlayerState->length() / slider->width());
123 mediaPlayerState->setPosition( val ); 122 mediaPlayerState->setPosition( val );
124} 123}
125 124
126 125
127void VideoWidget::setPosition( long i ) { 126void VideoWidget::setPosition( long i ) {
128 updateSlider( i, mediaPlayerState->length() ); 127 updateSlider( i, mediaPlayerState->length() );
129} 128}
130 129
131 130
132void VideoWidget::setLength( long max ) { 131void VideoWidget::setLength( long max ) {
133 updateSlider( mediaPlayerState->position(), max ); 132 updateSlider( mediaPlayerState->position(), max );
134} 133}
135 134
136 135
137void VideoWidget::setView( char view ) { 136void VideoWidget::setView( char view ) {
138 if ( view == 'v' ) { 137 if ( view == 'v' ) {
139 makeVisible(); 138 makeVisible();
140 } else { 139 } else {
141 // Effectively blank the view next time we show it so it looks nicer 140 // Effectively blank the view next time we show it so it looks nicer
142 scaledWidth = 0; 141 scaledWidth = 0;
143 scaledHeight = 0; 142 scaledHeight = 0;
144 hide(); 143 hide();
145 } 144 }
146} 145}
147 146
148 147
149void VideoWidget::updateSlider( long i, long max ) { 148void VideoWidget::updateSlider( long i, long max ) {
150 // Will flicker too much if we don't do this 149 // Will flicker too much if we don't do this
151 if ( max == 0 ) 150 if ( max == 0 )
152 return; 151 return;
153 int width = slider->width(); 152 int width = slider->width();
154 int val = int((double)i * width / max); 153 int val = int((double)i * width / max);
155 if ( !mediaPlayerState->fullscreen() && !videoSliderBeingMoved ) { 154 if ( !mediaPlayerState->fullscreen() && !videoSliderBeingMoved ) {
156 if ( slider->value() != val ) 155 if ( slider->value() != val )
157 slider->setValue( val ); 156 slider->setValue( val );
158 if ( slider->maxValue() != width ) 157 if ( slider->maxValue() != width )
159 slider->setMaxValue( width ); 158 slider->setMaxValue( width );
160 } 159 }
161} 160}
162 161
163 162
164void VideoWidget::setToggleButton( int i, bool down ) { 163void VideoWidget::setToggleButton( int i, bool down ) {
165 if ( down != videoButtons[i].isDown ) 164 if ( down != videoButtons[i].isDown )
166 toggleButton( i ); 165 toggleButton( i );
167} 166}
168 167
169 168
170void VideoWidget::toggleButton( int i ) { 169void VideoWidget::toggleButton( int i ) {
171 videoButtons[i].isDown = !videoButtons[i].isDown; 170 videoButtons[i].isDown = !videoButtons[i].isDown;
172 QPainter p(this); 171 QPainter p(this);
173 paintButton ( &p, i ); 172 paintButton ( &p, i );
174} 173}
175 174
176 175
177void VideoWidget::paintButton( QPainter *p, int i ) { 176void VideoWidget::paintButton( QPainter *p, int i ) {
178 int x = videoButtons[i].xPos; 177 int x = videoButtons[i].xPos;
179 int y = videoButtons[i].yPos; 178 int y = videoButtons[i].yPos;
180 int offset = 10 + videoButtons[i].isDown; 179 int offset = 10 + videoButtons[i].isDown;
181 p->drawPixmap( x, y, *pixmaps[videoButtons[i].isDown] ); 180 p->drawPixmap( x, y, *pixmaps[videoButtons[i].isDown] );
182 p->drawPixmap( x + 1 + offset, y + offset, *pixmaps[2], 9 * videoButtons[i].controlType, 0, 9, 9 ); 181 p->drawPixmap( x + 1 + offset, y + offset, *pixmaps[2], 9 * videoButtons[i].controlType, 0, 9, 9 );
183} 182}
184 183
185 184
186void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { 185void VideoWidget::mouseMoveEvent( QMouseEvent *event ) {
187 for ( int i = 0; i < numButtons; i++ ) { 186 for ( int i = 0; i < numButtons; i++ ) {
188 int x = videoButtons[i].xPos; 187 int x = videoButtons[i].xPos;
189 int y = videoButtons[i].yPos; 188 int y = videoButtons[i].yPos;
190 if ( event->state() == QMouseEvent::LeftButton ) { 189 if ( event->state() == QMouseEvent::LeftButton ) {
191 // The test to see if the mouse click is inside the circular button or not 190 // The test to see if the mouse click is inside the circular button or not
192 // (compared with the radius squared to avoid a square-root of our distance) 191 // (compared with the radius squared to avoid a square-root of our distance)
193 int radius = 16; 192 int radius = 16;
194 QPoint center = QPoint( x + radius, y + radius ); 193 QPoint center = QPoint( x + radius, y + radius );
195 QPoint dXY = center - event->pos(); 194 QPoint dXY = center - event->pos();
196 int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); 195 int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y();
197 bool isOnButton = dist <= (radius * radius); 196 bool isOnButton = dist <= (radius * radius);
198 if ( isOnButton != videoButtons[i].isHeld ) { 197 if ( isOnButton != videoButtons[i].isHeld ) {
199 videoButtons[i].isHeld = isOnButton; 198 videoButtons[i].isHeld = isOnButton;
200 toggleButton(i); 199 toggleButton(i);
201 } 200 }
202 } else { 201 } else {
203 if ( videoButtons[i].isHeld ) { 202 if ( videoButtons[i].isHeld ) {
204 videoButtons[i].isHeld = FALSE; 203 videoButtons[i].isHeld = FALSE;
205 if ( !videoButtons[i].isToggle ) 204 if ( !videoButtons[i].isToggle )
206 setToggleButton( i, FALSE ); 205 setToggleButton( i, FALSE );
207 switch (i) { 206 switch (i) {
208 case VideoPlay: mediaPlayerState->setPlaying(videoButtons[i].isDown); return; 207 case VideoPlay: mediaPlayerState->setPlaying(videoButtons[i].isDown); return;
209 case VideoStop: mediaPlayerState->setPlaying(FALSE); return; 208 case VideoStop: mediaPlayerState->setPlaying(FALSE); return;
210 case VideoPause: mediaPlayerState->setPaused(videoButtons[i].isDown); return; 209 case VideoPause: mediaPlayerState->setPaused(videoButtons[i].isDown); return;
211 case VideoNext: mediaPlayerState->setNext(); return; 210 case VideoNext: mediaPlayerState->setNext(); return;
212 case VideoPrevious: mediaPlayerState->setPrev(); return; 211 case VideoPrevious: mediaPlayerState->setPrev(); return;
213 case VideoPlayList: mediaPlayerState->setList(); return; 212 case VideoPlayList: mediaPlayerState->setList(); return;
214 case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return; 213 case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return;
215 } 214 }
216 } 215 }
217 } 216 }
218 } 217 }
219} 218}
220 219
221 220
222void VideoWidget::mousePressEvent( QMouseEvent *event ) { 221void VideoWidget::mousePressEvent( QMouseEvent *event ) {
223 mouseMoveEvent( event ); 222 mouseMoveEvent( event );
224} 223}
225 224
226 225
227void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { 226void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) {
228 if ( mediaPlayerState->fullscreen() ) { 227 if ( mediaPlayerState->fullscreen() ) {
229 mediaPlayerState->setFullscreen( FALSE ); 228 mediaPlayerState->setFullscreen( FALSE );
230 makeVisible(); 229 makeVisible();
231 } else { 230 } else {
232 mouseMoveEvent( event ); 231 mouseMoveEvent( event );
233 } 232 }
234} 233}
235 234
236 235
237void VideoWidget::makeVisible() { 236void VideoWidget::makeVisible() {
238 if ( mediaPlayerState->fullscreen() ) { 237 if ( mediaPlayerState->fullscreen() ) {
239 setBackgroundMode( QWidget::NoBackground ); 238 setBackgroundMode( QWidget::NoBackground );
240 showFullScreen(); 239 showFullScreen();
241 resize( qApp->desktop()->size() ); 240 resize( qApp->desktop()->size() );
242 slider->hide(); 241 slider->hide();
243 } else { 242 } else {
244 setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); 243 setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) );
245 showNormal(); 244 showNormal();
246 showMaximized(); 245 showMaximized();
247 slider->show(); 246 slider->show();
248 } 247 }
249} 248}
250 249
251 250
252void VideoWidget::paintEvent( QPaintEvent * ) { 251void VideoWidget::paintEvent( QPaintEvent * ) {
253 QPainter p( this ); 252 QPainter p( this );
254 253
255 if ( mediaPlayerState->fullscreen() ) { 254 if ( mediaPlayerState->fullscreen() ) {
256 // Clear the background 255 // Clear the background
257 p.setBrush( QBrush( Qt::black ) ); 256 p.setBrush( QBrush( Qt::black ) );
258 p.drawRect( rect() ); 257 p.drawRect( rect() );
259 258
260 // Draw the current frame 259 // Draw the current frame
261 //p.drawImage( ); // If using directpainter we won't have a copy except whats on the screen 260 //p.drawImage( ); // If using directpainter we won't have a copy except whats on the screen
262 } else { 261 } else {
263 // draw border 262 // draw border
264 qDrawShadePanel( &p, 4, 15, 230, 170, colorGroup(), TRUE, 5, NULL ); 263 qDrawShadePanel( &p, 4, 15, 230, 170, colorGroup(), TRUE, 5, NULL );
265 264
266 // Clear the movie screen first 265 // Clear the movie screen first
267 p.setBrush( QBrush( Qt::black ) ); 266 p.setBrush( QBrush( Qt::black ) );
268 p.drawRect( 9, 20, 220, 160 ); 267 p.drawRect( 9, 20, 220, 160 );
269 268
270 // draw current frame (centrally positioned from scaling to maintain aspect ratio) 269 // draw current frame (centrally positioned from scaling to maintain aspect ratio)
271 p.drawImage( 9 + (220 - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight ); 270 p.drawImage( 9 + (220 - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight );
272 271
273 // draw the buttons 272 // draw the buttons
274 for ( int i = 0; i < numButtons; i++ ) 273 for ( int i = 0; i < numButtons; i++ )
275 paintButton( &p, i ); 274 paintButton( &p, i );
276 275
277 // draw the slider 276 // draw the slider
278 slider->repaint( TRUE ); 277 slider->repaint( TRUE );
279 } 278 }
280} 279}
281 280
282 281
283void VideoWidget::closeEvent( QCloseEvent* ) { 282void VideoWidget::closeEvent( QCloseEvent* ) {
284 mediaPlayerState->setList(); 283 mediaPlayerState->setList();
285} 284}
286 285
287 286
288bool VideoWidget::playVideo() { 287bool VideoWidget::playVideo() {
289 bool result = FALSE; 288 bool result = FALSE;
290 289
291 int stream = 0; 290 int stream = 0;
292 291
293 int sw = mediaPlayerState->curDecoder()->videoWidth( stream ); 292 int sw = mediaPlayerState->curDecoder()->videoWidth( stream );
294 int sh = mediaPlayerState->curDecoder()->videoHeight( stream ); 293 int sh = mediaPlayerState->curDecoder()->videoHeight( stream );
295 int dd = QPixmap::defaultDepth(); 294 int dd = QPixmap::defaultDepth();
296 int w = height(); 295 int w = height();
297 int h = width(); 296 int h = width();
298 297
299 ColorFormat format = (dd == 16) ? RGB565 : BGRA8888; 298 ColorFormat format = (dd == 16) ? RGB565 : BGRA8888;
300 299
301 if ( mediaPlayerState->fullscreen() ) { 300 if ( mediaPlayerState->fullscreen() ) {
302#ifdef USE_DIRECT_PAINTER 301#ifdef USE_DIRECT_PAINTER
303 QDirectPainter p(this); 302 QDirectPainter p(this);
304 303
305 if ( ( qt_screen->transformOrientation() == 3 ) && 304 if ( ( qt_screen->transformOrientation() == 3 ) &&
306 ( ( dd == 16 ) || ( dd == 32 ) ) && ( p.numRects() == 1 ) ) { 305 ( ( dd == 16 ) || ( dd == 32 ) ) && ( p.numRects() == 1 ) ) {
307 306
308 w = 320; 307 w = 320;
309 h = 240; 308 h = 240;
310 309
311 if ( mediaPlayerState->scaled() ) { 310 if ( mediaPlayerState->scaled() ) {
312 // maintain aspect ratio 311 // maintain aspect ratio
313 if ( w * sh > sw * h ) 312 if ( w * sh > sw * h )
314 w = sw * h / sh; 313 w = sw * h / sh;
315 else 314 else
316 h = sh * w / sw; 315 h = sh * w / sw;
317 } else { 316 } else {
318 w = sw; 317 w = sw;
319 h = sh; 318 h = sh;
320 } 319 }
321 320
322 w--; // we can't allow libmpeg to overwrite. 321 w--; // we can't allow libmpeg to overwrite.
323 QPoint roff = qt_screen->mapToDevice( p.offset(), QSize( qt_screen->width(), qt_screen->height() ) ); 322 QPoint roff = qt_screen->mapToDevice( p.offset(), QSize( qt_screen->width(), qt_screen->height() ) );
324 323
325 int ox = roff.x() - height() + 2 + (height() - w) / 2; 324 int ox = roff.x() - height() + 2 + (height() - w) / 2;
326 int oy = roff.y() + (width() - h) / 2; 325 int oy = roff.y() + (width() - h) / 2;
327 int sx = 0, sy = 0; 326 int sx = 0, sy = 0;
328 327
329 uchar* fp = p.frameBuffer() + p.lineStep() * oy; 328 uchar* fp = p.frameBuffer() + p.lineStep() * oy;
330 fp += dd * ox / 8; 329 fp += dd * ox / 8;
331 uchar **jt = new uchar*[h]; 330 uchar **jt = new uchar*[h];
332 for ( int i = h; i; i-- ) { 331 for ( int i = h; i; i-- ) {
333 jt[h - i] = fp; 332 jt[h - i] = fp;
334 fp += p.lineStep(); 333 fp += p.lineStep();
335 } 334 }
336 335
337 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( jt, sx, sy, sw, sh, w, h, format, 0) == 0; 336 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( jt, sx, sy, sw, sh, w, h, format, 0) == 0;
338 337
339 delete [] jt; 338 delete [] jt;
340 } else { 339 } else {
341#endif 340#endif
342 QPainter p(this); 341 QPainter p(this);
343 342
344 w = 320; 343 w = 320;
345 h = 240; 344 h = 240;
346 345
347 if ( mediaPlayerState->scaled() ) { 346 if ( mediaPlayerState->scaled() ) {
348 // maintain aspect ratio 347 // maintain aspect ratio
349 if ( w * sh > sw * h ) 348 if ( w * sh > sw * h )
350 w = sw * h / sh; 349 w = sw * h / sh;
351 else 350 else
352 h = sh * w / sw; 351 h = sh * w / sw;
353 } else { 352 } else {
354 w = sw; 353 w = sw;
355 h = sh; 354 h = sh;
356 } 355 }
357 356
358 int bytes = ( dd == 16 ) ? 2 : 4; 357 int bytes = ( dd == 16 ) ? 2 : 4;
359 QImage tempFrame( w, h, bytes << 3 ); 358 QImage tempFrame( w, h, bytes << 3 );
360 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( tempFrame.jumpTable(), 359 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( tempFrame.jumpTable(),
361 0, 0, sw, sh, w, h, format, 0) == 0; 360 0, 0, sw, sh, w, h, format, 0) == 0;
362 if ( result && mediaPlayerState->fullscreen() ) { 361 if ( result && mediaPlayerState->fullscreen() ) {
363 362
364 int rw = h, rh = w; 363 int rw = h, rh = w;
365 QImage rotatedFrame( rw, rh, bytes << 3 ); 364 QImage rotatedFrame( rw, rh, bytes << 3 );
366 365
367 ushort* in = (ushort*)tempFrame.bits(); 366 ushort* in = (ushort*)tempFrame.bits();
368 ushort* out = (ushort*)rotatedFrame.bits(); 367 ushort* out = (ushort*)rotatedFrame.bits();
369 int spl = rotatedFrame.bytesPerLine() / bytes; 368 int spl = rotatedFrame.bytesPerLine() / bytes;
370 for (int x=0; x<h; x++) { 369 for (int x=0; x<h; x++) {
371 if ( bytes == 2 ) { 370 if ( bytes == 2 ) {
372 ushort* lout = out++ + (w - 1)*spl; 371 ushort* lout = out++ + (w - 1)*spl;
373 for (int y=0; y<w; y++) { 372 for (int y=0; y<w; y++) {
374 *lout=*in++; 373 *lout=*in++;
375 lout-=spl; 374 lout-=spl;
376 } 375 }
377 } else { 376 } else {
378 ulong* lout = ((ulong *)out)++ + (w - 1)*spl; 377 ulong* lout = ((ulong *)out)++ + (w - 1)*spl;
379 for (int y=0; y<w; y++) { 378 for (int y=0; y<w; y++) {
380 *lout=*((ulong*)in)++; 379 *lout=*((ulong*)in)++;
381 lout-=spl; 380 lout-=spl;
382 } 381 }
383 } 382 }
384 } 383 }
385 384
386 p.drawImage( (240 - rw) / 2, (320 - rh) / 2, rotatedFrame, 0, 0, rw, rh ); 385 p.drawImage( (240 - rw) / 2, (320 - rh) / 2, rotatedFrame, 0, 0, rw, rh );
387 } 386 }
388#ifdef USE_DIRECT_PAINTER 387#ifdef USE_DIRECT_PAINTER
389 } 388 }
390#endif 389#endif
391 } else { 390 } else {
392 391
393 w = 220; 392 w = 220;
394 h = 160; 393 h = 160;
395 394
396 // maintain aspect ratio 395 // maintain aspect ratio
397 if ( w * sh > sw * h ) 396 if ( w * sh > sw * h )
398 w = sw * h / sh; 397 w = sw * h / sh;
399 else 398 else
400 h = sh * w / sw; 399 h = sh * w / sw;
401 400
402 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( currentFrame->jumpTable(), 0, 0, sw, sh, w, h, format, 0) == 0; 401 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( currentFrame->jumpTable(), 0, 0, sw, sh, w, h, format, 0) == 0;
403 402
404 QPainter p( this ); 403 QPainter p( this );
405 404
406 // Image changed size, therefore need to blank the possibly unpainted regions first 405 // Image changed size, therefore need to blank the possibly unpainted regions first
407 if ( scaledWidth != w || scaledHeight != h ) { 406 if ( scaledWidth != w || scaledHeight != h ) {
408 p.setBrush( QBrush( Qt::black ) ); 407 p.setBrush( QBrush( Qt::black ) );
409 p.drawRect( 9, 20, 220, 160 ); 408 p.drawRect( 9, 20, 220, 160 );
410 } 409 }
411 410
412 scaledWidth = w; 411 scaledWidth = w;
413 scaledHeight = h; 412 scaledHeight = h;
414 413
415 if ( result ) { 414 if ( result ) {
416 p.drawImage( 9 + (220 - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight ); 415 p.drawImage( 9 + (220 - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight );
417 } 416 }
418 417
419 } 418 }
420 419
421 return result; 420 return result;
422} 421}
423 422
424 423
diff --git a/core/multimedia/opieplayer/wavplugin/Makefile.in b/core/multimedia/opieplayer/wavplugin/Makefile.in
index bcbe7f2..a46b925 100644
--- a/core/multimedia/opieplayer/wavplugin/Makefile.in
+++ b/core/multimedia/opieplayer/wavplugin/Makefile.in
@@ -55,55 +55,57 @@ OBJMOC =
55.c.o: 55.c.o:
56 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $< 56 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
57 57
58####### Build rules 58####### Build rules
59 59
60 60
61all: $(DESTDIR)$(SYSCONF_LINK_TARGET) 61all: $(DESTDIR)$(SYSCONF_LINK_TARGET)
62 62
63$(DESTDIR)$(SYSCONF_LINK_TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS) 63$(DESTDIR)$(SYSCONF_LINK_TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
64 $(SYSCONF_LINK_LIB) 64 $(SYSCONF_LINK_LIB)
65 65
66moc: $(SRCMOC) 66moc: $(SRCMOC)
67 67
68tmake: 68tmake:
69 tmake wavplugin.pro 69 tmake wavplugin.pro
70 70
71clean: 71clean:
72 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS) 72 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
73 -rm -f *~ core 73 -rm -f *~ core
74 -rm -f allmoc.cpp 74 -rm -f allmoc.cpp
75 75
76####### Extension Modules 76####### Extension Modules
77 77
78listpromodules: 78listpromodules:
79 @echo 79 @echo
80 80
81listallmodules: 81listallmodules:
82 @echo 82 @echo
83 83
84listaddonpromodules: 84listaddonpromodules:
85 @echo 85 @echo
86 86
87listaddonentmodules: 87listaddonentmodules:
88 @echo 88 @echo
89 89
90 90
91REQUIRES= 91REQUIRES=
92 92
93####### Sub-libraries 93####### Sub-libraries
94 94
95 95
96###### Combined headers 96###### Combined headers
97 97
98 98
99 99
100####### Compile 100####### Compile
101 101
102wavplugin.o: wavplugin.cpp \ 102wavplugin.o: wavplugin.cpp \
103 wavplugin.h 103 wavplugin.h \
104 ../mediaplayerplugininterface.h
104 105
105wavpluginimpl.o: wavpluginimpl.cpp \ 106wavpluginimpl.o: wavpluginimpl.cpp \
106 wavplugin.h \ 107 wavplugin.h \
108 ../mediaplayerplugininterface.h \
107 wavpluginimpl.h 109 wavpluginimpl.h
108 110
109 111