当前位置: 首页>>代码示例>>C++>>正文


C++ AP4_DataBuffer::Reserve方法代码示例

本文整理汇总了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;
}
开发者ID:satram,项目名称:Bento4,代码行数:36,代码来源:Ap4OmaDcf.cpp

示例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;
}
开发者ID:huangyt,项目名称:MyProjects,代码行数:30,代码来源:Ap4Marlin.cpp


注:本文中的AP4_DataBuffer::Reserve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。