1 /* GStreamer Raspberry Pi Camera Source Device Provider
2 * Copyright (C) 2014 Tim-Philipp Müller <tim@centricular.com>
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.
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.
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.
24 #include "gstrpicamsrcdeviceprovider.h"
28 #include "RaspiCapture.h"
30 /* FIXME: translations */
33 static GstRpiCamSrcDevice *gst_rpi_cam_src_device_new (void);
35 G_DEFINE_TYPE (GstRpiCamSrcDeviceProvider, gst_rpi_cam_src_device_provider,
36 GST_TYPE_DEVICE_PROVIDER);
39 static GList *gst_rpi_cam_src_device_provider_probe (GstDeviceProvider *
43 gst_rpi_cam_src_device_provider_class_init (GstRpiCamSrcDeviceProviderClass *
46 GstDeviceProviderClass *dprovider_class = GST_DEVICE_PROVIDER_CLASS (klass);
48 dprovider_class->probe = gst_rpi_cam_src_device_provider_probe;
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>");
57 gst_rpi_cam_src_device_provider_init (GstRpiCamSrcDeviceProvider * provider)
63 gst_rpi_cam_src_device_provider_probe (GstDeviceProvider * provider)
65 GstRpiCamSrcDevice *device;
66 int supported = 0, detected = 0;
68 raspicamcontrol_get_camera (&supported, &detected);
71 GST_INFO ("No Raspberry Pi camera module detected.");
73 } else if (!supported) {
75 ("Raspberry Pi camera module not supported, make sure to enable it.");
79 GST_INFO ("Raspberry Pi camera module detected and supported.");
81 device = gst_rpi_cam_src_device_new ();
83 return g_list_append (NULL, device);
86 G_DEFINE_TYPE (GstRpiCamSrcDevice, gst_rpi_cam_src_device, GST_TYPE_DEVICE);
88 static GstElement *gst_rpi_cam_src_device_create_element (GstDevice * device,
92 gst_rpi_cam_src_device_class_init (GstRpiCamSrcDeviceClass * klass)
94 GstDeviceClass *device_class = GST_DEVICE_CLASS (klass);
96 device_class->create_element = gst_rpi_cam_src_device_create_element;
100 gst_rpi_cam_src_device_init (GstRpiCamSrcDevice * device)
102 /* nothing to do here */
106 gst_rpi_cam_src_device_create_element (GstDevice * device, const gchar * name)
108 return gst_element_factory_make ("rpicamsrc", name);
111 static GstRpiCamSrcDevice *
112 gst_rpi_cam_src_device_new (void)
114 GstRpiCamSrcDevice *device;
115 GValue profiles = G_VALUE_INIT;
116 GValue val = G_VALUE_INIT;
117 GstStructure *s, *jpeg_s;
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);
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, "constrained-baseline");
135 gst_value_list_append_value (&profiles, &val);
136 g_value_set_static_string (&val, "baseline");
137 gst_value_list_append_and_take_value (&profiles, &val);
138 gst_structure_take_value (s, "profiles", &profiles);
140 jpeg_s = gst_structure_new ("image/jpeg",
141 "width", GST_TYPE_INT_RANGE, 1, 1920,
142 "height", GST_TYPE_INT_RANGE, 1, 1080,
143 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, RPICAMSRC_MAX_FPS, 1,
144 "parsed", G_TYPE_BOOLEAN, "true", NULL);
146 caps = gst_caps_new_full (s, jpeg_s, NULL);
148 device = g_object_new (GST_TYPE_RPICAMSRC_DEVICE,
149 "display-name", _("Raspberry Pi Camera Module"),
150 "device-class", "Video/Source", "caps", caps, NULL);
152 gst_caps_unref (caps);