]> git.sesse.net Git - vlc/commitdiff
Implement semi-proper AddRef and Release.
authorSteinar Gunderson <sgunderson@bigfoot.com>
Sat, 25 Sep 2010 17:33:44 +0000 (19:33 +0200)
committerSteinar Gunderson <sgunderson@bigfoot.com>
Sat, 25 Sep 2010 17:33:44 +0000 (19:33 +0200)
modules/access/sdi.cpp

index 84b3b4dad46614e86ef64071a3d7bf353c696146..aae8cb6c27a10eaead26a64e278ebc1cadf2530e 100644 (file)
@@ -125,17 +125,32 @@ struct demux_sys_t
 class DeckLinkCaptureDelegate : public IDeckLinkInputCallback
 {
 public:
-    DeckLinkCaptureDelegate( demux_t *p_demux ) : p_demux_(p_demux) {}
+    DeckLinkCaptureDelegate( demux_t *p_demux ) : m_ref_(1), p_demux_(p_demux) {}
 
-    // FIXME: These leak.
     virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv) { return E_NOINTERFACE; }
-    virtual ULONG STDMETHODCALLTYPE AddRef(void) { return 1; }
-    virtual ULONG STDMETHODCALLTYPE Release(void) { return 1; }
+
+    // Note: AddRef() and Release() here are not thread safe.
+
+    virtual ULONG STDMETHODCALLTYPE AddRef(void)
+    {
+        return ++m_ref_;
+    }
+
+    virtual ULONG STDMETHODCALLTYPE Release(void)
+    {
+        if ( --m_ref_ == 0 )
+        {
+            delete this;
+            return 0;
+        }
+        return m_ref_;
+    }
 
     virtual HRESULT STDMETHODCALLTYPE VideoInputFormatChanged(BMDVideoInputFormatChangedEvents, IDeckLinkDisplayMode*, BMDDetectedVideoInputFormatFlags);
     virtual HRESULT STDMETHODCALLTYPE VideoInputFrameArrived(IDeckLinkVideoInputFrame*, IDeckLinkAudioInputPacket*);
 
 private:
+    int m_ref_;
     demux_t *p_demux_;
 };
 
@@ -592,7 +607,9 @@ static void Close( vlc_object_t *p_this )
     if( p_sys->p_card )
         p_sys->p_card->Release();
 
-    delete p_sys->p_delegate;
+    if( p_sys->p_delegate )
+        p_sys->p_delegate->Release();
+
     free( p_sys );
 }