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

122 lines
4.0 KiB
C++
Raw Normal View History

/*
* CVideoHandler.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
#include "../lib/Rect.h"
2023-09-01 23:57:25 +02:00
#include "../lib/filesystem/ResourcePath.h"
2009-06-28 02:33:59 +03:00
struct SDL_Surface;
struct SDL_Texture;
2011-08-08 17:20:22 +03:00
2023-09-16 23:14:51 +02:00
class IVideoPlayer : boost::noncopyable
2011-08-08 17:20:22 +03:00
{
public:
2023-09-01 23:57:25 +02:00
virtual bool open(const VideoPath & 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:
2023-09-22 21:45:12 +02:00
virtual void update(int x, int y, SDL_Surface *dst, bool forceRedraw, bool update = true, std::function<void()> restart = 0){}
2023-09-01 23:57:25 +02:00
virtual bool openAndPlayVideo(const VideoPath & name, int x, int y, bool stopOnKey = false, bool scale = false)
2011-08-08 17:20:22 +03:00
{
return false;
}
2023-10-09 22:22:10 +02:00
virtual std::pair<std::unique_ptr<ui8 []>, si64> getAudio(const VideoPath & videoToOpen) { return std::make_pair(nullptr, 0); };
2011-08-08 17:20:22 +03:00
};
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;};
2023-09-01 23:57:25 +02:00
bool open(const VideoPath & name, bool scale = false) override {return false;};
2011-08-08 17:20:22 +03:00
};
#ifndef DISABLE_VIDEO
struct AVFormatContext;
struct AVCodecContext;
struct AVCodec;
struct AVFrame;
struct AVIOContext;
2015-11-14 02:59:16 +02:00
2023-09-16 23:14:51 +02:00
VCMI_LIB_NAMESPACE_BEGIN
class CInputStream;
VCMI_LIB_NAMESPACE_END
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
2022-05-10 18:25:48 +02:00
const AVCodec *codec;
2015-11-14 02:59:16 +02:00
AVFrame *frame;
2009-06-24 15:14:48 +03:00
struct SwsContext *sws;
AVIOContext * context;
2023-09-16 23:14:51 +02:00
VideoPath fname; //name of current video file (empty if idle)
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;
Rect destRect; // valid when dest is used
Rect pos; // destination on screen
2009-06-24 15:14:48 +03:00
/// video playback currnet progress, in seconds
double frameTime;
2009-06-28 02:33:59 +03:00
bool doLoop; // loop through video
bool playVideo(int x, int y, bool stopOnKey);
2023-09-01 23:57:25 +02:00
bool open(const VideoPath & fname, bool loop, bool useOverlay = false, bool scale = false);
2009-06-24 15:14:48 +03:00
public:
CVideoPlayer();
~CVideoPlayer();
bool init();
2023-09-01 23:57:25 +02:00
bool open(const VideoPath & 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
2023-09-23 20:41:30 +02:00
void update(int x, int y, SDL_Surface *dst, bool forceRedraw, bool update = true, std::function<void()> onVideoRestart = nullptr) override; //moves to next frame if appropriate, and blits it or blits only if redraw parameter is set true
2015-11-14 02:59:16 +02:00
2009-06-28 02:33:59 +03:00
// Opens video, calls playVideo, closes video; returns playVideo result (if whole video has been played)
2023-09-01 23:57:25 +02:00
bool openAndPlayVideo(const VideoPath & name, int x, int y, bool stopOnKey = false, bool scale = false) override;
2009-06-28 02:33:59 +03:00
2023-10-07 20:09:40 +02:00
std::pair<std::unique_ptr<ui8 []>, si64> getAudio(const VideoPath & videoToOpen) override;
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;
2023-10-07 20:09:40 +02:00
std::unique_ptr<CInputStream> dataAudio;
2009-06-24 15:14:48 +03:00
};
#endif