本文整理汇总了C++中AP4_Sample::GetDuration方法的典型用法代码示例。如果您正苦于以下问题:C++ AP4_Sample::GetDuration方法的具体用法?C++ AP4_Sample::GetDuration怎么用?C++ AP4_Sample::GetDuration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AP4_Sample
的用法示例。
在下文中一共展示了AP4_Sample::GetDuration方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
/*----------------------------------------------------------------------
| 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);
}
示例2:
/*----------------------------------------------------------------------
| TrackCursor::SetSampleIndex
+---------------------------------------------------------------------*/
AP4_Result
TrackCursor::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;
}
示例3: GetSampleDescription
/*----------------------------------------------------------------------
| 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;
}
示例4: printf
/*----------------------------------------------------------------------
| ShowSample
+---------------------------------------------------------------------*/
static void
ShowSample(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");
}
}
示例5: mfra
/*----------------------------------------------------------------------
| Fragment
+---------------------------------------------------------------------*/
static void
Fragment(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) {
//.........这里部分代码省略.........
示例6: if
static 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;
//.........这里部分代码省略.........
示例7: GetSampleCount
/*----------------------------------------------------------------------
| 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;
//.........这里部分代码省略.........