]> git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia2/lib/vidwin.cpp
b6f5ee9914d428e1b88e35614a183bd7ffed58ba
[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
49 wxFileOutputStream temp_file(m_filename);
50 temp_file << str;
51
52 OpenFile();
53 }
54
55 wxVideoWindows::wxVideoWindows(const wxString& filename)
56 : wxVideoBaseDriver(filename)
57 {
58 m_internal = new wxVIDWinternal;
59 m_remove_file = FALSE;
60 m_filename = filename;
61 m_paused = FALSE;
62 m_stopped = TRUE;
63 OpenFile();
64 }
65
66 wxVideoWindows::~wxVideoWindows(void)
67 {
68 mciSendCommand(m_internal->m_dev_id, MCI_CLOSE, 0, 0);
69
70 if (m_internal)
71 delete m_internal;
72 }
73
74 void wxVideoWindows::OpenFile()
75 {
76 MCI_DGV_OPEN_PARMS open_struct;
77 DWORD ret;
78
79 open_struct.lpstrDeviceType = "avivideo";
80 open_struct.lpstrElementName = (LPSTR)(m_filename.mb_str());
81 open_struct.hWndParent = 0;
82
83 ret = mciSendCommand(0, MCI_OPEN,
84 MCI_OPEN_ELEMENT|MCI_DGV_OPEN_PARENT|MCI_OPEN_TYPE|MCI_DGV_OPEN_32BIT,
85 (DWORD)(LPVOID)&open_struct);
86 m_internal->m_dev_id = open_struct.wDeviceID;
87 }
88
89 bool wxVideoWindows::Pause()
90 {
91 if (m_paused || m_stopped)
92 return TRUE;
93 m_paused = TRUE;
94 return (mciSendCommand(m_internal->m_dev_id, MCI_PAUSE, 0, 0) == 0);
95 }
96
97 bool wxVideoWindows::Resume()
98 {
99 if (!m_paused || m_stopped)
100 return TRUE;
101 m_paused = FALSE;
102 return (mciSendCommand(m_internal->m_dev_id, MCI_RESUME, 0, 0) == 0);
103 }
104
105 bool wxVideoWindows::IsPaused() const
106 {
107 return m_paused;
108 }
109
110 bool wxVideoWindows::IsStopped() const
111 {
112 return m_stopped;
113 }
114
115 bool wxVideoWindows::GetSize(wxSize& size) const
116 {
117 // Two random numbers.
118 size.SetWidth(200);
119 size.SetHeight(200);
120 return TRUE;
121 }
122
123 bool wxVideoWindows::SetSize(wxSize size)
124 {
125 return TRUE;
126 }
127
128 bool wxVideoWindows::IsCapable(wxVideoType v_type)
129 {
130 return (v_type == wxVIDEO_MSAVI);
131 }
132
133 bool wxVideoWindows::AttachOutput(wxWindow& output)
134 {
135 MCI_DGV_WINDOW_PARMS win_struct;
136
137 if (!wxVideoBaseDriver::AttachOutput(output))
138 return FALSE;
139
140 win_struct.hWnd = (HWND)output.GetHWND();
141 mciSendCommand(m_internal->m_dev_id, MCI_WINDOW,
142 MCI_DGV_WINDOW_HWND, (DWORD)(LPVOID)&win_struct);
143 return TRUE;
144 }
145
146 void wxVideoWindows::DetachOutput()
147 {
148 MCI_DGV_WINDOW_PARMS win_struct;
149
150 wxVideoBaseDriver::DetachOutput();
151
152 win_struct.hWnd = 0;
153 mciSendCommand(m_internal->m_dev_id, MCI_WINDOW,
154 MCI_DGV_WINDOW_HWND, (DWORD)(LPVOID)&win_struct);
155 }
156
157 bool wxVideoWindows::Play()
158 {
159 if (!m_stopped)
160 return FALSE;
161 m_stopped = FALSE;
162 return (mciSendCommand(m_internal->m_dev_id, MCI_PLAY, 0, NULL) == 0);
163 }
164
165 bool wxVideoWindows::Stop()
166 {
167 MCI_SEEK_PARMS seekStruct;
168
169 if (m_stopped)
170 return FALSE;
171 m_stopped = TRUE;
172 if (::mciSendCommand(m_internal->m_dev_id, MCI_STOP, 0, NULL) != 0)
173 return FALSE;
174
175 seekStruct.dwCallback = 0;
176 seekStruct.dwTo = 0;
177 return (::mciSendCommand(m_internal->m_dev_id, MCI_SEEK, 0, (DWORD)(LPVOID)&seekStruct) == 0);
178 }
179
180
181 // TODO TODO
182
183 wxString wxVideoWindows::GetMovieCodec() const
184 {
185 return wxT("No info");
186 }
187
188 wxString wxVideoWindows::GetAudioCodec() const
189 {
190 return wxT("No info");
191 }
192
193 wxUint32 wxVideoWindows::GetSampleRate() const
194 {
195 return 22500;
196 }
197
198 wxUint8 wxVideoWindows::GetChannels() const
199 {
200 return 1;
201 }
202
203 wxUint8 wxVideoWindows::GetBPS() const
204 {
205 return 8;
206 }
207
208 double wxVideoWindows::GetFrameRate() const
209 {
210 return 1.0;
211 }
212
213 wxUint32 wxVideoWindows::GetNbFrames() const
214 {
215 return 0;
216 }