| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/video_track_adapter.h" | 5 #include "content/renderer/media/video_track_adapter.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 // Min delta time between two frames allowed without being dropped if a max | 31 // Min delta time between two frames allowed without being dropped if a max |
| 32 // frame rate is specified. | 32 // frame rate is specified. |
| 33 const double kMinTimeInMsBetweenFrames = 5; | 33 const double kMinTimeInMsBetweenFrames = 5; |
| 34 // If the delta between two frames is bigger than this, we will consider it to | 34 // If the delta between two frames is bigger than this, we will consider it to |
| 35 // be invalid and reset the fps calculation. | 35 // be invalid and reset the fps calculation. |
| 36 const double kMaxTimeInMsBetweenFrames = 1000; | 36 const double kMaxTimeInMsBetweenFrames = 1000; |
| 37 | 37 |
| 38 // Empty method used for keeping a reference to the original media::VideoFrame | 38 // Empty method used for keeping a reference to the original media::VideoFrame |
| 39 // in VideoFrameResolutionAdapter::DeliverFrame if cropping is needed. | 39 // in VideoFrameResolutionAdapter::DeliverFrame if cropping is needed. |
| 40 // The reference to |frame| is kept in the closure that calls this method. | 40 // The reference to |frame| is kept in the closure that calls this method. |
| 41 void ReleaseOriginalFrame( | 41 void ReleaseOriginalFrame(const scoped_refptr<media::VideoFrame>& frame) { |
| 42 const scoped_refptr<media::VideoFrame>& frame) { | |
| 43 } | 42 } |
| 44 | 43 |
| 45 void ResetCallbackOnMainRenderThread( | 44 void ResetCallbackOnMainRenderThread( |
| 46 scoped_ptr<VideoCaptureDeliverFrameCB> callback) { | 45 scoped_ptr<VideoCaptureDeliverFrameCB> callback) { |
| 47 // |callback| will be deleted when this exits. | 46 // |callback| will be deleted when this exits. |
| 48 } | 47 } |
| 49 | 48 |
| 50 } // anonymous namespace | 49 } // anonymous namespace |
| 51 | 50 |
| 52 // VideoFrameResolutionAdapter is created on and lives on the IO-thread. It does | 51 // VideoFrameResolutionAdapter is created on and lives on the IO-thread. It does |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 // Returns |true| if the input frame rate is higher that the requested max | 94 // Returns |true| if the input frame rate is higher that the requested max |
| 96 // frame rate and |frame| should be dropped. | 95 // frame rate and |frame| should be dropped. |
| 97 bool MaybeDropFrame(const scoped_refptr<media::VideoFrame>& frame, | 96 bool MaybeDropFrame(const scoped_refptr<media::VideoFrame>& frame, |
| 98 float source_frame_rate); | 97 float source_frame_rate); |
| 99 | 98 |
| 100 // Bound to the IO-thread. | 99 // Bound to the IO-thread. |
| 101 base::ThreadChecker io_thread_checker_; | 100 base::ThreadChecker io_thread_checker_; |
| 102 | 101 |
| 103 // The task runner where we will release VideoCaptureDeliverFrameCB | 102 // The task runner where we will release VideoCaptureDeliverFrameCB |
| 104 // registered in AddCallback. | 103 // registered in AddCallback. |
| 105 scoped_refptr<base::SingleThreadTaskRunner> renderer_task_runner_; | 104 const scoped_refptr<base::SingleThreadTaskRunner> renderer_task_runner_; |
| 106 | 105 |
| 107 gfx::Size max_frame_size_; | 106 const gfx::Size max_frame_size_; |
| 108 double min_aspect_ratio_; | 107 const double min_aspect_ratio_; |
| 109 double max_aspect_ratio_; | 108 const double max_aspect_ratio_; |
| 110 | 109 |
| 111 double frame_rate_; | 110 double frame_rate_; |
| 112 base::TimeDelta last_time_stamp_; | 111 base::TimeDelta last_time_stamp_; |
| 113 double max_frame_rate_; | 112 double max_frame_rate_; |
| 114 double keep_frame_counter_; | 113 double keep_frame_counter_; |
| 115 | 114 |
| 116 typedef std::pair<const void*, VideoCaptureDeliverFrameCB> | 115 typedef std::pair<const MediaStreamVideoTrack*, VideoCaptureDeliverFrameCB> |
| 117 VideoIdCallbackPair; | 116 VideoIdCallbackPair; |
| 118 std::vector<VideoIdCallbackPair> callbacks_; | 117 std::vector<VideoIdCallbackPair> callbacks_; |
| 119 | 118 |
| 120 DISALLOW_COPY_AND_ASSIGN(VideoFrameResolutionAdapter); | 119 DISALLOW_COPY_AND_ASSIGN(VideoFrameResolutionAdapter); |
| 121 }; | 120 }; |
| 122 | 121 |
| 123 VideoTrackAdapter:: | 122 VideoTrackAdapter:: |
| 124 VideoFrameResolutionAdapter::VideoFrameResolutionAdapter( | 123 VideoFrameResolutionAdapter::VideoFrameResolutionAdapter( |
| 125 scoped_refptr<base::SingleThreadTaskRunner> render_message_loop, | 124 scoped_refptr<base::SingleThreadTaskRunner> render_message_loop, |
| 126 const gfx::Size& max_size, | 125 const gfx::Size& max_size, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 << "{ max_aspect_ratio_ =" << max_aspect_ratio_ << "}" | 160 << "{ max_aspect_ratio_ =" << max_aspect_ratio_ << "}" |
| 162 << "{ max_frame_rate_ =" << max_frame_rate_ << "}) "; | 161 << "{ max_frame_rate_ =" << max_frame_rate_ << "}) "; |
| 163 } | 162 } |
| 164 | 163 |
| 165 VideoTrackAdapter:: | 164 VideoTrackAdapter:: |
| 166 VideoFrameResolutionAdapter::~VideoFrameResolutionAdapter() { | 165 VideoFrameResolutionAdapter::~VideoFrameResolutionAdapter() { |
| 167 DCHECK(io_thread_checker_.CalledOnValidThread()); | 166 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 168 DCHECK(callbacks_.empty()); | 167 DCHECK(callbacks_.empty()); |
| 169 } | 168 } |
| 170 | 169 |
| 170 void VideoTrackAdapter::VideoFrameResolutionAdapter::AddCallback( |
| 171 const MediaStreamVideoTrack* track, |
| 172 const VideoCaptureDeliverFrameCB& callback) { |
| 173 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 174 callbacks_.push_back(std::make_pair(track, callback)); |
| 175 } |
| 176 |
| 177 void VideoTrackAdapter::VideoFrameResolutionAdapter::RemoveCallback( |
| 178 const MediaStreamVideoTrack* track) { |
| 179 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 180 std::vector<VideoIdCallbackPair>::iterator it = callbacks_.begin(); |
| 181 for (; it != callbacks_.end(); ++it) { |
| 182 if (it->first == track) { |
| 183 // Make sure the VideoCaptureDeliverFrameCB is released on the main |
| 184 // render thread since it was added on the main render thread in |
| 185 // VideoTrackAdapter::AddTrack. |
| 186 scoped_ptr<VideoCaptureDeliverFrameCB> callback( |
| 187 new VideoCaptureDeliverFrameCB(it->second)); |
| 188 callbacks_.erase(it); |
| 189 renderer_task_runner_->PostTask( |
| 190 FROM_HERE, base::Bind(&ResetCallbackOnMainRenderThread, |
| 191 base::Passed(&callback))); |
| 192 |
| 193 return; |
| 194 } |
| 195 } |
| 196 } |
| 197 |
| 171 void VideoTrackAdapter::VideoFrameResolutionAdapter::DeliverFrame( | 198 void VideoTrackAdapter::VideoFrameResolutionAdapter::DeliverFrame( |
| 172 const scoped_refptr<media::VideoFrame>& frame, | 199 const scoped_refptr<media::VideoFrame>& frame, |
| 173 const base::TimeTicks& estimated_capture_time) { | 200 const base::TimeTicks& estimated_capture_time) { |
| 174 DCHECK(io_thread_checker_.CalledOnValidThread()); | 201 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 175 | 202 |
| 176 double frame_rate; | 203 double frame_rate; |
| 177 if (!frame->metadata()->GetDouble(media::VideoFrameMetadata::FRAME_RATE, | 204 if (!frame->metadata()->GetDouble(media::VideoFrameMetadata::FRAME_RATE, |
| 178 &frame_rate)) { | 205 &frame_rate)) { |
| 179 frame_rate = MediaStreamVideoSource::kUnknownFrameRate; | 206 frame_rate = MediaStreamVideoSource::kUnknownFrameRate; |
| 180 } | 207 } |
| 208 |
| 181 if (MaybeDropFrame(frame, frame_rate)) | 209 if (MaybeDropFrame(frame, frame_rate)) |
| 182 return; | 210 return; |
| 183 | 211 |
| 184 // TODO(perkj): Allow cropping / scaling of textures once | 212 // TODO(perkj): Allow cropping / scaling of textures once |
| 185 // http://crbug/362521 is fixed. | 213 // http://crbug/362521 is fixed. |
| 186 if (frame->format() == media::VideoFrame::NATIVE_TEXTURE) { | 214 if (frame->format() == media::VideoFrame::NATIVE_TEXTURE) { |
| 187 DoDeliverFrame(frame, estimated_capture_time); | 215 DoDeliverFrame(frame, estimated_capture_time); |
| 188 return; | 216 return; |
| 189 } | 217 } |
| 190 scoped_refptr<media::VideoFrame> video_frame(frame); | 218 scoped_refptr<media::VideoFrame> video_frame(frame); |
| 191 double input_ratio = | 219 double input_ratio = |
| 192 static_cast<double>(frame->natural_size().width()) / | 220 static_cast<double>(frame->natural_size().width()) / |
| 193 frame->natural_size().height(); | 221 frame->natural_size().height(); |
| 194 | 222 |
| 195 // If |frame| has larger width or height than requested, or the aspect ratio | 223 // If |frame| has larger width or height than requested, or the aspect ratio |
| 196 // does not match the requested, we want to create a wrapped version of this | 224 // does not match the requested, we want to create a wrapped version of this |
| 197 // frame with a size that fulfills the constraints. | 225 // frame with a size that fulfills the constraints. |
| 198 if (frame->natural_size().width() > max_frame_size_.width() || | 226 if (frame->natural_size().width() > max_frame_size_.width() || |
| 199 frame->natural_size().height() > max_frame_size_.height() || | 227 frame->natural_size().height() > max_frame_size_.height() || |
| 200 input_ratio > max_aspect_ratio_ || | 228 input_ratio > max_aspect_ratio_ || |
| 201 input_ratio < min_aspect_ratio_) { | 229 input_ratio < min_aspect_ratio_) { |
| 202 int desired_width = std::min(max_frame_size_.width(), | 230 int desired_width = std::min(max_frame_size_.width(), |
| 203 frame->natural_size().width()); | 231 frame->natural_size().width()); |
| 204 int desired_height = std::min(max_frame_size_.height(), | 232 int desired_height = std::min(max_frame_size_.height(), |
| 205 frame->natural_size().height()); | 233 frame->natural_size().height()); |
| 206 | 234 |
| 207 double resulting_ratio = | 235 const double resulting_ratio = |
| 208 static_cast<double>(desired_width) / desired_height; | 236 static_cast<double>(desired_width) / desired_height; |
| 209 double requested_ratio = resulting_ratio; | 237 // Make sure |min_aspect_ratio_| < |requested_ratio| < |max_aspect_ratio_|. |
| 210 | 238 const double requested_ratio = std::max( |
| 211 if (requested_ratio > max_aspect_ratio_) | 239 std::min(resulting_ratio, max_aspect_ratio_), min_aspect_ratio_); |
| 212 requested_ratio = max_aspect_ratio_; | |
| 213 else if (requested_ratio < min_aspect_ratio_) | |
| 214 requested_ratio = min_aspect_ratio_; | |
| 215 | 240 |
| 216 if (resulting_ratio < requested_ratio) { | 241 if (resulting_ratio < requested_ratio) { |
| 217 desired_height = static_cast<int>((desired_height * resulting_ratio) / | 242 desired_height = static_cast<int>((desired_height * resulting_ratio) / |
| 218 requested_ratio); | 243 requested_ratio); |
| 219 // Make sure we scale to an even height to avoid rounding errors | 244 // Make sure we scale to an even height to avoid rounding errors |
| 220 desired_height = (desired_height + 1) & ~1; | 245 desired_height = (desired_height + 1) & ~1; |
| 221 } else if (resulting_ratio > requested_ratio) { | 246 } else if (resulting_ratio > requested_ratio) { |
| 222 desired_width = static_cast<int>((desired_width * requested_ratio) / | 247 desired_width = static_cast<int>((desired_width * requested_ratio) / |
| 223 resulting_ratio); | 248 resulting_ratio); |
| 224 // Make sure we scale to an even width to avoid rounding errors. | 249 // Make sure we scale to an even width to avoid rounding errors. |
| 225 desired_width = (desired_width + 1) & ~1; | 250 desired_width = (desired_width + 1) & ~1; |
| 226 } | 251 } |
| 227 | 252 |
| 228 gfx::Size desired_size(desired_width, desired_height); | 253 const gfx::Size desired_size(desired_width, desired_height); |
| 229 | 254 |
| 230 // Get the largest centered rectangle with the same aspect ratio of | 255 // Get the largest centered rectangle with the same aspect ratio of |
| 231 // |desired_size| that fits entirely inside of |frame->visible_rect()|. | 256 // |desired_size| that fits entirely inside of |frame->visible_rect()|. |
| 232 // This will be the rect we need to crop the original frame to. | 257 // This will be the rect we need to crop the original frame to. |
| 233 // From this rect, the original frame can be scaled down to |desired_size|. | 258 // From this rect, the original frame can be scaled down to |desired_size|. |
| 234 gfx::Rect region_in_frame = | 259 const gfx::Rect region_in_frame = |
| 235 media::ComputeLetterboxRegion(frame->visible_rect(), desired_size); | 260 media::ComputeLetterboxRegion(frame->visible_rect(), desired_size); |
| 236 | 261 |
| 237 video_frame = media::VideoFrame::WrapVideoFrame( | 262 video_frame = media::VideoFrame::WrapVideoFrame( |
| 238 frame, | 263 frame, |
| 239 region_in_frame, | 264 region_in_frame, |
| 240 desired_size, | 265 desired_size, |
| 241 base::Bind(&ReleaseOriginalFrame, frame)); | 266 base::Bind(&ReleaseOriginalFrame, frame)); |
| 242 | 267 |
| 243 DVLOG(3) << "desired size " << desired_size.ToString() | 268 DVLOG(3) << "desired size " << desired_size.ToString() |
| 244 << " output natural size " | 269 << " output natural size " |
| 245 << video_frame->natural_size().ToString() | 270 << video_frame->natural_size().ToString() |
| 246 << " output visible rect " | 271 << " output visible rect " |
| 247 << video_frame->visible_rect().ToString(); | 272 << video_frame->visible_rect().ToString(); |
| 248 } | 273 } |
| 249 DoDeliverFrame(video_frame, estimated_capture_time); | 274 DoDeliverFrame(video_frame, estimated_capture_time); |
| 250 } | 275 } |
| 251 | 276 |
| 277 bool VideoTrackAdapter::VideoFrameResolutionAdapter::ConstraintsMatch( |
| 278 const gfx::Size& max_size, |
| 279 double min_aspect_ratio, |
| 280 double max_aspect_ratio, |
| 281 double max_frame_rate) const { |
| 282 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 283 return max_frame_size_ == max_size && |
| 284 min_aspect_ratio_ == min_aspect_ratio && |
| 285 max_aspect_ratio_ == max_aspect_ratio && |
| 286 max_frame_rate_ == max_frame_rate; |
| 287 } |
| 288 |
| 289 bool VideoTrackAdapter::VideoFrameResolutionAdapter::IsEmpty() const { |
| 290 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 291 return callbacks_.empty(); |
| 292 } |
| 293 |
| 294 void VideoTrackAdapter::VideoFrameResolutionAdapter::DoDeliverFrame( |
| 295 const scoped_refptr<media::VideoFrame>& frame, |
| 296 const base::TimeTicks& estimated_capture_time) { |
| 297 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 298 for (const auto& callback : callbacks_) |
| 299 callback.second.Run(frame, estimated_capture_time); |
| 300 } |
| 301 |
| 252 bool VideoTrackAdapter::VideoFrameResolutionAdapter::MaybeDropFrame( | 302 bool VideoTrackAdapter::VideoFrameResolutionAdapter::MaybeDropFrame( |
| 253 const scoped_refptr<media::VideoFrame>& frame, | 303 const scoped_refptr<media::VideoFrame>& frame, |
| 254 float source_frame_rate) { | 304 float source_frame_rate) { |
| 255 DCHECK(io_thread_checker_.CalledOnValidThread()); | 305 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 256 | 306 |
| 257 // Do not drop frames if max frame rate hasn't been specified or the source | 307 // Do not drop frames if max frame rate hasn't been specified or the source |
| 258 // frame rate is known and is lower than max. | 308 // frame rate is known and is lower than max. |
| 259 if (max_frame_rate_ == 0.0f || | 309 if (max_frame_rate_ == 0.0f || |
| 260 (source_frame_rate > 0 && source_frame_rate <= max_frame_rate_)) { | 310 (source_frame_rate > 0 && source_frame_rate <= max_frame_rate_)) { |
| 261 return false; | 311 return false; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 keep_frame_counter_ += max_frame_rate_ / frame_rate_; | 350 keep_frame_counter_ += max_frame_rate_ / frame_rate_; |
| 301 if (keep_frame_counter_ >= 1) { | 351 if (keep_frame_counter_ >= 1) { |
| 302 keep_frame_counter_ -= 1; | 352 keep_frame_counter_ -= 1; |
| 303 // Keep the frame. | 353 // Keep the frame. |
| 304 return false; | 354 return false; |
| 305 } | 355 } |
| 306 DVLOG(3) << "Drop frame. Input frame_rate_ " << frame_rate_ << "."; | 356 DVLOG(3) << "Drop frame. Input frame_rate_ " << frame_rate_ << "."; |
| 307 return true; | 357 return true; |
| 308 } | 358 } |
| 309 | 359 |
| 310 void VideoTrackAdapter::VideoFrameResolutionAdapter::DoDeliverFrame( | |
| 311 const scoped_refptr<media::VideoFrame>& frame, | |
| 312 const base::TimeTicks& estimated_capture_time) { | |
| 313 DCHECK(io_thread_checker_.CalledOnValidThread()); | |
| 314 for (const auto& callback : callbacks_) | |
| 315 callback.second.Run(frame, estimated_capture_time); | |
| 316 } | |
| 317 | |
| 318 void VideoTrackAdapter::VideoFrameResolutionAdapter::AddCallback( | |
| 319 const MediaStreamVideoTrack* track, | |
| 320 const VideoCaptureDeliverFrameCB& callback) { | |
| 321 DCHECK(io_thread_checker_.CalledOnValidThread()); | |
| 322 callbacks_.push_back(std::make_pair(track, callback)); | |
| 323 } | |
| 324 | |
| 325 void VideoTrackAdapter::VideoFrameResolutionAdapter::RemoveCallback( | |
| 326 const MediaStreamVideoTrack* track) { | |
| 327 DCHECK(io_thread_checker_.CalledOnValidThread()); | |
| 328 std::vector<VideoIdCallbackPair>::iterator it = callbacks_.begin(); | |
| 329 for (; it != callbacks_.end(); ++it) { | |
| 330 if (it->first == track) { | |
| 331 // Make sure the VideoCaptureDeliverFrameCB is released on the main | |
| 332 // render thread since it was added on the main render thread in | |
| 333 // VideoTrackAdapter::AddTrack. | |
| 334 scoped_ptr<VideoCaptureDeliverFrameCB> callback( | |
| 335 new VideoCaptureDeliverFrameCB(it->second)); | |
| 336 callbacks_.erase(it); | |
| 337 renderer_task_runner_->PostTask( | |
| 338 FROM_HERE, base::Bind(&ResetCallbackOnMainRenderThread, | |
| 339 base::Passed(&callback))); | |
| 340 | |
| 341 return; | |
| 342 } | |
| 343 } | |
| 344 } | |
| 345 | |
| 346 bool VideoTrackAdapter::VideoFrameResolutionAdapter::ConstraintsMatch( | |
| 347 const gfx::Size& max_size, | |
| 348 double min_aspect_ratio, | |
| 349 double max_aspect_ratio, | |
| 350 double max_frame_rate) const { | |
| 351 DCHECK(io_thread_checker_.CalledOnValidThread()); | |
| 352 return max_frame_size_ == max_size && | |
| 353 min_aspect_ratio_ == min_aspect_ratio && | |
| 354 max_aspect_ratio_ == max_aspect_ratio && | |
| 355 max_frame_rate_ == max_frame_rate; | |
| 356 } | |
| 357 | |
| 358 bool VideoTrackAdapter::VideoFrameResolutionAdapter::IsEmpty() const { | |
| 359 DCHECK(io_thread_checker_.CalledOnValidThread()); | |
| 360 return callbacks_.empty(); | |
| 361 } | |
| 362 | |
| 363 VideoTrackAdapter::VideoTrackAdapter( | 360 VideoTrackAdapter::VideoTrackAdapter( |
| 364 const scoped_refptr<base::MessageLoopProxy>& io_message_loop) | 361 const scoped_refptr<base::MessageLoopProxy>& io_message_loop) |
| 365 : io_message_loop_(io_message_loop), | 362 : io_message_loop_(io_message_loop), |
| 366 renderer_task_runner_(base::MessageLoopProxy::current()), | 363 renderer_task_runner_(base::MessageLoopProxy::current()), |
| 367 monitoring_frame_rate_(false), | 364 monitoring_frame_rate_(false), |
| 368 muted_state_(false), | 365 muted_state_(false), |
| 369 frame_counter_(0), | 366 frame_counter_(0), |
| 370 source_frame_rate_(0.0f) { | 367 source_frame_rate_(0.0f) { |
| 371 DCHECK(io_message_loop_.get()); | 368 DCHECK(io_message_loop_.get()); |
| 372 } | 369 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 | 429 |
| 433 VideoTrackAdapter::OnMutedCallback bound_on_muted_callback = | 430 VideoTrackAdapter::OnMutedCallback bound_on_muted_callback = |
| 434 media::BindToCurrentLoop(on_muted_callback); | 431 media::BindToCurrentLoop(on_muted_callback); |
| 435 | 432 |
| 436 io_message_loop_->PostTask( | 433 io_message_loop_->PostTask( |
| 437 FROM_HERE, | 434 FROM_HERE, |
| 438 base::Bind(&VideoTrackAdapter::StartFrameMonitoringOnIO, | 435 base::Bind(&VideoTrackAdapter::StartFrameMonitoringOnIO, |
| 439 this, bound_on_muted_callback, source_frame_rate)); | 436 this, bound_on_muted_callback, source_frame_rate)); |
| 440 } | 437 } |
| 441 | 438 |
| 439 void VideoTrackAdapter::StopFrameMonitoring() { |
| 440 DCHECK(thread_checker_.CalledOnValidThread()); |
| 441 io_message_loop_->PostTask( |
| 442 FROM_HERE, |
| 443 base::Bind(&VideoTrackAdapter::StopFrameMonitoringOnIO, this)); |
| 444 } |
| 445 |
| 442 void VideoTrackAdapter::StartFrameMonitoringOnIO( | 446 void VideoTrackAdapter::StartFrameMonitoringOnIO( |
| 443 const OnMutedCallback& on_muted_callback, | 447 const OnMutedCallback& on_muted_callback, |
| 444 double source_frame_rate) { | 448 double source_frame_rate) { |
| 445 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 449 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 446 DCHECK(!monitoring_frame_rate_); | 450 DCHECK(!monitoring_frame_rate_); |
| 447 | 451 |
| 448 monitoring_frame_rate_ = true; | 452 monitoring_frame_rate_ = true; |
| 449 | 453 |
| 450 // If the source does not know the frame rate, set one by default. | 454 // If the source does not know the frame rate, set one by default. |
| 451 if (source_frame_rate == 0.0f) | 455 if (source_frame_rate == 0.0f) |
| 452 source_frame_rate = MediaStreamVideoSource::kDefaultFrameRate; | 456 source_frame_rate = MediaStreamVideoSource::kDefaultFrameRate; |
| 453 source_frame_rate_ = source_frame_rate; | 457 source_frame_rate_ = source_frame_rate; |
| 454 DVLOG(1) << "Monitoring frame creation, first (large) delay: " | 458 DVLOG(1) << "Monitoring frame creation, first (large) delay: " |
| 455 << (kFirstFrameTimeoutInFrameIntervals / source_frame_rate_) << "s"; | 459 << (kFirstFrameTimeoutInFrameIntervals / source_frame_rate_) << "s"; |
| 456 io_message_loop_->PostDelayedTask(FROM_HERE, | 460 io_message_loop_->PostDelayedTask(FROM_HERE, |
| 457 base::Bind(&VideoTrackAdapter::CheckFramesReceivedOnIO, this, | 461 base::Bind(&VideoTrackAdapter::CheckFramesReceivedOnIO, this, |
| 458 on_muted_callback, frame_counter_), | 462 on_muted_callback, frame_counter_), |
| 459 base::TimeDelta::FromSecondsD(kFirstFrameTimeoutInFrameIntervals / | 463 base::TimeDelta::FromSecondsD(kFirstFrameTimeoutInFrameIntervals / |
| 460 source_frame_rate_)); | 464 source_frame_rate_)); |
| 461 } | 465 } |
| 462 | 466 |
| 463 void VideoTrackAdapter::StopFrameMonitoring() { | |
| 464 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 465 io_message_loop_->PostTask( | |
| 466 FROM_HERE, | |
| 467 base::Bind(&VideoTrackAdapter::StopFrameMonitoringOnIO, this)); | |
| 468 } | |
| 469 | |
| 470 void VideoTrackAdapter::StopFrameMonitoringOnIO() { | 467 void VideoTrackAdapter::StopFrameMonitoringOnIO() { |
| 471 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 468 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 472 monitoring_frame_rate_ = false; | 469 monitoring_frame_rate_ = false; |
| 473 } | 470 } |
| 474 | 471 |
| 475 void VideoTrackAdapter::RemoveTrackOnIO(const MediaStreamVideoTrack* track) { | 472 void VideoTrackAdapter::RemoveTrackOnIO(const MediaStreamVideoTrack* track) { |
| 476 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 473 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 477 for (FrameAdapters::iterator it = adapters_.begin(); | 474 for (FrameAdapters::iterator it = adapters_.begin(); |
| 478 it != adapters_.end(); ++it) { | 475 it != adapters_.end(); ++it) { |
| 479 (*it)->RemoveCallback(track); | 476 (*it)->RemoveCallback(track); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 } | 509 } |
| 513 | 510 |
| 514 io_message_loop_->PostDelayedTask(FROM_HERE, | 511 io_message_loop_->PostDelayedTask(FROM_HERE, |
| 515 base::Bind(&VideoTrackAdapter::CheckFramesReceivedOnIO, this, | 512 base::Bind(&VideoTrackAdapter::CheckFramesReceivedOnIO, this, |
| 516 set_muted_state_callback, frame_counter_), | 513 set_muted_state_callback, frame_counter_), |
| 517 base::TimeDelta::FromSecondsD(kNormalFrameTimeoutInFrameIntervals / | 514 base::TimeDelta::FromSecondsD(kNormalFrameTimeoutInFrameIntervals / |
| 518 source_frame_rate_)); | 515 source_frame_rate_)); |
| 519 } | 516 } |
| 520 | 517 |
| 521 } // namespace content | 518 } // namespace content |
| OLD | NEW |