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

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

Issue 1906423005: Replace scoped_ptr with std::unique_ptr in //media/base. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scopedptr-media-base: . Created 4 years, 8 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
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 "media/base/android/sdk_media_codec_bridge.h"
6
5 #include <stddef.h> 7 #include <stddef.h>
6 #include <stdint.h> 8 #include <stdint.h>
7 9
10 #include <memory>
8 #include <string> 11 #include <string>
9 12
10 #include "base/logging.h" 13 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "media/base/android/media_codec_util.h" 14 #include "media/base/android/media_codec_util.h"
13 #include "media/base/android/sdk_media_codec_bridge.h"
14 #include "media/base/decoder_buffer.h" 15 #include "media/base/decoder_buffer.h"
15 #include "media/base/test_data_util.h" 16 #include "media/base/test_data_util.h"
16 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
17 18
18 namespace { 19 namespace {
19 20
20 // The first frame of 21 // The first frame of
21 // http://www.html5rocks.com/en/tutorials/audio/quick/test.mp3 22 // http://www.html5rocks.com/en/tutorials/audio/quick/test.mp3
22 unsigned char test_mp3[] = { 23 unsigned char test_mp3[] = {
23 0xff, 0xfb, 0xd2, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x69, 0x05, 0x00, 24 0xff, 0xfb, 0xd2, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x69, 0x05, 0x00,
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // Output time stamp should not be smaller than old timestamp. 144 // Output time stamp should not be smaller than old timestamp.
144 ASSERT_TRUE(new_timestamp >= timestamp); 145 ASSERT_TRUE(new_timestamp >= timestamp);
145 input_pts += base::TimeDelta::FromMicroseconds(33000); 146 input_pts += base::TimeDelta::FromMicroseconds(33000);
146 timestamp = new_timestamp; 147 timestamp = new_timestamp;
147 } 148 }
148 } 149 }
149 150
150 TEST(SdkMediaCodecBridgeTest, Initialize) { 151 TEST(SdkMediaCodecBridgeTest, Initialize) {
151 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 152 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
152 153
153 scoped_ptr<media::MediaCodecBridge> media_codec; 154 std::unique_ptr<media::MediaCodecBridge> media_codec;
154 media_codec.reset(VideoCodecBridge::CreateDecoder( 155 media_codec.reset(VideoCodecBridge::CreateDecoder(
155 kCodecH264, false, gfx::Size(640, 480), nullptr, nullptr)); 156 kCodecH264, false, gfx::Size(640, 480), nullptr, nullptr));
156 } 157 }
157 158
158 TEST(SdkMediaCodecBridgeTest, DoNormal) { 159 TEST(SdkMediaCodecBridgeTest, DoNormal) {
159 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 160 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
160 161
161 scoped_ptr<media::AudioCodecBridge> media_codec; 162 std::unique_ptr<media::AudioCodecBridge> media_codec;
162 media_codec.reset(AudioCodecBridge::Create(kCodecMP3)); 163 media_codec.reset(AudioCodecBridge::Create(kCodecMP3));
163 164
164 ASSERT_TRUE(media_codec->ConfigureAndStart(kCodecMP3, 44100, 2, nullptr, 0, 0, 165 ASSERT_TRUE(media_codec->ConfigureAndStart(kCodecMP3, 44100, 2, nullptr, 0, 0,
165 0, false, nullptr)); 166 0, false, nullptr));
166 167
167 int input_buf_index = -1; 168 int input_buf_index = -1;
168 MediaCodecStatus status = 169 MediaCodecStatus status =
169 media_codec->DequeueInputBuffer(InfiniteTimeOut(), &input_buf_index); 170 media_codec->DequeueInputBuffer(InfiniteTimeOut(), &input_buf_index);
170 ASSERT_EQ(MEDIA_CODEC_OK, status); 171 ASSERT_EQ(MEDIA_CODEC_OK, status);
171 ASSERT_GE(input_buf_index, 0); 172 ASSERT_GE(input_buf_index, 0);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 EXPECT_LE(1u, size); 211 EXPECT_LE(1u, size);
211 total_size += size; 212 total_size += size;
212 } 213 }
213 EXPECT_EQ(kDecodedAudioLengthInBytes, total_size); 214 EXPECT_EQ(kDecodedAudioLengthInBytes, total_size);
214 ASSERT_LE(input_pts, kMaxInputPts); 215 ASSERT_LE(input_pts, kMaxInputPts);
215 } 216 }
216 217
217 TEST(SdkMediaCodecBridgeTest, InvalidVorbisHeader) { 218 TEST(SdkMediaCodecBridgeTest, InvalidVorbisHeader) {
218 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 219 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
219 220
220 scoped_ptr<media::AudioCodecBridge> media_codec; 221 std::unique_ptr<media::AudioCodecBridge> media_codec;
221 media_codec.reset(AudioCodecBridge::Create(kCodecVorbis)); 222 media_codec.reset(AudioCodecBridge::Create(kCodecVorbis));
222 223
223 // The first byte of the header is not 0x02. 224 // The first byte of the header is not 0x02.
224 uint8_t invalid_first_byte[] = {0x00, 0xff, 0xff, 0xff, 0xff}; 225 uint8_t invalid_first_byte[] = {0x00, 0xff, 0xff, 0xff, 0xff};
225 EXPECT_FALSE(media_codec->ConfigureAndStart( 226 EXPECT_FALSE(media_codec->ConfigureAndStart(
226 kCodecVorbis, 44100, 2, invalid_first_byte, sizeof(invalid_first_byte), 0, 227 kCodecVorbis, 44100, 2, invalid_first_byte, sizeof(invalid_first_byte), 0,
227 0, false, nullptr)); 228 0, false, nullptr));
228 229
229 // Size of the header does not match with the data we passed in. 230 // Size of the header does not match with the data we passed in.
230 uint8_t invalid_size[] = {0x02, 0x01, 0xff, 0x01, 0xff}; 231 uint8_t invalid_size[] = {0x02, 0x01, 0xff, 0x01, 0xff};
(...skipping 10 matching lines...) Expand all
241 very_large_header[large_size - 1] = 0xfe; 242 very_large_header[large_size - 1] = 0xfe;
242 EXPECT_FALSE(media_codec->ConfigureAndStart(kCodecVorbis, 44100, 2, 243 EXPECT_FALSE(media_codec->ConfigureAndStart(kCodecVorbis, 44100, 2,
243 very_large_header, 0x80000000, 0, 244 very_large_header, 0x80000000, 0,
244 0, false, nullptr)); 245 0, false, nullptr));
245 delete[] very_large_header; 246 delete[] very_large_header;
246 } 247 }
247 248
248 TEST(SdkMediaCodecBridgeTest, InvalidOpusHeader) { 249 TEST(SdkMediaCodecBridgeTest, InvalidOpusHeader) {
249 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 250 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
250 251
251 scoped_ptr<media::AudioCodecBridge> media_codec; 252 std::unique_ptr<media::AudioCodecBridge> media_codec;
252 media_codec.reset(AudioCodecBridge::Create(kCodecOpus)); 253 media_codec.reset(AudioCodecBridge::Create(kCodecOpus));
253 if (!media_codec) 254 if (!media_codec)
254 return; 255 return;
255 256
256 uint8_t dummy_extra_data[] = {0, 0}; 257 uint8_t dummy_extra_data[] = {0, 0};
257 258
258 // Extra Data is NULL. 259 // Extra Data is NULL.
259 EXPECT_FALSE(media_codec->ConfigureAndStart(kCodecOpus, 48000, 2, nullptr, 0, 260 EXPECT_FALSE(media_codec->ConfigureAndStart(kCodecOpus, 48000, 2, nullptr, 0,
260 -1, 0, false, nullptr)); 261 -1, 0, false, nullptr));
261 262
262 // Codec Delay is < 0. 263 // Codec Delay is < 0.
263 EXPECT_FALSE(media_codec->ConfigureAndStart( 264 EXPECT_FALSE(media_codec->ConfigureAndStart(
264 kCodecOpus, 48000, 2, dummy_extra_data, sizeof(dummy_extra_data), -1, 0, 265 kCodecOpus, 48000, 2, dummy_extra_data, sizeof(dummy_extra_data), -1, 0,
265 false, nullptr)); 266 false, nullptr));
266 267
267 // Seek Preroll is < 0. 268 // Seek Preroll is < 0.
268 EXPECT_FALSE(media_codec->ConfigureAndStart( 269 EXPECT_FALSE(media_codec->ConfigureAndStart(
269 kCodecOpus, 48000, 2, dummy_extra_data, sizeof(dummy_extra_data), 0, -1, 270 kCodecOpus, 48000, 2, dummy_extra_data, sizeof(dummy_extra_data), 0, -1,
270 false, nullptr)); 271 false, nullptr));
271 } 272 }
272 273
273 TEST(SdkMediaCodecBridgeTest, PresentationTimestampsDoNotDecrease) { 274 TEST(SdkMediaCodecBridgeTest, PresentationTimestampsDoNotDecrease) {
274 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 275 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
275 276
276 scoped_ptr<VideoCodecBridge> media_codec(VideoCodecBridge::CreateDecoder( 277 std::unique_ptr<VideoCodecBridge> media_codec(VideoCodecBridge::CreateDecoder(
277 kCodecVP8, false, gfx::Size(320, 240), nullptr, nullptr)); 278 kCodecVP8, false, gfx::Size(320, 240), nullptr, nullptr));
278 EXPECT_TRUE(media_codec.get()); 279 EXPECT_TRUE(media_codec.get());
279 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("vp8-I-frame-320x240"); 280 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("vp8-I-frame-320x240");
280 DecodeMediaFrame(media_codec.get(), buffer->data(), buffer->data_size(), 281 DecodeMediaFrame(media_codec.get(), buffer->data(), buffer->data_size(),
281 base::TimeDelta(), base::TimeDelta()); 282 base::TimeDelta(), base::TimeDelta());
282 283
283 // Simulate a seek to 10 seconds, and each chunk has 2 I-frames. 284 // Simulate a seek to 10 seconds, and each chunk has 2 I-frames.
284 std::vector<uint8_t> chunk(buffer->data(), 285 std::vector<uint8_t> chunk(buffer->data(),
285 buffer->data() + buffer->data_size()); 286 buffer->data() + buffer->data_size());
286 chunk.insert(chunk.end(), buffer->data(), 287 chunk.insert(chunk.end(), buffer->data(),
(...skipping 11 matching lines...) Expand all
298 } 299 }
299 300
300 TEST(SdkMediaCodecBridgeTest, CreateUnsupportedCodec) { 301 TEST(SdkMediaCodecBridgeTest, CreateUnsupportedCodec) {
301 EXPECT_EQ(nullptr, AudioCodecBridge::Create(kUnknownAudioCodec)); 302 EXPECT_EQ(nullptr, AudioCodecBridge::Create(kUnknownAudioCodec));
302 EXPECT_EQ(nullptr, VideoCodecBridge::CreateDecoder(kUnknownVideoCodec, false, 303 EXPECT_EQ(nullptr, VideoCodecBridge::CreateDecoder(kUnknownVideoCodec, false,
303 gfx::Size(320, 240), 304 gfx::Size(320, 240),
304 nullptr, nullptr)); 305 nullptr, nullptr));
305 } 306 }
306 307
307 } // namespace media 308 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698