本文整理汇总了C++中NPT_DataBuffer类的典型用法代码示例。如果您正苦于以下问题:C++ NPT_DataBuffer类的具体用法?C++ NPT_DataBuffer怎么用?C++ NPT_DataBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NPT_DataBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
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;
}
示例2: fseek
//0 for success
int CStreamCtrl::Open(const char* name, int file_type)
{
int ret=0;
m_type=file_type;
m_openFileName=const_cast<char*>(name);
if (m_type==1)
{
ret=fopen_s(&m_openFile,name,"rb");
if(!ret)
{
fseek(m_openFile,0,SEEK_END);
m_fileSize=ftell(m_openFile);
m_available=m_fileSize;
rewind(m_openFile);
}
}
else if (m_type==2)
{
NPT_String path="/";
path+=m_openFileName;
NPT_HttpUrl url=NPT_HttpUrl(CDNIPAddress, CDNPort, path.GetChars());
NPT_DataBuffer buffer;
bool ret=true;
ret=RecvHeaderData(url,buffer);
if (ret)
{
NPT_Byte* pdata=const_cast<unsigned char*>(buffer.GetData());
SequenceInfo sInfo;
unsigned int tmp_size(0);
memcpy(&tmp_size,pdata,4);
unsigned int length=4;
unsigned int inum=sInfo.nSectionCount=tmp_size;
sInfo.pSectioninfo=new SectionInfo[inum];
pdata+=4;
for (unsigned int i=0;i<inum;++i)
{
memcpy(&tmp_size,pdata,4);
pdata+=4;
sInfo.pSectioninfo[i].ui32SectionInfoBufferSize=tmp_size;
sInfo.pSectioninfo[i].pSectionInfoBuffer=pdata;
pdata+=tmp_size;
}
m_sSequence=new QtSequence(&sInfo);
_uint32_t ui32FileSize = 0;
m_sSequence->getFileSize(&ui32FileSize);
m_fileSize=ui32FileSize;
m_available=ui32FileSize;
}
}
return ret;
}
示例3: while
/*----------------------------------------------------------------------
| NPT_Base64::Decode
+---------------------------------------------------------------------*/
NPT_Result
NPT_Base64::Decode(const char* base64,
NPT_Size size,
NPT_DataBuffer& data,
bool url_safe /* = false */)
{
// estimate the data size
data.SetBufferSize(size);
// reset the buffer
data.SetDataSize(0);
// keep a pointer to the buffer
unsigned char* buffer = data.UseData();
NPT_Size data_size = 0;
// iterate over all characters
unsigned char codes[4];
unsigned int code_count = 0;
while (size--) {
unsigned char c = *base64++;
if (c >= NPT_ARRAY_SIZE(NPT_Base64_Bytes)) continue;
if (url_safe) {
// remap some characters and forbid the mapped variants
if (c == '-') {
c = '+';
} else if (c == '_') {
c = '/';
} else if (c == '+' || c == '/') {
c = 0; // will be ignored later
}
}
signed char code = NPT_Base64_Bytes[c];
if (code >= 0) {
// valid code
codes[code_count++] = code;
if (code_count == 4) {
// group complete
if (codes[0] == NPT_BASE64_PAD_BYTE || codes[1] == NPT_BASE64_PAD_BYTE) {
return NPT_ERROR_INVALID_FORMAT;
}
if (codes[2] == NPT_BASE64_PAD_BYTE) {
// pad at char 3
if (codes[3] == NPT_BASE64_PAD_BYTE) {
// double padding
unsigned int packed = (codes[0]<<2)|(codes[1]>>4);
buffer[data_size++] = (unsigned char)packed;
} else {
// invalid padding
return NPT_ERROR_INVALID_FORMAT;
}
} else if (codes[3] == NPT_BASE64_PAD_BYTE) {
示例4: ParseConfig
/*----------------------------------------------------------------------
| NPT_LogManager::ParseConfigFile
+---------------------------------------------------------------------*/
NPT_Result
NPT_LogManager::ParseConfigFile(const char* filename)
{
NPT_Result result;
/* load the file */
NPT_DataBuffer buffer;
result = NPT_File::Load(filename, buffer);
if (NPT_FAILED(result)) return result;
/* parse the config */
return ParseConfig((const char*)buffer.GetData(), buffer.GetDataSize());
}
示例5: buildMsg
void Server::sendMessage(NPT_UdpSocket* socket, std::string nt, std::string message)
{
std::string msg = buildMsg(nt, message);
NPT_IpAddress upnpAddress = getUPNPAddress();
NPT_DataBuffer buffer;
NPT_SocketAddress address;
address.SetIpAddress(upnpAddress);
address.SetPort(UPNP_PORT);
buffer.SetData((NPT_Byte*)msg.c_str(), msg.length());
socket->Send(buffer, &address);
}
示例6:
/*----------------------------------------------------------------------
| NPT_TlsSessionImpl::GetSessionId
+---------------------------------------------------------------------*/
NPT_Result
NPT_TlsSessionImpl::GetSessionId(NPT_DataBuffer& session_id)
{
if (m_SSL == NULL) {
// no handshake done
session_id.SetDataSize(0);
return NPT_ERROR_INVALID_STATE;
}
// return the session id
session_id.SetData(ssl_get_session_id(m_SSL),
ssl_get_session_id_size(m_SSL));
return NPT_SUCCESS;
}
示例7: sendReply
void Server::sendReply(std::string host, int port, std::string msg)
{
NPT_UdpSocket socket;
NPT_DataBuffer buffer;
NPT_IpAddress ip;
NPT_SocketAddress address;
ip.Parse(host.c_str());
address.SetIpAddress(ip);
address.SetPort(port);
buffer.SetData((NPT_Byte*)msg.c_str(), msg.length());
socket.Send(buffer, &address);
}
示例8: ssdpConnectorOnPacket
void FrontEnd::ssdpConnectorOnPacket(SsdpServerTask *task, Interface *intf, const NPT_DataBuffer& data, const NPT_SocketAddress& fromAddr)
{
const char *dataStr = reinterpret_cast<const char*>(data.GetData());
if (data.GetDataSize() > 10) {
if (NPT_String::CompareN(dataStr, "NOTIFY", 6) == 0) {
ReadLocker locker(m_cpLock);
for (NPT_Ordinal i = 0; i < m_controlPointList.GetItemCount(); i++) {
NPT_List<ControlPointInfo*>::Iterator it = m_controlPointList.GetItem(i);
ControlPointInfo *info = *it;
if (task->aborted()) {
return;
}
info->m_controlPoint->processSsdpNotify(&intf->m_context, data, fromAddr);
}
} else if (NPT_String::CompareN(dataStr, "M-SEARCH", 8) == 0) {
processSsdpSearch(task, intf, data, fromAddr);
}
}
}
示例9: DcfParser_GetContentKey
/*----------------------------------------------------------------------
| DcfParser_GetContentKey
+---------------------------------------------------------------------*/
static BLT_Result
DcfParser_GetContentKey(DcfParser* self,
const char* content_id,
NPT_DataBuffer& key)
{
// default
key.SetDataSize(0);
// check that we have a key manager
if (self->key_manager == NULL) return BLT_ERROR_NO_MEDIA_KEY;
// ask the key manager to resolve the key
key.Reserve(1024);
BLT_Size key_size = 1024;
BLT_Result result = BLT_KeyManager_GetKeyByName(self->key_manager, content_id, key.UseData(), &key_size);
if (BLT_FAILED(result)) {
if (result == ATX_ERROR_NOT_ENOUGH_SPACE) {
key.Reserve(key_size);
result = BLT_KeyManager_GetKeyByName(self->key_manager, content_id, key.UseData(), &key_size);
} else {
return result;
}
}
key.SetDataSize(key_size);
return BLT_SUCCESS;
}
示例10: 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);
}
示例11: inputStream0
void FrontEnd::processSsdpSearch(SsdpServerTask *task, Interface *intf, const NPT_DataBuffer& data, const NPT_SocketAddress& fromAddr)
{
do {
NPT_HttpRequest *req;
NPT_InputStreamReference inputStream0(new NPT_MemoryStream(data.GetData(), data.GetDataSize()));
NPT_BufferedInputStream inputStream(inputStream0);
if (NPT_FAILED(NPT_HttpRequest::Parse(inputStream, NULL, req))) {
break;
}
PtrHolder<NPT_HttpRequest> req1(req);
if (req->GetMethod().Compare("M-SEARCH") != 0 || req->GetProtocol().Compare(NPT_HTTP_PROTOCOL_1_1) != 0 || req->GetUrl().GetPath().Compare("*") != 0) {
break;
}
NPT_HttpHeader *hdrMan = req->GetHeaders().GetHeader("MAN");
if (!hdrMan || hdrMan->GetValue().Compare("\"ssdp:discover\"") != 0) {
break;
}
NPT_HttpHeader *hdrHost = req->GetHeaders().GetHeader("HOST");
if (!hdrHost || (hdrHost->GetValue().Compare("239.255.255.250:1900") != 0 && hdrHost->GetValue().Compare("239.255.255.250") != 0)) {
break;
}
int mx;
NPT_HttpHeader *hdrMX = req->GetHeaders().GetHeader("MX");
if (!hdrMX || NPT_FAILED(NPT_ParseInteger(hdrMX->GetValue(), mx)) || mx < 1) {
break;
}
if (mx > 120) {
mx = 120;
}
NPT_HttpHeader *hdrST = req->GetHeaders().GetHeader("ST");
if (!hdrST) {
break;
}
NPT_List<MatchContext*> matchList;
NPT_UdpSocket sock(NPT_SOCKET_FLAG_CANCELLABLE);
sock.Bind(NPT_SocketAddress(intf->m_context.m_ifAddr, 0));
NPT_SharedVariable waitVar;
waitVar.SetValue(0);
{
ReadLocker locker(m_dsLock);
for (NPT_Ordinal i = 0; i < m_deviceImplList.GetItemCount(); i++) {
NPT_List<DeviceImplInfo*>::Iterator it = m_deviceImplList.GetItem(i);
DeviceImplInfo *info = *it;
MatchContext *matchContext = new MatchContext();
if (info->m_deviceImpl->match(hdrST->GetValue(), matchContext->matches)) {
matchList.Add(matchContext);
matchContext->deviceUuid = info->m_deviceImpl->uuid();
matchContext->expireSeconds = info->m_deviceImpl->m_expireSeconds;
matchContext->descPath = info->m_deviceImpl->m_descPath;
matchContext->httpRoot = info->m_context.m_httpRoot;
} else {
delete matchContext;
}
}
}
SsdpSearchAbortCallback abortCallback(&sock, &waitVar);
if (task->registerAbortCallback(&abortCallback)) {
for (NPT_Ordinal i = 0; i < matchList.GetItemCount(); i++) {
MatchContext *matchContext = *matchList.GetItem(i);
NPT_String location = NPT_String::Format("http://%s:%d%s%s", intf->m_context.m_ifAddr.ToString().GetChars(), intf->m_context.m_httpPort, matchContext->httpRoot.GetChars(), matchContext->descPath.GetChars());
bool broken = false;
for (NPT_Ordinal j = 0; j < matchContext->matches.GetItemCount(); j++) {
NPT_List<DeviceImplMatch>::Iterator it2 = matchContext->matches.GetItem(j);
NPT_Timeout timeout = NPT_System::GetRandomInteger() % (mx * 1000);
// TODO: wait or not ???
timeout = 0;
if (NPT_SUCCEEDED(waitVar.WaitWhileEquals(0, timeout))) {
break;
}
{
ReadLocker locker(m_dsLock);
if (m_deviceImplIndex.HasKey(matchContext->deviceUuid)) {
NPT_TimeStamp ts;
NPT_System::GetCurrentTimeStamp(ts);
NPT_String dateStr = NPT_DateTime(ts).ToString(NPT_DateTime::FORMAT_RFC_1123);
NPT_String resp = NPT_String::Format("HTTP/1.1 200 OK\r\nCACHE-CONTROL: max-age=%d\r\nDATE: %s\r\nEXT: \r\nLOCATION: %s\r\nSERVER: %s\r\nST: %s\r\nUSN: %s\r\nCUSTOM:%s\r\n\r\n",
matchContext->expireSeconds, dateStr.GetChars(), location.GetChars(), m_serverHeader.GetChars(), it2->m_st.GetChars(), it2->m_usn.GetChars(), m_DevName.GetChars());
NPT_DataBuffer packet(resp.GetChars(), resp.GetLength(), false);
sock.Send(packet, &fromAddr);
}
}
}
if (broken) {
//.........这里部分代码省略.........
示例12: main
/*----------------------------------------------------------------------
| main
+---------------------------------------------------------------------*/
int
main(int /*argc*/, char** /*argv*/)
{
NPT_Result result;
NPT_String t = "hello";
NPT_String base64;
NPT_DataBuffer data;
result = NPT_Base64::Encode((const NPT_Byte*)t.GetChars(), t.GetLength(), base64);
NPT_ASSERT(NPT_SUCCEEDED(result));
NPT_ASSERT(base64 == "aGVsbG8=");
result = NPT_Base64::Decode(base64.GetChars(), base64.GetLength(), data);
NPT_ASSERT(NPT_SUCCEEDED(result));
NPT_ASSERT(data.GetDataSize() == t.GetLength());
NPT_String tt((const char*)data.GetData(), data.GetDataSize());
NPT_ASSERT(tt == t);
t = "hello!";
result = NPT_Base64::Encode((const NPT_Byte*)t.GetChars(), t.GetLength(), base64);
NPT_ASSERT(NPT_SUCCEEDED(result));
NPT_ASSERT(base64 == "aGVsbG8h");
result = NPT_Base64::Decode(base64.GetChars(), base64.GetLength(), data);
NPT_ASSERT(NPT_SUCCEEDED(result));
NPT_ASSERT(data.GetDataSize() == t.GetLength());
tt.Assign((const char*)data.GetData(), data.GetDataSize());
NPT_ASSERT(tt == t);
t = "hello!!";
result = NPT_Base64::Encode((const NPT_Byte*)t.GetChars(), t.GetLength(), base64);
NPT_ASSERT(NPT_SUCCEEDED(result));
NPT_ASSERT(base64 == "aGVsbG8hIQ==");
result = NPT_Base64::Decode(base64.GetChars(), base64.GetLength(), data);
NPT_ASSERT(NPT_SUCCEEDED(result));
NPT_ASSERT(data.GetDataSize() == t.GetLength());
tt.Assign((const char*)data.GetData(), data.GetDataSize());
NPT_ASSERT(tt == t);
unsigned char r256_bin[] = {
0x7d, 0x5f, 0xd0, 0xf4, 0x6a, 0xa8, 0xae, 0x34, 0x6e, 0x32, 0x1d, 0xa1,
0xef, 0x66, 0xdd, 0x82, 0x76, 0xa6, 0xfd, 0x8c, 0x75, 0x97, 0xa0, 0x01,
0x00, 0xde, 0x52, 0xef, 0xdf, 0xb6, 0x3e, 0xe4, 0x7b, 0x45, 0xdd, 0x2b,
0xa1, 0x9c, 0xb0, 0x6d, 0x2c, 0x75, 0xb1, 0x87, 0x43, 0x0f, 0xea, 0x24,
0x36, 0x11, 0x7e, 0xee, 0xd1, 0x91, 0x7f, 0x7b, 0x02, 0xea, 0x9a, 0x2a,
0x25, 0xc0, 0xac, 0x99, 0xa4, 0x89, 0x55, 0x5b, 0x82, 0xdf, 0xb0, 0x7e,
0xa1, 0x78, 0x0f, 0xdf, 0x25, 0x5f, 0x3d, 0xba, 0xcb, 0xbc, 0x35, 0x04,
0xc3, 0xf4, 0xb8, 0xc0, 0x17, 0x8e, 0x75, 0x01, 0xe6, 0x2f, 0x88, 0x2c,
0x76, 0x0a, 0x8c, 0x3f, 0x83, 0xd4, 0x10, 0xa8, 0x00, 0xfc, 0xa0, 0x92,
0x7b, 0xae, 0xa3, 0x8c, 0x47, 0xea, 0x25, 0xf9, 0x29, 0x81, 0x1c, 0x21,
0xf2, 0xf4, 0xfe, 0x07, 0x7e, 0x4b, 0x01, 0x79, 0x41, 0x3a, 0xb6, 0x71,
0x0b, 0x75, 0xa7, 0x9d, 0x1b, 0x12, 0xc4, 0x46, 0x06, 0xf3, 0x5f, 0x00,
0x05, 0x2a, 0x1b, 0x34, 0xd6, 0x87, 0xc4, 0x70, 0xcc, 0xc3, 0x9e, 0xa8,
0x24, 0x2c, 0x97, 0x4e, 0xfc, 0x91, 0x70, 0x1c, 0x29, 0x66, 0xc3, 0x23,
0xbf, 0xd7, 0x4d, 0x35, 0x51, 0xff, 0xeb, 0xde, 0x45, 0xbd, 0x8d, 0x80,
0x44, 0x2a, 0x8d, 0xc0, 0xe8, 0x6a, 0xe2, 0x86, 0x46, 0x9f, 0xf2, 0x3c,
0x93, 0x0d, 0x27, 0x02, 0xe4, 0x79, 0xa1, 0x21, 0xf4, 0x43, 0xcd, 0x4c,
0x22, 0x25, 0x9e, 0x93, 0xeb, 0x77, 0x8e, 0x1e, 0x57, 0x1e, 0x9b, 0xcb,
0x91, 0x86, 0xcf, 0x15, 0xaf, 0xd5, 0x03, 0x0f, 0x70, 0xbe, 0x6e, 0x37,
0xea, 0x37, 0xdd, 0xf6, 0xa1, 0xb1, 0xf7, 0x05, 0xbc, 0x2d, 0x44, 0x60,
0x35, 0xa4, 0x05, 0x0b, 0x22, 0x7d, 0x7a, 0x71, 0xe5, 0x1d, 0x8e, 0xcb,
0xc3, 0xb8, 0x3a, 0xe1
};
NPT_String b64;
NPT_Base64::Encode(r256_bin, sizeof(r256_bin), b64);
NPT_DataBuffer r256_out;
NPT_Base64::Decode(b64.GetChars(), b64.GetLength(), r256_out);
NPT_ASSERT(r256_out.GetDataSize() == sizeof(r256_bin));
NPT_ASSERT(r256_bin[sizeof(r256_bin)-1] == r256_out.GetData()[sizeof(r256_bin)-1]);
unsigned char random_bytes[] = {
0xc7, 0xee, 0x49, 0x9e, 0x2c, 0x8b, 0x1c, 0x16, 0x9e, 0x7f, 0x30, 0xd0,
0xc6, 0x12, 0x30, 0x80, 0x81, 0xcd, 0x20, 0x20, 0x26, 0xaf, 0x4f, 0xd6,
0xfc, 0x86, 0x2e, 0x85, 0xf3, 0x10, 0x38, 0x2b, 0x0e, 0xbb, 0x80, 0x68,
0xbe, 0xff, 0x1c, 0xdc, 0x72, 0xb5, 0x0d, 0x8f, 0x8e, 0x6c, 0x09, 0x63,
0xba, 0x21, 0x23, 0xb2, 0x24, 0x17, 0xd3, 0x17, 0x69, 0x44, 0x77, 0x11,
0x36, 0x6a, 0x6e, 0xf2, 0x44, 0x87, 0xa1, 0xd3, 0xf3, 0x1f, 0x6c, 0x38,
0x22, 0x4a, 0x44, 0x70, 0x66, 0xef, 0x8c, 0x3a, 0x51, 0xc8, 0xee, 0x85,
0x00, 0x25, 0x93, 0x10, 0x2e, 0x0b, 0x1b, 0x03, 0x94, 0x47, 0x05, 0x22,
0xd0, 0xc4, 0xec, 0x2e, 0xcc, 0xbc, 0xbb, 0x67, 0xfd, 0xec, 0x0e, 0xb1,
0x3f, 0xbc, 0x82, 0xe0, 0xa7, 0x9c, 0xf3, 0xae, 0xbd, 0xb7, 0xab, 0x02,
0xf1, 0xd9, 0x17, 0x4c, 0x9d, 0xeb, 0xe2, 0x00, 0x1e, 0x19, 0x6e, 0xb3,
0xfd, 0x7d, 0xea, 0x49, 0x85, 0x43, 0x2f, 0x56, 0x81, 0x89, 0xba, 0x71,
0x37, 0x10, 0xb5, 0x74, 0xab, 0x90, 0x4d, 0xc4, 0xd1, 0x0d, 0x8d, 0x6f,
0x01, 0xf5, 0x2c, 0xc9, 0x1a, 0x79, 0xa1, 0x41, 0x71, 0x2b, 0xfb, 0xf3,
0xd5, 0xe4, 0x2a, 0xf5, 0xad, 0x80, 0x7a, 0x03, 0xff, 0x5f, 0x45, 0x8c,
0xec, 0x6a, 0x4b, 0x05, 0xe3, 0x65, 0x19, 0x70, 0x05, 0xad, 0xc4, 0xb8,
0x4e, 0x9e, 0x9a, 0x36, 0x4a, 0x86, 0x9d, 0xf5, 0x99, 0xcb, 0x00, 0xb8,
0xb9, 0xa7, 0x86, 0x18, 0xfc, 0x9a, 0xe7, 0x00, 0x6a, 0x67, 0xfa, 0x42,
0x9d, 0xff, 0x4d, 0x7a, 0xe4, 0xe8, 0x03, 0x88, 0xff, 0x60, 0xe1, 0x8d,
0x09, 0x5f, 0x6f, 0xde, 0x6b
};
NPT_Array<unsigned char> random(random_bytes, NPT_ARRAY_SIZE(random_bytes));
t = "x+5JniyLHBaefzDQxhIwgIHNICAmr0/W/IYuhfMQOCsOu4Bovv8c3HK1DY+ObAlj\r\n"
"uiEjsiQX0xdpRHcRNmpu8kSHodPzH2w4IkpEcGbvjDpRyO6FACWTEC4LGwOURwUi\r\n"
"0MTsLsy8u2f97A6xP7yC4Kec8669t6sC8dkXTJ3r4gAeGW6z/X3qSYVDL1aBibpx\r\n"
"NxC1dKuQTcTRDY1vAfUsyRp5oUFxK/vz1eQq9a2AegP/X0WM7GpLBeNlGXAFrcS4\r\n"
//.........这里部分代码省略.........
示例13: DcfParser_ParseV2Header
/*----------------------------------------------------------------------
| DcfParser_ParseV2Header
+---------------------------------------------------------------------*/
static BLT_Result
DcfParser_ParseV2Header(DcfParser* self, ATX_InputStream* stream)
{
/* rewind the byte stream */
ATX_InputStream_Seek(stream, 0);
/* parse the atoms from the stream */
AP4_ByteStream* mp4_stream = new ATX_InputStream_To_AP4_ByteStream_Adapter(stream);
AP4_AtomParent atoms;
AP4_Result result = AP4_DefaultAtomFactory::Instance.CreateAtomsFromStream(*mp4_stream, atoms);
mp4_stream->Release();
AP4_ByteStream* decrypting_stream = NULL;
AP4_ContainerAtom* odrm = dynamic_cast<AP4_ContainerAtom*>(atoms.GetChild(AP4_ATOM_TYPE_ODRM));
if (odrm) {
AP4_OdheAtom* odhe = dynamic_cast<AP4_OdheAtom*>(odrm->GetChild(AP4_ATOM_TYPE_ODHE));
AP4_OddaAtom* odda = dynamic_cast<AP4_OddaAtom*>(odrm->GetChild(AP4_ATOM_TYPE_ODDA));
if (odhe && odda) {
const char* content_id = "";
/* get the content ID */
AP4_OhdrAtom* ohdr = dynamic_cast<AP4_OhdrAtom*>(odhe->GetChild(AP4_ATOM_TYPE_OHDR));
if (ohdr) {
content_id = ohdr->GetContentId().GetChars();
}
/* get the content key */
NPT_DataBuffer key;
result = DcfParser_GetContentKey(self, content_id, key);
if (BLT_FAILED(result)) {
ATX_LOG_FINE_2("GetKeyForContent(%s) returned %d",
content_id,
result);
return BLT_ERROR_NO_MEDIA_KEY;
}
/* create the decrypting stream */
result = AP4_OmaDcfAtomDecrypter::CreateDecryptingStream(*odrm,
key.GetData(),
key.GetDataSize(),
self->cipher_factory,
decrypting_stream);
if (AP4_SUCCEEDED(result)) {
/* update the content type */
ATX_CopyStringN(self->input.content_type,
odhe->GetContentType().GetChars(),
sizeof(self->input.content_type));
/* update the encrypted size */
self->input.encrypted_size = odda->GetEncryptedDataLength();
}
}
}
/* check that we have found what we needed in the atoms */
if (decrypting_stream == NULL) return BLT_ERROR_INVALID_MEDIA_FORMAT;
/* update the output size */
AP4_LargeSize plaintext_size = 0;
if (AP4_SUCCEEDED(decrypting_stream->GetSize(plaintext_size))) {
self->output.size = plaintext_size;
} else {
self->output.size = self->input.encrypted_size;
}
/* create a reverse adapter */
result = AP4_ByteStream_To_ATX_InputStream_Adapter_Create(decrypting_stream, &self->output.stream);
decrypting_stream->Release();
return BLT_SUCCESS;
}
示例14: DcfParser_ParseV1Header
/*----------------------------------------------------------------------
| DcfParser_ParseV1Header
+---------------------------------------------------------------------*/
static BLT_Result
DcfParser_ParseV1Header(DcfParser* self, ATX_InputStream* stream)
{
/* rewind the byte stream */
ATX_InputStream_Seek(stream, 0);
/* user a buffer for parsing */
ATX_UInt8 buffer[3];
/* read the first 3 fields */
ATX_Result result;
result = ATX_InputStream_ReadFully(stream, buffer, 3);
if (ATX_FAILED(result)) return result;
/* check the version */
ATX_UInt8 version = buffer[0];
if (version != 1) {
ATX_LOG_FINE_1("unsupported DCF version (%d)", version);
return BLT_ERROR_UNSUPPORTED_FORMAT;
}
/* read the content type */
ATX_UInt8 content_type_length = buffer[1];
self->input.content_type[content_type_length] = 0; // null-terminate
result = ATX_InputStream_ReadFully(stream, self->input.content_type, content_type_length);
if (ATX_FAILED(result)) return result;
/* read the content URI */
ATX_UInt8 content_uri_length = buffer[2];
self->input.content_uri[content_uri_length] = 0; // null-terminate
result = ATX_InputStream_ReadFully(stream, self->input.content_uri, content_uri_length);
if (ATX_FAILED(result)) return result;
/* read the variable-length fields */
unsigned int var_length_1, var_length_2;
ATX_UInt32 headers_length = 0;
result = DcfParser_ReadUintvar(stream, headers_length, var_length_1);
if (ATX_FAILED(result)) return result;
ATX_UInt32 data_length = 0;
result = DcfParser_ReadUintvar(stream, data_length, var_length_2);
if (ATX_FAILED(result)) return result;
/* check that the encrypted size makes sense */
if (data_length < 32) return BLT_ERROR_INVALID_MEDIA_FORMAT;
self->input.encrypted_size = data_length;
/* get the content key */
NPT_DataBuffer key;
result = DcfParser_GetContentKey(self, self->input.content_uri, key);
if (BLT_FAILED(result)) {
ATX_LOG_FINE_2("GetKeyForContent(%s) returned %d",
self->input.content_uri,
result);
return BLT_ERROR_NO_MEDIA_KEY;
}
/* read the headers */
if (headers_length > BLT_DCF_PARSER_MAX_HEADERS_LENGTH) return BLT_ERROR_INVALID_MEDIA_FORMAT;
char* headers = new char[headers_length+1];
headers[headers_length] = '\0';
result = ATX_InputStream_ReadFully(stream, headers, headers_length);
if (ATX_FAILED(result)) {
delete[] headers;
return result;
}
/* as a first-order estimate, set the output size to the encrypted size minus the IV */
self->output.size = self->input.encrypted_size-16;
/* parse the headers */
NPT_MemoryStream* headers_memory_stream = new NPT_MemoryStream(headers, headers_length);
NPT_InputStreamReference headers_memory_stream_ref(headers_memory_stream);
NPT_BufferedInputStream* headers_buffered_stream =
new NPT_BufferedInputStream(headers_memory_stream_ref);
NPT_HttpHeaders content_headers;
content_headers.Parse(*headers_buffered_stream);
delete headers_buffered_stream;
delete[] headers;
/* find out about the encryption from the headers */
const NPT_String* encryption_method = content_headers.GetHeaderValue("Encryption-Method");
if (encryption_method == NULL) return BLT_ERROR_INVALID_MEDIA_FORMAT;
/* check the encryption method */
bool encryption_supported = false;
NPT_Map<NPT_String,NPT_String> encryption_params;
NPT_Size algorithm_id_length = 0;
/* parse the algorithm id */
int separator = encryption_method->Find(';', 0, true);
if (separator > 0) {
algorithm_id_length = separator;
/* parse the params */
result = NPT_ParseMimeParameters(((const char*)(*encryption_method))+separator+1,
encryption_params);
if (NPT_FAILED(result)) {
//.........这里部分代码省略.........
示例15: GetAvailable
/*----------------------------------------------------------------------
| NPT_InputStream::Load
+---------------------------------------------------------------------*/
NPT_Result
NPT_InputStream::Load(NPT_DataBuffer& buffer, NPT_Size max_read /* = 0 */)
{
NPT_Result result;
NPT_Size total_bytes_read;
// reset the buffer
buffer.SetDataSize(0);
// try to get the stream size
NPT_Size size;
if (NPT_SUCCEEDED(GetSize(size))) {
// make sure we don't read more than max_read
if (max_read && max_read < size) size = max_read;
} else {
size = max_read;
}
// pre-allocate the buffer
if (size) NPT_CHECK(buffer.Reserve(size));
// read the data from the file
total_bytes_read = 0;
do {
NPT_Size available = 0;
NPT_Size bytes_to_read;
NPT_Size bytes_read;
NPT_Byte* data;
// check if we know how much data is available
result = GetAvailable(available);
if (NPT_SUCCEEDED(result) && available) {
// we know how much is available
bytes_to_read = available;
} else {
bytes_to_read = NPT_INPUT_STREAM_LOAD_DEFAULT_READ_CHUNK;
}
// make sure we don't read more than what was asked
if (size != 0 && total_bytes_read+bytes_to_read>size) {
bytes_to_read = size-total_bytes_read;
}
// stop if we've read everything
if (bytes_to_read == 0) break;
// ensure that the buffer has enough space
NPT_CHECK(buffer.Reserve(total_bytes_read+bytes_to_read));
// read the data
data = buffer.UseData()+total_bytes_read;
result = Read((void*)data, bytes_to_read, &bytes_read);
if (NPT_SUCCEEDED(result) && bytes_read != 0) {
total_bytes_read += bytes_read;
buffer.SetDataSize(total_bytes_read);
}
} while(NPT_SUCCEEDED(result) && (size==0 || total_bytes_read < size));
if (result == NPT_ERROR_EOS) {
return NPT_SUCCESS;
} else {
return result;
}
}