VideoRendererRGB.cpp
上传用户:tuheem
上传日期:2007-05-01
资源大小:21889k
文件大小:18k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. /**************************************************************************************
  2.  *                                                                                    *
  3.  *                                                                                    *
  4.  **************************************************************************************/
  5. #include "VideoRendererRGB.h"
  6. /*
  7.  * 包括直接显示
  8.  *
  9.  */
  10. #include <ddraw.h>
  11. /*
  12.  * RGB视频补偿类
  13.  */
  14. MediaVideoRendererRGB::MediaVideoRendererRGB()
  15. {
  16. this->subtitler    = NULL;
  17. this->lpdd         = NULL;
  18. this->lpddClipper  = NULL;
  19. this->lpddsPrimary = NULL;
  20. this->lpddsBack    = NULL;
  21. this->bpp          = 0;
  22. this->videoMode    = VIDEO_MODE_NONE;
  23. }
  24. MediaVideoRendererRGB::~MediaVideoRendererRGB()
  25. {
  26. }
  27. /*
  28.  * 媒体项方法
  29.  */
  30. media_type_t  MediaVideoRendererRGB::GetType()
  31. {
  32. return MEDIA_TYPE_VIDEO_RENDERER;
  33. }
  34. char         *MediaVideoRendererRGB::GetName()
  35. {
  36. return "Standard RGB Video Renderer";
  37. }
  38. MP_RESULT MediaVideoRendererRGB::Connect(MediaItem *item)
  39. {
  40. /*
  41.  * 只接受字幕
  42.  *
  43.  */
  44. if(item && item->GetType() == MEDIA_TYPE_SUBTITLER) {
  45. /*
  46.  * 接受字幕源
  47.  */
  48. this->subtitler = (MediaItemSubtitler *) item;
  49. return MP_RESULT_OK;
  50. }
  51. return MP_RESULT_ERROR;
  52. }
  53. MP_RESULT MediaVideoRendererRGB::ReleaseConnections()
  54. {
  55. if(this->subtitler)
  56. this->subtitler = NULL;
  57. return MP_RESULT_OK;
  58. }
  59. DWORD         MediaVideoRendererRGB::GetCaps()
  60. {
  61. return 0;
  62. }
  63. MP_RESULT     MediaVideoRendererRGB::Configure(HINSTANCE hInstance, HWND hwnd)
  64. {
  65. return MP_RESULT_ERROR;
  66. }
  67. /*
  68.  * 视频补偿方法
  69.  */
  70. MP_RESULT MediaVideoRendererRGB::Init(HWND hwnd, unsigned int width, unsigned int height)
  71. {
  72. HRESULT        ddrval;
  73. DDSURFACEDESC2 ddsd;
  74. if(hwnd && width > 0 && height > 0) {
  75. /*
  76.  * 产生主要的直接显示对象
  77.  */
  78. ddrval = DirectDrawCreateEx(NULL, (void **) &this->lpdd, IID_IDirectDraw7, NULL);
  79. if(FAILED(ddrval)) {
  80. return MP_RESULT_ERROR;
  81. }
  82. ddrval = lpdd->SetCooperativeLevel(hwnd, DDSCL_NORMAL);
  83. if(FAILED(ddrval)) {
  84. this->lpdd->Release();
  85. this->lpdd = NULL;
  86. return MP_RESULT_ERROR;
  87. }
  88. /*
  89.  * 产生主界面Create the primary surface
  90.  */
  91. memset( &ddsd, 0, sizeof(ddsd) );
  92.     ddsd.dwSize     = sizeof( ddsd );
  93.     ddsd.dwFlags           = DDSD_CAPS;
  94. ddsd.ddsCaps.dwCaps    = DDSCAPS_PRIMARYSURFACE | DDSCAPS_VIDEOMEMORY;
  95.     ddrval = this->lpdd->CreateSurface(&ddsd, &this->lpddsPrimary, NULL);
  96. if(FAILED(ddrval)) {
  97. this->lpdd->Release();
  98. this->lpdd = NULL;
  99. return MP_RESULT_ERROR;
  100. }
  101. /*
  102.  * 设置剪辑
  103.  */
  104. ddrval = this->lpdd->CreateClipper(0, &this->lpddClipper, NULL);
  105. if(FAILED(ddrval)) {
  106. this->lpddsPrimary->Release();
  107. this->lpddsPrimary = NULL;
  108. this->lpdd->Release();
  109. this->lpdd = NULL;
  110. return MP_RESULT_ERROR;
  111. }
  112.     ddrval = this->lpddClipper->SetHWnd(0, hwnd);
  113.     if(FAILED(ddrval)) {
  114. this->lpddsPrimary->Release();
  115. this->lpddsPrimary = NULL;
  116. this->lpdd->Release();
  117. this->lpdd = NULL;
  118. return MP_RESULT_ERROR;
  119. }
  120. ddrval = this->lpddsPrimary->SetClipper(this->lpddClipper);
  121. if(ddrval != DD_OK) {
  122. this->lpddsPrimary->Release();
  123. this->lpddsPrimary = NULL;
  124. this->lpdd->Release();
  125. this->lpdd = NULL;
  126. return MP_RESULT_ERROR;
  127. }
  128. /*
  129.  * 最后产生背景Finally Create Back Surface
  130.  */
  131. ZeroMemory(&ddsd, sizeof(ddsd));
  132.      ddsd.dwSize     = sizeof(ddsd);
  133. ddsd.dwFlags        = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
  134. ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
  135. ddsd.dwWidth  = width;
  136. ddsd.dwHeight = height;
  137. if(this->lpdd->CreateSurface(&ddsd, &this->lpddsBack, NULL) != DD_OK) {
  138. this->lpddsPrimary->Release();
  139. this->lpddsPrimary = NULL;
  140. this->lpdd->Release();
  141. this->lpdd = NULL;
  142. return MP_RESULT_ERROR;
  143. }
  144. this->width  = width;
  145. this->height = height;
  146. this->hwndPlayback = hwnd;
  147. /*
  148.  * 获取视频模式
  149.  */
  150. ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
  151. ddsd.dwSize     = sizeof(DDSURFACEDESC2);
  152. ddrval = this->lpddsBack->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WRITEONLY | DDLOCK_WAIT, NULL);
  153. if(FAILED(ddrval)) {
  154. return MP_RESULT_ERROR;
  155. }
  156. this->lpddsBack->Unlock(NULL);
  157. switch(ddsd.ddpfPixelFormat.dwRGBBitCount) {
  158. case 8:
  159. return MP_RESULT_ERROR;
  160. break;
  161. case 16:
  162. this->bpp       = 2;
  163. this->videoMode = VIDEO_MODE_RGB16;
  164. break;
  165. case 24:
  166. this->bpp       = 3;
  167. this->videoMode = VIDEO_MODE_RGB24;
  168. break;
  169. case 32:
  170. this->bpp       = 4;
  171. this->videoMode = VIDEO_MODE_RGB32;
  172. break;
  173. }
  174. return MP_RESULT_OK;
  175. }
  176. return MP_RESULT_ERROR;
  177. }
  178. /*
  179.  * 为全屏显示初始化补偿器
  180.  */
  181. MP_RESULT MediaVideoRendererRGB::InitFullscreen(HWND hwnd, unsigned int width, unsigned int height)
  182. {
  183. if(hwnd && width > 0 && height > 0) {
  184. HRESULT         ddrval;
  185.     DDSURFACEDESC2  ddsd;
  186.     
  187.     ddrval = DirectDrawCreateEx(NULL, (VOID**)&this->lpdd, IID_IDirectDraw7, NULL);
  188. if( FAILED(ddrval))
  189. return MP_RESULT_ERROR;
  190.     
  191.     /*
  192.      * 设置独占的合作模式Set Exclusive Cooperative Mode
  193.      */
  194. ddrval = this->lpdd->SetCooperativeLevel(hwnd, DDSCL_NORMAL); //DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
  195. if( FAILED(ddrval)) {
  196.         this->lpdd->Release();
  197. this->lpdd = NULL;
  198. return MP_RESULT_ERROR;
  199. }
  200. /*
  201.  * 全屏
  202.  *
  203.  */
  204. DDSURFACEDESC2 ddDesc;
  205. memset(&ddDesc, 0, sizeof(DDSURFACEDESC2));
  206. ddDesc.dwSize    = sizeof(DDSURFACEDESC2);
  207. ddrval = this->lpdd->GetDisplayMode(&ddDesc);
  208. if(FAILED(ddrval)) {
  209.         this->lpdd->Release();
  210. this->lpdd=NULL;
  211. return MP_RESULT_ERROR;;
  212. }
  213. /*
  214.  * 存贮全屏模式
  215.  */
  216. this->fullscreenWidth  = ddDesc.dwWidth;
  217. this->fullscreenHeight = ddDesc.dwHeight;
  218. this->fullscreenVideoHeight = height * this->fullscreenWidth / width;
  219. /*
  220.  * 产生主界面
  221.  */
  222.    
  223.     ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
  224. ddsd.dwSize  = sizeof(DDSURFACEDESC2);
  225. ddsd.dwFlags = DDSD_CAPS;
  226. ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_VIDEOMEMORY; 
  227.     
  228. ddrval = this->lpdd->CreateSurface(&ddsd, &this->lpddsPrimary, NULL );
  229. if(FAILED(ddrval)) {
  230.         this->lpdd->Release();
  231. this->lpdd=NULL;
  232. return MP_RESULT_ERROR;;
  233. }
  234. /*
  235.  * 得到后缓冲
  236.  *
  237.  */
  238. ZeroMemory(&ddsd, sizeof(ddsd));
  239.      ddsd.dwSize     = sizeof(ddsd);
  240. ddsd.dwFlags        = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
  241. ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
  242. ddsd.dwWidth  = width;
  243. ddsd.dwHeight = height;
  244. if(this->lpdd->CreateSurface(&ddsd, &this->lpddsBack, NULL) != DD_OK) {
  245. this->lpddsPrimary->Release();
  246. this->lpddsPrimary = NULL;
  247. this->lpdd->Release();
  248. this->lpdd = NULL;
  249. return MP_RESULT_ERROR;
  250. }
  251. /*
  252.  * 为防止叠加继续停留在顶部产生一个剪辑
  253.  */
  254.     ddrval = this->lpdd->CreateClipper(0, &this->lpddClipper, NULL);
  255. if(FAILED(ddrval)) {
  256. return MP_RESULT_ERROR;
  257. }
  258.     ddrval = this->lpddClipper->SetHWnd(0, hwnd);
  259. if(FAILED(ddrval)) {
  260. return MP_RESULT_ERROR;
  261. }
  262.     ddrval = this->lpddsPrimary->SetClipper(this->lpddClipper);
  263. if(FAILED(ddrval)) {
  264. return MP_RESULT_ERROR;
  265. }
  266. /*
  267.  * 停止主的Black out the primary
  268.  */
  269. this->width  = width;
  270. this->height = height;
  271. this->hwndPlayback = hwnd;
  272. return MP_RESULT_OK;
  273. }
  274.     
  275. return MP_RESULT_ERROR;
  276. }
  277. media_video_mode_t MediaVideoRendererRGB::GetVideoMode()
  278. {
  279. return this->videoMode;
  280. }
  281. MP_RESULT MediaVideoRendererRGB::Stop()
  282. {
  283. return MP_RESULT_OK;
  284. }
  285. RECT *MediaVideoRendererRGB::GetFullscreenRects()
  286. {
  287. return NULL;
  288. }
  289. MP_RESULT MediaVideoRendererRGB::Draw(MediaBuffer *buffer, RECT *rect, int frameNumber, int invertFlag)
  290. {
  291. HRESULT        ddrval;
  292. DDSURFACEDESC2 desc;
  293. DWORD          i;
  294. subtitles_t   *sub;
  295. if(this->lpdd && this->lpddsBack && this->lpddsPrimary && buffer) {
  296. ZeroMemory(&desc, sizeof(DDSURFACEDESC2));
  297. desc.dwSize     = sizeof(DDSURFACEDESC2);
  298. ddrval = this->lpddsBack->Lock(NULL, &desc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WRITEONLY | DDLOCK_WAIT, NULL);
  299. if(FAILED(ddrval)) {
  300. return MP_RESULT_ERROR;
  301. }
  302. /*
  303.  * 复制象素
  304.  */
  305. for(i=0; i < desc.dwHeight; i++) {
  306. memcpy((char *) desc.lpSurface + i*desc.lPitch, (char *) buffer->GetData() + (desc.dwHeight - i - 1)*this->bpp*this->width, this->width*this->bpp);
  307. }
  308. this->lpddsBack->Unlock(NULL);
  309. /*
  310.  * 如果有字幕则应用
  311.  */
  312. if(this->subtitler) {
  313. sub = this->subtitler->GetSubtitles(frameNumber);
  314. if(sub != NULL) {
  315. /*
  316.  * 显示它们
  317.  */
  318. HDC dc;
  319. ddrval = this->lpddsBack->GetDC(&dc);
  320. if(!FAILED(ddrval)) {
  321. DWORD length, length2, length3;
  322. SetBkMode(dc, TRANSPARENT);
  323. switch(sub->nbSubtitles) {
  324. case 1:
  325. length = GetTabbedTextExtent(dc, sub->subtitlesText[0], 
  326.  strlen(sub->subtitlesText[0]),
  327.  0, NULL);
  328. SetTextColor(dc, 0);
  329. TextOut(dc, (this->width - length)/2 + 1, this->height - 40 + 1, sub->subtitlesText[0], strlen(sub->subtitlesText[0]));
  330. SetTextColor(dc, 0xFFFFFF);
  331. TextOut(dc, (this->width - length)/2, this->height - 40, sub->subtitlesText[0], strlen(sub->subtitlesText[0]));
  332. break;
  333. case 2:
  334. length = GetTabbedTextExtent(dc, sub->subtitlesText[0], 
  335.  strlen(sub->subtitlesText[0]),
  336.  0, NULL);
  337. length2 = GetTabbedTextExtent(dc, sub->subtitlesText[1], 
  338.  strlen(sub->subtitlesText[1]),
  339.  0, NULL);
  340. SetTextColor(dc, 0);
  341. TextOut(dc, (this->width - length)/2 + 1, this->height - 60 + 1, sub->subtitlesText[0], strlen(sub->subtitlesText[0]));
  342. TextOut(dc, (this->width - length2)/2 + 1, this->height - 40 + 1, sub->subtitlesText[1], strlen(sub->subtitlesText[1]));
  343. SetTextColor(dc, 0xFFFFFF);
  344. TextOut(dc, (this->width - length)/2, this->height - 60, sub->subtitlesText[0], strlen(sub->subtitlesText[0]));
  345. TextOut(dc, (this->width - length2)/2, this->height - 40, sub->subtitlesText[1], strlen(sub->subtitlesText[1]));
  346. break;
  347. case 3:
  348. length = GetTabbedTextExtent(dc, sub->subtitlesText[0], 
  349.  strlen(sub->subtitlesText[0]),
  350.  0, NULL);
  351. length2 = GetTabbedTextExtent(dc, sub->subtitlesText[1], 
  352.  strlen(sub->subtitlesText[1]),
  353.  0, NULL);
  354. length3 = GetTabbedTextExtent(dc, sub->subtitlesText[2], 
  355.  strlen(sub->subtitlesText[2]),
  356.  0, NULL);
  357. SetTextColor(dc, 0);
  358. TextOut(dc, (this->width - length)/2 + 1, this->height - 80 + 1, sub->subtitlesText[0], strlen(sub->subtitlesText[0]));
  359. TextOut(dc, (this->width - length2)/2 + 1, this->height - 60 + 1, sub->subtitlesText[1], strlen(sub->subtitlesText[1]));
  360. TextOut(dc, (this->width - length3)/2 + 1, this->height - 40 + 1, sub->subtitlesText[2], strlen(sub->subtitlesText[2]));
  361. SetTextColor(dc, 0xFFFFFF);
  362. TextOut(dc, (this->width - length)/2, this->height - 80, sub->subtitlesText[0], strlen(sub->subtitlesText[0]));
  363. TextOut(dc, (this->width - length2)/2, this->height - 60, sub->subtitlesText[1], strlen(sub->subtitlesText[1]));
  364. TextOut(dc, (this->width - length3)/2, this->height - 40, sub->subtitlesText[2], strlen(sub->subtitlesText[2]));
  365. break;
  366. }
  367. this->lpddsBack->ReleaseDC(dc);
  368. }
  369. }
  370. }
  371. /*
  372.  * 复制到窗口
  373.  */
  374. if(this->hwndPlayback) {
  375. RECT                rcRect;
  376. RECT                destRect;
  377. POINT               pt;
  378.         rcRect.left   = 0;
  379.     rcRect.top    = 0;
  380. rcRect.right  = this->width;
  381. rcRect.bottom = this->height;
  382. GetClientRect( this->hwndPlayback, &destRect );
  383. /*
  384.  * 压缩rect以便放置控件
  385.  */
  386. destRect.left   += rect->left;
  387. destRect.right  =  rect->left + rect->right;
  388. destRect.top    += rect->top;
  389. destRect.bottom  = rect->bottom;
  390. pt.x = pt.y = 0;
  391. ClientToScreen( this->hwndPlayback, &pt );
  392. OffsetRect(&destRect, pt.x, pt.y);
  393. while( 1 )
  394. {
  395. ddrval = this->lpddsPrimary->Blt( &destRect, this->lpddsBack, &rcRect, DDBLT_ASYNC | DDBLT_WAIT, NULL);
  396. if( ddrval == DD_OK )
  397. {
  398. break;
  399. }
  400. if( ddrval == DDERR_SURFACELOST )
  401. {
  402. if(!this->lpdd->RestoreAllSurfaces())
  403. {
  404. return MP_RESULT_ERROR;
  405. }
  406. }
  407. if( ddrval != DDERR_WASSTILLDRAWING )
  408. {
  409. return MP_RESULT_ERROR;
  410. }
  411. }
  412. if(ddrval != DD_OK)
  413. {
  414. return MP_RESULT_ERROR;
  415. }
  416. return MP_RESULT_OK;
  417. }
  418. }
  419. return MP_RESULT_ERROR;
  420. }
  421. MP_RESULT MediaVideoRendererRGB::DrawFullscreen(MediaBuffer *buffer, int frameNumber, int invertFlag, int desktop)
  422. {
  423. DDSURFACEDESC2 desc;
  424. DWORD          i;
  425. HRESULT        ddrval;
  426. subtitles_t   *sub;
  427. if(buffer && this->lpdd && this->lpddsPrimary) {
  428. ZeroMemory(&desc, sizeof(DDSURFACEDESC2));
  429. desc.dwSize = sizeof(DDSURFACEDESC2);
  430. this->lpddsBack->Lock(NULL, &desc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WRITEONLY | DDLOCK_WAIT, NULL);
  431. for(i=0; i < desc.dwHeight; i++) {
  432. memcpy((char *) desc.lpSurface + i*desc.lPitch, (char *) buffer->GetData() + (desc.dwHeight - i - 1)*this->bpp*this->width, this->width*this->bpp);
  433. }
  434. this->lpddsBack->Unlock(NULL);
  435. /*
  436.  * 字幕
  437.  */
  438. if(this->subtitler) {
  439. sub = this->subtitler->GetSubtitles(frameNumber);
  440. if(sub != NULL) {
  441. /*
  442.  * 显示
  443.  */
  444. HDC dc;
  445. ddrval = this->lpddsBack->GetDC(&dc);
  446. if(!FAILED(ddrval)) {
  447. DWORD length, length2, length3;
  448. SetBkMode(dc, TRANSPARENT);
  449. switch(sub->nbSubtitles) {
  450. case 1:
  451. length = GetTabbedTextExtent(dc, sub->subtitlesText[0], 
  452.  strlen(sub->subtitlesText[0]),
  453.  0, NULL);
  454. SetTextColor(dc, 0);
  455. TextOut(dc, (this->width - length)/2 + 1, this->height - 40 + 1, sub->subtitlesText[0], strlen(sub->subtitlesText[0]));
  456. SetTextColor(dc, 0xFFFFFF);
  457. TextOut(dc, (this->width - length)/2, this->height - 40, sub->subtitlesText[0], strlen(sub->subtitlesText[0]));
  458. break;
  459. case 2:
  460. length = GetTabbedTextExtent(dc, sub->subtitlesText[0], 
  461.  strlen(sub->subtitlesText[0]),
  462.  0, NULL);
  463. length2 = GetTabbedTextExtent(dc, sub->subtitlesText[1], 
  464.  strlen(sub->subtitlesText[1]),
  465.  0, NULL);
  466. SetTextColor(dc, 0);
  467. TextOut(dc, (this->width - length)/2 + 1, this->height - 60 + 1, sub->subtitlesText[0], strlen(sub->subtitlesText[0]));
  468. TextOut(dc, (this->width - length2)/2 + 1, this->height - 40 + 1, sub->subtitlesText[1], strlen(sub->subtitlesText[1]));
  469. SetTextColor(dc, 0xFFFFFF);
  470. TextOut(dc, (this->width - length)/2, this->height - 60, sub->subtitlesText[0], strlen(sub->subtitlesText[0]));
  471. TextOut(dc, (this->width - length2)/2, this->height - 40, sub->subtitlesText[1], strlen(sub->subtitlesText[1]));
  472. break;
  473. case 3:
  474. length = GetTabbedTextExtent(dc, sub->subtitlesText[0], 
  475.  strlen(sub->subtitlesText[0]),
  476.  0, NULL);
  477. length2 = GetTabbedTextExtent(dc, sub->subtitlesText[1], 
  478.  strlen(sub->subtitlesText[1]),
  479.  0, NULL);
  480. length3 = GetTabbedTextExtent(dc, sub->subtitlesText[2], 
  481.  strlen(sub->subtitlesText[2]),
  482.  0, NULL);
  483. SetTextColor(dc, 0);
  484. TextOut(dc, (this->width - length)/2 + 1, this->height - 80 + 1, sub->subtitlesText[0], strlen(sub->subtitlesText[0]));
  485. TextOut(dc, (this->width - length2)/2 + 1, this->height - 60 + 1, sub->subtitlesText[1], strlen(sub->subtitlesText[1]));
  486. TextOut(dc, (this->width - length3)/2 + 1, this->height - 40 + 1, sub->subtitlesText[2], strlen(sub->subtitlesText[2]));
  487. SetTextColor(dc, 0xFFFFFF);
  488. TextOut(dc, (this->width - length)/2, this->height - 80, sub->subtitlesText[0], strlen(sub->subtitlesText[0]));
  489. TextOut(dc, (this->width - length2)/2, this->height - 60, sub->subtitlesText[1], strlen(sub->subtitlesText[1]));
  490. TextOut(dc, (this->width - length3)/2, this->height - 40, sub->subtitlesText[2], strlen(sub->subtitlesText[2]));
  491. break;
  492. }
  493. this->lpddsBack->ReleaseDC(dc);
  494. }
  495. }
  496. }
  497. /*
  498.  * 清除后缓冲
  499.  *
  500.  */
  501. /*
  502.  * 复制到后缓冲
  503.  */
  504. RECT rcRect, dst;
  505. rcRect.left   = 0;
  506. rcRect.top    = 0;
  507. rcRect.right  = this->width;
  508. rcRect.bottom = this->height;
  509. DWORD height;
  510. DWORD width;
  511. switch(options.aspect_ratio) {
  512. case ASPECT_RATIO_FREE:
  513. case ASPECT_RATIO_ORIGINAL:
  514. width  = this->width;
  515. height = this->height;
  516. break;
  517. case ASPECT_RATIO_TV:
  518. case ASPECT_RATIO_WIDE:
  519. case ASPECT_RATIO_CUSTOM:
  520. if(aspectRatios[options.aspect_ratio].yFactor < aspectRatios[options.aspect_ratio].xFactor) {
  521. width  = this->width;
  522. height = this->width*aspectRatios[options.aspect_ratio].yFactor/aspectRatios[options.aspect_ratio].xFactor;
  523. }
  524. else {
  525. height = this->height;
  526. width  = this->height*aspectRatios[options.aspect_ratio].xFactor/aspectRatios[options.aspect_ratio].yFactor;
  527. }
  528. break;
  529. }
  530. if(this->fullscreenWidth * height / width > this->fullscreenHeight) {
  531.     dst.left   = (this->fullscreenWidth - (this->fullscreenHeight * width / height)) / 2; 
  532. dst.top    = 0; 
  533. dst.right  = dst.left + (this->fullscreenHeight * width / height);
  534. dst.bottom = this->fullscreenHeight; 
  535. }
  536. else {
  537. dst.left   = 0;
  538. dst.top    = (this->fullscreenHeight - (this->fullscreenWidth * height / width))/2;
  539. dst.right  = this->fullscreenWidth;
  540. dst.bottom = (this->fullscreenHeight - (this->fullscreenWidth * height / width))/2 + (this->fullscreenWidth * height / width);
  541. }
  542. ddrval = this->lpddsPrimary->Blt( &dst, this->lpddsBack, &rcRect, DDBLT_ASYNC, NULL);
  543. return MP_RESULT_OK;
  544. }
  545. return MP_RESULT_ERROR;
  546. }
  547. MP_RESULT MediaVideoRendererRGB::Close()
  548. {
  549. if(this->lpdd) {
  550. this->lpdd->RestoreDisplayMode();
  551. this->lpdd->SetCooperativeLevel(this->hwndPlayback, DDSCL_NORMAL);
  552. }
  553. if(this->lpddsBack) {
  554. this->lpddsBack->Release();
  555. this->lpddsBack = NULL;
  556. }
  557. if(this->lpddsPrimary) {
  558. this->lpddsPrimary->Release();
  559. this->lpddsPrimary = NULL;
  560. }
  561. if(this->lpdd) {
  562. this->lpdd->Release();
  563. this->lpdd = NULL;
  564. }
  565. return MP_RESULT_OK;
  566. }