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 1025305239Sbeveloper #define TRACE TRACE(a...) 11ca16f5cbSbeveloper #endif 12ca16f5cbSbeveloper 13ca16f5cbSbeveloper 14ca16f5cbSbeveloper status_t 1525305239Sbeveloper 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 2125305239Sbeveloper fInputFormat = *ioEncodedFormat; 2225305239Sbeveloper 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 2825305239Sbeveloper return B_OK; 2925305239Sbeveloper } 30bce1ab5eSbeveloper 3125305239Sbeveloper 3225305239Sbeveloper status_t 3325305239Sbeveloper RawDecoder::NegotiateOutputFormat(media_format *ioDecodedFormat) 3425305239Sbeveloper { 3525305239Sbeveloper // BeBook says: The codec will find and return in ioFormat its best matching format 3625305239Sbeveloper // => This means, we never return an error, and always change the format values 3725305239Sbeveloper // that we don't support to something more applicable 3825305239Sbeveloper 39*4ba72fcdSbeveloper char s[1024]; 40*4ba72fcdSbeveloper 41*4ba72fcdSbeveloper string_for_format(*ioDecodedFormat, s, sizeof(s)); 42*4ba72fcdSbeveloper printf("RawDecoder::NegotiateOutputFormat enter: %s\n", s); 43*4ba72fcdSbeveloper 4425305239Sbeveloper *ioDecodedFormat = fInputFormat; 45*4ba72fcdSbeveloper 46*4ba72fcdSbeveloper string_for_format(*ioDecodedFormat, s, sizeof(s)); 47*4ba72fcdSbeveloper printf("RawDecoder::NegotiateOutputFormat leave: %s\n", s); 48*4ba72fcdSbeveloper 49ca16f5cbSbeveloper return B_OK; 50ca16f5cbSbeveloper } 51ca16f5cbSbeveloper 52ca16f5cbSbeveloper 53ca16f5cbSbeveloper status_t 54d8591482Sbeveloper RawDecoder::Seek(uint32 seekTo, 55bce1ab5eSbeveloper int64 seekFrame, int64 *frame, 56bce1ab5eSbeveloper bigtime_t seekTime, bigtime_t *time) 57ca16f5cbSbeveloper { 58ca16f5cbSbeveloper return B_OK; 59ca16f5cbSbeveloper } 60ca16f5cbSbeveloper 61ca16f5cbSbeveloper 62ca16f5cbSbeveloper status_t 63ca16f5cbSbeveloper RawDecoder::Decode(void *buffer, int64 *frameCount, 64d8591482Sbeveloper media_header *mediaHeader, media_decode_info *info /* = 0 */) 65ca16f5cbSbeveloper { 66bce1ab5eSbeveloper void *chunkBuffer; 67bce1ab5eSbeveloper int32 chunkSize; 68bce1ab5eSbeveloper if (B_OK != GetNextChunk(&chunkBuffer, &chunkSize, mediaHeader)) 69bce1ab5eSbeveloper return B_ERROR; 70bce1ab5eSbeveloper 71bce1ab5eSbeveloper memcpy(buffer, chunkBuffer, chunkSize); 72bce1ab5eSbeveloper *frameCount = chunkSize / fFrameSize; 73bce1ab5eSbeveloper 74ca16f5cbSbeveloper return B_OK; 75ca16f5cbSbeveloper } 76ca16f5cbSbeveloper 77ca16f5cbSbeveloper 78ca16f5cbSbeveloper Decoder * 79ca16f5cbSbeveloper RawDecoderPlugin::NewDecoder() 80ca16f5cbSbeveloper { 81ca16f5cbSbeveloper return new RawDecoder; 82ca16f5cbSbeveloper } 83ca16f5cbSbeveloper 84bce1ab5eSbeveloper status_t 85bce1ab5eSbeveloper RawDecoderPlugin::RegisterPlugin() 86bce1ab5eSbeveloper { 87da87cefeSbeveloper PublishDecoder("audiocodec/raw", "raw", "RAW audio decoder", "{ WAV : 0x1 }, { QT : 0x20776172, 0x736f7774, 0x74776f73 }"); 88da87cefeSbeveloper PublishDecoder("videocodec/raw", "raw", "RAW video decoder"); 89bce1ab5eSbeveloper return B_OK; 90bce1ab5eSbeveloper } 91ca16f5cbSbeveloper 92ca16f5cbSbeveloper MediaPlugin *instantiate_plugin() 93ca16f5cbSbeveloper { 94ca16f5cbSbeveloper return new RawDecoderPlugin; 95ca16f5cbSbeveloper } 96