summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
Diffstat (limited to 'components')
-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;
}