1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Re-enabled video player, should now work with SDL 2

This commit is contained in:
Ivan Savenko 2014-05-24 20:12:07 +03:00 committed by AlexVinS
parent 47979d28bb
commit 6205d07223
4 changed files with 67 additions and 22 deletions

View File

@ -16,8 +16,6 @@
// Fixed width bool data type is important for serialization // Fixed width bool data type is important for serialization
static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size."); static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size.");
# define DISABLE_VIDEO
#if defined _M_X64 && defined _WIN32 //Win64 -> cannot load 32-bit DLLs for video handling #if defined _M_X64 && defined _WIN32 //Win64 -> cannot load 32-bit DLLs for video handling
# define DISABLE_VIDEO # define DISABLE_VIDEO
#endif #endif

View File

@ -605,7 +605,11 @@ CVideoPlayer::CVideoPlayer()
frame = nullptr; frame = nullptr;
codec = nullptr; codec = nullptr;
sws = nullptr; sws = nullptr;
#ifdef VCMI_SDL1
overlay = nullptr; overlay = nullptr;
#else
texture = nullptr;
#endif
dest = nullptr; dest = nullptr;
context = nullptr; context = nullptr;
@ -708,8 +712,13 @@ bool CVideoPlayer::open(std::string fname, bool loop, bool useOverlay)
// Allocate a place to put our YUV image on that screen // Allocate a place to put our YUV image on that screen
if (useOverlay) if (useOverlay)
{ {
#ifdef VCMI_SDL1
overlay = SDL_CreateYUVOverlay(codecContext->width, codecContext->height, overlay = SDL_CreateYUVOverlay(codecContext->width, codecContext->height,
SDL_YV12_OVERLAY, screen); SDL_YV12_OVERLAY, screen);
#else
texture = SDL_CreateTexture( mainRenderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STATIC, codecContext->width, codecContext->height);
#endif
} }
else else
{ {
@ -718,13 +727,18 @@ bool CVideoPlayer::open(std::string fname, bool loop, bool useOverlay)
destRect.w = codecContext->width; destRect.w = codecContext->width;
destRect.h = codecContext->height; destRect.h = codecContext->height;
} }
#ifdef VCMI_SDL1
if (overlay == nullptr && dest == nullptr) if (overlay == nullptr && dest == nullptr)
return false; return false;
// Convert the image into YUV format that SDL uses
if (overlay) if (overlay)
{ #else
if (texture == nullptr && dest == nullptr)
return false;
if (texture)
#endif
{ // Convert the image into YUV format that SDL uses
sws = sws_getContext(codecContext->width, codecContext->height, sws = sws_getContext(codecContext->width, codecContext->height,
codecContext->pix_fmt, codecContext->width, codecContext->height, codecContext->pix_fmt, codecContext->width, codecContext->height,
PIX_FMT_YUV420P, SWS_BICUBIC, nullptr, nullptr, nullptr); PIX_FMT_YUV420P, SWS_BICUBIC, nullptr, nullptr, nullptr);
@ -812,6 +826,7 @@ bool CVideoPlayer::nextFrame()
{ {
AVPicture pict; AVPicture pict;
#ifdef VCMI_SDL1
if (overlay) { if (overlay) {
SDL_LockYUVOverlay(overlay); SDL_LockYUVOverlay(overlay);
@ -827,6 +842,18 @@ bool CVideoPlayer::nextFrame()
0, codecContext->height, pict.data, pict.linesize); 0, codecContext->height, pict.data, pict.linesize);
SDL_UnlockYUVOverlay(overlay); SDL_UnlockYUVOverlay(overlay);
#else
if (texture) {
avpicture_alloc(&pict, AV_PIX_FMT_YUV420P, codecContext->width, codecContext->height);
sws_scale(sws, frame->data, frame->linesize,
0, codecContext->height, pict.data, pict.linesize);
SDL_UpdateYUVTexture(texture, NULL, pict.data[0], pict.linesize[0],
pict.data[1], pict.linesize[1],
pict.data[2], pict.linesize[2]);
avpicture_free(&pict);
#endif
} }
else else
{ {
@ -902,11 +929,21 @@ void CVideoPlayer::close()
sws = nullptr; sws = nullptr;
} }
#ifdef VCMI_SDL1
if (overlay) if (overlay)
{ {
SDL_FreeYUVOverlay(overlay); SDL_FreeYUVOverlay(overlay);
overlay = nullptr; overlay = nullptr;
} }
#else
if (texture)
{
SDL_DestroyTexture(texture);
texture = nullptr;
}
#endif
if (dest) if (dest)
{ {
@ -960,7 +997,13 @@ bool CVideoPlayer::playVideo(int x, int y, SDL_Surface *dst, bool stopOnKey)
if(stopOnKey && keyDown()) if(stopOnKey && keyDown())
return false; return false;
#ifdef VCMI_SDL1
SDL_DisplayYUVOverlay(overlay, &pos); SDL_DisplayYUVOverlay(overlay, &pos);
#else
SDL_RenderCopy(mainRenderer, texture, NULL, NULL);
SDL_RenderPresent(mainRenderer);
#endif
// Wait 3 frames // Wait 3 frames
GH.mainFPSmng->framerateDelay(); GH.mainFPSmng->framerateDelay();

View File

@ -242,7 +242,12 @@ class CVideoPlayer : public IMainVideoPlayer
AVIOContext * context; AVIOContext * context;
// Destination. Either overlay or dest. // Destination. Either overlay or dest.
SDL_Overlay *overlay; #ifdef VCMI_SDL1
SDL_Overlay overlay;
#else
SDL_Texture *texture;
#endif
SDL_Surface *dest; SDL_Surface *dest;
SDL_Rect destRect; // valid when dest is used SDL_Rect destRect; // valid when dest is used
SDL_Rect pos; // destination on screen SDL_Rect pos; // destination on screen

View File

@ -222,7 +222,6 @@ std::vector<std::string> VCMIDirs::dataPaths() const
{ {
std::string dataDirsEnv = getenv("XDG_DATA_DIRS"); std::string dataDirsEnv = getenv("XDG_DATA_DIRS");
std::vector<std::string> dataDirs; std::vector<std::string> dataDirs;
std::cout << dataDirsEnv;
boost::split(dataDirs, dataDirsEnv, boost::is_any_of(":")); boost::split(dataDirs, dataDirsEnv, boost::is_any_of(":"));
for (auto & entry : boost::adaptors::reverse(dataDirs)) for (auto & entry : boost::adaptors::reverse(dataDirs))
ret.push_back(entry + "/vcmi"); ret.push_back(entry + "/vcmi");