[usbd] Fixed Windows first recording failure.|修复windows下第一次录音失败的问题。

windows下第一次录放音失败的原因是:第一录放音时 windows 会先连续发送开始、结束检测设备,然后才正式开始。线程来不及处理两次开始事件不会累积,最后导致直接结束,
This commit is contained in:
guozhanxin 2019-09-19 21:52:20 +08:00
parent 98b1956937
commit 711ce4a0ea
2 changed files with 26 additions and 6 deletions

View File

@ -83,6 +83,7 @@ struct uac_audio_mic
{
rt_device_t dev;
rt_event_t event;
rt_uint8_t open_count;
rt_uint8_t *buffer;
rt_uint32_t buffer_index;
@ -300,12 +301,16 @@ void mic_entry(void *parameter)
while (1)
{
if (rt_event_recv(mic.event, EVENT_RECORD_START,
if (rt_event_recv(mic.event, EVENT_RECORD_START | EVENT_RECORD_STOP,
RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR,
1000, &e) != RT_EOK)
{
continue;
}
if (mic.open_count == 0)
{
continue;
}
LOG_D("record start");
rt_device_open(mic.dev, RT_DEVICE_OFLAG_RDONLY);
@ -323,7 +328,10 @@ void mic_entry(void *parameter)
RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR,
1000, &e) != RT_EOK)
{
continue;
if (mic.open_count > 0)
continue;
else
break;
}
if (e & EVENT_RECORD_DATA)
{
@ -351,12 +359,14 @@ static rt_err_t _record_start(ufunction_t func)
mic.ep->request.req_type = UIO_REQUEST_WRITE;
rt_usbd_io_request(func->device, mic.ep, &mic.ep->request);
mic.open_count ++;
rt_event_send(mic.event, EVENT_RECORD_START);
return 0;
}
static rt_err_t _record_stop(ufunction_t func)
{
mic.open_count --;
rt_event_send(mic.event, EVENT_RECORD_STOP);
return 0;
}

View File

@ -83,6 +83,7 @@ struct uac_audio_speaker
{
rt_device_t dev;
rt_event_t event;
rt_uint8_t open_count;
rt_uint8_t *buffer;
rt_uint32_t buffer_index;
@ -300,13 +301,17 @@ void speaker_entry(void *parameter)
while (1)
{
if (rt_event_recv(speaker.event, EVENT_AUDIO_START,
if (rt_event_recv(speaker.event, EVENT_AUDIO_START | EVENT_AUDIO_STOP,
RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR,
1000, &e) != RT_EOK)
{
continue;
}
LOG_D("record start");
if (speaker.open_count == 0)
{
continue;
}
LOG_D("play start");
rt_device_open(speaker.dev, RT_DEVICE_OFLAG_WRONLY);
@ -323,7 +328,10 @@ void speaker_entry(void *parameter)
RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR,
1000, &e) != RT_EOK)
{
continue;
if (speaker.open_count > 0)
continue;
else
break;
}
if (e & EVENT_AUDIO_DATA)
{
@ -335,7 +343,7 @@ void speaker_entry(void *parameter)
break;
}
}
LOG_D("record stop");
LOG_D("play stop");
rt_device_close(speaker.dev);
}
@ -351,6 +359,7 @@ static rt_err_t _audio_start(ufunction_t func)
speaker.ep->request.req_type = UIO_REQUEST_READ_FULL;
rt_usbd_io_request(func->device, speaker.ep, &speaker.ep->request);
speaker.open_count ++;
rt_event_send(speaker.event, EVENT_AUDIO_START);
return 0;
@ -358,6 +367,7 @@ static rt_err_t _audio_start(ufunction_t func)
static rt_err_t _audio_stop(ufunction_t func)
{
speaker.open_count --;
rt_event_send(speaker.event, EVENT_AUDIO_STOP);
return 0;
}