Skip to content
Permalink
Browse files
2010-03-04 Philippe Normand <pnormand@igalia.com>
        Reviewed by Eric Seidel.

        [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/46954@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@55657 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
philn committed Mar 8, 2010
1 parent 3c02351 commit c4af08f3c8438c81afa7107fa859f3cf67247f9c
Showing 3 changed files with 45 additions and 62 deletions.
@@ -1,3 +1,26 @@
2010-03-04 Philippe Normand <pnormand@igalia.com>

Reviewed by Eric Seidel.

[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-07 David Levin <levin@chromium.org>

Chromium Linux build fix.
@@ -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_seeking(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_fillStatus(0)
{
@@ -321,20 +299,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);
@@ -591,7 +557,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);
@@ -600,9 +566,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)
@@ -688,20 +653,20 @@ void MediaPlayerPrivate::processBufferingStats(GstMessage* message)
if (!m_startedBuffering) {
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;
@@ -728,16 +693,15 @@ bool MediaPlayerPrivate::queryBufferingStats()

if (m_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
@@ -759,7 +723,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;
@@ -850,7 +814,7 @@ void MediaPlayerPrivate::updateStates()
m_paused = true;

// Is on-disk buffering in progress?
if (m_fillTimeoutId) {
if (m_fillTimer.isActive()) {
m_networkState = MediaPlayer::Loading;
// Buffering has just started, we should now have enough
// data to restart playback if it was internally paused by
@@ -1114,7 +1078,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);
@@ -1123,10 +1087,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)
@@ -80,15 +80,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;
@@ -160,11 +160,9 @@ class MediaPlayerPrivate : public MediaPlayerPrivateInterface {
bool m_seeking;
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;
gdouble m_fillStatus;
};

0 comments on commit c4af08f

Please sign in to comment.