transcoding: Add more test configs for SimulatedTranscoder

Bug: 154734285
Bug: 145628554
Test: Unit test.
Change-Id: Id9d77e2d53c2dc582cc7034f158b5ab9eedcf586
diff --git a/media/libmediatranscoding/aidl/android/media/TranscodingTestConfig.aidl b/media/libmediatranscoding/aidl/android/media/TranscodingTestConfig.aidl
index 8d7091a..a564799 100644
--- a/media/libmediatranscoding/aidl/android/media/TranscodingTestConfig.aidl
+++ b/media/libmediatranscoding/aidl/android/media/TranscodingTestConfig.aidl
@@ -23,15 +23,21 @@
   */
 parcelable TranscodingTestConfig {
     /**
+     * Whether to use SimulatedTranscoder for testing. Note that SimulatedTranscoder does not send
+     * transcoding jobs to real MediaTranscoder.
+     */
+    boolean useSimulatedTranscoder = false;
+
+    /**
      * Passthrough mode used for testing. The transcoding service will assume the destination
      * path already contains the transcoding of the source file and return it to client directly.
      */
     boolean passThroughMode = false;
 
     /**
-     * Delay of processing the job in milliseconds. Used only for testing. This comebines with
-     * passThroughMode are used to simulate the transcoding latency in transcoding without involvign
-     * MediaTranscoder.
+     * Time of processing the job in milliseconds. Service will return the job result at least after
+     * processingTotalTimeMs from the time it starts to process the job. Note that if service uses
+     * real MediaTranscoder to do transcoding, the time spent on transcoding may be more than that.
      */
-    int processingDelayMs = 0;
+    int processingTotalTimeMs = 0;
 }
diff --git a/services/mediatranscoding/SimulatedTranscoder.cpp b/services/mediatranscoding/SimulatedTranscoder.cpp
index 1b68d5c..0a77fbe 100644
--- a/services/mediatranscoding/SimulatedTranscoder.cpp
+++ b/services/mediatranscoding/SimulatedTranscoder.cpp
@@ -48,7 +48,12 @@
 }
 
 void SimulatedTranscoder::start(ClientIdType clientId, JobIdType jobId,
-                                const TranscodingRequestParcel& /*request*/) {
+                                const TranscodingRequestParcel& request) {
+    if (request.testConfig.processingTotalTimeMs > 0) {
+        mJobProcessingTimeMs = request.testConfig.processingTotalTimeMs;
+    }
+    ALOGV("%s: job {%d}: processingTime: %lld", __FUNCTION__, jobId,
+          (long long)mJobProcessingTimeMs);
     queueEvent(Event::Start, clientId, jobId);
 }
 
@@ -123,7 +128,7 @@
                 lastRunningTime = std::chrono::system_clock::now();
                 lastRunningEvent = event;
                 if (event.type == Event::Start) {
-                    remainingUs = std::chrono::microseconds(kJobDurationUs);
+                    remainingUs = std::chrono::milliseconds(mJobProcessingTimeMs);
                 }
             } else if (running && (event.type == Event::Pause || event.type == Event::Stop)) {
                 running = false;
diff --git a/services/mediatranscoding/SimulatedTranscoder.h b/services/mediatranscoding/SimulatedTranscoder.h
index 646ba4e..9054b4c 100644
--- a/services/mediatranscoding/SimulatedTranscoder.h
+++ b/services/mediatranscoding/SimulatedTranscoder.h
@@ -29,6 +29,8 @@
  * SimulatedTranscoder is currently used to instantiate MediaTranscodingService
  * on service side for testing, so that we could actually test the IPC calls of
  * MediaTranscodingService to expose issues that's observable only over IPC.
+ * SimulatedTranscoder is used when useSimulatedTranscoder in TranscodingTestConfig
+ * is set to true.
  *
  * SimulatedTranscoder simulates job execution by reporting finish after kJobDurationUs.
  * Job lifecycle events are reported via progress updates with special progress
@@ -61,6 +63,9 @@
     std::condition_variable mCondition;
     std::list<Event> mQueue GUARDED_BY(mLock);
 
+    // Minimum time spent on transcode the video. This is used just for testing.
+    int64_t mJobProcessingTimeMs = kJobDurationUs / 1000;
+
     static const char* toString(Event::Type type);
     void queueEvent(Event::Type type, ClientIdType clientId, JobIdType jobId);
     void threadLoop();