Ocean
|
This class implements a frame provider for movie mediums. More...
Public Types | |
enum | EventType { ET_INVALID , ET_NEW_MEDIA , ET_PREVIEW_COMPLETED , ET_FRAME_SIZE_CHANGED , ET_REQUESTED_FRAME_FAILED } |
Definition of individual event types. More... | |
typedef Callback< void, const unsigned int, const bool > | FrameCallback |
Definition of frame callback function. More... | |
typedef Callback< void, const unsigned int > | PreviewFrameCallback |
Definition of a preview frame callback function. More... | |
typedef Callback< void, const EventType, const unsigned long long > | EventCallback |
Definition of an event callback function. More... | |
typedef IndexPair32 | Dimension |
Definition of a pair of sizes. More... | |
Public Member Functions | |
MovieFrameProvider (const bool enabled=true, const unsigned int maximalFrameStorage=150u, const unsigned int maximalQueueStorage=50u) | |
Creates a new movie frame provider. More... | |
~MovieFrameProvider () override | |
Destructs the movie frame provider. More... | |
bool | isEnabled () const |
Returns whether the provider is enabled. More... | |
bool | setEnabled (const bool state) |
Enables or disables the provider. More... | |
std::string | url () const |
Returns the url of the media. More... | |
bool | setMovie (const MovieRef &movie) |
Sets the movie providing the frames. More... | |
bool | setPreferredFrameType (const FrameType::PixelFormat pixelFormat, const FrameType::PixelOrigin pixelOrigin) |
Sets the preferred frame type of the frames of this provider. More... | |
bool | setPreferredPreviewDimension (const unsigned int width, const unsigned int height) |
Sets the dimension of the preview frames. More... | |
double | duration () const |
Returns the current duration of the media in seconds. More... | |
Dimension | frameDimension () const |
Returns the frame dimension of the frames of this provider. More... | |
const FrameType & | frameType () const |
Returns the frame type of the frames of this provider. More... | |
Dimension | preferredPreviewDimension () const |
Returns the preferred frame dimension of the preview frames. More... | |
size_t | frameCapacity () const |
Returns the capacity of frames that can be stored concurrently. More... | |
bool | setFrameCapacity (const size_t capacity) |
Sets or changes the capacity of the frames to be stored concurrently. More... | |
void | addFrameCallback (const FrameCallback &callback) |
Adds a new frame callback event function. More... | |
void | addPreviewFrameCallback (const PreviewFrameCallback &callback) |
Adds a new preview frame callback event function. More... | |
void | addEventCallback (const EventCallback &callback) |
Adds a new event callback event function. More... | |
void | removeFrameCallback (const FrameCallback &callback) |
Removes a frame callback event function. More... | |
void | removePreviewFrameCallback (const PreviewFrameCallback &callback) |
Removes a preview frame callback event function. More... | |
void | removeEventCallback (const EventCallback &callback) |
Removes an event callback event function. More... | |
unsigned int | actualFrameNumber () |
Returns the number of frames the media actually provides. More... | |
unsigned int | estimatedFrameNumber () |
Returns the estimated number of frames that can be provided. More... | |
unsigned int | currentFrameNumber () |
Returns the current number of frames that can be provided. More... | |
unsigned int | frameNumber () |
Returns the best guess of the number of frames of this provider. More... | |
FrameRef | synchronFrameRequest (const unsigned int index, const double timeout=10.0, bool *abort=nullptr) |
Requests a frame synchronously. More... | |
void | asynchronFrameRequest (const unsigned int index, const bool priority=true) |
Requests a frame asynchronously. More... | |
FrameRef | frame (const unsigned index) |
Returns a frame directly if the frame is currently available. More... | |
FrameRef | frameRequest (const unsigned int index) |
Returns a frame directly if the frame is currently available, otherwise the frame will be requested asynchronously (by internally calling asynchronously). More... | |
FrameRef | previewFrame (const unsigned int index) |
Returns a preview frame. More... | |
FrameRefs | previewFrames (const unsigned int index, const unsigned int size, const unsigned int zoom=1u) |
Returns several preview frames. More... | |
Dimension | determinePreviewDimensions () const |
Determines the current preview dimension for the current frame size and specified preferred preview dimension. More... | |
unsigned int | previewProgress () const |
Returns the preview progress of this frame provider. More... | |
Protected Member Functions | |
void | release () |
Releases the frame provider. More... | |
void | threadRun () override |
Thread run function. More... | |
void | onPreviewFrame (const Frame &frame, const SharedAnyCamera &camera) |
Internal event function for new preview frames. More... | |
void | onFrame (const Frame &frame, const SharedAnyCamera &camera) |
Internal event function for new frames. More... | |
bool | handlePreviewFrame (const Frame &frame, unsigned int index, const unsigned int previewWidth, const unsigned int previewHeight) |
Creates a new preview frame by a given original frame. More... | |
unsigned int | timestamp2index (const double timestamp, const bool lookup=false) |
Determines the frame index for a given timestamp. More... | |
double | index2timestamp (const unsigned int index) |
Converts the index of a frame into the corresponding timestamp. More... | |
Protected Member Functions inherited from Ocean::Thread | |
Thread (const Thread &thread)=delete | |
Disabled copy constructor. More... | |
void | createThread () |
Creates the thread itself. More... | |
void | destroyThread () |
Destroys the thread itself. More... | |
void | stopThreadExplicitly (const unsigned int timeout=5000u) |
Tries to stop the thread gracefully. More... | |
Thread & | operator= (const Thread &thread)=delete |
The disabled assign operator. More... | |
Thread (const std::string &name=std::string()) | |
Creates a new thread object. More... | |
Thread (const unsigned int randomNumberSeedValue, const std::string &name=std::string()) | |
Creates a new thread object. More... | |
virtual | ~Thread () |
Destructs a thread object. More... | |
bool | startThread () |
Starts the thread. More... | |
void | stopThread () |
Informs the thread to stop. More... | |
bool | terminateThread () |
Terminates the thread. More... | |
bool | joinThread (const unsigned int timeout=(unsigned int)(-1)) |
Waits until this thread has been stopped. More... | |
bool | shouldThreadStop () const |
Returns whether this thread should stop. More... | |
bool | isThreadInvokedToStart () const |
Returns whether this thread has been invoked to start immediately. More... | |
bool | isThreadActive () const |
Returns whether this thread is active. More... | |
Protected Attributes | |
bool | enabled_ = false |
Provider enabled state. More... | |
bool | released_ = false |
State that is set directly if the provider has been invoked to be disposed. More... | |
MovieRef | moviePreview_ |
Movie providing the preview frames. More... | |
MovieRef | movie_ |
Movie providing the frames. More... | |
FrameMedium::FrameCallbackScopedSubscription | scopedSubscriptionPreviewFrames_ |
The subscription objects for previewing frame callback events. More... | |
FrameMedium::FrameCallbackScopedSubscription | scopedSubscriptionFrames_ |
The subscription objects for frame callback events. More... | |
double | mediaDuration_ = 0.0 |
Duration of the media in seconds. More... | |
double | mediaFrameFrequency_ = 0.0 |
Frequency of the media in Hz. More... | |
double | mediaFrameTime_ = 0.0 |
Average time for one frame in the media. More... | |
unsigned int | actualFrameNumber_ = 0u |
Actual number of frames that the provider organizes. More... | |
unsigned int | estimatedFrameNumber_ = 0u |
Estimated number of frames that the provider will organize. More... | |
unsigned int | currentFrameNumber_ = 0u |
Number of frames that the provider currently organizes. More... | |
unsigned int | maximalQueueSize_ = 0u |
Maximal size of the internal intermediate frame queues. More... | |
FrameType::PixelFormat | preferredPixelFormat_ = FrameType::FORMAT_UNDEFINED |
The preferred pixel format of the provider's frames. More... | |
FrameType::PixelOrigin | preferredPixelOrigin_ = FrameType::ORIGIN_INVALID |
The preferred pixel origin of the provider's frames. More... | |
FrameQueue | previewFrameQueue_ |
Intermediate queue for preview frames. More... | |
FrameQueue | frameQueue_ |
Intermediate queue for frames. More... | |
FrameDatabase | frames_ |
Database holding the media frames. More... | |
PreviewFrames | previewFrames_ |
Vector holding the preview frames. More... | |
RequestList | requestList_ |
List of frames that are explicitly requested. More... | |
FrameType | frameType_ |
Frame type of the media frames. More... | |
unsigned int | preferredPreviewWidth_ = 0u |
Preferred width of the preview frames in pixel. More... | |
unsigned int | preferredPreviewHeight_ = 100u |
Preferred height of the preview frames in pixel. More... | |
FrameCallbacks | frameCallbacks_ |
Frame event callback functions. More... | |
PreviewFrameCallbacks | previewFrameCallbacks_ |
Preview frame event callback functions. More... | |
EventCallbacks | eventCallbacks_ |
Event callback functions. More... | |
unsigned int | frameRequestIndex_ = (unsigned int)(-1) |
Index of the currently requested frame. More... | |
Timestamp | lastFrameEventTimestamp_ |
Timestamp as the last frame has been arrived. More... | |
Timestamp | movieStopTimestamp_ |
Timestamp that stops the standard frame medium. More... | |
double | frameRequestTimeout_ = 1.0 |
Time period that may exceed until a frame is expected to be unavailable, in seconds, with range (0, infinity) More... | |
Lock | lock_ |
Provider lock. More... | |
Lock | frameLock_ |
Frame lock. More... | |
Private Types | |
typedef RingMapT< unsigned int, FrameRef, false > | FrameDatabase |
Definition of a non-thread-safe ring map mapping frame indices to frame references. More... | |
typedef std::pair< bool, FrameRef > | PreviewFrame |
Definition of a preview frame composed of a finished-state and the frame data. More... | |
typedef std::vector< PreviewFrame > | PreviewFrames |
Definition of a vector holding preview frames. More... | |
typedef std::queue< FrameRef > | FrameQueue |
Definition of a queue holding frames. More... | |
typedef std::list< unsigned int > | RequestList |
Definition of a list holding frame indices. More... | |
typedef ConcurrentCallbacks< FrameCallback > | FrameCallbacks |
Definition of a callback container storing frame callbacks. More... | |
typedef ConcurrentCallbacks< PreviewFrameCallback > | PreviewFrameCallbacks |
Definition of a callback container storing preview frame callbacks. More... | |
typedef ConcurrentCallbacks< EventCallback > | EventCallbacks |
Definition of a callback container storing event callbacks. More... | |
Additional Inherited Members | |
Protected Types inherited from Ocean::Thread | |
typedef std::pair< pthread_t, bool > | TimedJoinPair |
Definition of a pair holding a thread id and a boolean state. More... | |
enum | ThreadPriority { PRIORITY_IDLE , PRIORTY_BELOW_NORMAL , PRIORTY_NORMAL , PRIORTY_ABOVE_NORMAL , PRIORTY_HIGH , PRIORTY_REALTIME } |
Definition of different thread priority values. More... | |
Static Protected Member Functions inherited from Ocean::Thread | |
static void | sleep (unsigned int ms) |
Sleeps the calling thread for a given time. More... | |
static void | giveUp () |
Gives up the remaining thread time. More... | |
static ThreadId | currentThreadId () |
Returns the thread id of the current (calling) thread. More... | |
static ThreadPriority | threadPriority () |
Returns the priority of the current thread. More... | |
static bool | setThreadPriority (const ThreadPriority priority) |
Sets the priority of the current thread. More... | |
template<typename TObject , typename TExpectedValue > | |
static bool | waitForValue (TObject &object, const TExpectedValue &expectedValue, const double timeout=-1.0) |
Waits until an object/variable has an expected value. More... | |
template<typename TObject , typename TExpectedValue > | |
static bool | waitForValue (TObject &object, const TExpectedValue &expectedValue, TemporaryScopedLock &temporaryScopedLock, const double timeout=-1.0) |
Waits until an object/variable has an expected value. More... | |
static int | pthread_timedjoin_np (pthread_t thread, void **retval, const struct timespec *abstime) |
Implements a thread join function with timeout value. More... | |
This class implements a frame provider for movie mediums.
In addition to allowing access to the movie's frame, this provider also allows access to smaller preview frames.
Definition of a pair of sizes.
typedef Callback<void, const EventType, const unsigned long long> Ocean::Media::MovieFrameProvider::EventCallback |
Definition of an event callback function.
The first parameter specifies the event type.
The second parameter holds an optional event parameter.
Definition of a callback container storing event callbacks.
typedef Callback<void, const unsigned int, const bool> Ocean::Media::MovieFrameProvider::FrameCallback |
Definition of frame callback function.
The first parameter defines the index of the frame.
The second parameter states whether the frames has been explicitly requested.
Definition of a callback container storing frame callbacks.
|
private |
Definition of a non-thread-safe ring map mapping frame indices to frame references.
|
private |
Definition of a queue holding frames.
|
private |
Definition of a preview frame composed of a finished-state and the frame data.
typedef Callback<void, const unsigned int> Ocean::Media::MovieFrameProvider::PreviewFrameCallback |
Definition of a preview frame callback function.
The first parameter defines the index of the preview frame.
|
private |
Definition of a callback container storing preview frame callbacks.
|
private |
Definition of a vector holding preview frames.
|
private |
Definition of a list holding frame indices.
Definition of individual event types.
|
explicit |
Creates a new movie frame provider.
enabled | True, to enable the provider directly |
maximalFrameStorage | The maximal number of frames that will be stored inside the frame provider concurrently |
maximalQueueStorage | The maximal number of frames that will be queued inside the frame provider concurrently |
|
override |
Destructs the movie frame provider.
unsigned int Ocean::Media::MovieFrameProvider::actualFrameNumber | ( | ) |
Returns the number of frames the media actually provides.
The number of actual frames is unknown until all preview frames have been determined.
|
inline |
Adds a new event callback event function.
Each callback has to be removed before this frame provider is disposed.
callback | The callback function to be added |
|
inline |
Adds a new frame callback event function.
Each callback has to be removed before this frame provider is disposed.
callback | The callback function to be added |
|
inline |
Adds a new preview frame callback event function.
Each callback has to be removed before this frame provider is disposed.
callback | The callback function to be added |
void Ocean::Media::MovieFrameProvider::asynchronFrameRequest | ( | const unsigned int | index, |
const bool | priority = true |
||
) |
Requests a frame asynchronously.
If the frame is available the frame can be accessed by e.g. the frame() or frameRequest() function.
If a frame event callback has been defined, an event will occur if the requested frame is available.
index | The index of the frame that is requested |
priority | True, to receive the frame as fast as possible |
unsigned int Ocean::Media::MovieFrameProvider::currentFrameNumber | ( | ) |
Returns the current number of frames that can be provided.
This number is identical to the number of existing preview frames.
Dimension Ocean::Media::MovieFrameProvider::determinePreviewDimensions | ( | ) | const |
Determines the current preview dimension for the current frame size and specified preferred preview dimension.
|
inline |
Returns the current duration of the media in seconds.
unsigned int Ocean::Media::MovieFrameProvider::estimatedFrameNumber | ( | ) |
Returns the estimated number of frames that can be provided.
This number is an estimation due to the media information and may be an approximation only.
FrameRef Ocean::Media::MovieFrameProvider::frame | ( | const unsigned | index | ) |
Returns a frame directly if the frame is currently available.
If the frame does not exist, nothing happens.
index | The index of the frame that is requested |
|
inline |
Returns the capacity of frames that can be stored concurrently.
The capacity does not reflect the preview frames.
|
inline |
Returns the frame dimension of the frames of this provider.
unsigned int Ocean::Media::MovieFrameProvider::frameNumber | ( | ) |
Returns the best guess of the number of frames of this provider.
If the actual number of frames is known, this number is returned.
Otherwise the highest value of estimatedFrameNumber() and currentFrameNumber() is returned.
FrameRef Ocean::Media::MovieFrameProvider::frameRequest | ( | const unsigned int | index | ) |
Returns a frame directly if the frame is currently available, otherwise the frame will be requested asynchronously (by internally calling asynchronously).
If the frame is requested asynchronously the frame will be provided after this function returns.
If the frame is provided asynchronously, the an event will occur if the requested frame is available.
index | The index of the frame that is requested |
|
inline |
Returns the frame type of the frames of this provider.
|
protected |
Creates a new preview frame by a given original frame.
frame | The frame for that a preview frame has to be created |
index | The index of the given frame |
previewWidth | Width of the resulting preview frame in pixel, with range [1, infinity) |
previewHeight | Height of the resulting preview frame in pixel, with range [1, infinity) |
|
protected |
Converts the index of a frame into the corresponding timestamp.
index | The index for that the timestamp has to be found |
|
inline |
Returns whether the provider is enabled.
|
protected |
Internal event function for new frames.
frame | The new frame, will be valid |
camera | The camera profile associated with the frame, invalid if unknown |
|
protected |
Internal event function for new preview frames.
frame | The new preview frame, will be valid |
camera | The camera profile associated with the frame, invalid if unknown |
Dimension Ocean::Media::MovieFrameProvider::preferredPreviewDimension | ( | ) | const |
Returns the preferred frame dimension of the preview frames.
FrameRef Ocean::Media::MovieFrameProvider::previewFrame | ( | const unsigned int | index | ) |
Returns a preview frame.
The provided index should lie inside the number of expected media frame.
index | The index of the preview frame, with range [0, infinity) |
FrameRefs Ocean::Media::MovieFrameProvider::previewFrames | ( | const unsigned int | index, |
const unsigned int | size, | ||
const unsigned int | zoom = 1u |
||
) |
Returns several preview frames.
The provided index should lie inside the number of expected media frame.
A zooming factor may be used to return e.g. each 2nd, 3rd or each 10th preview frame (beginning at the specified index).
index | The index of the first preview frame to be returned |
size | Number of preview frames to be returned |
zoom | The zoom factor, with range [1, infinity) |
unsigned int Ocean::Media::MovieFrameProvider::previewProgress | ( | ) | const |
Returns the preview progress of this frame provider.
|
protected |
Releases the frame provider.
|
inline |
Removes an event callback event function.
callback | The callback function to be removed |
|
inline |
Removes a frame callback event function.
callback | The callback function to be removed |
|
inline |
Removes a preview frame callback event function.
callback | The callback function to be removed |
bool Ocean::Media::MovieFrameProvider::setEnabled | ( | const bool | state | ) |
Enables or disables the provider.
state | True, to enable the provider |
bool Ocean::Media::MovieFrameProvider::setFrameCapacity | ( | const size_t | capacity | ) |
Sets or changes the capacity of the frames to be stored concurrently.
The capacity does not reflect the preview frames.
capacity | The capacity to be set, with range [1, infinity) |
bool Ocean::Media::MovieFrameProvider::setMovie | ( | const MovieRef & | movie | ) |
Sets the movie providing the frames.
The movie must be exclusive so that the frame provider can use the movie's resources alone.
movie | The movie to set |
bool Ocean::Media::MovieFrameProvider::setPreferredFrameType | ( | const FrameType::PixelFormat | pixelFormat, |
const FrameType::PixelOrigin | pixelOrigin | ||
) |
Sets the preferred frame type of the frames of this provider.
However, there is no guarantee that this interface will be able to provided the requested frame type.
pixelFormat | The preferred pixel format |
pixelOrigin | The preferred pixel origin |
bool Ocean::Media::MovieFrameProvider::setPreferredPreviewDimension | ( | const unsigned int | width, |
const unsigned int | height | ||
) |
Sets the dimension of the preview frames.
Only one parameter has to be provided, either the width or the size.
The other parameter has to be zero.
width | The width of each preview frame in pixel, with range [0u, infinity) |
height | the height of each preview frame in pixel, with range [0u, infinity) |
FrameRef Ocean::Media::MovieFrameProvider::synchronFrameRequest | ( | const unsigned int | index, |
const double | timeout = 10.0 , |
||
bool * | abort = nullptr |
||
) |
Requests a frame synchronously.
The function blocks until the requested frame can be provided.
If the frame cannot be provided, the function returns directly after the timeout has been reached or the abort statement has been set.
index | The index of the frame that is requested |
timeout | Time period in that the function will wait if the requested frame cannot be provided directly, with range [0, infinity) |
abort | Optional abort statement allowing to abort the frame request at any time; set the value True to abort the request |
|
overrideprotectedvirtual |
Thread run function.
Implements Ocean::Thread.
|
protected |
Determines the frame index for a given timestamp.
If the frame preview creation has not been completed yet, the index is incremented with each new function call.
timestamp | Timestamp for that the index has to be determined |
lookup | True, ensure that the index is returned only if a corresponding preview frame exists already |
std::string Ocean::Media::MovieFrameProvider::url | ( | ) | const |
Returns the url of the media.
|
protected |
Actual number of frames that the provider organizes.
|
protected |
Number of frames that the provider currently organizes.
|
protected |
Provider enabled state.
|
protected |
Estimated number of frames that the provider will organize.
|
protected |
Event callback functions.
|
protected |
Frame event callback functions.
|
protected |
Intermediate queue for frames.
|
protected |
Index of the currently requested frame.
|
protected |
Time period that may exceed until a frame is expected to be unavailable, in seconds, with range (0, infinity)
|
protected |
Database holding the media frames.
|
protected |
Timestamp as the last frame has been arrived.
|
mutableprotected |
Provider lock.
|
protected |
Maximal size of the internal intermediate frame queues.
|
protected |
Duration of the media in seconds.
|
protected |
Frequency of the media in Hz.
|
protected |
Average time for one frame in the media.
|
protected |
Movie providing the preview frames.
|
protected |
Timestamp that stops the standard frame medium.
|
protected |
The preferred pixel format of the provider's frames.
|
protected |
The preferred pixel origin of the provider's frames.
|
protected |
Preferred height of the preview frames in pixel.
|
protected |
Preferred width of the preview frames in pixel.
|
protected |
Preview frame event callback functions.
|
protected |
Intermediate queue for preview frames.
|
protected |
Vector holding the preview frames.
|
protected |
State that is set directly if the provider has been invoked to be disposed.
|
protected |
List of frames that are explicitly requested.
|
protected |
The subscription objects for frame callback events.
|
protected |
The subscription objects for previewing frame callback events.