]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/mmedia/vidwin.cpp
wxVariant support for icon and bitmap should work regardless wxBitmapBase.
[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 #include "wx/wxprec.h"
12
13 #ifndef WX_PRECOMP
14 #include "wx/wx.h"
15 #endif
16
17 #if defined(__WINDOWS__) && !defined(__MINGW32__) && !defined(__WATCOMC__) && !defined(__CYGWIN__)
18 // versions of Open Watcom and MinGW tested against this source does not
19 // deliver "digitalv.h" required in this feature
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;
48 m_remove_file = true;
49 m_filename = wxGetTempFileName(_T("wxvid"));
50 m_paused = false;
51 m_stopped = true;
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;
64 m_remove_file = false;
65 m_filename = filename;
66 m_paused = false;
67 m_stopped = true;
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;
85
86 openStruct.lpstrDeviceType = _T("avivideo");
87 openStruct.lpstrElementName = (wxChar *)m_filename.c_str();
88 openStruct.hWndParent = 0;
89
90 mciSendCommand(0, MCI_OPEN,
91 MCI_OPEN_ELEMENT|MCI_DGV_OPEN_PARENT|MCI_OPEN_TYPE|MCI_DGV_OPEN_32BIT,
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
99 mciSendCommand(m_internal->m_dev_id, MCI_SET, MCI_SET_TIME_FORMAT,
100 (DWORD)(LPVOID)&setStruct);
101
102
103 statusStruct.dwCallback = 0;
104 statusStruct.dwItem = MCI_DGV_STATUS_FRAME_RATE;
105 mciSendCommand(m_internal->m_dev_id, MCI_STATUS,
106 MCI_STATUS_ITEM,
107 (DWORD)(LPVOID)&statusStruct);
108
109 m_frameRate = ((double)statusStruct.dwReturn) / 1000;
110
111 statusStruct.dwItem = MCI_DGV_STATUS_BITSPERSAMPLE;
112 mciSendCommand(m_internal->m_dev_id, MCI_STATUS, MCI_STATUS_ITEM,
113 (DWORD)(LPVOID)&statusStruct);
114 m_bps = statusStruct.dwReturn;
115
116 }
117
118 bool wxVideoWindows::Pause()
119 {
120 if (m_paused || m_stopped)
121 return true;
122 m_paused = true;
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)
129 return true;
130 m_paused = false;
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);
148 return true;
149 }
150
151 bool wxVideoWindows::SetSize(wxSize WXUNUSED(size))
152 {
153 return true;
154 }
155
156 bool wxVideoWindows::IsCapable(wxVideoType v_type) const
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))
166 return false;
167
168 win_struct.hWnd = (HWND)output.GetHWND();
169 mciSendCommand(m_internal->m_dev_id, MCI_WINDOW,
170 MCI_DGV_WINDOW_HWND, (DWORD)(LPVOID)&win_struct);
171 return true;
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,
182 MCI_DGV_WINDOW_HWND, (DWORD)(LPVOID)&win_struct);
183 }
184
185 bool wxVideoWindows::Play()
186 {
187 if (!m_stopped)
188 return false;
189 m_stopped = false;
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)
198 return false;
199 m_stopped = true;
200 if (::mciSendCommand(m_internal->m_dev_id, MCI_STOP, MCI_WAIT, NULL) != 0)
201 return false;
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__