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/webmediaplayer_impl.h" | 5 #include "content/renderer/media/webmediaplayer_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 | 110 |
111 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ | 111 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ |
112 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \ | 112 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \ |
113 static_cast<int>(BufferedResourceLoader::k ## name), \ | 113 static_cast<int>(BufferedResourceLoader::k ## name), \ |
114 mismatching_enums) | 114 mismatching_enums) |
115 COMPILE_ASSERT_MATCHING_ENUM(Unspecified); | 115 COMPILE_ASSERT_MATCHING_ENUM(Unspecified); |
116 COMPILE_ASSERT_MATCHING_ENUM(Anonymous); | 116 COMPILE_ASSERT_MATCHING_ENUM(Anonymous); |
117 COMPILE_ASSERT_MATCHING_ENUM(UseCredentials); | 117 COMPILE_ASSERT_MATCHING_ENUM(UseCredentials); |
118 #undef COMPILE_ASSERT_MATCHING_ENUM | 118 #undef COMPILE_ASSERT_MATCHING_ENUM |
119 | 119 |
120 #define BIND_TO_RENDER_LOOP(function) \ | 120 #define BIND_TO_CURRENT_LOOP(function) \ |
Ami GONE FROM CHROMIUM
2014/01/08 21:37:41
"CURRENT" is less informative at the callsite than
scherkus (not reviewing)
2014/01/09 01:52:02
I really like the DCHECK() idea, but since this ma
| |
121 media::BindToLoop(main_loop_, base::Bind(function, AsWeakPtr())) | 121 media::BindToCurrentLoop(base::Bind(function, AsWeakPtr())) |
122 | |
123 #define BIND_TO_RENDER_LOOP_1(function, arg1) \ | |
124 media::BindToLoop(main_loop_, base::Bind(function, AsWeakPtr(), arg1)) | |
125 | |
126 #define BIND_TO_RENDER_LOOP_2(function, arg1, arg2) \ | |
127 media::BindToLoop(main_loop_, base::Bind(function, AsWeakPtr(), arg1, arg2)) | |
128 | 122 |
129 static void LogMediaSourceError(const scoped_refptr<media::MediaLog>& media_log, | 123 static void LogMediaSourceError(const scoped_refptr<media::MediaLog>& media_log, |
130 const std::string& error) { | 124 const std::string& error) { |
131 media_log->AddEvent(media_log->CreateMediaSourceErrorEvent(error)); | 125 media_log->AddEvent(media_log->CreateMediaSourceErrorEvent(error)); |
132 } | 126 } |
133 | 127 |
134 WebMediaPlayerImpl::WebMediaPlayerImpl( | 128 WebMediaPlayerImpl::WebMediaPlayerImpl( |
135 content::RenderView* render_view, | 129 content::RenderView* render_view, |
136 blink::WebFrame* frame, | 130 blink::WebFrame* frame, |
137 blink::WebMediaPlayerClient* client, | 131 blink::WebMediaPlayerClient* client, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 FROM_HERE, | 180 FROM_HERE, |
187 base::Bind(&WebMediaPlayerImpl::IncrementExternallyAllocatedMemory, | 181 base::Bind(&WebMediaPlayerImpl::IncrementExternallyAllocatedMemory, |
188 AsWeakPtr())); | 182 AsWeakPtr())); |
189 | 183 |
190 if (blink::WebRuntimeFeatures::isPrefixedEncryptedMediaEnabled()) { | 184 if (blink::WebRuntimeFeatures::isPrefixedEncryptedMediaEnabled()) { |
191 decryptor_.reset(new ProxyDecryptor( | 185 decryptor_.reset(new ProxyDecryptor( |
192 #if defined(ENABLE_PEPPER_CDMS) | 186 #if defined(ENABLE_PEPPER_CDMS) |
193 client, | 187 client, |
194 frame, | 188 frame, |
195 #endif | 189 #endif |
196 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyAdded), | 190 BIND_TO_CURRENT_LOOP(&WebMediaPlayerImpl::OnKeyAdded), |
197 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyError), | 191 BIND_TO_CURRENT_LOOP(&WebMediaPlayerImpl::OnKeyError), |
198 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyMessage))); | 192 BIND_TO_CURRENT_LOOP(&WebMediaPlayerImpl::OnKeyMessage))); |
199 } | 193 } |
200 | 194 |
201 // Use the null sink if no sink was provided. | 195 // Use the null sink if no sink was provided. |
202 audio_source_provider_ = new WebAudioSourceProviderImpl( | 196 audio_source_provider_ = new WebAudioSourceProviderImpl( |
203 params.audio_renderer_sink().get() | 197 params.audio_renderer_sink().get() |
204 ? params.audio_renderer_sink() | 198 ? params.audio_renderer_sink() |
205 : new media::NullAudioSink(media_loop_)); | 199 : new media::NullAudioSink(media_loop_)); |
206 } | 200 } |
207 | 201 |
208 WebMediaPlayerImpl::~WebMediaPlayerImpl() { | 202 WebMediaPlayerImpl::~WebMediaPlayerImpl() { |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
368 paused_time_ = seek_time; | 362 paused_time_ = seek_time; |
369 | 363 |
370 seeking_ = true; | 364 seeking_ = true; |
371 | 365 |
372 if (chunk_demuxer_) | 366 if (chunk_demuxer_) |
373 chunk_demuxer_->StartWaitingForSeek(seek_time); | 367 chunk_demuxer_->StartWaitingForSeek(seek_time); |
374 | 368 |
375 // Kick off the asynchronous seek! | 369 // Kick off the asynchronous seek! |
376 pipeline_->Seek( | 370 pipeline_->Seek( |
377 seek_time, | 371 seek_time, |
378 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineSeek)); | 372 BIND_TO_CURRENT_LOOP(&WebMediaPlayerImpl::OnPipelineSeek)); |
379 } | 373 } |
380 | 374 |
381 void WebMediaPlayerImpl::setRate(double rate) { | 375 void WebMediaPlayerImpl::setRate(double rate) { |
382 DCHECK(main_loop_->BelongsToCurrentThread()); | 376 DCHECK(main_loop_->BelongsToCurrentThread()); |
383 | 377 |
384 // TODO(kylep): Remove when support for negatives is added. Also, modify the | 378 // TODO(kylep): Remove when support for negatives is added. Also, modify the |
385 // following checks so rewind uses reasonable values also. | 379 // following checks so rewind uses reasonable values also. |
386 if (rate < 0.0) | 380 if (rate < 0.0) |
387 return; | 381 return; |
388 | 382 |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1068 SetNetworkState(WebMediaPlayer::NetworkStateIdle); | 1062 SetNetworkState(WebMediaPlayer::NetworkStateIdle); |
1069 else if (is_downloading && network_state_ == WebMediaPlayer::NetworkStateIdle) | 1063 else if (is_downloading && network_state_ == WebMediaPlayer::NetworkStateIdle) |
1070 SetNetworkState(WebMediaPlayer::NetworkStateLoading); | 1064 SetNetworkState(WebMediaPlayer::NetworkStateLoading); |
1071 media_log_->AddEvent( | 1065 media_log_->AddEvent( |
1072 media_log_->CreateBooleanEvent( | 1066 media_log_->CreateBooleanEvent( |
1073 media::MediaLogEvent::NETWORK_ACTIVITY_SET, | 1067 media::MediaLogEvent::NETWORK_ACTIVITY_SET, |
1074 "is_downloading_data", is_downloading)); | 1068 "is_downloading_data", is_downloading)); |
1075 } | 1069 } |
1076 | 1070 |
1077 void WebMediaPlayerImpl::StartPipeline() { | 1071 void WebMediaPlayerImpl::StartPipeline() { |
1072 DCHECK(main_loop_->BelongsToCurrentThread()); | |
1078 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 1073 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
1079 | 1074 |
1080 // Keep track if this is a MSE or non-MSE playback. | 1075 // Keep track if this is a MSE or non-MSE playback. |
1081 UMA_HISTOGRAM_BOOLEAN("Media.MSE.Playback", | 1076 UMA_HISTOGRAM_BOOLEAN("Media.MSE.Playback", |
1082 (load_type_ == LoadTypeMediaSource)); | 1077 (load_type_ == LoadTypeMediaSource)); |
1083 | 1078 |
1084 // Figure out which demuxer to use. | 1079 // Figure out which demuxer to use. |
1085 if (load_type_ != LoadTypeMediaSource) { | 1080 if (load_type_ != LoadTypeMediaSource) { |
1086 DCHECK(!chunk_demuxer_); | 1081 DCHECK(!chunk_demuxer_); |
1087 DCHECK(data_source_); | 1082 DCHECK(data_source_); |
1088 | 1083 |
1089 demuxer_.reset(new media::FFmpegDemuxer( | 1084 demuxer_.reset(new media::FFmpegDemuxer( |
1090 media_loop_, data_source_.get(), | 1085 media_loop_, data_source_.get(), |
1091 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNeedKey), | 1086 BIND_TO_CURRENT_LOOP(&WebMediaPlayerImpl::OnNeedKey), |
1092 media_log_)); | 1087 media_log_)); |
1093 } else { | 1088 } else { |
1094 DCHECK(!chunk_demuxer_); | 1089 DCHECK(!chunk_demuxer_); |
1095 DCHECK(!data_source_); | 1090 DCHECK(!data_source_); |
1096 | 1091 |
1097 chunk_demuxer_ = new media::ChunkDemuxer( | 1092 chunk_demuxer_ = new media::ChunkDemuxer( |
1098 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDemuxerOpened), | 1093 BIND_TO_CURRENT_LOOP(&WebMediaPlayerImpl::OnDemuxerOpened), |
1099 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNeedKey), | 1094 BIND_TO_CURRENT_LOOP(&WebMediaPlayerImpl::OnNeedKey), |
1100 base::Bind(&LogMediaSourceError, media_log_)); | 1095 base::Bind(&LogMediaSourceError, media_log_)); |
1101 demuxer_.reset(chunk_demuxer_); | 1096 demuxer_.reset(chunk_demuxer_); |
1102 } | 1097 } |
1103 | 1098 |
1104 scoped_ptr<media::FilterCollection> filter_collection( | 1099 scoped_ptr<media::FilterCollection> filter_collection( |
1105 new media::FilterCollection()); | 1100 new media::FilterCollection()); |
1106 filter_collection->SetDemuxer(demuxer_.get()); | 1101 filter_collection->SetDemuxer(demuxer_.get()); |
1107 | 1102 |
1108 // Figure out if EME is enabled. | 1103 // Figure out if EME is enabled. |
1109 media::SetDecryptorReadyCB set_decryptor_ready_cb; | 1104 media::SetDecryptorReadyCB set_decryptor_ready_cb; |
(...skipping 29 matching lines...) Expand all Loading... | |
1139 #endif // !defined(MEDIA_DISABLE_LIBVPX) | 1134 #endif // !defined(MEDIA_DISABLE_LIBVPX) |
1140 | 1135 |
1141 video_decoders.push_back(new media::FFmpegVideoDecoder(media_loop_)); | 1136 video_decoders.push_back(new media::FFmpegVideoDecoder(media_loop_)); |
1142 | 1137 |
1143 scoped_ptr<media::VideoRenderer> video_renderer( | 1138 scoped_ptr<media::VideoRenderer> video_renderer( |
1144 new media::VideoRendererImpl( | 1139 new media::VideoRendererImpl( |
1145 media_loop_, | 1140 media_loop_, |
1146 video_decoders.Pass(), | 1141 video_decoders.Pass(), |
1147 set_decryptor_ready_cb, | 1142 set_decryptor_ready_cb, |
1148 base::Bind(&WebMediaPlayerImpl::FrameReady, base::Unretained(this)), | 1143 base::Bind(&WebMediaPlayerImpl::FrameReady, base::Unretained(this)), |
1149 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::SetOpaque), | 1144 BIND_TO_CURRENT_LOOP(&WebMediaPlayerImpl::SetOpaque), |
1150 true)); | 1145 true)); |
1151 filter_collection->SetVideoRenderer(video_renderer.Pass()); | 1146 filter_collection->SetVideoRenderer(video_renderer.Pass()); |
1152 | 1147 |
1153 if (cmd_line->HasSwitch(switches::kEnableInbandTextTracks)) { | 1148 if (cmd_line->HasSwitch(switches::kEnableInbandTextTracks)) { |
1154 scoped_ptr<media::TextRenderer> text_renderer( | 1149 scoped_ptr<media::TextRenderer> text_renderer( |
1155 new media::TextRenderer( | 1150 new media::TextRenderer( |
1156 media_loop_, | 1151 media_loop_, |
1157 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnAddTextTrack))); | 1152 BIND_TO_CURRENT_LOOP(&WebMediaPlayerImpl::OnAddTextTrack))); |
1158 | 1153 |
1159 filter_collection->SetTextRenderer(text_renderer.Pass()); | 1154 filter_collection->SetTextRenderer(text_renderer.Pass()); |
1160 } | 1155 } |
1161 | 1156 |
1162 // ... and we're ready to go! | 1157 // ... and we're ready to go! |
1163 starting_ = true; | 1158 starting_ = true; |
1164 pipeline_->Start( | 1159 pipeline_->Start( |
1165 filter_collection.Pass(), | 1160 filter_collection.Pass(), |
1166 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineEnded), | 1161 BIND_TO_CURRENT_LOOP(&WebMediaPlayerImpl::OnPipelineEnded), |
1167 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineError), | 1162 BIND_TO_CURRENT_LOOP(&WebMediaPlayerImpl::OnPipelineError), |
1168 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineSeek), | 1163 BIND_TO_CURRENT_LOOP(&WebMediaPlayerImpl::OnPipelineSeek), |
1169 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineBufferingState), | 1164 BIND_TO_CURRENT_LOOP(&WebMediaPlayerImpl::OnPipelineBufferingState), |
1170 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDurationChange)); | 1165 BIND_TO_CURRENT_LOOP(&WebMediaPlayerImpl::OnDurationChange)); |
1171 } | 1166 } |
1172 | 1167 |
1173 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { | 1168 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { |
1174 DCHECK(main_loop_->BelongsToCurrentThread()); | 1169 DCHECK(main_loop_->BelongsToCurrentThread()); |
1175 DVLOG(1) << "SetNetworkState: " << state; | 1170 DVLOG(1) << "SetNetworkState: " << state; |
1176 network_state_ = state; | 1171 network_state_ = state; |
1177 // Always notify to ensure client has the latest value. | 1172 // Always notify to ensure client has the latest value. |
1178 client_->networkStateChanged(); | 1173 client_->networkStateChanged(); |
1179 } | 1174 } |
1180 | 1175 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1302 // The |current_frame_| wasn't painted, it is being replaced, and we haven't | 1297 // The |current_frame_| wasn't painted, it is being replaced, and we haven't |
1303 // even gotten the chance to request a repaint for it yet. Mark it as dropped. | 1298 // even gotten the chance to request a repaint for it yet. Mark it as dropped. |
1304 TRACE_EVENT0("media", "WebMediaPlayerImpl:frameDropped"); | 1299 TRACE_EVENT0("media", "WebMediaPlayerImpl:frameDropped"); |
1305 DVLOG(1) << "Frame dropped before being painted: " | 1300 DVLOG(1) << "Frame dropped before being painted: " |
1306 << current_frame_->GetTimestamp().InSecondsF(); | 1301 << current_frame_->GetTimestamp().InSecondsF(); |
1307 if (frames_dropped_before_paint_ < kuint32max) | 1302 if (frames_dropped_before_paint_ < kuint32max) |
1308 frames_dropped_before_paint_++; | 1303 frames_dropped_before_paint_++; |
1309 } | 1304 } |
1310 | 1305 |
1311 } // namespace content | 1306 } // namespace content |
OLD | NEW |