summaryrefslogtreecommitdiff
path: root/components/drivers/usb
diff options
context:
space:
mode:
authorguozhanxin <[email protected]>2019-09-19 21:52:20 +0800
committerguozhanxin <[email protected]>2019-09-19 23:12:24 +0800
commit711ce4a0ea9c66a815a1071b5fed09dbd8e286c6 (patch)
tree076b057422273642c678c99156c8c127951bc238 /components/drivers/usb
parent98b19569375d384896706ffa55842b4f2f0e5922 (diff)
[usbd] Fixed Windows first recording failure.|修复windows下第一次录音失败的问题。
windows下第一次录放音失败的原因是:第一录放音时 windows 会先连续发送开始、结束检测设备,然后才正式开始。线程来不及处理两次开始事件不会累积,最后导致直接结束,
Diffstat (limited to 'components/drivers/usb')
-rw-r--r--components/drivers/usb/usbdevice/class/audio_mic.c14
-rw-r--r--components/drivers/usb/usbdevice/class/audio_speaker.c18
2 files changed, 26 insertions, 6 deletions
diff --git a/components/drivers/usb/usbdevice/class/audio_mic.c b/components/drivers/usb/usbdevice/class/audio_mic.c
index 242cd8a2d9..4ac85711ad 100644
--- a/components/drivers/usb/usbdevice/class/audio_mic.c
+++ b/components/drivers/usb/usbdevice/class/audio_mic.c
@@ -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;
}
diff --git a/components/drivers/usb/usbdevice/class/audio_speaker.c b/components/drivers/usb/usbdevice/class/audio_speaker.c
index a6023db051..84c36d2053 100644
--- a/components/drivers/usb/usbdevice/class/audio_speaker.c
+++ b/components/drivers/usb/usbdevice/class/audio_speaker.c
@@ -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;
}