OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Implementation of VideoCaptureDevice class for Blackmagic video capture | 5 // Implementation of VideoCaptureDevice class for Blackmagic video capture |
6 // devices by using the DeckLink SDK. | 6 // devices by using the DeckLink SDK. |
7 | 7 |
8 #ifndef MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_DECKLINK_MAC_H_ | 8 #ifndef MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_DECKLINK_MAC_H_ |
9 #define MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_DECKLINK_MAC_H_ | 9 #define MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_DECKLINK_MAC_H_ |
10 | 10 |
11 #include "media/video/capture/video_capture_device.h" | 11 #include "media/video/capture/video_capture_device.h" |
12 | 12 |
13 #import <Foundation/Foundation.h> | 13 #import <Foundation/Foundation.h> |
14 | 14 |
15 #include "third_party/decklink/mac/include/DeckLinkAPI.h" | |
16 | |
17 namespace { | |
18 | |
19 // DeckLink SDK uses ScopedComPtr-style APIs. Chrome ScopedComPtr is only | |
20 // available for Windows builds. This is a verbatim knock-off of the needed | |
21 // parts of base::win::ScopedComPtr<> for ref counting. | |
22 template <class T> | |
23 class ScopedDeckLinkPtr : public scoped_refptr<T> { | |
24 public: | |
25 using scoped_refptr<T>::ptr_; | |
tommi (sloooow) - chröme
2014/09/05 09:24:21
why do you need this?
mcasas
2014/09/09 11:05:00
Subtemplating a template is a bit special, meaning
tommi (sloooow) - chröme
2014/09/22 20:26:38
Ah, sorry, I was actually more thinking why you're
| |
26 | |
27 T** Receive() { | |
28 DCHECK(!ptr_) << "Object leak. Pointer must be NULL"; | |
29 return &ptr_; | |
30 } | |
31 | |
32 void** ReceiveVoid() { | |
33 return reinterpret_cast<void**>(Receive()); | |
34 } | |
35 | |
36 void Release() { | |
37 if (ptr_ != NULL) { | |
38 ptr_->Release(); | |
39 ptr_ = NULL; | |
40 } | |
41 } | |
42 }; | |
43 | |
44 } // namespace | |
45 | |
46 | |
15 namespace media { | 47 namespace media { |
16 | 48 |
17 // Extension of VideoCaptureDevice to create and manipulate Blackmagic devices | 49 // Extension of VideoCaptureDevice to create and manipulate Blackmagic devices |
18 // via DeckLink SDK. | 50 // via DeckLink SDK. |
19 class MEDIA_EXPORT VideoCaptureDeviceDeckLinkMac : public VideoCaptureDevice { | 51 class MEDIA_EXPORT VideoCaptureDeviceDeckLinkMac : |
52 public VideoCaptureDevice, | |
53 public IDeckLinkInputCallback { | |
20 public: | 54 public: |
21 // Gets the names of all DeckLink video capture devices connected to this | 55 // Gets the names of all DeckLink video capture devices connected to this |
22 // computer, as enumerated by the DeckLink SDK. | 56 // computer, as enumerated by the DeckLink SDK. |
23 static void EnumerateDevices(VideoCaptureDevice::Names* device_names); | 57 static void EnumerateDevices(VideoCaptureDevice::Names* device_names); |
24 | 58 |
25 // Gets the supported formats of a particular device attached to the system, | 59 // Gets the supported formats of a particular device attached to the system, |
26 // identified by |device|. Formats are retrieved from the DeckLink SDK. | 60 // identified by |device|. Formats are retrieved from the DeckLink SDK. |
27 static void EnumerateDeviceCapabilities( | 61 static void EnumerateDeviceCapabilities( |
28 const VideoCaptureDevice::Name& device, | 62 const VideoCaptureDevice::Name& device, |
29 VideoCaptureFormats* supported_formats); | 63 VideoCaptureFormats* supported_formats); |
30 | 64 |
31 explicit VideoCaptureDeviceDeckLinkMac(const Name& device_name); | 65 explicit VideoCaptureDeviceDeckLinkMac(const Name& device_name); |
32 virtual ~VideoCaptureDeviceDeckLinkMac(); | 66 virtual ~VideoCaptureDeviceDeckLinkMac(); |
33 | 67 |
34 // VideoCaptureDevice implementation. | 68 // VideoCaptureDevice implementation. |
35 virtual void AllocateAndStart( | 69 virtual void AllocateAndStart( |
36 const VideoCaptureParams& params, | 70 const VideoCaptureParams& params, |
37 scoped_ptr<VideoCaptureDevice::Client> client) OVERRIDE; | 71 scoped_ptr<VideoCaptureDevice::Client> client) OVERRIDE; |
38 virtual void StopAndDeAllocate() OVERRIDE; | 72 virtual void StopAndDeAllocate() OVERRIDE; |
39 | 73 |
74 // IDeckLinkInputCallback interface implementation. | |
tommi (sloooow) - chröme
2014/09/05 09:24:20
should this be private/protected? (same for the Vi
mcasas
2014/09/09 11:05:00
Had a second look at the inheritance qualifiers an
| |
75 virtual HRESULT VideoInputFormatChanged ( | |
76 BMDVideoInputFormatChangedEvents notification_events, | |
77 IDeckLinkDisplayMode *new_display_mode, | |
78 BMDDetectedVideoInputFormatFlags detected_signal_flags) OVERRIDE; | |
79 virtual HRESULT VideoInputFrameArrived ( | |
80 IDeckLinkVideoInputFrame* video_frame, | |
81 IDeckLinkAudioInputPacket* audio_packet) OVERRIDE; | |
82 | |
83 // IUnknown interface implementation. | |
84 virtual HRESULT QueryInterface (REFIID iid, LPVOID *ppv) OVERRIDE; | |
tommi (sloooow) - chröme
2014/09/05 09:24:21
Since this implements reference counting and Video
mcasas
2014/09/09 11:05:00
I created a DeckLinkCaptureDelegate class that hol
| |
85 virtual ULONG AddRef() OVERRIDE; | |
86 virtual ULONG Release() OVERRIDE; | |
87 | |
88 // Forwarder to VideoCaptureDevice::Client::OnError(). | |
89 void SetErrorState(const std::string& reason); | |
90 | |
91 // Forwarder to VideoCaptureDevice::Client::OnLog(). | |
92 void LogMessage(const std::string& message); | |
93 | |
40 private: | 94 private: |
95 scoped_ptr<VideoCaptureDevice::Client> client_; | |
96 | |
97 // This is used to control the video capturing device input interface. | |
98 ScopedDeckLinkPtr<IDeckLinkInput> decklink_input_; | |
tommi (sloooow) - chröme
2014/09/05 09:24:20
is this a circular dependency to an object that al
mcasas
2014/09/09 11:05:00
Yes, should I turn it into a weak pointer?
| |
99 // |decklink_| represents a physical device attached to the host. | |
100 ScopedDeckLinkPtr<IDeckLink> decklink_; | |
101 | |
102 // Internal counter for IUnknown interface implementation. | |
103 int32_t ref_count_; | |
tommi (sloooow) - chröme
2014/09/05 09:24:20
see comment above - I think this should be in a se
mcasas
2014/09/09 11:05:00
Acknowledged.
| |
104 const Name device_name_; | |
105 | |
41 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceDeckLinkMac); | 106 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceDeckLinkMac); |
42 }; | 107 }; |
43 | 108 |
44 } // namespace media | 109 } // namespace media |
45 | 110 |
46 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_DECKLINK_MAC_H_ | 111 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_DECKLINK_MAC_H_ |
OLD | NEW |