1 /* Copyright (c) 1998-99, Be Incorporated, All Rights Reserved. 2 * Distributed under the terms of the Be Sample Code license. 3 * 4 * Copyright (c) 2000-2008, Ingo Weinhold <ingo_weinhold@gmx.de>, 5 * Copyright (c) 2000-2008, Stephan Aßmus <superstippi@gmx.de>, 6 * All Rights Reserved. Distributed under the terms of the MIT license. 7 */ 8 #ifndef VIDEO_CONSUMER_H 9 #define VIDEO_CONSUMER_H 10 11 12 #include <BufferConsumer.h> 13 #include <Locker.h> 14 #include <MediaEventLooper.h> 15 16 17 class BBitmap; 18 class NodeManager; 19 class VideoTarget; 20 21 22 // TODO: The buffer count should depend on the latency! 23 static const unsigned int kBufferCount = 4; 24 25 26 class VideoConsumer : public BMediaEventLooper, public BBufferConsumer { 27 public: 28 VideoConsumer( 29 const char* name, 30 BMediaAddOn* addon, 31 const uint32 internal_id, 32 NodeManager* manager, 33 VideoTarget* target); 34 ~VideoConsumer(); 35 36 // BMediaNode interface 37 public: 38 39 virtual BMediaAddOn* AddOn(long* cookie) const; 40 41 protected: 42 virtual void NodeRegistered(); 43 virtual status_t RequestCompleted( 44 const media_request_info& info); 45 46 virtual status_t HandleMessage(int32 message, const void* data, 47 size_t size); 48 49 // BMediaEventLooper interface 50 protected: 51 virtual void HandleEvent(const media_timed_event* event, 52 bigtime_t lateness, bool realTimeEvent); 53 54 // BBufferConsumer interface 55 public: 56 virtual status_t AcceptFormat(const media_destination& dest, 57 media_format* format); 58 virtual status_t GetNextInput(int32* cookie, 59 media_input* _input); 60 61 virtual void DisposeInputCookie(int32 cookie); 62 63 protected: 64 virtual void BufferReceived(BBuffer* buffer); 65 66 private: 67 virtual void ProducerDataStatus( 68 const media_destination& forWhom, 69 int32 status, 70 bigtime_t atMediaTime); 71 virtual status_t GetLatencyFor( 72 const media_destination& forWhom, 73 bigtime_t* outLatency, 74 media_node_id* outId); 75 virtual status_t Connected(const media_source& producer, 76 const media_destination& where, 77 const media_format& withFormat, 78 media_input* outInput); 79 virtual void Disconnected(const media_source& producer, 80 const media_destination& where); 81 virtual status_t FormatChanged(const media_source& producer, 82 const media_destination& consumer, 83 int32 from_change_count, 84 const media_format& format); 85 86 // VideoConsumer 87 public: 88 status_t CreateBuffers( 89 const media_format& withFormat); 90 91 void DeleteBuffers(); 92 93 void SetTarget(VideoTarget* target); 94 void SetTryOverlay(bool tryOverlay); 95 96 private: 97 void _SetPerformanceTimeBase( 98 bigtime_t performanceTime); 99 void _HandleBuffer(BBuffer* buffer); 100 void _UnsetTargetBuffer(); 101 102 private: 103 uint32 fInternalID; 104 BMediaAddOn* fAddOn; 105 106 bool fConnectionActive; 107 media_input fIn; 108 bigtime_t fMyLatency; 109 bigtime_t fPerformanceTimeBase; 110 111 BBitmap* fBitmap[kBufferCount]; 112 bool fOurBuffers; 113 BBufferGroup* fBuffers; 114 BBuffer* fBufferMap[kBufferCount]; 115 116 NodeManager* fManager; 117 BLocker fTargetLock; // locks the following variable 118 VideoTarget* volatile fTarget; 119 int32 fLastBufferIndex; 120 121 bool fTryOverlay; 122 }; 123 124 #endif // VIDEO_CONSUMER_H 125