]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia2/board/mmbman.cpp
61f5f29b85987deea6d603b0758b31a48b406ce4
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();
90 wxString
GetStringType();
91 wxString
GetStringInformation();
94 wxSoundFileStream
*GetDecoder();
96 wxSoundStream
*m_output_stream
;
97 wxInputStream
*m_input_stream
;
98 wxSoundFileStream
*m_file_stream
;
100 MMBoardTime m_length
;
104 class MMBoardVideoFile
: public MMBoardFile
{
106 MMBoardVideoFile(const wxString
& filename
);
111 void SetWindow(wxWindow
*window
);
118 MMBoardTime
GetPosition();
119 MMBoardTime
GetLength();
124 wxString
GetStringType();
125 wxString
GetStringInformation();
128 wxWindow
*m_output_window
;
129 wxVideoBaseDriver
*m_video_driver
;
132 // ----------------------------------------------------------------------------
134 // ----------------------------------------------------------------------------
136 #define MMBoard_UNKNOWNTYPE 0
137 #define MMBoard_WAVE 1
138 #define MMBoard_AIFF 2
140 // ----------------------------------------------------------------------------
143 MMBoardSoundFile::MMBoardSoundFile(const wxString
& filename
)
146 m_input_stream
= new wxFileInputStream(filename
);
147 m_output_stream
= MMBoardManager::OpenSoundStream();
149 m_file_stream
= GetDecoder();
151 if (!m_file_stream
) {
152 SetError(MMBoard_UnknownFile
);
157 wxUint32 length
, seconds
;
159 length
= m_file_stream
->GetLength();
160 seconds
= m_file_stream
->GetSoundFormat().GetTimeFromBytes(length
);
161 m_length
.seconds
= seconds
% 60;
162 m_length
.minutes
= (seconds
/ 60) % 60;
163 m_length
.hours
= seconds
/ 3600;
166 MMBoardSoundFile::~MMBoardSoundFile()
169 delete m_file_stream
;
170 MMBoardManager::UnrefSoundStream(m_output_stream
);
171 delete m_input_stream
;
174 wxSoundFileStream
*MMBoardSoundFile::GetDecoder()
176 wxSoundFileStream
*f_stream
;
178 // First, we try a Wave decoder
179 f_stream
= new wxSoundWave(*m_input_stream
, *m_output_stream
);
180 m_file_type
= MMBoard_WAVE
;
181 if (f_stream
->CanRead())
185 // Then, a AIFF decoder
186 f_stream
= new wxSoundAiff(*m_input_stream
, *m_output_stream
);
187 m_file_type
= MMBoard_AIFF
;
188 if (f_stream
->CanRead())
192 m_file_type
= MMBoard_UNKNOWNTYPE
;
199 MMBoardTime
MMBoardSoundFile::GetLength()
204 bool MMBoardSoundFile::IsStopped()
206 return m_file_stream
->IsStopped();
209 bool MMBoardSoundFile::IsPaused()
211 return m_file_stream
->IsPaused();
214 MMBoardTime
MMBoardSoundFile::GetPosition()
216 wxUint32 length
, seconds
;
217 MMBoardTime file_time
;
219 file_time
.seconds
= file_time
.minutes
= file_time
.hours
= 0;
220 if (m_file_stream
->IsStopped())
223 length
= m_file_stream
->GetPosition();
224 seconds
= m_file_stream
->GetSoundFormat().GetTimeFromBytes(length
);
225 file_time
.seconds
= seconds
% 60;
226 file_time
.minutes
= (seconds
/ 60) % 60;
227 file_time
.hours
= seconds
/ 3600;
232 bool MMBoardSoundFile::NeedWindow()
237 void MMBoardSoundFile::SetWindow(wxWindow
*window
)
241 void MMBoardSoundFile::Play()
243 m_file_stream
->Play();
246 void MMBoardSoundFile::Pause()
248 m_file_stream
->Pause();
251 void MMBoardSoundFile::Resume()
253 m_file_stream
->Resume();
256 void MMBoardSoundFile::Stop()
258 m_file_stream
->Stop();
261 wxString
MMBoardSoundFile::GetStringType()
263 switch (m_file_type
) {
265 return wxString(wxT("WAVE file"));
268 return wxString(wxT("AIFF file"));
271 return wxString(wxT("Unknown file"));
276 wxString
MMBoardSoundFile::GetStringInformation()
279 wxSoundFormatBase
*format
;
281 format
= &(m_file_stream
->GetSoundFormat());
283 info
= wxT("Data encoding: ");
284 switch (format
->GetType()) {
286 wxSoundFormatPcm
*pcm_format
= (wxSoundFormatPcm
*)format
;
288 info
+= wxT("PCM\n");
289 info
+= wxString::Format(wxT("Sampling rate: %d\n")
290 wxT("Bits per sample: %d\n")
291 wxT("Number of channels: %d\n"),
292 pcm_format
->GetSampleRate(),
293 pcm_format
->GetBPS(),
294 pcm_format
->GetChannels());
299 wxSoundFormatUlaw
*ulaw_format
= (wxSoundFormatUlaw
*)format
;
300 info
+= wxT("ULAW\n");
301 info
+= wxString::Format(wxT("Sampling rate: %d\n"), ulaw_format
->GetSampleRate());
305 info
+= wxT("Unknown");
311 // ----------------------------------------------------------------------------
314 // ----------------------------------------------------------------------------
317 MMBoardVideoFile::MMBoardVideoFile(const wxString
& filename
)
319 m_output_window
= NULL
;
321 #if defined(__UNIX__)
322 m_video_driver
= new wxVideoXANIM(filename
);
323 #elif defined(__WIN32__)
324 m_video_driver
= new wxVideoWindows(filename
);
326 m_video_driver
= NULL
;
327 SetError(MMBoard_UnknownFile
);
331 MMBoardVideoFile::~MMBoardVideoFile()
334 delete m_video_driver
;
337 bool MMBoardVideoFile::NeedWindow()
342 void MMBoardVideoFile::SetWindow(wxWindow
*window
)
344 m_output_window
= window
;
345 m_video_driver
->AttachOutput(*window
);
348 m_video_driver
->GetSize(size
);
349 window
->SetSize(size
);
351 window
->GetParent()->GetSizer()->Fit(window
->GetParent());
354 void MMBoardVideoFile::Play()
356 m_video_driver
->Play();
359 void MMBoardVideoFile::Pause()
361 m_video_driver
->Pause();
364 void MMBoardVideoFile::Resume()
366 m_video_driver
->Resume();
369 void MMBoardVideoFile::Stop()
371 m_video_driver
->Stop();
374 MMBoardTime
MMBoardVideoFile::GetPosition()
378 btime
.seconds
= btime
.minutes
= btime
.hours
= 0;
382 MMBoardTime
MMBoardVideoFile::GetLength()
387 frameTime
= (int)( m_video_driver
->GetNbFrames() / m_video_driver
->GetFrameRate());
389 btime
.seconds
= frameTime
% 60;
390 btime
.minutes
= (frameTime
/ 60) % 60;
391 btime
.hours
= frameTime
/ 3600;
395 bool MMBoardVideoFile::IsStopped()
397 return m_video_driver
->IsStopped();
400 bool MMBoardVideoFile::IsPaused()
402 return m_video_driver
->IsPaused();
405 wxString
MMBoardVideoFile::GetStringType()
407 return wxString(wxT("Video XANIM"));
410 wxString
MMBoardVideoFile::GetStringInformation()
414 info
= wxT("Video codec: ");
415 info
+= m_video_driver
->GetMovieCodec() + "\n";
416 info
+= wxT("Audio codec: ");
417 info
+= m_video_driver
->GetAudioCodec();
418 info
+= wxString::Format(" Sample rate: %d Channels: %d\n", m_video_driver
->GetSampleRate(),
419 m_video_driver
->GetBPS());
420 info
+= wxString::Format(" Frame rate: %.01f", m_video_driver
->GetFrameRate());
424 // ----------------------------------------------------------------------------
426 // ----------------------------------------------------------------------------
429 MMBoardFile::MMBoardFile()
434 MMBoardFile::~MMBoardFile()
439 // ----------------------------------------------------------------------------
441 // ----------------------------------------------------------------------------
444 MMBoardFile
*MMBoardManager::Open(const wxString
& filename
)
448 // Test the audio codec
449 file
= new MMBoardSoundFile(filename
);
450 if (!file
->GetError())
454 // Test the video codec
455 file
= new MMBoardVideoFile(filename
);
456 if (!file
->GetError())
460 // Arrrgh, we just could not see what is that file ...
464 DECLARE_APP(MMBoardApp
)
466 wxSoundStream
*MMBoardManager::OpenSoundStream()
469 if ((wxGetApp().m_caps
& MM_SOUND_ESD
) != 0)
470 return new wxSoundStreamESD();
472 if ((wxGetApp().m_caps
& MM_SOUND_OSS
) != 0)
473 return new wxSoundStreamOSS();
477 if ((wxGetApp().m_caps
& MM_SOUND_WIN
) != 0)
478 return new wxSoundStreamWin();
481 wxMessageBox("You are trying to open a multimedia but you have not devices", "Error", wxOK
| wxICON_ERROR
, NULL
);
486 void MMBoardManager::UnrefSoundStream(wxSoundStream
*stream
)
491 // ----------------------------------------------------------------------------