diff options
-rw-r--r-- | camera/CameraParameters.cpp | 2 | ||||
-rw-r--r-- | include/camera/CameraParameters.h | 14 | ||||
-rw-r--r-- | media/libstagefright/codecs/aacdec/AACDecoder.cpp | 69 | ||||
-rw-r--r-- | media/libstagefright/include/AACDecoder.h | 2 |
4 files changed, 68 insertions, 19 deletions
diff --git a/camera/CameraParameters.cpp b/camera/CameraParameters.cpp index 362d9ee..83e5e57 100644 --- a/camera/CameraParameters.cpp +++ b/camera/CameraParameters.cpp @@ -142,7 +142,7 @@ const char CameraParameters::FOCUS_MODE_INFINITY[] = "infinity"; const char CameraParameters::FOCUS_MODE_MACRO[] = "macro"; const char CameraParameters::FOCUS_MODE_FIXED[] = "fixed"; const char CameraParameters::FOCUS_MODE_EDOF[] = "edof"; -const char CameraParameters::FOCUS_MODE_CONTINUOUS[] = "continuous"; +const char CameraParameters::FOCUS_MODE_CONTINUOUS_VIDEO[] = "continuous-video"; CameraParameters::CameraParameters() : mMap() diff --git a/include/camera/CameraParameters.h b/include/camera/CameraParameters.h index 7c5371a..53039a0 100644 --- a/include/camera/CameraParameters.h +++ b/include/camera/CameraParameters.h @@ -380,12 +380,14 @@ public: // continuously. Applications should not call // CameraHardwareInterface.autoFocus in this mode. static const char FOCUS_MODE_EDOF[]; - // Continuous auto focus mode. The camera continuously tries to focus. This - // is ideal for shooting video or shooting photo of moving object. 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[]; + // 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. + static const char FOCUS_MODE_CONTINUOUS_VIDEO[]; private: DefaultKeyedVector<String8,String8> mMap; diff --git a/media/libstagefright/codecs/aacdec/AACDecoder.cpp b/media/libstagefright/codecs/aacdec/AACDecoder.cpp index c5b51c0..e4ed5e6 100644 --- a/media/libstagefright/codecs/aacdec/AACDecoder.cpp +++ b/media/libstagefright/codecs/aacdec/AACDecoder.cpp @@ -123,6 +123,8 @@ status_t AACDecoder::start(MetaData *params) { mAnchorTimeUs = 0; mNumSamplesOutput = 0; mStarted = true; + mNumDecodedBuffers = 0; + mUpsamplingFactor = 2; return OK; } @@ -207,22 +209,65 @@ status_t AACDecoder::read( Int decoderErr = PVMP4AudioDecodeFrame(mConfig, mDecoderBuf); - // Check on the sampling rate to see whether it is changed. - int32_t sampleRate; - CHECK(mMeta->findInt32(kKeySampleRate, &sampleRate)); - if (mConfig->samplingRate != sampleRate) { - mMeta->setInt32(kKeySampleRate, mConfig->samplingRate); - LOGW("Sample rate was %d, but now is %d", - sampleRate, mConfig->samplingRate); - buffer->release(); - mInputBuffer->release(); - mInputBuffer = NULL; - return INFO_FORMAT_CHANGED; + /* + * AAC+/eAAC+ streams can be signalled in two ways: either explicitly + * or implicitly, according to MPEG4 spec. AAC+/eAAC+ is a dual + * rate system and the sampling rate in the final output is actually + * doubled compared with the core AAC decoder sampling rate. + * + * Explicit signalling is done by explicitly defining SBR audio object + * type in the bitstream. Implicit signalling is done by embedding + * SBR content in AAC extension payload specific to SBR, and hence + * requires an AAC decoder to perform pre-checks on actual audio frames. + * + * Thus, we could not say for sure whether a stream is + * AAC+/eAAC+ until the first data frame is decoded. + */ + if (++mNumDecodedBuffers <= 2) { + LOGV("audio/extended audio object type: %d + %d", + mConfig->audioObjectType, mConfig->extendedAudioObjectType); + LOGV("aac+ upsampling factor: %d desired channels: %d", + mConfig->aacPlusUpsamplingFactor, mConfig->desiredChannels); + + CHECK(mNumDecodedBuffers > 0); + if (mNumDecodedBuffers == 1) { + mUpsamplingFactor = mConfig->aacPlusUpsamplingFactor; + // Check on the sampling rate to see whether it is changed. + int32_t sampleRate; + CHECK(mMeta->findInt32(kKeySampleRate, &sampleRate)); + if (mConfig->samplingRate != sampleRate) { + mMeta->setInt32(kKeySampleRate, mConfig->samplingRate); + LOGW("Sample rate was %d Hz, but now is %d Hz", + sampleRate, mConfig->samplingRate); + buffer->release(); + mInputBuffer->release(); + mInputBuffer = NULL; + return INFO_FORMAT_CHANGED; + } + } else { // mNumDecodedBuffers == 2 + if (mConfig->extendedAudioObjectType == MP4AUDIO_AAC_LC || + mConfig->extendedAudioObjectType == MP4AUDIO_LTP) { + if (mUpsamplingFactor == 2) { + // The stream turns out to be not aacPlus mode anyway + LOGW("Disable AAC+/eAAC+ since extended audio object type is %d", + mConfig->extendedAudioObjectType); + mConfig->aacPlusEnabled = 0; + } + } else { + if (mUpsamplingFactor == 1) { + // aacPlus mode does not buy us anything, but to cause + // 1. CPU load to increase, and + // 2. a half speed of decoding + LOGW("Disable AAC+/eAAC+ since upsampling factor is 1"); + mConfig->aacPlusEnabled = 0; + } + } + } } size_t numOutBytes = mConfig->frameLength * sizeof(int16_t) * mConfig->desiredChannels; - if (mConfig->aacPlusUpsamplingFactor == 2) { + if (mUpsamplingFactor == 2) { if (mConfig->desiredChannels == 1) { memcpy(&mConfig->pOutputBuffer[1024], &mConfig->pOutputBuffer[2048], numOutBytes * 2); } diff --git a/media/libstagefright/include/AACDecoder.h b/media/libstagefright/include/AACDecoder.h index 200f93c..886a3b7 100644 --- a/media/libstagefright/include/AACDecoder.h +++ b/media/libstagefright/include/AACDecoder.h @@ -53,6 +53,8 @@ private: int64_t mAnchorTimeUs; int64_t mNumSamplesOutput; status_t mInitCheck; + int64_t mNumDecodedBuffers; + int32_t mUpsamplingFactor; MediaBuffer *mInputBuffer; |