diff options
author | Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de> | 2015-12-29 23:08:12 +0100 |
---|---|---|
committer | Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de> | 2015-12-29 23:08:12 +0100 |
commit | 1c47b26b1ae695c355e4ec0c317716a397588206 (patch) | |
tree | 525f78a0d8d9fa58360d1c33af7d553aa8968e50 | |
parent | b5b73768b74d369f47cafd5371a5eaf2ac3d9373 (diff) | |
parent | 8ca3dfd881424650951d1d72ee8809367b1c3d96 (diff) | |
download | frameworks_av-1c47b26b1ae695c355e4ec0c317716a397588206.zip frameworks_av-1c47b26b1ae695c355e4ec0c317716a397588206.tar.gz frameworks_av-1c47b26b1ae695c355e4ec0c317716a397588206.tar.bz2 |
Merge remote-tracking branch 'cyanogenmod/cm-13.0' into replicant-6.0
-rw-r--r-- | include/media/AudioTrack.h | 2 | ||||
-rw-r--r-- | include/media/stagefright/FFMPEGSoftCodec.h | 1 | ||||
-rw-r--r-- | include/media/stagefright/MediaExtractor.h | 2 | ||||
-rw-r--r-- | media/libavextensions/media/AVMediaExtensions.h | 29 | ||||
-rw-r--r-- | media/libavextensions/mediaplayerservice/AVNuUtils.cpp | 14 | ||||
-rw-r--r-- | media/libmediaplayerservice/nuplayer/GenericSource.cpp | 8 | ||||
-rw-r--r-- | media/libmediaplayerservice/nuplayer/NuPlayer.cpp | 14 | ||||
-rw-r--r-- | media/libstagefright/ACodec.cpp | 18 | ||||
-rw-r--r-- | media/libstagefright/DataSource.cpp | 52 | ||||
-rw-r--r-- | media/libstagefright/FFMPEGSoftCodec.cpp | 128 | ||||
-rw-r--r-- | media/libstagefright/FLACExtractor.cpp | 11 | ||||
-rw-r--r-- | media/libstagefright/MediaExtractor.cpp | 33 | ||||
-rw-r--r-- | media/libstagefright/WAVExtractor.cpp | 14 | ||||
-rw-r--r-- | media/libstagefright/codecs/amrwbenc/src/c2t64fx.c | 3 | ||||
-rw-r--r-- | media/libstagefright/codecs/amrwbenc/src/c4t64fx.c | 10 | ||||
-rw-r--r-- | media/libstagefright/codecs/amrwbenc/src/deemph.c | 13 | ||||
-rw-r--r-- | media/libstagefright/codecs/amrwbenc/src/preemph.c | 11 |
17 files changed, 204 insertions, 159 deletions
diff --git a/include/media/AudioTrack.h b/include/media/AudioTrack.h index 191802d..6f07f98 100644 --- a/include/media/AudioTrack.h +++ b/include/media/AudioTrack.h @@ -624,7 +624,7 @@ private: */ status_t obtainBuffer(Buffer* audioBuffer, const struct timespec *requested, struct timespec *elapsed = NULL, size_t *nonContig = NULL); - friend struct ExtendedMediaUtils; + friend struct AVMediaUtils; public: /* Public API for TRANSFER_OBTAIN mode. diff --git a/include/media/stagefright/FFMPEGSoftCodec.h b/include/media/stagefright/FFMPEGSoftCodec.h index 79ea229..c6b6482 100644 --- a/include/media/stagefright/FFMPEGSoftCodec.h +++ b/include/media/stagefright/FFMPEGSoftCodec.h @@ -60,6 +60,7 @@ struct FFMPEGSoftCodec { sp<IOMX> OMXhandle, IOMX::node_id nodeID); static status_t setVideoFormat( + status_t status, const sp<AMessage> &msg, const char* mime, sp<IOMX> OMXhandle,IOMX::node_id nodeID, bool isEncoder, OMX_VIDEO_CODINGTYPE *compressionFormat, diff --git a/include/media/stagefright/MediaExtractor.h b/include/media/stagefright/MediaExtractor.h index 2f2057f..e83defa 100644 --- a/include/media/stagefright/MediaExtractor.h +++ b/include/media/stagefright/MediaExtractor.h @@ -42,7 +42,7 @@ public: static sp<MediaExtractor> Create( const sp<DataSource> &source, const char *mime = NULL, - const uint32_t flags = 0); + const uint32_t flags = 0, const sp<AMessage> *meta = NULL); virtual size_t countTracks() = 0; virtual sp<MediaSource> getTrack(size_t index) = 0; diff --git a/media/libavextensions/media/AVMediaExtensions.h b/media/libavextensions/media/AVMediaExtensions.h index d48feec..9622253 100644 --- a/media/libavextensions/media/AVMediaExtensions.h +++ b/media/libavextensions/media/AVMediaExtensions.h @@ -47,18 +47,33 @@ struct AVMediaUtils { virtual bool AudioTrackIsPcmOffloaded(const audio_format_t format) { return audio_is_offload_pcm(format); } - virtual status_t AudioTrackGetPosition(AudioTrack* /*track*/, - uint32_t* /*position*/) { - return NO_INIT; + + virtual status_t AudioTrackGetPosition(AudioTrack* track, + uint32_t* position) { + uint32_t tempPos = (track->mState == AudioTrack::STATE_STOPPED || + track->mState == AudioTrack::STATE_FLUSHED) ? 0 : + track->updateAndGetPosition_l(); + *position = (tempPos / + (track->channelCount() * audio_bytes_per_sample(track->format()))); + return NO_ERROR; } - virtual status_t AudioTrackGetTimestamp(AudioTrack* /*track*/, - AudioTimestamp* /*timestamp*/) { - return NO_INIT; + virtual status_t AudioTrackGetTimestamp(AudioTrack* track, + AudioTimestamp* timestamp) { + if (!AudioTrackIsPcmOffloaded(track->format())) { + return NO_INIT; + } + uint32_t tempPos = (track->mState == AudioTrack::STATE_STOPPED || + track->mState == AudioTrack::STATE_FLUSHED) ? 0 : + track->updateAndGetPosition_l(); + timestamp->mPosition = (tempPos / (track->channelCount() * + audio_bytes_per_sample(track->format()))); + clock_gettime(CLOCK_MONOTONIC, ×tamp->mTime); + return NO_ERROR; } virtual size_t AudioTrackGetOffloadFrameCount(size_t frameCount) { - return frameCount; + return frameCount * 2; } virtual bool AudioTrackIsTrackOffloaded(audio_io_handle_t /*output*/) { diff --git a/media/libavextensions/mediaplayerservice/AVNuUtils.cpp b/media/libavextensions/mediaplayerservice/AVNuUtils.cpp index 34abd0a..5f146c7 100644 --- a/media/libavextensions/mediaplayerservice/AVNuUtils.cpp +++ b/media/libavextensions/mediaplayerservice/AVNuUtils.cpp @@ -55,21 +55,11 @@ namespace android { static bool is24bitPCMOffloadEnabled() { - char propPCMOfload[PROPERTY_VALUE_MAX] = {0}; - property_get("audio.offload.pcm.24bit.enable", propPCMOfload, "0"); - if (!strncmp(propPCMOfload, "true", 4) || atoi(propPCMOfload)) - return true; - else - return false; + return property_get_bool("audio.offload.pcm.24bit.enable", false); } static bool is16bitPCMOffloadEnabled() { - char propPCMOfload[PROPERTY_VALUE_MAX] = {0}; - property_get("audio.offload.pcm.16bit.enable", propPCMOfload, "0"); - if (!strncmp(propPCMOfload, "true", 4) || atoi(propPCMOfload)) - return true; - else - return false; + return property_get_bool("audio.offload.pcm.16bit.enable", false); } sp<MetaData> AVNuUtils::createPCMMetaFromSource(const sp<MetaData> &sMeta) { diff --git a/media/libmediaplayerservice/nuplayer/GenericSource.cpp b/media/libmediaplayerservice/nuplayer/GenericSource.cpp index e380f0a..beda8bd 100644 --- a/media/libmediaplayerservice/nuplayer/GenericSource.cpp +++ b/media/libmediaplayerservice/nuplayer/GenericSource.cpp @@ -141,14 +141,14 @@ status_t NuPlayer::GenericSource::initFromDataSource() { sp<MediaExtractor> extractor; String8 mimeType; float confidence; - sp<AMessage> dummy; + sp<AMessage> meta; bool isWidevineStreaming = false; CHECK(mDataSource != NULL); if (mIsWidevine) { isWidevineStreaming = SniffWVM( - mDataSource, &mimeType, &confidence, &dummy); + mDataSource, &mimeType, &confidence, &meta); if (!isWidevineStreaming || strcasecmp( mimeType.string(), MEDIA_MIMETYPE_CONTAINER_WVM)) { @@ -161,7 +161,7 @@ status_t NuPlayer::GenericSource::initFromDataSource() { Mutex::Autolock _l(mSourceLock); dataSource = mDataSource; } - if (!dataSource->sniff(&mimeType, &confidence, &dummy)) { + if (!dataSource->sniff(&mimeType, &confidence, &meta)) { return UNKNOWN_ERROR; } isWidevineStreaming = !strcasecmp( @@ -186,7 +186,7 @@ status_t NuPlayer::GenericSource::initFromDataSource() { #endif extractor = MediaExtractor::Create(mDataSource, mimeType.isEmpty() ? NULL : mimeType.string(), - mIsStreaming ? 0 : flags); + mIsStreaming ? 0 : flags, &meta); } if (extractor == NULL) { diff --git a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp index ee63a6e..c87208c 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp +++ b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp @@ -1488,16 +1488,22 @@ void NuPlayer::postScanSources() { void NuPlayer::tryOpenAudioSinkForOffload(const sp<AMessage> &format, bool hasVideo) { // Note: This is called early in NuPlayer to determine whether offloading // is possible; otherwise the decoders call the renderer openAudioSink directly. - + sp<MetaData> audioMeta = mSource->getFormatMeta(true /* audio */); + sp<AMessage> pcmFormat; + if (mOffloadDecodedPCM) { + sp<MetaData> pcm = AVNuUtils::get()->createPCMMetaFromSource(audioMeta); + audioMeta = pcm; + convertMetaDataToMessage(pcm, &pcmFormat); + } status_t err = mRenderer->openAudioSink( - format, true /* offloadOnly */, hasVideo, AUDIO_OUTPUT_FLAG_NONE, &mOffloadAudio, mSource->isStreaming()); + mOffloadDecodedPCM ? pcmFormat : format, + true /* offloadOnly */, hasVideo, AUDIO_OUTPUT_FLAG_NONE, + &mOffloadAudio, mSource->isStreaming()); if (err != OK) { // Any failure we turn off mOffloadAudio. mOffloadAudio = false; mOffloadDecodedPCM = false; } else if (mOffloadAudio) { - sp<MetaData> audioMeta = - mSource->getFormatMeta(true /* audio */); sendMetaDataToHal(mAudioSink, audioMeta); } } diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp index 6d26173..4286d3c 100644 --- a/media/libstagefright/ACodec.cpp +++ b/media/libstagefright/ACodec.cpp @@ -2966,13 +2966,11 @@ status_t ACodec::setupVideoDecoder( OMX_VIDEO_CODINGTYPE compressionFormat; status_t err = GetVideoCodingTypeFromMime(mime, &compressionFormat); - if (err != OK) { - err = FFMPEGSoftCodec::setVideoFormat( + err = FFMPEGSoftCodec::setVideoFormat(err, msg, mime, mOMX, mNode, mIsEncoder, &compressionFormat, mComponentName.c_str()); - if (err != OK) { - return err; - } + if (err != OK) { + return err; } err = setVideoPortFormatType( @@ -3121,14 +3119,12 @@ status_t ACodec::setupVideoEncoder(const char *mime, const sp<AMessage> &msg) { OMX_VIDEO_CODINGTYPE compressionFormat; err = GetVideoCodingTypeFromMime(mime, &compressionFormat); - if (err != OK) { - err = FFMPEGSoftCodec::setVideoFormat( + err = FFMPEGSoftCodec::setVideoFormat(err, msg, mime, mOMX, mNode, mIsEncoder, &compressionFormat, mComponentName.c_str()); - if (err != OK) { - ALOGE("Not a supported video mime type: %s", mime); - return err; - } + if (err != OK) { + ALOGE("Not a supported video mime type: %s", mime); + return err; } err = setVideoPortFormatType( diff --git a/media/libstagefright/DataSource.cpp b/media/libstagefright/DataSource.cpp index f32bb7e..b833f9e 100644 --- a/media/libstagefright/DataSource.cpp +++ b/media/libstagefright/DataSource.cpp @@ -131,18 +131,11 @@ status_t DataSource::getSize(off64_t *size) { Mutex DataSource::gSnifferMutex; List<DataSource::SnifferFunc> DataSource::gSniffers; -List<DataSource::SnifferFunc> DataSource::gExtraSniffers; bool DataSource::gSniffersRegistered = false; bool DataSource::sniff( String8 *mimeType, float *confidence, sp<AMessage> *meta) { - bool forceExtraSniffers = false; - - if (*confidence == 3.14f) { - // Magic value, as set by MediaExtractor when a video container looks incomplete - forceExtraSniffers = true; - } *mimeType = ""; *confidence = 0.0f; @@ -155,11 +148,18 @@ bool DataSource::sniff( } } + String8 newMimeType; + if (mimeType != NULL) { + newMimeType.setTo(*mimeType); + } + float newConfidence = *confidence; + for (List<SnifferFunc>::iterator it = gSniffers.begin(); it != gSniffers.end(); ++it) { - String8 newMimeType; - float newConfidence; - sp<AMessage> newMeta; + int64_t sniffStart = ALooper::GetNowUs(); + String8 newMimeType = *mimeType; + float newConfidence = *confidence; + sp<AMessage> newMeta = *meta; if ((*it)(this, &newMimeType, &newConfidence, &newMeta)) { if (newConfidence > *confidence) { *mimeType = newMimeType; @@ -167,23 +167,9 @@ bool DataSource::sniff( *meta = newMeta; } } - } - - /* Only do the deeper sniffers if the results are null or in doubt */ - if (mimeType->length() == 0 || *confidence < 0.21f || forceExtraSniffers) { - for (List<SnifferFunc>::iterator it = gExtraSniffers.begin(); - it != gExtraSniffers.end(); ++it) { - String8 newMimeType; - float newConfidence; - sp<AMessage> newMeta; - if ((*it)(this, &newMimeType, &newConfidence, &newMeta)) { - if (newConfidence > *confidence) { - *mimeType = newMimeType; - *confidence = newConfidence; - *meta = newMeta; - } - } - } + ALOGV("Sniffer (%p) completed in %.2f ms (mime=%s confidence=%.2f", + this, ((float)(ALooper::GetNowUs() - sniffStart) / 1000.0f), + mimeType == NULL ? NULL : (*mimeType).string(), *confidence); } return *confidence > 0.0; @@ -210,14 +196,7 @@ void DataSource::RegisterSnifferPlugin() { getExtractorPlugin(plugin); } if (plugin->sniff) { - for (List<SnifferFunc>::iterator it = gExtraSniffers.begin(); - it != gExtraSniffers.end(); ++it) { - if (*it == plugin->sniff) { - return; - } - } - - gExtraSniffers.push_back(plugin->sniff); + RegisterSniffer_l(plugin->sniff); } } @@ -232,9 +211,7 @@ void DataSource::RegisterDefaultSniffers() { RegisterSniffer_l(SniffMatroska); RegisterSniffer_l(SniffOgg); RegisterSniffer_l(SniffWAV); -#ifndef FLAC_OFFLOAD_ENABLED RegisterSniffer_l(SniffFLAC); -#endif RegisterSniffer_l(SniffAMR); RegisterSniffer_l(SniffMPEG2TS); RegisterSniffer_l(SniffMP3); @@ -250,6 +227,7 @@ void DataSource::RegisterDefaultSniffers() { && (!strcmp(value, "1") || !strcasecmp(value, "true"))) { RegisterSniffer_l(SniffDRM); } + gSniffersRegistered = true; } diff --git a/media/libstagefright/FFMPEGSoftCodec.cpp b/media/libstagefright/FFMPEGSoftCodec.cpp index 20c8359..26afd89 100644 --- a/media/libstagefright/FFMPEGSoftCodec.cpp +++ b/media/libstagefright/FFMPEGSoftCodec.cpp @@ -74,6 +74,7 @@ static const MetaKeyEntry MetaKeyTable[] { {kKeyWMVVersion , "wmv-version" , INT32}, {kKeyPCMFormat , "pcm-format" , INT32}, {kKeyDivXVersion , "divx-version" , INT32}, + {kKeyThumbnailTime , "thumbnail-time" , INT64}, }; const char* FFMPEGSoftCodec::getMsgKey(int key) { @@ -253,56 +254,63 @@ void FFMPEGSoftCodec::overrideComponentName( } status_t FFMPEGSoftCodec::setVideoFormat( + status_t status, const sp<AMessage> &msg, const char* mime, sp<IOMX> OMXhandle, IOMX::node_id nodeID, bool isEncoder, OMX_VIDEO_CODINGTYPE *compressionFormat, const char* componentName) { status_t err = OK; - if (isEncoder) { - ALOGE("Encoding not supported"); - err = BAD_VALUE; - - } else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_WMV, mime)) { - if (strncmp(componentName, "OMX.ffmpeg.", 11) == 0) { - err = setWMVFormat(msg, OMXhandle, nodeID); + //ALOGD("setVideoFormat: %s", msg->debugString(0).c_str()); + + /* status passed in is the result of the normal codec lookup */ + if (status != OK) { + + if (isEncoder) { + ALOGE("Encoding not supported"); + err = BAD_VALUE; + + } else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_WMV, mime)) { + if (strncmp(componentName, "OMX.ffmpeg.", 11) == 0) { + err = setWMVFormat(msg, OMXhandle, nodeID); + if (err != OK) { + ALOGE("setWMVFormat() failed (err = %d)", err); + } + } + *compressionFormat = OMX_VIDEO_CodingWMV; + } else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_RV, mime)) { + err = setRVFormat(msg, OMXhandle, nodeID); if (err != OK) { - ALOGE("setWMVFormat() failed (err = %d)", err); + ALOGE("setRVFormat() failed (err = %d)", err); + } else { + *compressionFormat = OMX_VIDEO_CodingRV; } - } - *compressionFormat = OMX_VIDEO_CodingWMV; - } else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_RV, mime)) { - err = setRVFormat(msg, OMXhandle, nodeID); - if (err != OK) { - ALOGE("setRVFormat() failed (err = %d)", err); - } else { - *compressionFormat = OMX_VIDEO_CodingRV; - } - } else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_VC1, mime)) { - *compressionFormat = (OMX_VIDEO_CODINGTYPE)OMX_VIDEO_CodingVC1; - } else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_FLV1, mime)) { - *compressionFormat = (OMX_VIDEO_CODINGTYPE)OMX_VIDEO_CodingFLV1; - } else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_DIVX, mime)) { - *compressionFormat = (OMX_VIDEO_CODINGTYPE)OMX_VIDEO_CodingDIVX; + } else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_VC1, mime)) { + *compressionFormat = (OMX_VIDEO_CODINGTYPE)OMX_VIDEO_CodingVC1; + } else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_FLV1, mime)) { + *compressionFormat = (OMX_VIDEO_CODINGTYPE)OMX_VIDEO_CodingFLV1; + } else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_DIVX, mime)) { + *compressionFormat = (OMX_VIDEO_CODINGTYPE)OMX_VIDEO_CodingDIVX; #ifdef QCOM_HARDWARE - // compressionFormat will be override later - } else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_DIVX4, mime)) { - *compressionFormat = (OMX_VIDEO_CODINGTYPE)OMX_VIDEO_CodingDIVX; - } else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_DIVX311, mime)) { - *compressionFormat = (OMX_VIDEO_CODINGTYPE)OMX_VIDEO_CodingDIVX; + // compressionFormat will be override later + } else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_DIVX4, mime)) { + *compressionFormat = (OMX_VIDEO_CODINGTYPE)OMX_VIDEO_CodingDIVX; + } else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_DIVX311, mime)) { + *compressionFormat = (OMX_VIDEO_CODINGTYPE)OMX_VIDEO_CodingDIVX; #endif - } else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_HEVC, mime)) { - *compressionFormat = (OMX_VIDEO_CODINGTYPE)OMX_VIDEO_CodingHEVC; - } else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_FFMPEG, mime)) { - ALOGV("Setting the OMX_VIDEO_PARAM_FFMPEGTYPE params"); - err = setFFmpegVideoFormat(msg, OMXhandle, nodeID); - if (err != OK) { - ALOGE("setFFmpegVideoFormat() failed (err = %d)", err); + } else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_HEVC, mime)) { + *compressionFormat = (OMX_VIDEO_CODINGTYPE)OMX_VIDEO_CodingHEVC; + } else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_FFMPEG, mime)) { + ALOGV("Setting the OMX_VIDEO_PARAM_FFMPEGTYPE params"); + err = setFFmpegVideoFormat(msg, OMXhandle, nodeID); + if (err != OK) { + ALOGE("setFFmpegVideoFormat() failed (err = %d)", err); + } else { + *compressionFormat = OMX_VIDEO_CodingAutoDetect; + } } else { - *compressionFormat = OMX_VIDEO_CodingAutoDetect; + err = BAD_TYPE; } - } else { - err = BAD_TYPE; } #ifdef QCOM_HARDWARE @@ -311,7 +319,7 @@ status_t FFMPEGSoftCodec::setVideoFormat( // from the CAF L release. It was unfortunately moved to a proprietary // blob and an architecture which is hellish for OEMs who wish to // customize the platform. - if (err != BAD_TYPE && (!strncmp(componentName, "OMX.qcom.", 9))) { + if (err == OK && (!strncmp(componentName, "OMX.qcom.", 9))) { status_t xerr = OK; @@ -343,13 +351,29 @@ status_t FFMPEGSoftCodec::setVideoFormat( // Enable timestamp reordering for mpeg4 and vc1 codec types, the AVI file // type, and hevc content in the ts container + AString container; + const char * containerStr = NULL; + if (msg->findString("file-format", &container)) { + containerStr = container.c_str(); + } + bool tsReorder = false; const char* roleVC1 = "OMX.qcom.video.decoder.vc1"; const char* roleMPEG4 = "OMX.qcom.video.decoder.mpeg4"; + const char* roleHEVC = "OMX.qcom.video.decoder.hevc"; if (!strncmp(componentName, roleVC1, strlen(roleVC1)) || !strncmp(componentName, roleMPEG4, strlen(roleMPEG4))) { // The codec requires timestamp reordering tsReorder = true; + } else if (containerStr != NULL) { + if (!strncmp(containerStr, MEDIA_MIMETYPE_CONTAINER_AVI, + strlen(MEDIA_MIMETYPE_CONTAINER_AVI))) { + tsReorder = true; + } else if (!strncmp(containerStr, MEDIA_MIMETYPE_CONTAINER_MPEG2TS, + strlen(MEDIA_MIMETYPE_CONTAINER_MPEG2TS)) || + !strncmp(componentName, roleHEVC, strlen(roleHEVC))) { + tsReorder = true; + } } if (tsReorder) { @@ -367,6 +391,32 @@ status_t FFMPEGSoftCodec::setVideoFormat( } } + // Enable Sync-frame decode mode for thumbnails + int32_t thumbnailMode = 0; + if (msg->findInt32("thumbnail-mode", &thumbnailMode) && + thumbnailMode > 0) { + ALOGV("Enabling thumbnail mode."); + QOMX_ENABLETYPE enableType; + OMX_INDEXTYPE indexType; + + status_t err = OMXhandle->getExtensionIndex( + nodeID, OMX_QCOM_INDEX_PARAM_VIDEO_SYNCFRAMEDECODINGMODE, + &indexType); + if (err != OK) { + ALOGW("Failed to get extension for SYNCFRAMEDECODINGMODE"); + } else { + + enableType.bEnable = OMX_TRUE; + err = OMXhandle->setParameter(nodeID,indexType, + (void *)&enableType, sizeof(enableType)); + if (err != OK) { + ALOGW("Failed to get extension for SYNCFRAMEDECODINGMODE"); + } else { + ALOGI("Thumbnail mode enabled."); + } + } + } + // MediaCodec clients can request decoder extradata by setting // "enable-extradata-<type>" in MediaFormat. // Following <type>s are supported: diff --git a/media/libstagefright/FLACExtractor.cpp b/media/libstagefright/FLACExtractor.cpp index 51a502d..55ce566 100644 --- a/media/libstagefright/FLACExtractor.cpp +++ b/media/libstagefright/FLACExtractor.cpp @@ -32,11 +32,6 @@ #include <media/stagefright/MediaSource.h> #include <media/stagefright/MediaBuffer.h> -#ifdef FLAC_OFFLOAD_ENABLED -#include "QCMediaDefs.h" -#include "QCMetaData.h" -#endif - #include <system/audio.h> namespace android { @@ -553,12 +548,6 @@ status_t FLACParser::init() mTrackMetadata->setInt64(kKeyDuration, (getTotalSamples() * 1000000LL) / getSampleRate()); mTrackMetadata->setInt32(kKeyBitsPerSample, getBitsPerSample()); -#ifdef FLAC_OFFLOAD_ENABLED - mTrackMetadata->setInt32(kKeyMinBlkSize, getMinBlockSize()); - mTrackMetadata->setInt32(kKeyMaxBlkSize, getMaxBlockSize()); - mTrackMetadata->setInt32(kKeyMinFrmSize, getMinFrameSize()); - mTrackMetadata->setInt32(kKeyMaxFrmSize, getMaxFrameSize()); -#endif } } else { ALOGE("missing STREAMINFO"); diff --git a/media/libstagefright/MediaExtractor.cpp b/media/libstagefright/MediaExtractor.cpp index cd0acfa..8c63de2 100644 --- a/media/libstagefright/MediaExtractor.cpp +++ b/media/libstagefright/MediaExtractor.cpp @@ -57,18 +57,14 @@ uint32_t MediaExtractor::flags() const { // static sp<MediaExtractor> MediaExtractor::Create( const sp<DataSource> &source, const char *mime, - const uint32_t flags) { - sp<AMessage> meta; + const uint32_t flags, const sp<AMessage> *prevMeta) { - bool secondPass = false; + sp<AMessage> meta; String8 tmp; -retry: - if (secondPass || mime == NULL) { + if (mime == NULL) { + int64_t sniffStart = ALooper::GetNowUs(); float confidence; - if (secondPass) { - confidence = 3.14f; - } if (!source->sniff(&tmp, &confidence, &meta)) { ALOGV("FAILED to autodetect media content."); @@ -76,8 +72,11 @@ retry: } mime = tmp.string(); - ALOGV("Autodetected media content as '%s' with confidence %.2f", - mime, confidence); + ALOGV("Autodetected media content as '%s' with confidence %.2f (%.2f ms)", + mime, confidence, + ((float)(ALooper::GetNowUs() - sniffStart) / 1000.0f)); + } else if (prevMeta != NULL) { + meta = *prevMeta; } bool isDrm = false; @@ -102,9 +101,10 @@ retry: } } - sp<MediaExtractor> ret = NULL; + sp<MediaExtractor> ret; AString extractorName; if ((ret = AVFactory::get()->createExtendedExtractor(source, mime, meta, flags)) != NULL) { + ALOGI("Using extended extractor"); } else if (meta.get() && meta->findString("extended-extractor-use", &extractorName) && sPlugin.create) { ALOGI("Use extended extractor for the special mime(%s) or codec", mime); @@ -117,10 +117,8 @@ retry: } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AMR_NB) || !strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AMR_WB)) { ret = new AMRExtractor(source); -#ifndef FLAC_OFFLOAD_ENABLED } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_FLAC)) { ret = new FLACExtractor(source); -#endif } else if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_WAV)) { ret = new WAVExtractor(source); } else if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_OGG)) { @@ -151,15 +149,6 @@ retry: } } - if (ret != NULL) { - - if (!secondPass && ( ret->countTracks() == 0 || - (!strncasecmp("video/", mime, 6) && ret->countTracks() < 2) ) ) { - secondPass = true; - goto retry; - } - } - return ret; } diff --git a/media/libstagefright/WAVExtractor.cpp b/media/libstagefright/WAVExtractor.cpp index b988f19..cc1d7ce 100644 --- a/media/libstagefright/WAVExtractor.cpp +++ b/media/libstagefright/WAVExtractor.cpp @@ -194,17 +194,17 @@ status_t WAVExtractor::init() { } mNumChannels = U16_LE_AT(&formatSpec[2]); + + if (mNumChannels < 1 || mNumChannels > 8) { + ALOGE("Unsupported number of channels (%d)", mNumChannels); + return ERROR_UNSUPPORTED; + } + if (mWaveFormat != WAVE_FORMAT_EXTENSIBLE) { - if (mNumChannels == 0) { - return ERROR_UNSUPPORTED; - } else if (mNumChannels != 1 && mNumChannels != 2) { + if (mNumChannels != 1 && mNumChannels != 2) { ALOGW("More than 2 channels (%d) in non-WAVE_EXT, unknown channel mask", mNumChannels); } - } else { - if (mNumChannels < 1 || mNumChannels > 8) { - return ERROR_UNSUPPORTED; - } } mSampleRate = U32_LE_AT(&formatSpec[4]); diff --git a/media/libstagefright/codecs/amrwbenc/src/c2t64fx.c b/media/libstagefright/codecs/amrwbenc/src/c2t64fx.c index 18698e2..519924d 100644 --- a/media/libstagefright/codecs/amrwbenc/src/c2t64fx.c +++ b/media/libstagefright/codecs/amrwbenc/src/c2t64fx.c @@ -80,6 +80,9 @@ void ACELP_2t64_fx( Isqrt_n(&s, &exp); s = L_shl(s, add1(exp, 5)); + if (s > INT_MAX - 0x8000) { + s = INT_MAX - 0x8000; + } k_cn = vo_round(s); /* set k_dn = 32..512 (ener_dn = 2^30..2^22) */ diff --git a/media/libstagefright/codecs/amrwbenc/src/c4t64fx.c b/media/libstagefright/codecs/amrwbenc/src/c4t64fx.c index 1ecc11f..6505e5d 100644 --- a/media/libstagefright/codecs/amrwbenc/src/c4t64fx.c +++ b/media/libstagefright/codecs/amrwbenc/src/c4t64fx.c @@ -628,8 +628,16 @@ void ACELP_4t64_fx( L_tmp = 0L; for(i = 0; i < L_SUBFR; i++) { + Word32 vecSq2; vec[i] = add1(add1(add1(*p0++, *p1++), *p2++), *p3++); - L_tmp += (vec[i] * vec[i]) << 1; + vecSq2 = (vec[i] * vec[i]) << 1; + if (vecSq2 > 0 && L_tmp > INT_MAX - vecSq2) { + L_tmp = INT_MAX; + } else if (vecSq2 < 0 && L_tmp < INT_MIN - vecSq2) { + L_tmp = INT_MIN; + } else { + L_tmp += vecSq2; + } } alp = ((L_tmp >> 3) + 0x8000) >> 16; diff --git a/media/libstagefright/codecs/amrwbenc/src/deemph.c b/media/libstagefright/codecs/amrwbenc/src/deemph.c index 0c49d6b..5eae6a7 100644 --- a/media/libstagefright/codecs/amrwbenc/src/deemph.c +++ b/media/libstagefright/codecs/amrwbenc/src/deemph.c @@ -68,8 +68,19 @@ void Deemph2( x[0] = (L_tmp + 0x8000)>>16; for (i = 1; i < L; i++) { + Word32 tmp; L_tmp = x[i] << 15; - L_tmp += (x[i - 1] * mu)<<1; + tmp = (x[i - 1] * mu)<<1; + if (tmp > 0 && L_tmp > INT_MAX - tmp) { + L_tmp = INT_MAX; + } else if (tmp < 0 && L_tmp < INT_MIN - tmp) { + L_tmp = INT_MIN; + } else { + L_tmp += tmp; + } + if (L_tmp > INT32_MAX - 0x8000) { + L_tmp = INT_MAX - 0x8000; + } x[i] = (L_tmp + 0x8000)>>16; } *mem = x[L - 1]; diff --git a/media/libstagefright/codecs/amrwbenc/src/preemph.c b/media/libstagefright/codecs/amrwbenc/src/preemph.c index c867bf7..6c26da5 100644 --- a/media/libstagefright/codecs/amrwbenc/src/preemph.c +++ b/media/libstagefright/codecs/amrwbenc/src/preemph.c @@ -69,14 +69,23 @@ void Preemph2( for (i = (Word16) (lg - 1); i > 0; i--) { L_tmp = L_deposit_h(x[i]); - L_tmp -= (x[i - 1] * mu)<<1; + L_tmp -= (x[i - 1] * mu)<<1; // only called with mu == 22282, so this won't overflow + if (L_tmp > INT32_MAX / 2) { + L_tmp = INT32_MAX / 2; + } L_tmp = (L_tmp << 1); x[i] = (L_tmp + 0x8000)>>16; } L_tmp = L_deposit_h(x[0]); L_tmp -= ((*mem) * mu)<<1; + if (L_tmp > INT32_MAX / 2) { + L_tmp = INT32_MAX / 2; + } L_tmp = (L_tmp << 1); + if (L_tmp > INT32_MAX - 0x8000) { + L_tmp = INT32_MAX - 0x8000; + } x[0] = (L_tmp + 0x8000)>>16; *mem = temp; |