After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 777682 - hls: m3u8: Set sequence position for live
hls: m3u8: Set sequence position for live
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-bad
git master
Other Linux
: Normal normal
: 1.11.2
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2017-01-24 06:57 UTC by Seungha Yang
Modified: 2017-01-31 11:25 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
hls: m3u8: Set sequence position for live (2.04 KB, patch)
2017-01-24 06:58 UTC, Seungha Yang
none Details | Review
hls: m3u8: Set sequence position for live (2.62 KB, patch)
2017-01-24 11:52 UTC, Seungha Yang
none Details | Review
hlsdemux: Consider timestamp of the first fragment in playlist when live seeking (1.19 KB, patch)
2017-01-24 11:52 UTC, Seungha Yang
committed Details | Review
hls: Exclusion of last three fragment in case of live playback (2.55 KB, patch)
2017-01-24 12:34 UTC, Seungha Yang
committed Details | Review
hls: m3u8: Set sequence position for live (2.13 KB, patch)
2017-01-25 01:04 UTC, Seungha Yang
none Details | Review
tests: hlsdemux_m3u: Fix live startup sequence and seek range (1.98 KB, patch)
2017-01-27 00:28 UTC, Seungha Yang
none Details | Review
hls: m3u8: Set sequence position for live (2.09 KB, patch)
2017-01-27 00:29 UTC, Seungha Yang
committed Details | Review
tests: hlsdemux: Fix live startup sequence and seek range (1.97 KB, patch)
2017-01-27 00:40 UTC, Seungha Yang
committed Details | Review

Description Seungha Yang 2017-01-24 06:57:50 UTC
hls live starts playback from the allowed latest fragment,
but its "sequence position" is set to zero, and so stream
time is also set to zero.

This does not make sense, because hls live allows seeking to past position,
and it's negative stream time from downstream element's point of view.
Note that, allowed seekable range (and seeking query) is
from the first fragment of playlist to the allowed latest fragment.
Comment 1 Seungha Yang 2017-01-24 06:58:53 UTC
Created attachment 344095 [details] [review]
hls: m3u8: Set sequence position for live
Comment 2 Sebastian Dröge (slomo) 2017-01-24 10:42:27 UTC
Review of attachment 344095 [details] [review]:

::: ext/hls/m3u8.c
@@ +765,3 @@
       for (i = 0; i < GST_M3U8_LIVE_MIN_FRAGMENT_DISTANCE - 1 && file->prev;
+          ++i) {
+        sequence_pos -= GST_M3U8_MEDIA_FILE (file->data)->duration;

You should probably check here that sequence_pos never becomes < 0 (i.e. wraps around)
Comment 3 Seungha Yang 2017-01-24 11:52:01 UTC
Created attachment 344131 [details] [review]
hls: m3u8: Set sequence position for live
Comment 4 Seungha Yang 2017-01-24 11:52:54 UTC
Created attachment 344132 [details] [review]
hlsdemux: Consider timestamp of the first fragment in playlist when live seeking

During live playback, the first fragment in a updated
playlist can be advanced from that of startup playlist.
Meanwhile, since hlsdemux finds target seek position
by just accumulating fragment's duration, the base should
be adjusted to the updated first fragment's timestamp.
Comment 5 Seungha Yang 2017-01-24 12:34:31 UTC
Created attachment 344148 [details] [review]
hls: Exclusion of last three fragment in case of live playback

HLS spec 6.3.3 is saying that
"the client SHOULD NOT choose a segment which starts less than
three target durations from the end of the Playlist file."

To ensure above statement, the third fragment from the end of playlist
should be excluded from seekable range and also from available starting fragment.
(i.e., the fourth fragment from end of playlist is the starting fragment).
Comment 6 Seungha Yang 2017-01-24 12:43:31 UTC
(In reply to Seungha Yang from comment #5)
> Created attachment 344148 [details] [review] [review]
> hls: Exclusion of last three fragment in case of live playback
> 

Current hlsdemux starts from the 4th fragment of the end of playlist.
But, m3u8 parser set the starting fragment to the 3rd one always, and go back it to the 4th in hlsdemux. It seems weird to me.. 

 12 0:00:01.589298541 29752      0x1203ca0 DEBUG                    hls m3u8.c:746:gst_m3u8_update: Live playlist range 0:00:00.000000000 -> 0:05:00.000000000
 13 0:00:01.589317656 29752      0x1203ca0 DEBUG                    hls m3u8.c:773:gst_m3u8_update: first sequence: 358891
 14 0:00:01.589325910 29752      0x1203ca0 LOG                      hls m3u8.c:777:gst_m3u8_update: processed media playlist 01.m3u8, 30 fragments
 15 0:00:01.589339508 29752      0x1203ca0 DEBUG               hlsdemux gsthlsdemux.c:1455:gst_hls_demux_update_playlist:<hlsdemux0> sequence:358891 , first_sequence:358864 , last_sequence:358893
 16 0:00:01.589350707 29752      0x1203ca0 DEBUG               hlsdemux gsthlsdemux.c:1462:gst_hls_demux_update_playlist:<hlsdemux0> Sequence is beyond playlist. Moving back to 358890

Also, following code check equality but there is nothing changed if they are equal. However, still print updating log
https://cgit.freedesktop.org/gstreamer/gst-plugins-bad/tree/ext/hls/gsthlsdemux.c#n1456
Comment 7 Seungha Yang 2017-01-24 15:20:40 UTC
Comment on attachment 344131 [details] [review]
hls: m3u8: Set sequence position for live

This patch's sequence position setting is wrong, I will update soon.
Comment 8 Seungha Yang 2017-01-25 01:04:35 UTC
Created attachment 344195 [details] [review]
hls: m3u8: Set sequence position for live
Comment 9 Sebastian Dröge (slomo) 2017-01-26 12:00:55 UTC
Comment on attachment 344195 [details] [review]
hls: m3u8: Set sequence position for live

This does not apply to latest GIT master
Comment 10 Sebastian Dröge (slomo) 2017-01-26 12:16:24 UTC
Review of attachment 344195 [details] [review]:

::: ext/hls/m3u8.c
@@ +760,3 @@
 
+      sequence_pos =
+          self->last_file_end - GST_M3U8_MEDIA_FILE (file->data)->duration;

Why would that never be negative?

@@ +771,2 @@
         file = file->prev;
+        sequence_pos -= GST_M3U8_MEDIA_FILE (file->data)->duration;

And this?
Comment 11 Sebastian Dröge (slomo) 2017-01-26 12:23:17 UTC
Comment on attachment 344148 [details] [review]
hls: Exclusion of last three fragment in case of live playback

This also breaks the unit test

Running suite(s): hlsdemux_m3u8
0:00:00.019038343 20758 0x55fa9c4e5e90 WARN            hlsdemux_m3u m3u8.c:1414:gst_hls_master_playlist_new_from_data: Data doesn't start with #EXTM3U
0:00:00.023648468 20761 0x55fa9c4e5e90 WARN            hlsdemux_m3u m3u8.c:1553:gst_hls_master_playlist_new_from_data: variant stream without uri, dropping
0:00:00.035432128 20771 0x55fa9c4e5e90 WARN            hlsdemux_m3u m3u8.c:576:gst_m3u8_update: EXTINF duration (0:00:10.321000000) > TARGETDURATION (0:00:10.000000000)
0:00:00.035466645 20771 0x55fa9c4e5e90 WARN            hlsdemux_m3u m3u8.c:576:gst_m3u8_update: EXTINF duration (0:00:10.234400000) > TARGETDURATION (0:00:10.000000000)
0:00:00.036834068 20772 0x55fa9c4e5e90 WARN            hlsdemux_m3u m3u8.c:654:gst_m3u8_update: Encryption method NONE not supported
0:00:00.038077800 20773 0x55fa9c4e5e90 WARN            hlsdemux_m3u m3u8.c:476:gst_m3u8_update: Data doesn't start with #EXTM3U
92%: Checks: 25, Failures: 2, Errors: 0
elements/hlsdemux_m3u8.c:520:F:m3u8client:test_live_playlist:0: 'pl->sequence' (2680) is not equal to '2681' (2681)
elements/hlsdemux_m3u8.c:555:F:m3u8client:test_live_playlist_rotated:0: 'pl->sequence' (2680) is not equal to '2681' (2681)
Comment 12 Seungha Yang 2017-01-27 00:28:34 UTC
Created attachment 344371 [details] [review]
tests: hlsdemux_m3u: Fix live startup sequence and seek range
Comment 13 Seungha Yang 2017-01-27 00:29:35 UTC
Created attachment 344372 [details] [review]
hls: m3u8: Set sequence position for live
Comment 14 Seungha Yang 2017-01-27 00:34:51 UTC
(In reply to Sebastian Dröge (slomo) from comment #10)
> Review of attachment 344195 [details] [review] [review]:
> 
> ::: ext/hls/m3u8.c
> @@ +760,3 @@
>  
> +      sequence_pos =
> +          self->last_file_end - GST_M3U8_MEDIA_FILE (file->data)->duration;
> 
> Why would that never be negative?

It doesn't make sense that it is negative at that moment, but for safe,
I added one more condition :)

> 
> @@ +771,2 @@
>          file = file->prev;
> +        sequence_pos -= GST_M3U8_MEDIA_FILE (file->data)->duration;
> 
> And this?

Since for loop is checking the file duration, it never be negative
At line 768

for (i = 0; i < GST_M3U8_LIVE_MIN_FRAGMENT_DISTANCE && file->prev &&
     GST_M3U8_MEDIA_FILE (file->prev->data)->duration <= sequence_pos;
     ++i) {
....


Please apply "hls: m3u8: Set sequence position for live" on top of 
"hls: Exclusion of last three fragment in case of live playback"
Comment 15 Seungha Yang 2017-01-27 00:35:43 UTC
(In reply to Sebastian Dröge (slomo) from comment #11)
> Comment on attachment 344148 [details] [review] [review]
> hls: Exclusion of last three fragment in case of live playback
> 
> This also breaks the unit test

Please refer to "tests: hlsdemux_m3u: Fix live startup sequence and seek range"

I modified unit test code.
Comment 16 Seungha Yang 2017-01-27 00:40:33 UTC
Created attachment 344373 [details] [review]
tests: hlsdemux: Fix live startup sequence and seek range
Comment 17 Sebastian Dröge (slomo) 2017-01-31 11:24:36 UTC
Attachment 344132 [details] pushed as e9e6e4a - hlsdemux: Consider timestamp of the first fragment in playlist when live seeking
Attachment 344148 [details] pushed as de86258 - hls: Exclusion of last three fragment in case of live playback
Attachment 344372 [details] pushed as b5cf96f - hls: m3u8: Set sequence position for live
Attachment 344373 [details] pushed as d59571e - tests: hlsdemux: Fix live startup sequence and seek range