Streaming video over network



  • Hi, I would like to create a QT application that views a video that is streamed over a network from my rasberry pi. I can stream the video from my rasberry using netcat and then I can view it on my laptop using netcat + mplayer. However, now I would like to create my own Qt application that reads the stream and views it. At this point I have tried the code below, but the readyRead() signal is never emitted and if I try to play the stream anyway I get the error message "stream contains no data". I'm very new to network programming and I would highly appreciate any help to solve the problem.

    code:

    @
    player = new QMediaPlayer(this);
    videoWidget = new VideoWidget(this);
    videoWidget->setMinimumSize(400,100);
    player->setVideoOutput(videoWidget);

    tcpserver = new QTcpServer(this);
    QHostAddress hostadd(IPaddress); // IPaddress is the Laptop's IP address
    tcpserver->listen(hostadd,port); //the port is the same as the port were the data is streamed from the rasberry

    con_socket=new QTcpSocket;
    connect(con_socket,SIGNAL(hostFound()),this,SLOT(hostIsFound()));
    connect(con_socket,SIGNAL(connected()),this,SLOT(connectionEstablished()));
    connect(con_socket,SIGNAL(readyRead()),this,SLOT(playStream()));
    connect(con_socket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(connectionError(QAbstractSocket::SocketError)));
    con_socket->connectToHost(IPaddress,port);

    void Player::playStream(){
    player->setMedia(QMediaContent(), con_socket);
    if (con_socket->canReadLine()){
    player->play();
    }
    }
    @



  • There is something I do not understand of your code. Shouldn't the Qt application be the client side one? If yes, why are you creating a QTcpServer object? I am not an expert, but I think you are making a loop, meaning that the Qt application is both server and client (I don't know if that is possible). You should only do all the streaming with the QTcpSocket object only.

    Did you saw the following doc links?
    "Networking and Connectivity":http://qt-project.org/doc/qt-5/topics-network-connectivity.html
    "Fortune Server Example":http://qt-project.org/doc/qt-5/qtnetwork-fortuneserver-example.html
    "Fortune Client Example":http://qt-project.org/doc/qt-5/qtnetwork-fortuneclient-example.html



  • Hi, yes in the first place I also assumed that I should only run the client part. However, in that case I got on error when I call the connectToHost() function. I also tried to use the QUdpsocket and the bind function. In this case I'm able to bind to port but I'm no more able to stream from the rasberry (if I have the server running rasberry keeps streaming, but I'm not able to catch the stream).

    I have read the examples suggested. However, I'm not sure how to apply those examples in this case, because I'm working with a continuous stream of data.



  • Maybe you need to apply the synchronous (blocking) approach. See the "Blocking Fortune Client Example":http://qt-project.org/doc/qt-5/qtnetwork-blockingfortuneclient-example.html.

    But be carefull that in this case you will need to do "multi-threading":http://qt-project.org/doc/qt-5/thread-basics.html.



  • Hi, I managed to make some process. No I can get the stream to the mediaplayer using the below code. However, the player is not able to play the stream (.h264 format) and I get errors like

    bq. Error: "Could not determine type of stream."
    appsrc: push buffer wrong state
    ** (video_player:5372): CRITICAL **: gst_type_find_helper_for_buffer: assertion `GST_BUFFER_OFFSET (buf) == 0 || GST_BUFFER_OFFSET (buf) == GST_BUFFER_OFFSET_NONE' failed .

    I'm however able to play a recorded sample from a file using the player. Also in this case I got errors like

    bq. Warning: "A lot of buffers are being dropped."

    and some video frames are missing. So I'm not sure if I'm missing some plugins or if I should somehow modify the stream before passing it to the player?

    @player = new QMediaPlayer(this);
    videoWidget = new VideoWidget(this);
    videoWidget->setMinimumSize(400,100);
    player->setVideoOutput(videoWidget);

    tcpserver = new QTcpServer(this);
    QHostAddress hostadd(IPaddress); // IPaddress is the Laptop's IP address
    tcpserver->listen(hostadd,port); //the port is the same as port were the data is streamed from the rasberry
    connect(tcpserver, SIGNAL(newConnection()), this, SLOT(streamFound()));

    void Player::streamFound(){
    con_socket= tcpserver->nextPendingConnection();
    connect(con_socket,SIGNAL(readyRead()),this,SLOT(playStream()));
    }

    void Player::playStream(){
    player->setMedia(QMediaContent(),con_socket);
    if (con_socket->canReadLine()){
    player->play();
    }
    }@


Log in to reply
 

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