: m_surface(surface)
, m_pool(0)
, m_renderReturn(GST_FLOW_ERROR)
- , m_lastPrerolledBuffer(0)
, m_bytesPerLine(0)
, m_startCanceled(false)
{
QVideoSurfaceGstDelegate::~QVideoSurfaceGstDelegate()
{
- setLastPrerolledBuffer(0);
}
QList<QVideoFrame::PixelFormat> QVideoSurfaceGstDelegate::supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const
return m_renderReturn;
}
-void QVideoSurfaceGstDelegate::setLastPrerolledBuffer(GstBuffer *prerolledBuffer)
-{
- // discard previously stored buffer
- if (m_lastPrerolledBuffer) {
- gst_buffer_unref(m_lastPrerolledBuffer);
- m_lastPrerolledBuffer = 0;
- }
-
- if (!prerolledBuffer)
- return;
-
- // store a reference to the buffer
- Q_ASSERT(!m_lastPrerolledBuffer);
- m_lastPrerolledBuffer = prerolledBuffer;
- gst_buffer_ref(m_lastPrerolledBuffer);
-}
-
void QVideoSurfaceGstDelegate::queuedStart()
{
if (!m_startCanceled) {
sink->delegate = new QVideoSurfaceGstDelegate(surface);
- g_signal_connect(G_OBJECT(sink), "notify::show-preroll-frame", G_CALLBACK(handleShowPrerollChange), sink);
-
return sink;
}
sink_parent_class = reinterpret_cast<GstVideoSinkClass *>(g_type_class_peek_parent(g_class));
+ GstVideoSinkClass *video_sink_class = reinterpret_cast<GstVideoSinkClass *>(g_class);
+ video_sink_class->show_frame = QVideoSurfaceGstSink::show_frame;
+
GstBaseSinkClass *base_sink_class = reinterpret_cast<GstBaseSinkClass *>(g_class);
base_sink_class->get_caps = QVideoSurfaceGstSink::get_caps;
base_sink_class->set_caps = QVideoSurfaceGstSink::set_caps;
base_sink_class->buffer_alloc = QVideoSurfaceGstSink::buffer_alloc;
base_sink_class->start = QVideoSurfaceGstSink::start;
base_sink_class->stop = QVideoSurfaceGstSink::stop;
- // base_sink_class->unlock = QVideoSurfaceGstSink::unlock; // Not implemented.
- base_sink_class->event = QVideoSurfaceGstSink::event;
- base_sink_class->preroll = QVideoSurfaceGstSink::preroll;
- base_sink_class->render = QVideoSurfaceGstSink::render;
GstElementClass *element_class = reinterpret_cast<GstElementClass *>(g_class);
element_class->change_state = QVideoSurfaceGstSink::change_state;
}
}
-void QVideoSurfaceGstSink::handleShowPrerollChange(GObject *o, GParamSpec *p, gpointer d)
-{
- Q_UNUSED(o);
- Q_UNUSED(p);
- QVideoSurfaceGstSink *sink = reinterpret_cast<QVideoSurfaceGstSink *>(d);
-
- gboolean value = true; // "show-preroll-frame" property is true by default
- g_object_get(G_OBJECT(sink), "show-preroll-frame", &value, NULL);
-
- GstBuffer *buffer = sink->delegate->lastPrerolledBuffer();
- // Render the stored prerolled buffer if requested.
- // e.g. player is in stopped mode, then seek operation is requested,
- // surface now stores a prerolled frame, but doesn't display it until
- // "show-preroll-frame" property is set to "true"
- // when switching to pause or playing state.
- if (value && buffer) {
- sink->delegate->render(buffer);
- sink->delegate->setLastPrerolledBuffer(0);
- }
-}
-
GstFlowReturn QVideoSurfaceGstSink::buffer_alloc(
GstBaseSink *base, guint64 offset, guint size, GstCaps *caps, GstBuffer **buffer)
{
return TRUE;
}
-gboolean QVideoSurfaceGstSink::unlock(GstBaseSink *base)
-{
- Q_UNUSED(base);
-
- return TRUE;
-}
-
-gboolean QVideoSurfaceGstSink::event(GstBaseSink *base, GstEvent *event)
-{
- // discard prerolled frame
- if (event->type == GST_EVENT_FLUSH_START) {
- VO_SINK(base);
- sink->delegate->setLastPrerolledBuffer(0);
- }
-
- return TRUE;
-}
-
-GstFlowReturn QVideoSurfaceGstSink::preroll(GstBaseSink *base, GstBuffer *buffer)
-{
- VO_SINK(base);
-
- gboolean value = true; // "show-preroll-frame" property is true by default
- g_object_get(G_OBJECT(base), "show-preroll-frame", &value, NULL);
- if (value) {
- sink->delegate->setLastPrerolledBuffer(0); // discard prerolled buffer
- return sink->delegate->render(buffer); // display frame
- }
-
- // otherwise keep a reference to the buffer to display it later
- sink->delegate->setLastPrerolledBuffer(buffer);
- return GST_FLOW_OK;
-}
-
-GstFlowReturn QVideoSurfaceGstSink::render(GstBaseSink *base, GstBuffer *buffer)
+GstFlowReturn QVideoSurfaceGstSink::show_frame(GstVideoSink *base, GstBuffer *buffer)
{
VO_SINK(base);
- sink->delegate->setLastPrerolledBuffer(0); // discard prerolled buffer
return sink->delegate->render(buffer);
}
, m_currentState(QMediaPlayer::StoppedState)
, m_mediaStatus(QMediaPlayer::NoMedia)
, m_bufferProgress(-1)
- , m_seekToStartPending(false)
, m_pendingSeekPosition(-1)
, m_setMediaPending(false)
, m_stream(0)
Q_ASSERT(m_resources);
connect(m_session, SIGNAL(positionChanged(qint64)),
- this, SLOT(updatePosition(qint64)));
+ this, SIGNAL(positionChanged(qint64)));
connect(m_session, SIGNAL(durationChanged(qint64)),
this, SIGNAL(durationChanged(qint64)));
connect(m_session, SIGNAL(mutedStateChanged(bool)),
this, SLOT(handleInvalidMedia()));
connect(m_session, SIGNAL(playbackRateChanged(qreal)),
this, SIGNAL(playbackRateChanged(qreal)));
- connect(m_session, SIGNAL(seekableChanged(bool)),
- this, SLOT(applyPendingSeek(bool)));
connect(m_resources, SIGNAL(resourcesGranted()), SLOT(handleResourcesGranted()));
//denied signal should be queued to have correct state update process,
qint64 QGstreamerPlayerControl::position() const
{
- return m_seekToStartPending ? 0 : m_session->position();
+ return m_pendingSeekPosition != -1 ? m_pendingSeekPosition : m_session->position();
}
qint64 QGstreamerPlayerControl::duration() const
if (m_mediaStatus == QMediaPlayer::EndOfMedia) {
m_mediaStatus = QMediaPlayer::LoadedMedia;
- m_seekToStartPending = true;
}
- if (m_session->isSeekable() && m_session->seek(pos)) {
- m_seekToStartPending = false;
- } else {
+ if (m_currentState == QMediaPlayer::StoppedState) {
m_pendingSeekPosition = pos;
- //don't display the first video frame since it's not what user requested.
- m_session->showPrerollFrames(false);
+ emit positionChanged(m_pendingSeekPosition);
+ } else if (m_session->isSeekable()) {
+ m_session->showPrerollFrames(true);
+ m_session->seek(pos);
+ m_pendingSeekPosition = -1;
+ } else if (m_session->state() == QMediaPlayer::StoppedState) {
+ m_pendingSeekPosition = pos;
+ emit positionChanged(m_pendingSeekPosition);
+ } else if (m_pendingSeekPosition != -1) {
+ m_pendingSeekPosition = -1;
+ emit positionChanged(m_pendingSeekPosition);
}
popAndNotifyState();
}
#endif
+ if (m_mediaStatus == QMediaPlayer::EndOfMedia && m_pendingSeekPosition == -1) {
+ m_pendingSeekPosition = 0;
+ }
+
if (!m_resources->isGranted())
m_resources->acquire();
if (m_resources->isGranted()) {
- if (m_seekToStartPending) {
+ // show prerolled frame if switching from stopped state
+ if (m_pendingSeekPosition == -1) {
+ m_session->showPrerollFrames(true);
+ } else if (m_session->state() == QMediaPlayer::StoppedState) {
+ // Don't evaluate the next two conditions.
+ } else if (m_session->isSeekable()) {
m_session->pause();
- if (!m_session->seek(0)) {
- m_bufferProgress = -1;
- m_session->stop();
- m_mediaStatus = QMediaPlayer::LoadingMedia;
- }
- m_seekToStartPending = false;
+ m_session->showPrerollFrames(true);
+ m_session->seek(m_pendingSeekPosition);
+ m_pendingSeekPosition = -1;
+ } else {
+ m_pendingSeekPosition = -1;
}
bool ok = false;
- // show prerolled frame if switching from stopped state
- if (newState != QMediaPlayer::StoppedState && m_currentState == QMediaPlayer::StoppedState && m_pendingSeekPosition == -1)
- m_session->showPrerollFrames(true);
-
//To prevent displaying the first video frame when playback is resumed
//the pipeline is paused instead of playing, seeked to requested position,
//and after seeking is finished (position updated) playback is restarted
m_session->pause();
if (m_mediaStatus != QMediaPlayer::EndOfMedia) {
- m_seekToStartPending = true;
+ m_pendingSeekPosition = 0;
emit positionChanged(position());
}
}
m_currentState = QMediaPlayer::StoppedState;
QMediaContent oldMedia = m_currentResource;
- m_pendingSeekPosition = -1;
+ m_pendingSeekPosition = 0;
m_session->showPrerollFrames(false); // do not show prerolled frames until pause() or play() explicitly called
m_setMediaPending = false;
m_currentResource = content;
m_stream = stream;
- m_seekToStartPending = false;
QNetworkRequest request;
{
pushState();
- if (state == QMediaPlayer::StoppedState)
+ if (state == QMediaPlayer::StoppedState) {
+ m_session->showPrerollFrames(false);
m_currentState = QMediaPlayer::StoppedState;
+ }
+
+ if (state == QMediaPlayer::PausedState && m_currentState != QMediaPlayer::StoppedState) {
+ if (m_pendingSeekPosition != -1 && m_session->isSeekable()) {
+ m_session->showPrerollFrames(true);
+ m_session->seek(m_pendingSeekPosition);
+ }
+ m_pendingSeekPosition = -1;
+
+ if (m_currentState == QMediaPlayer::PlayingState)
+ m_session->play();
+ }
updateMediaStatus();
m_mediaStatus = QMediaPlayer::EndOfMedia;
emit positionChanged(position());
m_session->endOfMediaReset();
- m_setMediaPending = true;
if (m_currentState != QMediaPlayer::StoppedState) {
m_currentState = QMediaPlayer::StoppedState;
emit bufferStatusChanged(m_bufferProgress);
}
-void QGstreamerPlayerControl::applyPendingSeek(bool isSeekable)
-{
- if (isSeekable && m_pendingSeekPosition != -1)
- setPosition(m_pendingSeekPosition);
-}
-
void QGstreamerPlayerControl::handleInvalidMedia()
{
pushState();
m_mediaStatus = QMediaPlayer::InvalidMedia;
m_currentState = QMediaPlayer::StoppedState;
+ m_setMediaPending = true;
popAndNotifyState();
}
}
}
-void QGstreamerPlayerControl::updatePosition(qint64 pos)
-{
-#ifdef DEBUG_PLAYBIN
- qDebug() << Q_FUNC_INFO << pos/1000.0 << "pending:" << m_pendingSeekPosition/1000.0;
-#endif
-
- if (m_pendingSeekPosition != -1) {
- //seek request is complete, it's safe to resume playback
- //with prerolled frame displayed
- m_pendingSeekPosition = -1;
- if (m_currentState != QMediaPlayer::StoppedState)
- m_session->showPrerollFrames(true);
- if (m_currentState == QMediaPlayer::PlayingState) {
- m_session->play();
- }
- }
-
- emit positionChanged(pos);
-}
-
QT_END_NAMESPACE