bool HLXIHXFileTest::HandleWriteCmd(const UTVector<UTString>& info) { bool bRetVal = false; if (m_pIHXDataFile) { IHXBuffer* pHXBuffer = new CHXBuffer(); if (pHXBuffer) { pHXBuffer->AddRef(); if (pHXBuffer->Set((const UINT8*) ((const char*) info[1]), strlen(info[1])) == HXR_OK) { ULONG32 ulRetSize; ULONG32 ulInSize; ulInSize = pHXBuffer->GetSize(); ulRetSize = m_pIHXDataFile->Write(pHXBuffer); bRetVal = (ulRetSize == ulInSize); bRetVal = (bRetVal == CFileTestUtil::ParseResultString(info[2])); } pHXBuffer->Release(); } } return bRetVal; }
HX_RESULT CHXFMTPParser::CollectToken(const char*& pBuf, const char* pDelims, IHXBuffer** ppTokDest, HXBOOL& bAddValue) { HX_RESULT res = HXR_OK; CHXCharStack tok(m_pCCF); // Collect value while((HXR_OK == res) && *pBuf && !strchr(pDelims, *pBuf)) { res = tok.AddChar(*pBuf++); } IHXBuffer* pTok = 0; if ((HXR_OK == res) && (HXR_OK == (res = tok.Finish(pTok)))) { // Make sure we dont have an empty string if (pTok->GetSize() > 1) { *ppTokDest = pTok; } else { bAddValue = TRUE; HX_RELEASE(pTok); } } return res; }
HX_RESULT HXSymbianTCPReader::Read(RSocket& socket, UINT16 uSize) { HX_RESULT res = HXR_FAILED; if (m_pParent) { res = HXSymbianSocketHelper::ResizeOrCreate(m_pCCF, uSize, m_pBuffer); if (HXR_OK == res) { IHXTimeStampedBuffer* pTSBuffer = 0; if(HXR_OK == m_pBuffer->QueryInterface(IID_IHXTimeStampedBuffer, (void **)&pTSBuffer)) { pTSBuffer->SetTimeStamp(HX_GET_TICKCOUNT()); HX_RELEASE(pTSBuffer); } m_bufDes.Set(m_pBuffer->GetBuffer(), 0, m_pBuffer->GetSize()); iStatus = KRequestPending; socket.RecvOneOrMore(m_bufDes, 0, iStatus, m_amountRead); SetActive(); } } return res; }
void OutputBuffers(UINT16 ulStreamID, IHXValues* pHdr) { const char* pName = 0; IHXBuffer* pValue = 0; HX_RESULT res = pHdr->GetFirstPropertyBuffer(pName, pValue); while (HXR_OK == res) { printf("GetBuffer %u \"%s\" \"", ulStreamID, pName); UCHAR* pCur = pValue->GetBuffer(); UCHAR* pEnd = pCur + pValue->GetSize(); static const char z_hexChars[] = "0123456789abcdef"; for (;pCur < pEnd; pCur++) { printf("%c%c", z_hexChars[*pCur >> 4], z_hexChars[*pCur & 0xf]); } printf("\"\n"); HX_RELEASE(pValue); res = pHdr->GetNextPropertyBuffer(pName, pValue); } HX_RELEASE(pValue); }
HX_RESULT HXCloakedV2TCPSocket::_ReadChunk(ULONG32& ulSizeRead ) { HX_RESULT res = HXR_FAIL; IHXBuffer* pBuf = NULL; IHXBuffer* pNew = NULL; ULONG32 ulBytesUsed = 0; HX_ASSERT( csReady == m_CloakingState || csPostWait == m_CloakingState || csGetWait == m_CloakingState ); res = _GetReadQueue(pBuf); if( pBuf && SUCCEEDED(res) ) { res = _UnChunkBuffer(pBuf, pNew, ulBytesUsed ); if( SUCCEEDED(res) ) { ulSizeRead = pNew->GetSize(); //Enque the data onto the RTSP queue. res = m_RTSPQueue.EnQueue(pNew->GetBuffer(), ulSizeRead); //Put back any unused data if( ulBytesUsed < pBuf->GetSize() ) { m_ReadQueue.EnQueue(pBuf->GetBuffer()+ulBytesUsed, pBuf->GetSize()-ulBytesUsed); } res = HXR_OK; } else { //We do not have a full chunk yet. Put our data back on //the read queue and wait for the full chunk to come in. m_ReadQueue.EnQueue(pBuf->GetBuffer(), pBuf->GetSize()); } HX_RELEASE(pNew); HX_RELEASE(pBuf); } return res; }
CHXString HXCloakedV2TCPSocket::_GetProxyAuthString() { IHXBuffer* pBuffer = NULL; CHXString retStr = ""; CHXString key = "proxy-authentication.http:"; IHXBuffer* pHeaderBuffer = NULL; HX_RESULT res = HXR_OK; IHXRegistry* pRegistry = NULL; CHXString recentProxyAuth; res = m_pContext->QueryInterface(IID_IHXRegistry, (void**)&pRegistry); if( SUCCEEDED(res) ) { res = pRegistry->GetStrByName("proxy-authentication.http.realm.recent", pHeaderBuffer); if (SUCCEEDED(res)) { recentProxyAuth = CHXString((const char*)pHeaderBuffer->GetBuffer(), pHeaderBuffer->GetSize()); } HX_RELEASE(pHeaderBuffer); key += m_pszProxyName; key += ":"; key += recentProxyAuth; res = pRegistry->GetStrByName((const char*)key, pBuffer); if( SUCCEEDED(res) && pBuffer ) { CHXString authString((const char*)pBuffer->GetBuffer(), pBuffer->GetSize()); retStr = "Proxy-Authorization: "; retStr += authString; } HX_RELEASE(pBuffer); } HX_RELEASE(pRegistry); return retStr; }
void HXSymbianTCPWriter::Write(RSocket& socket, IHXBuffer* pBuffer) { HX_RELEASE(m_pBuffer); m_pBuffer = pBuffer; if (m_pBuffer) { m_pBuffer->AddRef(); m_bufDes.Set(m_pBuffer->GetBuffer(), m_pBuffer->GetSize()); iStatus = KRequestPending; socket.Write(m_bufDes, iStatus); SetActive(); } }
// Don't protect anything in this method with mutexes. It has // already been done from where it is called from. But mostly // because we aren't using recursive mutexes yet. ULONG32 CAudioOutOpenwave::_PushBits() { if (!m_bWriteDone) { //OpDPRINTF("_PushBits : ERROR Both buffers are writing?\n"); return 0; } if (m_pWriteList == NULL || m_pWriteList->GetCount() <= 0) { //OpDPRINTF("_PushBits : ERROR Nothing to write\n"); //OpDPRINTF("_PushBits : m_pWriteList(%d) %d\n", m_pWriteList->GetCount(), m_nCurBuf); return 0; } if (m_SndBuf[m_nCurBuf].fState == OP_SNDBUF_STATE_NOWPLAYING || m_SndBuf[m_nCurBuf].fState == OP_SNDBUF_STATE_QUEUED) { //OpDPRINTF("_PushBits : buf playing %d\n", m_nCurBuf); return 0; } //OpDPRINTF("_PushBits : m_pWriteList(%d)\n", m_pWriteList->GetCount()); IHXBuffer* pBuffer = NULL; UCHAR* pData = 0; ULONG32 nSize = 0; op_sound_buffer* sndbuf; sndbuf = &m_SndBuf[m_nCurBuf]; m_nCurBuf = !m_nCurBuf; //m_nCurBuf = (m_nCurBuf + 1) % 10; // use all ten buffers //We are going to try and write. Grab the head and do it. pBuffer = (IHXBuffer*)m_pWriteList->RemoveHead(); pData = pBuffer->GetBuffer(); nSize = pBuffer->GetSize(); memcpy( (unsigned char*)sndbuf->fSampleBuffer, pData, nSize ); HX_RELEASE( pBuffer ); sndbuf->fNSamples = (nSize) / (m_unNumChannels * (m_unBitsPerSample/8)); m_ulTotalWritten += nSize; //Keep track of how much we have written to the device. op_sound_write (m_pSndDev, sndbuf); m_bWriteDone = false; return nSize; }
HX_RESULT HXCloakedV2TCPSocket::_ReadFromSocket() { HX_RESULT res = HXR_FAIL; IHXBuffer* pBuf = NULL; res = m_pTCPSocket->Read(&pBuf); if( pBuf && SUCCEEDED(res) ) { //XXXgfw performance problem here. All data is in IHXBuffers //up until this point. Now we are doing a memcpy for each //packet received. Bad bad bad. res = m_ReadQueue.EnQueue(pBuf->GetBuffer(), pBuf->GetSize()); HX_RELEASE(pBuf); } return res; }
/////////////////////////////////// // // DoProcess // // *** Called by Process and ProcessOutput *** // // The DoProcess method processes the sound data. // // Parameters // // pbData // Pointer to the output buffer // // pbInputData // Pointer to the input buffer // // dwQuanta // Number of quanta to process // // Return Value // S_OK Success // HRESULT CHXAudioDeviceHookBase::DoProcess(BYTE *pbData, const BYTE *pbInputData, DWORD dwQuanta) { if( m_pHook ) { DWORD dwInputBufSize = dwQuanta * WaveFormat()->nBlockAlign; IHXBuffer* pBuffer = NULL; if (HXR_OK == CreateAndSetBufferWithoutAllocCCF(pBuffer, (UCHAR*) pbInputData, dwInputBufSize, m_pContext)) { HXBOOL bChanged = FALSE; if( SUCCEEDED( m_pHook->ProcessAudioDeviceHooks( pBuffer, bChanged )) && bChanged ) { memcpy( pbData, pBuffer->GetBuffer(), HX_MIN( dwInputBufSize, pBuffer->GetSize()) ); } HX_RELEASE( pBuffer ); } } return S_OK; }
CMediaPacket* CPCMAudioFormat::CreateAssembledPacket(IHXPacket* pPacket) { CMediaPacket* pRet = NULL; if (pPacket) { IHXBuffer* pBuffer = pPacket->GetBuffer(); if (pBuffer) { UINT32 ulFlags = MDPCKT_USES_IHXBUFFER_FLAG; pRet = new CMediaPacket(pBuffer, (UINT8*) pBuffer->GetBuffer(), pBuffer->GetSize(), pBuffer->GetSize(), pPacket->GetTime(), ulFlags, NULL); pBuffer->Release(); } } return pRet; }
HX_RESULT CHXAltGroupIterator::GetAltIDSet(CHXAltIDSet& altIDSet) const { HX_RESULT res = HXR_UNEXPECTED; if (m_pItr) { altIDSet.Clear(); IUnknown* pUnk = m_pItr->GetItem(); IHXBuffer* pBuf = NULL; if (pUnk && (HXR_OK == pUnk->QueryInterface(IID_IHXBuffer, (void**)&pBuf))) { // AltIDs are stored in network byte order in the // IHXBuffer UINT32 uIDCount = pBuf->GetSize() / 4; UINT32* pIDs = (UINT32*)pBuf->GetBuffer(); // Add the AltIDs to altIDSet res = HXR_OK; for (UINT32 i = 0; (HXR_OK == res) && (i < uIDCount); i++) { UINT32 uAltID = DwToHost(pIDs[i]); res = altIDSet.AddID(uAltID); } } HX_RELEASE(pBuf); HX_RELEASE(pUnk); } return res; }
void DataRevertController::RevertHeaders(IHXValues* pFileHeader, CHXSimpleList* pStreamHeaders, IHXValues* pResponseHeaders) { IHXBuffer* pMimeType = 0; IHXValues* pHeader; CHXSimpleList::Iterator i; char* pConversionType = NULL; IUnknown* pUnkReverter = NULL; HX_RELEASE(m_pDataRevert); i = pStreamHeaders->Begin(); if (i != pStreamHeaders->End()) { pHeader = (IHXValues*)(*i); pHeader->GetPropertyCString("MimeType", pMimeType); if (!pMimeType) { HX_ASSERT(0); goto exit; } if (strncasecmp((const char*)pMimeType->GetBuffer(), HX_CONVERT_MIME_TYPE, (int)strlen(HX_CONVERT_MIME_TYPE))) { goto exit; } pConversionType = (char*)pMimeType->GetBuffer() + strlen(HX_CONVERT_MIME_TYPE); if (m_pPlugin2Handler && HXR_OK == m_pPlugin2Handler->FindPluginUsingStrings( PLUGIN_CLASS, PLUGIN_REVERTER_TYPE, PLUGIN_REVERTER_MIME, pConversionType, NULL, NULL, pUnkReverter)) { pUnkReverter->QueryInterface(IID_IHXDataRevert, (void**)&m_pDataRevert); pUnkReverter->Release(); } if (!m_pDataRevert) { goto exit; } IHXPlugin* pPlugin; m_pDataRevert->QueryInterface(IID_IHXPlugin, (void**)&pPlugin); pPlugin->InitPlugin(m_pContext); pPlugin->Release(); HX_RELEASE(pMimeType); m_pStreamHeaders = new CHXSimpleList; m_pRevertedStreamHeaders = new CHXSimpleList; IHXBuffer* pConvertHeader = 0; for (i = pStreamHeaders->Begin(); i != pStreamHeaders->End(); ++i) { pHeader = (IHXValues*)(*i); /* * If this stream header was converted and flattened then * the one we want to give to the plugin is the result * of re-inflating that. If not, then just give the plugin * the one we already got. */ if (HXR_OK == pHeader->GetPropertyBuffer("DataConvertStreamHeader", pConvertHeader)) { pHeader = InflateConvertHeader(pConvertHeader); pConvertHeader->Release(); } else { IHXBuffer* pPreConvertMimeType; if (HXR_OK == pHeader->GetPropertyCString("PreConvertMimeType", pPreConvertMimeType)) { pHeader->SetPropertyCString("MimeType", pPreConvertMimeType); pPreConvertMimeType->Release(); } pHeader->AddRef(); } m_pStreamHeaders->AddTail((void*)pHeader); } m_pResponseHeaders = pResponseHeaders; m_pResponseHeaders->AddRef(); /* * If playing through an old proxy which does not support * initiate-session then the DataConvertBuffer will come in here. * This is not an ideal situation because only one can come in * at this point, but it's better then nothing. */ IHXBuffer* pConvertBuffer = 0; if (HXR_OK == pFileHeader->GetPropertyBuffer("DataConvertBuffer", pConvertBuffer)) { const char* pContent = (const char*)pConvertBuffer->GetBuffer(); IHXBuffer* pNewBuffer = NULL; if (HXR_OK == CreateBufferCCF(pNewBuffer, m_pContext)) { int contentLen = pConvertBuffer->GetSize(); pNewBuffer->SetSize(contentLen); int offset = BinFrom64(pContent, contentLen, (unsigned char*)pNewBuffer->GetBuffer()); pNewBuffer->SetSize(offset); ControlBufferReady(pNewBuffer); HX_RELEASE(pNewBuffer); } HX_RELEASE(pConvertBuffer); } /* * Again for file header, if the header was converted and * flattened then give to plugin the inflated version of that. * If not, then give the straight old header that we already * have. */ if (HXR_OK == pFileHeader->GetPropertyBuffer("DataConvertFileHeader", pConvertHeader)) { m_pFileHeaders = InflateConvertHeader(pConvertHeader); pConvertHeader->Release(); } else { m_pFileHeaders = pFileHeader; m_pFileHeaders->AddRef(); } m_pDataRevert->DataRevertInit(this); return; } exit:; HX_RELEASE(pMimeType); m_pControlResp->RevertHeadersDone(pFileHeader, pStreamHeaders, pResponseHeaders, FALSE); }
HX_RESULT CRN1CloakPOSTHandler::HandlePOSTData(IHXBuffer* pBuf) { IHXBuffer* pDecBuf = NULL; CBaseCloakGETHandler* pGETHandler = NULL; BYTE* pData = (BYTE*)pBuf->GetBuffer(); UINT32 uDataLen = pBuf->GetSize(); if (m_bOnClosedCalled) { return HXR_OK; } if (m_pConn) { m_pConn->GetGETHandler(pGETHandler); } if (!pGETHandler) { QueuePendingData(pData, uDataLen); // m_pGETHandler is guaranteed to not exist here. HX_RELEASE(pGETHandler); return HXR_OK; } // We were unable to process a fragment of the previous // packet, so append this packet to it and try to process them // both as one bigger packet. if (m_pPendingData) { // If we're processing it, it shouldn't be in the queue anymore! HX_ASSERT(!m_bProcessingPendingData); QueuePendingData(pData, uDataLen); ProcessPendingData(); return HXR_OK; } HX_ASSERT(pGETHandler); pGETHandler->Release(); pGETHandler = NULL; while (!m_bOnClosedCalled && uDataLen) { BOOL bPostDone = FALSE; UINT32 n = decodeBuf(pData, uDataLen, pDecBuf, bPostDone); if (n == 0) { if (uDataLen < MAX_POST_MESSAGE_LENGTH) { QueuePendingData(pData, uDataLen); } else { // We're already trying to process a fragment. // We don't want to use too much memory, so stop now. DPRINTF(0x10000000, ("RN Cloak v1 -- Max POST length exceeded\n")); m_pDemux->Close(HXR_FAIL); CleanupConn(HXR_FAIL); } break; } pData += n; uDataLen -= n; if (pDecBuf->GetSize() == 1 && pDecBuf->GetBuffer()[0] == HTTP_DONE) { // Client is done with this cloak connection. Close all GET // and POST requests associated with this GUID. CleanupConn(HXR_FAIL); break; } HX_ASSERT(m_pConn); m_pConn->OnPOSTData(pDecBuf); HX_RELEASE(pDecBuf); // if m_pGETHandler is invalid at this point then there is an extra // m_pGETHandler->release() somewhere that needs to b found. if ((m_pConn->GetCloakMode() & CLOAK_MODE_MULTIPOST) && bPostDone) { // Client is in multi-POST mode and it is done with this POST. // Close this POST, leaving any other requests alone. m_pDemux->Close(HXR_OK); // Do not remove from the GUID dict, since other POSTs may follow. CleanupConn(HXR_OK); break; } } HX_RELEASE(pDecBuf); return HXR_OK; }
HX_RESULT HXCloakedV2TCPSocket::_ParseGetResponse() { HX_RESULT res = HXR_FAIL; HTTPResponseMessage* pMess = NULL; ULONG32 ulLength = 0; ULONG32 ulErrorCode = 0; IHXBuffer* pBuf = NULL; HTTPParser parser; res = _GetReadQueue(pBuf); if( pBuf && SUCCEEDED(res) ) { res = HXR_FAIL; ulLength = pBuf->GetSize(); #if !defined HELIX_FEATURE_SERVER pMess = (HTTPResponseMessage*)parser.parse( (const char*)pBuf->GetBuffer(), ulLength); #else BOOL bMsgTooLarge = FALSE; pMess = (HTTPResponseMessage*)parser.parse( (const char*)pBuf->GetBuffer(), ulLength, bMsgTooLarge); #endif /* !HELIX_FEATURE_SERVER */ HX_ASSERT(pMess); //Verify we have HTTP response message. if( pMess && HTTPMessage::T_UNKNOWN != pMess->tag() ) { if( pMess->errorCode() && strlen(pMess->errorCode())) { ulErrorCode = atoi(pMess->errorCode()); //Verify we have HTTP 1.1. if( pMess->majorVersion()==1 && pMess->minorVersion()==1) { if( ulErrorCode == 401 || ulErrorCode == 407 ) { //Proxy authentication is required. Close up the Socket, //get authentication and try again. m_pTCPSocket->Close(); res = _DoProxyAuthentication(pMess); } //Verify we have 200 OK. else if( 200 == ulErrorCode ) { res = HXR_OK; } } } // We need to put back any used data. Find the trailing // \r\n and put back all data after that. const char* pucData = (const char*)pBuf->GetBuffer(); const char* pszEndOfMess = HXFindString( pucData, "\r\n\r\n"); if( NULL != pszEndOfMess ) { pszEndOfMess += 4; //skip past \r\n\r\n. m_ReadQueue.EnQueue( pszEndOfMess, pBuf->GetSize()-(pszEndOfMess-pucData)); } } } HX_RELEASE(pBuf); return res; }
HX_RESULT CPCMAudioFormat::Init(IHXValues* pHeader) { HX_RESULT retVal = CAudioFormat::Init(pHeader); if (SUCCEEDED(retVal)) { // Get the mime type IHXBuffer* pMimeTypeStr = NULL; retVal = pHeader->GetPropertyCString("MimeType", pMimeTypeStr); if (SUCCEEDED(retVal)) { // Get the mime type string const char* pszMimeType = (const char*) pMimeTypeStr->GetBuffer(); // Reset the mime type member variable m_ucMimeType = kMimeTypeUnknown; // Determine the mime type if (!strcmp(pszMimeType, "audio/L8")) { m_ucMimeType = kMimeTypeAudioL8; m_pAudioFmt->uBitsPerSample = 8; } else if (!strcmp(pszMimeType, "audio/L16")) { m_ucMimeType = kMimeTypeAudioL16; m_pAudioFmt->uBitsPerSample = 16; } else if (!strcmp(pszMimeType, "audio/x-pn-wav")) { m_ucMimeType = kMimeTypeAudioXPNWav; } else if (!strcmp(pszMimeType, "audio/PCMA") || !strcmp(pszMimeType, "audio/pcma")) { m_ucMimeType = kMimeTypeAudioPCMA; m_pAudioFmt->uBitsPerSample = 16; } else if (!strcmp(pszMimeType, "audio/PCMU")) { m_ucMimeType = kMimeTypeAudioPCMU; m_pAudioFmt->uBitsPerSample = 16; } // Get the endianness HXBOOL bBigEndian = TestBigEndian(); if (m_ucMimeType == kMimeTypeAudioXPNWav) { // Get the opaque data IHXBuffer* pBuffer = NULL; retVal = pHeader->GetPropertyBuffer("OpaqueData", pBuffer); if (SUCCEEDED(retVal)) { AudioPCMHEADER audioPCMHEADER; PCMHEADER* pPcmFormatRecord; PCMHEADER tmpPcmFormatRecord; HXBOOL bIsOldHeader = TRUE; if(pBuffer->GetSize() == audioPCMHEADER.static_size()) { bIsOldHeader = FALSE; audioPCMHEADER.unpack(pBuffer->GetBuffer(), pBuffer->GetSize()); } // Check if this is from an old (preview release of G2 / rmasdk beta-9 // or earlier) file format: if(bIsOldHeader || audioPCMHEADER.usVersion != 0 || audioPCMHEADER.usMagicNumberTag != AUDIO_PCMHEADER_MAGIC_NUMBER) { pPcmFormatRecord = (PCMHEADER*) pBuffer->GetBuffer(); // Make sure endianness is ok by swapping bytes if and only if // usChannels is > 0xff; don't just count on this being net- // endian as some preview-release file formats did not send // the data net-endian: if(pPcmFormatRecord->usChannels > 0xff) { SwapWordBytes((UINT16*)&pPcmFormatRecord->usFormatTag, 1); SwapWordBytes((UINT16*)&pPcmFormatRecord->usChannels, 1); SwapDWordBytes((UINT32*)&pPcmFormatRecord->ulSamplesPerSec, 1); SwapWordBytes((UINT16*)&pPcmFormatRecord->usBitsPerSample, 1); SwapWordBytes((UINT16*)&pPcmFormatRecord->usSampleEndianness, 1); } } else { // This is a valid pAudioPCMHEADER and is already in the correct // byte-order as performed by audioPCMHEADER.unpack(): pPcmFormatRecord = &tmpPcmFormatRecord; switch(audioPCMHEADER.usVersion) { case 0: { // PCM format stuff starts 4 bytes into the buffer (which is // right after audioPCMHEADER.usVersion and // audioPCMHEADER.usMagicNumberTag: pPcmFormatRecord->usFormatTag = audioPCMHEADER.usFormatTag; pPcmFormatRecord->usChannels = audioPCMHEADER.usChannels; pPcmFormatRecord->ulSamplesPerSec = audioPCMHEADER.ulSamplesPerSec; pPcmFormatRecord->usBitsPerSample = audioPCMHEADER.usBitsPerSample; pPcmFormatRecord->usSampleEndianness = audioPCMHEADER.usSampleEndianness; break; } default: retVal = HXR_UNEXPECTED; } } if (SUCCEEDED(retVal)) { if (pPcmFormatRecord->usFormatTag == PN_PCM_ZERO_OFFSET && pPcmFormatRecord->usBitsPerSample == 8) { m_bZeroOffsetPCM = TRUE; } else { m_bZeroOffsetPCM = FALSE; } if (pPcmFormatRecord->usBitsPerSample == 16 && pPcmFormatRecord->usSampleEndianness != bBigEndian) { m_bSwapSampleBytes = TRUE; } else { m_bSwapSampleBytes = FALSE; } // Get the "MaxPacketSize" property UINT32 ulMaxPacketSize = 0; pHeader->GetPropertyULONG32("MaxPacketSize", ulMaxPacketSize); // Set the audio stream format parameters // (m_pAudioFmt is a member variable of our parent class) m_pAudioFmt->uChannels = pPcmFormatRecord->usChannels; m_pAudioFmt->uBitsPerSample = pPcmFormatRecord->usBitsPerSample; m_pAudioFmt->ulSamplesPerSec = pPcmFormatRecord->ulSamplesPerSec; m_pAudioFmt->uMaxBlockSize = (UINT16) ulMaxPacketSize; } } HX_RELEASE(pBuffer); } else if(m_ucMimeType == kMimeTypeAudioL8 || m_ucMimeType == kMimeTypeAudioL16 || m_ucMimeType == kMimeTypeAudioPCMA || m_ucMimeType == kMimeTypeAudioPCMU) { // We are either audio/L8 or audio/L16. Since these // formats are ALWAYS net-endian (big-endian), then // we only need to swap if we are NOT running on // a big-endian processor if (m_pAudioFmt->uBitsPerSample == 16 && !bBigEndian) { m_bSwapSampleBytes = TRUE; } else { m_bSwapSampleBytes = FALSE; } // We don't need to override the audio stream format // parameters for audio/L8 or audio/L16 since they // are covered correctly by CAudioFormat::Init(). } else { retVal = HXR_FAIL; } } HX_RELEASE(pMimeTypeStr); } return retVal; }
/************************************************************************ * Method: * IHXPacketHookManager::StartHook * Purpose: * called by the top level client to start recording */ STDMETHODIMP PacketHookManager::StartHook () { HX_RESULT hr = HXR_OK; UINT16 i = 0; UINT16 j = 0; UINT16 k = 0; UINT16 ulSources = 0; UINT16 ulStreams = 0; UINT16 ulStreamIndex = 0; IHXBuffer* pTitle = NULL; IHXBuffer* pAuthor = NULL; IHXBuffer* pCopyright = NULL; IHXValues* pFileHeader = NULL; IHXValues* pStreamHeader = NULL; IUnknown* pUnknown = NULL; IHXPrivateStreamSource *pPrivateSource = NULL; // for IsSaveAllowed, take this out; XXXCP IHXStreamSource* pSource = NULL; IHXInfoLogger* pInfoLogger = NULL; // make sure everything has been initialized if (!m_pPlayer || !m_pPacketHook) { hr = HXR_FAILED; goto cleanup; } // caculate the total number of streams + TAC info. if (!(ulSources = m_pPlayer->GetSourceCount())) { hr = HXR_FAILED; goto cleanup; } m_ulTotalStreams = 0; for (i = 0; i < ulSources; i++) { if (HXR_OK != m_pPlayer->GetSource(i, pUnknown)) { continue; } if (HXR_OK != pUnknown->QueryInterface(IID_IHXStreamSource, (void**)&pSource)) { HX_RELEASE(pUnknown); continue; } if (HXR_OK == pUnknown->QueryInterface(IID_IHXPrivateStreamSource, (void**)&pPrivateSource)) { if (!(pPrivateSource->IsSaveAllowed())) { pPrivateSource->Release(); continue; } pPrivateSource->Release(); } m_ulTotalStreams += pSource->GetStreamCount(); HX_RELEASE(pSource); HX_RELEASE(pUnknown); } if (!m_ulTotalStreams) { hr = HXR_FAILED; goto cleanup; } // prepare the file header CreateBufferCCF(pTitle, m_pPlayer); CreateBufferCCF(pAuthor, m_pPlayer); CreateBufferCCF(pCopyright, m_pPlayer); // XXX HP: find better way to collect TAC info #define szTitle "title" #define szAuthor "author" #define szCopyright "copyright" pTitle->Set((const unsigned char*)szTitle, strlen(szTitle)+1); pAuthor->Set((const unsigned char*)szAuthor, strlen(szAuthor)+1); pCopyright->Set((const unsigned char*)szCopyright, strlen(szCopyright)+1); if (HXR_OK == CreateValuesCCF(pFileHeader, m_pPlayer)) { // set attributes(i.e. num. of streams + TAC) pFileHeader->SetPropertyBuffer("Title", pTitle); pFileHeader->SetPropertyBuffer("Author", pAuthor); pFileHeader->SetPropertyBuffer("Copyright", pCopyright); pFileHeader->SetPropertyULONG32("StreamCount", m_ulTotalStreams); } // signal the top level client of upcoming content m_pPacketHook->OnStart(); // send file header to its top level client hr = m_pPacketHook->OnFileHeader(pFileHeader); if (hr != HXR_OK) { HX_RELEASE(m_pPacketHook); goto cleanup; } // prepare the stream headers m_ulRecordableStreams = 0; ulStreamIndex = 0; for (i = 0; i < ulSources; i++) { if (HXR_OK != m_pPlayer->GetSource(i, pUnknown)) { HX_RELEASE(pUnknown); continue; } if (HXR_OK != pUnknown->QueryInterface(IID_IHXStreamSource, (void**)&pSource)) { HX_RELEASE(pSource); continue; } if (HXR_OK == pUnknown->QueryInterface(IID_IHXPrivateStreamSource, (void**)&pPrivateSource)) { if (!(pPrivateSource->IsSaveAllowed())) { pPrivateSource->Release(); continue; } pPrivateSource->Release(); } if (HXR_OK == pUnknown->QueryInterface(IID_IHXInfoLogger, (void**)&pInfoLogger)) { pInfoLogger->LogInformation("RECSTART", NULL); } HX_RELEASE(pInfoLogger); ulStreams = pSource->GetStreamCount(); for (j = 0; j < ulStreams; j++) { const char* pszPropName = NULL; UINT16 ulRenderers = 0; ULONG32 ulPropValue = 0; HXBOOL bRecordable = FALSE; IHXValues* pHeader = NULL; IHXBuffer* pPropValueSource = NULL; IHXBuffer* pPropValueTarget = NULL; IHXStream* pStream = NULL; // retrieve the stream info pSource->GetStream(j, (IUnknown*&)pStream); pHeader = pStream->GetHeader(); // make a copy of this stream header // XXX HP: this could be wrapped up into one method in CHXHeader CreateValuesCCF(pStreamHeader, m_pPlayer); // copy all the ULONG32 attributes if (HXR_OK == pHeader->GetFirstPropertyULONG32(pszPropName, ulPropValue)) { pStreamHeader->SetPropertyULONG32(pszPropName, ulPropValue); while (HXR_OK == pHeader->GetNextPropertyULONG32(pszPropName, ulPropValue)) { pStreamHeader->SetPropertyULONG32(pszPropName, ulPropValue); } } // copy all the buffer attributes if (HXR_OK == pHeader->GetFirstPropertyBuffer(pszPropName, (IHXBuffer*&)pPropValueSource)) { if (HXR_OK == CreateAndSetBufferCCF(pPropValueTarget, pPropValueSource->GetBuffer(), pPropValueSource->GetSize(), m_pPlayer)) { pStreamHeader->SetPropertyBuffer(pszPropName, pPropValueTarget); HX_RELEASE(pPropValueTarget); } HX_RELEASE(pPropValueSource); while (HXR_OK == pHeader->GetNextPropertyBuffer(pszPropName, (IHXBuffer*&)pPropValueSource)) { if (HXR_OK == CreateAndSetBufferCCF(pPropValueTarget, pPropValueSource->GetBuffer(), pPropValueSource->GetSize(), m_pPlayer)) { pStreamHeader->SetPropertyBuffer(pszPropName, pPropValueTarget); HX_RELEASE(pPropValueTarget); } HX_RELEASE(pPropValueSource); } } // copy all the CString attributes if (HXR_OK == pHeader->GetFirstPropertyCString(pszPropName, (IHXBuffer*&)pPropValueSource)) { if (HXR_OK == CreateAndSetBufferCCF(pPropValueTarget, pPropValueSource->GetBuffer(), pPropValueSource->GetSize(), m_pPlayer)) { pStreamHeader->SetPropertyCString(pszPropName, pPropValueTarget); HX_RELEASE(pPropValueTarget); } HX_RELEASE(pPropValueSource); while (HXR_OK == pHeader->GetNextPropertyCString(pszPropName, (IHXBuffer*&)pPropValueSource)) { if (HXR_OK == CreateAndSetBufferCCF(pPropValueTarget, pPropValueSource->GetBuffer(), pPropValueSource->GetSize(), m_pPlayer)) { pStreamHeader->SetPropertyCString(pszPropName, pPropValueTarget); HX_RELEASE(pPropValueTarget); } HX_RELEASE(pPropValueSource); } } HX_RELEASE(pHeader); // modify some values pStreamHeader->SetPropertyULONG32("StreamNumber", ulStreamIndex); // the stream is recordable as long as there is one renderer supports // IHXPacketHookHelper. Multiple renderers can serve the packets with // the same stream number on it, One solution for this is to choose the // first renderer which supports IHXPacketHookHelper as the only source ulRenderers = pStream->GetRendererCount(); for (k = 0; k < ulRenderers; k++) { IUnknown* pUnknown = NULL; IHXPacketHookHelper* pPacketHookHelper = NULL; pStream->GetRenderer(k, pUnknown); if (HXR_OK == pUnknown->QueryInterface(IID_IHXPacketHookHelper, (void**)&pPacketHookHelper)) { bRecordable = TRUE; pPacketHookHelper->StartHook(ulStreamIndex, 0, new PacketHookHelperResponse(this, ulStreamIndex)); } HX_RELEASE(pPacketHookHelper); HX_RELEASE(pUnknown); } if (bRecordable) { m_ulRecordableStreams++; } pStreamHeader->SetPropertyULONG32("Recordable", (ULONG32)bRecordable); /* * It's possible that StartHook will cause the m_pPacketHook to * be released */ if (!m_pPacketHook) { hr = HXR_UNEXPECTED; goto cleanup; } // send stream header to its top level client hr = m_pPacketHook->OnStreamHeader(pStreamHeader); if (hr != HXR_OK) { HX_RELEASE(m_pPacketHook); goto cleanup; } ulStreamIndex++; HX_RELEASE(pStreamHeader); HX_RELEASE(pStream); } HX_RELEASE(pSource); HX_RELEASE(pUnknown); } cleanup: HX_RELEASE(pTitle); HX_RELEASE(pAuthor); HX_RELEASE(pCopyright); HX_RELEASE(pFileHeader); return hr; }
/* * Copyright (c) 1996, 1997, 1998 Real Networks * * Function Name: MulticastRuleChain::_parseRule * Input Params: const char* ruleNumStr, ULONG32 regId * Return Value: MulticastACRule* * Description: * This method takes a rule number (registry Composite property) * and the id and retrieves all the properties under it. it then * parses the info and puts it into a access rule structure which * gets returned back to the caller. * In case an error occurs while parsing, a NULL pointer is returned. */ MulticastACRule* MulticastRuleChain::_parseRule(const char* ruleNumStr, ULONG32 regId) { IHXValues* props = 0; const char* propName = 0; // here it represents the rule number ULONG32 propID = 0; MulticastACRule* rule = 0; char* ruleVar = 0; INT32 ruleNum = 0; char* strValue = 0; IHXBuffer* fromAddr = 0; IHXBuffer* netmask = 0; IHXBuffer* value = 0; ULONG32 netLongFromAddr = 0L; ULONG32 netLongFromNetmask = 0L; ULONG32 netLongFromLowerLimit = 0L; ULONG32 netLongFromUpperLimit = 0L; BOOL fromAddrIsAny = FALSE; int numProps = 0; ruleVar = (char*)strrchr(ruleNumStr, '.'); if (!ruleVar || !*ruleVar) { // printf("invalid Access rule # -- %s\n", ruleNumStr); goto fin; } ruleVar++; // advance past the '.' ruleNum = atoi(ruleVar); m_registry->GetPropList(regId, props, m_proc); if (!props) { // printf("invalid Access rule # -- %s - !props\n", ruleNumStr); goto fin; } props->GetFirstPropertyULONG32(propName, propID); if (!propName || !propID) { // printf("invalid Access rule # -- %s - !propName||!propID\n", // ruleNumStr); goto fin; } while (propName && propID) { ruleVar = (char*)strrchr(propName, '.'); if (!ruleVar || !*ruleVar) { // printf("invalid Access rule # -- %s - !ruleVar||!*ruleVar\n", ruleNumStr); break; } ruleVar++; // advance past the '.' // printf("%s ", ruleVar); if (!strcasecmp(ruleVar, "Allow")) { if (HXR_OK != m_registry->GetStr(propID, fromAddr, m_proc)) break; // printf("= %s", (const char *)fromAddr->GetBuffer()); if (!strcasecmp("any", (const char *)fromAddr->GetBuffer())) { netLongFromNetmask = 0xffffffff; netLongFromLowerLimit = 0L; netLongFromUpperLimit = netLongClassCULimit; fromAddrIsAny = TRUE; } else { // This is an error, INADDR_NONE was returned from parsing // the address and this caused a fail result to be returned // To handle gracefully, log an error to let know that the // error has occurred and specify all addresses allowed if (HXR_OK != _parseAddr( (const char *)fromAddr->GetBuffer(), fromAddr->GetSize(), netLongFromAddr, netLongFromNetmask)) { char szMsg[128]; snprintf(szMsg, 128, g_zcszInvalidAddressMsg, fromAddr->GetSize(), (const char*) fromAddr->GetBuffer()); // If this is not a valid ip address, then // report an error and default to any m_pErrorHandler->Report(HXLOG_ERR, 0, 0, szMsg, 0); netLongFromNetmask = 0xffffffff; netLongFromLowerLimit = 0L; netLongFromUpperLimit = netLongClassCULimit; fromAddrIsAny = TRUE; } else { // If INADDR_ANY '0.0.0.0' then should be the same as specifying Any // and this is not considered an error if(netLongFromAddr == INADDR_ANY) { netLongFromNetmask = 0xffffffff; netLongFromLowerLimit = 0L; netLongFromUpperLimit = netLongClassCULimit; fromAddrIsAny = TRUE; } else { /* * ToAddr ==> 172.16.2.0 * Netmask => 255.255.255.0 * UpperLimit => 172.16.2.255 */ netLongFromLowerLimit = netLongFromAddr; netLongFromUpperLimit = netLongFromAddr | ~netLongFromNetmask; } } } /**** printf(" -- addr(%lu), lower(%lu), upper(%lu)\n", netLongFromAddr, netLongFromLowerLimit, netLongFromUpperLimit); ****/ numProps++; } else { // printf("erroneous property under rule # %s\n", ruleNumStr); } propName = 0; propID = 0; props->GetNextPropertyULONG32(propName, propID); } // printf("\n"); if (numProps == 1) { rule = new MulticastACRule; rule->nRuleNum = ruleNum; rule->pFromAddr = fromAddr; rule->pFromAddr->AddRef(); if (netmask) { rule->pNetmask = netmask; rule->pNetmask->AddRef(); } rule->ulFromAddr = netLongFromAddr; rule->ulFromNetmask = netLongFromNetmask; rule->ulFromAddrLowerLimit = netLongFromLowerLimit; rule->ulFromAddrUpperLimit = netLongFromUpperLimit; rule->bFromAddrIsAny = fromAddrIsAny; // printf("all of 1 rule parts detected\n"); } fin: return rule; }
STDMETHODIMP HXCloakedV2TCPSocket::ResponseReady( HX_RESULT res, IHXRequest* pRequestResponse) { IHXCommonClassFactory* pCCF = NULL; IHXRegistry* pRegistry = NULL; IHXValues* pHeaders = NULL; const char* pName = NULL; IHXBuffer* pBuf = NULL; CHXString key = ""; IHXBuffer* pTmpBuffer = NULL; if( SUCCEEDED(res) ) { //Extract the authentication info, again, this is a real waste to just //get a username password. See comment in _DoProxyAuthentication. res = m_pContext->QueryInterface(IID_IHXCommonClassFactory, (void**)&pCCF); if( SUCCEEDED(res) ) { res = m_pContext->QueryInterface(IID_IHXRegistry, (void**)&pRegistry); if( SUCCEEDED(res) ) { res = pRequestResponse->GetRequestHeaders(pHeaders); if( SUCCEEDED(res) ) { res = pHeaders->GetFirstPropertyCString(pName, pBuf); while( SUCCEEDED(res) && pBuf ) { if( !strcasecmp(pName, "Proxy-Authorization") ) { CHXString key = "proxy-authentication.http:"; key += m_pszProxyName; key += ":"; res = pRegistry->GetStrByName( "proxy-authentication.http.realm.recent", pTmpBuffer); if( SUCCEEDED(res) ) { key += CHXString((const char*)pTmpBuffer->GetBuffer(), pTmpBuffer->GetSize()); } HX_RELEASE(pTmpBuffer); res = pCCF->CreateInstance(CLSID_IHXBuffer, (void**)&pTmpBuffer); if( SUCCEEDED(res) ) { pTmpBuffer->Set(pBuf->GetBuffer(), pBuf->GetSize()); UINT32 regid = pRegistry->GetId((const char*)key); if (!regid) { pRegistry->AddStr((const char*)key, pTmpBuffer); } else { pRegistry->SetStrByName((const char*)key, pTmpBuffer); } } HX_RELEASE(pTmpBuffer); break; } // get next header name value line HX_RELEASE(pBuf); res = pHeaders->GetNextPropertyCString(pName, pBuf); } HX_RELEASE(pBuf); HX_RELEASE(pHeaders); } } HX_RELEASE(pRegistry); } HX_RELEASE(pCCF); } HX_RELEASE(pRequestResponse); //We need to start over connting again.... m_CloakingState = csDisconnected; if( m_pTCPSocket) { m_pTCPSocket->Close(); HX_RELEASE(m_pTCPSocket); } res = m_pNetworkServices->CreateSocket(&m_pTCPSocket); if(m_pTCPSocket && SUCCEEDED(res) ) { res = m_pTCPSocket->SetResponse(this); if( SUCCEEDED(res) ) { res = m_pTCPSocket->Init(m_family, m_type, m_protocol); m_pTCPSocket->SetOption( HX_SOCKOPT_APP_BUFFER_TYPE, HX_SOCKBUF_DEFAULT); m_pTCPSocket->SelectEvents(HX_SOCK_EVENT_READ| HX_SOCK_EVENT_CONNECT| HX_SOCK_EVENT_CLOSE); res = m_pTCPSocket->ConnectToOne(m_pDestAddr); } } return res; }
HX_RESULT CPCMAudioFormat::DecodeAudioData(HXAudioData& audioData, HXBOOL bFlushCodec, CMediaPacket *pPacket) { HX_RESULT retVal = HXR_FAIL; if (pPacket && m_pCommonClassFactory) { // Create an IHXBuffer IHXBuffer* pBuffer = NULL; m_pCommonClassFactory->CreateInstance(CLSID_IHXBuffer, (void**) &pBuffer); if (pBuffer) { switch(m_ucMimeType) { case kMimeTypeAudioL8: case kMimeTypeAudioL16: case kMimeTypeAudioXPNWav: // Copy the media packet into this buffer retVal = pBuffer->Set(pPacket->m_pData, pPacket->m_ulDataSize); if(SUCCEEDED(retVal)) { // Byteswap the samples if necessary if (m_bSwapSampleBytes) { SwapWordBytes((UINT16*) pBuffer->GetBuffer(), pBuffer->GetSize() / 2); } // Offset 8-bit samples if necessary if (m_bZeroOffsetPCM) { UCHAR* pTmp = (UCHAR*) pBuffer->GetBuffer(); for (UINT32 i = 0; i < pBuffer->GetSize(); i++) { pTmp[i] -= 128; } } } break; case kMimeTypeAudioPCMA: case kMimeTypeAudioPCMU: { UCHAR* pbCurSrc = (UCHAR*)(pPacket->m_pData); UINT16* pwCurDes = NULL; ULONG32 ulSampleNum = pPacket->m_ulDataSize; retVal = pBuffer->SetSize(ulSampleNum<<1); if(SUCCEEDED(retVal)) { pwCurDes = (UINT16*)(pBuffer->GetBuffer()); if(m_ucMimeType == kMimeTypeAudioPCMA) PCM_CONVERTER_ALaw2Linear(pbCurSrc,pwCurDes,ulSampleNum); else PCM_CONVERTER_ULaw2Linear(pbCurSrc,pwCurDes,ulSampleNum); } break; } default: retVal = HXR_FAIL; } if (SUCCEEDED(retVal)) { audioData.pData = pBuffer; audioData.ulAudioTime = pPacket->m_ulTime; audioData.uAudioStreamType = STREAMING_AUDIO; audioData.pData->AddRef(); } } HX_RELEASE(pBuffer); // Delete the packet CMediaPacket::DeletePacket(pPacket); } return retVal; }
HX_RESULT CHXAudioDeviceDS::_Imp_Write(const HXAudioData* pAudioHdr) { HRESULT res ; HXBOOL bFireOnTimeSync = FALSE; IHXBuffer* pBuffer = pAudioHdr->pData; UINT32 ulBufSize = pBuffer->GetSize(); void* pAudioPtr1 = NULL; void* pAudioPtr2 = NULL; DWORD ulAudioBytes1 = 0; DWORD ulAudioBytes2 = 0; res = m_pSecondaryBuffer->Lock(m_ulLastWriteCursor, ulBufSize, &pAudioPtr1, &ulAudioBytes1, &pAudioPtr2, &ulAudioBytes2, 0); if(res != DS_OK) { return HXR_FAIL ; } HX_ASSERT(ulBufSize = ulAudioBytes1+ulAudioBytes2); m_ulLastWriteCursor += ulBufSize ; if (m_ulLastWriteCursor >= m_ulTotalBuffer) m_ulLastWriteCursor -= m_ulTotalBuffer; if(pAudioPtr1) { ::memcpy(pAudioPtr1, (void*) pBuffer->GetBuffer(), ulAudioBytes1); /* Flawfinder: ignore */ if(!m_pAudioPtrStart) { m_pAudioPtrStart = pAudioPtr1; m_ulLoops = 0; m_pSecondaryBuffer->SetCurrentPosition(0); // resume has been called if (E_DEV_RESUMED == m_eState && m_pSecondaryBuffer) { m_pSecondaryBuffer->Play(0, 0, DSBPLAY_LOOPING); if(m_bPaused) { m_bPaused = FALSE; } bFireOnTimeSync = TRUE; } } } if (pAudioPtr2) ::memcpy(pAudioPtr2, ((char*)pBuffer->GetBuffer()) + ulAudioBytes1 , ulAudioBytes2); /* Flawfinder: ignore */ res = m_pSecondaryBuffer->Unlock(pAudioPtr1, ulAudioBytes1, pAudioPtr2, ulAudioBytes2); if (bFireOnTimeSync) { // Call to OnTimeSync can kill audio device. // We need to either self-addref or make sure member variables // are not accessed after OnTimeSync call. OnTimeSync(); } if(res != DS_OK) { return HXR_FAIL ; } return HXR_OK; }