Line data Source code
1 : /*
2 : * Copyright (C) 2022 Sky UK
3 : *
4 : * This library is free software; you can redistribute it and/or
5 : * modify it under the terms of the GNU Lesser General Public
6 : * License as published by the Free Software Foundation;
7 : * version 2.1 of the License.
8 : *
9 : * This library 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 GNU
12 : * Lesser General Public License for more details.
13 : *
14 : * You should have received a copy of the GNU Lesser General Public
15 : * License along with this library; if not, write to the Free Software
16 : * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 : */
18 :
19 : #include "GStreamerUtils.h"
20 :
21 : #define GST_CAT_DEFAULT rialtoGStreamerCat
22 :
23 24 : GstMappedBuffer::GstMappedBuffer(GstBuffer *buffer, GstMapFlags flags)
24 24 : : m_buffer(buffer), m_isMapped(gst_buffer_map(m_buffer, &m_info, flags))
25 : {
26 : }
27 :
28 24 : GstMappedBuffer::~GstMappedBuffer()
29 : {
30 24 : if (m_isMapped)
31 : {
32 22 : gst_buffer_unmap(m_buffer, &m_info);
33 : }
34 24 : }
35 :
36 44 : uint8_t *GstMappedBuffer::data()
37 : {
38 44 : if (m_isMapped)
39 : {
40 43 : return static_cast<uint8_t *>(m_info.data);
41 : }
42 : else
43 : {
44 1 : return nullptr;
45 : }
46 : }
47 :
48 33 : size_t GstMappedBuffer::size() const
49 : {
50 33 : if (m_isMapped)
51 : {
52 32 : return static_cast<size_t>(m_info.size);
53 : }
54 : else
55 : {
56 1 : return 0;
57 : }
58 : }
59 :
60 24 : GstMappedBuffer::operator bool() const
61 : {
62 24 : return m_isMapped;
63 : }
64 :
65 13 : GstRefSample::GstRefSample(GstSample *sample) : m_sample{sample ? gst_sample_ref(sample) : nullptr} {}
66 :
67 13 : GstRefSample::~GstRefSample()
68 : {
69 13 : if (m_sample)
70 : {
71 11 : gst_sample_unref(m_sample);
72 : }
73 13 : }
74 :
75 5 : GstRefSample::operator bool() const
76 : {
77 5 : return m_sample;
78 : }
79 :
80 3 : GstBuffer *GstRefSample::getBuffer() const
81 : {
82 3 : return gst_sample_get_buffer(m_sample);
83 : }
84 :
85 10 : GstCaps *GstRefSample::getCaps() const
86 : {
87 10 : return gst_sample_get_caps(m_sample);
88 : }
|