Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 72425b11 authored by Hong Teng's avatar Hong Teng
Browse files

Fix for issue 5309336

    -add videoeditor maximum prefetch YUV frames in media_profiles.xml to
     limit the total memory usage.

Change-Id: I43c03fc626194d9ebbe8d914d9209a04bc085831
parent e20c2c17
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -3746,7 +3746,11 @@ M4OSA_ERR M4MCS_setOutputParams( M4MCS_Context pContext,
            /**
            * Set output video profile and level */
            pC->encodingVideoProfile = pC->InputFileProperties.uiVideoProfile;
            pC->encodingVideoLevel = pC->InputFileProperties.uiVideoLevel;
            /** Set the target video level, because input 3gp file may
             *  have wrong video level value (some encoders do not respect
             *  level restrictions like video resolution when content is created).
             **/
            pC->encodingVideoLevel = pParams->outputVideoLevel;

            // Clip's original width and height may not be
            // multiple of 16.
+4 −0
Original line number Diff line number Diff line
@@ -2587,6 +2587,10 @@ M4OSA_ERR M4xVSS_SendCommand( M4OSA_Context pContext,
                }
                else
                {
                    pParams->outputVideoProfile =
                        xVSS_context->pSettings->xVSS.outputVideoProfile;
                    pParams->outputVideoLevel =
                        xVSS_context->pSettings->xVSS.outputVideoLevel;
                    pParams->OutputVideoFormat = M4VIDEOEDITING_kNullVideo;
                    pParams->OutputVideoFrameRate =
                        M4VIDEOEDITING_k15_FPS; /* Must be set, otherwise, MCS returns an error */
+38 −7
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@
#include <media/stagefright/MetaData.h>
#include <media/stagefright/OMXClient.h>
#include <media/stagefright/OMXCodec.h>
#include <media/MediaProfiles.h>
#include "OMX_Video.h"

/********************
@@ -68,6 +69,7 @@ struct VideoEditorVideoEncoderSource : public MediaSource {
        virtual status_t read(MediaBuffer **buffer,
            const ReadOptions *options = NULL);
        virtual int32_t storeBuffer(MediaBuffer *buffer);
        virtual int32_t getNumberOfBuffersInQueue();

    protected:
        virtual ~VideoEditorVideoEncoderSource();
@@ -242,6 +244,10 @@ int32_t VideoEditorVideoEncoderSource::storeBuffer(MediaBuffer *buffer) {
    return mNbBuffer;
}

int32_t VideoEditorVideoEncoderSource::getNumberOfBuffersInQueue() {
    Mutex::Autolock autolock(mLock);
    return mNbBuffer;
}
/********************
 *      PULLER      *
 ********************/
@@ -257,6 +263,7 @@ public:
    MediaBuffer* getBufferBlocking();
    MediaBuffer* getBufferNonBlocking();
    void putBuffer(MediaBuffer* buffer);
    bool hasMediaSourceReturnedError();
private:
    static int acquireThreadStart(void* arg);
    void acquireThreadFunc();
@@ -277,6 +284,7 @@ private:
    bool mAskToStop;       // Asks the threads to stop
    bool mAcquireStopped;  // The acquire thread has stopped
    bool mReleaseStopped;  // The release thread has stopped
    status_t mSourceError; // Error returned by MediaSource read
};

VideoEditorVideoEncoderPuller::VideoEditorVideoEncoderPuller(
@@ -286,6 +294,7 @@ VideoEditorVideoEncoderPuller::VideoEditorVideoEncoderPuller(
    mAskToStop = false;
    mAcquireStopped = false;
    mReleaseStopped = false;
    mSourceError = OK;
    androidCreateThread(acquireThreadStart, this);
    androidCreateThread(releaseThreadStart, this);
}
@@ -294,6 +303,10 @@ VideoEditorVideoEncoderPuller::~VideoEditorVideoEncoderPuller() {
    stop();
}

bool VideoEditorVideoEncoderPuller::hasMediaSourceReturnedError() {
    Mutex::Autolock autolock(mLock);
    return ((mSourceError != OK) ? true : false);
}
void VideoEditorVideoEncoderPuller::start() {
    Mutex::Autolock autolock(mLock);
    mAskToStart = true;
@@ -381,6 +394,7 @@ void VideoEditorVideoEncoderPuller::acquireThreadFunc() {
        mLock.unlock();
        status_t result = mSource->read(&pBuffer, NULL);
        mLock.lock();
        mSourceError = result;
        if (result != OK) {
            break;
        }
@@ -464,6 +478,8 @@ typedef struct {
    int64_t                           mFirstOutputCts;
    int64_t                           mLastOutputCts;

    MediaProfiles *mVideoEditorProfile;
    int32_t mMaxPrefetchFrames;
} VideoEditorVideoEncoder_Context;

/********************
@@ -747,6 +763,10 @@ M4OSA_ERR VideoEditorVideoEncoder_open(M4ENCODER_Context pContext,

    // Context initialization
    pEncoderContext->mAccessUnit = pAU;
    pEncoderContext->mVideoEditorProfile = MediaProfiles::getInstance();
    pEncoderContext->mMaxPrefetchFrames =
        pEncoderContext->mVideoEditorProfile->getVideoEditorCapParamByName(
        "maxPrefetchYUVFrames");

    // Allocate & initialize the encoding parameters
    SAFE_MALLOC(pEncoderContext->mCodecParams, M4ENCODER_Params, 1,
@@ -1181,8 +1201,18 @@ M4OSA_ERR VideoEditorVideoEncoder_encode(M4ENCODER_Context pContext,
        MediaBuffer *outputBuffer =
                pEncoderContext->mPuller->getBufferNonBlocking();

        if (outputBuffer == NULL) break;

        if (outputBuffer == NULL) {
            int32_t YUVBufferNumber =
                    pEncoderContext->mEncoderSource->getNumberOfBuffersInQueue();
            /* Make sure that the configured maximum number of prefetch YUV frames is
             * not exceeded. This is to limit the amount of memory usage of video editor engine.
             * The value of maximum prefetch Yuv frames is defined in media_profiles.xml */
            if ((YUVBufferNumber < pEncoderContext->mMaxPrefetchFrames) ||
                (pEncoderContext->mPuller->hasMediaSourceReturnedError()
                    == true)) {
                break;
            }
        } else {
            // Provide the encoded AU to the writer
            err = VideoEditorVideoEncoder_processOutputBuffer(pEncoderContext,
                outputBuffer);
@@ -1190,6 +1220,7 @@ M4OSA_ERR VideoEditorVideoEncoder_encode(M4ENCODER_Context pContext,

            pEncoderContext->mPuller->putBuffer(outputBuffer);
        }
    }

cleanUp:
    if( M4NO_ERROR == err ) {