Tcp -video client



  • Hi All,

    New to Qt, started working well.

    I am developing a video client. Server is already sending a data using opencv decodeimage so i got receving .jpg image with header info .

    In the client side i did
    @
    _pSocketVideo = new QTcpSocket( this );

       _pSocketVideo->connectToHost(IpList[DeviceNumber],VIDEO_PORT);
    
        connect( _pSocketVideo, SIGNAL(readyRead()), SLOT(VideoDataRead()) );
    

    connect(this,SIGNAL(getFrame(QByteArray)),cameraViewMap[DeviceNumber],SLOT(packFrame(QByteArray)));

    void MainWindow::VideoDataRead()
    {

    VideoData =VideoData+_pSocketVideo->readAll();
    if(firstread)
    {
       byte= MAKEDWORD(VideoData.at(0),VideoData.at(1),VideoData.at(2),VideoData.at(3));
    
        std::cout << byte ;
        firstread=0;
    }
    if(byte == VideoData.size())  // here i get the required data in buffer.
        emit getFrame(VideoData);
    

    }
    @
    Here comes by problem. The received data
    @
    void CameraView::packFrame(QByteArray ReadData)
    {

    unsigned char FrameBuffer[1024*20];
    QByteArray CopyData;
    

    int i;
    int size;
    frameprocess.lock();
    CopyData=ReadData;
    size=CopyData.size();
    iSync = MAKEDWORD(CopyData.at(0),CopyData.at(1),CopyData.at(2),CopyData.at(3));
    iLength = MAKEDWORD(CopyData.at(4),CopyData.at(5),CopyData.at(6),CopyData.at(7));
    iSize = MAKEDWORD(CopyData.at(8),CopyData.at(9),CopyData.at(10),CopyData.at(11));
    iRows = MAKEDWORD(CopyData.at(12),CopyData.at(13),CopyData.at(14),CopyData.at(15));
    iCols = MAKEDWORD(CopyData.at(16),CopyData.at(17),CopyData.at(18),CopyData.at(19));

    // all my datas go correct here matching with the server

      memcpy(&FrameBuffer[0],&CopyData,size);
    

    /*
    here i try to match the server data and client data i am going wrong...
    FILE *fin=fopen("test.bin","wb");
    fwrite(&FrameBuffer[20],sizeof(unsigned char),iSize,fin);
    fclose(fin);
    */

    // ofcourse i dont have option of using QImage as its from opencv .jpg
    cvMat *decode =cvCreateMat(iRows,iSize,CV_8UC1);
    decode->data.ptr=&FrameBuffer[20];
    frame = cvDecodeImage(decode,CV_LOAD_IMAGE_COLOR);
    if(frame)
    std::cout << "not a vaid frame ";
    // here it goes wrong ?? I am not ware why . My bins dont match... pls help
    }
    @

    [Edited to add @ tags -- mlong]



  • Please add @ around your code. It will format the code.



  • Which is the problem exactly? I think is not so hard to do.
    Remember that the jpg image starts with 0xff 0xd9 and ends with 0xff 0xd8.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.