summaryrefslogtreecommitdiff
path: root/src/QGst/bin.cpp
blob: eec98862a02afed976acb1a1c3acae3c5df8c34e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
    Copyright (C) 2009-2010  George Kiagiadakis <kiagiadakis.george@gmail.com>

    This library is free software; you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published
    by the Free Software Foundation; either version 2.1 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "bin.h"
#include "pad.h"
#include "../QGlib/error.h"
#include <gst/gst.h>

namespace QGst {

//static
BinPtr Bin::create(const char *name)
{
    GstElement *bin = gst_bin_new(name);
    if (bin) {
        gst_object_ref_sink(bin);
    }
    return BinPtr::wrap(GST_BIN(bin), false);
}

//static
BinPtr Bin::fromDescription(const char *description, BinFromDescriptionOption ghostUnlinkedPads)
{
    GError *error = NULL;
    GstElement *e = gst_parse_bin_from_description_full(description, ghostUnlinkedPads,
                                                        NULL, GST_PARSE_FLAG_FATAL_ERRORS, &error);
    if (error) {
        throw QGlib::Error(error);
    }
    if (e) {
        gst_object_ref_sink(e);
    }
    return BinPtr::wrap(GST_BIN(e), false);
}

bool Bin::add(const ElementPtr & element)
{
    return gst_bin_add(object<GstBin>(), element);
}

bool Bin::remove(const ElementPtr & element)
{
    return gst_bin_remove(object<GstBin>(), element);
}

ElementPtr Bin::getElementByName(const char *name, RecursionType r) const
{
    GstElement *e = NULL;
    switch(r) {
    case RecurseDown:
        e = gst_bin_get_by_name(object<GstBin>(), name);
        break;
    case RecurseUp:
        e = gst_bin_get_by_name_recurse_up(object<GstBin>(), name);
        break;
    default:
        Q_ASSERT_X(false, "QGst::Bin::getElementByName", "Invalid RecursionType");
    }
    return ElementPtr::wrap(e, false);
}

ElementPtr Bin::getElementByInterface(QGlib::Type interfaceType) const
{
    return ElementPtr::wrap(gst_bin_get_by_interface(object<GstBin>(), interfaceType), false);
}

PadPtr Bin::findUnlinkedPad(PadDirection direction) const
{
    return PadPtr::wrap(gst_bin_find_unlinked_pad(object<GstBin>(),
                                                  static_cast<GstPadDirection>(direction)), false);
}

bool Bin::recalculateLatency()
{
    return gst_bin_recalculate_latency(object<GstBin>());
}

}