Ejemplo n.º 1
0
PlanetC_VideoPlayer::PlanetC_VideoPlayer(QGraphicsView* p_view)
	: QMediaPlayer(0, QMediaPlayer::VideoSurface)
{
	posX = 0;
	posY = 0;
	sizeW = 100;
	sizeH = 100;
	rotationAngle = 0.;

	//Create a QGraphicsVideoItem object to display the videow
	video = new QGraphicsVideoItem();
	video->setVisible(true);
	video->setAspectRatioMode(Qt::KeepAspectRatio);

	//Add QGraphicsVideoItem object to the main scene
	view = p_view;
	view->scene()->addItem(video);

	//Connect the player to the video item
	setVideoOutput(video);
	video->setVisible(true);

	//Once geometry properties are available (width, height) set the GraphicsVideoItem geometry
	connect(this, SIGNAL(metaDataChanged(QString,QVariant)), this, SLOT(setOptions(QString,QVariant)));
}
QMediaControl *DirectShowPlayerService::requestControl(const char *name)
{
    if (qstrcmp(name, QMediaPlayerControl_iid) == 0) {
        return m_playerControl;
    } else if (qstrcmp(name, QAudioEndpointSelector_iid) == 0) {
        return m_audioEndpointControl;
    } else if (qstrcmp(name, QMetaDataReaderControl_iid) == 0) {
        return m_metaDataControl;
    } else if (qstrcmp(name, QVideoRendererControl_iid) == 0) {
        if (!m_videoRendererControl && !m_videoWindowControl) {
            m_videoRendererControl = new DirectShowVideoRendererControl(m_loop);

            connect(m_videoRendererControl, SIGNAL(filterChanged()),
                    this, SLOT(videoOutputChanged()));

            return m_videoRendererControl;
        }
    } else if (qstrcmp(name, QVideoWindowControl_iid) == 0) {
        if (!m_videoRendererControl && !m_videoWindowControl) {
            m_videoWindowControl = new Vmr9VideoWindowControl;

            setVideoOutput(m_videoWindowControl->filter());

            return m_videoWindowControl;
        }
    }
    return 0;
}
void DirectShowPlayerService::releaseControl(QMediaControl *control)
{
    if (!control) {
        qWarning("QMediaService::releaseControl():"
                " Attempted release of null control");
    } else if (control == m_videoRendererControl) {
        setVideoOutput(0);

        delete m_videoRendererControl;

        m_videoRendererControl = 0;
    } else if (control == m_videoWindowControl) {
        setVideoOutput(0);

        delete m_videoWindowControl;

        m_videoWindowControl = 0;
    }
}
Ejemplo n.º 4
0
int QMPwidget::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 21)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 21;
    } else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
        if (_id < 21)
            *reinterpret_cast<int*>(_a[0]) = -1;
        _id -= 21;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< State*>(_v) = state(); break;
        case 1: *reinterpret_cast< double*>(_v) = tell(); break;
        case 2: *reinterpret_cast< QString*>(_v) = videoOutput(); break;
        case 3: *reinterpret_cast< QString*>(_v) = mplayerPath(); break;
        case 4: *reinterpret_cast< QString*>(_v) = mplayerVersion(); break;
        }
        _id -= 5;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 2: setVideoOutput(*reinterpret_cast< QString*>(_v)); break;
        case 3: setMPlayerPath(*reinterpret_cast< QString*>(_v)); break;
        }
        _id -= 5;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 5;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 5;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 5;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 5;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 5;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 5;
    } else if (_c == QMetaObject::RegisterPropertyMetaType) {
        if (_id < 5)
            *reinterpret_cast<int*>(_a[0]) = -1;
        _id -= 5;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
QMediaControl *DirectShowPlayerService::requestControl(const char *name)
{
    if (qstrcmp(name, QMediaPlayerControl_iid) == 0) {
        return m_playerControl;
    } else if (qstrcmp(name, QAudioEndpointSelector_iid) == 0) {
        return m_audioEndpointControl;
    } else if (qstrcmp(name, QMetaDataReaderControl_iid) == 0) {
        return m_metaDataControl;
    } else if (qstrcmp(name, QVideoRendererControl_iid) == 0) {
#ifndef Q_WS_SIMULATOR
        if (!m_videoRendererControl && !m_videoWindowControl) {
#else
        if (!m_videoRendererControl) {
#endif
            m_videoRendererControl = new DirectShowVideoRendererControl(m_loop);

            connect(m_videoRendererControl, SIGNAL(filterChanged()),
                    this, SLOT(videoOutputChanged()));

            return m_videoRendererControl;
        }
#ifndef Q_WS_SIMULATOR
    } else if (qstrcmp(name, QVideoWindowControl_iid) == 0) {
        if (!m_videoRendererControl && !m_videoWindowControl) {
            m_videoWindowControl = new Vmr9VideoWindowControl;

            setVideoOutput(m_videoWindowControl->filter());

            return m_videoWindowControl;
        }
#endif
    }
    return 0;
}

void DirectShowPlayerService::releaseControl(QMediaControl *control)
{
    if (!control) {
        qWarning("QMediaService::releaseControl():"
                " Attempted release of null control");
    } else if (control == m_videoRendererControl) {
        setVideoOutput(0);

        delete m_videoRendererControl;

        m_videoRendererControl = 0;
#ifndef Q_WS_SIMULATOR
    } else if (control == m_videoWindowControl) {
        setVideoOutput(0);

        delete m_videoWindowControl;

        m_videoWindowControl = 0;
#endif
    }
}

void DirectShowPlayerService::load(const QMediaContent &media, QIODevice *stream)
{
    QMutexLocker locker(&m_mutex);

    m_pendingTasks = 0;

    if (m_graph)
        releaseGraph();

    m_resources = media.resources();
    m_stream = stream;
    m_error = QMediaPlayer::NoError;
    m_errorString = QString();
    m_position = 0;
    m_duration = 0;
    m_streamTypes = 0;
    m_executedTasks = 0;
    m_buffering = false;
    m_seekable = false;
    m_atEnd = false;
    m_metaDataControl->updateGraph(0, 0);

    if (m_resources.isEmpty() && !stream) {
        m_pendingTasks = 0;
        m_graphStatus = NoMedia;

        m_url.clear();
    } else if (stream && (!stream->isReadable() || stream->isSequential())) {
        m_pendingTasks = 0;
        m_graphStatus = InvalidMedia;
        m_error = QMediaPlayer::ResourceError;
    } else {
        // {36b73882-c2c8-11cf-8b46-00805f6cef60}
        static const GUID iid_IFilterGraph2 = {
            0x36b73882, 0xc2c8, 0x11cf, {0x8b, 0x46, 0x00, 0x80, 0x5f, 0x6c, 0xef, 0x60} };
        m_graphStatus = Loading;

        m_graph = com_new<IFilterGraph2>(CLSID_FilterGraph, iid_IFilterGraph2);

        if (stream)
            m_pendingTasks = SetStreamSource;
        else
            m_pendingTasks = SetUrlSource;

        ::SetEvent(m_taskHandle);
    }

    m_playerControl->updateError(m_error, m_errorString);
    m_playerControl->updateMediaInfo(m_duration, m_streamTypes, m_seekable);
    m_playerControl->updateState(QMediaPlayer::StoppedState);
    m_playerControl->updatePosition(m_position);
    updateStatus();
}
void DirectShowPlayerService::videoOutputChanged()
{
    setVideoOutput(m_videoRendererControl->filter());
}