qtmobility/src/multimedia/qxvideosurface_maemo5.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 11 06b8e2af4411
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
   261 
   261 
   262 bool QXVideoSurface::start(const QVideoSurfaceFormat &format)
   262 bool QXVideoSurface::start(const QVideoSurfaceFormat &format)
   263 {
   263 {
   264     //qDebug() << "QXVideoSurface::start" << format;
   264     //qDebug() << "QXVideoSurface::start" << format;
   265 
   265 
       
   266     m_lastFrame = QVideoFrame();
       
   267 
   266     if (m_image)
   268     if (m_image)
   267         XFree(m_image);
   269         XFree(m_image);
   268 
   270 
   269     m_xvFormatId = 0;
   271     m_xvFormatId = 0;
   270     for (int i = 0; i < m_supportedPixelFormats.count(); ++i) {
   272     for (int i = 0; i < m_supportedPixelFormats.count(); ++i) {
   338 void QXVideoSurface::stop()
   340 void QXVideoSurface::stop()
   339 {
   341 {
   340     if (m_image) {
   342     if (m_image) {
   341         XFree(m_image);
   343         XFree(m_image);
   342         m_image = 0;
   344         m_image = 0;
   343         lastFrame = QVideoFrame();
   345         m_lastFrame = QVideoFrame();
   344 
   346 
   345         QAbstractVideoSurface::stop();
   347         QAbstractVideoSurface::stop();
   346     }
   348     }
   347 }
   349 }
   348 
   350 
   353         return false;
   355         return false;
   354     } else if (m_image->width != frame.width() || m_image->height != frame.height()) {
   356     } else if (m_image->width != frame.width() || m_image->height != frame.height()) {
   355         setError(IncorrectFormatError);
   357         setError(IncorrectFormatError);
   356         return false;
   358         return false;
   357     } else {
   359     } else {
   358         lastFrame = frame;
   360         m_lastFrame = frame;
   359 
   361 
   360         if (!lastFrame.map(QAbstractVideoBuffer::ReadOnly)) {
   362         if (!m_lastFrame.map(QAbstractVideoBuffer::ReadOnly)) {
   361             qWarning() << "Failed to map video frame";
   363             qWarning() << "Failed to map video frame";
   362             setError(IncorrectFormatError);
   364             setError(IncorrectFormatError);
   363             return false;
   365             return false;
   364         } else {
   366         } else {
   365             bool presented = false;
   367             bool presented = false;
   366 
   368 
   367             if (frame.handleType() != XvHandleType &&
   369             if (frame.handleType() != XvHandleType &&
   368                 m_image->data_size > lastFrame.mappedBytes()) {
   370                 m_image->data_size > m_lastFrame.mappedBytes()) {
   369                 qWarning("Insufficient frame buffer size");
   371                 qWarning("Insufficient frame buffer size");
   370                 setError(IncorrectFormatError);
   372                 setError(IncorrectFormatError);
   371             } else if (frame.handleType() != XvHandleType &&
   373             } else if (frame.handleType() != XvHandleType &&
   372                        m_image->num_planes > 0 &&
   374                        m_image->num_planes > 0 &&
   373                        m_image->pitches[0] != lastFrame.bytesPerLine()) {
   375                        m_image->pitches[0] != m_lastFrame.bytesPerLine()) {
   374                 qWarning("Incompatible frame pitches");
   376                 qWarning("Incompatible frame pitches");
   375                 setError(IncorrectFormatError);
   377                 setError(IncorrectFormatError);
   376             } else {
   378             } else {
   377                 XvImage *img = 0;
   379                 XvImage *img = 0;
   378 
   380 
   379                 if (frame.handleType() == XvHandleType) {
   381                 if (frame.handleType() == XvHandleType) {
   380                     img = frame.handle().value<XvImage*>();
   382                     img = frame.handle().value<XvImage*>();
   381                 } else {
   383                 } else {
   382                     img = m_image;
   384                     img = m_image;
   383                     memcpy(m_image->data, lastFrame.bits(), qMin(lastFrame.mappedBytes(), m_image->data_size));
   385                     memcpy(m_image->data, m_lastFrame.bits(), qMin(m_lastFrame.mappedBytes(), m_image->data_size));
   384                 }
   386                 }
   385 
   387 
   386                 if (img)
   388                 if (img)
   387                     XvShmPutImage(
   389                     XvShmPutImage(
   388                        QX11Info::display(),
   390                        QX11Info::display(),
   401                        false);
   403                        false);
   402 
   404 
   403                 presented = true;
   405                 presented = true;
   404             }
   406             }
   405 
   407 
   406             lastFrame.unmap();
   408             m_lastFrame.unmap();
   407 
   409 
   408             return presented;
   410             return presented;
   409         }
   411         }
   410     }
   412     }
   411 }
   413 }
   412 
   414 
   413 void QXVideoSurface::repaintLastFrame()
   415 void QXVideoSurface::repaintLastFrame()
   414 {
   416 {
   415     if (lastFrame.isValid())
   417     if (m_lastFrame.isValid())
   416         present(QVideoFrame(lastFrame));
   418         present(QVideoFrame(m_lastFrame));
   417 }
   419 }
   418 
   420 
   419 bool QXVideoSurface::findPort()
   421 bool QXVideoSurface::findPort()
   420 {
   422 {
   421     unsigned int count = 0;
   423     unsigned int count = 0;