mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-23 23:58:17 +00:00
Add camerabin element.
This commit is contained in:
parent
f081d3e7b6
commit
3751eaeb79
17 changed files with 5393 additions and 0 deletions
|
@ -239,6 +239,7 @@ dnl these are all the gst plug-ins, compilable without additional libs
|
||||||
AG_GST_CHECK_PLUGIN(aacparse)
|
AG_GST_CHECK_PLUGIN(aacparse)
|
||||||
AG_GST_CHECK_PLUGIN(aiffparse)
|
AG_GST_CHECK_PLUGIN(aiffparse)
|
||||||
AG_GST_CHECK_PLUGIN(amrparse)
|
AG_GST_CHECK_PLUGIN(amrparse)
|
||||||
|
AG_GST_CHECK_PLUGIN(camerabin)
|
||||||
AG_GST_CHECK_PLUGIN(legacyresample)
|
AG_GST_CHECK_PLUGIN(legacyresample)
|
||||||
AG_GST_CHECK_PLUGIN(bayer)
|
AG_GST_CHECK_PLUGIN(bayer)
|
||||||
AG_GST_CHECK_PLUGIN(cdxaparse)
|
AG_GST_CHECK_PLUGIN(cdxaparse)
|
||||||
|
@ -1412,6 +1413,7 @@ gst/aiffparse/Makefile
|
||||||
gst/amrparse/Makefile
|
gst/amrparse/Makefile
|
||||||
gst/legacyresample/Makefile
|
gst/legacyresample/Makefile
|
||||||
gst/bayer/Makefile
|
gst/bayer/Makefile
|
||||||
|
gst/camerabin/Makefile
|
||||||
gst/cdxaparse/Makefile
|
gst/cdxaparse/Makefile
|
||||||
gst/dccp/Makefile
|
gst/dccp/Makefile
|
||||||
gst/deinterlace/Makefile
|
gst/deinterlace/Makefile
|
||||||
|
|
46
gst/camerabin/Makefile.am
Normal file
46
gst/camerabin/Makefile.am
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
glib_enum_prefix = gst_camerabin
|
||||||
|
|
||||||
|
include $(top_srcdir)/common/glib-gen.mak
|
||||||
|
|
||||||
|
built_sources = gstcamerabin-marshal.c
|
||||||
|
built_headers = gstcamerabin-marshal.h
|
||||||
|
|
||||||
|
BUILT_SOURCES = $(built_sources) $(built_headers)
|
||||||
|
|
||||||
|
CLEANFILES = $(BUILT_SOURCES)
|
||||||
|
|
||||||
|
EXTRA_DIST = gstcamerabin-marshal.list
|
||||||
|
|
||||||
|
plugin_LTLIBRARIES = libgstcamerabin.la
|
||||||
|
|
||||||
|
libgstcamerabin_la_SOURCES = gstcamerabin.c \
|
||||||
|
gstcamerabinxoverlay.c \
|
||||||
|
gstcamerabincolorbalance.c \
|
||||||
|
camerabinimage.c \
|
||||||
|
camerabinvideo.c \
|
||||||
|
camerabingeneral.c \
|
||||||
|
gstcamerabinphotography.c
|
||||||
|
|
||||||
|
nodist_libgstcamerabin_la_SOURCES = $(built_sources)
|
||||||
|
|
||||||
|
# libcamerabin_ladir = $(includedir)/gstreamer-@GST_MAJORMINOR@/camerabin
|
||||||
|
|
||||||
|
# libcamerabin_la_HEADERS = gstcamerabin.h
|
||||||
|
|
||||||
|
libgstcamerabin_la_CFLAGS = $(GST_CFLAGS) $(GST_BASE_CFLAGS)
|
||||||
|
|
||||||
|
libgstcamerabin_la_LIBADD = $(GST_LIBS) $(GST_BASE_LIBS) \
|
||||||
|
-lgstinterfaces-$(GST_MAJORMINOR) \
|
||||||
|
$(top_builddir)/gst-libs/gst/interfaces/libgstphotography-$(GST_MAJORMINOR).la
|
||||||
|
|
||||||
|
libgstcamerabin_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
|
||||||
|
libgstcamerabin__la_LIBTOOLFLAGS = --tag=disable-static
|
||||||
|
|
||||||
|
noinst_HEADERS = gstcamerabin.h \
|
||||||
|
gstcamerabinxoverlay.h \
|
||||||
|
gstcamerabincolorbalance.h \
|
||||||
|
camerabinimage.h \
|
||||||
|
camerabinvideo.h \
|
||||||
|
camerabingeneral.h \
|
||||||
|
gstcamerabinphotography.h \
|
||||||
|
$(built_headers)
|
262
gst/camerabin/camerabingeneral.c
Normal file
262
gst/camerabin/camerabingeneral.c
Normal file
|
@ -0,0 +1,262 @@
|
||||||
|
/*
|
||||||
|
* GStreamer
|
||||||
|
* Copyright (C) 2008 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SECTION:camerabingeneral
|
||||||
|
* @short_description: helper functions for #GstCameraBin and it's modules
|
||||||
|
*
|
||||||
|
* Common helper functions for #GstCameraBin, #GstCameraBinImage and
|
||||||
|
* #GstCameraBinVideo.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "camerabingeneral.h"
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
GST_DEBUG_CATEGORY (gst_camerabin_debug);
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
camerabin_general_dbg_have_event (GstPad * pad, GstEvent * event,
|
||||||
|
gpointer u_data)
|
||||||
|
{
|
||||||
|
switch (GST_EVENT_TYPE (event)) {
|
||||||
|
case GST_EVENT_NEWSEGMENT:
|
||||||
|
{
|
||||||
|
GstElement *elem = (GstElement *) u_data;
|
||||||
|
gchar *elem_name = gst_element_get_name (elem);
|
||||||
|
gchar *pad_name = gst_pad_get_name (pad);
|
||||||
|
|
||||||
|
gboolean update;
|
||||||
|
gdouble rate;
|
||||||
|
GstFormat format;
|
||||||
|
gint64 start, stop, pos;
|
||||||
|
gst_event_parse_new_segment (event, &update, &rate, &format, &start,
|
||||||
|
&stop, &pos);
|
||||||
|
|
||||||
|
GST_DEBUG ("element %s, pad %s, new_seg_start =%" GST_TIME_FORMAT
|
||||||
|
", new_seg_stop =%" GST_TIME_FORMAT
|
||||||
|
", new_seg_pos =%" GST_TIME_FORMAT "\n", elem_name, pad_name,
|
||||||
|
GST_TIME_ARGS (start), GST_TIME_ARGS (stop), GST_TIME_ARGS (pos));
|
||||||
|
|
||||||
|
g_free (pad_name);
|
||||||
|
g_free (elem_name);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
camerabin_general_dbg_have_buffer (GstPad * pad, GstBuffer * buffer,
|
||||||
|
gpointer u_data)
|
||||||
|
{
|
||||||
|
GstElement *elem = (GstElement *) u_data;
|
||||||
|
gchar *elem_name = gst_element_get_name (elem);
|
||||||
|
gchar *pad_name = gst_pad_get_name (pad);
|
||||||
|
|
||||||
|
GST_DEBUG ("element %s, pad %s, buf_ts =%" GST_TIME_FORMAT "\n", elem_name,
|
||||||
|
pad_name, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)));
|
||||||
|
|
||||||
|
g_free (pad_name);
|
||||||
|
g_free (elem_name);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
camerabin_general_dbg_set_probe (GstElement * elem, gchar * pad_name,
|
||||||
|
gboolean buf, gboolean evt)
|
||||||
|
{
|
||||||
|
GstPad *pad = gst_element_get_static_pad (elem, pad_name);
|
||||||
|
|
||||||
|
if (buf)
|
||||||
|
gst_pad_add_buffer_probe (pad,
|
||||||
|
G_CALLBACK (camerabin_general_dbg_have_buffer), elem);
|
||||||
|
if (evt)
|
||||||
|
gst_pad_add_event_probe (pad,
|
||||||
|
G_CALLBACK (camerabin_general_dbg_have_event), elem);
|
||||||
|
|
||||||
|
gst_object_unref (pad);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_camerabin_add_element:
|
||||||
|
* @bin: add an element to this bin
|
||||||
|
* @new_elem: new element to be added
|
||||||
|
*
|
||||||
|
* Adds given element to given @bin. Looks for an unconnected src pad
|
||||||
|
* from the @bin and links the element to it. Raises an error if adding
|
||||||
|
* or linking failed.
|
||||||
|
*
|
||||||
|
* Returns: %TRUE if adding and linking succeeded, %FALSE otherwise.
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
gst_camerabin_add_element (GstBin * bin, GstElement * new_elem)
|
||||||
|
{
|
||||||
|
gboolean ret = FALSE;
|
||||||
|
|
||||||
|
ret = gst_camerabin_try_add_element (bin, new_elem);
|
||||||
|
|
||||||
|
if (!ret) {
|
||||||
|
gchar *elem_name = gst_element_get_name (new_elem);
|
||||||
|
GST_ELEMENT_ERROR (bin, CORE, NEGOTIATION, (NULL),
|
||||||
|
("linking %s failed", elem_name));
|
||||||
|
g_free (elem_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_camerabin_try_add_element:
|
||||||
|
* @bin: tries adding an element to this bin
|
||||||
|
* @new_elem: new element to be added
|
||||||
|
*
|
||||||
|
* Adds given element to given @bin. Looks for an unconnected src pad
|
||||||
|
* from the @bin and links the element to it.
|
||||||
|
*
|
||||||
|
* Returns: %TRUE if adding and linking succeeded, %FALSE otherwise.
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
gst_camerabin_try_add_element (GstBin * bin, GstElement * new_elem)
|
||||||
|
{
|
||||||
|
GstPad *bin_pad;
|
||||||
|
GstElement *bin_elem;
|
||||||
|
gboolean ret = TRUE;
|
||||||
|
|
||||||
|
if (!bin || !new_elem) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get pads for linking */
|
||||||
|
GST_DEBUG ("finding unconnected src pad");
|
||||||
|
bin_pad = gst_bin_find_unlinked_pad (bin, GST_PAD_SRC);
|
||||||
|
GST_DEBUG ("unconnected pad %s:%s", GST_DEBUG_PAD_NAME (bin_pad));
|
||||||
|
/* Add to bin */
|
||||||
|
gst_bin_add (GST_BIN (bin), new_elem);
|
||||||
|
/* Link, if unconnected pad was found, otherwise just add it to bin */
|
||||||
|
if (bin_pad) {
|
||||||
|
bin_elem = gst_pad_get_parent_element (bin_pad);
|
||||||
|
gst_object_unref (bin_pad);
|
||||||
|
if (!gst_element_link (bin_elem, new_elem)) {
|
||||||
|
gst_bin_remove (bin, new_elem);
|
||||||
|
ret = FALSE;
|
||||||
|
}
|
||||||
|
gst_object_unref (bin_elem);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_camerabin_create_and_add_element:
|
||||||
|
* @bin: tries adding an element to this bin
|
||||||
|
* @elem_name: name of the element to be created
|
||||||
|
*
|
||||||
|
* Creates an element according to given name and
|
||||||
|
* adds it to given @bin. Looks for an unconnected src pad
|
||||||
|
* from the @bin and links the element to it.
|
||||||
|
*
|
||||||
|
* Returns: pointer to the new element if successful, NULL otherwise.
|
||||||
|
*/
|
||||||
|
GstElement *
|
||||||
|
gst_camerabin_create_and_add_element (GstBin * bin, const gchar * elem_name)
|
||||||
|
{
|
||||||
|
GstElement *new_elem = NULL;
|
||||||
|
|
||||||
|
GST_DEBUG ("adding %s", elem_name);
|
||||||
|
new_elem = gst_element_factory_make (elem_name, NULL);
|
||||||
|
if (!new_elem) {
|
||||||
|
GST_ELEMENT_ERROR (bin, CORE, MISSING_PLUGIN, (NULL),
|
||||||
|
("could not create \"%s\" element.", elem_name));
|
||||||
|
} else if (!gst_camerabin_add_element (bin, new_elem)) {
|
||||||
|
new_elem = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new_elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_camerabin_remove_elements_from_bin:
|
||||||
|
* @bin: removes all elements from this bin
|
||||||
|
*
|
||||||
|
* Removes all elements from this @bin.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
gst_camerabin_remove_elements_from_bin (GstBin * bin)
|
||||||
|
{
|
||||||
|
GstIterator *iter = NULL;
|
||||||
|
gpointer data = NULL;
|
||||||
|
GstElement *elem = NULL;
|
||||||
|
gboolean done = FALSE;
|
||||||
|
|
||||||
|
iter = gst_bin_iterate_elements (bin);
|
||||||
|
while (!done) {
|
||||||
|
switch (gst_iterator_next (iter, &data)) {
|
||||||
|
case GST_ITERATOR_OK:
|
||||||
|
elem = GST_ELEMENT (data);
|
||||||
|
gst_bin_remove (bin, elem);
|
||||||
|
/* Iterator increased the element refcount, so unref */
|
||||||
|
gst_object_unref (elem);
|
||||||
|
break;
|
||||||
|
case GST_ITERATOR_RESYNC:
|
||||||
|
gst_iterator_resync (iter);
|
||||||
|
break;
|
||||||
|
case GST_ITERATOR_ERROR:
|
||||||
|
GST_WARNING_OBJECT (bin, "error in iterating elements");
|
||||||
|
done = TRUE;
|
||||||
|
break;
|
||||||
|
case GST_ITERATOR_DONE:
|
||||||
|
done = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gst_iterator_free (iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_camerabin_drop_eos_probe:
|
||||||
|
* @pad: pad receiving the event
|
||||||
|
* @event: received event
|
||||||
|
* @u_data: not used
|
||||||
|
*
|
||||||
|
* Event probe that drop all eos events.
|
||||||
|
*
|
||||||
|
* Returns: FALSE to drop the event, TRUE otherwise
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
gst_camerabin_drop_eos_probe (GstPad * pad, GstEvent * event, gpointer u_data)
|
||||||
|
{
|
||||||
|
gboolean ret = TRUE;
|
||||||
|
|
||||||
|
switch (GST_EVENT_TYPE (event)) {
|
||||||
|
case GST_EVENT_EOS:
|
||||||
|
GST_DEBUG ("dropping eos in %s:%s", GST_DEBUG_PAD_NAME (pad));
|
||||||
|
ret = FALSE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
62
gst/camerabin/camerabingeneral.h
Normal file
62
gst/camerabin/camerabingeneral.h
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* GStreamer
|
||||||
|
* Copyright (C) 2008 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 __CAMERABIN_GENERAL_H_
|
||||||
|
#define __CAMERABIN_GENERAL_H_
|
||||||
|
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include <gst/gst.h>
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct timeval TIME_TYPE;
|
||||||
|
#define GET_TIME(t) do { gettimeofday(&(t), NULL); } while(0)
|
||||||
|
#define DIFF_TIME(t2,t1,d) do { d = ((t2).tv_sec - (t1).tv_sec) * 1000000 + \
|
||||||
|
(t2).tv_usec - (t1).tv_usec; } while(0)
|
||||||
|
|
||||||
|
#define _INIT_TIMER_BLOCK TIME_TYPE t1, t2; guint32 d; do {;}while (0)
|
||||||
|
|
||||||
|
#define _OPEN_TIMER_BLOCK { GET_TIME(t1); do {;}while (0)
|
||||||
|
#define _CLOSE_TIMER_BLOCK GET_TIME(t2); DIFF_TIME(t2,t1,d); \
|
||||||
|
GST_DEBUG("elapsed time = %u\n", d); \
|
||||||
|
} do {;}while (0)
|
||||||
|
|
||||||
|
|
||||||
|
extern void
|
||||||
|
camerabin_general_dbg_set_probe (GstElement * elem, gchar * pad_name,
|
||||||
|
gboolean buf, gboolean evt);
|
||||||
|
|
||||||
|
gboolean gst_camerabin_try_add_element (GstBin * bin, GstElement * new_elem);
|
||||||
|
|
||||||
|
gboolean gst_camerabin_add_element (GstBin * bin, GstElement * new_elem);
|
||||||
|
|
||||||
|
GstElement *gst_camerabin_create_and_add_element (GstBin * bin,
|
||||||
|
const gchar * elem_name);
|
||||||
|
|
||||||
|
void gst_camerabin_remove_elements_from_bin (GstBin * bin);
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
gst_camerabin_drop_eos_probe (GstPad * pad, GstEvent * event, gpointer u_data);
|
||||||
|
|
||||||
|
GST_DEBUG_CATEGORY_EXTERN (gst_camerabin_debug);
|
||||||
|
#define GST_CAT_DEFAULT gst_camerabin_debug
|
||||||
|
|
||||||
|
#endif /* #ifndef __CAMERABIN_GENERAL_H_ */
|
571
gst/camerabin/camerabinimage.c
Normal file
571
gst/camerabin/camerabinimage.c
Normal file
|
@ -0,0 +1,571 @@
|
||||||
|
/*
|
||||||
|
* GStreamer
|
||||||
|
* Copyright (C) 2008 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SECTION:camerabinimage
|
||||||
|
* @short_description: image capturing module of #GstCameraBin
|
||||||
|
*
|
||||||
|
* <refsect2>
|
||||||
|
* <para>
|
||||||
|
*
|
||||||
|
* The pipeline for this module is:
|
||||||
|
*
|
||||||
|
* <informalexample>
|
||||||
|
* <programlisting>
|
||||||
|
*-----------------------------------------------------------------------------
|
||||||
|
* (src0) -> queue ->
|
||||||
|
* -> [post proc] -> tee <
|
||||||
|
* (src1) -> imageenc -> metadatamuxer -> filesink
|
||||||
|
*-----------------------------------------------------------------------------
|
||||||
|
* </programlisting>
|
||||||
|
* </informalexample>
|
||||||
|
*
|
||||||
|
* The property of elements are:
|
||||||
|
*
|
||||||
|
* queue - "max-size-buffers", 1, "leaky", 2,
|
||||||
|
*
|
||||||
|
* The image bin opens file for image writing in READY to PAUSED state change.
|
||||||
|
* The image bin closes the file in PAUSED to READY state change.
|
||||||
|
*
|
||||||
|
* </para>
|
||||||
|
* </refsect2>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* includes
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <gst/gst.h>
|
||||||
|
|
||||||
|
#include "camerabinimage.h"
|
||||||
|
#include "camerabingeneral.h"
|
||||||
|
|
||||||
|
#include "string.h"
|
||||||
|
|
||||||
|
/* default internal element names */
|
||||||
|
|
||||||
|
#define DEFAULT_SINK "filesink"
|
||||||
|
#define DEFAULT_ENC "jpegenc"
|
||||||
|
#define DEFAULT_META_MUX "metadatamux"
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
PROP_0,
|
||||||
|
PROP_FILENAME
|
||||||
|
};
|
||||||
|
|
||||||
|
static gboolean gst_camerabin_image_create_elements (GstCameraBinImage * img);
|
||||||
|
static void gst_camerabin_image_destroy_elements (GstCameraBinImage * img);
|
||||||
|
|
||||||
|
static void gst_camerabin_image_dispose (GstCameraBinImage * sink);
|
||||||
|
static GstStateChangeReturn
|
||||||
|
gst_camerabin_image_change_state (GstElement * element,
|
||||||
|
GstStateChange transition);
|
||||||
|
static gboolean gst_camerabin_image_send_event (GstElement * element,
|
||||||
|
GstEvent * event);
|
||||||
|
static void gst_camerabin_image_set_property (GObject * object, guint prop_id,
|
||||||
|
const GValue * value, GParamSpec * pspec);
|
||||||
|
static void gst_camerabin_image_get_property (GObject * object, guint prop_id,
|
||||||
|
GValue * value, GParamSpec * pspec);
|
||||||
|
|
||||||
|
GST_BOILERPLATE (GstCameraBinImage, gst_camerabin_image, GstBin, GST_TYPE_BIN);
|
||||||
|
|
||||||
|
static const GstElementDetails gst_camerabin_image_details =
|
||||||
|
GST_ELEMENT_DETAILS ("Image capture bin for camerabin",
|
||||||
|
"Bin/Image",
|
||||||
|
"Process and store image data",
|
||||||
|
"Edgard Lima <edgard.lima@indt.org.br>\n"
|
||||||
|
"Nokia Corporation <multimedia@maemo.org>");
|
||||||
|
|
||||||
|
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||||
|
GST_PAD_SINK,
|
||||||
|
GST_PAD_ALWAYS,
|
||||||
|
GST_STATIC_CAPS_ANY);
|
||||||
|
|
||||||
|
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
|
||||||
|
GST_PAD_SRC,
|
||||||
|
GST_PAD_ALWAYS,
|
||||||
|
GST_STATIC_CAPS_ANY);
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_camerabin_image_base_init (gpointer klass)
|
||||||
|
{
|
||||||
|
GstElementClass *eklass = GST_ELEMENT_CLASS (klass);
|
||||||
|
|
||||||
|
gst_element_class_add_pad_template (eklass,
|
||||||
|
gst_static_pad_template_get (&sink_template));
|
||||||
|
gst_element_class_add_pad_template (eklass,
|
||||||
|
gst_static_pad_template_get (&src_template));
|
||||||
|
gst_element_class_set_details (eklass, &gst_camerabin_image_details);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_camerabin_image_class_init (GstCameraBinImageClass * klass)
|
||||||
|
{
|
||||||
|
GObjectClass *gobject_class;
|
||||||
|
GstElementClass *eklass = GST_ELEMENT_CLASS (klass);
|
||||||
|
|
||||||
|
gobject_class = G_OBJECT_CLASS (klass);
|
||||||
|
gobject_class->dispose =
|
||||||
|
(GObjectFinalizeFunc) GST_DEBUG_FUNCPTR (gst_camerabin_image_dispose);
|
||||||
|
eklass->change_state = GST_DEBUG_FUNCPTR (gst_camerabin_image_change_state);
|
||||||
|
eklass->send_event = GST_DEBUG_FUNCPTR (gst_camerabin_image_send_event);
|
||||||
|
|
||||||
|
gobject_class->set_property =
|
||||||
|
GST_DEBUG_FUNCPTR (gst_camerabin_image_set_property);
|
||||||
|
gobject_class->get_property =
|
||||||
|
GST_DEBUG_FUNCPTR (gst_camerabin_image_get_property);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GstCameraBinImage:filename
|
||||||
|
*
|
||||||
|
* This property can be used to specify the filename of the image.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
g_object_class_install_property (gobject_class, PROP_FILENAME,
|
||||||
|
g_param_spec_string ("filename", "Filename",
|
||||||
|
"Filename of the image to save", NULL, G_PARAM_READWRITE));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_camerabin_image_init (GstCameraBinImage * img,
|
||||||
|
GstCameraBinImageClass * g_class)
|
||||||
|
{
|
||||||
|
img->filename = g_string_new ("");
|
||||||
|
|
||||||
|
img->pad_tee_enc = NULL;
|
||||||
|
img->pad_tee_view = NULL;
|
||||||
|
|
||||||
|
img->post = NULL;
|
||||||
|
img->tee = NULL;
|
||||||
|
img->enc = NULL;
|
||||||
|
img->user_enc = NULL;
|
||||||
|
img->meta_mux = NULL;
|
||||||
|
img->sink = NULL;
|
||||||
|
img->queue = NULL;
|
||||||
|
|
||||||
|
/* Create src and sink ghost pads */
|
||||||
|
img->sinkpad = gst_ghost_pad_new_no_target ("sink", GST_PAD_SINK);
|
||||||
|
gst_element_add_pad (GST_ELEMENT (img), img->sinkpad);
|
||||||
|
|
||||||
|
img->srcpad = gst_ghost_pad_new_no_target ("src", GST_PAD_SRC);
|
||||||
|
gst_element_add_pad (GST_ELEMENT (img), img->srcpad);
|
||||||
|
|
||||||
|
img->elements_created = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_camerabin_image_dispose (GstCameraBinImage * img)
|
||||||
|
{
|
||||||
|
g_string_free (img->filename, TRUE);
|
||||||
|
img->filename = NULL;
|
||||||
|
|
||||||
|
if (img->user_enc) {
|
||||||
|
gst_object_unref (img->user_enc);
|
||||||
|
img->user_enc = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (img->post) {
|
||||||
|
gst_object_unref (img->post);
|
||||||
|
img->post = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (parent_class)->dispose ((GObject *) img);
|
||||||
|
}
|
||||||
|
|
||||||
|
static GstStateChangeReturn
|
||||||
|
gst_camerabin_image_change_state (GstElement * element,
|
||||||
|
GstStateChange transition)
|
||||||
|
{
|
||||||
|
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
||||||
|
GstCameraBinImage *img = GST_CAMERABIN_IMAGE (element);
|
||||||
|
|
||||||
|
switch (transition) {
|
||||||
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
||||||
|
if (!gst_camerabin_image_create_elements (img)) {
|
||||||
|
return GST_STATE_CHANGE_FAILURE;
|
||||||
|
}
|
||||||
|
/* Allow setting filename when image bin in READY state */
|
||||||
|
gst_element_set_locked_state (img->sink, TRUE);
|
||||||
|
break;
|
||||||
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
||||||
|
gst_element_set_locked_state (img->sink, FALSE);
|
||||||
|
break;
|
||||||
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
||||||
|
/* Set sink to NULL in order to write the file _now_ */
|
||||||
|
GST_INFO ("write img file: %s", img->filename->str);
|
||||||
|
gst_element_set_locked_state (img->sink, TRUE);
|
||||||
|
gst_element_set_state (img->sink, GST_STATE_NULL);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
||||||
|
|
||||||
|
switch (transition) {
|
||||||
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
||||||
|
gst_camerabin_image_destroy_elements (img);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
gst_camerabin_image_send_event (GstElement * element, GstEvent * event)
|
||||||
|
{
|
||||||
|
GstCameraBinImage *bin = GST_CAMERABIN_IMAGE (element);
|
||||||
|
gboolean ret = FALSE;
|
||||||
|
|
||||||
|
GST_INFO ("got %s event", GST_EVENT_TYPE_NAME (event));
|
||||||
|
|
||||||
|
if (GST_EVENT_IS_DOWNSTREAM (event)) {
|
||||||
|
ret = gst_pad_send_event (bin->sinkpad, event);
|
||||||
|
} else {
|
||||||
|
if (bin->sink) {
|
||||||
|
ret = gst_element_send_event (bin->sink, event);
|
||||||
|
} else {
|
||||||
|
GST_WARNING ("upstream event handling failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_camerabin_image_set_property (GObject * object, guint prop_id,
|
||||||
|
const GValue * value, GParamSpec * pspec)
|
||||||
|
{
|
||||||
|
GstCameraBinImage *bin = GST_CAMERABIN_IMAGE (object);
|
||||||
|
|
||||||
|
switch (prop_id) {
|
||||||
|
case PROP_FILENAME:
|
||||||
|
g_string_assign (bin->filename, g_value_get_string (value));
|
||||||
|
if (bin->sink) {
|
||||||
|
g_object_set (G_OBJECT (bin->sink), "location", bin->filename->str,
|
||||||
|
NULL);
|
||||||
|
} else {
|
||||||
|
GST_INFO ("no sink, not setting name yet");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_camerabin_image_get_property (GObject * object, guint prop_id,
|
||||||
|
GValue * value, GParamSpec * pspec)
|
||||||
|
{
|
||||||
|
GstCameraBinImage *bin = GST_CAMERABIN_IMAGE (object);
|
||||||
|
|
||||||
|
switch (prop_id) {
|
||||||
|
case PROP_FILENAME:
|
||||||
|
g_value_set_string (value, bin->filename->str);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* static helper functions implementation
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* metadata_write_probe:
|
||||||
|
* @pad: sink pad of metadata muxer
|
||||||
|
* @buffer: received buffer
|
||||||
|
* @u_data: image bin object
|
||||||
|
*
|
||||||
|
* Buffer probe that sets Xmp.dc.type and Xmp.dc.format tags
|
||||||
|
* to metadata muxer based on preceding element src pad caps.
|
||||||
|
*
|
||||||
|
* Returns: TRUE always
|
||||||
|
*/
|
||||||
|
static gboolean
|
||||||
|
metadata_write_probe (GstPad * pad, GstBuffer * buffer, gpointer u_data)
|
||||||
|
{
|
||||||
|
/* Add XMP tags */
|
||||||
|
GstCameraBinImage *img = NULL;
|
||||||
|
GstTagSetter *setter = NULL;
|
||||||
|
GstPad *srcpad = NULL;
|
||||||
|
GstCaps *caps = NULL;
|
||||||
|
GstStructure *st = NULL;
|
||||||
|
|
||||||
|
img = GST_CAMERABIN_IMAGE (u_data);
|
||||||
|
|
||||||
|
g_return_val_if_fail (img != NULL, TRUE);
|
||||||
|
|
||||||
|
setter = GST_TAG_SETTER (img->meta_mux);
|
||||||
|
|
||||||
|
if (!setter) {
|
||||||
|
GST_WARNING_OBJECT (img, "setting tags failed");
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Xmp.dc.type tag */
|
||||||
|
gst_tag_setter_add_tags (setter, GST_TAG_MERGE_REPLACE,
|
||||||
|
GST_TAG_CODEC, "Image", NULL);
|
||||||
|
/* Xmp.dc.format tag */
|
||||||
|
if (img->enc) {
|
||||||
|
srcpad = gst_element_get_static_pad (img->enc, "src");
|
||||||
|
}
|
||||||
|
GST_LOG_OBJECT (img, "srcpad:%" GST_PTR_FORMAT, srcpad);
|
||||||
|
if (srcpad) {
|
||||||
|
caps = gst_pad_get_negotiated_caps (srcpad);
|
||||||
|
GST_LOG_OBJECT (img, "caps:%" GST_PTR_FORMAT, caps);
|
||||||
|
if (caps) {
|
||||||
|
/* If there are many structures, we can't know which one to use */
|
||||||
|
if (gst_caps_get_size (caps) != 1) {
|
||||||
|
GST_WARNING_OBJECT (img, "can't decide structure for format tag");
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
st = gst_caps_get_structure (caps, 0);
|
||||||
|
if (st) {
|
||||||
|
GST_DEBUG_OBJECT (img, "Xmp.dc.format:%s", gst_structure_get_name (st));
|
||||||
|
gst_tag_setter_add_tags (setter, GST_TAG_MERGE_REPLACE,
|
||||||
|
GST_TAG_VIDEO_CODEC, gst_structure_get_name (st), NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
done:
|
||||||
|
if (caps)
|
||||||
|
gst_caps_unref (caps);
|
||||||
|
if (srcpad)
|
||||||
|
gst_object_unref (srcpad);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_camerabin_image_create_elements:
|
||||||
|
* @img: a pointer to #GstCameraBinImage object
|
||||||
|
*
|
||||||
|
* This function creates needed #GstElements and resources to capture images.
|
||||||
|
* Use gst_camerabin_image_destroy_elements to release these resources.
|
||||||
|
*
|
||||||
|
* Image bin:
|
||||||
|
* img->sinkpad ! [ post process !] tee name=t0 ! encoder ! metadata ! filesink
|
||||||
|
* t0. ! queue ! img->srcpad
|
||||||
|
*
|
||||||
|
* Returns: %TRUE if succeeded or FALSE if failed
|
||||||
|
*/
|
||||||
|
static gboolean
|
||||||
|
gst_camerabin_image_create_elements (GstCameraBinImage * img)
|
||||||
|
{
|
||||||
|
GstPad *sinkpad = NULL, *img_sinkpad = NULL, *img_srcpad = NULL;
|
||||||
|
gboolean ret = FALSE;
|
||||||
|
GstBin *imgbin = NULL;
|
||||||
|
|
||||||
|
g_return_val_if_fail (img != NULL, FALSE);
|
||||||
|
|
||||||
|
GST_DEBUG ("creating image capture elements");
|
||||||
|
|
||||||
|
imgbin = GST_BIN (img);
|
||||||
|
|
||||||
|
if (img->elements_created) {
|
||||||
|
GST_WARNING ("elements already created");
|
||||||
|
ret = TRUE;
|
||||||
|
goto done;
|
||||||
|
} else {
|
||||||
|
img->elements_created = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create image pre/post-processing element if any */
|
||||||
|
if (img->post) {
|
||||||
|
if (!gst_camerabin_add_element (imgbin, img->post)) {
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
img_sinkpad = gst_element_get_static_pad (img->post, "sink");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create tee */
|
||||||
|
if (!(img->tee = gst_camerabin_create_and_add_element (imgbin, "tee"))) {
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set up sink ghost pad for img bin */
|
||||||
|
if (!img_sinkpad) {
|
||||||
|
img_sinkpad = gst_element_get_static_pad (img->tee, "sink");
|
||||||
|
}
|
||||||
|
gst_ghost_pad_set_target (GST_GHOST_PAD (img->sinkpad), img_sinkpad);
|
||||||
|
|
||||||
|
/* Add colorspace converter */
|
||||||
|
img->pad_tee_enc = gst_element_get_request_pad (img->tee, "src%d");
|
||||||
|
if (!gst_camerabin_create_and_add_element (imgbin, "ffmpegcolorspace")) {
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create image encoder */
|
||||||
|
if (img->user_enc) {
|
||||||
|
img->enc = img->user_enc;
|
||||||
|
if (!gst_camerabin_add_element (imgbin, img->enc)) {
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
} else if (!(img->enc =
|
||||||
|
gst_camerabin_create_and_add_element (imgbin, DEFAULT_ENC))) {
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create metadata element */
|
||||||
|
if (!(img->meta_mux =
|
||||||
|
gst_camerabin_create_and_add_element (imgbin, DEFAULT_META_MUX))) {
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
/* Add probe for XMP metadata writing */
|
||||||
|
sinkpad = gst_element_get_static_pad (img->meta_mux, "sink");
|
||||||
|
gst_pad_add_buffer_probe (sinkpad, G_CALLBACK (metadata_write_probe), img);
|
||||||
|
gst_object_unref (sinkpad);
|
||||||
|
/* Set "Intel" exif byte-order if possible */
|
||||||
|
if (g_object_class_find_property (G_OBJECT_GET_CLASS (img->meta_mux),
|
||||||
|
"exif-byte-order")) {
|
||||||
|
g_object_set (G_OBJECT (img->meta_mux), "exif-byte-order", 1, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create file sink element */
|
||||||
|
if (!(img->sink =
|
||||||
|
gst_camerabin_create_and_add_element (imgbin, DEFAULT_SINK))) {
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create queue element leading to view finder, attaches it to the tee */
|
||||||
|
img->pad_tee_view = gst_element_get_request_pad (img->tee, "src%d");
|
||||||
|
if (!(img->queue = gst_camerabin_create_and_add_element (imgbin, "queue"))) {
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set properties */
|
||||||
|
g_object_set (G_OBJECT (img->sink), "location", img->filename->str, NULL);
|
||||||
|
g_object_set (G_OBJECT (img->sink), "async", FALSE, NULL);
|
||||||
|
|
||||||
|
g_object_set (G_OBJECT (img->queue), "max-size-buffers", 1, "leaky", 2, NULL);
|
||||||
|
|
||||||
|
/* Set up src ghost pad for img bin */
|
||||||
|
img_srcpad = gst_element_get_static_pad (img->queue, "src");
|
||||||
|
gst_ghost_pad_set_target (GST_GHOST_PAD (img->srcpad), img_srcpad);
|
||||||
|
|
||||||
|
/* Never let image bin eos events reach view finder */
|
||||||
|
gst_pad_add_event_probe (img->srcpad,
|
||||||
|
G_CALLBACK (gst_camerabin_drop_eos_probe), img);
|
||||||
|
|
||||||
|
ret = TRUE;
|
||||||
|
|
||||||
|
done:
|
||||||
|
|
||||||
|
if (img_srcpad) {
|
||||||
|
gst_object_unref (img_srcpad);
|
||||||
|
}
|
||||||
|
if (img_sinkpad) {
|
||||||
|
gst_object_unref (img_sinkpad);
|
||||||
|
}
|
||||||
|
if (!ret) {
|
||||||
|
gst_camerabin_image_destroy_elements (img);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_camerabin_image_destroy_elements:
|
||||||
|
* @img: a pointer to #GstCameraBinImage object
|
||||||
|
*
|
||||||
|
* This function releases resources allocated in
|
||||||
|
* gst_camerabin_image_create_elements.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
gst_camerabin_image_destroy_elements (GstCameraBinImage * img)
|
||||||
|
{
|
||||||
|
GST_LOG ("destroying img elements");
|
||||||
|
if (img->pad_tee_enc) {
|
||||||
|
gst_element_release_request_pad (img->tee, img->pad_tee_enc);
|
||||||
|
img->pad_tee_enc = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (img->pad_tee_view) {
|
||||||
|
gst_element_release_request_pad (img->tee, img->pad_tee_view);
|
||||||
|
img->pad_tee_view = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
gst_ghost_pad_set_target (GST_GHOST_PAD (img->sinkpad), NULL);
|
||||||
|
gst_ghost_pad_set_target (GST_GHOST_PAD (img->srcpad), NULL);
|
||||||
|
|
||||||
|
gst_camerabin_remove_elements_from_bin (GST_BIN (img));
|
||||||
|
|
||||||
|
img->post = NULL;
|
||||||
|
img->tee = NULL;
|
||||||
|
img->enc = NULL;
|
||||||
|
img->meta_mux = NULL;
|
||||||
|
img->sink = NULL;
|
||||||
|
img->queue = NULL;
|
||||||
|
|
||||||
|
img->elements_created = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gst_camerabin_image_set_encoder (GstCameraBinImage * img, GstElement * encoder)
|
||||||
|
{
|
||||||
|
if (img->user_enc)
|
||||||
|
gst_object_unref (img->user_enc);
|
||||||
|
if (encoder)
|
||||||
|
gst_object_ref (encoder);
|
||||||
|
|
||||||
|
img->user_enc = encoder;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gst_camerabin_image_set_postproc (GstCameraBinImage * img,
|
||||||
|
GstElement * postproc)
|
||||||
|
{
|
||||||
|
if (img->post)
|
||||||
|
gst_object_unref (img->post);
|
||||||
|
if (postproc)
|
||||||
|
gst_object_ref (postproc);
|
||||||
|
|
||||||
|
img->post = postproc;
|
||||||
|
}
|
||||||
|
|
||||||
|
GstElement *
|
||||||
|
gst_camerabin_image_get_encoder (GstCameraBinImage * img)
|
||||||
|
{
|
||||||
|
GstElement *enc;
|
||||||
|
|
||||||
|
if (img->user_enc) {
|
||||||
|
enc = img->user_enc;
|
||||||
|
} else {
|
||||||
|
enc = img->enc;
|
||||||
|
}
|
||||||
|
|
||||||
|
return enc;
|
||||||
|
}
|
||||||
|
|
||||||
|
GstElement *
|
||||||
|
gst_camerabin_image_get_postproc (GstCameraBinImage * img)
|
||||||
|
{
|
||||||
|
return img->post;
|
||||||
|
}
|
90
gst/camerabin/camerabinimage.h
Normal file
90
gst/camerabin/camerabinimage.h
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
* GStreamer
|
||||||
|
* Copyright (C) 2008 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 __CAMERABIN_IMAGE_H__
|
||||||
|
#define __CAMERABIN_IMAGE_H__
|
||||||
|
|
||||||
|
#include <gst/gstbin.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
#define GST_TYPE_CAMERABIN_IMAGE (gst_camerabin_image_get_type())
|
||||||
|
#define GST_CAMERABIN_IMAGE_CAST(obj) ((GstCameraBinImage*)(obj))
|
||||||
|
#define GST_CAMERABIN_IMAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_CAMERABIN_IMAGE,GstCameraBinImage))
|
||||||
|
#define GST_CAMERABIN_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_CAMERABIN_IMAGE,GstCameraBinImageClass))
|
||||||
|
#define GST_IS_CAMERABIN_IMAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_CAMERABIN_IMAGE))
|
||||||
|
#define GST_IS_CAMERABIN_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_CAMERABIN_IMAGE))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GstCameraBinImage:
|
||||||
|
*
|
||||||
|
* The opaque #GstCameraBinImage structure.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct _GstCameraBinImage GstCameraBinImage;
|
||||||
|
typedef struct _GstCameraBinImageClass GstCameraBinImageClass;
|
||||||
|
|
||||||
|
struct _GstCameraBinImage
|
||||||
|
{
|
||||||
|
GstBin parent;
|
||||||
|
GString *filename;
|
||||||
|
|
||||||
|
/* Ghost pads of image bin */
|
||||||
|
GstPad *sinkpad;
|
||||||
|
GstPad *srcpad;
|
||||||
|
|
||||||
|
/* Tee src pad leading to image encoder */
|
||||||
|
GstPad *pad_tee_enc;
|
||||||
|
/* Tee src pad leading to view finder */
|
||||||
|
GstPad *pad_tee_view;
|
||||||
|
|
||||||
|
GstElement *post;
|
||||||
|
|
||||||
|
GstElement *tee;
|
||||||
|
GstElement *enc;
|
||||||
|
GstElement *user_enc;
|
||||||
|
GstElement *meta_mux;
|
||||||
|
GstElement *sink;
|
||||||
|
GstElement *queue;
|
||||||
|
|
||||||
|
gboolean elements_created;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _GstCameraBinImageClass
|
||||||
|
{
|
||||||
|
GstBinClass parent_class;
|
||||||
|
};
|
||||||
|
|
||||||
|
GType gst_camerabin_image_get_type (void);
|
||||||
|
|
||||||
|
void
|
||||||
|
gst_camerabin_image_set_encoder (GstCameraBinImage * img, GstElement * encoder);
|
||||||
|
|
||||||
|
void
|
||||||
|
gst_camerabin_image_set_postproc (GstCameraBinImage * img,
|
||||||
|
GstElement * postproc);
|
||||||
|
|
||||||
|
GstElement *gst_camerabin_image_get_encoder (GstCameraBinImage * img);
|
||||||
|
|
||||||
|
GstElement *gst_camerabin_image_get_postproc (GstCameraBinImage * img);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif /* #ifndef __CAMERABIN_IMAGE_H__ */
|
826
gst/camerabin/camerabinvideo.c
Normal file
826
gst/camerabin/camerabinvideo.c
Normal file
|
@ -0,0 +1,826 @@
|
||||||
|
/*
|
||||||
|
* GStreamer
|
||||||
|
* Copyright (C) 2008 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SECTION:camerabinvideo
|
||||||
|
* @short_description: video recording module of #GstCameraBin
|
||||||
|
*
|
||||||
|
* <refsect2>
|
||||||
|
* <para>
|
||||||
|
*
|
||||||
|
* The pipeline for this module is:
|
||||||
|
*
|
||||||
|
* <informalexample>
|
||||||
|
* <programlisting>
|
||||||
|
*-----------------------------------------------------------------------------
|
||||||
|
* audiosrc -> audio_queue -> audioconvert -> volume -> audioenc
|
||||||
|
* > videomux -> filesink
|
||||||
|
* video_queue -> [timeoverlay] -> videoenc
|
||||||
|
* -> [post proc] -> tee <
|
||||||
|
* queue ->
|
||||||
|
*-----------------------------------------------------------------------------
|
||||||
|
* </programlisting>
|
||||||
|
* </informalexample>
|
||||||
|
*
|
||||||
|
* The properties of elements are:
|
||||||
|
*
|
||||||
|
* queue - "leaky", 2 (Leaky on downstream (old buffers))
|
||||||
|
*
|
||||||
|
* </para>
|
||||||
|
* </refsect2>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* includes
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <gst/gst.h>
|
||||||
|
#include "camerabingeneral.h"
|
||||||
|
|
||||||
|
#include "camerabinvideo.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* defines and static global vars
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* internal element names */
|
||||||
|
|
||||||
|
#define DEFAULT_AUD_SRC "pulsesrc"
|
||||||
|
#define DEFAULT_AUD_ENC "vorbisenc"
|
||||||
|
#define DEFAULT_VID_ENC "theoraenc"
|
||||||
|
#define DEFAULT_MUX "oggmux"
|
||||||
|
#define DEFAULT_SINK "filesink"
|
||||||
|
|
||||||
|
#define USE_AUDIO_CONVERSION 1
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
PROP_0,
|
||||||
|
PROP_FILENAME
|
||||||
|
};
|
||||||
|
|
||||||
|
static void gst_camerabin_video_dispose (GstCameraBinVideo * sink);
|
||||||
|
static void gst_camerabin_video_set_property (GObject * object, guint prop_id,
|
||||||
|
const GValue * value, GParamSpec * pspec);
|
||||||
|
static void gst_camerabin_video_get_property (GObject * object, guint prop_id,
|
||||||
|
GValue * value, GParamSpec * pspec);
|
||||||
|
|
||||||
|
static GstClock *gst_camerabin_video_provide_clock (GstElement * elem);
|
||||||
|
static GstStateChangeReturn
|
||||||
|
gst_camerabin_video_change_state (GstElement * element,
|
||||||
|
GstStateChange transition);
|
||||||
|
|
||||||
|
static
|
||||||
|
gboolean camerabin_video_pad_tee_src0_have_buffer (GstPad * pad,
|
||||||
|
GstBuffer * buffer, gpointer u_data);
|
||||||
|
static gboolean camerabin_video_pad_aud_src_have_buffer (GstPad * pad,
|
||||||
|
GstBuffer * buffer, gpointer u_data);
|
||||||
|
static gboolean camerabin_video_sink_have_event (GstPad * pad, GstEvent * event,
|
||||||
|
gpointer u_data);
|
||||||
|
static gboolean gst_camerabin_video_create_elements (GstCameraBinVideo * vid);
|
||||||
|
static void gst_camerabin_video_destroy_elements (GstCameraBinVideo * vid);
|
||||||
|
|
||||||
|
GST_BOILERPLATE (GstCameraBinVideo, gst_camerabin_video, GstBin, GST_TYPE_BIN);
|
||||||
|
|
||||||
|
static const GstElementDetails gst_camerabin_video_details =
|
||||||
|
GST_ELEMENT_DETAILS ("Video capture bin for camerabin",
|
||||||
|
"Bin/Video",
|
||||||
|
"Process and store video data",
|
||||||
|
"Edgard Lima <edgard.lima@indt.org.br>\n"
|
||||||
|
"Nokia Corporation <multimedia@maemo.org>");
|
||||||
|
|
||||||
|
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||||
|
GST_PAD_SINK,
|
||||||
|
GST_PAD_ALWAYS,
|
||||||
|
GST_STATIC_CAPS_ANY);
|
||||||
|
|
||||||
|
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
|
||||||
|
GST_PAD_SRC,
|
||||||
|
GST_PAD_ALWAYS,
|
||||||
|
GST_STATIC_CAPS_ANY);
|
||||||
|
|
||||||
|
|
||||||
|
/* GObject methods implementation */
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_camerabin_video_base_init (gpointer klass)
|
||||||
|
{
|
||||||
|
GstElementClass *eklass = GST_ELEMENT_CLASS (klass);
|
||||||
|
|
||||||
|
gst_element_class_add_pad_template (eklass,
|
||||||
|
gst_static_pad_template_get (&sink_template));
|
||||||
|
gst_element_class_add_pad_template (eklass,
|
||||||
|
gst_static_pad_template_get (&src_template));
|
||||||
|
gst_element_class_set_details (eklass, &gst_camerabin_video_details);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_camerabin_video_class_init (GstCameraBinVideoClass * klass)
|
||||||
|
{
|
||||||
|
GObjectClass *gobject_class;
|
||||||
|
GstElementClass *eklass = GST_ELEMENT_CLASS (klass);
|
||||||
|
|
||||||
|
gobject_class = G_OBJECT_CLASS (klass);
|
||||||
|
gobject_class->dispose =
|
||||||
|
(GObjectFinalizeFunc) GST_DEBUG_FUNCPTR (gst_camerabin_video_dispose);
|
||||||
|
eklass->change_state = GST_DEBUG_FUNCPTR (gst_camerabin_video_change_state);
|
||||||
|
|
||||||
|
eklass->provide_clock = GST_DEBUG_FUNCPTR (gst_camerabin_video_provide_clock);
|
||||||
|
|
||||||
|
gobject_class->set_property =
|
||||||
|
GST_DEBUG_FUNCPTR (gst_camerabin_video_set_property);
|
||||||
|
gobject_class->get_property =
|
||||||
|
GST_DEBUG_FUNCPTR (gst_camerabin_video_get_property);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GstCameraBinVideo:filename:
|
||||||
|
*
|
||||||
|
* This property can be used to specify the filename of the video.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
g_object_class_install_property (gobject_class, PROP_FILENAME,
|
||||||
|
g_param_spec_string ("filename", "Filename",
|
||||||
|
"Filename of the video to save", NULL, G_PARAM_READWRITE));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_camerabin_video_init (GstCameraBinVideo * vid,
|
||||||
|
GstCameraBinVideoClass * g_class)
|
||||||
|
{
|
||||||
|
vid->filename = g_string_new ("");
|
||||||
|
|
||||||
|
vid->user_post = NULL;
|
||||||
|
vid->user_vid_enc = NULL;
|
||||||
|
vid->user_aud_enc = NULL;
|
||||||
|
vid->user_aud_src = NULL;
|
||||||
|
vid->user_mux = NULL;
|
||||||
|
|
||||||
|
vid->aud_src = NULL;
|
||||||
|
vid->sink = NULL;
|
||||||
|
vid->tee = NULL;
|
||||||
|
vid->volume = NULL;
|
||||||
|
vid->video_queue = NULL;
|
||||||
|
|
||||||
|
vid->tee_video_srcpad = NULL;
|
||||||
|
vid->tee_vf_srcpad = NULL;
|
||||||
|
|
||||||
|
vid->pending_eos = NULL;
|
||||||
|
|
||||||
|
/* Create src and sink ghost pads */
|
||||||
|
vid->sinkpad = gst_ghost_pad_new_no_target ("sink", GST_PAD_SINK);
|
||||||
|
gst_element_add_pad (GST_ELEMENT (vid), vid->sinkpad);
|
||||||
|
|
||||||
|
vid->srcpad = gst_ghost_pad_new_no_target ("src", GST_PAD_SRC);
|
||||||
|
gst_element_add_pad (GST_ELEMENT (vid), vid->srcpad);
|
||||||
|
|
||||||
|
/* Add probe for handling eos when stopping recording */
|
||||||
|
gst_pad_add_event_probe (vid->sinkpad,
|
||||||
|
G_CALLBACK (camerabin_video_sink_have_event), vid);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_camerabin_video_dispose (GstCameraBinVideo * vid)
|
||||||
|
{
|
||||||
|
GST_DEBUG_OBJECT (vid, "disposing");
|
||||||
|
|
||||||
|
g_string_free (vid->filename, TRUE);
|
||||||
|
vid->filename = NULL;
|
||||||
|
|
||||||
|
if (vid->user_post) {
|
||||||
|
gst_object_unref (vid->user_post);
|
||||||
|
vid->user_post = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vid->user_vid_enc) {
|
||||||
|
gst_object_unref (vid->user_vid_enc);
|
||||||
|
vid->user_vid_enc = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vid->user_aud_enc) {
|
||||||
|
gst_object_unref (vid->user_aud_enc);
|
||||||
|
vid->user_aud_enc = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vid->user_aud_src) {
|
||||||
|
gst_object_unref (vid->user_aud_src);
|
||||||
|
vid->user_aud_src = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vid->user_mux) {
|
||||||
|
gst_object_unref (vid->user_mux);
|
||||||
|
vid->user_mux = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (parent_class)->dispose ((GObject *) vid);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_camerabin_video_set_property (GObject * object, guint prop_id,
|
||||||
|
const GValue * value, GParamSpec * pspec)
|
||||||
|
{
|
||||||
|
GstCameraBinVideo *bin = GST_CAMERABIN_VIDEO (object);
|
||||||
|
|
||||||
|
switch (prop_id) {
|
||||||
|
case PROP_FILENAME:
|
||||||
|
g_string_assign (bin->filename, g_value_get_string (value));
|
||||||
|
if (bin->sink) {
|
||||||
|
g_object_set (G_OBJECT (bin->sink), "location", bin->filename->str,
|
||||||
|
NULL);
|
||||||
|
} else {
|
||||||
|
GST_INFO ("no sink, not setting name yet");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_camerabin_video_get_property (GObject * object, guint prop_id,
|
||||||
|
GValue * value, GParamSpec * pspec)
|
||||||
|
{
|
||||||
|
GstCameraBinVideo *bin = GST_CAMERABIN_VIDEO (object);
|
||||||
|
|
||||||
|
switch (prop_id) {
|
||||||
|
case PROP_FILENAME:
|
||||||
|
g_value_set_string (value, bin->filename->str);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* GstElement methods implementation */
|
||||||
|
|
||||||
|
static GstClock *
|
||||||
|
gst_camerabin_video_provide_clock (GstElement * elem)
|
||||||
|
{
|
||||||
|
GstElement *aud_src = GST_CAMERABIN_VIDEO (elem)->aud_src;
|
||||||
|
if (aud_src) {
|
||||||
|
return gst_element_provide_clock (aud_src);
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static GstStateChangeReturn
|
||||||
|
gst_camerabin_video_change_state (GstElement * element,
|
||||||
|
GstStateChange transition)
|
||||||
|
{
|
||||||
|
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
||||||
|
GstCameraBinVideo *vid = GST_CAMERABIN_VIDEO (element);
|
||||||
|
|
||||||
|
switch (transition) {
|
||||||
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
||||||
|
if (!gst_camerabin_video_create_elements (vid)) {
|
||||||
|
return GST_STATE_CHANGE_FAILURE;
|
||||||
|
}
|
||||||
|
/* Don't change sink to READY yet to allow changing the
|
||||||
|
filename in READY state. */
|
||||||
|
gst_element_set_locked_state (vid->sink, TRUE);
|
||||||
|
break;
|
||||||
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
||||||
|
vid->calculate_adjust_ts_video = TRUE;
|
||||||
|
vid->calculate_adjust_ts_aud = TRUE;
|
||||||
|
g_object_set (G_OBJECT (vid->sink), "async", FALSE, NULL);
|
||||||
|
gst_element_set_locked_state (vid->sink, FALSE);
|
||||||
|
break;
|
||||||
|
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
||||||
|
vid->calculate_adjust_ts_video = TRUE;
|
||||||
|
vid->calculate_adjust_ts_aud = TRUE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
||||||
|
/* Set sink to NULL in order to write the file _now_ */
|
||||||
|
GST_INFO ("write vid file: %s", vid->filename->str);
|
||||||
|
gst_element_set_locked_state (vid->sink, TRUE);
|
||||||
|
gst_element_set_state (vid->sink, GST_STATE_NULL);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
||||||
|
|
||||||
|
switch (transition) {
|
||||||
|
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
||||||
|
if (vid->pending_eos) {
|
||||||
|
/* Video bin is still paused, so push eos directly to video queue */
|
||||||
|
GST_DEBUG_OBJECT (vid, "pushing pending eos");
|
||||||
|
gst_pad_push_event (vid->tee_video_srcpad, vid->pending_eos);
|
||||||
|
vid->pending_eos = NULL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
||||||
|
/* Reset counters related to timestamp rewriting */
|
||||||
|
vid->adjust_ts_video = 0;
|
||||||
|
vid->last_ts_video = 0;
|
||||||
|
vid->adjust_ts_aud = 0;
|
||||||
|
vid->last_ts_aud = 0;
|
||||||
|
|
||||||
|
if (vid->pending_eos) {
|
||||||
|
gst_event_unref (vid->pending_eos);
|
||||||
|
vid->pending_eos = NULL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
||||||
|
gst_camerabin_video_destroy_elements (vid);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* static helper functions implementation
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* camerabin_video_pad_tee_src0_have_buffer:
|
||||||
|
* @pad: tee src pad leading to video encoding
|
||||||
|
* @event: received buffer
|
||||||
|
* @u_data: video bin object
|
||||||
|
*
|
||||||
|
* Buffer probe for rewriting video buffer timestamps.
|
||||||
|
*
|
||||||
|
* Returns: TRUE always
|
||||||
|
*/
|
||||||
|
static gboolean
|
||||||
|
camerabin_video_pad_tee_src0_have_buffer (GstPad * pad, GstBuffer * buffer,
|
||||||
|
gpointer u_data)
|
||||||
|
{
|
||||||
|
GstCameraBinVideo *vid = (GstCameraBinVideo *) u_data;
|
||||||
|
|
||||||
|
GST_LOG ("buffer in with size %d ts %" GST_TIME_FORMAT,
|
||||||
|
GST_BUFFER_SIZE (buffer), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)));
|
||||||
|
|
||||||
|
if (G_UNLIKELY (vid->calculate_adjust_ts_video)) {
|
||||||
|
GstEvent *event;
|
||||||
|
GstObject *tee;
|
||||||
|
GstPad *sinkpad;
|
||||||
|
vid->adjust_ts_video = GST_BUFFER_TIMESTAMP (buffer) - vid->last_ts_video;
|
||||||
|
vid->calculate_adjust_ts_video = FALSE;
|
||||||
|
event = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME,
|
||||||
|
0, GST_CLOCK_TIME_NONE, vid->last_ts_video);
|
||||||
|
/* Send the newsegment to both view finder and video bin */
|
||||||
|
tee = gst_pad_get_parent (pad);
|
||||||
|
sinkpad = gst_element_get_static_pad (GST_ELEMENT (tee), "sink");
|
||||||
|
gst_pad_send_event (sinkpad, event);
|
||||||
|
gst_object_unref (tee);
|
||||||
|
gst_object_unref (sinkpad);
|
||||||
|
GST_LOG_OBJECT (vid, "vid ts adjustment: %" GST_TIME_FORMAT,
|
||||||
|
GST_TIME_ARGS (vid->adjust_ts_video));
|
||||||
|
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DISCONT);
|
||||||
|
}
|
||||||
|
GST_BUFFER_TIMESTAMP (buffer) -= vid->adjust_ts_video;
|
||||||
|
vid->last_ts_video = GST_BUFFER_TIMESTAMP (buffer);
|
||||||
|
if (GST_BUFFER_DURATION_IS_VALID (buffer))
|
||||||
|
vid->last_ts_video += GST_BUFFER_DURATION (buffer);
|
||||||
|
|
||||||
|
|
||||||
|
GST_LOG ("buffer out with size %d ts %" GST_TIME_FORMAT,
|
||||||
|
GST_BUFFER_SIZE (buffer), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)));
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* camerabin_video_pad_aud_src_have_buffer:
|
||||||
|
* @pad: audio source src pad
|
||||||
|
* @event: received buffer
|
||||||
|
* @u_data: video bin object
|
||||||
|
*
|
||||||
|
* Buffer probe for rewriting audio buffer timestamps.
|
||||||
|
*
|
||||||
|
* Returns: TRUE always
|
||||||
|
*/
|
||||||
|
static gboolean
|
||||||
|
camerabin_video_pad_aud_src_have_buffer (GstPad * pad, GstBuffer * buffer,
|
||||||
|
gpointer u_data)
|
||||||
|
{
|
||||||
|
GstCameraBinVideo *vid = (GstCameraBinVideo *) u_data;
|
||||||
|
|
||||||
|
if (vid->calculate_adjust_ts_aud) {
|
||||||
|
GstEvent *event;
|
||||||
|
GstPad *peerpad = NULL;
|
||||||
|
vid->adjust_ts_aud = GST_BUFFER_TIMESTAMP (buffer) - vid->last_ts_aud;
|
||||||
|
vid->calculate_adjust_ts_aud = FALSE;
|
||||||
|
event = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME,
|
||||||
|
0, GST_CLOCK_TIME_NONE, vid->last_ts_aud);
|
||||||
|
peerpad = gst_pad_get_peer (pad);
|
||||||
|
if (peerpad) {
|
||||||
|
gst_pad_send_event (peerpad, event);
|
||||||
|
gst_object_unref (peerpad);
|
||||||
|
}
|
||||||
|
GST_LOG_OBJECT (vid, "aud ts adjustment: %" GST_TIME_FORMAT,
|
||||||
|
GST_TIME_ARGS (vid->adjust_ts_aud));
|
||||||
|
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DISCONT);
|
||||||
|
}
|
||||||
|
GST_BUFFER_TIMESTAMP (buffer) -= vid->adjust_ts_aud;
|
||||||
|
vid->last_ts_aud = GST_BUFFER_TIMESTAMP (buffer);
|
||||||
|
if (GST_BUFFER_DURATION_IS_VALID (buffer))
|
||||||
|
vid->last_ts_aud += GST_BUFFER_DURATION (buffer);
|
||||||
|
GST_LOG ("buffer out with size %d ts %" GST_TIME_FORMAT,
|
||||||
|
GST_BUFFER_SIZE (buffer), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)));
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* camerabin_video_sink_have_event:
|
||||||
|
* @pad: video bin sink pad
|
||||||
|
* @event: received event
|
||||||
|
* @u_data: video bin object
|
||||||
|
*
|
||||||
|
* Event probe for video bin eos handling.
|
||||||
|
* Copies the eos event to audio branch of video bin.
|
||||||
|
*
|
||||||
|
* Returns: FALSE to drop the event, TRUE otherwise
|
||||||
|
*/
|
||||||
|
static gboolean
|
||||||
|
camerabin_video_sink_have_event (GstPad * pad, GstEvent * event,
|
||||||
|
gpointer u_data)
|
||||||
|
{
|
||||||
|
GstCameraBinVideo *vid = (GstCameraBinVideo *) u_data;
|
||||||
|
gboolean ret = TRUE;
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (vid, "got videobin sink event: %s",
|
||||||
|
GST_EVENT_TYPE_NAME (event));
|
||||||
|
|
||||||
|
switch (GST_EVENT_TYPE (event)) {
|
||||||
|
case GST_EVENT_EOS:
|
||||||
|
if (vid->aud_src) {
|
||||||
|
GST_DEBUG_OBJECT (vid, "copying %s to audio branch",
|
||||||
|
GST_EVENT_TYPE_NAME (event));
|
||||||
|
gst_element_send_event (vid->aud_src, gst_event_copy (event));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If we're paused, we can't pass eos to video now to avoid blocking.
|
||||||
|
Instead send eos when changing to playing next time. */
|
||||||
|
if (GST_STATE (GST_ELEMENT (vid)) == GST_STATE_PAUSED) {
|
||||||
|
GST_DEBUG_OBJECT (vid, "paused, delay eos sending");
|
||||||
|
vid->pending_eos = gst_event_ref (event);
|
||||||
|
ret = FALSE; /* Drop the event */
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_camerabin_video_create_elements:
|
||||||
|
* @vid: a pointer to #GstCameraBinVideo
|
||||||
|
*
|
||||||
|
* This function creates the needed #GstElements and resources to record videos.
|
||||||
|
* Use gst_camerabin_video_destroy_elements() to free these resources.
|
||||||
|
*
|
||||||
|
* Returns: %TRUE if succeeded or FALSE if failed
|
||||||
|
*/
|
||||||
|
static gboolean
|
||||||
|
gst_camerabin_video_create_elements (GstCameraBinVideo * vid)
|
||||||
|
{
|
||||||
|
GstPad *pad = NULL, *vid_sinkpad = NULL, *vid_srcpad = NULL;
|
||||||
|
GstBin *vidbin = GST_BIN (vid);
|
||||||
|
GstElement *queue = NULL;
|
||||||
|
|
||||||
|
vid->adjust_ts_video = 0;
|
||||||
|
vid->last_ts_video = 0;
|
||||||
|
vid->calculate_adjust_ts_video = FALSE;
|
||||||
|
|
||||||
|
vid->adjust_ts_aud = 0;
|
||||||
|
vid->last_ts_aud = 0;
|
||||||
|
vid->calculate_adjust_ts_aud = FALSE;
|
||||||
|
|
||||||
|
/* Add video post processing element if any */
|
||||||
|
if (vid->user_post) {
|
||||||
|
if (!gst_camerabin_add_element (vidbin, vid->user_post)) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
vid_sinkpad = gst_element_get_static_pad (vid->user_post, "sink");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add tee element */
|
||||||
|
if (!(vid->tee = gst_camerabin_create_and_add_element (vidbin, "tee"))) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set up sink ghost pad for video bin */
|
||||||
|
if (!vid_sinkpad) {
|
||||||
|
vid_sinkpad = gst_element_get_static_pad (vid->tee, "sink");
|
||||||
|
}
|
||||||
|
gst_ghost_pad_set_target (GST_GHOST_PAD (vid->sinkpad), vid_sinkpad);
|
||||||
|
|
||||||
|
|
||||||
|
/* Add queue element for video */
|
||||||
|
vid->tee_video_srcpad = gst_element_get_request_pad (vid->tee, "src%d");
|
||||||
|
if (!(vid->video_queue =
|
||||||
|
gst_camerabin_create_and_add_element (vidbin, "queue"))) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add probe for rewriting video timestamps */
|
||||||
|
gst_pad_add_buffer_probe (vid->tee_video_srcpad,
|
||||||
|
G_CALLBACK (camerabin_video_pad_tee_src0_have_buffer), vid);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef USE_TIMEOVERLAY
|
||||||
|
/* Add timeoverlay element to visualize elapsed time for debugging */
|
||||||
|
if (!(gst_camerabin_create_and_add_element (vidbin, "timeoverlay"))) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Add user set or default video encoder element */
|
||||||
|
if (vid->user_vid_enc) {
|
||||||
|
vid->vid_enc = vid->user_vid_enc;
|
||||||
|
if (!gst_camerabin_add_element (vidbin, vid->vid_enc)) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
} else if (!(vid->vid_enc =
|
||||||
|
gst_camerabin_create_and_add_element (vidbin, DEFAULT_VID_ENC))) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add user set or default muxer element */
|
||||||
|
if (vid->user_mux) {
|
||||||
|
vid->muxer = vid->user_mux;
|
||||||
|
if (!gst_camerabin_add_element (vidbin, vid->muxer)) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
} else if (!(vid->muxer =
|
||||||
|
gst_camerabin_create_and_add_element (vidbin, DEFAULT_MUX))) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add sink element for storing the video */
|
||||||
|
if (!(vid->sink =
|
||||||
|
gst_camerabin_create_and_add_element (vidbin, DEFAULT_SINK))) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
g_object_set (G_OBJECT (vid->sink), "location", vid->filename->str, NULL);
|
||||||
|
|
||||||
|
|
||||||
|
/* Add user set or default audio source element */
|
||||||
|
if (vid->user_aud_src) {
|
||||||
|
vid->aud_src = vid->user_aud_src;
|
||||||
|
if (!gst_camerabin_add_element (vidbin, vid->aud_src)) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
} else if (!(vid->aud_src =
|
||||||
|
gst_camerabin_create_and_add_element (vidbin, DEFAULT_AUD_SRC))) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add queue element for audio */
|
||||||
|
if (!(queue = gst_camerabin_create_and_add_element (vidbin, "queue"))) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
queue = NULL;
|
||||||
|
|
||||||
|
/* Add optional audio conversion and volume elements and
|
||||||
|
raise no errors if adding them fails */
|
||||||
|
#ifdef USE_AUDIO_CONVERSION
|
||||||
|
if (!gst_camerabin_try_add_element (vidbin,
|
||||||
|
gst_element_factory_make ("audioconvert", NULL))) {
|
||||||
|
GST_WARNING_OBJECT (vid, "unable to add audio conversion element");
|
||||||
|
/* gst_camerabin_try_add_element() destroyed the element */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
vid->volume = gst_element_factory_make ("volume", NULL);
|
||||||
|
if (!gst_camerabin_try_add_element (vidbin, vid->volume)) {
|
||||||
|
GST_WARNING_OBJECT (vid, "unable to add volume element");
|
||||||
|
/* gst_camerabin_try_add_element() destroyed the element */
|
||||||
|
vid->volume = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add user set or default audio encoder element */
|
||||||
|
if (vid->user_aud_enc) {
|
||||||
|
vid->aud_enc = vid->user_aud_enc;
|
||||||
|
if (!gst_camerabin_add_element (vidbin, vid->aud_enc)) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
} else if (!(vid->aud_enc =
|
||||||
|
gst_camerabin_create_and_add_element (vidbin, DEFAULT_AUD_ENC))) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Link audio part to the muxer */
|
||||||
|
if (!gst_element_link (vid->aud_enc, vid->muxer)) {
|
||||||
|
GST_ELEMENT_ERROR (vid, CORE, NEGOTIATION, (NULL),
|
||||||
|
("linking audio encoder and muxer failed"));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add queue leading out of the video bin and to view finder */
|
||||||
|
vid->tee_vf_srcpad = gst_element_get_request_pad (vid->tee, "src%d");
|
||||||
|
if (!(queue = gst_camerabin_create_and_add_element (vidbin, "queue"))) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
/* Set queue leaky, we don't want to block video encoder feed, but
|
||||||
|
prefer leaking view finder buffers instead. */
|
||||||
|
g_object_set (G_OBJECT (queue), "leaky", 2, NULL);
|
||||||
|
|
||||||
|
/* Set up src ghost pad for video bin */
|
||||||
|
vid_srcpad = gst_element_get_static_pad (queue, "src");
|
||||||
|
gst_ghost_pad_set_target (GST_GHOST_PAD (vid->srcpad), vid_srcpad);
|
||||||
|
/* Never let video bin eos events reach view finder */
|
||||||
|
gst_pad_add_event_probe (vid_srcpad,
|
||||||
|
G_CALLBACK (gst_camerabin_drop_eos_probe), vid);
|
||||||
|
|
||||||
|
pad = gst_element_get_static_pad (vid->aud_src, "src");
|
||||||
|
gst_pad_add_buffer_probe (pad,
|
||||||
|
G_CALLBACK (camerabin_video_pad_aud_src_have_buffer), vid);
|
||||||
|
gst_object_unref (pad);
|
||||||
|
|
||||||
|
GST_DEBUG ("created video elements");
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
error:
|
||||||
|
|
||||||
|
gst_camerabin_video_destroy_elements (vid);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_camerabin_video_destroy_elements:
|
||||||
|
* @vid: a pointer to #GstCameraBinVideo
|
||||||
|
*
|
||||||
|
* This function destroys all the elements created by
|
||||||
|
* gst_camerabin_video_create_elements().
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
gst_camerabin_video_destroy_elements (GstCameraBinVideo * vid)
|
||||||
|
{
|
||||||
|
GST_DEBUG ("destroying video elements");
|
||||||
|
|
||||||
|
/* Release tee request pads */
|
||||||
|
if (vid->tee_video_srcpad) {
|
||||||
|
gst_element_release_request_pad (vid->tee, vid->tee_video_srcpad);
|
||||||
|
vid->tee_video_srcpad = NULL;
|
||||||
|
}
|
||||||
|
if (vid->tee_vf_srcpad) {
|
||||||
|
gst_element_release_request_pad (vid->tee, vid->tee_vf_srcpad);
|
||||||
|
vid->tee_vf_srcpad = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
gst_ghost_pad_set_target (GST_GHOST_PAD (vid->sinkpad), NULL);
|
||||||
|
gst_ghost_pad_set_target (GST_GHOST_PAD (vid->srcpad), NULL);
|
||||||
|
|
||||||
|
gst_camerabin_remove_elements_from_bin (GST_BIN (vid));
|
||||||
|
|
||||||
|
vid->aud_src = NULL;
|
||||||
|
vid->sink = NULL;
|
||||||
|
vid->tee = NULL;
|
||||||
|
vid->volume = NULL;
|
||||||
|
vid->video_queue = NULL;
|
||||||
|
vid->vid_enc = NULL;
|
||||||
|
vid->aud_enc = NULL;
|
||||||
|
vid->muxer = NULL;
|
||||||
|
|
||||||
|
if (vid->pending_eos) {
|
||||||
|
gst_event_unref (vid->pending_eos);
|
||||||
|
vid->pending_eos = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set & get mute and video capture elements
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
gst_camerabin_video_set_mute (GstCameraBinVideo * vid, gboolean mute)
|
||||||
|
{
|
||||||
|
if (vid && vid->volume) {
|
||||||
|
GST_DEBUG_OBJECT (vid, "setting mute %s", mute ? "on" : "off");
|
||||||
|
g_object_set (vid->volume, "mute", mute, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gst_camerabin_video_set_post (GstCameraBinVideo * vid, GstElement * post)
|
||||||
|
{
|
||||||
|
GstElement **user_post;
|
||||||
|
GST_DEBUG_OBJECT (vid, "setting video post processing: %" GST_PTR_FORMAT,
|
||||||
|
post);
|
||||||
|
GST_OBJECT_LOCK (vid);
|
||||||
|
user_post = &vid->user_post;
|
||||||
|
gst_object_replace ((GstObject **) user_post, GST_OBJECT (post));
|
||||||
|
GST_OBJECT_UNLOCK (vid);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gst_camerabin_video_set_video_enc (GstCameraBinVideo * vid,
|
||||||
|
GstElement * video_enc)
|
||||||
|
{
|
||||||
|
GstElement **user_vid_enc;
|
||||||
|
GST_DEBUG_OBJECT (vid, "setting video encoder: %" GST_PTR_FORMAT, video_enc);
|
||||||
|
GST_OBJECT_LOCK (vid);
|
||||||
|
user_vid_enc = &vid->user_vid_enc;
|
||||||
|
gst_object_replace ((GstObject **) user_vid_enc, GST_OBJECT (video_enc));
|
||||||
|
GST_OBJECT_UNLOCK (vid);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gst_camerabin_video_set_audio_enc (GstCameraBinVideo * vid,
|
||||||
|
GstElement * audio_enc)
|
||||||
|
{
|
||||||
|
GstElement **user_aud_enc;
|
||||||
|
GST_DEBUG_OBJECT (vid, "setting audio encoder: %" GST_PTR_FORMAT, audio_enc);
|
||||||
|
GST_OBJECT_LOCK (vid);
|
||||||
|
user_aud_enc = &vid->user_aud_enc;
|
||||||
|
gst_object_replace ((GstObject **) user_aud_enc, GST_OBJECT (audio_enc));
|
||||||
|
GST_OBJECT_UNLOCK (vid);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gst_camerabin_video_set_muxer (GstCameraBinVideo * vid, GstElement * muxer)
|
||||||
|
{
|
||||||
|
GstElement **user_mux;
|
||||||
|
GST_DEBUG_OBJECT (vid, "setting muxer: %" GST_PTR_FORMAT, muxer);
|
||||||
|
GST_OBJECT_LOCK (vid);
|
||||||
|
user_mux = &vid->user_mux;
|
||||||
|
gst_object_replace ((GstObject **) user_mux, GST_OBJECT (muxer));
|
||||||
|
GST_OBJECT_UNLOCK (vid);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gst_camerabin_video_set_audio_src (GstCameraBinVideo * vid,
|
||||||
|
GstElement * audio_src)
|
||||||
|
{
|
||||||
|
GstElement **user_aud_src;
|
||||||
|
GST_DEBUG_OBJECT (vid, "setting audio source: %" GST_PTR_FORMAT, audio_src);
|
||||||
|
GST_OBJECT_LOCK (vid);
|
||||||
|
user_aud_src = &vid->user_aud_src;
|
||||||
|
gst_object_replace ((GstObject **) user_aud_src, GST_OBJECT (audio_src));
|
||||||
|
GST_OBJECT_UNLOCK (vid);
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
gst_camerabin_video_get_mute (GstCameraBinVideo * vid)
|
||||||
|
{
|
||||||
|
gboolean mute = ARG_DEFAULT_MUTE;
|
||||||
|
|
||||||
|
if (vid && vid->volume) {
|
||||||
|
g_object_get (vid->volume, "mute", &mute, NULL);
|
||||||
|
}
|
||||||
|
return mute;
|
||||||
|
}
|
||||||
|
|
||||||
|
GstElement *
|
||||||
|
gst_camerabin_video_get_post (GstCameraBinVideo * vid)
|
||||||
|
{
|
||||||
|
return vid->user_post;
|
||||||
|
}
|
||||||
|
|
||||||
|
GstElement *
|
||||||
|
gst_camerabin_video_get_video_enc (GstCameraBinVideo * vid)
|
||||||
|
{
|
||||||
|
return vid->vid_enc ? vid->vid_enc : vid->user_vid_enc;
|
||||||
|
}
|
||||||
|
|
||||||
|
GstElement *
|
||||||
|
gst_camerabin_video_get_audio_enc (GstCameraBinVideo * vid)
|
||||||
|
{
|
||||||
|
return vid->aud_enc ? vid->aud_enc : vid->user_aud_enc;
|
||||||
|
}
|
||||||
|
|
||||||
|
GstElement *
|
||||||
|
gst_camerabin_video_get_muxer (GstCameraBinVideo * vid)
|
||||||
|
{
|
||||||
|
return vid->muxer ? vid->muxer : vid->user_mux;
|
||||||
|
}
|
||||||
|
|
||||||
|
GstElement *
|
||||||
|
gst_camerabin_video_get_audio_src (GstCameraBinVideo * vid)
|
||||||
|
{
|
||||||
|
return vid->aud_src ? vid->aud_src : vid->user_aud_src;
|
||||||
|
}
|
136
gst/camerabin/camerabinvideo.h
Normal file
136
gst/camerabin/camerabinvideo.h
Normal file
|
@ -0,0 +1,136 @@
|
||||||
|
/*
|
||||||
|
* GStreamer
|
||||||
|
* Copyright (C) 2008 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 __CAMERABIN_VIDEO_H__
|
||||||
|
#define __CAMERABIN_VIDEO_H__
|
||||||
|
|
||||||
|
#include <gst/gstbin.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
//#define USE_TIMEOVERLAY 1
|
||||||
|
|
||||||
|
#define ARG_DEFAULT_MUTE FALSE
|
||||||
|
|
||||||
|
#define GST_TYPE_CAMERABIN_VIDEO (gst_camerabin_video_get_type())
|
||||||
|
#define GST_CAMERABIN_VIDEO_CAST(obj) ((GstCameraBinVideo*)(obj))
|
||||||
|
#define GST_CAMERABIN_VIDEO(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_CAMERABIN_VIDEO,GstCameraBinVideo))
|
||||||
|
#define GST_CAMERABIN_VIDEO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_CAMERABIN_VIDEO,GstCameraBinVideoClass))
|
||||||
|
#define GST_IS_CAMERABIN_VIDEO(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_CAMERABIN_VIDEO))
|
||||||
|
#define GST_IS_CAMERABIN_VIDEO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_CAMERABIN_VIDEO))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GstCameraBinVideo:
|
||||||
|
*
|
||||||
|
* The opaque #GstCameraBinVideo structure.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct _GstCameraBinVideo GstCameraBinVideo;
|
||||||
|
typedef struct _GstCameraBinVideoClass GstCameraBinVideoClass;
|
||||||
|
|
||||||
|
struct _GstCameraBinVideo
|
||||||
|
{
|
||||||
|
GstBin parent;
|
||||||
|
|
||||||
|
GString *filename;
|
||||||
|
|
||||||
|
/* A/V timestamp rewriting */
|
||||||
|
guint64 adjust_ts_video;
|
||||||
|
guint64 last_ts_video;
|
||||||
|
gboolean calculate_adjust_ts_video;
|
||||||
|
|
||||||
|
guint64 adjust_ts_aud;
|
||||||
|
guint64 last_ts_aud;
|
||||||
|
gboolean calculate_adjust_ts_aud;
|
||||||
|
|
||||||
|
/* Sink and src pads of video bin */
|
||||||
|
GstPad *sinkpad;
|
||||||
|
GstPad *srcpad;
|
||||||
|
|
||||||
|
/* Tee src pads leading to video encoder and view finder */
|
||||||
|
GstPad *tee_video_srcpad;
|
||||||
|
GstPad *tee_vf_srcpad;
|
||||||
|
|
||||||
|
/* User set elements */
|
||||||
|
GstElement *user_post; /* Video post processing */
|
||||||
|
GstElement *user_vid_enc;
|
||||||
|
GstElement *user_aud_enc;
|
||||||
|
GstElement *user_aud_src;
|
||||||
|
GstElement *user_mux;
|
||||||
|
|
||||||
|
/* Other elements */
|
||||||
|
GstElement *aud_src; /* Audio source */
|
||||||
|
GstElement *sink; /* Sink for recorded video */
|
||||||
|
GstElement *tee; /* Split output to view finder and recording sink */
|
||||||
|
GstElement *volume; /* Volume for muting */
|
||||||
|
GstElement *video_queue; /* Buffer for raw video frames */
|
||||||
|
GstElement *vid_enc; /* Video encoder */
|
||||||
|
GstElement *aud_enc; /* Audio encoder */
|
||||||
|
GstElement *muxer; /* Muxer */
|
||||||
|
|
||||||
|
GstEvent *pending_eos;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _GstCameraBinVideoClass
|
||||||
|
{
|
||||||
|
GstBinClass parent_class;
|
||||||
|
};
|
||||||
|
|
||||||
|
GType gst_camerabin_video_get_type (void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* external function prototypes
|
||||||
|
*/
|
||||||
|
|
||||||
|
void gst_camerabin_video_set_mute (GstCameraBinVideo * vid, gboolean mute);
|
||||||
|
|
||||||
|
void gst_camerabin_video_set_post (GstCameraBinVideo * vid, GstElement * post);
|
||||||
|
|
||||||
|
void
|
||||||
|
gst_camerabin_video_set_video_enc (GstCameraBinVideo * vid,
|
||||||
|
GstElement * video_enc);
|
||||||
|
|
||||||
|
void
|
||||||
|
gst_camerabin_video_set_audio_enc (GstCameraBinVideo * vid,
|
||||||
|
GstElement * audio_enc);
|
||||||
|
|
||||||
|
void
|
||||||
|
gst_camerabin_video_set_muxer (GstCameraBinVideo * vid, GstElement * muxer);
|
||||||
|
|
||||||
|
void
|
||||||
|
gst_camerabin_video_set_audio_src (GstCameraBinVideo * vid,
|
||||||
|
GstElement * audio_src);
|
||||||
|
|
||||||
|
|
||||||
|
gboolean gst_camerabin_video_get_mute (GstCameraBinVideo * vid);
|
||||||
|
|
||||||
|
GstElement *gst_camerabin_video_get_post (GstCameraBinVideo * vid);
|
||||||
|
|
||||||
|
GstElement *gst_camerabin_video_get_video_enc (GstCameraBinVideo * vid);
|
||||||
|
|
||||||
|
GstElement *gst_camerabin_video_get_audio_enc (GstCameraBinVideo * vid);
|
||||||
|
|
||||||
|
GstElement *gst_camerabin_video_get_muxer (GstCameraBinVideo * vid);
|
||||||
|
|
||||||
|
GstElement *gst_camerabin_video_get_audio_src (GstCameraBinVideo * vid);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif /* #ifndef __CAMERABIN_VIDEO_H__ */
|
6
gst/camerabin/gstcamerabin-marshal.list
Normal file
6
gst/camerabin/gstcamerabin-marshal.list
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
# glib-genmarshal --header --prefix=gst_camerabin camerabin_marshal.marshal > camerabin_marshal.h
|
||||||
|
# glib-genmarshal --body --prefix=gst_camerabin camerabin_marshal.marshal > camerabin_marshal.c
|
||||||
|
|
||||||
|
VOID:INT,INT,INT,INT
|
||||||
|
VOID:INT,INT
|
||||||
|
|
2762
gst/camerabin/gstcamerabin.c
Normal file
2762
gst/camerabin/gstcamerabin.c
Normal file
File diff suppressed because it is too large
Load diff
168
gst/camerabin/gstcamerabin.h
Normal file
168
gst/camerabin/gstcamerabin.h
Normal file
|
@ -0,0 +1,168 @@
|
||||||
|
/*
|
||||||
|
* GStreamer
|
||||||
|
* Copyright (C) 2008 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_H__
|
||||||
|
#define __GST_CAMERABIN_H__
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <gst/gstbin.h>
|
||||||
|
#include <gst/interfaces/photography.h>
|
||||||
|
|
||||||
|
#include "camerabinimage.h"
|
||||||
|
#include "camerabinvideo.h"
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
/* #defines don't like whitespacey bits */
|
||||||
|
#define GST_TYPE_CAMERABIN \
|
||||||
|
(gst_camerabin_get_type())
|
||||||
|
#define GST_CAMERABIN(obj) \
|
||||||
|
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_CAMERABIN,GstCameraBin))
|
||||||
|
#define GST_CAMERABIN_CLASS(klass) \
|
||||||
|
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_CAMERABIN,GstCameraBinClass))
|
||||||
|
#define GST_IS_CAMERABIN(obj) \
|
||||||
|
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_CAMERABIN))
|
||||||
|
#define GST_IS_CAMERABIN_CLASS(klass) \
|
||||||
|
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_CAMERABIN))
|
||||||
|
|
||||||
|
typedef struct _GstCameraBin GstCameraBin;
|
||||||
|
typedef struct _GstCameraBinClass GstCameraBinClass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GstCameraBin:
|
||||||
|
*
|
||||||
|
* The opaque #GstCameraBin structure.
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct _GstCameraBin
|
||||||
|
{
|
||||||
|
GstPipeline parent;
|
||||||
|
|
||||||
|
/* private */
|
||||||
|
GString *filename;
|
||||||
|
gint mode; /* MODE_IMAGE or MODE_VIDEO */
|
||||||
|
guint num_img_buffers; /* no of image buffers captured */
|
||||||
|
gboolean stop_requested; /* TRUE if capturing stop needed */
|
||||||
|
gboolean paused; /* TRUE if capturing paused */
|
||||||
|
|
||||||
|
/* resolution and frames per second of image captured by v4l2 device */
|
||||||
|
gint width;
|
||||||
|
gint height;
|
||||||
|
gint fps_n;
|
||||||
|
gint fps_d;
|
||||||
|
|
||||||
|
/* Caps applied to capsfilters when taking still image */
|
||||||
|
GstCaps *image_capture_caps;
|
||||||
|
|
||||||
|
/* Caps applied to capsfilters when in view finder mode */
|
||||||
|
GstCaps *view_finder_caps;
|
||||||
|
|
||||||
|
/* Caps that videosrc supports */
|
||||||
|
GstCaps *allowed_caps;
|
||||||
|
|
||||||
|
/* The digital zoom (from 100% to 1000%) */
|
||||||
|
gint zoom;
|
||||||
|
|
||||||
|
/* concurrency control */
|
||||||
|
GMutex *capture_mutex;
|
||||||
|
GCond *cond;
|
||||||
|
gboolean capturing;
|
||||||
|
|
||||||
|
/* pad names for output and input selectors */
|
||||||
|
GstPad *pad_src_view;
|
||||||
|
GstPad *pad_view_src;
|
||||||
|
GstPad *pad_src_img;
|
||||||
|
GstPad *pad_view_img;
|
||||||
|
GstPad *pad_src_vid;
|
||||||
|
GstPad *pad_view_vid;
|
||||||
|
|
||||||
|
GstPad *srcpad_zoom_filter;
|
||||||
|
|
||||||
|
GstElement *imgbin; /* bin that holds image capturing elements */
|
||||||
|
GstElement *vidbin; /* bin that holds video capturing elements */
|
||||||
|
GstElement *active_bin; /* image or video bin that is currently in use */
|
||||||
|
|
||||||
|
/* source elements */
|
||||||
|
GstElement *src_vid_src;
|
||||||
|
GstElement *src_filter;
|
||||||
|
GstElement *src_zoom_crop;
|
||||||
|
GstElement *src_zoom_scale;
|
||||||
|
GstElement *src_zoom_filter;
|
||||||
|
GstElement *src_out_sel;
|
||||||
|
|
||||||
|
/* view finder elements */
|
||||||
|
GstElement *view_in_sel;
|
||||||
|
GstElement *view_scale;
|
||||||
|
GstElement *view_sink;
|
||||||
|
|
||||||
|
/* User configurable elements */
|
||||||
|
GstElement *user_vid_src;
|
||||||
|
GstElement *user_vf_sink;
|
||||||
|
|
||||||
|
/* Night mode handling */
|
||||||
|
gboolean night_mode;
|
||||||
|
gint pre_night_fps_n;
|
||||||
|
gint pre_night_fps_d;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GstCameraBinClass:
|
||||||
|
*
|
||||||
|
* The #GstCameraBin class structure.
|
||||||
|
*/
|
||||||
|
struct _GstCameraBinClass
|
||||||
|
{
|
||||||
|
GstPipelineClass parent_class;
|
||||||
|
|
||||||
|
/* action signals */
|
||||||
|
|
||||||
|
void (*user_start) (GstCameraBin * camera);
|
||||||
|
void (*user_stop) (GstCameraBin * camera);
|
||||||
|
void (*user_pause) (GstCameraBin * camera);
|
||||||
|
void (*user_res_fps) (GstCameraBin * camera, gint width, gint height,
|
||||||
|
gint fps_n, gint fps_d);
|
||||||
|
void (*user_image_res) (GstCameraBin * camera, gint width, gint height);
|
||||||
|
|
||||||
|
/* signals (callback) */
|
||||||
|
|
||||||
|
gboolean (*img_done) (GstCameraBin * camera, GString * filename);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GstCameraBinMode:
|
||||||
|
* @MODE_IMAGE: image capture
|
||||||
|
* @MODE_VIDEO: video capture
|
||||||
|
*
|
||||||
|
* Capture mode to use.
|
||||||
|
*/
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
MODE_IMAGE = 0,
|
||||||
|
MODE_VIDEO
|
||||||
|
} GstCameraBinMode;
|
||||||
|
|
||||||
|
GType gst_camerabin_get_type (void);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif /* #ifndef __GST_CAMERABIN_H__ */
|
81
gst/camerabin/gstcamerabincolorbalance.c
Normal file
81
gst/camerabin/gstcamerabincolorbalance.c
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
/*
|
||||||
|
* GStreamer
|
||||||
|
* Copyright (C) 2008 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Includes
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "gstcamerabincolorbalance.h"
|
||||||
|
#include "gstcamerabin.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* static functions implementation
|
||||||
|
*/
|
||||||
|
|
||||||
|
static const GList *
|
||||||
|
gst_camerabin_color_balance_list_channels (GstColorBalance * cb)
|
||||||
|
{
|
||||||
|
if (cb && GST_CAMERABIN (cb)->src_vid_src) {
|
||||||
|
GstColorBalance *cbl = GST_COLOR_BALANCE (GST_CAMERABIN (cb)->src_vid_src);
|
||||||
|
return gst_color_balance_list_channels (cbl);
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_camerabin_color_balance_set_value (GstColorBalance * cb,
|
||||||
|
GstColorBalanceChannel * channel, gint value)
|
||||||
|
{
|
||||||
|
if (cb && GST_CAMERABIN (cb)->src_vid_src) {
|
||||||
|
GstColorBalance *cbl = GST_COLOR_BALANCE (GST_CAMERABIN (cb)->src_vid_src);
|
||||||
|
gst_color_balance_set_value (cbl, channel, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static gint
|
||||||
|
gst_camerabin_color_balance_get_value (GstColorBalance * cb,
|
||||||
|
GstColorBalanceChannel * channel)
|
||||||
|
{
|
||||||
|
if (cb && GST_CAMERABIN (cb)->src_vid_src) {
|
||||||
|
GstColorBalance *cbl = GST_COLOR_BALANCE (GST_CAMERABIN (cb)->src_vid_src);
|
||||||
|
return gst_color_balance_get_value (cbl, channel);
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* extern functions implementation
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
gst_camerabin_color_balance_init (GstColorBalanceClass * iface)
|
||||||
|
{
|
||||||
|
/* FIXME: to get the same type as v4l2src */
|
||||||
|
GST_COLOR_BALANCE_TYPE (iface) = GST_COLOR_BALANCE_HARDWARE;
|
||||||
|
iface->list_channels = gst_camerabin_color_balance_list_channels;
|
||||||
|
iface->set_value = gst_camerabin_color_balance_set_value;
|
||||||
|
iface->get_value = gst_camerabin_color_balance_get_value;
|
||||||
|
}
|
28
gst/camerabin/gstcamerabincolorbalance.h
Normal file
28
gst/camerabin/gstcamerabincolorbalance.h
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
* GStreamer
|
||||||
|
* Copyright (C) 2008 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_CAMERA_COLOR_BALANCE_H__
|
||||||
|
#define __GST_CAMERA_COLOR_BALANCE_H__
|
||||||
|
|
||||||
|
#include <gst/interfaces/colorbalance.h>
|
||||||
|
|
||||||
|
extern void gst_camerabin_color_balance_init (GstColorBalanceClass * iface);
|
||||||
|
|
||||||
|
#endif /* #ifndef __GST_CAMERA_COLOR_BALANCE_H__ */
|
222
gst/camerabin/gstcamerabinphotography.c
Normal file
222
gst/camerabin/gstcamerabinphotography.c
Normal file
|
@ -0,0 +1,222 @@
|
||||||
|
/*
|
||||||
|
* GStreamer
|
||||||
|
* Copyright (C) 2008 Nokia Corporation <multimedia@maemo.org>
|
||||||
|
*
|
||||||
|
* Photography interface implementation for camerabin.
|
||||||
|
*
|
||||||
|
* 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 "gstcamerabinphotography.h"
|
||||||
|
#include "gstcamerabin.h"
|
||||||
|
|
||||||
|
GST_DEBUG_CATEGORY_STATIC (camerabinphoto_debug);
|
||||||
|
#define GST_CAT_DEFAULT camerabinphoto_debug
|
||||||
|
|
||||||
|
#define PHOTOGRAPHY_IS_OK(photo_elem) (GST_IS_ELEMENT (photo_elem) && \
|
||||||
|
gst_element_implements_interface (photo_elem, GST_TYPE_PHOTOGRAPHY))
|
||||||
|
|
||||||
|
#define GST_PHOTOGRAPHY_IMPL_TEMPLATE(function_name, param_type) \
|
||||||
|
static gboolean \
|
||||||
|
gst_camerabin_set_ ## function_name (GstPhotography *photo, param_type param) \
|
||||||
|
{ \
|
||||||
|
GstCameraBin *camera; \
|
||||||
|
gboolean ret = FALSE; \
|
||||||
|
g_return_val_if_fail (photo != NULL, FALSE); \
|
||||||
|
camera = GST_CAMERABIN (photo); \
|
||||||
|
if (PHOTOGRAPHY_IS_OK (camera->src_vid_src)) { \
|
||||||
|
ret = gst_photography_set_ ## function_name (GST_PHOTOGRAPHY (camera->src_vid_src), param); \
|
||||||
|
} \
|
||||||
|
return ret; \
|
||||||
|
} \
|
||||||
|
static gboolean \
|
||||||
|
gst_camerabin_get_ ## function_name (GstPhotography *photo, param_type * param) \
|
||||||
|
{ \
|
||||||
|
GstCameraBin *camera; \
|
||||||
|
gboolean ret = FALSE; \
|
||||||
|
g_return_val_if_fail (photo != NULL, FALSE); \
|
||||||
|
camera = GST_CAMERABIN (photo); \
|
||||||
|
if (PHOTOGRAPHY_IS_OK (camera->src_vid_src)) { \
|
||||||
|
ret = gst_photography_get_ ## function_name (GST_PHOTOGRAPHY (camera->src_vid_src), param); \
|
||||||
|
} \
|
||||||
|
return ret; \
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_PHOTOGRAPHY_IMPL_TEMPLATE (ev_compensation, gfloat);
|
||||||
|
GST_PHOTOGRAPHY_IMPL_TEMPLATE (iso_speed, guint);
|
||||||
|
GST_PHOTOGRAPHY_IMPL_TEMPLATE (white_balance_mode, GstWhiteBalanceMode);
|
||||||
|
GST_PHOTOGRAPHY_IMPL_TEMPLATE (colour_tone_mode, GstColourToneMode);
|
||||||
|
GST_PHOTOGRAPHY_IMPL_TEMPLATE (flash_mode, GstFlashMode);
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_camerabin_set_zoom (GstPhotography * photo, gfloat zoom)
|
||||||
|
{
|
||||||
|
GstCameraBin *camera;
|
||||||
|
|
||||||
|
g_return_val_if_fail (photo != NULL, FALSE);
|
||||||
|
|
||||||
|
camera = GST_CAMERABIN (photo);
|
||||||
|
|
||||||
|
/* camerabin can zoom by itself */
|
||||||
|
g_object_set (camera, "zoom", (gint) (CLAMP (zoom, 1.0, 10.0) * 100), NULL);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_camerabin_get_zoom (GstPhotography * photo, gfloat * zoom)
|
||||||
|
{
|
||||||
|
GstCameraBin *camera;
|
||||||
|
gint cb_zoom = 0;
|
||||||
|
|
||||||
|
g_return_val_if_fail (photo != NULL, FALSE);
|
||||||
|
|
||||||
|
camera = GST_CAMERABIN (photo);
|
||||||
|
|
||||||
|
g_object_get (camera, "zoom", &cb_zoom, NULL);
|
||||||
|
*zoom = (gfloat) (cb_zoom / 100.0);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_camerabin_set_scene_mode (GstPhotography * photo, GstSceneMode scene_mode)
|
||||||
|
{
|
||||||
|
GstCameraBin *camera;
|
||||||
|
gboolean ret = FALSE;
|
||||||
|
|
||||||
|
g_return_val_if_fail (photo != NULL, FALSE);
|
||||||
|
|
||||||
|
camera = GST_CAMERABIN (photo);
|
||||||
|
|
||||||
|
if (scene_mode == GST_PHOTOGRAPHY_SCENE_MODE_NIGHT) {
|
||||||
|
GST_DEBUG ("enabling night mode, lowering fps");
|
||||||
|
/* Make camerabin select the lowest allowed frame rate */
|
||||||
|
camera->night_mode = TRUE;
|
||||||
|
/* Remember frame rate before setting night mode */
|
||||||
|
camera->pre_night_fps_n = camera->fps_n;
|
||||||
|
camera->pre_night_fps_d = camera->fps_d;
|
||||||
|
g_signal_emit_by_name (camera, "user-res-fps", camera->width,
|
||||||
|
camera->height, 0, 0, 0);
|
||||||
|
} else {
|
||||||
|
if (camera->night_mode) {
|
||||||
|
GST_DEBUG ("disabling night mode, restoring fps to %d/%d",
|
||||||
|
camera->pre_night_fps_n, camera->pre_night_fps_d);
|
||||||
|
camera->night_mode = FALSE;
|
||||||
|
g_signal_emit_by_name (camera, "user-res-fps", camera->width,
|
||||||
|
camera->height, camera->pre_night_fps_n, camera->pre_night_fps_d, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PHOTOGRAPHY_IS_OK (camera->src_vid_src)) {
|
||||||
|
ret = gst_photography_set_scene_mode (GST_PHOTOGRAPHY (camera->src_vid_src),
|
||||||
|
scene_mode);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_camerabin_get_scene_mode (GstPhotography * photo, GstSceneMode * scene_mode)
|
||||||
|
{
|
||||||
|
GstCameraBin *camera;
|
||||||
|
gboolean ret = FALSE;
|
||||||
|
|
||||||
|
g_return_val_if_fail (photo != NULL, FALSE);
|
||||||
|
|
||||||
|
camera = GST_CAMERABIN (photo);
|
||||||
|
|
||||||
|
if (PHOTOGRAPHY_IS_OK (camera->src_vid_src)) {
|
||||||
|
ret = gst_photography_get_scene_mode (GST_PHOTOGRAPHY (camera->src_vid_src),
|
||||||
|
scene_mode);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static GstPhotoCaps
|
||||||
|
gst_camerabin_get_capabilities (GstPhotography * photo)
|
||||||
|
{
|
||||||
|
GstCameraBin *camera;
|
||||||
|
/* camerabin can zoom by itself */
|
||||||
|
GstPhotoCaps pcaps = GST_PHOTOGRAPHY_CAPS_ZOOM;
|
||||||
|
|
||||||
|
g_return_val_if_fail (photo != NULL, FALSE);
|
||||||
|
|
||||||
|
camera = GST_CAMERABIN (photo);
|
||||||
|
|
||||||
|
if (GST_IS_ELEMENT (camera->src_vid_src) &&
|
||||||
|
gst_element_implements_interface (camera->src_vid_src,
|
||||||
|
GST_TYPE_PHOTOGRAPHY)) {
|
||||||
|
GstPhotography *p2 = GST_PHOTOGRAPHY (camera->src_vid_src);
|
||||||
|
pcaps |= gst_photography_get_capabilities (p2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pcaps;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_camerabin_set_autofocus (GstPhotography * photo, gboolean on)
|
||||||
|
{
|
||||||
|
GstCameraBin *camera;
|
||||||
|
|
||||||
|
g_return_if_fail (photo != NULL);
|
||||||
|
|
||||||
|
camera = GST_CAMERABIN (photo);
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (camera, "setting autofocus %s", on ? "ON" : "OFF");
|
||||||
|
|
||||||
|
if (PHOTOGRAPHY_IS_OK (camera->src_vid_src)) {
|
||||||
|
gst_photography_set_autofocus (GST_PHOTOGRAPHY (camera->src_vid_src), on);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
gst_camerabin_photography_init (GstPhotographyInterface * iface)
|
||||||
|
{
|
||||||
|
GST_DEBUG_CATEGORY_INIT (camerabinphoto_debug, "camerabinphoto", 0,
|
||||||
|
"Camerabin photography interface debugging");
|
||||||
|
|
||||||
|
GST_INFO ("initing");
|
||||||
|
|
||||||
|
iface->set_ev_compensation = gst_camerabin_set_ev_compensation;
|
||||||
|
iface->get_ev_compensation = gst_camerabin_get_ev_compensation;
|
||||||
|
|
||||||
|
iface->set_iso_speed = gst_camerabin_set_iso_speed;
|
||||||
|
iface->get_iso_speed = gst_camerabin_get_iso_speed;
|
||||||
|
|
||||||
|
iface->set_white_balance_mode = gst_camerabin_set_white_balance_mode;
|
||||||
|
iface->get_white_balance_mode = gst_camerabin_get_white_balance_mode;
|
||||||
|
|
||||||
|
iface->set_colour_tone_mode = gst_camerabin_set_colour_tone_mode;
|
||||||
|
iface->get_colour_tone_mode = gst_camerabin_get_colour_tone_mode;
|
||||||
|
|
||||||
|
iface->set_scene_mode = gst_camerabin_set_scene_mode;
|
||||||
|
iface->get_scene_mode = gst_camerabin_get_scene_mode;
|
||||||
|
|
||||||
|
iface->set_flash_mode = gst_camerabin_set_flash_mode;
|
||||||
|
iface->get_flash_mode = gst_camerabin_get_flash_mode;
|
||||||
|
|
||||||
|
iface->set_zoom = gst_camerabin_set_zoom;
|
||||||
|
iface->get_zoom = gst_camerabin_get_zoom;
|
||||||
|
|
||||||
|
iface->get_capabilities = gst_camerabin_get_capabilities;
|
||||||
|
|
||||||
|
iface->set_autofocus = gst_camerabin_set_autofocus;
|
||||||
|
}
|
30
gst/camerabin/gstcamerabinphotography.h
Normal file
30
gst/camerabin/gstcamerabinphotography.h
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* GStreamer
|
||||||
|
* Copyright (C) 2008 Nokia Corporation <multimedia@maemo.org>
|
||||||
|
*
|
||||||
|
* Photography interface implementation for camerabin
|
||||||
|
*
|
||||||
|
* 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_PHOTOGRAPHY_H__
|
||||||
|
#define __GST_CAMERABIN_PHOTOGRAPHY_H__
|
||||||
|
|
||||||
|
#include <gst/interfaces/photography.h>
|
||||||
|
|
||||||
|
void gst_camerabin_photography_init (GstPhotographyInterface * iface);
|
||||||
|
|
||||||
|
#endif /* #ifndef __GST_CAMERABIN_PHOTOGRAPHY_H__ */
|
73
gst/camerabin/gstcamerabinxoverlay.c
Normal file
73
gst/camerabin/gstcamerabinxoverlay.c
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
/*
|
||||||
|
* GStreamer
|
||||||
|
* Copyright (C) 2008 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Includes
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "gstcamerabinxoverlay.h"
|
||||||
|
#include "gstcamerabin.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* static functions implementation
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_camerabin_expose (GstXOverlay * overlay)
|
||||||
|
{
|
||||||
|
if (overlay && GST_CAMERABIN (overlay)->view_sink) {
|
||||||
|
GstXOverlay *xoverlay = GST_X_OVERLAY (GST_CAMERABIN (overlay)->view_sink);
|
||||||
|
gst_x_overlay_expose (xoverlay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_camerabin_set_xwindow_id (GstXOverlay * overlay, gulong xwindow_id)
|
||||||
|
{
|
||||||
|
if (overlay && GST_CAMERABIN (overlay)->view_sink) {
|
||||||
|
GstXOverlay *xoverlay = GST_X_OVERLAY (GST_CAMERABIN (overlay)->view_sink);
|
||||||
|
gst_x_overlay_set_xwindow_id (xoverlay, xwindow_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_camerabin_set_event_handling (GstXOverlay * overlay, gboolean handle_events)
|
||||||
|
{
|
||||||
|
if (overlay && GST_CAMERABIN (overlay)->view_sink) {
|
||||||
|
GstXOverlay *xoverlay = GST_X_OVERLAY (GST_CAMERABIN (overlay)->view_sink);
|
||||||
|
gst_x_overlay_handle_events (xoverlay, handle_events);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* extern functions implementation
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
gst_camerabin_xoverlay_init (GstXOverlayClass * iface)
|
||||||
|
{
|
||||||
|
iface->set_xwindow_id = gst_camerabin_set_xwindow_id;
|
||||||
|
iface->expose = gst_camerabin_expose;
|
||||||
|
iface->handle_events = gst_camerabin_set_event_handling;
|
||||||
|
}
|
28
gst/camerabin/gstcamerabinxoverlay.h
Normal file
28
gst/camerabin/gstcamerabinxoverlay.h
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
* GStreamer
|
||||||
|
* Copyright (C) 2008 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_CAMERAXOVERLAY_H__
|
||||||
|
#define __GST_CAMERAXOVERLAY_H__
|
||||||
|
|
||||||
|
#include <gst/interfaces/xoverlay.h>
|
||||||
|
|
||||||
|
extern void gst_camerabin_xoverlay_init (GstXOverlayClass * iface);
|
||||||
|
|
||||||
|
#endif /* #ifndef __GST_CAMERAXOVERLAY_H__ */
|
Loading…
Reference in a new issue