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/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "media/base/android/media_codec_bridge.h" | 9 #include "media/base/android/media_codec_bridge.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 90 |
91 namespace media { | 91 namespace media { |
92 | 92 |
93 static const int kPresentationTimeBase = 100; | 93 static const int kPresentationTimeBase = 100; |
94 | 94 |
95 TEST(MediaCodecBridgeTest, Initialize) { | 95 TEST(MediaCodecBridgeTest, Initialize) { |
96 if (!MediaCodecBridge::IsAvailable()) | 96 if (!MediaCodecBridge::IsAvailable()) |
97 return; | 97 return; |
98 | 98 |
99 scoped_ptr<media::MediaCodecBridge> media_codec; | 99 scoped_ptr<media::MediaCodecBridge> media_codec; |
100 media_codec.reset(new VideoCodecBridge(kCodecH264)); | 100 media_codec.reset(VideoCodecBridge::Create(kCodecH264)); |
101 } | 101 } |
102 | 102 |
103 TEST(MediaCodecBridgeTest, DoNormal) { | 103 TEST(MediaCodecBridgeTest, DoNormal) { |
104 if (!MediaCodecBridge::IsAvailable()) | 104 if (!MediaCodecBridge::IsAvailable()) |
105 return; | 105 return; |
106 | 106 |
107 scoped_ptr<media::AudioCodecBridge> media_codec; | 107 scoped_ptr<media::AudioCodecBridge> media_codec; |
108 media_codec.reset(new AudioCodecBridge(kCodecMP3)); | 108 media_codec.reset(AudioCodecBridge::Create(kCodecMP3)); |
109 | 109 |
110 media_codec->Start(kCodecMP3, 44100, 2, NULL, 0); | 110 media_codec->Start(kCodecMP3, 44100, 2, NULL, 0); |
111 | 111 |
112 ASSERT_GT(media_codec->GetOutputBuffers(), 0); | 112 ASSERT_GT(media_codec->GetOutputBuffers(), 0); |
113 | 113 |
114 int input_buf_index = media_codec->DequeueInputBuffer( | 114 int input_buf_index = media_codec->DequeueInputBuffer( |
115 MediaCodecBridge::kTimeOutInfinity); | 115 MediaCodecBridge::kTimeOutInfinity); |
116 ASSERT_GE(input_buf_index, 0); | 116 ASSERT_GE(input_buf_index, 0); |
117 | 117 |
118 int64 input_pts = kPresentationTimeBase; | 118 int64 input_pts = kPresentationTimeBase; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 ASSERT_LE(input_pts, kPresentationTimeBase + 2); | 157 ASSERT_LE(input_pts, kPresentationTimeBase + 2); |
158 } | 158 } |
159 ASSERT_EQ(input_pts, kPresentationTimeBase + 2); | 159 ASSERT_EQ(input_pts, kPresentationTimeBase + 2); |
160 } | 160 } |
161 | 161 |
162 TEST(MediaCodecBridgeTest, InvalidVorbisHeader) { | 162 TEST(MediaCodecBridgeTest, InvalidVorbisHeader) { |
163 if (!MediaCodecBridge::IsAvailable()) | 163 if (!MediaCodecBridge::IsAvailable()) |
164 return; | 164 return; |
165 | 165 |
166 scoped_ptr<media::AudioCodecBridge> media_codec; | 166 scoped_ptr<media::AudioCodecBridge> media_codec; |
167 media_codec.reset(new AudioCodecBridge(kCodecVorbis)); | 167 media_codec.reset(AudioCodecBridge::Create(kCodecVorbis)); |
168 | 168 |
169 // The first byte of the header is not 0x02. | 169 // The first byte of the header is not 0x02. |
170 uint8 invalid_first_byte[] = { 0x00, 0xff, 0xff, 0xff, 0xff }; | 170 uint8 invalid_first_byte[] = { 0x00, 0xff, 0xff, 0xff, 0xff }; |
171 EXPECT_FALSE(media_codec->Start( | 171 EXPECT_FALSE(media_codec->Start( |
172 kCodecVorbis, 44100, 2, invalid_first_byte, sizeof(invalid_first_byte))); | 172 kCodecVorbis, 44100, 2, invalid_first_byte, sizeof(invalid_first_byte))); |
173 | 173 |
174 // Size of the header does not match with the data we passed in. | 174 // Size of the header does not match with the data we passed in. |
175 uint8 invalid_size[] = { 0x02, 0x01, 0xff, 0x01, 0xff }; | 175 uint8 invalid_size[] = { 0x02, 0x01, 0xff, 0x01, 0xff }; |
176 EXPECT_FALSE(media_codec->Start( | 176 EXPECT_FALSE(media_codec->Start( |
177 kCodecVorbis, 44100, 2, invalid_size, sizeof(invalid_size))); | 177 kCodecVorbis, 44100, 2, invalid_size, sizeof(invalid_size))); |
178 | 178 |
179 // Size of the header is too large. | 179 // Size of the header is too large. |
180 size_t large_size = 8 * 1024 * 1024 + 2; | 180 size_t large_size = 8 * 1024 * 1024 + 2; |
181 uint8* very_large_header = new uint8[large_size]; | 181 uint8* very_large_header = new uint8[large_size]; |
182 very_large_header[0] = 0x02; | 182 very_large_header[0] = 0x02; |
183 for (size_t i = 1; i < large_size - 1; ++i) | 183 for (size_t i = 1; i < large_size - 1; ++i) |
184 very_large_header[i] = 0xff; | 184 very_large_header[i] = 0xff; |
185 very_large_header[large_size - 1] = 0xfe; | 185 very_large_header[large_size - 1] = 0xfe; |
186 EXPECT_FALSE(media_codec->Start( | 186 EXPECT_FALSE(media_codec->Start( |
187 kCodecVorbis, 44100, 2, very_large_header, 0x80000000)); | 187 kCodecVorbis, 44100, 2, very_large_header, 0x80000000)); |
188 delete[] very_large_header; | 188 delete[] very_large_header; |
189 } | 189 } |
190 | 190 |
191 } // namespace media | 191 } // namespace media |
OLD | NEW |