1 // MediaReader.h 2 // 3 // Andrew Bachmann, 2002 4 // 5 // A MediaReader is a node that 6 // implements FileInterface and BBufferProducer. 7 // It reads any file and produces one output, 8 // which is a multistream. It has a rather 9 // unique interpretation of time. Time is 10 // distance in the file. So the duration is the 11 // file length. (in bytes) 12 13 #if !defined(_MEDIA_READER_H) 14 #define _MEDIA_READER_H 15 16 #include <MediaDefs.h> 17 #include <MediaNode.h> 18 #include <FileInterface.h> 19 #include <BufferProducer.h> 20 #include <Controllable.h> 21 #include <MediaEventLooper.h> 22 #include <File.h> 23 #include <Entry.h> 24 #include <BufferGroup.h> 25 26 #include "../AbstractFileInterfaceNode.h" 27 28 class MediaReader : 29 public BBufferProducer, 30 public AbstractFileInterfaceNode 31 { 32 protected: 33 virtual ~MediaReader(void); 34 35 public: 36 37 explicit MediaReader( 38 size_t defaultChunkSize = 8192, // chunk size = 8 KB 39 float defaultBitRate = 800000, // bit rate = 100.000 KB/sec = 5.85 MB/minute 40 const flavor_info * info = 0, // buffer period = 80 milliseconds 41 BMessage * config = 0, 42 BMediaAddOn * addOn = 0); 43 44 /*************************/ 45 /* begin from BMediaNode */ 46 protected: 47 /* These don't return errors; instead, they use the global error condition reporter. */ 48 /* A node is required to have a queue of at least one pending command (plus TimeWarp) */ 49 /* and is recommended to allow for at least one pending command of each type. */ 50 /* Allowing an arbitrary number of outstanding commands might be nice, but apps */ 51 /* cannot depend on that happening. */ 52 virtual void Preroll(void); 53 54 public: 55 virtual status_t HandleMessage( 56 int32 message, 57 const void * data, 58 size_t size); 59 60 protected: 61 virtual void NodeRegistered(void); /* reserved 2 */ 62 63 /* end from BMediaNode */ 64 /***********************/ 65 66 /*****************************/ 67 /* begin from BFileInterface */ 68 protected: 69 virtual status_t SetRef( 70 const entry_ref & file, 71 bool create, 72 bigtime_t * out_time); 73 74 /* end from BFileInterface */ 75 /***************************/ 76 77 // provided for BMediaReaderAddOn 78 public: 79 static status_t StaticSniffRef( 80 const entry_ref & file, 81 char * out_mime_type, /* 256 bytes */ 82 float * out_quality); 83 84 /******************************/ 85 /* begin from BBufferProducer */ 86 protected: 87 /* functionality of BBufferProducer */ 88 virtual status_t FormatSuggestionRequested( 89 media_type type, 90 int32 quality, 91 media_format * format); 92 virtual status_t FormatProposal( 93 const media_source & output, 94 media_format * format); 95 /* If the format isn't good, put a good format into *io_format and return error */ 96 /* If format has wildcard, specialize to what you can do (and change). */ 97 /* If you can change the format, return OK. */ 98 /* The request comes from your destination sychronously, so you cannot ask it */ 99 /* whether it likes it -- you should assume it will since it asked. */ 100 virtual status_t FormatChangeRequested( 101 const media_source & source, 102 const media_destination & destination, 103 media_format * io_format, 104 int32 * _deprecated_); 105 virtual status_t GetNextOutput( /* cookie starts as 0 */ 106 int32 * cookie, 107 media_output * out_output); 108 virtual status_t DisposeOutputCookie( 109 int32 cookie); 110 /* In this function, you should either pass on the group to your upstream guy, */ 111 /* or delete your current group and hang on to this group. Deleting the previous */ 112 /* group (unless you passed it on with the reclaim flag set to false) is very */ 113 /* important, else you will 1) leak memory and 2) block someone who may want */ 114 /* to reclaim the buffers living in that group. */ 115 virtual status_t SetBufferGroup( 116 const media_source & for_source, 117 BBufferGroup * group); 118 /* Format of clipping is (as int16-s): <from line> <npairs> <startclip> <endclip>. */ 119 /* Repeat for each line where the clipping is different from the previous line. */ 120 /* If <npairs> is negative, use the data from line -<npairs> (there are 0 pairs after */ 121 /* a negative <npairs>. Yes, we only support 32k*32k frame buffers for clipping. */ 122 /* Any non-0 field of 'display' means that that field changed, and if you don't support */ 123 /* that change, you should return an error and ignore the request. Note that the buffer */ 124 /* offset values do not have wildcards; 0 (or -1, or whatever) are real values and must */ 125 /* be adhered to. */ 126 virtual status_t VideoClippingChanged( 127 const media_source & for_source, 128 int16 num_shorts, 129 int16 * clip_data, 130 const media_video_display_info & display, 131 int32 * _deprecated_); 132 /* Iterates over all outputs and maxes the latency found */ 133 virtual status_t GetLatency( 134 bigtime_t * out_latency); 135 virtual status_t PrepareToConnect( 136 const media_source & what, 137 const media_destination & where, 138 media_format * format, 139 media_source * out_source, 140 char * out_name); 141 virtual void Connect( 142 status_t error, 143 const media_source & source, 144 const media_destination & destination, 145 const media_format & format, 146 char * io_name); 147 virtual void Disconnect( 148 const media_source & what, 149 const media_destination & where); 150 virtual void LateNoticeReceived( 151 const media_source & what, 152 bigtime_t how_much, 153 bigtime_t performance_time); 154 virtual void EnableOutput( 155 const media_source & what, 156 bool enabled, 157 int32 * _deprecated_); 158 virtual status_t SetPlayRate( 159 int32 numer, 160 int32 denom); 161 162 //included from BMediaNode 163 //virtual status_t HandleMessage( /* call this from the thread that listens to the port */ 164 // int32 message, 165 // const void * data, 166 // size_t size); 167 168 virtual void AdditionalBufferRequested( // used to be Reserved 0 169 const media_source & source, 170 media_buffer_id prev_buffer, 171 bigtime_t prev_time, 172 const media_seek_tag * prev_tag); // may be NULL 173 174 virtual void LatencyChanged( // used to be Reserved 1 175 const media_source & source, 176 const media_destination & destination, 177 bigtime_t new_latency, 178 uint32 flags); 179 180 /* end from BBufferProducer */ 181 /****************************/ 182 183 /*****************/ 184 /* BControllable */ 185 /*****************/ 186 187 /*********************/ 188 /* BMediaEventLooper */ 189 /*********************/ 190 191 protected: 192 193 virtual status_t HandleBuffer( 194 const media_timed_event *event, 195 bigtime_t lateness, 196 bool realTimeEvent = false); 197 virtual status_t HandleDataStatus( 198 const media_timed_event *event, 199 bigtime_t lateness, 200 bool realTimeEvent = false); 201 202 public: 203 204 static void GetFlavor(flavor_info * outInfo, int32 id); 205 static void GetFormat(media_format * outFormat); 206 static void GetFileFormat(media_file_format * outFileFormat); 207 208 protected: 209 210 virtual status_t GetFilledBuffer(BBuffer ** outBuffer); 211 virtual status_t FillFileBuffer(BBuffer * buffer); 212 213 private: 214 215 MediaReader( /* private unimplemented */ 216 const MediaReader & clone); 217 MediaReader & operator=( 218 const MediaReader & clone); 219 220 media_output output; 221 222 bool fOutputEnabled; 223 224 BBufferGroup * fBufferGroup; 225 bigtime_t fDownstreamLatency; 226 bigtime_t fInternalLatency; 227 // this is computed from the real (negotiated) chunk size and bit rate, 228 // not the defaults that are in the parameters 229 bigtime_t fBufferPeriod; 230 231 /* Mmmh, stuffing! */ 232 virtual status_t _Reserved_MediaReader_0(void *); 233 virtual status_t _Reserved_MediaReader_1(void *); 234 virtual status_t _Reserved_MediaReader_2(void *); 235 virtual status_t _Reserved_MediaReader_3(void *); 236 virtual status_t _Reserved_MediaReader_4(void *); 237 virtual status_t _Reserved_MediaReader_5(void *); 238 virtual status_t _Reserved_MediaReader_6(void *); 239 virtual status_t _Reserved_MediaReader_7(void *); 240 virtual status_t _Reserved_MediaReader_8(void *); 241 virtual status_t _Reserved_MediaReader_9(void *); 242 virtual status_t _Reserved_MediaReader_10(void *); 243 virtual status_t _Reserved_MediaReader_11(void *); 244 virtual status_t _Reserved_MediaReader_12(void *); 245 virtual status_t _Reserved_MediaReader_13(void *); 246 virtual status_t _Reserved_MediaReader_14(void *); 247 virtual status_t _Reserved_MediaReader_15(void *); 248 249 uint32 _reserved_media_reader_[16]; 250 251 }; 252 253 #endif /* _MEDIA_READER_H */ 254