]> git.sesse.net Git - vlc/blobdiff - modules/access/decklink.cpp
Add a check for i_card_index < 0.
[vlc] / modules / access / decklink.cpp
index 1afee5450c794d3e292fedfaa2fdfdb00d717da8..631dc76dae9defa4daf02b836d8d8b62fdc6a567 100644 (file)
@@ -9,12 +9,12 @@
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
@@ -159,7 +159,12 @@ public:
         return new_ref;
     }
 
-    virtual HRESULT STDMETHODCALLTYPE VideoInputFormatChanged(BMDVideoInputFormatChangedEvents, IDeckLinkDisplayMode*, BMDDetectedVideoInputFormatFlags);
+    virtual HRESULT STDMETHODCALLTYPE VideoInputFormatChanged(BMDVideoInputFormatChangedEvents, IDeckLinkDisplayMode*, BMDDetectedVideoInputFormatFlags)
+    {
+        msg_Dbg( p_demux_, "Video input format changed" );
+        return S_OK;
+    }
+
     virtual HRESULT STDMETHODCALLTYPE VideoInputFrameArrived(IDeckLinkVideoInputFrame*, IDeckLinkAudioInputPacket*);
 
 private:
@@ -167,12 +172,6 @@ private:
     demux_t *p_demux_;
 };
 
-HRESULT DeckLinkCaptureDelegate::VideoInputFormatChanged(BMDVideoInputFormatChangedEvents events, IDeckLinkDisplayMode *mode, BMDDetectedVideoInputFormatFlags)
-{
-    msg_Dbg( p_demux_, "Video input format changed" );
-    return S_OK;
-}
-
 HRESULT DeckLinkCaptureDelegate::VideoInputFrameArrived(IDeckLinkVideoInputFrame* videoFrame, IDeckLinkAudioInputPacket* audioFrame)
 {
     demux_sys_t *p_sys = p_demux_->p_sys;
@@ -204,18 +203,13 @@ HRESULT DeckLinkCaptureDelegate::VideoInputFrameArrived(IDeckLinkVideoInputFrame
         for( int y = 0; y < i_height; ++y )
         {
             const uint8_t *src = (const uint8_t *)frame_bytes + i_stride * y;
-            uint8_t *dst = (uint8_t *)p_video_frame->p_buffer + i_width * i_bpp * y;
+            uint8_t *dst = p_video_frame->p_buffer + i_width * i_bpp * y;
             memcpy( dst, src, i_width * i_bpp );
         }
 
         BMDTimeValue stream_time, frame_duration;
         videoFrame->GetStreamTime( &stream_time, &frame_duration, CLOCK_FREQ );
         p_video_frame->i_flags = BLOCK_FLAG_TYPE_I | p_sys->i_dominance_flags;
-        if( p_sys->b_first_frame )
-        {
-            p_video_frame->i_flags |= BLOCK_FLAG_DISCONTINUITY;
-            p_sys->b_first_frame = false;
-        }
         p_video_frame->i_pts = p_video_frame->i_dts = VLC_TS_0 + stream_time;
     }
 
@@ -267,7 +261,7 @@ static int Open( vlc_object_t *p_this )
 {
     demux_t     *p_demux = (demux_t*)p_this;
     demux_sys_t *p_sys;
-    int         ret = VLC_SUCCESS;
+    int         ret = VLC_EGENERIC;
     char        *psz_aspect;
     char        *psz_display_mode = NULL;
     char        *psz_video_connection = NULL;
@@ -299,13 +293,18 @@ static int Open( vlc_object_t *p_this )
     if( !decklink_iterator )
     {
         msg_Err( p_demux, "DeckLink drivers not found." );
-        ret = VLC_EGENERIC;
         goto finish;
     }
 
     HRESULT result;
 
     i_card_index = var_InheritInteger( p_demux, "decklink-card-index" );
+    if( i_card_index < 0 )
+    {
+        msg_Err( p_demux, "Invalid card index %d", i_card_index );
+        goto finish;
+    }
+
     for( int i = 0; i <= i_card_index; ++i )
     {
         if( p_sys->p_card )
@@ -318,7 +317,6 @@ static int Open( vlc_object_t *p_this )
     if( result != S_OK )
     {
         msg_Err( p_demux, "DeckLink PCI card %d not found", i_card_index );
-        ret = VLC_EGENERIC;
         goto finish;
     }
 
@@ -328,7 +326,6 @@ static int Open( vlc_object_t *p_this )
     if( result != S_OK )
     {
         msg_Err( p_demux, "Could not get model name" );
-        ret = VLC_EGENERIC;
         goto finish;
     }
 
@@ -337,7 +334,6 @@ static int Open( vlc_object_t *p_this )
     if( p_sys->p_card->QueryInterface( IID_IDeckLinkInput, (void**)&p_sys->p_input) != S_OK )
     {
         msg_Err( p_demux, "Card has no inputs" );
-        ret = VLC_EGENERIC;
         goto finish;
     }
 
@@ -346,7 +342,6 @@ static int Open( vlc_object_t *p_this )
     if( p_sys->p_card->QueryInterface( IID_IDeckLinkConfiguration, (void**)&p_config) != S_OK )
     {
         msg_Err( p_demux, "Failed to get configuration interface" );
-        ret = VLC_EGENERIC;
         goto finish;
     }
 
@@ -370,7 +365,6 @@ static int Open( vlc_object_t *p_this )
         {
             msg_Err( p_demux, "Invalid --decklink-video-connection specified; choose one of " \
                               "sdi, hdmi, opticalsdi, component, composite, or svideo." );
-            ret = VLC_EGENERIC;
             goto finish;
         }
 
@@ -379,7 +373,6 @@ static int Open( vlc_object_t *p_this )
         if( result != S_OK )
         {
             msg_Err( p_demux, "Failed to set video input connection" );
-            ret = VLC_EGENERIC;
             goto finish;
         }
     }
@@ -398,7 +391,6 @@ static int Open( vlc_object_t *p_this )
         {
             msg_Err( p_demux, "Invalid --decklink-audio-connection specified; choose one of " \
                               "embedded, aesebu, or analog." );
-            ret = VLC_EGENERIC;
             goto finish;
         }
 
@@ -407,7 +399,6 @@ static int Open( vlc_object_t *p_this )
         if( result != S_OK )
         {
             msg_Err( p_demux, "Failed to set audio input connection" );
-            ret = VLC_EGENERIC;
             goto finish;
         }
     }
@@ -418,14 +409,12 @@ static int Open( vlc_object_t *p_this )
     if( result != S_OK )
     {
         msg_Err( p_demux, "Failed to enumerate display modes" );
-        ret = VLC_EGENERIC;
         goto finish;
     }
 
     psz_display_mode = var_InheritString( p_demux, "decklink-mode" );
     if( !psz_display_mode || strlen( psz_display_mode ) == 0 || strlen( psz_display_mode ) > 4 ) {
         msg_Err( p_demux, "Missing or invalid --decklink-mode string" );
-        ret = VLC_EGENERIC;
         goto finish;
     }
 
@@ -460,7 +449,6 @@ static int Open( vlc_object_t *p_this )
         {
             msg_Err( p_demux, "Failed to get display mode name" );
             p_display_mode->Release();
-            ret = VLC_EGENERIC;
             goto finish;
         }
 
@@ -470,7 +458,6 @@ static int Open( vlc_object_t *p_this )
         {
             msg_Err( p_demux, "Failed to get frame rate" );
             p_display_mode->Release();
-            ret = VLC_EGENERIC;
             goto finish;
         }
 
@@ -521,7 +508,6 @@ static int Open( vlc_object_t *p_this )
         msg_Err( p_demux, "Unknown video mode specified. " \
                           "Run VLC with -v --verbose-objects=-all,+decklink " \
                           "to get a list of supported modes." );
-        ret = VLC_EGENERIC;
         goto finish;
     }
 
@@ -529,7 +515,6 @@ static int Open( vlc_object_t *p_this )
     if( result != S_OK )
     {
         msg_Err( p_demux, "Failed to enable video input" );
-        ret = VLC_EGENERIC;
         goto finish;
     }
 
@@ -542,7 +527,6 @@ static int Open( vlc_object_t *p_this )
         if( result != S_OK )
         {
             msg_Err( p_demux, "Failed to enable audio input" );
-            ret = VLC_EGENERIC;
             goto finish;
         }
     }
@@ -555,7 +539,6 @@ static int Open( vlc_object_t *p_this )
     {
         msg_Err( p_demux, "Could not start streaming from SDI card. This could be caused "
                           "by invalid video mode or flags, access denied, or card already in use." );
-        ret = VLC_EGENERIC;
         goto finish;
     }
 
@@ -602,6 +585,8 @@ static int Open( vlc_object_t *p_this )
     /* Update default_pts to a suitable value for access */
     var_Create( p_demux, "decklink-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
 
+    ret = VLC_SUCCESS;
+
 finish:
     if( decklink_iterator )
         decklink_iterator->Release();