kiall / android-tvheadend

Android + TV Headend + TV Input Framework
Apache License 2.0
191 stars 61 forks source link

Implement Fast Forward and Rewind during Timeshifting and playing back of Recorded Shows #239

Open TheDiamondPicks opened 6 years ago

TheDiamondPicks commented 6 years ago

Title says all

I have tested this, and it seems to work well although it does cause low memory warnings on the Mi Box.

TheDiamondPicks commented 6 years ago

It seems that rewind is not working - it doesn't seem like HtspSession#onTimeShiftSetPlaybackParams is being called at all when rewinding, at least not in my testing.

kiall commented 6 years ago

I've been refreshing my memory... Rewind is significantly harder, as ExoPlayer doesn't support playing in reverse (as media codecs in general don't really support that either). I've created PR #243 with your code, and a few extra changes - but it still doesn't seem to be quite reliable yet - specifically, if you pause, wait a bit, and then fast-forward through the buffer - the audio will get way out of sync.

TheDiamondPicks commented 6 years ago

Much tidier now, thanks!

With regards to rewind support, is it possible to simply skip back frames, it wouldn't be as nice as changing the speed obviously, but it's better than nothing. Although this might not be practical, my understanding of ExoPlayer is rather limited at this stage.

I will see if I can reproduce the audio sync issue as well, because it sounds like it could be quite tricky to sort out.

(a little offtopic but I would appreciate your input in #242)

kiall commented 6 years ago

With regards to rewind support, is it possible to simply skip back frames, it wouldn't be as nice as changing the speed obviously, but it's better than nothing. Although this might not be practical, my understanding of ExoPlayer is rather limited at this stage.

I've been playing with that - the code is messy as hell but works - I've pushed that commit to the other PR.

I will see if I can reproduce the audio sync issue as well, because it sounds like it could be quite tricky to sort out.

What I don't quite get is, ExoPlayer should be handling that for us. All the different tracks -audio, video, text come with presentation timestamps - and the audio tracks timestamp is used to synchronise the playback rates and positions of each. If there is a mismatch, ExoPlayer should pause the video - line things back up - and resume. So, I'm quite confused as to how the delay exists :)

re the translated speeds - So - there doesn't seem to be a fixed mapping from the UI display (2x, 3x, 4x, 5x) to the value we receive! Playing with this for the last little while, I keep getting different values passed in. I've not quite figured out what's happening here, but I suspect Android TV's UI is "lying" - and when it says for example "2x Rewind" on the UI, it's giving us totally different numbers.

speed: increases or decreases the time to play back a set of audio or video frames. It is expressed as a multiplicative factor, where normal speed is 1.0f.

However - the UI doesn't even go below -5x rewind, yet we get much lower numbers than -5.0f in. Humm.

TheDiamondPicks commented 6 years ago

With regards to the audio sync issue, are we able to print timestamps of the audio / video every second or so, so we can see when it becomes out of sync?

With the speed factors, from what I saw in my testing it was 2, 8, 32 etc, do the numbers match this pattern?

michaelarnauts commented 4 years ago

@TheDiamondPicks have you given up on tvheadend in Android TV, or did you switch to another TV backend service?

TheDiamondPicks commented 4 years ago

@michaelarnauts yeah, I've switch to Plex now, which unfortunately doesn't have a live channels backend, but the integration into the rest of Plex outweighed those downsides for me.