| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Implementation notes: This needs to work on a variety of hardware | 5 // Implementation notes: This needs to work on a variety of hardware |
| 6 // configurations where the speed of the CPU and GPU greatly affect overall | 6 // configurations where the speed of the CPU and GPU greatly affect overall |
| 7 // performance. Spanning several threads, the process of capturing has been | 7 // performance. Spanning several threads, the process of capturing has been |
| 8 // split up into four conceptual stages: | 8 // split up into four conceptual stages: |
| 9 // | 9 // |
| 10 // 1. Reserve Buffer: Before a frame can be captured, a slot in the consumer's | 10 // 1. Reserve Buffer: Before a frame can be captured, a slot in the consumer's |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 should_sample = sampler_.IsOverdueForSamplingAt(now); | 449 should_sample = sampler_.IsOverdueForSamplingAt(now); |
| 450 } | 450 } |
| 451 | 451 |
| 452 const char* event_name = (event == TIMER_POLL ? "poll" : | 452 const char* event_name = (event == TIMER_POLL ? "poll" : |
| 453 (event == COMPOSITOR_UPDATE ? "gpu" : | 453 (event == COMPOSITOR_UPDATE ? "gpu" : |
| 454 "paint")); | 454 "paint")); |
| 455 | 455 |
| 456 // Step 3: Consider the various reasons not to initiate a capture. | 456 // Step 3: Consider the various reasons not to initiate a capture. |
| 457 if (should_sample && !output_buffer) { | 457 if (should_sample && !output_buffer) { |
| 458 TRACE_EVENT_INSTANT1("mirroring", "EncodeLimited", | 458 TRACE_EVENT_INSTANT1("mirroring", "EncodeLimited", |
| 459 TRACE_EVENT_SCOPE_THREAD, |
| 459 "trigger", event_name); | 460 "trigger", event_name); |
| 460 return false; | 461 return false; |
| 461 } else if (!should_sample && output_buffer) { | 462 } else if (!should_sample && output_buffer) { |
| 462 if (content_is_dirty) { | 463 if (content_is_dirty) { |
| 463 // This is a normal and acceptable way to drop a frame. We've hit our | 464 // This is a normal and acceptable way to drop a frame. We've hit our |
| 464 // capture rate limit: for example, the content is animating at 60fps but | 465 // capture rate limit: for example, the content is animating at 60fps but |
| 465 // we're capturing at 30fps. | 466 // we're capturing at 30fps. |
| 466 TRACE_EVENT_INSTANT1("mirroring", "FpsRateLimited", | 467 TRACE_EVENT_INSTANT1("mirroring", "FpsRateLimited", |
| 468 TRACE_EVENT_SCOPE_THREAD, |
| 467 "trigger", event_name); | 469 "trigger", event_name); |
| 468 } | 470 } |
| 469 return false; | 471 return false; |
| 470 } else if (!should_sample && !output_buffer) { | 472 } else if (!should_sample && !output_buffer) { |
| 471 // We decided not to capture, but we wouldn't have been able to if we wanted | 473 // We decided not to capture, but we wouldn't have been able to if we wanted |
| 472 // to because no output buffer was available. | 474 // to because no output buffer was available. |
| 473 TRACE_EVENT_INSTANT1("mirroring", "NearlyEncodeLimited", | 475 TRACE_EVENT_INSTANT1("mirroring", "NearlyEncodeLimited", |
| 476 TRACE_EVENT_SCOPE_THREAD, |
| 474 "trigger", event_name); | 477 "trigger", event_name); |
| 475 return false; | 478 return false; |
| 476 } | 479 } |
| 477 | 480 |
| 478 // Step 4: Initiate a capture. | 481 // Step 4: Initiate a capture. |
| 479 sampler_.RecordSample(); | 482 sampler_.RecordSample(); |
| 480 TRACE_EVENT_ASYNC_BEGIN2("mirroring", "Capture", output_buffer.get(), | 483 TRACE_EVENT_ASYNC_BEGIN2("mirroring", "Capture", output_buffer.get(), |
| 481 "frame_number", frame_number_, | 484 "frame_number", frame_number_, |
| 482 "trigger", event_name); | 485 "trigger", event_name); |
| 483 *storage = output_buffer; | 486 *storage = output_buffer; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 498 | 501 |
| 499 void CaptureOracle::ReportError() { | 502 void CaptureOracle::ReportError() { |
| 500 base::AutoLock guard(lock_); | 503 base::AutoLock guard(lock_); |
| 501 if (consumer_) | 504 if (consumer_) |
| 502 consumer_->OnError(); | 505 consumer_->OnError(); |
| 503 } | 506 } |
| 504 | 507 |
| 505 void CaptureOracle::InvalidateConsumer() { | 508 void CaptureOracle::InvalidateConsumer() { |
| 506 base::AutoLock guard(lock_); | 509 base::AutoLock guard(lock_); |
| 507 | 510 |
| 508 TRACE_EVENT_INSTANT0("mirroring", "InvalidateConsumer"); | 511 TRACE_EVENT_INSTANT0("mirroring", "InvalidateConsumer", |
| 512 TRACE_EVENT_SCOPE_THREAD); |
| 509 | 513 |
| 510 is_started_ = false; | 514 is_started_ = false; |
| 511 consumer_ = NULL; | 515 consumer_ = NULL; |
| 512 } | 516 } |
| 513 | 517 |
| 514 void CaptureOracle::DidCaptureFrame( | 518 void CaptureOracle::DidCaptureFrame( |
| 515 const scoped_refptr<media::VideoFrame>& frame, | 519 const scoped_refptr<media::VideoFrame>& frame, |
| 516 base::Time timestamp, | 520 base::Time timestamp, |
| 517 bool success) { | 521 bool success) { |
| 518 base::AutoLock guard(lock_); | 522 base::AutoLock guard(lock_); |
| (...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1303 return false; | 1307 return false; |
| 1304 else | 1308 else |
| 1305 return true; | 1309 return true; |
| 1306 } | 1310 } |
| 1307 | 1311 |
| 1308 base::Time SmoothEventSampler::GetLastSampledEvent() { | 1312 base::Time SmoothEventSampler::GetLastSampledEvent() { |
| 1309 return last_sample_; | 1313 return last_sample_; |
| 1310 } | 1314 } |
| 1311 | 1315 |
| 1312 } // namespace content | 1316 } // namespace content |
| OLD | NEW |