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_PRODUCER_H 9 #define _VIDEO_PRODUCER_H 10 11 12 #include <BufferProducer.h> 13 #include <Controllable.h> 14 #include <Locker.h> 15 #include <MediaDefs.h> 16 #include <MediaEventLooper.h> 17 #include <MediaNode.h> 18 #include <OS.h> 19 #include <Rect.h> 20 21 22 class NodeManager; 23 class VideoSupplier; 24 25 26 class VideoProducer : public virtual BMediaEventLooper, 27 public virtual BBufferProducer { 28 public: 29 VideoProducer(BMediaAddOn* addon, const char* name, 30 int32 internalId, NodeManager* manager, 31 VideoSupplier* supplier); 32 virtual ~VideoProducer(); 33 34 virtual status_t InitCheck() const 35 { return fInitStatus; } 36 37 // BMediaNode interface 38 public: 39 virtual port_id ControlPort() const; 40 virtual BMediaAddOn* AddOn(int32* _internalId) const; 41 virtual status_t HandleMessage(int32 message, const void* data, 42 size_t size); 43 protected: 44 virtual void SetTimeSource(BTimeSource* timeSource); 45 virtual status_t RequestCompleted(const media_request_info& info); 46 47 // BMediaEventLooper interface 48 protected: 49 virtual void NodeRegistered(); 50 virtual void Start(bigtime_t performanceTime); 51 virtual void Stop(bigtime_t performanceTime, bool immediate); 52 virtual void Seek(bigtime_t mediaTime, 53 bigtime_t performanceTime); 54 virtual void TimeWarp(bigtime_t atRealTime, 55 bigtime_t toPerformanceTime); 56 virtual status_t AddTimer(bigtime_t atPerformanceTime, 57 int32 cookie); 58 virtual void SetRunMode(run_mode mode); 59 virtual void HandleEvent(const media_timed_event* event, 60 bigtime_t lateness, 61 bool realTimeEvent = false); 62 virtual void CleanUpEvent(const media_timed_event* event); 63 virtual bigtime_t OfflineTime(); 64 virtual void ControlLoop(); 65 virtual status_t DeleteHook(BMediaNode* node); 66 67 // BBufferProducer interface 68 protected: 69 virtual status_t FormatSuggestionRequested(media_type type, 70 int32 quality, media_format* format); 71 virtual status_t FormatProposal(const media_source &output, 72 media_format* format); 73 virtual status_t FormatChangeRequested(const media_source& source, 74 const media_destination& destination, 75 media_format* ioFormat, int32* _deprecated_); 76 virtual status_t GetNextOutput(int32* cookie, 77 media_output* outOutput); 78 virtual status_t DisposeOutputCookie(int32 cookie); 79 virtual status_t SetBufferGroup(const media_source& forSource, 80 BBufferGroup* group); 81 virtual status_t VideoClippingChanged(const media_source& forSource, 82 int16 numShorts, int16* clipData, 83 const media_video_display_info& display, 84 int32* _deprecated_); 85 virtual status_t GetLatency(bigtime_t* out_latency); 86 virtual status_t PrepareToConnect(const media_source& what, 87 const media_destination& where, 88 media_format* format, media_source* outSource, 89 char* out_name); 90 virtual void Connect(status_t error, const media_source& source, 91 const media_destination& destination, 92 const media_format& format, char* ioName); 93 virtual void Disconnect(const media_source& what, 94 const media_destination& where); 95 virtual void LateNoticeReceived(const media_source& what, 96 bigtime_t howMuch, bigtime_t performanceTime); 97 virtual void EnableOutput(const media_source& what, bool enabled, 98 int32* _deprecated_); 99 virtual status_t SetPlayRate(int32 numer, int32 denom); 100 virtual void AdditionalBufferRequested( 101 const media_source& source, 102 media_buffer_id prevBuffer, 103 bigtime_t prevTime, 104 const media_seek_tag* prevTag); 105 virtual void LatencyChanged(const media_source& source, 106 const media_destination& destination, 107 bigtime_t newLatency, uint32 flags); 108 109 private: 110 void _HandleStart(bigtime_t performance_time); 111 void _HandleStop(); 112 void _HandleTimeWarp(bigtime_t performance_time); 113 void _HandleSeek(bigtime_t performance_time); 114 115 static int32 _FrameGeneratorThreadEntry(void* data); 116 int32 _FrameGeneratorThread(); 117 118 status_t fInitStatus; 119 120 int32 fInternalID; 121 BMediaAddOn* fAddOn; 122 123 BLocker fLock; 124 BBufferGroup* fBufferGroup; 125 BBufferGroup* fUsedBufferGroup; 126 127 thread_id fThread; 128 sem_id fFrameSync; 129 130 // The remaining variables should be declared volatile, but they 131 // are not here to improve the legibility of the sample code. 132 int64 fFrame; 133 int64 fFrameBase; 134 bigtime_t fPerformanceTimeBase; 135 media_output fOutput; 136 media_raw_video_format fConnectedFormat; 137 bool fRunning; 138 bool fConnected; 139 bool fEnabled; 140 141 NodeManager* fManager; 142 VideoSupplier* fSupplier; 143 }; 144 145 #endif // VIDEO_PRODUCER_H 146