drivertest: Fix drivertest_audio crash
1.call AUDIOIOC_RELEASE when finished 2.make sure the driver dequeue all buffers before free the buffers Signed-off-by: renjianguang <renjianguang@xiaomi.com>
This commit is contained in:
parent
4d9f2e3692
commit
d9b8a0ee62
@ -511,6 +511,12 @@ static int audio_test_cleanup(FAR struct audio_state_s *state, int direction)
|
|||||||
|
|
||||||
ioctl(fd, AUDIOIOC_UNREGISTERMQ, (unsigned long)state->mq);
|
ioctl(fd, AUDIOIOC_UNREGISTERMQ, (unsigned long)state->mq);
|
||||||
|
|
||||||
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||||
|
ioctl(fd, AUDIOIOC_RELEASE, (unsigned long)state->session);
|
||||||
|
#else
|
||||||
|
ioctl(fd, AUDIOIOC_RELEASE, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (state->out_fd >= 0)
|
if (state->out_fd >= 0)
|
||||||
{
|
{
|
||||||
close(state->out_fd);
|
close(state->out_fd);
|
||||||
@ -535,6 +541,7 @@ static void audio_test_case(void **audio_state)
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct mq_attr attr;
|
struct mq_attr attr;
|
||||||
|
int unconsumed = 0;
|
||||||
unsigned int prio;
|
unsigned int prio;
|
||||||
bool streaming;
|
bool streaming;
|
||||||
bool running;
|
bool running;
|
||||||
@ -596,6 +603,8 @@ static void audio_test_case(void **audio_state)
|
|||||||
printf("Start %s. \n", direct == AUDIO_TYPE_OUTPUT ?
|
printf("Start %s. \n", direct == AUDIO_TYPE_OUTPUT ?
|
||||||
"Playback" : "Capture");
|
"Playback" : "Capture");
|
||||||
|
|
||||||
|
unconsumed = buf_info.nbuffers;
|
||||||
|
|
||||||
while (running)
|
while (running)
|
||||||
{
|
{
|
||||||
ret = mq_receive(state->mq, (FAR char *)&msg, sizeof(msg), &prio);
|
ret = mq_receive(state->mq, (FAR char *)&msg, sizeof(msg), &prio);
|
||||||
@ -607,6 +616,7 @@ static void audio_test_case(void **audio_state)
|
|||||||
switch (msg.msg_id)
|
switch (msg.msg_id)
|
||||||
{
|
{
|
||||||
case AUDIO_MSG_DEQUEUE:
|
case AUDIO_MSG_DEQUEUE:
|
||||||
|
unconsumed--;
|
||||||
if (streaming)
|
if (streaming)
|
||||||
{
|
{
|
||||||
if (direct == AUDIO_TYPE_INPUT)
|
if (direct == AUDIO_TYPE_INPUT)
|
||||||
@ -632,6 +642,10 @@ static void audio_test_case(void **audio_state)
|
|||||||
state->out_fd = -1;
|
state->out_fd = -1;
|
||||||
streaming = false;
|
streaming = false;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
unconsumed++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -659,12 +673,16 @@ static void audio_test_case(void **audio_state)
|
|||||||
ret = mq_getattr(state->mq, &attr);
|
ret = mq_getattr(state->mq, &attr);
|
||||||
assert_false(ret < 0);
|
assert_false(ret < 0);
|
||||||
|
|
||||||
if (attr.mq_curmsgs == 0)
|
if (attr.mq_curmsgs == 0 && unconsumed <= 0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
mq_receive(state->mq, (FAR char *)&msg, sizeof(msg), &prio);
|
mq_receive(state->mq, (FAR char *)&msg, sizeof(msg), &prio);
|
||||||
|
if (msg.msg_id == AUDIO_MSG_DEQUEUE)
|
||||||
|
{
|
||||||
|
unconsumed--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
while (ret >= 0);
|
while (ret >= 0);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user