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

Commit 98b8a370 authored by Chong Zhang's avatar Chong Zhang
Browse files

transcoding: post progress update to client

bug: 160277443
bug: 154733526
test: unit tests
Change-Id: I04cd198d5fb1e83b1d256e4968fb3685c16b7a55
parent b035849c
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -103,6 +103,8 @@ const char* TranscoderWrapper::toString(Event::Type type) {
        return "Finish";
    case Event::Error:
        return "Error";
    case Event::Progress:
        return "Progress";
    default:
        break;
    }
@@ -132,8 +134,10 @@ public:

    virtual void onProgressUpdate(const MediaTranscoder* transcoder __unused,
                                  int32_t progress) override {
        ALOGV("%s: job {%lld, %d}, progress %d", __FUNCTION__, (long long)mClientId, mJobId,
              progress);
        auto owner = mOwner.lock();
        if (owner != nullptr) {
            owner->onProgress(mClientId, mJobId, progress);
        }
    }

    virtual void onCodecResourceLost(const MediaTranscoder* transcoder __unused,
@@ -261,6 +265,15 @@ void TranscoderWrapper::onError(ClientIdType clientId, JobIdType jobId,
    });
}

void TranscoderWrapper::onProgress(ClientIdType clientId, JobIdType jobId, int32_t progress) {
    queueEvent(Event::Progress, clientId, jobId, [=] {
        auto callback = mCallback.lock();
        if (callback != nullptr) {
            callback->onProgressUpdate(clientId, jobId, progress);
        }
    });
}

TranscodingErrorCode TranscoderWrapper::setupTranscoder(
        ClientIdType clientId, JobIdType jobId, const TranscodingRequestParcel& request,
        const std::shared_ptr<ITranscodingClientCallback>& clientCb,
+2 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ public:
private:
    class CallbackImpl;
    struct Event {
        enum Type { NoEvent, Start, Pause, Resume, Stop, Finish, Error } type;
        enum Type { NoEvent, Start, Pause, Resume, Stop, Finish, Error, Progress } type;
        ClientIdType clientId;
        JobIdType jobId;
        std::function<void()> runnable;
@@ -71,6 +71,7 @@ private:
    static const char* toString(Event::Type type);
    void onFinish(ClientIdType clientId, JobIdType jobId);
    void onError(ClientIdType clientId, JobIdType jobId, TranscodingErrorCode error);
    void onProgress(ClientIdType clientId, JobIdType jobId, int32_t progress);

    TranscodingErrorCode handleStart(ClientIdType clientId, JobIdType jobId,
                                     const TranscodingRequestParcel& request,
+16 −1
Original line number Diff line number Diff line
@@ -180,6 +180,18 @@ struct EventTracker {
        mCondition.notify_one();
    }

    void updateProgress(int progress) {
        std::unique_lock lock(mLock);
        mLastProgress = progress;
        mUpdateCount++;
    }

    int getUpdateCount(int *lastProgress) {
        std::unique_lock lock(mLock);
        *lastProgress = mLastProgress;
        return mUpdateCount;
    }

    TranscodingErrorCode getLastError() {
        std::unique_lock lock(mLock);
        return mLastErr;
@@ -191,6 +203,8 @@ private:
    Event mPoppedEvent;
    std::list<Event> mEventQueue;
    TranscodingErrorCode mLastErr;
    int mUpdateCount = 0;
    int mLastProgress = -1;
};

// Operators for GTest macros.
@@ -266,7 +280,8 @@ struct TestClientCallback : public BnTranscodingClientCallback, public EventTrac
        return Status::ok();
    }

    Status onProgressUpdate(int32_t /* in_jobId */, int32_t /* in_progress */) override {
    Status onProgressUpdate(int32_t /* in_jobId */, int32_t in_progress) override {
        updateProgress(in_progress);
        return Status::ok();
    }

+23 −0
Original line number Diff line number Diff line
@@ -100,6 +100,29 @@ TEST_F(MediaTranscodingServiceRealTest, TestTranscodeVideo) {
    unregisterMultipleClients();
}

TEST_F(MediaTranscodingServiceRealTest, TestTranscodeVideoProgress) {
    registerMultipleClients();

    const char* dstPath = OUTPATH(TestTranscodeVideoProgress);
    deleteFile(dstPath);

    // Submit one job.
    EXPECT_TRUE(
            submit(mClient1, 0, kLongSrcPath, dstPath, TranscodingJobPriority::kNormal, kBitRate));

    // Wait for job to finish.
    EXPECT_EQ(mClientCallback1->pop(kPaddingUs), EventTracker::Start(CLIENT(1), 0));
    EXPECT_EQ(mClientCallback1->pop(kJobWithPaddingUs), EventTracker::Finished(CLIENT(1), 0));

    // Check the progress update messages are received. For this clip (around ~15 second long),
    // expect at least 10 updates, and the last update should be 100.
    int lastProgress;
    EXPECT_GE(mClientCallback1->getUpdateCount(&lastProgress), 10);
    EXPECT_EQ(lastProgress, 100);

    unregisterMultipleClients();
}

/*
 * Test cancel immediately after start.
 */