Skip to content

Commit

Permalink
压缩语音数据
Browse files Browse the repository at this point in the history
  • Loading branch information
muleimulei committed Jul 31, 2021
1 parent d7b108c commit 77c3133
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 29 deletions.
12 changes: 8 additions & 4 deletions AudioInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,20 @@ void AudioInput::onreadyRead()
{
memset(msg, 0, sizeof(MESG));
msg->msg_type = AUDIO_SEND;
msg->data = (uchar*)malloc(totallen);
//ѹËõÊý¾Ý£¬×ªbase64
QByteArray rr(recvbuf, totallen);
QByteArray cc = qCompress(rr).toBase64();
msg->len = cc.size();

msg->data = (uchar*)malloc(msg->len);
if (msg->data == nullptr)
{
qWarning() << "malloc mesg.data fail";
}
else
{
memset(msg->data, 0, totallen);
memcpy_s(msg->data, totallen, recvbuf, totallen);
msg->len = totallen;
memset(msg->data, 0, msg->len);
memcpy_s(msg->data, msg->len, cc.data(), cc.size());
queue_send.push_msg(msg);
}
}
Expand Down
2 changes: 0 additions & 2 deletions AudioOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,10 @@ void AudioOutput::run()
}
MESG* msg = audio_recv.pop_msg();
if (msg == NULL) continue;

{
QMutexLocker lock(&device_lock);
if (outputdevice != nullptr)
{

m_pcmDataBuffer.append((char*)msg->data, msg->len);

if (m_pcmDataBuffer.size() >= FRAME_LEN_500MS)
Expand Down
45 changes: 27 additions & 18 deletions mytcpsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void MyTcpSocket::sendData(MESG* send)
*/
void MyTcpSocket::run()
{
qDebug() << "send data" << QThread::currentThreadId();
//qDebug() << "send data" << QThread::currentThreadId();
m_isCanRun = true; //标记可以运行
/*
*$_MSGType_IPV4_MSGSize_data_# //
Expand Down Expand Up @@ -194,7 +194,7 @@ qint64 MyTcpSocket::readn(char * buf, quint64 maxsize, int n)
void MyTcpSocket::recvFromSocket()
{

qDebug() << "recv data socket" <<QThread::currentThread();
//qDebug() << "recv data socket" <<QThread::currentThread();
/*
*$_msgtype_ip_size_data_#
*/
Expand Down Expand Up @@ -388,28 +388,37 @@ void MyTcpSocket::recvFromSocket()
}
else if (msgtype == AUDIO_RECV)
{
MESG* msg = (MESG*)malloc(sizeof(MESG));
if (msg == NULL)
{
qDebug() << __LINE__ << "malloc failed";
}
else
//解压缩
QByteArray cc((char*)recvbuf + MSG_HEADER, data_size);
QByteArray rc = QByteArray::fromBase64(cc);
QByteArray rdc = qUncompress(rc);

if (rdc.size() > 0)
{
memset(msg, 0, sizeof(MESG));
msg->msg_type = AUDIO_RECV;
msg->ip = ip;
msg->data = (uchar*)malloc(data_size);
if (msg->data == nullptr)
MESG* msg = (MESG*)malloc(sizeof(MESG));
if (msg == NULL)
{
qDebug() << __LINE__ << "malloc msg.data failed";
qDebug() << __LINE__ << "malloc failed";
}
else
{
memset(msg->data, 0, data_size);
memcpy_s(msg->data, data_size, recvbuf + MSG_HEADER, data_size);
msg->len = data_size;
memset(msg, 0, sizeof(MESG));
msg->msg_type = AUDIO_RECV;
msg->ip = ip;
audio_recv.push_msg(msg);

msg->data = (uchar*)malloc(rdc.size());
if (msg->data == nullptr)
{
qDebug() << __LINE__ << "malloc msg.data failed";
}
else
{
memset(msg->data, 0, rdc.size());
memcpy_s(msg->data, rdc.size(), rdc.data(), rdc.size());
msg->len = rdc.size();
msg->ip = ip;
audio_recv.push_msg(msg);
}
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ void Widget::cameraImageCapture(QVideoFrame frame)

QImage img = videoImg.transformed(matrix, Qt::FastTransformation);

// if(partner.size() > 1)
// {
emit pushImg(img);
// }
if(partner.size() > 1)
{
emit pushImg(img);
}

if(_mytcpSocket->getlocalip() == mainip)
{
Expand Down Expand Up @@ -515,7 +515,7 @@ void Widget::datasolve(MESG *msg)

Partner* Widget::addPartner(quint32 ip)
{
//if (partner.contains(ip)) return NULL;
if (partner.contains(ip)) return NULL;
Partner *p = new Partner(ui->scrollAreaWidgetContents ,ip);
if (p == NULL)
{
Expand Down

0 comments on commit 77c3133

Please sign in to comment.