- added support for main menu background video
This commit is contained in:
parent
3187252936
commit
0d38e2eb5d
|
@ -21,6 +21,7 @@
|
|||
#include "game_util.h"
|
||||
#include "lang.h"
|
||||
#include "game_settings.h"
|
||||
#include "video_player.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace Shared::Sound;
|
||||
|
@ -76,6 +77,9 @@ CoreData::CoreData() {
|
|||
menuFontBig3D=NULL;
|
||||
menuFontVeryBig3D=NULL;
|
||||
consoleFont3D=NULL;
|
||||
|
||||
introVideoFilename="";
|
||||
mainMenuVideoFilename="";
|
||||
}
|
||||
|
||||
CoreData::~CoreData() {
|
||||
|
@ -397,6 +401,51 @@ void CoreData::load() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false &&
|
||||
Shared::Graphics::VideoPlayer::hasBackEndVideoPlayer() == true) {
|
||||
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
|
||||
|
||||
introVideoFilename = "";
|
||||
string introVideoPath = getGameCustomCoreDataPath(data_path, "") + "data/core/menu/videos/intro.*";
|
||||
vector<string> introVideos;
|
||||
findAll(introVideoPath, introVideos, false, false);
|
||||
for(int i = 0; i < introVideos.size(); ++i) {
|
||||
string video = getGameCustomCoreDataPath(data_path, "") + "data/core/menu/videos/" + introVideos[i];
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Checking if intro video [%s] exists\n",video.c_str());
|
||||
|
||||
if(fileExists(video)) {
|
||||
introVideoFilename = video;
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("FOUND intro video [%s] will use this file\n",video.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mainMenuVideoFilename = "";
|
||||
string mainVideoPath = getGameCustomCoreDataPath(data_path, "") + "data/core/menu/videos/main.*";
|
||||
vector<string> mainVideos;
|
||||
findAll(mainVideoPath, mainVideos, false, false);
|
||||
for(int i = 0; i < mainVideos.size(); ++i) {
|
||||
string video = getGameCustomCoreDataPath(data_path, "") + "data/core/menu/videos/" + mainVideos[i];
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Checking if intro video [%s] exists\n",video.c_str());
|
||||
|
||||
if(fileExists(video)) {
|
||||
mainMenuVideoFilename = video;
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("FOUND intro video [%s] will use this file\n",video.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CoreData::hasIntroVideoFilename() const {
|
||||
bool result = (introVideoFilename != "" && fileExists(introVideoFilename) == true);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool CoreData::hasMainMenuVideoFilename() const {
|
||||
bool result = (mainMenuVideoFilename != "" && fileExists(mainMenuVideoFilename) == true);
|
||||
return result;
|
||||
}
|
||||
|
||||
void CoreData::loadFonts() {
|
||||
|
|
|
@ -88,6 +88,9 @@ private:
|
|||
Font3D *menuFontVeryBig3D;
|
||||
Font3D *consoleFont3D;
|
||||
|
||||
string introVideoFilename;
|
||||
string mainMenuVideoFilename;
|
||||
|
||||
public:
|
||||
|
||||
enum TextureSystemType {
|
||||
|
@ -174,6 +177,12 @@ public:
|
|||
Font3D *getMenuFontVeryBig3D() const {return menuFontVeryBig3D;}
|
||||
Font3D *getConsoleFont3D() const {return consoleFont3D;}
|
||||
|
||||
string getMainMenuVideoFilename() const { return mainMenuVideoFilename; }
|
||||
bool hasMainMenuVideoFilename() const;
|
||||
|
||||
string getIntroVideoFilename() const { return introVideoFilename; }
|
||||
bool hasIntroVideoFilename() const;
|
||||
|
||||
void saveGameSettingsToFile(std::string fileName, GameSettings *gameSettings,int advancedIndex=0);
|
||||
bool loadGameSettingsFromFile(std::string fileName, GameSettings *gameSettings);
|
||||
|
||||
|
|
|
@ -80,7 +80,9 @@ BattleEnd::~BattleEnd() {
|
|||
delete originState;
|
||||
originState = NULL;
|
||||
|
||||
SoundRenderer::getInstance().playMusic(CoreData::getInstance().getMenuMusic());
|
||||
if(CoreData::getInstance().hasMainMenuVideoFilename() == false) {
|
||||
SoundRenderer::getInstance().playMusic(CoreData::getInstance().getMenuMusic());
|
||||
}
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
|
|
|
@ -493,32 +493,19 @@ 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");
|
||||
string introVideoFile = "";
|
||||
string introVideoPath = getGameCustomCoreDataPath(data_path, "") + "data/core/menu/videos/intro.*";
|
||||
vector<string> introVideos;
|
||||
findAll(introVideoPath, introVideos, false, false);
|
||||
for(int i = 0; i < introVideos.size(); ++i) {
|
||||
string video = getGameCustomCoreDataPath(data_path, "") + "data/core/menu/videos/" + introVideos[i];
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Checking if intro video [%s] exists\n",video.c_str());
|
||||
|
||||
if(fileExists(video)) {
|
||||
introVideoFile = video;
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("FOUND intro video [%s] will use this file\n",video.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false &&
|
||||
Shared::Graphics::VideoPlayer::hasBackEndVideoPlayer() == true &&
|
||||
CoreData::getInstance().hasIntroVideoFilename() == true) {
|
||||
string introVideoFile = CoreData::getInstance().getIntroVideoFilename();
|
||||
if(fileExists(introVideoFile)) {
|
||||
Context *c= GraphicsInterface::getInstance().getCurrentContext();
|
||||
SDL_Surface *screen = static_cast<ContextGl*>(c)->getPlatformContextGlPtr()->getScreen();
|
||||
|
||||
string vlcPluginsPath = Config::getInstance().getString("VideoPlayerPluginsPath","");
|
||||
//printf("screen->w = %d screen->h = %d screen->format->BitsPerPixel = %d\n",screen->w,screen->h,screen->format->BitsPerPixel);
|
||||
VideoPlayer player(introVideoFile.c_str(),
|
||||
Shared::Graphics::VideoPlayer player(introVideoFile.c_str(),
|
||||
screen,
|
||||
-1,-1,
|
||||
screen->w,
|
||||
screen->h,
|
||||
screen->format->BitsPerPixel,
|
||||
|
@ -548,7 +535,8 @@ Intro::~Intro() {
|
|||
|
||||
void Intro::update() {
|
||||
if(exitAfterIntroVideo == true) {
|
||||
mouseUpLeft(0, 0);
|
||||
//mouseUpLeft(0, 0);
|
||||
cleanup();
|
||||
return;
|
||||
}
|
||||
timer++;
|
||||
|
@ -854,7 +842,9 @@ void Intro::mouseUpLeft(int x, int y) {
|
|||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
soundRenderer.playMusic(CoreData::getInstance().getMenuMusic());
|
||||
if(CoreData::getInstance().hasMainMenuVideoFilename() == false) {
|
||||
soundRenderer.playMusic(CoreData::getInstance().getMenuMusic());
|
||||
}
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "network_message.h"
|
||||
#include "socket.h"
|
||||
#include "menu_state_root.h"
|
||||
#include "video_player.h"
|
||||
|
||||
#include "leak_dumper.h"
|
||||
|
||||
|
@ -44,9 +45,7 @@ namespace Glest{ namespace Game{
|
|||
// ===================== PUBLIC ========================
|
||||
MenuState * MainMenu::oldstate=NULL;
|
||||
|
||||
MainMenu::MainMenu(Program *program):
|
||||
ProgramState(program)
|
||||
{
|
||||
MainMenu::MainMenu(Program *program) : ProgramState(program), menuBackgroundVideo(NULL) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
mouseX=100;
|
||||
|
@ -71,6 +70,11 @@ void MainMenu::reloadUI() {
|
|||
MainMenu::~MainMenu() {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
if(menuBackgroundVideo != NULL) {
|
||||
menuBackgroundVideo->closePlayer();
|
||||
delete menuBackgroundVideo;
|
||||
menuBackgroundVideo = NULL;
|
||||
}
|
||||
delete state;
|
||||
state = NULL;
|
||||
delete oldstate;
|
||||
|
@ -90,16 +94,33 @@ MainMenu::~MainMenu() {
|
|||
|
||||
void MainMenu::init() {
|
||||
Renderer::getInstance().initMenu(this);
|
||||
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false &&
|
||||
Shared::Graphics::VideoPlayer::hasBackEndVideoPlayer() == true) {
|
||||
string introVideoFile = CoreData::getInstance().getMainMenuVideoFilename();
|
||||
if(introVideoFile != "" && fileExists(introVideoFile)) {
|
||||
Context *c= GraphicsInterface::getInstance().getCurrentContext();
|
||||
SDL_Surface *screen = static_cast<ContextGl*>(c)->getPlatformContextGlPtr()->getScreen();
|
||||
|
||||
string vlcPluginsPath = Config::getInstance().getString("VideoPlayerPluginsPath","");
|
||||
//printf("screen->w = %d screen->h = %d screen->format->BitsPerPixel = %d\n",screen->w,screen->h,screen->format->BitsPerPixel);
|
||||
menuBackgroundVideo = new VideoPlayer(introVideoFile.c_str(),
|
||||
screen,
|
||||
0,0,
|
||||
screen->w,
|
||||
screen->h,
|
||||
screen->format->BitsPerPixel,
|
||||
vlcPluginsPath,
|
||||
SystemFlags::VERBOSE_MODE_ENABLED);
|
||||
menuBackgroundVideo->initPlayer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//asynchronus render update
|
||||
void MainMenu::render() {
|
||||
|
||||
//Config &config= Config::getInstance();
|
||||
Renderer &renderer= Renderer::getInstance();
|
||||
//CoreData &coreData= CoreData::getInstance();
|
||||
|
||||
//fps++;
|
||||
canRender();
|
||||
incrementFps();
|
||||
|
||||
|
@ -109,14 +130,22 @@ void MainMenu::render() {
|
|||
|
||||
//3d
|
||||
renderer.reset3dMenu();
|
||||
|
||||
renderer.clearZBuffer();
|
||||
renderer.loadCameraMatrix(menuBackground.getCamera());
|
||||
renderer.renderMenuBackground(&menuBackground);
|
||||
renderer.renderParticleManager(rsMenu);
|
||||
|
||||
if(menuBackgroundVideo == NULL) {
|
||||
renderer.loadCameraMatrix(menuBackground.getCamera());
|
||||
renderer.renderMenuBackground(&menuBackground);
|
||||
renderer.renderParticleManager(rsMenu);
|
||||
}
|
||||
|
||||
//2d
|
||||
renderer.reset2d();
|
||||
|
||||
if(menuBackgroundVideo != NULL) {
|
||||
if(menuBackgroundVideo->isPlaying() == true) {
|
||||
menuBackgroundVideo->playFrame(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
state->render();
|
||||
|
||||
|
@ -130,9 +159,13 @@ void MainMenu::render() {
|
|||
|
||||
//syncronus update
|
||||
void MainMenu::update(){
|
||||
Renderer::getInstance().updateParticleManager(rsMenu);
|
||||
if(menuBackgroundVideo != NULL) {
|
||||
Renderer::getInstance().updateParticleManager(rsMenu);
|
||||
}
|
||||
mouse2dAnim= (mouse2dAnim +1) % Renderer::maxMouse2dAnim;
|
||||
menuBackground.update();
|
||||
if(menuBackgroundVideo != NULL) {
|
||||
menuBackground.update();
|
||||
}
|
||||
state->update();
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,10 @@
|
|||
#include "game_settings.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
namespace Shared { namespace Graphics {
|
||||
class VideoPlayer;
|
||||
}}
|
||||
|
||||
namespace Glest{ namespace Game{
|
||||
|
||||
class MenuState;
|
||||
|
@ -47,6 +51,7 @@ private:
|
|||
//shared
|
||||
GameSettings gameSettings;
|
||||
MenuBackground menuBackground;
|
||||
Shared::Graphics::VideoPlayer *menuBackgroundVideo;
|
||||
|
||||
MenuState *state;
|
||||
|
||||
|
|
|
@ -1158,7 +1158,9 @@ void MenuStateOptions::saveConfig(){
|
|||
soundRenderer.setMusicVolume(CoreData::getInstance().getMenuMusic());
|
||||
program->startSoundSystem();
|
||||
|
||||
soundRenderer.playMusic(CoreData::getInstance().getMenuMusic());
|
||||
if(CoreData::getInstance().hasMainMenuVideoFilename() == false) {
|
||||
soundRenderer.playMusic(CoreData::getInstance().getMenuMusic());
|
||||
}
|
||||
|
||||
Renderer::getInstance().loadConfig();
|
||||
}
|
||||
|
|
|
@ -14,31 +14,52 @@
|
|||
#include <string>
|
||||
|
||||
class SDL_Surface;
|
||||
class ctx;
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
class VideoPlayer {
|
||||
protected:
|
||||
|
||||
string filename;
|
||||
SDL_Surface *surface;
|
||||
int x;
|
||||
int y;
|
||||
int width;
|
||||
int height;
|
||||
int colorBits;
|
||||
|
||||
bool successLoadingLib;
|
||||
string pluginsPath;
|
||||
bool verboseEnabled;
|
||||
|
||||
bool stop;
|
||||
bool finished;
|
||||
|
||||
ctx *ctxPtr;
|
||||
|
||||
void init();
|
||||
|
||||
public:
|
||||
VideoPlayer(string filename, SDL_Surface *surface, int width, int height,
|
||||
int colorBits, string pluginsPath,bool verboseEnabled=false);
|
||||
VideoPlayer(string filename, SDL_Surface *surface, int x, int y,
|
||||
int width, int height, int colorBits,
|
||||
string pluginsPath,bool verboseEnabled=false);
|
||||
virtual ~VideoPlayer();
|
||||
|
||||
void PlayVideo();
|
||||
void StopVideo() { stop = true; }
|
||||
|
||||
bool initPlayer();
|
||||
void closePlayer();
|
||||
|
||||
bool playFrame(bool swapBuffers = true);
|
||||
bool isPlaying() const;
|
||||
|
||||
static bool hasBackEndVideoPlayer();
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif /* VIDEO_PLAYER_H_ */
|
||||
|
|
|
@ -66,17 +66,56 @@ std::string getRegKey(const std::string& location, const std::string& name){
|
|||
}
|
||||
#endif
|
||||
|
||||
struct ctx {
|
||||
class ctx {
|
||||
public:
|
||||
ctx() {
|
||||
empty = NULL;
|
||||
textureId = 0; // Texture ID
|
||||
surf = NULL;
|
||||
mutex = NULL;
|
||||
x= 0;
|
||||
y = 0;
|
||||
width = 0;
|
||||
height = 0;
|
||||
rawData = NULL;
|
||||
isPlaying = 0;
|
||||
needToQuit = false;
|
||||
verboseEnabled = 0;
|
||||
|
||||
#ifdef HAS_LIBVLC
|
||||
libvlc = NULL;
|
||||
m = NULL;
|
||||
mp = NULL;
|
||||
vlc_argv.clear();
|
||||
vlc_argv_str.clear();
|
||||
#endif
|
||||
}
|
||||
|
||||
SDL_Surface *empty;
|
||||
GLuint textureId; // Texture ID
|
||||
SDL_Surface *surf;
|
||||
SDL_mutex *mutex;
|
||||
int x;
|
||||
int y;
|
||||
int width;
|
||||
int height;
|
||||
void *rawData;
|
||||
bool isPlaying;
|
||||
bool needToQuit;
|
||||
bool verboseEnabled;
|
||||
|
||||
#ifdef HAS_LIBVLC
|
||||
libvlc_instance_t *libvlc;
|
||||
libvlc_media_t *m;
|
||||
libvlc_media_player_t *mp;
|
||||
|
||||
std::vector<const char *> vlc_argv;
|
||||
std::vector<string> vlc_argv_str;
|
||||
#endif
|
||||
};
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// Load a texture
|
||||
static void loadTexture(struct ctx *ctx) {
|
||||
if(ctx->verboseEnabled) printf("In [%s] Line: %d\n",__FUNCTION__,__LINE__);
|
||||
|
@ -165,21 +204,45 @@ void trapErrorEvent(const libvlc_event_t *evt, void *data) {
|
|||
#endif
|
||||
|
||||
VideoPlayer::VideoPlayer(string filename, SDL_Surface *surface,
|
||||
int width, int height,int colorBits,string pluginsPath,
|
||||
bool verboseEnabled) {
|
||||
int x, int y,int width, int height,int colorBits,string pluginsPath,
|
||||
bool verboseEnabled) : ctxPtr(NULL) {
|
||||
this->filename = filename;
|
||||
this->surface = surface;
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
this->colorBits = colorBits;
|
||||
this->pluginsPath = pluginsPath;
|
||||
this->verboseEnabled = verboseEnabled;
|
||||
|
||||
this->stop = false;
|
||||
this->finished = false;
|
||||
this->successLoadingLib = false;
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
void VideoPlayer::init() {
|
||||
//verboseEnabled = true;
|
||||
ctxPtr = new ctx();
|
||||
ctxPtr->x = x;
|
||||
ctxPtr->y = y;
|
||||
ctxPtr->width = width;
|
||||
ctxPtr->height = height;
|
||||
ctxPtr->rawData = (void *) malloc(width * height * 4);
|
||||
ctxPtr->verboseEnabled = verboseEnabled;
|
||||
}
|
||||
|
||||
VideoPlayer::~VideoPlayer() {
|
||||
if(ctxPtr != NULL) {
|
||||
if(ctxPtr->rawData != NULL) {
|
||||
free(ctxPtr->rawData);
|
||||
ctxPtr->rawData = NULL;
|
||||
}
|
||||
|
||||
delete ctxPtr;
|
||||
ctxPtr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool VideoPlayer::hasBackEndVideoPlayer() {
|
||||
|
@ -188,14 +251,255 @@ bool VideoPlayer::hasBackEndVideoPlayer() {
|
|||
#endif
|
||||
return false;
|
||||
}
|
||||
void VideoPlayer::PlayVideo() {
|
||||
//verboseEnabled = true;
|
||||
struct ctx ctx;
|
||||
ctx.width = width;
|
||||
ctx.height = height;
|
||||
ctx.rawData = (void *) malloc(width * height * 4);
|
||||
ctx.verboseEnabled = verboseEnabled;
|
||||
|
||||
bool VideoPlayer::initPlayer() {
|
||||
#ifdef HAS_LIBVLC
|
||||
ctxPtr->libvlc = NULL;
|
||||
ctxPtr->m = NULL;
|
||||
ctxPtr->mp = NULL;
|
||||
ctxPtr->vlc_argv.clear();
|
||||
ctxPtr->vlc_argv.push_back("--intf=dummy");
|
||||
ctxPtr->vlc_argv.push_back("--no-media-library");
|
||||
ctxPtr->vlc_argv.push_back("--ignore-config"); /* Don't use VLC's config */
|
||||
ctxPtr->vlc_argv.push_back("--no-xlib"); /* tell VLC to not use Xlib */
|
||||
ctxPtr->vlc_argv.push_back("--no-video-title-show");
|
||||
|
||||
#if defined(LIBVLC_VERSION_PRE_2)
|
||||
ctxPtr->vlc_argv_str.push_back("--plugin-path=" + pluginsPath);
|
||||
ctxPtr->vlc_argv.push_back(ctxPtr->vlc_argv_str[ctxPtr->vlc_argv_str.size()-1].c_str());
|
||||
#endif
|
||||
|
||||
#if defined(LIBVLC_VERSION_PRE_2) && defined(LIBVLC_VERSION_PRE_1_1_13)
|
||||
char clock[64], cunlock[64], cdata[64];
|
||||
char cwidth[32], cheight[32], cpitch[32];
|
||||
/*
|
||||
* Initialise libVLC
|
||||
*/
|
||||
sprintf(clock, "%lld", (long long int)(intptr_t)lock);
|
||||
sprintf(cunlock, "%lld", (long long int)(intptr_t)unlock);
|
||||
sprintf(cdata, "%lld", (long long int)(intptr_t)ctxPtr);
|
||||
sprintf(cwidth, "%i", width);
|
||||
sprintf(cheight, "%i", height);
|
||||
sprintf(cpitch, "%i", colorBits);
|
||||
|
||||
vlc_argv.push_back("--vout");
|
||||
vlc_argv.push_back("vmem");
|
||||
vlc_argv.push_back("--vmem-width");
|
||||
ctxPtr->vlc_argv_str.push_back(cwidth);
|
||||
ctxPtr->vlc_argv.push_back(ctxPtr->vlc_argv_str[ctxPtr->vlc_argv_str.size()-1].c_str());
|
||||
vlc_argv.push_back("--vmem-height");
|
||||
ctxPtr->vlc_argv_str.push_back(cheight);
|
||||
ctxPtr->vlc_argv.push_back(ctxPtr->vlc_argv_str[ctxPtr->vlc_argv_str.size()-1].c_str());
|
||||
vlc_argv.push_back("--vmem-pitch");
|
||||
ctxPtr->vlc_argv_str.push_back(cpitch);
|
||||
ctxPtr->vlc_argv.push_back(ctxPtr->vlc_argv_str[ctxPtr->vlc_argv_str.size()-1].c_str());
|
||||
vlc_argv.push_back("--vmem-chroma");
|
||||
vlc_argv.push_back("RV16");
|
||||
vlc_argv.push_back("--vmem-lock");
|
||||
ctxPtr->vlc_argv_str.push_back(clock);
|
||||
ctxPtr->vlc_argv.push_back(ctxPtr->vlc_argv_str[ctxPtr->vlc_argv_str.size()-1].c_str());
|
||||
vlc_argv.push_back("--vmem-unlock");
|
||||
ctxPtr->vlc_argv_str.push_back(cunlock);
|
||||
ctxPtr->vlc_argv.push_back(ctxPtr->vlc_argv_str[ctxPtr->vlc_argv_str.size()-1].c_str());
|
||||
vlc_argv.push_back("--vmem-data");
|
||||
ctxPtr->vlc_argv_str.push_back(cdata);
|
||||
ctxPtr->vlc_argv.push_back(ctxPtr->vlc_argv_str[ctxPtr->vlc_argv_str.size()-1].c_str());
|
||||
|
||||
#endif
|
||||
|
||||
if(verboseEnabled) ctxPtr->vlc_argv.push_back("--verbose=2");
|
||||
if(verboseEnabled) ctxPtr->vlc_argv.push_back("--extraintf=logger"); //log anything
|
||||
#if defined(WIN32)
|
||||
if(verboseEnabled) _putenv("VLC_VERBOSE=2");
|
||||
#endif
|
||||
int vlc_argc = ctxPtr->vlc_argv.size();
|
||||
|
||||
// char const *vlc_argv[] =
|
||||
// {
|
||||
// //"--no-audio", /* skip any audio track */
|
||||
// "--no-xlib", /* tell VLC to not use Xlib */
|
||||
// "--no-video-title-show",
|
||||
// pluginParam.c_str(),
|
||||
// };
|
||||
// int vlc_argc = sizeof(vlc_argv) / sizeof(*vlc_argv);
|
||||
#endif
|
||||
|
||||
ctxPtr->empty = NULL;
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
// Init Texture
|
||||
glGenTextures(1, &ctxPtr->textureId);
|
||||
glBindTexture(GL_TEXTURE_2D, ctxPtr->textureId);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
ctxPtr->empty = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
|
||||
colorBits, 0, 0, 0, 0);
|
||||
ctxPtr->surf = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
|
||||
colorBits, 0x001f, 0x07e0, 0xf800, 0);
|
||||
ctxPtr->mutex = SDL_CreateMutex();
|
||||
|
||||
#ifdef HAS_LIBVLC
|
||||
/*
|
||||
* Initialize libVLC
|
||||
*/
|
||||
if(verboseEnabled) printf("Trying [%s]\n",getenv("VLC_PLUGIN_PATH"));
|
||||
|
||||
#if defined(LIBVLC_VERSION_PRE_2) && defined(LIBVLC_VERSION_PRE_1_1_13)
|
||||
libvlc_exception_t ex;
|
||||
libvlc_exception_init(&ex);
|
||||
|
||||
ctxPtr->libvlc = libvlc_new(ctxPtr->vlc_argc, &ctxPtr->vlc_argv[0],&ex);
|
||||
catchError(&ex);
|
||||
#else
|
||||
ctxPtr->libvlc = libvlc_new(vlc_argc, &ctxPtr->vlc_argv[0]);
|
||||
#endif
|
||||
|
||||
if(verboseEnabled) printf("In [%s] Line: %d, libvlc [%p]\n",__FUNCTION__,__LINE__,ctxPtr->libvlc);
|
||||
|
||||
/* It is meaningless to try all this because we have to restart mg to pickup new env vars
|
||||
#if defined(WIN32)
|
||||
if(libvlc == NULL) {
|
||||
// For windows check registry for install path
|
||||
std::string strValue = getRegKey("Software\\VideoLAN\\VLC", "InstallDir");
|
||||
if(strValue != "") {
|
||||
if(strValue.length() >= 2) {
|
||||
if(strValue[0] == '"') {
|
||||
strValue = strValue.erase(0);
|
||||
}
|
||||
if(strValue[strValue.length()-1] == '"') {
|
||||
strValue = strValue.erase(strValue.length()-1);
|
||||
}
|
||||
}
|
||||
strValue = "VLC_PLUGIN_PATH=" + strValue;
|
||||
_putenv(strValue.c_str());
|
||||
|
||||
if(verboseEnabled) printf("Trying [%s]\n",getenv("VLC_PLUGIN_PATH"));
|
||||
libvlc = libvlc_new(vlc_argc, &vlc_argv[0]);
|
||||
}
|
||||
|
||||
if(libvlc == NULL) {
|
||||
_putenv("VLC_PLUGIN_PATH=c:\\program files\\videolan\\vlc\\plugins");
|
||||
|
||||
if(verboseEnabled) printf("Trying [%s]\n",getenv("VLC_PLUGIN_PATH"));
|
||||
libvlc = libvlc_new(vlc_argc, &vlc_argv[0]);
|
||||
}
|
||||
if(libvlc == NULL) {
|
||||
_putenv("VLC_PLUGIN_PATH=\\program files\\videolan\\vlc\\plugins");
|
||||
|
||||
if(verboseEnabled) printf("Trying [%s]\n",getenv("VLC_PLUGIN_PATH"));
|
||||
libvlc = libvlc_new(vlc_argc, &vlc_argv[0]);
|
||||
}
|
||||
if(libvlc == NULL) {
|
||||
_putenv("VLC_PLUGIN_PATH=c:\\program files (x86)\\videolan\\vlc\\plugins");
|
||||
|
||||
if(verboseEnabled) printf("Trying [%s]\n",getenv("VLC_PLUGIN_PATH"));
|
||||
libvlc = libvlc_new(vlc_argc, &vlc_argv[0]);
|
||||
}
|
||||
if(libvlc == NULL) {
|
||||
_putenv("VLC_PLUGIN_PATH=\\program files (x86)\\videolan\\vlc\\plugins");
|
||||
|
||||
if(verboseEnabled) printf("Trying [%s]\n",getenv("VLC_PLUGIN_PATH"));
|
||||
libvlc = libvlc_new(vlc_argc, &vlc_argv[0]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
|
||||
if(ctxPtr->libvlc != NULL) {
|
||||
#if defined(LIBVLC_VERSION_PRE_2) && defined(LIBVLC_VERSION_PRE_1_1_13)
|
||||
ctxPtr->m = libvlc_media_new(ctxPtr->libvlc, filename.c_str(), &ex);
|
||||
if(verboseEnabled) printf("In [%s] Line: %d, m [%p]\n",__FUNCTION__,__LINE__,ctxPtr->m);
|
||||
|
||||
catchError(&ex);
|
||||
ctxPtr->mp = libvlc_media_player_new_from_media(ctxPtr->m);
|
||||
if(verboseEnabled) printf("In [%s] Line: %d, mp [%p]\n",__FUNCTION__,__LINE__,ctxPtr->mp);
|
||||
#else
|
||||
/* Create a new item */
|
||||
ctxPtr->m = libvlc_media_new_path(ctxPtr->libvlc, filename.c_str());
|
||||
if(verboseEnabled) printf("In [%s] Line: %d, m [%p]\n",__FUNCTION__,__LINE__,ctxPtr->m);
|
||||
|
||||
ctxPtr->mp = libvlc_media_player_new_from_media(ctxPtr->m);
|
||||
if(verboseEnabled) printf("In [%s] Line: %d, mp [%p]\n",__FUNCTION__,__LINE__,ctxPtr->mp);
|
||||
#endif
|
||||
libvlc_media_release(ctxPtr->m);
|
||||
|
||||
#if !defined(LIBVLC_VERSION_PRE_2) && !defined(LIBVLC_VERSION_PRE_1_1_13)
|
||||
libvlc_video_set_callbacks(ctxPtr->mp, lock, unlock, display, ctxPtr);
|
||||
libvlc_video_set_format(ctxPtr->mp, "RV16", width, height, this->surface->pitch);
|
||||
|
||||
// Get an event manager for the media player.
|
||||
//libvlc_event_manager_t *eventManager = libvlc_media_player_event_manager(mp, &ex);
|
||||
libvlc_event_manager_t *eventManager = libvlc_media_player_event_manager(ctxPtr->mp);
|
||||
if(eventManager) {
|
||||
// libvlc_event_attach(eventManager, libvlc_MediaPlayerPlaying, (libvlc_callback_t)trapPlayingEvent, NULL, &ex);
|
||||
// libvlc_event_attach(eventManager, libvlc_MediaPlayerEndReached, (libvlc_callback_t)trapEndReachedEvent, NULL, &ex);
|
||||
// libvlc_event_attach(eventManager, libvlc_MediaPlayerBuffering, (libvlc_callback_t)trapBufferingEvent, NULL, &ex);
|
||||
// libvlc_event_attach(eventManager, libvlc_MediaPlayerEncounteredError, (libvlc_callback_t)trapErrorEvent, NULL, &ex);
|
||||
libvlc_event_attach(eventManager, libvlc_MediaPlayerPlaying, (libvlc_callback_t)trapPlayingEvent, ctxPtr);
|
||||
libvlc_event_attach(eventManager, libvlc_MediaPlayerEndReached, (libvlc_callback_t)trapEndReachedEvent, ctxPtr);
|
||||
libvlc_event_attach(eventManager, libvlc_MediaPlayerBuffering, (libvlc_callback_t)trapBufferingEvent, ctxPtr);
|
||||
libvlc_event_attach(eventManager, libvlc_MediaPlayerEncounteredError, (libvlc_callback_t)trapErrorEvent, ctxPtr);
|
||||
}
|
||||
#endif
|
||||
|
||||
ctxPtr->isPlaying = true;
|
||||
#if defined(LIBVLC_VERSION_PRE_2) && defined(LIBVLC_VERSION_PRE_1_1_13)
|
||||
int play_result = libvlc_media_player_play(ctxPtr->mp,&ex);
|
||||
#else
|
||||
int play_result = libvlc_media_player_play(ctxPtr->mp);
|
||||
#endif
|
||||
|
||||
//SDL_Delay(5);
|
||||
if(verboseEnabled) printf("In [%s] Line: %d, play_result [%d]\n",__FUNCTION__,__LINE__,play_result);
|
||||
|
||||
successLoadingLib = (play_result == 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
return successLoadingLib;
|
||||
}
|
||||
|
||||
void VideoPlayer::closePlayer() {
|
||||
#ifdef HAS_LIBVLC
|
||||
if(ctxPtr->libvlc != NULL) {
|
||||
//
|
||||
// Stop stream and clean up libVLC
|
||||
//
|
||||
#if defined(LIBVLC_VERSION_PRE_2) && defined(LIBVLC_VERSION_PRE_1_1_13)
|
||||
libvlc_media_player_stop(ctxPtr->mp,&ex);
|
||||
catchError(&ex);
|
||||
#else
|
||||
libvlc_media_player_stop(ctxPtr->mp);
|
||||
#endif
|
||||
libvlc_media_player_release(ctxPtr->mp);
|
||||
libvlc_release(ctxPtr->libvlc);
|
||||
}
|
||||
#endif
|
||||
|
||||
//
|
||||
// Close window and clean up libSDL
|
||||
//
|
||||
if(ctxPtr->mutex != NULL) {
|
||||
SDL_DestroyMutex(ctxPtr->mutex);
|
||||
}
|
||||
if(ctxPtr->surf != NULL) {
|
||||
SDL_FreeSurface(ctxPtr->surf);
|
||||
}
|
||||
if(ctxPtr->empty != NULL) {
|
||||
SDL_FreeSurface(ctxPtr->empty);
|
||||
}
|
||||
|
||||
glDeleteTextures(1, &ctxPtr->textureId);
|
||||
|
||||
if(ctxPtr->needToQuit == true) {
|
||||
SDL_Event quit_event = {SDL_QUIT};
|
||||
SDL_PushEvent(&quit_event);
|
||||
}
|
||||
}
|
||||
|
||||
void VideoPlayer::PlayVideo() {
|
||||
/*
|
||||
#ifdef HAS_LIBVLC
|
||||
libvlc_instance_t *libvlc = NULL;
|
||||
libvlc_media_t *m = NULL;
|
||||
|
@ -209,8 +513,8 @@ void VideoPlayer::PlayVideo() {
|
|||
std::vector<const char *> vlc_argv;
|
||||
vlc_argv.push_back("--intf=dummy");
|
||||
vlc_argv.push_back("--no-media-library");
|
||||
vlc_argv.push_back("--ignore-config"); /* Don't use VLC's config */
|
||||
vlc_argv.push_back("--no-xlib"); /* tell VLC to not use Xlib */
|
||||
vlc_argv.push_back("--ignore-config"); // Don't use VLC's config
|
||||
vlc_argv.push_back("--no-xlib"); // tell VLC to not use Xlib
|
||||
vlc_argv.push_back("--no-video-title-show");
|
||||
#if defined(LIBVLC_VERSION_PRE_2)
|
||||
string fullPluginsParam = "--plugin-path=" + pluginsPath;
|
||||
|
@ -220,12 +524,12 @@ void VideoPlayer::PlayVideo() {
|
|||
#if defined(LIBVLC_VERSION_PRE_2) && defined(LIBVLC_VERSION_PRE_1_1_13)
|
||||
char clock[64], cunlock[64], cdata[64];
|
||||
char cwidth[32], cheight[32], cpitch[32];
|
||||
/*
|
||||
* Initialise libVLC
|
||||
*/
|
||||
//
|
||||
// Initialise libVLC
|
||||
//
|
||||
sprintf(clock, "%lld", (long long int)(intptr_t)lock);
|
||||
sprintf(cunlock, "%lld", (long long int)(intptr_t)unlock);
|
||||
sprintf(cdata, "%lld", (long long int)(intptr_t)&ctx);
|
||||
sprintf(cdata, "%lld", (long long int)(intptr_t)ctxPtr);
|
||||
sprintf(cwidth, "%i", width);
|
||||
sprintf(cheight, "%i", height);
|
||||
sprintf(cpitch, "%i", colorBits);
|
||||
|
@ -258,8 +562,8 @@ void VideoPlayer::PlayVideo() {
|
|||
|
||||
// char const *vlc_argv[] =
|
||||
// {
|
||||
// //"--no-audio", /* skip any audio track */
|
||||
// "--no-xlib", /* tell VLC to not use Xlib */
|
||||
// //"--no-audio", // skip any audio track
|
||||
// "--no-xlib", // tell VLC to not use Xlib
|
||||
// "--no-video-title-show",
|
||||
// pluginParam.c_str(),
|
||||
// };
|
||||
|
@ -267,30 +571,24 @@ void VideoPlayer::PlayVideo() {
|
|||
#endif
|
||||
|
||||
SDL_Surface *empty = NULL;
|
||||
SDL_Event event;
|
||||
|
||||
int done = 0, action = 0, pause = 0, n = 0;
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
// Init Texture
|
||||
glGenTextures(1, &ctx.textureId);
|
||||
glBindTexture(GL_TEXTURE_2D, ctx.textureId);
|
||||
glGenTextures(1, &ctxPtr->textureId);
|
||||
glBindTexture(GL_TEXTURE_2D, ctxPtr->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,
|
||||
ctxPtr->surf = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
|
||||
colorBits, 0x001f, 0x07e0, 0xf800, 0);
|
||||
ctx.mutex = SDL_CreateMutex();
|
||||
ctxPtr->mutex = SDL_CreateMutex();
|
||||
|
||||
bool successLoadingVLC = false;
|
||||
#ifdef HAS_LIBVLC
|
||||
/*
|
||||
* Initialize libVLC
|
||||
*/
|
||||
//
|
||||
// Initialize libVLC
|
||||
//
|
||||
if(verboseEnabled) printf("Trying [%s]\n",getenv("VLC_PLUGIN_PATH"));
|
||||
|
||||
#if defined(LIBVLC_VERSION_PRE_2) && defined(LIBVLC_VERSION_PRE_1_1_13)
|
||||
|
@ -305,7 +603,7 @@ void VideoPlayer::PlayVideo() {
|
|||
|
||||
if(verboseEnabled) printf("In [%s] Line: %d, libvlc [%p]\n",__FUNCTION__,__LINE__,libvlc);
|
||||
|
||||
/* It is meaningless to try all this because we have to restart mg to pickup new env vars
|
||||
// It is meaningless to try all this because we have to restart mg to pickup new env vars
|
||||
#if defined(WIN32)
|
||||
if(libvlc == NULL) {
|
||||
// For windows check registry for install path
|
||||
|
@ -352,7 +650,7 @@ void VideoPlayer::PlayVideo() {
|
|||
}
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
//
|
||||
|
||||
if(libvlc != NULL) {
|
||||
#if defined(LIBVLC_VERSION_PRE_2) && defined(LIBVLC_VERSION_PRE_1_1_13)
|
||||
|
@ -363,7 +661,7 @@ void VideoPlayer::PlayVideo() {
|
|||
mp = libvlc_media_player_new_from_media(m);
|
||||
if(verboseEnabled) printf("In [%s] Line: %d, mp [%p]\n",__FUNCTION__,__LINE__,mp);
|
||||
#else
|
||||
/* Create a new item */
|
||||
// Create a new item
|
||||
m = libvlc_media_new_path(libvlc, filename.c_str());
|
||||
if(verboseEnabled) printf("In [%s] Line: %d, m [%p]\n",__FUNCTION__,__LINE__,m);
|
||||
|
||||
|
@ -373,7 +671,7 @@ void VideoPlayer::PlayVideo() {
|
|||
libvlc_media_release(m);
|
||||
|
||||
#if !defined(LIBVLC_VERSION_PRE_2) && !defined(LIBVLC_VERSION_PRE_1_1_13)
|
||||
libvlc_video_set_callbacks(mp, lock, unlock, display, &ctx);
|
||||
libvlc_video_set_callbacks(mp, lock, unlock, display, ctxPtr);
|
||||
libvlc_video_set_format(mp, "RV16", width, height, this->surface->pitch);
|
||||
|
||||
// Get an event manager for the media player.
|
||||
|
@ -384,14 +682,14 @@ void VideoPlayer::PlayVideo() {
|
|||
// libvlc_event_attach(eventManager, libvlc_MediaPlayerEndReached, (libvlc_callback_t)trapEndReachedEvent, NULL, &ex);
|
||||
// libvlc_event_attach(eventManager, libvlc_MediaPlayerBuffering, (libvlc_callback_t)trapBufferingEvent, NULL, &ex);
|
||||
// libvlc_event_attach(eventManager, libvlc_MediaPlayerEncounteredError, (libvlc_callback_t)trapErrorEvent, NULL, &ex);
|
||||
libvlc_event_attach(eventManager, libvlc_MediaPlayerPlaying, (libvlc_callback_t)trapPlayingEvent, &ctx);
|
||||
libvlc_event_attach(eventManager, libvlc_MediaPlayerEndReached, (libvlc_callback_t)trapEndReachedEvent, &ctx);
|
||||
libvlc_event_attach(eventManager, libvlc_MediaPlayerBuffering, (libvlc_callback_t)trapBufferingEvent, &ctx);
|
||||
libvlc_event_attach(eventManager, libvlc_MediaPlayerEncounteredError, (libvlc_callback_t)trapErrorEvent, &ctx);
|
||||
libvlc_event_attach(eventManager, libvlc_MediaPlayerPlaying, (libvlc_callback_t)trapPlayingEvent, ctxPtr);
|
||||
libvlc_event_attach(eventManager, libvlc_MediaPlayerEndReached, (libvlc_callback_t)trapEndReachedEvent, ctxPtr);
|
||||
libvlc_event_attach(eventManager, libvlc_MediaPlayerBuffering, (libvlc_callback_t)trapBufferingEvent, ctxPtr);
|
||||
libvlc_event_attach(eventManager, libvlc_MediaPlayerEncounteredError, (libvlc_callback_t)trapErrorEvent, ctxPtr);
|
||||
}
|
||||
#endif
|
||||
|
||||
ctx.isPlaying = true;
|
||||
ctxPtr->isPlaying = true;
|
||||
#if defined(LIBVLC_VERSION_PRE_2) && defined(LIBVLC_VERSION_PRE_1_1_13)
|
||||
int play_result = libvlc_media_player_play(mp,&ex);
|
||||
#else
|
||||
|
@ -401,77 +699,24 @@ void VideoPlayer::PlayVideo() {
|
|||
//SDL_Delay(5);
|
||||
if(verboseEnabled) printf("In [%s] Line: %d, play_result [%d]\n",__FUNCTION__,__LINE__,play_result);
|
||||
|
||||
successLoadingVLC = (play_result == 0);
|
||||
successLoadingLib = (play_result == 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Main loop
|
||||
*/
|
||||
|
||||
//
|
||||
/ Main loop
|
||||
//
|
||||
//int done = 0, action = 0, pause = 0, n = 0;
|
||||
bool needToQuit = false;
|
||||
while(successLoadingVLC == true && ctx.isPlaying == true &&
|
||||
done == 0 && 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();
|
||||
}
|
||||
while(isPlaying() == true) {
|
||||
needToQuit = playFrame();
|
||||
}
|
||||
|
||||
#ifdef HAS_LIBVLC
|
||||
if(libvlc != NULL) {
|
||||
/*
|
||||
* Stop stream and clean up libVLC
|
||||
*/
|
||||
//
|
||||
/ Stop stream and clean up libVLC
|
||||
//
|
||||
#if defined(LIBVLC_VERSION_PRE_2) && defined(LIBVLC_VERSION_PRE_1_1_13)
|
||||
libvlc_media_player_stop(mp,&ex);
|
||||
catchError(&ex);
|
||||
|
@ -483,18 +728,168 @@ void VideoPlayer::PlayVideo() {
|
|||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Close window and clean up libSDL
|
||||
*/
|
||||
SDL_DestroyMutex(ctx.mutex);
|
||||
SDL_FreeSurface(ctx.surf);
|
||||
//
|
||||
/ Close window and clean up libSDL
|
||||
//
|
||||
SDL_DestroyMutex(ctxPtr->mutex);
|
||||
SDL_FreeSurface(ctxPtr->surf);
|
||||
SDL_FreeSurface(empty);
|
||||
|
||||
glDeleteTextures(1, &ctx.textureId);
|
||||
free(ctx.rawData);
|
||||
glDeleteTextures(1, &ctxPtr->textureId);
|
||||
|
||||
if(needToQuit == true) {
|
||||
SDL_Event quit_event = {SDL_QUIT};
|
||||
SDL_PushEvent(&quit_event);
|
||||
}
|
||||
*/
|
||||
|
||||
initPlayer();
|
||||
for(;isPlaying() == true;) {
|
||||
playFrame();
|
||||
}
|
||||
closePlayer();
|
||||
}
|
||||
|
||||
bool VideoPlayer::isPlaying() const {
|
||||
bool result = (successLoadingLib == true &&
|
||||
ctxPtr != NULL && ctxPtr->isPlaying == true &&
|
||||
finished == false && stop == false);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool VideoPlayer::playFrame(bool swapBuffers) {
|
||||
//bool needToQuit = false;
|
||||
int action = 0, pause = 0, n = 0;
|
||||
if(successLoadingLib == true &&
|
||||
ctxPtr != NULL && ctxPtr->isPlaying == true &&
|
||||
finished == false && stop == false) {
|
||||
action = 0;
|
||||
|
||||
SDL_Event event;
|
||||
/* Keys: enter (fullscreen), space (pause), escape (quit) */
|
||||
while( SDL_PollEvent( &event ) ) {
|
||||
switch(event.type) {
|
||||
case SDL_QUIT:
|
||||
finished = true;
|
||||
ctxPtr->needToQuit = true;
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
action = event.key.keysym.sym;
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
finished = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(finished == false && stop == false) {
|
||||
switch(action) {
|
||||
case SDLK_ESCAPE:
|
||||
finished = true;
|
||||
break;
|
||||
case SDLK_RETURN:
|
||||
//options ^= SDL_FULLSCREEN;
|
||||
//screen = SDL_SetVideoMode(WIDTH, HEIGHT, 0, options);
|
||||
finished = true;
|
||||
break;
|
||||
case ' ':
|
||||
//pause = !pause;
|
||||
break;
|
||||
}
|
||||
|
||||
if(pause == 0) {
|
||||
n++;
|
||||
}
|
||||
|
||||
//assertGl();
|
||||
|
||||
glPushAttrib(GL_ENABLE_BIT);
|
||||
|
||||
//glDisable(GL_LIGHTING);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
loadTexture(ctxPtr); // 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();
|
||||
|
||||
// glBegin(GL_TRIANGLE_STRIP);
|
||||
// glTexCoord2i(0, 1);
|
||||
// glVertex2i(1, 1+600);
|
||||
// glTexCoord2i(0, 0);
|
||||
// glVertex2i(1, 1);
|
||||
// glTexCoord2i(1, 1);
|
||||
// glVertex2i(1+800, 1+600);
|
||||
// glTexCoord2i(1, 0);
|
||||
// glVertex2i(1+800, 600);
|
||||
// glEnd();
|
||||
|
||||
// glBegin(GL_TRIANGLE_STRIP);
|
||||
// glTexCoord2i(0, 1);
|
||||
// glVertex2i(ctxPtr->x, ctxPtr->y + ctxPtr->height);
|
||||
// glTexCoord2i(0, 0);
|
||||
// glVertex2i(ctxPtr->x, ctxPtr->y);
|
||||
// glTexCoord2i(1, 1);
|
||||
// glVertex2i(ctxPtr->x + ctxPtr->width, ctxPtr->y + ctxPtr->height);
|
||||
// glTexCoord2i(1, 0);
|
||||
// glVertex2i(ctxPtr->x + ctxPtr->width, ctxPtr->y);
|
||||
// glEnd();
|
||||
|
||||
if(ctxPtr->x == -1 || ctxPtr->y == -1) {
|
||||
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();
|
||||
}
|
||||
else {
|
||||
// glBegin(GL_QUADS);
|
||||
// glTexCoord2d(0, 1);
|
||||
// glVertex2f(ctxPtr->x, ctxPtr->y + ctxPtr->height);
|
||||
// glTexCoord2d(1, 1);
|
||||
// glVertex2f(ctxPtr->x + ctxPtr->width, ctxPtr->y + ctxPtr->height);
|
||||
// glTexCoord2d(1, 0);
|
||||
// glVertex2f(ctxPtr->x + ctxPtr->width, ctxPtr->y);
|
||||
// glTexCoord2d(0, 0);
|
||||
// glVertex2f(ctxPtr->x, ctxPtr->y);
|
||||
// glEnd();
|
||||
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
glTexCoord2i(0, 1);
|
||||
glVertex2i(ctxPtr->x, ctxPtr->y + ctxPtr->height * 0.80);
|
||||
glTexCoord2i(0, 0);
|
||||
glVertex2i(ctxPtr->x, ctxPtr->y);
|
||||
glTexCoord2i(1, 1);
|
||||
glVertex2i(ctxPtr->x+ctxPtr->width * 0.60, ctxPtr->y+ctxPtr->height * 0.80);
|
||||
glTexCoord2i(1, 0);
|
||||
glVertex2i(ctxPtr->x+ctxPtr->width * 0.60, ctxPtr->y);
|
||||
glEnd();
|
||||
|
||||
}
|
||||
|
||||
glPopAttrib();
|
||||
|
||||
if(swapBuffers == true) {
|
||||
SDL_GL_SwapBuffers();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ctxPtr->needToQuit;
|
||||
}
|
||||
|
||||
}}
|
||||
|
|
Loading…
Reference in New Issue