void MP4RootAtom::FinishOptimalWrite() { // finish writing mdat m_pChildAtoms[GetLastMdatIndex()]->FinishWrite(m_pFile->Use64Bits("mdat")); // find moov atom u_int32_t size = m_pChildAtoms.Size(); MP4Atom* pMoovAtom = NULL; u_int32_t i; for (i = 0; i < size; i++) { if (!strcmp("moov", m_pChildAtoms[i]->GetType())) { pMoovAtom = m_pChildAtoms[i]; break; } } ASSERT(i < size); // rewrite moov so that updated chunkOffsets are written to disk m_pFile->SetPosition(pMoovAtom->GetStart()); u_int64_t oldSize = pMoovAtom->GetSize(); pMoovAtom->Write(); // sanity check u_int64_t newSize = pMoovAtom->GetSize(); ASSERT(oldSize == newSize); }
void MP4RootAtom::BeginWrite(bool use64) { // only call under MP4Create() control WriteAtomType("ftyp", OnlyOne); m_pChildAtoms[GetLastMdatIndex()]->BeginWrite(m_pFile->Use64Bits("mdat")); }
void MP4RootAtom::FinishWrite(bool use64) { if( m_rewrite_ftyp ) { const uint64_t savepos = m_pFile->GetPosition(); m_pFile->SetPosition( m_rewrite_ftypPosition ); m_rewrite_ftyp->Write(); const uint64_t newpos = m_pFile->GetPosition(); if( newpos > m_rewrite_freePosition ) m_rewrite_free->SetSize( m_rewrite_free->GetSize() - (newpos - m_rewrite_freePosition) ); // shrink else if( newpos < m_rewrite_freePosition ) m_rewrite_free->SetSize( m_rewrite_free->GetSize() + (m_rewrite_freePosition - newpos) ); // grow m_rewrite_free->Write(); m_pFile->SetPosition( savepos ); } // finish writing last mdat atom const uint32_t mdatIndex = GetLastMdatIndex(); m_pChildAtoms[mdatIndex]->FinishWrite( m_pFile->Use64Bits( "mdat" )); // write all atoms after last mdat const uint32_t size = m_pChildAtoms.Size(); for ( uint32_t i = mdatIndex + 1; i < size; i++ ) m_pChildAtoms[i]->Write(); }
void MP4RootAtom::BeginOptimalWrite() { WriteAtomType("ftyp", OnlyOne); WriteAtomType("moov", OnlyOne); WriteAtomType("udta", Many); m_pChildAtoms[GetLastMdatIndex()]->BeginWrite(m_pFile->Use64Bits("mdat")); }
void MP4RootAtom::FinishWrite(bool use64) { // finish writing last mdat atom u_int32_t mdatIndex = GetLastMdatIndex(); m_pChildAtoms[mdatIndex]->FinishWrite(m_pFile->Use64Bits("mdat")); // write all atoms after last mdat u_int32_t size = m_pChildAtoms.Size(); for (u_int32_t i = mdatIndex + 1; i < size; i++) { m_pChildAtoms[i]->Write(); } }
void MP4RootAtom::BeginWrite(bool use64) { m_rewrite_ftyp = (MP4FtypAtom*)FindChildAtom( "ftyp" ); if( m_rewrite_ftyp ) { m_rewrite_free = (MP4FreeAtom*)MP4Atom::CreateAtom( NULL, "free" ); m_rewrite_free->SetSize( 32*4 ); // room for 32 additional brands AddChildAtom( m_rewrite_free ); m_rewrite_ftypPosition = m_pFile->GetPosition(); m_rewrite_ftyp->Write(); m_rewrite_freePosition = m_pFile->GetPosition(); m_rewrite_free->Write(); } m_pChildAtoms[GetLastMdatIndex()]->BeginWrite( m_pFile->Use64Bits( "mdat" )); }