Skip to content

Commit

Permalink
fixed QIODevice with waitforbytes
Browse files Browse the repository at this point in the history
  • Loading branch information
taraldv committed Aug 13, 2020
1 parent 7b6fd55 commit d7be8e9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
15 changes: 8 additions & 7 deletions handlers/audiohandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<<error<< " meaning: " << errbuff;
qDebug() << "Failed playbackhandler av_buffersrc_add_frame_flags: code " <<error<< " meaning: " << errbuff;
exit(1);
}

Expand All @@ -827,7 +827,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_buffersink_get_frame: code "<<error<< " meaning: " << errbuff;
qDebug() << "Failed playbackhandler av_buffersink_get_frame: code " <<error<< " meaning: " << errbuff;
exit(1);
}

Expand All @@ -853,9 +853,8 @@ int AudioHandler::encodeAudioFrame(AVFrame *frame,int *data_present)


/* Packet used for temporary storage. */
AVPacket output_packet;
AVPacket* output_packet = av_packet_alloc();

initPacket(&output_packet);

/* Set a timestamp based on the sample rate for the container. */
if(first)
Expand Down Expand Up @@ -887,7 +886,7 @@ int AudioHandler::encodeAudioFrame(AVFrame *frame,int *data_present)
}

/* Receive one encoded frame from the encoder. */
error = avcodec_receive_packet(mOutputCodecContext, &output_packet);
error = avcodec_receive_packet(mOutputCodecContext, output_packet);
/* If the encoder asks for more data to be able to provide an
* encoded frame, return indicating that no data is present. */
if (error == AVERROR(EAGAIN))
Expand Down Expand Up @@ -915,17 +914,19 @@ int AudioHandler::encodeAudioFrame(AVFrame *frame,int *data_present)
/* Write one audio frame from the temporary packet to the output file. */
mWriteLock->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();
goto cleanup;
}
//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;
}

Expand Down
6 changes: 3 additions & 3 deletions handlers/outputstreamhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
3 changes: 2 additions & 1 deletion handlers/tcpsockethandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ void TcpSocketHandler::writeHeader()
qDebug() << "My Header: " << mHeader.length() << "\n" << mHeader;

mSocket->write(mHeader);
qDebug() << "after write";
mHeader.clear();
}

Expand Down Expand Up @@ -209,7 +210,7 @@ void TcpSocketHandler::sendDisabledVideoSignal()
qDebug() << "My Header: " << header.length() << "\n" << header;

mSocket->write(header);
header.clear();
mSocket->waitForBytesWritten();
}

void TcpSocketHandler::sendDisabledAudioSignal()
Expand Down
2 changes: 1 addition & 1 deletion handlers/videohandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ void VideoHandler::grabFrames()
{
//init();

//emit callWriteHeader();
emit callWriteHeader();

mActive = true;
AVPacket* pkt = av_packet_alloc();
Expand Down

0 comments on commit d7be8e9

Please sign in to comment.