#include "wx/wxprec.h"
#ifdef __BORLANDC__
-#pragma hdrstop
+ #pragma hdrstop
#endif
// disable "cast truncates constant value" for VARIANT_BOOL values
#pragma warning (disable:4310)
#endif
-//---------------------------------------------------------------------------
-// MediaCtrl include
-//---------------------------------------------------------------------------
+#if wxUSE_MEDIACTRL && wxUSE_ACTIVEX
+
#include "wx/mediactrl.h"
-//---------------------------------------------------------------------------
-// Compilation guard
-//---------------------------------------------------------------------------
-#if wxUSE_MEDIACTRL
+#ifndef WX_PRECOMP
+ #include "wx/log.h"
+ #include "wx/dcclient.h"
+ #include "wx/timer.h"
+ #include "wx/math.h" // log10 & pow
+ #include "wx/stopwatch.h"
+#endif
-//---------------------------------------------------------------------------
-// WX Includes
-//---------------------------------------------------------------------------
-#include "wx/log.h" // wxLogDebug
-#include "wx/math.h" // log10 & pow
#include "wx/msw/private.h" // user info and wndproc setting/getting
-#include "wx/dcclient.h"
-#include "wx/timer.h"
#include "wx/dynlib.h"
-#include "wx/stopwatch.h"
//---------------------------------------------------------------------------
// wxActiveXContainer - includes all the COM-specific stuff we need
#endif
wxSize m_bestSize; // Cached size
-#ifdef __WXDEBUG__ // Stuff for getting useful debugging strings
+ // Stuff for getting useful debugging strings
+#if wxDEBUG_LEVEL
wxDynamicLibrary m_dllQuartz;
LPAMGETERRORTEXT m_lpAMGetErrorText;
wxString GetErrorString(HRESULT hrdsv);
-#endif // __WXDEBUG__
+#endif // wxDEBUG_LEVEL
+ wxEvtHandler* m_evthandler;
friend class wxAMMediaEvtHandler;
DECLARE_DYNAMIC_CLASS(wxAMMediaBackend)
bool m_bLoadEventSent; // Whether or not FinishLoaded was already called
// prevents it being called multiple times
- DECLARE_NO_COPY_CLASS(wxAMMediaEvtHandler)
+ wxDECLARE_NO_COPY_CLASS(wxAMMediaEvtHandler);
};
//===========================================================================
//---------------------------------------------------------------------------
// Usual debugging macros
//---------------------------------------------------------------------------
-#ifdef __WXDEBUG__
+#if wxDEBUG_LEVEL
#define MAX_ERROR_TEXT_LEN 160
// Get the error string for Active Movie
wxAMMediaBackend::wxAMMediaBackend()
:m_pAX(NULL),
#ifdef __WXWINCE__
- m_pWMP(NULL)
+ m_pWMP(NULL),
#else
m_pAM(NULL),
- m_pMP(NULL)
+ m_pMP(NULL),
#endif
+ m_bestSize(wxDefaultSize)
{
+ m_evthandler = NULL;
}
//---------------------------------------------------------------------------
if (GetMP())
GetMP()->Release();
- m_ctrl->PopEventHandler(true);
+ if (m_evthandler)
+ {
+ m_ctrl->RemoveEventHandler(m_evthandler);
+ delete m_evthandler;
+ }
}
}
{
// First get the AMGetErrorText procedure in debug
// mode for more meaningful messages
-#ifdef __WXDEBUG__
- if ( m_dllQuartz.Load(_T("quartz.dll"), wxDL_VERBATIM) )
+#if wxDEBUG_LEVEL
+ if ( m_dllQuartz.Load(wxT("quartz.dll"), wxDL_VERBATIM) )
{
m_lpAMGetErrorText = (LPAMGETERRORTEXT)
m_dllQuartz.GetSymbolAorW(wxT("AMGetErrorText"));
}
-#endif // __WXDEBUG__
+#endif // wxDEBUG_LEVEL
#endif
);
// Connect for events
- m_ctrl->PushEventHandler(new wxAMMediaEvtHandler(this));
+ m_evthandler = new wxAMMediaEvtHandler(this);
+ m_ctrl->PushEventHandler(m_evthandler);
//
// Here we set up wx-specific stuff for the default
return false;
}
+ m_bestSize = wxDefaultSize;
return true;
}
//---------------------------------------------------------------------------
void wxAMMediaBackend::FinishLoad()
{
- // Get the original video size
- GetAM()->get_ImageSourceWidth((long*)&m_bestSize.x);
- GetAM()->get_ImageSourceHeight((long*)&m_bestSize.y);
-
NotifyMovieLoaded();
}
}
//---------------------------------------------------------------------------
-// wxAMMediaBackend::GetVolume
+// wxAMMediaBackend::GetVolume and SetVolume()
//
-// Gets the volume through the IActiveMovie interface -
-// value ranges from 0 (MAX volume) to -10000 (minimum volume).
-// -100 per decibel (Logorithmic in 0.01db per step).
+// Notice that for the IActiveMovie interface value ranges from 0 (MAX volume)
+// to -10000 (minimum volume) and the scale is logarithmic in 0.01db per step.
//---------------------------------------------------------------------------
+
double wxAMMediaBackend::GetVolume()
{
long lVolume;
return 0.0;
}
- // Volume conversion from Greg Hazel
- double dVolume = (double)lVolume / 125;
+ double dVolume = lVolume / 2000.; // volume is now in [-5..0] range
+ dVolume = pow(10.0, dVolume); // [10^-5, 1]
+ dVolume -= 0.00001; // [0, 1-10^-5]
+ dVolume /= 1 - 0.00001; // [0, 1]
- // convert to 0 to 1
- dVolume = pow(10.0, dVolume/20.0);
- // handle -INF
- dVolume *= 1 + pow(10.0, -5.0);
- dVolume -= pow(10.0, -5.0);
return dVolume;
}
-//---------------------------------------------------------------------------
-// wxAMMediaBackend::SetVolume
-//
-// Sets the volume through the IActiveMovie interface -
-// value ranges from 0 (MAX volume) to -10000 (minimum volume).
-// -100 per decibel (Logorithmic in 0.01db per step).
-//---------------------------------------------------------------------------
bool wxAMMediaBackend::SetVolume(double dVolume)
{
- // Volume conversion from Greg Hazel
- long lVolume;
- // handle -INF
- dVolume *= 1 - pow(10.0, -5.0);
- dVolume += pow(10.0, -5.0);
- // convert to -100db to 0db
- dVolume = 20 * log10(dVolume);
- // scale to -10000 to 0
- lVolume = (long)(125 * dVolume);
-
- HRESULT hr = GetAM()->put_Volume( lVolume );
+ // inverse the transformation above
+ long lVolume = static_cast<long>(2000*log10(dVolume + (1 - dVolume)*0.00001));
+
+ HRESULT hr = GetAM()->put_Volume(lVolume);
if(FAILED(hr))
{
wxAMLOG(hr);
//---------------------------------------------------------------------------
wxSize wxAMMediaBackend::GetVideoSize() const
{
- return m_bestSize;
+ if (m_bestSize == wxDefaultSize)
+ {
+ wxAMMediaBackend* self = wxConstCast(this, wxAMMediaBackend);
+ long w = 0;
+ long h = 0;
+
+ self->GetAM()->get_ImageSourceWidth(&w);
+ self->GetAM()->get_ImageSourceHeight(&h);
+
+ if (w != 0 && h != 0)
+ self->m_bestSize.Set(w, h);
+ else
+ return wxSize(0,0);
+ }
+
+ return m_bestSize;
}
//---------------------------------------------------------------------------
#include "wx/html/forcelnk.h"
FORCE_LINK_ME(wxmediabackend_am)
-//---------------------------------------------------------------------------
-// End wxMediaCtrl Compilation Guard and this file
-//---------------------------------------------------------------------------
-#endif // wxUSE_MEDIACTRL
\ No newline at end of file
+#endif // wxUSE_MEDIACTRL && wxUSE_ACTIVEX