Просмотр исходного кода

decklink: Use ComPtr for variables

This makes sure Decklink variables are automatically released.

Closes https://github.com/obsproject/obs-studio/pull/5508
cg2121 3 лет назад
Родитель
Сommit
efce0f41d0

+ 1 - 1
plugins/decklink/decklink-device-discovery.cpp

@@ -5,7 +5,7 @@
 
 DeckLinkDeviceDiscovery::DeckLinkDeviceDiscovery()
 {
-	discovery = CreateDeckLinkDiscoveryInstance();
+	discovery.Set(CreateDeckLinkDiscoveryInstance());
 	if (discovery == nullptr)
 		blog(LOG_INFO, "No blackmagic support");
 }

+ 9 - 16
plugins/decklink/decklink-device-instance.cpp

@@ -142,14 +142,14 @@ void DeckLinkDeviceInstance::HandleVideoFrame(
 	if (videoFrame == nullptr)
 		return;
 
-	IDeckLinkVideoFrameAncillaryPackets *packets;
+	ComPtr<IDeckLinkVideoFrameAncillaryPackets> packets;
 
 	if (videoFrame->QueryInterface(IID_IDeckLinkVideoFrameAncillaryPackets,
 				       (void **)&packets) == S_OK) {
-		IDeckLinkAncillaryPacketIterator *iterator;
+		ComPtr<IDeckLinkAncillaryPacketIterator> iterator;
 		packets->GetPacketIterator(&iterator);
 
-		IDeckLinkAncillaryPacket *packet;
+		ComPtr<IDeckLinkAncillaryPacket> packet;
 		iterator->Next(&packet);
 
 		if (packet) {
@@ -160,18 +160,13 @@ void DeckLinkDeviceInstance::HandleVideoFrame(
 			if (did == 0x61 && sdid == 0x01) {
 				this->HandleCaptionPacket(packet, timestamp);
 			}
-
-			packet->Release();
 		}
-
-		iterator->Release();
-		packets->Release();
 	}
 
-	IDeckLinkVideoFrame *frame;
+	ComPtr<IDeckLinkVideoFrame> frame;
 	if (videoFrame->GetPixelFormat() != convertFrame->GetPixelFormat()) {
-		IDeckLinkVideoConversion *frameConverter =
-			CreateVideoConversionInstance();
+		ComPtr<IDeckLinkVideoConversion> frameConverter;
+		frameConverter.Set(CreateVideoConversionInstance());
 
 		frameConverter->ConvertFrame(videoFrame, convertFrame);
 
@@ -373,7 +368,7 @@ bool DeckLinkDeviceInstance::StartCapture(DeckLinkDeviceMode *mode_,
 	if (!device->GetInput(&input))
 		return false;
 
-	IDeckLinkConfiguration *deckLinkConfiguration = NULL;
+	ComPtr<IDeckLinkConfiguration> deckLinkConfiguration;
 	HRESULT result = input->QueryInterface(IID_IDeckLinkConfiguration,
 					       (void **)&deckLinkConfiguration);
 	if (result != S_OK) {
@@ -526,7 +521,7 @@ bool DeckLinkDeviceInstance::StartOutput(DeckLinkDeviceMode *mode_)
 
 	int keyerMode = device->GetKeyerMode();
 
-	IDeckLinkKeyer *deckLinkKeyer = nullptr;
+	ComPtr<IDeckLinkKeyer> deckLinkKeyer;
 	if (device->GetKeyer(&deckLinkKeyer)) {
 		if (keyerMode) {
 			deckLinkKeyer->Enable(keyerMode == 1);
@@ -574,10 +569,8 @@ bool DeckLinkDeviceInstance::StopOutput()
 	output->DisableVideoOutput();
 	output->DisableAudioOutput();
 
-	if (decklinkOutputFrame != nullptr) {
-		decklinkOutputFrame->Release();
+	if (decklinkOutputFrame != nullptr)
 		decklinkOutputFrame = nullptr;
-	}
 
 	return true;
 }

+ 1 - 1
plugins/decklink/decklink-device-instance.hpp

@@ -38,7 +38,7 @@ protected:
 	bool allow10Bit;
 
 	OBSVideoFrame *convertFrame = nullptr;
-	IDeckLinkMutableVideoFrame *decklinkOutputFrame = nullptr;
+	ComPtr<IDeckLinkMutableVideoFrame> decklinkOutputFrame;
 
 	void FinalizeStream();
 	void SetupVideoFormat(DeckLinkDeviceMode *mode_);

+ 1 - 11
plugins/decklink/decklink-device-mode.cpp

@@ -18,11 +18,7 @@ DeckLinkDeviceMode::DeckLinkDeviceMode(const std::string &name, long long id)
 {
 }
 
-DeckLinkDeviceMode::~DeckLinkDeviceMode(void)
-{
-	if (mode != nullptr)
-		mode->Release();
-}
+DeckLinkDeviceMode::~DeckLinkDeviceMode(void) {}
 
 BMDDisplayMode DeckLinkDeviceMode::GetDisplayMode(void) const
 {
@@ -82,11 +78,5 @@ bool DeckLinkDeviceMode::IsEqualFrameRate(int64_t num, int64_t den)
 
 void DeckLinkDeviceMode::SetMode(IDeckLinkDisplayMode *mode_)
 {
-	IDeckLinkDisplayMode *old = mode;
-	if (old != nullptr)
-		old->Release();
-
 	mode = mode_;
-	if (mode != nullptr)
-		mode->AddRef();
 }

+ 1 - 1
plugins/decklink/decklink-device-mode.hpp

@@ -9,7 +9,7 @@
 class DeckLinkDeviceMode {
 protected:
 	long long id;
-	IDeckLinkDisplayMode *mode;
+	ComPtr<IDeckLinkDisplayMode> mode;
 	std::string name;
 
 public:

+ 4 - 10
plugins/decklink/decklink-device.cpp

@@ -49,9 +49,9 @@ bool DeckLinkDevice::Init()
 	ComPtr<IDeckLinkInput> input;
 	if (device->QueryInterface(IID_IDeckLinkInput, (void **)&input) ==
 	    S_OK) {
-		IDeckLinkDisplayModeIterator *modeIterator;
+		ComPtr<IDeckLinkDisplayModeIterator> modeIterator;
 		if (input->GetDisplayModeIterator(&modeIterator) == S_OK) {
-			IDeckLinkDisplayMode *displayMode;
+			ComPtr<IDeckLinkDisplayMode> displayMode;
 			long long modeId = 1;
 
 			while (modeIterator->Next(&displayMode) == S_OK) {
@@ -63,11 +63,8 @@ bool DeckLinkDevice::Init()
 							       modeId);
 				inputModes.push_back(mode);
 				inputModeIdMap[modeId] = mode;
-				displayMode->Release();
 				++modeId;
 			}
-
-			modeIterator->Release();
 		}
 	}
 
@@ -88,9 +85,9 @@ bool DeckLinkDevice::Init()
 	if (device->QueryInterface(IID_IDeckLinkOutput, (void **)&output) ==
 	    S_OK) {
 
-		IDeckLinkDisplayModeIterator *modeIterator;
+		ComPtr<IDeckLinkDisplayModeIterator> modeIterator;
 		if (output->GetDisplayModeIterator(&modeIterator) == S_OK) {
-			IDeckLinkDisplayMode *displayMode;
+			ComPtr<IDeckLinkDisplayMode> displayMode;
 			long long modeId = 1;
 
 			while (modeIterator->Next(&displayMode) == S_OK) {
@@ -102,11 +99,8 @@ bool DeckLinkDevice::Init()
 							       modeId);
 				outputModes.push_back(mode);
 				outputModeIdMap[modeId] = mode;
-				displayMode->Release();
 				++modeId;
 			}
-
-			modeIterator->Release();
 		}
 	}
 

+ 2 - 4
plugins/decklink/plugin-main.cpp

@@ -16,8 +16,8 @@ struct obs_output_info decklink_output_info;
 
 bool log_sdk_version()
 {
-	IDeckLinkIterator *deckLinkIterator;
-	IDeckLinkAPIInformation *deckLinkAPIInformation;
+	ComPtr<IDeckLinkIterator> deckLinkIterator;
+	ComPtr<IDeckLinkAPIInformation> deckLinkAPIInformation;
 	HRESULT result;
 
 	deckLinkIterator = CreateDeckLinkIteratorInstance();
@@ -42,8 +42,6 @@ bool log_sdk_version()
 
 		blog(LOG_INFO, "Decklink API Installed version %s",
 		     versionString.c_str());
-
-		deckLinkAPIInformation->Release();
 	}
 
 	return true;