]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia2/board/mmbman.cpp
7f875c2b8f5bc97a3d97b77e5a2cc180e7af88bd
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
+= 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());
312 wxSoundFormatUlaw
*ulaw_format
= (wxSoundFormatUlaw
*)format
;
313 info
+= wxT("ULAW\n");
314 info
+= wxString::Format(wxT("Sampling rate: %d\n"), ulaw_format
->GetSampleRate());
318 info
+= wxT("Unknown");
324 // ----------------------------------------------------------------------------
327 // ----------------------------------------------------------------------------
330 MMBoardVideoFile::MMBoardVideoFile(const wxString
& filename
)
332 m_output_window
= NULL
;
334 #if defined(__UNIX__)
335 m_video_driver
= new wxVideoXANIM(filename
);
336 #elif defined(__WIN32__)
337 m_video_driver
= new wxVideoWindows(filename
);
339 m_video_driver
= NULL
;
340 SetError(MMBoard_UnknownFile
);
344 MMBoardVideoFile::~MMBoardVideoFile()
347 delete m_video_driver
;
350 bool MMBoardVideoFile::NeedWindow()
355 void MMBoardVideoFile::SetWindow(wxWindow
*window
)
357 m_output_window
= window
;
358 m_video_driver
->AttachOutput(*window
);
361 m_video_driver
->GetSize(size
);
362 window
->SetSize(size
);
365 // window->GetParent()->GetSizer()->Fit(window->GetParent());
368 void MMBoardVideoFile::Play()
370 m_video_driver
->Play();
373 void MMBoardVideoFile::Pause()
375 m_video_driver
->Pause();
378 void MMBoardVideoFile::Resume()
380 m_video_driver
->Resume();
383 void MMBoardVideoFile::Stop()
385 m_video_driver
->Stop();
388 MMBoardTime
MMBoardVideoFile::GetPosition()
392 btime
.seconds
= btime
.minutes
= btime
.hours
= 0;
396 MMBoardTime
MMBoardVideoFile::GetLength()
401 frameTime
= (int)( m_video_driver
->GetNbFrames() / m_video_driver
->GetFrameRate());
403 btime
.seconds
= frameTime
% 60;
404 btime
.minutes
= (frameTime
/ 60) % 60;
405 btime
.hours
= frameTime
/ 3600;
409 void MMBoardVideoFile::SetPosition(MMBoardTime btime
)
413 bool MMBoardVideoFile::IsStopped()
415 return m_video_driver
->IsStopped();
418 bool MMBoardVideoFile::IsPaused()
420 return m_video_driver
->IsPaused();
423 wxString
MMBoardVideoFile::GetStringType()
425 return wxString(wxT("Video XANIM"));
428 wxString
MMBoardVideoFile::GetStringInformation()
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());
442 // ----------------------------------------------------------------------------
444 // ----------------------------------------------------------------------------
447 MMBoardFile::MMBoardFile()
452 MMBoardFile::~MMBoardFile()
457 // ----------------------------------------------------------------------------
459 // ----------------------------------------------------------------------------
462 MMBoardFile
*MMBoardManager::Open(const wxString
& filename
)
466 // Test the audio codec
467 file
= new MMBoardSoundFile(filename
);
468 if (!file
->GetError())
472 // Test the video codec
473 file
= new MMBoardVideoFile(filename
);
474 if (!file
->GetError())
478 // Arrrgh, we just could not see what is that file ...
482 DECLARE_APP(MMBoardApp
)
484 wxSoundStream
*MMBoardManager::OpenSoundStream()
487 if ((wxGetApp().m_caps
& MM_SOUND_ESD
) != 0)
488 return new wxSoundStreamESD();
490 if ((wxGetApp().m_caps
& MM_SOUND_OSS
) != 0)
491 return new wxSoundStreamOSS();
495 if ((wxGetApp().m_caps
& MM_SOUND_WIN
) != 0)
496 return new wxSoundStreamWin();
499 wxMessageBox("You are trying to open a multimedia but you have not devices", "Error", wxOK
| wxICON_ERROR
, NULL
);
504 void MMBoardManager::UnrefSoundStream(wxSoundStream
*stream
)
509 // ----------------------------------------------------------------------------