qtmobility/plugins/multimedia/gstreamer/mediacapture/maemo/qgstreamercapturemetadatacontrol_maemo.cpp
changeset 4 90517678cc4f
child 5 453da2cfceef
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include "qgstreamercapturemetadatacontrol_maemo.h"
       
    43 
       
    44 #include <gst/gst.h>
       
    45 #include <gst/gstversion.h>
       
    46 
       
    47 struct QGstreamerMetaDataKeyLookup
       
    48 {
       
    49     QtMedia::MetaData key;
       
    50     const char *token;
       
    51 };
       
    52 
       
    53 static const QGstreamerMetaDataKeyLookup qt_gstreamerMetaDataKeys[] =
       
    54 {
       
    55     { QtMedia::Title, GST_TAG_TITLE },
       
    56     //{ QtMedia::SubTitle, 0 },
       
    57     //{ QtMedia::Author, 0 },
       
    58     { QtMedia::Comment, GST_TAG_COMMENT },
       
    59     { QtMedia::Description, GST_TAG_DESCRIPTION },
       
    60     //{ QtMedia::Category, 0 },
       
    61     { QtMedia::Genre, GST_TAG_GENRE },
       
    62     //{ QtMedia::Year, 0 },
       
    63     //{ QtMedia::UserRating, 0 },
       
    64 
       
    65     { QtMedia::Language, GST_TAG_LANGUAGE_CODE },
       
    66 
       
    67     { QtMedia::Publisher, GST_TAG_ORGANIZATION },
       
    68     { QtMedia::Copyright, GST_TAG_COPYRIGHT },
       
    69     //{ QtMedia::ParentalRating, 0 },
       
    70     //{ QtMedia::RatingOrganisation, 0 },
       
    71 
       
    72     // Media
       
    73     //{ QtMedia::Size, 0 },
       
    74     //{ QtMedia::MediaType, 0 },
       
    75     { QtMedia::Duration, GST_TAG_DURATION },
       
    76 
       
    77     // Audio
       
    78     { QtMedia::AudioBitRate, GST_TAG_BITRATE },
       
    79     { QtMedia::AudioCodec, GST_TAG_AUDIO_CODEC },
       
    80     //{ QtMedia::ChannelCount, 0 },
       
    81     //{ QtMedia::SampleRate, 0 },
       
    82 
       
    83     // Music
       
    84     { QtMedia::AlbumTitle, GST_TAG_ALBUM },
       
    85     { QtMedia::AlbumArtist,  GST_TAG_ARTIST},
       
    86     { QtMedia::ContributingArtist, GST_TAG_PERFORMER },
       
    87 #if (GST_VERSION_MAJOR >= 0) && (GST_VERSION_MINOR >= 10) && (GST_VERSION_MICRO >= 19)
       
    88     { QtMedia::Composer, GST_TAG_COMPOSER },
       
    89 #endif
       
    90     //{ QtMedia::Conductor, 0 },
       
    91     //{ QtMedia::Lyrics, 0 },
       
    92     //{ QtMedia::Mood, 0 },
       
    93     { QtMedia::TrackNumber, GST_TAG_TRACK_NUMBER },
       
    94 
       
    95     //{ QtMedia::CoverArtUrlSmall, 0 },
       
    96     //{ QtMedia::CoverArtUrlLarge, 0 },
       
    97 
       
    98     // Image/Video
       
    99     //{ QtMedia::Resolution, 0 },
       
   100     //{ QtMedia::PixelAspectRatio, 0 },
       
   101 
       
   102     // Video
       
   103     //{ QtMedia::VideoFrameRate, 0 },
       
   104     //{ QtMedia::VideoBitRate, 0 },
       
   105     { QtMedia::VideoCodec, GST_TAG_VIDEO_CODEC },
       
   106 
       
   107     //{ QtMedia::PosterUrl, 0 },
       
   108 
       
   109     // Movie
       
   110     //{ QtMedia::ChapterNumber, 0 },
       
   111     //{ QtMedia::Director, 0 },
       
   112     { QtMedia::LeadPerformer, GST_TAG_PERFORMER },
       
   113     //{ QtMedia::Writer, 0 },
       
   114 
       
   115     // Photos
       
   116     //{ QtMedia::CameraManufacturer, 0 },
       
   117     //{ QtMedia::CameraModel, 0 },
       
   118     //{ QtMedia::Event, 0 },
       
   119     //{ QtMedia::Subject, 0 }
       
   120 };
       
   121 
       
   122 QGstreamerCaptureMetaDataControl::QGstreamerCaptureMetaDataControl(QObject *parent)
       
   123     :QMetaDataControl(parent)
       
   124 {
       
   125 }
       
   126 
       
   127 QVariant QGstreamerCaptureMetaDataControl::metaData(QtMedia::MetaData key) const
       
   128 {
       
   129     static const int count = sizeof(qt_gstreamerMetaDataKeys) / sizeof(QGstreamerMetaDataKeyLookup);
       
   130 
       
   131     for (int i = 0; i < count; ++i) {
       
   132         if (qt_gstreamerMetaDataKeys[i].key == key) {
       
   133             const char *name = qt_gstreamerMetaDataKeys[i].token;
       
   134 
       
   135             return m_values.value(QByteArray::fromRawData(name, qstrlen(name)));
       
   136         }
       
   137     }
       
   138     return QVariant();
       
   139 }
       
   140 
       
   141 void QGstreamerCaptureMetaDataControl::setMetaData(QtMedia::MetaData key, const QVariant &value)
       
   142 {
       
   143     static const int count = sizeof(qt_gstreamerMetaDataKeys) / sizeof(QGstreamerMetaDataKeyLookup);
       
   144 
       
   145     for (int i = 0; i < count; ++i) {
       
   146         if (qt_gstreamerMetaDataKeys[i].key == key) {
       
   147             const char *name = qt_gstreamerMetaDataKeys[i].token;
       
   148 
       
   149             m_values.insert(QByteArray::fromRawData(name, qstrlen(name)), value);
       
   150 
       
   151             emit QMetaDataControl::metaDataChanged();
       
   152             emit metaDataChanged(m_values);
       
   153 
       
   154             return;
       
   155         }
       
   156     }
       
   157 }
       
   158 
       
   159 QList<QtMedia::MetaData> QGstreamerCaptureMetaDataControl::availableMetaData() const
       
   160 {
       
   161     static QMap<QByteArray, QtMedia::MetaData> keysMap;
       
   162     if (keysMap.isEmpty()) {
       
   163         const int count = sizeof(qt_gstreamerMetaDataKeys) / sizeof(QGstreamerMetaDataKeyLookup);
       
   164         for (int i = 0; i < count; ++i) {
       
   165             keysMap[QByteArray(qt_gstreamerMetaDataKeys[i].token)] = qt_gstreamerMetaDataKeys[i].key;
       
   166         }
       
   167     }
       
   168 
       
   169     QList<QtMedia::MetaData> res;
       
   170     foreach (const QByteArray &key, m_values.keys()) {
       
   171         QtMedia::MetaData tag = keysMap.value(key, QtMedia::MetaData(-1));
       
   172         if (tag != -1)
       
   173             res.append(tag);
       
   174     }
       
   175 
       
   176     return res;
       
   177 }
       
   178 
       
   179 QVariant QGstreamerCaptureMetaDataControl::extendedMetaData(QString const &name) const
       
   180 {
       
   181     return m_values.value(name.toLatin1());
       
   182 }
       
   183 
       
   184 void QGstreamerCaptureMetaDataControl::setExtendedMetaData(QString const &name, QVariant const &value)
       
   185 {
       
   186     m_values.insert(name.toLatin1(), value);
       
   187     emit QMetaDataControl::metaDataChanged();
       
   188     emit metaDataChanged(m_values);
       
   189 }
       
   190 
       
   191 QStringList QGstreamerCaptureMetaDataControl::availableExtendedMetaData() const
       
   192 {
       
   193     QStringList res;
       
   194     foreach (const QByteArray &key, m_values.keys())
       
   195         res.append(QString(key));
       
   196 
       
   197     return res;
       
   198 }