]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia2/board/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 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "mmbman.cpp"
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" wxWindows headers
35 #include "wx/stream.h"
36 #include "wx/wfstream.h"
66 // ----------------------------------------------------------------------------
67 // Private class definitions
68 // ----------------------------------------------------------------------------
70 class MMBoardSoundFile
: public MMBoardFile
{
72 MMBoardSoundFile(const wxString
& filename
);
77 void SetWindow(wxWindow
*window
);
84 MMBoardTime
GetPosition();
85 MMBoardTime
GetLength();
86 void SetPosition(MMBoardTime btime
);
91 wxString
GetStringType();
92 wxString
GetStringInformation();
95 wxSoundFileStream
*GetDecoder();
97 wxSoundStream
*m_output_stream
;
98 wxInputStream
*m_input_stream
;
99 wxSoundFileStream
*m_file_stream
;
101 MMBoardTime m_length
;
105 class MMBoardVideoFile
: public MMBoardFile
{
107 MMBoardVideoFile(const wxString
& filename
);
112 void SetWindow(wxWindow
*window
);
119 MMBoardTime
GetPosition();
120 MMBoardTime
GetLength();
121 void SetPosition(MMBoardTime btime
);
126 wxString
GetStringType();
127 wxString
GetStringInformation();
130 wxWindow
*m_output_window
;
131 wxVideoBaseDriver
*m_video_driver
;
134 // ----------------------------------------------------------------------------
136 // ----------------------------------------------------------------------------
138 #define MMBoard_UNKNOWNTYPE 0
139 #define MMBoard_WAVE 1
140 #define MMBoard_AIFF 2
142 // ----------------------------------------------------------------------------
145 MMBoardSoundFile::MMBoardSoundFile(const wxString
& filename
)
148 m_input_stream
= new wxFileInputStream(filename
);
149 m_output_stream
= MMBoardManager::OpenSoundStream();
151 m_file_stream
= GetDecoder();
153 if (!m_file_stream
) {
154 SetError(MMBoard_UnknownFile
);
159 wxUint32 length
, seconds
;
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;
168 MMBoardSoundFile::~MMBoardSoundFile()
171 delete m_file_stream
;
172 MMBoardManager::UnrefSoundStream(m_output_stream
);
173 delete m_input_stream
;
176 wxSoundFileStream
*MMBoardSoundFile::GetDecoder()
178 wxSoundFileStream
*f_stream
;
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())
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())
194 m_file_type
= MMBoard_UNKNOWNTYPE
;
201 MMBoardTime
MMBoardSoundFile::GetLength()
206 bool MMBoardSoundFile::IsStopped()
208 return m_file_stream
->IsStopped();
211 bool MMBoardSoundFile::IsPaused()
213 return m_file_stream
->IsPaused();
216 MMBoardTime
MMBoardSoundFile::GetPosition()
218 wxUint32 length
, seconds
;
219 MMBoardTime file_time
;
221 file_time
.seconds
= file_time
.minutes
= file_time
.hours
= 0;
222 if (m_file_stream
->IsStopped())
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;
234 void MMBoardSoundFile::SetPosition(MMBoardTime btime
)
238 itime
= btime
.seconds
+ btime
.minutes
* 60 + btime
.hours
;
240 m_file_stream
->SetPosition(
241 m_file_stream
->GetSoundFormat().GetBytesFromTime(itime
)
245 bool MMBoardSoundFile::NeedWindow()
250 void MMBoardSoundFile::SetWindow(wxWindow
*window
)
254 void MMBoardSoundFile::Play()
256 m_file_stream
->Play();
259 void MMBoardSoundFile::Pause()
261 m_file_stream
->Pause();
264 void MMBoardSoundFile::Resume()
266 m_file_stream
->Resume();
269 void MMBoardSoundFile::Stop()
271 m_file_stream
->Stop();
274 wxString
MMBoardSoundFile::GetStringType()
276 switch (m_file_type
) {
278 return wxString(wxT("WAVE file"));
281 return wxString(wxT("AIFF file"));
284 return wxString(wxT("Unknown file"));
289 wxString
MMBoardSoundFile::GetStringInformation()
292 wxSoundFormatBase
*format
;
294 format
= &(m_file_stream
->GetSoundFormat());
296 info
= wxT("Data encoding: ");
297 switch (format
->GetType()) {
299 wxSoundFormatPcm
*pcm_format
= (wxSoundFormatPcm
*)format
;
301 info
+= wxString::Format(wxT("PCM %s %s\n"),
302 pcm_format
->Signed() ? wxT("signed") : wxT("unsigned"),
303 pcm_format
->GetOrder() == wxLITTLE_ENDIAN
? wxT("little endian") : wxT("big endian"));
304 info
+= wxString::Format(wxT("Sampling rate: %d\n")
305 wxT("Bits per sample: %d\n")
306 wxT("Number of channels: %d\n"),
307 pcm_format
->GetSampleRate(),
308 pcm_format
->GetBPS(),
309 pcm_format
->GetChannels());
314 wxSoundFormatUlaw
*ulaw_format
= (wxSoundFormatUlaw
*)format
;
315 info
+= wxT("ULAW\n");
316 info
+= wxString::Format(wxT("Sampling rate: %d\n"), ulaw_format
->GetSampleRate());
320 info
+= wxT("Unknown");
326 // ----------------------------------------------------------------------------
329 // ----------------------------------------------------------------------------
332 MMBoardVideoFile::MMBoardVideoFile(const wxString
& filename
)
334 m_output_window
= NULL
;
336 #if defined(__UNIX__)
337 m_video_driver
= new wxVideoXANIM(filename
);
338 #elif defined(__WIN32__)
339 m_video_driver
= new wxVideoWindows(filename
);
341 m_video_driver
= NULL
;
342 SetError(MMBoard_UnknownFile
);
346 MMBoardVideoFile::~MMBoardVideoFile()
349 delete m_video_driver
;
352 bool MMBoardVideoFile::NeedWindow()
357 void MMBoardVideoFile::SetWindow(wxWindow
*window
)
359 m_output_window
= window
;
360 m_video_driver
->AttachOutput(*window
);
363 m_video_driver
->GetSize(size
);
364 window
->SetSize(size
);
367 // window->GetParent()->GetSizer()->Fit(window->GetParent());
370 void MMBoardVideoFile::Play()
372 m_video_driver
->Play();
375 void MMBoardVideoFile::Pause()
377 m_video_driver
->Pause();
380 void MMBoardVideoFile::Resume()
382 m_video_driver
->Resume();
385 void MMBoardVideoFile::Stop()
387 m_video_driver
->Stop();
390 MMBoardTime
MMBoardVideoFile::GetPosition()
394 btime
.seconds
= btime
.minutes
= btime
.hours
= 0;
398 MMBoardTime
MMBoardVideoFile::GetLength()
403 frameTime
= (int)( m_video_driver
->GetNbFrames() / m_video_driver
->GetFrameRate());
405 btime
.seconds
= frameTime
% 60;
406 btime
.minutes
= (frameTime
/ 60) % 60;
407 btime
.hours
= frameTime
/ 3600;
411 void MMBoardVideoFile::SetPosition(MMBoardTime btime
)
415 bool MMBoardVideoFile::IsStopped()
417 return m_video_driver
->IsStopped();
420 bool MMBoardVideoFile::IsPaused()
422 return m_video_driver
->IsPaused();
425 wxString
MMBoardVideoFile::GetStringType()
427 return wxString(wxT("Video XANIM"));
430 wxString
MMBoardVideoFile::GetStringInformation()
434 info
= wxT("Video codec: ");
435 info
+= m_video_driver
->GetMovieCodec() + "\n";
436 info
+= wxT("Audio codec: ");
437 info
+= m_video_driver
->GetAudioCodec();
438 info
+= wxString::Format(" Sample rate: %d Channels: %d\n", m_video_driver
->GetSampleRate(),
439 m_video_driver
->GetBPS());
440 info
+= wxString::Format(" Frame rate: %.01f", m_video_driver
->GetFrameRate());
444 // ----------------------------------------------------------------------------
446 // ----------------------------------------------------------------------------
449 MMBoardFile::MMBoardFile()
454 MMBoardFile::~MMBoardFile()
459 // ----------------------------------------------------------------------------
461 // ----------------------------------------------------------------------------
464 MMBoardFile
*MMBoardManager::Open(const wxString
& filename
)
468 // Test the audio codec
469 file
= new MMBoardSoundFile(filename
);
470 if (!file
->GetError())
474 // Test the video codec
475 file
= new MMBoardVideoFile(filename
);
476 if (!file
->GetError())
480 // Arrrgh, we just could not see what is that file ...
484 DECLARE_APP(MMBoardApp
)
486 wxSoundStream
*MMBoardManager::OpenSoundStream()
489 if ((wxGetApp().m_caps
& MM_SOUND_ESD
) != 0)
490 return new wxSoundStreamESD();
492 if ((wxGetApp().m_caps
& MM_SOUND_OSS
) != 0)
493 return new wxSoundStreamOSS();
497 if ((wxGetApp().m_caps
& MM_SOUND_WIN
) != 0)
498 return new wxSoundStreamWin();
501 wxMessageBox("You are trying to open a multimedia but you have not devices", "Error", wxOK
| wxICON_ERROR
, NULL
);
506 void MMBoardManager::UnrefSoundStream(wxSoundStream
*stream
)
511 // ----------------------------------------------------------------------------