Skip to content

Commit

Permalink
Cherry-pick 272777@main (ef04947). https://bugs.webkit.org/show_bug.c…
Browse files Browse the repository at this point in the history
…gi?id=267127

    [GStreamer][MediaStream] Track removal doesn't trigger corresponding appsrc removal
    https://bugs.webkit.org/show_bug.cgi?id=267127

    Reviewed by Xabier Rodriguez-Calvar.

    Clean-up the corresponding appsrc and pad when a MediaStreamTrack is removed from its MediaStream.

    * Source/WebCore/platform/mediastream/gstreamer/GStreamerMediaStreamSource.cpp:
    (WebKitMediaStreamObserver::didRemoveTrack):

    Canonical link: https://commits.webkit.org/272777@main
  • Loading branch information
philn authored and aperezdc committed Jan 28, 2024
1 parent 89cad36 commit a1796de
Showing 1 changed file with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,8 @@ void WebKitMediaStreamObserver::didRemoveTrack(MediaStreamTrackPrivate& track)
if (!m_src)
return;

auto* element = WEBKIT_MEDIA_STREAM_SRC_CAST(m_src);
auto* priv = element->priv;
auto self = WEBKIT_MEDIA_STREAM_SRC_CAST(m_src);
auto priv = self->priv;

// Lookup the corresponding InternalSource and take it from the storage.
auto index = priv->sources.findIf([&](auto& item) {
Expand All @@ -635,11 +635,28 @@ void WebKitMediaStreamObserver::didRemoveTrack(MediaStreamTrackPrivate& track)
return item->id() == track.id();
});

// Make sure that the video.videoWidth is reset to 0.
webkitMediaStreamSrcEnsureStreamCollectionPosted(element);

// Properly stop data flow. The source stops observing notifications from WebCore.
source->signalEndOfStream();

auto element = GST_ELEMENT_CAST(self);
{
auto locker = GstStateLocker(element);
auto* appSrc = source->get();
gst_element_set_locked_state(appSrc, true);
gst_element_set_state(appSrc, GST_STATE_NULL);
gst_bin_remove(GST_BIN_CAST(self), appSrc);
gst_element_set_locked_state(appSrc, false);
}

auto pad = adoptGRef(gst_element_get_static_pad(element, source->padName().ascii().data()));
if (auto proxyPad = adoptGRef(GST_PAD_CAST(gst_proxy_pad_get_internal(GST_PROXY_PAD(pad.get())))))
gst_flow_combiner_remove_pad(priv->flowCombiner.get(), proxyPad.get());

gst_pad_set_active(pad.get(), FALSE);
gst_element_remove_pad(element, pad.get());

// Make sure that the video.videoWidth is reset to 0.
webkitMediaStreamSrcEnsureStreamCollectionPosted(self);
}

static GstURIType webkitMediaStreamSrcUriGetType(GType)
Expand Down

0 comments on commit a1796de

Please sign in to comment.