1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00
vcmi/client/CVideoHandler.h

120 lines
3.7 KiB
C
Raw Normal View History

#pragma once
2009-06-28 02:33:59 +03:00
struct SDL_Surface;
2011-08-08 17:20:22 +03:00
class IVideoPlayer
{
public:
virtual bool open(std::string name, bool scale = false)=0; //true - succes
2011-08-08 17:20:22 +03:00
virtual void close()=0;
virtual bool nextFrame()=0;
virtual void show(int x, int y, SDL_Surface *dst, bool update = true)=0;
virtual void redraw(int x, int y, SDL_Surface *dst, bool update = true)=0; //reblits buffer
virtual bool wait()=0;
virtual int curFrame() const =0;
virtual int frameCount() const =0;
};
class IMainVideoPlayer : public IVideoPlayer
{
public:
std::string fname; //name of current video file (empty if idle)
virtual void update(int x, int y, SDL_Surface *dst, bool forceRedraw, bool update = true){}
virtual bool openAndPlayVideo(std::string name, int x, int y, SDL_Surface *dst, bool stopOnKey = false, bool scale = false)
2011-08-08 17:20:22 +03:00
{
return false;
}
};
class CEmptyVideoPlayer : public IMainVideoPlayer
{
public:
int curFrame() const override {return -1;};
int frameCount() const override {return -1;};
void redraw( int x, int y, SDL_Surface *dst, bool update = true ) override {};
void show( int x, int y, SDL_Surface *dst, bool update = true ) override {};
bool nextFrame() override {return false;};
void close() override {};
bool wait() override {return false;};
bool open(std::string name, bool scale = false) override {return false;};
2011-08-08 17:20:22 +03:00
};
#ifndef DISABLE_VIDEO
2013-04-07 13:48:07 +03:00
#include "../lib/filesystem/CInputStream.h"
#include <SDL.h>
2009-06-24 15:14:48 +03:00
#include <SDL_video.h>
extern "C" {
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
// compatibility with different versions od libavutil
#if (LIBAVUTIL_VERSION_INT < AV_VERSION_INT(51, 42, 0)) || \
(LIBAVUTIL_VERSION_INT == AV_VERSION_INT(51, 73, 101))
#define AV_PIX_FMT_NONE PIX_FMT_NONE
#define AV_PIX_FMT_NV12 PIX_FMT_NV12
#define AV_PIX_FMT_YUV420P PIX_FMT_YUV420P
#define AV_PIX_FMT_UYVY422 PIX_FMT_UYVY422
#define AV_PIX_FMT_YUYV422 PIX_FMT_YUYV422
#endif
}
2009-06-24 15:14:48 +03:00
2011-08-08 17:20:22 +03:00
class CVideoPlayer : public IMainVideoPlayer
2009-06-24 15:14:48 +03:00
{
int stream; // stream index in video
AVFormatContext *format;
AVCodecContext *codecContext; // codec context for stream
AVCodec *codec;
AVFrame *frame;
struct SwsContext *sws;
AVIOContext * context;
2009-06-28 02:33:59 +03:00
// Destination. Either overlay or dest.
2015-06-21 00:13:45 +02:00
SDL_Texture *texture;
2009-06-28 02:33:59 +03:00
SDL_Surface *dest;
SDL_Rect destRect; // valid when dest is used
SDL_Rect pos; // destination on screen
2009-06-24 15:14:48 +03:00
2009-06-28 02:33:59 +03:00
int refreshWait; // Wait several refresh before updating the image
int refreshCount;
bool doLoop; // loop through video
2011-08-08 17:20:22 +03:00
bool playVideo(int x, int y, SDL_Surface *dst, bool stopOnKey);
bool open(std::string fname, bool loop, bool useOverlay = false, bool scale = false);
2011-08-08 17:20:22 +03:00
2009-06-24 15:14:48 +03:00
public:
CVideoPlayer();
~CVideoPlayer();
bool init();
bool open(std::string fname, bool scale = false) override;
void close() override;
bool nextFrame() override; // display next frame
2009-06-24 15:14:48 +03:00
void show(int x, int y, SDL_Surface *dst, bool update = true) override; //blit current frame
void redraw(int x, int y, SDL_Surface *dst, bool update = true) override; //reblits buffer
void update(int x, int y, SDL_Surface *dst, bool forceRedraw, bool update = true) override; //moves to next frame if appropriate, and blits it or blits only if redraw parameter is set true
2009-06-28 02:33:59 +03:00
// Opens video, calls playVideo, closes video; returns playVideo result (if whole video has been played)
bool openAndPlayVideo(std::string name, int x, int y, SDL_Surface *dst, bool stopOnKey = false, bool scale = false) override;
2009-06-28 02:33:59 +03:00
2011-08-08 17:20:22 +03:00
//TODO:
bool wait() override {return false;};
int curFrame() const override {return -1;};
int frameCount() const override {return -1;};
// public to allow access from ffmpeg IO functions
std::unique_ptr<CInputStream> data;
2009-06-24 15:14:48 +03:00
};
#endif