]> git.sesse.net Git - vlc/commitdiff
Enable SDI video mode selection on the command line.
authorSteinar Gunderson <sgunderson@bigfoot.com>
Fri, 24 Sep 2010 21:18:31 +0000 (23:18 +0200)
committerSteinar Gunderson <sgunderson@bigfoot.com>
Fri, 24 Sep 2010 21:18:31 +0000 (23:18 +0200)
modules/access/sdi.cpp

index 691cd1f35f9409a86478293204e399f781949cf4..266937451e7c5304b4ba062d0de672f47fcfe468 100644 (file)
 static int  Open ( vlc_object_t * );
 static void Close( vlc_object_t * );
 
+#define MODE_TEXT N_("Desired input video mode")
+#define MODE_LONGTEXT N_( \
+    "Desired input video mode for SDI captures. " \
+    "This value should be a FOURCC code in textual " \
+    "form, e.g. \"ntsc\"." )
+
 #define CACHING_TEXT N_("Caching value in ms")
 #define CACHING_LONGTEXT N_( \
     "Caching value for SDI captures. This " \
@@ -35,7 +41,9 @@ vlc_module_begin ()
     set_description( N_("BlackMagic SDI input") )
     set_category( CAT_INPUT )
     set_subcategory( SUBCAT_INPUT_ACCESS )
-
+    
+    add_string( "sdi-mode", "pal ", NULL,
+                 MODE_TEXT, MODE_LONGTEXT, true )
     add_integer( "sdi-caching", DEFAULT_PTS_DELAY / 1000, NULL,
                  CACHING_TEXT, CACHING_LONGTEXT, true )
 
@@ -54,10 +62,14 @@ struct demux_sys_t
     IDeckLink *p_card;
     IDeckLinkInput *p_input;
     DeckLinkCaptureDelegate *p_delegate;
+
     es_out_id_t *p_video_es;
     es_out_id_t *p_audio_es;
     bool b_first_frame;
 
+    int i_width, i_height, i_fps_num, i_fps_den;
+    // FIXME: field dominance
+
     vlc_mutex_t frame_lock;
     block_t *p_video_frame;  // protected by <frame_lock>
     block_t *p_audio_frame;  // protected by <frame_lock>
@@ -213,13 +225,6 @@ static int Open( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
 
-    result = p_sys->p_input->EnableVideoInput( bmdModePAL, bmdFormat8BitYUV, 0 );
-    if( result != S_OK )
-    {
-        msg_Err( p_demux, "Failed to enable video input" );
-        return VLC_EGENERIC;
-    }
-        
     IDeckLinkDisplayModeIterator *p_display_iterator;
     result = p_sys->p_input->GetDisplayModeIterator( &p_display_iterator );
     if( result != S_OK )
@@ -227,6 +232,24 @@ static int Open( vlc_object_t *p_this )
         msg_Err( p_demux, "Failed to enumerate display modes" );
         return VLC_EGENERIC;
     }
+    
+    char *mode_string = var_CreateGetString( p_demux, "sdi-mode" );
+    if( !mode_string || strlen( mode_string ) == 0 || strlen( mode_string ) > 4 ) {
+        msg_Err( p_demux, "Missing or invalid --sdi-mode string" );
+        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.
+    char mode_string_padded[5];
+    strcpy(mode_string_padded, "    ");
+    for( int i = 0; i < strlen(mode_string); ++i )
+        mode_string_padded[i] = mode_string[i];
+
+    BMDDisplayMode wanted_mode_id;
+    memcpy( &wanted_mode_id, &mode_string_padded, sizeof(wanted_mode_id) );
+    
+    bool b_found_mode = false;
 
     for (;;)
     {
@@ -284,6 +307,30 @@ static int Open( vlc_object_t *p_this )
                  p_display_mode->GetWidth(), p_display_mode->GetHeight(),
                  double(time_scale) / frame_duration, field_dominance );
         msg_Dbg( p_demux, buf );
+
+        if( wanted_mode_id == mode_id )
+        {
+            b_found_mode = true;
+            p_sys->i_width = p_display_mode->GetWidth();
+            p_sys->i_height = p_display_mode->GetHeight();
+            p_sys->i_fps_num = time_scale;
+            p_sys->i_fps_den = frame_duration;
+        }
+    }
+
+    if( !b_found_mode )
+    {
+        msg_Err( p_demux, "Unknown SDI mode specified. " \
+                          "Run VLC with -v --verbose-objects=-all,+sdi " \
+                          "to get a list of supported modes." );
+        return VLC_EGENERIC;
+    }
+
+    result = p_sys->p_input->EnableVideoInput( htonl( wanted_mode_id ), bmdFormat8BitYUV, 0 );
+    if( result != S_OK )
+    {
+        msg_Err( p_demux, "Failed to enable video input" );
+        return VLC_EGENERIC;
     }
    
     result = p_sys->p_input->EnableAudioInput( 48000, bmdAudioSampleType16bitInteger, 2 );
@@ -306,12 +353,12 @@ static int Open( vlc_object_t *p_this )
     /* Declare elementary streams */
     es_format_t video_fmt;
     es_format_Init( &video_fmt, VIDEO_ES, VLC_CODEC_UYVY );
-    video_fmt.video.i_width = 720;
-    video_fmt.video.i_height = 576;
+    video_fmt.video.i_width = p_sys->i_width;
+    video_fmt.video.i_height = p_sys->i_height;
     video_fmt.video.i_sar_num = 16 * video_fmt.video.i_height;
     video_fmt.video.i_sar_den = 9 * video_fmt.video.i_width;
-    video_fmt.video.i_frame_rate = 25;
-    video_fmt.video.i_frame_rate_base = 1;
+    video_fmt.video.i_frame_rate = p_sys->i_fps_num;
+    video_fmt.video.i_frame_rate_base = p_sys->i_fps_den;
     video_fmt.i_bitrate = video_fmt.video.i_width * video_fmt.video.i_height * video_fmt.video.i_frame_rate * 2;
 
     msg_Dbg( p_demux, "added new video es %4.4s %dx%d",