本文整理汇总了C++中AP4_ContainerAtom::Write方法的典型用法代码示例。如果您正苦于以下问题:C++ AP4_ContainerAtom::Write方法的具体用法?C++ AP4_ContainerAtom::Write怎么用?C++ AP4_ContainerAtom::Write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AP4_ContainerAtom
的用法示例。
在下文中一共展示了AP4_ContainerAtom::Write方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: od_update
//.........这里部分代码省略.........
// add the iods atom to the moov atom (try to put it just after mvhd)
int iods_position = 0;
int item_position = 0;
for (AP4_List<AP4_Atom>::Item* item = moov->GetChildren().FirstItem();
item;
++item) {
++item_position;
if (item->GetData()->GetType() == AP4_ATOM_TYPE_MVHD) {
iods_position = item_position;
break;
}
}
AP4_Result result = moov->AddChild(iods, iods_position);
if (AP4_FAILED(result)) {
delete iods;
return result;
}
// create a sample table for the OD track
AP4_SyntheticSampleTable* od_sample_table = new AP4_SyntheticSampleTable();
// create the sample description for the OD track
AP4_MpegSystemSampleDescription* od_sample_description;
od_sample_description = new AP4_MpegSystemSampleDescription(AP4_STREAM_TYPE_OD,
AP4_OTI_MPEG4_SYSTEM,
NULL,
32768, // buffer size
1024, // max bitrate
512); // avg bitrate
od_sample_table->AddSampleDescription(od_sample_description, true);
// create the OD descriptor update
AP4_DescriptorUpdateCommand od_update(AP4_COMMAND_TAG_OBJECT_DESCRIPTOR_UPDATE);
for (unsigned int i=0; i<mpod->GetTrackIds().ItemCount(); i++) {
AP4_ObjectDescriptor* od = new AP4_ObjectDescriptor(AP4_DESCRIPTOR_TAG_MP4_OD, 256+i); // descriptor id = 256+i
od->AddSubDescriptor(new AP4_EsIdRefDescriptor(i+1)); // index into mpod (1-based)
od->AddSubDescriptor(new AP4_IpmpDescriptorPointer(i+1)); // descriptor id = i+1
od_update.AddDescriptor(od);
}
// create the IPMP descriptor update
AP4_DescriptorUpdateCommand ipmp_update(AP4_COMMAND_TAG_IPMP_DESCRIPTOR_UPDATE);
for (unsigned int i=0; i<mpod->GetTrackIds().ItemCount(); i++) {
// create the ipmp descriptor
AP4_IpmpDescriptor* ipmp_descriptor = new AP4_IpmpDescriptor(i+1, AP4_MARLIN_IPMPS_TYPE_MGSV);
// create the sinf container
AP4_ContainerAtom* sinf = new AP4_ContainerAtom(AP4_ATOM_TYPE_SINF);
// add the scheme type atom
sinf->AddChild(new AP4_SchmAtom(AP4_PROTECTION_SCHEME_TYPE_MARLIN_ACBC, 0x0100, NULL, true));
// setup the scheme info atom
const char* content_id = m_PropertyMap.GetProperty(mpod->GetTrackIds()[i], "ContentId");
if (content_id) {
AP4_ContainerAtom* schi = new AP4_ContainerAtom(AP4_ATOM_TYPE_SCHI);
schi->AddChild(new AP4_NullTerminatedStringAtom(AP4_ATOM_TYPE_8ID_, content_id));
sinf->AddChild(schi);
}
// serialize the sinf atom to a buffer and set it as the ipmp data
AP4_MemoryByteStream* sinf_data = new AP4_MemoryByteStream((AP4_Size)sinf->GetSize());
sinf->Write(*sinf_data);
ipmp_descriptor->SetData(sinf_data->GetData(), sinf_data->GetDataSize());
sinf_data->Release();
ipmp_update.AddDescriptor(ipmp_descriptor);
}
// add the sample with the descriptors and updates
AP4_MemoryByteStream* sample_data = new AP4_MemoryByteStream();
od_update.Write(*sample_data);
ipmp_update.Write(*sample_data);
od_sample_table->AddSample(*sample_data, 0, sample_data->GetDataSize(), 0, 0, 0, 0, true);
// create the OD track
AP4_TrakAtom* od_track = new AP4_TrakAtom(od_sample_table,
AP4_HANDLER_TYPE_ODSM,
"Bento4 Marlin OD Handler",
od_track_id,
0, 0,
1, 1000, 1, 0, "und",
0, 0);
// add an entry in the processor's stream table to indicate that the
// media data for the OD track is not in the file stream, but in our
// memory stream.
m_ExternalTrackData.Add(new ExternalTrackData(od_track_id, sample_data));
sample_data->Release();
// add a tref track reference atom
AP4_ContainerAtom* tref = new AP4_ContainerAtom(AP4_ATOM_TYPE_TREF);
tref->AddChild(mpod);
od_track->AddChild(tref, 1); // add after 'tkhd'
// add the track to the moov atoms (just after the last track)
moov->AddChild(od_track, od_track_position);
return AP4_SUCCESS;
}
示例2: od_update
//.........这里部分代码省略.........
wrapped_key.GetData(),
wrapped_key.GetDataSize());
schi->AddChild(gkey);
}
}
// create and add the security attributes (satr)
if (track_type != AP4_Track::TYPE_UNKNOWN && key != NULL && key != NULL) {
AP4_ContainerAtom* satr = new AP4_ContainerAtom(AP4_ATOM_TYPE_SATR);
switch (track_type) {
case AP4_Track::TYPE_AUDIO:
satr->AddChild(new AP4_NullTerminatedStringAtom(AP4_ATOM_TYPE_STYP, AP4_MARLIN_IPMP_STYP_AUDIO));
break;
case AP4_Track::TYPE_VIDEO:
satr->AddChild(new AP4_NullTerminatedStringAtom(AP4_ATOM_TYPE_STYP, AP4_MARLIN_IPMP_STYP_VIDEO));
break;
default:
break;
}
// add the signed attributes, if any
const char* signed_attributes = m_PropertyMap.GetProperty(mpod->GetTrackIds()[i], "SignedAttributes");
if (signed_attributes) {
// decode the hex-encoded data
unsigned int size = (unsigned int)AP4_StringLength(signed_attributes)/2;
AP4_DataBuffer attributes_atoms;
attributes_atoms.SetDataSize(size);
if (AP4_SUCCEEDED(AP4_ParseHex(signed_attributes, attributes_atoms.UseData(), size))) {
// parse all the atoms encoded in the data and add them to the 'schi' container
AP4_MemoryByteStream* mbs = new AP4_MemoryByteStream(attributes_atoms.GetData(),
attributes_atoms.GetDataSize());
do {
AP4_Atom* atom = NULL;
result = AP4_DefaultAtomFactory::Instance.CreateAtomFromStream(*mbs, atom);
if (AP4_SUCCEEDED(result) && atom) {
satr->AddChild(atom);
}
} while (AP4_SUCCEEDED(result));
mbs->Release();
}
}
// compute the hmac
AP4_MemoryByteStream* mbs = new AP4_MemoryByteStream();
satr->Write(*mbs);
AP4_Hmac* digester = NULL;
AP4_Hmac::Create(AP4_Hmac::SHA256, key->GetData(), key->GetDataSize(), digester);
digester->Update(mbs->GetData(), mbs->GetDataSize());
AP4_DataBuffer hmac_value;
digester->Final(hmac_value);
AP4_Atom* hmac = new AP4_UnknownAtom(AP4_ATOM_TYPE_HMAC, hmac_value.GetData(), hmac_value.GetDataSize());
schi->AddChild(satr);
schi->AddChild(hmac);
mbs->Release();
}
sinf->AddChild(schi);
// serialize the sinf atom to a buffer and set it as the ipmp data
AP4_MemoryByteStream* sinf_data = new AP4_MemoryByteStream((AP4_Size)sinf->GetSize());
sinf->Write(*sinf_data);
ipmp_descriptor->SetData(sinf_data->GetData(), sinf_data->GetDataSize());
sinf_data->Release();
ipmp_update.AddDescriptor(ipmp_descriptor);
}
// add the sample with the descriptors and updates
AP4_MemoryByteStream* sample_data = new AP4_MemoryByteStream();
od_update.Write(*sample_data);
ipmp_update.Write(*sample_data);
od_sample_table->AddSample(*sample_data, 0, sample_data->GetDataSize(), 0, 0, 0, 0, true);
// create the OD track
AP4_TrakAtom* od_track = new AP4_TrakAtom(od_sample_table,
AP4_HANDLER_TYPE_ODSM,
"Bento4 Marlin OD Handler",
od_track_id,
0, 0,
1, 1000, 1, 0, "und",
0, 0);
// add an entry in the processor's stream table to indicate that the
// media data for the OD track is not in the file stream, but in our
// memory stream.
m_ExternalTrackData.Add(new ExternalTrackData(od_track_id, sample_data));
sample_data->Release();
// add a tref track reference atom
AP4_ContainerAtom* tref = new AP4_ContainerAtom(AP4_ATOM_TYPE_TREF);
tref->AddChild(mpod);
od_track->AddChild(tref, 1); // add after 'tkhd'
// add the track to the moov atoms (just after the last track)
moov->AddChild(od_track, od_track_position);
return AP4_SUCCESS;
}
示例3: if
//.........这里部分代码省略.........
}
// process the tracks (ex: sample descriptions processing)
for (AP4_Ordinal i=0; i<track_count; i++) {
TrackHandler* handler = m_TrackData[i].track_handler;
if (handler)
handler->ProcessTrack();
}
}
// finalize the processor
Finalize(top_level);
if (!fragments) {
// calculate the size of all atoms combined
AP4_UI64 atoms_size = 0;
top_level.GetChildren().Apply(AP4_AtomSizeAdder(atoms_size));
// see if we need a 64-bit or 32-bit mdat
AP4_Size mdat_header_size = AP4_ATOM_HEADER_SIZE;
if (mdat_payload_size+mdat_header_size > 0xFFFFFFFF) {
// we need a 64-bit size
mdat_header_size += 8;
}
// adjust the chunk offsets
for (AP4_Ordinal i=0; i<track_count; i++) {
AP4_TrakAtom* trak;
trak_atoms->Get(i, trak);
trak->AdjustChunkOffsets(atoms_size+mdat_header_size);
}
// write all atoms
top_level.GetChildren().Apply(AP4_AtomListWriter(output));
// write mdat header
if (mdat_payload_size) {
if (mdat_header_size == AP4_ATOM_HEADER_SIZE) {
// 32-bit size
output.WriteUI32((AP4_UI32)(mdat_header_size+mdat_payload_size));
output.WriteUI32(AP4_ATOM_TYPE_MDAT);
} else {
// 64-bit size
output.WriteUI32(1);
output.WriteUI32(AP4_ATOM_TYPE_MDAT);
output.WriteUI64(mdat_header_size+mdat_payload_size);
}
}
}
// write the samples
if (moov) {
if (!fragments) {
#if defined(AP4_DEBUG)
AP4_Position before;
output.Tell(before);
#endif
AP4_Sample sample;
AP4_DataBuffer data_in;
AP4_DataBuffer data_out;
for (unsigned int i=0; i<locators.ItemCount(); i++) {
AP4_SampleLocator& locator = locators[i];
locator.m_Sample.ReadData(data_in);
TrackHandler* handler = m_TrackData[locator.m_TrakIndex].track_handler;
if (handler) {
result = handler->ProcessSample(data_in, data_out);
示例4: mfra
//.........这里部分代码省略.........
0,
0,
0);
mvex->AddChild(trex);
}
if (cursors.ItemCount() == 0) {
fprintf(stderr, "ERROR: no track found\n");
return;
}
for (unsigned int i=0; i<cursors.ItemCount(); i++) {
if (cursors[i]->m_Track->GetType() == AP4_Track::TYPE_VIDEO) {
cursors[i]->m_TargetDuration = AP4_ConvertTime(fragment_duration>AP4_FRAGMENTER_FRAGMENT_DURATION_TOLERANCE ?
fragment_duration-AP4_FRAGMENTER_FRAGMENT_DURATION_TOLERANCE : 0,
1000,
cursors[i]->m_Track->GetMediaTimeScale());
} else {
cursors[i]->m_TargetDuration = AP4_ConvertTime(fragment_duration,
1000,
cursors[i]->m_Track->GetMediaTimeScale());
}
}
// update the mehd duration
mehd->SetDuration(output_movie->GetDuration());
// the mvex container to the moov container
output_movie->GetMoovAtom()->AddChild(mvex);
// write the ftyp atom
AP4_FtypAtom* ftyp = input_file.GetFileType();
if (ftyp) {
ftyp->Write(output_stream);
}
// write the moov atom
output_movie->GetMoovAtom()->Write(output_stream);
// write all the fragments
unsigned int sequence_number = 1;
for(;;) {
// select the next track to read from
TrackCursor* cursor = NULL;
AP4_UI64 min_dts = (AP4_UI64)(-1);
for (unsigned int i=0; i<cursors.ItemCount(); i++) {
if (cursors[i]->m_Eos) continue;
AP4_UI64 dts = AP4_ConvertTime(cursors[i]->m_Sample.GetDts(),
cursors[i]->m_Track->GetMediaTimeScale(),
AP4_FRAGMENTER_BASE_TIMESCALE);
if (dts < min_dts) {
min_dts = dts;
cursor = cursors[i];
}
}
if (cursor == NULL) break; // all done
// compute the target end for the segment
cursor->m_EndDts = cursor->m_Sample.GetDts()+cursor->m_TargetDuration;
// emit a fragment for the selected track
if (Options.verbosity > 0) {
printf("fragment: track ID %d ", cursor->m_Track->GetId());
}
// remember the time and position of this fragment
示例5: CreateFragmentHandler
/*----------------------------------------------------------------------
| AP4_Processor::ProcessFragments
+---------------------------------------------------------------------*/
AP4_Result
AP4_Processor::ProcessFragments(AP4_MoovAtom* moov,
AP4_List<AP4_MoofLocator>& moofs,
AP4_ContainerAtom* mfra,
AP4_ByteStream& input,
AP4_ByteStream& output)
{
// FIXME: this only works for non-changing moofs
for (AP4_List<AP4_MoofLocator>::Item* item = moofs.FirstItem();
item;
item = item->GetNext()) {
AP4_MoofLocator* locator = item->GetData();
AP4_ContainerAtom* moof = locator->m_Moof;
AP4_UI64 moof_offset = locator->m_Offset;
AP4_UI64 mdat_payload_offset = moof_offset+moof->GetSize()+8;
AP4_MovieFragment* fragment = new AP4_MovieFragment(moof);
AP4_Sample sample;
AP4_DataBuffer sample_data_in;
AP4_DataBuffer sample_data_out;
AP4_Result result;
// process all the traf atoms
AP4_Array<AP4_Processor::FragmentHandler*> handlers;
for (;AP4_Atom* atom = moof->GetChild(AP4_ATOM_TYPE_TRAF, handlers.ItemCount());) {
AP4_ContainerAtom* traf = AP4_DYNAMIC_CAST(AP4_ContainerAtom, atom);
AP4_Processor::FragmentHandler* handler = CreateFragmentHandler(traf);
if (handler) result = handler->ProcessFragment();
handlers.Append(handler);
}
// write the moof
AP4_UI64 moof_out_start = 0;
output.Tell(moof_out_start);
bool moof_has_changed = false;
moof->Write(output);
// process all track runs
for (unsigned int i=0; i<handlers.ItemCount(); i++) {
AP4_FragmentSampleTable* sample_table = NULL;
AP4_Processor::FragmentHandler* handler = handlers[i];
// get the track ID
AP4_ContainerAtom* traf = AP4_DYNAMIC_CAST(AP4_ContainerAtom, moof->GetChild(AP4_ATOM_TYPE_TRAF, i));
AP4_TfhdAtom* tfhd = AP4_DYNAMIC_CAST(AP4_TfhdAtom, traf->GetChild(AP4_ATOM_TYPE_TFHD, i));
// create a sample table object so we can read the sample data
result = fragment->CreateSampleTable(moov, tfhd->GetTrackId(), &input, moof_offset, mdat_payload_offset, sample_table);
if (AP4_FAILED(result)) return result;
// compute the mdat size
AP4_UI64 mdat_size = 0;
for (unsigned int j=0; j<sample_table->GetSampleCount(); j++) {
result = sample_table->GetSample(j, sample);
if (AP4_FAILED(result)) return result;
mdat_size += sample.GetSize();
}
// write an mdat header
if (mdat_size > 0xFFFFFFFF-8) {
// we don't support large mdat fragments
return AP4_ERROR_OUT_OF_RANGE;
}
if (mdat_size) {
output.WriteUI32((AP4_UI32)(8+mdat_size));
output.WriteUI32(AP4_ATOM_TYPE_MDAT);
}
#if defined(AP4_DEBUG)
AP4_Position before;
output.Tell(before);
#endif
// write the mdat
for (unsigned int j=0; j<sample_table->GetSampleCount(); j++) {
result = sample_table->GetSample(j, sample);
if (AP4_FAILED(result)) return result;
sample.ReadData(sample_data_in);
// process the sample data
if (handler) {
result = handler->ProcessSample(sample_data_in, sample_data_out);
if (AP4_FAILED(result)) return result;
// write the sample data
result = output.Write(sample_data_out.GetData(), sample_data_out.GetDataSize());
if (AP4_FAILED(result)) return result;
// give the handler a chance to update the atoms
result = handler->FinishFragment();
if (AP4_SUCCEEDED(result)) moof_has_changed = true;
} else {
// write the sample data (unmodified)
result = output.Write(sample_data_in.GetData(), sample_data_in.GetDataSize());
if (AP4_FAILED(result)) return result;
}
}
//.........这里部分代码省略.........
示例6: if
//.........这里部分代码省略.........
current_chunk_size += sample_size;
mdat_payload_size += sample_size;
}
// process the tracks (ex: sample descriptions processing)
for (AP4_Ordinal i=0; i<track_count; i++) {
TrackHandler* handler = handlers[i];
if (handler) handler->ProcessTrack();
}
}
// finalize the processor
Finalize(top_level);
// calculate the size of all atoms combined
AP4_UI64 atoms_size = 0;
top_level.GetChildren().Apply(AP4_AtomSizeAdder(atoms_size));
// see if we need a 64-bit or 32-bit mdat
AP4_Size mdat_header_size = AP4_ATOM_HEADER_SIZE;
if (mdat_payload_size+mdat_header_size > 0xFFFFFFFF) {
// we need a 64-bit size
mdat_header_size += 8;
}
// adjust the chunk offsets
for (AP4_Ordinal i=0; i<track_count; i++) {
AP4_TrakAtom* trak;
trak_atoms->Get(i, trak);
trak->AdjustChunkOffsets(atoms_size+mdat_header_size);
}
// write all atoms
top_level.GetChildren().Apply(AP4_AtomListWriter(output));
// write mdat header
if (mdat_payload_size) {
if (mdat_header_size == AP4_ATOM_HEADER_SIZE) {
// 32-bit size
output.WriteUI32((AP4_UI32)(mdat_header_size+mdat_payload_size));
output.WriteUI32(AP4_ATOM_TYPE_MDAT);
} else {
// 64-bit size
output.WriteUI32(1);
output.WriteUI32(AP4_ATOM_TYPE_MDAT);
output.WriteUI64(mdat_header_size+mdat_payload_size);
}
}
#if defined(AP4_DEBUG)
AP4_Position before;
output.Tell(before);
#endif
// write the samples
if (moov) {
AP4_Sample sample;
AP4_DataBuffer data_in;
AP4_DataBuffer data_out;
for (unsigned int i=0; i<locators.ItemCount(); i++) {
AP4_SampleLocator& locator = locators[i];
locator.m_Sample.ReadData(data_in);
TrackHandler* handler = handlers[locator.m_TrakIndex];
if (handler) {
result = handler->ProcessSample(data_in, data_out);
if (AP4_FAILED(result)) return result;