| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "media/base/android/media_codec_bridge.h" | 10 #include "media/base/android/media_codec_bridge.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 if (is_audio) { | 101 if (is_audio) { |
| 102 return reinterpret_cast<MediaDecoderJob*>( | 102 return reinterpret_cast<MediaDecoderJob*>( |
| 103 player_->audio_decoder_job_.get()); | 103 player_->audio_decoder_job_.get()); |
| 104 } | 104 } |
| 105 return reinterpret_cast<MediaDecoderJob*>( | 105 return reinterpret_cast<MediaDecoderJob*>( |
| 106 player_->video_decoder_job_.get()); | 106 player_->video_decoder_job_.get()); |
| 107 } | 107 } |
| 108 | 108 |
| 109 // Starts an audio decoder job. | 109 // Starts an audio decoder job. |
| 110 void StartAudioDecoderJob() { | 110 void StartAudioDecoderJob() { |
| 111 MediaPlayerHostMsg_DemuxerReady_Params params; | 111 DemuxerConfigs configs; |
| 112 params.audio_codec = kCodecVorbis; | 112 configs.audio_codec = kCodecVorbis; |
| 113 params.audio_channels = 2; | 113 configs.audio_channels = 2; |
| 114 params.audio_sampling_rate = 44100; | 114 configs.audio_sampling_rate = 44100; |
| 115 params.is_audio_encrypted = false; | 115 configs.is_audio_encrypted = false; |
| 116 params.duration_ms = kDefaultDurationInMs; | 116 configs.duration_ms = kDefaultDurationInMs; |
| 117 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("vorbis-extradata"); | 117 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("vorbis-extradata"); |
| 118 params.audio_extra_data = std::vector<uint8>( | 118 configs.audio_extra_data = std::vector<uint8>( |
| 119 buffer->data(), | 119 buffer->data(), |
| 120 buffer->data() + buffer->data_size()); | 120 buffer->data() + buffer->data_size()); |
| 121 Start(params); | 121 Start(configs); |
| 122 } | 122 } |
| 123 | 123 |
| 124 void StartVideoDecoderJob() { | 124 void StartVideoDecoderJob() { |
| 125 MediaPlayerHostMsg_DemuxerReady_Params params; | 125 DemuxerConfigs configs; |
| 126 params.video_codec = kCodecVP8; | 126 configs.video_codec = kCodecVP8; |
| 127 params.video_size = gfx::Size(320, 240); | 127 configs.video_size = gfx::Size(320, 240); |
| 128 params.is_video_encrypted = false; | 128 configs.is_video_encrypted = false; |
| 129 params.duration_ms = kDefaultDurationInMs; | 129 configs.duration_ms = kDefaultDurationInMs; |
| 130 Start(params); | 130 Start(configs); |
| 131 } | 131 } |
| 132 | 132 |
| 133 // Starts decoding the data. | 133 // Starts decoding the data. |
| 134 void Start(const MediaPlayerHostMsg_DemuxerReady_Params& params) { | 134 void Start(const DemuxerConfigs& configs) { |
| 135 player_->DemuxerReady(params); | 135 player_->DemuxerReady(configs); |
| 136 player_->Start(); | 136 player_->Start(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 MediaPlayerHostMsg_ReadFromDemuxerAck_Params | 139 DemuxerData CreateReadFromDemuxerAckForAudio(int packet_id) { |
| 140 CreateReadFromDemuxerAckForAudio(int packet_id) { | 140 DemuxerData data; |
| 141 MediaPlayerHostMsg_ReadFromDemuxerAck_Params ack_params; | 141 data.type = DemuxerStream::AUDIO; |
| 142 ack_params.type = DemuxerStream::AUDIO; | 142 data.access_units.resize(1); |
| 143 ack_params.access_units.resize(1); | 143 data.access_units[0].status = DemuxerStream::kOk; |
| 144 ack_params.access_units[0].status = DemuxerStream::kOk; | |
| 145 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile( | 144 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile( |
| 146 base::StringPrintf("vorbis-packet-%d", packet_id)); | 145 base::StringPrintf("vorbis-packet-%d", packet_id)); |
| 147 ack_params.access_units[0].data = std::vector<uint8>( | 146 data.access_units[0].data = std::vector<uint8>( |
| 148 buffer->data(), buffer->data() + buffer->data_size()); | 147 buffer->data(), buffer->data() + buffer->data_size()); |
| 149 // Vorbis needs 4 extra bytes padding on Android to decode properly. Check | 148 // Vorbis needs 4 extra bytes padding on Android to decode properly. Check |
| 150 // NuMediaExtractor.cpp in Android source code. | 149 // NuMediaExtractor.cpp in Android source code. |
| 151 uint8 padding[4] = { 0xff , 0xff , 0xff , 0xff }; | 150 uint8 padding[4] = { 0xff , 0xff , 0xff , 0xff }; |
| 152 ack_params.access_units[0].data.insert( | 151 data.access_units[0].data.insert( |
| 153 ack_params.access_units[0].data.end(), padding, padding + 4); | 152 data.access_units[0].data.end(), padding, padding + 4); |
| 154 return ack_params; | 153 return data; |
| 155 } | 154 } |
| 156 | 155 |
| 157 MediaPlayerHostMsg_ReadFromDemuxerAck_Params | 156 DemuxerData CreateReadFromDemuxerAckForVideo() { |
| 158 CreateReadFromDemuxerAckForVideo() { | 157 DemuxerData data; |
| 159 MediaPlayerHostMsg_ReadFromDemuxerAck_Params ack_params; | 158 data.type = DemuxerStream::VIDEO; |
| 160 ack_params.type = DemuxerStream::VIDEO; | 159 data.access_units.resize(1); |
| 161 ack_params.access_units.resize(1); | 160 data.access_units[0].status = DemuxerStream::kOk; |
| 162 ack_params.access_units[0].status = DemuxerStream::kOk; | |
| 163 scoped_refptr<DecoderBuffer> buffer = | 161 scoped_refptr<DecoderBuffer> buffer = |
| 164 ReadTestDataFile("vp8-I-frame-320x240"); | 162 ReadTestDataFile("vp8-I-frame-320x240"); |
| 165 ack_params.access_units[0].data = std::vector<uint8>( | 163 data.access_units[0].data = std::vector<uint8>( |
| 166 buffer->data(), buffer->data() + buffer->data_size()); | 164 buffer->data(), buffer->data() + buffer->data_size()); |
| 167 return ack_params; | 165 return data; |
| 168 } | 166 } |
| 169 | 167 |
| 170 MediaPlayerHostMsg_ReadFromDemuxerAck_Params CreateEOSAck(bool is_audio) { | 168 DemuxerData CreateEOSAck(bool is_audio) { |
| 171 MediaPlayerHostMsg_ReadFromDemuxerAck_Params ack_params; | 169 DemuxerData data; |
| 172 ack_params.type = is_audio ? DemuxerStream::AUDIO : DemuxerStream::VIDEO; | 170 data.type = is_audio ? DemuxerStream::AUDIO : DemuxerStream::VIDEO; |
| 173 ack_params.access_units.resize(1); | 171 data.access_units.resize(1); |
| 174 ack_params.access_units[0].status = DemuxerStream::kOk; | 172 data.access_units[0].status = DemuxerStream::kOk; |
| 175 ack_params.access_units[0].end_of_stream = true; | 173 data.access_units[0].end_of_stream = true; |
| 176 return ack_params; | 174 return data; |
| 177 } | 175 } |
| 178 | 176 |
| 179 base::TimeTicks StartTimeTicks() { | 177 base::TimeTicks StartTimeTicks() { |
| 180 return player_->start_time_ticks_; | 178 return player_->start_time_ticks_; |
| 181 } | 179 } |
| 182 | 180 |
| 183 protected: | 181 protected: |
| 184 scoped_ptr<MockMediaPlayerManager> manager_; | 182 scoped_ptr<MockMediaPlayerManager> manager_; |
| 185 scoped_ptr<MediaSourcePlayer> player_; | 183 scoped_ptr<MediaSourcePlayer> player_; |
| 186 | 184 |
| 187 DISALLOW_COPY_AND_ASSIGN(MediaSourcePlayerTest); | 185 DISALLOW_COPY_AND_ASSIGN(MediaSourcePlayerTest); |
| 188 }; | 186 }; |
| 189 | 187 |
| 190 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithValidConfig) { | 188 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithValidConfig) { |
| 191 if (!MediaCodecBridge::IsAvailable()) | 189 if (!MediaCodecBridge::IsAvailable()) |
| 192 return; | 190 return; |
| 193 | 191 |
| 194 // Test audio decoder job will be created when codec is successfully started. | 192 // Test audio decoder job will be created when codec is successfully started. |
| 195 StartAudioDecoderJob(); | 193 StartAudioDecoderJob(); |
| 196 EXPECT_TRUE(NULL != GetMediaDecoderJob(true)); | 194 EXPECT_TRUE(NULL != GetMediaDecoderJob(true)); |
| 197 EXPECT_EQ(1, manager_->num_requests()); | 195 EXPECT_EQ(1, manager_->num_requests()); |
| 198 } | 196 } |
| 199 | 197 |
| 200 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithInvalidConfig) { | 198 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithInvalidConfig) { |
| 201 if (!MediaCodecBridge::IsAvailable()) | 199 if (!MediaCodecBridge::IsAvailable()) |
| 202 return; | 200 return; |
| 203 | 201 |
| 204 // Test audio decoder job will not be created when failed to start the codec. | 202 // Test audio decoder job will not be created when failed to start the codec. |
| 205 MediaPlayerHostMsg_DemuxerReady_Params params; | 203 DemuxerConfigs configs; |
| 206 params.audio_codec = kCodecVorbis; | 204 configs.audio_codec = kCodecVorbis; |
| 207 params.audio_channels = 2; | 205 configs.audio_channels = 2; |
| 208 params.audio_sampling_rate = 44100; | 206 configs.audio_sampling_rate = 44100; |
| 209 params.is_audio_encrypted = false; | 207 configs.is_audio_encrypted = false; |
| 210 params.duration_ms = kDefaultDurationInMs; | 208 configs.duration_ms = kDefaultDurationInMs; |
| 211 uint8 invalid_codec_data[] = { 0x00, 0xff, 0xff, 0xff, 0xff }; | 209 uint8 invalid_codec_data[] = { 0x00, 0xff, 0xff, 0xff, 0xff }; |
| 212 params.audio_extra_data.insert(params.audio_extra_data.begin(), | 210 configs.audio_extra_data.insert(configs.audio_extra_data.begin(), |
| 213 invalid_codec_data, invalid_codec_data + 4); | 211 invalid_codec_data, invalid_codec_data + 4); |
| 214 Start(params); | 212 Start(configs); |
| 215 EXPECT_EQ(NULL, GetMediaDecoderJob(true)); | 213 EXPECT_EQ(NULL, GetMediaDecoderJob(true)); |
| 216 EXPECT_EQ(0, manager_->num_requests()); | 214 EXPECT_EQ(0, manager_->num_requests()); |
| 217 } | 215 } |
| 218 | 216 |
| 219 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithValidSurface) { | 217 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithValidSurface) { |
| 220 if (!MediaCodecBridge::IsAvailable()) | 218 if (!MediaCodecBridge::IsAvailable()) |
| 221 return; | 219 return; |
| 222 | 220 |
| 223 // Test video decoder job will be created when surface is valid. | 221 // Test video decoder job will be created when surface is valid. |
| 224 scoped_refptr<gfx::SurfaceTexture> surface_texture( | 222 scoped_refptr<gfx::SurfaceTexture> surface_texture( |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 player_->OnSeekRequestAck(manager_->last_seek_request_id()); | 298 player_->OnSeekRequestAck(manager_->last_seek_request_id()); |
| 301 EXPECT_TRUE(NULL != GetMediaDecoderJob(false)); | 299 EXPECT_TRUE(NULL != GetMediaDecoderJob(false)); |
| 302 EXPECT_EQ(1, manager_->num_requests()); | 300 EXPECT_EQ(1, manager_->num_requests()); |
| 303 } | 301 } |
| 304 | 302 |
| 305 TEST_F(MediaSourcePlayerTest, StartAfterSeekFinish) { | 303 TEST_F(MediaSourcePlayerTest, StartAfterSeekFinish) { |
| 306 if (!MediaCodecBridge::IsAvailable()) | 304 if (!MediaCodecBridge::IsAvailable()) |
| 307 return; | 305 return; |
| 308 | 306 |
| 309 // Test decoder job will not start until all pending seek event is handled. | 307 // Test decoder job will not start until all pending seek event is handled. |
| 310 MediaPlayerHostMsg_DemuxerReady_Params params; | 308 DemuxerConfigs configs; |
| 311 params.audio_codec = kCodecVorbis; | 309 configs.audio_codec = kCodecVorbis; |
| 312 params.audio_channels = 2; | 310 configs.audio_channels = 2; |
| 313 params.audio_sampling_rate = 44100; | 311 configs.audio_sampling_rate = 44100; |
| 314 params.is_audio_encrypted = false; | 312 configs.is_audio_encrypted = false; |
| 315 params.duration_ms = kDefaultDurationInMs; | 313 configs.duration_ms = kDefaultDurationInMs; |
| 316 player_->DemuxerReady(params); | 314 player_->DemuxerReady(configs); |
| 317 EXPECT_EQ(NULL, GetMediaDecoderJob(true)); | 315 EXPECT_EQ(NULL, GetMediaDecoderJob(true)); |
| 318 EXPECT_EQ(0, manager_->num_requests()); | 316 EXPECT_EQ(0, manager_->num_requests()); |
| 319 | 317 |
| 320 // Initiate a seek | 318 // Initiate a seek |
| 321 player_->SeekTo(base::TimeDelta()); | 319 player_->SeekTo(base::TimeDelta()); |
| 322 EXPECT_EQ(1u, manager_->last_seek_request_id()); | 320 EXPECT_EQ(1u, manager_->last_seek_request_id()); |
| 323 | 321 |
| 324 player_->Start(); | 322 player_->Start(); |
| 325 EXPECT_EQ(NULL, GetMediaDecoderJob(true)); | 323 EXPECT_EQ(NULL, GetMediaDecoderJob(true)); |
| 326 EXPECT_EQ(0, manager_->num_requests()); | 324 EXPECT_EQ(0, manager_->num_requests()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 EXPECT_EQ(2, manager_->num_requests()); | 362 EXPECT_EQ(2, manager_->num_requests()); |
| 365 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding()); | 363 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding()); |
| 366 } | 364 } |
| 367 | 365 |
| 368 TEST_F(MediaSourcePlayerTest, DecoderJobsCannotStartWithoutAudio) { | 366 TEST_F(MediaSourcePlayerTest, DecoderJobsCannotStartWithoutAudio) { |
| 369 if (!MediaCodecBridge::IsAvailable()) | 367 if (!MediaCodecBridge::IsAvailable()) |
| 370 return; | 368 return; |
| 371 | 369 |
| 372 // Test that when Start() is called, video decoder jobs will wait for audio | 370 // Test that when Start() is called, video decoder jobs will wait for audio |
| 373 // decoder job before start decoding the data. | 371 // decoder job before start decoding the data. |
| 374 MediaPlayerHostMsg_DemuxerReady_Params params; | 372 DemuxerConfigs configs; |
| 375 params.audio_codec = kCodecVorbis; | 373 configs.audio_codec = kCodecVorbis; |
| 376 params.audio_channels = 2; | 374 configs.audio_channels = 2; |
| 377 params.audio_sampling_rate = 44100; | 375 configs.audio_sampling_rate = 44100; |
| 378 params.is_audio_encrypted = false; | 376 configs.is_audio_encrypted = false; |
| 379 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("vorbis-extradata"); | 377 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("vorbis-extradata"); |
| 380 params.audio_extra_data = std::vector<uint8>( | 378 configs.audio_extra_data = std::vector<uint8>( |
| 381 buffer->data(), | 379 buffer->data(), |
| 382 buffer->data() + buffer->data_size()); | 380 buffer->data() + buffer->data_size()); |
| 383 params.video_codec = kCodecVP8; | 381 configs.video_codec = kCodecVP8; |
| 384 params.video_size = gfx::Size(320, 240); | 382 configs.video_size = gfx::Size(320, 240); |
| 385 params.is_video_encrypted = false; | 383 configs.is_video_encrypted = false; |
| 386 params.duration_ms = kDefaultDurationInMs; | 384 configs.duration_ms = kDefaultDurationInMs; |
| 387 Start(params); | 385 Start(configs); |
| 388 EXPECT_EQ(0, manager_->num_requests()); | 386 EXPECT_EQ(0, manager_->num_requests()); |
| 389 | 387 |
| 390 scoped_refptr<gfx::SurfaceTexture> surface_texture( | 388 scoped_refptr<gfx::SurfaceTexture> surface_texture( |
| 391 new gfx::SurfaceTexture(0)); | 389 new gfx::SurfaceTexture(0)); |
| 392 gfx::ScopedJavaSurface surface(surface_texture.get()); | 390 gfx::ScopedJavaSurface surface(surface_texture.get()); |
| 393 player_->SetVideoSurface(surface.Pass()); | 391 player_->SetVideoSurface(surface.Pass()); |
| 394 EXPECT_EQ(1u, manager_->last_seek_request_id()); | 392 EXPECT_EQ(1u, manager_->last_seek_request_id()); |
| 395 player_->OnSeekRequestAck(manager_->last_seek_request_id()); | 393 player_->OnSeekRequestAck(manager_->last_seek_request_id()); |
| 396 | 394 |
| 397 MediaDecoderJob* audio_decoder_job = GetMediaDecoderJob(true); | 395 MediaDecoderJob* audio_decoder_job = GetMediaDecoderJob(true); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 EXPECT_EQ(2, manager_->num_requests()); | 459 EXPECT_EQ(2, manager_->num_requests()); |
| 462 | 460 |
| 463 // Send EOS. | 461 // Send EOS. |
| 464 player_->ReadFromDemuxerAck(CreateEOSAck(false)); | 462 player_->ReadFromDemuxerAck(CreateEOSAck(false)); |
| 465 manager_->message_loop()->Run(); | 463 manager_->message_loop()->Run(); |
| 466 // No more request for data should be made. | 464 // No more request for data should be made. |
| 467 EXPECT_EQ(2, manager_->num_requests()); | 465 EXPECT_EQ(2, manager_->num_requests()); |
| 468 } | 466 } |
| 469 | 467 |
| 470 } // namespace media | 468 } // namespace media |
| OLD | NEW |