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

Commit c042e020 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "transcoding: Make Mpeg4writer thread run with background priority in...

Merge "transcoding: Make Mpeg4writer thread run with background priority in transcoding usage." into sc-dev
parents c4e542c9 6aa1f4b2
Loading
Loading
Loading
Loading
+27 −2
Original line number Diff line number Diff line
@@ -522,6 +522,7 @@ void MPEG4Writer::initInternal(int fd, bool isFirstSession) {
    // Reset following variables for all the sessions and they will be
    // initialized in start(MetaData *param).
    mIsRealTimeRecording = true;
    mIsBackgroundMode = false;
    mUse4ByteNalLength = true;
    mOffset = 0;
    mMaxOffsetAppend = 0;
@@ -662,6 +663,14 @@ status_t MPEG4Writer::addSource(const sp<MediaSource> &source) {
    sp<MetaData> meta = source->getFormat();
    meta->findCString(kKeyMIMEType, &mime);


    // Background mode for media transcoding. If either audio or video track signal this is in
    // background mode, we will set all the threads to run in background priority.
    int32_t isBackgroundMode;
    if (meta && meta->findInt32(kKeyBackgroundMode, &isBackgroundMode)) {
        mIsBackgroundMode |= isBackgroundMode;
    }

    if (Track::getFourCCForMime(mime) == NULL) {
        ALOGE("Unsupported mime '%s'", mime);
        return ERROR_UNSUPPORTED;
@@ -2309,7 +2318,11 @@ status_t MPEG4Writer::setupAndStartLooper() {
    if (mLooper == nullptr) {
        mLooper = new ALooper;
        mLooper->setName("MP4WtrCtrlHlpLooper");
        if (mIsBackgroundMode) {
            err = mLooper->start(false, false, ANDROID_PRIORITY_BACKGROUND);
        } else {
            err = mLooper->start();
        }
        mReflector = new AHandlerReflector<MPEG4Writer>(this);
        mLooper->registerHandler(mReflector);
    }
@@ -2778,6 +2791,11 @@ void MPEG4Writer::threadFunc() {

    prctl(PR_SET_NAME, (unsigned long)"MPEG4Writer", 0, 0, 0);

    if (mIsBackgroundMode) {
        // Background priority for media transcoding.
        androidSetThreadPriority(0 /* tid (0 = current) */, ANDROID_PRIORITY_BACKGROUND);
    }

    Mutex::Autolock autoLock(mLock);
    while (!mDone) {
        Chunk chunk;
@@ -3379,6 +3397,9 @@ status_t MPEG4Writer::Track::threadEntry() {

    if (mOwner->isRealTimeRecording()) {
        androidSetThreadPriority(0, ANDROID_PRIORITY_AUDIO);
    } else if (mOwner->isBackgroundMode()) {
        // Background priority for media transcoding.
        androidSetThreadPriority(0 /* tid (0 = current) */, ANDROID_PRIORITY_BACKGROUND);
    }

    sp<MetaData> meta_data;
@@ -4076,6 +4097,10 @@ bool MPEG4Writer::isRealTimeRecording() const {
    return mIsRealTimeRecording;
}

bool MPEG4Writer::isBackgroundMode() const {
    return mIsBackgroundMode;
}

bool MPEG4Writer::useNalLengthFour() {
    return mUse4ByteNalLength;
}
+6 −0
Original line number Diff line number Diff line
@@ -1707,6 +1707,12 @@ status_t convertMessageToMetaData(const sp<AMessage> &msg, sp<MetaData> &meta) {
        meta->setInt32(kKeyIsSyncFrame, 1);
    }

    // Mode for media transcoding.
    int32_t isBackgroundMode;
    if (msg->findInt32("android._background-mode", &isBackgroundMode) && isBackgroundMode != 0) {
        meta->setInt32(isBackgroundMode, 1);
    }

    int32_t avgBitrate = 0;
    int32_t maxBitrate;
    if (msg->findInt32("bitrate", &avgBitrate) && avgBitrate > 0) {
+5 −0
Original line number Diff line number Diff line
@@ -97,6 +97,7 @@ private:
    sp<MetaData> mStartMeta;
    status_t mInitCheck;
    bool mIsRealTimeRecording;
    bool mIsBackgroundMode;
    bool mUse4ByteNalLength;
    bool mIsFileSizeLimitExplicitlyRequested;
    bool mPaused;
@@ -275,6 +276,10 @@ private:
    // By default, real time recording is on.
    bool isRealTimeRecording() const;

    // Return whether the writer is used in background mode for media
    // transcoding.
    bool isBackgroundMode() const;

    void lock();
    void unlock();

+2 −0
Original line number Diff line number Diff line
@@ -127,6 +127,8 @@ enum {
    kKeyTrackTimeStatus   = 'tktm',  // int64_t

    kKeyRealTimeRecording = 'rtrc',  // bool (int32_t)
    kKeyBackgroundMode = 'bkmd',  // bool (int32_t)

    kKeyNumBuffers        = 'nbbf',  // int32_t

    // Ogg files can be tagged to be automatically looping...