decklink: HD modes are square pixels
[platform/upstream/gstreamer.git] / sys / decklink / gstdecklink.cpp
1 /* GStreamer
2  * Copyright (C) 2011 David Schleef <ds@schleef.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Suite 500,
17  * Boston, MA 02110-1335, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include <gst/gst.h>
25 #include "gstdecklink.h"
26 #include "gstdecklinksrc.h"
27 #include "gstdecklinksink.h"
28
29 GType
30 gst_decklink_mode_get_type (void)
31 {
32   static GType type;
33
34   if (!type) {
35     static const GEnumValue modes[] = {
36       {GST_DECKLINK_MODE_NTSC, "ntsc", "NTSC SD 60i"},
37       {GST_DECKLINK_MODE_NTSC2398, "ntsc2398", "NTSC SD 60i (24 fps)"},
38       {GST_DECKLINK_MODE_PAL, "pal", "PAL SD 50i"},
39       {GST_DECKLINK_MODE_NTSC_P, "ntsc-p", "NTSC SD 60p"},
40       {GST_DECKLINK_MODE_PAL_P, "pal-p", "PAL SD 50p"},
41
42       {GST_DECKLINK_MODE_1080p2398, "1080p2398", "HD1080 23.98p"},
43       {GST_DECKLINK_MODE_1080p24, "1080p24", "HD1080 24p"},
44       {GST_DECKLINK_MODE_1080p25, "1080p25", "HD1080 25p"},
45       {GST_DECKLINK_MODE_1080p2997, "1080p2997", "HD1080 29.97p"},
46       {GST_DECKLINK_MODE_1080p30, "1080p30", "HD1080 30p"},
47
48       {GST_DECKLINK_MODE_1080i50, "1080i50", "HD1080 50i"},
49       {GST_DECKLINK_MODE_1080i5994, "1080i5994", "HD1080 59.94i"},
50       {GST_DECKLINK_MODE_1080i60, "1080i60", "HD1080 60i"},
51
52       {GST_DECKLINK_MODE_1080p50, "1080p50", "HD1080 50p"},
53       {GST_DECKLINK_MODE_1080p5994, "1080p5994", "HD1080 59.94p"},
54       {GST_DECKLINK_MODE_1080p60, "1080p60", "HD1080 60p"},
55
56       {GST_DECKLINK_MODE_720p50, "720p50", "HD720 50p"},
57       {GST_DECKLINK_MODE_720p5994, "720p5994", "HD720 59.94p"},
58       {GST_DECKLINK_MODE_720p60, "720p60", "HD720 60p"},
59
60       {0, NULL, NULL}
61     };
62
63     type = g_enum_register_static ("GstDecklinkModes", modes);
64   }
65   return type;
66 }
67
68 GType
69 gst_decklink_connection_get_type (void)
70 {
71   static GType type;
72
73   if (!type) {
74     static const GEnumValue connections[] = {
75       {GST_DECKLINK_CONNECTION_SDI, "sdi", "SDI"},
76       {GST_DECKLINK_CONNECTION_HDMI, "hdmi", "HDMI"},
77       {GST_DECKLINK_CONNECTION_OPTICAL_SDI, "optical-sdi", "Optical SDI"},
78       {GST_DECKLINK_CONNECTION_COMPONENT, "component", "Component"},
79       {GST_DECKLINK_CONNECTION_COMPOSITE, "composite", "Composite"},
80       {GST_DECKLINK_CONNECTION_SVIDEO, "svideo", "S-Video"},
81       {0, NULL, NULL}
82     };
83
84     type = g_enum_register_static ("GstDecklinkConnection", connections);
85   }
86   return type;
87 }
88
89 #define NTSC 10, 11, false, false
90 #define PAL 12, 11, true, false
91 #define HD 1, 1, false, true
92
93 static const GstDecklinkMode modes[] = {
94   {bmdModeNTSC, 720, 486, 30000, 1001, true, NTSC },
95   {bmdModeNTSC2398, 720, 486, 24000, 1001, true, NTSC },
96   {bmdModePAL, 720, 576, 25, 1, true, PAL },
97   {bmdModeNTSCp, 720, 486, 30000, 1001, false, NTSC },
98   {bmdModePALp, 720, 576, 25, 1, false, PAL },
99
100   {bmdModeHD1080p2398, 1920, 1080, 24000, 1001, false, HD },
101   {bmdModeHD1080p24, 1920, 1080, 24, 1, false, HD },
102   {bmdModeHD1080p25, 1920, 1080, 25, 1, false, HD },
103   {bmdModeHD1080p2997, 1920, 1080, 30000, 1001, false, HD },
104   {bmdModeHD1080p30, 1920, 1080, 30, 1, false, HD },
105
106   {bmdModeHD1080i50, 1920, 1080, 25, 1, true, HD },
107   {bmdModeHD1080i5994, 1920, 1080, 30000, 1001, true, HD },
108   {bmdModeHD1080i6000, 1920, 1080, 30, 1, true, HD },
109
110   {bmdModeHD1080p50, 1920, 1080, 50, 1, false, HD },
111   {bmdModeHD1080p5994, 1920, 1080, 30000, 1001, false, HD },
112   {bmdModeHD1080p6000, 1920, 1080, 60, 1, false, HD },
113
114   {bmdModeHD720p50, 1280, 720, 50, 1, false, HD },
115   {bmdModeHD720p5994, 1280, 720, 60000, 1001, false, HD },
116   {bmdModeHD720p60, 1280, 720, 60, 1, false, HD }
117
118 };
119
120 const GstDecklinkMode *
121 gst_decklink_get_mode (GstDecklinkModeEnum e)
122 {
123   return &modes[e];
124 }
125
126 static GstStructure *
127 gst_decklink_mode_get_structure (GstDecklinkModeEnum e)
128 {
129   const GstDecklinkMode *mode = &modes[e];
130
131   return gst_structure_new ("video/x-raw-yuv",
132       "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'),
133       "width", G_TYPE_INT, mode->width,
134       "height", G_TYPE_INT, mode->height,
135       "framerate", GST_TYPE_FRACTION, mode->fps_n, mode->fps_d,
136       "interlaced", G_TYPE_BOOLEAN, mode->interlaced,
137       "pixel-aspect-ratio", GST_TYPE_FRACTION, mode->par_n, mode->par_d,
138       "color-matrix", G_TYPE_STRING, mode->is_hdtv ? "hdtv" : "sdtv",
139       "chroma-site", G_TYPE_STRING, "mpeg2",
140       NULL);
141 }
142
143 GstCaps *
144 gst_decklink_mode_get_caps (GstDecklinkModeEnum e)
145 {
146   GstCaps *caps;
147
148   caps = gst_caps_new_empty ();
149   gst_caps_append_structure (caps, gst_decklink_mode_get_structure (e));
150
151   return caps;
152 }
153
154 GstCaps *
155 gst_decklink_mode_get_template_caps (void)
156 {
157   int i;
158   GstCaps *caps;
159   GstStructure *s;
160
161   caps = gst_caps_new_empty ();
162   for(i=0;i<(int)G_N_ELEMENTS(modes);i++) {
163     s = gst_decklink_mode_get_structure ((GstDecklinkModeEnum)i);
164     gst_caps_append_structure (caps, s);
165   }
166
167   return caps;
168 }
169
170 static gboolean
171 plugin_init (GstPlugin * plugin)
172 {
173
174   gst_element_register (plugin, "decklinksrc", GST_RANK_NONE,
175       gst_decklink_src_get_type ());
176   gst_element_register (plugin, "decklinksink", GST_RANK_NONE,
177       gst_decklink_sink_get_type ());
178
179   return TRUE;
180 }
181
182 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
183     GST_VERSION_MINOR,
184     "decklink",
185     "Blackmagic Decklink plugin",
186     plugin_init, VERSION, "LGPL", PACKAGE_NAME, GST_PACKAGE_ORIGIN)