2020-09-15 20:57:54 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-28 16:39:18 +00:00
|
|
|
//
|
2020-09-15 20:57:54 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-28 16:39:18 +00:00
|
|
|
// VideoComponent.h
|
|
|
|
//
|
|
|
|
// Base class for playing videos.
|
|
|
|
//
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#ifndef ES_CORE_COMPONENTS_VIDEO_COMPONENT_H
|
|
|
|
#define ES_CORE_COMPONENTS_VIDEO_COMPONENT_H
|
2016-12-04 23:47:34 +00:00
|
|
|
|
|
|
|
#include "GuiComponent.h"
|
2021-07-07 18:31:46 +00:00
|
|
|
#include "components/ImageComponent.h"
|
2020-06-28 16:39:18 +00:00
|
|
|
|
2021-11-16 16:49:05 +00:00
|
|
|
#include <atomic>
|
2016-12-04 23:47:34 +00:00
|
|
|
#include <string>
|
2017-11-01 22:21:10 +00:00
|
|
|
|
2021-05-16 11:12:31 +00:00
|
|
|
class MediaViewer;
|
2017-11-01 22:21:10 +00:00
|
|
|
class TextureResource;
|
2016-12-04 23:47:34 +00:00
|
|
|
|
|
|
|
class VideoComponent : public GuiComponent
|
|
|
|
{
|
2020-06-28 16:39:18 +00:00
|
|
|
// Structure that groups together the configuration of the video component.
|
|
|
|
struct Configuration {
|
|
|
|
unsigned startDelay;
|
2023-07-30 18:12:23 +00:00
|
|
|
bool showStaticImageDelay;
|
2020-06-28 16:39:18 +00:00
|
|
|
std::string defaultVideoPath;
|
2022-01-29 17:41:22 +00:00
|
|
|
std::string staticVideoPath;
|
2020-06-28 16:39:18 +00:00
|
|
|
};
|
2016-12-04 23:47:34 +00:00
|
|
|
|
|
|
|
public:
|
2022-01-19 17:01:54 +00:00
|
|
|
VideoComponent();
|
2020-06-28 16:39:18 +00:00
|
|
|
virtual ~VideoComponent();
|
2016-12-04 23:47:34 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
// Loads the video at the given filepath.
|
|
|
|
bool setVideo(std::string path);
|
|
|
|
// Configures the component to show the default video.
|
2021-07-07 18:31:46 +00:00
|
|
|
void setDefaultVideo() { setVideo(mConfig.defaultVideoPath); }
|
2022-01-29 17:41:22 +00:00
|
|
|
// Configures the component to show the static video.
|
|
|
|
void setStaticVideo() { setVideo(mConfig.staticVideoPath); }
|
2020-11-17 21:13:33 +00:00
|
|
|
// Loads a static image that is displayed if the video cannot be played.
|
2022-02-14 18:32:07 +00:00
|
|
|
void setImage(const std::string& path, bool tile = false) override;
|
2022-12-21 18:53:03 +00:00
|
|
|
// Same as setImage() but does not set the default image if the path argument is empty.
|
|
|
|
void setImageNoDefault(const std::string& path);
|
2021-05-16 11:12:31 +00:00
|
|
|
// Sets whether we're in media viewer mode.
|
2021-07-07 18:31:46 +00:00
|
|
|
void setMediaViewerMode(bool isMediaViewer) { mMediaViewerMode = isMediaViewer; }
|
2021-05-16 11:12:31 +00:00
|
|
|
// Sets whether we're in screensaver mode.
|
2021-07-07 18:31:46 +00:00
|
|
|
void setScreensaverMode(bool isScreensaver) { mScreensaverMode = isScreensaver; }
|
2020-11-17 21:13:33 +00:00
|
|
|
// Set the opacity for the embedded static image.
|
2022-02-11 21:10:25 +00:00
|
|
|
void setOpacity(float opacity) override { mOpacity = opacity; }
|
2022-02-12 16:46:31 +00:00
|
|
|
// Set whether to draw black pillarboxes/letterboxes behind videos.
|
|
|
|
void setDrawPillarboxes(bool state) { mDrawPillarboxes = state; }
|
2022-09-16 21:54:13 +00:00
|
|
|
// Whether to fade out the entire video surface including the black rectangle.
|
|
|
|
void setGeneralFade(bool state) { mGeneralFade = state; }
|
2017-06-01 20:08:44 +00:00
|
|
|
|
2022-01-29 17:41:22 +00:00
|
|
|
bool hasStaticVideo() { return !mConfig.staticVideoPath.empty(); }
|
2022-02-09 17:16:15 +00:00
|
|
|
bool hasStaticImage() { return mStaticImage.getTextureSize() != glm::ivec2 {0, 0}; }
|
2023-07-30 16:17:27 +00:00
|
|
|
bool hasStartDelay() { return mConfig.startDelay > 0; }
|
2016-12-04 23:47:34 +00:00
|
|
|
|
2020-11-17 21:13:33 +00:00
|
|
|
// These functions update the embedded static image.
|
2021-07-07 18:31:46 +00:00
|
|
|
void onOriginChanged() override { mStaticImage.setOrigin(mOrigin); }
|
|
|
|
void onPositionChanged() override { mStaticImage.setPosition(mPosition); }
|
|
|
|
void onSizeChanged() override { mStaticImage.onSizeChanged(); }
|
2016-12-04 23:47:34 +00:00
|
|
|
|
2022-01-18 16:40:47 +00:00
|
|
|
void applyTheme(const std::shared_ptr<ThemeData>& theme,
|
|
|
|
const std::string& view,
|
|
|
|
const std::string& element,
|
|
|
|
unsigned int properties) override;
|
2016-12-04 23:47:34 +00:00
|
|
|
|
2022-01-18 16:40:47 +00:00
|
|
|
std::vector<HelpPrompt> getHelpPrompts() override;
|
2016-12-04 23:47:34 +00:00
|
|
|
|
2022-01-18 16:40:47 +00:00
|
|
|
void update(int deltaTime) override;
|
2016-12-04 23:47:34 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
// Resize the video to be as large as possible but fit within a box of this size.
|
|
|
|
// This can be set before or after a video is loaded.
|
|
|
|
// Never breaks the aspect ratio. setMaxSize() and setResize() are mutually exclusive.
|
|
|
|
virtual void setMaxSize(float width, float height) = 0;
|
2021-08-16 16:25:01 +00:00
|
|
|
void setMaxSize(const glm::vec2& size) { setMaxSize(size.x, size.y); }
|
2023-03-01 19:55:22 +00:00
|
|
|
// Resize and crop the video so it fills the entire area.
|
|
|
|
virtual void setCroppedSize(const glm::vec2& size) = 0;
|
2017-03-25 17:02:28 +00:00
|
|
|
|
2022-02-19 16:04:23 +00:00
|
|
|
// Basic video controls.
|
|
|
|
void startVideoPlayer();
|
2022-09-29 18:18:33 +00:00
|
|
|
virtual void stopVideoPlayer(bool muteAudio = true) {}
|
2022-02-19 16:04:23 +00:00
|
|
|
virtual void pauseVideoPlayer() {}
|
|
|
|
|
2020-11-17 21:13:33 +00:00
|
|
|
// Handle looping of the video. Must be called periodically.
|
2021-07-07 18:31:46 +00:00
|
|
|
virtual void handleLooping() {}
|
2022-02-19 16:04:23 +00:00
|
|
|
// Used to immediately mute audio even if there are still samples to play in the buffer.
|
|
|
|
virtual void muteVideoPlayer() {}
|
2021-07-07 18:31:46 +00:00
|
|
|
virtual void updatePlayer() {}
|
2016-12-04 23:47:34 +00:00
|
|
|
|
2017-01-25 15:00:56 +00:00
|
|
|
protected:
|
2022-02-19 16:04:23 +00:00
|
|
|
virtual void startVideoStream() {}
|
2023-08-13 12:48:00 +00:00
|
|
|
void renderStaticImage(const glm::mat4& parentTrans, bool forceRender);
|
|
|
|
|
|
|
|
enum class OnIterationsDone {
|
|
|
|
NOTHING,
|
|
|
|
IMAGE
|
|
|
|
};
|
2022-02-19 16:04:23 +00:00
|
|
|
|
2023-08-20 17:41:07 +00:00
|
|
|
Renderer* mRenderer;
|
2021-09-18 07:53:26 +00:00
|
|
|
ImageComponent mStaticImage;
|
2023-08-20 17:41:07 +00:00
|
|
|
ImageComponent mBlackFrame;
|
2021-09-18 07:53:26 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
unsigned mVideoWidth;
|
|
|
|
unsigned mVideoHeight;
|
2022-12-12 20:51:27 +00:00
|
|
|
unsigned int mColorShift;
|
|
|
|
unsigned int mColorShiftEnd;
|
2023-08-20 17:41:07 +00:00
|
|
|
float mVideoCornerRadius;
|
2022-12-12 20:51:27 +00:00
|
|
|
bool mColorGradientHorizontal;
|
2021-08-16 16:25:01 +00:00
|
|
|
glm::vec2 mTargetSize;
|
|
|
|
glm::vec2 mVideoAreaPos;
|
|
|
|
glm::vec2 mVideoAreaSize;
|
2023-03-01 19:55:22 +00:00
|
|
|
glm::vec2 mTopLeftCrop;
|
|
|
|
glm::vec2 mBottomRightCrop;
|
2022-10-16 14:40:52 +00:00
|
|
|
glm::vec2 mPillarboxThreshold;
|
2020-06-28 16:39:18 +00:00
|
|
|
std::shared_ptr<TextureResource> mTexture;
|
|
|
|
std::string mStaticImagePath;
|
2022-02-14 18:32:07 +00:00
|
|
|
std::string mDefaultImagePath;
|
2020-06-28 16:39:18 +00:00
|
|
|
|
2022-08-19 15:07:45 +00:00
|
|
|
static inline std::vector<std::string> supportedImageTypes {
|
|
|
|
"image", "miximage", "marquee", "screenshot", "titlescreen",
|
|
|
|
"cover", "backcover", "3dbox", "physicalmedia", "fanart"};
|
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
std::string mVideoPath;
|
2023-08-13 12:48:00 +00:00
|
|
|
OnIterationsDone mOnIterationsDone;
|
2020-06-28 16:39:18 +00:00
|
|
|
unsigned mStartTime;
|
2021-11-16 16:49:05 +00:00
|
|
|
std::atomic<bool> mIsPlaying;
|
|
|
|
std::atomic<bool> mIsActuallyPlaying;
|
2022-02-19 16:04:23 +00:00
|
|
|
std::atomic<bool> mPaused;
|
2021-05-16 11:12:31 +00:00
|
|
|
bool mMediaViewerMode;
|
2020-06-28 16:39:18 +00:00
|
|
|
bool mScreensaverMode;
|
|
|
|
bool mTargetIsMax;
|
2023-03-01 19:55:22 +00:00
|
|
|
bool mTargetIsCrop;
|
2022-02-19 20:45:31 +00:00
|
|
|
bool mPlayAudio;
|
2022-02-12 16:46:31 +00:00
|
|
|
bool mDrawPillarboxes;
|
|
|
|
bool mRenderScanlines;
|
2022-02-19 16:04:23 +00:00
|
|
|
bool mHasVideo;
|
2022-09-16 21:54:13 +00:00
|
|
|
bool mGeneralFade;
|
2022-02-15 20:26:40 +00:00
|
|
|
float mFadeIn;
|
|
|
|
float mFadeInTime;
|
2023-08-13 12:48:00 +00:00
|
|
|
int mIterationCount;
|
|
|
|
int mPlayCount;
|
2020-06-28 16:39:18 +00:00
|
|
|
|
2020-07-18 11:21:44 +00:00
|
|
|
Configuration mConfig;
|
2016-12-04 23:47:34 +00:00
|
|
|
};
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#endif // ES_CORE_COMPONENTS_VIDEO_COMPONENT_H
|