| 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 "content/renderer/media/android/media_source_delegate.h" | 5 #include "content/renderer/media/android/media_source_delegate.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 // The size of the access unit to transfer in an IPC in case of MediaSource. | 33 // The size of the access unit to transfer in an IPC in case of MediaSource. |
| 34 // 4: approximately 64ms of content in 60 fps movies. | 34 // 4: approximately 64ms of content in 60 fps movies. |
| 35 const size_t kAccessUnitSizeForMediaSource = 4; | 35 const size_t kAccessUnitSizeForMediaSource = 4; |
| 36 | 36 |
| 37 const uint8 kVorbisPadding[] = { 0xff, 0xff, 0xff, 0xff }; | 37 const uint8 kVorbisPadding[] = { 0xff, 0xff, 0xff, 0xff }; |
| 38 | 38 |
| 39 } // namespace | 39 } // namespace |
| 40 | 40 |
| 41 namespace content { | 41 namespace content { |
| 42 | 42 |
| 43 static void AddLogEntry(const scoped_refptr<media::MediaLog>& media_log, |
| 44 media::MediaLog::MediaLogLevel level, |
| 45 const std::string& message) { |
| 46 media_log->AddEvent(media_log->CreateLogEvent(level, message)); |
| 47 } |
| 48 |
| 43 MediaSourceDelegate::MediaSourceDelegate( | 49 MediaSourceDelegate::MediaSourceDelegate( |
| 44 RendererDemuxerAndroid* demuxer_client, | 50 RendererDemuxerAndroid* demuxer_client, |
| 45 int demuxer_client_id, | 51 int demuxer_client_id, |
| 46 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner, | 52 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner, |
| 47 const scoped_refptr<media::MediaLog> media_log) | 53 const scoped_refptr<media::MediaLog> media_log) |
| 48 : demuxer_client_(demuxer_client), | 54 : demuxer_client_(demuxer_client), |
| 49 demuxer_client_id_(demuxer_client_id), | 55 demuxer_client_id_(demuxer_client_id), |
| 50 media_log_(media_log), | 56 media_log_(media_log), |
| 51 is_demuxer_ready_(false), | 57 is_demuxer_ready_(false), |
| 52 audio_stream_(NULL), | 58 audio_stream_(NULL), |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 duration_change_cb_ = duration_change_cb; | 164 duration_change_cb_ = duration_change_cb; |
| 159 waiting_for_decryption_key_cb_ = | 165 waiting_for_decryption_key_cb_ = |
| 160 media::BindToCurrentLoop(waiting_for_decryption_key_cb); | 166 media::BindToCurrentLoop(waiting_for_decryption_key_cb); |
| 161 access_unit_size_ = kAccessUnitSizeForMediaSource; | 167 access_unit_size_ = kAccessUnitSizeForMediaSource; |
| 162 | 168 |
| 163 chunk_demuxer_.reset(new media::ChunkDemuxer( | 169 chunk_demuxer_.reset(new media::ChunkDemuxer( |
| 164 media::BindToCurrentLoop( | 170 media::BindToCurrentLoop( |
| 165 base::Bind(&MediaSourceDelegate::OnDemuxerOpened, main_weak_this_)), | 171 base::Bind(&MediaSourceDelegate::OnDemuxerOpened, main_weak_this_)), |
| 166 media::BindToCurrentLoop(base::Bind( | 172 media::BindToCurrentLoop(base::Bind( |
| 167 &MediaSourceDelegate::OnEncryptedMediaInitData, main_weak_this_)), | 173 &MediaSourceDelegate::OnEncryptedMediaInitData, main_weak_this_)), |
| 168 base::Bind(&media::MediaLog::AddLogEvent, media_log_), media_log_, | 174 base::Bind(&AddLogEntry, media_log_), media_log_, false)); |
| 169 false)); | |
| 170 | 175 |
| 171 // |this| will be retained until StopDemuxer() is posted, so Unretained() is | 176 // |this| will be retained until StopDemuxer() is posted, so Unretained() is |
| 172 // safe here. | 177 // safe here. |
| 173 media_task_runner_->PostTask(FROM_HERE, | 178 media_task_runner_->PostTask(FROM_HERE, |
| 174 base::Bind(&MediaSourceDelegate::InitializeDemuxer, | 179 base::Bind(&MediaSourceDelegate::InitializeDemuxer, |
| 175 base::Unretained(this))); | 180 base::Unretained(this))); |
| 176 } | 181 } |
| 177 | 182 |
| 178 void MediaSourceDelegate::InitializeDemuxer() { | 183 void MediaSourceDelegate::InitializeDemuxer() { |
| 179 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 184 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 | 663 |
| 659 return media::ConvertSecondsToTimestamp(duration); | 664 return media::ConvertSecondsToTimestamp(duration); |
| 660 } | 665 } |
| 661 | 666 |
| 662 void MediaSourceDelegate::OnDemuxerOpened() { | 667 void MediaSourceDelegate::OnDemuxerOpened() { |
| 663 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 668 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 664 if (media_source_opened_cb_.is_null()) | 669 if (media_source_opened_cb_.is_null()) |
| 665 return; | 670 return; |
| 666 | 671 |
| 667 media_source_opened_cb_.Run(new media::WebMediaSourceImpl( | 672 media_source_opened_cb_.Run(new media::WebMediaSourceImpl( |
| 668 chunk_demuxer_.get(), | 673 chunk_demuxer_.get(), base::Bind(&AddLogEntry, media_log_))); |
| 669 base::Bind(&media::MediaLog::AddLogEvent, media_log_))); | |
| 670 } | 674 } |
| 671 | 675 |
| 672 void MediaSourceDelegate::OnEncryptedMediaInitData( | 676 void MediaSourceDelegate::OnEncryptedMediaInitData( |
| 673 const std::string& init_data_type, | 677 const std::string& init_data_type, |
| 674 const std::vector<uint8>& init_data) { | 678 const std::vector<uint8>& init_data) { |
| 675 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 679 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 676 if (encrypted_media_init_data_cb_.is_null()) | 680 if (encrypted_media_init_data_cb_.is_null()) |
| 677 return; | 681 return; |
| 678 | 682 |
| 679 encrypted_media_init_data_cb_.Run(init_data_type, init_data); | 683 encrypted_media_init_data_cb_.Run(init_data_type, init_data); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 configs->video_size = config.natural_size(); | 758 configs->video_size = config.natural_size(); |
| 755 configs->is_video_encrypted = config.is_encrypted(); | 759 configs->is_video_encrypted = config.is_encrypted(); |
| 756 configs->video_extra_data = std::vector<uint8>( | 760 configs->video_extra_data = std::vector<uint8>( |
| 757 config.extra_data(), config.extra_data() + config.extra_data_size()); | 761 config.extra_data(), config.extra_data() + config.extra_data_size()); |
| 758 return true; | 762 return true; |
| 759 } | 763 } |
| 760 return false; | 764 return false; |
| 761 } | 765 } |
| 762 | 766 |
| 763 } // namespace content | 767 } // namespace content |
| OLD | NEW |