Commit 9b8b32e4 authored by Brendan Long's avatar Brendan Long
Browse files

Disable video when all video tracks are deselected and disable audio when all...

Disable video when all video tracks are deselected and disable audio when all audio tracks are disabled.
parent bdf05243
2014-11-25 Brendan Long <b.long@cablelabs.com>
[GStreamer] Disable video and/or audio if all tracks are deselected
https://bugs.webkit.org/show_bug.cgi?id=129774
Reviewed by NOBODY (OOPS!).
* platform/graphics/gstreamer/AudioTrackPrivateGStreamer.cpp:
(WebCore::AudioTrackPrivateGStreamer::AudioTrackPrivateGStreamer): Have TrackPrivateBaseGStreamer handle m_playbin.
(WebCore::AudioTrackPrivateGStreamer::setEnabled): Have TrackPrivateBaseGStreamer handle switching streams.
* platform/graphics/gstreamer/AudioTrackPrivateGStreamer.h: Don't need m_playbin or overriding disconnect() anymore.
* platform/graphics/gstreamer/GStreamerUtilities.cpp:
(WebCore::setPlaybinFlag): Added, handles setting playbin flags.
* platform/graphics/gstreamer/GStreamerUtilities.h: Add setPlaybinFlag()
* platform/graphics/gstreamer/InbandTextTrackPrivateGStreamer.cpp:
(WebCore::InbandTextTrackPrivateGStreamer::InbandTextTrackPrivateGStreamer): Handle changed TrackPrivateBaseGStreamer constructor.
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer): Add m_fixingClock to indicate that we paused in response to a GST_MESSSAGE_CLOCK_LOST.
(WebCore::MediaPlayerPrivateGStreamer::handleMessage): Handle GST_MESSAGE_CLOCK_LOST.
(WebCore::MediaPlayerPrivateGStreamer::clockLost): Pause and set m_fixingClock so we'll restart.
(WebCore::MediaPlayerPrivateGStreamer::updateStates): Restart playback if we paused to fix the clock.
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h: Add clockLost() and m_clockLost.
* platform/graphics/gstreamer/TrackPrivateBaseGStreamer.cpp:
(WebCore::TrackPrivateBaseGStreamer::TrackPrivateBaseGStreamer): Handle m_playbin for children.
(WebCore::TrackPrivateBaseGStreamer::disconnect): Clear m_playbin.
(WebCore::TrackPrivateBaseGStreamer::setEnabled): Sets current audio or video stream.
* platform/graphics/gstreamer/TrackPrivateBaseGStreamer.h: Add m_playbin and functions above.
* platform/graphics/gstreamer/VideoTrackPrivateGStreamer.cpp:
(WebCore::VideoTrackPrivateGStreamer::VideoTrackPrivateGStreamer): Have TrackPrivateBaseGStreamer handle m_playbin.
(WebCore::VideoTrackPrivateGStreamer::setSelected): Have TrackPrivateBaseGStreamer handle switching streams.
* platform/graphics/gstreamer/VideoTrackPrivateGStreamer.h: Don't need m_playbin or overriding disconnect() anymore.
2014-11-24 Joanmarie Diggs <jdiggs@igalia.com>
 
AX: [ATK] Unskip the skipped ATK tests in roles-exposed.html
......
......@@ -34,26 +34,17 @@
namespace WebCore {
AudioTrackPrivateGStreamer::AudioTrackPrivateGStreamer(GRefPtr<GstElement> playbin, gint index, GRefPtr<GstPad> pad)
: TrackPrivateBaseGStreamer(this, index, pad)
, m_playbin(playbin)
: TrackPrivateBaseGStreamer(this, playbin, index, pad)
{
notifyTrackOfActiveChanged();
}
void AudioTrackPrivateGStreamer::disconnect()
{
m_playbin.clear();
TrackPrivateBaseGStreamer::disconnect();
}
void AudioTrackPrivateGStreamer::setEnabled(bool enabled)
{
if (enabled == this->enabled())
return;
AudioTrackPrivate::setEnabled(enabled);
if (enabled && m_playbin)
g_object_set(m_playbin.get(), "current-audio", m_index, NULL);
TrackPrivateBaseGStreamer::setEnabled("audio", "current-audio", enabled);
}
} // namespace WebCore
......
......@@ -41,8 +41,6 @@ public:
return adoptRef(new AudioTrackPrivateGStreamer(playbin, index, pad));
}
virtual void disconnect() override;
virtual void setEnabled(bool) override;
virtual void setActive(bool enabled) override { setEnabled(enabled); }
......@@ -53,8 +51,6 @@ public:
private:
AudioTrackPrivateGStreamer(GRefPtr<GstElement> playbin, gint index, GRefPtr<GstPad>);
GRefPtr<GstElement> m_playbin;
};
} // namespace WebCore
......
......@@ -159,6 +159,24 @@ GstClockTime toGstClockTime(float time)
return GST_TIMEVAL_TO_TIME(timeValue);
}
void setPlaybinFlag(GstElement* playbin, const char* flagName, bool value)
{
unsigned flag = getGstPlayFlag(flagName);
unsigned flags;
g_object_get(playbin, "flags", &flags, nullptr);
if (value == static_cast<bool>(flags & flag))
return;
if (value)
flags |= flag;
else
flags &= ~flag;
g_object_set(playbin, "flags", flags, nullptr);
}
}
#endif // USE(GSTREAMER)
......@@ -74,5 +74,6 @@ void unmapGstBuffer(GstBuffer*);
bool initializeGStreamer();
unsigned getGstPlayFlag(const char* nick);
GstClockTime toGstClockTime(float time);
void setPlaybinFlag(GstElement* playbin, const char* flagName, bool value);
}
......@@ -53,7 +53,7 @@ static GstPadProbeReturn textTrackPrivateEventCallback(GstPad*, GstPadProbeInfo*
}
InbandTextTrackPrivateGStreamer::InbandTextTrackPrivateGStreamer(gint index, GRefPtr<GstPad> pad)
: InbandTextTrackPrivate(WebVTT), TrackPrivateBaseGStreamer(this, index, pad)
: InbandTextTrackPrivate(WebVTT), TrackPrivateBaseGStreamer(this, nullptr, index, pad)
{
m_eventProbe = gst_pad_add_probe(m_pad.get(), GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM,
reinterpret_cast<GstPadProbeCallback>(textTrackPrivateEventCallback), this, 0);
......
......@@ -189,6 +189,7 @@ MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer(MediaPlayer* player)
, m_mediaLocationCurrentIndex(0)
, m_resetPipeline(false)
, m_paused(true)
, m_fixingClock(false)
, m_playbackRatePause(false)
, m_seeking(false)
, m_seekIsPending(false)
......@@ -952,6 +953,9 @@ gboolean MediaPlayerPrivateGStreamer::handleMessage(GstMessage* message)
if (issueError)
loadingFailed(error);
break;
case GST_MESSAGE_CLOCK_LOST:
clockLost();
break;
case GST_MESSAGE_EOS:
didEnd();
break;
......@@ -1023,6 +1027,12 @@ gboolean MediaPlayerPrivateGStreamer::handleMessage(GstMessage* message)
return TRUE;
}
void MediaPlayerPrivateGStreamer::clockLost()
{
m_fixingClock = true;
changePipelineState(GST_STATE_PAUSED);
}
void MediaPlayerPrivateGStreamer::handlePluginInstallerResult(GstInstallPluginsReturn result)
{
m_missingPlugins = false;
......@@ -1411,8 +1421,11 @@ void MediaPlayerPrivateGStreamer::updateStates()
notifyPlayerOfMute();
m_volumeAndMuteInitialized = true;
}
if (didBuffering && !m_buffering && !m_paused && m_playbackRate) {
if (m_fixingClock) {
LOG_MEDIA_MESSAGE("[Clock Changed] Restarting playback.");
m_fixingClock = false;
changePipelineState(GST_STATE_PLAYING);
} else if (didBuffering && !m_buffering && !m_paused && m_playbackRate) {
LOG_MEDIA_MESSAGE("[Buffering] Restarting playback.");
changePipelineState(GST_STATE_PLAYING);
}
......
......@@ -148,6 +148,7 @@ private:
bool loadNextLocation();
void mediaLocationChanged(GstMessage*);
void clockLost();
void setDownloadBuffering();
void processBufferingStats(GstMessage*);
#if ENABLE(VIDEO_TRACK) && USE(GSTREAMER_MPEGTS)
......@@ -182,6 +183,7 @@ private:
int m_mediaLocationCurrentIndex;
bool m_resetPipeline;
bool m_paused;
bool m_fixingClock;
bool m_playbackRatePause;
bool m_seeking;
bool m_seekIsPending;
......
......@@ -53,9 +53,10 @@ static void trackPrivateTagsChangedCallback(GObject*, GParamSpec*, TrackPrivateB
track->tagsChanged();
}
TrackPrivateBaseGStreamer::TrackPrivateBaseGStreamer(TrackPrivateBase* owner, gint index, GRefPtr<GstPad> pad)
TrackPrivateBaseGStreamer::TrackPrivateBaseGStreamer(TrackPrivateBase* owner, GRefPtr<GstElement> playbin, gint index, GRefPtr<GstPad> pad)
: m_index(index)
, m_pad(pad)
, m_playbin(playbin)
, m_owner(owner)
{
ASSERT(m_pad);
......@@ -86,10 +87,27 @@ void TrackPrivateBaseGStreamer::disconnect()
m_activeTimerHandler.cancel();
m_tagTimerHandler.cancel();
m_playbin.clear();
m_pad.clear();
m_tags.clear();
}
void TrackPrivateBaseGStreamer::setEnabled(const char* flagName, const char* currentStreamProperty, bool enabled)
{
if (!m_playbin)
return;
if (enabled) {
g_object_set(m_playbin.get(), currentStreamProperty, m_index, nullptr);
setPlaybinFlag(m_playbin.get(), flagName, true);
} else {
int currentStream;
g_object_get(m_playbin.get(), currentStreamProperty, &currentStream, nullptr);
if (currentStream == m_index)
setPlaybinFlag(m_playbin.get(), flagName, false);
}
}
void TrackPrivateBaseGStreamer::activeChanged()
{
m_activeTimerHandler.schedule("[WebKit] TrackPrivateBaseGStreamer::notifyTrackOfActiveChanged", std::function<void()>(std::bind(&TrackPrivateBaseGStreamer::notifyTrackOfActiveChanged, this)));
......
......@@ -56,12 +56,14 @@ public:
void notifyTrackOfTagsChanged();
protected:
TrackPrivateBaseGStreamer(TrackPrivateBase* owner, gint index, GRefPtr<GstPad>);
TrackPrivateBaseGStreamer(TrackPrivateBase* owner, GRefPtr<GstElement> playbin, gint index, GRefPtr<GstPad>);
void setEnabled(const char* flagName, const char* currentStreamProperty, bool enabled);
gint m_index;
AtomicString m_label;
AtomicString m_language;
GRefPtr<GstPad> m_pad;
GRefPtr<GstElement> m_playbin;
private:
bool getLanguageCode(GstTagList* tags, AtomicString& value);
......
......@@ -34,26 +34,17 @@
namespace WebCore {
VideoTrackPrivateGStreamer::VideoTrackPrivateGStreamer(GRefPtr<GstElement> playbin, gint index, GRefPtr<GstPad> pad)
: TrackPrivateBaseGStreamer(this, index, pad)
, m_playbin(playbin)
: TrackPrivateBaseGStreamer(this, playbin, index, pad)
{
notifyTrackOfActiveChanged();
}
void VideoTrackPrivateGStreamer::disconnect()
{
m_playbin.clear();
TrackPrivateBaseGStreamer::disconnect();
}
void VideoTrackPrivateGStreamer::setSelected(bool selected)
{
if (selected == this->selected())
return;
VideoTrackPrivate::setSelected(selected);
if (selected && m_playbin)
g_object_set(m_playbin.get(), "current-video", m_index, NULL);
TrackPrivateBaseGStreamer::setEnabled("video", "current-video", selected);
}
} // namespace WebCore
......
......@@ -41,8 +41,6 @@ public:
return adoptRef(new VideoTrackPrivateGStreamer(playbin, index, pad));
}
virtual void disconnect() override;
virtual void setSelected(bool) override;
virtual void setActive(bool enabled) override { setSelected(enabled); }
......@@ -53,8 +51,6 @@ public:
private:
VideoTrackPrivateGStreamer(GRefPtr<GstElement> playbin, gint index, GRefPtr<GstPad>);
GRefPtr<GstElement> m_playbin;
};
} // namespace WebCore
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment