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