Code Cleanup

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13927 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
David McPaul 2005-08-10 10:46:25 +00:00
parent 13d77a4cde
commit 6108dafc2a
11 changed files with 544 additions and 369 deletions

View File

@ -124,9 +124,11 @@ bool AtomBase::IsKnown()
void AtomBase::ReadArrayHeader(array_header *pHeader) void AtomBase::ReadArrayHeader(array_header *pHeader)
{ {
getStream()->Read(pHeader,sizeof(array_header)); Read(&pHeader->Version);
Read(&pHeader->Flags1);
pHeader->NoEntries = B_BENDIAN_TO_HOST_INT32(pHeader->NoEntries); Read(&pHeader->Flags2);
Read(&pHeader->Flags3);
Read(&pHeader->NoEntries);
} }
BPositionIO *AtomBase::OnGetStream() BPositionIO *AtomBase::OnGetStream()
@ -140,6 +142,66 @@ BPositionIO *AtomBase::getStream()
return OnGetStream(); return OnGetStream();
} }
void AtomBase::Read(uint64 *value)
{
uint32 bytes_read;
bytes_read = getStream()->Read(value,sizeof(uint64));
// Assert((bytes_read == sizeof(uint64),"Read Error");
*value = B_BENDIAN_TO_HOST_INT64(*value);
}
void AtomBase::Read(uint32 *value)
{
uint32 bytes_read;
bytes_read = getStream()->Read(value,sizeof(uint32));
// Assert((bytes_read == sizeof(uint32),"Read Error");
*value = B_BENDIAN_TO_HOST_INT32(*value);
}
void AtomBase::Read(uint16 *value)
{
uint32 bytes_read;
bytes_read = getStream()->Read(value,sizeof(uint16));
// Assert((bytes_read == sizeof(uint16),"Read Error");
*value = B_BENDIAN_TO_HOST_INT16(*value);
}
void AtomBase::Read(uint8 *value)
{
uint32 bytes_read;
bytes_read = getStream()->Read(value,sizeof(uint8));
// Assert((bytes_read == sizeof(uint8),"Read Error");
}
void AtomBase::Read(char *value, uint32 maxread)
{
uint32 bytes_read;
bytes_read = getStream()->Read(value,maxread);
// Assert((bytes_read == maxread,"Read Error");
}
void AtomBase::Read(uint8 *value, uint32 maxread)
{
uint32 bytes_read;
bytes_read = getStream()->Read(value,maxread);
// Assert((bytes_read == maxread,"Read Error");
}
AtomContainer::AtomContainer(BPositionIO *pStream, off_t pstreamOffset, uint32 patomType, uint64 patomSize) : AtomBase(pStream, pstreamOffset, patomType, patomSize) AtomContainer::AtomContainer(BPositionIO *pStream, off_t pstreamOffset, uint32 patomType, uint64 patomSize) : AtomBase(pStream, pstreamOffset, patomType, patomSize)
{ {
TotalChildren = 0; TotalChildren = 0;

View File

@ -132,6 +132,13 @@ public:
void setParent(AtomBase *pParent) {parentAtom = pParent;}; void setParent(AtomBase *pParent) {parentAtom = pParent;};
AtomBase *getParent() { return parentAtom;}; AtomBase *getParent() { return parentAtom;};
void Read(uint64 *value);
void Read(uint32 *value);
void Read(uint16 *value);
void Read(uint8 *value);
void Read(char *value, uint32 maxread);
void Read(uint8 *value, uint32 maxread);
}; };
class AtomContainer : public AtomBase { class AtomContainer : public AtomBase {

View File

@ -555,25 +555,6 @@ uint32 MOVFileReader::getChunkSize(uint32 stream_index, uint32 pFrameNo)
uint32 ChunkNo = pFrameNo; uint32 ChunkNo = pFrameNo;
off_t Chunk_Start = aTrakAtom->getOffsetForChunk(ChunkNo); off_t Chunk_Start = aTrakAtom->getOffsetForChunk(ChunkNo);
uint32 ChunkSize = ChunkSize = theChunkSuperIndex.getChunkSize(stream_index,ChunkNo,Chunk_Start); uint32 ChunkSize = ChunkSize = theChunkSuperIndex.getChunkSize(stream_index,ChunkNo,Chunk_Start);
uint32 NoSamples = aTrakAtom->getNoSamplesInChunk(ChunkNo);
uint32 TotalSampleSize = 0;
// Get first sample in chunk
uint32 SampleNo = aTrakAtom->getFirstSampleInChunk(ChunkNo);
if (aTrakAtom->IsSingleSampleSize()) {
TotalSampleSize = NoSamples * aTrakAtom->getSizeForSample(SampleNo);
} else {
// Add up all sample sizes in chunk
for (uint32 i=0;i<NoSamples;i++) {
TotalSampleSize += aTrakAtom->getSizeForSample(SampleNo);
SampleNo++;
}
}
TotalSampleSize = TotalSampleSize * aTrakAtom->getBytesPerSample();
// printf("[%ld] start %lld, size %ld NoSamples %ld TotalSampleSize %ld\n",ChunkNo,Chunk_Start,ChunkSize,NoSamples,TotalSampleSize);
return ChunkSize; return ChunkSize;
} }

View File

@ -28,8 +28,11 @@
#include <SupportKit.h> #include <SupportKit.h>
#include <MediaFormats.h> #include <MediaFormats.h>
#ifdef __HAIKU__
#include <libs/zlib/zlib.h> #include <libs/zlib/zlib.h>
//#include <zlib.h> #else
#include <zlib.h>
#endif
#include "MOVParser.h" #include "MOVParser.h"
@ -316,9 +319,7 @@ DCOMAtom::~DCOMAtom()
void DCOMAtom::OnProcessMetaData() void DCOMAtom::OnProcessMetaData()
{ {
theStream->Read(&compressionID,sizeof(uint32)); Read(&compressionID);
compressionID = B_BENDIAN_TO_HOST_INT32(compressionID);
} }
char *DCOMAtom::OnGetAtomName() char *DCOMAtom::OnGetAtomName()
@ -342,14 +343,12 @@ CMVDAtom::~CMVDAtom()
void CMVDAtom::OnProcessMetaData() void CMVDAtom::OnProcessMetaData()
{ {
theStream->Read(&UncompressedSize,sizeof(uint32)); Read(&UncompressedSize);
UncompressedSize = B_BENDIAN_TO_HOST_INT32(UncompressedSize);
if (UncompressedSize > 0) { if (UncompressedSize > 0) {
BufferSize = getBytesRemaining(); BufferSize = getBytesRemaining();
Buffer = (uint8 *)(malloc(BufferSize)); Buffer = (uint8 *)(malloc(BufferSize));
theStream->Read(Buffer,BufferSize); Read(Buffer,BufferSize);
} }
} }
@ -368,22 +367,19 @@ MVHDAtom::~MVHDAtom()
void MVHDAtom::OnProcessMetaData() void MVHDAtom::OnProcessMetaData()
{ {
theStream->Read(&theHeader,sizeof(mvhd)); Read(&theHeader.CreationTime);
Read(&theHeader.ModificationTime);
theHeader.CreationTime = B_BENDIAN_TO_HOST_INT32(theHeader.CreationTime); Read(&theHeader.TimeScale);
theHeader.ModificationTime = B_BENDIAN_TO_HOST_INT32(theHeader.ModificationTime); Read(&theHeader.Duration);
theHeader.TimeScale = B_BENDIAN_TO_HOST_INT32(theHeader.TimeScale); Read(&theHeader.PreferredRate);
theHeader.Duration = B_BENDIAN_TO_HOST_INT32(theHeader.Duration); Read(&theHeader.PreferredVolume);
theHeader.PreferredRate = B_BENDIAN_TO_HOST_INT32(theHeader.PreferredRate); Read(&theHeader.PreviewTime);
theHeader.PreferredVolume = B_BENDIAN_TO_HOST_INT16(theHeader.PreferredVolume); Read(&theHeader.PreviewDuration);
theHeader.PreviewTime = B_BENDIAN_TO_HOST_INT32(theHeader.PreviewTime); Read(&theHeader.PosterTime);
theHeader.PreviewDuration = B_BENDIAN_TO_HOST_INT32(theHeader.PreviewDuration); Read(&theHeader.SelectionTime);
theHeader.PosterTime = B_BENDIAN_TO_HOST_INT32(theHeader.PosterTime); Read(&theHeader.SelectionDuration);
theHeader.SelectionTime = B_BENDIAN_TO_HOST_INT32(theHeader.SelectionTime); Read(&theHeader.CurrentTime);
theHeader.SelectionDuration = B_BENDIAN_TO_HOST_INT32(theHeader.SelectionDuration); Read(&theHeader.NextTrackID);
theHeader.CurrentTime = B_BENDIAN_TO_HOST_INT32(theHeader.CurrentTime);
theHeader.NextTrackID = B_BENDIAN_TO_HOST_INT32(theHeader.NextTrackID);
} }
char *MVHDAtom::OnGetAtomName() char *MVHDAtom::OnGetAtomName()
@ -428,9 +424,8 @@ TimeToSample *aTimeToSample;
for (uint32 i=0;i<theHeader.NoEntries;i++) { for (uint32 i=0;i<theHeader.NoEntries;i++) {
aTimeToSample = new TimeToSample; aTimeToSample = new TimeToSample;
theStream->Read(aTimeToSample,sizeof(TimeToSample)); Read(&aTimeToSample->Count);
aTimeToSample->Count = B_BENDIAN_TO_HOST_INT32(aTimeToSample->Count); Read(&aTimeToSample->Duration);
aTimeToSample->Duration = B_BENDIAN_TO_HOST_INT32(aTimeToSample->Duration);
theTimeToSampleArray[i] = aTimeToSample; theTimeToSampleArray[i] = aTimeToSample;
SUMDurations += (theTimeToSampleArray[i]->Duration * theTimeToSampleArray[i]->Count); SUMDurations += (theTimeToSampleArray[i]->Duration * theTimeToSampleArray[i]->Count);
@ -483,24 +478,20 @@ SampleToChunk *aSampleToChunk;
ReadArrayHeader(&theHeader); ReadArrayHeader(&theHeader);
uint32 TotalPrevFrames = 0; uint32 TotalPrevSamples = 0;
for (uint32 i=0;i<theHeader.NoEntries;i++) { for (uint32 i=0;i<theHeader.NoEntries;i++) {
aSampleToChunk = new SampleToChunk; aSampleToChunk = new SampleToChunk;
theStream->Read(&aSampleToChunk->FirstChunk,sizeof(uint32)); Read(&aSampleToChunk->FirstChunk);
theStream->Read(&aSampleToChunk->SamplesPerChunk,sizeof(uint32)); Read(&aSampleToChunk->SamplesPerChunk);
theStream->Read(&aSampleToChunk->SampleDescriptionID,sizeof(uint32)); Read(&aSampleToChunk->SampleDescriptionID);
aSampleToChunk->FirstChunk = B_BENDIAN_TO_HOST_INT32(aSampleToChunk->FirstChunk);
aSampleToChunk->SamplesPerChunk = B_BENDIAN_TO_HOST_INT32(aSampleToChunk->SamplesPerChunk);
aSampleToChunk->SampleDescriptionID = B_BENDIAN_TO_HOST_INT32(aSampleToChunk->SampleDescriptionID);
if (i > 0) { if (i > 0) {
TotalPrevFrames = TotalPrevFrames + (aSampleToChunk->FirstChunk - theSampleToChunkArray[i-1]->FirstChunk) * theSampleToChunkArray[i-1]->SamplesPerChunk; TotalPrevSamples = TotalPrevSamples + (aSampleToChunk->FirstChunk - theSampleToChunkArray[i-1]->FirstChunk) * theSampleToChunkArray[i-1]->SamplesPerChunk;
aSampleToChunk->TotalPrevFrames = TotalPrevFrames; aSampleToChunk->TotalPrevSamples = TotalPrevSamples;
} else { } else {
aSampleToChunk->TotalPrevFrames = 0; aSampleToChunk->TotalPrevSamples = 0;
} }
theSampleToChunkArray[i] = aSampleToChunk; theSampleToChunkArray[i] = aSampleToChunk;
@ -516,7 +507,6 @@ uint32 STSCAtom::getNoSamplesInChunk(uint32 pChunkID)
{ {
for (uint32 i=0;i<theHeader.NoEntries;i++) { for (uint32 i=0;i<theHeader.NoEntries;i++) {
if (theSampleToChunkArray[i]->FirstChunk > pChunkID) { if (theSampleToChunkArray[i]->FirstChunk > pChunkID) {
// printf("Chunk %ld contains %ld samples\n",pChunkID, theSampleToChunkArray[i-1]->SamplesPerChunk);
return theSampleToChunkArray[i-1]->SamplesPerChunk; return theSampleToChunkArray[i-1]->SamplesPerChunk;
} }
} }
@ -526,15 +516,17 @@ uint32 STSCAtom::getNoSamplesInChunk(uint32 pChunkID)
uint32 STSCAtom::getFirstSampleInChunk(uint32 pChunkID) uint32 STSCAtom::getFirstSampleInChunk(uint32 pChunkID)
{ {
uint32 Diff;
for (uint32 i=0;i<theHeader.NoEntries;i++) { for (uint32 i=0;i<theHeader.NoEntries;i++) {
if (theSampleToChunkArray[i]->FirstChunk > pChunkID) { if (theSampleToChunkArray[i]->FirstChunk > pChunkID) {
uint32 Diff = pChunkID - theSampleToChunkArray[i-1]->FirstChunk; Diff = pChunkID - theSampleToChunkArray[i-1]->FirstChunk;
uint32 pSampleNo = (Diff * theSampleToChunkArray[i-1]->SamplesPerChunk) + theSampleToChunkArray[i-1]->TotalPrevFrames; return ((Diff * theSampleToChunkArray[i-1]->SamplesPerChunk) + theSampleToChunkArray[i-1]->TotalPrevSamples);
return pSampleNo;
} }
} }
return 0; Diff = pChunkID - theSampleToChunkArray[theHeader.NoEntries-1]->FirstChunk;
return ((Diff * theSampleToChunkArray[theHeader.NoEntries-1]->SamplesPerChunk) + theSampleToChunkArray[theHeader.NoEntries-1]->TotalPrevSamples);
} }
uint32 STSCAtom::getChunkForSample(uint32 pSample, uint32 *pOffsetInChunk) uint32 STSCAtom::getChunkForSample(uint32 pSample, uint32 *pOffsetInChunk)
@ -543,12 +535,12 @@ uint32 STSCAtom::getChunkForSample(uint32 pSample, uint32 *pOffsetInChunk)
uint32 OffsetInChunk = 0; uint32 OffsetInChunk = 0;
for (int32 i=theHeader.NoEntries-1;i>=0;i--) { for (int32 i=theHeader.NoEntries-1;i>=0;i--) {
if (pSample >= theSampleToChunkArray[i]->TotalPrevFrames) { if (pSample >= theSampleToChunkArray[i]->TotalPrevSamples) {
// Found chunk now calculate offset // Found chunk now calculate offset
ChunkID = (pSample - theSampleToChunkArray[i]->TotalPrevFrames) / theSampleToChunkArray[i]->SamplesPerChunk; ChunkID = (pSample - theSampleToChunkArray[i]->TotalPrevSamples) / theSampleToChunkArray[i]->SamplesPerChunk;
ChunkID += theSampleToChunkArray[i]->FirstChunk; ChunkID += theSampleToChunkArray[i]->FirstChunk;
OffsetInChunk = (pSample - theSampleToChunkArray[i]->TotalPrevFrames) % theSampleToChunkArray[i]->SamplesPerChunk; OffsetInChunk = (pSample - theSampleToChunkArray[i]->TotalPrevSamples) % theSampleToChunkArray[i]->SamplesPerChunk;
*pOffsetInChunk = OffsetInChunk; *pOffsetInChunk = OffsetInChunk;
return ChunkID; return ChunkID;
@ -581,9 +573,7 @@ SyncSample *aSyncSample;
for (uint32 i=0;i<theHeader.NoEntries;i++) { for (uint32 i=0;i<theHeader.NoEntries;i++) {
aSyncSample = new SyncSample; aSyncSample = new SyncSample;
theStream->Read(aSyncSample,sizeof(SyncSample)); Read(&aSyncSample->SyncSampleNo);
aSyncSample->SyncSampleNo = B_BENDIAN_TO_HOST_INT32(aSyncSample->SyncSampleNo);
theSyncSampleArray[i] = aSyncSample; theSyncSampleArray[i] = aSyncSample;
} }
} }
@ -624,22 +614,22 @@ STSZAtom::~STSZAtom()
void STSZAtom::OnProcessMetaData() void STSZAtom::OnProcessMetaData()
{ {
SampleSize *aSampleSize; SampleSizeEntry *aSampleSize;
// Just to make things difficult this is not quite a standard array header // Just to make things difficult this is not quite a standard array header
theStream->Read(&theHeader,sizeof(SampleSizeHeader)); Read(&theHeader.Version);
Read(&theHeader.Flags1);
theHeader.SampleSize = B_BENDIAN_TO_HOST_INT32(theHeader.SampleSize); Read(&theHeader.Flags2);
theHeader.NoEntries = B_BENDIAN_TO_HOST_INT32(theHeader.NoEntries); Read(&theHeader.Flags3);
Read(&theHeader.SampleSize);
Read(&theHeader.NoEntries);
// If the sample size is constant there is no array and NoEntries seems to contain bad values // If the sample size is constant there is no array and NoEntries seems to contain bad values
if (theHeader.SampleSize == 0) { if (theHeader.SampleSize == 0) {
for (uint32 i=0;i<theHeader.NoEntries;i++) { for (uint32 i=0;i<theHeader.NoEntries;i++) {
aSampleSize = new SampleSize; aSampleSize = new SampleSizeEntry;
theStream->Read(aSampleSize,sizeof(SampleSize));
aSampleSize->Size = B_BENDIAN_TO_HOST_INT32(aSampleSize->Size);
Read(&aSampleSize->EntrySize);
theSampleSizeArray[i] = aSampleSize; theSampleSizeArray[i] = aSampleSize;
} }
} }
@ -659,7 +649,7 @@ uint32 STSZAtom::getSizeForSample(uint32 pSampleNo)
} }
// Sample Array indexed by SampleNo // Sample Array indexed by SampleNo
return theSampleSizeArray[pSampleNo]->Size; return theSampleSizeArray[pSampleNo]->EntrySize;
} }
bool STSZAtom::IsSingleSampleSize() bool STSZAtom::IsSingleSampleSize()
@ -684,10 +674,10 @@ uint64 STCOAtom::OnGetChunkOffset()
{ {
uint32 Offset; uint32 Offset;
theStream->Read(&Offset,sizeof(uint32)); Read(&Offset);
// Upconvert to uint64 // Upconvert to uint64
return uint64(B_BENDIAN_TO_HOST_INT32(Offset)); return uint64(Offset);
} }
void STCOAtom::OnProcessMetaData() void STCOAtom::OnProcessMetaData()
@ -722,7 +712,7 @@ uint64 STCOAtom::getOffsetForChunk(uint32 pChunkID)
DEBUGGER(("Bad Chunk ID %ld / %ld\n",pChunkID,theHeader.NoEntries)); DEBUGGER(("Bad Chunk ID %ld / %ld\n",pChunkID,theHeader.NoEntries));
TRESPASS(); TRESPASS();
return -1LL; return 0LL;
} }
STSDAtom::STSDAtom(BPositionIO *pStream, off_t pstreamOffset, uint32 patomType, uint64 patomSize) : AtomBase(pStream, pstreamOffset, patomType, patomSize) STSDAtom::STSDAtom(BPositionIO *pStream, off_t pstreamOffset, uint32 patomType, uint64 patomSize) : AtomBase(pStream, pstreamOffset, patomType, patomSize)
@ -752,53 +742,38 @@ uint32 STSDAtom::getMediaComponentSubType()
void STSDAtom::ReadSoundDescription() void STSDAtom::ReadSoundDescription()
{ {
uint32 descBytesLeft; uint64 descBytesLeft;
SoundDescriptionV1 *aSoundDescriptionV1; SoundDescriptionV1 *aSoundDescriptionV1;
aSoundDescriptionV1 = new SoundDescriptionV1; aSoundDescriptionV1 = new SoundDescriptionV1;
theStream->Read(&aSoundDescriptionV1->basefields,sizeof(SampleDescBase)); Read(&aSoundDescriptionV1->basefields.Size);
Read(&aSoundDescriptionV1->basefields.DataFormat);
aSoundDescriptionV1->basefields.Size = B_BENDIAN_TO_HOST_INT32(aSoundDescriptionV1->basefields.Size); Read(aSoundDescriptionV1->basefields.Reserved,6);
aSoundDescriptionV1->basefields.DataFormat = B_BENDIAN_TO_HOST_INT32(aSoundDescriptionV1->basefields.DataFormat); Read(&aSoundDescriptionV1->basefields.DataReference);
aSoundDescriptionV1->basefields.DataReference = B_BENDIAN_TO_HOST_INT16(aSoundDescriptionV1->basefields.DataReference);
descBytesLeft = aSoundDescriptionV1->basefields.Size - sizeof(SampleDescBase);
// Read in Audio Sample Data // Read in Audio Sample Data
// We place into a V1 description even though it might be a V0 or earlier // We place into a V1 description even though it might be a V0 or earlier
theStream->Read(&aSoundDescriptionV1->desc,sizeof(SoundDescription)); Read(&aSoundDescriptionV1->desc.Version);
descBytesLeft = descBytesLeft - sizeof(SoundDescription); Read(&aSoundDescriptionV1->desc.Revision);
Read(&aSoundDescriptionV1->desc.Vendor);
aSoundDescriptionV1->desc.Version = B_BENDIAN_TO_HOST_INT16(aSoundDescriptionV1->desc.Version); Read(&aSoundDescriptionV1->desc.NoOfChannels);
aSoundDescriptionV1->desc.Revision = B_BENDIAN_TO_HOST_INT16(aSoundDescriptionV1->desc.Revision); Read(&aSoundDescriptionV1->desc.SampleSize);
aSoundDescriptionV1->desc.Vendor = B_BENDIAN_TO_HOST_INT32(aSoundDescriptionV1->desc.Vendor); Read(&aSoundDescriptionV1->desc.CompressionID);
aSoundDescriptionV1->desc.NoOfChannels = B_BENDIAN_TO_HOST_INT16(aSoundDescriptionV1->desc.NoOfChannels); Read(&aSoundDescriptionV1->desc.PacketSize);
aSoundDescriptionV1->desc.SampleSize = B_BENDIAN_TO_HOST_INT16(aSoundDescriptionV1->desc.SampleSize); Read(&aSoundDescriptionV1->desc.SampleRate);
aSoundDescriptionV1->desc.CompressionID = B_BENDIAN_TO_HOST_INT16(aSoundDescriptionV1->desc.CompressionID);
aSoundDescriptionV1->desc.PacketSize = B_BENDIAN_TO_HOST_INT16(aSoundDescriptionV1->desc.PacketSize);
aSoundDescriptionV1->desc.SampleRate = B_BENDIAN_TO_HOST_INT32(aSoundDescriptionV1->desc.SampleRate);
if (aSoundDescriptionV1->desc.Version == 1) { if (aSoundDescriptionV1->desc.Version == 1) {
printf("V1 Sound\n"); Read(&(aSoundDescriptionV1->samplesPerPacket));
theStream->Read(&(aSoundDescriptionV1->samplesPerPacket),4); Read(&(aSoundDescriptionV1->bytesPerPacket));
theStream->Read(&(aSoundDescriptionV1->bytesPerPacket),4); Read(&(aSoundDescriptionV1->bytesPerFrame));
theStream->Read(&(aSoundDescriptionV1->bytesPerFrame),4); Read(&(aSoundDescriptionV1->bytesPerSample));
theStream->Read(&(aSoundDescriptionV1->bytesPerSample),4);
aSoundDescriptionV1->samplesPerPacket = B_BENDIAN_TO_HOST_INT32(aSoundDescriptionV1->samplesPerPacket);
aSoundDescriptionV1->bytesPerPacket = B_BENDIAN_TO_HOST_INT32(aSoundDescriptionV1->bytesPerPacket);
aSoundDescriptionV1->bytesPerFrame = B_BENDIAN_TO_HOST_INT32(aSoundDescriptionV1->bytesPerFrame);
aSoundDescriptionV1->bytesPerSample = B_BENDIAN_TO_HOST_INT32(aSoundDescriptionV1->bytesPerSample);
descBytesLeft = descBytesLeft - 16;
} else { } else {
printf("V0 Sound\n");
// Calculate? // Calculate?
aSoundDescriptionV1->bytesPerSample = aSoundDescriptionV1->desc.SampleSize / 8; aSoundDescriptionV1->bytesPerSample = aSoundDescriptionV1->desc.SampleSize / 8;
if (aSoundDescriptionV1->basefields.DataFormat == 'ima4') { if (aSoundDescriptionV1->basefields.DataFormat == 'ima4') {
printf("IMA4\n");
aSoundDescriptionV1->bytesPerFrame = aSoundDescriptionV1->desc.NoOfChannels * 64 / 34; aSoundDescriptionV1->bytesPerFrame = aSoundDescriptionV1->desc.NoOfChannels * 64 / 34;
} else { } else {
aSoundDescriptionV1->bytesPerFrame = aSoundDescriptionV1->desc.NoOfChannels * aSoundDescriptionV1->bytesPerSample; aSoundDescriptionV1->bytesPerFrame = aSoundDescriptionV1->desc.NoOfChannels * aSoundDescriptionV1->bytesPerSample;
@ -810,6 +785,8 @@ void STSDAtom::ReadSoundDescription()
// 0 means we dont have one // 0 means we dont have one
aSoundDescriptionV1->theWaveFormat.format_tag = 0; aSoundDescriptionV1->theWaveFormat.format_tag = 0;
descBytesLeft = getBytesRemaining();
while (descBytesLeft > 0) { while (descBytesLeft > 0) {
// More extended atoms // More extended atoms
@ -836,50 +813,40 @@ void STSDAtom::ReadSoundDescription()
theAudioDescArray[0] = aSoundDescriptionV1; theAudioDescArray[0] = aSoundDescriptionV1;
theStream->Seek(descBytesLeft,0); PRINT(("Size:Format=%ld:%ld %Ld\n",aSoundDescriptionV1->basefields.Size,aSoundDescriptionV1->basefields.DataFormat,descBytesLeft));
PRINT(("Size:Format=%ld:%ld %ld\n",aSoundDescriptionV1->basefields.Size,aSoundDescriptionV1->basefields.DataFormat,descBytesLeft));
} }
void STSDAtom::ReadVideoDescription() void STSDAtom::ReadVideoDescription()
{ {
// read in Video Sample Data // read in Video Sample Data
uint32 descBytesLeft;
VideoDescriptionV0 *aVideoDescription; VideoDescriptionV0 *aVideoDescription;
aVideoDescription = new VideoDescriptionV0; aVideoDescription = new VideoDescriptionV0;
theStream->Read(&aVideoDescription->basefields,sizeof(SampleDescBase)); Read(&aVideoDescription->basefields.Size);
aVideoDescription->basefields.Size = B_BENDIAN_TO_HOST_INT32(aVideoDescription->basefields.Size); Read(&aVideoDescription->basefields.DataFormat);
aVideoDescription->basefields.DataFormat = B_BENDIAN_TO_HOST_INT32(aVideoDescription->basefields.DataFormat); Read(aVideoDescription->basefields.Reserved,6);
aVideoDescription->basefields.DataReference = B_BENDIAN_TO_HOST_INT16(aVideoDescription->basefields.DataReference); Read(&aVideoDescription->basefields.DataReference);
descBytesLeft = aVideoDescription->basefields.Size - sizeof(SampleDescBase); Read(&aVideoDescription->desc.Version);
Read(&aVideoDescription->desc.Revision);
theStream->Read(&(aVideoDescription->desc),sizeof(VideoDescription)); Read(&aVideoDescription->desc.Vendor);
Read(&aVideoDescription->desc.TemporaralQuality);
aVideoDescription->desc.Version = B_BENDIAN_TO_HOST_INT16(aVideoDescription->desc.Version); Read(&aVideoDescription->desc.SpacialQuality);
aVideoDescription->desc.Vendor = B_BENDIAN_TO_HOST_INT32(aVideoDescription->desc.Vendor); Read(&aVideoDescription->desc.Width);
aVideoDescription->desc.TemporaralQuality = B_BENDIAN_TO_HOST_INT32(aVideoDescription->desc.TemporaralQuality); Read(&aVideoDescription->desc.Height);
aVideoDescription->desc.SpacialQuality = B_BENDIAN_TO_HOST_INT32(aVideoDescription->desc.SpacialQuality); Read(&aVideoDescription->desc.HorizontalResolution);
aVideoDescription->desc.Width = B_BENDIAN_TO_HOST_INT16(aVideoDescription->desc.Width); Read(&aVideoDescription->desc.VerticalResolution);
aVideoDescription->desc.Height = B_BENDIAN_TO_HOST_INT16(aVideoDescription->desc.Height); Read(&aVideoDescription->desc.DataSize);
aVideoDescription->desc.HorizontalResolution = B_BENDIAN_TO_HOST_INT32(aVideoDescription->desc.HorizontalResolution); // FrameCount is actually No of Frames per Sample which is usually 1
aVideoDescription->desc.VerticalResolution = B_BENDIAN_TO_HOST_INT32(aVideoDescription->desc.VerticalResolution); Read(&aVideoDescription->desc.FrameCount);
aVideoDescription->desc.DataSize = B_BENDIAN_TO_HOST_INT32(aVideoDescription->desc.DataSize); Read(aVideoDescription->desc.CompressorName,32);
// This framecount never seems to be right Read(&aVideoDescription->desc.Depth);
aVideoDescription->desc.FrameCount = B_BENDIAN_TO_HOST_INT16(aVideoDescription->desc.FrameCount); Read(&aVideoDescription->desc.ColourTableID);
aVideoDescription->desc.Depth = B_BENDIAN_TO_HOST_INT16(aVideoDescription->desc.Depth);
aVideoDescription->desc.ColourTableID = B_BENDIAN_TO_HOST_INT16(aVideoDescription->desc.ColourTableID);
descBytesLeft = descBytesLeft - sizeof(VideoDescription);
theVideoDescArray[0] = aVideoDescription; theVideoDescArray[0] = aVideoDescription;
// We seem to have read 2 bytes too many??? PRINT(("Size:Format=%ld:%ld %Ld\n",aVideoDescription->basefields.Size,aVideoDescription->basefields.DataFormat,getBytesRemaining()));
theStream->Seek(descBytesLeft,0);
PRINT(("Size:Format=%ld:%ld %ld\n",aVideoDescription->basefields.Size,aVideoDescription->basefields.DataFormat,descBytesLeft));
} }
void STSDAtom::OnProcessMetaData() void STSDAtom::OnProcessMetaData()
@ -898,9 +865,12 @@ void STSDAtom::OnProcessMetaData()
default: default:
// Skip // Skip
SampleDescBase aSampleDescBase; SampleDescBase aSampleDescBase;
theStream->Read(&aSampleDescBase,sizeof(SampleDescBase)); Read(&aSampleDescBase.Size);
aSampleDescBase.Size = B_BENDIAN_TO_HOST_INT32(aSampleDescBase.Size); Read(&aSampleDescBase.DataFormat);
theStream->Seek(aSampleDescBase.Size - sizeof(SampleDescBase),0); Read(aSampleDescBase.Reserved,6);
Read(&aSampleDescBase.DataReference);
theStream->Seek(aSampleDescBase.Size - SampleDescBaseSize, 0);
break; break;
} }
} }
@ -934,7 +904,13 @@ WAVEAtom::~WAVEAtom()
void WAVEAtom::OnProcessMetaData() void WAVEAtom::OnProcessMetaData()
{ {
// This should be in LITTLE ENDIAN DATA // This should be in LITTLE ENDIAN DATA
theStream->Read(&theWaveFormat,sizeof(wave_format_ex)); theStream->Read(&theWaveFormat.format_tag,sizeof(uint16));
theStream->Read(&theWaveFormat.channels,sizeof(uint16));
theStream->Read(&theWaveFormat.frames_per_sec,sizeof(uint32));
theStream->Read(&theWaveFormat.avg_bytes_per_sec,sizeof(uint32));
theStream->Read(&theWaveFormat.block_align,sizeof(uint16));
theStream->Read(&theWaveFormat.bits_per_sample,sizeof(uint16));
theStream->Read(&theWaveFormat.extra_size,sizeof(uint16));
theWaveFormat.format_tag = B_LENDIAN_TO_HOST_INT16(theWaveFormat.format_tag); theWaveFormat.format_tag = B_LENDIAN_TO_HOST_INT16(theWaveFormat.format_tag);
theWaveFormat.channels = B_LENDIAN_TO_HOST_INT16(theWaveFormat.channels); theWaveFormat.channels = B_LENDIAN_TO_HOST_INT16(theWaveFormat.channels);
@ -1128,43 +1104,69 @@ TKHDAtom::~TKHDAtom()
void TKHDAtom::OnProcessMetaData() void TKHDAtom::OnProcessMetaData()
{ {
theStream->Read(&Version,sizeof(uint8)); Read(&Version);
if (Version == 0) { if (Version == 0) {
// Read into V0 header and convert to V1 Header
tkhdV0 aHeaderV0; tkhdV0 aHeaderV0;
theStream->Read(&aHeaderV0,sizeof(tkhdV0));
Read(&aHeaderV0.Flags1);
Read(&aHeaderV0.Flags2);
Read(&aHeaderV0.Flags3);
Read(&aHeaderV0.CreationTime);
Read(&aHeaderV0.ModificationTime);
Read(&aHeaderV0.TrackID);
Read(&aHeaderV0.Reserved1);
Read(&aHeaderV0.Duration);
Read(&aHeaderV0.Reserved2);
Read(&aHeaderV0.Layer);
Read(&aHeaderV0.AlternateGroup);
Read(&aHeaderV0.Volume);
Read(&aHeaderV0.Reserved3);
Read(aHeaderV0.MatrixStructure,36);
Read(&aHeaderV0.TrackWidth);
Read(&aHeaderV0.TrackHeight);
theHeader.Flags1 = aHeaderV0.Flags1; theHeader.Flags1 = aHeaderV0.Flags1;
theHeader.Flags2 = aHeaderV0.Flags2; theHeader.Flags2 = aHeaderV0.Flags2;
theHeader.Flags3 = aHeaderV0.Flags3; theHeader.Flags3 = aHeaderV0.Flags3;
theHeader.Reserved1 = aHeaderV0.Reserved1;
theHeader.Reserved2 = aHeaderV0.Reserved2;
theHeader.Reserved3 = aHeaderV0.Reserved3;
for (uint32 i=0;i<36;i++) { for (uint32 i=0;i<36;i++) {
theHeader.MatrixStructure[i] = aHeaderV0.MatrixStructure[i]; theHeader.MatrixStructure[i] = aHeaderV0.MatrixStructure[i];
} }
// upconvert to V1 header // upconvert to V1 header
theHeader.CreationTime = B_BENDIAN_TO_HOST_INT32(aHeaderV0.CreationTime); theHeader.CreationTime = uint64(aHeaderV0.CreationTime);
theHeader.ModificationTime = B_BENDIAN_TO_HOST_INT32(aHeaderV0.ModificationTime); theHeader.ModificationTime = uint64(aHeaderV0.ModificationTime);
theHeader.TrackID = B_BENDIAN_TO_HOST_INT32(aHeaderV0.TrackID); theHeader.TrackID = aHeaderV0.TrackID;
theHeader.Duration = B_BENDIAN_TO_HOST_INT32(aHeaderV0.Duration); theHeader.Duration = aHeaderV0.Duration;
theHeader.Layer = B_BENDIAN_TO_HOST_INT16(aHeaderV0.Layer); theHeader.Layer = aHeaderV0.Layer;
theHeader.AlternateGroup = B_BENDIAN_TO_HOST_INT16(aHeaderV0.AlternateGroup); theHeader.AlternateGroup = aHeaderV0.AlternateGroup;
theHeader.Volume = B_BENDIAN_TO_HOST_INT16(aHeaderV0.Volume); theHeader.Volume = aHeaderV0.Volume;
theHeader.TrackWidth = B_BENDIAN_TO_HOST_INT32(aHeaderV0.TrackWidth); theHeader.TrackWidth = aHeaderV0.TrackWidth;
theHeader.TrackHeight = B_BENDIAN_TO_HOST_INT32(aHeaderV0.TrackHeight); theHeader.TrackHeight = aHeaderV0.TrackHeight;
} else { } else {
theStream->Read(&theHeader,sizeof(tkhdV1)); // Read direct into V1 Header
Read(&theHeader.Flags1);
theHeader.CreationTime = B_BENDIAN_TO_HOST_INT64(theHeader.CreationTime); Read(&theHeader.Flags2);
theHeader.ModificationTime = B_BENDIAN_TO_HOST_INT64(theHeader.ModificationTime); Read(&theHeader.Flags3);
theHeader.TrackID = B_BENDIAN_TO_HOST_INT32(theHeader.TrackID); Read(&theHeader.CreationTime);
theHeader.Duration = B_BENDIAN_TO_HOST_INT32(theHeader.Duration); Read(&theHeader.ModificationTime);
theHeader.Layer = B_BENDIAN_TO_HOST_INT16(theHeader.Layer); Read(&theHeader.TrackID);
theHeader.AlternateGroup = B_BENDIAN_TO_HOST_INT16(theHeader.AlternateGroup); Read(&theHeader.Reserved1);
theHeader.Volume = B_BENDIAN_TO_HOST_INT16(theHeader.Volume); Read(&theHeader.Duration);
theHeader.TrackWidth = B_BENDIAN_TO_HOST_INT32(theHeader.TrackWidth); Read(&theHeader.Reserved2);
theHeader.TrackHeight = B_BENDIAN_TO_HOST_INT32(theHeader.TrackHeight); Read(&theHeader.Layer);
Read(&theHeader.AlternateGroup);
Read(&theHeader.Volume);
Read(&theHeader.Reserved3);
Read(theHeader.MatrixStructure,36);
Read(&theHeader.TrackWidth);
Read(&theHeader.TrackHeight);
} }
} }
@ -1214,14 +1216,16 @@ MDHDAtom::~MDHDAtom()
void MDHDAtom::OnProcessMetaData() void MDHDAtom::OnProcessMetaData()
{ {
theStream->Read(&theHeader,sizeof(mdhd)); Read(&theHeader.Version);
Read(&theHeader.Flags1);
theHeader.CreationTime = B_BENDIAN_TO_HOST_INT32(theHeader.CreationTime); Read(&theHeader.Flags2);
theHeader.ModificationTime = B_BENDIAN_TO_HOST_INT32(theHeader.ModificationTime); Read(&theHeader.Flags3);
theHeader.TimeScale = B_BENDIAN_TO_HOST_INT32(theHeader.TimeScale); Read(&theHeader.CreationTime);
theHeader.Duration = B_BENDIAN_TO_HOST_INT32(theHeader.Duration); Read(&theHeader.ModificationTime);
theHeader.Language = B_BENDIAN_TO_HOST_INT16(theHeader.Language); Read(&theHeader.TimeScale);
theHeader.Quality = B_BENDIAN_TO_HOST_INT16(theHeader.Quality); Read(&theHeader.Duration);
Read(&theHeader.Language);
Read(&theHeader.Quality);
} }
char *MDHDAtom::OnGetAtomName() char *MDHDAtom::OnGetAtomName()
@ -1249,12 +1253,15 @@ HDLRAtom::~HDLRAtom()
void HDLRAtom::OnProcessMetaData() void HDLRAtom::OnProcessMetaData()
{ {
theStream->Read(&theHeader,sizeof(hdlr)); Read(&theHeader.Version);
theHeader.ComponentType = B_BENDIAN_TO_HOST_INT32(theHeader.ComponentType); Read(&theHeader.Flags1);
theHeader.ComponentSubType = B_BENDIAN_TO_HOST_INT32(theHeader.ComponentSubType); Read(&theHeader.Flags2);
theHeader.ComponentManufacturer = B_BENDIAN_TO_HOST_INT32(theHeader.ComponentManufacturer); Read(&theHeader.Flags3);
theHeader.ComponentFlags = B_BENDIAN_TO_HOST_INT32(theHeader.ComponentFlags); Read(&theHeader.ComponentType);
theHeader.ComponentFlagsMask = B_BENDIAN_TO_HOST_INT32(theHeader.ComponentFlagsMask); Read(&theHeader.ComponentSubType);
Read(&theHeader.ComponentManufacturer);
Read(&theHeader.ComponentFlags);
Read(&theHeader.ComponentFlagsMask);
// Read Array of Strings? // Read Array of Strings?
} }
@ -1290,7 +1297,14 @@ VMHDAtom::~VMHDAtom()
void VMHDAtom::OnProcessMetaData() void VMHDAtom::OnProcessMetaData()
{ {
vmhd aHeader; vmhd aHeader;
theStream->Read(&aHeader,sizeof(vmhd)); Read(&aHeader.Version);
Read(&aHeader.Flags1);
Read(&aHeader.Flags2);
Read(&aHeader.Flags3);
Read(&aHeader.GraphicsMode);
Read(&aHeader.OpColourRed);
Read(&aHeader.OpColourGreen);
Read(&aHeader.OpColourBlue);
} }
char *VMHDAtom::OnGetAtomName() char *VMHDAtom::OnGetAtomName()
@ -1309,7 +1323,12 @@ SMHDAtom::~SMHDAtom()
void SMHDAtom::OnProcessMetaData() void SMHDAtom::OnProcessMetaData()
{ {
smhd aHeader; smhd aHeader;
theStream->Read(&aHeader,sizeof(smhd)); Read(&aHeader.Version);
Read(&aHeader.Flags1);
Read(&aHeader.Flags2);
Read(&aHeader.Flags3);
Read(&aHeader.Balance);
Read(&aHeader.Reserved);
} }
char *SMHDAtom::OnGetAtomName() char *SMHDAtom::OnGetAtomName()

View File

@ -47,8 +47,8 @@ typedef ChunkToOffset* ChunkToOffsetPtr;
typedef std::map<uint32, ChunkToOffsetPtr, std::less<uint32> > ChunkToOffsetArray; typedef std::map<uint32, ChunkToOffsetPtr, std::less<uint32> > ChunkToOffsetArray;
typedef SyncSample* SyncSamplePtr; typedef SyncSample* SyncSamplePtr;
typedef std::map<uint32, SyncSamplePtr, std::less<uint32> > SyncSampleArray; typedef std::map<uint32, SyncSamplePtr, std::less<uint32> > SyncSampleArray;
typedef SampleSize* SampleSizePtr; typedef SampleSizeEntry* SampleSizeEntryPtr;
typedef std::map<uint32, SampleSizePtr, std::less<uint32> > SampleSizeArray; typedef std::map<uint32, SampleSizeEntryPtr, std::less<uint32> > SampleSizeArray;
// Atom class for reading the movie header atom // Atom class for reading the movie header atom
class MVHDAtom : public AtomBase { class MVHDAtom : public AtomBase {

View File

@ -131,7 +131,7 @@ struct SampleToChunk {
uint32 FirstChunk; uint32 FirstChunk;
uint32 SamplesPerChunk; uint32 SamplesPerChunk;
uint32 SampleDescriptionID; uint32 SampleDescriptionID;
uint32 TotalPrevFrames; uint32 TotalPrevSamples;
}; };
// Note standard is 32bits offsets but later is 64 // Note standard is 32bits offsets but later is 64
@ -153,8 +153,8 @@ struct SampleSizeHeader {
uint32 NoEntries; uint32 NoEntries;
}; };
struct SampleSize { struct SampleSizeEntry {
uint32 Size; uint32 EntrySize;
}; };
struct mvhd { struct mvhd {
@ -277,6 +277,8 @@ struct SampleDescBase {
uint16 DataReference; uint16 DataReference;
}; };
#define SampleDescBaseSize 16
struct SoundDescription { struct SoundDescription {
uint16 Version; uint16 Version;
uint16 Revision; uint16 Revision;
@ -288,6 +290,8 @@ struct SoundDescription {
uint32 SampleRate; uint32 SampleRate;
}; };
#define SoundDescriptionSize 20
struct SoundDescriptionV0 { struct SoundDescriptionV0 {
SampleDescBase basefields; SampleDescBase basefields;
SoundDescription desc; SoundDescription desc;
@ -322,6 +326,8 @@ struct VideoDescription {
// Optional atoms follow // Optional atoms follow
}; };
#define VideoDescriptionSize 70
struct VideoDescriptionV0 { struct VideoDescriptionV0 {
SampleDescBase basefields; SampleDescBase basefields;
VideoDescription desc; VideoDescription desc;

View File

@ -124,9 +124,7 @@ bool AtomBase::IsKnown()
void AtomBase::ReadArrayHeader(array_header *pHeader) void AtomBase::ReadArrayHeader(array_header *pHeader)
{ {
getStream()->Read(pHeader,sizeof(array_header)); Read(&pHeader->NoEntries);
pHeader->NoEntries = B_BENDIAN_TO_HOST_INT32(pHeader->NoEntries);
} }
BPositionIO *AtomBase::OnGetStream() BPositionIO *AtomBase::OnGetStream()
@ -140,6 +138,77 @@ BPositionIO *AtomBase::getStream()
return OnGetStream(); return OnGetStream();
} }
void AtomBase::Read(uint64 *value)
{
uint32 bytes_read;
bytes_read = getStream()->Read(value,sizeof(uint64));
// Assert((bytes_read == sizeof(uint64),"Read Error");
*value = B_BENDIAN_TO_HOST_INT64(*value);
}
void AtomBase::Read(uint32 *value)
{
uint32 bytes_read;
bytes_read = getStream()->Read(value,sizeof(uint32));
// Assert((bytes_read == sizeof(uint32),"Read Error");
*value = B_BENDIAN_TO_HOST_INT32(*value);
}
void AtomBase::Read(int32 *value)
{
uint32 bytes_read;
bytes_read = getStream()->Read(value,sizeof(int32));
// Assert((bytes_read == sizeof(int32),"Read Error");
*value = B_BENDIAN_TO_HOST_INT32(*value);
}
void AtomBase::Read(uint16 *value)
{
uint32 bytes_read;
bytes_read = getStream()->Read(value,sizeof(uint16));
// Assert((bytes_read == sizeof(uint16),"Read Error");
*value = B_BENDIAN_TO_HOST_INT16(*value);
}
void AtomBase::Read(uint8 *value)
{
uint32 bytes_read;
bytes_read = getStream()->Read(value,sizeof(uint8));
// Assert((bytes_read == sizeof(uint8),"Read Error");
}
void AtomBase::Read(char *value, uint32 maxread)
{
uint32 bytes_read;
bytes_read = getStream()->Read(value,maxread);
// Assert((bytes_read == maxread,"Read Error");
}
void AtomBase::Read(uint8 *value, uint32 maxread)
{
uint32 bytes_read;
bytes_read = getStream()->Read(value,maxread);
// Assert((bytes_read == maxread,"Read Error");
}
FullAtom::FullAtom(BPositionIO *pStream, off_t pstreamOffset, uint32 patomType, uint64 patomSize) : AtomBase(pStream, pstreamOffset, patomType, patomSize) FullAtom::FullAtom(BPositionIO *pStream, off_t pstreamOffset, uint32 patomType, uint64 patomSize) : AtomBase(pStream, pstreamOffset, patomType, patomSize)
{ {
} }
@ -150,10 +219,10 @@ FullAtom::~FullAtom()
void FullAtom::OnProcessMetaData() void FullAtom::OnProcessMetaData()
{ {
getStream()->Read(&Version,sizeof(uint8)); Read(&Version);
getStream()->Read(&Flags1,sizeof(uint8)); Read(&Flags1);
getStream()->Read(&Flags2,sizeof(uint8)); Read(&Flags2);
getStream()->Read(&Flags3,sizeof(uint8)); Read(&Flags3);
} }
AtomContainer::AtomContainer(BPositionIO *pStream, off_t pstreamOffset, uint32 patomType, uint64 patomSize) : AtomBase(pStream, pstreamOffset, patomType, patomSize) AtomContainer::AtomContainer(BPositionIO *pStream, off_t pstreamOffset, uint32 patomType, uint64 patomSize) : AtomBase(pStream, pstreamOffset, patomType, patomSize)

View File

@ -134,6 +134,14 @@ public:
void setParent(AtomBase *pParent) {parentAtom = pParent;}; void setParent(AtomBase *pParent) {parentAtom = pParent;};
AtomBase *getParent() { return parentAtom;}; AtomBase *getParent() { return parentAtom;};
void Read(uint64 *value);
void Read(uint32 *value);
void Read(int32 *value);
void Read(uint16 *value);
void Read(uint8 *value);
void Read(char *value, uint32 maxread);
void Read(uint8 *value, uint32 maxread);
}; };
class FullAtom : public AtomBase { class FullAtom : public AtomBase {

View File

@ -554,23 +554,6 @@ uint32 MP4FileReader::getChunkSize(uint32 stream_index, uint32 pFrameNo)
uint32 ChunkNo = pFrameNo; uint32 ChunkNo = pFrameNo;
off_t Chunk_Start = aTrakAtom->getOffsetForChunk(ChunkNo); off_t Chunk_Start = aTrakAtom->getOffsetForChunk(ChunkNo);
uint32 ChunkSize = theChunkSuperIndex.getChunkSize(stream_index,ChunkNo,Chunk_Start); uint32 ChunkSize = theChunkSuperIndex.getChunkSize(stream_index,ChunkNo,Chunk_Start);
uint32 NoSamples = aTrakAtom->getNoSamplesInChunk(ChunkNo);
uint32 TotalSampleSize = 0;
// Get first sample in chunk
uint32 SampleNo = aTrakAtom->getFirstSampleInChunk(ChunkNo);
if (aTrakAtom->IsSingleSampleSize()) {
TotalSampleSize = NoSamples * aTrakAtom->getSizeForSample(SampleNo);
} else {
// Add up all sample sizes in chunk
for (uint32 i=0;i<NoSamples;i++) {
TotalSampleSize += aTrakAtom->getSizeForSample(SampleNo);
SampleNo++;
}
}
TotalSampleSize = TotalSampleSize * aTrakAtom->getBytesPerSample();
return ChunkSize; return ChunkSize;
} }
@ -610,6 +593,7 @@ bool MP4FileReader::GetNextChunkInfo(uint32 stream_index, uint32 pFrameNo, off_t
*keyframe = IsKeyFrame(stream_index, pFrameNo); *keyframe = IsKeyFrame(stream_index, pFrameNo);
} }
// TODO need a better method for detecting End of Data Note ChunkSize of 0 seems to be it.
return ((*start > 0) && (*size > 0) && !(IsEndOfFile(*start + *size)) && !(IsEndOfData(*start + *size))); return ((*start > 0) && (*size > 0) && !(IsEndOfFile(*start + *size)) && !(IsEndOfData(*start + *size)));
} }

View File

@ -28,8 +28,11 @@
#include <SupportKit.h> #include <SupportKit.h>
#include <MediaFormats.h> #include <MediaFormats.h>
#ifdef __HAIKU__
#include <libs/zlib/zlib.h> #include <libs/zlib/zlib.h>
//#include <zlib.h> #else
#include <zlib.h>
#endif
#include "MP4Parser.h" #include "MP4Parser.h"
@ -332,9 +335,7 @@ DCOMAtom::~DCOMAtom()
void DCOMAtom::OnProcessMetaData() void DCOMAtom::OnProcessMetaData()
{ {
theStream->Read(&compressionID,sizeof(uint32)); Read(&compressionID);
compressionID = B_BENDIAN_TO_HOST_INT32(compressionID);
} }
char *DCOMAtom::OnGetAtomName() char *DCOMAtom::OnGetAtomName()
@ -358,14 +359,12 @@ CMVDAtom::~CMVDAtom()
void CMVDAtom::OnProcessMetaData() void CMVDAtom::OnProcessMetaData()
{ {
theStream->Read(&UncompressedSize,sizeof(uint32)); Read(&UncompressedSize);
UncompressedSize = B_BENDIAN_TO_HOST_INT32(UncompressedSize);
if (UncompressedSize > 0) { if (UncompressedSize > 0) {
BufferSize = getBytesRemaining(); BufferSize = getBytesRemaining();
Buffer = (uint8 *)(malloc(BufferSize)); Buffer = (uint8 *)(malloc(BufferSize));
theStream->Read(Buffer,BufferSize); Read(Buffer,BufferSize);
} }
} }
@ -388,27 +387,52 @@ void MVHDAtom::OnProcessMetaData()
if (getVersion() == 0) { if (getVersion() == 0) {
mvhdV0 aHeader; mvhdV0 aHeader;
theStream->Read(&aHeader,sizeof(mvhdV0));
theHeader.CreationTime = (uint64)(B_BENDIAN_TO_HOST_INT32(aHeader.CreationTime)); Read(&aHeader.CreationTime);
theHeader.ModificationTime = (uint64)(B_BENDIAN_TO_HOST_INT32(aHeader.ModificationTime)); Read(&aHeader.ModificationTime);
theHeader.TimeScale = B_BENDIAN_TO_HOST_INT32(aHeader.TimeScale); Read(&aHeader.TimeScale);
theHeader.Duration = (uint64)(B_BENDIAN_TO_HOST_INT32(aHeader.Duration)); Read(&aHeader.Duration);
theHeader.PreferredRate = B_BENDIAN_TO_HOST_INT32(aHeader.PreferredRate); Read(&aHeader.PreferredRate);
theHeader.PreferredVolume = B_BENDIAN_TO_HOST_INT16(aHeader.PreferredVolume); Read(&aHeader.PreferredVolume);
theHeader.NextTrackID = B_BENDIAN_TO_HOST_INT32(aHeader.NextTrackID); Read(&aHeader.Reserved1);
Read(&aHeader.Reserved2[0]);
Read(&aHeader.Reserved2[1]);
for (uint32 i=0;i<9;i++) {
Read(&aHeader.Matrix[i]);
}
for (uint32 j=0;j<6;j++) {
Read(&aHeader.pre_defined[j]);
}
Read(&aHeader.NextTrackID);
// Upconvert to V1 header
theHeader.CreationTime = (uint64)(aHeader.CreationTime);
theHeader.ModificationTime = (uint64)(aHeader.ModificationTime);
theHeader.TimeScale = aHeader.TimeScale;
theHeader.Duration = (uint64)(aHeader.Duration);
theHeader.PreferredRate = aHeader.PreferredRate;
theHeader.PreferredVolume = aHeader.PreferredVolume;
theHeader.NextTrackID = aHeader.NextTrackID;
} }
if (getVersion() == 1) { if (getVersion() == 1) {
theStream->Read(&theHeader,sizeof(mvhdV1)); // Read direct into V1 Header
Read(&theHeader.CreationTime);
theHeader.CreationTime = B_BENDIAN_TO_HOST_INT64(theHeader.CreationTime); Read(&theHeader.ModificationTime);
theHeader.ModificationTime = B_BENDIAN_TO_HOST_INT64(theHeader.ModificationTime); Read(&theHeader.TimeScale);
theHeader.TimeScale = B_BENDIAN_TO_HOST_INT32(theHeader.TimeScale); Read(&theHeader.Duration);
theHeader.Duration = B_BENDIAN_TO_HOST_INT64(theHeader.Duration); Read(&theHeader.PreferredRate);
theHeader.PreferredRate = B_BENDIAN_TO_HOST_INT32(theHeader.PreferredRate); Read(&theHeader.PreferredVolume);
theHeader.PreferredVolume = B_BENDIAN_TO_HOST_INT16(theHeader.PreferredVolume); Read(&theHeader.Reserved1);
theHeader.NextTrackID = B_BENDIAN_TO_HOST_INT32(theHeader.NextTrackID); Read(&theHeader.Reserved2[0]);
Read(&theHeader.Reserved2[1]);
for (uint32 i=0;i<9;i++) {
Read(&theHeader.Matrix[i]);
}
for (uint32 j=0;j<6;j++) {
Read(&theHeader.pre_defined[j]);
}
Read(&theHeader.NextTrackID);
} }
} }
@ -456,9 +480,8 @@ TimeToSample *aTimeToSample;
for (uint32 i=0;i<theHeader.NoEntries;i++) { for (uint32 i=0;i<theHeader.NoEntries;i++) {
aTimeToSample = new TimeToSample; aTimeToSample = new TimeToSample;
theStream->Read(aTimeToSample,sizeof(TimeToSample)); Read(&aTimeToSample->Count);
aTimeToSample->Count = B_BENDIAN_TO_HOST_INT32(aTimeToSample->Count); Read(&aTimeToSample->Duration);
aTimeToSample->Duration = B_BENDIAN_TO_HOST_INT32(aTimeToSample->Duration);
theTimeToSampleArray[i] = aTimeToSample; theTimeToSampleArray[i] = aTimeToSample;
SUMDurations += (theTimeToSampleArray[i]->Duration * theTimeToSampleArray[i]->Count); SUMDurations += (theTimeToSampleArray[i]->Duration * theTimeToSampleArray[i]->Count);
@ -516,9 +539,8 @@ CompTimeToSample *aCompTimeToSample;
for (uint32 i=0;i<theHeader.NoEntries;i++) { for (uint32 i=0;i<theHeader.NoEntries;i++) {
aCompTimeToSample = new CompTimeToSample; aCompTimeToSample = new CompTimeToSample;
theStream->Read(aCompTimeToSample,sizeof(CompTimeToSample)); Read(&aCompTimeToSample->Count);
aCompTimeToSample->Count = B_BENDIAN_TO_HOST_INT32(aCompTimeToSample->Count); Read(&aCompTimeToSample->Offset);
aCompTimeToSample->Offset = B_BENDIAN_TO_HOST_INT32(aCompTimeToSample->Offset);
theCompTimeToSampleArray[i] = aCompTimeToSample; theCompTimeToSampleArray[i] = aCompTimeToSample;
} }
@ -550,24 +572,20 @@ SampleToChunk *aSampleToChunk;
ReadArrayHeader(&theHeader); ReadArrayHeader(&theHeader);
uint32 TotalPrevFrames = 0; uint32 TotalPrevSamples = 0;
for (uint32 i=0;i<theHeader.NoEntries;i++) { for (uint32 i=0;i<theHeader.NoEntries;i++) {
aSampleToChunk = new SampleToChunk; aSampleToChunk = new SampleToChunk;
theStream->Read(&aSampleToChunk->FirstChunk,sizeof(uint32)); Read(&aSampleToChunk->FirstChunk);
theStream->Read(&aSampleToChunk->SamplesPerChunk,sizeof(uint32)); Read(&aSampleToChunk->SamplesPerChunk);
theStream->Read(&aSampleToChunk->SampleDescriptionID,sizeof(uint32)); Read(&aSampleToChunk->SampleDescriptionID);
aSampleToChunk->FirstChunk = B_BENDIAN_TO_HOST_INT32(aSampleToChunk->FirstChunk);
aSampleToChunk->SamplesPerChunk = B_BENDIAN_TO_HOST_INT32(aSampleToChunk->SamplesPerChunk);
aSampleToChunk->SampleDescriptionID = B_BENDIAN_TO_HOST_INT32(aSampleToChunk->SampleDescriptionID);
if (i > 0) { if (i > 0) {
TotalPrevFrames = TotalPrevFrames + (aSampleToChunk->FirstChunk - theSampleToChunkArray[i-1]->FirstChunk) * theSampleToChunkArray[i-1]->SamplesPerChunk; TotalPrevSamples = TotalPrevSamples + (aSampleToChunk->FirstChunk - theSampleToChunkArray[i-1]->FirstChunk) * theSampleToChunkArray[i-1]->SamplesPerChunk;
aSampleToChunk->TotalPrevFrames = TotalPrevFrames; aSampleToChunk->TotalPrevSamples = TotalPrevSamples;
} else { } else {
aSampleToChunk->TotalPrevFrames = 0; aSampleToChunk->TotalPrevSamples = 0;
} }
theSampleToChunkArray[i] = aSampleToChunk; theSampleToChunkArray[i] = aSampleToChunk;
@ -587,20 +605,22 @@ uint32 STSCAtom::getNoSamplesInChunk(uint32 pChunkID)
} }
} }
return 0; return theSampleToChunkArray[theHeader.NoEntries-1]->SamplesPerChunk;
} }
uint32 STSCAtom::getFirstSampleInChunk(uint32 pChunkID) uint32 STSCAtom::getFirstSampleInChunk(uint32 pChunkID)
{ {
uint32 Diff;
for (uint32 i=0;i<theHeader.NoEntries;i++) { for (uint32 i=0;i<theHeader.NoEntries;i++) {
if (theSampleToChunkArray[i]->FirstChunk > pChunkID) { if (theSampleToChunkArray[i]->FirstChunk > pChunkID) {
uint32 Diff = pChunkID - theSampleToChunkArray[i-1]->FirstChunk; Diff = pChunkID - theSampleToChunkArray[i-1]->FirstChunk;
uint32 pSampleNo = (Diff * theSampleToChunkArray[i-1]->SamplesPerChunk) + theSampleToChunkArray[i-1]->TotalPrevFrames; return ((Diff * theSampleToChunkArray[i-1]->SamplesPerChunk) + theSampleToChunkArray[i-1]->TotalPrevSamples);
return pSampleNo;
} }
} }
return 0; Diff = pChunkID - theSampleToChunkArray[theHeader.NoEntries-1]->FirstChunk;
return ((Diff * theSampleToChunkArray[theHeader.NoEntries-1]->SamplesPerChunk) + theSampleToChunkArray[theHeader.NoEntries-1]->TotalPrevSamples);
} }
uint32 STSCAtom::getChunkForSample(uint32 pSample, uint32 *pOffsetInChunk) uint32 STSCAtom::getChunkForSample(uint32 pSample, uint32 *pOffsetInChunk)
@ -609,12 +629,12 @@ uint32 STSCAtom::getChunkForSample(uint32 pSample, uint32 *pOffsetInChunk)
uint32 OffsetInChunk = 0; uint32 OffsetInChunk = 0;
for (int32 i=theHeader.NoEntries-1;i>=0;i--) { for (int32 i=theHeader.NoEntries-1;i>=0;i--) {
if (pSample >= theSampleToChunkArray[i]->TotalPrevFrames) { if (pSample >= theSampleToChunkArray[i]->TotalPrevSamples) {
// Found chunk now calculate offset // Found chunk now calculate offset
ChunkID = (pSample - theSampleToChunkArray[i]->TotalPrevFrames) / theSampleToChunkArray[i]->SamplesPerChunk; ChunkID = (pSample - theSampleToChunkArray[i]->TotalPrevSamples) / theSampleToChunkArray[i]->SamplesPerChunk;
ChunkID += theSampleToChunkArray[i]->FirstChunk; ChunkID += theSampleToChunkArray[i]->FirstChunk;
OffsetInChunk = (pSample - theSampleToChunkArray[i]->TotalPrevFrames) % theSampleToChunkArray[i]->SamplesPerChunk; OffsetInChunk = (pSample - theSampleToChunkArray[i]->TotalPrevSamples) % theSampleToChunkArray[i]->SamplesPerChunk;
*pOffsetInChunk = OffsetInChunk; *pOffsetInChunk = OffsetInChunk;
return ChunkID; return ChunkID;
@ -649,8 +669,7 @@ SyncSample *aSyncSample;
for (uint32 i=0;i<theHeader.NoEntries;i++) { for (uint32 i=0;i<theHeader.NoEntries;i++) {
aSyncSample = new SyncSample; aSyncSample = new SyncSample;
theStream->Read(aSyncSample,sizeof(SyncSample)); Read(&aSyncSample->SyncSampleNo);
aSyncSample->SyncSampleNo = B_BENDIAN_TO_HOST_INT32(aSyncSample->SyncSampleNo);
theSyncSampleArray[i] = aSyncSample; theSyncSampleArray[i] = aSyncSample;
} }
@ -694,11 +713,8 @@ void STSZAtom::OnProcessMetaData()
{ {
FullAtom::OnProcessMetaData(); FullAtom::OnProcessMetaData();
theStream->Read(&SampleSize,sizeof(uint32)); Read(&SampleSize);
theStream->Read(&SampleCount,sizeof(uint32)); Read(&SampleCount);
SampleSize = B_BENDIAN_TO_HOST_INT32(SampleSize);
SampleCount = B_BENDIAN_TO_HOST_INT32(SampleCount);
// If the sample size is constant there is no array and NoEntries seems to contain bad values // If the sample size is constant there is no array and NoEntries seems to contain bad values
if (SampleSize == 0) { if (SampleSize == 0) {
@ -707,8 +723,7 @@ void STSZAtom::OnProcessMetaData()
for (uint32 i=0;i<SampleCount;i++) { for (uint32 i=0;i<SampleCount;i++) {
aSampleSizePtr = new SampleSizeEntry; aSampleSizePtr = new SampleSizeEntry;
theStream->Read(aSampleSizePtr,sizeof(SampleSizeEntry)); Read(&aSampleSizePtr->EntrySize);
aSampleSizePtr->EntrySize = B_BENDIAN_TO_HOST_INT32(aSampleSizePtr->EntrySize);
theSampleSizeArray[i] = aSampleSizePtr; theSampleSizeArray[i] = aSampleSizePtr;
} }
@ -754,14 +769,12 @@ void STZ2Atom::OnProcessMetaData()
FullAtom::OnProcessMetaData(); FullAtom::OnProcessMetaData();
uint8 reserved; uint8 reserved;
theStream->Read(&reserved,sizeof(uint8)); Read(&reserved);
theStream->Read(&reserved,sizeof(uint8)); Read(&reserved);
theStream->Read(&reserved,sizeof(uint8)); Read(&reserved);
theStream->Read(&FieldSize,sizeof(uint8)); Read(&FieldSize);
theStream->Read(&SampleCount,sizeof(uint32)); Read(&SampleCount);
SampleCount = B_BENDIAN_TO_HOST_INT32(SampleCount);
SampleSizePtr aSampleSizePtr; SampleSizePtr aSampleSizePtr;
uint8 EntrySize8; uint8 EntrySize8;
@ -772,17 +785,17 @@ void STZ2Atom::OnProcessMetaData()
switch (FieldSize) { switch (FieldSize) {
case 4: case 4:
theStream->Read(&EntrySize8,sizeof(uint8)); Read(&EntrySize8);
// 2 values per byte // 2 values per byte
aSampleSizePtr->EntrySize = (uint32)(EntrySize8); aSampleSizePtr->EntrySize = (uint32)(EntrySize8);
break; break;
case 8: case 8:
theStream->Read(&EntrySize8,sizeof(uint8)); Read(&EntrySize8);
// 1 value per byte // 1 value per byte
aSampleSizePtr->EntrySize = (uint32)(EntrySize8); aSampleSizePtr->EntrySize = (uint32)(EntrySize8);
break; break;
case 16: case 16:
theStream->Read(&EntrySize16,sizeof(uint16)); Read(&EntrySize16);
// 1 value per 2 bytes // 1 value per 2 bytes
aSampleSizePtr->EntrySize = (uint32)(EntrySize16); aSampleSizePtr->EntrySize = (uint32)(EntrySize16);
break; break;
@ -849,10 +862,10 @@ uint64 STCOAtom::OnGetChunkOffset()
{ {
uint32 Offset; uint32 Offset;
theStream->Read(&Offset,sizeof(uint32)); Read(&Offset);
// Upconvert to uint64 // Upconvert to uint64
return uint64(B_BENDIAN_TO_HOST_INT32(Offset)); return uint64(Offset);
} }
void STCOAtom::OnProcessMetaData() void STCOAtom::OnProcessMetaData()
@ -889,7 +902,7 @@ uint64 STCOAtom::getOffsetForChunk(uint32 pChunkID)
DEBUGGER(("Bad Chunk ID %ld / %ld\n",pChunkID,theHeader.NoEntries)); DEBUGGER(("Bad Chunk ID %ld / %ld\n",pChunkID,theHeader.NoEntries));
TRESPASS(); TRESPASS();
return -1LL; return 0LL;
} }
ESDSAtom::ESDSAtom(BPositionIO *pStream, off_t pstreamOffset, uint32 patomType, uint64 patomSize) : AtomBase(pStream, pstreamOffset, patomType, patomSize) ESDSAtom::ESDSAtom(BPositionIO *pStream, off_t pstreamOffset, uint32 patomType, uint64 patomSize) : AtomBase(pStream, pstreamOffset, patomType, patomSize)
@ -907,7 +920,7 @@ ESDSAtom::~ESDSAtom()
void ESDSAtom::OnProcessMetaData() void ESDSAtom::OnProcessMetaData()
{ {
theVOL = (uint8 *)(malloc(getBytesRemaining())); theVOL = (uint8 *)(malloc(getBytesRemaining()));
theStream->Read(theVOL,getBytesRemaining()); Read(theVOL,getBytesRemaining());
} }
uint8 *ESDSAtom::getVOL() uint8 *ESDSAtom::getVOL()
@ -974,34 +987,44 @@ void STSDAtom::ReadESDS(uint8 **VOL, size_t *VOLSize)
void STSDAtom::ReadSoundDescription() void STSDAtom::ReadSoundDescription()
{ {
theStream->Read(&theAudioDescription.theAudioSampleEntry,AudioSampleEntrySize); Read(&theAudioDescription.theAudioSampleEntry.Reserved[1]);
Read(&theAudioDescription.theAudioSampleEntry.Reserved[2]);
theAudioDescription.theAudioSampleEntry.ChannelCount = B_BENDIAN_TO_HOST_INT16(theAudioDescription.theAudioSampleEntry.ChannelCount); Read(&theAudioDescription.theAudioSampleEntry.ChannelCount);
theAudioDescription.theAudioSampleEntry.SampleSize = B_BENDIAN_TO_HOST_INT16(theAudioDescription.theAudioSampleEntry.SampleSize); Read(&theAudioDescription.theAudioSampleEntry.SampleSize);
theAudioDescription.theAudioSampleEntry.SampleRate = B_BENDIAN_TO_HOST_INT32(theAudioDescription.theAudioSampleEntry.SampleRate); Read(&theAudioDescription.theAudioSampleEntry.pre_defined);
Read(&theAudioDescription.theAudioSampleEntry.reserved);
Read(&theAudioDescription.theAudioSampleEntry.SampleRate);
ReadESDS(&theAudioDescription.theVOL,&theAudioDescription.VOLSize); ReadESDS(&theAudioDescription.theVOL,&theAudioDescription.VOLSize);
} }
void STSDAtom::ReadVideoDescription() void STSDAtom::ReadVideoDescription()
{ {
// Hmm VideoSampleEntry is 70 bytes but the struct is 72 bytes stupid padding Read(&theVideoDescription.theVideoSampleEntry.pre_defined1);
theStream->Read(&theVideoDescription.theVideoSampleEntry,VideoSampleEntrySize); Read(&theVideoDescription.theVideoSampleEntry.reserved1);
Read(&theVideoDescription.theVideoSampleEntry.pre_defined2[0]);
Read(&theVideoDescription.theVideoSampleEntry.pre_defined2[1]);
Read(&theVideoDescription.theVideoSampleEntry.pre_defined2[2]);
Read(&theVideoDescription.theVideoSampleEntry.Width);
Read(&theVideoDescription.theVideoSampleEntry.Height);
Read(&theVideoDescription.theVideoSampleEntry.HorizontalResolution);
Read(&theVideoDescription.theVideoSampleEntry.VerticalResolution);
Read(&theVideoDescription.theVideoSampleEntry.reserved2);
Read(&theVideoDescription.theVideoSampleEntry.FrameCount);
theVideoDescription.theVideoSampleEntry.Width = B_BENDIAN_TO_HOST_INT16(theVideoDescription.theVideoSampleEntry.Width); Read(theVideoDescription.theVideoSampleEntry.CompressorName,32);
theVideoDescription.theVideoSampleEntry.Height = B_BENDIAN_TO_HOST_INT16(theVideoDescription.theVideoSampleEntry.Height);
theVideoDescription.theVideoSampleEntry.HorizontalResolution = B_BENDIAN_TO_HOST_INT32(theVideoDescription.theVideoSampleEntry.HorizontalResolution);
theVideoDescription.theVideoSampleEntry.VerticalResolution = B_BENDIAN_TO_HOST_INT32(theVideoDescription.theVideoSampleEntry.VerticalResolution);
theVideoDescription.theVideoSampleEntry.FrameCount = B_BENDIAN_TO_HOST_INT16(theVideoDescription.theVideoSampleEntry.FrameCount);
theVideoDescription.theVideoSampleEntry.Depth = B_BENDIAN_TO_HOST_INT16(theVideoDescription.theVideoSampleEntry.Depth);
// convert from pascal string (first bytes size) to C string (null terminated) // convert from pascal string (first bytes size) to C string (null terminated)
uint8 size = (uint8)(theVideoDescription.theVideoSampleEntry.CompressorName[0]); uint8 size = (uint8)(theVideoDescription.theVideoSampleEntry.CompressorName[0]);
if (size > 0) { if (size > 0) {
memcpy(&theVideoDescription.theVideoSampleEntry.CompressorName[0],&theVideoDescription.theVideoSampleEntry.CompressorName[1],size); memmove(&theVideoDescription.theVideoSampleEntry.CompressorName[0],&theVideoDescription.theVideoSampleEntry.CompressorName[1],size);
theVideoDescription.theVideoSampleEntry.CompressorName[size] = '\0'; theVideoDescription.theVideoSampleEntry.CompressorName[size] = '\0';
printf("%s\n",theVideoDescription.theVideoSampleEntry.CompressorName);
} }
Read(&theVideoDescription.theVideoSampleEntry.Depth);
Read(&theVideoDescription.theVideoSampleEntry.pre_defined3);
ReadESDS(&theVideoDescription.theVOL,&theVideoDescription.VOLSize); ReadESDS(&theVideoDescription.theVOL,&theVideoDescription.VOLSize);
} }
@ -1018,14 +1041,11 @@ void STSDAtom::OnProcessMetaData()
// We are actually reading a Atom/Box where the Atom Type is the codec id. // We are actually reading a Atom/Box where the Atom Type is the codec id.
uint32 Size; uint32 Size;
theStream->Read(&Size,sizeof(uint32)); Read(&Size);
theStream->Read(&codecid,sizeof(uint32)); Read(&codecid);
Size = B_BENDIAN_TO_HOST_INT32(Size); Read(theSampleEntry.Reserved,6);
codecid = B_BENDIAN_TO_HOST_INT32(codecid); Read(&theSampleEntry.DataReference);
theStream->Read(&theSampleEntry,sizeof(SampleEntry));
theSampleEntry.DataReference = B_BENDIAN_TO_HOST_INT16(theSampleEntry.DataReference);
switch (getMediaHandlerType()) { switch (getMediaHandlerType()) {
case 'soun': case 'soun':
@ -1105,11 +1125,8 @@ FTYPAtom::~FTYPAtom()
void FTYPAtom::OnProcessMetaData() void FTYPAtom::OnProcessMetaData()
{ {
theStream->Read(&major_brand,sizeof(uint32)); Read(&major_brand);
theStream->Read(&minor_version,sizeof(uint32)); Read(&minor_version);
major_brand = B_BENDIAN_TO_HOST_INT32(major_brand);
minor_version = B_BENDIAN_TO_HOST_INT32(minor_version);
total_brands = getBytesRemaining() / sizeof(uint32); total_brands = getBytesRemaining() / sizeof(uint32);
@ -1118,8 +1135,7 @@ void FTYPAtom::OnProcessMetaData()
} }
for (uint32 i=0;i<total_brands;i++) { for (uint32 i=0;i<total_brands;i++) {
theStream->Read(&compatable_brands[i],sizeof(uint32)); Read(&compatable_brands[i]);
compatable_brands[i] = B_BENDIAN_TO_HOST_INT32(compatable_brands[i]);
} }
} }
@ -1279,39 +1295,56 @@ void TKHDAtom::OnProcessMetaData()
if (getVersion() == 0) { if (getVersion() == 0) {
tkhdV0 aHeaderV0; tkhdV0 aHeaderV0;
theStream->Read(&aHeaderV0,sizeof(tkhdV0));
Read(&aHeaderV0.CreationTime);
Read(&aHeaderV0.ModificationTime);
Read(&aHeaderV0.TrackID);
Read(&aHeaderV0.Reserved1);
Read(&aHeaderV0.Duration);
Read(&aHeaderV0.Reserved2[0]);
Read(&aHeaderV0.Reserved2[1]);
Read(&aHeaderV0.Layer);
Read(&aHeaderV0.AlternateGroup);
Read(&aHeaderV0.Volume);
Read(&aHeaderV0.Reserved3);
for (uint32 i=0;i<9;i++) { for (uint32 i=0;i<9;i++) {
theHeader.MatrixStructure[i] = B_BENDIAN_TO_HOST_INT32(aHeaderV0.MatrixStructure[i]); Read(&theHeader.MatrixStructure[i]);
} }
Read(&aHeaderV0.TrackWidth);
Read(&aHeaderV0.TrackHeight);
// upconvert to V1 header // upconvert to V1 header
theHeader.CreationTime = (uint64)(B_BENDIAN_TO_HOST_INT32(aHeaderV0.CreationTime)); theHeader.CreationTime = (uint64)(aHeaderV0.CreationTime);
theHeader.ModificationTime = (uint64)(B_BENDIAN_TO_HOST_INT32(aHeaderV0.ModificationTime)); theHeader.ModificationTime = (uint64)(aHeaderV0.ModificationTime);
theHeader.TrackID = B_BENDIAN_TO_HOST_INT32(aHeaderV0.TrackID); theHeader.TrackID = aHeaderV0.TrackID;
theHeader.Duration = (uint64)(B_BENDIAN_TO_HOST_INT32(aHeaderV0.Duration)); theHeader.Duration = (uint64)(aHeaderV0.Duration);
theHeader.Layer = B_BENDIAN_TO_HOST_INT16(aHeaderV0.Layer); theHeader.Layer = aHeaderV0.Layer;
theHeader.AlternateGroup = B_BENDIAN_TO_HOST_INT16(aHeaderV0.AlternateGroup); theHeader.AlternateGroup = aHeaderV0.AlternateGroup;
theHeader.Volume = B_BENDIAN_TO_HOST_INT16(aHeaderV0.Volume); theHeader.Volume = aHeaderV0.Volume;
theHeader.TrackWidth = B_BENDIAN_TO_HOST_INT32(aHeaderV0.TrackWidth); theHeader.TrackWidth = aHeaderV0.TrackWidth;
theHeader.TrackHeight = B_BENDIAN_TO_HOST_INT32(aHeaderV0.TrackHeight); theHeader.TrackHeight = aHeaderV0.TrackHeight;
} else { } else {
theStream->Read(&theHeader,sizeof(tkhdV1)); Read(&theHeader.CreationTime);
Read(&theHeader.ModificationTime);
Read(&theHeader.TrackID);
Read(&theHeader.Reserved1);
Read(&theHeader.Duration);
Read(&theHeader.Reserved2[0]);
Read(&theHeader.Reserved2[1]);
Read(&theHeader.Layer);
Read(&theHeader.AlternateGroup);
Read(&theHeader.Volume);
Read(&theHeader.Reserved3);
for (uint32 i=0;i<9;i++) { for (uint32 i=0;i<9;i++) {
theHeader.MatrixStructure[i] = B_BENDIAN_TO_HOST_INT32(theHeader.MatrixStructure[i]); Read(&theHeader.MatrixStructure[i]);
} }
theHeader.CreationTime = B_BENDIAN_TO_HOST_INT64(theHeader.CreationTime); Read(&theHeader.TrackWidth);
theHeader.ModificationTime = B_BENDIAN_TO_HOST_INT64(theHeader.ModificationTime); Read(&theHeader.TrackHeight);
theHeader.TrackID = B_BENDIAN_TO_HOST_INT32(theHeader.TrackID);
theHeader.Duration = B_BENDIAN_TO_HOST_INT64(theHeader.Duration);
theHeader.Layer = B_BENDIAN_TO_HOST_INT16(theHeader.Layer);
theHeader.AlternateGroup = B_BENDIAN_TO_HOST_INT16(theHeader.AlternateGroup);
theHeader.Volume = B_BENDIAN_TO_HOST_INT16(theHeader.Volume);
theHeader.TrackWidth = B_BENDIAN_TO_HOST_INT32(theHeader.TrackWidth);
theHeader.TrackHeight = B_BENDIAN_TO_HOST_INT32(theHeader.TrackHeight);
} }
} }
@ -1366,21 +1399,25 @@ void MDHDAtom::OnProcessMetaData()
if (getVersion() == 0) { if (getVersion() == 0) {
mdhdV0 aHeader; mdhdV0 aHeader;
theStream->Read(&aHeader,sizeof(mdhdV0)); Read(&aHeader.CreationTime);
Read(&aHeader.ModificationTime);
Read(&aHeader.TimeScale);
Read(&aHeader.Duration);
Read(&aHeader.Language);
Read(&aHeader.Reserved);
theHeader.CreationTime = (uint64)(B_BENDIAN_TO_HOST_INT32(aHeader.CreationTime)); theHeader.CreationTime = (uint64)(aHeader.CreationTime);
theHeader.ModificationTime = (uint64)(B_BENDIAN_TO_HOST_INT32(aHeader.ModificationTime)); theHeader.ModificationTime = (uint64)(aHeader.ModificationTime);
theHeader.TimeScale = B_BENDIAN_TO_HOST_INT32(aHeader.TimeScale); theHeader.TimeScale = aHeader.TimeScale;
theHeader.Duration = (uint64)(B_BENDIAN_TO_HOST_INT32(aHeader.Duration)); theHeader.Duration = (uint64)(aHeader.Duration);
theHeader.Language = B_BENDIAN_TO_HOST_INT16(aHeader.Language); theHeader.Language = aHeader.Language;
} else { } else {
theStream->Read(&theHeader,sizeof(mdhdV1)); Read(&theHeader.CreationTime);
Read(&theHeader.ModificationTime);
theHeader.CreationTime = B_BENDIAN_TO_HOST_INT64(theHeader.CreationTime); Read(&theHeader.TimeScale);
theHeader.ModificationTime = B_BENDIAN_TO_HOST_INT64(theHeader.ModificationTime); Read(&theHeader.Duration);
theHeader.TimeScale = B_BENDIAN_TO_HOST_INT32(theHeader.TimeScale); Read(&theHeader.Language);
theHeader.Duration = B_BENDIAN_TO_HOST_INT64(theHeader.Duration); Read(&theHeader.Reserved);
theHeader.Language = B_BENDIAN_TO_HOST_INT16(theHeader.Language);
} }
} }
@ -1415,12 +1452,15 @@ void HDLRAtom::OnProcessMetaData()
{ {
FullAtom::OnProcessMetaData(); FullAtom::OnProcessMetaData();
theStream->Read(&theHeader,sizeof(hdlr)); Read(&theHeader.pre_defined);
theHeader.handler_type = B_BENDIAN_TO_HOST_INT32(theHeader.handler_type); Read(&theHeader.handler_type);
Read(&theHeader.Reserved[0]);
Read(&theHeader.Reserved[1]);
Read(&theHeader.Reserved[2]);
name = (char *)(malloc(getBytesRemaining())); name = (char *)(malloc(getBytesRemaining()));
theStream->Read(name,getBytesRemaining()); Read(name,getBytesRemaining());
} }
char *HDLRAtom::OnGetAtomName() char *HDLRAtom::OnGetAtomName()
@ -1456,11 +1496,10 @@ void VMHDAtom::OnProcessMetaData()
{ {
FullAtom::OnProcessMetaData(); FullAtom::OnProcessMetaData();
theStream->Read(&theHeader,sizeof(vmhd)); Read(&theHeader.GraphicsMode);
theHeader.GraphicsMode = B_BENDIAN_TO_HOST_INT16(theHeader.GraphicsMode); Read(&theHeader.OpColour[0]);
theHeader.OpColour[0] = B_BENDIAN_TO_HOST_INT16(theHeader.OpColour[0]); Read(&theHeader.OpColour[1]);
theHeader.OpColour[1] = B_BENDIAN_TO_HOST_INT16(theHeader.OpColour[1]); Read(&theHeader.OpColour[2]);
theHeader.OpColour[2] = B_BENDIAN_TO_HOST_INT16(theHeader.OpColour[2]);
} }
char *VMHDAtom::OnGetAtomName() char *VMHDAtom::OnGetAtomName()
@ -1480,8 +1519,8 @@ void SMHDAtom::OnProcessMetaData()
{ {
FullAtom::OnProcessMetaData(); FullAtom::OnProcessMetaData();
theStream->Read(&theHeader,sizeof(smhd)); Read(&theHeader.Balance);
theHeader.Balance = B_BENDIAN_TO_HOST_INT16(theHeader.Balance); Read(&theHeader.Reserved);
} }
char *SMHDAtom::OnGetAtomName() char *SMHDAtom::OnGetAtomName()

View File

@ -110,7 +110,7 @@ struct SampleToChunk {
uint32 FirstChunk; uint32 FirstChunk;
uint32 SamplesPerChunk; uint32 SamplesPerChunk;
uint32 SampleDescriptionID; uint32 SampleDescriptionID;
uint32 TotalPrevFrames; uint32 TotalPrevSamples;
}; };
// Note standard is 32bits offsets but later is 64 // Note standard is 32bits offsets but later is 64