Exemplo n.º 1
0
bool TCPServerProcessor::process()
{
    QVariantList frameData;

    PipelineElement::InputPinMap::iterator itr = m_inputPins.begin();
    for( ; itr != m_inputPins.end(); ++itr )
    {
        if( itr->second->isConnected() )
        {
            QVariant v;
            itr->second->getVariant(v);
            frameData.append(v);
        }
    }
    quint32 frameNumber = (quint32)getProcessingSerial();
    emit sendFrame(frameNumber, frameData);
    return true;
}
bool TCPServerProcessor::process()
{
    QVariantList frameData;

    PipelineElement::InputPinMap::iterator itr = m_inputPins.begin();
    for( ; itr != m_inputPins.end(); ++itr )
    {
        plv::IInputPin* pin = itr->second.getPtr();
        if( pin->isConnected() )
        {

            if( pin->getTypeId() == m_cvMatDataTypeId &&
                    m_convertCvMatToQImage )
            {
                QVariant v;
                pin->getVariant(v);
                plv::CvMatData data = v.value<plv::CvMatData>();
                QImage img = plvgui::ImageConverter::cvMatToQImageNoThrow(data);
                QVariant v2;
                v2.setValue(img);
                frameData.append(v2);
            }
            else
            {
                QVariant v;
                pin->getVariant(v);
                frameData.append(v);
            }
        }
    }
    quint32 frameNumber = (quint32)getProcessingSerial();

    QByteArray block;
    QDataStream out(&block, QIODevice::WriteOnly);
    out.setVersion(QDataStream::Qt_4_0);

    // write the header
    out << (quint32)0; // reserved for number of bytes later
    out << (quint32)PROTO_FRAME;    // msg type
    out << (quint32)frameNumber;    // frame number / serial number
    out << (quint32)frameData.size(); // number of arguments

    // write all data to the stream
    foreach( const QVariant& v, frameData )
    {
#if 0
        // we do not want QImage to convert
        // to the default PNG because that
        // is way too slow
        if( v.type() == QVariant::Image )
        {
            out << QVariant::UserType;

            if(out.version() >= QDataStream::Qt_4_2)
                out << qint8(v.isNull());

            QByteArray a("plv::QImageWrapper");
            out << a;

            if( !v.isValid() )
            {
                out << QString();
            }
            else
            {
                QImage img = v.value<QImage>();
                QImageWriter writer(out.device(), "png");
                if(!writer.write(img))
                {
                    QString err = writer.errorString();
                    qWarning() << "Failed to write image to stream because " << err;
                }
            }
        }
        else
        {
            out << v;
        }
#else
        out << v;
#endif
    }

    // calculate size of total data and write it as first 4 bytes
    out.device()->seek(0);
    out << (quint32)(block.size() - sizeof(quint32));

    m_server->sendFrame(frameNumber, block);
    return true;
}