📄 videorendererrgb.cpp
字号:
}
return MP_RESULT_ERROR;
}
media_video_mode_t MediaVideoRendererRGB::GetVideoMode()
{
return this->videoMode;
}
MP_RESULT MediaVideoRendererRGB::Stop()
{
return MP_RESULT_OK;
}
RECT *MediaVideoRendererRGB::GetFullscreenRects()
{
return NULL;
}
MP_RESULT MediaVideoRendererRGB::Draw(MediaBuffer *buffer, RECT *rect, int frameNumber, int invertFlag)
{
HRESULT ddrval;
DDSURFACEDESC2 desc;
DWORD i;
subtitles_t *sub;
if(this->lpdd && this->lpddsBack && this->lpddsPrimary && buffer) {
ZeroMemory(&desc, sizeof(DDSURFACEDESC2));
desc.dwSize = sizeof(DDSURFACEDESC2);
ddrval = this->lpddsBack->Lock(NULL, &desc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WRITEONLY | DDLOCK_WAIT, NULL);
if(FAILED(ddrval)) {
return MP_RESULT_ERROR;
}
/*
* 复制象素
*/
for(i=0; i < desc.dwHeight; i++) {
memcpy((char *) desc.lpSurface + i*desc.lPitch, (char *) buffer->GetData() + (desc.dwHeight - i - 1)*this->bpp*this->width, this->width*this->bpp);
}
this->lpddsBack->Unlock(NULL);
/*
* 如果有字幕则应用
*/
if(this->subtitler) {
sub = this->subtitler->GetSubtitles(frameNumber);
if(sub != NULL) {
/*
* 显示它们
*/
HDC dc;
ddrval = this->lpddsBack->GetDC(&dc);
if(!FAILED(ddrval)) {
DWORD length, length2, length3;
SetBkMode(dc, TRANSPARENT);
switch(sub->nbSubtitles) {
case 1:
length = GetTabbedTextExtent(dc, sub->subtitlesText[0],
strlen(sub->subtitlesText[0]),
0, NULL);
SetTextColor(dc, 0);
TextOut(dc, (this->width - length)/2 + 1, this->height - 40 + 1, sub->subtitlesText[0], strlen(sub->subtitlesText[0]));
SetTextColor(dc, 0xFFFFFF);
TextOut(dc, (this->width - length)/2, this->height - 40, sub->subtitlesText[0], strlen(sub->subtitlesText[0]));
break;
case 2:
length = GetTabbedTextExtent(dc, sub->subtitlesText[0],
strlen(sub->subtitlesText[0]),
0, NULL);
length2 = GetTabbedTextExtent(dc, sub->subtitlesText[1],
strlen(sub->subtitlesText[1]),
0, NULL);
SetTextColor(dc, 0);
TextOut(dc, (this->width - length)/2 + 1, this->height - 60 + 1, sub->subtitlesText[0], strlen(sub->subtitlesText[0]));
TextOut(dc, (this->width - length2)/2 + 1, this->height - 40 + 1, sub->subtitlesText[1], strlen(sub->subtitlesText[1]));
SetTextColor(dc, 0xFFFFFF);
TextOut(dc, (this->width - length)/2, this->height - 60, sub->subtitlesText[0], strlen(sub->subtitlesText[0]));
TextOut(dc, (this->width - length2)/2, this->height - 40, sub->subtitlesText[1], strlen(sub->subtitlesText[1]));
break;
case 3:
length = GetTabbedTextExtent(dc, sub->subtitlesText[0],
strlen(sub->subtitlesText[0]),
0, NULL);
length2 = GetTabbedTextExtent(dc, sub->subtitlesText[1],
strlen(sub->subtitlesText[1]),
0, NULL);
length3 = GetTabbedTextExtent(dc, sub->subtitlesText[2],
strlen(sub->subtitlesText[2]),
0, NULL);
SetTextColor(dc, 0);
TextOut(dc, (this->width - length)/2 + 1, this->height - 80 + 1, sub->subtitlesText[0], strlen(sub->subtitlesText[0]));
TextOut(dc, (this->width - length2)/2 + 1, this->height - 60 + 1, sub->subtitlesText[1], strlen(sub->subtitlesText[1]));
TextOut(dc, (this->width - length3)/2 + 1, this->height - 40 + 1, sub->subtitlesText[2], strlen(sub->subtitlesText[2]));
SetTextColor(dc, 0xFFFFFF);
TextOut(dc, (this->width - length)/2, this->height - 80, sub->subtitlesText[0], strlen(sub->subtitlesText[0]));
TextOut(dc, (this->width - length2)/2, this->height - 60, sub->subtitlesText[1], strlen(sub->subtitlesText[1]));
TextOut(dc, (this->width - length3)/2, this->height - 40, sub->subtitlesText[2], strlen(sub->subtitlesText[2]));
break;
}
this->lpddsBack->ReleaseDC(dc);
}
}
}
/*
* 复制到窗口
*/
if(this->hwndPlayback) {
RECT rcRect;
RECT destRect;
POINT pt;
rcRect.left = 0;
rcRect.top = 0;
rcRect.right = this->width;
rcRect.bottom = this->height;
GetClientRect( this->hwndPlayback, &destRect );
/*
* 压缩rect以便放置控件
*/
destRect.left += rect->left;
destRect.right = rect->left + rect->right;
destRect.top += rect->top;
destRect.bottom = rect->bottom;
pt.x = pt.y = 0;
ClientToScreen( this->hwndPlayback, &pt );
OffsetRect(&destRect, pt.x, pt.y);
while( 1 )
{
ddrval = this->lpddsPrimary->Blt( &destRect, this->lpddsBack, &rcRect, DDBLT_ASYNC | DDBLT_WAIT, NULL);
if( ddrval == DD_OK )
{
break;
}
if( ddrval == DDERR_SURFACELOST )
{
if(!this->lpdd->RestoreAllSurfaces())
{
return MP_RESULT_ERROR;
}
}
if( ddrval != DDERR_WASSTILLDRAWING )
{
return MP_RESULT_ERROR;
}
}
if(ddrval != DD_OK)
{
return MP_RESULT_ERROR;
}
return MP_RESULT_OK;
}
}
return MP_RESULT_ERROR;
}
MP_RESULT MediaVideoRendererRGB::DrawFullscreen(MediaBuffer *buffer, int frameNumber, int invertFlag, int desktop)
{
DDSURFACEDESC2 desc;
DWORD i;
HRESULT ddrval;
subtitles_t *sub;
if(buffer && this->lpdd && this->lpddsPrimary) {
ZeroMemory(&desc, sizeof(DDSURFACEDESC2));
desc.dwSize = sizeof(DDSURFACEDESC2);
this->lpddsBack->Lock(NULL, &desc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WRITEONLY | DDLOCK_WAIT, NULL);
for(i=0; i < desc.dwHeight; i++) {
memcpy((char *) desc.lpSurface + i*desc.lPitch, (char *) buffer->GetData() + (desc.dwHeight - i - 1)*this->bpp*this->width, this->width*this->bpp);
}
this->lpddsBack->Unlock(NULL);
/*
* 字幕
*/
if(this->subtitler) {
sub = this->subtitler->GetSubtitles(frameNumber);
if(sub != NULL) {
/*
* 显示
*/
HDC dc;
ddrval = this->lpddsBack->GetDC(&dc);
if(!FAILED(ddrval)) {
DWORD length, length2, length3;
SetBkMode(dc, TRANSPARENT);
switch(sub->nbSubtitles) {
case 1:
length = GetTabbedTextExtent(dc, sub->subtitlesText[0],
strlen(sub->subtitlesText[0]),
0, NULL);
SetTextColor(dc, 0);
TextOut(dc, (this->width - length)/2 + 1, this->height - 40 + 1, sub->subtitlesText[0], strlen(sub->subtitlesText[0]));
SetTextColor(dc, 0xFFFFFF);
TextOut(dc, (this->width - length)/2, this->height - 40, sub->subtitlesText[0], strlen(sub->subtitlesText[0]));
break;
case 2:
length = GetTabbedTextExtent(dc, sub->subtitlesText[0],
strlen(sub->subtitlesText[0]),
0, NULL);
length2 = GetTabbedTextExtent(dc, sub->subtitlesText[1],
strlen(sub->subtitlesText[1]),
0, NULL);
SetTextColor(dc, 0);
TextOut(dc, (this->width - length)/2 + 1, this->height - 60 + 1, sub->subtitlesText[0], strlen(sub->subtitlesText[0]));
TextOut(dc, (this->width - length2)/2 + 1, this->height - 40 + 1, sub->subtitlesText[1], strlen(sub->subtitlesText[1]));
SetTextColor(dc, 0xFFFFFF);
TextOut(dc, (this->width - length)/2, this->height - 60, sub->subtitlesText[0], strlen(sub->subtitlesText[0]));
TextOut(dc, (this->width - length2)/2, this->height - 40, sub->subtitlesText[1], strlen(sub->subtitlesText[1]));
break;
case 3:
length = GetTabbedTextExtent(dc, sub->subtitlesText[0],
strlen(sub->subtitlesText[0]),
0, NULL);
length2 = GetTabbedTextExtent(dc, sub->subtitlesText[1],
strlen(sub->subtitlesText[1]),
0, NULL);
length3 = GetTabbedTextExtent(dc, sub->subtitlesText[2],
strlen(sub->subtitlesText[2]),
0, NULL);
SetTextColor(dc, 0);
TextOut(dc, (this->width - length)/2 + 1, this->height - 80 + 1, sub->subtitlesText[0], strlen(sub->subtitlesText[0]));
TextOut(dc, (this->width - length2)/2 + 1, this->height - 60 + 1, sub->subtitlesText[1], strlen(sub->subtitlesText[1]));
TextOut(dc, (this->width - length3)/2 + 1, this->height - 40 + 1, sub->subtitlesText[2], strlen(sub->subtitlesText[2]));
SetTextColor(dc, 0xFFFFFF);
TextOut(dc, (this->width - length)/2, this->height - 80, sub->subtitlesText[0], strlen(sub->subtitlesText[0]));
TextOut(dc, (this->width - length2)/2, this->height - 60, sub->subtitlesText[1], strlen(sub->subtitlesText[1]));
TextOut(dc, (this->width - length3)/2, this->height - 40, sub->subtitlesText[2], strlen(sub->subtitlesText[2]));
break;
}
this->lpddsBack->ReleaseDC(dc);
}
}
}
/*
* 清除后缓冲
*
*/
/*
* 复制到后缓冲
*/
RECT rcRect, dst;
rcRect.left = 0;
rcRect.top = 0;
rcRect.right = this->width;
rcRect.bottom = this->height;
DWORD height;
DWORD width;
switch(options.aspect_ratio) {
case ASPECT_RATIO_FREE:
case ASPECT_RATIO_ORIGINAL:
width = this->width;
height = this->height;
break;
case ASPECT_RATIO_TV:
case ASPECT_RATIO_WIDE:
case ASPECT_RATIO_CUSTOM:
if(aspectRatios[options.aspect_ratio].yFactor < aspectRatios[options.aspect_ratio].xFactor) {
width = this->width;
height = this->width*aspectRatios[options.aspect_ratio].yFactor/aspectRatios[options.aspect_ratio].xFactor;
}
else {
height = this->height;
width = this->height*aspectRatios[options.aspect_ratio].xFactor/aspectRatios[options.aspect_ratio].yFactor;
}
break;
}
if(this->fullscreenWidth * height / width > this->fullscreenHeight) {
dst.left = (this->fullscreenWidth - (this->fullscreenHeight * width / height)) / 2;
dst.top = 0;
dst.right = dst.left + (this->fullscreenHeight * width / height);
dst.bottom = this->fullscreenHeight;
}
else {
dst.left = 0;
dst.top = (this->fullscreenHeight - (this->fullscreenWidth * height / width))/2;
dst.right = this->fullscreenWidth;
dst.bottom = (this->fullscreenHeight - (this->fullscreenWidth * height / width))/2 + (this->fullscreenWidth * height / width);
}
ddrval = this->lpddsPrimary->Blt( &dst, this->lpddsBack, &rcRect, DDBLT_ASYNC, NULL);
return MP_RESULT_OK;
}
return MP_RESULT_ERROR;
}
MP_RESULT MediaVideoRendererRGB::Close()
{
if(this->lpdd) {
this->lpdd->RestoreDisplayMode();
this->lpdd->SetCooperativeLevel(this->hwndPlayback, DDSCL_NORMAL);
}
if(this->lpddsBack) {
this->lpddsBack->Release();
this->lpddsBack = NULL;
}
if(this->lpddsPrimary) {
this->lpddsPrimary->Release();
this->lpddsPrimary = NULL;
}
if(this->lpdd) {
this->lpdd->Release();
this->lpdd = NULL;
}
return MP_RESULT_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -