Merge "To make SniffMP3() more concrete so that we can remove false-positve responses from MPEG-PS streams."
diff --git a/camera/CameraParameters.cpp b/camera/CameraParameters.cpp
index 51b96c1..0eb5d50 100644
--- a/camera/CameraParameters.cpp
+++ b/camera/CameraParameters.cpp
@@ -160,6 +160,7 @@
 const char CameraParameters::FOCUS_MODE_FIXED[] = "fixed";
 const char CameraParameters::FOCUS_MODE_EDOF[] = "edof";
 const char CameraParameters::FOCUS_MODE_CONTINUOUS_VIDEO[] = "continuous-video";
+const char CameraParameters::FOCUS_MODE_CONTINUOUS_PICTURE[] = "continuous-picture";
 
 CameraParameters::CameraParameters()
                 : mMap()
diff --git a/include/camera/CameraParameters.h b/include/camera/CameraParameters.h
index b661496..6c91dfc 100644
--- a/include/camera/CameraParameters.h
+++ b/include/camera/CameraParameters.h
@@ -597,13 +597,24 @@
     // CameraHardwareInterface.autoFocus in this mode.
     static const char FOCUS_MODE_EDOF[];
     // Continuous auto focus mode intended for video recording. The camera
-    // continuously tries to focus. This is ideal for shooting video.
-    // Applications still can call CameraHardwareInterface.takePicture in this
-    // mode but the subject may not be in focus. Auto focus starts when the
-    // parameter is set. Applications should not call
-    // CameraHardwareInterface.autoFocus in this mode. To stop continuous focus,
-    // applications should change the focus mode to other modes.
+    // continuously tries to focus. This is the best choice for video
+    // recording because the focus changes smoothly . Applications still can
+    // call CameraHardwareInterface.takePicture in this mode but the subject may
+    // not be in focus. Auto focus starts when the parameter is set.
+    // Applications should not call CameraHardwareInterface.autoFocus in this
+    // mode. To stop continuous focus, applications should change the focus mode
+    // to other modes.
     static const char FOCUS_MODE_CONTINUOUS_VIDEO[];
+    // Continuous auto focus mode intended for taking pictures. The camera
+    // continuously tries to focus. The speed of focus change is more aggressive
+    // than FOCUS_MODE_CONTINUOUS_VIDEO. Auto focus starts when the parameter is
+    // set. If applications call autoFocus in this mode, the focus callback will
+    // immediately return with a boolean that indicates the focus is sharp or
+    // not. The apps can then decide if they want to take a picture immediately
+    // or to change the focus mode to auto, and run a full autofocus cycle. To
+    // stop continuous focus, applications should change the focus mode to other
+    // modes.
+    static const char FOCUS_MODE_CONTINUOUS_PICTURE[];
 
 private:
     DefaultKeyedVector<String8,String8>    mMap;
diff --git a/include/media/MediaProfiles.h b/include/media/MediaProfiles.h
index 69d5001..4b023d1 100644
--- a/include/media/MediaProfiles.h
+++ b/include/media/MediaProfiles.h
@@ -140,6 +140,19 @@
     int getVideoEditorCapParamByName(const char *name) const;
 
     /**
+     * Returns the value for the given param name for the video editor export codec format
+     * param or -1 if error.
+     * Supported param name are:
+     * videoeditor.export.profile - export video profile
+     * videoeditor.export.level - export video level
+     * Supported param codec are:
+     * 1 for h263
+     * 2 for h264
+     * 3 for mpeg4
+     */
+    int getVideoEditorExportParamByName(const char *name, int codec) const;
+
+    /**
      * Returns the audio encoders supported.
      */
     Vector<audio_encoder> getAudioEncoders() const;
@@ -332,7 +345,14 @@
         int mCameraId;
         Vector<int> mLevels;
     };
-
+    struct ExportVideoProfile {
+        ExportVideoProfile(int codec, int profile, int level)
+            :mCodec(codec),mProfile(profile),mLevel(level) {}
+        ~ExportVideoProfile() {}
+        int mCodec;
+        int mProfile;
+        int mLevel;
+    };
     struct VideoEditorCap {
         VideoEditorCap(int inFrameWidth, int inFrameHeight,
             int outFrameWidth, int outFrameHeight)
@@ -374,6 +394,7 @@
     static AudioEncoderCap* createAudioEncoderCap(const char **atts);
     static VideoEditorCap* createVideoEditorCap(
                 const char **atts, MediaProfiles *profiles);
+    static ExportVideoProfile* createExportVideoProfile(const char **atts);
 
     static CamcorderProfile* createCamcorderProfile(
                 int cameraId, const char **atts, Vector<int>& cameraIds);
@@ -418,6 +439,8 @@
     static void createDefaultImageEncodingQualityLevels(MediaProfiles *profiles);
     static void createDefaultImageDecodingMaxMemory(MediaProfiles *profiles);
     static void createDefaultVideoEditorCap(MediaProfiles *profiles);
+    static void createDefaultExportVideoProfiles(MediaProfiles *profiles);
+
     static VideoEncoderCap* createDefaultH263VideoEncoderCap();
     static VideoEncoderCap* createDefaultM4vVideoEncoderCap();
     static AudioEncoderCap* createDefaultAmrNBEncoderCap();
@@ -475,6 +498,7 @@
     RequiredProfiles *mRequiredProfileRefs;
     Vector<int>              mCameraIds;
     VideoEditorCap* mVideoEditorCap;
+    Vector<ExportVideoProfile*> mVideoEditorExportProfiles;
 };
 
 }; // namespace android
diff --git a/media/libmedia/MediaProfiles.cpp b/media/libmedia/MediaProfiles.cpp
index f0f07a2..5a8bc60 100644
--- a/media/libmedia/MediaProfiles.cpp
+++ b/media/libmedia/MediaProfiles.cpp
@@ -26,6 +26,7 @@
 #include <expat.h>
 #include <media/MediaProfiles.h>
 #include <media/stagefright/MediaDebug.h>
+#include <media/stagefright/openmax/OMX_Video.h>
 
 namespace android {
 
@@ -377,7 +378,24 @@
     LOGV("%s: cameraId=%d, offset=%d ms", __func__, cameraId, offsetTimeMs);
     mStartTimeOffsets.replaceValueFor(cameraId, offsetTimeMs);
 }
+/*static*/ MediaProfiles::ExportVideoProfile*
+MediaProfiles::createExportVideoProfile(const char **atts)
+{
+    CHECK(!strcmp("name", atts[0]) &&
+          !strcmp("profile", atts[2]) &&
+          !strcmp("level", atts[4]));
 
+    const size_t nMappings =
+        sizeof(sVideoEncoderNameMap)/sizeof(sVideoEncoderNameMap[0]);
+    const int codec = findTagForName(sVideoEncoderNameMap, nMappings, atts[1]);
+    CHECK(codec != -1);
+
+    MediaProfiles::ExportVideoProfile *profile =
+        new MediaProfiles::ExportVideoProfile(
+            codec, atoi(atts[3]), atoi(atts[5]));
+
+    return profile;
+}
 /*static*/ MediaProfiles::VideoEditorCap*
 MediaProfiles::createVideoEditorCap(const char **atts, MediaProfiles *profiles)
 {
@@ -428,6 +446,8 @@
         profiles->addImageEncodingQualityLevel(profiles->mCurrentCameraId, atts);
     } else if (strcmp("VideoEditorCap", name) == 0) {
         createVideoEditorCap(atts, profiles);
+    } else if (strcmp("ExportVideoProfile", name) == 0) {
+        profiles->mVideoEditorExportProfiles.add(createExportVideoProfile(atts));
     }
 }
 
@@ -830,6 +850,20 @@
                 VIDEOEDITOR_DEFAULT_MAX_OUTPUT_FRAME_WIDTH,
                 VIDEOEDITOR_DEFUALT_MAX_OUTPUT_FRAME_HEIGHT);
 }
+/*static*/ void
+MediaProfiles::createDefaultExportVideoProfiles(MediaProfiles *profiles)
+{
+    // Create default video export profiles
+    profiles->mVideoEditorExportProfiles.add(
+        new ExportVideoProfile(VIDEO_ENCODER_H263,
+            OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level10));
+    profiles->mVideoEditorExportProfiles.add(
+        new ExportVideoProfile(VIDEO_ENCODER_MPEG_4_SP,
+            OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level1));
+    profiles->mVideoEditorExportProfiles.add(
+        new ExportVideoProfile(VIDEO_ENCODER_H264,
+            OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel13));
+}
 
 /*static*/ MediaProfiles*
 MediaProfiles::createDefaultInstance()
@@ -843,6 +877,7 @@
     createDefaultEncoderOutputFileFormats(profiles);
     createDefaultImageEncodingQualityLevels(profiles);
     createDefaultVideoEditorCap(profiles);
+    createDefaultExportVideoProfiles(profiles);
     return profiles;
 }
 
@@ -940,7 +975,31 @@
     LOGE("The given video encoder param name %s is not found", name);
     return -1;
 }
+int MediaProfiles::getVideoEditorExportParamByName(
+    const char *name, int codec) const
+{
+    LOGV("getVideoEditorExportParamByName: name %s codec %d", name, codec);
+    ExportVideoProfile *exportProfile = NULL;
+    int index = -1;
+    for (size_t i =0; i < mVideoEditorExportProfiles.size(); i++) {
+        exportProfile = mVideoEditorExportProfiles[i];
+        if (exportProfile->mCodec == codec) {
+            index = i;
+            break;
+        }
+    }
+    if (index == -1) {
+        LOGE("The given video decoder %d is not found", codec);
+        return -1;
+    }
+    if (!strcmp("videoeditor.export.profile", name))
+        return exportProfile->mProfile;
+    if (!strcmp("videoeditor.export.level", name))
+        return exportProfile->mLevel;
 
+    LOGE("The given video editor export param name %s is not found", name);
+    return -1;
+}
 int MediaProfiles::getVideoEditorCapParamByName(const char *name) const
 {
     LOGV("getVideoEditorCapParamByName: %s", name);
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp
index 99242ab..f2673b3 100644
--- a/media/libstagefright/AwesomePlayer.cpp
+++ b/media/libstagefright/AwesomePlayer.cpp
@@ -59,6 +59,7 @@
 #include <cutils/properties.h>
 
 #define USE_SURFACE_ALLOC 1
+#define FRAME_DROP_FREQ 0
 
 namespace android {
 
@@ -548,7 +549,7 @@
     mVideoTimeUs = 0;
 
     mSeeking = NO_SEEK;
-    mSeekNotificationSent = false;
+    mSeekNotificationSent = true;
     mSeekTimeUs = 0;
 
     mUri.setTo("");
@@ -820,7 +821,12 @@
         return;
     }
 
-    if (mFlags & (LOOPING | AUTO_LOOPING)) {
+    if ((mFlags & LOOPING)
+            || ((mFlags & AUTO_LOOPING)
+                && (mAudioSink == NULL || mAudioSink->realtime()))) {
+        // Don't AUTO_LOOP if we're being recorded, since that cannot be
+        // turned off and recording would go on indefinitely.
+
         seekTo_l(0);
 
         if (mVideoSource != NULL) {
@@ -1204,7 +1210,6 @@
 
     if (mLastVideoTimeUs >= 0) {
         mSeeking = SEEK;
-        mSeekNotificationSent = true;
         mSeekTimeUs = mLastVideoTimeUs;
         modifyFlags((AT_EOS | AUDIO_AT_EOS | VIDEO_AT_EOS), CLEAR);
     }
@@ -1305,8 +1310,10 @@
 }
 
 void AwesomePlayer::onRTSPSeekDone() {
-    notifyListener_l(MEDIA_SEEK_COMPLETE);
-    mSeekNotificationSent = true;
+    if (!mSeekNotificationSent) {
+        notifyListener_l(MEDIA_SEEK_COMPLETE);
+        mSeekNotificationSent = true;
+    }
 }
 
 status_t AwesomePlayer::seekTo_l(int64_t timeUs) {
@@ -1518,14 +1525,29 @@
     }
 
     if (mVideoSource != NULL) {
-        Mutex::Autolock autoLock(mStatsLock);
-        TrackStat *stat = &mStats.mTracks.editItemAt(mStats.mVideoTrackIndex);
-
-        const char *component;
+        const char *componentName;
         CHECK(mVideoSource->getFormat()
-                ->findCString(kKeyDecoderComponent, &component));
+                ->findCString(kKeyDecoderComponent, &componentName));
 
-        stat->mDecoderName = component;
+        {
+            Mutex::Autolock autoLock(mStatsLock);
+            TrackStat *stat = &mStats.mTracks.editItemAt(mStats.mVideoTrackIndex);
+
+            stat->mDecoderName = componentName;
+        }
+
+        static const char *kPrefix = "OMX.Nvidia.";
+        static const char *kSuffix = ".decode";
+        static const size_t kSuffixLength = strlen(kSuffix);
+
+        size_t componentNameLength = strlen(componentName);
+
+        if (!strncmp(componentName, kPrefix, strlen(kPrefix))
+                && componentNameLength >= kSuffixLength
+                && !strcmp(&componentName[
+                    componentNameLength - kSuffixLength], kSuffix)) {
+            modifyFlags(SLOW_DECODER_HACK, SET);
+        }
     }
 
     return mVideoSource != NULL ? OK : UNKNOWN_ERROR;
@@ -1705,6 +1727,7 @@
 
     if (mFlags & FIRST_FRAME) {
         modifyFlags(FIRST_FRAME, CLEAR);
+        mSinceLastDropped = 0;
         mTimeSourceDeltaUs = ts->getRealTimeUs() - timeUs;
     }
 
@@ -1751,18 +1774,28 @@
 
         if (latenessUs > 40000) {
             // We're more than 40ms late.
-            LOGV("we're late by %lld us (%.2f secs), dropping frame",
+            LOGV("we're late by %lld us (%.2f secs)",
                  latenessUs, latenessUs / 1E6);
-            mVideoBuffer->release();
-            mVideoBuffer = NULL;
 
+            if (!(mFlags & SLOW_DECODER_HACK)
+                    || mSinceLastDropped > FRAME_DROP_FREQ)
             {
-                Mutex::Autolock autoLock(mStatsLock);
-                ++mStats.mNumVideoFramesDropped;
-            }
+                LOGV("we're late by %lld us (%.2f secs) dropping "
+                     "one after %d frames",
+                     latenessUs, latenessUs / 1E6, mSinceLastDropped);
 
-            postVideoEvent_l();
-            return;
+                mSinceLastDropped = 0;
+                mVideoBuffer->release();
+                mVideoBuffer = NULL;
+
+                {
+                    Mutex::Autolock autoLock(mStatsLock);
+                    ++mStats.mNumVideoFramesDropped;
+                }
+
+                postVideoEvent_l();
+                return;
+            }
         }
 
         if (latenessUs < -10000) {
@@ -1781,6 +1814,7 @@
     }
 
     if (mVideoRenderer != NULL) {
+        mSinceLastDropped++;
         mVideoRenderer->render(mVideoBuffer);
     }
 
diff --git a/media/libstagefright/codecs/aacdec/SoftAAC.cpp b/media/libstagefright/codecs/aacdec/SoftAAC.cpp
index f0a330f..2abdb56 100644
--- a/media/libstagefright/codecs/aacdec/SoftAAC.cpp
+++ b/media/libstagefright/codecs/aacdec/SoftAAC.cpp
@@ -378,24 +378,36 @@
             // fall through
         }
 
-        if (mUpsamplingFactor == 2) {
-            if (mConfig->desiredChannels == 1) {
-                memcpy(&mConfig->pOutputBuffer[1024],
-                       &mConfig->pOutputBuffer[2048],
-                       numOutBytes * 2);
+        if (decoderErr == MP4AUDEC_SUCCESS || mNumSamplesOutput > 0) {
+            // We'll only output data if we successfully decoded it or
+            // we've previously decoded valid data, in the latter case
+            // (decode failed) we'll output a silent frame.
+
+            if (mUpsamplingFactor == 2) {
+                if (mConfig->desiredChannels == 1) {
+                    memcpy(&mConfig->pOutputBuffer[1024],
+                           &mConfig->pOutputBuffer[2048],
+                           numOutBytes * 2);
+                }
+                numOutBytes *= 2;
             }
-            numOutBytes *= 2;
+
+            outHeader->nFilledLen = numOutBytes;
+            outHeader->nFlags = 0;
+
+            outHeader->nTimeStamp =
+                mAnchorTimeUs
+                    + (mNumSamplesOutput * 1000000ll) / mConfig->samplingRate;
+
+            mNumSamplesOutput += mConfig->frameLength * mUpsamplingFactor;
+
+            outInfo->mOwnedByUs = false;
+            outQueue.erase(outQueue.begin());
+            outInfo = NULL;
+            notifyFillBufferDone(outHeader);
+            outHeader = NULL;
         }
 
-        outHeader->nFilledLen = numOutBytes;
-        outHeader->nFlags = 0;
-
-        outHeader->nTimeStamp =
-            mAnchorTimeUs
-                + (mNumSamplesOutput * 1000000ll) / mConfig->samplingRate;
-
-        mNumSamplesOutput += mConfig->frameLength * mUpsamplingFactor;
-
         if (inHeader->nFilledLen == 0) {
             inInfo->mOwnedByUs = false;
             inQueue.erase(inQueue.begin());
@@ -404,12 +416,6 @@
             inHeader = NULL;
         }
 
-        outInfo->mOwnedByUs = false;
-        outQueue.erase(outQueue.begin());
-        outInfo = NULL;
-        notifyFillBufferDone(outHeader);
-        outHeader = NULL;
-
         if (decoderErr == MP4AUDEC_SUCCESS) {
             ++mInputBufferCount;
         }
diff --git a/media/libstagefright/codecs/on2/dec/SoftVPX.cpp b/media/libstagefright/codecs/on2/dec/SoftVPX.cpp
index 7e83163..61a02ac 100644
--- a/media/libstagefright/codecs/on2/dec/SoftVPX.cpp
+++ b/media/libstagefright/codecs/on2/dec/SoftVPX.cpp
@@ -66,7 +66,7 @@
     def.eDir = OMX_DirInput;
     def.nBufferCountMin = kNumBuffers;
     def.nBufferCountActual = def.nBufferCountMin;
-    def.nBufferSize = 8192;
+    def.nBufferSize = 256 * 1024;
     def.bEnabled = OMX_TRUE;
     def.bPopulated = OMX_FALSE;
     def.eDomain = OMX_PortDomainVideo;
diff --git a/media/libstagefright/include/AwesomePlayer.h b/media/libstagefright/include/AwesomePlayer.h
index 95f2ae8..14476d3 100644
--- a/media/libstagefright/include/AwesomePlayer.h
+++ b/media/libstagefright/include/AwesomePlayer.h
@@ -141,6 +141,8 @@
 
         TEXT_RUNNING        = 0x10000,
         TEXTPLAYER_STARTED  = 0x20000,
+
+        SLOW_DECODER_HACK   = 0x40000,
     };
 
     mutable Mutex mLock;
@@ -181,6 +183,7 @@
 
     uint32_t mFlags;
     uint32_t mExtractorFlags;
+    uint32_t mSinceLastDropped;
 
     int64_t mTimeSourceDeltaUs;
     int64_t mVideoTimeUs;
diff --git a/media/libstagefright/matroska/MatroskaExtractor.cpp b/media/libstagefright/matroska/MatroskaExtractor.cpp
index e1b9991..3ef7b71 100644
--- a/media/libstagefright/matroska/MatroskaExtractor.cpp
+++ b/media/libstagefright/matroska/MatroskaExtractor.cpp
@@ -493,7 +493,8 @@
     : mDataSource(source),
       mReader(new DataSourceReader(mDataSource)),
       mSegment(NULL),
-      mExtractedThumbnails(false) {
+      mExtractedThumbnails(false),
+      mIsWebm(false) {
     off64_t size;
     mIsLiveStreaming =
         (mDataSource->flags()
@@ -507,6 +508,10 @@
         return;
     }
 
+    if (ebmlHeader.m_docType && !strcmp("webm", ebmlHeader.m_docType)) {
+        mIsWebm = true;
+    }
+
     long long ret =
         mkvparser::Segment::CreateInstance(mReader, pos, mSegment);
 
@@ -757,7 +762,10 @@
 
 sp<MetaData> MatroskaExtractor::getMetaData() {
     sp<MetaData> meta = new MetaData;
-    meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_CONTAINER_MATROSKA);
+
+    meta->setCString(
+            kKeyMIMEType,
+            mIsWebm ? "video/webm" : MEDIA_MIMETYPE_CONTAINER_MATROSKA);
 
     return meta;
 }
diff --git a/media/libstagefright/matroska/MatroskaExtractor.h b/media/libstagefright/matroska/MatroskaExtractor.h
index 38ebd61..1294b4f 100644
--- a/media/libstagefright/matroska/MatroskaExtractor.h
+++ b/media/libstagefright/matroska/MatroskaExtractor.h
@@ -68,6 +68,7 @@
     mkvparser::Segment *mSegment;
     bool mExtractedThumbnails;
     bool mIsLiveStreaming;
+    bool mIsWebm;
 
     void addTracks();
     void findThumbnails();
diff --git a/media/libstagefright/omx/OMXNodeInstance.cpp b/media/libstagefright/omx/OMXNodeInstance.cpp
index 12ab941..b612f89 100644
--- a/media/libstagefright/omx/OMXNodeInstance.cpp
+++ b/media/libstagefright/omx/OMXNodeInstance.cpp
@@ -419,7 +419,7 @@
     def.nVersion.s.nStep = 0;
     def.nPortIndex = portIndex;
     OMX_ERRORTYPE err = OMX_GetParameter(mHandle, OMX_IndexParamPortDefinition, &def);
-    if (err != OK)
+    if (err != OMX_ErrorNone)
     {
         LOGE("%s::%d:Error getting OMX_IndexParamPortDefinition", __FUNCTION__, __LINE__);
         return err;
@@ -474,9 +474,6 @@
         return useGraphicBuffer2_l(portIndex, graphicBuffer, buffer);
     }
 
-    LOGW("Falling back to the deprecated useAndroidNativeBuffer support.  You "
-        "should switch to the useAndroidNativeBuffer2 extension.");
-
     OMX_ERRORTYPE err = OMX_GetExtensionIndex(
             mHandle,
             const_cast<OMX_STRING>("OMX.google.android.index.useAndroidNativeBuffer"),
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 941c9c8..744fa50 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -522,6 +522,11 @@
 
 status_t AudioFlinger::setMasterVolume(float value)
 {
+    status_t ret = initCheck();
+    if (ret != NO_ERROR) {
+        return ret;
+    }
+
     // check calling permissions
     if (!settingsAllowed()) {
         return PERMISSION_DENIED;
@@ -547,7 +552,10 @@
 
 status_t AudioFlinger::setMode(int mode)
 {
-    status_t ret;
+    status_t ret = initCheck();
+    if (ret != NO_ERROR) {
+        return ret;
+    }
 
     // check calling permissions
     if (!settingsAllowed()) {
@@ -577,6 +585,11 @@
 
 status_t AudioFlinger::setMicMute(bool state)
 {
+    status_t ret = initCheck();
+    if (ret != NO_ERROR) {
+        return ret;
+    }
+
     // check calling permissions
     if (!settingsAllowed()) {
         return PERMISSION_DENIED;
@@ -584,13 +597,18 @@
 
     AutoMutex lock(mHardwareLock);
     mHardwareStatus = AUDIO_HW_SET_MIC_MUTE;
-    status_t ret = mPrimaryHardwareDev->set_mic_mute(mPrimaryHardwareDev, state);
+    ret = mPrimaryHardwareDev->set_mic_mute(mPrimaryHardwareDev, state);
     mHardwareStatus = AUDIO_HW_IDLE;
     return ret;
 }
 
 bool AudioFlinger::getMicMute() const
 {
+    status_t ret = initCheck();
+    if (ret != NO_ERROR) {
+        return false;
+    }
+
     bool state = AUDIO_MODE_INVALID;
     mHardwareStatus = AUDIO_HW_GET_MIC_MUTE;
     mPrimaryHardwareDev->get_mic_mute(mPrimaryHardwareDev, &state);
@@ -814,6 +832,11 @@
 
 size_t AudioFlinger::getInputBufferSize(uint32_t sampleRate, int format, int channelCount)
 {
+    status_t ret = initCheck();
+    if (ret != NO_ERROR) {
+        return 0;
+    }
+
     return mPrimaryHardwareDev->get_input_buffer_size(mPrimaryHardwareDev, sampleRate, format, channelCount);
 }
 
@@ -834,6 +857,11 @@
 
 status_t AudioFlinger::setVoiceVolume(float value)
 {
+    status_t ret = initCheck();
+    if (ret != NO_ERROR) {
+        return ret;
+    }
+
     // check calling permissions
     if (!settingsAllowed()) {
         return PERMISSION_DENIED;
@@ -841,7 +869,7 @@
 
     AutoMutex lock(mHardwareLock);
     mHardwareStatus = AUDIO_SET_VOICE_VOLUME;
-    status_t ret = mPrimaryHardwareDev->set_voice_volume(mPrimaryHardwareDev, value);
+    ret = mPrimaryHardwareDev->set_voice_volume(mPrimaryHardwareDev, value);
     mHardwareStatus = AUDIO_HW_IDLE;
 
     return ret;