rpicamsrc: fix indentation
[platform/upstream/gstreamer.git] / sys / rpicamsrc / gstrpicamsrcdeviceprovider.c
1 /* GStreamer Raspberry Pi Camera Source Device Provider
2  * Copyright (C) 2014 Tim-Philipp Müller <tim@centricular.com>
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., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include "gstrpicamsrcdeviceprovider.h"
25
26 #include <string.h>
27
28 #include "RaspiCapture.h"
29
30 /* FIXME: translations */
31 #define _(s) s
32
33 static GstRpiCamSrcDevice *gst_rpi_cam_src_device_new (void);
34
35 G_DEFINE_TYPE (GstRpiCamSrcDeviceProvider, gst_rpi_cam_src_device_provider,
36     GST_TYPE_DEVICE_PROVIDER);
37
38
39 static GList *gst_rpi_cam_src_device_provider_probe (GstDeviceProvider *
40     provider);
41
42 static void
43 gst_rpi_cam_src_device_provider_class_init (GstRpiCamSrcDeviceProviderClass *
44     klass)
45 {
46   GstDeviceProviderClass *dprovider_class = GST_DEVICE_PROVIDER_CLASS (klass);
47
48   dprovider_class->probe = gst_rpi_cam_src_device_provider_probe;
49
50   gst_device_provider_class_set_static_metadata (dprovider_class,
51       "Raspberry Pi Camera Source Device Provider", "Source/Video",
52       "Lists Raspberry Pi camera devices",
53       "Tim-Philipp Müller <tim@centricular.com>");
54 }
55
56 static void
57 gst_rpi_cam_src_device_provider_init (GstRpiCamSrcDeviceProvider * provider)
58 {
59   raspicapture_init ();
60 }
61
62 static GList *
63 gst_rpi_cam_src_device_provider_probe (GstDeviceProvider * provider)
64 {
65   GstRpiCamSrcDevice *device;
66   int supported = 0, detected = 0;
67
68   raspicamcontrol_get_camera (&supported, &detected);
69
70   if (!detected) {
71     GST_INFO ("No Raspberry Pi camera module detected.");
72     return NULL;
73   } else if (!supported) {
74     GST_WARNING
75         ("Raspberry Pi camera module not supported, make sure to enable it.");
76     return NULL;
77   }
78
79   GST_INFO ("Raspberry Pi camera module detected and supported.");
80
81   device = gst_rpi_cam_src_device_new ();
82
83   return g_list_append (NULL, device);
84 }
85
86 G_DEFINE_TYPE (GstRpiCamSrcDevice, gst_rpi_cam_src_device, GST_TYPE_DEVICE);
87
88 static GstElement *gst_rpi_cam_src_device_create_element (GstDevice * device,
89     const gchar * name);
90
91 static void
92 gst_rpi_cam_src_device_class_init (GstRpiCamSrcDeviceClass * klass)
93 {
94   GstDeviceClass *device_class = GST_DEVICE_CLASS (klass);
95
96   device_class->create_element = gst_rpi_cam_src_device_create_element;
97 }
98
99 static void
100 gst_rpi_cam_src_device_init (GstRpiCamSrcDevice * device)
101 {
102   /* nothing to do here */
103 }
104
105 static GstElement *
106 gst_rpi_cam_src_device_create_element (GstDevice * device, const gchar * name)
107 {
108   return gst_element_factory_make ("rpicamsrc", name);
109 }
110
111 static GstRpiCamSrcDevice *
112 gst_rpi_cam_src_device_new (void)
113 {
114   GstRpiCamSrcDevice *device;
115   GValue profiles = G_VALUE_INIT;
116   GValue val = G_VALUE_INIT;
117   GstStructure *s;
118   GstCaps *caps;
119
120   /* FIXME: retrieve limits from the camera module, max width/height/fps etc. */
121   s = gst_structure_new ("video/x-h264",
122       "width", GST_TYPE_INT_RANGE, 1, 1920,
123       "height", GST_TYPE_INT_RANGE, 1, 1080,
124       "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, RPICAMSRC_MAX_FPS, 1,
125       "stream-format", G_TYPE_STRING, "byte-stream",
126       "alignment", G_TYPE_STRING, "au", NULL);
127
128   g_value_init (&profiles, GST_TYPE_LIST);
129   g_value_init (&val, G_TYPE_STRING);
130   g_value_set_static_string (&val, "high");
131   gst_value_list_append_value (&profiles, &val);
132   g_value_set_static_string (&val, "main");
133   gst_value_list_append_value (&profiles, &val);
134   g_value_set_static_string (&val, "baseline");
135   gst_value_list_append_and_take_value (&profiles, &val);
136   gst_structure_take_value (s, "profiles", &profiles);
137
138   caps = gst_caps_new_full (s, NULL);
139
140   device = g_object_new (GST_TYPE_RPICAMSRC_DEVICE,
141       "display-name", _("Raspberry Pi Camera Module"),
142       "device-class", "Video/Source", "caps", caps, NULL);
143
144   gst_caps_unref (caps);
145
146   return device;
147 }