Skip to content
Permalink
Browse files

gst: new sub-library

This library contains three classes:

- OwrGstAudioRenderer
- OwrGstVideoRenderer
- OwrGstMediaSource

Applications can use these renderers and the source to enable the use
of custom GStreamer source and sink elements in the OpenWebRTC
pipeline. For instance, this is specially useful if your application
needs to render video with a very specific (sometimes even internal to
your project) sink.

By default this sub-library is disabled. It can be enabled by using
the --enable-owr-gst=yes configure option.

See #221
  • Loading branch information...
philn authored and superdump committed Mar 27, 2015
1 parent 3e93337 commit c4778589e69da2368fad0c2344260cb46be76aa7
@@ -1,11 +1,17 @@
## Process this file with automake to produce Makefile.in

SUBDIRS = transport local owr docs
SUBDIRS = transport local owr

if OWR_BRIDGE
SUBDIRS += bridge
endif

if OWR_GST
SUBDIRS += gst
endif

SUBDIRS += docs

if OWR_TESTS
SUBDIRS += tests
endif
@@ -119,6 +119,24 @@ fi
AC_SUBST(GST_STATIC_PLUGINS_DIR)
AM_CONDITIONAL(OWR_STATIC, test x$enable_owr_static = xyes)

dnl build GStreamer library or not
AC_MSG_CHECKING([whether to build owr-gst or not])
AC_ARG_ENABLE(owr-gst,
AC_HELP_STRING(
[--enable-owr-gst],
[Enable owr-gst @<:@default=no@:>@]),
[case "${enableval}" in
yes) enable_owr_gst=yes ;;
no) enable_owr_gst=no ;;
*) AC_MSG_ERROR(bad value ${enableval} for --enable-owr-gst) ;;
esac],[enable_owr_gst=no])
AC_MSG_RESULT([$enable_owr_gst])
if test "x$enable_owr_gst" = xyes; then
AC_DEFINE(OWR_GST, 1,
[Define if building owr-gst])
fi
AM_CONDITIONAL(OWR_GST, test x$enable_owr_gst = xyes)

dnl pick dependencies and build flags based on OS
case "$host_os" in
darwin*)
@@ -286,6 +304,7 @@ bridge/client/Makefile
bridge/seed/Makefile
bridge/shared/Makefile
bridge/worker/Makefile
gst/Makefile
owr/Makefile
owr/openwebrtc-$OWR_API_VERSION.pc
transport/Makefile
@@ -0,0 +1,39 @@
## Process this file with automake to produce Makefile.in

AM_CPPFLAGS = \
-DPACKAGE_LOCALE_DIR=\""$(localedir)"\" \
-DPACKAGE_SRC_DIR=\""$(srcdir)"\" \
-DPACKAGE_DATA_DIR=\""$(pkgdatadir)"\" \
$(GLIB_CFLAGS) \
$(GSTREAMER_CFLAGS) \
-I$(top_srcdir)/owr \
-I$(top_srcdir)/local

AM_CFLAGS = \
-Wall \
-Wextra \
-Werror \
$(DEBUG_CFLAGS)

noinst_LTLIBRARIES = libopenwebrtc_gst.la

libopenwebrtc_gst_la_SOURCES = \
owr_gst_audio_renderer.c \
owr_gst_media_source.c \
owr_gst_video_renderer.c

libopenwebrtc_gst_la_LIBADD = \
$(top_builddir)/owr/libopenwebrtc.la \
$(GSTREAMER_LIBS) \
$(GLIB_LIBS)

libopenwebrtc_gst_la_DEPENDENCIES = \
$(top_builddir)/owr/libopenwebrtc.la

includedir = $(prefix)/include/owr
include_HEADERS = \
owr_gst_audio_renderer.h \
owr_gst_media_source.h \
owr_gst_video_renderer.h

-include $(top_srcdir)/git.mk
@@ -0,0 +1,175 @@
/*
* Copyright (c) 2015, Igalia S.L
* Author: Philippe Normand <philn@igalia.com>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*/

/*/
\*\ OwrGstAudioRenderer
/*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "owr_gst_audio_renderer.h"

#include "owr_media_renderer_private.h"
#include "owr_private.h"

#define DEFAULT_AUDIO_SINK "pulsesink"

#define OWR_GST_AUDIO_RENDERER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OWR_GST_TYPE_AUDIO_RENDERER, OwrGstAudioRendererPrivate))

G_DEFINE_TYPE(OwrGstAudioRenderer, owr_gst_audio_renderer, OWR_TYPE_AUDIO_RENDERER)

enum {
PROP_0,
PROP_SINK,
N_PROPERTIES
};

static GParamSpec *obj_properties[N_PROPERTIES] = {NULL, };

static void owr_gst_audio_renderer_set_property(GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec);
static void owr_gst_audio_renderer_get_property(GObject *object, guint property_id,
GValue *value, GParamSpec *pspec);

static GstElement *owr_gst_audio_renderer_get_sink(OwrMediaRenderer *renderer);

struct _OwrGstAudioRendererPrivate {
GstElement *sink;
};

static void owr_gst_audio_renderer_dispose(GObject *object)
{
OwrGstAudioRenderer *renderer = OWR_GST_AUDIO_RENDERER(object);
OwrGstAudioRendererPrivate *priv = renderer->priv;

if (priv->sink) {
gst_object_unref(priv->sink);
priv->sink = NULL;
}

G_OBJECT_CLASS(owr_gst_audio_renderer_parent_class)->dispose(object);
}

static void owr_gst_audio_renderer_class_init(OwrGstAudioRendererClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
OwrMediaRendererClass *media_renderer_class = OWR_MEDIA_RENDERER_CLASS(klass);

g_type_class_add_private(klass, sizeof(OwrGstAudioRendererPrivate));

obj_properties[PROP_SINK] = g_param_spec_object("sink", "sink",
"Audio sink to use for rendering (default: pulsesink)", G_TYPE_OBJECT,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

gobject_class->set_property = owr_gst_audio_renderer_set_property;
gobject_class->get_property = owr_gst_audio_renderer_get_property;

gobject_class->dispose = owr_gst_audio_renderer_dispose;

media_renderer_class->get_sink = (void *(*)(OwrMediaRenderer *))owr_gst_audio_renderer_get_sink;

g_object_class_install_properties(gobject_class, N_PROPERTIES, obj_properties);
}

static void owr_gst_audio_renderer_init(OwrGstAudioRenderer *renderer)
{
OwrGstAudioRendererPrivate *priv;
renderer->priv = priv = OWR_GST_AUDIO_RENDERER_GET_PRIVATE(renderer);

priv->sink = NULL;
}

static void owr_gst_audio_renderer_set_property(GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec)
{
OwrGstAudioRendererPrivate *priv;
GstElement *sink;

g_return_if_fail(object);
priv = OWR_GST_AUDIO_RENDERER_GET_PRIVATE(object);

switch (property_id) {
case PROP_SINK:
sink = g_value_get_object(value);
if (!GST_IS_ELEMENT(sink))
break;
if (priv->sink)
gst_object_unref(priv->sink);
priv->sink = sink;
gst_object_ref_sink(sink);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
break;
}
}

static void owr_gst_audio_renderer_get_property(GObject *object, guint property_id,
GValue *value, GParamSpec *pspec)
{
OwrGstAudioRendererPrivate *priv;

g_return_if_fail(object);
priv = OWR_GST_AUDIO_RENDERER_GET_PRIVATE(object);

switch (property_id) {
case PROP_SINK:
g_value_set_object(value, priv->sink);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
break;
}
}

/**
* owr_gst_audio_renderer_new: (constructor)
* @sink:
*
* Returns: The new #OwrGstAudioRenderer
*/
OwrGstAudioRenderer *owr_gst_audio_renderer_new(GstElement *sink)
{
return g_object_new(OWR_GST_TYPE_AUDIO_RENDERER,
"media-type", OWR_MEDIA_TYPE_AUDIO,
"sink", sink,
NULL);
}

static GstElement *owr_gst_audio_renderer_get_sink(OwrMediaRenderer *renderer)
{
OwrGstAudioRenderer *audio_renderer;
OwrGstAudioRendererPrivate *priv;
GstElement *sink;

g_assert(renderer);
audio_renderer = OWR_GST_AUDIO_RENDERER(renderer);
priv = audio_renderer->priv;

sink = priv->sink ? priv->sink : gst_element_factory_make(DEFAULT_AUDIO_SINK, "audio-renderer-sink");
return sink;
}
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2015, Igalia S.L
* Author: Philippe Normand <philn@igalia.com>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*/

/*/
\*\ OwrGstAudioRenderer
/*/

#ifndef __OWR_GST_AUDIO_RENDERER_H__
#define __OWR_GST_AUDIO_RENDERER_H__

#include "owr_audio_renderer.h"

#include <gst/gst.h>

G_BEGIN_DECLS

#define OWR_GST_TYPE_AUDIO_RENDERER (owr_gst_audio_renderer_get_type())
#define OWR_GST_AUDIO_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OWR_GST_TYPE_AUDIO_RENDERER, OwrGstAudioRenderer))
#define OWR_GST_AUDIO_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OWR_GST_TYPE_AUDIO_RENDERER, OwrGstAudioRendererClass))
#define OWR_GST_IS_AUDIO_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OWR_GST_TYPE_AUDIO_RENDERER))
#define OWR_GST_IS_AUDIO_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OWR_GST_TYPE_AUDIO_RENDERER))
#define OWR_GST_AUDIO_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OWR_GST_TYPE_AUDIO_RENDERER, OwrGstAudioRendererClass))

typedef struct _OwrGstAudioRenderer OwrGstAudioRenderer;
typedef struct _OwrGstAudioRendererClass OwrGstAudioRendererClass;
typedef struct _OwrGstAudioRendererPrivate OwrGstAudioRendererPrivate;

struct _OwrGstAudioRenderer {
OwrAudioRenderer parent_instance;

/*< private >*/
OwrGstAudioRendererPrivate *priv;
};

struct _OwrGstAudioRendererClass {
OwrAudioRendererClass parent_class;
};

GType owr_gst_audio_renderer_get_type(void) G_GNUC_CONST;

OwrGstAudioRenderer *owr_gst_audio_renderer_new(GstElement* sink);

G_END_DECLS

#endif /* __OWR_GST_AUDIO_RENDERER_H__ */
Oops, something went wrong.

0 comments on commit c477858

Please sign in to comment.
You can’t perform that action at this time.