Fix a rare crash.

- Crash could be reproduced by seeking to the very end of a voicemail,
  playing the voicemail to see the ui reset to beginning, then
  increasing rate.
- Reason was that during playback, insufficient data has been read to
  read the sample rate and channels, and in that situation the increase
  rate requires constructing the time scaler, which in turn requires
  a valid sample rate and channels.
- Added a test to prove that the bug exists, and to prove the fix which
  is to ignore the rate change call when sample rate and channels not
  known.
- Also added another unit test in the process to verify that it's safe
  to call set rate at any point during the life cycle of the player.

Bug: 5140693
Change-Id: I474e5769f2b72762348534e4d06104af247e8726
diff --git a/variablespeed/jni/variablespeed.cc b/variablespeed/jni/variablespeed.cc
index 12684f1..344eca5 100644
--- a/variablespeed/jni/variablespeed.cc
+++ b/variablespeed/jni/variablespeed.cc
@@ -296,9 +296,15 @@
 // Regular AudioEngine class methods.
 
 void AudioEngine::SetVariableSpeed(float speed) {
-  // TODO: Add test, prove that this doesn't crash if called before playing.
   // TODO: Mutex for shared time scaler accesses.
-  GetTimeScaler()->set_speed(speed);
+  if (HasSampleRateAndChannels()) {
+    GetTimeScaler()->set_speed(speed);
+  } else {
+    // This is being called at a point where we have not yet processed enough
+    // data to determine the sample rate and number of channels.
+    // Ignore the call.  See http://b/5140693.
+    LOGD("set varaible speed called, sample rate and channels not ready yet");
+  }
 }
 
 void AudioEngine::RequestStart() {