Skip to content
Permalink
Browse files
[GStreamer] Rewrite purgeInvalid*Tracks methods
https://bugs.webkit.org/show_bug.cgi?id=183004

Reviewed by Carlos Garcia Campos.

Removing items from a hashmap while iterating is bad.

* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::purgeInvalidAudioTracks):
Safely remove items from the hashmap using removeIf().
(WebCore::MediaPlayerPrivateGStreamer::purgeInvalidVideoTracks): Ditto.
(WebCore::MediaPlayerPrivateGStreamer::purgeInvalidTextTracks): Ditto.

Canonical link: https://commits.webkit.org/198750@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@228875 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
philn committed Feb 21, 2018
1 parent be5ba39 commit c49010de1b1089e81a733da44d321868fde60945
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 36 deletions.
@@ -1,3 +1,18 @@
2018-02-21 Philippe Normand <pnormand@igalia.com>

[GStreamer] Rewrite purgeInvalid*Tracks methods
https://bugs.webkit.org/show_bug.cgi?id=183004

Reviewed by Carlos Garcia Campos.

Removing items from a hashmap while iterating is bad.

* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::purgeInvalidAudioTracks):
Safely remove items from the hashmap using removeIf().
(WebCore::MediaPlayerPrivateGStreamer::purgeInvalidVideoTracks): Ditto.
(WebCore::MediaPlayerPrivateGStreamer::purgeInvalidTextTracks): Ditto.

2018-02-21 Chris Dumez <cdumez@apple.com>

Unreviewed attempt to fix build after r228867.
@@ -1455,50 +1455,23 @@ void MediaPlayerPrivateGStreamer::processTableOfContentsEntry(GstTocEntry* entry

void MediaPlayerPrivateGStreamer::purgeInvalidAudioTracks(Vector<String> validTrackIds)
{
if (validTrackIds.isEmpty()) {
m_audioTracks.clear();
return;
}
for (auto audioTrackId : m_audioTracks.keys()) {
if (validTrackIds.contains(audioTrackId))
continue;
auto track = m_audioTracks.get(audioTrackId);
track->disconnect();
m_player->removeAudioTrack(*track);
m_audioTracks.remove(audioTrackId);
}
m_audioTracks.removeIf([validTrackIds](auto& keyAndValue) {
return !validTrackIds.contains(keyAndValue.key);
});
}

void MediaPlayerPrivateGStreamer::purgeInvalidVideoTracks(Vector<String> validTrackIds)
{
if (validTrackIds.isEmpty()) {
m_videoTracks.clear();
return;
}
for (auto videoTrackId : m_videoTracks.keys()) {
if (validTrackIds.contains(videoTrackId))
continue;
auto track = m_videoTracks.get(videoTrackId);
track->disconnect();
m_player->removeVideoTrack(*track);
m_videoTracks.remove(videoTrackId);
}
m_videoTracks.removeIf([validTrackIds](auto& keyAndValue) {
return !validTrackIds.contains(keyAndValue.key);
});
}

void MediaPlayerPrivateGStreamer::purgeInvalidTextTracks(Vector<String> validTrackIds)
{
if (validTrackIds.isEmpty()) {
m_textTracks.clear();
return;
}
for (auto textTrackId : m_textTracks.keys()) {
if (validTrackIds.contains(textTrackId))
continue;
auto track = m_textTracks.get(textTrackId);
track->disconnect();
m_player->removeTextTrack(*track);
m_textTracks.remove(textTrackId);
}
m_textTracks.removeIf([validTrackIds](auto& keyAndValue) {
return !validTrackIds.contains(keyAndValue.key);
});
}
#endif

0 comments on commit c49010d

Please sign in to comment.