本文整理汇总了C++中AP4_DataBuffer类的典型用法代码示例。如果您正苦于以下问题:C++ AP4_DataBuffer类的具体用法?C++ AP4_DataBuffer怎么用?C++ AP4_DataBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AP4_DataBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
/*----------------------------------------------------------------------
| AP4_OmaDcfCtrSampleEncrypter::EncryptSampleData
+---------------------------------------------------------------------*/
AP4_Result
AP4_OmaDcfCtrSampleEncrypter::EncryptSampleData(AP4_DataBuffer& data_in,
AP4_DataBuffer& data_out,
AP4_UI64 counter,
bool /*skip_encryption*/)
{
// setup the buffers
const unsigned char* in = data_in.GetData();
AP4_CHECK(data_out.SetDataSize(data_in.GetDataSize()+AP4_CIPHER_BLOCK_SIZE+1));
unsigned char* out = data_out.UseData();
// selective encryption flag
*out++ = 0x80;
// IV on 16 bytes: [SSSSSSSSXXXXXXXX]
// where SSSSSSSS is the 64-bit salt and
// XXXXXXXX is the 64-bit base counter
AP4_CopyMemory(out, m_Salt, 8);
AP4_BytesFromUInt64BE(&out[8], counter);
// encrypt the payload
AP4_Size data_size = data_in.GetDataSize();
m_Cipher->SetIV(out);
m_Cipher->ProcessBuffer(in, data_size, out+AP4_CIPHER_BLOCK_SIZE);
return AP4_SUCCESS;
}
示例2: AP4_FormatFourChars
/*----------------------------------------------------------------------
| AP4_SgpdAtom::InspectFields
+---------------------------------------------------------------------*/
AP4_Result
AP4_SgpdAtom::InspectFields(AP4_AtomInspector& inspector)
{
char fourcc[5];
AP4_FormatFourChars(fourcc, m_GroupingType);
inspector.AddField("grouping_type", fourcc);
if (m_Version >= 1) {
inspector.AddField("default_length", m_DefaultLength);
}
inspector.AddField("entry_count", m_Entries.ItemCount());
// inspect entries
char header[32];
unsigned int i=0;
for (AP4_List<AP4_DataBuffer>::Item* item = m_Entries.FirstItem();
item;
item = item->GetNext()) {
AP4_DataBuffer* entry = item->GetData();
AP4_FormatString(header, sizeof(header), "entry %02d", i);
++i;
inspector.AddField(header, entry->GetData(), entry->GetDataSize());
}
return AP4_SUCCESS;
}
示例3:
/*----------------------------------------------------------------------
| AP4_SgpdAtom::WriteFields
+---------------------------------------------------------------------*/
AP4_Result
AP4_SgpdAtom::WriteFields(AP4_ByteStream& stream)
{
AP4_Result result;
result = stream.WriteUI32(m_GroupingType);
if (AP4_FAILED(result)) return result;
if (m_Version >= 1) {
result = stream.WriteUI32(m_DefaultLength);
if (AP4_FAILED(result)) return result;
}
// write the children
result = stream.WriteUI32(m_Entries.ItemCount());
if (AP4_FAILED(result)) return result;
for (AP4_List<AP4_DataBuffer>::Item* item = m_Entries.FirstItem();
item;
item = item->GetNext()) {
AP4_DataBuffer* entry = item->GetData();
if (m_Version >= 1) {
if (m_DefaultLength == 0) {
stream.WriteUI32((AP4_UI32)entry->GetDataSize());
}
}
result = stream.Write(entry->GetData(), entry->GetDataSize());
if (AP4_FAILED(result)) {
return result;
}
}
return AP4_SUCCESS;
}
示例4: MinHeaderSize
/*----------------------------------------------------------------------
| AP4_DecoderSpecificInfoDescriptor::AP4_DecoderSpecificInfoDescriptor
+---------------------------------------------------------------------*/
AP4_DecoderSpecificInfoDescriptor::AP4_DecoderSpecificInfoDescriptor(
const AP4_DataBuffer& data) :
AP4_Descriptor(AP4_DESCRIPTOR_TAG_DECODER_SPECIFIC_INFO,
MinHeaderSize(data.GetDataSize()),
data.GetDataSize()),
m_Info(data)
{
}
示例5:
/*----------------------------------------------------------------------
| AP4_DefaultFragmentHandler::ProcessSample
+---------------------------------------------------------------------*/
AP4_Result
AP4_DefaultFragmentHandler::ProcessSample(AP4_DataBuffer& data_in, AP4_DataBuffer& data_out)
{
if (m_TrackHandler == NULL) {
data_out.SetData(data_in.GetData(), data_in.GetDataSize());
return AP4_SUCCESS;
}
return m_TrackHandler->ProcessSample(data_in, data_out);
}
示例6: while
/*----------------------------------------------------------------------
| AP4_IsmaCipher::DecryptSample
+---------------------------------------------------------------------*/
AP4_Result
AP4_IsmaCipher::DecryptSample(AP4_DataBuffer& data_in,
AP4_DataBuffer& data_out)
{
bool is_encrypted = true;
const unsigned char* in = data_in.GetData();
if (m_SelectiveEncryption) {
is_encrypted = ((in[0]&1)==1);
in++;
}
// get the IV (this implementation only supports un to 32 bits of IV)
// so we skip anything beyond the last 4 bytes
unsigned int to_read = m_IvLength;
if (to_read > 16 || to_read == 0) return AP4_ERROR_INVALID_FORMAT;
while (to_read > 4) {
to_read--;
in++;
}
AP4_UI32 iv = 0;
while (to_read--) {
iv = (iv<<8) | *in++;
}
// get the key indicator (we only support up to 32 bits as well)
to_read = m_KeyIndicatorLength;
if (to_read > 4 ) return AP4_ERROR_INVALID_FORMAT;
while (to_read > 4) {
to_read--;
in++;
}
AP4_UI32 key_indicator = 0;
while (to_read--) {
key_indicator = (key_indicator<<8) | *in++;
}
// we only support key indicator = 0 for now... (TODO)
if (key_indicator != 0) {
return AP4_FAILURE;
}
// process the sample data
unsigned int header_size = in-data_in.GetData();
unsigned int payload_size = data_in.GetDataSize()-header_size;
data_out.SetDataSize(payload_size);
unsigned char* out = data_out.UseData();
if (is_encrypted) {
m_Cipher->SetStreamOffset(iv);
m_Cipher->ProcessBuffer(in, out, payload_size);
} else {
memcpy(out, in, payload_size);
}
return AP4_SUCCESS;
}
示例7: UpdatePPSId
virtual void UpdatePPSId(AP4_DataBuffer const &buffer) override
{
//Search the Slice header NALU
const AP4_UI08 *data(buffer.GetData());
unsigned int data_size(buffer.GetDataSize());
for (; data_size;)
{
// sanity check
if (data_size < naluLengthSize)
break;
// get the next NAL unit
AP4_UI32 nalu_size;
switch (naluLengthSize) {
case 1:nalu_size = *data++; data_size--; break;
case 2:nalu_size = AP4_BytesToInt16BE(data); data += 2; data_size -= 2; break;
case 4:nalu_size = AP4_BytesToInt32BE(data); data += 4; data_size -= 4; break;
default: data_size = 0; nalu_size = 1; break;
}
if (nalu_size > data_size)
break;
// Stop further NALU processing
if (countPictureSetIds < 2)
naluLengthSize = 0;
unsigned int nal_unit_type = *data & 0x1F;
if (
//nal_unit_type == AP4_AVC_NAL_UNIT_TYPE_CODED_SLICE_OF_NON_IDR_PICTURE ||
nal_unit_type == AP4_AVC_NAL_UNIT_TYPE_CODED_SLICE_OF_IDR_PICTURE //||
//nal_unit_type == AP4_AVC_NAL_UNIT_TYPE_CODED_SLICE_DATA_PARTITION_A ||
//nal_unit_type == AP4_AVC_NAL_UNIT_TYPE_CODED_SLICE_DATA_PARTITION_B ||
//nal_unit_type == AP4_AVC_NAL_UNIT_TYPE_CODED_SLICE_DATA_PARTITION_C
) {
AP4_DataBuffer unescaped(data, data_size);
AP4_NalParser::Unescape(unescaped);
AP4_BitReader bits(unescaped.GetData(), unescaped.GetDataSize());
bits.SkipBits(8); // NAL Unit Type
AP4_AvcFrameParser::ReadGolomb(bits); // first_mb_in_slice
AP4_AvcFrameParser::ReadGolomb(bits); // slice_type
pictureId = AP4_AvcFrameParser::ReadGolomb(bits); //picture_set_id
}
// move to the next NAL unit
data += nalu_size;
data_size -= nalu_size;
}
}
示例8:
/*----------------------------------------------------------------------
| AP4_UnknownSampleEntry::AP4_UnknownSampleEntry
+---------------------------------------------------------------------*/
AP4_UnknownSampleEntry::AP4_UnknownSampleEntry(AP4_Atom::Type type,
AP4_DataBuffer& payload) :
AP4_SampleEntry(type),
m_Payload(payload)
{
m_Size32 += payload.GetDataSize();
}
示例9:
/*----------------------------------------------------------------------
| AP4_IsmaTrackEncrypter::ProcessSample
+---------------------------------------------------------------------*/
AP4_Result
AP4_IsmaTrackEncrypter::ProcessSample(AP4_DataBuffer& data_in,
AP4_DataBuffer& data_out)
{
AP4_Result result = m_Cipher->EncryptSample(data_in, data_out, m_ByteOffset, false);
if (AP4_FAILED(result)) return result;
m_ByteOffset += data_in.GetDataSize();
return AP4_SUCCESS;
}
示例10: while
/*----------------------------------------------------------------------
| AP4_HintTrackReader::BuildRtpPacket
+---------------------------------------------------------------------*/
AP4_Result
AP4_HintTrackReader::BuildRtpPacket(AP4_RtpPacket* packet,
AP4_DataBuffer& packet_data)
{
// set the data size
AP4_Result result = packet_data.SetDataSize(packet->GetConstructedDataSize());
if (AP4_FAILED(result)) return result;
// now write
AP4_ByteStream* stream = new AP4_MemoryByteStream(packet_data);
// header + ssrc
stream->WriteUI08(0x80 | (packet->GetPBit() << 5) | (packet->GetXBit() << 4));
stream->WriteUI08((packet->GetMBit() << 7) | packet->GetPayloadType());
stream->WriteUI16(m_RtpSequenceStart + packet->GetSequenceSeed());
stream->WriteUI32(m_RtpTimeStampStart + (AP4_UI32)m_CurrentHintSample.GetCts() + packet->GetTimeStampOffset());
stream->WriteUI32(m_Ssrc);
AP4_List<AP4_RtpConstructor>::Item* constructors_it
= packet->GetConstructors().FirstItem();
while (constructors_it != NULL) {
AP4_RtpConstructor* constructor = constructors_it->GetData();
// add data to the packet according to the constructor
switch (constructor->GetType()) {
case AP4_RTP_CONSTRUCTOR_TYPE_NOOP:
// nothing to do here
break;
case AP4_RTP_CONSTRUCTOR_TYPE_IMMEDIATE:
result = WriteImmediateRtpData(
static_cast<AP4_ImmediateRtpConstructor*>(constructor), stream);
if (AP4_FAILED(result)) return result;
break;
case AP4_RTP_CONSTRUCTOR_TYPE_SAMPLE:
result = WriteSampleRtpData(
static_cast<AP4_SampleRtpConstructor*>(constructor), stream);
if (AP4_FAILED(result)) return result;
break;
case AP4_RTP_CONSTRUCTOR_TYPE_SAMPLE_DESC:
return AP4_ERROR_NOT_SUPPORTED;
default:
// unknown constructor type
return AP4_FAILURE;
}
// iterate
constructors_it = constructors_it->GetNext();
}
// release the stream
stream->Release();
return result;
}
示例11: AP4_Atom
/*----------------------------------------------------------------------
| AP4_SgpdAtom::AP4_SgpdAtom
+---------------------------------------------------------------------*/
AP4_SgpdAtom::AP4_SgpdAtom(AP4_UI32 size,
AP4_UI08 version,
AP4_UI32 flags,
AP4_ByteStream& stream) :
AP4_Atom(AP4_ATOM_TYPE_SGPD, size, version, flags),
m_GroupingType(0),
m_DefaultLength(0)
{
AP4_Size bytes_available = size-AP4_FULL_ATOM_HEADER_SIZE;
stream.ReadUI32(m_GroupingType);
bytes_available -= 4;
if (version >= 1) {
stream.ReadUI32(m_DefaultLength);
bytes_available -= 4;
}
// read the number of entries
AP4_UI32 entry_count = 0;
AP4_Result result = stream.ReadUI32(entry_count);
if (AP4_FAILED(result)) return;
bytes_available -= 4;
// read all entries
for (unsigned int i=0; i<entry_count; i++) {
AP4_UI32 description_length = m_DefaultLength;
if (m_Version == 0) {
// entry size unknown, read the whole thing
description_length = bytes_available;
} else {
if (m_DefaultLength == 0) {
description_length = stream.ReadUI32(description_length);
}
}
if (description_length <= bytes_available) {
AP4_DataBuffer* payload = new AP4_DataBuffer(description_length);
payload->SetDataSize(description_length);
stream.Read(payload->UseData(), description_length);
m_Entries.Add(payload);
}
}
}
示例12:
/*----------------------------------------------------------------------
| AP4_MarlinIpmpTrackDecrypter:ProcessSample
+---------------------------------------------------------------------*/
AP4_Result
AP4_MarlinIpmpTrackDecrypter::ProcessSample(AP4_DataBuffer& data_in,
AP4_DataBuffer& data_out)
{
AP4_Result result;
const AP4_UI08* in = data_in.GetData();
AP4_Size in_size = data_in.GetDataSize();
// default to 0 output
data_out.SetDataSize(0);
// check that we have at least the minimum size
if (in_size < 2*AP4_AES_BLOCK_SIZE) return AP4_ERROR_INVALID_FORMAT;
// process the sample data
AP4_Size out_size = in_size-AP4_AES_BLOCK_SIZE; // worst case
data_out.SetDataSize(out_size);
AP4_UI08* out = data_out.UseData();
// decrypt the data
m_Cipher->SetIV(in);
result = m_Cipher->ProcessBuffer(in+AP4_AES_BLOCK_SIZE,
in_size-AP4_AES_BLOCK_SIZE,
out,
&out_size,
true);
if (AP4_FAILED(result)) return result;
// update the payload size
data_out.SetDataSize(out_size);
return AP4_SUCCESS;
}
示例13: 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");
}
}
示例14: DecryptSampleData
/*----------------------------------------------------------------------
| WV_CencSingleSampleDecrypter::DecryptSampleData
+---------------------------------------------------------------------*/
AP4_Result WV_CencSingleSampleDecrypter::DecryptSampleData(
AP4_DataBuffer& data_in,
AP4_DataBuffer& data_out,
const AP4_UI08* iv,
unsigned int subsample_count,
const AP4_UI16* bytes_of_cleartext_data,
const AP4_UI32* bytes_of_encrypted_data)
{
// the output has the same size as the input
data_out.SetDataSize(data_in.GetDataSize());
if (!wv_adapter)
{
data_out.SetData(data_in.GetData(), data_in.GetDataSize());
return AP4_SUCCESS;
}
// check input parameters
if (iv == NULL) return AP4_ERROR_INVALID_PARAMETERS;
if (subsample_count) {
if (bytes_of_cleartext_data == NULL || bytes_of_encrypted_data == NULL) {
return AP4_ERROR_INVALID_PARAMETERS;
}
}
// transform ap4 format into cmd format
cdm::InputBuffer cdm_in;
if (subsample_count > max_subsample_count_)
{
subsample_buffer_ = (cdm::SubsampleEntry*)realloc(subsample_buffer_, subsample_count*sizeof(cdm::SubsampleEntry));
max_subsample_count_ = subsample_count;
}
for (cdm::SubsampleEntry *b(subsample_buffer_), *e(subsample_buffer_ + subsample_count); b != e; ++b, ++bytes_of_cleartext_data, ++bytes_of_encrypted_data)
{
b->clear_bytes = *bytes_of_cleartext_data;
b->cipher_bytes = *bytes_of_encrypted_data;
}
cdm_in.data = data_in.GetData();
cdm_in.data_size = data_in.GetDataSize();
cdm_in.iv = iv;
cdm_in.iv_size = 16; //Always 16, see AP4_CencSingleSampleDecrypter declaration.
cdm_in.key_id = wv_adapter->GetKeyId();
cdm_in.key_id_size = wv_adapter->GetKeyIdSize();
cdm_in.num_subsamples = subsample_count;
cdm_in.subsamples = subsample_buffer_;
CdmBuffer buf(&data_out);
CdmDecryptedBlock cdm_out;
cdm_out.SetDecryptedBuffer(&buf);
cdm::Status ret = wv_adapter->Decrypt(cdm_in, &cdm_out);
return (ret == cdm::Status::kSuccess) ? AP4_SUCCESS : AP4_ERROR_INVALID_PARAMETERS;
}
示例15: 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;
}