825b416c0318b53e576624f6bddbea2791b58bda
[platform/upstream/gstreamer.git] / sys / decklink / gstdecklink.h
1 /* GStreamer
2  * Copyright (C) 2011 David Schleef <ds@schleef.org>
3  * Copyright (C) 2014 Sebastian Dröge <sebastian@centricular.com>
4  * Copyright (C) 2015 Florian Langlois <florian.langlois@fr.thalesgroup.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 #ifndef _GST_DECKLINK_H_
23 #define _GST_DECKLINK_H_
24
25 #include <gst/gst.h>
26 #include <gst/video/video.h>
27
28 #include <stdint.h>
29
30 #ifdef G_OS_UNIX
31 #include "linux/DeckLinkAPI.h"
32 #endif
33
34 #ifdef G_OS_WIN32
35 #include "win/DeckLinkAPI.h"
36
37 #include <comutil.h>
38
39 #define bool BOOL
40
41 #define COMSTR_T BSTR*
42 #define FREE_COM_STRING(s) delete[] s;
43 #define CONVERT_COM_STRING(s) BSTR _s = (BSTR)s; s = _com_util::ConvertBSTRToString(_s); ::SysFreeString(_s);
44 #else
45 #define COMSTR_T const char*
46 #define FREE_COM_STRING(s)
47 #define CONVERT_COM_STRING(s)
48 #endif /* _MSC_VER */
49
50 typedef enum {
51   GST_DECKLINK_MODE_AUTO,
52
53   GST_DECKLINK_MODE_NTSC,
54   GST_DECKLINK_MODE_NTSC2398,
55   GST_DECKLINK_MODE_PAL,
56   GST_DECKLINK_MODE_NTSC_P,
57   GST_DECKLINK_MODE_PAL_P,
58
59   GST_DECKLINK_MODE_1080p2398,
60   GST_DECKLINK_MODE_1080p24,
61   GST_DECKLINK_MODE_1080p25,
62   GST_DECKLINK_MODE_1080p2997,
63   GST_DECKLINK_MODE_1080p30,
64
65   GST_DECKLINK_MODE_1080i50,
66   GST_DECKLINK_MODE_1080i5994,
67   GST_DECKLINK_MODE_1080i60,
68
69   GST_DECKLINK_MODE_1080p50,
70   GST_DECKLINK_MODE_1080p5994,
71   GST_DECKLINK_MODE_1080p60,
72
73   GST_DECKLINK_MODE_720p50,
74   GST_DECKLINK_MODE_720p5994,
75   GST_DECKLINK_MODE_720p60,
76
77   GST_DECKLINK_MODE_1556p2398,
78   GST_DECKLINK_MODE_1556p24,
79   GST_DECKLINK_MODE_1556p25,
80
81   GST_DECKLINK_MODE_2160p2398,
82   GST_DECKLINK_MODE_2160p24,
83   GST_DECKLINK_MODE_2160p25,
84   GST_DECKLINK_MODE_2160p2997,
85   GST_DECKLINK_MODE_2160p30,
86   GST_DECKLINK_MODE_2160p50,
87   GST_DECKLINK_MODE_2160p5994,
88   GST_DECKLINK_MODE_2160p60
89 } GstDecklinkModeEnum;
90 #define GST_TYPE_DECKLINK_MODE (gst_decklink_mode_get_type ())
91 GType gst_decklink_mode_get_type (void);
92
93 typedef enum {
94   GST_DECKLINK_CONNECTION_AUTO,
95   GST_DECKLINK_CONNECTION_SDI,
96   GST_DECKLINK_CONNECTION_HDMI,
97   GST_DECKLINK_CONNECTION_OPTICAL_SDI,
98   GST_DECKLINK_CONNECTION_COMPONENT,
99   GST_DECKLINK_CONNECTION_COMPOSITE,
100   GST_DECKLINK_CONNECTION_SVIDEO
101 } GstDecklinkConnectionEnum;
102 #define GST_TYPE_DECKLINK_CONNECTION (gst_decklink_connection_get_type ())
103 GType gst_decklink_connection_get_type (void);
104
105 typedef enum {
106   GST_DECKLINK_AUDIO_CONNECTION_AUTO,
107   GST_DECKLINK_AUDIO_CONNECTION_EMBEDDED,
108   GST_DECKLINK_AUDIO_CONNECTION_AES_EBU,
109   GST_DECKLINK_AUDIO_CONNECTION_ANALOG,
110   GST_DECKLINK_AUDIO_CONNECTION_ANALOG_XLR,
111   GST_DECKLINK_AUDIO_CONNECTION_ANALOG_RCA
112 } GstDecklinkAudioConnectionEnum;
113 #define GST_TYPE_DECKLINK_AUDIO_CONNECTION (gst_decklink_audio_connection_get_type ())
114 GType gst_decklink_audio_connection_get_type (void);
115
116 typedef enum {
117   GST_DECKLINK_AUDIO_CHANNELS_MAX = 0,
118   GST_DECKLINK_AUDIO_CHANNELS_2 = 2,
119   GST_DECKLINK_AUDIO_CHANNELS_8 = 8,
120   GST_DECKLINK_AUDIO_CHANNELS_16 = 16
121 } GstDecklinkAudioChannelsEnum;
122 #define GST_TYPE_DECKLINK_AUDIO_CHANNELS (gst_decklink_audio_channels_get_type ())
123 GType gst_decklink_audio_channels_get_type (void);
124
125 typedef enum {
126   GST_DECKLINK_VIDEO_FORMAT_AUTO,
127   GST_DECKLINK_VIDEO_FORMAT_8BIT_YUV, /* bmdFormat8BitYUV */
128   GST_DECKLINK_VIDEO_FORMAT_10BIT_YUV, /* bmdFormat10BitYUV */
129   GST_DECKLINK_VIDEO_FORMAT_8BIT_ARGB, /* bmdFormat8BitARGB */
130   GST_DECKLINK_VIDEO_FORMAT_8BIT_BGRA, /* bmdFormat8BitBGRA */
131   GST_DECKLINK_VIDEO_FORMAT_10BIT_RGB, /* bmdFormat10BitRGB */
132   GST_DECKLINK_VIDEO_FORMAT_12BIT_RGB, /* bmdFormat12BitRGB */
133   GST_DECKLINK_VIDEO_FORMAT_12BIT_RGBLE, /* bmdFormat12BitRGBLE */
134   GST_DECKLINK_VIDEO_FORMAT_10BIT_RGBXLE, /* bmdFormat10BitRGBXLE */
135   GST_DECKLINK_VIDEO_FORMAT_10BIT_RGBX, /* bmdFormat10BitRGBX */
136 } GstDecklinkVideoFormat;
137 #define GST_TYPE_DECKLINK_VIDEO_FORMAT (gst_decklink_video_format_get_type ())
138 GType gst_decklink_video_format_get_type (void);
139
140 typedef enum {
141   GST_DECKLINK_TIMECODE_FORMAT_RP188VITC1, /*bmdTimecodeRP188VITC1 */
142   GST_DECKLINK_TIMECODE_FORMAT_RP188VITC2, /*bmdTimecodeRP188VITC2 */
143   GST_DECKLINK_TIMECODE_FORMAT_RP188LTC, /*bmdTimecodeRP188LTC */
144   GST_DECKLINK_TIMECODE_FORMAT_RP188ANY, /*bmdTimecodeRP188Any */
145   GST_DECKLINK_TIMECODE_FORMAT_VITC, /*bmdTimecodeVITC */
146   GST_DECKLINK_TIMECODE_FORMAT_VITCFIELD2, /*bmdTimecodeVITCField2 */
147   GST_DECKLINK_TIMECODE_FORMAT_SERIAL /* bmdTimecodeSerial */
148 } GstDecklinkTimecodeFormat;
149 #define GST_TYPE_DECKLINK_TIMECODE_FORMAT (gst_decklink_timecode_format_get_type ())
150 GType gst_decklink_timecode_format_get_type (void);
151
152 const BMDPixelFormat gst_decklink_pixel_format_from_type (GstDecklinkVideoFormat t);
153 const gint gst_decklink_bpp_from_type (GstDecklinkVideoFormat t);
154 const GstDecklinkVideoFormat gst_decklink_type_from_video_format (GstVideoFormat f);
155 const BMDTimecodeFormat gst_decklink_timecode_format_from_enum (GstDecklinkTimecodeFormat f);
156 const GstDecklinkTimecodeFormat gst_decklink_timecode_format_to_enum (BMDTimecodeFormat f);
157
158 typedef struct _GstDecklinkMode GstDecklinkMode;
159 struct _GstDecklinkMode {
160   BMDDisplayMode mode;
161   int width;
162   int height;
163   int fps_n;
164   int fps_d;
165   gboolean interlaced;
166   int par_n;
167   int par_d;
168   gboolean tff;
169   const gchar *colorimetry;
170 };
171
172 const GstDecklinkMode * gst_decklink_get_mode (GstDecklinkModeEnum e);
173 const GstDecklinkModeEnum gst_decklink_get_mode_enum_from_bmd (BMDDisplayMode mode);
174 const BMDVideoConnection gst_decklink_get_connection (GstDecklinkConnectionEnum e);
175 GstCaps * gst_decklink_mode_get_caps (GstDecklinkModeEnum e, BMDPixelFormat f, gboolean input);
176 GstCaps * gst_decklink_mode_get_template_caps (gboolean input);
177
178 typedef struct _GstDecklinkOutput GstDecklinkOutput;
179 struct _GstDecklinkOutput {
180   IDeckLink *device;
181   IDeckLinkOutput *output;
182   IDeckLinkAttributes *attributes;
183   GstClock *clock;
184   GstClockTime clock_start_time, clock_last_time, clock_epoch;
185   GstClockTimeDiff clock_offset;
186   gboolean started, clock_restart;
187
188   /* Everything below protected by mutex */
189   GMutex lock;
190
191   /* Set by the video source */
192   /* Configured mode or NULL */
193   const GstDecklinkMode *mode;
194
195   /* Set by the audio sink */
196   GstClock *audio_clock;
197
198   GstElement *audiosink;
199   gboolean audio_enabled;
200   GstElement *videosink;
201   gboolean video_enabled;
202   void (*start_scheduled_playback) (GstElement *videosink);
203 };
204
205 typedef struct _GstDecklinkInput GstDecklinkInput;
206 struct _GstDecklinkInput {
207   IDeckLink *device;
208   IDeckLinkInput *input;
209   IDeckLinkConfiguration *config;
210   IDeckLinkAttributes *attributes;
211
212   /* Everything below protected by mutex */
213   GMutex lock;
214
215   /* Set by the video source */
216   void (*got_video_frame) (GstElement *videosrc, IDeckLinkVideoInputFrame * frame, GstDecklinkModeEnum mode, GstClockTime capture_time, GstClockTime stream_time, GstClockTime stream_duration, IDeckLinkTimecode *dtc, gboolean no_signal);
217   /* Configured mode or NULL */
218   const GstDecklinkMode *mode;
219   BMDPixelFormat format;
220
221   /* Set by the audio source */
222   void (*got_audio_packet) (GstElement *videosrc, IDeckLinkAudioInputPacket * packet, GstClockTime capture_time, GstClockTime packet_time, gboolean no_signal);
223
224   GstElement *audiosrc;
225   gboolean audio_enabled;
226   GstElement *videosrc;
227   gboolean video_enabled;
228   void (*start_streams) (GstElement *videosrc);
229 };
230
231 GstDecklinkOutput * gst_decklink_acquire_nth_output (gint n, GstElement * sink, gboolean is_audio);
232 void                gst_decklink_release_nth_output (gint n, GstElement * sink, gboolean is_audio);
233
234 void                gst_decklink_output_set_audio_clock (GstDecklinkOutput * output, GstClock * clock);
235 GstClock *          gst_decklink_output_get_audio_clock (GstDecklinkOutput * output);
236
237 GstDecklinkInput *  gst_decklink_acquire_nth_input (gint n, GstElement * src, gboolean is_audio);
238 void                gst_decklink_release_nth_input (gint n, GstElement * src, gboolean is_audio);
239
240 const GstDecklinkMode * gst_decklink_find_mode_for_caps (GstCaps * caps);
241 const GstDecklinkMode * gst_decklink_find_mode_and_format_for_caps (GstCaps * caps, BMDPixelFormat * format);
242 GstCaps * gst_decklink_mode_get_caps_all_formats (GstDecklinkModeEnum e, gboolean input);
243 GstCaps * gst_decklink_pixel_format_get_caps (BMDPixelFormat f, gboolean input);
244
245 #endif