void MP4DescriptorProperty::Read(MP4File* pFile, u_int32_t index) { ASSERT(index == 0); if (m_implicit) { return; } u_int64_t start = pFile->GetPosition(); while (true) { // enforce size limitation if (m_sizeLimit && pFile->GetPosition() >= start + m_sizeLimit) { break; } u_int8_t tag; try { pFile->PeekBytes(&tag, 1); } catch (MP4Error* e) { if (pFile->GetPosition() >= pFile->GetSize()) { // EOF delete e; break; } throw e; } // check if tag is in desired range if (tag < m_tagsStart || tag > m_tagsEnd) { break; } MP4Descriptor* pDescriptor = AddDescriptor(tag); pDescriptor->Read(pFile); } // warnings if (m_mandatory && m_pDescriptors.Size() == 0) { VERBOSE_READ(pFile->GetVerbosity(), printf("Warning: Mandatory descriptor 0x%02x missing\n", m_tagsStart)); } else if (m_onlyOne && m_pDescriptors.Size() > 1) { VERBOSE_READ(pFile->GetVerbosity(), printf("Warning: Descriptor 0x%02x has more than one instance\n", m_tagsStart)); } }
void MP4RtpAtom::Read() { if (!strcmp(m_pParentAtom->GetType(), "stsd")) { AddPropertiesStsdType(); ReadStsdType(); } else if (!strcmp(m_pParentAtom->GetType(), "hnti")) { AddPropertiesHntiType(); ReadHntiType(); } else { VERBOSE_READ(m_pFile->GetVerbosity(), printf("rtp atom in unexpected context, can not read")); } Skip(); // to end of atom }
void MP4DrefAtom::Read() { /* do the usual read */ MP4Atom::Read(); // check that number of children == entryCount MP4Integer32Property* pCount = (MP4Integer32Property*)m_pProperties[2]; if (m_pChildAtoms.Size() != pCount->GetValue()) { VERBOSE_READ(GetVerbosity(), MP4Printf("Warning: dref inconsistency with number of entries")); /* fix it */ pCount->SetReadOnly(false); pCount->SetValue(m_pChildAtoms.Size()); pCount->SetReadOnly(true); } }
MP4SampleId MP4Track::GetSampleIdFromTime( MP4Timestamp when, bool wantSyncSample) { u_int32_t numStts = m_pSttsCountProperty->GetValue(); MP4SampleId sid = 1; MP4Duration elapsed = 0; for (u_int32_t sttsIndex = 0; sttsIndex < numStts; sttsIndex++) { u_int32_t sampleCount = m_pSttsSampleCountProperty->GetValue(sttsIndex); u_int32_t sampleDelta = m_pSttsSampleDeltaProperty->GetValue(sttsIndex); if (sampleDelta == 0 && sttsIndex < numStts - 1) { VERBOSE_READ(m_pFile->GetVerbosity(), printf("Warning: Zero sample duration, stts entry %u\n", sttsIndex)); } MP4Duration d = when - elapsed; if (d <= sampleCount * sampleDelta) { MP4SampleId sampleId = sid; if (sampleDelta) { sampleId += (d / sampleDelta); } if (wantSyncSample) { return GetNextSyncSample(sampleId); } return sampleId; } sid += sampleCount; elapsed += sampleCount * sampleDelta; } throw new MP4Error("time out of range", "MP4Track::GetSampleIdFromTime"); return 0; // satisfy MS compiler }
void MP4ContentIdDescriptor::Read(MP4File* pFile) { ReadHeader(pFile); /* read the first property, 'compatiblity' */ ReadProperties(pFile, 0, 1); /* if compatiblity != 0 */ if (((MP4Integer8Property*)m_pProperties[0])->GetValue() != 0) { /* we don't understand it */ VERBOSE_READ(pFile->GetVerbosity(), printf("incompatible content id descriptor\n")); return; } /* read the next four properties */ ReadProperties(pFile, 1, 4); /* which allows us to reconfigure ourselves */ Mutate(); /* read the remaining properties */ ReadProperties(pFile, 5); }