Skip to content

Commit 15a233e

Browse files
committed
Fix stop engine
1 parent 3caa0cb commit 15a233e

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

src/engine.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ ow_engine_init (struct ow_engine *engine, struct ow_device *device,
536536
int err;
537537
ow_err_t ret = OW_OK;
538538

539+
engine->status = OW_ENGINE_STATUS_READY;
539540
engine->device = device;
540541
engine->usb.xfr_audio_in = NULL;
541542
engine->usb.xfr_audio_out = NULL;
@@ -757,7 +758,14 @@ run_audio (void *data)
757758
engine->context->get_time ());
758759
}
759760

760-
ow_engine_set_status (engine, OW_ENGINE_STATUS_BOOT);
761+
pthread_spin_lock (&engine->lock);
762+
if (engine->status <= OW_ENGINE_STATUS_STOP)
763+
{
764+
pthread_spin_unlock (&engine->lock);
765+
return NULL;
766+
}
767+
engine->status = OW_ENGINE_STATUS_BOOT;
768+
pthread_spin_unlock (&engine->lock);
761769

762770
while (1)
763771
{
@@ -769,12 +777,12 @@ run_audio (void *data)
769777

770778
//status == OW_ENGINE_STATUS_BOOT || status == OW_ENGINE_STATUS_CLEAR
771779

772-
if (ow_engine_get_status (engine) == OW_ENGINE_STATUS_CLEAR)
780+
pthread_spin_lock (&engine->lock);
781+
if (engine->status == OW_ENGINE_STATUS_CLEAR)
773782
{
774783
engine->status = OW_ENGINE_STATUS_RUN;
775784
}
776785

777-
pthread_spin_lock (&engine->lock);
778786
if (engine->context->dll)
779787
{
780788
if (engine->status == OW_ENGINE_STATUS_BOOT)
@@ -890,7 +898,6 @@ ow_engine_start (struct ow_engine *engine, struct ow_context *context)
890898
{
891899
return OW_INIT_ERROR_NO_DLL;
892900
}
893-
engine->status = OW_ENGINE_STATUS_READY;
894901
}
895902

896903
debug_print (1, "Starting thread...");
@@ -906,7 +913,8 @@ ow_engine_start (struct ow_engine *engine, struct ow_context *context)
906913
}
907914

908915
//Wait till the thread has reached the USB loop
909-
while (ow_engine_get_status (engine) < OW_ENGINE_STATUS_WAIT)
916+
while (ow_engine_get_status (engine) > OW_ENGINE_STATUS_STOP &&
917+
ow_engine_get_status (engine) < OW_ENGINE_STATUS_WAIT)
910918
{
911919
usleep (PAUSE_TO_BE_WAITING_USECS);
912920
}
@@ -962,7 +970,10 @@ inline void
962970
ow_engine_set_status (struct ow_engine *engine, ow_engine_status_t status)
963971
{
964972
pthread_spin_lock (&engine->lock);
965-
engine->status = status;
973+
if (engine->status >= OW_ENGINE_STATUS_READY)
974+
{
975+
engine->status = status;
976+
}
966977
pthread_spin_unlock (&engine->lock);
967978
}
968979

src/resampler.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -567,20 +567,7 @@ ow_resampler_start (struct ow_resampler *resampler,
567567
void
568568
ow_resampler_wait (struct ow_resampler *resampler)
569569
{
570-
ow_resampler_status_t status;
571-
572570
ow_engine_wait (resampler->engine);
573-
574-
if (ow_engine_get_status (resampler->engine) == OW_ENGINE_STATUS_ERROR)
575-
{
576-
status = OW_RESAMPLER_STATUS_ERROR;
577-
}
578-
else
579-
{
580-
status = OW_RESAMPLER_STATUS_STOP;
581-
}
582-
ow_resampler_set_status (resampler, status);
583-
584571
ow_resampler_report_state (resampler);
585572
}
586573

0 commit comments

Comments
 (0)