summaryrefslogtreecommitdiff
path: root/gst-libs
diff options
context:
space:
mode:
authorThiago Santos <thiago.sousa.santos@collabora.co.uk>2010-12-13 19:36:41 -0300
committerThiago Santos <thiago.sousa.santos@collabora.co.uk>2010-12-23 13:20:31 -0300
commit4938c2e9ea2613d4049dc01756346bbb055eab70 (patch)
tree048300e5ec8cbb2e0d82811b36d01895f5a1330d /gst-libs
parent4a28d5f4780ec680ab53579630830a59d862457a (diff)
camerabin2: Move basecamerasrc to gst-libs
Move the base camera src class to gst-libs/gst/basecamerabinsrc to allow it to be included from the tests.
Diffstat (limited to 'gst-libs')
-rw-r--r--gst-libs/gst/Makefile.am8
-rw-r--r--gst-libs/gst/basecamerabinsrc/Makefile.am26
-rw-r--r--gst-libs/gst/basecamerabinsrc/gstbasecamerasrc.c551
-rw-r--r--gst-libs/gst/basecamerabinsrc/gstbasecamerasrc.h147
-rw-r--r--gst-libs/gst/basecamerabinsrc/gstcamerabin-enum.c39
-rw-r--r--gst-libs/gst/basecamerabinsrc/gstcamerabin-enum.h57
6 files changed, 826 insertions, 2 deletions
diff --git a/gst-libs/gst/Makefile.am b/gst-libs/gst/Makefile.am
index e48cdd802..561c1f4ea 100644
--- a/gst-libs/gst/Makefile.am
+++ b/gst-libs/gst/Makefile.am
@@ -1,5 +1,9 @@
-SUBDIRS = interfaces signalprocessor video
+if BUILD_EXPERIMENTAL
+EXPERIMENTAL_LIBS=basecamerabinsrc
+endif
+
+SUBDIRS = $(EXPERIMENTAL_LIBS) interfaces signalprocessor video
noinst_HEADERS = gst-i18n-plugin.h gettext.h
-DIST_SUBDIRS = interfaces signalprocessor video
+DIST_SUBDIRS = $(EXPERIMENTAL_LIBS) interfaces signalprocessor video
diff --git a/gst-libs/gst/basecamerabinsrc/Makefile.am b/gst-libs/gst/basecamerabinsrc/Makefile.am
new file mode 100644
index 000000000..d0b69b5fe
--- /dev/null
+++ b/gst-libs/gst/basecamerabinsrc/Makefile.am
@@ -0,0 +1,26 @@
+
+lib_LTLIBRARIES = libgstbasecamerabinsrc-@GST_MAJORMINOR@.la
+
+CLEANFILES = $(BUILT_SOURCES)
+
+libgstbasecamerabinsrc_@GST_MAJORMINOR@_la_SOURCES = \
+ gstcamerabin-enum.c \
+ gstbasecamerasrc.c
+
+libgstbasecamerabinsrc_@GST_MAJORMINOR@includedir = $(includedir)/gstreamer-@GST_MAJORMINOR@/gst/basecamerabinsrc
+libgstbasecamerabinsrc_@GST_MAJORMINOR@include_HEADERS = \
+ gstcamerabin-enum.h \
+ gstbasecamerasrc.h
+
+libgstbasecamerabinsrc_@GST_MAJORMINOR@_la_CFLAGS = \
+ $(GST_PLUGINS_BAD_CFLAGS) \
+ $(GST_PLUGINS_BASE_CFLAGS) \
+ -DGST_USE_UNSTABLE_API \
+ $(GST_CFLAGS)
+libgstbasecamerabinsrc_@GST_MAJORMINOR@_la_LIBADD = \
+ $(top_builddir)/gst-libs/gst/interfaces/libgstphotography-@GST_MAJORMINOR@.la \
+ $(GST_PLUGINS_BASE_LIBS) $(GST_BASE_LIBS) $(GST_LIBS) \
+ -lgstinterfaces-$(GST_MAJORMINOR)
+
+libgstbasecamerabinsrc_@GST_MAJORMINOR@_la_LDFLAGS = $(GST_LIB_LDFLAGS) $(GST_ALL_LDFLAGS) $(GST_LT_LDFLAGS)
+
diff --git a/gst-libs/gst/basecamerabinsrc/gstbasecamerasrc.c b/gst-libs/gst/basecamerabinsrc/gstbasecamerasrc.c
new file mode 100644
index 000000000..a90684067
--- /dev/null
+++ b/gst-libs/gst/basecamerabinsrc/gstbasecamerasrc.c
@@ -0,0 +1,551 @@
+/*
+ * GStreamer
+ * Copyright (C) 2010 Texas Instruments, Inc
+ *
+ * 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.
+ */
+
+
+
+/**
+ * SECTION:element-basecamerasrc
+ *
+ * Base class for the camera source bin used by camerabin for capture.
+ * Sophisticated camera hardware can derive from this baseclass and map the
+ * features to this interface.
+ *
+ * The design mandates that the subclasses implement the following features and
+ * behaviour:
+ * <itemizedlist>
+ * <listitem><para>
+ * 3 pads: viewfinder, image capture, video capture
+ * </para></listitem>
+ * <listitem><para>
+ * </para></listitem>
+ * </itemizedlist>
+ *
+ * During construct_pipeline() vmethod a subclass can add several elements into
+ * the bin and expose 3 srcs pads as ghostpads implementing the 3 pad templates.
+ *
+ * It is also possible to add regular pads from the subclass and implement the
+ * dataflow methods on these pads. This way all functionality can be implemneted
+ * directly in the subclass without extra elements.
+ *
+ * The src will receive the capture mode from #GstCameraBin2 on the
+ * #GstBaseCameraSrc:mode property. Possible capture modes are defined in
+ * #GstCameraBinMode.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "gstbasecamerasrc.h"
+
+enum
+{
+ PROP_0,
+ PROP_MODE,
+ PROP_ZOOM,
+ PROP_READY_FOR_CAPTURE
+};
+
+enum
+{
+ /* action signals */
+ START_CAPTURE_SIGNAL,
+ STOP_CAPTURE_SIGNAL,
+ /* emit signals */
+ LAST_SIGNAL
+};
+
+static guint basecamerasrc_signals[LAST_SIGNAL];
+
+GST_DEBUG_CATEGORY (base_camera_src_debug);
+#define GST_CAT_DEFAULT base_camera_src_debug
+
+GST_BOILERPLATE (GstBaseCameraSrc, gst_base_camera_src, GstBin, GST_TYPE_BIN);
+
+static GstStaticPadTemplate vfsrc_template =
+GST_STATIC_PAD_TEMPLATE (GST_BASE_CAMERA_SRC_VIEWFINDER_PAD_NAME,
+ GST_PAD_SRC,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS_ANY);
+
+static GstStaticPadTemplate imgsrc_template =
+GST_STATIC_PAD_TEMPLATE (GST_BASE_CAMERA_SRC_IMAGE_PAD_NAME,
+ GST_PAD_SRC,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS_ANY);
+
+static GstStaticPadTemplate vidsrc_template =
+GST_STATIC_PAD_TEMPLATE (GST_BASE_CAMERA_SRC_VIDEO_PAD_NAME,
+ GST_PAD_SRC,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS_ANY);
+
+/* NOTE: we could provide a vmethod for derived class to overload to provide
+ * it's own implementation of interface.. but in all cases I can think of at
+ * moment, either the camerasrc itself, or some element within the bin, will
+ * be implementing the interface..
+ */
+
+/**
+ * gst_base_camera_src_get_photography:
+ * @self: the camerasrc bin
+ *
+ * Get object implementing photography interface, if there is one. Otherwise
+ * returns NULL.
+ */
+GstPhotography *
+gst_base_camera_src_get_photography (GstBaseCameraSrc * self)
+{
+ GstElement *elem;
+
+ if (GST_IS_PHOTOGRAPHY (self)) {
+ elem = GST_ELEMENT (self);
+ } else {
+ elem = gst_bin_get_by_interface (GST_BIN (self), GST_TYPE_PHOTOGRAPHY);
+ }
+
+ if (elem) {
+ return GST_PHOTOGRAPHY (self);
+ }
+
+ return NULL;
+}
+
+
+/**
+ * gst_base_camera_src_get_colorbalance:
+ * @self: the camerasrc bin
+ *
+ * Get object implementing colorbalance interface, if there is one. Otherwise
+ * returns NULL.
+ */
+GstColorBalance *
+gst_base_camera_src_get_color_balance (GstBaseCameraSrc * self)
+{
+ GstElement *elem;
+
+ if (GST_IS_COLOR_BALANCE (self)) {
+ elem = GST_ELEMENT (self);
+ } else {
+ elem = gst_bin_get_by_interface (GST_BIN (self), GST_TYPE_COLOR_BALANCE);
+ }
+
+ if (elem) {
+ return GST_COLOR_BALANCE (self);
+ }
+
+ return NULL;
+}
+
+/**
+ * gst_base_camera_src_set_mode:
+ * @self: the camerasrc bin
+ * @mode: the mode
+ *
+ * Set the chosen #GstCameraBinMode capture mode.
+ */
+gboolean
+gst_base_camera_src_set_mode (GstBaseCameraSrc * self, GstCameraBinMode mode)
+{
+ GstBaseCameraSrcClass *bclass = GST_BASE_CAMERA_SRC_GET_CLASS (self);
+
+ g_return_val_if_fail (bclass->set_mode, FALSE);
+
+ if (bclass->set_mode (self, mode)) {
+ self->mode = mode;
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/**
+ * gst_base_camera_src_setup_zoom:
+ * @self: camerasrc object
+ *
+ * Apply zoom configured to camerabin to capture.
+ */
+void
+gst_base_camera_src_setup_zoom (GstBaseCameraSrc * self)
+{
+ GstBaseCameraSrcClass *bclass = GST_BASE_CAMERA_SRC_GET_CLASS (self);
+ gint zoom;
+
+ zoom = g_atomic_int_get (&self->zoom);
+
+ g_return_if_fail (zoom);
+ g_return_if_fail (bclass->set_zoom);
+
+ bclass->set_zoom (self, zoom);
+}
+
+
+/**
+ * gst_base_camera_src_get_allowed_input_caps:
+ * @self: the camerasrc bin
+ *
+ * Retrieve caps from videosrc describing formats it supports
+ *
+ * Returns: caps object from videosrc
+ */
+GstCaps *
+gst_base_camera_src_get_allowed_input_caps (GstBaseCameraSrc * self)
+{
+ GstBaseCameraSrcClass *bclass = GST_BASE_CAMERA_SRC_GET_CLASS (self);
+
+ g_return_val_if_fail (bclass->get_allowed_input_caps, NULL);
+
+ return bclass->get_allowed_input_caps (self);
+}
+
+/**
+ * gst_base_camera_src_find_better_framerate:
+ * @self: camerasrc object
+ * @st: structure that contains framerate candidates
+ * @orig_framerate: best framerate so far
+ *
+ * Looks for framerate better than @orig_framerate from @st structure.
+ * In night mode lowest framerate is considered best, otherwise highest is
+ * best.
+ *
+ * Returns: @orig_framerate or better if found
+ */
+const GValue *
+gst_base_camera_src_find_better_framerate (GstBaseCameraSrc * self,
+ GstStructure * st, const GValue * orig_framerate)
+{
+ const GValue *framerate = NULL;
+ guint i, i_best, list_size;
+ gint res, comparison;
+
+ if (self->night_mode) {
+ GST_LOG_OBJECT (self, "finding min framerate in %" GST_PTR_FORMAT, st);
+ comparison = GST_VALUE_LESS_THAN;
+ } else {
+ GST_LOG_OBJECT (self, "finding max framerate in %" GST_PTR_FORMAT, st);
+ comparison = GST_VALUE_GREATER_THAN;
+ }
+
+ if (gst_structure_has_field (st, "framerate")) {
+ framerate = gst_structure_get_value (st, "framerate");
+ /* Handle framerate lists */
+ if (GST_VALUE_HOLDS_LIST (framerate)) {
+ list_size = gst_value_list_get_size (framerate);
+ GST_LOG_OBJECT (self, "finding framerate from list");
+ for (i = 0, i_best = 0; i < list_size; i++) {
+ res = gst_value_compare (gst_value_list_get_value (framerate, i),
+ gst_value_list_get_value (framerate, i_best));
+ if (comparison == res) {
+ i_best = i;
+ }
+ }
+ GST_LOG_OBJECT (self, "found best framerate from index %d", i_best);
+ framerate = gst_value_list_get_value (framerate, i_best);
+ }
+ /* Handle framerate ranges */
+ if (GST_VALUE_HOLDS_FRACTION_RANGE (framerate)) {
+ if (self->night_mode) {
+ GST_LOG_OBJECT (self, "getting min framerate from range");
+ framerate = gst_value_get_fraction_range_min (framerate);
+ } else {
+ GST_LOG_OBJECT (self, "getting max framerate from range");
+ framerate = gst_value_get_fraction_range_max (framerate);
+ }
+ }
+ }
+
+ /* Check if we found better framerate */
+ if (orig_framerate && framerate) {
+ res = gst_value_compare (orig_framerate, framerate);
+ if (comparison == res) {
+ GST_LOG_OBJECT (self, "original framerate was the best");
+ framerate = orig_framerate;
+ }
+ }
+
+ return framerate;
+}
+
+static void
+gst_base_camera_src_start_capture (GstBaseCameraSrc * src)
+{
+ GstBaseCameraSrcClass *klass = GST_BASE_CAMERA_SRC_GET_CLASS (src);
+
+ g_return_if_fail (klass->start_capture != NULL);
+
+ g_mutex_lock (src->capturing_mutex);
+ if (src->capturing) {
+ GST_WARNING_OBJECT (src, "Capturing already ongoing");
+ g_mutex_unlock (src->capturing_mutex);
+ return;
+ }
+
+ if (klass->start_capture (src)) {
+ src->capturing = TRUE;
+ g_object_notify (G_OBJECT (src), "ready-for-capture");
+ } else {
+ GST_WARNING_OBJECT (src, "Failed to start capture");
+ }
+ g_mutex_unlock (src->capturing_mutex);
+}
+
+static void
+gst_base_camera_src_stop_capture (GstBaseCameraSrc * src)
+{
+ GstBaseCameraSrcClass *klass = GST_BASE_CAMERA_SRC_GET_CLASS (src);
+
+ g_return_if_fail (klass->stop_capture != NULL);
+
+ g_mutex_lock (src->capturing_mutex);
+ if (!src->capturing) {
+ GST_DEBUG_OBJECT (src, "No ongoing capture");
+ g_mutex_unlock (src->capturing_mutex);
+ return;
+ }
+ klass->stop_capture (src);
+ g_mutex_unlock (src->capturing_mutex);
+}
+
+void
+gst_base_camera_src_finish_capture (GstBaseCameraSrc * self)
+{
+ g_return_if_fail (self->capturing);
+ self->capturing = FALSE;
+ g_object_notify (G_OBJECT (self), "ready-for-capture");
+}
+
+static void
+gst_base_camera_src_dispose (GObject * object)
+{
+ GstBaseCameraSrc *src = GST_BASE_CAMERA_SRC_CAST (object);
+
+ g_mutex_free (src->capturing_mutex);
+
+ G_OBJECT_CLASS (parent_class)->dispose (object);
+}
+
+static void
+gst_base_camera_src_finalize (GstBaseCameraSrc * self)
+{
+ G_OBJECT_CLASS (parent_class)->finalize ((GObject *) (self));
+}
+
+static void
+gst_base_camera_src_set_property (GObject * object,
+ guint prop_id, const GValue * value, GParamSpec * pspec)
+{
+ GstBaseCameraSrc *self = GST_BASE_CAMERA_SRC (object);
+
+ switch (prop_id) {
+ case PROP_MODE:
+ gst_base_camera_src_set_mode (GST_BASE_CAMERA_SRC (self),
+ g_value_get_enum (value));
+ break;
+ case PROP_ZOOM:{
+ g_atomic_int_set (&self->zoom, g_value_get_int (value));
+ /* does not set it if in NULL, the src is not created yet */
+ if (GST_STATE (self) != GST_STATE_NULL)
+ gst_base_camera_src_setup_zoom (self);
+ break;
+ }
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (self, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gst_base_camera_src_get_property (GObject * object,
+ guint prop_id, GValue * value, GParamSpec * pspec)
+{
+ GstBaseCameraSrc *self = GST_BASE_CAMERA_SRC (object);
+
+ switch (prop_id) {
+ case PROP_MODE:
+ g_value_set_enum (value, self->mode);
+ break;
+ case PROP_READY_FOR_CAPTURE:
+ g_value_set_boolean (value, !self->capturing);
+ break;
+ case PROP_ZOOM:
+ g_value_set_int (value, g_atomic_int_get (&self->zoom));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (self, prop_id, pspec);
+ break;
+ }
+}
+
+static gboolean
+construct_pipeline (GstBaseCameraSrc * self)
+{
+ GstBaseCameraSrcClass *bclass = GST_BASE_CAMERA_SRC_GET_CLASS (self);
+
+ if (bclass->construct_pipeline) {
+ if (!bclass->construct_pipeline (self)) {
+ GST_ERROR_OBJECT (self, "pipeline construction failed");
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+static gboolean
+setup_pipeline (GstBaseCameraSrc * self)
+{
+ GstBaseCameraSrcClass *bclass = GST_BASE_CAMERA_SRC_GET_CLASS (self);
+ if (bclass->setup_pipeline)
+ return bclass->setup_pipeline (self);
+ return TRUE;
+}
+
+static GstStateChangeReturn
+gst_base_camera_src_change_state (GstElement * element,
+ GstStateChange transition)
+{
+ GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
+ GstBaseCameraSrc *self = GST_BASE_CAMERA_SRC (element);
+
+ GST_DEBUG_OBJECT (self, "%d -> %d",
+ GST_STATE_TRANSITION_CURRENT (transition),
+ GST_STATE_TRANSITION_NEXT (transition));
+
+ switch (transition) {
+ case GST_STATE_CHANGE_NULL_TO_READY:
+ if (!construct_pipeline (self))
+ return GST_STATE_CHANGE_FAILURE;
+ break;
+ case GST_STATE_CHANGE_READY_TO_PAUSED:
+ if (!setup_pipeline (self))
+ return GST_STATE_CHANGE_FAILURE;
+ break;
+ default:
+ break;
+ }
+
+ ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
+
+ return ret;
+}
+
+static void
+gst_base_camera_src_base_init (gpointer g_class)
+{
+ GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
+
+ GST_DEBUG_CATEGORY_INIT (base_camera_src_debug, "base_camera_src", 0,
+ "Base camera src");
+
+ gst_element_class_set_details_simple (gstelement_class,
+ "Base class for camerabin src bin", "Source/Video",
+ "Abstracts capture device for camerabin2", "Rob Clark <rob@ti.com>");
+
+ gst_element_class_add_pad_template (gstelement_class,
+ gst_static_pad_template_get (&vfsrc_template));
+
+ gst_element_class_add_pad_template (gstelement_class,
+ gst_static_pad_template_get (&imgsrc_template));
+
+ gst_element_class_add_pad_template (gstelement_class,
+ gst_static_pad_template_get (&vidsrc_template));
+}
+
+static void
+gst_base_camera_src_class_init (GstBaseCameraSrcClass * klass)
+{
+ GObjectClass *gobject_class;
+ GstElementClass *gstelement_class;
+
+ gobject_class = G_OBJECT_CLASS (klass);
+ gstelement_class = GST_ELEMENT_CLASS (klass);
+
+ gobject_class->dispose = gst_base_camera_src_dispose;
+ gobject_class->finalize = (GObjectFinalizeFunc) gst_base_camera_src_finalize;
+ gobject_class->set_property = gst_base_camera_src_set_property;
+ gobject_class->get_property = gst_base_camera_src_get_property;
+
+ g_object_class_install_property (gobject_class, PROP_MODE,
+ g_param_spec_enum ("mode", "Mode",
+ "The capture mode (still image capture or video recording)",
+ GST_TYPE_CAMERABIN_MODE, MODE_IMAGE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ /**
+ * GstBaseCameraSrc:ready-for-capture:
+ *
+ * When TRUE new capture can be prepared. If FALSE capturing is ongoing
+ * and starting a new capture immediately is not possible.
+ *
+ * Note that calling start-capture from the notify callback of this property
+ * will cause a deadlock. If you need to react like this on the notify
+ * function, please schedule a new thread to do it. If you're using glib's
+ * mainloop you can use g_idle_add() for example.
+ */
+ g_object_class_install_property (gobject_class, PROP_READY_FOR_CAPTURE,
+ g_param_spec_boolean ("ready-for-capture", "Ready for capture",
+ "Informs this element is ready for starting another capture",
+ TRUE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+
+ /* Signals */
+ basecamerasrc_signals[START_CAPTURE_SIGNAL] =
+ g_signal_new ("start-capture",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (GstBaseCameraSrcClass, private_start_capture),
+ NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+
+ basecamerasrc_signals[STOP_CAPTURE_SIGNAL] =
+ g_signal_new ("stop-capture",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (GstBaseCameraSrcClass, private_stop_capture),
+ NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+
+ /* TODO these should be moved to a private struct
+ * that is allocated sequentially to the main struct as said at:
+ * http://library.gnome.org/devel/gobject/unstable/gobject-Type-Information.html#g-type-add-class-private
+ */
+ klass->private_start_capture = gst_base_camera_src_start_capture;
+ klass->private_stop_capture = gst_base_camera_src_stop_capture;
+
+ gstelement_class->change_state = gst_base_camera_src_change_state;
+}
+
+static void
+gst_base_camera_src_init (GstBaseCameraSrc * self,
+ GstBaseCameraSrcClass * klass)
+{
+ self->width = DEFAULT_WIDTH;
+ self->height = DEFAULT_HEIGHT;
+ self->zoom = DEFAULT_ZOOM;
+ self->image_capture_width = 0;
+ self->image_capture_height = 0;
+ self->mode = MODE_IMAGE;
+
+ self->night_mode = FALSE;
+
+ self->fps_n = DEFAULT_FPS_N;
+ self->fps_d = DEFAULT_FPS_D;
+
+ self->capturing = FALSE;
+ self->capturing_mutex = g_mutex_new ();
+}
diff --git a/gst-libs/gst/basecamerabinsrc/gstbasecamerasrc.h b/gst-libs/gst/basecamerabinsrc/gstbasecamerasrc.h
new file mode 100644
index 000000000..dd74ba81a
--- /dev/null
+++ b/gst-libs/gst/basecamerabinsrc/gstbasecamerasrc.h
@@ -0,0 +1,147 @@
+/*
+ * GStreamer
+ * Copyright (C) 2010 Texas Instruments, Inc
+ *
+ * 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_BASE_CAMERA_SRC_H__
+#define __GST_BASE_CAMERA_SRC_H__
+
+#include <gst/gst.h>
+#include <gst/gstbin.h>
+#include <gst/interfaces/photography.h>
+#include <gst/interfaces/colorbalance.h>
+#include "gstcamerabin-enum.h"
+
+G_BEGIN_DECLS
+#define GST_TYPE_BASE_CAMERA_SRC \
+ (gst_base_camera_src_get_type())
+#define GST_BASE_CAMERA_SRC(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_BASE_CAMERA_SRC,GstBaseCameraSrc))
+#define GST_BASE_CAMERA_SRC_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_BASE_CAMERA_SRC, GstBaseCameraSrcClass))
+#define GST_BASE_CAMERA_SRC_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_BASE_CAMERA_SRC,GstBaseCameraSrcClass))
+#define GST_IS_BASE_CAMERA_SRC(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BASE_CAMERA_SRC))
+#define GST_IS_BASE_CAMERA_SRC_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASE_CAMERA_SRC))
+#define GST_BASE_CAMERA_SRC_CAST(obj) \
+ ((GstBaseCameraSrc *) (obj))
+GType gst_base_camera_src_get_type (void);
+
+typedef struct _GstBaseCameraSrc GstBaseCameraSrc;
+typedef struct _GstBaseCameraSrcClass GstBaseCameraSrcClass;
+
+#define GST_BASE_CAMERA_SRC_VIEWFINDER_PAD_NAME "vfsrc"
+#define GST_BASE_CAMERA_SRC_IMAGE_PAD_NAME "imgsrc"
+#define GST_BASE_CAMERA_SRC_VIDEO_PAD_NAME "vidsrc"
+
+/**
+ * GstBaseCameraSrc:
+ */
+struct _GstBaseCameraSrc
+{
+ GstBin parent;
+
+ GstCameraBinMode mode;
+
+ gboolean capturing;
+ GMutex *capturing_mutex;
+
+ /* XXX preview pads? */
+
+ /* Resolution of the buffers configured to camerabin */
+ gint width;
+ gint height;
+
+ /* The digital zoom (from 100% to 1000%) */
+ gint zoom;
+
+ /* Image capture resolution */
+ gint image_capture_width;
+ gint image_capture_height;
+
+ /* Frames per second configured to camerabin */
+ gint fps_n;
+ gint fps_d;
+
+ /* Night mode handling */
+ gboolean night_mode;
+ gint pre_night_fps_n;
+ gint pre_night_fps_d;
+
+ gpointer _gst_reserved[GST_PADDING_LARGE];
+};
+
+
+/**
+ * GstBaseCameraSrcClass:
+ * @construct_pipeline: construct pipeline must be implemented by derived class
+ * @setup_pipeline: configure pipeline for the chosen settings
+ * @set_zoom: set the zoom
+ * @set_mode: set the mode
+ */
+struct _GstBaseCameraSrcClass
+{
+ GstBinClass parent;
+
+ /* construct pipeline must be implemented by derived class */
+ gboolean (*construct_pipeline) (GstBaseCameraSrc *self);
+
+ /* optional */
+ gboolean (*setup_pipeline) (GstBaseCameraSrc *self);
+
+ /* set the zoom */
+ void (*set_zoom) (GstBaseCameraSrc *self, gint zoom);
+
+ /* set the mode */
+ gboolean (*set_mode) (GstBaseCameraSrc *self,
+ GstCameraBinMode mode);
+
+ /* */
+ GstCaps * (*get_allowed_input_caps) (GstBaseCameraSrc * self);
+
+ void (*private_start_capture) (GstBaseCameraSrc * src);
+ void (*private_stop_capture) (GstBaseCameraSrc * src);
+ gboolean (*start_capture) (GstBaseCameraSrc * src);
+ void (*stop_capture) (GstBaseCameraSrc * src);
+
+ gpointer _gst_reserved[GST_PADDING_LARGE];
+};
+
+
+#define MIN_ZOOM 100
+#define MAX_ZOOM 1000
+#define ZOOM_1X MIN_ZOOM
+
+GstPhotography * gst_base_camera_src_get_photography (GstBaseCameraSrc *self);
+GstColorBalance * gst_base_camera_src_get_color_balance (GstBaseCameraSrc *self);
+
+gboolean gst_base_camera_src_set_mode (GstBaseCameraSrc *self, GstCameraBinMode mode);
+void gst_base_camera_src_setup_zoom (GstBaseCameraSrc * self);
+GstCaps * gst_base_camera_src_get_allowed_input_caps (GstBaseCameraSrc * self);
+const GValue * gst_base_camera_src_find_better_framerate (
+ GstBaseCameraSrc * self, GstStructure * st, const GValue * orig_framerate);
+
+void gst_base_camera_src_finish_capture (GstBaseCameraSrc *self);
+
+
+// XXX add methods to get/set img capture and vid capture caps..
+
+#endif /* __GST_BASE_CAMERA_SRC_H__ */
diff --git a/gst-libs/gst/basecamerabinsrc/gstcamerabin-enum.c b/gst-libs/gst/basecamerabinsrc/gstcamerabin-enum.c
new file mode 100644
index 000000000..ba09dcf3e
--- /dev/null
+++ b/gst-libs/gst/basecamerabinsrc/gstcamerabin-enum.c
@@ -0,0 +1,39 @@
+/*
+ * GStreamer
+ * Copyright (C) 2009 Nokia Corporation <multimedia@maemo.org>
+ *
+ * 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.
+ */
+
+#include "gstcamerabin-enum.h"
+
+GType
+gst_camerabin_mode_get_type (void)
+{
+ static GType gtype = 0;
+
+ if (gtype == 0) {
+ static const GEnumValue values[] = {
+ /* {MODE_PREVIEW, "Preview mode (should be default?)", "mode-preview"}, */
+ {MODE_IMAGE, "Still image capture (default)", "mode-image"},
+ {MODE_VIDEO, "Video recording", "mode-video"},
+ {0, NULL, NULL}
+ };
+
+ gtype = g_enum_register_static ("GstCameraBin2Mode", values);
+ }
+ return gtype;
+}
diff --git a/gst-libs/gst/basecamerabinsrc/gstcamerabin-enum.h b/gst-libs/gst/basecamerabinsrc/gstcamerabin-enum.h
new file mode 100644
index 000000000..590cb6882
--- /dev/null
+++ b/gst-libs/gst/basecamerabinsrc/gstcamerabin-enum.h
@@ -0,0 +1,57 @@
+/*
+ * GStreamer
+ * Copyright (C) 2009 Nokia Corporation <multimedia@maemo.org>
+ *
+ * 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_CAMERABIN_ENUM_H__
+#define __GST_CAMERABIN_ENUM_H__
+
+#include <gst/gst.h>
+
+G_BEGIN_DECLS
+
+#define DEFAULT_WIDTH 640
+#define DEFAULT_HEIGHT 480
+#define DEFAULT_CAPTURE_WIDTH 800
+#define DEFAULT_CAPTURE_HEIGHT 600
+#define DEFAULT_FPS_N 0 /* makes it use the default */
+#define DEFAULT_FPS_D 1
+#define DEFAULT_ZOOM MIN_ZOOM
+
+
+/**
+ * GstCameraBinMode:
+ * @MODE_IMAGE: image capture
+ * @MODE_VIDEO: video capture
+ *
+ * Capture mode to use.
+ */
+typedef enum
+{
+ /* MODE_PREVIEW = 0, No use for this */
+ MODE_IMAGE = 1,
+ MODE_VIDEO = 2,
+} GstCameraBinMode;
+
+
+#define GST_TYPE_CAMERABIN_MODE (gst_camerabin_mode_get_type ())
+GType gst_camerabin_mode_get_type (void);
+
+G_END_DECLS
+
+#endif /* #ifndef __GST_CAMERABIN_ENUM_H__ */