Don't change the video recording frame rate if it is not requested.

o set the default video frame rate to the current frame rate being used
o add check on whether the requested frame rate is supported
o fix an issue where the hardware video encoder setting was bypassed
o increases the max frame rate from 30 t0 120 frames per second
  the actual frame rate will be clipped if the requested frame rate is too
  high when recording starts by checking the hardware encoder capabilities

Change-Id: I1b47671d74da0ebcb9601bdca390d430cc048fbc
diff --git a/media/libstagefright/CameraSource.cpp b/media/libstagefright/CameraSource.cpp
index 95afb1d..159d937 100644
--- a/media/libstagefright/CameraSource.cpp
+++ b/media/libstagefright/CameraSource.cpp
@@ -313,6 +313,20 @@
     }
 
     if (frameRate != -1) {
+        CHECK(frameRate > 0 && frameRate <= 120);
+        const char* supportedFrameRates =
+                params->get(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES);
+        CHECK(supportedFrameRates != NULL);
+        LOGV("Supported frame rates: %s", supportedFrameRates);
+        char buf[4];
+        snprintf(buf, 4, "%d", frameRate);
+        if (strstr(supportedFrameRates, buf) == NULL) {
+            LOGE("Requested frame rate (%d) is not supported: %s",
+                frameRate, supportedFrameRates);
+            return BAD_VALUE;
+        }
+
+        // The frame rate is supported, set the camera to the requested value.
         params->setPreviewFrameRate(frameRate);
         isCameraParamChanged = true;
     } else {  // frameRate == -1
@@ -517,6 +531,7 @@
     mMeta->setInt32(kKeyHeight,      mVideoSize.height);
     mMeta->setInt32(kKeyStride,      mVideoSize.width);
     mMeta->setInt32(kKeySliceHeight, mVideoSize.height);
+    mMeta->setInt32(kKeySampleRate,  mVideoFrameRate);
     return OK;
 }