bool VideoSurface_ForQQuickItem::start(const QVideoSurfaceFormat& format)
{
    if (!supportedPixelFormats(format.handleType()).contains(format.pixelFormat())) {
        qDebug() << format.handleType() << " " << format.pixelFormat() << " - format is not supported.";
        return false;
    }
    return QAbstractVideoSurface::start(format);
}
Ejemplo n.º 2
0
bool QVideoSurfaceRasterPainter::isFormatSupported(
        const QVideoSurfaceFormat &format, QVideoSurfaceFormat *) const
{
    return format.handleType() == QAbstractVideoBuffer::NoHandle
            && m_imagePixelFormats.contains(format.pixelFormat())
            && !format.frameSize().isEmpty();
}
Ejemplo n.º 3
0
bool myVideoPlayer::presentImage(const QImage &image)
{
	QVideoFrame frame(image);

	if (!frame.isValid())
		return false;

	QVideoSurfaceFormat currentFormat = surface->surfaceFormat();

	if (frame.pixelFormat() != currentFormat.pixelFormat()
		|| frame.size() != currentFormat.frameSize()) 
	{
		QVideoSurfaceFormat format(frame.size(), frame.pixelFormat());

		if (!surface->start(format))
			return false;
	}

	if (!surface->present(frame)) 
	{
		surface->stop();

		return false;
	} 
	else
	{
		return true;
	}
}
Ejemplo n.º 4
0
int DirectShowMediaType::bytesPerLine(const QVideoSurfaceFormat &format)
{
    switch (format.pixelFormat()) {
    // 32 bpp packed formats.
    case QVideoFrame::Format_RGB32:
    case QVideoFrame::Format_AYUV444:
        return format.frameWidth() * 4;
    // 24 bpp packed formats.
    case QVideoFrame::Format_RGB24:
        return PAD_TO_DWORD(format.frameWidth() * 3);
    // 16 bpp packed formats.
    case QVideoFrame::Format_RGB565:
    case QVideoFrame::Format_RGB555:
    case QVideoFrame::Format_YUYV:
    case QVideoFrame::Format_UYVY:
        return PAD_TO_DWORD(format.frameWidth() * 2);
    // Planar formats.
    case QVideoFrame::Format_IMC1:
    case QVideoFrame::Format_IMC2:
    case QVideoFrame::Format_IMC3:
    case QVideoFrame::Format_IMC4:
    case QVideoFrame::Format_YV12:
    case QVideoFrame::Format_NV12:
    case QVideoFrame::Format_YUV420P:
        return PAD_TO_DWORD(format.frameWidth());
    default:
        return 0;
    }
}
Ejemplo n.º 5
0
bool VideoWidgetSurface::isFormatSupported(const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar) const
{
    Q_UNUSED(similar);

    const QImage::Format imageFormat = QVideoFrame::imageFormatFromPixelFormat(format.pixelFormat());
    const QSize size = format.frameSize();

    return imageFormat != QImage::Format_Invalid && !size.isEmpty() && format.handleType() == QAbstractVideoBuffer::NoHandle;
}
Ejemplo n.º 6
0
bool VideoSurface::start(const QVideoSurfaceFormat &format)
{
    mVideoFormat = format;
    //start only if format is UYVY, dont handle other format now
    if( format.pixelFormat() == QVideoFrame::Format_YV12 ){
        QAbstractVideoSurface::start(format);
        return true;
    } else {
        return false;
    }
}
Ejemplo n.º 7
0
QAbstractVideoSurface::Error QVideoSurfaceRasterPainter::start(const QVideoSurfaceFormat &format)
{
    m_frame = QVideoFrame();
    m_imageFormat = QVideoFrame::imageFormatFromPixelFormat(format.pixelFormat());
    m_imageSize = format.frameSize();
    m_scanLineDirection = format.scanLineDirection();

    return format.handleType() == QAbstractVideoBuffer::NoHandle
            && m_imageFormat != QImage::Format_Invalid
            && !m_imageSize.isEmpty()
            ? QAbstractVideoSurface::NoError
            : QAbstractVideoSurface::UnsupportedFormatError;
}
Ejemplo n.º 8
0
bool MyVideoSurface::start(const QVideoSurfaceFormat &format)
{
    m_videoFormat = format;
    const QImage::Format imageFormat = QVideoFrame::imageFormatFromPixelFormat(format.pixelFormat());
    const QSize size = format.frameSize();

    if (imageFormat != QImage::Format_Invalid && !size.isEmpty()) {
        m_imageFormat = imageFormat;
        QAbstractVideoSurface::start(format);
        return true;
    } else {
        return false;
    }
}
Ejemplo n.º 9
0
    // Overridden from QAbstractVideoSurface
    virtual bool start( const QVideoSurfaceFormat &format )
    {
        m_mutex.lock();

        m_flipped = ( format.scanLineDirection() == QVideoSurfaceFormat::BottomToTop );
        m_frameFormat = QVideoFrame::imageFormatFromPixelFormat( format.pixelFormat() );
        m_viewport = format.viewport();
        m_valid = 1;

        // We want to unlock it before calling the parent function, which may call present() and deadlock
        m_mutex.unlock();

        return QAbstractVideoSurface::start( format );
    }
QDebug operator<<(QDebug dbg, const QVideoSurfaceFormat &f)
{
    dbg.nospace() << "QVideoSurfaceFormat(" << f.pixelFormat();
    dbg.nospace() << ", " << f.frameSize();
    dbg.nospace() << ", viewport=" << f.viewport();
    dbg.nospace() << ", pixelAspectRatio=" << f.pixelAspectRatio();
    dbg.nospace() << ", handleType=" << f.handleType();
    dbg.nospace() << ", yCbCrColorSpace=" << f.yCbCrColorSpace();
    dbg.nospace() << ")";

    foreach(const QByteArray& propertyName, f.propertyNames())
        dbg << "\n    " << propertyName.data() << " = " << f.property(propertyName.data());

    return dbg.space();
}
Ejemplo n.º 11
0
void tst_QVideoSurfaceFormat::constructNull()
{
    QVideoSurfaceFormat format;

    QVERIFY(!format.isValid());
    QCOMPARE(format.handleType(), QAbstractVideoBuffer::NoHandle);
    QCOMPARE(format.pixelFormat(), QVideoFrame::Format_Invalid);
    QCOMPARE(format.frameSize(), QSize());
    QCOMPARE(format.frameWidth(), -1);
    QCOMPARE(format.frameHeight(), -1);
    QCOMPARE(format.viewport(), QRect());
    QCOMPARE(format.scanLineDirection(), QVideoSurfaceFormat::TopToBottom);
    QCOMPARE(format.frameRate(), 0.0);
    QCOMPARE(format.pixelAspectRatio(), QSize(1, 1));
    QCOMPARE(format.yCbCrColorSpace(), QVideoSurfaceFormat::YCbCr_Undefined);
}
Ejemplo n.º 12
0
bool VideoItem::start(const QVideoSurfaceFormat &format)
{
    if (isFormatSupported(format)) {
        imageFormat = QVideoFrame::imageFormatFromPixelFormat(format.pixelFormat());
        imageSize = format.frameSize();
        framePainted = true;

        QAbstractVideoSurface::start(format);

        prepareGeometryChange();

        return true;
    } else {
        return false;
    }
}
Ejemplo n.º 13
0
bool QX11VideoSurface::start(const QVideoSurfaceFormat &format)
{
    if (m_image)
        XFree(m_image);

    int xvFormatId = 0;
    for (int i = 0; i < m_supportedPixelFormats.count(); ++i) {
        if (m_supportedPixelFormats.at(i) == format.pixelFormat()) {
            xvFormatId = m_formatIds.at(i);
            break;
        }
    }

    if (xvFormatId == 0) {
        setError(UnsupportedFormatError);
    } else {
        XvImage *image = XvCreateImage(
                QX11Info::display(),
                m_portId,
                xvFormatId,
                0,
                format.frameWidth(),
                format.frameHeight());

        if (!image) {
            setError(ResourceError);
        } else {
            m_viewport = format.viewport();
            m_image = image;

            QVideoSurfaceFormat newFormat = format;
            newFormat.setProperty("portId", QVariant(quint64(m_portId)));
            newFormat.setProperty("xvFormatId", xvFormatId);
            newFormat.setProperty("dataSize", image->data_size);

            return QAbstractVideoSurface::start(newFormat);
        }
    }

    if (m_image) {
        m_image = 0;

        QAbstractVideoSurface::stop();
    }

    return false;
}
Ejemplo n.º 14
0
QSGVideoMaterial_YUV::QSGVideoMaterial_YUV(const QVideoSurfaceFormat &format) :
    m_format(format),
    m_opacity(1.0)
{
    memset(m_textureIds, 0, sizeof(m_textureIds));

    switch (format.pixelFormat()) {
    case QVideoFrame::Format_NV12:
    case QVideoFrame::Format_NV21:
        m_planeCount = 2;
        break;
    case QVideoFrame::Format_YUV420P:
    case QVideoFrame::Format_YV12:
        m_planeCount = 3;
        break;
    default:
        m_planeCount = 1;
        break;
    }

    switch (format.yCbCrColorSpace()) {
    case QVideoSurfaceFormat::YCbCr_JPEG:
        m_colorMatrix = QMatrix4x4(
                    1.0f,  0.000f,  1.402f, -0.701f,
                    1.0f, -0.344f, -0.714f,  0.529f,
                    1.0f,  1.772f,  0.000f, -0.886f,
                    0.0f,  0.000f,  0.000f,  1.0000f);
        break;
    case QVideoSurfaceFormat::YCbCr_BT709:
    case QVideoSurfaceFormat::YCbCr_xvYCC709:
        m_colorMatrix = QMatrix4x4(
                    1.164f,  0.000f,  1.793f, -0.5727f,
                    1.164f, -0.534f, -0.213f,  0.3007f,
                    1.164f,  2.115f,  0.000f, -1.1302f,
                    0.0f,    0.000f,  0.000f,  1.0000f);
        break;
    default: //BT 601:
        m_colorMatrix = QMatrix4x4(
                    1.164f,  0.000f,  1.596f, -0.8708f,
                    1.164f, -0.392f, -0.813f,  0.5296f,
                    1.164f,  2.017f,  0.000f, -1.081f,
                    0.0f,    0.000f,  0.000f,  1.0000f);
    }

    setFlag(Blending, false);
}
Ejemplo n.º 15
0
bool AndroidVideoSurface::start(const QVideoSurfaceFormat &format)
{
    const QImage::Format m_imageFormat = QVideoFrame::imageFormatFromPixelFormat(format.pixelFormat());
    const QSize size = format.frameSize();

    if (m_imageFormat != QImage::Format_Invalid && !size.isEmpty()) {
        this->m_imageFormat = m_imageFormat;
        m_imageSize = size;
        m_sourceRect = format.viewport();
        emit(surfaceStarted(format));
        m_widget->updateGeometry();
        updateVideoRect();
        return true;
    } else {
        return false;
    }
}
Ejemplo n.º 16
0
bool MyVideoSurface::start(const QVideoSurfaceFormat &format)
{
    QImage::Format imageFormat =
        QVideoFrame::imageFormatFromPixelFormat(format.pixelFormat());

    if (imageFormat == QImage::Format_Invalid)
        imageFormat = QImage::Format_RGB32;

    const QSize frameSize = format.frameSize();

    if ((imageFormat != QImage::Format_Invalid) && !frameSize.isEmpty()) {
        QAbstractVideoSurface::start(format);

        emit frameSizeChanged(frameSize);

        return true;
    }

    return false;
}
Ejemplo n.º 17
0
//! [2]
bool VideoWidgetSurface::start(const QVideoSurfaceFormat &format)
{
    const QImage::Format imageFormat = QVideoFrame::imageFormatFromPixelFormat(format.pixelFormat());
    const QSize size = format.frameSize();

    if (imageFormat != QImage::Format_Invalid && !size.isEmpty()) {
        this->imageFormat = imageFormat;
        imageSize = size;
        sourceRect = format.viewport();

        QAbstractVideoSurface::start(format);

        widget->updateGeometry();
        updateVideoRect();

        return true;
    } else {
        return false;
    }
}
Ejemplo n.º 18
0
/* Test case for api isValid */
void tst_QVideoSurfaceFormat::isValid()
{
    /* When both pixel format and framesize is not valid */
    QVideoSurfaceFormat format;
    QVERIFY(!format.isValid());

    /* When framesize is valid and pixel format is not valid */
    format.setFrameSize(64,64);
    QVERIFY(format.frameSize() == QSize(64,64));
    QVERIFY(!format.pixelFormat());
    QVERIFY(!format.isValid());

    /* When both the pixel format and framesize is valid. */
    QVideoSurfaceFormat format1(QSize(32, 32), QVideoFrame::Format_AYUV444);
    QVERIFY(format1.isValid());

    /* When pixel format is valid and frame size is not valid */
    format1.setFrameSize(-1,-1);
    QVERIFY(!format1.frameSize().isValid());
    QVERIFY(!format1.isValid());
}
Ejemplo n.º 19
0
void QSGVideoMaterial_YUV::bind()
{
    QOpenGLFunctions *functions = QOpenGLContext::currentContext()->functions();
    QMutexLocker lock(&m_frameMutex);
    if (m_frame.isValid()) {
        if (m_frame.map(QAbstractVideoBuffer::ReadOnly)) {
            int fw = m_frame.width();
            int fh = m_frame.height();

            // Frame has changed size, recreate textures...
            if (m_textureSize != m_frame.size()) {
                if (!m_textureSize.isEmpty())
                    functions->glDeleteTextures(m_planeCount, m_textureIds);
                functions->glGenTextures(m_planeCount, m_textureIds);
                m_textureSize = m_frame.size();
            }

            GLint previousAlignment;
            functions->glGetIntegerv(GL_UNPACK_ALIGNMENT, &previousAlignment);
            functions->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

            if (m_format.pixelFormat() == QVideoFrame::Format_NV12
                    || m_format.pixelFormat() == QVideoFrame::Format_NV21) {
                const int y = 0;
                const int uv = 1;

                m_planeWidth[0] = m_planeWidth[1] = qreal(fw) / m_frame.bytesPerLine(y);

                functions->glActiveTexture(GL_TEXTURE1);
                bindTexture(m_textureIds[1], m_frame.bytesPerLine(uv) / 2, fh / 2, m_frame.bits(uv), GL_LUMINANCE_ALPHA);
                functions->glActiveTexture(GL_TEXTURE0); // Finish with 0 as default texture unit
                bindTexture(m_textureIds[0], m_frame.bytesPerLine(y), fh, m_frame.bits(y), GL_LUMINANCE);

            } else { // YUV420P || YV12
                const int y = 0;
                const int u = m_frame.pixelFormat() == QVideoFrame::Format_YUV420P ? 1 : 2;
                const int v = m_frame.pixelFormat() == QVideoFrame::Format_YUV420P ? 2 : 1;

                m_planeWidth[0] = qreal(fw) / m_frame.bytesPerLine(y);
                m_planeWidth[1] = m_planeWidth[2] = qreal(fw) / (2 * m_frame.bytesPerLine(u));

                functions->glActiveTexture(GL_TEXTURE1);
                bindTexture(m_textureIds[1], m_frame.bytesPerLine(u), fh / 2, m_frame.bits(u), GL_LUMINANCE);
                functions->glActiveTexture(GL_TEXTURE2);
                bindTexture(m_textureIds[2], m_frame.bytesPerLine(v), fh / 2, m_frame.bits(v), GL_LUMINANCE);
                functions->glActiveTexture(GL_TEXTURE0); // Finish with 0 as default texture unit
                bindTexture(m_textureIds[0], m_frame.bytesPerLine(y), fh, m_frame.bits(y), GL_LUMINANCE);
            }

            functions->glPixelStorei(GL_UNPACK_ALIGNMENT, previousAlignment);
            m_frame.unmap();
        }

        m_frame = QVideoFrame();
    } else {
        // Go backwards to finish with GL_TEXTURE0
        for (int i = m_planeCount - 1; i >= 0; --i) {
            functions->glActiveTexture(GL_TEXTURE0 + i);
            functions->glBindTexture(GL_TEXTURE_2D, m_textureIds[i]);
        }
    }
}
Ejemplo n.º 20
0
bool QAbstractVideoSurface::isFormatSupported(const QVideoSurfaceFormat &format) const
{
    return supportedPixelFormats(format.handleType()).contains(format.pixelFormat());
}
Ejemplo n.º 21
0
bool CameraFormatProxy::isFormatSupported(const QVideoSurfaceFormat &format) const
{
    return QVideoFrame::imageFormatFromPixelFormat(format.pixelFormat())!=QImage::Format_Invalid;
}
Ejemplo n.º 22
0
 bool needsSwizzling() const {
     return m_format.pixelFormat() == QVideoFrame::Format_RGB32
             || m_format.pixelFormat() == QVideoFrame::Format_ARGB32;
 }
 bool needsSwizzling() const {
     return !QMediaOpenGLHelper::isANGLE()
             && (m_format.pixelFormat() == QVideoFrame::Format_RGB32
                 || m_format.pixelFormat() == QVideoFrame::Format_ARGB32);
 }
Ejemplo n.º 24
0
QDebug operator<<(QDebug dbg, const QVideoSurfaceFormat &f)
{
    QString typeName;
    switch (f.pixelFormat()) {
    case QVideoFrame::Format_Invalid:
        typeName = QLatin1String("Format_Invalid");
        break;
    case QVideoFrame::Format_ARGB32:
        typeName = QLatin1String("Format_ARGB32");
        break;
    case QVideoFrame::Format_ARGB32_Premultiplied:
        typeName = QLatin1String("Format_ARGB32_Premultiplied");
        break;
    case QVideoFrame::Format_RGB32:
        typeName = QLatin1String("Format_RGB32");
        break;
    case QVideoFrame::Format_RGB24:
        typeName = QLatin1String("Format_RGB24");
        break;
    case QVideoFrame::Format_RGB565:
        typeName = QLatin1String("Format_RGB565");
        break;
    case QVideoFrame::Format_RGB555:
        typeName = QLatin1String("Format_RGB555");
        break;
    case QVideoFrame::Format_ARGB8565_Premultiplied:
        typeName = QLatin1String("Format_ARGB8565_Premultiplied");
        break;
    case QVideoFrame::Format_BGRA32:
        typeName = QLatin1String("Format_BGRA32");
        break;
    case QVideoFrame::Format_BGRA32_Premultiplied:
        typeName = QLatin1String("Format_BGRA32_Premultiplied");
        break;
    case QVideoFrame::Format_BGR32:
        typeName = QLatin1String("Format_BGR32");
        break;
    case QVideoFrame::Format_BGR24:
        typeName = QLatin1String("Format_BGR24");
        break;
    case QVideoFrame::Format_BGR565:
        typeName = QLatin1String("Format_BGR565");
        break;
    case QVideoFrame::Format_BGR555:
        typeName = QLatin1String("Format_BGR555");
        break;
    case QVideoFrame::Format_BGRA5658_Premultiplied:
        typeName = QLatin1String("Format_BGRA5658_Premultiplied");
        break;
    case QVideoFrame::Format_AYUV444:
        typeName = QLatin1String("Format_AYUV444");
        break;
    case QVideoFrame::Format_AYUV444_Premultiplied:
        typeName = QLatin1String("Format_AYUV444_Premultiplied");
        break;
    case QVideoFrame::Format_YUV444:
        typeName = QLatin1String("Format_YUV444");
        break;
    case QVideoFrame::Format_YUV420P:
        typeName = QLatin1String("Format_YUV420P");
        break;
    case QVideoFrame::Format_YV12:
        typeName = QLatin1String("Format_YV12");
        break;
    case QVideoFrame::Format_UYVY:
        typeName = QLatin1String("Format_UYVY");
        break;
    case QVideoFrame::Format_YUYV:
        typeName = QLatin1String("Format_YUYV");
        break;
    case QVideoFrame::Format_NV12:
        typeName = QLatin1String("Format_NV12");
        break;
    case QVideoFrame::Format_NV21:
        typeName = QLatin1String("Format_NV21");
        break;
    case QVideoFrame::Format_IMC1:
        typeName = QLatin1String("Format_IMC1");
        break;
    case QVideoFrame::Format_IMC2:
        typeName = QLatin1String("Format_IMC2");
        break;
    case QVideoFrame::Format_IMC3:
        typeName = QLatin1String("Format_IMC3");
        break;
    case QVideoFrame::Format_IMC4:
        typeName = QLatin1String("Format_IMC4");
        break;
    case QVideoFrame::Format_Y8:
        typeName = QLatin1String("Format_Y8");
        break;
    case QVideoFrame::Format_Y16:
        typeName = QLatin1String("Format_Y16");
    default:
        typeName = QString(QLatin1String("UserType(%1)" )).arg(int(f.pixelFormat()));
    }

    dbg.nospace() << "QVideoSurfaceFormat(" << typeName;
    dbg.nospace() << ", " << f.frameSize();
    dbg.nospace() << ", viewport=" << f.viewport();
    dbg.nospace() << ", pixelAspectRatio=" << f.pixelAspectRatio();
    dbg.nospace() << ")";

    foreach(const QByteArray& propertyName, f.propertyNames())
        dbg << "\n    " << propertyName.data() << " = " << f.property(propertyName.data());

    return dbg.space();
}