void ASFStream::parseStreamHeader() { ASFGUID guid = ASFGUID(*_stream); if (guid != s_asfAudioStream) throw Common::Exception("ASFStream::parseStreamHeader(): Found non-audio stream"); _stream->skip(16); // skip a guid _stream->readUint64LE(); // total size uint32 typeSpecificSize = _stream->readUint32LE(); _stream->readUint32LE(); _streamID = _stream->readUint16LE(); _stream->readUint32LE(); // Parse the wave header _compression = _stream->readUint16LE(); _channels = _stream->readUint16LE(); _sampleRate = _stream->readUint32LE(); _bitRate = _stream->readUint32LE() * 8; _blockAlign = _stream->readUint16LE(); _bitsPerCodedSample = (typeSpecificSize == 14) ? 8 : _stream->readUint16LE(); if (typeSpecificSize >= 18) { uint32 cbSize = _stream->readUint16LE(); cbSize = MIN<int>(cbSize, typeSpecificSize - 18); _extraData = _stream->readStream(cbSize); } _codec = createCodec(); }
void ERFFile::readV3ResList(Common::SeekableReadStream &erf, const ERFHeader &header) { if (!erf.seek(header.offResList)) throw Common::Exception(Common::kSeekError); uint32 index = 0; ResourceList::iterator res = _resources.begin(); IResourceList::iterator iRes = _iResources.begin(); for (; (res != _resources.end()) && (iRes != _iResources.end()); ++index, ++res, ++iRes) { int32 nameOffset = erf.readSint32LE(); if (nameOffset >= 0) { if ((uint32)nameOffset >= header.stringTableSize) throw Common::Exception("Invalid ERF string table offset"); Common::UString name = header.stringTable + nameOffset; res->name = TypeMan.setFileType(name, kFileTypeNone); res->type = TypeMan.getFileType(name); } res->index = index; res->hash = erf.readUint64LE(); uint32 typeHash = erf.readUint32LE(); // Look up the file type by its hash FileType type = TypeMan.getFileType(Common::kHashFNV32, typeHash); if (type != kFileTypeNone) res->type = type; iRes->offset = erf.readUint32LE(); iRes->packedSize = erf.readUint32LE(); iRes->unpackedSize = erf.readUint32LE(); } }
int64 GFF4Struct::getSint(Common::SeekableReadStream &data, IFieldType type) const { switch (type) { case kIFieldTypeUint8: return (int64) ((uint64) data.readByte()); case kIFieldTypeSint8: return (int64) data.readSByte(); case kIFieldTypeUint16: return (int64) ((uint64) data.readUint16LE()); case kIFieldTypeSint16: return (int64) data.readSint16LE(); case kIFieldTypeUint32: return (int64) ((uint64) data.readUint32LE()); case kIFieldTypeSint32: return (int64) data.readSint32LE(); case kIFieldTypeUint64: return (int64) ((uint64) data.readUint64LE()); case kIFieldTypeSint64: return (int64) data.readSint64LE(); default: break; } throw Common::Exception("GFF4: Field is not an int type"); }
void ASFStream::load() { ASFGUID guid = ASFGUID(*_stream); if (guid != s_asfHeader) throw Common::Exception("ASFStream: Missing asf header"); _stream->readUint64LE(); _stream->readUint32LE(); _stream->readByte(); _stream->readByte(); for (;;) { size_t startPos = _stream->pos(); guid = ASFGUID(*_stream); uint64 size = _stream->readUint64LE(); if (_stream->eos()) throw Common::Exception("ASFStream: Unexpected eos"); // TODO: Parse each chunk if (guid == s_asfFileHeader) { parseFileHeader(); } else if (guid == s_asfHead1) { // Should be safe to ignore } else if (guid == s_asfComment) { // Ignored } else if (guid == s_asfStreamHeader) { parseStreamHeader(); } else if (guid == s_asfCodecComment) { // TODO } else if (guid == s_asfDataHeader) { // Done parsing the header break; } else if (guid == s_asfExtendedHeader) { // TODO } else if (guid == s_asfStreamBitRate) { // Ignored } else warning("Found unknown ASF GUID: %s", guid.toString().c_str()); _stream->seek(startPos + size); } // Skip to the beginning of the packets _stream->skip(26); _rewindPos = _stream->pos(); }
void ASFStream::parseFileHeader() { _stream->skip(16); // skip client GUID /* uint64 fileSize = */ _stream->readUint64LE(); /* uint64 creationTime = */ _stream->readUint64LE(); _packetCount = _stream->readUint64LE(); /* uint64 endTimestamp = */ _stream->readUint64LE(); _duration = _stream->readUint64LE(); /* uint32 startTimestamp = */ _stream->readUint32LE(); /* uint32 unknown = */ _stream->readUint32LE(); /* uint32 flags = */ _stream->readUint32LE(); _minPacketSize = _stream->readUint32LE(); _maxPacketSize = _stream->readUint32LE(); /* uint32 uncFrameSize = */ _stream->readUint32LE(); // We only know how to support packets of one length if (_minPacketSize != _maxPacketSize) throw Common::Exception("ASFStream::parseFileHeader(): Mismatched packet sizes: Min = %d, Max = %d", _minPacketSize, _maxPacketSize); }