ObjectDataICommand ObjectDataOCommand::_getCommand( LocalNodePtr node )
{
    lunchbox::Bufferb& outBuffer = getBuffer();
    uint8_t* bytes = outBuffer.getData();
    reinterpret_cast< uint64_t* >( bytes )[ 0 ] = outBuffer.getSize();

    BufferPtr inBuffer = node->allocBuffer( outBuffer.getSize( ));
    inBuffer->swap( outBuffer );
    return ObjectDataICommand( node, node, inBuffer, false );
}
Example #2
0
OCommand::~OCommand()
{
    if( _impl->isLocked )
    {
        LBASSERT( _impl->size > 0 );
        const uint64_t size = _impl->size + getBuffer().getSize();
        const size_t minSize = Buffer::getMinSize();
        const Connections& connections = getConnections();
        if( size < minSize ) // Fill send to minimal size
        {
            const size_t delta = minSize - size;
            void* padding = alloca( delta );
            for( ConnectionsCIter i = connections.begin();
                 i != connections.end(); ++i )
            {
                ConnectionPtr connection = *i;
                connection->send( padding, delta, true );
            }
        }
        for( ConnectionsCIter i = connections.begin();
             i != connections.end(); ++i )
        {
            ConnectionPtr connection = *i;
            connection->unlockSend();
        }
        _impl->isLocked = false;
        _impl->size = 0;
        reset();
    }
    else
        disable();

    if( _impl->dispatcher )
    {
        LBASSERT( _impl->localNode );

        // #145 proper local command dispatch?
        LBASSERT( _impl->size == 0 );
        const uint64_t size = getBuffer().getSize();
        BufferPtr buffer = _impl->localNode->allocBuffer( size );
        buffer->swap( getBuffer( ));
        reinterpret_cast< uint64_t* >( buffer->getData( ))[ 0 ] = size;

        ICommand cmd( _impl->localNode, _impl->localNode, buffer, false );
        _impl->dispatcher->dispatchCommand( cmd );
    }

    delete _impl;
}
Example #3
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;
}