blob: bfc1f3b18804b7201c9784b71cbe1b8f18c091bd [file] [log] [blame]
Linus Nilssoncab39d82020-05-14 16:32:21 -07001/*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17// Unit Test for MediaTranscoder
18
19// #define LOG_NDEBUG 0
20#define LOG_TAG "MediaTranscoderTests"
21
22#include <android-base/logging.h>
Linus Nilsson93cf9132020-09-24 12:12:48 -070023#include <android/binder_process.h>
Chong Zhangb55c5452020-06-26 14:32:12 -070024#include <fcntl.h>
Linus Nilssoncab39d82020-05-14 16:32:21 -070025#include <gtest/gtest.h>
Chong Zhang5855ee52020-06-22 11:41:25 -070026#include <media/MediaSampleReaderNDK.h>
Linus Nilssoncab39d82020-05-14 16:32:21 -070027#include <media/MediaTranscoder.h>
Chong Zhang5855ee52020-06-22 11:41:25 -070028#include <media/NdkCommon.h>
Linus Nilssoncab39d82020-05-14 16:32:21 -070029
30namespace android {
31
Chong Zhang5855ee52020-06-22 11:41:25 -070032#define DEFINE_FORMAT_VALUE_EQUAL_FUNC(_type, _typeName) \
33 static bool equal##_typeName(const char* key, AMediaFormat* src, AMediaFormat* dst) { \
34 _type srcVal, dstVal; \
35 bool srcPresent = AMediaFormat_get##_typeName(src, key, &srcVal); \
36 bool dstPresent = AMediaFormat_get##_typeName(dst, key, &dstVal); \
37 return (srcPresent == dstPresent) && (!srcPresent || (srcVal == dstVal)); \
38 }
39
40DEFINE_FORMAT_VALUE_EQUAL_FUNC(int64_t, Int64);
41DEFINE_FORMAT_VALUE_EQUAL_FUNC(int32_t, Int32);
42
43struct FormatVerifierEntry {
44 const char* key;
Chong Zhangd6e4aec2020-06-22 14:13:07 -070045 std::function<bool(const char*, AMediaFormat*, AMediaFormat*)> equal;
Chong Zhang5855ee52020-06-22 11:41:25 -070046};
47
48static const FormatVerifierEntry kFieldsToPreserve[] = {
49 {AMEDIAFORMAT_KEY_DURATION, equalInt64}, {AMEDIAFORMAT_KEY_WIDTH, equalInt32},
50 {AMEDIAFORMAT_KEY_HEIGHT, equalInt32}, {AMEDIAFORMAT_KEY_FRAME_RATE, equalInt32},
51 {AMEDIAFORMAT_KEY_FRAME_COUNT, equalInt32}, {AMEDIAFORMAT_KEY_DISPLAY_WIDTH, equalInt32},
52 {AMEDIAFORMAT_KEY_DISPLAY_HEIGHT, equalInt32}, {AMEDIAFORMAT_KEY_SAR_WIDTH, equalInt32},
53 {AMEDIAFORMAT_KEY_SAR_HEIGHT, equalInt32}, {AMEDIAFORMAT_KEY_ROTATION, equalInt32},
54};
55
Linus Nilssoncab39d82020-05-14 16:32:21 -070056class TestCallbacks : public MediaTranscoder::CallbackInterface {
57public:
58 virtual void onFinished(const MediaTranscoder* transcoder __unused) override {
59 std::unique_lock<std::mutex> lock(mMutex);
60 EXPECT_FALSE(mFinished);
61 mFinished = true;
62 mCondition.notify_all();
63 }
64
65 virtual void onError(const MediaTranscoder* transcoder __unused,
66 media_status_t error) override {
67 std::unique_lock<std::mutex> lock(mMutex);
68 EXPECT_NE(error, AMEDIA_OK);
69 EXPECT_FALSE(mFinished);
70 mFinished = true;
71 mStatus = error;
72 mCondition.notify_all();
73 }
74
75 virtual void onProgressUpdate(const MediaTranscoder* transcoder __unused,
Linus Nilsson93cf9132020-09-24 12:12:48 -070076 int32_t progress) override {
77 std::unique_lock<std::mutex> lock(mMutex);
78 if (progress > 0 && !mProgressMade) {
79 mProgressMade = true;
80 mCondition.notify_all();
81 }
82 }
Linus Nilssoncab39d82020-05-14 16:32:21 -070083
84 virtual void onCodecResourceLost(const MediaTranscoder* transcoder __unused,
Chong Zhange4e088f2020-10-21 19:10:42 -070085 const std::shared_ptr<ndk::ScopedAParcel>& pausedState
Linus Nilssoncab39d82020-05-14 16:32:21 -070086 __unused) override {}
87
88 void waitForTranscodingFinished() {
89 std::unique_lock<std::mutex> lock(mMutex);
90 while (!mFinished) {
91 mCondition.wait(lock);
92 }
93 }
94
Linus Nilsson93cf9132020-09-24 12:12:48 -070095 void waitForProgressMade() {
96 std::unique_lock<std::mutex> lock(mMutex);
97 while (!mProgressMade && !mFinished) {
98 mCondition.wait(lock);
99 }
100 }
Linus Nilssoncab39d82020-05-14 16:32:21 -0700101 media_status_t mStatus = AMEDIA_OK;
Linus Nilssonfdb3e332020-09-18 17:11:41 -0700102 bool mFinished = false;
Linus Nilssoncab39d82020-05-14 16:32:21 -0700103
104private:
105 std::mutex mMutex;
106 std::condition_variable mCondition;
Linus Nilsson93cf9132020-09-24 12:12:48 -0700107 bool mProgressMade = false;
Linus Nilssoncab39d82020-05-14 16:32:21 -0700108};
109
Chong Zhang308e91f2020-06-10 15:27:56 -0700110// Write-only, create file if non-existent, don't overwrite existing file.
111static constexpr int kOpenFlags = O_WRONLY | O_CREAT | O_EXCL;
112// User R+W permission.
113static constexpr int kFileMode = S_IRUSR | S_IWUSR;
Linus Nilssoncab39d82020-05-14 16:32:21 -0700114
115class MediaTranscoderTests : public ::testing::Test {
116public:
117 MediaTranscoderTests() { LOG(DEBUG) << "MediaTranscoderTests created"; }
118 ~MediaTranscoderTests() { LOG(DEBUG) << "MediaTranscoderTests destroyed"; }
119
120 void SetUp() override {
121 LOG(DEBUG) << "MediaTranscoderTests set up";
122 mCallbacks = std::make_shared<TestCallbacks>();
Linus Nilsson93cf9132020-09-24 12:12:48 -0700123 ABinderProcess_startThreadPool();
Linus Nilssoncab39d82020-05-14 16:32:21 -0700124 }
125
126 void TearDown() override {
127 LOG(DEBUG) << "MediaTranscoderTests tear down";
128 mCallbacks.reset();
129 }
130
131 void deleteFile(const char* path) { unlink(path); }
132
Linus Nilsson800793f2020-07-31 16:16:38 -0700133 float getFileSizeDiffPercent(const char* path1, const char* path2, bool absolute = false) {
134 struct stat s1, s2;
135 EXPECT_EQ(stat(path1, &s1), 0);
136 EXPECT_EQ(stat(path2, &s2), 0);
137
138 int64_t diff = s2.st_size - s1.st_size;
139 if (absolute && diff < 0) diff = -diff;
140
141 return (float)diff * 100.0f / s1.st_size;
142 }
143
Linus Nilsson93cf9132020-09-24 12:12:48 -0700144 typedef enum {
145 kRunToCompletion,
146 kCancelAfterProgress,
147 kCancelAfterStart,
Linus Nilssonfdb3e332020-09-18 17:11:41 -0700148 kPauseAfterProgress,
149 kPauseAfterStart,
Linus Nilsson93cf9132020-09-24 12:12:48 -0700150 } TranscodeExecutionControl;
151
Linus Nilssoncab39d82020-05-14 16:32:21 -0700152 using FormatConfigurationCallback = std::function<AMediaFormat*(AMediaFormat*)>;
Chong Zhang5855ee52020-06-22 11:41:25 -0700153 media_status_t transcodeHelper(const char* srcPath, const char* destPath,
Linus Nilsson93cf9132020-09-24 12:12:48 -0700154 FormatConfigurationCallback formatCallback,
155 TranscodeExecutionControl executionControl = kRunToCompletion) {
Chong Zhangbbb4eac2020-11-18 11:12:06 -0800156 auto transcoder = MediaTranscoder::create(mCallbacks);
Linus Nilssoncab39d82020-05-14 16:32:21 -0700157 EXPECT_NE(transcoder, nullptr);
158
Chong Zhang5855ee52020-06-22 11:41:25 -0700159 const int srcFd = open(srcPath, O_RDONLY);
Chong Zhang308e91f2020-06-10 15:27:56 -0700160 EXPECT_EQ(transcoder->configureSource(srcFd), AMEDIA_OK);
Linus Nilssoncab39d82020-05-14 16:32:21 -0700161
162 std::vector<std::shared_ptr<AMediaFormat>> trackFormats = transcoder->getTrackFormats();
163 EXPECT_GT(trackFormats.size(), 0);
164
165 for (int i = 0; i < trackFormats.size(); ++i) {
166 AMediaFormat* format = formatCallback(trackFormats[i].get());
167 EXPECT_EQ(transcoder->configureTrackFormat(i, format), AMEDIA_OK);
Chong Zhang5855ee52020-06-22 11:41:25 -0700168
169 // Save original video track format for verification.
170 const char* mime = nullptr;
171 AMediaFormat_getString(trackFormats[i].get(), AMEDIAFORMAT_KEY_MIME, &mime);
172 if (strncmp(mime, "video/", 6) == 0) {
173 mSourceVideoFormat = trackFormats[i];
174 }
175
Linus Nilssoncab39d82020-05-14 16:32:21 -0700176 if (format != nullptr) {
177 AMediaFormat_delete(format);
178 }
179 }
180 deleteFile(destPath);
Chong Zhang308e91f2020-06-10 15:27:56 -0700181 const int dstFd = open(destPath, kOpenFlags, kFileMode);
182 EXPECT_EQ(transcoder->configureDestination(dstFd), AMEDIA_OK);
Linus Nilssoncab39d82020-05-14 16:32:21 -0700183
184 media_status_t startStatus = transcoder->start();
185 EXPECT_EQ(startStatus, AMEDIA_OK);
Linus Nilssonfdb3e332020-09-18 17:11:41 -0700186
Linus Nilssoncab39d82020-05-14 16:32:21 -0700187 if (startStatus == AMEDIA_OK) {
Linus Nilssonfdb3e332020-09-18 17:11:41 -0700188 std::shared_ptr<ndk::ScopedAParcel> pausedState;
189
Linus Nilsson93cf9132020-09-24 12:12:48 -0700190 switch (executionControl) {
191 case kCancelAfterProgress:
192 mCallbacks->waitForProgressMade();
193 FALLTHROUGH_INTENDED;
194 case kCancelAfterStart:
195 transcoder->cancel();
196 break;
Linus Nilssonfdb3e332020-09-18 17:11:41 -0700197 case kPauseAfterProgress:
198 mCallbacks->waitForProgressMade();
199 FALLTHROUGH_INTENDED;
200 case kPauseAfterStart:
201 transcoder->pause(&pausedState);
202 break;
Linus Nilsson93cf9132020-09-24 12:12:48 -0700203 case kRunToCompletion:
204 default:
205 mCallbacks->waitForTranscodingFinished();
206 break;
207 }
Linus Nilssoncab39d82020-05-14 16:32:21 -0700208 }
Chong Zhang308e91f2020-06-10 15:27:56 -0700209 close(srcFd);
210 close(dstFd);
Linus Nilssoncab39d82020-05-14 16:32:21 -0700211
212 return mCallbacks->mStatus;
213 }
214
Linus Nilsson800793f2020-07-31 16:16:38 -0700215 void testTranscodeVideo(const char* srcPath, const char* destPath, const char* dstMime,
216 int32_t bitrate = 0) {
217 EXPECT_EQ(transcodeHelper(srcPath, destPath,
218 [dstMime, bitrate](AMediaFormat* sourceFormat) {
219 AMediaFormat* format = nullptr;
220 const char* mime = nullptr;
221 AMediaFormat_getString(sourceFormat, AMEDIAFORMAT_KEY_MIME,
222 &mime);
Chong Zhangd6e4aec2020-06-22 14:13:07 -0700223
Linus Nilsson800793f2020-07-31 16:16:38 -0700224 if (strncmp(mime, "video/", 6) == 0 &&
225 (bitrate > 0 || dstMime != nullptr)) {
226 format = AMediaFormat_new();
Chong Zhangd6e4aec2020-06-22 14:13:07 -0700227
Linus Nilsson800793f2020-07-31 16:16:38 -0700228 if (bitrate > 0) {
229 AMediaFormat_setInt32(
230 format, AMEDIAFORMAT_KEY_BIT_RATE, bitrate);
231 }
Chong Zhangd6e4aec2020-06-22 14:13:07 -0700232
Linus Nilsson800793f2020-07-31 16:16:38 -0700233 if (dstMime != nullptr) {
234 AMediaFormat_setString(format, AMEDIAFORMAT_KEY_MIME,
235 dstMime);
236 }
237 }
238 return format;
239 }),
240 AMEDIA_OK);
Chong Zhangd6e4aec2020-06-22 14:13:07 -0700241
242 if (dstMime != nullptr) {
243 std::vector<FormatVerifierEntry> extraVerifiers = {
244 {AMEDIAFORMAT_KEY_MIME,
245 [dstMime](const char* key, AMediaFormat* src __unused, AMediaFormat* dst) {
246 const char* mime = nullptr;
247 AMediaFormat_getString(dst, key, &mime);
248 return !strcmp(mime, dstMime);
249 }},
250 };
251 verifyOutputFormat(destPath, &extraVerifiers);
252 } else {
253 verifyOutputFormat(destPath);
254 }
255 }
256
Chong Zhang5855ee52020-06-22 11:41:25 -0700257 void verifyOutputFormat(const char* destPath,
258 const std::vector<FormatVerifierEntry>* extraVerifiers = nullptr) {
259 int dstFd = open(destPath, O_RDONLY);
260 EXPECT_GT(dstFd, 0);
261 ssize_t fileSize = lseek(dstFd, 0, SEEK_END);
262 lseek(dstFd, 0, SEEK_SET);
263
264 std::shared_ptr<MediaSampleReader> sampleReader =
265 MediaSampleReaderNDK::createFromFd(dstFd, 0, fileSize);
Linus Nilsson42a971b2020-07-01 16:41:11 -0700266 ASSERT_NE(sampleReader, nullptr);
Chong Zhang5855ee52020-06-22 11:41:25 -0700267
268 std::shared_ptr<AMediaFormat> videoFormat;
269 const size_t trackCount = sampleReader->getTrackCount();
270 for (size_t trackIndex = 0; trackIndex < trackCount; ++trackIndex) {
271 AMediaFormat* trackFormat = sampleReader->getTrackFormat(static_cast<int>(trackIndex));
272 if (trackFormat != nullptr) {
273 const char* mime = nullptr;
274 AMediaFormat_getString(trackFormat, AMEDIAFORMAT_KEY_MIME, &mime);
Linus Nilsson42a971b2020-07-01 16:41:11 -0700275
Chong Zhang5855ee52020-06-22 11:41:25 -0700276 if (strncmp(mime, "video/", 6) == 0) {
277 LOG(INFO) << "Track # " << trackIndex << ": "
278 << AMediaFormat_toString(trackFormat);
279 videoFormat = std::shared_ptr<AMediaFormat>(trackFormat, &AMediaFormat_delete);
280 break;
281 }
282 }
283 }
284
285 EXPECT_NE(videoFormat, nullptr);
Linus Nilssonaf4a3212020-12-15 08:18:25 -0800286 if (videoFormat != nullptr) {
287 LOG(INFO) << "source video format: " << AMediaFormat_toString(mSourceVideoFormat.get());
288 LOG(INFO) << "transcoded video format: " << AMediaFormat_toString(videoFormat.get());
Chong Zhang5855ee52020-06-22 11:41:25 -0700289
Linus Nilssonaf4a3212020-12-15 08:18:25 -0800290 for (int i = 0; i < (sizeof(kFieldsToPreserve) / sizeof(kFieldsToPreserve[0])); ++i) {
291 EXPECT_TRUE(kFieldsToPreserve[i].equal(kFieldsToPreserve[i].key,
292 mSourceVideoFormat.get(), videoFormat.get()))
293 << "Failed at key " << kFieldsToPreserve[i].key;
294 }
Chong Zhang5855ee52020-06-22 11:41:25 -0700295
Linus Nilssonaf4a3212020-12-15 08:18:25 -0800296 if (extraVerifiers != nullptr) {
297 for (int i = 0; i < extraVerifiers->size(); ++i) {
298 const FormatVerifierEntry& entry = (*extraVerifiers)[i];
299 EXPECT_TRUE(
300 entry.equal(entry.key, mSourceVideoFormat.get(), videoFormat.get()));
301 }
Chong Zhang5855ee52020-06-22 11:41:25 -0700302 }
303 }
304
305 close(dstFd);
306 }
307
Linus Nilssoncab39d82020-05-14 16:32:21 -0700308 std::shared_ptr<TestCallbacks> mCallbacks;
Chong Zhang5855ee52020-06-22 11:41:25 -0700309 std::shared_ptr<AMediaFormat> mSourceVideoFormat;
Linus Nilssoncab39d82020-05-14 16:32:21 -0700310};
311
312TEST_F(MediaTranscoderTests, TestPassthrough) {
Chong Zhangd6e4aec2020-06-22 14:13:07 -0700313 const char* srcPath = "/data/local/tmp/TranscodingTestAssets/cubicle_avc_480x240_aac_24KHz.mp4";
Linus Nilssoncab39d82020-05-14 16:32:21 -0700314 const char* destPath = "/data/local/tmp/MediaTranscoder_Passthrough.MP4";
Linus Nilsson800793f2020-07-31 16:16:38 -0700315 testTranscodeVideo(srcPath, destPath, nullptr);
Linus Nilssoncab39d82020-05-14 16:32:21 -0700316}
317
Chong Zhangd6e4aec2020-06-22 14:13:07 -0700318TEST_F(MediaTranscoderTests, TestVideoTranscode_AvcToAvc_Basic) {
319 const char* srcPath = "/data/local/tmp/TranscodingTestAssets/cubicle_avc_480x240_aac_24KHz.mp4";
320 const char* destPath = "/data/local/tmp/MediaTranscoder_VideoTranscode_AvcToAvc_Basic.MP4";
Linus Nilsson800793f2020-07-31 16:16:38 -0700321 testTranscodeVideo(srcPath, destPath, AMEDIA_MIMETYPE_VIDEO_AVC);
Chong Zhang5855ee52020-06-22 11:41:25 -0700322}
323
Chong Zhangd6e4aec2020-06-22 14:13:07 -0700324TEST_F(MediaTranscoderTests, TestVideoTranscode_HevcToAvc_Basic) {
325 const char* srcPath = "/data/local/tmp/TranscodingTestAssets/jets_hevc_1280x720_20Mbps.mp4";
326 const char* destPath = "/data/local/tmp/MediaTranscoder_VideoTranscode_HevcToAvc_Basic.MP4";
327 testTranscodeVideo(srcPath, destPath, AMEDIA_MIMETYPE_VIDEO_AVC);
328}
Chong Zhang5855ee52020-06-22 11:41:25 -0700329
Chong Zhangd6e4aec2020-06-22 14:13:07 -0700330TEST_F(MediaTranscoderTests, TestVideoTranscode_HevcToAvc_Rotation) {
331 const char* srcPath =
332 "/data/local/tmp/TranscodingTestAssets/desk_hevc_1920x1080_aac_48KHz_rot90.mp4";
333 const char* destPath = "/data/local/tmp/MediaTranscoder_VideoTranscode_HevcToAvc_Rotation.MP4";
334 testTranscodeVideo(srcPath, destPath, AMEDIA_MIMETYPE_VIDEO_AVC);
Linus Nilssoncab39d82020-05-14 16:32:21 -0700335}
336
Linus Nilsson800793f2020-07-31 16:16:38 -0700337TEST_F(MediaTranscoderTests, TestPreserveBitrate) {
338 const char* srcPath = "/data/local/tmp/TranscodingTestAssets/cubicle_avc_480x240_aac_24KHz.mp4";
339 const char* destPath = "/data/local/tmp/MediaTranscoder_PreserveBitrate.MP4";
340 testTranscodeVideo(srcPath, destPath, AMEDIA_MIMETYPE_VIDEO_AVC);
341
Linus Nilsson24ba9212020-12-02 11:46:39 -0800342 // Require maximum of 25% difference in file size.
343 // TODO(b/174678336): Find a better test asset to tighten the threshold.
344 EXPECT_LT(getFileSizeDiffPercent(srcPath, destPath, true /* absolute*/), 25);
Linus Nilsson800793f2020-07-31 16:16:38 -0700345}
346
347TEST_F(MediaTranscoderTests, TestCustomBitrate) {
348 const char* srcPath = "/data/local/tmp/TranscodingTestAssets/cubicle_avc_480x240_aac_24KHz.mp4";
349 const char* destPath1 = "/data/local/tmp/MediaTranscoder_CustomBitrate_2Mbps.MP4";
350 const char* destPath2 = "/data/local/tmp/MediaTranscoder_CustomBitrate_8Mbps.MP4";
351 testTranscodeVideo(srcPath, destPath1, AMEDIA_MIMETYPE_VIDEO_AVC, 2 * 1000 * 1000);
352 mCallbacks = std::make_shared<TestCallbacks>();
353 testTranscodeVideo(srcPath, destPath2, AMEDIA_MIMETYPE_VIDEO_AVC, 8 * 1000 * 1000);
354
355 // The source asset is very short and heavily compressed from the beginning so don't expect the
Linus Nilsson24ba9212020-12-02 11:46:39 -0800356 // requested bitrate to be exactly matched. However the 8mbps should at least be larger.
357 // TODO(b/174678336): Find a better test asset to tighten the threshold.
358 EXPECT_GT(getFileSizeDiffPercent(destPath1, destPath2), 10);
Linus Nilsson800793f2020-07-31 16:16:38 -0700359}
360
Linus Nilsson93cf9132020-09-24 12:12:48 -0700361static AMediaFormat* getAVCVideoFormat(AMediaFormat* sourceFormat) {
362 AMediaFormat* format = nullptr;
363 const char* mime = nullptr;
364 AMediaFormat_getString(sourceFormat, AMEDIAFORMAT_KEY_MIME, &mime);
365
366 if (strncmp(mime, "video/", 6) == 0) {
367 format = AMediaFormat_new();
368 AMediaFormat_setString(format, AMEDIAFORMAT_KEY_MIME, AMEDIA_MIMETYPE_VIDEO_AVC);
369 }
370
371 return format;
372}
373
374TEST_F(MediaTranscoderTests, TestCancelAfterProgress) {
375 const char* srcPath = "/data/local/tmp/TranscodingTestAssets/longtest_15s.mp4";
376 const char* destPath = "/data/local/tmp/MediaTranscoder_Cancel.MP4";
377
Linus Nilssonfdb3e332020-09-18 17:11:41 -0700378 for (int i = 0; i < 20; ++i) {
Linus Nilsson93cf9132020-09-24 12:12:48 -0700379 EXPECT_EQ(transcodeHelper(srcPath, destPath, getAVCVideoFormat, kCancelAfterProgress),
380 AMEDIA_OK);
Linus Nilssonfdb3e332020-09-18 17:11:41 -0700381 EXPECT_FALSE(mCallbacks->mFinished);
Linus Nilsson93cf9132020-09-24 12:12:48 -0700382 mCallbacks = std::make_shared<TestCallbacks>();
383 }
384}
385
386TEST_F(MediaTranscoderTests, TestCancelAfterStart) {
387 const char* srcPath = "/data/local/tmp/TranscodingTestAssets/longtest_15s.mp4";
388 const char* destPath = "/data/local/tmp/MediaTranscoder_Cancel.MP4";
389
Linus Nilssonfdb3e332020-09-18 17:11:41 -0700390 for (int i = 0; i < 20; ++i) {
Linus Nilsson93cf9132020-09-24 12:12:48 -0700391 EXPECT_EQ(transcodeHelper(srcPath, destPath, getAVCVideoFormat, kCancelAfterStart),
392 AMEDIA_OK);
Linus Nilssonfdb3e332020-09-18 17:11:41 -0700393 EXPECT_FALSE(mCallbacks->mFinished);
394 mCallbacks = std::make_shared<TestCallbacks>();
395 }
396}
397
398TEST_F(MediaTranscoderTests, TestPauseAfterProgress) {
399 const char* srcPath = "/data/local/tmp/TranscodingTestAssets/longtest_15s.mp4";
400 const char* destPath = "/data/local/tmp/MediaTranscoder_Pause.MP4";
401
402 for (int i = 0; i < 20; ++i) {
403 EXPECT_EQ(transcodeHelper(srcPath, destPath, getAVCVideoFormat, kPauseAfterProgress),
404 AMEDIA_OK);
405 EXPECT_FALSE(mCallbacks->mFinished);
406 mCallbacks = std::make_shared<TestCallbacks>();
407 }
408}
409
410TEST_F(MediaTranscoderTests, TestPauseAfterStart) {
411 const char* srcPath = "/data/local/tmp/TranscodingTestAssets/longtest_15s.mp4";
412 const char* destPath = "/data/local/tmp/MediaTranscoder_Pause.MP4";
413
414 for (int i = 0; i < 20; ++i) {
415 EXPECT_EQ(transcodeHelper(srcPath, destPath, getAVCVideoFormat, kPauseAfterStart),
416 AMEDIA_OK);
417 EXPECT_FALSE(mCallbacks->mFinished);
Linus Nilsson93cf9132020-09-24 12:12:48 -0700418 mCallbacks = std::make_shared<TestCallbacks>();
419 }
420}
421
Linus Nilssoncab39d82020-05-14 16:32:21 -0700422} // namespace android
423
424int main(int argc, char** argv) {
425 ::testing::InitGoogleTest(&argc, argv);
426 return RUN_ALL_TESTS();
427}