Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ static MediaTime bufferTimeToStreamTime(const GstSegment* segment, GstClockTime
return MediaTime(sign * streamTime, GST_SECOND);
}

void AppendPipeline::appsinkNewSample(const Track& track, GRefPtr<GstSample>&& sample)
void AppendPipeline::appsinkNewSample(Track& track, GRefPtr<GstSample>&& sample)
{
ASSERT(isMainThread());

Expand All @@ -529,14 +529,16 @@ void AppendPipeline::appsinkNewSample(const Track& track, GRefPtr<GstSample>&& s
GST_TRACE_OBJECT(track.appsinkPad.get(), "Mapped buffer to segment, PTS %" GST_TIME_FORMAT " -> %s DTS %" GST_TIME_FORMAT " -> %s",
GST_TIME_ARGS(GST_BUFFER_PTS(buffer)), pts.toString().utf8().data(), GST_TIME_ARGS(GST_BUFFER_DTS(buffer)), dts.toString().utf8().data());
mediaSample->setTimestamps(pts, dts);
} else if (!GST_BUFFER_DTS(buffer) && GST_BUFFER_PTS(buffer) > 0 && GST_BUFFER_PTS(buffer) <= 100'000'000) {
} else if (!GST_BUFFER_DTS(buffer) && GST_BUFFER_PTS(buffer) > 0 && GST_BUFFER_PTS(buffer) <= 100'000'000 &&
!track.hasExtendedFirstSample) {
// Because a track presentation time starting at some close to zero, but not exactly zero time can cause unexpected
// results for applications, we extend the duration of this first sample to the left so that it starts at zero.
// This is relevant for files that should have an edit list but don't, or when using GStreamer < 1.16, where
// edit lists are not parsed in push-mode.

GST_DEBUG("Extending first sample of track '%" PRIu64 "' to make it start at PTS=0 %" GST_PTR_FORMAT, track.trackId, buffer);
mediaSample->extendToTheBeginning();
track.hasExtendedFirstSample = true;
}

GST_TRACE_OBJECT(pipeline(), "append: trackId=%" PRIu64 " PTS=%s DTS=%s DUR=%s presentationSize=%.0fx%.0f",
Expand Down Expand Up @@ -744,6 +746,10 @@ void AppendPipeline::resetParserState()
// We can listen again to new requests coming from the streaming thread.
m_taskQueue.finishAborting();

// Reset the flag for extending the first sample, as we're starting fresh with new data.
for (std::unique_ptr<Track>& track : m_tracks)
track->hasExtendedFirstSample = false;

#if (!(LOG_DISABLED || defined(GST_DISABLE_GST_DEBUG)))
{
static unsigned i = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ class AppendPipeline {
, streamType(streamType)
, caps(caps)
, presentationSize(presentationSize)
, hasExtendedFirstSample(false)
{ }

TrackID trackId;
StreamType streamType;
GRefPtr<GstCaps> caps;
FloatSize presentationSize;
bool hasExtendedFirstSample;

// Needed by some formats. To simplify the code, parser can be a GstIdentity when not needed.
GRefPtr<GstElement> parser;
Expand Down Expand Up @@ -117,7 +119,7 @@ class AppendPipeline {
static std::tuple<GRefPtr<GstCaps>, AppendPipeline::StreamType, FloatSize> parseDemuxerSrcPadCaps(GstCaps*);
Ref<WebCore::TrackPrivateBase> makeWebKitTrack(int trackIndex, TrackID);
void appsinkCapsChanged(Track&);
void appsinkNewSample(const Track&, GRefPtr<GstSample>&&);
void appsinkNewSample(Track&, GRefPtr<GstSample>&&);
void handleEndOfAppend();
void didReceiveInitializationSegment();

Expand Down