Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
Fix Minor Bugs in Linux
Browse files Browse the repository at this point in the history
Fix a small issue that pointer to audio output device in Linux can't de deleted, or it will cause crashes.
  • Loading branch information
zty199 committed Mar 12, 2021
1 parent c60e54c commit 8ad1fe3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
17 changes: 10 additions & 7 deletions src/UDPMulticast/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void MainWindow::on_videoFrameChanged(QVideoFrame frame)
#elif defined Q_OS_LINUX
image = image.mirrored(false, false); // 左右/上下镜像
#endif
image.scaled(image.size().boundedTo(QSize(1280, 720)), Qt::KeepAspectRatio, Qt::SmoothTransformation); // 分辨率高于 1080p 则压缩
image.scaled(image.size().boundedTo(QSize(1280, 720)), Qt::KeepAspectRatio, Qt::SmoothTransformation); // 分辨率高于 720p 则压缩

// 本地窗口预览
ui->videoViewer->setPixmap(QPixmap::fromImage(image).scaled(ui->videoViewer->size(), Qt::KeepAspectRatio, Qt::FastTransformation));
Expand Down Expand Up @@ -295,9 +295,10 @@ void MainWindow::on_videoFrameChanged(QVideoFrame frame)
len = UDP_MAX_SIZE;
}

if((res = video_socket->writeDatagram(byteArray.data() + sentBytes, len, groupAddress, video_port)) != len)
res = video_socket->writeDatagram(byteArray.data() + sentBytes, len, groupAddress, video_port);
if(res < 0)
{
qDebug() << "res = " << res << " sentBytes = " << len;
qDebug() << "video_socket: Write Datagram Failed!";
break;
}
video_socket->waitForBytesWritten();
Expand Down Expand Up @@ -373,9 +374,10 @@ void MainWindow::on_timeOut()
len = UDP_MAX_SIZE;
}

if((res = video_socket->writeDatagram(byteArray.data() + sentBytes, len, groupAddress, video_port)) != len)
res = video_socket->writeDatagram(byteArray.data() + sentBytes, len, groupAddress, video_port);
if(res < 0)
{
qDebug() << "res = " << res << " sentBytes = " << len;
qDebug() << "video_socket: Write Datagram Failed!";
break;
}
video_socket->waitForBytesWritten();
Expand Down Expand Up @@ -459,9 +461,10 @@ void MainWindow::on_deviceReadyRead()
len = UDP_MAX_SIZE;
}

if((res = audio_socket->writeDatagram(reinterpret_cast<const char *>(&vp) + sentBytes, len, groupAddress, audio_port)) != len)
res = audio_socket->writeDatagram(reinterpret_cast<const char *>(&vp) + sentBytes, len, groupAddress, audio_port);
if(res < 0)
{
qDebug() << "res = " << res << " sentBytes = " << len;
qDebug() << "audio_socket: Write Datagram Failed!";
break;
}
audio_socket->waitForBytesWritten();
Expand Down
16 changes: 15 additions & 1 deletion src/UDPReceiver/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ void MainWindow::on_videoReadyRead()
QByteArray byteArray;
byteArray.resize(static_cast<int>(video_socket->pendingDatagramSize()));
res = video_socket->readDatagram(byteArray.data(), video_socket->pendingDatagramSize());
if(res < 0)
{
qDebug() << "video_socket: Read Datagram Failed!";
return;
}

// 接收到停止信号则清空画面
if(QString(byteArray) == "Stop")
Expand Down Expand Up @@ -171,7 +176,11 @@ void MainWindow::on_cb_device_currentIndexChanged(int index)
format = info.nearestFormat(this->format);
}

delete m_audioOutput;
/*
* 删除旧音频输出设备并新建设备,
* 在 Linux 上会引起程序异常结束,原因未知
*/
// delete m_audioOutput;
m_audioOutput = new QAudioOutput(info, format, this);

if(flag_audio)
Expand Down Expand Up @@ -199,6 +208,11 @@ void MainWindow::on_audioReadyRead()
QByteArray byteArray;
byteArray.resize(static_cast<int>(audio_socket->pendingDatagramSize()));
res = audio_socket->readDatagram(byteArray.data(), audio_socket->pendingDatagramSize());
if(res < 0)
{
qDebug() << "audio_socket: Read Datagram Failed!";
return;
}

// 接收到开始信号则清空上个数据包并准备写入新的数据包
if(QString(byteArray) == "Begin")
Expand Down

0 comments on commit 8ad1fe3

Please sign in to comment.