Example #1
0
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);
}
Example #2
0
void MP4File::MakeFtypAtom(char* majorBrand, u_int32_t minorVersion, char** supportedBrands, u_int32_t supportedBrandsCount)
{
    bool rewriteNeeded = false;
    u_int32_t currentSupportedBrandsCount;
    u_int64_t currentSize;
    u_int32_t i;




    MP4Atom* ftypAtom = m_pRootAtom->FindAtom("ftyp");
    ASSERT(ftypAtom);

    currentSize = ftypAtom->GetSize();

    MP4StringProperty* pMajorBrandProperty;
    ftypAtom->FindProperty(
        "ftyp.majorBrand",
        (MP4Property**)&pMajorBrandProperty);

    pMajorBrandProperty->SetValue(majorBrand);


    MP4Integer32Property* pMinorVersionProperty;
    ftypAtom->FindProperty(
        "ftype.minorVersion",
        (MP4Property**)&pMinorVersionProperty);

    pMinorVersionProperty->SetValue(minorVersion);

    MP4Integer32Property* pCompatibleBrandsCountProperty;
    ftypAtom->FindProperty(
        "ftyp.compatibleBrandsCount",
        (MP4Property**)&pCompatibleBrandsCountProperty);

    currentSupportedBrandsCount = pCompatibleBrandsCountProperty->GetValue();

    MP4TableProperty* pCompatibleBrandsProperty;
    ftypAtom->FindProperty(
        "ftyp.compatibleBrands",
        (MP4Property**)&pCompatibleBrandsProperty);

    MP4StringProperty* pBrandProperty = (MP4StringProperty*)
                                        pCompatibleBrandsProperty->GetProperty(0);
    ASSERT(pBrandProperty);

    for (i = 0 ; i < ((currentSupportedBrandsCount > supportedBrandsCount) ? supportedBrandsCount : currentSupportedBrandsCount) ; i++) {
        pBrandProperty->SetValue(supportedBrands[i], i);

    }

    if (i < supportedBrandsCount) {
        for ( ; i < supportedBrandsCount ; i++) {
            pBrandProperty->AddValue(supportedBrands[i]);
        }
    }

    if (currentSupportedBrandsCount != supportedBrandsCount) {
        rewriteNeeded = true;
        pBrandProperty->SetCount(supportedBrandsCount);
        pCompatibleBrandsCountProperty->SetReadOnly(false);
        pCompatibleBrandsCountProperty->SetValue(supportedBrandsCount);
        pCompatibleBrandsCountProperty->SetReadOnly(true);
    }

}