videomixer2: Add videomixer2 element

This is based on collectpads2 and is synchronizing
all streams based on the running time.

New features compared to old videomixer:
 * Synchronizing frames on the running time
 * Improved and simplified negotiation
 * Full QoS support
 * Variable framerate support

Fixes bug #626048, #624905.
This commit is contained in:
Sebastian Dröge 2010-07-26 16:07:15 +02:00
parent 6940559c46
commit bcfd60a8d2
6 changed files with 4362 additions and 5 deletions

View file

@ -3,14 +3,27 @@ plugin_LTLIBRARIES = libgstvideomixer.la
ORC_SOURCE=blendorc
include $(top_srcdir)/common/orc.mak
libgstvideomixer_la_SOURCES = videomixer.c blend.c
libgstvideomixer_la_SOURCES = \
videomixer.c \
blend.c \
videomixer2.c \
gstcollectpads2.c
nodist_libgstvideomixer_la_SOURCES = $(ORC_NODIST_SOURCES)
libgstvideomixer_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) \
$(GST_BASE_CFLAGS) $(GST_CONTROLLER_CFLAGS) $(GST_CFLAGS) $(ORC_CFLAGS)
libgstvideomixer_la_LIBADD = $(GST_PLUGINS_BASE_LIBS) -lgstvideo-@GST_MAJORMINOR@ \
$(GST_BASE_CFLAGS) $(GST_CONTROLLER_CFLAGS) $(GST_CFLAGS) $(ORC_CFLAGS) \
-DGstCollectPads2=GstVideoMixer2Pads \
-DGstCollectPads2Class=GstVideoMixer2PadsClass
libgstvideomixer_la_LIBADD = $(GST_PLUGINS_BASE_LIBS) \
-lgstvideo-@GST_MAJORMINOR@ \
$(GST_BASE_LIBS) $(GST_CONTROLLER_LIBS) $(GST_LIBS) $(ORC_LIBS)
libgstvideomixer_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstvideomixer_la_LIBTOOLFLAGS = --tag=disable-static
# headers we need but don't want installed
noinst_HEADERS = videomixer.h videomixerpad.h blend.h
noinst_HEADERS = \
videomixer.h \
videomixerpad.h \
blend.h \
videomixer2.h \
gstcollectpads2.h

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,336 @@
/* GStreamer
* Copyright (C) 2005 Wim Taymans <wim@fluendo.com>
* Copyright (C) 2008 Mark Nauwelaerts <mnauw@users.sourceforge.net>
*
* gstcollectpads2.h:
*
* 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_COLLECT_PADS2_H__
#define __GST_COLLECT_PADS2_H__
#include <gst/gst.h>
G_BEGIN_DECLS
#define GST_TYPE_COLLECT_PADS2 (gst_collect_pads2_get_type())
#define GST_COLLECT_PADS2(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_COLLECT_PADS2,GstCollectPads2))
#define GST_COLLECT_PADS2_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_COLLECT_PADS2,GstCollectPads2Class))
#define GST_COLLECT_PADS2_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_COLLECT_PADS2,GstCollectPads2Class))
#define GST_IS_COLLECT_PADS2(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_COLLECT_PADS2))
#define GST_IS_COLLECT_PADS2_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_COLLECT_PADS2))
typedef struct _GstCollectData2 GstCollectData2;
typedef struct _GstCollectPads2 GstCollectPads2;
typedef struct _GstCollectPads2Class GstCollectPads2Class;
/**
* GstCollectData2DestroyNotify:
* @data: the #GstCollectData2 that will be freed
*
* A function that will be called when the #GstCollectData2 will be freed.
* It is passed the pointer to the structure and should free any custom
* memory and resources allocated for it.
*
* Since: 0.10.12
*/
typedef void (*GstCollectData2DestroyNotify) (GstCollectData2 *data);
/**
* GstCollectPads2StateFlags:
* @GST_COLLECT_PADS2_STATE_EOS: Set if collectdata's pad is EOS.
* @GST_COLLECT_PADS2_STATE_FLUSHING: Set if collectdata's pad is flushing.
* @GST_COLLECT_PADS2_STATE_NEW_SEGMENT: Set if collectdata's pad received a
* new_segment event.
* @GST_COLLECT_PADS2_STATE_WAITING: Set if collectdata's pad must be waited
* for when collecting.
* @GST_COLLECT_PADS2_STATE_LOCKED: Set collectdata's pad WAITING state must
* not be changed.
* #GstCollectPads2StateFlags indicate private state of a collectdata('s pad).
*/
typedef enum {
GST_COLLECT_PADS2_STATE_EOS = 1 << 0,
GST_COLLECT_PADS2_STATE_FLUSHING = 1 << 1,
GST_COLLECT_PADS2_STATE_NEW_SEGMENT = 1 << 2,
GST_COLLECT_PADS2_STATE_WAITING = 1 << 3,
GST_COLLECT_PADS2_STATE_LOCKED = 1 << 4
} GstCollectPads2StateFlags;
/**
* GST_COLLECT_PADS2_STATE:
* @data: a #GstCollectData2.
*
* A flags word containing #GstCollectPads2StateFlags flags set
* on this collected pad.
*/
#define GST_COLLECT_PADS2_STATE(data) (((GstCollectData2 *) data)->state)
/**
* GST_COLLECT_PADS2_STATE_IS_SET:
* @data: a #GstCollectData2.
* @flag: the #GstCollectPads2StateFlags to check.
*
* Gives the status of a specific flag on a collected pad.
*/
#define GST_COLLECT_PADS2_STATE_IS_SET(data,flag) !!(GST_COLLECT_PADS2_STATE (data) & flag)
/**
* GST_COLLECT_PADS2_STATE_SET:
* @data: a #GstCollectData2.
* @flag: the #GstCollectPads2StateFlags to set.
*
* Sets a state flag on a collected pad.
*/
#define GST_COLLECT_PADS2_STATE_SET(data,flag) (GST_COLLECT_PADS2_STATE (data) |= flag)
/**
* GST_COLLECT_PADS2_STATE_UNSET:
* @data: a #GstCollectData2.
* @flag: the #GstCollectPads2StateFlags to clear.
*
* Clears a state flag on a collected pad.
*/
#define GST_COLLECT_PADS2_STATE_UNSET(data,flag) (GST_COLLECT_PADS2_STATE (data) &= ~(flag))
#define GST_COLLECT_PADS2_FLOW_DROP GST_FLOW_CUSTOM_SUCCESS
/**
* GstCollectData2:
* @collect: owner #GstCollectPads2
* @pad: #GstPad managed by this data
* @buffer: currently queued buffer.
* @pos: position in the buffer
* @segment: last segment received.
*
* Structure used by the collect_pads2.
*/
struct _GstCollectData2
{
/* with STREAM_LOCK of @collect */
GstCollectPads2 *collect;
GstPad *pad;
GstBuffer *buffer;
guint pos;
GstSegment segment;
/*< private >*/
/* state: bitfield for easier extension;
* eos, flushing, new_segment, waiting */
guint state;
/* refcounting for struct, and destroy callback */
GstCollectData2DestroyNotify destroy_notify;
gint refcount;
gpointer _gst_reserved[GST_PADDING];
};
/**
* GstCollectPads2Function:
* @pads: the #GstCollectPads2 that trigered the callback
* @user_data: user data passed to gst_collect_pads2_set_function()
*
* A function that will be called when all pads have received data.
*
* Returns: #GST_FLOW_OK for success
*/
typedef GstFlowReturn (*GstCollectPads2Function) (GstCollectPads2 *pads, gpointer user_data);
/**
* GstCollectPads2BufferFunction:
* @pads: the #GstCollectPads2 that trigered the callback
* @data: the #GstCollectData2 of pad that has received the buffer
* @buffer: the #GstBuffer
* @user_data: user data passed to gst_collect_pads2_set_buffer_function()
*
* A function that will be called when a (considered oldest) buffer can be muxed.
* If all pads have reached EOS, this function is called with NULL @buffer
* and NULL @data.
*
* Returns: #GST_FLOW_OK for success
*/
typedef GstFlowReturn (*GstCollectPads2BufferFunction) (GstCollectPads2 *pads, GstCollectData2 *data,
GstBuffer *buffer, gpointer user_data);
/**
* GstCollectPads2CompareFunction:
* @pads: the #GstCollectPads that is comparing the timestamps
* @data1: the first #GstCollectData2
* @timestamp1: the first timestamp
* @data2: the second #GstCollectData2
* @timestamp2: the second timestamp
* @user_data: user data passed to gst_collect_pads2_set_compare_function()
*
* A function for comparing two timestamps of buffers or newsegments collected on one pad.
*
* Returns: Integer less than zero when first timestamp is deemed older than the second one.
* Zero if the timestamps are deemed equally old.
* Integer greate than zero when second timestamp is deemed older than the first one.
*/
typedef gint (*GstCollectPads2CompareFunction) (GstCollectPads2 *pads,
GstCollectData2 * data1, GstClockTime timestamp1,
GstCollectData2 * data2, GstClockTime timestamp2,
gpointer user_data);
/**
* GstCollectPads2EventFunction:
* @pads: the #GstCollectPads2 that trigered the callback
* @pad: the #GstPad that received an event
* @event: the #GstEvent received
* @user_data: user data passed to gst_collect_pads2_set_event_function()
*
* A function that will be called after collectpads has processed the event.
*
* Returns: %TRUE if the pad could handle the event
*/
typedef gboolean (*GstCollectPads2EventFunction) (GstCollectPads2 *pads, GstCollectData2 * pad,
GstEvent * event, gpointer user_data);
/**
* GST_COLLECT_PADS2_GET_STREAM_LOCK:
* @pads: a #GstCollectPads2
*
* Get the stream lock of @pads. The stream lock is used to coordinate and
* serialize execution among the various streams being collected, and in
* protecting the resources used to accomplish this.
*/
#define GST_COLLECT_PADS2_GET_STREAM_LOCK(pads) (&((GstCollectPads2 *)pads)->stream_lock)
/**
* GST_COLLECT_PADS2_STREAM_LOCK:
* @pads: a #GstCollectPads2
*
* Lock the stream lock of @pads.
*/
#define GST_COLLECT_PADS2_STREAM_LOCK(pads) (g_static_rec_mutex_lock(GST_COLLECT_PADS2_GET_STREAM_LOCK (pads)))
/**
* GST_COLLECT_PADS2_STREAM_UNLOCK:
* @pads: a #GstCollectPads2
*
* Unlock the stream lock of @pads.
*/
#define GST_COLLECT_PADS2_STREAM_UNLOCK(pads) (g_static_rec_mutex_unlock(GST_COLLECT_PADS2_GET_STREAM_LOCK (pads)))
/**
* GstCollectPads2:
* @data: #GList of #GstCollectData2 managed by this #GstCollectPads2.
*
* Collectpads object.
*/
struct _GstCollectPads2 {
GstObject object;
/*< public >*/ /* with LOCK and/or STREAM_LOCK */
GSList *data; /* list of CollectData items */
/*< private >*/
GStaticRecMutex stream_lock; /* used to serialize collection among several streams */
/* with LOCK and/or STREAM_LOCK*/
gboolean started;
/* with STREAM_LOCK */
guint32 cookie; /* @data list cookie */
guint numpads; /* number of pads in @data */
guint queuedpads; /* number of pads with a buffer */
guint eospads; /* number of pads that are EOS */
GstClockTime earliest_time; /* Current earliest time */
GstCollectData2 *earliest_data; /* Pad data for current earliest time */
/* with LOCK */
GSList *pad_list; /* updated pad list */
guint32 pad_cookie; /* updated cookie */
GstCollectPads2Function func; /* function and user_data for callback */
gpointer user_data;
GstCollectPads2BufferFunction prepare_buffer_func; /* function and user_data for prepare buffer callback */
gpointer prepare_buffer_user_data;
GstCollectPads2BufferFunction buffer_func; /* function and user_data for buffer callback */
gpointer buffer_user_data;
GstCollectPads2CompareFunction compare_func;
gpointer compare_user_data;
GstCollectPads2EventFunction event_func; /* function and data for event callback */
gpointer event_user_data;
/* no other lock needed */
GMutex *evt_lock; /* these make up sort of poor man's event signaling */
GCond *evt_cond;
guint32 evt_cookie;
gpointer _gst_reserved[GST_PADDING + 0];
};
struct _GstCollectPads2Class {
GstObjectClass parent_class;
/*< private >*/
gpointer _gst_reserved[GST_PADDING];
};
GType gst_collect_pads2_get_type(void);
/* creating the object */
GstCollectPads2* gst_collect_pads2_new (void);
/* set the callbacks */
void gst_collect_pads2_set_function (GstCollectPads2 *pads, GstCollectPads2Function func,
gpointer user_data);
void gst_collect_pads2_set_prepare_buffer_function (GstCollectPads2 *pads,
GstCollectPads2BufferFunction func, gpointer user_data);
void gst_collect_pads2_set_buffer_function (GstCollectPads2 *pads,
GstCollectPads2BufferFunction func, gpointer user_data);
void gst_collect_pads2_set_event_function (GstCollectPads2 *pads,
GstCollectPads2EventFunction func, gpointer user_data);
void gst_collect_pads2_set_compare_function (GstCollectPads2 *pads,
GstCollectPads2CompareFunction func, gpointer user_data);
/* pad management */
GstCollectData2* gst_collect_pads2_add_pad (GstCollectPads2 *pads, GstPad *pad, guint size);
GstCollectData2* gst_collect_pads2_add_pad_full (GstCollectPads2 *pads, GstPad *pad, guint size, GstCollectData2DestroyNotify destroy_notify,
gboolean lock);
gboolean gst_collect_pads2_remove_pad (GstCollectPads2 *pads, GstPad *pad);
gboolean gst_collect_pads2_is_active (GstCollectPads2 *pads, GstPad *pad);
void gst_mux_pads_set_locked (GstCollectPads2 *pads, GstCollectData2 *data,
gboolean locked);
/* start/stop collection */
GstFlowReturn gst_collect_pads2_collect (GstCollectPads2 *pads);
GstFlowReturn gst_collect_pads2_collect_range (GstCollectPads2 *pads, guint64 offset, guint length);
void gst_collect_pads2_start (GstCollectPads2 *pads);
void gst_collect_pads2_stop (GstCollectPads2 *pads);
void gst_collect_pads2_set_flushing (GstCollectPads2 *pads, gboolean flushing);
/* get collected buffers */
GstBuffer* gst_collect_pads2_peek (GstCollectPads2 *pads, GstCollectData2 *data);
GstBuffer* gst_collect_pads2_pop (GstCollectPads2 *pads, GstCollectData2 *data);
/* get collected bytes */
guint gst_collect_pads2_available (GstCollectPads2 *pads);
guint gst_collect_pads2_read (GstCollectPads2 *pads, GstCollectData2 *data,
guint8 **bytes, guint size);
guint gst_collect_pads2_flush (GstCollectPads2 *pads, GstCollectData2 *data,
guint size);
GstBuffer* gst_collect_pads2_read_buffer (GstCollectPads2 * pads, GstCollectData2 * data,
guint size);
GstBuffer* gst_collect_pads2_take_buffer (GstCollectPads2 * pads, GstCollectData2 * data,
guint size);
/* setting and unsetting waiting mode */
void gst_collect_pads2_set_waiting (GstCollectPads2 *pads, GstCollectData2 *data,
gboolean waiting);
G_END_DECLS
#endif /* __GST_COLLECT_PADS22_H__ */

View file

@ -85,6 +85,7 @@
#endif
#include "videomixer.h"
#include "videomixer2.h"
GST_DEBUG_CATEGORY_STATIC (gst_videomixer_debug);
#define GST_CAT_DEFAULT gst_videomixer_debug
@ -1855,7 +1856,7 @@ plugin_init (GstPlugin * plugin)
gst_video_mixer_init_blend ();
return gst_element_register (plugin, "videomixer", GST_RANK_PRIMARY,
GST_TYPE_VIDEO_MIXER);
GST_TYPE_VIDEO_MIXER) && gst_videomixer2_register (plugin);
}
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,

1951
gst/videomixer/videomixer2.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,121 @@
/* Generic video mixer plugin
* Copyright (C) 2008 Wim Taymans <wim@fluendo.com>
* Copyright (C) 2010 Sebastian Dröge <sebastian.droege@collabora.co.uk>
*
* 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_VIDEO_MIXER2_H__
#define __GST_VIDEO_MIXER2_H__
#include <gst/gst.h>
#include <gst/video/video.h>
#include "blend.h"
#include "gstcollectpads2.h"
G_BEGIN_DECLS
#define GST_TYPE_VIDEO_MIXER2 (gst_videomixer2_get_type())
#define GST_VIDEO_MIXER2(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_VIDEO_MIXER2, GstVideoMixer2))
#define GST_VIDEO_MIXER2_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_VIDEO_MIXER2, GstVideoMixer2Class))
#define GST_IS_VIDEO_MIXER2(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_VIDEO_MIXER2))
#define GST_IS_VIDEO_MIXER2_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_VIDEO_MIXER2))
typedef struct _GstVideoMixer2 GstVideoMixer2;
typedef struct _GstVideoMixer2Class GstVideoMixer2Class;
/**
* GstVideoMixer2Background:
* @VIDEO_MIXER2_BACKGROUND_CHECKER: checker pattern background
* @VIDEO_MIXER2_BACKGROUND_BLACK: solid color black background
* @VIDEO_MIXER2_BACKGROUND_WHITE: solid color white background
*
* The different backgrounds videomixer can blend over.
*/
typedef enum
{
VIDEO_MIXER2_BACKGROUND_CHECKER,
VIDEO_MIXER2_BACKGROUND_BLACK,
VIDEO_MIXER2_BACKGROUND_WHITE
}
GstVideoMixer2Background;
/**
* GstVideoMixer2:
*
* The opaque #GstVideoMixer2 structure.
*/
struct _GstVideoMixer2
{
GstElement element;
/* pad */
GstPad *srcpad;
/* Lock to prevent the state to change while blending */
GMutex *lock;
/* Sink pads using Collect Pads 2*/
GstCollectPads2 *collect;
/* sinkpads, a GSList of GstVideoMixer2Pads */
GSList *sinkpads;
gint numpads;
/* Next available sinkpad index */
gint next_sinkpad;
/* Output caps */
GstVideoFormat format;
gint width, height;
gint fps_n;
gint fps_d;
gint par_n;
gint par_d;
gboolean newseg_pending;
gboolean flush_stop_pending;
GstVideoMixer2Background background;
/* Current downstream segment */
GstSegment segment;
GstClockTime ts_offset;
guint64 nframes;
/* QoS stuff */
gdouble proportion;
GstClockTime earliest_time;
guint64 qos_processed, qos_dropped;
BlendFunction blend;
FillCheckerFunction fill_checker;
FillColorFunction fill_color;
};
struct _GstVideoMixer2Class
{
GstElementClass parent_class;
};
GType gst_videomixer2_get_type (void);
gboolean gst_videomixer2_register (GstPlugin * plugin);
G_END_DECLS
#endif /* __GST_VIDEO_MIXER2_H__ */