]> git.sesse.net Git - vlc/blob - modules/access/sdi.c
6395c27dd0cd10592b54fe609857d374fe44bf8e
[vlc] / modules / access / sdi.c
1 /* BlackMagic SDI driver */
2
3 #ifdef HAVE_CONFIG_H
4 # include "config.h"
5 #endif
6
7 #include <vlc_common.h>
8 #include <vlc_plugin.h>
9 #include <vlc_input.h>
10 #include <vlc_demux.h>
11 #include <vlc_access.h>
12 #include <vlc_picture.h>
13 #include <vlc_charset.h>
14 #include <vlc_fs.h>
15
16 static int  Open ( vlc_object_t * );
17 static void Close( vlc_object_t * );
18
19 #define CACHING_TEXT N_("Caching value in ms")
20 #define CACHING_LONGTEXT N_( \
21     "Caching value for SDI captures. This " \
22     "value should be set in milliseconds." )
23
24 vlc_module_begin ()
25     set_shortname( N_("SDI") )
26     set_description( N_("BlackMagic SDI input") )
27     set_category( CAT_INPUT )
28     set_subcategory( SUBCAT_INPUT_ACCESS )
29
30     add_shortcut( "sdi" )
31     set_capability( "access_demux", 10 )
32     set_callbacks( Open, Close )
33 vlc_module_end ()
34
35 static int Demux  ( demux_t * );
36 static int Control( demux_t *, int, va_list );
37
38 struct demux_sys_t
39 {
40     es_out_id_t  *p_es;
41 };
42
43 static int Open( vlc_object_t *p_this )
44 {
45     demux_t     *p_demux = (demux_t*)p_this;
46     demux_sys_t *p_sys;
47
48     /* Only when selected */
49     if( *p_demux->psz_access == '\0' )
50         return VLC_EGENERIC;
51
52     /* Set up p_demux */
53     p_demux->pf_demux = Demux;
54     p_demux->pf_control = Control;
55     p_demux->info.i_update = 0;
56     p_demux->info.i_title = 0;
57     p_demux->info.i_seekpoint = 0;
58     p_demux->p_sys = p_sys = calloc( 1, sizeof( demux_sys_t ) );
59     if( !p_sys )
60         return VLC_ENOMEM;
61
62     msg_Dbg( p_demux, "hello world" );
63
64     /* Declare elementary streams */
65     es_format_t fmt;
66     es_format_Init( &fmt, VIDEO_ES, VLC_CODEC_YUYV );
67     fmt.video.i_width = 720;
68     fmt.video.i_height = 576;
69     fmt.video.i_sar_num = 1;
70     fmt.video.i_sar_den = 1;
71
72     msg_Dbg( p_demux, "added new video es %4.4s %dx%d",
73              (char*)&fmt.i_codec, fmt.video.i_width, fmt.video.i_height );
74     p_sys->p_es = es_out_Add( p_demux->out, &fmt );
75
76     /* Update default_pts to a suitable value for access */
77     var_Create( p_demux, "sdi-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
78
79     return VLC_SUCCESS;
80 }
81
82 static void Close( vlc_object_t *p_this )
83 {
84     demux_t     *p_demux = (demux_t *)p_this;
85     demux_sys_t *p_sys   = p_demux->p_sys;
86
87     free( p_sys );
88 }
89
90 static int Control( demux_t *p_demux, int i_query, va_list args )
91 {
92     bool *pb;
93     int64_t    *pi64;
94
95     switch( i_query )
96     {
97         /* Special for access_demux */
98         case DEMUX_CAN_PAUSE:
99         case DEMUX_CAN_SEEK:
100         case DEMUX_CAN_CONTROL_PACE:
101             pb = (bool*)va_arg( args, bool * );
102             *pb = false;
103             return VLC_SUCCESS;
104
105         case DEMUX_GET_PTS_DELAY:
106             pi64 = (int64_t*)va_arg( args, int64_t * );
107             *pi64 = var_GetInteger( p_demux, "sdi-caching" ) * 1000;
108             return VLC_SUCCESS;
109
110         case DEMUX_GET_TIME:
111             pi64 = (int64_t*)va_arg( args, int64_t * );
112             *pi64 = mdate();  // FIXME
113             return VLC_SUCCESS;
114
115         /* TODO implement others */
116         default:
117             return VLC_EGENERIC;
118     }
119
120     return VLC_EGENERIC;
121 }
122
123 static int Demux( demux_t *p_demux )
124 {
125     demux_sys_t *p_sys = p_demux->p_sys;
126
127     // FIXME
128
129     return 1;
130 }
131