documentation: fixed a heap o' typos
[platform/upstream/gstreamer.git] / sys / ipcpipeline / gstipcslavepipeline.c
1 /* GStreamer
2  * Copyright (C) 2015-2017 YouView TV Ltd
3  *   Author: Vincent Penquerc'h <vincent.penquerch@collabora.co.uk>
4  *
5  * gstipcslavepipeline.c:
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22 /**
23  * SECTION:element-ipcslavepipeline
24  * @see_also: #GstIpcPipelineSink, #GstIpcPipelineSrc
25  *
26  * This is a GstPipeline subclass meant to embed one ore more ipcpipelinesrc
27  * elements, and be slaved transparently to the master pipeline, using one ore
28  * more ipcpipelinesink elements on the master.
29  *
30  * The actual pipeline slaving logic happens in ipcpipelinesrc. The only thing
31  * that this class actually does is that it watches the pipeline bus for
32  * messages and forwards them to the master pipeline through the ipcpipelinesrc
33  * elements that it contains.
34  *
35  * For more details about this mechanism and its uses, see the documentation
36  * of the ipcpipelinesink element.
37  */
38
39 #ifdef HAVE_CONFIG_H
40 #include "config.h"
41 #endif
42
43 #include <string.h>
44
45 #include "gstipcpipelinesrc.h"
46 #include "gstipcslavepipeline.h"
47
48 GST_DEBUG_CATEGORY_STATIC (gst_ipcslavepipeline_debug);
49 #define GST_CAT_DEFAULT gst_ipcslavepipeline_debug
50
51 #define _do_init \
52     GST_DEBUG_CATEGORY_INIT (gst_ipcslavepipeline_debug, "ipcslavepipeline", 0, "ipcslavepipeline element");
53 #define gst_ipc_slave_pipeline_parent_class parent_class
54 G_DEFINE_TYPE_WITH_CODE (GstIpcSlavePipeline, gst_ipc_slave_pipeline,
55     GST_TYPE_PIPELINE, _do_init);
56
57 static gboolean gst_ipc_slave_pipeline_post_message (GstElement * element,
58     GstMessage * message);
59
60 static void
61 gst_ipc_slave_pipeline_class_init (GstIpcSlavePipelineClass * klass)
62 {
63   GstElementClass *element_class;
64
65   element_class = GST_ELEMENT_CLASS (klass);
66
67   element_class->post_message = gst_ipc_slave_pipeline_post_message;
68
69   gst_element_class_set_static_metadata (element_class,
70       "Inter-process slave pipeline",
71       "Generic/Bin/Slave",
72       "Contains the slave part of an inter-process pipeline",
73       "Vincent Penquerc'h <vincent.penquerch@collabora.co.uk");
74 }
75
76 static void
77 gst_ipc_slave_pipeline_init (GstIpcSlavePipeline * isp)
78 {
79 }
80
81 static gboolean
82 send_message_if_ipcpipelinesrc (const GValue * v, GValue * r,
83     gpointer user_data)
84 {
85   GstElement *e;
86   GType et;
87   gboolean ret;
88   GstMessage *message = user_data;
89
90   e = g_value_get_object (v);
91   et = gst_element_factory_get_element_type (gst_element_get_factory (e));
92   if (et == GST_TYPE_IPC_PIPELINE_SRC) {
93     g_signal_emit_by_name (G_OBJECT (e), "forward-message", message, &ret);
94
95     /* if we successfully sent this to the master and it's not ASYNC_DONE or EOS,
96      * we can skip sending it again through the other ipcpipelinesrcs */
97     if (ret && GST_MESSAGE_TYPE (message) != GST_MESSAGE_ASYNC_DONE &&
98         GST_MESSAGE_TYPE (message) != GST_MESSAGE_EOS)
99       return FALSE;
100   }
101   return TRUE;
102 }
103
104 static void
105 gst_ipc_slave_pipeline_forward_message (GstIpcSlavePipeline * pipeline,
106     GstMessage * message)
107 {
108   GstIterator *it;
109
110   it = gst_bin_iterate_sources (GST_BIN (pipeline));
111   gst_iterator_fold (it, send_message_if_ipcpipelinesrc, NULL, message);
112   gst_iterator_free (it);
113 }
114
115 static gboolean
116 gst_ipc_slave_pipeline_post_message (GstElement * element, GstMessage * message)
117 {
118   gst_ipc_slave_pipeline_forward_message (GST_IPC_SLAVE_PIPELINE
119       (element), message);
120
121   return GST_ELEMENT_CLASS (parent_class)->post_message (element, message);
122 }