X64 transport [Part 5] (Update plugins.cpp)
[xy_vsfilter.git] / src / apps / mplayerc / ShockwaveGraph.cpp
blob5530b04ac481bfd2e4bc99dc90a77a1df3c9a063
1 /*
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)
8 * any later version.
9 *
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
22 #include "stdafx.h"
23 #include "shockwavegraph.h"
24 #include "resource.h"
25 #include "..\..\DSUtil\DSUtil.h"
27 CShockwaveGraph::CShockwaveGraph(HWND hParent, HRESULT& hr)
28 : m_fs(State_Stopped)
30 hr = S_OK;
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))
35 hr = E_FAIL;
36 return;
39 if(!m_wndDestFrame.Create(NULL, WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,
40 CRect(0, 0, 0, 0), &m_wndWindowFrame, 0))
42 hr = E_FAIL;
43 return;
47 CShockwaveGraph::~CShockwaveGraph()
49 m_wndDestFrame.DestroyWindow();
50 m_wndWindowFrame.DestroyWindow();
53 // IGraphBuilder
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;}
58 return S_OK;
61 // IMediaControl
62 STDMETHODIMP CShockwaveGraph::Run()
64 try {if(m_fs != State_Running) m_wndDestFrame.Play();}
65 catch(CException* e) {e->Delete(); return E_FAIL;}
66 m_fs = State_Running;
67 m_wndWindowFrame.EnableWindow();
68 // m_wndDestFrame.EnableWindow();
69 return S_OK;
71 STDMETHODIMP CShockwaveGraph::Pause()
73 try {if(m_fs == State_Running) m_wndDestFrame.Stop();}
74 catch(CException* e) {e->Delete(); return E_FAIL;}
75 m_fs = State_Paused;
76 return S_OK;
78 STDMETHODIMP CShockwaveGraph::Stop()
80 try {m_wndDestFrame.Stop();}
81 catch(CException* e) {e->Delete(); return E_FAIL;}
82 m_fs = State_Stopped;
83 return S_OK;
85 STDMETHODIMP CShockwaveGraph::GetState(LONG msTimeout, OAFilterState* pfs)
87 OAFilterState fs = m_fs;
89 try
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;
93 fs = m_fs;
95 catch(CException* e)
97 e->Delete();
98 return E_FAIL;
101 return pfs ? *pfs = fs, S_OK : E_POINTER;
104 // IMediaSeeking
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);
116 *pDuration = 0;
117 try {if(m_wndDestFrame.get_ReadyState() >= READYSTATE_COMPLETE) *pDuration = m_wndDestFrame.get_TotalFrames();}
118 catch(CException* e) {e->Delete(); return E_FAIL;}
119 return S_OK;
121 STDMETHODIMP CShockwaveGraph::GetCurrentPosition(LONGLONG* pCurrent)
123 CheckPointer(pCurrent, E_POINTER);
124 *pCurrent = 0;
125 try {if(m_wndDestFrame.get_ReadyState() >= READYSTATE_COMPLETE) *pCurrent = m_wndDestFrame.get_FrameNum();}
126 catch(CException* e) {e->Delete(); return E_FAIL;}
127 return S_OK;
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
142 return S_OK;
145 return E_INVALIDARG;
148 // IVideoWindow
149 STDMETHODIMP CShockwaveGraph::put_Visible(long Visible)
151 if(IsWindow(m_wndDestFrame.m_hWnd))
152 m_wndDestFrame.ShowWindow(Visible == OATRUE ? SW_SHOWNORMAL : SW_HIDE);
153 return S_OK;
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);
164 return S_OK;
167 // IBasicVideo
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);
173 return S_OK;
175 STDMETHODIMP CShockwaveGraph::GetVideoSize(long* pWidth, long* pHeight)
177 if(!pWidth || !pHeight) return E_POINTER;
179 CRect r;
180 m_wndWindowFrame.GetWindowRect(r);
181 if(!r.IsRectEmpty())
183 *pWidth = r.Width();
184 *pHeight = r.Height();
186 else
188 // no call exists to determine these...
189 *pWidth = 384;//m_wndDestFrame.get_;
190 *pHeight = 288;
192 NotifyEvent(EC_BG_AUDIO_CHANGED, 2, 0);
195 return S_OK;
198 #include <math.h>
200 // IBasicAudio
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);
208 return S_OK;
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);
220 return S_OK;
223 // IAMOpenProgress
224 STDMETHODIMP CShockwaveGraph::QueryProgress(LONGLONG* pllTotal, LONGLONG* pllCurrent)
226 *pllTotal = 100;
227 *pllCurrent = m_wndDestFrame.PercentLoaded();
228 return S_OK;
231 // IGraphEngine
232 STDMETHODIMP_(engine_t) CShockwaveGraph::GetEngine() {return ShockWave;}