blob: 9f96d3b2a052a1b6d40211ea36876ea1d6faef8d [file] [log] [blame]
Manisha Jajoo90f569a2019-09-06 17:24:22 +05301/*
2 * Copyright (C) 2019 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//#define LOG_NDEBUG 0
18#define LOG_TAG "decoderTest"
19
20#include <fstream>
21#include <iostream>
22#include <limits>
23
Manisha Jajoo90f569a2019-09-06 17:24:22 +053024#include "BenchmarkTestEnvironment.h"
Manisha Jajoo2d931a82019-12-20 15:49:52 +053025#include "Decoder.h"
Manisha Jajoo90f569a2019-09-06 17:24:22 +053026
27static BenchmarkTestEnvironment *gEnv = nullptr;
28
29class DecoderTest : public ::testing::TestWithParam<tuple<string, string, bool>> {};
30
31TEST_P(DecoderTest, Decode) {
32 ALOGV("Decode the samples given by extractor");
33 tuple<string /* InputFile */, string /* CodecName */, bool /* asyncMode */> params = GetParam();
34
35 string inputFile = gEnv->getRes() + get<0>(params);
36 FILE *inputFp = fopen(inputFile.c_str(), "rb");
Manisha Jajoo2d931a82019-12-20 15:49:52 +053037 ASSERT_NE(inputFp, nullptr) << "Unable to open " << inputFile << " file for reading";
Manisha Jajoo90f569a2019-09-06 17:24:22 +053038
39 Decoder *decoder = new Decoder();
Manisha Jajoo2d931a82019-12-20 15:49:52 +053040 ASSERT_NE(decoder, nullptr) << "Decoder creation failed";
41
Manisha Jajoo90f569a2019-09-06 17:24:22 +053042 Extractor *extractor = decoder->getExtractor();
Manisha Jajoo2d931a82019-12-20 15:49:52 +053043 ASSERT_NE(extractor, nullptr) << "Extractor creation failed";
Manisha Jajoo90f569a2019-09-06 17:24:22 +053044
45 // Read file properties
Manisha Jajoo2d931a82019-12-20 15:49:52 +053046 struct stat buf;
47 stat(inputFile.c_str(), &buf);
48 size_t fileSize = buf.st_size;
Manisha Jajoo90f569a2019-09-06 17:24:22 +053049 int32_t fd = fileno(inputFp);
50
51 int32_t trackCount = extractor->initExtractor(fd, fileSize);
Manisha Jajoo2d931a82019-12-20 15:49:52 +053052 ASSERT_GT(trackCount, 0) << "initExtractor failed";
53
Manisha Jajoo90f569a2019-09-06 17:24:22 +053054 for (int curTrack = 0; curTrack < trackCount; curTrack++) {
55 int32_t status = extractor->setupTrackFormat(curTrack);
Manisha Jajoo2d931a82019-12-20 15:49:52 +053056 ASSERT_EQ(status, 0) << "Track Format invalid";
Manisha Jajoo90f569a2019-09-06 17:24:22 +053057
58 uint8_t *inputBuffer = (uint8_t *)malloc(kMaxBufferSize);
Manisha Jajoo2d931a82019-12-20 15:49:52 +053059 ASSERT_NE(inputBuffer, nullptr) << "Insufficient memory";
60
Manisha Jajoo90f569a2019-09-06 17:24:22 +053061 vector<AMediaCodecBufferInfo> frameInfo;
62 AMediaCodecBufferInfo info;
63 uint32_t inputBufferOffset = 0;
Manisha Jajoo90f569a2019-09-06 17:24:22 +053064
Manisha Jajoo90f569a2019-09-06 17:24:22 +053065 // Get frame data
66 while (1) {
67 status = extractor->getFrameSample(info);
68 if (status || !info.size) break;
69 // copy the meta data and buffer to be passed to decoder
Manisha Jajoo2d931a82019-12-20 15:49:52 +053070 ASSERT_LE(inputBufferOffset + info.size, kMaxBufferSize)
71 << "Memory allocated not sufficient";
72
Manisha Jajoo90f569a2019-09-06 17:24:22 +053073 memcpy(inputBuffer + inputBufferOffset, extractor->getFrameBuf(), info.size);
74 frameInfo.push_back(info);
75 inputBufferOffset += info.size;
76 }
77
78 string codecName = get<1>(params);
79 bool asyncMode = get<2>(params);
80 decoder->setupDecoder();
81 status = decoder->decode(inputBuffer, frameInfo, codecName, asyncMode);
Manisha Jajoo2d931a82019-12-20 15:49:52 +053082 ASSERT_EQ(status, AMEDIA_OK) << "Decoder failed for " << codecName;
83
Manisha Jajoo90f569a2019-09-06 17:24:22 +053084 decoder->deInitCodec();
Manisha Jajoo2d931a82019-12-20 15:49:52 +053085 ALOGV("codec : %s", codecName.c_str());
Manisha Jajoo90f569a2019-09-06 17:24:22 +053086 string inputReference = get<0>(params);
87 decoder->dumpStatistics(inputReference);
88 free(inputBuffer);
89 decoder->resetDecoder();
90 }
91 fclose(inputFp);
92 extractor->deInitExtractor();
93 delete decoder;
94}
95
96// TODO: (b/140549596)
97// Add wav files
98INSTANTIATE_TEST_SUITE_P(
99 AudioDecoderSyncTest, DecoderTest,
100 ::testing::Values(make_tuple("bbb_44100hz_2ch_128kbps_aac_30sec.mp4", "", false),
101 make_tuple("bbb_44100hz_2ch_128kbps_mp3_30sec.mp3", "", false),
102 make_tuple("bbb_8000hz_1ch_8kbps_amrnb_30sec.3gp", "", false),
103 make_tuple("bbb_16000hz_1ch_9kbps_amrwb_30sec.3gp", "", false),
Manisha Jajoo8ff51af2020-01-30 14:41:38 +0530104 make_tuple("bbb_44100hz_2ch_80kbps_vorbis_30sec.webm", "", false),
Manisha Jajooca8de042019-09-16 18:58:42 +0530105 make_tuple("bbb_44100hz_2ch_600kbps_flac_30sec.mp4", "", false),
Manisha Jajoo90f569a2019-09-06 17:24:22 +0530106 make_tuple("bbb_48000hz_2ch_100kbps_opus_30sec.webm", "", false)));
107
108INSTANTIATE_TEST_SUITE_P(
109 AudioDecoderAsyncTest, DecoderTest,
110 ::testing::Values(make_tuple("bbb_44100hz_2ch_128kbps_aac_30sec.mp4", "", true),
111 make_tuple("bbb_44100hz_2ch_128kbps_mp3_30sec.mp3", "", true),
112 make_tuple("bbb_8000hz_1ch_8kbps_amrnb_30sec.3gp", "", true),
113 make_tuple("bbb_16000hz_1ch_9kbps_amrwb_30sec.3gp", "", true),
Manisha Jajoo8ff51af2020-01-30 14:41:38 +0530114 make_tuple("bbb_44100hz_2ch_80kbps_vorbis_30sec.webm", "", true),
Manisha Jajooca8de042019-09-16 18:58:42 +0530115 make_tuple("bbb_44100hz_2ch_600kbps_flac_30sec.mp4", "", true),
Manisha Jajoo90f569a2019-09-06 17:24:22 +0530116 make_tuple("bbb_48000hz_2ch_100kbps_opus_30sec.webm", "", true)));
117
118INSTANTIATE_TEST_SUITE_P(VideDecoderSyncTest, DecoderTest,
119 ::testing::Values(
120 // Hardware codecs
121 make_tuple("crowd_1920x1080_25fps_4000kbps_vp9.webm", "", false),
122 make_tuple("crowd_1920x1080_25fps_4000kbps_vp8.webm", "", false),
123 make_tuple("crowd_1920x1080_25fps_4000kbps_av1.webm", "", false),
124 make_tuple("crowd_1920x1080_25fps_7300kbps_mpeg2.mp4", "", false),
125 make_tuple("crowd_1920x1080_25fps_6000kbps_mpeg4.mp4", "", false),
126 make_tuple("crowd_352x288_25fps_6000kbps_h263.3gp", "", false),
127 make_tuple("crowd_1920x1080_25fps_6700kbps_h264.ts", "", false),
128 make_tuple("crowd_1920x1080_25fps_4000kbps_h265.mkv", "", false),
129 // Software codecs
130 make_tuple("crowd_1920x1080_25fps_4000kbps_vp9.webm",
131 "c2.android.vp9.decoder", false),
132 make_tuple("crowd_1920x1080_25fps_4000kbps_vp8.webm",
133 "c2.android.vp8.decoder", false),
134 make_tuple("crowd_1920x1080_25fps_4000kbps_av1.webm",
135 "c2.android.av1.decoder", false),
136 make_tuple("crowd_1920x1080_25fps_7300kbps_mpeg2.mp4",
137 "c2.android.mpeg2.decoder", false),
138 make_tuple("crowd_1920x1080_25fps_6000kbps_mpeg4.mp4",
139 "c2.android.mpeg4.decoder", false),
140 make_tuple("crowd_352x288_25fps_6000kbps_h263.3gp",
141 "c2.android.h263.decoder", false),
142 make_tuple("crowd_1920x1080_25fps_6700kbps_h264.ts",
143 "c2.android.avc.decoder", false),
144 make_tuple("crowd_1920x1080_25fps_4000kbps_h265.mkv",
145 "c2.android.hevc.decoder", false)));
146
147INSTANTIATE_TEST_SUITE_P(VideoDecoderAsyncTest, DecoderTest,
148 ::testing::Values(
149 // Hardware codecs
150 make_tuple("crowd_1920x1080_25fps_4000kbps_vp9.webm", "", true),
151 make_tuple("crowd_1920x1080_25fps_4000kbps_vp8.webm", "", true),
152 make_tuple("crowd_1920x1080_25fps_4000kbps_av1.webm", "", true),
153 make_tuple("crowd_1920x1080_25fps_7300kbps_mpeg2.mp4", "", true),
154 make_tuple("crowd_1920x1080_25fps_6000kbps_mpeg4.mp4", "", true),
155 make_tuple("crowd_352x288_25fps_6000kbps_h263.3gp", "", true),
156 make_tuple("crowd_1920x1080_25fps_6700kbps_h264.ts", "", true),
157 make_tuple("crowd_1920x1080_25fps_4000kbps_h265.mkv", "", true),
158 // Software codecs
159 make_tuple("crowd_1920x1080_25fps_4000kbps_vp9.webm",
160 "c2.android.vp9.decoder", true),
161 make_tuple("crowd_1920x1080_25fps_4000kbps_vp8.webm",
162 "c2.android.vp8.decoder", true),
163 make_tuple("crowd_1920x1080_25fps_4000kbps_av1.webm",
164 "c2.android.av1.decoder", true),
165 make_tuple("crowd_1920x1080_25fps_7300kbps_mpeg2.mp4",
166 "c2.android.mpeg2.decoder", true),
167 make_tuple("crowd_1920x1080_25fps_6000kbps_mpeg4.mp4",
168 "c2.android.mpeg4.decoder", true),
169 make_tuple("crowd_352x288_25fps_6000kbps_h263.3gp",
170 "c2.android.h263.decoder", true),
171 make_tuple("crowd_1920x1080_25fps_6700kbps_h264.ts",
172 "c2.android.avc.decoder", true),
173 make_tuple("crowd_1920x1080_25fps_4000kbps_h265.mkv",
174 "c2.android.hevc.decoder", true)));
175
176int main(int argc, char **argv) {
177 gEnv = new BenchmarkTestEnvironment();
178 ::testing::AddGlobalTestEnvironment(gEnv);
179 ::testing::InitGoogleTest(&argc, argv);
180 int status = gEnv->initFromOptions(argc, argv);
181 if (status == 0) {
182 status = RUN_ALL_TESTS();
183 ALOGD("Decoder Test result = %d\n", status);
184 }
185 return status;
186}