]>
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
+= 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
);
364 window
->GetParent()->GetSizer()->Fit(window
->GetParent());
367 void MMBoardVideoFile::Play()
369 m_video_driver
->Play();
372 void MMBoardVideoFile::Pause()
374 m_video_driver
->Pause();
377 void MMBoardVideoFile::Resume()
379 m_video_driver
->Resume();
382 void MMBoardVideoFile::Stop()
384 m_video_driver
->Stop();
387 MMBoardTime
MMBoardVideoFile::GetPosition()
391 btime
.seconds
= btime
.minutes
= btime
.hours
= 0;
395 MMBoardTime
MMBoardVideoFile::GetLength()
400 frameTime
= (int)( m_video_driver
->GetNbFrames() / m_video_driver
->GetFrameRate());
402 btime
.seconds
= frameTime
% 60;
403 btime
.minutes
= (frameTime
/ 60) % 60;
404 btime
.hours
= frameTime
/ 3600;
408 void MMBoardVideoFile::SetPosition(MMBoardTime btime
)
412 bool MMBoardVideoFile::IsStopped()
414 return m_video_driver
->IsStopped();
417 bool MMBoardVideoFile::IsPaused()
419 return m_video_driver
->IsPaused();
422 wxString
MMBoardVideoFile::GetStringType()
424 return wxString(wxT("Video XANIM"));
427 wxString
MMBoardVideoFile::GetStringInformation()
431 info
= wxT("Video codec: ");
432 info
+= m_video_driver
->GetMovieCodec() + "\n";
433 info
+= wxT("Audio codec: ");
434 info
+= m_video_driver
->GetAudioCodec();
435 info
+= wxString::Format(" Sample rate: %d Channels: %d\n", m_video_driver
->GetSampleRate(),
436 m_video_driver
->GetBPS());
437 info
+= wxString::Format(" Frame rate: %.01f", m_video_driver
->GetFrameRate());
441 // ----------------------------------------------------------------------------
443 // ----------------------------------------------------------------------------
446 MMBoardFile::MMBoardFile()
451 MMBoardFile::~MMBoardFile()
456 // ----------------------------------------------------------------------------
458 // ----------------------------------------------------------------------------
461 MMBoardFile
*MMBoardManager::Open(const wxString
& filename
)
465 // Test the audio codec
466 file
= new MMBoardSoundFile(filename
);
467 if (!file
->GetError())
471 // Test the video codec
472 file
= new MMBoardVideoFile(filename
);
473 if (!file
->GetError())
477 // Arrrgh, we just could not see what is that file ...
481 DECLARE_APP(MMBoardApp
)
483 wxSoundStream
*MMBoardManager::OpenSoundStream()
486 if ((wxGetApp().m_caps
& MM_SOUND_ESD
) != 0)
487 return new wxSoundStreamESD();
489 if ((wxGetApp().m_caps
& MM_SOUND_OSS
) != 0)
490 return new wxSoundStreamOSS();
494 if ((wxGetApp().m_caps
& MM_SOUND_WIN
) != 0)
495 return new wxSoundStreamWin();
498 wxMessageBox("You are trying to open a multimedia but you have not devices", "Error", wxOK
| wxICON_ERROR
, NULL
);
503 void MMBoardManager::UnrefSoundStream(wxSoundStream
*stream
)
508 // ----------------------------------------------------------------------------