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