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

Unified Diff: media/capture/video/mac/video_capture_device_mac.mm

Issue 2169013002: Change class VideoCaptureDevice::Name to struct VideoCaptureDeviceDescriptor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build errors Created 4 years, 5 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
« no previous file with comments | « media/capture/video/mac/video_capture_device_mac.h ('k') | media/capture/video/video_capture_device.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/capture/video/mac/video_capture_device_mac.mm
diff --git a/media/capture/video/mac/video_capture_device_mac.mm b/media/capture/video/mac/video_capture_device_mac.mm
index e11e646de7f847979beb018dbe337ca03937dfbd..8a87ec94387a2295a460182739de511a3c46e42c 100644
--- a/media/capture/video/mac/video_capture_device_mac.mm
+++ b/media/capture/video/mac/video_capture_device_mac.mm
@@ -292,32 +292,13 @@ static void SetAntiFlickerInUsbDevice(const int vendor_id,
}
}
-const std::string VideoCaptureDevice::Name::GetModel() const {
- // Skip the AVFoundation's not USB nor built-in devices.
- if (capture_api_type() == AVFOUNDATION && transport_type() != USB_OR_BUILT_IN)
- return "";
- if (capture_api_type() == DECKLINK)
- return "";
- // Both PID and VID are 4 characters.
- if (unique_id_.size() < 2 * kVidPidSize)
- return "";
-
- // The last characters of device id is a concatenation of VID and then PID.
- const size_t vid_location = unique_id_.size() - 2 * kVidPidSize;
- std::string id_vendor = unique_id_.substr(vid_location, kVidPidSize);
- const size_t pid_location = unique_id_.size() - kVidPidSize;
- std::string id_product = unique_id_.substr(pid_location, kVidPidSize);
-
- return id_vendor + ":" + id_product;
-}
-
-VideoCaptureDeviceMac::VideoCaptureDeviceMac(const Name& device_name)
- : device_name_(device_name),
+VideoCaptureDeviceMac::VideoCaptureDeviceMac(
+ const VideoCaptureDeviceDescriptor& device_descriptor)
+ : device_descriptor_(device_descriptor),
task_runner_(base::ThreadTaskRunnerHandle::Get()),
state_(kNotInitialized),
capture_device_(nil),
- weak_factory_(this) {
-}
+ weak_factory_(this) {}
VideoCaptureDeviceMac::~VideoCaptureDeviceMac() {
DCHECK(task_runner_->BelongsToCurrentThread());
@@ -332,11 +313,12 @@ void VideoCaptureDeviceMac::AllocateAndStart(
}
client_ = std::move(client);
- if (device_name_.capture_api_type() == Name::AVFOUNDATION)
- LogMessage("Using AVFoundation for device: " + device_name_.name());
+ if (device_descriptor_.capture_api == VideoCaptureApi::MACOSX_AVFOUNDATION)
+ LogMessage("Using AVFoundation for device: " +
+ device_descriptor_.display_name);
NSString* deviceId =
- [NSString stringWithUTF8String:device_name_.id().c_str()];
+ [NSString stringWithUTF8String:device_descriptor_.device_id.c_str()];
[capture_device_ setFrameReceiver:this];
@@ -359,7 +341,9 @@ void VideoCaptureDeviceMac::AllocateAndStart(
// Try setting the power line frequency removal (anti-flicker). The built-in
// cameras are normally suspended so the configuration must happen right
// before starting capture and during configuration.
- const std::string& device_model = device_name_.GetModel();
+ const std::string device_model = GetDeviceModelId(
+ device_descriptor_.device_id, device_descriptor_.capture_api,
+ device_descriptor_.transport_type);
if (device_model.length() > 2 * kVidPidSize) {
std::string vendor_id = device_model.substr(0, kVidPidSize);
std::string model_id = device_model.substr(kVidPidSize + 1);
@@ -400,12 +384,11 @@ void VideoCaptureDeviceMac::TakePhoto(TakePhotoCallback callback) {
[capture_device_ takePhoto];
}
-bool VideoCaptureDeviceMac::Init(
- VideoCaptureDevice::Name::CaptureApiType capture_api_type) {
+bool VideoCaptureDeviceMac::Init(VideoCaptureApi capture_api_type) {
DCHECK(task_runner_->BelongsToCurrentThread());
DCHECK_EQ(state_, kNotInitialized);
- if (capture_api_type != Name::AVFOUNDATION)
+ if (capture_api_type != VideoCaptureApi::MACOSX_AVFOUNDATION)
return false;
capture_device_.reset(
@@ -464,6 +447,36 @@ void VideoCaptureDeviceMac::ReceiveError(
weak_factory_.GetWeakPtr(), from_here, reason));
}
+void VideoCaptureDeviceMac::LogMessage(const std::string& message) {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+ if (client_)
+ client_->OnLog(message);
+}
+
+// static
+std::string VideoCaptureDeviceMac::GetDeviceModelId(
+ const std::string& device_id,
+ VideoCaptureApi capture_api,
+ VideoCaptureTransportType transport_type) {
+ // Skip the AVFoundation's not USB nor built-in devices.
+ if (capture_api == VideoCaptureApi::MACOSX_AVFOUNDATION &&
+ transport_type != VideoCaptureTransportType::MACOSX_USB_OR_BUILT_IN)
+ return "";
+ if (capture_api == VideoCaptureApi::MACOSX_DECKLINK)
+ return "";
+ // Both PID and VID are 4 characters.
+ if (device_id.size() < 2 * kVidPidSize)
+ return "";
+
+ // The last characters of device id is a concatenation of VID and then PID.
+ const size_t vid_location = device_id.size() - 2 * kVidPidSize;
+ std::string id_vendor = device_id.substr(vid_location, kVidPidSize);
+ const size_t pid_location = device_id.size() - kVidPidSize;
+ std::string id_product = device_id.substr(pid_location, kVidPidSize);
+
+ return id_vendor + ":" + id_product;
+}
+
void VideoCaptureDeviceMac::SetErrorState(
const tracked_objects::Location& from_here,
const std::string& reason) {
@@ -472,12 +485,6 @@ void VideoCaptureDeviceMac::SetErrorState(
client_->OnError(from_here, reason);
}
-void VideoCaptureDeviceMac::LogMessage(const std::string& message) {
- DCHECK(task_runner_->BelongsToCurrentThread());
- if (client_)
- client_->OnLog(message);
-}
-
bool VideoCaptureDeviceMac::UpdateCaptureResolution() {
if (![capture_device_ setCaptureHeight:capture_format_.frame_size.height()
width:capture_format_.frame_size.width()
« no previous file with comments | « media/capture/video/mac/video_capture_device_mac.h ('k') | media/capture/video/video_capture_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698