]>
git.saurik.com Git - wxWidgets.git/blob - contrib/samples/mmedia/mmbman.cpp
ab4f5c8c5477e8465dfa0fbefa9ed853833292b1
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 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "mmbman.h"
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
27 // for all others, include the necessary headers (this file is usually all you
28 // need because it includes almost all "standard" wxWidgets headers
35 #include "wx/stream.h"
36 #include "wx/wfstream.h"
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"
44 #include "wx/mmedia/sndmsad.h"
47 #include "wx/mmedia/sndoss.h"
48 #include "wx/mmedia/sndesd.h"
52 #include "wx/mmedia/sndwin.h"
55 #include "wx/mmedia/vidbase.h"
57 #include "wx/mmedia/vidxanm.h"
61 #include "wx/mmedia/vidwin.h"
67 // ----------------------------------------------------------------------------
68 // Private class definitions
69 // ----------------------------------------------------------------------------
71 class MMBoardSoundFile
: public MMBoardFile
{
73 MMBoardSoundFile(const wxString
& filename
);
78 void SetWindow(wxWindow
*window
);
85 MMBoardTime
GetPosition();
86 MMBoardTime
GetLength();
87 void SetPosition(MMBoardTime btime
);
92 wxString
GetStringType();
93 wxString
GetStringInformation();
96 wxSoundFileStream
*GetDecoder();
98 wxSoundStream
*m_output_stream
;
99 wxInputStream
*m_input_stream
;
100 wxSoundFileStream
*m_file_stream
;
102 MMBoardTime m_length
;
106 class MMBoardVideoFile
: public MMBoardFile
{
108 MMBoardVideoFile(const wxString
& filename
);
113 void SetWindow(wxWindow
*window
);
120 MMBoardTime
GetPosition();
121 MMBoardTime
GetLength();
122 void SetPosition(MMBoardTime btime
);
127 wxString
GetStringType();
128 wxString
GetStringInformation();
131 wxWindow
*m_output_window
;
132 wxVideoBaseDriver
*m_video_driver
;
135 // ----------------------------------------------------------------------------
137 // ----------------------------------------------------------------------------
139 #define MMBoard_UNKNOWNTYPE 0
140 #define MMBoard_WAVE 1
141 #define MMBoard_AIFF 2
143 // ----------------------------------------------------------------------------
146 MMBoardSoundFile::MMBoardSoundFile(const wxString
& filename
)
149 m_input_stream
= new wxFileInputStream(filename
);
150 m_output_stream
= MMBoardManager::OpenSoundStream();
152 m_file_stream
= GetDecoder();
154 if (!m_file_stream
) {
155 SetError(MMBoard_UnknownFile
);
160 wxUint32 length
, seconds
;
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;
169 MMBoardSoundFile::~MMBoardSoundFile()
172 delete m_file_stream
;
173 MMBoardManager::UnrefSoundStream(m_output_stream
);
174 delete m_input_stream
;
177 wxSoundFileStream
*MMBoardSoundFile::GetDecoder()
179 wxSoundFileStream
*f_stream
;
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())
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())
195 m_file_type
= MMBoard_UNKNOWNTYPE
;
202 MMBoardTime
MMBoardSoundFile::GetLength()
207 bool MMBoardSoundFile::IsStopped()
209 return m_file_stream
->IsStopped();
212 bool MMBoardSoundFile::IsPaused()
214 return m_file_stream
->IsPaused();
217 MMBoardTime
MMBoardSoundFile::GetPosition()
219 wxUint32 length
, seconds
;
220 MMBoardTime file_time
;
222 file_time
.seconds
= file_time
.minutes
= file_time
.hours
= 0;
223 if (m_file_stream
->IsStopped())
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;
235 void MMBoardSoundFile::SetPosition(MMBoardTime btime
)
239 itime
= btime
.seconds
+ btime
.minutes
* 60 + btime
.hours
;
241 m_file_stream
->SetPosition(
242 m_file_stream
->GetSoundFormat().GetBytesFromTime(itime
)
246 bool MMBoardSoundFile::NeedWindow()
251 void MMBoardSoundFile::SetWindow(wxWindow
*WXUNUSED(window
))
255 void MMBoardSoundFile::Play()
257 m_file_stream
->Play();
260 void MMBoardSoundFile::Pause()
262 m_file_stream
->Pause();
265 void MMBoardSoundFile::Resume()
267 m_file_stream
->Resume();
270 void MMBoardSoundFile::Stop()
272 m_file_stream
->Stop();
275 wxString
MMBoardSoundFile::GetStringType()
277 switch (m_file_type
) {
279 return wxString(wxT("WAVE file"));
281 // break is not reachable after return
285 return wxString(wxT("AIFF file"));
287 // break is not reachable after return
291 // default moved outside switch for those compilers
292 // which complain about lack of return in function
294 return wxString(wxT("Unknown file"));
298 return wxString(wxT("Unknown file"));
301 wxString
MMBoardSoundFile::GetStringInformation()
304 wxSoundFormatBase
*format
;
306 format
= &(m_file_stream
->GetSoundFormat());
308 info
= wxT("Data encoding: ");
309 switch (format
->GetType()) {
311 wxSoundFormatPcm
*pcm_format
= (wxSoundFormatPcm
*)format
;
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());
325 case wxSOUND_MSADPCM
: {
326 wxSoundFormatMSAdpcm
*adpcm_format
= (wxSoundFormatMSAdpcm
*)format
;
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());
336 wxSoundFormatUlaw
*ulaw_format
= (wxSoundFormatUlaw
*)format
;
337 info
+= wxT("ULAW\n");
338 info
+= wxString::Format(wxT("Sampling rate: %d\n"), ulaw_format
->GetSampleRate());
342 info
+= wxT("Unknown");
348 // ----------------------------------------------------------------------------
351 // ----------------------------------------------------------------------------
354 MMBoardVideoFile::MMBoardVideoFile(const wxString
& filename
)
356 m_output_window
= NULL
;
358 #if defined(__UNIX__) && !defined(__CYGWIN__)
359 m_video_driver
= new wxVideoXANIM(filename
);
360 #elif defined(__WINDOWS__) && !defined(__MINGW32__) && !defined(__WATCOMC__) && !defined(__CYGWIN__)
361 // versions of Open Watcom and MinGW tested against this source does not
362 // deliver "digitalv.h" required in this feature
363 m_video_driver
= new wxVideoWindows(filename
);
365 wxUnusedVar(filename
);
366 m_video_driver
= NULL
;
367 SetError(MMBoard_UnknownFile
);
371 MMBoardVideoFile::~MMBoardVideoFile()
374 delete m_video_driver
;
377 bool MMBoardVideoFile::NeedWindow()
382 void MMBoardVideoFile::SetWindow(wxWindow
*window
)
384 m_output_window
= window
;
385 m_video_driver
->AttachOutput(*window
);
388 m_video_driver
->GetSize(size
);
389 window
->SetSize(size
);
392 // window->GetParent()->GetSizer()->Fit(window->GetParent());
395 void MMBoardVideoFile::Play()
397 m_video_driver
->Play();
400 void MMBoardVideoFile::Pause()
402 m_video_driver
->Pause();
405 void MMBoardVideoFile::Resume()
407 m_video_driver
->Resume();
410 void MMBoardVideoFile::Stop()
412 m_video_driver
->Stop();
415 MMBoardTime
MMBoardVideoFile::GetPosition()
419 btime
.seconds
= btime
.minutes
= btime
.hours
= 0;
423 MMBoardTime
MMBoardVideoFile::GetLength()
428 frameTime
= (int)( m_video_driver
->GetNbFrames() / m_video_driver
->GetFrameRate());
430 btime
.seconds
= frameTime
% 60;
431 btime
.minutes
= (frameTime
/ 60) % 60;
432 btime
.hours
= frameTime
/ 3600;
436 void MMBoardVideoFile::SetPosition(MMBoardTime
WXUNUSED(btime
))
440 bool MMBoardVideoFile::IsStopped()
442 return m_video_driver
->IsStopped();
445 bool MMBoardVideoFile::IsPaused()
447 return m_video_driver
->IsPaused();
450 wxString
MMBoardVideoFile::GetStringType()
452 return wxString(wxT("Video XANIM"));
455 wxString
MMBoardVideoFile::GetStringInformation()
459 info
= wxT("Video codec: ");
460 info
+= m_video_driver
->GetMovieCodec() + _T("\n");
461 info
+= wxT("Audio codec: ");
462 info
+= m_video_driver
->GetAudioCodec();
463 info
+= wxString::Format(_T(" Sample rate: %d Channels: %d\n"), m_video_driver
->GetSampleRate(),
464 m_video_driver
->GetBPS());
465 info
+= wxString::Format(_T(" Frame rate: %.01f"), m_video_driver
->GetFrameRate());
469 // ----------------------------------------------------------------------------
471 // ----------------------------------------------------------------------------
474 MMBoardFile::MMBoardFile()
479 MMBoardFile::~MMBoardFile()
484 // ----------------------------------------------------------------------------
486 // ----------------------------------------------------------------------------
489 MMBoardFile
*MMBoardManager::Open(const wxString
& filename
)
493 // Test the audio codec
494 file
= new MMBoardSoundFile(filename
);
495 if (!file
->GetError())
499 // Test the video codec
500 file
= new MMBoardVideoFile(filename
);
501 if (!file
->GetError())
505 // Arrrgh, we just could not see what is that file ...
509 DECLARE_APP(MMBoardApp
)
511 wxSoundStream
*MMBoardManager::OpenSoundStream()
514 if ((wxGetApp().m_caps
& MM_SOUND_WIN
) != 0)
515 return new wxSoundStreamWin();
517 if ((wxGetApp().m_caps
& MM_SOUND_ESD
) != 0)
518 return new wxSoundStreamESD();
520 if ((wxGetApp().m_caps
& MM_SOUND_OSS
) != 0)
521 return new wxSoundStreamOSS();
524 wxMessageBox(_T("You are trying to open a multimedia but you have not devices"), _T("Error"), wxOK
| wxICON_ERROR
, NULL
);
529 void MMBoardManager::UnrefSoundStream(wxSoundStream
*stream
)
534 // ----------------------------------------------------------------------------