QtGStreamer  0.10.2
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
value.cpp
00001 /*
00002     Copyright (C) 2010-2011 Collabora Ltd.
00003       @author George Kiagiadakis <george.kiagiadakis@collabora.co.uk>
00004 
00005     This library is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU Lesser General Public License as published
00007     by the Free Software Foundation; either version 2.1 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU Lesser General Public License for more details.
00014 
00015     You should have received a copy of the GNU Lesser General Public License
00016     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 */
00018 #include "structs.h"
00019 #include "miniobject.h"
00020 #include "structure.h"
00021 #include "../QGlib/value.h"
00022 #include <cmath>
00023 #include <gst/gstvalue.h>
00024 #include <gst/gstminiobject.h>
00025 #include <gst/gstdatetime.h>
00026 
00027 namespace QGlib {
00028 
00029 GetTypeImpl<QDate>::operator Type() { return GST_TYPE_DATE; }
00030 GetTypeImpl<QDateTime>::operator Type() { return GST_TYPE_DATE_TIME; }
00031 
00032 } //namespace QGlib
00033 
00034 namespace QGst {
00035 namespace Private {
00036 
00037 void registerValueVTables()
00038 {
00039     struct ValueVTable_MiniObject
00040     {
00041         static void get(const QGlib::Value & value, void *data)
00042         {
00043             *reinterpret_cast<GstMiniObject**>(data) = gst_value_get_mini_object(value);
00044         };
00045 
00046         static void set(QGlib::Value & value, const void *data)
00047         {
00048             gst_value_set_mini_object(value, *reinterpret_cast<GstMiniObject* const *>(data));
00049         };
00050     };
00051     QGlib::Value::registerValueVTable(QGlib::GetType<MiniObject>(),
00052             QGlib::ValueVTable(ValueVTable_MiniObject::set, ValueVTable_MiniObject::get));
00053 
00054 
00055     struct ValueVTable_Fourcc
00056     {
00057         static void get(const QGlib::Value & value, void *data)
00058         {
00059             reinterpret_cast<Fourcc*>(data)->value.as_integer = gst_value_get_fourcc(value);
00060         };
00061 
00062         static void set(QGlib::Value & value, const void *data)
00063         {
00064             gst_value_set_fourcc(value, reinterpret_cast<Fourcc const *>(data)->value.as_integer);
00065         };
00066     };
00067     QGlib::Value::registerValueVTable(QGlib::GetType<Fourcc>(),
00068             QGlib::ValueVTable(ValueVTable_Fourcc::set, ValueVTable_Fourcc::get));
00069 
00070 
00071     struct ValueVTable_Fraction
00072     {
00073         static void get(const QGlib::Value & value, void *data)
00074         {
00075             reinterpret_cast<Fraction*>(data)->numerator = gst_value_get_fraction_numerator(value);
00076             reinterpret_cast<Fraction*>(data)->denominator = gst_value_get_fraction_denominator(value);
00077         };
00078 
00079         static void set(QGlib::Value & value, const void *data)
00080         {
00081             gst_value_set_fraction(value, reinterpret_cast<Fraction const *>(data)->numerator,
00082                                           reinterpret_cast<Fraction const *>(data)->denominator);
00083         };
00084     };
00085     QGlib::Value::registerValueVTable(QGlib::GetType<Fraction>(),
00086             QGlib::ValueVTable(ValueVTable_Fraction::set, ValueVTable_Fraction::get));
00087 
00088 
00089     struct ValueVTable_IntRange
00090     {
00091         static void get(const QGlib::Value & value, void *data)
00092         {
00093             reinterpret_cast<IntRange*>(data)->start = gst_value_get_int_range_min(value);
00094             reinterpret_cast<IntRange*>(data)->end = gst_value_get_int_range_max(value);
00095         };
00096 
00097         static void set(QGlib::Value & value, const void *data)
00098         {
00099             gst_value_set_int_range(value, reinterpret_cast<IntRange const *>(data)->start,
00100                                            reinterpret_cast<IntRange const *>(data)->end);
00101         };
00102     };
00103     QGlib::Value::registerValueVTable(QGlib::GetType<IntRange>(),
00104             QGlib::ValueVTable(ValueVTable_IntRange::set, ValueVTable_IntRange::get));
00105 
00106     struct ValueVTable_Int64Range
00107     {
00108         static void get(const QGlib::Value & value, void *data)
00109         {
00110             reinterpret_cast<Int64Range*>(data)->start = gst_value_get_int64_range_min(value);
00111             reinterpret_cast<Int64Range*>(data)->end = gst_value_get_int64_range_max(value);
00112         };
00113 
00114         static void set(QGlib::Value & value, const void *data)
00115         {
00116             gst_value_set_int64_range(value, reinterpret_cast<Int64Range const *>(data)->start,
00117                                              reinterpret_cast<Int64Range const *>(data)->end);
00118         };
00119     };
00120     QGlib::Value::registerValueVTable(QGlib::GetType<Int64Range>(),
00121             QGlib::ValueVTable(ValueVTable_Int64Range::set, ValueVTable_Int64Range::get));
00122 
00123 
00124     struct ValueVTable_DoubleRange
00125     {
00126         static void get(const QGlib::Value & value, void *data)
00127         {
00128             reinterpret_cast<DoubleRange*>(data)->start = gst_value_get_double_range_min(value);
00129             reinterpret_cast<DoubleRange*>(data)->end = gst_value_get_double_range_max(value);
00130         };
00131 
00132         static void set(QGlib::Value & value, const void *data)
00133         {
00134             gst_value_set_double_range(value, reinterpret_cast<DoubleRange const *>(data)->start,
00135                                               reinterpret_cast<DoubleRange const *>(data)->end);
00136         };
00137     };
00138     QGlib::Value::registerValueVTable(QGlib::GetType<DoubleRange>(),
00139             QGlib::ValueVTable(ValueVTable_DoubleRange::set, ValueVTable_DoubleRange::get));
00140 
00141 
00142     struct ValueVTable_FractionRange
00143     {
00144         static void get(const QGlib::Value & value, void *data)
00145         {
00146             reinterpret_cast<FractionRange*>(data)->start.numerator =
00147                 gst_value_get_fraction_numerator(gst_value_get_fraction_range_min(value));
00148             reinterpret_cast<FractionRange*>(data)->start.denominator =
00149                 gst_value_get_fraction_denominator(gst_value_get_fraction_range_min(value));
00150             reinterpret_cast<FractionRange*>(data)->end.numerator =
00151                 gst_value_get_fraction_numerator(gst_value_get_fraction_range_max(value));
00152             reinterpret_cast<FractionRange*>(data)->end.denominator =
00153                 gst_value_get_fraction_denominator(gst_value_get_fraction_range_max(value));
00154         };
00155 
00156         static void set(QGlib::Value & value, const void *data)
00157         {
00158             gst_value_set_fraction_range_full(value,
00159                     reinterpret_cast<FractionRange const *>(data)->start.numerator,
00160                     reinterpret_cast<FractionRange const *>(data)->start.denominator,
00161                     reinterpret_cast<FractionRange const *>(data)->end.numerator,
00162                     reinterpret_cast<FractionRange const *>(data)->end.denominator);
00163         };
00164     };
00165     QGlib::Value::registerValueVTable(QGlib::GetType<FractionRange>(),
00166             QGlib::ValueVTable(ValueVTable_FractionRange::set, ValueVTable_FractionRange::get));
00167 
00168     struct ValueVTable_Structure
00169     {
00170         static void get(const QGlib::Value & value, void *data)
00171         {
00172             *reinterpret_cast<Structure*>(data) = Structure(gst_value_get_structure(value));
00173         };
00174 
00175         static void set(QGlib::Value & value, const void *data)
00176         {
00177             gst_value_set_structure(value, *reinterpret_cast<Structure const *>(data));
00178         };
00179     };
00180     QGlib::Value::registerValueVTable(QGlib::GetType<Structure>(),
00181             QGlib::ValueVTable(ValueVTable_Structure::set, ValueVTable_Structure::get));
00182 
00183     struct ValueVTable_QDate
00184     {
00185         static void get(const QGlib::Value & value, void *data)
00186         {
00187             const GDate *gdate = gst_value_get_date(value);
00188             *reinterpret_cast<QDate*>(data) = QDate(g_date_get_year(gdate),
00189                                                     g_date_get_month(gdate),
00190                                                     g_date_get_day(gdate));
00191         }
00192 
00193         static void set(QGlib::Value & value, const void *data)
00194         {
00195             const QDate *qdate = reinterpret_cast<QDate const *>(data);
00196             GDate *gdate = g_date_new_dmy(qdate->day(),
00197                                           static_cast<GDateMonth>(qdate->month()),
00198                                           qdate->year());
00199             gst_value_set_date(value, gdate);
00200             g_date_free(gdate);
00201         }
00202     };
00203     QGlib::Value::registerValueVTable(QGlib::GetType<QDate>(),
00204             QGlib::ValueVTable(ValueVTable_QDate::set, ValueVTable_QDate::get));
00205 
00206     struct ValueVTable_QDateTime
00207     {
00208         static void get(const QGlib::Value & value, void *data)
00209         {
00210             const GstDateTime *gdatetime = static_cast<GstDateTime*>(g_value_get_boxed(value));
00211 
00212             QDate date = QDate(gst_date_time_get_year(gdatetime),
00213                                gst_date_time_get_month(gdatetime),
00214                                gst_date_time_get_day(gdatetime));
00215 
00216             /* timezone conversion */
00217             float tzoffset = gst_date_time_get_time_zone_offset(gdatetime);
00218             float hourOffset;
00219             float minutesOffset = std::modf(tzoffset, &hourOffset);
00220 
00221             int hour = gst_date_time_get_hour(gdatetime) - hourOffset;
00222             int minute = gst_date_time_get_minute(gdatetime) - (minutesOffset * 60);
00223 
00224             /* handle overflow */
00225             if (minute >= 60) {
00226                 hour++;
00227                 minute -= 60;
00228             } else if (minute < 0) {
00229                 hour--;
00230                 minute = 60 + minute;
00231             }
00232 
00233             if (hour >= 24) {
00234                 date = date.addDays(1);
00235                 hour -= 24;
00236             } else if (hour < 0) {
00237                 date = date.addDays(-1);
00238                 hour = 24 + hour;
00239             }
00240 
00241             QTime time = QTime(hour, minute,
00242                                gst_date_time_get_second(gdatetime),
00243                                gst_date_time_get_microsecond(gdatetime)/1000);
00244 
00245             *reinterpret_cast<QDateTime*>(data) = QDateTime(date, time, Qt::UTC);
00246         }
00247 
00248         static void set(QGlib::Value & value, const void *data)
00249         {
00250             QDateTime qdatetime = reinterpret_cast<QDateTime const *>(data)->toUTC();
00251             GstDateTime *gdatetime = gst_date_time_new(0.0f,
00252                 qdatetime.date().year(),
00253                 qdatetime.date().month(),
00254                 qdatetime.date().day(),
00255                 qdatetime.time().hour(),
00256                 qdatetime.time().minute(),
00257                 qdatetime.time().second() + (qdatetime.time().msec()/1000.0)
00258             );
00259 
00260             g_value_take_boxed(value, gdatetime);
00261         }
00262     };
00263     QGlib::Value::registerValueVTable(QGlib::GetType<QDateTime>(),
00264             QGlib::ValueVTable(ValueVTable_QDateTime::set, ValueVTable_QDateTime::get));
00265 }
00266 
00267 } //namespace Private
00268 } //namespace QGst