QtGStreamer  0.10.2
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
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/gstvalue.h>
24 #include <gst/gstminiobject.h>
25 #include <gst/gstdatetime.h>
26 
27 namespace QGlib {
28 
29 GetTypeImpl<QDate>::operator Type() { return GST_TYPE_DATE; }
30 GetTypeImpl<QDateTime>::operator Type() { return GST_TYPE_DATE_TIME; }
31 
32 } //namespace QGlib
33 
34 namespace QGst {
35 namespace Private {
36 
37 void registerValueVTables()
38 {
39  struct ValueVTable_MiniObject
40  {
41  static void get(const QGlib::Value & value, void *data)
42  {
43  *reinterpret_cast<GstMiniObject**>(data) = gst_value_get_mini_object(value);
44  };
45 
46  static void set(QGlib::Value & value, const void *data)
47  {
48  gst_value_set_mini_object(value, *reinterpret_cast<GstMiniObject* const *>(data));
49  };
50  };
51  QGlib::Value::registerValueVTable(QGlib::GetType<MiniObject>(),
52  QGlib::ValueVTable(ValueVTable_MiniObject::set, ValueVTable_MiniObject::get));
53 
54 
55  struct ValueVTable_Fourcc
56  {
57  static void get(const QGlib::Value & value, void *data)
58  {
59  reinterpret_cast<Fourcc*>(data)->value.as_integer = gst_value_get_fourcc(value);
60  };
61 
62  static void set(QGlib::Value & value, const void *data)
63  {
64  gst_value_set_fourcc(value, reinterpret_cast<Fourcc const *>(data)->value.as_integer);
65  };
66  };
67  QGlib::Value::registerValueVTable(QGlib::GetType<Fourcc>(),
68  QGlib::ValueVTable(ValueVTable_Fourcc::set, ValueVTable_Fourcc::get));
69 
70 
71  struct ValueVTable_Fraction
72  {
73  static void get(const QGlib::Value & value, void *data)
74  {
75  reinterpret_cast<Fraction*>(data)->numerator = gst_value_get_fraction_numerator(value);
76  reinterpret_cast<Fraction*>(data)->denominator = gst_value_get_fraction_denominator(value);
77  };
78 
79  static void set(QGlib::Value & value, const void *data)
80  {
81  gst_value_set_fraction(value, reinterpret_cast<Fraction const *>(data)->numerator,
82  reinterpret_cast<Fraction const *>(data)->denominator);
83  };
84  };
85  QGlib::Value::registerValueVTable(QGlib::GetType<Fraction>(),
86  QGlib::ValueVTable(ValueVTable_Fraction::set, ValueVTable_Fraction::get));
87 
88 
89  struct ValueVTable_IntRange
90  {
91  static void get(const QGlib::Value & value, void *data)
92  {
93  reinterpret_cast<IntRange*>(data)->start = gst_value_get_int_range_min(value);
94  reinterpret_cast<IntRange*>(data)->end = gst_value_get_int_range_max(value);
95  };
96 
97  static void set(QGlib::Value & value, const void *data)
98  {
99  gst_value_set_int_range(value, reinterpret_cast<IntRange const *>(data)->start,
100  reinterpret_cast<IntRange const *>(data)->end);
101  };
102  };
103  QGlib::Value::registerValueVTable(QGlib::GetType<IntRange>(),
104  QGlib::ValueVTable(ValueVTable_IntRange::set, ValueVTable_IntRange::get));
105 
106  struct ValueVTable_Int64Range
107  {
108  static void get(const QGlib::Value & value, void *data)
109  {
110  reinterpret_cast<Int64Range*>(data)->start = gst_value_get_int64_range_min(value);
111  reinterpret_cast<Int64Range*>(data)->end = gst_value_get_int64_range_max(value);
112  };
113 
114  static void set(QGlib::Value & value, const void *data)
115  {
116  gst_value_set_int64_range(value, reinterpret_cast<Int64Range const *>(data)->start,
117  reinterpret_cast<Int64Range const *>(data)->end);
118  };
119  };
120  QGlib::Value::registerValueVTable(QGlib::GetType<Int64Range>(),
121  QGlib::ValueVTable(ValueVTable_Int64Range::set, ValueVTable_Int64Range::get));
122 
123 
124  struct ValueVTable_DoubleRange
125  {
126  static void get(const QGlib::Value & value, void *data)
127  {
128  reinterpret_cast<DoubleRange*>(data)->start = gst_value_get_double_range_min(value);
129  reinterpret_cast<DoubleRange*>(data)->end = gst_value_get_double_range_max(value);
130  };
131 
132  static void set(QGlib::Value & value, const void *data)
133  {
134  gst_value_set_double_range(value, reinterpret_cast<DoubleRange const *>(data)->start,
135  reinterpret_cast<DoubleRange const *>(data)->end);
136  };
137  };
138  QGlib::Value::registerValueVTable(QGlib::GetType<DoubleRange>(),
139  QGlib::ValueVTable(ValueVTable_DoubleRange::set, ValueVTable_DoubleRange::get));
140 
141 
142  struct ValueVTable_FractionRange
143  {
144  static void get(const QGlib::Value & value, void *data)
145  {
146  reinterpret_cast<FractionRange*>(data)->start.numerator =
147  gst_value_get_fraction_numerator(gst_value_get_fraction_range_min(value));
148  reinterpret_cast<FractionRange*>(data)->start.denominator =
149  gst_value_get_fraction_denominator(gst_value_get_fraction_range_min(value));
150  reinterpret_cast<FractionRange*>(data)->end.numerator =
151  gst_value_get_fraction_numerator(gst_value_get_fraction_range_max(value));
152  reinterpret_cast<FractionRange*>(data)->end.denominator =
153  gst_value_get_fraction_denominator(gst_value_get_fraction_range_max(value));
154  };
155 
156  static void set(QGlib::Value & value, const void *data)
157  {
158  gst_value_set_fraction_range_full(value,
159  reinterpret_cast<FractionRange const *>(data)->start.numerator,
160  reinterpret_cast<FractionRange const *>(data)->start.denominator,
161  reinterpret_cast<FractionRange const *>(data)->end.numerator,
162  reinterpret_cast<FractionRange const *>(data)->end.denominator);
163  };
164  };
165  QGlib::Value::registerValueVTable(QGlib::GetType<FractionRange>(),
166  QGlib::ValueVTable(ValueVTable_FractionRange::set, ValueVTable_FractionRange::get));
167 
168  struct ValueVTable_Structure
169  {
170  static void get(const QGlib::Value & value, void *data)
171  {
172  *reinterpret_cast<Structure*>(data) = Structure(gst_value_get_structure(value));
173  };
174 
175  static void set(QGlib::Value & value, const void *data)
176  {
177  gst_value_set_structure(value, *reinterpret_cast<Structure const *>(data));
178  };
179  };
180  QGlib::Value::registerValueVTable(QGlib::GetType<Structure>(),
181  QGlib::ValueVTable(ValueVTable_Structure::set, ValueVTable_Structure::get));
182 
183  struct ValueVTable_QDate
184  {
185  static void get(const QGlib::Value & value, void *data)
186  {
187  const GDate *gdate = gst_value_get_date(value);
188  *reinterpret_cast<QDate*>(data) = QDate(g_date_get_year(gdate),
189  g_date_get_month(gdate),
190  g_date_get_day(gdate));
191  }
192 
193  static void set(QGlib::Value & value, const void *data)
194  {
195  const QDate *qdate = reinterpret_cast<QDate const *>(data);
196  GDate *gdate = g_date_new_dmy(qdate->day(),
197  static_cast<GDateMonth>(qdate->month()),
198  qdate->year());
199  gst_value_set_date(value, gdate);
200  g_date_free(gdate);
201  }
202  };
203  QGlib::Value::registerValueVTable(QGlib::GetType<QDate>(),
204  QGlib::ValueVTable(ValueVTable_QDate::set, ValueVTable_QDate::get));
205 
206  struct ValueVTable_QDateTime
207  {
208  static void get(const QGlib::Value & value, void *data)
209  {
210  const GstDateTime *gdatetime = static_cast<GstDateTime*>(g_value_get_boxed(value));
211 
212  QDate date = QDate(gst_date_time_get_year(gdatetime),
213  gst_date_time_get_month(gdatetime),
214  gst_date_time_get_day(gdatetime));
215 
216  /* timezone conversion */
217  float tzoffset = gst_date_time_get_time_zone_offset(gdatetime);
218  float hourOffset;
219  float minutesOffset = std::modf(tzoffset, &hourOffset);
220 
221  int hour = gst_date_time_get_hour(gdatetime) - hourOffset;
222  int minute = gst_date_time_get_minute(gdatetime) - (minutesOffset * 60);
223 
224  /* handle overflow */
225  if (minute >= 60) {
226  hour++;
227  minute -= 60;
228  } else if (minute < 0) {
229  hour--;
230  minute = 60 + minute;
231  }
232 
233  if (hour >= 24) {
234  date = date.addDays(1);
235  hour -= 24;
236  } else if (hour < 0) {
237  date = date.addDays(-1);
238  hour = 24 + hour;
239  }
240 
241  QTime time = QTime(hour, minute,
242  gst_date_time_get_second(gdatetime),
243  gst_date_time_get_microsecond(gdatetime)/1000);
244 
245  *reinterpret_cast<QDateTime*>(data) = QDateTime(date, time, Qt::UTC);
246  }
247 
248  static void set(QGlib::Value & value, const void *data)
249  {
250  QDateTime qdatetime = reinterpret_cast<QDateTime const *>(data)->toUTC();
251  GstDateTime *gdatetime = gst_date_time_new(0.0f,
252  qdatetime.date().year(),
253  qdatetime.date().month(),
254  qdatetime.date().day(),
255  qdatetime.time().hour(),
256  qdatetime.time().minute(),
257  qdatetime.time().second() + (qdatetime.time().msec()/1000.0)
258  );
259 
260  g_value_take_boxed(value, gdatetime);
261  }
262  };
263  QGlib::Value::registerValueVTable(QGlib::GetType<QDateTime>(),
264  QGlib::ValueVTable(ValueVTable_QDateTime::set, ValueVTable_QDateTime::get));
265 }
266 
267 } //namespace Private
268 } //namespace QGst