1 #include "qtcammetadata.h"
2 #include <gst/gsttaglist.h>
3 #include "qtcamdevice.h"
4 #include "qtcamdevice_p.h"
10 const char *orientations[] = {
17 class QtCamMetaDataPrivate {
19 void addTag(const char *tag, const QString& value) {
24 gst_tag_setter_add_tags(setter, GST_TAG_MERGE_REPLACE, tag, value.toUtf8().data(), NULL);
27 void addTag(const char *tag, double value) {
32 gst_tag_setter_add_tags(setter, GST_TAG_MERGE_REPLACE, tag, value, NULL);
35 void addTag(const char *tag, GstDateTime *value) {
40 gst_tag_setter_add_tags(setter, GST_TAG_MERGE_REPLACE, tag, value, NULL);
46 QtCamMetaData::QtCamMetaData(QObject *parent) :
47 QObject(parent), d_ptr(new QtCamMetaDataPrivate) {
51 QtCamMetaData::~QtCamMetaData() {
53 delete d_ptr; d_ptr = 0;
56 void QtCamMetaData::setDevice(QtCamDevice *device) {
58 gst_object_unref(d_ptr->setter);
62 if (!device || !device->d_ptr->cameraBin) {
66 if (!GST_IS_TAG_SETTER(device->d_ptr->cameraBin)) {
70 d_ptr->setter = GST_TAG_SETTER(gst_object_ref(device->d_ptr->cameraBin));
73 void QtCamMetaData::setManufacturer(const QString& manufacturer) {
74 d_ptr->addTag(GST_TAG_DEVICE_MANUFACTURER, manufacturer);
77 void QtCamMetaData::setModel(const QString& model) {
78 d_ptr->addTag(GST_TAG_DEVICE_MODEL, model);
81 void QtCamMetaData::setCountry(const QString& country) {
82 d_ptr->addTag(GST_TAG_GEO_LOCATION_COUNTRY, country);
85 void QtCamMetaData::setCity(const QString& city) {
86 d_ptr->addTag(GST_TAG_GEO_LOCATION_CITY, city);
89 void QtCamMetaData::setSuburb(const QString& suburb) {
90 d_ptr->addTag(GST_TAG_GEO_LOCATION_SUBLOCATION, suburb);
93 void QtCamMetaData::setLongitude(double longitude) {
94 d_ptr->addTag(GST_TAG_GEO_LOCATION_LONGITUDE, longitude);
97 void QtCamMetaData::setLatitude(double latitude) {
98 d_ptr->addTag(GST_TAG_GEO_LOCATION_LATITUDE, latitude);
101 void QtCamMetaData::setElevation(double elevation) {
102 d_ptr->addTag(GST_TAG_GEO_LOCATION_ELEVATION, elevation);
105 void QtCamMetaData::setOrientation(Orientation orientation) {
106 int len = sizeof(orientations) / sizeof(orientations[0]);
108 if (orientation <= 0 || orientation >= len) {
109 orientation = Landscape;
112 d_ptr->addTag(GST_TAG_IMAGE_ORIENTATION, orientations[orientation]);
115 void QtCamMetaData::setArtist(const QString& artist) {
116 d_ptr->addTag(GST_TAG_ARTIST, artist);
119 void QtCamMetaData::setDateTime(const QDateTime& dateTime) {
120 QDate d = dateTime.date();
121 QTime t = dateTime.time();
124 int month = d.month();
127 int minute = t.minute();
129 // GstDateTime seconds expects microseconds to be there too :|
130 gdouble seconds = t.second();
131 seconds += t.msec()/(1000.0);
133 // Current UTC time. Created through string so that the link between
134 // current and utc is lost and secsTo returns non-zero values.
135 QDateTime utcTime = QDateTime::fromString(dateTime.toUTC().toString());
136 gfloat tzoffset = (utcTime.secsTo(dateTime)/3600.0);
138 GstDateTime *dt = gst_date_time_new(tzoffset, year, month, day,
139 hour, minute, seconds);
141 d_ptr->addTag(GST_TAG_DATE_TIME, dt);
143 gst_date_time_unref(dt);
146 void QtCamMetaData::setCaptureDirection(double direction) {
147 d_ptr->addTag(GST_TAG_GEO_LOCATION_CAPTURE_DIRECTION, direction);
150 void QtCamMetaData::setHorizontalError(double error) {
151 d_ptr->addTag(GST_TAG_GEO_LOCATION_HORIZONTAL_ERROR, error);
154 void QtCamMetaData::reset() {
156 gst_tag_setter_reset_tags(d_ptr->setter);