| Index: media/capture/video/mac/video_capture_device_decklink_mac.mm
|
| diff --git a/media/capture/video/mac/video_capture_device_decklink_mac.mm b/media/capture/video/mac/video_capture_device_decklink_mac.mm
|
| index 3841be64f27cc6d4efcb1079082264ad1b4cfe4f..3bcd8cdb8d49c479422501d815f3561bfeb48b95 100644
|
| --- a/media/capture/video/mac/video_capture_device_decklink_mac.mm
|
| +++ b/media/capture/video/mac/video_capture_device_decklink_mac.mm
|
| @@ -15,6 +15,9 @@
|
|
|
| namespace {
|
|
|
| +static std::string JoinDeviceNameAndFormat(CFStringRef name,
|
| + CFStringRef format);
|
| +
|
| // DeckLink SDK uses ScopedComPtr-style APIs. Chrome ScopedComPtr is only
|
| // available for Windows builds. This is a verbatim knock-off of the needed
|
| // parts of base::win::ScopedComPtr<> for ref counting.
|
| @@ -138,49 +141,64 @@ void DeckLinkCaptureDelegate::AllocateAndStart(
|
| if (!decklink_iter.get())
|
| return;
|
|
|
| - ScopedDeckLinkPtr<IDeckLink> decklink_local;
|
| - while (decklink_iter->Next(decklink_local.Receive()) == S_OK) {
|
| - CFStringRef device_model_name = NULL;
|
| - if ((decklink_local->GetModelName(&device_model_name) == S_OK) ||
|
| - (device_name_.id() == base::SysCFStringRefToUTF8(device_model_name))) {
|
| - break;
|
| + ScopedDeckLinkPtr<IDeckLink> chosen_device;
|
| + ScopedDeckLinkPtr<IDeckLinkInput> chosen_input;
|
| + ScopedDeckLinkPtr<IDeckLinkDisplayMode> chosen_display_mode;
|
| + ScopedDeckLinkPtr<IDeckLink> decklink;
|
| + while (decklink_iter->Next(decklink.Receive()) == S_OK) {
|
| + ScopedDeckLinkPtr<IDeckLink> decklink_local;
|
| + decklink_local.swap(decklink);
|
| +
|
| + CFStringRef device_model_name = nil;
|
| + HRESULT hr = decklink_local->GetModelName(&device_model_name);
|
| + DLOG_IF(ERROR, hr != S_OK) << "Error reading Blackmagic device model name";
|
| + CFStringRef device_display_name = nullptr;
|
| + hr = decklink_local->GetDisplayName(&device_display_name);
|
| + DLOG_IF(ERROR, hr != S_OK)
|
| + << "Error reading Blackmagic device display name";
|
| + DLOG_IF(ERROR, hr == S_OK)
|
| + << "Blackmagic device found with name: "
|
| + << base::SysCFStringRefToUTF8(device_display_name);
|
| +
|
| + if (!device_model_name && !device_display_name)
|
| + continue;
|
| +
|
| + ScopedDeckLinkPtr<IDeckLinkInput> decklink_input;
|
| + if (decklink_local->QueryInterface(IID_IDeckLinkInput,
|
| + decklink_input.ReceiveVoid()) != S_OK) {
|
| + DLOG(ERROR) << "Error Blackmagic querying input interface.";
|
| + return;
|
| }
|
| - }
|
| - if (!decklink_local.get()) {
|
| - SendErrorString(FROM_HERE, "Device id not found in the system");
|
| - return;
|
| - }
|
|
|
| - ScopedDeckLinkPtr<IDeckLinkInput> decklink_input_local;
|
| - if (decklink_local->QueryInterface(
|
| - IID_IDeckLinkInput, decklink_input_local.ReceiveVoid()) != S_OK) {
|
| - SendErrorString(FROM_HERE, "Error querying input interface.");
|
| - return;
|
| - }
|
| + ScopedDeckLinkPtr<IDeckLinkDisplayModeIterator> display_mode_iter;
|
| + if (decklink_input->GetDisplayModeIterator(display_mode_iter.Receive()) !=
|
| + S_OK) {
|
| + continue;
|
| + }
|
|
|
| - ScopedDeckLinkPtr<IDeckLinkDisplayModeIterator> display_mode_iter;
|
| - if (decklink_input_local->GetDisplayModeIterator(
|
| - display_mode_iter.Receive()) != S_OK) {
|
| - SendErrorString(FROM_HERE, "Error creating Display Mode Iterator");
|
| - return;
|
| - }
|
| + ScopedDeckLinkPtr<IDeckLinkDisplayMode> display_mode;
|
| + while (display_mode_iter->Next(display_mode.Receive()) == S_OK) {
|
| + CFStringRef format_name = NULL;
|
| + if (display_mode->GetName(&format_name) == S_OK) {
|
| + media::VideoCaptureDevice::Name name(
|
| + JoinDeviceNameAndFormat(device_display_name, format_name),
|
| + JoinDeviceNameAndFormat(device_model_name, format_name),
|
| + media::VideoCaptureDevice::Name::DECKLINK,
|
| + media::VideoCaptureDevice::Name::OTHER_TRANSPORT);
|
|
|
| - ScopedDeckLinkPtr<IDeckLinkDisplayMode> chosen_display_mode;
|
| - ScopedDeckLinkPtr<IDeckLinkDisplayMode> display_mode;
|
| - float min_diff = FLT_MAX;
|
| - while (display_mode_iter->Next(display_mode.Receive()) == S_OK) {
|
| - const float diff = labs(display_mode->GetWidth() -
|
| - params.requested_format.frame_size.width()) +
|
| - labs(params.requested_format.frame_size.height() -
|
| - display_mode->GetHeight()) +
|
| - fabs(params.requested_format.frame_rate -
|
| - GetDisplayModeFrameRate(display_mode));
|
| - if (diff < min_diff) {
|
| - chosen_display_mode = display_mode;
|
| - min_diff = diff;
|
| + if (device_name_.id() == name.id()) {
|
| + chosen_device.swap(decklink_local);
|
| + chosen_input.swap(decklink_input);
|
| + chosen_display_mode.swap(display_mode);
|
| + break;
|
| + }
|
| +
|
| + DVLOG(1) << "Blackmagic camera enumerated: " << name.name();
|
| + }
|
| + display_mode.Release();
|
| }
|
| - display_mode.Release();
|
| }
|
| +
|
| if (!chosen_display_mode.get()) {
|
| SendErrorString(FROM_HERE, "Could not find a display mode");
|
| return;
|
| @@ -195,19 +213,19 @@ void DeckLinkCaptureDelegate::AllocateAndStart(
|
|
|
| // Enable video input. Configure for no input video format change detection,
|
| // this in turn will disable calls to VideoInputFormatChanged().
|
| - if (decklink_input_local->EnableVideoInput(
|
| - chosen_display_mode->GetDisplayMode(), bmdFormat8BitYUV,
|
| - bmdVideoInputFlagDefault) != S_OK) {
|
| + if (chosen_input->EnableVideoInput(chosen_display_mode->GetDisplayMode(),
|
| + bmdFormat8BitYUV,
|
| + bmdVideoInputFlagDefault) != S_OK) {
|
| SendErrorString(FROM_HERE, "Could not select the video format we like.");
|
| return;
|
| }
|
|
|
| - decklink_input_local->SetCallback(this);
|
| - if (decklink_input_local->StartStreams() != S_OK)
|
| + chosen_input->SetCallback(this);
|
| + if (chosen_input->StartStreams() != S_OK) {
|
| SendErrorString(FROM_HERE, "Could not start capturing");
|
| -
|
| - decklink_.swap(decklink_local);
|
| - decklink_input_.swap(decklink_input_local);
|
| + }
|
| + decklink_.swap(chosen_device);
|
| + decklink_input_.swap(chosen_input);
|
| }
|
|
|
| void DeckLinkCaptureDelegate::StopAndDeAllocate() {
|
| @@ -312,9 +330,6 @@ void DeckLinkCaptureDelegate::ResetVideoCaptureDeviceReference() {
|
| frame_receiver_ = NULL;
|
| }
|
|
|
| -} // namespace
|
| -
|
| -namespace media {
|
|
|
| static std::string JoinDeviceNameAndFormat(CFStringRef name,
|
| CFStringRef format) {
|
| @@ -322,6 +337,10 @@ static std::string JoinDeviceNameAndFormat(CFStringRef name,
|
| base::SysCFStringRefToUTF8(format);
|
| }
|
|
|
| +} // namespace
|
| +
|
| +namespace media {
|
| +
|
| // static
|
| void VideoCaptureDeviceDeckLinkMac::EnumerateDevices(
|
| VideoCaptureDevice::Names* device_names) {
|
| @@ -329,7 +348,7 @@ void VideoCaptureDeviceDeckLinkMac::EnumerateDevices(
|
| CreateDeckLinkIteratorInstance());
|
| // At this point, not being able to create a DeckLink iterator means that
|
| // there are no Blackmagic DeckLink devices in the system, don't print error.
|
| - DVLOG_IF(1, !decklink_iter.get()) << "Could not create DeckLink iterator";
|
| + DLOG_IF(ERROR, !decklink_iter.get()) << "Could not create DeckLink iterator";
|
| if (!decklink_iter.get())
|
| return;
|
|
|
| @@ -340,12 +359,14 @@ void VideoCaptureDeviceDeckLinkMac::EnumerateDevices(
|
|
|
| CFStringRef device_model_name = NULL;
|
| HRESULT hr = decklink_local->GetModelName(&device_model_name);
|
| - DVLOG_IF(1, hr != S_OK) << "Error reading Blackmagic device model name";
|
| + DLOG_IF(ERROR, hr != S_OK) << "Error reading Blackmagic device model name";
|
| CFStringRef device_display_name = NULL;
|
| hr = decklink_local->GetDisplayName(&device_display_name);
|
| - DVLOG_IF(1, hr != S_OK) << "Error reading Blackmagic device display name";
|
| - DVLOG_IF(1, hr == S_OK) << "Blackmagic device found with name: "
|
| - << base::SysCFStringRefToUTF8(device_display_name);
|
| + DLOG_IF(ERROR, hr != S_OK)
|
| + << "Error reading Blackmagic device display name";
|
| + DLOG_IF(ERROR, hr == S_OK)
|
| + << "Blackmagic device found with name: "
|
| + << base::SysCFStringRefToUTF8(device_display_name);
|
|
|
| if (!device_model_name && !device_display_name)
|
| continue;
|
|
|