]> git.saurik.com Git - wxWidgets.git/blame - utils/wxMMedia2/lib/vidwin.cpp
Ok. Vidwin works again on Windows.
[wxWidgets.git] / utils / wxMMedia2 / lib / vidwin.cpp
CommitLineData
4d6306eb
GL
1////////////////////////////////////////////////////////////////////////////////
2// Name: vidwin.h
3// Purpose: wxMMedia
4// Author: Guilhem Lavaux
5// Created: February 1998
6// Updated:
ef366f35 7// Copyright: (C) 1998, 1999, 2000 Guilhem Lavaux
4d6306eb
GL
8// License: wxWindows license
9////////////////////////////////////////////////////////////////////////////////
10
11#ifdef __GNUG__
12#pragma implementation "vidwin.h"
13#endif
14
4d6306eb 15#include "wx/wxprec.h"
ebaad2cc
GL
16
17#ifndef WX_PRECOMP
4d6306eb
GL
18#include "wx/wx.h"
19#endif
20
ebaad2cc
GL
21#include "wx/stream.h"
22#include "wx/wfstream.h"
23
4d6306eb
GL
24#define WXMMEDIA_INTERNAL
25#include <windows.h>
26#include <mmsystem.h>
27#include <digitalv.h>
4d6306eb
GL
28#include "vidwin.h"
29
30#ifdef __BORLANDC__
31#pragma hdrstop
32#endif
33
ebaad2cc
GL
34IMPLEMENT_DYNAMIC_CLASS(wxVideoWindows, wxVideoBaseDriver)
35
36wxVideoWindows::wxVideoWindows()
4d6306eb
GL
37{
38}
39
ebaad2cc
GL
40wxVideoWindows::wxVideoWindows(wxInputStream& str)
41 : wxVideoBaseDriver(str)
4d6306eb 42{
ebaad2cc
GL
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();
4d6306eb
GL
53}
54
ebaad2cc
GL
55wxVideoWindows::wxVideoWindows(const wxString& filename)
56 : wxVideoBaseDriver(filename)
4d6306eb 57{
ebaad2cc
GL
58 m_internal = new wxVIDWinternal;
59 m_remove_file = FALSE;
60 m_filename = filename;
61 m_paused = FALSE;
62 m_stopped = TRUE;
63 OpenFile();
4d6306eb
GL
64}
65
66wxVideoWindows::~wxVideoWindows(void)
67{
ebaad2cc 68 mciSendCommand(m_internal->m_dev_id, MCI_CLOSE, 0, 0);
4d6306eb 69
ebaad2cc
GL
70 if (m_internal)
71 delete m_internal;
4d6306eb
GL
72}
73
ebaad2cc 74void wxVideoWindows::OpenFile()
4d6306eb 75{
ebaad2cc
GL
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}
4d6306eb 88
ebaad2cc
GL
89bool 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}
4d6306eb 96
ebaad2cc
GL
97bool wxVideoWindows::Resume()
98{
99 if (!m_paused || m_stopped)
100 return TRUE;
101 m_paused = FALSE;
171774fc 102 return (mciSendCommand(m_internal->m_dev_id, MCI_RESUME, 0, 0) == 0);
4d6306eb
GL
103}
104
171774fc 105bool wxVideoWindows::IsPaused() const
4d6306eb 106{
ebaad2cc 107 return m_paused;
4d6306eb
GL
108}
109
171774fc 110bool wxVideoWindows::IsStopped() const
4d6306eb 111{
ebaad2cc 112 return m_stopped;
4d6306eb
GL
113}
114
ebaad2cc 115bool wxVideoWindows::GetSize(wxSize& size) const
4d6306eb 116{
171774fc
GL
117 // Two random numbers.
118 size.SetWidth(200);
119 size.SetHeight(200);
ebaad2cc 120 return TRUE;
4d6306eb
GL
121}
122
171774fc 123bool wxVideoWindows::SetSize(wxSize size)
4d6306eb 124{
ebaad2cc 125 return TRUE;
4d6306eb
GL
126}
127
128bool wxVideoWindows::IsCapable(wxVideoType v_type)
129{
ebaad2cc 130 return (v_type == wxVIDEO_MSAVI);
4d6306eb
GL
131}
132
ebaad2cc 133bool wxVideoWindows::AttachOutput(wxWindow& output)
4d6306eb 134{
ebaad2cc
GL
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;
4d6306eb
GL
144}
145
ebaad2cc 146void wxVideoWindows::DetachOutput()
4d6306eb 147{
ebaad2cc 148 MCI_DGV_WINDOW_PARMS win_struct;
4d6306eb 149
ebaad2cc
GL
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);
4d6306eb
GL
155}
156
ebaad2cc 157bool wxVideoWindows::Play()
4d6306eb 158{
ebaad2cc
GL
159 if (!m_stopped)
160 return FALSE;
161 m_stopped = FALSE;
162 return (mciSendCommand(m_internal->m_dev_id, MCI_PLAY, 0, NULL) == 0);
4d6306eb
GL
163}
164
ebaad2cc 165bool wxVideoWindows::Stop()
4d6306eb 166{
171774fc
GL
167 MCI_SEEK_PARMS seekStruct;
168
ebaad2cc
GL
169 if (m_stopped)
170 return FALSE;
171 m_stopped = TRUE;
171774fc
GL
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
183wxString wxVideoWindows::GetMovieCodec() const
184{
185 return wxT("No info");
186}
187
188wxString wxVideoWindows::GetAudioCodec() const
189{
190 return wxT("No info");
191}
192
193wxUint32 wxVideoWindows::GetSampleRate() const
194{
195 return 22500;
196}
197
198wxUint8 wxVideoWindows::GetChannels() const
199{
200 return 1;
201}
202
203wxUint8 wxVideoWindows::GetBPS() const
204{
205 return 8;
206}
207
208double wxVideoWindows::GetFrameRate() const
209{
210 return 1.0;
211}
212
213wxUint32 wxVideoWindows::GetNbFrames() const
214{
215 return 0;
4d6306eb 216}