16,239
社区成员
发帖
与我相关
我的任务
分享
void Widget::slotNewConnection()//当有一个新连接时触发的槽函数
{
qDebug()<<"new connection";
socket = server->nextPendingConnection();
connect(socket,SIGNAL(readyRead()),this,SLOT(slotReadyRead()));
}
void Widget::slotReadyRead()//有数据可取时触发的槽函数
{
qDebug()<<socket->read(buffer,size);
rc = snd_pcm_writei(handle,buffer,frames);
if(rc == -EPIPE)
{
qDebug()<<"underrun occured";
snd_pcm_prepare(handle);
}
else if(rc < 0)
{
qDebug()<<"error from writei"<<rc;
}
else if(rc != (int)frames)
{
qDebug()<<"short write"<<rc;
}
}
//对周期的大小和获取一定时间需要的周期数
frames = 32;
snd_pcm_hw_params_get_period_size(params,&frames,&dir);
size = frames * 4;
buffer = (char *)malloc(size);
snd_pcm_hw_params_get_period_time(params,&val,&dir);
loops = 5000000 / val;
void Widget::on_Button_start_clicked()
{
socket->connectToHost(QHostAddress("172.16.182.31"),PORT);
connect(socket,SIGNAL(connected()),this,SLOT(slotConnected()));
}
void Widget::slotConnected()//当两台机子连接在一起时触发的槽函数
{
qDebug()<<"connected";
init_device_capture();
while(loops > 0)
{
loops--;
qDebug()<<loops;
rc = snd_pcm_readi(handle,buffer,frames);
qDebug()<<rc;
if(rc == -EPIPE)
{
qDebug()<<"over run";
snd_pcm_prepare(handle);
}
else if(rc < 0)
qDebug()<<"error from read:"<<snd_strerror(rc);
else if(rc != (int)frames)
qDebug()<<"short read frames:"<<rc;
socket->write(buffer,size);
socket->waitForBytesWritten(-1);
}
qDebug()<<"end capture";
snd_pcm_drain(handle);
snd_pcm_close(handle);
}