xref: /haiku/docs/develop/media/MediaExtractorAddOn.h (revision 41acdd1d90c2ca793a73a9dee0be1a6e719c7f52)
1*41acdd1dSDario Casalinuovo extern "C" {
2*41acdd1dSDario Casalinuovo   // Your addon should implement this function.
3*41acdd1dSDario Casalinuovo   // Return a new instance of your BMediaExtractorAddOn subclass.
4*41acdd1dSDario Casalinuovo   // This function will be called multiple times, and should return a
5*41acdd1dSDario Casalinuovo   // new instance each time.  Return NULL if allocation fails.
6*41acdd1dSDario Casalinuovo   BMediaExtractorAddOn * instantiate_media_extractor_add_on();
7*41acdd1dSDario Casalinuovo }
8*41acdd1dSDario Casalinuovo 
9*41acdd1dSDario Casalinuovo // Your add-on must implement a subclass of this class
10*41acdd1dSDario Casalinuovo class BMediaExtractorAddOn
11*41acdd1dSDario Casalinuovo {
12*41acdd1dSDario Casalinuovo public:
13*41acdd1dSDario Casalinuovo   BMediaExtractorAddOn(void);
14*41acdd1dSDario Casalinuovo   virtual ~BMediaExtractorAddOn(void);
15*41acdd1dSDario Casalinuovo 
16*41acdd1dSDario Casalinuovo   //// stateless functions
17*41acdd1dSDario Casalinuovo   // these should work without dependency on a current stream
18*41acdd1dSDario Casalinuovo 
19*41acdd1dSDario Casalinuovo /* begin BFileInterface functions */
20*41acdd1dSDario Casalinuovo   // These are used to enumerate the set of file formats that this
21*41acdd1dSDario Casalinuovo   // extractor is prepared to read from.  Implementing these meaningfully
22*41acdd1dSDario Casalinuovo   // is important for discovering all types supported by the system.
23*41acdd1dSDario Casalinuovo 
24*41acdd1dSDario Casalinuovo   // Implement per BFileInterface::GetNextFileFormat
25*41acdd1dSDario Casalinuovo   //
26*41acdd1dSDario Casalinuovo   // Return codes:
27*41acdd1dSDario Casalinuovo   // B_OK : No error
28*41acdd1dSDario Casalinuovo   // B_ERROR : No more formats
29*41acdd1dSDario Casalinuovo   // GetNextInputFormat: required for BFileInterface functionality
30*41acdd1dSDario Casalinuovo   virtual status_t GetNextInputFormat(int32 * cookie,
31*41acdd1dSDario Casalinuovo                                       media_file_format * outFormat) = 0;
32*41acdd1dSDario Casalinuovo   // Implement per BFileInterface::DisposeFileFormatCookie
33*41acdd1dSDario Casalinuovo   // DisposeInputFormatCookie: required for BFileInterface functionality
34*41acdd1dSDario Casalinuovo   virtual void DisposeInputFormatCookie(int32 cookie) = 0;
35*41acdd1dSDario Casalinuovo 
36*41acdd1dSDario Casalinuovo /* begin transcoding functions */
37*41acdd1dSDario Casalinuovo   // These are used to enumerate the set of file formats that this
38*41acdd1dSDario Casalinuovo   // extractor is prepared to transcode to.  The default implementation
39*41acdd1dSDario Casalinuovo   // simply returns no support.
40*41acdd1dSDario Casalinuovo 
41*41acdd1dSDario Casalinuovo   // Implement per BFileInterface::GetNextFileFormat
42*41acdd1dSDario Casalinuovo   //
43*41acdd1dSDario Casalinuovo   // Return codes:
44*41acdd1dSDario Casalinuovo   // B_OK : No error
45*41acdd1dSDario Casalinuovo   // B_ERROR : No more formats
46*41acdd1dSDario Casalinuovo   virtual status_t GetNextOutputFormat(int32 * cookie,
47*41acdd1dSDario Casalinuovo                                        media_file_format * outFormat);
48*41acdd1dSDario Casalinuovo   // Implement per BFileInterface::DisposeFileFormatCookie
49*41acdd1dSDario Casalinuovo   virtual void DisposeOutputFormatCookie(int32 cookie);
50*41acdd1dSDario Casalinuovo /* end transcoding functions */
51*41acdd1dSDario Casalinuovo /* end BFileInterface functions */
52*41acdd1dSDario Casalinuovo 
53*41acdd1dSDario Casalinuovo /* begin BMediaAddOn functions */
54*41acdd1dSDario Casalinuovo   // These are used to discover an extractors quality rating for a
55*41acdd1dSDario Casalinuovo   // particular media format.
56*41acdd1dSDario Casalinuovo   // Implement per BMediaAddOn::SniffType
57*41acdd1dSDario Casalinuovo   //
58*41acdd1dSDario Casalinuovo   // Return codes:
59*41acdd1dSDario Casalinuovo   // B_OK : No error
60*41acdd1dSDario Casalinuovo   // B_MEDIA_NO_HANDLER : This extractor doesn't handle that mime type
61*41acdd1dSDario Casalinuovo   virtual status_t SniffInputType(BMimeType & mimeType, float * outQuality) = 0;
62*41acdd1dSDario Casalinuovo /* begin transcoding function */
63*41acdd1dSDario Casalinuovo   virtual status_t SniffOutputType(BMimeType & mimeType, float * outQuality);
64*41acdd1dSDario Casalinuovo /* end transcoding function */
65*41acdd1dSDario Casalinuovo /* end BMediaAddOn functions */
66*41acdd1dSDario Casalinuovo 
67*41acdd1dSDario Casalinuovo   // Same as above, but for a media file format
68*41acdd1dSDario Casalinuovo   // The default implementation of this will iterate through your formats using
69*41acdd1dSDario Casalinuovo   // the appropriate interface from above, and simply return 0 for the quality
70*41acdd1dSDario Casalinuovo   // if it finds a matching supported format.
71*41acdd1dSDario Casalinuovo   //
72*41acdd1dSDario Casalinuovo   // Return codes:
73*41acdd1dSDario Casalinuovo   // B_OK : No error
74*41acdd1dSDario Casalinuovo   // B_MEDIA_NO_HANDLER : This extractor doesn't handle that format
75*41acdd1dSDario Casalinuovo   virtual status_t SniffInputFormat(const media_file_format & format, float * outQuality);
76*41acdd1dSDario Casalinuovo /* begin transcoding function */
77*41acdd1dSDario Casalinuovo   virtual status_t SniffOutputFormat(const media_file_format & format, float * outQuality);
78*41acdd1dSDario Casalinuovo /* end transcoding function */
79*41acdd1dSDario Casalinuovo 
80*41acdd1dSDario Casalinuovo   //// state creation functions
81*41acdd1dSDario Casalinuovo   // calling these functions shouldn't affect the results of the stateless functions
82*41acdd1dSDario Casalinuovo 
83*41acdd1dSDario Casalinuovo   // Sets the current stream to source or destination
84*41acdd1dSDario Casalinuovo   // The default implementation for the BDataIO SetSource is to wrap
85*41acdd1dSDario Casalinuovo   // the BDataIO object in a buffer and call the BPositionIO SetSource.
86*41acdd1dSDario Casalinuovo   // The default implementation for the BFile SetSource is to send the
87*41acdd1dSDario Casalinuovo   // call directly to BPositionIO.  Note that it is highly recommended
88*41acdd1dSDario Casalinuovo   // to utilize the BNode properties of the BNodeIO/BFile object in
89*41acdd1dSDario Casalinuovo   // order to dynamically update your extractor state when the file
90*41acdd1dSDario Casalinuovo   // changes.  It is also recommended to use the BNode properties in
91*41acdd1dSDario Casalinuovo   // order to access the attributes of the source file; store or load
92*41acdd1dSDario Casalinuovo   // file specific extractor properties from here.
93*41acdd1dSDario Casalinuovo   // Note: the extractor is not require to return B_MEDIA_NO_HANDLER at
94*41acdd1dSDario Casalinuovo   // this point.  However, calling any stateful function after this
95*41acdd1dSDario Casalinuovo   // should return B_MEDIA_NO_HANDLER.
96*41acdd1dSDario Casalinuovo   //
97*41acdd1dSDario Casalinuovo   // Return codes:
98*41acdd1dSDario Casalinuovo   // B_OK : No error
99*41acdd1dSDario Casalinuovo   // B_NO_MEMORY : Storage for the buffer could not be allocated.
100*41acdd1dSDario Casalinuovo   // B_MEDIA_NO_HANDLER : This extractor doesn't handle that format
101*41acdd1dSDario Casalinuovo   virtual status_t SetSource(const BFile * source);
102*41acdd1dSDario Casalinuovo   virtual status_t SetSource(const entry_ref * source, int32 flags = 0);
103*41acdd1dSDario Casalinuovo   virtual status_t SetSource(const BDataIO * source);
104*41acdd1dSDario Casalinuovo /* begin transcoding functions */
105*41acdd1dSDario Casalinuovo   virtual status_t SetDestination(const BFile * source);
106*41acdd1dSDario Casalinuovo   virtual status_t SetDestination(const entry_ref * source, int32 flags = 0);
107*41acdd1dSDario Casalinuovo   virtual status_t SetDestination(const BDataIO * source);
108*41acdd1dSDario Casalinuovo /* end transcoding functions */
109*41acdd1dSDario Casalinuovo 
110*41acdd1dSDario Casalinuovo   //// stateful functions
111*41acdd1dSDario Casalinuovo   // Calling these functions shouldn't affect the results of the stateless functions.
112*41acdd1dSDario Casalinuovo   // Calling these functions before calling a state creation function should return
113*41acdd1dSDario Casalinuovo   // B_NO_INIT.  Calling these functions after calling a state creation function with
114*41acdd1dSDario Casalinuovo   // an invalid argument should return B_MEDIA_NO_HANDLER.  Generally these
115*41acdd1dSDario Casalinuovo   // functions may also return any appropriate Storage Kit/File System Errors, such
116*41acdd1dSDario Casalinuovo   // as B_FILE_NOT_FOUND, B_BUSTED_PIPE, etc.
117*41acdd1dSDario Casalinuovo 
118*41acdd1dSDario Casalinuovo   // inspired by BMediaFile::GetFileFormatInfo
119*41acdd1dSDario Casalinuovo   //
120*41acdd1dSDario Casalinuovo   // Fills the specified media_file_format structure with
121*41acdd1dSDario Casalinuovo   // information describing the file format of the stream
122*41acdd1dSDario Casalinuovo   // currently referenced by the BEncoder.
123*41acdd1dSDario Casalinuovo   //
124*41acdd1dSDario Casalinuovo   // Return codes:
125*41acdd1dSDario Casalinuovo   // B_OK        : No error
126*41acdd1dSDario Casalinuovo   // B_NO_INIT   : The BEncoder doesn't reference a valid stream.
127*41acdd1dSDario Casalinuovo   // B_NO_MEMORY : Storage for part of the media_file_format
128*41acdd1dSDario Casalinuovo   //               object couldn't be allocated.
129*41acdd1dSDario Casalinuovo   // B_MEDIA_NO_HANDLER : This extractor doesn't handle this format
130*41acdd1dSDario Casalinuovo   virtual status_t GetFileFormatInfo(media_file_format * mfi) = 0;
131*41acdd1dSDario Casalinuovo 
132*41acdd1dSDario Casalinuovo   // The extractor should implement this function in the
133*41acdd1dSDario Casalinuovo   // manner described for BFileInterface::SniffRef, except that
134*41acdd1dSDario Casalinuovo   // it uses the current Source instead of an entry_ref
135*41acdd1dSDario Casalinuovo   //
136*41acdd1dSDario Casalinuovo   // Return codes:
137*41acdd1dSDario Casalinuovo   // B_OK : No error
138*41acdd1dSDario Casalinuovo   // B_NO_INIT   : The BEncoder doesn't reference a valid stream.
139*41acdd1dSDario Casalinuovo   // B_MEDIA_NO_HANDLER : This extractor doesn't handle this format
140*41acdd1dSDario Casalinuovo   virtual status_t Sniff(char * outMimeType, float * outQuality) = 0;
141*41acdd1dSDario Casalinuovo 
142*41acdd1dSDario Casalinuovo   // implement per BMediaTrack::AddChunk(void)
143*41acdd1dSDario Casalinuovo   //
144*41acdd1dSDario Casalinuovo   // Return codes:
145*41acdd1dSDario Casalinuovo   // B_OK        : No error
146*41acdd1dSDario Casalinuovo   // B_NO_INIT   : The BEncoder doesn't reference a valid stream.
147*41acdd1dSDario Casalinuovo   // B_MEDIA_NO_HANDLER : This extractor doesn't handle this format
148*41acdd1dSDario Casalinuovo   virtual status_t WriteChunk(int32 type,
149*41acdd1dSDario Casalinuovo                               const void * data,
150*41acdd1dSDario Casalinuovo                               size_t size);
151*41acdd1dSDario Casalinuovo 
152*41acdd1dSDario Casalinuovo /* begin weird function that is missing but parallels add chunk */
153*41acdd1dSDario Casalinuovo   // implement per BMediaTrack::ReadChunk(void) <- missing????
154*41acdd1dSDario Casalinuovo   // umm.. has the same semantics as AddChunk, yeah that's it...
155*41acdd1dSDario Casalinuovo   //
156*41acdd1dSDario Casalinuovo   // Return codes:
157*41acdd1dSDario Casalinuovo   // B_OK        : No error
158*41acdd1dSDario Casalinuovo   // B_NO_INIT   : The BEncoder doesn't reference a valid stream.
159*41acdd1dSDario Casalinuovo   // B_MEDIA_NO_HANDLER : This extractor doesn't handle this format
160*41acdd1dSDario Casalinuovo   virtual status_t ReadChunk(int32 * outType,
161*41acdd1dSDario Casalinuovo                              const void * outData,
162*41acdd1dSDario Casalinuovo                              size_t * outSize);
163*41acdd1dSDario Casalinuovo /* end weird function that is missing but parallels add chunk */
164*41acdd1dSDario Casalinuovo 
165*41acdd1dSDario Casalinuovo   // The extractor should do any cleanup required.  After
166*41acdd1dSDario Casalinuovo   // this function returns, the source object should be
167*41acdd1dSDario Casalinuovo   // closed and deleted by the caller, not by Close().
168*41acdd1dSDario Casalinuovo   // The default implementation simply returns B_OK.
169*41acdd1dSDario Casalinuovo   //
170*41acdd1dSDario Casalinuovo   // Return codes:
171*41acdd1dSDario Casalinuovo   // B_OK : No error
172*41acdd1dSDario Casalinuovo   // B_NO_INIT   : The BEncoder doesn't reference a valid stream.
173*41acdd1dSDario Casalinuovo   // B_MEDIA_NO_HANDLER : This extractor doesn't handle this format
174*41acdd1dSDario Casalinuovo   virtual status_t Close(void);
175*41acdd1dSDario Casalinuovo 
176*41acdd1dSDario Casalinuovo   //// shared state functions
177*41acdd1dSDario Casalinuovo   // The ParameterWeb interface is used to publish both file specific
178*41acdd1dSDario Casalinuovo   // and extractor specific options.  Accessing a file specific parameter
179*41acdd1dSDario Casalinuovo   // before calling a state creation function should return B_NO_INIT.
180*41acdd1dSDario Casalinuovo   // Accessing a file parameter after calling a state creation function
181*41acdd1dSDario Casalinuovo   // with an invalid argument should return B_MEDIA_NO_HANDLER.  Accessing
182*41acdd1dSDario Casalinuovo   // extractor specific options should never return these errors, but may
183*41acdd1dSDario Casalinuovo   // return other errors.
184*41acdd1dSDario Casalinuovo 
185*41acdd1dSDario Casalinuovo   // the extractor should provide several basic parameters
186*41acdd1dSDario Casalinuovo   // through this interface, such as B_TRACK_COUNT, and B_DURATION
187*41acdd1dSDario Casalinuovo   // see also BMediaFile::GetParameterValue
188*41acdd1dSDario Casalinuovo   // hmmm... how to pick which stream parameters apply to?
189*41acdd1dSDario Casalinuovo   // could use a bitwise or with B_OUTPUT_STREAM (and a
190*41acdd1dSDario Casalinuovo   // B_INPUT_STREAM for completeness)
191*41acdd1dSDario Casalinuovo   //
192*41acdd1dSDario Casalinuovo   // Return codes:
193*41acdd1dSDario Casalinuovo   // B_OK : No error
194*41acdd1dSDario Casalinuovo   // B_NO_INIT   : The BEncoder doesn't reference a valid stream.
195*41acdd1dSDario Casalinuovo   // B_MEDIA_NO_HANDLER : This extractor doesn't handle this format
196*41acdd1dSDario Casalinuovo   virtual status_t GetParameterValue(int32 id, const void * value,
197*41acdd1dSDario Casalinuovo                                      size_t * size) = 0;
198*41acdd1dSDario Casalinuovo 
199*41acdd1dSDario Casalinuovo   // the extractor may optionally supply parameters for the
200*41acdd1dSDario Casalinuovo   // user to configure, such as buffering information(?)
201*41acdd1dSDario Casalinuovo   // see also BMediaFile::SetParameterValue
202*41acdd1dSDario Casalinuovo   //
203*41acdd1dSDario Casalinuovo   // Return codes:
204*41acdd1dSDario Casalinuovo   // B_OK : No error
205*41acdd1dSDario Casalinuovo   // B_NO_INIT   : The BEncoder doesn't reference a valid stream.
206*41acdd1dSDario Casalinuovo   // B_MEDIA_NO_HANDLER : This extractor doesn't handle this format
207*41acdd1dSDario Casalinuovo   virtual status_t SetParameterValue(int32 id, const void * value,
208*41acdd1dSDario Casalinuovo                                      size_t size);
209*41acdd1dSDario Casalinuovo 
210*41acdd1dSDario Casalinuovo   // The extractor may return a BParameterWeb for browsing or
211*41acdd1dSDario Casalinuovo   // configuring the extractor's parameters.  Returns NULL if the
212*41acdd1dSDario Casalinuovo   // extractor doesn't support this.  The default implementation
213*41acdd1dSDario Casalinuovo   // simply returns NULL.  Note: if the Source is not in a good
214*41acdd1dSDario Casalinuovo   // state, this web may not include file specific parameters.
215*41acdd1dSDario Casalinuovo   //
216*41acdd1dSDario Casalinuovo   // As a suggestion you should use groups to gather parameters
217*41acdd1dSDario Casalinuovo   // related to the encoder and separate them from parameters
218*41acdd1dSDario Casalinuovo   // related to the input stream and output stream (if applicable)
219*41acdd1dSDario Casalinuovo   //
220*41acdd1dSDario Casalinuovo   // See also BMediaFile::Web
Web(void)221*41acdd1dSDario Casalinuovo   virtual BParameterWeb * Web(void) { return NULL; }
222*41acdd1dSDario Casalinuovo 
223*41acdd1dSDario Casalinuovo   // The extractor may return a BView for browsing or configuring
224*41acdd1dSDario Casalinuovo   // the extractor's parameters.  Returns NULL if the extractor
225*41acdd1dSDario Casalinuovo   // doesn't support this.  The default implementation simply
226*41acdd1dSDario Casalinuovo   // returns NULL.
GetParameterView(void)227*41acdd1dSDario Casalinuovo   virtual BView * GetParameterView(void) (void) { return NULL; }
228*41acdd1dSDario Casalinuovo 
229*41acdd1dSDario Casalinuovo /* begin seek/sync functions for the extractor */
230*41acdd1dSDario Casalinuovo   // The extractor will seek first on the seek track, just like
231*41acdd1dSDario Casalinuovo   // BMediaTrack::SeekToTime.  Like SeekToTime, it accepts a flag
232*41acdd1dSDario Casalinuovo   // argument which tells how to find the nearest acceptable frame.
233*41acdd1dSDario Casalinuovo   // After finding this frame, it will also seek any other open
234*41acdd1dSDario Casalinuovo   // streams in an extractor-dependent fashion.  Usually the seek
235*41acdd1dSDario Casalinuovo   // stream will be a video stream.  If seeked to a keyframe, for
236*41acdd1dSDario Casalinuovo   // example, the audio stream will be seeked to an appropriate time.
237*41acdd1dSDario Casalinuovo   //
238*41acdd1dSDario Casalinuovo   // This may be more efficient than seeking the seek track through
239*41acdd1dSDario Casalinuovo   // the BMediaTrack interface, and then calling Sync() here.  It
240*41acdd1dSDario Casalinuovo   // should not be less efficient.
241*41acdd1dSDario Casalinuovo   //
242*41acdd1dSDario Casalinuovo   // See also BMediaTrack::SeekToTime
243*41acdd1dSDario Casalinuovo   // see above for additions to media_seek_type (used for flags)
244*41acdd1dSDario Casalinuovo   // seekMode per BFile::Seek, only SEEK_SET is required
245*41acdd1dSDario Casalinuovo   //
246*41acdd1dSDario Casalinuovo   // Return codes:
247*41acdd1dSDario Casalinuovo   // B_OK : No error
248*41acdd1dSDario Casalinuovo   // B_UNSUPPORTED : This extractor does not support general seeking
249*41acdd1dSDario Casalinuovo   //                 for this stream.
250*41acdd1dSDario Casalinuovo   // B_NO_INIT   : The BEncoder doesn't reference a valid stream.
251*41acdd1dSDario Casalinuovo   // B_MEDIA_NO_HANDLER : This extractor doesn't handle this format
252*41acdd1dSDario Casalinuovo   virtual status_t SeekToTime(bigtime_t * ioTime,
253*41acdd1dSDario Casalinuovo                               int32 mediaSeekFlags = 0,
254*41acdd1dSDario Casalinuovo                               int32 seekMode = 0) = 0;
255*41acdd1dSDario Casalinuovo 
256*41acdd1dSDario Casalinuovo   // The extractor will seek first on the seek track, just like
257*41acdd1dSDario Casalinuovo   // BMediaTrack::SeekToFrame.  Like SeekToFrame, it accepts a flag
258*41acdd1dSDario Casalinuovo   // argument which tells how to find the nearest acceptable frame.
259*41acdd1dSDario Casalinuovo   // After finding this frame, it will also seek any other open
260*41acdd1dSDario Casalinuovo   // streams in an extractor-dependent fashion.  Usually the seek
261*41acdd1dSDario Casalinuovo   // stream will be a video stream.  If seeked to a keyframe, for
262*41acdd1dSDario Casalinuovo   // example, the audio stream will be seeked to an appropriate time.
263*41acdd1dSDario Casalinuovo   //
264*41acdd1dSDario Casalinuovo   // This may be more efficient than seeking the seek track through
265*41acdd1dSDario Casalinuovo   // the BMediaTrack interface, and then calling Sync() here.  It
266*41acdd1dSDario Casalinuovo   // should not be less efficient.
267*41acdd1dSDario Casalinuovo   //
268*41acdd1dSDario Casalinuovo   // See also BMediaTrack::SeekToFrame
269*41acdd1dSDario Casalinuovo   // see above for additions to media_seek_type (used for flags)
270*41acdd1dSDario Casalinuovo   // seekMode per BFile::Seek, only SEEK_SET is required
271*41acdd1dSDario Casalinuovo   //
272*41acdd1dSDario Casalinuovo   // Return codes:
273*41acdd1dSDario Casalinuovo   // B_OK : No error
274*41acdd1dSDario Casalinuovo   // B_UNSUPPORTED : This extractor does not support general seeking
275*41acdd1dSDario Casalinuovo   //                 for this stream.
276*41acdd1dSDario Casalinuovo   // B_NO_INIT   : The BEncoder doesn't reference a valid stream.
277*41acdd1dSDario Casalinuovo   // B_MEDIA_NO_HANDLER : This extractor doesn't handle this format
278*41acdd1dSDario Casalinuovo   virtual status_t SeekToFrame(int64 * ioFrame,
279*41acdd1dSDario Casalinuovo                                int32 mediaSeekFlags = 0,
280*41acdd1dSDario Casalinuovo                                int32 seekMode = 0) = 0;
281*41acdd1dSDario Casalinuovo 
282*41acdd1dSDario Casalinuovo /* begin seek extensions functions */
283*41acdd1dSDario Casalinuovo   // The extractor will seek first on the seek track.  It goes to
284*41acdd1dSDario Casalinuovo   // a position defined by ioChunk*chunkSize, where chunkSize is
285*41acdd1dSDario Casalinuovo   // defined by the decoder.  For example, some streams are not byte
286*41acdd1dSDario Casalinuovo   // streams, but rather bitstreams.  In this case the chunkSize may
287*41acdd1dSDario Casalinuovo   // correspond to 1 bit.  Like the other MediaTrack Seeks, it
288*41acdd1dSDario Casalinuovo   // accepts a flag argument which tells how to find the nearest
289*41acdd1dSDario Casalinuovo   // acceptable frame.
290*41acdd1dSDario Casalinuovo   // After finding this frame, it will also seek any other open
291*41acdd1dSDario Casalinuovo   // streams in an extractor-dependent fashion.  Usually the seek
292*41acdd1dSDario Casalinuovo   // stream will be a video stream.  If seeked to a keyframe, for
293*41acdd1dSDario Casalinuovo   // example, the audio stream will be seeked to an appropriate time.
294*41acdd1dSDario Casalinuovo   //
295*41acdd1dSDario Casalinuovo   // This may be more efficient than seeking the seek track through
296*41acdd1dSDario Casalinuovo   // the BMediaTrack interface, and then calling Sync() here.  It
297*41acdd1dSDario Casalinuovo   // should not be less efficient.
298*41acdd1dSDario Casalinuovo   //
299*41acdd1dSDario Casalinuovo   // see above for additions to media_seek_type (used for flags)
300*41acdd1dSDario Casalinuovo   // seekMode per BFile::Seek, only SEEK_SET is required
301*41acdd1dSDario Casalinuovo   //
302*41acdd1dSDario Casalinuovo   // Return codes:
303*41acdd1dSDario Casalinuovo   // B_OK : No error
304*41acdd1dSDario Casalinuovo   // B_UNSUPPORTED : This extractor does not support general seeking
305*41acdd1dSDario Casalinuovo   //                 for this stream.
306*41acdd1dSDario Casalinuovo   // B_NO_INIT   : The BEncoder doesn't reference a valid stream.
307*41acdd1dSDario Casalinuovo   // B_MEDIA_NO_HANDLER : This extractor doesn't handle this format
308*41acdd1dSDario Casalinuovo   virtual status_t SeekToChunk(int64 * ioChunk,
309*41acdd1dSDario Casalinuovo                                int32 mediaSeekFlags = 0,
310*41acdd1dSDario Casalinuovo                                int32 seekMode = 0) = 0;
311*41acdd1dSDario Casalinuovo 
312*41acdd1dSDario Casalinuovo   // The extractor will seek first on the seek track.  It goes to a
313*41acdd1dSDario Casalinuovo   // position defined by numerator/(duration of this file).  For
314*41acdd1dSDario Casalinuovo   // example: Seek(LONG_LONG_MAX/2) would seek halfway through the
315*41acdd1dSDario Casalinuovo   // stream.  Like the other MediaTrack Seeks, it accepts a flag
316*41acdd1dSDario Casalinuovo   // argument which tells how to find the nearest acceptable frame.
317*41acdd1dSDario Casalinuovo   // If the seekMode is SEEK_SET it will seek a fraction of the way
318*41acdd1dSDario Casalinuovo   // back to the beginning from the current location.  If the seekMode
319*41acdd1dSDario Casalinuovo   // is SEEK_END it will seek a fraction of the way to the end from
320*41acdd1dSDario Casalinuovo   // the current location.  If the seekMode is SEEK_CUR it will seek
321*41acdd1dSDario Casalinuovo   // as above. (fraction of the entire file duration)
322*41acdd1dSDario Casalinuovo   // After finding this frame, it will also seek any other open
323*41acdd1dSDario Casalinuovo   // streams in an extractor-dependent fashion.  Usually the seek
324*41acdd1dSDario Casalinuovo   // stream will be a video stream.  If seeked to a keyframe, for
325*41acdd1dSDario Casalinuovo   // example, the audio stream will be seeked to an appropriate time.
326*41acdd1dSDario Casalinuovo   //
327*41acdd1dSDario Casalinuovo   // This may be a lot more efficient than seeking to a time or frame
328*41acdd1dSDario Casalinuovo   // for some streams. (in particular, nonindexed streams)
329*41acdd1dSDario Casalinuovo   //
330*41acdd1dSDario Casalinuovo   // This may be more efficient than seeking the seek track through
331*41acdd1dSDario Casalinuovo   // the BMediaTrack interface, and then calling Sync() here.  It
332*41acdd1dSDario Casalinuovo   // should not be less efficient.
333*41acdd1dSDario Casalinuovo   //
334*41acdd1dSDario Casalinuovo   // Note: because the duration may change over time (if the file is
335*41acdd1dSDario Casalinuovo   // being written to, for example) the result of seeking with a
336*41acdd1dSDario Casalinuovo   // particular numerator may also change.  It will usually be later,
337*41acdd1dSDario Casalinuovo   // but could also be earlier.
338*41acdd1dSDario Casalinuovo   //
339*41acdd1dSDario Casalinuovo   // see above for additions to media_seek_type (used for flags)
340*41acdd1dSDario Casalinuovo   // seekMode per BFile::Seek, only SEEK_CUR is required
341*41acdd1dSDario Casalinuovo   //
342*41acdd1dSDario Casalinuovo   // Return codes:
343*41acdd1dSDario Casalinuovo   // B_OK : No error
344*41acdd1dSDario Casalinuovo   // B_UNSUPPORTED : This extractor does not support general seeking
345*41acdd1dSDario Casalinuovo   //                 for this stream.
346*41acdd1dSDario Casalinuovo   // B_NO_INIT     : The BEncoder doesn't reference a valid stream.
347*41acdd1dSDario Casalinuovo   // B_MEDIA_NO_HANDLER : This extractor doesn't handle this format
348*41acdd1dSDario Casalinuovo   virtual status_t Seek(int64 * numerator,
349*41acdd1dSDario Casalinuovo                         int32 mediaSeekFlags = 0,
350*41acdd1dSDario Casalinuovo                         int32 seekMode = 0) = 0;
351*41acdd1dSDario Casalinuovo /* end seek extensions functions */
352*41acdd1dSDario Casalinuovo 
353*41acdd1dSDario Casalinuovo   // Using the location from the seek stream, seeks any other open
354*41acdd1dSDario Casalinuovo   // streams in an extractor-dependent fashion.  Usually the seek
355*41acdd1dSDario Casalinuovo   // stream will be a video stream.  If seeked to a keyframe, for
356*41acdd1dSDario Casalinuovo   // example, the audio stream will be seeked to an appropriate time.
357*41acdd1dSDario Casalinuovo   //
358*41acdd1dSDario Casalinuovo   // Note: if not supplied, the seek stream will be the current one
359*41acdd1dSDario Casalinuovo   // as retrieved by GetParameterValue, not zero.  Sync() will do
360*41acdd1dSDario Casalinuovo   // this check for you.
361*41acdd1dSDario Casalinuovo   //
362*41acdd1dSDario Casalinuovo   // Return codes:
363*41acdd1dSDario Casalinuovo   // B_OK : No error
364*41acdd1dSDario Casalinuovo   // B_UNSUPPORTED : This extractor does not support general syncing
365*41acdd1dSDario Casalinuovo   //                 for this stream.
366*41acdd1dSDario Casalinuovo   // B_NO_INIT   : The BEncoder doesn't reference a valid stream.
367*41acdd1dSDario Casalinuovo   // B_MEDIA_NO_HANDLER : This extractor doesn't handle this format
368*41acdd1dSDario Casalinuovo   virtual status_t Sync(int32 seekStream = 0) = 0;
369*41acdd1dSDario Casalinuovo /* end seek/sync functions for the extractor */
370*41acdd1dSDario Casalinuovo 
371*41acdd1dSDario Casalinuovo   // Returns a thing that is useful for MediaTrack to do its business.
372*41acdd1dSDario Casalinuovo   //
373*41acdd1dSDario Casalinuovo   // May simply include state but will probably include a pointer back
374*41acdd1dSDario Casalinuovo   // to this object, and will likely call functions that are defined by
375*41acdd1dSDario Casalinuovo   // subclasses of this extractor.  For example, the subclass may define
376*41acdd1dSDario Casalinuovo   // a function like this:
377*41acdd1dSDario Casalinuovo   // SeekTrackToFrame(BTrack * track, int64 ioFrame, int32 flags = 0) {
378*41acdd1dSDario Casalinuovo   // ... }
379*41acdd1dSDario Casalinuovo   // and then when SeekToFrame is called on the BTrack object the work
380*41acdd1dSDario Casalinuovo   // would be done by the Extractor.
381*41acdd1dSDario Casalinuovo   //
382*41acdd1dSDario Casalinuovo   // Also, any track extracted using this function will be seeked by
383*41acdd1dSDario Casalinuovo   // the extractor seek functions.  Any track not extracted by this
384*41acdd1dSDario Casalinuovo   // function will not be seeked.  If the seekMode parameter is
385*41acdd1dSDario Casalinuovo   // supplied as SEEK_CUR the track will be seeked before being
386*41acdd1dSDario Casalinuovo   // returned, as per Sync().  However because this involves only
387*41acdd1dSDario Casalinuovo   // one track it may be more efficient than retrieving the track and
388*41acdd1dSDario Casalinuovo   // then calling Sync();  If seekMode is SEEK_SET then the current
389*41acdd1dSDario Casalinuovo   // seek time for the track will be no later than the earliest
390*41acdd1dSDario Casalinuovo   // seekable time.  If seekMode is SEEK_END the current seek time
391*41acdd1dSDario Casalinuovo   // for the track will be no earlier than the earliest seekable time.
392*41acdd1dSDario Casalinuovo   // Note: for non-seekable tracks, this may may no difference.
393*41acdd1dSDario Casalinuovo   // The default for seekMode is SEEK_SET.
394*41acdd1dSDario Casalinuovo   //
395*41acdd1dSDario Casalinuovo   // If the seek parameter is passed as false, no pre-seeking will be
396*41acdd1dSDario Casalinuovo   // performed on the track.  The current seek time may be arbitrary
397*41acdd1dSDario Casalinuovo   // or even illegal.  Attempting to decode data from the track in
398*41acdd1dSDario Casalinuovo   // this state will result in an error if the state is illegal.
399*41acdd1dSDario Casalinuovo   //
400*41acdd1dSDario Casalinuovo   // Return codes:
401*41acdd1dSDario Casalinuovo   // B_OK : No error
402*41acdd1dSDario Casalinuovo   // B_STREAM_NOT_FOUND
403*41acdd1dSDario Casalinuovo   // B_BAD_INDEX : The index supplied does not correspond to a valid
404*41acdd1dSDario Casalinuovo   //               track in this stream.
405*41acdd1dSDario Casalinuovo   // B_NO_INIT   : The BEncoder doesn't reference a valid stream.
406*41acdd1dSDario Casalinuovo   // B_MEDIA_NO_HANDLER : This extractor doesn't handle this format
407*41acdd1dSDario Casalinuovo   virtual BTrack * TrackAt(int32 index, int32 seekMode = 0,
408*41acdd1dSDario Casalinuovo                                         bool seek = true) = 0;
409*41acdd1dSDario Casalinuovo 
410*41acdd1dSDario Casalinuovo   // Disclaims interest in a particular track.  After releasing a
411*41acdd1dSDario Casalinuovo   // track the track will no longer be seeked by the extractor.
412*41acdd1dSDario Casalinuovo   //
413*41acdd1dSDario Casalinuovo   // Return codes:
414*41acdd1dSDario Casalinuovo   // B_OK : No error
415*41acdd1dSDario Casalinuovo   // B_BAD_TYPE  : This track does not correspond to this extractor.
416*41acdd1dSDario Casalinuovo   // B_NO_INIT   : The BEncoder doesn't reference a valid stream.
417*41acdd1dSDario Casalinuovo   // B_MEDIA_NO_HANDLER : This extractor doesn't handle this format
418*41acdd1dSDario Casalinuovo   status_t ReleaseTrack(BTrack * track);
419*41acdd1dSDario Casalinuovo 
420*41acdd1dSDario Casalinuovo protected:
421*41acdd1dSDario Casalinuovo   // use to negotiate the format for this track
422*41acdd1dSDario Casalinuovo   // straight BMediaTrack::DecodedFormat behavior
423*41acdd1dSDario Casalinuovo   virtual status_t NegotiateOutputFormat(BTrack * track,
424*41acdd1dSDario Casalinuovo                                          media_format * ioFormat) = 0;
425*41acdd1dSDario Casalinuovo 
426*41acdd1dSDario Casalinuovo   // get/set information about a particular track
427*41acdd1dSDario Casalinuovo   virtual status_t GetParameterValue(BTrack * track, int32 id,
428*41acdd1dSDario Casalinuovo                                      const void * value, size_t * size) = 0;
429*41acdd1dSDario Casalinuovo   virtual status_t SetParameterValue(BTrack * track, int32 id,
430*41acdd1dSDario Casalinuovo                                      const void * value, size_t size);
Web(BTrack * track)431*41acdd1dSDario Casalinuovo   virtual BParameterWeb * Web(BTrack * track) { return NULL; }
GetParameterView(BTrack * track)432*41acdd1dSDario Casalinuovo   virtual BView * GetParameterView(BTrack * track) { return NULL; }
433*41acdd1dSDario Casalinuovo 
434*41acdd1dSDario Casalinuovo   // seek only this particular track to the given time
435*41acdd1dSDario Casalinuovo   // straight BMediaTrack::SeekToTime behavior
436*41acdd1dSDario Casalinuovo   virtual status_t SeekToTime(BTrack * track,
437*41acdd1dSDario Casalinuovo                               bigtime_t * ioTime,
438*41acdd1dSDario Casalinuovo                               int32 mediaSeekFlags = 0,
439*41acdd1dSDario Casalinuovo                               int32 seekMode = 0) = 0;
440*41acdd1dSDario Casalinuovo   // seek only this particular track to the given frame
441*41acdd1dSDario Casalinuovo   // straight BMediaTrack::SeekToFrame behavior
442*41acdd1dSDario Casalinuovo   virtual status_t SeekToFrame(BTrack * track,
443*41acdd1dSDario Casalinuovo                                int64 * ioFrame,
444*41acdd1dSDario Casalinuovo                                int32 mediaSeekFlags = 0,
445*41acdd1dSDario Casalinuovo                                int32 seekMode = 0) = 0;
446*41acdd1dSDario Casalinuovo   // seek only this particular track to the given chunk
447*41acdd1dSDario Casalinuovo   // straight BMediaTrack::SeekToChunk behavior
448*41acdd1dSDario Casalinuovo   virtual status_t SeekToChunk(BTrack * track,
449*41acdd1dSDario Casalinuovo                                int64 * ioChunk,
450*41acdd1dSDario Casalinuovo                                int32 mediaSeekFlags = 0,
451*41acdd1dSDario Casalinuovo                                int32 seekMode = 0) = 0;
452*41acdd1dSDario Casalinuovo   // seek only this particular track to the given chunk
453*41acdd1dSDario Casalinuovo   // straight BMediaTrack::Seek behavior
454*41acdd1dSDario Casalinuovo   virtual status_t Seek(BTrack * track,
455*41acdd1dSDario Casalinuovo                         int64 * numerator,
456*41acdd1dSDario Casalinuovo                         int32 mediaSeekFlags = 0,
457*41acdd1dSDario Casalinuovo                         int32 seekMode = 0) = 0;
458*41acdd1dSDario Casalinuovo 
459*41acdd1dSDario Casalinuovo   // read a chunk from this track only
460*41acdd1dSDario Casalinuovo   // straight BMediaTrack::ReadChunk behavior
461*41acdd1dSDario Casalinuovo   virtual status_t ReadChunk(BTrack * track,
462*41acdd1dSDario Casalinuovo                              char ** outBuffer, int32 * ioSize,
463*41acdd1dSDario Casalinuovo                              media_header * outHeader = NULL) = 0;
464*41acdd1dSDario Casalinuovo   // read frames from this track only
465*41acdd1dSDario Casalinuovo   // straight BMediaTrack::ReadChunk behavior
466*41acdd1dSDario Casalinuovo   virtual status_t ReadFrames(BTrack * track,
467*41acdd1dSDario Casalinuovo                               void * outBuffer, int64 * outFrameCount,
468*41acdd1dSDario Casalinuovo                               media_header * outHeader = NULL,
469*41acdd1dSDario Casalinuovo                               media_decode_info * info = NULL) = 0;
470*41acdd1dSDario Casalinuovo /* begin read extensions functions */
471*41acdd1dSDario Casalinuovo   // read units of time from this track only
472*41acdd1dSDario Casalinuovo   virtual status_t ReadTime(BTrack * track,
473*41acdd1dSDario Casalinuovo                             void * outBuffer, int64 * outTimeCount,
474*41acdd1dSDario Casalinuovo                             media_header * outHeader = NULL,
475*41acdd1dSDario Casalinuovo                             media_decode_info * info = NULL) = 0;
476*41acdd1dSDario Casalinuovo   // for completeness sake?
477*41acdd1dSDario Casalinuovo   // read a percentage from this track only
478*41acdd1dSDario Casalinuovo   virtual status_t Read(BTrack * track,
479*41acdd1dSDario Casalinuovo                         void * outBuffer, int64 * outNumerator,
480*41acdd1dSDario Casalinuovo                         media_header * outHeader = NULL,
481*41acdd1dSDario Casalinuovo                         media_decode_info * info = NULL) = 0;
482*41acdd1dSDario Casalinuovo /* end read extensions functions */
483*41acdd1dSDario Casalinuovo 
484*41acdd1dSDario Casalinuovo private:
485*41acdd1dSDario Casalinuovo   // this class is used by individual tracks
486*41acdd1dSDario Casalinuovo   // as a private interface to the extractor
487*41acdd1dSDario Casalinuovo   class BTrack {
488*41acdd1dSDario Casalinuovo     // use to negotiate the format for this track
NegotiateOutputFormat(media_format * ioFormat)489*41acdd1dSDario Casalinuovo     virtual status_t NegotiateOutputFormat(media_format * ioFormat) {
490*41acdd1dSDario Casalinuovo       return BExtractor::NegotiateOutputFormat(ioFormat);
491*41acdd1dSDario Casalinuovo     }
492*41acdd1dSDario Casalinuovo 
493*41acdd1dSDario Casalinuovo     // access to parameters for this track
GetParameterValue(int32 id,const void * value,size_t * size)494*41acdd1dSDario Casalinuovo     virtual status_t GetParameterValue(int32 id, const void * value,
495*41acdd1dSDario Casalinuovo                                        size_t * size) {
496*41acdd1dSDario Casalinuovo       return BExtractor::GetParameterValue(this,id,value,size);
497*41acdd1dSDario Casalinuovo     }
SetParameterValue(int32 id,const void * value,size_t size)498*41acdd1dSDario Casalinuovo     virtual status_t SetParameterValue(int32 id, const void * value,
499*41acdd1dSDario Casalinuovo                                        size_t size) {
500*41acdd1dSDario Casalinuovo       return BExtractor::SetParameterValue(this,id,value,size);
501*41acdd1dSDario Casalinuovo     }
Web(void)502*41acdd1dSDario Casalinuovo     virtual BParameterWeb * Web(void) {
503*41acdd1dSDario Casalinuovo       return BExtractor::Web(this);
504*41acdd1dSDario Casalinuovo     }
GetParameterView(void)505*41acdd1dSDario Casalinuovo     virtual BView * GetParameterView(void) {
506*41acdd1dSDario Casalinuovo       return BExtractor::GetParameterView(this);
507*41acdd1dSDario Casalinuovo     }
508*41acdd1dSDario Casalinuovo 
509*41acdd1dSDario Casalinuovo     // access to seek functionality on this track
510*41acdd1dSDario Casalinuovo     virtual status_t SeekToTime(bigtime_t * ioTime,
511*41acdd1dSDario Casalinuovo                               int32 mediaSeekFlags = 0,
512*41acdd1dSDario Casalinuovo                               int32 seekMode = 0) {
513*41acdd1dSDario Casalinuovo       return BExtractor::SeekToTime(this,ioTime,mediaSeekFlags,seekMode);
514*41acdd1dSDario Casalinuovo     }
515*41acdd1dSDario Casalinuovo     virtual status_t SeekToFrame(int64 * ioFrame,
516*41acdd1dSDario Casalinuovo                                  int32 mediaSeekFlags = 0,
517*41acdd1dSDario Casalinuovo                                  int32 seekMode = 0) {
518*41acdd1dSDario Casalinuovo       return BExtractor::SeekToFrame(this,ioFrame,mediaSeekFlags,seekMode);
519*41acdd1dSDario Casalinuovo     }
520*41acdd1dSDario Casalinuovo     virtual status_t SeekToChunk(int64 * ioChunk,
521*41acdd1dSDario Casalinuovo                                  int32 mediaSeekFlags = 0,
522*41acdd1dSDario Casalinuovo                                  int32 seekMode = 0) {
523*41acdd1dSDario Casalinuovo       return BExtractor::SeekToChunk(this,ioChunk,mediaSeekFlags,seekMode);
524*41acdd1dSDario Casalinuovo     }
525*41acdd1dSDario Casalinuovo     virtual status_t Seek(int64 * numerator,
526*41acdd1dSDario Casalinuovo                           int32 mediaSeekFlags = 0,
527*41acdd1dSDario Casalinuovo                           int32 seekMode = 0) {
528*41acdd1dSDario Casalinuovo       return BExtractor::Seek(this,numerator,mediaSeekFlags,seekMode);
529*41acdd1dSDario Casalinuovo     }
530*41acdd1dSDario Casalinuovo 
531*41acdd1dSDario Casalinuovo     // access to readers for this track
532*41acdd1dSDario Casalinuovo     virtual status_t ReadChunk(char ** outBuffer, int32 * ioSize,
533*41acdd1dSDario Casalinuovo                                media_header * outHeader = NULL) {
534*41acdd1dSDario Casalinuovo       return BExtractor::ReadChunk(this,outBuffer,ioSize,outHeader);
535*41acdd1dSDario Casalinuovo     }
536*41acdd1dSDario Casalinuovo     virtual status_t ReadFrames(void * outBuffer, int64 * outFrameCount,
537*41acdd1dSDario Casalinuovo                                 media_header * outHeader = NULL,
538*41acdd1dSDario Casalinuovo                                 media_decode_info * info = NULL) {
539*41acdd1dSDario Casalinuovo       return BExtractor::ReadFrames(this,outBuffer,outFrameCount,outHeader,info);
540*41acdd1dSDario Casalinuovo     }
541*41acdd1dSDario Casalinuovo /* begin read extensions functions */
542*41acdd1dSDario Casalinuovo 	virtual status_t ReadTime(void * outBuffer, int64 * outTimeCount,
543*41acdd1dSDario Casalinuovo                               media_header * outHeader = NULL,
544*41acdd1dSDario Casalinuovo                               media_decode_info * info = NULL) {
545*41acdd1dSDario Casalinuovo       return BExtractor::ReadTime(this,outBuffer,outTimeCount,outHeader,info);
546*41acdd1dSDario Casalinuovo     }
547*41acdd1dSDario Casalinuovo     // for completeness sake?
548*41acdd1dSDario Casalinuovo     virtual status_t Read(void * outBuffer, int64 * outNumerator,
549*41acdd1dSDario Casalinuovo                           media_header * outHeader = NULL,
550*41acdd1dSDario Casalinuovo                           media_decode_info * info = NULL) {
551*41acdd1dSDario Casalinuovo       return BExtractor::Read(this,outBuffer,outNumerator,outHeader,info);
552*41acdd1dSDario Casalinuovo     }
553*41acdd1dSDario Casalinuovo /* end read extensions functions */
554*41acdd1dSDario Casalinuovo     // pad me
555*41acdd1dSDario Casalinuovo   };
556*41acdd1dSDario Casalinuovo 
557*41acdd1dSDario Casalinuovo   // pad me
558*41acdd1dSDario Casalinuovo };
559*41acdd1dSDario Casalinuovo 
560*41acdd1dSDario Casalinuovo 
561