1 // -----------------------------------------------------------------------------
4 // Author: Guilhem Lavaux
5 // Created: February 1998
7 // Copyright: (C) 1998, 1999, 2000 Guilhem Lavaux
8 // License: wxWindows license
9 // -----------------------------------------------------------------------------
12 #pragma implementation "vidwin.h"
15 #include "wx/wxprec.h"
21 #include "wx/stream.h"
22 #include "wx/wfstream.h"
24 #define WXMMEDIA_INTERNAL
34 IMPLEMENT_DYNAMIC_CLASS(wxVideoWindows
, wxVideoBaseDriver
)
36 wxVideoWindows::wxVideoWindows()
40 wxVideoWindows::wxVideoWindows(wxInputStream
& str
)
41 : wxVideoBaseDriver(str
)
43 m_internal
= new wxVIDWinternal
;
45 m_filename
= wxGetTempFileName("wxvid");
50 wxFileOutputStream
temp_file(m_filename
);
56 wxVideoWindows::wxVideoWindows(const wxString
& filename
)
57 : wxVideoBaseDriver(filename
)
59 m_internal
= new wxVIDWinternal
;
60 m_remove_file
= FALSE
;
61 m_filename
= filename
;
68 wxVideoWindows::~wxVideoWindows(void)
70 mciSendCommand(m_internal
->m_dev_id
, MCI_CLOSE
, 0, 0);
76 void wxVideoWindows::OpenFile()
78 MCI_DGV_OPEN_PARMS openStruct
;
79 MCI_DGV_SET_PARMS setStruct
;
80 MCI_STATUS_PARMS statusStruct
;
83 openStruct
.lpstrDeviceType
= "avivideo";
84 openStruct
.lpstrElementName
= (LPSTR
)(m_filename
.mb_str());
85 openStruct
.hWndParent
= 0;
87 ret
= mciSendCommand(0, MCI_OPEN
,
88 MCI_OPEN_ELEMENT
|MCI_DGV_OPEN_PARENT
|MCI_OPEN_TYPE
|MCI_DGV_OPEN_32BIT
,
89 (DWORD
)(LPVOID
)&openStruct
);
90 m_internal
->m_dev_id
= openStruct
.wDeviceID
;
93 setStruct
.dwCallback
= 0;
94 setStruct
.dwTimeFormat
= MCI_FORMAT_FRAMES
;
96 ret
= mciSendCommand(m_internal
->m_dev_id
, MCI_SET
, MCI_SET_TIME_FORMAT
,
97 (DWORD
)(LPVOID
)&setStruct
);
100 statusStruct
.dwCallback
= 0;
101 statusStruct
.dwItem
= MCI_DGV_STATUS_FRAME_RATE
;
102 ret
= mciSendCommand(m_internal
->m_dev_id
, MCI_STATUS
,
104 (DWORD
)(LPVOID
)&statusStruct
);
106 m_frameRate
= ((double)statusStruct
.dwReturn
) / 1000;
108 statusStruct
.dwItem
= MCI_DGV_STATUS_BITSPERSAMPLE
;
109 ret
= mciSendCommand(m_internal
->m_dev_id
, MCI_STATUS
, MCI_STATUS_ITEM
,
110 (DWORD
)(LPVOID
)&statusStruct
);
111 m_bps
= statusStruct
.dwReturn
;
115 bool wxVideoWindows::Pause()
117 if (m_paused
|| m_stopped
)
120 return (mciSendCommand(m_internal
->m_dev_id
, MCI_PAUSE
, MCI_WAIT
, 0) == 0);
123 bool wxVideoWindows::Resume()
125 if (!m_paused
|| m_stopped
)
128 return (mciSendCommand(m_internal
->m_dev_id
, MCI_RESUME
, 0, 0) == 0);
131 bool wxVideoWindows::IsPaused() const
136 bool wxVideoWindows::IsStopped() const
141 bool wxVideoWindows::GetSize(wxSize
& size
) const
148 bool wxVideoWindows::SetSize(wxSize size
)
153 bool wxVideoWindows::IsCapable(wxVideoType v_type
)
155 return (v_type
== wxVIDEO_MSAVI
);
158 bool wxVideoWindows::AttachOutput(wxWindow
& output
)
160 MCI_DGV_WINDOW_PARMS win_struct
;
162 if (!wxVideoBaseDriver::AttachOutput(output
))
165 win_struct
.hWnd
= (HWND
)output
.GetHWND();
166 mciSendCommand(m_internal
->m_dev_id
, MCI_WINDOW
,
167 MCI_DGV_WINDOW_HWND
, (DWORD
)(LPVOID
)&win_struct
);
171 void wxVideoWindows::DetachOutput()
173 MCI_DGV_WINDOW_PARMS win_struct
;
175 wxVideoBaseDriver::DetachOutput();
178 mciSendCommand(m_internal
->m_dev_id
, MCI_WINDOW
,
179 MCI_DGV_WINDOW_HWND
, (DWORD
)(LPVOID
)&win_struct
);
182 bool wxVideoWindows::Play()
187 return (mciSendCommand(m_internal
->m_dev_id
, MCI_PLAY
, 0, NULL
) == 0);
190 bool wxVideoWindows::Stop()
192 MCI_SEEK_PARMS seekStruct
;
197 if (::mciSendCommand(m_internal
->m_dev_id
, MCI_STOP
, MCI_WAIT
, NULL
) != 0)
200 seekStruct
.dwCallback
= 0;
202 return (::mciSendCommand(m_internal
->m_dev_id
, MCI_SEEK
, MCI_SEEK_TO_START
|MCI_WAIT
, (DWORD
)(LPVOID
)&seekStruct
) == 0);
206 // I hate windows :-(. The doc says MCI_STATUS should return all info I want but when I call it
207 // it returns to me with an UNSUPPORTED_FUNCTION error. I will have to do all by myself. Grrrr !
209 wxString
wxVideoWindows::GetMovieCodec() const
211 return wxT("No info");
214 wxString
wxVideoWindows::GetAudioCodec() const
216 return wxT("No info");
219 wxUint32
wxVideoWindows::GetSampleRate() const
224 wxUint8
wxVideoWindows::GetChannels() const
229 wxUint8
wxVideoWindows::GetBPS() const
234 double wxVideoWindows::GetFrameRate() const
239 wxUint32
wxVideoWindows::GetNbFrames() const