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_; |
| 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 // Gets the supported formats of a particular device attached to the system, | 58 // Gets the supported formats of a particular device attached to the system, |
25 // identified by |device|. Formats are retrieved from the DeckLink SDK. | 59 // identified by |device|. Formats are retrieved from the DeckLink SDK. |
26 static void EnumerateDeviceCapabilities( | 60 static void EnumerateDeviceCapabilities( |
27 const VideoCaptureDevice::Name& device, | 61 const VideoCaptureDevice::Name& device, |
28 VideoCaptureFormats* supported_formats); | 62 VideoCaptureFormats* supported_formats); |
29 | 63 |
30 explicit VideoCaptureDeviceDeckLinkMac(const Name& device_name); | 64 explicit VideoCaptureDeviceDeckLinkMac(const Name& device_name); |
31 virtual ~VideoCaptureDeviceDeckLinkMac(); | 65 virtual ~VideoCaptureDeviceDeckLinkMac(); |
32 | 66 |
33 // VideoCaptureDevice implementation. | 67 // VideoCaptureDevice implementation. |
34 virtual void AllocateAndStart( | 68 virtual void AllocateAndStart( |
35 const VideoCaptureParams& params, | 69 const VideoCaptureParams& params, |
36 scoped_ptr<VideoCaptureDevice::Client> client) OVERRIDE; | 70 scoped_ptr<VideoCaptureDevice::Client> client) OVERRIDE; |
37 virtual void StopAndDeAllocate() OVERRIDE; | 71 virtual void StopAndDeAllocate() OVERRIDE; |
38 | 72 |
| 73 // IDeckLinkInputCallback interface implementation. |
| 74 virtual HRESULT VideoInputFormatChanged ( |
| 75 BMDVideoInputFormatChangedEvents notification_events, |
| 76 IDeckLinkDisplayMode *new_display_mode, |
| 77 BMDDetectedVideoInputFormatFlags detected_signal_flags) OVERRIDE; |
| 78 virtual HRESULT VideoInputFrameArrived ( |
| 79 IDeckLinkVideoInputFrame* video_frame, |
| 80 IDeckLinkAudioInputPacket* audio_packet) OVERRIDE; |
| 81 |
| 82 // IUnknown interface implementation. |
| 83 virtual HRESULT QueryInterface (REFIID iid, LPVOID *ppv) OVERRIDE; |
| 84 virtual ULONG AddRef() OVERRIDE; |
| 85 virtual ULONG Release() OVERRIDE; |
| 86 |
| 87 // Forwarder to VideoCaptureDevice::Client::OnError(). |
| 88 void SetErrorState(const std::string& reason); |
| 89 |
| 90 // Forwarder to VideoCaptureDevice::Client::OnLog(). |
| 91 void LogMessage(const std::string& message); |
| 92 |
39 private: | 93 private: |
| 94 scoped_ptr<VideoCaptureDevice::Client> client_; |
| 95 |
| 96 // This is used to control the video capturing device input interface. |
| 97 ScopedDeckLinkPtr<IDeckLinkInput> decklink_input_; |
| 98 // |decklink_| represents a physical device attached to the host. |
| 99 ScopedDeckLinkPtr<IDeckLink> decklink_; |
| 100 |
| 101 // Internal counter for IUnknown interface implementation. |
| 102 int32_t ref_count_; |
| 103 const Name device_name_; |
| 104 |
40 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceDeckLinkMac); | 105 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceDeckLinkMac); |
41 }; | 106 }; |
42 | 107 |
43 } // namespace media | 108 } // namespace media |
44 | 109 |
45 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_DECKLINK_MAC_H_ | 110 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_DECKLINK_MAC_H_ |
OLD | NEW |