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