diff options
Diffstat (limited to 'media/libstagefright')
-rw-r--r-- | media/libstagefright/ACodec.cpp | 26 | ||||
-rw-r--r-- | media/libstagefright/Android.mk | 1 | ||||
-rw-r--r-- | media/libstagefright/AudioPlayer.cpp | 9 | ||||
-rw-r--r-- | media/libstagefright/DataSource.cpp | 2 | ||||
-rw-r--r-- | media/libstagefright/MediaExtractor.cpp | 3 | ||||
-rw-r--r-- | media/libstagefright/NuMediaExtractor.cpp | 169 | ||||
-rwxr-xr-x | media/libstagefright/OMXCodec.cpp | 11 | ||||
-rw-r--r-- | media/libstagefright/Utils.cpp | 188 | ||||
-rw-r--r-- | media/libstagefright/colorconversion/SoftwareRenderer.cpp | 18 |
9 files changed, 229 insertions, 198 deletions
diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp index 0de2d0a..1e00c5d 100644 --- a/media/libstagefright/ACodec.cpp +++ b/media/libstagefright/ACodec.cpp @@ -333,7 +333,11 @@ ACodec::ACodec() mNode(NULL), mSentFormat(false), mIsEncoder(false), - mShutdownInProgress(false) { + mShutdownInProgress(false), + mEncoderDelay(0), + mEncoderPadding(0), + mChannelMaskPresent(false), + mChannelMask(0) { mUninitializedState = new UninitializedState(this); mLoadedState = new LoadedState(this); mLoadedToIdleState = new LoadedToIdleState(this); @@ -892,10 +896,17 @@ status_t ACodec::configureCodec( if (!msg->findInt32("encoder-delay", &mEncoderDelay)) { mEncoderDelay = 0; } + if (!msg->findInt32("encoder-padding", &mEncoderPadding)) { mEncoderPadding = 0; } + if (msg->findInt32("channel-mask", &mChannelMask)) { + mChannelMaskPresent = true; + } else { + mChannelMaskPresent = false; + } + int32_t maxInputSize; if (msg->findInt32("max-input-size", &maxInputSize)) { err = setMinBufferSize(kPortIndexInput, (size_t)maxInputSize); @@ -1704,7 +1715,9 @@ status_t ACodec::setupAVCEncoderParameters(const sp<AMessage> &msg) { } // XXX - if (!strncmp(mComponentName.c_str(), "OMX.TI.DUCATI1", 14)) { + if (h264type.eProfile != OMX_VIDEO_AVCProfileBaseline) { + ALOGW("Use baseline profile instead of %d for AVC recording", + h264type.eProfile); h264type.eProfile = OMX_VIDEO_AVCProfileBaseline; } @@ -1739,10 +1752,6 @@ status_t ACodec::setupAVCEncoderParameters(const sp<AMessage> &msg) { h264type.bMBAFF = OMX_FALSE; h264type.eLoopFilterMode = OMX_VIDEO_AVCLoopFilterEnable; - if (!strcasecmp("OMX.Nvidia.h264.encoder", mComponentName.c_str())) { - h264type.eLevel = OMX_VIDEO_AVCLevelMax; - } - err = mOMX->setParameter( mNode, OMX_IndexParamVideoAvc, &h264type, sizeof(h264type)); @@ -2021,6 +2030,11 @@ void ACodec::sendFormatChange() { mSkipCutBuffer = new SkipCutBuffer(mEncoderDelay * frameSize, mEncoderPadding * frameSize); } + + if (mChannelMaskPresent) { + notify->setInt32("channel-mask", mChannelMask); + } + break; } diff --git a/media/libstagefright/Android.mk b/media/libstagefright/Android.mk index e2e5091..78a68fd 100644 --- a/media/libstagefright/Android.mk +++ b/media/libstagefright/Android.mk @@ -9,7 +9,6 @@ LOCAL_SRC_FILES:= \ AACWriter.cpp \ AMRExtractor.cpp \ AMRWriter.cpp \ - AVIExtractor.cpp \ AudioPlayer.cpp \ AudioSource.cpp \ AwesomePlayer.cpp \ diff --git a/media/libstagefright/AudioPlayer.cpp b/media/libstagefright/AudioPlayer.cpp index 8fb0d8d..ca49782 100644 --- a/media/libstagefright/AudioPlayer.cpp +++ b/media/libstagefright/AudioPlayer.cpp @@ -450,11 +450,8 @@ size_t AudioPlayer::fillBuffer(void *data, size_t size) { kKeyTime, &mPositionTimeMediaUs)); mPositionTimeRealUs = - -mLatencyUs + ((mNumFramesPlayed + size_done / mFrameSize) * 1000000) + ((mNumFramesPlayed + size_done / mFrameSize) * 1000000) / mSampleRate; - if (mPositionTimeRealUs < 0) { - mPositionTimeRealUs = 0; - } ALOGV("buffer->size() = %d, " "mPositionTimeMediaUs=%.2f mPositionTimeRealUs=%.2f", @@ -509,9 +506,7 @@ int64_t AudioPlayer::getRealTimeUs() { int64_t AudioPlayer::getRealTimeUsLocked() const { CHECK(mStarted); CHECK_NE(mSampleRate, 0); - int64_t t = -mLatencyUs + (mNumFramesPlayed * 1000000) / mSampleRate; - if (t < 0) return 0; - return t; + return -mLatencyUs + (mNumFramesPlayed * 1000000) / mSampleRate; } int64_t AudioPlayer::getMediaTimeUs() { diff --git a/media/libstagefright/DataSource.cpp b/media/libstagefright/DataSource.cpp index 3400724..c75f100 100644 --- a/media/libstagefright/DataSource.cpp +++ b/media/libstagefright/DataSource.cpp @@ -15,7 +15,6 @@ */ #include "include/AMRExtractor.h" -#include "include/AVIExtractor.h" #if CHROMIUM_AVAILABLE #include "include/DataUriSource.h" @@ -119,7 +118,6 @@ void DataSource::RegisterDefaultSniffers() { RegisterSniffer(SniffMPEG2TS); RegisterSniffer(SniffMP3); RegisterSniffer(SniffAAC); - RegisterSniffer(SniffAVI); RegisterSniffer(SniffMPEG2PS); RegisterSniffer(SniffWVM); diff --git a/media/libstagefright/MediaExtractor.cpp b/media/libstagefright/MediaExtractor.cpp index 2171492..c581525 100644 --- a/media/libstagefright/MediaExtractor.cpp +++ b/media/libstagefright/MediaExtractor.cpp @@ -19,7 +19,6 @@ #include <utils/Log.h> #include "include/AMRExtractor.h" -#include "include/AVIExtractor.h" #include "include/MP3Extractor.h" #include "include/MPEG4Extractor.h" #include "include/WAVExtractor.h" @@ -110,8 +109,6 @@ sp<MediaExtractor> MediaExtractor::Create( ret = new MatroskaExtractor(source); } else if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MPEG2TS)) { ret = new MPEG2TSExtractor(source); - } else if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_AVI)) { - ret = new AVIExtractor(source); } else if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_WVM)) { ret = new WVMExtractor(source); } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AAC_ADTS)) { diff --git a/media/libstagefright/NuMediaExtractor.cpp b/media/libstagefright/NuMediaExtractor.cpp index d6075cd..cfe4773 100644 --- a/media/libstagefright/NuMediaExtractor.cpp +++ b/media/libstagefright/NuMediaExtractor.cpp @@ -193,174 +193,7 @@ status_t NuMediaExtractor::getTrackFormat( } sp<MetaData> meta = mImpl->getTrackMetaData(index); - - const char *mime; - CHECK(meta->findCString(kKeyMIMEType, &mime)); - - sp<AMessage> msg = new AMessage; - msg->setString("mime", mime); - - int64_t durationUs; - if (meta->findInt64(kKeyDuration, &durationUs)) { - msg->setInt64("durationUs", durationUs); - } - - if (!strncasecmp("video/", mime, 6)) { - int32_t width, height; - CHECK(meta->findInt32(kKeyWidth, &width)); - CHECK(meta->findInt32(kKeyHeight, &height)); - - msg->setInt32("width", width); - msg->setInt32("height", height); - } else if (!strncasecmp("audio/", mime, 6)) { - int32_t numChannels, sampleRate; - CHECK(meta->findInt32(kKeyChannelCount, &numChannels)); - CHECK(meta->findInt32(kKeySampleRate, &sampleRate)); - - msg->setInt32("channel-count", numChannels); - msg->setInt32("sample-rate", sampleRate); - - int32_t delay = 0; - if (meta->findInt32(kKeyEncoderDelay, &delay)) { - msg->setInt32("encoder-delay", delay); - } - int32_t padding = 0; - if (meta->findInt32(kKeyEncoderPadding, &padding)) { - msg->setInt32("encoder-padding", padding); - } - - int32_t isADTS; - if (meta->findInt32(kKeyIsADTS, &isADTS)) { - msg->setInt32("is-adts", true); - } - } - - int32_t maxInputSize; - if (meta->findInt32(kKeyMaxInputSize, &maxInputSize)) { - msg->setInt32("max-input-size", maxInputSize); - } - - uint32_t type; - const void *data; - size_t size; - if (meta->findData(kKeyAVCC, &type, &data, &size)) { - // Parse the AVCDecoderConfigurationRecord - - const uint8_t *ptr = (const uint8_t *)data; - - CHECK(size >= 7); - CHECK_EQ((unsigned)ptr[0], 1u); // configurationVersion == 1 - uint8_t profile = ptr[1]; - uint8_t level = ptr[3]; - - // There is decodable content out there that fails the following - // assertion, let's be lenient for now... - // CHECK((ptr[4] >> 2) == 0x3f); // reserved - - size_t lengthSize = 1 + (ptr[4] & 3); - - // commented out check below as H264_QVGA_500_NO_AUDIO.3gp - // violates it... - // CHECK((ptr[5] >> 5) == 7); // reserved - - size_t numSeqParameterSets = ptr[5] & 31; - - ptr += 6; - size -= 6; - - sp<ABuffer> buffer = new ABuffer(1024); - buffer->setRange(0, 0); - - for (size_t i = 0; i < numSeqParameterSets; ++i) { - CHECK(size >= 2); - size_t length = U16_AT(ptr); - - ptr += 2; - size -= 2; - - CHECK(size >= length); - - memcpy(buffer->data() + buffer->size(), "\x00\x00\x00\x01", 4); - memcpy(buffer->data() + buffer->size() + 4, ptr, length); - buffer->setRange(0, buffer->size() + 4 + length); - - ptr += length; - size -= length; - } - - buffer->meta()->setInt32("csd", true); - buffer->meta()->setInt64("timeUs", 0); - - msg->setBuffer("csd-0", buffer); - - buffer = new ABuffer(1024); - buffer->setRange(0, 0); - - CHECK(size >= 1); - size_t numPictureParameterSets = *ptr; - ++ptr; - --size; - - for (size_t i = 0; i < numPictureParameterSets; ++i) { - CHECK(size >= 2); - size_t length = U16_AT(ptr); - - ptr += 2; - size -= 2; - - CHECK(size >= length); - - memcpy(buffer->data() + buffer->size(), "\x00\x00\x00\x01", 4); - memcpy(buffer->data() + buffer->size() + 4, ptr, length); - buffer->setRange(0, buffer->size() + 4 + length); - - ptr += length; - size -= length; - } - - buffer->meta()->setInt32("csd", true); - buffer->meta()->setInt64("timeUs", 0); - msg->setBuffer("csd-1", buffer); - } else if (meta->findData(kKeyESDS, &type, &data, &size)) { - ESDS esds((const char *)data, size); - CHECK_EQ(esds.InitCheck(), (status_t)OK); - - const void *codec_specific_data; - size_t codec_specific_data_size; - esds.getCodecSpecificInfo( - &codec_specific_data, &codec_specific_data_size); - - sp<ABuffer> buffer = new ABuffer(codec_specific_data_size); - - memcpy(buffer->data(), codec_specific_data, - codec_specific_data_size); - - buffer->meta()->setInt32("csd", true); - buffer->meta()->setInt64("timeUs", 0); - msg->setBuffer("csd-0", buffer); - } else if (meta->findData(kKeyVorbisInfo, &type, &data, &size)) { - sp<ABuffer> buffer = new ABuffer(size); - memcpy(buffer->data(), data, size); - - buffer->meta()->setInt32("csd", true); - buffer->meta()->setInt64("timeUs", 0); - msg->setBuffer("csd-0", buffer); - - if (!meta->findData(kKeyVorbisBooks, &type, &data, &size)) { - return -EINVAL; - } - - buffer = new ABuffer(size); - memcpy(buffer->data(), data, size); - - buffer->meta()->setInt32("csd", true); - buffer->meta()->setInt64("timeUs", 0); - msg->setBuffer("csd-1", buffer); - } - - *format = msg; - - return OK; + return convertMetaDataToMessage(meta, format); } status_t NuMediaExtractor::selectTrack(size_t index) { diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp index 56016a8..604d0e0 100755 --- a/media/libstagefright/OMXCodec.cpp +++ b/media/libstagefright/OMXCodec.cpp @@ -1123,9 +1123,10 @@ status_t OMXCodec::setupAVCEncoderParameters(const sp<MetaData>& meta) { h264type.eProfile = static_cast<OMX_VIDEO_AVCPROFILETYPE>(profileLevel.mProfile); h264type.eLevel = static_cast<OMX_VIDEO_AVCLEVELTYPE>(profileLevel.mLevel); - // FIXME: - // Remove the workaround after the work in done. - if (!strncmp(mComponentName, "OMX.TI.DUCATI1", 14)) { + // XXX + if (h264type.eProfile != OMX_VIDEO_AVCProfileBaseline) { + ALOGW("Use baseline profile instead of %d for AVC recording", + h264type.eProfile); h264type.eProfile = OMX_VIDEO_AVCProfileBaseline; } @@ -1160,10 +1161,6 @@ status_t OMXCodec::setupAVCEncoderParameters(const sp<MetaData>& meta) { h264type.bMBAFF = OMX_FALSE; h264type.eLoopFilterMode = OMX_VIDEO_AVCLoopFilterEnable; - if (!strcasecmp("OMX.Nvidia.h264.encoder", mComponentName)) { - h264type.eLevel = OMX_VIDEO_AVCLevelMax; - } - err = mOMX->setParameter( mNode, OMX_IndexParamVideoAvc, &h264type, sizeof(h264type)); CHECK_EQ(err, (status_t)OK); diff --git a/media/libstagefright/Utils.cpp b/media/libstagefright/Utils.cpp index c563ce6..2a16f66 100644 --- a/media/libstagefright/Utils.cpp +++ b/media/libstagefright/Utils.cpp @@ -14,8 +14,18 @@ * limitations under the License. */ +//#define LOG_NDEBUG 0 +#define LOG_TAG "Utils" +#include <utils/Log.h> + +#include "include/ESDS.h" + #include <arpa/inet.h> +#include <media/stagefright/foundation/ABuffer.h> +#include <media/stagefright/foundation/ADebug.h> +#include <media/stagefright/foundation/AMessage.h> +#include <media/stagefright/MetaData.h> #include <media/stagefright/Utils.h> namespace android { @@ -53,5 +63,183 @@ uint64_t hton64(uint64_t x) { return ((uint64_t)htonl(x & 0xffffffff) << 32) | htonl(x >> 32); } +status_t convertMetaDataToMessage( + const sp<MetaData> &meta, sp<AMessage> *format) { + format->clear(); + + const char *mime; + CHECK(meta->findCString(kKeyMIMEType, &mime)); + + sp<AMessage> msg = new AMessage; + msg->setString("mime", mime); + + int64_t durationUs; + if (meta->findInt64(kKeyDuration, &durationUs)) { + msg->setInt64("durationUs", durationUs); + } + + if (!strncasecmp("video/", mime, 6)) { + int32_t width, height; + CHECK(meta->findInt32(kKeyWidth, &width)); + CHECK(meta->findInt32(kKeyHeight, &height)); + + msg->setInt32("width", width); + msg->setInt32("height", height); + } else if (!strncasecmp("audio/", mime, 6)) { + int32_t numChannels, sampleRate; + CHECK(meta->findInt32(kKeyChannelCount, &numChannels)); + CHECK(meta->findInt32(kKeySampleRate, &sampleRate)); + + msg->setInt32("channel-count", numChannels); + msg->setInt32("sample-rate", sampleRate); + + int32_t channelMask; + if (meta->findInt32(kKeyChannelMask, &channelMask)) { + msg->setInt32("channel-mask", channelMask); + } + + int32_t delay = 0; + if (meta->findInt32(kKeyEncoderDelay, &delay)) { + msg->setInt32("encoder-delay", delay); + } + int32_t padding = 0; + if (meta->findInt32(kKeyEncoderPadding, &padding)) { + msg->setInt32("encoder-padding", padding); + } + + int32_t isADTS; + if (meta->findInt32(kKeyIsADTS, &isADTS)) { + msg->setInt32("is-adts", true); + } + } + + int32_t maxInputSize; + if (meta->findInt32(kKeyMaxInputSize, &maxInputSize)) { + msg->setInt32("max-input-size", maxInputSize); + } + + uint32_t type; + const void *data; + size_t size; + if (meta->findData(kKeyAVCC, &type, &data, &size)) { + // Parse the AVCDecoderConfigurationRecord + + const uint8_t *ptr = (const uint8_t *)data; + + CHECK(size >= 7); + CHECK_EQ((unsigned)ptr[0], 1u); // configurationVersion == 1 + uint8_t profile = ptr[1]; + uint8_t level = ptr[3]; + + // There is decodable content out there that fails the following + // assertion, let's be lenient for now... + // CHECK((ptr[4] >> 2) == 0x3f); // reserved + + size_t lengthSize = 1 + (ptr[4] & 3); + + // commented out check below as H264_QVGA_500_NO_AUDIO.3gp + // violates it... + // CHECK((ptr[5] >> 5) == 7); // reserved + + size_t numSeqParameterSets = ptr[5] & 31; + + ptr += 6; + size -= 6; + + sp<ABuffer> buffer = new ABuffer(1024); + buffer->setRange(0, 0); + + for (size_t i = 0; i < numSeqParameterSets; ++i) { + CHECK(size >= 2); + size_t length = U16_AT(ptr); + + ptr += 2; + size -= 2; + + CHECK(size >= length); + + memcpy(buffer->data() + buffer->size(), "\x00\x00\x00\x01", 4); + memcpy(buffer->data() + buffer->size() + 4, ptr, length); + buffer->setRange(0, buffer->size() + 4 + length); + + ptr += length; + size -= length; + } + + buffer->meta()->setInt32("csd", true); + buffer->meta()->setInt64("timeUs", 0); + + msg->setBuffer("csd-0", buffer); + + buffer = new ABuffer(1024); + buffer->setRange(0, 0); + + CHECK(size >= 1); + size_t numPictureParameterSets = *ptr; + ++ptr; + --size; + + for (size_t i = 0; i < numPictureParameterSets; ++i) { + CHECK(size >= 2); + size_t length = U16_AT(ptr); + + ptr += 2; + size -= 2; + + CHECK(size >= length); + + memcpy(buffer->data() + buffer->size(), "\x00\x00\x00\x01", 4); + memcpy(buffer->data() + buffer->size() + 4, ptr, length); + buffer->setRange(0, buffer->size() + 4 + length); + + ptr += length; + size -= length; + } + + buffer->meta()->setInt32("csd", true); + buffer->meta()->setInt64("timeUs", 0); + msg->setBuffer("csd-1", buffer); + } else if (meta->findData(kKeyESDS, &type, &data, &size)) { + ESDS esds((const char *)data, size); + CHECK_EQ(esds.InitCheck(), (status_t)OK); + + const void *codec_specific_data; + size_t codec_specific_data_size; + esds.getCodecSpecificInfo( + &codec_specific_data, &codec_specific_data_size); + + sp<ABuffer> buffer = new ABuffer(codec_specific_data_size); + + memcpy(buffer->data(), codec_specific_data, + codec_specific_data_size); + + buffer->meta()->setInt32("csd", true); + buffer->meta()->setInt64("timeUs", 0); + msg->setBuffer("csd-0", buffer); + } else if (meta->findData(kKeyVorbisInfo, &type, &data, &size)) { + sp<ABuffer> buffer = new ABuffer(size); + memcpy(buffer->data(), data, size); + + buffer->meta()->setInt32("csd", true); + buffer->meta()->setInt64("timeUs", 0); + msg->setBuffer("csd-0", buffer); + + if (!meta->findData(kKeyVorbisBooks, &type, &data, &size)) { + return -EINVAL; + } + + buffer = new ABuffer(size); + memcpy(buffer->data(), data, size); + + buffer->meta()->setInt32("csd", true); + buffer->meta()->setInt64("timeUs", 0); + msg->setBuffer("csd-1", buffer); + } + + *format = msg; + + return OK; +} + } // namespace android diff --git a/media/libstagefright/colorconversion/SoftwareRenderer.cpp b/media/libstagefright/colorconversion/SoftwareRenderer.cpp index 059d6b9..8673bad 100644 --- a/media/libstagefright/colorconversion/SoftwareRenderer.cpp +++ b/media/libstagefright/colorconversion/SoftwareRenderer.cpp @@ -19,6 +19,7 @@ #include "../include/SoftwareRenderer.h" +#include <cutils/properties.h> // for property_get #include <media/stagefright/foundation/ADebug.h> #include <media/stagefright/MetaData.h> #include <system/window.h> @@ -27,6 +28,11 @@ namespace android { +static bool runningInEmulator() { + char prop[PROPERTY_VALUE_MAX]; + return (property_get("ro.kernel.qemu", prop, NULL) > 0); +} + SoftwareRenderer::SoftwareRenderer( const sp<ANativeWindow> &nativeWindow, const sp<MetaData> &meta) : mConverter(NULL), @@ -62,10 +68,14 @@ SoftwareRenderer::SoftwareRenderer( case OMX_COLOR_FormatYUV420Planar: case OMX_TI_COLOR_FormatYUV420PackedSemiPlanar: { - halFormat = HAL_PIXEL_FORMAT_YV12; - bufWidth = (mCropWidth + 1) & ~1; - bufHeight = (mCropHeight + 1) & ~1; - break; + if (!runningInEmulator()) { + halFormat = HAL_PIXEL_FORMAT_YV12; + bufWidth = (mCropWidth + 1) & ~1; + bufHeight = (mCropHeight + 1) & ~1; + break; + } + + // fall through. } default: |