1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00
vcmi/client/media/CVideoHandler.h

110 lines
2.5 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
#ifndef DISABLE_VIDEO
2024-05-17 18:01:08 +02:00
#include "../lib/Point.h"
#include "IVideoPlayer.h"
struct SDL_Surface;
struct SDL_Texture;
struct AVFormatContext;
struct AVCodecContext;
struct AVCodecParameters;
struct AVCodec;
struct AVFrame;
struct AVIOContext;
VCMI_LIB_NAMESPACE_BEGIN
class CInputStream;
2024-05-17 18:01:08 +02:00
class Point;
VCMI_LIB_NAMESPACE_END
2024-05-17 18:01:08 +02:00
class FFMpegStream : boost::noncopyable
{
std::unique_ptr<CInputStream> input;
AVIOContext * context = nullptr;
AVFormatContext * formatContext = nullptr;
const AVCodec * codec = nullptr;
AVCodecContext * codecContext = nullptr;
int streamIndex = -1;
AVFrame * frame = nullptr;
protected:
void openContext();
void openCodec(int streamIndex);
2024-05-17 18:01:08 +02:00
int findVideoStream() const;
int findAudioStream() const;
2024-05-17 18:01:08 +02:00
const AVCodecParameters * getCodecParameters() const;
const AVCodecContext * getCodecContext() const;
void decodeNextFrame();
2024-05-17 18:01:08 +02:00
const AVFrame * getCurrentFrame() const;
double getCurrentFrameEndTime() const;
double getCurrentFrameDuration() const;
public:
virtual ~FFMpegStream();
2024-05-17 17:43:21 +02:00
bool openInput(const VideoPath & fname);
};
class CAudioInstance final : public FFMpegStream
{
public:
2024-05-15 18:15:25 +02:00
std::pair<std::unique_ptr<ui8[]>, si64> extractAudio(const VideoPath & videoToOpen);
};
class CVideoInstance final : public IVideoInstance, public FFMpegStream
{
friend class CVideoPlayer;
struct SwsContext * sws = nullptr;
SDL_Texture * textureRGB = nullptr;
SDL_Texture * textureYUV = nullptr;
SDL_Surface * surface = nullptr;
Point dimensions;
/// video playback current progress, in seconds
double frameTime = 0.0;
2024-09-12 23:06:33 +02:00
void prepareOutput(float scaleFactor, bool useTextureOutput);
public:
~CVideoInstance();
void openVideo();
bool loadNextFrame();
bool videoEnded() final;
Point size() final;
void show(const Point & position, Canvas & canvas) final;
void tick(uint32_t msPassed) final;
};
class CVideoPlayer final : public IVideoPlayer
{
2024-09-12 22:28:45 +02:00
bool openAndPlayVideoImpl(const VideoPath & name, const Point & position, bool useOverlay, bool stopOnKey);
void openVideoFile(CVideoInstance & state, const VideoPath & fname);
public:
void playSpellbookAnimation(const VideoPath & name, const Point & position) final;
2024-09-12 23:06:33 +02:00
std::unique_ptr<IVideoInstance> open(const VideoPath & name, float scaleFactor) final;
2024-05-15 18:15:25 +02:00
std::pair<std::unique_ptr<ui8[]>, si64> getAudio(const VideoPath & videoToOpen) final;
};
#endif