OLD | NEW |
---|---|
(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 verbatim knock-off of the needed | |
15 // parts of 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) { | |
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) << "Error creating DeckLink iterator"; | |
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]; | |
Robert Sesek
2014/09/02 18:50:50
SysCFStringRefToUTF8
mcasas
2014/09/03 09:04:42
Done.
| |
61 | |
62 if (device_model_name || device_display_name) { | |
63 VideoCaptureDevice::Name name([(NSString*)device_model_name UTF8String], | |
Robert Sesek
2014/09/02 18:50:50
SysCFStringRefToUTF8
mcasas
2014/09/03 09:04:42
Done.
| |
64 [(NSString*)device_display_name UTF8String], | |
Robert Sesek
2014/09/02 18:50:50
SysCFStringRefToUTF8
mcasas
2014/09/03 09:04:42
Done.
| |
65 VideoCaptureDevice::Name::DECKLINK, | |
66 VideoCaptureDevice::Name::OTHER_TRANSPORT); | |
67 device_names->push_back(name); | |
68 } | |
69 decklink.Release(); | |
70 } | |
71 } | |
72 | |
73 // static | |
74 void VideoCaptureDeviceDeckLinkMac::EnumerateDeviceCapabilities( | |
75 const VideoCaptureDevice::Name& device, | |
76 VideoCaptureFormats* supported_formats) { | |
77 ScopedDeckLinkPtr<IDeckLink> decklink; | |
78 scoped_refptr<IDeckLinkIterator> decklink_iter( | |
79 CreateDeckLinkIteratorInstance()); | |
80 DLOG_IF(ERROR, !decklink_iter) << "Error creating DeckLink iterator"; | |
81 if (!decklink_iter) | |
82 return; | |
83 | |
84 while (decklink_iter->Next(decklink.Receive()) == S_OK) { | |
85 CFStringRef device_model_name = NULL; | |
86 if (decklink->GetModelName(&device_model_name) != S_OK) | |
87 continue; | |
88 if (device.id().compare([(NSString*)device_model_name UTF8String]) != 0) | |
Robert Sesek
2014/09/02 18:50:50
SysCFStringRefToUTF8
mcasas
2014/09/03 09:04:42
Done.
| |
89 continue; | |
90 | |
91 ScopedDeckLinkPtr<IDeckLinkInput> decklink_input; | |
92 if (decklink->QueryInterface(IID_IDeckLinkInput, | |
93 decklink_input.ReceiveVoid()) != S_OK) { | |
94 DLOG(ERROR) << "Error Blackmagic querying input interface."; | |
95 return; | |
96 } | |
97 | |
98 ScopedDeckLinkPtr<IDeckLinkDisplayModeIterator> display_mode_iter; | |
99 if (decklink_input->GetDisplayModeIterator(display_mode_iter.Receive()) != | |
100 S_OK) { | |
101 continue; | |
102 } | |
103 | |
104 ScopedDeckLinkPtr<IDeckLinkDisplayMode> display_mode; | |
105 while (display_mode_iter->Next(display_mode.Receive()) == S_OK) { | |
106 // IDeckLinkDisplayMode does not have information on pixel format, it | |
107 // is only available on capture. | |
108 media::VideoPixelFormat pixel_format = media::PIXEL_FORMAT_UNKNOWN; | |
109 BMDTimeValue time_value, time_scale; | |
110 float frame_rate = 0.0f; | |
111 if (display_mode->GetFrameRate(&time_value, &time_scale) == S_OK && | |
112 time_value > 0) { | |
113 frame_rate = static_cast<float>(time_scale) / time_value; | |
114 } | |
115 media::VideoCaptureFormat format( | |
116 gfx::Size(display_mode->GetWidth(), display_mode->GetHeight()), | |
117 frame_rate, | |
118 pixel_format); | |
119 supported_formats->push_back(format); | |
120 DVLOG(2) << device.name() << " resolution: " | |
121 << format.frame_size.ToString() << "@: " << format.frame_rate | |
122 << ", pixel format: " << format.pixel_format; | |
123 display_mode.Release(); | |
124 } | |
125 decklink.Release(); | |
126 } | |
127 } | |
128 | |
129 VideoCaptureDeviceDeckLinkMac::VideoCaptureDeviceDeckLinkMac( | |
130 const Name& device_name) {} | |
131 | |
132 VideoCaptureDeviceDeckLinkMac::~VideoCaptureDeviceDeckLinkMac() {} | |
133 | |
134 void VideoCaptureDeviceDeckLinkMac::AllocateAndStart( | |
135 const VideoCaptureParams& params, | |
136 scoped_ptr<VideoCaptureDevice::Client> client) { | |
137 NOTIMPLEMENTED(); | |
Robert Sesek
2014/09/02 18:50:50
Are these going to need to be implemented? What ha
mcasas
2014/09/03 09:04:42
Yes, there is a follow up CL implementing these tw
| |
138 } | |
139 | |
140 void VideoCaptureDeviceDeckLinkMac::StopAndDeAllocate() { | |
141 NOTIMPLEMENTED(); | |
142 } | |
143 | |
144 } // namespace media | |
OLD | NEW |