QtGStreamer  1.2.0
segment.cpp
1 /*
2  Copyright (C) 2014 George Kiagiadakis <kiagiadakis.george@gmail.com>
3 
4  This library is free software; you can redistribute it and/or modify
5  it under the terms of the GNU Lesser General Public License as published
6  by the Free Software Foundation; either version 2.1 of the License, or
7  (at your option) any later version.
8 
9  This program 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
12  GNU Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 #include "segment.h"
18 #include <gst/gst.h>
19 
20 namespace QGst {
21 
22 #ifndef DOXYGEN_RUN
23 
24 struct QTGSTREAMER_NO_EXPORT Segment::Data : public QSharedData
25 {
26  Data() : QSharedData(), segment(NULL) {}
27  Data(const Data & other);
28  virtual ~Data();
29 
30  GstSegment *segment;
31 };
32 
33 Segment::Data::Data(const Segment::Data & other)
34  : QSharedData(other), segment(NULL)
35 {
36  if (other.segment) {
37  segment = gst_segment_copy(other.segment);
38  }
39 }
40 
41 Segment::Data::~Data()
42 {
43  if (segment) {
44  gst_segment_free(segment);
45  }
46 }
47 
48 #endif //DOXYGEN_RUN
49 
50 Segment::Segment()
51  : d(new Data)
52 {
53 }
54 
55 Segment::Segment(Format fmt)
56  : d(new Data)
57 {
58  d->segment = gst_segment_new();
59  init(fmt);
60 }
61 
62 Segment::Segment(const GstSegment * segment)
63  : d(new Data)
64 {
65  d->segment = gst_segment_copy(segment);
66 }
67 
68 Segment::Segment(const Segment & other)
69  : d(other.d)
70 {
71 }
72 
73 Segment & Segment::operator=(const Segment & other)
74 {
75  d = other.d;
76  return *this;
77 }
78 
79 Segment::~Segment()
80 {
81 }
82 
83 bool Segment::isValid() const
84 {
85  return d->segment != NULL;
86 }
87 
88 void Segment::init(Format fmt)
89 {
90  gst_segment_init(d->segment, static_cast<GstFormat>(fmt));
91 }
92 
93 SegmentFlags Segment::flags() const
94 {
95  return d->segment ? static_cast<SegmentFlag>(d->segment->flags) : SegmentFlagNone;
96 }
97 
98 double Segment::rate() const
99 {
100  return d->segment ? d->segment->rate : 1.0;
101 }
102 
103 double Segment::appliedRate() const
104 {
105  return d->segment ? d->segment->applied_rate : 1.0;
106 }
107 
108 Format Segment::format() const
109 {
110  return d->segment ? static_cast<Format>(d->segment->format) : FormatUndefined;
111 }
112 
113 quint64 Segment::base() const
114 {
115  return d->segment ? d->segment->base : 0;
116 }
117 
118 quint64 Segment::offset() const
119 {
120  return d->segment ? d->segment->offset : 0;
121 }
122 
123 quint64 Segment::start() const
124 {
125  return d->segment ? d->segment->start : 0;
126 }
127 
128 quint64 Segment::stop() const
129 {
130  return d->segment ? d->segment->stop : -1;
131 }
132 
133 quint64 Segment::time() const
134 {
135  return d->segment ? d->segment->time : 0;
136 }
137 
138 quint64 Segment::position() const
139 {
140  return d->segment ? d->segment->position : 0;
141 }
142 
143 quint64 Segment::duration() const
144 {
145  return d->segment ? d->segment->duration : -1;
146 }
147 
148 Segment::operator GstSegment*()
149 {
150  return d->segment;
151 }
152 
153 Segment::operator const GstSegment*() const
154 {
155  return d->segment;
156 }
157 
158 } //namespace QGst
void init()
Definition: init.cpp:27
Wrappers for GStreamer classes.