Chromium Code Reviews| Index: content/browser/media/capture/desktop_capture_device_aura.cc |
| diff --git a/content/browser/media/capture/desktop_capture_device_aura.cc b/content/browser/media/capture/desktop_capture_device_aura.cc |
| index 2c7d196531b121795f84848105a6603edba4bf54..6af66118ff4d48befd000c102cbd6bacca13dd44 100644 |
| --- a/content/browser/media/capture/desktop_capture_device_aura.cc |
| +++ b/content/browser/media/capture/desktop_capture_device_aura.cc |
| @@ -5,11 +5,13 @@ |
| #include "content/browser/media/capture/desktop_capture_device_aura.h" |
| #include "base/logging.h" |
| +#include "base/metrics/histogram.h" |
| #include "base/timer/timer.h" |
| #include "cc/output/copy_output_request.h" |
| #include "cc/output/copy_output_result.h" |
| #include "content/browser/compositor/image_transport_factory.h" |
| #include "content/browser/media/capture/content_video_capture_device_core.h" |
| +#include "content/browser/media/capture/desktop_capture_device_uma_types.h" |
| #include "content/common/gpu/client/gl_helper.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "media/base/video_util.h" |
| @@ -30,6 +32,12 @@ namespace content { |
| namespace { |
| +void IncrementCounter(DesktopCaptureCounters counter) { |
| + UMA_HISTOGRAM_ENUMERATION(kUMADesopCaptureCounters, |
| + counter, |
| + DESKTOP_CAPTURE_COUNTER_BOUNDARY); |
| +} |
| + |
| int clip_byte(int x) { |
| return std::max(0, std::min(x, 255)); |
| } |
| @@ -129,6 +137,14 @@ class DesktopVideoCaptureMachine |
| const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, |
| scoped_ptr<cc::CopyOutputResult> result); |
| + // A helper which does the real work for DidCopyOutput. Returns true if |
| + // succeeded. |
| + bool DidCopyOutputHelper( |
| + scoped_refptr<media::VideoFrame> video_frame, |
| + base::TimeTicks start_time, |
| + const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, |
| + scoped_ptr<cc::CopyOutputResult> result); |
| + |
| // Helper function to update cursor state. |
| // |region_in_frame| defines the desktop bound in the captured frame. |
| // Returns the current cursor position in captured frame. |
| @@ -292,8 +308,30 @@ void DesktopVideoCaptureMachine::DidCopyOutput( |
| base::TimeTicks start_time, |
| const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, |
| scoped_ptr<cc::CopyOutputResult> result) { |
| + static bool first_call = true; |
| + |
| + bool succeeded = DidCopyOutputHelper( |
| + video_frame, start_time, capture_frame_cb, result.Pass()); |
| + |
| + if (first_call) { |
| + first_call = false; |
| + if (window_id_.type == DesktopMediaID::TYPE_SCREEN) { |
| + IncrementCounter(succeeded ? FIRST_SCREEN_CAPTURE_SUCCEEDED : |
| + FIRST_SCREEN_CAPTURE_FAILED); |
|
Sergey Ulanov
2014/04/24 19:33:24
nit: indentation. Also : can be wrapped. clang-for
jiayl
2014/04/24 20:58:55
Done.
|
| + } else { |
| + IncrementCounter(succeeded ? FIRST_WINDOW_CAPTURE_SUCCEEDED : |
| + FIRST_WINDOW_CAPTURE_SUCCEEDED); |
| + } |
| + } |
| +} |
| + |
| +bool DesktopVideoCaptureMachine::DidCopyOutputHelper( |
|
Sergey Ulanov
2014/04/24 19:33:24
Call this something like ProcessCopyOutputResponse
jiayl
2014/04/24 20:58:55
Done.
|
| + scoped_refptr<media::VideoFrame> video_frame, |
| + base::TimeTicks start_time, |
| + const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, |
| + scoped_ptr<cc::CopyOutputResult> result) { |
| if (result->IsEmpty() || result->size().IsEmpty() || !desktop_layer_) |
| - return; |
| + return false; |
| // Compute the dest size we want after the letterboxing resize. Make the |
| // coordinates and sizes even because we letterbox in YUV space |
| @@ -309,19 +347,19 @@ void DesktopVideoCaptureMachine::DidCopyOutput( |
| region_in_frame.width() & ~1, |
| region_in_frame.height() & ~1); |
| if (region_in_frame.IsEmpty()) |
| - return; |
| + return false; |
| ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| GLHelper* gl_helper = factory->GetGLHelper(); |
| if (!gl_helper) |
| - return; |
| + return false; |
| cc::TextureMailbox texture_mailbox; |
| scoped_ptr<cc::SingleReleaseCallback> release_callback; |
| result->TakeTexture(&texture_mailbox, &release_callback); |
| DCHECK(texture_mailbox.IsTexture()); |
| if (!texture_mailbox.IsTexture()) |
| - return; |
| + return false; |
| gfx::Rect result_rect(result->size()); |
| if (!yuv_readback_pipeline_ || |
| @@ -350,6 +388,14 @@ void DesktopVideoCaptureMachine::DidCopyOutput( |
| scaled_cursor_bitmap_, |
| cursor_position_in_frame, |
| base::Passed(&release_callback))); |
| + |
| + base::TimeDelta capture_time = base::TimeTicks::Now() - start_time; |
|
Sergey Ulanov
2014/04/24 19:33:24
Move this to DidCopyOutput() so that all UMA logic
jiayl
2014/04/24 20:58:55
Done.
|
| + if (window_id_.type == DesktopMediaID::TYPE_SCREEN) |
| + UMA_HISTOGRAM_TIMES(kUMAScreenCaptureTime, capture_time); |
|
Sergey Ulanov
2014/04/24 19:33:24
{}
jiayl
2014/04/24 20:58:55
It's not required for single line conditionals.
|
| + else |
| + UMA_HISTOGRAM_TIMES(kUMAWindowCaptureTime, capture_time); |
| + |
| + return true; |
| } |
| gfx::Point DesktopVideoCaptureMachine::UpdateCursorState( |
| @@ -432,6 +478,8 @@ DesktopCaptureDeviceAura::~DesktopCaptureDeviceAura() { |
| // static |
| media::VideoCaptureDevice* DesktopCaptureDeviceAura::Create( |
| const DesktopMediaID& source) { |
| + IncrementCounter(source.type == DesktopMediaID::TYPE_SCREEN ? |
| + SCREEN_CAPTURER_CREATED : WINDOW_CATPTURER_CREATED); |
| return new DesktopCaptureDeviceAura(source); |
| } |