pcm_record: Track initialization state
It should not access audio hardware and change settings unless it has been initialized first and given control of it. Change-Id: I5004602d7caa604ded751f6838b792d1ff24b3fb
This commit is contained in:
parent
5a1e697e2a
commit
df6e1bcce5
1 changed files with 19 additions and 1 deletions
|
@ -42,6 +42,7 @@
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
|
||||||
/** General recording state **/
|
/** General recording state **/
|
||||||
|
static bool is_initialized = false; /* Subsystem ready? */
|
||||||
static bool is_recording; /* We are recording */
|
static bool is_recording; /* We are recording */
|
||||||
static bool is_paused; /* We have paused */
|
static bool is_paused; /* We have paused */
|
||||||
static unsigned long errors; /* An error has occured */
|
static unsigned long errors; /* An error has occured */
|
||||||
|
@ -1133,6 +1134,8 @@ static void pcmrec_new_stream(const char *filename, /* next file name */
|
||||||
/* PCMREC_INIT */
|
/* PCMREC_INIT */
|
||||||
static void pcmrec_init(void)
|
static void pcmrec_init(void)
|
||||||
{
|
{
|
||||||
|
is_initialized = true;
|
||||||
|
|
||||||
unsigned char *buffer;
|
unsigned char *buffer;
|
||||||
send_event(RECORDING_EVENT_START, NULL);
|
send_event(RECORDING_EVENT_START, NULL);
|
||||||
|
|
||||||
|
@ -1185,6 +1188,7 @@ static void pcmrec_init(void)
|
||||||
/* PCMREC_CLOSE */
|
/* PCMREC_CLOSE */
|
||||||
static void pcmrec_close(void)
|
static void pcmrec_close(void)
|
||||||
{
|
{
|
||||||
|
is_initialized = false;
|
||||||
dma_lock = true;
|
dma_lock = true;
|
||||||
pre_record_ticks = 0; /* Can't be prerecording any more */
|
pre_record_ticks = 0; /* Can't be prerecording any more */
|
||||||
warnings = 0;
|
warnings = 0;
|
||||||
|
@ -1490,6 +1494,17 @@ static void pcmrec_thread(void)
|
||||||
{
|
{
|
||||||
/* Not doing anything - sit and wait for commands */
|
/* Not doing anything - sit and wait for commands */
|
||||||
queue_wait(&pcmrec_queue, &ev);
|
queue_wait(&pcmrec_queue, &ev);
|
||||||
|
|
||||||
|
/* Some messages must be handled even if not initialized */
|
||||||
|
switch (ev.id)
|
||||||
|
{
|
||||||
|
case PCMREC_INIT:
|
||||||
|
case SYS_USB_CONNECTED:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (!is_initialized)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (ev.id)
|
switch (ev.id)
|
||||||
|
@ -1533,7 +1548,10 @@ static void pcmrec_thread(void)
|
||||||
case SYS_USB_CONNECTED:
|
case SYS_USB_CONNECTED:
|
||||||
if (is_recording)
|
if (is_recording)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
if (is_initialized)
|
||||||
pcmrec_close();
|
pcmrec_close();
|
||||||
|
|
||||||
usb_acknowledge(SYS_USB_CONNECTED_ACK);
|
usb_acknowledge(SYS_USB_CONNECTED_ACK);
|
||||||
usb_wait_for_disconnect(&pcmrec_queue);
|
usb_wait_for_disconnect(&pcmrec_queue);
|
||||||
flush_interrupts = 0;
|
flush_interrupts = 0;
|
||||||
|
|
Loading…
Reference in a new issue