BaseGraph.cpp
上传用户:xjjlds
上传日期:2015-12-05
资源大小:22823k
文件大小:15k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. /* 
  2.  * Copyright (C) 2003-2005 Gabest
  3.  * http://www.gabest.org
  4.  *
  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.
  14.  *   
  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
  19.  *
  20.  */
  21. #include "stdafx.h"
  22. #include "basegraph.h"
  23. #include "....DSUtilDSUtil.h"
  24. //
  25. // CPlayerWindow
  26. //
  27. BOOL CPlayerWindow::PreCreateWindow(CREATESTRUCT& cs) 
  28. {
  29. if(!CWnd::PreCreateWindow(cs))
  30. return FALSE;
  31. cs.style &= ~WS_BORDER;
  32. cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, 
  33. ::LoadCursor(NULL, IDC_HAND), NULL, NULL);
  34. return TRUE;
  35. }
  36. BEGIN_MESSAGE_MAP(CPlayerWindow, CWnd)
  37. ON_WM_ERASEBKGND()
  38. END_MESSAGE_MAP()
  39. BOOL CPlayerWindow::OnEraseBkgnd(CDC* pDC)
  40. {
  41. for(CWnd* pChild = GetWindow(GW_CHILD); pChild; pChild = pChild->GetNextWindow())
  42. {
  43. if(!pChild->IsWindowVisible()) continue;
  44. CRect r;
  45. pChild->GetClientRect(&r);
  46. pChild->MapWindowPoints(this, &r);
  47. pDC->ExcludeClipRect(&r);
  48. }
  49. CRect r;
  50. GetClientRect(&r);
  51. pDC->FillSolidRect(&r, 0);
  52. return TRUE;
  53. }
  54. //
  55. // CBaseGraph
  56. //
  57. CBaseGraph::CBaseGraph()
  58. : CUnknown(NAME("CBaseGraph"), NULL)
  59. , m_hNotifyWnd(NULL)
  60. {
  61. }
  62. CBaseGraph::~CBaseGraph()
  63. {
  64. }
  65. STDMETHODIMP CBaseGraph::NonDelegatingQueryInterface(REFIID riid, void** ppv)
  66. {
  67.     CheckPointer(ppv, E_POINTER);
  68. return 
  69. QI(IFilterGraph)
  70. QI(IGraphBuilder)
  71. QI(IMediaControl)
  72. QI(IMediaSeeking)
  73. QI(IMediaEventEx)
  74. QI(IVideoWindow)
  75. QI(IBasicVideo)
  76. QI(IBasicAudio)
  77. QI(IAMOpenProgress)
  78. QI(IGraphEngine)
  79. __super::NonDelegatingQueryInterface(riid, ppv);
  80. }
  81. void CBaseGraph::ClearMessageQueue()
  82. {
  83. while(!m_msgqueue.IsEmpty())
  84. {
  85. GMSG msg = m_msgqueue.RemoveHead();
  86. FreeEventParams(msg.m_lEventCode, msg.m_lParam1, msg.m_lParam2);
  87. }
  88. }
  89. void CBaseGraph::NotifyEvent(long lEventCode, LONG_PTR lParam1, LONG_PTR lParam2)
  90. {
  91. if(!m_hNotifyWnd) return;
  92. GMSG msg;
  93. msg.m_lEventCode = lEventCode;
  94. msg.m_lParam1 = lParam1;
  95. msg.m_lParam2 = lParam2;
  96. m_msgqueue.AddTail(msg);
  97. PostMessage((HWND)m_hNotifyWnd, m_lNotifyMsg, 0, m_lNotifyInstData);
  98. }
  99. // IDispatch
  100. STDMETHODIMP CBaseGraph::GetTypeInfoCount(UINT* pctinfo) {return E_NOTIMPL;}
  101. STDMETHODIMP CBaseGraph::GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo) {return E_NOTIMPL;}
  102. STDMETHODIMP CBaseGraph::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId) {return E_NOTIMPL;}
  103. STDMETHODIMP CBaseGraph::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr) {return E_NOTIMPL;}
  104. // IFilterGraph
  105. STDMETHODIMP CBaseGraph::AddFilter(IBaseFilter* pFilter, LPCWSTR pName) {return E_NOTIMPL;}
  106. STDMETHODIMP CBaseGraph::RemoveFilter(IBaseFilter* pFilter) {return E_NOTIMPL;}
  107. STDMETHODIMP CBaseGraph::EnumFilters(IEnumFilters** ppEnum) {return E_NOTIMPL;}
  108. STDMETHODIMP CBaseGraph::FindFilterByName(LPCWSTR pName, IBaseFilter** ppFilter) {return E_NOTIMPL;}
  109. STDMETHODIMP CBaseGraph::ConnectDirect(IPin* ppinOut, IPin* ppinIn, const AM_MEDIA_TYPE* pmt) {return E_NOTIMPL;}
  110. STDMETHODIMP CBaseGraph::Reconnect(IPin* ppin) {return E_NOTIMPL;}
  111. STDMETHODIMP CBaseGraph::Disconnect(IPin* ppin) {return E_NOTIMPL;}
  112. STDMETHODIMP CBaseGraph::SetDefaultSyncSource() {return E_NOTIMPL;}
  113. // IGraphBuilder
  114. STDMETHODIMP CBaseGraph::Connect(IPin* ppinOut, IPin* ppinIn) {return E_NOTIMPL;}
  115. STDMETHODIMP CBaseGraph::Render(IPin* ppinOut) {return E_NOTIMPL;}
  116. STDMETHODIMP CBaseGraph::RenderFile(LPCWSTR lpcwstrFile, LPCWSTR lpcwstrPlayList) {return E_NOTIMPL;}
  117. STDMETHODIMP CBaseGraph::AddSourceFilter(LPCWSTR lpcwstrFileName, LPCWSTR lpcwstrFilterName, IBaseFilter** ppFilter) {*ppFilter = NULL; return RenderFile(lpcwstrFileName, NULL);}//E_NOTIMPL;}
  118. STDMETHODIMP CBaseGraph::SetLogFile(DWORD_PTR hFile) {return E_NOTIMPL;}
  119. STDMETHODIMP CBaseGraph::Abort() {return E_NOTIMPL;}
  120. STDMETHODIMP CBaseGraph::ShouldOperationContinue() {return E_NOTIMPL;}
  121. // IMediaControl
  122. STDMETHODIMP CBaseGraph::Run() {return E_NOTIMPL;}
  123. STDMETHODIMP CBaseGraph::Pause() {return E_NOTIMPL;}
  124. STDMETHODIMP CBaseGraph::Stop() {return E_NOTIMPL;}
  125. STDMETHODIMP CBaseGraph::GetState(LONG msTimeout, OAFilterState* pfs) {return E_NOTIMPL;}
  126. STDMETHODIMP CBaseGraph::RenderFile(BSTR strFilename) {return E_NOTIMPL;}
  127. STDMETHODIMP CBaseGraph::AddSourceFilter(BSTR strFilename, IDispatch** ppUnk) {return E_NOTIMPL;}
  128. STDMETHODIMP CBaseGraph::get_FilterCollection(IDispatch** ppUnk) {return E_NOTIMPL;}
  129. STDMETHODIMP CBaseGraph::get_RegFilterCollection(IDispatch** ppUnk) {return E_NOTIMPL;}
  130. STDMETHODIMP CBaseGraph::StopWhenReady() {return Stop();}
  131. // IMediaEvent
  132. STDMETHODIMP CBaseGraph::GetEventHandle(OAEVENT* hEvent) {return E_NOTIMPL;}
  133. STDMETHODIMP CBaseGraph::GetEvent(long* lEventCode, LONG_PTR* lParam1, LONG_PTR* lParam2, long msTimeout)
  134. {
  135. if(m_msgqueue.IsEmpty()) return E_FAIL;
  136. GMSG msg = m_msgqueue.RemoveHead();
  137. if(lEventCode) *lEventCode = msg.m_lEventCode;
  138. if(lParam1) *lParam1 = msg.m_lParam1;
  139. if(lParam2) *lParam2 = msg.m_lParam2;
  140. return S_OK;
  141. }
  142. STDMETHODIMP CBaseGraph::WaitForCompletion(long msTimeout, long* pEvCode) {return E_NOTIMPL;}
  143. STDMETHODIMP CBaseGraph::CancelDefaultHandling(long lEvCode) {return E_NOTIMPL;}
  144. STDMETHODIMP CBaseGraph::RestoreDefaultHandling(long lEvCode) {return E_NOTIMPL;}
  145. STDMETHODIMP CBaseGraph::FreeEventParams(long lEvCode, LONG_PTR lParam1, LONG_PTR lParam2)
  146. {
  147. if(EC_BG_ERROR == lEvCode)
  148. {
  149. if(lParam1) CoTaskMemFree((void*)lParam1);
  150. }
  151. return S_OK;
  152. }
  153. // IMediaEventEx
  154. STDMETHODIMP CBaseGraph::SetNotifyWindow(OAHWND hwnd, long lMsg, LONG_PTR lInstanceData)
  155. {
  156. m_hNotifyWnd = hwnd;
  157. m_lNotifyMsg = lMsg;
  158. m_lNotifyInstData = lInstanceData;
  159. if(!IsWindow((HWND)m_hNotifyWnd)) 
  160. {
  161. m_hNotifyWnd = NULL;
  162. return E_FAIL;
  163. }
  164. return S_OK;
  165. }
  166. STDMETHODIMP CBaseGraph::SetNotifyFlags(long lNoNotifyFlags) {return E_NOTIMPL;}
  167. STDMETHODIMP CBaseGraph::GetNotifyFlags(long* lplNoNotifyFlags) {return E_NOTIMPL;}
  168. // IMediaSeeking
  169. STDMETHODIMP CBaseGraph::GetCapabilities(DWORD* pCapabilities)
  170. {
  171. return pCapabilities ? *pCapabilities = AM_SEEKING_CanSeekAbsolute|AM_SEEKING_CanGetCurrentPos|AM_SEEKING_CanGetDuration, S_OK : E_POINTER;
  172. }
  173. STDMETHODIMP CBaseGraph::CheckCapabilities(DWORD* pCapabilities)
  174. {
  175. CheckPointer(pCapabilities, E_POINTER);
  176. if(*pCapabilities == 0) return S_OK;
  177. DWORD caps;
  178. GetCapabilities(&caps);
  179. DWORD caps2 = caps & *pCapabilities;
  180. return caps2 == 0 ? E_FAIL : caps2 == *pCapabilities ? S_OK : S_FALSE;
  181. }
  182. STDMETHODIMP CBaseGraph::IsFormatSupported(const GUID* pFormat)
  183. {
  184. return !pFormat ? E_POINTER : *pFormat == TIME_FORMAT_MEDIA_TIME ? S_OK : S_FALSE;
  185. }
  186. STDMETHODIMP CBaseGraph::QueryPreferredFormat(GUID* pFormat)
  187. {
  188. return GetTimeFormat(pFormat);
  189. }
  190. STDMETHODIMP CBaseGraph::GetTimeFormat(GUID* pFormat)
  191. {
  192. return pFormat ? *pFormat = TIME_FORMAT_MEDIA_TIME, S_OK : E_POINTER;
  193. }
  194. STDMETHODIMP CBaseGraph::IsUsingTimeFormat(const GUID* pFormat)
  195. {
  196. return IsFormatSupported(pFormat);
  197. }
  198. STDMETHODIMP CBaseGraph::SetTimeFormat(const GUID* pFormat)
  199. {
  200. return S_OK == IsFormatSupported(pFormat) ? S_OK : E_INVALIDARG;
  201. }
  202. STDMETHODIMP CBaseGraph::GetDuration(LONGLONG* pDuration) {return E_NOTIMPL;}
  203. STDMETHODIMP CBaseGraph::GetStopPosition(LONGLONG* pStop) {return E_NOTIMPL;}
  204. STDMETHODIMP CBaseGraph::GetCurrentPosition(LONGLONG* pCurrent) {return E_NOTIMPL;}
  205. STDMETHODIMP CBaseGraph::ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat) {return E_NOTIMPL;}
  206. STDMETHODIMP CBaseGraph::SetPositions(LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags) {return E_NOTIMPL;}
  207. STDMETHODIMP CBaseGraph::GetPositions(LONGLONG* pCurrent, LONGLONG* pStop) {return E_NOTIMPL;}
  208. STDMETHODIMP CBaseGraph::GetAvailable(LONGLONG* pEarliest, LONGLONG* pLatest) {return E_NOTIMPL;}
  209. STDMETHODIMP CBaseGraph::SetRate(double dRate) {return E_NOTIMPL;}
  210. STDMETHODIMP CBaseGraph::GetRate(double* pdRate) {return E_NOTIMPL;}
  211. STDMETHODIMP CBaseGraph::GetPreroll(LONGLONG* pllPreroll) {return E_NOTIMPL;}
  212. // IVideoWindow
  213. STDMETHODIMP CBaseGraph::put_Caption(BSTR strCaption) {return E_NOTIMPL;}    
  214. STDMETHODIMP CBaseGraph::get_Caption(BSTR* strCaption) {return E_NOTIMPL;}
  215. STDMETHODIMP CBaseGraph::put_WindowStyle(long WindowStyle) {return E_NOTIMPL;}
  216. STDMETHODIMP CBaseGraph::get_WindowStyle(long* WindowStyle) {return E_NOTIMPL;}
  217. STDMETHODIMP CBaseGraph::put_WindowStyleEx(long WindowStyleEx) {return E_NOTIMPL;}
  218. STDMETHODIMP CBaseGraph::get_WindowStyleEx(long* WindowStyleEx) {return E_NOTIMPL;}
  219. STDMETHODIMP CBaseGraph::put_AutoShow(long AutoShow) {return E_NOTIMPL;}
  220. STDMETHODIMP CBaseGraph::get_AutoShow(long* AutoShow) {return E_NOTIMPL;}
  221. STDMETHODIMP CBaseGraph::put_WindowState(long WindowState) {return E_NOTIMPL;}
  222. STDMETHODIMP CBaseGraph::get_WindowState(long* WindowState) {return E_NOTIMPL;}
  223. STDMETHODIMP CBaseGraph::put_BackgroundPalette(long BackgroundPalette) {return E_NOTIMPL;}
  224. STDMETHODIMP CBaseGraph::get_BackgroundPalette(long* pBackgroundPalette) {return E_NOTIMPL;}
  225. STDMETHODIMP CBaseGraph::put_Visible(long Visible) {return E_NOTIMPL;}
  226. STDMETHODIMP CBaseGraph::get_Visible(long* pVisible) {return E_NOTIMPL;}
  227. STDMETHODIMP CBaseGraph::put_Left(long Left) {return E_NOTIMPL;}
  228. STDMETHODIMP CBaseGraph::get_Left(long* pLeft) {return E_NOTIMPL;}
  229. STDMETHODIMP CBaseGraph::put_Width(long Width) {return E_NOTIMPL;}
  230. STDMETHODIMP CBaseGraph::get_Width(long* pWidth) {return E_NOTIMPL;}
  231. STDMETHODIMP CBaseGraph::put_Top(long Top) {return E_NOTIMPL;}
  232. STDMETHODIMP CBaseGraph::get_Top(long* pTop) {return E_NOTIMPL;}
  233. STDMETHODIMP CBaseGraph::put_Height(long Height) {return E_NOTIMPL;}
  234. STDMETHODIMP CBaseGraph::get_Height(long* pHeight) {return E_NOTIMPL;}
  235. STDMETHODIMP CBaseGraph::put_Owner(OAHWND Owner) {return E_NOTIMPL;}
  236. STDMETHODIMP CBaseGraph::get_Owner(OAHWND* Owner) {return E_NOTIMPL;}
  237. STDMETHODIMP CBaseGraph::put_MessageDrain(OAHWND Drain) {return E_NOTIMPL;}
  238. STDMETHODIMP CBaseGraph::get_MessageDrain(OAHWND* Drain) {return E_NOTIMPL;}
  239. STDMETHODIMP CBaseGraph::get_BorderColor(long* Color) {return E_NOTIMPL;}
  240. STDMETHODIMP CBaseGraph::put_BorderColor(long Color) {return E_NOTIMPL;}
  241. STDMETHODIMP CBaseGraph::get_FullScreenMode(long* FullScreenMode) {return E_NOTIMPL;}
  242. STDMETHODIMP CBaseGraph::put_FullScreenMode(long FullScreenMode) {return E_NOTIMPL;}
  243. STDMETHODIMP CBaseGraph::SetWindowForeground(long Focus) {return E_NOTIMPL;}
  244. STDMETHODIMP CBaseGraph::NotifyOwnerMessage(OAHWND hwnd, long uMsg, LONG_PTR wParam, LONG_PTR lParam) {return E_NOTIMPL;}
  245. STDMETHODIMP CBaseGraph::SetWindowPosition(long Left, long Top, long Width, long Height) {return E_NOTIMPL;}
  246. STDMETHODIMP CBaseGraph::GetWindowPosition(long* pLeft, long* pTop, long* pWidth, long* pHeight) {return E_NOTIMPL;}
  247. STDMETHODIMP CBaseGraph::GetMinIdealImageSize(long* pWidth, long* pHeight) {return E_NOTIMPL;}
  248. STDMETHODIMP CBaseGraph::GetMaxIdealImageSize(long* pWidth, long* pHeight) {return E_NOTIMPL;}
  249. STDMETHODIMP CBaseGraph::GetRestorePosition(long* pLeft, long* pTop, long* pWidth, long* pHeight) {return E_NOTIMPL;}
  250. STDMETHODIMP CBaseGraph::HideCursor(long HideCursor) {return E_NOTIMPL;}
  251. STDMETHODIMP CBaseGraph::IsCursorHidden(long* CursorHidden) {return E_NOTIMPL;}
  252. // IBasicVideo
  253. STDMETHODIMP CBaseGraph::get_AvgTimePerFrame(REFTIME* pAvgTimePerFrame) {return E_NOTIMPL;}
  254. STDMETHODIMP CBaseGraph::get_BitRate(long* pBitRate) {return E_NOTIMPL;}
  255. STDMETHODIMP CBaseGraph::get_BitErrorRate(long* pBitErrorRate) {return E_NOTIMPL;}
  256. STDMETHODIMP CBaseGraph::get_VideoWidth(long* pVideoWidth) {return E_NOTIMPL;}
  257. STDMETHODIMP CBaseGraph::get_VideoHeight(long* pVideoHeight) {return E_NOTIMPL;}
  258. STDMETHODIMP CBaseGraph::put_SourceLeft(long SourceLeft) {return E_NOTIMPL;}
  259. STDMETHODIMP CBaseGraph::get_SourceLeft(long* pSourceLeft) {return E_NOTIMPL;}
  260. STDMETHODIMP CBaseGraph::put_SourceWidth(long SourceWidth) {return E_NOTIMPL;}
  261. STDMETHODIMP CBaseGraph::get_SourceWidth(long* pSourceWidth) {return E_NOTIMPL;}
  262. STDMETHODIMP CBaseGraph::put_SourceTop(long SourceTop) {return E_NOTIMPL;}
  263. STDMETHODIMP CBaseGraph::get_SourceTop(long* pSourceTop) {return E_NOTIMPL;}
  264. STDMETHODIMP CBaseGraph::put_SourceHeight(long SourceHeight) {return E_NOTIMPL;}
  265. STDMETHODIMP CBaseGraph::get_SourceHeight(long* pSourceHeight) {return E_NOTIMPL;}
  266. STDMETHODIMP CBaseGraph::put_DestinationLeft(long DestinationLeft) {return E_NOTIMPL;}
  267. STDMETHODIMP CBaseGraph::get_DestinationLeft(long* pDestinationLeft) {return E_NOTIMPL;}
  268. STDMETHODIMP CBaseGraph::put_DestinationWidth(long DestinationWidth) {return E_NOTIMPL;}
  269. STDMETHODIMP CBaseGraph::get_DestinationWidth(long* pDestinationWidth) {return E_NOTIMPL;}
  270. STDMETHODIMP CBaseGraph::put_DestinationTop(long DestinationTop) {return E_NOTIMPL;}
  271. STDMETHODIMP CBaseGraph::get_DestinationTop(long* pDestinationTop) {return E_NOTIMPL;}
  272. STDMETHODIMP CBaseGraph::put_DestinationHeight(long DestinationHeight) {return E_NOTIMPL;}
  273. STDMETHODIMP CBaseGraph::get_DestinationHeight(long* pDestinationHeight) {return E_NOTIMPL;}
  274. STDMETHODIMP CBaseGraph::SetSourcePosition(long Left, long Top, long Width, long Height) {return E_NOTIMPL;}
  275. STDMETHODIMP CBaseGraph::GetSourcePosition(long* pLeft, long* pTop, long* pWidth, long* pHeight) {return E_NOTIMPL;}
  276. STDMETHODIMP CBaseGraph::SetDefaultSourcePosition() {return E_NOTIMPL;}
  277. STDMETHODIMP CBaseGraph::SetDestinationPosition(long Left, long Top, long Width, long Height) {return E_NOTIMPL;}
  278. STDMETHODIMP CBaseGraph::GetDestinationPosition(long* pLeft, long* pTop, long* pWidth, long* pHeight) {return E_NOTIMPL;}
  279. STDMETHODIMP CBaseGraph::SetDefaultDestinationPosition() {return E_NOTIMPL;}
  280. STDMETHODIMP CBaseGraph::GetVideoSize(long* pWidth, long* pHeight) {return E_NOTIMPL;}
  281. STDMETHODIMP CBaseGraph::GetVideoPaletteEntries(long StartIndex, long Entries, long* pRetrieved, long* pPalette) {return E_NOTIMPL;}
  282. STDMETHODIMP CBaseGraph::GetCurrentImage(long* pBufferSize, long* pDIBImage) {return E_NOTIMPL;}
  283. STDMETHODIMP CBaseGraph::IsUsingDefaultSource() {return E_NOTIMPL;}
  284. STDMETHODIMP CBaseGraph::IsUsingDefaultDestination() {return E_NOTIMPL;}
  285. // IBasicAudio
  286. STDMETHODIMP CBaseGraph::put_Volume(long lVolume) {return E_NOTIMPL;}
  287. STDMETHODIMP CBaseGraph::get_Volume(long* plVolume) {return E_NOTIMPL;}
  288. STDMETHODIMP CBaseGraph::put_Balance(long lBalance) {return E_NOTIMPL;}
  289. STDMETHODIMP CBaseGraph::get_Balance(long* plBalance) {return E_NOTIMPL;}
  290. // IAMOpenProgress
  291. STDMETHODIMP CBaseGraph::QueryProgress(LONGLONG* pllTotal, LONGLONG* pllCurrent) {return E_NOTIMPL;}
  292. STDMETHODIMP CBaseGraph::AbortOperation() {return E_NOTIMPL;}
  293. // IGraphEngine
  294. STDMETHODIMP_(engine_t) CBaseGraph::GetEngine() {return DirectShow;}