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