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