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

Side by Side Diff: media/video/capture/mac/video_capture_device_decklink_mac.mm

Issue 518073002: Mac VideoCapture: Support for Blackmagic DeckLink device & capabilities enumeration, using SDK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/video/capture/mac/video_capture_device_decklink_mac.h"
6
7 #include "base/logging.h"
8 #include "base/memory/ref_counted.h"
9 #include "third_party/decklink/mac/include/DeckLinkAPI.h"
10
11 namespace {
12
13 // DeckLink SDK uses ScopedComPtr-style APIs. Chrome ScopedComPtr is only
14 // available for Windows builds. This is a knock-off of the needed parts of
15 // base::win::ScopedComPtr<> for ref counting.
16 template <class T>
17 class ScopedDeckLinkPtr : public scoped_refptr<T> {
18 public:
19 using scoped_refptr<T>::ptr_;
20
21 T** Receive() {
22 DCHECK(!ptr_) << "Object leak. Pointer must be NULL";
23 return &ptr_;
24 }
25
26 void** ReceiveVoid() {
27 return reinterpret_cast<void**>(Receive());
28 }
29
30 void Release() {
31 if (ptr_ != NULL) {
magjed_chromium 2014/09/01 10:41:13 Sometimes you compare with NULL, sometimes you don
mcasas 2014/09/01 14:04:49 This is copy-paste from [1] and I wanted to leave
magjed_chromium 2014/09/01 14:44:37 Ok, but you do it in the rest of the code as well,
32 ptr_->Release();
33 ptr_ = NULL;
34 }
35 }
36 };
37
38 } // namespace
39
40 namespace media {
41
42 //static
43 void VideoCaptureDeviceDeckLinkMac::EnumerateDevices(
44 VideoCaptureDevice::Names* device_names) {
45 scoped_refptr<IDeckLinkIterator> decklink_iter(
46 CreateDeckLinkIteratorInstance());
47 DLOG_IF(ERROR, decklink_iter != NULL) << "Error creating DeckLink iterator";
magjed_chromium 2014/09/01 14:44:37 This looks wrong, shouldn't it be "decklink_iter =
48 if (!decklink_iter)
49 return;
50
51 ScopedDeckLinkPtr<IDeckLink> decklink;
52 while (decklink_iter->Next(decklink.Receive()) == S_OK) {
53 CFStringRef device_model_name = NULL;
54 HRESULT hr = decklink->GetModelName(&device_model_name);
55 DVLOG_IF(1, hr != S_OK) << "Error reading Blackmagic device model name";
56 CFStringRef device_display_name = NULL;
57 hr = decklink->GetDisplayName(&device_display_name);
58 DVLOG_IF(1, hr != S_OK) << "Error reading Blackmagic device display name";
59 DVLOG_IF(1, hr == S_OK) << "Blackmagic camera found, name: " <<
60 [(NSString*)device_display_name UTF8String];
61
62 VideoCaptureDevice::Name name([(NSString*)device_model_name UTF8String],
63 [(NSString*)device_display_name UTF8String],
64 VideoCaptureDevice::Name::DECKLINK,
65 VideoCaptureDevice::Name::OTHER_TRANSPORT);
66 device_names->push_back(name);
magjed_chromium 2014/09/01 10:41:13 Should we really add this device even if GetModelN
mcasas 2014/09/01 14:04:50 Done.
67 decklink.Release();
68 }
69 }
70
71 // static
72 void VideoCaptureDeviceDeckLinkMac::EnumerateDeviceCapabilities(
73 const VideoCaptureDevice::Name& device,
74 VideoCaptureFormats* supported_formats) {
75 ScopedDeckLinkPtr<IDeckLink> decklink;
76 scoped_refptr<IDeckLinkIterator> decklink_iter(
77 CreateDeckLinkIteratorInstance());
78 DLOG_IF(ERROR, decklink_iter != NULL) << "Error creating DeckLink iterator";
magjed_chromium 2014/09/01 14:44:37 Same as above.
79 if (!decklink_iter)
80 return;
81
82 while (decklink_iter->Next(decklink.Receive()) == S_OK) {
83 CFStringRef device_model_name = NULL;
84 if (decklink->GetModelName(&device_model_name) != S_OK)
85 continue;
86 if (device.id().compare([(NSString*)device_model_name UTF8String]) != 0)
87 continue;
88
89 ScopedDeckLinkPtr<IDeckLinkInput> decklink_input;
90 if (decklink->QueryInterface(IID_IDeckLinkInput,
91 decklink_input.ReceiveVoid()) != S_OK) {
92 DLOG(ERROR) << "Error Blackmagic querying input interface.";
93 return;
94 }
95
96 ScopedDeckLinkPtr<IDeckLinkDisplayModeIterator> display_mode_iter;
97 if (decklink_input->GetDisplayModeIterator(display_mode_iter.Receive())
98 != S_OK) {
perkj_chrome 2014/09/01 09:50:41 nit try to keep != on the line with the first arg
mcasas 2014/09/01 14:04:50 Done.
99 continue;
100 }
101
102 ScopedDeckLinkPtr<IDeckLinkDisplayMode> displayMode;
103 while (display_mode_iter->Next(displayMode.Receive()) == S_OK) {
104 // IDeckLinkDisplayMode does not have information on pixel format, it
105 // is only available on capture.
106 media::VideoPixelFormat pixelFormat = media::PIXEL_FORMAT_UNKNOWN;
107 BMDTimeValue time_value, time_scale;
108 float frame_rate = 0.0f;
109 if (displayMode->GetFrameRate(&time_value, &time_scale) == S_OK &&
110 time_value > 0) {
111 frame_rate = static_cast<float>(time_scale) / time_value;
112 }
113 media::VideoCaptureFormat format(
114 gfx::Size(displayMode->GetWidth(), displayMode->GetHeight()),
115 frame_rate,
116 pixelFormat);
117 supported_formats->push_back(format);
118 DVLOG(2) << device.name() << " resolution: "
magjed_chromium 2014/09/01 10:41:13 I have seen similar code like this in at least fou
mcasas 2014/09/01 14:04:49 Probably. http://crbug.com/409636
119 << format.frame_size.ToString() << "@: " << format.frame_rate
120 << ", pixel format: " << format.pixel_format;
121 displayMode.Release();
122 }
123 decklink.Release();
124 }
125 }
126
127 VideoCaptureDeviceDeckLinkMac::VideoCaptureDeviceDeckLinkMac(
128 const Name& device_name) {}
129
130 VideoCaptureDeviceDeckLinkMac::~VideoCaptureDeviceDeckLinkMac() {}
131
132 void VideoCaptureDeviceDeckLinkMac::AllocateAndStart(
133 const VideoCaptureParams& params,
134 scoped_ptr<VideoCaptureDevice::Client> client) {}
perkj_chrome 2014/09/01 09:50:41 add NOTIMPLEMENTED
mcasas 2014/09/01 14:04:50 Done.
135
136 void VideoCaptureDeviceDeckLinkMac::StopAndDeAllocate() {}
perkj_chrome 2014/09/01 09:50:41 add NOTIMPLEMENTED
mcasas 2014/09/01 14:04:49 Done.
137
138 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698