Commit 62ecf35d authored by François Cartegnie's avatar François Cartegnie 🤞

demux: adaptive: fix in-band and out-of-band time offset handling

was regression with AAC seek since rewrite of buffering
parent 7f656d00
......@@ -112,6 +112,7 @@ void AbstractStream::prepareRestart(bool b_discontinuity)
{
/* Enqueue Del Commands for all current ES */
demuxer->drain();
setTimeOffset(true);
/* Enqueue Del Commands for all current ES */
fakeesout->scheduleAllForDeletion();
if(b_discontinuity)
......@@ -294,7 +295,6 @@ AbstractStream::buffering_status AbstractStream::bufferize(mtime_t nz_deadline,
vlc_mutex_unlock(&lock);
return AbstractStream::buffering_end;
}
setTimeOffset();
}
const int64_t i_total_buffering = i_min_buffering + i_extra_buffering;
......@@ -443,10 +443,11 @@ bool AbstractStream::setPosition(mtime_t time, bool tryonly)
currentChunk = NULL;
needrestart = false;
setTimeOffset(-1);
setTimeOffset(segmentTracker->getPlaybackTime());
if( !restartDemux() )
dead = true;
setTimeOffset();
}
else commandsqueue->Abort( true );
......@@ -475,14 +476,19 @@ void AbstractStream::fillExtraFMTInfo( es_format_t *p_fmt ) const
p_fmt->psz_description = strdup(description.c_str());
}
void AbstractStream::setTimeOffset()
void AbstractStream::setTimeOffset(mtime_t i_offset)
{
/* Check if we need to set an offset as the demuxer
* will start from zero from seek point */
if(demuxer && demuxer->alwaysStartsFromZero())
fakeesout->setTimestampOffset(segmentTracker->getPlaybackTime());
else
if(i_offset < 0) /* reset */
{
fakeesout->setTimestampOffset(0);
}
else if(demuxer)
{
if(demuxer->alwaysStartsFromZero())
fakeesout->setTimestampOffset(i_offset);
}
}
void AbstractStream::trackerEvent(const SegmentTrackerEvent &event)
......
......@@ -95,7 +95,7 @@ namespace adaptive
protected:
bool seekAble() const;
virtual void setTimeOffset();
virtual void setTimeOffset(mtime_t);
virtual block_t *checkBlock(block_t *, bool) = 0;
virtual AbstractDemuxer * createDemux(const StreamFormat &) = 0;
virtual bool startDemux();
......
......@@ -34,28 +34,27 @@ using namespace hls;
HLSStream::HLSStream(demux_t *demux)
: AbstractStream(demux)
{
b_timestamps_offset_set = false;
i_aac_offset = 0;
b_id3_timestamps_offset_set = false;
}
bool HLSStream::setPosition(mtime_t time, bool tryonly)
void HLSStream::setTimeOffset(mtime_t i_offset)
{
bool b_ret = AbstractStream::setPosition(time, tryonly);
if(!tryonly && b_ret)
if(i_offset >= 0)
{
/* Should be correct, has a restarted demux shouldn't have been fed with data yet */
fakeesout->setTimestampOffset( VLC_TS_INVALID );
b_timestamps_offset_set = false;
if((unsigned)format == StreamFormat::PACKEDAAC)
{
if(!b_id3_timestamps_offset_set)
{
fakeesout->setTimestampOffset(i_offset);
}
return;
}
}
return b_ret;
}
bool HLSStream::restartDemux()
{
bool b_ret = AbstractStream::restartDemux();
if(b_ret)
b_timestamps_offset_set = false;
return b_ret;
else
{
b_id3_timestamps_offset_set = false;
}
AbstractStream::setTimeOffset(i_offset);
}
AbstractDemuxer * HLSStream::createDemux(const StreamFormat &format)
......@@ -93,26 +92,17 @@ AbstractDemuxer * HLSStream::createDemux(const StreamFormat &format)
return ret;
}
void HLSStream::prepareRestart(bool b_discontinuity)
{
AbstractStream::prepareRestart(b_discontinuity);
if((unsigned)format == StreamFormat::PACKEDAAC)
{
fakeesout->setTimestampOffset( i_aac_offset );
}
else
{
fakeesout->setTimestampOffset( 0 );
}
}
int HLSStream::ID3PrivTagHandler(const uint8_t *p_payload, size_t i_payload)
{
if(i_payload == 53 &&
!memcmp( p_payload, "com.apple.streaming.transportStreamTimestamp", 45))
{
i_aac_offset = GetQWBE(&p_payload[45]) * 100 / 9;
b_timestamps_offset_set = true;
if(!b_id3_timestamps_offset_set)
{
const mtime_t i_aac_offset = GetQWBE(&p_payload[45]) * 100 / 9;
setTimeOffset(i_aac_offset);
b_id3_timestamps_offset_set = true;
}
return VLC_EGENERIC; /* stop parsing */
}
return VLC_SUCCESS;
......
......@@ -30,19 +30,15 @@ namespace hls
{
public:
HLSStream(demux_t *);
virtual bool setPosition(mtime_t, bool); /* reimpl */
int ID3PrivTagHandler( const uint8_t *, size_t );
protected:
virtual AbstractDemuxer * createDemux(const StreamFormat &); /* reimpl */
virtual bool restartDemux(); /* reimpl */
virtual void prepareRestart(bool = true); /* reimpl */
virtual void setTimeOffset(mtime_t); /* reimpl */
virtual block_t *checkBlock(block_t *, bool); /* reimpl */
private:
bool b_timestamps_offset_set;
mtime_t i_aac_offset;
bool b_id3_timestamps_offset_set;
};
class HLSStreamFactory : public AbstractStreamFactory
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment