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.

543 lines
13 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: commands.cpp
  3. *
  4. * Processes commands from the user.
  5. *
  6. *
  7. * Created: dd-mm-94
  8. * Author: Stephen Estrop [StephenE]
  9. *
  10. * Copyright (c) 1994 - 1999 Microsoft Corporation. All Rights Reserved.
  11. \**************************************************************************/
  12. #include <streams.h>
  13. #include <mmreg.h>
  14. #include <commctrl.h>
  15. #include "project.h"
  16. #include "mpgcodec.h"
  17. #include <stdio.h>
  18. BOOL GetAMErrorText(HRESULT hr, TCHAR *Buffer, DWORD dwLen);
  19. extern CMpegMovie *pMpegMovie;
  20. /******************************Public*Routine******************************\
  21. * VcdPlayerOpenCmd
  22. *
  23. *
  24. *
  25. * History:
  26. * dd-mm-94 - StephenE - Created
  27. *
  28. \**************************************************************************/
  29. BOOL
  30. VcdPlayerOpenCmd(
  31. void
  32. )
  33. {
  34. static BOOL fFirstTime = TRUE;
  35. BOOL fRet;
  36. TCHAR achFileName[MAX_PATH];
  37. TCHAR achFilter[MAX_PATH];
  38. LPTSTR lp;
  39. if (fFirstTime) {
  40. ofn.lStructSize = sizeof(ofn);
  41. ofn.hwndOwner = hwndApp;
  42. ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST |
  43. OFN_SHAREAWARE | OFN_PATHMUSTEXIST;
  44. }
  45. lstrcpy(achFilter, IdStr(STR_FILE_FILTER) );
  46. ofn.lpstrFilter = achFilter;
  47. /*
  48. ** Convert the resource string into to something suitable for
  49. ** GetOpenFileName ie. replace '#' characters with '\0' characters.
  50. */
  51. for (lp = achFilter; *lp; lp++ ) {
  52. if (*lp == TEXT('#')) {
  53. *lp = TEXT('\0');
  54. }
  55. }
  56. ofn.lpstrFile = achFileName;
  57. ofn.nMaxFile = sizeof(achFileName) / sizeof(TCHAR);
  58. ZeroMemory(achFileName, sizeof(achFileName));
  59. fRet = GetOpenFileName(&ofn);
  60. if ( fRet ) {
  61. fFirstTime = FALSE;
  62. ProcessOpen(achFileName);
  63. }
  64. return fRet;
  65. }
  66. /******************************Public*Routine******************************\
  67. * VcdPlayerSetLog
  68. *
  69. *
  70. *
  71. * History:
  72. * 11-04-94 - LaurieGr - Created
  73. *
  74. \**************************************************************************/
  75. BOOL
  76. VcdPlayerSetLog(
  77. void
  78. )
  79. {
  80. BOOL fRet;
  81. TCHAR achFileName[MAX_PATH];
  82. TCHAR achFilter[MAX_PATH];
  83. LPTSTR lp;
  84. OPENFILENAME opfn;
  85. ZeroMemory(&opfn, sizeof(opfn));
  86. opfn.lStructSize = sizeof(opfn);
  87. opfn.hwndOwner = hwndApp;
  88. opfn.Flags = OFN_HIDEREADONLY | OFN_SHAREAWARE | OFN_PATHMUSTEXIST;
  89. lstrcpy(achFilter, IdStr(STR_FILE_LOG_FILTER) );
  90. opfn.lpstrFilter = achFilter;
  91. /*
  92. ** Convert the resource string into to something suitable for
  93. ** GetOpenFileName ie. replace '#' characters with '\0' characters.
  94. */
  95. for (lp = achFilter; *lp; lp++ ) {
  96. if (*lp == TEXT('#')) {
  97. *lp = TEXT('\0');
  98. }
  99. }
  100. opfn.lpstrFile = achFileName;
  101. opfn.nMaxFile = sizeof(achFileName) / sizeof(TCHAR);
  102. ZeroMemory(achFileName, sizeof(achFileName));
  103. fRet = GetOpenFileName(&opfn);
  104. if ( fRet ) {
  105. hRenderLog = CreateFile( achFileName
  106. , GENERIC_WRITE
  107. , 0 // no sharing
  108. , NULL // no security
  109. , OPEN_ALWAYS
  110. , 0 // no attributes, no flags
  111. , NULL // no template
  112. );
  113. if (hRenderLog==INVALID_HANDLE_VALUE) {
  114. volatile int Err = GetLastError();
  115. fRet = FALSE;
  116. }
  117. // Seek to end of file
  118. SetFilePointer(hRenderLog, 0, NULL, FILE_END);
  119. }
  120. return fRet;
  121. }
  122. /******************************Public*Routine******************************\
  123. * VcdPlayerSetPerfLogFile
  124. *
  125. *
  126. *
  127. * History:
  128. * 30-05-96 - StephenE - Created
  129. *
  130. \**************************************************************************/
  131. BOOL
  132. VcdPlayerSetPerfLogFile(
  133. void
  134. )
  135. {
  136. BOOL fRet;
  137. TCHAR achFileName[MAX_PATH];
  138. TCHAR achFilter[MAX_PATH];
  139. LPTSTR lp;
  140. OPENFILENAME opfn;
  141. ZeroMemory(&opfn, sizeof(opfn));
  142. opfn.lStructSize = sizeof(opfn);
  143. opfn.hwndOwner = hwndApp;
  144. opfn.Flags = OFN_HIDEREADONLY | OFN_SHAREAWARE | OFN_PATHMUSTEXIST;
  145. lstrcpy(achFilter, IdStr(STR_FILE_PERF_LOG) );
  146. opfn.lpstrFilter = achFilter;
  147. /*
  148. ** Convert the resource string into to something suitable for
  149. ** GetOpenFileName ie. replace '#' characters with '\0' characters.
  150. */
  151. for (lp = achFilter; *lp; lp++ ) {
  152. if (*lp == TEXT('#')) {
  153. *lp = TEXT('\0');
  154. }
  155. }
  156. opfn.lpstrFile = achFileName;
  157. opfn.nMaxFile = sizeof(achFileName) / sizeof(TCHAR);
  158. lstrcpy(achFileName, g_szPerfLog);
  159. fRet = GetOpenFileName(&opfn);
  160. if ( fRet ) {
  161. lstrcpy(g_szPerfLog, achFileName);
  162. }
  163. return fRet;
  164. }
  165. /******************************Public*Routine******************************\
  166. * VcdPlayerCloseCmd
  167. *
  168. *
  169. *
  170. * History:
  171. * dd-mm-94 - StephenE - Created
  172. *
  173. \**************************************************************************/
  174. BOOL
  175. VcdPlayerCloseCmd(
  176. void
  177. )
  178. {
  179. if (pMpegMovie) {
  180. LONG cx, cy;
  181. if (pMpegMovie->pMpegDecoder != NULL) {
  182. KillTimer(hwndApp, 32);
  183. }
  184. g_State = VCD_NO_CD;
  185. pMpegMovie->GetMoviePosition(&lMovieOrgX, &lMovieOrgY, &cx, &cy);
  186. pMpegMovie->CloseMovie();
  187. SetDurationLength((REFTIME)0);
  188. SetCurrentPosition((REFTIME)0);
  189. delete pMpegMovie;
  190. pMpegMovie = NULL;
  191. }
  192. InvalidateRect( hwndApp, NULL, FALSE );
  193. UpdateWindow( hwndApp );
  194. return TRUE;
  195. }
  196. /******************************Public*Routine******************************\
  197. * VcdPlayerPlayCmd
  198. *
  199. *
  200. *
  201. * History:
  202. * dd-mm-94 - StephenE - Created
  203. *
  204. \**************************************************************************/
  205. BOOL
  206. VcdPlayerPlayCmd(
  207. void
  208. )
  209. {
  210. BOOL fStopped = (g_State & VCD_STOPPED);
  211. BOOL fPaused = (g_State & VCD_PAUSED);
  212. if ( (fStopped || fPaused) ) {
  213. HDC hdc;
  214. RECT rc;
  215. //
  216. // Clear out the old stats from the main window
  217. //
  218. hdc = GetDC(hwndApp);
  219. GetAdjustedClientRect(&rc);
  220. FillRect(hdc, &rc, (HBRUSH)(COLOR_BTNFACE + 1));
  221. ReleaseDC(hwndApp, hdc);
  222. if (pMpegMovie) {
  223. pMpegMovie->PlayMovie();
  224. }
  225. g_State &= ~(fStopped ? VCD_STOPPED : VCD_PAUSED);
  226. g_State |= VCD_PLAYING;
  227. }
  228. return TRUE;
  229. }
  230. /******************************Public*Routine******************************\
  231. * VcdPlayerPlayCmd
  232. *
  233. *
  234. *
  235. * History:
  236. * dd-mm-94 - StephenE - Created
  237. *
  238. \**************************************************************************/
  239. BOOL
  240. VcdPlayerStopCmd(
  241. void
  242. )
  243. {
  244. BOOL fPlaying = (g_State & VCD_PLAYING);
  245. BOOL fPaused = (g_State & VCD_PAUSED);
  246. if ( (fPlaying || fPaused) ) {
  247. if (pMpegMovie) {
  248. pMpegMovie->StopMovie();
  249. pMpegMovie->SetFullScreenMode(FALSE);
  250. SetCurrentPosition(pMpegMovie->GetCurrentPosition());
  251. }
  252. g_State &= ~(fPlaying ? VCD_PLAYING : VCD_PAUSED);
  253. g_State |= VCD_STOPPED;
  254. }
  255. return TRUE;
  256. }
  257. /******************************Public*Routine******************************\
  258. * VcdPlayerPauseCmd
  259. *
  260. *
  261. *
  262. * History:
  263. * dd-mm-94 - StephenE - Created
  264. *
  265. \**************************************************************************/
  266. BOOL
  267. VcdPlayerPauseCmd(
  268. void
  269. )
  270. {
  271. BOOL fPlaying = (g_State & VCD_PLAYING);
  272. BOOL fPaused = (g_State & VCD_PAUSED);
  273. if (fPlaying) {
  274. if (pMpegMovie) {
  275. pMpegMovie->PauseMovie();
  276. SetCurrentPosition(pMpegMovie->GetCurrentPosition());
  277. }
  278. g_State &= ~VCD_PLAYING;
  279. g_State |= VCD_PAUSED;
  280. }
  281. else if (fPaused) {
  282. if (pMpegMovie) {
  283. pMpegMovie->PlayMovie();
  284. }
  285. g_State &= ~VCD_PAUSED;
  286. g_State |= VCD_PLAYING;
  287. }
  288. return TRUE;
  289. }
  290. /******************************Public*Routine******************************\
  291. * VcdPlayerSeekCmd
  292. *
  293. *
  294. *
  295. * History:
  296. * dd-mm-95 - StephenE - Created
  297. *
  298. \**************************************************************************/
  299. void
  300. VcdPlayerSeekCmd(
  301. REFTIME rtSeekBy
  302. )
  303. {
  304. REFTIME rt;
  305. REFTIME rtDur;
  306. rtDur = pMpegMovie->GetDuration();
  307. rt = pMpegMovie->GetCurrentPosition() + rtSeekBy;
  308. rt = max(0, min(rt, rtDur));
  309. pMpegMovie->SeekToPosition(rt,TRUE);
  310. SetCurrentPosition(pMpegMovie->GetCurrentPosition());
  311. }
  312. /******************************Public*Routine******************************\
  313. * ProcessOpen
  314. *
  315. *
  316. *
  317. * History:
  318. * dd-mm-95 - StephenE - Created
  319. *
  320. \**************************************************************************/
  321. void
  322. ProcessOpen(
  323. TCHAR *achFileName,
  324. BOOL bPlay
  325. )
  326. {
  327. /*
  328. ** If we currently have a video loaded we need to discard it here.
  329. */
  330. if ( g_State & VCD_LOADED) {
  331. VcdPlayerCloseCmd();
  332. }
  333. lstrcpy(g_achFileName, achFileName);
  334. pMpegMovie = new CMpegMovie(hwndApp);
  335. if (pMpegMovie) {
  336. HRESULT hr = pMpegMovie->OpenMovie(g_achFileName);
  337. if (SUCCEEDED(hr)) {
  338. TCHAR achTmp[MAX_PATH];
  339. LONG x, y, cx, cy;
  340. nRecentFiles = SetRecentFiles(achFileName, nRecentFiles);
  341. wsprintf( achTmp, IdStr(STR_APP_TITLE_LOADED),
  342. g_achFileName );
  343. g_State = (VCD_LOADED | VCD_STOPPED);
  344. if (pMpegMovie->pMpegDecoder != NULL
  345. || pMpegMovie->pVideoRenderer != NULL) {
  346. SetTimer(hwndApp, PerformanceTimer, 1000, NULL);
  347. }
  348. // SetDurationLength(pMpegMovie->GetDuration());
  349. g_TimeFormat = VcdPlayerChangeTimeFormat(g_TimeFormat);
  350. pMpegMovie->GetMoviePosition(&x, &y, &cx, &cy);
  351. pMpegMovie->PutMoviePosition(lMovieOrgX, lMovieOrgY, cx, cy);
  352. pMpegMovie->SetWindowForeground(OATRUE);
  353. // If play
  354. if (bPlay) {
  355. pMpegMovie->PlayMovie();
  356. }
  357. }
  358. else {
  359. TCHAR Buffer[MAX_ERROR_TEXT_LEN];
  360. if (GetAMErrorText(hr, Buffer, MAX_ERROR_TEXT_LEN)) {
  361. MessageBox( hwndApp, Buffer,
  362. IdStr(STR_APP_TITLE), MB_OK );
  363. }
  364. else {
  365. MessageBox( hwndApp,
  366. TEXT("Failed to open the movie; ")
  367. TEXT("either the file was not found or ")
  368. TEXT("the wave device is in use"),
  369. IdStr(STR_APP_TITLE), MB_OK );
  370. }
  371. pMpegMovie->CloseMovie();
  372. delete pMpegMovie;
  373. pMpegMovie = NULL;
  374. }
  375. }
  376. InvalidateRect( hwndApp, NULL, FALSE );
  377. UpdateWindow( hwndApp );
  378. }
  379. /******************************Public*Routine******************************\
  380. * VcdPlayerChangeTimeFormat
  381. *
  382. * Tries to change the time format to id. Returns the time format that
  383. * actually got set. This may differ from id if the graph does not support
  384. * the requested time format.
  385. *
  386. * History:
  387. * 15-04-96 - AnthonyP - Created
  388. *
  389. \**************************************************************************/
  390. int
  391. VcdPlayerChangeTimeFormat(
  392. int id
  393. )
  394. {
  395. // Menu items are disabled while we are playing
  396. BOOL bRet = FALSE;
  397. int idActual = id;
  398. ASSERT(pMpegMovie);
  399. ASSERT(pMpegMovie->StatusMovie() != MOVIE_NOTOPENED);
  400. // Change the time format with the filtergraph
  401. switch (id) {
  402. case IDM_FRAME:
  403. bRet = pMpegMovie->SetTimeFormat(TIME_FORMAT_FRAME);
  404. break;
  405. case IDM_FIELD:
  406. bRet = pMpegMovie->SetTimeFormat(TIME_FORMAT_FIELD);
  407. break;
  408. case IDM_SAMPLE:
  409. bRet = pMpegMovie->SetTimeFormat(TIME_FORMAT_SAMPLE);
  410. break;
  411. case IDM_BYTES:
  412. bRet = pMpegMovie->SetTimeFormat(TIME_FORMAT_BYTE);
  413. break;
  414. }
  415. if (!bRet) {
  416. // IDM_TIME and all other cases, everyone should support IDM_TIME
  417. bRet = pMpegMovie->SetTimeFormat(TIME_FORMAT_MEDIA_TIME);
  418. ASSERT(bRet);
  419. idActual = IDM_TIME;
  420. }
  421. // Pause the movie to get a current position
  422. SetDurationLength(pMpegMovie->GetDuration());
  423. SetCurrentPosition(pMpegMovie->GetCurrentPosition());
  424. return idActual;
  425. }
  426. const TCHAR quartzdllname[] = TEXT("quartz.dll");
  427. #ifdef UNICODE
  428. const char amgeterrorprocname[] = "AMGetErrorTextW";
  429. #else
  430. const char amgeterrorprocname[] = "AMGetErrorTextA";
  431. #endif
  432. BOOL GetAMErrorText(HRESULT hr, TCHAR *Buffer, DWORD dwLen)
  433. {
  434. HMODULE hInst = GetModuleHandle(quartzdllname);
  435. if (hInst) {
  436. AMGETERRORTEXTPROC lpProc;
  437. *((FARPROC *)&lpProc) = GetProcAddress(hInst, amgeterrorprocname);
  438. if (lpProc) {
  439. return 0 != (*lpProc)(hr, Buffer, dwLen);
  440. }
  441. }
  442. return FALSE;
  443. }