]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia2/lib/vidxanm.cpp
1 ////////////////////////////////////////////////////////////////////////////////
4 // Author: Guilhem Lavaux
7 // Copyright: (C) 1997, 1998, 1999 Guilhem Lavaux
8 // License: wxWindows license
9 ////////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "vidxanm.h"
20 #include <wx/gtk/win_gtk.h>
23 #include <X11/Intrinsic.h>
25 #include <gtk/gtkwidget.h>
26 #include <gtk/gtkwindow.h>
28 #include <gdk/gdkprivate.h>
31 #include <wx/filefn.h>
32 #include <wx/wfstream.h>
34 #define WXMMEDIA_INTERNAL
38 IMPLEMENT_DYNAMIC_CLASS(wxVideoXANIM
, wxVideoBaseDriver
)
40 class wxVideoXANIMProcess
: public wxProcess
{
42 wxVideoXANIMProcess(wxVideoXANIM
*xanim
);
44 void OnTerminate(int pid
, int status
);
47 wxVideoXANIM
*m_vid_xanim
;
51 wxVideoXANIMProcess::wxVideoXANIMProcess(wxVideoXANIM
*xanim
)
56 void wxVideoXANIMProcess::OnTerminate(int WXUNUSED(pid
), int WXUNUSED(status
))
58 m_vid_xanim
->m_xanim_started
= FALSE
;
61 wxVideoXANIM::wxVideoXANIM()
64 m_internal
= new wxXANIMinternal
;
65 m_xanim_detector
= new wxVideoXANIMProcess(this);
66 m_xanim_started
= FALSE
;
71 wxVideoXANIM::wxVideoXANIM(wxInputStream
& str
)
72 : wxVideoBaseDriver(str
)
74 m_internal
= new wxXANIMinternal
;
75 m_xanim_detector
= new wxVideoXANIMProcess(this);
76 m_xanim_started
= FALSE
;
79 m_filename
= wxGetTempFileName("vidxa");
80 wxFileOutputStream
fout(m_filename
);
85 wxVideoXANIM::~wxVideoXANIM()
90 delete m_xanim_detector
;
92 wxRemoveFile(m_filename
);
95 bool wxVideoXANIM::Play()
97 if (!m_paused
&& m_xanim_started
)
99 if (!m_video_output
) {
100 wxVideoCreateFrame(this);
104 // The movie starts with xanim
105 if (RestartXANIM()) {
112 bool wxVideoXANIM::Pause()
114 if (!m_paused
&& SendCommand(" ")) {
121 bool wxVideoXANIM::Resume()
123 if (m_paused
&& SendCommand(" ")) {
130 bool wxVideoXANIM::Stop()
132 if (!m_xanim_started
)
137 m_xanim_started
= FALSE
;
143 bool wxVideoXANIM::SetVolume(wxUint8 vol
)
148 wxString
str_vol("v%d", vol
);
149 return SendCommand(str_vol
.GetData());
152 bool wxVideoXANIM::Resize(wxUint16
WXUNUSED(w
), wxUint16
WXUNUSED(h
))
155 // Actually, I think that we just need to resize the output window ...
159 bool wxVideoXANIM::GetSize(wxSize
& size
) const
165 bool wxVideoXANIM::IsCapable(wxVideoType v_type
)
167 if (v_type
== wxVIDEO_MSAVI
|| v_type
== wxVIDEO_MPEG
||
168 v_type
== wxVIDEO_QT
|| v_type
== wxVIDEO_GIF
|| v_type
== wxVIDEO_JMOV
||
169 v_type
== wxVIDEO_FLI
|| v_type
== wxVIDEO_IFF
|| v_type
== wxVIDEO_SGI
)
175 bool wxVideoXANIM::IsPaused()
180 bool wxVideoXANIM::IsStopped()
182 return !m_xanim_started
;
185 bool wxVideoXANIM::AttachOutput(wxWindow
& out
)
187 if (!wxVideoBaseDriver::AttachOutput(out
))
193 void wxVideoXANIM::DetachOutput()
196 m_xanim_started
= FALSE
;
199 wxVideoBaseDriver::DetachOutput();
202 bool wxVideoXANIM::SendCommand(const char *command
, char **ret
,
205 if (!m_xanim_started
)
209 // Send a command to XAnim through X11 Property
210 XChangeProperty(m_internal
->xanim_dpy
, m_internal
->xanim_window
,
211 m_internal
->xanim_atom
,
212 XA_STRING
, 8, PropModeReplace
, (unsigned char *)command
,
214 XFlush(m_internal
->xanim_dpy
);
220 XGetWindowProperty(m_internal
->xanim_dpy
, m_internal
->xanim_window
,
221 m_internal
->xanim_ret
, 0, 16, True
, AnyPropertyType
,
222 &prop_type
, &prop_format
, (unsigned long *)size
,
223 &extra
, (unsigned char **)ret
);
228 bool wxVideoXANIM::RestartXANIM()
230 wxString xanim_command
;
234 unsigned long nitems
;
239 if (!m_video_output
|| m_xanim_started
)
242 // Check if we can change the size of the window dynamicly
243 xanim_chg_size
= TRUE
;
244 // Get current display
246 m_internal
->xanim_dpy
= gdk_display
;
247 // We absolutely need the window to be realized.
248 GtkPizza
*pizza
= GTK_PIZZA( m_video_output
->m_wxwindow
);
249 GdkWindow
*window
= pizza
->bin_window
;
251 m_internal
->xanim_window
=
252 ((GdkWindowPrivate
*)window
)->xwindow
;
254 // Get the XANIM atom
255 m_internal
->xanim_atom
= XInternAtom(m_internal
->xanim_dpy
,
256 "XANIM_PROPERTY", False
);
259 xanim_command
.Printf(_T("xanim -Zr +Ze +Sr +f +W%d +f +q "
260 "+Av70 %s %s"), m_internal
->xanim_window
,
261 (xanim_chg_size
) ? _T("") : _T(""),
262 WXSTRINGCAST m_filename
);
265 if (!wxExecute(xanim_command
, FALSE
, m_xanim_detector
))
268 // Wait for XAnim to be ready
270 m_xanim_started
= TRUE
;
271 while (nitems
== 0 && m_xanim_started
) {
272 ret
= XGetWindowProperty(m_internal
->xanim_dpy
, m_internal
->xanim_window
,
273 m_internal
->xanim_atom
,
274 0, 4, False
, AnyPropertyType
, &prop_type
,
275 &prop_format
, &nitems
, &extra
,
276 (unsigned char **)&prop
);