]> git.sesse.net Git - vlc/blobdiff - modules/access/decklink.cpp
Use var_InheritString for --decklink-video-connection.
[vlc] / modules / access / decklink.cpp
index 3aaf8ef0641e80effcf73d84ea6cb40cee0801c9..a8f3a71dc12b3bb6627135c629385e5fa10af9bf 100644 (file)
@@ -79,6 +79,13 @@ static void Close( vlc_object_t * );
     "composite, svideo. " \
     "Leave blank for card default." )
 
+static const char *const ppsz_videoconns[] = {
+    "sdi", "hdmi", "opticalsdi", "component", "composite", "svideo"
+};
+static const char *const ppsz_videoconns_text[] = {
+    N_("SDI"), N_("HDMI"), N_("Optical SDI"), N_("Component"), N_("Composite"), N_("S-video")
+};
+        
 #define ASPECT_RATIO_TEXT N_("Aspect ratio")
 #define ASPECT_RATIO_LONGTEXT N_( \
     "Aspect ratio (4:3, 16:9). Default assumes square pixels." )
@@ -103,6 +110,7 @@ vlc_module_begin ()
                  CHANNELS_TEXT, CHANNELS_LONGTEXT, true )
     add_string( "decklink-video-connection", 0, NULL,
                  VIDEO_CONNECTION_TEXT, VIDEO_CONNECTION_LONGTEXT, true )
+        change_string_list( ppsz_videoconns, ppsz_videoconns_text, 0 )
     add_string( "decklink-aspect-ratio", NULL, NULL,
                 ASPECT_RATIO_TEXT, ASPECT_RATIO_LONGTEXT, true )
 
@@ -203,18 +211,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;
     }
 
@@ -266,7 +269,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;
@@ -275,6 +278,7 @@ static int Open( vlc_object_t *p_this )
     int         i_card_index;
     int         i_width, i_height, i_fps_num, i_fps_den;
     int         i_rate;
+    unsigned    u_aspect_num, u_aspect_den;
 
     /* Only when selected */
     if( *p_demux->psz_access == '\0' )
@@ -298,13 +302,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 )
@@ -317,7 +326,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;
     }
 
@@ -327,7 +335,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;
     }
 
@@ -336,7 +343,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;
     }
 
@@ -345,11 +351,10 @@ 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;
     }
 
-    psz_video_connection = var_CreateGetNonEmptyString( p_demux, "decklink-video-connection" );
+    psz_video_connection = var_InheritString( p_demux, "decklink-video-connection" );
     if( psz_video_connection )
     {
         BMDVideoConnection conn;
@@ -369,7 +374,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;
         }
 
@@ -378,7 +382,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;
         }
     }
@@ -397,7 +400,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;
         }
 
@@ -406,7 +408,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;
         }
     }
@@ -417,14 +418,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 ) {
+    psz_display_mode = var_CreateGetNonEmptyString( p_demux, "decklink-mode" );
+    if( !psz_display_mode || strlen( psz_display_mode ) > 4 ) {
         msg_Err( p_demux, "Missing or invalid --decklink-mode string" );
-        ret = VLC_EGENERIC;
         goto finish;
     }
 
@@ -459,7 +458,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;
         }
 
@@ -469,7 +467,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;
         }
 
@@ -520,7 +517,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;
     }
 
@@ -528,7 +524,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;
     }
 
@@ -541,7 +536,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;
         }
     }
@@ -554,7 +548,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;
     }
 
@@ -569,17 +562,10 @@ static int Open( vlc_object_t *p_this )
     video_fmt.video.i_frame_rate_base = i_fps_den;
     video_fmt.i_bitrate = video_fmt.video.i_width * video_fmt.video.i_height * video_fmt.video.i_frame_rate * 2 * 8;
 
-    psz_aspect = var_CreateGetNonEmptyString( p_demux, "decklink-aspect-ratio" );
-    if( psz_aspect )
-    {
-        char *psz_denominator = strchr( psz_aspect, ':' );
-        if( psz_denominator )
-        {
-            *psz_denominator++ = '\0';
-            video_fmt.video.i_sar_num = atoi( psz_aspect )      * video_fmt.video.i_height;
-            video_fmt.video.i_sar_den = atoi( psz_denominator ) * video_fmt.video.i_width;
-        }
-        free( psz_aspect );
+    if ( !var_InheritURational( p_demux, &u_aspect_num, &u_aspect_den, "decklink-aspect-ratio" ) &&
+         u_aspect_num > 0 && u_aspect_den > 0 ) {
+        video_fmt.video.i_sar_num = u_aspect_num * video_fmt.video.i_height;
+        video_fmt.video.i_sar_den = u_aspect_den * video_fmt.video.i_width;
     }
 
     msg_Dbg( p_demux, "added new video es %4.4s %dx%d",
@@ -598,8 +584,7 @@ static int Open( vlc_object_t *p_this )
              (char*)&audio_fmt.i_codec, audio_fmt.audio.i_rate, audio_fmt.audio.i_bitspersample, audio_fmt.audio.i_channels);
     p_sys->p_audio_es = es_out_Add( p_demux->out, &audio_fmt );
 
-    /* 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 )
@@ -665,7 +650,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
 
         case DEMUX_GET_PTS_DELAY:
             pi64 = (int64_t*)va_arg( args, int64_t * );
-            *pi64 = var_GetInteger( p_demux, "decklink-caching" ) * 1000;
+            *pi64 = var_InheritInteger( p_demux, "decklink-caching" ) * 1000;
             return VLC_SUCCESS;
 
         case DEMUX_GET_TIME: