#include <videoplayer.h>
Public Member Functions | |
VideoPlayer (VideoService &service) | |
const VideoFile & | getFile () const |
const Video & | getVideo () const |
Video & | getVideo () |
int | getIndex () const |
int | getCount () const |
bool | selectVideo (int index, utility::ErrorState &error) |
void | play (double startTime=0.0, bool clearTextures=true) |
void | stopPlayback () |
bool | isPlaying () const |
void | loop (bool value) |
bool | isLooping () const |
void | setSpeed (float speed) |
float | getSpeed () const |
void | seek (double seconds) |
double | getCurrentTime () const |
double | getDuration () const |
int | getWidth () const |
int | getHeight () const |
bool | hasAudio () const |
virtual bool | start (utility::ErrorState &errorState) override |
virtual void | stop () override |
bool | hasSelection () const |
Texture2D & | getYTexture () |
Texture2D & | getUTexture () |
Texture2D & | getVTexture () |
![]() | |
Resource () | |
![]() | |
Object () | |
virtual | ~Object () |
virtual bool | init (utility::ErrorState &errorState) |
virtual void | onDestroy () |
Object (Object &)=delete | |
Object & | operator= (const Object &)=delete |
Object (Object &&)=delete | |
Object & | operator= (Object &&)=delete |
Public Attributes | |
std::vector< nap::ResourcePtr< VideoFile > > | mVideoFiles |
Property: 'Files' All video file links. More... | |
nap::uint | mVideoIndex = 0 |
Property: 'Index' Selected video index. More... | |
bool | mLoop = false |
Property: 'Loop' if the selected video loops. More... | |
float | mSpeed = 1.0f |
Property: 'Speed' video playback speed. More... | |
nap::Signal< nap::VideoPlayer & > | VideoChanged |
![]() | |
std::string | mID |
Property: 'mID' unique name of the object. Used as an identifier by the system. More... | |
Additional Inherited Members | |
![]() | |
static bool | isIDProperty (rtti::Instance &object, const rtti::Property &property) |
Video playback device.
Decodes a video, from a list of videos, in a background thread and stores the result in a set of YUV textures. The textures are filled with the latest frame data on update(), which is a non-blocking operation. The nap::VideoService calls update() automatically each frame.
The main thread will consume the frames when they are present in the frame queue and their timestamp has 'passed'. Internally the textures are only updated when needed. YUV to RGB Conversion can be done in a shader.
Videos are cached internally. This means that all videos in the playlist are created on start(), including the associated video format and video codec contexts. This ensures that a video can be started and stopped fast, without having to re-open a video when switching. The IO and decode threads are spawned on play() and stopped on stopPlayback().
Note that the YUV textures are (re)-created when the video dimensions change from selection to selection. This is done to ensure there is always only 1 set of YUV textures allocated on the GPU per video player instance, instead of a set of textures per video. A valid set of textures is always available after a successful call to selectVideo() Listen to the VideoChanged signal to get notified about a video change.
Every video must contain a video stream, the audio stream is optional. Use a nap::VideoAudioComponent to decode and play back the audio of a video. Without a nap::VideoAudioComponent no audio is decoded and therefore played back.
Do not call start() and stop() at runtime, unless you want to completely restart the device and free all memory, start() and stop() are called automatically by the engine at the appropiate time. Use play() and stopPlayback() instead to start and stop playback of the currently selected video. You always have to call play() after selecting a different video:
VideoPlayer | ( | VideoService & | service | ) |
int getCount | ( | ) | const |
double getCurrentTime | ( | ) | const |
double getDuration | ( | ) | const |
const VideoFile& getFile | ( | ) | const |
int getHeight | ( | ) | const |
int getIndex | ( | ) | const |
float getSpeed | ( | ) | const |
Texture2D& getUTexture | ( | ) |
Returns the decoded video U texture. The texture is not initialized to zero, but to the 'black' equivalent in YUV space. The size of the U texture is HALF the width * height.
Video& getVideo | ( | ) |
const Video& getVideo | ( | ) | const |
Texture2D& getVTexture | ( | ) |
Returns the decoded video V texture. The texture is not initialized to zero, but to the 'black' equivalent in YUV space. The size of the V texture is HALF the width * height.
int getWidth | ( | ) | const |
Texture2D& getYTexture | ( | ) |
Returns the decoded video Y texture. The texture is not initialized to zero, but to the 'black' equivalent in YUV space. The size of the Y texture is width * height.
bool hasAudio | ( | ) | const |
bool hasSelection | ( | ) | const |
bool isLooping | ( | ) | const |
bool isPlaying | ( | ) | const |
Check if the currently loaded video is playing.
void loop | ( | bool | value | ) |
If the video re-starts after completion.
value | if the video re-starts after completion. |
void play | ( | double | startTime = 0.0 , |
bool | clearTextures = true |
||
) |
Starts playback of the current video at the given offset in seconds.
startTime | The offset in seconds to start the video at. |
clearTextures | if the old textures should be cleared before starting playback. |
void seek | ( | double | seconds | ) |
Seeks within the video to the time provided. This can be called while playing.
seconds | the time offset in seconds in the video. |
bool selectVideo | ( | int | index, |
utility::ErrorState & | error | ||
) |
Loads a new video to play, returns false if selection fails. The 'VideoChanged' signal is emitted on success. Call play() afterwards to start playback of the video.
A new set of YUV textures is generated IF the new video has different dimensions or is the first to be selected. The old set of textures will be destroyed immediately and will be invalid after this call.
index | index of the video to load. |
error | contains the error if changing the video fails. |
void setSpeed | ( | float | speed | ) |
Changes the playback speed of the player.
speed | new playback speed, 1.0f = default speed. |
|
overridevirtual |
Starts the device.
errorState | contains the error if the device can't be started |
Reimplemented from Device.
|
overridevirtual |
Stops the device
Reimplemented from Device.
void stopPlayback | ( | ) |
Stops playback of the current video.
bool mLoop = false |
Property: 'Loop' if the selected video loops.
float mSpeed = 1.0f |
Property: 'Speed' video playback speed.
std::vector<nap::ResourcePtr<VideoFile> > mVideoFiles |
Property: 'Files' All video file links.
nap::uint mVideoIndex = 0 |
Property: 'Index' Selected video index.
nap::Signal<nap::VideoPlayer&> VideoChanged |
Emitted after a successful video switch.