Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

9983 lines
291 KiB

  1. /*************************************************************************/
  2. /* Copyright (C) 1999 Microsoft Corporation */
  3. /* File: msdvd.cpp */
  4. /* Description: Implementation of CMSWebDVD. */
  5. /* Author: David Janecek */
  6. /*************************************************************************/
  7. #include "stdafx.h"
  8. #include "MSDVD.h"
  9. #include "resource.h"
  10. #include <mpconfig.h>
  11. #include <il21dec.h> // line 21 decoder
  12. #include <commctrl.h>
  13. #include "ThunkProc.h"
  14. #include "ddrawobj.h"
  15. #include "stdio.h"
  16. /*************************************************************************/
  17. /* Local constants and defines */
  18. /*************************************************************************/
  19. const DWORD cdwDVDCtrlFlags = DVD_CMD_FLAG_Block| DVD_CMD_FLAG_Flush;
  20. const DWORD cdwMaxFP_DOMWait = 30000; // 30sec for FP_DOM passing should be OK
  21. const LONG cgStateTimeout = 0; // wait till the state transition occurs
  22. // modify if needed
  23. const LONG cgDVD_MIN_SUBPICTURE = 0;
  24. const LONG cgDVD_MAX_SUBPICTURE = 31;
  25. const LONG cgDVD_ALT_SUBPICTURE = 63;
  26. const LONG cgDVD_MIN_ANGLE = 0;
  27. const LONG cgDVD_MAX_ANGLE = 9;
  28. const double cgdNormalSpeed = 1.00;
  29. const LONG cgDVDMAX_TITLE_COUNT = 99;
  30. const LONG cgDVDMIN_TITLE_COUNT = 1;
  31. const LONG cgDVDMAX_CHAPTER_COUNT = 999;
  32. const LONG cgDVDMIN_CHAPTER_COUNT = 1;
  33. const LONG cgTIME_STRING_LEN = 2;
  34. const LONG cgMAX_DELIMITER_LEN = 4;
  35. const LONG cgDVD_TIME_STR_LEN = (3*cgMAX_DELIMITER_LEN)+(4*cgTIME_STRING_LEN) + 1 /*NULL Terminator*/;
  36. const LONG cgVOLUME_MAX = 0;
  37. const LONG cgVOLUME_MIN = -10000;
  38. const LONG cgBALANCE_MIN = -10000;
  39. const LONG cgBALANCE_MAX = 10000;
  40. const WORD cgWAVE_VOLUME_MIN = 0;
  41. const WORD cgWAVE_VOLUME_MAX = 0xffff;
  42. const DWORD cdwTimeout = 10; //100
  43. const LONG cgnStepTimeout = 100;
  44. #define EC_DVD_PLAYING (EC_DVDBASE + 0xFE)
  45. #define EC_DVD_PAUSED (EC_DVDBASE + 0xFF)
  46. #define E_NO_IDVD2_PRESENT MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0xFF0)
  47. #define E_REGION_CHANGE_FAIL MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0xFF1)
  48. #define E_NO_DVD_VOLUME MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0xFF3)
  49. #define E_REGION_CHANGE_NOT_COMPLETED MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0xFF4)
  50. #define E_NO_SOUND_STREAM MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0xFF5)
  51. #define E_NO_VIDEO_STREAM MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0xFF6)
  52. #define E_NO_OVERLAY MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0xFF7)
  53. #define E_NO_USABLE_OVERLAY MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0xFF8)
  54. #define E_NO_DECODER MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0xFF9)
  55. #define E_NO_CAPTURE_SUPPORT MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0xFFA)
  56. #define DVD_ERROR_NoSubpictureStream 99
  57. #if WINVER < 0x0500
  58. typedef struct tagCURSORINFO
  59. {
  60. DWORD cbSize;
  61. DWORD flags;
  62. HCURSOR hCursor;
  63. POINT ptScreenPos;
  64. } CURSORINFO, *PCURSORINFO, *LPCURSORINFO;
  65. #define CURSOR_SHOWING 0x00000001
  66. static BOOL (WINAPI *pfnGetCursorInfo)(PCURSORINFO);
  67. typedef BOOL (WINAPI *PFNGETCURSORINFOHANDLE)(PCURSORINFO);
  68. HRESULT CallGetCursorInfo(PCURSORINFO pci)
  69. {
  70. HRESULT hr = E_FAIL;
  71. HINSTANCE hinstDll = ::LoadLibrary(TEXT("USER32.DLL"));
  72. if (hinstDll)
  73. {
  74. pfnGetCursorInfo = (PFNGETCURSORINFOHANDLE)GetProcAddress(hinstDll, "GetCursorInfo");
  75. if (pfnGetCursorInfo)
  76. {
  77. hr = pfnGetCursorInfo(pci);
  78. }
  79. FreeLibrary(hinstDll);
  80. }
  81. return hr;
  82. }
  83. #endif
  84. GUID IID_IAMSpecifyDDrawConnectionDevice = {
  85. 0xc5265dba,0x3de3,0x4919,{0x94,0x0b,0x5a,0xc6,0x61,0xc8,0x2e,0xf4}};
  86. extern CComModule _Module;
  87. /*************************************************************************/
  88. /* Global Helper Functions */
  89. /*************************************************************************/
  90. // helper function for converting a captured YUV image to RGB
  91. // and saving to file.
  92. extern HRESULT GDIConvertImageAndSave(YUV_IMAGE *lpImage, RECT *prc, HWND hwnd);
  93. extern HRESULT ConvertImageAndSave(YUV_IMAGE *lpImage, RECT *prc, HWND hwnd);
  94. // Helper function to calcuate max common denominator
  95. long MCD(long i, long j) {
  96. if (i == j)
  97. return i;
  98. else if (i>j) {
  99. if (i%j == 0)
  100. return j;
  101. else
  102. return MCD(i%j, j);
  103. }
  104. else {
  105. if (j%i == 0)
  106. return i;
  107. else
  108. return MCD(j%i, i);
  109. }
  110. }
  111. /////////////////////////////////////////////////////////////////////////////
  112. // CMSWebDVD
  113. /*************************************************************************/
  114. /* General initialization methods */
  115. /*************************************************************************/
  116. /*************************************************************************/
  117. /* Function: CMSWebDVD */
  118. /*************************************************************************/
  119. CMSWebDVD::CMSWebDVD(){
  120. Init();
  121. }/* end of function CMSWebDVD */
  122. /*************************************************************************/
  123. /* Function: ~CMSWebDVD */
  124. /*************************************************************************/
  125. CMSWebDVD::~CMSWebDVD(){
  126. // if we haven't been rendered or already been cleaned up
  127. if (!m_fInitialized){
  128. return;
  129. }/* end of if statement */
  130. Stop();
  131. Cleanup();
  132. Init();
  133. ATLTRACE(TEXT("Inside the MSWEBDVD DESTRUCTOR!!\n"));
  134. }/* end of function ~CMSWebDVD */
  135. /*************************************************************************/
  136. /* Function: Init */
  137. /*************************************************************************/
  138. VOID CMSWebDVD::Init(){
  139. #if 1 // switch this to have the windowless case to be the deafult handling case
  140. m_bWindowOnly = TRUE; // turn on and off window only implementation
  141. m_fUseDDrawDirect = false;
  142. #else
  143. m_bWindowOnly = FALSE;
  144. m_fUseDDrawDirect = true;
  145. #endif
  146. m_lChapter = m_lTitle = 1;
  147. m_lChapterCount = NO_STOP;
  148. m_clrColorKey = UNDEFINED_COLORKEY_COLOR;
  149. m_nReadyState = READYSTATE_LOADING;
  150. m_bMute = FALSE;
  151. m_lLastVolume = 0;
  152. m_fEnableResetOnStop = FALSE; // TRUE
  153. m_clrBackColor = DEFAULT_BACK_COLOR; // off black used as a default key value to avoid flashing
  154. #if 1
  155. m_nTTMaxWidth = 200;
  156. m_hWndTip = NULL;
  157. m_bTTCreated = FALSE;
  158. #endif
  159. m_fInitialized = false;
  160. m_hFPDOMEvent = NULL;
  161. m_fDisableAutoMouseProcessing = false;
  162. m_bEjected = false;
  163. m_fStillOn = false;
  164. m_nCursorType = dvdCursor_Arrow;
  165. m_pClipRect = NULL;
  166. m_bMouseDown = FALSE;
  167. m_hCursor = ::LoadCursor(NULL, MAKEINTRESOURCE(OCR_ARROW_DEFAULT));
  168. m_dZoomRatio = 1;
  169. m_hWndOuter = NULL;
  170. ::ZeroMemory(&m_rcOldPos, sizeof(RECT));
  171. m_hTimerId = NULL;
  172. m_fResetSpeed = true;
  173. m_DVDFilterState = dvdState_Undefined;
  174. m_lKaraokeAudioPresentationMode = 0;
  175. m_dwTTInitalDelay = 10;
  176. m_dwTTReshowDelay = 2;
  177. m_dwTTAutopopDelay = 10000;
  178. m_pDDrawDVD = NULL;
  179. m_dwNumDevices = 0;
  180. m_lpInfo = NULL;
  181. m_lpCurMonitor = NULL;
  182. m_MonitorWarn = FALSE;
  183. ::ZeroMemory(&m_ClipRectDown, sizeof(RECT));
  184. m_fStepComplete = false;
  185. m_bFireUpdateOverlay = FALSE;
  186. m_dwAspectX = 1;
  187. m_dwAspectY = 1;
  188. m_dwVideoWidth = 1;
  189. m_dwVideoHeight =1;
  190. // default overlay stretch factor x1000
  191. m_dwOvMaxStretch = 32000;
  192. m_bFireNoSubpictureStream = FALSE;
  193. // flags for caching decoder flags
  194. m_fBackWardsFlagInitialized = false;
  195. m_fCanStepBackwards = false;
  196. }/* end of function Init */
  197. /*************************************************************************/
  198. /* Function: Cleanup */
  199. /* Description: Releases all the interfaces. */
  200. /*************************************************************************/
  201. VOID CMSWebDVD::Cleanup(){
  202. m_mediaHandler.Close();
  203. if (m_pME){
  204. m_pME->SetNotifyWindow(NULL, WM_DVDPLAY_EVENT, 0) ;
  205. m_pME.Release() ;
  206. }/* end of if statement */
  207. if(NULL != m_hTimerId){
  208. ::KillTimer(NULL, m_hTimerId);
  209. }/* end of if statement */
  210. if(NULL != m_hFPDOMEvent){
  211. ::CloseHandle(m_hFPDOMEvent);
  212. m_hFPDOMEvent = NULL;
  213. }/* end of if statement */
  214. m_pAudio.Release();
  215. m_pMediaSink.Release();
  216. m_pDvdInfo2.Release();
  217. m_pDvdCtl2.Release();
  218. m_pMC.Release();
  219. m_pVideoFrameStep.Release();
  220. m_pGB.Release();
  221. m_pDvdGB.Release();
  222. m_pDDEX.Release();
  223. m_pDvdAdmin.Release();
  224. if (m_hCursor != NULL) {
  225. ::DestroyCursor(m_hCursor);
  226. }/* end of if statement */
  227. if(NULL != m_pDDrawDVD){
  228. delete m_pDDrawDVD;
  229. m_pDDrawDVD = NULL;
  230. }/* end of if statement */
  231. if(NULL != m_lpInfo){
  232. ::CoTaskMemFree(m_lpInfo);
  233. m_lpInfo = NULL;
  234. }/* end of if statement */
  235. ::ZeroMemory(&m_rcOldPos, sizeof(RECT));
  236. }/* end of function Cleanup */
  237. /*************************************************************************/
  238. /* "ActiveX" methods needed to support our interfaces */
  239. /*************************************************************************/
  240. /*************************************************************************/
  241. /* Function: OnDraw */
  242. /* Description: Just Draws the rectangular background. */
  243. /*************************************************************************/
  244. HRESULT CMSWebDVD::OnDraw(ATL_DRAWINFO& di){
  245. try {
  246. if(!m_bWndLess && m_fInitialized){
  247. // have to draw background only if in windowless mode or if we are not rendered yet
  248. // Get the active movie window
  249. HWND hwnd = ::GetWindow(m_hWnd, GW_CHILD);
  250. if (!::IsWindow(hwnd)){
  251. return S_OK;
  252. }/* end of if statement */
  253. if(::IsWindowVisible(hwnd)){
  254. return S_OK;
  255. }/* end of if statement */
  256. }/* end of if statement */
  257. HDC hdc = di.hdcDraw;
  258. // Not used for now
  259. // bool fHandled = true;
  260. // Paint backcolor first
  261. COLORREF clr;
  262. ::OleTranslateColor(m_clrBackColor, NULL, &clr);
  263. RECT rcClient = *(RECT*)di.prcBounds;
  264. HBRUSH hbrush = ::CreateSolidBrush(clr);
  265. if(NULL != hbrush){
  266. HBRUSH oldBrush = (HBRUSH)::SelectObject(hdc, hbrush);
  267. ::Rectangle(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
  268. //ATLTRACE(TEXT("BackColor, %d %d %d %d\n"), rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
  269. ::SelectObject(hdc, oldBrush);
  270. ::DeleteObject(hbrush);
  271. hbrush = NULL;
  272. }/* end of if statement */
  273. // Paint color key in the video area
  274. if(NULL == m_pDDrawDVD){
  275. return(S_OK);
  276. }/* end of if statement */
  277. if(SUCCEEDED(AdjustDestRC())){
  278. RECT rcVideo = m_rcPosAspectRatioAjusted;
  279. rcVideo.left = rcClient.left+(RECTWIDTH(&rcClient)-RECTWIDTH(&rcVideo))/2;
  280. rcVideo.top = rcClient.top+(RECTHEIGHT(&rcClient)-RECTHEIGHT(&rcVideo))/2;
  281. rcVideo.right = rcVideo.left + RECTWIDTH(&rcVideo);
  282. rcVideo.bottom = rcVideo.top + RECTHEIGHT(&rcVideo);
  283. m_clrColorKey = m_pDDrawDVD->GetColorKey();
  284. #if 1
  285. hbrush = ::CreateSolidBrush(::GetNearestColor(hdc, m_clrColorKey));
  286. #else
  287. m_pDDrawDVD->CreateDIBBrush(m_clrColorKey, &hbrush);
  288. #endif
  289. if(NULL != hbrush){
  290. HBRUSH oldBrush = (HBRUSH)::SelectObject(hdc, hbrush);
  291. ::Rectangle(hdc, rcVideo.left, rcVideo.top, rcVideo.right, rcVideo.bottom);
  292. //ATLTRACE(TEXT("ColorKey, %d %d %d %d\n"), rcVideo.left, rcVideo.top, rcVideo.right, rcVideo.bottom);
  293. ::SelectObject(hdc, oldBrush);
  294. ::DeleteObject(hbrush);
  295. hbrush = NULL;
  296. }/* end of if statement */
  297. }/* end of if statement */
  298. // in case we have a multimon we need to draw our warning
  299. HandleMultiMonPaint(hdc);
  300. }/* end of try statement statement */
  301. catch(...){
  302. return(0);
  303. }/* end of catch statement */
  304. return(1);
  305. }/* end of function OnDraw */
  306. #ifdef _WMP
  307. /*************************************************************************/
  308. /* Function: InPlaceActivate */
  309. /* Description: Modified InPlaceActivate so WMP can startup. */
  310. /*************************************************************************/
  311. HRESULT CMSWebDVD::InPlaceActivate(LONG iVerb, const RECT* /*prcPosRect*/){
  312. HRESULT hr;
  313. if (m_spClientSite == NULL)
  314. return S_OK;
  315. CComPtr<IOleInPlaceObject> pIPO;
  316. ControlQueryInterface(IID_IOleInPlaceObject, (void**)&pIPO);
  317. ATLASSERT(pIPO != NULL);
  318. if (!m_bNegotiatedWnd)
  319. {
  320. if (!m_bWindowOnly)
  321. // Try for windowless site
  322. hr = m_spClientSite->QueryInterface(IID_IOleInPlaceSiteWindowless, (void **)&m_spInPlaceSite);
  323. if (m_spInPlaceSite)
  324. {
  325. m_bInPlaceSiteEx = TRUE;
  326. // CanWindowlessActivate returns S_OK or S_FALSE
  327. if ( m_spInPlaceSite->CanWindowlessActivate() == S_OK )
  328. {
  329. m_bWndLess = TRUE;
  330. m_bWasOnceWindowless = TRUE;
  331. }
  332. else
  333. {
  334. m_bWndLess = FALSE;
  335. }
  336. }
  337. else
  338. {
  339. m_spClientSite->QueryInterface(IID_IOleInPlaceSiteEx, (void **)&m_spInPlaceSite);
  340. if (m_spInPlaceSite)
  341. m_bInPlaceSiteEx = TRUE;
  342. else
  343. hr = m_spClientSite->QueryInterface(IID_IOleInPlaceSite, (void **)&m_spInPlaceSite);
  344. }
  345. }
  346. ATLASSERT(m_spInPlaceSite);
  347. if (!m_spInPlaceSite)
  348. return E_FAIL;
  349. m_bNegotiatedWnd = TRUE;
  350. if (!m_bInPlaceActive)
  351. {
  352. BOOL bNoRedraw = FALSE;
  353. if (m_bWndLess)
  354. m_spInPlaceSite->OnInPlaceActivateEx(&bNoRedraw, ACTIVATE_WINDOWLESS);
  355. else
  356. {
  357. if (m_bInPlaceSiteEx)
  358. m_spInPlaceSite->OnInPlaceActivateEx(&bNoRedraw, 0);
  359. else
  360. {
  361. hr = m_spInPlaceSite->CanInPlaceActivate();
  362. // CanInPlaceActivate returns S_FALSE or S_OK
  363. if (FAILED(hr))
  364. return hr;
  365. if ( hr != S_OK )
  366. {
  367. // CanInPlaceActivate returned S_FALSE.
  368. return( E_FAIL );
  369. }
  370. m_spInPlaceSite->OnInPlaceActivate();
  371. }
  372. }
  373. }
  374. m_bInPlaceActive = TRUE;
  375. // get location in the parent window,
  376. // as well as some information about the parent
  377. //
  378. OLEINPLACEFRAMEINFO frameInfo;
  379. RECT rcPos, rcClip;
  380. CComPtr<IOleInPlaceFrame> spInPlaceFrame;
  381. CComPtr<IOleInPlaceUIWindow> spInPlaceUIWindow;
  382. frameInfo.cb = sizeof(OLEINPLACEFRAMEINFO);
  383. HWND hwndParent;
  384. // DJ - GetParentHWND per MNnovak
  385. if (SUCCEEDED( GetParentHWND(&hwndParent) ))
  386. {
  387. m_spInPlaceSite->GetWindowContext(&spInPlaceFrame,
  388. &spInPlaceUIWindow, &rcPos, &rcClip, &frameInfo);
  389. if (!m_bWndLess)
  390. {
  391. if (m_hWndCD)
  392. {
  393. ::ShowWindow(m_hWndCD, SW_SHOW);
  394. if (!::IsChild(m_hWndCD, ::GetFocus()))
  395. ::SetFocus(m_hWndCD);
  396. }
  397. else
  398. {
  399. HWND h = CreateControlWindow(hwndParent, rcPos);
  400. ATLASSERT(h != NULL); // will assert if creation failed
  401. ATLASSERT(h == m_hWndCD);
  402. h; // avoid unused warning
  403. }
  404. }
  405. pIPO->SetObjectRects(&rcPos, &rcClip);
  406. }
  407. CComPtr<IOleInPlaceActiveObject> spActiveObject;
  408. ControlQueryInterface(IID_IOleInPlaceActiveObject, (void**)&spActiveObject);
  409. // Gone active by now, take care of UIACTIVATE
  410. if (DoesVerbUIActivate(iVerb))
  411. {
  412. if (!m_bUIActive)
  413. {
  414. m_bUIActive = TRUE;
  415. hr = m_spInPlaceSite->OnUIActivate();
  416. if (FAILED(hr))
  417. return hr;
  418. SetControlFocus(TRUE);
  419. // set ourselves up in the host.
  420. //
  421. if (spActiveObject)
  422. {
  423. if (spInPlaceFrame)
  424. spInPlaceFrame->SetActiveObject(spActiveObject, NULL);
  425. if (spInPlaceUIWindow)
  426. spInPlaceUIWindow->SetActiveObject(spActiveObject, NULL);
  427. }
  428. if (spInPlaceFrame)
  429. spInPlaceFrame->SetBorderSpace(NULL);
  430. if (spInPlaceUIWindow)
  431. spInPlaceUIWindow->SetBorderSpace(NULL);
  432. }
  433. }
  434. m_spClientSite->ShowObject();
  435. return S_OK;
  436. }/* end of function InPlaceActivate */
  437. #endif
  438. /*************************************************************************/
  439. /* Function: InterfaceSupportsErrorInfo */
  440. /*************************************************************************/
  441. STDMETHODIMP CMSWebDVD::InterfaceSupportsErrorInfo(REFIID riid){
  442. static const IID* arr[] = {
  443. &IID_IMSWebDVD,
  444. };
  445. for (int i=0; i<sizeof(arr)/sizeof(arr[0]); i++){
  446. if (InlineIsEqualGUID(*arr[i], riid))
  447. return S_OK;
  448. }/* end of for loop */
  449. return S_FALSE;
  450. }/* end of function InterfaceSupportsErrorInfo */
  451. /*************************************************************************/
  452. /* Function: OnSize */
  453. /*************************************************************************/
  454. LRESULT CMSWebDVD::OnSize(UINT uMsg, WPARAM /* wParam */,
  455. LPARAM lParam, BOOL& bHandled){
  456. #ifdef _DEBUG
  457. if (WM_SIZING == uMsg) {
  458. //ATLTRACE(TEXT("WM_SIZING\n"));
  459. }
  460. #endif
  461. if(m_pDvdGB == NULL){
  462. return(0);
  463. }/* end of if statement */
  464. if (m_bWndLess || m_fUseDDrawDirect){
  465. OnResize();
  466. }
  467. else {
  468. IVideoWindow* pVW;
  469. HRESULT hr = m_pDvdGB->GetDvdInterface(IID_IVideoWindow, (LPVOID *)&pVW) ;
  470. if (SUCCEEDED(hr)){
  471. LONG nWidth = LOWORD(lParam); // width of client area
  472. LONG nHeight = HIWORD(lParam); // height of client area
  473. hr = pVW->SetWindowPosition(0, 0, nWidth, nHeight);
  474. pVW->Release();
  475. }/* end of if statement */
  476. }/* end of if statement */
  477. bHandled = TRUE;
  478. return(0);
  479. }/* end of function OnSize */
  480. /*************************************************************************/
  481. /* Function: OnResize */
  482. /* Description: Handles the resizing and moving in windowless case. */
  483. /*************************************************************************/
  484. HRESULT CMSWebDVD::OnResize(){
  485. HRESULT hr = S_FALSE;
  486. if (m_bWndLess || m_fUseDDrawDirect){
  487. RECT rc;
  488. hr = GetClientRectInScreen(&rc);
  489. if(FAILED(hr)){
  490. return(hr);
  491. }/* end of if statement */
  492. if(m_pDDEX){
  493. hr = m_pDDEX->SetDrawParameters(m_pClipRect, &rc);
  494. //ATLTRACE(TEXT("SetDrawParameters\n"));
  495. }/* end of if statement */
  496. HandleMultiMonMove();
  497. }/* end of if statement */
  498. return(hr);
  499. }/* end of function OnResize */
  500. /*************************************************************************/
  501. /* Function: OnErase */
  502. /* Description: Skip the erasing to avoid flickers. */
  503. /*************************************************************************/
  504. LRESULT CMSWebDVD::OnErase(UINT, WPARAM wParam, LPARAM lParam, BOOL& bHandled){
  505. bHandled = TRUE;
  506. return 1;
  507. }/* end of function OnErase */
  508. /*************************************************************************/
  509. /* Function: OnCreate */
  510. /* Description: Sets our state to complete so we can proceed in */
  511. /* in initialization. */
  512. /*************************************************************************/
  513. LRESULT CMSWebDVD::OnCreate(UINT /* uMsg */, WPARAM /* wParam */,
  514. LPARAM lParam, BOOL& bHandled){
  515. return(0);
  516. }/* end of function OnCreate */
  517. /*************************************************************************/
  518. /* Function: OnDestroy */
  519. /* Description: Sets our state to complete so we can proceed in */
  520. /* in initialization. */
  521. /*************************************************************************/
  522. LRESULT CMSWebDVD::OnDestroy(UINT /* uMsg */, WPARAM /* wParam */,
  523. LPARAM lParam, BOOL& bHandled){
  524. // if we haven't been rendered
  525. if (!m_fInitialized){
  526. return 0;
  527. }/* end of if statement */
  528. Stop();
  529. Cleanup();
  530. Init();
  531. return(0);
  532. }/* end of function OnCreate */
  533. /*************************************************************************/
  534. /* Function: GetInterfaceSafetyOptions */
  535. /* Description: For support of security model in IE */
  536. /* This control is safe since it does not write to HD. */
  537. /*************************************************************************/
  538. STDMETHODIMP CMSWebDVD::GetInterfaceSafetyOptions(REFIID riid,
  539. DWORD* pdwSupportedOptions,
  540. DWORD* pdwEnabledOptions){
  541. HRESULT hr = S_OK;
  542. *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA;
  543. *pdwEnabledOptions = *pdwSupportedOptions;
  544. return(hr);
  545. }/* end of function GetInterfaceSafetyOptions */
  546. /*************************************************************************/
  547. /* Function: SetInterfaceSafetyOptions */
  548. /* Description: For support of security model in IE */
  549. /*************************************************************************/
  550. STDMETHODIMP CMSWebDVD::SetInterfaceSafetyOptions(REFIID riid,
  551. DWORD /* dwSupportedOptions */,
  552. DWORD /* pdwEnabledOptions */){
  553. return (S_OK);
  554. }/* end of function SetInterfaceSafetyOptions */
  555. /*************************************************************************/
  556. /* Function: SetObjectRects */
  557. /*************************************************************************/
  558. STDMETHODIMP CMSWebDVD::SetObjectRects(LPCRECT prcPos,LPCRECT prcClip){
  559. #if 0
  560. ATLTRACE(TEXT("Resizing control prcPos->left = %d, prcPos.right = %d, prcPos.bottom =%d, prcPos.top = %d\n"),
  561. prcPos->left, prcPos->right, prcPos->bottom, prcPos->top);
  562. ATLTRACE(TEXT("Resizing control Clip prcClip->left = %d, prcClip.right = %d, prcClip.bottom =%d, prcClip.top = %d\n"),
  563. prcClip->left, prcClip->right, prcClip->bottom, prcClip->top);
  564. #endif
  565. HRESULT hr = IOleInPlaceObjectWindowlessImpl<CMSWebDVD>::SetObjectRects(prcPos,prcClip);
  566. if(FAILED(hr)){
  567. return(hr);
  568. }/* end of if statement */
  569. if(!::IsWindow(m_hWnd)){
  570. hr = OnResize(); // need to update DDraw destination rectangle
  571. }/* end of if statement */
  572. return(hr);
  573. }/* end of function SetObjectRects */
  574. /*************************************************************************/
  575. /* Function: GetParentHWND */
  576. /* Description: Gets the parent window HWND where we are operating. */
  577. /*************************************************************************/
  578. HRESULT CMSWebDVD::GetParentHWND(HWND* pWnd){
  579. HRESULT hr = S_OK;
  580. IOleClientSite *pClientSite;
  581. IOleContainer *pContainer;
  582. IOleObject *pObject;
  583. hr = GetClientSite(&pClientSite);
  584. if(FAILED(hr)){
  585. return(hr);
  586. }/* end of if statement */
  587. IOleWindow *pOleWindow;
  588. do {
  589. hr = pClientSite->QueryInterface(IID_IOleWindow, (LPVOID *) &pOleWindow);
  590. if(FAILED(hr)){
  591. return(hr);
  592. }/* end of if statement */
  593. hr = pOleWindow->GetWindow((HWND*)pWnd);
  594. pOleWindow->Release();
  595. // if pClientSite is windowless, go get its container
  596. if (FAILED(hr)) {
  597. HRESULT hrTemp = pClientSite->GetContainer(&pContainer);
  598. if(FAILED(hrTemp)){
  599. return(hrTemp);
  600. }/* end of if statement */
  601. pClientSite->Release();
  602. hrTemp = pContainer->QueryInterface(IID_IOleObject, (LPVOID*)&pObject);
  603. if(FAILED(hrTemp)){
  604. return(hrTemp);
  605. }/* end of if statement */
  606. pContainer->Release();
  607. hrTemp = pObject->GetClientSite(&pClientSite);
  608. if(FAILED(hrTemp)){
  609. return(hrTemp);
  610. }/* end of if statement */
  611. }
  612. } while (FAILED(hr));
  613. pClientSite->Release();
  614. return(hr);
  615. }/* end of function GetParentHWND */
  616. /*************************************************************************/
  617. /* Function: SetReadyState */
  618. /* Description: Sets ready state and fires event if it needs to be fired */
  619. /*************************************************************************/
  620. HRESULT CMSWebDVD::SetReadyState(LONG lReadyState){
  621. HRESULT hr = S_OK;
  622. bool bFireEvent = (lReadyState != m_nReadyState);
  623. #ifdef _DEBUG
  624. if(m_nFreezeEvents > 0){
  625. ::Sleep(10);
  626. ATLTRACE("Container not expecting events at the moment");
  627. }/* end of is statement */
  628. #endif
  629. if(bFireEvent){
  630. put_ReadyState(lReadyState);
  631. Fire_ReadyStateChange(lReadyState);
  632. }
  633. else {
  634. // set the variable
  635. m_nReadyState = lReadyState;
  636. }/* end of if statement */
  637. return(hr);
  638. }/* end of function SetReadyState */
  639. /*************************************************************************/
  640. /* DVD methods to do with supporting DVD Playback */
  641. /*************************************************************************/
  642. /*************************************************************************/
  643. /* Function: Render */
  644. /* Description: Builds Graph. */
  645. /* lRender not used in curent implemetation, but might be used in the */
  646. /* future to denote different mode of initializations. */
  647. /*************************************************************************/
  648. STDMETHODIMP CMSWebDVD::Render(long lRender){
  649. USES_CONVERSION;
  650. HRESULT hr = S_OK;
  651. try {
  652. //throw(E_NO_DECODER);
  653. if(m_fInitialized && ((dvdRender_Reinitialize & lRender) != dvdRender_Reinitialize)){
  654. ATLTRACE(TEXT("Graph was already initialized\n"));
  655. throw(S_FALSE);
  656. }/* end of if statement */
  657. Cleanup(); // release all the interfaces so we start from ground up
  658. //Init(); // initialize the variables
  659. m_fInitialized = false; // set the flag that we are not initialized in
  660. // case if something goes wrong
  661. // create an event that lets us know we are past FP_DOM
  662. m_hFPDOMEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL);
  663. ATLASSERT(m_hFPDOMEvent);
  664. hr = ::CoCreateInstance(CLSID_DvdGraphBuilder, NULL, CLSCTX_INPROC,
  665. IID_IDvdGraphBuilder, (LPVOID *)&m_pDvdGB) ;
  666. if (FAILED(hr) || !m_pDvdGB){
  667. #ifdef _DEBUG
  668. ::MessageBox(::GetFocus(), TEXT("DirectShow DVD software not installed properly.\nPress OK to end the app."),
  669. TEXT("Error"), MB_OK | MB_ICONSTOP) ;
  670. #endif
  671. throw(hr);
  672. }/* end of if statement */
  673. /* Force NonExclMode (in other words: use Overlay Mixer and NOT VMR) */
  674. GUID IID_IDDrawNonExclModeVideo = {0xec70205c,0x45a3,0x4400,{0xa3,0x65,0xc4,0x47,0x65,0x78,0x45,0xc7}};
  675. // Set DDraw object and surface on DVD graph builder before starting to build graph
  676. hr = m_pDvdGB->GetDvdInterface(IID_IDDrawNonExclModeVideo, (LPVOID *)&m_pDDEX) ;
  677. if (FAILED(hr) || !m_pDDEX){
  678. ATLTRACE(TEXT("ERROR: IDvdGB::GetDvdInterface(IDDrawExclModeVideo) \n"));
  679. ATLTRACE(TEXT("The QDVD.DLL does not support IDvdInfo2 or IID_IDvdControl2, please update QDVD.DLL\n"));
  680. throw(E_NO_IDVD2_PRESENT);
  681. }/* end of if statement */
  682. if (m_bWndLess || m_fUseDDrawDirect){
  683. hr = SetupDDraw();
  684. if(FAILED(hr)){
  685. throw(hr);
  686. }/* end of if statement */
  687. hr = m_pDDrawDVD->HasOverlay();
  688. if(FAILED(hr)){
  689. throw(hr);
  690. }/* end of if statement */
  691. if(S_FALSE == hr){
  692. throw(E_NO_OVERLAY);
  693. }/* end of if statement */
  694. hr = m_pDDrawDVD->HasAvailableOverlay();
  695. if(FAILED(hr)){
  696. throw(hr);
  697. }/* end of if statement */
  698. hr = m_pDDrawDVD->GetOverlayMaxStretch(&m_dwOvMaxStretch);
  699. if(FAILED(hr)){
  700. throw(hr);
  701. }/* end of if statement */
  702. if(S_FALSE == hr){
  703. throw(E_NO_USABLE_OVERLAY);
  704. }/* end of if statement */
  705. hr = m_pDDEX->SetDDrawObject(m_pDDrawDVD->GetDDrawObj());
  706. if (FAILED(hr)){
  707. ATLTRACE(TEXT("ERROR: IDDrawExclModeVideo::SetDDrawObject()"));
  708. m_pDDEX.Release() ; // release before returning
  709. throw(hr);
  710. }/* end of if statement */
  711. hr = m_pDDEX->SetDDrawSurface(m_pDDrawDVD->GetDDrawSurf()); // have to set the surface if NOT the IDDExcl complains
  712. if (FAILED(hr)){
  713. m_pDDEX.Release() ; // release before returning
  714. throw(hr);
  715. }/* end of if statement */
  716. //OnResize(); // set the DDRAW RECTS, we are doing it in the thread
  717. #if 1
  718. hr = m_pDDEX->SetCallbackInterface(m_pDDrawDVD->GetCallbackInterface(), 0) ;
  719. if (FAILED(hr))
  720. {
  721. throw(hr);
  722. }/* end of it statement */
  723. #endif
  724. }/* end of if statement */
  725. DWORD dwRenderFlag = AM_DVD_HWDEC_PREFER; // use the hardware if possible
  726. AM_DVD_RENDERSTATUS amDvdStatus;
  727. //Completes building a filter graph according to user specifications for
  728. // playing back a default DVD-Video volume
  729. hr = m_pDvdGB->RenderDvdVideoVolume(NULL, dwRenderFlag, &amDvdStatus);
  730. if (FAILED(hr)){
  731. #ifdef _DEBUG
  732. TCHAR strError[1000];
  733. AMGetErrorText(hr, strError, sizeof(strError)) ;
  734. ::MessageBox(::GetFocus(), strError, TEXT("Error"), MB_OK) ;
  735. #endif
  736. if(VFW_E_DVD_DECNOTENOUGH == hr){
  737. throw(E_NO_DECODER);
  738. }/* end of if statement */
  739. throw(hr);
  740. }/* end of if statement */
  741. HRESULT hrTmp = m_pDvdGB->GetDvdInterface(IID_IDvdControl2, (LPVOID *)&m_pDvdCtl2) ;
  742. if(FAILED(hrTmp)){
  743. ATLTRACE(TEXT("The QDVD.DLL does not support IDvdInfo2 or IID_IDvdControl2, please update QDVD.DLL\n"));
  744. throw(E_NO_IDVD2_PRESENT);
  745. }/* end of if statement */
  746. if (hr == S_FALSE){ // if partial success
  747. if((dvdRender_Error_On_Missing_Drive & lRender) && amDvdStatus.bDvdVolInvalid || amDvdStatus.bDvdVolUnknown){
  748. #if 0
  749. TCHAR filename[MAX_PATH];
  750. if (OpenIFOFile(::GetDesktopWindow(), filename)){
  751. USES_CONVERSION;
  752. if(!m_pDvdCtl2){
  753. throw (E_UNEXPECTED);
  754. }/* end of if statement */
  755. hr = m_pDvdCtl2->SetDVDDirectory(T2W(filename));
  756. }
  757. else{
  758. hr = E_NO_DVD_VOLUME;
  759. }/* end of if statement */
  760. #else
  761. hr = E_NO_DVD_VOLUME;
  762. #endif
  763. if(FAILED(hr)){
  764. throw(E_NO_DVD_VOLUME);
  765. }/* end of if statement */
  766. }/* end of if statement */
  767. // improve your own error handling
  768. if(amDvdStatus.bNoLine21Out != NULL){ // we do not care about the caption
  769. #ifdef _DEBUG
  770. if (::MessageBox(::GetFocus(), TEXT(" Line 21 has failed Do you still want to continue?"), TEXT("Warning"), MB_YESNO) == IDNO){
  771. throw(E_FAIL);
  772. }/* end of if statement */
  773. #endif
  774. }/* end of if statement */
  775. if((amDvdStatus.iNumStreamsFailed > 0) && ((amDvdStatus.dwFailedStreamsFlag & AM_DVD_STREAM_VIDEO) == AM_DVD_STREAM_VIDEO)){
  776. throw(E_NO_VIDEO_STREAM);
  777. }/* end of if statement */
  778. // handeling this below
  779. if((amDvdStatus.iNumStreamsFailed > 0) && ((amDvdStatus.dwFailedStreamsFlag & AM_DVD_STREAM_SUBPIC) == AM_DVD_STREAM_SUBPIC)){
  780. #if 0
  781. TCHAR strBuffer1[MAX_PATH];
  782. if(!::LoadString(_Module.m_hInstResource, IDS_E_NO_SUBPICT_STREAM, strBuffer1, MAX_PATH)){
  783. throw(E_UNEXPECTED);
  784. }/* end of if statement */
  785. TCHAR strBuffer2[MAX_PATH];
  786. if(!::LoadString(_Module.m_hInstResource, IDS_WARNING, strBuffer2, MAX_PATH)){
  787. throw(E_UNEXPECTED);
  788. }/* end of if statement */
  789. ::MessageBox(::GetFocus(), strBuffer1, strBuffer2, MB_OK);
  790. #else
  791. // Will bubble up the error to the app
  792. m_bFireNoSubpictureStream = TRUE;
  793. #endif
  794. }/* end of if statement */
  795. }/* end of if statement */
  796. // Now get all the interfaces to playback the DVD-Video volume
  797. hr = m_pDvdGB->GetFiltergraph(&m_pGB) ;
  798. if(FAILED(hr)){
  799. throw(hr);
  800. }/* end of if statement */
  801. hr = m_pGB->QueryInterface(IID_IMediaControl, (LPVOID *)&m_pMC) ;
  802. if(FAILED(hr)){
  803. throw(hr);
  804. }/* end of if statement */
  805. hr = m_pGB->QueryInterface(IID_IVideoFrameStep, (LPVOID *)&m_pVideoFrameStep);
  806. if(FAILED(hr)){
  807. // do not bail out, since frame stepping is not that important
  808. ATLTRACE(TEXT("Frame stepping QI failed"));
  809. ATLASSERT(FALSE);
  810. }/* end of if statement */
  811. hr = m_pGB->QueryInterface(IID_IMediaEventEx, (LPVOID *)&m_pME) ;
  812. if(FAILED(hr)){
  813. throw(hr);
  814. }/* end of if statement */
  815. IVideoWindow* pVW = NULL;
  816. if (!m_bWndLess){
  817. //
  818. // Also set up the event notification so that the main window gets
  819. // informed about all that we care about during playback.
  820. //
  821. // HAVE THREAD !!!
  822. INT iCount = 0;
  823. while(m_hWnd == NULL){
  824. if(iCount >10) break;
  825. ::Sleep(100);
  826. iCount ++;
  827. }/* end of while loop */
  828. if(m_hWnd == NULL){
  829. ATLTRACE(TEXT("Window is not active as of yet\n returning with E_PENDING\n"));
  830. hr = E_PENDING;
  831. throw(hr);
  832. }/* end of if statement */
  833. hr = m_pME->SetNotifyWindow((OAHWND) m_hWnd, WM_DVDPLAY_EVENT, 0);
  834. if(FAILED(hr)){
  835. throw(hr);
  836. }/* end of if statement */
  837. if(!m_fUseDDrawDirect){
  838. hr = m_pDvdGB->GetDvdInterface(IID_IVideoWindow, (LPVOID *)&pVW) ;
  839. if(FAILED(hr)){
  840. throw(hr);
  841. }/* end of if statement */
  842. hr = pVW->put_MessageDrain((OAHWND)m_hWnd); // get our mouse messages over
  843. if(FAILED(hr)){
  844. throw(hr);
  845. }/* end of if statement */
  846. }/* end of if statement */
  847. }
  848. else {
  849. // create the timer which will keep us updated
  850. m_hTimerId = ::SetTimer(NULL, 0, cdwTimeout, GetTimerProc());
  851. }/* end of if statement */
  852. hr = m_pDvdGB->GetDvdInterface(IID_IDvdInfo2, (LPVOID *)&m_pDvdInfo2) ;
  853. if(FAILED(hr)){
  854. ATLTRACE(TEXT("The QDVD.DLL does not support IDvdInfo2 or IID_IDvdControl2, please update QDVD.DLL\n"));
  855. throw(E_NO_IDVD2_PRESENT);
  856. }/* end of if statement */
  857. hr = SetupAudio();
  858. if(FAILED(hr)){
  859. #if 1
  860. throw(E_NO_SOUND_STREAM);
  861. #else
  862. TCHAR strBuffer1[MAX_PATH];
  863. if(!::LoadString(_Module.m_hInstResource, IDS_E_NO_SOUND_STREAM, strBuffer1, MAX_PATH)){
  864. throw(E_UNEXPECTED);
  865. }/* end of if statement */
  866. TCHAR strBuffer2[MAX_PATH];
  867. if(!::LoadString(_Module.m_hInstResource, IDS_WARNING, strBuffer2, MAX_PATH)){
  868. throw(E_UNEXPECTED);
  869. }/* end of if statement */
  870. ::MessageBox(::GetFocus(), strBuffer1, strBuffer2, MB_OK);
  871. #endif
  872. }/* end of if statement */
  873. hr = SetupEventNotifySink();
  874. #ifdef _DEBUG
  875. if(FAILED(hr)){
  876. ATLTRACE(TEXT("Failed to setup event notify sink\n"));
  877. }/* end of if statement */
  878. #endif
  879. if (!m_bWndLess && !m_fUseDDrawDirect){
  880. // set the window position and style
  881. hr = pVW->put_Owner((OAHWND)m_hWnd);
  882. RECT rc;
  883. ::GetWindowRect(m_hWnd, &rc);
  884. hr = pVW->SetWindowPosition(0, 0, WIDTH(&rc), HEIGHT(&rc));
  885. LONG lStyle = GetWindowLong(GWL_STYLE);
  886. hr = pVW->put_WindowStyle(lStyle);
  887. lStyle = GetWindowLong(GWL_EXSTYLE);
  888. hr = pVW->put_WindowStyleEx(lStyle);
  889. pVW->Release();
  890. }/* end of if statement */
  891. bool fSetColorKey = false; // flag so we do not duplicate code, and simplify logic
  892. // case when windowless and color key is not defined
  893. // then in that case get the color key from the OV mixer
  894. if(m_bWndLess || m_fUseDDrawDirect){
  895. COLORREF clr;
  896. hrTmp = GetColorKey(&clr);
  897. if(FAILED(hrTmp)){
  898. #ifdef _DEBUG
  899. ::MessageBox(::GetFocus(), TEXT("failed to get color key"), TEXT("error"), MB_OK);
  900. #endif
  901. throw(hrTmp);
  902. }/* end of if statement */
  903. if((m_clrColorKey & UNDEFINED_COLORKEY_COLOR) == UNDEFINED_COLORKEY_COLOR) {
  904. m_clrColorKey = clr;
  905. }/* end of if statement */
  906. else if (clr != m_clrColorKey) {
  907. fSetColorKey = true;
  908. }
  909. }/* end of if statement */
  910. // case when color key is defined
  911. // if windowless set the background color at the same time
  912. if(fSetColorKey){
  913. hrTmp = put_ColorKey(m_clrColorKey);
  914. #ifdef _DEBUG
  915. if(FAILED(hrTmp)){
  916. ::MessageBox(::GetFocus(), TEXT("failed to set color key"), TEXT("error"), MB_OK);
  917. throw(E_FAIL);
  918. }/* end of if statement */
  919. #endif
  920. }/* end of if statement */
  921. m_fInitialized = true;
  922. // turn off the closed caption. it is turned on by default
  923. // this code should be in the DVDNav!
  924. put_CCActive(VARIANT_FALSE);
  925. // Create the DVD administrator and set player level
  926. m_pDvdAdmin = new CComObject<CMSDVDAdm>;
  927. //m_pDvdAdmin.AddRef();
  928. if(!m_pDvdAdmin){
  929. return E_UNEXPECTED;
  930. }
  931. RestoreDefaultSettings();
  932. // disc eject and insert handler
  933. BSTR bstrRoot;
  934. hr = get_DVDDirectory(&bstrRoot);
  935. if (SUCCEEDED(hr)) {
  936. TCHAR *szRoot;
  937. szRoot = OLE2T(bstrRoot);
  938. m_mediaHandler.SetDrive(szRoot[0] );
  939. m_mediaHandler.SetDVD(this);
  940. m_mediaHandler.Open();
  941. }
  942. hr = m_pDvdCtl2->SetOption( DVD_HMSF_TimeCodeEvents, TRUE);
  943. }/* end of try statement */
  944. catch(HRESULT hrTmp){
  945. hr = hrTmp;
  946. }/* end of catch statement */
  947. catch(...){
  948. hr = E_UNEXPECTED;
  949. }/* end of catch statement */
  950. return HandleError(hr);
  951. }/* end of function Render */
  952. /*************************************************************************/
  953. /* Function: Play */
  954. /* Description: Puts the DVDNav in the run mode. */
  955. /*************************************************************************/
  956. STDMETHODIMP CMSWebDVD::Play(){
  957. HRESULT hr = S_OK;
  958. try {
  959. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  960. if(!m_pMC){
  961. throw(E_UNEXPECTED);
  962. }/* end of if statement */
  963. if(!m_pDvdCtl2 ){
  964. throw(E_UNEXPECTED);
  965. }/* end of if statement */
  966. OAFilterState state;
  967. hr = m_pMC->GetState(cgStateTimeout, &state);
  968. m_DVDFilterState = (DVDFilterState) state; // save the state so we can restore it if an API fails
  969. if(FAILED(hr)){
  970. throw(hr);
  971. }/* end of if statement */
  972. bool bFireEvent = false; // fire event only when we change the state
  973. if(state != dvdState_Running){
  974. bFireEvent = true;
  975. // disable the stop in case CTRL+ALT+DEL
  976. if(state == dvdState_Stopped){
  977. if(FALSE == m_fEnableResetOnStop){
  978. hr = m_pDvdCtl2->SetOption(DVD_ResetOnStop, FALSE);
  979. if(FAILED(hr)){
  980. throw(hr);
  981. }/* end of if statement */
  982. }/* end of if statement */
  983. }/* end of if statement */
  984. hr = m_pMC->Run(); // put it into running state just in case we are not in the running
  985. // state
  986. if(FAILED(hr)){
  987. throw(hr);
  988. }/* end of if statement */
  989. }/* end of if statement */
  990. if(bFireEvent && m_pMediaSink){
  991. m_pMediaSink->Notify(EC_DVD_PLAYING, 0, 0);
  992. }/* end of if statement */
  993. // not collect hr
  994. #ifdef _DEBUG
  995. if(m_fStillOn){
  996. ATLTRACE(TEXT("Not reseting the speed to 1.0 \n"));
  997. }/* end of if statement */
  998. #endif
  999. if(false == m_fStillOn && true == m_fResetSpeed){
  1000. // if we are in the still do not reset the speed
  1001. m_pDvdCtl2->PlayForwards(cgdNormalSpeed,0,0);
  1002. }/* end of if statement */
  1003. }/* end of try statement */
  1004. catch(HRESULT hrTmp){
  1005. hr = hrTmp;
  1006. }/* end of catch statement */
  1007. catch(...){
  1008. hr = E_UNEXPECTED;
  1009. }/* end of catch statement */
  1010. return HandleError(hr);
  1011. }/* end of function Play */
  1012. /*************************************************************************/
  1013. /* Function: Pause */
  1014. /* Description: Pauses the filter graph just only in the case when stat */
  1015. /* would not indicate that it was paused. */
  1016. /*************************************************************************/
  1017. STDMETHODIMP CMSWebDVD::Pause(){
  1018. HRESULT hr = S_OK;
  1019. try {
  1020. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1021. if(!m_pMC){
  1022. throw(E_UNEXPECTED);
  1023. }/* end of if statement */
  1024. OAFilterState state;
  1025. hr = m_pMC->GetState(cgStateTimeout, &state);
  1026. if(FAILED(hr)){
  1027. throw(hr);
  1028. }/* end of if statement */
  1029. bool bFireEvent = false; // fire event only when we change the state
  1030. if(state != dvdState_Paused){
  1031. bFireEvent = true;
  1032. hr = m_pMC->Pause(); // put it into running state just in case we are not in the running
  1033. // state
  1034. if(FAILED(hr)){
  1035. throw(hr);
  1036. }/* end of if statement */
  1037. }/* end of if statement */
  1038. #if 1
  1039. // Fired our own paused event
  1040. if(bFireEvent && m_pMediaSink){
  1041. m_pMediaSink->Notify(EC_DVD_PAUSED, 0, 0);
  1042. }/* end of if statement */
  1043. #endif
  1044. }/* end of try statement */
  1045. catch(HRESULT hrTmp){
  1046. hr = hrTmp;
  1047. }/* end of catch statement */
  1048. catch(...){
  1049. hr = E_UNEXPECTED;
  1050. }/* end of catch statement */
  1051. return HandleError(hr);
  1052. }/* end of function Pause */
  1053. /*************************************************************************/
  1054. /* Function: Stop */
  1055. /* Description: Stops the filter graph if the state does not indicate */
  1056. /* it was stopped. */
  1057. /*************************************************************************/
  1058. STDMETHODIMP CMSWebDVD::Stop(){
  1059. HRESULT hr = S_OK;
  1060. try {
  1061. if(!m_pMC){
  1062. throw(E_UNEXPECTED);
  1063. }/* end of if statement */
  1064. if(!m_pDvdCtl2){
  1065. return(E_UNEXPECTED);
  1066. }/* end of if statement */
  1067. OAFilterState state;
  1068. hr = m_pMC->GetState(cgStateTimeout, &state);
  1069. if(FAILED(hr)){
  1070. throw(hr);
  1071. }/* end of if statement */
  1072. if(state != dvdState_Stopped){
  1073. if(FALSE == m_fEnableResetOnStop){
  1074. hr = m_pDvdCtl2->SetOption(DVD_ResetOnStop, TRUE);
  1075. if(FAILED(hr)){
  1076. throw(hr);
  1077. }/* end of if statement */
  1078. }/* end of if statement */
  1079. hr = m_pMC->Stop(); // put it into running state just in case we are not in the running
  1080. // state
  1081. }/* end of if statement */
  1082. }/* end of try statement */
  1083. catch(HRESULT hrTmp){
  1084. hr = hrTmp;
  1085. }/* end of catch statement */
  1086. catch(...){
  1087. hr = E_UNEXPECTED;
  1088. }/* end of catch statement */
  1089. return HandleError(hr);
  1090. }/* end of function Stop */
  1091. /*************************************************************************/
  1092. /* Function: OnDVDEvent */
  1093. /* Description: Handles the DVD events */
  1094. /*************************************************************************/
  1095. LRESULT CMSWebDVD::OnDVDEvent(UINT /* uMsg */, WPARAM wParam, LPARAM lParam, BOOL& bHandled){
  1096. if (m_bFireUpdateOverlay == TRUE) {
  1097. if (m_fInitialized) {
  1098. m_bFireUpdateOverlay = FALSE;
  1099. Fire_UpdateOverlay();
  1100. }
  1101. }
  1102. LONG lEvent ;
  1103. LONG_PTR lParam1, lParam2 ;
  1104. if (m_bFireNoSubpictureStream) {
  1105. m_bFireNoSubpictureStream = FALSE;
  1106. lEvent = EC_DVD_ERROR;
  1107. lParam1 = DVD_ERROR_NoSubpictureStream;
  1108. lParam2 = 0;
  1109. VARIANT varLParam1;
  1110. VARIANT varLParam2;
  1111. #ifdef _WIN64
  1112. varLParam1.llVal = lParam1;
  1113. varLParam1.vt = VT_I8;
  1114. varLParam2.llVal = lParam2;
  1115. varLParam2.vt = VT_I8;
  1116. #else
  1117. varLParam1.lVal = lParam1;
  1118. varLParam1.vt = VT_I4;
  1119. varLParam2.lVal = lParam2;
  1120. varLParam2.vt = VT_I4;
  1121. #endif
  1122. // fire the event now after we have processed it internally
  1123. Fire_DVDNotify(lEvent, varLParam1, varLParam2);
  1124. }
  1125. bHandled = TRUE;
  1126. //
  1127. // Because the message mode for IMediaEvent may not be set before
  1128. // we get the first event it's important to read all the events
  1129. // pending when we get a window message to say there are events pending.
  1130. // GetEvent() returns E_ABORT when no more event is left.
  1131. //
  1132. while (m_pME && SUCCEEDED(m_pME->GetEvent(&lEvent, &lParam1, &lParam2, 0))){
  1133. switch (lEvent){
  1134. //
  1135. // First the DVD error events
  1136. //
  1137. case EC_DVD_ERROR:
  1138. switch (lParam1){
  1139. case DVD_ERROR_Unexpected:
  1140. #ifdef _DEBUG
  1141. ::MessageBox(::GetFocus(),
  1142. TEXT("An unexpected error (possibly incorrectly authored content)")
  1143. TEXT("\nwas encountered.")
  1144. TEXT("\nCan't playback this DVD-Video disc."),
  1145. TEXT("Error"), MB_OK | MB_ICONINFORMATION) ;
  1146. #endif
  1147. //m_pMC->Stop() ;
  1148. break ;
  1149. case DVD_ERROR_CopyProtectFail:
  1150. #ifdef _DEBUG
  1151. ::MessageBox(::GetFocus(),
  1152. TEXT("Key exchange for DVD copy protection failed.")
  1153. TEXT("\nCan't playback this DVD-Video disc."),
  1154. TEXT("Error"), MB_OK | MB_ICONINFORMATION) ;
  1155. #endif
  1156. //m_pMC->Stop() ;
  1157. break ;
  1158. case DVD_ERROR_InvalidDVD1_0Disc:
  1159. #ifdef _DEBUG
  1160. ::MessageBox(::GetFocus(),
  1161. TEXT("This DVD-Video disc is incorrectly authored for v1.0 of the spec.")
  1162. TEXT("\nCan't playback this disc."),
  1163. TEXT("Error"), MB_OK | MB_ICONINFORMATION) ;
  1164. #endif
  1165. //m_pMC->Stop() ;
  1166. break ;
  1167. case DVD_ERROR_InvalidDiscRegion:
  1168. #ifdef _DEBUG
  1169. ::MessageBox(::GetFocus(),
  1170. TEXT("This DVD-Video disc cannot be played, because it is not")
  1171. TEXT("\nauthored to play in the current system region.")
  1172. TEXT("\nThe region mismatch may be fixed by changing the")
  1173. TEXT("\nsystem region (with DVDRgn.exe)."),
  1174. TEXT("Error"), MB_OK | MB_ICONINFORMATION) ;
  1175. #endif
  1176. Stop();
  1177. // fire the region change dialog
  1178. RegionChange();
  1179. break ;
  1180. case DVD_ERROR_LowParentalLevel:
  1181. #ifdef _DEBUG
  1182. ::MessageBox(::GetFocus(),
  1183. TEXT("Player parental level is set lower than the lowest parental")
  1184. TEXT("\nlevel available in this DVD-Video content.")
  1185. TEXT("\nCannot playback this DVD-Video disc."),
  1186. TEXT("Error"), MB_OK | MB_ICONINFORMATION) ;
  1187. #endif
  1188. //m_pMC->Stop() ;
  1189. break ;
  1190. case DVD_ERROR_MacrovisionFail:
  1191. #ifdef _DEBUG
  1192. ::MessageBox(::GetFocus(),
  1193. TEXT("This DVD-Video content is protected by Macrovision.")
  1194. TEXT("\nThe system does not satisfy Macrovision requirement.")
  1195. TEXT("\nCan't continue playing this disc."),
  1196. TEXT("Error"), MB_OK | MB_ICONINFORMATION) ;
  1197. #endif
  1198. //m_pMC->Stop() ;
  1199. break ;
  1200. case DVD_ERROR_IncompatibleSystemAndDecoderRegions:
  1201. #ifdef _DEBUG
  1202. ::MessageBox(::GetFocus(),
  1203. TEXT("No DVD-Video disc can be played on this system, because ")
  1204. TEXT("\nthe system region does not match the decoder region.")
  1205. TEXT("\nPlease contact the manufacturer of this system."),
  1206. TEXT("Error"), MB_OK | MB_ICONINFORMATION) ;
  1207. #endif
  1208. //m_pMC->Stop() ;
  1209. break ;
  1210. case DVD_ERROR_IncompatibleDiscAndDecoderRegions:
  1211. #ifdef _DEBUG
  1212. ::MessageBox(::GetFocus(),
  1213. TEXT("This DVD-Video disc cannot be played on this system, because it is")
  1214. TEXT("\nnot authored to be played in the installed decoder's region."),
  1215. TEXT("Error"), MB_OK | MB_ICONINFORMATION) ;
  1216. #endif
  1217. //m_pMC->Stop() ;
  1218. break ;
  1219. }/* end of switch case */
  1220. break ;
  1221. //
  1222. // Next the normal DVD related events
  1223. //
  1224. case EC_DVD_VALID_UOPS_CHANGE:
  1225. {
  1226. VALID_UOP_SOMTHING_OR_OTHER validUOPs = (DWORD) lParam1;
  1227. if (validUOPs&UOP_FLAG_Play_Title_Or_AtTime) {
  1228. Fire_PlayAtTimeInTitle(VARIANT_FALSE);
  1229. Fire_PlayAtTime(VARIANT_FALSE);
  1230. }
  1231. else {
  1232. Fire_PlayAtTimeInTitle(VARIANT_TRUE);
  1233. Fire_PlayAtTime(VARIANT_TRUE);
  1234. }
  1235. if (validUOPs&UOP_FLAG_Play_Chapter) {
  1236. Fire_PlayChapterInTitle(VARIANT_FALSE);
  1237. Fire_PlayChapter(VARIANT_FALSE);
  1238. }
  1239. else {
  1240. Fire_PlayChapterInTitle(VARIANT_TRUE);
  1241. Fire_PlayChapter(VARIANT_TRUE);
  1242. }
  1243. if (validUOPs&UOP_FLAG_Play_Title){
  1244. Fire_PlayTitle(VARIANT_FALSE);
  1245. }
  1246. else {
  1247. Fire_PlayTitle(VARIANT_TRUE);
  1248. }
  1249. if (validUOPs&UOP_FLAG_Stop)
  1250. Fire_Stop(VARIANT_FALSE);
  1251. else
  1252. Fire_Stop(VARIANT_TRUE);
  1253. if (validUOPs&UOP_FLAG_ReturnFromSubMenu)
  1254. Fire_ReturnFromSubmenu(VARIANT_FALSE);
  1255. else
  1256. Fire_ReturnFromSubmenu(VARIANT_TRUE);
  1257. if (validUOPs&UOP_FLAG_Play_Chapter_Or_AtTime) {
  1258. Fire_PlayAtTimeInTitle(VARIANT_FALSE);
  1259. Fire_PlayChapterInTitle(VARIANT_FALSE);
  1260. }
  1261. else {
  1262. Fire_PlayAtTimeInTitle(VARIANT_TRUE);
  1263. Fire_PlayChapterInTitle(VARIANT_TRUE);
  1264. }
  1265. if (validUOPs&UOP_FLAG_PlayPrev_Or_Replay_Chapter){
  1266. Fire_PlayPrevChapter(VARIANT_FALSE);
  1267. Fire_ReplayChapter(VARIANT_FALSE);
  1268. }
  1269. else {
  1270. Fire_PlayPrevChapter(VARIANT_TRUE);
  1271. Fire_ReplayChapter(VARIANT_TRUE);
  1272. }/* end of if statement */
  1273. if (validUOPs&UOP_FLAG_PlayNext_Chapter)
  1274. Fire_PlayNextChapter(VARIANT_FALSE);
  1275. else
  1276. Fire_PlayNextChapter(VARIANT_TRUE);
  1277. if (validUOPs&UOP_FLAG_Play_Forwards)
  1278. Fire_PlayForwards(VARIANT_FALSE);
  1279. else
  1280. Fire_PlayForwards(VARIANT_TRUE);
  1281. if (validUOPs&UOP_FLAG_Play_Backwards)
  1282. Fire_PlayBackwards(VARIANT_FALSE);
  1283. else
  1284. Fire_PlayBackwards(VARIANT_TRUE);
  1285. if (validUOPs&UOP_FLAG_ShowMenu_Title)
  1286. Fire_ShowMenu(dvdMenu_Title, VARIANT_FALSE);
  1287. else
  1288. Fire_ShowMenu(dvdMenu_Title, VARIANT_TRUE);
  1289. if (validUOPs&UOP_FLAG_ShowMenu_Root)
  1290. Fire_ShowMenu(dvdMenu_Root, VARIANT_FALSE);
  1291. else
  1292. Fire_ShowMenu(dvdMenu_Root, VARIANT_TRUE);
  1293. //TODO: Add the event for specific menus
  1294. if (validUOPs&UOP_FLAG_ShowMenu_SubPic)
  1295. Fire_ShowMenu(dvdMenu_Subpicture, VARIANT_FALSE);
  1296. else
  1297. Fire_ShowMenu(dvdMenu_Subpicture, VARIANT_TRUE);
  1298. if (validUOPs&UOP_FLAG_ShowMenu_Audio)
  1299. Fire_ShowMenu(dvdMenu_Audio, VARIANT_FALSE);
  1300. else
  1301. Fire_ShowMenu(dvdMenu_Audio, VARIANT_TRUE);
  1302. if (validUOPs&UOP_FLAG_ShowMenu_Angle)
  1303. Fire_ShowMenu(dvdMenu_Angle, VARIANT_FALSE);
  1304. else
  1305. Fire_ShowMenu(dvdMenu_Angle, VARIANT_TRUE);
  1306. if (validUOPs&UOP_FLAG_ShowMenu_Chapter)
  1307. Fire_ShowMenu(dvdMenu_Chapter, VARIANT_FALSE);
  1308. else
  1309. Fire_ShowMenu(dvdMenu_Chapter, VARIANT_TRUE);
  1310. if (validUOPs&UOP_FLAG_Resume)
  1311. Fire_Resume(VARIANT_FALSE);
  1312. else
  1313. Fire_Resume(VARIANT_TRUE);
  1314. if (validUOPs&UOP_FLAG_Select_Or_Activate_Button)
  1315. Fire_SelectOrActivatButton(VARIANT_FALSE);
  1316. else
  1317. Fire_SelectOrActivatButton(VARIANT_TRUE);
  1318. if (validUOPs&UOP_FLAG_Still_Off)
  1319. Fire_StillOff(VARIANT_FALSE);
  1320. else
  1321. Fire_StillOff(VARIANT_TRUE);
  1322. if (validUOPs&UOP_FLAG_Pause_On)
  1323. Fire_PauseOn(VARIANT_FALSE);
  1324. else
  1325. Fire_PauseOn(VARIANT_TRUE);
  1326. if (validUOPs&UOP_FLAG_Select_Audio_Stream)
  1327. Fire_ChangeCurrentAudioStream(VARIANT_FALSE);
  1328. else
  1329. Fire_ChangeCurrentAudioStream(VARIANT_TRUE);
  1330. if (validUOPs&UOP_FLAG_Select_SubPic_Stream)
  1331. Fire_ChangeCurrentSubpictureStream(VARIANT_FALSE);
  1332. else
  1333. Fire_ChangeCurrentSubpictureStream(VARIANT_TRUE);
  1334. if (validUOPs&UOP_FLAG_Select_Angle)
  1335. Fire_ChangeCurrentAngle(VARIANT_FALSE);
  1336. else
  1337. Fire_ChangeCurrentAngle(VARIANT_TRUE);
  1338. /*
  1339. if (validUOPs&UOP_FLAG_Karaoke_Audio_Pres_Mode_Change)
  1340. ;
  1341. if (validUOPs&UOP_FLAG_Video_Pres_Mode_Change)
  1342. ;
  1343. */
  1344. }
  1345. break;
  1346. case EC_DVD_STILL_ON:
  1347. m_fStillOn = true;
  1348. break ;
  1349. case EC_DVD_STILL_OFF:
  1350. m_fStillOn = false;
  1351. break ;
  1352. case EC_DVD_DOMAIN_CHANGE:
  1353. switch (lParam1){
  1354. case DVD_DOMAIN_FirstPlay: // = 1
  1355. //case DVD_DOMAIN_VideoManagerMenu: // = 2
  1356. if(m_hFPDOMEvent){
  1357. // whenever we enter FP Domain we reset
  1358. ::ResetEvent(m_hFPDOMEvent);
  1359. }
  1360. else {
  1361. ATLTRACE(TEXT("No event initialized bug!!"));
  1362. ATLASSERT(FALSE);
  1363. }/* end of if statement */
  1364. break;
  1365. case DVD_DOMAIN_Stop: // = 5
  1366. case DVD_DOMAIN_VideoManagerMenu: // = 2
  1367. case DVD_DOMAIN_VideoTitleSetMenu: // = 3
  1368. case DVD_DOMAIN_Title: // = 4
  1369. default:
  1370. if(m_hFPDOMEvent){
  1371. // whenever we get out of the FP Dom Set our state
  1372. ::SetEvent(m_hFPDOMEvent);
  1373. }
  1374. else {
  1375. ATLTRACE(TEXT("No event initialized bug!!"));
  1376. ATLASSERT(FALSE);
  1377. }/* end of if statement */
  1378. break;
  1379. }/* end of switch case */
  1380. break ;
  1381. case EC_DVD_BUTTON_CHANGE:
  1382. break;
  1383. case EC_DVD_TITLE_CHANGE:
  1384. break ;
  1385. case EC_DVD_CHAPTER_START:
  1386. break ;
  1387. case EC_DVD_CURRENT_TIME:
  1388. //ATLTRACE(TEXT("Time event \n"));
  1389. break;
  1390. /**************
  1391. DVD_TIMECODE *pTime = (DVD_TIMECODE *) &lParam1 ;
  1392. wsprintf(m_achTimeText, TEXT("Current Time is %d%d:%d%d:%d%d"),
  1393. pTime->Hours10, pTime->Hours1,
  1394. pTime->Minutes10, pTime->Minutes1,
  1395. pTime->Seconds10, pTime->Seconds1) ;
  1396. InvalidateRect(m_hWnd, NULL, TRUE) ;
  1397. ************************/
  1398. case EC_DVD_CURRENT_HMSF_TIME:
  1399. //ATLTRACE(TEXT("New Time event \n"));
  1400. break;
  1401. //
  1402. // Then the general DirectShow related events
  1403. //
  1404. case EC_COMPLETE:
  1405. case EC_DVD_PLAYBACK_STOPPED:
  1406. Stop() ; // DShow doesn't stop on end; we should do that
  1407. break;
  1408. // fall through now...
  1409. case EC_USERABORT:
  1410. case EC_ERRORABORT:
  1411. case EC_FULLSCREEN_LOST:
  1412. //TO DO: Implement StopFullScreen() ; // we must get out of fullscreen mode now
  1413. break ;
  1414. case EC_DVD_DISC_EJECTED:
  1415. m_bEjected = true;
  1416. break;
  1417. case EC_DVD_DISC_INSERTED:
  1418. m_bEjected = false;
  1419. break;
  1420. case EC_STEP_COMPLETE:
  1421. m_fStepComplete = true;
  1422. break;
  1423. default:
  1424. break ;
  1425. }/* end of switch case */
  1426. // update for win64 since DShow uses now LONGLONG
  1427. VARIANT varLParam1;
  1428. VARIANT varLParam2;
  1429. #ifdef _WIN64
  1430. varLParam1.llVal = lParam1;
  1431. varLParam1.vt = VT_I8;
  1432. varLParam2.llVal = lParam2;
  1433. varLParam2.vt = VT_I8;
  1434. #else
  1435. varLParam1.lVal = lParam1;
  1436. varLParam1.vt = VT_I4;
  1437. varLParam2.lVal = lParam2;
  1438. varLParam2.vt = VT_I4;
  1439. #endif
  1440. // fire the event now after we have processed it internally
  1441. Fire_DVDNotify(lEvent, varLParam1, varLParam2);
  1442. //
  1443. // Remember to free the event params
  1444. //
  1445. m_pME->FreeEventParams(lEvent, lParam1, lParam2) ;
  1446. }/* end of while loop */
  1447. return 0 ;
  1448. }/* end of function OnDVDEvent */
  1449. /*************************************************************************/
  1450. /* Function: OnButtonDown */
  1451. /* Description: Selects the button. */
  1452. /*************************************************************************/
  1453. LRESULT CMSWebDVD::OnButtonDown(UINT, WPARAM wParam, LPARAM lParam, BOOL& bHandled){
  1454. try {
  1455. if(!m_fInitialized){
  1456. return(0);
  1457. }/* end of if statement */
  1458. m_bMouseDown = TRUE;
  1459. RECT rc;
  1460. HWND hwnd;
  1461. if(m_bWndLess){
  1462. HRESULT hr = GetParentHWND(&hwnd);
  1463. if(FAILED(hr)){
  1464. return(hr);
  1465. }/* end of if statement */
  1466. rc = m_rcPos;
  1467. }
  1468. else {
  1469. hwnd = m_hWnd;
  1470. ::GetClientRect(hwnd, &rc);
  1471. }/* end of if statement */
  1472. if(::IsWindow(hwnd)){
  1473. ::MapWindowPoints(hwnd, ::GetDesktopWindow(), (LPPOINT)&rc, 2);
  1474. }/* end of if statement */
  1475. ::ClipCursor(&rc);
  1476. m_LastMouse.x = GET_X_LPARAM(lParam);
  1477. m_LastMouse.y = GET_Y_LPARAM(lParam);
  1478. if (m_pClipRect)
  1479. m_ClipRectDown = *m_pClipRect;
  1480. m_LastMouseDown = m_LastMouse;
  1481. if(!m_fDisableAutoMouseProcessing){
  1482. SelectAtPosition(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
  1483. }/* end of if statement */
  1484. }/* end of try statement */
  1485. catch(...){
  1486. }/* end of if statement */
  1487. bHandled = true;
  1488. return 0;
  1489. }/* end of function OnButtonDown */
  1490. /*************************************************************************/
  1491. /* Function: OnButtonUp */
  1492. /* Description: Activates the button. The problem is that when we move */
  1493. /* away from a button while holding left button down over some other */
  1494. /* button then the button we are under gets activated. What should happen*/
  1495. /* is that no button gets activated. */
  1496. /*************************************************************************/
  1497. LRESULT CMSWebDVD::OnButtonUp(UINT, WPARAM wParam, LPARAM lParam, BOOL& bHandled){
  1498. try {
  1499. if(!m_fInitialized){
  1500. return(0);
  1501. }/* end of if statement */
  1502. m_bMouseDown = FALSE;
  1503. ::ClipCursor(NULL);
  1504. if(!m_fDisableAutoMouseProcessing && m_nCursorType == dvdCursor_Arrow){
  1505. ActivateAtPosition(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
  1506. }
  1507. else if(m_nCursorType == dvdCursor_ZoomIn ||
  1508. m_nCursorType == dvdCursor_ZoomOut) {
  1509. // Compute new clipping top left corner
  1510. long x = GET_X_LPARAM(lParam);
  1511. long y = GET_Y_LPARAM(lParam);
  1512. POINT CenterPoint = {x, y};
  1513. if (m_bWndLess) {
  1514. RECT rc = {m_rcPos.left, m_rcPos.top, m_rcPos.right, m_rcPos.bottom};
  1515. HWND hwnd;
  1516. HRESULT hr = GetParentHWND(&hwnd);
  1517. if(FAILED(hr)){
  1518. return(hr);
  1519. }/* end of if statement */
  1520. if(::IsWindow(hwnd)){
  1521. ::MapWindowPoints(hwnd, ::GetDesktopWindow(), &CenterPoint, 1);
  1522. ::MapWindowPoints(hwnd, ::GetDesktopWindow(), (LPPOINT)&rc, 2);
  1523. }/* end of if statement */
  1524. x = CenterPoint.x - rc.left;
  1525. y = CenterPoint.y - rc.top;
  1526. }
  1527. CComPtr<IDVDRect> pDvdClipRect;
  1528. HRESULT hr = GetClipVideoRect(&pDvdClipRect);
  1529. if (FAILED(hr))
  1530. throw(hr);
  1531. // Get current clipping width and height
  1532. long clipWidth, clipHeight;
  1533. pDvdClipRect->get_Width(&clipWidth);
  1534. pDvdClipRect->get_Height(&clipHeight);
  1535. // Get current clipping top left corner
  1536. long clipX, clipY;
  1537. pDvdClipRect->get_x(&clipX);
  1538. pDvdClipRect->get_y(&clipY);
  1539. long newClipCenterX = x*clipWidth/RECTWIDTH(&m_rcPos) + clipX;
  1540. long newClipCenterY = y*clipHeight/RECTHEIGHT(&m_rcPos) + clipY;
  1541. if (m_nCursorType == dvdCursor_ZoomIn) {
  1542. Zoom(newClipCenterX, newClipCenterY, 2.0);
  1543. }
  1544. else if (m_nCursorType == dvdCursor_ZoomOut) {
  1545. Zoom(newClipCenterX, newClipCenterY, 0.5);
  1546. }/* end of if statement */
  1547. }
  1548. }/* end of try statement */
  1549. catch(...){
  1550. }/* end of if statement */
  1551. bHandled = true;
  1552. return 0;
  1553. }/* end of function OnButtonUp */
  1554. /*************************************************************************/
  1555. /* Function: OnMouseMove */
  1556. /* Description: Selects the button. */
  1557. /*************************************************************************/
  1558. LRESULT CMSWebDVD::OnMouseMove(UINT, WPARAM wParam, LPARAM lParam, BOOL& bHandled){
  1559. try {
  1560. if(!m_fInitialized){
  1561. return(0);
  1562. }/* end of if statement */
  1563. if(!m_fDisableAutoMouseProcessing && m_nCursorType == dvdCursor_Arrow){
  1564. SelectAtPosition(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
  1565. }
  1566. else if (m_bMouseDown && m_nCursorType == dvdCursor_Hand) {
  1567. CComPtr<IDVDRect> pDvdClipRect;
  1568. CComPtr<IDVDRect> pDvdRect;
  1569. HRESULT hr = GetVideoSize(&pDvdRect);
  1570. if (FAILED(hr))
  1571. throw(hr);
  1572. hr = GetClipVideoRect(&pDvdClipRect);
  1573. if (FAILED(hr))
  1574. throw(hr);
  1575. // Get video width and height
  1576. long videoWidth, videoHeight;
  1577. pDvdRect->get_Width(&videoWidth);
  1578. pDvdRect->get_Height(&videoHeight);
  1579. // Get clipping width and height;
  1580. long clipWidth, clipHeight;
  1581. pDvdClipRect->get_Width(&clipWidth);
  1582. pDvdClipRect->get_Height(&clipHeight);
  1583. if (!m_bWndLess) {
  1584. AdjustDestRC();
  1585. }/* end of if statement */
  1586. double scaleFactorX = clipWidth/(double)RECTWIDTH(&m_rcPosAspectRatioAjusted);
  1587. double scaleFactorY = clipHeight/(double)RECTHEIGHT(&m_rcPosAspectRatioAjusted);
  1588. long xAdjustment = (long) ((GET_X_LPARAM(lParam) - m_LastMouseDown.x)*scaleFactorX);
  1589. long yAdjustment = (long) ((GET_Y_LPARAM(lParam) - m_LastMouseDown.y)*scaleFactorY);
  1590. RECT clipRect = m_ClipRectDown;
  1591. ::OffsetRect(&clipRect, -xAdjustment, -yAdjustment);
  1592. if (clipRect.left<0)
  1593. ::OffsetRect(&clipRect, -clipRect.left, 0);
  1594. if (clipRect.top<0)
  1595. ::OffsetRect(&clipRect, 0, -clipRect.top);
  1596. if (clipRect.right>videoWidth)
  1597. ::OffsetRect(&clipRect, videoWidth-clipRect.right, 0);
  1598. if (clipRect.bottom>videoHeight)
  1599. ::OffsetRect(&clipRect, 0, videoHeight-clipRect.bottom);
  1600. //ATLTRACE(TEXT("SetClipVideoRect %d %d %d %d\n"),
  1601. // m_pClipRect->left, m_pClipRect->top, m_pClipRect->right, m_pClipRect->bottom);
  1602. pDvdClipRect->put_x(clipRect.left);
  1603. pDvdClipRect->put_y(clipRect.top);
  1604. hr = SetClipVideoRect(pDvdClipRect);
  1605. if (FAILED(hr))
  1606. throw(hr);
  1607. m_LastMouse.x = GET_X_LPARAM(lParam);
  1608. m_LastMouse.y = GET_Y_LPARAM(lParam);
  1609. }/* end of if statement */
  1610. }/* end of try statement */
  1611. catch(...){
  1612. }/* end of if statement */
  1613. bHandled = true;
  1614. return 0;
  1615. }/* end of function OnMouseMove */
  1616. /*************************************************************/
  1617. /* Function: OnSetCursor */
  1618. /* Description: Sets the cursor to what we want overwrite */
  1619. /* the default window proc. */
  1620. /*************************************************************/
  1621. LRESULT CMSWebDVD::OnSetCursor(UINT, WPARAM wParam, LPARAM lParam, BOOL& bHandled){
  1622. //ATLTRACE(TEXT("CMSWebDVD::OnSetCursor\n"));
  1623. if (m_hCursor && m_nCursorType != dvdCursor_None){
  1624. ::SetCursor(m_hCursor);
  1625. //ATLTRACE(TEXT("Actually setting the cursor OnSetCursor\n"));
  1626. return(TRUE);
  1627. }/* end of if statement */
  1628. bHandled = FALSE;
  1629. return 0;
  1630. }/* end of function OnSetCursor */
  1631. /*************************************************************************/
  1632. /* Function: get_TitlesAvailable */
  1633. /* Description: Gets the number of titles. */
  1634. /*************************************************************************/
  1635. STDMETHODIMP CMSWebDVD::get_TitlesAvailable(long *pVal){
  1636. HRESULT hr = S_OK;
  1637. try {
  1638. if(NULL == pVal){
  1639. throw(E_POINTER);
  1640. }/* end of if statement */
  1641. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1642. if(!m_pDvdInfo2){
  1643. throw(E_UNEXPECTED);
  1644. }/* end of if statement */
  1645. ULONG NumOfVol;
  1646. ULONG ThisVolNum;
  1647. DVD_DISC_SIDE Side;
  1648. ULONG TitleCount;
  1649. hr = m_pDvdInfo2->GetDVDVolumeInfo(&NumOfVol, &ThisVolNum, &Side, &TitleCount);
  1650. *pVal = (LONG) TitleCount;
  1651. }
  1652. catch(HRESULT hrTmp){
  1653. hr = hrTmp;
  1654. }/* end of catch statement */
  1655. catch(...){
  1656. hr = E_UNEXPECTED;
  1657. }/* end of catch statement */
  1658. return HandleError(hr);
  1659. }/* end of function get_TitlesAvailable */
  1660. /*************************************************************************/
  1661. /* Function: GetNumberChapterOfChapters */
  1662. /* Description: Returns the number of chapters in title. */
  1663. /*************************************************************************/
  1664. STDMETHODIMP CMSWebDVD::GetNumberOfChapters(long lTitle, long *pVal){
  1665. HRESULT hr = S_OK;
  1666. try {
  1667. if(NULL == pVal){
  1668. throw(E_POINTER);
  1669. }/* end of if statement */
  1670. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1671. if(!m_pDvdInfo2){
  1672. throw(E_UNEXPECTED);
  1673. }/* end of if statement */
  1674. hr = m_pDvdInfo2->GetNumberOfChapters(lTitle, (ULONG*)pVal);
  1675. }
  1676. catch(HRESULT hrTmp){
  1677. hr = hrTmp;
  1678. }/* end of catch statement */
  1679. catch(...){
  1680. hr = E_UNEXPECTED;
  1681. }/* end of catch statement */
  1682. return HandleError(hr);
  1683. }/* end of function GetNumberChapterOfChapters */
  1684. /*************************************************************************/
  1685. /* Function: get_FullScreenMode */
  1686. /* Description: Gets the current fullscreen mode. */
  1687. /*************************************************************************/
  1688. STDMETHODIMP CMSWebDVD::get_FullScreenMode(VARIANT_BOOL *pfFullScreenMode){
  1689. //TODO: handle the other cases when not having IVideoWindow
  1690. HRESULT hr = S_OK;
  1691. try {
  1692. if(NULL == pfFullScreenMode){
  1693. throw(E_POINTER);
  1694. }/* end of if statement */
  1695. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1696. IVideoWindow* pVW;
  1697. if(!m_pDvdGB){
  1698. return(E_UNEXPECTED);
  1699. }/* end of if statement */
  1700. hr = m_pDvdGB->GetDvdInterface(IID_IVideoWindow, (LPVOID *)&pVW) ;
  1701. if (SUCCEEDED(hr) && pVW != NULL){
  1702. long lMode;
  1703. hr = pVW->get_FullScreenMode(&lMode);
  1704. if(SUCCEEDED(hr)){
  1705. *pfFullScreenMode = ((lMode == OAFALSE) ? VARIANT_FALSE : VARIANT_TRUE);
  1706. }/* end of if statement */
  1707. pVW->Release();
  1708. }/* end of if statement */
  1709. }/* end of try statement */
  1710. catch(HRESULT hrTmp){
  1711. hr = hrTmp;
  1712. }/* end of catch statement */
  1713. catch(...){
  1714. hr = E_UNEXPECTED;
  1715. }/* end of catch statement */
  1716. return HandleError(hr);
  1717. }/* end of function get_FullScreenMode */
  1718. /*************************************************************************/
  1719. /* Function: put_FullScreenMode */
  1720. /* Description: Sets the full screen mode. */
  1721. /*************************************************************************/
  1722. STDMETHODIMP CMSWebDVD::put_FullScreenMode(VARIANT_BOOL fFullScreenMode){
  1723. HRESULT hr = S_OK;
  1724. try {
  1725. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1726. IVideoWindow* pVW;
  1727. if(!m_pDvdGB){
  1728. return(E_UNEXPECTED);
  1729. }/* end of if statement */
  1730. hr = m_pDvdGB->GetDvdInterface(IID_IVideoWindow, (LPVOID *)&pVW) ;
  1731. if (SUCCEEDED(hr) && pVW != NULL){
  1732. hr = pVW->put_FullScreenMode(fFullScreenMode);
  1733. pVW->Release();
  1734. }/* end of if statement */
  1735. }/* end of try statement */
  1736. catch(HRESULT hrTmp){
  1737. hr = hrTmp;
  1738. }/* end of catch statement */
  1739. catch(...){
  1740. hr = E_UNEXPECTED;
  1741. }/* end of catch statement */
  1742. return HandleError(hr);
  1743. }/* end of function put_FullScreenMode */
  1744. /*************************************************************************/
  1745. /* Function: SetDDrawExcl */
  1746. /* Descirption: Sets up Overlays Mixer DDraw interface. That way we avoid*/
  1747. /* drawing using IVideo Window and the control, can be windowless. */
  1748. /*************************************************************************/
  1749. HRESULT CMSWebDVD::SetDDrawExcl(){
  1750. HRESULT hr = S_OK;
  1751. HWND hwndBrowser = NULL;
  1752. hr = GetParentHWND(&hwndBrowser);
  1753. if(FAILED(hr)){
  1754. return(hr);
  1755. }/* end of if statement */
  1756. if(hwndBrowser == NULL){
  1757. hr = E_POINTER;
  1758. return(E_POINTER);
  1759. }/* end of if statement */
  1760. HDC hDC = ::GetWindowDC(hwndBrowser);
  1761. if(hDC == NULL){
  1762. hr = E_UNEXPECTED;
  1763. return(hr);
  1764. }/* end of if statement */
  1765. LPDIRECTDRAW pDDraw = NULL;
  1766. hr = DirectDrawCreate(NULL, &pDDraw, NULL);
  1767. if(FAILED(hr)){
  1768. ::ReleaseDC(hwndBrowser, hDC);
  1769. return(hr);
  1770. }/* end of if statement */
  1771. LPDIRECTDRAW4 pDDraw4 = NULL;
  1772. hr = pDDraw->QueryInterface(IID_IDirectDraw4, (LPVOID*)&pDDraw4);
  1773. pDDraw->Release();
  1774. if(FAILED(hr)){
  1775. ::ReleaseDC(hwndBrowser, hDC);
  1776. return(hr);
  1777. }/* end of if statement */
  1778. LPDIRECTDRAWSURFACE4 pDDS4 = NULL;
  1779. pDDraw4->GetSurfaceFromDC(hDC, &pDDS4);
  1780. pDDraw4->Release();
  1781. ::ReleaseDC(hwndBrowser, hDC);
  1782. if(FAILED(hr)){
  1783. return(hr);
  1784. }/* end of if statement */
  1785. LPDIRECTDRAW4 pDDrawIE = NULL;
  1786. hr = pDDS4->GetDDInterface((LPVOID*)&pDDrawIE);
  1787. pDDS4->Release();
  1788. pDDrawIE->Release();
  1789. return HandleError(hr);
  1790. }/* end of function SetDDrawExcl */
  1791. /*************************************************************************/
  1792. /* Function: PlayBackwards */
  1793. /* Description: Rewind, set to play state to start with. */
  1794. /*************************************************************************/
  1795. STDMETHODIMP CMSWebDVD::PlayBackwards(double dSpeed, VARIANT_BOOL fDoNotReset){
  1796. HRESULT hr = S_OK;
  1797. try {
  1798. if(VARIANT_FALSE != fDoNotReset){
  1799. m_fResetSpeed = false;
  1800. }/* end of if statement */
  1801. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY
  1802. m_fResetSpeed = true;
  1803. if(!m_pDvdCtl2){
  1804. throw(E_UNEXPECTED);
  1805. }/* end of if statement */
  1806. RETRY_IF_IN_FPDOM(m_pDvdCtl2->PlayBackwards(dSpeed,0,0));
  1807. }/* end of try statement */
  1808. catch(HRESULT hrTmp){
  1809. hr = hrTmp;
  1810. }/* end of catch statement */
  1811. catch(...){
  1812. hr = E_UNEXPECTED;
  1813. }/* end of catch statement */
  1814. return HandleError(hr);
  1815. }/* end of function BackwardScan */
  1816. /*************************************************************************/
  1817. /* Function: PlayForwards */
  1818. /* Description: Set DVD in fast forward mode. */
  1819. /*************************************************************************/
  1820. STDMETHODIMP CMSWebDVD::PlayForwards(double dSpeed, VARIANT_BOOL fDoNotReset){
  1821. HRESULT hr = S_OK;
  1822. try {
  1823. if(VARIANT_FALSE != fDoNotReset){
  1824. m_fResetSpeed = false;
  1825. }/* end of if statement */
  1826. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY
  1827. m_fResetSpeed = true;
  1828. if(!m_pDvdCtl2){
  1829. throw(E_UNEXPECTED);
  1830. }/* end of if statement */
  1831. RETRY_IF_IN_FPDOM(m_pDvdCtl2->PlayForwards(dSpeed,0,0));
  1832. }/* end of try statement */
  1833. catch(HRESULT hrTmp){
  1834. hr = hrTmp;
  1835. }/* end of catch statement */
  1836. catch(...){
  1837. hr = E_UNEXPECTED;
  1838. }/* end of catch statement */
  1839. return HandleError(hr);
  1840. }/* end of function PlayForwards */
  1841. /*************************************************************************/
  1842. /* Function: Resume */
  1843. /* Description: Resume from menu. We put our self in play state, just */
  1844. /* in the case we were not in it. This might lead to some unexpected */
  1845. /* behavior in case when we stopped and the tried to hit this button */
  1846. /* but I think in this case might be appropriate as well. */
  1847. /*************************************************************************/
  1848. STDMETHODIMP CMSWebDVD::Resume(){
  1849. HRESULT hr = S_OK;
  1850. try {
  1851. hr = Play(); // put in the play mode
  1852. if(FAILED(hr)){
  1853. throw(hr);
  1854. }/* end of if statement */
  1855. if(!m_pDvdCtl2){
  1856. throw(E_UNEXPECTED);
  1857. }/* end of if statement */
  1858. hr = m_pDvdCtl2->Resume(cdwDVDCtrlFlags, 0);
  1859. }/* end of try statement */
  1860. catch(HRESULT hrTmp){
  1861. hr = hrTmp;
  1862. }/* end of catch statement */
  1863. catch(...){
  1864. hr = E_UNEXPECTED;
  1865. }/* end of catch statement */
  1866. return HandleError(hr);
  1867. }/* end of function Resume */
  1868. /*************************************************************************/
  1869. /* Function: ShowMenu */
  1870. /* Description: Invokes specific menu call. */
  1871. /* We set our selfs to play mode so we can execute this in case we were */
  1872. /* paused or stopped. */
  1873. /*************************************************************************/
  1874. STDMETHODIMP CMSWebDVD::ShowMenu(DVDMenuIDConstants MenuID){
  1875. HRESULT hr = S_OK;
  1876. try {
  1877. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY
  1878. if(!m_pDvdCtl2){
  1879. throw(E_UNEXPECTED);
  1880. }/* end of if statement */
  1881. RETRY_IF_IN_FPDOM(m_pDvdCtl2->ShowMenu((tagDVD_MENU_ID)MenuID, cdwDVDCtrlFlags, 0)); //!!keep in sync, or this cast will not work
  1882. }/* end of try statement */
  1883. catch(HRESULT hrTmp){
  1884. hr = hrTmp;
  1885. }/* end of catch statement */
  1886. catch(...){
  1887. hr = E_UNEXPECTED;
  1888. }/* end of catch statement */
  1889. return HandleError(hr);
  1890. }/* end of function MenuCall */
  1891. /*************************************************************************/
  1892. /* Function: get_PlayState */
  1893. /* Description: Needs to be expanded for DVD, using their base APIs, */
  1894. /* get DVD specific states as well. */
  1895. /*************************************************************************/
  1896. STDMETHODIMP CMSWebDVD::get_PlayState(DVDFilterState *pFilterState){
  1897. HRESULT hr = S_OK;
  1898. try {
  1899. if (NULL == pFilterState){
  1900. throw(E_POINTER);
  1901. }/* end of if statement */
  1902. if(!m_fInitialized){
  1903. *pFilterState = dvdState_Unitialized;
  1904. return(hr);
  1905. }/* end of if statement */
  1906. if(!m_pMC){
  1907. throw(E_UNEXPECTED);
  1908. }/* end of if statement */
  1909. OAFilterState fs;
  1910. hr = m_pMC->GetState(cgStateTimeout, &fs);
  1911. *pFilterState = (DVDFilterState)fs; // !!keep in sync, or this cast will not work
  1912. }/* end of try statement */
  1913. catch(HRESULT hrTmp){
  1914. hr = hrTmp;
  1915. }/* end of catch statement */
  1916. catch(...){
  1917. hr = E_UNEXPECTED;
  1918. }/* end of catch statement */
  1919. return HandleError(hr);
  1920. }/* end of get_PlayState */
  1921. /*************************************************************************/
  1922. /* Function: SelectUpperButton */
  1923. /* Description: Selects the upper button on DVD Menu. */
  1924. /*************************************************************************/
  1925. STDMETHODIMP CMSWebDVD::SelectUpperButton(){
  1926. HRESULT hr = S_OK;
  1927. try {
  1928. hr = Play(); // put in the play mode
  1929. if(FAILED(hr)){
  1930. throw(hr);
  1931. }/* end of if statement */
  1932. if(!m_pDvdCtl2){
  1933. throw(E_UNEXPECTED);
  1934. }/* end of if statement */
  1935. hr = m_pDvdCtl2->SelectRelativeButton(DVD_Relative_Upper);
  1936. }/* end of try statement */
  1937. catch(HRESULT hrTmp){
  1938. hr = hrTmp;
  1939. }/* end of catch statement */
  1940. catch(...){
  1941. hr = E_UNEXPECTED;
  1942. }/* end of catch statement */
  1943. return HandleError(hr);
  1944. }/* end of function SelectUpperButton */
  1945. /*************************************************************************/
  1946. /* Function: SelectLowerButton */
  1947. /* Description: Selects the lower button on DVD Menu. */
  1948. /*************************************************************************/
  1949. STDMETHODIMP CMSWebDVD::SelectLowerButton(){
  1950. HRESULT hr = S_OK;
  1951. try {
  1952. hr = Play(); // put in the play mode
  1953. if(FAILED(hr)){
  1954. throw(hr);
  1955. }/* end of if statement */
  1956. if(!m_pDvdCtl2){
  1957. throw(E_UNEXPECTED);
  1958. }/* end of if statement */
  1959. hr = m_pDvdCtl2->SelectRelativeButton(DVD_Relative_Lower);
  1960. }/* end of try statement */
  1961. catch(HRESULT hrTmp){
  1962. hr = hrTmp;
  1963. }/* end of catch statement */
  1964. catch(...){
  1965. hr = E_UNEXPECTED;
  1966. }/* end of catch statement */
  1967. return HandleError(hr);
  1968. }/* end of function SelectLowerButton */
  1969. /*************************************************************************/
  1970. /* Function: SelectLeftButton */
  1971. /* Description: Selects the left button on DVD Menu. */
  1972. /*************************************************************************/
  1973. STDMETHODIMP CMSWebDVD::SelectLeftButton(){
  1974. HRESULT hr = S_OK;
  1975. try {
  1976. hr = Play(); // put in the play mode
  1977. if(FAILED(hr)){
  1978. throw(hr);
  1979. }/* end of if statement */
  1980. if(!m_pDvdCtl2){
  1981. throw(E_UNEXPECTED);
  1982. }/* end of if statement */
  1983. hr = m_pDvdCtl2->SelectRelativeButton(DVD_Relative_Left);
  1984. }/* end of try statement */
  1985. catch(HRESULT hrTmp){
  1986. hr = hrTmp;
  1987. }/* end of catch statement */
  1988. catch(...){
  1989. hr = E_UNEXPECTED;
  1990. }/* end of catch statement */
  1991. return HandleError(hr);
  1992. }/* end of function SelectLeftButton */
  1993. /*************************************************************************/
  1994. /* Function: SelectRightButton */
  1995. /* Description: Selects the right button on DVD Menu. */
  1996. /*************************************************************************/
  1997. STDMETHODIMP CMSWebDVD::SelectRightButton(){
  1998. HRESULT hr = S_OK;
  1999. try {
  2000. hr = Play(); // put in the play mode
  2001. if(FAILED(hr)){
  2002. throw(hr);
  2003. }/* end of if statement */
  2004. if(!m_pDvdCtl2){
  2005. throw(E_UNEXPECTED);
  2006. }/* end of if statement */
  2007. hr = m_pDvdCtl2->SelectRelativeButton(DVD_Relative_Right);
  2008. }/* end of try statement */
  2009. catch(HRESULT hrTmp){
  2010. hr = hrTmp;
  2011. }/* end of catch statement */
  2012. catch(...){
  2013. hr = E_UNEXPECTED;
  2014. }/* end of catch statement */
  2015. return HandleError(hr);
  2016. }/* end of function SelectRightButton */
  2017. /*************************************************************************/
  2018. /* Function: ActivateButton */
  2019. /* Description: Activates the selected button on DVD Menu. */
  2020. /*************************************************************************/
  2021. STDMETHODIMP CMSWebDVD::ActivateButton(){
  2022. HRESULT hr = S_OK;
  2023. try {
  2024. hr = Play(); // put in the play mode
  2025. if(FAILED(hr)){
  2026. throw(hr);
  2027. }/* end of if statement */
  2028. if(!m_pDvdCtl2){
  2029. throw(E_UNEXPECTED);
  2030. }/* end of if statement */
  2031. hr = m_pDvdCtl2->ActivateButton();
  2032. }/* end of try statement */
  2033. catch(HRESULT hrTmp){
  2034. hr = hrTmp;
  2035. }/* end of catch statement */
  2036. catch(...){
  2037. hr = E_UNEXPECTED;
  2038. }/* end of catch statement */
  2039. return HandleError(hr);
  2040. }/* end of function ActivateButton */
  2041. /*************************************************************************/
  2042. /* Function: SelectAndActivateButton */
  2043. /* Description: Selects and activates the specific button. */
  2044. /*************************************************************************/
  2045. STDMETHODIMP CMSWebDVD::SelectAndActivateButton(long lButton){
  2046. HRESULT hr = S_OK;
  2047. try {
  2048. hr = Play(); // put in the play mode
  2049. if(FAILED(hr)){
  2050. throw(hr);
  2051. }
  2052. if(lButton < 0){
  2053. throw(E_INVALIDARG);
  2054. }
  2055. if( !m_pDvdCtl2){
  2056. throw(E_UNEXPECTED);
  2057. }
  2058. hr = m_pDvdCtl2->SelectAndActivateButton((ULONG)lButton);
  2059. }
  2060. catch(HRESULT hrTmp){
  2061. hr = hrTmp;
  2062. }
  2063. catch(...){
  2064. hr = E_UNEXPECTED;
  2065. }
  2066. return HandleError(hr);
  2067. }/* end of function SelectAndActivateButton */
  2068. /*************************************************************************/
  2069. /* Function: PlayNextChapter */
  2070. /* Description: Goes to next chapter */
  2071. /*************************************************************************/
  2072. STDMETHODIMP CMSWebDVD::PlayNextChapter(){
  2073. HRESULT hr = S_OK;
  2074. try {
  2075. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY
  2076. if(!m_pDvdCtl2){
  2077. throw(E_UNEXPECTED);
  2078. }/* end of if statement */
  2079. RETRY_IF_IN_FPDOM(m_pDvdCtl2->PlayNextChapter(cdwDVDCtrlFlags, 0));
  2080. }/* end of try statement */
  2081. catch(HRESULT hrTmp){
  2082. hr = hrTmp;
  2083. }/* end of catch statement */
  2084. catch(...){
  2085. hr = E_UNEXPECTED;
  2086. }/* end of catch statement */
  2087. return HandleError(hr);
  2088. }/* end of function PlayNextChapter */
  2089. /*************************************************************************/
  2090. /* Function: PlayPrevChapter */
  2091. /* Description: Goes to previous chapter */
  2092. /*************************************************************************/
  2093. STDMETHODIMP CMSWebDVD::PlayPrevChapter(){
  2094. HRESULT hr = S_OK;
  2095. try {
  2096. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY
  2097. if(!m_pDvdCtl2){
  2098. throw(E_UNEXPECTED);
  2099. }/* end of if statement */
  2100. RETRY_IF_IN_FPDOM(m_pDvdCtl2->PlayPrevChapter(cdwDVDCtrlFlags, 0));
  2101. }/* end of try statement */
  2102. catch(HRESULT hrTmp){
  2103. hr = hrTmp;
  2104. }/* end of catch statement */
  2105. catch(...){
  2106. hr = E_UNEXPECTED;
  2107. }/* end of catch statement */
  2108. return HandleError(hr);
  2109. }/* end of function PlayPrevChapter */
  2110. /*************************************************************************/
  2111. /* Function: ReplayChapter */
  2112. /* Description: Halts playback and restarts the playback of current */
  2113. /* program inside PGC. */
  2114. /*************************************************************************/
  2115. STDMETHODIMP CMSWebDVD::ReplayChapter(){
  2116. HRESULT hr = S_OK;
  2117. try {
  2118. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY
  2119. if(!m_pDvdCtl2){
  2120. throw(E_UNEXPECTED);
  2121. }/* end of if statement */
  2122. RETRY_IF_IN_FPDOM(m_pDvdCtl2->ReplayChapter(cdwDVDCtrlFlags, 0));
  2123. }/* end of try statement */
  2124. catch(HRESULT hrTmp){
  2125. hr = hrTmp;
  2126. }/* end of catch statement */
  2127. catch(...){
  2128. hr = E_UNEXPECTED;
  2129. }/* end of catch statement */
  2130. return HandleError(hr);
  2131. }/* end of function ReplayChapter */
  2132. /*************************************************************************/
  2133. /* Function: Return */
  2134. /* Description: Used in menu to return into prevoius menu. */
  2135. /*************************************************************************/
  2136. STDMETHODIMP CMSWebDVD::ReturnFromSubmenu(){
  2137. HRESULT hr = S_OK;
  2138. try {
  2139. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY
  2140. if(!m_pDvdCtl2){
  2141. throw(E_UNEXPECTED);
  2142. }/* end of if statement */
  2143. RETRY_IF_IN_FPDOM(m_pDvdCtl2->ReturnFromSubmenu(cdwDVDCtrlFlags, 0));
  2144. }/* end of try statement */
  2145. catch(HRESULT hrTmp){
  2146. hr = hrTmp;
  2147. }/* end of catch statement */
  2148. catch(...){
  2149. hr = E_UNEXPECTED;
  2150. }/* end of catch statement */
  2151. return HandleError(hr);
  2152. }/* end of function Return */
  2153. /*************************************************************************/
  2154. /* Function: PlayChapter */
  2155. /* Description: Does chapter search. Waits for FP_DOM to pass and initi */
  2156. /* lizes the graph as the other smar routines. */
  2157. /*************************************************************************/
  2158. STDMETHODIMP CMSWebDVD::PlayChapter(LONG lChapter){
  2159. HRESULT hr = S_OK;
  2160. try {
  2161. if(lChapter < 0){
  2162. throw(E_INVALIDARG);
  2163. }/* end of if statement */
  2164. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY
  2165. if(!m_pDvdCtl2){
  2166. throw(E_UNEXPECTED);
  2167. }/* end of if statement */
  2168. RETRY_IF_IN_FPDOM(m_pDvdCtl2->PlayChapter(lChapter, cdwDVDCtrlFlags, 0));
  2169. }/* end of try statement */
  2170. catch(HRESULT hrTmp){
  2171. hr = hrTmp;
  2172. }/* end of catch statement */
  2173. catch(...){
  2174. hr = E_UNEXPECTED;
  2175. }/* end of catch statement */
  2176. return HandleError(hr);
  2177. }/* end of function PlayChapter */
  2178. /*************************************************************************/
  2179. /* Function: GetAudioLanguage */
  2180. /* Description: Returns audio language associated with a stream. */
  2181. /*************************************************************************/
  2182. STDMETHODIMP CMSWebDVD::GetAudioLanguage(LONG lStream, VARIANT_BOOL fFormat, BSTR *strAudioLang){
  2183. HRESULT hr = S_OK;
  2184. LPTSTR pszString = NULL;
  2185. try {
  2186. if(NULL == strAudioLang){
  2187. throw(E_POINTER);
  2188. }/* end of if statement */
  2189. if(lStream < 0){
  2190. throw(E_INVALIDARG);
  2191. }/* end of if statement */
  2192. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2193. if(!m_pDvdInfo2){
  2194. throw(E_UNEXPECTED);
  2195. }/* end of if statement */
  2196. USES_CONVERSION;
  2197. LCID lcid;
  2198. hr = m_pDvdInfo2->GetAudioLanguage(lStream, &lcid);
  2199. if (SUCCEEDED( hr )){
  2200. // count up the streams for the same LCID like English 2
  2201. pszString = m_LangID.GetLangFromLangID((WORD)PRIMARYLANGID(LANGIDFROMLCID(lcid)));
  2202. if (pszString == NULL) {
  2203. pszString = new TCHAR[MAX_PATH];
  2204. TCHAR strBuffer[MAX_PATH];
  2205. if(!::LoadString(_Module.m_hInstResource, IDS_AUDIOTRACK, strBuffer, MAX_PATH)){
  2206. delete[] pszString;
  2207. throw(E_UNEXPECTED);
  2208. }/* end of if statement */
  2209. StringCchPrintf(pszString, MAX_PATH, strBuffer, lStream);
  2210. }/* end of if statement */
  2211. DVD_AudioAttributes attr;
  2212. if(SUCCEEDED(m_pDvdInfo2->GetAudioAttributes(lStream, &attr))){
  2213. // If want audio format param is set
  2214. if (fFormat != VARIANT_FALSE) {
  2215. switch(attr.AudioFormat){
  2216. case DVD_AudioFormat_AC3: AppendString(pszString, IDS_DOLBY, MAX_PATH ); break;
  2217. case DVD_AudioFormat_MPEG1: AppendString(pszString, IDS_MPEG1, MAX_PATH ); break;
  2218. case DVD_AudioFormat_MPEG1_DRC: AppendString(pszString, IDS_MPEG1, MAX_PATH ); break;
  2219. case DVD_AudioFormat_MPEG2: AppendString(pszString, IDS_MPEG2, MAX_PATH ); break;
  2220. case DVD_AudioFormat_MPEG2_DRC: AppendString(pszString, IDS_MPEG2, MAX_PATH); break;
  2221. case DVD_AudioFormat_LPCM: AppendString(pszString, IDS_LPCM, MAX_PATH ); break;
  2222. case DVD_AudioFormat_DTS: AppendString(pszString, IDS_DTS, MAX_PATH ); break;
  2223. case DVD_AudioFormat_SDDS: AppendString(pszString, IDS_SDDS, MAX_PATH ); break;
  2224. }/* end of switch statement */
  2225. }
  2226. switch(attr.LanguageExtension){
  2227. case DVD_AUD_EXT_NotSpecified:
  2228. case DVD_AUD_EXT_Captions: break; // do not add anything
  2229. case DVD_AUD_EXT_VisuallyImpaired: AppendString(pszString, IDS_AUDIO_VISUALLY_IMPAIRED, MAX_PATH ); break;
  2230. case DVD_AUD_EXT_DirectorComments1: AppendString(pszString, IDS_AUDIO_DIRC1, MAX_PATH ); break;
  2231. case DVD_AUD_EXT_DirectorComments2: AppendString(pszString, IDS_AUDIO_DIRC2, MAX_PATH ); break;
  2232. }/* end of switch statement */
  2233. }/* end of if statement */
  2234. *strAudioLang = ::SysAllocString( T2W(pszString) );
  2235. delete[] pszString;
  2236. pszString = NULL;
  2237. }
  2238. else {
  2239. *strAudioLang = ::SysAllocString( L"");
  2240. // hr used to be not failed and return nothing
  2241. if(SUCCEEDED(hr)) // remove this after gets fixed in DVDNav
  2242. hr = E_FAIL;
  2243. }/* end of if statement */
  2244. }/* end of try statement */
  2245. catch(HRESULT hrTmp){
  2246. if (pszString) {
  2247. delete[] pszString;
  2248. pszString = NULL;
  2249. }
  2250. hr = hrTmp;
  2251. }/* end of catch statement */
  2252. catch(...){
  2253. if (pszString) {
  2254. delete[] pszString;
  2255. pszString = NULL;
  2256. }
  2257. hr = E_UNEXPECTED;
  2258. }/* end of catch statement */
  2259. return HandleError(hr);
  2260. }/* end of function GetAudioLanguage */
  2261. /*************************************************************************/
  2262. /* Function: StillOff */
  2263. /* Description: Turns the still off, what that can be used for is a */
  2264. /* mistery to me. */
  2265. /*************************************************************************/
  2266. STDMETHODIMP CMSWebDVD::StillOff(){
  2267. if(!m_pDvdCtl2){
  2268. return E_UNEXPECTED;
  2269. }/* end of if statement */
  2270. return HandleError(m_pDvdCtl2->StillOff());
  2271. }/* end of function StillOff */
  2272. /*************************************************************************/
  2273. /* Function: PlayTitle */
  2274. /* Description: If fails waits for FP_DOM to pass and tries later. */
  2275. /*************************************************************************/
  2276. STDMETHODIMP CMSWebDVD::PlayTitle(LONG lTitle){
  2277. HRESULT hr = S_OK;
  2278. try {
  2279. if(0 > lTitle){
  2280. throw(E_INVALIDARG);
  2281. }/* end of if statement */
  2282. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY
  2283. if(!m_pDvdCtl2){
  2284. throw(E_UNEXPECTED);
  2285. }/* end of if statement */
  2286. long lNumTitles = 0;
  2287. hr = get_TitlesAvailable(&lNumTitles);
  2288. if(FAILED(hr)){
  2289. throw hr;
  2290. }
  2291. if(lTitle > lNumTitles){
  2292. throw E_INVALIDARG;
  2293. }
  2294. RETRY_IF_IN_FPDOM(m_pDvdCtl2->PlayTitle(lTitle, cdwDVDCtrlFlags, 0));
  2295. }/* end of try statement */
  2296. catch(HRESULT hrTmp){
  2297. hr = hrTmp;
  2298. }/* end of catch statement */
  2299. catch(...){
  2300. hr = E_UNEXPECTED;
  2301. }/* end of catch statement */
  2302. return HandleError(hr);
  2303. }/* end of function PlayTitle */
  2304. /*************************************************************************/
  2305. /* Function: GetSubpictureLanguage */
  2306. /* Description: Gets subpicture language. */
  2307. /*************************************************************************/
  2308. STDMETHODIMP CMSWebDVD::GetSubpictureLanguage(LONG lStream, BSTR* strSubpictLang){
  2309. HRESULT hr = S_OK;
  2310. LPTSTR pszString = NULL;
  2311. try {
  2312. if(NULL == strSubpictLang){
  2313. throw(E_POINTER);
  2314. }/* end of if statement */
  2315. if(0 > lStream){
  2316. throw(E_INVALIDARG);
  2317. }/* end of if statement */
  2318. if((lStream > cgDVD_MAX_SUBPICTURE
  2319. && lStream != cgDVD_ALT_SUBPICTURE)){
  2320. throw(E_INVALIDARG);
  2321. }/* end of if statement */
  2322. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2323. if(!m_pDvdInfo2){
  2324. throw(E_UNEXPECTED);
  2325. }/* end of if statement */
  2326. LCID lcid;
  2327. hr = m_pDvdInfo2->GetSubpictureLanguage(lStream, &lcid);
  2328. if (SUCCEEDED( hr )){
  2329. pszString = m_LangID.GetLangFromLangID((WORD)PRIMARYLANGID(LANGIDFROMLCID(lcid)));
  2330. if (pszString == NULL) {
  2331. pszString = new TCHAR[MAX_PATH];
  2332. TCHAR strBuffer[MAX_PATH];
  2333. if(!::LoadString(_Module.m_hInstResource, IDS_SUBPICTURETRACK, strBuffer, MAX_PATH)){
  2334. delete[] pszString;
  2335. throw(E_UNEXPECTED);
  2336. }/* end of if statement */
  2337. StringCchPrintf(pszString, MAX_PATH, strBuffer, lStream);
  2338. }/* end of if statement */
  2339. #if 0
  2340. DVD_SubpictureATR attr;
  2341. if(SUCCEEDED(m_pDvdInfo2->GetSubpictureAttributes(lStream, &attr))){
  2342. switch(attr){
  2343. case DVD_SP_EXT_NotSpecified:
  2344. case DVD_SP_EXT_Caption_Normal: break;
  2345. case DVD_SP_EXT_Caption_Big: AppendString(pszString, IDS_CAPTION_BIG, MAX_PATH ); break;
  2346. case DVD_SP_EXT_Caption_Children: AppendString(pszString, IDS_CAPTION_CHILDREN, MAX_PATH ); break;
  2347. case DVD_SP_EXT_CC_Normal: AppendString(pszString, IDS_CLOSED_CAPTION, MAX_PATH ); break;
  2348. case DVD_SP_EXT_CC_Big: AppendString(pszString, IDS_CLOSED_CAPTION_BIG, MAX_PATH ); break;
  2349. case DVD_SP_EXT_CC_Children: AppendString(pszString, IDS_CLOSED_CAPTION_CHILDREN, MAX_PATH ); break;
  2350. case DVD_SP_EXT_Forced: AppendString(pszString, IDS_CLOSED_CAPTION_FORCED, MAX_PATH ); break;
  2351. case DVD_SP_EXT_DirectorComments_Normal: AppendString(pszString, IDS_DIRS_COMMNETS, MAX_PATH ); break;
  2352. case DVD_SP_EXT_DirectorComments_Big: AppendString(pszString, IDS_DIRS_COMMNETS_BIG, MAX_PATH ); break;
  2353. case DVD_SP_EXT_DirectorComments_Children: AppendString(pszString, IDS_DIRS_COMMNETS_CHILDREN, MAX_PATH ); break;
  2354. }/* end of switch statement */
  2355. #endif
  2356. USES_CONVERSION;
  2357. *strSubpictLang = ::SysAllocString( T2W(pszString) );
  2358. delete[] pszString;
  2359. pszString = NULL;
  2360. }
  2361. else {
  2362. *strSubpictLang = ::SysAllocString( L"");
  2363. // hr used to be not failed and return nothing
  2364. if(SUCCEEDED(hr)) // remove this after gets fixed in DVDNav
  2365. hr = E_FAIL;
  2366. }/* end of if statement */
  2367. }/* end of try statement */
  2368. catch(HRESULT hrTmp){
  2369. if (pszString) {
  2370. delete[] pszString;
  2371. pszString = NULL;
  2372. }
  2373. hr = hrTmp;
  2374. }/* end of catch statement */
  2375. catch(...){
  2376. if (pszString) {
  2377. delete[] pszString;
  2378. pszString = NULL;
  2379. }
  2380. hr = E_UNEXPECTED;
  2381. }/* end of catch statement */
  2382. return HandleError(hr);
  2383. }/* end of function GetSubpictureLanguage */
  2384. /*************************************************************************/
  2385. /* Function: PlayChapterInTitle */
  2386. /* Description: Plays from the specified chapter without stopping */
  2387. /* THIS NEEDS TO BE ENHANCED !!! Current implementation and queing */
  2388. /* into the message loop is insufficient!!! TODO. */
  2389. /*************************************************************************/
  2390. STDMETHODIMP CMSWebDVD::PlayChapterInTitle(LONG lTitle, LONG lChapter){
  2391. HRESULT hr = S_OK;
  2392. try {
  2393. if ((lTitle > cgDVDMAX_TITLE_COUNT) || (lTitle < cgDVDMIN_TITLE_COUNT)){
  2394. throw(E_INVALIDARG);
  2395. }/* end of if statement */
  2396. if ((lChapter > cgDVDMAX_CHAPTER_COUNT) || (lChapter < cgDVDMIN_CHAPTER_COUNT)){
  2397. throw(E_INVALIDARG);
  2398. }/* end of if statement */
  2399. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY
  2400. if(!m_pDvdCtl2){
  2401. throw(E_UNEXPECTED);
  2402. }/* end of if statement */
  2403. RETRY_IF_IN_FPDOM(m_pDvdCtl2->PlayChapterInTitle(lTitle, lChapter, cdwDVDCtrlFlags, 0));
  2404. }/* end of try statement */
  2405. catch(HRESULT hrTmp){
  2406. hr = hrTmp;
  2407. }
  2408. catch(...){
  2409. hr = E_UNEXPECTED;
  2410. }/* end of catch statement */
  2411. return HandleError(hr);
  2412. }/* end of function PlayChapterInTitle */
  2413. /*************************************************************************/
  2414. /* Function: PlayChapterAutoStop */
  2415. /* Description: Plays set ammount of chapters. */
  2416. /*************************************************************************/
  2417. STDMETHODIMP CMSWebDVD::PlayChaptersAutoStop(LONG lTitle, LONG lChapter,
  2418. LONG lChapterCount){
  2419. HRESULT hr = S_OK;
  2420. try {
  2421. if ((lTitle > cgDVDMAX_TITLE_COUNT) || (lTitle < cgDVDMIN_TITLE_COUNT)){
  2422. throw(E_INVALIDARG);
  2423. }/* end of if statement */
  2424. if ((lChapter > cgDVDMAX_CHAPTER_COUNT) || (lChapter < cgDVDMIN_CHAPTER_COUNT)){
  2425. throw(E_INVALIDARG);
  2426. }/* end of if statement */
  2427. if ((lChapterCount > cgDVDMAX_CHAPTER_COUNT) || (lChapterCount < cgDVDMIN_CHAPTER_COUNT)){
  2428. throw(E_INVALIDARG);
  2429. }/* end of if statement */
  2430. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY
  2431. if(!m_pDvdCtl2){
  2432. throw(E_UNEXPECTED);
  2433. }/* end of if statement */
  2434. RETRY_IF_IN_FPDOM(m_pDvdCtl2->PlayChaptersAutoStop(lTitle, lChapter, lChapterCount, cdwDVDCtrlFlags, 0));
  2435. }/* end of try statement */
  2436. catch(HRESULT hrTmp){
  2437. hr = hrTmp;
  2438. }
  2439. catch(...){
  2440. hr = E_UNEXPECTED;
  2441. }/* end of catch statement */
  2442. return HandleError(hr);
  2443. }/* end of function PlayChaptersAutoStop */
  2444. /*************************************************************************/
  2445. /* Function: PlayPeriodInTitleAutoStop */
  2446. /* Description: Time plays, converts from hh:mm:ss:ff format */
  2447. /*************************************************************************/
  2448. STDMETHODIMP CMSWebDVD::PlayPeriodInTitleAutoStop(long lTitle,
  2449. BSTR strStartTime, BSTR strEndTime){
  2450. HRESULT hr = S_OK;
  2451. try {
  2452. if(NULL == strStartTime){
  2453. throw(E_POINTER);
  2454. }/* end of if statement */
  2455. if(NULL == strEndTime){
  2456. throw(E_POINTER);
  2457. }/* end of if statement */
  2458. DVD_HMSF_TIMECODE tcStartTimeCode;
  2459. hr = Bstr2DVDTime(&tcStartTimeCode, &strStartTime);
  2460. if(FAILED(hr)){
  2461. throw (hr);
  2462. }
  2463. DVD_HMSF_TIMECODE tcEndTimeCode;
  2464. Bstr2DVDTime(&tcEndTimeCode, &strEndTime);
  2465. if(FAILED(hr)){
  2466. throw(hr);
  2467. }/* end of if statement */
  2468. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY
  2469. if(!m_pDvdCtl2){
  2470. throw(E_UNEXPECTED);
  2471. }/* end of if statement */
  2472. RETRY_IF_IN_FPDOM(m_pDvdCtl2->PlayPeriodInTitleAutoStop(lTitle, &tcStartTimeCode,
  2473. &tcEndTimeCode, cdwDVDCtrlFlags, 0));
  2474. }/* end of try statement */
  2475. catch(HRESULT hrTmp){
  2476. hr = hrTmp;
  2477. }
  2478. catch(...){
  2479. hr = E_UNEXPECTED;
  2480. }/* end of catch statement */
  2481. return HandleError(hr);
  2482. }/* end of function PlayPeriodInTitleAutoStop */
  2483. /*************************************************************************/
  2484. /* Function: PlayAtTimeInTitle */
  2485. /* Description: Time plays, converts from hh:mm:ss:ff format */
  2486. /*************************************************************************/
  2487. STDMETHODIMP CMSWebDVD::PlayAtTimeInTitle(long lTitle, BSTR strTime){
  2488. HRESULT hr = S_OK;
  2489. try {
  2490. if(NULL == strTime){
  2491. throw(E_POINTER);
  2492. }/* end of if statement */
  2493. DVD_HMSF_TIMECODE tcTimeCode;
  2494. hr = Bstr2DVDTime(&tcTimeCode, &strTime);
  2495. if(FAILED(hr)){
  2496. throw(hr);
  2497. }/* end of if statement */
  2498. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY
  2499. if(!m_pDvdCtl2){
  2500. throw(E_UNEXPECTED);
  2501. }/* end of if statement */
  2502. RETRY_IF_IN_FPDOM(m_pDvdCtl2->PlayAtTimeInTitle(lTitle, &tcTimeCode, cdwDVDCtrlFlags, 0));
  2503. }/* end of try statement */
  2504. catch(HRESULT hrTmp){
  2505. hr = hrTmp;
  2506. }
  2507. catch(...){
  2508. hr = E_UNEXPECTED;
  2509. }/* end of catch statement */
  2510. return HandleError(hr);
  2511. }/* end of function PlayAtTimeInTitle */
  2512. /*************************************************************************/
  2513. /* Function: PlayAtTime */
  2514. /* Description: TimeSearch, converts from hh:mm:ss:ff format */
  2515. /*************************************************************************/
  2516. STDMETHODIMP CMSWebDVD::PlayAtTime(BSTR strTime){
  2517. HRESULT hr = S_OK;
  2518. try {
  2519. if(NULL == strTime){
  2520. throw(E_POINTER);
  2521. }/* end of if statement */
  2522. DVD_HMSF_TIMECODE tcTimeCode;
  2523. Bstr2DVDTime(&tcTimeCode, &strTime);
  2524. if(FAILED(hr)){
  2525. throw(hr);
  2526. }/* end of if statement */
  2527. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY
  2528. if(!m_pDvdCtl2){
  2529. throw(E_UNEXPECTED);
  2530. }/* end of if statement */
  2531. RETRY_IF_IN_FPDOM(m_pDvdCtl2->PlayAtTime( &tcTimeCode, cdwDVDCtrlFlags, 0));
  2532. }/* end of try statement */
  2533. catch(HRESULT hrTmp){
  2534. hr = hrTmp;
  2535. }
  2536. catch(...){
  2537. hr = E_UNEXPECTED;
  2538. }/* end of catch statement */
  2539. return HandleError(hr);
  2540. }/* end of function PlayAtTime */
  2541. /*************************************************************************/
  2542. /* Function: get_CurrentTitle */
  2543. /* Description: Gets current title. */
  2544. /*************************************************************************/
  2545. STDMETHODIMP CMSWebDVD::get_CurrentTitle(long *pVal){
  2546. HRESULT hr = S_OK;
  2547. try {
  2548. if(NULL == pVal){
  2549. throw(E_POINTER);
  2550. }/* end of if statement */
  2551. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2552. if(!m_pDvdInfo2){
  2553. throw(E_UNEXPECTED);
  2554. }/* end of if statement */
  2555. DVD_PLAYBACK_LOCATION2 dvdLocation;
  2556. RETRY_IF_IN_FPDOM(m_pDvdInfo2->GetCurrentLocation(&dvdLocation));
  2557. if(SUCCEEDED(hr)){
  2558. *pVal = dvdLocation.TitleNum;
  2559. }
  2560. else {
  2561. *pVal = 0;
  2562. }/* end of if statement */
  2563. }/* end of try statement */
  2564. catch(HRESULT hrTmp){
  2565. hr = hrTmp;
  2566. }
  2567. catch(...){
  2568. hr = E_UNEXPECTED;
  2569. }/* end of catch statement */
  2570. return HandleError(hr);
  2571. }/* end of function get_CurrentTitle */
  2572. /*************************************************************************/
  2573. /* Function: get_CurrentChapter */
  2574. /* Description: Gets current chapter */
  2575. /*************************************************************************/
  2576. STDMETHODIMP CMSWebDVD::get_CurrentChapter(long *pVal){
  2577. HRESULT hr = S_OK;
  2578. try {
  2579. if(NULL == pVal){
  2580. throw(E_POINTER);
  2581. }/* end of if statement */
  2582. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2583. if(!m_pDvdInfo2){
  2584. throw(E_UNEXPECTED);
  2585. }/* end of if statement */
  2586. DVD_PLAYBACK_LOCATION2 dvdLocation;
  2587. RETRY_IF_IN_FPDOM(m_pDvdInfo2->GetCurrentLocation(&dvdLocation));
  2588. if(SUCCEEDED(hr)){
  2589. *pVal = dvdLocation.ChapterNum;
  2590. }
  2591. else {
  2592. *pVal = 0;
  2593. }/* end of if statement */
  2594. }/* end of try statement */
  2595. catch(HRESULT hrTmp){
  2596. hr = hrTmp;
  2597. }
  2598. catch(...){
  2599. hr = E_UNEXPECTED;
  2600. }/* end of catch statement */
  2601. return HandleError(hr);
  2602. }/* end of function get_CurrentChapter */
  2603. /*************************************************************************/
  2604. /* Function: get_FramesPerSecond */
  2605. /* Description: Gets number of frames per second. */
  2606. /*************************************************************************/
  2607. STDMETHODIMP CMSWebDVD::get_FramesPerSecond(long *pVal){
  2608. HRESULT hr = S_OK;
  2609. try {
  2610. if(NULL == pVal){
  2611. throw(E_POINTER);
  2612. }/* end of if statement */
  2613. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2614. if(!m_pDvdInfo2){
  2615. throw(E_UNEXPECTED);
  2616. }/* end of if statement */
  2617. DVD_PLAYBACK_LOCATION2 dvdLocation;
  2618. hr = m_pDvdInfo2->GetCurrentLocation(&dvdLocation);
  2619. // we handle right now only 25 and 30 fps at the moment
  2620. if( dvdLocation.TimeCodeFlags & DVD_TC_FLAG_25fps ) {
  2621. *pVal = 25;
  2622. } else if( dvdLocation.TimeCodeFlags & DVD_TC_FLAG_30fps ) {
  2623. *pVal = 30;
  2624. } else {
  2625. // unknown
  2626. *pVal = 0;
  2627. }/* end of if statement */
  2628. }/* end of try statement */
  2629. catch(HRESULT hrTmp){
  2630. hr = hrTmp;
  2631. }/* end of catch statement */
  2632. catch(...){
  2633. hr = E_UNEXPECTED;
  2634. }/* end of catch statement */
  2635. return HandleError(hr);
  2636. }/* end of function get_FramesPerSecond */
  2637. /*************************************************************************/
  2638. /* Function: get_CurrentTime */
  2639. /* Description: Gets current time. */
  2640. /*************************************************************************/
  2641. STDMETHODIMP CMSWebDVD::get_CurrentTime(BSTR *pVal){
  2642. HRESULT hr = S_OK;
  2643. try {
  2644. if(NULL == pVal){
  2645. throw(E_POINTER);
  2646. }/* end of if statement */
  2647. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2648. if(!m_pDvdInfo2){
  2649. throw(E_UNEXPECTED);
  2650. }/* end of if statement */
  2651. DVD_PLAYBACK_LOCATION2 dvdLocation;
  2652. hr = m_pDvdInfo2->GetCurrentLocation(&dvdLocation);
  2653. DVDTime2bstr(&(dvdLocation.TimeCode), pVal);
  2654. }/* end of try statement */
  2655. catch(HRESULT hrTmp){
  2656. hr = hrTmp;
  2657. }/* end of catch statement */
  2658. catch(...){
  2659. hr = E_UNEXPECTED;
  2660. }/* end of catch statement */
  2661. return HandleError(hr);
  2662. }/* end of function get_CurrentTime */
  2663. /*************************************************************************/
  2664. /* Function: get_DVDDirectory */
  2665. /* Description: Gets the root of the DVD drive. */
  2666. /*************************************************************************/
  2667. STDMETHODIMP CMSWebDVD::get_DVDDirectory(BSTR *pVal){
  2668. HRESULT hr = S_OK;
  2669. try {
  2670. if(NULL == pVal){
  2671. throw(E_POINTER);
  2672. }/* end of if statement */
  2673. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2674. if(!m_pDvdInfo2){
  2675. throw(E_UNEXPECTED);
  2676. }/* end of if statement */
  2677. WCHAR szRoot[MAX_PATH];
  2678. ULONG ulActual;
  2679. hr = m_pDvdInfo2->GetDVDDirectory(szRoot, MAX_PATH, &ulActual);
  2680. *pVal = ::SysAllocString(szRoot);
  2681. }
  2682. catch(HRESULT hrTmp){
  2683. hr = hrTmp;
  2684. }/* end of catch statement */
  2685. catch(...){
  2686. hr = E_UNEXPECTED;
  2687. }/* end of catch statement */
  2688. return HandleError(hr);
  2689. }/* end of function get_DVDDirectory */
  2690. /*************************************************************************/
  2691. /* Function: put_DVDDirectory */
  2692. /* Description: Sets the root for DVD control. */
  2693. /*************************************************************************/
  2694. STDMETHODIMP CMSWebDVD::put_DVDDirectory(BSTR bstrRoot){
  2695. HRESULT hr = S_OK;
  2696. try {
  2697. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2698. if(!m_pDvdCtl2){
  2699. throw (E_UNEXPECTED);
  2700. }/* end of if statement */
  2701. hr = m_pDvdCtl2->SetDVDDirectory(bstrRoot);
  2702. }
  2703. catch(HRESULT hrTmp){
  2704. hr = hrTmp;
  2705. }/* end of catch statement */
  2706. catch(...){
  2707. hr = E_UNEXPECTED;
  2708. }/* end of catch statement */
  2709. return HandleError(hr);
  2710. }/* end of function put_DVDDirectory */
  2711. /*************************************************************************/
  2712. /* Function: get_CurrentDomain */
  2713. /* Description: gets current DVD domain. */
  2714. /*************************************************************************/
  2715. STDMETHODIMP CMSWebDVD::get_CurrentDomain(long *plDomain){
  2716. HRESULT hr = S_OK;
  2717. try {
  2718. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2719. if(!m_pDvdInfo2){
  2720. throw(E_UNEXPECTED);
  2721. }/* end of if statement */
  2722. if(NULL == plDomain){
  2723. throw(E_POINTER);
  2724. }/* end of if statememt */
  2725. hr = m_pDvdInfo2->GetCurrentDomain((DVD_DOMAIN *)plDomain);
  2726. }/* end of try statement */
  2727. catch(HRESULT hrTmp){
  2728. hr = hrTmp;
  2729. }/* end of catch statement */
  2730. catch(...){
  2731. hr = E_UNEXPECTED;
  2732. }/* end of catch statement */
  2733. return HandleError(hr);
  2734. }/* end of function get_CurrentDomain */
  2735. /*************************************************************************/
  2736. /* Function: get_CurrentDiscSide */
  2737. /*************************************************************************/
  2738. STDMETHODIMP CMSWebDVD::get_CurrentDiscSide(long *plDiscSide){
  2739. HRESULT hr = S_OK;
  2740. try {
  2741. if(NULL == plDiscSide){
  2742. throw(E_POINTER);
  2743. }/* end of if statement */
  2744. ULONG ulNumOfVol;
  2745. ULONG ulThisVolNum;
  2746. DVD_DISC_SIDE discSide;
  2747. ULONG ulNumOfTitles;
  2748. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2749. if(!m_pDvdInfo2){
  2750. throw(E_UNEXPECTED);
  2751. }/* end of if statement */
  2752. hr = m_pDvdInfo2->GetDVDVolumeInfo( &ulNumOfVol,
  2753. &ulThisVolNum,
  2754. &discSide,
  2755. &ulNumOfTitles);
  2756. *plDiscSide = discSide;
  2757. }/* end of try statement */
  2758. catch(HRESULT hrTmp){
  2759. hr = hrTmp;
  2760. }/* end of catch statement */
  2761. catch(...){
  2762. hr = E_UNEXPECTED;
  2763. }/* end of catch statement */
  2764. return HandleError(hr);
  2765. }/* end of function get_CurrentDiscSide */
  2766. /*************************************************************************/
  2767. /* Function: get_CurrentVolume */
  2768. /* Description: Gets current volume. */
  2769. /*************************************************************************/
  2770. STDMETHODIMP CMSWebDVD::get_CurrentVolume(long *plVolume){
  2771. HRESULT hr = S_OK;
  2772. try {
  2773. if(NULL == plVolume){
  2774. throw(E_POINTER);
  2775. }/* end of if statement */
  2776. ULONG ulNumOfVol;
  2777. DVD_DISC_SIDE discSide;
  2778. ULONG ulNumOfTitles;
  2779. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2780. if(!m_pDvdInfo2){
  2781. throw(E_UNEXPECTED);
  2782. }/* end of if statement */
  2783. hr = m_pDvdInfo2->GetDVDVolumeInfo( &ulNumOfVol,
  2784. (ULONG*)plVolume,
  2785. &discSide,
  2786. &ulNumOfTitles);
  2787. }/* end of try statement */
  2788. catch(HRESULT hrTmp){
  2789. hr = hrTmp;
  2790. }/* end of catch statement */
  2791. catch(...){
  2792. hr = E_UNEXPECTED;
  2793. }/* end of catch statement */
  2794. return HandleError(hr);
  2795. }/* end of function get_CurrentVolume */
  2796. /*************************************************************************/
  2797. /* Function: get_VolumesAvailable */
  2798. /* Description: Gets total number of volumes available. */
  2799. /*************************************************************************/
  2800. STDMETHODIMP CMSWebDVD::get_VolumesAvailable(long *plNumOfVol){
  2801. HRESULT hr = S_OK;
  2802. try {
  2803. if(NULL == plNumOfVol){
  2804. throw(E_POINTER);
  2805. }/* end of if statement */
  2806. ULONG ulThisVolNum;
  2807. DVD_DISC_SIDE discSide;
  2808. ULONG ulNumOfTitles;
  2809. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2810. if(!m_pDvdInfo2){
  2811. throw(E_UNEXPECTED);
  2812. }/* end of if statement */
  2813. hr = m_pDvdInfo2->GetDVDVolumeInfo( (ULONG*)plNumOfVol,
  2814. &ulThisVolNum,
  2815. &discSide,
  2816. &ulNumOfTitles);
  2817. }/* end of try statement */
  2818. catch(HRESULT hrTmp){
  2819. hr = hrTmp;
  2820. }/* end of catch statement */
  2821. catch(...){
  2822. hr = E_UNEXPECTED;
  2823. }/* end of catch statement */
  2824. return HandleError(hr);
  2825. }/* end of function get_VolumesAvailable */
  2826. /*************************************************************************/
  2827. /* Function: get_CurrentSubpictureStream */
  2828. /* Description: Gets the current subpicture stream. */
  2829. /*************************************************************************/
  2830. STDMETHODIMP CMSWebDVD::get_CurrentSubpictureStream(long *plSubpictureStream){
  2831. HRESULT hr = S_OK;
  2832. try {
  2833. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2834. if(!m_pDvdInfo2){
  2835. throw(E_UNEXPECTED);
  2836. }/* end of if statement */
  2837. ULONG ulStreamsAvailable = 0L;
  2838. BOOL bIsDisabled = TRUE;
  2839. RETRY_IF_IN_FPDOM(m_pDvdInfo2->GetCurrentSubpicture(&ulStreamsAvailable, (ULONG*)plSubpictureStream, &bIsDisabled ));
  2840. }/* end of try statement */
  2841. catch(HRESULT hrTmp){
  2842. hr = hrTmp;
  2843. }/* end of catch statement */
  2844. catch(...){
  2845. hr = E_UNEXPECTED;
  2846. }/* end of catch statement */
  2847. return HandleError(hr);
  2848. }/* end of function get_CurrentSubpictureStream */
  2849. /*************************************************************************/
  2850. /* Function: put_CurrentSubpictureStream */
  2851. /* Description: Sets the current subpicture stream. */
  2852. /*************************************************************************/
  2853. STDMETHODIMP CMSWebDVD::put_CurrentSubpictureStream(long lSubpictureStream){
  2854. HRESULT hr = S_OK;
  2855. try {
  2856. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2857. if(!m_pDvdCtl2){
  2858. throw(E_UNEXPECTED);
  2859. }/* end of if statement */
  2860. if(!m_pDvdInfo2){
  2861. throw(E_UNEXPECTED);
  2862. }/* end of if statement */
  2863. if( lSubpictureStream < cgDVD_MIN_SUBPICTURE
  2864. || (lSubpictureStream > cgDVD_MAX_SUBPICTURE
  2865. && lSubpictureStream != cgDVD_ALT_SUBPICTURE)){
  2866. throw(E_INVALIDARG);
  2867. }/* end of if statement */
  2868. RETRY_IF_IN_FPDOM(m_pDvdCtl2->SelectSubpictureStream(lSubpictureStream,0,0));
  2869. if(FAILED(hr)){
  2870. throw(hr);
  2871. }/* end of if statement */
  2872. // now enabled the subpicture stream if it is not enabled
  2873. ULONG ulStraemsAvial = 0L, ulCurrentStrean = 0L;
  2874. BOOL fDisabled = TRUE;
  2875. hr = m_pDvdInfo2->GetCurrentSubpicture(&ulStraemsAvial, &ulCurrentStrean, &fDisabled);
  2876. if(FAILED(hr)){
  2877. throw(hr);
  2878. }/* end of if statement */
  2879. if(TRUE == fDisabled){
  2880. hr = m_pDvdCtl2->SetSubpictureState(TRUE,0,0); //turn it on
  2881. }/* end of if statement */
  2882. }/* end of try statement */
  2883. catch(HRESULT hrTmp){
  2884. hr = hrTmp;
  2885. }/* end of catch statement */
  2886. catch(...){
  2887. hr = E_UNEXPECTED;
  2888. }/* end of catch statement */
  2889. return HandleError(hr);
  2890. }/* end of function put_CurrentSubpictureStream */
  2891. /*************************************************************************/
  2892. /* Function: get_SubpictureOn */
  2893. /* Description: Gets the current subpicture status On or Off */
  2894. /*************************************************************************/
  2895. STDMETHODIMP CMSWebDVD::get_SubpictureOn(VARIANT_BOOL *pfDisplay){
  2896. HRESULT hr = S_OK;
  2897. try {
  2898. if(NULL == pfDisplay){
  2899. throw(E_POINTER);
  2900. }/* end of if statement */
  2901. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2902. if(!m_pDvdInfo2){
  2903. throw(E_UNEXPECTED);
  2904. }/* end of if statement */
  2905. ULONG ulSubpictureStream = 0L, ulStreamsAvailable = 0L;
  2906. BOOL fDisabled = TRUE;
  2907. RETRY_IF_IN_FPDOM(m_pDvdInfo2->GetCurrentSubpicture(&ulStreamsAvailable, &ulSubpictureStream, &fDisabled))
  2908. if(SUCCEEDED(hr)){
  2909. *pfDisplay = fDisabled == FALSE ? VARIANT_TRUE : VARIANT_FALSE; // compensate for -1 true in OLE
  2910. }/* end of if statement */
  2911. }/* end of try statement */
  2912. catch(HRESULT hrTmp){
  2913. hr = hrTmp;
  2914. }/* end of catch statement */
  2915. catch(...){
  2916. hr = E_UNEXPECTED;
  2917. }/* end of catch statement */
  2918. return HandleError(hr);
  2919. }/* end of function get_SubpictureOn */
  2920. /*************************************************************************/
  2921. /* Function: put_SubpictureOn */
  2922. /* Description: Turns the subpicture On or Off */
  2923. /*************************************************************************/
  2924. STDMETHODIMP CMSWebDVD::put_SubpictureOn(VARIANT_BOOL fDisplay){
  2925. HRESULT hr = S_OK;
  2926. try {
  2927. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2928. if(!m_pDvdInfo2){
  2929. throw(E_UNEXPECTED);
  2930. }/* end of if statement */
  2931. if(!m_pDvdCtl2){
  2932. throw(E_UNEXPECTED);
  2933. }/* end of if statement */
  2934. ULONG ulSubpictureStream = 0L, ulStreamsAvailable = 0L;
  2935. BOOL bIsDisabled = TRUE;
  2936. RETRY_IF_IN_FPDOM(m_pDvdInfo2->GetCurrentSubpicture(&ulStreamsAvailable, &ulSubpictureStream, &bIsDisabled ));
  2937. if(FAILED(hr)){
  2938. throw(hr);
  2939. }/* end of if statement */
  2940. BOOL bDisplay = fDisplay == VARIANT_FALSE ? FALSE : TRUE; // compensate for -1 true in OLE
  2941. hr = m_pDvdCtl2->SetSubpictureState(bDisplay,0,0);
  2942. }/* end of try statement */
  2943. catch(HRESULT hrTmp){
  2944. hr = hrTmp;
  2945. }/* end of catch statement */
  2946. catch(...){
  2947. hr = E_UNEXPECTED;
  2948. }/* end of catch statement */
  2949. return HandleError(hr);
  2950. }/* end of function put_SubpictureOn */
  2951. /*************************************************************************/
  2952. /* Function: get_SubpictureStreamsAvailable */
  2953. /* Description: gets the number of streams available. */
  2954. /*************************************************************************/
  2955. STDMETHODIMP CMSWebDVD::get_SubpictureStreamsAvailable(long *plStreamsAvailable){
  2956. HRESULT hr = S_OK;
  2957. try {
  2958. if (NULL == plStreamsAvailable){
  2959. throw(E_POINTER);
  2960. }/* end of if statement */
  2961. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2962. if(!m_pDvdInfo2){
  2963. throw(E_UNEXPECTED);
  2964. }/* end of if statement */
  2965. ULONG ulSubpictureStream = 0L;
  2966. *plStreamsAvailable = 0L;
  2967. BOOL bIsDisabled = TRUE;
  2968. RETRY_IF_IN_FPDOM(m_pDvdInfo2->GetCurrentSubpicture((ULONG*)plStreamsAvailable, &ulSubpictureStream, &bIsDisabled));
  2969. }/* end of try statement */
  2970. catch(HRESULT hrTmp){
  2971. hr = hrTmp;
  2972. }/* end of catch statement */
  2973. catch(...){
  2974. hr = E_UNEXPECTED;
  2975. }/* end of catch statement */
  2976. return HandleError(hr);
  2977. }/* end of function get_SubpictureStreamsAvailable */
  2978. /*************************************************************************/
  2979. /* Function: get_TotalTitleTime */
  2980. /* Description: Gets total time in the title. */
  2981. /*************************************************************************/
  2982. STDMETHODIMP CMSWebDVD::get_TotalTitleTime(BSTR *pTime){
  2983. HRESULT hr = S_OK;
  2984. try {
  2985. if(NULL == pTime){
  2986. throw(E_POINTER);
  2987. }/* end of if statement */
  2988. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2989. if(!m_pDvdInfo2){
  2990. throw(E_UNEXPECTED);
  2991. }/* end of if statement */
  2992. DVD_HMSF_TIMECODE tcTime;
  2993. ULONG ulFlags; // contains 30fps/25fps
  2994. hr = m_pDvdInfo2->GetTotalTitleTime(&tcTime, &ulFlags);
  2995. if(FAILED(hr)){
  2996. throw(hr);
  2997. }/* end of if statement */
  2998. hr = DVDTime2bstr(&tcTime, pTime);
  2999. }/* end of try statement */
  3000. catch(HRESULT hrTmp){
  3001. hr = hrTmp;
  3002. }/* end of catch statement */
  3003. catch(...){
  3004. hr = E_UNEXPECTED;
  3005. }/* end of catch statement */
  3006. return HandleError(hr);
  3007. }/* end of function get_TotalTitleTime */
  3008. /*************************************************************************/
  3009. /* Function: get_CurrentCCService */
  3010. /* Description: Gets current closed caption service. */
  3011. /*************************************************************************/
  3012. STDMETHODIMP CMSWebDVD::get_CurrentCCService(long *plService){
  3013. HRESULT hr = S_OK;
  3014. try {
  3015. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  3016. if(!m_pDvdGB){
  3017. throw(E_UNEXPECTED);
  3018. }/* end of if statement */
  3019. if(NULL == plService){
  3020. throw(E_POINTER);
  3021. }/* end of if statement */
  3022. CComPtr<IAMLine21Decoder> pLine21Dec;
  3023. hr = m_pDvdGB->GetDvdInterface(IID_IAMLine21Decoder, (LPVOID *)&pLine21Dec);
  3024. if (FAILED(hr)){
  3025. throw(hr);
  3026. }/* end of if statement */
  3027. AM_LINE21_CCSERVICE Service;
  3028. RETRY_IF_IN_FPDOM(pLine21Dec->GetCurrentService(&Service));
  3029. if (FAILED(hr)){
  3030. throw(hr);
  3031. }/* end of if statement */
  3032. *plService = (ULONG)Service;
  3033. }/* end of try statement */
  3034. catch(HRESULT hrTmp){
  3035. hr = hrTmp;
  3036. }/* end of catch statement */
  3037. catch(...){
  3038. hr = E_UNEXPECTED;
  3039. }/* end of catch statement */
  3040. return HandleError(hr);
  3041. }/* end of function get_CurrentCCService */
  3042. /*************************************************************************/
  3043. /* Function: put_CurrentCCService */
  3044. /* Description: Sets current closed caption service. */
  3045. /*************************************************************************/
  3046. STDMETHODIMP CMSWebDVD::put_CurrentCCService(long lService){
  3047. HRESULT hr = S_OK;
  3048. try {
  3049. if(lService < 0){
  3050. throw(E_INVALIDARG);
  3051. }/* end of if statement */
  3052. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  3053. if(!m_pDvdGB){
  3054. throw(E_UNEXPECTED);
  3055. }/* end of if statement */
  3056. CComPtr<IAMLine21Decoder> pLine21Dec;
  3057. hr = m_pDvdGB->GetDvdInterface(IID_IAMLine21Decoder, (LPVOID *)&pLine21Dec);
  3058. if (FAILED(hr)){
  3059. throw(hr);
  3060. }/* end of if statement */
  3061. RETRY_IF_IN_FPDOM(pLine21Dec->SetCurrentService((AM_LINE21_CCSERVICE)lService));
  3062. }/* end of try statement */
  3063. catch(HRESULT hrTmp){
  3064. hr = hrTmp;
  3065. }/* end of catch statement */
  3066. catch(...){
  3067. hr = E_UNEXPECTED;
  3068. }/* end of catch statement */
  3069. return HandleError(hr);
  3070. }/* end of function put_CurrentCCService */
  3071. /*************************************************************************/
  3072. /* Function: get_CurrentButton */
  3073. /* Description: Gets currently selected button. */
  3074. /*************************************************************************/
  3075. STDMETHODIMP CMSWebDVD::get_CurrentButton(long *plCurrentButton){
  3076. HRESULT hr = S_OK;
  3077. try {
  3078. if(NULL == plCurrentButton){
  3079. throw(E_POINTER);
  3080. }/* end of if statement */
  3081. if(!m_pDvdInfo2){
  3082. throw(E_UNEXPECTED);
  3083. }/* end of if statement */
  3084. ULONG ulNumButtons = 0L;
  3085. *plCurrentButton = 0;
  3086. hr = m_pDvdInfo2->GetCurrentButton(&ulNumButtons, (ULONG*)plCurrentButton);
  3087. }/* end of try statement */
  3088. catch(HRESULT hrTmp){
  3089. hr = hrTmp;
  3090. }/* end of catch statement */
  3091. catch(...){
  3092. hr = E_UNEXPECTED;
  3093. }/* end of catch statement */
  3094. return HandleError(hr);
  3095. }/* end of function get_CurrentButton */
  3096. /*************************************************************************/
  3097. /* Function: get_ButtonsAvailable */
  3098. /* Description: Gets the count of the available buttons. */
  3099. /*************************************************************************/
  3100. STDMETHODIMP CMSWebDVD::get_ButtonsAvailable(long *plNumButtons){
  3101. HRESULT hr = S_OK;
  3102. try {
  3103. if(!m_pDvdInfo2){
  3104. throw(E_UNEXPECTED);
  3105. }/* end of if statement */
  3106. ULONG ulCurrentButton = 0L;
  3107. hr = m_pDvdInfo2->GetCurrentButton((ULONG*)plNumButtons, &ulCurrentButton);
  3108. }/* end of try statement */
  3109. catch(HRESULT hrTmp){
  3110. hr = hrTmp;
  3111. }/* end of catch statement */
  3112. catch(...){
  3113. hr = E_UNEXPECTED;
  3114. }/* end of catch statement */
  3115. return HandleError(hr);
  3116. }/* end of function get_ButtonsAvailable */
  3117. /*************************************************************************/
  3118. /* Function: get_CCActive */
  3119. /* Description: Gets the state of the closed caption service. */
  3120. /*************************************************************************/
  3121. STDMETHODIMP CMSWebDVD::get_CCActive(VARIANT_BOOL *fState){
  3122. HRESULT hr = S_OK;
  3123. try {
  3124. if(NULL == fState ){
  3125. throw(E_POINTER);
  3126. }/* end of if statement */
  3127. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  3128. if(!m_pDvdGB){
  3129. throw(E_UNEXPECTED);
  3130. }/* end of if statement */
  3131. CComPtr<IAMLine21Decoder> pLine21Dec;
  3132. hr = m_pDvdGB->GetDvdInterface(IID_IAMLine21Decoder, (LPVOID *)&pLine21Dec);
  3133. if (FAILED(hr)){
  3134. throw(hr);
  3135. }/* end of if statement */
  3136. AM_LINE21_CCSTATE State;
  3137. RETRY_IF_IN_FPDOM(pLine21Dec->GetServiceState(&State));
  3138. if (FAILED(hr)){
  3139. throw(hr);
  3140. }/* end of if statement */
  3141. if(AM_L21_CCSTATE_On == State){
  3142. *fState = VARIANT_TRUE; // OLE TRUE
  3143. }
  3144. else {
  3145. *fState = VARIANT_FALSE;
  3146. }/* end of if statement */
  3147. }/* end of try statement */
  3148. catch(HRESULT hrTmp){
  3149. hr = hrTmp;
  3150. }/* end of catch statement */
  3151. catch(...){
  3152. hr = E_UNEXPECTED;
  3153. }/* end of catch statement */
  3154. return HandleError(hr);
  3155. }/* end of function get_CCActive */
  3156. /*************************************************************************/
  3157. /* Function: put_CCActive */
  3158. /* Description: Sets the ccActive state */
  3159. /*************************************************************************/
  3160. STDMETHODIMP CMSWebDVD::put_CCActive(VARIANT_BOOL fState){
  3161. HRESULT hr = S_OK;
  3162. try {
  3163. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  3164. if(!m_pDvdGB){
  3165. throw(E_UNEXPECTED);
  3166. }/* end of if statement */
  3167. CComPtr<IAMLine21Decoder> pLine21Dec;
  3168. hr = m_pDvdGB->GetDvdInterface(IID_IAMLine21Decoder, (LPVOID *)&pLine21Dec);
  3169. if (FAILED(hr)){
  3170. throw(hr);
  3171. }/* end of if statement */
  3172. AM_LINE21_CCSTATE ccState = (fState == VARIANT_FALSE ? AM_L21_CCSTATE_Off: AM_L21_CCSTATE_On);
  3173. RETRY_IF_IN_FPDOM(pLine21Dec->SetServiceState(ccState));
  3174. }/* end of try statement */
  3175. catch(HRESULT hrTmp){
  3176. hr = hrTmp;
  3177. }/* end of catch statement */
  3178. catch(...){
  3179. hr = E_UNEXPECTED;
  3180. }/* end of catch statement */
  3181. return HandleError(hr);
  3182. }/* end of function put_CCActive */
  3183. /*************************************************************************/
  3184. /* Function: get_CurrentAngle */
  3185. /* Description: Gets current angle. */
  3186. /*************************************************************************/
  3187. STDMETHODIMP CMSWebDVD::get_CurrentAngle(long *plAngle){
  3188. HRESULT hr = S_OK;
  3189. try {
  3190. if(NULL == plAngle){
  3191. throw(E_POINTER);
  3192. }/* end of if statement */
  3193. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  3194. if(!m_pDvdInfo2){
  3195. throw(E_UNEXPECTED);
  3196. }/* end of if statement */
  3197. ULONG ulAnglesAvailable = 0;
  3198. RETRY_IF_IN_FPDOM(m_pDvdInfo2->GetCurrentAngle(&ulAnglesAvailable, (ULONG*)plAngle));
  3199. }/* end of try statement */
  3200. catch(HRESULT hrTmp){
  3201. hr = hrTmp;
  3202. }/* end of catch statement */
  3203. catch(...){
  3204. hr = E_UNEXPECTED;
  3205. }/* end of catch statement */
  3206. return HandleError(hr);
  3207. }/* end of function get_CurrentAngle */
  3208. /*************************************************************************/
  3209. /* Function: put_CurrentAngle */
  3210. /* Description: Sets the current angle (different DVD angle track.) */
  3211. /*************************************************************************/
  3212. STDMETHODIMP CMSWebDVD::put_CurrentAngle(long lAngle){
  3213. HRESULT hr = S_OK;
  3214. try {
  3215. if( lAngle < cgDVD_MIN_ANGLE || lAngle > cgDVD_MAX_ANGLE ){
  3216. throw(E_INVALIDARG);
  3217. }/* end of if statement */
  3218. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY
  3219. if(!m_pDvdCtl2){
  3220. throw(E_UNEXPECTED);
  3221. }/* end of if statement */
  3222. RETRY_IF_IN_FPDOM(m_pDvdCtl2->SelectAngle(lAngle,0,0));
  3223. }/* end of try statement */
  3224. catch(HRESULT hrTmp){
  3225. hr = hrTmp;
  3226. }/* end of catch statement */
  3227. catch(...){
  3228. hr = E_UNEXPECTED;
  3229. }/* end of catch statement */
  3230. return HandleError(hr);
  3231. }/* end of function put_CurrentAngle */
  3232. /*************************************************************************/
  3233. /* Function: get_AnglesAvailable */
  3234. /* Description: Gets the number of angles available. */
  3235. /*************************************************************************/
  3236. STDMETHODIMP CMSWebDVD::get_AnglesAvailable(long *plAnglesAvailable){
  3237. HRESULT hr = S_OK;
  3238. try {
  3239. if(NULL == plAnglesAvailable){
  3240. throw(E_POINTER);
  3241. }/* end of if statement */
  3242. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  3243. if(!m_pDvdInfo2){
  3244. throw(E_UNEXPECTED);
  3245. }/* end of if statement */
  3246. ULONG ulCurrentAngle = 0;
  3247. RETRY_IF_IN_FPDOM(m_pDvdInfo2->GetCurrentAngle((ULONG*)plAnglesAvailable, &ulCurrentAngle));
  3248. }/* end of try statement */
  3249. catch(HRESULT hrTmp){
  3250. hr = hrTmp;
  3251. }/* end of catch statement */
  3252. catch(...){
  3253. hr = E_UNEXPECTED;
  3254. }/* end of catch statement */
  3255. return HandleError(hr);
  3256. }/* end of function get_AnglesAvailable */
  3257. /*************************************************************************/
  3258. /* Function: get_AudioStreamsAvailable */
  3259. /* Description: Gets number of available Audio Streams */
  3260. /*************************************************************************/
  3261. STDMETHODIMP CMSWebDVD::get_AudioStreamsAvailable(long *plNumAudioStreams){
  3262. HRESULT hr = S_OK;
  3263. try {
  3264. if(NULL == plNumAudioStreams){
  3265. throw(E_POINTER);
  3266. }/* end of if statement */
  3267. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  3268. if(!m_pDvdInfo2){
  3269. throw(E_UNEXPECTED);
  3270. }/* end of if statement */
  3271. ULONG ulCurrentStream;
  3272. RETRY_IF_IN_FPDOM(m_pDvdInfo2->GetCurrentAudio((ULONG*)plNumAudioStreams, &ulCurrentStream));
  3273. }/* end of try statement */
  3274. catch(HRESULT hrTmp){
  3275. hr = hrTmp;
  3276. }/* end of catch statement */
  3277. catch(...){
  3278. hr = E_UNEXPECTED;
  3279. }/* end of catch statement */
  3280. return HandleError(hr);
  3281. }/* end of function get_AudioStreamsAvailable */
  3282. /*************************************************************************/
  3283. /* Function: get_CurrentAudioStream */
  3284. /* Description: Gets current audio stream. */
  3285. /*************************************************************************/
  3286. STDMETHODIMP CMSWebDVD::get_CurrentAudioStream(long *plCurrentStream){
  3287. HRESULT hr = S_OK;
  3288. try {
  3289. if(NULL == plCurrentStream){
  3290. throw(E_POINTER);
  3291. }/* end of if statement */
  3292. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  3293. if(!m_pDvdInfo2){
  3294. throw(E_UNEXPECTED);
  3295. }/* end of if statement */
  3296. ULONG ulNumAudioStreams;
  3297. RETRY_IF_IN_FPDOM(m_pDvdInfo2->GetCurrentAudio(&ulNumAudioStreams, (ULONG*)plCurrentStream ));
  3298. }/* end of try statement */
  3299. catch(HRESULT hrTmp){
  3300. hr = hrTmp;
  3301. }/* end of catch statement */
  3302. catch(...){
  3303. hr = E_UNEXPECTED;
  3304. }/* end of catch statement */
  3305. return HandleError(hr);
  3306. }/* end of function get_CurrentAudioStream */
  3307. /*************************************************************************/
  3308. /* Function: put_CurrentAudioStream */
  3309. /* Description: Changes the current audio stream. */
  3310. /*************************************************************************/
  3311. STDMETHODIMP CMSWebDVD::put_CurrentAudioStream(long lAudioStream){
  3312. HRESULT hr = S_OK;
  3313. try {
  3314. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  3315. if(!m_pDvdCtl2){
  3316. throw(E_UNEXPECTED);
  3317. }/* end of if statement */
  3318. RETRY_IF_IN_FPDOM(m_pDvdCtl2->SelectAudioStream(lAudioStream,0,0));
  3319. }/* end of try statement */
  3320. catch(HRESULT hrTmp){
  3321. hr = hrTmp;
  3322. }/* end of catch statement */
  3323. catch(...){
  3324. hr = E_UNEXPECTED;
  3325. }/* end of catch statement */
  3326. return HandleError(hr);
  3327. }/* end of function put_CurrentAudioStream */
  3328. /*************************************************************************/
  3329. /* Function: get_ColorKey */
  3330. /* Description: Gets the current color key. Goes to the dshow if we have */
  3331. /* a graph otherwise just gets the cached color key. */
  3332. /*************************************************************************/
  3333. STDMETHODIMP CMSWebDVD::get_ColorKey(long *pClr){
  3334. HRESULT hr = S_OK;
  3335. try {
  3336. if( NULL == pClr ){
  3337. throw(E_POINTER);
  3338. }/* end of if statement */
  3339. *pClr = 0; // cleanup the variable
  3340. COLORREF clr;
  3341. ::ZeroMemory(&clr, sizeof(COLORREF));
  3342. hr = GetColorKey(&clr); // we get COLORREF HERE and CANNOT be palette index
  3343. HWND hwnd = ::GetDesktopWindow();
  3344. HDC hdc = ::GetWindowDC(hwnd);
  3345. if(NULL == hdc){
  3346. throw(E_UNEXPECTED);
  3347. }/* end of if statement */
  3348. clr = ::GetNearestColor(hdc, clr);
  3349. ::ReleaseDC(hwnd, hdc);
  3350. // handles only case when getting RGB BACK, which is taken care of in the GetColorKey function
  3351. *pClr = ((OLE_COLOR)(((BYTE)(GetBValue(clr))|((WORD)((BYTE)(GetGValue(clr)))<<8))|(((DWORD)(BYTE)(GetRValue(clr)))<<16)));
  3352. if(FAILED(hr)){
  3353. if(false == m_fInitialized){
  3354. *pClr = ((OLE_COLOR)(((BYTE)(GetBValue(m_clrColorKey))|((WORD)((BYTE)(GetGValue(m_clrColorKey)))<<8))|(((DWORD)(BYTE)(GetRValue(m_clrColorKey)))<<16))); // give them our default value
  3355. throw(S_FALSE); // we are not initialized yet, so probably we are called from property bag
  3356. }/* end of if statement */
  3357. throw(hr);
  3358. }/* end of if statement */
  3359. m_clrColorKey = clr; // cache up the value
  3360. }/* end of try statement */
  3361. catch(HRESULT hrTmp){
  3362. hr = hrTmp;
  3363. }/* end of catch statement */
  3364. catch(...){
  3365. hr = E_UNEXPECTED;
  3366. }/* end of catch statement */
  3367. return HandleError(hr);
  3368. }/* end of function get_ColorKey */
  3369. /*************************************************************************/
  3370. /* Function: put_ColorKey */
  3371. /* Description: Sets the color key. */
  3372. /*************************************************************************/
  3373. STDMETHODIMP CMSWebDVD::put_ColorKey(long clr){
  3374. HRESULT hr = S_OK;
  3375. try {
  3376. #if 1
  3377. HWND hwnd = ::GetDesktopWindow();
  3378. HDC hdc = ::GetWindowDC(hwnd);
  3379. if(NULL == hdc){
  3380. throw(E_UNEXPECTED);
  3381. }/* end of if statement */
  3382. if((::GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) == RC_PALETTE){
  3383. clr = MAGENTA_COLOR_KEY;
  3384. }/* end of if statement */
  3385. ::ReleaseDC(hwnd, hdc);
  3386. #endif
  3387. BYTE r = ((BYTE)((clr)>>16));
  3388. BYTE g = (BYTE)(((WORD)(clr)) >> 8);
  3389. BYTE b = ((BYTE)(clr));
  3390. COLORREF clrColorKey = RGB(r, g, b); // convert to color ref
  3391. hr = SetColorKey(clrColorKey);
  3392. if(FAILED(hr)){
  3393. if(false == m_fInitialized){
  3394. m_clrColorKey = clrColorKey; // cache up the value for later
  3395. hr = S_FALSE;
  3396. }/* end of if statement */
  3397. throw(hr);
  3398. }/* end of if statement */
  3399. #if 1
  3400. hr = GetColorKey(&m_clrColorKey);
  3401. #endif
  3402. }/* end of try statement */
  3403. catch(HRESULT hrTmp){
  3404. hr = hrTmp;
  3405. }/* end of catch statement */
  3406. catch(...){
  3407. hr = E_UNEXPECTED;
  3408. }/* end of catch statement */
  3409. return HandleError(hr);
  3410. }/* end of function put_ColorKey */
  3411. /*************************************************************************/
  3412. /* Function: put_BackColor */
  3413. /* Description: Put back color is sinonymous to ColorKey when in the */
  3414. /* windowless mode. */
  3415. /*************************************************************************/
  3416. STDMETHODIMP CMSWebDVD::put_BackColor(VARIANT clrBackColor){
  3417. HRESULT hr = S_OK;
  3418. try {
  3419. VARIANT dest;
  3420. VariantInit(&dest);
  3421. hr = VariantChangeTypeEx(&dest, &clrBackColor, 0, 0, VT_COLOR);
  3422. if (FAILED(hr))
  3423. throw hr;
  3424. hr = CStockPropImpl<CMSWebDVD, IMSWebDVD,
  3425. &IID_IMSWebDVD, &LIBID_MSWEBDVDLib>::put_BackColor(dest.lVal);
  3426. if(FAILED(hr)){
  3427. throw(hr);
  3428. }/* end of if statement */
  3429. }/* end of try statement */
  3430. catch(HRESULT hrTmp){
  3431. hr = hrTmp;
  3432. }/* end of catch statement */
  3433. catch(...){
  3434. hr = E_UNEXPECTED;
  3435. }/* end of catch statement */
  3436. return HandleError(hr);
  3437. }/* end of function put_BackColor */
  3438. /*************************************************************************/
  3439. /* Function: get_BackColor */
  3440. /* Description: Put back color is sinonymous to ColorKey when in the */
  3441. /* windowless mode. */
  3442. /*************************************************************************/
  3443. STDMETHODIMP CMSWebDVD::get_BackColor(VARIANT* pclrBackColor){
  3444. HRESULT hr = S_OK;
  3445. try {
  3446. if ( NULL == pclrBackColor) {
  3447. throw (E_POINTER);
  3448. }
  3449. OLE_COLOR clrColor;
  3450. hr = CStockPropImpl<CMSWebDVD, IMSWebDVD,
  3451. &IID_IMSWebDVD, &LIBID_MSWEBDVDLib>::get_BackColor(&clrColor);
  3452. if (FAILED(hr))
  3453. throw(hr);
  3454. VariantInit(pclrBackColor);
  3455. pclrBackColor->vt = VT_COLOR;
  3456. pclrBackColor->lVal = clrColor;
  3457. }/* end of try statement */
  3458. catch(HRESULT hrTmp){
  3459. hr = hrTmp;
  3460. }/* end of catch statement */
  3461. catch(...){
  3462. hr = E_UNEXPECTED;
  3463. }/* end of catch statement */
  3464. return HandleError(hr);
  3465. }/* end of function get_BackColor */
  3466. /*************************************************************************/
  3467. /* Function: get_ReadyState */
  3468. /* Description: Put back color is sinonymous to ColorKey when in the */
  3469. /* windowless mode. */
  3470. /*************************************************************************/
  3471. STDMETHODIMP CMSWebDVD::get_ReadyState(LONG *pVal){
  3472. HRESULT hr = S_OK;
  3473. try {
  3474. if (NULL == pVal) {
  3475. throw (E_POINTER);
  3476. }
  3477. hr = CStockPropImpl<CMSWebDVD, IMSWebDVD,
  3478. &IID_IMSWebDVD, &LIBID_MSWEBDVDLib>::get_ReadyState(pVal);
  3479. if (FAILED(hr))
  3480. throw(hr);
  3481. }/* end of try statement */
  3482. catch(HRESULT hrTmp){
  3483. hr = hrTmp;
  3484. }/* end of catch statement */
  3485. catch(...){
  3486. hr = E_UNEXPECTED;
  3487. }/* end of catch statement */
  3488. return HandleError(hr);
  3489. }/* end of function get_ReadyState */
  3490. /*************************************************************************/
  3491. /* Function: UOPValid */
  3492. /* Description: Tells if UOP is valid or not, valid means the feature is */
  3493. /* turned on. */
  3494. /*************************************************************************/
  3495. STDMETHODIMP CMSWebDVD::UOPValid(long lUOP, VARIANT_BOOL *pfValid){
  3496. HRESULT hr = S_OK;
  3497. try {
  3498. if (NULL == pfValid){
  3499. throw(E_POINTER);
  3500. }/* end of if statement */
  3501. if ((lUOP > 24) || (lUOP < 0)){
  3502. throw(E_INVALIDARG);
  3503. }/* end of if statement */
  3504. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  3505. if( !m_pDvdInfo2){
  3506. throw(E_UNEXPECTED);
  3507. }/* end of if statement */
  3508. ULONG ulUOPS = 0;
  3509. hr = m_pDvdInfo2->GetCurrentUOPS(&ulUOPS);
  3510. *pfValid = ulUOPS & (1 << lUOP) ? VARIANT_FALSE : VARIANT_TRUE;
  3511. }/* end of try statement */
  3512. catch(HRESULT hrTmp){
  3513. hr = hrTmp;
  3514. }
  3515. catch(...){
  3516. hr = E_UNEXPECTED;
  3517. }/* end of catch statement */
  3518. return HandleError(hr);
  3519. }/* end of function UOPValid */
  3520. /*************************************************************************/
  3521. /* Function: GetGPRM */
  3522. /* Description: Gets the GPRM at specified index */
  3523. /*************************************************************************/
  3524. STDMETHODIMP CMSWebDVD::GetGPRM(long lIndex, short *psGPRM){
  3525. HRESULT hr = E_FAIL;
  3526. try {
  3527. if (NULL == psGPRM){
  3528. throw(E_POINTER);
  3529. }/* end of if statement */
  3530. GPRMARRAY gprm;
  3531. int iArraySize = sizeof(GPRMARRAY)/sizeof(gprm[0]);
  3532. if(0 > lIndex || iArraySize <= lIndex){
  3533. return(E_INVALIDARG);
  3534. }/* end of if statement */
  3535. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  3536. if(!m_pDvdInfo2){
  3537. throw(E_UNEXPECTED);
  3538. }/* end of if statement */
  3539. hr = m_pDvdInfo2->GetAllGPRMs(&gprm);
  3540. if(FAILED(hr)){
  3541. throw(hr);
  3542. }/* end of if statement */
  3543. *psGPRM = gprm[lIndex];
  3544. }/* end of try statement */
  3545. catch(HRESULT hrTmp){
  3546. hr = hrTmp;
  3547. }
  3548. catch(...){
  3549. hr = E_UNEXPECTED;
  3550. }/* end of catch statement */
  3551. return HandleError(hr);
  3552. }/* end of function GetGPRM */
  3553. /*************************************************************************/
  3554. /* Function: GetDVDTextNumberOfLanguages */
  3555. /* Description: Retrieves the number of languages available. */
  3556. /*************************************************************************/
  3557. STDMETHODIMP CMSWebDVD::GetDVDTextNumberOfLanguages(long *plNumOfLangs){
  3558. HRESULT hr = S_OK;
  3559. try {
  3560. if (NULL == plNumOfLangs){
  3561. throw(E_POINTER);
  3562. }/* end of if statement */
  3563. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  3564. if( !m_pDvdInfo2){
  3565. throw(E_UNEXPECTED);
  3566. }/* end of if statement */
  3567. ULONG ulNumOfLangs;
  3568. RETRY_IF_IN_FPDOM(m_pDvdInfo2->GetDVDTextNumberOfLanguages(&ulNumOfLangs));
  3569. if(FAILED(hr)){
  3570. throw(hr);
  3571. }/* end of if statement */
  3572. *plNumOfLangs = ulNumOfLangs;
  3573. }/* end of try statement */
  3574. catch(HRESULT hrTmp){
  3575. hr = hrTmp;
  3576. }
  3577. catch(...){
  3578. hr = E_UNEXPECTED;
  3579. }/* end of catch statement */
  3580. return HandleError(hr);
  3581. }/* end of function GetDVDTextNumberOfLanguages */
  3582. /*************************************************************************/
  3583. /* Function: GetDVDTextNumberOfStrings */
  3584. /* Description: Gets the number of strings in the partical language. */
  3585. /*************************************************************************/
  3586. STDMETHODIMP CMSWebDVD::GetDVDTextNumberOfStrings(long lLangIndex, long *plNumOfStrings){
  3587. HRESULT hr = S_OK;
  3588. try {
  3589. if (NULL == plNumOfStrings){
  3590. throw(E_POINTER);
  3591. }/* end of if statement */
  3592. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  3593. if( !m_pDvdInfo2){
  3594. throw(E_UNEXPECTED);
  3595. }/* end of if statement */
  3596. LCID wLangCode;
  3597. ULONG uNumOfStings;
  3598. DVD_TextCharSet charSet;
  3599. RETRY_IF_IN_FPDOM(m_pDvdInfo2->GetDVDTextLanguageInfo(lLangIndex, &uNumOfStings, &wLangCode, &charSet));
  3600. if(FAILED(hr)){
  3601. throw(hr);
  3602. }/* end of if statement */
  3603. *plNumOfStrings = uNumOfStings;
  3604. }/* end of try statement */
  3605. catch(HRESULT hrTmp){
  3606. hr = hrTmp;
  3607. }
  3608. catch(...){
  3609. hr = E_UNEXPECTED;
  3610. }/* end of catch statement */
  3611. return HandleError(hr);
  3612. }/* end of function GetDVDTextNumberOfStrings */
  3613. /*************************************************************/
  3614. /* Name: GetDVDTextLanguageLCID
  3615. /* Description: Get the LCID of an index of the DVD texts
  3616. /*************************************************************/
  3617. STDMETHODIMP CMSWebDVD::GetDVDTextLanguageLCID(long lLangIndex, long *lcid)
  3618. {
  3619. HRESULT hr = S_OK;
  3620. try {
  3621. if (NULL == lcid){
  3622. throw(E_POINTER);
  3623. }/* end of if statement */
  3624. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  3625. if( !m_pDvdInfo2){
  3626. throw(E_UNEXPECTED);
  3627. }/* end of if statement */
  3628. LCID wLangCode;
  3629. ULONG uNumOfStings;
  3630. DVD_TextCharSet charSet;
  3631. RETRY_IF_IN_FPDOM(m_pDvdInfo2->GetDVDTextLanguageInfo(lLangIndex, &uNumOfStings, &wLangCode, &charSet));
  3632. if(FAILED(hr)){
  3633. throw(hr);
  3634. }/* end of if statement */
  3635. *lcid = wLangCode;
  3636. }/* end of try statement */
  3637. catch(HRESULT hrTmp){
  3638. hr = hrTmp;
  3639. }
  3640. catch(...){
  3641. hr = E_UNEXPECTED;
  3642. }/* end of catch statement */
  3643. return HandleError(hr);
  3644. }/* end of function GetDVDTextLanguageLCID */
  3645. /*************************************************************************/
  3646. /* Function: GetDVDtextString */
  3647. /* Description: Gets the DVD Text string at specific location. */
  3648. /*************************************************************************/
  3649. STDMETHODIMP CMSWebDVD::GetDVDTextString(long lLangIndex, long lStringIndex, BSTR *pstrText){
  3650. HRESULT hr = S_OK;
  3651. try {
  3652. if (NULL == pstrText){
  3653. throw(E_POINTER);
  3654. }/* end of if statement */
  3655. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  3656. if( !m_pDvdInfo2){
  3657. throw(E_UNEXPECTED);
  3658. }/* end of if statement */
  3659. ULONG ulSize;
  3660. DVD_TextStringType type;
  3661. RETRY_IF_IN_FPDOM(m_pDvdInfo2->GetDVDTextStringAsUnicode(lLangIndex, lStringIndex, NULL, 0, &ulSize, &type));
  3662. if(FAILED(hr)){
  3663. throw(hr);
  3664. }/* end of if statement */
  3665. if (ulSize == 0) {
  3666. *pstrText = ::SysAllocString(L"");
  3667. }
  3668. else {
  3669. // got the length so lets allocate a buffer of that size
  3670. WCHAR* wstrBuff = new WCHAR[ulSize];
  3671. ULONG ulActualSize;
  3672. hr = m_pDvdInfo2->GetDVDTextStringAsUnicode(lLangIndex, lStringIndex, wstrBuff, ulSize, &ulActualSize, &type);
  3673. ATLASSERT(ulActualSize == ulSize);
  3674. if(FAILED(hr)){
  3675. delete [] wstrBuff;
  3676. throw(hr);
  3677. }/* end of if statement */
  3678. *pstrText = ::SysAllocString(wstrBuff);
  3679. delete [] wstrBuff;
  3680. }/* end of if statement */
  3681. }/* end of try statement */
  3682. catch(HRESULT hrTmp){
  3683. hr = hrTmp;
  3684. }
  3685. catch(...){
  3686. hr = E_UNEXPECTED;
  3687. }/* end of catch statement */
  3688. return HandleError(hr);
  3689. }/* end of function GetDVDtextString */
  3690. /*************************************************************************/
  3691. /* Function: GetDVDTextStringType */
  3692. /* Description: Gets the type of the string at the specified location. */
  3693. /*************************************************************************/
  3694. STDMETHODIMP CMSWebDVD::GetDVDTextStringType(long lLangIndex, long lStringIndex, DVDTextStringType *pType){
  3695. HRESULT hr = S_OK;
  3696. try {
  3697. if (NULL == pType){
  3698. throw(E_POINTER);
  3699. }/* end of if statement */
  3700. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  3701. if( !m_pDvdInfo2){
  3702. throw(E_UNEXPECTED);
  3703. }/* end of if statement */
  3704. ULONG ulTheSize;
  3705. DVD_TextStringType type;
  3706. RETRY_IF_IN_FPDOM(m_pDvdInfo2->GetDVDTextStringAsUnicode(lLangIndex, lStringIndex, NULL, 0, &ulTheSize, &type));
  3707. if(SUCCEEDED(hr)){
  3708. *pType = (DVDTextStringType) type;
  3709. }/* end of if statement */
  3710. }/* end of try statement */
  3711. catch(HRESULT hrTmp){
  3712. hr = hrTmp;
  3713. }
  3714. catch(...){
  3715. hr = E_UNEXPECTED;
  3716. }/* end of catch statement */
  3717. return HandleError(hr);
  3718. }/* end of function GetDVDTextStringType */
  3719. /*************************************************************************/
  3720. /* Function: GetSPRM */
  3721. /* Description: Gets SPRM at the specific index. */
  3722. /*************************************************************************/
  3723. STDMETHODIMP CMSWebDVD::GetSPRM(long lIndex, short *psSPRM){
  3724. HRESULT hr = E_FAIL;
  3725. try {
  3726. if (NULL == psSPRM){
  3727. throw(E_POINTER);
  3728. }/* end of if statement */
  3729. SPRMARRAY sprm;
  3730. int iArraySize = sizeof(SPRMARRAY)/sizeof(sprm[0]);
  3731. if(0 > lIndex || iArraySize <= lIndex){
  3732. return(E_INVALIDARG);
  3733. }/* end of if statement */
  3734. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  3735. if(!m_pDvdInfo2){
  3736. throw(E_UNEXPECTED);
  3737. }/* end of if statement */
  3738. hr = m_pDvdInfo2->GetAllSPRMs(&sprm);
  3739. if(FAILED(hr)){
  3740. throw(hr);
  3741. }/* end of if statement */
  3742. *psSPRM = sprm[lIndex];
  3743. }/* end of try statement */
  3744. catch(HRESULT hrTmp){
  3745. hr = hrTmp;
  3746. }
  3747. catch(...){
  3748. hr = E_UNEXPECTED;
  3749. }/* end of catch statement */
  3750. return HandleError(hr);
  3751. }/* end of function GetSPRM */
  3752. /*************************************************************************/
  3753. /* Function: get_DVDUniqueID */
  3754. /* Description: Gets the UNIQUE ID that identifies the string. */
  3755. /*************************************************************************/
  3756. STDMETHODIMP CMSWebDVD::get_DVDUniqueID(BSTR *pStrID){
  3757. HRESULT hr = E_FAIL;
  3758. try {
  3759. // TODO: Be able to get m_pDvdInfo2 without initializing the graph
  3760. if (NULL == pStrID){
  3761. throw(E_POINTER);
  3762. }/* end of if statement */
  3763. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  3764. if(!m_pDvdInfo2){
  3765. throw(E_UNEXPECTED);
  3766. }/* end of if statement */
  3767. ULONGLONG ullUniqueID;
  3768. hr = m_pDvdInfo2->GetDiscID(NULL, &ullUniqueID);
  3769. if(FAILED(hr)){
  3770. throw(hr);
  3771. }/* end of if statement */
  3772. //TODO: Get rid of the STDLIB call!!
  3773. // taken out of WMP
  3774. // Script can't handle a 64 bit value so convert it to a string.
  3775. // Doc's say _ui64tow returns 33 bytes (chars?) max.
  3776. // we'll use double that just in case...
  3777. //
  3778. WCHAR wszBuffer[66];
  3779. _ui64tow( ullUniqueID, wszBuffer, 10);
  3780. *pStrID = SysAllocString(wszBuffer);
  3781. }/* end of try statement */
  3782. catch(HRESULT hrTmp){
  3783. hr = hrTmp;
  3784. }
  3785. catch(...){
  3786. hr = E_UNEXPECTED;
  3787. }/* end of catch statement */
  3788. return HandleError(hr);
  3789. }/* end of function get_DVDUniqueID */
  3790. /*************************************************************************/
  3791. /* Function: get_EnableResetOnStop */
  3792. /* Description: Gets the flag. */
  3793. /*************************************************************************/
  3794. STDMETHODIMP CMSWebDVD::get_EnableResetOnStop(VARIANT_BOOL *pVal){
  3795. HRESULT hr = S_OK;
  3796. try {
  3797. if(NULL == pVal){
  3798. throw(E_POINTER);
  3799. }/* end of if statement */
  3800. *pVal = m_fEnableResetOnStop ? VARIANT_TRUE: VARIANT_FALSE;
  3801. }/* end of try statement */
  3802. catch(HRESULT hrTmp){
  3803. hr = hrTmp;
  3804. }
  3805. catch(...){
  3806. hr = E_UNEXPECTED;
  3807. }/* end of catch statement */
  3808. return HandleError(hr);
  3809. }/* end of function get_EnableResetOnStop */
  3810. /*************************************************************************/
  3811. /* Function: put_EnableResetOnStop */
  3812. /* Description: Sets the flag. The flag is used only on stop and play. */
  3813. /* Transitions. */
  3814. /*************************************************************************/
  3815. STDMETHODIMP CMSWebDVD::put_EnableResetOnStop(VARIANT_BOOL newVal){
  3816. HRESULT hr = S_OK;
  3817. try {
  3818. BOOL fEnable = (VARIANT_FALSE == newVal) ? FALSE: TRUE;
  3819. BOOL fEnableOld = m_fEnableResetOnStop;
  3820. m_fEnableResetOnStop = fEnable;
  3821. if(!m_pDvdCtl2){
  3822. throw(S_FALSE); // we might not have initialized graph as of yet, but will
  3823. // defer this to play state
  3824. }/* end of if statement */
  3825. hr = m_pDvdCtl2->SetOption(DVD_ResetOnStop, fEnable);
  3826. if(FAILED(hr)){
  3827. m_fEnableResetOnStop = fEnableOld; // restore the old state
  3828. }/* end of if statement */
  3829. }/* end of try statement */
  3830. catch(HRESULT hrTmp){
  3831. hr = hrTmp;
  3832. }
  3833. catch(...){
  3834. hr = E_UNEXPECTED;
  3835. }/* end of catch statement */
  3836. return HandleError(hr);
  3837. }/* end of function put_EnableResetOnStop */
  3838. /*************************************************************************/
  3839. /* Function: get_Mute */
  3840. /* Description: Gets the mute state. */
  3841. /*************************************************************************/
  3842. STDMETHODIMP CMSWebDVD::get_Mute(VARIANT_BOOL *pfMute){
  3843. HRESULT hr = S_OK;
  3844. try {
  3845. if(NULL == pfMute){
  3846. throw(E_POINTER);
  3847. }/* end of if statement */
  3848. *pfMute = m_bMute ? VARIANT_TRUE: VARIANT_FALSE;
  3849. }/* end of try statement */
  3850. catch(HRESULT hrTmp){
  3851. hr = hrTmp;
  3852. }
  3853. catch(...){
  3854. hr = E_UNEXPECTED;
  3855. }/* end of catch statement */
  3856. return HandleError(hr);
  3857. }/* end of function get_Mute */
  3858. /*************************************************************************/
  3859. /* Function: DShowToWaveV */
  3860. /*************************************************************************/
  3861. inline DShowToWaveV(long x){
  3862. FLOAT fy = (((FLOAT)x + (-cgVOLUME_MIN)) / (-cgVOLUME_MIN)) * cgWAVE_VOLUME_MAX;
  3863. return((WORD)fy);
  3864. }/* end of function DShowToWaveV */
  3865. /*************************************************************************/
  3866. /* Function: WaveToDShowV */
  3867. /*************************************************************************/
  3868. inline LONG WaveToDShowV(WORD y){
  3869. FLOAT fx = ((FLOAT)y * (-cgVOLUME_MIN)) / cgWAVE_VOLUME_MAX + cgVOLUME_MIN;
  3870. return((LONG)fx);
  3871. }/* end of function WaveToDShowV */
  3872. /*************************************************************************/
  3873. /* Function: MixerSetVolume */
  3874. /*************************************************************************/
  3875. HRESULT MixerSetVolume(DWORD dwVolume){
  3876. WORD wVolume = (WORD)(0xffff & dwVolume);
  3877. HRESULT hr = S_OK;
  3878. HMIXER hmx = NULL;
  3879. UINT cMixer = ::mixerGetNumDevs();
  3880. if (cMixer <= 0) {
  3881. return E_FAIL;
  3882. }
  3883. BOOL bVolControlFound = FALSE;
  3884. DWORD dwVolControlID = 0;
  3885. for (UINT i=0; i<cMixer; i++) {
  3886. if(::mixerOpen(&hmx, i, 0, 0, 0) != MMSYSERR_NOERROR){
  3887. // Can't open device, try next device
  3888. continue;
  3889. }/* end of if statement */
  3890. MIXERLINE mxl;
  3891. ::ZeroMemory(&mxl, sizeof(MIXERLINE));
  3892. mxl.cbStruct = sizeof(MIXERLINE);
  3893. mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
  3894. if(::mixerGetLineInfo((HMIXEROBJ)hmx, &mxl, MIXER_GETLINEINFOF_COMPONENTTYPE) != MMSYSERR_NOERROR){
  3895. // Can't find a audio line to adjust the speakers, try next device
  3896. ::mixerClose(hmx);
  3897. continue;
  3898. }
  3899. MIXERLINECONTROLS mxlc;
  3900. ::ZeroMemory(&mxlc, sizeof(MIXERLINECONTROLS));
  3901. mxlc.cbStruct = sizeof(MIXERLINECONTROLS);
  3902. mxlc.dwLineID = mxl.dwLineID;
  3903. mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
  3904. mxlc.cControls = 1;
  3905. MIXERCONTROL mxc;
  3906. ::ZeroMemory(&mxc, sizeof(MIXERCONTROL));
  3907. mxc.cbStruct = sizeof(MIXERCONTROL);
  3908. mxlc.cbmxctrl = sizeof(MIXERCONTROL);
  3909. mxlc.pamxctrl = &mxc;
  3910. if(::mixerGetLineControls((HMIXEROBJ) hmx, &mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE) != MMSYSERR_NOERROR){
  3911. // Can't get volume control on the audio line, try next device
  3912. ::mixerClose(hmx);
  3913. continue;
  3914. }
  3915. if(cgWAVE_VOLUME_MAX != mxc.Bounds.dwMaximum){
  3916. ATLASSERT(FALSE); // improve algorith to take different max and min
  3917. ::mixerClose(hmx);
  3918. hr = E_FAIL;
  3919. return(hr);
  3920. }/* end of if statement */
  3921. if(cgWAVE_VOLUME_MIN != mxc.Bounds.dwMinimum){
  3922. ATLASSERT(FALSE); // improve algorith to take different max and min
  3923. ::mixerClose(hmx);
  3924. hr = E_FAIL;
  3925. return(hr);
  3926. }/* end of if statement */
  3927. // Volume control found, break out loop
  3928. bVolControlFound = TRUE;
  3929. dwVolControlID = mxc.dwControlID;
  3930. break;
  3931. }/*end of for loop*/
  3932. if (!bVolControlFound)
  3933. return E_FAIL;
  3934. MIXERCONTROLDETAILS mxcd;
  3935. MIXERCONTROLDETAILS_SIGNED volStruct;
  3936. ::ZeroMemory(&mxcd, sizeof(MIXERCONTROLDETAILS));
  3937. mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
  3938. mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_SIGNED);
  3939. mxcd.dwControlID = dwVolControlID;
  3940. mxcd.paDetails = &volStruct;
  3941. volStruct.lValue = wVolume;
  3942. mxcd.cChannels = 1;
  3943. if(::mixerSetControlDetails((HMIXEROBJ) hmx, &mxcd, MIXER_SETCONTROLDETAILSF_VALUE) != MMSYSERR_NOERROR){
  3944. ::mixerClose(hmx);
  3945. hr = E_FAIL;
  3946. return(hr);
  3947. }/* end of if statement */
  3948. ::mixerClose(hmx);
  3949. return(hr);
  3950. }/* end of fucntion MixerSetVolume */
  3951. /*************************************************************************/
  3952. /* Function: MixerGetVolume */
  3953. /*************************************************************************/
  3954. HRESULT MixerGetVolume(DWORD& dwVolume){
  3955. HRESULT hr = S_OK;
  3956. HMIXER hmx = NULL;
  3957. UINT cMixer = ::mixerGetNumDevs();
  3958. if (cMixer <= 0) {
  3959. return E_FAIL;
  3960. }
  3961. BOOL bVolControlFound = FALSE;
  3962. DWORD dwVolControlID = 0;
  3963. for (UINT i=0; i<cMixer; i++) {
  3964. if(::mixerOpen(&hmx, i, 0, 0, 0) != MMSYSERR_NOERROR){
  3965. // Can't open device, try next device
  3966. continue;
  3967. }/* end of if statement */
  3968. MIXERLINE mxl;
  3969. ::ZeroMemory(&mxl, sizeof(MIXERLINE));
  3970. mxl.cbStruct = sizeof(MIXERLINE);
  3971. mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
  3972. if(::mixerGetLineInfo((HMIXEROBJ)hmx, &mxl, MIXER_GETLINEINFOF_COMPONENTTYPE) != MMSYSERR_NOERROR){
  3973. // Can't find a audio line to adjust the speakers, try next device
  3974. ::mixerClose(hmx);
  3975. continue;
  3976. }
  3977. MIXERLINECONTROLS mxlc;
  3978. ::ZeroMemory(&mxlc, sizeof(MIXERLINECONTROLS));
  3979. mxlc.cbStruct = sizeof(MIXERLINECONTROLS);
  3980. mxlc.dwLineID = mxl.dwLineID;
  3981. mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
  3982. mxlc.cControls = 1;
  3983. MIXERCONTROL mxc;
  3984. ::ZeroMemory(&mxc, sizeof(MIXERCONTROL));
  3985. mxc.cbStruct = sizeof(MIXERCONTROL);
  3986. mxlc.cbmxctrl = sizeof(MIXERCONTROL);
  3987. mxlc.pamxctrl = &mxc;
  3988. if(::mixerGetLineControls((HMIXEROBJ) hmx, &mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE) != MMSYSERR_NOERROR){
  3989. // Can't get volume control on the audio line, try next device
  3990. ::mixerClose(hmx);
  3991. continue;
  3992. }
  3993. if(cgWAVE_VOLUME_MAX != mxc.Bounds.dwMaximum){
  3994. ATLASSERT(FALSE); // improve algorith to take different max and min
  3995. ::mixerClose(hmx);
  3996. hr = E_FAIL;
  3997. return(hr);
  3998. }/* end of if statement */
  3999. if(cgWAVE_VOLUME_MIN != mxc.Bounds.dwMinimum){
  4000. ATLASSERT(FALSE); // improve algorith to take different max and min
  4001. ::mixerClose(hmx);
  4002. hr = E_FAIL;
  4003. return(hr);
  4004. }/* end of if statement */
  4005. // Volume control found, break out loop
  4006. bVolControlFound = TRUE;
  4007. dwVolControlID = mxc.dwControlID;
  4008. break;
  4009. }/*end of for loop*/
  4010. if (!bVolControlFound)
  4011. return E_FAIL;
  4012. MIXERCONTROLDETAILS mxcd;
  4013. MIXERCONTROLDETAILS_SIGNED volStruct;
  4014. ::ZeroMemory(&mxcd, sizeof(MIXERCONTROLDETAILS));
  4015. mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
  4016. mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_SIGNED);
  4017. mxcd.dwControlID = dwVolControlID;
  4018. mxcd.paDetails = &volStruct;
  4019. mxcd.cChannels = 1;
  4020. if(::mixerGetControlDetails((HMIXEROBJ) hmx, &mxcd, MIXER_GETCONTROLDETAILSF_VALUE) != MMSYSERR_NOERROR){
  4021. ::mixerClose(hmx);
  4022. hr = E_FAIL;
  4023. return(hr);
  4024. }/* end of if statement */
  4025. // the volStruct.lValue gets initialize via call to mixerGetControlDetails with mxcd.paDetails = &volStruct;
  4026. dwVolume = volStruct.lValue;
  4027. ::mixerClose(hmx);
  4028. return(hr);
  4029. }/* end of function MixerGetVolume */
  4030. /*************************************************************************/
  4031. /* Function: get_IntVolume */
  4032. /*************************************************************************/
  4033. HRESULT CMSWebDVD::get_IntVolume(LONG* plVolume){
  4034. HRESULT hr = S_OK;
  4035. if(m_pAudio){
  4036. hr = m_pAudio->get_Volume(plVolume); // get the volume
  4037. }
  4038. else {
  4039. DWORD dwVolume;
  4040. hr = MixerGetVolume(dwVolume);
  4041. if(FAILED(hr)){
  4042. return(hr);
  4043. }/* end of if statement */
  4044. *plVolume = WaveToDShowV(LOWORD(dwVolume));
  4045. }/* end of if statememt */
  4046. return(hr);
  4047. }/* end of function get_VolumeHelper */
  4048. /*************************************************************************/
  4049. /* Function: put_IntVolume */
  4050. /*************************************************************************/
  4051. HRESULT CMSWebDVD::put_IntVolume(long lVolume){
  4052. HRESULT hr = S_OK;
  4053. if(m_pAudio){
  4054. hr = m_pAudio->put_Volume(lVolume);
  4055. }
  4056. else {
  4057. WORD wVolume = WORD(DShowToWaveV(lVolume));
  4058. // set left and right volume same for now
  4059. DWORD dwVolume;
  4060. dwVolume = ((DWORD)(((WORD)(wVolume)) | ((DWORD)((WORD)(wVolume))) << 16));
  4061. hr = MixerSetVolume(dwVolume);
  4062. }/* end of if statement */
  4063. return(hr);
  4064. }/* end of function put_IntVolume */
  4065. /*************************************************************************/
  4066. /* Function: put_Mute */
  4067. /* Description: Gets the mute state. */
  4068. /*************************************************************************/
  4069. STDMETHODIMP CMSWebDVD::put_Mute(VARIANT_BOOL newVal){
  4070. HRESULT hr = E_FAIL;
  4071. try {
  4072. if(VARIANT_FALSE == newVal){
  4073. // case when we are unmutting
  4074. LONG lVolume;
  4075. if(TRUE != m_bMute){
  4076. hr = get_IntVolume(&lVolume); // get the volume
  4077. if(FAILED(hr)){
  4078. throw(hr);
  4079. }/* end of if statement */
  4080. if(cgVOLUME_MIN != lVolume){
  4081. // OK we are not really muted, so
  4082. // send little displesure the app
  4083. throw(S_FALSE);
  4084. }/* end of if statement */
  4085. // otherwise proceed normally and sync our flag
  4086. }/* end of if statement */
  4087. hr = put_IntVolume(m_lLastVolume);
  4088. if(FAILED(hr)){
  4089. throw(hr);
  4090. }/* end of if statement */
  4091. m_bMute = FALSE; // reset our flag, that we are muted
  4092. }
  4093. else {
  4094. // case when we are mutting
  4095. LONG lVolume;
  4096. hr = get_IntVolume(&lVolume); // get the volume
  4097. if(FAILED(hr)){
  4098. throw(hr);
  4099. }/* end of if statement */
  4100. m_lLastVolume = lVolume; // store the volume for when we are unmutting
  4101. hr = put_IntVolume(cgVOLUME_MIN);
  4102. if(FAILED(hr)){
  4103. throw(hr);
  4104. }/* end of if statement */
  4105. m_bMute = TRUE; // set the mute flage
  4106. }/* end of if statement */
  4107. }/* end of try statement */
  4108. catch(HRESULT hrTmp){
  4109. hr = hrTmp;
  4110. }
  4111. catch(...){
  4112. hr = E_UNEXPECTED;
  4113. }/* end of catch statement */
  4114. return HandleError(hr);
  4115. }/* end of function put_Mute */
  4116. /*************************************************************************/
  4117. /* Function: get_Volume */
  4118. /* Description: Gets the volume. */
  4119. /*************************************************************************/
  4120. STDMETHODIMP CMSWebDVD::get_Volume(long *plVolume){
  4121. HRESULT hr = E_FAIL;
  4122. try {
  4123. if(NULL == plVolume){
  4124. throw(E_POINTER);
  4125. }/* end of if statement */
  4126. if(FALSE == m_bMute){
  4127. hr = get_IntVolume(plVolume);
  4128. }
  4129. else {
  4130. // we are in mute state so save the volume for "unmuting"
  4131. *plVolume = m_lLastVolume;
  4132. hr = S_FALSE; // indicate we are sort of unhappy
  4133. }/* end of if statement */
  4134. }/* end of try statement */
  4135. catch(HRESULT hrTmp){
  4136. hr = hrTmp;
  4137. }
  4138. catch(...){
  4139. hr = E_UNEXPECTED;
  4140. }/* end of catch statement */
  4141. return HandleError(hr);
  4142. }/* end of function get_Volume */
  4143. /*************************************************************************/
  4144. /* Function: put_Volume */
  4145. /* Description: Sets the volume. */
  4146. /*************************************************************************/
  4147. STDMETHODIMP CMSWebDVD::put_Volume(long lVolume){
  4148. HRESULT hr = E_FAIL;
  4149. try {
  4150. // cgVOLUME_MIN is max and cgVOLUME_MAX is min by value
  4151. if(cgVOLUME_MIN > lVolume || cgVOLUME_MAX < lVolume){
  4152. throw(E_INVALIDARG);
  4153. }/* end of if statement */
  4154. if(TRUE == m_bMute){
  4155. // unmute we are setting volume
  4156. m_bMute = FALSE;
  4157. }/* end of if statement */
  4158. hr = put_IntVolume(lVolume);
  4159. // this statement might be taken out but might prevent some error scenarious
  4160. // when things are not working right.
  4161. if(SUCCEEDED(hr)){
  4162. m_lLastVolume = lVolume; // cash up the volume
  4163. }/* end of if statement */
  4164. }/* end of try statement */
  4165. catch(HRESULT hrTmp){
  4166. hr = hrTmp;
  4167. }
  4168. catch(...){
  4169. hr = E_UNEXPECTED;
  4170. }/* end of catch statement */
  4171. return HandleError(hr);
  4172. }/* end of function put_Volume */
  4173. /*************************************************************************/
  4174. /* Function: get_Balance */
  4175. /* Description: Gets the balance. */
  4176. /*************************************************************************/
  4177. STDMETHODIMP CMSWebDVD::get_Balance(long *plBalance){
  4178. HRESULT hr = E_FAIL;
  4179. try {
  4180. if(NULL == plBalance){
  4181. throw(E_POINTER);
  4182. }/* end of if statement */
  4183. if(!m_pAudio){
  4184. throw(E_NOTIMPL);
  4185. }/* end of if statement */
  4186. hr = m_pAudio->get_Balance(plBalance);
  4187. }/* end of try statement */
  4188. catch(HRESULT hrTmp){
  4189. hr = hrTmp;
  4190. }
  4191. catch(...){
  4192. hr = E_UNEXPECTED;
  4193. }/* end of catch statement */
  4194. return HandleError(hr);
  4195. }/* end of function get_Balance */
  4196. /*************************************************************************/
  4197. /* Function: put_Balance */
  4198. /* Description: Sets the balance. */
  4199. /*************************************************************************/
  4200. STDMETHODIMP CMSWebDVD::put_Balance(long lBalance){
  4201. HRESULT hr = E_FAIL;
  4202. try {
  4203. if(cgBALANCE_MIN > lBalance || cgBALANCE_MAX < lBalance){
  4204. throw(E_INVALIDARG);
  4205. }/* end of if statement */
  4206. if(!m_pAudio){
  4207. throw(E_NOTIMPL);
  4208. }/* end of if statement */
  4209. hr = m_pAudio->put_Balance(lBalance);
  4210. }/* end of try statement */
  4211. catch(HRESULT hrTmp){
  4212. hr = hrTmp;
  4213. }
  4214. catch(...){
  4215. hr = E_UNEXPECTED;
  4216. }/* end of catch statement */
  4217. return HandleError(hr);
  4218. }/* end of function put_Balance */
  4219. #if 1 // USE TOOLTIPS
  4220. /*************************************************************************/
  4221. /* Function: OnMouseToolTip */
  4222. /* Description: Check if we were captured/pushed the do not do much, */
  4223. /* otherwise do the hit detection and see if we are in static or hower */
  4224. /* state. */
  4225. /*************************************************************************/
  4226. LRESULT CMSWebDVD::OnMouseToolTip(UINT msg, WPARAM wParam, LPARAM lParam, BOOL& bHandled){
  4227. bHandled = FALSE;
  4228. if (!m_hWndTip){
  4229. return 0;
  4230. }/* end of if statement */
  4231. MSG mssg;
  4232. HWND hwnd;
  4233. HRESULT hr = GetUsableWindow(&hwnd);
  4234. if(FAILED(hr)){
  4235. return(1);
  4236. }/* end of if statement */
  4237. if(!m_bWndLess){
  4238. HWND hwndTmp = hwnd;
  4239. // Get the active movie window
  4240. hwnd = ::GetWindow(hwndTmp, GW_CHILD);
  4241. if (!::IsWindow(hwnd)){
  4242. return S_FALSE;
  4243. }/* end of if statement */
  4244. }/* end of if statement */
  4245. mssg.hwnd = hwnd;
  4246. ATLASSERT(mssg.hwnd);
  4247. mssg.message = msg;
  4248. mssg.wParam = wParam;
  4249. mssg.lParam = lParam;
  4250. ::SendMessage(m_hWndTip, TTM_RELAYEVENT, 0, (LPARAM) &mssg);
  4251. return 0;
  4252. }/* end of function OnMouseToolTip */
  4253. /*************************************************************/
  4254. /* Name: get_ToolTip */
  4255. /* Description: create a tool tip for the button */
  4256. /*************************************************************/
  4257. STDMETHODIMP CMSWebDVD::get_ToolTip(BSTR *pVal){
  4258. HRESULT hr = S_OK;
  4259. try {
  4260. if (NULL == pVal) {
  4261. throw (E_POINTER);
  4262. } /* end of if statment */
  4263. *pVal = m_bstrToolTip.Copy();
  4264. }
  4265. catch(HRESULT hrTmp){
  4266. hr = hrTmp;
  4267. }/* end of catch statement */
  4268. catch(...){
  4269. hr = E_UNEXPECTED;
  4270. }/* end of catch statement */
  4271. return HandleError(hr);
  4272. }/* end of function get_ToolTip */
  4273. /*************************************************************/
  4274. /* Name: put_ToolTip */
  4275. /* Description: create a tool tip for the button */
  4276. /* Cache the tooltip string if there is no window available */
  4277. /*************************************************************/
  4278. STDMETHODIMP CMSWebDVD::put_ToolTip(BSTR newVal){
  4279. HRESULT hr = S_OK;
  4280. try {
  4281. if(NULL == newVal){
  4282. throw(E_POINTER);
  4283. }/* end of if statement */
  4284. m_bstrToolTip = newVal;
  4285. hr = CreateToolTip();
  4286. }
  4287. catch(HRESULT hrTmp){
  4288. hr = hrTmp;
  4289. }/* end of catch statement */
  4290. catch(...){
  4291. hr = E_UNEXPECTED;
  4292. }/* end of catch statement */
  4293. return HandleError(hr);
  4294. }/* end of function put_ToolTip */
  4295. /*************************************************************************/
  4296. /* Function: GetUsableWindow */
  4297. /* Description: Gets the window. If we are windowless we pass */
  4298. /* down the parent container window, which is really in a sense parent. */
  4299. /*************************************************************************/
  4300. HRESULT CMSWebDVD::GetUsableWindow(HWND* pWnd){
  4301. HRESULT hr = S_OK;
  4302. if(NULL == pWnd){
  4303. hr = E_POINTER;
  4304. return(hr);
  4305. }/* end of if statement */
  4306. *pWnd = NULL;
  4307. HWND hwnd; // temp
  4308. if(m_bWndLess){
  4309. hr = GetParentHWND(&hwnd);
  4310. if(FAILED(hr)){
  4311. return(hr);
  4312. }/* end of if statement */
  4313. }
  4314. else {
  4315. hwnd = m_hWnd;
  4316. }/* end of if statement */
  4317. if(::IsWindow(hwnd)){
  4318. *pWnd = hwnd;
  4319. hr = S_OK;
  4320. }
  4321. else {
  4322. hr = E_UNEXPECTED;
  4323. }/* end of if statement */
  4324. return(hr);
  4325. }/* end of function GetUsableWindow */
  4326. /*************************************************************************/
  4327. /* Function: GetUsableWindow */
  4328. /* Description: Gets the window. If we are windowless we pass */
  4329. /* down the parent container window, which is really in a sense parent. */
  4330. /*************************************************************************/
  4331. HRESULT CMSWebDVD::GetClientRectInScreen(RECT* prc){
  4332. HRESULT hr = S_OK;
  4333. if(NULL == prc){
  4334. hr = E_POINTER;
  4335. return(hr);
  4336. }/* end of if statement */
  4337. *prc = m_rcPos; //{m_rcPos.left, m_rcPos.top, m_rcPos.right, m_rcPos.bottom};
  4338. HWND hwnd;
  4339. hr = GetUsableWindow(&hwnd);
  4340. if(FAILED(hr)){
  4341. return(hr);
  4342. }/* end of if statement */
  4343. ::MapWindowPoints(hwnd, ::GetDesktopWindow(), (LPPOINT)prc, 2);
  4344. return(hr);
  4345. }/* end of function GetClientRectInScreen */
  4346. /*************************************************************/
  4347. /* Name: CreateToolTip
  4348. /* Description: create a tool tip for the button
  4349. /*************************************************************/
  4350. HRESULT CMSWebDVD::CreateToolTip(void){
  4351. HWND hwnd;
  4352. HRESULT hr = GetUsableWindow(&hwnd);
  4353. if(FAILED(hr)){
  4354. return(hr);
  4355. }/* end of if statement */
  4356. if(!m_bWndLess){
  4357. HWND hwndTmp = hwnd;
  4358. // Get the active movie window
  4359. hwnd = ::GetWindow(hwndTmp, GW_CHILD);
  4360. if (!::IsWindow(hwnd)){
  4361. return S_FALSE;
  4362. }/* end of if statement */
  4363. }/* end of if statement */
  4364. USES_CONVERSION;
  4365. // If tool tip is to be created for the first time
  4366. if (m_hWndTip == (HWND) NULL) {
  4367. // Ensure that the common control DLL is loaded, and create
  4368. // a tooltip control.
  4369. InitCommonControls();
  4370. m_hWndTip = CreateWindow(TOOLTIPS_CLASS, (LPTSTR) NULL, TTS_ALWAYSTIP,
  4371. CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  4372. hwnd, (HMENU) NULL, _Module.GetModuleInstance(), NULL);
  4373. }
  4374. if (m_hWndTip == (HWND) NULL)
  4375. return S_FALSE;
  4376. TOOLINFO ti; // tool information
  4377. ti.cbSize = sizeof(TOOLINFO);
  4378. ti.uFlags = 0;
  4379. ti.hwnd = hwnd;
  4380. ti.hinst = _Module.GetModuleInstance();
  4381. ti.uId = (UINT) 0;
  4382. ti.lpszText = OLE2T(m_bstrToolTip);
  4383. // if the button is a windowed control, the tool tip is added to
  4384. // the button's own window, and the tool tip area should just be
  4385. // the client rect of the window
  4386. if (hwnd == m_hWnd)
  4387. ::GetClientRect(hwnd, &ti.rect);
  4388. // otherwise the tool tip is added to the closet windowed parent of
  4389. // the button, and the tool tip area should be the relative postion
  4390. // of the button in the parent window
  4391. else {
  4392. ti.rect.left = m_rcPos.left;
  4393. ti.rect.top = m_rcPos.top;
  4394. ti.rect.right = m_rcPos.right;
  4395. ti.rect.bottom = m_rcPos.bottom;
  4396. }
  4397. if (!SendMessage(m_hWndTip, TTM_ADDTOOL, 0,
  4398. (LPARAM) (LPTOOLINFO) &ti))
  4399. return S_FALSE;
  4400. // Set initial delay time
  4401. put_ToolTipMaxWidth(m_nTTMaxWidth);
  4402. VARIANT varTemp;
  4403. VariantInit(&varTemp);
  4404. #ifdef _WIN64
  4405. varTemp.vt = VT_I8;
  4406. #define VARTEMP_VAL (varTemp.llVal)
  4407. #else
  4408. varTemp.vt = VT_I4;
  4409. #define VARTEMP_VAL (varTemp.lVal)
  4410. #endif
  4411. VARTEMP_VAL = m_dwTTAutopopDelay;
  4412. SetDelayTime(TTDT_AUTOPOP, varTemp);
  4413. VARTEMP_VAL = m_dwTTInitalDelay;
  4414. SetDelayTime(TTDT_INITIAL, varTemp);
  4415. VARTEMP_VAL = m_dwTTReshowDelay;
  4416. SetDelayTime(TTDT_RESHOW, varTemp);
  4417. #undef VARTEMP_VAL
  4418. return S_OK;
  4419. }/* end of function CreateToolTip */
  4420. /*************************************************************************/
  4421. /* Function: get_ToolTipMaxWidth */
  4422. /*************************************************************************/
  4423. STDMETHODIMP CMSWebDVD::get_ToolTipMaxWidth(long *pVal){
  4424. HRESULT hr = S_OK;
  4425. try {
  4426. if (NULL == pVal) {
  4427. throw E_POINTER;
  4428. } /* end of if statement */
  4429. if (NULL != m_hWndTip){
  4430. // Return value is width in pixels. Safe to cast to 32-bit.
  4431. m_nTTMaxWidth = (LONG)::SendMessage(m_hWndTip, TTM_GETMAXTIPWIDTH, 0, 0);
  4432. }/* end of if statement */
  4433. *pVal = m_nTTMaxWidth;
  4434. }
  4435. catch(HRESULT hrTmp){
  4436. hr = hrTmp;
  4437. }/* end of catch statement */
  4438. catch(...){
  4439. hr = E_UNEXPECTED;
  4440. }/* end of catch statement */
  4441. return HandleError(hr);
  4442. }/* end of function get_ToolTipMaxWidth */
  4443. /*************************************************************************/
  4444. /* Function: put_ToolTipMaxWidth */
  4445. /*************************************************************************/
  4446. STDMETHODIMP CMSWebDVD::put_ToolTipMaxWidth(long newVal){
  4447. HRESULT hr = S_OK;
  4448. try {
  4449. if (newVal <= 0) {
  4450. throw E_INVALIDARG;
  4451. } /* end of if statement */
  4452. m_nTTMaxWidth = newVal;
  4453. if (m_hWndTip){
  4454. ::SendMessage(m_hWndTip, TTM_SETMAXTIPWIDTH, 0, (LPARAM)(INT) newVal);
  4455. }/* end of if statement */
  4456. }
  4457. catch(HRESULT hrTmp){
  4458. hr = hrTmp;
  4459. }/* end of catch statement */
  4460. catch(...){
  4461. hr = E_UNEXPECTED;
  4462. }/* end of catch statement */
  4463. return HandleError(hr);
  4464. }/* end of function put_ToolTipMaxWidth */
  4465. /*************************************************************/
  4466. /* Name: GetDelayTime
  4467. /* Description: Get the length of time a pointer must remain
  4468. /* stationary within a tool's bounding rectangle before the
  4469. /* tooltip window appears
  4470. /* delayTypes: TTDT_RESHOW 1
  4471. /* TTDT_AUTOPOP 2
  4472. /* TTDT_INITIAL 3
  4473. /*************************************************************/
  4474. STDMETHODIMP CMSWebDVD::GetDelayTime(long delayType, VARIANT *pVal){
  4475. HRESULT hr = S_OK;
  4476. LRESULT lDelay = 0; //BUGBUG: Is this a good initialization value?
  4477. try {
  4478. if (NULL == pVal) {
  4479. throw E_POINTER;
  4480. } /* end of if statement */
  4481. if (delayType>TTDT_INITIAL || delayType<TTDT_RESHOW) {
  4482. throw E_INVALIDARG;
  4483. } /* end of if statement */
  4484. if (m_hWndTip) {
  4485. lDelay = SendMessage(m_hWndTip, TTM_GETDELAYTIME,
  4486. (WPARAM) (DWORD) delayType, 0);
  4487. }
  4488. // else return cached values
  4489. else {
  4490. switch (delayType) {
  4491. case TTDT_AUTOPOP:
  4492. lDelay = m_dwTTAutopopDelay;
  4493. break;
  4494. case TTDT_INITIAL:
  4495. lDelay = m_dwTTInitalDelay;
  4496. break;
  4497. case TTDT_RESHOW:
  4498. lDelay = m_dwTTReshowDelay;
  4499. break;
  4500. }
  4501. } /* end of if statement */
  4502. /*
  4503. * Copy the delay to the VARIANT return variable.
  4504. * BUGBUG: If pVal was a properly initialized variant, we should
  4505. * call VariantClear to free any pointers. If it wasn't initialized
  4506. * VariantInit is the right thing to call instead. I prefer a leak
  4507. * to a crash so I'll use VariantInit below
  4508. */
  4509. VariantInit(pVal);
  4510. #ifdef _WIN64
  4511. pVal->vt = VT_I8;
  4512. pVal->llVal = lDelay;
  4513. #else
  4514. pVal->vt = VT_I4;
  4515. pVal->lVal = lDelay;
  4516. #endif
  4517. }
  4518. catch(HRESULT hrTmp){
  4519. hr = hrTmp;
  4520. }/* end of catch statement */
  4521. catch(...){
  4522. hr = E_UNEXPECTED;
  4523. }/* end of catch statement */
  4524. return HandleError(hr);
  4525. }/* end of function GetDelayTime */
  4526. /*************************************************************/
  4527. /* Name: SetDelayTime
  4528. /* Description: Set the length of time a pointer must remain
  4529. /* stationary within a tool's bounding rectangle before the
  4530. /* tooltip window appears
  4531. /* delayTypes: TTDT_AUTOMATIC 0
  4532. /* TTDT_RESHOW 1
  4533. /* TTDT_AUTOPOP 2
  4534. /* TTDT_INITIAL 3
  4535. /*************************************************************/
  4536. STDMETHODIMP CMSWebDVD::SetDelayTime(long delayType, VARIANT newVal){
  4537. HRESULT hr = S_OK;
  4538. LPARAM lNewDelay = 0;
  4539. try {
  4540. if (delayType>TTDT_INITIAL || delayType<TTDT_AUTOMATIC) {
  4541. throw E_INVALIDARG;
  4542. } /* end of if statement */
  4543. VARIANT dest;
  4544. VariantInit(&dest);
  4545. #ifdef _WIN64
  4546. hr = VariantChangeTypeEx(&dest, &newVal, 0, 0, VT_I8);
  4547. if (FAILED(hr))
  4548. throw hr;
  4549. lNewDelay = dest.llVal;
  4550. #else
  4551. hr = VariantChangeTypeEx(&dest, &newVal, 0, 0, VT_I4);
  4552. if (FAILED(hr))
  4553. throw hr;
  4554. lNewDelay = dest.lVal;
  4555. #endif
  4556. if (lNewDelay < 0) {
  4557. throw E_INVALIDARG;
  4558. } /* end of if statement */
  4559. if (m_hWndTip) {
  4560. if (!SendMessage(m_hWndTip, TTM_SETDELAYTIME,
  4561. (WPARAM) (DWORD) delayType,
  4562. lNewDelay))
  4563. return S_FALSE;
  4564. }
  4565. // cache these values
  4566. switch (delayType) {
  4567. case TTDT_AUTOPOP:
  4568. m_dwTTAutopopDelay = lNewDelay;
  4569. break;
  4570. case TTDT_INITIAL:
  4571. m_dwTTInitalDelay = lNewDelay;
  4572. break;
  4573. case TTDT_RESHOW:
  4574. m_dwTTReshowDelay = lNewDelay;
  4575. break;
  4576. case TTDT_AUTOMATIC:
  4577. m_dwTTInitalDelay = lNewDelay;
  4578. m_dwTTAutopopDelay = lNewDelay*10;
  4579. m_dwTTReshowDelay = lNewDelay/5;
  4580. break;
  4581. } /* end of switch statement */
  4582. }
  4583. catch(HRESULT hrTmp){
  4584. hr = hrTmp;
  4585. }/* end of catch statement */
  4586. catch(...){
  4587. hr = E_UNEXPECTED;
  4588. }/* end of catch statement */
  4589. return HandleError(hr);
  4590. }/* end of function SetDelayTime */
  4591. #endif
  4592. /*************************************************************************/
  4593. /* Function: ProcessEvents */
  4594. /* Description: Triggers the message, which checks if the messagess are */
  4595. /* ready. */
  4596. /*************************************************************************/
  4597. HRESULT CMSWebDVD::ProcessEvents(){
  4598. HRESULT hr = S_OK;
  4599. try {
  4600. // see if we have lost the DDraw Surf on in Windowless MODE
  4601. if((m_pDDrawDVD) && (!::IsWindow(m_hWnd))){
  4602. LPDIRECTDRAWSURFACE pDDPrimary = m_pDDrawDVD->GetDDrawSurf();
  4603. if (pDDPrimary && (pDDPrimary->IsLost() == DDERR_SURFACELOST)){
  4604. if (pDDPrimary->Restore() == DD_OK){
  4605. RestoreSurfaces();
  4606. }/* end of if statement */
  4607. }/* end of if statement */
  4608. }/* end of if statement */
  4609. // process the DVD event
  4610. LRESULT lRes;
  4611. ProcessWindowMessage(NULL, WM_DVDPLAY_EVENT, 0, 0, lRes);
  4612. }/* end of try statement */
  4613. catch(HRESULT hrTmp){
  4614. hr = hrTmp;
  4615. }/* end of catch statement */
  4616. catch(...){
  4617. hr = E_UNEXPECTED;
  4618. }/* end of catch statement */
  4619. return hr;
  4620. }/* end of function ProcessEvents */
  4621. /*************************************************************************/
  4622. /* Function: get_WindowlessActivation */
  4623. /* Description: Gets if we we tried to be windowless activated or not. */
  4624. /*************************************************************************/
  4625. STDMETHODIMP CMSWebDVD::get_WindowlessActivation(VARIANT_BOOL *pVal){
  4626. HRESULT hr = S_OK;
  4627. try {
  4628. if(NULL == pVal){
  4629. throw(E_POINTER);
  4630. }/* end of if statement */
  4631. BOOL fUserMode = FALSE;
  4632. GetAmbientUserMode(fUserMode);
  4633. if(READYSTATE_COMPLETE == m_nReadyState && fUserMode){
  4634. // case when we are up and running
  4635. *pVal = m_bWndLess == FALSE ? VARIANT_FALSE: VARIANT_TRUE;
  4636. }
  4637. else {
  4638. *pVal = m_bWindowOnly == TRUE ? VARIANT_FALSE: VARIANT_TRUE;
  4639. }/* end of if statement */
  4640. }/* end of try statement */
  4641. catch(HRESULT hrTmp){
  4642. hr = hrTmp;
  4643. }/* end of catch statement */
  4644. catch(...){
  4645. hr = E_UNEXPECTED;
  4646. }/* end of catch statement */
  4647. return HandleError(hr);
  4648. }/* end of function get_WindowlessActivation */
  4649. /*************************************************************************/
  4650. /* Function: put_WindowlessActivation */
  4651. /* Description: This sets the windowless mode, should be set from the */
  4652. /* property bag. */
  4653. /*************************************************************************/
  4654. STDMETHODIMP CMSWebDVD::put_WindowlessActivation(VARIANT_BOOL newVal){
  4655. HRESULT hr = S_OK;
  4656. try {
  4657. if(VARIANT_FALSE == newVal){
  4658. m_bWindowOnly = TRUE;
  4659. m_fUseDDrawDirect = false;
  4660. }
  4661. else {
  4662. m_bWindowOnly = FALSE;
  4663. m_fUseDDrawDirect = true;
  4664. }/* end of if statement */
  4665. // TODO: This function should fail after we inplace activated !!
  4666. }/* end of try statement */
  4667. catch(HRESULT hrTmp){
  4668. hr = hrTmp;
  4669. }/* end of catch statement */
  4670. catch(...){
  4671. hr = E_UNEXPECTED;
  4672. }/* end of catch statement */
  4673. return HandleError(hr);
  4674. }/* end of function put_WindowlessActivation */
  4675. /*************************************************************************/
  4676. /* Function: get_DisableAutoMouseProcessing */
  4677. /* Description: Gets the current state of the mouse processing code. */
  4678. /*************************************************************************/
  4679. STDMETHODIMP CMSWebDVD::get_DisableAutoMouseProcessing(VARIANT_BOOL *pVal){
  4680. HRESULT hr = S_OK;
  4681. try {
  4682. if(NULL == pVal){
  4683. throw(E_POINTER);
  4684. }/* end of if statement */
  4685. *pVal = m_fDisableAutoMouseProcessing;
  4686. }/* end of try statement */
  4687. catch(HRESULT hrTmp){
  4688. hr = hrTmp;
  4689. }/* end of catch statement */
  4690. catch(...){
  4691. hr = E_UNEXPECTED;
  4692. }/* end of catch statement */
  4693. return HandleError(hr);
  4694. }/* end of function get_DisableAutoMouseProcessing */
  4695. /*************************************************************************/
  4696. /* Function: put_DisableAutoMouseProcessing */
  4697. /* Description: Gets the state of the mouse processing. */
  4698. /*************************************************************************/
  4699. STDMETHODIMP CMSWebDVD::put_DisableAutoMouseProcessing(VARIANT_BOOL newVal){
  4700. HRESULT hr = S_OK;
  4701. try {
  4702. m_fDisableAutoMouseProcessing = VARIANT_FALSE == newVal ? false : true;
  4703. }/* end of try statement */
  4704. catch(HRESULT hrTmp){
  4705. hr = hrTmp;
  4706. }/* end of catch statement */
  4707. catch(...){
  4708. hr = E_UNEXPECTED;
  4709. }/* end of catch statement */
  4710. return HandleError(hr);
  4711. }/* end of function put_DisableAutoMouseProcessing */
  4712. /*************************************************************************/
  4713. /* Function: ActivateAtPosition */
  4714. /* Description: Activates a button at selected position. */
  4715. /*************************************************************************/
  4716. STDMETHODIMP CMSWebDVD::ActivateAtPosition(long xPos, long yPos){
  4717. HRESULT hr = S_OK;
  4718. try {
  4719. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  4720. if(!m_pDvdCtl2){
  4721. throw(E_UNEXPECTED);
  4722. }/* end of if statement */
  4723. POINT pt = {xPos, yPos};
  4724. hr = TransformToWndwls(pt);
  4725. if(FAILED(hr)){
  4726. throw(hr);
  4727. }/* end of if statement */
  4728. hr = m_pDvdCtl2->ActivateAtPosition(pt);
  4729. }/* end of try statement */
  4730. catch(HRESULT hrTmp){
  4731. hr = hrTmp;
  4732. }/* end of catch statement */
  4733. catch(...){
  4734. hr = E_UNEXPECTED;
  4735. }/* end of catch statement */
  4736. return HandleError(hr);
  4737. }/* end of function ActivateAtPosition */
  4738. /*************************************************************************/
  4739. /* Function: SelectAtPosition */
  4740. /* Description: Selects a button at selected position. */
  4741. /*************************************************************************/
  4742. STDMETHODIMP CMSWebDVD::SelectAtPosition(long xPos, long yPos){
  4743. HRESULT hr = S_OK;
  4744. try {
  4745. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  4746. if(!m_pDvdCtl2){
  4747. throw(E_UNEXPECTED);
  4748. }/* end of if statement */
  4749. POINT pt = {xPos, yPos};
  4750. hr = TransformToWndwls(pt);
  4751. if(FAILED(hr)){
  4752. throw(hr);
  4753. }/* end of if statement */
  4754. hr = m_pDvdCtl2->SelectAtPosition(pt);
  4755. }/* end of try statement */
  4756. catch(HRESULT hrTmp){
  4757. hr = hrTmp;
  4758. }/* end of catch statement */
  4759. catch(...){
  4760. hr = E_UNEXPECTED;
  4761. }/* end of catch statement */
  4762. return HandleError(hr);
  4763. }/* end of function SelectAtPosition */
  4764. /*************************************************************************/
  4765. /* Function: GetButtonAtPosition */
  4766. /* Description: Gets the button number associated with a position. */
  4767. /*************************************************************************/
  4768. STDMETHODIMP CMSWebDVD::GetButtonAtPosition(long xPos, long yPos,
  4769. long *plButton)
  4770. {
  4771. HRESULT hr = S_OK;
  4772. try {
  4773. INITIALIZE_GRAPH_IF_NEEDS_TO_BE;
  4774. if(!plButton){
  4775. throw E_POINTER;
  4776. }
  4777. if(!m_pDvdInfo2){
  4778. throw(E_UNEXPECTED);
  4779. }/* end of if statement */
  4780. POINT pt = {xPos, yPos};
  4781. hr = TransformToWndwls(pt);
  4782. if(FAILED(hr)){
  4783. throw(hr);
  4784. }/* end of if statement */
  4785. ULONG ulButton;
  4786. hr = m_pDvdInfo2->GetButtonAtPosition(pt, &ulButton);
  4787. if(SUCCEEDED(hr)){
  4788. *plButton = ulButton;
  4789. }
  4790. else {
  4791. plButton = 0;
  4792. }/* end of if statement */
  4793. }/* end of try statement */
  4794. catch(HRESULT hrTmp){
  4795. hr = hrTmp;
  4796. }/* end of catch statement */
  4797. catch(...){
  4798. hr = E_UNEXPECTED;
  4799. }/* end of catch statement */
  4800. return HandleError(hr);
  4801. }/* end of function GetButtonAtPosition */
  4802. /*************************************************************************/
  4803. /* Function: GetButtonRect */
  4804. /* Description: Gets an button rect associated with a button ID. */
  4805. /*************************************************************************/
  4806. STDMETHODIMP CMSWebDVD::GetButtonRect(long lButton, IDVDRect** ppRect){
  4807. // no support in MS DVDNav
  4808. return HandleError(E_NOTIMPL);
  4809. }/* end of function GetButtonRect */
  4810. /*************************************************************************/
  4811. /* Function: GetDVDScreenInMouseCoordinates */
  4812. /* Description: Gets the mouse coordinate screen. */
  4813. /*************************************************************************/
  4814. STDMETHODIMP CMSWebDVD::GetDVDScreenInMouseCoordinates(IDVDRect **ppRect){
  4815. // no support in MS DVDNav
  4816. return HandleError(E_NOTIMPL);
  4817. }/* end of function GetDVDScreenInMouseCoordinates */
  4818. /*************************************************************************/
  4819. /* Function: SetDVDScreenInMouseCoordinates */
  4820. /* Description: Sets the screen in mouse coordinates. */
  4821. /*************************************************************************/
  4822. STDMETHODIMP CMSWebDVD::SetDVDScreenInMouseCoordinates(IDVDRect *pRect){
  4823. // no support in MS DVDNav
  4824. return HandleError(E_NOTIMPL);
  4825. }/* end of function SetDVDScreenInMouseCoordinates */
  4826. /*************************************************************************/
  4827. /* Function: GetClipVideoRect */
  4828. /* Description: Gets the source rect that is being used. */
  4829. /*************************************************************************/
  4830. STDMETHODIMP CMSWebDVD::GetClipVideoRect(IDVDRect **ppRect){
  4831. HRESULT hr = S_OK;
  4832. IBasicVideo* pIVid = NULL;
  4833. try {
  4834. if(NULL == ppRect){
  4835. throw(E_POINTER);
  4836. }/* end of if statement */
  4837. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  4838. // If windowless and m_pDvdClipRect hasn't been yet,
  4839. // then the clipping size is the default video size
  4840. if (m_bWndLess && !m_pClipRect) {
  4841. return GetVideoSize(ppRect);
  4842. }
  4843. long lLeft=0, lTop=0, lWidth=0, lHeight=0;
  4844. hr = ::CoCreateInstance(CLSID_DVDRect, NULL, CLSCTX_INPROC, IID_IDVDRect, (LPVOID*) ppRect);
  4845. if(FAILED(hr)){
  4846. throw(hr);
  4847. }/* end of if statement */
  4848. IDVDRect* pIRect = *ppRect; // just to make the code esier to read
  4849. // Windowed case, it'll be cached in m_rcvdClipRect
  4850. if (m_bWndLess) {
  4851. // get it from cached m_pDvdClipRect
  4852. hr = pIRect->put_x(m_pClipRect->left);
  4853. if(FAILED(hr)){
  4854. throw(hr);
  4855. }/* end of if statement */
  4856. hr = pIRect->put_y(m_pClipRect->top);
  4857. if(FAILED(hr)){
  4858. throw(hr);
  4859. }/* end of if statement */
  4860. hr = pIRect->put_Width(RECTWIDTH(m_pClipRect));
  4861. if(FAILED(hr)){
  4862. throw(hr);
  4863. }/* end of if statement */
  4864. hr = pIRect->put_Height(RECTHEIGHT(m_pClipRect));
  4865. if(FAILED(hr)){
  4866. throw(hr);
  4867. }/* end of if statement */
  4868. }
  4869. // Windowed case, get it from IBasicVideo
  4870. else {
  4871. hr = TraverseForInterface(IID_IBasicVideo, (LPVOID*) &pIVid);
  4872. if(FAILED(hr)){
  4873. throw(hr);
  4874. }/* end of if statement */
  4875. hr = pIVid->GetSourcePosition(&lLeft, &lTop, &lWidth, &lHeight);
  4876. pIVid->Release();
  4877. if(FAILED(hr)){
  4878. throw(hr);
  4879. }/* end of if statement */
  4880. hr = pIRect->put_x(lLeft);
  4881. if(FAILED(hr)){
  4882. throw(hr);
  4883. }/* end of if statement */
  4884. hr = pIRect->put_y(lTop);
  4885. if(FAILED(hr)){
  4886. throw(hr);
  4887. }/* end of if statement */
  4888. hr = pIRect->put_Width(lWidth);
  4889. if(FAILED(hr)){
  4890. throw(hr);
  4891. }/* end of if statement */
  4892. hr = pIRect->put_Height(lHeight);
  4893. if(FAILED(hr)){
  4894. throw(hr);
  4895. }/* end of if statement */
  4896. }
  4897. }/* end of try statement */
  4898. catch(HRESULT hrTmp){
  4899. if(NULL != pIVid){
  4900. pIVid->Release();
  4901. pIVid = NULL;
  4902. }/* end of if statement */
  4903. hr = hrTmp;
  4904. }/* end of catch statement */
  4905. catch(...){
  4906. if(NULL != pIVid){
  4907. pIVid->Release();
  4908. pIVid = NULL;
  4909. }/* end of if statement */
  4910. hr = E_UNEXPECTED;
  4911. }/* end of catch statement */
  4912. return HandleError(hr);
  4913. }/* end of function GetClipVideoRect */
  4914. /*************************************************************************/
  4915. /* Function: GetVideoSize */
  4916. /* Description: Gets the video, size. 0, 0 for origin for now. */
  4917. /*************************************************************************/
  4918. STDMETHODIMP CMSWebDVD::GetVideoSize(IDVDRect **ppRect){
  4919. HRESULT hr = S_OK;
  4920. IBasicVideo* pIVid = NULL;
  4921. try {
  4922. if(NULL == ppRect){
  4923. throw(E_POINTER);
  4924. }/* end of if statement */
  4925. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  4926. // Windowless case
  4927. if(m_bWndLess){
  4928. if(!m_pDDEX){
  4929. throw(E_UNEXPECTED);
  4930. }/* end of if statement */
  4931. DWORD dwVideoWidth, dwVideoHeight, dwAspectX, dwAspectY;
  4932. hr = m_pDDEX->GetNativeVideoProps(&dwVideoWidth, &dwVideoHeight, &dwAspectX, &dwAspectY);
  4933. if(FAILED(hr)){
  4934. throw(hr);
  4935. }/* end of if statement */
  4936. m_dwVideoWidth = dwVideoWidth;
  4937. m_dwVideoHeight = dwVideoWidth*3/4;
  4938. //m_dwVideoHeight = dwVideoHeight;
  4939. m_dwAspectX = dwAspectX;
  4940. m_dwAspectY = dwAspectY;
  4941. //ATLTRACE(TEXT("GetNativeVideoProps %d %d %d %d\n"), dwVideoWidth, dwVideoHeight, dwAspectX, dwAspectY);
  4942. }
  4943. // Windowed case, get it from IBasicVideo
  4944. else {
  4945. hr = TraverseForInterface(IID_IBasicVideo, (LPVOID*) &pIVid);
  4946. if(FAILED(hr)){
  4947. throw(hr);
  4948. }/* end of if statement */
  4949. hr = pIVid->GetVideoSize((LONG*)&m_dwVideoWidth, (LONG*)&m_dwVideoHeight);
  4950. pIVid->Release();
  4951. if(FAILED(hr)){
  4952. throw(hr);
  4953. }/* end of if statement */
  4954. }/* end of if statement */
  4955. hr = ::CoCreateInstance(CLSID_DVDRect, NULL, CLSCTX_INPROC, IID_IDVDRect, (LPVOID*) ppRect);
  4956. if(FAILED(hr)){
  4957. throw(hr);
  4958. }/* end of if statement */
  4959. IDVDRect* pIRect = *ppRect; // just to make the code esier to read
  4960. hr = pIRect->put_Width(m_dwVideoWidth);
  4961. if(FAILED(hr)){
  4962. throw(hr);
  4963. }/* end of if statement */
  4964. hr = pIRect->put_Height(m_dwVideoHeight);
  4965. if(FAILED(hr)){
  4966. throw(hr);
  4967. }/* end of if statement */
  4968. }/* end of try statement */
  4969. catch(HRESULT hrTmp){
  4970. hr = hrTmp;
  4971. if(NULL != pIVid){
  4972. pIVid->Release();
  4973. pIVid = NULL;
  4974. }/* end of if statement */
  4975. }/* end of catch statement */
  4976. catch(...){
  4977. hr = E_UNEXPECTED;
  4978. if(NULL != pIVid){
  4979. pIVid->Release();
  4980. pIVid = NULL;
  4981. }/* end of if statement */
  4982. }/* end of catch statement */
  4983. return HandleError(hr);
  4984. }/* end of function GetVideoSize */
  4985. /*************************************************************/
  4986. /* Name: AdjustDestRC
  4987. /* Description: Adjust dest RC to the right aspect ratio
  4988. /*************************************************************/
  4989. HRESULT CMSWebDVD::AdjustDestRC(){
  4990. if(!m_fInitialized){
  4991. return(E_FAIL);
  4992. }/* end of if statement */
  4993. m_rcPosAspectRatioAjusted = m_rcPos;
  4994. RECT rc = m_rcPos;
  4995. //ATLTRACE(TEXT("Dest Rect %d %d %d %d\n"), rc.left, rc.top, rc.right, rc.bottom);
  4996. long width = RECTWIDTH(&rc);
  4997. long height = RECTHEIGHT(&rc);
  4998. // Make sure we get the right aspect ratio
  4999. CComPtr<IDVDRect> pDvdRect;
  5000. HRESULT hr = GetVideoSize(&pDvdRect);
  5001. if (FAILED(hr))
  5002. return hr;
  5003. double aspectRatio = m_dwAspectX/(double)m_dwAspectY;
  5004. long adjustedHeight, adjustedWidth;
  5005. adjustedHeight = long (width / aspectRatio);
  5006. if (adjustedHeight<=height) {
  5007. rc.top += (height-adjustedHeight)/2;
  5008. rc.bottom = rc.top + adjustedHeight;
  5009. }
  5010. else {
  5011. adjustedWidth = long (height * aspectRatio);
  5012. rc.left += (width - adjustedWidth)/2;
  5013. rc.right = rc.left + adjustedWidth;
  5014. }
  5015. //ATLTRACE(TEXT("Ajusted Dest Rect %d %d %d %d\n"), rc.left, rc.top, rc.right, rc.bottom);
  5016. m_rcPosAspectRatioAjusted = rc;
  5017. return S_OK;
  5018. }
  5019. /*************************************************************************/
  5020. /* Function: SetClipVideoRect */
  5021. /* Description: Set a video source rect. TODO: Might want to handle */
  5022. /* preserving aspect ratio. */
  5023. /*************************************************************************/
  5024. STDMETHODIMP CMSWebDVD::SetClipVideoRect(IDVDRect *pIRect){
  5025. HRESULT hr = S_OK;
  5026. IBasicVideo* pIVid = NULL;
  5027. try {
  5028. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  5029. long lLeft = 0, lTop = 0, lWidth = 0, lHeight = 0;
  5030. if(NULL == pIRect){
  5031. if (m_pClipRect) {
  5032. delete m_pClipRect;
  5033. m_pClipRect = NULL;
  5034. } /* end of if statement */
  5035. }
  5036. else {
  5037. hr = pIRect->get_x(&lLeft);
  5038. if(FAILED(hr)){
  5039. throw(hr);
  5040. }/* end of if statement */
  5041. hr = pIRect->get_y(&lTop);
  5042. if(FAILED(hr)){
  5043. throw(hr);
  5044. }/* end of if statement */
  5045. hr = pIRect->get_Width(&lWidth);
  5046. if(FAILED(hr)){
  5047. throw(hr);
  5048. }/* end of if statement */
  5049. hr = pIRect->get_Height(&lHeight);
  5050. if(FAILED(hr)){
  5051. throw(hr);
  5052. }/* end of if statement */
  5053. }
  5054. CComPtr<IDVDRect> pDvdRect;
  5055. hr = GetVideoSize(&pDvdRect);
  5056. if (FAILED(hr))
  5057. throw(hr);
  5058. // Get video width and height
  5059. long videoWidth, videoHeight;
  5060. pDvdRect->get_Width(&videoWidth);
  5061. pDvdRect->get_Height(&videoHeight);
  5062. if (lLeft < 0 || lLeft >= videoWidth || lTop < 0 || lTop >= videoHeight){
  5063. throw(E_INVALIDARG);
  5064. }/* end of if statement */
  5065. if (lLeft+lWidth > videoWidth || lTop+lHeight > videoHeight){
  5066. throw(E_INVALIDARG);
  5067. }/* end of if statement */
  5068. // Windowless case
  5069. if (m_bWndLess) {
  5070. #if 0
  5071. hr = AdjustDestRC();
  5072. if(FAILED(hr)){
  5073. throw(hr);
  5074. }/* end of if statement */
  5075. RECT rc = m_rcPosAspectRatioAjusted;
  5076. if (!pIRect)
  5077. rc = m_rcPos;
  5078. #else
  5079. RECT rc = m_rcPos;
  5080. #endif
  5081. HWND hwnd;
  5082. hr = GetUsableWindow(&hwnd);
  5083. if(FAILED(hr)){
  5084. return(hr);
  5085. }/* end of if statement */
  5086. ::MapWindowPoints(hwnd, ::GetDesktopWindow(), (LPPOINT)&rc, 2);
  5087. //ATLTRACE(TEXT("Ajusted Dest Rect %d %d %d %d\n"), rc.left, rc.top, rc.right, rc.bottom);
  5088. if(m_pDDEX){
  5089. if (pIRect) {
  5090. if (!m_pClipRect)
  5091. m_pClipRect = new RECT;
  5092. m_pClipRect->left = lLeft;
  5093. m_pClipRect->top = lTop;
  5094. m_pClipRect->right = lLeft+lWidth;
  5095. m_pClipRect->bottom = lTop + lHeight;
  5096. hr = m_pDDEX->SetDrawParameters(m_pClipRect, &rc);
  5097. }
  5098. else {
  5099. hr = m_pDDEX->SetDrawParameters(NULL, &rc);
  5100. }
  5101. }/* end of if statement */
  5102. }/* end of if statement */
  5103. // Windowed case, set it via IBasicVideo
  5104. else {
  5105. hr = TraverseForInterface(IID_IBasicVideo, (LPVOID*) &pIVid);
  5106. if(FAILED(hr)){
  5107. throw(hr);
  5108. }/* end of if statement */
  5109. if (pIRect) {
  5110. if (!m_pClipRect)
  5111. m_pClipRect = new RECT;
  5112. m_pClipRect->left = lLeft;
  5113. m_pClipRect->top = lTop;
  5114. m_pClipRect->right = lLeft+lWidth;
  5115. m_pClipRect->bottom = lTop + lHeight;
  5116. hr = pIVid->SetSourcePosition(lLeft, lTop, lWidth, lHeight);
  5117. }
  5118. else {
  5119. hr = pIVid->SetDefaultSourcePosition();
  5120. }
  5121. if(FAILED(hr)){
  5122. throw(hr);
  5123. }/* end of if statement */
  5124. //hr = pIVid->SetDestinationPosition(m_rcPos.left, m_rcPos.top, WIDTH(&m_rcPos), HEIGHT(&m_rcPos));
  5125. pIVid->Release();
  5126. pIVid = NULL;
  5127. #if 0
  5128. if(FAILED(hr)){
  5129. throw(hr);
  5130. }/* end of if statement */
  5131. #endif
  5132. }
  5133. }
  5134. catch(HRESULT hrTmp){
  5135. if(NULL != pIVid){
  5136. pIVid->Release();
  5137. pIVid = NULL;
  5138. }/* end of if statement */
  5139. hr = hrTmp;
  5140. }/* end of catch statement */
  5141. catch(...){
  5142. if(NULL != pIVid){
  5143. pIVid->Release();
  5144. pIVid = NULL;
  5145. }/* end of if statement */
  5146. hr = E_UNEXPECTED;
  5147. }/* end of catch statement */
  5148. return HandleError(hr);
  5149. }/* end of function SetClipVideoRect */
  5150. /*************************************************************************/
  5151. /* Function: get_DVDAdm */
  5152. /* Description: Returns DVD admin interface. */
  5153. /*************************************************************************/
  5154. STDMETHODIMP CMSWebDVD::get_DVDAdm(IDispatch **pVal){
  5155. HRESULT hr = S_OK;
  5156. try {
  5157. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  5158. if (m_pDvdAdmin){
  5159. hr = m_pDvdAdmin->QueryInterface(IID_IDispatch, (LPVOID*)pVal);
  5160. }
  5161. else {
  5162. *pVal = NULL;
  5163. throw(E_FAIL);
  5164. }/* end of if statement */
  5165. }/* end of try statement */
  5166. catch(HRESULT hrTmp){
  5167. hr = hrTmp;
  5168. }/* end of catch statement */
  5169. catch(...){
  5170. hr = E_UNEXPECTED;
  5171. }/* end of catch statement */
  5172. return HandleError(hr);
  5173. }/* end of function get_DVDAdm */
  5174. /*************************************************************************/
  5175. /* Function: GetPlayerParentalLevel */
  5176. /* Description: Gets the player parental level. *
  5177. /*************************************************************************/
  5178. STDMETHODIMP CMSWebDVD::GetPlayerParentalLevel(long *plParentalLevel){
  5179. HRESULT hr = S_OK;
  5180. try {
  5181. if(NULL == plParentalLevel){
  5182. throw(E_POINTER);
  5183. }/* end of if statement */
  5184. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  5185. if(!m_pDvdInfo2){
  5186. throw(E_UNEXPECTED);
  5187. }/* end of if statement */
  5188. ULONG ulLevel;
  5189. BYTE bCountryCode[2];
  5190. hr = m_pDvdInfo2->GetPlayerParentalLevel(&ulLevel, bCountryCode);
  5191. if(SUCCEEDED(hr)){
  5192. *plParentalLevel = ulLevel;
  5193. }
  5194. else {
  5195. *plParentalLevel = 0;
  5196. }/* end of if statement */
  5197. }/* end of try statement */
  5198. catch(HRESULT hrTmp){
  5199. hr = hrTmp;
  5200. }/* end of catch statement */
  5201. catch(...){
  5202. hr = E_UNEXPECTED;
  5203. }/* end of catch statement */
  5204. return HandleError(hr);
  5205. }/* end of function GetPlayerParentalLevel */
  5206. /*************************************************************************/
  5207. /* Function: GetPlayerParentalCountry */
  5208. /* Description: Gets the player parental country. */
  5209. /*************************************************************************/
  5210. STDMETHODIMP CMSWebDVD::GetPlayerParentalCountry(long *plCountryCode){
  5211. HRESULT hr = S_OK;
  5212. try {
  5213. if(NULL == plCountryCode){
  5214. throw(E_POINTER);
  5215. }/* end of if statement */
  5216. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  5217. if(!m_pDvdInfo2){
  5218. throw(E_UNEXPECTED);
  5219. }/* end of if statement */
  5220. BYTE bCountryCode[2];
  5221. ULONG ulLevel;
  5222. hr = m_pDvdInfo2->GetPlayerParentalLevel(&ulLevel, bCountryCode);
  5223. if(SUCCEEDED(hr)){
  5224. *plCountryCode = bCountryCode[0]<<8 | bCountryCode[1];
  5225. }
  5226. else {
  5227. *plCountryCode = 0;
  5228. }/* end of if statement */
  5229. }/* end of try statement */
  5230. catch(HRESULT hrTmp){
  5231. hr = hrTmp;
  5232. }/* end of catch statement */
  5233. catch(...){
  5234. hr = E_UNEXPECTED;
  5235. }/* end of catch statement */
  5236. return HandleError(hr);
  5237. }/* end of function GetPlayerParentalCountry */
  5238. /*************************************************************************/
  5239. /* Function: GetTitleParentalLevels */
  5240. /* Description: Gets the parental level associated with a specific title.*/
  5241. /*************************************************************************/
  5242. STDMETHODIMP CMSWebDVD::GetTitleParentalLevels(long lTitle, long *plParentalLevels){
  5243. HRESULT hr = S_OK;
  5244. try {
  5245. if(NULL == plParentalLevels){
  5246. throw(E_POINTER);
  5247. }/* end of if statement */
  5248. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  5249. if(!m_pDvdInfo2){
  5250. throw(E_UNEXPECTED);
  5251. }/* end of if statement */
  5252. ULONG ulLevel;
  5253. hr = m_pDvdInfo2->GetTitleParentalLevels(lTitle, &ulLevel);
  5254. if(SUCCEEDED(hr)){
  5255. *plParentalLevels = ulLevel;
  5256. }
  5257. else {
  5258. *plParentalLevels = 0;
  5259. }/* end of if statement */
  5260. }/* end of try statement */
  5261. catch(HRESULT hrTmp){
  5262. hr = hrTmp;
  5263. }/* end of catch statement */
  5264. catch(...){
  5265. hr = E_UNEXPECTED;
  5266. }/* end of catch statement */
  5267. return HandleError(hr);
  5268. }/* end of function GetTitleParentalLevels */
  5269. /*************************************************************************/
  5270. /* Function: SelectParentalLevel */
  5271. /* Description: Selects the parental level. */
  5272. /*************************************************************************/
  5273. STDMETHODIMP CMSWebDVD::SelectParentalLevel(long lParentalLevel, BSTR strUserName, BSTR strPassword){
  5274. HRESULT hr = S_OK;
  5275. try {
  5276. if (lParentalLevel != LEVEL_DISABLED &&
  5277. (lParentalLevel < LEVEL_G || lParentalLevel > LEVEL_ADULT)) {
  5278. throw (E_INVALIDARG);
  5279. } /* end of if statement */
  5280. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  5281. // Confirm password first
  5282. VARIANT_BOOL temp;
  5283. hr = m_pDvdAdmin->_ConfirmPassword(NULL, strPassword, &temp);
  5284. if (temp == VARIANT_FALSE)
  5285. throw (E_ACCESSDENIED);
  5286. hr = SelectParentalLevel(lParentalLevel);
  5287. }
  5288. catch(HRESULT hrTmp){
  5289. hr = hrTmp;
  5290. }
  5291. catch(...){
  5292. hr = E_UNEXPECTED;
  5293. }
  5294. return HandleError(hr);
  5295. }
  5296. /*************************************************************************/
  5297. /* Function: SelectParentalLevel */
  5298. /* Description: Selects the parental level. */
  5299. /*************************************************************************/
  5300. HRESULT CMSWebDVD::SelectParentalLevel(long lParentalLevel){
  5301. HRESULT hr = S_OK;
  5302. try {
  5303. //INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  5304. if(!m_pDvdCtl2){
  5305. throw(E_UNEXPECTED);
  5306. }/* end of if statement */
  5307. hr = m_pDvdCtl2->SelectParentalLevel(lParentalLevel);
  5308. }/* end of try statement */
  5309. catch(HRESULT hrTmp){
  5310. hr = hrTmp;
  5311. }/* end of catch statement */
  5312. catch(...){
  5313. hr = E_UNEXPECTED;
  5314. }/* end of catch statement */
  5315. return (hr);
  5316. }/* end of function SelectParentalLevel */
  5317. /*************************************************************************/
  5318. /* Function: SelectParentalCountry */
  5319. /* Description: Selects Parental Country. */
  5320. /*************************************************************************/
  5321. STDMETHODIMP CMSWebDVD::SelectParentalCountry(long lCountry, BSTR strUserName, BSTR strPassword){
  5322. HRESULT hr = S_OK;
  5323. try {
  5324. if(lCountry < 0 && lCountry > 0xffff){
  5325. throw(E_INVALIDARG);
  5326. }/* end of if statement */
  5327. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  5328. // Confirm password first
  5329. VARIANT_BOOL temp;
  5330. hr = m_pDvdAdmin->_ConfirmPassword(NULL, strPassword, &temp);
  5331. if (temp == VARIANT_FALSE)
  5332. throw (E_ACCESSDENIED);
  5333. hr = SelectParentalCountry(lCountry);
  5334. }
  5335. catch(HRESULT hrTmp){
  5336. hr = hrTmp;
  5337. }
  5338. catch(...){
  5339. hr = E_UNEXPECTED;
  5340. }
  5341. return HandleError(hr);
  5342. }
  5343. /*************************************************************************/
  5344. /* Function: SelectParentalCountry */
  5345. /* Description: Selects Parental Country. */
  5346. /*************************************************************************/
  5347. HRESULT CMSWebDVD::SelectParentalCountry(long lCountry){
  5348. HRESULT hr = S_OK;
  5349. try {
  5350. if(!m_pDvdCtl2){
  5351. throw(E_UNEXPECTED);
  5352. }/* end of if statement */
  5353. BYTE bCountryCode[2];
  5354. bCountryCode[0] = BYTE(lCountry>>8);
  5355. bCountryCode[1] = BYTE(lCountry);
  5356. hr = m_pDvdCtl2->SelectParentalCountry(bCountryCode);
  5357. }/* end of try statement */
  5358. catch(HRESULT hrTmp){
  5359. hr = hrTmp;
  5360. }/* end of catch statement */
  5361. catch(...){
  5362. hr = E_UNEXPECTED;
  5363. }/* end of catch statement */
  5364. return (hr);
  5365. }/* end of function SelectParentalCountry */
  5366. /*************************************************************************/
  5367. /* Function: put_NotifyParentalLevelChange */
  5368. /* Description: Sets the flag if to notify when parental level change */
  5369. /* notification is required on the fly. */
  5370. /*************************************************************************/
  5371. STDMETHODIMP CMSWebDVD::NotifyParentalLevelChange(VARIANT_BOOL fNotify){
  5372. HRESULT hr = S_OK;
  5373. try {
  5374. //TODO: Add IE parantal level control
  5375. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  5376. if(!m_pDvdCtl2){
  5377. throw(E_UNEXPECTED);
  5378. }/* end of if statement */
  5379. hr = m_pDvdCtl2->SetOption(DVD_NotifyParentalLevelChange,
  5380. VARIANT_FALSE == fNotify? FALSE : TRUE);
  5381. }/* end of try statement */
  5382. catch(HRESULT hrTmp){
  5383. hr = hrTmp;
  5384. }/* end of catch statement */
  5385. catch(...){
  5386. hr = E_UNEXPECTED;
  5387. }/* end of catch statement */
  5388. return HandleError(hr);
  5389. }/* end of function NotifyParentalLevelChange */
  5390. /*************************************************************************/
  5391. /* Function: AcceptParentalLevelChange */
  5392. /* Description: Accepts the temprary parental level change that is */
  5393. /* done on the fly. */
  5394. /*************************************************************************/
  5395. STDMETHODIMP CMSWebDVD::AcceptParentalLevelChange(VARIANT_BOOL fAccept, BSTR strUserName, BSTR strPassword){
  5396. VARIANT_BOOL fRight;
  5397. HRESULT hr = m_pDvdAdmin->_ConfirmPassword(NULL, strPassword, &fRight);
  5398. // if password is wrong and want to accept, no
  5399. if (fAccept != VARIANT_FALSE && fRight == VARIANT_FALSE)
  5400. return E_ACCESSDENIED;
  5401. try {
  5402. // should not make sense to do initialization here, since this should
  5403. // be a response to a callback
  5404. //INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  5405. if(!m_pDvdCtl2){
  5406. throw(E_UNEXPECTED);
  5407. }/* end of if statement */
  5408. hr = m_pDvdCtl2->AcceptParentalLevelChange(VARIANT_FALSE == fAccept? FALSE : TRUE);
  5409. }/* end of try statement */
  5410. catch(HRESULT hrTmp){
  5411. hr = hrTmp;
  5412. }/* end of catch statement */
  5413. catch(...){
  5414. hr = E_UNEXPECTED;
  5415. }/* end of catch statement */
  5416. return HandleError(hr);
  5417. }/* end of function AcceptParentalLevelChange */
  5418. /*************************************************************/
  5419. /* Name: Eject */
  5420. /* Description: Stop DVD playback and eject DVD from drive */
  5421. /* Inserts the disk as well. */
  5422. /*************************************************************/
  5423. STDMETHODIMP CMSWebDVD::Eject(){
  5424. HRESULT hr = S_OK;
  5425. try {
  5426. USES_CONVERSION;
  5427. DWORD dwHandle;
  5428. BSTR root;
  5429. hr = get_DVDDirectory(&root);
  5430. if (FAILED(hr))
  5431. throw (hr);
  5432. LPTSTR szDriveLetter = OLE2T(root);
  5433. ::SysFreeString(root);
  5434. if(m_bEjected == false){
  5435. if(szDriveLetter[0] == 0){
  5436. throw(S_FALSE);
  5437. }/* end of if statement */
  5438. DWORD dwErr;
  5439. dwHandle = OpenCdRom(szDriveLetter[0], &dwErr);
  5440. if (dwErr != MMSYSERR_NOERROR){
  5441. throw(S_FALSE);
  5442. }/* end of if statement */
  5443. EjectCdRom(dwHandle);
  5444. }
  5445. else{
  5446. //do uneject
  5447. DWORD dwErr;
  5448. dwHandle = OpenCdRom(szDriveLetter[0], &dwErr);
  5449. if (dwErr != MMSYSERR_NOERROR){
  5450. throw(S_FALSE);
  5451. }/* end of if statement */
  5452. UnEjectCdRom(dwHandle);
  5453. }/* end of if statement */
  5454. CloseCdRom(dwHandle);
  5455. }/* end of try statement */
  5456. catch(HRESULT hrTmp){
  5457. hr = hrTmp;
  5458. }/* end of catch statement */
  5459. catch(...){
  5460. hr = E_UNEXPECTED;
  5461. }/* end of catch statement */
  5462. return HandleError(hr);
  5463. }/* end of function Eject */
  5464. /*************************************************************************/
  5465. /* Function: SetGPRM */
  5466. /* Description: Sets a GPRM at index. */
  5467. /*************************************************************************/
  5468. STDMETHODIMP CMSWebDVD::SetGPRM(long lIndex, short sValue){
  5469. HRESULT hr = S_OK;
  5470. try {
  5471. if(lIndex < 0){
  5472. throw(E_INVALIDARG);
  5473. }/* end of if statement */
  5474. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  5475. if(!m_pDvdCtl2){
  5476. throw(E_UNEXPECTED);
  5477. }/* end of if statement */
  5478. hr = m_pDvdCtl2->SetGPRM(lIndex, sValue, cdwDVDCtrlFlags, 0);
  5479. }/* end of try statement */
  5480. catch(HRESULT hrTmp){
  5481. hr = hrTmp;
  5482. }/* end of catch statement */
  5483. catch(...){
  5484. hr = E_UNEXPECTED;
  5485. }/* end of catch statement */
  5486. return HandleError(hr);
  5487. }/* end of function SetGPRM */
  5488. /*************************************************************************/
  5489. /* Function: Capture */
  5490. /* Capture a image from DVD stream, convert it to RGB, and save it */
  5491. /* to file. */
  5492. /*************************************************************************/
  5493. STDMETHODIMP CMSWebDVD::Capture(){
  5494. HWND hwnd = NULL;
  5495. HRESULT hr = S_OK;
  5496. YUV_IMAGE *lpImage = NULL;
  5497. try {
  5498. hr = GetUsableWindow(&hwnd);
  5499. if(FAILED(hr)){
  5500. throw(hr);
  5501. }/* end of if statement */
  5502. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  5503. if(::IsWindow(m_hWnd)){
  5504. throw(E_NO_CAPTURE_SUPPORT);
  5505. }/* end of if statement */
  5506. if(!m_pDDEX){
  5507. throw(E_UNEXPECTED);
  5508. }/* end of if statement */
  5509. hr = m_pDDEX->IsImageCaptureSupported();
  5510. if(S_FALSE == hr){
  5511. throw(E_FORMAT_NOT_SUPPORTED);
  5512. }/* end of if statement */
  5513. hr = m_pDDEX->GetCurrentImage(&lpImage);
  5514. if (SUCCEEDED(hr))
  5515. {
  5516. #if 0
  5517. // use the GDI version first, it should work when GDI+ is installed (Millennium)
  5518. // otherwise use the standalone version
  5519. // 12.04.00 GDI+ interfaces have changed and the function needs to be rewritten
  5520. // look at this for blackcomb maybe for now just do the non-GDI+ function
  5521. hr = GDIConvertImageAndSave(lpImage, m_pClipRect, hwnd);
  5522. if(FAILED(hr))
  5523. #endif
  5524. {
  5525. hr = ConvertImageAndSave(lpImage, m_pClipRect, hwnd);
  5526. if(FAILED(hr)){
  5527. throw(hr);
  5528. }/* end of if statement */
  5529. }
  5530. }
  5531. }/* end of try statement */
  5532. catch(HRESULT hrTmp){
  5533. hr = hrTmp;
  5534. }/* end of catch statement */
  5535. catch(...){
  5536. hr = E_UNEXPECTED;
  5537. }/* end of catch statement */
  5538. if(lpImage){
  5539. CoTaskMemFree(lpImage);
  5540. }
  5541. return HandleError(hr);
  5542. }/* end of function Capture */
  5543. /*************************************************************/
  5544. /* Name: get_CursorType */
  5545. /* Description: Return cursor type over video */
  5546. /*************************************************************/
  5547. STDMETHODIMP CMSWebDVD::get_CursorType(DVDCursorType *pVal){
  5548. HRESULT hr = S_OK;
  5549. try {
  5550. if(NULL == pVal){
  5551. throw(E_POINTER);
  5552. }/* end of if statement */
  5553. *pVal = m_nCursorType;
  5554. }/* end of try statement */
  5555. catch(HRESULT hrTmp){
  5556. hr = hrTmp;
  5557. }/* end of catch statement */
  5558. catch(...){
  5559. hr = E_UNEXPECTED;
  5560. }/* end of catch statement */
  5561. return HandleError(hr);
  5562. }/* end of function get_CursorType */
  5563. /*************************************************************/
  5564. /* Name: put_CursorType */
  5565. /* Description: Set cursor type over video */
  5566. /*************************************************************/
  5567. STDMETHODIMP CMSWebDVD::put_CursorType(DVDCursorType newVal){
  5568. HRESULT hr = S_OK;
  5569. try {
  5570. if (newVal<dvdCursor_None || newVal>dvdCursor_Hand) {
  5571. throw (E_INVALIDARG);
  5572. } /* end of if statement */
  5573. m_nCursorType = newVal;
  5574. if (m_hCursor)
  5575. ::DestroyCursor(m_hCursor);
  5576. switch(m_nCursorType) {
  5577. case dvdCursor_ZoomIn:
  5578. case dvdCursor_ZoomOut:
  5579. m_hCursor = ::LoadCursor(_Module.GetModuleInstance(), MAKEINTRESOURCE(IDC_ZOOMIN));
  5580. break;
  5581. case dvdCursor_Hand:
  5582. m_hCursor = ::LoadCursor(_Module.GetModuleInstance(), MAKEINTRESOURCE(IDC_HAND));
  5583. break;
  5584. case dvdCursor_Arrow:
  5585. default:
  5586. //#define OCR_ARROW_DEFAULT 100
  5587. // need special cursor, we we do not have color key around it
  5588. //m_hCursor = (HCURSOR) ::LoadImage((HINSTANCE) NULL,
  5589. // MAKEINTRESOURCE(OCR_ARROW_DEFAULT),
  5590. // IMAGE_CURSOR,0,0,0);
  5591. m_hCursor = ::LoadCursor(NULL, MAKEINTRESOURCE(OCR_ARROW_DEFAULT));
  5592. break;
  5593. }
  5594. if (m_hCursor)
  5595. ::SetCursor(m_hCursor);
  5596. }/* end of try statement */
  5597. catch(HRESULT hrTmp){
  5598. hr = hrTmp;
  5599. }/* end of catch statement */
  5600. catch(...){
  5601. hr = E_UNEXPECTED;
  5602. }/* end of catch statement */
  5603. return HandleError(hr);
  5604. }/* end of function put_CursorType */
  5605. /*************************************************************/
  5606. /* Name: Zoom
  5607. /* Description: Zoom in at (x, y) in original video
  5608. /* enlarge or decrease video size by zoomRatio
  5609. /* if zoomRatio > 1 zoom in
  5610. /* if zoomRatio = 1
  5611. /* if zoomRatio < 1 zoom out
  5612. /* if zoomRatio <= 0 invalid
  5613. /*************************************************************/
  5614. STDMETHODIMP CMSWebDVD::Zoom(long x, long y, double zoomRatio){
  5615. HRESULT hr = S_OK;
  5616. try {
  5617. if (zoomRatio< 0){
  5618. throw(E_INVALIDARG);
  5619. }/* end of if statement */
  5620. // Can't go beyond 1.0
  5621. if (m_dZoomRatio <= 1.0) {
  5622. if (zoomRatio <= 1.0) {
  5623. m_dZoomRatio = 1.0;
  5624. throw(hr);
  5625. }
  5626. m_dZoomRatio = 1.0;
  5627. }
  5628. // Can't go beyond the max stretch factor
  5629. if (m_dZoomRatio*zoomRatio > m_dwOvMaxStretch/1000.0)
  5630. throw hr;
  5631. m_dZoomRatio *= zoomRatio;
  5632. // Can't go beyond 1.0
  5633. if (m_dZoomRatio <= 1.0)
  5634. m_dZoomRatio = 1.0;
  5635. CComPtr<IDVDRect> pDvdRect;
  5636. hr = GetVideoSize(&pDvdRect);
  5637. if (FAILED(hr))
  5638. throw(hr);
  5639. if(1.0 == m_dZoomRatio){
  5640. hr = SetClipVideoRect(NULL);
  5641. put_CursorType(dvdCursor_Arrow);
  5642. throw(hr);
  5643. }/* end of if statement */
  5644. // Get video width and height
  5645. long videoWidth, videoHeight;
  5646. pDvdRect->get_Width(&videoWidth);
  5647. pDvdRect->get_Height(&videoHeight);
  5648. if (x < 0 || x >= videoWidth || y < 0 || y >= videoHeight){
  5649. throw(E_INVALIDARG);
  5650. }/* end of if statement */
  5651. // Compute new clipping width and height
  5652. long mcd = MCD(m_dwVideoWidth, m_dwVideoHeight);
  5653. long videoX = m_dwVideoWidth/mcd;
  5654. long videoY = m_dwVideoHeight/mcd;
  5655. long newClipHeight = (long) (videoHeight/m_dZoomRatio);
  5656. newClipHeight /= videoY;
  5657. newClipHeight *= videoY;
  5658. if (newClipHeight < 1) newClipHeight = 1;
  5659. long newClipWidth = (long) (newClipHeight*videoX/videoY);
  5660. if (newClipWidth < 1) newClipWidth = 1;
  5661. // Can't go beyong native video size
  5662. if (newClipWidth>videoWidth)
  5663. newClipWidth = videoWidth;
  5664. if (newClipHeight>videoHeight)
  5665. newClipHeight = videoHeight;
  5666. if (newClipWidth == videoWidth && newClipHeight == videoHeight) {
  5667. put_CursorType(dvdCursor_Arrow);
  5668. }
  5669. else {
  5670. put_CursorType(dvdCursor_Hand);
  5671. }
  5672. long newClipX = x - newClipWidth/2;
  5673. long newClipY = y - newClipHeight/2;
  5674. // Can't go outsize the native video rect
  5675. if (newClipX < 0)
  5676. newClipX = 0;
  5677. else if (newClipX + newClipWidth > videoWidth)
  5678. newClipX = videoWidth - newClipWidth;
  5679. if (newClipY < 0)
  5680. newClipY = 0;
  5681. else if (newClipY + newClipHeight > videoHeight)
  5682. newClipY = videoHeight - newClipHeight;
  5683. CComPtr<IDVDRect> pDvdClipRect;
  5684. hr = GetClipVideoRect(&pDvdClipRect);
  5685. if (FAILED(hr))
  5686. throw(hr);
  5687. pDvdClipRect->put_x(newClipX);
  5688. pDvdClipRect->put_y(newClipY);
  5689. pDvdClipRect->put_Width(newClipWidth);
  5690. pDvdClipRect->put_Height(newClipHeight);
  5691. hr = SetClipVideoRect(pDvdClipRect);
  5692. }
  5693. catch(HRESULT hrTmp){
  5694. hr = hrTmp;
  5695. }/* end of catch statement */
  5696. catch(...){
  5697. hr = E_UNEXPECTED;
  5698. }/* end of catch statement */
  5699. return HandleError(hr);
  5700. }/* end of function Zoom */
  5701. /*************************************************************************/
  5702. /* Function: RegionChange */
  5703. /* Description:Changes the region code. */
  5704. /*************************************************************************/
  5705. STDMETHODIMP CMSWebDVD::RegionChange(){
  5706. USES_CONVERSION;
  5707. HRESULT hr = S_OK;
  5708. typedef BOOL (APIENTRY *DVDPPLAUNCHER) (HWND HWnd, CHAR DriveLetter);
  5709. try {
  5710. HWND parentWnd = NULL;
  5711. HRESULT hrTmp = GetParentHWND(&parentWnd);
  5712. if (SUCCEEDED(hrTmp) && (NULL != parentWnd)) {
  5713. // take the container out of the top-most mode
  5714. ::SetWindowPos(parentWnd, HWND_NOTOPMOST, 0, 0, 0, 0,
  5715. SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE);
  5716. }
  5717. BOOL regionChanged = FALSE;
  5718. OSVERSIONINFO ver;
  5719. ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  5720. ::GetVersionEx(&ver);
  5721. if (ver.dwPlatformId==VER_PLATFORM_WIN32_NT) {
  5722. HINSTANCE dllInstance;
  5723. DVDPPLAUNCHER dvdPPLauncher;
  5724. TCHAR szCmdLine[MAX_PATH], szDriveLetter[4];
  5725. LPSTR szDriveLetterA;
  5726. //
  5727. // tell the user why we are showing the dvd region property page
  5728. //
  5729. // DVDMessageBox(m_hWnd, IDS_REGION_CHANGE_PROMPT);
  5730. hr = getDVDDriveLetter(szDriveLetter);
  5731. if(FAILED(hr)){
  5732. hr = E_UNEXPECTED;
  5733. throw(hr);
  5734. }/* end of if statement */
  5735. szDriveLetterA = T2A(szDriveLetter);
  5736. GetSystemDirectory(szCmdLine, MAX_PATH);
  5737. StringCchCat(szCmdLine, sizeof(szCmdLine) / sizeof(szCmdLine), _T("\\storprop.dll"));
  5738. dllInstance = LoadLibrary (szCmdLine);
  5739. if (dllInstance) {
  5740. dvdPPLauncher = (DVDPPLAUNCHER) GetProcAddress(
  5741. dllInstance,
  5742. "DvdLauncher");
  5743. if (dvdPPLauncher) {
  5744. regionChanged = dvdPPLauncher(this->m_hWnd,
  5745. szDriveLetterA[0]);
  5746. }
  5747. FreeLibrary(dllInstance);
  5748. }
  5749. }
  5750. else {
  5751. #if 0 // need to check for win9x or winnt
  5752. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  5753. //Get path of \windows\dvdrgn.exe and command line string
  5754. TCHAR szCmdLine[MAX_PATH], szDriveLetter[4];
  5755. hr = getDVDDriveLetter(szDriveLetter);
  5756. if(FAILED(hr)){
  5757. throw(hr);
  5758. }/* end of if statement */
  5759. GetWindowsDirectory(szCmdLine, MAX_PATH);
  5760. StringCchCat(szCmdLine, sizeof(szCmdLine) / sizeof(szCmdLine[0]), _T("\\dvdrgn.exe "));
  5761. TCHAR strModuleName[MAX_PATH];
  5762. lstrcpyn(strModuleName, szCmdLine, sizeof(strModuleName) / sizeof(strModuleName[0]));
  5763. TCHAR csTmp[2]; ::ZeroMemory(csTmp, sizeof(TCHAR)* 2);
  5764. csTmp[0] = szDriveLetter[0];
  5765. StringCchCat(szCmdLine, sizeof(szCmdLine) / sizeof(szCmdLine[0]), csTmp);
  5766. //Prepare and execuate dvdrgn.exe
  5767. STARTUPINFO StartupInfo;
  5768. PROCESS_INFORMATION ProcessInfo;
  5769. StartupInfo.cb = sizeof(StartupInfo);
  5770. StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
  5771. StartupInfo.wShowWindow = SW_SHOW;
  5772. StartupInfo.lpReserved = NULL;
  5773. StartupInfo.lpDesktop = NULL;
  5774. StartupInfo.lpTitle = NULL;
  5775. StartupInfo.cbReserved2 = 0;
  5776. StartupInfo.lpReserved2 = NULL;
  5777. if( ::CreateProcess(strModuleName, szCmdLine, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS,
  5778. NULL, NULL, &StartupInfo, &ProcessInfo) ){
  5779. //Wait dvdrgn.exe finishes.
  5780. WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
  5781. DWORD dwRet = 1;
  5782. BOOL bRet = GetExitCodeProcess(ProcessInfo.hProcess, &dwRet);
  5783. if(dwRet == 0){
  5784. //User changed the region successfully
  5785. regionChanged = TRUE;
  5786. }
  5787. else{
  5788. throw(E_REGION_CHANGE_NOT_COMPLETED);
  5789. }
  5790. }/* end of if statement */
  5791. #endif
  5792. }/* end of if statement */
  5793. if (regionChanged) {
  5794. // start playing again
  5795. hr = Play();
  5796. }
  5797. else {
  5798. throw(E_REGION_CHANGE_FAIL);
  5799. }/* end of if statement */
  5800. }
  5801. catch(HRESULT hrTmp){
  5802. hr = hrTmp;
  5803. }/* end of catch statement */
  5804. catch(...){
  5805. hr = E_UNEXPECTED;
  5806. }/* end of catch statement */
  5807. return HandleError(hr);
  5808. }/* end of function RegionChange */
  5809. /*************************************************************************/
  5810. /* Function: getDVDDriveLetter */
  5811. /* Description: Gets the first three characters that denote the DVD-ROM */
  5812. /*************************************************************************/
  5813. HRESULT CMSWebDVD::getDVDDriveLetter(TCHAR* lpDrive) {
  5814. HRESULT hr = E_FAIL;
  5815. if(!m_pDvdInfo2){
  5816. hr = E_UNEXPECTED;
  5817. return(hr);
  5818. }/* end of if statement */
  5819. WCHAR szRoot[MAX_PATH];
  5820. ULONG ulActual;
  5821. hr = m_pDvdInfo2->GetDVDDirectory(szRoot, MAX_PATH, &ulActual);
  5822. if(FAILED(hr)){
  5823. return(hr);
  5824. }/* end of if statement */
  5825. USES_CONVERSION;
  5826. lstrcpyn(lpDrive, OLE2T(szRoot), 3);
  5827. if(::GetDriveType(&lpDrive[0]) == DRIVE_CDROM){
  5828. return(hr);
  5829. }
  5830. else {
  5831. //possibly root=c: or drive in hard disc
  5832. hr = E_FAIL;
  5833. return(hr);
  5834. }/* end of if statement */
  5835. // does not seem to make sense to loop to figure out the drive letter
  5836. #if 0
  5837. DWORD totChrs = GetLogicalDriveStrings(MAX_PATH, szTemp); //get all drives
  5838. ptr = szTemp;
  5839. for(DWORD i = 0; i < totChrs; i+=4) //look at these drives one by one
  5840. {
  5841. if(GetDriveType(ptr) == DRIVE_CDROM) //look only CD-ROM and see if it has a disc
  5842. {
  5843. TCHAR achDVDFilePath1[MAX_PATH], achDVDFilePath2[MAX_PATH];
  5844. lstrcpyn(achDVDFilePath1, ptr, 4);
  5845. lstrcpyn(achDVDFilePath2, ptr, 4);
  5846. lstrcat(achDVDFilePath1, _T("Video_ts\\Video_ts.ifo"));
  5847. lstrcat(achDVDFilePath2, _T("Video_ts\\Vts_01_0.ifo"));
  5848. if( ((CDvdplayApp*) AfxGetApp())->DoesFileExist(achDVDFilePath1) &&
  5849. ((CDvdplayApp*) AfxGetApp())->DoesFileExist(achDVDFilePath2) )
  5850. {
  5851. lstrcpyn(lpDrive, ptr, 3);
  5852. return(hr); //Return the first found drive which has a valid DVD disc
  5853. }
  5854. }
  5855. ptr += 4;
  5856. }
  5857. #endif
  5858. return(hr);
  5859. }/* end of function getDVDDriveLetter */
  5860. /*************************************************************/
  5861. /* Name: SelectDefaultAudioLanguage
  5862. /* Description:
  5863. /*************************************************************/
  5864. STDMETHODIMP CMSWebDVD::SelectDefaultAudioLanguage(long lang, long ext){
  5865. HRESULT hr = S_OK;
  5866. try {
  5867. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  5868. if(!m_pDvdCtl2 || !m_pDvdAdmin){
  5869. throw(E_UNEXPECTED);
  5870. }/* end of if statement */
  5871. hr = m_pDvdCtl2->SelectDefaultAudioLanguage(lang, (DVD_AUDIO_LANG_EXT)ext);
  5872. if (FAILED(hr))
  5873. throw(hr);
  5874. // Save it with DVDAdmin
  5875. //hr = m_pDvdAdmin->put_DefaultAudioLCID(lang);
  5876. //if (FAILED(hr))
  5877. // throw(hr);
  5878. }
  5879. catch(HRESULT hrTmp){
  5880. hr = hrTmp;
  5881. }/* end of catch statement */
  5882. catch(...){
  5883. hr = E_UNEXPECTED;
  5884. }/* end of catch statement */
  5885. return HandleError(hr);
  5886. }
  5887. /*************************************************************/
  5888. /* Name: SelectDefaultSubpictureLanguage
  5889. /* Description:
  5890. /*************************************************************/
  5891. STDMETHODIMP CMSWebDVD::SelectDefaultSubpictureLanguage(long lang, DVDSPExt ext){
  5892. HRESULT hr = S_OK;
  5893. try {
  5894. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  5895. if(!m_pDvdCtl2 || !m_pDvdAdmin){
  5896. throw(E_UNEXPECTED);
  5897. }/* end of if statement */
  5898. hr = m_pDvdCtl2->SelectDefaultSubpictureLanguage(lang, (DVD_SUBPICTURE_LANG_EXT)ext);
  5899. if (FAILED(hr))
  5900. throw(hr);
  5901. // Save it with DVDAdmin
  5902. //hr = m_pDvdAdmin->put_DefaultSubpictureLCID(lang);
  5903. //if (FAILED(hr))
  5904. // throw(hr);
  5905. }
  5906. catch(HRESULT hrTmp){
  5907. hr = hrTmp;
  5908. }/* end of catch statement */
  5909. catch(...){
  5910. hr = E_UNEXPECTED;
  5911. }/* end of catch statement */
  5912. return HandleError(hr);
  5913. }
  5914. /*************************************************************/
  5915. /* Name: put_DefaultMenuLanguage
  5916. /* Description:
  5917. /*************************************************************/
  5918. STDMETHODIMP CMSWebDVD::put_DefaultMenuLanguage(long lang){
  5919. HRESULT hr = S_OK;
  5920. try {
  5921. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  5922. if(!m_pDvdCtl2 || !m_pDvdAdmin){
  5923. throw(E_UNEXPECTED);
  5924. }/* end of if statement */
  5925. hr = m_pDvdCtl2->SelectDefaultMenuLanguage(lang);
  5926. if (FAILED(hr))
  5927. throw(hr);
  5928. // Save it with DVDAdmin
  5929. //hr = m_pDvdAdmin->put_DefaultMenuLCID(lang);
  5930. //if (FAILED(hr))
  5931. // throw(hr);
  5932. }
  5933. catch(HRESULT hrTmp){
  5934. hr = hrTmp;
  5935. }/* end of catch statement */
  5936. catch(...){
  5937. hr = E_UNEXPECTED;
  5938. }/* end of catch statement */
  5939. return HandleError(hr);
  5940. }
  5941. /*************************************************************************/
  5942. /* Function: get_PreferredSubpictureStream */
  5943. /* Description: Gets current audio stream. */
  5944. /*************************************************************************/
  5945. STDMETHODIMP CMSWebDVD::get_PreferredSubpictureStream(long *plPreferredStream){
  5946. HRESULT hr = S_OK;
  5947. try {
  5948. if (NULL == plPreferredStream){
  5949. throw(E_POINTER);
  5950. }/* end of if statement */
  5951. LCID langDefaultSP;
  5952. m_pDvdAdmin->get_DefaultSubpictureLCID((long*)&langDefaultSP);
  5953. // if none has been set
  5954. if (langDefaultSP == (LCID) -1) {
  5955. *plPreferredStream = 0;
  5956. return hr;
  5957. } /* end of if statement */
  5958. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  5959. if(!m_pDvdInfo2){
  5960. throw(E_UNEXPECTED);
  5961. }/* end of if statement */
  5962. USES_CONVERSION;
  5963. LCID lcid = 0;
  5964. ULONG ulNumAudioStreams = 0;
  5965. ULONG ulCurrentStream = 0;
  5966. BOOL fDisabled = TRUE;
  5967. RETRY_IF_IN_FPDOM(m_pDvdInfo2->GetCurrentSubpicture(&ulNumAudioStreams, &ulCurrentStream, &fDisabled));
  5968. *plPreferredStream = 0;
  5969. for (ULONG i = 0; i<ulNumAudioStreams; i++) {
  5970. hr = m_pDvdInfo2->GetSubpictureLanguage(i, &lcid);
  5971. if (SUCCEEDED( hr ) && lcid){
  5972. if (lcid == langDefaultSP) {
  5973. *plPreferredStream = i;
  5974. }
  5975. }
  5976. }
  5977. }
  5978. catch(HRESULT hrTmp){
  5979. return hrTmp;
  5980. }/* end of catch statement */
  5981. catch(...){
  5982. return E_UNEXPECTED;
  5983. }/* end of catch statement */
  5984. return HandleError(hr);
  5985. }
  5986. /*************************************************************/
  5987. /* Name: get_AspectRatio
  5988. /* Description:
  5989. /*************************************************************/
  5990. STDMETHODIMP CMSWebDVD::get_AspectRatio(double *pVal)
  5991. {
  5992. HRESULT hr = S_OK;
  5993. // Make sure we get the right aspect ratio
  5994. try {
  5995. if (NULL == pVal){
  5996. throw(E_POINTER);
  5997. }/* end of if statement */
  5998. CComPtr<IDVDRect> pDvdRect;
  5999. hr = GetVideoSize(&pDvdRect);
  6000. if (FAILED(hr))
  6001. throw(hr);
  6002. //ATLTRACE(TEXT("get_AspectRatio, %d %d \n"), m_dwAspectX, m_dwAspectY);
  6003. *pVal = (m_dwAspectX*1.0)/m_dwAspectY;
  6004. }
  6005. catch(HRESULT hrTmp){
  6006. return hrTmp;
  6007. }/* end of catch statement */
  6008. catch(...){
  6009. return E_UNEXPECTED;
  6010. }/* end of catch statement */
  6011. return HandleError(hr);
  6012. }
  6013. /*************************************************************************/
  6014. /* Function: CanStep */
  6015. /*************************************************************************/
  6016. STDMETHODIMP CMSWebDVD::CanStep(VARIANT_BOOL fBackwards, VARIANT_BOOL *pfCan){
  6017. HRESULT hr = S_OK;
  6018. try {
  6019. if (NULL == pfCan){
  6020. throw(E_POINTER);
  6021. }/* end of if statement */
  6022. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  6023. *pfCan = VARIANT_FALSE;
  6024. // Can't step if still is on
  6025. if (m_fStillOn == true) {
  6026. throw (hr);
  6027. }/* end of if statement */
  6028. if(!m_pVideoFrameStep){
  6029. throw(E_UNEXPECTED);
  6030. }/* end of if statement */
  6031. if(VARIANT_FALSE != fBackwards){
  6032. if(S_OK != CanStepBackwards()){
  6033. // we cannot step on decodors that do not provide smooth backward playback
  6034. //*pfCan = VARIANT_FALSE; already set above so do not have to do that any more
  6035. hr = S_OK;
  6036. throw(hr);
  6037. }/* end of if statement */
  6038. }/* end of if statement */
  6039. hr = m_pVideoFrameStep->CanStep(1L, NULL);
  6040. if(S_OK == hr){
  6041. *pfCan = VARIANT_TRUE;
  6042. }/* end of if statement */
  6043. hr = S_OK;
  6044. }
  6045. catch(HRESULT hrTmp){
  6046. hr = hrTmp;
  6047. }/* end of catch statement */
  6048. catch(...){
  6049. hr = E_UNEXPECTED;
  6050. }/* end of catch statement */
  6051. return HandleError(hr);
  6052. }/* end of function CanStep */
  6053. /*************************************************************************/
  6054. /* Function: Step */
  6055. /* Description: Steps forwards or backwords. Mutes un umutes sound if */
  6056. /* necessary. */
  6057. /*************************************************************************/
  6058. STDMETHODIMP CMSWebDVD::Step(long lStep){
  6059. HRESULT hr = S_OK;
  6060. try {
  6061. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  6062. if(!m_pDvdInfo2){
  6063. throw(E_UNEXPECTED);
  6064. }/* end of if statement */
  6065. if(lStep < 0){
  6066. // going backwards so check if we can do it
  6067. if(S_OK != CanStepBackwards()){
  6068. hr = E_FAIL; // aperently we cannot on this decoder
  6069. throw(hr);
  6070. }/* end of if statement */
  6071. }/* end of if statement */
  6072. if(!m_pVideoFrameStep){
  6073. throw(E_UNEXPECTED);
  6074. }/* end of if statement */
  6075. bool fUnMute = false;
  6076. if(FALSE == m_bMute){
  6077. hr = put_Mute(VARIANT_TRUE);
  6078. if (SUCCEEDED(hr)){
  6079. fUnMute = true;
  6080. }/* end of if statement */
  6081. }/* end if if statement */
  6082. ProcessEvents(); // cleanup the message queu
  6083. m_fStepComplete = false;
  6084. hr = m_pVideoFrameStep->Step(lStep, NULL);
  6085. if(SUCCEEDED(hr)){
  6086. HRESULT hrTmp = hr;
  6087. hr = E_FAIL;
  6088. for(INT i = 0; i < cgnStepTimeout; i++){
  6089. // now wait for EC_STEP_COMPLETE flag
  6090. ProcessEvents();
  6091. if(m_fStepComplete){
  6092. hr = hrTmp;
  6093. break;
  6094. }/* end of if statement */
  6095. ::Sleep(cdwTimeout);
  6096. }/* end of for loop */
  6097. }/* end of if statement */
  6098. if(fUnMute){
  6099. hr = put_Mute(VARIANT_FALSE);
  6100. if (FAILED(hr)){
  6101. throw(hr);
  6102. }/* end of if statement */
  6103. }/* end if if statement */
  6104. if(FAILED(hr)){
  6105. throw(hr);
  6106. }/* end of if statement */
  6107. }
  6108. catch(HRESULT hrTmp){
  6109. hr = hrTmp;
  6110. }/* end of catch statement */
  6111. catch(...){
  6112. hr = E_UNEXPECTED;
  6113. }/* end of catch statement */
  6114. return HandleError(hr);
  6115. }/* end of function Step */
  6116. /*************************************************************/
  6117. /* Function: CanStepBackwards */
  6118. /* Description: Checks if the decoder can step backwqards */
  6119. /* cashesh the variable. */
  6120. /* Returns S_OK if can, S_FALSE otherwise */
  6121. /*************************************************************/
  6122. HRESULT CMSWebDVD::CanStepBackwards(){
  6123. HRESULT hr = S_OK;
  6124. if(m_fBackWardsFlagInitialized){
  6125. // pulling out the result from the cache
  6126. return (m_fCanStepBackwards ? S_OK : S_FALSE);
  6127. }/* end of if statement */
  6128. DVD_DECODER_CAPS dvdCaps;
  6129. ::ZeroMemory(&dvdCaps, sizeof(DVD_DECODER_CAPS));
  6130. dvdCaps.dwSize = sizeof(DVD_DECODER_CAPS);
  6131. hr = m_pDvdInfo2->GetDecoderCaps(&dvdCaps);
  6132. if(FAILED(hr)){
  6133. return(hr);
  6134. }/* end of if statement */
  6135. //dvdCaps.dBwdMaxRateVideo is zero if decoder does not support smooth reverse
  6136. // playback that means it will not support reverse stepping mechanism as well
  6137. if(0 == dvdCaps.dBwdMaxRateVideo){
  6138. // we cannot step on decodors that do not provide smooth backward playback
  6139. m_fBackWardsFlagInitialized = true;
  6140. m_fCanStepBackwards = false;
  6141. hr = S_FALSE;
  6142. return(hr);
  6143. }/* end of if statement */
  6144. m_fBackWardsFlagInitialized = true;
  6145. m_fCanStepBackwards = true;
  6146. hr = S_OK;
  6147. return(hr);
  6148. }/* end of function CanStepBackwards */
  6149. /*************************************************************/
  6150. /* Name: GetKaraokeChannelAssignment
  6151. /* Description:
  6152. /*************************************************************/
  6153. STDMETHODIMP CMSWebDVD::GetKaraokeChannelAssignment(long lStream, long *lChannelAssignment)
  6154. {
  6155. HRESULT hr = S_OK;
  6156. try {
  6157. if(!lChannelAssignment){
  6158. return E_POINTER;
  6159. }
  6160. if(lStream < 0){
  6161. throw(E_INVALIDARG);
  6162. }/* end of if statement */
  6163. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  6164. if(!m_pDvdInfo2){
  6165. throw(E_UNEXPECTED);
  6166. }/* end of if statement */
  6167. DVD_KaraokeAttributes attrib;
  6168. RETRY_IF_IN_FPDOM(m_pDvdInfo2->GetKaraokeAttributes(lStream, &attrib));
  6169. if(FAILED(hr)){
  6170. throw(hr);
  6171. }/* end of if statement */
  6172. *lChannelAssignment = (long)attrib.ChannelAssignment;
  6173. }/* end of try statement */
  6174. catch(HRESULT hrTmp){
  6175. hr = hrTmp;
  6176. }/* end of catch statement */
  6177. catch(...){
  6178. hr = E_UNEXPECTED;
  6179. }/* end of catch statement */
  6180. return HandleError(hr);
  6181. }
  6182. /*************************************************************/
  6183. /* Name: GetKaraokeChannelContent
  6184. /* Description:
  6185. /*************************************************************/
  6186. STDMETHODIMP CMSWebDVD::GetKaraokeChannelContent(long lStream, long lChan, long *lContent)
  6187. {
  6188. HRESULT hr = S_OK;
  6189. try {
  6190. if(!lContent){
  6191. return E_POINTER;
  6192. }
  6193. if(lStream < 0){
  6194. throw(E_INVALIDARG);
  6195. }/* end of if statement */
  6196. if (lChan >=8 ) {
  6197. throw(E_INVALIDARG);
  6198. }/* end of if statement */
  6199. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  6200. if(!m_pDvdInfo2){
  6201. throw(E_UNEXPECTED);
  6202. }/* end of if statement */
  6203. DVD_KaraokeAttributes attrib;
  6204. RETRY_IF_IN_FPDOM(m_pDvdInfo2->GetKaraokeAttributes(lStream, &attrib));
  6205. if(FAILED(hr)){
  6206. throw(hr);
  6207. }/* end of if statement */
  6208. *lContent = (long)attrib.wChannelContents[lChan];
  6209. }/* end of try statement */
  6210. catch(HRESULT hrTmp){
  6211. hr = hrTmp;
  6212. }/* end of catch statement */
  6213. catch(...){
  6214. hr = E_UNEXPECTED;
  6215. }/* end of catch statement */
  6216. return HandleError(hr);
  6217. }
  6218. /*************************************************************/
  6219. /* Name: get_KaraokeAudioPresentationMode
  6220. /* Description:
  6221. /*************************************************************/
  6222. STDMETHODIMP CMSWebDVD::get_KaraokeAudioPresentationMode(long *pVal)
  6223. {
  6224. HRESULT hr = S_OK;
  6225. try {
  6226. if (NULL == pVal) {
  6227. throw (E_POINTER);
  6228. } /* end of if statement */
  6229. *pVal = m_lKaraokeAudioPresentationMode;
  6230. }/* end of try statement */
  6231. catch(HRESULT hrTmp){
  6232. hr = hrTmp;
  6233. }/* end of catch statement */
  6234. catch(...){
  6235. hr = E_UNEXPECTED;
  6236. }/* end of catch statement */
  6237. return HandleError(hr);
  6238. }
  6239. /*************************************************************/
  6240. /* Name: put_KaraokeAudioPresentationMode
  6241. /* Description:
  6242. /*************************************************************/
  6243. STDMETHODIMP CMSWebDVD::put_KaraokeAudioPresentationMode(long newVal)
  6244. {
  6245. HRESULT hr = S_OK;
  6246. try {
  6247. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  6248. if(!m_pDvdCtl2){
  6249. throw(E_UNEXPECTED);
  6250. }/* end of if statement */
  6251. RETRY_IF_IN_FPDOM(m_pDvdCtl2->SelectKaraokeAudioPresentationMode((ULONG)newVal));
  6252. if(FAILED(hr)){
  6253. throw(hr);
  6254. }/* end of if statement */
  6255. // Cache the value
  6256. m_lKaraokeAudioPresentationMode = newVal;
  6257. }/* end of try statement */
  6258. catch(HRESULT hrTmp){
  6259. hr = hrTmp;
  6260. }/* end of catch statement */
  6261. catch(...){
  6262. hr = E_UNEXPECTED;
  6263. }/* end of catch statement */
  6264. return HandleError(hr);
  6265. }
  6266. /*************************************************************/
  6267. /* Name: get_DefaultAudioLanguage
  6268. /* Description:
  6269. /*************************************************************/
  6270. STDMETHODIMP CMSWebDVD::get_DefaultAudioLanguage(long *lang)
  6271. {
  6272. HRESULT hr = S_OK;
  6273. try {
  6274. if(NULL == lang){
  6275. throw (E_POINTER);
  6276. }/* end of if statement */
  6277. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  6278. if(!m_pDvdInfo2){
  6279. throw (E_UNEXPECTED);
  6280. }/* end of if statement */
  6281. long ext;
  6282. hr = m_pDvdInfo2->GetDefaultAudioLanguage((LCID*)lang, (DVD_AUDIO_LANG_EXT*)&ext);
  6283. if (FAILED(hr))
  6284. throw(hr);
  6285. }
  6286. catch(HRESULT hrTmp){
  6287. hr = hrTmp;
  6288. }/* end of catch statement */
  6289. catch(...){
  6290. hr = E_UNEXPECTED;
  6291. }/* end of catch statement */
  6292. return HandleError(hr);
  6293. }
  6294. /*************************************************************/
  6295. /* Name: get_DefaultAudioLanguageExt
  6296. /* Description:
  6297. /*************************************************************/
  6298. STDMETHODIMP CMSWebDVD::get_DefaultAudioLanguageExt(long *ext)
  6299. {
  6300. HRESULT hr = S_OK;
  6301. try {
  6302. if(NULL == ext){
  6303. throw (E_POINTER);
  6304. }/* end of if statement */
  6305. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  6306. if(!m_pDvdInfo2){
  6307. throw (E_UNEXPECTED);
  6308. }/* end of if statement */
  6309. long lang;
  6310. hr = m_pDvdInfo2->GetDefaultAudioLanguage((LCID*)&lang, (DVD_AUDIO_LANG_EXT*)ext);
  6311. if (FAILED(hr))
  6312. throw(hr);
  6313. }
  6314. catch(HRESULT hrTmp){
  6315. hr = hrTmp;
  6316. }/* end of catch statement */
  6317. catch(...){
  6318. hr = E_UNEXPECTED;
  6319. }/* end of catch statement */
  6320. return HandleError(hr);
  6321. }
  6322. /*************************************************************/
  6323. /* Name: get_DefaultSubpictureLanguage
  6324. /* Description:
  6325. /*************************************************************/
  6326. STDMETHODIMP CMSWebDVD::get_DefaultSubpictureLanguage(long *lang)
  6327. {
  6328. HRESULT hr = S_OK;
  6329. try {
  6330. if(NULL == lang){
  6331. throw (E_POINTER);
  6332. }/* end of if statement */
  6333. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  6334. if(!m_pDvdInfo2){
  6335. throw (E_UNEXPECTED);
  6336. }/* end of if statement */
  6337. long ext;
  6338. hr = m_pDvdInfo2->GetDefaultSubpictureLanguage((LCID*)lang, (DVD_SUBPICTURE_LANG_EXT*)&ext);
  6339. if (FAILED(hr))
  6340. throw(hr);
  6341. }
  6342. catch(HRESULT hrTmp){
  6343. hr = hrTmp;
  6344. }/* end of catch statement */
  6345. catch(...){
  6346. hr = E_UNEXPECTED;
  6347. }/* end of catch statement */
  6348. return HandleError(hr);
  6349. }
  6350. /*************************************************************/
  6351. /* Name: get_DefaultSubpictureLanguageExt
  6352. /* Description:
  6353. /*************************************************************/
  6354. STDMETHODIMP CMSWebDVD::get_DefaultSubpictureLanguageExt(DVDSPExt *ext)
  6355. {
  6356. HRESULT hr = S_OK;
  6357. try {
  6358. if(NULL == ext){
  6359. throw (E_POINTER);
  6360. }/* end of if statement */
  6361. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  6362. if(!m_pDvdInfo2){
  6363. throw (E_UNEXPECTED);
  6364. }/* end of if statement */
  6365. long lang;
  6366. hr = m_pDvdInfo2->GetDefaultSubpictureLanguage((LCID*)&lang, (DVD_SUBPICTURE_LANG_EXT*)ext);
  6367. if (FAILED(hr))
  6368. throw(hr);
  6369. }
  6370. catch(HRESULT hrTmp){
  6371. hr = hrTmp;
  6372. }/* end of catch statement */
  6373. catch(...){
  6374. hr = E_UNEXPECTED;
  6375. }/* end of catch statement */
  6376. return HandleError(hr);
  6377. }
  6378. /*************************************************************/
  6379. /* Name: get_DefaultMenuLanguage
  6380. /* Description:
  6381. /*************************************************************/
  6382. STDMETHODIMP CMSWebDVD::get_DefaultMenuLanguage(long *lang)
  6383. {
  6384. HRESULT hr = S_OK;
  6385. try {
  6386. if(NULL == lang){
  6387. throw (E_POINTER);
  6388. }/* end of if statement */
  6389. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  6390. if(!m_pDvdInfo2){
  6391. throw (E_UNEXPECTED);
  6392. }/* end of if statement */
  6393. hr = m_pDvdInfo2->GetDefaultMenuLanguage((LCID*)lang);
  6394. if (FAILED(hr))
  6395. throw(hr);
  6396. }
  6397. catch(HRESULT hrTmp){
  6398. hr = hrTmp;
  6399. }/* end of catch statement */
  6400. catch(...){
  6401. hr = E_UNEXPECTED;
  6402. }/* end of catch statement */
  6403. return HandleError(hr);
  6404. }
  6405. /*************************************************************/
  6406. /* Name: RestoreDefaultSettings
  6407. /* Description:
  6408. /*************************************************************/
  6409. HRESULT CMSWebDVD::RestoreDefaultSettings()
  6410. {
  6411. HRESULT hr = S_OK;
  6412. try {
  6413. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  6414. if(!m_pDvdAdmin){
  6415. throw (E_UNEXPECTED);
  6416. }/* end of if statement */
  6417. if(!m_pDvdInfo2){
  6418. throw (E_UNEXPECTED);
  6419. }/* end of if statement */
  6420. // get the curent domain
  6421. DVD_DOMAIN domain;
  6422. hr = m_pDvdInfo2->GetCurrentDomain(&domain);
  6423. if(FAILED(hr)){
  6424. throw(hr);
  6425. }/* end of if statement */
  6426. // Have to be in the stop domain
  6427. if(DVD_DOMAIN_Stop != domain)
  6428. throw (VFW_E_DVD_INVALIDDOMAIN);
  6429. long level;
  6430. hr = m_pDvdAdmin->GetParentalLevel(&level);
  6431. if (SUCCEEDED(hr))
  6432. SelectParentalLevel(level);
  6433. LCID audioLCID;
  6434. LCID subpictureLCID;
  6435. LCID menuLCID;
  6436. hr = m_pDvdAdmin->get_DefaultAudioLCID((long*)&audioLCID);
  6437. if (SUCCEEDED(hr))
  6438. SelectDefaultAudioLanguage(audioLCID, 0);
  6439. hr = m_pDvdAdmin->get_DefaultSubpictureLCID((long*)&subpictureLCID);
  6440. if (SUCCEEDED(hr))
  6441. SelectDefaultSubpictureLanguage(subpictureLCID, dvdSPExt_NotSpecified);
  6442. hr = m_pDvdAdmin->get_DefaultMenuLCID((long*)&menuLCID);
  6443. if (SUCCEEDED(hr))
  6444. put_DefaultMenuLanguage(menuLCID);
  6445. }
  6446. catch(HRESULT hrTmp){
  6447. hr = hrTmp;
  6448. }/* end of catch statement */
  6449. catch(...){
  6450. hr = E_UNEXPECTED;
  6451. }/* end of catch statement */
  6452. return HandleError(hr);
  6453. }
  6454. /*************************************************************************/
  6455. /* DVD Helper Methods, used by the default interface */
  6456. /*************************************************************************/
  6457. /*************************************************************************/
  6458. /* Function: GetColorKey */
  6459. /* Description: Gets a colorkey via RGB filled COLORREF or palette index.*/
  6460. /* Helper function. */
  6461. /*************************************************************************/
  6462. HRESULT CMSWebDVD::GetColorKey(COLORREF* pClr)
  6463. {
  6464. HRESULT hr = S_OK;
  6465. if(m_pDvdGB == NULL)
  6466. return(E_FAIL);
  6467. CComPtr<IMixerPinConfig2> pMixerPinConfig;
  6468. hr = m_pDvdGB->GetDvdInterface(IID_IMixerPinConfig2, (LPVOID *) &pMixerPinConfig);
  6469. if(FAILED(hr))
  6470. return(hr);
  6471. COLORKEY ck;
  6472. DWORD dwColor;
  6473. hr = pMixerPinConfig->GetColorKey(&ck, &dwColor); // get the color key
  6474. if(FAILED(hr))
  6475. return(hr);
  6476. HWND hwnd = ::GetDesktopWindow();
  6477. HDC hdc = ::GetWindowDC(hwnd);
  6478. if(NULL == hdc){
  6479. return(E_UNEXPECTED);
  6480. }/* end of if statement */
  6481. BOOL bPalette = (RC_PALETTE == (RC_PALETTE & GetDeviceCaps( hdc, RASTERCAPS )));
  6482. if ((ck.KeyType & CK_INDEX)&& bPalette) {
  6483. PALETTEENTRY PaletteEntry;
  6484. UINT nTmp = GetSystemPaletteEntries( hdc, ck.PaletteIndex, 1, &PaletteEntry );
  6485. if ( nTmp == 1 )
  6486. {
  6487. *pClr = RGB( PaletteEntry.peRed, PaletteEntry.peGreen, PaletteEntry.peBlue );
  6488. }
  6489. }
  6490. else if (ck.KeyType & CK_RGB)
  6491. {
  6492. *pClr = ck.HighColorValue; // set the RGB color
  6493. }
  6494. ::ReleaseDC(hwnd, hdc);
  6495. return(hr);
  6496. }/* end of function GetColorKey */
  6497. /*************************************************************************/
  6498. /* Function: SetColorKey */
  6499. /* Description: Sets a colorkey via RGB filled COLORREF. */
  6500. /* Helper function. */
  6501. /*************************************************************************/
  6502. HRESULT CMSWebDVD::SetColorKey(COLORREF clr){
  6503. HRESULT hr = S_OK;
  6504. if(m_pDvdGB == NULL)
  6505. return(E_FAIL);
  6506. CComPtr<IMixerPinConfig2> pMixerPinConfig;
  6507. hr = m_pDvdGB->GetDvdInterface(IID_IMixerPinConfig2, (LPVOID *) &pMixerPinConfig);
  6508. if( SUCCEEDED( hr )){
  6509. COLORKEY ck;
  6510. HWND hwnd = ::GetDesktopWindow();
  6511. HDC hdc = ::GetWindowDC(hwnd);
  6512. if(NULL == hdc){
  6513. return(E_UNEXPECTED);
  6514. }/* end of if statement */
  6515. if((::GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) == RC_PALETTE)
  6516. {
  6517. ck.KeyType = CK_INDEX|CK_RGB; // have an index to the palette
  6518. ck.PaletteIndex = 253;
  6519. PALETTEENTRY PaletteEntry;
  6520. UINT nTmp = GetSystemPaletteEntries( hdc, ck.PaletteIndex, 1, &PaletteEntry );
  6521. if ( nTmp == 1 )
  6522. {
  6523. ck.LowColorValue = ck.HighColorValue = RGB( PaletteEntry.peRed, PaletteEntry.peGreen, PaletteEntry.peBlue );
  6524. }
  6525. }
  6526. else
  6527. {
  6528. ck.KeyType = CK_RGB;
  6529. ck.LowColorValue = clr;
  6530. ck.HighColorValue = clr;
  6531. }/* end of if statement */
  6532. hr = pMixerPinConfig->SetColorKey(&ck);
  6533. ::ReleaseDC(hwnd, hdc);
  6534. }/* end of if statement */
  6535. return hr;
  6536. }/* end of function SetColorKey */
  6537. /*************************************************************************/
  6538. /* Function: TwoDigitToByte */
  6539. /*************************************************************************/
  6540. static BYTE TwoDigitToByte( const WCHAR* pTwoDigit ){
  6541. int tens = int(pTwoDigit[0] - L'0');
  6542. return BYTE( (pTwoDigit[1] - L'0') + tens*10);
  6543. }/* end of function TwoDigitToByte */
  6544. /*************************************************************************/
  6545. /* Function: Bstr2DVDTime */
  6546. /* Description: Converts a DVD Time info from BSTR into a TIMECODE. */
  6547. /*************************************************************************/
  6548. HRESULT CMSWebDVD::Bstr2DVDTime(DVD_HMSF_TIMECODE *ptrTimeCode, const BSTR *pbstrTime){
  6549. if(NULL == pbstrTime || NULL == ptrTimeCode){
  6550. return E_INVALIDARG;
  6551. }/* end of if statement */
  6552. ::ZeroMemory(ptrTimeCode, sizeof(DVD_HMSF_TIMECODE));
  6553. WCHAR *pszTime = *pbstrTime;
  6554. ULONG lStringLength = wcslen(pszTime);
  6555. if(0 == lStringLength){
  6556. return E_INVALIDARG;
  6557. }/* end of if statement */
  6558. TCHAR tszTimeSep[5];
  6559. ::GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STIME, tszTimeSep, 5);
  6560. // If the string is two long, it is seconds only
  6561. if(lStringLength == 2){
  6562. ptrTimeCode->bSeconds = TwoDigitToByte( &pszTime[0] );
  6563. return S_OK;
  6564. }
  6565. // Otherwise it is a normal time code of the format
  6566. // 43:32:21:10
  6567. // Where the ':' can be replaced with a localized string of upto 4 char in len
  6568. // There is a possible error case where the length of the delimeter is different
  6569. // then the current delimeter
  6570. if(lStringLength >= (4*cgTIME_STRING_LEN)+(3 * _tcslen(tszTimeSep))){ // longest string nnxnnxnnxnn e.g. 43:23:21:10
  6571. // where n is a number and
  6572. // x is a time delimeter usually ':', but can be any string upto 4 char in len)
  6573. ptrTimeCode->bFrames = TwoDigitToByte( &pszTime[(3*cgTIME_STRING_LEN)+(3*_tcslen(tszTimeSep))]);
  6574. }
  6575. if(lStringLength >= (3*cgTIME_STRING_LEN)+(2 * _tcslen(tszTimeSep))) { // string nnxnnxnn e.g. 43:23:21
  6576. ptrTimeCode->bSeconds = TwoDigitToByte( &pszTime[(2*cgTIME_STRING_LEN)+(2*_tcslen(tszTimeSep))] );
  6577. }
  6578. if(lStringLength >= (2*cgTIME_STRING_LEN)+(1 * _tcslen(tszTimeSep))) { // string nnxnn e.g. 43:23
  6579. ptrTimeCode->bMinutes = TwoDigitToByte( &pszTime[(1*cgTIME_STRING_LEN)+(1*_tcslen(tszTimeSep))] );
  6580. }
  6581. if(lStringLength >= (cgTIME_STRING_LEN)) { // string nn e.g. 43
  6582. ptrTimeCode->bHours = TwoDigitToByte( &pszTime[0] );
  6583. }
  6584. return (S_OK);
  6585. }/* end of function bstr2DVDTime */
  6586. /*************************************************************************/
  6587. /* Function: DVDTime2bstr */
  6588. /* Description: Converts a DVD Time info from ULONG into a BSTR. */
  6589. /*************************************************************************/
  6590. HRESULT CMSWebDVD::DVDTime2bstr( const DVD_HMSF_TIMECODE *pTimeCode, BSTR *pbstrTime){
  6591. if(NULL == pTimeCode || NULL == pbstrTime)
  6592. return E_INVALIDARG;
  6593. USES_CONVERSION;
  6594. TCHAR tszTime[cgDVD_TIME_STR_LEN];
  6595. TCHAR tszTimeSep[5];
  6596. ::ZeroMemory(tszTime, sizeof(TCHAR)*cgDVD_TIME_STR_LEN);
  6597. ::GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STIME, tszTimeSep, 5);
  6598. StringCchPrintf( tszTime, sizeof(tszTime) / sizeof(tszTime[0]), TEXT("%02lu%s%02lu%s%02lu%s%02lu"),
  6599. pTimeCode->bHours, tszTimeSep,
  6600. pTimeCode->bMinutes, tszTimeSep,
  6601. pTimeCode->bSeconds, tszTimeSep,
  6602. pTimeCode->bFrames );
  6603. *pbstrTime = SysAllocString(T2OLE(tszTime));
  6604. return (S_OK);
  6605. }/* end of function DVDTime2bstr */
  6606. /*************************************************************************/
  6607. /* Function: SetupAudio */
  6608. /* Description: Initialize the audio interface. */
  6609. /*************************************************************************/
  6610. HRESULT CMSWebDVD::SetupAudio(){
  6611. HRESULT hr = E_FAIL;
  6612. try {
  6613. #if 0 // Using
  6614. if(!m_pDvdGB){
  6615. throw(E_UNEXPECTED);
  6616. }/* end of if statement */
  6617. hr = m_pDvdGB->GetDvdInterface(IID_IBasicAudio, (LPVOID*) &m_pAudio) ;
  6618. if(FAILED(hr)){
  6619. ATLTRACE(TEXT("The QDVD.DLL does not support IID_IBasicAudio please update QDVD.DLL\n"));
  6620. throw(hr);
  6621. }/* end of if statement */
  6622. #else
  6623. hr = TraverseForInterface(IID_IBasicAudio, (LPVOID*) &m_pAudio);
  6624. if(FAILED(hr)){
  6625. // might be a HW decoder
  6626. HMIXER hmx = NULL;
  6627. if(::mixerOpen(&hmx, 0, 0, 0, 0) != MMSYSERR_NOERROR){
  6628. hr = E_FAIL;
  6629. return(hr);
  6630. }/* end of if statement */
  6631. ::mixerClose(hmx);
  6632. hr = S_OK;
  6633. }/* end of if statement */
  6634. #endif
  6635. }/* end of try statement */
  6636. catch(HRESULT hrTmp){
  6637. hr = hrTmp;
  6638. }
  6639. catch(...){
  6640. hr = E_UNEXPECTED;
  6641. }/* end of catch statement */
  6642. return hr;
  6643. }/* end of function SetupAudio */
  6644. /*************************************************************************/
  6645. /* Function: TraverseForInterface */
  6646. /* Description: Goes through the interface list and finds a desired one. */
  6647. /*************************************************************************/
  6648. HRESULT CMSWebDVD::TraverseForInterface(REFIID iid, LPVOID* ppvObject){
  6649. HRESULT hr = E_FAIL;
  6650. try {
  6651. // take care and release any interface before passing
  6652. // it over otherwise we leak
  6653. if(!m_pDvdGB){
  6654. throw(E_UNEXPECTED);
  6655. }/* end of if statement */
  6656. IGraphBuilder *pFilterGraph;
  6657. hr = m_pDvdGB->GetFiltergraph(&pFilterGraph);
  6658. if(FAILED(hr)){
  6659. throw(hr);
  6660. }/* end of if statement */
  6661. CComPtr<IBaseFilter> pFilter;
  6662. CComPtr<IEnumFilters> pEnum;
  6663. hr = pFilterGraph->EnumFilters(&pEnum);
  6664. pFilterGraph->Release();
  6665. if(FAILED(hr)){
  6666. throw(hr);
  6667. }/* end of if statement */
  6668. hr = E_FAIL; // set the hr to E_FAIL in case we do not find the IBasicAudio
  6669. while(pEnum->Next(1, &pFilter, NULL) == S_OK){
  6670. HRESULT hrTmp = pFilter->QueryInterface(iid, ppvObject);
  6671. pFilter.Release();
  6672. if(SUCCEEDED(hrTmp)){
  6673. ATLASSERT(*ppvObject);
  6674. // found our audio time to break
  6675. if(*ppvObject == NULL){
  6676. throw(E_UNEXPECTED);
  6677. }/* end of if statement */
  6678. hr = hrTmp; // set the hr to SUCCEED
  6679. break;
  6680. }/* end of if statement */
  6681. }/* end of while loop */
  6682. }/* end of try statement */
  6683. catch(HRESULT hrTmp){
  6684. hr = hrTmp;
  6685. }
  6686. catch(...){
  6687. hr = E_UNEXPECTED;
  6688. }/* end of catch statement */
  6689. return hr;
  6690. }/* end of function TraverseForInterface */
  6691. /*************************************************************************/
  6692. /* Function: SetupEventNotifySink */
  6693. /* Description: Gets the event notify sink interface. */
  6694. /*************************************************************************/
  6695. HRESULT CMSWebDVD::SetupEventNotifySink(){
  6696. HRESULT hr = E_FAIL;
  6697. try {
  6698. if(m_pMediaSink){
  6699. m_pMediaSink.Release();
  6700. }/* end of if statement */
  6701. if(!m_pDvdGB){
  6702. throw(E_UNEXPECTED);
  6703. }/* end of if statement */
  6704. IGraphBuilder *pFilterGraph;
  6705. hr = m_pDvdGB->GetFiltergraph(&pFilterGraph);
  6706. if(FAILED(hr)){
  6707. throw(hr);
  6708. }/* end of if statement */
  6709. hr = pFilterGraph->QueryInterface(IID_IMediaEventSink, (void**)&m_pMediaSink);
  6710. pFilterGraph->Release();
  6711. }/* end of try statement */
  6712. catch(HRESULT hrTmp){
  6713. hr = hrTmp;
  6714. }
  6715. catch(...){
  6716. hr = E_UNEXPECTED;
  6717. }/* end of catch statement */
  6718. return hr;
  6719. }/* end of function SetupEventNotifySink */
  6720. /*************************************************************************/
  6721. /* Function: OnPostVerbInPlaceActivate */
  6722. /* Description: Creates the in place active object. */
  6723. /*************************************************************************/
  6724. HRESULT CMSWebDVD::OnPostVerbInPlaceActivate(){
  6725. SetReadyState(READYSTATE_COMPLETE);
  6726. return(S_OK);
  6727. }/* end of function OnPostVerbInPlaceActivate */
  6728. /*************************************************************************/
  6729. /* Function: RenderGraphIfNeeded */
  6730. /* Description: Initializes graph if it needs to be. */
  6731. /*************************************************************************/
  6732. HRESULT CMSWebDVD::RenderGraphIfNeeded(){
  6733. HRESULT hr = S_OK;
  6734. try {
  6735. m_DVDFilterState = dvdState_Undefined; // just a flag set so we can restore
  6736. // graph state if the API fails
  6737. if(!m_fInitialized){
  6738. hr = Render(); // render the graph
  6739. }/* end of if statement */
  6740. }/* end of try statement */
  6741. catch(HRESULT hrTmp){
  6742. hr = hrTmp;
  6743. }/* end of catch statement */
  6744. catch(...){
  6745. hr = E_UNEXPECTED;
  6746. }/* end of catch statement */
  6747. return(hr);
  6748. }/* end of function RenderGraphIfNeeded */
  6749. /*************************************************************************/
  6750. /* Function: PassFP_DOM */
  6751. /* Description: Gets into title domain, past fp domain. */
  6752. /*************************************************************************/
  6753. HRESULT CMSWebDVD::PassFP_DOM(){
  6754. HRESULT hr = S_OK;
  6755. try {
  6756. // get the curent domain
  6757. DVD_DOMAIN domain;
  6758. //INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  6759. if(!m_pDvdInfo2){
  6760. throw(E_UNEXPECTED);
  6761. }/* end of if statement */
  6762. hr = m_pDvdInfo2->GetCurrentDomain(&domain);
  6763. if(FAILED(hr)){
  6764. throw(hr);
  6765. }/* end of if statement */
  6766. if(DVD_DOMAIN_FirstPlay == domain /* || DVD_DOMAIN_VideoManagerMenu == domain */){
  6767. // if the domain is FP_DOM wait a specified timeout
  6768. if(NULL == m_hFPDOMEvent){
  6769. ATLTRACE(TEXT("The handle should have been already set \n"));
  6770. throw(E_UNEXPECTED);
  6771. }/* end of if statement */
  6772. if(WAIT_OBJECT_0 == ::WaitForSingleObject(m_hFPDOMEvent, cdwMaxFP_DOMWait)){
  6773. hr = S_OK;
  6774. }
  6775. else {
  6776. hr = E_FAIL;
  6777. }/* end of if statement */
  6778. }
  6779. else {
  6780. hr = E_FAIL; // we were not originally in FP_DOM so it should have worked
  6781. // there is a potential for raice condition, when we issue the command
  6782. // the command failed due to that we were not in FP_DOM, but after the execution
  6783. // it has changed before we got a chance to look it up
  6784. }/* end of if statement */
  6785. }/* end of try statement */
  6786. catch(HRESULT hrTmp){
  6787. hr = hrTmp;
  6788. }/* end of catch statement */
  6789. catch(...){
  6790. hr = E_UNEXPECTED;
  6791. }/* end of catch statement */
  6792. return(hr);
  6793. }/* end of function PassFP_DOM */
  6794. /*************************************************************/
  6795. /* Name: OpenCdRom */
  6796. /* Description: Open CDRom and return the device ID */
  6797. /*************************************************************/
  6798. DWORD CMSWebDVD::OpenCdRom(TCHAR chDrive, LPDWORD lpdwErrCode){
  6799. MCI_OPEN_PARMS mciOpen;
  6800. TCHAR szElementName[4];
  6801. TCHAR szAliasName[32];
  6802. DWORD dwFlags;
  6803. DWORD dwAliasCount = GetCurrentTime();
  6804. DWORD dwRet;
  6805. ZeroMemory( &mciOpen, sizeof(mciOpen) );
  6806. mciOpen.lpstrDeviceType = (LPTSTR)MCI_DEVTYPE_CD_AUDIO;
  6807. StringCchPrintf( szElementName, sizeof(szElementName) / sizeof(szElementName[0]), TEXT("%c:"), chDrive );
  6808. StringCchPrintf( szAliasName, sizeof(szAliasName) / sizeof(szAliasName[0]), TEXT("SJE%lu:"), dwAliasCount );
  6809. mciOpen.lpstrAlias = szAliasName;
  6810. mciOpen.lpstrDeviceType = (LPTSTR)MCI_DEVTYPE_CD_AUDIO;
  6811. mciOpen.lpstrElementName = szElementName;
  6812. dwFlags = MCI_OPEN_ELEMENT | MCI_OPEN_ALIAS |
  6813. MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID | MCI_WAIT;
  6814. // send mci command
  6815. dwRet = mciSendCommand(0, MCI_OPEN, dwFlags, reinterpret_cast<DWORD_PTR>(&mciOpen));
  6816. if ( dwRet != MMSYSERR_NOERROR )
  6817. mciOpen.wDeviceID = 0;
  6818. if (lpdwErrCode != NULL)
  6819. *lpdwErrCode = dwRet;
  6820. return mciOpen.wDeviceID;
  6821. }/* end of function OpenCdRom */
  6822. /*************************************************************/
  6823. /* Name: CloseCdRom */
  6824. /* Description: Close device handle for CDRom */
  6825. /*************************************************************/
  6826. HRESULT CMSWebDVD::CloseCdRom(DWORD DevHandle){
  6827. MCI_OPEN_PARMS mciOpen;
  6828. ZeroMemory( &mciOpen, sizeof(mciOpen) );
  6829. MCIERROR theMciErr = mciSendCommand( DevHandle, MCI_CLOSE, 0L, reinterpret_cast<DWORD_PTR>(&mciOpen) );
  6830. HRESULT hr = theMciErr ? E_FAIL : S_OK; // zero for success
  6831. return (hr);
  6832. }/* end of function CloseCdRom */
  6833. /*************************************************************/
  6834. /* Name: EjectCdRom */
  6835. /* Description: Open device door for CDRom */
  6836. /*************************************************************/
  6837. HRESULT CMSWebDVD::EjectCdRom(DWORD DevHandle){
  6838. MCI_OPEN_PARMS mciOpen;
  6839. ZeroMemory( &mciOpen, sizeof(mciOpen) );
  6840. MCIERROR theMciErr = mciSendCommand( DevHandle, MCI_SET, MCI_SET_DOOR_OPEN, reinterpret_cast<DWORD_PTR>(&mciOpen) );
  6841. HRESULT hr = theMciErr ? E_FAIL : S_OK; // zero for success
  6842. return (hr);
  6843. }/* end of function EjectCdRom */
  6844. /*************************************************************/
  6845. /* Name: UnEjectCdRom */
  6846. /* Description: Close device door for CDRom */
  6847. /*************************************************************/
  6848. HRESULT CMSWebDVD::UnEjectCdRom(DWORD DevHandle){
  6849. MCI_OPEN_PARMS mciOpen;
  6850. ZeroMemory( &mciOpen, sizeof(mciOpen) );
  6851. MCIERROR theMciErr = mciSendCommand( DevHandle, MCI_SET, MCI_SET_DOOR_CLOSED, reinterpret_cast<DWORD_PTR>(&mciOpen) );
  6852. HRESULT hr = theMciErr ? E_FAIL : S_OK; // zero for success
  6853. return (hr);
  6854. }/* end of function UnEjectCdRom */
  6855. /*************************************************************************/
  6856. /* Function: SetupDDraw */
  6857. /* Description: Creates DDrawObject and Surface */
  6858. /*************************************************************************/
  6859. HRESULT CMSWebDVD::SetupDDraw(){
  6860. HRESULT hr = E_UNEXPECTED;
  6861. HWND hwnd;
  6862. hr = GetUsableWindow(&hwnd);
  6863. if(FAILED(hr)){
  6864. return(hr);
  6865. }/* end of if statement */
  6866. IAMSpecifyDDrawConnectionDevice* pSDDC;
  6867. hr = m_pDDEX->QueryInterface(IID_IAMSpecifyDDrawConnectionDevice, (LPVOID *)&pSDDC);
  6868. if (FAILED(hr)){
  6869. return(hr);
  6870. }/* end of if statement */
  6871. AMDDRAWGUID amGUID;
  6872. hr = pSDDC->GetDDrawGUID(&amGUID);
  6873. if (FAILED(hr)){
  6874. pSDDC->Release();
  6875. return(hr);
  6876. }/* end of if statement */
  6877. hr = pSDDC->GetDDrawGUIDs(&m_dwNumDevices, &m_lpInfo);
  6878. pSDDC->Release();
  6879. if(FAILED(hr)){
  6880. return(hr);
  6881. }/* end of if statement */
  6882. UpdateCurrentMonitor(&amGUID);
  6883. m_pDDrawDVD = new CDDrawDVD(this);
  6884. if(NULL == m_pDDrawDVD){
  6885. return(E_OUTOFMEMORY);
  6886. }
  6887. hr = m_pDDrawDVD->SetupDDraw(&amGUID, hwnd);
  6888. return(hr);
  6889. }/* end of function SetupDDraw */
  6890. /*************************************************************************/
  6891. /* Function: TransformToWndwls */
  6892. /* Description: Transforms the coordinates to screen onse. */
  6893. /*************************************************************************/
  6894. HRESULT CMSWebDVD::TransformToWndwls(POINT& pt){
  6895. HRESULT hr = S_FALSE;
  6896. // we are windowless we need to map the points to screen coordinates
  6897. if(m_bWndLess){
  6898. HWND hwnd = NULL;
  6899. hr = GetParentHWND(&hwnd);
  6900. if(FAILED(hr)){
  6901. return(hr);
  6902. }/* end of if statement */
  6903. if(!::IsWindow(hwnd)){
  6904. hr = E_UNEXPECTED;
  6905. return(hr);
  6906. }/* end of if statement */
  6907. #ifdef _DEBUG
  6908. // POINT ptOld = pt;
  6909. #endif
  6910. ::MapWindowPoints(hwnd, ::GetDesktopWindow(), &pt, 1);
  6911. hr = S_OK;
  6912. #ifdef _DEBUG
  6913. // ATLTRACE(TEXT("Mouse Client:x= %d, y = %d, Screen: x=%d, y= %d\n"),ptOld.x, ptOld.y, pt.x, pt.y);
  6914. #endif
  6915. }/* end of if statement */
  6916. return(hr);
  6917. }/* end of function TransformToWndwls */
  6918. /*************************************************************************/
  6919. /* Function: RestoreGraphState */
  6920. /* Description: Restores the graph state. Used when API fails. */
  6921. /*************************************************************************/
  6922. HRESULT CMSWebDVD::RestoreGraphState(){
  6923. HRESULT hr = S_OK;
  6924. switch(m_DVDFilterState){
  6925. case dvdState_Undefined:
  6926. case dvdState_Running: // do not do anything
  6927. break;
  6928. case dvdState_Unitialized:
  6929. case dvdState_Stopped: hr = Stop(); break;
  6930. case dvdState_Paused: hr = Pause();
  6931. }/* end of switch statement */
  6932. return(hr);
  6933. }/* end of if statement */
  6934. /*************************************************************************/
  6935. /* Function: AppendString */
  6936. /* Description: Appends a string to an existing one. */
  6937. /*************************************************************************/
  6938. HRESULT CMSWebDVD::AppendString(TCHAR* strDest, INT strID, LONG dwLen){
  6939. TCHAR strBuffer[MAX_PATH];
  6940. if(!::LoadString(_Module.m_hInstResource, strID, strBuffer, MAX_PATH)){
  6941. return(E_UNEXPECTED);
  6942. }/* end of if statement */
  6943. StringCchCat(strDest, dwLen, strBuffer);
  6944. return(S_OK);
  6945. }/* end of function AppendString */
  6946. /*************************************************************************/
  6947. /* Function: HandleError */
  6948. /* Description: Gets Error Descriptio, so we can suppor IError Info. */
  6949. /*************************************************************************/
  6950. HRESULT CMSWebDVD::HandleError(HRESULT hr){
  6951. try {
  6952. if(FAILED(hr)){
  6953. switch(hr){
  6954. case E_REGION_CHANGE_FAIL: Error(IDS_REGION_CHANGE_FAIL); return (hr);
  6955. case E_NO_IDVD2_PRESENT: Error(IDS_EDVD2INT); return (hr);
  6956. case E_FORMAT_NOT_SUPPORTED: Error(IDS_FORMAT_NOT_SUPPORTED); return (hr);
  6957. case E_NO_DVD_VOLUME: Error(IDS_E_NO_DVD_VOLUME); return (hr);
  6958. case E_REGION_CHANGE_NOT_COMPLETED: Error(IDS_E_REGION_CHANGE_NOT_COMPLETED); return(hr);
  6959. case E_NO_SOUND_STREAM: Error(IDS_E_NO_SOUND_STREAM); return(hr);
  6960. case E_NO_VIDEO_STREAM: Error(IDS_E_NO_VIDEO_STREAM); return(hr);
  6961. case E_NO_OVERLAY: Error(IDS_E_NO_OVERLAY); return(hr);
  6962. case E_NO_USABLE_OVERLAY: Error(IDS_E_NO_USABLE_OVERLAY); return(hr);
  6963. case E_NO_DECODER: Error(IDS_E_NO_DECODER); return(hr);
  6964. case E_NO_CAPTURE_SUPPORT: Error(IDS_E_NO_CAPTURE_SUPPORT); return(hr);
  6965. }/* end of switch statement */
  6966. // Ensure that the string is Null Terminated
  6967. TCHAR strError[MAX_ERROR_TEXT_LEN+1];
  6968. ZeroMemory(strError, MAX_ERROR_TEXT_LEN+1);
  6969. if(AMGetErrorText(hr , strError , MAX_ERROR_TEXT_LEN)){
  6970. USES_CONVERSION;
  6971. Error(T2W(strError));
  6972. }
  6973. else {
  6974. ATLTRACE(TEXT("Unhandled Error Code \n")); // please add it
  6975. ATLASSERT(FALSE);
  6976. }/* end of if statement */
  6977. }/* end of if statement */
  6978. }/* end of try statement */
  6979. catch(HRESULT hrTmp){
  6980. hr = hrTmp;
  6981. }/* end of catch statement */
  6982. catch(...){
  6983. // keep the hr same
  6984. }/* end of catch statement */
  6985. return (hr);
  6986. }/* end of function HandleError */
  6987. /*************************************************************/
  6988. /* Name: get_ShowCursor */
  6989. /*************************************************************/
  6990. STDMETHODIMP CMSWebDVD::get_ShowCursor(VARIANT_BOOL* pfShow)
  6991. {
  6992. HRESULT hr = S_OK;
  6993. try {
  6994. if(NULL == pfShow){
  6995. throw(E_POINTER);
  6996. }/* end of if statement */
  6997. CURSORINFO pci;
  6998. ::ZeroMemory(&pci, sizeof(CURSORINFO));
  6999. pci.cbSize = sizeof(CURSORINFO);
  7000. #if WINVER >= 0x0500
  7001. if(!::GetCursorInfo(&pci)){
  7002. #else
  7003. if(!CallGetCursorInfo(&pci)){
  7004. #endif
  7005. throw(E_FAIL);
  7006. }/* end of if statement */
  7007. *pfShow = (pci.flags == CURSOR_SHOWING) ? VARIANT_TRUE:VARIANT_FALSE;
  7008. }/* end of try statement */
  7009. catch(HRESULT hrTmp){
  7010. hr = hrTmp;
  7011. }/* end of catch statement */
  7012. catch(...){
  7013. hr = E_UNEXPECTED;
  7014. }/* end of catch statement */
  7015. return (hr);
  7016. }/* end of function get_ShowCursor */
  7017. /*************************************************************/
  7018. /* Name: put_ShowCursor */
  7019. /* Description: Shows the cursor or hides it. */
  7020. /*************************************************************/
  7021. STDMETHODIMP CMSWebDVD::put_ShowCursor(VARIANT_BOOL fShow){
  7022. HRESULT hr = S_OK;
  7023. try {
  7024. BOOL bTemp = (fShow==VARIANT_FALSE) ? FALSE:TRUE;
  7025. if (bTemp)
  7026. // Call ShowCursor(TRUE) until new counter is >= 0
  7027. while (::ShowCursor(bTemp) < 0);
  7028. else
  7029. // Call ShowCursor(FALSE) until new counter is < 0
  7030. while (::ShowCursor(bTemp) >= 0);
  7031. }/* end of try statement */
  7032. catch(HRESULT hrTmp){
  7033. hr = hrTmp;
  7034. }/* end of catch statement */
  7035. catch(...){
  7036. hr = E_UNEXPECTED;
  7037. }/* end of catch statement */
  7038. return (hr);
  7039. }/* end of function put_ShowCursor */
  7040. /*************************************************************/
  7041. /* Name: GetLangFromLangID */
  7042. /*************************************************************/
  7043. STDMETHODIMP CMSWebDVD::GetLangFromLangID(long langID, BSTR* lang){
  7044. HRESULT hr = S_OK;
  7045. try {
  7046. if (lang == NULL) {
  7047. throw(E_POINTER);
  7048. }/* end of if statement */
  7049. USES_CONVERSION;
  7050. if((unsigned long)langID > (WORD)langID){
  7051. throw(E_INVALIDARG);
  7052. }
  7053. LPTSTR pszString = m_LangID.GetLangFromLangID((WORD)langID);
  7054. if (pszString) {
  7055. *lang = ::SysAllocString(T2OLE(pszString));
  7056. }
  7057. else {
  7058. *lang = ::SysAllocString( L"");
  7059. throw(E_INVALIDARG);
  7060. }/* end of if statement */
  7061. }/* end of try statement */
  7062. catch(HRESULT hrTmp){
  7063. hr = hrTmp;
  7064. }/* end of catch statement */
  7065. catch(...){
  7066. hr = E_UNEXPECTED;
  7067. }/* end of catch statement */
  7068. return HandleError(hr);
  7069. }/* end of function GetLangFromLangID */
  7070. /*************************************************************/
  7071. /* Name: IsAudioStreamEnabled
  7072. /* Description:
  7073. /*************************************************************/
  7074. STDMETHODIMP CMSWebDVD::IsAudioStreamEnabled(long lStream, VARIANT_BOOL *fEnabled)
  7075. {
  7076. HRESULT hr = S_OK;
  7077. try {
  7078. if(lStream < 0){
  7079. throw(E_INVALIDARG);
  7080. }/* end of if statement */
  7081. if (fEnabled == NULL) {
  7082. throw(E_POINTER);
  7083. }/* end of if statement */
  7084. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  7085. if(!m_pDvdInfo2){
  7086. throw(E_UNEXPECTED);
  7087. }/* end of if statement */
  7088. BOOL temp;
  7089. hr = m_pDvdInfo2->IsAudioStreamEnabled(lStream, &temp);
  7090. if (FAILED(hr))
  7091. throw hr;
  7092. *fEnabled = temp==FALSE? VARIANT_FALSE:VARIANT_TRUE;
  7093. }/* end of try statement */
  7094. catch(HRESULT hrTmp){
  7095. hr = hrTmp;
  7096. }/* end of catch statement */
  7097. catch(...){
  7098. hr = E_UNEXPECTED;
  7099. }/* end of catch statement */
  7100. return HandleError(hr);
  7101. }
  7102. /*************************************************************/
  7103. /* Name: IsSubpictureStreamEnabled
  7104. /* Description:
  7105. /*************************************************************/
  7106. STDMETHODIMP CMSWebDVD::IsSubpictureStreamEnabled(long lStream, VARIANT_BOOL *fEnabled)
  7107. {
  7108. HRESULT hr = S_OK;
  7109. try {
  7110. if(lStream < 0){
  7111. throw(E_INVALIDARG);
  7112. }/* end of if statement */
  7113. if (fEnabled == NULL) {
  7114. throw(E_POINTER);
  7115. }/* end of if statement */
  7116. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  7117. if(!m_pDvdInfo2){
  7118. throw(E_UNEXPECTED);
  7119. }/* end of if statement */
  7120. BOOL temp;
  7121. hr = m_pDvdInfo2->IsSubpictureStreamEnabled(lStream, &temp);
  7122. if (FAILED(hr))
  7123. throw hr;
  7124. *fEnabled = temp==FALSE? VARIANT_FALSE:VARIANT_TRUE;
  7125. }/* end of try statement */
  7126. catch(HRESULT hrTmp){
  7127. hr = hrTmp;
  7128. }/* end of catch statement */
  7129. catch(...){
  7130. hr = E_UNEXPECTED;
  7131. }/* end of catch statement */
  7132. return HandleError(hr);
  7133. }
  7134. /*************************************************************/
  7135. /* Name: DVDTimeCode2bstr
  7136. /* Description:
  7137. /*************************************************************/
  7138. STDMETHODIMP CMSWebDVD::DVDTimeCode2bstr(long timeCode, BSTR *pTimeStr)
  7139. {
  7140. return DVDTime2bstr((DVD_HMSF_TIMECODE*)&timeCode, pTimeStr);
  7141. }
  7142. /*************************************************************/
  7143. /* Name: UpdateOverlay
  7144. /* Description:
  7145. /*************************************************************/
  7146. HRESULT CMSWebDVD::UpdateOverlay()
  7147. {
  7148. RECT rc;
  7149. HWND hwnd;
  7150. if(m_bWndLess){
  7151. HRESULT hr = GetParentHWND(&hwnd);
  7152. if(FAILED(hr)){
  7153. return(hr);
  7154. }/* end of if statement */
  7155. rc = m_rcPos;
  7156. }
  7157. else {
  7158. hwnd = m_hWnd;
  7159. ::GetClientRect(hwnd, &rc);
  7160. }/* end of if statement */
  7161. ::InvalidateRect(hwnd, &rc, FALSE);
  7162. m_bFireUpdateOverlay = TRUE;
  7163. return S_OK;
  7164. }
  7165. HRESULT CMSWebDVD::SetClientSite(IOleClientSite *pClientSite){
  7166. if(!!pClientSite){
  7167. HRESULT hr = IsSafeSite(pClientSite);
  7168. if(FAILED(hr)){
  7169. return hr;
  7170. }
  7171. }
  7172. return IOleObjectImpl<CMSWebDVD>::SetClientSite(pClientSite);
  7173. }
  7174. /*************************************************************************/
  7175. /* End of file: msdvd.cpp */
  7176. /*************************************************************************/