From d07139e2e817a9b3ae9c87ba4e1e8d65d3e549da Mon Sep 17 00:00:00 2001 From: James Dong Date: Mon, 7 Jun 2010 14:41:41 -0700 Subject: Second part of speeding up video recording frame rate 1. Avoid copying the input recording frames to the encoder via OMX interface for TI video encoder This is a missing change for part one which help reduces the CPU load. 2. Release output buffers as early as possible. This is a little bit helpful, but not critical. TODO: We should save the underlying pointers allocated by the OMX component before we replace them and restore them before we call OMX_FreeBuffer()! Change-Id: Ib3a88978f4c3b1153808872eaa7ac4c265a811ff --- media/libstagefright/OMXCodec.cpp | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'media/libstagefright/OMXCodec.cpp') diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp index 66011ca..7c3df31 100644 --- a/media/libstagefright/OMXCodec.cpp +++ b/media/libstagefright/OMXCodec.cpp @@ -347,6 +347,9 @@ uint32_t OMXCodec::getComponentQuirks(const char *componentName) { quirks |= kRequiresAllocateBufferOnInputPorts; quirks |= kRequiresAllocateBufferOnOutputPorts; + if (!strncmp(componentName, "OMX.TI.video.encoder", 20)) { + quirks |= kAvoidMemcopyInputRecordingFrames; + } } if (!strcmp(componentName, "OMX.TI.Video.Decoder")) { @@ -574,7 +577,10 @@ status_t OMXCodec::configureCodec(const sp &meta) { CHECK(success); if (mIsEncoder) { - setVideoInputFormat(mMIME, width, height); + int32_t frameRate = 25; // XXX + int32_t bitRate = 3000000; // bit rate + //success = success && meta->findInt32(kKeySampleRate, &frameRate); + setVideoInputFormat(mMIME, width, height, frameRate, bitRate); } else { status_t err = setVideoOutputFormat( mMIME, width, height); @@ -739,7 +745,8 @@ static size_t getFrameSize( } void OMXCodec::setVideoInputFormat( - const char *mime, OMX_U32 width, OMX_U32 height) { + const char *mime, OMX_U32 width, OMX_U32 height, + OMX_U32 frameRate, OMX_U32 bitRate) { CODEC_LOGV("setVideoInputFormat width=%ld, height=%ld", width, height); OMX_VIDEO_CODINGTYPE compressionFormat = OMX_VIDEO_CodingUnused; @@ -769,6 +776,7 @@ void OMXCodec::setVideoInputFormat( CHECK_EQ(setVideoPortFormatType( kPortIndexInput, OMX_VIDEO_CodingUnused, colorFormat), OK); + InitOMXParams(&def); def.nPortIndex = kPortIndexInput; @@ -782,11 +790,10 @@ void OMXCodec::setVideoInputFormat( video_def->nFrameWidth = width; video_def->nFrameHeight = height; + video_def->xFramerate = (frameRate << 16); // Q16 format video_def->eCompressionFormat = OMX_VIDEO_CodingUnused; video_def->eColorFormat = colorFormat; - video_def->xFramerate = (24 << 16); // Q16 format - err = mOMX->setParameter( mNode, OMX_IndexParamPortDefinition, &def, sizeof(def)); CHECK_EQ(err, OK); @@ -806,7 +813,8 @@ void OMXCodec::setVideoInputFormat( video_def->nFrameWidth = width; video_def->nFrameHeight = height; - + video_def->xFramerate = (frameRate << 16); // Q16 format + video_def->nBitrate = bitRate; // Q16 format video_def->eCompressionFormat = compressionFormat; video_def->eColorFormat = OMX_COLOR_FormatUnused; @@ -928,6 +936,7 @@ status_t OMXCodec::setupAVCEncoderParameters() { h264type.nSliceHeaderSpacing = 0; h264type.nBFrames = 0; + h264type.nPFrames = 24; // XXX h264type.bUseHadamard = OMX_TRUE; h264type.nRefFrames = 1; h264type.nRefIdx10ActiveMinus1 = 0; @@ -960,7 +969,7 @@ status_t OMXCodec::setupAVCEncoderParameters() { CHECK_EQ(err, OK); bitrateType.eControlRate = OMX_Video_ControlRateVariable; - bitrateType.nTargetBitrate = 3000000; + bitrateType.nTargetBitrate = 3000000; // XXX err = mOMX->setParameter( mNode, OMX_IndexParamVideoBitrate, @@ -2049,9 +2058,15 @@ void OMXCodec::drainInputBuffer(BufferInfo *info) { break; } - memcpy((uint8_t *)info->mData + offset, - (const uint8_t *)srcBuffer->data() + srcBuffer->range_offset(), - srcBuffer->range_length()); + if (mIsEncoder && (mQuirks & kAvoidMemcopyInputRecordingFrames)) { + CHECK(mOMXLivesLocally && offset == 0); + OMX_BUFFERHEADERTYPE *header = (OMX_BUFFERHEADERTYPE *) info->mBuffer; + header->pBuffer = (OMX_U8 *) srcBuffer->data() + srcBuffer->range_offset(); + } else { + memcpy((uint8_t *)info->mData + offset, + (const uint8_t *)srcBuffer->data() + srcBuffer->range_offset(), + srcBuffer->range_length()); + } int64_t lastBufferTimeUs; CHECK(srcBuffer->meta_data()->findInt64(kKeyTime, &lastBufferTimeUs)); -- cgit v1.1