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

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

Issue 1806883004: Use the encoded video mode for capture setup of decklink devices. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..b31e0b4887e0a5100296a039dffdea66af639924 100644
--- a/media/capture/video/mac/video_capture_device_decklink_mac.mm
+++ b/media/capture/video/mac/video_capture_device_decklink_mac.mm
@@ -13,6 +13,11 @@
#include "base/synchronization/lock.h"
#include "third_party/decklink/mac/include/DeckLinkAPI.h"
+namespace media {
+static std::string JoinDeviceNameAndFormat(CFStringRef name,
mcasas 2016/04/12 17:54:42 If this function is only used in this file, we can
jensf 2016/04/21 07:29:47 Done.
+ CFStringRef format);
+};
+
namespace {
// DeckLink SDK uses ScopedComPtr-style APIs. Chrome ScopedComPtr is only
@@ -135,52 +140,66 @@ void DeckLinkCaptureDelegate::AllocateAndStart(
scoped_refptr<IDeckLinkIterator> decklink_iter(
CreateDeckLinkIteratorInstance());
DLOG_IF(ERROR, !decklink_iter.get()) << "Error creating DeckLink iterator";
- if (!decklink_iter.get())
+ if (!decklink_iter.get()) {
mcasas 2016/04/12 17:54:42 No {} for one-line bodies.
jensf 2016/04/21 07:29:47 Done.
return;
+ }
+
+ 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);
- ScopedDeckLinkPtr<IDeckLink> decklink_local;
- while (decklink_iter->Next(decklink_local.Receive()) == S_OK) {
CFStringRef device_model_name = NULL;
mcasas 2016/04/12 17:54:42 nullptr? nil?
jensf 2016/04/21 07:29:47 Done.
- if ((decklink_local->GetModelName(&device_model_name) == S_OK) ||
- (device_name_.id() == base::SysCFStringRefToUTF8(device_model_name))) {
- break;
+ HRESULT hr = decklink_local->GetModelName(&device_model_name);
+ DVLOG_IF(1, hr != S_OK) << "Error reading Blackmagic device model name";
mcasas 2016/04/12 17:54:42 Consider DLOG_IF(ERROR,...
jensf 2016/04/21 07:29:46 Done.
+ 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);
+
+ 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(
+ media::JoinDeviceNameAndFormat(device_display_name, format_name),
+ media::JoinDeviceNameAndFormat(device_model_name, format_name),
+ media::VideoCaptureDevice::Name::DECKLINK,
+ media::VideoCaptureDevice::Name::OTHER_TRANSPORT);
+
+ if (device_name_.id() == name.id()) {
+ chosen_device.swap(decklink_local);
+ chosen_input.swap(decklink_input);
+ chosen_display_mode.swap(display_mode);
+ break;
+ }
- 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;
+ 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 +214,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() {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698