qtmobility/plugins/multimedia/gstreamer/qgstreamerserviceplugin.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 5 453da2cfceef
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
    48 #include "qgstreamerserviceplugin.h"
    48 #include "qgstreamerserviceplugin.h"
    49 
    49 
    50 #ifdef QMEDIA_GSTREAMER_PLAYER
    50 #ifdef QMEDIA_GSTREAMER_PLAYER
    51 #include "qgstreamerplayerservice.h"
    51 #include "qgstreamerplayerservice.h"
    52 #endif
    52 #endif
    53 #ifdef QMEDIA_GSTREAMER_CAPTURE
    53 #if defined(QMEDIA_GSTREAMER_CAPTURE) && (defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6))
       
    54 #include "qgstreamercaptureservice_maemo.h"
       
    55 #elif defined(QMEDIA_GSTREAMER_CAPTURE)
    54 #include "qgstreamercaptureservice.h"
    56 #include "qgstreamercaptureservice.h"
    55 #endif
    57 #endif
    56 
    58 
    57 #include <qmediaserviceprovider.h>
    59 #include <qmediaserviceprovider.h>
    58 
    60 
    75 #ifdef QMEDIA_GSTREAMER_PLAYER
    77 #ifdef QMEDIA_GSTREAMER_PLAYER
    76             << QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER)
    78             << QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER)
    77 #endif
    79 #endif
    78 #ifdef QMEDIA_GSTREAMER_CAPTURE
    80 #ifdef QMEDIA_GSTREAMER_CAPTURE
    79             << QLatin1String(Q_MEDIASERVICE_AUDIOSOURCE)
    81             << QLatin1String(Q_MEDIASERVICE_AUDIOSOURCE)
    80             << QLatin1String(Q_MEDIASERVICE_CAMERA)
       
    81 #endif
    82 #endif
    82             ;
    83             ;
    83 }
    84 }
    84 
    85 
    85 QMediaService* QGstreamerServicePlugin::create(const QString &key)
    86 QMediaService* QGstreamerServicePlugin::create(const QString &key)
    89         return new QGstreamerPlayerService;
    90         return new QGstreamerPlayerService;
    90 #endif
    91 #endif
    91 #ifdef QMEDIA_GSTREAMER_CAPTURE
    92 #ifdef QMEDIA_GSTREAMER_CAPTURE
    92     if (key == QLatin1String(Q_MEDIASERVICE_AUDIOSOURCE))
    93     if (key == QLatin1String(Q_MEDIASERVICE_AUDIOSOURCE))
    93         return new QGstreamerCaptureService(key);
    94         return new QGstreamerCaptureService(key);
    94 
       
    95     if (key == QLatin1String(Q_MEDIASERVICE_CAMERA))
       
    96         return new QGstreamerCaptureService(key);
       
    97 #endif
    95 #endif
    98 
    96 
    99     //qDebug() << "unsupported key:" << key;
    97     //qDebug() << "unsupported key:" << key;
   100     return 0;
    98     return 0;
   101 }
    99 }
   103 void QGstreamerServicePlugin::release(QMediaService *service)
   101 void QGstreamerServicePlugin::release(QMediaService *service)
   104 {
   102 {
   105     delete service;
   103     delete service;
   106 }
   104 }
   107 
   105 
   108 QList<QByteArray> QGstreamerServicePlugin::devices(const QByteArray &service) const
       
   109 {
       
   110     if (service == Q_MEDIASERVICE_CAMERA) {
       
   111         if (m_cameraDevices.isEmpty())
       
   112             updateDevices();
       
   113 
       
   114         return m_cameraDevices;
       
   115     }
       
   116 
       
   117     return QList<QByteArray>();
       
   118 }
       
   119 
       
   120 QString QGstreamerServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &device)
       
   121 {
       
   122     if (service == Q_MEDIASERVICE_CAMERA) {
       
   123         if (m_cameraDevices.isEmpty())
       
   124             updateDevices();
       
   125 
       
   126         for (int i=0; i<m_cameraDevices.count(); i++)
       
   127             if (m_cameraDevices[i] == device)
       
   128                 return m_cameraDescriptions[i];
       
   129     }
       
   130 
       
   131     return QString();
       
   132 }
       
   133 
       
   134 void QGstreamerServicePlugin::updateDevices() const
       
   135 {
       
   136     m_cameraDevices.clear();
       
   137     m_cameraDescriptions.clear();
       
   138 
       
   139     QDir devDir("/dev");
       
   140     devDir.setFilter(QDir::System);
       
   141 
       
   142     QFileInfoList entries = devDir.entryInfoList(QStringList() << "video*");
       
   143 
       
   144     foreach( const QFileInfo &entryInfo, entries ) {
       
   145         //qDebug() << "Try" << entryInfo.filePath();
       
   146 
       
   147         int fd = ::open(entryInfo.filePath().toLatin1().constData(), O_RDWR );
       
   148         if (fd == -1)
       
   149             continue;
       
   150 
       
   151         bool isCamera = false;
       
   152 
       
   153         v4l2_input input;
       
   154         memset(&input, 0, sizeof(input));
       
   155         for (; ::ioctl(fd, VIDIOC_ENUMINPUT, &input) >= 0; ++input.index) {
       
   156             if(input.type == V4L2_INPUT_TYPE_CAMERA || input.type == 0) {
       
   157                 isCamera = ::ioctl(fd, VIDIOC_S_INPUT, input.index) != 0;
       
   158                 break;
       
   159             }
       
   160         }
       
   161 
       
   162         if (isCamera) {
       
   163             // find out its driver "name"
       
   164             QString name;
       
   165             struct v4l2_capability vcap;
       
   166             memset(&vcap, 0, sizeof(struct v4l2_capability));
       
   167 
       
   168             if (ioctl(fd, VIDIOC_QUERYCAP, &vcap) != 0)
       
   169                 name = entryInfo.fileName();
       
   170             else
       
   171                 name = QString((const char*)vcap.card);
       
   172             //qDebug() << "found camera: " << name;
       
   173 
       
   174             m_cameraDevices.append(entryInfo.filePath().toLocal8Bit());
       
   175             m_cameraDescriptions.append(name);
       
   176         }
       
   177         ::close(fd);
       
   178     }
       
   179 }
       
   180 
       
   181 Q_EXPORT_PLUGIN2(gstengine, QGstreamerServicePlugin);
   106 Q_EXPORT_PLUGIN2(gstengine, QGstreamerServicePlugin);