core/audio: Change audio_pause_after() to return a boolean

This will be useful later to let the gui know if their change had an
effect.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2018-02-08 10:39:48 -05:00
parent e6fb772cad
commit e6ab06cf2b
3 changed files with 22 additions and 11 deletions

View File

@ -305,13 +305,15 @@ struct track *audio_prev()
return __audio_load(playlist_prev(), LOAD_PLAYING); return __audio_load(playlist_prev(), LOAD_PLAYING);
} }
void audio_pause_after(int n) bool audio_pause_after(int n)
{ {
if (n != audio_pause_count) { if (n >= -1 && n != audio_pause_count) {
audio_pause_count = n; audio_pause_count = n;
if (audio_cb) if (audio_cb)
audio_cb->audio_cb_config_pause(audio_pause_count); audio_cb->audio_cb_config_pause(audio_pause_count);
return true;
} }
return false;
} }
#ifdef CONFIG_TESTING #ifdef CONFIG_TESTING

View File

@ -73,8 +73,11 @@ struct track *audio_next();
/* Called to load the previous track. */ /* Called to load the previous track. */
struct track *audio_prev(); struct track *audio_prev();
/* Called to configure automatic pausing. */ /*
void audio_pause_after(int); * Called to configure automatic pausing.
* Returns true if the value has been changed.
*/
bool audio_pause_after(int);
#ifdef CONFIG_TESTING #ifdef CONFIG_TESTING
void test_audio_eos(); void test_audio_eos();

View File

@ -201,20 +201,26 @@ void test_autopause()
struct playlist *history = playlist_lookup(PL_SYSTEM, "History"); struct playlist *history = playlist_lookup(PL_SYSTEM, "History");
int i; int i;
audio_pause_after(3); g_assert_true(audio_pause_after(3));
g_assert_cmpuint(pause_count, ==, 3); g_assert_cmpint(pause_count, ==, 3);
g_assert_false(audio_pause_after(-2));
g_assert_cmpint(pause_count, ==, 3);
pause_count = 0; pause_count = 0;
audio_pause_after(3); g_assert_false(audio_pause_after(3));
g_assert_cmpuint(pause_count, ==, 0); g_assert_cmpint(pause_count, ==, 0);
audio_pause_after(5); g_assert_true(audio_pause_after(-1));
g_assert_cmpuint(pause_count, ==, 5); g_assert_cmpint(pause_count, ==, -1);
g_assert_true(audio_pause_after(5));
g_assert_cmpint(pause_count, ==, 5);
state_count = 0; state_count = 0;
for (i = 4; i > -1; i--) { for (i = 4; i > -1; i--) {
test_audio_eos(); test_audio_eos();
g_assert_cmpuint(pause_count, ==, i); g_assert_cmpint(pause_count, ==, i);
g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_PLAYING); g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_PLAYING);
g_assert(playlist_at(history, 0) == audio_cur_track()); g_assert(playlist_at(history, 0) == audio_cur_track());
} }