]> git.sesse.net Git - vlc/blob - modules/access/sdi.cpp
Include the DeckLink API and try to open the card on Open().
[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 #include "DeckLinkAPI.h"
21 #include "DeckLinkAPIDispatch.cpp"
22
23 static int  Open ( vlc_object_t * );
24 static void Close( vlc_object_t * );
25
26 #define CACHING_TEXT N_("Caching value in ms")
27 #define CACHING_LONGTEXT N_( \
28     "Caching value for SDI captures. This " \
29     "value should be set in milliseconds." )
30
31 vlc_module_begin ()
32     set_shortname( N_("SDI") )
33     set_description( N_("BlackMagic SDI input") )
34     set_category( CAT_INPUT )
35     set_subcategory( SUBCAT_INPUT_ACCESS )
36
37     add_integer( "sdi-caching", DEFAULT_PTS_DELAY / 1000, NULL,
38                  CACHING_TEXT, CACHING_LONGTEXT, true )
39
40     add_shortcut( "sdi" )
41     set_capability( "access_demux", 10 )
42     set_callbacks( Open, Close )
43 vlc_module_end ()
44
45 static int Demux  ( demux_t * );
46 static int Control( demux_t *, int, va_list );
47
48 struct demux_sys_t
49 {
50     IDeckLink *p_card;
51     IDeckLinkInput *p_input;
52     es_out_id_t  *p_es;
53 };
54
55 static int Open( vlc_object_t *p_this )
56 {
57     demux_t     *p_demux = (demux_t*)p_this;
58     demux_sys_t *p_sys;
59
60     /* Only when selected */
61     if( *p_demux->psz_access == '\0' )
62         return VLC_EGENERIC;
63
64     /* Set up p_demux */
65     p_demux->pf_demux = Demux;
66     p_demux->pf_control = Control;
67     p_demux->info.i_update = 0;
68     p_demux->info.i_title = 0;
69     p_demux->info.i_seekpoint = 0;
70     p_demux->p_sys = p_sys = (demux_sys_t*)calloc( 1, sizeof( demux_sys_t ) );
71     if( !p_sys )
72         return VLC_ENOMEM;
73
74     msg_Dbg( p_demux, "hello world" );
75
76     IDeckLinkIterator *decklink_iterator = CreateDeckLinkIteratorInstance();
77     if ( !decklink_iterator ) {
78         msg_Err( p_demux, "DeckLink drivers not found." );
79         // FIXME: Leak here and several other error paths.
80         return VLC_EGENERIC;
81     }
82
83     HRESULT result;
84     result = decklink_iterator->Next( &p_sys->p_card );
85
86     if ( result != S_OK ) {
87         msg_Err( p_demux, "No DeckLink PCI cards found." );
88         return VLC_EGENERIC;
89     }
90
91     if ( p_sys->p_card->QueryInterface(IID_IDeckLinkInput, (void**)&p_sys->p_input) != S_OK ) {
92         msg_Err( p_demux, "Card has no inputs" );
93         return VLC_EGENERIC;
94     }
95
96     /*eDeclare elementary streams */
97     es_format_t fmt;
98     es_format_Init( &fmt, VIDEO_ES, VLC_CODEC_YUYV );
99     fmt.video.i_width = 720;
100     fmt.video.i_height = 576;
101     fmt.video.i_sar_num = 1;
102     fmt.video.i_sar_den = 1;
103
104     msg_Dbg( p_demux, "added new video es %4.4s %dx%d",
105              (char*)&fmt.i_codec, fmt.video.i_width, fmt.video.i_height );
106     p_sys->p_es = es_out_Add( p_demux->out, &fmt );
107
108     /* Update default_pts to a suitable value for access */
109     var_Create( p_demux, "sdi-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
110
111     return VLC_SUCCESS;
112 }
113
114 static void Close( vlc_object_t *p_this )
115 {
116     demux_t     *p_demux = (demux_t *)p_this;
117     demux_sys_t *p_sys   = p_demux->p_sys;
118
119     free( p_sys );
120 }
121
122 static int Control( demux_t *p_demux, int i_query, va_list args )
123 {
124     bool *pb;
125     int64_t    *pi64;
126
127     switch( i_query )
128     {
129         /* Special for access_demux */
130         case DEMUX_CAN_PAUSE:
131         case DEMUX_CAN_SEEK:
132         case DEMUX_CAN_CONTROL_PACE:
133             pb = (bool*)va_arg( args, bool * );
134             *pb = false;
135             return VLC_SUCCESS;
136
137         case DEMUX_GET_PTS_DELAY:
138             pi64 = (int64_t*)va_arg( args, int64_t * );
139             *pi64 = var_GetInteger( p_demux, "sdi-caching" ) * 1000;
140             return VLC_SUCCESS;
141
142         case DEMUX_GET_TIME:
143             pi64 = (int64_t*)va_arg( args, int64_t * );
144             *pi64 = mdate();  // FIXME
145             return VLC_SUCCESS;
146
147         /* TODO implement others */
148         default:
149             return VLC_EGENERIC;
150     }
151
152     return VLC_EGENERIC;
153 }
154
155 static int Demux( demux_t *p_demux )
156 {
157     demux_sys_t *p_sys = p_demux->p_sys;
158
159     // FIXME
160
161     return 1;
162 }
163