Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
gstreamer - better error checking, set QtopiaMedia::Stopped in stop
QtopiaMedia::Stopped was only emited on EOS, but it was never set
after calling stop() function.

This left our session in SessionManagerPrivate::activeSessions and
the power manager refused to suspend.
  • Loading branch information
radekp committed Nov 11, 2012
1 parent 92e7beb commit b9b8946
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 30 deletions.
83 changes: 54 additions & 29 deletions src/plugins/mediaengines/gstreamer/gstreamerplaybinsession.cpp
Expand Up @@ -17,8 +17,6 @@
**
****************************************************************************/

#include <gst/gst.h>

#include <QDebug>
#include <QVideoSurface>
#include <QMediaVideoControlServer>
Expand Down Expand Up @@ -122,35 +120,75 @@ bool PlaybinSession::isValid() const
return true;
}

static const char *qtStateName(QtopiaMedia::State state)
{
switch(state)
{
case QtopiaMedia::Playing: return "playing";
case QtopiaMedia::Paused: return "paused";
case QtopiaMedia::Stopped: return "stopped";
case QtopiaMedia::Buffering: return "buffering";
case QtopiaMedia::Error: return "error";
default: return "???";
}
}

// Set QtopiaMedia state
void PlaybinSession::setQtState(QtopiaMedia::State state)
{
if(state == d->state)
return;

#if DEBUG_SESSION
qDebug() << "PlaybinSession::setQtState " << qtStateName(d->state) << "->" << qtStateName(state);
#endif

d->state = state;
emit playerStateChanged(state);
}

// Set gst playbin element state
bool PlaybinSession::setGstState(GstState state)
{
#if DEBUG_SESSION
qDebug() << "PlaybinSession::setGstState " << gst_element_state_get_name(state);
#endif

if(d->playbin == 0)
return false;

if(gst_element_set_state(d->playbin, state) != GST_STATE_CHANGE_FAILURE)
return true;

qWarning() << "setGstState failed, state=" << gst_element_state_get_name(state) << ", url=" << d->url.toString();
emit playerStateChanged(QtopiaMedia::Error);
return false;
}


void PlaybinSession::start()
{
#if DEBUG_SESSION
qDebug() << "PlaybinSession::start()";
#endif
if (d->playbin != 0) {
if (gst_element_set_state(d->playbin, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
qWarning() << "GStreamer; Unable to play -" << d->url.toString();
emit playerStateChanged(QtopiaMedia::Error);
}
}
setGstState(GST_STATE_PLAYING);
}

void PlaybinSession::pause()
{
#if DEBUG_SESSION
qDebug() << "PlaybinSession::pause()";
#endif
if (d->playbin != 0)
gst_element_set_state(d->playbin, GST_STATE_PAUSED);
setGstState(GST_STATE_PAUSED);
}

void PlaybinSession::stop()
{
#if DEBUG_SESSION
qDebug() << "PlaybinSession::stop()";
#endif
if (d->playbin != 0)
gst_element_set_state(d->playbin, GST_STATE_NULL);
#endif
if(setGstState(GST_STATE_NULL))
setQtState(QtopiaMedia::Stopped);
}

void PlaybinSession::suspend()
Expand Down Expand Up @@ -326,7 +364,7 @@ void PlaybinSession::busMessage(Message const& msg)
case GST_STATE_READY:
break;
case GST_STATE_PAUSED:
changeState(QtopiaMedia::Paused);
setQtState(QtopiaMedia::Paused);

if ( d->jumpPosition ) {
gst_element_seek_simple(d->playbin, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, d->jumpPosition );
Expand All @@ -337,14 +375,14 @@ void PlaybinSession::busMessage(Message const& msg)
if (oldState == GST_STATE_PAUSED)
getStreamsInfo();

changeState(QtopiaMedia::Playing);
setQtState(QtopiaMedia::Playing);
break;
}
}
break;

case GST_MESSAGE_EOS:
changeState(QtopiaMedia::Stopped);
setQtState(QtopiaMedia::Stopped);
break;

case GST_MESSAGE_STREAM_STATUS:
Expand Down Expand Up @@ -458,19 +496,6 @@ void PlaybinSession::getStreamsInfo()
}
}

void PlaybinSession::changeState(QtopiaMedia::State state)
{
if(state == d->state)
return;

#if DEBUG_SESSION
qDebug() << "PlaybinSession::changeState " << d->state << "->" << state;
#endif

d->state = state;
emit playerStateChanged(state);
}

void PlaybinSession::readySession()
{
d->playbin = gst_element_factory_make("playbin", NULL);
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/mediaengines/gstreamer/gstreamerplaybinsession.h
Expand Up @@ -24,6 +24,8 @@
#include <QUuid>
#include <QMediaServerSession>

#include <gst/gst.h>

namespace gstreamer
{

Expand Down Expand Up @@ -78,7 +80,8 @@ private slots:
private:
void getStreamsInfo();
void readySession();
void changeState(QtopiaMedia::State);
void setQtState(QtopiaMedia::State);
bool setGstState(GstState);

PlaybinSessionPrivate* d;
};
Expand Down

0 comments on commit b9b8946

Please sign in to comment.