RTSP now properly publishes its "seekable" flags after connection

has successfully completed and only then signals that preparation is
complete.

Change-Id: I1a60f718e673fe1462c69369c40eafbed6a14326
diff --git a/media/libmediaplayerservice/nuplayer/RTSPSource.cpp b/media/libmediaplayerservice/nuplayer/RTSPSource.cpp
index e4d72d9..d787647 100644
--- a/media/libmediaplayerservice/nuplayer/RTSPSource.cpp
+++ b/media/libmediaplayerservice/nuplayer/RTSPSource.cpp
@@ -96,16 +96,6 @@
 
         mHandler->connect();
     }
-
-    notifyVideoSizeChanged(0, 0);
-
-    notifyFlagsChanged(
-            FLAG_CAN_PAUSE
-            | FLAG_CAN_SEEK_BACKWARD
-            | FLAG_CAN_SEEK_FORWARD
-            | FLAG_CAN_SEEK);
-
-    notifyPrepared();
 }
 
 void NuPlayer::RTSPSource::start() {
@@ -270,12 +260,31 @@
 
     switch (what) {
         case MyHandler::kWhatConnected:
+        {
             onConnected();
+
+            notifyVideoSizeChanged(0, 0);
+
+            uint32_t flags = 0;
+
+            if (mHandler->isSeekable()) {
+                flags = FLAG_CAN_PAUSE | FLAG_CAN_SEEK;
+
+                // Seeking 10secs forward or backward is a very expensive
+                // operation for rtsp, so let's not enable that.
+                // The user can always use the seek bar.
+            }
+
+            notifyFlagsChanged(flags);
+            notifyPrepared();
             break;
+        }
 
         case MyHandler::kWhatDisconnected:
+        {
             onDisconnected(msg);
             break;
+        }
 
         case MyHandler::kWhatSeekDone:
         {
@@ -520,6 +529,12 @@
     }
 
     if (err != OK) {
+        if (mState == CONNECTING) {
+            // We're still in the preparation phase, signal that it
+            // failed.
+            notifyPrepared(err);
+        }
+
         mState = DISCONNECTED;
         mFinalResult = err;
 
@@ -537,6 +552,12 @@
     mLooper->unregisterHandler(mHandler->id());
     mHandler.clear();
 
+    if (mState == CONNECTING) {
+        // We're still in the preparation phase, signal that it
+        // failed.
+        notifyPrepared(err);
+    }
+
     mState = DISCONNECTED;
     mFinalResult = err;