Merge "Proper support for variable NALsize lengths of AVC content in .mkv files."
diff --git a/camera/Camera.cpp b/camera/Camera.cpp
index 148e864..450971d 100644
--- a/camera/Camera.cpp
+++ b/camera/Camera.cpp
@@ -372,6 +372,9 @@
     }
     if (listener != NULL) {
         listener->postDataTimestamp(timestamp, msgType, dataPtr);
+    } else {
+        LOGW("No listener was set. Drop a recording frame.");
+        releaseRecordingFrame(dataPtr);
     }
 }
 
diff --git a/cmds/stagefright/recordvideo.cpp b/cmds/stagefright/recordvideo.cpp
index f8eb514..1264215 100644
--- a/cmds/stagefright/recordvideo.cpp
+++ b/cmds/stagefright/recordvideo.cpp
@@ -264,7 +264,7 @@
     }
     enc_meta->setInt32(kKeyWidth, width);
     enc_meta->setInt32(kKeyHeight, height);
-    enc_meta->setInt32(kKeySampleRate, frameRateFps);
+    enc_meta->setInt32(kKeyFrameRate, frameRateFps);
     enc_meta->setInt32(kKeyBitRate, bitRateBps);
     enc_meta->setInt32(kKeyStride, width);
     enc_meta->setInt32(kKeySliceHeight, height);
diff --git a/media/libstagefright/CameraSource.cpp b/media/libstagefright/CameraSource.cpp
index b8450fb..d9ff723 100644
--- a/media/libstagefright/CameraSource.cpp
+++ b/media/libstagefright/CameraSource.cpp
@@ -495,26 +495,6 @@
         mIsMetaDataStoredInVideoBuffers = true;
     }
 
-    /*
-     * mCamera->startRecording() signals camera hal to make
-     * available the video buffers (for instance, allocation
-     * of the video buffers may be triggered when camera hal's
-     * startRecording() method is called). Making available these
-     * video buffers earlier (before calling start()) is critical,
-     * if one wants to configure omx video encoders to use these
-     * buffers for passing video frame data during video recording
-     * without the need to memcpy the video frame data stored
-     * in these buffers. Eliminating memcpy for video frame data
-     * is crucial in performance for HD quality video recording
-     * applications.
-     *
-     * Based on OMX IL spec, configuring the omx video encoders
-     * must occur in loaded state. When start() is called, omx
-     * video encoders are already in idle state, which is too
-     * late. Thus, we must call mCamera->startRecording() earlier.
-     */
-    startCameraRecording();
-
     IPCThreadState::self()->restoreCallingIdentity(token);
 
     int64_t glitchDurationUs = (1000000LL / mVideoFrameRate);
@@ -565,8 +545,11 @@
         mStartTimeUs = startTimeUs;
     }
 
+    // Call setListener first before calling startCameraRecording()
+    // to avoid recording frames being dropped.
     int64_t token = IPCThreadState::self()->clearCallingIdentity();
     mCamera->setListener(new CameraSourceListener(this));
+    startCameraRecording();
     IPCThreadState::self()->restoreCallingIdentity(token);
 
     mStarted = true;