QtGStreamer  0.10.2
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
bin.cpp
1 /*
2  Copyright (C) 2009-2010 George Kiagiadakis <kiagiadakis.george@gmail.com>
3 
4  This library is free software; you can redistribute it and/or modify
5  it under the terms of the GNU Lesser General Public License as published
6  by the Free Software Foundation; either version 2.1 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 #include "bin.h"
18 #include "pad.h"
19 #include "../QGlib/error.h"
20 #include <gst/gstbin.h>
21 #include <gst/gstutils.h>
22 
23 namespace QGst {
24 
25 //static
26 BinPtr Bin::create(const char *name)
27 {
28  GstElement *bin = gst_bin_new(name);
29  if (bin) {
30  gst_object_ref_sink(bin);
31  }
32  return BinPtr::wrap(GST_BIN(bin), false);
33 }
34 
35 //static
36 BinPtr Bin::fromDescription(const char *description, BinFromDescriptionOption ghostUnlinkedPads)
37 {
38  GError *error = NULL;
39  GstElement *e = gst_parse_bin_from_description_full(description, ghostUnlinkedPads,
40  NULL, GST_PARSE_FLAG_FATAL_ERRORS, &error);
41  if (error) {
42  throw QGlib::Error(error);
43  }
44  if (e) {
45  gst_object_ref_sink(e);
46  }
47  return BinPtr::wrap(GST_BIN(e), false);
48 }
49 
50 bool Bin::add(const ElementPtr & element)
51 {
52  return gst_bin_add(object<GstBin>(), element);
53 }
54 
55 bool Bin::remove(const ElementPtr & element)
56 {
57  return gst_bin_remove(object<GstBin>(), element);
58 }
59 
61 {
62  GstElement *e = NULL;
63  switch(r) {
64  case RecurseDown:
65  e = gst_bin_get_by_name(object<GstBin>(), name);
66  break;
67  case RecurseUp:
68  e = gst_bin_get_by_name_recurse_up(object<GstBin>(), name);
69  break;
70  default:
71  Q_ASSERT_X(false, "QGst::Bin::getElementByName", "Invalid RecursionType");
72  }
73  return ElementPtr::wrap(e, false);
74 }
75 
77 {
78  return ElementPtr::wrap(gst_bin_get_by_interface(object<GstBin>(), interfaceType), false);
79 }
80 
81 PadPtr Bin::findUnlinkedPad(PadDirection direction) const
82 {
83  return PadPtr::wrap(gst_bin_find_unlinked_pad(object<GstBin>(),
84  static_cast<GstPadDirection>(direction)), false);
85 }
86 
87 bool Bin::recalculateLatency()
88 {
89  return gst_bin_recalculate_latency(object<GstBin>());
90 }
91 
92 }