我正在开发免提模块,在完成服务级别连接后,我正在设置与手机音频网关的sco连接并接收音频数据,如下所示......
void audio_connection_setup(char *bluetooth_addr)
{
struct sockaddr_sco addr;
pthread_t tid;
int scoSock = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_SCO);
memset(&addr, 0, sizeof(addr));
addr.sco_family = AF_BLUETOOTH;
addr.sco_bdaddr = *BDADDR_ANY;
if (bind(scoSock, (struct sockaddr *) &addr, sizeof(addr)) < 0)
{
printf( "Can't bind socket: %s (%d)",strerror(errno), errno);
}
hci_read_voice_setting(scoSock, &voice, 5000);
hci_write_voice_setting(scoSock, BT_VOICE_CVSD_16BIT, 5000);
str2ba(bluetooth_addr, &addr.sco_bdaddr);
if (connect(scoSock, (struct sockaddr *) &addr, sizeof(addr)) < 0)
{
printf( "\nCan't connect: %s (%d)", strerror(errno), errno);
}
pthread_create(&tid, NULL, &read_data, &scoSock);
}
这是read_data线程
gBuff[16284];
void* read_data(int *scoSock)
{
int fd = *scoSock;
int len = -1;
char buff[48];
int numBytesRead;
while (1)
{
numBytesRead = 0;
while(numBytesRead < 16284)
{
memset(buff, 0x0, 48);
len = recv(fd, buff, 48, MSG_DONTWAIT);
usleep(10);
memcpy(gBuff + numBytesRead, buff + 2, len - 2);
numBytesRead = numBytesRead + len - 2;
}
printf("Number of bytes received = %d errno = %d\n", numBytesRead, errno);
memset(gBuff, 0x0, numBytesRead);
}
}
如果我在linux PC上运行它,这段代码工作正常,但是当我在arm board上运行时,recv系统调用会在连续循环中返回errno EAGAIN并且永远不会出现。在PC上,recv系统调用正确返回字节数。可能导致此问题的原因是什么?
答案 0 :(得分:0)
我认为原因应该是当您的代码在PC上运行时,您可以从HCI链接获取音频数据,即通过HCI获取HF sco,然后将其传输到PC驱动程序。但是当你切换到主板时,我想知道主板的硬件蓝牙接口是否可以说UART,是否具有高吞吐量来传输sco数据,最重要的是,你需要检查sco数据是否被路由到PCM接口即不发送给HCI。