2015-05-11 18:23:24 +02:00
|
|
|
/* GStreamer
|
|
|
|
|
* Copyright (C) <2015> Wim Taymans <wim.taymans@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* 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., 51 Franklin St, Fifth Floor,
|
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2015-06-30 18:06:36 +02:00
|
|
|
* SECTION:element-pinossink
|
2015-05-11 18:23:24 +02:00
|
|
|
*
|
|
|
|
|
* <refsect2>
|
|
|
|
|
* <title>Example launch line</title>
|
|
|
|
|
* |[
|
2015-06-30 18:06:36 +02:00
|
|
|
* gst-launch -v videotestsrc ! pinossink
|
|
|
|
|
* ]| Sends a test video source to pinos
|
2015-05-11 18:23:24 +02:00
|
|
|
* </refsect2>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#endif
|
2015-07-07 16:46:23 +02:00
|
|
|
#include "gstpinossink.h"
|
2015-05-11 18:23:24 +02:00
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
#include <gio/gunixfdmessage.h>
|
|
|
|
|
#include <gst/allocators/gstfdmemory.h>
|
|
|
|
|
|
|
|
|
|
#include "gsttmpfileallocator.h"
|
|
|
|
|
|
|
|
|
|
|
2015-06-30 18:06:36 +02:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (pinos_sink_debug);
|
|
|
|
|
#define GST_CAT_DEFAULT pinos_sink_debug
|
2015-05-11 18:23:24 +02:00
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
PROP_0,
|
|
|
|
|
PROP_LAST
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
#define PINOSS_VIDEO_CAPS GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS_ALL)
|
2015-05-11 18:23:24 +02:00
|
|
|
|
2015-06-30 18:06:36 +02:00
|
|
|
static GstStaticPadTemplate gst_pinos_sink_template =
|
2015-05-11 18:23:24 +02:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
|
GST_PAD_SINK,
|
|
|
|
|
GST_PAD_ALWAYS,
|
2015-05-15 13:34:32 +02:00
|
|
|
GST_STATIC_CAPS_ANY
|
2015-05-11 18:23:24 +02:00
|
|
|
);
|
|
|
|
|
|
2015-06-30 18:06:36 +02:00
|
|
|
#define gst_pinos_sink_parent_class parent_class
|
|
|
|
|
G_DEFINE_TYPE (GstPinosSink, gst_pinos_sink, GST_TYPE_BASE_SINK);
|
2015-05-11 18:23:24 +02:00
|
|
|
|
2015-06-30 18:06:36 +02:00
|
|
|
static void gst_pinos_sink_set_property (GObject * object, guint prop_id,
|
2015-05-11 18:23:24 +02:00
|
|
|
const GValue * value, GParamSpec * pspec);
|
2015-06-30 18:06:36 +02:00
|
|
|
static void gst_pinos_sink_get_property (GObject * object, guint prop_id,
|
2015-05-11 18:23:24 +02:00
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
|
|
|
|
|
static GstStateChangeReturn
|
2015-06-30 18:06:36 +02:00
|
|
|
gst_pinos_sink_change_state (GstElement * element, GstStateChange transition);
|
2015-05-11 18:23:24 +02:00
|
|
|
|
2015-06-30 18:06:36 +02:00
|
|
|
static GstCaps *gst_pinos_sink_getcaps (GstBaseSink * bsink, GstCaps * filter);
|
|
|
|
|
static gboolean gst_pinos_sink_setcaps (GstBaseSink * bsink, GstCaps * caps);
|
|
|
|
|
static GstCaps *gst_pinos_sink_sink_fixate (GstBaseSink * bsink,
|
2015-05-11 18:23:24 +02:00
|
|
|
GstCaps * caps);
|
|
|
|
|
|
2015-06-30 18:06:36 +02:00
|
|
|
static GstFlowReturn gst_pinos_sink_render (GstBaseSink * psink,
|
2015-05-11 18:23:24 +02:00
|
|
|
GstBuffer * buffer);
|
2015-06-30 18:06:36 +02:00
|
|
|
static gboolean gst_pinos_sink_start (GstBaseSink * basesink);
|
|
|
|
|
static gboolean gst_pinos_sink_stop (GstBaseSink * basesink);
|
2015-05-11 18:23:24 +02:00
|
|
|
|
|
|
|
|
static void
|
2015-06-30 18:06:36 +02:00
|
|
|
gst_pinos_sink_class_init (GstPinosSinkClass * klass)
|
2015-05-11 18:23:24 +02:00
|
|
|
{
|
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
GstBaseSinkClass *gstbasesink_class;
|
|
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
|
gstbasesink_class = (GstBaseSinkClass *) klass;
|
|
|
|
|
|
2015-06-30 18:06:36 +02:00
|
|
|
gobject_class->set_property = gst_pinos_sink_set_property;
|
|
|
|
|
gobject_class->get_property = gst_pinos_sink_get_property;
|
2015-05-11 18:23:24 +02:00
|
|
|
|
2015-06-30 18:06:36 +02:00
|
|
|
gstelement_class->change_state = gst_pinos_sink_change_state;
|
2015-05-11 18:23:24 +02:00
|
|
|
|
|
|
|
|
gst_element_class_set_static_metadata (gstelement_class,
|
2015-06-30 18:06:36 +02:00
|
|
|
"Pinos sink", "Sink/Video",
|
|
|
|
|
"Send video to pinos", "Wim Taymans <wim.taymans@gmail.com>");
|
2015-05-11 18:23:24 +02:00
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
2015-06-30 18:06:36 +02:00
|
|
|
gst_static_pad_template_get (&gst_pinos_sink_template));
|
2015-05-11 18:23:24 +02:00
|
|
|
|
2015-06-30 18:06:36 +02:00
|
|
|
gstbasesink_class->get_caps = gst_pinos_sink_getcaps;
|
|
|
|
|
gstbasesink_class->set_caps = gst_pinos_sink_setcaps;
|
|
|
|
|
gstbasesink_class->fixate = gst_pinos_sink_sink_fixate;
|
|
|
|
|
gstbasesink_class->start = gst_pinos_sink_start;
|
|
|
|
|
gstbasesink_class->stop = gst_pinos_sink_stop;
|
|
|
|
|
gstbasesink_class->render = gst_pinos_sink_render;
|
2015-05-11 18:23:24 +02:00
|
|
|
|
2015-06-30 18:06:36 +02:00
|
|
|
GST_DEBUG_CATEGORY_INIT (pinos_sink_debug, "pinossink", 0,
|
|
|
|
|
"Pinos Sink");
|
2015-05-11 18:23:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-06-30 18:06:36 +02:00
|
|
|
gst_pinos_sink_init (GstPinosSink * sink)
|
2015-05-11 18:23:24 +02:00
|
|
|
{
|
|
|
|
|
sink->allocator = gst_tmpfile_allocator_new ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GstCaps *
|
2015-06-30 18:06:36 +02:00
|
|
|
gst_pinos_sink_sink_fixate (GstBaseSink * bsink, GstCaps * caps)
|
2015-05-11 18:23:24 +02:00
|
|
|
{
|
|
|
|
|
GstStructure *structure;
|
|
|
|
|
|
|
|
|
|
caps = gst_caps_make_writable (caps);
|
|
|
|
|
|
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
|
|
2015-06-30 18:14:36 +02:00
|
|
|
if (gst_structure_has_name (structure, "video/x-raw")) {
|
|
|
|
|
gst_structure_fixate_field_nearest_int (structure, "width", 320);
|
|
|
|
|
gst_structure_fixate_field_nearest_int (structure, "height", 240);
|
|
|
|
|
gst_structure_fixate_field_nearest_fraction (structure, "framerate", 30, 1);
|
|
|
|
|
|
|
|
|
|
if (gst_structure_has_field (structure, "pixel-aspect-ratio"))
|
|
|
|
|
gst_structure_fixate_field_nearest_fraction (structure,
|
|
|
|
|
"pixel-aspect-ratio", 1, 1);
|
|
|
|
|
else
|
|
|
|
|
gst_structure_set (structure, "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
if (gst_structure_has_field (structure, "colorimetry"))
|
|
|
|
|
gst_structure_fixate_field_string (structure, "colorimetry", "bt601");
|
|
|
|
|
if (gst_structure_has_field (structure, "chroma-site"))
|
|
|
|
|
gst_structure_fixate_field_string (structure, "chroma-site", "mpeg2");
|
|
|
|
|
|
|
|
|
|
if (gst_structure_has_field (structure, "interlace-mode"))
|
|
|
|
|
gst_structure_fixate_field_string (structure, "interlace-mode",
|
|
|
|
|
"progressive");
|
|
|
|
|
else
|
|
|
|
|
gst_structure_set (structure, "interlace-mode", G_TYPE_STRING,
|
|
|
|
|
"progressive", NULL);
|
|
|
|
|
} else if (gst_structure_has_name (structure, "audio/x-raw")) {
|
|
|
|
|
gst_structure_fixate_field_string (structure, "format", "S16LE");
|
|
|
|
|
gst_structure_fixate_field_nearest_int (structure, "channels", 2);
|
|
|
|
|
gst_structure_fixate_field_nearest_int (structure, "rate", 44100);
|
|
|
|
|
}
|
2015-05-11 18:23:24 +02:00
|
|
|
|
|
|
|
|
caps = GST_BASE_SINK_CLASS (parent_class)->fixate (bsink, caps);
|
|
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-06-30 18:06:36 +02:00
|
|
|
gst_pinos_sink_set_property (GObject * object, guint prop_id,
|
2015-05-11 18:23:24 +02:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
|
{
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-06-30 18:06:36 +02:00
|
|
|
gst_pinos_sink_get_property (GObject * object, guint prop_id,
|
2015-05-11 18:23:24 +02:00
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
|
{
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
on_new_buffer (GObject *gobject,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
GstPinosSink *pinossink = user_data;
|
2015-05-11 18:23:24 +02:00
|
|
|
|
2015-07-08 12:11:55 +02:00
|
|
|
pinos_main_loop_signal (pinossink->loop, FALSE);
|
2015-05-11 18:23:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
on_stream_notify (GObject *gobject,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStreamState state;
|
2015-07-08 12:11:55 +02:00
|
|
|
PinosStream *stream = PINOS_STREAM (gobject);
|
2015-07-07 16:46:23 +02:00
|
|
|
GstPinosSink *pinossink = user_data;
|
2015-05-11 18:23:24 +02:00
|
|
|
|
2015-07-08 12:11:55 +02:00
|
|
|
state = pinos_stream_get_state (stream);
|
|
|
|
|
GST_DEBUG ("got stream state %d\n", state);
|
2015-06-12 12:10:27 +02:00
|
|
|
|
2015-07-08 12:11:55 +02:00
|
|
|
switch (state) {
|
|
|
|
|
case PINOS_STREAM_STATE_UNCONNECTED:
|
|
|
|
|
case PINOS_STREAM_STATE_CONNECTING:
|
|
|
|
|
case PINOS_STREAM_STATE_STARTING:
|
|
|
|
|
case PINOS_STREAM_STATE_STREAMING:
|
|
|
|
|
case PINOS_STREAM_STATE_READY:
|
|
|
|
|
break;
|
|
|
|
|
case PINOS_STREAM_STATE_ERROR:
|
|
|
|
|
GST_ELEMENT_ERROR (pinossink, RESOURCE, FAILED,
|
|
|
|
|
("stream error: %s",
|
|
|
|
|
pinos_stream_get_error (stream)->message), (NULL));
|
|
|
|
|
break;
|
2015-05-11 18:23:24 +02:00
|
|
|
}
|
2015-07-08 12:11:55 +02:00
|
|
|
pinos_main_loop_signal (pinossink->loop, FALSE);
|
2015-05-11 18:23:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GstCaps *
|
2015-06-30 18:06:36 +02:00
|
|
|
gst_pinos_sink_getcaps (GstBaseSink * bsink, GstCaps * filter)
|
2015-05-11 18:23:24 +02:00
|
|
|
{
|
|
|
|
|
return GST_BASE_SINK_CLASS (parent_class)->get_caps (bsink, filter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2015-06-30 18:06:36 +02:00
|
|
|
gst_pinos_sink_setcaps (GstBaseSink * bsink, GstCaps * caps)
|
2015-05-11 18:23:24 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
GstPinosSink *pinossink;
|
2015-05-14 17:46:12 +02:00
|
|
|
gchar *str;
|
|
|
|
|
GBytes *format;
|
2015-05-11 18:23:24 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
pinossink = GST_PINOS_SINK (bsink);
|
2015-05-11 18:23:24 +02:00
|
|
|
|
2015-06-12 12:10:27 +02:00
|
|
|
str = gst_caps_to_string (caps);
|
|
|
|
|
format = g_bytes_new_take (str, strlen (str) + 1);
|
|
|
|
|
|
2015-07-08 12:11:55 +02:00
|
|
|
pinos_main_loop_lock (pinossink->loop);
|
2015-07-07 16:46:23 +02:00
|
|
|
pinossink->stream = pinos_stream_new (pinossink->ctx, "test", NULL);
|
|
|
|
|
g_signal_connect (pinossink->stream, "notify::state", (GCallback) on_stream_notify, pinossink);
|
|
|
|
|
g_signal_connect (pinossink->stream, "new-buffer", (GCallback) on_new_buffer, pinossink);
|
2015-05-11 18:23:24 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
pinos_stream_connect_provide (pinossink->stream, 0, format);
|
2015-05-11 18:23:24 +02:00
|
|
|
|
|
|
|
|
while (TRUE) {
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStreamState state = pinos_stream_get_state (pinossink->stream);
|
2015-05-11 18:23:24 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
if (state == PINOS_STREAM_STATE_READY)
|
2015-05-11 18:23:24 +02:00
|
|
|
break;
|
|
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
if (state == PINOS_STREAM_STATE_ERROR)
|
2015-05-11 18:23:24 +02:00
|
|
|
goto connect_error;
|
|
|
|
|
|
2015-07-08 12:11:55 +02:00
|
|
|
pinos_main_loop_wait (pinossink->loop);
|
2015-05-11 18:23:24 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
pinos_stream_start (pinossink->stream, format, PINOS_STREAM_MODE_BUFFER);
|
2015-05-15 15:58:13 +02:00
|
|
|
|
|
|
|
|
while (TRUE) {
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStreamState state = pinos_stream_get_state (pinossink->stream);
|
2015-05-15 15:58:13 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
if (state == PINOS_STREAM_STATE_STREAMING)
|
2015-05-15 15:58:13 +02:00
|
|
|
break;
|
|
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
if (state == PINOS_STREAM_STATE_ERROR)
|
2015-05-15 15:58:13 +02:00
|
|
|
goto connect_error;
|
|
|
|
|
|
2015-07-08 12:11:55 +02:00
|
|
|
pinos_main_loop_wait (pinossink->loop);
|
2015-05-15 15:58:13 +02:00
|
|
|
}
|
2015-07-08 12:11:55 +02:00
|
|
|
pinos_main_loop_unlock (pinossink->loop);
|
2015-05-15 15:58:13 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
pinossink->negotiated = TRUE;
|
2015-05-11 18:23:24 +02:00
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
connect_error:
|
|
|
|
|
{
|
2015-07-08 12:11:55 +02:00
|
|
|
pinos_main_loop_unlock (pinossink->loop);
|
2015-05-11 18:23:24 +02:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2015-06-30 18:06:36 +02:00
|
|
|
gst_pinos_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
|
2015-05-11 18:23:24 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
GstPinosSink *pinossink;
|
|
|
|
|
PinosBufferInfo info;
|
2015-05-11 18:23:24 +02:00
|
|
|
GSocketControlMessage *mesg;
|
|
|
|
|
GstMemory *mem = NULL;
|
2015-07-14 15:46:25 +02:00
|
|
|
GstClockTime pts, dts, base;
|
2015-05-11 18:23:24 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
pinossink = GST_PINOS_SINK (bsink);
|
2015-05-11 18:23:24 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
if (!pinossink->negotiated)
|
2015-05-11 18:23:24 +02:00
|
|
|
goto not_negotiated;
|
|
|
|
|
|
2015-07-14 15:46:25 +02:00
|
|
|
base = GST_ELEMENT_CAST (bsink)->base_time;
|
|
|
|
|
|
|
|
|
|
pts = GST_BUFFER_PTS (buffer);
|
|
|
|
|
dts = GST_BUFFER_DTS (buffer);
|
|
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (pts))
|
|
|
|
|
pts = dts;
|
|
|
|
|
else if (!GST_CLOCK_TIME_IS_VALID (dts))
|
|
|
|
|
dts = pts;
|
|
|
|
|
|
2015-05-11 18:23:24 +02:00
|
|
|
info.flags = 0;
|
2015-07-14 15:46:25 +02:00
|
|
|
info.seq = GST_BUFFER_OFFSET (buffer);
|
|
|
|
|
info.pts = GST_CLOCK_TIME_IS_VALID (pts) ? pts + base : base;
|
|
|
|
|
info.dts_offset = GST_CLOCK_TIME_IS_VALID (dts) && GST_CLOCK_TIME_IS_VALID (pts) ? pts - dts : 0;
|
2015-05-11 18:23:24 +02:00
|
|
|
info.offset = 0;
|
|
|
|
|
info.size = gst_buffer_get_size (buffer);
|
|
|
|
|
|
|
|
|
|
mesg = g_unix_fd_message_new ();
|
|
|
|
|
if (gst_buffer_n_memory (buffer) == 1
|
|
|
|
|
&& gst_is_fd_memory (gst_buffer_peek_memory (buffer, 0))) {
|
|
|
|
|
mem = gst_buffer_get_memory (buffer, 0);
|
|
|
|
|
} else {
|
|
|
|
|
GstMapInfo minfo;
|
|
|
|
|
GstAllocationParams params = {0, 0, 0, 0, { NULL, }};
|
|
|
|
|
|
|
|
|
|
GST_INFO_OBJECT (bsink, "Buffer cannot be payloaded without copying");
|
|
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
mem = gst_allocator_alloc (pinossink->allocator, info.size, ¶ms);
|
2015-05-11 18:23:24 +02:00
|
|
|
if (!gst_memory_map (mem, &minfo, GST_MAP_WRITE))
|
2015-06-12 12:10:27 +02:00
|
|
|
goto map_error;
|
2015-05-11 18:23:24 +02:00
|
|
|
gst_buffer_extract (buffer, 0, minfo.data, info.size);
|
|
|
|
|
gst_memory_unmap (mem, &minfo);
|
|
|
|
|
}
|
|
|
|
|
g_unix_fd_message_append_fd ((GUnixFDMessage*)mesg, gst_fd_memory_get_fd (mem), NULL);
|
2015-05-18 16:58:16 +02:00
|
|
|
gst_memory_unref (mem);
|
2015-05-11 18:23:24 +02:00
|
|
|
info.message = mesg;
|
|
|
|
|
|
2015-07-08 12:11:55 +02:00
|
|
|
pinos_main_loop_lock (pinossink->loop);
|
2015-07-07 16:46:23 +02:00
|
|
|
if (pinos_stream_get_state (pinossink->stream) != PINOS_STREAM_STATE_STREAMING)
|
2015-06-12 12:10:27 +02:00
|
|
|
goto streaming_error;
|
2015-07-07 16:46:23 +02:00
|
|
|
pinos_stream_provide_buffer (pinossink->stream, &info);
|
2015-07-08 12:11:55 +02:00
|
|
|
pinos_main_loop_unlock (pinossink->loop);
|
2015-05-11 18:23:24 +02:00
|
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
|
|
|
|
|
not_negotiated:
|
|
|
|
|
{
|
|
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
|
}
|
2015-06-12 12:10:27 +02:00
|
|
|
map_error:
|
2015-05-11 18:23:24 +02:00
|
|
|
{
|
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
|
}
|
2015-06-12 12:10:27 +02:00
|
|
|
streaming_error:
|
|
|
|
|
{
|
2015-07-08 12:11:55 +02:00
|
|
|
pinos_main_loop_unlock (pinossink->loop);
|
2015-06-12 12:10:27 +02:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
|
}
|
2015-05-11 18:23:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2015-06-30 18:06:36 +02:00
|
|
|
gst_pinos_sink_start (GstBaseSink * basesink)
|
2015-05-11 18:23:24 +02:00
|
|
|
{
|
2015-06-30 18:06:36 +02:00
|
|
|
GstPinosSink *sink = GST_PINOS_SINK (basesink);
|
2015-05-11 18:23:24 +02:00
|
|
|
|
2015-05-14 17:46:12 +02:00
|
|
|
sink->negotiated = FALSE;
|
2015-05-11 18:23:24 +02:00
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2015-06-30 18:06:36 +02:00
|
|
|
gst_pinos_sink_stop (GstBaseSink * basesink)
|
2015-05-11 18:23:24 +02:00
|
|
|
{
|
2015-06-30 18:06:36 +02:00
|
|
|
GstPinosSink *sink = GST_PINOS_SINK (basesink);
|
2015-05-14 17:46:12 +02:00
|
|
|
|
|
|
|
|
sink->negotiated = FALSE;
|
|
|
|
|
|
2015-05-11 18:23:24 +02:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-08 12:11:55 +02:00
|
|
|
on_context_notify (GObject *gobject,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
gpointer user_data)
|
2015-05-11 18:23:24 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
GstPinosSink *pinossink = user_data;
|
2015-07-08 12:11:55 +02:00
|
|
|
PinosContext *ctx = PINOS_CONTEXT (gobject);
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosContextState state;
|
2015-05-11 18:23:24 +02:00
|
|
|
|
2015-07-08 12:11:55 +02:00
|
|
|
state = pinos_context_get_state (ctx);
|
|
|
|
|
GST_DEBUG ("got context state %d\n", state);
|
2015-05-11 18:23:24 +02:00
|
|
|
|
2015-07-08 12:11:55 +02:00
|
|
|
switch (state) {
|
|
|
|
|
case PINOS_CONTEXT_STATE_UNCONNECTED:
|
|
|
|
|
case PINOS_CONTEXT_STATE_CONNECTING:
|
|
|
|
|
case PINOS_CONTEXT_STATE_REGISTERING:
|
|
|
|
|
case PINOS_CONTEXT_STATE_READY:
|
|
|
|
|
break;
|
|
|
|
|
case PINOS_CONTEXT_STATE_ERROR:
|
|
|
|
|
GST_ELEMENT_ERROR (pinossink, RESOURCE, FAILED,
|
|
|
|
|
("context error: %s",
|
|
|
|
|
pinos_context_get_error (pinossink->ctx)->message), (NULL));
|
|
|
|
|
break;
|
2015-05-11 18:23:24 +02:00
|
|
|
}
|
2015-07-08 12:11:55 +02:00
|
|
|
pinos_main_loop_signal (pinossink->loop, FALSE);
|
2015-05-11 18:23:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2015-07-07 16:46:23 +02:00
|
|
|
gst_pinos_sink_open (GstPinosSink * pinossink)
|
2015-05-11 18:23:24 +02:00
|
|
|
{
|
2015-07-08 12:11:55 +02:00
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
|
|
pinossink->context = g_main_context_new ();
|
|
|
|
|
GST_DEBUG ("context %p\n", pinossink->context);
|
|
|
|
|
|
|
|
|
|
pinossink->loop = pinos_main_loop_new (pinossink->context, "pinos-sink-loop");
|
|
|
|
|
if (!pinos_main_loop_start (pinossink->loop, &error))
|
|
|
|
|
goto mainloop_error;
|
|
|
|
|
|
|
|
|
|
pinos_main_loop_lock (pinossink->loop);
|
2015-07-07 16:46:23 +02:00
|
|
|
pinossink->ctx = pinos_context_new (pinossink->context, "test-client", NULL);
|
2015-07-08 12:11:55 +02:00
|
|
|
g_signal_connect (pinossink->ctx, "notify::state", (GCallback) on_context_notify, pinossink);
|
2015-05-11 18:23:24 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
pinos_context_connect(pinossink->ctx, PINOS_CONTEXT_FLAGS_NONE);
|
2015-05-11 18:23:24 +02:00
|
|
|
|
|
|
|
|
while (TRUE) {
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosContextState state = pinos_context_get_state (pinossink->ctx);
|
2015-05-11 18:23:24 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
if (state == PINOS_CONTEXT_STATE_READY)
|
2015-05-11 18:23:24 +02:00
|
|
|
break;
|
|
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
if (state == PINOS_CONTEXT_STATE_ERROR)
|
2015-05-11 18:23:24 +02:00
|
|
|
goto connect_error;
|
|
|
|
|
|
2015-07-08 12:11:55 +02:00
|
|
|
pinos_main_loop_wait (pinossink->loop);
|
2015-05-11 18:23:24 +02:00
|
|
|
}
|
2015-07-08 12:11:55 +02:00
|
|
|
pinos_main_loop_unlock (pinossink->loop);
|
2015-05-11 18:23:24 +02:00
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
/* ERRORS */
|
2015-07-08 12:11:55 +02:00
|
|
|
mainloop_error:
|
|
|
|
|
{
|
|
|
|
|
GST_ELEMENT_ERROR (pinossink, RESOURCE, FAILED,
|
|
|
|
|
("Failed to start mainloop: %s", error->message), (NULL));
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2015-05-11 18:23:24 +02:00
|
|
|
connect_error:
|
|
|
|
|
{
|
2015-07-08 12:11:55 +02:00
|
|
|
pinos_main_loop_unlock (pinossink->loop);
|
2015-05-11 18:23:24 +02:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-27 18:16:52 +02:00
|
|
|
static gboolean
|
2015-07-07 16:46:23 +02:00
|
|
|
gst_pinos_sink_close (GstPinosSink * pinossink)
|
2015-05-27 18:16:52 +02:00
|
|
|
{
|
2015-07-08 12:11:55 +02:00
|
|
|
pinos_main_loop_lock (pinossink->loop);
|
2015-07-07 16:46:23 +02:00
|
|
|
if (pinossink->stream) {
|
|
|
|
|
pinos_stream_disconnect (pinossink->stream);
|
2015-05-27 18:16:52 +02:00
|
|
|
}
|
2015-07-07 16:46:23 +02:00
|
|
|
if (pinossink->ctx) {
|
2015-07-08 12:11:55 +02:00
|
|
|
pinos_context_disconnect (pinossink->ctx);
|
2015-05-27 18:16:52 +02:00
|
|
|
|
|
|
|
|
while (TRUE) {
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosContextState state = pinos_context_get_state (pinossink->ctx);
|
2015-05-27 18:16:52 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
if (state == PINOS_CONTEXT_STATE_UNCONNECTED)
|
2015-05-27 18:16:52 +02:00
|
|
|
break;
|
|
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
if (state == PINOS_CONTEXT_STATE_ERROR)
|
2015-05-27 18:16:52 +02:00
|
|
|
break;
|
|
|
|
|
|
2015-07-08 12:11:55 +02:00
|
|
|
pinos_main_loop_wait (pinossink->loop);
|
2015-05-27 18:16:52 +02:00
|
|
|
}
|
|
|
|
|
}
|
2015-07-08 12:11:55 +02:00
|
|
|
pinos_main_loop_unlock (pinossink->loop);
|
|
|
|
|
|
|
|
|
|
pinos_main_loop_stop (pinossink->loop);
|
|
|
|
|
g_clear_object (&pinossink->loop);
|
|
|
|
|
g_clear_object (&pinossink->stream);
|
|
|
|
|
g_clear_object (&pinossink->ctx);
|
|
|
|
|
g_main_context_unref (pinossink->context);
|
2015-05-27 18:16:52 +02:00
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-11 18:23:24 +02:00
|
|
|
static GstStateChangeReturn
|
2015-06-30 18:06:36 +02:00
|
|
|
gst_pinos_sink_change_state (GstElement * element, GstStateChange transition)
|
2015-05-11 18:23:24 +02:00
|
|
|
{
|
|
|
|
|
GstStateChangeReturn ret;
|
2015-06-30 18:06:36 +02:00
|
|
|
GstPinosSink *this = GST_PINOS_SINK_CAST (element);
|
2015-05-11 18:23:24 +02:00
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
2015-07-08 12:11:55 +02:00
|
|
|
if (!gst_pinos_sink_open (this))
|
|
|
|
|
goto open_failed;
|
2015-05-11 18:23:24 +02:00
|
|
|
break;
|
2015-06-05 18:21:18 +02:00
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
|
|
|
|
break;
|
2015-05-11 18:23:24 +02:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
|
|
|
|
/* uncork and start recording */
|
|
|
|
|
break;
|
|
|
|
|
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
|
|
|
|
|
/* stop recording ASAP by corking */
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
|
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
|
|
|
|
|
break;
|
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
|
|
|
break;
|
|
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
2015-06-30 18:06:36 +02:00
|
|
|
gst_pinos_sink_close (this);
|
2015-05-11 18:23:24 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
2015-07-08 12:11:55 +02:00
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
|
open_failed:
|
|
|
|
|
{
|
|
|
|
|
return GST_STATE_CHANGE_FAILURE;
|
|
|
|
|
}
|
2015-05-11 18:23:24 +02:00
|
|
|
}
|