From b2ac9d7f1d33aa795f6c3827b120f7591678ab3b Mon Sep 17 00:00:00 2001 From: Diogo Ferreira Date: Thu, 4 Dec 2014 11:26:43 +0000 Subject: bootanimation: Only try to shutdown the mediaplayer if it was prepared The bootanimation tries to shutdown the mediaplayer gracefully by waiting on an asynchronous shutdown event for 5 seconds. If, however, there is no boot sound, that asynchronous shutdown event will never happen and the animation will be stopped for 5 seconds before shutting down. Visibly, this fixes the issue where the bootanimation would simply stop near the end for exactly 5 seconds. Change-Id: I77f5631368c7d9b9fef7941a6278af9c36032044 --- cmds/bootanimation/BootAnimation.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'cmds') diff --git a/cmds/bootanimation/BootAnimation.cpp b/cmds/bootanimation/BootAnimation.cpp index 9d9b20b..e92e826 100644 --- a/cmds/bootanimation/BootAnimation.cpp +++ b/cmds/bootanimation/BootAnimation.cpp @@ -827,20 +827,22 @@ bool BootAnimation::movie() } - ALOGD("waiting for media player to complete."); - struct timespec timeout; - clock_gettime(CLOCK_REALTIME, &timeout); - timeout.tv_sec += 5; //timeout after 5s. - - pthread_mutex_lock(&mp_lock); - while (!isMPlayerCompleted) { - int err = pthread_cond_timedwait(&mp_cond, &mp_lock, &timeout); - if (err == ETIMEDOUT) { - break; + if (isMPlayerPrepared) { + ALOGD("waiting for media player to complete."); + struct timespec timeout; + clock_gettime(CLOCK_REALTIME, &timeout); + timeout.tv_sec += 5; //timeout after 5s. + + pthread_mutex_lock(&mp_lock); + while (!isMPlayerCompleted) { + int err = pthread_cond_timedwait(&mp_cond, &mp_lock, &timeout); + if (err == ETIMEDOUT) { + break; + } } + pthread_mutex_unlock(&mp_lock); + ALOGD("media player is completed."); } - pthread_mutex_unlock(&mp_lock); - ALOGD("media player is completed."); pthread_cond_destroy(&mp_cond); pthread_mutex_destroy(&mp_lock); -- cgit v1.1