qtmobility/plugins/multimedia/gstreamer/mediacapture/maemo/qgstreamermediacontainercontrol_maemo.cpp
changeset 4 90517678cc4f
child 11 06b8e2af4411
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 "qgstreamermediacontainercontrol_maemo.h"
       
    43 
       
    44 
       
    45 #include <QtCore/qdebug.h>
       
    46 
       
    47 QGstreamerMediaContainerControl::QGstreamerMediaContainerControl(QObject *parent)
       
    48     :QMediaContainerControl(parent)
       
    49 {
       
    50     QList<QByteArray> formatCandidates;
       
    51     formatCandidates << "mp4" << "ogg" << "wav" << "amr";
       
    52 
       
    53     m_elementNames["mp4"] = "hantromp4mux";
       
    54     m_elementNames["ogg"] = "oggmux";
       
    55     m_elementNames["wav"] = "wavenc";
       
    56     m_elementNames["amr"] = "ffmux_amr";
       
    57 
       
    58     QSet<QString> allTypes;
       
    59 
       
    60     foreach( const QByteArray& formatName, formatCandidates ) {
       
    61         QByteArray elementName = m_elementNames[formatName];
       
    62         GstElementFactory *factory = gst_element_factory_find(elementName.constData());
       
    63         if (factory) {
       
    64             m_supportedContainers.append(formatName);
       
    65             const gchar *descr = gst_element_factory_get_description(factory);
       
    66             m_containerDescriptions.insert(formatName, QString::fromUtf8(descr));
       
    67 
       
    68 
       
    69             if (formatName == QByteArray("raw")) {
       
    70                 m_streamTypes.insert(formatName, allTypes);
       
    71             } else {
       
    72                 QSet<QString> types = supportedStreamTypes(factory, GST_PAD_SINK);
       
    73                 m_streamTypes.insert(formatName, types);
       
    74                 allTypes.unite(types);
       
    75             }
       
    76 
       
    77             gst_object_unref(GST_OBJECT(factory));
       
    78         }
       
    79     }
       
    80 
       
    81     if (!m_supportedContainers.isEmpty())
       
    82         setContainerMimeType(m_supportedContainers[0]);
       
    83 }
       
    84 
       
    85 QSet<QString> QGstreamerMediaContainerControl::supportedStreamTypes(GstElementFactory *factory, GstPadDirection direction)
       
    86 {
       
    87     QSet<QString> types;
       
    88     const GList *pads = gst_element_factory_get_static_pad_templates(factory);
       
    89     for (const GList *pad = pads; pad; pad = g_list_next(pad)) {
       
    90         GstStaticPadTemplate *templ = (GstStaticPadTemplate*)pad->data;
       
    91         if (templ->direction == direction) {
       
    92             GstCaps *caps = gst_static_caps_get(&templ->static_caps);
       
    93             for (uint i=0; i<gst_caps_get_size(caps); i++) {
       
    94                 GstStructure *structure = gst_caps_get_structure(caps, i);
       
    95                 types.insert( QString::fromUtf8(gst_structure_get_name(structure)) );
       
    96             }
       
    97             gst_caps_unref(caps);
       
    98         }
       
    99     }
       
   100 
       
   101     return types;
       
   102 }
       
   103 
       
   104 
       
   105 QSet<QString> QGstreamerMediaContainerControl::supportedStreamTypes(const QString &container) const
       
   106 {
       
   107     return m_streamTypes.value(container);
       
   108 }