Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Unified Diff: content/browser/media/capture/content_video_capture_device_core.cc

Issue 1135823004: Implement all resolution change policies for desktop and tab capture. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@resolution_change_policy_constraints_ITEM1_CR1
Patch Set: REBASE Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/media/capture/content_video_capture_device_core.cc
diff --git a/content/browser/media/capture/content_video_capture_device_core.cc b/content/browser/media/capture/content_video_capture_device_core.cc
index 8d44104c1c418f4a3f21d9648b682d4a34ce74d7..da0862ccb8ee4d1f2c07980a818c54d0c5c91d81 100644
--- a/content/browser/media/capture/content_video_capture_device_core.cc
+++ b/content/browser/media/capture/content_video_capture_device_core.cc
@@ -49,7 +49,9 @@ ThreadSafeCaptureOracle::ThreadSafeCaptureOracle(
oracle_(base::TimeDelta::FromMicroseconds(
static_cast<int64>(1000000.0 / params.requested_format.frame_rate +
0.5 /* to round to nearest int */))),
- params_(params) {}
+ params_(params),
+ resolution_chooser_(params.requested_format.frame_size,
+ params.resolution_change_policy) {}
ThreadSafeCaptureOracle::~ThreadSafeCaptureOracle() {}
@@ -67,9 +69,7 @@ bool ThreadSafeCaptureOracle::ObserveEventAndDecideCapture(
if (!client_)
return false; // Capture is stopped.
- if (capture_size_.IsEmpty())
- capture_size_ = max_frame_size();
- const gfx::Size visible_size = capture_size_;
+ const gfx::Size visible_size = resolution_chooser_.capture_size();
// Always round up the coded size to multiple of 16 pixels.
// See http://crbug.com/402151.
const gfx::Size coded_size((visible_size.width() + 15) & ~15,
@@ -141,30 +141,15 @@ bool ThreadSafeCaptureOracle::ObserveEventAndDecideCapture(
gfx::Size ThreadSafeCaptureOracle::GetCaptureSize() const {
base::AutoLock guard(lock_);
- return capture_size_.IsEmpty() ? max_frame_size() : capture_size_;
+ return resolution_chooser_.capture_size();
}
void ThreadSafeCaptureOracle::UpdateCaptureSize(const gfx::Size& source_size) {
base::AutoLock guard(lock_);
-
- // Update |capture_size_| based on |source_size| if either: 1) The resolution
- // change policy specifies fixed frame sizes and |capture_size_| has not yet
- // been set; or 2) The resolution change policy specifies dynamic frame
- // sizes.
- if (capture_size_.IsEmpty() || params_.resolution_change_policy ==
- media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT) {
- capture_size_ = source_size;
- // The capture size should not exceed the maximum frame size.
- if (capture_size_.width() > max_frame_size().width() ||
- capture_size_.height() > max_frame_size().height()) {
- capture_size_ = media::ComputeLetterboxRegion(
- gfx::Rect(max_frame_size()), capture_size_).size();
- }
- // The capture size must be even and not less than the minimum frame size.
- capture_size_ = gfx::Size(
- std::max(kMinFrameWidth, MakeEven(capture_size_.width())),
- std::max(kMinFrameHeight, MakeEven(capture_size_.height())));
- }
+ resolution_chooser_.SetSourceSize(source_size);
+ VLOG(1) << "Source size changed to " << source_size.ToString()
+ << " --> Capture size is now "
+ << resolution_chooser_.capture_size().ToString();
}
void ThreadSafeCaptureOracle::Stop() {
@@ -234,23 +219,15 @@ void ContentVideoCaptureDeviceCore::AllocateAndStart(
return;
}
- if (params.requested_format.frame_size.width() < kMinFrameWidth ||
- params.requested_format.frame_size.height() < kMinFrameHeight) {
- std::string error_msg =
- "invalid frame size: " + params.requested_format.frame_size.ToString();
- DVLOG(1) << error_msg;
- client->OnError(error_msg);
- return;
- }
-
- media::VideoCaptureParams new_params = params;
- // Frame dimensions must each be an even integer since the client wants (or
- // will convert to) YUV420.
- new_params.requested_format.frame_size.SetSize(
- MakeEven(params.requested_format.frame_size.width()),
- MakeEven(params.requested_format.frame_size.height()));
+ if (params.requested_format.frame_size.IsEmpty()) {
+ std::string error_msg =
+ "invalid frame size: " + params.requested_format.frame_size.ToString();
+ DVLOG(1) << error_msg;
+ client->OnError(error_msg);
+ return;
+ }
- oracle_proxy_ = new ThreadSafeCaptureOracle(client.Pass(), new_params);
+ oracle_proxy_ = new ThreadSafeCaptureOracle(client.Pass(), params);
// Starts the capture machine asynchronously.
BrowserThread::PostTaskAndReplyWithResult(
@@ -259,7 +236,7 @@ void ContentVideoCaptureDeviceCore::AllocateAndStart(
base::Bind(&VideoCaptureMachine::Start,
base::Unretained(capture_machine_.get()),
oracle_proxy_,
- new_params),
+ params),
base::Bind(&ContentVideoCaptureDeviceCore::CaptureStarted, AsWeakPtr()));
TransitionStateTo(kCapturing);

Powered by Google App Engine
This is Rietveld 408576698