]> git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia2/lib/vidxanm.cpp
Sound recording works on Windows
[wxWidgets.git] / utils / wxMMedia2 / lib / vidxanm.cpp
1 ////////////////////////////////////////////////////////////////////////////////
2 // Name: vidxanm.cpp
3 // Purpose: wxMMedia
4 // Author: Guilhem Lavaux
5 // Created: 1997
6 // Updated: 1998
7 // Copyright: (C) 1997, 1998, 1999 Guilhem Lavaux
8 // License: wxWindows license
9 ////////////////////////////////////////////////////////////////////////////////
10 #ifdef __GNUG__
11 #pragma implementation "vidxanm.h"
12 #endif
13 #ifdef WX_PRECOMP
14 #include <wx_prec.h>
15 #else
16 #include <wx/wx.h>
17 #endif
18 #include <X11/Xlib.h>
19 #include <X11/Intrinsic.h>
20 #ifdef __WXGTK__
21 #include <gtk/gtkwidget.h>
22 #include <gtk/gtkwindow.h>
23 #include <gdk/gdk.h>
24 #include <gdk/gdkprivate.h>
25 #endif
26
27 #include <wx/filefn.h>
28 #include <wx/wfstream.h>
29
30 #define WXMMEDIA_INTERNAL
31 #include "vidbase.h"
32 #include "vidxanm.h"
33
34 IMPLEMENT_DYNAMIC_CLASS(wxVideoXANIM, wxVideoBaseDriver)
35
36 wxVideoXANIM::wxVideoXANIM()
37 : wxVideoBaseDriver()
38 {
39 m_internal = new wxXANIMinternal;
40 m_xanim_started = FALSE;
41 m_paused = FALSE;
42 m_filename = "";
43 }
44
45 wxVideoXANIM::wxVideoXANIM(wxInputStream& str)
46 : wxVideoBaseDriver(str)
47 {
48 m_internal = new wxXANIMinternal;
49 m_xanim_started = FALSE;
50 m_paused = FALSE;
51
52 m_filename = wxGetTempFileName("vidxa");
53 wxFileOutputStream fout(m_filename);
54
55 fout << str;
56 }
57
58 wxVideoXANIM::~wxVideoXANIM()
59 {
60 if (m_xanim_started)
61 Stop();
62 delete m_internal;
63
64 wxRemoveFile(m_filename);
65 }
66
67 bool wxVideoXANIM::Play()
68 {
69 if (!m_paused && m_xanim_started)
70 return TRUE;
71 if (!m_video_output) {
72 wxVideoCreateFrame(this);
73 return TRUE;
74 }
75
76 // The movie starts with xanim
77 if (RestartXANIM()) {
78 m_paused = FALSE;
79 return TRUE;
80 }
81 return FALSE;
82 }
83
84 bool wxVideoXANIM::Pause()
85 {
86 if (!m_paused && SendCommand(" ")) {
87 m_paused = TRUE;
88 return TRUE;
89 }
90 return FALSE;
91 }
92
93 bool wxVideoXANIM::Resume()
94 {
95 if (m_paused && SendCommand(" ")) {
96 m_paused = FALSE;
97 return TRUE;
98 }
99 return FALSE;
100 }
101
102 bool wxVideoXANIM::Stop()
103 {
104 if (!m_xanim_started)
105 return FALSE;
106
107 SendCommand("q");
108
109 m_xanim_started = FALSE;
110 m_paused = FALSE;
111
112 return TRUE;
113 }
114
115 bool wxVideoXANIM::SetVolume(wxUint8 vol)
116 {
117 if (vol > 100)
118 vol = 100;
119
120 wxString str_vol("v%d", vol);
121 return SendCommand(str_vol.GetData());
122 }
123
124 bool wxVideoXANIM::Resize(wxUint16 WXUNUSED(w), wxUint16 WXUNUSED(h))
125 {
126 // Not implemented
127 // Actually, I think that we just need to resize the output window ...
128 return FALSE;
129 }
130
131 bool wxVideoXANIM::GetSize(wxSize& size) const
132 {
133 // Not implemented
134 return FALSE;
135 }
136
137 bool wxVideoXANIM::IsCapable(wxVideoType v_type)
138 {
139 if (v_type == wxVIDEO_MSAVI || v_type == wxVIDEO_MPEG ||
140 v_type == wxVIDEO_QT || v_type == wxVIDEO_GIF || v_type == wxVIDEO_JMOV ||
141 v_type == wxVIDEO_FLI || v_type == wxVIDEO_IFF || v_type == wxVIDEO_SGI)
142 return TRUE;
143 else
144 return FALSE;
145 }
146
147 bool wxVideoXANIM::AttachOutput(wxVideoOutput& out)
148 {
149 if (!wxVideoBaseDriver::AttachOutput(out))
150 return FALSE;
151
152 return TRUE;
153 }
154
155 void wxVideoXANIM::DetachOutput()
156 {
157 SendCommand("q");
158 m_xanim_started = FALSE;
159 m_paused = FALSE;
160
161 wxVideoBaseDriver::DetachOutput();
162 }
163
164 bool wxVideoXANIM::SendCommand(const char *command, char **ret,
165 wxUint32 *size)
166 {
167 if (!m_xanim_started)
168 if (!RestartXANIM())
169 return FALSE;
170
171 // Send a command to XAnim through X11 Property
172 XChangeProperty(m_internal->xanim_dpy, m_internal->xanim_window,
173 m_internal->xanim_atom,
174 XA_STRING, 8, PropModeReplace, (unsigned char *)command,
175 strlen(command));
176 XFlush(m_internal->xanim_dpy);
177 if (ret) {
178 int prop_format;
179 Atom prop_type;
180 unsigned long extra;
181
182 XGetWindowProperty(m_internal->xanim_dpy, m_internal->xanim_window,
183 m_internal->xanim_ret, 0, 16, True, AnyPropertyType,
184 &prop_type, &prop_format, (unsigned long *)size,
185 &extra, (unsigned char **)ret);
186 }
187 return TRUE;
188 }
189
190 bool wxVideoXANIM::RestartXANIM()
191 {
192 wxString xanim_command;
193 int ret;
194 Atom prop_type;
195 int prop_format;
196 unsigned long nitems;
197 unsigned long extra;
198 char prop[4];
199 bool xanim_chg_size;
200
201 if (!m_video_output || m_xanim_started)
202 return FALSE;
203
204 // Check if we can change the size of the window dynamicly
205 xanim_chg_size = m_video_output->DynamicSize();
206 // Get current display
207 #ifdef __WXGTK__
208 m_internal->xanim_dpy = gdk_display;
209 // We absolutely need the window to be realized.
210 gtk_widget_realize(m_video_output->m_wxwindow);
211 m_internal->xanim_window =
212 ((GdkWindowPrivate *)m_video_output->m_wxwindow->window)->xwindow;
213 #endif
214 // Get the XANIM atom
215 m_internal->xanim_atom = XInternAtom(m_internal->xanim_dpy,
216 "XANIM_PROPERTY", False);
217
218 // Build the command
219 xanim_command.Printf(_T("xanim -Zr +Ze +Sr +f +W%d +f +q "
220 "+Av70 %s %s"), m_internal->xanim_window,
221 (xanim_chg_size) ? _T("") : _T(""),
222 WXSTRINGCAST m_filename);
223
224 // Execute it
225 if (!wxExecute(xanim_command, FALSE))
226 return FALSE;
227
228 // Wait for XAnim to be ready
229 nitems = 0;
230 while (nitems == 0) {
231 ret = XGetWindowProperty(m_internal->xanim_dpy, m_internal->xanim_window,
232 m_internal->xanim_atom,
233 0, 4, False, AnyPropertyType, &prop_type,
234 &prop_format, &nitems, &extra,
235 (unsigned char **)&prop);
236 // wxYield();
237 }
238
239 m_paused = FALSE;
240 m_xanim_started = TRUE;
241
242 return TRUE;
243 }