本文整理汇总了C++中AP4_DataBuffer::Reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ AP4_DataBuffer::Reserve方法的具体用法?C++ AP4_DataBuffer::Reserve怎么用?C++ AP4_DataBuffer::Reserve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AP4_DataBuffer
的用法示例。
在下文中一共展示了AP4_DataBuffer::Reserve方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
/*----------------------------------------------------------------------
| AP4_OmaDcfCbcSampleEncrypter::EncryptSampleData
+---------------------------------------------------------------------*/
AP4_Result
AP4_OmaDcfCbcSampleEncrypter::EncryptSampleData(AP4_DataBuffer& data_in,
AP4_DataBuffer& data_out,
AP4_UI64 counter,
bool /*skip_encryption*/)
{
// make sure there is enough space in the output buffer
data_out.Reserve(data_in.GetDataSize()+2*AP4_CIPHER_BLOCK_SIZE+1);
// setup the buffers
AP4_Size out_size = data_in.GetDataSize()+AP4_CIPHER_BLOCK_SIZE;
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
m_Cipher->SetIV(out);
m_Cipher->ProcessBuffer(data_in.GetData(),
data_in.GetDataSize(),
out+AP4_CIPHER_BLOCK_SIZE,
&out_size,
true);
AP4_CHECK(data_out.SetDataSize(out_size+AP4_CIPHER_BLOCK_SIZE+1));
return AP4_SUCCESS;
}
示例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;
}