| 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 "media/blink/webmediaplayer_impl.h" | 5 #include "media/blink/webmediaplayer_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "base/task_runner_util.h" | 25 #include "base/task_runner_util.h" |
| 26 #include "base/threading/thread_task_runner_handle.h" | 26 #include "base/threading/thread_task_runner_handle.h" |
| 27 #include "base/trace_event/trace_event.h" | 27 #include "base/trace_event/trace_event.h" |
| 28 #include "build/build_config.h" | 28 #include "build/build_config.h" |
| 29 #include "cc/blink/web_layer_impl.h" | 29 #include "cc/blink/web_layer_impl.h" |
| 30 #include "cc/layers/video_layer.h" | 30 #include "cc/layers/video_layer.h" |
| 31 #include "media/audio/null_audio_sink.h" | 31 #include "media/audio/null_audio_sink.h" |
| 32 #include "media/base/bind_to_current_loop.h" | 32 #include "media/base/bind_to_current_loop.h" |
| 33 #include "media/base/cdm_context.h" | 33 #include "media/base/cdm_context.h" |
| 34 #include "media/base/content_decryption_module.h" | 34 #include "media/base/content_decryption_module.h" |
| 35 #include "media/base/demuxer.h" |
| 35 #include "media/base/limits.h" | 36 #include "media/base/limits.h" |
| 36 #include "media/base/media_content_type.h" | 37 #include "media/base/media_content_type.h" |
| 37 #include "media/base/media_log.h" | 38 #include "media/base/media_log.h" |
| 38 #include "media/base/media_switches.h" | 39 #include "media/base/media_switches.h" |
| 40 #include "media/base/media_tracks.h" |
| 39 #include "media/base/media_url_demuxer.h" | 41 #include "media/base/media_url_demuxer.h" |
| 42 #include "media/base/source_buffer.h" |
| 40 #include "media/base/text_renderer.h" | 43 #include "media/base/text_renderer.h" |
| 44 #include "media/base/text_track_config.h" |
| 41 #include "media/base/timestamp_constants.h" | 45 #include "media/base/timestamp_constants.h" |
| 42 #include "media/base/video_frame.h" | 46 #include "media/base/video_frame.h" |
| 43 #include "media/blink/texttrack_impl.h" | 47 #include "media/blink/texttrack_impl.h" |
| 44 #include "media/blink/watch_time_reporter.h" | 48 #include "media/blink/watch_time_reporter.h" |
| 45 #include "media/blink/webaudiosourceprovider_impl.h" | 49 #include "media/blink/webaudiosourceprovider_impl.h" |
| 46 #include "media/blink/webcontentdecryptionmodule_impl.h" | 50 #include "media/blink/webcontentdecryptionmodule_impl.h" |
| 47 #include "media/blink/webinbandtexttrack_impl.h" | 51 #include "media/blink/webinbandtexttrack_impl.h" |
| 48 #include "media/blink/webmediaplayer_delegate.h" | 52 #include "media/blink/webmediaplayer_delegate.h" |
| 49 #include "media/blink/webmediaplayer_util.h" | 53 #include "media/blink/webmediaplayer_util.h" |
| 50 #include "media/blink/webmediasource_impl.h" | 54 #include "media/blink/webmediasource_impl.h" |
| 51 #include "media/filters/chunk_demuxer.h" | |
| 52 #include "media/filters/ffmpeg_demuxer.h" | |
| 53 #include "third_party/WebKit/public/platform/WebEncryptedMediaTypes.h" | 55 #include "third_party/WebKit/public/platform/WebEncryptedMediaTypes.h" |
| 54 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" | 56 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" |
| 55 #include "third_party/WebKit/public/platform/WebMediaPlayerEncryptedMediaClient.
h" | 57 #include "third_party/WebKit/public/platform/WebMediaPlayerEncryptedMediaClient.
h" |
| 56 #include "third_party/WebKit/public/platform/WebMediaPlayerSource.h" | 58 #include "third_party/WebKit/public/platform/WebMediaPlayerSource.h" |
| 57 #include "third_party/WebKit/public/platform/WebMediaSource.h" | 59 #include "third_party/WebKit/public/platform/WebMediaSource.h" |
| 58 #include "third_party/WebKit/public/platform/WebRect.h" | 60 #include "third_party/WebKit/public/platform/WebRect.h" |
| 59 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 61 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
| 60 #include "third_party/WebKit/public/platform/WebSize.h" | 62 #include "third_party/WebKit/public/platform/WebSize.h" |
| 61 #include "third_party/WebKit/public/platform/WebString.h" | 63 #include "third_party/WebKit/public/platform/WebString.h" |
| 62 #include "third_party/WebKit/public/platform/WebURL.h" | 64 #include "third_party/WebKit/public/platform/WebURL.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 UrlData::CORS_UNSPECIFIED); | 165 UrlData::CORS_UNSPECIFIED); |
| 164 STATIC_ASSERT_ENUM(WebMediaPlayer::CORSModeAnonymous, UrlData::CORS_ANONYMOUS); | 166 STATIC_ASSERT_ENUM(WebMediaPlayer::CORSModeAnonymous, UrlData::CORS_ANONYMOUS); |
| 165 STATIC_ASSERT_ENUM(WebMediaPlayer::CORSModeUseCredentials, | 167 STATIC_ASSERT_ENUM(WebMediaPlayer::CORSModeUseCredentials, |
| 166 UrlData::CORS_USE_CREDENTIALS); | 168 UrlData::CORS_USE_CREDENTIALS); |
| 167 | 169 |
| 168 WebMediaPlayerImpl::WebMediaPlayerImpl( | 170 WebMediaPlayerImpl::WebMediaPlayerImpl( |
| 169 blink::WebLocalFrame* frame, | 171 blink::WebLocalFrame* frame, |
| 170 blink::WebMediaPlayerClient* client, | 172 blink::WebMediaPlayerClient* client, |
| 171 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, | 173 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, |
| 172 WebMediaPlayerDelegate* delegate, | 174 WebMediaPlayerDelegate* delegate, |
| 175 std::unique_ptr<DemuxerFactory> demuxer_factory, |
| 173 std::unique_ptr<RendererFactory> renderer_factory, | 176 std::unique_ptr<RendererFactory> renderer_factory, |
| 174 linked_ptr<UrlIndex> url_index, | 177 linked_ptr<UrlIndex> url_index, |
| 175 const WebMediaPlayerParams& params) | 178 const WebMediaPlayerParams& params) |
| 176 : frame_(frame), | 179 : frame_(frame), |
| 177 delegate_state_(DelegateState::GONE), | 180 delegate_state_(DelegateState::GONE), |
| 178 delegate_has_audio_(false), | 181 delegate_has_audio_(false), |
| 179 network_state_(WebMediaPlayer::NetworkStateEmpty), | 182 network_state_(WebMediaPlayer::NetworkStateEmpty), |
| 180 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 183 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
| 181 highest_ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 184 highest_ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
| 182 preload_(MultibufferDataSource::AUTO), | 185 preload_(MultibufferDataSource::AUTO), |
| (...skipping 25 matching lines...) Expand all Loading... |
| 208 decoder_requires_restart_for_overlay_(false), | 211 decoder_requires_restart_for_overlay_(false), |
| 209 client_(client), | 212 client_(client), |
| 210 encrypted_client_(encrypted_client), | 213 encrypted_client_(encrypted_client), |
| 211 delegate_(delegate), | 214 delegate_(delegate), |
| 212 delegate_id_(0), | 215 delegate_id_(0), |
| 213 defer_load_cb_(params.defer_load_cb()), | 216 defer_load_cb_(params.defer_load_cb()), |
| 214 context_3d_cb_(params.context_3d_cb()), | 217 context_3d_cb_(params.context_3d_cb()), |
| 215 adjust_allocated_memory_cb_(params.adjust_allocated_memory_cb()), | 218 adjust_allocated_memory_cb_(params.adjust_allocated_memory_cb()), |
| 216 last_reported_memory_usage_(0), | 219 last_reported_memory_usage_(0), |
| 217 supports_save_(true), | 220 supports_save_(true), |
| 218 chunk_demuxer_(NULL), | 221 data_source_(nullptr), |
| 222 demuxer_(nullptr), |
| 223 source_buffer_(nullptr), |
| 219 url_index_(url_index), | 224 url_index_(url_index), |
| 220 // Threaded compositing isn't enabled universally yet. | 225 // Threaded compositing isn't enabled universally yet. |
| 221 compositor_task_runner_(params.compositor_task_runner() | 226 compositor_task_runner_(params.compositor_task_runner() |
| 222 ? params.compositor_task_runner() | 227 ? params.compositor_task_runner() |
| 223 : base::ThreadTaskRunnerHandle::Get()), | 228 : base::ThreadTaskRunnerHandle::Get()), |
| 224 compositor_(new VideoFrameCompositor(compositor_task_runner_)), | 229 compositor_(new VideoFrameCompositor(compositor_task_runner_)), |
| 225 #if defined(OS_ANDROID) // WMPI_CAST | 230 #if defined(OS_ANDROID) // WMPI_CAST |
| 226 cast_impl_(this, client_, params.context_3d_cb()), | 231 cast_impl_(this, client_, params.context_3d_cb()), |
| 227 #endif | 232 #endif |
| 228 volume_(1.0), | 233 volume_(1.0), |
| 229 volume_multiplier_(1.0), | 234 volume_multiplier_(1.0), |
| 235 demuxer_factory_(std::move(demuxer_factory)), |
| 230 renderer_factory_(std::move(renderer_factory)), | 236 renderer_factory_(std::move(renderer_factory)), |
| 231 surface_manager_(params.surface_manager()), | 237 surface_manager_(params.surface_manager()), |
| 232 overlay_surface_id_(SurfaceManager::kNoSurfaceID), | 238 overlay_surface_id_(SurfaceManager::kNoSurfaceID), |
| 233 suppress_destruction_errors_(false), | 239 suppress_destruction_errors_(false), |
| 234 suspend_enabled_(params.allow_suspend()), | 240 suspend_enabled_(params.allow_suspend()), |
| 235 use_fallback_path_(false), | 241 use_fallback_path_(false), |
| 236 is_encrypted_(false), | 242 is_encrypted_(false), |
| 237 underflow_count_(0), | 243 underflow_count_(0), |
| 238 preroll_attempt_pending_(false), | 244 preroll_attempt_pending_(false), |
| 239 observer_(params.media_observer()), | 245 observer_(params.media_observer()), |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 | 509 |
| 504 // When paused, we know exactly what the current time is and can elide seeks | 510 // When paused, we know exactly what the current time is and can elide seeks |
| 505 // to it. However, there are two cases that are not elided: | 511 // to it. However, there are two cases that are not elided: |
| 506 // 1) When the pipeline state is not stable. | 512 // 1) When the pipeline state is not stable. |
| 507 // In this case we just let |pipeline_controller_| decide what to do, as | 513 // In this case we just let |pipeline_controller_| decide what to do, as |
| 508 // it has complete information. | 514 // it has complete information. |
| 509 // 2) For MSE. | 515 // 2) For MSE. |
| 510 // Because the buffers may have changed between seeks, MSE seeks are | 516 // Because the buffers may have changed between seeks, MSE seeks are |
| 511 // never elided. | 517 // never elided. |
| 512 if (paused_ && pipeline_controller_.IsStable() && paused_time_ == time && | 518 if (paused_ && pipeline_controller_.IsStable() && paused_time_ == time && |
| 513 !chunk_demuxer_) { | 519 !demuxer_) { |
| 514 // If the ready state was high enough before, we can indicate that the seek | 520 // If the ready state was high enough before, we can indicate that the seek |
| 515 // completed just by restoring it. Otherwise we will just wait for the real | 521 // completed just by restoring it. Otherwise we will just wait for the real |
| 516 // ready state change to eventually happen. | 522 // ready state change to eventually happen. |
| 517 if (old_state == ReadyStateHaveEnoughData) { | 523 if (old_state == ReadyStateHaveEnoughData) { |
| 518 main_task_runner_->PostTask( | 524 main_task_runner_->PostTask( |
| 519 FROM_HERE, base::Bind(&WebMediaPlayerImpl::OnBufferingStateChange, | 525 FROM_HERE, base::Bind(&WebMediaPlayerImpl::OnBufferingStateChange, |
| 520 AsWeakPtr(), BUFFERING_HAVE_ENOUGH)); | 526 AsWeakPtr(), BUFFERING_HAVE_ENOUGH)); |
| 521 } | 527 } |
| 522 return; | 528 return; |
| 523 } | 529 } |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 714 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 709 | 715 |
| 710 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) | 716 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) |
| 711 return std::numeric_limits<double>::quiet_NaN(); | 717 return std::numeric_limits<double>::quiet_NaN(); |
| 712 | 718 |
| 713 // Use duration from ChunkDemuxer when present. MSE allows users to specify | 719 // Use duration from ChunkDemuxer when present. MSE allows users to specify |
| 714 // duration as a double. This propagates to the rest of the pipeline as a | 720 // duration as a double. This propagates to the rest of the pipeline as a |
| 715 // TimeDelta with potentially reduced precision (limited to Microseconds). | 721 // TimeDelta with potentially reduced precision (limited to Microseconds). |
| 716 // ChunkDemuxer returns the full-precision user-specified double. This ensures | 722 // ChunkDemuxer returns the full-precision user-specified double. This ensures |
| 717 // users can "get" the exact duration they "set". | 723 // users can "get" the exact duration they "set". |
| 718 if (chunk_demuxer_) | 724 if (source_buffer_) |
| 719 return chunk_demuxer_->GetDuration(); | 725 return source_buffer_->GetDuration(); |
| 720 | 726 |
| 721 base::TimeDelta pipeline_duration = GetPipelineMediaDuration(); | 727 base::TimeDelta pipeline_duration = GetPipelineMediaDuration(); |
| 722 return pipeline_duration == kInfiniteDuration | 728 return pipeline_duration == kInfiniteDuration |
| 723 ? std::numeric_limits<double>::infinity() | 729 ? std::numeric_limits<double>::infinity() |
| 724 : pipeline_duration.InSecondsF(); | 730 : pipeline_duration.InSecondsF(); |
| 725 } | 731 } |
| 726 | 732 |
| 727 double WebMediaPlayerImpl::timelineOffset() const { | 733 double WebMediaPlayerImpl::timelineOffset() const { |
| 728 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 734 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 729 | 735 |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1004 encrypted_client_->encrypted( | 1010 encrypted_client_->encrypted( |
| 1005 ConvertToWebInitDataType(init_data_type), init_data.data(), | 1011 ConvertToWebInitDataType(init_data_type), init_data.data(), |
| 1006 base::saturated_cast<unsigned int>(init_data.size())); | 1012 base::saturated_cast<unsigned int>(init_data.size())); |
| 1007 } | 1013 } |
| 1008 | 1014 |
| 1009 void WebMediaPlayerImpl::OnFFmpegMediaTracksUpdated( | 1015 void WebMediaPlayerImpl::OnFFmpegMediaTracksUpdated( |
| 1010 std::unique_ptr<MediaTracks> tracks) { | 1016 std::unique_ptr<MediaTracks> tracks) { |
| 1011 // For MSE/chunk_demuxer case the media track updates are handled by | 1017 // For MSE/chunk_demuxer case the media track updates are handled by |
| 1012 // WebSourceBufferImpl. | 1018 // WebSourceBufferImpl. |
| 1013 DCHECK(demuxer_.get()); | 1019 DCHECK(demuxer_.get()); |
| 1014 DCHECK(!chunk_demuxer_); | 1020 DCHECK(!source_buffer_); |
| 1015 | 1021 |
| 1016 // Report the media track information to blink. | 1022 // Report the media track information to blink. |
| 1017 for (const auto& track : tracks->tracks()) { | 1023 for (const auto& track : tracks->tracks()) { |
| 1018 if (track->type() == MediaTrack::Audio) { | 1024 if (track->type() == MediaTrack::Audio) { |
| 1019 client_->addAudioTrack(blink::WebString::fromUTF8(track->id()), | 1025 client_->addAudioTrack(blink::WebString::fromUTF8(track->id()), |
| 1020 blink::WebMediaPlayerClient::AudioTrackKindMain, | 1026 blink::WebMediaPlayerClient::AudioTrackKindMain, |
| 1021 blink::WebString::fromUTF8(track->label()), | 1027 blink::WebString::fromUTF8(track->label()), |
| 1022 blink::WebString::fromUTF8(track->language()), | 1028 blink::WebString::fromUTF8(track->language()), |
| 1023 /*enabled*/ true); | 1029 /*enabled*/ true); |
| 1024 } else if (track->type() == MediaTrack::Video) { | 1030 } else if (track->type() == MediaTrack::Video) { |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1153 | 1159 |
| 1154 void WebMediaPlayerImpl::OnPipelineResumed() { | 1160 void WebMediaPlayerImpl::OnPipelineResumed() { |
| 1155 is_pipeline_resuming_ = false; | 1161 is_pipeline_resuming_ = false; |
| 1156 | 1162 |
| 1157 UpdateBackgroundVideoOptimizationState(); | 1163 UpdateBackgroundVideoOptimizationState(); |
| 1158 } | 1164 } |
| 1159 | 1165 |
| 1160 void WebMediaPlayerImpl::OnDemuxerOpened() { | 1166 void WebMediaPlayerImpl::OnDemuxerOpened() { |
| 1161 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1167 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1162 client_->mediaSourceOpened( | 1168 client_->mediaSourceOpened( |
| 1163 new WebMediaSourceImpl(chunk_demuxer_, media_log_)); | 1169 new WebMediaSourceImpl(source_buffer_, media_log_)); |
| 1164 } | 1170 } |
| 1165 | 1171 |
| 1166 void WebMediaPlayerImpl::OnMemoryPressure( | 1172 void WebMediaPlayerImpl::OnMemoryPressure( |
| 1167 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { | 1173 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
| 1168 DVLOG(2) << __func__ << " memory_pressure_level=" << memory_pressure_level; | 1174 DVLOG(2) << __func__ << " memory_pressure_level=" << memory_pressure_level; |
| 1169 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1175 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1170 DCHECK(base::FeatureList::IsEnabled(kMemoryPressureBasedSourceBufferGC)); | 1176 DCHECK(base::FeatureList::IsEnabled(kMemoryPressureBasedSourceBufferGC)); |
| 1171 DCHECK(chunk_demuxer_); | 1177 DCHECK(source_buffer_); |
| 1172 | 1178 |
| 1173 // The new value of |memory_pressure_level| will take effect on the next | 1179 // The new value of |memory_pressure_level| will take effect on the next |
| 1174 // garbage collection. Typically this means the next SourceBuffer append() | 1180 // garbage collection. Typically this means the next SourceBuffer append() |
| 1175 // operation, since per MSE spec, the garbage collection must only occur | 1181 // operation, since per MSE spec, the garbage collection must only occur |
| 1176 // during SourceBuffer append(). But if memory pressure is critical it might | 1182 // during SourceBuffer append(). But if memory pressure is critical it might |
| 1177 // be better to perform GC immediately rather than wait for the next append | 1183 // be better to perform GC immediately rather than wait for the next append |
| 1178 // and potentially get killed due to out-of-memory. | 1184 // and potentially get killed due to out-of-memory. |
| 1179 // So if this experiment is enabled and pressure level is critical, we'll pass | 1185 // So if this experiment is enabled and pressure level is critical, we'll pass |
| 1180 // down force_instant_gc==true, which will force immediate GC on | 1186 // down force_instant_gc==true, which will force immediate GC on |
| 1181 // SourceBufferStreams. | 1187 // SourceBufferStreams. |
| 1182 bool force_instant_gc = | 1188 bool force_instant_gc = |
| 1183 (enable_instant_source_buffer_gc_ && | 1189 (enable_instant_source_buffer_gc_ && |
| 1184 memory_pressure_level == | 1190 memory_pressure_level == |
| 1185 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); | 1191 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 1186 | 1192 |
| 1187 // base::Unretained is safe, since chunk_demuxer_ is actually owned by | 1193 // base::Unretained is safe, since chunk_demuxer_ is actually owned by |
| 1188 // |this| via this->demuxer_. | 1194 // |this| via this->demuxer_. |
| 1189 media_task_runner_->PostTask( | 1195 media_task_runner_->PostTask( |
| 1190 FROM_HERE, base::Bind(&ChunkDemuxer::OnMemoryPressure, | 1196 FROM_HERE, base::Bind(&media::SourceBuffer::OnMemoryPressure, |
| 1191 base::Unretained(chunk_demuxer_), | 1197 base::Unretained(source_buffer_), |
| 1192 base::TimeDelta::FromSecondsD(currentTime()), | 1198 base::TimeDelta::FromSecondsD(currentTime()), |
| 1193 memory_pressure_level, force_instant_gc)); | 1199 memory_pressure_level, force_instant_gc)); |
| 1194 } | 1200 } |
| 1195 | 1201 |
| 1196 void WebMediaPlayerImpl::OnError(PipelineStatus status) { | 1202 void WebMediaPlayerImpl::OnError(PipelineStatus status) { |
| 1197 DVLOG(1) << __func__; | 1203 DVLOG(1) << __func__; |
| 1198 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1204 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1199 DCHECK_NE(status, PIPELINE_OK); | 1205 DCHECK_NE(status, PIPELINE_OK); |
| 1200 | 1206 |
| 1201 if (suppress_destruction_errors_) | 1207 if (suppress_destruction_errors_) |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1684 set_surface_cb_ = set_surface_cb; | 1690 set_surface_cb_ = set_surface_cb; |
| 1685 | 1691 |
| 1686 // If we're waiting for the surface to arrive, OnSurfaceCreated() will be | 1692 // If we're waiting for the surface to arrive, OnSurfaceCreated() will be |
| 1687 // called later when it arrives; so do nothing for now. | 1693 // called later when it arrives; so do nothing for now. |
| 1688 if (overlay_enabled_ && overlay_surface_id_ == SurfaceManager::kNoSurfaceID) | 1694 if (overlay_enabled_ && overlay_surface_id_ == SurfaceManager::kNoSurfaceID) |
| 1689 return; | 1695 return; |
| 1690 | 1696 |
| 1691 OnSurfaceCreated(overlay_surface_id_); | 1697 OnSurfaceCreated(overlay_surface_id_); |
| 1692 } | 1698 } |
| 1693 | 1699 |
| 1700 std::unique_ptr<Demuxer> WebMediaPlayerImpl::CreateDemuxer() { |
| 1701 CHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1702 |
| 1703 if (load_type_ != LoadTypeMediaSource) { |
| 1704 return demuxer_factory_->CreateDemuxer( |
| 1705 main_task_runner_, media_task_runner_, data_source_.get(), |
| 1706 BindToCurrentLoop(base::Bind( |
| 1707 &WebMediaPlayerImpl::OnEncryptedMediaInitData, AsWeakPtr())), |
| 1708 BindToCurrentLoop(base::Bind( |
| 1709 &WebMediaPlayerImpl::OnFFmpegMediaTracksUpdated, AsWeakPtr()))); |
| 1710 } |
| 1711 |
| 1712 if (base::FeatureList::IsEnabled(kMemoryPressureBasedSourceBufferGC)) { |
| 1713 // base::Unretained is safe because |this| owns memory_pressure_listener_. |
| 1714 memory_pressure_listener_ = |
| 1715 base::MakeUnique<base::MemoryPressureListener>(base::Bind( |
| 1716 &WebMediaPlayerImpl::OnMemoryPressure, base::Unretained(this))); |
| 1717 } |
| 1718 |
| 1719 return demuxer_factory_->CreateDemuxerSourceBuffer( |
| 1720 main_task_runner_, media_task_runner_, |
| 1721 BindToCurrentLoop( |
| 1722 base::Bind(&WebMediaPlayerImpl::OnDemuxerOpened, AsWeakPtr())), |
| 1723 BindToCurrentLoop(base::Bind( |
| 1724 &WebMediaPlayerImpl::OnEncryptedMediaInitData, AsWeakPtr())), |
| 1725 &source_buffer_); |
| 1726 } |
| 1727 |
| 1694 std::unique_ptr<Renderer> WebMediaPlayerImpl::CreateRenderer() { | 1728 std::unique_ptr<Renderer> WebMediaPlayerImpl::CreateRenderer() { |
| 1695 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1729 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1696 | 1730 |
| 1697 if (force_video_overlays_) | 1731 if (force_video_overlays_) |
| 1698 EnableOverlay(); | 1732 EnableOverlay(); |
| 1699 | 1733 |
| 1700 RequestSurfaceCB request_surface_cb; | 1734 RequestSurfaceCB request_surface_cb; |
| 1701 #if defined(OS_ANDROID) | 1735 #if defined(OS_ANDROID) |
| 1702 request_surface_cb = BindToCurrentLoop( | 1736 request_surface_cb = BindToCurrentLoop( |
| 1703 base::Bind(&WebMediaPlayerImpl::OnSurfaceRequested, AsWeakPtr())); | 1737 base::Bind(&WebMediaPlayerImpl::OnSurfaceRequested, AsWeakPtr())); |
| 1704 #endif | 1738 #endif |
| 1705 return renderer_factory_->CreateRenderer( | 1739 return renderer_factory_->CreateRenderer( |
| 1706 media_task_runner_, worker_task_runner_, audio_source_provider_.get(), | 1740 media_task_runner_, worker_task_runner_, audio_source_provider_.get(), |
| 1707 compositor_, request_surface_cb); | 1741 compositor_, request_surface_cb); |
| 1708 } | 1742 } |
| 1709 | 1743 |
| 1710 void WebMediaPlayerImpl::StartPipeline() { | 1744 void WebMediaPlayerImpl::StartPipeline() { |
| 1711 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1745 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1712 | 1746 |
| 1713 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb = | |
| 1714 BindToCurrentLoop(base::Bind( | |
| 1715 &WebMediaPlayerImpl::OnEncryptedMediaInitData, AsWeakPtr())); | |
| 1716 | |
| 1717 if (use_fallback_path_) { | 1747 if (use_fallback_path_) { |
| 1718 demuxer_.reset( | 1748 demuxer_.reset( |
| 1719 new MediaUrlDemuxer(media_task_runner_, fallback_url_, | 1749 new MediaUrlDemuxer(media_task_runner_, fallback_url_, |
| 1720 frame_->document().firstPartyForCookies())); | 1750 frame_->document().firstPartyForCookies())); |
| 1721 pipeline_controller_.Start(demuxer_.get(), this, false, false); | 1751 pipeline_controller_.Start(demuxer_.get(), this, false, false); |
| 1722 return; | 1752 return; |
| 1723 } | 1753 } |
| 1724 | 1754 |
| 1725 // Figure out which demuxer to use. | 1755 demuxer_ = CreateDemuxer(); |
| 1726 if (load_type_ != LoadTypeMediaSource) { | 1756 if (!demuxer_) { |
| 1727 DCHECK(!chunk_demuxer_); | |
| 1728 DCHECK(data_source_); | |
| 1729 | |
| 1730 #if !defined(MEDIA_DISABLE_FFMPEG) | |
| 1731 Demuxer::MediaTracksUpdatedCB media_tracks_updated_cb = | |
| 1732 BindToCurrentLoop(base::Bind( | |
| 1733 &WebMediaPlayerImpl::OnFFmpegMediaTracksUpdated, AsWeakPtr())); | |
| 1734 | |
| 1735 demuxer_.reset(new FFmpegDemuxer(media_task_runner_, data_source_.get(), | |
| 1736 encrypted_media_init_data_cb, | |
| 1737 media_tracks_updated_cb, media_log_)); | |
| 1738 #else | |
| 1739 OnError(PipelineStatus::DEMUXER_ERROR_COULD_NOT_OPEN); | 1757 OnError(PipelineStatus::DEMUXER_ERROR_COULD_NOT_OPEN); |
| 1740 return; | 1758 return; |
| 1741 #endif | |
| 1742 } else { | |
| 1743 DCHECK(!chunk_demuxer_); | |
| 1744 DCHECK(!data_source_); | |
| 1745 | |
| 1746 chunk_demuxer_ = new ChunkDemuxer( | |
| 1747 BindToCurrentLoop( | |
| 1748 base::Bind(&WebMediaPlayerImpl::OnDemuxerOpened, AsWeakPtr())), | |
| 1749 encrypted_media_init_data_cb, media_log_); | |
| 1750 demuxer_.reset(chunk_demuxer_); | |
| 1751 | |
| 1752 if (base::FeatureList::IsEnabled(kMemoryPressureBasedSourceBufferGC)) { | |
| 1753 // base::Unretained is safe because |this| owns memory_pressure_listener_. | |
| 1754 memory_pressure_listener_ = | |
| 1755 base::MakeUnique<base::MemoryPressureListener>(base::Bind( | |
| 1756 &WebMediaPlayerImpl::OnMemoryPressure, base::Unretained(this))); | |
| 1757 } | |
| 1758 } | 1759 } |
| 1759 | 1760 |
| 1760 // TODO(sandersd): FileSystem objects may also be non-static, but due to our | 1761 // TODO(sandersd): FileSystem objects may also be non-static, but due to our |
| 1761 // caching layer such situations are broken already. http://crbug.com/593159 | 1762 // caching layer such situations are broken already. http://crbug.com/593159 |
| 1762 bool is_static = !chunk_demuxer_; | 1763 bool is_static = !demuxer_; |
| 1763 bool is_streaming = IsStreaming(); | 1764 bool is_streaming = IsStreaming(); |
| 1764 UMA_HISTOGRAM_BOOLEAN("Media.IsStreaming", is_streaming); | 1765 UMA_HISTOGRAM_BOOLEAN("Media.IsStreaming", is_streaming); |
| 1765 | 1766 |
| 1766 // ... and we're ready to go! | 1767 // ... and we're ready to go! |
| 1767 // TODO(sandersd): On Android, defer Start() if the tab is not visible. | 1768 // TODO(sandersd): On Android, defer Start() if the tab is not visible. |
| 1768 seeking_ = true; | 1769 seeking_ = true; |
| 1769 pipeline_controller_.Start(demuxer_.get(), this, is_streaming, is_static); | 1770 pipeline_controller_.Start(demuxer_.get(), this, is_streaming, is_static); |
| 1770 } | 1771 } |
| 1771 | 1772 |
| 1772 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { | 1773 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2109 return; | 2110 return; |
| 2110 #endif | 2111 #endif |
| 2111 | 2112 |
| 2112 // Idle timeout chosen arbitrarily. | 2113 // Idle timeout chosen arbitrarily. |
| 2113 background_pause_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(5), | 2114 background_pause_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(5), |
| 2114 this, &WebMediaPlayerImpl::OnPause); | 2115 this, &WebMediaPlayerImpl::OnPause); |
| 2115 } | 2116 } |
| 2116 | 2117 |
| 2117 void WebMediaPlayerImpl::CreateWatchTimeReporter() { | 2118 void WebMediaPlayerImpl::CreateWatchTimeReporter() { |
| 2118 // Create the watch time reporter and synchronize its initial state. | 2119 // Create the watch time reporter and synchronize its initial state. |
| 2119 watch_time_reporter_.reset(new WatchTimeReporter( | 2120 watch_time_reporter_.reset( |
| 2120 hasAudio(), hasVideo(), !!chunk_demuxer_, is_encrypted_, media_log_, | 2121 new WatchTimeReporter(hasAudio(), hasVideo(), !!demuxer_, is_encrypted_, |
| 2121 pipeline_metadata_.natural_size, | 2122 media_log_, pipeline_metadata_.natural_size, |
| 2122 base::Bind(&GetCurrentTimeInternal, this))); | 2123 base::Bind(&GetCurrentTimeInternal, this))); |
| 2123 watch_time_reporter_->OnVolumeChange(volume_); | 2124 watch_time_reporter_->OnVolumeChange(volume_); |
| 2124 if (delegate_->IsFrameHidden()) | 2125 if (delegate_->IsFrameHidden()) |
| 2125 watch_time_reporter_->OnHidden(); | 2126 watch_time_reporter_->OnHidden(); |
| 2126 else | 2127 else |
| 2127 watch_time_reporter_->OnShown(); | 2128 watch_time_reporter_->OnShown(); |
| 2128 } | 2129 } |
| 2129 | 2130 |
| 2130 bool WebMediaPlayerImpl::IsHidden() const { | 2131 bool WebMediaPlayerImpl::IsHidden() const { |
| 2131 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 2132 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 2132 | 2133 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2281 UMA_HISTOGRAM_TIMES( | 2282 UMA_HISTOGRAM_TIMES( |
| 2282 "Media.Video.TimeFromForegroundToFirstFrame.DisableTrack", | 2283 "Media.Video.TimeFromForegroundToFirstFrame.DisableTrack", |
| 2283 time_to_first_frame); | 2284 time_to_first_frame); |
| 2284 } else { | 2285 } else { |
| 2285 UMA_HISTOGRAM_TIMES("Media.Video.TimeFromForegroundToFirstFrame.Paused", | 2286 UMA_HISTOGRAM_TIMES("Media.Video.TimeFromForegroundToFirstFrame.Paused", |
| 2286 time_to_first_frame); | 2287 time_to_first_frame); |
| 2287 } | 2288 } |
| 2288 } | 2289 } |
| 2289 | 2290 |
| 2290 } // namespace media | 2291 } // namespace media |
| OLD | NEW |