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