]> git.saurik.com Git - wxWidgets.git/blame - utils/wxMMedia2/lib/vidxanm.cpp
* Added IsPaused() to wxSoundFileStream
[wxWidgets.git] / utils / wxMMedia2 / lib / vidxanm.cpp
CommitLineData
4d6306eb
GL
1////////////////////////////////////////////////////////////////////////////////
2// Name: vidxanm.cpp
3// Purpose: wxMMedia
4// Author: Guilhem Lavaux
5// Created: 1997
6// Updated: 1998
526ddb13 7// Copyright: (C) 1997, 1998, 1999 Guilhem Lavaux
4d6306eb
GL
8// License: wxWindows license
9////////////////////////////////////////////////////////////////////////////////
10#ifdef __GNUG__
11#pragma implementation "vidxanm.h"
12#endif
4d6306eb 13#ifdef WX_PRECOMP
526ddb13 14#include <wx_prec.h>
4d6306eb 15#else
526ddb13 16#include <wx/wx.h>
4d6306eb
GL
17#endif
18#include <X11/Xlib.h>
19#include <X11/Intrinsic.h>
20#ifdef __WXGTK__
8a7c9dcc 21#include <gtk/gtkwidget.h>
526ddb13 22#include <gtk/gtkwindow.h>
4d6306eb
GL
23#include <gdk/gdk.h>
24#include <gdk/gdkprivate.h>
25#endif
26
526ddb13
GL
27#include <wx/filefn.h>
28#include <wx/wfstream.h>
29
30#define WXMMEDIA_INTERNAL
31#include "vidbase.h"
32#include "vidxanm.h"
33
526ddb13 34IMPLEMENT_DYNAMIC_CLASS(wxVideoXANIM, wxVideoBaseDriver)
526ddb13 35
4d6306eb
GL
36wxVideoXANIM::wxVideoXANIM()
37 : wxVideoBaseDriver()
38{
526ddb13
GL
39 m_internal = new wxXANIMinternal;
40 m_xanim_started = FALSE;
41 m_paused = FALSE;
42 m_filename = "";
4d6306eb
GL
43}
44
45wxVideoXANIM::wxVideoXANIM(wxInputStream& str)
526ddb13 46 : wxVideoBaseDriver(str)
4d6306eb 47{
526ddb13
GL
48 m_internal = new wxXANIMinternal;
49 m_xanim_started = FALSE;
50 m_paused = FALSE;
4d6306eb 51
526ddb13
GL
52 m_filename = wxGetTempFileName("vidxa");
53 wxFileOutputStream fout(m_filename);
54
55 fout << str;
4d6306eb
GL
56}
57
58wxVideoXANIM::~wxVideoXANIM()
59{
526ddb13 60 if (m_xanim_started)
b83290c3 61 Stop();
526ddb13
GL
62 delete m_internal;
63
64 wxRemoveFile(m_filename);
4d6306eb
GL
65}
66
b83290c3 67bool wxVideoXANIM::Play()
4d6306eb 68{
526ddb13
GL
69 if (!m_paused && m_xanim_started)
70 return TRUE;
71 if (!m_video_output) {
4d6306eb 72 wxVideoCreateFrame(this);
526ddb13
GL
73 return TRUE;
74 }
4d6306eb 75
b83290c3
GL
76 // The movie starts with xanim
77 if (RestartXANIM()) {
526ddb13
GL
78 m_paused = FALSE;
79 return TRUE;
4d6306eb 80 }
526ddb13 81 return FALSE;
4d6306eb
GL
82}
83
84bool wxVideoXANIM::Pause()
85{
526ddb13
GL
86 if (!m_paused && SendCommand(" ")) {
87 m_paused = TRUE;
4d6306eb
GL
88 return TRUE;
89 }
90 return FALSE;
91}
92
93bool wxVideoXANIM::Resume()
94{
526ddb13
GL
95 if (m_paused && SendCommand(" ")) {
96 m_paused = FALSE;
4d6306eb
GL
97 return TRUE;
98 }
99 return FALSE;
100}
101
b83290c3 102bool wxVideoXANIM::Stop()
4d6306eb 103{
526ddb13 104 if (!m_xanim_started)
b83290c3 105 return FALSE;
4d6306eb
GL
106
107 SendCommand("q");
108
526ddb13
GL
109 m_xanim_started = FALSE;
110 m_paused = FALSE;
b83290c3
GL
111
112 return TRUE;
4d6306eb
GL
113}
114
115bool 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
124bool 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
b83290c3
GL
131bool wxVideoXANIM::GetSize(wxSize& size) const
132{
133 // Not implemented
134 return FALSE;
135}
136
4d6306eb
GL
137bool 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)
526ddb13 142 return TRUE;
4d6306eb 143 else
526ddb13 144 return FALSE;
4d6306eb
GL
145}
146
147bool wxVideoXANIM::AttachOutput(wxVideoOutput& out)
148{
149 if (!wxVideoBaseDriver::AttachOutput(out))
526ddb13 150 return FALSE;
4d6306eb 151
b83290c3 152 return TRUE;
4d6306eb
GL
153}
154
155void wxVideoXANIM::DetachOutput()
156{
157 SendCommand("q");
526ddb13
GL
158 m_xanim_started = FALSE;
159 m_paused = FALSE;
4d6306eb
GL
160
161 wxVideoBaseDriver::DetachOutput();
162}
163
164bool wxVideoXANIM::SendCommand(const char *command, char **ret,
165 wxUint32 *size)
166{
526ddb13 167 if (!m_xanim_started)
4d6306eb 168 if (!RestartXANIM())
526ddb13 169 return FALSE;
4d6306eb
GL
170
171 // Send a command to XAnim through X11 Property
526ddb13
GL
172 XChangeProperty(m_internal->xanim_dpy, m_internal->xanim_window,
173 m_internal->xanim_atom,
4d6306eb
GL
174 XA_STRING, 8, PropModeReplace, (unsigned char *)command,
175 strlen(command));
526ddb13 176 XFlush(m_internal->xanim_dpy);
4d6306eb
GL
177 if (ret) {
178 int prop_format;
179 Atom prop_type;
180 unsigned long extra;
181
526ddb13
GL
182 XGetWindowProperty(m_internal->xanim_dpy, m_internal->xanim_window,
183 m_internal->xanim_ret, 0, 16, True, AnyPropertyType,
4d6306eb
GL
184 &prop_type, &prop_format, (unsigned long *)size,
185 &extra, (unsigned char **)ret);
186 }
526ddb13 187 return TRUE;
4d6306eb
GL
188}
189
190bool 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
526ddb13
GL
201 if (!m_video_output || m_xanim_started)
202 return FALSE;
4d6306eb
GL
203
204 // Check if we can change the size of the window dynamicly
526ddb13 205 xanim_chg_size = m_video_output->DynamicSize();
4d6306eb 206 // Get current display
4d6306eb 207#ifdef __WXGTK__
526ddb13
GL
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;
4d6306eb
GL
213#endif
214 // Get the XANIM atom
526ddb13 215 m_internal->xanim_atom = XInternAtom(m_internal->xanim_dpy,
4d6306eb
GL
216 "XANIM_PROPERTY", False);
217
218 // Build the command
526ddb13
GL
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
4d6306eb 224 // Execute it
526ddb13
GL
225 if (!wxExecute(xanim_command, FALSE))
226 return FALSE;
4d6306eb
GL
227
228 // Wait for XAnim to be ready
229 nitems = 0;
230 while (nitems == 0) {
526ddb13
GL
231 ret = XGetWindowProperty(m_internal->xanim_dpy, m_internal->xanim_window,
232 m_internal->xanim_atom,
4d6306eb
GL
233 0, 4, False, AnyPropertyType, &prop_type,
234 &prop_format, &nitems, &extra,
235 (unsigned char **)&prop);
236// wxYield();
237 }
238
b83290c3 239 m_paused = FALSE;
526ddb13 240 m_xanim_started = TRUE;
4d6306eb 241
526ddb13 242 return TRUE;
4d6306eb 243}