]> git.saurik.com Git - wxWidgets.git/blame - contrib/src/mmedia/vidwin.cpp
Avoid warnings from mgl headers if possible.
[wxWidgets.git] / contrib / src / mmedia / vidwin.cpp
CommitLineData
e8482f24
GL
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
2b3644c7
JS
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
e8482f24
GL
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
42IMPLEMENT_DYNAMIC_CLASS(wxVideoWindows, wxVideoBaseDriver)
43
44wxVideoWindows::wxVideoWindows()
45{
46}
47
48wxVideoWindows::wxVideoWindows(wxInputStream& str)
49 : wxVideoBaseDriver(str)
50{
51 m_internal = new wxVIDWinternal;
dea7e44a 52 m_remove_file = true;
42c37dec 53 m_filename = wxGetTempFileName(_T("wxvid"));
dea7e44a
WS
54 m_paused = false;
55 m_stopped = true;
e8482f24
GL
56 m_frameRate = 1.0;
57
58 wxFileOutputStream temp_file(m_filename);
59 temp_file << str;
60
61 OpenFile();
62}
63
64wxVideoWindows::wxVideoWindows(const wxString& filename)
65 : wxVideoBaseDriver(filename)
66{
67 m_internal = new wxVIDWinternal;
dea7e44a 68 m_remove_file = false;
e8482f24 69 m_filename = filename;
dea7e44a
WS
70 m_paused = false;
71 m_stopped = true;
e8482f24
GL
72 m_frameRate = 1.0;
73 OpenFile();
74}
75
76wxVideoWindows::~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
84void wxVideoWindows::OpenFile()
85{
86 MCI_DGV_OPEN_PARMS openStruct;
87 MCI_DGV_SET_PARMS setStruct;
88 MCI_STATUS_PARMS statusStruct;
e8482f24 89
42c37dec 90 openStruct.lpstrDeviceType = _T("avivideo");
2b3644c7 91 openStruct.lpstrElementName = (wxChar *)m_filename.c_str();
e8482f24
GL
92 openStruct.hWndParent = 0;
93
42c37dec 94 mciSendCommand(0, MCI_OPEN,
dea7e44a 95 MCI_OPEN_ELEMENT|MCI_DGV_OPEN_PARENT|MCI_OPEN_TYPE|MCI_DGV_OPEN_32BIT,
e8482f24
GL
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
42c37dec 103 mciSendCommand(m_internal->m_dev_id, MCI_SET, MCI_SET_TIME_FORMAT,
e8482f24
GL
104 (DWORD)(LPVOID)&setStruct);
105
106
107 statusStruct.dwCallback = 0;
108 statusStruct.dwItem = MCI_DGV_STATUS_FRAME_RATE;
42c37dec 109 mciSendCommand(m_internal->m_dev_id, MCI_STATUS,
e8482f24
GL
110 MCI_STATUS_ITEM,
111 (DWORD)(LPVOID)&statusStruct);
112
113 m_frameRate = ((double)statusStruct.dwReturn) / 1000;
114
115 statusStruct.dwItem = MCI_DGV_STATUS_BITSPERSAMPLE;
42c37dec 116 mciSendCommand(m_internal->m_dev_id, MCI_STATUS, MCI_STATUS_ITEM,
e8482f24
GL
117 (DWORD)(LPVOID)&statusStruct);
118 m_bps = statusStruct.dwReturn;
119
120}
121
122bool wxVideoWindows::Pause()
123{
124 if (m_paused || m_stopped)
dea7e44a
WS
125 return true;
126 m_paused = true;
e8482f24
GL
127 return (mciSendCommand(m_internal->m_dev_id, MCI_PAUSE, MCI_WAIT, 0) == 0);
128}
129
130bool wxVideoWindows::Resume()
131{
132 if (!m_paused || m_stopped)
dea7e44a
WS
133 return true;
134 m_paused = false;
e8482f24
GL
135 return (mciSendCommand(m_internal->m_dev_id, MCI_RESUME, 0, 0) == 0);
136}
137
138bool wxVideoWindows::IsPaused() const
139{
140 return m_paused;
141}
142
143bool wxVideoWindows::IsStopped() const
144{
145 return m_stopped;
146}
147
148bool wxVideoWindows::GetSize(wxSize& size) const
149{
150 size.SetWidth(200);
151 size.SetHeight(200);
dea7e44a 152 return true;
e8482f24
GL
153}
154
42c37dec 155bool wxVideoWindows::SetSize(wxSize WXUNUSED(size))
e8482f24 156{
dea7e44a 157 return true;
e8482f24
GL
158}
159
2bbf230a 160bool wxVideoWindows::IsCapable(wxVideoType v_type) const
e8482f24
GL
161{
162 return (v_type == wxVIDEO_MSAVI);
163}
164
165bool wxVideoWindows::AttachOutput(wxWindow& output)
166{
167 MCI_DGV_WINDOW_PARMS win_struct;
168
169 if (!wxVideoBaseDriver::AttachOutput(output))
dea7e44a 170 return false;
e8482f24
GL
171
172 win_struct.hWnd = (HWND)output.GetHWND();
173 mciSendCommand(m_internal->m_dev_id, MCI_WINDOW,
dea7e44a
WS
174 MCI_DGV_WINDOW_HWND, (DWORD)(LPVOID)&win_struct);
175 return true;
e8482f24
GL
176}
177
178void 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,
dea7e44a 186 MCI_DGV_WINDOW_HWND, (DWORD)(LPVOID)&win_struct);
e8482f24
GL
187}
188
189bool wxVideoWindows::Play()
190{
191 if (!m_stopped)
dea7e44a
WS
192 return false;
193 m_stopped = false;
e8482f24
GL
194 return (mciSendCommand(m_internal->m_dev_id, MCI_PLAY, 0, NULL) == 0);
195}
196
197bool wxVideoWindows::Stop()
198{
199 MCI_SEEK_PARMS seekStruct;
200
201 if (m_stopped)
dea7e44a
WS
202 return false;
203 m_stopped = true;
e8482f24 204 if (::mciSendCommand(m_internal->m_dev_id, MCI_STOP, MCI_WAIT, NULL) != 0)
dea7e44a 205 return false;
e8482f24
GL
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
216wxString wxVideoWindows::GetMovieCodec() const
217{
218 return wxT("No info");
219}
220
221wxString wxVideoWindows::GetAudioCodec() const
222{
223 return wxT("No info");
224}
225
226wxUint32 wxVideoWindows::GetSampleRate() const
227{
228 return 22500;
229}
230
231wxUint8 wxVideoWindows::GetChannels() const
232{
233 return 1;
234}
235
236wxUint8 wxVideoWindows::GetBPS() const
237{
238 return m_bps;
239}
240
241double wxVideoWindows::GetFrameRate() const
242{
243 return m_frameRate;
244}
245
246wxUint32 wxVideoWindows::GetNbFrames() const
247{
248 return 0;
249}
250
251#endif
252 // __WINDOWS__