通过蓝牙插座c ++实时音频传输

时间:2017-07-20 09:28:15

标签: c++ linux qt sockets bluetooth

我尝试使用蓝牙套接字和rfcomm在2台设备之间进行通信,但我的程序崩溃了(请参阅here了解错误图片)。

我只听了大约1或2秒,然后项目就崩溃了。

这是我的客户端发送音频:

void ClientTalk::startTalk()
{
    qDebug() << "Start talk";

    audio_output->stop();
    connect(audio_input, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChangedInput(QAudio::State)));

    audio_input->start(socket);

    qDebug() << "Talking to server";
}

这是我的客户端听服务器:

void ClientTalk::readSocket()
{
    //QBuffer *buffer;
    QByteArray buff;

    audio_input->stop();

    connect(audio_output, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChangedOutput(QAudio::State)));


    while(socket->canReadLine())
    {
        buff.append(socket->readLine());
        QBuffer audio_buffer(&buff);
        audio_buffer.open(QIODevice::WriteOnly);
        //QDataStream s(buff, QIODevice::ReadWrite);
        audio_output->start(&audio_buffer);
        qDebug() << buff << endl;
    }
    buff.clear()
}

这是我的服务器谈话和倾听:

void ServerTalk::readSocket()
{
    QBluetoothSocket *socket = qobject_cast<QBluetoothSocket *>(sender());
    if (!socket)
        return;

    //QBuffer *buffer;

    audio_input->stop();
    QByteArray buff;

    connect(audio_output, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChangedOutput(QAudio::State)));

    while(socket->canReadLine())
    {
        buff.append(socket->readLine());
        QBuffer audio_buffer(&buff);
        audio_buffer.open(QIODevice::WriteOnly);
        //QDataStream s(buff, QIODevice::ReadWrite);
        audio_output->start(&audio_buffer);
        qDebug() << buff << endl;
    }
    buff.clear();
}

我有一个开始说话和听的按钮:

connect(btn_talk, SIGNAL(pressed()), server, SLOT(startTalk()));
connect(btn_talk, SIGNAL(released()), server, SLOT(readSocket()));

0 个答案:

没有答案