plugins/multimedia/gstreamer/mediacapture/maemo/qgstreamercaptureservice_maemo.cpp
changeset 0 876b1a06bc25
equal deleted inserted replaced
-1:000000000000 0:876b1a06bc25
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 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 "qgstreamercaptureservice_maemo.h"
       
    43 #include "qgstreamercapturesession_maemo.h"
       
    44 #include "qgstreamerrecordercontrol_maemo.h"
       
    45 #include "qgstreamermediacontainercontrol_maemo.h"
       
    46 #include "qgstreameraudioencode_maemo.h"
       
    47 #include "qgstreamervideoencode_maemo.h"
       
    48 #include "qgstreamerbushelper.h"
       
    49 #include "qgstreamercapturemetadatacontrol_maemo.h"
       
    50 
       
    51 #include "qgstreameraudioinputendpointselector.h"
       
    52 #include "qgstreamervideoinputdevicecontrol.h"
       
    53 
       
    54 #include "qgstreamervideooverlay.h"
       
    55 #include "qgstreamervideorenderer.h"
       
    56 
       
    57 #include "qgstreamervideowidget.h"
       
    58 
       
    59 #include <qmediaserviceprovider.h>
       
    60 
       
    61 #include <QtCore/qdebug.h>
       
    62 
       
    63 class QGstreamerVideoRendererWrapper : public QGstreamerElementFactory
       
    64 {
       
    65 public:
       
    66     QGstreamerVideoRendererWrapper(QGstreamerVideoRendererInterface *videoRenderer)
       
    67         :m_videoRenderer(videoRenderer),
       
    68          m_bin(0),
       
    69          m_element(0),
       
    70          m_colorspace(0)
       
    71     {
       
    72     }
       
    73 
       
    74     virtual ~QGstreamerVideoRendererWrapper()
       
    75     {
       
    76         if (m_bin)
       
    77             gst_object_unref(GST_OBJECT(m_bin));
       
    78     }
       
    79 
       
    80     GstElement *buildElement()
       
    81     {
       
    82 #ifdef Q_WS_MAEMO_5
       
    83         return m_element = m_videoRenderer->videoSink();
       
    84 #endif
       
    85         if (m_bin == NULL) {
       
    86             GstBin * bin = GST_BIN(gst_bin_new(NULL));
       
    87 
       
    88             m_colorspace = gst_element_factory_make("ffmpegcolorspace", NULL);
       
    89             m_element = m_videoRenderer->videoSink();
       
    90 
       
    91             gst_bin_add(bin, m_colorspace);
       
    92             gst_bin_add(bin, m_element);
       
    93             gst_element_link(m_colorspace, m_element);
       
    94 
       
    95             // add ghostpads
       
    96             GstPad *pad = gst_element_get_static_pad(m_colorspace, "sink");
       
    97             gst_element_add_pad(GST_ELEMENT(bin), gst_ghost_pad_new("sink", pad));
       
    98             gst_object_unref(GST_OBJECT(pad));
       
    99 
       
   100             m_bin = GST_ELEMENT(bin);
       
   101         }
       
   102 
       
   103         m_videoRenderer->precessNewStream();
       
   104 
       
   105         gst_object_ref(GST_OBJECT(m_bin));
       
   106         return m_bin;
       
   107     }
       
   108 
       
   109     void prepareWinId()
       
   110     {
       
   111         m_videoRenderer->precessNewStream();
       
   112     }
       
   113 
       
   114 private:
       
   115     QGstreamerVideoRendererInterface *m_videoRenderer;
       
   116 
       
   117     GstElement *m_bin;
       
   118     GstElement *m_element;
       
   119     GstElement *m_colorspace;
       
   120 };
       
   121 
       
   122 
       
   123 QGstreamerCaptureService::QGstreamerCaptureService(const QString &service, QObject *parent):
       
   124     QMediaService(parent)
       
   125 {
       
   126     static bool initialized = false;
       
   127     if (!initialized) {
       
   128         initialized = true;
       
   129         gst_init(NULL, NULL);
       
   130     }
       
   131 
       
   132     m_captureSession = 0;
       
   133     m_cameraControl = 0;
       
   134     m_metaDataControl = 0;
       
   135 
       
   136     m_audioInputEndpointSelector = 0;
       
   137     m_videoInputDevice = 0;
       
   138 
       
   139     m_videoRenderer = 0;
       
   140     m_videoRendererFactory = 0;
       
   141     m_videoWindow = 0;
       
   142     m_videoWindowFactory = 0;
       
   143     m_videoWidgetControl = 0;
       
   144     m_videoWidgetFactory = 0;
       
   145     m_imageCaptureControl = 0;
       
   146 
       
   147 
       
   148     if (service == Q_MEDIASERVICE_AUDIOSOURCE) {
       
   149         m_captureSession = new QGstreamerCaptureSession(QGstreamerCaptureSession::Audio, this);
       
   150     }
       
   151 
       
   152     bool captureVideo = false;
       
   153     
       
   154     if (captureVideo) {
       
   155         m_captureSession = new QGstreamerCaptureSession(QGstreamerCaptureSession::AudioAndVideo, this);
       
   156         //TODO:m_captureSession->setVideoInput(m_cameraControl);
       
   157         m_videoInputDevice = new QGstreamerVideoInputDeviceControl(m_captureSession);
       
   158 
       
   159         //TODO:connect(m_videoInputDevice, SIGNAL(selectedDeviceChanged(QString)),
       
   160         //        m_cameraControl, SLOT(setDevice(QString)));
       
   161 
       
   162         //TODO:if (m_videoInputDevice->deviceCount())
       
   163         //    m_cameraControl->setDevice(m_videoInputDevice->deviceName(m_videoInputDevice->selectedDevice()));
       
   164 
       
   165         m_videoRenderer = new QGstreamerVideoRenderer(this);
       
   166         m_videoRendererFactory = new QGstreamerVideoRendererWrapper(m_videoRenderer);
       
   167         m_videoWindow = new QGstreamerVideoOverlay(this);
       
   168         m_videoWindowFactory = new QGstreamerVideoRendererWrapper(m_videoWindow);
       
   169 
       
   170         m_videoWidgetControl = new QGstreamerVideoWidgetControl(this);
       
   171         m_videoWidgetFactory = new QGstreamerVideoRendererWrapper(m_videoWidgetControl);
       
   172 
       
   173     }
       
   174     
       
   175     if (!m_captureSession) {
       
   176         qWarning() << "Service type is not supported:" << service;
       
   177         return;
       
   178     }
       
   179 
       
   180     m_audioInputEndpointSelector = new QGstreamerAudioInputEndpointSelector(this);
       
   181     connect(m_audioInputEndpointSelector, SIGNAL(activeEndpointChanged(QString)), m_captureSession, SLOT(setCaptureDevice(QString)));
       
   182 
       
   183     if (m_captureSession && m_audioInputEndpointSelector->availableEndpoints().size() > 0)
       
   184         m_captureSession->setCaptureDevice(m_audioInputEndpointSelector->defaultEndpoint());
       
   185 
       
   186     m_metaDataControl = new QGstreamerCaptureMetaDataControl(this);
       
   187     connect(m_metaDataControl, SIGNAL(metaDataChanged(QMap<QByteArray,QVariant>)),
       
   188             m_captureSession, SLOT(setMetaData(QMap<QByteArray,QVariant>)));
       
   189 }
       
   190 
       
   191 QGstreamerCaptureService::~QGstreamerCaptureService()
       
   192 {
       
   193 }
       
   194 
       
   195 QMediaControl *QGstreamerCaptureService::requestControl(const char *name)
       
   196 {
       
   197     if (!m_captureSession)
       
   198         return 0;
       
   199 
       
   200     if (!m_videoOutput) {
       
   201         if (qstrcmp(name, QVideoRendererControl_iid) == 0) {
       
   202             m_videoOutput = m_videoRenderer;
       
   203             m_captureSession->setVideoPreview(m_videoRendererFactory);
       
   204         } else if (qstrcmp(name, QVideoWindowControl_iid) == 0) {
       
   205             m_videoOutput = m_videoWindow;
       
   206             m_captureSession->setVideoPreview(m_videoWindowFactory);
       
   207         } else if (qstrcmp(name, QVideoWidgetControl_iid) == 0) {
       
   208             m_captureSession->setVideoPreview(m_videoWidgetFactory);
       
   209             m_videoOutput = m_videoWidgetControl;
       
   210         }
       
   211 
       
   212         if (m_videoOutput)
       
   213             return m_videoOutput;
       
   214     }
       
   215 
       
   216     if (qstrcmp(name,QAudioEndpointSelector_iid) == 0)
       
   217         return m_audioInputEndpointSelector;
       
   218 
       
   219     if (qstrcmp(name,QVideoDeviceControl_iid) == 0)
       
   220         return m_videoInputDevice;
       
   221 
       
   222     if (qstrcmp(name,QMediaRecorderControl_iid) == 0)
       
   223         return m_captureSession->recorderControl();
       
   224 
       
   225     if (qstrcmp(name,QAudioEncoderControl_iid) == 0)
       
   226         return m_captureSession->audioEncodeControl();
       
   227 
       
   228     if (qstrcmp(name,QVideoEncoderControl_iid) == 0)
       
   229         return m_captureSession->videoEncodeControl();
       
   230 
       
   231     if (qstrcmp(name,QMediaContainerControl_iid) == 0)
       
   232         return m_captureSession->mediaContainerControl();
       
   233 
       
   234     if (qstrcmp(name,QMetaDataWriterControl_iid) == 0)
       
   235         return m_metaDataControl;
       
   236 
       
   237     return 0;
       
   238 }
       
   239 
       
   240 void QGstreamerCaptureService::releaseControl(QMediaControl *control)
       
   241 {
       
   242     if (control && control == m_videoOutput) {
       
   243         m_videoOutput = 0;
       
   244         m_captureSession->setVideoPreview(0);
       
   245     }
       
   246 }
       
   247 
       
   248