本文整理汇总了C++中AP4_Sample类的典型用法代码示例。如果您正苦于以下问题:C++ AP4_Sample类的具体用法?C++ AP4_Sample怎么用?C++ AP4_Sample使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AP4_Sample类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buffer
/*----------------------------------------------------------------------
| AP4_HintTrackReader::WriteSampleRtpData
+---------------------------------------------------------------------*/
AP4_Result
AP4_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());
}
示例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;
}
示例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);
}
示例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;
}
示例5:
/*----------------------------------------------------------------------
| AP4_OmaDcfCbcSampleEncrypter::GetEncryptedSampleSize
+---------------------------------------------------------------------*/
AP4_Size
AP4_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;
}
示例6: assert
/*----------------------------------------------------------------------
| AP4_LinearReader::PopSample
+---------------------------------------------------------------------*/
bool
AP4_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;
}
示例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);
}
示例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;
}
示例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;
}
示例10: IsIFrame
/*----------------------------------------------------------------------
| IsIFrame
+---------------------------------------------------------------------*/
static bool
IsIFrame(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;
}
示例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;
}
示例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);
}
示例13: StoreSample
AP4_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;
}
示例14: ReadSample
/*----------------------------------------------------------------------
| ReadSample
+---------------------------------------------------------------------*/
static AP4_Result
ReadSample(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;
}
示例15: ShowSample
/*----------------------------------------------------------------------
| 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");
}
}