Mercurial > mm7
diff MediaPlayer.cpp @ 2450:90349b8048a5
remove VideoPlayer.cpp/.h
author | Ritor1 |
---|---|
date | Fri, 25 Jul 2014 14:17:57 +0600 |
parents | 99e7bd7ec0a2 |
children | 5991abe37c1d |
line wrap: on
line diff
--- a/MediaPlayer.cpp Thu Jul 24 12:50:24 2014 +0600 +++ b/MediaPlayer.cpp Fri Jul 25 14:17:57 2014 +0600 @@ -21,16 +21,31 @@ #include <vector> #include <deque> +#define _CRT_SECURE_NO_WARNINGS + +#include "mm7_unsorted_subs.h" +#include "Mouse.h" +#include "Game.h" +#include "Party.h" +#include "GUIWindow.h" +#include "texts.h" +#include "UI\UIHouses.h" #include "stuff.h" +#include "mm7_data.h" #include "OpenALSoundProvider.h" - #include "Log.h" +#include "MediaPlayer.h" +#include "CShow.h" +#include "Bink_Smacker.h" +#include "AudioPlayer.h" +#include "Timer.h" +#include "Render.h" -#include "MediaPlayer.h" -#include "Log.h" +#pragma comment(lib, "Version.lib") + using namespace Media; -Media::MPlayer *pMediaPlayer; +Media::MPlayer *pMediaPlayer = nullptr; Media::IMovie *pMovie_Track; Media::ITrack *pAudio_Track; Movie *movie; @@ -139,12 +154,6 @@ size_t current_pos; }; -bool end_current_file; -bool loop_current_file; -DWORD time_video_begin; -int current_movie_width; -int current_movie_height; - OpenALSoundProvider *provider = nullptr; static int av_num_bytes_per_sample(AVSampleFormat sample_fmt) @@ -767,10 +776,10 @@ OpenALSoundProvider::TrackBuffer *device_buffer; }; -class Movie: public Media::IMovie//класс производная от базового Media::IMovie +class Movie: public Media::IMovie { public: - inline Movie()//прямая вставка в код + inline Movie() { this->movie_filename[0] = 0; this->width = 0; @@ -844,26 +853,14 @@ width = dst_width; height = dst_height; // Open video file - //откроем входной файл(Шаг 2) - //Функция avformat_open_input читает файловый заголовок и сохраняет информацию о найденных форматах в структуре - //AVFormatContext. Остальные аргументы могут быть установлены в NULL, в этом случае libavformat использует - //автоматическое определение параметров. Последние 2 аргумента используются для формата файла и опций. if (avformat_open_input(&format_ctx, filenamea, nullptr, nullptr) >= 0) { // Retrieve stream information - // Проверяем потоки - //Т.к. avformat_open_input читает только заголовок файла, то следующим шагом нужно получить информацию о потоках - //в файле. Это делается функцией avformat_find_stream_info.(Шаг 3) if (avformat_find_stream_info(format_ctx, nullptr) >= 0) { // Dump information about file onto standard error - //Инициализируем pFormatCtx->streams - //После этого format_context->streams содержит все существующие потоки файла. - //Их количество равно format_context->nb_streams. - //Вывести подробную информацию о файле и обо всех потоках можно функцией av_dump_format. av_dump_format(format_ctx, 0, filenamea, 0); - //pFormatCtx->streams - массив указателей, размера pFormatCtx->nb_streams, поищем тут потоки. if (!av_open_audio_stream(format_ctx, &audio)) { Error("Cannot open audio stream: %s", filenamea); @@ -879,30 +876,29 @@ //Ritor1: include if (_stricmp("binkvideo", video.dec->name) ) { - current_movie_width = video.dec_ctx->width; - current_movie_height = video.dec_ctx->height; + pMediaPlayer->current_movie_width = video.dec_ctx->width; + pMediaPlayer->current_movie_height = video.dec_ctx->height; } else { - current_movie_width = width; - current_movie_height = height; + pMediaPlayer->current_movie_width = width; + pMediaPlayer->current_movie_height = height; } // decoding_packet = new AVPacket; av_init_packet(decoding_packet); // Allocate video frame - //Выделим память для фрейма decoding_frame = avcodec_alloc_frame(); audio_data_in_device = provider->CreateStreamingTrack16(audio.dec_ctx->channels, audio.dec_ctx->sample_rate, 2); return true; } fprintf(stderr, "ffmpeg: Unable to find stream info\n"); - return Release(), false; // Не найдена информация о потоке + return Release(), false; } fprintf(stderr, "ffmpeg: Unable to open input file\n"); - return Release(), false; // Не может открыть файл + return Release(), false; } bool LoadFromLOD(HANDLE h, int readFunction(void*, uint8_t*, int), int64_t seekFunction(void*, int64_t, int), int width, int height) @@ -917,66 +913,56 @@ return Load(L"dummyFilename", width, height, 0); } - virtual void GetNextFrame(double dt, void *dst_surface)// Получить следующий фрейм + virtual void GetNextFrame(double dt, void *dst_surface) { - playback_time += dt;//изменение времени + playback_time += dt; - //Данные из файла читаются пакетами (AVPacket), а для отображения используется фрейм (AVFrame). AVPacket *avpacket = decoding_packet; AVFrame *avframe = decoding_frame; - - //Инизиализируем avframe + avcodec_get_frame_defaults(avframe); int desired_frame_number = floor(playback_time * video.dec_ctx->time_base.den / video.dec_ctx->time_base.num + 0.5); if (last_resampled_frame_num == desired_frame_number) { - memcpy(dst_surface, last_resampled_frame_data[0], current_movie_height * last_resampled_frame_linesize[0]); + memcpy(dst_surface, last_resampled_frame_data[0], pMediaPlayer->current_movie_height * last_resampled_frame_linesize[0]); return; } volatile int frameFinished = false; - //чтение пакетов // keep reading packets until we hit the end or find a video packet do { - if (loop_current_file) + if (pMediaPlayer->loop_current_file) { //Now seek back to the beginning of the stream if (video.dec_ctx->frame_number >= video.stream->duration - 1 ) - end_current_file = true; + pMediaPlayer->bPlaying_Movie = false; } - //чтение пакетов - if (av_read_frame(format_ctx, avpacket) < 0) //воспроизведение завершено + if (av_read_frame(format_ctx, avpacket) < 0) { // probably movie is finished - end_current_file = true; + pMediaPlayer->bPlaying_Movie = false; av_free_packet(avpacket); return; } // Is this a packet from the video stream? // audio packet - queue into playing - //Принадлежит ли пакет к аудиопотоку if (avpacket->stream_index == audio.stream_idx) { MemoryStream audio_data; if (DecodeAudioFrame(audio.dec_ctx, avpacket, avframe, &audio_data, &num_audio_samples)) provider->Stream16(audio_data_in_device, num_audio_samples, audio_data.Ptr()); //continue; - } //неявно вызывается деструктор для audio_data + } // Decode video frame - //пакет к видеопотоку // video packet - decode & maybe show else if (avpacket->stream_index == video.stream_idx) { do { - //Функция avcodec_decode_video2 осуществляет декодирование пакета в фрейм с использованием кодека, - //который мы получили раньше (codec_context). Функция устанавливает положительное значение frame_finished в случае - //если фрейм декодирован целиком (то есть один фрейм может занимать несколько пакетов и frame_finished будет - //установлен только при декодировании последнего пакета). if (avcodec_decode_video2(video.dec_ctx, avframe, (int *)&frameFinished, avpacket) < 0) __debugbreak(); } while (!frameFinished); @@ -995,27 +981,24 @@ uint8_t *rescaled_data[4] = {nullptr, nullptr, nullptr, nullptr}; int rescaled_linesize[4] = {0, 0, 0, 0}; - if (av_image_alloc(rescaled_data, rescaled_linesize, current_movie_width, current_movie_height, rescaled_format, 1) >= 0) + if (av_image_alloc(rescaled_data, rescaled_linesize, pMediaPlayer->current_movie_width, pMediaPlayer->current_movie_height, rescaled_format, 1) >= 0) { - // создание контекста для преобразования SwsContext *converter = sws_getContext(avframe->width, avframe->height, (AVPixelFormat)avframe->format, - current_movie_width, current_movie_height, rescaled_format, + pMediaPlayer->current_movie_width, pMediaPlayer->current_movie_height, rescaled_format, SWS_BICUBIC, nullptr, nullptr, nullptr); - // преобразование кадра(масштабирование) sws_scale(converter, avframe->data, avframe->linesize, 0, avframe->height, rescaled_data, rescaled_linesize); sws_freeContext(converter); - //копирование в возвращаемую переменную - memcpy(dst_surface, rescaled_data[0], current_movie_height * rescaled_linesize[0]); + memcpy(dst_surface, rescaled_data[0], pMediaPlayer->current_movie_height * rescaled_linesize[0]); last_resampled_frame_num = desired_frame_number; memcpy(last_resampled_frame_data, rescaled_data, sizeof(rescaled_data)); memcpy(last_resampled_frame_linesize, rescaled_linesize, sizeof(rescaled_linesize)); - //av_freep(&rescaled_data[0]);//вроде должен быть + //av_freep(&rescaled_data[0]); } } else - memset(dst_surface, 0, width * current_movie_height * 4); + memset(dst_surface, 0, width * pMediaPlayer->current_movie_height * 4); // Free the packet that was allocated by av_read_frame av_free_packet(avpacket); @@ -1050,7 +1033,7 @@ int last_resampled_frame_linesize[4]; }; -ITrack *MPlayer::LoadTrack(const wchar_t *filename) //Загрузить mp3 +ITrack *MPlayer::LoadTrack(const wchar_t *filename) { auto audio_track = new Track; Log::Warning(L"allocation dynamic memory for audio_track\n"); @@ -1076,6 +1059,425 @@ return movie; } +//----- (004BE9D8) -------------------------------------------------------- +void MPlayer::Initialize(OSWindow *target_window) +{ + DWORD NumberOfBytesRead; // [sp+10h] [bp-4h]@9 + + window = target_window; + + unsigned int uBinkVersionMajor = -1, + uBinkVersionMinor = -1; + //GetDllVersion(L"BINKW32.DLL", &uBinkVersionMajor, &uBinkVersionMinor); + //uBinkVersion = (unsigned __int64)uBinkVersionMajor << 32 | uBinkVersionMinor; + + strcpy(pTmpBuf.data(), "anims\\might7.vid"); + hMightVid = CreateFileW(L"anims\\might7.vid", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0x8000080, 0); + if ( hMightVid == INVALID_HANDLE_VALUE ) + { + sprintf(pTmpBuf2.data(), "Can't open file - anims\\%s.smk", pTmpBuf.data()); + MessageBoxA(0, pTmpBuf2.data(), "Video File Error", 0); + return; + } + strcpy(pTmpBuf.data(), "anims\\magic7.vid"); + hMagicVid = CreateFileW(L"anims\\magic7.vid", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0x8000080, 0); + if ( hMagicVid == INVALID_HANDLE_VALUE ) + { + if ( !bCanLoadFromCD ) + { + sprintf(pTmpBuf2.data(), "Can't open file - anims\\%s.smk", pTmpBuf.data()); + MessageBoxA(0, pTmpBuf2.data(), "Video File Error", 0); + return; + } + sprintf(pTmpBuf2.data(), "%c:\\%s", (unsigned __int8)cMM7GameCDDriveLetter, pTmpBuf.data()); + hMagicVid = CreateFileA(pTmpBuf2.data(), GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0x8000080, 0); + if ( hMagicVid == (HANDLE)INVALID_HANDLE_VALUE ) + { + sprintf(pTmpBuf2.data(), "Can't open file - %s", pTmpBuf.data()); + MessageBoxA(0, pTmpBuf2.data(), "Video File Error", 0); + return; + } + } + ReadFile(hMightVid, &uNumMightVideoHeaders, 4, &NumberOfBytesRead, 0); + ReadFile(hMagicVid, &uNumMagicVideoHeaders, 4, &NumberOfBytesRead, 0); + pMightVideoHeaders = (MovieHeader *)malloc(sizeof(MovieHeader) * uNumMightVideoHeaders + 2); + pMagicVideoHeaders = (MovieHeader *)malloc(sizeof(MovieHeader) * uNumMagicVideoHeaders + 2); + ReadFile(hMightVid, pMightVideoHeaders, 44 * uNumMightVideoHeaders, &NumberOfBytesRead, 0); + ReadFile(hMagicVid, pMagicVideoHeaders, 44 * uNumMagicVideoHeaders, &NumberOfBytesRead, 0); +} + +//----- (004BF411) -------------------------------------------------------- +void MPlayer::OpenGlobalMovie(const char *pFilename, unsigned int bLoop/*, int ScreenSizeFlag*/) +{ + if (!this->bPlaying_Movie) + { + pEventTimer->Pause(); + if (pAudioPlayer->hAILRedbook) + AIL_redbook_pause(pAudioPlayer->hAILRedbook); + + bStopBeforeSchedule = false; + bFirstFrame = false; + this->bLoopPlaying = bLoop; + LoadMovie(pFilename); + return; + } +} + +//----- (004BF28F) -------------------------------------------------------- +void MPlayer::OpenHouseMovie(const char *pMovieName, unsigned int a3_1) +{ + if (!this->bPlaying_Movie) + { + //Prepare(); + pEventTimer->Pause(); + if (pAudioPlayer->hAILRedbook) + AIL_redbook_pause(pAudioPlayer->hAILRedbook); + + bStopBeforeSchedule = false; + bFirstFrame = false; + + 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; + }*/ + + LoadMovie(pMovieName); + time_video_begin = GetTickCount(); + } +} + +//----- (004BE70E) -------------------------------------------------------- +void MPlayer::GlobalMovieLoop(const char *pMovieName, int a2/*, int ScreenSizeFlag, int a4*/) +{ + int v4; // ebp@1 + MSG Msg; // [sp+Ch] [bp-1Ch]@12 + + v4 = a2; + if ( dword_6BE364_game_settings_1 & (GAME_SETTINGS_NO_HOUSE_ANIM | GAME_SETTINGS_NO_INTRO) || + bNoVideo) + return; + + if ( a2 == 2 ) + v4 = 0; + ShowCursor(0); + OpenGlobalMovie(pMovieName, 0); + bPlaying_Movie = 1; + field_44 = v4; + pRenderer->ClearTarget(0); + pCurrentScreen = SCREEN_VIDEO; + + auto hwnd = pMediaPlayer->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 = CreateCompatibleBitmap(dc, client_width, client_height); + auto frame_buffer = new char[client_width * client_height * 4]; + SelectObject(back_dc, back_bmp); + + DWORD t = GetTickCount(); + + bPlaying_Movie = true; + + while (true) + { + if (pMediaPlayer->bStopBeforeSchedule) + break; + while (PeekMessageA(&Msg, hwnd, 0, 0, PM_REMOVE)) + { + if (Msg.message == WM_QUIT) + Game_DeinitializeAndTerminate(0); + if (Msg.message == WM_PAINT) + break; + TranslateMessage(&Msg); + DispatchMessageA(&Msg); + } + + double dt = (GetTickCount() - t) / 1000.0; + t = GetTickCount(); + + pMovie_Track->GetNextFrame(dt, frame_buffer); + + if (!bPlaying_Movie) + break; + + if (frame_buffer) + { + // 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, frame_buffer, &bmi, DIB_RGB_COLORS); + BitBlt(dc, 0, 0, client_width, client_height, back_dc, 0, 0, SRCCOPY); + } + + GUI_MainMenuMessageProc(); + + if (pMediaPlayer->bStopBeforeSchedule == 1) + Sleep(1000); + } + delete [] frame_buffer; + DeleteObject(back_bmp); + DeleteObject(back_dc); + ReleaseDC(hwnd, dc); + + pMediaPlayer->Unload(); + + //if (a4 == 1) + pCurrentScreen = SCREEN_GAME; + + pMediaPlayer->bPlaying_Movie = false; + + ShowCursor(1); + + /*if ( pCurrentScreen == SCREEN_VIDEO ) + pCurrentScreen = SCREEN_GAME;*/ +} + +void MPlayer::HouseMovieLoop() +{ + if (pMovie_Track && !bNoVideo) + { + pRenderer->BeginScene(); + pMouse->DrawCursorToTarget(); + + Log::Warning(L"smacker"); + loop_current_file = true; + pRenderer->BeginScene(); + if (!bPlaying_Movie)//reload + { + unsigned int width = game_viewport_width; + unsigned int height = game_viewport_height; + MovieRelease(); + + SetFilePointer(hVidFile, uOffset, nullptr, FILE_BEGIN); + pMovie_Track = nullptr; + Log::Warning(L"reload pMovie_Track"); + pMovie_Track = pMediaPlayer->LoadMovieFromLOD(hVidFile, &readFunction, &seekFunction, width, height); + bPlaying_Movie = true; + } + //else + //{ + double dt = (GetTickCount() - time_video_begin) / 1000.0; + //dt = 1.0/15.0; + time_video_begin = GetTickCount(); + + //log("dt=%.5f\n", dt); + + auto image = new char[current_movie_width * current_movie_height * 4]; + + pMovie_Track->GetNextFrame(dt, image); + + int image_array[460 * 344];//game_viewport_width * game_viewport_height + if (image) + { + memcpy(image_array, image, sizeof (image_array)); + for (unsigned int y = 8; y < 8 + game_viewport_height; ++y)//координаты местоположения видеоролика + { + for (unsigned int x = 8; x < 8 + game_viewport_width; ++x) + { + auto p = (unsigned __int32 *)pRenderer->pTargetSurface + x + y * pRenderer->uTargetSurfacePitch; + *p = image_array[((x - 8) + ((y - 8)*game_viewport_width))]; + } + } + delete[] image; + } + //} + pRenderer->EndScene(); + pMouse->ReadCursorWithItem(); + pRenderer->EndScene(); + } +} + +//----- (004BF5B2) -------------------------------------------------------- +void MPlayer::_4BF5B2() +{ + pMouse->_469E24(); + if ( window_SpeakInHouse && window_SpeakInHouse->ptr_1C == (void *)165 && !pMovie_Track)//!this->pSmackerMovie ) + { + bGameoverLoop = true; + HouseDialogPressCloseBtn(); + window_SpeakInHouse->Release(); + pParty->uFlags &= 0xFFFFFFFD; + if ( EnterHouse(HOUSE_BODY_GUILD_ERATHIA) ) + { + pAudioPlayer->PlaySound(SOUND_Invalid, 0, 0, -1, 0, 0, 0, 0); + window_SpeakInHouse = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_HouseInterior, 165, 0); + window_SpeakInHouse->CreateButton(0x3Du, 0x1A8u, 0x1Fu, 0, 2, 94, UIMSG_SelectCharacter, 1, 0x31, "", 0); + window_SpeakInHouse->CreateButton(0xB1u, 0x1A8u, 0x1Fu, 0, 2, 94, UIMSG_SelectCharacter, 2, 0x32, "", 0); + window_SpeakInHouse->CreateButton(0x124u, 0x1A8u, 0x1Fu, 0, 2, 94, UIMSG_SelectCharacter, 3, 0x33, "", 0); + window_SpeakInHouse->CreateButton(0x197u, 0x1A8u, 0x1Fu, 0, 2, 94, UIMSG_SelectCharacter, 4, 0x34, "", 0); + } + bGameoverLoop = 0; + } +} + +//----- (004BF73A) -------------------------------------------------------- +void MPlayer::SelectMovieType() +{ + char Source[32]; // [sp+Ch] [bp-40h]@1 + + strcpy(Source, this->pCurrentMovieName); + pMediaPlayer->Unload(); + if ( this->uMovieType == 1 ) + OpenHouseMovie(Source, LOBYTE(this->bLoopPlaying)); + else if ( this->uMovieType == 2 ) + OpenGlobalMovie(Source, LOBYTE(this->bLoopPlaying)); + else + __debugbreak(); +} + +void MPlayer::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) + { + if (!_stricmp(pVideoNameSmk, pMightVideoHeaders[i].pVideoName)) + { + hVidFile = hMightVid; + uOffset = pMightVideoHeaders[i].uFileOffset; + uSize = pMightVideoHeaders[i + 1].uFileOffset - uOffset; + this->uMovieType = 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->uMovieType = 1; + } + if (!_stricmp(pVideoNameSmk, pMagicVideoHeaders[i].pVideoName)) + { + hVidFile = hMagicVid; + uOffset = pMagicVideoHeaders[i].uFileOffset; + uSize = pMagicVideoHeaders[i + 1].uFileOffset - uOffset; + this->uMovieType = 2; + } + } + if (!hVidFile) + { + pMediaPlayer->Unload(); + MessageBoxA(0, "MediaPlayer error", "MediaPlayer Error", 0); + return; + } + + SetFilePointer(hVidFile, uOffset, 0, FILE_BEGIN); + strcpy(this->pCurrentMovieName, pFilename); + + auto hwnd = pMediaPlayer->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_Track = pMediaPlayer->LoadMovieFromLOD(hVidFile, &readFunction, &seekFunction, client_width, client_height); +} + + +//----- (004BF794) -------------------------------------------------------- +void MPlayer::ShowMM7IntroVideo_and_LoadingScreen() +{ + RGBTexture tex; // [sp+Ch] [bp-30h]@1 + unsigned int uTrackStartMS; // [sp+34h] [bp-8h]@8 + unsigned int uTrackEndMS; // [sp+38h] [bp-4h]@8 + + pMediaPlayer->bStopBeforeSchedule = false; +// pMediaPlayer->pResetflag = 0; + bGameoverLoop = true; + if (!bNoVideo) + { + pRenderer->PresentBlackScreen(); + if ( !pMediaPlayer->bStopBeforeSchedule ) + PlayFullscreenMovie(MOVIE_Intro, true); + } + + tex.Load("mm6title.pcx", 2); + pRenderer->BeginScene(); + pRenderer->DrawTextureRGB(0, 0, &tex); + free(tex.pPixels); + tex.pPixels = 0; + + //LoadFonts_and_DrawCopyrightWindow(); + DrawMM7CopyrightWindow(); + + pRenderer->EndScene(); + pRenderer->Present(); + + #ifndef _DEBUG + Sleep(1500); // let the copyright window stay for a while + #endif + + if (!bNoSound && pAudioPlayer->hAILRedbook ) + { + pAudioPlayer->SetMusicVolume((signed __int64)(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0)); + AIL_redbook_stop(pAudioPlayer->hAILRedbook); + AIL_redbook_track_info(pAudioPlayer->hAILRedbook, 14, &uTrackStartMS, &uTrackEndMS); + AIL_redbook_play(pAudioPlayer->hAILRedbook, uTrackStartMS + 1, uTrackEndMS); + } + bGameoverLoop = false; +} + +//----- (004BEBD7) -------------------------------------------------------- +void MPlayer::Unload() +{ + bPlaying_Movie = false; + uMovieType = 0; + memset(pCurrentMovieName, 0, 0x40); + if ( pAudioPlayer->hAILRedbook && !bGameoverLoop ) + AIL_redbook_resume(pAudioPlayer->hAILRedbook); + pEventTimer->Resume(); + + pMovie_Track->Release(); + delete pMovie_Track; + pMovie_Track = nullptr; +} + +int MPlayer::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 MPlayer::seekFunction(void* opaque, int64_t offset, int whence) +{ + if (whence == AVSEEK_SIZE) + return pMediaPlayer->uSize; + HANDLE h = (HANDLE)opaque; + LARGE_INTEGER li; + li.QuadPart = offset; + + if (!SetFilePointerEx(h, li, (PLARGE_INTEGER)&li, FILE_BEGIN)) + return -1; + return li.QuadPart; +} + + IMovie *MPlayer::LoadMovieFromLOD(HANDLE h, int readFunction(void*, uint8_t*, int), int64_t seekFunction(void*, int64_t, int), int width, int height) { movie = new Movie; @@ -1103,6 +1505,9 @@ MPlayer::MPlayer() { + bPlaying_Movie = false; + //pSmackMovieBlit = nullptr; + static int libavcodec_initialized = false; if (!libavcodec_initialized) @@ -1111,14 +1516,15 @@ avcodec_register_all(); // Register all available file formats and codecs - //инициализируем библиотеку ffmpeg(Шаг 1) - //Во время инициализации регистрируются все имеющиеся в библиотеке форматы файлов и кодеков. - //После этого они будут использоваться автоматически при открытии файлов этого формата и с этими кодеками. av_register_all(); libavcodec_initialized = true; } + bStopBeforeSchedule = false; +// pResetflag = 0; + pMovie_Track = nullptr; + if (!provider) { provider = new OpenALSoundProvider; @@ -1131,6 +1537,10 @@ { delete provider; Log::Warning(L"delete dynamic memory for provider\n"); + + bStopBeforeSchedule = false; +// pResetflag = 0; + pVideoFrame.Release(); } void PlayAudio(const wchar_t * pFilename) @@ -1154,19 +1564,4 @@ delete movie; Log::Warning(L"delete dynamic memory for movie\n"); movie = nullptr; -} - -////////////////////////////////////////////////////////////////////////// -//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; -// - +} \ No newline at end of file