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