]> git.sesse.net Git - vlc/blobdiff - modules/access/sdi.cpp
Use C comments consistently.
[vlc] / modules / access / sdi.cpp
index 84b3b4dad46614e86ef64071a3d7bf353c696146..61bb92ac8540dd2f93469c63b5e6876dca27ba2f 100644 (file)
@@ -117,25 +117,40 @@ struct demux_sys_t
     int i_rate, i_channels;
 
     vlc_mutex_t frame_lock;
-    block_t *p_video_frame;  // protected by <frame_lock>
-    block_t *p_audio_frame;  // protected by <frame_lock>
-    vlc_cond_t has_frame;  // related to <frame_lock>
+    block_t *p_video_frame;  /* protected by <frame_lock> */
+    block_t *p_audio_frame;  /* protected by <frame_lock> */
+    vlc_cond_t has_frame;  /* related to <frame_lock> */
 };
 
 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_;
 };
 
@@ -303,7 +318,7 @@ static int Open( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
    
-    // Set up the video and audio sources. 
+    /* Set up the video and audio sources. */
     IDeckLinkConfiguration *p_config;
     if( p_sys->p_card->QueryInterface( IID_IDeckLinkConfiguration, (void**)&p_config) != S_OK )
     {
@@ -382,7 +397,7 @@ static int Open( vlc_object_t *p_this )
 
     p_config->Release();
 
-    // Get the list of display modes.
+    /* Get the list of display modes. */
     IDeckLinkDisplayModeIterator *p_display_iterator;
     result = p_sys->p_input->GetDisplayModeIterator( &p_display_iterator );
     if( result != S_OK )
@@ -401,8 +416,10 @@ static int Open( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
 
-    // Pad the --sdi-mode string to four characters, so the user can specify e.g. "pal"
-    // without having to add the trailing space.
+    /*
+     * Pad the --sdi-mode string to four characters, so the user can specify e.g. "pal"
+     * without having to add the trailing space.
+     */
     char sz_display_mode_padded[5];
     strcpy(sz_display_mode_padded, "    ");
     for( int i = 0; i < strlen( psz_display_mode ); ++i )
@@ -505,7 +522,7 @@ static int Open( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
   
-    // Set up audio. 
+    /* Set up audio. */
     p_sys->i_rate = var_CreateGetInteger( p_demux, "sdi-audio-rate" );
     p_sys->i_channels = var_CreateGetInteger( p_demux, "sdi-audio-channels" );
     if( p_sys->i_rate > 0 && p_sys->i_channels > 0 )
@@ -592,7 +609,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 );
 }
 
@@ -618,7 +637,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
 
         case DEMUX_GET_TIME:
             pi64 = (int64_t*)va_arg( args, int64_t * );
-            *pi64 = mdate();  // FIXME
+            *pi64 = mdate();  /* FIXME */
             return VLC_SUCCESS;
 
         /* TODO implement others */