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


C++ NPT_DataBuffer::GetBufferSize方法代码示例

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


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

示例1: Read

int CStreamCtrl::Read(void* buffer, unsigned int bytes_to_read, unsigned int* bytes_read)
{
	int ret=0;
	if (m_type==1)
	{
		*bytes_read=fread(buffer,1,bytes_to_read,m_openFile);
	}
	else if (m_type==2)
	{
		_pbyte_t pHeaderBuffer = NULL;
		_uint32_t ui32HeaderBufferSize = 0;
		m_sSequence->getHeaderBuffer(&pHeaderBuffer,&ui32HeaderBufferSize);
		if (m_curPos<ui32HeaderBufferSize)
		{
			unsigned int tmp_bytes=ui32HeaderBufferSize-static_cast<unsigned int>(m_curPos);
			*bytes_read= (bytes_to_read>tmp_bytes) ? tmp_bytes : bytes_to_read;
			pHeaderBuffer+=m_curPos;
			memcpy(buffer,pHeaderBuffer,*bytes_read);
			m_curPos+=*bytes_read;
		}
		else
		{
			_uint32_t pos=static_cast<unsigned int>(m_curPos);
			_uint32_t startclipnum = 0;
			_uint32_t endclipnum = 0;

			if (pos + bytes_to_read <= m_fileSize)
				m_sSequence->TranslateSectionRange(pos, pos+bytes_to_read, &startclipnum, &endclipnum);
			else
				m_sSequence->TranslateSectionRange(pos, m_fileSize, &startclipnum, &endclipnum);
			unsigned int index(0);
			for (_uint32_t j = startclipnum; j <= endclipnum; j++)
			{
				ClipOfRangeInfo sClipInfo;
				m_sSequence->getSectionInfoByIndex(j, &sClipInfo);
				char query[10]={};

				NPT_String path="/";
				path+=m_openFileName;

				NPT_HttpUrl url=NPT_HttpUrl(P2PIPAddress, 8082, path);
				_itoa_s(j,query,10);
				url.SetQuery(query);

				NPT_DataBuffer mediadata;
				RecvMediaData(url,sClipInfo.StartOffset,sClipInfo.EndOffset,mediadata);	

				memcpy((unsigned char*)buffer+index,mediadata.GetData(),mediadata.GetBufferSize());
				index+=mediadata.GetBufferSize();
				m_curPos+=mediadata.GetBufferSize();
			}
			*bytes_read=index;
		}
	}
	return ret;
}
开发者ID:liudeyan,项目名称:CodesAndNotes,代码行数:56,代码来源:StreamControl.cpp

示例2: MapError

/*----------------------------------------------------------------------
|   NPT_Zip::Inflate
+---------------------------------------------------------------------*/
NPT_Result
NPT_Zip::Inflate(const NPT_DataBuffer& in,
                 NPT_DataBuffer&       out,
                 bool                  raw)
{
    // assume an output buffer twice the size of the input plus a bit
    NPT_CHECK_WARNING(out.Reserve(32+2*in.GetDataSize()));

    // setup the stream
    z_stream stream;
    stream.next_in   = (Bytef*)in.GetData();
    stream.avail_in  = (uInt)in.GetDataSize();
    stream.next_out  = out.UseData();
    stream.avail_out = (uInt)out.GetBufferSize();

    // setup the memory functions
    stream.zalloc = (alloc_func)0;
    stream.zfree = (free_func)0;
    stream.opaque = (voidpf)0;

    // initialize the decompressor
    int err = inflateInit2(&stream, raw?-15:15+32); // 15 = default window bits, +32 = automatic header
    if (err != Z_OK) return MapError(err);

    // decompress until the end
    do {
        err = inflate(&stream, Z_SYNC_FLUSH);
        if (err == Z_STREAM_END || err == Z_OK || err == Z_BUF_ERROR) {
            out.SetDataSize((NPT_Size)stream.total_out);
            if ((err == Z_OK && stream.avail_out == 0) || err == Z_BUF_ERROR) {
                // grow the output buffer
                out.Reserve(out.GetBufferSize()*2);
                stream.next_out = out.UseData()+stream.total_out;
                stream.avail_out = out.GetBufferSize()-(NPT_Size)stream.total_out;
            }
        }
    } while (err == Z_OK);

    // check for errors
    if (err != Z_STREAM_END) {
        inflateEnd(&stream);
        return MapError(err);
    }

    // cleanup
    err = inflateEnd(&stream);
    return MapError(err);
}
开发者ID:sandalsoft,项目名称:mrmc,代码行数:51,代码来源:NptZip.cpp

示例3: MapError

/*----------------------------------------------------------------------
|   NPT_Zip::Deflate
+---------------------------------------------------------------------*/
NPT_Result 
NPT_Zip::Deflate(const NPT_DataBuffer& in,
                 NPT_DataBuffer&       out,
                 int                   compression_level,
                 Format                format /* = ZLIB */)
{
    // default return state
    out.SetDataSize(0);
    
    // check parameters
    if (compression_level < NPT_ZIP_COMPRESSION_LEVEL_DEFAULT ||
        compression_level > NPT_ZIP_COMPRESSION_LEVEL_MAX) {
        return NPT_ERROR_INVALID_PARAMETERS;
    }
                
    // setup the stream
    z_stream stream;
    NPT_SetMemory(&stream, 0, sizeof(stream));
    stream.next_in   = (Bytef*)in.GetData();
    stream.avail_in  = (uInt)in.GetDataSize();
    
    // setup the memory functions
    stream.zalloc = (alloc_func)0;
    stream.zfree = (free_func)0;
    stream.opaque = (voidpf)0;

    // initialize the compressor
    int err = deflateInit2(&stream, 
                           compression_level,
                           Z_DEFLATED,
                           15 + (format == GZIP ? 16 : 0),
                           8,
                           Z_DEFAULT_STRATEGY);
    if (err != Z_OK) return MapError(err);

    // reserve an output buffer known to be large enough
    out.Reserve(deflateBound(&stream, stream.avail_in) + (format==GZIP?10:0));
    stream.next_out  = out.UseData();
    stream.avail_out = out.GetBufferSize();

    // decompress
    err = deflate(&stream, Z_FINISH);
    if (err != Z_STREAM_END) {
        deflateEnd(&stream);
        return MapError(err);
    }
    
    // update the output size
    out.SetDataSize(stream.total_out);

    // cleanup
    err = deflateEnd(&stream);
    return MapError(err);
}
开发者ID:NAGAVENDRA,项目名称:GenieForiOS,代码行数:57,代码来源:NptZip.cpp


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