2010-10-27 17:30:11 +00:00
|
|
|
/*
|
2010-11-04 18:02:50 +00:00
|
|
|
* Copyright (C) 2010 Ole André Vadla Ravnås <oravnas@cisco.com>
|
2010-10-27 17:30:11 +00:00
|
|
|
*
|
|
|
|
* 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
|
2012-11-03 20:38:00 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2010-10-27 17:30:11 +00:00
|
|
|
*/
|
|
|
|
|
2010-11-04 17:59:44 +00:00
|
|
|
#include "celvideosrc.h"
|
2010-10-27 17:30:11 +00:00
|
|
|
|
|
|
|
#include "coremediabuffer.h"
|
|
|
|
|
|
|
|
#include <gst/video/video.h>
|
|
|
|
|
2010-11-10 19:44:15 +00:00
|
|
|
#define DEFAULT_DEVICE_INDEX -1
|
|
|
|
#define DEFAULT_DO_STATS FALSE
|
2010-10-27 17:30:11 +00:00
|
|
|
|
2010-11-11 23:40:33 +00:00
|
|
|
#define QUEUE_READY_LOCK(instance) GST_OBJECT_LOCK (instance)
|
|
|
|
#define QUEUE_READY_UNLOCK(instance) GST_OBJECT_UNLOCK (instance)
|
|
|
|
#define QUEUE_READY_WAIT(instance) \
|
|
|
|
g_cond_wait (instance->ready_cond, GST_OBJECT_GET_LOCK (instance))
|
|
|
|
#define QUEUE_READY_NOTIFY(instance) g_cond_signal (instance->ready_cond)
|
2010-10-27 17:30:11 +00:00
|
|
|
|
2010-11-04 17:59:44 +00:00
|
|
|
GST_DEBUG_CATEGORY (gst_cel_video_src_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_cel_video_src_debug
|
2010-10-27 17:30:11 +00:00
|
|
|
|
|
|
|
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2010-11-08 22:54:31 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("NV12") ";"
|
2010-11-08 12:52:49 +00:00
|
|
|
GST_VIDEO_CAPS_YUV ("YUY2"))
|
2010-10-27 17:30:11 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2010-11-10 19:44:15 +00:00
|
|
|
PROP_DEVICE_INDEX,
|
2010-11-05 15:51:57 +00:00
|
|
|
PROP_DO_STATS,
|
|
|
|
PROP_FPS
|
2010-10-27 17:30:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
guint index;
|
|
|
|
|
|
|
|
GstVideoFormat video_format;
|
|
|
|
guint32 fourcc;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint fps_n;
|
|
|
|
gint fps_d;
|
2010-11-04 17:59:44 +00:00
|
|
|
} GstCelVideoFormat;
|
|
|
|
|
|
|
|
static gboolean gst_cel_video_src_open_device (GstCelVideoSrc * self);
|
|
|
|
static void gst_cel_video_src_close_device (GstCelVideoSrc * self);
|
|
|
|
static void gst_cel_video_src_ensure_device_caps_and_formats
|
|
|
|
(GstCelVideoSrc * self);
|
|
|
|
static void gst_cel_video_src_release_device_caps_and_formats
|
|
|
|
(GstCelVideoSrc * self);
|
|
|
|
static gboolean gst_cel_video_src_select_format (GstCelVideoSrc * self,
|
|
|
|
GstCelVideoFormat * format);
|
|
|
|
|
2010-11-05 14:14:08 +00:00
|
|
|
static gboolean gst_cel_video_src_parse_stream_format
|
|
|
|
(GstCelVideoSrc * self, guint index, CFDictionaryRef stream_format,
|
2010-11-04 17:59:44 +00:00
|
|
|
GstCelVideoFormat * format);
|
2010-11-05 14:14:08 +00:00
|
|
|
static OSStatus gst_cel_video_src_set_stream_property_i32
|
2010-11-04 17:59:44 +00:00
|
|
|
(GstCelVideoSrc * self, CFStringRef name, SInt32 value);
|
2010-11-05 14:14:08 +00:00
|
|
|
static OSStatus gst_cel_video_src_set_stream_property_value
|
|
|
|
(GstCelVideoSrc * self, CFStringRef name, CFTypeRef value);
|
2010-10-27 17:30:11 +00:00
|
|
|
|
|
|
|
static GstPushSrcClass *parent_class;
|
|
|
|
|
2010-11-04 17:59:44 +00:00
|
|
|
GST_BOILERPLATE (GstCelVideoSrc, gst_cel_video_src, GstPushSrc,
|
2010-10-27 17:30:11 +00:00
|
|
|
GST_TYPE_PUSH_SRC);
|
|
|
|
|
|
|
|
static void
|
2010-11-04 17:59:44 +00:00
|
|
|
gst_cel_video_src_init (GstCelVideoSrc * self, GstCelVideoSrcClass * gclass)
|
2010-10-27 17:30:11 +00:00
|
|
|
{
|
|
|
|
GstBaseSrc *base_src = GST_BASE_SRC_CAST (self);
|
|
|
|
|
|
|
|
gst_base_src_set_live (base_src, TRUE);
|
|
|
|
gst_base_src_set_format (base_src, GST_FORMAT_TIME);
|
|
|
|
|
2010-11-11 23:40:33 +00:00
|
|
|
self->ready_cond = g_cond_new ();
|
2010-10-27 17:30:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-04 17:59:44 +00:00
|
|
|
gst_cel_video_src_dispose (GObject * object)
|
2010-10-27 17:30:11 +00:00
|
|
|
{
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-04 17:59:44 +00:00
|
|
|
gst_cel_video_src_finalize (GObject * object)
|
2010-10-27 17:30:11 +00:00
|
|
|
{
|
2010-11-04 17:59:44 +00:00
|
|
|
GstCelVideoSrc *self = GST_CEL_VIDEO_SRC_CAST (object);
|
2010-10-27 17:30:11 +00:00
|
|
|
|
2010-11-11 23:40:33 +00:00
|
|
|
g_cond_free (self->ready_cond);
|
2010-10-27 17:30:11 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-04 17:59:44 +00:00
|
|
|
gst_cel_video_src_get_property (GObject * object, guint prop_id,
|
2010-10-27 17:30:11 +00:00
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2010-11-04 17:59:44 +00:00
|
|
|
GstCelVideoSrc *self = GST_CEL_VIDEO_SRC_CAST (object);
|
2010-10-27 17:30:11 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2010-11-10 19:44:15 +00:00
|
|
|
case PROP_DEVICE_INDEX:
|
|
|
|
g_value_set_int (value, self->device_index);
|
|
|
|
break;
|
2010-10-27 17:30:11 +00:00
|
|
|
case PROP_DO_STATS:
|
|
|
|
g_value_set_boolean (value, self->do_stats);
|
|
|
|
break;
|
2010-11-05 15:51:57 +00:00
|
|
|
case PROP_FPS:
|
|
|
|
GST_OBJECT_LOCK (object);
|
|
|
|
g_value_set_int (value, self->fps);
|
|
|
|
GST_OBJECT_UNLOCK (object);
|
|
|
|
break;
|
2010-10-27 17:30:11 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-04 17:59:44 +00:00
|
|
|
gst_cel_video_src_set_property (GObject * object, guint prop_id,
|
2010-10-27 17:30:11 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2010-11-04 17:59:44 +00:00
|
|
|
GstCelVideoSrc *self = GST_CEL_VIDEO_SRC_CAST (object);
|
2010-10-27 17:30:11 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2010-11-10 19:44:15 +00:00
|
|
|
case PROP_DEVICE_INDEX:
|
|
|
|
self->device_index = g_value_get_int (value);
|
|
|
|
break;
|
2010-10-27 17:30:11 +00:00
|
|
|
case PROP_DO_STATS:
|
|
|
|
self->do_stats = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstStateChangeReturn
|
2010-11-04 17:59:44 +00:00
|
|
|
gst_cel_video_src_change_state (GstElement * element, GstStateChange transition)
|
2010-10-27 17:30:11 +00:00
|
|
|
{
|
2010-11-04 17:59:44 +00:00
|
|
|
GstCelVideoSrc *self = GST_CEL_VIDEO_SRC_CAST (element);
|
2010-10-27 17:30:11 +00:00
|
|
|
GstStateChangeReturn ret;
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
2010-11-04 17:59:44 +00:00
|
|
|
if (!gst_cel_video_src_open_device (self))
|
2010-10-27 17:30:11 +00:00
|
|
|
goto open_failed;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
2010-11-04 17:59:44 +00:00
|
|
|
gst_cel_video_src_close_device (self);
|
2010-10-27 17:30:11 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
open_failed:
|
|
|
|
{
|
|
|
|
return GST_STATE_CHANGE_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstCaps *
|
2010-11-04 17:59:44 +00:00
|
|
|
gst_cel_video_src_get_caps (GstBaseSrc * basesrc)
|
2010-10-27 17:30:11 +00:00
|
|
|
{
|
2010-11-04 17:59:44 +00:00
|
|
|
GstCelVideoSrc *self = GST_CEL_VIDEO_SRC_CAST (basesrc);
|
2010-10-27 17:30:11 +00:00
|
|
|
GstCaps *result;
|
|
|
|
|
|
|
|
if (self->device != NULL) {
|
2010-11-04 17:59:44 +00:00
|
|
|
gst_cel_video_src_ensure_device_caps_and_formats (self);
|
2010-10-27 17:30:11 +00:00
|
|
|
|
|
|
|
result = gst_caps_ref (self->device_caps);
|
|
|
|
} else {
|
|
|
|
result = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result != NULL) {
|
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
str = gst_caps_to_string (result);
|
|
|
|
GST_DEBUG_OBJECT (self, "returning: %s", str);
|
|
|
|
g_free (str);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2010-11-04 17:59:44 +00:00
|
|
|
gst_cel_video_src_set_caps (GstBaseSrc * basesrc, GstCaps * caps)
|
2010-10-27 17:30:11 +00:00
|
|
|
{
|
2010-11-04 17:59:44 +00:00
|
|
|
GstCelVideoSrc *self = GST_CEL_VIDEO_SRC_CAST (basesrc);
|
2010-10-27 17:30:11 +00:00
|
|
|
GstVideoFormat video_format;
|
|
|
|
gint width, height, fps_n, fps_d;
|
|
|
|
guint i;
|
2010-11-04 17:59:44 +00:00
|
|
|
GstCelVideoFormat *selected_format;
|
2010-10-27 17:30:11 +00:00
|
|
|
|
|
|
|
if (self->device == NULL)
|
|
|
|
goto no_device;
|
|
|
|
|
|
|
|
if (!gst_video_format_parse_caps (caps, &video_format, &width, &height))
|
|
|
|
goto invalid_format;
|
|
|
|
if (!gst_video_parse_caps_framerate (caps, &fps_n, &fps_d))
|
|
|
|
goto invalid_format;
|
|
|
|
|
2010-11-04 17:59:44 +00:00
|
|
|
gst_cel_video_src_ensure_device_caps_and_formats (self);
|
2010-10-27 17:30:11 +00:00
|
|
|
|
|
|
|
selected_format = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i != self->device_formats->len; i++) {
|
2010-11-04 17:59:44 +00:00
|
|
|
GstCelVideoFormat *format;
|
2010-10-27 17:30:11 +00:00
|
|
|
|
2010-11-04 17:59:44 +00:00
|
|
|
format = &g_array_index (self->device_formats, GstCelVideoFormat, i);
|
2010-10-27 17:30:11 +00:00
|
|
|
if (format->video_format == video_format &&
|
|
|
|
format->width == width && format->height == height &&
|
|
|
|
format->fps_n == fps_n && format->fps_d == fps_d) {
|
|
|
|
selected_format = format;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selected_format == NULL)
|
|
|
|
goto invalid_format;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (self, "selecting format %u", selected_format->index);
|
|
|
|
|
2010-11-04 17:59:44 +00:00
|
|
|
if (!gst_cel_video_src_select_format (self, selected_format))
|
2010-10-27 17:30:11 +00:00
|
|
|
goto select_failed;
|
|
|
|
|
2010-11-04 17:59:44 +00:00
|
|
|
gst_cel_video_src_release_device_caps_and_formats (self);
|
2010-10-27 17:30:11 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_device:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (self, RESOURCE, FAILED, ("no device"), (NULL));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
invalid_format:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (self, RESOURCE, FAILED, ("invalid format"), (NULL));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
select_failed:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (self, RESOURCE, FAILED, ("failed to select format"),
|
|
|
|
(NULL));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2010-11-04 17:59:44 +00:00
|
|
|
gst_cel_video_src_start (GstBaseSrc * basesrc)
|
2010-10-27 17:30:11 +00:00
|
|
|
{
|
2010-11-04 17:59:44 +00:00
|
|
|
GstCelVideoSrc *self = GST_CEL_VIDEO_SRC_CAST (basesrc);
|
2010-10-27 17:30:11 +00:00
|
|
|
|
2010-11-11 23:40:33 +00:00
|
|
|
g_atomic_int_set (&self->is_running, TRUE);
|
2010-10-27 17:30:11 +00:00
|
|
|
self->offset = 0;
|
|
|
|
|
2010-11-05 15:51:57 +00:00
|
|
|
self->last_sampling = GST_CLOCK_TIME_NONE;
|
|
|
|
self->count = 0;
|
|
|
|
self->fps = -1;
|
|
|
|
|
2010-10-27 17:30:11 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2010-11-04 17:59:44 +00:00
|
|
|
gst_cel_video_src_stop (GstBaseSrc * basesrc)
|
2010-10-27 17:30:11 +00:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2010-11-04 17:59:44 +00:00
|
|
|
gst_cel_video_src_query (GstBaseSrc * basesrc, GstQuery * query)
|
2010-10-27 17:30:11 +00:00
|
|
|
{
|
2010-11-04 17:59:44 +00:00
|
|
|
GstCelVideoSrc *self = GST_CEL_VIDEO_SRC_CAST (basesrc);
|
2010-10-27 17:30:11 +00:00
|
|
|
gboolean result = FALSE;
|
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_LATENCY:{
|
|
|
|
GstClockTime min_latency, max_latency;
|
|
|
|
|
|
|
|
if (self->device == NULL || !GST_CLOCK_TIME_IS_VALID (self->duration))
|
|
|
|
goto beach;
|
|
|
|
|
|
|
|
min_latency = max_latency = self->duration;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (self, "reporting latency of min %" GST_TIME_FORMAT
|
|
|
|
" max %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (min_latency), GST_TIME_ARGS (max_latency));
|
|
|
|
|
|
|
|
gst_query_set_latency (query, TRUE, min_latency, max_latency);
|
|
|
|
result = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
result = GST_BASE_SRC_CLASS (parent_class)->query (basesrc, query);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
beach:
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2010-11-04 17:59:44 +00:00
|
|
|
gst_cel_video_src_unlock (GstBaseSrc * basesrc)
|
2010-10-27 17:30:11 +00:00
|
|
|
{
|
2010-11-04 17:59:44 +00:00
|
|
|
GstCelVideoSrc *self = GST_CEL_VIDEO_SRC_CAST (basesrc);
|
2010-10-27 17:30:11 +00:00
|
|
|
|
2010-11-11 23:40:33 +00:00
|
|
|
g_atomic_int_set (&self->is_running, FALSE);
|
|
|
|
|
|
|
|
QUEUE_READY_LOCK (self);
|
|
|
|
QUEUE_READY_NOTIFY (self);
|
|
|
|
QUEUE_READY_UNLOCK (self);
|
2010-10-27 17:30:11 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2010-11-04 17:59:44 +00:00
|
|
|
gst_cel_video_src_unlock_stop (GstBaseSrc * basesrc)
|
2010-10-27 17:30:11 +00:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-11-11 23:40:33 +00:00
|
|
|
static void
|
|
|
|
gst_cel_video_src_on_queue_ready (void *triggerRefcon,
|
|
|
|
CMBufferQueueTriggerToken triggerToken)
|
2010-10-27 17:30:11 +00:00
|
|
|
{
|
2010-11-11 23:40:33 +00:00
|
|
|
GstCelVideoSrc *self = GST_CEL_VIDEO_SRC_CAST (triggerRefcon);
|
2010-10-27 17:30:11 +00:00
|
|
|
|
2010-11-11 23:40:33 +00:00
|
|
|
QUEUE_READY_LOCK (self);
|
|
|
|
self->queue_is_ready = TRUE;
|
|
|
|
QUEUE_READY_NOTIFY (self);
|
|
|
|
QUEUE_READY_UNLOCK (self);
|
2010-10-27 17:30:11 +00:00
|
|
|
}
|
|
|
|
|
2010-11-05 15:51:57 +00:00
|
|
|
static void
|
|
|
|
gst_cel_video_src_timestamp_buffer (GstCelVideoSrc * self, GstBuffer * buf)
|
2010-10-27 17:30:11 +00:00
|
|
|
{
|
|
|
|
GstClock *clock;
|
|
|
|
GstClockTime ts;
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (self);
|
|
|
|
if ((clock = GST_ELEMENT_CLOCK (self)) != NULL) {
|
|
|
|
ts = gst_clock_get_time (clock);
|
|
|
|
|
|
|
|
if (ts > GST_ELEMENT (self)->base_time)
|
|
|
|
ts -= GST_ELEMENT (self)->base_time;
|
|
|
|
else
|
|
|
|
ts = 0;
|
|
|
|
|
|
|
|
if (ts > self->duration)
|
|
|
|
ts -= self->duration;
|
|
|
|
else
|
|
|
|
ts = 0;
|
|
|
|
} else {
|
|
|
|
ts = GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (self);
|
|
|
|
|
2010-11-05 15:51:57 +00:00
|
|
|
GST_BUFFER_OFFSET (buf) = self->offset;
|
|
|
|
GST_BUFFER_OFFSET_END (buf) = self->offset + 1;
|
|
|
|
GST_BUFFER_TIMESTAMP (buf) = ts;
|
|
|
|
GST_BUFFER_DURATION (buf) = self->duration;
|
|
|
|
|
|
|
|
if (self->offset == 0)
|
|
|
|
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
|
2010-10-27 17:30:11 +00:00
|
|
|
|
|
|
|
self->offset++;
|
2010-11-05 15:51:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_cel_video_src_update_statistics (GstCelVideoSrc * self)
|
|
|
|
{
|
|
|
|
GstClock *clock;
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (self);
|
|
|
|
clock = GST_ELEMENT_CLOCK (self);
|
|
|
|
if (clock != NULL)
|
|
|
|
gst_object_ref (clock);
|
|
|
|
GST_OBJECT_UNLOCK (self);
|
|
|
|
|
|
|
|
if (clock != NULL) {
|
|
|
|
GstClockTime now = gst_clock_get_time (clock);
|
|
|
|
gst_object_unref (clock);
|
|
|
|
|
|
|
|
self->count++;
|
|
|
|
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (self->last_sampling)) {
|
|
|
|
if (now - self->last_sampling >= GST_SECOND) {
|
|
|
|
GST_OBJECT_LOCK (self);
|
|
|
|
self->fps = self->count;
|
|
|
|
GST_OBJECT_UNLOCK (self);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (self), "fps");
|
|
|
|
|
|
|
|
self->last_sampling = now;
|
|
|
|
self->count = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
self->last_sampling = now;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_cel_video_src_create (GstPushSrc * pushsrc, GstBuffer ** buf)
|
|
|
|
{
|
|
|
|
GstCelVideoSrc *self = GST_CEL_VIDEO_SRC_CAST (pushsrc);
|
|
|
|
GstCMApi *cm = self->ctx->cm;
|
2010-11-11 23:40:33 +00:00
|
|
|
CMSampleBufferRef sbuf;
|
2010-11-05 15:51:57 +00:00
|
|
|
|
|
|
|
sbuf = cm->CMBufferQueueDequeueAndRetain (self->queue);
|
|
|
|
|
2010-11-11 23:40:33 +00:00
|
|
|
while (sbuf == NULL) {
|
|
|
|
QUEUE_READY_LOCK (self);
|
|
|
|
while (!self->queue_is_ready && g_atomic_int_get (&self->is_running))
|
|
|
|
QUEUE_READY_WAIT (self);
|
|
|
|
self->queue_is_ready = FALSE;
|
|
|
|
QUEUE_READY_UNLOCK (self);
|
|
|
|
|
|
|
|
if (G_UNLIKELY (!g_atomic_int_get (&self->is_running)))
|
|
|
|
goto shutting_down;
|
|
|
|
|
|
|
|
sbuf = cm->CMBufferQueueDequeueAndRetain (self->queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (G_UNLIKELY (!g_atomic_int_get (&self->is_running)))
|
2010-11-05 15:51:57 +00:00
|
|
|
goto shutting_down;
|
|
|
|
|
|
|
|
*buf = gst_core_media_buffer_new (self->ctx, sbuf);
|
|
|
|
gst_cel_video_src_timestamp_buffer (self, *buf);
|
2010-10-27 17:30:11 +00:00
|
|
|
|
|
|
|
cm->FigSampleBufferRelease (sbuf);
|
|
|
|
|
2010-11-05 15:51:57 +00:00
|
|
|
if (self->do_stats)
|
|
|
|
gst_cel_video_src_update_statistics (self);
|
|
|
|
|
2010-10-27 17:30:11 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
shutting_down:
|
|
|
|
{
|
|
|
|
cm->FigSampleBufferRelease (sbuf);
|
2012-02-08 15:37:13 +00:00
|
|
|
return GST_FLOW_FLUSHING;
|
2010-10-27 17:30:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2010-11-04 17:59:44 +00:00
|
|
|
gst_cel_video_src_open_device (GstCelVideoSrc * self)
|
2010-10-27 17:30:11 +00:00
|
|
|
{
|
|
|
|
GstCoreMediaCtx *ctx = NULL;
|
|
|
|
GError *error = NULL;
|
|
|
|
GstCMApi *cm = NULL;
|
|
|
|
GstMTApi *mt = NULL;
|
|
|
|
GstCelApi *cel = NULL;
|
2010-11-02 21:53:33 +00:00
|
|
|
OSStatus status;
|
2010-10-27 17:30:11 +00:00
|
|
|
FigCaptureDeviceRef device = NULL;
|
|
|
|
FigBaseObjectRef device_base;
|
|
|
|
FigBaseVTable *device_vt;
|
2010-11-10 19:44:15 +00:00
|
|
|
CFArrayRef stream_array = NULL;
|
|
|
|
CFIndex stream_index;
|
2010-10-27 17:30:11 +00:00
|
|
|
FigCaptureStreamRef stream = NULL;
|
|
|
|
FigBaseObjectRef stream_base;
|
|
|
|
FigBaseVTable *stream_vt;
|
2010-11-02 21:53:33 +00:00
|
|
|
CMBufferQueueRef queue = NULL;
|
2010-11-11 23:40:33 +00:00
|
|
|
CMTime ignored_time;
|
2010-10-27 17:30:11 +00:00
|
|
|
|
|
|
|
ctx = gst_core_media_ctx_new (GST_API_CORE_VIDEO | GST_API_CORE_MEDIA
|
|
|
|
| GST_API_MEDIA_TOOLBOX | GST_API_CELESTIAL, &error);
|
|
|
|
if (error != NULL)
|
|
|
|
goto api_error;
|
|
|
|
cm = ctx->cm;
|
|
|
|
mt = ctx->mt;
|
|
|
|
cel = ctx->cel;
|
|
|
|
|
|
|
|
status = cel->FigCreateCaptureDevicesAndStreamsForPreset (NULL,
|
|
|
|
*(cel->kFigRecorderCapturePreset_VideoRecording), NULL,
|
|
|
|
&device, &stream, NULL, NULL);
|
2010-11-02 21:53:33 +00:00
|
|
|
if (status == kCelError_ResourceBusy)
|
2010-10-27 17:30:11 +00:00
|
|
|
goto device_busy;
|
2010-11-02 21:53:33 +00:00
|
|
|
else if (status != noErr)
|
2010-10-27 17:30:11 +00:00
|
|
|
goto unexpected_error;
|
|
|
|
|
|
|
|
device_base = mt->FigCaptureDeviceGetFigBaseObject (device);
|
|
|
|
device_vt = cm->FigBaseObjectGetVTable (device_base);
|
|
|
|
|
2010-11-10 19:44:15 +00:00
|
|
|
status = device_vt->base->CopyProperty (device_base,
|
|
|
|
*(mt->kFigCaptureDeviceProperty_StreamArray), NULL,
|
|
|
|
(CFTypeRef *) & stream_array);
|
|
|
|
if (status != noErr)
|
|
|
|
goto unexpected_error;
|
|
|
|
|
|
|
|
if (self->device_index >= 0)
|
|
|
|
stream_index = self->device_index;
|
|
|
|
else
|
|
|
|
stream_index = 0;
|
|
|
|
|
|
|
|
if (stream_index >= CFArrayGetCount (stream_array))
|
|
|
|
goto invalid_device_index;
|
|
|
|
|
|
|
|
CFRelease (stream);
|
|
|
|
stream = (FigCaptureStreamRef) CFArrayGetValueAtIndex (stream_array,
|
|
|
|
stream_index);
|
|
|
|
CFRetain (stream);
|
|
|
|
|
2010-10-27 17:30:11 +00:00
|
|
|
stream_base = mt->FigCaptureStreamGetFigBaseObject (stream);
|
|
|
|
stream_vt = cm->FigBaseObjectGetVTable (stream_base);
|
|
|
|
|
|
|
|
status = stream_vt->base->CopyProperty (stream_base,
|
|
|
|
*(mt->kFigCaptureStreamProperty_BufferQueue), NULL, &queue);
|
2010-11-02 21:53:33 +00:00
|
|
|
if (status != noErr)
|
2010-10-27 17:30:11 +00:00
|
|
|
goto unexpected_error;
|
|
|
|
|
2010-11-11 23:40:33 +00:00
|
|
|
self->queue_is_ready = FALSE;
|
2010-10-27 17:30:11 +00:00
|
|
|
|
2010-11-11 23:40:33 +00:00
|
|
|
ignored_time = cm->CMTimeMake (1, 1);
|
|
|
|
status = cm->CMBufferQueueInstallTrigger (queue,
|
|
|
|
gst_cel_video_src_on_queue_ready, self,
|
|
|
|
kCMBufferQueueTrigger_WhenDataBecomesReady, ignored_time,
|
|
|
|
&self->ready_trigger);
|
|
|
|
if (status != noErr)
|
|
|
|
goto unexpected_error;
|
2010-10-27 17:30:11 +00:00
|
|
|
|
|
|
|
self->ctx = ctx;
|
|
|
|
|
|
|
|
self->device = device;
|
2010-11-05 14:14:08 +00:00
|
|
|
self->device_iface = device_vt->derived;
|
|
|
|
self->device_base = device_base;
|
|
|
|
self->device_base_iface = device_vt->base;
|
2010-10-27 17:30:11 +00:00
|
|
|
self->stream = stream;
|
2010-11-05 14:14:08 +00:00
|
|
|
self->stream_iface = stream_vt->derived;
|
|
|
|
self->stream_base = stream_base;
|
|
|
|
self->stream_base_iface = stream_vt->base;
|
2010-10-27 17:30:11 +00:00
|
|
|
|
2010-11-05 14:14:08 +00:00
|
|
|
self->queue = queue;
|
2010-10-27 17:30:11 +00:00
|
|
|
self->duration = GST_CLOCK_TIME_NONE;
|
|
|
|
|
2010-11-10 19:44:15 +00:00
|
|
|
CFRelease (stream_array);
|
|
|
|
|
2010-10-27 17:30:11 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
api_error:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (self, RESOURCE, FAILED, ("API error"),
|
|
|
|
("%s", error->message));
|
|
|
|
g_clear_error (&error);
|
|
|
|
goto any_error;
|
|
|
|
}
|
|
|
|
device_busy:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (self, RESOURCE, BUSY,
|
|
|
|
("device is already in use"), (NULL));
|
|
|
|
goto any_error;
|
|
|
|
}
|
2010-11-10 19:44:15 +00:00
|
|
|
invalid_device_index:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (self, RESOURCE, NOT_FOUND,
|
|
|
|
("invalid video capture device index"), (NULL));
|
|
|
|
goto any_error;
|
|
|
|
}
|
2010-10-27 17:30:11 +00:00
|
|
|
unexpected_error:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (self, RESOURCE, FAILED,
|
2010-11-02 21:53:33 +00:00
|
|
|
("unexpected error while opening device (%d)", (gint) status), (NULL));
|
2010-10-27 17:30:11 +00:00
|
|
|
goto any_error;
|
|
|
|
}
|
|
|
|
any_error:
|
|
|
|
{
|
|
|
|
if (stream != NULL)
|
|
|
|
CFRelease (stream);
|
2010-11-10 19:44:15 +00:00
|
|
|
if (stream_array != NULL)
|
|
|
|
CFRelease (stream_array);
|
2010-10-27 17:30:11 +00:00
|
|
|
if (device != NULL)
|
|
|
|
CFRelease (device);
|
|
|
|
|
|
|
|
if (ctx != NULL) {
|
|
|
|
cm->FigBufferQueueRelease (queue);
|
|
|
|
g_object_unref (ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-04 17:59:44 +00:00
|
|
|
gst_cel_video_src_close_device (GstCelVideoSrc * self)
|
2010-10-27 17:30:11 +00:00
|
|
|
{
|
2010-11-04 17:59:44 +00:00
|
|
|
gst_cel_video_src_release_device_caps_and_formats (self);
|
2010-10-27 17:30:11 +00:00
|
|
|
|
|
|
|
self->stream_iface->Stop (self->stream);
|
2010-11-05 14:14:08 +00:00
|
|
|
self->stream_base_iface->Finalize (self->stream_base);
|
2010-10-27 17:30:11 +00:00
|
|
|
CFRelease (self->stream);
|
|
|
|
self->stream = NULL;
|
2010-11-05 14:14:08 +00:00
|
|
|
self->stream_iface = NULL;
|
|
|
|
self->stream_base = NULL;
|
|
|
|
self->stream_base_iface = NULL;
|
2010-10-27 17:30:11 +00:00
|
|
|
|
2010-11-05 14:14:08 +00:00
|
|
|
self->device_base_iface->Finalize (self->device_base);
|
2010-10-27 17:30:11 +00:00
|
|
|
CFRelease (self->device);
|
|
|
|
self->device = NULL;
|
2010-11-05 14:14:08 +00:00
|
|
|
self->device_iface = NULL;
|
|
|
|
self->device_base = NULL;
|
|
|
|
self->device_base_iface = NULL;
|
2010-10-27 17:30:11 +00:00
|
|
|
|
2010-11-11 23:40:33 +00:00
|
|
|
self->ctx->cm->CMBufferQueueRemoveTrigger (self->queue, self->ready_trigger);
|
2010-10-27 17:30:11 +00:00
|
|
|
self->ctx->cm->FigBufferQueueRelease (self->queue);
|
2010-11-11 23:40:33 +00:00
|
|
|
self->ready_trigger = NULL;
|
2010-10-27 17:30:11 +00:00
|
|
|
self->queue = NULL;
|
|
|
|
|
|
|
|
g_object_unref (self->ctx);
|
|
|
|
self->ctx = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-04 17:59:44 +00:00
|
|
|
gst_cel_video_src_ensure_device_caps_and_formats (GstCelVideoSrc * self)
|
2010-10-27 17:30:11 +00:00
|
|
|
{
|
2010-11-02 21:53:33 +00:00
|
|
|
OSStatus status;
|
2010-11-05 14:14:08 +00:00
|
|
|
CFArrayRef stream_formats = NULL;
|
2010-10-27 17:30:11 +00:00
|
|
|
CFIndex format_count, i;
|
|
|
|
|
|
|
|
if (self->device_caps != NULL)
|
|
|
|
goto already_probed;
|
|
|
|
|
|
|
|
self->device_caps = gst_caps_new_empty ();
|
2010-11-04 17:59:44 +00:00
|
|
|
self->device_formats = g_array_new (FALSE, FALSE, sizeof (GstCelVideoFormat));
|
2010-10-27 17:30:11 +00:00
|
|
|
|
2010-11-05 14:14:08 +00:00
|
|
|
status = self->stream_base_iface->CopyProperty (self->stream_base,
|
|
|
|
*(self->ctx->mt->kFigCaptureStreamProperty_SupportedFormatsArray),
|
|
|
|
NULL, (CFTypeRef *) & stream_formats);
|
2010-11-02 21:53:33 +00:00
|
|
|
if (status != noErr)
|
2010-10-27 17:30:11 +00:00
|
|
|
goto beach;
|
|
|
|
|
2010-11-05 14:14:08 +00:00
|
|
|
format_count = CFArrayGetCount (stream_formats);
|
2010-10-27 17:30:11 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "device supports %d formats", (gint) format_count);
|
|
|
|
|
|
|
|
for (i = 0; i != format_count; i++) {
|
2010-11-05 14:14:08 +00:00
|
|
|
CFDictionaryRef sformat;
|
2010-11-04 17:59:44 +00:00
|
|
|
GstCelVideoFormat format;
|
2010-10-27 17:30:11 +00:00
|
|
|
|
2010-11-05 14:14:08 +00:00
|
|
|
sformat = CFArrayGetValueAtIndex (stream_formats, i);
|
2010-10-27 17:30:11 +00:00
|
|
|
|
2010-11-05 14:14:08 +00:00
|
|
|
if (gst_cel_video_src_parse_stream_format (self, i, sformat, &format)) {
|
2010-10-27 17:30:11 +00:00
|
|
|
gst_caps_append_structure (self->device_caps,
|
|
|
|
gst_structure_new ("video/x-raw-yuv",
|
|
|
|
"format", GST_TYPE_FOURCC, format.fourcc,
|
|
|
|
"width", G_TYPE_INT, format.width,
|
|
|
|
"height", G_TYPE_INT, format.height,
|
|
|
|
"framerate", GST_TYPE_FRACTION, format.fps_n, format.fps_d,
|
|
|
|
"pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1, NULL));
|
|
|
|
g_array_append_val (self->device_formats, format);
|
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (self, "ignoring unknown format #%d", (gint) i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-05 14:14:08 +00:00
|
|
|
CFRelease (stream_formats);
|
2010-10-27 17:30:11 +00:00
|
|
|
|
|
|
|
already_probed:
|
|
|
|
beach:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-04 17:59:44 +00:00
|
|
|
gst_cel_video_src_release_device_caps_and_formats (GstCelVideoSrc * self)
|
2010-10-27 17:30:11 +00:00
|
|
|
{
|
|
|
|
if (self->device_caps != NULL) {
|
|
|
|
gst_caps_unref (self->device_caps);
|
|
|
|
self->device_caps = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self->device_formats != NULL) {
|
|
|
|
g_array_free (self->device_formats, TRUE);
|
|
|
|
self->device_formats = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2010-11-04 17:59:44 +00:00
|
|
|
gst_cel_video_src_select_format (GstCelVideoSrc * self,
|
|
|
|
GstCelVideoFormat * format)
|
2010-10-27 17:30:11 +00:00
|
|
|
{
|
|
|
|
gboolean result = FALSE;
|
|
|
|
GstMTApi *mt = self->ctx->mt;
|
2010-11-05 14:14:08 +00:00
|
|
|
GstCelApi *cel = self->ctx->cel;
|
2010-11-02 21:53:33 +00:00
|
|
|
OSStatus status;
|
2010-10-27 17:30:11 +00:00
|
|
|
SInt32 framerate;
|
|
|
|
|
2010-11-05 14:14:08 +00:00
|
|
|
status = gst_cel_video_src_set_stream_property_i32 (self,
|
|
|
|
*(mt->kFigCaptureStreamProperty_FormatIndex), format->index);
|
2010-11-02 21:53:33 +00:00
|
|
|
if (status != noErr)
|
2010-10-27 17:30:11 +00:00
|
|
|
goto beach;
|
|
|
|
|
|
|
|
framerate = format->fps_n / format->fps_d;
|
|
|
|
|
2010-11-05 14:14:08 +00:00
|
|
|
status = gst_cel_video_src_set_stream_property_i32 (self,
|
|
|
|
*(mt->kFigCaptureStreamProperty_MinimumFrameRate), framerate);
|
2010-11-02 21:53:33 +00:00
|
|
|
if (status != noErr)
|
2010-10-27 17:30:11 +00:00
|
|
|
goto beach;
|
|
|
|
|
2010-11-05 14:14:08 +00:00
|
|
|
status = gst_cel_video_src_set_stream_property_i32 (self,
|
|
|
|
*(mt->kFigCaptureStreamProperty_MaximumFrameRate), framerate);
|
2010-11-02 21:53:33 +00:00
|
|
|
if (status != noErr)
|
2010-10-27 17:30:11 +00:00
|
|
|
goto beach;
|
|
|
|
|
2010-11-05 14:14:08 +00:00
|
|
|
status = gst_cel_video_src_set_stream_property_value (self,
|
|
|
|
*(cel->kFigCaptureStreamProperty_ColorRange),
|
|
|
|
*(cel->kFigCapturePropertyValue_ColorRangeSDVideo));
|
2010-11-02 21:53:33 +00:00
|
|
|
if (status != noErr)
|
2010-10-27 17:30:11 +00:00
|
|
|
goto beach;
|
|
|
|
|
|
|
|
status = self->stream_iface->Start (self->stream);
|
2010-11-02 21:53:33 +00:00
|
|
|
if (status != noErr)
|
2010-10-27 17:30:11 +00:00
|
|
|
goto beach;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (self, "configured format %d (%d x %d @ %d Hz)",
|
|
|
|
format->index, format->width, format->height, (gint) framerate);
|
|
|
|
|
|
|
|
self->duration =
|
|
|
|
gst_util_uint64_scale (GST_SECOND, format->fps_d, format->fps_n);
|
|
|
|
|
|
|
|
result = TRUE;
|
|
|
|
|
|
|
|
beach:
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2010-11-05 14:14:08 +00:00
|
|
|
gst_cel_video_src_parse_stream_format (GstCelVideoSrc * self,
|
|
|
|
guint index, CFDictionaryRef stream_format, GstCelVideoFormat * format)
|
2010-10-27 17:30:11 +00:00
|
|
|
{
|
|
|
|
GstCMApi *cm = self->ctx->cm;
|
|
|
|
GstMTApi *mt = self->ctx->mt;
|
2010-11-02 21:53:33 +00:00
|
|
|
CMFormatDescriptionRef desc;
|
|
|
|
CMVideoDimensions dim;
|
2010-10-27 17:30:11 +00:00
|
|
|
UInt32 subtype;
|
|
|
|
CFNumberRef framerate_value;
|
|
|
|
SInt32 fps_n;
|
|
|
|
|
|
|
|
format->index = index;
|
|
|
|
|
2010-11-05 14:14:08 +00:00
|
|
|
desc = CFDictionaryGetValue (stream_format,
|
|
|
|
*(mt->kFigSupportedFormat_FormatDescription));
|
2010-10-27 17:30:11 +00:00
|
|
|
|
2010-11-02 21:53:33 +00:00
|
|
|
dim = cm->CMVideoFormatDescriptionGetDimensions (desc);
|
2010-10-27 17:30:11 +00:00
|
|
|
format->width = dim.width;
|
|
|
|
format->height = dim.height;
|
|
|
|
|
2010-11-02 21:53:33 +00:00
|
|
|
subtype = cm->CMFormatDescriptionGetMediaSubType (desc);
|
2010-10-27 17:30:11 +00:00
|
|
|
|
|
|
|
switch (subtype) {
|
|
|
|
case kComponentVideoUnsigned:
|
|
|
|
format->video_format = GST_VIDEO_FORMAT_YUY2;
|
|
|
|
format->fourcc = GST_MAKE_FOURCC ('Y', 'U', 'Y', '2');
|
|
|
|
break;
|
|
|
|
case kYUV420vCodecType:
|
2010-11-08 22:54:31 +00:00
|
|
|
format->video_format = GST_VIDEO_FORMAT_NV12;
|
|
|
|
format->fourcc = GST_MAKE_FOURCC ('N', 'V', '1', '2');
|
2010-10-27 17:30:11 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto unsupported_format;
|
|
|
|
}
|
|
|
|
|
2010-11-05 14:14:08 +00:00
|
|
|
framerate_value = CFDictionaryGetValue (stream_format,
|
|
|
|
*(mt->kFigSupportedFormat_VideoMaxFrameRate));
|
2010-10-27 17:30:11 +00:00
|
|
|
CFNumberGetValue (framerate_value, kCFNumberSInt32Type, &fps_n);
|
|
|
|
format->fps_n = fps_n;
|
|
|
|
format->fps_d = 1;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
unsupported_format:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-11-02 21:53:33 +00:00
|
|
|
static OSStatus
|
2010-11-05 14:14:08 +00:00
|
|
|
gst_cel_video_src_set_stream_property_i32 (GstCelVideoSrc * self,
|
2010-10-27 17:30:11 +00:00
|
|
|
CFStringRef name, SInt32 value)
|
|
|
|
{
|
2010-11-02 21:53:33 +00:00
|
|
|
OSStatus status;
|
2010-10-27 17:30:11 +00:00
|
|
|
CFNumberRef number;
|
|
|
|
|
|
|
|
number = CFNumberCreate (NULL, kCFNumberSInt32Type, &value);
|
2010-11-05 14:14:08 +00:00
|
|
|
status = self->stream_base_iface->SetProperty (self->stream_base, name,
|
|
|
|
number);
|
2010-10-27 17:30:11 +00:00
|
|
|
CFRelease (number);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2010-11-02 21:53:33 +00:00
|
|
|
static OSStatus
|
2010-11-05 14:14:08 +00:00
|
|
|
gst_cel_video_src_set_stream_property_value (GstCelVideoSrc * self,
|
|
|
|
CFStringRef name, CFTypeRef value)
|
2010-10-27 17:30:11 +00:00
|
|
|
{
|
2010-11-05 14:14:08 +00:00
|
|
|
return self->stream_base_iface->SetProperty (self->stream_base, name, value);
|
2010-10-27 17:30:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-04 17:59:44 +00:00
|
|
|
gst_cel_video_src_base_init (gpointer gclass)
|
2010-10-27 17:30:11 +00:00
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
|
|
|
|
|
2012-09-14 15:08:49 +00:00
|
|
|
gst_element_class_set_metadata (element_class,
|
2010-11-04 18:25:24 +00:00
|
|
|
"Video Source (Celestial)", "Source/Video",
|
|
|
|
"Reads frames from an iOS Celestial device",
|
2010-11-04 18:02:50 +00:00
|
|
|
"Ole André Vadla Ravnås <oravnas@cisco.com>");
|
2010-10-27 17:30:11 +00:00
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&src_template));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-04 17:59:44 +00:00
|
|
|
gst_cel_video_src_class_init (GstCelVideoSrcClass * klass)
|
2010-10-27 17:30:11 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass);
|
|
|
|
GstPushSrcClass *gstpushsrc_class = GST_PUSH_SRC_CLASS (klass);
|
|
|
|
|
2010-11-04 17:59:44 +00:00
|
|
|
gobject_class->dispose = gst_cel_video_src_dispose;
|
|
|
|
gobject_class->finalize = gst_cel_video_src_finalize;
|
|
|
|
gobject_class->get_property = gst_cel_video_src_get_property;
|
|
|
|
gobject_class->set_property = gst_cel_video_src_set_property;
|
2010-10-27 17:30:11 +00:00
|
|
|
|
2010-11-04 17:59:44 +00:00
|
|
|
gstelement_class->change_state = gst_cel_video_src_change_state;
|
2010-10-27 17:30:11 +00:00
|
|
|
|
2010-11-04 17:59:44 +00:00
|
|
|
gstbasesrc_class->get_caps = gst_cel_video_src_get_caps;
|
|
|
|
gstbasesrc_class->set_caps = gst_cel_video_src_set_caps;
|
|
|
|
gstbasesrc_class->start = gst_cel_video_src_start;
|
|
|
|
gstbasesrc_class->stop = gst_cel_video_src_stop;
|
|
|
|
gstbasesrc_class->query = gst_cel_video_src_query;
|
|
|
|
gstbasesrc_class->unlock = gst_cel_video_src_unlock;
|
|
|
|
gstbasesrc_class->unlock_stop = gst_cel_video_src_unlock_stop;
|
2010-10-27 17:30:11 +00:00
|
|
|
|
2010-11-04 17:59:44 +00:00
|
|
|
gstpushsrc_class->create = gst_cel_video_src_create;
|
2010-10-27 17:30:11 +00:00
|
|
|
|
2010-11-10 19:44:15 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_DEVICE_INDEX,
|
|
|
|
g_param_spec_int ("device-index", "Device Index",
|
|
|
|
"The zero-based device index",
|
|
|
|
-1, G_MAXINT, DEFAULT_DEVICE_INDEX,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
|
2010-10-27 17:30:11 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_DO_STATS,
|
|
|
|
g_param_spec_boolean ("do-stats", "Enable statistics",
|
|
|
|
"Enable logging of statistics", DEFAULT_DO_STATS,
|
|
|
|
G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2010-11-05 15:51:57 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_FPS,
|
|
|
|
g_param_spec_int ("fps", "Frames per second",
|
|
|
|
"Last measured framerate, if statistics are enabled",
|
|
|
|
-1, G_MAXINT, -1, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2010-10-27 17:30:11 +00:00
|
|
|
|
2010-11-04 17:59:44 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_cel_video_src_debug, "celvideosrc",
|
2010-11-05 14:08:56 +00:00
|
|
|
0, "iOS Celestial video source");
|
2010-10-27 17:30:11 +00:00
|
|
|
}
|