コード例 #1
0
ファイル: sender.cpp プロジェクト: NikitaKarnauhov/lansink
void Sender::Impl::prepare() {
    // FIXME race condition.
    // Stop thread first.
    if (m_status & Sender::usRunning) {
        m_status = Sender::usStopping;
        _stop_worker();
        m_status = Sender::usStopped;
    }

    std::lock_guard<std::mutex> lock(m_mutex);
    const std::string strOldFormat = m_strFormat;
    const size_t cOldRate = m_cBitsPerSample;
    const size_t cOldChannels = m_cChannels;

    _reset(true);
    m_nFramesQueued = 0;
    m_strFormat = alsa::get_format_name(m_pPlug->get_format());
    m_cBitsPerSample = alsa::format_physical_width(m_pPlug->get_format());
    m_cChannels = m_pPlug->get_channel_count();

    if (m_strFormat != strOldFormat || m_cBitsPerSample != cOldRate ||
            m_cChannels != cOldChannels)
        m_cStreamId = s_randomEngine();

    assert(get_bytes_per_frame() > 0);
    assert(m_pPlug->get_buffer_size() > 0);
    std::unique_ptr<char[]> pBuffer(new char[m_pPlug->get_buffer_size()*get_bytes_per_frame()]);
    m_pBuffer = std::move(pBuffer);
    m_bPrepared = true;
    m_status = Sender::usPaused;
    m_bStarted = false;
    m_bDraining = false;
}
コード例 #2
0
ファイル: AudioDecoderThread.cpp プロジェクト: BeepC/libavg
void AudioDecoderThread::insertSilence(float duration)
{
    int numDelaySamples = int(duration*m_AP.m_SampleRate);
    AudioBufferPtr pBuffer(new AudioBuffer(numDelaySamples, m_AP));
    pBuffer->clear();
    pushAudioMsg(pBuffer, m_LastFrameTime);
}
コード例 #3
0
ファイル: buffersource.cpp プロジェクト: aveminus/freq
void BufferSource::
        test()
{
    pBuffer b(new Buffer(Interval(60,70), 40, 7));
    for (int c=0; c<b->number_of_channels (); ++c)
    {
        float *p = b->getChannel (c)->waveform_data ()->getCpuMemory ();
        for (int i=0; i<b->number_of_samples (); ++i)
            p[i] = c + i/(float)b->number_of_samples ();
    }
    BufferSource s(b);
    Operation::ptr o = s.createOperation (0);
    Operation::test (o, &s);

    pBuffer r(new Buffer(Interval(60,70), 40, 7));
    pBuffer d = o->process (r);
    EXCEPTION_ASSERT( *d == *b );

    r = pBuffer(new Buffer(Interval(61,71), 1, 1));
    d = o->process (r);
    EXCEPTION_ASSERT_EQUALS (b->number_of_channels (), d->number_of_channels ());
    EXCEPTION_ASSERT_EQUALS (b->number_of_samples (), d->number_of_samples ());
    EXCEPTION_ASSERT_EQUALS (r->getInterval (), d->getInterval ());
    for (int c=0; c<b->number_of_channels (); ++c)
    {
        float *bp = b->getChannel (c)->waveform_data ()->getCpuMemory ();
        float *dp = d->getChannel (c)->waveform_data ()->getCpuMemory ();

        for (int i=0; i<b->number_of_samples ()-1; ++i)
            EXCEPTION_ASSERT_EQUALS (bp[1+i], dp[i]);
        EXCEPTION_ASSERT_EQUALS (dp[9], 0);
    }
}
コード例 #4
0
//---
IOS_ERROR_CODE IOSFileExtractW( const WCHAR * pszFullFileName, WCHAR * pszFileName, uint uicchBufferLen ) {
#if defined(_UNICODE)
	return ::IOSFileExtract( pszFullFileName, pszFileName, uicchBufferLen );
#else
  if ( pszFullFileName && pszFileName ) {
		
    if ( g_bUnicodePlatform ) {
			CAPointer<WCHAR> fFile = new WCHAR[_MAX_FNAME];
			CAPointer<WCHAR> fExt  = new WCHAR[_MAX_EXT];
			
			// выделить диск и каталог
			_wsplitpath( pszFullFileName, NULL, NULL, fFile, fExt);
			
			if ( uint(wcslen(fFile) + wcslen(fExt)) < uicchBufferLen ) {
				wcscpy( pszFileName, fFile );
				pszFileName = _wcsninc(pszFileName, wcslen(pszFileName) );
				wcscpy( pszFileName, fExt );
			}  
			else
				return IOS_ERR_OUT_OF_MEMORY;  
			
			return IOS_ERR_OK;
		}
		else {
			CPathStrA pConverted(pszFullFileName);
			CPathStrA pBuffer( (int)uicchBufferLen * 2 );
			IOS_ERROR_CODE nError = ::IOSFileExtract( pConverted, pBuffer, uicchBufferLen * 2  );
			wcsncpy( pszFileName, CPathStrW(pBuffer), uicchBufferLen );
			return nError;
		}
  }
  return IOS_ERR_INVALID_FILE_NAME;
#endif	
}
コード例 #5
0
// ---------------------------------------------------------
// RNSmlPrivateAPI::GetDMAuthInfoL( CNSmlDMAuthInfo& aAuthInfo )
// Retrieves DM auhentication info from settings
// ---------------------------------------------------------
//	
EXPORT_C void RNSmlPrivateAPI::GetDMAuthInfoL( CNSmlDMAuthInfo& aAuthInfo )
	{
	TPckgBuf<TInt> buf;
	TIpcArgs args(aAuthInfo.iProfileId, &buf);
	
	User::LeaveIfError( SendReceive( ECmdInitDMAuthInfo, args) );
	
	CBufFlat* buffer = CBufFlat::NewL( KDefaultNSmlBufferGranularity );
	CleanupStack::PushL( buffer );
	buffer->ResizeL( buf() );
	
	TPtr8 pBuffer(0, NULL, 0);
	pBuffer.Set( buffer->Ptr(0) );
	                
	TIpcArgs argsGet( &pBuffer );
	User::LeaveIfError( SendReceive( ECmdGetDMAuthInfo, argsGet) );
	
	RDesReadStream stream;
	stream.Open( pBuffer );
	CleanupClosePushL( stream );
	
	aAuthInfo.InternalizeL( stream );
	
	CleanupStack::PopAndDestroy(2); // stream, buffer	
	}
コード例 #6
0
ファイル: renderoperation.cpp プロジェクト: aveminus/freq
void RenderOperationDesc::
    test()
{
    // The RenderOperationDesc class should keep the filter operation used by a
    // render target and notify the render target about processing events.
    {
        RenderOperationDesc* rod;
        RenderOperationDescMockTarget* target;

        OperationDesc::ptr operation( new Test::TransparentOperationDesc() );
        RenderTarget::ptr rtp(target = new RenderOperationDescMockTarget());

        Signal::OperationDesc::ptr ro(rod = new RenderOperationDesc(operation, rtp));
        Signal::Operation::ptr o = ro.write ()->createOperation(0);

        // Operations are processed through a Processing::Step
        Processing::Step step(ro);
        step.deprecateCache (Interval(4,9));
        o->process (pBuffer());

        EXCEPTION_ASSERT_EQUALS( Interval(4,9), target->I );
        EXCEPTION_ASSERT_EQUALS( 1, target->processed_count );
        EXCEPTION_ASSERT_EQUALS( (void*)0, rod->transform_desc ().get () );
    }
}
コード例 #7
0
ファイル: AudioDecoderThread.cpp プロジェクト: BeepC/libavg
AudioBufferPtr AudioDecoderThread::resampleAudio(char* pDecodedData, int framesDecoded,
        int currentSampleFormat)
{
    if (!m_pResampleContext) {
#ifdef LIBAVRESAMPLE_VERSION
        m_pResampleContext = avresample_alloc_context();
        av_opt_set_int(m_pResampleContext, "in_channel_layout",
                av_get_default_channel_layout(m_pStream->codec->channels), 0);
        av_opt_set_int(m_pResampleContext, "out_channel_layout", AV_CH_LAYOUT_STEREO, 0);
        av_opt_set_int(m_pResampleContext, "in_sample_rate", m_InputSampleRate, 0);
        av_opt_set_int(m_pResampleContext, "out_sample_rate", m_AP.m_SampleRate, 0);
        av_opt_set_int(m_pResampleContext, "in_sample_fmt",
                (AVSampleFormat)currentSampleFormat, 0);
        av_opt_set_int(m_pResampleContext, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0);
        int err = avresample_open(m_pResampleContext);
        AVG_ASSERT(err >= 0);
#else
        m_pResampleContext = av_audio_resample_init(m_AP.m_Channels, 
                m_pStream->codec->channels, m_AP.m_SampleRate, m_InputSampleRate,
                AV_SAMPLE_FMT_S16, (AVSampleFormat)currentSampleFormat, 16, 10, 0, 0.8);
#endif
        AVG_ASSERT(m_pResampleContext);
    }
#ifdef LIBAVRESAMPLE_VERSION
    uint8_t *pResampledData;
    int leftoverSamples = avresample_available(m_pResampleContext);
    int framesAvailable = leftoverSamples +
            av_rescale_rnd(avresample_get_delay(m_pResampleContext) +
                    framesDecoded, m_AP.m_SampleRate, m_InputSampleRate, AV_ROUND_UP);
    av_samples_alloc(&pResampledData, 0, 2, framesAvailable,
            AV_SAMPLE_FMT_S16, 0);
    int framesResampled = avresample_convert(m_pResampleContext, &pResampledData, 0, 
            framesAvailable, (uint8_t**)&pDecodedData, 0, framesDecoded);
    AudioBufferPtr pBuffer(new AudioBuffer(framesResampled, m_AP));
    memcpy(pBuffer->getData(), pResampledData, 
            framesResampled*m_AP.m_Channels*sizeof(short));
    av_freep(&pResampledData);
#else
    short pResampledData[AVCODEC_MAX_AUDIO_FRAME_SIZE/2];
    int framesResampled = audio_resample(m_pResampleContext, pResampledData,
            (short*)pDecodedData, framesDecoded);
    AudioBufferPtr pBuffer(new AudioBuffer(framesResampled, m_AP));
    memcpy(pBuffer->getData(), pResampledData, 
            framesResampled*m_AP.m_Channels*sizeof(short));
#endif
    return pBuffer;
}
コード例 #8
0
BOOL CUploadTransferDC::OnWrite()
{
	ASSUME_LOCK( Transfers.m_pSection );
	ASSERT( m_pClient );

	m_mOutput.tLast = m_pClient->m_mOutput.tLast;

	if ( m_pClient->GetOutputLength() != 0 )
		// There is data in output buffer
		return TRUE;

	if ( m_nState == upsUploading )
	{
		ASSERT( m_nLength != SIZE_UNKNOWN );

		// No file data left to transfer
		if ( m_nPosition >= m_nLength )
		{
			// File completed

			Uploads.SetStable( GetAverageSpeed() );

			m_nState = upsRequest;
			m_tRequest = GetTickCount();

			m_pBaseFile->AddFragment( m_nOffset, m_nLength );

			theApp.Message( MSG_INFO, IDS_UPLOAD_FINISHED, (LPCTSTR)m_sName, (LPCTSTR)m_sAddress );
		}
		else
		{
			// Reading next data chunk of file
			QWORD nToRead = min( m_nLength - m_nPosition, (QWORD)Settings.Uploads.ChunkSize );	// ~1000 KB
			QWORD nRead = 0;
			auto_array< BYTE > pBuffer( new BYTE[ nToRead ] );
			if ( ! ReadFile( m_nFileBase + m_nOffset + m_nPosition, pBuffer.get(), nToRead, &nRead ) || nToRead != nRead )
			{
				// File error
				return FALSE;
			}
			m_pClient->Write( pBuffer.get(), (DWORD)nRead );

			m_nPosition += nRead;
			m_nUploaded += nRead;

			Statistics.Current.Uploads.Volume += ( nRead / 1024 );
		}
	}
	else if ( m_nState >= upsResponse )
	{
		// Current transfer completed
		m_nState	= ( m_nState == upsPreQueue ) ? upsQueued : upsRequest;
		m_tRequest	= GetTickCount();
	}

	return TRUE;
}
コード例 #9
0
ファイル: SSH.cpp プロジェクト: subutai-io/launcher
    std::string SSH::execute(const std::string& command)
    {
        _logger->trace("Executing SSH command: %s", command);
        int rc;
        char buffer[1024];
        int nbytes;
        memset(buffer, 0, 1024);
        if (_ssh == NULL)
        {
            _logger->debug("Initializing SSH");
            _ssh = ssh_new();
        }
        if (_ssh == NULL) {
            throw SubutaiException("Failed to start SSH session");
        }

        if (!_bChanOpen)
        {
            rc = openChannel();
            if (rc != E_NOERR)
            {
                _logger->error("Couldn't open SSH channel: %d", rc);
                return "";
            }
        }

        _logger->trace("Starting SSH command execution");
        rc = ssh_channel_request_exec(_channel, command.c_str());
        if (rc != SSH_OK) {
            closeChannel();
            throw SSHException("Failed to execute SSH command", SSHErrorCode::E_CMD_EXEC_FAILED);
        }

        _logger->trace("Reading from channel");
        nbytes = ssh_channel_read(_channel, buffer, sizeof(buffer), 0);

        std::string pBuffer("");

        while (nbytes > 0)
        {
            pBuffer.append(buffer);
            nbytes = ssh_channel_read(_channel, buffer, sizeof(buffer), 0);
        }

        if (nbytes < 0) 
        {
            closeChannel();
            throw SSHException("Output channel is empty", SSHErrorCode::E_EMPTY_OUTPUT_CHAN);
        }

        closeChannel();
        _logger->debug("SSH Execution output: %s", pBuffer);
        return Poco::trim(pBuffer);
    }
コード例 #10
0
ファイル: pcmsound.cpp プロジェクト: Salimlou/AudioAnecdotes
int main() 
{
   pablioBuffer pBuffer(44100, 2, 1, 10.0);
   pBuffer.print();

   pBuffer.SetBytes(88200);
   pBuffer.print();

   pBuffer.SetFrames(22050);
   pBuffer.print();

   pBuffer.SetSeconds(0.1);
   pBuffer.print();
}
コード例 #11
0
EXPORT_C void CMemSpyEngineOutputSink::OutputLineL( const TDesC& aLine, TBool aIncludePrefix )
{
    TPtr pBuffer( iLocalBuffer->Des() );
    if  ( aIncludePrefix )
    {
        pBuffer.Copy( *iPrefix );
    }
    else
    {
        pBuffer.Zero();
    }

    pBuffer.Append( aLine );
    DoOutputLineL( pBuffer );
}
コード例 #12
0
ファイル: UDPSocket.cpp プロジェクト: 8088/MonaServer
UDPSocket::UDPSocket(const SocketManager& manager, bool allowBroadcast) : _socket(manager,Socket::DATAGRAM), _allowBroadcast(allowBroadcast) {

	onReadable = [this](Exception& ex,UInt32 available) {
		if(available==0)
			return;

		PoolBuffer pBuffer(_socket.manager().poolBuffers,available);
		SocketAddress address;
		int size = _socket.receiveFrom(ex,pBuffer->data(), available, address);
		if (ex || size <= 0)
			return;
		pBuffer->resize(size, true);

		OnPacket::raise(pBuffer,address);
	};
	_socket.OnError::subscribe(*this);
	_socket.OnReadable::subscribe(onReadable);
}
コード例 #13
0
ファイル: wrapperxml.cpp プロジェクト: DatosII/ClienteInmemdb
/**
 * @brief WrapperXml::writeXml, metodo para escribir un xml
 * @param pRuta, directorio en el que se guardara el documento
 * @param pRoot, raiz del documento
 * @param pSon, hijo del documento
 */
void WrapperXml::writeCreateSchemeXml(std::string pMsg, xml_document<> &pDocument){
    xml_node<>* decl = pDocument.allocate_node(node_declaration);
    decl->append_attribute(pDocument.allocate_attribute(VERSION, NUMVERSION));
    decl->append_attribute(pDocument.allocate_attribute(ENCODE, TYPEENCODE));
    pDocument.append_node(decl);

    xml_node<>* root = pDocument.allocate_node(node_element, SCHEME);
    pDocument.append_node(root);

    std::istringstream pBuffer(pMsg);
    std::string subString;
    pBuffer >> subString;
    xml_node<>* childSN = pDocument.allocate_node(node_element, SCHEMENAME);
    childSN->value(strdup(subString.c_str()));
    root->append_node(childSN);
    pBuffer >> subString;
    xml_node<>* childR = pDocument.allocate_node(node_element, RAID);
    childR->value(strdup(subString.c_str()));
    root->append_node(childR);

    while(pBuffer){
        pBuffer >> subString;
        if(subString==HASH)
            break;
        else{
            xml_node<>* childD = pDocument.allocate_node(node_element, DATA);
            xml_node<>* childDT = pDocument.allocate_node(node_element, DATATYPE);
            childDT->value(strdup(subString.c_str()));
            childD->append_node(childDT);
            pBuffer >> subString;
            xml_node<>* childDL = pDocument.allocate_node(node_element, DATANAME );
            childDL->value(strdup(subString.c_str()));
            childD->append_node(childDL);
            pBuffer >> subString;
            xml_node<>* childDN= pDocument.allocate_node(node_element, DATANAME);
            childDN->value(strdup(subString.c_str()));
            childD->append_node(childDN);
            root->append_node(childD);
        }
    }

}
コード例 #14
0
// ---------------------------------------------------------
// RNSmlPrivateAPI::SetDMAuthInfoL( const CNSmlDMAuthInfo& aAuthInfo )
// Sends DM auhentication info to be saved
// ---------------------------------------------------------
//	
EXPORT_C void RNSmlPrivateAPI::SetDMAuthInfoL( const CNSmlDMAuthInfo& aAuthInfo )
	{
	CBufFlat* buffer = CBufFlat::NewL( KDefaultNSmlBufferGranularity );
	CleanupStack::PushL( buffer );
	
	RBufWriteStream stream( *buffer );	
	CleanupClosePushL( stream );
	
	aAuthInfo.ExternalizeL( stream );
	
	TPtr8 pBuffer(0, NULL, 0);
	pBuffer.Set( buffer->Ptr(0) );
	
	CleanupStack::PopAndDestroy(); // stream
	
	TIpcArgs args(aAuthInfo.iProfileId, &pBuffer);
	User::LeaveIfError( SendReceive( ECmdSetDMAuthInfo, args) );
	
	CleanupStack::PopAndDestroy(); // buffer
	}
コード例 #15
0
ファイル: PoolBuffers.cpp プロジェクト: 8088/MonaServer
Buffer* PoolBuffers::beginBuffer(UInt32 size) const {
	Buffer* pBuffer(NULL);
	{
		lock_guard<mutex> lock(_mutex);
		// choose the smaller buffer 
		if (_buffers.empty()) {
			pBuffer = new Buffer(size);
			_lastEmptyTime.update();
			size = 0; // not to resize
		} else {
			auto itBigger(size ? _buffers.lower_bound(size) : _buffers.end());
			if (itBigger == _buffers.end())
				--itBigger;
			pBuffer = itBigger->second;
			_buffers.erase(itBigger);
		}
	}
	if (size)
		pBuffer->resize(size,false);
	return pBuffer;
}
コード例 #16
0
PConstantBuffer Device::createConstantBufferSize(int iNumBytes)
{
    PConstantBuffer pBuffer(new ConstantBuffer(m_pLog, iNumBytes));

    D3D11_BUFFER_DESC bd;
    ZeroMemory( &bd, sizeof(bd) );
    bd.Usage = D3D11_USAGE_DEFAULT;
    bd.ByteWidth = iNumBytes;
    bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
    bd.CPUAccessFlags = 0;

    HRESULT hr = m_pDevice->CreateBuffer( &bd, NULL, &(pBuffer->m_pBuffer) );

    if (SUCCEEDED(hr))
        return pBuffer;
    else
    {
        INFO(WinUtils::stringify(hr));
        return PConstantBuffer(0);
    }
}
コード例 #17
0
PVertexBuffer Device::createVertexBuffer(const QVector<Vertex>& v)
{
    PVertexBuffer pBuffer(new VertexBuffer(m_pLog));

    D3D11_BUFFER_DESC bd;
    ZeroMemory( &bd, sizeof(bd) );
    bd.Usage = D3D11_USAGE_DEFAULT;
    bd.ByteWidth = sizeof( Vertex ) * v.size();
    bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    bd.CPUAccessFlags = 0;
    D3D11_SUBRESOURCE_DATA InitData;
    ZeroMemory( &InitData, sizeof(InitData) );
    InitData.pSysMem = v.data();
    HRESULT hr = m_pDevice->CreateBuffer( &bd, &InitData, &(pBuffer->m_pBuffer) );
    if (SUCCEEDED(hr))
        return pBuffer;
    else
    {
        INFO(WinUtils::stringify(hr));
        return PVertexBuffer(0);
    }
}
コード例 #18
0
/// creates 3d sound from given buffer and size (pcm stream with the parameters: channels(1/2) bitrate(8/16) and frequency (ie 22050)
cSoundSourceOpenAl *cSoundSystemOpenAl::CreateSoundSource3D(const float x, const float y, const float z, const char *buffer, const int size, const int channels, const int bitrate, const int frequency){
	/* TODO */
	cSoundBufferPtr pBuffer(new cSoundBuffer(buffer,size,channels,bitrate,frequency));
	return new cSoundSourceBuffer(pBuffer);
}
コード例 #19
0
ファイル: Plugins.cpp プロジェクト: lemonxiao0/peerproject
BOOL CPlugins::Register(const CString& sPath)
{
	Clear();

	DWORD nSucceeded = 0, nFailed = 0;

	LPCTSTR szParam =
#if defined(_MSC_VER) && (_MSC_VER >= 1500)	// No VS2005
	AfxGetPerUserRegistration() ? _T("/RegServerPerUser") :
#endif
	_T("/RegServer");

	CFileFind finder;
	BOOL bWorking = finder.FindFile( sPath + _T("\\*.*") );	// .DLLs +.EXEs
	while ( bWorking )
	{
		bWorking = finder.FindNextFile();
		const CString strPath = finder.GetFilePath();
		const CString strName = finder.GetFileName();
		const CString strExt  = PathFindExtension( strName );

		if ( strExt.CompareNoCase( _T(".dll") ) == 0 )
		{
			if ( strName == _T("WebHook.dll") && ! Settings.Downloads.WebHookEnable )
				continue;	// Skip WebHook Integration

			if ( HINSTANCE hDll = LoadLibrary( strPath ) )
			{
				HRESULT hr = S_FALSE;

#if defined(_MSC_VER) && (_MSC_VER >= 1500)		// Legacy VS2005 No AfxGetPerUserRegistration
				HRESULT (WINAPI *pfnDllInstall)(BOOL bInstall, LPCWSTR pszCmdLine);
				(FARPROC&)pfnDllInstall = GetProcAddress( hDll, "DllInstall" );
				if ( pfnDllInstall && AfxGetPerUserRegistration() )
				{
					hr = pfnDllInstall( TRUE, L"user" );
				}
				else
#endif
				{
					HRESULT (WINAPI *pfnDllRegisterServer)(void);
					(FARPROC&)pfnDllRegisterServer = GetProcAddress( hDll, "DllRegisterServer" );
					if ( pfnDllRegisterServer )
						hr = pfnDllRegisterServer();
				}

				if ( hr == S_OK )
				{
					nSucceeded++;
					theApp.Message( MSG_NOTICE, _T("Registered plugin: %s"), strName );
				}
				else if ( FAILED( hr ) )
				{
					nFailed++;
					theApp.Message( MSG_ERROR, _T("Failed to register plugin: %s : 0x%08x"), strName, hr );
				}

				FreeLibrary( hDll );
			}
		}
		else if ( strExt.CompareNoCase( _T(".exe") ) == 0 )
		{
			DWORD dwSize = GetFileVersionInfoSize( sPath, &dwSize );
			CAutoVectorPtr< BYTE > pBuffer( new BYTE[ dwSize ] );
			if ( pBuffer && GetFileVersionInfo( sPath, NULL, dwSize, pBuffer ) )
			{
				LPCWSTR pValue = NULL;
				if ( VerQueryValue( pBuffer, _T("\\StringFileInfo\\000004b0\\SpecialBuild"), (void**)&pValue, (UINT*)&dwSize ) &&
					 pValue && dwSize && _wcsicmp( pValue, _T("plugin") ) == 0 )
				{
					SHELLEXECUTEINFO sei =
					{
						sizeof( SHELLEXECUTEINFO ),
						SEE_MASK_NOCLOSEPROCESS,
						NULL,
						NULL,
						strPath,
						szParam,
						sPath,
						SW_HIDE
					};
					DWORD dwError = ERROR_INVALID_FUNCTION;
					if ( ShellExecuteEx( &sei ) )
					{
						WaitForSingleObject( sei.hProcess, INFINITE );
						GetExitCodeProcess( sei.hProcess, &dwError );
						CloseHandle( sei.hProcess );
					}
					else
						dwError = GetLastError();

					if ( dwError == ERROR_SUCCESS )
					{
						nSucceeded++;
						theApp.Message( MSG_NOTICE, _T("Registered plugin: %s"), strName );
					}
					else
					{
						nFailed++;
						theApp.Message( MSG_ERROR, _T("Failed to register plugin: %s : 0x%08x"), strName, dwError );
					}
				}
			}
		}
	}

	return ( nSucceeded != 0 && nFailed == 0 );
}
コード例 #20
0
BOOL CDownloadTransferED2K::OnCompressedPart(CEDPacket* pPacket)
{
	if ( pPacket->GetRemaining() <= Hashes::Ed2kHash::byteCount + 8 )
	{
		theApp.Message( MSG_ERROR, IDS_ED2K_CLIENT_BAD_PACKET, (LPCTSTR)m_sAddress, pPacket->m_nType );
		Close( TRI_FALSE );
		return FALSE;
	}

	Hashes::Ed2kHash oED2K;
	pPacket->Read( oED2K );

	if ( validAndUnequal( oED2K, m_pDownload->m_oED2K ) )
	{
		theApp.Message( MSG_ERROR, IDS_DOWNLOAD_WRONG_HASH, (LPCTSTR)m_sAddress, (LPCTSTR)m_pDownload->GetDisplayName() );
		// Close( TRI_FALSE );
		// return FALSE;
		return TRUE;
	}

	QWORD nBaseOffset = pPacket->ReadLongLE();
	QWORD nBaseLength = pPacket->ReadLongLE();

	z_streamp pStream = (z_streamp)m_pInflatePtr;

	if ( m_pInflatePtr == NULL || m_nInflateOffset != nBaseOffset || m_nInflateLength != nBaseLength )
	{
		if ( pStream != NULL )
		{
			inflateEnd( pStream );
			delete pStream;
		}

		m_nInflateOffset	= nBaseOffset;
		m_nInflateLength	= nBaseLength;
		m_nInflateRead		= 0;
		m_nInflateWritten	= 0;
		m_pInflateBuffer->Clear();

		m_pInflatePtr = new z_stream;
		pStream = (z_streamp)m_pInflatePtr;
		ZeroMemory( pStream, sizeof( z_stream ) );

		if ( inflateInit( pStream ) != Z_OK )
		{
			delete pStream;
			m_pInflatePtr = NULL;

			theApp.Message( MSG_ERROR, IDS_DOWNLOAD_INFLATE_ERROR, (LPCTSTR)m_pDownload->GetDisplayName() );

			Close( TRI_FALSE );
			return FALSE;
		}
	}

	m_pInflateBuffer->Add( pPacket->m_pBuffer + pPacket->m_nPosition, pPacket->GetRemaining() );

	auto_array< BYTE > pBuffer( new BYTE[ BUFFER_SIZE ] );

	if ( m_pInflateBuffer->m_nLength > 0 && m_nInflateRead < m_nInflateLength )
	{
		pStream->next_in  = m_pInflateBuffer->m_pBuffer;
		pStream->avail_in = m_pInflateBuffer->m_nLength;

		do
		{
			pStream->next_out  = pBuffer.get();
			pStream->avail_out = BUFFER_SIZE;

			inflate( pStream, Z_SYNC_FLUSH );

			if ( pStream->avail_out < BUFFER_SIZE )
			{
				QWORD nOffset = m_nInflateOffset + m_nInflateWritten;
				QWORD nLength = BUFFER_SIZE - pStream->avail_out;

				m_pDownload->SubmitData( nOffset, pBuffer.get(), nLength );

				m_oRequested.erase( Fragments::Fragment( nOffset, nOffset + nLength ) );

				m_pSource->AddFragment( nOffset, nLength, ( nOffset % ED2K_PART_SIZE ) ? TRUE : FALSE );

				m_nDownloaded += nLength;
				m_nInflateWritten += nLength;
			}
		}
		while ( pStream->avail_out == 0 );

		if ( pStream->avail_in < m_pInflateBuffer->m_nLength )
		{
			m_nInflateRead += ( m_pInflateBuffer->m_nLength - pStream->avail_in );
			m_pInflateBuffer->Remove( m_pInflateBuffer->m_nLength - pStream->avail_in );
		}
	}

	if ( m_nInflateRead >= m_nInflateLength )
	{
		inflateEnd( pStream );
		delete pStream;
		m_pInflatePtr = NULL;
		m_pInflateBuffer->Clear();
	}

	m_pSource->SetValid();

	return SendFragmentRequests();
}
コード例 #21
0
ファイル: CollectionFile.cpp プロジェクト: GetEnvy/Envy
BOOL CCollectionFile::LoadCollection(LPCTSTR pszFile)
{
	m_nType = EnvyCollection;

	CZIPFile pZIP;
	if ( ! pZIP.Open( pszFile ) ) return FALSE;

	CZIPFile::File* pFile = pZIP.GetFile( L"Collection.xml", TRUE );
	if ( ! pFile ) return FALSE;

	if ( pZIP.GetCount() == 1 )		// xml-only
		m_nType = SimpleCollection;

	augment::auto_ptr< CBuffer > pBuffer ( pFile->Decompress() );
	if ( ! pBuffer.get() ) return FALSE;

	augment::auto_ptr< CXMLElement > pXML ( CXMLElement::FromString( pBuffer->ReadString( pBuffer->m_nLength, CP_UTF8 ), TRUE ) );
	if ( ! pXML.get() ) return FALSE;
	if ( ! pXML->IsNamed( L"collection" ) ) return FALSE;

	CXMLElement* pProperties = pXML->GetElementByName( L"properties" );
	if ( ! pProperties ) return FALSE;

	CXMLElement* pContents = pXML->GetElementByName( L"contents" );
	if ( ! pContents ) return FALSE;

	for ( POSITION pos = pContents->GetElementIterator(); pos; )
	{
		CXMLElement* pElement = pContents->GetNextElement( pos );
		if ( pElement->IsNamed( L"file" ) )
		{
			augment::auto_ptr< File > pNewFile( new File( this ) );
			if ( pNewFile.get() && pNewFile->Parse( pElement ) )
				m_pFiles.AddTail( pNewFile.release() );
		}
	}

	if ( CXMLElement* pMetadata = pProperties->GetElementByName( L"metadata" ) )
	{
		m_pMetadata = CloneMetadata( pMetadata );
		if ( m_pMetadata )
			m_sThisURI = m_pMetadata->GetAttributeValue( CXMLAttribute::schemaName );
	}

	if ( CXMLElement* pTitle = pProperties->GetElementByName( L"title" ) )
		m_sTitle = pTitle->GetValue();

	if ( CXMLElement* pMounting = pProperties->GetElementByName( L"mounting" ) )
	{
		if ( CXMLElement* pParent = pMounting->GetElementByName( L"parent" ) )
			m_sParentURI = pParent->GetAttributeValue( L"uri" );

		if ( CXMLElement* pThis = pMounting->GetElementByName( L"this" ) )
			m_sThisURI = pThis->GetAttributeValue( L"uri" );
	}

	if ( m_sThisURI.IsEmpty() )
	{
		Close();
		return FALSE;
	}

	return TRUE;
}
コード例 #22
0
/// creates 2d soudn from given buffer and size (pcm stream with the parameters: channels(1/2) bitrate(8/16) and frequency (ie 22050)
cSoundSourceOpenAl *cSoundSystemOpenAl::CreateSoundSource(const char *buffer, const int size, const int channels, const int bitrate, const int frequency){
	//printf("###########################################\n");
	cSoundBufferPtr pBuffer(new cSoundBuffer(buffer,size,channels,bitrate,frequency));
	return new cSoundSourceBuffer(pBuffer);
}