From: Guilhem Lavaux Date: Tue, 22 Feb 2000 18:20:46 +0000 (+0000) Subject: AVI file playing on Windows is working X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/ebaad2ccc7fe8bc698af75206a208491779f032e AVI file playing on Windows is working Many fixes git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6219 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/utils/wxMMedia2/board/mmbman.cpp b/utils/wxMMedia2/board/mmbman.cpp index 9b8723a6d9..1c813e1624 100644 --- a/utils/wxMMedia2/board/mmbman.cpp +++ b/utils/wxMMedia2/board/mmbman.cpp @@ -263,50 +263,50 @@ wxString MMBoardSoundFile::GetStringType() { switch (m_file_type) { case MMBoard_WAVE: - return wxString("WAVE file"); + return wxString(wxT("WAVE file")); break; case MMBoard_AIFF: - return wxString("AIFF file"); + return wxString(wxT("AIFF file")); break; default: - return wxString("Unknown file"); + return wxString(wxT("Unknown file")); break; } } wxString MMBoardSoundFile::GetStringInformation() { - wxString info; - wxSoundFormatBase *format; - - format = &(m_file_stream->GetSoundFormat()); - - info = _T("Data encoding: "); - switch (format->GetType()) { - case wxSOUND_PCM: { - wxSoundFormatPcm *pcm_format = (wxSoundFormatPcm *)format; - - info += _T("PCM\n"); - info += wxString::Format(_T("Sampling rate: %d\n") - _T("Bits per sample: %d\n") - _T("Number of channels: %d\n"), - pcm_format->GetSampleRate(), - pcm_format->GetBPS(), - pcm_format->GetChannels()); - - break; - } - case wxSOUND_ULAW: { - wxSoundFormatUlaw *ulaw_format = (wxSoundFormatUlaw *)format; - info += _T("ULAW\n"); - info += wxString::Format(_T("Sampling rate: %d\n"), ulaw_format->GetSampleRate()); - break; - } - default: - info += _T("Unknown"); - break; - } - return info; + wxString info; + wxSoundFormatBase *format; + + format = &(m_file_stream->GetSoundFormat()); + + info = wxT("Data encoding: "); + switch (format->GetType()) { + case wxSOUND_PCM: { + wxSoundFormatPcm *pcm_format = (wxSoundFormatPcm *)format; + + info += wxT("PCM\n"); + info += wxString::Format(wxT("Sampling rate: %d\n") + wxT("Bits per sample: %d\n") + wxT("Number of channels: %d\n"), + pcm_format->GetSampleRate(), + pcm_format->GetBPS(), + pcm_format->GetChannels()); + + break; + } + case wxSOUND_ULAW: { + wxSoundFormatUlaw *ulaw_format = (wxSoundFormatUlaw *)format; + info += wxT("ULAW\n"); + info += wxString::Format(wxT("Sampling rate: %d\n"), ulaw_format->GetSampleRate()); + break; + } + default: + info += wxT("Unknown"); + break; + } + return info; } // ---------------------------------------------------------------------------- @@ -317,93 +317,92 @@ wxString MMBoardSoundFile::GetStringInformation() MMBoardVideoFile::MMBoardVideoFile(const wxString& filename) { - m_output_window = NULL; - m_input_stream = new wxFileInputStream(filename); + m_output_window = NULL; #if defined(__UNIX__) - m_video_driver = new wxVideoXANIM(*m_input_stream); + m_video_driver = new wxVideoXANIM(filename); #elif defined(__WIN32__) - m_video_driver = new wxVideoWindows(m_input_stream); + m_video_driver = new wxVideoWindows(filename); #else - m_video_driver = NULL; - SetError(MMBoard_UnknownFile); + m_video_driver = NULL; + SetError(MMBoard_UnknownFile); #endif } MMBoardVideoFile::~MMBoardVideoFile() { - if (m_video_driver) - delete m_video_driver; + if (m_video_driver) + delete m_video_driver; - delete m_input_stream; + delete m_input_stream; } bool MMBoardVideoFile::NeedWindow() { - return TRUE; + return TRUE; } void MMBoardVideoFile::SetWindow(wxWindow *window) { - m_output_window = window; - m_video_driver->AttachOutput(*window); + m_output_window = window; + m_video_driver->AttachOutput(*window); } void MMBoardVideoFile::Play() { - m_video_driver->Play(); + m_video_driver->Play(); } void MMBoardVideoFile::Pause() { - m_video_driver->Pause(); + m_video_driver->Pause(); } void MMBoardVideoFile::Resume() { - m_video_driver->Resume(); + m_video_driver->Resume(); } void MMBoardVideoFile::Stop() { - m_video_driver->Stop(); + m_video_driver->Stop(); } MMBoardTime MMBoardVideoFile::GetPosition() { - MMBoardTime btime; + MMBoardTime btime; - btime.seconds = btime.minutes = btime.hours = 0; - return btime; + btime.seconds = btime.minutes = btime.hours = 0; + return btime; } MMBoardTime MMBoardVideoFile::GetLength() { - MMBoardTime btime; + MMBoardTime btime; - btime.seconds = 1; - btime.minutes = btime.hours = 0; - return btime; + btime.seconds = 1; + btime.minutes = btime.hours = 0; + return btime; } bool MMBoardVideoFile::IsStopped() { - return m_video_driver->IsStopped(); + return m_video_driver->IsStopped(); } bool MMBoardVideoFile::IsPaused() { - return m_video_driver->IsPaused(); + return m_video_driver->IsPaused(); } wxString MMBoardVideoFile::GetStringType() { - return wxString("Video XANIM"); + return wxString(wxT("Video XANIM")); } wxString MMBoardVideoFile::GetStringInformation() { - return wxString("No info"); + return wxString(wxT("No info")); } // ---------------------------------------------------------------------------- diff --git a/utils/wxMMedia2/board/mmboard.cpp b/utils/wxMMedia2/board/mmboard.cpp index f314449534..4291ca950a 100644 --- a/utils/wxMMedia2/board/mmboard.cpp +++ b/utils/wxMMedia2/board/mmboard.cpp @@ -196,18 +196,18 @@ wxUint8 MMBoardApp::TestMultimediaCaps() caps = 0; #ifdef __UNIX__ - // We test the OSS (Open Sound System) support. + // We now test the ESD support - dev = new wxSoundStreamOSS(); + dev = new wxSoundStreamESD(); if (dev->GetError() == wxSOUND_NOERR) - caps |= MM_SOUND_OSS; + caps |= MM_SOUND_ESD; delete dev; - // We now test the ESD support + // We test the OSS (Open Sound System) support. - dev = new wxSoundStreamESD(); + dev = new wxSoundStreamOSS(); if (dev->GetError() == wxSOUND_NOERR) - caps |= MM_SOUND_ESD; + caps |= MM_SOUND_OSS; delete dev; #endif @@ -355,9 +355,9 @@ void MMBoardFrame::OpenVideoWindow() if (m_video_window) return; - m_video_window = new wxWindow(m_panel, -1, wxDefaultPosition, wxSize(400, 400)); + m_video_window = new wxWindow(m_panel, -1, wxDefaultPosition, wxSize(200, 200)); m_video_window->SetBackgroundColour(*wxBLACK); - m_sizer->Prepend(m_video_window, 0, wxGROW | wxSHRINK | wxCENTRE, 0); + m_sizer->Prepend(m_video_window, 2, wxGROW | wxSHRINK | wxCENTRE, 1); m_sizer->Fit(this); } diff --git a/utils/wxMMedia2/lib/makefile.vc b/utils/wxMMedia2/lib/makefile.vc index 28224c0016..458d3d076b 100644 --- a/utils/wxMMedia2/lib/makefile.vc +++ b/utils/wxMMedia2/lib/makefile.vc @@ -21,7 +21,7 @@ LIBTARGET=$(WXDIR)\lib\mmedia2.lib OBJECTS = cdbase.obj cdwin.obj g711.obj g721.obj g723_24.obj sndg72x.obj \ g723_40.obj g72x.obj sndbase.obj sndcodec.obj sndpcm.obj \ sndcpcm.obj sndulaw.obj sndfile.obj sndwav.obj sndaiff.obj sndwin.obj \ - vidbase.obj + vidbase.obj vidwin.obj !include $(WXDIR)\src\makelib.vc @@ -104,3 +104,9 @@ vidbase.obj: vidbase.h vidbase.$(SRCSUFF) $(cc) @<< $(CPPFLAGS) /c /Tp $*.$(SRCSUFF) << + +vidwin.obj: vidwin.h vidwin.$(SRCSUFF) + $(cc) @<< +$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) +<< + diff --git a/utils/wxMMedia2/lib/sndoss.cpp b/utils/wxMMedia2/lib/sndoss.cpp index cf276aca35..77e8ec47b9 100644 --- a/utils/wxMMedia2/lib/sndoss.cpp +++ b/utils/wxMMedia2/lib/sndoss.cpp @@ -28,7 +28,7 @@ wxSoundStreamOSS::wxSoundStreamOSS(const wxString& dev_name) { wxSoundFormatPcm pcm_default; - m_fd = open(dev_name.mb_str(), O_RDWR); + m_fd = open(dev_name.mb_str(), O_WRONLY); if (m_fd == -1) { m_snderror = wxSOUND_INVDEV; diff --git a/utils/wxMMedia2/lib/vidbase.cpp b/utils/wxMMedia2/lib/vidbase.cpp index 7af8388218..2a7ed761fb 100644 --- a/utils/wxMMedia2/lib/vidbase.cpp +++ b/utils/wxMMedia2/lib/vidbase.cpp @@ -37,6 +37,11 @@ wxVideoBaseDriver::wxVideoBaseDriver(wxInputStream& str) m_video_output = NULL; } +wxVideoBaseDriver::wxVideoBaseDriver(const wxString& filename) +{ + m_video_output = NULL; +} + wxVideoBaseDriver::~wxVideoBaseDriver() { } diff --git a/utils/wxMMedia2/lib/vidbase.h b/utils/wxMMedia2/lib/vidbase.h index 4498131a62..7dd24aa09d 100644 --- a/utils/wxMMedia2/lib/vidbase.h +++ b/utils/wxMMedia2/lib/vidbase.h @@ -13,14 +13,32 @@ #define __VID_bdrv_H__ #ifdef __GNUG__ -#pragma interface +#pragma interface "vidbase.h" #endif -#include "wx/string.h" -#include "wx/window.h" -#include "wx/frame.h" +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +// for all others, include the necessary headers (this file is usually all you +// need because it includes almost all "standard" wxWindows headers +#ifndef WX_PRECOMP + #include "wx/defs.h" + #include "wx/stream.h" + #include "wx/string.h" + #include "wx/window.h" + #include "wx/frame.h" +#endif + +// ---------------------------------------------------------------------------- +// wxMMedia2 (video) types -/// typedef enum { wxVIDEO_MSAVI, wxVIDEO_MPEG, @@ -31,58 +49,49 @@ typedef enum { wxVIDEO_IFF, wxVIDEO_SGI, wxVIDEO_MPEG2 -} /// - wxVideoType; +} wxVideoType; -/// -class wxVideoBaseDriver; +// ---------------------------------------------------------------------------- +// Classes definition -/// -class wxVideoBaseDriver : public wxObject { - /// - DECLARE_ABSTRACT_CLASS(wxVideoBaseDriver) +class WXDLLEXPORT wxVideoBaseDriver : public wxObject { + DECLARE_ABSTRACT_CLASS(wxVideoBaseDriver) protected: - wxWindow *m_video_output; + wxWindow *m_video_output; public: - // - wxVideoBaseDriver(); - // - wxVideoBaseDriver(wxInputStream& str); - // - virtual ~wxVideoBaseDriver(); - - // - virtual bool Play() = 0; - // - virtual bool Stop() = 0; - // - virtual bool Pause() = 0; - // - virtual bool Resume() = 0; - - // - virtual bool SetVolume(wxUint8 vol) = 0; - // - virtual bool Resize(wxUint16 w, wxUint16 h) = 0; - // - virtual bool GetSize(wxSize& size) const = 0; - - // - virtual bool IsCapable(wxVideoType WXUNUSED(v_type)) { return FALSE; } - - // - virtual void OnFinished() {} - - // - virtual bool AttachOutput(wxWindow& output); - // - virtual void DetachOutput(); - - virtual bool IsPaused() = 0; - virtual bool IsStopped() = 0; + // Ctors + wxVideoBaseDriver(); + wxVideoBaseDriver(wxInputStream& str); + wxVideoBaseDriver(const wxString& filename); + // Dtor + virtual ~wxVideoBaseDriver(); + + // Usual functions ... They all return FALSE in case of errors. + virtual bool Play() = 0; + virtual bool Stop() = 0; + virtual bool Pause() = 0; + virtual bool Resume() = 0; + + // Size management + virtual bool Resize(wxUint16 w, wxUint16 h) = 0; + virtual bool GetSize(wxSize& size) const = 0; + + // Test the capability of the driver to handle the specified type + virtual bool IsCapable(wxVideoType WXUNUSED(v_type)) { return FALSE; } + + // Called when the movie finished + virtual void OnFinished() {} + + // Attaches the video output to a window. The video will be shown in that window. + virtual bool AttachOutput(wxWindow& output); + virtual void DetachOutput(); + + // They return the state of the movie. + virtual bool IsPaused() = 0; + virtual bool IsStopped() = 0; }; -extern wxFrame *wxVideoCreateFrame(wxVideoBaseDriver *vid_drv); +WXDLLEXPORT wxFrame *wxVideoCreateFrame(wxVideoBaseDriver *vid_drv); #endif diff --git a/utils/wxMMedia2/lib/vidwin.cpp b/utils/wxMMedia2/lib/vidwin.cpp index 5340a0f293..e8e478039e 100644 --- a/utils/wxMMedia2/lib/vidwin.cpp +++ b/utils/wxMMedia2/lib/vidwin.cpp @@ -12,120 +12,157 @@ #pragma implementation "vidwin.h" #endif -#if 0 #include "wx/wxprec.h" -#else + +#ifndef WX_PRECOMP #include "wx/wx.h" #endif +#include "wx/stream.h" +#include "wx/wfstream.h" + #define WXMMEDIA_INTERNAL #include #include #include -#include "mmtype.h" -#include "mmfile.h" #include "vidwin.h" #ifdef __BORLANDC__ #pragma hdrstop #endif -wxVideoWindows::wxVideoWindows(void) +IMPLEMENT_DYNAMIC_CLASS(wxVideoWindows, wxVideoBaseDriver) + +wxVideoWindows::wxVideoWindows() { } -wxVideoWindows::wxVideoWindows(wxInputStream& str, bool seekable) - : wxVideoBaseDriver(str, seekable) +wxVideoWindows::wxVideoWindows(wxInputStream& str) + : wxVideoBaseDriver(str) { - OpenFile(GetCurrentFile()); + m_internal = new wxVIDWinternal; + m_remove_file = TRUE; + m_filename = wxGetTempFileName("wxvid"); + m_paused = FALSE; + m_stopped = TRUE; + + wxFileOutputStream temp_file(m_filename); + temp_file << str; + + OpenFile(); } -wxVideoWindows::wxVideoWindows(const char *fname) - : wxVideoBaseDriver(fname) +wxVideoWindows::wxVideoWindows(const wxString& filename) + : wxVideoBaseDriver(filename) { - OpenFile(fname); + m_internal = new wxVIDWinternal; + m_remove_file = FALSE; + m_filename = filename; + m_paused = FALSE; + m_stopped = TRUE; + OpenFile(); } wxVideoWindows::~wxVideoWindows(void) { - mciSendCommand(internal->dev_id, MCI_CLOSE, 0, 0); + mciSendCommand(m_internal->m_dev_id, MCI_CLOSE, 0, 0); - if (internal) - delete internal; + if (m_internal) + delete m_internal; } -void wxVideoWindows::OpenFile(const char *fname) +void wxVideoWindows::OpenFile() { - MCI_DGV_OPEN_PARMS open_struct; - DWORD ret; - - internal = new VIDW_Internal; + MCI_DGV_OPEN_PARMS open_struct; + DWORD ret; + + open_struct.lpstrDeviceType = "avivideo"; + open_struct.lpstrElementName = (LPSTR)(m_filename.mb_str()); + open_struct.hWndParent = 0; + + ret = mciSendCommand(0, MCI_OPEN, + MCI_OPEN_ELEMENT|MCI_DGV_OPEN_PARENT|MCI_OPEN_TYPE|MCI_DGV_OPEN_32BIT, + (DWORD)(LPVOID)&open_struct); + m_internal->m_dev_id = open_struct.wDeviceID; +} - open_struct.lpstrDeviceType = "avivideo"; - open_struct.lpstrElementName = (LPSTR)fname; - open_struct.hWndParent = 0; +bool wxVideoWindows::Pause() +{ + if (m_paused || m_stopped) + return TRUE; + m_paused = TRUE; + return (mciSendCommand(m_internal->m_dev_id, MCI_PAUSE, 0, 0) == 0); +} - ret = mciSendCommand(0, MCI_OPEN, - MCI_OPEN_ELEMENT|MCI_DGV_OPEN_PARENT|MCI_OPEN_TYPE|MCI_DGV_OPEN_32BIT, - (DWORD)(LPVOID)&open_struct); - internal->dev_id = open_struct.wDeviceID; +bool wxVideoWindows::Resume() +{ + if (!m_paused || m_stopped) + return TRUE; + m_paused = FALSE; + return (mciSendCommand(m_internal->m_dev_id, MCI_PAUSE, 0, 0) == 0); } -bool wxVideoWindows::Pause(void) +bool wxVideoWindows::IsPaused() { - return (mciSendCommand(internal->dev_id, MCI_PAUSE, 0, 0) == 0); + return m_paused; } -bool wxVideoWindows::Resume(void) +bool wxVideoWindows::IsStopped() { - return (mciSendCommand(internal->dev_id, MCI_PAUSE, 0, 0) == 0); + return m_stopped; } -bool wxVideoWindows::SetVolume(wxUint8 vol) +bool wxVideoWindows::GetSize(wxSize& size) const { - return TRUE; + return TRUE; } bool wxVideoWindows::Resize(wxUint16 w, wxUint16 h) { - return TRUE; + return TRUE; } bool wxVideoWindows::IsCapable(wxVideoType v_type) { - return (v_type == wxVIDEO_MSAVI); + return (v_type == wxVIDEO_MSAVI); } -bool wxVideoWindows::AttachOutput(wxVideoOutput& output) +bool wxVideoWindows::AttachOutput(wxWindow& output) { - MCI_DGV_WINDOW_PARMS win_struct; - - if (!wxVideoBaseDriver::AttachOutput(output)) - return FALSE; - - win_struct.hWnd = (HWND)output.GetHWND(); - mciSendCommand(internal->dev_id, MCI_WINDOW, - MCI_DGV_WINDOW_HWND, (DWORD)(LPVOID)&win_struct); - return TRUE; + MCI_DGV_WINDOW_PARMS win_struct; + + if (!wxVideoBaseDriver::AttachOutput(output)) + return FALSE; + + win_struct.hWnd = (HWND)output.GetHWND(); + mciSendCommand(m_internal->m_dev_id, MCI_WINDOW, + MCI_DGV_WINDOW_HWND, (DWORD)(LPVOID)&win_struct); + return TRUE; } -void wxVideoWindows::DetachOutput(void) +void wxVideoWindows::DetachOutput() { - MCI_DGV_WINDOW_PARMS win_struct; - - wxVideoBaseDriver::DetachOutput(); + MCI_DGV_WINDOW_PARMS win_struct; - win_struct.hWnd = 0; - mciSendCommand(internal->dev_id, MCI_WINDOW, - MCI_DGV_WINDOW_HWND, (DWORD)(LPVOID)&win_struct); + wxVideoBaseDriver::DetachOutput(); + + win_struct.hWnd = 0; + mciSendCommand(m_internal->m_dev_id, MCI_WINDOW, + MCI_DGV_WINDOW_HWND, (DWORD)(LPVOID)&win_struct); } -bool wxVideoWindows::StartPlay(void) +bool wxVideoWindows::Play() { - return (mciSendCommand(internal->dev_id, MCI_PLAY, 0, NULL) == 0); + if (!m_stopped) + return FALSE; + m_stopped = FALSE; + return (mciSendCommand(m_internal->m_dev_id, MCI_PLAY, 0, NULL) == 0); } -void wxVideoWindows::StopPlay(void) +bool wxVideoWindows::Stop() { - mciSendCommand(internal->dev_id, MCI_STOP, 0, NULL); + if (m_stopped) + return FALSE; + m_stopped = TRUE; + return (mciSendCommand(m_internal->m_dev_id, MCI_STOP, 0, NULL) == 0); } diff --git a/utils/wxMMedia2/lib/vidwin.h b/utils/wxMMedia2/lib/vidwin.h index 784d72a2c0..db1877591f 100644 --- a/utils/wxMMedia2/lib/vidwin.h +++ b/utils/wxMMedia2/lib/vidwin.h @@ -1,4 +1,4 @@ -// ///////////////////////////////////////////////////////////////////////////// +// ---------------------------------------------------------------------------- // Name: vidwin.h // Purpose: wxMMedia // Author: Guilhem Lavaux @@ -6,57 +6,82 @@ // Updated: // Copyright: (C) 1998, Guilhem Lavaux // License: wxWindows license -// ///////////////////////////////////////////////////////////////////////////// -/* Real -*- C++ -*- */ +// ---------------------------------------------------------------------------- + #ifndef __VID_windows_H__ #define __VID_windows_H__ #ifdef __GNUG__ -#pragma interface + #pragma interface "vidwin.h" #endif -#include "mmtype.h" -#include "mmfile.h" -#ifdef WX_PRECOMP +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- +// For compilers that support precompilation, includes "wx/wx.h". #include "wx/wxprec.h" -#else -#include "wx/wx.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +// for all others, include the necessary headers (this file is usually all you +// need because it includes almost all "standard" wxWindows headers +#ifndef WX_PRECOMP + #include "wx/string.h" + #include "wx/stream.h" + #include "wx/window.h" #endif + +// ---------------------------------------------------------------------------- +// wxMMedia2 headers + #include "vidbase.h" +// ---------------------------------------------------------------------------- +// System headers and private types + #ifdef WXMMEDIA_INTERNAL #include #include typedef struct VIDW_Internal { - MCIDEVICEID dev_id; -} VIDW_Internal; + MCIDEVICEID m_dev_id; +} wxVIDWinternal; #endif -class wxVideoWindows : public wxVideoBaseDriver { - DECLARE_DYNAMIC_CLASS(wxVideoWindows) +// ---------------------------------------------------------------------------- +// Class definition + +class WXDLLEXPORT wxVideoWindows : public wxVideoBaseDriver { + DECLARE_DYNAMIC_CLASS(wxVideoWindows) protected: - struct VIDW_Internal *internal; + struct VIDW_Internal *m_internal; + bool m_paused, m_stopped, m_remove_file; + wxString m_filename; - void OpenFile(const char *fname); + void OpenFile(); public: - wxVideoWindows(void); - wxVideoWindows(wxInputStream& str, bool seekable = FALSE); - wxVideoWindows(const char *fname); - virtual ~wxVideoWindows(void); - - virtual bool StartPlay(void); - virtual void StopPlay(void); - virtual bool Pause(void); - virtual bool Resume(void); - - virtual bool SetVolume(wxUint8 vol); - virtual bool Resize(wxUint16 w, wxUint16 h); - - virtual bool IsCapable(wxVideoType v_type); + wxVideoWindows(void); + wxVideoWindows(wxInputStream& str); + wxVideoWindows(const wxString& fname); + ~wxVideoWindows(void); - virtual bool AttachOutput(wxVideoOutput& output); - virtual void DetachOutput(void); + bool Play(); + bool Stop(); + bool Pause(); + bool Resume(); + + bool Resize(wxUint16 w, wxUint16 h); + bool GetSize(wxSize& size) const; + + bool IsCapable(wxVideoType v_type); + + bool AttachOutput(wxWindow& output); + void DetachOutput(void); + + bool IsPaused(); + bool IsStopped(); }; #endif diff --git a/utils/wxMMedia2/lib/vidxanm.cpp b/utils/wxMMedia2/lib/vidxanm.cpp index 4ff0454b90..a4ca4ef074 100644 --- a/utils/wxMMedia2/lib/vidxanm.cpp +++ b/utils/wxMMedia2/lib/vidxanm.cpp @@ -1,4 +1,4 @@ -//////////////////////////////////////////////////////////////////////////////// +// ------------------------------------------------------------------------- // Name: vidxanm.cpp // Purpose: wxMMedia // Author: Guilhem Lavaux @@ -6,13 +6,15 @@ // Updated: 1998 // Copyright: (C) 1997, 1998, 1999 Guilhem Lavaux // License: wxWindows license -//////////////////////////////////////////////////////////////////////////////// +// ------------------------------------------------------------------------- + #ifdef __GNUG__ #pragma implementation "vidxanm.h" #endif -#ifdef WX_PRECOMP -#include -#else + +#include + +#ifndef WX_PRECOMP #include #endif @@ -37,247 +39,265 @@ IMPLEMENT_DYNAMIC_CLASS(wxVideoXANIM, wxVideoBaseDriver) +// ------------------------------------------------------------------------- +// End process detector + class wxVideoXANIMProcess: public wxProcess { - public: - wxVideoXANIMProcess(wxVideoXANIM *xanim); +public: + wxVideoXANIMProcess(wxVideoXANIM *xanim); - void OnTerminate(int pid, int status); + void OnTerminate(int pid, int status); - protected: - wxVideoXANIM *m_vid_xanim; +protected: + wxVideoXANIM *m_vid_xanim; }; +// ------------------------------------------------------------------------- +// XAnim video driver (implementation) wxVideoXANIMProcess::wxVideoXANIMProcess(wxVideoXANIM *xanim) { - m_vid_xanim = xanim; + m_vid_xanim = xanim; } void wxVideoXANIMProcess::OnTerminate(int WXUNUSED(pid), int WXUNUSED(status)) { - m_vid_xanim->m_xanim_started = FALSE; + m_vid_xanim->m_xanim_started = FALSE; + m_vid_xanim->OnFinished(); } wxVideoXANIM::wxVideoXANIM() : wxVideoBaseDriver() { - m_internal = new wxXANIMinternal; - m_xanim_detector = new wxVideoXANIMProcess(this); - m_xanim_started = FALSE; - m_paused = FALSE; - m_filename = ""; + m_internal = new wxXANIMinternal; + m_xanim_detector = new wxVideoXANIMProcess(this); + m_xanim_started = FALSE; + m_paused = FALSE; + m_filename = ""; + m_remove_file = FALSE; } wxVideoXANIM::wxVideoXANIM(wxInputStream& str) : wxVideoBaseDriver(str) { - m_internal = new wxXANIMinternal; - m_xanim_detector = new wxVideoXANIMProcess(this); - m_xanim_started = FALSE; - m_paused = FALSE; + m_internal = new wxXANIMinternal; + m_xanim_detector = new wxVideoXANIMProcess(this); + m_xanim_started = FALSE; + m_paused = FALSE; + + m_filename = wxGetTempFileName("vidxa"); + m_remove_file = TRUE; + wxFileOutputStream fout(m_filename); + + fout << str; +} - m_filename = wxGetTempFileName("vidxa"); - wxFileOutputStream fout(m_filename); +wxVideoXANIM::wxVideoXANIM(const wxString& filename) +{ + m_internal = new wxXANIMinternal; + m_xanim_detector = new wxVideoXANIMProcess(this); + m_xanim_started = FALSE; + m_paused = FALSE; - fout << str; + m_filename = filename; + m_remove_file = FALSE; } wxVideoXANIM::~wxVideoXANIM() { - if (m_xanim_started) - Stop(); - delete m_internal; - delete m_xanim_detector; - - wxRemoveFile(m_filename); + if (m_xanim_started) + Stop(); + delete m_internal; + delete m_xanim_detector; + + if (m_remove_file) + wxRemoveFile(m_filename); } bool wxVideoXANIM::Play() { - if (!m_paused && m_xanim_started) - return TRUE; - if (!m_video_output) { - wxVideoCreateFrame(this); - return TRUE; - } - - // The movie starts with xanim - if (RestartXANIM()) { - m_paused = FALSE; - return TRUE; - } - return FALSE; + if (!m_paused && m_xanim_started) + return TRUE; + if (!m_video_output) { + wxVideoCreateFrame(this); + return TRUE; + } + + // The movie starts with xanim + if (RestartXANIM()) { + m_paused = FALSE; + return TRUE; + } + return FALSE; } bool wxVideoXANIM::Pause() { - if (!m_paused && SendCommand(" ")) { - m_paused = TRUE; - return TRUE; - } - return FALSE; + if (!m_paused && SendCommand(" ")) { + m_paused = TRUE; + return TRUE; + } + return FALSE; } bool wxVideoXANIM::Resume() { - if (m_paused && SendCommand(" ")) { - m_paused = FALSE; - return TRUE; - } - return FALSE; + if (m_paused && SendCommand(" ")) { + m_paused = FALSE; + return TRUE; + } + return FALSE; } bool wxVideoXANIM::Stop() { - if (!m_xanim_started) - return FALSE; + if (!m_xanim_started) + return FALSE; - SendCommand("q"); + SendCommand("q"); - m_xanim_started = FALSE; - m_paused = FALSE; + // We are waiting for the termination of the subprocess. + while (m_xanim_started) { + wxYield(); + } - return TRUE; + m_paused = FALSE; + + return TRUE; } -bool wxVideoXANIM::SetVolume(wxUint8 vol) +bool wxVideoXANIM::Resize(wxUint16 w, wxUint16 h) { - if (vol > 100) - vol = 100; - - wxString str_vol("v%d", vol); - return SendCommand(str_vol.GetData()); -} + if (!m_video_output) + return FALSE; -bool wxVideoXANIM::Resize(wxUint16 WXUNUSED(w), wxUint16 WXUNUSED(h)) -{ - // Not implemented - // Actually, I think that we just need to resize the output window ... - return FALSE; + m_video_output->SetSize(w, h); + return FALSE; } bool wxVideoXANIM::GetSize(wxSize& size) const { - // Not implemented - return FALSE; + return FALSE; } bool wxVideoXANIM::IsCapable(wxVideoType v_type) { - if (v_type == wxVIDEO_MSAVI || v_type == wxVIDEO_MPEG || - v_type == wxVIDEO_QT || v_type == wxVIDEO_GIF || v_type == wxVIDEO_JMOV || - v_type == wxVIDEO_FLI || v_type == wxVIDEO_IFF || v_type == wxVIDEO_SGI) - return TRUE; - else - return FALSE; + if (v_type == wxVIDEO_MSAVI || v_type == wxVIDEO_MPEG || + v_type == wxVIDEO_QT || v_type == wxVIDEO_GIF || v_type == wxVIDEO_JMOV || + v_type == wxVIDEO_FLI || v_type == wxVIDEO_IFF || v_type == wxVIDEO_SGI) + return TRUE; + else + return FALSE; } bool wxVideoXANIM::IsPaused() { - return m_paused; + return m_paused; } bool wxVideoXANIM::IsStopped() { - return !m_xanim_started; + return !m_xanim_started; } bool wxVideoXANIM::AttachOutput(wxWindow& out) { - if (!wxVideoBaseDriver::AttachOutput(out)) - return FALSE; + if (!wxVideoBaseDriver::AttachOutput(out)) + return FALSE; - return TRUE; + return TRUE; } void wxVideoXANIM::DetachOutput() { - SendCommand("q"); - m_xanim_started = FALSE; - m_paused = FALSE; + SendCommand("q"); + m_xanim_started = FALSE; + m_paused = FALSE; - wxVideoBaseDriver::DetachOutput(); + wxVideoBaseDriver::DetachOutput(); } bool wxVideoXANIM::SendCommand(const char *command, char **ret, - wxUint32 *size) + wxUint32 *size) { - if (!m_xanim_started) - if (!RestartXANIM()) - return FALSE; - - // Send a command to XAnim through X11 Property - XChangeProperty(m_internal->xanim_dpy, m_internal->xanim_window, - m_internal->xanim_atom, - XA_STRING, 8, PropModeReplace, (unsigned char *)command, - strlen(command)); - XFlush(m_internal->xanim_dpy); - if (ret) { - int prop_format; - Atom prop_type; - unsigned long extra; - - XGetWindowProperty(m_internal->xanim_dpy, m_internal->xanim_window, - m_internal->xanim_ret, 0, 16, True, AnyPropertyType, - &prop_type, &prop_format, (unsigned long *)size, - &extra, (unsigned char **)ret); - } - return TRUE; + if (!m_xanim_started) + if (!RestartXANIM()) + return FALSE; + + // Send a command to XAnim through X11 Property + XChangeProperty(m_internal->xanim_dpy, m_internal->xanim_window, + m_internal->xanim_atom, + XA_STRING, 8, PropModeReplace, (unsigned char *)command, + strlen(command)); + XFlush(m_internal->xanim_dpy); + if (ret) { + int prop_format; + Atom prop_type; + unsigned long extra; + + XGetWindowProperty(m_internal->xanim_dpy, m_internal->xanim_window, + m_internal->xanim_ret, 0, 16, True, AnyPropertyType, + &prop_type, &prop_format, (unsigned long *)size, + &extra, (unsigned char **)ret); + } + return TRUE; } bool wxVideoXANIM::RestartXANIM() { - wxString xanim_command; - int ret; - Atom prop_type; - int prop_format; - unsigned long nitems; - unsigned long extra; - char prop[4]; - bool xanim_chg_size; - - if (!m_video_output || m_xanim_started) - return FALSE; - - // Check if we can change the size of the window dynamicly - xanim_chg_size = TRUE; - // Get current display + wxString xanim_command; + int ret; + Atom prop_type; + int prop_format; + unsigned long nitems; + unsigned long extra; + char prop[4]; + bool xanim_chg_size; + + if (!m_video_output || m_xanim_started) + return FALSE; + + // Check if we can change the size of the window dynamicly + xanim_chg_size = TRUE; + // Get current display #ifdef __WXGTK__ - m_internal->xanim_dpy = gdk_display; - // We absolutely need the window to be realized. - GtkPizza *pizza = GTK_PIZZA( m_video_output->m_wxwindow ); - GdkWindow *window = pizza->bin_window; - - m_internal->xanim_window = - ((GdkWindowPrivate *)window)->xwindow; + m_internal->xanim_dpy = gdk_display; + GtkPizza *pizza = GTK_PIZZA( m_video_output->m_wxwindow ); + GdkWindow *window = pizza->bin_window; + + m_internal->xanim_window = + ((GdkWindowPrivate *)window)->xwindow; #endif - // Get the XANIM atom - m_internal->xanim_atom = XInternAtom(m_internal->xanim_dpy, - "XANIM_PROPERTY", False); - - // Build the command - xanim_command.Printf(_T("xanim -Zr +Ze +Sr +f +W%d +f +q " - "+Av70 %s %s"), m_internal->xanim_window, - (xanim_chg_size) ? _T("") : _T(""), - WXSTRINGCAST m_filename); - - // Execute it - if (!wxExecute(xanim_command, FALSE, m_xanim_detector)) - return FALSE; - - // Wait for XAnim to be ready - nitems = 0; - m_xanim_started = TRUE; - while (nitems == 0 && m_xanim_started) { - ret = XGetWindowProperty(m_internal->xanim_dpy, m_internal->xanim_window, - m_internal->xanim_atom, - 0, 4, False, AnyPropertyType, &prop_type, - &prop_format, &nitems, &extra, - (unsigned char **)&prop); - wxYield(); - } - - m_paused = FALSE; - - return TRUE; + // Get the XANIM atom + m_internal->xanim_atom = XInternAtom(m_internal->xanim_dpy, + "XANIM_PROPERTY", False); + + // Build the command + xanim_command.Printf(wxT("xanim -Zr +Ze +Sr +f +W%d +f +q " + "+Av70 %s %s"), m_internal->xanim_window, + (xanim_chg_size) ? _T("") : _T(""), + WXSTRINGCAST m_filename); + + // Execute it + if (!wxExecute(xanim_command, FALSE, m_xanim_detector)) + return FALSE; + + // Wait for XAnim to be ready + nitems = 0; + m_xanim_started = TRUE; + while (nitems == 0 && m_xanim_started) { + ret = XGetWindowProperty(m_internal->xanim_dpy, m_internal->xanim_window, + m_internal->xanim_atom, + 0, 4, False, AnyPropertyType, &prop_type, + &prop_format, &nitems, &extra, + (unsigned char **)&prop); + wxYield(); + } + + m_video_output->SetSize(m_video_output->GetSize()); + // Very useful ! Actually it sends a SETSIZE event to XAnim + + m_paused = FALSE; + + return TRUE; } diff --git a/utils/wxMMedia2/lib/vidxanm.h b/utils/wxMMedia2/lib/vidxanm.h index 2400be1510..648e8816db 100644 --- a/utils/wxMMedia2/lib/vidxanm.h +++ b/utils/wxMMedia2/lib/vidxanm.h @@ -15,65 +15,97 @@ #pragma interface "vidxanm.h" #endif -#include "wx/defs.h" -#include "wx/string.h" -#include "wx/process.h" +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +// for all others, include the necessary headers (this file is usually all you +// need because it includes almost all "standard" wxWindows headers +#ifndef WX_PRECOMP + #include "wx/defs.h" + #include "wx/string.h" + #include "wx/process.h" +#endif + +// ---------------------------------------------------------------------------- +// System dependent headers #if defined(WXMMEDIA_INTERNAL) && (defined(__X__) || defined(__WXGTK__)) #include #include #endif +// ---------------------------------------------------------------------------- +// wxMMedia2 headers + #include "vidbase.h" +// ---------------------------------------------------------------------------- +// Internal types + #ifdef WXMMEDIA_INTERNAL typedef struct wxXANIMinternal { - Display *xanim_dpy; - Window xanim_window; - Atom xanim_atom, xanim_ret; + Display *xanim_dpy; + Window xanim_window; + Atom xanim_atom, xanim_ret; } wxXANIMinternal; #ifndef __XANIM_COMMAND__ -#define __XANIM_COMMAND__ "/usr/X11R6/bin/xanim" + #define __XANIM_COMMAND__ "/usr/X11R6/bin/xanim" #endif + #endif -class wxVideoXANIM : public wxVideoBaseDriver { - DECLARE_DYNAMIC_CLASS(wxVideoXANIM) +// ---------------------------------------------------------------------------- +// Class definition + +class WXDLLEXPORT wxVideoXANIM : public wxVideoBaseDriver { + DECLARE_DYNAMIC_CLASS(wxVideoXANIM) protected: - bool m_xanim_started, m_paused; - struct wxXANIMinternal *m_internal; - wxString m_filename; - wxProcess *m_xanim_detector; + // Remember the state of the subprocess + bool m_xanim_started, m_paused; + // Pure X11 variables + struct wxXANIMinternal *m_internal; + wxString m_filename; + wxProcess *m_xanim_detector; + // Remember to delete the temporary file when necessary + bool m_remove_file; public: - wxVideoXANIM(); - wxVideoXANIM(wxInputStream& str); - ~wxVideoXANIM(); - - bool Play(); - bool Pause(); - bool Resume(); - bool Stop(); - - bool SetVolume(wxUint8 vol); - bool Resize(wxUint16 w, wxUint16 h); - bool GetSize(wxSize& size) const; - - bool IsCapable(wxVideoType v_type); - - bool AttachOutput(wxWindow& output); - void DetachOutput(); - - bool IsPaused(); - bool IsStopped(); - - friend class wxVideoXANIMProcess; + wxVideoXANIM(); + wxVideoXANIM(wxInputStream& str); + wxVideoXANIM(const wxString& filename); + ~wxVideoXANIM(); + + bool Play(); + bool Pause(); + bool Resume(); + bool Stop(); + + bool SetVolume(wxUint8 vol); + bool Resize(wxUint16 w, wxUint16 h); + bool GetSize(wxSize& size) const; + bool IsCapable(wxVideoType v_type); + + bool AttachOutput(wxWindow& output); + void DetachOutput(); + + bool IsPaused(); + bool IsStopped(); + + friend class wxVideoXANIMProcess; + protected: - /// - bool RestartXANIM(); - /// - bool SendCommand(const char *command, char **ret = NULL, + // Start the subprocess with the right parameters + bool RestartXANIM(); + // Send a command to the subprocess + bool SendCommand(const char *command,char **ret = NULL, wxUint32 *size = NULL); };