rpicamsrc: Add GstDeviceProvider for rpi camera module

This commit is contained in:
Tim-Philipp Müller 2014-10-29 00:43:51 +00:00
parent 4b15fa2abc
commit 8e9c8663f8
3 changed files with 228 additions and 2 deletions

View file

@ -64,6 +64,7 @@
#include "gstrpicamsrc.h"
#include "gstrpicam_types.h"
#include "gstrpicam-enum-types.h"
#include "gstrpicamsrcdeviceprovider.h"
#include "RaspiCapture.h"
#include "bcm_host.h"
@ -684,13 +685,24 @@ gst_rpi_cam_src_create (GstPushSrc * parent, GstBuffer ** buf)
}
static gboolean
plugin_init (GstPlugin * rpicamsrc)
plugin_init (GstPlugin * plugin)
{
gboolean ret;
GST_DEBUG_CATEGORY_INIT (gst_rpi_cam_src_debug, "rpicamsrc",
0, "rpicamsrc debug");
return gst_element_register (rpicamsrc, "rpicamsrc", GST_RANK_NONE,
ret = gst_element_register (plugin, "rpicamsrc", GST_RANK_NONE,
GST_TYPE_RPICAMSRC);
#if GST_CHECK_VERSION (1,4,0)
ret &= gst_device_provider_register (plugin, "rpicamsrcdeviceprovider",
GST_RANK_PRIMARY, GST_TYPE_RPICAMSRC_DEVICE_PROVIDER);
#endif
return ret;
}
#ifndef PACKAGE

View file

@ -0,0 +1,135 @@
/* GStreamer Raspberry Pi Camera Source Device Provider
* Copyright (C) 2014 Tim-Philipp Müller <tim@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstrpicamsrcdeviceprovider.h"
#include <string.h>
#if GST_CHECK_VERSION (1,4,0)
/* FIXME: translations */
#define _(s) s
static GstRpiCamSrcDevice * gst_rpi_cam_src_device_new (void);
G_DEFINE_TYPE (GstRpiCamSrcDeviceProvider, gst_rpi_cam_src_device_provider,
GST_TYPE_DEVICE_PROVIDER);
static GList *gst_rpi_cam_src_device_provider_probe (GstDeviceProvider * provider);
static void
gst_rpi_cam_src_device_provider_class_init (GstRpiCamSrcDeviceProviderClass * klass)
{
GstDeviceProviderClass *dprovider_class = GST_DEVICE_PROVIDER_CLASS (klass);
dprovider_class->probe = gst_rpi_cam_src_device_provider_probe;
gst_device_provider_class_set_static_metadata (dprovider_class,
"Raspberry Pi Camera Source Device Provider", "Source/Video",
"Lists Raspberry Pi camera devices",
"Tim-Philipp Müller <tim@centricular.com>");
}
static void
gst_rpi_cam_src_device_provider_init (GstRpiCamSrcDeviceProvider * provider)
{
/* nothing to do here yet */
}
static GList *
gst_rpi_cam_src_device_provider_probe (GstDeviceProvider * provider)
{
GstRpiCamSrcDevice *device;
/* FIXME: check if camera module is usable and supported */
device = gst_rpi_cam_src_device_new ();
return g_list_append (NULL, device);
}
G_DEFINE_TYPE (GstRpiCamSrcDevice, gst_rpi_cam_src_device, GST_TYPE_DEVICE);
static GstElement *gst_rpi_cam_src_device_create_element (GstDevice * device,
const gchar * name);
static void
gst_rpi_cam_src_device_class_init (GstRpiCamSrcDeviceClass * klass)
{
GstDeviceClass *device_class = GST_DEVICE_CLASS (klass);
device_class->create_element = gst_rpi_cam_src_device_create_element;
}
static void
gst_rpi_cam_src_device_init (GstRpiCamSrcDevice * device)
{
/* nothing to do here */
}
static GstElement *
gst_rpi_cam_src_device_create_element (GstDevice * device, const gchar * name)
{
return gst_element_factory_make ("rpicamsrc", name);
}
static GstRpiCamSrcDevice *
gst_rpi_cam_src_device_new (void)
{
GstRpiCamSrcDevice *device;
GValue profiles = G_VALUE_INIT;
GValue val = G_VALUE_INIT;
GstStructure *s;
GstCaps *caps;
/* FIXME: retrieve limits from the camera module, max width/height/fps etc. */
s = gst_structure_new ("video/x-h264",
"width", GST_TYPE_INT_RANGE, 1, 1920,
"height", GST_TYPE_INT_RANGE, 1, 1080,
"framerate", GST_TYPE_FRACTION_RANGE, 0, 1, 90, 1,
"stream-format", G_TYPE_STRING, "byte-stream",
"alignment", G_TYPE_STRING, "au",
NULL);
g_value_init (&profiles, GST_TYPE_LIST);
g_value_init (&val, G_TYPE_STRING);
g_value_set_static_string (&val, "high");
gst_value_list_append_value (&profiles, &val);
g_value_set_static_string (&val, "main");
gst_value_list_append_value (&profiles, &val);
g_value_set_static_string (&val, "baseline");
gst_value_list_append_and_take_value (&profiles, &val);
gst_structure_take_value (s, "profiles", &profiles);
caps = gst_caps_new_full (s, NULL);
device = g_object_new (GST_TYPE_RPICAMSRC_DEVICE,
"display-name", _("Raspberry Pi Camera Module"),
"device-class", "Video/Source", "caps", caps, NULL);
gst_caps_unref (caps);
return device;
}
#endif /* GST_CHECK_VERSION (1,4,0) */

View file

@ -0,0 +1,79 @@
/* GStreamer Raspberry Pi Camera Source Device Provider
* Copyright (C) 2014 Tim-Philipp Müller <tim@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GST_RPICAMSRC_DEVICE_PROVIDER_H__
#define __GST_RPICAMSRC_DEVICE_PROVIDER_H__
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/gst.h>
#if GST_CHECK_VERSION (1,4,0)
G_BEGIN_DECLS
typedef struct _GstRpiCamSrcDeviceProvider GstRpiCamSrcDeviceProvider;
typedef struct _GstRpiCamSrcDeviceProviderClass GstRpiCamSrcDeviceProviderClass;
#define GST_TYPE_RPICAMSRC_DEVICE_PROVIDER (gst_rpi_cam_src_device_provider_get_type())
#define GST_IS_RPICAMSRC_DEVICE_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_RPICAMSRC_DEVICE_PROVIDER))
#define GST_IS_RPICAMSRC_DEVICE_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_RPICAMSRC_DEVICE_PROVIDER))
#define GST_RPICAMSRC_DEVICE_PROVIDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_RPICAMSRC_DEVICE_PROVIDER, GstRpiCamSrcDeviceProviderClass))
#define GST_RPICAMSRC_DEVICE_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_RPICAMSRC_DEVICE_PROVIDER, GstRpiCamSrcDeviceProvider))
#define GST_RPICAMSRC_DEVICE_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_DEVICE_PROVIDER, GstRpiCamSrcDeviceProviderClass))
#define GST_RPICAMSRC_DEVICE_PROVIDER_CAST(obj) ((GstRpiCamSrcDeviceProvider *)(obj))
struct _GstRpiCamSrcDeviceProvider {
GstDeviceProvider parent;
};
struct _GstRpiCamSrcDeviceProviderClass {
GstDeviceProviderClass parent_class;
};
GType gst_rpi_cam_src_device_provider_get_type (void);
typedef struct _GstRpiCamSrcDevice GstRpiCamSrcDevice;
typedef struct _GstRpiCamSrcDeviceClass GstRpiCamSrcDeviceClass;
#define GST_TYPE_RPICAMSRC_DEVICE (gst_rpi_cam_src_device_get_type())
#define GST_IS_RPICAMSRC_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_RPICAMSRC_DEVICE))
#define GST_IS_RPICAMSRC_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_RPICAMSRC_DEVICE))
#define GST_RPICAMSRC_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_RPICAMSRC_DEVICE, GstRpiCamSrcDeviceClass))
#define GST_RPICAMSRC_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_RPICAMSRC_DEVICE, GstRpiCamSrcDevice))
#define GST_RPICAMSRC_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_DEVICE, GstRpiCamSrcDeviceClass))
#define GST_RPICAMSRC_DEVICE_CAST(obj) ((GstRpiCamSrcDevice *)(obj))
struct _GstRpiCamSrcDevice {
GstDevice parent;
};
struct _GstRpiCamSrcDeviceClass {
GstDeviceClass parent_class;
};
GType gst_rpi_cam_src_device_get_type (void);
G_END_DECLS
#endif /* GST_CHECK_VERSION (1,4,0) */
#endif /* __GST_RPICAMSRC_DEVICE_PROVIDER_H__ */