Add provide mode to pinossink

Add a mode to provide a stream to pinossink
Small improvements, leak fixes.
This commit is contained in:
Wim Taymans 2016-05-06 17:54:23 +02:00
parent ba4ef9b5d9
commit 20c50772fa
20 changed files with 309 additions and 212 deletions

View file

@ -18,12 +18,12 @@
*/
/**
* SECTION:element-pinossink
* SECTION:element-pinosprovide
*
* <refsect2>
* <title>Example launch line</title>
* |[
* gst-launch -v videotestsrc ! pinossink
* gst-launch -v videotestsrc ! pinosprovide
* ]| Sends a test video source to pinos
* </refsect2>
*/
@ -31,7 +31,7 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstpinossink.h"
#include "gstpinosprovide.h"
#include <string.h>
#include <stdlib.h>

View file

@ -17,8 +17,8 @@
* Boston, MA 02110-1301, USA.
*/
#ifndef __GST_PINOS_SINK_H__
#define __GST_PINOS_SINK_H__
#ifndef __GST_PINOS_PROVIDE_H__
#define __GST_PINOS_PROVIDE_H__
#include <gst/gst.h>
#include <gst/base/gstbasesink.h>
@ -27,28 +27,28 @@
G_BEGIN_DECLS
#define GST_TYPE_PINOS_SINK \
(gst_pinos_sink_get_type())
#define GST_PINOS_SINK(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PINOS_SINK,GstPinosSink))
#define GST_PINOS_SINK_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PINOS_SINK,GstPinosSinkClass))
#define GST_IS_PINOS_SINK(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PINOS_SINK))
#define GST_IS_PINOS_SINK_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PINOS_SINK))
#define GST_PINOS_SINK_CAST(obj) \
((GstPinosSink *) (obj))
#define GST_TYPE_PINOS_PROVIDE \
(gst_pinos_provide_get_type())
#define GST_PINOS_PROVIDE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PINOS_PROVIDE,GstPinosProvide))
#define GST_PINOS_PROVIDE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PINOS_PROVIDE,GstPinosProvideClass))
#define GST_IS_PINOS_PROVIDE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PINOS_PROVIDE))
#define GST_IS_PINOS_PROVIDE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PINOS_PROVIDE))
#define GST_PINOS_PROVIDE_CAST(obj) \
((GstPinosProvide *) (obj))
typedef struct _GstPinosSink GstPinosSink;
typedef struct _GstPinosSinkClass GstPinosSinkClass;
typedef struct _GstPinosProvide GstPinosProvide;
typedef struct _GstPinosProvideClass GstPinosProvideClass;
/**
* GstPinosSink:
* GstPinosProvide:
*
* Opaque data structure.
*/
struct _GstPinosSink {
struct _GstPinosProvide {
GstBaseSink element;
/*< private >*/
@ -68,12 +68,12 @@ struct _GstPinosSink {
GHashTable *fdids;
};
struct _GstPinosSinkClass {
struct _GstPinosProvideClass {
GstBaseSinkClass parent_class;
};
GType gst_pinos_sink_get_type (void);
GType gst_pinos_provide_get_type (void);
G_END_DECLS
#endif /* __GST_PINOS_SINK_H__ */
#endif /* __GST_PINOS_PROVIDE_H__ */

View file

@ -49,14 +49,37 @@
GST_DEBUG_CATEGORY_STATIC (pinos_sink_debug);
#define GST_CAT_DEFAULT pinos_sink_debug
#define DEFAULT_PROP_MODE GST_PINOS_SINK_MODE_DEFAULT
enum
{
PROP_0,
PROP_PATH,
PROP_CLIENT_NAME,
PROP_STREAM_PROPERTIES
PROP_STREAM_PROPERTIES,
PROP_MODE
};
GType
gst_pinos_sink_mode_get_type (void)
{
static volatile gsize mode_type = 0;
static const GEnumValue mode[] = {
{GST_PINOS_SINK_MODE_DEFAULT, "GST_PINOS_SINK_MODE_DEFAULT", "default"},
{GST_PINOS_SINK_MODE_RENDER, "GST_PINOS_SINK_MODE_RENDER", "render"},
{GST_PINOS_SINK_MODE_PROVIDE, "GST_PINOS_SINK_MODE_PROVIDE", "provide"},
{0, NULL, NULL},
};
if (g_once_init_enter (&mode_type)) {
GType tmp =
g_enum_register_static ("GstPinosSinkMode", mode);
g_once_init_leave (&mode_type, tmp);
}
return (GType) mode_type;
}
#define PINOSS_VIDEO_CAPS GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS_ALL)
@ -147,17 +170,27 @@ gst_pinos_sink_class_init (GstPinosSinkClass * klass)
g_object_class_install_property (gobject_class,
PROP_STREAM_PROPERTIES,
g_param_spec_boxed ("stream-properties",
"stream properties",
"list of pinos stream properties",
"Stream properties",
"List of pinos stream properties",
GST_TYPE_STRUCTURE,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_MODE,
g_param_spec_enum ("mode",
"Mode",
"The mode to operate in",
GST_TYPE_PINOS_SINK_MODE,
DEFAULT_PROP_MODE,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
gstelement_class->change_state = gst_pinos_sink_change_state;
gst_element_class_set_static_metadata (gstelement_class,
"Pinos sink", "Sink/Video",
"Send video to pinos", "Wim Taymans <wim.taymans@gmail.com>");
"Send video to Pinos", "Wim Taymans <wim.taymans@gmail.com>");
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_pinos_sink_template));
@ -178,6 +211,7 @@ gst_pinos_sink_init (GstPinosSink * sink)
{
sink->allocator = gst_tmpfile_allocator_new ();
sink->client_name = pinos_client_name();
sink->mode = DEFAULT_PROP_MODE;
sink->fdids = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL,
(GDestroyNotify) gst_buffer_unref);
@ -250,6 +284,10 @@ gst_pinos_sink_set_property (GObject * object, guint prop_id,
gst_structure_copy (gst_value_get_structure (value));
break;
case PROP_MODE:
pinossink->mode = g_value_get_enum (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -275,6 +313,10 @@ gst_pinos_sink_get_property (GObject * object, guint prop_id,
gst_value_set_structure (value, pinossink->properties);
break;
case PROP_MODE:
g_value_set_enum (value, pinossink->mode);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -382,11 +424,17 @@ gst_pinos_sink_setcaps (GstBaseSink * bsink, GstCaps * caps)
goto start_error;
if (state == PINOS_STREAM_STATE_UNCONNECTED) {
pinos_stream_connect (pinossink->stream,
PINOS_DIRECTION_INPUT,
pinossink->path,
0,
g_bytes_ref (format));
if (pinossink->mode == GST_PINOS_SINK_MODE_PROVIDE) {
pinos_stream_connect_provide (pinossink->stream,
0,
g_bytes_ref (format));
} else {
pinos_stream_connect (pinossink->stream,
PINOS_DIRECTION_INPUT,
pinossink->path,
0,
g_bytes_ref (format));
}
while (TRUE) {
state = pinos_stream_get_state (pinossink->stream);

View file

@ -43,6 +43,24 @@ G_BEGIN_DECLS
typedef struct _GstPinosSink GstPinosSink;
typedef struct _GstPinosSinkClass GstPinosSinkClass;
/**
* GstPinosSinkMode:
* @GST_PINOS_SINK_MODE_DEFAULT: the default mode as configured in the server
* @GST_PINOS_SINK_MODE_RENDER: try to render the media
* @GST_PINOS_SINK_MODE_PROVIDE: provide the media
*
* Different modes of operation.
*/
typedef enum
{
GST_PINOS_SINK_MODE_DEFAULT,
GST_PINOS_SINK_MODE_RENDER,
GST_PINOS_SINK_MODE_PROVIDE,
} GstPinosSinkMode;
#define GST_TYPE_PINOS_SINK_MODE (gst_pinos_sink_mode_get_type ())
/**
* GstPinosSink:
*
@ -64,6 +82,7 @@ struct _GstPinosSink {
PinosStream *stream;
GstAllocator *allocator;
GstStructure *properties;
GstPinosSinkMode mode;
guint32 id_counter;
GHashTable *fdids;
@ -74,6 +93,7 @@ struct _GstPinosSinkClass {
};
GType gst_pinos_sink_get_type (void);
GType gst_pinos_sink_mode_get_type (void);
G_END_DECLS