1998-11-09 18:37:38 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: vidxanm.cpp
|
|
|
|
// Purpose: wxMMedia
|
|
|
|
// Author: Guilhem Lavaux
|
|
|
|
// Created: 1997
|
|
|
|
// Updated: 1998
|
1999-08-14 12:06:35 +00:00
|
|
|
// Copyright: (C) 1997, 1998, 1999 Guilhem Lavaux
|
1998-11-09 18:37:38 +00:00
|
|
|
// License: wxWindows license
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation "vidxanm.h"
|
|
|
|
#endif
|
|
|
|
#ifdef WX_PRECOMP
|
1999-08-14 12:06:35 +00:00
|
|
|
#include <wx_prec.h>
|
1998-11-09 18:37:38 +00:00
|
|
|
#else
|
1999-08-14 12:06:35 +00:00
|
|
|
#include <wx/wx.h>
|
1998-11-09 18:37:38 +00:00
|
|
|
#endif
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Intrinsic.h>
|
|
|
|
#ifdef __WXGTK__
|
1999-02-18 18:18:06 +00:00
|
|
|
#include <gtk/gtkwidget.h>
|
1999-08-14 12:06:35 +00:00
|
|
|
#include <gtk/gtkwindow.h>
|
1998-11-09 18:37:38 +00:00
|
|
|
#include <gdk/gdk.h>
|
|
|
|
#include <gdk/gdkprivate.h>
|
|
|
|
#endif
|
|
|
|
|
1999-08-14 12:06:35 +00:00
|
|
|
#include <wx/filefn.h>
|
|
|
|
#include <wx/wfstream.h>
|
|
|
|
|
|
|
|
#define WXMMEDIA_INTERNAL
|
|
|
|
#include "vidbase.h"
|
|
|
|
#include "vidxanm.h"
|
|
|
|
|
|
|
|
#if !USE_SHARED_LIBRARY
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS(wxVideoXANIM, wxVideoBaseDriver)
|
|
|
|
#endif
|
|
|
|
|
1998-11-09 18:37:38 +00:00
|
|
|
wxVideoXANIM::wxVideoXANIM()
|
|
|
|
: wxVideoBaseDriver()
|
|
|
|
{
|
1999-08-14 12:06:35 +00:00
|
|
|
m_internal = new wxXANIMinternal;
|
|
|
|
m_xanim_started = FALSE;
|
|
|
|
m_paused = FALSE;
|
|
|
|
m_filename = "";
|
1998-11-09 18:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxVideoXANIM::wxVideoXANIM(wxInputStream& str)
|
1999-08-14 12:06:35 +00:00
|
|
|
: wxVideoBaseDriver(str)
|
1998-11-09 18:37:38 +00:00
|
|
|
{
|
1999-08-14 12:06:35 +00:00
|
|
|
m_internal = new wxXANIMinternal;
|
|
|
|
m_xanim_started = FALSE;
|
|
|
|
m_paused = FALSE;
|
1998-11-09 18:37:38 +00:00
|
|
|
|
1999-08-14 12:06:35 +00:00
|
|
|
m_filename = wxGetTempFileName("vidxa");
|
|
|
|
wxFileOutputStream fout(m_filename);
|
|
|
|
|
|
|
|
fout << str;
|
1998-11-09 18:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxVideoXANIM::~wxVideoXANIM()
|
|
|
|
{
|
1999-08-14 12:06:35 +00:00
|
|
|
if (m_xanim_started)
|
1998-11-09 18:37:38 +00:00
|
|
|
StopPlay();
|
1999-08-14 12:06:35 +00:00
|
|
|
delete m_internal;
|
|
|
|
|
|
|
|
wxRemoveFile(m_filename);
|
1998-11-09 18:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool wxVideoXANIM::StartPlay()
|
|
|
|
{
|
1999-08-14 12:06:35 +00:00
|
|
|
if (!m_paused && m_xanim_started)
|
|
|
|
return TRUE;
|
|
|
|
if (!m_video_output) {
|
1998-11-09 18:37:38 +00:00
|
|
|
wxVideoCreateFrame(this);
|
1999-08-14 12:06:35 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
1998-11-09 18:37:38 +00:00
|
|
|
|
|
|
|
if (SendCommand(" ")) {
|
1999-08-14 12:06:35 +00:00
|
|
|
m_paused = FALSE;
|
|
|
|
return TRUE;
|
1998-11-09 18:37:38 +00:00
|
|
|
}
|
1999-08-14 12:06:35 +00:00
|
|
|
return FALSE;
|
1998-11-09 18:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool wxVideoXANIM::Pause()
|
|
|
|
{
|
1999-08-14 12:06:35 +00:00
|
|
|
if (!m_paused && SendCommand(" ")) {
|
|
|
|
m_paused = TRUE;
|
1998-11-09 18:37:38 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool wxVideoXANIM::Resume()
|
|
|
|
{
|
1999-08-14 12:06:35 +00:00
|
|
|
if (m_paused && SendCommand(" ")) {
|
|
|
|
m_paused = FALSE;
|
1998-11-09 18:37:38 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wxVideoXANIM::StopPlay()
|
|
|
|
{
|
1999-08-14 12:06:35 +00:00
|
|
|
if (!m_xanim_started)
|
1998-11-09 18:37:38 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
SendCommand("q");
|
|
|
|
|
1999-08-14 12:06:35 +00:00
|
|
|
m_xanim_started = FALSE;
|
|
|
|
m_paused = FALSE;
|
1998-11-09 18:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool wxVideoXANIM::SetVolume(wxUint8 vol)
|
|
|
|
{
|
|
|
|
if (vol > 100)
|
|
|
|
vol = 100;
|
|
|
|
|
|
|
|
wxString str_vol("v%d", vol);
|
|
|
|
return SendCommand(str_vol.GetData());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool wxVideoXANIM::Resize(wxUint16 WXUNUSED(w), wxUint16 WXUNUSED(h))
|
|
|
|
{
|
|
|
|
// Not implemented
|
|
|
|
// Actually, I think that we just need to resize the output window ...
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool wxVideoXANIM::IsCapable(wxVideoType v_type)
|
|
|
|
{
|
|
|
|
if (v_type == wxVIDEO_MSAVI || v_type == wxVIDEO_MPEG ||
|
|
|
|
v_type == wxVIDEO_QT || v_type == wxVIDEO_GIF || v_type == wxVIDEO_JMOV ||
|
|
|
|
v_type == wxVIDEO_FLI || v_type == wxVIDEO_IFF || v_type == wxVIDEO_SGI)
|
1999-08-14 12:06:35 +00:00
|
|
|
return TRUE;
|
1998-11-09 18:37:38 +00:00
|
|
|
else
|
1999-08-14 12:06:35 +00:00
|
|
|
return FALSE;
|
1998-11-09 18:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool wxVideoXANIM::AttachOutput(wxVideoOutput& out)
|
|
|
|
{
|
|
|
|
if (!wxVideoBaseDriver::AttachOutput(out))
|
1999-08-14 12:06:35 +00:00
|
|
|
return FALSE;
|
1998-11-09 18:37:38 +00:00
|
|
|
|
|
|
|
return RestartXANIM();
|
|
|
|
}
|
|
|
|
|
|
|
|
void wxVideoXANIM::DetachOutput()
|
|
|
|
{
|
|
|
|
SendCommand("q");
|
1999-08-14 12:06:35 +00:00
|
|
|
m_xanim_started = FALSE;
|
|
|
|
m_paused = FALSE;
|
1998-11-09 18:37:38 +00:00
|
|
|
|
|
|
|
wxVideoBaseDriver::DetachOutput();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool wxVideoXANIM::SendCommand(const char *command, char **ret,
|
|
|
|
wxUint32 *size)
|
|
|
|
{
|
1999-08-14 12:06:35 +00:00
|
|
|
if (!m_xanim_started)
|
1998-11-09 18:37:38 +00:00
|
|
|
if (!RestartXANIM())
|
1999-08-14 12:06:35 +00:00
|
|
|
return FALSE;
|
1998-11-09 18:37:38 +00:00
|
|
|
|
|
|
|
// Send a command to XAnim through X11 Property
|
1999-08-14 12:06:35 +00:00
|
|
|
XChangeProperty(m_internal->xanim_dpy, m_internal->xanim_window,
|
|
|
|
m_internal->xanim_atom,
|
1998-11-09 18:37:38 +00:00
|
|
|
XA_STRING, 8, PropModeReplace, (unsigned char *)command,
|
|
|
|
strlen(command));
|
1999-08-14 12:06:35 +00:00
|
|
|
XFlush(m_internal->xanim_dpy);
|
1998-11-09 18:37:38 +00:00
|
|
|
if (ret) {
|
|
|
|
int prop_format;
|
|
|
|
Atom prop_type;
|
|
|
|
unsigned long extra;
|
|
|
|
|
1999-08-14 12:06:35 +00:00
|
|
|
XGetWindowProperty(m_internal->xanim_dpy, m_internal->xanim_window,
|
|
|
|
m_internal->xanim_ret, 0, 16, True, AnyPropertyType,
|
1998-11-09 18:37:38 +00:00
|
|
|
&prop_type, &prop_format, (unsigned long *)size,
|
|
|
|
&extra, (unsigned char **)ret);
|
|
|
|
}
|
1999-08-14 12:06:35 +00:00
|
|
|
return TRUE;
|
1998-11-09 18:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool wxVideoXANIM::RestartXANIM()
|
|
|
|
{
|
|
|
|
wxString xanim_command;
|
|
|
|
int ret;
|
|
|
|
Atom prop_type;
|
|
|
|
int prop_format;
|
|
|
|
unsigned long nitems;
|
|
|
|
unsigned long extra;
|
|
|
|
char prop[4];
|
|
|
|
bool xanim_chg_size;
|
|
|
|
|
1999-08-14 12:06:35 +00:00
|
|
|
if (!m_video_output || m_xanim_started)
|
|
|
|
return FALSE;
|
1998-11-09 18:37:38 +00:00
|
|
|
|
|
|
|
// Check if we can change the size of the window dynamicly
|
1999-08-14 12:06:35 +00:00
|
|
|
xanim_chg_size = m_video_output->DynamicSize();
|
1998-11-09 18:37:38 +00:00
|
|
|
// Get current display
|
|
|
|
#ifdef __WXGTK__
|
1999-08-14 12:06:35 +00:00
|
|
|
m_internal->xanim_dpy = gdk_display;
|
|
|
|
// We absolutely need the window to be realized.
|
|
|
|
gtk_widget_realize(m_video_output->m_wxwindow);
|
|
|
|
m_internal->xanim_window =
|
|
|
|
((GdkWindowPrivate *)m_video_output->m_wxwindow->window)->xwindow;
|
1998-11-09 18:37:38 +00:00
|
|
|
#endif
|
|
|
|
// Get the XANIM atom
|
1999-08-14 12:06:35 +00:00
|
|
|
m_internal->xanim_atom = XInternAtom(m_internal->xanim_dpy,
|
1998-11-09 18:37:38 +00:00
|
|
|
"XANIM_PROPERTY", False);
|
|
|
|
|
|
|
|
// Build the command
|
1999-08-14 12:06:35 +00:00
|
|
|
xanim_command.Printf(_T("xanim -Zr +Ze +Sr +f +W%d +f +q "
|
|
|
|
"+Av70 %s %s"), m_internal->xanim_window,
|
|
|
|
(xanim_chg_size) ? _T("") : _T(""),
|
|
|
|
WXSTRINGCAST m_filename);
|
|
|
|
|
1998-11-09 18:37:38 +00:00
|
|
|
// Execute it
|
1999-08-14 12:06:35 +00:00
|
|
|
if (!wxExecute(xanim_command, FALSE))
|
|
|
|
return FALSE;
|
1998-11-09 18:37:38 +00:00
|
|
|
|
|
|
|
// Wait for XAnim to be ready
|
|
|
|
nitems = 0;
|
|
|
|
while (nitems == 0) {
|
1999-08-14 12:06:35 +00:00
|
|
|
ret = XGetWindowProperty(m_internal->xanim_dpy, m_internal->xanim_window,
|
|
|
|
m_internal->xanim_atom,
|
1998-11-09 18:37:38 +00:00
|
|
|
0, 4, False, AnyPropertyType, &prop_type,
|
|
|
|
&prop_format, &nitems, &extra,
|
|
|
|
(unsigned char **)&prop);
|
|
|
|
// wxYield();
|
|
|
|
}
|
|
|
|
|
1999-08-14 12:06:35 +00:00
|
|
|
// m_paused = TRUE;
|
|
|
|
m_xanim_started = TRUE;
|
1998-11-09 18:37:38 +00:00
|
|
|
|
1999-08-14 12:06:35 +00:00
|
|
|
return TRUE;
|
1998-11-09 18:37:38 +00:00
|
|
|
}
|