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