| 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 // 16: approximately 250ms of content in 60 fps movies. | 34 // 16: approximately 250ms of content in 60 fps movies. |
| 35 const size_t kAccessUnitSizeForMediaSource = 16; | 35 const size_t kAccessUnitSizeForMediaSource = 16; |
| 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 scoped_ptr<media::TextTrack> ReturnNullTextTrack( | |
| 44 media::TextKind kind, | |
| 45 const std::string& label, | |
| 46 const std::string& language) { | |
| 47 return scoped_ptr<media::TextTrack>(); | |
| 48 } | |
| 49 | |
| 50 static void LogMediaSourceError(const scoped_refptr<media::MediaLog>& media_log, | 43 static void LogMediaSourceError(const scoped_refptr<media::MediaLog>& media_log, |
| 51 const std::string& error) { | 44 const std::string& error) { |
| 52 media_log->AddEvent(media_log->CreateMediaSourceErrorEvent(error)); | 45 media_log->AddEvent(media_log->CreateMediaSourceErrorEvent(error)); |
| 53 } | 46 } |
| 54 | 47 |
| 55 MediaSourceDelegate::MediaSourceDelegate( | 48 MediaSourceDelegate::MediaSourceDelegate( |
| 56 RendererDemuxerAndroid* demuxer_client, | 49 RendererDemuxerAndroid* demuxer_client, |
| 57 int demuxer_client_id, | 50 int demuxer_client_id, |
| 58 const scoped_refptr<base::MessageLoopProxy>& media_loop, | 51 const scoped_refptr<base::MessageLoopProxy>& media_loop, |
| 59 media::MediaLog* media_log) | 52 media::MediaLog* media_log) |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 set_decryptor_ready_cb_ = set_decryptor_ready_cb; | 150 set_decryptor_ready_cb_ = set_decryptor_ready_cb; |
| 158 update_network_state_cb_ = media::BindToCurrentLoop(update_network_state_cb); | 151 update_network_state_cb_ = media::BindToCurrentLoop(update_network_state_cb); |
| 159 duration_change_cb_ = duration_change_cb; | 152 duration_change_cb_ = duration_change_cb; |
| 160 access_unit_size_ = kAccessUnitSizeForMediaSource; | 153 access_unit_size_ = kAccessUnitSizeForMediaSource; |
| 161 | 154 |
| 162 chunk_demuxer_.reset(new media::ChunkDemuxer( | 155 chunk_demuxer_.reset(new media::ChunkDemuxer( |
| 163 media::BindToCurrentLoop(base::Bind( | 156 media::BindToCurrentLoop(base::Bind( |
| 164 &MediaSourceDelegate::OnDemuxerOpened, main_weak_this_)), | 157 &MediaSourceDelegate::OnDemuxerOpened, main_weak_this_)), |
| 165 media::BindToCurrentLoop(base::Bind( | 158 media::BindToCurrentLoop(base::Bind( |
| 166 &MediaSourceDelegate::OnNeedKey, main_weak_this_)), | 159 &MediaSourceDelegate::OnNeedKey, main_weak_this_)), |
| 167 base::Bind(&ReturnNullTextTrack), | |
| 168 base::Bind(&LogMediaSourceError, media_log_))); | 160 base::Bind(&LogMediaSourceError, media_log_))); |
| 169 demuxer_ = chunk_demuxer_.get(); | 161 demuxer_ = chunk_demuxer_.get(); |
| 170 | 162 |
| 171 // |this| will be retained until StopDemuxer() is posted, so Unretained() is | 163 // |this| will be retained until StopDemuxer() is posted, so Unretained() is |
| 172 // safe here. | 164 // safe here. |
| 173 media_loop_->PostTask(FROM_HERE, | 165 media_loop_->PostTask(FROM_HERE, |
| 174 base::Bind(&MediaSourceDelegate::InitializeDemuxer, | 166 base::Bind(&MediaSourceDelegate::InitializeDemuxer, |
| 175 base::Unretained(this))); | 167 base::Unretained(this))); |
| 176 } | 168 } |
| 177 | 169 |
| 178 void MediaSourceDelegate::InitializeDemuxer() { | 170 void MediaSourceDelegate::InitializeDemuxer() { |
| 179 DCHECK(media_loop_->BelongsToCurrentThread()); | 171 DCHECK(media_loop_->BelongsToCurrentThread()); |
| 180 demuxer_client_->AddDelegate(demuxer_client_id_, this); | 172 demuxer_client_->AddDelegate(demuxer_client_id_, this); |
| 181 demuxer_->Initialize(this, base::Bind(&MediaSourceDelegate::OnDemuxerInitDone, | 173 demuxer_->Initialize(this, base::Bind(&MediaSourceDelegate::OnDemuxerInitDone, |
| 182 media_weak_factory_.GetWeakPtr())); | 174 media_weak_factory_.GetWeakPtr()), |
| 175 false); |
| 183 } | 176 } |
| 184 | 177 |
| 185 #if defined(GOOGLE_TV) | 178 #if defined(GOOGLE_TV) |
| 186 void MediaSourceDelegate::InitializeMediaStream( | 179 void MediaSourceDelegate::InitializeMediaStream( |
| 187 media::Demuxer* demuxer, | 180 media::Demuxer* demuxer, |
| 188 const UpdateNetworkStateCB& update_network_state_cb) { | 181 const UpdateNetworkStateCB& update_network_state_cb) { |
| 189 DCHECK(main_loop_->BelongsToCurrentThread()); | 182 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 190 DCHECK(demuxer); | 183 DCHECK(demuxer); |
| 191 demuxer_ = demuxer; | 184 demuxer_ = demuxer; |
| 192 update_network_state_cb_ = media::BindToCurrentLoop(update_network_state_cb); | 185 update_network_state_cb_ = media::BindToCurrentLoop(update_network_state_cb); |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 demuxer_client_->ReadFromDemuxerAck(demuxer_client_id_, *data); | 492 demuxer_client_->ReadFromDemuxerAck(demuxer_client_id_, *data); |
| 500 } | 493 } |
| 501 | 494 |
| 502 void MediaSourceDelegate::OnDemuxerError(media::PipelineStatus status) { | 495 void MediaSourceDelegate::OnDemuxerError(media::PipelineStatus status) { |
| 503 DVLOG(1) << __FUNCTION__ << "(" << status << ") : " << demuxer_client_id_; | 496 DVLOG(1) << __FUNCTION__ << "(" << status << ") : " << demuxer_client_id_; |
| 504 // |update_network_state_cb_| is bound to the main thread. | 497 // |update_network_state_cb_| is bound to the main thread. |
| 505 if (status != media::PIPELINE_OK && !update_network_state_cb_.is_null()) | 498 if (status != media::PIPELINE_OK && !update_network_state_cb_.is_null()) |
| 506 update_network_state_cb_.Run(PipelineErrorToNetworkState(status)); | 499 update_network_state_cb_.Run(PipelineErrorToNetworkState(status)); |
| 507 } | 500 } |
| 508 | 501 |
| 502 void MediaSourceDelegate::AddTextStream( |
| 503 media::DemuxerStream* /* text_stream */ , |
| 504 const media::TextTrackConfig& /* config */ ) { |
| 505 // TODO(matthewjheaney): add text stream (http://crbug/322115). |
| 506 NOTIMPLEMENTED(); |
| 507 } |
| 508 |
| 509 void MediaSourceDelegate::RemoveTextStream( |
| 510 media::DemuxerStream* /* text_stream */ ) { |
| 511 // TODO(matthewjheaney): remove text stream (http://crbug/322115). |
| 512 NOTIMPLEMENTED(); |
| 513 } |
| 514 |
| 509 void MediaSourceDelegate::OnDemuxerInitDone(media::PipelineStatus status) { | 515 void MediaSourceDelegate::OnDemuxerInitDone(media::PipelineStatus status) { |
| 510 DCHECK(media_loop_->BelongsToCurrentThread()); | 516 DCHECK(media_loop_->BelongsToCurrentThread()); |
| 511 DVLOG(1) << __FUNCTION__ << "(" << status << ") : " << demuxer_client_id_; | 517 DVLOG(1) << __FUNCTION__ << "(" << status << ") : " << demuxer_client_id_; |
| 512 DCHECK(demuxer_); | 518 DCHECK(demuxer_); |
| 513 | 519 |
| 514 if (status != media::PIPELINE_OK) { | 520 if (status != media::PIPELINE_OK) { |
| 515 OnDemuxerError(status); | 521 OnDemuxerError(status); |
| 516 return; | 522 return; |
| 517 } | 523 } |
| 518 | 524 |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 // current time have been garbage collected or removed by the web app, this is | 828 // current time have been garbage collected or removed by the web app, this is |
| 823 // unlikely. This may cause unexpected playback stall due to seek pending an | 829 // unlikely. This may cause unexpected playback stall due to seek pending an |
| 824 // append for a GOP prior to the last GOP demuxed. | 830 // append for a GOP prior to the last GOP demuxed. |
| 825 // TODO(wolenetz): Remove the possibility for this seek to cause unexpected | 831 // TODO(wolenetz): Remove the possibility for this seek to cause unexpected |
| 826 // player stall by replaying cached data since last keyframe in browser player | 832 // player stall by replaying cached data since last keyframe in browser player |
| 827 // rather than issuing browser seek. See http://crbug.com/304234. | 833 // rather than issuing browser seek. See http://crbug.com/304234. |
| 828 return seek_time; | 834 return seek_time; |
| 829 } | 835 } |
| 830 | 836 |
| 831 } // namespace content | 837 } // namespace content |
| OLD | NEW |