]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia2/lib/vidxanm.cpp
a4ca4ef074a9426ecbcf22e84de26b109e548911
1 // -------------------------------------------------------------------------
4 // Author: Guilhem Lavaux
7 // Copyright: (C) 1997, 1998, 1999 Guilhem Lavaux
8 // License: wxWindows license
9 // -------------------------------------------------------------------------
12 #pragma implementation "vidxanm.h"
15 #include <wx/wxprec.h>
22 #include <wx/gtk/win_gtk.h>
25 #include <X11/Intrinsic.h>
27 #include <gtk/gtkwidget.h>
28 #include <gtk/gtkwindow.h>
30 #include <gdk/gdkprivate.h>
33 #include <wx/filefn.h>
34 #include <wx/wfstream.h>
36 #define WXMMEDIA_INTERNAL
40 IMPLEMENT_DYNAMIC_CLASS(wxVideoXANIM
, wxVideoBaseDriver
)
42 // -------------------------------------------------------------------------
43 // End process detector
45 class wxVideoXANIMProcess
: public wxProcess
{
47 wxVideoXANIMProcess(wxVideoXANIM
*xanim
);
49 void OnTerminate(int pid
, int status
);
52 wxVideoXANIM
*m_vid_xanim
;
55 // -------------------------------------------------------------------------
56 // XAnim video driver (implementation)
58 wxVideoXANIMProcess::wxVideoXANIMProcess(wxVideoXANIM
*xanim
)
63 void wxVideoXANIMProcess::OnTerminate(int WXUNUSED(pid
), int WXUNUSED(status
))
65 m_vid_xanim
->m_xanim_started
= FALSE
;
66 m_vid_xanim
->OnFinished();
69 wxVideoXANIM::wxVideoXANIM()
72 m_internal
= new wxXANIMinternal
;
73 m_xanim_detector
= new wxVideoXANIMProcess(this);
74 m_xanim_started
= FALSE
;
77 m_remove_file
= FALSE
;
80 wxVideoXANIM::wxVideoXANIM(wxInputStream
& str
)
81 : wxVideoBaseDriver(str
)
83 m_internal
= new wxXANIMinternal
;
84 m_xanim_detector
= new wxVideoXANIMProcess(this);
85 m_xanim_started
= FALSE
;
88 m_filename
= wxGetTempFileName("vidxa");
90 wxFileOutputStream
fout(m_filename
);
95 wxVideoXANIM::wxVideoXANIM(const wxString
& filename
)
97 m_internal
= new wxXANIMinternal
;
98 m_xanim_detector
= new wxVideoXANIMProcess(this);
99 m_xanim_started
= FALSE
;
102 m_filename
= filename
;
103 m_remove_file
= FALSE
;
106 wxVideoXANIM::~wxVideoXANIM()
111 delete m_xanim_detector
;
114 wxRemoveFile(m_filename
);
117 bool wxVideoXANIM::Play()
119 if (!m_paused
&& m_xanim_started
)
121 if (!m_video_output
) {
122 wxVideoCreateFrame(this);
126 // The movie starts with xanim
127 if (RestartXANIM()) {
134 bool wxVideoXANIM::Pause()
136 if (!m_paused
&& SendCommand(" ")) {
143 bool wxVideoXANIM::Resume()
145 if (m_paused
&& SendCommand(" ")) {
152 bool wxVideoXANIM::Stop()
154 if (!m_xanim_started
)
159 // We are waiting for the termination of the subprocess.
160 while (m_xanim_started
) {
169 bool wxVideoXANIM::Resize(wxUint16 w
, wxUint16 h
)
174 m_video_output
->SetSize(w
, h
);
178 bool wxVideoXANIM::GetSize(wxSize
& size
) const
183 bool wxVideoXANIM::IsCapable(wxVideoType v_type
)
185 if (v_type
== wxVIDEO_MSAVI
|| v_type
== wxVIDEO_MPEG
||
186 v_type
== wxVIDEO_QT
|| v_type
== wxVIDEO_GIF
|| v_type
== wxVIDEO_JMOV
||
187 v_type
== wxVIDEO_FLI
|| v_type
== wxVIDEO_IFF
|| v_type
== wxVIDEO_SGI
)
193 bool wxVideoXANIM::IsPaused()
198 bool wxVideoXANIM::IsStopped()
200 return !m_xanim_started
;
203 bool wxVideoXANIM::AttachOutput(wxWindow
& out
)
205 if (!wxVideoBaseDriver::AttachOutput(out
))
211 void wxVideoXANIM::DetachOutput()
214 m_xanim_started
= FALSE
;
217 wxVideoBaseDriver::DetachOutput();
220 bool wxVideoXANIM::SendCommand(const char *command
, char **ret
,
223 if (!m_xanim_started
)
227 // Send a command to XAnim through X11 Property
228 XChangeProperty(m_internal
->xanim_dpy
, m_internal
->xanim_window
,
229 m_internal
->xanim_atom
,
230 XA_STRING
, 8, PropModeReplace
, (unsigned char *)command
,
232 XFlush(m_internal
->xanim_dpy
);
238 XGetWindowProperty(m_internal
->xanim_dpy
, m_internal
->xanim_window
,
239 m_internal
->xanim_ret
, 0, 16, True
, AnyPropertyType
,
240 &prop_type
, &prop_format
, (unsigned long *)size
,
241 &extra
, (unsigned char **)ret
);
246 bool wxVideoXANIM::RestartXANIM()
248 wxString xanim_command
;
252 unsigned long nitems
;
257 if (!m_video_output
|| m_xanim_started
)
260 // Check if we can change the size of the window dynamicly
261 xanim_chg_size
= TRUE
;
262 // Get current display
264 m_internal
->xanim_dpy
= gdk_display
;
265 GtkPizza
*pizza
= GTK_PIZZA( m_video_output
->m_wxwindow
);
266 GdkWindow
*window
= pizza
->bin_window
;
268 m_internal
->xanim_window
=
269 ((GdkWindowPrivate
*)window
)->xwindow
;
271 // Get the XANIM atom
272 m_internal
->xanim_atom
= XInternAtom(m_internal
->xanim_dpy
,
273 "XANIM_PROPERTY", False
);
276 xanim_command
.Printf(wxT("xanim -Zr +Ze +Sr +f +W%d +f +q "
277 "+Av70 %s %s"), m_internal
->xanim_window
,
278 (xanim_chg_size
) ? _T("") : _T(""),
279 WXSTRINGCAST m_filename
);
282 if (!wxExecute(xanim_command
, FALSE
, m_xanim_detector
))
285 // Wait for XAnim to be ready
287 m_xanim_started
= TRUE
;
288 while (nitems
== 0 && m_xanim_started
) {
289 ret
= XGetWindowProperty(m_internal
->xanim_dpy
, m_internal
->xanim_window
,
290 m_internal
->xanim_atom
,
291 0, 4, False
, AnyPropertyType
, &prop_type
,
292 &prop_format
, &nitems
, &extra
,
293 (unsigned char **)&prop
);
297 m_video_output
->SetSize(m_video_output
->GetSize());
298 // Very useful ! Actually it sends a SETSIZE event to XAnim