Title: [232579] trunk/Source/WebCore
Revision
232579
Author
[email protected]
Date
2018-06-07 02:36:00 -0700 (Thu, 07 Jun 2018)

Log Message

[GStreamer] Fix the way GstStreamCollection is handled
https://bugs.webkit.org/show_bug.cgi?id=184588

Patch by Thibault Saunier <[email protected]> on 2018-06-07
Reviewed by Philippe Normand.

The stream collection message replaces the collection of stream previously
advertised, this means that we should rebuild our set of Track from scratch
and not update previously exposed tracks.

In the end, this simplifies the code as we do not care about what
tracks existed previously, we just need to expose what GStreamer tells
us, deleting any previous state.

Handle the STREAM_COLLECTION message from the sync handler so that tracks
are updated before we mark the pipeline as READY for the live case (everything
happen synchronously with the call to the `load()` method in that case),
the update still always happens on the main thread.

No new tests is added as this is mostly refactoring, it is already tested and it
will fix MediaStream tests that are currently disabled as the support is being
implemented in #185787.

* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::clearTracks): Removes all tracks.
(WebCore::MediaPlayerPrivateGStreamer::updateTracks): Updates configured tracks from the new GstStreamColection track.
(WebCore::MediaPlayerPrivateGStreamer::handleMessage): Stop handling GST_STREAM_COLLECTION event.
(WebCore::MediaPlayerPrivateGStreamer::handleSyncMessage): Handle stream collection event synchronously.
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h: Add handleSyncMessage

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (232578 => 232579)


--- trunk/Source/WebCore/ChangeLog	2018-06-07 08:44:59 UTC (rev 232578)
+++ trunk/Source/WebCore/ChangeLog	2018-06-07 09:36:00 UTC (rev 232579)
@@ -1,3 +1,34 @@
+2018-06-07  Thibault Saunier  <[email protected]>
+
+        [GStreamer] Fix the way GstStreamCollection is handled
+        https://bugs.webkit.org/show_bug.cgi?id=184588
+
+        Reviewed by Philippe Normand.
+
+        The stream collection message replaces the collection of stream previously
+        advertised, this means that we should rebuild our set of Track from scratch
+        and not update previously exposed tracks.
+
+        In the end, this simplifies the code as we do not care about what
+        tracks existed previously, we just need to expose what GStreamer tells
+        us, deleting any previous state.
+
+        Handle the STREAM_COLLECTION message from the sync handler so that tracks
+        are updated before we mark the pipeline as READY for the live case (everything
+        happen synchronously with the call to the `load()` method in that case),
+        the update still always happens on the main thread.
+
+        No new tests is added as this is mostly refactoring, it is already tested and it
+        will fix MediaStream tests that are currently disabled as the support is being
+        implemented in #185787.
+
+        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
+        (WebCore::MediaPlayerPrivateGStreamer::clearTracks): Removes all tracks.
+        (WebCore::MediaPlayerPrivateGStreamer::updateTracks): Updates configured tracks from the new GstStreamColection track.
+        (WebCore::MediaPlayerPrivateGStreamer::handleMessage): Stop handling GST_STREAM_COLLECTION event.
+        (WebCore::MediaPlayerPrivateGStreamer::handleSyncMessage): Handle stream collection event synchronously.
+        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h: Add handleSyncMessage
+
 2018-06-07  Michael Catanzaro  <[email protected]>
 
         Remove unused image encoders

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp (232578 => 232579)


--- trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp	2018-06-07 08:44:59 UTC (rev 232578)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp	2018-06-07 09:36:00 UTC (rev 232579)
@@ -622,6 +622,36 @@
 }
 
 #if GST_CHECK_VERSION(1, 10, 0)
+#define CLEAR_TRACKS(tracks, method) \
+    for (auto& track : tracks.values())\
+        method(*track);\
+    tracks.clear();
+
+void MediaPlayerPrivateGStreamer::clearTracks()
+{
+#if ENABLE(VIDEO_TRACK)
+    CLEAR_TRACKS(m_audioTracks, m_player->removeAudioTrack);
+    CLEAR_TRACKS(m_videoTracks, m_player->removeVideoTrack);
+    CLEAR_TRACKS(m_textTracks, m_player->removeTextTrack);
+#endif // ENABLE(VIDEO_TRACK)
+}
+#undef CLEAR_TRACKS
+
+#if ENABLE(VIDEO_TRACK)
+#define CREATE_TRACK(type, Type) \
+    m_has##Type = true; \
+    if (!useMediaSource) {\
+        RefPtr<Type##TrackPrivateGStreamer> track = Type##TrackPrivateGStreamer::create(createWeakPtr(), i, stream); \
+        m_##type##Tracks.add(track->id(), track); \
+        m_player->add##Type##Track(*track);\
+        if (gst_stream_get_stream_flags(stream.get()) & GST_STREAM_FLAG_SELECT) {                                    \
+            m_current##Type##StreamId = String(gst_stream_get_stream_id(stream.get()));                              \
+        }                                                                                                            \
+    }
+#else
+#define CREATE_TRACK(type, _id, tracks, method, stream) m_has##Type## = true;
+#endif // ENABLE(VIDEO_TRACK)
+
 void MediaPlayerPrivateGStreamer::updateTracks()
 {
     ASSERT(!m_isLegacyPlaybin);
@@ -628,69 +658,31 @@
 
     bool useMediaSource = isMediaSource();
     unsigned length = gst_stream_collection_get_size(m_streamCollection.get());
-    Vector<String> validAudioStreams;
-    Vector<String> validVideoStreams;
-    Vector<String> validTextStreams;
+
+    bool oldHasAudio = m_hasAudio;
+    bool oldHasVideo = m_hasVideo;
+    // New stream collections override previous ones.
+    clearTracks();
     for (unsigned i = 0; i < length; i++) {
         GRefPtr<GstStream> stream = gst_stream_collection_get_stream(m_streamCollection.get(), i);
         String streamId(gst_stream_get_stream_id(stream.get()));
         GstStreamType type = gst_stream_get_stream_type(stream.get());
-        GST_DEBUG("Inspecting %s track with ID %s", gst_stream_type_get_name(type), streamId.utf8().data());
+
+        GST_DEBUG_OBJECT(pipeline(), "Inspecting %s track with ID %s", gst_stream_type_get_name(type), streamId.utf8().data());
         if (type & GST_STREAM_TYPE_AUDIO) {
-            validAudioStreams.append(streamId);
-#if ENABLE(VIDEO_TRACK)
-            if (!useMediaSource) {
-                unsigned localIndex = i - validVideoStreams.size() - validTextStreams.size();
-                if (localIndex < m_audioTracks.size()) {
-                    if (m_audioTracks.contains(streamId))
-                        continue;
-                }
-
-                RefPtr<AudioTrackPrivateGStreamer> track = AudioTrackPrivateGStreamer::create(createWeakPtr(), i, stream);
-                m_audioTracks.add(track->id(), track);
-                m_player->addAudioTrack(*track);
-            }
-#endif
+            CREATE_TRACK(audio, Audio)
         } else if (type & GST_STREAM_TYPE_VIDEO) {
-            validVideoStreams.append(streamId);
+            CREATE_TRACK(video, Video)
+        } else if (type & GST_STREAM_TYPE_TEXT && !useMediaSource) {
 #if ENABLE(VIDEO_TRACK)
-            if (!useMediaSource) {
-                unsigned localIndex = i - validAudioStreams.size() - validTextStreams.size();
-                if (localIndex < m_videoTracks.size()) {
-                    if (m_videoTracks.contains(streamId))
-                        continue;
-                }
-
-                RefPtr<VideoTrackPrivateGStreamer> track = VideoTrackPrivateGStreamer::create(createWeakPtr(), i, stream);
-                m_videoTracks.add(track->id(), track);
-                m_player->addVideoTrack(*track);
-            }
+            RefPtr<InbandTextTrackPrivateGStreamer> track = InbandTextTrackPrivateGStreamer::create(i, stream);
+            m_textTracks.add(streamId, track);
+            m_player->addTextTrack(*track);
 #endif
-        } else if (type & GST_STREAM_TYPE_TEXT) {
-            validTextStreams.append(streamId);
-#if ENABLE(VIDEO_TRACK)
-            if (!useMediaSource) {
-                unsigned localIndex = i - validVideoStreams.size() - validAudioStreams.size();
-                if (localIndex < m_textTracks.size()) {
-                    if (m_textTracks.contains(streamId))
-                        continue;
-                }
-
-                RefPtr<InbandTextTrackPrivateGStreamer> track = InbandTextTrackPrivateGStreamer::create(localIndex, stream);
-                m_textTracks.add(streamId, track);
-                m_player->addTextTrack(*track);
-            }
-#endif
         } else
             GST_WARNING("Unknown track type found for stream %s", streamId.utf8().data());
     }
 
-    GST_INFO("Media has %zu video tracks, %zu audio tracks and %zu text tracks", validVideoStreams.size(), validAudioStreams.size(), validTextStreams.size());
-
-    bool oldHasAudio = m_hasAudio;
-    bool oldHasVideo = m_hasVideo;
-    m_hasAudio = !validAudioStreams.isEmpty();
-    m_hasVideo = !validVideoStreams.isEmpty();
     if ((oldHasVideo != m_hasVideo) || (oldHasAudio != m_hasAudio))
         m_player->characteristicChanged();
 
@@ -703,15 +695,9 @@
         return;
     }
 
-#if ENABLE(VIDEO_TRACK)
-    purgeInvalidAudioTracks(validAudioStreams);
-    purgeInvalidVideoTracks(validVideoStreams);
-    purgeInvalidTextTracks(validTextStreams);
-#endif
-
     m_player->client().mediaPlayerEngineUpdated(m_player);
 }
-#endif
+#endif // GST_CHECK_VERSION(1, 10, 0)
 
 void MediaPlayerPrivateGStreamer::enableTrack(TrackPrivateBaseGStreamer::TrackType trackType, unsigned index)
 {
@@ -1299,21 +1285,6 @@
         break;
     }
 #if GST_CHECK_VERSION(1, 10, 0)
-    case GST_MESSAGE_STREAM_COLLECTION: {
-        if (m_isLegacyPlaybin)
-            break;
-
-        GRefPtr<GstStreamCollection> collection;
-        gst_message_parse_stream_collection(message, &collection.outPtr());
-
-        if (collection) {
-            m_streamCollection.swap(collection);
-            m_notifier->notify(MainThreadNotification::StreamCollectionChanged, [this] {
-                this->updateTracks();
-            });
-        }
-        break;
-    }
     case GST_MESSAGE_STREAMS_SELECTED: {
         GRefPtr<GstStreamCollection> collection;
         gst_message_parse_streams_selected(message, &collection.outPtr());
@@ -1983,6 +1954,25 @@
     }
 }
 
+bool MediaPlayerPrivateGStreamer::handleSyncMessage(GstMessage* message)
+{
+#if GST_CHECK_VERSION(1, 10, 0)
+    if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_STREAM_COLLECTION && !m_isLegacyPlaybin) {
+        GRefPtr<GstStreamCollection> collection;
+        gst_message_parse_stream_collection(message, &collection.outPtr());
+
+        if (collection) {
+            m_streamCollection.swap(collection);
+            m_notifier->notify(MainThreadNotification::StreamCollectionChanged, [this] {
+                this->updateTracks();
+            });
+        }
+    }
+#endif
+
+    return MediaPlayerPrivateGStreamerBase::handleSyncMessage(message);
+}
+
 void MediaPlayerPrivateGStreamer::mediaLocationChanged(GstMessage* message)
 {
     if (m_mediaLocations)

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h (232578 => 232579)


--- trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h	2018-06-07 08:44:59 UTC (rev 232578)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h	2018-06-07 09:36:00 UTC (rev 232579)
@@ -133,6 +133,8 @@
 
     void enableTrack(TrackPrivateBaseGStreamer::TrackType, unsigned index);
 
+    bool handleSyncMessage(GstMessage*) override;
+
 private:
     static void getSupportedTypes(HashSet<String, ASCIICaseInsensitiveHash>&);
     static MediaPlayer::SupportsType supportsType(const MediaEngineSupportParameters&);
@@ -180,6 +182,7 @@
 
 #if GST_CHECK_VERSION(1, 10, 0)
     void updateTracks();
+    void clearTracks();
 #endif
 
 protected:
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to