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/browser/media/capture/content_video_capture_device_core.h" | 5 #include "content/browser/media/capture/content_video_capture_device_core.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback_forward.h" | 9 #include "base/callback_forward.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 client_->ReserveOutputBuffer(video_frame_format, coded_size); | 83 client_->ReserveOutputBuffer(video_frame_format, coded_size); |
84 const bool should_capture = | 84 const bool should_capture = |
85 oracle_.ObserveEventAndDecideCapture(event, damage_rect, event_time); | 85 oracle_.ObserveEventAndDecideCapture(event, damage_rect, event_time); |
86 const char* event_name = | 86 const char* event_name = |
87 (event == VideoCaptureOracle::kTimerPoll ? "poll" : | 87 (event == VideoCaptureOracle::kTimerPoll ? "poll" : |
88 (event == VideoCaptureOracle::kCompositorUpdate ? "gpu" : | 88 (event == VideoCaptureOracle::kCompositorUpdate ? "gpu" : |
89 "paint")); | 89 "paint")); |
90 | 90 |
91 // Consider the various reasons not to initiate a capture. | 91 // Consider the various reasons not to initiate a capture. |
92 if (should_capture && !output_buffer.get()) { | 92 if (should_capture && !output_buffer.get()) { |
93 TRACE_EVENT_INSTANT1("mirroring", | 93 TRACE_EVENT_INSTANT1("gpu.capture", |
94 "PipelineLimited", | 94 "PipelineLimited", |
95 TRACE_EVENT_SCOPE_THREAD, | 95 TRACE_EVENT_SCOPE_THREAD, |
96 "trigger", | 96 "trigger", |
97 event_name); | 97 event_name); |
98 return false; | 98 return false; |
99 } else if (!should_capture && output_buffer.get()) { | 99 } else if (!should_capture && output_buffer.get()) { |
100 if (event == VideoCaptureOracle::kCompositorUpdate) { | 100 if (event == VideoCaptureOracle::kCompositorUpdate) { |
101 // This is a normal and acceptable way to drop a frame. We've hit our | 101 // This is a normal and acceptable way to drop a frame. We've hit our |
102 // capture rate limit: for example, the content is animating at 60fps but | 102 // capture rate limit: for example, the content is animating at 60fps but |
103 // we're capturing at 30fps. | 103 // we're capturing at 30fps. |
104 TRACE_EVENT_INSTANT1("mirroring", "FpsRateLimited", | 104 TRACE_EVENT_INSTANT1("gpu.capture", "FpsRateLimited", |
105 TRACE_EVENT_SCOPE_THREAD, | 105 TRACE_EVENT_SCOPE_THREAD, |
106 "trigger", event_name); | 106 "trigger", event_name); |
107 } | 107 } |
108 return false; | 108 return false; |
109 } else if (!should_capture && !output_buffer.get()) { | 109 } else if (!should_capture && !output_buffer.get()) { |
110 // We decided not to capture, but we wouldn't have been able to if we wanted | 110 // We decided not to capture, but we wouldn't have been able to if we wanted |
111 // to because no output buffer was available. | 111 // to because no output buffer was available. |
112 TRACE_EVENT_INSTANT1("mirroring", "NearlyPipelineLimited", | 112 TRACE_EVENT_INSTANT1("gpu.capture", "NearlyPipelineLimited", |
113 TRACE_EVENT_SCOPE_THREAD, | 113 TRACE_EVENT_SCOPE_THREAD, |
114 "trigger", event_name); | 114 "trigger", event_name); |
115 return false; | 115 return false; |
116 } | 116 } |
117 int frame_number = oracle_.RecordCapture(); | 117 int frame_number = oracle_.RecordCapture(); |
118 TRACE_EVENT_ASYNC_BEGIN2("mirroring", "Capture", output_buffer.get(), | 118 TRACE_EVENT_ASYNC_BEGIN2("gpu.capture", "Capture", output_buffer.get(), |
119 "frame_number", frame_number, | 119 "frame_number", frame_number, |
120 "trigger", event_name); | 120 "trigger", event_name); |
121 // NATIVE_TEXTURE frames wrap a texture mailbox, which we don't have at the | 121 // NATIVE_TEXTURE frames wrap a texture mailbox, which we don't have at the |
122 // moment. We do not construct those frames. | 122 // moment. We do not construct those frames. |
123 if (video_frame_format != media::VideoFrame::NATIVE_TEXTURE) { | 123 if (video_frame_format != media::VideoFrame::NATIVE_TEXTURE) { |
124 *storage = media::VideoFrame::WrapExternalPackedMemory( | 124 *storage = media::VideoFrame::WrapExternalPackedMemory( |
125 video_frame_format, | 125 video_frame_format, |
126 coded_size, | 126 coded_size, |
127 gfx::Rect(visible_size), | 127 gfx::Rect(visible_size), |
128 visible_size, | 128 visible_size, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 } | 182 } |
183 | 183 |
184 void ThreadSafeCaptureOracle::DidCaptureFrame( | 184 void ThreadSafeCaptureOracle::DidCaptureFrame( |
185 int frame_number, | 185 int frame_number, |
186 const scoped_refptr<media::VideoCaptureDevice::Client::Buffer>& buffer, | 186 const scoped_refptr<media::VideoCaptureDevice::Client::Buffer>& buffer, |
187 base::TimeTicks capture_begin_time, | 187 base::TimeTicks capture_begin_time, |
188 const scoped_refptr<media::VideoFrame>& frame, | 188 const scoped_refptr<media::VideoFrame>& frame, |
189 base::TimeTicks timestamp, | 189 base::TimeTicks timestamp, |
190 bool success) { | 190 bool success) { |
191 base::AutoLock guard(lock_); | 191 base::AutoLock guard(lock_); |
192 TRACE_EVENT_ASYNC_END2("mirroring", "Capture", buffer.get(), | 192 TRACE_EVENT_ASYNC_END2("gpu.capture", "Capture", buffer.get(), |
193 "success", success, | 193 "success", success, |
194 "timestamp", timestamp.ToInternalValue()); | 194 "timestamp", timestamp.ToInternalValue()); |
195 | 195 |
196 if (!client_) | 196 if (!client_) |
197 return; // Capture is stopped. | 197 return; // Capture is stopped. |
198 | 198 |
199 if (success) { | 199 if (success) { |
200 if (oracle_.CompleteCapture(frame_number, ×tamp)) { | 200 if (oracle_.CompleteCapture(frame_number, ×tamp)) { |
201 // TODO(miu): Use the locked-in frame rate from AnimatedContentSampler. | 201 // TODO(miu): Use the locked-in frame rate from AnimatedContentSampler. |
202 frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, | 202 frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 return; | 341 return; |
342 | 342 |
343 if (oracle_proxy_.get()) | 343 if (oracle_proxy_.get()) |
344 oracle_proxy_->ReportError(reason); | 344 oracle_proxy_->ReportError(reason); |
345 | 345 |
346 StopAndDeAllocate(); | 346 StopAndDeAllocate(); |
347 TransitionStateTo(kError); | 347 TransitionStateTo(kError); |
348 } | 348 } |
349 | 349 |
350 } // namespace content | 350 } // namespace content |
OLD | NEW |