Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(437)

Side by Side Diff: media/base/android/sdk_media_codec_bridge_unittest.cc

Issue 2672313006: media: Remove the unused NdkMediaCodecBridge (Closed)
Patch Set: rebase past conflict Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/base/android/sdk_media_codec_bridge.h"
6
7 #include <stddef.h>
8 #include <stdint.h>
9
10 #include <memory>
11 #include <string>
12
13 #include "base/logging.h"
14 #include "media/base/android/media_codec_util.h"
15 #include "media/base/decoder_buffer.h"
16 #include "media/base/test_data_util.h"
17 #include "testing/gmock/include/gmock/gmock.h"
18
19 namespace {
20
21 // The first frame of
22 // http://www.html5rocks.com/en/tutorials/audio/quick/test.mp3
23 unsigned char test_mp3[] = {
24 0xff, 0xfb, 0xd2, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x69, 0x05, 0x00,
25 0x00, 0x00, 0x00, 0x00, 0x0d, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x7e, 0x40,
26 0xc0, 0x19, 0x4a, 0x80, 0x0d, 0x60, 0x48, 0x1b, 0x40, 0xf7, 0xbd, 0xb9,
27 0xd9, 0x40, 0x6f, 0x82, 0x01, 0x8b, 0x17, 0xa0, 0x80, 0xc5, 0x01, 0xad,
28 0x9a, 0xd3, 0x00, 0x12, 0xc0, 0x72, 0x93, 0x67, 0xd0, 0x03, 0x6f, 0xa4,
29 0xc0, 0xc3, 0x23, 0xee, 0x9b, 0xc0, 0xcc, 0x02, 0xa0, 0xa1, 0x30, 0x0c,
30 0x52, 0x2d, 0xfd, 0x6e, 0x08, 0x83, 0x60, 0x40, 0x46, 0x06, 0x4b, 0x20,
31 0x82, 0x82, 0x7f, 0xd4, 0x81, 0xe7, 0x00, 0x64, 0x20, 0x18, 0xec, 0xc2,
32 0x06, 0x57, 0x0f, 0x81, 0x93, 0x0b, 0x00, 0x66, 0xe3, 0xb7, 0xe8, 0x32,
33 0x6e, 0xf0, 0x32, 0xb0, 0x58, 0x0c, 0x7c, 0x3a, 0x03, 0x22, 0x14, 0x80,
34 0xc9, 0x01, 0x80, 0x30, 0x20, 0x14, 0x0c, 0x96, 0x73, 0xfe, 0x9f, 0x6c,
35 0x0c, 0xd2, 0x25, 0x0f, 0xdc, 0x0c, 0x32, 0x43, 0x03, 0x27, 0x87, 0xc0,
36 0xc2, 0xc0, 0x20, 0xfc, 0x42, 0xc5, 0xff, 0xff, 0xd4, 0x80, 0x01, 0x01,
37 0x80, 0xc3, 0x81, 0x01, 0x95, 0x03, 0x28, 0x82, 0xc0, 0xc3, 0x01, 0xa1,
38 0x06, 0x81, 0x87, 0xc2, 0x40, 0x64, 0xc1, 0xf0, 0x12, 0x02, 0xff, 0xf6,
39 0x5b, 0x9f, 0x44, 0xdc, 0xdd, 0x0b, 0x38, 0x59, 0xe0, 0x31, 0x71, 0x60,
40 0x0c, 0xb4, 0x22, 0x03, 0x3b, 0x96, 0x40, 0xc8, 0x63, 0x90, 0x0a, 0x23,
41 0x81, 0x9e, 0x4c, 0x20, 0x65, 0xb3, 0x18, 0x19, 0x6c, 0x42, 0x06, 0x36,
42 0x1d, 0x01, 0x90, 0x87, 0xdf, 0xff, 0xd0, 0x65, 0xa6, 0xea, 0x66, 0xfd,
43 0x40, 0x0c, 0x48, 0x03, 0x1a, 0x09, 0x01, 0x21, 0x98, 0x19, 0x2c, 0x36,
44 0x06, 0x43, 0x21, 0x81, 0x92, 0xca, 0x60, 0x64, 0x70, 0xb8, 0x19, 0x20,
45 0x6c, 0x02, 0x83, 0x80, 0xcb, 0x60, 0x65, 0x32, 0x28, 0x18, 0x64, 0x24,
46 0x06, 0x3a, 0x0c, 0x00, 0xe1, 0x00, 0x18, 0xd0, 0x35, 0xff, 0xff, 0xff,
47 0xe8, 0x32, 0xef, 0xb2, 0x90, 0x65, 0xbb, 0xdd, 0x94, 0x82, 0x0b, 0x4c,
48 0xfa, 0x25, 0xf3, 0x74, 0x13, 0x0f, 0xf8, 0x19, 0x28, 0x84, 0x06, 0x36,
49 0x11, 0x01, 0x20, 0x80, 0x18, 0xb4, 0x52, 0x0e, 0x15, 0x00, 0x30, 0x50,
50 0x0c, 0x84, 0x32, 0x03, 0x11, 0x04, 0x03, 0x48, 0x04, 0x00, 0x00, 0x31,
51 0x21, 0x00, 0x0c, 0x84, 0x18, 0x03, 0x07, 0x85, 0x40, 0xc6, 0xa5, 0x70,
52 0x32, 0xb8, 0x7c, 0x0c, 0x54, 0x04, 0x00, 0xd0, 0x08, 0x59, 0x58, 0x18,
53 0x20, 0x14, 0x06, 0x30, 0x30, 0x01, 0x9b, 0x86, 0x00, 0x6b, 0x54, 0xa8,
54 0x19, 0x8c, 0x2a, 0x06, 0x16, 0x09, 0x01, 0xa0, 0xd0, 0xa0, 0x69, 0x74,
55 0xb8, 0x19, 0xc4, 0x4a, 0xa3, 0xda, 0x9d, 0x1e, 0x4f, 0x05, 0xc0, 0x5b,
56 0x0b, 0x03, 0xc2, 0x76, 0xa3, 0x4f, 0xb9, 0x16, 0xc2, 0x70, 0x41, 0x07,
57 0xa0, 0x84, 0x16, 0x38, 0x4a, 0xc8, 0xaf, 0xee, 0x7f, 0x93, 0xb5, 0x5c,
58 0x39, 0x1e, 0x29, 0xd9, 0x8c, 0x80, 0xb5, 0x80, 0xe6, 0x85, 0xb2, 0x99,
59 0x68, 0x85, 0x46, 0x91, 0x60, 0xdb, 0x06, 0xfa, 0x38, 0x7a, 0xc7, 0xac,
60 0x85, 0xa8, 0xd3, 0xe6, 0x99, 0x3b, 0x66, 0x43, 0x23, 0x1f, 0x84, 0xe1,
61 0x65, 0x5e, 0xbc, 0x84, 0x18, 0x62, 0xe6, 0x42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06, 0x68, 0x1d, 0x6e, 0x4e,
77 0x8b, 0x79, 0xd6, 0xfc, 0xff, 0x2e, 0x6e, 0x7c, 0xba, 0x03, 0x90, 0xd4,
78 0x25, 0x65, 0x8e, 0xe7, 0x3a, 0xd1, 0xd6, 0xdc, 0xf0, 0xbe, 0x12, 0xc4,
79 0x31, 0x08, 0x16, 0x70, 0x31, 0x85, 0x61, 0x38, 0x27, 0x0a, 0x91, 0x5f,
80 0x03, 0x38, 0xeb, 0x37, 0x13, 0x48, 0x41, 0xbe, 0x7f, 0x04, 0x70, 0x62,
81 0x2b, 0x15, 0x91, 0x67, 0x63, 0x4f, 0xad, 0xa7, 0x1d, 0x3f, 0x44, 0x17,
82 0x02, 0x08, 0x0d, 0xf2, 0xfc, 0x03, 0xa0, 0x74, 0x21, 0x8b, 0x07, 0x3a,
83 0x8d, 0x0f, 0x54, 0x58, 0x94, 0x12, 0xc5, 0x62, 0x18, 0xb9, 0x42, 0xf0,
84 0x6c, 0x73, 0xa0, 0x92, 0xad, 0x27, 0x1c, 0x20, 0x0f, 0xc1, 0xca, 0x44,
85 0x87, 0x47, 0xc5, 0x43, 0x23, 0x01, 0xda, 0x23, 0xe2, 0x89, 0x38, 0x9f,
86 0x1f, 0x8d, 0x8c, 0xc6, 0x95, 0xa3, 0x34, 0x21, 0x21, 0x2d, 0x49, 0xea,
87 0x4b, 0x05, 0x85, 0xf5, 0x58, 0x25, 0x13, 0xcd, 0x51, 0x19, 0x1a, 0x88,
88 0xa6, 0x83, 0xd6, 0xd0, 0xbc, 0x25, 0x19, 0x1c, 0x92, 0x12, 0x44, 0x5d,
89 0x1c, 0x04, 0xf1, 0x99, 0xdf, 0x92, 0x8e, 0x09, 0x85, 0xf3, 0x88, 0x82,
90 0x4c, 0x22, 0x17, 0xc5, 0x25, 0x23, 0xed, 0x78, 0xf5, 0x41, 0xd1, 0xe9,
91 0x8a, 0xb3, 0x52, 0xd1, 0x3d, 0x79, 0x81, 0x4d, 0x31, 0x24, 0xf9, 0x38,
92 0x96, 0xbc, 0xf4, 0x8c, 0x25, 0xe9, 0xf2, 0x73, 0x94, 0x85, 0xc2, 0x61,
93 0x6a, 0x34, 0x68, 0x65, 0x78, 0x87, 0xa6, 0x4f};
94 static const size_t kDecodedAudioLengthInBytes = 9216u;
95
96 } // namespace
97
98 namespace media {
99
100 // Helper macro to skip the test if MediaCodecBridge isn't available.
101 #define SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE() \
102 do { \
103 if (!MediaCodecUtil::IsMediaCodecAvailable()) { \
104 VLOG(0) << "Could not run test - not supported on device."; \
105 return; \
106 } \
107 } while (0)
108
109 static const int kPresentationTimeBase = 100;
110 static const int kMaxInputPts = kPresentationTimeBase + 2;
111
112 static inline const base::TimeDelta InfiniteTimeOut() {
113 return base::TimeDelta::FromMicroseconds(-1);
114 }
115
116 void DecodeMediaFrame(VideoCodecBridge* media_codec,
117 const uint8_t* data,
118 size_t data_size,
119 const base::TimeDelta input_presentation_timestamp,
120 const base::TimeDelta initial_timestamp_lower_bound) {
121 base::TimeDelta input_pts = input_presentation_timestamp;
122 base::TimeDelta timestamp = initial_timestamp_lower_bound;
123 base::TimeDelta new_timestamp;
124 for (int i = 0; i < 10; ++i) {
125 int input_buf_index = -1;
126 MediaCodecStatus status =
127 media_codec->DequeueInputBuffer(InfiniteTimeOut(), &input_buf_index);
128 ASSERT_EQ(MEDIA_CODEC_OK, status);
129
130 media_codec->QueueInputBuffer(input_buf_index, data, data_size,
131 input_presentation_timestamp);
132
133 size_t unused_offset = 0;
134 size_t size = 0;
135 bool eos = false;
136 int output_buf_index = -1;
137 status = media_codec->DequeueOutputBuffer(
138 InfiniteTimeOut(), &output_buf_index, &unused_offset, &size,
139 &new_timestamp, &eos, nullptr);
140
141 if (status == MEDIA_CODEC_OK && output_buf_index > 0) {
142 media_codec->ReleaseOutputBuffer(output_buf_index, false);
143 }
144 // Output time stamp should not be smaller than old timestamp.
145 ASSERT_TRUE(new_timestamp >= timestamp);
146 input_pts += base::TimeDelta::FromMicroseconds(33000);
147 timestamp = new_timestamp;
148 }
149 }
150
151 TEST(SdkMediaCodecBridgeTest, Initialize) {
152 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
153
154 std::unique_ptr<media::MediaCodecBridge> media_codec;
155 media_codec.reset(VideoCodecBridge::CreateDecoder(
156 kCodecH264, false, gfx::Size(640, 480), nullptr, nullptr,
157 std::vector<uint8_t>(), std::vector<uint8_t>()));
158 }
159
160 TEST(SdkMediaCodecBridgeTest, DoNormal) {
161 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
162
163 std::unique_ptr<media::AudioCodecBridge> media_codec;
164 media_codec.reset(AudioCodecBridge::Create(kCodecMP3));
165
166 ASSERT_TRUE(media_codec->ConfigureAndStart(kCodecMP3, 44100, 2, nullptr, 0, 0,
167 0, nullptr));
168
169 int input_buf_index = -1;
170 MediaCodecStatus status =
171 media_codec->DequeueInputBuffer(InfiniteTimeOut(), &input_buf_index);
172 ASSERT_EQ(MEDIA_CODEC_OK, status);
173 ASSERT_GE(input_buf_index, 0);
174
175 int64_t input_pts = kPresentationTimeBase;
176 media_codec->QueueInputBuffer(input_buf_index, test_mp3, sizeof(test_mp3),
177 base::TimeDelta::FromMicroseconds(++input_pts));
178
179 status = media_codec->DequeueInputBuffer(InfiniteTimeOut(), &input_buf_index);
180 media_codec->QueueInputBuffer(input_buf_index, test_mp3, sizeof(test_mp3),
181 base::TimeDelta::FromMicroseconds(++input_pts));
182
183 status = media_codec->DequeueInputBuffer(InfiniteTimeOut(), &input_buf_index);
184 media_codec->QueueEOS(input_buf_index);
185
186 input_pts = kPresentationTimeBase;
187 bool eos = false;
188 size_t total_size = 0;
189 while (!eos) {
190 size_t unused_offset = 0;
191 size_t size = 0;
192 base::TimeDelta timestamp;
193 int output_buf_index = -1;
194 status = media_codec->DequeueOutputBuffer(InfiniteTimeOut(),
195 &output_buf_index, &unused_offset,
196 &size, &timestamp, &eos, nullptr);
197 switch (status) {
198 case MEDIA_CODEC_DEQUEUE_OUTPUT_AGAIN_LATER:
199 FAIL();
200 return;
201
202 case MEDIA_CODEC_OUTPUT_FORMAT_CHANGED:
203 continue;
204
205 case MEDIA_CODEC_OUTPUT_BUFFERS_CHANGED:
206 continue;
207
208 default:
209 break;
210 }
211 ASSERT_GE(output_buf_index, 0);
212 EXPECT_LE(1u, size);
213 total_size += size;
214 }
215 EXPECT_EQ(kDecodedAudioLengthInBytes, total_size);
216 ASSERT_LE(input_pts, kMaxInputPts);
217 }
218
219 TEST(SdkMediaCodecBridgeTest, InvalidVorbisHeader) {
220 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
221
222 std::unique_ptr<media::AudioCodecBridge> media_codec;
223 media_codec.reset(AudioCodecBridge::Create(kCodecVorbis));
224
225 // The first byte of the header is not 0x02.
226 uint8_t invalid_first_byte[] = {0x00, 0xff, 0xff, 0xff, 0xff};
227 EXPECT_FALSE(media_codec->ConfigureAndStart(
228 kCodecVorbis, 44100, 2, invalid_first_byte, sizeof(invalid_first_byte), 0,
229 0, nullptr));
230
231 // Size of the header does not match with the data we passed in.
232 uint8_t invalid_size[] = {0x02, 0x01, 0xff, 0x01, 0xff};
233 EXPECT_FALSE(
234 media_codec->ConfigureAndStart(kCodecVorbis, 44100, 2, invalid_size,
235 sizeof(invalid_size), 0, 0, nullptr));
236
237 // Size of the header is too large.
238 size_t large_size = 8 * 1024 * 1024 + 2;
239 uint8_t* very_large_header = new uint8_t[large_size];
240 very_large_header[0] = 0x02;
241 for (size_t i = 1; i < large_size - 1; ++i)
242 very_large_header[i] = 0xff;
243 very_large_header[large_size - 1] = 0xfe;
244 EXPECT_FALSE(media_codec->ConfigureAndStart(
245 kCodecVorbis, 44100, 2, very_large_header, 0x80000000, 0, 0, nullptr));
246 delete[] very_large_header;
247 }
248
249 TEST(SdkMediaCodecBridgeTest, InvalidOpusHeader) {
250 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
251
252 std::unique_ptr<media::AudioCodecBridge> media_codec;
253 media_codec.reset(AudioCodecBridge::Create(kCodecOpus));
254 if (!media_codec)
255 return;
256
257 uint8_t dummy_extra_data[] = {0, 0};
258
259 // Extra Data is NULL.
260 EXPECT_FALSE(media_codec->ConfigureAndStart(kCodecOpus, 48000, 2, nullptr, 0,
261 -1, 0, nullptr));
262
263 // Codec Delay is < 0.
264 EXPECT_FALSE(
265 media_codec->ConfigureAndStart(kCodecOpus, 48000, 2, dummy_extra_data,
266 sizeof(dummy_extra_data), -1, 0, nullptr));
267
268 // Seek Preroll is < 0.
269 EXPECT_FALSE(
270 media_codec->ConfigureAndStart(kCodecOpus, 48000, 2, dummy_extra_data,
271 sizeof(dummy_extra_data), 0, -1, nullptr));
272 }
273
274 TEST(SdkMediaCodecBridgeTest, PresentationTimestampsDoNotDecrease) {
275 SKIP_TEST_IF_VP8_DECODER_IS_NOT_SUPPORTED();
276
277 std::unique_ptr<VideoCodecBridge> media_codec(VideoCodecBridge::CreateDecoder(
278 kCodecVP8, false, gfx::Size(320, 240), nullptr, nullptr,
279 std::vector<uint8_t>(), std::vector<uint8_t>()));
280 EXPECT_TRUE(media_codec.get());
281 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("vp8-I-frame-320x240");
282 DecodeMediaFrame(media_codec.get(), buffer->data(), buffer->data_size(),
283 base::TimeDelta(), base::TimeDelta());
284
285 // Simulate a seek to 10 seconds, and each chunk has 2 I-frames.
286 std::vector<uint8_t> chunk(buffer->data(),
287 buffer->data() + buffer->data_size());
288 chunk.insert(chunk.end(), buffer->data(),
289 buffer->data() + buffer->data_size());
290 media_codec->Flush();
291 DecodeMediaFrame(media_codec.get(), &chunk[0], chunk.size(),
292 base::TimeDelta::FromMicroseconds(10000000),
293 base::TimeDelta::FromMicroseconds(9900000));
294
295 // Simulate a seek to 5 seconds.
296 media_codec->Flush();
297 DecodeMediaFrame(media_codec.get(), &chunk[0], chunk.size(),
298 base::TimeDelta::FromMicroseconds(5000000),
299 base::TimeDelta::FromMicroseconds(4900000));
300 }
301
302 TEST(SdkMediaCodecBridgeTest, CreateUnsupportedCodec) {
303 EXPECT_EQ(nullptr, AudioCodecBridge::Create(kUnknownAudioCodec));
304 EXPECT_EQ(nullptr,
305 VideoCodecBridge::CreateDecoder(
306 kUnknownVideoCodec, false, gfx::Size(320, 240), nullptr,
307 nullptr, std::vector<uint8_t>(), std::vector<uint8_t>()));
308 }
309
310 } // namespace media
OLDNEW
« no previous file with comments | « media/base/android/sdk_media_codec_bridge.cc ('k') | media/filters/android/media_codec_audio_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698