Rewrote header.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32780 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2009-08-28 12:58:59 +00:00
parent d4d27fac86
commit 05d5d7ad58

View File

@ -1,169 +1,161 @@
/******************************************************************************* /*
/ * Copyright 2009, Haiku, Inc. All rights reserved.
/ File: MediaEventLooper.h * Distributed under the terms of the MIT License.
/ */
/ Description: BMediaEventLooper spawns a thread which calls WaitForMessage, #ifndef _MEDIA_EVENT_LOOPER_H
/ pushes BMediaNode messages onto its BTimedEventQueues.
/ informs you when it is time to handle an event.
/ Report your event latency, push other events onto the queue
/ and override HandleEvent to do your work.
/
/ Copyright 1999, Be Incorporated, All Rights Reserved
/
*******************************************************************************/
#if !defined(_MEDIA_EVENT_LOOPER_H)
#define _MEDIA_EVENT_LOOPER_H #define _MEDIA_EVENT_LOOPER_H
#include <MediaNode.h> #include <MediaNode.h>
#include <TimedEventQueue.h> #include <TimedEventQueue.h>
class BMediaEventLooper :
public virtual BMediaNode
{
protected:
enum run_state {
B_IN_DISTRESS = -1,
B_UNREGISTERED,
B_STOPPED,
B_STARTED,
B_QUITTING,
B_TERMINATED,
B_USER_RUN_STATES = 0x4000
};
protected: /*! BMediaEventLooper spawns a thread which calls WaitForMessage, pushes
/* this has to be on top rather than bottom to force a vtable in mwcc */ BMediaNode messages onto its BTimedEventQueues. informs you when it
virtual ~BMediaEventLooper(); is time to handle an event. Report your event latency, push other events
explicit BMediaEventLooper(uint32 apiVersion = B_BEOS_VERSION); onto the queue and override HandleEvent to do your work.
*/
class BMediaEventLooper : public virtual BMediaNode {
protected:
enum run_state {
B_IN_DISTRESS = -1,
B_UNREGISTERED,
B_STOPPED,
B_STARTED,
B_QUITTING,
B_TERMINATED,
B_USER_RUN_STATES = 0x4000
};
/* from BMediaNode */ protected:
protected: explicit BMediaEventLooper(
virtual void NodeRegistered(); uint32 apiVersion = B_BEOS_VERSION);
virtual void Start(bigtime_t performance_time); virtual ~BMediaEventLooper();
virtual void Stop(bigtime_t performance_time, bool immediate);
virtual void Seek(bigtime_t media_time, bigtime_t performance_time);
virtual void TimeWarp(bigtime_t at_real_time, bigtime_t to_performance_time);
virtual status_t AddTimer(bigtime_t at_performance_time, int32 cookie);
virtual void SetRunMode(run_mode mode);
/* BMediaEventLooper Hook functions */ protected:
protected: // BMediaNode interface
/* you must override to handle your events! */ virtual void NodeRegistered();
/* you should not call HandleEvent directly */ virtual void Start(bigtime_t performanceTime);
virtual void HandleEvent( const media_timed_event *event, virtual void Stop(bigtime_t performanceTime,
bigtime_t lateness, bool immediate);
bool realTimeEvent = false) = 0; virtual void Seek(bigtime_t mediaTime,
bigtime_t performanceTime);
virtual void TimeWarp(bigtime_t atRealTime,
bigtime_t toPerformanceTime);
virtual status_t AddTimer(bigtime_t atPerformanceTime,
int32 cookie);
virtual void SetRunMode(run_mode mode);
/* override to clean up custom events you have added to your queue */ protected:
virtual void CleanUpEvent(const media_timed_event *event); // BMediaEventLooper Hook functions
/* called from Offline mode to determine the current time of the node */ // NOTE: You must override this method to handle your events!
/* update your internal information whenever it changes */ // You should not call HandleEvent directly.
virtual bigtime_t OfflineTime(); virtual void HandleEvent(const media_timed_event* event,
bigtime_t lateness,
bool realTimeEvent = false) = 0;
/* override only if you know what you are doing! */ // Override this method to properly clean up any custom events you have
/* otherwise much badness could occur */ // added to your event queue.
/* the actual control loop function: */ virtual void CleanUpEvent(const media_timed_event* event);
/* waits for messages, Pops events off the queue and calls DispatchEvent */
virtual void ControlLoop();
thread_id ControlThread(); // NOTE: Called in offline mode to determine the current time of the node.
// Update your internal information whenever it changes.
virtual bigtime_t OfflineTime();
protected: // NOTE: Override this method only if you know what you are doing!
BTimedEventQueue * EventQueue(); // The default control loop function waits for messages, pops events
BTimedEventQueue * RealTimeQueue(); // off the queue and calls DispatchEvent.
virtual void ControlLoop();
int32 Priority() const; thread_id ControlThread();
int32 RunState() const;
bigtime_t EventLatency() const;
bigtime_t BufferDuration() const;
bigtime_t SchedulingLatency() const;
/* use the priority constants from OS.h */ protected:
/* or suggest_thread_priority from scheduler.h */ BTimedEventQueue* EventQueue();
/* will clamp priorities to be inbetween 5 and 120 */ BTimedEventQueue* RealTimeQueue();
status_t SetPriority(int32 priority);
/* set the run state */ int32 Priority() const;
void SetRunState(run_state state); int32 RunState() const;
bigtime_t EventLatency() const;
bigtime_t BufferDuration() const;
bigtime_t SchedulingLatency() const;
/* clamps to 0 if latency < 0 */ // NOTE: Use the priority constants from OS.h or suggest_thread_priority
void SetEventLatency(bigtime_t latency); // from scheduler.h. The passed priority will be clamped to be in range 5
// to 120.
status_t SetPriority(int32 priority);
void SetRunState(run_state state);
void SetEventLatency(bigtime_t latency);
void SetBufferDuration(bigtime_t duration);
void SetOfflineTime(bigtime_t offTime);
/* clamps to 0 if duration is < 0 */ // Spawns and resumes the control thread - must be called from
void SetBufferDuration(bigtime_t duration); // NodeRegistered().
void Run();
/* set the offline time returned in OfflineTime */ // Quits the control thread - must be called from your destructor.
void SetOfflineTime(bigtime_t offTime); void Quit();
/* spawn and resume the thread - must be called from NodeRegistered */ // Calls HandleEvent and does BMediaEventLooper event work
void Run(); void DispatchEvent(const media_timed_event* event,
bigtime_t lateness,
bool realTimeEvent = false);
/* close down the thread - must be called from your destructor */ private:
void Quit(); static int32 _ControlThreadStart(void* cookie);
static void _CleanUpEntry(const media_timed_event* event,
void* context);
void _DispatchCleanUp(
const media_timed_event* event);
/* calls HandleEvent and does BMediaEventLooper event work */ private:
void DispatchEvent( const media_timed_event *event, BTimedEventQueue fEventQueue;
bigtime_t lateness, BTimedEventQueue fRealTimeQueue;
bool realTimeEvent = false); thread_id fControlThread;
int32 fCurrentPriority;
int32 fSetPriority;
vint32 fRunState;
bigtime_t fEventLatency;
bigtime_t fSchedulingLatency;
bigtime_t fBufferDuration;
bigtime_t fOfflineTime;
uint32 fApiVersion;
private: protected:
static int32 _ControlThreadStart(void *arg); virtual status_t DeleteHook(BMediaNode * node);
static void _CleanUpEntry(const media_timed_event *event, void *context);
void _DispatchCleanUp(const media_timed_event *event);
BTimedEventQueue fEventQueue; private:
BTimedEventQueue fRealTimeQueue; // FBC padding and forbidden methods
thread_id fControlThread; BMediaEventLooper(const BMediaEventLooper&);
int32 fCurrentPriority; BMediaEventLooper& operator=(const BMediaEventLooper&);
int32 fSetPriority;
volatile int32 fRunState;
bigtime_t fEventLatency;
bigtime_t fSchedulingLatency;
bigtime_t fBufferDuration;
bigtime_t fOfflineTime;
uint32 fApiVersion;
private: virtual status_t _Reserved_BMediaEventLooper_0(int32 arg, ...);
/* unimplemented for your protection */ virtual status_t _Reserved_BMediaEventLooper_1(int32 arg, ...);
BMediaEventLooper(const BMediaEventLooper&); virtual status_t _Reserved_BMediaEventLooper_2(int32 arg, ...);
BMediaEventLooper& operator=(const BMediaEventLooper&); virtual status_t _Reserved_BMediaEventLooper_3(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_4(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_5(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_6(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_7(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_8(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_9(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_10(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_11(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_12(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_13(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_14(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_15(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_16(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_17(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_18(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_19(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_20(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_21(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_22(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_23(int32 arg, ...);
protected: bool _reserved_bool_[4];
virtual status_t DeleteHook(BMediaNode * node); uint32 _reserved_BMediaEventLooper_[12];
/* fragile base class stuffing */
private:
/* it must be thanksgiving!! lots of stuffing! */
virtual status_t _Reserved_BMediaEventLooper_0(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_1(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_2(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_3(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_4(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_5(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_6(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_7(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_8(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_9(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_10(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_11(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_12(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_13(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_14(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_15(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_16(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_17(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_18(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_19(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_20(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_21(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_22(int32 arg, ...);
virtual status_t _Reserved_BMediaEventLooper_23(int32 arg, ...);
/* turkey for weeks! */
bool _reserved_bool_[4];
uint32 _reserved_BMediaEventLooper_[12];
}; };
#endif #endif // _MEDIA_EVENT_LOOPER_H