Skip to content

Commit d500197

Browse files
committed
bmd: keep notification interface in BMDNotificationCallback
I am not entierly sure if releasing IDeckLinkNotification in register fuction actually doesn't cleanup the state. It seems it does not but just to be sure.
1 parent 7395ad7 commit d500197

File tree

4 files changed

+31
-37
lines changed

4 files changed

+31
-37
lines changed

src/blackmagic_common.cpp

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,11 +1355,14 @@ print_status_item(IDeckLinkStatus *deckLinkStatus, BMDDeckLinkStatusID prop)
13551355
}
13561356

13571357
// from BMD SDK sample StatusMonitor.cpp
1358-
class NotificationCallback : public IDeckLinkNotificationCallback
1358+
class BMDNotificationCallback : public IDeckLinkNotificationCallback
13591359
{
13601360
public:
1361-
explicit NotificationCallback(IDeckLinkStatus *deckLinkStatus)
1362-
: m_deckLinkStatus(deckLinkStatus), m_refCount(1)
1361+
explicit BMDNotificationCallback(
1362+
IDeckLinkStatus *deckLinkStatus,
1363+
IDeckLinkNotification *deckLinkNotification)
1364+
: m_deckLinkStatus(deckLinkStatus),
1365+
m_deckLinkNotification(deckLinkNotification), m_refCount(1)
13631366

13641367
{
13651368
m_deckLinkStatus->AddRef();
@@ -1404,10 +1407,18 @@ class NotificationCallback : public IDeckLinkNotificationCallback
14041407
}
14051408

14061409
private:
1407-
IDeckLinkStatus *m_deckLinkStatus;
1408-
std::atomic<ULONG> m_refCount;
1410+
IDeckLinkStatus *m_deckLinkStatus;
1411+
IDeckLinkNotification *m_deckLinkNotification;
1412+
std::atomic<ULONG> m_refCount;
14091413

1410-
virtual ~NotificationCallback() { m_deckLinkStatus->Release(); }
1414+
virtual ~BMDNotificationCallback()
1415+
{
1416+
m_deckLinkNotification->Unsubscribe(bmdStatusChanged, this);
1417+
m_deckLinkStatus->Release();
1418+
m_deckLinkNotification->Release();
1419+
}
1420+
1421+
public:
14111422
};
14121423

14131424
/**
@@ -1425,7 +1436,7 @@ class NotificationCallback : public IDeckLinkNotificationCallback
14251436
* @todo
14261437
* Print some useful information also normally (non-IP devices).
14271438
*/
1428-
IDeckLinkNotificationCallback *
1439+
BMDNotificationCallback *
14291440
bmd_print_status_subscribe_notify(IDeckLink *deckLink, bool capture)
14301441
{
14311442
IDeckLinkProfileAttributes *deckLinkAttributes = nullptr;
@@ -1474,8 +1485,9 @@ bmd_print_status_subscribe_notify(IDeckLink *deckLink, bool capture)
14741485
return nullptr;
14751486
}
14761487

1477-
auto *notificationCallback = new NotificationCallback(deckLinkStatus);
1478-
assert(notificationCallback!= nullptr);
1488+
auto *notificationCallback =
1489+
new BMDNotificationCallback(deckLinkStatus, deckLinkNotification);
1490+
assert(notificationCallback != nullptr);
14791491

14801492
result = deckLinkNotification->Subscribe(bmdStatusChanged,
14811493
notificationCallback);
@@ -1488,32 +1500,16 @@ bmd_print_status_subscribe_notify(IDeckLink *deckLink, bool capture)
14881500
return nullptr;
14891501
}
14901502

1491-
deckLinkNotification->Release();;
1492-
14931503
return notificationCallback;
14941504
}
14951505
void
1496-
bmd_unsubscribe_notify(IDeckLink *deckLink,
1497-
IDeckLinkNotificationCallback *notificationCallback) {
1506+
bmd_unsubscribe_notify(BMDNotificationCallback *notificationCallback)
1507+
{
14981508
if (notificationCallback == nullptr) {
14991509
return;
15001510
}
15011511

1502-
// Obtain the notification interface
1503-
IDeckLinkNotification *deckLinkNotification = nullptr;
1504-
HRESULT result = deckLink->QueryInterface(IID_IDeckLinkNotification,
1505-
(void **) &deckLinkNotification);
1506-
if (result != S_OK) {
1507-
MSG(ERROR,
1508-
"Could not obtain the IDeckLinkNotification interface - "
1509-
"result = %08x; cannot unsubscribe\n",
1510-
result);
1511-
return;
1512-
}
1513-
deckLinkNotification->Unsubscribe(bmdStatusChanged,
1514-
notificationCallback);
15151512
notificationCallback->Release();
1516-
deckLinkNotification->Release();
15171513
}
15181514

15191515
ADD_TO_PARAM(R10K_FULL_OPT, "* " R10K_FULL_OPT "\n"

src/blackmagic_common.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,10 @@ using bmd_dev = std::tuple<std::unique_ptr<IDeckLink, void (*)(IDeckLink *)>,
190190
std::vector<bmd_dev> bmd_get_sorted_devices(bool *com_initialized,
191191
bool verbose = true,
192192
bool natural_sort = false);
193-
IDeckLinkNotificationCallback *
194-
bmd_print_status_subscribe_notify(IDeckLink *deckLink, bool capture);
195-
void
196-
bmd_unsubscribe_notify(IDeckLink *deckLink,
197-
IDeckLinkNotificationCallback *notificationCallback);
193+
class BMDNotificationCallback;
194+
BMDNotificationCallback *bmd_print_status_subscribe_notify(IDeckLink *deckLink,
195+
bool capture);
196+
void bmd_unsubscribe_notify(BMDNotificationCallback *notificationCallback);
198197

199198
#endif // defined BLACKMAGIC_COMMON_HPP
200199

src/video_capture/decklink.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ struct device_state {
173173
unique_ptr<VideoDelegate> delegate;
174174
IDeckLinkProfileAttributes *deckLinkAttributes = nullptr;
175175
IDeckLinkConfiguration *deckLinkConfiguration = nullptr;
176-
IDeckLinkNotificationCallback *notificationCallback = nullptr;
176+
BMDNotificationCallback *notificationCallback = nullptr;
177177
string device_id = "0"; // either numeric value or device name
178178
bool audio = false; /* wheather we process audio or not */
179179
struct tile *tile = nullptr;
@@ -1519,8 +1519,7 @@ static void cleanup_common(struct vidcap_decklink_state *s) {
15191519
}
15201520

15211521
for (int i = 0; i < s->devices_cnt; ++i) {
1522-
bmd_unsubscribe_notify(s->state[i].deckLink,
1523-
s->state[i].notificationCallback);
1522+
bmd_unsubscribe_notify(s->state[i].notificationCallback);
15241523
RELEASE_IF_NOT_NULL(s->state[i].deckLinkConfiguration);
15251524
RELEASE_IF_NOT_NULL(s->state[i].deckLinkAttributes);
15261525
RELEASE_IF_NOT_NULL(s->state[i].deckLinkInput);

src/video_display/decklink.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ struct state_decklink {
508508
IDeckLinkOutput *deckLinkOutput;
509509
IDeckLinkConfiguration *deckLinkConfiguration;
510510
IDeckLinkProfileAttributes *deckLinkAttributes;
511-
IDeckLinkNotificationCallback *notificationCallback = nullptr;
511+
BMDNotificationCallback *notificationCallback = nullptr;
512512

513513
DeckLinkTimecode *timecode{}; ///< @todo Should be actually allocated dynamically and
514514
///< its lifespan controlled by AddRef()/Release() methods
@@ -1604,7 +1604,7 @@ static void display_decklink_done(void *state)
16041604
"DisableVideoOutput");
16051605
}
16061606

1607-
bmd_unsubscribe_notify(s->deckLink, s->notificationCallback);
1607+
bmd_unsubscribe_notify(s->notificationCallback);
16081608
RELEASE_IF_NOT_NULL(s->deckLinkAttributes);
16091609
RELEASE_IF_NOT_NULL(s->deckLinkConfiguration);
16101610
RELEASE_IF_NOT_NULL(s->deckLinkOutput);

0 commit comments

Comments
 (0)