bool PictureAspectRatioBox::set( MP4FileHandle file, uint16_t trackIndex, const Item& item ) { MP4Atom* coding; if( findCoding( file, trackIndex, coding )) throw new MP4Exception( "supported coding not found" ); MP4Atom* pasp; if( findPictureAspectRatioBox( file, *coding, pasp )) throw new MP4Exception( "pasp-box not found" ); MP4Integer16Property* hSpacing; MP4Integer16Property* vSpacing; if( pasp->FindProperty( "pasp.hSpacing", (MP4Property**)&hSpacing )) hSpacing->SetValue( item.hSpacing ); if( pasp->FindProperty( "pasp.vSpacing", (MP4Property**)&vSpacing )) vSpacing->SetValue( item.vSpacing ); return false; }
FILE* MP4Track::GetSampleFile(MP4SampleId sampleId) { u_int32_t stscIndex = GetSampleStscIndex(sampleId); u_int32_t stsdIndex = m_pStscSampleDescrIndexProperty->GetValue(stscIndex); // check if the answer will be the same as last time if (m_lastStsdIndex && stsdIndex == m_lastStsdIndex) { return m_lastSampleFile; } MP4Atom* pStsdAtom = m_pTrakAtom->FindAtom("trak.mdia.minf.stbl.stsd"); ASSERT(pStsdAtom); MP4Atom* pStsdEntryAtom = pStsdAtom->GetChildAtom(stsdIndex - 1); ASSERT(pStsdEntryAtom); MP4Integer16Property* pDrefIndexProperty = NULL; pStsdEntryAtom->FindProperty( "*.dataReferenceIndex", (MP4Property**)&pDrefIndexProperty); if (pDrefIndexProperty == NULL) { throw new MP4Error("invalid stsd entry", "GetSampleFile"); } u_int32_t drefIndex = pDrefIndexProperty->GetValue(); MP4Atom* pDrefAtom = m_pTrakAtom->FindAtom("trak.mdia.minf.dinf.dref"); ASSERT(pDrefAtom); MP4Atom* pUrlAtom = pDrefAtom->GetChildAtom(drefIndex - 1); ASSERT(pUrlAtom); FILE* pFile; if (pUrlAtom->GetFlags() & 1) { pFile = NULL; // self-contained } else { #ifndef USE_FILE_CALLBACKS MP4StringProperty* pLocationProperty = NULL; pUrlAtom->FindProperty( "*.location", (MP4Property**)&pLocationProperty); ASSERT(pLocationProperty); const char* url = pLocationProperty->GetValue(); VERBOSE_READ_SAMPLE(m_pFile->GetVerbosity(), printf("dref url = %s\n", url)); pFile = (FILE*)-1; // attempt to open url if it's a file url // currently this is the only thing we understand if (!strncmp(url, "file:", 5)) { const char* fileName = url + 5; if (!strncmp(fileName, "//", 2)) { fileName = strchr(fileName + 2, '/'); } if (fileName) { pFile = fopen(fileName, "rb"); if (!pFile) { pFile = (FILE*)-1; } } } #else throw new MP4Error(errno, "Function not supported when using callbacks", "GetSampleFile"); #endif } if (m_lastSampleFile) { #ifndef USE_FILE_CALLBACKS fclose(m_lastSampleFile); #else throw new MP4Error(errno, "Function not supported when using callbacks", "GetSampleFile"); #endif } // cache the answer m_lastStsdIndex = stsdIndex; m_lastSampleFile = pFile; return pFile; }
void MP4File::CreateIsmaODUpdateCommandFromFileForFile( MP4TrackId odTrackId, MP4TrackId audioTrackId, MP4TrackId videoTrackId, u_int8_t** ppBytes, u_int64_t* pNumBytes) { MP4Descriptor* pCommand = CreateODCommand(MP4ODUpdateODCommandTag); pCommand->Generate(); for (u_int8_t i = 0; i < 2; i++) { MP4TrackId trackId; u_int16_t odId; if (i == 0) { trackId = audioTrackId; odId = 10; } else { trackId = videoTrackId; odId = 20; } if (trackId == MP4_INVALID_TRACK_ID) { continue; } MP4DescriptorProperty* pOdDescrProperty = (MP4DescriptorProperty*)(pCommand->GetProperty(0)); pOdDescrProperty->SetTags(MP4FileODescrTag); MP4Descriptor* pOd = pOdDescrProperty->AddDescriptor(MP4FileODescrTag); pOd->Generate(); MP4BitfieldProperty* pOdIdProperty = NULL; pOd->FindProperty("objectDescriptorId", (MP4Property**)&pOdIdProperty); pOdIdProperty->SetValue(odId); MP4DescriptorProperty* pEsIdsDescriptorProperty = NULL; pOd->FindProperty("esIds", (MP4Property**)&pEsIdsDescriptorProperty); ASSERT(pEsIdsDescriptorProperty); pEsIdsDescriptorProperty->SetTags(MP4ESIDRefDescrTag); MP4Descriptor *pRefDescriptor = pEsIdsDescriptorProperty->AddDescriptor(MP4ESIDRefDescrTag); pRefDescriptor->Generate(); MP4Integer16Property* pRefIndexProperty = NULL; pRefDescriptor->FindProperty("refIndex", (MP4Property**)&pRefIndexProperty); ASSERT(pRefIndexProperty); u_int32_t mpodIndex = FindTrackReference( MakeTrackName(odTrackId, "tref.mpod"), trackId); ASSERT(mpodIndex != 0); pRefIndexProperty->SetValue(mpodIndex); } pCommand->WriteToMemory(this, ppBytes, pNumBytes); delete pCommand; }