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;
|
|
|
|
bool showSnapshotNoVideo;
|
|
|
|
bool showSnapshotDelay;
|
|
|
|
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;
|
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}; }
|
2022-02-19 16:04:23 +00:00
|
|
|
bool hasStartDelay()
|
|
|
|
{
|
|
|
|
if (mLegacyTheme)
|
|
|
|
return mConfig.showSnapshotDelay && mConfig.startDelay > 0;
|
|
|
|
else
|
|
|
|
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); }
|
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() {}
|
|
|
|
void renderSnapshot(const glm::mat4& parentTrans);
|
|
|
|
|
2021-09-18 07:53:26 +00:00
|
|
|
ImageComponent mStaticImage;
|
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
unsigned mVideoWidth;
|
|
|
|
unsigned mVideoHeight;
|
2021-08-16 16:25:01 +00:00
|
|
|
glm::vec2 mTargetSize;
|
|
|
|
glm::vec2 mVideoAreaPos;
|
|
|
|
glm::vec2 mVideoAreaSize;
|
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;
|
|
|
|
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;
|
2022-02-19 20:45:31 +00:00
|
|
|
bool mPlayAudio;
|
2022-02-12 16:46:31 +00:00
|
|
|
bool mDrawPillarboxes;
|
|
|
|
bool mRenderScanlines;
|
|
|
|
bool mLegacyTheme;
|
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;
|
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
|