]> git.saurik.com Git - wxWidgets.git/blame - utils/wxMMedia2/board/mmbman.cpp
Reenabled OSS support
[wxWidgets.git] / utils / wxMMedia2 / board / mmbman.cpp
CommitLineData
55196c54
GL
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
d73dd2b2 33// Personal headers
55196c54
GL
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
d73dd2b2
GL
54#include "vidbase.h"
55#ifdef __UNIX__
56#include "vidxanm.h"
57#endif
58
59#ifdef __WIN32__
60#include "vidwin.h"
61#endif
62
55196c54
GL
63#include "mmboard.h"
64#include "mmbman.h"
65
66// ----------------------------------------------------------------------------
67// Private class definitions
68// ----------------------------------------------------------------------------
69
70class MMBoardSoundFile: public MMBoardFile {
71public:
794bcc2d
GL
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 void SetPosition(MMBoardTime btime);
87
88 bool IsStopped();
89 bool IsPaused();
90
91 wxString GetStringType();
92 wxString GetStringInformation();
93
55196c54 94protected:
794bcc2d
GL
95 wxSoundFileStream *GetDecoder();
96
97 wxSoundStream *m_output_stream;
98 wxInputStream *m_input_stream;
99 wxSoundFileStream *m_file_stream;
55196c54 100
794bcc2d
GL
101 MMBoardTime m_length;
102 wxUint8 m_file_type;
d73dd2b2
GL
103};
104
105class MMBoardVideoFile: public MMBoardFile {
106public:
794bcc2d
GL
107 MMBoardVideoFile(const wxString& filename);
108 ~MMBoardVideoFile();
109
110 bool NeedWindow();
111
112 void SetWindow(wxWindow *window);
113
114 void Play();
115 void Pause();
116 void Resume();
117 void Stop();
118
119 MMBoardTime GetPosition();
120 MMBoardTime GetLength();
121 void SetPosition(MMBoardTime btime);
122
123 bool IsStopped();
124 bool IsPaused();
125
126 wxString GetStringType();
127 wxString GetStringInformation();
128
d73dd2b2 129protected:
794bcc2d
GL
130 wxWindow *m_output_window;
131 wxVideoBaseDriver *m_video_driver;
55196c54
GL
132};
133
134// ----------------------------------------------------------------------------
135// Implementation
136// ----------------------------------------------------------------------------
137
d73dd2b2
GL
138#define MMBoard_UNKNOWNTYPE 0
139#define MMBoard_WAVE 1
140#define MMBoard_AIFF 2
55196c54
GL
141
142// ----------------------------------------------------------------------------
143// MMBoardSoundFile
144
145MMBoardSoundFile::MMBoardSoundFile(const wxString& filename)
146 : MMBoardFile()
147{
794bcc2d
GL
148 m_input_stream = new wxFileInputStream(filename);
149 m_output_stream = MMBoardManager::OpenSoundStream();
150
151 m_file_stream = GetDecoder();
152
153 if (!m_file_stream) {
154 SetError(MMBoard_UnknownFile);
155 return;
156 }
d73dd2b2 157
794bcc2d
GL
158 // Compute length
159 wxUint32 length, seconds;
160
161 length = m_file_stream->GetLength();
162 seconds = m_file_stream->GetSoundFormat().GetTimeFromBytes(length);
163 m_length.seconds = seconds % 60;
164 m_length.minutes = (seconds / 60) % 60;
165 m_length.hours = seconds / 3600;
55196c54
GL
166}
167
168MMBoardSoundFile::~MMBoardSoundFile()
169{
794bcc2d
GL
170 if (m_file_stream)
171 delete m_file_stream;
172 MMBoardManager::UnrefSoundStream(m_output_stream);
173 delete m_input_stream;
55196c54
GL
174}
175
176wxSoundFileStream *MMBoardSoundFile::GetDecoder()
177{
794bcc2d
GL
178 wxSoundFileStream *f_stream;
179
180 // First, we try a Wave decoder
181 f_stream = new wxSoundWave(*m_input_stream, *m_output_stream);
182 m_file_type = MMBoard_WAVE;
183 if (f_stream->CanRead())
184 return f_stream;
185 delete f_stream;
186
187 // Then, a AIFF decoder
188 f_stream = new wxSoundAiff(*m_input_stream, *m_output_stream);
189 m_file_type = MMBoard_AIFF;
190 if (f_stream->CanRead())
191 return f_stream;
192 delete f_stream;
193
194 m_file_type = MMBoard_UNKNOWNTYPE;
195
196 // TODO: automate
197
198 return NULL;
55196c54
GL
199}
200
201MMBoardTime MMBoardSoundFile::GetLength()
202{
794bcc2d 203 return m_length;
55196c54
GL
204}
205
206bool MMBoardSoundFile::IsStopped()
207{
794bcc2d 208 return m_file_stream->IsStopped();
55196c54
GL
209}
210
5bee458a
GL
211bool MMBoardSoundFile::IsPaused()
212{
794bcc2d 213 return m_file_stream->IsPaused();
5bee458a
GL
214}
215
55196c54
GL
216MMBoardTime MMBoardSoundFile::GetPosition()
217{
794bcc2d
GL
218 wxUint32 length, seconds;
219 MMBoardTime file_time;
220
221 file_time.seconds = file_time.minutes = file_time.hours = 0;
222 if (m_file_stream->IsStopped())
223 return file_time;
224
225 length = m_file_stream->GetPosition();
226 seconds = m_file_stream->GetSoundFormat().GetTimeFromBytes(length);
227 file_time.seconds = seconds % 60;
228 file_time.minutes = (seconds / 60) % 60;
229 file_time.hours = seconds / 3600;
230
55196c54 231 return file_time;
794bcc2d
GL
232}
233
234void MMBoardSoundFile::SetPosition(MMBoardTime btime)
235{
236 wxUint32 itime;
55196c54 237
794bcc2d 238 itime = btime.seconds + btime.minutes * 60 + btime.hours;
55196c54 239
794bcc2d
GL
240 m_file_stream->SetPosition(
241 m_file_stream->GetSoundFormat().GetBytesFromTime(itime)
242 );
55196c54
GL
243}
244
245bool MMBoardSoundFile::NeedWindow()
246{
794bcc2d 247 return FALSE;
55196c54
GL
248}
249
250void MMBoardSoundFile::SetWindow(wxWindow *window)
251{
252}
253
254void MMBoardSoundFile::Play()
255{
794bcc2d 256 m_file_stream->Play();
55196c54
GL
257}
258
259void MMBoardSoundFile::Pause()
260{
794bcc2d 261 m_file_stream->Pause();
55196c54
GL
262}
263
264void MMBoardSoundFile::Resume()
265{
794bcc2d 266 m_file_stream->Resume();
55196c54
GL
267}
268
269void MMBoardSoundFile::Stop()
270{
794bcc2d 271 m_file_stream->Stop();
55196c54
GL
272}
273
274wxString MMBoardSoundFile::GetStringType()
275{
794bcc2d
GL
276 switch (m_file_type) {
277 case MMBoard_WAVE:
278 return wxString(wxT("WAVE file"));
279 break;
280 case MMBoard_AIFF:
281 return wxString(wxT("AIFF file"));
282 break;
283 default:
284 return wxString(wxT("Unknown file"));
285 break;
286 }
55196c54
GL
287}
288
289wxString MMBoardSoundFile::GetStringInformation()
290{
ebaad2cc
GL
291 wxString info;
292 wxSoundFormatBase *format;
293
294 format = &(m_file_stream->GetSoundFormat());
295
296 info = wxT("Data encoding: ");
297 switch (format->GetType()) {
298 case wxSOUND_PCM: {
299 wxSoundFormatPcm *pcm_format = (wxSoundFormatPcm *)format;
300
301 info += wxT("PCM\n");
302 info += wxString::Format(wxT("Sampling rate: %d\n")
303 wxT("Bits per sample: %d\n")
304 wxT("Number of channels: %d\n"),
305 pcm_format->GetSampleRate(),
306 pcm_format->GetBPS(),
307 pcm_format->GetChannels());
308
309 break;
310 }
311 case wxSOUND_ULAW: {
312 wxSoundFormatUlaw *ulaw_format = (wxSoundFormatUlaw *)format;
313 info += wxT("ULAW\n");
314 info += wxString::Format(wxT("Sampling rate: %d\n"), ulaw_format->GetSampleRate());
315 break;
316 }
317 default:
318 info += wxT("Unknown");
319 break;
320 }
321 return info;
55196c54
GL
322}
323
324// ----------------------------------------------------------------------------
325
326
d73dd2b2
GL
327// ----------------------------------------------------------------------------
328// MMBoardVideoFile
329
330MMBoardVideoFile::MMBoardVideoFile(const wxString& filename)
331{
ebaad2cc 332 m_output_window = NULL;
d73dd2b2
GL
333
334#if defined(__UNIX__)
ebaad2cc 335 m_video_driver = new wxVideoXANIM(filename);
d73dd2b2 336#elif defined(__WIN32__)
ebaad2cc 337 m_video_driver = new wxVideoWindows(filename);
d73dd2b2 338#else
ebaad2cc
GL
339 m_video_driver = NULL;
340 SetError(MMBoard_UnknownFile);
d73dd2b2
GL
341#endif
342}
343
344MMBoardVideoFile::~MMBoardVideoFile()
345{
ebaad2cc
GL
346 if (m_video_driver)
347 delete m_video_driver;
d73dd2b2
GL
348}
349
350bool MMBoardVideoFile::NeedWindow()
351{
ebaad2cc 352 return TRUE;
d73dd2b2
GL
353}
354
355void MMBoardVideoFile::SetWindow(wxWindow *window)
356{
ebaad2cc
GL
357 m_output_window = window;
358 m_video_driver->AttachOutput(*window);
2018e574
GL
359
360 wxSize size;
361 m_video_driver->GetSize(size);
362 window->SetSize(size);
363 // BAD BAD
c12a24e2
GL
364 // and we remove
365 // window->GetParent()->GetSizer()->Fit(window->GetParent());
d73dd2b2
GL
366}
367
368void MMBoardVideoFile::Play()
369{
ebaad2cc 370 m_video_driver->Play();
d73dd2b2
GL
371}
372
373void MMBoardVideoFile::Pause()
374{
ebaad2cc 375 m_video_driver->Pause();
d73dd2b2
GL
376}
377
378void MMBoardVideoFile::Resume()
379{
ebaad2cc 380 m_video_driver->Resume();
d73dd2b2
GL
381}
382
383void MMBoardVideoFile::Stop()
384{
ebaad2cc 385 m_video_driver->Stop();
d73dd2b2
GL
386}
387
388MMBoardTime MMBoardVideoFile::GetPosition()
389{
ebaad2cc 390 MMBoardTime btime;
d73dd2b2 391
ebaad2cc
GL
392 btime.seconds = btime.minutes = btime.hours = 0;
393 return btime;
d73dd2b2
GL
394}
395
396MMBoardTime MMBoardVideoFile::GetLength()
397{
ebaad2cc 398 MMBoardTime btime;
2018e574 399 int frameTime;
d73dd2b2 400
2018e574
GL
401 frameTime = (int)( m_video_driver->GetNbFrames() / m_video_driver->GetFrameRate());
402
403 btime.seconds = frameTime % 60;
404 btime.minutes = (frameTime / 60) % 60;
405 btime.hours = frameTime / 3600;
ebaad2cc 406 return btime;
d73dd2b2
GL
407}
408
794bcc2d
GL
409void MMBoardVideoFile::SetPosition(MMBoardTime btime)
410{
411}
412
d73dd2b2
GL
413bool MMBoardVideoFile::IsStopped()
414{
ebaad2cc 415 return m_video_driver->IsStopped();
d73dd2b2
GL
416}
417
418bool MMBoardVideoFile::IsPaused()
419{
ebaad2cc 420 return m_video_driver->IsPaused();
d73dd2b2
GL
421}
422
423wxString MMBoardVideoFile::GetStringType()
424{
ebaad2cc 425 return wxString(wxT("Video XANIM"));
d73dd2b2
GL
426}
427
428wxString MMBoardVideoFile::GetStringInformation()
429{
2018e574
GL
430 wxString info;
431
432 info = wxT("Video codec: ");
433 info += m_video_driver->GetMovieCodec() + "\n";
434 info += wxT("Audio codec: ");
435 info += m_video_driver->GetAudioCodec();
436 info += wxString::Format(" Sample rate: %d Channels: %d\n", m_video_driver->GetSampleRate(),
437 m_video_driver->GetBPS());
438 info += wxString::Format(" Frame rate: %.01f", m_video_driver->GetFrameRate());
439 return info;
d73dd2b2
GL
440}
441
442// ----------------------------------------------------------------------------
443
55196c54
GL
444// ----------------------------------------------------------------------------
445// MMBoardFile
446
447MMBoardFile::MMBoardFile()
448{
449 m_error = 0;
450}
451
452MMBoardFile::~MMBoardFile()
453{
454}
455
456//
457// ----------------------------------------------------------------------------
458
459// ----------------------------------------------------------------------------
460// MMBoardManager
461
462MMBoardFile *MMBoardManager::Open(const wxString& filename)
463{
464 MMBoardFile *file;
465
d73dd2b2 466 // Test the audio codec
55196c54 467 file = new MMBoardSoundFile(filename);
d73dd2b2
GL
468 if (!file->GetError())
469 return file;
470 delete file;
471
472 // Test the video codec
473 file = new MMBoardVideoFile(filename);
474 if (!file->GetError())
475 return file;
476 delete file;
477
478 // Arrrgh, we just could not see what is that file ...
479 return NULL;
55196c54
GL
480}
481
482DECLARE_APP(MMBoardApp)
483
484wxSoundStream *MMBoardManager::OpenSoundStream()
485{
486#ifdef __UNIX__
487 if ((wxGetApp().m_caps & MM_SOUND_ESD) != 0)
488 return new wxSoundStreamESD();
489
490 if ((wxGetApp().m_caps & MM_SOUND_OSS) != 0)
491 return new wxSoundStreamOSS();
492#endif
493
494#ifdef __WIN32__
495 if ((wxGetApp().m_caps & MM_SOUND_WIN) != 0)
496 return new wxSoundStreamWin();
497#endif
498
499 wxMessageBox("You are trying to open a multimedia but you have not devices", "Error", wxOK | wxICON_ERROR, NULL);
500
501 return NULL;
502}
503
504void MMBoardManager::UnrefSoundStream(wxSoundStream *stream)
505{
506 delete stream;
507}
508
509// ----------------------------------------------------------------------------
510