Title: [253748] trunk/Source/WebCore
- Revision
- 253748
- Author
- [email protected]
- Date
- 2019-12-19 05:24:59 -0800 (Thu, 19 Dec 2019)
Log Message
[GStreamer][EME] Notify all elements waiting for CDM attachment
https://bugs.webkit.org/show_bug.cgi?id=205382
Reviewed by Xabier Rodriguez-Calvar.
When multiple demuxers are in flight asking for a CDM instance,
only one of them was getting woken up when a CDM was attached,
leaving the other(s) blocking their respective streaming threads
and locking the pipeline. Switch back to a condition variable from
a semaphore to fix this issue.
Covered by existing tests.
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer):
Initialize the new isPlayerShuttingDown predicate to false.
(WebCore::MediaPlayerPrivateGStreamer::~MediaPlayerPrivateGStreamer):
Set the new predicate for player shutdown at the start of
destruction, so that background threads can known when the should
abort their operations as a result of being unblocked by the
destructor.
(WebCore::MediaPlayerPrivateGStreamer::handleSyncMessage): Go back
to using condition variables, so we can unblock more than one
waiter.
(WebCore::MediaPlayerPrivateGStreamer::cdmInstanceAttached):
Helper predicate to make clear that the presence of a valid
CDMInstance pointer is a sign that it has been attached.
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h: Add
an isPlayerShuttingDown method using an Atomic<bool>. We need this
to avoid racing set_context() on a decryptor element with the
pipeline being set to NULL. Before we were using the notifier as a
proxy for player shutdown, since it is invalidated during player
destruction. This is not a maintainable solution, since other
programmers would feel free to reorder the position at which the
notifier is invalidated, and then introduce a very hard to find
bug. By introducing this flag at the start of destruction, we will
always have a known way to check, after a streaming thread has
woken up again, whether we should call any player methods, or
return early due to shutdown in progress.
(WebCore::MediaPlayerPrivateGStreamer::isPlayerShuttingDown
const): Predicate for player in the process of shutdown. This
should be used by background threads, which upon wakeup, may need
to be aware of whether they will be in a race with the pipeline
going to NULL.
(WebCore::MediaPlayerPrivateGStreamer::isCDMAttached const):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (253747 => 253748)
--- trunk/Source/WebCore/ChangeLog 2019-12-19 12:54:59 UTC (rev 253747)
+++ trunk/Source/WebCore/ChangeLog 2019-12-19 13:24:59 UTC (rev 253748)
@@ -1,3 +1,51 @@
+2019-12-19 Charlie Turner <[email protected]>
+
+ [GStreamer][EME] Notify all elements waiting for CDM attachment
+ https://bugs.webkit.org/show_bug.cgi?id=205382
+
+ Reviewed by Xabier Rodriguez-Calvar.
+
+ When multiple demuxers are in flight asking for a CDM instance,
+ only one of them was getting woken up when a CDM was attached,
+ leaving the other(s) blocking their respective streaming threads
+ and locking the pipeline. Switch back to a condition variable from
+ a semaphore to fix this issue.
+
+ Covered by existing tests.
+
+ * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
+ (WebCore::MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer):
+ Initialize the new isPlayerShuttingDown predicate to false.
+ (WebCore::MediaPlayerPrivateGStreamer::~MediaPlayerPrivateGStreamer):
+ Set the new predicate for player shutdown at the start of
+ destruction, so that background threads can known when the should
+ abort their operations as a result of being unblocked by the
+ destructor.
+ (WebCore::MediaPlayerPrivateGStreamer::handleSyncMessage): Go back
+ to using condition variables, so we can unblock more than one
+ waiter.
+ (WebCore::MediaPlayerPrivateGStreamer::cdmInstanceAttached):
+ Helper predicate to make clear that the presence of a valid
+ CDMInstance pointer is a sign that it has been attached.
+ * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h: Add
+ an isPlayerShuttingDown method using an Atomic<bool>. We need this
+ to avoid racing set_context() on a decryptor element with the
+ pipeline being set to NULL. Before we were using the notifier as a
+ proxy for player shutdown, since it is invalidated during player
+ destruction. This is not a maintainable solution, since other
+ programmers would feel free to reorder the position at which the
+ notifier is invalidated, and then introduce a very hard to find
+ bug. By introducing this flag at the start of destruction, we will
+ always have a known way to check, after a streaming thread has
+ woken up again, whether we should call any player methods, or
+ return early due to shutdown in progress.
+ (WebCore::MediaPlayerPrivateGStreamer::isPlayerShuttingDown
+ const): Predicate for player in the process of shutdown. This
+ should be used by background threads, which upon wakeup, may need
+ to be aware of whether they will be in a race with the pipeline
+ going to NULL.
+ (WebCore::MediaPlayerPrivateGStreamer::isCDMAttached const):
+
2019-12-19 Carlos Garcia Campos <[email protected]>
[CoordinatedGraphics] ThreadedDisplayRefreshMonitor is never released
Modified: trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp (253747 => 253748)
--- trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp 2019-12-19 12:54:59 UTC (rev 253747)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp 2019-12-19 13:24:59 UTC (rev 253748)
@@ -369,11 +369,13 @@
#if USE(GLIB)
m_readyTimerHandler.setPriority(G_PRIORITY_DEFAULT_IDLE);
#endif
+ m_isPlayerShuttingDown.store(false);
}
MediaPlayerPrivateGStreamer::~MediaPlayerPrivateGStreamer()
{
GST_DEBUG_OBJECT(pipeline(), "Disposing player");
+ m_isPlayerShuttingDown.store(true);
#if ENABLE(VIDEO_TRACK)
for (auto& track : m_audioTracks.values())
@@ -443,7 +445,10 @@
cancelRepaint(true);
#if ENABLE(ENCRYPTED_MEDIA)
- m_cdmAttachmentSemaphore.signal();
+ {
+ LockHolder lock(m_cdmAttachmentMutex);
+ m_cdmAttachmentCondition.notifyAll();
+ }
#endif
// The change to GST_STATE_NULL state is always synchronous. So after this gets executed we don't need to worry
@@ -1781,9 +1786,16 @@
initializationDataEncountered(WTFMove(initData));
GST_INFO_OBJECT(pipeline(), "waiting for a CDM instance");
- if (m_cdmAttachmentSemaphore.waitFor(4_s)
- && m_notifier->isValid() // Check the player is not being destroyed.
- && !m_cdmInstance->keySystem().isEmpty()) {
+
+ bool didCDMAttach = false;
+ {
+ auto cdmAttachmentLocker = holdLock(m_cdmAttachmentMutex);
+ didCDMAttach = m_cdmAttachmentCondition.waitFor(m_cdmAttachmentMutex, 4_s, [this]() {
+ return isCDMAttached();
+ });
+ }
+
+ if (didCDMAttach && !isPlayerShuttingDown() && !m_cdmInstance->keySystem().isEmpty()) {
const char* preferredKeySystemUuid = GStreamerEMEUtilities::keySystemToUuid(m_cdmInstance->keySystem());
GST_INFO_OBJECT(pipeline(), "working with key system %s, continuing with key system %s on %s", m_cdmInstance->keySystem().utf8().data(), preferredKeySystemUuid, GST_MESSAGE_SRC_NAME(message));
@@ -3611,7 +3623,9 @@
GST_DEBUG_OBJECT(m_pipeline.get(), "CDM proxy instance %p dispatched as context", m_cdmInstance->proxyCDM().get());
- m_cdmAttachmentSemaphore.signal();
+ LockHolder lock(m_cdmAttachmentMutex);
+ // We must notify all waiters, since several demuxers can be simultaneously waiting for a CDM.
+ m_cdmAttachmentCondition.notifyAll();
}
void MediaPlayerPrivateGStreamer::cdmInstanceDetached(CDMInstance& instance)
Modified: trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h (253747 => 253748)
--- trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h 2019-12-19 12:54:59 UTC (rev 253747)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h 2019-12-19 13:24:59 UTC (rev 253748)
@@ -34,11 +34,11 @@
#include <glib.h>
#include <gst/gst.h>
#include <gst/pbutils/install-plugins.h>
+#include <wtf/Atomics.h>
#include <wtf/Condition.h>
#include <wtf/Forward.h>
#include <wtf/RunLoop.h>
#include <wtf/WeakPtr.h>
-#include <wtf/threads/BinarySemaphore.h>
#if ENABLE(VIDEO_TRACK)
#include "TrackPrivateBaseGStreamer.h"
@@ -369,7 +369,8 @@
ImageOrientation m_videoSourceOrientation;
#if ENABLE(ENCRYPTED_MEDIA)
- BinarySemaphore m_cdmAttachmentSemaphore;
+ Lock m_cdmAttachmentMutex;
+ Condition m_cdmAttachmentCondition;
RefPtr<const CDMInstance> m_cdmInstance;
Lock m_protectionMutex; // Guards access to m_handledProtectionEvents.
@@ -381,6 +382,7 @@
Optional<GstVideoDecoderPlatform> m_videoDecoderPlatform;
private:
+ bool isPlayerShuttingDown() const { return m_isPlayerShuttingDown.load(); }
MediaTime maxTimeLoaded() const;
GstElement* pipeline() const { return m_pipeline.get(); }
void setVideoSourceOrientation(ImageOrientation);
@@ -445,11 +447,13 @@
void clearTracks();
#if ENABLE(ENCRYPTED_MEDIA)
+ bool isCDMAttached() const { return m_cdmInstance; }
void attemptToDecryptWithLocalInstance();
void initializationDataEncountered(InitData&&);
void setWaitingForKey(bool);
#endif
+ Atomic<bool> m_isPlayerShuttingDown;
#if ENABLE(VIDEO_TRACK)
GRefPtr<GstElement> m_textAppSink;
GRefPtr<GstPad> m_textAppSinkPad;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes