Chromium Code Reviews| Index: content/browser/media/capture/web_contents_video_capture_device.cc |
| diff --git a/content/browser/media/capture/web_contents_video_capture_device.cc b/content/browser/media/capture/web_contents_video_capture_device.cc |
| index bdadcd2783835a0f5b5be9609d2cd897a218610c..a5d07531988f27c0c759960018034b355c15de12 100644 |
| --- a/content/browser/media/capture/web_contents_video_capture_device.cc |
| +++ b/content/browser/media/capture/web_contents_video_capture_device.cc |
| @@ -69,6 +69,7 @@ |
| #include "base/time/time.h" |
| #include "build/build_config.h" |
| #include "content/browser/media/capture/cursor_renderer.h" |
| +#include "content/browser/media/capture/desktop_capture_device_uma_types.h" |
| #include "content/browser/media/capture/web_contents_tracker.h" |
| #include "content/browser/media/capture/window_activity_tracker.h" |
| #include "content/browser/renderer_host/render_widget_host_impl.h" |
| @@ -260,7 +261,8 @@ class WebContentsCaptureMachine : public media::VideoCaptureMachine { |
| public: |
| WebContentsCaptureMachine(int render_process_id, |
| int main_render_frame_id, |
| - bool enable_auto_throttling); |
| + bool enable_auto_throttling, |
| + WebContentsVideoCaptureDevice::JavaScriptType type); |
| ~WebContentsCaptureMachine() override; |
| // VideoCaptureMachine overrides. |
| @@ -329,6 +331,9 @@ class WebContentsCaptureMachine : public media::VideoCaptureMachine { |
| // option in the WebContentsVideoCaptureDevice device ID. |
| const bool auto_throttling_enabled_; |
| + bool is_first_capture_; |
| + const WebContentsVideoCaptureDevice::JavaScriptType js_type_; |
| + |
| // A dedicated worker thread on which SkBitmap->VideoFrame conversion will |
| // occur. Only used when this activity cannot be done on the GPU. |
| scoped_ptr<base::Thread> render_thread_; |
| @@ -629,11 +634,13 @@ void VideoFrameDeliveryLog::ChronicleFrameDelivery(base::TimeTicks frame_time) { |
| WebContentsCaptureMachine::WebContentsCaptureMachine( |
| int render_process_id, |
| int main_render_frame_id, |
| - bool enable_auto_throttling) |
| + bool enable_auto_throttling, |
| + WebContentsVideoCaptureDevice::JavaScriptType type) |
| : initial_render_process_id_(render_process_id), |
| initial_main_render_frame_id_(main_render_frame_id), |
| tracker_(new WebContentsTracker(true)), |
| auto_throttling_enabled_(enable_auto_throttling), |
| + js_type_(type), |
| weak_ptr_factory_(this) { |
| DVLOG(1) << "Created WebContentsCaptureMachine for " |
| << render_process_id << ':' << main_render_frame_id |
| @@ -651,6 +658,8 @@ void WebContentsCaptureMachine::Start( |
| const scoped_refptr<media::ThreadSafeCaptureOracle>& oracle_proxy, |
| const media::VideoCaptureParams& params, |
| const base::Callback<void(bool)> callback) { |
| + is_first_capture_ = true; |
| + |
| // Starts the capture machine asynchronously. |
| BrowserThread::PostTaskAndReplyWithResult( |
| BrowserThread::UI, |
| @@ -866,6 +875,17 @@ void WebContentsCaptureMachine::DidCopyFromBackingStore( |
| DVLOG(1) << "CopyFromBackingStore failed; skipping frame."; |
| deliver_frame_cb.Run(start_time, gfx::Rect(), false); |
| } |
| + |
| + if (is_first_capture_) { |
| + is_first_capture_ = false; |
| + if (js_type_ == |
| + WebContentsVideoCaptureDevice::CHROME_CHOOSE_DESKTOP_MEDIA) { |
| + if (response == READBACK_SUCCESS) |
|
miu
2016/03/24 20:51:02
It's very possible for the first few frames to fai
GeorgeZ
2016/03/25 16:35:04
Very valuable comments. I guess this is why a owne
|
| + IncrementDesktopCaptureCounter(FIRST_TAB_CAPTURE_SUCCEEDED); |
| + else |
| + IncrementDesktopCaptureCounter(FIRST_TAB_CAPTURE_FAILED); |
| + } |
| + } |
| } |
| void WebContentsCaptureMachine::DidCopyFromCompositingSurfaceToVideoFrame( |
| @@ -883,6 +903,18 @@ void WebContentsCaptureMachine::DidCopyFromCompositingSurfaceToVideoFrame( |
| // Capture can fail due to transient issues, so just skip this frame. |
| DVLOG(1) << "CopyFromCompositingSurface failed; skipping frame."; |
| } |
| + |
| + if (is_first_capture_) { |
| + is_first_capture_ = false; |
| + if (js_type_ == |
| + WebContentsVideoCaptureDevice::CHROME_CHOOSE_DESKTOP_MEDIA) { |
| + if (success) |
| + IncrementDesktopCaptureCounter(FIRST_TAB_CAPTURE_SUCCEEDED); |
| + else |
| + IncrementDesktopCaptureCounter(FIRST_TAB_CAPTURE_FAILED); |
| + } |
| + } |
| + |
| deliver_frame_cb.Run(start_time, region_in_frame, success); |
| } |
| @@ -947,12 +979,14 @@ void WebContentsCaptureMachine::UpdateCaptureSize() { |
| WebContentsVideoCaptureDevice::WebContentsVideoCaptureDevice( |
| int render_process_id, |
| int main_render_frame_id, |
| - bool enable_auto_throttling) |
| + bool enable_auto_throttling, |
| + JavaScriptType type) |
| : core_(new media::ScreenCaptureDeviceCore( |
| - scoped_ptr<media::VideoCaptureMachine>(new WebContentsCaptureMachine( |
| - render_process_id, |
| - main_render_frame_id, |
| - enable_auto_throttling)))) {} |
| + scoped_ptr<media::VideoCaptureMachine>( |
| + new WebContentsCaptureMachine(render_process_id, |
| + main_render_frame_id, |
| + enable_auto_throttling, |
| + type)))) {} |
| WebContentsVideoCaptureDevice::~WebContentsVideoCaptureDevice() { |
| DVLOG(2) << "WebContentsVideoCaptureDevice@" << this << " destroying."; |
| @@ -960,7 +994,8 @@ WebContentsVideoCaptureDevice::~WebContentsVideoCaptureDevice() { |
| // static |
| media::VideoCaptureDevice* WebContentsVideoCaptureDevice::Create( |
| - const std::string& device_id) { |
| + const std::string& device_id, |
| + JavaScriptType type) { |
| // Parse device_id into render_process_id and main_render_frame_id. |
| int render_process_id = -1; |
| int main_render_frame_id = -1; |
| @@ -969,9 +1004,12 @@ media::VideoCaptureDevice* WebContentsVideoCaptureDevice::Create( |
| return NULL; |
| } |
| + if (type == CHROME_CHOOSE_DESKTOP_MEDIA) |
| + IncrementDesktopCaptureCounter(TAB_VIDEO_CAPTURER_CREATED); |
| + |
| return new WebContentsVideoCaptureDevice( |
| render_process_id, main_render_frame_id, |
| - WebContentsMediaCaptureId::IsAutoThrottlingOptionSet(device_id)); |
| + WebContentsMediaCaptureId::IsAutoThrottlingOptionSet(device_id), type); |
| } |
| void WebContentsVideoCaptureDevice::AllocateAndStart( |