Skip to content

Commit 2d71744

Browse files
committed
bmd_status improvements
- use BMD_CHECK to check HRESULT - check Unsubscribe ret val - if deckLink->QueryInterface(IID_IDeckLinkNotification, ..) fails, release deckLinkStatus - doxygen updates
1 parent d500197 commit 2d71744

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

src/blackmagic_common.cpp

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,7 +1413,9 @@ class BMDNotificationCallback : public IDeckLinkNotificationCallback
14131413

14141414
virtual ~BMDNotificationCallback()
14151415
{
1416-
m_deckLinkNotification->Unsubscribe(bmdStatusChanged, this);
1416+
BMD_CHECK(
1417+
m_deckLinkNotification->Unsubscribe(bmdStatusChanged, this),
1418+
"BMD device notification unsubscribe", BMD_NOOP);
14171419
m_deckLinkStatus->Release();
14181420
m_deckLinkNotification->Release();
14191421
}
@@ -1433,6 +1435,9 @@ class BMDNotificationCallback : public IDeckLinkNotificationCallback
14331435
* actually printed while the new value is set later and it can be observed by
14341436
* the notification observer.
14351437
*
1438+
* @returns a pointer representing the notification callback, must be passed to
1439+
* destroy with bmd_unsubscribe_notify()
1440+
*
14361441
* @todo
14371442
* Print some useful information also normally (non-IP devices).
14381443
*/
@@ -1451,20 +1456,17 @@ bmd_print_status_subscribe_notify(IDeckLink *deckLink, bool capture)
14511456
MSG(INFO, "Ethernet MAC address: %s\n",
14521457
mac_addr.c_str());
14531458
}
1454-
RELEASE_IF_NOT_NULL(deckLinkAttributes);
1459+
deckLinkAttributes->Release();
14551460
} else {
14561461
MSG(ERROR, "Cannot obtain IID_IDeckLinkProfileAttributes from "
14571462
"DeckLink!\n");
14581463
}
14591464

14601465
IDeckLinkStatus *deckLinkStatus = nullptr;
1461-
if (HRESULT result = deckLink->QueryInterface(
1462-
IID_IDeckLinkStatus, (void **) &deckLinkStatus);
1463-
FAILED(result)) {
1464-
MSG(ERROR,
1465-
"Cannot obtain IID_IDeckLinkStatus from DeckLink!\n");
1466-
return nullptr;
1467-
}
1466+
BMD_CHECK(deckLink->QueryInterface(IID_IDeckLinkStatus,
1467+
(void **) &deckLinkStatus),
1468+
"Cannot obtain IID_IDeckLinkStatus from DeckLink",
1469+
return nullptr);
14681470
// print status_map values now
14691471
for (unsigned u = 0; u < ARR_COUNT(status_map); ++u) {
14701472
if (capture && status_map[u].playback_only) {
@@ -1475,33 +1477,30 @@ bmd_print_status_subscribe_notify(IDeckLink *deckLink, bool capture)
14751477

14761478
// Obtain the notification interface
14771479
IDeckLinkNotification *deckLinkNotification = nullptr;
1478-
result = deckLink->QueryInterface(IID_IDeckLinkNotification,
1479-
(void **) &deckLinkNotification);
1480-
if (result != S_OK) {
1481-
MSG(ERROR,
1482-
"Could not obtain the IDeckLinkNotification interface - "
1483-
"result = %08x\n",
1484-
result);
1485-
return nullptr;
1486-
}
1480+
BMD_CHECK(deckLink->QueryInterface(IID_IDeckLinkNotification,
1481+
(void **) &deckLinkNotification),
1482+
"Could not obtain the IDeckLinkNotification interface",
1483+
deckLinkStatus->Release();
1484+
return nullptr);
14871485

14881486
auto *notificationCallback =
14891487
new BMDNotificationCallback(deckLinkStatus, deckLinkNotification);
14901488
assert(notificationCallback != nullptr);
14911489

1492-
result = deckLinkNotification->Subscribe(bmdStatusChanged,
1493-
notificationCallback);
1494-
if (result != S_OK) {
1495-
MSG(ERROR,
1496-
"Could not subscribe to the status change notification "
1497-
"- result = %08x\n",
1498-
result);
1499-
notificationCallback->Release();
1500-
return nullptr;
1501-
}
1490+
BMD_CHECK(deckLinkNotification->Subscribe(bmdStatusChanged,
1491+
notificationCallback),
1492+
"Could not subscribe to the status "
1493+
"change notification",
1494+
notificationCallback->Release();
1495+
return nullptr);
15021496

15031497
return notificationCallback;
15041498
}
1499+
1500+
/**
1501+
* @param notificationCallback the pointer returned by
1502+
* bmd_print_status_subscribe_notify(); may be nullptr
1503+
*/
15051504
void
15061505
bmd_unsubscribe_notify(BMDNotificationCallback *notificationCallback)
15071506
{

src/blackmagic_common.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ std::ostream &operator<<(std::ostream &output, REFIID iid);
162162
}\
163163
} while (0)
164164

165+
#define BMD_NOOP ///< can be passed to @ref BMD_CHECK
165166

166167
#define R10K_FULL_OPT "bmd-r10k-full-range"
167168
#define BMD_NAT_SORT "bmd-sort-natural"

0 commit comments

Comments
 (0)