2 * This file is part of CameraPlus.
4 * Copyright (C) 2012 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"
30 const char *orientations[] = {
37 class QtCamMetaDataPrivate {
39 void addTag(const char *tag, const QString& value) {
44 gst_tag_setter_add_tags(setter, GST_TAG_MERGE_REPLACE, tag, value.toUtf8().data(), NULL);
47 void addTag(const char *tag, double value) {
52 gst_tag_setter_add_tags(setter, GST_TAG_MERGE_REPLACE, tag, value, NULL);
55 void addTag(const char *tag, GstDateTime *value) {
60 gst_tag_setter_add_tags(setter, GST_TAG_MERGE_REPLACE, tag, value, NULL);
66 QtCamMetaData::QtCamMetaData(QObject *parent) :
67 QObject(parent), d_ptr(new QtCamMetaDataPrivate) {
71 QtCamMetaData::~QtCamMetaData() {
73 delete d_ptr; d_ptr = 0;
76 void QtCamMetaData::setDevice(QtCamDevice *device) {
78 gst_object_unref(d_ptr->setter);
82 if (!device || !device->d_ptr->cameraBin) {
86 if (!GST_IS_TAG_SETTER(device->d_ptr->cameraBin)) {
90 d_ptr->setter = GST_TAG_SETTER(gst_object_ref(device->d_ptr->cameraBin));
93 void QtCamMetaData::setManufacturer(const QString& manufacturer) {
94 d_ptr->addTag(GST_TAG_DEVICE_MANUFACTURER, manufacturer);
97 void QtCamMetaData::setModel(const QString& model) {
98 d_ptr->addTag(GST_TAG_DEVICE_MODEL, model);
101 void QtCamMetaData::setCountry(const QString& country) {
102 d_ptr->addTag(GST_TAG_GEO_LOCATION_COUNTRY, country);
105 void QtCamMetaData::setCity(const QString& city) {
106 d_ptr->addTag(GST_TAG_GEO_LOCATION_CITY, city);
109 void QtCamMetaData::setSuburb(const QString& suburb) {
110 d_ptr->addTag(GST_TAG_GEO_LOCATION_SUBLOCATION, suburb);
113 void QtCamMetaData::setLongitude(double longitude) {
114 d_ptr->addTag(GST_TAG_GEO_LOCATION_LONGITUDE, longitude);
117 void QtCamMetaData::setLatitude(double latitude) {
118 d_ptr->addTag(GST_TAG_GEO_LOCATION_LATITUDE, latitude);
121 void QtCamMetaData::setElevation(double elevation) {
122 d_ptr->addTag(GST_TAG_GEO_LOCATION_ELEVATION, elevation);
125 void QtCamMetaData::setOrientation(Orientation orientation) {
126 int len = sizeof(orientations) / sizeof(orientations[0]);
128 if (orientation <= 0 || orientation >= len) {
129 orientation = Landscape;
132 d_ptr->addTag(GST_TAG_IMAGE_ORIENTATION, orientations[orientation]);
135 void QtCamMetaData::setArtist(const QString& artist) {
136 d_ptr->addTag(GST_TAG_ARTIST, artist);
139 void QtCamMetaData::setDateTime(const QDateTime& dateTime) {
140 QDate d = dateTime.date();
141 QTime t = dateTime.time();
144 int month = d.month();
147 int minute = t.minute();
149 // GstDateTime seconds expects microseconds to be there too :|
150 gdouble seconds = t.second();
151 seconds += t.msec()/(1000.0);
153 // Current UTC time. Created through string so that the link between
154 // current and utc is lost and secsTo returns non-zero values.
155 QDateTime utcTime = QDateTime::fromString(dateTime.toUTC().toString());
156 gfloat tzoffset = (utcTime.secsTo(dateTime)/3600.0);
158 GstDateTime *dt = gst_date_time_new(tzoffset, year, month, day,
159 hour, minute, seconds);
161 d_ptr->addTag(GST_TAG_DATE_TIME, dt);
163 gst_date_time_unref(dt);
166 void QtCamMetaData::setCaptureDirection(double direction) {
167 d_ptr->addTag(GST_TAG_GEO_LOCATION_CAPTURE_DIRECTION, direction);
170 void QtCamMetaData::setHorizontalError(double error) {
171 d_ptr->addTag(GST_TAG_GEO_LOCATION_HORIZONTAL_ERROR, error);
174 void QtCamMetaData::reset() {
176 gst_tag_setter_reset_tags(d_ptr->setter);