| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/html_video_element_capturer_source.h" | 5 #include "content/renderer/media/html_video_element_capturer_source.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 55 |
| 56 HtmlVideoElementCapturerSource::~HtmlVideoElementCapturerSource() { | 56 HtmlVideoElementCapturerSource::~HtmlVideoElementCapturerSource() { |
| 57 DCHECK(thread_checker_.CalledOnValidThread()); | 57 DCHECK(thread_checker_.CalledOnValidThread()); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void HtmlVideoElementCapturerSource::GetCurrentSupportedFormats( | 60 void HtmlVideoElementCapturerSource::GetCurrentSupportedFormats( |
| 61 int max_requested_width, | 61 int max_requested_width, |
| 62 int max_requested_height, | 62 int max_requested_height, |
| 63 double max_requested_frame_rate, | 63 double max_requested_frame_rate, |
| 64 const VideoCaptureDeviceFormatsCB& callback) { | 64 const VideoCaptureDeviceFormatsCB& callback) { |
| 65 DVLOG(3) << __FUNCTION__ << "{ max_requested_height = " | 65 DVLOG(3) << __func__ << "{ max_requested_height = " << max_requested_height |
| 66 << max_requested_height << "}) { max_requested_width = " | 66 << "}) { max_requested_width = " << max_requested_width |
| 67 << max_requested_width << "}) { max_requested_frame_rate = " | 67 << "}) { max_requested_frame_rate = " << max_requested_frame_rate |
| 68 << max_requested_frame_rate << "})"; | 68 << "})"; |
| 69 DCHECK(thread_checker_.CalledOnValidThread()); | 69 DCHECK(thread_checker_.CalledOnValidThread()); |
| 70 | 70 |
| 71 // WebMediaPlayer has a setRate() but can't be read back. | 71 // WebMediaPlayer has a setRate() but can't be read back. |
| 72 // TODO(mcasas): Add getRate() to WMPlayer and/or fix the spec to allow users | 72 // TODO(mcasas): Add getRate() to WMPlayer and/or fix the spec to allow users |
| 73 // to specify it. | 73 // to specify it. |
| 74 const media::VideoCaptureFormat format( | 74 const media::VideoCaptureFormat format( |
| 75 web_media_player_->naturalSize(), | 75 web_media_player_->naturalSize(), |
| 76 MediaStreamVideoSource::kDefaultFrameRate, | 76 MediaStreamVideoSource::kDefaultFrameRate, |
| 77 media::PIXEL_FORMAT_I420); | 77 media::PIXEL_FORMAT_I420); |
| 78 media::VideoCaptureFormats formats; | 78 media::VideoCaptureFormats formats; |
| 79 formats.push_back(format); | 79 formats.push_back(format); |
| 80 callback.Run(formats); | 80 callback.Run(formats); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void HtmlVideoElementCapturerSource::StartCapture( | 83 void HtmlVideoElementCapturerSource::StartCapture( |
| 84 const media::VideoCaptureParams& params, | 84 const media::VideoCaptureParams& params, |
| 85 const VideoCaptureDeliverFrameCB& new_frame_callback, | 85 const VideoCaptureDeliverFrameCB& new_frame_callback, |
| 86 const RunningCallback& running_callback) { | 86 const RunningCallback& running_callback) { |
| 87 DVLOG(3) << __FUNCTION__ << " requested " | 87 DVLOG(3) << __func__ << " requested " |
| 88 << media::VideoCaptureFormat::ToString(params.requested_format); | 88 << media::VideoCaptureFormat::ToString(params.requested_format); |
| 89 DCHECK(params.requested_format.IsValid()); | 89 DCHECK(params.requested_format.IsValid()); |
| 90 DCHECK(thread_checker_.CalledOnValidThread()); | 90 DCHECK(thread_checker_.CalledOnValidThread()); |
| 91 | 91 |
| 92 running_callback_ = running_callback; | 92 running_callback_ = running_callback; |
| 93 if (!web_media_player_ || !web_media_player_->hasVideo()) { | 93 if (!web_media_player_ || !web_media_player_->hasVideo()) { |
| 94 running_callback_.Run(false); | 94 running_callback_.Run(false); |
| 95 return; | 95 return; |
| 96 } | 96 } |
| 97 const blink::WebSize resolution = web_media_player_->naturalSize(); | 97 const blink::WebSize resolution = web_media_player_->naturalSize(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 109 std::min(static_cast<float>(media::limits::kMaxFramesPerSecond), | 109 std::min(static_cast<float>(media::limits::kMaxFramesPerSecond), |
| 110 params.requested_format.frame_rate)); | 110 params.requested_format.frame_rate)); |
| 111 | 111 |
| 112 running_callback_.Run(true); | 112 running_callback_.Run(true); |
| 113 base::ThreadTaskRunnerHandle::Get()->PostTask( | 113 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 114 FROM_HERE, base::Bind(&HtmlVideoElementCapturerSource::sendNewFrame, | 114 FROM_HERE, base::Bind(&HtmlVideoElementCapturerSource::sendNewFrame, |
| 115 weak_factory_.GetWeakPtr())); | 115 weak_factory_.GetWeakPtr())); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void HtmlVideoElementCapturerSource::StopCapture() { | 118 void HtmlVideoElementCapturerSource::StopCapture() { |
| 119 DVLOG(3) << __FUNCTION__; | 119 DVLOG(3) << __func__; |
| 120 DCHECK(thread_checker_.CalledOnValidThread()); | 120 DCHECK(thread_checker_.CalledOnValidThread()); |
| 121 running_callback_.Reset(); | 121 running_callback_.Reset(); |
| 122 new_frame_callback_.Reset(); | 122 new_frame_callback_.Reset(); |
| 123 next_capture_time_ = base::TimeTicks(); | 123 next_capture_time_ = base::TimeTicks(); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void HtmlVideoElementCapturerSource::sendNewFrame() { | 126 void HtmlVideoElementCapturerSource::sendNewFrame() { |
| 127 DVLOG(3) << __FUNCTION__; | 127 DVLOG(3) << __func__; |
| 128 TRACE_EVENT0("video", "HtmlVideoElementCapturerSource::sendNewFrame"); | 128 TRACE_EVENT0("video", "HtmlVideoElementCapturerSource::sendNewFrame"); |
| 129 DCHECK(thread_checker_.CalledOnValidThread()); | 129 DCHECK(thread_checker_.CalledOnValidThread()); |
| 130 | 130 |
| 131 if (!web_media_player_ || new_frame_callback_.is_null()) | 131 if (!web_media_player_ || new_frame_callback_.is_null()) |
| 132 return; | 132 return; |
| 133 | 133 |
| 134 const base::TimeTicks current_time = base::TimeTicks::Now(); | 134 const base::TimeTicks current_time = base::TimeTicks::Now(); |
| 135 const blink::WebSize resolution = web_media_player_->naturalSize(); | 135 const blink::WebSize resolution = web_media_player_->naturalSize(); |
| 136 | 136 |
| 137 SkCanvas* canvas = surface_->getCanvas(); | 137 SkCanvas* canvas = surface_->getCanvas(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 next_capture_time_ = current_time; | 194 next_capture_time_ = current_time; |
| 195 } | 195 } |
| 196 // Schedule next capture. | 196 // Schedule next capture. |
| 197 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 197 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 198 FROM_HERE, base::Bind(&HtmlVideoElementCapturerSource::sendNewFrame, | 198 FROM_HERE, base::Bind(&HtmlVideoElementCapturerSource::sendNewFrame, |
| 199 weak_factory_.GetWeakPtr()), | 199 weak_factory_.GetWeakPtr()), |
| 200 next_capture_time_ - current_time); | 200 next_capture_time_ - current_time); |
| 201 } | 201 } |
| 202 | 202 |
| 203 } // namespace content | 203 } // namespace content |
| OLD | NEW |