]>
git.saurik.com Git - wxWidgets.git/blob - contrib/samples/mmedia/mmbman.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Multimedia Board manager
4 // Author: Guilhem Lavaux, <guilhem.lavaux@libertysurf.fr>
8 // Copyright: (c) 2000, Guilhem Lavaux
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ----------------------------------------------------------------------------
14 // ----------------------------------------------------------------------------
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
23 // for all others, include the necessary headers (this file is usually all you
24 // need because it includes almost all "standard" wxWidgets headers
31 #include "wx/stream.h"
32 #include "wx/wfstream.h"
34 #include "wx/mmedia/sndbase.h"
35 #include "wx/mmedia/sndfile.h"
36 #include "wx/mmedia/sndwav.h"
37 #include "wx/mmedia/sndaiff.h"
38 #include "wx/mmedia/sndpcm.h"
39 #include "wx/mmedia/sndulaw.h"
40 #include "wx/mmedia/sndmsad.h"
43 #include "wx/mmedia/sndoss.h"
44 #include "wx/mmedia/sndesd.h"
48 #include "wx/mmedia/sndwin.h"
51 #include "wx/mmedia/vidbase.h"
53 #include "wx/mmedia/vidxanm.h"
57 #include "wx/mmedia/vidwin.h"
63 // ----------------------------------------------------------------------------
64 // Private class definitions
65 // ----------------------------------------------------------------------------
67 class MMBoardSoundFile
: public MMBoardFile
{
69 MMBoardSoundFile(const wxString
& filename
);
74 void SetWindow(wxWindow
*window
);
81 MMBoardTime
GetPosition();
82 MMBoardTime
GetLength();
83 void SetPosition(MMBoardTime btime
);
88 wxString
GetStringType();
89 wxString
GetStringInformation();
92 wxSoundFileStream
*GetDecoder();
94 wxSoundStream
*m_output_stream
;
95 wxInputStream
*m_input_stream
;
96 wxSoundFileStream
*m_file_stream
;
102 class MMBoardVideoFile
: public MMBoardFile
{
104 MMBoardVideoFile(const wxString
& filename
);
109 void SetWindow(wxWindow
*window
);
116 MMBoardTime
GetPosition();
117 MMBoardTime
GetLength();
118 void SetPosition(MMBoardTime btime
);
123 wxString
GetStringType();
124 wxString
GetStringInformation();
127 wxWindow
*m_output_window
;
128 wxVideoBaseDriver
*m_video_driver
;
131 // ----------------------------------------------------------------------------
133 // ----------------------------------------------------------------------------
135 #define MMBoard_UNKNOWNTYPE 0
136 #define MMBoard_WAVE 1
137 #define MMBoard_AIFF 2
139 // ----------------------------------------------------------------------------
142 MMBoardSoundFile::MMBoardSoundFile(const wxString
& filename
)
145 m_input_stream
= new wxFileInputStream(filename
);
146 m_output_stream
= MMBoardManager::OpenSoundStream();
148 m_file_stream
= GetDecoder();
150 if (!m_file_stream
) {
151 SetError(MMBoard_UnknownFile
);
156 wxUint32 length
, seconds
;
158 length
= m_file_stream
->GetLength();
159 seconds
= m_file_stream
->GetSoundFormat().GetTimeFromBytes(length
);
160 m_length
.seconds
= seconds
% 60;
161 m_length
.minutes
= (seconds
/ 60) % 60;
162 m_length
.hours
= seconds
/ 3600;
165 MMBoardSoundFile::~MMBoardSoundFile()
168 delete m_file_stream
;
169 MMBoardManager::UnrefSoundStream(m_output_stream
);
170 delete m_input_stream
;
173 wxSoundFileStream
*MMBoardSoundFile::GetDecoder()
175 wxSoundFileStream
*f_stream
;
177 // First, we try a Wave decoder
178 f_stream
= new wxSoundWave(*m_input_stream
, *m_output_stream
);
179 m_file_type
= MMBoard_WAVE
;
180 if (f_stream
->CanRead())
184 // Then, a AIFF decoder
185 f_stream
= new wxSoundAiff(*m_input_stream
, *m_output_stream
);
186 m_file_type
= MMBoard_AIFF
;
187 if (f_stream
->CanRead())
191 m_file_type
= MMBoard_UNKNOWNTYPE
;
198 MMBoardTime
MMBoardSoundFile::GetLength()
203 bool MMBoardSoundFile::IsStopped()
205 return m_file_stream
->IsStopped();
208 bool MMBoardSoundFile::IsPaused()
210 return m_file_stream
->IsPaused();
213 MMBoardTime
MMBoardSoundFile::GetPosition()
215 wxUint32 length
, seconds
;
216 MMBoardTime file_time
;
218 file_time
.seconds
= file_time
.minutes
= file_time
.hours
= 0;
219 if (m_file_stream
->IsStopped())
222 length
= m_file_stream
->GetPosition();
223 seconds
= m_file_stream
->GetSoundFormat().GetTimeFromBytes(length
);
224 file_time
.seconds
= seconds
% 60;
225 file_time
.minutes
= (seconds
/ 60) % 60;
226 file_time
.hours
= seconds
/ 3600;
231 void MMBoardSoundFile::SetPosition(MMBoardTime btime
)
235 itime
= btime
.seconds
+ btime
.minutes
* 60 + btime
.hours
;
237 m_file_stream
->SetPosition(
238 m_file_stream
->GetSoundFormat().GetBytesFromTime(itime
)
242 bool MMBoardSoundFile::NeedWindow()
247 void MMBoardSoundFile::SetWindow(wxWindow
*WXUNUSED(window
))
251 void MMBoardSoundFile::Play()
253 m_file_stream
->Play();
256 void MMBoardSoundFile::Pause()
258 m_file_stream
->Pause();
261 void MMBoardSoundFile::Resume()
263 m_file_stream
->Resume();
266 void MMBoardSoundFile::Stop()
268 m_file_stream
->Stop();
271 wxString
MMBoardSoundFile::GetStringType()
273 switch (m_file_type
) {
275 return wxString(wxT("WAVE file"));
277 // break is not reachable after return
281 return wxString(wxT("AIFF file"));
283 // break is not reachable after return
287 // default moved outside switch for those compilers
288 // which complain about lack of return in function
290 return wxString(wxT("Unknown file"));
294 return wxString(wxT("Unknown file"));
297 wxString
MMBoardSoundFile::GetStringInformation()
300 wxSoundFormatBase
*format
;
302 format
= &(m_file_stream
->GetSoundFormat());
304 info
= wxT("Data encoding: ");
305 switch (format
->GetType()) {
307 wxSoundFormatPcm
*pcm_format
= (wxSoundFormatPcm
*)format
;
309 info
+= wxString::Format(wxT("PCM %s %s\n"),
310 pcm_format
->Signed() ? wxT("signed") : wxT("unsigned"),
311 pcm_format
->GetOrder() == wxLITTLE_ENDIAN
? wxT("little endian") : wxT("big endian"));
312 info
+= wxString::Format(wxT("Sampling rate: %d\n")
313 wxT("Bits per sample: %d\n")
314 wxT("Number of channels: %d\n"),
315 pcm_format
->GetSampleRate(),
316 pcm_format
->GetBPS(),
317 pcm_format
->GetChannels());
321 case wxSOUND_MSADPCM
: {
322 wxSoundFormatMSAdpcm
*adpcm_format
= (wxSoundFormatMSAdpcm
*)format
;
324 info
+= wxString::Format(wxT("Microsoft ADPCM\n"));
325 info
+= wxString::Format(wxT("Sampling Rate: %d\n")
326 wxT("Number of channels: %d\n"),
327 adpcm_format
->GetSampleRate(),
328 adpcm_format
->GetChannels());
332 wxSoundFormatUlaw
*ulaw_format
= (wxSoundFormatUlaw
*)format
;
333 info
+= wxT("ULAW\n");
334 info
+= wxString::Format(wxT("Sampling rate: %d\n"), ulaw_format
->GetSampleRate());
338 info
+= wxT("Unknown");
344 // ----------------------------------------------------------------------------
347 // ----------------------------------------------------------------------------
350 MMBoardVideoFile::MMBoardVideoFile(const wxString
& filename
)
352 m_output_window
= NULL
;
354 #if defined(__UNIX__) && !defined(__CYGWIN__)
355 m_video_driver
= new wxVideoXANIM(filename
);
356 #elif defined(__WINDOWS__) && !defined(__MINGW32__) && !defined(__WATCOMC__) && !defined(__CYGWIN__)
357 // versions of Open Watcom and MinGW tested against this source does not
358 // deliver "digitalv.h" required in this feature
359 m_video_driver
= new wxVideoWindows(filename
);
361 wxUnusedVar(filename
);
362 m_video_driver
= NULL
;
363 SetError(MMBoard_UnknownFile
);
367 MMBoardVideoFile::~MMBoardVideoFile()
370 delete m_video_driver
;
373 bool MMBoardVideoFile::NeedWindow()
378 void MMBoardVideoFile::SetWindow(wxWindow
*window
)
380 m_output_window
= window
;
381 m_video_driver
->AttachOutput(*window
);
384 m_video_driver
->GetSize(size
);
385 window
->SetSize(size
);
388 // window->GetParent()->GetSizer()->Fit(window->GetParent());
391 void MMBoardVideoFile::Play()
393 m_video_driver
->Play();
396 void MMBoardVideoFile::Pause()
398 m_video_driver
->Pause();
401 void MMBoardVideoFile::Resume()
403 m_video_driver
->Resume();
406 void MMBoardVideoFile::Stop()
408 m_video_driver
->Stop();
411 MMBoardTime
MMBoardVideoFile::GetPosition()
415 btime
.seconds
= btime
.minutes
= btime
.hours
= 0;
419 MMBoardTime
MMBoardVideoFile::GetLength()
424 frameTime
= (int)( m_video_driver
->GetNbFrames() / m_video_driver
->GetFrameRate());
426 btime
.seconds
= frameTime
% 60;
427 btime
.minutes
= (frameTime
/ 60) % 60;
428 btime
.hours
= frameTime
/ 3600;
432 void MMBoardVideoFile::SetPosition(MMBoardTime
WXUNUSED(btime
))
436 bool MMBoardVideoFile::IsStopped()
438 return m_video_driver
->IsStopped();
441 bool MMBoardVideoFile::IsPaused()
443 return m_video_driver
->IsPaused();
446 wxString
MMBoardVideoFile::GetStringType()
448 return wxString(wxT("Video XANIM"));
451 wxString
MMBoardVideoFile::GetStringInformation()
455 info
= wxT("Video codec: ");
456 info
+= m_video_driver
->GetMovieCodec() + _T("\n");
457 info
+= wxT("Audio codec: ");
458 info
+= m_video_driver
->GetAudioCodec();
459 info
+= wxString::Format(_T(" Sample rate: %d Channels: %d\n"), m_video_driver
->GetSampleRate(),
460 m_video_driver
->GetBPS());
461 info
+= wxString::Format(_T(" Frame rate: %.01f"), m_video_driver
->GetFrameRate());
465 // ----------------------------------------------------------------------------
467 // ----------------------------------------------------------------------------
470 MMBoardFile::MMBoardFile()
475 MMBoardFile::~MMBoardFile()
480 // ----------------------------------------------------------------------------
482 // ----------------------------------------------------------------------------
485 MMBoardFile
*MMBoardManager::Open(const wxString
& filename
)
489 // Test the audio codec
490 file
= new MMBoardSoundFile(filename
);
491 if (!file
->GetError())
495 // Test the video codec
496 file
= new MMBoardVideoFile(filename
);
497 if (!file
->GetError())
501 // Arrrgh, we just could not see what is that file ...
505 DECLARE_APP(MMBoardApp
)
507 wxSoundStream
*MMBoardManager::OpenSoundStream()
510 if ((wxGetApp().m_caps
& MM_SOUND_WIN
) != 0)
511 return new wxSoundStreamWin();
513 if ((wxGetApp().m_caps
& MM_SOUND_ESD
) != 0)
514 return new wxSoundStreamESD();
516 if ((wxGetApp().m_caps
& MM_SOUND_OSS
) != 0)
517 return new wxSoundStreamOSS();
520 wxMessageBox(_T("You are trying to open a multimedia but you have not devices"), _T("Error"), wxOK
| wxICON_ERROR
, NULL
);
525 void MMBoardManager::UnrefSoundStream(wxSoundStream
*stream
)
530 // ----------------------------------------------------------------------------