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 key_added_(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 if (CanNotifyDemuxerReady()) |
| 336 NotifyDemuxerReady(""); |
335 } | 337 } |
336 | 338 |
337 void MediaSourceDelegate::OnDemuxerStopDone() { | 339 void MediaSourceDelegate::OnDemuxerStopDone() { |
338 DVLOG(1) << "MediaSourceDelegate::OnDemuxerStopDone() : " << player_id_; | 340 DVLOG(1) << "MediaSourceDelegate::OnDemuxerStopDone() : " << player_id_; |
339 chunk_demuxer_.reset(); | 341 chunk_demuxer_.reset(); |
340 delete this; | 342 delete this; |
341 } | 343 } |
342 | 344 |
343 void MediaSourceDelegate::OnMediaConfigRequest() { | 345 void MediaSourceDelegate::OnMediaConfigRequest() { |
344 NotifyDemuxerReady(""); | 346 if (CanNotifyDemuxerReady()) |
| 347 NotifyDemuxerReady(""); |
| 348 } |
| 349 |
| 350 void MediaSourceDelegate::NotifyKeyAdded(const std::string& key_system) { |
| 351 // TODO(kjyoun): Enhance logic to detect when to call NotifyDemuxerReady() |
| 352 // For now, we calls it when the first key is added. |
| 353 if (key_added_) |
| 354 return; |
| 355 key_added_ = true; |
| 356 if (CanNotifyDemuxerReady()) |
| 357 NotifyDemuxerReady(key_system); |
| 358 } |
| 359 |
| 360 bool MediaSourceDelegate::CanNotifyDemuxerReady() { |
| 361 if (key_added_) |
| 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 DCHECK(demuxer_); |
349 return; | |
350 MediaPlayerHostMsg_DemuxerReady_Params params; | 374 MediaPlayerHostMsg_DemuxerReady_Params params; |
351 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 375 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); |
352 if (audio_stream) { | 376 if (audio_stream) { |
353 const media::AudioDecoderConfig& config = | 377 const media::AudioDecoderConfig& config = |
354 audio_stream->audio_decoder_config(); | 378 audio_stream->audio_decoder_config(); |
355 params.audio_codec = config.codec(); | 379 params.audio_codec = config.codec(); |
356 params.audio_channels = | 380 params.audio_channels = |
357 media::ChannelLayoutToChannelCount(config.channel_layout()); | 381 media::ChannelLayoutToChannelCount(config.channel_layout()); |
358 params.audio_sampling_rate = config.samples_per_second(); | 382 params.audio_sampling_rate = config.samples_per_second(); |
359 params.is_audio_encrypted = config.is_encrypted(); | 383 params.is_audio_encrypted = config.is_encrypted(); |
360 params.audio_extra_data = std::vector<uint8>( | 384 params.audio_extra_data = std::vector<uint8>( |
361 config.extra_data(), config.extra_data() + config.extra_data_size()); | 385 config.extra_data(), config.extra_data() + config.extra_data_size()); |
362 } | 386 } |
363 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 387 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); |
364 if (video_stream) { | 388 if (video_stream) { |
365 const media::VideoDecoderConfig& config = | 389 const media::VideoDecoderConfig& config = |
366 video_stream->video_decoder_config(); | 390 video_stream->video_decoder_config(); |
367 params.video_codec = config.codec(); | 391 params.video_codec = config.codec(); |
368 params.video_size = config.natural_size(); | 392 params.video_size = config.natural_size(); |
369 params.is_video_encrypted = config.is_encrypted(); | 393 params.is_video_encrypted = config.is_encrypted(); |
370 params.video_extra_data = std::vector<uint8>( | 394 params.video_extra_data = std::vector<uint8>( |
371 config.extra_data(), config.extra_data() + config.extra_data_size()); | 395 config.extra_data(), config.extra_data() + config.extra_data_size()); |
372 } | 396 } |
373 params.duration_ms = GetDurationMs(); | 397 params.duration_ms = GetDurationMs(); |
374 params.key_system = key_system; | 398 params.key_system = key_system; |
375 | 399 |
376 bool ready_to_send = (!params.is_audio_encrypted && | 400 if (proxy_) |
377 !params.is_video_encrypted) || !key_system.empty(); | |
378 if (proxy_ && ready_to_send) | |
379 proxy_->DemuxerReady(player_id_, params); | 401 proxy_->DemuxerReady(player_id_, params); |
380 } | 402 } |
381 | 403 |
382 int MediaSourceDelegate::GetDurationMs() { | 404 int MediaSourceDelegate::GetDurationMs() { |
383 if (!chunk_demuxer_) | 405 if (!chunk_demuxer_) |
384 return -1; | 406 return -1; |
385 | 407 |
386 double duration_ms = chunk_demuxer_->GetDuration() * 1000; | 408 double duration_ms = chunk_demuxer_->GetDuration() * 1000; |
387 if (duration_ms > std::numeric_limits<int32>::max()) { | 409 if (duration_ms > std::numeric_limits<int32>::max()) { |
388 LOG(WARNING) << "Duration from ChunkDemuxer is too large; probably " | 410 LOG(WARNING) << "Duration from ChunkDemuxer is too large; probably " |
(...skipping 22 matching lines...) Expand all Loading... |
411 } | 433 } |
412 | 434 |
413 scoped_ptr<media::TextTrack> MediaSourceDelegate::OnAddTextTrack( | 435 scoped_ptr<media::TextTrack> MediaSourceDelegate::OnAddTextTrack( |
414 media::TextKind kind, | 436 media::TextKind kind, |
415 const std::string& label, | 437 const std::string& label, |
416 const std::string& language) { | 438 const std::string& language) { |
417 return scoped_ptr<media::TextTrack>(); | 439 return scoped_ptr<media::TextTrack>(); |
418 } | 440 } |
419 | 441 |
420 } // namespace webkit_media | 442 } // namespace webkit_media |
OLD | NEW |