Debian Codegraph @

gstreamer/src/bin.ccg

raw
1 /* gstreamermm - a C++ wrapper for gstreamer
2 *
3 * Copyright 2008-2016 The gstreamermm Development Team
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <gst/gst.h>
21 #include <gstreamermm/pad.h>
22 #include <gstreamermm/ghostpad.h>
23 #include <gstreamermm/iterator.h>
24 #include <gstreamermm/bus.h>
25 #include <gstreamermm/handle_error.h>
26
27 _PINCLUDE(glibmm/private/object_p.h)
28 _PINCLUDE(gstreamermm/private/element_p.h)
29
30 namespace Gst
31 {
32
33 Bin::Bin()
34 : _CONSTRUCT("name", nullptr)
35 {}
36
37 Glib::RefPtr<Gst::Bin> Bin::add(const Glib::RefPtr<Gst::Element>& element)
38 {
39 if(!element)
40 gstreamermm_handle_error("Failed to add null element.");
41
42 GstElement* celement = Glib::unwrap(element);
43
44 // The following is needed because when adding an element to a bin, the bin
45 // likes to have the last reference and then destroy it when the bin itself
46 // is destroyed. Without the extra reference, when the last Glib::RefPtr<>
47 // to the element goes out of scope, the element may be destroyed before the
48 // bin and GStreamer complains about it. The extra reference to the element
49 // is removed when the bin is destroyed or when the element is removed from
50 // the bin (see gst_bin_remove).
51 if(G_LIKELY(g_object_is_floating(celement)))
52 element->reference();
53
54 const bool result = gst_bin_add(gobj(), celement);
55
56 // If addition successful, return RefPtr<..> to this bin, otherwise throw an
57 // exception
58 if(!result)
59 gstreamermm_handle_error("Failed to add " + element->get_name() +
60 " element.");
61
62 return Glib::wrap(gobj(), true);
63 }
64
65 Glib::RefPtr<Gst::Bin> Bin::remove(const Glib::RefPtr<Gst::Element>& element)
66 {
67 if(!element)
68 gstreamermm_handle_error("Failed to remove null element.");
69
70
71 const bool result = gst_bin_remove(gobj(), Glib::unwrap(element));
72
73 // If removal successful, return RefPtr<..> to this bin, otherwise throw an
74 // exception
75 if(!result)
76 gstreamermm_handle_error("Failed to remove " + element->get_name() +
77 " element.");
78
79 return Glib::wrap(gobj(), true);
80 }
81
82 Glib::RefPtr<Gst::GhostPad> Bin::add_ghost_pad(const
83 Glib::RefPtr<Gst::Element>& element, const Glib::ustring& pad_name, const
84 Glib::ustring& name)
85 {
86 Glib::RefPtr<Gst::Pad> static_pad = element->get_static_pad(pad_name);
87 Glib::RefPtr<Gst::GhostPad> ghost_pad = Gst::GhostPad::create(static_pad,
88 name);
89 add_pad(ghost_pad);
90 return ghost_pad;
91 }
92
93 } //namespace Gst