Пример #1
0
PcmBuffer32fRef InputImplAudioUnit::getPcmBuffer()
{
	if( ! mIsCapturing ) { return PcmBuffer32fRef(); }
	
	mBufferMutex.lock();
	
	//TODO: don't just assume the data is non-interleaved
	PcmBuffer32fRef outBuffer( new PcmBuffer32f( mCircularBuffers[0]->size(), mCircularBuffers.size(), false ) );
	/*for( int i = 0; i < mBuffers.size(); i++ ) {
		circular_buffer<float>::array_range ar = mBuffers[i]->array_one();
		outBuffer->appendChannelData( ar.first, ar.second, static_cast<ChannelIdentifier>( i ) );
		ar = mBuffers[i]->array_two();
		outBuffer->appendChannelData( ar.first, ar.second, static_cast<ChannelIdentifier>( i ) );
	}*/
	
	for( int i = 0; i < mCircularBuffers.size(); i++ ) {
		CircularBuffer<float>::ArrayRange ar = mCircularBuffers[i]->arrayOne();
		outBuffer->appendChannelData( ar.first, ar.second, static_cast<ChannelIdentifier>( i ) );
		ar = mCircularBuffers[i]->arrayTwo();
		outBuffer->appendChannelData( ar.first, ar.second, static_cast<ChannelIdentifier>( i ) );
	}
	
	mBufferMutex.unlock();
	
	return outBuffer;
}
Пример #2
0
JNIH_EXCEPTION_TRAP_BEGIN() {
    JByteArray jInBuffer(env, inBuffer);
    JByteArray tempBuffer(env, inBufferLength);
    jsize outBufferLength = inBufferLength;


    jboolean result = SCompCompress(
        tempBuffer.getData(),
        reinterpret_cast<int*>(&outBufferLength),
        (jInBuffer.getData() + inBufferOffset),
        inBufferLength,
        compressionMask,
        0,
        compressionLevel
    );

    if (!result) {
        ErrorCodeToException(env, GetLastError());
    } else {
        JByteArray outBuffer(env, outBufferLength);
        memcpy(outBuffer.getData(), tempBuffer.getData(), outBufferLength);

        return outBuffer.getArray();
    }
} JNIH_EXCEPTION_TRAP_END
Пример #3
0
	void SocketProvider::GetExtensionFunctionPtr(const SocketPtr &socket, GUID *guid, LPVOID pfn)
	{
		BufferPtr inBuffer(sizeof(GUID), NoRebindTag());
		BufferPtr outBuffer(sizeof(void *), NoRebindTag());

		RtlMoveMemory(inBuffer->Pointer(), guid, sizeof(GUID));
		socket->IOControl(SIO_GET_EXTENSION_FUNCTION_POINTER, inBuffer, outBuffer);
		RtlMoveMemory(pfn, outBuffer->Pointer(), sizeof(void *));
	}
    ByteArray MemoryStream::ToArray()
      { 
      int32 l = _length - _initialIndex;
      ByteArray outBuffer(l);

      if(_internalBuffer.Get() != nullptr)
        Buffer::BlockCopy((*_internalBuffer), _initialIndex, outBuffer, 0, l);
      return outBuffer;
      }
Пример #5
0
DWORD WINAPI CExtractDlg::ThreadProc(LPVOID lpParameter)
{
	OPTIONS options;
	ExtractParams* exParams = (ExtractParams*)lpParameter;

	COMMANDPARAMS params(cmdExtract, NULL, exParams);
	std::auto_ptr<OUTBUFFER> outBuffer(pExecuteFunc(&params, &options));

	return 0;
}
Пример #6
0
void NAbstractWaveformBuilder::cacheSave()
{
	QByteArray buffer;
	QDataStream outBuffer(&buffer, QIODevice::WriteOnly);
	outBuffer << m_peaksCache << m_dateHash;
	QByteArray compressed = qCompress(buffer);

	QFile cache(m_cacheFile);
	QDataStream outFile(&cache);
	cache.open(QIODevice::WriteOnly);
	outFile << compressed;
	cache.close();
}
Пример #7
0
	void CGameServerState::sendMapInfo(Net::NetID playerNetId) {
		// Una vez recibida la informacion del cliente, le indicamos que cargue el mapa
				
		// Obtenemos el nombre del mapa que el servidor tiene en uso
		std::string mapName = _map->getMapName();
		mapName = mapName.substr( 0, mapName.find("_") );

		// Construimos el mensaje de load_map con el nombre del mapa
		Net::NetMessageType loadMapMsg = Net::LOAD_MAP;
		Net::CBuffer outBuffer( sizeof(loadMapMsg) + sizeof(unsigned int) + (mapName.size() * sizeof(char)) );
		outBuffer.write( &loadMapMsg, sizeof(loadMapMsg) );
		outBuffer.serialize(mapName, false);
				
		// Enviamos el mensaje de carga de mapa al cliente
		_netMgr->sendTo(playerNetId, outBuffer.getbuffer(), outBuffer.getSize());
	}
Пример #8
0
JNIH_EXCEPTION_TRAP_BEGIN() {
    JByteArray jInBuffer(env, inBuffer);
    JByteArray tempBuffer(env, outBufferLength);
    jint decompressedSize = outBufferLength;

    jboolean result = SCompExplode(
        tempBuffer.getData(),
        reinterpret_cast<int*>(&decompressedSize),
        (jInBuffer.getData() + inBufferOffset),
        inBufferLength
    );

    if (!result) {
        ErrorCodeToException(env, GetLastError());
    } else {
        JByteArray outBuffer(env, decompressedSize);
        memcpy(outBuffer.getData(), tempBuffer.getData(), decompressedSize);

        return outBuffer.getArray();
    }
} JNIH_EXCEPTION_TRAP_END
Пример #9
0
    double OCLProvider::FC_R_Star(int nLoc, 
                                  int nTpts,
                                  int* S_star,
                                  int* E_star,
                                  int* R_star,
                                  int* S,
                                  int* I,
                                  int* R,
                                  double* p_se,
                                  double* p_rs,
                                  double* p_ir)
    {
        cl::Context* context = *currentContext;
        cl::Device device = **((*currentDevice) -> device);
        int i;       
        if (R_star_args -> totalWorkUnits == -1)
        {
            // Not populated, need to calculate kernel parameters. 
            
            // Figure out a good way to partition the data 
            // and set up the index space. 
            //
            // Input:
            // 1. Integers (4 bytes)
            //    S_star (TxP)
            //    E_star (TxP)
            //    R_star (TxP)
            //    S      (TxP)
            //    R      (TxP)
            //    I      (TxP)
            // 2. Doubles (8 bytes)
            //    p_rs   (T), might use as (TxP) for simplicity. 
            //    p_ir   (T)
            //    p_se   (TxP)
            R_star_args -> totalWorkUnits = nLoc*nTpts;
            size_t localMemPerCore = device.getInfo<CL_DEVICE_LOCAL_MEM_SIZE>();
            int deviceMaxSize = (device.getInfo<CL_DEVICE_MAX_WORK_GROUP_SIZE>());
            int localSizeMultiple = (R_Star_kernel -> getWorkGroupInfo<CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE>(device));
            int reportedMaxSize = (R_Star_kernel -> getWorkGroupInfo<CL_KERNEL_WORK_GROUP_SIZE>(device));


            int maxLocalSize = localMemPerCore/(4*6 + 3*8);
            maxLocalSize = std::min(std::min(maxLocalSize, deviceMaxSize), reportedMaxSize);
            i=-1;
            int workGroupSize = 0;
            while(workGroupSize <= maxLocalSize && workGroupSize < (R_star_args -> totalWorkUnits))
            {
                i++;
                workGroupSize = pow(2,i)*localSizeMultiple;
            }
            if (workGroupSize >= maxLocalSize)
            {
                workGroupSize = pow(2,i-1)*localSizeMultiple;
            }
            R_star_args -> workGroupSize = workGroupSize;

            int numWorkGroups = ((R_star_args -> totalWorkUnits)/workGroupSize); 
                numWorkGroups += (numWorkGroups*workGroupSize < (R_star_args -> totalWorkUnits));
            int globalSize = numWorkGroups*workGroupSize;
            double* output = new double[numWorkGroups]();

            R_star_args -> globalSize = globalSize;
            R_star_args -> numWorkGroups = numWorkGroups;
            R_star_args -> outCache = output; 
        }


        void* mem_map;
        size_t buffSize = (R_star_args -> totalWorkUnits)*sizeof(int);
        size_t localBuffSize = (R_star_args -> workGroupSize*sizeof(int));

        cl::Buffer SstarBuffer(*context, CL_MEM_WRITE_ONLY | 
            CL_MEM_USE_HOST_PTR, buffSize, S_star);
        cl::Buffer EstarBuffer(*context, CL_MEM_WRITE_ONLY | 
            CL_MEM_USE_HOST_PTR, buffSize, E_star);
        cl::Buffer RstarBuffer(*context, CL_MEM_WRITE_ONLY | 
            CL_MEM_USE_HOST_PTR, buffSize, R_star);
        cl::Buffer SBuffer(*context, CL_MEM_WRITE_ONLY | 
            CL_MEM_USE_HOST_PTR, buffSize, S);
        cl::Buffer IBuffer(*context, CL_MEM_WRITE_ONLY | 
            CL_MEM_USE_HOST_PTR, buffSize, I);
        cl::Buffer RBuffer(*context, CL_MEM_WRITE_ONLY | 
            CL_MEM_USE_HOST_PTR, buffSize, R);
        cl::Buffer p_seBuffer(*context, CL_MEM_WRITE_ONLY | 
            CL_MEM_USE_HOST_PTR, (R_star_args -> totalWorkUnits)*sizeof(double), p_se);
        cl::Buffer p_rsBuffer(*context, CL_MEM_WRITE_ONLY | 
            CL_MEM_USE_HOST_PTR, nTpts*sizeof(double), p_rs);
        cl::Buffer p_irBuffer(*context, CL_MEM_WRITE_ONLY | 
            CL_MEM_USE_HOST_PTR, nTpts*sizeof(double), p_ir);
        cl::Buffer outBuffer(*context, CL_MEM_READ_WRITE | 
            CL_MEM_COPY_HOST_PTR, (R_star_args -> numWorkGroups)*sizeof(double), (R_star_args -> outCache));

        int err;  

        err = R_Star_kernel -> setArg(0, nTpts);
        err |= R_Star_kernel -> setArg(1, nLoc);
        err |= R_Star_kernel -> setArg(2, SstarBuffer);
        err |= R_Star_kernel -> setArg(3, EstarBuffer);
        err |= R_Star_kernel -> setArg(4, RstarBuffer);

        err |= R_Star_kernel -> setArg(5, SBuffer);
        err |= R_Star_kernel -> setArg(6, IBuffer);
        err |= R_Star_kernel -> setArg(7, RBuffer);
        err |= R_Star_kernel -> setArg(8, p_seBuffer);
        err |= R_Star_kernel -> setArg(9, p_rsBuffer);
        err |= R_Star_kernel -> setArg(10, p_irBuffer);
        err |= R_Star_kernel -> setArg(11, outBuffer);
        // Local Declarations
        err |= R_Star_kernel -> setArg(12, localBuffSize, NULL); //S_star
        err |= R_Star_kernel -> setArg(13, localBuffSize, NULL); //E_star
        err |= R_Star_kernel -> setArg(14, localBuffSize, NULL); //R_star
        err |= R_Star_kernel -> setArg(15, localBuffSize, NULL); //S
        err |= R_Star_kernel -> setArg(16, localBuffSize, NULL); //I
        err |= R_Star_kernel -> setArg(17, localBuffSize, NULL); //R
        err |= R_Star_kernel -> setArg(18, (R_star_args -> workGroupSize)*sizeof(double), NULL); //p_se
        err |= R_Star_kernel -> setArg(19, (R_star_args -> workGroupSize)*sizeof(double), NULL); //p_rs
        err |= R_Star_kernel -> setArg(20, (R_star_args -> workGroupSize)*sizeof(double), NULL); //p_ir

        if (err < 0)
        {
            std::cerr << "Couldn't set kernel args.\n";
            throw(err);
        }
        // Optimize this to use subbuffers so that we only write the data 
        // once per sampleR_star event
        try
        {
            (*currentDevice) -> commandQueue -> enqueueNDRangeKernel(*R_Star_kernel,
                                                                     0,
                                                                     R_star_args -> globalSize,
                                                                     R_star_args -> workGroupSize,
                                                                     NULL,
                                                                     NULL
                                                                     );
        }
        catch(cl::Error e)
        {
            std::cerr << "Error enqueueing kernel: " << e.what() << "\n";
            std::cerr << "Error: " << e.err() << "\n";
            throw(-1);
        }

        mem_map = ((*currentDevice) -> commandQueue) -> enqueueMapBuffer(outBuffer, CL_TRUE, CL_MAP_READ, 0, (R_star_args -> numWorkGroups)*sizeof(double));
        memcpy((R_star_args -> outCache), mem_map, (R_star_args -> numWorkGroups)*sizeof(double));
        ((*currentDevice) -> commandQueue) -> enqueueUnmapMemObject(outBuffer, mem_map);

        double outSum = 0.0;
        for (i = 0; i < (R_star_args -> numWorkGroups); i++)
        {
            outSum += (R_star_args -> outCache)[i];
        } 

        if (std::isnan(outSum))
        {
            outSum = -INFINITY;
        }

        return(outSum);
    }
int
vsnprintf(char *buffer, size_t bufferSize, const char *format, va_list args)
{
	uint64 num;
	int base;
	int flags;			/* flags to number() */
	int fieldWidth;	/* width of output field */
	int precision;
		/* min. # of digits for integers; max number of chars for from string */
	int qualifier;		/* 'h', 'l', or 'L' for integer fields */

	Buffer outBuffer(buffer, bufferSize);

	for (; format[0]; format++) {
		if (format[0] != '%') {
			outBuffer.PutCharacter(format[0]);
			continue;
		}

		/* process flags */

		flags = 0;

	repeat:
		format++;
			/* this also skips first '%' */
		switch (format[0]) {
			case '-': flags |= LEFT; goto repeat;
			case '+': flags |= PLUS; goto repeat;
			case ' ': flags |= SPACE; goto repeat;
			case '#': flags |= SPECIAL; goto repeat;
			case '0': flags |= ZEROPAD; goto repeat;

			case '%':
				outBuffer.PutCharacter(format[0]);
				continue;
		}

		/* get field width */

		fieldWidth = -1;
		if (isdigit(*format))
			fieldWidth = skip_atoi(&format);
		else if (format[0] == '*') {
			format++;
			/* it's the next argument */
			fieldWidth = va_arg(args, int);
			if (fieldWidth < 0) {
				fieldWidth = -fieldWidth;
				flags |= LEFT;
			}
		}

		/* get the precision */

		precision = -1;
		if (format[0] == '.') {
			format++;
			if (isdigit(*format))
				precision = skip_atoi(&format);
			else if (format[0] == '*') {
				format++;
				/* it's the next argument */
				precision = va_arg(args, int);
			}
Пример #11
0
AbstractFilter::FilterResult SAAFilter::ProcessMessage( AbstractFilter::buffer_type inputData, AbstractFilter::buffer_type outputData, NameValueCollection& transportHeaders, bool asClient )
{
	ManagedBuffer *inputBuffer = inputData.get();
	string groupId = transportHeaders[ MqFilter::MQGROUPID ];
	if( !asClient )
	{
		if ( inputBuffer )
		{
			DEBUG( "Applying SAA filter..." );

			XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* doc = NULL;
			char* outputXslt = NULL;

			try
			{
				const string& payload = inputBuffer->str();
				doc = XmlUtil::DeserializeFromString( payload );
				XSLTFilter xsltFilter;
				xsltFilter.ProcessMessage( doc, reinterpret_cast< unsigned char** >( &outputXslt), transportHeaders, true );
				size_t outputXsltSize = strlen( outputXslt );
				WorkItem< ManagedBuffer > inBuffer( new ManagedBuffer( reinterpret_cast<unsigned char*> ( outputXslt ), ManagedBuffer::Ref, outputXsltSize) );
				WorkItem< ManagedBuffer > outBuffer( new ManagedBuffer() );
				SwiftFormatFilter swiftFormatFilter;
				swiftFormatFilter.ProcessMessage( inBuffer, outBuffer, transportHeaders, false );
				BatchItem item;
				m_BatchStorage->open( groupId, ios_base::out );
				item.setBinPayload( outBuffer.get() );
				item.setBatchId( groupId );
				item.setSequence( 1 );
				*m_BatchStorage << item;
				item.setSequence( 2 );
				item.setLast();
				item.setPayload( payload );
				*m_BatchStorage << item;
			}
			catch( ... )
			{
				if ( doc != NULL )
					doc->release();
				delete outputXslt;
				TRACE( "Unhandled exception while applying SAA filter");
				throw;
			}
			doc->release();
			delete outputXslt;

			return SAAFilter::Completed;
		}
	}
	else
	{
		DEBUG( "Applying SAA filter ..." );

		WorkItem< ManagedBuffer > outputBuffer( new ManagedBuffer() );
		ManagedBuffer* managedOutputData = outputData.get();
		WorkItem< ManagedBuffer > inputBuffer( new ManagedBuffer() );
		ManagedBuffer* managedInputBuffer = inputBuffer.get();

		m_BatchStorage->open( Base64::decode( groupId ), ios_base::in );
		BatchItem batchItem;
		bool backoutCountExceeds = false;
		try
		{
			//get partner message
			*m_BatchStorage >> batchItem;
			managedInputBuffer->copyFrom( batchItem.getPayload() );

			//check backout count
			// TODO: Change backout count expose mechanism to avoid cast
			BatchManager<BatchMQStorage>* castStorage = dynamic_cast< BatchManager<BatchMQStorage> * >( m_BatchStorage.get() );
			if( castStorage != NULL )
			{
				//backout count exceeded, try Abort
				if( castStorage->storage().getCleaningUp() )
				{
					*m_BatchStorage >> batchItem;
					managedOutputData->copyFrom( batchItem.getPayload() );
					// Dont't  rely on filter user to Abort;
					// The commit is save because SAAFilter-server is always the first stage of message processing
					// ( nothing is partial commited when backout count exceeded)
					castStorage->storage().setCleaningUp( false );
					m_BatchStorage->commit();

					AppException aex( "FileAct message moved to dead letter queue because backout count exceeded" );
					aex.setSeverity( EventSeverity::Fatal );
					throw aex;
				}
			}
			else
				TRACE( "Backout counts should be check here..." )

			//check signature in partner message
			SwiftFormatFilter swiftFormatFilter;
			swiftFormatFilter.ProcessMessage( inputBuffer, outputBuffer, transportHeaders, true );
		}
		catch( runtime_error &ex )