1 // LoggingConsumer.h 2 3 #ifndef LoggingConsumer_H 4 #define LoggingConsumer_H 1 5 6 #include <media/BufferConsumer.h> 7 #include <media/Controllable.h> 8 #include <media/MediaEventLooper.h> 9 #include "LogWriter.h" 10 11 // forward declarations 12 struct entry_ref; 13 class BTimeSource; 14 class BMediaAddOn; 15 class BParameterWeb; 16 class LogWriter; 17 struct input_record; 18 19 // -------------------- 20 // LoggingConsumer node class 21 22 class LoggingConsumer : 23 public BBufferConsumer, 24 public BControllable, 25 public BMediaEventLooper 26 { 27 public: 28 // add-on-friendly ctor 29 // e.moon [11jun99] 30 LoggingConsumer( 31 const entry_ref& logFile, // points to an *existing* file 32 BMediaAddOn* pAddOn=0); 33 ~LoggingConsumer(); 34 35 // Our own logging-control methods 36 void SetEnabled(log_what what, bool enable); 37 void EnableAllMessages(); 38 void DisableAllMessages(); 39 40 // A little bit of instrumentation 41 long LateBuffers() const { return mLateBuffers; } 42 void ResetLateBufferCount() { mLateBuffers = 0; } 43 44 // Methods from BMediaNode 45 BMediaAddOn* AddOn(int32*) const; 46 void SetRunMode(run_mode); 47 void Preroll(); 48 void SetTimeSource(BTimeSource* time_source); 49 status_t RequestCompleted(const media_request_info & info); 50 51 // e.moon [11jun99; testing add-on] +++++no longer needed 52 status_t DeleteHook(BMediaNode* pNode); 53 54 // Methods from BControllable 55 status_t GetParameterValue( 56 int32 id, 57 bigtime_t* last_change, 58 void* value, 59 size_t* ioSize); 60 61 void SetParameterValue( 62 int32 id, 63 bigtime_t when, 64 const void* value, 65 size_t size); 66 67 // Methods from BBufferConsumer 68 status_t HandleMessage( 69 int32 message, 70 const void* data, 71 size_t size ); 72 73 // all of these are pure virtual in BBufferConsumer 74 status_t AcceptFormat( 75 const media_destination& dest, 76 media_format* format); 77 78 status_t GetNextInput( 79 int32* cookie, 80 media_input* out_input); 81 82 void DisposeInputCookie( int32 cookie ); 83 84 void BufferReceived( BBuffer* buffer ); 85 86 void ProducerDataStatus( 87 const media_destination& for_whom, 88 int32 status, 89 bigtime_t at_performance_time); 90 91 status_t GetLatencyFor( 92 const media_destination& for_whom, 93 bigtime_t* out_latency, 94 media_node_id* out_timesource); 95 96 status_t Connected( 97 const media_source& producer, /* here's a good place to request buffer group usage */ 98 const media_destination& where, 99 const media_format& with_format, 100 media_input* out_input); 101 102 void Disconnected( 103 const media_source& producer, 104 const media_destination& where); 105 106 /* The notification comes from the upstream producer, so he's already cool with */ 107 /* the format; you should not ask him about it in here. */ 108 status_t FormatChanged( 109 const media_source& producer, 110 const media_destination& consumer, 111 int32 change_tag, 112 const media_format& format); 113 114 /* Given a performance time of some previous buffer, retrieve the remembered tag */ 115 /* of the closest (previous or exact) performance time. Set *out_flags to 0; the */ 116 /* idea being that flags can be added later, and the understood flags returned in */ 117 /* *out_flags. */ 118 status_t SeekTagRequested( 119 const media_destination& destination, 120 bigtime_t in_target_time, 121 uint32 in_flags, 122 media_seek_tag* out_seek_tag, 123 bigtime_t* out_tagged_time, 124 uint32* out_flags); 125 126 // Methods from BMediaEventLooper 127 128 void NodeRegistered(); 129 void Start( bigtime_t performance_time ); 130 void Stop( bigtime_t performance_time, bool immediate ); 131 void Seek( bigtime_t media_time, bigtime_t performance_time ); 132 void TimeWarp( bigtime_t at_real_time, bigtime_t to_performance_time ); 133 134 // The primary event processing method 135 void HandleEvent(const media_timed_event *event, bigtime_t lateness, bool realTimeEvent = false); 136 137 // Private stuff -- various data we need for the logging implementation and parameter handling 138 private: 139 entry_ref mLogRef; // file that we're logging to 140 media_input mInput; // descriptor of our single input 141 BParameterWeb* mWeb; // description of our controllable parameters 142 LogWriter* mLogger; // the actual logging object that we use 143 bigtime_t mSchedulingLatency; // our scheduling latency (estimated at run time) 144 long mLateBuffers; // track how many late buffers we've gotten 145 146 // controllable parameters and their change history 147 bigtime_t mLatency; // our internal latency 148 float mSpinPercentage; // how much of our latency time to spin the CPU 149 int32 mPriority; // our control thread's priority 150 bigtime_t mLastLatencyChange; // when did we last change our latency? 151 bigtime_t mLastSpinChange; // when did we last change our CPU usage? 152 bigtime_t mLastPrioChange; // when did we last change thread priority? 153 154 // host addon 155 // [11jun99] e.moon 156 BMediaAddOn* m_pAddOn; 157 }; 158 159 #endif 160