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;
|
|
|
|
};
|
2016-12-04 23:47:34 +00:00
|
|
|
|
|
|
|
public:
|
2020-06-28 16:39:18 +00:00
|
|
|
VideoComponent(Window* window);
|
|
|
|
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); }
|
2020-11-17 21:13:33 +00:00
|
|
|
// Loads a static image that is displayed if the video cannot be played.
|
|
|
|
void setImage(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.
|
2021-07-07 18:31:46 +00:00
|
|
|
void setOpacity(unsigned char opacity) override { mOpacity = opacity; }
|
2017-06-01 20:08:44 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
virtual void onShow() override;
|
|
|
|
virtual void onHide() override;
|
2021-01-31 19:51:24 +00:00
|
|
|
virtual void onStopVideo() override;
|
2020-09-15 20:57:54 +00:00
|
|
|
virtual void onPauseVideo() override;
|
2020-09-26 20:15:36 +00:00
|
|
|
virtual void onUnpauseVideo() override;
|
2020-10-10 13:46:01 +00:00
|
|
|
virtual bool isVideoPaused() override { return mPause; }
|
2020-11-10 21:33:57 +00:00
|
|
|
virtual void onScreensaverActivate() override;
|
|
|
|
virtual void onScreensaverDeactivate() override;
|
2020-07-18 11:21:44 +00:00
|
|
|
virtual void onGameLaunchedActivate() override;
|
|
|
|
virtual void onGameLaunchedDeactivate() override;
|
2020-06-28 16:39:18 +00:00
|
|
|
virtual void topWindow(bool isTop) override;
|
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
|
|
|
|
2021-08-15 17:30:31 +00:00
|
|
|
void render(const glm::mat4& parentTrans) override;
|
|
|
|
void renderSnapshot(const glm::mat4& parentTrans);
|
2016-12-04 23:47:34 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
virtual 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
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
virtual std::vector<HelpPrompt> getHelpPrompts() override;
|
2016-12-04 23:47:34 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
virtual 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 fit this size. If one axis is zero, scale that axis to maintain
|
|
|
|
// aspect ratio. If both are non-zero, potentially break the aspect ratio. If both are
|
|
|
|
// zero, no resizing. This can be set before or after a video is loaded.
|
|
|
|
// setMaxSize() and setResize() are mutually exclusive.
|
2020-12-17 19:49:20 +00:00
|
|
|
virtual void setResize(float width, float height) override = 0;
|
2021-08-16 16:25:01 +00:00
|
|
|
void setResize(const glm::vec2& size) { setResize(size.x, size.y); }
|
2017-03-25 17:02:28 +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
|
|
|
|
2016-12-04 23:47:34 +00:00
|
|
|
private:
|
2020-06-28 16:39:18 +00:00
|
|
|
// Start the video immediately.
|
2021-07-07 18:31:46 +00:00
|
|
|
virtual void startVideo() {}
|
2020-06-28 16:39:18 +00:00
|
|
|
// Stop the video.
|
2021-07-07 18:31:46 +00:00
|
|
|
virtual void stopVideo() {}
|
2020-07-18 11:21:44 +00:00
|
|
|
// Pause the video when a game has been launched.
|
2021-07-07 18:31:46 +00:00
|
|
|
virtual void pauseVideo() {}
|
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() {}
|
|
|
|
virtual void updatePlayer() {}
|
2016-12-04 23:47:34 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
// Start the video after any configured delay.
|
|
|
|
void startVideoWithDelay();
|
|
|
|
// Handle any delay to the start of playing the video clip. Must be called periodically.
|
|
|
|
void handleStartDelay();
|
|
|
|
// Manage the playing state of the component.
|
|
|
|
void manageState();
|
2016-12-04 23:47:34 +00:00
|
|
|
|
2021-05-16 11:12:31 +00:00
|
|
|
friend MediaViewer;
|
|
|
|
|
2017-01-25 15:00:56 +00:00
|
|
|
protected:
|
2020-11-12 16:13:24 +00:00
|
|
|
Window* mWindow;
|
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;
|
2020-06-28 16:39:18 +00:00
|
|
|
std::shared_ptr<TextureResource> mTexture;
|
|
|
|
std::string mStaticImagePath;
|
|
|
|
|
|
|
|
std::string mVideoPath;
|
|
|
|
std::string mPlayingVideoPath;
|
|
|
|
unsigned mStartTime;
|
2020-09-15 20:57:54 +00:00
|
|
|
bool mStartDelayed;
|
2021-11-16 16:49:05 +00:00
|
|
|
std::atomic<bool> mIsPlaying;
|
|
|
|
std::atomic<bool> mIsActuallyPlaying;
|
|
|
|
std::atomic<bool> mPause;
|
2020-06-28 16:39:18 +00:00
|
|
|
bool mShowing;
|
|
|
|
bool mDisable;
|
2021-05-16 11:12:31 +00:00
|
|
|
bool mMediaViewerMode;
|
2020-06-28 16:39:18 +00:00
|
|
|
bool mScreensaverActive;
|
|
|
|
bool mScreensaverMode;
|
2020-07-18 11:21:44 +00:00
|
|
|
bool mGameLaunched;
|
2020-09-15 20:57:54 +00:00
|
|
|
bool mBlockPlayer;
|
2020-06-28 16:39:18 +00:00
|
|
|
bool mTargetIsMax;
|
2020-10-11 16:57:37 +00:00
|
|
|
float mFadeIn; // Used for fading in the video screensaver.
|
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
|