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

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

Merge "transcoding: separate pause&stop on transcoder<->scheduler interface"

parents 700f2c68 00feca22
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ void TranscodingJobScheduler::updateCurrentJob_l() {
        // the topJob now.
        if (!mResourceLost) {
            if (topJob->state == Job::NOT_STARTED) {
                mTranscoder->start(topJob->key.first, topJob->key.second);
                mTranscoder->start(topJob->key.first, topJob->key.second, curJob->request);
            } else if (topJob->state == Job::PAUSED) {
                mTranscoder->resume(topJob->key.first, topJob->key.second);
            }
@@ -257,9 +257,12 @@ bool TranscodingJobScheduler::cancel(ClientIdType clientId, JobIdType jobId) {
    }

    for (auto it = jobsToRemove.begin(); it != jobsToRemove.end(); ++it) {
        // If the job is running, pause it first.
        if (mJobMap[*it].state == Job::RUNNING) {
            mTranscoder->pause(clientId, jobId);
        // If the job has ever been started, stop it now.
        // Note that stop() is needed even if the job is currently paused. This instructs
        // the transcoder to discard any states for the job, otherwise the states may
        // never be discarded.
        if (mJobMap[*it].state != Job::NOT_STARTED) {
            mTranscoder->stop(it->first, it->second);
        }

        // Remove the job.
+5 −1
Original line number Diff line number Diff line
@@ -18,11 +18,13 @@
#define ANDROID_MEDIA_TRANSCODER_INTERFACE_H

#include <aidl/android/media/TranscodingErrorCode.h>
#include <aidl/android/media/TranscodingRequestParcel.h>
#include <media/TranscodingDefs.h>

namespace android {

using ::aidl::android::media::TranscodingErrorCode;
using ::aidl::android::media::TranscodingRequestParcel;
class TranscoderCallbackInterface;

// Interface for the scheduler to call the transcoder to take actions.
@@ -31,9 +33,11 @@ public:
    // TODO(chz): determine what parameters are needed here.
    // For now, always pass in clientId&jobId.
    virtual void setCallback(const std::shared_ptr<TranscoderCallbackInterface>& cb) = 0;
    virtual void start(ClientIdType clientId, JobIdType jobId) = 0;
    virtual void start(ClientIdType clientId, JobIdType jobId,
                       const TranscodingRequestParcel& request) = 0;
    virtual void pause(ClientIdType clientId, JobIdType jobId) = 0;
    virtual void resume(ClientIdType clientId, JobIdType jobId) = 0;
    virtual void stop(ClientIdType clientId, JobIdType jobId) = 0;

protected:
    virtual ~TranscoderInterface() = default;
+19 −4
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ using Status = ::ndk::ScopedAStatus;
using aidl::android::media::BnTranscodingClientCallback;
using aidl::android::media::IMediaTranscodingService;
using aidl::android::media::ITranscodingClient;
using aidl::android::media::TranscodingRequestParcel;

constexpr ClientIdType kClientId = 1000;
constexpr JobIdType kClientJobId = 0;
@@ -86,7 +87,8 @@ public:
    // TranscoderInterface
    void setCallback(const std::shared_ptr<TranscoderCallbackInterface>& /*cb*/) override {}

    void start(ClientIdType clientId, JobIdType jobId) override {
    void start(ClientIdType clientId, JobIdType jobId,
               const TranscodingRequestParcel& /*request*/) override {
        mEventQueue.push_back(Start(clientId, jobId));
    }
    void pause(ClientIdType clientId, JobIdType jobId) override {
@@ -95,6 +97,9 @@ public:
    void resume(ClientIdType clientId, JobIdType jobId) override {
        mEventQueue.push_back(Resume(clientId, jobId));
    }
    void stop(ClientIdType clientId, JobIdType jobId) override {
        mEventQueue.push_back(Stop(clientId, jobId));
    }

    void onFinished(ClientIdType clientId, JobIdType jobId) {
        mEventQueue.push_back(Finished(clientId, jobId));
@@ -112,7 +117,7 @@ public:
    }

    struct Event {
        enum { NoEvent, Start, Pause, Resume, Finished, Failed } type;
        enum { NoEvent, Start, Pause, Resume, Stop, Finished, Failed } type;
        ClientIdType clientId;
        JobIdType jobId;
    };
@@ -127,6 +132,7 @@ public:
    DECLARE_EVENT(Start);
    DECLARE_EVENT(Pause);
    DECLARE_EVENT(Resume);
    DECLARE_EVENT(Stop);
    DECLARE_EVENT(Finished);
    DECLARE_EVENT(Failed);

@@ -296,11 +302,20 @@ TEST_F(TranscodingJobSchedulerTest, TestCancelJob) {
    EXPECT_EQ(mTranscoder->popEvent(), TestTranscoder::NoEvent);

    // Cancel running real-time job JOB(0).
    // - Should be paused first then cancelled.
    // - Should be stopped first then cancelled.
    // - Should also start offline job JOB(2) because real-time queue is empty.
    EXPECT_TRUE(mScheduler->cancel(CLIENT(0), JOB(0)));
    EXPECT_EQ(mTranscoder->popEvent(), TestTranscoder::Pause(CLIENT(0), JOB(0)));
    EXPECT_EQ(mTranscoder->popEvent(), TestTranscoder::Stop(CLIENT(0), JOB(0)));
    EXPECT_EQ(mTranscoder->popEvent(), TestTranscoder::Start(CLIENT(0), JOB(3)));

    // Submit real-time job JOB(4), offline JOB(3) should pause and JOB(4) should start.
    mScheduler->submit(CLIENT(0), JOB(4), UID(0), mRealtimeRequest, mClientCallback0);
    EXPECT_EQ(mTranscoder->popEvent(), TestTranscoder::Pause(CLIENT(0), JOB(3)));
    EXPECT_EQ(mTranscoder->popEvent(), TestTranscoder::Start(CLIENT(0), JOB(4)));

    // Cancel paused JOB(3). JOB(3) should be stopped.
    EXPECT_TRUE(mScheduler->cancel(CLIENT(0), JOB(3)));
    EXPECT_EQ(mTranscoder->popEvent(), TestTranscoder::Stop(CLIENT(0), JOB(3)));
}

TEST_F(TranscodingJobSchedulerTest, TestFinishJob) {
+8 −3
Original line number Diff line number Diff line
@@ -47,7 +47,8 @@ void SimulatedTranscoder::setCallback(const std::shared_ptr<TranscoderCallbackIn
    mCallback = cb;
}

void SimulatedTranscoder::start(ClientIdType clientId, JobIdType jobId) {
void SimulatedTranscoder::start(ClientIdType clientId, JobIdType jobId,
                                const TranscodingRequestParcel& /*request*/) {
    queueEvent(Event::Start, clientId, jobId);
}

@@ -59,6 +60,10 @@ void SimulatedTranscoder::resume(ClientIdType clientId, JobIdType jobId) {
    queueEvent(Event::Resume, clientId, jobId);
}

void SimulatedTranscoder::stop(ClientIdType clientId, JobIdType jobId) {
    queueEvent(Event::Stop, clientId, jobId);
}

void SimulatedTranscoder::queueEvent(Event::Type type, ClientIdType clientId, JobIdType jobId) {
    ALOGV("%s: job {%lld, %d}: %s", __FUNCTION__, (long long)clientId, jobId, toString(type));

@@ -120,7 +125,7 @@ void SimulatedTranscoder::threadLoop() {
                if (event.type == Event::Start) {
                    remainingUs = std::chrono::microseconds(kJobDurationUs);
                }
            } else if (running && event.type == Event::Pause) {
            } else if (running && (event.type == Event::Pause || event.type == Event::Stop)) {
                running = false;
                remainingUs -= (std::chrono::system_clock::now() - lastRunningTime);
            } else {
+4 −2
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ namespace android {
class SimulatedTranscoder : public TranscoderInterface {
public:
    struct Event {
        enum Type { NoEvent, Start, Pause, Resume, Finished, Failed } type;
        enum Type { NoEvent, Start, Pause, Resume, Stop, Finished, Failed } type;
        ClientIdType clientId;
        JobIdType jobId;
    };
@@ -48,9 +48,11 @@ public:

    // TranscoderInterface
    void setCallback(const std::shared_ptr<TranscoderCallbackInterface>& cb) override;
    void start(ClientIdType clientId, JobIdType jobId) override;
    void start(ClientIdType clientId, JobIdType jobId,
               const TranscodingRequestParcel& request) override;
    void pause(ClientIdType clientId, JobIdType jobId) override;
    void resume(ClientIdType clientId, JobIdType jobId) override;
    void stop(ClientIdType clientId, JobIdType jobId) override;
    // ~TranscoderInterface

private: