- added support for intro videos using libvlc (if libvlc is installed for the developer, its optional)

This commit is contained in:
Mark Vejvoda 2012-05-12 20:33:18 +00:00
parent 345b2e670b
commit 7b3de2d109
9 changed files with 391 additions and 7 deletions

View File

@ -0,0 +1,78 @@
# CMake module to search for LIBVLC (VLC library)
# Author: Rohit Yadav <rohityadav89@gmail.com>
#
# If it's found it sets LIBVLC_FOUND to TRUE
# and following variables are set:
# LIBVLC_INCLUDE_DIR
# LIBVLC_LIBRARY
# FIND_PATH and FIND_LIBRARY normally search standard locations
# before the specified paths. To search non-standard paths first,
# FIND_* is invoked first with specified paths and NO_DEFAULT_PATH
# and then again with no specified paths to search the default
# locations. When an earlier FIND_* succeeds, subsequent FIND_*s
# searching for the same item do nothing.
#Put here path to custom location
#example: /home/user/vlc/include etc..
FIND_PATH(LIBVLC_INCLUDE_DIR vlc/vlc.h
HINTS "$ENV{LIBVLC_INCLUDE_PATH}"
PATHS
#Mac OS and Contribs
"${CMAKE_CURRENT_SOURCE_DIR}/contribs/include"
"${CMAKE_CURRENT_SOURCE_DIR}/contribs/include/vlc"
# Env
"$ENV{LIB_DIR}/include"
"$ENV{LIB_DIR}/include/vlc"
#
"/usr/include"
"/usr/include/vlc"
"/usr/local/include"
"/usr/local/include/vlc"
#mingw
c:/msys/local/include
)
FIND_PATH(LIBVLC_INCLUDE_DIR PATHS "${CMAKE_INCLUDE_PATH}/vlc" NAMES vlc.h)
#Put here path to custom location
#example: /home/user/vlc/lib etc..
FIND_LIBRARY(LIBVLC_LIBRARY NAMES vlc libvlc
HINTS "$ENV{LIBVLC_LIBRARY_PATH}"
PATHS
"$ENV{LIB_DIR}/lib"
#Mac OS
"${CMAKE_CURRENT_SOURCE_DIR}/contribs/lib"
"${CMAKE_CURRENT_SOURCE_DIR}/contribs/plugins"
#mingw
c:/msys/local/lib
)
FIND_LIBRARY(LIBVLC_LIBRARY NAMES vlc libvlc)
FIND_LIBRARY(LIBVLCCORE_LIBRARY NAMES vlccore libvlccore
HINTS "$ENV{LIBVLC_LIBRARY_PATH}"
PATHS
"$ENV{LIB_DIR}/lib"
#Mac OS
"${CMAKE_CURRENT_SOURCE_DIR}/contribs/lib"
"${CMAKE_CURRENT_SOURCE_DIR}/contribs/plugins"
#mingw
c:/msys/local/lib
)
FIND_LIBRARY(LIBVLCCORE_LIBRARY NAMES vlccore libvlccore)
IF (LIBVLC_INCLUDE_DIR AND LIBVLC_LIBRARY AND LIBVLCCORE_LIBRARY)
SET(LIBVLC_FOUND TRUE)
ENDIF (LIBVLC_INCLUDE_DIR AND LIBVLC_LIBRARY AND LIBVLCCORE_LIBRARY)
IF (LIBVLC_FOUND)
IF (NOT LIBVLC_FIND_QUIETLY)
MESSAGE(STATUS "Found LibVLC include-dir path: ${LIBVLC_INCLUDE_DIR}")
MESSAGE(STATUS "Found LibVLC library path:${LIBVLC_LIBRARY}")
MESSAGE(STATUS "Found LibVLCcore library path:${LIBVLCCORE_LIBRARY}")
ENDIF (NOT LIBVLC_FIND_QUIETLY)
ELSE (LIBVLC_FOUND)
IF (LIBVLC_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find LibVLC")
ENDIF (LIBVLC_FIND_REQUIRED)
ENDIF (LIBVLC_FOUND)

View File

@ -28,12 +28,12 @@ elif [ -f /etc/fedora-release ]; then
sudo yum install SDL-devel xerces-c-devel mesa-libGL-devel mesa-libGLU-devel libvorbis-devel wxBase wxGTK-devel lua-devel libjpeg-devel libpng-devel libcurl-devel openal-soft-devel libX11-devel libxml2-dev libircclient-dev glew-devel ftgl-devel
elif [ "$OSTYPE" = "i686" ] && [ "$version" = "Ubuntu" ]; then
echo "=====> Using build deps for old Ubuntu 8.04..."
sudo apt-get install libsdl1.2-dev libxerces28-dev libalut-dev libgl1-mesa-dev libglu1-mesa-dev libvorbis-dev libwxbase2.8-dev libwxgtk2.8-dev libx11-dev liblua5.1-0-dev libjpeg-dev libpng12-dev libcurl4-gnutls-dev libxml2-dev libircclient-dev libglew-dev libluajit-5.1-dev
sudo apt-get install libsdl1.2-dev libxerces28-dev libalut-dev libgl1-mesa-dev libglu1-mesa-dev libvorbis-dev libwxbase2.8-dev libwxgtk2.8-dev libx11-dev liblua5.1-0-dev libjpeg-dev libpng12-dev libcurl4-gnutls-dev libxml2-dev libircclient-dev libglew-dev libluajit-5.1-dev libvlc-dev
elif [ "$OSTYPE" = "x86_64" ]; then
echo "=====> Using build deps for debian based 64 bit linux..."
sudo apt-get install libsdl1.2-dev libxerces-c2-dev libalut-dev libgl1-mesa-dev libglu1-mesa-dev libvorbis-dev libwxbase2.8-dev libwxgtk2.8-dev libx11-dev liblua5.1-0-dev libjpeg-dev libpng12-dev libcurl4-gnutls-dev cmake-curses-gui libgtk2.0-dev libxml2-dev libircclient-dev libftgl-dev libminiupnpc-dev libglew-dev librtmp-dev libluajit-5.1-dev
sudo apt-get install libsdl1.2-dev libxerces-c2-dev libalut-dev libgl1-mesa-dev libglu1-mesa-dev libvorbis-dev libwxbase2.8-dev libwxgtk2.8-dev libx11-dev liblua5.1-0-dev libjpeg-dev libpng12-dev libcurl4-gnutls-dev cmake-curses-gui libgtk2.0-dev libxml2-dev libircclient-dev libftgl-dev libminiupnpc-dev libglew-dev librtmp-dev libluajit-5.1-dev libvlc-dev
else
echo "=====> Using build deps for debian based 32 bit Linux..."
sudo apt-get install libsdl1.2-dev libxerces-c2-dev libalut-dev libgl1-mesa-dev libglu1-mesa-dev libvorbis-dev libwxbase2.8-dev libwxgtk2.8-dev libx11-dev liblua5.1-0-dev libjpeg-dev libpng12-dev libcurl4-gnutls-dev cmake-curses-gui libgtk2.0-dev libxml2-dev libircclient-dev libftgl-dev libminiupnpc-dev libglew-dev librtmp-dev libluajit-5.1-dev
echo "=====> Using build deps for debian based 32 or 64 bit Linux..."
sudo apt-get install libsdl1.2-dev libxerces-c2-dev libalut-dev libgl1-mesa-dev libglu1-mesa-dev libvorbis-dev libwxbase2.8-dev libwxgtk2.8-dev libx11-dev liblua5.1-0-dev libjpeg-dev libpng12-dev libcurl4-gnutls-dev cmake-curses-gui libgtk2.0-dev libxml2-dev libircclient-dev libftgl-dev libminiupnpc-dev libglew-dev librtmp-dev libluajit-5.1-dev libvlc-dev
fi

View File

@ -24,6 +24,9 @@
//#include "glm.h"
//#include "md5util.h"
//#include "Mathlib.h"
#include "video_player.h"
#include "leak_dumper.h"
using namespace Shared::Util;
@ -489,6 +492,20 @@ Intro::Intro(Program *program):
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(VideoPlayer::hasBackEndVideoPlayer() == true) {
//string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
string introVideoFile = getGameCustomCoreDataPath(data_path, "data/core/menu/videos/intro.avi");
if(fileExists(introVideoFile)) {
Context *c= GraphicsInterface::getInstance().getCurrentContext();
SDL_Surface *screen = static_cast<ContextGl*>(c)->getPlatformContextGlPtr()->getScreen();
//printf("screen->w = %d screen->h = %d screen->format->BitsPerPixel = %d\n",screen->w,screen->h,screen->format->BitsPerPixel);
VideoPlayer player(introVideoFile.c_str(),screen,screen->w,screen->h,screen->format->BitsPerPixel);
player.PlayVideo();
return;
}
}
soundRenderer.playMusic(CoreData::getInstance().getIntroMusic());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -616,6 +633,7 @@ void Intro::render() {
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
return;
}
int difTime=0;
canRender();

View File

@ -116,7 +116,7 @@ IF(BUILD_MEGAGLEST_MODEL_VIEWER OR BUILD_MEGAGLEST_MAP_EDITOR OR BUILD_MEGAGLEST
INCLUDE_DIRECTORIES(${LUAJIT_INCLUDE_DIR})
IF(UNIX)
SET(EXTERNAL_LIBS ${EXTERNAL_LIBS} ${LUAJIT_LIBRARIES})
SET(EXTERNAL_LIBS ${EXTERNAL_LIBS} ${LUAJIT_LIBRARIES} "libdl.so")
ENDIF()
ELSE()
MESSAGE(STATUS "**WARNING: LUAJIT NOT found and will grealy affect Lua performance.")
@ -124,7 +124,7 @@ IF(BUILD_MEGAGLEST_MODEL_VIEWER OR BUILD_MEGAGLEST_MAP_EDITOR OR BUILD_MEGAGLEST
FIND_PACKAGE(LUA REQUIRED)
INCLUDE_DIRECTORIES(${LUA_INCLUDE_DIR})
IF(UNIX)
SET(EXTERNAL_LIBS ${EXTERNAL_LIBS} ${LUA_LIBRARIES})
SET(EXTERNAL_LIBS ${EXTERNAL_LIBS} ${LUA_LIBRARIES} "libdl.so")
ENDIF()
ENDIF()
@ -228,6 +228,18 @@ IF(BUILD_MEGAGLEST_MODEL_VIEWER OR BUILD_MEGAGLEST_MAP_EDITOR OR BUILD_MEGAGLEST
SET(EXTERNAL_LIBS ${EXTERNAL_LIBS} ${GLEW_LIBRARY})
ENDIF()
FIND_PACKAGE(LIBVLC)
IF(LIBVLC_FOUND)
MESSAGE(STATUS "**NOTE: LIBVLC found so intro videos are supported.")
INCLUDE_DIRECTORIES(${LIBVLC_INCLUDE_DIR})
IF(UNIX)
SET(EXTERNAL_LIBS ${EXTERNAL_LIBS} ${LIBVLC_LIBRARY})
ADD_DEFINITIONS(-DHAS_LIBVLC)
ENDIF()
ELSE()
MESSAGE(STATUS "**WARNING: LIBVLC NOT found so intro videos are NOT supported.")
ENDIF()
#########################################################################################
# megaglest lib

View File

@ -40,6 +40,7 @@ public:
virtual void swapBuffers();
const PlatformContextGl *getPlatformContextGl() const {return &pcgl;}
PlatformContextGl *getPlatformContextGlPtr() {return &pcgl;}
};
}}}//end namespace

View File

@ -0,0 +1,40 @@
// ==============================================================
// This file is part of MegaGlest Shared Library (www.glest.org)
//
// Copyright (C) 2012 Mark Vejvoda (mark_vejvoda@hotmail.com)
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#ifndef VIDEO_PLAYER_H_
#define VIDEO_PLAYER_H_
#include <string>
class SDL_Surface;
using namespace std;
class VideoPlayer {
protected:
string filename;
SDL_Surface *surface;
int width;
int height;
int colorBits;
bool stop;
public:
VideoPlayer(string filename, SDL_Surface *surface, int width, int height,int colorBits);
virtual ~VideoPlayer();
void PlayVideo();
void StopVideo() { stop = true; }
static bool hasBackEndVideoPlayer();
};
#endif /* VIDEO_PLAYER_H_ */

View File

@ -59,6 +59,8 @@ public:
virtual void makeCurrent();
virtual void swapBuffers();
SDL_Surface * getScreen() { return screen; }
DeviceContextHandle getHandle() const { return 0; }
};

View File

@ -0,0 +1,234 @@
// ==============================================================
// This file is part of MegaGlest Shared Library (www.glest.org)
//
// Copyright (C) 2012 Mark Vejvoda (mark_vejvoda@hotmail.com)
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#include <GL/glew.h>
#include "video_player.h"
#include <SDL/SDL.h>
#include <SDL/SDL_mutex.h>
#ifdef HAS_LIBVLC
#include <vlc/vlc.h>
#endif
struct ctx {
GLuint textureId; // Texture ID
SDL_Surface *surf;
SDL_mutex *mutex;
int width;
int height;
void *rawData;
};
// Load a texture
static void loadTexture(struct ctx *ctx) {
void *rawData = ctx->rawData;
Uint8 * pixelSource = 0;
Uint8 * pixelDestination = (Uint8 *) rawData;
Uint32 pix = 0;
for (unsigned int i = ctx->height; i > 0; i--) {
for (unsigned int j = 0; j < ctx->width; j++) {
pixelSource = (Uint8 *) ctx->surf->pixels + (i-1) * ctx->surf->pitch + j * 2;
pix = *(Uint16 *) pixelSource;
SDL_GetRGBA(pix, ctx->surf->format, &(pixelDestination[0]), &(pixelDestination[1]), &(pixelDestination[2]), &(pixelDestination[3]));
pixelDestination += 4;
}
}
// Building the texture
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindTexture(GL_TEXTURE_2D, ctx->textureId);
glTexImage2D(GL_TEXTURE_2D, 0, 4, ctx->width, ctx->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (Uint8 *) rawData);
}
static void *lock(void *data, void **p_pixels) {
struct ctx *ctx = (struct ctx *)data;
SDL_LockMutex(ctx->mutex);
SDL_LockSurface(ctx->surf);
*p_pixels = ctx->surf->pixels;
return NULL; /* picture identifier, not needed here */
}
static void unlock(void *data, void *id, void *const *p_pixels) {
struct ctx *ctx = (struct ctx *)data;
/* VLC just rendered the video, but we can also render stuff */
SDL_UnlockSurface(ctx->surf);
SDL_UnlockMutex(ctx->mutex);
}
static void display(void *data, void *id) {
/* VLC wants to display the video */
(void) data;
}
VideoPlayer::VideoPlayer(string filename, SDL_Surface *surface,
int width, int height,int colorBits) {
this->filename = filename;
this->surface = surface;
this->width = width;
this->height = height;
this->colorBits = colorBits;
this->stop = false;
}
VideoPlayer::~VideoPlayer() {
}
bool VideoPlayer::hasBackEndVideoPlayer() {
#ifdef HAS_LIBVLC
return true;
#endif
return false;
}
void VideoPlayer::PlayVideo() {
#ifdef HAS_LIBVLC
libvlc_instance_t *libvlc = NULL;
libvlc_media_t *m = NULL;
libvlc_media_player_t *mp = NULL;
char const *vlc_argv[] =
{
//"--no-audio", /* skip any audio track */
"--no-xlib", /* tell VLC to not use Xlib */
"--no-video-title-show",
};
int vlc_argc = sizeof(vlc_argv) / sizeof(*vlc_argv);
#endif
SDL_Surface *empty = NULL;
SDL_Event event;
int done = 0, action = 0, pause = 0, n = 0;
struct ctx ctx;
ctx.width = width;
ctx.height = height;
ctx.rawData = (void *) malloc(width * height * 4);
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
// Init Texture
glGenTextures(1, &ctx.textureId);
glBindTexture(GL_TEXTURE_2D, ctx.textureId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
empty = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
colorBits, 0, 0, 0, 0);
ctx.surf = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
colorBits, 0x001f, 0x07e0, 0xf800, 0);
ctx.mutex = SDL_CreateMutex();
#ifdef HAS_LIBVLC
/*
* Initialise libVLC
*/
libvlc = libvlc_new(vlc_argc, vlc_argv);
m = libvlc_media_new_path(libvlc, filename.c_str());
mp = libvlc_media_player_new_from_media(m);
libvlc_media_release(m);
libvlc_video_set_callbacks(mp, lock, unlock, display, &ctx);
libvlc_video_set_format(mp, "RV16", width, height, this->surface->pitch);
libvlc_media_player_play(mp);
#endif
/*
* Main loop
*/
bool needToQuit = false;
while(!done && stop == false) {
action = 0;
/* Keys: enter (fullscreen), space (pause), escape (quit) */
while( SDL_PollEvent( &event ) ) {
switch(event.type) {
case SDL_QUIT:
done = 1;
needToQuit = true;
break;
case SDL_KEYDOWN:
action = event.key.keysym.sym;
break;
case SDL_MOUSEBUTTONDOWN:
done = 1;
break;
}
}
if(!done && stop == false) {
switch(action) {
case SDLK_ESCAPE:
done = 1;
break;
case SDLK_RETURN:
//options ^= SDL_FULLSCREEN;
//screen = SDL_SetVideoMode(WIDTH, HEIGHT, 0, options);
done = 1;
break;
case ' ':
//pause = !pause;
break;
}
if(!pause) {
n++;
}
loadTexture(&ctx); // Loading the texture
// Square
glBegin(GL_QUADS);
glTexCoord2d(0, 1);
glVertex2f(-0.85, 0.85);
glTexCoord2d(1, 1);
glVertex2f(0.85, 0.85);
glTexCoord2d(1, 0);
glVertex2f(0.85, -0.85);
glTexCoord2d(0, 0);
glVertex2f(-0.85, -0.85);
glEnd();
SDL_GL_SwapBuffers();
}
}
#ifdef HAS_LIBVLC
/*
* Stop stream and clean up libVLC
*/
libvlc_media_player_stop(mp);
libvlc_media_player_release(mp);
libvlc_release(libvlc);
#endif
/*
* Close window and clean up libSDL
*/
SDL_DestroyMutex(ctx.mutex);
SDL_FreeSurface(ctx.surf);
SDL_FreeSurface(empty);
glDeleteTextures(1, &ctx.textureId);
free(ctx.rawData);
if(needToQuit == true) {
SDL_Event quit_event = {SDL_QUIT};
SDL_PushEvent(&quit_event);
}
}

View File

@ -156,7 +156,6 @@ void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,
screen = NULL;
}
screen = SDL_SetVideoMode(resW, resH, colorBits, flags);
if(screen == 0) {
std::ostringstream msg;