Skip to content
Permalink
Browse files
2010-03-15 Philippe Normand <pnormand@igalia.com>
        Reviewed by Gustavo Noronha Silva.

        [GStreamer] replace g_idle_add / g_timeout_add calls with Timers in the gstreamer player
        https://bugs.webkit.org/show_bug.cgi?id=35735

        Replaced g_idle_add calls with Timers immediately started once
        only. The g_timeout_add was replaced by a periodic Timer.

        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
        (WebCore::MediaPlayerPrivate::MediaPlayerPrivate):
        (WebCore::MediaPlayerPrivate::~MediaPlayerPrivate):
        (WebCore::MediaPlayerPrivate::volumeChangedTimerFired):
        (WebCore::MediaPlayerPrivate::volumeChanged):
        (WebCore::MediaPlayerPrivate::processBufferingStats):
        (WebCore::MediaPlayerPrivate::fillTimerFired):
        (WebCore::MediaPlayerPrivate::maxTimeLoaded):
        (WebCore::MediaPlayerPrivate::updateStates):
        (WebCore::MediaPlayerPrivate::muteChangedTimerFired):
        (WebCore::MediaPlayerPrivate::muteChanged):
        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h:

Canonical link: https://commits.webkit.org/47291@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@55996 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
philn committed Mar 15, 2010
1 parent 037797e commit f8cf3236c8a17651b9d102b56cd8d562a870005f
Showing 3 changed files with 45 additions and 63 deletions.
@@ -1,3 +1,26 @@
2010-03-15 Philippe Normand <pnormand@igalia.com>

Reviewed by Gustavo Noronha Silva.

[GStreamer] replace g_idle_add / g_timeout_add calls with Timers in the gstreamer player
https://bugs.webkit.org/show_bug.cgi?id=35735

Replaced g_idle_add calls with Timers immediately started once
only. The g_timeout_add was replaced by a periodic Timer.

* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivate::MediaPlayerPrivate):
(WebCore::MediaPlayerPrivate::~MediaPlayerPrivate):
(WebCore::MediaPlayerPrivate::volumeChangedTimerFired):
(WebCore::MediaPlayerPrivate::volumeChanged):
(WebCore::MediaPlayerPrivate::processBufferingStats):
(WebCore::MediaPlayerPrivate::fillTimerFired):
(WebCore::MediaPlayerPrivate::maxTimeLoaded):
(WebCore::MediaPlayerPrivate::updateStates):
(WebCore::MediaPlayerPrivate::muteChangedTimerFired):
(WebCore::MediaPlayerPrivate::muteChanged):
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h:

2010-03-12 Gustavo Noronha Silva <gustavo.noronha@collabora.co.uk>

Reviewed by Eric Carlson.
@@ -177,33 +177,13 @@ void mediaPlayerPrivateVolumeChangedCallback(GObject *element, GParamSpec *pspec
mp->volumeChanged();
}

gboolean notifyVolumeIdleCallback(gpointer data)
{
MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(data);
mp->volumeChangedCallback();
return FALSE;
}

void mediaPlayerPrivateMuteChangedCallback(GObject *element, GParamSpec *pspec, gpointer data)
{
// This is called when playbin receives the notify::mute signal.
MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(data);
mp->muteChanged();
}

gboolean notifyMuteIdleCallback(gpointer data)
{
MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(data);
mp->muteChangedCallback();
return FALSE;
}

gboolean bufferingTimeoutCallback(gpointer data)
{
MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(data);
return mp->queryBufferingStats();
}

static float playbackPosition(GstElement* playbin)
{

@@ -307,11 +287,9 @@ MediaPlayerPrivate::MediaPlayerPrivate(MediaPlayer* player)
, m_buffering(false)
, m_playbackRate(1)
, m_errorOccured(false)
, m_volumeIdleId(0)
, m_mediaDuration(0)
, m_muteIdleId(0)
, m_startedBuffering(false)
, m_fillTimeoutId(0)
, m_fillTimer(this, &MediaPlayerPrivate::fillTimerFired)
, m_maxTimeLoaded(0)
, m_bufferingPercentage(0)
, m_preload(MediaPlayer::Auto)
@@ -323,20 +301,8 @@ MediaPlayerPrivate::MediaPlayerPrivate(MediaPlayer* player)

MediaPlayerPrivate::~MediaPlayerPrivate()
{
if (m_fillTimeoutId) {
g_source_remove(m_fillTimeoutId);
m_fillTimeoutId = 0;
}

if (m_volumeIdleId) {
g_source_remove(m_volumeIdleId);
m_volumeIdleId = 0;
}

if (m_muteIdleId) {
g_source_remove(m_muteIdleId);
m_muteIdleId = 0;
}
if (m_fillTimer.isActive())
m_fillTimer.stop();

if (m_buffer)
gst_buffer_unref(m_buffer);
@@ -617,7 +583,7 @@ void MediaPlayerPrivate::setVolume(float volume)
g_object_set(m_playBin, "volume", static_cast<double>(volume), NULL);
}

void MediaPlayerPrivate::volumeChangedCallback()
void MediaPlayerPrivate::volumeChangedTimerFired(Timer<MediaPlayerPrivate>*)
{
double volume;
g_object_get(m_playBin, "volume", &volume, NULL);
@@ -626,9 +592,8 @@ void MediaPlayerPrivate::volumeChangedCallback()

void MediaPlayerPrivate::volumeChanged()
{
if (m_volumeIdleId)
g_source_remove(m_volumeIdleId);
m_volumeIdleId = g_idle_add((GSourceFunc) notifyVolumeIdleCallback, this);
Timer<MediaPlayerPrivate> volumeChangedTimer(this, &MediaPlayerPrivate::volumeChangedTimerFired);
volumeChangedTimer.startOneShot(0);
}

void MediaPlayerPrivate::setRate(float rate)
@@ -727,20 +692,20 @@ void MediaPlayerPrivate::processBufferingStats(GstMessage* message)

m_startedBuffering = true;

if (m_fillTimeoutId > 0)
g_source_remove(m_fillTimeoutId);
if (m_fillTimer.isActive())
m_fillTimer.stop();

m_fillTimeoutId = g_timeout_add(200, (GSourceFunc) bufferingTimeoutCallback, this);
m_fillTimer.startRepeating(0.2);
}
}

bool MediaPlayerPrivate::queryBufferingStats()
void MediaPlayerPrivate::fillTimerFired(Timer<MediaPlayerPrivate>*)
{
GstQuery* query = gst_query_new_buffering(GST_FORMAT_PERCENT);

if (!gst_element_query(m_playBin, query)) {
gst_query_unref(query);
return TRUE;
return;
}

gint64 start, stop;
@@ -766,16 +731,15 @@ bool MediaPlayerPrivate::queryBufferingStats()

if (fillStatus != 100.0) {
updateStates();
return TRUE;
return;
}

// Media is now fully loaded. It will play even if network
// connection is cut. Buffering is done, remove the fill source
// from the main loop.
m_fillTimeoutId = 0;
m_fillTimer.stop();
m_startedBuffering = false;
updateStates();
return FALSE;
}

float MediaPlayerPrivate::maxTimeSeekable() const
@@ -797,7 +761,7 @@ float MediaPlayerPrivate::maxTimeLoaded() const
return 0.0;

float loaded = m_maxTimeLoaded;
if (!loaded && !m_fillTimeoutId)
if (!loaded && !m_fillTimer.isActive())
loaded = duration();
LOG_VERBOSE(Media, "maxTimeLoaded: %f", loaded);
return loaded;
@@ -923,8 +887,7 @@ void MediaPlayerPrivate::updateStates()
m_paused = true;

// Is on-disk buffering in progress?

if (m_fillTimeoutId)
if (m_fillTimer.isActive())
m_networkState = MediaPlayer::Loading;

if (m_changingRate) {
@@ -1166,7 +1129,7 @@ void MediaPlayerPrivate::setMuted(bool muted)
g_object_set(m_playBin, "mute", muted, NULL);
}

void MediaPlayerPrivate::muteChangedCallback()
void MediaPlayerPrivate::muteChangedTimerFired(Timer<MediaPlayerPrivate>*)
{
gboolean muted;
g_object_get(m_playBin, "mute", &muted, NULL);
@@ -1175,10 +1138,8 @@ void MediaPlayerPrivate::muteChangedCallback()

void MediaPlayerPrivate::muteChanged()
{
if (m_muteIdleId)
g_source_remove(m_muteIdleId);

m_muteIdleId = g_idle_add((GSourceFunc) notifyMuteIdleCallback, this);
Timer<MediaPlayerPrivate> muteChangedTimer(this, &MediaPlayerPrivate::muteChangedTimerFired);
muteChangedTimer.startOneShot(0);
}

void MediaPlayerPrivate::loadingFailed(MediaPlayer::NetworkState error)
@@ -82,15 +82,15 @@ class MediaPlayerPrivate : public MediaPlayerPrivateInterface {

void setVolume(float);
void volumeChanged();
void volumeChangedCallback();
void volumeChangedTimerFired(Timer<MediaPlayerPrivate>*);

bool supportsMuting() const;
void setMuted(bool);
void muteChanged();
void muteChangedCallback();
void muteChangedTimerFired(Timer<MediaPlayerPrivate>*);

void setPreload(MediaPlayer::Preload);
bool queryBufferingStats();
void fillTimerFired(Timer<MediaPlayerPrivate>*);

MediaPlayer::NetworkState networkState() const;
MediaPlayer::ReadyState readyState() const;
@@ -162,11 +162,9 @@ class MediaPlayerPrivate : public MediaPlayerPrivateInterface {
bool m_buffering;
float m_playbackRate;
bool m_errorOccured;
guint m_volumeIdleId;
gfloat m_mediaDuration;
guint m_muteIdleId;
bool m_startedBuffering;
guint m_fillTimeoutId;
Timer<MediaPlayerPrivate> m_fillTimer;
float m_maxTimeLoaded;
int m_bufferingPercentage;
MediaPlayer::Preload m_preload;

0 comments on commit f8cf323

Please sign in to comment.