Mercurial > mm7
changeset 2356:08c4f1799ca1
Elements of VideoPlayer structure moved
author | Ritor1 |
---|---|
date | Thu, 10 Apr 2014 17:34:50 +0600 |
parents | d57505d3c70c |
children | 44c91cec72ad |
files | Arcomage.cpp Game.cpp MMT.cpp MediaPlayer.cpp MediaPlayer.h OSWindow.cpp Render.cpp SaveLoad.cpp UI/UITransition.cpp VideoPlayer.cpp VideoPlayer.h |
diffstat | 11 files changed, 223 insertions(+), 106 deletions(-) [+] |
line wrap: on
line diff
--- a/Arcomage.cpp Tue Apr 08 17:39:59 2014 +0600 +++ b/Arcomage.cpp Thu Apr 10 17:34:50 2014 +0600 @@ -1109,7 +1109,7 @@ pArcomageGame->pSprites.Release(); pArcomageGame->bGameInProgress = false; viewparams->bRedrawGameUI = true; - if ( pVideoPlayer->AnyMovieLoaded() ) + if ( pMovie ) pVideoPlayer->_4BF5B2(); for( int i = 0; i < 12; ++i ) pSoundList->UnloadSound(am_sounds[i], 1);
--- a/Game.cpp Tue Apr 08 17:39:59 2014 +0600 +++ b/Game.cpp Thu Apr 10 17:34:50 2014 +0600 @@ -93,7 +93,7 @@ pIndoorCameraD3D->CreateWorldMatrixAndSomeStuff(); pIndoorCameraD3D->_4374E8_ProllyBuildFrustrum(); - if ( pVideoPlayer->AnyMovieLoaded() ) + if ( pMovie ) { /*if ( !pRenderer->pRenderD3D ) { @@ -163,7 +163,7 @@ GameUI_Footer_2(); viewparams->bRedrawGameUI = false; } - if (!pVideoPlayer->pMovie)//!pVideoPlayer->pSmackerMovie) + if (!pMovie)//!pVideoPlayer->pSmackerMovie) { GameUI_DrawMinimap(488, 16, 625, 133, viewparams->uMinimapZoom, true);//redraw = pParty->uFlags & 2); if (v4) @@ -187,7 +187,7 @@ GameUI_DrawCharacterSelectionFrame(); if ( _44100D_should_alter_right_panel() ) GameUI_DrawRightPanel(); - if ( !pVideoPlayer->AnyMovieLoaded() ) + if ( !pMovie ) { pStru6Instance->DrawPlayerBuffAnims(); pOtherOverlayList->DrawTurnBasedIcon(v4); @@ -422,7 +422,7 @@ pNPCStats->pNewNPCData[i].uFlags &= 0xFFFFFF7Fu; } pVideoPlayer->PlayDeathMovie(); - if ( pVideoPlayer->AnyMovieLoaded() ) + if ( pMovie ) pVideoPlayer->Unload(); SaveGame(0, 0); ++pParty->uNumDeaths;
--- a/MMT.cpp Tue Apr 08 17:39:59 2014 +0600 +++ b/MMT.cpp Thu Apr 10 17:34:50 2014 +0600 @@ -179,7 +179,7 @@ pAudioPlayer->StopChannels(-1, -1);//остановить/подготовить канал if (!bNoSound ) - pVideoPlayer->PlayAudio(L"Sounds\\New_Sounds/Stronghold_Theme.mp3");//воспроизводим мп3 + PlayAudio(L"Sounds\\New_Sounds/Stronghold_Theme.mp3");//воспроизводим мп3 //if (!bNoVideo ) //pVideoPlayer->PlayMovie(L"Anims\\New_Video/3DOLOGO.smk");
--- a/MediaPlayer.cpp Tue Apr 08 17:39:59 2014 +0600 +++ b/MediaPlayer.cpp Thu Apr 10 17:34:50 2014 +0600 @@ -22,6 +22,14 @@ #include "MediaPlayer.h" using namespace Media; + +Media::MPlayer *pMediaPlayer; +Media::IMovie *pMovie; +Media::ITrack *pTrack; + +void PlayMovie(const wchar_t * pFilename); +void PlayAudio(const wchar_t * pFilename); +void LoadMovie(const char *); class MemoryStream { @@ -344,6 +352,15 @@ } } +const uint16_t ff_wma_critical_freqs[25] = { + 100, 200, 300, 400, 510, 630, 770, 920, + 1080, 1270, 1480, 1720, 2000, 2320, 2700, 3150, + 3700, 4400, 5300, 6400, 7700, 9500, 12000, 15500, + 24500, +}; +extern const uint16_t ff_wma_critical_freqs[25]; +static float quant_table[96]; + bool DecodeAudioFrame(AVCodecContext *dec_ctx, AVPacket *avpacket, AVFrame *avframe, MemoryStream *out_audio_data, int *out_num_audio_samples) { volatile int decoded = false; @@ -362,6 +379,10 @@ switch (dec_ctx->codec_id) { + case AV_CODEC_ID_BINKAUDIO_DCT: + { + __debugbreak(); + } case AV_CODEC_ID_BINKAUDIO_RDFT: {//pts samples dpts // 0 960 @@ -370,7 +391,7 @@ //20160 960 1920 2x960 //21120 960 960 1x960 //23040 960 1920 2x960 - static int bink_next_pts = 0; + /*static int bink_next_pts = 0; // there's a gap in the sound - fill empty samples in if (bink_next_pts < avpacket->pts) @@ -378,7 +399,7 @@ short silence[1024]; memset(silence, 0, sizeof(silence)); - int samples_to_fill = /*dec_ctx->channels * */(avpacket->pts - bink_next_pts); + int samples_to_fill = /*dec_ctx->channels * (avpacket->pts - bink_next_pts); while (samples_to_fill > 0) { int samples_to_fill_this_step = samples_to_fill >= 1024 ? 1024 : samples_to_fill; @@ -388,7 +409,118 @@ } } - bink_next_pts = avpacket->pts + /*dec_ctx->channels * */avframe->nb_samples; + bink_next_pts = avpacket->pts + /*dec_ctx->channels * avframe->nb_samples; */ + + AVFrame frame; + int first; + int version_b; + int frame_len; + int overlap_len; + int block_size; + int num_bands; + unsigned int *bands; + float root; + int sample_rate = dec_ctx->sample_rate; + int sample_rate_half; + int i; + int frame_len_bits; + int channels; + + //compresses audio in chunks of varying sizes depending on sample rate: + // if sample rate < 22050, frame size is 2048 samples + // if sample rate < 44100, frame size is 4096 samples + // else, frame size is 8192 samples + + //сжимает аудио в куски различных размеров в зависимости от частоты дискретизации: + //если частота дискретизации < 22050, размер кадра составляет 2048 самплов + //если частота дискретизации < 44100, размер кадра составляет 4096 самплов + //или, размер кадра составляет 8192 самплов + + /* determine frame length */ + if (dec_ctx->sample_rate < 22050) + frame_len_bits = 9; + else if (dec_ctx->sample_rate < 44100) + frame_len_bits = 10; + else + frame_len_bits = 11; + + //проверка количества каналов (не меньше 1 и не больше 2) + if (dec_ctx->channels < 1 || dec_ctx->channels > 2) + { + av_log(dec_ctx, AV_LOG_ERROR, "invalid number of channels: %d\n", dec_ctx->channels); + return AVERROR_INVALIDDATA; + } + + version_b = dec_ctx->extradata_size >= 4 && dec_ctx->extradata[3] == 'b'; + if (version_b) + __debugbreak(); + + if (dec_ctx->codec->id == AV_CODEC_ID_BINKAUDIO_RDFT) + { + // audio is already interleaved for the RDFT format variant + dec_ctx->sample_fmt = AV_SAMPLE_FMT_FLT; + sample_rate *= dec_ctx->channels; + channels = 1; + if (!version_b) + frame_len_bits += av_log2(dec_ctx->channels); + } + else + { + channels = dec_ctx->channels; + dec_ctx->sample_fmt = AV_SAMPLE_FMT_FLTP; + } + + frame_len = 1 << frame_len_bits; //2048 + + //a frame is windowed with the previous frame; the size of the window is frame size / 16 + //кадр оконный с предыдущего кадра;Размер окна = размер кадра / 16 + overlap_len = frame_len / 16; //128 + block_size = (frame_len - overlap_len) * channels; //1920 + + //compute half the sample rate as (sample rate + 1) / 2; + //initialize an array of band frequencies corresponding to an array of 25 critical frequencies (same as WMA, apparently), + // any for which the critical frequencies are less than half the sample rate + + //вычислить половину частоты дискретизации(частота дискретизации + 1) / 2; + //инициализировать массив группы частот, соответствующих массиву 25 критических частот (аналогично WMA, очевидно), + // любой, для которых критические частоты в два раза меньше частота дискретизации + sample_rate_half = (sample_rate + 1) / 2; //22050 + if (dec_ctx->codec->id == AV_CODEC_ID_BINKAUDIO_RDFT) + root = 2.0 / (sqrt(frame_len) * 32768.0); + else + root = frame_len / (sqrt(frame_len) * 32768.0); + for (i = 0; i < 96; i++) + { + /* constant is result of 0.066399999/log10(M_E) */ + quant_table[i] = expf(i * 0.15289164787221953823f) * root; + } + + /* calculate number of bands */ + //bands calculation: + //bands[0] = 1; + //foreach (i in 1..# of bands-1): + //bands[i] = crit_freq[i-1] * (frame length / 2) / (sample rate / 2); + //bands[# of bands] = frame length / 2 + for (num_bands = 1; num_bands < 25; num_bands++) + if (sample_rate_half <= ff_wma_critical_freqs[num_bands - 1]) + break; + + bands = (unsigned int *)(av_malloc((num_bands + 1) * sizeof(*bands))); + if (!bands) + return AVERROR(ENOMEM); + + /* populate bands data */ + bands[0] = 2; + for (i = 1; i < num_bands; i++) + bands[i] = (ff_wma_critical_freqs[i - 1] * frame_len / sample_rate_half) & ~1; + bands[num_bands] = frame_len; + + first = 1; + + //ff_rdft_init(&trans.rdft, frame_len_bits, DFT_C2R); + + avcodec_get_frame_defaults(&frame); + dec_ctx->coded_frame = &frame; } break; /* @@ -873,7 +1005,7 @@ int last_resampled_frame_linesize[4]; }; -ITrack *Player::LoadTrack(const wchar_t *filename) //Загрузить mp3 +ITrack *MPlayer::LoadTrack(const wchar_t *filename) //Загрузить mp3 { auto track = new Track; if (!track->LoadAudio(filename)) @@ -884,7 +1016,7 @@ return track; } -IMovie *Player::LoadMovie(const wchar_t *filename, int width, int height, int cache_ms) //Загрузить видео +IMovie *MPlayer::LoadMovie(const wchar_t *filename, int width, int height, int cache_ms) //Загрузить видео { auto movie = new Movie; if (!movie->Load(filename, width, height, cache_ms)) @@ -895,7 +1027,7 @@ return movie; } -IMovie *Player::LoadMovieFromLOD(HANDLE h, int readFunction(void*, uint8_t*, int), int64_t seekFunction(void*, int64_t, int), int width, int height) +IMovie *MPlayer::LoadMovieFromLOD(HANDLE h, int readFunction(void*, uint8_t*, int), int64_t seekFunction(void*, int64_t, int), int width, int height) { auto movie = new Movie; if (movie) @@ -918,7 +1050,7 @@ log("av: %s", msg); } -Player::Player() +MPlayer::MPlayer() { static int libavcodec_initialized = false; @@ -943,6 +1075,33 @@ } } -Player::~Player() +MPlayer::~MPlayer() { } + +void PlayAudio(const wchar_t * pFilename) +{ + pTrack = pMediaPlayer->LoadTrack(pFilename); + pTrack->Play(); +} + +void PlayMovie(const wchar_t * pFilename) +{ + Media::IMovie *track = pMediaPlayer->LoadMovie(pFilename, 640, 480, 0); + track->Play(); +} + +////////////////////////////////////////////////////////////////////////// +//Included from a VideoPlayer.cpp file/вставлено из файла VideoPlayer.cpp/ +////////////////////////////////////////////////////////////////////////// + +//used in void VideoPlayer::Initialize(OSWindow *target_window) for open .vid files +MovieHeader *pMightVideoHeaders; +MovieHeader *pMagicVideoHeaders; +HANDLE hMightVid; +HANDLE hMagicVid; +unsigned __int64 uBinkVersion; +unsigned int uNumMightVideoHeaders; +unsigned int uNumMagicVideoHeaders; +// +
--- a/MediaPlayer.h Tue Apr 08 17:39:59 2014 +0600 +++ b/MediaPlayer.h Thu Apr 10 17:34:50 2014 +0600 @@ -13,11 +13,11 @@ virtual void GetNextFrame(double dt, void *target_surface) = 0; }; - class Player + class MPlayer { public: - Player(); - virtual ~Player(); + MPlayer(); + virtual ~MPlayer(); ITrack *LoadTrack(const wchar_t *name); IMovie *LoadMovie(const wchar_t *name, int width, int height, int cache_ms); @@ -25,6 +25,10 @@ }; }; +extern Media::MPlayer *pMediaPlayer; +extern Media::IMovie *pMovie; +extern Media::ITrack *pTrack; + extern bool end_current_file; extern bool loop_current_file; extern DWORD time_video_begin; @@ -32,4 +36,25 @@ extern int current_movie_height; int64_t seekFunction(void* opaque, int64_t offset, int whence); +extern void PlayMovie(const wchar_t * pFilename); +extern void PlayAudio(const wchar_t * pFilename); +////////////////////////////////////////////////////////////////////////// +//Included from a VideoPlayer.h file/вставлено из файла VideoPlayer.h/ +////////////////////////////////////////////////////////////////////////// + +//used in void VideoPlayer::Initialize(OSWindow *target_window) for open .vid files +struct MovieHeader +{ + char pVideoName[40]; + unsigned int uFileOffset; +}; + +extern MovieHeader *pMightVideoHeaders; +extern MovieHeader *pMagicVideoHeaders; +extern HANDLE hMightVid; +extern HANDLE hMagicVid; +extern unsigned __int64 uBinkVersion; +extern unsigned int uNumMightVideoHeaders; +extern unsigned int uNumMagicVideoHeaders; +// \ No newline at end of file
--- a/OSWindow.cpp Tue Apr 08 17:39:59 2014 +0600 +++ b/OSWindow.cpp Thu Apr 10 17:34:50 2014 +0600 @@ -316,14 +316,14 @@ pMiscTimer->Resume(); viewparams->bRedrawGameUI = true; - if ( pVideoPlayer->pMovie)//pVideoPlayer->pSmackerMovie ) + if ( pMovie)//pVideoPlayer->pSmackerMovie ) { pRenderer->RestoreFrontBuffer(); pRenderer->RestoreBackBuffer(); //pVideoPlayer->_4BF5B2(); } } - if ( pAudioPlayer->hAILRedbook && !bGameoverLoop && !pVideoPlayer->pMovie)//!pVideoPlayer->pSmackerMovie ) + if ( pAudioPlayer->hAILRedbook && !bGameoverLoop && !pMovie)//!pVideoPlayer->pSmackerMovie ) AIL_redbook_resume(pAudioPlayer->hAILRedbook); } } @@ -332,7 +332,7 @@ if (!(dword_6BE364_game_settings_1 & GAME_SETTINGS_APP_INACTIVE)) { dword_4E98BC_bApplicationActive = 0; - if ( pVideoPlayer->pMovie//(pVideoPlayer->pSmackerMovie || pVideoPlayer->pBinkMovie) + if ( pMovie//(pVideoPlayer->pSmackerMovie || pVideoPlayer->pBinkMovie) && pVideoPlayer->bPlayingMovie ) pVideoPlayer->bStopBeforeSchedule = 1;
--- a/Render.cpp Tue Apr 08 17:39:59 2014 +0600 +++ b/Render.cpp Thu Apr 10 17:34:50 2014 +0600 @@ -9035,7 +9035,7 @@ && pCurrentScreen != SCREEN_CHANGE_LOCATION ) { if (pCurrentScreen == SCREEN_INPUT_BLV) - return pVideoPlayer->pMovie;//pSmackerMovie != 0; + return pMovie;//pSmackerMovie != 0; if ( pCurrentScreen != SCREEN_BRANCHLESS_NPC_DIALOG ) return true; }
--- a/SaveLoad.cpp Tue Apr 08 17:39:59 2014 +0600 +++ b/SaveLoad.cpp Thu Apr 10 17:34:50 2014 +0600 @@ -570,7 +570,7 @@ FILE *file; // eax@7 void *pSave; // [sp+170h] [bp-8h]@3 - if ( pVideoPlayer->AnyMovieLoaded() ) + if ( pMovie ) pVideoPlayer->Unload(); pSave = malloc(1000000); pNew_LOD->CloseWriteFile();
--- a/UI/UITransition.cpp Tue Apr 08 17:39:59 2014 +0600 +++ b/UI/UITransition.cpp Thu Apr 10 17:34:50 2014 +0600 @@ -178,7 +178,7 @@ pRenderer->DrawTextureIndexed(556, 451, pIcons_LOD->GetTexture(uTextureID_x_x_u)); pRenderer->DrawTextureIndexed(476, 451, pIcons_LOD->GetTexture(uTextureID_x_ok_u)); map_id = pMapStats->GetMapInfo(pCurrentMapName); - if ( (pVideoPlayer->AnyMovieLoaded() || v9) && *dword_591164_teleport_map_name != ' ' ) + if ( (pMovie || v9) && *dword_591164_teleport_map_name != ' ' ) map_id = pMapStats->GetMapInfo(dword_591164_teleport_map_name); transition_window.uFrameX = 493; transition_window.uFrameWidth = 126;
--- a/VideoPlayer.cpp Tue Apr 08 17:39:59 2014 +0600 +++ b/VideoPlayer.cpp Thu Apr 10 17:34:50 2014 +0600 @@ -45,8 +45,6 @@ return true; } -unsigned __int64 uBinkVersion; - //----- (004BF794) -------------------------------------------------------- void ShowMM7IntroVideo_and_LoadingScreen() { @@ -245,38 +243,6 @@ //----- (004BEBD7) -------------------------------------------------------- void VideoPlayer::Unload() { - //_BINK *pBinkMovie; // eax@1 - //_BINKBUF *pBinkBuffer; // eax@3 - //_SMACK *pSmackerMovie; // eax@5 - /* - if ( pBinkMovie ) - { - //BinkPause(pBinkMovie, 1); - Sleep(300); - //BinkClose(pBinkMovie); - pBinkMovie = 0; - } - - if ( pBinkBuffer ) - { - pBinkBuffer->pTargetDDrawSurface->Release(); - pBinkBuffer->pTargetDDrawSurface = 0; - free(pBinkBuffer); - pBinkBuffer = 0; - } - - if ( pSmackerMovie ) - { - //SmackSoundOnOff(pSmackerMovie, 0); - //SmackClose(pSmackerMovie); - pSmackerMovie = 0; - } - if ( pSmackerBuffer ) - { - SmackBufferClose(pSmackerBuffer); - pSmackerBuffer = 0; - } - */ if ( pSmackMovieBlit ) { SmackBlitClose(pSmackMovieBlit); @@ -309,12 +275,12 @@ } } -void VideoPlayer::UpdatePalette() +void VideoPlayer::UpdatePalette() //UpdateVideo { Log::Warning(L"smacker"); loop_current_file = true; pRenderer->BeginScene(); - /*if (pMovie->Stopped())//видео завершено/перезагрузка + /*if (end_current_file)//видео завершено/перезагрузка { int width = game_viewport_width; int height = game_viewport_height; @@ -434,7 +400,7 @@ } }*/ pMouse->_469E24(); - if ( window_SpeakInHouse && window_SpeakInHouse->ptr_1C == (void *)165 && !this->pMovie)//!this->pSmackerMovie ) + if ( window_SpeakInHouse && window_SpeakInHouse->ptr_1C == (void *)165 && !pMovie)//!this->pSmackerMovie ) { bGameoverLoop = true; HouseDialogPressCloseBtn(); @@ -487,9 +453,7 @@ //RGBTexture::RGBTexture(&pVideoPlayer->pVideoFrame); bStopBeforeSchedule = false; pResetflag = 0; - //pPlayer = new MultimediaPlayer(); - //pPlayer->Initialize(); - pPlayer = new Media::Player;//создаётся плеер + pMediaPlayer = new Media::MPlayer;//создаётся плеер pMovie = nullptr; //pBinkMovie = nullptr; } @@ -525,17 +489,6 @@ 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; @@ -581,16 +534,6 @@ client_height = rc_client.bottom - rc_client.top; - pMovie = pPlayer->LoadMovieFromLOD(hVidFile, &readFunction, &seekFunction, client_width, client_height); + pMovie = pMediaPlayer->LoadMovieFromLOD(hVidFile, &readFunction, &seekFunction, client_width, client_height); } -void VideoPlayer::PlayAudio(const wchar_t * pFilename) -{ - Media::ITrack *track = pPlayer->LoadTrack(pFilename); - track->Play(); -} -void VideoPlayer::PlayMovie(const wchar_t * pFilename) -{ - Media::IMovie *track = pPlayer->LoadMovie(pFilename, 640, 480, 0); - track->Play(); -} \ No newline at end of file
--- a/VideoPlayer.h Tue Apr 08 17:39:59 2014 +0600 +++ b/VideoPlayer.h Thu Apr 10 17:34:50 2014 +0600 @@ -8,11 +8,6 @@ #pragma pack(pop) #pragma pack(push, 1) -struct MovieHeader -{ - char pVideoName[40]; - unsigned int uFileOffset; -}; #pragma pack(pop) void ShowMM7IntroVideo_and_LoadingScreen(); @@ -49,25 +44,29 @@ pVideoFrame.Release(); } - void PlayDeathMovie(); void Initialize(OSWindow *window); void Unload(); + void OpenHouseMovie(const char *pMovieName, unsigned int a3_1);//0x4BF28F + void PlayDeathMovie(); bool AnyMovieLoaded(); void OpenGlobalMovie(const char *pFilename, unsigned int bLoop, int a4); void _4BF5B2(); void SelectMovieType();//0x4BF73A void _inlined_in_463149(); + void MovieLoop(const char *pMovieName, int a2, int a3, int a4); + void UpdatePalette(); + static int readFunction(void *, uint8_t *, int); + static int64_t seekFunction(void *, int64_t, int); + void LoadMovie(const char *); RGBTexture pVideoFrame; int field_34; - MovieHeader *pMightVideoHeaders; - MovieHeader *pMagicVideoHeaders; + int pResetflag; int field_44; - unsigned int uNumMightVideoHeaders; - unsigned int uNumMagicVideoHeaders; + int uBinkDirectDrawSurfaceType; int bBufferLoaded; unsigned int bPlayingMovie; @@ -78,26 +77,17 @@ unsigned int bStopBeforeSchedule; OSWindow *window; struct _SMACKBLIT *pSmackMovieBlit; - HANDLE hMightVid; - HANDLE hMagicVid; + char field_88[20]; unsigned int uMovieFormat; int uMovieFormatSwapped; char pCurrentMovieName[64]; char pVideoFrameTextureFilename[32]; int field_104; - Media::Player *pPlayer; - Media::IMovie *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 *); - void PlayAudio(const wchar_t * pFilename); - void PlayMovie(const wchar_t * pFilename); }; #pragma pack(pop)