Mercurial > mm7
changeset 2142:ca548138d6aa
some code cleaning in video playing, loops play but there is a memory leak
author | zipi |
---|---|
date | Thu, 02 Jan 2014 18:25:42 +0000 |
parents | 1283eedcc028 |
children | feeb7bfcb19e |
files | CShow.h Events.cpp Game.cpp OSWindow.cpp Render.cpp VideoPlayer.cpp VideoPlayer.h |
diffstat | 7 files changed, 257 insertions(+), 279 deletions(-) [+] |
line wrap: on
line diff
--- a/CShow.h Thu Jan 02 17:57:09 2014 +0600 +++ b/CShow.h Thu Jan 02 18:25:42 2014 +0000 @@ -23,13 +23,13 @@ switch (movie) { - case MOVIE_3DOLogo: VideoPlayer::MovieLoop("3dologo", 0, 0, 1); break; - case MOVIE_NWCLogo: VideoPlayer::MovieLoop("new world logo", 0, 1, 1); break; - case MOVIE_JVC: VideoPlayer::MovieLoop("jvc", 0, 1, 1); break; - case MOVIE_Intro: VideoPlayer::MovieLoop("Intro", 0, 1, 1); break; - case MOVIE_Emerald: VideoPlayer::MovieLoop("Intro Post", 0, 1, 1); break; - case MOVIE_Death: VideoPlayer::MovieLoop("losegame", 2, 1, 1); break; - case MOVIE_Outro: VideoPlayer::MovieLoop("end_seq1", 20, 1, 1); break; + case MOVIE_3DOLogo: pVideoPlayer->MovieLoop("3dologo", 0, 0, 1); break; + case MOVIE_NWCLogo: pVideoPlayer->MovieLoop("new world logo", 0, 1, 1); break; + case MOVIE_JVC: pVideoPlayer->MovieLoop("jvc", 0, 1, 1); break; + case MOVIE_Intro: pVideoPlayer->MovieLoop("Intro", 0, 1, 1); break; + case MOVIE_Emerald: pVideoPlayer->MovieLoop("Intro Post", 0, 1, 1); break; + case MOVIE_Death: pVideoPlayer->MovieLoop("losegame", 2, 1, 1); break; + case MOVIE_Outro: pVideoPlayer->MovieLoop("end_seq1", 20, 1, 1); break; default: Error("Invalid movie requested: %u", movie);
--- a/Events.cpp Thu Jan 02 17:57:09 2014 +0600 +++ b/Events.cpp Thu Jan 02 18:25:42 2014 +0000 @@ -508,7 +508,7 @@ v15 = _evt->v6; strcpy(Str, Source); v16 = RemoveQuotes(Str); - VideoPlayer::MovieLoop(v16, 0, v14, 1); + pVideoPlayer->MovieLoop(v16, 0, v14, 1); if ( !_stricmp(v16, "arbiter good") ) { pParty->alignment = PartyAlignment_Good;
--- a/Game.cpp Thu Jan 02 17:57:09 2014 +0600 +++ b/Game.cpp Thu Jan 02 18:25:42 2014 +0000 @@ -168,7 +168,7 @@ GameUI_Footer_2(); viewparams->bRedrawGameUI = false; } - if (!pVideoPlayer->pSmackerMovie) + if (!pVideoPlayer->pMovie)//!pVideoPlayer->pSmackerMovie) { GameUI_DrawMinimap(488, 16, 625, 133, viewparams->uMinimapZoom, true);//redraw = pParty->uFlags & 2); if (v4) @@ -4591,8 +4591,8 @@ } if ( GetCurrentMenuID() == MENU_CREDITSPROC && !pCurrentScreen ) { - if ( pCurrentScreen == SCREEN_VIDEO ) - pVideoPlayer->FastForwardToFrame(pVideoPlayer->pResetflag); + //if ( pCurrentScreen == SCREEN_VIDEO ) + //pVideoPlayer->FastForwardToFrame(pVideoPlayer->pResetflag); if (GetCurrentMenuID() == MENU_NAMEPANELESC) { SetCurrentMenuID(MENU_CREATEPARTY);
--- a/OSWindow.cpp Thu Jan 02 17:57:09 2014 +0600 +++ b/OSWindow.cpp Thu Jan 02 18:25:42 2014 +0000 @@ -76,8 +76,8 @@ case WM_SIZING: return *result = 1, true; case WM_WINDOWPOSCHANGED: - if (pVideoPlayer && pVideoPlayer->AnyMovieLoaded() && pVideoPlayer->pBinkBuffer) - BinkBufferSetOffset(pVideoPlayer->pBinkBuffer, 0, 0); + //if (pVideoPlayer && pVideoPlayer->AnyMovieLoaded() && pVideoPlayer->pBinkBuffer) + //BinkBufferSetOffset(pVideoPlayer->pBinkBuffer, 0, 0); return false; case WM_CHAR: @@ -301,14 +301,14 @@ pMiscTimer->Resume(); viewparams->bRedrawGameUI = true; - if ( pVideoPlayer->pSmackerMovie ) + if ( pVideoPlayer->pMovie)//pVideoPlayer->pSmackerMovie ) { pRenderer->RestoreFrontBuffer(); pRenderer->_4A184C(); - pVideoPlayer->_4BF5B2(); + //pVideoPlayer->_4BF5B2(); } } - if ( pAudioPlayer->hAILRedbook && !bGameoverLoop && !pVideoPlayer->pSmackerMovie ) + if ( pAudioPlayer->hAILRedbook && !bGameoverLoop && !pVideoPlayer->pMovie)//!pVideoPlayer->pSmackerMovie ) AIL_redbook_resume(pAudioPlayer->hAILRedbook); } } @@ -317,7 +317,8 @@ if (!(dword_6BE364_game_settings_1 & GAME_SETTINGS_APP_INACTIVE)) { dword_4E98BC_bApplicationActive = 0; - if ( (pVideoPlayer->pSmackerMovie || pVideoPlayer->pBinkMovie) && pVideoPlayer->bPlayingMovie ) + if ( pVideoPlayer->pMovie//(pVideoPlayer->pSmackerMovie || pVideoPlayer->pBinkMovie) + && pVideoPlayer->bPlayingMovie ) pVideoPlayer->bStopBeforeSchedule = 1; if (/*pRenderer->bUserDirect3D && */pRenderer->uAcquiredDirect3DDevice == 1)
--- a/Render.cpp Thu Jan 02 17:57:09 2014 +0600 +++ b/Render.cpp Thu Jan 02 18:25:42 2014 +0000 @@ -9127,8 +9127,8 @@ && pCurrentScreen != SCREEN_NPC_DIALOGUE && pCurrentScreen != SCREEN_CHANGE_LOCATION ) { - if ( pCurrentScreen == SCREEN_INPUT_BLV ) - return pVideoPlayer->pSmackerMovie != 0; + if (pCurrentScreen == SCREEN_INPUT_BLV) + return pVideoPlayer->pMovie;//pSmackerMovie != 0; if ( pCurrentScreen != SCREEN_BRANCHLESS_NPC_DIALOG ) return true; }
--- a/VideoPlayer.cpp Thu Jan 02 17:57:09 2014 +0600 +++ b/VideoPlayer.cpp Thu Jan 02 18:25:42 2014 +0000 @@ -356,9 +356,9 @@ if ( a2 == 2 ) v4 = 0; ShowCursor(0); - pVideoPlayer->OpenGlobalMovie(pName, 0, ScreenSizeFlag); - pVideoPlayer->bPlayingMovie = 1; - pVideoPlayer->field_44 = v4; + OpenGlobalMovie(pName, 0, ScreenSizeFlag); + bPlayingMovie = 1; + field_44 = v4; if ( pRenderer->pRenderD3D ) { pRenderer->ClearTarget(0); @@ -397,13 +397,9 @@ } GUI_MainMenuMessageProc(); - if (!pVideoPlayer->mMovie) - { - pVideoPlayer->mMovie = pVideoPlayer->mPlayer->LoadMovie("dummyFilename", client_width, client_height); - } - else if (pVideoPlayer->mMovie->Stopped()) + if (pMovie->Stopped()) break; - auto image = pVideoPlayer->mPlayer->DoFrame(); + auto image = pPlayer->DoFrame(); if (image) { // draw to hwnd @@ -568,10 +564,12 @@ bStopBeforeSchedule = false; bBufferLoaded = 1; + /* pSmackerMovie = 0; pSmackerBuffer = 0; pBinkMovie = 0; pBinkBuffer = 0; + */ bPlayingMovie = false; bFirstFrame = false; bUsingSmackerMMX = SmackUseMMX(1); @@ -590,7 +588,7 @@ //_BINK *pBinkMovie; // eax@1 //_BINKBUF *pBinkBuffer; // eax@3 //_SMACK *pSmackerMovie; // eax@5 - + /* if ( pBinkMovie ) { //BinkPause(pBinkMovie, 1); @@ -618,6 +616,7 @@ SmackBufferClose(pSmackerBuffer); pSmackerBuffer = 0; } + */ if ( pSmackMovieBlit ) { SmackBlitClose(pSmackMovieBlit); @@ -631,14 +630,15 @@ AIL_redbook_resume(pAudioPlayer->hAILRedbook); pEventTimer->Resume(); - if (mMovie) + if (pMovie) { - delete mMovie; - mMovie = nullptr; + delete pMovie; + pMovie = nullptr; } } //----- (004BECD5) -------------------------------------------------------- +/* void VideoPlayer::FastForwardToFrame(unsigned int uDstFrameNum) { VideoPlayer *v2; // esi@1 @@ -859,10 +859,11 @@ Unload(); } } - +*/ void VideoPlayer::_inlined_in_463149() { - if ( mMovie )// && !SmackWait(pSmackerMovie) ) + /* + if ( pSmackMovie && !SmackWait(pSmackerMovie) ) { pRenderer->BeginScene(); pMouse->DrawCursorToTarget(); @@ -870,7 +871,7 @@ pMouse->_469EA4(); pRenderer->EndScene(); } - else if ( pBinkMovie )//&& !BinkWait(pBinkMovie) ) + else if ( pBinkMovie && !BinkWait(pBinkMovie) ) { pRenderer->BeginScene(); pMouse->DrawCursorToTarget(); @@ -878,9 +879,55 @@ pMouse->_469EA4(); pRenderer->EndScene(); } + */ + if (pMovie) + { + pRenderer->BeginScene(); + pMouse->DrawCursorToTarget(); + UpdatePalette(); + pMouse->_469EA4(); + pRenderer->EndScene(); + } } -auto pixels = new unsigned short[640 * 480]; +//auto pixels = new unsigned short[640 * 480]; + +void VideoPlayer::UpdatePalette() +{ + //VideoPlayer *v2; // esi@1 + unsigned __int16 *v3; // ebx@1 + unsigned int v4; // edi@1 + unsigned int v5; // eax@1 + //_SMACK *v6; // eax@1 + + Log::Warning(L"smacker"); + + pRenderer->BeginScene(); + + if (pMovie->Stopped()) + { + int width = pMovie->GetWidth(); + int height = pMovie->GetHeight(); + delete pMovie; + SetFilePointer(hVidFile, uOffset, nullptr, FILE_BEGIN); + + pMovie = pPlayer->LoadMovieFromLOD(hVidFile, &readFunction, &seekFunction, width, height); + } + else + { + + auto image = pPlayer->DoFrame(); + + if (image) + { + memcpy(pRenderer->pTargetSurface, image, 480 * 480 * 4); + delete[] image; + } + } + + pRenderer->EndScene(); +} +/* //----- (004BF08B) -------------------------------------------------------- void VideoPlayer::SmackUpdatePalette() { @@ -891,59 +938,26 @@ //_SMACK *v6; // eax@1 Log::Warning(L"smacker"); - //return; - + pRenderer->BeginScene(); 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) - //{ - - 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(); - - /* + while (true) + { if ( pSmackerMovie->NewPalette ) { SmackBufferNewPalette(pSmackerBuffer, pSmackerMovie->Palette, (pSmackerMovie->PalType)); @@ -959,15 +973,14 @@ SmackNextFrame(pSmackerMovie); else Unload(); - */ pRenderer->EndScene(); } +*/ - - +/* //----- (004BF141) -------------------------------------------------------- _BINK *VideoPlayer::OpenBink(const char *pName) { @@ -1030,7 +1043,7 @@ } return 0; } - +*/ //----- (004BF28F) -------------------------------------------------------- void VideoPlayer::OpenHouseMovie(const char *pMovieName, unsigned int a3_1) { @@ -1043,10 +1056,12 @@ bStopBeforeSchedule = false; bBufferLoaded = 1; + /* pSmackerMovie = 0; pSmackerBuffer = 0; pBinkMovie = 0; pBinkBuffer = 0; + */ bPlayingMovie = false; bFirstFrame = false; bUsingSmackerMMX = SmackUseMMX(1); @@ -1058,49 +1073,7 @@ return; } - 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); - + LoadMovie(pMovieName); /* this->pSmackerMovie = OpenSmack(Str2); if ( !this->pSmackerMovie ) @@ -1131,15 +1104,13 @@ //----- (004BF3F9) -------------------------------------------------------- bool VideoPlayer::AnyMovieLoaded() { - return pSmackerMovie || pBinkMovie; + return pMovie;// pSmackerMovie || pBinkMovie; } //----- (004BF411) -------------------------------------------------------- void VideoPlayer::OpenGlobalMovie(const char *pFilename, unsigned int bLoop, int a4) { unsigned int v10; // eax@11 - char pVideoNameBik[120]; // [sp+Ch] [bp-28h]@2 - char pVideoNameSmk[120]; // [sp+Ch] [bp-28h]@2 if (!this->bBufferLoaded) { @@ -1150,70 +1121,17 @@ 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; + LoadMovie(pFilename); return; @@ -1281,7 +1199,9 @@ //----- (004BF5B2) -------------------------------------------------------- void VideoPlayer::_4BF5B2() { - if ( this->uMovieFormat == 2 ) + //__debugbreak(); + + /*if ( this->uMovieFormat == 2 ) { BinkGoto(pBinkMovie, 1, 0); BinkDoFrame(pBinkMovie); @@ -1297,9 +1217,9 @@ SmackDoFrame(pSmackerMovie); SmackNextFrame(pSmackerMovie); } - } + }*/ pMouse->_469E24(); - if ( window_SpeakInHouse && window_SpeakInHouse->ptr_1C == (void *)165 && !this->pSmackerMovie ) + if ( window_SpeakInHouse && window_SpeakInHouse->ptr_1C == (void *)165 && !this->pMovie)//!this->pSmackerMovie ) { bGameoverLoop = 1; HouseDialogPressCloseBtn(); @@ -1316,6 +1236,7 @@ } bGameoverLoop = 0; } + } //----- (004BF73A) -------------------------------------------------------- @@ -1345,16 +1266,17 @@ //----- (004BE6F5) -------------------------------------------------------- VideoPlayer::VideoPlayer() : bBufferLoaded(0), - pBinkMovie(nullptr), pBinkBuffer(nullptr), - pSmackerMovie(nullptr), pSmackerBuffer(nullptr), pSmackMovieBlit(nullptr) + //pBinkMovie(nullptr), pBinkBuffer(nullptr), + //pSmackerMovie(nullptr), pSmackerBuffer(nullptr), + pSmackMovieBlit(nullptr) { //RGBTexture::RGBTexture(&pVideoPlayer->pVideoFrame); bStopBeforeSchedule = false; pResetflag = 0; byte_F8BC0C = 0; - mPlayer = new MultimediaPlayer(); - mPlayer->Initialize(); - mMovie = nullptr; + pPlayer = new MultimediaPlayer(); + pPlayer->Initialize(); + pMovie = nullptr; //pBinkMovie = nullptr; } @@ -1369,7 +1291,7 @@ WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), msg, lstrlenA(msg), &w, nullptr); } -int readFunction(void* opaque, uint8_t* buf, int buf_size) +int VideoPlayer::readFunction(void* opaque, uint8_t* buf, int buf_size) { HANDLE stream = (HANDLE)opaque; //int numBytes = stream->read((char*)buf, buf_size); @@ -1378,20 +1300,84 @@ return numBytes; } -int64_t seekFunction(void* opaque, int64_t offset, int whence) +int64_t VideoPlayer::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; + return pVideoPlayer->uSize; + HANDLE h = (HANDLE)opaque; + LARGE_INTEGER li; li.QuadPart = offset; - SetFilePointerEx(stream, li, pli, FILE_BEGIN); - return pli->QuadPart; - return SetFilePointer(stream, LODWORD(offset), (PLONG)(&offset)+1, FILE_BEGIN); + + if (!SetFilePointerEx(h, li, (PLARGE_INTEGER)&li, FILE_BEGIN)) + return -1; + return li.QuadPart; } + +void VideoPlayer::LoadMovie(const char * pFilename) +{ + char pVideoNameBik[120]; // [sp+Ch] [bp-28h]@2 + char pVideoNameSmk[120]; // [sp+Ch] [bp-28h]@2 + + sprintf(pVideoNameBik, "%s.bik", pFilename); + sprintf(pVideoNameSmk, "%s.smk", pFilename); + for (uint i = 0; i < uNumMightVideoHeaders; ++i) + { + //no BIK in MightVid + /* + if (!_stricmp(pVideoNameBik, pMightVideoHeaders[i].pVideoName)) + { + hVidFile = hMightVid; + uOffset = pMightVideoHeaders[i].uFileOffset; + uSize = pMightVideoHeaders[i + 1].uFileOffset - uOffset; + this->uMovieFormat = 2; + this->uMovieFormatSwapped = 1; + } + */ + if (!_stricmp(pVideoNameSmk, pMightVideoHeaders[i].pVideoName)) + { + hVidFile = hMightVid; + uOffset = pMightVideoHeaders[i].uFileOffset; + uSize = pMightVideoHeaders[i + 1].uFileOffset - uOffset; + this->uMovieFormat = 1; + this->uMovieFormatSwapped = 2; + } + } + for (uint i = 0; i < uNumMagicVideoHeaders; ++i) + { + if (!_stricmp(pVideoNameBik, pMagicVideoHeaders[i].pVideoName)) + { + hVidFile = hMagicVid; + uOffset = pMagicVideoHeaders[i].uFileOffset; + uSize = pMagicVideoHeaders[i + 1].uFileOffset - uOffset; + this->uMovieFormat = 2; + this->uMovieFormatSwapped = 1; + } + if (!_stricmp(pVideoNameSmk, pMagicVideoHeaders[i].pVideoName)) + { + hVidFile = hMagicVid; + uOffset = pMagicVideoHeaders[i].uFileOffset; + uSize = pMagicVideoHeaders[i + 1].uFileOffset - uOffset; + this->uMovieFormat = 1; + this->uMovieFormatSwapped = 2; + } + } + if (!hVidFile) + { + Unload(); + MessageBoxA(0, "VideoPlayer error", "VideoPlayer Error", 0); + return; + } + + SetFilePointer(hVidFile, uOffset, 0, FILE_BEGIN); + strcpy(this->pCurrentMovieName, pFilename); + + 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; + + + pMovie = pPlayer->LoadMovieFromLOD(hVidFile, &readFunction, &seekFunction, client_width, client_height); + +} \ No newline at end of file
--- a/VideoPlayer.h Thu Jan 02 17:57:09 2014 +0600 +++ b/VideoPlayer.h Thu Jan 02 18:25:42 2014 +0000 @@ -522,8 +522,13 @@ class MovieCached { public: - bool Stopped() const { return stopped; } - + bool Stopped() { return stopped; } + int GetWidth() { return width; } + int GetHeight() { return height; } + inline ~MovieCached() + { + Release(); + } protected: friend class MultimediaPlayer; inline MovieCached(OpenALSoundProvider *sound_provider) @@ -541,6 +546,23 @@ this->audio_stream = nullptr; this->audio_stream_dec = nullptr; this->audio_stream_dec_ctx = nullptr; + + packet = nullptr; + ioBuffer = nullptr; + format_ctx = nullptr; + avioContext = nullptr; + } + + bool LoadFromLOD(HANDLE h, int readFunction(void*, uint8_t*, int), int64_t seekFunction(void*, int64_t, int), int width, int height) + { + if (!ioBuffer) + ioBuffer = (unsigned char *)av_malloc(16384 + FF_INPUT_BUFFER_PADDING_SIZE); // can get av_free()ed by libav + if (!avioContext) + avioContext = avio_alloc_context(ioBuffer, 16384, 0, h, &readFunction, NULL, &seekFunction); + if (!format_ctx) + format_ctx = avformat_alloc_context(); + format_ctx->pb = avioContext; + return Load("dummyFilename", width, height); } bool Load(const char *video_filename, int width, int height) @@ -548,42 +570,12 @@ this->width = width; this->height = height; -/* for (uint i = 0; i < pVideoPlayer->uNumMagicVideoHeaders; ++i) - if (!_stricmp(video_filename, pVideoPlayer->pMagicVideoHeaders[i].pVideoName)) - { - SetFilePointer(pVideoPlayer->hMagicVid, pVideoPlayer->pMagicVideoHeaders[i].uFileOffset, 0, FILE_BEGIN); - break; - } -*/ packet = nullptr; - int ioBufferSize = 32768; - void *src; - - unsigned char * ioBuffer = (unsigned char *)av_malloc(ioBufferSize + FF_INPUT_BUFFER_PADDING_SIZE); // can get av_free()ed by libav - if (pVideoPlayer->uVidFile) - { - src = (void*)pVideoPlayer->hMagicVid; - } - else - { - src = (void*)pVideoPlayer->hMightVid; - } - - avioContext = avio_alloc_context(ioBuffer, ioBufferSize, 0, src, &readFunction, NULL, &seekFunction); - //offset = SetFilePointer(pVideoPlayer->hMagicVid,0,0,FILE_CURRENT); - LARGE_INTEGER li, li2; - PLARGE_INTEGER pli = &li2; - li.QuadPart = 0; - SetFilePointerEx(pVideoPlayer->hMagicVid, li, pli, FILE_CURRENT); - offset = pli->QuadPart; - - format_ctx = avformat_alloc_context(); - format_ctx->pb = avioContext; if (avformat_open_input(&format_ctx, video_filename, nullptr, nullptr) >= 0) { if (avformat_find_stream_info(format_ctx, nullptr) >= 0) { av_dump_format(format_ctx, 0, video_filename, 0); - + video_stream_idx = OpenStream(AVMEDIA_TYPE_VIDEO, &video_stream, &video_stream_dec, &video_stream_dec_ctx); if (video_stream_idx < 0) return Release(), false; @@ -603,11 +595,6 @@ bool Release() { - if (format_ctx) - { - avformat_free_context(format_ctx); - format_ctx = nullptr; - } if (packet) { av_free_packet(packet); @@ -630,6 +617,17 @@ audio_stream = nullptr; audio_stream_dec = nullptr; avcodec_close(audio_stream_dec_ctx); + + } + if (avioContext) + { + av_free(avioContext); + avioContext = nullptr; + } + if (format_ctx) + { + avformat_free_context(format_ctx); + format_ctx = nullptr; } return true; } @@ -657,27 +655,6 @@ return -1; } - void Rewind() - { - //auto i=avio_seek(avioContext, pVideoPlayer->uOffset, 0); - //auto i = av_seek_frame(format_ctx, -1, 0, AVSEEK_FLAG_BYTE); - //i = av_seek_frame(format_ctx, audio_stream_idx, 0, AVSEEK_FLAG_BYTE); - - int64_t timestamp = 9; - int ret, i; - if (format_ctx->start_time != AV_NOPTS_VALUE) - timestamp += format_ctx->start_time; - ret = av_seek_frame(format_ctx, -1, format_ctx->start_time, AVSEEK_FLAG_BYTE); - if (ret < 0) { -// av_log(ctx, AV_LOG_ERROR, "Unable to loop: %s\n", av_err2str(ret)); - //loop_count = 1; /* do not try again */ - return;// ret; - } - - - stopped = false; - } - MultimediaFrame::Ptr GetNextFrame() { packet->data = nullptr; @@ -722,8 +699,8 @@ AVStream *audio_stream; AVCodec *audio_stream_dec; AVCodecContext *audio_stream_dec_ctx; - AVIOContext * avioContext; - int64_t offset; + unsigned char * ioBuffer; + AVIOContext *avioContext; }; typedef MovieCached<10> Movie; @@ -754,6 +731,21 @@ return true; } + Movie *LoadMovieFromLOD(HANDLE h, int readFunction(void*, uint8_t*, int), int64_t seekFunction(void*, int64_t, int), int width, int height) + { + auto movie = new Movie(sound_provider); + if (movie) + { + if (movie->LoadFromLOD(h, readFunction, seekFunction, width, height)) + { + current_movie_width = width; + current_movie_height = height; + return current_movie = movie; + } + delete movie; + } + return nullptr; + } Movie *LoadMovie(const char *filename, int width, int height) { @@ -771,11 +763,6 @@ return nullptr; } - inline void Rewind() - { - current_movie->Rewind(); - } - inline char *DoFrame() { if (!current_movie) @@ -865,13 +852,13 @@ _BINKBUF *CreateBinkBuffer(unsigned int uWidth, unsigned int uHeight, char a4); void _inlined_in_463149(); - static void MovieLoop(const char *pMovieName, int a2, int a3, int a4); + void MovieLoop(const char *pMovieName, int a2, int a3, int a4); RGBTexture pVideoFrame; - struct _SMACK *pSmackerMovie; - struct _SMACKBUF *pSmackerBuffer; - char *pSomeSmackerBuffer; + //struct _SMACK *pSmackerMovie; + //struct _SMACKBUF *pSmackerBuffer; + //char *pSomeSmackerBuffer; int field_34; MovieHeader *pMightVideoHeaders; MovieHeader *pMagicVideoHeaders; @@ -892,19 +879,23 @@ struct _SMACKBLIT *pSmackMovieBlit; HANDLE hMightVid; HANDLE hMagicVid; - _BINK *pBinkMovie; - _BINKBUF *pBinkBuffer; + //_BINK *pBinkMovie; + //_BINKBUF *pBinkBuffer; char field_88[20]; unsigned int uMovieFormat; int uMovieFormatSwapped; char pCurrentMovieName[64]; char pVideoFrameTextureFilename[32]; int field_104; - MultimediaPlayer *mPlayer; - Movie *mMovie; - int uVidFile; + MultimediaPlayer *pPlayer; + Movie *pMovie; + HANDLE hVidFile; int uSize; int uOffset; + void UpdatePalette(); + static int readFunction(void *, uint8_t *, int); + static int64_t seekFunction(void *, int64_t, int); + void LoadMovie(const char *); }; #pragma pack(pop)