From d7be8e9f967a65992f43d08d1767098715e46c68 Mon Sep 17 00:00:00 2001 From: Tarald Date: Thu, 13 Aug 2020 13:44:23 +0200 Subject: [PATCH] fixed QIODevice with waitforbytes --- handlers/audiohandler.cpp | 15 ++++++++------- handlers/outputstreamhandler.cpp | 6 +++--- handlers/tcpsockethandler.cpp | 3 ++- handlers/videohandler.cpp | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/handlers/audiohandler.cpp b/handlers/audiohandler.cpp index 4ef3235..8669db4 100644 --- a/handlers/audiohandler.cpp +++ b/handlers/audiohandler.cpp @@ -818,7 +818,7 @@ int AudioHandler::encodeAudioFrame(AVFrame *frame,int *data_present) if(error<0){ char* errbuff = (char *)malloc((1000)*sizeof(char)); av_strerror(error,errbuff,1000); - qDebug() << "Failed playbackhandler av_buffersrc_add_frame_flags: code "<lock(); if (*data_present && - (error = av_interleaved_write_frame(mOutputFormatContext, &output_packet)) < 0) + (error = av_interleaved_write_frame(mOutputFormatContext, output_packet)) < 0) { fprintf(stderr, "Could not write audio frame"); mWriteLock->unlock(); @@ -923,9 +922,11 @@ int AudioHandler::encodeAudioFrame(AVFrame *frame,int *data_present) } //qDebug() << error; mWriteLock->unlock(); + av_packet_free(&output_packet); cleanup: - av_packet_unref(&output_packet); + av_packet_unref(output_packet); + av_packet_free(&output_packet); return error; } diff --git a/handlers/outputstreamhandler.cpp b/handlers/outputstreamhandler.cpp index a6acaf2..cfc8e72 100644 --- a/handlers/outputstreamhandler.cpp +++ b/handlers/outputstreamhandler.cpp @@ -144,14 +144,14 @@ int OutputStreamHandler::enableVideo(bool screenShare) } const int error = mVideoHandler->init(); - mTcpSocketHandler->writeHeader(); - /*if(error < 0) + //mTcpSocketHandler->writeHeader(); + if(error < 0) { fprintf(stderr, "Could not init videohandler"); errorHandler->giveErrorDialog("Could not stream video"); qDebug() << "Error: " << error; return (int)error; - }*/ + } mVideoHandler->toggleGrabFrames(mVideoEnabled); qDebug() << "Before grab frames"; diff --git a/handlers/tcpsockethandler.cpp b/handlers/tcpsockethandler.cpp index 5792b29..bbe5816 100644 --- a/handlers/tcpsockethandler.cpp +++ b/handlers/tcpsockethandler.cpp @@ -182,6 +182,7 @@ void TcpSocketHandler::writeHeader() qDebug() << "My Header: " << mHeader.length() << "\n" << mHeader; mSocket->write(mHeader); + qDebug() << "after write"; mHeader.clear(); } @@ -209,7 +210,7 @@ void TcpSocketHandler::sendDisabledVideoSignal() qDebug() << "My Header: " << header.length() << "\n" << header; mSocket->write(header); - header.clear(); + mSocket->waitForBytesWritten(); } void TcpSocketHandler::sendDisabledAudioSignal() diff --git a/handlers/videohandler.cpp b/handlers/videohandler.cpp index dd2cd15..1283b96 100644 --- a/handlers/videohandler.cpp +++ b/handlers/videohandler.cpp @@ -341,7 +341,7 @@ void VideoHandler::grabFrames() { //init(); - //emit callWriteHeader(); + emit callWriteHeader(); mActive = true; AVPacket* pkt = av_packet_alloc();