本文整理汇总了C++中AP4_DataBuffer::GetData方法的典型用法代码示例。如果您正苦于以下问题:C++ AP4_DataBuffer::GetData方法的具体用法?C++ AP4_DataBuffer::GetData怎么用?C++ AP4_DataBuffer::GetData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AP4_DataBuffer
的用法示例。
在下文中一共展示了AP4_DataBuffer::GetData方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
/*----------------------------------------------------------------------
| 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;
}
示例2: 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;
}
示例3: 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;
}
示例4:
/*----------------------------------------------------------------------
| 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;
}
示例5: sizeof
/*----------------------------------------------------------------------
| 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;
}
示例6:
/*----------------------------------------------------------------------
| 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;
}
示例7:
/*----------------------------------------------------------------------
| 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);
}
示例8: 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;
}
}
示例9:
/*----------------------------------------------------------------------
| AP4_IsmaCipher::EncryptSample
+---------------------------------------------------------------------*/
AP4_Result
AP4_IsmaCipher::EncryptSample(AP4_DataBuffer& data_in,
AP4_DataBuffer& data_out,
AP4_Offset iv,
bool skip_encryption)
{
// setup the buffers
const unsigned char* in = data_in.GetData();
data_out.SetDataSize(data_in.GetDataSize()+4);
unsigned char* out = data_out.UseData();
// IV on 4 bytes
AP4_BytesFromUInt32BE(out, iv);
out += 4;
// encrypt the payload
m_Cipher->SetStreamOffset(iv);
m_Cipher->ProcessBuffer(in, out, data_in.GetDataSize());
return AP4_FAILURE;
}
示例10: 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");
}
}
示例11: while
/*----------------------------------------------------------------------
| WriteSample
+---------------------------------------------------------------------*/
static void
WriteSample(const AP4_DataBuffer& sample_data,
AP4_DataBuffer& prefix,
unsigned int nalu_length_size,
AP4_ByteStream* output)
{
const unsigned char* data = sample_data.GetData();
unsigned int data_size = sample_data.GetDataSize();
// detect if we have VPS/SPS/PPS and/or AUD NAL units already
bool have_param_sets = false;
bool have_access_unit_delimiter = false;
while (data_size) {
// sanity check
if (data_size < nalu_length_size) break;
// get the next NAL unit
AP4_UI32 nalu_size;
if (nalu_length_size == 1) {
nalu_size = *data++;
data_size--;
} else if (nalu_length_size == 2) {
nalu_size = AP4_BytesToInt16BE(data);
data += 2;
data_size -= 2;
} else if (nalu_length_size == 4) {
nalu_size = AP4_BytesToInt32BE(data);
data += 4;
data_size -= 4;
} else {
break;
}
if (nalu_size > data_size) break;
unsigned int nal_unit_type = (data[0]>>1)&0x3F;
if (nal_unit_type == AP4_HEVC_NALU_TYPE_AUD_NUT) {
have_access_unit_delimiter = true;
}
if (nal_unit_type == AP4_HEVC_NALU_TYPE_VPS_NUT ||
nal_unit_type == AP4_HEVC_NALU_TYPE_SPS_NUT ||
nal_unit_type == AP4_HEVC_NALU_TYPE_PPS_NUT) {
have_param_sets = true;
break;
}
// move to the next NAL unit
data += nalu_size;
data_size -= nalu_size;
}
data = sample_data.GetData();
data_size = sample_data.GetDataSize();
// allocate a buffer for the frame data
AP4_DataBuffer frame_data;
unsigned char* frame_buffer = NULL;
// add a delimiter if we don't already have one
if (data_size && !have_access_unit_delimiter) {
AP4_Size frame_data_size = frame_data.GetDataSize();
frame_data.SetDataSize(frame_data_size+7);
frame_buffer = frame_data.UseData()+frame_data_size;
// start of access unit
frame_buffer[0] = 0;
frame_buffer[1] = 0;
frame_buffer[2] = 0;
frame_buffer[3] = 1;
frame_buffer[4] = AP4_HEVC_NALU_TYPE_AUD_NUT<<1;
frame_buffer[5] = 1;
frame_buffer[6] = 0x40; // pic_type = 2 (B,P,I)
}
// write the NAL units
bool prefix_added = false;
while (data_size) {
// sanity check
if (data_size < nalu_length_size) break;
// get the next NAL unit
AP4_UI32 nalu_size;
if (nalu_length_size == 1) {
nalu_size = *data++;
data_size--;
} else if (nalu_length_size == 2) {
nalu_size = AP4_BytesToInt16BE(data);
data += 2;
data_size -= 2;
} else if (nalu_length_size == 4) {
nalu_size = AP4_BytesToInt32BE(data);
data += 4;
data_size -= 4;
} else {
break;
}
if (nalu_size > data_size) break;
// add the prefix if needed
//.........这里部分代码省略.........
示例12: while
/*----------------------------------------------------------------------
| WriteSample
+---------------------------------------------------------------------*/
static void
WriteSample(const AP4_DataBuffer& sample_data,
AP4_DataBuffer& prefix,
unsigned int nalu_length_size,
AP4_ByteStream* output)
{
const unsigned char* data = sample_data.GetData();
unsigned int data_size = sample_data.GetDataSize();
// allocate a buffer for the PES packet
AP4_DataBuffer frame_data;
unsigned char* frame_buffer = NULL;
// add a delimiter if we don't already have one
bool have_access_unit_delimiter = (data_size > nalu_length_size) && ((data[nalu_length_size] & 0x1F) == AP4_AVC_NAL_UNIT_TYPE_ACCESS_UNIT_DELIMITER);
if (!have_access_unit_delimiter) {
AP4_Size frame_data_size = frame_data.GetDataSize();
frame_data.SetDataSize(frame_data_size+6);
frame_buffer = frame_data.UseData()+frame_data_size;
// start of access unit
frame_buffer[0] = 0;
frame_buffer[1] = 0;
frame_buffer[2] = 0;
frame_buffer[3] = 1;
frame_buffer[4] = 9; // NAL type = Access Unit Delimiter;
frame_buffer[5] = 0xE0; // Slice types = ANY
}
// write the NAL units
bool prefix_added = false;
while (data_size) {
// sanity check
if (data_size < nalu_length_size) break;
// get the next NAL unit
AP4_UI32 nalu_size;
if (nalu_length_size == 1) {
nalu_size = *data++;
data_size--;
} else if (nalu_length_size == 2) {
nalu_size = AP4_BytesToInt16BE(data);
data += 2;
data_size -= 2;
} else if (nalu_length_size == 4) {
nalu_size = AP4_BytesToInt32BE(data);
data += 4;
data_size -= 4;
} else {
break;
}
if (nalu_size > data_size) break;
// add the prefix if needed
if (prefix.GetDataSize() && !prefix_added && !have_access_unit_delimiter) {
AP4_Size frame_data_size = frame_data.GetDataSize();
frame_data.SetDataSize(frame_data_size+prefix.GetDataSize());
frame_buffer = frame_data.UseData()+frame_data_size;
AP4_CopyMemory(frame_buffer, prefix.GetData(), prefix.GetDataSize());
prefix_added = true;
}
// add a start code before the NAL unit
AP4_Size frame_data_size = frame_data.GetDataSize();
frame_data.SetDataSize(frame_data_size+3+nalu_size);
frame_buffer = frame_data.UseData()+frame_data_size;
frame_buffer[0] = 0;
frame_buffer[1] = 0;
frame_buffer[2] = 1;
AP4_CopyMemory(frame_buffer+3, data, nalu_size);
// add the prefix if needed
if (prefix.GetDataSize() && !prefix_added) {
AP4_Size frame_data_size = frame_data.GetDataSize();
frame_data.SetDataSize(frame_data_size+prefix.GetDataSize());
frame_buffer = frame_data.UseData()+frame_data_size;
AP4_CopyMemory(frame_buffer, prefix.GetData(), prefix.GetDataSize());
prefix_added = true;
}
// move to the next NAL unit
data += nalu_size;
data_size -= nalu_size;
}
output->Write(frame_data.GetData(), frame_data.GetDataSize());
}
示例13: while
//.........这里部分代码省略.........
fprintf(stderr, "ERROR: invalid argument syntax for --pssh\n");
return 1;
}
unsigned char system_id[16];
arg[32] = '\0';
result = AP4_ParseHex(arg, system_id, 16);
if (AP4_FAILED(result)) {
fprintf(stderr, "ERROR: invalid argument syntax for --pssh\n");
return 1;
}
const char* pssh_filename = arg+33;
// load the pssh payload
AP4_DataBuffer pssh_payload;
if (pssh_filename[0]) {
AP4_ByteStream* pssh_input = NULL;
result = AP4_FileByteStream::Create(pssh_filename, AP4_FileByteStream::STREAM_MODE_READ, pssh_input);
if (AP4_FAILED(result)) {
fprintf(stderr, "ERROR: cannot open pssh payload file (%d)\n", result);
return 1;
}
AP4_LargeSize pssh_payload_size = 0;
pssh_input->GetSize(pssh_payload_size);
pssh_payload.SetDataSize((AP4_Size)pssh_payload_size);
result = pssh_input->Read(pssh_payload.UseData(), (AP4_Size)pssh_payload_size);
if (AP4_FAILED(result)) {
fprintf(stderr, "ERROR: cannot read pssh payload from file (%d)\n", result);
return 1;
}
}
AP4_PsshAtom* pssh;
if (v1) {
if (kid_count) {
pssh = new AP4_PsshAtom(system_id, kids.GetData(), kid_count);
} else {
pssh = new AP4_PsshAtom(system_id);
}
} else {
pssh = new AP4_PsshAtom(system_id);
}
if (pssh_payload.GetDataSize()) {
pssh->SetData(pssh_payload.GetData(), pssh_payload.GetDataSize());
}
pssh_atoms.Append(pssh);
} else if (!strcmp(arg, "--kms-uri")) {
arg = *++argv;
if (arg == NULL) {
fprintf(stderr, "ERROR: missing argument for --kms-uri option\n");
return 1;
}
if (method != METHOD_ISMA_AES) {
fprintf(stderr, "ERROR: --kms-uri only applies to method ISMA-IAEC\n");
return 1;
}
kms_uri = arg;
} else if (!strcmp(arg, "--show-progress")) {
show_progress = true;
} else if (!strcmp(arg, "--strict")) {
strict = true;
} else if (!strcmp(arg, "--key")) {
if (method == METHOD_NONE) {
fprintf(stderr, "ERROR: --method argument must appear before --key\n");
return 1;
}
arg = *++argv;
if (arg == NULL) {
示例14: ProcessSample
virtual AP4_Result ProcessSample(AP4_DataBuffer& data_in,
AP4_DataBuffer& data_out) {
return data_out.SetData(data_in.GetData(), data_in.GetDataSize());
}