本文整理汇总了C++中AP4_Atom::Detach方法的典型用法代码示例。如果您正苦于以下问题:C++ AP4_Atom::Detach方法的具体用法?C++ AP4_Atom::Detach怎么用?C++ AP4_Atom::Detach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AP4_Atom
的用法示例。
在下文中一共展示了AP4_Atom::Detach方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
/*----------------------------------------------------------------------
| AP4_Processor::Process
+---------------------------------------------------------------------*/
AP4_Result
AP4_Processor::Process(AP4_ByteStream& input,
AP4_ByteStream& output,
ProgressListener* listener,
AP4_AtomFactory& atom_factory)
{
// read all atoms
AP4_AtomParent top_level;
AP4_Atom* atom;
while (AP4_SUCCEEDED(atom_factory.CreateAtomFromStream(input, atom))) {
top_level.AddChild(atom);
}
// remove the [mdat] atom, keep a ref to [moov]
AP4_MoovAtom* moov = NULL;
AP4_List<AP4_Atom>::Item* atom_item = top_level.GetChildren().FirstItem();
while (atom_item) {
atom = atom_item->GetData();
AP4_List<AP4_Atom>::Item* next = atom_item->GetNext();
if (atom->GetType() == AP4_ATOM_TYPE_MDAT) {
atom->Detach();
delete atom;
} else if (atom->GetType() == AP4_ATOM_TYPE_MOOV) {
moov = (AP4_MoovAtom*)atom;
}
atom_item = next;
}
// initialize the processor
AP4_Result result = Initialize(top_level, input);
if (AP4_FAILED(result)) return result;
// process the tracks if we have a moov atom
AP4_Array<AP4_SampleLocator> locators;
AP4_Cardinal track_count = 0;
AP4_List<AP4_TrakAtom>* trak_atoms = NULL;
AP4_LargeSize mdat_payload_size = 0;
TrackHandler** handlers = NULL;
AP4_SampleCursor* cursors = NULL;
if (moov) {
// build an array of track sample locators
trak_atoms = &moov->GetTrakAtoms();
track_count = trak_atoms->ItemCount();
cursors = new AP4_SampleCursor[track_count];
handlers = new TrackHandler*[track_count];
for (AP4_Ordinal i=0; i<track_count; i++) {
handlers[i] = NULL;
}
unsigned int index = 0;
for (AP4_List<AP4_TrakAtom>::Item* item = trak_atoms->FirstItem(); item; item=item->GetNext()) {
AP4_TrakAtom* trak = item->GetData();
// find the stsd atom
AP4_ContainerAtom* stbl = AP4_DYNAMIC_CAST(AP4_ContainerAtom, trak->FindChild("mdia/minf/stbl"));
if (stbl == NULL) continue;
// see if there's an external data source for this track
AP4_ByteStream* trak_data_stream = &input;
for (AP4_List<ExternalTrackData>::Item* ditem = m_ExternalTrackData.FirstItem(); ditem; ditem=ditem->GetNext()) {
ExternalTrackData* tdata = ditem->GetData();
if (tdata->m_TrackId == trak->GetId()) {
trak_data_stream = tdata->m_MediaData;
break;
}
}
// create the track handler
handlers[index] = CreateTrackHandler(trak);
cursors[index].m_Locator.m_TrakIndex = index;
cursors[index].m_Locator.m_SampleTable = new AP4_AtomSampleTable(stbl, *trak_data_stream);
cursors[index].m_Locator.m_SampleIndex = 0;
cursors[index].m_Locator.m_ChunkIndex = 0;
cursors[index].m_Locator.m_SampleTable->GetSample(0, cursors[index].m_Locator.m_Sample);
index++;
}
// figure out the layout of the chunks
for (;;) {
// see which is the next sample to write
AP4_UI64 min_offset = (AP4_UI64)(-1);
int cursor = -1;
for (unsigned int i=0; i<track_count; i++) {
if (!cursors[i].m_EndReached &&
cursors[i].m_Locator.m_Sample.GetOffset() <= min_offset) {
min_offset = cursors[i].m_Locator.m_Sample.GetOffset();
cursor = i;
}
}
// stop if all cursors are exhausted
if (cursor == -1) break;
// append this locator to the layout list
AP4_SampleLocator& locator = cursors[cursor].m_Locator;
locators.Append(locator);
//.........这里部分代码省略.........
示例2: PrintUsageAndExit
//.........这里部分代码省略.........
fprintf(stderr, "--track-id option specified, but no such track found\n");
return 1;
}
Options.track_filter = track->GetId();
}
// save the init segment
AP4_ByteStream* output = NULL;
result = AP4_FileByteStream::Create(Options.init_segment_name, AP4_FileByteStream::STREAM_MODE_WRITE, output);
if (AP4_FAILED(result)) {
fprintf(stderr, "ERROR: cannot open output file (%d)\n", result);
return 1;
}
AP4_FtypAtom* ftyp = file->GetFileType();
if (ftyp) {
result = ftyp->Write(*output);
if (AP4_FAILED(result)) {
fprintf(stderr, "ERROR: cannot write ftyp segment (%d)\n", result);
return 1;
}
}
if (Options.track_filter) {
AP4_MoovAtom* moov = movie->GetMoovAtom();
// only keep the 'trak' atom that we need
AP4_List<AP4_Atom>::Item* child = moov->GetChildren().FirstItem();
while (child) {
AP4_Atom* atom = child->GetData();
child = child->GetNext();
if (atom->GetType() == AP4_ATOM_TYPE_TRAK) {
AP4_TrakAtom* trak = (AP4_TrakAtom*)atom;
AP4_TkhdAtom* tkhd = (AP4_TkhdAtom*)trak->GetChild(AP4_ATOM_TYPE_TKHD);
if (tkhd && tkhd->GetTrackId() != Options.track_filter) {
atom->Detach();
delete atom;
}
}
}
// only keep the 'trex' atom that we need
AP4_ContainerAtom* mvex = AP4_DYNAMIC_CAST(AP4_ContainerAtom, moov->GetChild(AP4_ATOM_TYPE_MVEX));
if (mvex) {
child = mvex->GetChildren().FirstItem();
while (child) {
AP4_Atom* atom = child->GetData();
child = child->GetNext();
if (atom->GetType() == AP4_ATOM_TYPE_TREX) {
AP4_TrexAtom* trex = AP4_DYNAMIC_CAST(AP4_TrexAtom, atom);
if (trex && trex->GetTrackId() != Options.track_filter) {
atom->Detach();
delete atom;
}
}
}
}
}
result = movie->GetMoovAtom()->Write(*output);
if (AP4_FAILED(result)) {
fprintf(stderr, "ERROR: cannot write init segment (%d)\n", result);
return 1;
}
AP4_Atom* atom = NULL;
unsigned int track_id = 0;
for (;!Options.init_only;) {
// process the next atom
示例3:
/*----------------------------------------------------------------------
| AP4_MoovAtom::AP4_MoovAtom
+---------------------------------------------------------------------*/
AP4_MoovAtom::AP4_MoovAtom(AP4_Size size,
AP4_ByteStream& stream,
AP4_AtomFactory& atom_factory) :
AP4_ContainerAtom(AP4_ATOM_TYPE_MOOV, size, false, stream, atom_factory),
m_TimeScale(0)
{
if(AP4_ContainerAtom* cmov = dynamic_cast<AP4_ContainerAtom*>(GetChild(AP4_ATOM_TYPE_CMOV)))
{
AP4_DcomAtom* dcom = dynamic_cast<AP4_DcomAtom*>(cmov->GetChild(AP4_ATOM_TYPE_DCOM));
AP4_CmvdAtom* cmvd = dynamic_cast<AP4_CmvdAtom*>(cmov->GetChild(AP4_ATOM_TYPE_CMVD));
if(dcom && dcom->GetCompressorSubType() == AP4_ATOM_TYPE('z','l','i','b') && cmvd)
{
const AP4_DataBuffer& data = cmvd->GetDataBuffer();
z_stream d_stream;
d_stream.zalloc = (alloc_func)0;
d_stream.zfree = (free_func)0;
d_stream.opaque = (voidpf)0;
int res;
if(Z_OK == (res = inflateInit(&d_stream)))
{
d_stream.next_in = (Bytef*)data.GetData();
d_stream.avail_in = data.GetDataSize();
unsigned char* dst = NULL;
int n = 0;
do
{
dst = (unsigned char*)realloc(dst, ++n*1000);
d_stream.next_out = &dst[(n-1)*1000];
d_stream.avail_out = 1000;
if(Z_OK != (res = inflate(&d_stream, Z_NO_FLUSH)) && Z_STREAM_END != res)
{
free(dst);
dst = NULL;
break;
}
}
while(0 == d_stream.avail_out && 0 != d_stream.avail_in && Z_STREAM_END != res);
inflateEnd(&d_stream);
if(dst)
{
AP4_ByteStream* s = new AP4_MemoryByteStream(dst, d_stream.total_out);
ReadChildren(atom_factory, *s, d_stream.total_out);
s->Release();
free(dst);
}
if(AP4_MoovAtom* moov = dynamic_cast<AP4_MoovAtom*>(GetChild(AP4_ATOM_TYPE_MOOV)))
{
AP4_List<AP4_Atom> Children;
for(AP4_List<AP4_Atom>::Item* item = moov->GetChildren().FirstItem();
item;
item = item->GetNext())
{
Children.Add(item->GetData());
}
for(AP4_List<AP4_Atom>::Item* item = Children.FirstItem();
item;
item = item->GetNext())
{
AP4_Atom* atom = item->GetData();
atom->Detach();
atom->SetParent(this);
m_Children.Add(atom);
}
moov->Detach();
delete moov;
}
}
}
}
// collect all trak atoms
m_Children.Apply(AP4_TrakAtomCollector(&m_TrakAtoms));
}
示例4: while
/*----------------------------------------------------------------------
| AP4_Processor::Process
+---------------------------------------------------------------------*/
AP4_Result
AP4_Processor::Process(AP4_ByteStream& input,
AP4_ByteStream& output,
AP4_AtomFactory& atom_factory)
{
// read all atoms
AP4_AtomParent top_level;
AP4_Atom* atom;
while (AP4_SUCCEEDED(atom_factory.CreateAtomFromStream(input, atom))) {
top_level.AddChild(atom);
}
// remove the [mdat] and [free] atoms, keep a ref to [moov]
AP4_MoovAtom* moov = NULL;
AP4_List<AP4_Atom>::Item* atom_item = top_level.GetChildren().FirstItem();
while (atom_item) {
atom = atom_item->GetData();
AP4_List<AP4_Atom>::Item* next = atom_item->GetNext();
if (//atom->GetType() == AP4_ATOM_TYPE_FREE ||
atom->GetType() == AP4_ATOM_TYPE_MDAT) {
atom->Detach();
delete atom;
} else if (atom->GetType() == AP4_ATOM_TYPE_MOOV) {
moov = (AP4_MoovAtom*)atom;
}
atom_item = next;
}
// check that we have a moov atom
if (moov == NULL) return AP4_FAILURE;
// initialize the processor
AP4_Result result = Initialize(top_level);
if (AP4_FAILED(result)) return result;
// build an array of track sample cursors
AP4_List<AP4_TrakAtom>& trak_atoms = moov->GetTrakAtoms();
AP4_Cardinal track_count = trak_atoms.ItemCount();
AP4_SampleCursor* cursors = new AP4_SampleCursor[track_count];
TrackHandler** handlers = new TrackHandler*[track_count];
AP4_List<AP4_TrakAtom>::Item* item = trak_atoms.FirstItem();
unsigned int index = 0;
while (item) {
// create the track handler // find the stsd atom
AP4_ContainerAtom* stbl = dynamic_cast<AP4_ContainerAtom*>(
item->GetData()->FindChild("mdia/minf/stbl"));
if (stbl == NULL) continue;
handlers[index] = CreateTrackHandler(item->GetData());
cursors[index].m_Locator.m_TrakIndex = index;
cursors[index].m_Locator.m_SampleTable = new AP4_AtomSampleTable(stbl, input);
cursors[index].m_Locator.m_SampleIndex = 0;
cursors[index].m_Locator.m_SampleTable->GetSample(0, cursors[index].m_Locator.m_Sample);
cursors[index].m_Locator.m_Chunk = 1;
index++;
item = item->GetNext();
}
// figure out the layout of the chunks
AP4_Array<AP4_SampleLocator> locators;
for (;;) {
// see which is the next sample to write
unsigned int min_offset = 0xFFFFFFFF;
int cursor = -1;
for (unsigned int i=0; i<track_count; i++) {
if (cursors[i].m_Locator.m_SampleTable &&
cursors[i].m_Locator.m_Sample.GetOffset() <= min_offset) {
min_offset = cursors[i].m_Locator.m_Sample.GetOffset();
cursor = i;
}
}
// stop if all cursors are exhausted
if (cursor == -1) break;
// append this locator to the layout list
AP4_SampleLocator& locator = cursors[cursor].m_Locator;
locators.Append(locator);
//AP4_Debug("NEXT: track %d, sample %d:%d: offset=%d, size=%d\n",
// locator.m_TrakIndex,
// locator.m_Chunk,
// locator.m_SampleIndex,
// locator.m_Sample.GetOffset(),
// locator.m_Sample.GetSize());
// move the cursor to the next sample
locator.m_SampleIndex++;
if (locator.m_SampleIndex == locator.m_SampleTable->GetSampleCount()) {
// mark this track as completed
locator.m_SampleTable = NULL;
} else {
// get the next sample info
locator.m_SampleTable->GetSample(locator.m_SampleIndex,
locator.m_Sample);
AP4_Ordinal skip, sdesc;
locator.m_SampleTable->GetChunkForSample(locator.m_SampleIndex+1, // the internal API is 1-based
locator.m_Chunk,
skip, sdesc);
//.........这里部分代码省略.........