• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "gstipcpipelineelements.h"
46 #include "gstipcpipelinesrc.h"
47 #include "gstipcslavepipeline.h"
48 
49 GST_DEBUG_CATEGORY_STATIC (gst_ipcslavepipeline_debug);
50 #define GST_CAT_DEFAULT gst_ipcslavepipeline_debug
51 
52 #define _do_init \
53     GST_DEBUG_CATEGORY_INIT (gst_ipcslavepipeline_debug, "ipcslavepipeline", 0, "ipcslavepipeline element");
54 #define gst_ipc_slave_pipeline_parent_class parent_class
55 G_DEFINE_TYPE_WITH_CODE (GstIpcSlavePipeline, gst_ipc_slave_pipeline,
56     GST_TYPE_PIPELINE, _do_init);
57 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (ipcslavepipeline, "ipcslavepipeline",
58     GST_RANK_NONE, GST_TYPE_IPC_SLAVE_PIPELINE,
59     icepipeline_element_init (plugin));
60 
61 static gboolean gst_ipc_slave_pipeline_post_message (GstElement * element,
62     GstMessage * message);
63 
64 static void
gst_ipc_slave_pipeline_class_init(GstIpcSlavePipelineClass * klass)65 gst_ipc_slave_pipeline_class_init (GstIpcSlavePipelineClass * klass)
66 {
67   GstElementClass *element_class;
68 
69   element_class = GST_ELEMENT_CLASS (klass);
70 
71   element_class->post_message = gst_ipc_slave_pipeline_post_message;
72 
73   gst_element_class_set_static_metadata (element_class,
74       "Inter-process slave pipeline",
75       "Generic/Bin/Slave",
76       "Contains the slave part of an inter-process pipeline",
77       "Vincent Penquerc'h <vincent.penquerch@collabora.co.uk");
78 }
79 
80 static void
gst_ipc_slave_pipeline_init(GstIpcSlavePipeline * isp)81 gst_ipc_slave_pipeline_init (GstIpcSlavePipeline * isp)
82 {
83 }
84 
85 static gboolean
send_message_if_ipcpipelinesrc(const GValue * v,GValue * r,gpointer user_data)86 send_message_if_ipcpipelinesrc (const GValue * v, GValue * r,
87     gpointer user_data)
88 {
89   GstElement *e;
90   GType et;
91   gboolean ret;
92   GstMessage *message = user_data;
93 
94   e = g_value_get_object (v);
95   et = gst_element_factory_get_element_type (gst_element_get_factory (e));
96   if (et == GST_TYPE_IPC_PIPELINE_SRC) {
97     g_signal_emit_by_name (G_OBJECT (e), "forward-message", message, &ret);
98 
99     /* if we successfully sent this to the master and it's not ASYNC_DONE or EOS,
100      * we can skip sending it again through the other ipcpipelinesrcs */
101     if (ret && GST_MESSAGE_TYPE (message) != GST_MESSAGE_ASYNC_DONE &&
102         GST_MESSAGE_TYPE (message) != GST_MESSAGE_EOS)
103       return FALSE;
104   }
105   return TRUE;
106 }
107 
108 static void
gst_ipc_slave_pipeline_forward_message(GstIpcSlavePipeline * pipeline,GstMessage * message)109 gst_ipc_slave_pipeline_forward_message (GstIpcSlavePipeline * pipeline,
110     GstMessage * message)
111 {
112   GstIterator *it;
113 
114   it = gst_bin_iterate_sources (GST_BIN (pipeline));
115   gst_iterator_fold (it, send_message_if_ipcpipelinesrc, NULL, message);
116   gst_iterator_free (it);
117 }
118 
119 static gboolean
gst_ipc_slave_pipeline_post_message(GstElement * element,GstMessage * message)120 gst_ipc_slave_pipeline_post_message (GstElement * element, GstMessage * message)
121 {
122   gst_ipc_slave_pipeline_forward_message (GST_IPC_SLAVE_PIPELINE
123       (element), message);
124 
125   return GST_ELEMENT_CLASS (parent_class)->post_message (element, message);
126 }
127