QtGStreamer 1.2.0
Loading...
Searching...
No Matches
value.cpp
1/*
2 Copyright (C) 2010-2011 Collabora Ltd.
3 @author George Kiagiadakis <george.kiagiadakis@collabora.co.uk>
4
5 This library is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published
7 by the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18#include "structs.h"
19#include "miniobject.h"
20#include "structure.h"
21#include "../QGlib/value.h"
22#include <cmath>
23#include <gst/gst.h>
24
25namespace QGlib {
26
27GetTypeImpl<QDate>::operator Type() { return G_TYPE_DATE; }
28GetTypeImpl<QDateTime>::operator Type() { return GST_TYPE_DATE_TIME; }
29
30} //namespace QGlib
31
32namespace QGst {
33namespace Private {
34
35void registerValueVTables()
36{
37 struct ValueVTable_Fraction
38 {
39 static void get(const QGlib::Value & value, void *data)
40 {
41 reinterpret_cast<Fraction*>(data)->numerator = gst_value_get_fraction_numerator(value);
42 reinterpret_cast<Fraction*>(data)->denominator = gst_value_get_fraction_denominator(value);
43 };
44
45 static void set(QGlib::Value & value, const void *data)
46 {
47 gst_value_set_fraction(value, reinterpret_cast<Fraction const *>(data)->numerator,
48 reinterpret_cast<Fraction const *>(data)->denominator);
49 };
50 };
51 QGlib::Value::registerValueVTable(QGlib::GetType<Fraction>(),
52 QGlib::ValueVTable(ValueVTable_Fraction::set, ValueVTable_Fraction::get));
53
54
55 struct ValueVTable_IntRange
56 {
57 static void get(const QGlib::Value & value, void *data)
58 {
59 reinterpret_cast<IntRange*>(data)->start = gst_value_get_int_range_min(value);
60 reinterpret_cast<IntRange*>(data)->end = gst_value_get_int_range_max(value);
61 };
62
63 static void set(QGlib::Value & value, const void *data)
64 {
65 gst_value_set_int_range(value, reinterpret_cast<IntRange const *>(data)->start,
66 reinterpret_cast<IntRange const *>(data)->end);
67 };
68 };
69 QGlib::Value::registerValueVTable(QGlib::GetType<IntRange>(),
70 QGlib::ValueVTable(ValueVTable_IntRange::set, ValueVTable_IntRange::get));
71
72 struct ValueVTable_Int64Range
73 {
74 static void get(const QGlib::Value & value, void *data)
75 {
76 reinterpret_cast<Int64Range*>(data)->start = gst_value_get_int64_range_min(value);
77 reinterpret_cast<Int64Range*>(data)->end = gst_value_get_int64_range_max(value);
78 };
79
80 static void set(QGlib::Value & value, const void *data)
81 {
82 gst_value_set_int64_range(value, reinterpret_cast<Int64Range const *>(data)->start,
83 reinterpret_cast<Int64Range const *>(data)->end);
84 };
85 };
86 QGlib::Value::registerValueVTable(QGlib::GetType<Int64Range>(),
87 QGlib::ValueVTable(ValueVTable_Int64Range::set, ValueVTable_Int64Range::get));
88
89
90 struct ValueVTable_DoubleRange
91 {
92 static void get(const QGlib::Value & value, void *data)
93 {
94 reinterpret_cast<DoubleRange*>(data)->start = gst_value_get_double_range_min(value);
95 reinterpret_cast<DoubleRange*>(data)->end = gst_value_get_double_range_max(value);
96 };
97
98 static void set(QGlib::Value & value, const void *data)
99 {
100 gst_value_set_double_range(value, reinterpret_cast<DoubleRange const *>(data)->start,
101 reinterpret_cast<DoubleRange const *>(data)->end);
102 };
103 };
104 QGlib::Value::registerValueVTable(QGlib::GetType<DoubleRange>(),
105 QGlib::ValueVTable(ValueVTable_DoubleRange::set, ValueVTable_DoubleRange::get));
106
107
108 struct ValueVTable_FractionRange
109 {
110 static void get(const QGlib::Value & value, void *data)
111 {
112 reinterpret_cast<FractionRange*>(data)->start.numerator =
113 gst_value_get_fraction_numerator(gst_value_get_fraction_range_min(value));
114 reinterpret_cast<FractionRange*>(data)->start.denominator =
115 gst_value_get_fraction_denominator(gst_value_get_fraction_range_min(value));
116 reinterpret_cast<FractionRange*>(data)->end.numerator =
117 gst_value_get_fraction_numerator(gst_value_get_fraction_range_max(value));
118 reinterpret_cast<FractionRange*>(data)->end.denominator =
119 gst_value_get_fraction_denominator(gst_value_get_fraction_range_max(value));
120 };
121
122 static void set(QGlib::Value & value, const void *data)
123 {
124 gst_value_set_fraction_range_full(value,
125 reinterpret_cast<FractionRange const *>(data)->start.numerator,
126 reinterpret_cast<FractionRange const *>(data)->start.denominator,
127 reinterpret_cast<FractionRange const *>(data)->end.numerator,
128 reinterpret_cast<FractionRange const *>(data)->end.denominator);
129 };
130 };
131 QGlib::Value::registerValueVTable(QGlib::GetType<FractionRange>(),
132 QGlib::ValueVTable(ValueVTable_FractionRange::set, ValueVTable_FractionRange::get));
133
134 struct ValueVTable_Structure
135 {
136 static void get(const QGlib::Value & value, void *data)
137 {
138 *reinterpret_cast<Structure*>(data) = Structure(gst_value_get_structure(value));
139 };
140
141 static void set(QGlib::Value & value, const void *data)
142 {
143 gst_value_set_structure(value, *reinterpret_cast<Structure const *>(data));
144 };
145 };
146 QGlib::Value::registerValueVTable(QGlib::GetType<Structure>(),
147 QGlib::ValueVTable(ValueVTable_Structure::set, ValueVTable_Structure::get));
148
149 struct ValueVTable_QDate
150 {
151 static void get(const QGlib::Value & value, void *data)
152 {
153 const GDate *gdate = static_cast<const GDate *>(g_value_get_boxed(value));
154 *reinterpret_cast<QDate*>(data) = QDate(g_date_get_year(gdate),
155 g_date_get_month(gdate),
156 g_date_get_day(gdate));
157 }
158
159 static void set(QGlib::Value & value, const void *data)
160 {
161 const QDate *qdate = reinterpret_cast<QDate const *>(data);
162 GDate *gdate = g_date_new_dmy(qdate->day(),
163 static_cast<GDateMonth>(qdate->month()),
164 qdate->year());
165 g_value_set_boxed(value, gdate);
166 g_date_free(gdate);
167 }
168 };
169 QGlib::Value::registerValueVTable(QGlib::GetType<QDate>(),
170 QGlib::ValueVTable(ValueVTable_QDate::set, ValueVTable_QDate::get));
171
172 struct ValueVTable_QDateTime
173 {
174 static void get(const QGlib::Value & value, void *data)
175 {
176 const GstDateTime *gdatetime = static_cast<GstDateTime*>(g_value_get_boxed(value));
177
178 QDate date = QDate(gst_date_time_get_year(gdatetime),
179 gst_date_time_get_month(gdatetime),
180 gst_date_time_get_day(gdatetime));
181
182 /* timezone conversion */
183 float tzoffset = gst_date_time_get_time_zone_offset(gdatetime);
184 float hourOffset;
185 float minutesOffset = std::modf(tzoffset, &hourOffset);
186
187 int hour = gst_date_time_get_hour(gdatetime) - hourOffset;
188 int minute = gst_date_time_get_minute(gdatetime) - (minutesOffset * 60);
189
190 /* handle overflow */
191 if (minute >= 60) {
192 hour++;
193 minute -= 60;
194 } else if (minute < 0) {
195 hour--;
196 minute = 60 + minute;
197 }
198
199 if (hour >= 24) {
200 date = date.addDays(1);
201 hour -= 24;
202 } else if (hour < 0) {
203 date = date.addDays(-1);
204 hour = 24 + hour;
205 }
206
207 QTime time = QTime(hour, minute,
208 gst_date_time_get_second(gdatetime),
209 gst_date_time_get_microsecond(gdatetime)/1000);
210
211 *reinterpret_cast<QDateTime*>(data) = QDateTime(date, time, Qt::UTC);
212 }
213
214 static void set(QGlib::Value & value, const void *data)
215 {
216 QDateTime qdatetime = reinterpret_cast<QDateTime const *>(data)->toUTC();
217 GstDateTime *gdatetime = gst_date_time_new(0.0f,
218 qdatetime.date().year(),
219 qdatetime.date().month(),
220 qdatetime.date().day(),
221 qdatetime.time().hour(),
222 qdatetime.time().minute(),
223 qdatetime.time().second() + (qdatetime.time().msec()/1000.0)
224 );
225
226 g_value_take_boxed(value, gdatetime);
227 }
228 };
229 QGlib::Value::registerValueVTable(QGlib::GetType<QDateTime>(),
230 QGlib::ValueVTable(ValueVTable_QDateTime::set, ValueVTable_QDateTime::get));
231}
232
233} //namespace Private
234} //namespace QGst
Wrapper class for GValue.
Definition value.h:77
static void registerValueVTable(Type type, const ValueVTable &vtable)
Definition value.cpp:292
Wrappers for Glib and GObject classes.
Wrappers for GStreamer classes.
Private::Range< double > DoubleRange
Helper structure for accessing double ranges.
Definition structs.h:127
Private::Range< Fraction > FractionRange
Helper structure for accessing fraction ranges.
Definition structs.h:132
Private::Range< qint64 > Int64Range
Helper structure for accessing qint64 ranges.
Definition structs.h:122
Private::Range< int > IntRange
Helper structure for accessing int ranges.
Definition structs.h:117