]>
Commit | Line | Data |
---|---|---|
e8482f24 GL |
1 | // ----------------------------------------------------------------------------- |
2 | // Name: vidwin.h | |
3 | // Purpose: wxMMedia | |
4 | // Author: Guilhem Lavaux | |
5 | // Created: February 1998 | |
6 | // Updated: | |
7 | // Copyright: (C) 1998, 1999, 2000 Guilhem Lavaux | |
8 | // License: wxWindows license | |
9 | // ----------------------------------------------------------------------------- | |
10 | ||
e8482f24 GL |
11 | #include "wx/wxprec.h" |
12 | ||
13 | #ifndef WX_PRECOMP | |
14 | #include "wx/wx.h" | |
15 | #endif | |
16 | ||
72d29cf0 | 17 | #if defined(__WINDOWS__) && !defined(__MINGW32__) && !defined(__WATCOMC__) && !defined(__CYGWIN__) |
2b3644c7 JS |
18 | // versions of Open Watcom and MinGW tested against this source does not |
19 | // deliver "digitalv.h" required in this feature | |
e8482f24 GL |
20 | |
21 | #ifdef __BORLANDC__ | |
22 | #pragma hdrstop | |
23 | #endif | |
24 | ||
25 | #include "wx/stream.h" | |
26 | #include "wx/wfstream.h" | |
27 | ||
28 | #define WXMMEDIA_INTERNAL | |
29 | #include <windows.h> | |
30 | #include <mmsystem.h> | |
31 | #include <digitalv.h> | |
32 | #include "wx/mmedia/vidwin.h" | |
33 | ||
34 | #ifdef __BORLANDC__ | |
35 | #pragma hdrstop | |
36 | #endif | |
37 | ||
38 | IMPLEMENT_DYNAMIC_CLASS(wxVideoWindows, wxVideoBaseDriver) | |
39 | ||
40 | wxVideoWindows::wxVideoWindows() | |
41 | { | |
42 | } | |
43 | ||
44 | wxVideoWindows::wxVideoWindows(wxInputStream& str) | |
45 | : wxVideoBaseDriver(str) | |
46 | { | |
47 | m_internal = new wxVIDWinternal; | |
dea7e44a | 48 | m_remove_file = true; |
42c37dec | 49 | m_filename = wxGetTempFileName(_T("wxvid")); |
dea7e44a WS |
50 | m_paused = false; |
51 | m_stopped = true; | |
e8482f24 GL |
52 | m_frameRate = 1.0; |
53 | ||
54 | wxFileOutputStream temp_file(m_filename); | |
55 | temp_file << str; | |
56 | ||
57 | OpenFile(); | |
58 | } | |
59 | ||
60 | wxVideoWindows::wxVideoWindows(const wxString& filename) | |
61 | : wxVideoBaseDriver(filename) | |
62 | { | |
63 | m_internal = new wxVIDWinternal; | |
dea7e44a | 64 | m_remove_file = false; |
e8482f24 | 65 | m_filename = filename; |
dea7e44a WS |
66 | m_paused = false; |
67 | m_stopped = true; | |
e8482f24 GL |
68 | m_frameRate = 1.0; |
69 | OpenFile(); | |
70 | } | |
71 | ||
72 | wxVideoWindows::~wxVideoWindows(void) | |
73 | { | |
74 | mciSendCommand(m_internal->m_dev_id, MCI_CLOSE, 0, 0); | |
75 | ||
76 | if (m_internal) | |
77 | delete m_internal; | |
78 | } | |
79 | ||
80 | void wxVideoWindows::OpenFile() | |
81 | { | |
82 | MCI_DGV_OPEN_PARMS openStruct; | |
83 | MCI_DGV_SET_PARMS setStruct; | |
84 | MCI_STATUS_PARMS statusStruct; | |
e8482f24 | 85 | |
42c37dec | 86 | openStruct.lpstrDeviceType = _T("avivideo"); |
2b3644c7 | 87 | openStruct.lpstrElementName = (wxChar *)m_filename.c_str(); |
e8482f24 GL |
88 | openStruct.hWndParent = 0; |
89 | ||
42c37dec | 90 | mciSendCommand(0, MCI_OPEN, |
dea7e44a | 91 | MCI_OPEN_ELEMENT|MCI_DGV_OPEN_PARENT|MCI_OPEN_TYPE|MCI_DGV_OPEN_32BIT, |
e8482f24 GL |
92 | (DWORD)(LPVOID)&openStruct); |
93 | m_internal->m_dev_id = openStruct.wDeviceID; | |
94 | ||
95 | ||
96 | setStruct.dwCallback = 0; | |
97 | setStruct.dwTimeFormat = MCI_FORMAT_FRAMES; | |
98 | ||
42c37dec | 99 | mciSendCommand(m_internal->m_dev_id, MCI_SET, MCI_SET_TIME_FORMAT, |
e8482f24 GL |
100 | (DWORD)(LPVOID)&setStruct); |
101 | ||
102 | ||
103 | statusStruct.dwCallback = 0; | |
104 | statusStruct.dwItem = MCI_DGV_STATUS_FRAME_RATE; | |
42c37dec | 105 | mciSendCommand(m_internal->m_dev_id, MCI_STATUS, |
e8482f24 GL |
106 | MCI_STATUS_ITEM, |
107 | (DWORD)(LPVOID)&statusStruct); | |
108 | ||
109 | m_frameRate = ((double)statusStruct.dwReturn) / 1000; | |
110 | ||
111 | statusStruct.dwItem = MCI_DGV_STATUS_BITSPERSAMPLE; | |
42c37dec | 112 | mciSendCommand(m_internal->m_dev_id, MCI_STATUS, MCI_STATUS_ITEM, |
e8482f24 GL |
113 | (DWORD)(LPVOID)&statusStruct); |
114 | m_bps = statusStruct.dwReturn; | |
115 | ||
116 | } | |
117 | ||
118 | bool wxVideoWindows::Pause() | |
119 | { | |
120 | if (m_paused || m_stopped) | |
dea7e44a WS |
121 | return true; |
122 | m_paused = true; | |
e8482f24 GL |
123 | return (mciSendCommand(m_internal->m_dev_id, MCI_PAUSE, MCI_WAIT, 0) == 0); |
124 | } | |
125 | ||
126 | bool wxVideoWindows::Resume() | |
127 | { | |
128 | if (!m_paused || m_stopped) | |
dea7e44a WS |
129 | return true; |
130 | m_paused = false; | |
e8482f24 GL |
131 | return (mciSendCommand(m_internal->m_dev_id, MCI_RESUME, 0, 0) == 0); |
132 | } | |
133 | ||
134 | bool wxVideoWindows::IsPaused() const | |
135 | { | |
136 | return m_paused; | |
137 | } | |
138 | ||
139 | bool wxVideoWindows::IsStopped() const | |
140 | { | |
141 | return m_stopped; | |
142 | } | |
143 | ||
144 | bool wxVideoWindows::GetSize(wxSize& size) const | |
145 | { | |
146 | size.SetWidth(200); | |
147 | size.SetHeight(200); | |
dea7e44a | 148 | return true; |
e8482f24 GL |
149 | } |
150 | ||
42c37dec | 151 | bool wxVideoWindows::SetSize(wxSize WXUNUSED(size)) |
e8482f24 | 152 | { |
dea7e44a | 153 | return true; |
e8482f24 GL |
154 | } |
155 | ||
2bbf230a | 156 | bool wxVideoWindows::IsCapable(wxVideoType v_type) const |
e8482f24 GL |
157 | { |
158 | return (v_type == wxVIDEO_MSAVI); | |
159 | } | |
160 | ||
161 | bool wxVideoWindows::AttachOutput(wxWindow& output) | |
162 | { | |
163 | MCI_DGV_WINDOW_PARMS win_struct; | |
164 | ||
165 | if (!wxVideoBaseDriver::AttachOutput(output)) | |
dea7e44a | 166 | return false; |
e8482f24 GL |
167 | |
168 | win_struct.hWnd = (HWND)output.GetHWND(); | |
169 | mciSendCommand(m_internal->m_dev_id, MCI_WINDOW, | |
dea7e44a WS |
170 | MCI_DGV_WINDOW_HWND, (DWORD)(LPVOID)&win_struct); |
171 | return true; | |
e8482f24 GL |
172 | } |
173 | ||
174 | void wxVideoWindows::DetachOutput() | |
175 | { | |
176 | MCI_DGV_WINDOW_PARMS win_struct; | |
177 | ||
178 | wxVideoBaseDriver::DetachOutput(); | |
179 | ||
180 | win_struct.hWnd = 0; | |
181 | mciSendCommand(m_internal->m_dev_id, MCI_WINDOW, | |
dea7e44a | 182 | MCI_DGV_WINDOW_HWND, (DWORD)(LPVOID)&win_struct); |
e8482f24 GL |
183 | } |
184 | ||
185 | bool wxVideoWindows::Play() | |
186 | { | |
187 | if (!m_stopped) | |
dea7e44a WS |
188 | return false; |
189 | m_stopped = false; | |
e8482f24 GL |
190 | return (mciSendCommand(m_internal->m_dev_id, MCI_PLAY, 0, NULL) == 0); |
191 | } | |
192 | ||
193 | bool wxVideoWindows::Stop() | |
194 | { | |
195 | MCI_SEEK_PARMS seekStruct; | |
196 | ||
197 | if (m_stopped) | |
dea7e44a WS |
198 | return false; |
199 | m_stopped = true; | |
e8482f24 | 200 | if (::mciSendCommand(m_internal->m_dev_id, MCI_STOP, MCI_WAIT, NULL) != 0) |
dea7e44a | 201 | return false; |
e8482f24 GL |
202 | |
203 | seekStruct.dwCallback = 0; | |
204 | seekStruct.dwTo = 0; | |
205 | return (::mciSendCommand(m_internal->m_dev_id, MCI_SEEK, MCI_SEEK_TO_START|MCI_WAIT, (DWORD)(LPVOID)&seekStruct) == 0); | |
206 | } | |
207 | ||
208 | // TODO TODO | |
209 | // I hate windows :-(. The doc says MCI_STATUS should return all info I want but when I call it | |
210 | // it returns to me with an UNSUPPORTED_FUNCTION error. I will have to do all by myself. Grrrr ! | |
211 | ||
212 | wxString wxVideoWindows::GetMovieCodec() const | |
213 | { | |
214 | return wxT("No info"); | |
215 | } | |
216 | ||
217 | wxString wxVideoWindows::GetAudioCodec() const | |
218 | { | |
219 | return wxT("No info"); | |
220 | } | |
221 | ||
222 | wxUint32 wxVideoWindows::GetSampleRate() const | |
223 | { | |
224 | return 22500; | |
225 | } | |
226 | ||
227 | wxUint8 wxVideoWindows::GetChannels() const | |
228 | { | |
229 | return 1; | |
230 | } | |
231 | ||
232 | wxUint8 wxVideoWindows::GetBPS() const | |
233 | { | |
234 | return m_bps; | |
235 | } | |
236 | ||
237 | double wxVideoWindows::GetFrameRate() const | |
238 | { | |
239 | return m_frameRate; | |
240 | } | |
241 | ||
242 | wxUint32 wxVideoWindows::GetNbFrames() const | |
243 | { | |
244 | return 0; | |
245 | } | |
246 | ||
247 | #endif | |
248 | // __WINDOWS__ |