3rdparty/licenseReport: Add seperate LGPL checks
[haiku.git] / src / add-ons / media / plugins / musepack / MusePackReader.cpp
blob01747cb367922cf9815fc7719299f3dbec914eb4
1 /*
2 ** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 ** Distributed under the terms of the MIT License.
4 */
7 #include "MusePackReader.h"
9 #include <InterfaceDefs.h>
10 #include <stdio.h>
11 #include <string.h>
14 //#define TRACE_MUSEPACK_READER
15 #ifdef TRACE_MUSEPACK_READER
16 #define TRACE printf
17 #else
18 #define TRACE(a...)
19 #endif
22 MusePackReader::MusePackReader()
27 MusePackReader::~MusePackReader()
32 const char *
33 MusePackReader::Copyright()
35 return "MusePack reader, " B_UTF8_COPYRIGHT " by Axel Dörfler";
39 status_t
40 MusePackReader::Sniff(int32 *_streamCount)
42 BPositionIO *file = dynamic_cast<BPositionIO *>(Source());
43 if (file == NULL)
44 // we cannot handle non seekable files for now
45 return B_ERROR;
47 file->Seek(0, SEEK_SET);
48 int error = fInfo.ReadStreamInfo(file);
49 if (error > B_OK) {
50 // error came from engine
51 TRACE("MusePackReader: ReadStreamInfo() engine error %d\n", error);
52 return B_ERROR;
53 } else if (error < B_OK)
54 return error;
56 TRACE("MusePackReader: recognized MPC file\n");
57 *_streamCount = 1;
58 return B_OK;
62 void
63 MusePackReader::GetFileFormatInfo(media_file_format *mff)
66 mff->capabilities = media_file_format::B_READABLE
67 | media_file_format::B_KNOWS_ENCODED_AUDIO
68 | media_file_format::B_IMPERFECTLY_SEEKABLE;
69 mff->family = B_MISC_FORMAT_FAMILY;
70 mff->version = 100;
71 strcpy(mff->mime_type, "audio/x-mpc");
72 strcpy(mff->file_extension, "mpc");
73 strcpy(mff->short_name, "MusePack");
74 strcpy(mff->pretty_name, "MusePack");
78 status_t
79 MusePackReader::AllocateCookie(int32 streamNumber, void **_cookie)
81 // we don't need a cookie - we only know one single stream
82 *_cookie = NULL;
84 media_format_description description;
85 description.family = B_MISC_FORMAT_FAMILY;
86 description.u.misc.file_format = 'mpc ';
87 description.u.misc.codec = 'MPC7';
88 // 7 is the most recent stream version
90 status_t status = BMediaFormats().GetFormatFor(description, &fFormat);
91 if (status < B_OK)
92 return status;
94 // allocate and initialize internal decoder
95 fDecoder = new MPC_decoder(static_cast<BPositionIO *>(Source()));
96 fDecoder->RESET_Globals();
97 fDecoder->RESET_Synthesis();
98 fDecoder->SetStreamInfo(&fInfo);
99 if (!fDecoder->FileInit()) {
100 delete fDecoder;
101 fDecoder = 0;
102 return B_ERROR;
105 #if 0 // not required to report
106 fFormat.u.encoded_audio.output.frame_rate = fInfo.simple.SampleFreq;
107 fFormat.u.encoded_audio.output.channel_count = fInfo.simple.Channels;
108 fFormat.u.encoded_audio.output.format = media_raw_audio_format::B_AUDIO_FLOAT;
109 fFormat.u.encoded_audio.output.byte_order = B_MEDIA_HOST_ENDIAN;
110 fFormat.u.encoded_audio.output.buffer_size = sizeof(MPC_SAMPLE_FORMAT) * FRAMELEN * 2;
111 #endif
113 return B_OK;
117 status_t
118 MusePackReader::FreeCookie(void *cookie)
120 // nothing to do here
121 return B_OK;
125 status_t
126 MusePackReader::GetStreamInfo(void *cookie, int64 *_frameCount, bigtime_t *_duration,
127 media_format *format, const void **_infoBuffer, size_t *_infoSize)
129 if (cookie != NULL)
130 return B_BAD_VALUE;
132 *_frameCount = FRAMELEN * (int64)fInfo.simple.Frames;
133 *_duration = bigtime_t(1000.0 * fInfo.simple.Frames * FRAMELEN
134 / (fInfo.simple.SampleFreq / 1000.0) + 0.5);
136 *format = fFormat;
138 // we provide the stream info in this place
139 *_infoBuffer = (void *)fDecoder;
140 *_infoSize = sizeof(MPC_decoder);
142 return B_OK;
146 status_t
147 MusePackReader::Seek(void *cookie, uint32 seekTo, int64 *frame, bigtime_t *time)
149 // we don't care, let the decoder do the work...
150 // (MPC not really differentiates between decoder and container)
151 return B_OK;
155 status_t
156 MusePackReader::GetNextChunk(void *cookie, const void **chunkBuffer, size_t *chunkSize,
157 media_header *mediaHeader)
159 // this one will never be called by our decoder
160 return B_ERROR;