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


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

本文整理汇总了C++中AP4_DataBuffer::SetDataSize方法的典型用法代码示例。如果您正苦于以下问题:C++ AP4_DataBuffer::SetDataSize方法的具体用法?C++ AP4_DataBuffer::SetDataSize怎么用?C++ AP4_DataBuffer::SetDataSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AP4_DataBuffer的用法示例。


在下文中一共展示了AP4_DataBuffer::SetDataSize方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

/*----------------------------------------------------------------------
|   AP4_MarlinIpmpTrackEncrypter:ProcessSample
+---------------------------------------------------------------------*/
AP4_Result 
AP4_MarlinIpmpTrackEncrypter::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);

    // process the sample data
    AP4_Size out_size = AP4_CIPHER_BLOCK_SIZE*(2+(in_size/AP4_CIPHER_BLOCK_SIZE));
    data_out.SetDataSize(out_size);
    AP4_UI08* out = data_out.UseData();

    // write the IV
    AP4_CopyMemory(out, m_IV, AP4_CIPHER_BLOCK_SIZE);
    out_size -= AP4_CIPHER_BLOCK_SIZE;
    
    // encrypt the data
    m_Cipher->SetIV(m_IV);
    result = m_Cipher->ProcessBuffer(in, 
                                     in_size, 
                                     out+AP4_AES_BLOCK_SIZE,
                                     &out_size,
                                     true);
    if (AP4_FAILED(result)) return result;
    
    // update the payload size
    data_out.SetDataSize(out_size+AP4_AES_BLOCK_SIZE);
    
    return AP4_SUCCESS;
}
开发者ID:huangyt,项目名称:MyProjects,代码行数:38,代码来源:Ap4Marlin.cpp

示例2:

/*----------------------------------------------------------------------
|   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

示例3: 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;
}
开发者ID:AchimTuran,项目名称:inputstream.mpd,代码行数:57,代码来源:wvdecrypter.cpp

示例4: 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;
}
开发者ID:AeonAxan,项目名称:mpc-hc,代码行数:57,代码来源:Ap4IsmaCryp.cpp

示例5: 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;
}
开发者ID:AchimTuran,项目名称:inputstream.mpd,代码行数:57,代码来源:Ap4HintTrackReader.cpp

示例6: fprintf

/*----------------------------------------------------------------------
|   MakeFramePrefix
+---------------------------------------------------------------------*/
static AP4_Result
MakeFramePrefix(AP4_SampleDescription* sdesc, AP4_DataBuffer& prefix, unsigned int& nalu_length_size)
{
    AP4_AvcSampleDescription* avc_desc = AP4_DYNAMIC_CAST(AP4_AvcSampleDescription, sdesc);
    if (avc_desc == NULL) {
        fprintf(stderr, "ERROR: track does not contain an AVC stream\n");
        return AP4_FAILURE;
    }
    
    if (sdesc->GetFormat() == AP4_SAMPLE_FORMAT_AVC3 || sdesc->GetFormat() == AP4_SAMPLE_FORMAT_AVC4) {
        // no need for a prefix, SPS/PPS NALs should be in the elementary stream already
        return AP4_SUCCESS;
    }
    
    // make the SPS/PPS prefix
    nalu_length_size = avc_desc->GetNaluLengthSize();
    for (unsigned int i=0; i<avc_desc->GetSequenceParameters().ItemCount(); i++) {
        AP4_DataBuffer& buffer = avc_desc->GetSequenceParameters()[i];
        unsigned int prefix_size = prefix.GetDataSize();
        prefix.SetDataSize(prefix_size+4+buffer.GetDataSize());
        unsigned char* p = prefix.UseData()+prefix_size;
        *p++ = 0;
        *p++ = 0;
        *p++ = 0;
        *p++ = 1;
        AP4_CopyMemory(p, buffer.GetData(), buffer.GetDataSize());
    }
    for (unsigned int i=0; i<avc_desc->GetPictureParameters().ItemCount(); i++) {
        AP4_DataBuffer& buffer = avc_desc->GetPictureParameters()[i];
        unsigned int prefix_size = prefix.GetDataSize();
        prefix.SetDataSize(prefix_size+4+buffer.GetDataSize());
        unsigned char* p = prefix.UseData()+prefix_size;
        *p++ = 0;
        *p++ = 0;
        *p++ = 0;
        *p++ = 1;
        AP4_CopyMemory(p, buffer.GetData(), buffer.GetDataSize());
    }
    
    return AP4_SUCCESS;
}
开发者ID:garybruckheimer,项目名称:raypackSuite,代码行数:44,代码来源:Mp42Avc.cpp

示例7:

/*----------------------------------------------------------------------
|   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);
        }
    }
}
开发者ID:ravmike,项目名称:Bento4,代码行数:44,代码来源:Ap4SgpdAtom.cpp

示例8:

/*----------------------------------------------------------------------
|       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;
}
开发者ID:AeonAxan,项目名称:mpc-hc,代码行数:24,代码来源:Ap4IsmaCryp.cpp

示例9: fprintf

/*----------------------------------------------------------------------
|   MakeFramePrefix
+---------------------------------------------------------------------*/
static AP4_Result
MakeFramePrefix(AP4_SampleDescription* sdesc, AP4_DataBuffer& prefix, unsigned int& nalu_length_size)
{
    AP4_HevcSampleDescription* hevc_desc = AP4_DYNAMIC_CAST(AP4_HevcSampleDescription, sdesc);
    if (hevc_desc == NULL) {
        fprintf(stderr, "ERROR: track does not contain an HEVC stream\n");
        return AP4_FAILURE;
    }
    
    // extract the nalu length size
    nalu_length_size = hevc_desc->GetNaluLengthSize();

    // make the VPS/SPS/PPS prefix
    for (unsigned int i=0; i<hevc_desc->GetSequences().ItemCount(); i++) {
        const AP4_HvccAtom::Sequence& seq = hevc_desc->GetSequences()[i];
        if (seq.m_NaluType == AP4_HEVC_NALU_TYPE_VPS_NUT) {
            for (unsigned int j=0; j<seq.m_Nalus.ItemCount(); j++) {
                const AP4_DataBuffer& buffer = seq.m_Nalus[j];
                unsigned int prefix_size = prefix.GetDataSize();
                prefix.SetDataSize(prefix_size+4+buffer.GetDataSize());
                unsigned char* p = prefix.UseData()+prefix_size;
                *p++ = 0;
                *p++ = 0;
                *p++ = 0;
                *p++ = 1;
                AP4_CopyMemory(p, buffer.GetData(), buffer.GetDataSize());
            }
        }
    }

    for (unsigned int i=0; i<hevc_desc->GetSequences().ItemCount(); i++) {
        const AP4_HvccAtom::Sequence& seq = hevc_desc->GetSequences()[i];
        if (seq.m_NaluType == AP4_HEVC_NALU_TYPE_SPS_NUT) {
            for (unsigned int j=0; j<seq.m_Nalus.ItemCount(); j++) {
                const AP4_DataBuffer& buffer = seq.m_Nalus[j];
                unsigned int prefix_size = prefix.GetDataSize();
                prefix.SetDataSize(prefix_size+4+buffer.GetDataSize());
                unsigned char* p = prefix.UseData()+prefix_size;
                *p++ = 0;
                *p++ = 0;
                *p++ = 0;
                *p++ = 1;
                AP4_CopyMemory(p, buffer.GetData(), buffer.GetDataSize());
            }
        }
    }

    for (unsigned int i=0; i<hevc_desc->GetSequences().ItemCount(); i++) {
        const AP4_HvccAtom::Sequence& seq = hevc_desc->GetSequences()[i];
        if (seq.m_NaluType == AP4_HEVC_NALU_TYPE_PPS_NUT) {
            for (unsigned int j=0; j<seq.m_Nalus.ItemCount(); j++) {
                const AP4_DataBuffer& buffer = seq.m_Nalus[j];
                unsigned int prefix_size = prefix.GetDataSize();
                prefix.SetDataSize(prefix_size+4+buffer.GetDataSize());
                unsigned char* p = prefix.UseData()+prefix_size;
                *p++ = 0;
                *p++ = 0;
                *p++ = 0;
                *p++ = 1;
                AP4_CopyMemory(p, buffer.GetData(), buffer.GetDataSize());
            }
        }
    }
    
    return AP4_SUCCESS;
}
开发者ID:garybruckheimer,项目名称:raypackSuite,代码行数:69,代码来源:Mp42Hevc.cpp


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