diff --git a/Source/WebCore/platform/graphics/SourceBufferPrivate.cpp b/Source/WebCore/platform/graphics/SourceBufferPrivate.cpp index 4d74f7efad31..d443588be695 100644 --- a/Source/WebCore/platform/graphics/SourceBufferPrivate.cpp +++ b/Source/WebCore/platform/graphics/SourceBufferPrivate.cpp @@ -358,7 +358,10 @@ void SourceBufferPrivate::reenqueueMediaIfNeeded(const MediaTime& currentTime) TrackBuffer& trackBuffer = trackBufferPair.value; const AtomString& trackID = trackBufferPair.key; + fprintf(stderr, "JJ: before needsReenqueueing, reenqueueMediaIfNeeded, id: %s, needsReenq: %d\n", trackID.string().utf8().data(), trackBuffer.needsReenqueueing()); + if (trackBuffer.needsReenqueueing()) { + fprintf(stderr, "JJ: eenqueuing at time: %s\n", trackID.string().utf8().data()); DEBUG_LOG(LOGIDENTIFIER, "reenqueuing at time ", currentTime); reenqueueMediaForTime(trackBuffer, trackID, currentTime); } else @@ -394,6 +397,9 @@ void SourceBufferPrivate::removeCodedFrames(const MediaTime& start, const MediaT return; } + LOG(Media, "JJ: BEFORE SourceBuffer::removeCodedFrames(%p) - buffered = %s", this, toString(m_buffered->ranges()).utf8().data()); + + // 3.5.9 Coded Frame Removal Algorithm // https://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html#sourcebuffer-coded-frame-removal @@ -404,16 +410,22 @@ void SourceBufferPrivate::removeCodedFrames(const MediaTime& start, const MediaT TrackBuffer& trackBuffer = trackBufferKeyValue.value; AtomString trackID = trackBufferKeyValue.key; - if (!trackBuffer.removeCodedFrames(start, end, currentTime)) + LOG(Media, "JJ: before removeCodedFrames, trackID: %s", trackID.string().utf8().data()); + if (!trackBuffer.removeCodedFrames(start, end, currentTime, trackID.string())) continue; - + LOG(Media, "JJ: after removeCodedFrames, trackID: %s", trackID.string().utf8().data()); + setBufferedDirty(true); // 3.4 If this object is in activeSourceBuffers, the current playback position is greater than or equal to start // and less than the remove end timestamp, and HTMLMediaElement.readyState is greater than HAVE_METADATA, then set // the HTMLMediaElement.readyState attribute to HAVE_METADATA and stall playback. - if (isActive() && currentTime >= start && currentTime < end && readyState() > MediaPlayer::ReadyState::HaveMetadata) + if (isActive() && currentTime >= start && currentTime < end && readyState() > MediaPlayer::ReadyState::HaveMetadata) { + LOG(Media, "JJ: should stall playback! (%p), trackID: %s - buffered = %s", this, trackID.string().utf8().data(), toString(m_buffered->ranges()).utf8().data()); + setReadyState(MediaPlayer::ReadyState::HaveMetadata); + + } } reenqueueMediaIfNeeded(currentTime); @@ -425,7 +437,7 @@ void SourceBufferPrivate::removeCodedFrames(const MediaTime& start, const MediaT updateHighestPresentationTimestamp(); - LOG(Media, "SourceBuffer::removeCodedFrames(%p) - buffered = %s", this, toString(m_buffered->ranges()).utf8().data()); + LOG(Media, "JJ: SourceBuffer::removeCodedFrames(%p) - buffered = %s", this, toString(m_buffered->ranges()).utf8().data()); m_client->sourceBufferPrivateReportExtraMemoryCost(totalTrackBufferSizeInBytes()); diff --git a/Source/WebCore/platform/graphics/TrackBuffer.cpp b/Source/WebCore/platform/graphics/TrackBuffer.cpp index a096db0b83d1..de9f57c2a6f9 100644 --- a/Source/WebCore/platform/graphics/TrackBuffer.cpp +++ b/Source/WebCore/platform/graphics/TrackBuffer.cpp @@ -249,7 +249,7 @@ static WARN_UNUSED_RETURN bool decodeTimeComparator(const PresentationOrderSampl return a.second->decodeTime() < b.second->decodeTime(); }; -bool TrackBuffer::removeCodedFrames(const MediaTime& start, const MediaTime& end, const MediaTime& currentTime) +bool TrackBuffer::removeCodedFrames(const MediaTime& start, const MediaTime& end, const MediaTime& currentTime, const WTF::String trackID) { // 3.5.9 Coded Frame Removal Algorithm // https://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html#sourcebuffer-coded-frame-removal @@ -309,9 +309,14 @@ bool TrackBuffer::removeCodedFrames(const MediaTime& start, const MediaTime& end PlatformTimeRanges possiblyEnqueuedRanges(currentTime, m_highestEnqueuedPresentationTime); possiblyEnqueuedRanges.intersectWith(erasedRanges); if (possiblyEnqueuedRanges.length()) { + LOG(Media, "JJ: m_needsReenqueueing == true; currentTime: %f, m_highestEnqueuedPresentationTime: %f, trackID: %s", currentTime.toFloat() , m_highestEnqueuedPresentationTime.toFloat(), trackID.utf8().data()); m_needsReenqueueing = true; DEBUG_LOG_IF(m_logger, LOGIDENTIFIER, "the range in removeCodedFrames() includes already enqueued samples, reenqueueing from ", currentTime); + } else { + LOG(Media, "JJ: m_needsReenqueueing == false; currentTime: %f, m_highestEnqueuedPresentationTime: %f, trackID: %s", currentTime.toFloat() , m_highestEnqueuedPresentationTime.toFloat(), trackID.utf8().data()); } + } else { + LOG(Media, "JJ: not _highestEnqueuedPresentationTime.isValid() && currentTime < m_highestEnqueuedPresentationTime, curentTime: %f, m_highestEnqueuedPresentationTime: %f, m_highestEnqueuedPresentationTime.isValid(): %d, trackID: %s", currentTime.toFloat(), m_highestEnqueuedPresentationTime.toFloat(), m_highestEnqueuedPresentationTime.isValid(), trackID.utf8().data()); } erasedRanges.invert(); diff --git a/Source/WebCore/platform/graphics/TrackBuffer.h b/Source/WebCore/platform/graphics/TrackBuffer.h index bbda7b866ae9..564ee728cc71 100644 --- a/Source/WebCore/platform/graphics/TrackBuffer.h +++ b/Source/WebCore/platform/graphics/TrackBuffer.h @@ -35,6 +35,7 @@ #include #include #include +#include namespace WebCore { @@ -56,7 +57,7 @@ class TrackBuffer final bool reenqueueMediaForTime(const MediaTime&, const MediaTime& timeFudgeFactor); MediaTime findSeekTimeForTargetTime(const MediaTime& targetTime, const MediaTime& negativeThreshold, const MediaTime& positiveThreshold); - bool removeCodedFrames(const MediaTime& start, const MediaTime& end, const MediaTime& currentTime); + bool removeCodedFrames(const MediaTime& start, const MediaTime& end, const MediaTime& currentTime, const WTF::String trackID); PlatformTimeRanges removeSamples(const DecodeOrderSampleMap::MapType&, const char*); void resetTimestampOffset(); diff --git a/Source/WebCore/platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.cpp index 80b581093ba3..021d0acdca04 100644 --- a/Source/WebCore/platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.cpp @@ -146,12 +146,12 @@ void SourceBufferPrivateGStreamer::flush(const AtomString& trackId) // This is only for on-the-fly reenqueues after appends. When seeking, the seek will do its own flush. - if (!m_playerPrivate.hasAllTracks()) { - GST_DEBUG_OBJECT(m_playerPrivate.pipeline(), "Source element has not emitted tracks yet, so we only need to clear the queue. trackId = '%s'", trackId.string().utf8().data()); - MediaSourceTrackGStreamer* track = m_tracks.get(trackId); - track->clearQueue(); - return; - } + // if (!m_playerPrivate.hasAllTracks()) { + // GST_DEBUG_OBJECT(m_playerPrivate.pipeline(), "Source element has not emitted tracks yet, so we only need to clear the queue. trackId = '%s'", trackId.string().utf8().data()); + // MediaSourceTrackGStreamer* track = m_tracks.get(trackId); + // track->clearQueue(); + // return; + // } GST_DEBUG_OBJECT(m_playerPrivate.pipeline(), "Source element has emitted tracks, let it handle the flush, which may cause a pipeline flush as well. trackId = '%s'", trackId.string().utf8().data()); webKitMediaSrcFlush(m_playerPrivate.webKitMediaSrc(), trackId);