1 /***********************************************************************
2 * AUTHOR: Andrew Bachmann, Marcus Overhagen
3 * FILE: MediaDecoder.cpp
5 ***********************************************************************/
6 #include <MediaDecoder.h>
7 #include <DecoderPlugin.h>
9 #include "PluginManager.h"
12 /*************************************************************
13 * public BMediaDecoder
14 *************************************************************/
16 BMediaDecoder::BMediaDecoder()
18 fInitStatus(B_NO_INIT
)
23 BMediaDecoder::BMediaDecoder(const media_format
*in_format
,
27 fInitStatus(B_NO_INIT
)
29 SetTo(in_format
, info
, info_size
);
33 BMediaDecoder::BMediaDecoder(const media_codec_info
*mci
)
35 fInitStatus(B_NO_INIT
)
42 BMediaDecoder::~BMediaDecoder()
44 gPluginManager
.DestroyDecoder(fDecoder
);
49 BMediaDecoder::InitCheck() const
56 BMediaDecoder::SetTo(const media_format
*in_format
,
60 gPluginManager
.DestroyDecoder(fDecoder
);
63 status_t err
= gPluginManager
.CreateDecoder(&fDecoder
, *in_format
);
67 err
= AttachToDecoder();
71 err
= SetInputFormat(in_format
, info
, info_size
);
79 gPluginManager
.DestroyDecoder(fDecoder
);
81 fInitStatus
= B_NO_INIT
;
87 BMediaDecoder::SetTo(const media_codec_info
*mci
)
89 gPluginManager
.DestroyDecoder(fDecoder
);
92 status_t err
= gPluginManager
.CreateDecoder(&fDecoder
, *mci
);
96 err
= AttachToDecoder();
104 gPluginManager
.DestroyDecoder(fDecoder
);
106 fInitStatus
= B_NO_INIT
;
111 /** SetInputFormat() sets the input data format to in_format.
112 * Unlike SetTo(), the SetInputFormat() function does not
113 * select a codec, so the currently-selected codec will
114 * continue to be used. You should only use SetInputFormat()
115 * to refine the format settings if it will not require the
116 * use of a different decoder.
120 BMediaDecoder::SetInputFormat(const media_format
*in_format
,
127 media_format format
= *in_format
;
128 return fDecoder
->Setup(&format
, in_info
, in_size
);
132 /** SetOutputFormat() sets the format the decoder should output.
133 * On return, the output_format is changed to match the actual
134 * format that will be output; this can be different if you
135 * specified any wildcards.
139 BMediaDecoder::SetOutputFormat(media_format
*output_format
)
144 return fDecoder
->NegotiateOutputFormat(output_format
);
148 /** Decodes a chunk of media data into the output buffer specified
149 * by out_buffer. On return, out_frameCount is set to indicate how
150 * many frames of data were decoded, and out_mh is the header for
151 * the decoded buffer. The media_decode_info structure info is used
152 * on input to specify decoding parameters.
154 * The amount of data decoded is part of the format determined by
155 * SetTo() or SetInputFormat(). For audio, it's the buffer_size.
156 * For video, it's one frame, which is height*row_bytes. The data
157 * to be decoded will be fetched from the source by the decoder
158 * add-on calling the derived class' GetNextChunk() function.
162 BMediaDecoder::Decode(void *out_buffer
,
163 int64
*out_frameCount
,
164 media_header
*out_mh
,
165 media_decode_info
*info
)
170 return fDecoder
->Decode(out_buffer
, out_frameCount
, out_mh
, info
);
175 BMediaDecoder::GetDecoderInfo(media_codec_info
*out_info
) const
180 return gPluginManager
.GetDecoderInfo(fDecoder
, out_info
);
184 /*************************************************************
185 * protected BMediaDecoder
186 *************************************************************/
189 /*************************************************************
190 * private BMediaDecoder
191 *************************************************************/
195 BMediaDecoder::BMediaDecoder(const BMediaDecoder &);
196 BMediaDecoder::BMediaDecoder & operator=(const BMediaDecoder &);
200 BMediaDecoder::AttachToDecoder()
202 class MediaDecoderChunkProvider
: public ChunkProvider
{
204 BMediaDecoder
* fDecoder
;
206 MediaDecoderChunkProvider(BMediaDecoder
* decoder
) {
209 virtual status_t
GetNextChunk(const void **chunkBuffer
, size_t *chunkSize
,
210 media_header
*mediaHeader
) {
211 return fDecoder
->GetNextChunk(chunkBuffer
, chunkSize
, mediaHeader
);
213 } * provider
= new(std::nothrow
) MediaDecoderChunkProvider(this);
218 fDecoder
->SetChunkProvider(provider
);
223 status_t
BMediaDecoder::_Reserved_BMediaDecoder_0(int32 arg
, ...) { return B_ERROR
; }
224 status_t
BMediaDecoder::_Reserved_BMediaDecoder_1(int32 arg
, ...) { return B_ERROR
; }
225 status_t
BMediaDecoder::_Reserved_BMediaDecoder_2(int32 arg
, ...) { return B_ERROR
; }
226 status_t
BMediaDecoder::_Reserved_BMediaDecoder_3(int32 arg
, ...) { return B_ERROR
; }
227 status_t
BMediaDecoder::_Reserved_BMediaDecoder_4(int32 arg
, ...) { return B_ERROR
; }
228 status_t
BMediaDecoder::_Reserved_BMediaDecoder_5(int32 arg
, ...) { return B_ERROR
; }
229 status_t
BMediaDecoder::_Reserved_BMediaDecoder_6(int32 arg
, ...) { return B_ERROR
; }
230 status_t
BMediaDecoder::_Reserved_BMediaDecoder_7(int32 arg
, ...) { return B_ERROR
; }
231 status_t
BMediaDecoder::_Reserved_BMediaDecoder_8(int32 arg
, ...) { return B_ERROR
; }
232 status_t
BMediaDecoder::_Reserved_BMediaDecoder_9(int32 arg
, ...) { return B_ERROR
; }
233 status_t
BMediaDecoder::_Reserved_BMediaDecoder_10(int32 arg
, ...) { return B_ERROR
; }
234 status_t
BMediaDecoder::_Reserved_BMediaDecoder_11(int32 arg
, ...) { return B_ERROR
; }
235 status_t
BMediaDecoder::_Reserved_BMediaDecoder_12(int32 arg
, ...) { return B_ERROR
; }
236 status_t
BMediaDecoder::_Reserved_BMediaDecoder_13(int32 arg
, ...) { return B_ERROR
; }
237 status_t
BMediaDecoder::_Reserved_BMediaDecoder_14(int32 arg
, ...) { return B_ERROR
; }
238 status_t
BMediaDecoder::_Reserved_BMediaDecoder_15(int32 arg
, ...) { return B_ERROR
; }
240 /*************************************************************
241 * public BMediaBufferDecoder
242 *************************************************************/
244 BMediaBufferDecoder::BMediaBufferDecoder()
251 BMediaBufferDecoder::BMediaBufferDecoder(const media_format
*in_format
,
254 : BMediaDecoder(in_format
, info
, info_size
)
260 BMediaBufferDecoder::BMediaBufferDecoder(const media_codec_info
*mci
)
268 BMediaBufferDecoder::DecodeBuffer(const void *input_buffer
,
271 int64
*out_frameCount
,
272 media_header
*out_mh
,
273 media_decode_info
*info
)
275 fBuffer
= input_buffer
;
276 fBufferSize
= input_size
;
277 return Decode(out_buffer
, out_frameCount
, out_mh
,info
);
281 /*************************************************************
282 * protected BMediaBufferDecoder
283 *************************************************************/
287 BMediaBufferDecoder::GetNextChunk(const void **chunkData
,
292 return B_LAST_BUFFER_ERROR
;
294 *chunkData
= fBuffer
;
295 *chunkLen
= fBufferSize
;