Leaked source code of windows server 2003
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.

4924 lines
145 KiB

  1. // MSVidWebDVD.cpp : Implementation of CMSVidApp and DLL registration.
  2. #include "stdafx.h"
  3. #ifndef TUNING_MODEL_ONLY
  4. #include "MSVidCtl.h"
  5. #include "MSVidWebDVD.h"
  6. #include "MSVidDVDAdm.h"
  7. //#include "vidrect.h"
  8. #include <evcode.h>
  9. #include <atltmp.h>
  10. DEFINE_EXTERN_OBJECT_ENTRY(CLSID_MSVidWebDVD, CMSVidWebDVD)
  11. DEFINE_EXTERN_OBJECT_ENTRY(CLSID_MSVidRect, CVidRect)
  12. /*************************************************************************/
  13. /* Local constants and defines */
  14. /*************************************************************************/
  15. const DWORD cdwDVDCtrlFlags = DVD_CMD_FLAG_Block | DVD_CMD_FLAG_Flush;
  16. const DWORD cdwMaxFP_DOMWait = 30000; // 30sec for FP_DOM passing should be OK
  17. const long cgStateTimeout = 0; // wait till the state transition occurs
  18. // modify if needed
  19. const long cgDVD_MIN_SUBPICTURE = 0;
  20. const long cgDVD_MAX_SUBPICTURE = 31;
  21. const long cgDVD_ALT_SUBPICTURE = 63;
  22. const long cgDVD_MIN_ANGLE = 0;
  23. const long cgDVD_MAX_ANGLE = 9;
  24. const double cgdNormalSpeed = 1.00;
  25. const long cgDVDMAX_TITLE_COUNT = 99;
  26. const long cgDVDMIN_TITLE_COUNT = 1;
  27. const long cgDVDMAX_CHAPTER_COUNT = 999;
  28. const long cgDVDMIN_CHAPTER_COUNT = 1;
  29. const LONG cgTIME_STRING_LEN = 2;
  30. const LONG cgMAX_DELIMITER_LEN = 4;
  31. const LONG cgDVD_TIME_STR_LEN = (3*cgMAX_DELIMITER_LEN)+(4*cgTIME_STRING_LEN) + 1 /*NULL Terminator*/;
  32. const long cgVOLUME_MAX = 0;
  33. const long cgVOLUME_MIN = -10000;
  34. const long cgBALANCE_MIN = -10000;
  35. const long cgBALANCE_MAX = 10000;
  36. const WORD cgWAVE_VOLUME_MIN = 0;
  37. const WORD cgWAVE_VOLUME_MAX = 0xffff;
  38. const DWORD cdwTimeout = 10; //100
  39. const long cgnStepTimeout = 100;
  40. /////////////////////////////////////////////////////////////////////////////
  41. //
  42. STDMETHODIMP CMSVidWebDVD::InterfaceSupportsErrorInfo(REFIID riid)
  43. {
  44. static const IID* arr[] =
  45. {
  46. &IID_IMSVidWebDVD,
  47. };
  48. for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
  49. {
  50. if (InlineIsEqualGUID(*arr[i],riid))
  51. return S_OK;
  52. }
  53. return S_FALSE;
  54. }
  55. /*************************************************************************/
  56. /* Function: AppendString */
  57. /* Description: Appends a string to an existing one. */
  58. /* strDest is MAX_PATH in length
  59. /*************************************************************************/
  60. HRESULT CMSVidWebDVD::AppendString(TCHAR* strDest, INT strID, LONG dwLen){
  61. if(dwLen < 0){
  62. return E_INVALIDARG;
  63. }
  64. TCHAR strBuffer[MAX_PATH];
  65. if(!::LoadString(_Module.m_hInstResource, strID, strBuffer, MAX_PATH)){
  66. return(E_UNEXPECTED);
  67. }/* end of if statement */
  68. (void)StringCchCat(strDest, dwLen, strBuffer);
  69. return(S_OK);
  70. }/* end of function AppendString */
  71. /*************************************************************************/
  72. /* Function: HandleError */
  73. /* Description: Gets Error Descriptio, so we can suppor IError Info. */
  74. /*************************************************************************/
  75. HRESULT CMSVidWebDVD::HandleError(HRESULT hr){
  76. try {
  77. if(FAILED(hr)){
  78. switch(hr){
  79. case E_NO_IDVD2_PRESENT:
  80. Error(IDS_E_NO_IDVD2_PRESENT);
  81. return (hr);
  82. case E_NO_DVD_VOLUME:
  83. Error(IDS_E_NO_DVD_VOLUME);
  84. return (hr);
  85. case E_REGION_CHANGE_FAIL:
  86. Error(IDS_E_REGION_CHANGE_FAIL);
  87. return (hr);
  88. case E_REGION_CHANGE_NOT_COMPLETED:
  89. Error(IDS_E_REGION_CHANGE_NOT_COMPLETED);
  90. return(hr);
  91. }/* end of switch statement */
  92. #if 0
  93. TCHAR strError[MAX_ERROR_TEXT_LEN] = TEXT("");
  94. if(AMGetErrorText(hr , strError , MAX_ERROR_TEXT_LEN)){
  95. USES_CONVERSION;
  96. Error(T2W(strError));
  97. }
  98. else
  99. {
  100. ATLTRACE(TEXT("Unhandled Error Code \n")); // please add it
  101. ATLASSERT(FALSE);
  102. }/* end of if statement */
  103. #endif
  104. }/* end of if statement */
  105. }/* end of try statement */
  106. catch(HRESULT hrTmp){
  107. hr = hrTmp;
  108. }/* end of catch statement */
  109. catch(...){
  110. // keep the hr same
  111. }/* end of catch statement */
  112. return (hr);
  113. }/* end of function HandleError */
  114. /*************************************************************/
  115. /* Name: CleanUp
  116. /* Description:
  117. /*************************************************************/
  118. HRESULT CMSVidWebDVD::CleanUp(){
  119. m_pDvdAdmin.Release();
  120. m_pDvdAdmin = NULL;
  121. DeleteUrlInfo();
  122. return NOERROR;
  123. }
  124. /*************************************************************/
  125. /* Name: Init
  126. /* Description:
  127. /*************************************************************/
  128. STDMETHODIMP CMSVidWebDVD::put_Init(IUnknown *pInit)
  129. {
  130. HRESULT hr = IMSVidGraphSegmentImpl<CMSVidWebDVD, MSVidSEG_SOURCE, &GUID_NULL>::put_Init(pInit);
  131. if (FAILED(hr)) {
  132. return hr;
  133. }
  134. if (pInit) {
  135. m_fInit = false;
  136. return E_NOTIMPL;
  137. }
  138. // create an event that lets us know we are past FP_DOM
  139. m_fResetSpeed = true;
  140. m_fStillOn = false;
  141. m_fEnableResetOnStop = false;
  142. m_fFireNoSubpictureStream = false;
  143. m_fStepComplete = false;
  144. m_bEjected = false;
  145. m_DVDFilterState = dvdState_Undefined;
  146. m_lKaraokeAudioPresentationMode = 0;
  147. // Create the DVD administrator
  148. m_pDvdAdmin = new CComObject<CMSVidWebDVDAdm>;
  149. return NOERROR;
  150. }
  151. /*************************************************************************/
  152. /* Function: RestoreGraphState */
  153. /* Description: Restores the graph state. Used when API fails. */
  154. /*************************************************************************/
  155. HRESULT CMSVidWebDVD::RestoreGraphState(){
  156. HRESULT hr = S_OK;
  157. switch(m_DVDFilterState){
  158. case dvdState_Undefined:
  159. case dvdState_Running: // do not do anything
  160. break;
  161. case dvdState_Unitialized:
  162. case dvdState_Stopped:
  163. hr = Stop();
  164. break;
  165. case dvdState_Paused:
  166. hr = Pause();
  167. break;
  168. }/* end of switch statement */
  169. return(hr);
  170. }/* end of if statement */
  171. /*************************************************************************/
  172. /* Function: TwoDigitToByte */
  173. /*************************************************************************/
  174. static BYTE TwoDigitToByte( const WCHAR* pTwoDigit ){
  175. int tens = int(pTwoDigit[0] - L'0');
  176. return BYTE( (pTwoDigit[1] - L'0') + tens*10);
  177. }/* end of function TwoDigitToByte */
  178. /*************************************************************************/
  179. /* Function: Bstr2DVDTime */
  180. /* Description: Converts a DVD Time info from BSTR into a TIMECODE. */
  181. /*************************************************************************/
  182. HRESULT CMSVidWebDVD::Bstr2DVDTime(DVD_HMSF_TIMECODE *ptrTimeCode, const BSTR *pbstrTime){
  183. if(NULL == pbstrTime || NULL == ptrTimeCode){
  184. return E_INVALIDARG;
  185. }/* end of if statement */
  186. ::ZeroMemory(ptrTimeCode, sizeof(DVD_HMSF_TIMECODE));
  187. WCHAR *pszTime = *pbstrTime;
  188. ULONG lStringLength = wcslen(pszTime);
  189. if(0 == lStringLength){
  190. return E_INVALIDARG;
  191. }/* end of if statement */
  192. TCHAR tszTimeSep[5];
  193. ::GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STIME, tszTimeSep, 5);
  194. // If the string is two long, it is seconds only
  195. if(lStringLength == 2){
  196. ptrTimeCode->bSeconds = TwoDigitToByte( &pszTime[0] );
  197. return S_OK;
  198. }
  199. // Otherwise it is a normal time code of the format
  200. // 43:32:21:10
  201. // Where the ':' can be replaced with a localized string of upto 4 char in len
  202. // There is a possible error case where the length of the delimeter is different
  203. // then the current delimeter
  204. if(lStringLength >= (4*cgTIME_STRING_LEN)+(3 * _tcslen(tszTimeSep))){ // longest string nnxnnxnnxnn e.g. 43:23:21:10
  205. // where n is a number and
  206. // x is a time delimeter usually ':', but can be any string upto 4 char in len)
  207. ptrTimeCode->bFrames = TwoDigitToByte( &pszTime[(3*cgTIME_STRING_LEN)+(3*_tcslen(tszTimeSep))]);
  208. }
  209. if(lStringLength >= (3*cgTIME_STRING_LEN)+(2 * _tcslen(tszTimeSep))) { // string nnxnnxnn e.g. 43:23:21
  210. ptrTimeCode->bSeconds = TwoDigitToByte( &pszTime[(2*cgTIME_STRING_LEN)+(2*_tcslen(tszTimeSep))] );
  211. }
  212. if(lStringLength >= (2*cgTIME_STRING_LEN)+(1 * _tcslen(tszTimeSep))) { // string nnxnn e.g. 43:23
  213. ptrTimeCode->bMinutes = TwoDigitToByte( &pszTime[(1*cgTIME_STRING_LEN)+(1*_tcslen(tszTimeSep))] );
  214. }
  215. if(lStringLength >= (cgTIME_STRING_LEN)) { // string nn e.g. 43
  216. ptrTimeCode->bHours = TwoDigitToByte( &pszTime[0] );
  217. }
  218. return (S_OK);
  219. }/* end of function bstr2DVDTime */
  220. /*************************************************************************/
  221. /* Function: DVDTime2bstr */
  222. /* Description: Converts a DVD Time info from ULONG into a BSTR. */
  223. /*************************************************************************/
  224. HRESULT CMSVidWebDVD::DVDTime2bstr( const DVD_HMSF_TIMECODE *pTimeCode, BSTR *pbstrTime){
  225. if(NULL == pTimeCode || NULL == pbstrTime)
  226. return E_INVALIDARG;
  227. USES_CONVERSION;
  228. TCHAR tszTime[cgDVD_TIME_STR_LEN];
  229. TCHAR tszTimeSep[5];
  230. ::ZeroMemory(tszTime, sizeof(TCHAR)*cgDVD_TIME_STR_LEN);
  231. ::GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STIME, tszTimeSep, 5);
  232. (void)StringCchPrintf( tszTime, cgDVD_TIME_STR_LEN, TEXT("%02lu%s%02lu%s%02lu%s%02lu"),
  233. pTimeCode->bHours, tszTimeSep,
  234. pTimeCode->bMinutes, tszTimeSep,
  235. pTimeCode->bSeconds, tszTimeSep,
  236. pTimeCode->bFrames );
  237. *pbstrTime = SysAllocString(T2OLE(tszTime));
  238. return (S_OK);
  239. }/* end of function DVDTime2bstr */
  240. /*************************************************************************/
  241. /* Function: PreRun */
  242. /* Description: called before the filter graph is running */
  243. /* set DVD_ResetOnStop to be false */
  244. /*************************************************************************/
  245. STDMETHODIMP CMSVidWebDVD::PreRun(){
  246. HRESULT hr = S_OK;
  247. try {
  248. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  249. if(!m_pDVDControl2){
  250. throw(E_UNEXPECTED);
  251. }/* end of if statement */
  252. // set dvd root directory from url
  253. // this has to happen before IMediaControl->Run()
  254. hr = SetDirectoryFromUrlInfo();
  255. if(FAILED(hr)){
  256. throw(hr);
  257. }/* end of if statement */
  258. if (!m_pGraph.IsPlaying()) {
  259. if(FALSE == m_fEnableResetOnStop){
  260. hr = m_pDVDControl2->SetOption(DVD_ResetOnStop, FALSE);
  261. if(FAILED(hr)){
  262. throw(hr);
  263. }/* end of if statement */
  264. }/* end of if statement */
  265. hr = m_pDVDControl2->SetOption( DVD_HMSF_TimeCodeEvents, TRUE);
  266. if(FAILED(hr)){
  267. throw(hr);
  268. }/* end of if statement */
  269. }/* end of if statement */
  270. }/* end of try statement */
  271. catch(HRESULT hrTmp){
  272. hr = hrTmp;
  273. }/* end of catch statement */
  274. catch(...){
  275. hr = E_UNEXPECTED;
  276. }/* end of catch statement */
  277. return HandleError(hr);
  278. }/* end of PreRun */
  279. /*************************************************************************/
  280. /* Function: PostRun */
  281. /* Description: Puts the filter graph in the running state in case not */
  282. /* and reset play speed to normal */
  283. /*************************************************************************/
  284. STDMETHODIMP CMSVidWebDVD::PostRun(){
  285. HRESULT hr = S_OK;
  286. try {
  287. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  288. // save the state so we can restore it if an API fails
  289. m_DVDFilterState = (DVDFilterState) m_pGraph.GetState();
  290. bool bFireEvent = false; // fire event only when we change the state
  291. if(!m_pDVDControl2){
  292. throw(E_UNEXPECTED);
  293. }/* end of if statement */
  294. if(false == m_fStillOn && true == m_fResetSpeed){
  295. // if we are in the still do not reset the speed
  296. m_pDVDControl2->PlayForwards(cgdNormalSpeed,0,0);
  297. }/* end of if statement */
  298. // set playback references such title/chapter
  299. // this call will clear urlInfo
  300. hr = SetPlaybackFromUrlInfo();
  301. }/* end of try statement */
  302. catch(HRESULT hrTmp){
  303. hr = hrTmp;
  304. }/* end of catch statement */
  305. catch(...){
  306. hr = E_UNEXPECTED;
  307. }/* end of catch statement */
  308. return HandleError(hr);
  309. }/* end of function PostRun */
  310. /*************************************************************************/
  311. /* Function: PreStop */
  312. /* Description: called before the filter graph is stopped */
  313. /* set DVD_ResetOnStop to be true */
  314. /*************************************************************************/
  315. STDMETHODIMP CMSVidWebDVD::PreStop(){
  316. HRESULT hr = S_OK;
  317. try {
  318. if(!m_pDVDControl2){
  319. throw(E_UNEXPECTED);
  320. }
  321. if (!m_pGraph.IsStopped()) {
  322. VARIANT_BOOL onStop;
  323. long dwDomain = 0;
  324. hr = get_CurrentDomain(&dwDomain);
  325. if(FAILED(hr)){
  326. return hr;
  327. }
  328. if(dwDomain != DVD_DOMAIN_Stop){
  329. hr = m_pDvdAdmin->get_BookmarkOnStop(&onStop);
  330. if(FAILED(hr)){
  331. throw(hr);
  332. }
  333. if(VARIANT_TRUE == onStop){
  334. hr = SaveBookmark();
  335. if(FAILED(hr)){
  336. throw(hr);
  337. }
  338. }
  339. if(FALSE == m_fEnableResetOnStop){
  340. hr = m_pDVDControl2->SetOption(DVD_ResetOnStop, TRUE);
  341. if(FAILED(hr)){
  342. throw(hr);
  343. }
  344. }
  345. }
  346. }
  347. }
  348. catch(HRESULT hrTmp){
  349. hr = hrTmp;
  350. }
  351. catch(...){
  352. hr = E_UNEXPECTED;
  353. }
  354. return HandleError(hr);
  355. }/* end of function PreStop */
  356. /*************************************************************************/
  357. /* Function: PostStop */
  358. /* Description: Stops the filter graph if the state does not indicate */
  359. /* it was stopped. */
  360. /*************************************************************************/
  361. STDMETHODIMP CMSVidWebDVD::PostStop(){
  362. HRESULT hr = S_OK;
  363. try {
  364. #if 0
  365. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  366. PQVidCtl pvc(m_pContainer);
  367. MSVidCtlStateList slState;
  368. HRESULT hr = pvc->get_State(&slState);
  369. if (SUCCEEDED(hr) && slState != STATE_STOP) {
  370. hr = pvc->Stop();
  371. if (FAILED(hr)) {
  372. throw (hr);
  373. }/* end of if statement */
  374. }/* end of if statement */
  375. #endif
  376. }/* end of try statement */
  377. catch(HRESULT hrTmp){
  378. hr = hrTmp;
  379. }/* end of catch statement */
  380. catch(...){
  381. hr = E_UNEXPECTED;
  382. }/* end of catch statement */
  383. return HandleError(hr);
  384. }/* end of PostStop */
  385. /*************************************************************************/
  386. /* Function: PlayTitle */
  387. /* Description: If fails waits for FP_DOM to pass and tries later. */
  388. /*************************************************************************/
  389. STDMETHODIMP CMSVidWebDVD::PlayTitle(LONG lTitle){
  390. HRESULT hr = S_OK;
  391. try {
  392. if(0 > lTitle){
  393. throw(E_INVALIDARG);
  394. }/* end of if statement */
  395. long lNumTitles = 0;
  396. hr = get_TitlesAvailable(&lNumTitles);
  397. if(FAILED(hr)){
  398. throw hr;
  399. }
  400. if(lTitle > lNumTitles){
  401. throw E_INVALIDARG;
  402. }
  403. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY;
  404. if(!m_pDVDControl2){
  405. throw(E_UNEXPECTED);
  406. }/* end of if statement */
  407. long pauseCookie = 0;
  408. HRESULT hres = RunIfPause(&pauseCookie);
  409. if(FAILED(hres)){
  410. return hres;
  411. }
  412. hr = m_pDVDControl2->PlayTitle(lTitle, cdwDVDCtrlFlags, 0);
  413. hres = PauseIfRan(pauseCookie);
  414. if(FAILED(hres)){
  415. return hres;
  416. }
  417. }/* end of try statement */
  418. catch(HRESULT hrTmp){
  419. hr = hrTmp;
  420. }/* end of catch statement */
  421. catch(...){
  422. hr = E_UNEXPECTED;
  423. }/* end of catch statement */
  424. return HandleError(hr);
  425. }/* end of function PlayTitle */
  426. /*************************************************************************/
  427. /* Function: PlayChapterInTitle */
  428. /* Description: Plays from the specified chapter without stopping */
  429. /* THIS NEEDS TO BE ENHANCED !!! Current implementation and queing */
  430. /* into the message loop is insufficient!!! TODO. */
  431. /*************************************************************************/
  432. STDMETHODIMP CMSVidWebDVD::PlayChapterInTitle(LONG lTitle, LONG lChapter){
  433. HRESULT hr = S_OK;
  434. try {
  435. if ((lTitle > cgDVDMAX_TITLE_COUNT) || (lTitle < cgDVDMIN_TITLE_COUNT)){
  436. throw(E_INVALIDARG);
  437. }/* end of if statement */
  438. if ((lChapter > cgDVDMAX_CHAPTER_COUNT) || (lChapter < cgDVDMIN_CHAPTER_COUNT)){
  439. throw(E_INVALIDARG);
  440. }/* end of if statement */
  441. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY;
  442. if(!m_pDVDControl2){
  443. throw(E_UNEXPECTED);
  444. }/* end of if statement */
  445. long pauseCookie = 0;
  446. HRESULT hres = RunIfPause(&pauseCookie);
  447. if(FAILED(hres)){
  448. return hres;
  449. }
  450. hr = m_pDVDControl2->PlayChapterInTitle(lTitle, lChapter, cdwDVDCtrlFlags, 0);
  451. hres = PauseIfRan(pauseCookie);
  452. if(FAILED(hres)){
  453. return hres;
  454. }
  455. }/* end of try statement */
  456. catch(HRESULT hrTmp){
  457. hr = hrTmp;
  458. }
  459. catch(...){
  460. hr = E_UNEXPECTED;
  461. }/* end of catch statement */
  462. return HandleError(hr);
  463. }/* end of function PlayChapterInTitle */
  464. /*************************************************************************/
  465. /* Function: PlayChapter */
  466. /* Description: Does chapter search. Waits for FP_DOM to pass and initi */
  467. /* lizes the graph as the other smar routines. */
  468. /*************************************************************************/
  469. STDMETHODIMP CMSVidWebDVD::PlayChapter(LONG lChapter){
  470. HRESULT hr = S_OK;
  471. try {
  472. if(lChapter < 0){
  473. throw(E_INVALIDARG);
  474. }/* end of if statement */
  475. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY;
  476. if(!m_pDVDControl2){
  477. throw(E_UNEXPECTED);
  478. }/* end of if statement */
  479. long pauseCookie = 0;
  480. HRESULT hres = RunIfPause(&pauseCookie);
  481. if(FAILED(hres)){
  482. return hres;
  483. }
  484. hr = m_pDVDControl2->PlayChapter(lChapter, cdwDVDCtrlFlags, 0);
  485. hres = PauseIfRan(pauseCookie);
  486. if(FAILED(hres)){
  487. return hres;
  488. }
  489. }/* end of try statement */
  490. catch(HRESULT hrTmp){
  491. hr = hrTmp;
  492. }/* end of catch statement */
  493. catch(...){
  494. hr = E_UNEXPECTED;
  495. }/* end of catch statement */
  496. return HandleError(hr);
  497. }/* end of function PlayChapter */
  498. /*************************************************************************/
  499. /* Function: PlayChapterAutoStop */
  500. /* Description: Plays set ammount of chapters. */
  501. /*************************************************************************/
  502. STDMETHODIMP CMSVidWebDVD::PlayChaptersAutoStop(LONG lTitle, LONG lChapter,
  503. LONG lChapterCount){
  504. HRESULT hr = S_OK;
  505. try {
  506. if ((lTitle > cgDVDMAX_TITLE_COUNT) || (lTitle < cgDVDMIN_TITLE_COUNT)){
  507. throw(E_INVALIDARG);
  508. }/* end of if statement */
  509. if ((lChapter > cgDVDMAX_CHAPTER_COUNT) || (lChapter < cgDVDMIN_CHAPTER_COUNT)){
  510. throw(E_INVALIDARG);
  511. }/* end of if statement */
  512. if ((lChapterCount > cgDVDMAX_CHAPTER_COUNT) || (lChapterCount < cgDVDMIN_CHAPTER_COUNT)){
  513. throw(E_INVALIDARG);
  514. }/* end of if statement */
  515. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY;
  516. if(!m_pDVDControl2){
  517. throw(E_UNEXPECTED);
  518. }/* end of if statement */
  519. long pauseCookie = 0;
  520. HRESULT hres = RunIfPause(&pauseCookie);
  521. if(FAILED(hres)){
  522. return hres;
  523. }
  524. hr = m_pDVDControl2->PlayChaptersAutoStop(lTitle, lChapter, lChapterCount, cdwDVDCtrlFlags, 0);
  525. hres = PauseIfRan(pauseCookie);
  526. if(FAILED(hres)){
  527. return hres;
  528. }
  529. }/* end of try statement */
  530. catch(HRESULT hrTmp){
  531. hr = hrTmp;
  532. }
  533. catch(...){
  534. hr = E_UNEXPECTED;
  535. }/* end of catch statement */
  536. return HandleError(hr);
  537. }/* end of function PlayChaptersAutoStop */
  538. /*************************************************************************/
  539. /* Function: PlayAtTime */
  540. /* Description: TimeSearch, converts from hh:mm:ss:ff format */
  541. /*************************************************************************/
  542. STDMETHODIMP CMSVidWebDVD::PlayAtTime(BSTR strTime){
  543. HRESULT hr = S_OK;
  544. try {
  545. if(NULL == strTime){
  546. throw(E_POINTER);
  547. }/* end of if statement */
  548. DVD_HMSF_TIMECODE tcTimeCode;
  549. Bstr2DVDTime(&tcTimeCode, &strTime);
  550. if(FAILED(hr)){
  551. throw(hr);
  552. }/* end of if statement */
  553. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY;
  554. if(!m_pDVDControl2){
  555. throw(E_UNEXPECTED);
  556. }/* end of if statement */
  557. long pauseCookie = 0;
  558. HRESULT hres = RunIfPause(&pauseCookie);
  559. if(FAILED(hres)){
  560. return hres;
  561. }
  562. hr = m_pDVDControl2->PlayAtTime( &tcTimeCode, cdwDVDCtrlFlags, 0);
  563. hres = PauseIfRan(pauseCookie);
  564. if(FAILED(hres)){
  565. return hres;
  566. }
  567. }/* end of try statement */
  568. catch(HRESULT hrTmp){
  569. hr = hrTmp;
  570. }
  571. catch(...){
  572. hr = E_UNEXPECTED;
  573. }/* end of catch statement */
  574. return HandleError(hr);
  575. }/* end of function PlayAtTime */
  576. /*************************************************************************/
  577. /* Function: PlayAtTimeInTitle */
  578. /* Description: Time plays, converts from hh:mm:ss:ff format */
  579. /*************************************************************************/
  580. STDMETHODIMP CMSVidWebDVD::PlayAtTimeInTitle(long lTitle, BSTR strTime){
  581. HRESULT hr = S_OK;
  582. try {
  583. if(NULL == strTime){
  584. throw(E_POINTER);
  585. }/* end of if statement */
  586. DVD_HMSF_TIMECODE tcTimeCode;
  587. hr = Bstr2DVDTime(&tcTimeCode, &strTime);
  588. if(FAILED(hr)){
  589. throw(hr);
  590. }/* end of if statement */
  591. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY;
  592. if(!m_pDVDControl2){
  593. throw(E_UNEXPECTED);
  594. }/* end of if statement */
  595. long pauseCookie = 0;
  596. HRESULT hres = RunIfPause(&pauseCookie);
  597. if(FAILED(hres)){
  598. return hres;
  599. }
  600. hr = m_pDVDControl2->PlayAtTimeInTitle(lTitle, &tcTimeCode, cdwDVDCtrlFlags, 0);
  601. hres = PauseIfRan(pauseCookie);
  602. if(FAILED(hres)){
  603. return hres;
  604. }
  605. }/* end of try statement */
  606. catch(HRESULT hrTmp){
  607. hr = hrTmp;
  608. }
  609. catch(...){
  610. hr = E_UNEXPECTED;
  611. }/* end of catch statement */
  612. return HandleError(hr);
  613. }/* end of function PlayAtTimeInTitle */
  614. /*************************************************************************/
  615. /* Function: PlayPeriodInTitleAutoStop */
  616. /* Description: Time plays, converts from hh:mm:ss:ff format */
  617. /*************************************************************************/
  618. STDMETHODIMP CMSVidWebDVD::PlayPeriodInTitleAutoStop(long lTitle,
  619. BSTR strStartTime, BSTR strEndTime){
  620. HRESULT hr = S_OK;
  621. try {
  622. if(NULL == strStartTime){
  623. throw(E_POINTER);
  624. }/* end of if statement */
  625. if(NULL == strEndTime){
  626. throw(E_POINTER);
  627. }/* end of if statement */
  628. DVD_HMSF_TIMECODE tcStartTimeCode;
  629. hr = Bstr2DVDTime(&tcStartTimeCode, &strStartTime);
  630. if(FAILED(hr)){
  631. throw (hr);
  632. }
  633. DVD_HMSF_TIMECODE tcEndTimeCode;
  634. Bstr2DVDTime(&tcEndTimeCode, &strEndTime);
  635. if(FAILED(hr)){
  636. throw(hr);
  637. }/* end of if statement */
  638. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY;
  639. if(!m_pDVDControl2){
  640. throw(E_UNEXPECTED);
  641. }/* end of if statement */
  642. long pauseCookie = 0;
  643. HRESULT hres = RunIfPause(&pauseCookie);
  644. if(FAILED(hres)){
  645. return hres;
  646. }
  647. hr = m_pDVDControl2->PlayPeriodInTitleAutoStop(lTitle, &tcStartTimeCode,
  648. &tcEndTimeCode, cdwDVDCtrlFlags, 0);
  649. hres = PauseIfRan(pauseCookie);
  650. if(FAILED(hres)){
  651. return hres;
  652. }
  653. }/* end of try statement */
  654. catch(HRESULT hrTmp){
  655. hr = hrTmp;
  656. }
  657. catch(...){
  658. hr = E_UNEXPECTED;
  659. }/* end of catch statement */
  660. return HandleError(hr);
  661. }/* end of function PlayPeriodInTitleAutoStop */
  662. /*************************************************************************/
  663. /* Function: ReplayChapter */
  664. /* Description: Halts playback and restarts the playback of current */
  665. /* program inside PGC. */
  666. /*************************************************************************/
  667. STDMETHODIMP CMSVidWebDVD::ReplayChapter(){
  668. HRESULT hr = S_OK;
  669. try {
  670. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY;
  671. if(!m_pDVDControl2){
  672. throw(E_UNEXPECTED);
  673. }/* end of if statement */
  674. long pauseCookie = 0;
  675. HRESULT hres = RunIfPause(&pauseCookie);
  676. if(FAILED(hres)){
  677. return hres;
  678. }
  679. hr = m_pDVDControl2->ReplayChapter(cdwDVDCtrlFlags, 0);
  680. hres = PauseIfRan(pauseCookie);
  681. if(FAILED(hres)){
  682. return hres;
  683. }
  684. }/* end of try statement */
  685. catch(HRESULT hrTmp){
  686. hr = hrTmp;
  687. }/* end of catch statement */
  688. catch(...){
  689. hr = E_UNEXPECTED;
  690. }/* end of catch statement */
  691. return HandleError(hr);
  692. }/* end of function ReplayChapter */
  693. /*************************************************************************/
  694. /* Function: PlayPrevChapter */
  695. /* Description: Goes to previous chapter */
  696. /*************************************************************************/
  697. STDMETHODIMP CMSVidWebDVD::PlayPrevChapter(){
  698. HRESULT hr = S_OK;
  699. try {
  700. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY;
  701. if(!m_pDVDControl2){
  702. throw(E_UNEXPECTED);
  703. }/* end of if statement */
  704. long pauseCookie = 0;
  705. HRESULT hres = RunIfPause(&pauseCookie);
  706. if(FAILED(hres)){
  707. return hres;
  708. }
  709. hr = m_pDVDControl2->PlayPrevChapter(cdwDVDCtrlFlags, 0);
  710. hres = PauseIfRan(pauseCookie);
  711. if(FAILED(hres)){
  712. return hres;
  713. }
  714. }/* end of try statement */
  715. catch(HRESULT hrTmp){
  716. hr = hrTmp;
  717. }/* end of catch statement */
  718. catch(...){
  719. hr = E_UNEXPECTED;
  720. }/* end of catch statement */
  721. return HandleError(hr);
  722. }/* end of function PlayPrevChapter */
  723. /*************************************************************************/
  724. /* Function: PlayNextChapter */
  725. /* Description: Goes to next chapter */
  726. /*************************************************************************/
  727. STDMETHODIMP CMSVidWebDVD::PlayNextChapter(){
  728. HRESULT hr = S_OK;
  729. CComQIPtr<IDvdCmd>IDCmd;
  730. try {
  731. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY;
  732. if(!m_pDVDControl2){
  733. throw(E_UNEXPECTED);
  734. }/* end of if statement */
  735. long pauseCookie = 0;
  736. HRESULT hres = RunIfPause(&pauseCookie);
  737. if(FAILED(hres)){
  738. return hres;
  739. }
  740. hr = m_pDVDControl2->PlayNextChapter(cdwDVDCtrlFlags, 0);
  741. hres = PauseIfRan(pauseCookie);
  742. if(FAILED(hres)){
  743. return hres;
  744. }
  745. }/* end of try statement */
  746. catch(HRESULT hrTmp){
  747. hr = hrTmp;
  748. }/* end of catch statement */
  749. catch(...){
  750. hr = E_UNEXPECTED;
  751. }/* end of catch statement */
  752. return HandleError(hr);
  753. }/* end of function PlayNextChapter */
  754. /*************************************************************************/
  755. /* Function: StillOff */
  756. /* Description: Turns the still off, what that can be used for is a */
  757. /* mistery to me. */
  758. /*************************************************************************/
  759. STDMETHODIMP CMSVidWebDVD::StillOff(){
  760. if(!m_pDVDControl2){
  761. throw(E_UNEXPECTED);
  762. }/* end of if statement */
  763. return HandleError(m_pDVDControl2->StillOff());
  764. }/* end of function StillOff */
  765. /*************************************************************************/
  766. /* Function: GetAudioLanguage */
  767. /* Description: Returns audio language associated with a stream. */
  768. /*************************************************************************/
  769. STDMETHODIMP CMSVidWebDVD::get_AudioLanguage(LONG lStream, VARIANT_BOOL fFormat, BSTR *strAudioLang){
  770. HRESULT hr = S_OK;
  771. LPTSTR pszString = NULL;
  772. try {
  773. if(NULL == strAudioLang){
  774. throw(E_POINTER);
  775. }/* end of if statement */
  776. if(lStream < 0){
  777. throw(E_INVALIDARG);
  778. }/* end of if statement */
  779. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  780. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  781. if(!pDvdInfo2){
  782. throw(E_UNEXPECTED);
  783. }/* end of if statement */
  784. USES_CONVERSION;
  785. LCID lcid = _UI32_MAX;
  786. hr = pDvdInfo2->GetAudioLanguage(lStream, &lcid);
  787. if (SUCCEEDED( hr ) && lcid < _UI32_MAX){
  788. // count up the streams for the same LCID like English 2
  789. pszString = m_LangID.GetLanguageFromLCID(PRIMARYLANGID(LANGIDFROMLCID(lcid)));
  790. if (pszString == NULL) {
  791. pszString = new TCHAR[MAX_PATH];
  792. TCHAR strBuffer[MAX_PATH];
  793. if(!::LoadString(_Module.m_hInstResource, IDS_DVD_AUDIOTRACK, strBuffer, MAX_PATH)){
  794. delete[] pszString;
  795. throw(E_UNEXPECTED);
  796. }/* end of if statement */
  797. (void)StringCchPrintf(pszString, MAX_PATH, strBuffer, lStream);
  798. }/* end of if statement */
  799. DVD_AudioAttributes attr;
  800. if(SUCCEEDED(pDvdInfo2->GetAudioAttributes(lStream, &attr))){
  801. // If want audio format param is set
  802. if (fFormat != VARIANT_FALSE) {
  803. switch(attr.AudioFormat){
  804. case DVD_AudioFormat_AC3: AppendString(pszString, IDS_DVD_DOLBY, MAX_PATH ); break;
  805. case DVD_AudioFormat_MPEG1: AppendString(pszString, IDS_DVD_MPEG1, MAX_PATH ); break;
  806. case DVD_AudioFormat_MPEG1_DRC: AppendString(pszString, IDS_DVD_MPEG1, MAX_PATH ); break;
  807. case DVD_AudioFormat_MPEG2: AppendString(pszString, IDS_DVD_MPEG2, MAX_PATH ); break;
  808. case DVD_AudioFormat_MPEG2_DRC: AppendString(pszString, IDS_DVD_MPEG2, MAX_PATH); break;
  809. case DVD_AudioFormat_LPCM: AppendString(pszString, IDS_DVD_LPCM, MAX_PATH ); break;
  810. case DVD_AudioFormat_DTS: AppendString(pszString, IDS_DVD_DTS, MAX_PATH ); break;
  811. case DVD_AudioFormat_SDDS: AppendString(pszString, IDS_DVD_SDDS, MAX_PATH ); break;
  812. }/* end of switch statement */
  813. }
  814. switch(attr.LanguageExtension){
  815. case DVD_AUD_EXT_NotSpecified:
  816. case DVD_AUD_EXT_Captions: break; // do not add anything
  817. case DVD_AUD_EXT_VisuallyImpaired: AppendString(pszString, IDS_DVD_AUDIO_VISUALLY_IMPAIRED, MAX_PATH ); break;
  818. case DVD_AUD_EXT_DirectorComments1: AppendString(pszString, IDS_DVD_AUDIO_DIRC1, MAX_PATH ); break;
  819. case DVD_AUD_EXT_DirectorComments2: AppendString(pszString, IDS_DVD_AUDIO_DIRC2, MAX_PATH ); break;
  820. }/* end of switch statement */
  821. }/* end of if statement */
  822. *strAudioLang = ::SysAllocString( T2W(pszString) );
  823. delete[] pszString;
  824. pszString = NULL;
  825. }
  826. else {
  827. *strAudioLang = ::SysAllocString( L"");
  828. // hr used to be not failed and return nothing
  829. if(SUCCEEDED(hr)) // remove this after gets fixed in DVDNav
  830. hr = E_FAIL;
  831. }/* end of if statement */
  832. }/* end of try statement */
  833. catch(HRESULT hrTmp){
  834. if (pszString) {
  835. delete[] pszString;
  836. pszString = NULL;
  837. }
  838. hr = hrTmp;
  839. }/* end of catch statement */
  840. catch(...){
  841. if (pszString) {
  842. delete[] pszString;
  843. pszString = NULL;
  844. }
  845. hr = E_UNEXPECTED;
  846. }/* end of catch statement */
  847. return HandleError(hr);
  848. }/* end of function GetAudioLanguage */
  849. /*************************************************************************/
  850. /* Function: ShowMenu */
  851. /* Description: Invokes specific menu call. */
  852. /* We set our selfs to play mode so we can execute this in case we were */
  853. /* paused or stopped. */
  854. /*************************************************************************/
  855. STDMETHODIMP CMSVidWebDVD::ShowMenu(DVDMenuIDConstants MenuID){
  856. HRESULT hr = S_OK;
  857. try {
  858. if(!m_pDVDControl2){
  859. throw(E_UNEXPECTED);
  860. }/* end of if statement */
  861. RETRY_IF_IN_FPDOM(m_pDVDControl2->ShowMenu((tagDVD_MENU_ID)MenuID, cdwDVDCtrlFlags, 0)); //!!keep in sync, or this cast will not work
  862. }/* end of try statement */
  863. catch(HRESULT hrTmp){
  864. hr = hrTmp;
  865. }/* end of catch statement */
  866. catch(...){
  867. hr = E_UNEXPECTED;
  868. }/* end of catch statement */
  869. return HandleError(hr);
  870. }
  871. /*************************************************************************/
  872. /* Function: Resume */
  873. /* Description: Resume from menu. We put our self in play state, just */
  874. /* in the case we were not in it. This might lead to some unexpected */
  875. /* behavior in case when we stopped and the tried to hit this button */
  876. /* but I think in this case might be appropriate as well. */
  877. /*************************************************************************/
  878. STDMETHODIMP CMSVidWebDVD::Resume(){
  879. HRESULT hr = S_OK;
  880. try {
  881. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY
  882. if(!m_pDVDControl2){
  883. throw(E_UNEXPECTED);
  884. }/* end of if statement */
  885. hr = m_pDVDControl2->Resume(cdwDVDCtrlFlags, 0);
  886. }/* end of try statement */
  887. catch(HRESULT hrTmp){
  888. hr = hrTmp;
  889. }/* end of catch statement */
  890. catch(...){
  891. hr = E_UNEXPECTED;
  892. }/* end of catch statement */
  893. return HandleError(hr);
  894. }/* end of function Resume */
  895. /*************************************************************************/
  896. /* Function: ReturnFromSubmenu */
  897. /* Description: Used in menu to return into prevoius menu. */
  898. /*************************************************************************/
  899. STDMETHODIMP CMSVidWebDVD::ReturnFromSubmenu(){
  900. HRESULT hr = S_OK;
  901. try {
  902. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY
  903. if(!m_pDVDControl2){
  904. throw(E_UNEXPECTED);
  905. }/* end of if statement */
  906. RETRY_IF_IN_FPDOM(m_pDVDControl2->ReturnFromSubmenu(cdwDVDCtrlFlags, 0));
  907. }/* end of try statement */
  908. catch(HRESULT hrTmp){
  909. hr = hrTmp;
  910. }/* end of catch statement */
  911. catch(...){
  912. hr = E_UNEXPECTED;
  913. }/* end of catch statement */
  914. return HandleError(hr);
  915. }/* end of function Return */
  916. /*************************************************************************/
  917. /* Function: get_ButtonsAvailable */
  918. /* Description: Gets the count of the available buttons. */
  919. /*************************************************************************/
  920. STDMETHODIMP CMSVidWebDVD::get_ButtonsAvailable(long *plNumButtons){
  921. HRESULT hr = S_OK;
  922. try {
  923. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  924. if(!pDvdInfo2){
  925. throw(E_UNEXPECTED);
  926. }/* end of if statement */
  927. ULONG ulCurrentButton = 0L;
  928. hr = pDvdInfo2->GetCurrentButton((ULONG*)plNumButtons, &ulCurrentButton);
  929. }/* end of try statement */
  930. catch(HRESULT hrTmp){
  931. hr = hrTmp;
  932. }/* end of catch statement */
  933. catch(...){
  934. hr = E_UNEXPECTED;
  935. }/* end of catch statement */
  936. return HandleError(hr);
  937. }/* end of function get_ButtonsAvailable */
  938. /*************************************************************************/
  939. /* Function: get_CurrentButton */
  940. /* Description: Gets currently selected button. */
  941. /*************************************************************************/
  942. STDMETHODIMP CMSVidWebDVD::get_CurrentButton(long *plCurrentButton){
  943. HRESULT hr = S_OK;
  944. try {
  945. if(NULL == plCurrentButton){
  946. throw(E_POINTER);
  947. }/* end of if statement */
  948. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  949. if(!pDvdInfo2){
  950. throw(E_UNEXPECTED);
  951. }/* end of if statement */
  952. ULONG ulNumButtons = 0L;
  953. *plCurrentButton = 0;
  954. hr = pDvdInfo2->GetCurrentButton(&ulNumButtons, (ULONG*)plCurrentButton);
  955. }/* end of try statement */
  956. catch(HRESULT hrTmp){
  957. hr = hrTmp;
  958. }/* end of catch statement */
  959. catch(...){
  960. hr = E_UNEXPECTED;
  961. }/* end of catch statement */
  962. return HandleError(hr);
  963. }/* end of function get_CurrentButton */
  964. /*************************************************************************/
  965. /* Function: SelectUpperButton */
  966. /* Description: Selects the upper button on DVD Menu. */
  967. /*************************************************************************/
  968. STDMETHODIMP CMSVidWebDVD::SelectUpperButton(){
  969. HRESULT hr = S_OK;
  970. try {
  971. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY
  972. if(!m_pDVDControl2){
  973. throw(E_UNEXPECTED);
  974. }/* end of if statement */
  975. hr = m_pDVDControl2->SelectRelativeButton(DVD_Relative_Upper);
  976. }/* end of try statement */
  977. catch(HRESULT hrTmp){
  978. hr = hrTmp;
  979. }/* end of catch statement */
  980. catch(...){
  981. hr = E_UNEXPECTED;
  982. }/* end of catch statement */
  983. return HandleError(hr);
  984. }/* end of function SelectUpperButton */
  985. /*************************************************************************/
  986. /* Function: SelectLowerButton */
  987. /* Description: Selects the lower button on DVD Menu. */
  988. /*************************************************************************/
  989. STDMETHODIMP CMSVidWebDVD::SelectLowerButton(){
  990. HRESULT hr = S_OK;
  991. try {
  992. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY
  993. if(!m_pDVDControl2){
  994. throw(E_UNEXPECTED);
  995. }/* end of if statement */
  996. hr = m_pDVDControl2->SelectRelativeButton(DVD_Relative_Lower);
  997. }/* end of try statement */
  998. catch(HRESULT hrTmp){
  999. hr = hrTmp;
  1000. }/* end of catch statement */
  1001. catch(...){
  1002. hr = E_UNEXPECTED;
  1003. }/* end of catch statement */
  1004. return HandleError(hr);
  1005. }/* end of function SelectLowerButton */
  1006. /*************************************************************************/
  1007. /* Function: SelectLeftButton */
  1008. /* Description: Selects the left button on DVD Menu. */
  1009. /*************************************************************************/
  1010. STDMETHODIMP CMSVidWebDVD::SelectLeftButton(){
  1011. HRESULT hr = S_OK;
  1012. try {
  1013. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY
  1014. if(!m_pDVDControl2){
  1015. throw(E_UNEXPECTED);
  1016. }/* end of if statement */
  1017. hr = m_pDVDControl2->SelectRelativeButton(DVD_Relative_Left);
  1018. }/* end of try statement */
  1019. catch(HRESULT hrTmp){
  1020. hr = hrTmp;
  1021. }/* end of catch statement */
  1022. catch(...){
  1023. hr = E_UNEXPECTED;
  1024. }/* end of catch statement */
  1025. return HandleError(hr);
  1026. }/* end of function SelectLeftButton */
  1027. /*************************************************************************/
  1028. /* Function: SelectRightButton */
  1029. /* Description: Selects the right button on DVD Menu. */
  1030. /*************************************************************************/
  1031. STDMETHODIMP CMSVidWebDVD::SelectRightButton(){
  1032. HRESULT hr = S_OK;
  1033. try {
  1034. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY
  1035. if(!m_pDVDControl2){
  1036. throw(E_UNEXPECTED);
  1037. }/* end of if statement */
  1038. hr = m_pDVDControl2->SelectRelativeButton(DVD_Relative_Right);
  1039. }/* end of try statement */
  1040. catch(HRESULT hrTmp){
  1041. hr = hrTmp;
  1042. }/* end of catch statement */
  1043. catch(...){
  1044. hr = E_UNEXPECTED;
  1045. }/* end of catch statement */
  1046. return HandleError(hr);
  1047. }/* end of function SelectRightButton */
  1048. /*************************************************************************/
  1049. /* Function: ActivateButton */
  1050. /* Description: Activates the selected button on DVD Menu. */
  1051. /*************************************************************************/
  1052. STDMETHODIMP CMSVidWebDVD::ActivateButton(){
  1053. HRESULT hr = S_OK;
  1054. try {
  1055. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY
  1056. if(!m_pDVDControl2){
  1057. throw(E_UNEXPECTED);
  1058. }/* end of if statement */
  1059. hr = m_pDVDControl2->ActivateButton();
  1060. }/* end of try statement */
  1061. catch(HRESULT hrTmp){
  1062. hr = hrTmp;
  1063. }/* end of catch statement */
  1064. catch(...){
  1065. hr = E_UNEXPECTED;
  1066. }/* end of catch statement */
  1067. return HandleError(hr);
  1068. }/* end of function ActivateButton */
  1069. /*************************************************************************/
  1070. /* Function: SelectAndActivateButton */
  1071. /* Description: Selects and activates the specific button. */
  1072. /*************************************************************************/
  1073. STDMETHODIMP CMSVidWebDVD::SelectAndActivateButton(long lButton){
  1074. HRESULT hr = S_OK;
  1075. try {
  1076. if(lButton < 0){
  1077. throw(E_INVALIDARG);
  1078. }/* end of if statement */
  1079. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY
  1080. if(!m_pDVDControl2){
  1081. throw(E_UNEXPECTED);
  1082. }/* end of if statement */
  1083. hr = m_pDVDControl2->SelectAndActivateButton((ULONG)lButton);
  1084. }/* end of try statement */
  1085. catch(HRESULT hrTmp){
  1086. hr = hrTmp;
  1087. }/* end of catch statement */
  1088. catch(...){
  1089. hr = E_UNEXPECTED;
  1090. }/* end of catch statement */
  1091. return HandleError(hr);
  1092. }/* end of function SelectAndActivateButton */
  1093. /*************************************************************************/
  1094. /* Function: TransformToWndwls */
  1095. /* Description: Transforms the coordinates to screen onse. */
  1096. /*************************************************************************/
  1097. HRESULT CMSVidWebDVD::TransformToWndwls(POINT& pt){
  1098. HRESULT hr = S_FALSE;
  1099. #if 0
  1100. // we are windowless we need to map the points to screen coordinates
  1101. if(m_bWndLess){
  1102. HWND hwnd = NULL;
  1103. hr = GetParentHWND(&hwnd);
  1104. if(FAILED(hr)){
  1105. return(hr);
  1106. }/* end of if statement */
  1107. if(!::IsWindow(hwnd)){
  1108. hr = E_UNEXPECTED;
  1109. return(hr);
  1110. }/* end of if statement */
  1111. ::MapWindowPoints(hwnd, ::GetDesktopWindow(), &pt, 1);
  1112. hr = S_OK;
  1113. }/* end of if statement */
  1114. #endif
  1115. return(hr);
  1116. }/* end of function TransformToWndwls */
  1117. /*************************************************************************/
  1118. /* Function: ActivateAtPosition */
  1119. /* Description: Activates a button at selected position. */
  1120. /*************************************************************************/
  1121. STDMETHODIMP CMSVidWebDVD::ActivateAtPosition(long xPos, long yPos){
  1122. HRESULT hr = S_OK;
  1123. try {
  1124. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1125. if(!m_pDVDControl2){
  1126. throw(E_UNEXPECTED);
  1127. }/* end of if statement */
  1128. POINT pt = {xPos, yPos};
  1129. hr = TransformToWndwls(pt);
  1130. if(FAILED(hr)){
  1131. throw(hr);
  1132. }/* end of if statement */
  1133. hr = m_pDVDControl2->ActivateAtPosition(pt);
  1134. }/* end of try statement */
  1135. catch(HRESULT hrTmp){
  1136. hr = hrTmp;
  1137. }/* end of catch statement */
  1138. catch(...){
  1139. hr = E_UNEXPECTED;
  1140. }/* end of catch statement */
  1141. return HandleError(hr);
  1142. }/* end of function ActivateAtPosition */
  1143. /*************************************************************************/
  1144. /* Function: SelectAtPosition */
  1145. /* Description: Selects a button at selected position. */
  1146. /*************************************************************************/
  1147. STDMETHODIMP CMSVidWebDVD::SelectAtPosition(long xPos, long yPos){
  1148. HRESULT hr = S_OK;
  1149. try {
  1150. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1151. if(!m_pDVDControl2){
  1152. throw(E_UNEXPECTED);
  1153. }/* end of if statement */
  1154. POINT pt = {xPos, yPos};
  1155. hr = TransformToWndwls(pt);
  1156. if(FAILED(hr)){
  1157. throw(hr);
  1158. }/* end of if statement */
  1159. hr = m_pDVDControl2->SelectAtPosition(pt);
  1160. }/* end of try statement */
  1161. catch(HRESULT hrTmp){
  1162. hr = hrTmp;
  1163. }/* end of catch statement */
  1164. catch(...){
  1165. hr = E_UNEXPECTED;
  1166. }/* end of catch statement */
  1167. return HandleError(hr);
  1168. }/* end of function SelectAtPosition */
  1169. /*************************************************************************/
  1170. /* Function: GetButtonAtPosition */
  1171. /* Description: Gets the button number associated with a position. */
  1172. /*************************************************************************/
  1173. STDMETHODIMP CMSVidWebDVD::get_ButtonAtPosition(long xPos, long yPos,
  1174. long *plButton)
  1175. {
  1176. HRESULT hr = S_OK;
  1177. try {
  1178. if(!plButton){
  1179. return E_POINTER;
  1180. }
  1181. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1182. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  1183. if(!pDvdInfo2){
  1184. throw(E_UNEXPECTED);
  1185. }/* end of if statement */
  1186. POINT pt = {xPos, yPos};
  1187. hr = TransformToWndwls(pt);
  1188. if(FAILED(hr)){
  1189. throw(hr);
  1190. }/* end of if statement */
  1191. ULONG ulButton;
  1192. hr = pDvdInfo2->GetButtonAtPosition(pt, &ulButton);
  1193. if(SUCCEEDED(hr)){
  1194. *plButton = ulButton;
  1195. }
  1196. else {
  1197. plButton = 0;
  1198. }/* end of if statement */
  1199. }/* end of try statement */
  1200. catch(HRESULT hrTmp){
  1201. hr = hrTmp;
  1202. }/* end of catch statement */
  1203. catch(...){
  1204. hr = E_UNEXPECTED;
  1205. }/* end of catch statement */
  1206. return HandleError(hr);
  1207. }/* end of function GetButtonAtPosition */
  1208. /*************************************************************************/
  1209. /* Function: GetNumberChapterOfChapters */
  1210. /* Description: Returns the number of chapters in title. */
  1211. /*************************************************************************/
  1212. STDMETHODIMP CMSVidWebDVD::get_NumberOfChapters(long lTitle, long *pVal){
  1213. HRESULT hr = S_OK;
  1214. try {
  1215. if(NULL == pVal){
  1216. throw(E_POINTER);
  1217. }/* end of if statement */
  1218. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1219. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  1220. if(!pDvdInfo2){
  1221. throw(E_UNEXPECTED);
  1222. }/* end of if statement */
  1223. hr = pDvdInfo2->GetNumberOfChapters(lTitle, (ULONG*)pVal);
  1224. }
  1225. catch(HRESULT hrTmp){
  1226. hr = hrTmp;
  1227. }/* end of catch statement */
  1228. catch(...){
  1229. hr = E_UNEXPECTED;
  1230. }/* end of catch statement */
  1231. return HandleError(hr);
  1232. }/* end of function GetNumberChapterOfChapters */
  1233. /*************************************************************************/
  1234. /* Function: get_TitlesAvailable */
  1235. /* Description: Gets the number of titles. */
  1236. /*************************************************************************/
  1237. STDMETHODIMP CMSVidWebDVD::get_TitlesAvailable(long *pVal){
  1238. HRESULT hr = S_OK;
  1239. try {
  1240. if(NULL == pVal){
  1241. throw(E_POINTER);
  1242. }/* end of if statement */
  1243. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1244. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  1245. if(!pDvdInfo2){
  1246. throw(E_UNEXPECTED);
  1247. }/* end of if statement */
  1248. ULONG NumOfVol;
  1249. ULONG ThisVolNum;
  1250. DVD_DISC_SIDE Side;
  1251. ULONG TitleCount;
  1252. hr = pDvdInfo2->GetDVDVolumeInfo(&NumOfVol, &ThisVolNum, &Side, &TitleCount);
  1253. *pVal = (LONG) TitleCount;
  1254. }
  1255. catch(HRESULT hrTmp){
  1256. hr = hrTmp;
  1257. }/* end of catch statement */
  1258. catch(...){
  1259. hr = E_UNEXPECTED;
  1260. }/* end of catch statement */
  1261. return HandleError(hr);
  1262. }/* end of function get_TitlesAvailable */
  1263. /*************************************************************************/
  1264. /* Function: get_TotalTitleTime */
  1265. /* Description: Gets total time in the title. */
  1266. /*************************************************************************/
  1267. STDMETHODIMP CMSVidWebDVD::get_TotalTitleTime(BSTR *pTime){
  1268. HRESULT hr = S_OK;
  1269. try {
  1270. if(NULL == pTime){
  1271. throw(E_POINTER);
  1272. }/* end of if statement */
  1273. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1274. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  1275. if(!pDvdInfo2){
  1276. throw(E_UNEXPECTED);
  1277. }/* end of if statement */
  1278. DVD_HMSF_TIMECODE tcTime;
  1279. ULONG ulFlags; // contains 30fps/25fps
  1280. hr = pDvdInfo2->GetTotalTitleTime(&tcTime, &ulFlags);
  1281. if(FAILED(hr)){
  1282. throw(hr);
  1283. }/* end of if statement */
  1284. hr = DVDTime2bstr(&tcTime, pTime);
  1285. }/* end of try statement */
  1286. catch(HRESULT hrTmp){
  1287. hr = hrTmp;
  1288. }/* end of catch statement */
  1289. catch(...){
  1290. hr = E_UNEXPECTED;
  1291. }/* end of catch statement */
  1292. return HandleError(hr);
  1293. }/* end of function get_TotalTitleTime */
  1294. /*************************************************************************/
  1295. /* Function: get_VolumesAvailable */
  1296. /* Description: Gets total number of volumes available. */
  1297. /*************************************************************************/
  1298. STDMETHODIMP CMSVidWebDVD::get_VolumesAvailable(long *plNumOfVol){
  1299. HRESULT hr = S_OK;
  1300. try {
  1301. if(NULL == plNumOfVol){
  1302. throw(E_POINTER);
  1303. }/* end of if statement */
  1304. ULONG ulThisVolNum;
  1305. DVD_DISC_SIDE discSide;
  1306. ULONG ulNumOfTitles;
  1307. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1308. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  1309. if(!pDvdInfo2){
  1310. throw(E_UNEXPECTED);
  1311. }/* end of if statement */
  1312. hr = pDvdInfo2->GetDVDVolumeInfo( (ULONG*)plNumOfVol,
  1313. &ulThisVolNum,
  1314. &discSide,
  1315. &ulNumOfTitles);
  1316. }/* end of try statement */
  1317. catch(HRESULT hrTmp){
  1318. hr = hrTmp;
  1319. }/* end of catch statement */
  1320. catch(...){
  1321. hr = E_UNEXPECTED;
  1322. }/* end of catch statement */
  1323. return HandleError(hr);
  1324. }/* end of function get_VolumesAvailable */
  1325. /*************************************************************************/
  1326. /* Function: get_CurrentVolume */
  1327. /* Description: Gets current volume. */
  1328. /*************************************************************************/
  1329. STDMETHODIMP CMSVidWebDVD::get_CurrentVolume(long *plVolume){
  1330. HRESULT hr = S_OK;
  1331. try {
  1332. if(NULL == plVolume){
  1333. throw(E_POINTER);
  1334. }/* end of if statement */
  1335. ULONG ulNumOfVol;
  1336. DVD_DISC_SIDE discSide;
  1337. ULONG ulNumOfTitles;
  1338. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1339. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  1340. if(!pDvdInfo2){
  1341. throw(E_UNEXPECTED);
  1342. }/* end of if statement */
  1343. hr = pDvdInfo2->GetDVDVolumeInfo( &ulNumOfVol,
  1344. (ULONG*)plVolume,
  1345. &discSide,
  1346. &ulNumOfTitles);
  1347. }/* end of try statement */
  1348. catch(HRESULT hrTmp){
  1349. hr = hrTmp;
  1350. }/* end of catch statement */
  1351. catch(...){
  1352. hr = E_UNEXPECTED;
  1353. }/* end of catch statement */
  1354. return HandleError(hr);
  1355. }/* end of function get_CurrentVolume */
  1356. /*************************************************************************/
  1357. /* Function: get_CurrentDiscSide */
  1358. /*************************************************************************/
  1359. STDMETHODIMP CMSVidWebDVD::get_CurrentDiscSide(long *plDiscSide){
  1360. HRESULT hr = S_OK;
  1361. try {
  1362. if(NULL == plDiscSide){
  1363. throw(E_POINTER);
  1364. }/* end of if statement */
  1365. ULONG ulNumOfVol;
  1366. ULONG ulThisVolNum;
  1367. DVD_DISC_SIDE discSide;
  1368. ULONG ulNumOfTitles;
  1369. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1370. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  1371. if(!pDvdInfo2){
  1372. throw(E_UNEXPECTED);
  1373. }/* end of if statement */
  1374. hr = pDvdInfo2->GetDVDVolumeInfo( &ulNumOfVol,
  1375. &ulThisVolNum,
  1376. &discSide,
  1377. &ulNumOfTitles);
  1378. *plDiscSide = discSide;
  1379. }/* end of try statement */
  1380. catch(HRESULT hrTmp){
  1381. hr = hrTmp;
  1382. }/* end of catch statement */
  1383. catch(...){
  1384. hr = E_UNEXPECTED;
  1385. }/* end of catch statement */
  1386. return HandleError(hr);
  1387. }/* end of function get_CurrentDiscSide */
  1388. /*************************************************************************/
  1389. /* Function: get_CurrentDomain */
  1390. /* Description: gets current DVD domain. */
  1391. /*************************************************************************/
  1392. STDMETHODIMP CMSVidWebDVD::get_CurrentDomain(long *plDomain){
  1393. HRESULT hr = S_OK;
  1394. try {
  1395. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1396. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  1397. if(!pDvdInfo2){
  1398. throw(E_UNEXPECTED);
  1399. }/* end of if statement */
  1400. if(NULL == plDomain){
  1401. throw(E_POINTER);
  1402. }/* end of if statememt */
  1403. hr = pDvdInfo2->GetCurrentDomain((DVD_DOMAIN *)plDomain);
  1404. }/* end of try statement */
  1405. catch(HRESULT hrTmp){
  1406. hr = hrTmp;
  1407. }/* end of catch statement */
  1408. catch(...){
  1409. hr = E_UNEXPECTED;
  1410. }/* end of catch statement */
  1411. return HandleError(hr);
  1412. }/* end of function get_CurrentDomain */
  1413. /*************************************************************************/
  1414. /* Function: get_CurrentChapter */
  1415. /* Description: Gets current chapter */
  1416. /*************************************************************************/
  1417. STDMETHODIMP CMSVidWebDVD::get_CurrentChapter(long *pVal){
  1418. HRESULT hr = S_OK;
  1419. try {
  1420. if(NULL == pVal){
  1421. throw(E_POINTER);
  1422. }/* end of if statement */
  1423. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1424. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  1425. if(!pDvdInfo2){
  1426. throw(E_UNEXPECTED);
  1427. }/* end of if statement */
  1428. DVD_PLAYBACK_LOCATION2 dvdLocation;
  1429. RETRY_IF_IN_FPDOM(pDvdInfo2->GetCurrentLocation(&dvdLocation));
  1430. if(SUCCEEDED(hr)){
  1431. *pVal = dvdLocation.ChapterNum;
  1432. }
  1433. else {
  1434. *pVal = 0;
  1435. }/* end of if statement */
  1436. }/* end of try statement */
  1437. catch(HRESULT hrTmp){
  1438. hr = hrTmp;
  1439. }
  1440. catch(...){
  1441. hr = E_UNEXPECTED;
  1442. }/* end of catch statement */
  1443. return HandleError(hr);
  1444. }/* end of function get_CurrentChapter */
  1445. /*************************************************************************/
  1446. /* Function: get_CurrentTitle */
  1447. /* Description: Gets current title. */
  1448. /*************************************************************************/
  1449. STDMETHODIMP CMSVidWebDVD::get_CurrentTitle(long *pVal){
  1450. HRESULT hr = S_OK;
  1451. try {
  1452. if(NULL == pVal){
  1453. throw(E_POINTER);
  1454. }/* end of if statement */
  1455. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1456. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  1457. if(!pDvdInfo2){
  1458. throw(E_UNEXPECTED);
  1459. }/* end of if statement */
  1460. DVD_PLAYBACK_LOCATION2 dvdLocation;
  1461. RETRY_IF_IN_FPDOM(pDvdInfo2->GetCurrentLocation(&dvdLocation));
  1462. if(SUCCEEDED(hr)){
  1463. *pVal = dvdLocation.TitleNum;
  1464. }
  1465. else {
  1466. *pVal = 0;
  1467. }/* end of if statement */
  1468. }/* end of try statement */
  1469. catch(HRESULT hrTmp){
  1470. hr = hrTmp;
  1471. }
  1472. catch(...){
  1473. hr = E_UNEXPECTED;
  1474. }/* end of catch statement */
  1475. return HandleError(hr);
  1476. }/* end of function get_CurrentTitle */
  1477. /*************************************************************************/
  1478. /* Function: get_CurrentTime */
  1479. /* Description: Gets current time. */
  1480. /*************************************************************************/
  1481. STDMETHODIMP CMSVidWebDVD::get_CurrentTime(BSTR *pVal){
  1482. HRESULT hr = S_OK;
  1483. try {
  1484. if(NULL == pVal){
  1485. throw(E_POINTER);
  1486. }/* end of if statement */
  1487. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1488. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  1489. if(!pDvdInfo2){
  1490. throw(E_UNEXPECTED);
  1491. }/* end of if statement */
  1492. DVD_PLAYBACK_LOCATION2 dvdLocation;
  1493. hr = pDvdInfo2->GetCurrentLocation(&dvdLocation);
  1494. DVDTime2bstr(&(dvdLocation.TimeCode), pVal);
  1495. }/* end of try statement */
  1496. catch(HRESULT hrTmp){
  1497. hr = hrTmp;
  1498. }/* end of catch statement */
  1499. catch(...){
  1500. hr = E_UNEXPECTED;
  1501. }/* end of catch statement */
  1502. return HandleError(hr);
  1503. }/* end of function get_CurrentTime */
  1504. /*************************************************************/
  1505. /* Name: DVDTimeCode2bstr
  1506. /* Description: returns time string for HMSF timecode
  1507. /*************************************************************/
  1508. STDMETHODIMP CMSVidWebDVD::DVDTimeCode2bstr(/*[in]*/ long timeCode, /*[out, retval]*/ BSTR *pTimeStr){
  1509. return DVDTime2bstr((DVD_HMSF_TIMECODE*)&timeCode, pTimeStr);
  1510. }
  1511. /*************************************************************************/
  1512. /* Function: get_DVDDirectory */
  1513. /* Description: Gets the root of the DVD drive. */
  1514. /*************************************************************************/
  1515. STDMETHODIMP CMSVidWebDVD::get_DVDDirectory(BSTR *pVal){
  1516. HRESULT hr = S_OK;
  1517. try {
  1518. if(NULL == pVal){
  1519. throw(E_POINTER);
  1520. }/* end of if statement */
  1521. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1522. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  1523. if(!pDvdInfo2){
  1524. throw(E_UNEXPECTED);
  1525. }/* end of if statement */
  1526. WCHAR szRoot[MAX_PATH];
  1527. ULONG ulActual;
  1528. hr = pDvdInfo2->GetDVDDirectory(szRoot, MAX_PATH, &ulActual);
  1529. *pVal = ::SysAllocString(szRoot);
  1530. }
  1531. catch(HRESULT hrTmp){
  1532. hr = hrTmp;
  1533. }/* end of catch statement */
  1534. catch(...){
  1535. hr = E_UNEXPECTED;
  1536. }/* end of catch statement */
  1537. return HandleError(hr);
  1538. }/* end of function get_DVDDirectory */
  1539. /*************************************************************************/
  1540. /* Function: put_DVDDirectory */
  1541. /* Description: Sets the root for DVD control. */
  1542. /*************************************************************************/
  1543. STDMETHODIMP CMSVidWebDVD::put_DVDDirectory(BSTR bstrRoot){
  1544. HRESULT hr = S_OK;
  1545. try {
  1546. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1547. if(!m_pDVDControl2){
  1548. throw(E_UNEXPECTED);
  1549. }/* end of if statement */
  1550. hr = m_pDVDControl2->SetDVDDirectory(bstrRoot);
  1551. }
  1552. catch(HRESULT hrTmp){
  1553. hr = hrTmp;
  1554. }/* end of catch statement */
  1555. catch(...){
  1556. hr = E_UNEXPECTED;
  1557. }/* end of catch statement */
  1558. return HandleError(hr);
  1559. }/* end of function put_DVDDirectory */
  1560. /*************************************************************/
  1561. /* Name: IsSubpictureStreamEnabled
  1562. /* Description:
  1563. /*************************************************************/
  1564. STDMETHODIMP CMSVidWebDVD::IsSubpictureStreamEnabled(long lStream, VARIANT_BOOL *fEnabled)
  1565. {
  1566. HRESULT hr = S_OK;
  1567. try {
  1568. if(lStream < 0){
  1569. throw(E_INVALIDARG);
  1570. }/* end of if statement */
  1571. if (fEnabled == NULL) {
  1572. throw(E_POINTER);
  1573. }/* end of if statement */
  1574. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1575. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  1576. if(!pDvdInfo2){
  1577. throw(E_UNEXPECTED);
  1578. }/* end of if statement */
  1579. BOOL temp;
  1580. hr = pDvdInfo2->IsSubpictureStreamEnabled(lStream, &temp);
  1581. if (FAILED(hr))
  1582. throw hr;
  1583. *fEnabled = temp==FALSE? VARIANT_FALSE:VARIANT_TRUE;
  1584. }/* end of try statement */
  1585. catch(HRESULT hrTmp){
  1586. hr = hrTmp;
  1587. }/* end of catch statement */
  1588. catch(...){
  1589. hr = E_UNEXPECTED;
  1590. }/* end of catch statement */
  1591. return HandleError(hr);
  1592. }
  1593. /*************************************************************/
  1594. /* Name: IsAudioStreamEnabled
  1595. /* Description:
  1596. /*************************************************************/
  1597. STDMETHODIMP CMSVidWebDVD::IsAudioStreamEnabled(long lStream, VARIANT_BOOL *fEnabled)
  1598. {
  1599. HRESULT hr = S_OK;
  1600. try {
  1601. if(lStream < 0){
  1602. throw(E_INVALIDARG);
  1603. }/* end of if statement */
  1604. if (fEnabled == NULL) {
  1605. throw(E_POINTER);
  1606. }/* end of if statement */
  1607. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1608. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  1609. if(!pDvdInfo2){
  1610. throw(E_UNEXPECTED);
  1611. }/* end of if statement */
  1612. BOOL temp;
  1613. hr = pDvdInfo2->IsAudioStreamEnabled(lStream, &temp);
  1614. if (FAILED(hr))
  1615. throw hr;
  1616. *fEnabled = temp==FALSE? VARIANT_FALSE:VARIANT_TRUE;
  1617. }/* end of try statement */
  1618. catch(HRESULT hrTmp){
  1619. hr = hrTmp;
  1620. }/* end of catch statement */
  1621. catch(...){
  1622. hr = E_UNEXPECTED;
  1623. }/* end of catch statement */
  1624. return HandleError(hr);
  1625. }
  1626. /*************************************************************************/
  1627. /* Function: get_CurrentSubpictureStream */
  1628. /* Description: Gets the current subpicture stream. */
  1629. /*************************************************************************/
  1630. STDMETHODIMP CMSVidWebDVD::get_CurrentSubpictureStream(long *plSubpictureStream){
  1631. HRESULT hr = S_OK;
  1632. try {
  1633. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1634. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  1635. if(!pDvdInfo2){
  1636. throw(E_UNEXPECTED);
  1637. }/* end of if statement */
  1638. ULONG ulStreamsAvailable = 0L;
  1639. BOOL bIsDisabled = TRUE;
  1640. RETRY_IF_IN_FPDOM(pDvdInfo2->GetCurrentSubpicture(&ulStreamsAvailable, (ULONG*)plSubpictureStream, &bIsDisabled ));
  1641. }/* end of try statement */
  1642. catch(HRESULT hrTmp){
  1643. hr = hrTmp;
  1644. }/* end of catch statement */
  1645. catch(...){
  1646. hr = E_UNEXPECTED;
  1647. }/* end of catch statement */
  1648. return HandleError(hr);
  1649. }/* end of function get_CurrentSubpictureStream */
  1650. /*************************************************************************/
  1651. /* Function: put_CurrentSubpictureStream */
  1652. /* Description: Sets the current subpicture stream. */
  1653. /*************************************************************************/
  1654. STDMETHODIMP CMSVidWebDVD::put_CurrentSubpictureStream(long lSubpictureStream){
  1655. HRESULT hr = S_OK;
  1656. try {
  1657. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1658. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  1659. if(!pDvdInfo2){
  1660. throw(E_UNEXPECTED);
  1661. }/* end of if statement */
  1662. if(!m_pDVDControl2){
  1663. throw(E_UNEXPECTED);
  1664. }/* end of if statement */
  1665. if( lSubpictureStream < cgDVD_MIN_SUBPICTURE
  1666. || (lSubpictureStream > cgDVD_MAX_SUBPICTURE
  1667. && lSubpictureStream != cgDVD_ALT_SUBPICTURE)){
  1668. throw(E_INVALIDARG);
  1669. }/* end of if statement */
  1670. RETRY_IF_IN_FPDOM(m_pDVDControl2->SelectSubpictureStream(lSubpictureStream,0,0));
  1671. if(FAILED(hr)){
  1672. throw(hr);
  1673. }/* end of if statement */
  1674. // now enabled the subpicture stream if it is not enabled
  1675. ULONG ulStraemsAvial = 0L, ulCurrentStrean = 0L;
  1676. BOOL fDisabled = TRUE;
  1677. hr = pDvdInfo2->GetCurrentSubpicture(&ulStraemsAvial, &ulCurrentStrean, &fDisabled);
  1678. if(FAILED(hr)){
  1679. throw(hr);
  1680. }/* end of if statement */
  1681. if(TRUE == fDisabled){
  1682. hr = m_pDVDControl2->SetSubpictureState(TRUE,0,0); //turn it on
  1683. }/* end of if statement */
  1684. }/* end of try statement */
  1685. catch(HRESULT hrTmp){
  1686. hr = hrTmp;
  1687. }/* end of catch statement */
  1688. catch(...){
  1689. hr = E_UNEXPECTED;
  1690. }/* end of catch statement */
  1691. return HandleError(hr);
  1692. }/* end of function put_CurrentSubpictureStream */
  1693. /*************************************************************************/
  1694. /* Function: get_SubpictureOn */
  1695. /* Description: Gets the current subpicture status On or Off */
  1696. /*************************************************************************/
  1697. STDMETHODIMP CMSVidWebDVD::get_SubpictureOn(VARIANT_BOOL *pfDisplay){
  1698. HRESULT hr = S_OK;
  1699. try {
  1700. if(NULL == pfDisplay){
  1701. throw(E_POINTER);
  1702. }/* end of if statement */
  1703. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1704. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  1705. if(!pDvdInfo2){
  1706. throw(E_UNEXPECTED);
  1707. }/* end of if statement */
  1708. ULONG ulSubpictureStream = 0L, ulStreamsAvailable = 0L;
  1709. BOOL fDisabled = TRUE;
  1710. RETRY_IF_IN_FPDOM(pDvdInfo2->GetCurrentSubpicture(&ulStreamsAvailable, &ulSubpictureStream, &fDisabled))
  1711. if(SUCCEEDED(hr)){
  1712. *pfDisplay = fDisabled == FALSE ? VARIANT_TRUE : VARIANT_FALSE; // compensate for -1 true in OLE
  1713. }/* end of if statement */
  1714. }/* end of try statement */
  1715. catch(HRESULT hrTmp){
  1716. hr = hrTmp;
  1717. }/* end of catch statement */
  1718. catch(...){
  1719. hr = E_UNEXPECTED;
  1720. }/* end of catch statement */
  1721. return HandleError(hr);
  1722. }/* end of function get_SubpictureOn */
  1723. /*************************************************************************/
  1724. /* Function: put_SubpictureOn */
  1725. /* Description: Turns the subpicture On or Off */
  1726. /*************************************************************************/
  1727. STDMETHODIMP CMSVidWebDVD::put_SubpictureOn(VARIANT_BOOL fDisplay){
  1728. HRESULT hr = S_OK;
  1729. try {
  1730. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1731. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  1732. if(!pDvdInfo2){
  1733. throw(E_UNEXPECTED);
  1734. }/* end of if statement */
  1735. if(!m_pDVDControl2){
  1736. throw(E_UNEXPECTED);
  1737. }/* end of if statement */
  1738. ULONG ulSubpictureStream = 0L, ulStreamsAvailable = 0L;
  1739. BOOL bIsDisabled = TRUE;
  1740. RETRY_IF_IN_FPDOM(pDvdInfo2->GetCurrentSubpicture(&ulStreamsAvailable, &ulSubpictureStream, &bIsDisabled ));
  1741. if(FAILED(hr)){
  1742. throw(hr);
  1743. }/* end of if statement */
  1744. BOOL bDisplay = fDisplay == VARIANT_FALSE ? FALSE : TRUE; // compensate for -1 true in OLE
  1745. hr = m_pDVDControl2->SetSubpictureState(bDisplay,0,0);
  1746. }/* end of try statement */
  1747. catch(HRESULT hrTmp){
  1748. hr = hrTmp;
  1749. }/* end of catch statement */
  1750. catch(...){
  1751. hr = E_UNEXPECTED;
  1752. }/* end of catch statement */
  1753. return HandleError(hr);
  1754. }/* end of function put_SubpictureOn */
  1755. /*************************************************************************/
  1756. /* Function: get_SubpictureStreamsAvailable */
  1757. /* Description: gets the number of streams available. */
  1758. /*************************************************************************/
  1759. STDMETHODIMP CMSVidWebDVD::get_SubpictureStreamsAvailable(long *plStreamsAvailable){
  1760. HRESULT hr = S_OK;
  1761. try {
  1762. if (NULL == plStreamsAvailable){
  1763. throw(E_POINTER);
  1764. }/* end of if statement */
  1765. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1766. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  1767. if(!pDvdInfo2){
  1768. throw(E_UNEXPECTED);
  1769. }/* end of if statement */
  1770. ULONG ulSubpictureStream = 0L;
  1771. *plStreamsAvailable = 0L;
  1772. BOOL bIsDisabled = TRUE;
  1773. RETRY_IF_IN_FPDOM(pDvdInfo2->GetCurrentSubpicture((ULONG*)plStreamsAvailable, &ulSubpictureStream, &bIsDisabled));
  1774. }/* end of try statement */
  1775. catch(HRESULT hrTmp){
  1776. hr = hrTmp;
  1777. }/* end of catch statement */
  1778. catch(...){
  1779. hr = E_UNEXPECTED;
  1780. }/* end of catch statement */
  1781. return HandleError(hr);
  1782. }/* end of function get_SubpictureStreamsAvailable */
  1783. /*************************************************************************/
  1784. /* Function: GetSubpictureLanguage */
  1785. /* Description: Gets subpicture language. */
  1786. /*************************************************************************/
  1787. STDMETHODIMP CMSVidWebDVD::get_SubpictureLanguage(LONG lStream, BSTR* strSubpictLang){
  1788. HRESULT hr = S_OK;
  1789. LPTSTR pszString = NULL;
  1790. try {
  1791. if(NULL == strSubpictLang){
  1792. throw(E_POINTER);
  1793. }/* end of if statement */
  1794. if(0 > lStream){
  1795. throw(E_INVALIDARG);
  1796. }/* end of if statement */
  1797. if((lStream > cgDVD_MAX_SUBPICTURE
  1798. && lStream != cgDVD_ALT_SUBPICTURE)){
  1799. throw(E_INVALIDARG);
  1800. }/* end of if statement */
  1801. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1802. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  1803. if(!pDvdInfo2){
  1804. throw(E_UNEXPECTED);
  1805. }/* end of if statement */
  1806. LCID lcid = _UI32_MAX;
  1807. hr = pDvdInfo2->GetSubpictureLanguage(lStream, &lcid);
  1808. if (SUCCEEDED( hr ) && lcid < _UI32_MAX){
  1809. pszString = m_LangID.GetLanguageFromLCID(lcid);
  1810. if (pszString == NULL) {
  1811. pszString = new TCHAR[MAX_PATH];
  1812. TCHAR strBuffer[MAX_PATH];
  1813. if(!::LoadString(_Module.m_hInstResource, IDS_DVD_SUBPICTURETRACK, strBuffer, MAX_PATH)){
  1814. delete[] pszString;
  1815. throw(E_UNEXPECTED);
  1816. }/* end of if statement */
  1817. (void)StringCchPrintf(pszString, MAX_PATH, strBuffer, lStream);
  1818. }/* end of if statement */
  1819. #if 0
  1820. DVD_SubpictureAttributes attr;
  1821. if(SUCCEEDED(pDvdInfo2->GetSubpictureAttributes(lStream, &attr))){
  1822. switch(attr.LanguageExtension){
  1823. case DVD_SP_EXT_NotSpecified:
  1824. case DVD_SP_EXT_Caption_Normal: break;
  1825. case DVD_SP_EXT_Caption_Big: AppendString(pszString, IDS_DVD_CAPTION_BIG, MAX_PATH ); break;
  1826. case DVD_SP_EXT_Caption_Children: AppendString(pszString, IDS_DVD_CAPTION_CHILDREN, MAX_PATH ); break;
  1827. case DVD_SP_EXT_CC_Normal: AppendString(pszString, IDS_DVD_CLOSED_CAPTION, MAX_PATH ); break;
  1828. case DVD_SP_EXT_CC_Big: AppendString(pszString, IDS_DVD_CLOSED_CAPTION_BIG, MAX_PATH ); break;
  1829. case DVD_SP_EXT_CC_Children: AppendString(pszString, IDS_DVD_CLOSED_CAPTION_CHILDREN, MAX_PATH ); break;
  1830. case DVD_SP_EXT_Forced: AppendString(pszString, IDS_DVD_CLOSED_CAPTION_FORCED, MAX_PATH ); break;
  1831. case DVD_SP_EXT_DirectorComments_Normal: AppendString(pszString, IDS_DVD_DIRS_COMMNETS, MAX_PATH ); break;
  1832. case DVD_SP_EXT_DirectorComments_Big: AppendString(pszString, IDS_DVD_DIRS_COMMNETS_BIG, MAX_PATH ); break;
  1833. case DVD_SP_EXT_DirectorComments_Children: AppendString(pszString, IDS_DVD_DIRS_COMMNETS_CHILDREN, MAX_PATH ); break;
  1834. }/* end of switch statement */
  1835. }/* end of if statement */
  1836. #endif
  1837. USES_CONVERSION;
  1838. *strSubpictLang = ::SysAllocString( T2W(pszString) );
  1839. delete[] pszString;
  1840. pszString = NULL;
  1841. }
  1842. else {
  1843. *strSubpictLang = ::SysAllocString( L"");
  1844. // hr used to be not failed and return nothing
  1845. if(SUCCEEDED(hr)) // remove this after gets fixed in DVDNav
  1846. hr = E_FAIL;
  1847. }/* end of if statement */
  1848. }/* end of try statement */
  1849. catch(HRESULT hrTmp){
  1850. if (pszString) {
  1851. delete[] pszString;
  1852. pszString = NULL;
  1853. }
  1854. hr = hrTmp;
  1855. }/* end of catch statement */
  1856. catch(...){
  1857. if (pszString) {
  1858. delete[] pszString;
  1859. pszString = NULL;
  1860. }
  1861. hr = E_UNEXPECTED;
  1862. }/* end of catch statement */
  1863. return HandleError(hr);
  1864. }/* end of function GetSubpictureLanguage */
  1865. /*************************************************************************/
  1866. /* Function: get_AudioStreamsAvailable */
  1867. /* Description: Gets number of available Audio Streams */
  1868. /*************************************************************************/
  1869. STDMETHODIMP CMSVidWebDVD::get_AudioStreamsAvailable(long *plNumAudioStreams){
  1870. HRESULT hr = S_OK;
  1871. try {
  1872. if(NULL == plNumAudioStreams){
  1873. throw(E_POINTER);
  1874. }/* end of if statement */
  1875. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1876. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  1877. if(!pDvdInfo2){
  1878. throw(E_UNEXPECTED);
  1879. }/* end of if statement */
  1880. ULONG ulCurrentStream;
  1881. RETRY_IF_IN_FPDOM(pDvdInfo2->GetCurrentAudio((ULONG*)plNumAudioStreams, &ulCurrentStream));
  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 get_AudioStreamsAvailable */
  1891. /*************************************************************************/
  1892. /* Function: get_CurrentAudioStream */
  1893. /* Description: Gets current audio stream. */
  1894. /*************************************************************************/
  1895. STDMETHODIMP CMSVidWebDVD::get_CurrentAudioStream(long *plCurrentStream){
  1896. HRESULT hr = S_OK;
  1897. try {
  1898. if(NULL == plCurrentStream){
  1899. throw(E_POINTER);
  1900. }/* end of if statement */
  1901. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1902. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  1903. if(!pDvdInfo2){
  1904. throw(E_UNEXPECTED);
  1905. }/* end of if statement */
  1906. ULONG ulNumAudioStreams;
  1907. RETRY_IF_IN_FPDOM(pDvdInfo2->GetCurrentAudio(&ulNumAudioStreams, (ULONG*)plCurrentStream ));
  1908. }/* end of try statement */
  1909. catch(HRESULT hrTmp){
  1910. hr = hrTmp;
  1911. }/* end of catch statement */
  1912. catch(...){
  1913. hr = E_UNEXPECTED;
  1914. }/* end of catch statement */
  1915. return HandleError(hr);
  1916. }/* end of function get_CurrentAudioStream */
  1917. /*************************************************************************/
  1918. /* Function: put_CurrentAudioStream */
  1919. /* Description: Changes the current audio stream. */
  1920. /*************************************************************************/
  1921. STDMETHODIMP CMSVidWebDVD::put_CurrentAudioStream(long lAudioStream){
  1922. HRESULT hr = S_OK;
  1923. try {
  1924. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1925. if(!m_pDVDControl2){
  1926. throw(E_UNEXPECTED);
  1927. }/* end of if statement */
  1928. RETRY_IF_IN_FPDOM(m_pDVDControl2->SelectAudioStream(lAudioStream,0,0));
  1929. }/* end of try statement */
  1930. catch(HRESULT hrTmp){
  1931. hr = hrTmp;
  1932. }/* end of catch statement */
  1933. catch(...){
  1934. hr = E_UNEXPECTED;
  1935. }/* end of catch statement */
  1936. return HandleError(hr);
  1937. }/* end of function put_CurrentAudioStream */
  1938. /*************************************************************************/
  1939. /* Function: get_CurrentAngle */
  1940. /* Description: Gets current angle. */
  1941. /*************************************************************************/
  1942. STDMETHODIMP CMSVidWebDVD::get_CurrentAngle(long *plAngle){
  1943. HRESULT hr = S_OK;
  1944. try {
  1945. if(NULL == plAngle){
  1946. throw(E_POINTER);
  1947. }/* end of if statement */
  1948. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1949. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  1950. if(!pDvdInfo2){
  1951. throw(E_UNEXPECTED);
  1952. }/* end of if statement */
  1953. ULONG ulAnglesAvailable = 0;
  1954. RETRY_IF_IN_FPDOM(pDvdInfo2->GetCurrentAngle(&ulAnglesAvailable, (ULONG*)plAngle));
  1955. }/* end of try statement */
  1956. catch(HRESULT hrTmp){
  1957. hr = hrTmp;
  1958. }/* end of catch statement */
  1959. catch(...){
  1960. hr = E_UNEXPECTED;
  1961. }/* end of catch statement */
  1962. return HandleError(hr);
  1963. }/* end of function get_CurrentAngle */
  1964. /*************************************************************************/
  1965. /* Function: put_CurrentAngle */
  1966. /* Description: Sets the current angle (different DVD angle track.) */
  1967. /*************************************************************************/
  1968. STDMETHODIMP CMSVidWebDVD::put_CurrentAngle(long lAngle){
  1969. HRESULT hr = S_OK;
  1970. try {
  1971. if( lAngle < cgDVD_MIN_ANGLE || lAngle > cgDVD_MAX_ANGLE ){
  1972. throw(E_INVALIDARG);
  1973. }/* end of if statement */
  1974. INITIALIZE_GRAPH_IF_NEEDS_TO_BE_AND_PLAY
  1975. if(!m_pDVDControl2){
  1976. throw(E_UNEXPECTED);
  1977. }/* end of if statement */
  1978. RETRY_IF_IN_FPDOM(m_pDVDControl2->SelectAngle(lAngle,0,0));
  1979. }/* end of try statement */
  1980. catch(HRESULT hrTmp){
  1981. hr = hrTmp;
  1982. }/* end of catch statement */
  1983. catch(...){
  1984. hr = E_UNEXPECTED;
  1985. }/* end of catch statement */
  1986. return HandleError(hr);
  1987. }/* end of function put_CurrentAngle */
  1988. /*************************************************************************/
  1989. /* Function: get_AnglesAvailable */
  1990. /* Description: Gets the number of angles available. */
  1991. /*************************************************************************/
  1992. STDMETHODIMP CMSVidWebDVD::get_AnglesAvailable(long *plAnglesAvailable){
  1993. HRESULT hr = S_OK;
  1994. try {
  1995. if(NULL == plAnglesAvailable){
  1996. throw(E_POINTER);
  1997. }/* end of if statement */
  1998. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  1999. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  2000. if(!pDvdInfo2){
  2001. throw(E_UNEXPECTED);
  2002. }/* end of if statement */
  2003. ULONG ulCurrentAngle = 0;
  2004. RETRY_IF_IN_FPDOM(pDvdInfo2->GetCurrentAngle((ULONG*)plAnglesAvailable, &ulCurrentAngle));
  2005. }/* end of try statement */
  2006. catch(HRESULT hrTmp){
  2007. hr = hrTmp;
  2008. }/* end of catch statement */
  2009. catch(...){
  2010. hr = E_UNEXPECTED;
  2011. }/* end of catch statement */
  2012. return HandleError(hr);
  2013. }/* end of function get_AnglesAvailable */
  2014. /*************************************************************************/
  2015. /* Function: get_DVDUniqueID */
  2016. /* Description: Gets the UNIQUE ID that identifies the string. */
  2017. /*************************************************************************/
  2018. STDMETHODIMP CMSVidWebDVD::get_DVDUniqueID(BSTR *pStrID){
  2019. HRESULT hr = E_FAIL;
  2020. try {
  2021. // TODO: Be able to get m_pDvdInfo2 without initializing the graph
  2022. if (NULL == pStrID){
  2023. throw(E_POINTER);
  2024. }/* end of if statement */
  2025. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2026. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  2027. if(!pDvdInfo2){
  2028. throw(E_UNEXPECTED);
  2029. }/* end of if statement */
  2030. ULONGLONG ullUniqueID;
  2031. hr = pDvdInfo2->GetDiscID(NULL, &ullUniqueID);
  2032. if(FAILED(hr)){
  2033. throw(hr);
  2034. }/* end of if statement */
  2035. //TODO: Get rid of the STDLIB call!!
  2036. // taken out of WMP
  2037. // Script can't handle a 64 bit value so convert it to a string.
  2038. // Doc's say _ui64tow returns 33 bytes (chars?) max.
  2039. // we'll use double that just in case...
  2040. //
  2041. WCHAR wszBuffer[66];
  2042. _ui64tow( ullUniqueID, wszBuffer, 10);
  2043. *pStrID = SysAllocString(wszBuffer);
  2044. }/* end of try statement */
  2045. catch(HRESULT hrTmp){
  2046. hr = hrTmp;
  2047. }
  2048. catch(...){
  2049. hr = E_UNEXPECTED;
  2050. }/* end of catch statement */
  2051. return HandleError(hr);
  2052. }/* end of function get_DVDUniqueID */
  2053. /*************************************************************************/
  2054. /* Function: AcceptParentalLevelChange */
  2055. /* Description: Accepts the temprary parental level change that is */
  2056. /* done on the fly. */
  2057. /*************************************************************************/
  2058. STDMETHODIMP CMSVidWebDVD::AcceptParentalLevelChange(VARIANT_BOOL fAccept, BSTR strUserName, BSTR strPassword){
  2059. // Comfirm password first
  2060. if (m_pDvdAdmin == NULL) {
  2061. throw(E_UNEXPECTED);
  2062. } /* end of if statement */
  2063. VARIANT_BOOL fRight;
  2064. HRESULT hr = m_pDvdAdmin->ConfirmPassword(NULL, strPassword, &fRight);
  2065. // if password is wrong and want to accept, no
  2066. if (fAccept != VARIANT_FALSE && fRight == VARIANT_FALSE)
  2067. return E_ACCESSDENIED;
  2068. try {
  2069. // should not make sense to do initialization here, since this should
  2070. // be a response to a callback
  2071. //INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2072. if(!m_pDVDControl2){
  2073. throw(E_UNEXPECTED);
  2074. }/* end of if statement */
  2075. hr = m_pDVDControl2->AcceptParentalLevelChange(VARIANT_FALSE == fAccept? FALSE : TRUE);
  2076. }/* end of try statement */
  2077. catch(HRESULT hrTmp){
  2078. hr = hrTmp;
  2079. }/* end of catch statement */
  2080. catch(...){
  2081. hr = E_UNEXPECTED;
  2082. }/* end of catch statement */
  2083. return HandleError(hr);
  2084. }/* end of function AcceptParentalLevelChange */
  2085. /*************************************************************************/
  2086. /* Function: put_NotifyParentalLevelChange */
  2087. /* Description: Sets the flag if to notify when parental level change */
  2088. /* notification is required on the fly. */
  2089. /*************************************************************************/
  2090. STDMETHODIMP CMSVidWebDVD::NotifyParentalLevelChange(VARIANT_BOOL fNotify){
  2091. HRESULT hr = S_OK;
  2092. try {
  2093. //TODO: Add IE parantal level control
  2094. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2095. if(!m_pDVDControl2){
  2096. throw(E_UNEXPECTED);
  2097. }/* end of if statement */
  2098. hr = m_pDVDControl2->SetOption(DVD_NotifyParentalLevelChange,
  2099. VARIANT_FALSE == fNotify? FALSE : TRUE);
  2100. }/* end of try statement */
  2101. catch(HRESULT hrTmp){
  2102. hr = hrTmp;
  2103. }/* end of catch statement */
  2104. catch(...){
  2105. hr = E_UNEXPECTED;
  2106. }/* end of catch statement */
  2107. return HandleError(hr);
  2108. }/* end of function NotifyParentalLevelChange */
  2109. /*************************************************************************/
  2110. /* Function: SelectParentalCountry */
  2111. /* Description: Selects Parental Country. */
  2112. /*************************************************************************/
  2113. STDMETHODIMP CMSVidWebDVD::SelectParentalCountry(long lCountry, BSTR strUserName, BSTR strPassword){
  2114. HRESULT hr = S_OK;
  2115. try {
  2116. if(lCountry < 0 && lCountry > 0xffff){
  2117. throw(E_INVALIDARG);
  2118. }/* end of if statement */
  2119. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2120. // Confirm password first
  2121. if (m_pDvdAdmin == NULL) {
  2122. throw(E_UNEXPECTED);
  2123. }/* end of if statement */
  2124. VARIANT_BOOL temp;
  2125. hr = m_pDvdAdmin->ConfirmPassword(NULL, strPassword, &temp);
  2126. if (temp == VARIANT_FALSE)
  2127. throw (E_ACCESSDENIED);
  2128. hr = SelectParentalCountry(lCountry);
  2129. }
  2130. catch(HRESULT hrTmp){
  2131. hr = hrTmp;
  2132. }
  2133. catch(...){
  2134. hr = E_UNEXPECTED;
  2135. }
  2136. return HandleError(hr);
  2137. }
  2138. /*************************************************************************/
  2139. /* Function: SelectParentalCountry */
  2140. /* Description: Selects Parental Country. */
  2141. /*************************************************************************/
  2142. HRESULT CMSVidWebDVD::SelectParentalCountry(long lCountry){
  2143. HRESULT hr = S_OK;
  2144. try {
  2145. if(!m_pDVDControl2){
  2146. throw(E_UNEXPECTED);
  2147. }/* end of if statement */
  2148. BYTE bCountryCode[2];
  2149. bCountryCode[0] = BYTE(lCountry>>8);
  2150. bCountryCode[1] = BYTE(lCountry);
  2151. hr = m_pDVDControl2->SelectParentalCountry(bCountryCode);
  2152. }/* end of try statement */
  2153. catch(HRESULT hrTmp){
  2154. hr = hrTmp;
  2155. }/* end of catch statement */
  2156. catch(...){
  2157. hr = E_UNEXPECTED;
  2158. }/* end of catch statement */
  2159. return (hr);
  2160. }/* end of function SelectParentalCountry */
  2161. /*************************************************************************/
  2162. /* Function: SelectParentalLevel */
  2163. /* Description: Selects the parental level. */
  2164. /*************************************************************************/
  2165. STDMETHODIMP CMSVidWebDVD::SelectParentalLevel(long lParentalLevel, BSTR strUserName, BSTR strPassword){
  2166. HRESULT hr = S_OK;
  2167. try {
  2168. if (lParentalLevel != PARENTAL_LEVEL_DISABLED &&
  2169. (lParentalLevel < 1 || lParentalLevel > 8)) {
  2170. throw (E_INVALIDARG);
  2171. } /* end of if statement */
  2172. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2173. // Confirm password first
  2174. if (m_pDvdAdmin == NULL) {
  2175. throw(E_UNEXPECTED);
  2176. } /* end of if statement */
  2177. VARIANT_BOOL temp;
  2178. hr = m_pDvdAdmin->ConfirmPassword(NULL, strPassword, &temp);
  2179. if (temp == VARIANT_FALSE)
  2180. throw (E_ACCESSDENIED);
  2181. hr = SelectParentalLevel(lParentalLevel);
  2182. }
  2183. catch(HRESULT hrTmp){
  2184. hr = hrTmp;
  2185. }
  2186. catch(...){
  2187. hr = E_UNEXPECTED;
  2188. }
  2189. return HandleError(hr);
  2190. }
  2191. /*************************************************************************/
  2192. /* Function: SelectParentalLevel */
  2193. /* Description: Selects the parental level. */
  2194. /*************************************************************************/
  2195. HRESULT CMSVidWebDVD::SelectParentalLevel(long lParentalLevel){
  2196. HRESULT hr = S_OK;
  2197. try {
  2198. //INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2199. if(!m_pDVDControl2){
  2200. throw(E_UNEXPECTED);
  2201. }/* end of if statement */
  2202. hr = m_pDVDControl2->SelectParentalLevel(lParentalLevel);
  2203. }/* end of try statement */
  2204. catch(HRESULT hrTmp){
  2205. hr = hrTmp;
  2206. }/* end of catch statement */
  2207. catch(...){
  2208. hr = E_UNEXPECTED;
  2209. }/* end of catch statement */
  2210. return (hr);
  2211. }/* end of function SelectParentalLevel */
  2212. /*************************************************************************/
  2213. /* Function: GetTitleParentalLevels */
  2214. /* Description: Gets the parental level associated with a specific title.*/
  2215. /*************************************************************************/
  2216. STDMETHODIMP CMSVidWebDVD::get_TitleParentalLevels(long lTitle, long *plParentalLevels){
  2217. HRESULT hr = S_OK;
  2218. try {
  2219. if(NULL == plParentalLevels){
  2220. throw(E_POINTER);
  2221. }/* end of if statement */
  2222. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2223. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  2224. if(!pDvdInfo2){
  2225. throw(E_UNEXPECTED);
  2226. }/* end of if statement */
  2227. ULONG ulLevel;
  2228. hr = pDvdInfo2->GetTitleParentalLevels(lTitle, &ulLevel);
  2229. if(SUCCEEDED(hr)){
  2230. *plParentalLevels = ulLevel;
  2231. }
  2232. else {
  2233. *plParentalLevels = 0;
  2234. }/* end of if statement */
  2235. }/* end of try statement */
  2236. catch(HRESULT hrTmp){
  2237. hr = hrTmp;
  2238. }/* end of catch statement */
  2239. catch(...){
  2240. hr = E_UNEXPECTED;
  2241. }/* end of catch statement */
  2242. return HandleError(hr);
  2243. }/* end of function GetTitleParentalLevels */
  2244. /*************************************************************************/
  2245. /* Function: GetPlayerParentalCountry */
  2246. /* Description: Gets the player parental country. */
  2247. /*************************************************************************/
  2248. STDMETHODIMP CMSVidWebDVD::get_PlayerParentalCountry(long *plCountryCode){
  2249. HRESULT hr = S_OK;
  2250. try {
  2251. if(NULL == plCountryCode){
  2252. throw(E_POINTER);
  2253. }/* end of if statement */
  2254. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2255. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  2256. if(!pDvdInfo2){
  2257. throw(E_UNEXPECTED);
  2258. }/* end of if statement */
  2259. BYTE bCountryCode[2];
  2260. ULONG ulLevel;
  2261. hr = pDvdInfo2->GetPlayerParentalLevel(&ulLevel, bCountryCode);
  2262. if(SUCCEEDED(hr)){
  2263. *plCountryCode = bCountryCode[0]<<8 | bCountryCode[1];
  2264. }
  2265. else {
  2266. *plCountryCode = 0;
  2267. }/* end of if statement */
  2268. }/* end of try statement */
  2269. catch(HRESULT hrTmp){
  2270. hr = hrTmp;
  2271. }/* end of catch statement */
  2272. catch(...){
  2273. hr = E_UNEXPECTED;
  2274. }/* end of catch statement */
  2275. return HandleError(hr);
  2276. }/* end of function GetPlayerParentalCountry */
  2277. /*************************************************************************/
  2278. /*************************************************************************/
  2279. /* Function: GetPlayerParentalLevel */
  2280. /* Description: Gets the player parental level. *
  2281. /*************************************************************************/
  2282. STDMETHODIMP CMSVidWebDVD::get_PlayerParentalLevel(long *plParentalLevel){
  2283. HRESULT hr = S_OK;
  2284. try {
  2285. if(NULL == plParentalLevel){
  2286. throw(E_POINTER);
  2287. }/* end of if statement */
  2288. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2289. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  2290. if(!pDvdInfo2){
  2291. throw(E_UNEXPECTED);
  2292. }/* end of if statement */
  2293. ULONG ulLevel;
  2294. BYTE bCountryCode[2];
  2295. hr = pDvdInfo2->GetPlayerParentalLevel(&ulLevel, bCountryCode);
  2296. if(SUCCEEDED(hr)){
  2297. *plParentalLevel = ulLevel;
  2298. }
  2299. else {
  2300. *plParentalLevel = 0;
  2301. }/* end of if statement */
  2302. }/* end of try statement */
  2303. catch(HRESULT hrTmp){
  2304. hr = hrTmp;
  2305. }/* end of catch statement */
  2306. catch(...){
  2307. hr = E_UNEXPECTED;
  2308. }/* end of catch statement */
  2309. return HandleError(hr);
  2310. }/* end of function GetPlayerParentalLevel */
  2311. STDMETHODIMP CMSVidWebDVD::Eject(){
  2312. USES_CONVERSION;
  2313. BSTR bDrive;
  2314. HRESULT hr = get_DVDDirectory(&bDrive);
  2315. if(FAILED(hr)){
  2316. return hr;
  2317. }
  2318. MCI_OPEN_PARMS mciDrive;
  2319. WCHAR* pDrive = bDrive;
  2320. TCHAR szElementName[4];
  2321. TCHAR szAliasName[32];
  2322. DWORD dwFlags;
  2323. DWORD dwAliasCount = GetCurrentTime();
  2324. DWORD theMciErr;
  2325. ZeroMemory( &mciDrive, sizeof(mciDrive) );
  2326. mciDrive.lpstrDeviceType = (LPTSTR)MCI_DEVTYPE_CD_AUDIO;
  2327. (void)StringCchPrintf( szElementName, sizeof(szElementName) / sizeof(szElementName[0]), TEXT("%c:"), pDrive[0] );
  2328. (void)StringCchPrintf( szAliasName, sizeof(szAliasName) / sizeof(szAliasName[0]), TEXT("SJE%lu:"), dwAliasCount );
  2329. mciDrive.lpstrAlias = szAliasName;
  2330. mciDrive.lpstrDeviceType = (LPTSTR)MCI_DEVTYPE_CD_AUDIO;
  2331. mciDrive.lpstrElementName = szElementName;
  2332. dwFlags = MCI_OPEN_ELEMENT | MCI_OPEN_ALIAS |
  2333. MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID | MCI_WAIT;
  2334. // send mci command
  2335. theMciErr = mciSendCommand(0, MCI_OPEN, dwFlags, reinterpret_cast<DWORD_PTR>(&mciDrive));
  2336. if ( theMciErr != MMSYSERR_NOERROR )
  2337. return E_UNEXPECTED;
  2338. DWORD DevHandle = mciDrive.wDeviceID;
  2339. if(m_bEjected==false){
  2340. m_bEjected = true;
  2341. ZeroMemory( &mciDrive, sizeof(mciDrive) );
  2342. theMciErr = mciSendCommand( DevHandle, MCI_SET, MCI_SET_DOOR_OPEN,
  2343. reinterpret_cast<DWORD_PTR>(&mciDrive) );
  2344. hr = theMciErr ? E_FAIL : S_OK; // zero for success
  2345. if(FAILED(hr)){
  2346. return hr;
  2347. }
  2348. }
  2349. else{
  2350. m_bEjected = false;
  2351. ZeroMemory( &mciDrive, sizeof(mciDrive) );
  2352. theMciErr = mciSendCommand( DevHandle, MCI_SET, MCI_SET_DOOR_CLOSED,
  2353. reinterpret_cast<DWORD_PTR>(&mciDrive) );
  2354. hr = theMciErr ? E_FAIL : S_OK; // zero for success
  2355. if(FAILED(hr)){
  2356. return hr;
  2357. }
  2358. }
  2359. ZeroMemory( &mciDrive, sizeof(mciDrive) );
  2360. theMciErr = mciSendCommand( DevHandle, MCI_CLOSE, 0L, reinterpret_cast<DWORD_PTR>(&mciDrive) );
  2361. hr = theMciErr ? E_FAIL : S_OK; // zero for success
  2362. return hr;
  2363. }
  2364. /*************************************************************************/
  2365. /* Function: UOPValid */
  2366. /* Description: Tells if UOP is valid or not, valid means the feature is */
  2367. /* turned on. */
  2368. /*************************************************************************/
  2369. STDMETHODIMP CMSVidWebDVD::UOPValid(long lUOP, VARIANT_BOOL *pfValid){
  2370. HRESULT hr = S_OK;
  2371. try {
  2372. if (NULL == pfValid){
  2373. throw(E_POINTER);
  2374. }/* end of if statement */
  2375. if ((lUOP > 24) || (lUOP < 0)){
  2376. throw(E_INVALIDARG);
  2377. }/* end of if statement */
  2378. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2379. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  2380. if(!pDvdInfo2){
  2381. throw(E_UNEXPECTED);
  2382. }/* end of if statement */
  2383. ULONG ulUOPS = 0;
  2384. hr = pDvdInfo2->GetCurrentUOPS(&ulUOPS);
  2385. *pfValid = ulUOPS & (1 << lUOP) ? VARIANT_FALSE : VARIANT_TRUE;
  2386. }/* end of try statement */
  2387. catch(HRESULT hrTmp){
  2388. hr = hrTmp;
  2389. }
  2390. catch(...){
  2391. hr = E_UNEXPECTED;
  2392. }/* end of catch statement */
  2393. return HandleError(hr);
  2394. }/* end of function UOPValid */
  2395. /*************************************************************************/
  2396. /* Function: GetSPRM */
  2397. /* Description: Gets SPRM at the specific index. */
  2398. /*************************************************************************/
  2399. STDMETHODIMP CMSVidWebDVD::get_SPRM(long lIndex, short *psSPRM){
  2400. HRESULT hr = E_FAIL;
  2401. try {
  2402. if (NULL == psSPRM){
  2403. throw(E_POINTER);
  2404. }/* end of if statement */
  2405. SPRMARRAY sprm;
  2406. int iArraySize = sizeof(SPRMARRAY)/sizeof(sprm[0]);
  2407. if(0 > lIndex || iArraySize <= lIndex){
  2408. return(E_INVALIDARG);
  2409. }/* end of if statement */
  2410. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2411. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  2412. if(!pDvdInfo2){
  2413. throw(E_UNEXPECTED);
  2414. }/* end of if statement */
  2415. hr = pDvdInfo2->GetAllSPRMs(&sprm);
  2416. if(FAILED(hr)){
  2417. throw(hr);
  2418. }/* end of if statement */
  2419. *psSPRM = sprm[lIndex];
  2420. }/* end of try statement */
  2421. catch(HRESULT hrTmp){
  2422. hr = hrTmp;
  2423. }
  2424. catch(...){
  2425. hr = E_UNEXPECTED;
  2426. }/* end of catch statement */
  2427. return HandleError(hr);
  2428. }/* end of function GetSPRM */
  2429. /*************************************************************************/
  2430. /* Function: SetGPRM */
  2431. /* Description: Sets a GPRM at index. */
  2432. /*************************************************************************/
  2433. STDMETHODIMP CMSVidWebDVD::put_GPRM(long lIndex, short sValue){
  2434. HRESULT hr = S_OK;
  2435. try {
  2436. if(lIndex < 0){
  2437. throw(E_INVALIDARG);
  2438. }/* end of if statement */
  2439. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2440. if(!m_pDVDControl2){
  2441. throw(E_UNEXPECTED);
  2442. }/* end of if statement */
  2443. hr = m_pDVDControl2->SetGPRM(lIndex, sValue, cdwDVDCtrlFlags, 0);
  2444. }/* end of try statement */
  2445. catch(HRESULT hrTmp){
  2446. hr = hrTmp;
  2447. }/* end of catch statement */
  2448. catch(...){
  2449. hr = E_UNEXPECTED;
  2450. }/* end of catch statement */
  2451. return HandleError(hr);
  2452. }/* end of function SetGPRM */
  2453. /*************************************************************************/
  2454. /* Function: GetGPRM */
  2455. /* Description: Gets the GPRM at specified index */
  2456. /*************************************************************************/
  2457. STDMETHODIMP CMSVidWebDVD::get_GPRM(long lIndex, short *psGPRM){
  2458. HRESULT hr = E_FAIL;
  2459. try {
  2460. if (NULL == psGPRM){
  2461. throw(E_POINTER);
  2462. }/* end of if statement */
  2463. GPRMARRAY gprm;
  2464. int iArraySize = sizeof(GPRMARRAY)/sizeof(gprm[0]);
  2465. if(0 > lIndex || iArraySize <= lIndex){
  2466. return(E_INVALIDARG);
  2467. }/* end of if statement */
  2468. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2469. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  2470. if(!pDvdInfo2){
  2471. throw(E_UNEXPECTED);
  2472. }/* end of if statement */
  2473. hr = pDvdInfo2->GetAllGPRMs(&gprm);
  2474. if(FAILED(hr)){
  2475. throw(hr);
  2476. }/* end of if statement */
  2477. *psGPRM = gprm[lIndex];
  2478. }/* end of try statement */
  2479. catch(HRESULT hrTmp){
  2480. hr = hrTmp;
  2481. }
  2482. catch(...){
  2483. hr = E_UNEXPECTED;
  2484. }/* end of catch statement */
  2485. return HandleError(hr);
  2486. }/* end of function GetGPRM */
  2487. /*************************************************************************/
  2488. /* Function: GetDVDTextNumberOfLanguages */
  2489. /* Description: Retrieves the number of languages available. */
  2490. /*************************************************************************/
  2491. STDMETHODIMP CMSVidWebDVD::get_DVDTextNumberOfLanguages(long *plNumOfLangs){
  2492. HRESULT hr = S_OK;
  2493. try {
  2494. if (NULL == plNumOfLangs){
  2495. throw(E_POINTER);
  2496. }/* end of if statement */
  2497. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2498. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  2499. if(!pDvdInfo2){
  2500. throw(E_UNEXPECTED);
  2501. }/* end of if statement */
  2502. ULONG ulNumOfLangs;
  2503. RETRY_IF_IN_FPDOM(pDvdInfo2->GetDVDTextNumberOfLanguages(&ulNumOfLangs));
  2504. if(FAILED(hr)){
  2505. throw(hr);
  2506. }/* end of if statement */
  2507. *plNumOfLangs = ulNumOfLangs;
  2508. }/* end of try statement */
  2509. catch(HRESULT hrTmp){
  2510. hr = hrTmp;
  2511. }
  2512. catch(...){
  2513. hr = E_UNEXPECTED;
  2514. }/* end of catch statement */
  2515. return HandleError(hr);
  2516. }/* end of function GetDVDTextNumberOfLanguages */
  2517. /*************************************************************************/
  2518. /* Function: GetDVDTextNumberOfStrings */
  2519. /* Description: Gets the number of strings in the partical language. */
  2520. /*************************************************************************/
  2521. STDMETHODIMP CMSVidWebDVD::get_DVDTextNumberOfStrings(long lLangIndex, long *plNumOfStrings){
  2522. HRESULT hr = S_OK;
  2523. try {
  2524. if (NULL == plNumOfStrings){
  2525. throw(E_POINTER);
  2526. }/* end of if statement */
  2527. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2528. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  2529. if(!pDvdInfo2){
  2530. throw(E_UNEXPECTED);
  2531. }/* end of if statement */
  2532. LCID wLangCode;
  2533. ULONG uNumOfStings;
  2534. DVD_TextCharSet charSet;
  2535. RETRY_IF_IN_FPDOM(pDvdInfo2->GetDVDTextLanguageInfo(lLangIndex, &uNumOfStings, &wLangCode, &charSet));
  2536. if(FAILED(hr)){
  2537. throw(hr);
  2538. }/* end of if statement */
  2539. *plNumOfStrings = uNumOfStings;
  2540. }/* end of try statement */
  2541. catch(HRESULT hrTmp){
  2542. hr = hrTmp;
  2543. }
  2544. catch(...){
  2545. hr = E_UNEXPECTED;
  2546. }/* end of catch statement */
  2547. return HandleError(hr);
  2548. }/* end of function GetDVDTextNumberOfStrings */
  2549. /*************************************************************/
  2550. /* Name: GetDVDTextLanguageLCID
  2551. /* Description: Get the LCID of an index of the DVD texts
  2552. /*************************************************************/
  2553. STDMETHODIMP CMSVidWebDVD::get_DVDTextLanguageLCID(long lLangIndex, long *lcid)
  2554. {
  2555. HRESULT hr = S_OK;
  2556. try {
  2557. if (NULL == lcid){
  2558. throw(E_POINTER);
  2559. }/* end of if statement */
  2560. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2561. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  2562. if(!pDvdInfo2){
  2563. throw(E_UNEXPECTED);
  2564. }/* end of if statement */
  2565. LCID wLangCode;
  2566. ULONG uNumOfStings;
  2567. DVD_TextCharSet charSet;
  2568. RETRY_IF_IN_FPDOM(pDvdInfo2->GetDVDTextLanguageInfo(lLangIndex, &uNumOfStings, &wLangCode, &charSet));
  2569. if(FAILED(hr)){
  2570. throw(hr);
  2571. }/* end of if statement */
  2572. *lcid = wLangCode;
  2573. }/* end of try statement */
  2574. catch(HRESULT hrTmp){
  2575. hr = hrTmp;
  2576. }
  2577. catch(...){
  2578. hr = E_UNEXPECTED;
  2579. }/* end of catch statement */
  2580. return HandleError(hr);
  2581. }/* end of function GetDVDTextLanguageLCID */
  2582. /*************************************************************************/
  2583. /* Function: GetDVDtextString */
  2584. /* Description: Gets the DVD Text string at specific location. */
  2585. /*************************************************************************/
  2586. STDMETHODIMP CMSVidWebDVD::get_DVDTextString(long lLangIndex, long lStringIndex, BSTR *pstrText){
  2587. HRESULT hr = S_OK;
  2588. try {
  2589. if (NULL == pstrText){
  2590. throw(E_POINTER);
  2591. }/* end of if statement */
  2592. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2593. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  2594. if(!pDvdInfo2){
  2595. throw(E_UNEXPECTED);
  2596. }/* end of if statement */
  2597. ULONG ulSize;
  2598. DVD_TextStringType type;
  2599. RETRY_IF_IN_FPDOM(pDvdInfo2->GetDVDTextStringAsUnicode(lLangIndex, lStringIndex, NULL, 0, &ulSize, &type));
  2600. if(FAILED(hr)){
  2601. throw(hr);
  2602. }/* end of if statement */
  2603. if (ulSize == 0) {
  2604. *pstrText = ::SysAllocString(L"");
  2605. }
  2606. else {
  2607. // got the length so lets allocate a buffer of that size
  2608. WCHAR* wstrBuff = new WCHAR[ulSize];
  2609. ULONG ulActualSize;
  2610. hr = pDvdInfo2->GetDVDTextStringAsUnicode(lLangIndex, lStringIndex, wstrBuff, ulSize, &ulActualSize, &type);
  2611. ATLASSERT(ulActualSize == ulSize);
  2612. if(FAILED(hr)){
  2613. delete [] wstrBuff;
  2614. throw(hr);
  2615. }/* end of if statement */
  2616. *pstrText = ::SysAllocString(wstrBuff);
  2617. delete [] wstrBuff;
  2618. }/* end of if statement */
  2619. }/* end of try statement */
  2620. catch(HRESULT hrTmp){
  2621. hr = hrTmp;
  2622. }
  2623. catch(...){
  2624. hr = E_UNEXPECTED;
  2625. }/* end of catch statement */
  2626. return HandleError(hr);
  2627. }/* end of function GetDVDtextString */
  2628. /*************************************************************************/
  2629. /* Function: GetDVDTextStringType */
  2630. /* Description: Gets the type of the string at the specified location. */
  2631. /*************************************************************************/
  2632. STDMETHODIMP CMSVidWebDVD::get_DVDTextStringType(long lLangIndex, long lStringIndex, DVDTextStringType *pType){
  2633. HRESULT hr = S_OK;
  2634. try {
  2635. if (NULL == pType){
  2636. throw(E_POINTER);
  2637. }/* end of if statement */
  2638. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2639. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  2640. if(!pDvdInfo2){
  2641. throw(E_UNEXPECTED);
  2642. }/* end of if statement */
  2643. ULONG ulTheSize;
  2644. DVD_TextStringType type;
  2645. RETRY_IF_IN_FPDOM(pDvdInfo2->GetDVDTextStringAsUnicode(lLangIndex, lStringIndex, NULL, 0, &ulTheSize, &type));
  2646. if(SUCCEEDED(hr)){
  2647. *pType = (DVDTextStringType) type;
  2648. }/* end of if statement */
  2649. }/* end of try statement */
  2650. catch(HRESULT hrTmp){
  2651. hr = hrTmp;
  2652. }
  2653. catch(...){
  2654. hr = E_UNEXPECTED;
  2655. }/* end of catch statement */
  2656. return HandleError(hr);
  2657. }/* end of function GetDVDTextStringType */
  2658. /*************************************************************************/
  2659. /* Function: RegionChange */
  2660. /* Description:Changes the region code. */
  2661. /*************************************************************************/
  2662. STDMETHODIMP CMSVidWebDVD::RegionChange(){
  2663. USES_CONVERSION;
  2664. HRESULT hr = S_OK;
  2665. typedef BOOL (APIENTRY *DVDPPLAUNCHER) (HWND HWnd, CHAR DriveLetter);
  2666. try {
  2667. #if 0
  2668. HWND parentWnd;
  2669. GetParentHWND(&parentWnd);
  2670. if (NULL != parentWnd) {
  2671. // take the container out of the top-most mode
  2672. ::SetWindowPos(parentWnd, HWND_NOTOPMOST, 0, 0, 0, 0,
  2673. SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE);
  2674. }
  2675. #endif
  2676. BOOL regionChanged = FALSE;
  2677. OSVERSIONINFO ver;
  2678. ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  2679. ::GetVersionEx(&ver);
  2680. if (ver.dwPlatformId==VER_PLATFORM_WIN32_NT) {
  2681. HINSTANCE dllInstance;
  2682. DVDPPLAUNCHER dvdPPLauncher;
  2683. TCHAR szCmdLine[MAX_PATH], szDriveLetter[4];
  2684. LPSTR szDriveLetterA;
  2685. //
  2686. // tell the user why we are showing the dvd region property page
  2687. //
  2688. // DVDMessageBox(m_hWnd, IDS_REGION_CHANGE_PROMPT);
  2689. hr = GetDVDDriveLetter(szDriveLetter);
  2690. if(FAILED(hr)){
  2691. throw(hr);
  2692. }/* end of if statement */
  2693. szDriveLetterA = T2A(szDriveLetter);
  2694. GetSystemDirectory(szCmdLine, MAX_PATH);
  2695. (void)StringCchCat(szCmdLine, SIZEOF_CH(szCmdLine), _T("\\storprop.dll"));
  2696. dllInstance = LoadLibrary (szCmdLine);
  2697. if (dllInstance) {
  2698. dvdPPLauncher = (DVDPPLAUNCHER) GetProcAddress(
  2699. dllInstance,
  2700. "DvdLauncher");
  2701. if (dvdPPLauncher) {
  2702. regionChanged = dvdPPLauncher(NULL,
  2703. szDriveLetterA[0]);
  2704. }
  2705. FreeLibrary(dllInstance);
  2706. }
  2707. }
  2708. else {
  2709. #if 0
  2710. // win9x code should be using complier defines rather than if0'ing it out
  2711. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2712. //Get path of \windows\dvdrgn.exe and command line string
  2713. TCHAR szCmdLine[MAX_PATH], szDriveLetter[4];
  2714. hr = GetDVDDriveLetter(szDriveLetter);
  2715. if(FAILED(hr)){
  2716. throw(hr);
  2717. }/* end of if statement */
  2718. UINT rc = GetWindowsDirectory(szCmdLine, MAX_PATH);
  2719. if (!rc) {
  2720. return E_UNEXPECTED;
  2721. }
  2722. (void)StringCchCat(szCmdLine, SIZEOF_CH(szCmdLine), _T("\\dvdrgn.exe "));
  2723. TCHAR strModuleName[MAX_PATH];
  2724. lstrcpyn(strModuleName, szCmdLine, MAX_PATH);
  2725. TCHAR csTmp[2]; ::ZeroMemory(csTmp, sizeof(TCHAR)* 2);
  2726. csTmp[0] = szDriveLetter[0];
  2727. (void)StringCchCat(szCmdLine, SIZEOF_CH(szCmdLine), csTmp);
  2728. //Prepare and execuate dvdrgn.exe
  2729. STARTUPINFO StartupInfo;
  2730. PROCESS_INFORMATION ProcessInfo;
  2731. StartupInfo.cb = sizeof(StartupInfo);
  2732. StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
  2733. StartupInfo.wShowWindow = SW_SHOW;
  2734. StartupInfo.lpReserved = NULL;
  2735. StartupInfo.lpDesktop = NULL;
  2736. StartupInfo.lpTitle = NULL;
  2737. StartupInfo.cbReserved2 = 0;
  2738. StartupInfo.lpReserved2 = NULL;
  2739. if( ::CreateProcess(strModuleName, szCmdLine, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS,
  2740. NULL, NULL, &StartupInfo, &ProcessInfo) ){
  2741. //Wait dvdrgn.exe finishes.
  2742. WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
  2743. DWORD dwRet = 1;
  2744. BOOL bRet = GetExitCodeProcess(ProcessInfo.hProcess, &dwRet);
  2745. if(dwRet == 0){
  2746. //User changed the region successfully
  2747. regionChanged = TRUE;
  2748. }
  2749. else{
  2750. throw(E_REGION_CHANGE_NOT_COMPLETED);
  2751. }
  2752. }/* end of if statement */
  2753. #endif
  2754. }/* end of if statement */
  2755. if (regionChanged) {
  2756. // start playing again
  2757. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2758. }
  2759. else {
  2760. throw(E_REGION_CHANGE_FAIL);
  2761. }/* end of if statement */
  2762. }
  2763. catch(HRESULT hrTmp){
  2764. hr = hrTmp;
  2765. }/* end of catch statement */
  2766. catch(...){
  2767. hr = E_UNEXPECTED;
  2768. }/* end of catch statement */
  2769. return HandleError(hr);
  2770. }/* end of function RegionChange */
  2771. /*************************************************************************/
  2772. /* Function: GetDVDDriveLetter */
  2773. /* Description: Gets the first three characters that denote the DVD-ROM */
  2774. /*************************************************************************/
  2775. HRESULT CMSVidWebDVD::GetDVDDriveLetter(TCHAR* lpDrive) {
  2776. HRESULT hr = E_FAIL;
  2777. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  2778. if(!pDvdInfo2){
  2779. throw(E_UNEXPECTED);
  2780. }/* end of if statement */
  2781. WCHAR szRoot[MAX_PATH];
  2782. ULONG ulActual;
  2783. hr = pDvdInfo2->GetDVDDirectory(szRoot, MAX_PATH, &ulActual);
  2784. if(FAILED(hr)){
  2785. return(hr);
  2786. }/* end of if statement */
  2787. USES_CONVERSION;
  2788. lstrcpyn(lpDrive, OLE2T(szRoot), 3);
  2789. if(::GetDriveType(&lpDrive[0]) == DRIVE_CDROM){
  2790. return(hr);
  2791. }
  2792. else {
  2793. //possibly root=c: or drive in hard disc
  2794. hr = E_FAIL;
  2795. return(hr);
  2796. }/* end of if statement */
  2797. return(hr);
  2798. }/* end of function GetDVDDriveLetter */
  2799. /*************************************************************************/
  2800. /* Function: get_DVDAdm */
  2801. /* Description: Returns DVD admin interface. */
  2802. /*************************************************************************/
  2803. STDMETHODIMP CMSVidWebDVD::get_DVDAdm(IDispatch **pVal){
  2804. HRESULT hr = S_OK;
  2805. try {
  2806. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2807. if (m_pDvdAdmin){
  2808. hr = m_pDvdAdmin->QueryInterface(IID_IDispatch, (LPVOID*)pVal);
  2809. }
  2810. else {
  2811. *pVal = NULL;
  2812. throw(E_FAIL);
  2813. }/* end of if statement */
  2814. }/* end of try statement */
  2815. catch(HRESULT hrTmp){
  2816. hr = hrTmp;
  2817. }/* end of catch statement */
  2818. catch(...){
  2819. hr = E_UNEXPECTED;
  2820. }/* end of catch statement */
  2821. return HandleError(hr);
  2822. }/* end of function get_DVDAdm */
  2823. /*************************************************************/
  2824. /* Name: SelectDefaultAudioLanguage
  2825. /* Description:
  2826. /*************************************************************/
  2827. STDMETHODIMP CMSVidWebDVD::SelectDefaultAudioLanguage(long lang, long ext){
  2828. HRESULT hr = S_OK;
  2829. try {
  2830. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2831. if(!m_pDVDControl2){
  2832. throw(E_UNEXPECTED);
  2833. }/* end of if statement */
  2834. hr = m_pDVDControl2->SelectDefaultAudioLanguage(lang, (DVD_AUDIO_LANG_EXT)ext);
  2835. if (FAILED(hr))
  2836. throw(hr);
  2837. }
  2838. catch(HRESULT hrTmp){
  2839. hr = hrTmp;
  2840. }/* end of catch statement */
  2841. catch(...){
  2842. hr = E_UNEXPECTED;
  2843. }/* end of catch statement */
  2844. return HandleError(hr);
  2845. }
  2846. /*************************************************************/
  2847. /* Name: SelectDefaultSubpictureLanguage
  2848. /* Description:
  2849. /*************************************************************/
  2850. STDMETHODIMP CMSVidWebDVD::SelectDefaultSubpictureLanguage(long lang, DVDSPExt ext){
  2851. HRESULT hr = S_OK;
  2852. try {
  2853. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2854. if(!m_pDVDControl2){
  2855. throw(E_UNEXPECTED);
  2856. }/* end of if statement */
  2857. hr = m_pDVDControl2->SelectDefaultSubpictureLanguage(lang, (DVD_SUBPICTURE_LANG_EXT)ext);
  2858. if (FAILED(hr))
  2859. throw(hr);
  2860. }
  2861. catch(HRESULT hrTmp){
  2862. hr = hrTmp;
  2863. }/* end of catch statement */
  2864. catch(...){
  2865. hr = E_UNEXPECTED;
  2866. }/* end of catch statement */
  2867. return HandleError(hr);
  2868. }
  2869. /*************************************************************/
  2870. /* Name: get_DefaultMenuLanguage
  2871. /* Description:
  2872. /*************************************************************/
  2873. STDMETHODIMP CMSVidWebDVD::get_DefaultMenuLanguage(long *lang)
  2874. {
  2875. HRESULT hr = S_OK;
  2876. try {
  2877. if(NULL == lang){
  2878. throw (E_POINTER);
  2879. }/* end of if statement */
  2880. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2881. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  2882. if(!pDvdInfo2){
  2883. throw(E_UNEXPECTED);
  2884. }/* end of if statement */
  2885. hr = pDvdInfo2->GetDefaultMenuLanguage((LCID*)lang);
  2886. if (FAILED(hr))
  2887. throw(hr);
  2888. }
  2889. catch(HRESULT hrTmp){
  2890. hr = hrTmp;
  2891. }/* end of catch statement */
  2892. catch(...){
  2893. hr = E_UNEXPECTED;
  2894. }/* end of catch statement */
  2895. return HandleError(hr);
  2896. }
  2897. /*************************************************************/
  2898. /* Name: put_DefaultMenuLanguage
  2899. /* Description:
  2900. /*************************************************************/
  2901. STDMETHODIMP CMSVidWebDVD::put_DefaultMenuLanguage(long lang){
  2902. HRESULT hr = S_OK;
  2903. try {
  2904. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2905. if(!m_pDVDControl2){
  2906. throw(E_UNEXPECTED);
  2907. }/* end of if statement */
  2908. hr = m_pDVDControl2->SelectDefaultMenuLanguage(lang);
  2909. if (FAILED(hr))
  2910. throw(hr);
  2911. }
  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. }
  2920. /*************************************************************************/
  2921. /* Function: get_PreferredSubpictureStream */
  2922. /* Description: Gets current audio stream. */
  2923. /*************************************************************************/
  2924. STDMETHODIMP CMSVidWebDVD::get_PreferredSubpictureStream(long *plPreferredStream){
  2925. HRESULT hr = S_OK;
  2926. try {
  2927. if (NULL == plPreferredStream){
  2928. throw(E_POINTER);
  2929. }/* end of if statement */
  2930. if(!m_pDvdAdmin){
  2931. throw(E_UNEXPECTED);
  2932. }/* end of if statement */
  2933. LCID langDefaultSP;
  2934. m_pDvdAdmin->get_DefaultSubpictureLCID((long*)&langDefaultSP);
  2935. // if none has been set
  2936. if (langDefaultSP == (LCID) -1) {
  2937. *plPreferredStream = 0;
  2938. return hr;
  2939. } /* end of if statement */
  2940. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2941. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  2942. if(!pDvdInfo2){
  2943. throw(E_UNEXPECTED);
  2944. }/* end of if statement */
  2945. USES_CONVERSION;
  2946. LCID lcid = 0;
  2947. ULONG ulNumAudioStreams = 0;
  2948. ULONG ulCurrentStream = 0;
  2949. BOOL fDisabled = TRUE;
  2950. RETRY_IF_IN_FPDOM(pDvdInfo2->GetCurrentSubpicture(&ulNumAudioStreams, &ulCurrentStream, &fDisabled));
  2951. *plPreferredStream = 0;
  2952. for (ULONG i = 0; i<ulNumAudioStreams; i++) {
  2953. hr = pDvdInfo2->GetSubpictureLanguage(i, &lcid);
  2954. if (SUCCEEDED( hr ) && lcid){
  2955. if (lcid == langDefaultSP) {
  2956. *plPreferredStream = i;
  2957. }
  2958. }
  2959. }
  2960. }
  2961. catch(HRESULT hrTmp){
  2962. return hrTmp;
  2963. }/* end of catch statement */
  2964. catch(...){
  2965. return E_UNEXPECTED;
  2966. }/* end of catch statement */
  2967. return HandleError(hr);
  2968. }
  2969. /*************************************************************/
  2970. /* Name: get_DefaultSubpictureLanguage
  2971. /* Description:
  2972. /*************************************************************/
  2973. STDMETHODIMP CMSVidWebDVD::get_DefaultSubpictureLanguage(long *lang)
  2974. {
  2975. HRESULT hr = S_OK;
  2976. try {
  2977. if(NULL == lang){
  2978. throw (E_POINTER);
  2979. }/* end of if statement */
  2980. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  2981. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  2982. if(!pDvdInfo2){
  2983. throw(E_UNEXPECTED);
  2984. }/* end of if statement */
  2985. long ext;
  2986. hr = pDvdInfo2->GetDefaultSubpictureLanguage((LCID*)lang, (DVD_SUBPICTURE_LANG_EXT*)&ext);
  2987. if (FAILED(hr))
  2988. throw(hr);
  2989. }
  2990. catch(HRESULT hrTmp){
  2991. hr = hrTmp;
  2992. }/* end of catch statement */
  2993. catch(...){
  2994. hr = E_UNEXPECTED;
  2995. }/* end of catch statement */
  2996. return HandleError(hr);
  2997. }
  2998. /*************************************************************/
  2999. /* Name: get_DefaultSubpictureLanguageExt
  3000. /* Description:
  3001. /*************************************************************/
  3002. STDMETHODIMP CMSVidWebDVD::get_DefaultSubpictureLanguageExt(DVDSPExt *ext)
  3003. {
  3004. HRESULT hr = S_OK;
  3005. try {
  3006. if(NULL == ext){
  3007. throw (E_POINTER);
  3008. }/* end of if statement */
  3009. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  3010. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  3011. if(!pDvdInfo2){
  3012. throw(E_UNEXPECTED);
  3013. }/* end of if statement */
  3014. long lang;
  3015. hr = pDvdInfo2->GetDefaultSubpictureLanguage((LCID*)&lang, (DVD_SUBPICTURE_LANG_EXT*)ext);
  3016. if (FAILED(hr))
  3017. throw(hr);
  3018. }
  3019. catch(HRESULT hrTmp){
  3020. hr = hrTmp;
  3021. }/* end of catch statement */
  3022. catch(...){
  3023. hr = E_UNEXPECTED;
  3024. }/* end of catch statement */
  3025. return HandleError(hr);
  3026. }
  3027. /*************************************************************/
  3028. /* Name: get_DefaultAudioLanguage
  3029. /* Description:
  3030. /*************************************************************/
  3031. STDMETHODIMP CMSVidWebDVD::get_DefaultAudioLanguage(long *lang)
  3032. {
  3033. HRESULT hr = S_OK;
  3034. try {
  3035. if(NULL == lang){
  3036. throw (E_POINTER);
  3037. }/* end of if statement */
  3038. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  3039. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  3040. if(!pDvdInfo2){
  3041. throw(E_UNEXPECTED);
  3042. }/* end of if statement */
  3043. long ext;
  3044. hr = pDvdInfo2->GetDefaultAudioLanguage((LCID*)lang, (DVD_AUDIO_LANG_EXT*)&ext);
  3045. if (FAILED(hr))
  3046. throw(hr);
  3047. }
  3048. catch(HRESULT hrTmp){
  3049. hr = hrTmp;
  3050. }/* end of catch statement */
  3051. catch(...){
  3052. hr = E_UNEXPECTED;
  3053. }/* end of catch statement */
  3054. return HandleError(hr);
  3055. }
  3056. /*************************************************************/
  3057. /* Name: get_DefaultAudioLanguageExt
  3058. /* Description:
  3059. /*************************************************************/
  3060. STDMETHODIMP CMSVidWebDVD::get_DefaultAudioLanguageExt(long *ext)
  3061. {
  3062. HRESULT hr = S_OK;
  3063. try {
  3064. if(NULL == ext){
  3065. throw (E_POINTER);
  3066. }/* end of if statement */
  3067. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  3068. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  3069. if(!pDvdInfo2){
  3070. throw(E_UNEXPECTED);
  3071. }/* end of if statement */
  3072. long lang;
  3073. hr = pDvdInfo2->GetDefaultAudioLanguage((LCID*)&lang, (DVD_AUDIO_LANG_EXT*)ext);
  3074. if (FAILED(hr))
  3075. throw(hr);
  3076. }
  3077. catch(HRESULT hrTmp){
  3078. hr = hrTmp;
  3079. }/* end of catch statement */
  3080. catch(...){
  3081. hr = E_UNEXPECTED;
  3082. }/* end of catch statement */
  3083. return HandleError(hr);
  3084. }
  3085. /*************************************************************/
  3086. /* Name: GetLanguageFromLCID
  3087. /* Description:
  3088. /*************************************************************/
  3089. STDMETHODIMP CMSVidWebDVD::get_LanguageFromLCID(long lcid, BSTR* lang)
  3090. {
  3091. HRESULT hr = S_OK;
  3092. try {
  3093. if (lang == NULL) {
  3094. throw(E_POINTER);
  3095. }/* end of if statement */
  3096. USES_CONVERSION;
  3097. LPTSTR pszString = m_LangID.GetLanguageFromLCID(lcid);
  3098. if (pszString) {
  3099. *lang = ::SysAllocString(T2OLE(pszString));
  3100. delete[] pszString;
  3101. }
  3102. else {
  3103. *lang = ::SysAllocString( L"");
  3104. throw(E_NOTIMPL);
  3105. }/* end of if statement */
  3106. }/* end of try statement */
  3107. catch(HRESULT hrTmp){
  3108. hr = hrTmp;
  3109. }/* end of catch statement */
  3110. catch(...){
  3111. hr = E_UNEXPECTED;
  3112. }/* end of catch statement */
  3113. return HandleError(hr);
  3114. }
  3115. /*************************************************************/
  3116. /* Name: get_KaraokeAudioPresentationMode
  3117. /* Description:
  3118. /*************************************************************/
  3119. STDMETHODIMP CMSVidWebDVD::get_KaraokeAudioPresentationMode(long *pVal)
  3120. {
  3121. HRESULT hr = S_OK;
  3122. try {
  3123. if (NULL == pVal) {
  3124. throw (E_POINTER);
  3125. } /* end of if statement */
  3126. *pVal = m_lKaraokeAudioPresentationMode;
  3127. }/* end of try statement */
  3128. catch(HRESULT hrTmp){
  3129. hr = hrTmp;
  3130. }/* end of catch statement */
  3131. catch(...){
  3132. hr = E_UNEXPECTED;
  3133. }/* end of catch statement */
  3134. return HandleError(hr);
  3135. }
  3136. /*************************************************************/
  3137. /* Name: put_KaraokeAudioPresentationMode
  3138. /* Description:
  3139. /*************************************************************/
  3140. STDMETHODIMP CMSVidWebDVD::put_KaraokeAudioPresentationMode(long newVal)
  3141. {
  3142. HRESULT hr = S_OK;
  3143. try {
  3144. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  3145. if(!m_pDVDControl2){
  3146. throw(E_UNEXPECTED);
  3147. }/* end of if statement */
  3148. RETRY_IF_IN_FPDOM(m_pDVDControl2->SelectKaraokeAudioPresentationMode((ULONG)newVal));
  3149. if(FAILED(hr)){
  3150. throw(hr);
  3151. }/* end of if statement */
  3152. // Cache the value
  3153. m_lKaraokeAudioPresentationMode = newVal;
  3154. }/* end of try statement */
  3155. catch(HRESULT hrTmp){
  3156. hr = hrTmp;
  3157. }/* end of catch statement */
  3158. catch(...){
  3159. hr = E_UNEXPECTED;
  3160. }/* end of catch statement */
  3161. return HandleError(hr);
  3162. }
  3163. /*************************************************************/
  3164. /* Name: GetKaraokeChannelContent
  3165. /* Description:
  3166. /*************************************************************/
  3167. STDMETHODIMP CMSVidWebDVD::get_KaraokeChannelContent(long lStream, long lChan, long *lContent)
  3168. {
  3169. HRESULT hr = S_OK;
  3170. try {
  3171. if(!lContent){
  3172. return E_POINTER;
  3173. }
  3174. if(lStream < 0){
  3175. throw(E_INVALIDARG);
  3176. }/* end of if statement */
  3177. if (lChan >=8 || lChan < 0 ) {
  3178. throw(E_INVALIDARG);
  3179. }/* end of if statement */
  3180. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  3181. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  3182. if(!pDvdInfo2){
  3183. throw(E_UNEXPECTED);
  3184. }/* end of if statement */
  3185. DVD_KaraokeAttributes attrib;
  3186. RETRY_IF_IN_FPDOM(pDvdInfo2->GetKaraokeAttributes(lStream, &attrib));
  3187. if(FAILED(hr)){
  3188. throw(hr);
  3189. }/* end of if statement */
  3190. *lContent = (long)attrib.wChannelContents[lChan];
  3191. }/* end of try statement */
  3192. catch(HRESULT hrTmp){
  3193. hr = hrTmp;
  3194. }/* end of catch statement */
  3195. catch(...){
  3196. hr = E_UNEXPECTED;
  3197. }/* end of catch statement */
  3198. return HandleError(hr);
  3199. }
  3200. /*************************************************************/
  3201. /* Name: GetKaraokeChannelAssignment
  3202. /* Description:
  3203. /*************************************************************/
  3204. STDMETHODIMP CMSVidWebDVD::get_KaraokeChannelAssignment(long lStream, long *lChannelAssignment)
  3205. {
  3206. HRESULT hr = S_OK;
  3207. try {
  3208. if(!lChannelAssignment){
  3209. return E_POINTER;
  3210. }
  3211. if(lStream < 0){
  3212. throw(E_INVALIDARG);
  3213. }/* end of if statement */
  3214. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  3215. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  3216. if(!pDvdInfo2){
  3217. throw(E_UNEXPECTED);
  3218. }/* end of if statement */
  3219. DVD_KaraokeAttributes attrib;
  3220. RETRY_IF_IN_FPDOM(pDvdInfo2->GetKaraokeAttributes(lStream, &attrib));
  3221. if(FAILED(hr)){
  3222. throw(hr);
  3223. }/* end of if statement */
  3224. *lChannelAssignment = (long)attrib.ChannelAssignment;
  3225. }/* end of try statement */
  3226. catch(HRESULT hrTmp){
  3227. hr = hrTmp;
  3228. }/* end of catch statement */
  3229. catch(...){
  3230. hr = E_UNEXPECTED;
  3231. }/* end of catch statement */
  3232. return HandleError(hr);
  3233. }
  3234. STDMETHODIMP CMSVidWebDVD::OnEventNotify(long lEvent, LONG_PTR lParam1, LONG_PTR lParam2) {
  3235. if (lEvent == EC_STEP_COMPLETE || (lEvent > EC_DVDBASE && lEvent <= EC_DVD_KARAOKE_MODE) ) {
  3236. return OnDVDEvent(lEvent, lParam1, lParam2);
  3237. }
  3238. if(lEvent == EC_STATE_CHANGE && lParam1 == State_Running){
  3239. VARIANT_BOOL onStop;
  3240. HRESULT hr = m_pDvdAdmin->get_BookmarkOnStop(&onStop);
  3241. if(FAILED(hr)){
  3242. throw(hr);
  3243. }
  3244. if(VARIANT_TRUE == onStop){
  3245. hr = RestoreBookmark();
  3246. if(FAILED(hr)){
  3247. throw(hr);
  3248. }
  3249. }
  3250. }
  3251. return IMSVidPBGraphSegmentImpl<CMSVidWebDVD, MSVidSEG_SOURCE, &GUID_NULL>::OnEventNotify(lEvent, lParam1, lParam2);
  3252. }
  3253. /*************************************************************/
  3254. /* Name: OnDVDEvent
  3255. /* Description: Deal with DVD events
  3256. /*************************************************************/
  3257. STDMETHODIMP CMSVidWebDVD::OnDVDEvent(long lEvent, LONG_PTR lParam1, LONG_PTR lParam2)
  3258. {
  3259. if (m_fFireNoSubpictureStream) {
  3260. m_fFireNoSubpictureStream = FALSE;
  3261. lEvent = EC_DVD_ERROR;
  3262. lParam1 = DVD_ERROR_NoSubpictureStream;
  3263. lParam2 = 0;
  3264. VARIANT varLParam1;
  3265. VARIANT varLParam2;
  3266. #ifdef _WIN64
  3267. varLParam1.llVal = lParam1;
  3268. varLParam1.vt = VT_I8;
  3269. varLParam2.llVal = lParam2;
  3270. varLParam2.vt = VT_I8;
  3271. #else
  3272. varLParam1.lVal = lParam1;
  3273. varLParam1.vt = VT_I4;
  3274. varLParam2.lVal = lParam2;
  3275. varLParam2.vt = VT_I4;
  3276. #endif
  3277. // fire the event now after we have processed it internally
  3278. Fire_DVDNotify(lEvent, varLParam1, varLParam2);
  3279. }
  3280. ATLTRACE(TEXT("CMSVidWebDVD::OnDVDEvent %x\n"), lEvent-EC_DVDBASE);
  3281. switch (lEvent){
  3282. //
  3283. // First the DVD error events
  3284. //
  3285. case EC_DVD_ERROR:
  3286. switch (lParam1){
  3287. case DVD_ERROR_Unexpected:
  3288. break ;
  3289. case DVD_ERROR_CopyProtectFail:
  3290. break ;
  3291. case DVD_ERROR_InvalidDVD1_0Disc:
  3292. break ;
  3293. case DVD_ERROR_InvalidDiscRegion:
  3294. PreStop();
  3295. PostStop();
  3296. break ;
  3297. case DVD_ERROR_LowParentalLevel:
  3298. break ;
  3299. case DVD_ERROR_MacrovisionFail:
  3300. break ;
  3301. case DVD_ERROR_IncompatibleSystemAndDecoderRegions:
  3302. break ;
  3303. case DVD_ERROR_IncompatibleDiscAndDecoderRegions:
  3304. break ;
  3305. }
  3306. break;
  3307. //
  3308. // Next the normal DVD related events
  3309. //
  3310. case EC_DVD_VALID_UOPS_CHANGE:
  3311. {
  3312. VALID_UOP_SOMTHING_OR_OTHER validUOPs = (DWORD) lParam1;
  3313. if (validUOPs&UOP_FLAG_Play_Title_Or_AtTime) {
  3314. Fire_PlayAtTimeInTitle(VARIANT_FALSE);
  3315. Fire_PlayAtTime(VARIANT_FALSE);
  3316. }
  3317. else {
  3318. Fire_PlayAtTimeInTitle(VARIANT_TRUE);
  3319. Fire_PlayAtTime(VARIANT_TRUE);
  3320. }
  3321. if (validUOPs&UOP_FLAG_Play_Chapter) {
  3322. Fire_PlayChapterInTitle(VARIANT_FALSE);
  3323. Fire_PlayChapter(VARIANT_FALSE);
  3324. }
  3325. else {
  3326. Fire_PlayChapterInTitle(VARIANT_TRUE);
  3327. Fire_PlayChapter(VARIANT_TRUE);
  3328. }
  3329. if (validUOPs&UOP_FLAG_Play_Title){
  3330. Fire_PlayTitle(VARIANT_FALSE);
  3331. }
  3332. else {
  3333. Fire_PlayTitle(VARIANT_TRUE);
  3334. }
  3335. if (validUOPs&UOP_FLAG_Stop)
  3336. Fire_Stop(VARIANT_FALSE);
  3337. else
  3338. Fire_Stop(VARIANT_TRUE);
  3339. if (validUOPs&UOP_FLAG_ReturnFromSubMenu)
  3340. Fire_ReturnFromSubmenu(VARIANT_FALSE);
  3341. else
  3342. Fire_ReturnFromSubmenu(VARIANT_TRUE);
  3343. if (validUOPs&UOP_FLAG_Play_Chapter_Or_AtTime) {
  3344. Fire_PlayAtTimeInTitle(VARIANT_FALSE);
  3345. Fire_PlayChapterInTitle(VARIANT_FALSE);
  3346. }
  3347. else {
  3348. Fire_PlayAtTimeInTitle(VARIANT_TRUE);
  3349. Fire_PlayChapterInTitle(VARIANT_TRUE);
  3350. }
  3351. if (validUOPs&UOP_FLAG_PlayPrev_Or_Replay_Chapter){
  3352. Fire_PlayPrevChapter(VARIANT_FALSE);
  3353. Fire_ReplayChapter(VARIANT_FALSE);
  3354. }
  3355. else {
  3356. Fire_PlayPrevChapter(VARIANT_TRUE);
  3357. Fire_ReplayChapter(VARIANT_TRUE);
  3358. }/* end of if statement */
  3359. if (validUOPs&UOP_FLAG_PlayNext_Chapter)
  3360. Fire_PlayNextChapter(VARIANT_FALSE);
  3361. else
  3362. Fire_PlayNextChapter(VARIANT_TRUE);
  3363. if (validUOPs&UOP_FLAG_Play_Forwards)
  3364. Fire_PlayForwards(VARIANT_FALSE);
  3365. else
  3366. Fire_PlayForwards(VARIANT_TRUE);
  3367. if (validUOPs&UOP_FLAG_Play_Backwards)
  3368. Fire_PlayBackwards(VARIANT_FALSE);
  3369. else
  3370. Fire_PlayBackwards(VARIANT_TRUE);
  3371. if (validUOPs&UOP_FLAG_ShowMenu_Title)
  3372. Fire_ShowMenu(dvdMenu_Title, VARIANT_FALSE);
  3373. else
  3374. Fire_ShowMenu(dvdMenu_Title, VARIANT_TRUE);
  3375. if (validUOPs&UOP_FLAG_ShowMenu_Root)
  3376. Fire_ShowMenu(dvdMenu_Root, VARIANT_FALSE);
  3377. else
  3378. Fire_ShowMenu(dvdMenu_Root, VARIANT_TRUE);
  3379. //TODO: Add the event for specific menus
  3380. if (validUOPs&UOP_FLAG_ShowMenu_SubPic)
  3381. Fire_ShowMenu(dvdMenu_Subpicture, VARIANT_FALSE);
  3382. else
  3383. Fire_ShowMenu(dvdMenu_Subpicture, VARIANT_TRUE);
  3384. if (validUOPs&UOP_FLAG_ShowMenu_Audio)
  3385. Fire_ShowMenu(dvdMenu_Audio, VARIANT_FALSE);
  3386. else
  3387. Fire_ShowMenu(dvdMenu_Audio, VARIANT_TRUE);
  3388. if (validUOPs&UOP_FLAG_ShowMenu_Angle)
  3389. Fire_ShowMenu(dvdMenu_Angle, VARIANT_FALSE);
  3390. else
  3391. Fire_ShowMenu(dvdMenu_Angle, VARIANT_TRUE);
  3392. if (validUOPs&UOP_FLAG_ShowMenu_Chapter)
  3393. Fire_ShowMenu(dvdMenu_Chapter, VARIANT_FALSE);
  3394. else
  3395. Fire_ShowMenu(dvdMenu_Chapter, VARIANT_TRUE);
  3396. if (validUOPs&UOP_FLAG_Resume)
  3397. Fire_Resume(VARIANT_FALSE);
  3398. else
  3399. Fire_Resume(VARIANT_TRUE);
  3400. if (validUOPs&UOP_FLAG_Select_Or_Activate_Button)
  3401. Fire_SelectOrActivateButton(VARIANT_FALSE);
  3402. else
  3403. Fire_SelectOrActivateButton(VARIANT_TRUE);
  3404. if (validUOPs&UOP_FLAG_Still_Off)
  3405. Fire_StillOff(VARIANT_FALSE);
  3406. else
  3407. Fire_StillOff(VARIANT_TRUE);
  3408. if (validUOPs&UOP_FLAG_Pause_On)
  3409. Fire_PauseOn(VARIANT_FALSE);
  3410. else
  3411. Fire_PauseOn(VARIANT_TRUE);
  3412. if (validUOPs&UOP_FLAG_Select_Audio_Stream)
  3413. Fire_ChangeCurrentAudioStream(VARIANT_FALSE);
  3414. else
  3415. Fire_ChangeCurrentAudioStream(VARIANT_TRUE);
  3416. if (validUOPs&UOP_FLAG_Select_SubPic_Stream)
  3417. Fire_ChangeCurrentSubpictureStream(VARIANT_FALSE);
  3418. else
  3419. Fire_ChangeCurrentSubpictureStream(VARIANT_TRUE);
  3420. if (validUOPs&UOP_FLAG_Select_Angle)
  3421. Fire_ChangeCurrentAngle(VARIANT_FALSE);
  3422. else
  3423. Fire_ChangeCurrentAngle(VARIANT_TRUE);
  3424. /*
  3425. if (validUOPs&UOP_FLAG_Karaoke_Audio_Pres_Mode_Change)
  3426. ;
  3427. if (validUOPs&UOP_FLAG_Video_Pres_Mode_Change)
  3428. ;
  3429. */
  3430. }
  3431. break;
  3432. case EC_DVD_STILL_ON:
  3433. m_fStillOn = true;
  3434. break ;
  3435. case EC_DVD_STILL_OFF:
  3436. m_fStillOn = false;
  3437. break ;
  3438. case EC_DVD_DOMAIN_CHANGE:
  3439. switch (lParam1){
  3440. case DVD_DOMAIN_FirstPlay: // = 1
  3441. //case DVD_DOMAIN_VideoManagerMenu: // = 2
  3442. break;
  3443. case DVD_DOMAIN_Stop: // = 5
  3444. case DVD_DOMAIN_VideoManagerMenu: // = 2
  3445. case DVD_DOMAIN_VideoTitleSetMenu: // = 3
  3446. case DVD_DOMAIN_Title: // = 4
  3447. default:
  3448. break;
  3449. }/* end of switch case */
  3450. break ;
  3451. case EC_DVD_BUTTON_CHANGE:
  3452. break;
  3453. case EC_DVD_CHAPTER_START:
  3454. break ;
  3455. case EC_DVD_CURRENT_TIME:
  3456. //ATLTRACE(TEXT("Time event \n"));
  3457. break;
  3458. //
  3459. // Then the general DirectShow related events
  3460. //
  3461. case EC_DVD_PLAYBACK_STOPPED:
  3462. // DShow doesn't stop on end; we should do that
  3463. // call PostStop to make sure graph is stopped properly
  3464. //PostStop();
  3465. break;
  3466. case EC_DVD_DISC_EJECTED:
  3467. m_bEjected = true;
  3468. break;
  3469. case EC_DVD_DISC_INSERTED:
  3470. m_bEjected = false;
  3471. break;
  3472. case EC_STEP_COMPLETE:
  3473. m_fStepComplete = true;
  3474. break;
  3475. case EC_DVD_PLAYBACK_RATE_CHANGE:
  3476. m_Rate = lParam1 / 10000;
  3477. break;
  3478. default:
  3479. break ;
  3480. }/* end of switch case */
  3481. VARIANT varLParam1;
  3482. VARIANT varLParam2;
  3483. #ifdef _WIN64
  3484. varLParam1.llVal = lParam1;
  3485. varLParam1.vt = VT_I8;
  3486. varLParam2.llVal = lParam2;
  3487. varLParam2.vt = VT_I8;
  3488. #else
  3489. varLParam1.lVal = lParam1;
  3490. varLParam1.vt = VT_I4;
  3491. varLParam2.lVal = lParam2;
  3492. varLParam2.vt = VT_I4;
  3493. #endif
  3494. // fire the event now after we have processed it internally
  3495. Fire_DVDNotify(lEvent, varLParam1, varLParam2);
  3496. return NOERROR;
  3497. }
  3498. /*************************************************************/
  3499. /* Name: RestorePreferredSettings
  3500. /* Description:
  3501. /*************************************************************/
  3502. HRESULT CMSVidWebDVD::RestorePreferredSettings()
  3503. {
  3504. HRESULT hr = S_OK;
  3505. try {
  3506. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  3507. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  3508. if(!pDvdInfo2){
  3509. throw(E_UNEXPECTED);
  3510. }/* end of if statement */
  3511. // get the curent domain
  3512. DVD_DOMAIN domain;
  3513. hr = pDvdInfo2->GetCurrentDomain(&domain);
  3514. if(FAILED(hr)){
  3515. throw(hr);
  3516. }/* end of if statement */
  3517. // Have to be in the stop domain
  3518. if(DVD_DOMAIN_Stop != domain)
  3519. throw (VFW_E_DVD_INVALIDDOMAIN);
  3520. if(!m_pDvdAdmin){
  3521. throw (E_UNEXPECTED);
  3522. }/* end of if statement */
  3523. long level;
  3524. hr = m_pDvdAdmin->GetParentalLevel(&level);
  3525. if (SUCCEEDED(hr))
  3526. SelectParentalLevel(level);
  3527. LCID audioLCID;
  3528. LCID subpictureLCID;
  3529. LCID menuLCID;
  3530. hr = m_pDvdAdmin->get_DefaultAudioLCID((long*)&audioLCID);
  3531. if (SUCCEEDED(hr))
  3532. SelectDefaultAudioLanguage(audioLCID, 0);
  3533. hr = m_pDvdAdmin->get_DefaultSubpictureLCID((long*)&subpictureLCID);
  3534. if (SUCCEEDED(hr))
  3535. SelectDefaultSubpictureLanguage(subpictureLCID, dvdSPExt_NotSpecified);
  3536. hr = m_pDvdAdmin->get_DefaultMenuLCID((long*)&menuLCID);
  3537. if (SUCCEEDED(hr))
  3538. put_DefaultMenuLanguage(menuLCID);
  3539. }
  3540. catch(HRESULT hrTmp){
  3541. hr = hrTmp;
  3542. }/* end of catch statement */
  3543. catch(...){
  3544. hr = E_UNEXPECTED;
  3545. }/* end of catch statement */
  3546. return HandleError(hr);
  3547. }
  3548. HRESULT CMSVidWebDVD::get_ButtonRect(long lButton, /*[out, retval] */ IMSVidRect** pRect){
  3549. try{
  3550. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  3551. if(!pDvdInfo2){
  3552. throw(E_UNEXPECTED);
  3553. }/* end of if statement */
  3554. if(!pRect){
  3555. return E_POINTER;
  3556. }
  3557. CRect oRect;
  3558. HRESULT hr = pDvdInfo2->GetButtonRect( lButton, &oRect);
  3559. if(FAILED(hr)){
  3560. return hr;
  3561. }
  3562. *((CRect*)(*pRect)) = oRect;
  3563. }
  3564. catch(...){
  3565. return E_UNEXPECTED;
  3566. }
  3567. return S_OK;
  3568. }
  3569. HRESULT CMSVidWebDVD::get_DVDScreenInMouseCoordinates(/*[out, retval] */ IMSVidRect** ppRect){
  3570. return E_NOTIMPL;
  3571. }
  3572. HRESULT CMSVidWebDVD::put_DVDScreenInMouseCoordinates(IMSVidRect* pRect){
  3573. return E_NOTIMPL;
  3574. }
  3575. #endif //TUNING_MODEL_ONLY