1 // MediaWriter.h 2 // 3 // Andrew Bachmann, 2002 4 // 5 // A MediaWriter is a node that 6 // implements FileInterface and BBufferConsumer. 7 // It consumes on input, which is a multistream, 8 // and writes the stream to a file. 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_WRITER_H) 14 #define _MEDIA_WRITER_H 15 16 #include <MediaDefs.h> 17 #include <MediaNode.h> 18 #include <FileInterface.h> 19 #include <BufferConsumer.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 MediaWriter : 29 public BBufferConsumer, 30 public AbstractFileInterfaceNode 31 { 32 protected: 33 virtual ~MediaWriter(void); 34 35 public: 36 37 explicit MediaWriter( 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 BMediaWriterAddOn 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 BBufferConsumer */ 86 87 //included from BMediaAddOn 88 //virtual status_t HandleMessage( 89 // int32 message, 90 // const void * data, 91 // size_t size); 92 93 /* Someone, probably the producer, is asking you about this format. Give */ 94 /* your honest opinion, possibly modifying *format. Do not ask upstream */ 95 /* producer about the format, since he's synchronously waiting for your */ 96 /* reply. */ 97 virtual status_t AcceptFormat( 98 const media_destination & dest, 99 media_format * format); 100 virtual status_t GetNextInput( 101 int32 * cookie, 102 media_input * out_input); 103 virtual void DisposeInputCookie( 104 int32 cookie); 105 virtual void BufferReceived( 106 BBuffer * buffer); 107 virtual void ProducerDataStatus( 108 const media_destination & for_whom, 109 int32 status, 110 bigtime_t at_performance_time); 111 virtual status_t GetLatencyFor( 112 const media_destination & for_whom, 113 bigtime_t * out_latency, 114 media_node_id * out_timesource); 115 virtual status_t Connected( 116 const media_source & producer, /* here's a good place to request buffer group usage */ 117 const media_destination & where, 118 const media_format & with_format, 119 media_input * out_input); 120 virtual void Disconnected( 121 const media_source & producer, 122 const media_destination & where); 123 /* The notification comes from the upstream producer, so he's already cool with */ 124 /* the format; you should not ask him about it in here. */ 125 virtual status_t FormatChanged( 126 const media_source & producer, 127 const media_destination & consumer, 128 int32 change_tag, 129 const media_format & format); 130 131 /* Given a performance time of some previous buffer, retrieve the remembered tag */ 132 /* of the closest (previous or exact) performance time. Set *out_flags to 0; the */ 133 /* idea being that flags can be added later, and the understood flags returned in */ 134 /* *out_flags. */ 135 virtual status_t SeekTagRequested( 136 const media_destination & destination, 137 bigtime_t in_target_time, 138 uint32 in_flags, 139 media_seek_tag * out_seek_tag, 140 bigtime_t * out_tagged_time, 141 uint32 * out_flags); 142 143 /* end from BBufferConsumer */ 144 /****************************/ 145 146 /*****************/ 147 /* BControllable */ 148 /*****************/ 149 150 /*********************/ 151 /* BMediaEventLooper */ 152 /*********************/ 153 154 protected: 155 156 virtual status_t HandleBuffer( 157 const media_timed_event *event, 158 bigtime_t lateness, 159 bool realTimeEvent = false); 160 virtual status_t HandleDataStatus( 161 const media_timed_event *event, 162 bigtime_t lateness, 163 bool realTimeEvent = false); 164 165 public: 166 167 static void GetFlavor(flavor_info * outInfo, int32 id); 168 static void GetFormat(media_format * outFormat); 169 static void GetFileFormat(media_file_format * outFileFormat); 170 171 protected: 172 173 virtual status_t WriteFileBuffer(BBuffer * buffer); 174 175 private: 176 177 MediaWriter( /* private unimplemented */ 178 const MediaWriter & clone); 179 MediaWriter & operator=( 180 const MediaWriter & clone); 181 182 media_input input; 183 184 BBufferGroup * fBufferGroup; 185 bigtime_t fInternalLatency; 186 // this is computed from the real (negotiated) chunk size and bit rate, 187 // not the defaults that are in the parameters 188 bigtime_t fBufferPeriod; 189 190 /* Mmmh, stuffing! */ 191 virtual status_t _Reserved_MediaWriter_0(void *); 192 virtual status_t _Reserved_MediaWriter_1(void *); 193 virtual status_t _Reserved_MediaWriter_2(void *); 194 virtual status_t _Reserved_MediaWriter_3(void *); 195 virtual status_t _Reserved_MediaWriter_4(void *); 196 virtual status_t _Reserved_MediaWriter_5(void *); 197 virtual status_t _Reserved_MediaWriter_6(void *); 198 virtual status_t _Reserved_MediaWriter_7(void *); 199 virtual status_t _Reserved_MediaWriter_8(void *); 200 virtual status_t _Reserved_MediaWriter_9(void *); 201 virtual status_t _Reserved_MediaWriter_10(void *); 202 virtual status_t _Reserved_MediaWriter_11(void *); 203 virtual status_t _Reserved_MediaWriter_12(void *); 204 virtual status_t _Reserved_MediaWriter_13(void *); 205 virtual status_t _Reserved_MediaWriter_14(void *); 206 virtual status_t _Reserved_MediaWriter_15(void *); 207 208 uint32 _reserved_media_writer_[16]; 209 210 }; 211 212 #endif /* _MEDIA_WRITER_H */ 213