Mercurial > mm7
diff VideoPlayer.cpp @ 2137:d24ee391fd1f
libavcodec playing movies and houses, loops not working yet
author | zipi |
---|---|
date | Wed, 01 Jan 2014 13:43:09 +0000 |
parents | 992d2e6f907d |
children | ca548138d6aa |
line wrap: on
line diff
--- a/VideoPlayer.cpp Tue Dec 31 23:03:01 2013 +0600 +++ b/VideoPlayer.cpp Wed Jan 01 13:43:09 2014 +0000 @@ -301,7 +301,7 @@ if (!bNoVideo) { pRenderer->PresentBlackScreen(); - //PlayFullscreenMovie(MOVIE_3DOLogo, true); + PlayFullscreenMovie(MOVIE_3DOLogo, true); //pGame->pCShow->PlayMovie(MOVIE_3DOLogo, 1); if ( !pVideoPlayer->bStopBeforeSchedule ) { @@ -342,16 +342,13 @@ bGameoverLoop = 0; } - - - //----- (004BE70E) -------------------------------------------------------- void VideoPlayer::MovieLoop(const char *pMovieName, int a2, int ScreenSizeFlag, int a4) { int v4; // ebp@1 const char *pName; // edi@1 MSG Msg; // [sp+Ch] [bp-1Ch]@12 - + v4 = a2; pName = pMovieName; if ( !(dword_6BE364_game_settings_1 & (GAME_SETTINGS_NO_HOUSE_ANIM | GAME_SETTINGS_NO_INTRO)) ) @@ -361,7 +358,7 @@ ShowCursor(0); pVideoPlayer->OpenGlobalMovie(pName, 0, ScreenSizeFlag); pVideoPlayer->bPlayingMovie = 1; - pVideoPlayer->field_44 = v4; + pVideoPlayer->field_44 = v4; if ( pRenderer->pRenderD3D ) { pRenderer->ClearTarget(0); @@ -373,63 +370,105 @@ pRenderer->EndScene(); } pCurrentScreen = SCREEN_VIDEO; + + auto hwnd = pVideoPlayer->window->GetApiHandle(); + RECT rc_client; + GetClientRect(hwnd, &rc_client); + int client_width = rc_client.right - rc_client.left, + client_height = rc_client.bottom - rc_client.top; + + HDC dc = GetDC(hwnd); + HDC back_dc = CreateCompatibleDC(dc); + HBITMAP back_bmp; + SelectObject(back_dc, back_bmp = CreateCompatibleBitmap(dc, client_width, client_height)); + + while (true) + { + if ( pVideoPlayer->bStopBeforeSchedule ) + break; + while (PeekMessageA(&Msg, hwnd, 0, 0, PM_REMOVE)) + { + if (Msg.message == 18) + Game_DeinitializeAndTerminate(0); + if (Msg.message == 15) + break; + TranslateMessage(&Msg); + DispatchMessageA(&Msg); + } + GUI_MainMenuMessageProc(); + + if (!pVideoPlayer->mMovie) + { + pVideoPlayer->mMovie = pVideoPlayer->mPlayer->LoadMovie("dummyFilename", client_width, client_height); + } + else if (pVideoPlayer->mMovie->Stopped()) + break; + auto image = pVideoPlayer->mPlayer->DoFrame(); + if (image) + { + // draw to hwnd + BITMAPINFO bmi; + bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + bmi.bmiHeader.biWidth = client_width; + bmi.bmiHeader.biHeight = -client_height; + bmi.bmiHeader.biPlanes = 1; + bmi.bmiHeader.biBitCount = 32; + bmi.bmiHeader.biCompression = BI_RGB; + bmi.bmiHeader.biSizeImage = 0; + bmi.bmiHeader.biXPelsPerMeter = 0; + bmi.bmiHeader.biYPelsPerMeter = 0; + bmi.bmiHeader.biClrUsed = 0; + bmi.bmiHeader.biClrImportant = 0; + GetDIBits(back_dc, back_bmp, 0, client_height, 0, &bmi, DIB_RGB_COLORS); + SetDIBits(back_dc, back_bmp, 0, client_height, image, &bmi, DIB_RGB_COLORS); + BitBlt(dc, 0, 0, client_width, client_height, back_dc, 0, 0, SRCCOPY); + + delete[] image; + } + if (pVideoPlayer->bStopBeforeSchedule == 1) + Sleep(0x3E8u); + } + pVideoPlayer->Unload(); + /* if ( pVideoPlayer->uMovieFormat == 2 ) { if ( pVideoPlayer->pBinkMovie ) { - pVideoPlayer->BinkDrawFrame(v4, ScreenSizeFlag); - while ( pVideoPlayer->pBinkMovie ) - { - if ( pVideoPlayer->bStopBeforeSchedule ) - break; - while ( PeekMessageA(&Msg, 0, 0, 0, 1) ) - { - if ( Msg.message == 18 ) - Game_DeinitializeAndTerminate(0); - if ( Msg.message == 15 ) - break; - TranslateMessage(&Msg); - DispatchMessageA(&Msg); - } - GUI_MainMenuMessageProc(); - if ( !pVideoPlayer->pBinkMovie ) - break; - if ( !BinkWait(pVideoPlayer->pBinkMovie) && !pVideoPlayer->bStopBeforeSchedule ) - pVideoPlayer->BinkDrawFrame(v4, ScreenSizeFlag); - } + //pVideoPlayer->BinkDrawFrame(v4, ScreenSizeFlag); + } + } if ( pVideoPlayer->bStopBeforeSchedule == 1 ) Sleep(0x3E8u); - } - else + }*/ + /* + if ( pVideoPlayer->uMovieFormat == 1 ) { - if ( pVideoPlayer->uMovieFormat == 1 ) - { - if ( pVideoPlayer->pSmackerMovie ) - { - pVideoPlayer->SmackDrawFrame(v4, ScreenSizeFlag); - while ( pVideoPlayer->pSmackerMovie ) - { - if ( pVideoPlayer->bStopBeforeSchedule ) - break; - while ( PeekMessageW(&Msg, 0, 0, 0, 1) ) - { - if (Msg.message == WM_QUIT) - Game_DeinitializeAndTerminate(0); - if (Msg.message == WM_PAINT) - break; - TranslateMessage(&Msg); - DispatchMessageW(&Msg); - } - GUI_MainMenuMessageProc(); - if ( !pVideoPlayer->pSmackerMovie ) - break; - if ( !SmackWait(pVideoPlayer->pSmackerMovie) && !pVideoPlayer->bStopBeforeSchedule ) - pVideoPlayer->SmackDrawFrame(v4, ScreenSizeFlag); - } - } - } + if ( pVideoPlayer->pSmackerMovie ) + { + pVideoPlayer->SmackDrawFrame(v4, ScreenSizeFlag); + while ( pVideoPlayer->pSmackerMovie ) + { + if ( pVideoPlayer->bStopBeforeSchedule ) + break; + while ( PeekMessageW(&Msg, 0, 0, 0, 1) ) + { + if (Msg.message == WM_QUIT) + Game_DeinitializeAndTerminate(0); + if (Msg.message == WM_PAINT) + break; + TranslateMessage(&Msg); + DispatchMessageW(&Msg); + } + GUI_MainMenuMessageProc(); + if ( !pVideoPlayer->pSmackerMovie ) + break; + if ( !SmackWait(pVideoPlayer->pSmackerMovie) && !pVideoPlayer->bStopBeforeSchedule ) + pVideoPlayer->SmackDrawFrame(v4, ScreenSizeFlag); + } + } } + */ if (a4 == 1) pCurrentScreen = SCREEN_GAME; pVideoPlayer->bPlayingMovie = 0; @@ -528,7 +567,7 @@ AIL_redbook_pause(pAudioPlayer->hAILRedbook); bStopBeforeSchedule = false; - field_54 = 1; + bBufferLoaded = 1; pSmackerMovie = 0; pSmackerBuffer = 0; pBinkMovie = 0; @@ -541,6 +580,7 @@ uBinkDirectDrawSurfaceType = BinkDDSurfaceType((IDirectDrawSurface *)pRenderer->pBackBuffer4); else uBinkDirectDrawSurfaceType = BinkDDSurfaceType((IDirectDrawSurface *)pRenderer->pBackBuffer2); + } @@ -553,9 +593,9 @@ if ( pBinkMovie ) { - BinkPause(pBinkMovie, 1); + //BinkPause(pBinkMovie, 1); Sleep(300); - BinkClose(pBinkMovie); + //BinkClose(pBinkMovie); pBinkMovie = 0; } @@ -569,8 +609,8 @@ if ( pSmackerMovie ) { - SmackSoundOnOff(pSmackerMovie, 0); - SmackClose(pSmackerMovie); + //SmackSoundOnOff(pSmackerMovie, 0); + //SmackClose(pSmackerMovie); pSmackerMovie = 0; } if ( pSmackerBuffer ) @@ -583,13 +623,19 @@ SmackBlitClose(pSmackMovieBlit); pSmackMovieBlit = 0; } - field_54 = 0; + bBufferLoaded = 0; uMovieFormat = 0; - dword_0000A0 = 0; + uMovieFormatSwapped = 0; memset(pCurrentMovieName, 0, 0x40); if ( pAudioPlayer->hAILRedbook && !bGameoverLoop ) AIL_redbook_resume(pAudioPlayer->hAILRedbook); pEventTimer->Resume(); + + if (mMovie) + { + delete mMovie; + mMovie = nullptr; + } } //----- (004BECD5) -------------------------------------------------------- @@ -816,7 +862,7 @@ void VideoPlayer::_inlined_in_463149() { - if ( pSmackerMovie && !SmackWait(pSmackerMovie) ) + if ( mMovie )// && !SmackWait(pSmackerMovie) ) { pRenderer->BeginScene(); pMouse->DrawCursorToTarget(); @@ -824,7 +870,7 @@ pMouse->_469EA4(); pRenderer->EndScene(); } - else if ( pBinkMovie && !BinkWait(pBinkMovie) ) + else if ( pBinkMovie )//&& !BinkWait(pBinkMovie) ) { pRenderer->BeginScene(); pMouse->DrawCursorToTarget(); @@ -851,19 +897,53 @@ v3 = pixels;//pRenderer->pTargetSurface; v4 = 640;//pRenderer->uTargetSurfacePitch; - v5 = SmackCheckSurfaceFromat(); + //v5 = SmackCheckSurfaceFromat(); + + //SmackToBuffer(pSmackerMovie, 8, 8, 2 * v4, pRenderer->field_14, v3, v5); - SmackToBuffer(pSmackerMovie, 8, 8, 2 * v4, pRenderer->field_14, v3, v5); - - + /* for (unsigned int y = 8; y < 8 + pSmackerMovie->Height; ++y) for (unsigned int x = 8; x < 8 + pSmackerMovie->Width; ++x) { pRenderer->WritePixel16(x, y, pixels[x + y * 640]); } //delete [] pixels; + */ + //v6 = pSmackerMovie; +// int i = 0; +// while (true) + //{ - //v6 = pSmackerMovie; + if (pVideoPlayer->mMovie->Stopped()) + { + //delete pVideoPlayer->mMovie; + //pVideoPlayer->mMovie = nullptr; + //Unload();//break; + pVideoPlayer->mPlayer->Rewind(); + } + else + { + + auto image = pVideoPlayer->mPlayer->DoFrame(); + + if (image) + { + memcpy(pRenderer->pTargetSurface, image, 480*480*4); + /*for (unsigned int y = 8; y < 8 + 360; ++y) + for (unsigned int x = 8; x < 8 + 480; ++x) + { + pRenderer->WritePixel16(x, y, image[y + x * 360]); + + }*/ + delete[] image; + } + } + + //delete pVideoPlayer->mMovie; + //pVideoPlayer->mMovie = nullptr; + //pVideoPlayer->Unload(); + + /* if ( pSmackerMovie->NewPalette ) { SmackBufferNewPalette(pSmackerBuffer, pSmackerMovie->Palette, (pSmackerMovie->PalType)); @@ -879,6 +959,8 @@ SmackNextFrame(pSmackerMovie); else Unload(); + */ + pRenderer->EndScene(); } @@ -952,17 +1034,75 @@ //----- (004BF28F) -------------------------------------------------------- void VideoPlayer::OpenHouseMovie(const char *pMovieName, unsigned int a3_1) { - if ( !this->field_54 ) + if (!this->bBufferLoaded) { - Prepare(); + //Prepare(); + pEventTimer->Pause(); + if (pAudioPlayer->hAILRedbook) + AIL_redbook_pause(pAudioPlayer->hAILRedbook); + + bStopBeforeSchedule = false; + bBufferLoaded = 1; + pSmackerMovie = 0; + pSmackerBuffer = 0; + pBinkMovie = 0; + pBinkBuffer = 0; + bPlayingMovie = false; + bFirstFrame = false; + bUsingSmackerMMX = SmackUseMMX(1); + this->bLoopPlaying = a3_1; if ( LOBYTE(this->field_104) == 1 ) { MessageBoxA(nullptr, "Unsupported Bink playback!", "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Video.cpp:925", 0); return; } - sprintfex(Str2, "%s.smk", pMovieName); - this->pSmackerMovie = OpenSmack(Str2); + + sprintf(Str2, "%s.smk", pMovieName); + void *src = nullptr; + unsigned int *offset = nullptr; + for (uint i = 0; i < uNumMightVideoHeaders; ++i) + { + if (!_stricmp(Str2, pMightVideoHeaders[i].pVideoName)) + { + src = (void *)hMightVid; + offset = &pMightVideoHeaders[i].uFileOffset; + uVidFile = 0; + } + } + for (uint i = 0; i < uNumMagicVideoHeaders; ++i) + { + if (!_stricmp(Str2, pMagicVideoHeaders[i].pVideoName)) + { + src = (void *)hMagicVid; + offset = &pMagicVideoHeaders[i].uFileOffset; + uVidFile = 1; + } + } + if (!src) + { + Unload(); + MessageBoxA(0, "VideoPlayer error", "VideoPlayer Error", 0); + return; + } + + SetFilePointer(src, *offset, 0, FILE_BEGIN); + strcpy(this->pCurrentMovieName, pMovieName); + this->uMovieFormat = 1; + this->uMovieFormatSwapped = 2; + uSize = *(offset + sizeof(MovieHeader)) - *offset; + + + auto hwnd = pVideoPlayer->window->GetApiHandle(); + RECT rc_client; + GetClientRect(hwnd, &rc_client); + int client_width = rc_client.right - rc_client.left, + client_height = rc_client.bottom - rc_client.top; + + pVideoPlayer->mMovie = pVideoPlayer->mPlayer->LoadMovie("dummyFilename", client_width, client_height); + + /* + this->pSmackerMovie = OpenSmack(Str2); if ( !this->pSmackerMovie ) { this->Unload(); @@ -970,10 +1110,12 @@ MessageBoxA(nullptr, pTmpBuf.data(), "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Video.cpp:937", 0); return; } - this->uMovieFormat = 1; - strcpy(this->pCurrentMovieName, (const char *)pMovieName); - this->dword_0000A0 = 1; - this->pSmackerBuffer = (_SMACKBUF *)SmackBufferOpen(window->GetApiHandle(), 4, LOWORD(this->pSmackerMovie->Width), LOWORD(this->pSmackerMovie->Height), LOWORD(this->pSmackerMovie->Width), LOWORD(this->pSmackerMovie->Height)); + */ + + + + /* + this->pSmackerBuffer = (_SMACKBUF *)SmackBufferOpen(window->GetApiHandle(), 4, LOWORD(this->pSmackerMovie->Width), LOWORD(this->pSmackerMovie->Height), LOWORD(this->pSmackerMovie->Width), LOWORD(this->pSmackerMovie->Height)); if ( this->pSmackerBuffer ) { pRenderer->BeginScene(); @@ -981,6 +1123,8 @@ pRenderer->EndScene(); } SmackVolumePan(this->pSmackerMovie, 1040384, (signed __int64)(pSoundVolumeLevels[(char)uSoundVolumeMultiplier] * 32767.0), 32767); + */ + } } @@ -994,12 +1138,86 @@ void VideoPlayer::OpenGlobalMovie(const char *pFilename, unsigned int bLoop, int a4) { unsigned int v10; // eax@11 - char pVideoName[120]; // [sp+Ch] [bp-28h]@2 + char pVideoNameBik[120]; // [sp+Ch] [bp-28h]@2 + char pVideoNameSmk[120]; // [sp+Ch] [bp-28h]@2 + + if (!this->bBufferLoaded) + { + //Prepare(); + pEventTimer->Pause(); + if (pAudioPlayer->hAILRedbook) + AIL_redbook_pause(pAudioPlayer->hAILRedbook); - if ( !this->field_54 ) - { - Prepare(); - this->bLoopPlaying = bLoop; + bStopBeforeSchedule = false; + bBufferLoaded = 1; + pSmackerMovie = 0; + pSmackerBuffer = 0; + pBinkMovie = 0; + pBinkBuffer = 0; + bPlayingMovie = false; + bFirstFrame = false; + bUsingSmackerMMX = SmackUseMMX(1); + this->bLoopPlaying = bLoop; + + sprintf(pVideoNameBik, "%s.bik", pFilename); + sprintf(pVideoNameSmk, "%s.smk", pFilename); + void *src = nullptr; + unsigned int *offset = nullptr; + for (uint i = 0; i < uNumMightVideoHeaders; ++i) + { + //no BIK in MightVid + /* + if (!_stricmp(pVideoNameBik, pMightVideoHeaders[i].pVideoName)) + { + src = (void *)hMightVid; + offset = pMightVideoHeaders[i].uFileOffset; + uVidFile = 1; + this->uMovieFormat = 2; + this->uMovieFormatSwapped = 1; + } + */ + if (!_stricmp(pVideoNameSmk, pMightVideoHeaders[i].pVideoName)) + { + src = (void *)hMightVid; + offset = &pMightVideoHeaders[i].uFileOffset; + uVidFile = 0; + this->uMovieFormat = 1; + this->uMovieFormatSwapped = 2; + } + } + for (uint i = 0; i < uNumMagicVideoHeaders; ++i) + { + if (!_stricmp(pVideoNameBik, pMagicVideoHeaders[i].pVideoName)) + { + src = (void *)hMagicVid; + offset = &pMagicVideoHeaders[i].uFileOffset; + uVidFile = 1; + this->uMovieFormat = 2; + this->uMovieFormatSwapped = 1; + } + if (!_stricmp(pVideoNameSmk, pMagicVideoHeaders[i].pVideoName)) + { + src = (void *)hMagicVid; + offset = &pMagicVideoHeaders[i].uFileOffset; + uVidFile = 1; + this->uMovieFormat = 1; + this->uMovieFormatSwapped = 2; + } + } + if (!src) + { + Unload(); + MessageBoxA(0, "VideoPlayer error", "VideoPlayer Error", 0); + return; + } + + SetFilePointer(src, *offset, 0, FILE_BEGIN); + strcpy(this->pCurrentMovieName, pFilename); + uSize = *(offset+sizeof(MovieHeader))-*offset; + return; + + + /* sprintf(pVideoName, "%s.bik", pFilename); this->pBinkMovie = OpenBink(pVideoName); if ( this->pBinkMovie ) @@ -1007,7 +1225,7 @@ this->uMovieFormat = 2; strcpy(this->pCurrentMovieName, pFilename); pBinkMovie = this->pBinkMovie; - this->dword_0000A0 = 1; + this->uMovieFormatSwapped = 1; if ( pBinkMovie ) this->pBinkBuffer = CreateBinkBuffer(pBinkMovie->uWidth, pBinkMovie->uHeight, 0); } @@ -1025,7 +1243,7 @@ } this->uMovieFormat = 1; strcpy(this->pCurrentMovieName, pFilename); - this->dword_0000A0 = 2; + this->uMovieFormatSwapped = 2; this->pSomeSmackerBuffer = (char *)malloc(this->pSmackerMovie->Width * this->pSmackerMovie->Height); if ( !this->pSomeSmackerBuffer ) { @@ -1054,8 +1272,8 @@ sprintf(pVideoName, "Failed to open Blit API"); MessageBoxA(0, pVideoName, "Smacker Error", 0); return; - } - } + } + }*/ } } @@ -1107,9 +1325,9 @@ strcpy(Source, this->pCurrentMovieName); Unload(); - if ( this->dword_0000A0 == 1 ) + if ( this->uMovieFormatSwapped == 1 ) OpenHouseMovie(Source, LOBYTE(this->bLoopPlaying)); - else if ( this->dword_0000A0 == 2 ) + else if ( this->uMovieFormatSwapped == 2 ) OpenGlobalMovie(Source, LOBYTE(this->bLoopPlaying), 1); else __debugbreak(); @@ -1126,7 +1344,7 @@ //----- (004BE6F5) -------------------------------------------------------- VideoPlayer::VideoPlayer() : - field_54(0), +bBufferLoaded(0), pBinkMovie(nullptr), pBinkBuffer(nullptr), pSmackerMovie(nullptr), pSmackerBuffer(nullptr), pSmackMovieBlit(nullptr) { @@ -1134,6 +1352,9 @@ bStopBeforeSchedule = false; pResetflag = 0; byte_F8BC0C = 0; + mPlayer = new MultimediaPlayer(); + mPlayer->Initialize(); + mMovie = nullptr; //pBinkMovie = nullptr; } @@ -1147,3 +1368,30 @@ DWORD w; WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), msg, lstrlenA(msg), &w, nullptr); } + +int readFunction(void* opaque, uint8_t* buf, int buf_size) +{ + HANDLE stream = (HANDLE)opaque; + //int numBytes = stream->read((char*)buf, buf_size); + int numBytes; + ReadFile(stream, (char *)buf, buf_size, (LPDWORD)&numBytes, NULL); + return numBytes; +} + +int64_t seekFunction(void* opaque, int64_t offset, int whence) +{ + if (whence == AVSEEK_SIZE) + return pVideoPlayer->uSize;// -1; // I don't know "size of my handle in bytes" + HANDLE stream = (HANDLE)opaque; + /*if (stream->isSequential()) + return -1; // cannot seek a sequential stream + if (!stream->seek(offset)) + return -1; + return stream->pos();*/ + LARGE_INTEGER li,li2; + PLARGE_INTEGER pli = &li2; + li.QuadPart = offset; + SetFilePointerEx(stream, li, pli, FILE_BEGIN); + return pli->QuadPart; + return SetFilePointer(stream, LODWORD(offset), (PLONG)(&offset)+1, FILE_BEGIN); +}