File size: 2,619 Bytes
be94e5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2021 Intel Corporation

#include "gstreamerenv.hpp"
#include "gstreamerptr.hpp"

#ifdef HAVE_GSTREAMER
#include <gst/gst.h>
#endif // HAVE_GSTREAMER

namespace cv {
namespace gapi {
namespace wip {
namespace gst {

#ifdef HAVE_GSTREAMER

const GStreamerEnv& GStreamerEnv::init()

{
    static GStreamerEnv gInit;
    return gInit;
}

GStreamerEnv::GStreamerEnv()
{
    if (!gst_is_initialized())
    {
        GError* error = NULL;
        gst_init_check(NULL, NULL, &error);

        GStreamerPtr<GError> err(error);

        if (err)
        {
            cv::util::throw_error(
                std::runtime_error(std::string("GStreamer initializaton error! Details: ") +
                                   err->message));
        }
    }

    // FIXME: GStreamer libs which have same MAJOR and MINOR versions are API and ABI compatible.
    //        If GStreamer runtime MAJOR version differs from the version the application was
    //        compiled with, will it fail on the linkage stage? If so, the code below isn't needed.
    guint major, minor, micro, nano;
    gst_version(&major, &minor, &micro, &nano);
    if (GST_VERSION_MAJOR != major)
    {
        cv::util::throw_error(
            std::runtime_error(std::string("Incompatible GStreamer version: compiled with ") +
                               std::to_string(GST_VERSION_MAJOR) + '.' +
                               std::to_string(GST_VERSION_MINOR) + '.' +
                               std::to_string(GST_VERSION_MICRO) + '.' +
                               std::to_string(GST_VERSION_NANO) +
                               ", but runtime has " +
                               std::to_string(major) + '.' + std::to_string(minor) + '.' +
                               std::to_string(micro) + '.' + std::to_string(nano) + '.'));
    }
}

GStreamerEnv::~GStreamerEnv()
{
    gst_deinit();
}

#else // HAVE_GSTREAMER

const GStreamerEnv& GStreamerEnv::init()

{
    GAPI_Error("Built without GStreamer support!");
}

GStreamerEnv::GStreamerEnv()
{
    GAPI_Error("Built without GStreamer support!");
}

GStreamerEnv::~GStreamerEnv()
{
    // No need an assert here. The assert raise C4722 warning. Constructor have already got assert.
}

#endif // HAVE_GSTREAMER

} // namespace gst
} // namespace wip
} // namespace gapi
} // namespace cv