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)
{
getStream()->Read(pHeader,sizeof(array_header));
pHeader->NoEntries = B_BENDIAN_TO_HOST_INT32(pHeader->NoEntries);
Read(&pHeader->Version);
Read(&pHeader->Flags1);
Read(&pHeader->Flags2);
Read(&pHeader->Flags3);
Read(&pHeader->NoEntries);
}
BPositionIO *AtomBase::OnGetStream()
@ -140,6 +142,66 @@ BPositionIO *AtomBase::getStream()
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)
{
TotalChildren = 0;

View File

@ -132,6 +132,13 @@ public:
void setParent(AtomBase *pParent) {parentAtom = pParent;};
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 {

View File

@ -555,25 +555,6 @@ uint32 MOVFileReader::getChunkSize(uint32 stream_index, uint32 pFrameNo)
uint32 ChunkNo = pFrameNo;
off_t Chunk_Start = aTrakAtom->getOffsetForChunk(ChunkNo);
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;
}

View File

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

View File

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

View File

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

View File

@ -124,9 +124,7 @@ bool AtomBase::IsKnown()
void AtomBase::ReadArrayHeader(array_header *pHeader)
{
getStream()->Read(pHeader,sizeof(array_header));
pHeader->NoEntries = B_BENDIAN_TO_HOST_INT32(pHeader->NoEntries);
Read(&pHeader->NoEntries);
}
BPositionIO *AtomBase::OnGetStream()
@ -140,6 +138,77 @@ BPositionIO *AtomBase::getStream()
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)
{
}
@ -150,10 +219,10 @@ FullAtom::~FullAtom()
void FullAtom::OnProcessMetaData()
{
getStream()->Read(&Version,sizeof(uint8));
getStream()->Read(&Flags1,sizeof(uint8));
getStream()->Read(&Flags2,sizeof(uint8));
getStream()->Read(&Flags3,sizeof(uint8));
Read(&Version);
Read(&Flags1);
Read(&Flags2);
Read(&Flags3);
}
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;};
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 {

View File

@ -554,23 +554,6 @@ uint32 MP4FileReader::getChunkSize(uint32 stream_index, uint32 pFrameNo)
uint32 ChunkNo = pFrameNo;
off_t Chunk_Start = aTrakAtom->getOffsetForChunk(ChunkNo);
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;
}
@ -610,6 +593,7 @@ bool MP4FileReader::GetNextChunkInfo(uint32 stream_index, uint32 pFrameNo, off_t
*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)));
}

View File

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

View File

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