| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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" | |
| 8 #include "base/logging.h" | 7 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 10 #include "media/base/android/media_codec_util.h" | 9 #include "media/base/android/media_codec_util.h" |
| 11 #include "media/base/android/sdk_media_codec_bridge.h" | 10 #include "media/base/android/sdk_media_codec_bridge.h" |
| 12 #include "media/base/decoder_buffer.h" | 11 #include "media/base/decoder_buffer.h" |
| 13 #include "media/base/test_data_util.h" | 12 #include "media/base/test_data_util.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 15 | 14 |
| 16 namespace { | 15 namespace { |
| 17 | 16 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 } \ | 101 } \ |
| 103 } while (0) | 102 } while (0) |
| 104 | 103 |
| 105 static const int kPresentationTimeBase = 100; | 104 static const int kPresentationTimeBase = 100; |
| 106 | 105 |
| 107 static inline const base::TimeDelta InfiniteTimeOut() { | 106 static inline const base::TimeDelta InfiniteTimeOut() { |
| 108 return base::TimeDelta::FromMicroseconds(-1); | 107 return base::TimeDelta::FromMicroseconds(-1); |
| 109 } | 108 } |
| 110 | 109 |
| 111 void DecodeMediaFrame(VideoCodecBridge* media_codec, | 110 void DecodeMediaFrame(VideoCodecBridge* media_codec, |
| 112 const uint8* data, | 111 const uint8_t* data, |
| 113 size_t data_size, | 112 size_t data_size, |
| 114 const base::TimeDelta input_presentation_timestamp, | 113 const base::TimeDelta input_presentation_timestamp, |
| 115 const base::TimeDelta initial_timestamp_lower_bound) { | 114 const base::TimeDelta initial_timestamp_lower_bound) { |
| 116 base::TimeDelta input_pts = input_presentation_timestamp; | 115 base::TimeDelta input_pts = input_presentation_timestamp; |
| 117 base::TimeDelta timestamp = initial_timestamp_lower_bound; | 116 base::TimeDelta timestamp = initial_timestamp_lower_bound; |
| 118 base::TimeDelta new_timestamp; | 117 base::TimeDelta new_timestamp; |
| 119 for (int i = 0; i < 10; ++i) { | 118 for (int i = 0; i < 10; ++i) { |
| 120 int input_buf_index = -1; | 119 int input_buf_index = -1; |
| 121 MediaCodecStatus status = | 120 MediaCodecStatus status = |
| 122 media_codec->DequeueInputBuffer(InfiniteTimeOut(), &input_buf_index); | 121 media_codec->DequeueInputBuffer(InfiniteTimeOut(), &input_buf_index); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 | 158 |
| 160 ASSERT_TRUE(media_codec->ConfigureAndStart(kCodecMP3, 44100, 2, nullptr, 0, 0, | 159 ASSERT_TRUE(media_codec->ConfigureAndStart(kCodecMP3, 44100, 2, nullptr, 0, 0, |
| 161 0, false, nullptr)); | 160 0, false, nullptr)); |
| 162 | 161 |
| 163 int input_buf_index = -1; | 162 int input_buf_index = -1; |
| 164 MediaCodecStatus status = | 163 MediaCodecStatus status = |
| 165 media_codec->DequeueInputBuffer(InfiniteTimeOut(), &input_buf_index); | 164 media_codec->DequeueInputBuffer(InfiniteTimeOut(), &input_buf_index); |
| 166 ASSERT_EQ(MEDIA_CODEC_OK, status); | 165 ASSERT_EQ(MEDIA_CODEC_OK, status); |
| 167 ASSERT_GE(input_buf_index, 0); | 166 ASSERT_GE(input_buf_index, 0); |
| 168 | 167 |
| 169 int64 input_pts = kPresentationTimeBase; | 168 int64_t input_pts = kPresentationTimeBase; |
| 170 media_codec->QueueInputBuffer(input_buf_index, test_mp3, sizeof(test_mp3), | 169 media_codec->QueueInputBuffer(input_buf_index, test_mp3, sizeof(test_mp3), |
| 171 base::TimeDelta::FromMicroseconds(++input_pts)); | 170 base::TimeDelta::FromMicroseconds(++input_pts)); |
| 172 | 171 |
| 173 status = media_codec->DequeueInputBuffer(InfiniteTimeOut(), &input_buf_index); | 172 status = media_codec->DequeueInputBuffer(InfiniteTimeOut(), &input_buf_index); |
| 174 media_codec->QueueInputBuffer(input_buf_index, test_mp3, sizeof(test_mp3), | 173 media_codec->QueueInputBuffer(input_buf_index, test_mp3, sizeof(test_mp3), |
| 175 base::TimeDelta::FromMicroseconds(++input_pts)); | 174 base::TimeDelta::FromMicroseconds(++input_pts)); |
| 176 | 175 |
| 177 status = media_codec->DequeueInputBuffer(InfiniteTimeOut(), &input_buf_index); | 176 status = media_codec->DequeueInputBuffer(InfiniteTimeOut(), &input_buf_index); |
| 178 media_codec->QueueEOS(input_buf_index); | 177 media_codec->QueueEOS(input_buf_index); |
| 179 | 178 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 210 ASSERT_EQ(input_pts, kPresentationTimeBase + 2); | 209 ASSERT_EQ(input_pts, kPresentationTimeBase + 2); |
| 211 } | 210 } |
| 212 | 211 |
| 213 TEST(SdkMediaCodecBridgeTest, InvalidVorbisHeader) { | 212 TEST(SdkMediaCodecBridgeTest, InvalidVorbisHeader) { |
| 214 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 213 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 215 | 214 |
| 216 scoped_ptr<media::AudioCodecBridge> media_codec; | 215 scoped_ptr<media::AudioCodecBridge> media_codec; |
| 217 media_codec.reset(AudioCodecBridge::Create(kCodecVorbis)); | 216 media_codec.reset(AudioCodecBridge::Create(kCodecVorbis)); |
| 218 | 217 |
| 219 // The first byte of the header is not 0x02. | 218 // The first byte of the header is not 0x02. |
| 220 uint8 invalid_first_byte[] = {0x00, 0xff, 0xff, 0xff, 0xff}; | 219 uint8_t invalid_first_byte[] = {0x00, 0xff, 0xff, 0xff, 0xff}; |
| 221 EXPECT_FALSE(media_codec->ConfigureAndStart( | 220 EXPECT_FALSE(media_codec->ConfigureAndStart( |
| 222 kCodecVorbis, 44100, 2, invalid_first_byte, sizeof(invalid_first_byte), 0, | 221 kCodecVorbis, 44100, 2, invalid_first_byte, sizeof(invalid_first_byte), 0, |
| 223 0, false, nullptr)); | 222 0, false, nullptr)); |
| 224 | 223 |
| 225 // Size of the header does not match with the data we passed in. | 224 // Size of the header does not match with the data we passed in. |
| 226 uint8 invalid_size[] = {0x02, 0x01, 0xff, 0x01, 0xff}; | 225 uint8_t invalid_size[] = {0x02, 0x01, 0xff, 0x01, 0xff}; |
| 227 EXPECT_FALSE(media_codec->ConfigureAndStart( | 226 EXPECT_FALSE(media_codec->ConfigureAndStart( |
| 228 kCodecVorbis, 44100, 2, invalid_size, sizeof(invalid_size), 0, 0, false, | 227 kCodecVorbis, 44100, 2, invalid_size, sizeof(invalid_size), 0, 0, false, |
| 229 nullptr)); | 228 nullptr)); |
| 230 | 229 |
| 231 // Size of the header is too large. | 230 // Size of the header is too large. |
| 232 size_t large_size = 8 * 1024 * 1024 + 2; | 231 size_t large_size = 8 * 1024 * 1024 + 2; |
| 233 uint8* very_large_header = new uint8[large_size]; | 232 uint8_t* very_large_header = new uint8_t[large_size]; |
| 234 very_large_header[0] = 0x02; | 233 very_large_header[0] = 0x02; |
| 235 for (size_t i = 1; i < large_size - 1; ++i) | 234 for (size_t i = 1; i < large_size - 1; ++i) |
| 236 very_large_header[i] = 0xff; | 235 very_large_header[i] = 0xff; |
| 237 very_large_header[large_size - 1] = 0xfe; | 236 very_large_header[large_size - 1] = 0xfe; |
| 238 EXPECT_FALSE(media_codec->ConfigureAndStart(kCodecVorbis, 44100, 2, | 237 EXPECT_FALSE(media_codec->ConfigureAndStart(kCodecVorbis, 44100, 2, |
| 239 very_large_header, 0x80000000, 0, | 238 very_large_header, 0x80000000, 0, |
| 240 0, false, nullptr)); | 239 0, false, nullptr)); |
| 241 delete[] very_large_header; | 240 delete[] very_large_header; |
| 242 } | 241 } |
| 243 | 242 |
| 244 TEST(SdkMediaCodecBridgeTest, InvalidOpusHeader) { | 243 TEST(SdkMediaCodecBridgeTest, InvalidOpusHeader) { |
| 245 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 244 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 246 | 245 |
| 247 scoped_ptr<media::AudioCodecBridge> media_codec; | 246 scoped_ptr<media::AudioCodecBridge> media_codec; |
| 248 media_codec.reset(AudioCodecBridge::Create(kCodecOpus)); | 247 media_codec.reset(AudioCodecBridge::Create(kCodecOpus)); |
| 249 uint8 dummy_extra_data[] = {0, 0}; | 248 uint8_t dummy_extra_data[] = {0, 0}; |
| 250 | 249 |
| 251 // Extra Data is NULL. | 250 // Extra Data is NULL. |
| 252 EXPECT_FALSE(media_codec->ConfigureAndStart(kCodecOpus, 48000, 2, nullptr, 0, | 251 EXPECT_FALSE(media_codec->ConfigureAndStart(kCodecOpus, 48000, 2, nullptr, 0, |
| 253 -1, 0, false, nullptr)); | 252 -1, 0, false, nullptr)); |
| 254 | 253 |
| 255 // Codec Delay is < 0. | 254 // Codec Delay is < 0. |
| 256 EXPECT_FALSE(media_codec->ConfigureAndStart( | 255 EXPECT_FALSE(media_codec->ConfigureAndStart( |
| 257 kCodecOpus, 48000, 2, dummy_extra_data, sizeof(dummy_extra_data), -1, 0, | 256 kCodecOpus, 48000, 2, dummy_extra_data, sizeof(dummy_extra_data), -1, 0, |
| 258 false, nullptr)); | 257 false, nullptr)); |
| 259 | 258 |
| 260 // Seek Preroll is < 0. | 259 // Seek Preroll is < 0. |
| 261 EXPECT_FALSE(media_codec->ConfigureAndStart( | 260 EXPECT_FALSE(media_codec->ConfigureAndStart( |
| 262 kCodecOpus, 48000, 2, dummy_extra_data, sizeof(dummy_extra_data), 0, -1, | 261 kCodecOpus, 48000, 2, dummy_extra_data, sizeof(dummy_extra_data), 0, -1, |
| 263 false, nullptr)); | 262 false, nullptr)); |
| 264 } | 263 } |
| 265 | 264 |
| 266 TEST(SdkMediaCodecBridgeTest, PresentationTimestampsDoNotDecrease) { | 265 TEST(SdkMediaCodecBridgeTest, PresentationTimestampsDoNotDecrease) { |
| 267 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 266 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 268 | 267 |
| 269 scoped_ptr<VideoCodecBridge> media_codec(VideoCodecBridge::CreateDecoder( | 268 scoped_ptr<VideoCodecBridge> media_codec(VideoCodecBridge::CreateDecoder( |
| 270 kCodecVP8, false, gfx::Size(320, 240), nullptr, nullptr)); | 269 kCodecVP8, false, gfx::Size(320, 240), nullptr, nullptr)); |
| 271 EXPECT_TRUE(media_codec.get()); | 270 EXPECT_TRUE(media_codec.get()); |
| 272 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("vp8-I-frame-320x240"); | 271 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("vp8-I-frame-320x240"); |
| 273 DecodeMediaFrame(media_codec.get(), buffer->data(), buffer->data_size(), | 272 DecodeMediaFrame(media_codec.get(), buffer->data(), buffer->data_size(), |
| 274 base::TimeDelta(), base::TimeDelta()); | 273 base::TimeDelta(), base::TimeDelta()); |
| 275 | 274 |
| 276 // Simulate a seek to 10 seconds, and each chunk has 2 I-frames. | 275 // Simulate a seek to 10 seconds, and each chunk has 2 I-frames. |
| 277 std::vector<uint8> chunk(buffer->data(), | 276 std::vector<uint8_t> chunk(buffer->data(), |
| 278 buffer->data() + buffer->data_size()); | 277 buffer->data() + buffer->data_size()); |
| 279 chunk.insert(chunk.end(), buffer->data(), | 278 chunk.insert(chunk.end(), buffer->data(), |
| 280 buffer->data() + buffer->data_size()); | 279 buffer->data() + buffer->data_size()); |
| 281 media_codec->Reset(); | 280 media_codec->Reset(); |
| 282 DecodeMediaFrame(media_codec.get(), &chunk[0], chunk.size(), | 281 DecodeMediaFrame(media_codec.get(), &chunk[0], chunk.size(), |
| 283 base::TimeDelta::FromMicroseconds(10000000), | 282 base::TimeDelta::FromMicroseconds(10000000), |
| 284 base::TimeDelta::FromMicroseconds(9900000)); | 283 base::TimeDelta::FromMicroseconds(9900000)); |
| 285 | 284 |
| 286 // Simulate a seek to 5 seconds. | 285 // Simulate a seek to 5 seconds. |
| 287 media_codec->Reset(); | 286 media_codec->Reset(); |
| 288 DecodeMediaFrame(media_codec.get(), &chunk[0], chunk.size(), | 287 DecodeMediaFrame(media_codec.get(), &chunk[0], chunk.size(), |
| 289 base::TimeDelta::FromMicroseconds(5000000), | 288 base::TimeDelta::FromMicroseconds(5000000), |
| 290 base::TimeDelta::FromMicroseconds(4900000)); | 289 base::TimeDelta::FromMicroseconds(4900000)); |
| 291 } | 290 } |
| 292 | 291 |
| 293 TEST(SdkMediaCodecBridgeTest, CreateUnsupportedCodec) { | 292 TEST(SdkMediaCodecBridgeTest, CreateUnsupportedCodec) { |
| 294 EXPECT_EQ(nullptr, AudioCodecBridge::Create(kUnknownAudioCodec)); | 293 EXPECT_EQ(nullptr, AudioCodecBridge::Create(kUnknownAudioCodec)); |
| 295 EXPECT_EQ(nullptr, VideoCodecBridge::CreateDecoder(kUnknownVideoCodec, false, | 294 EXPECT_EQ(nullptr, VideoCodecBridge::CreateDecoder(kUnknownVideoCodec, false, |
| 296 gfx::Size(320, 240), | 295 gfx::Size(320, 240), |
| 297 nullptr, nullptr)); | 296 nullptr, nullptr)); |
| 298 } | 297 } |
| 299 | 298 |
| 300 } // namespace media | 299 } // namespace media |
| OLD | NEW |