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

#include <gst/gst.h>

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;
        }
    }

    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