ConstBufferPtr
Digest<Hash>::computeDigest(const uint8_t* buffer, size_t size)
{
  Hash hash;
  BufferPtr result = make_shared<Buffer>(hash.DigestSize());
  hash.Update(buffer, size);
  hash.Final(result->get());

  return result;
}
size_t FileInput::read(std::string &string)
{
	if(mFileSize == 0)
		return 0;

	BufferPtr data = std::make_shared<Buffer>(mFileSize + 1);

	//string.reserve(mFileSize);
	int returnval = read((unsigned char *) data->get(), mFileSize);

	if(returnval <= 0)
		return returnval;

	//Null terminate the string
	data->get()[mFileSize] = '\0';

	//Copy into the std string
	string = (char *) data->get();

	return returnval;
}
Beispiel #3
0
size_t Stream::write(BufferPtr buffer)
{
	if(!buffer)
	{
#ifdef AEON_USE_AEON_CONSOLE_LIBRARY
		Console::error("Stream: Tried writing an empty buffer to a stream.");
#endif

		return 0;
	}

	return write(buffer->get(), buffer->size());
}
Beispiel #4
0
BufferPtr Stream::GetNextBuffer(){
    // First get the next decoded buffer
    BufferPtr currentBuffer = this->GetNextDecoderBuffer();

    if(currentBuffer){
        /////////////////////////////////////////////
        // Lets check if the buffer is too small
        bool moreBuffers(true);
        while(currentBuffer->Samples()<this->preferedBufferSampleSize && moreBuffers){
            BufferPtr appendBuffer = this->GetNextDecoderBuffer();
            if(appendBuffer){
                currentBuffer->Append(appendBuffer);
                this->DeleteBuffer(appendBuffer);
            }else{
                moreBuffers = false;
            }
        }
        /////////////////////////////////////////////

        BufferPtr oldBuffer     = this->NewBuffer();

        // Now lets loop through all DSP plugins
        for(Dsps::iterator dsp=this->dsps.begin();dsp!=this->dsps.end();++dsp){
            oldBuffer->CopyFormat(currentBuffer);
            oldBuffer->position = currentBuffer->position;

            if( (*dsp)->ProcessBuffers(currentBuffer.get(),oldBuffer.get()) ){
                // Success in processing DSP, swap the buffers
                currentBuffer.swap(oldBuffer);
            }
        }

        this->DeleteBuffer(oldBuffer);

    }

    return currentBuffer;
}
	Error operator()(CommandBufferImpl* cmd)
	{
		TextureImpl& tex = m_tex.get();
		BufferImpl& buff = m_buff.get();

		// Bind
		GLuint copyFbo = cmd->getManager().getImplementation().
			getRenderingThread().getCopyFbo();
		glBindFramebuffer(GL_FRAMEBUFFER, copyFbo);

		// Attach texture
		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
			tex.getTarget(), tex.getGlName(), 0);

		// Set draw buffers
		GLuint drawBuff = GL_COLOR_ATTACHMENT0;
		glDrawBuffers(1, &drawBuff);

		// Bind buffer
		ANKI_ASSERT(m_buff.getTarget() == GL_PIXEL_PACK_BUFFER);
		buff.bind();

		// Read pixels
		GLuint format = GL_NONE, type = GL_NONE;
		if(tex.getInternalFormat() == GL_RG32UI)
		{
			format = GL_RG_INTEGER;
			type = GL_UNSIGNED_INT;
		}
		else if(tex.getInternalFormat() == GL_RG32F)
		{
			format = GL_RG;
			type = GL_FLOAT;
		}
		else
		{
			ANKI_ASSERT(0 && "Not implemented");
		}

		glReadPixels(0, 0, tex.getWidth(), tex.getHeight(),
			format, type, nullptr);

		// End
		buff.unbind();
		glBindFramebuffer(GL_FRAMEBUFFER, 0);

		return ErrorCode::NONE;
	}
Beispiel #6
0
BufferPtr Stream::GetNextDecoderBuffer(){
    // First get a buffer
    BufferPtr buffer = this->NewBuffer();

    // Get the buffer from the decoder
    if(!this->decoder->GetBuffer(buffer.get())){
        // Nothing to decode left, return a empty buffer
        return BufferPtr();
    }

    // We need to save the decoders samplerate to be able to calculate the current time-position
    if(!this->decoderSampleRate){
        this->decoderSampleRate = buffer->SampleRate();
    }

    // Calculate the current sample position
    this->decoderSamplePosition += buffer->Samples();

    // Save the position (seconds) in the buffer
    buffer->position    = ((double)this->decoderSamplePosition)/((double)this->decoderSampleRate);

    return buffer;

}
Beispiel #7
0
	void UGraphicsDevice::UnmapBuffer(BufferPtr inBuffer)
	{
		mD3dDeviceCtx->Unmap(inBuffer.get(), 0);
	}
Beispiel #8
0
	void UGraphicsDevice::SetPSConstantBuffer(BufferPtr inBuffer, int inSlot)
	{
		auto buffer = inBuffer.get();
		mD3dDeviceCtx->PSSetConstantBuffers(inSlot, 1, &buffer);
	}
Beispiel #9
0
	void UGraphicsDevice::SetIndexBuffer(BufferPtr inBuffer, DXGI_FORMAT inIndexFormat)
	{
		mD3dDeviceCtx->IASetIndexBuffer(inBuffer.get(), inIndexFormat, 0);
	}
Beispiel #10
0
	void UGraphicsDevice::SetVertexBuffer(BufferPtr inBuffer, uint32_t inVertexSize)
	{
		auto buffer = inBuffer.get();
		UINT offset = 0;
		mD3dDeviceCtx->IASetVertexBuffers(0, 1, &buffer, &inVertexSize, &offset);
	}
Beispiel #11
0
void Player::ThreadLoop(){
    // First start the stream
    this->stream    = Stream::Create();
    if(this->stream->OpenStream(this->url)){
        {
            boost::mutex::scoped_lock lock(this->mutex);
            // Set the volume in the output
            this->output->SetVolume(this->volume);
        }

        // If it's not started, lets precache
        bool keepPrecaching(true);
        while(this->State()==Precache && keepPrecaching){
            keepPrecaching  = this->PreBuffer();
            boost::thread::yield();
        }

        // Lets wait until we are not precaching anymore
        {
            boost::mutex::scoped_lock lock(this->mutex);
            while(this->state==Precache){
                this->waitCondition.wait(lock);
            }
        }

        this->PlaybackStarted(this);

        // Player should be started or quit by now
        bool finished(false);
        while(!finished && !this->Exited()){
            if(this->setPosition!=-1){
                // Set a new position
                this->output->ClearBuffers();
                this->stream->SetPosition(this->setPosition);
                {
                    boost::mutex::scoped_lock lock(this->mutex);
                    this->bufferQueue.clear();
//                    this->lockedBuffers.clear();
                    this->setPosition       = -1;
                    this->totalBufferSize   = 0;
                }
            }

            this->output->ReleaseBuffers();

            // Get a buffer, either from the bufferQueue, or from the stream
            BufferPtr buffer;

            if(!this->BufferQueueEmpty()){
                boost::mutex::scoped_lock lock(this->mutex);
                buffer  = this->bufferQueue.front();
            }else{
                buffer  = this->stream->NextBuffer();
                if(buffer){
                    boost::mutex::scoped_lock lock(this->mutex);
                    this->bufferQueue.push_back(buffer);
                    this->totalBufferSize += buffer->Bytes();
                }
		else {
			
		}
            }

            if(buffer){

                {
                    // Add the buffer to locked buffers so the output do not have time to play and 
                    // try to release the buffer before we have to add it.
                    boost::mutex::scoped_lock lock(this->mutex);
                    this->lockedBuffers.push_back(buffer);
                }

                // Try to play the buffer
                if(!this->output->PlayBuffer(buffer.get(),this)){
                    {
                        // We didn't manage to play the buffer, remove it from the locked buffer queue
                        boost::mutex::scoped_lock lock(this->mutex);
                        this->lockedBuffers.pop_back();
                    }

                    if(!this->PreBuffer()){
#ifdef _DEBUG
        	std::cerr << "!this->PreBuffer" << std::endl;
#endif
                        // Wait for buffersize to become smaller
                        boost::mutex::scoped_lock lock(this->mutex);
                        if(this->totalBufferSize>this->maxBufferSize){
                            this->waitCondition.wait(lock);
                        }

                    }
                }else{
                    // Buffer send to output
                    boost::mutex::scoped_lock lock(this->mutex);
                    if(!this->bufferQueue.empty()){
                        this->bufferQueue.pop_front();

                        // Set currentPosition
                        if(this->lockedBuffers.size()==1){
                            this->currentPosition   = buffer->Position();
                        }
                    }

                }
            }else{
                // We have no more to decode
                finished    = true;
            }
        }

        // TODO: call a signal to notify that player is almost done
        if(!this->Exited()){
            this->PlaybackAlmostEnded(this);
        }

        // We need to wait for all the lockedBuffers to be released
        bool buffersEmpty=false;
        do{
            this->output->ReleaseBuffers();
            {
                boost::mutex::scoped_lock lock(this->mutex);
                buffersEmpty    = this->lockedBuffers.empty();
                if(!buffersEmpty && this->state!=Player::Quit){
                    this->waitCondition.wait(lock);
                }
            }
        }while(!buffersEmpty && !this->Exited());

    }else{
        // Unable to open stream
        this->PlaybackError(this);
    }

    {
        boost::mutex::scoped_lock lock(this->mutex);
        this->state    = Player::Quit;
    }

    this->PlaybackEnded(this);

    this->output->ReleaseBuffers();

    this->output.reset();
    this->stream.reset();

}