1 /******************************************************************************* 2 / 3 / File: BBufferProducer.h 4 / 5 / Description: A BBufferProducer is any source of media buffers in the Media Kit 6 / 7 / Copyright 1997-98, Be Incorporated, All Rights Reserved 8 / 9 *******************************************************************************/ 10 11 #if !defined(_BUFFER_PRODUCER_H) 12 #define _BUFFER_PRODUCER_H 13 14 #include <MediaDefs.h> 15 #include <MediaNode.h> 16 17 class BBuffer; 18 class BBufferGroup; 19 class BRegion; 20 21 namespace BPrivate { namespace media { 22 class BMediaRosterEx; 23 }} 24 25 26 class BBufferProducer : 27 public virtual BMediaNode 28 { 29 protected: 30 /* this has to be at the top to force a vtable */ 31 virtual ~BBufferProducer(); 32 33 public: 34 35 /* Supported formats for low-level clipping data */ 36 enum { 37 B_CLIP_SHORT_RUNS = 1 38 }; 39 40 /* Handy conversion functions for dealing with clip information */ 41 static status_t ClipDataToRegion( 42 int32 format, 43 int32 size, 44 const void * data, 45 BRegion * region); 46 47 media_type ProducerType(); 48 49 protected: 50 explicit BBufferProducer( 51 media_type producer_type /* = B_MEDIA_UNKNOWN_TYPE */); 52 53 enum suggestion_quality { 54 B_ANY_QUALITY = 0, 55 B_LOW_QUALITY = 10, 56 B_MEDIUM_QUALITY = 50, 57 B_HIGH_QUALITY = 100 58 }; 59 60 /* functionality of BBufferProducer */ 61 virtual status_t FormatSuggestionRequested( 62 media_type type, 63 int32 quality, 64 media_format * format) = 0; 65 virtual status_t FormatProposal( 66 const media_source & output, 67 media_format * ioFormat) = 0; 68 /* If the format isn't good, put a good format into *io_format and return error */ 69 /* If format has wildcard, specialize to what you can do (and change). */ 70 /* If you can change the format, return OK. */ 71 /* The request comes from your destination sychronously, so you cannot ask it */ 72 /* whether it likes it -- you should assume it will since it asked. */ 73 virtual status_t FormatChangeRequested( 74 const media_source & source, 75 const media_destination & destination, 76 media_format * io_format, 77 int32 * _deprecated_) = 0; 78 virtual status_t GetNextOutput( /* cookie starts as 0 */ 79 int32 * cookie, 80 media_output * out_output) = 0; 81 virtual status_t DisposeOutputCookie( 82 int32 cookie) = 0; 83 /* In this function, you should either pass on the group to your upstream guy, */ 84 /* or delete your current group and hang on to this group. Deleting the previous */ 85 /* group (unless you passed it on with the reclaim flag set to false) is very */ 86 /* important, else you will 1) leak memory and 2) block someone who may want */ 87 /* to reclaim the buffers living in that group. */ 88 virtual status_t SetBufferGroup( 89 const media_source & for_source, 90 BBufferGroup * group) = 0; 91 /* Format of clipping is (as int16-s): <from line> <npairs> <startclip> <endclip>. */ 92 /* Repeat for each line where the clipping is different from the previous line. */ 93 /* If <npairs> is negative, use the data from line -<npairs> (there are 0 pairs after */ 94 /* a negative <npairs>. Yes, we only support 32k*32k frame buffers for clipping. */ 95 /* Any non-0 field of 'display' means that that field changed, and if you don't support */ 96 /* that change, you should return an error and ignore the request. Note that the buffer */ 97 /* offset values do not have wildcards; 0 (or -1, or whatever) are real values and must */ 98 /* be adhered to. */ 99 virtual status_t VideoClippingChanged( 100 const media_source & for_source, 101 int16 num_shorts, 102 int16 * clip_data, 103 const media_video_display_info & display, 104 int32 * _deprecated_); 105 /* Iterates over all outputs and maxes the latency found */ 106 virtual status_t GetLatency( 107 bigtime_t * out_lantency); 108 virtual status_t PrepareToConnect( 109 const media_source & what, 110 const media_destination & where, 111 media_format * format, 112 media_source * out_source, 113 char * out_name) = 0; 114 virtual void Connect( 115 status_t error, 116 const media_source & source, 117 const media_destination & destination, 118 const media_format & format, 119 char * io_name) = 0; 120 virtual void Disconnect( 121 const media_source & what, 122 const media_destination & where) = 0; 123 virtual void LateNoticeReceived( 124 const media_source & what, 125 bigtime_t how_much, 126 bigtime_t performance_time) = 0; 127 virtual void EnableOutput( 128 const media_source & what, 129 bool enabled, 130 int32 * _deprecated_) = 0; 131 virtual status_t SetPlayRate( 132 int32 numer, 133 int32 denom); 134 135 virtual status_t HandleMessage( /* call this from the thread that listens to the port */ 136 int32 message, 137 const void * data, 138 size_t size); 139 140 virtual void AdditionalBufferRequested( // used to be Reserved 0 141 const media_source & source, 142 media_buffer_id prev_buffer, 143 bigtime_t prev_time, 144 const media_seek_tag * prev_tag); // may be NULL 145 146 virtual void LatencyChanged( // used to be Reserved 1 147 const media_source & source, 148 const media_destination & destination, 149 bigtime_t new_latency, 150 uint32 flags); 151 152 /* Use this function in BBufferProducer to pass on the buffer. */ 153 status_t SendBuffer( 154 BBuffer * buffer, 155 const media_destination & destination); 156 157 status_t SendDataStatus( 158 int32 status, 159 const media_destination & destination, 160 bigtime_t at_time); 161 162 /* Check in advance if a target is prepared to accept a format. You may */ 163 /* want to call this from Connect(), although that's not required. */ 164 status_t ProposeFormatChange( 165 media_format * format, 166 const media_destination & for_destination); 167 /* Tell consumer to accept a proposed format change */ 168 /* YOU MUST NOT CALL BROADCAST_BUFFER WHILE THIS CALL IS OUTSTANDING! */ 169 status_t ChangeFormat( 170 const media_source & for_source, 171 const media_destination & for_destination, 172 media_format * format); 173 /* Check how much latency the down-stream graph introduces */ 174 status_t FindLatencyFor( 175 const media_destination & for_destination, 176 bigtime_t * out_latency, 177 media_node_id * out_timesource); 178 179 /* Find the tag of a previously seen buffer to expedite seeking */ 180 status_t FindSeekTag( 181 const media_destination & for_destination, 182 bigtime_t in_target_time, 183 media_seek_tag * out_tag, 184 bigtime_t * out_tagged_time, 185 uint32 * out_flags = 0, 186 uint32 in_flags = 0); 187 188 /* Set the initial latency, which is the maximum additional latency */ 189 /* that will be imposed while starting/syncing to a signal (such as */ 190 /* starting a TV capture card in the middle of a field). Most nodes */ 191 /* have this at 0 (the default); only TV input Nodes need it currently */ 192 /* because they slave to a low-resolution (59.94 Hz) clock that arrives */ 193 /* from the outside world. Call this from the constructor if you need it. */ 194 void SetInitialLatency( 195 bigtime_t inInitialLatency, 196 uint32 flags = 0); 197 198 private: 199 200 friend class BBufferConsumer; 201 friend class BMediaNode; 202 friend class BMediaRoster; 203 friend class BPrivate::media::BMediaRosterEx; 204 205 BBufferProducer(); /* private unimplemented */ 206 BBufferProducer( 207 const BBufferProducer & clone); 208 BBufferProducer & operator=( 209 const BBufferProducer & clone); 210 211 /* Mmmh, stuffing! */ 212 status_t _Reserved_BufferProducer_0(void *); /* AdditionalBufferRequested() */ 213 status_t _Reserved_BufferProducer_1(void *); /* LatencyChanged() */ 214 virtual status_t _Reserved_BufferProducer_2(void *); 215 virtual status_t _Reserved_BufferProducer_3(void *); 216 virtual status_t _Reserved_BufferProducer_4(void *); 217 virtual status_t _Reserved_BufferProducer_5(void *); 218 virtual status_t _Reserved_BufferProducer_6(void *); 219 virtual status_t _Reserved_BufferProducer_7(void *); 220 virtual status_t _Reserved_BufferProducer_8(void *); 221 virtual status_t _Reserved_BufferProducer_9(void *); 222 virtual status_t _Reserved_BufferProducer_10(void *); 223 virtual status_t _Reserved_BufferProducer_11(void *); 224 virtual status_t _Reserved_BufferProducer_12(void *); 225 virtual status_t _Reserved_BufferProducer_13(void *); 226 virtual status_t _Reserved_BufferProducer_14(void *); 227 virtual status_t _Reserved_BufferProducer_15(void *); 228 229 230 media_type fProducerType; 231 bigtime_t fInitialLatency; 232 uint32 fInitialFlags; 233 bigtime_t fDelay; 234 235 static status_t clip_shorts_to_region( 236 const int16 * data, 237 int count, 238 BRegion * output); 239 static status_t clip_region_to_shorts( 240 const BRegion * input, 241 int16 * data, 242 int max_count, 243 int * out_count); 244 245 uint32 _reserved_buffer_producer_[12]; 246 }; 247 248 #endif /* _BUFFER_PRODUCER_H */ 249 250