xref: /haiku/src/add-ons/media/plugins/raw_decoder/RawDecoderPlugin.cpp (revision 2530523976c41f4c5219b00cd5a328b84ce6d38d)
1ca16f5cbSbeveloper #include <stdio.h>
2bce1ab5eSbeveloper #include <string.h>
3ca16f5cbSbeveloper #include <DataIO.h>
4ca16f5cbSbeveloper #include "RawDecoderPlugin.h"
5ca16f5cbSbeveloper 
6ca16f5cbSbeveloper #define TRACE_THIS 1
7ca16f5cbSbeveloper #if TRACE_THIS
8ca16f5cbSbeveloper   #define TRACE printf
9ca16f5cbSbeveloper #else
10*25305239Sbeveloper   #define TRACE TRACE(a...)
11ca16f5cbSbeveloper #endif
12ca16f5cbSbeveloper 
13ca16f5cbSbeveloper 
14ca16f5cbSbeveloper status_t
15*25305239Sbeveloper RawDecoder::Setup(media_format *ioEncodedFormat,
16bce1ab5eSbeveloper 				  const void *infoBuffer, int32 infoSize)
17ca16f5cbSbeveloper {
18bce1ab5eSbeveloper 	if (ioEncodedFormat->type != B_MEDIA_RAW_AUDIO && ioEncodedFormat->type != B_MEDIA_RAW_VIDEO)
19ca16f5cbSbeveloper 		return B_ERROR;
20ca16f5cbSbeveloper 
21*25305239Sbeveloper 	fInputFormat = *ioEncodedFormat;
22*25305239Sbeveloper 
23bce1ab5eSbeveloper 	if (ioEncodedFormat->type == B_MEDIA_RAW_VIDEO)
24bce1ab5eSbeveloper 		fFrameSize = ioEncodedFormat->u.raw_video.display.line_count * ioEncodedFormat->u.raw_video.display.bytes_per_row;
25bce1ab5eSbeveloper 	else
26bce1ab5eSbeveloper 		fFrameSize = (ioEncodedFormat->u.raw_audio.format & 0xf) * ioEncodedFormat->u.raw_audio.channel_count;
27bce1ab5eSbeveloper 
28*25305239Sbeveloper 	return B_OK;
29*25305239Sbeveloper }
30bce1ab5eSbeveloper 
31*25305239Sbeveloper 
32*25305239Sbeveloper status_t
33*25305239Sbeveloper RawDecoder::NegotiateOutputFormat(media_format *ioDecodedFormat)
34*25305239Sbeveloper {
35*25305239Sbeveloper 	// BeBook says: The codec will find and return in ioFormat its best matching format
36*25305239Sbeveloper 	// => This means, we never return an error, and always change the format values
37*25305239Sbeveloper 	//    that we don't support to something more applicable
38*25305239Sbeveloper 
39*25305239Sbeveloper 	*ioDecodedFormat = fInputFormat;
40ca16f5cbSbeveloper 	return B_OK;
41ca16f5cbSbeveloper }
42ca16f5cbSbeveloper 
43ca16f5cbSbeveloper 
44ca16f5cbSbeveloper status_t
45d8591482Sbeveloper RawDecoder::Seek(uint32 seekTo,
46bce1ab5eSbeveloper 				 int64 seekFrame, int64 *frame,
47bce1ab5eSbeveloper 				 bigtime_t seekTime, bigtime_t *time)
48ca16f5cbSbeveloper {
49ca16f5cbSbeveloper 	return B_OK;
50ca16f5cbSbeveloper }
51ca16f5cbSbeveloper 
52ca16f5cbSbeveloper 
53ca16f5cbSbeveloper status_t
54ca16f5cbSbeveloper RawDecoder::Decode(void *buffer, int64 *frameCount,
55d8591482Sbeveloper 				   media_header *mediaHeader, media_decode_info *info /* = 0 */)
56ca16f5cbSbeveloper {
57bce1ab5eSbeveloper 	void *chunkBuffer;
58bce1ab5eSbeveloper 	int32 chunkSize;
59bce1ab5eSbeveloper 	if (B_OK != GetNextChunk(&chunkBuffer, &chunkSize, mediaHeader))
60bce1ab5eSbeveloper 		return B_ERROR;
61bce1ab5eSbeveloper 
62bce1ab5eSbeveloper 	memcpy(buffer, chunkBuffer, chunkSize);
63bce1ab5eSbeveloper 	*frameCount = chunkSize / fFrameSize;
64bce1ab5eSbeveloper 
65ca16f5cbSbeveloper 	return B_OK;
66ca16f5cbSbeveloper }
67ca16f5cbSbeveloper 
68ca16f5cbSbeveloper 
69ca16f5cbSbeveloper Decoder *
70ca16f5cbSbeveloper RawDecoderPlugin::NewDecoder()
71ca16f5cbSbeveloper {
72ca16f5cbSbeveloper 	return new RawDecoder;
73ca16f5cbSbeveloper }
74ca16f5cbSbeveloper 
75bce1ab5eSbeveloper status_t
76bce1ab5eSbeveloper RawDecoderPlugin::RegisterPlugin()
77bce1ab5eSbeveloper {
78da87cefeSbeveloper 	PublishDecoder("audiocodec/raw", "raw", "RAW audio decoder", "{ WAV : 0x1 }, { QT : 0x20776172, 0x736f7774, 0x74776f73 }");
79da87cefeSbeveloper 	PublishDecoder("videocodec/raw", "raw", "RAW video decoder");
80bce1ab5eSbeveloper 	return B_OK;
81bce1ab5eSbeveloper }
82ca16f5cbSbeveloper 
83ca16f5cbSbeveloper MediaPlugin *instantiate_plugin()
84ca16f5cbSbeveloper {
85ca16f5cbSbeveloper 	return new RawDecoderPlugin;
86ca16f5cbSbeveloper }
87