70 ASFGUID(
byte a0,
byte a1,
byte a2,
byte a3,
byte a4,
byte a5,
byte a6,
byte a7,
byte a8,
byte a9,
byte a10,
byte a11,
byte a12,
byte a13,
byte a14,
byte a15) {
71 id[0] = a0;
id[1] = a1;
id[2] = a2;
id[3] = a3;
72 id[4] = a4;
id[5] = a5;
id[6] = a6;
id[7] = a7;
73 id[8] = a8;
id[9] = a9;
id[10] = a10;
id[11] = a11;
74 id[12] = a12;
id[13] = a13;
id[14] = a14;
id[15] = a15;
78 return !std::memcmp(g.
id,
id, 16);
82 return std::memcmp(g.
id,
id, 16) != 0;
86 return Common::UString::format(
"%02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x",
87 id[0],
id[1],
id[2],
id[3],
id[4],
id[5],
id[6],
id[7],
id[8],
id[9],
id[10],
id[11],
id[12],
id[13],
id[14],
id[15]);
95 static const ASFGUID s_asfHeader =
ASFGUID(0x30, 0x26, 0xB2, 0x75, 0x8E, 0x66, 0xCF, 0x11, 0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C);
96 static const ASFGUID s_asfFileHeader =
ASFGUID(0xA1, 0xDC, 0xAB, 0x8C, 0x47, 0xA9, 0xCF, 0x11, 0x8E, 0xE4, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65);
97 static const ASFGUID s_asfHead1 =
ASFGUID(0xb5, 0x03, 0xbf, 0x5f, 0x2E, 0xA9, 0xCF, 0x11, 0x8e, 0xe3, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65);
98 static const ASFGUID s_asfComment =
ASFGUID(0x33, 0x26, 0xb2, 0x75, 0x8E, 0x66, 0xCF, 0x11, 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c);
99 static const ASFGUID s_asfStreamHeader =
ASFGUID(0x91, 0x07, 0xDC, 0xB7, 0xB7, 0xA9, 0xCF, 0x11, 0x8E, 0xE6, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65);
100 static const ASFGUID s_asfCodecComment =
ASFGUID(0x40, 0x52, 0xD1, 0x86, 0x1D, 0x31, 0xD0, 0x11, 0xA3, 0xA4, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6);
101 static const ASFGUID s_asfDataHeader =
ASFGUID(0x36, 0x26, 0xb2, 0x75, 0x8E, 0x66, 0xCF, 0x11, 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c);
102 static const ASFGUID s_asfAudioStream =
ASFGUID(0x40, 0x9E, 0x69, 0xF8, 0x4D, 0x5B, 0xCF, 0x11, 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B);
103 static const ASFGUID s_asfExtendedHeader =
ASFGUID(0x40, 0xA4, 0xD0, 0xD2, 0x07, 0xE3, 0xD2, 0x11, 0x97, 0xF0, 0x00, 0xA0, 0xC9, 0x5E, 0xA8, 0x50);
104 static const ASFGUID s_asfStreamBitRate =
ASFGUID(0xce, 0x75, 0xf8, 0x7b, 0x8d, 0x46, 0xd1, 0x11, 0x8d, 0x82, 0x00, 0x60, 0x97, 0xc9, 0xa2, 0xb2);
137 std::vector<Common::SeekableReadStream *>
data;
179 for (
size_t i = 0; i < segments.size(); i++)
180 for (
size_t j = 0; j < segments[i].data.size(); j++)
181 delete segments[i].data[j];
205 size_t startPos =
_stream->pos();
233 _stream->seek(startPos + size);
266 throw Common::Exception(
"ASFStream::parseStreamHeader(): Multiple stream headers found");
271 throw Common::Exception(
"ASFStream::parseStreamHeader(): Found non-audio stream");
288 if (typeSpecificSize >= 18) {
290 cbSize = MIN<int>(cbSize, typeSpecificSize - 18);
325 size_t packetStartPos =
_stream->pos();
328 if (
_stream->readByte() != 0x82)
331 if (
_stream->readUint16LE() != 0)
340 if (packet->
flags & 0x10)
341 paddingSize =
_stream->readUint16LE();
342 else if (packet->
flags & 0x08)
343 paddingSize =
_stream->readByte();
349 packet->
segments.resize(segmentCount & 0x3F);
359 uint32 fragmentOffset = 0;
361 fragmentOffset =
_stream->readByte();
363 fragmentOffset =
_stream->readUint16LE();
365 fragmentOffset =
_stream->readUint32LE();
375 size_t startObjectPos =
_stream->pos();
377 while (
_stream->pos() < dataLength + startObjectPos)
379 }
else if (flags == 8) {
383 size_t dataLength = 0;
386 else if (segmentCount & 0x40)
387 dataLength =
_stream->readByte();
389 dataLength =
_stream->readUint16LE();
392 segment.
data.push_back(
_stream->readStream(dataLength));
394 throw Common::Exception(
"ASFStream::readPacket(): Unknown packet flags 0x%02x", flags);
424 if (packet->segments.size() != 1)
425 throw Common::Exception(
"ASFStream::feedAudioData(): Only single segment packets supported");
431 throw Common::Exception(
"ASFStream::feedAudioData(): Packet stream ID mismatch");
435 throw Common::Exception(
"ASFStream::feedAudioData(): Only one sequence number per packet supported");
441 if (segment.
data.size() != 1)
442 throw Common::Exception(
"ASFStream::feedAudioData(): Packet grouping not supported");
451 size_t samplesDecoded = 0;
455 const size_t n =
_curAudioStream->readBuffer(buffer + samplesDecoded, numSamples - samplesDecoded);
470 return samplesDecoded;
482 return new ASFStream(stream, disposeAfterUse);
bool rewind()
Rewinds the stream to its start.
static const ASFGUID s_asfStreamHeader
ASFGUID(Common::SeekableReadStream &stream)
Common::DisposablePtr< Common::SeekableReadStream > _stream
static const ASFGUID s_asfFileHeader
A class holding an UTF-8 string.
uint64 getLength() const
Estimate the total number of samples per channel in this stream.
void reset(PointerType o=0)
Resets the pointer with the new value.
std::vector< Segment > segments
Implementing the reading stream interfaces for plain memory blocks.
static const ASFGUID s_asfHeader
int getRate() const
Sample rate of the stream.
Compression types in Microsoft's WAVEFORMAT(EX).
RewindableAudioStream * makeASFStream(Common::SeekableReadStream *stream, bool disposeAfterUse)
Try to load a ASF from the given seekable stream and create a RewindableAudioStream from that data...
size_t readBuffer(int16 *buffer, const size_t numSamples)
Fill the given buffer with up to numSamples samples.
int getChannels() const
Return the number channels in this stream.
Exception that provides a stack of explanations.
A simple scoped smart pointer template.
Common::ScopedPtr< PacketizedAudioStream > _curAudioStream
Basic exceptions to throw.
A rewindable audio stream.
const char * c_str() const
Return the (utf8 encoded) string data.
bool operator!=(const ASFGUID &g) const
static UString format(const char *s,...) GCC_PRINTF(1
Print formatted data into an UString object, similar to sprintf().
ASFStream(Common::SeekableReadStream *stream, bool dispose)
Utility templates and functions.
static const size_t kSizeInvalid
An AudioStream designed to work in terms of packets.
Common::UString toString() const
virtual size_t read(void *dataPtr, size_t dataSize)=0
Read data from the stream.
A scoped plain pointer, allowing pointer-y access and normal deletion.
Common::ScopedPtr< Common::SeekableReadStream > _extraData
void warning(const char *s,...)
static const ASFGUID s_asfHead1
static const ASFGUID s_asfCodecComment
Decoding Microsoft's Windows Media Audio.
bool allDataLoaded() const
bool operator==(const ASFGUID &g) const
static const ASFGUID s_asfComment
A smart pointer with a deletion flag.
uint16 _bitsPerCodedSample
uint64 getDuration() const
Estimate the total duration of the stream in milliseconds.
std::vector< Common::SeekableReadStream * > data
bool endOfData() const
End of data reached? If this returns true, it means that at this time there is no data available in t...
ASFGUID(byte a0, byte a1, byte a2, byte a3, byte a4, byte a5, byte a6, byte a7, byte a8, byte a9, byte a10, byte a11, byte a12, byte a13, byte a14, byte a15)
Decoding Microsoft's Advanced Streaming Format.
PacketizedAudioStream * createAudioStream()
static const ASFGUID s_asfAudioStream
PacketizedAudioStream * makeWMAStream(int version, uint32 sampleRate, uint8 channels, uint32 bitRate, uint32 blockAlign, Common::SeekableReadStream &extraData)
Create a PacketizedAudioStream that decodes WMA sound.
static const ASFGUID s_asfStreamBitRate
Interface for a seekable & readable data stream.
static const ASFGUID s_asfDataHeader
static const ASFGUID s_asfExtendedHeader