]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/mmedia/vidwin.cpp
The last commit was too hasty.
[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(__GNUWIN32__)
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;
51 m_filename = wxGetTempFileName("wxvid");
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;
87 DWORD ret;
88
89 openStruct.lpstrDeviceType = "avivideo";
90 openStruct.lpstrElementName = (LPSTR)(m_filename.mb_str());
91 openStruct.hWndParent = 0;
92
93 ret = mciSendCommand(0, MCI_OPEN,
94 MCI_OPEN_ELEMENT|MCI_DGV_OPEN_PARENT|MCI_OPEN_TYPE|MCI_DGV_OPEN_32BIT,
95 (DWORD)(LPVOID)&openStruct);
96 m_internal->m_dev_id = openStruct.wDeviceID;
97
98
99 setStruct.dwCallback = 0;
100 setStruct.dwTimeFormat = MCI_FORMAT_FRAMES;
101
102 ret = mciSendCommand(m_internal->m_dev_id, MCI_SET, MCI_SET_TIME_FORMAT,
103 (DWORD)(LPVOID)&setStruct);
104
105
106 statusStruct.dwCallback = 0;
107 statusStruct.dwItem = MCI_DGV_STATUS_FRAME_RATE;
108 ret = mciSendCommand(m_internal->m_dev_id, MCI_STATUS,
109 MCI_STATUS_ITEM,
110 (DWORD)(LPVOID)&statusStruct);
111
112 m_frameRate = ((double)statusStruct.dwReturn) / 1000;
113
114 statusStruct.dwItem = MCI_DGV_STATUS_BITSPERSAMPLE;
115 ret = mciSendCommand(m_internal->m_dev_id, MCI_STATUS, MCI_STATUS_ITEM,
116 (DWORD)(LPVOID)&statusStruct);
117 m_bps = statusStruct.dwReturn;
118
119 }
120
121 bool wxVideoWindows::Pause()
122 {
123 if (m_paused || m_stopped)
124 return TRUE;
125 m_paused = TRUE;
126 return (mciSendCommand(m_internal->m_dev_id, MCI_PAUSE, MCI_WAIT, 0) == 0);
127 }
128
129 bool wxVideoWindows::Resume()
130 {
131 if (!m_paused || m_stopped)
132 return TRUE;
133 m_paused = FALSE;
134 return (mciSendCommand(m_internal->m_dev_id, MCI_RESUME, 0, 0) == 0);
135 }
136
137 bool wxVideoWindows::IsPaused() const
138 {
139 return m_paused;
140 }
141
142 bool wxVideoWindows::IsStopped() const
143 {
144 return m_stopped;
145 }
146
147 bool wxVideoWindows::GetSize(wxSize& size) const
148 {
149 size.SetWidth(200);
150 size.SetHeight(200);
151 return TRUE;
152 }
153
154 bool wxVideoWindows::SetSize(wxSize size)
155 {
156 return TRUE;
157 }
158
159 bool wxVideoWindows::IsCapable(wxVideoType v_type)
160 {
161 return (v_type == wxVIDEO_MSAVI);
162 }
163
164 bool wxVideoWindows::AttachOutput(wxWindow& output)
165 {
166 MCI_DGV_WINDOW_PARMS win_struct;
167
168 if (!wxVideoBaseDriver::AttachOutput(output))
169 return FALSE;
170
171 win_struct.hWnd = (HWND)output.GetHWND();
172 mciSendCommand(m_internal->m_dev_id, MCI_WINDOW,
173 MCI_DGV_WINDOW_HWND, (DWORD)(LPVOID)&win_struct);
174 return TRUE;
175 }
176
177 void wxVideoWindows::DetachOutput()
178 {
179 MCI_DGV_WINDOW_PARMS win_struct;
180
181 wxVideoBaseDriver::DetachOutput();
182
183 win_struct.hWnd = 0;
184 mciSendCommand(m_internal->m_dev_id, MCI_WINDOW,
185 MCI_DGV_WINDOW_HWND, (DWORD)(LPVOID)&win_struct);
186 }
187
188 bool wxVideoWindows::Play()
189 {
190 if (!m_stopped)
191 return FALSE;
192 m_stopped = FALSE;
193 return (mciSendCommand(m_internal->m_dev_id, MCI_PLAY, 0, NULL) == 0);
194 }
195
196 bool wxVideoWindows::Stop()
197 {
198 MCI_SEEK_PARMS seekStruct;
199
200 if (m_stopped)
201 return FALSE;
202 m_stopped = TRUE;
203 if (::mciSendCommand(m_internal->m_dev_id, MCI_STOP, MCI_WAIT, NULL) != 0)
204 return FALSE;
205
206 seekStruct.dwCallback = 0;
207 seekStruct.dwTo = 0;
208 return (::mciSendCommand(m_internal->m_dev_id, MCI_SEEK, MCI_SEEK_TO_START|MCI_WAIT, (DWORD)(LPVOID)&seekStruct) == 0);
209 }
210
211 // TODO TODO
212 // I hate windows :-(. The doc says MCI_STATUS should return all info I want but when I call it
213 // it returns to me with an UNSUPPORTED_FUNCTION error. I will have to do all by myself. Grrrr !
214
215 wxString wxVideoWindows::GetMovieCodec() const
216 {
217 return wxT("No info");
218 }
219
220 wxString wxVideoWindows::GetAudioCodec() const
221 {
222 return wxT("No info");
223 }
224
225 wxUint32 wxVideoWindows::GetSampleRate() const
226 {
227 return 22500;
228 }
229
230 wxUint8 wxVideoWindows::GetChannels() const
231 {
232 return 1;
233 }
234
235 wxUint8 wxVideoWindows::GetBPS() const
236 {
237 return m_bps;
238 }
239
240 double wxVideoWindows::GetFrameRate() const
241 {
242 return m_frameRate;
243 }
244
245 wxUint32 wxVideoWindows::GetNbFrames() const
246 {
247 return 0;
248 }
249
250 #endif
251 // __WINDOWS__