2002-07-26 22:18:57 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*#define DEBUG_ENABLED */
|
2003-06-29 19:46:12 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2002-07-26 22:18:57 +00:00
|
|
|
#include <gstvideotestsrc.h>
|
2003-04-16 07:52:54 +00:00
|
|
|
#include <videotestsrc.h>
|
2002-07-26 22:18:57 +00:00
|
|
|
|
2002-07-28 13:40:53 +00:00
|
|
|
#include <string.h>
|
2002-07-26 22:18:57 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* elementfactory information */
|
2003-11-02 20:48:33 +00:00
|
|
|
static GstElementDetails videotestsrc_details = GST_ELEMENT_DETAILS (
|
2002-07-26 22:18:57 +00:00
|
|
|
"Video test source",
|
|
|
|
"Source/Video",
|
|
|
|
"Creates a test video stream",
|
2003-11-02 20:48:33 +00:00
|
|
|
"David A. Schleef <ds@schleef.org>"
|
|
|
|
);
|
2002-07-26 22:18:57 +00:00
|
|
|
|
|
|
|
/* GstVideotestsrc signals and args */
|
2002-10-04 06:49:51 +00:00
|
|
|
enum
|
|
|
|
{
|
2002-07-26 22:18:57 +00:00
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2002-10-04 06:49:51 +00:00
|
|
|
enum
|
|
|
|
{
|
2002-07-26 22:18:57 +00:00
|
|
|
ARG_0,
|
|
|
|
ARG_WIDTH,
|
|
|
|
ARG_HEIGHT,
|
2002-10-04 06:49:51 +00:00
|
|
|
ARG_FOURCC,
|
2002-10-23 06:03:03 +00:00
|
|
|
ARG_RATE,
|
2003-04-23 07:38:32 +00:00
|
|
|
ARG_TYPE,
|
2003-05-18 23:20:24 +00:00
|
|
|
ARG_SYNC,
|
2002-07-26 22:18:57 +00:00
|
|
|
/* FILL ME */
|
|
|
|
};
|
|
|
|
|
2003-11-02 20:48:33 +00:00
|
|
|
static void gst_videotestsrc_base_init (gpointer g_class);
|
2002-10-04 06:49:51 +00:00
|
|
|
static void gst_videotestsrc_class_init (GstVideotestsrcClass * klass);
|
|
|
|
static void gst_videotestsrc_init (GstVideotestsrc * videotestsrc);
|
|
|
|
static GstElementStateReturn gst_videotestsrc_change_state (GstElement * element);
|
2003-05-01 06:24:34 +00:00
|
|
|
static void gst_videotestsrc_set_clock (GstElement *element, GstClock *clock);
|
2002-07-26 22:18:57 +00:00
|
|
|
|
2003-04-23 07:38:32 +00:00
|
|
|
static void gst_videotestsrc_set_pattern (GstVideotestsrc *src, int pattern_type);
|
2002-10-04 06:49:51 +00:00
|
|
|
static void gst_videotestsrc_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_videotestsrc_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec);
|
2002-07-26 22:18:57 +00:00
|
|
|
|
2003-10-08 16:08:22 +00:00
|
|
|
static GstData *gst_videotestsrc_get (GstPad * pad);
|
2002-07-26 22:18:57 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
|
|
|
|
2003-04-16 07:52:54 +00:00
|
|
|
static GstCaps * gst_videotestsrc_get_capslist (void);
|
2003-10-30 19:24:49 +00:00
|
|
|
static GstCaps * gst_videotestsrc_get_capslist_size (int width, int height, float rate);
|
2003-04-16 07:52:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
static GstPadTemplate *
|
|
|
|
videotestsrc_src_template_factory(void)
|
|
|
|
{
|
|
|
|
static GstPadTemplate *templ = NULL;
|
2002-07-26 22:18:57 +00:00
|
|
|
|
2003-04-16 07:52:54 +00:00
|
|
|
if(!templ){
|
2003-07-06 20:49:52 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
|
2003-07-14 08:36:03 +00:00
|
|
|
caps = gst_videotestsrc_get_capslist_size(0,0,0.0);
|
2003-04-16 07:52:54 +00:00
|
|
|
|
|
|
|
templ = GST_PAD_TEMPLATE_NEW("src", GST_PAD_SRC, GST_PAD_ALWAYS, caps);
|
|
|
|
}
|
|
|
|
return templ;
|
|
|
|
}
|
|
|
|
|
|
|
|
GType
|
2002-07-26 22:18:57 +00:00
|
|
|
gst_videotestsrc_get_type (void)
|
|
|
|
{
|
|
|
|
static GType videotestsrc_type = 0;
|
|
|
|
|
|
|
|
if (!videotestsrc_type) {
|
|
|
|
static const GTypeInfo videotestsrc_info = {
|
2003-11-02 20:48:33 +00:00
|
|
|
sizeof (GstVideotestsrcClass),
|
|
|
|
gst_videotestsrc_base_init,
|
2002-07-26 22:18:57 +00:00
|
|
|
NULL,
|
2002-10-04 06:49:51 +00:00
|
|
|
(GClassInitFunc) gst_videotestsrc_class_init,
|
2002-07-26 22:18:57 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2002-10-04 06:49:51 +00:00
|
|
|
sizeof (GstVideotestsrc),
|
2002-07-26 22:18:57 +00:00
|
|
|
0,
|
2002-10-04 06:49:51 +00:00
|
|
|
(GInstanceInitFunc) gst_videotestsrc_init,
|
2002-07-26 22:18:57 +00:00
|
|
|
};
|
2002-10-04 06:49:51 +00:00
|
|
|
|
|
|
|
videotestsrc_type =
|
|
|
|
g_type_register_static (GST_TYPE_ELEMENT, "GstVideotestsrc", &videotestsrc_info, 0);
|
2002-07-26 22:18:57 +00:00
|
|
|
}
|
|
|
|
return videotestsrc_type;
|
|
|
|
}
|
|
|
|
|
2003-04-23 07:38:32 +00:00
|
|
|
#define GST_TYPE_VIDEOTESTSRC_PATTERN (gst_videotestsrc_pattern_get_type ())
|
|
|
|
static GType
|
|
|
|
gst_videotestsrc_pattern_get_type (void)
|
|
|
|
{
|
|
|
|
static GType videotestsrc_pattern_type = 0;
|
|
|
|
static GEnumValue pattern_types[] = {
|
|
|
|
{ GST_VIDEOTESTSRC_SMPTE, "smpte", "SMPTE 100% color bars" },
|
|
|
|
{ GST_VIDEOTESTSRC_SNOW, "snow", "Random (television snow)" },
|
|
|
|
{ GST_VIDEOTESTSRC_BLACK, "black", "0% Black" },
|
|
|
|
{ 0, NULL, NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!videotestsrc_pattern_type){
|
|
|
|
videotestsrc_pattern_type = g_enum_register_static("GstVideotestsrcPattern",
|
|
|
|
pattern_types);
|
|
|
|
}
|
|
|
|
return videotestsrc_pattern_type;
|
|
|
|
}
|
|
|
|
|
2003-11-02 20:48:33 +00:00
|
|
|
static void
|
|
|
|
gst_videotestsrc_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
|
|
|
gst_element_class_set_details (element_class, &videotestsrc_details);
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
GST_PAD_TEMPLATE_GET (videotestsrc_src_template_factory));
|
|
|
|
}
|
2002-07-26 22:18:57 +00:00
|
|
|
static void
|
2002-10-04 06:49:51 +00:00
|
|
|
gst_videotestsrc_class_init (GstVideotestsrcClass * klass)
|
2002-07-26 22:18:57 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
2002-10-04 06:49:51 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2002-07-26 22:18:57 +00:00
|
|
|
|
2002-10-30 09:16:03 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_WIDTH,
|
2003-07-14 08:36:03 +00:00
|
|
|
g_param_spec_int ("width", "width", "Default width",
|
|
|
|
1, G_MAXINT, 320, G_PARAM_READWRITE));
|
2002-10-30 09:16:03 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_HEIGHT,
|
2003-07-14 08:36:03 +00:00
|
|
|
g_param_spec_int ("height", "height", "Default height",
|
|
|
|
1, G_MAXINT, 240, G_PARAM_READWRITE));
|
2002-10-04 06:49:51 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FOURCC,
|
2002-10-30 09:16:03 +00:00
|
|
|
g_param_spec_string ("fourcc", "fourcc", "fourcc",
|
|
|
|
NULL, G_PARAM_READWRITE));
|
2002-10-23 06:03:03 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_RATE,
|
2003-07-14 08:36:03 +00:00
|
|
|
g_param_spec_float ("fps", "FPS", "Default frame rate",
|
2003-07-06 20:49:52 +00:00
|
|
|
0., G_MAXFLOAT, 30., G_PARAM_READWRITE));
|
2003-04-23 07:38:32 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_TYPE,
|
|
|
|
g_param_spec_enum ("pattern", "Pattern", "Type of test pattern to generate",
|
|
|
|
GST_TYPE_VIDEOTESTSRC_PATTERN, 1, G_PARAM_READWRITE));
|
2003-05-18 23:20:24 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SYNC,
|
|
|
|
g_param_spec_boolean ("sync", "Sync", "Synchronize to clock",
|
|
|
|
TRUE, G_PARAM_READWRITE));
|
2002-07-26 22:18:57 +00:00
|
|
|
|
2002-10-04 06:49:51 +00:00
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
2002-07-26 22:18:57 +00:00
|
|
|
|
|
|
|
gobject_class->set_property = gst_videotestsrc_set_property;
|
|
|
|
gobject_class->get_property = gst_videotestsrc_get_property;
|
|
|
|
|
2002-07-30 07:38:01 +00:00
|
|
|
gstelement_class->change_state = gst_videotestsrc_change_state;
|
2003-05-01 06:24:34 +00:00
|
|
|
gstelement_class->set_clock = gst_videotestsrc_set_clock;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_videotestsrc_set_clock (GstElement *element, GstClock *clock)
|
|
|
|
{
|
|
|
|
GstVideotestsrc *v;
|
|
|
|
|
|
|
|
v = GST_VIDEOTESTSRC (element);
|
|
|
|
|
|
|
|
gst_object_replace ((GstObject **)&v->clock, (GstObject *)clock);
|
2002-07-26 22:18:57 +00:00
|
|
|
}
|
|
|
|
|
2003-01-10 13:38:32 +00:00
|
|
|
static GstPadLinkReturn
|
2003-09-11 19:25:40 +00:00
|
|
|
gst_videotestsrc_src_link (GstPad * pad, GstCaps * caps)
|
2002-07-26 22:18:57 +00:00
|
|
|
{
|
|
|
|
GstVideotestsrc *videotestsrc;
|
2003-10-14 10:08:28 +00:00
|
|
|
GstCaps *caps1 = NULL;
|
2002-07-26 22:18:57 +00:00
|
|
|
|
2003-09-11 19:25:40 +00:00
|
|
|
GST_DEBUG ("gst_videotestsrc_src_link");
|
2002-07-26 22:18:57 +00:00
|
|
|
videotestsrc = GST_VIDEOTESTSRC (gst_pad_get_parent (pad));
|
|
|
|
|
2003-06-10 16:22:41 +00:00
|
|
|
for ( ; caps != NULL; caps = caps->next) {
|
|
|
|
GstPadLinkReturn ret;
|
|
|
|
|
2003-07-14 08:36:03 +00:00
|
|
|
caps1 = gst_caps_copy_1(caps);
|
|
|
|
|
|
|
|
if(!gst_caps_has_fixed_property(caps1, "framerate")){
|
|
|
|
gst_caps_set(caps1, "framerate", GST_PROPS_FLOAT(videotestsrc->default_rate));
|
|
|
|
}
|
|
|
|
if(!gst_caps_has_fixed_property(caps1, "width")){
|
|
|
|
gst_caps_set(caps1, "width", GST_PROPS_INT(videotestsrc->default_width));
|
|
|
|
}
|
|
|
|
if(!gst_caps_has_fixed_property(caps1, "height")){
|
|
|
|
gst_caps_set(caps1, "height", GST_PROPS_INT(videotestsrc->default_height));
|
|
|
|
}
|
2003-07-08 07:40:09 +00:00
|
|
|
|
2003-07-14 08:36:03 +00:00
|
|
|
gst_caps_ref(caps1);
|
|
|
|
gst_caps_sink(caps1);
|
2003-07-08 07:40:09 +00:00
|
|
|
|
2003-06-10 16:22:41 +00:00
|
|
|
ret = gst_pad_try_set_caps(pad, caps1);
|
|
|
|
|
|
|
|
if (ret != GST_PAD_LINK_OK &&
|
|
|
|
ret != GST_PAD_LINK_DONE) {
|
|
|
|
gst_caps_unref(caps1);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
videotestsrc->fourcc = paintinfo_find_by_caps(caps1);
|
|
|
|
if (!videotestsrc->fourcc) {
|
|
|
|
gst_caps_unref(caps1);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-07-14 08:36:03 +00:00
|
|
|
/* if we get here, it's OK */
|
|
|
|
//gst_caps_unref(caps1);
|
2003-06-10 16:22:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (caps == NULL) {
|
2003-07-08 07:40:09 +00:00
|
|
|
GST_DEBUG ("videotestsrc: no suitable opposite-side caps found");
|
2003-06-10 16:22:41 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2002-07-26 22:18:57 +00:00
|
|
|
}
|
|
|
|
|
2003-07-14 08:36:03 +00:00
|
|
|
g_return_val_if_fail(videotestsrc->fourcc, GST_PAD_LINK_REFUSED);
|
2003-04-16 07:52:54 +00:00
|
|
|
|
2003-07-14 08:36:03 +00:00
|
|
|
//g_print ("videotestsrc: using fourcc element %p %s\n",
|
|
|
|
// videotestsrc->fourcc, videotestsrc->fourcc->name);
|
|
|
|
|
|
|
|
gst_caps_get_int (caps1, "width", &videotestsrc->width);
|
|
|
|
gst_caps_get_int (caps1, "height", &videotestsrc->height);
|
|
|
|
gst_caps_get_float (caps1, "framerate", &videotestsrc->rate);
|
2002-07-26 22:18:57 +00:00
|
|
|
|
2003-04-16 07:52:54 +00:00
|
|
|
videotestsrc->bpp = videotestsrc->fourcc->bitspp;
|
2002-10-04 06:49:51 +00:00
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("size %d x %d", videotestsrc->width, videotestsrc->height);
|
2002-07-26 22:18:57 +00:00
|
|
|
|
2003-09-11 19:25:40 +00:00
|
|
|
videotestsrc->pool = gst_pad_get_bufferpool (videotestsrc->srcpad);
|
|
|
|
|
2003-06-10 16:22:41 +00:00
|
|
|
return GST_PAD_LINK_DONE;
|
2002-07-26 22:18:57 +00:00
|
|
|
}
|
|
|
|
|
2003-09-11 19:25:40 +00:00
|
|
|
static void
|
|
|
|
gst_videotestsrc_src_unlink (GstPad * pad)
|
|
|
|
{
|
|
|
|
GstVideotestsrc *videotestsrc;
|
|
|
|
|
|
|
|
videotestsrc = GST_VIDEOTESTSRC (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
if (videotestsrc->pool) {
|
|
|
|
gst_buffer_pool_unref (videotestsrc->pool);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-30 07:38:01 +00:00
|
|
|
static GstElementStateReturn
|
2002-10-04 06:49:51 +00:00
|
|
|
gst_videotestsrc_change_state (GstElement * element)
|
2002-07-30 07:38:01 +00:00
|
|
|
{
|
2003-09-11 19:25:40 +00:00
|
|
|
GstVideotestsrc *videotestsrc;
|
2002-10-04 06:49:51 +00:00
|
|
|
|
2003-09-11 19:25:40 +00:00
|
|
|
videotestsrc = GST_VIDEOTESTSRC (element);
|
2002-07-30 07:38:01 +00:00
|
|
|
|
2002-10-04 06:49:51 +00:00
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
2003-09-11 19:25:40 +00:00
|
|
|
case GST_STATE_NULL_TO_READY:
|
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
|
|
|
break;
|
2002-10-04 06:49:51 +00:00
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
|
|
|
break;
|
|
|
|
case GST_STATE_PLAYING_TO_PAUSED:
|
2003-09-11 19:25:40 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
|
|
|
videotestsrc->timestamp_offset = 0;
|
|
|
|
videotestsrc->n_frames = 0;
|
2002-10-04 06:49:51 +00:00
|
|
|
break;
|
2003-06-11 22:39:37 +00:00
|
|
|
case GST_STATE_READY_TO_NULL:
|
|
|
|
break;
|
2002-10-04 06:49:51 +00:00
|
|
|
}
|
2002-07-30 07:38:01 +00:00
|
|
|
|
2003-05-24 10:18:38 +00:00
|
|
|
return parent_class->change_state (element);
|
2002-10-04 06:49:51 +00:00
|
|
|
}
|
2002-07-30 07:38:01 +00:00
|
|
|
|
2002-10-04 06:49:51 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_videotestsrc_get_capslist (void)
|
|
|
|
{
|
|
|
|
static GstCaps *capslist = NULL;
|
|
|
|
GstCaps *caps;
|
|
|
|
int i;
|
|
|
|
|
2003-07-14 08:36:03 +00:00
|
|
|
if(!capslist){
|
|
|
|
for(i=0;i<n_fourccs;i++){
|
|
|
|
caps = paint_get_caps(fourcc_list + i);
|
|
|
|
capslist = gst_caps_append(capslist, caps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_return_val_if_fail(capslist->refcount > 0, NULL);
|
|
|
|
|
|
|
|
return gst_caps_ref(capslist);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstCaps *
|
2003-10-30 19:24:49 +00:00
|
|
|
gst_videotestsrc_get_capslist_size (int width, int height, float rate)
|
2003-07-14 08:36:03 +00:00
|
|
|
{
|
|
|
|
GstCaps *capslist;
|
|
|
|
GstCaps *caps;
|
|
|
|
GstCaps *caps_yuv_mask;
|
|
|
|
GstCaps *caps_rgb_mask;
|
|
|
|
GstCaps *caps_yuv;
|
|
|
|
GstCaps *caps_rgb;
|
2002-10-04 06:49:51 +00:00
|
|
|
|
2003-07-14 08:36:03 +00:00
|
|
|
caps_rgb_mask = GST_CAPS_NEW("src","video/x-raw-rgb",
|
|
|
|
"width", GST_PROPS_INT_RANGE (1, G_MAXINT),
|
|
|
|
"height", GST_PROPS_INT_RANGE (1, G_MAXINT),
|
|
|
|
"framerate", GST_PROPS_FLOAT_RANGE (0, G_MAXFLOAT));
|
|
|
|
caps_yuv_mask = GST_CAPS_NEW("src","video/x-raw-yuv",
|
|
|
|
"width", GST_PROPS_INT_RANGE (1, G_MAXINT),
|
|
|
|
"height", GST_PROPS_INT_RANGE (1, G_MAXINT),
|
|
|
|
"framerate", GST_PROPS_FLOAT_RANGE (0, G_MAXFLOAT));
|
|
|
|
|
|
|
|
if(height){
|
|
|
|
gst_caps_set(caps_rgb_mask, "height", GST_PROPS_INT(height));
|
|
|
|
gst_caps_set(caps_yuv_mask, "height", GST_PROPS_INT(height));
|
|
|
|
}
|
|
|
|
if(width){
|
|
|
|
gst_caps_set(caps_rgb_mask, "width", GST_PROPS_INT(width));
|
|
|
|
gst_caps_set(caps_yuv_mask, "width", GST_PROPS_INT(width));
|
|
|
|
}
|
|
|
|
if(rate > 0){
|
|
|
|
gst_caps_set(caps_rgb_mask, "framerate", GST_PROPS_FLOAT(rate));
|
|
|
|
gst_caps_set(caps_yuv_mask, "framerate", GST_PROPS_FLOAT(rate));
|
2002-10-04 06:49:51 +00:00
|
|
|
}
|
|
|
|
|
2003-07-14 08:36:03 +00:00
|
|
|
capslist = gst_videotestsrc_get_capslist ();
|
|
|
|
g_return_val_if_fail(capslist->refcount > 0, NULL);
|
|
|
|
caps_yuv = gst_caps_intersect(caps_yuv_mask, capslist);
|
|
|
|
caps_rgb = gst_caps_intersect(caps_rgb_mask, capslist);
|
|
|
|
caps = gst_caps_append(caps_yuv, caps_rgb);
|
|
|
|
|
|
|
|
//gst_caps_unref (capslist);
|
|
|
|
//gst_caps_unref (caps_yuv_mask);
|
|
|
|
//gst_caps_unref (caps_rgb_mask);
|
|
|
|
|
|
|
|
g_return_val_if_fail(caps->refcount > 0, NULL);
|
|
|
|
|
|
|
|
return caps;
|
2002-07-30 07:38:01 +00:00
|
|
|
}
|
|
|
|
|
2002-10-04 06:49:51 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_videotestsrc_getcaps (GstPad * pad, GstCaps * caps)
|
2002-07-26 22:18:57 +00:00
|
|
|
{
|
2002-10-04 06:49:51 +00:00
|
|
|
GstVideotestsrc *vts;
|
|
|
|
|
|
|
|
vts = GST_VIDEOTESTSRC (gst_pad_get_parent (pad));
|
|
|
|
|
2003-07-14 08:36:03 +00:00
|
|
|
#if 0
|
2003-04-16 07:52:54 +00:00
|
|
|
if (vts->forced_format != NULL) {
|
|
|
|
struct fourcc_list_struct *fourcc;
|
2003-05-14 18:43:36 +00:00
|
|
|
|
2003-04-16 07:52:54 +00:00
|
|
|
fourcc = paintrect_find_name (vts->forced_format);
|
2003-05-14 18:43:36 +00:00
|
|
|
if (fourcc) {
|
|
|
|
caps1 = paint_get_caps(fourcc);
|
|
|
|
}
|
|
|
|
}
|
2003-07-14 08:36:03 +00:00
|
|
|
#endif
|
2003-05-14 18:43:36 +00:00
|
|
|
|
2003-07-14 08:36:03 +00:00
|
|
|
caps = gst_videotestsrc_get_capslist_size (vts->width, vts->height, vts->rate);
|
2003-04-16 07:52:54 +00:00
|
|
|
|
2003-07-14 08:36:03 +00:00
|
|
|
g_return_val_if_fail(caps->refcount > 0, NULL);
|
2003-04-16 07:52:54 +00:00
|
|
|
|
2003-07-14 08:36:03 +00:00
|
|
|
return caps;
|
2002-10-04 06:49:51 +00:00
|
|
|
}
|
2002-07-26 22:18:57 +00:00
|
|
|
|
2002-10-04 06:49:51 +00:00
|
|
|
static void
|
|
|
|
gst_videotestsrc_init (GstVideotestsrc * videotestsrc)
|
|
|
|
{
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("gst_videotestsrc_init");
|
2002-07-26 22:18:57 +00:00
|
|
|
|
2002-10-04 06:49:51 +00:00
|
|
|
videotestsrc->srcpad =
|
|
|
|
gst_pad_new_from_template (GST_PAD_TEMPLATE_GET (videotestsrc_src_template_factory), "src");
|
|
|
|
gst_pad_set_getcaps_function (videotestsrc->srcpad, gst_videotestsrc_getcaps);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (videotestsrc), videotestsrc->srcpad);
|
|
|
|
gst_pad_set_get_function (videotestsrc->srcpad, gst_videotestsrc_get);
|
2003-09-11 19:25:40 +00:00
|
|
|
gst_pad_set_link_function (videotestsrc->srcpad, gst_videotestsrc_src_link);
|
|
|
|
gst_pad_set_unlink_function (videotestsrc->srcpad, gst_videotestsrc_src_unlink);
|
2002-07-26 22:18:57 +00:00
|
|
|
|
2003-06-11 22:39:37 +00:00
|
|
|
videotestsrc->pool = NULL;
|
|
|
|
gst_videotestsrc_set_pattern(videotestsrc, GST_VIDEOTESTSRC_SMPTE);
|
2003-07-14 08:36:03 +00:00
|
|
|
|
|
|
|
videotestsrc->sync = TRUE;
|
|
|
|
videotestsrc->default_width = 320;
|
|
|
|
videotestsrc->default_height = 240;
|
|
|
|
videotestsrc->default_rate = 30.;
|
2003-06-11 22:39:37 +00:00
|
|
|
}
|
2003-05-18 23:20:24 +00:00
|
|
|
|
2002-07-26 22:18:57 +00:00
|
|
|
|
2003-10-08 16:08:22 +00:00
|
|
|
static GstData *
|
2002-10-04 06:49:51 +00:00
|
|
|
gst_videotestsrc_get (GstPad * pad)
|
2002-07-26 22:18:57 +00:00
|
|
|
{
|
|
|
|
GstVideotestsrc *videotestsrc;
|
|
|
|
gulong newsize;
|
|
|
|
GstBuffer *buf;
|
2003-05-01 06:24:34 +00:00
|
|
|
GstClockTimeDiff jitter = 0;
|
2002-07-26 22:18:57 +00:00
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("gst_videotestsrc_get");
|
2002-07-26 22:18:57 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (pad != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GST_IS_PAD (pad), NULL);
|
|
|
|
|
|
|
|
videotestsrc = GST_VIDEOTESTSRC (gst_pad_get_parent (pad));
|
|
|
|
|
2003-07-14 08:36:03 +00:00
|
|
|
g_return_val_if_fail (videotestsrc->fourcc != NULL, NULL);
|
|
|
|
|
2002-10-04 06:49:51 +00:00
|
|
|
newsize = (videotestsrc->width * videotestsrc->height * videotestsrc->bpp) >> 3;
|
2003-07-14 08:36:03 +00:00
|
|
|
g_return_val_if_fail (newsize > 0, NULL);
|
2002-07-26 22:18:57 +00:00
|
|
|
|
2003-07-27 05:31:01 +00:00
|
|
|
GST_DEBUG ("size=%ld %dx%d", newsize, videotestsrc->width, videotestsrc->height);
|
2002-07-26 22:18:57 +00:00
|
|
|
|
2002-07-30 07:38:01 +00:00
|
|
|
buf = NULL;
|
2002-10-04 06:49:51 +00:00
|
|
|
if (videotestsrc->pool) {
|
|
|
|
buf = gst_buffer_new_from_pool (videotestsrc->pool, 0, 0);
|
2003-05-10 17:37:27 +00:00
|
|
|
/* if the buffer we get is too small, make our own */
|
2003-05-13 07:14:36 +00:00
|
|
|
if (buf && GST_BUFFER_SIZE (buf) < newsize){
|
2003-05-10 17:37:27 +00:00
|
|
|
gst_buffer_unref (buf);
|
|
|
|
buf = NULL;
|
|
|
|
}
|
2002-07-30 07:38:01 +00:00
|
|
|
}
|
2002-10-04 06:49:51 +00:00
|
|
|
if (!buf) {
|
2003-07-27 05:31:01 +00:00
|
|
|
buf = gst_buffer_new_and_alloc (newsize);
|
2002-07-30 07:38:01 +00:00
|
|
|
}
|
2002-10-04 06:49:51 +00:00
|
|
|
g_return_val_if_fail (GST_BUFFER_DATA (buf) != NULL, NULL);
|
2002-07-30 01:25:26 +00:00
|
|
|
|
2002-10-04 06:49:51 +00:00
|
|
|
videotestsrc->make_image (videotestsrc, (void *) GST_BUFFER_DATA (buf),
|
|
|
|
videotestsrc->width, videotestsrc->height);
|
2003-05-01 06:24:34 +00:00
|
|
|
|
2003-05-18 23:20:24 +00:00
|
|
|
if (videotestsrc->sync){
|
|
|
|
do {
|
|
|
|
GstClockID id;
|
2003-05-01 06:24:34 +00:00
|
|
|
|
2003-07-14 08:36:03 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (buf) = videotestsrc->timestamp_offset +
|
|
|
|
(videotestsrc->n_frames * GST_SECOND)/(double)videotestsrc->rate;
|
|
|
|
videotestsrc->n_frames++;
|
2003-05-01 06:24:34 +00:00
|
|
|
|
2003-07-14 08:36:03 +00:00
|
|
|
/* FIXME this is not correct if we do QoS */
|
2003-05-18 23:20:24 +00:00
|
|
|
if (videotestsrc->clock) {
|
2003-07-14 08:36:03 +00:00
|
|
|
id = gst_clock_new_single_shot_id (videotestsrc->clock,
|
|
|
|
GST_BUFFER_TIMESTAMP (buf));
|
2003-05-18 23:20:24 +00:00
|
|
|
gst_element_clock_wait (GST_ELEMENT (videotestsrc), id, &jitter);
|
|
|
|
gst_clock_id_free (id);
|
|
|
|
}
|
|
|
|
} while (jitter > 100 * GST_MSECOND);
|
2003-07-14 08:36:03 +00:00
|
|
|
}else{
|
|
|
|
GST_BUFFER_TIMESTAMP (buf) = videotestsrc->timestamp_offset +
|
|
|
|
(videotestsrc->n_frames * GST_SECOND)/(double)videotestsrc->rate;
|
|
|
|
videotestsrc->n_frames++;
|
2003-05-01 06:24:34 +00:00
|
|
|
}
|
2002-07-26 22:18:57 +00:00
|
|
|
|
2003-10-08 16:08:22 +00:00
|
|
|
return GST_DATA (buf);
|
2002-07-26 22:18:57 +00:00
|
|
|
}
|
|
|
|
|
2003-04-23 07:38:32 +00:00
|
|
|
static void
|
|
|
|
gst_videotestsrc_set_pattern (GstVideotestsrc *src, int pattern_type)
|
|
|
|
{
|
|
|
|
src->type = pattern_type;
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("setting pattern to %d\n",pattern_type);
|
2003-04-23 07:38:32 +00:00
|
|
|
switch(pattern_type){
|
|
|
|
case GST_VIDEOTESTSRC_SMPTE:
|
|
|
|
src->make_image = gst_videotestsrc_smpte;
|
|
|
|
break;
|
|
|
|
case GST_VIDEOTESTSRC_SNOW:
|
|
|
|
src->make_image = gst_videotestsrc_snow;
|
|
|
|
break;
|
|
|
|
case GST_VIDEOTESTSRC_BLACK:
|
|
|
|
src->make_image = gst_videotestsrc_black;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-26 22:18:57 +00:00
|
|
|
static void
|
2002-10-04 06:49:51 +00:00
|
|
|
gst_videotestsrc_set_property (GObject * object, guint prop_id, const GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2002-07-26 22:18:57 +00:00
|
|
|
{
|
|
|
|
GstVideotestsrc *src;
|
2003-05-13 07:14:36 +00:00
|
|
|
const char *format;
|
2002-07-26 22:18:57 +00:00
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2002-10-04 06:49:51 +00:00
|
|
|
g_return_if_fail (GST_IS_VIDEOTESTSRC (object));
|
|
|
|
src = GST_VIDEOTESTSRC (object);
|
2002-07-26 22:18:57 +00:00
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("gst_videotestsrc_set_property");
|
2002-07-26 22:18:57 +00:00
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_WIDTH:
|
2003-07-14 08:36:03 +00:00
|
|
|
src->default_width = g_value_get_int (value);
|
2002-07-26 22:18:57 +00:00
|
|
|
break;
|
|
|
|
case ARG_HEIGHT:
|
2003-07-14 08:36:03 +00:00
|
|
|
src->default_height = g_value_get_int (value);
|
2002-07-26 22:18:57 +00:00
|
|
|
break;
|
2002-10-04 06:49:51 +00:00
|
|
|
case ARG_FOURCC:
|
2003-05-13 07:14:36 +00:00
|
|
|
format = g_value_get_string (value);
|
|
|
|
if(paintrect_find_name (format) != NULL){
|
|
|
|
src->forced_format = g_strdup(format);
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("forcing format to \"%s\"\n", format);
|
2003-05-13 07:14:36 +00:00
|
|
|
}else{
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("unknown format \"%s\"\n", format);
|
2003-05-13 07:14:36 +00:00
|
|
|
}
|
2002-07-26 22:18:57 +00:00
|
|
|
break;
|
2002-10-23 06:03:03 +00:00
|
|
|
case ARG_RATE:
|
2003-07-14 08:36:03 +00:00
|
|
|
src->default_rate = g_value_get_float (value);
|
2002-10-23 06:03:03 +00:00
|
|
|
break;
|
2003-04-23 07:38:32 +00:00
|
|
|
case ARG_TYPE:
|
|
|
|
gst_videotestsrc_set_pattern (src, g_value_get_enum (value));
|
|
|
|
break;
|
2003-05-18 23:20:24 +00:00
|
|
|
case ARG_SYNC:
|
|
|
|
src->sync = g_value_get_boolean (value);
|
|
|
|
break;
|
2002-07-26 22:18:57 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-10-04 06:49:51 +00:00
|
|
|
gst_videotestsrc_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec)
|
2002-07-26 22:18:57 +00:00
|
|
|
{
|
|
|
|
GstVideotestsrc *src;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2002-10-04 06:49:51 +00:00
|
|
|
g_return_if_fail (GST_IS_VIDEOTESTSRC (object));
|
|
|
|
src = GST_VIDEOTESTSRC (object);
|
2002-07-26 22:18:57 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_WIDTH:
|
2003-07-14 08:36:03 +00:00
|
|
|
g_value_set_int (value, src->default_width);
|
2002-07-26 22:18:57 +00:00
|
|
|
break;
|
|
|
|
case ARG_HEIGHT:
|
2003-07-14 08:36:03 +00:00
|
|
|
g_value_set_int (value, src->default_height);
|
2002-07-26 22:18:57 +00:00
|
|
|
break;
|
2002-10-04 06:49:51 +00:00
|
|
|
case ARG_FOURCC:
|
2003-05-13 07:14:36 +00:00
|
|
|
g_value_set_string (value, src->forced_format);
|
2002-07-26 22:18:57 +00:00
|
|
|
break;
|
2002-10-23 06:03:03 +00:00
|
|
|
case ARG_RATE:
|
2003-07-14 08:36:03 +00:00
|
|
|
g_value_set_float (value, src->default_rate);
|
2002-10-23 06:03:03 +00:00
|
|
|
break;
|
2003-04-23 07:38:32 +00:00
|
|
|
case ARG_TYPE:
|
|
|
|
g_value_set_enum (value, src->type);
|
|
|
|
break;
|
2003-05-18 23:20:24 +00:00
|
|
|
case ARG_SYNC:
|
|
|
|
g_value_set_boolean (value, src->sync);
|
|
|
|
break;
|
2002-07-26 22:18:57 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2003-11-02 20:48:33 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2002-07-26 22:18:57 +00:00
|
|
|
{
|
2003-11-02 20:48:33 +00:00
|
|
|
return gst_element_register (plugin, "videotestsrc", GST_RANK_NONE, GST_TYPE_VIDEOTESTSRC);
|
2002-07-26 22:18:57 +00:00
|
|
|
}
|
|
|
|
|
2003-11-02 20:48:33 +00:00
|
|
|
GST_PLUGIN_DEFINE (
|
2002-07-26 22:18:57 +00:00
|
|
|
GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"videotestsrc",
|
2003-11-02 20:48:33 +00:00
|
|
|
"Creates a test video stream",
|
|
|
|
plugin_init,
|
|
|
|
VERSION,
|
|
|
|
GST_LICENSE,
|
|
|
|
GST_COPYRIGHT,
|
|
|
|
GST_PACKAGE,
|
|
|
|
GST_ORIGIN
|
|
|
|
)
|
2002-07-26 22:18:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
|