]> git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia2/board/mmbman.cpp
Corrected an HTML typo
[wxWidgets.git] / utils / wxMMedia2 / board / mmbman.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: mmbman.cpp
3 // Purpose: Multimedia Board manager
4 // Author: Guilhem Lavaux, <guilhem.lavaux@libertysurf.fr>
5 // Modified by:
6 // Created: 13/02/2000
7 // RCS-ID: $Id$
8 // Copyright: (c) 2000, Guilhem Lavaux
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "mmbman.cpp"
14 #endif
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 // for all others, include the necessary headers (this file is usually all you
28 // need because it includes almost all "standard" wxWindows headers
29 #ifndef WX_PRECOMP
30 #include "wx/wx.h"
31 #endif
32
33 // Personal headers
34
35 #include "wx/stream.h"
36 #include "wx/wfstream.h"
37
38 #include "sndbase.h"
39 #include "sndfile.h"
40 #include "sndwav.h"
41 #include "sndaiff.h"
42 #include "sndpcm.h"
43 #include "sndulaw.h"
44
45 #ifdef __UNIX__
46 #include "sndoss.h"
47 #include "sndesd.h"
48 #endif
49
50 #ifdef __WIN32__
51 #include "sndwin.h"
52 #endif
53
54 #include "vidbase.h"
55 #ifdef __UNIX__
56 #include "vidxanm.h"
57 #endif
58
59 #ifdef __WIN32__
60 #include "vidwin.h"
61 #endif
62
63 #include "mmboard.h"
64 #include "mmbman.h"
65
66 // ----------------------------------------------------------------------------
67 // Private class definitions
68 // ----------------------------------------------------------------------------
69
70 class MMBoardSoundFile: public MMBoardFile {
71 public:
72 MMBoardSoundFile(const wxString& filename);
73 ~MMBoardSoundFile();
74
75 bool NeedWindow();
76
77 void SetWindow(wxWindow *window);
78
79 void Play();
80 void Pause();
81 void Resume();
82 void Stop();
83
84 MMBoardTime GetPosition();
85 MMBoardTime GetLength();
86
87 bool IsStopped();
88 bool IsPaused();
89
90 wxString GetStringType();
91 wxString GetStringInformation();
92
93 protected:
94 wxSoundFileStream *GetDecoder();
95
96 wxSoundStream *m_output_stream;
97 wxInputStream *m_input_stream;
98 wxSoundFileStream *m_file_stream;
99
100 MMBoardTime m_length;
101 wxUint8 m_file_type;
102 };
103
104 class MMBoardVideoFile: public MMBoardFile {
105 public:
106 MMBoardVideoFile(const wxString& filename);
107 ~MMBoardVideoFile();
108
109 bool NeedWindow();
110
111 void SetWindow(wxWindow *window);
112
113 void Play();
114 void Pause();
115 void Resume();
116 void Stop();
117
118 MMBoardTime GetPosition();
119 MMBoardTime GetLength();
120
121 bool IsStopped();
122 bool IsPaused();
123
124 wxString GetStringType();
125 wxString GetStringInformation();
126
127 protected:
128 wxWindow *m_output_window;
129 wxInputStream *m_input_stream;
130 wxVideoBaseDriver *m_video_driver;
131 };
132
133 // ----------------------------------------------------------------------------
134 // Implementation
135 // ----------------------------------------------------------------------------
136
137 #define MMBoard_UNKNOWNTYPE 0
138 #define MMBoard_WAVE 1
139 #define MMBoard_AIFF 2
140
141 // ----------------------------------------------------------------------------
142 // MMBoardSoundFile
143
144 MMBoardSoundFile::MMBoardSoundFile(const wxString& filename)
145 : MMBoardFile()
146 {
147 m_input_stream = new wxFileInputStream(filename);
148 m_output_stream = MMBoardManager::OpenSoundStream();
149
150 m_file_stream = GetDecoder();
151
152 if (!m_file_stream) {
153 SetError(MMBoard_UnknownFile);
154 return;
155 }
156
157 // Compute length
158 wxUint32 length, seconds;
159
160 length = m_file_stream->GetLength();
161 seconds = m_file_stream->GetSoundFormat().GetTimeFromBytes(length);
162 m_length.seconds = seconds % 60;
163 m_length.minutes = (seconds / 60) % 60;
164 m_length.hours = seconds / 3600;
165 }
166
167 MMBoardSoundFile::~MMBoardSoundFile()
168 {
169 if (m_file_stream)
170 delete m_file_stream;
171 MMBoardManager::UnrefSoundStream(m_output_stream);
172 delete m_input_stream;
173 }
174
175 wxSoundFileStream *MMBoardSoundFile::GetDecoder()
176 {
177 wxSoundFileStream *f_stream;
178
179 // First, we try a Wave decoder
180 f_stream = new wxSoundWave(*m_input_stream, *m_output_stream);
181 m_file_type = MMBoard_WAVE;
182 if (f_stream->CanRead())
183 return f_stream;
184 delete f_stream;
185
186 // Then, a AIFF decoder
187 f_stream = new wxSoundAiff(*m_input_stream, *m_output_stream);
188 m_file_type = MMBoard_AIFF;
189 if (f_stream->CanRead())
190 return f_stream;
191 delete f_stream;
192
193 m_file_type = MMBoard_UNKNOWNTYPE;
194
195 // TODO: automate
196
197 return NULL;
198 }
199
200 MMBoardTime MMBoardSoundFile::GetLength()
201 {
202 return m_length;
203 }
204
205 bool MMBoardSoundFile::IsStopped()
206 {
207 return m_file_stream->IsStopped();
208 }
209
210 bool MMBoardSoundFile::IsPaused()
211 {
212 return m_file_stream->IsPaused();
213 }
214
215 MMBoardTime MMBoardSoundFile::GetPosition()
216 {
217 wxUint32 length, seconds;
218 MMBoardTime file_time;
219
220 file_time.seconds = file_time.minutes = file_time.hours = 0;
221 if (m_file_stream->IsStopped())
222 return file_time;
223
224 length = m_file_stream->GetPosition();
225 seconds = m_file_stream->GetSoundFormat().GetTimeFromBytes(length);
226 file_time.seconds = seconds % 60;
227 file_time.minutes = (seconds / 60) % 60;
228 file_time.hours = seconds / 3600;
229
230 return file_time;
231 }
232
233 bool MMBoardSoundFile::NeedWindow()
234 {
235 return FALSE;
236 }
237
238 void MMBoardSoundFile::SetWindow(wxWindow *window)
239 {
240 }
241
242 void MMBoardSoundFile::Play()
243 {
244 m_file_stream->Play();
245 }
246
247 void MMBoardSoundFile::Pause()
248 {
249 m_file_stream->Pause();
250 }
251
252 void MMBoardSoundFile::Resume()
253 {
254 m_file_stream->Resume();
255 }
256
257 void MMBoardSoundFile::Stop()
258 {
259 m_file_stream->Stop();
260 }
261
262 wxString MMBoardSoundFile::GetStringType()
263 {
264 switch (m_file_type) {
265 case MMBoard_WAVE:
266 return wxString(wxT("WAVE file"));
267 break;
268 case MMBoard_AIFF:
269 return wxString(wxT("AIFF file"));
270 break;
271 default:
272 return wxString(wxT("Unknown file"));
273 break;
274 }
275 }
276
277 wxString MMBoardSoundFile::GetStringInformation()
278 {
279 wxString info;
280 wxSoundFormatBase *format;
281
282 format = &(m_file_stream->GetSoundFormat());
283
284 info = wxT("Data encoding: ");
285 switch (format->GetType()) {
286 case wxSOUND_PCM: {
287 wxSoundFormatPcm *pcm_format = (wxSoundFormatPcm *)format;
288
289 info += wxT("PCM\n");
290 info += wxString::Format(wxT("Sampling rate: %d\n")
291 wxT("Bits per sample: %d\n")
292 wxT("Number of channels: %d\n"),
293 pcm_format->GetSampleRate(),
294 pcm_format->GetBPS(),
295 pcm_format->GetChannels());
296
297 break;
298 }
299 case wxSOUND_ULAW: {
300 wxSoundFormatUlaw *ulaw_format = (wxSoundFormatUlaw *)format;
301 info += wxT("ULAW\n");
302 info += wxString::Format(wxT("Sampling rate: %d\n"), ulaw_format->GetSampleRate());
303 break;
304 }
305 default:
306 info += wxT("Unknown");
307 break;
308 }
309 return info;
310 }
311
312 // ----------------------------------------------------------------------------
313
314
315 // ----------------------------------------------------------------------------
316 // MMBoardVideoFile
317
318 MMBoardVideoFile::MMBoardVideoFile(const wxString& filename)
319 {
320 m_output_window = NULL;
321
322 #if defined(__UNIX__)
323 m_video_driver = new wxVideoXANIM(filename);
324 #elif defined(__WIN32__)
325 m_video_driver = new wxVideoWindows(filename);
326 #else
327 m_video_driver = NULL;
328 SetError(MMBoard_UnknownFile);
329 #endif
330 }
331
332 MMBoardVideoFile::~MMBoardVideoFile()
333 {
334 if (m_video_driver)
335 delete m_video_driver;
336
337 delete m_input_stream;
338 }
339
340 bool MMBoardVideoFile::NeedWindow()
341 {
342 return TRUE;
343 }
344
345 void MMBoardVideoFile::SetWindow(wxWindow *window)
346 {
347 m_output_window = window;
348 m_video_driver->AttachOutput(*window);
349 }
350
351 void MMBoardVideoFile::Play()
352 {
353 m_video_driver->Play();
354 }
355
356 void MMBoardVideoFile::Pause()
357 {
358 m_video_driver->Pause();
359 }
360
361 void MMBoardVideoFile::Resume()
362 {
363 m_video_driver->Resume();
364 }
365
366 void MMBoardVideoFile::Stop()
367 {
368 m_video_driver->Stop();
369 }
370
371 MMBoardTime MMBoardVideoFile::GetPosition()
372 {
373 MMBoardTime btime;
374
375 btime.seconds = btime.minutes = btime.hours = 0;
376 return btime;
377 }
378
379 MMBoardTime MMBoardVideoFile::GetLength()
380 {
381 MMBoardTime btime;
382
383 btime.seconds = 1;
384 btime.minutes = btime.hours = 0;
385 return btime;
386 }
387
388 bool MMBoardVideoFile::IsStopped()
389 {
390 return m_video_driver->IsStopped();
391 }
392
393 bool MMBoardVideoFile::IsPaused()
394 {
395 return m_video_driver->IsPaused();
396 }
397
398 wxString MMBoardVideoFile::GetStringType()
399 {
400 return wxString(wxT("Video XANIM"));
401 }
402
403 wxString MMBoardVideoFile::GetStringInformation()
404 {
405 return wxString(wxT("No info"));
406 }
407
408 // ----------------------------------------------------------------------------
409
410 // ----------------------------------------------------------------------------
411 // MMBoardFile
412
413 MMBoardFile::MMBoardFile()
414 {
415 m_error = 0;
416 }
417
418 MMBoardFile::~MMBoardFile()
419 {
420 }
421
422 //
423 // ----------------------------------------------------------------------------
424
425 // ----------------------------------------------------------------------------
426 // MMBoardManager
427
428 MMBoardFile *MMBoardManager::Open(const wxString& filename)
429 {
430 MMBoardFile *file;
431
432 // Test the audio codec
433 file = new MMBoardSoundFile(filename);
434 if (!file->GetError())
435 return file;
436 delete file;
437
438 // Test the video codec
439 file = new MMBoardVideoFile(filename);
440 if (!file->GetError())
441 return file;
442 delete file;
443
444 // Arrrgh, we just could not see what is that file ...
445 return NULL;
446 }
447
448 DECLARE_APP(MMBoardApp)
449
450 wxSoundStream *MMBoardManager::OpenSoundStream()
451 {
452 #ifdef __UNIX__
453 if ((wxGetApp().m_caps & MM_SOUND_ESD) != 0)
454 return new wxSoundStreamESD();
455
456 if ((wxGetApp().m_caps & MM_SOUND_OSS) != 0)
457 return new wxSoundStreamOSS();
458 #endif
459
460 #ifdef __WIN32__
461 if ((wxGetApp().m_caps & MM_SOUND_WIN) != 0)
462 return new wxSoundStreamWin();
463 #endif
464
465 wxMessageBox("You are trying to open a multimedia but you have not devices", "Error", wxOK | wxICON_ERROR, NULL);
466
467 return NULL;
468 }
469
470 void MMBoardManager::UnrefSoundStream(wxSoundStream *stream)
471 {
472 delete stream;
473 }
474
475 // ----------------------------------------------------------------------------
476