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

Unified Diff: content/browser/renderer_host/media/video_capture_manager.cc

Issue 29423003: Added video capture capabilities retrieval and caching to VideoCaptureManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed mechanics of Caps enumeration to be asynchronous and 2 threaded. UT adapted. Created 7 years, 2 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/renderer_host/media/video_capture_manager.cc
diff --git a/content/browser/renderer_host/media/video_capture_manager.cc b/content/browser/renderer_host/media/video_capture_manager.cc
index b271583a3e13c18da5826d55de12a1f98e73f25b..2c46693a2e35b98161ac3cfdfeaaeae096550146 100644
--- a/content/browser/renderer_host/media/video_capture_manager.cc
+++ b/content/browser/renderer_host/media/video_capture_manager.cc
@@ -150,6 +150,12 @@ void VideoCaptureManager::DoStartDeviceOnDeviceThread(
video_capture_device.reset(use_fake_device_ ?
media::FakeVideoCaptureDevice::Create(*found) :
media::VideoCaptureDevice::Create(*found));
+
+ // Filter capture capabilities: remove all except the current one.
tommi (sloooow) - chröme 2013/10/25 14:15:34 why? (usually that's more important to document th
mcasas 2013/10/28 12:50:08 Done.
+ media::VideoCaptureCapabilities& formats =
+ video_capture_capabilities_[entry->id];
+ formats.clear();
+ formats.push_back(capture_params);
}
break;
}
@@ -253,6 +259,23 @@ void VideoCaptureManager::StopCaptureForClient(
DestroyDeviceEntryIfNoClients(entry);
}
+void VideoCaptureManager::EnumerateDeviceCapabilities(
+ const StreamDeviceInfo& device_info) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DVLOG(1) << "VideoCaptureManager::EnumerateDeviceCapabilites for device: "
+ << device_info.device.name;
+ DCHECK(listener_);
+ base::PostTaskAndReplyWithResult(
+ device_loop_,
+ FROM_HERE,
+ base::Bind(&VideoCaptureManager::GetDeviceCapabilitiesOnDeviceThread,
+ this,
+ device_info),
+ base::Bind(&VideoCaptureManager::OnDeviceCapabilitiesEnumerated,
+ this,
+ device_info));
+}
+
void VideoCaptureManager::DoStopDeviceOnDeviceThread(DeviceEntry* entry) {
SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StopDeviceTime");
DCHECK(IsOnDeviceThread());
@@ -291,6 +314,7 @@ void VideoCaptureManager::OnDevicesEnumerated(
// Listener has been removed.
return;
}
+ DVLOG(1) << "OnDevicesEnumerated";
tommi (sloooow) - chröme 2013/10/25 14:15:34 nit: above the listener check
mcasas 2013/10/28 12:50:08 Done.
// Transform from VCD::Name to StreamDeviceInfo.
StreamDeviceInfoArray devices;
@@ -303,6 +327,20 @@ void VideoCaptureManager::OnDevicesEnumerated(
listener_->DevicesEnumerated(stream_type, devices);
}
+void VideoCaptureManager::OnDeviceCapabilitiesEnumerated(
+ const StreamDeviceInfo& device_info,
+ const media::VideoCaptureCapabilities& capabilities) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+
+ if (!listener_) {
+ // Listener has been removed.
+ return;
+ }
+ DVLOG(1) << "OnDeviceCapabilitiesEnumerated device: "
tommi (sloooow) - chröme 2013/10/25 14:15:34 nit: move this DLOG above the listener_ check so t
mcasas 2013/10/28 12:50:08 Done.
+ << device_info.device.id;
+ listener_->DeviceCapabilitiesEnumerated(device_info, capabilities);
+}
+
bool VideoCaptureManager::IsOnDeviceThread() const {
return device_loop_->BelongsToCurrentThread();
}
@@ -322,8 +360,21 @@ VideoCaptureManager::GetAvailableDevicesOnDeviceThread(
// enumerate the devices again.
if (!use_fake_device_) {
media::VideoCaptureDevice::GetDeviceNames(&result);
+ // Add to the cache the devices' supported capture formats.
tommi (sloooow) - chröme 2013/10/25 14:15:34 nit: sentence structure - it feels more natural to
mcasas 2013/10/28 12:50:08 Done.
+ media::VideoCaptureDevice::Names::iterator name_it;
+ for (name_it = result.begin(); name_it != result.end(); ++name_it) {
+ media::VideoCaptureDevice::GetDeviceSupportedFormats(
+ *name_it, &video_capture_capabilities_[name_it->id()] );
tommi (sloooow) - chröme 2013/10/25 14:15:34 before sending a pointer to the entry in the map,
mcasas 2013/10/28 12:50:08 I guess this doesn't apply since the map is gone.
+ }
} else {
media::FakeVideoCaptureDevice::GetDeviceNames(&result);
+ // Add to the cache the devices' supported capture formats.
+ media::VideoCaptureDevice::Names::iterator name_it;
+ media::VideoCaptureCapabilities formats;
+ for (name_it = result.begin(); name_it != result.end(); ++name_it) {
+ media::FakeVideoCaptureDevice::GetDeviceSupportedFormats(
+ *name_it, &video_capture_capabilities_[name_it->id()] );
tommi (sloooow) - chröme 2013/10/25 14:15:34 same here
mcasas 2013/10/28 12:50:08 dixit.
+ }
}
// TODO(nick): The correctness of device start depends on this cache being
@@ -343,6 +394,19 @@ VideoCaptureManager::GetAvailableDevicesOnDeviceThread(
return result;
}
+media::VideoCaptureCapabilities
+VideoCaptureManager::GetDeviceCapabilitiesOnDeviceThread(
+ const StreamDeviceInfo& device_info) const {
+ DCHECK(IsOnDeviceThread());
+
+ // Find the device we are looking for and return its associated capabilities.
+ std::map<std::string, media::VideoCaptureCapabilities>::const_iterator it =
+ video_capture_capabilities_.find(device_info.device.id);
+ if ( it != video_capture_capabilities_.end())
tommi (sloooow) - chröme 2013/10/25 14:15:34 fix spaces
mcasas 2013/10/28 12:50:08 Done.
+ return it->second;
+ return media::VideoCaptureCapabilities();
+}
+
VideoCaptureManager::DeviceEntry*
VideoCaptureManager::GetDeviceEntryForMediaStreamDevice(
const MediaStreamDevice& device_info) {

Powered by Google App Engine
This is Rietveld 408576698