summaryrefslogtreecommitdiff
path: root/src/QuickStreamer/plugin.cpp
blob: fd10f2f81e646d55026a5bff561dfb1389cd04b4 (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
#include "plugin.h"
#include "item.h"

#include <gst/gst.h>

#include <QtQml>

namespace QQuickStreamer {

static const auto NAMESPACE_URI = QByteArrayLiteral("QuickStreamer");

Plugin::Plugin(QObject *parent)
    : QQmlExtensionPlugin(parent)
{
}

void Plugin::registerTypes(const char *uri)
{
    Q_ASSERT(uri == NAMESPACE_URI);

    if (not gst_is_initialized()) {
        GError *error = Q_NULLPTR;

        if (not gst_init_check(Q_NULLPTR, Q_NULLPTR, &error)) {
            qWarning("Cannot initialize %s module: %s", NAMESPACE_URI.constData(), error->message);
            g_error_free(error);
            return;
        }
    }

    Item::registerObjectClass(GST_TYPE_BIN);
    Item::registerObjectClass(GST_TYPE_PIPELINE);

    auto *const elements = gst_element_factory_list_get_elements(GST_ELEMENT_FACTORY_TYPE_ANY, GST_RANK_NONE);

    for (auto *l = elements; l; l = l->next) {
        auto *const feature = GST_PLUGIN_FEATURE(l->data);
        auto *const factory = GST_ELEMENT_FACTORY(gst_plugin_feature_load(feature));
        Item::registerElementFactory(factory);
        g_object_unref(factory);
    }

    gst_plugin_feature_list_free(elements);
}

} // namespace QQuickStreamer