QtGStreamer  1.2.0
 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/gst.h>
21 
22 namespace QGst {
23 
24 //static
25 BinPtr Bin::create(const char *name)
26 {
27  GstElement *bin = gst_bin_new(name);
28  if (bin) {
29  gst_object_ref_sink(bin);
30  }
31  return BinPtr::wrap(GST_BIN(bin), false);
32 }
33 
34 //static
35 BinPtr Bin::fromDescription(const char *description, BinFromDescriptionOption ghostUnlinkedPads)
36 {
37  GError *error = NULL;
38  GstElement *e = gst_parse_bin_from_description_full(description, ghostUnlinkedPads,
39  NULL, GST_PARSE_FLAG_FATAL_ERRORS, &error);
40  if (error) {
41  throw QGlib::Error(error);
42  }
43  if (e) {
44  gst_object_ref_sink(e);
45  }
46  return BinPtr::wrap(GST_BIN(e), false);
47 }
48 
49 bool Bin::add(const ElementPtr & element)
50 {
51  return gst_bin_add(object<GstBin>(), element);
52 }
53 
54 bool Bin::remove(const ElementPtr & element)
55 {
56  return gst_bin_remove(object<GstBin>(), element);
57 }
58 
60 {
61  GstElement *e = NULL;
62  switch(r) {
63  case RecurseDown:
64  e = gst_bin_get_by_name(object<GstBin>(), name);
65  break;
66  case RecurseUp:
67  e = gst_bin_get_by_name_recurse_up(object<GstBin>(), name);
68  break;
69  default:
70  Q_ASSERT_X(false, "QGst::Bin::getElementByName", "Invalid RecursionType");
71  }
72  return ElementPtr::wrap(e, false);
73 }
74 
76 {
77  return ElementPtr::wrap(gst_bin_get_by_interface(object<GstBin>(), interfaceType), false);
78 }
79 
80 PadPtr Bin::findUnlinkedPad(PadDirection direction) const
81 {
82  return PadPtr::wrap(gst_bin_find_unlinked_pad(object<GstBin>(),
83  static_cast<GstPadDirection>(direction)), false);
84 }
85 
86 bool Bin::recalculateLatency()
87 {
88  return gst_bin_recalculate_latency(object<GstBin>());
89 }
90 
91 }
static RefPointer< T > wrap(typename T::CType *nativePtr, bool increaseRef=true)
Definition: refpointer.h:326
Smart pointer class for working with wrapper classes that support reference counting.
Definition: global.h:56
BinFromDescriptionOption
Definition: bin.h:53
PadPtr findUnlinkedPad(PadDirection direction) const
Definition: bin.cpp:80
RecursionType
Definition: bin.h:132
static BinPtr create(const char *name=NULL)
Definition: bin.cpp:25
ElementPtr getElementByName(const char *name, RecursionType recursionType=RecurseDown) const
Definition: bin.cpp:59
static BinPtr fromDescription(const char *description, BinFromDescriptionOption ghostUnlinkedPads=Ghost)
Definition: bin.cpp:35
QGlib::RefPointer< T > getElementByInterface() const
Definition: bin.h:175
bool add(const ElementPtr &element)
Definition: bin.cpp:49
Wrapper class for GType.
Definition: type.h:63
bool remove(const ElementPtr &element)
Definition: bin.cpp:54
Wrapper class for GError.
Definition: error.h:30