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 "webkit/renderer/media/android/media_source_delegate.h" | 5 #include "webkit/renderer/media/android/media_source_delegate.h" |
6 | 6 |
7 #include "base/message_loop/message_loop_proxy.h" | 7 #include "base/message_loop/message_loop_proxy.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "media/base/android/demuxer_stream_player_params.h" | 9 #include "media/base/android/demuxer_stream_player_params.h" |
10 #include "media/base/bind_to_loop.h" | 10 #include "media/base/bind_to_loop.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 int player_id, | 62 int player_id, |
63 media::MediaLog* media_log) | 63 media::MediaLog* media_log) |
64 : weak_this_(this), | 64 : weak_this_(this), |
65 proxy_(proxy), | 65 proxy_(proxy), |
66 player_id_(player_id), | 66 player_id_(player_id), |
67 media_log_(media_log), | 67 media_log_(media_log), |
68 demuxer_(NULL), | 68 demuxer_(NULL), |
69 audio_params_(new MediaPlayerHostMsg_ReadFromDemuxerAck_Params), | 69 audio_params_(new MediaPlayerHostMsg_ReadFromDemuxerAck_Params), |
70 video_params_(new MediaPlayerHostMsg_ReadFromDemuxerAck_Params), | 70 video_params_(new MediaPlayerHostMsg_ReadFromDemuxerAck_Params), |
71 seeking_(false), | 71 seeking_(false), |
72 can_start_decrypt_(false), | |
72 access_unit_size_(0) { | 73 access_unit_size_(0) { |
73 } | 74 } |
74 | 75 |
75 MediaSourceDelegate::~MediaSourceDelegate() { | 76 MediaSourceDelegate::~MediaSourceDelegate() { |
76 DVLOG(1) << "MediaSourceDelegate::~MediaSourceDelegate() : " << player_id_; | 77 DVLOG(1) << "MediaSourceDelegate::~MediaSourceDelegate() : " << player_id_; |
77 DCHECK(!chunk_demuxer_); | 78 DCHECK(!chunk_demuxer_); |
78 DCHECK(!demuxer_); | 79 DCHECK(!demuxer_); |
79 } | 80 } |
80 | 81 |
81 void MediaSourceDelegate::Destroy() { | 82 void MediaSourceDelegate::Destroy() { |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 } | 325 } |
325 | 326 |
326 void MediaSourceDelegate::OnDemuxerInitDone( | 327 void MediaSourceDelegate::OnDemuxerInitDone( |
327 media::PipelineStatus status) { | 328 media::PipelineStatus status) { |
328 DVLOG(1) << "MediaSourceDelegate::OnDemuxerInitDone(" << status << ") : " | 329 DVLOG(1) << "MediaSourceDelegate::OnDemuxerInitDone(" << status << ") : " |
329 << player_id_; | 330 << player_id_; |
330 if (status != media::PIPELINE_OK) { | 331 if (status != media::PIPELINE_OK) { |
331 OnDemuxerError(status); | 332 OnDemuxerError(status); |
332 return; | 333 return; |
333 } | 334 } |
334 NotifyDemuxerReady(""); | 335 NotifyDemuxerReady(); |
xhwang
2013/06/20 17:30:50
It appears that we NotifyDemuxerReady() multiple t
kjyoun
2013/06/21 00:05:39
Done.
| |
335 } | 336 } |
336 | 337 |
337 void MediaSourceDelegate::OnDemuxerStopDone() { | 338 void MediaSourceDelegate::OnDemuxerStopDone() { |
338 DVLOG(1) << "MediaSourceDelegate::OnDemuxerStopDone() : " << player_id_; | 339 DVLOG(1) << "MediaSourceDelegate::OnDemuxerStopDone() : " << player_id_; |
339 chunk_demuxer_.reset(); | 340 chunk_demuxer_.reset(); |
340 delete this; | 341 delete this; |
341 } | 342 } |
342 | 343 |
343 void MediaSourceDelegate::OnMediaConfigRequest() { | 344 void MediaSourceDelegate::OnMediaConfigRequest() { |
344 NotifyDemuxerReady(""); | 345 NotifyDemuxerReady(); |
346 } | |
347 | |
348 void MediaSourceDelegate::NotifyKeyAdded( | |
349 const std::string& key_system, | |
350 const std::string& session_id) { | |
351 // TODO(kjyoun): Change this logic to call NotifyDemuxerReady() when | |
352 // keys for both of audio and video are loaded, if both are encrypted. | |
353 // Currently, we notifies when the first key is loaded. | |
354 if (!can_start_decrypt_) { | |
355 can_start_decrypt_ = true; | |
356 NotifyDemuxerReady(key_system); | |
357 } | |
358 } | |
359 | |
360 bool MediaSourceDelegate::CanNotifyDemuxerReady() { | |
361 if (can_start_decrypt_) | |
362 return true; | |
363 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | |
364 if (audio_stream && audio_stream->audio_decoder_config().is_encrypted()) | |
365 return false; | |
366 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | |
367 if (video_stream && video_stream->video_decoder_config().is_encrypted()) | |
368 return false; | |
369 return true; | |
345 } | 370 } |
346 | 371 |
347 void MediaSourceDelegate::NotifyDemuxerReady(const std::string& key_system) { | 372 void MediaSourceDelegate::NotifyDemuxerReady(const std::string& key_system) { |
348 if (!demuxer_) | 373 if (!demuxer_ || !CanNotifyDemuxerReady()) |
xhwang
2013/06/20 17:30:50
I prefer DCHECK to "if". Can |demuxer| be NULL her
kjyoun
2013/06/21 00:05:39
Done.
| |
349 return; | 374 return; |
350 MediaPlayerHostMsg_DemuxerReady_Params params; | 375 MediaPlayerHostMsg_DemuxerReady_Params params; |
351 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 376 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); |
352 if (audio_stream) { | 377 if (audio_stream) { |
353 const media::AudioDecoderConfig& config = | 378 const media::AudioDecoderConfig& config = |
354 audio_stream->audio_decoder_config(); | 379 audio_stream->audio_decoder_config(); |
355 params.audio_codec = config.codec(); | 380 params.audio_codec = config.codec(); |
356 params.audio_channels = | 381 params.audio_channels = |
357 media::ChannelLayoutToChannelCount(config.channel_layout()); | 382 media::ChannelLayoutToChannelCount(config.channel_layout()); |
358 params.audio_sampling_rate = config.samples_per_second(); | 383 params.audio_sampling_rate = config.samples_per_second(); |
359 params.is_audio_encrypted = config.is_encrypted(); | 384 params.is_audio_encrypted = config.is_encrypted(); |
360 params.audio_extra_data = std::vector<uint8>( | 385 params.audio_extra_data = std::vector<uint8>( |
361 config.extra_data(), config.extra_data() + config.extra_data_size()); | 386 config.extra_data(), config.extra_data() + config.extra_data_size()); |
362 } | 387 } |
363 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 388 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); |
364 if (video_stream) { | 389 if (video_stream) { |
365 const media::VideoDecoderConfig& config = | 390 const media::VideoDecoderConfig& config = |
366 video_stream->video_decoder_config(); | 391 video_stream->video_decoder_config(); |
367 params.video_codec = config.codec(); | 392 params.video_codec = config.codec(); |
368 params.video_size = config.natural_size(); | 393 params.video_size = config.natural_size(); |
369 params.is_video_encrypted = config.is_encrypted(); | 394 params.is_video_encrypted = config.is_encrypted(); |
370 params.video_extra_data = std::vector<uint8>( | 395 params.video_extra_data = std::vector<uint8>( |
371 config.extra_data(), config.extra_data() + config.extra_data_size()); | 396 config.extra_data(), config.extra_data() + config.extra_data_size()); |
372 } | 397 } |
373 params.duration_ms = GetDurationMs(); | 398 params.duration_ms = GetDurationMs(); |
374 params.key_system = key_system; | 399 params.key_system = key_system; |
375 | 400 |
376 bool ready_to_send = (!params.is_audio_encrypted && | 401 if (proxy_) |
377 !params.is_video_encrypted) || !key_system.empty(); | |
378 if (proxy_ && ready_to_send) | |
379 proxy_->DemuxerReady(player_id_, params); | 402 proxy_->DemuxerReady(player_id_, params); |
380 } | 403 } |
381 | 404 |
382 int MediaSourceDelegate::GetDurationMs() { | 405 int MediaSourceDelegate::GetDurationMs() { |
383 if (!chunk_demuxer_) | 406 if (!chunk_demuxer_) |
384 return -1; | 407 return -1; |
385 | 408 |
386 double duration_ms = chunk_demuxer_->GetDuration() * 1000; | 409 double duration_ms = chunk_demuxer_->GetDuration() * 1000; |
387 if (duration_ms > std::numeric_limits<int32>::max()) { | 410 if (duration_ms > std::numeric_limits<int32>::max()) { |
388 LOG(WARNING) << "Duration from ChunkDemuxer is too large; probably " | 411 LOG(WARNING) << "Duration from ChunkDemuxer is too large; probably " |
(...skipping 22 matching lines...) Expand all Loading... | |
411 } | 434 } |
412 | 435 |
413 scoped_ptr<media::TextTrack> MediaSourceDelegate::OnAddTextTrack( | 436 scoped_ptr<media::TextTrack> MediaSourceDelegate::OnAddTextTrack( |
414 media::TextKind kind, | 437 media::TextKind kind, |
415 const std::string& label, | 438 const std::string& label, |
416 const std::string& language) { | 439 const std::string& language) { |
417 return scoped_ptr<media::TextTrack>(); | 440 return scoped_ptr<media::TextTrack>(); |
418 } | 441 } |
419 | 442 |
420 } // namespace webkit_media | 443 } // namespace webkit_media |
OLD | NEW |