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