1 /* 2 * Copyright 2015, Dario Casalinuovo. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #ifndef _MEDIA_CLIENT_NODE_H 7 #define _MEDIA_CLIENT_NODE_H 8 9 10 #include <BufferConsumer.h> 11 #include <BufferProducer.h> 12 #include <Controllable.h> 13 #include <MediaDefs.h> 14 #include <MediaEventLooper.h> 15 16 17 namespace BPrivate { namespace media { 18 19 20 class BMediaClient; 21 class BMediaConnection; 22 class BMediaOutput; 23 24 class BMediaClientNode : public BBufferConsumer, public BBufferProducer, 25 public BMediaEventLooper { 26 public: 27 BMediaClientNode(const char* name, 28 BMediaClient* owner, 29 media_type type 30 = B_MEDIA_UNKNOWN_TYPE); 31 32 // Various useful stuff 33 34 status_t SendBuffer(BBuffer* buffer, BMediaConnection* conn); 35 36 protected: 37 38 virtual BMediaAddOn* AddOn(int32* id) const; 39 40 virtual void NodeRegistered(); 41 42 virtual void SetRunMode(run_mode mode); 43 44 virtual void Start(bigtime_t performanceTime); 45 46 virtual void Stop(bigtime_t performanceTime, 47 bool immediate); 48 49 virtual void Seek(bigtime_t mediaTime, 50 bigtime_t performanceTime); 51 52 virtual void TimeWarp(bigtime_t realTime, 53 bigtime_t performanceTime); 54 55 virtual status_t HandleMessage(int32 message, 56 const void* data, 57 size_t size); 58 59 // BBufferConsumer 60 61 virtual status_t AcceptFormat(const media_destination& dest, 62 media_format* format); 63 64 virtual status_t GetNextInput(int32* cookie, 65 media_input* input); 66 67 virtual void DisposeInputCookie(int32 cookie); 68 69 virtual void BufferReceived(BBuffer* buffer); 70 71 virtual status_t GetLatencyFor(const media_destination& dest, 72 bigtime_t* latency, 73 media_node_id* timesource); 74 75 virtual status_t Connected(const media_source& source, 76 const media_destination& dest, 77 const media_format& format, 78 media_input* outInput); 79 80 virtual void Disconnected(const media_source& source, 81 const media_destination& dest); 82 83 virtual status_t FormatChanged(const media_source& source, 84 const media_destination& consumer, 85 int32 tag, 86 const media_format& format); 87 88 // BBufferProducer 89 90 virtual status_t FormatSuggestionRequested(media_type type, 91 int32 quality, media_format* format); 92 virtual status_t FormatProposal(const media_source& source, 93 media_format *format); 94 virtual status_t FormatChangeRequested(const media_source& source, 95 const media_destination& dest, 96 media_format *format, 97 int32* _deprecated_); 98 virtual void LateNoticeReceived(const media_source& source, 99 bigtime_t late, bigtime_t when); 100 virtual status_t GetNextOutput(int32 *cookie, media_output *output); 101 virtual status_t DisposeOutputCookie(int32 cookie); 102 virtual status_t SetBufferGroup(const media_source& source, 103 BBufferGroup *group); 104 virtual status_t PrepareToConnect(const media_source& source, 105 const media_destination& dest, 106 media_format *format, 107 media_source *out_source, 108 char *name); 109 virtual void Connect(status_t status, 110 const media_source& source, 111 const media_destination& dest, 112 const media_format &format, 113 char* name); 114 virtual void Disconnect(const media_source& source, 115 const media_destination& dest); 116 virtual void EnableOutput(const media_source& source, 117 bool enabled, int32* _deprecated_); 118 virtual status_t GetLatency(bigtime_t *outLatency); 119 virtual void LatencyChanged( const media_source& source, 120 const media_destination& dest, 121 bigtime_t latency, uint32 flags); 122 123 void ProducerDataStatus(const media_destination& dest, 124 int32 status, bigtime_t when); 125 protected: 126 virtual void HandleEvent(const media_timed_event *event, 127 bigtime_t late, 128 bool realTimeEvent=false); 129 130 virtual ~BMediaClientNode(); 131 132 private: 133 void _ScheduleConnections(bigtime_t eventTime); 134 void _HandleBuffer(BBuffer* buffer); 135 void _ProduceNewBuffer(const media_timed_event* event, 136 bigtime_t late); 137 BBuffer* _GetNextBuffer(BMediaOutput* output, 138 bigtime_t eventTime); 139 140 BMediaClient* fOwner; 141 bigtime_t fStartTime; 142 }; 143 144 } 145 } 146 147 using namespace BPrivate::media; 148 149 #endif 150