OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "media/base/android/media_codec_bridge.h" | 10 #include "media/base/android/media_codec_bridge.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 if (status == MEDIA_CODEC_OK && output_buf_index > 0) | 125 if (status == MEDIA_CODEC_OK && output_buf_index > 0) |
126 media_codec->ReleaseOutputBuffer(output_buf_index, false); | 126 media_codec->ReleaseOutputBuffer(output_buf_index, false); |
127 // Output time stamp should not be smaller than old timestamp. | 127 // Output time stamp should not be smaller than old timestamp. |
128 ASSERT_TRUE(new_timestamp >= timestamp); | 128 ASSERT_TRUE(new_timestamp >= timestamp); |
129 input_pts += base::TimeDelta::FromMicroseconds(33000); | 129 input_pts += base::TimeDelta::FromMicroseconds(33000); |
130 timestamp = new_timestamp; | 130 timestamp = new_timestamp; |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 TEST(MediaCodecBridgeTest, Initialize) { | 134 TEST(MediaCodecBridgeTest, Initialize) { |
135 if (!MediaCodecBridge::IsAvailable()) | |
136 return; | |
137 | |
138 scoped_ptr<media::MediaCodecBridge> media_codec; | 135 scoped_ptr<media::MediaCodecBridge> media_codec; |
139 media_codec.reset(VideoCodecBridge::Create(kCodecH264, false)); | 136 media_codec.reset(VideoCodecBridge::Create(kCodecH264, false)); |
140 } | 137 } |
141 | 138 |
142 TEST(MediaCodecBridgeTest, DoNormal) { | 139 TEST(MediaCodecBridgeTest, DoNormal) { |
143 if (!MediaCodecBridge::IsAvailable()) | |
144 return; | |
145 | |
146 scoped_ptr<media::AudioCodecBridge> media_codec; | 140 scoped_ptr<media::AudioCodecBridge> media_codec; |
147 media_codec.reset(AudioCodecBridge::Create(kCodecMP3)); | 141 media_codec.reset(AudioCodecBridge::Create(kCodecMP3)); |
148 | 142 |
149 media_codec->Start(kCodecMP3, 44100, 2, NULL, 0, false, NULL); | 143 media_codec->Start(kCodecMP3, 44100, 2, NULL, 0, false, NULL); |
150 | 144 |
151 int input_buf_index = -1; | 145 int input_buf_index = -1; |
152 MediaCodecStatus status = | 146 MediaCodecStatus status = |
153 media_codec->DequeueInputBuffer(InfiniteTimeOut(), &input_buf_index); | 147 media_codec->DequeueInputBuffer(InfiniteTimeOut(), &input_buf_index); |
154 ASSERT_EQ(MEDIA_CODEC_OK, status); | 148 ASSERT_EQ(MEDIA_CODEC_OK, status); |
155 ASSERT_GE(input_buf_index, 0); | 149 ASSERT_GE(input_buf_index, 0); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 ASSERT_GE(output_buf_index, 0); | 188 ASSERT_GE(output_buf_index, 0); |
195 EXPECT_LE(1u, size); | 189 EXPECT_LE(1u, size); |
196 if (!eos) | 190 if (!eos) |
197 EXPECT_EQ(++input_pts, timestamp.InMicroseconds()); | 191 EXPECT_EQ(++input_pts, timestamp.InMicroseconds()); |
198 ASSERT_LE(input_pts, kPresentationTimeBase + 2); | 192 ASSERT_LE(input_pts, kPresentationTimeBase + 2); |
199 } | 193 } |
200 ASSERT_EQ(input_pts, kPresentationTimeBase + 2); | 194 ASSERT_EQ(input_pts, kPresentationTimeBase + 2); |
201 } | 195 } |
202 | 196 |
203 TEST(MediaCodecBridgeTest, InvalidVorbisHeader) { | 197 TEST(MediaCodecBridgeTest, InvalidVorbisHeader) { |
204 if (!MediaCodecBridge::IsAvailable()) | |
205 return; | |
206 | |
207 scoped_ptr<media::AudioCodecBridge> media_codec; | 198 scoped_ptr<media::AudioCodecBridge> media_codec; |
208 media_codec.reset(AudioCodecBridge::Create(kCodecVorbis)); | 199 media_codec.reset(AudioCodecBridge::Create(kCodecVorbis)); |
209 | 200 |
210 // The first byte of the header is not 0x02. | 201 // The first byte of the header is not 0x02. |
211 uint8 invalid_first_byte[] = { 0x00, 0xff, 0xff, 0xff, 0xff }; | 202 uint8 invalid_first_byte[] = { 0x00, 0xff, 0xff, 0xff, 0xff }; |
212 EXPECT_FALSE(media_codec->Start( | 203 EXPECT_FALSE(media_codec->Start( |
213 kCodecVorbis, 44100, 2, invalid_first_byte, sizeof(invalid_first_byte), | 204 kCodecVorbis, 44100, 2, invalid_first_byte, sizeof(invalid_first_byte), |
214 false, NULL)); | 205 false, NULL)); |
215 | 206 |
216 // Size of the header does not match with the data we passed in. | 207 // Size of the header does not match with the data we passed in. |
217 uint8 invalid_size[] = { 0x02, 0x01, 0xff, 0x01, 0xff }; | 208 uint8 invalid_size[] = { 0x02, 0x01, 0xff, 0x01, 0xff }; |
218 EXPECT_FALSE(media_codec->Start( | 209 EXPECT_FALSE(media_codec->Start( |
219 kCodecVorbis, 44100, 2, invalid_size, sizeof(invalid_size), false, NULL)); | 210 kCodecVorbis, 44100, 2, invalid_size, sizeof(invalid_size), false, NULL)); |
220 | 211 |
221 // Size of the header is too large. | 212 // Size of the header is too large. |
222 size_t large_size = 8 * 1024 * 1024 + 2; | 213 size_t large_size = 8 * 1024 * 1024 + 2; |
223 uint8* very_large_header = new uint8[large_size]; | 214 uint8* very_large_header = new uint8[large_size]; |
224 very_large_header[0] = 0x02; | 215 very_large_header[0] = 0x02; |
225 for (size_t i = 1; i < large_size - 1; ++i) | 216 for (size_t i = 1; i < large_size - 1; ++i) |
226 very_large_header[i] = 0xff; | 217 very_large_header[i] = 0xff; |
227 very_large_header[large_size - 1] = 0xfe; | 218 very_large_header[large_size - 1] = 0xfe; |
228 EXPECT_FALSE(media_codec->Start( | 219 EXPECT_FALSE(media_codec->Start( |
229 kCodecVorbis, 44100, 2, very_large_header, 0x80000000, false, NULL)); | 220 kCodecVorbis, 44100, 2, very_large_header, 0x80000000, false, NULL)); |
230 delete[] very_large_header; | 221 delete[] very_large_header; |
231 } | 222 } |
232 | 223 |
233 TEST(MediaCodecBridgeTest, PresentationTimestampsDoNotDecrease) { | 224 TEST(MediaCodecBridgeTest, PresentationTimestampsDoNotDecrease) { |
234 if (!MediaCodecBridge::IsAvailable()) | |
235 return; | |
236 | |
237 scoped_ptr<VideoCodecBridge> media_codec; | 225 scoped_ptr<VideoCodecBridge> media_codec; |
238 media_codec.reset(VideoCodecBridge::Create(kCodecVP8, false)); | 226 media_codec.reset(VideoCodecBridge::Create(kCodecVP8, false)); |
239 EXPECT_TRUE(media_codec->Start( | 227 EXPECT_TRUE(media_codec->Start( |
240 kCodecVP8, gfx::Size(320, 240), NULL, NULL)); | 228 kCodecVP8, gfx::Size(320, 240), NULL, NULL)); |
241 scoped_refptr<DecoderBuffer> buffer = | 229 scoped_refptr<DecoderBuffer> buffer = |
242 ReadTestDataFile("vp8-I-frame-320x240"); | 230 ReadTestDataFile("vp8-I-frame-320x240"); |
243 DecodeMediaFrame( | 231 DecodeMediaFrame( |
244 media_codec.get(), buffer->data(), buffer->data_size(), | 232 media_codec.get(), buffer->data(), buffer->data_size(), |
245 base::TimeDelta(), base::TimeDelta()); | 233 base::TimeDelta(), base::TimeDelta()); |
246 | 234 |
(...skipping 13 matching lines...) Expand all Loading... |
260 base::TimeDelta::FromMicroseconds(5000000), | 248 base::TimeDelta::FromMicroseconds(5000000), |
261 base::TimeDelta::FromMicroseconds(4900000)); | 249 base::TimeDelta::FromMicroseconds(4900000)); |
262 } | 250 } |
263 | 251 |
264 TEST(MediaCodecBridgeTest, CreateUnsupportedCodec) { | 252 TEST(MediaCodecBridgeTest, CreateUnsupportedCodec) { |
265 EXPECT_EQ(NULL, AudioCodecBridge::Create(kUnknownAudioCodec)); | 253 EXPECT_EQ(NULL, AudioCodecBridge::Create(kUnknownAudioCodec)); |
266 EXPECT_EQ(NULL, VideoCodecBridge::Create(kUnknownVideoCodec, false)); | 254 EXPECT_EQ(NULL, VideoCodecBridge::Create(kUnknownVideoCodec, false)); |
267 } | 255 } |
268 | 256 |
269 } // namespace media | 257 } // namespace media |
OLD | NEW |