2 * This file is part of CameraPlus.
4 * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "qtcammetadata.h"
22 #include <gst/gsttaglist.h>
23 #include "qtcamdevice.h"
24 #include "qtcamdevice_p.h"
31 const char *orientations[] = {
38 class QtCamMetaDataPrivate {
40 void addTag(const char *tag, const QString& value) {
41 GstTagSetter *s = setter();
46 gst_tag_setter_add_tags(s, GST_TAG_MERGE_REPLACE, tag, value.toUtf8().data(), NULL);
51 void addTag(const char *tag, double value) {
52 GstTagSetter *s = setter();
57 gst_tag_setter_add_tags(s, GST_TAG_MERGE_REPLACE, tag, value, NULL);
62 void addTag(const char *tag, GstDateTime *value) {
63 GstTagSetter *s = setter();
68 gst_tag_setter_add_tags(s, GST_TAG_MERGE_REPLACE, tag, value, NULL);
73 GstTagSetter *setter() {
74 if (!device || !device->d_ptr->cameraBin) {
78 if (!GST_IS_TAG_SETTER(device->d_ptr->cameraBin)) {
82 return GST_TAG_SETTER(gst_object_ref(device->d_ptr->cameraBin));
85 QPointer<QtCamDevice> device;
88 QtCamMetaData::QtCamMetaData(QObject *parent) :
89 QObject(parent), d_ptr(new QtCamMetaDataPrivate) {
92 QtCamMetaData::~QtCamMetaData() {
94 delete d_ptr; d_ptr = 0;
97 void QtCamMetaData::setDevice(QtCamDevice *device) {
98 if (device != d_ptr->device) {
99 d_ptr->device = device;
103 void QtCamMetaData::setManufacturer(const QString& manufacturer) {
104 d_ptr->addTag(GST_TAG_DEVICE_MANUFACTURER, manufacturer);
107 void QtCamMetaData::setModel(const QString& model) {
108 d_ptr->addTag(GST_TAG_DEVICE_MODEL, model);
111 void QtCamMetaData::setCountry(const QString& country) {
112 d_ptr->addTag(GST_TAG_GEO_LOCATION_COUNTRY, country);
115 void QtCamMetaData::setCity(const QString& city) {
116 d_ptr->addTag(GST_TAG_GEO_LOCATION_CITY, city);
119 void QtCamMetaData::setSuburb(const QString& suburb) {
120 d_ptr->addTag(GST_TAG_GEO_LOCATION_SUBLOCATION, suburb);
123 void QtCamMetaData::setLongitude(double longitude) {
124 d_ptr->addTag(GST_TAG_GEO_LOCATION_LONGITUDE, longitude);
127 void QtCamMetaData::setLatitude(double latitude) {
128 d_ptr->addTag(GST_TAG_GEO_LOCATION_LATITUDE, latitude);
131 void QtCamMetaData::setElevation(double elevation) {
132 d_ptr->addTag(GST_TAG_GEO_LOCATION_ELEVATION, elevation);
135 void QtCamMetaData::setOrientation(Orientation orientation) {
136 int len = sizeof(orientations) / sizeof(orientations[0]);
138 if (orientation <= 0 || orientation >= len) {
139 orientation = Landscape;
142 d_ptr->addTag(GST_TAG_IMAGE_ORIENTATION, orientations[orientation]);
145 void QtCamMetaData::setArtist(const QString& artist) {
146 d_ptr->addTag(GST_TAG_ARTIST, artist);
149 void QtCamMetaData::setDateTime(const QDateTime& dateTime) {
150 QDate d = dateTime.date();
151 QTime t = dateTime.time();
154 int month = d.month();
157 int minute = t.minute();
159 // GstDateTime seconds expects microseconds to be there too :|
160 gdouble seconds = t.second();
161 seconds += t.msec()/(1000.0);
163 // Current UTC time. Created through string so that the link between
164 // current and utc is lost and secsTo returns non-zero values.
165 QDateTime utcTime = QDateTime::fromString(dateTime.toUTC().toString());
166 gfloat tzoffset = (utcTime.secsTo(dateTime)/3600.0);
168 GstDateTime *dt = gst_date_time_new(tzoffset, year, month, day,
169 hour, minute, seconds);
171 d_ptr->addTag(GST_TAG_DATE_TIME, dt);
173 gst_date_time_unref(dt);
176 void QtCamMetaData::setCaptureDirection(double direction) {
177 d_ptr->addTag(GST_TAG_GEO_LOCATION_CAPTURE_DIRECTION, direction);
180 void QtCamMetaData::setHorizontalError(double error) {
181 d_ptr->addTag(GST_TAG_GEO_LOCATION_HORIZONTAL_ERROR, error);
184 void QtCamMetaData::reset() {
185 GstTagSetter *s = d_ptr->setter();
190 gst_tag_setter_reset_tags(s);