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 "media/base/android/media_source_player.h" | 5 #include "media/base/android/media_source_player.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 (HasVideo() && !video_decoder_job_)) { | 184 (HasVideo() && !video_decoder_job_)) { |
185 return; | 185 return; |
186 } | 186 } |
187 | 187 |
188 audio_finished_ = false; | 188 audio_finished_ = false; |
189 video_finished_ = false; | 189 video_finished_ = false; |
190 sync_decoder_jobs_ = true; | 190 sync_decoder_jobs_ = true; |
191 SyncAndStartDecoderJobs(); | 191 SyncAndStartDecoderJobs(); |
192 } | 192 } |
193 | 193 |
194 void MediaSourcePlayer::DemuxerReady( | 194 void MediaSourcePlayer::DemuxerReady(const MediaConfigs& configs) { |
195 const MediaPlayerHostMsg_DemuxerReady_Params& params) { | 195 duration_ = base::TimeDelta::FromMilliseconds(configs.duration_ms); |
196 duration_ = base::TimeDelta::FromMilliseconds(params.duration_ms); | |
197 clock_.SetDuration(duration_); | 196 clock_.SetDuration(duration_); |
198 | 197 |
199 audio_codec_ = params.audio_codec; | 198 audio_codec_ = configs.audio_codec; |
200 num_channels_ = params.audio_channels; | 199 num_channels_ = configs.audio_channels; |
201 sampling_rate_ = params.audio_sampling_rate; | 200 sampling_rate_ = configs.audio_sampling_rate; |
202 is_audio_encrypted_ = params.is_audio_encrypted; | 201 is_audio_encrypted_ = configs.is_audio_encrypted; |
203 audio_extra_data_ = params.audio_extra_data; | 202 audio_extra_data_ = configs.audio_extra_data; |
204 if (HasAudio()) { | 203 if (HasAudio()) { |
205 DCHECK_GT(num_channels_, 0); | 204 DCHECK_GT(num_channels_, 0); |
206 audio_timestamp_helper_.reset(new AudioTimestampHelper(sampling_rate_)); | 205 audio_timestamp_helper_.reset(new AudioTimestampHelper(sampling_rate_)); |
207 audio_timestamp_helper_->SetBaseTimestamp(GetCurrentTime()); | 206 audio_timestamp_helper_->SetBaseTimestamp(GetCurrentTime()); |
208 } else { | 207 } else { |
209 audio_timestamp_helper_.reset(); | 208 audio_timestamp_helper_.reset(); |
210 } | 209 } |
211 | 210 |
212 video_codec_ = params.video_codec; | 211 video_codec_ = configs.video_codec; |
213 width_ = params.video_size.width(); | 212 width_ = configs.video_size.width(); |
214 height_ = params.video_size.height(); | 213 height_ = configs.video_size.height(); |
215 is_video_encrypted_ = params.is_video_encrypted; | 214 is_video_encrypted_ = configs.is_video_encrypted; |
216 | 215 |
217 OnMediaMetadataChanged(duration_, width_, height_, true); | 216 OnMediaMetadataChanged(duration_, width_, height_, true); |
218 | 217 |
219 if (pending_event_ & CONFIG_CHANGE_EVENT_PENDING) { | 218 if (pending_event_ & CONFIG_CHANGE_EVENT_PENDING) { |
220 if (reconfig_audio_decoder_) | 219 if (reconfig_audio_decoder_) |
221 ConfigureAudioDecoderJob(); | 220 ConfigureAudioDecoderJob(); |
222 | 221 |
223 // If there is a pending surface change, we can merge it with the config | 222 // If there is a pending surface change, we can merge it with the config |
224 // change. | 223 // change. |
225 if (reconfig_video_decoder_) { | 224 if (reconfig_video_decoder_) { |
226 pending_event_ &= ~SURFACE_CHANGE_EVENT_PENDING; | 225 pending_event_ &= ~SURFACE_CHANGE_EVENT_PENDING; |
227 ConfigureVideoDecoderJob(); | 226 ConfigureVideoDecoderJob(); |
228 } | 227 } |
229 pending_event_ &= ~CONFIG_CHANGE_EVENT_PENDING; | 228 pending_event_ &= ~CONFIG_CHANGE_EVENT_PENDING; |
230 if (playing_) | 229 if (playing_) |
231 StartInternal(); | 230 StartInternal(); |
232 } | 231 } |
233 } | 232 } |
234 | 233 |
235 void MediaSourcePlayer::ReadFromDemuxerAck( | 234 void MediaSourcePlayer::ReadFromDemuxerAck(const MediaData& data) { |
236 const MediaPlayerHostMsg_ReadFromDemuxerAck_Params& params) { | 235 DCHECK_LT(0u, data.access_units.size()); |
237 DCHECK_LT(0u, params.access_units.size()); | 236 if (data.type == DemuxerStream::AUDIO) |
238 if (params.type == DemuxerStream::AUDIO) | |
239 waiting_for_audio_data_ = false; | 237 waiting_for_audio_data_ = false; |
240 else | 238 else |
241 waiting_for_video_data_ = false; | 239 waiting_for_video_data_ = false; |
242 | 240 |
243 // If there is a pending seek request, ignore the data from the chunk demuxer. | 241 // If there is a pending seek request, ignore the data from the chunk demuxer. |
244 // The data will be requested later when OnSeekRequestAck() is called. | 242 // The data will be requested later when OnSeekRequestAck() is called. |
245 if (pending_event_ & SEEK_EVENT_PENDING) | 243 if (pending_event_ & SEEK_EVENT_PENDING) |
246 return; | 244 return; |
247 | 245 |
248 if (params.type == DemuxerStream::AUDIO) { | 246 if (data.type == DemuxerStream::AUDIO) { |
249 DCHECK_EQ(0u, audio_access_unit_index_); | 247 DCHECK_EQ(0u, audio_access_unit_index_); |
250 received_audio_ = params; | 248 received_audio_ = data; |
251 } else { | 249 } else { |
252 DCHECK_EQ(0u, video_access_unit_index_); | 250 DCHECK_EQ(0u, video_access_unit_index_); |
253 received_video_ = params; | 251 received_video_ = data; |
254 } | 252 } |
255 | 253 |
256 if (pending_event_ != NO_EVENT_PENDING || !playing_) | 254 if (pending_event_ != NO_EVENT_PENDING || !playing_) |
257 return; | 255 return; |
258 | 256 |
259 if (sync_decoder_jobs_) { | 257 if (sync_decoder_jobs_) { |
260 SyncAndStartDecoderJobs(); | 258 SyncAndStartDecoderJobs(); |
261 return; | 259 return; |
262 } | 260 } |
263 | 261 |
264 if (params.type == DemuxerStream::AUDIO) | 262 if (data.type == DemuxerStream::AUDIO) |
265 DecodeMoreAudio(); | 263 DecodeMoreAudio(); |
266 else | 264 else |
267 DecodeMoreVideo(); | 265 DecodeMoreVideo(); |
268 } | 266 } |
269 | 267 |
270 void MediaSourcePlayer::DurationChanged(const base::TimeDelta& duration) { | 268 void MediaSourcePlayer::DurationChanged(const base::TimeDelta& duration) { |
271 duration_ = duration; | 269 duration_ = duration; |
272 clock_.SetDuration(duration_); | 270 clock_.SetDuration(duration_); |
273 } | 271 } |
274 | 272 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 | 423 |
426 void MediaSourcePlayer::DecodeMoreAudio() { | 424 void MediaSourcePlayer::DecodeMoreAudio() { |
427 DCHECK(!audio_decoder_job_->is_decoding()); | 425 DCHECK(!audio_decoder_job_->is_decoding()); |
428 DCHECK(HasAudioData()); | 426 DCHECK(HasAudioData()); |
429 | 427 |
430 if (DemuxerStream::kConfigChanged == | 428 if (DemuxerStream::kConfigChanged == |
431 received_audio_.access_units[audio_access_unit_index_].status) { | 429 received_audio_.access_units[audio_access_unit_index_].status) { |
432 // Wait for demuxer ready message. | 430 // Wait for demuxer ready message. |
433 reconfig_audio_decoder_ = true; | 431 reconfig_audio_decoder_ = true; |
434 pending_event_ |= CONFIG_CHANGE_EVENT_PENDING; | 432 pending_event_ |= CONFIG_CHANGE_EVENT_PENDING; |
435 received_audio_ = MediaPlayerHostMsg_ReadFromDemuxerAck_Params(); | 433 received_audio_ = MediaData(); |
436 audio_access_unit_index_ = 0; | 434 audio_access_unit_index_ = 0; |
437 ProcessPendingEvents(); | 435 ProcessPendingEvents(); |
438 return; | 436 return; |
439 } | 437 } |
440 | 438 |
441 audio_decoder_job_->Decode( | 439 audio_decoder_job_->Decode( |
442 received_audio_.access_units[audio_access_unit_index_], | 440 received_audio_.access_units[audio_access_unit_index_], |
443 start_time_ticks_, start_presentation_timestamp_, | 441 start_time_ticks_, start_presentation_timestamp_, |
444 base::Bind(&MediaSourcePlayer::MediaDecoderCallback, | 442 base::Bind(&MediaSourcePlayer::MediaDecoderCallback, |
445 weak_this_.GetWeakPtr(), true)); | 443 weak_this_.GetWeakPtr(), true)); |
446 } | 444 } |
447 | 445 |
448 void MediaSourcePlayer::DecodeMoreVideo() { | 446 void MediaSourcePlayer::DecodeMoreVideo() { |
449 DVLOG(1) << "DecodeMoreVideo()"; | 447 DVLOG(1) << "DecodeMoreVideo()"; |
450 DCHECK(!video_decoder_job_->is_decoding()); | 448 DCHECK(!video_decoder_job_->is_decoding()); |
451 DCHECK(HasVideoData()); | 449 DCHECK(HasVideoData()); |
452 | 450 |
453 if (DemuxerStream::kConfigChanged == | 451 if (DemuxerStream::kConfigChanged == |
454 received_video_.access_units[video_access_unit_index_].status) { | 452 received_video_.access_units[video_access_unit_index_].status) { |
455 // Wait for demuxer ready message. | 453 // Wait for demuxer ready message. |
456 reconfig_video_decoder_ = true; | 454 reconfig_video_decoder_ = true; |
457 pending_event_ |= CONFIG_CHANGE_EVENT_PENDING; | 455 pending_event_ |= CONFIG_CHANGE_EVENT_PENDING; |
458 received_video_ = MediaPlayerHostMsg_ReadFromDemuxerAck_Params(); | 456 received_video_ = MediaData(); |
459 video_access_unit_index_ = 0; | 457 video_access_unit_index_ = 0; |
460 ProcessPendingEvents(); | 458 ProcessPendingEvents(); |
461 return; | 459 return; |
462 } | 460 } |
463 | 461 |
464 DVLOG(3) << "VideoDecoderJob::Decode(" << video_access_unit_index_ << ", " | 462 DVLOG(3) << "VideoDecoderJob::Decode(" << video_access_unit_index_ << ", " |
465 << start_time_ticks_.ToInternalValue() << ", " | 463 << start_time_ticks_.ToInternalValue() << ", " |
466 << start_presentation_timestamp_.InMilliseconds() << ")"; | 464 << start_presentation_timestamp_.InMilliseconds() << ")"; |
467 video_decoder_job_->Decode( | 465 video_decoder_job_->Decode( |
468 received_video_.access_units[video_access_unit_index_], | 466 received_video_.access_units[video_access_unit_index_], |
(...skipping 16 matching lines...) Expand all Loading... |
485 } | 483 } |
486 } | 484 } |
487 | 485 |
488 void MediaSourcePlayer::ClearDecodingData() { | 486 void MediaSourcePlayer::ClearDecodingData() { |
489 DVLOG(1) << "ClearDecodingData()"; | 487 DVLOG(1) << "ClearDecodingData()"; |
490 if (audio_decoder_job_) | 488 if (audio_decoder_job_) |
491 audio_decoder_job_->Flush(); | 489 audio_decoder_job_->Flush(); |
492 if (video_decoder_job_) | 490 if (video_decoder_job_) |
493 video_decoder_job_->Flush(); | 491 video_decoder_job_->Flush(); |
494 start_time_ticks_ = base::TimeTicks(); | 492 start_time_ticks_ = base::TimeTicks(); |
495 received_audio_ = MediaPlayerHostMsg_ReadFromDemuxerAck_Params(); | 493 received_audio_ = MediaData(); |
496 received_video_ = MediaPlayerHostMsg_ReadFromDemuxerAck_Params(); | 494 received_video_ = MediaData(); |
497 audio_access_unit_index_ = 0; | 495 audio_access_unit_index_ = 0; |
498 video_access_unit_index_ = 0; | 496 video_access_unit_index_ = 0; |
499 waiting_for_audio_data_ = false; | 497 waiting_for_audio_data_ = false; |
500 waiting_for_video_data_ = false; | 498 waiting_for_video_data_ = false; |
501 } | 499 } |
502 | 500 |
503 bool MediaSourcePlayer::HasVideo() { | 501 bool MediaSourcePlayer::HasVideo() { |
504 return kUnknownVideoCodec != video_codec_; | 502 return kUnknownVideoCodec != video_codec_; |
505 } | 503 } |
506 | 504 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 } | 619 } |
622 | 620 |
623 void MediaSourcePlayer::RequestAudioData() { | 621 void MediaSourcePlayer::RequestAudioData() { |
624 DVLOG(2) << "RequestAudioData()"; | 622 DVLOG(2) << "RequestAudioData()"; |
625 DCHECK(HasAudio()); | 623 DCHECK(HasAudio()); |
626 | 624 |
627 if (waiting_for_audio_data_) | 625 if (waiting_for_audio_data_) |
628 return; | 626 return; |
629 | 627 |
630 manager()->OnReadFromDemuxer(player_id(), DemuxerStream::AUDIO); | 628 manager()->OnReadFromDemuxer(player_id(), DemuxerStream::AUDIO); |
631 received_audio_ = MediaPlayerHostMsg_ReadFromDemuxerAck_Params(); | 629 received_audio_ = MediaData(); |
632 audio_access_unit_index_ = 0; | 630 audio_access_unit_index_ = 0; |
633 waiting_for_audio_data_ = true; | 631 waiting_for_audio_data_ = true; |
634 } | 632 } |
635 | 633 |
636 void MediaSourcePlayer::RequestVideoData() { | 634 void MediaSourcePlayer::RequestVideoData() { |
637 DVLOG(2) << "RequestVideoData()"; | 635 DVLOG(2) << "RequestVideoData()"; |
638 DCHECK(HasVideo()); | 636 DCHECK(HasVideo()); |
639 if (waiting_for_video_data_) | 637 if (waiting_for_video_data_) |
640 return; | 638 return; |
641 | 639 |
642 manager()->OnReadFromDemuxer(player_id(), DemuxerStream::VIDEO); | 640 manager()->OnReadFromDemuxer(player_id(), DemuxerStream::VIDEO); |
643 received_video_ = MediaPlayerHostMsg_ReadFromDemuxerAck_Params(); | 641 received_video_ = MediaData(); |
644 video_access_unit_index_ = 0; | 642 video_access_unit_index_ = 0; |
645 waiting_for_video_data_ = true; | 643 waiting_for_video_data_ = true; |
646 } | 644 } |
647 | 645 |
648 bool MediaSourcePlayer::HasAudioData() const { | 646 bool MediaSourcePlayer::HasAudioData() const { |
649 return audio_access_unit_index_ < received_audio_.access_units.size(); | 647 return audio_access_unit_index_ < received_audio_.access_units.size(); |
650 } | 648 } |
651 | 649 |
652 bool MediaSourcePlayer::HasVideoData() const { | 650 bool MediaSourcePlayer::HasVideoData() const { |
653 return video_access_unit_index_ < received_video_.access_units.size(); | 651 return video_access_unit_index_ < received_video_.access_units.size(); |
654 } | 652 } |
655 | 653 |
656 void MediaSourcePlayer::SetVolumeInternal() { | 654 void MediaSourcePlayer::SetVolumeInternal() { |
657 if (audio_decoder_job_ && volume_ >= 0) | 655 if (audio_decoder_job_ && volume_ >= 0) |
658 audio_decoder_job_.get()->SetVolume(volume_); | 656 audio_decoder_job_.get()->SetVolume(volume_); |
659 } | 657 } |
660 | 658 |
661 bool MediaSourcePlayer::IsProtectedSurfaceRequired() { | 659 bool MediaSourcePlayer::IsProtectedSurfaceRequired() { |
662 return is_video_encrypted_ && | 660 return is_video_encrypted_ && |
663 drm_bridge_ && drm_bridge_->IsProtectedSurfaceRequired(); | 661 drm_bridge_ && drm_bridge_->IsProtectedSurfaceRequired(); |
664 } | 662 } |
665 | 663 |
666 } // namespace media | 664 } // namespace media |
OLD | NEW |