BitmapToolkit Scol plugin
|
This class provides media playback functionality. More...
#include <MediaPlayer.h>
Public Types | |
enum | AudioFormats { AUDIO_8BIT_MONO , AUDIO_8BIT_STEREO , AUDIO_16BIT_MONO , AUDIO_16BIT_STEREO } |
enum | State { STOPPED , PLAYING , PAUSED } |
Public Member Functions | |
MediaPlayer () | |
Create an empty player. | |
virtual | ~MediaPlayer () |
void | Open (std::string path) |
Open the media file at the given path. If a media was already loaded, it will be replaced by the new one. | |
void | OpenUrl (std::string url) |
Open the media at the given URL. | |
void | Close () |
Close the current media file, if any. | |
bool | IsReady () |
Check whether the player has a media ready to play. | |
State | GetState () |
Get the current state of this player. | |
bool | HasAudio () |
Check whether the player has an audio track selected and ready to play. | |
bool | HasVideo () |
Check whether the player has a video track selected and ready to play. | |
long | GetLength () |
Get the length of the current media stream. | |
bool | IsSeekable () |
Check whether the file or stream is seekable. | |
bool | IsLiveStream () |
Check whether the current media is a live stream. | |
void | GetSize (int &width, int &height) |
Get the current size of the video (after resize) | |
void | GetSourceSize (int &width, int &height) |
Get the original size of the video (before resize) | |
void | SetSize (int width, int height) |
Set the target size for the video. | |
void | SetAudioFormat (AudioFormats format, int sampleRate) |
Set the output format for audio. | |
void | Play (long startPosition=0) |
Play/resume the currently loaded media. | |
void | Pause () |
Pause the current media playback. | |
void | Stop () |
Stop media playback. | |
void | SetLoop (bool loop) |
Set whether media playback should loop or not. | |
void | SetCurrentTime (long time) |
Set the current playback time of the media. | |
long | GetCurrentTime () |
Get the current playback time of the media. | |
bool | GetFrame (ObjBitmap *scolBitmap) |
Get the current decoded video frame. | |
bool | GetFrame (cv::Mat &buffer) |
Get the current decoded video frame. | |
cv::Mat | GetFrame () |
Get the current decoded video frame. | |
int | GetAudioThreaded (char *destBuffer, size_t length) |
Get decoded audio data from the media (using the dedicated audio thread). | |
int | SetVideoStream (int streamIndex=-1) |
Select the video stream to play from the current file. | |
int | SetAudioStream (int streamIndex=-1) |
Select the audio stream to play from the current file. | |
std::vector< std::string > | ListStreams (AVMediaType type) |
Static Public Member Functions | |
static void | InitFFmpeg () |
Init FFmpeg functionalities. Call this before any other MediaPlayer functions. | |
static void | DeInitFFmpeg () |
Free resources allocated by init. Call this when you're done with MediaPlayer. | |
static void | SetGlobalPause (bool pause) |
Pause/unpause every MediaPlayer. | |
static bool | IsValidPlayer (MediaPlayer *player) |
Check whether a media player is still valid. | |
Static Public Attributes | |
static const int | VIDEO_SIZE_AUTO = 0 |
static const int | STREAM_UNDEFINED = -1 |
static const int | BUFFER_COUNT = 2 |
static const AVPixelFormat | DEST_PIXEL_FORMAT = AV_PIX_FMT_BGR24 |
static const AVRational | TIME_BASE = { 1, 1000 } |
static const AVRational | FF_AV_TIME_BASE_Q = { 1, AV_TIME_BASE } |
static const int | AV_SYNC_THRESHOLD = 16 |
static const int | MAX_READ_ERRORS = 30 |
Detailed Description
This class provides media playback functionality.
Definition at line 52 of file MediaPlayer.h.
Member Enumeration Documentation
◆ AudioFormats
Enumerator | |
---|---|
AUDIO_8BIT_MONO | |
AUDIO_8BIT_STEREO | |
AUDIO_16BIT_MONO | |
AUDIO_16BIT_STEREO |
Definition at line 71 of file MediaPlayer.h.
◆ State
enum MediaPlayer::State |
Enumerator | |
---|---|
STOPPED | |
PLAYING | |
PAUSED |
Definition at line 79 of file MediaPlayer.h.
Constructor & Destructor Documentation
◆ MediaPlayer()
MediaPlayer::MediaPlayer | ( | ) |
Create an empty player.
Definition at line 110 of file MediaPlayer.cpp.
◆ ~MediaPlayer()
|
virtual |
Definition at line 161 of file MediaPlayer.cpp.
Member Function Documentation
◆ Close()
void MediaPlayer::Close | ( | ) |
Close the current media file, if any.
Definition at line 329 of file MediaPlayer.cpp.
◆ DeInitFFmpeg()
|
static |
Free resources allocated by init. Call this when you're done with MediaPlayer.
Definition at line 76 of file MediaPlayer.cpp.
◆ GetAudioThreaded()
int MediaPlayer::GetAudioThreaded | ( | char * | destBuffer, |
size_t | length | ||
) |
Get decoded audio data from the media (using the dedicated audio thread).
- Parameters
-
destBuffer Buffer where the audio data will be stored. length How much data to retrieve, in bytes.
- Returns
- Number of bytes that were actually written to the buffer.
Definition at line 1481 of file MediaPlayer.cpp.
◆ GetCurrentTime()
long MediaPlayer::GetCurrentTime | ( | ) |
Get the current playback time of the media.
- Returns
- Time in milliseconds.
Definition at line 590 of file MediaPlayer.cpp.
◆ GetFrame() [1/3]
cv::Mat MediaPlayer::GetFrame | ( | ) |
Get the current decoded video frame.
- Returns
- cv::Mat buffer if frame was retrieved, empty frame if no new frame available.
Definition at line 648 of file MediaPlayer.cpp.
◆ GetFrame() [2/3]
bool MediaPlayer::GetFrame | ( | cv::Mat & | buffer | ) |
Get the current decoded video frame.
- Parameters
-
cv::Mat buffer where the frame will be copied.
- Returns
- True if a new frame was retrieved, false if no new frame available.
Definition at line 624 of file MediaPlayer.cpp.
◆ GetFrame() [3/3]
bool MediaPlayer::GetFrame | ( | ObjBitmap * | scolBitmap | ) |
Get the current decoded video frame.
- Parameters
-
scolBitmap Bitmap where the frame will be copied.
- Returns
- True if a new frame was retrieved, false if no new frame available.
Definition at line 595 of file MediaPlayer.cpp.
◆ GetLength()
long MediaPlayer::GetLength | ( | ) |
Get the length of the current media stream.
- Returns
- Length of the stream in milliseconds, -1 if unknown
Definition at line 370 of file MediaPlayer.cpp.
◆ GetSize()
void MediaPlayer::GetSize | ( | int & | width, |
int & | height | ||
) |
Get the current size of the video (after resize)
- Parameters
-
[out] width Width of the video in pixels [out] height Height of the video in pixels
Definition at line 398 of file MediaPlayer.cpp.
◆ GetSourceSize()
void MediaPlayer::GetSourceSize | ( | int & | width, |
int & | height | ||
) |
Get the original size of the video (before resize)
- Parameters
-
[out] width Width of the video in pixels [out] height Height of the video in pixels
Definition at line 409 of file MediaPlayer.cpp.
◆ GetState()
MediaPlayer::State MediaPlayer::GetState | ( | ) |
Get the current state of this player.
- Returns
- Either STOPPED(0), PLAYING(1) or PAUSED(2).
Definition at line 350 of file MediaPlayer.cpp.
◆ HasAudio()
bool MediaPlayer::HasAudio | ( | ) |
Check whether the player has an audio track selected and ready to play.
- Returns
- True if it is the case.
Definition at line 360 of file MediaPlayer.cpp.
◆ HasVideo()
bool MediaPlayer::HasVideo | ( | ) |
Check whether the player has a video track selected and ready to play.
- Returns
- True if it is the case.
Definition at line 365 of file MediaPlayer.cpp.
◆ InitFFmpeg()
|
static |
Init FFmpeg functionalities. Call this before any other MediaPlayer functions.
Definition at line 69 of file MediaPlayer.cpp.
◆ IsLiveStream()
bool MediaPlayer::IsLiveStream | ( | ) |
Check whether the current media is a live stream.
- Returns
- True if the source is a live stream.
Definition at line 392 of file MediaPlayer.cpp.
◆ IsReady()
bool MediaPlayer::IsReady | ( | ) |
Check whether the player has a media ready to play.
- Returns
- True if a media is loaded and a stream selected.
Definition at line 345 of file MediaPlayer.cpp.
◆ IsSeekable()
bool MediaPlayer::IsSeekable | ( | ) |
Check whether the file or stream is seekable.
- Returns
- True if the source is seekable.
Definition at line 380 of file MediaPlayer.cpp.
◆ IsValidPlayer()
|
static |
Check whether a media player is still valid.
- Parameters
-
player Pointer to the MediaPlayer object to be checked.
- Returns
- True if player is present in the global player list, false otherwise.
Definition at line 99 of file MediaPlayer.cpp.
◆ ListStreams()
std::vector< std::string > MediaPlayer::ListStreams | ( | AVMediaType | type | ) |
Definition at line 788 of file MediaPlayer.cpp.
◆ Open()
void MediaPlayer::Open | ( | std::string | path | ) |
Open the media file at the given path. If a media was already loaded, it will be replaced by the new one.
- Parameters
-
path Path to the media file.
Definition at line 239 of file MediaPlayer.cpp.
◆ OpenUrl()
void MediaPlayer::OpenUrl | ( | std::string | url | ) |
Open the media at the given URL.
- Parameters
-
url Url of the media. close Whether to close the currently open file or not (used internally). Should be left to true.
Definition at line 321 of file MediaPlayer.cpp.
◆ Pause()
void MediaPlayer::Pause | ( | ) |
Pause the current media playback.
Definition at line 514 of file MediaPlayer.cpp.
◆ Play()
void MediaPlayer::Play | ( | long | startPosition = 0 | ) |
Play/resume the currently loaded media.
- Parameters
-
startPosition In case the player is stopped, the position in milliseconds at which we want it to start. Defaults to 0 (beginning).
Definition at line 487 of file MediaPlayer.cpp.
◆ SetAudioFormat()
void MediaPlayer::SetAudioFormat | ( | AudioFormats | format, |
int | sampleRate | ||
) |
Set the output format for audio.
- Parameters
-
format Sample format with channel layout (one of AUDIO_*) sampleRate Frequency in Hz
Definition at line 432 of file MediaPlayer.cpp.
◆ SetAudioStream()
int MediaPlayer::SetAudioStream | ( | int | streamIndex = -1 | ) |
Select the audio stream to play from the current file.
- Parameters
-
streamIndex Index of the desired stream. Leave to -1 for default stream.
- Returns
- The selected stream.
Definition at line 703 of file MediaPlayer.cpp.
◆ SetCurrentTime()
void MediaPlayer::SetCurrentTime | ( | long | time | ) |
Set the current playback time of the media.
- Parameters
-
time Time in milliseconds to seek to.
Definition at line 561 of file MediaPlayer.cpp.
◆ SetGlobalPause()
|
static |
Pause/unpause every MediaPlayer.
- Parameters
-
pause True to pause, false to unpause.
Definition at line 81 of file MediaPlayer.cpp.
◆ SetLoop()
void MediaPlayer::SetLoop | ( | bool | loop | ) |
Set whether media playback should loop or not.
- Parameters
-
loop true to loop playback, false to stop on media end.
Definition at line 556 of file MediaPlayer.cpp.
◆ SetSize()
void MediaPlayer::SetSize | ( | int | width, |
int | height | ||
) |
Set the target size for the video.
- Parameters
-
width Desired width in pixels height Desired height in pixels
Definition at line 420 of file MediaPlayer.cpp.
◆ SetVideoStream()
int MediaPlayer::SetVideoStream | ( | int | streamIndex = -1 | ) |
Select the video stream to play from the current file.
- Parameters
-
streamIndex Index of the desired stream. Leave to -1 for default stream.
- Returns
- The selected stream.
Definition at line 662 of file MediaPlayer.cpp.
◆ Stop()
void MediaPlayer::Stop | ( | ) |
Stop media playback.
Definition at line 533 of file MediaPlayer.cpp.
Member Data Documentation
◆ AV_SYNC_THRESHOLD
|
static |
Definition at line 66 of file MediaPlayer.h.
◆ BUFFER_COUNT
|
static |
Definition at line 57 of file MediaPlayer.h.
◆ DEST_PIXEL_FORMAT
|
static |
Definition at line 58 of file MediaPlayer.h.
◆ FF_AV_TIME_BASE_Q
|
static |
Definition at line 53 of file MediaPlayer.h.
◆ MAX_READ_ERRORS
|
static |
Definition at line 69 of file MediaPlayer.h.
◆ STREAM_UNDEFINED
|
static |
Definition at line 56 of file MediaPlayer.h.
◆ TIME_BASE
|
static |
Definition at line 51 of file MediaPlayer.h.
◆ VIDEO_SIZE_AUTO
|
static |
Definition at line 55 of file MediaPlayer.h.
The documentation for this class was generated from the following files:
- include/MediaPlayer.h
- src/MediaPlayer.cpp
Generated by 1.9.8