Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live alt audio inspired on fredvb and pull 700 #832

Conversation

sergiojm
Copy link
Contributor

Live alternative audio inspired on
fredvb pull request 727 and INIT_PTS_FOUND on pull request 700
using base code 0.6.10

@mangui
Copy link
Member

mangui commented Nov 21, 2016

thanks @sergiojm
as discussed on Slack, remuxing of alternate audio fragment should not start until INIT_PTS_FOUND event has been fired.
this is to maintain consistent timestamp synchronization between alt audio and main playlist and avoid AV sync issue.

one way to do it would be to add a new state in audio-stream-controller
WAITING_INIT_PTS name would do the trick

when a new alt audio frag is loaded, you should then check if initPTS is defined.

  • if defined, you could start remuxing as it is done today
  • if not defined, you should save fragment payload in class context, then switch to WAITING_INIT_PTS state

onInitPtsFound:
if WAITING_INIT_PTS state you should also trigger audio frag remuxing.

Sergio Monteiro added 3 commits November 29, 2016 17:13
Changing BUFFER_FLUSH on audio with alternative audio
On Live alt audio if we FLUSH Buffer imediatly can hold the play and delay that can lead to a moment that Alt audio is not available anymore
Also now if it user pauses, gets away from live, switch audio track, would not break cause it will wait until it has a valid frag to flush
Copy link
Member

@mangui mangui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @sergiojm I made a couple of comments, some are cosmetic, main point i am not clear about is all the stuff related to this.prevTrackId in audioStreamController. If you could explain in layman's term what you are trying to achieve it ?
thanks !


var currentTime=this.media.currentTime;

// When switching audio track the bufferEnd should only be considered
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not clear about these code changes, could you explain what you are trying to achieve here ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se bellow comments

@@ -229,6 +271,22 @@ class AudioStreamController extends EventHandler {
}
}
if(frag) {
//Only flush when we have a startPTS
//Calculating when we have a new track frag available to play
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not clear as well why flushing is done before FRAG_LOADING, could you explain the logic here ?

Copy link

@sergiojgm sergiojgm Dec 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we flush(0 to infinity audio) before loading and parse the stream get stuck until we receive the track, if we ever recieve it.

On VOD no impact since playlists are always available on any current time.

On Live streams, especially with low chunk durations, you get error on playlists and the player just hangs the playback since it cannot download a playlist with chunk for the current time, just downloads forward chunks and get a hole on the buffer since we already flushed.

The ideia is, trigger that a audio switch occur, dont flush, and when the frag is loaded and parsed(with correct start), then flush and append to buffer. Meantime it just continues to play the current audio buffer until is safe to make the proper flush and append.

The problem increases if u change multiple times the audio track, cause every time u just get delay from the live pos(due to the flush 0 to inifity). Will lead u to a position when the playlist simple doesn't have any valid ts for the currentTime.

Also if u pause a live stream with alt audio, then resume and switch the audio track, the player will immediatly crash, cause you are forcing the behavour.

So now with flushing only when you download and parsed a valid frag for the currentTime you can even pause for long secondes cause it will use the current audio track in buffer until
its safe to flush and append.

let accurateTimeOffset = details.PTSKnown || !details.live;
this.demuxer.push(data.payload, audioCodec, null, start, fragCurrent.cc, trackId, sn, duration, fragCurrent.decryptdata, accurateTimeOffset, this.initPTS);
} else {
logger.log(`No video PTS for audio frag ${sn} of [${details.startSN} ,${details.endSN}],track ${trackId} , waiting for video pts`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest renaming 'No video PTS' into 'unknown video PTS'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes good point will patch tomorrow

@@ -47,6 +47,8 @@ module.exports = {
AUDIO_TRACK_LOADING: 'hlsAudioTrackLoading',
// fired when an audio track loading finishes - data: { details : levelDetails object, id : audio track id, stats : { trequest, tfirst, tload, mtime} }
AUDIO_TRACK_LOADED: 'hlsAudioTrackLoaded',
// fired when the first timestamp is found.
INIT_PTS_FOUND: 'hlsInitPtsFound',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you also describe the data object dispatched along with this event ?
you need to make it consistent with other events dispatched by demuxer:

{ id : demuxerId, initPTS: initPTS}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes good point will patch tomorrow

@@ -149,6 +153,7 @@ class MP4Remuxer {
if (computePTSDTS) {
initPTS = Math.min(initPTS,videoSamples[0].pts - pesTimeScale * timeOffset);
initDTS = Math.min(initDTS,videoSamples[0].dts - pesTimeScale * timeOffset);
this.observer.trigger(Event.INIT_PTS_FOUND, {initPTS});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you change the dispatched object (for consistency) as being something like :
{ id : demuxerId, initPTS: initPTS}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes good point will patch tomorrow

//Always update the new INIT PTS
//Can change due level switch
this.initPTS = data.initPTS;
logger(`InitPTS , ${this.initPTS}, found from video track`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/logger/logger.log

@mangui
Copy link
Member

mangui commented Dec 2, 2016

this PR breaks support of alt audio VoD stream with discontinuity such as
https://hls.ted.com/talks/2024.m3u8?qr&network=tv&preroll=Blank

@mangui
Copy link
Member

mangui commented Dec 2, 2016

initPTS should be linked to a continuity counter index.
looking into it

@mangui
Copy link
Member

mangui commented Dec 6, 2016

closing in favor of https://github.com/dailymotion/hls.js/pull/860 that also contains these changes

@mangui mangui closed this Dec 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants