这篇教程C++ AP4_Sample类代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中AP4_Sample类的典型用法代码示例。如果您正苦于以下问题:C++ AP4_Sample类的具体用法?C++ AP4_Sample怎么用?C++ AP4_Sample使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。 在下文中一共展示了AP4_Sample类的24个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: buffer/*----------------------------------------------------------------------| AP4_HintTrackReader::WriteSampleRtpData+---------------------------------------------------------------------*/AP4_ResultAP4_HintTrackReader::WriteSampleRtpData(AP4_SampleRtpConstructor* constructor, AP4_ByteStream* data_stream){ AP4_Track* referenced_track = NULL; if (constructor->GetTrackRefIndex() == 0xFF) { // data is in the hint track referenced_track = &m_HintTrack; } else { // check if we have a media track if (m_MediaTrack == NULL) return AP4_FAILURE; referenced_track = m_MediaTrack; } // write the sample data AP4_Sample sample; AP4_Result result = referenced_track->GetSample(constructor->GetSampleNum()-1, // adjust sample); if (AP4_FAILED(result)) return result; AP4_DataBuffer buffer(constructor->GetLength()); result = sample.ReadData( buffer, constructor->GetLength(), constructor->GetSampleOffset()); if (AP4_FAILED(result)) return result; // write the data return data_stream->Write(buffer.GetData(), buffer.GetDataSize());}
开发者ID:AchimTuran,项目名称:inputstream.mpd,代码行数:30,
示例2: /*----------------------------------------------------------------------| AP4_MarlinIpmpTrackDecrypter:GetProcessedSampleSize+---------------------------------------------------------------------*/AP4_Size AP4_MarlinIpmpTrackDecrypter::GetProcessedSampleSize(AP4_Sample& sample){ // with CBC, we need to decrypt the last block to know what the padding was AP4_Size encrypted_size = sample.GetSize()-AP4_AES_BLOCK_SIZE; AP4_DataBuffer encrypted; AP4_DataBuffer decrypted; AP4_Size decrypted_size = AP4_CIPHER_BLOCK_SIZE; if (sample.GetSize() < 2*AP4_CIPHER_BLOCK_SIZE) { return 0; } AP4_Size offset = sample.GetSize()-2*AP4_CIPHER_BLOCK_SIZE; if (AP4_FAILED(sample.ReadData(encrypted, 2*AP4_CIPHER_BLOCK_SIZE, offset))) { return 0; } decrypted.Reserve(decrypted_size); m_Cipher->SetIV(encrypted.GetData()); if (AP4_FAILED(m_Cipher->ProcessBuffer(encrypted.GetData()+AP4_CIPHER_BLOCK_SIZE, AP4_CIPHER_BLOCK_SIZE, decrypted.UseData(), &decrypted_size, true))) { return 0; } unsigned int padding_size = AP4_CIPHER_BLOCK_SIZE-decrypted_size; return encrypted_size-padding_size;}
开发者ID:huangyt,项目名称:MyProjects,代码行数:30,
示例3: AutoDetectAudioFragmentDuration/*----------------------------------------------------------------------| AutoDetectAudioFragmentDuration+---------------------------------------------------------------------*/static unsigned int AutoDetectAudioFragmentDuration(AP4_ByteStream& stream, TrackCursor* cursor){ // remember where we are in the stream AP4_Position where = 0; stream.Tell(where); AP4_LargeSize stream_size = 0; stream.GetSize(stream_size); AP4_LargeSize bytes_available = stream_size-where; AP4_UI64 fragment_count = 0; AP4_UI32 last_fragment_size = 0; AP4_Atom* atom = NULL; while (AP4_SUCCEEDED(AP4_DefaultAtomFactory::Instance.CreateAtomFromStream(stream, bytes_available, atom))) { if (atom && atom->GetType() == AP4_ATOM_TYPE_MOOF) { AP4_ContainerAtom* moof = AP4_DYNAMIC_CAST(AP4_ContainerAtom, atom); AP4_TfhdAtom* tfhd = AP4_DYNAMIC_CAST(AP4_TfhdAtom, moof->FindChild("traf/tfhd")); if (tfhd && tfhd->GetTrackId() == cursor->m_Track->GetId()) { ++fragment_count; AP4_TrunAtom* trun = AP4_DYNAMIC_CAST(AP4_TrunAtom, moof->FindChild("traf/trun")); if (trun) { last_fragment_size = trun->GetEntries().ItemCount(); } } } delete atom; atom = NULL; } // restore the stream to its original position stream.Seek(where); // decide if we can infer an fragment size if (fragment_count == 0 || cursor->m_Samples->GetSampleCount() == 0) { return 0; } // don't count the last fragment if we have more than one if (fragment_count > 1 && last_fragment_size) { --fragment_count; } if (fragment_count <= 1 || cursor->m_Samples->GetSampleCount() < last_fragment_size) { last_fragment_size = 0; } AP4_Sample sample; AP4_UI64 total_duration = 0; for (unsigned int i=0; i<cursor->m_Samples->GetSampleCount()-last_fragment_size; i++) { cursor->m_Samples->GetSample(i, sample); total_duration += sample.GetDuration(); } return (unsigned int)AP4_ConvertTime(total_duration/fragment_count, cursor->m_Track->GetMediaTimeScale(), 1000);}
开发者ID:garybruckheimer,项目名称:raypackSuite,代码行数:54,
示例4: AutoDetectFragmentDuration/*----------------------------------------------------------------------| AutoDetectFragmentDuration+---------------------------------------------------------------------*/static unsigned int AutoDetectFragmentDuration(TrackCursor* cursor){ AP4_Sample sample; unsigned int sample_count = cursor->m_Samples->GetSampleCount(); // get the first sample as the starting point AP4_Result result = cursor->m_Samples->GetSample(0, sample); if (AP4_FAILED(result)) { fprintf(stderr, "ERROR: failed to read first sample/n"); return 0; } if (!sample.IsSync()) { fprintf(stderr, "ERROR: first sample is not an I frame/n"); return 0; } for (unsigned int interval = 1; interval < sample_count; interval++) { bool irregular = false; unsigned int sync_count = 0; unsigned int i; for (i = 0; i < sample_count; i += interval) { result = cursor->m_Samples->GetSample(i, sample); if (AP4_FAILED(result)) { fprintf(stderr, "ERROR: failed to read sample %d/n", i); return 0; } if (!sample.IsSync()) { irregular = true; break; } ++sync_count; } if (sync_count < 1) continue; if (!irregular) { // found a pattern AP4_UI64 duration = sample.GetDts(); double fps = (double)(interval*(sync_count-1))/((double)duration/(double)cursor->m_Track->GetMediaTimeScale()); if (Options.verbosity > 0) { printf("found regular I-frame interval: %d frames (at %.3f frames per second)/n", interval, (float)fps); } return (unsigned int)(1000.0*(double)interval/fps); } } return 0;}
开发者ID:garybruckheimer,项目名称:raypackSuite,代码行数:51,
示例5: /*----------------------------------------------------------------------| AP4_OmaDcfCbcSampleEncrypter::GetEncryptedSampleSize+---------------------------------------------------------------------*/AP4_SizeAP4_OmaDcfCbcSampleEncrypter::GetEncryptedSampleSize(AP4_Sample& sample){ AP4_Size sample_size = sample.GetSize(); AP4_Size padding_size = AP4_CIPHER_BLOCK_SIZE-(sample_size%AP4_CIPHER_BLOCK_SIZE); return sample_size+padding_size+AP4_CIPHER_BLOCK_SIZE+1;}
开发者ID:satram,项目名称:Bento4,代码行数:10,
示例6: assert/*----------------------------------------------------------------------| AP4_LinearReader::PopSample+---------------------------------------------------------------------*/boolAP4_LinearReader::PopSample(Tracker* tracker, AP4_Sample& sample, AP4_DataBuffer& sample_data){ SampleBuffer* head = NULL; if (AP4_SUCCEEDED(tracker->m_Samples.PopHead(head))) { assert(head->m_Sample); sample = *head->m_Sample; sample_data.SetData(head->m_Data.GetData(), head->m_Data.GetDataSize()); assert(m_BufferFullness >= sample.GetSize()); m_BufferFullness -= sample.GetSize(); delete head; return true; } return false;}
开发者ID:Fluffiest,项目名称:mpc-hc,代码行数:21,
示例7: /*----------------------------------------------------------------------| AP4_DecryptingSampleReader::ReadSampleData+---------------------------------------------------------------------*/AP4_Result AP4_DecryptingSampleReader::ReadSampleData(AP4_Sample& sample, AP4_DataBuffer& sample_data){ AP4_Result result = sample.ReadData(m_DataBuffer); if (AP4_FAILED(result)) return result; return m_Decrypter->DecryptSampleData(m_DataBuffer, sample_data);}
开发者ID:olegloa,项目名称:wkrj,代码行数:12,
示例8: GetSample virtual AP4_Result GetSample(AP4_Ordinal index, AP4_Sample& sample) { AP4_Result result = m_Track->GetSample(index, sample); if (AP4_SUCCEEDED(result)) { if (m_ForcedSync[index]) { sample.SetSync(true); } } return result; }
开发者ID:garybruckheimer,项目名称:raypackSuite,代码行数:9,
示例9: /*----------------------------------------------------------------------| AP4_IsmaTrackDecrypter::GetProcessedSampleSize+---------------------------------------------------------------------*/AP4_Size AP4_IsmaTrackDecrypter::GetProcessedSampleSize(AP4_Sample& sample){ AP4_Size isma_header_size = m_CipherParams->GetKeyIndicatorLength() + m_CipherParams->GetIvLength(); if (m_CipherParams->GetSelectiveEncryption()) { isma_header_size++; } return sample.GetSize()-isma_header_size;}
开发者ID:AeonAxan,项目名称:mpc-hc,代码行数:14,
示例10: IsIFrame/*----------------------------------------------------------------------| IsIFrame+---------------------------------------------------------------------*/static boolIsIFrame(AP4_Sample& sample, AP4_AvcSampleDescription* avc_desc) { AP4_DataBuffer sample_data; if (AP4_FAILED(sample.ReadData(sample_data))) { return false; } const unsigned char* data = sample_data.GetData(); AP4_Size size = sample_data.GetDataSize(); while (size >= avc_desc->GetNaluLengthSize()) { unsigned int nalu_length = 0; if (avc_desc->GetNaluLengthSize() == 1) { nalu_length = *data++; --size; } else if (avc_desc->GetNaluLengthSize() == 2) { nalu_length = AP4_BytesToUInt16BE(data); data += 2; size -= 2; } else if (avc_desc->GetNaluLengthSize() == 4) { nalu_length = AP4_BytesToUInt32BE(data); data += 4; size -= 4; } else { return false; } if (nalu_length <= size) { size -= nalu_length; } else { size = 0; } switch (*data & 0x1F) { case 1: { AP4_BitStream bits; bits.WriteBytes(data+1, 8); ReadGolomb(bits); unsigned int slice_type = ReadGolomb(bits); if (slice_type == 2 || slice_type == 7) { return true; } else { return false; // only show first slice type } } case 5: return true; } data += nalu_length; } return false;}
开发者ID:garybruckheimer,项目名称:raypackSuite,代码行数:57,
示例11: AP4_SyntheticSampleTable/*----------------------------------------------------------------------| AP4_Track::Clone+---------------------------------------------------------------------*/AP4_Track* AP4_Track::Clone(AP4_Result* result){ AP4_SyntheticSampleTable* sample_table = new AP4_SyntheticSampleTable(); // default return value if (result) *result = AP4_SUCCESS; // add clones of the sample descriptions to the new sample table for (unsigned int i=0; ;i++) { AP4_SampleDescription* sample_description = GetSampleDescription(i); if (sample_description == NULL) break; sample_table->AddSampleDescription(sample_description->Clone()); } AP4_Sample sample; AP4_Ordinal index = 0; while (AP4_SUCCEEDED(GetSample(index, sample))) { AP4_ByteStream* data_stream; data_stream = sample.GetDataStream(); sample_table->AddSample(*data_stream, sample.GetOffset(), sample.GetSize(), sample.GetDuration(), sample.GetDescriptionIndex(), sample.GetDts(), sample.GetCtsDelta(), sample.IsSync()); AP4_RELEASE(data_stream); // release our ref, the table has kept its own ref. index++; } // create the cloned track AP4_Track* clone = new AP4_Track(GetType(), sample_table, GetId(), GetMovieTimeScale(), GetDuration(), GetMediaTimeScale(), GetMediaDuration(), GetTrackLanguage(), GetWidth(), GetHeight()); return clone;}
开发者ID:danelledeano,项目名称:VTech-InnoTab,代码行数:49,
示例12: GetSample/*----------------------------------------------------------------------| AP4_Track::ReadSample+---------------------------------------------------------------------*/AP4_Result AP4_Track::ReadSample(AP4_Ordinal index, AP4_Sample& sample, AP4_DataBuffer& data){ AP4_Result result; // get the sample result = GetSample(index, sample); if (AP4_FAILED(result)) return result; // read the data return sample.ReadData(data);}
开发者ID:Fluffiest,项目名称:splayer,代码行数:17,
示例13: StoreSampleAP4_Result SampleFileStorage::StoreSample(AP4_Sample& from_sample, AP4_Sample& to_sample) { // clone the sample fields to_sample = from_sample; // read the sample data AP4_DataBuffer sample_data; AP4_Result result = from_sample.ReadData(sample_data); if (AP4_FAILED(result)) return result; // mark where we are going to store the sample data AP4_Position position; m_Stream->Tell(position); to_sample.SetOffset(position); // write the sample data result = m_Stream->Write(sample_data.GetData(), sample_data.GetDataSize()); if (AP4_FAILED(result)) return result; // update the stream for the new sample to_sample.SetDataStream(*m_Stream); return AP4_SUCCESS;}
开发者ID:VideoInsight,项目名称:TranscodeModules,代码行数:23,
示例14: ReadSample/*----------------------------------------------------------------------| ReadSample+---------------------------------------------------------------------*/static AP4_ResultReadSample(SampleReader& reader, AP4_Track& track, AP4_Sample& sample, AP4_DataBuffer& sample_data, double& ts, bool& eos){ AP4_Result result = reader.ReadSample(sample, sample_data); if (AP4_FAILED(result)) { if (result == AP4_ERROR_EOS) { eos = true; } else { return result; } } ts = (double)sample.GetDts()/(double)track.GetMediaTimeScale(); return AP4_SUCCESS;}
开发者ID:garybruckheimer,项目名称:raypackSuite,代码行数:23,
示例15: ShowSample/*----------------------------------------------------------------------| ShowSample+---------------------------------------------------------------------*/static voidShowSample(AP4_Sample& sample, unsigned int index, AP4_SampleDecrypter* sample_decrypter){ printf("[%06d] size=%6d duration=%6d", index, (int)sample.GetSize(), (int)sample.GetDuration()); printf(" offset=%10lld dts=%10lld cts=%10lld ", sample.GetOffset(), sample.GetDts(), sample.GetCts()); if (sample.IsSync()) { printf(" [S] "); } else { printf(" "); } AP4_DataBuffer sample_data; sample.ReadData(sample_data); AP4_DataBuffer* data = &sample_data; AP4_DataBuffer decrypted_sample_data; if (sample_decrypter) { sample_decrypter->DecryptSampleData(sample_data, decrypted_sample_data); data = & decrypted_sample_data; } unsigned int show = data->GetDataSize(); if (show > 12) show = 12; // max first 12 chars for (unsigned int i=0; i<show; i++) { printf("%02x", data->GetData()[i]); } if (show == data->GetDataSize()) { printf("/n"); } else { printf(".../n"); }}
开发者ID:danelledeano,项目名称:VTech-InnoTab,代码行数:42,
示例16: main//.........这里部分代码省略......... fprintf(stderr, "ERROR: no video track found/n"); return 1; } } else if (!strncmp("subtitles", track_selector, 9)) { if (subtitles_track) { selected_track_id = subtitles_track->m_Track->GetId(); } else { fprintf(stderr, "ERROR: no subtitles track found/n"); return 1; } } else { selected_track_id = (AP4_UI32)strtol(track_selector, NULL, 10); bool found = false; for (unsigned int i=0; i<cursors.ItemCount(); i++) { if (cursors[i]->m_Track->GetId() == selected_track_id) { found = true; break; } } if (!found) { fprintf(stderr, "ERROR: track not found/n"); return 1; } } } if (video_track_count == 0 && audio_track_count == 0 && subtitles_track_count == 0) { fprintf(stderr, "ERROR: no audio, video, or subtitles track in the file/n"); return 1; } AP4_AvcSampleDescription* avc_desc = NULL; if (video_track && (Options.force_i_frame_sync != AP4_FRAGMENTER_FORCE_SYNC_MODE_NONE)) { // that feature is only supported for AVC AP4_SampleDescription* sdesc = video_track->m_Track->GetSampleDescription(0); if (sdesc) { avc_desc = AP4_DYNAMIC_CAST(AP4_AvcSampleDescription, sdesc); } if (avc_desc == NULL) { fprintf(stderr, "--force-i-frame-sync can only be used with AVC/H.264 video/n"); return 1; } } // remember where the stream was AP4_Position position; input_stream->Tell(position); // for fragmented input files, we need to populate the sample arrays if (input_file.GetMovie()->HasFragments()) { AP4_LinearReader reader(*input_file.GetMovie(), input_stream); for (unsigned int i=0; i<cursors.ItemCount(); i++) { reader.EnableTrack(cursors[i]->m_Track->GetId()); } AP4_UI32 track_id; AP4_Sample sample; do { result = reader.GetNextSample(sample, track_id); if (AP4_SUCCEEDED(result)) { for (unsigned int i=0; i<cursors.ItemCount(); i++) { if (cursors[i]->m_Track->GetId() == track_id) { cursors[i]->m_Samples->AddSample(sample); break; } } } } while (AP4_SUCCEEDED(result));
开发者ID:garybruckheimer,项目名称:raypackSuite,代码行数:67,
示例17: Mp4Parser_Seek/*----------------------------------------------------------------------| Mp4Parser_Seek+---------------------------------------------------------------------*/BLT_METHODMp4Parser_Seek(BLT_MediaNode* _self, BLT_SeekMode* mode, BLT_SeekPoint* point){ Mp4Parser* self = ATX_SELF_EX(Mp4Parser, BLT_BaseMediaNode, BLT_MediaNode); /* estimate the seek point */ if (ATX_BASE(self, BLT_BaseMediaNode).context == NULL) return BLT_FAILURE; BLT_Stream_EstimateSeekPoint(ATX_BASE(self, BLT_BaseMediaNode).context, *mode, point); if (!(point->mask & BLT_SEEK_POINT_MASK_TIME_STAMP)) { return BLT_FAILURE; } /* seek to the estimated offset on all tracks */ AP4_Ordinal sample_index = 0; AP4_UI32 ts_ms = point->time_stamp.seconds*1000+point->time_stamp.nanoseconds/1000000; if (self->video_output.track) { AP4_Result result = self->video_output.track->GetSampleIndexForTimeStampMs(ts_ms, sample_index); if (AP4_FAILED(result)) { ATX_LOG_WARNING_1("video GetSampleIndexForTimeStampMs failed (%d)", result); return BLT_FAILURE; } ATX_LOG_FINE_1("seeking to video time %d ms", ts_ms); // go to the nearest sync sample self->video_output.sample = self->video_output.track->GetNearestSyncSampleIndex(sample_index); if (self->input.reader) { self->input.reader->SetSampleIndex(self->video_output.track->GetId(), self->video_output.sample); } ATX_LOG_FINE_1("seeking to video sync sample %d", self->video_output.sample); // compute the timestamp of the video sample we're seeking to, so we can pick an audio // sample that is close in time (there are many more audio sync points than video) AP4_Sample sample; if (AP4_SUCCEEDED(self->video_output.track->GetSample(self->video_output.sample, sample))) { AP4_UI32 media_timescale = self->video_output.track->GetMediaTimeScale(); if (media_timescale) { ts_ms = (AP4_UI32)((((AP4_UI64)sample.GetCts())*1000)/media_timescale); ATX_LOG_FINE_1("sync sample time is %d ms", ts_ms); } } else { ATX_LOG_FINE_1("unable to get sample info for sample %d", self->video_output.sample); } } if (self->audio_output.track) { AP4_Result result = self->audio_output.track->GetSampleIndexForTimeStampMs(ts_ms, sample_index); if (AP4_FAILED(result)) { ATX_LOG_WARNING_1("audio GetSampleIndexForTimeStampMs failed (%d)", result); return BLT_FAILURE; } self->audio_output.sample = sample_index; if (self->input.reader) { self->input.reader->SetSampleIndex(self->audio_output.track->GetId(), sample_index); } } /* set the mode so that the nodes down the chain know the seek has */ /* already been done on the stream */ *mode = BLT_SEEK_MODE_IGNORE; return BLT_SUCCESS;}
开发者ID:danelledeano,项目名称:VTech-InnoTab,代码行数:66,
示例18: Mp4ParserOutput_GetPacket/*----------------------------------------------------------------------| Mp4ParserOutput_GetPacket+---------------------------------------------------------------------*/BLT_METHODMp4ParserOutput_GetPacket(BLT_PacketProducer* _self, BLT_MediaPacket** packet){ Mp4ParserOutput* self = ATX_SELF(Mp4ParserOutput, BLT_PacketProducer); *packet = NULL; // if we don't have an input yet, we can't produce packets //if (self->parser->input.mp4_file == NULL) { // return BLT_ERROR_PORT_HAS_NO_DATA; //} if (self->track == NULL) { return BLT_ERROR_EOS; } else { // check for end-of-stream if (self->sample >= self->track->GetSampleCount()) { return BLT_ERROR_EOS; } // read one sample AP4_Sample sample; AP4_DataBuffer* sample_buffer = self->sample_buffer; AP4_Result result; if (self->parser->input.reader) { // linear reader mode result = self->parser->input.reader->ReadNextSample(self->track->GetId(), sample, *sample_buffer); if (AP4_SUCCEEDED(result)) self->sample++; } else { // normal mode result = self->track->ReadSample(self->sample++, sample, *sample_buffer); } if (AP4_FAILED(result)) { ATX_LOG_WARNING_1("ReadSample failed (%d)", result); if (result == AP4_ERROR_EOS || result == ATX_ERROR_OUT_OF_RANGE) { ATX_LOG_WARNING("incomplete media"); return BLT_ERROR_INCOMPLETE_MEDIA; } else { return BLT_ERROR_PORT_HAS_NO_DATA; } } // update the sample description if it has changed if (sample.GetDescriptionIndex() != self->sample_description_index) { result = Mp4ParserOutput_SetSampleDescription(self, sample.GetDescriptionIndex()); if (BLT_FAILED(result)) return result; } // decrypt the sample if needed if (self->sample_decrypter) { self->sample_decrypter->DecryptSampleData(*sample_buffer, *self->sample_decrypted_buffer); sample_buffer = self->sample_decrypted_buffer; } AP4_Size packet_size = sample_buffer->GetDataSize(); result = BLT_Core_CreateMediaPacket(ATX_BASE(self->parser, BLT_BaseMediaNode).core, packet_size, (const BLT_MediaType*)self->media_type, packet); if (BLT_FAILED(result)) return result; BLT_MediaPacket_SetPayloadSize(*packet, packet_size); void* buffer = BLT_MediaPacket_GetPayloadBuffer(*packet); ATX_CopyMemory(buffer, sample_buffer->GetData(), packet_size); // set the timestamp AP4_UI32 media_timescale = self->track->GetMediaTimeScale(); if (media_timescale) { AP4_UI64 ts = ((AP4_UI64)sample.GetCts())*1000000; ts /= media_timescale; BLT_TimeStamp bt_ts = { (BLT_Int32)(ts / 1000000), (BLT_Int32)((ts % 1000000)*1000) }; BLT_MediaPacket_SetTimeStamp(*packet, bt_ts); } // set packet flags if (self->sample == 1) { BLT_MediaPacket_SetFlags(*packet, BLT_MEDIA_PACKET_FLAG_START_OF_STREAM); } return BLT_SUCCESS; }}
开发者ID:danelledeano,项目名称:VTech-InnoTab,代码行数:88,
示例19: Fragment/*----------------------------------------------------------------------| Fragment+---------------------------------------------------------------------*/static voidFragment(AP4_File& input_file, AP4_ByteStream& output_stream, AP4_Array<TrackCursor*>& cursors, unsigned int fragment_duration, AP4_UI32 timescale, AP4_UI32 track_id, bool create_segment_index){ AP4_List<FragmentInfo> fragments; TrackCursor* index_cursor = NULL; AP4_Result result; AP4_Movie* input_movie = input_file.GetMovie(); if (input_movie == NULL) { fprintf(stderr, "ERROR: no moov found in the input file/n"); return; } // create the output file object AP4_Movie* output_movie = new AP4_Movie(1000); // create an mvex container AP4_ContainerAtom* mvex = new AP4_ContainerAtom(AP4_ATOM_TYPE_MVEX); AP4_MehdAtom* mehd = new AP4_MehdAtom(0); mvex->AddChild(mehd); // add an output track for each track in the input file for (unsigned int i=0; i<cursors.ItemCount(); i++) { AP4_Track* track = cursors[i]->m_Track; // skip non matching tracks if we have a selector if (track_id && track->GetId() != track_id) { continue; } result = cursors[i]->Init(); if (AP4_FAILED(result)) { fprintf(stderr, "ERROR: failed to init sample cursor (%d), skipping track %d/n", result, track->GetId()); return; } // create a sample table (with no samples) to hold the sample description AP4_SyntheticSampleTable* sample_table = new AP4_SyntheticSampleTable(); for (unsigned int j=0; j<track->GetSampleDescriptionCount(); j++) { AP4_SampleDescription* sample_description = track->GetSampleDescription(j); sample_table->AddSampleDescription(sample_description, false); } // create the track AP4_Track* output_track = new AP4_Track(sample_table, track->GetId(), timescale?timescale:1000, AP4_ConvertTime(track->GetDuration(), input_movie->GetTimeScale(), timescale?timescale:1000), timescale?timescale:track->GetMediaTimeScale(), 0,//track->GetMediaDuration(), track); output_movie->AddTrack(output_track); // add a trex entry to the mvex container AP4_TrexAtom* trex = new AP4_TrexAtom(track->GetId(), 1, 0, 0, 0); mvex->AddChild(trex); } // select the anchor cursor TrackCursor* anchor_cursor = NULL; for (unsigned int i=0; i<cursors.ItemCount(); i++) { if (cursors[i]->m_Track->GetId() == track_id) { anchor_cursor = cursors[i]; } } if (anchor_cursor == NULL) { for (unsigned int i=0; i<cursors.ItemCount(); i++) { // use this as the anchor track if it is the first video track if (cursors[i]->m_Track->GetType() == AP4_Track::TYPE_VIDEO) { anchor_cursor = cursors[i]; break; } } } if (anchor_cursor == NULL) { // no video track to anchor with, pick the first audio track for (unsigned int i=0; i<cursors.ItemCount(); i++) { if (cursors[i]->m_Track->GetType() == AP4_Track::TYPE_AUDIO) { anchor_cursor = cursors[i]; break; } } // no audio track to anchor with, pick the first subtitles track for (unsigned int i=0; i<cursors.ItemCount(); i++) { if (cursors[i]->m_Track->GetType() == AP4_Track::TYPE_SUBTITLES) {//.........这里部分代码省略.........
开发者ID:garybruckheimer,项目名称:raypackSuite,代码行数:101,
示例20: CreateFragmentHandler/*----------------------------------------------------------------------| AP4_Processor::ProcessFragments+---------------------------------------------------------------------*/AP4_ResultAP4_Processor::ProcessFragment( AP4_ContainerAtom* moof, AP4_SidxAtom* sidx, AP4_Position sidx_position, AP4_ByteStream& output, AP4_Array<AP4_Position>& moof_positions, AP4_Array<AP4_Position>& mdat_positions){ unsigned int fragment_index = 0; //AP4_UI64 mdat_payload_offset = atom_offset+atom->GetSize()+AP4_ATOM_HEADER_SIZE; AP4_Sample sample; AP4_DataBuffer sample_data_in; AP4_DataBuffer sample_data_out; AP4_Result result = AP4_SUCCESS; // parse the moof //AP4_MovieFragment* fragment = new AP4_MovieFragment(moof); // process all the traf atoms AP4_Array<AP4_Processor::FragmentHandler*> handlers; AP4_Array<AP4_FragmentSampleTable*> sample_tables; for (; AP4_Atom* child = moof->GetChild(AP4_ATOM_TYPE_TRAF, handlers.ItemCount());) { AP4_TrafAtom* traf = AP4_DYNAMIC_CAST(AP4_TrafAtom, child); PERTRACK &track_data(m_TrackData[traf->GetInternalTrackId()]); AP4_TrakAtom* trak = track_data.track_handler->GetTrakAtom(); AP4_TrexAtom* trex = track_data.track_handler->GetTrexAtom(); // create the handler for this traf AP4_Processor::FragmentHandler* handler = CreateFragmentHandler(trak, trex, traf, *(m_StreamData[track_data.streamId].stream), moof_positions[track_data.streamId]); if (handler) { result = handler->ProcessFragment(); if (AP4_FAILED(result)) return result; } handlers.Append(handler); // create a sample table object so we can read the sample data AP4_FragmentSampleTable* sample_table = new AP4_FragmentSampleTable( traf, trex, traf->GetInternalTrackId(), m_StreamData[track_data.streamId].stream, moof_positions[traf->GetInternalTrackId()], mdat_positions[traf->GetInternalTrackId()], 0); sample_tables.Append(sample_table); // let the handler look at the samples before we process them if (handler) result = handler->PrepareForSamples(sample_table); if (AP4_FAILED(result)) return result; } output.Buffer(); // write the moof AP4_UI64 moof_out_start = 0; output.Tell(moof_out_start); moof->Write(output); // remember the location of this fragment FragmentMapEntry map_entry = { moof_positions[0], moof_out_start }; fragment_map_.Append(map_entry); // write an mdat header AP4_Position mdat_out_start; AP4_UI64 mdat_size = AP4_ATOM_HEADER_SIZE; output.Tell(mdat_out_start); output.WriteUI32(0); output.WriteUI32(AP4_ATOM_TYPE_MDAT); // process all track runs for (unsigned int i=0; i<handlers.ItemCount(); i++) { 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)); if (traf == NULL) continue; AP4_TfhdAtom* tfhd = AP4_DYNAMIC_CAST(AP4_TfhdAtom, traf->GetChild(AP4_ATOM_TYPE_TFHD)); // compute the base data offset AP4_UI64 base_data_offset; if (tfhd->GetFlags() & AP4_TFHD_FLAG_BASE_DATA_OFFSET_PRESENT) { base_data_offset = mdat_out_start+AP4_ATOM_HEADER_SIZE; } else { base_data_offset = moof_out_start; } // build a list of all trun atoms AP4_Array<AP4_TrunAtom*> truns; for (AP4_List<AP4_Atom>::Item* child_item = traf->GetChildren().FirstItem(); child_item;//.........这里部分代码省略.........
开发者ID:AchimTuran,项目名称:inputstream.mpd,代码行数:101,
示例21: SDKImportAudio7static prMALError SDKImportAudio7( imStdParms *stdParms, imFileRef SDKfileRef, imImportAudioRec7 *audioRec7){ prMALError result = malNoError; // privateData ImporterLocalRec8H ldataH = reinterpret_cast<ImporterLocalRec8H>(audioRec7->privateData); stdParms->piSuites->memFuncs->lockHandle(reinterpret_cast<char**>(ldataH)); ImporterLocalRec8Ptr localRecP = reinterpret_cast<ImporterLocalRec8Ptr>( *ldataH ); if(localRecP && localRecP->audio_track && localRecP->alac) { assert(localRecP->reader != NULL); assert(localRecP->file != NULL && localRecP->file->GetMovie() != NULL); assert(audioRec7->position >= 0); // Do they really want contiguous samples? assert(audioRec7->position < localRecP->duration); if(audioRec7->size > localRecP->duration - audioRec7->position) { // this does happen, we get asked for audio data past the duration // let's make sure there's no garbage there and re-set audioRec7->size for(int c=0; c < localRecP->numChannels; c++) { memset(audioRec7->buffer[c], 0, sizeof(float) * audioRec7->size); } audioRec7->size = localRecP->duration - audioRec7->position; } const AP4_UI32 timestamp_ms = audioRec7->position * 1000 / localRecP->audioSampleRate; const size_t bytes_per_sample = (localRecP->alac->mConfig.bitDepth <= 16 ? 2 : 4); const size_t alac_buf_size = localRecP->alac->mConfig.frameLength * localRecP->alac->mConfig.numChannels * bytes_per_sample + kALACMaxEscapeHeaderBytes; uint8_t *alac_buffer = (uint8_t *)malloc(alac_buf_size); AP4_Ordinal sample_index = 0; AP4_Result ap4_result = localRecP->audio_track->GetSampleIndexForTimeStampMs(timestamp_ms, sample_index); if(ap4_result == AP4_SUCCESS) { // for surround channels // Premiere uses Left, Right, Left Rear, Right Rear, Center, LFE // ALAC uses Center, Left, Right, Left Rear, Right Rear, LFE // http://alac.macosforge.org/trac/browser/trunk/ReadMe.txt static const int surround_swizzle[] = {4, 0, 1, 2, 3, 5}; static const int stereo_swizzle[] = {0, 1, 2, 3, 4, 5}; // no swizzle, actually const int *swizzle = localRecP->numChannels > 2 ? surround_swizzle : stereo_swizzle; csSDK_uint32 samples_needed = audioRec7->size; PrAudioSample pos = 0; AP4_DataBuffer dataBuffer; while(samples_needed > 0 && ap4_result == AP4_SUCCESS && result == malNoError) { AP4_Sample sample; ap4_result = localRecP->audio_track->ReadSample(sample_index, sample, dataBuffer); if(ap4_result == AP4_SUCCESS) { const PrAudioSample sample_pos = sample.GetDts() * localRecP->audioSampleRate / localRecP->audio_track->GetMediaTimeScale(); const PrAudioSample sample_len = sample.GetDuration() * localRecP->audioSampleRate / localRecP->audio_track->GetMediaTimeScale(); const PrAudioSample skip_samples = (audioRec7->position > sample_pos) ? (audioRec7->position - sample_pos) : 0; long samples_to_read = sample_len - skip_samples; if(samples_to_read > samples_needed) samples_to_read = samples_needed; else if(samples_to_read < 0) samples_to_read = 0; if(samples_to_read > 0) { BitBuffer bits; BitBufferInit(&bits, dataBuffer.UseData(), dataBuffer.GetDataSize()); uint32_t outSamples = 0;//.........这里部分代码省略.........
开发者ID:fnordware,项目名称:AdobeALAC,代码行数:101,
示例22: AP4_ContainerAtom/*----------------------------------------------------------------------| AP4_SampleTable::GenerateStblAtom+---------------------------------------------------------------------*/AP4_Result AP4_SampleTable::GenerateStblAtom(AP4_ContainerAtom*& stbl){ // create the stbl container stbl = new AP4_ContainerAtom(AP4_ATOM_TYPE_STBL); // create the stsd atom AP4_StsdAtom* stsd = new AP4_StsdAtom(this); // create the stsz atom AP4_StszAtom* stsz = new AP4_StszAtom(); // create the stsc atom AP4_StscAtom* stsc = new AP4_StscAtom(); // create the stts atom AP4_SttsAtom* stts = new AP4_SttsAtom(); // create the stss atom AP4_StssAtom* stss = new AP4_StssAtom(); // declare the ctts atom (may be created later) AP4_CttsAtom* ctts = NULL; // start chunk table AP4_Ordinal current_chunk_index = 0; AP4_Size current_chunk_size = 0; AP4_Position current_chunk_offset = 0; AP4_Cardinal current_samples_in_chunk = 0; AP4_Ordinal current_sample_description_index = 0; AP4_UI32 current_duration = 0; AP4_Cardinal current_duration_run = 0; AP4_UI32 current_cts_delta = 0; AP4_Cardinal current_cts_delta_run = 0; AP4_Array<AP4_Position> chunk_offsets; // process all the samples bool all_samples_are_sync = false; AP4_Cardinal sample_count = GetSampleCount(); for (AP4_Ordinal i=0; i<sample_count; i++) { AP4_Sample sample; GetSample(i, sample); // update DTS table AP4_UI32 new_duration = sample.GetDuration(); if (new_duration != current_duration && current_duration_run != 0) { // emit a new stts entry stts->AddEntry(current_duration_run, current_duration); // reset the run count current_duration_run = 0; } ++current_duration_run; current_duration = new_duration; // update CTS table AP4_UI32 new_cts_delta = sample.GetCtsDelta(); if (new_cts_delta != current_cts_delta && current_cts_delta_run != 0) { // create a ctts atom if we don't have one if (ctts == NULL) ctts = new AP4_CttsAtom(); //emit a new ctts entry ctts->AddEntry(current_cts_delta_run, current_cts_delta); // reset the run count current_cts_delta_run = 0; } ++current_cts_delta_run; current_cts_delta = new_cts_delta; // add an entry into the stsz atom stsz->AddEntry(sample.GetSize()); // update the sync sample table if (sample.IsSync()) { stss->AddEntry(i+1); if (i==0) all_samples_are_sync = true; } else { all_samples_are_sync = false; } // see in which chunk this sample is AP4_Ordinal chunk_index = 0; AP4_Ordinal position_in_chunk = 0; AP4_Result result = GetSampleChunkPosition(i, chunk_index, position_in_chunk); if (AP4_SUCCEEDED(result)) { if (chunk_index != current_chunk_index && current_samples_in_chunk != 0) { // new chunk chunk_offsets.Append(current_chunk_offset); current_chunk_offset += current_chunk_size; stsc->AddEntry(1, current_samples_in_chunk, current_sample_description_index+1); current_samples_in_chunk = 0; current_chunk_size = 0;//.........这里部分代码省略.........
开发者ID:9aa5,项目名称:Bento4,代码行数:101,
示例23: /*----------------------------------------------------------------------| AP4_Processor::TrackHandler::GetProcessedSampleSize+---------------------------------------------------------------------*/AP4_Size AP4_Processor::TrackHandler::GetProcessedSampleSize(AP4_Sample& sample){ // default implementation: do no change the sample size return sample.GetSize();}
开发者ID:huangyt,项目名称:MyProjects,代码行数:9,
示例24: /*----------------------------------------------------------------------| TrackCursor::SetSampleIndex+---------------------------------------------------------------------*/AP4_ResultTrackCursor::SetSampleIndex(AP4_Ordinal sample_index){ m_SampleIndex = sample_index; // check if we're at the end if (sample_index >= m_Samples->GetSampleCount()) { AP4_UI64 end_dts = m_Sample.GetDts()+m_Sample.GetDuration(); m_Sample.Reset(); m_Sample.SetDts(end_dts); m_Eos = true; } else { return m_Samples->GetSample(m_SampleIndex, m_Sample); } return AP4_SUCCESS;}
开发者ID:garybruckheimer,项目名称:raypackSuite,代码行数:20,
注:本文中的AP4_Sample类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ APDU类代码示例 C++ AP4_DataBuffer类代码示例 |