2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
23 #include "shockwavegraph.h"
25 #include "..\..\DSUtil\DSUtil.h"
27 CShockwaveGraph::CShockwaveGraph(HWND hParent
, HRESULT
& hr
)
32 if(!m_wndWindowFrame
.Create(NULL
, NULL
, WS_CHILD
|WS_VISIBLE
|WS_CLIPSIBLINGS
|WS_CLIPCHILDREN
,
33 CRect(0, 0, 0, 0), CWnd::FromHandle(hParent
), 0, NULL
))
39 if(!m_wndDestFrame
.Create(NULL
, WS_CHILD
|WS_VISIBLE
|WS_CLIPCHILDREN
|WS_CLIPSIBLINGS
,
40 CRect(0, 0, 0, 0), &m_wndWindowFrame
, 0))
47 CShockwaveGraph::~CShockwaveGraph()
49 m_wndDestFrame
.DestroyWindow();
50 m_wndWindowFrame
.DestroyWindow();
54 STDMETHODIMP
CShockwaveGraph::RenderFile(LPCWSTR lpcwstrFile
, LPCWSTR lpcwstrPlayList
)
56 try {m_wndDestFrame
.LoadMovie(0, CString(lpcwstrFile
));}
57 catch(CException
* e
) {e
->Delete(); return E_FAIL
;}
62 STDMETHODIMP
CShockwaveGraph::Run()
64 try {if(m_fs
!= State_Running
) m_wndDestFrame
.Play();}
65 catch(CException
* e
) {e
->Delete(); return E_FAIL
;}
67 m_wndWindowFrame
.EnableWindow();
68 // m_wndDestFrame.EnableWindow();
71 STDMETHODIMP
CShockwaveGraph::Pause()
73 try {if(m_fs
== State_Running
) m_wndDestFrame
.Stop();}
74 catch(CException
* e
) {e
->Delete(); return E_FAIL
;}
78 STDMETHODIMP
CShockwaveGraph::Stop()
80 try {m_wndDestFrame
.Stop();}
81 catch(CException
* e
) {e
->Delete(); return E_FAIL
;}
85 STDMETHODIMP
CShockwaveGraph::GetState(LONG msTimeout
, OAFilterState
* pfs
)
87 OAFilterState fs
= m_fs
;
91 if(m_wndDestFrame
.IsPlaying() && m_fs
== State_Stopped
) m_fs
= State_Running
;
92 else if(!m_wndDestFrame
.IsPlaying() && m_fs
== State_Running
) m_fs
= State_Stopped
;
101 return pfs
? *pfs
= fs
, S_OK
: E_POINTER
;
105 STDMETHODIMP
CShockwaveGraph::IsFormatSupported(const GUID
* pFormat
)
107 return !pFormat
? E_POINTER
: *pFormat
== TIME_FORMAT_FRAME
? S_OK
: S_FALSE
;
109 STDMETHODIMP
CShockwaveGraph::GetTimeFormat(GUID
* pFormat
)
111 return pFormat
? *pFormat
= TIME_FORMAT_FRAME
, S_OK
: E_POINTER
;
113 STDMETHODIMP
CShockwaveGraph::GetDuration(LONGLONG
* pDuration
)
115 CheckPointer(pDuration
, E_POINTER
);
117 try {if(m_wndDestFrame
.get_ReadyState() >= READYSTATE_COMPLETE
) *pDuration
= m_wndDestFrame
.get_TotalFrames();}
118 catch(CException
* e
) {e
->Delete(); return E_FAIL
;}
121 STDMETHODIMP
CShockwaveGraph::GetCurrentPosition(LONGLONG
* pCurrent
)
123 CheckPointer(pCurrent
, E_POINTER
);
125 try {if(m_wndDestFrame
.get_ReadyState() >= READYSTATE_COMPLETE
) *pCurrent
= m_wndDestFrame
.get_FrameNum();}
126 catch(CException
* e
) {e
->Delete(); return E_FAIL
;}
129 STDMETHODIMP
CShockwaveGraph::SetPositions(LONGLONG
* pCurrent
, DWORD dwCurrentFlags
, LONGLONG
* pStop
, DWORD dwStopFlags
)
131 if(dwCurrentFlags
&AM_SEEKING_AbsolutePositioning
)
133 m_wndDestFrame
.put_FrameNum(*pCurrent
);
135 if(m_fs
== State_Running
&& !m_wndDestFrame
.IsPlaying())
136 m_wndDestFrame
.Play();
137 else if((m_fs
== State_Paused
|| m_fs
== State_Stopped
) && m_wndDestFrame
.IsPlaying())
138 m_wndDestFrame
.Stop();
140 m_wndDestFrame
.put_Quality(1); // 0=Low, 1=High, 2=AutoLow, 3=AutoHigh
149 STDMETHODIMP
CShockwaveGraph::put_Visible(long Visible
)
151 if(IsWindow(m_wndDestFrame
.m_hWnd
))
152 m_wndDestFrame
.ShowWindow(Visible
== OATRUE
? SW_SHOWNORMAL
: SW_HIDE
);
155 STDMETHODIMP
CShockwaveGraph::get_Visible(long* pVisible
)
157 return pVisible
? *pVisible
= (m_wndDestFrame
.IsWindowVisible() ? OATRUE
: OAFALSE
), S_OK
: E_POINTER
;
159 STDMETHODIMP
CShockwaveGraph::SetWindowPosition(long Left
, long Top
, long Width
, long Height
)
161 if(IsWindow(m_wndWindowFrame
.m_hWnd
))
162 m_wndWindowFrame
.MoveWindow(Left
, Top
, Width
, Height
);
168 STDMETHODIMP
CShockwaveGraph::SetDestinationPosition(long Left
, long Top
, long Width
, long Height
)// {return E_NOTIMPL;}
170 if(IsWindow(m_wndDestFrame
.m_hWnd
))
171 m_wndDestFrame
.MoveWindow(Left
, Top
, Width
, Height
);
175 STDMETHODIMP
CShockwaveGraph::GetVideoSize(long* pWidth
, long* pHeight
)
177 if(!pWidth
|| !pHeight
) return E_POINTER
;
180 m_wndWindowFrame
.GetWindowRect(r
);
184 *pHeight
= r
.Height();
188 // no call exists to determine these...
189 *pWidth
= 384;//m_wndDestFrame.get_;
192 NotifyEvent(EC_BG_AUDIO_CHANGED
, 2, 0);
201 STDMETHODIMP
CShockwaveGraph::put_Volume(long lVolume
)
203 lVolume
= (lVolume
== -10000) ? 0 : (int)pow(10.0, ((double)lVolume
)/5000+2);
204 lVolume
= lVolume
*0x10000/100;
205 lVolume
= max(min(lVolume
, 0xffff), 0);
206 waveOutSetVolume(0, (lVolume
<<16)|lVolume
);
210 STDMETHODIMP
CShockwaveGraph::get_Volume(long* plVolume
)
212 CheckPointer(plVolume
, E_POINTER
);
214 waveOutGetVolume(0, (DWORD
*)plVolume
);
215 *plVolume
= (*plVolume
&0xffff + ((*plVolume
>>16)&0xffff)) / 2;
216 *plVolume
= *plVolume
*100/0x10000;
217 *plVolume
= (int)((log10(1.0*(*plVolume
))-2)*5000);
218 *plVolume
= max(min(*plVolume
, 0), -10000);
224 STDMETHODIMP
CShockwaveGraph::QueryProgress(LONGLONG
* pllTotal
, LONGLONG
* pllCurrent
)
227 *pllCurrent
= m_wndDestFrame
.PercentLoaded();
232 STDMETHODIMP_(engine_t
) CShockwaveGraph::GetEngine() {return ShockWave
;}