## Context

We are creating our own Low Latency Hls server using ByteRange mode. We are having problems with some fragments that in
the manifest already has a defined range, but at the moment of requesting them they are still incomplete (they are not
preload hint fragments).

This behavior happens so often that we had to validate the range of bytes requested vs. the current size of the segment
in our server. If the requested bytes are not yet there we need to wait for Gpac to finish writing them.

We are not clear if this behavior is normal.
If the fragments have a byte range defined in the manifest does not mean that they are already ready in that range of
bytes?
(I clarify again that we are not talking about preload hint fragments)

We have been testing with some players and in all of them, we have seen the same behavior.

## Evidence

The player got a playlist like this:

```
#EXTM3U
#EXT-X-TARGETDURATION:2
#EXT-X-VERSION:9
#EXT-X-SERVER-CONTROL:CAN-BLOCK-RELOAD=YES,CAN-SKIP-UNTIL=12,PART-HOLD-BACK=0.630
#EXT-X-PART-INF:PART-TARGET=0.210000
#EXT-X-MEDIA-SEQUENCE:88
#EXT-X-SKIP:SKIPPED-SEGMENTS=8
#EXTINF:2.00600,
segment_track2_96.m4s
#EXTINF:1.98400,
segment_track2_97.m4s
#EXTINF:2.00500,
segment_track2_98.m4s
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_99.m4s",BYTERANGE="4294@0"
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_99.m4s",BYTERANGE="3051@4294"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_99.m4s",BYTERANGE="2658@7345"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_99.m4s",BYTERANGE="2724@10003"
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_99.m4s",BYTERANGE="3320@12727"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_99.m4s",BYTERANGE="3680@16047"
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_99.m4s",BYTERANGE="3036@19727"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_99.m4s",BYTERANGE="2761@22763"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_99.m4s",BYTERANGE="2809@25524"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_99.m4s",BYTERANGE="2711@28333"
#EXTINF:2.00500,
segment_track2_99.m4s
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_100.m4s",BYTERANGE="3920@0"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_100.m4s",BYTERANGE="2806@3920"
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_100.m4s",BYTERANGE="3099@6726"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_100.m4s",BYTERANGE="2760@9825"
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_100.m4s",BYTERANGE="3249@12585"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_100.m4s",BYTERANGE="3344@15834"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_100.m4s",BYTERANGE="2813@19178"
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_100.m4s",BYTERANGE="3065@21991"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_100.m4s",BYTERANGE="2826@25056"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_100.m4s",BYTERANGE="2786@27882"
#EXTINF:2.00600,
segment_track2_100.m4s
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_101.m4s",BYTERANGE="3958@0"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_101.m4s",BYTERANGE="2777@3958"
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_101.m4s",BYTERANGE="3134@6735"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_101.m4s",BYTERANGE="2785@9869"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_101.m4s",BYTERANGE="2775@12654"
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_101.m4s",BYTERANGE="4025@15429"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_101.m4s",BYTERANGE="2841@19454"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_101.m4s",BYTERANGE="2724@22295"
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_101.m4s",BYTERANGE="2951@25019"
#EXT-X-PART:DURATION=0.16800,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_101.m4s",BYTERANGE="2438@27970"
#EXTINF:1.98400,
segment_track2_101.m4s
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_102.m4s",BYTERANGE="4093@0"
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_102.m4s",BYTERANGE="3111@4093"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_102.m4s",BYTERANGE="2797@7204"
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_102.m4s",BYTERANGE="3030@10001"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_102.m4s",BYTERANGE="2774@13031"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_102.m4s",BYTERANGE="3601@15805"
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_102.m4s",BYTERANGE="3084@19406"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_102.m4s",BYTERANGE="2704@22490"
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_102.m4s",BYTERANGE="3103@25194"
#EXT-X-PART:DURATION=0.16800,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_102.m4s",BYTERANGE="2412@28297"
#EXTINF:2.00500,
segment_track2_102.m4s
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_103.m4s",BYTERANGE="3996@0"
#EXT-X-PRELOAD-HINT:TYPE=PART,URI="lowLatencySeg.m4s?segment=segment_track2_103.m4s",BYTERANGE-START=3996
#EXT-X-RENDITION-REPORT:URI="playlist_2.m3u8",LAST-MSN=102,LAST-PART=10
#
```

The segment_track2_103.m4s is supposed to have its Part 0 or first fragment with a defined range and already written
from 0 to 3996 Bytes.

The player requests that fragment by sending in the headers `Range: Bytes=0-3995`

![requestOfThePlayer](https://user-images.githubusercontent.com/34746520/199320089-e8c185c8-c1aa-4584-914e-6f454ad2b435.png)

Our server handles the request and validates the current size of the segment vs. the range of bytes being requested. In
the next image we can see that the segment has a size of `196 bytes` and the fragment that was requested has a range from
`0 to 3995 bytes` i.e. **it is not ready yet**, and we will have to wait until Gpac finishes writing it.

![logFromTheServer](https://user-images.githubusercontent.com/34746520/199320035-ee1dd612-7e93-4fd8-aee6-a4e9ca200203.png)


We would like to know why this is happening, the fragment is not ready yet, but in the playlist, it says it is ready...

This is our command:
```gpac -i 'rtmp://nginx/playback' -o http://origin:8080/live/public/playlist.mpd:gpac:dual=1:segdur=2:cdur=0.2:asto=1.8:llhls=br:hlsc=1:cmaf=cmf2:profile=dashif.ll:dmode=dynamic:template=segment:hmode=push:rdirs=gmem```


Gpac ll-hls advertising byte range segments that are not ready yet
This is a GitHub Issue
repo:gpac
owner:gpac
Title : Gpac ll-hls advertising byte range segments that are not ready yet
Issue date:

--- start body ---
## Context

We are creating our own Low Latency Hls server using ByteRange mode. We are having problems with some fragments that in
the manifest already has a defined range, but at the moment of requesting them they are still incomplete (they are not
preload hint fragments).

This behavior happens so often that we had to validate the range of bytes requested vs. the current size of the segment
in our server. If the requested bytes are not yet there we need to wait for Gpac to finish writing them.

We are not clear if this behavior is normal.
If the fragments have a byte range defined in the manifest does not mean that they are already ready in that range of
bytes?
(I clarify again that we are not talking about preload hint fragments)

We have been testing with some players and in all of them, we have seen the same behavior.

## Evidence

The player got a playlist like this:

```
#EXTM3U
#EXT-X-TARGETDURATION:2
#EXT-X-VERSION:9
#EXT-X-SERVER-CONTROL:CAN-BLOCK-RELOAD=YES,CAN-SKIP-UNTIL=12,PART-HOLD-BACK=0.630
#EXT-X-PART-INF:PART-TARGET=0.210000
#EXT-X-MEDIA-SEQUENCE:88
#EXT-X-SKIP:SKIPPED-SEGMENTS=8
#EXTINF:2.00600,
segment_track2_96.m4s
#EXTINF:1.98400,
segment_track2_97.m4s
#EXTINF:2.00500,
segment_track2_98.m4s
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_99.m4s",BYTERANGE="4294@0"
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_99.m4s",BYTERANGE="3051@4294"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_99.m4s",BYTERANGE="2658@7345"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_99.m4s",BYTERANGE="2724@10003"
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_99.m4s",BYTERANGE="3320@12727"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_99.m4s",BYTERANGE="3680@16047"
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_99.m4s",BYTERANGE="3036@19727"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_99.m4s",BYTERANGE="2761@22763"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_99.m4s",BYTERANGE="2809@25524"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_99.m4s",BYTERANGE="2711@28333"
#EXTINF:2.00500,
segment_track2_99.m4s
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_100.m4s",BYTERANGE="3920@0"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_100.m4s",BYTERANGE="2806@3920"
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_100.m4s",BYTERANGE="3099@6726"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_100.m4s",BYTERANGE="2760@9825"
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_100.m4s",BYTERANGE="3249@12585"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_100.m4s",BYTERANGE="3344@15834"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_100.m4s",BYTERANGE="2813@19178"
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_100.m4s",BYTERANGE="3065@21991"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_100.m4s",BYTERANGE="2826@25056"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_100.m4s",BYTERANGE="2786@27882"
#EXTINF:2.00600,
segment_track2_100.m4s
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_101.m4s",BYTERANGE="3958@0"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_101.m4s",BYTERANGE="2777@3958"
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_101.m4s",BYTERANGE="3134@6735"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_101.m4s",BYTERANGE="2785@9869"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_101.m4s",BYTERANGE="2775@12654"
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_101.m4s",BYTERANGE="4025@15429"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_101.m4s",BYTERANGE="2841@19454"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_101.m4s",BYTERANGE="2724@22295"
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_101.m4s",BYTERANGE="2951@25019"
#EXT-X-PART:DURATION=0.16800,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_101.m4s",BYTERANGE="2438@27970"
#EXTINF:1.98400,
segment_track2_101.m4s
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_102.m4s",BYTERANGE="4093@0"
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_102.m4s",BYTERANGE="3111@4093"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_102.m4s",BYTERANGE="2797@7204"
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_102.m4s",BYTERANGE="3030@10001"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_102.m4s",BYTERANGE="2774@13031"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_102.m4s",BYTERANGE="3601@15805"
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_102.m4s",BYTERANGE="3084@19406"
#EXT-X-PART:DURATION=0.18900,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_102.m4s",BYTERANGE="2704@22490"
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_102.m4s",BYTERANGE="3103@25194"
#EXT-X-PART:DURATION=0.16800,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_102.m4s",BYTERANGE="2412@28297"
#EXTINF:2.00500,
segment_track2_102.m4s
#EXT-X-PART:DURATION=0.21000,INDEPENDENT=YES,URI="lowLatencySeg.m4s?segment=segment_track2_103.m4s",BYTERANGE="3996@0"
#EXT-X-PRELOAD-HINT:TYPE=PART,URI="lowLatencySeg.m4s?segment=segment_track2_103.m4s",BYTERANGE-START=3996
#EXT-X-RENDITION-REPORT:URI="playlist_2.m3u8",LAST-MSN=102,LAST-PART=10
#
```

The segment_track2_103.m4s is supposed to have its Part 0 or first fragment with a defined range and already written
from 0 to 3996 Bytes.

The player requests that fragment by sending in the headers `Range: Bytes=0-3995`

![requestOfThePlayer](https://user-images.githubusercontent.com/34746520/199320089-e8c185c8-c1aa-4584-914e-6f454ad2b435.png)

Our server handles the request and validates the current size of the segment vs. the range of bytes being requested. In
the next image we can see that the segment has a size of `196 bytes` and the fragment that was requested has a range from
`0 to 3995 bytes` i.e. **it is not ready yet**, and we will have to wait until Gpac finishes writing it.

![logFromTheServer](https://user-images.githubusercontent.com/34746520/199320035-ee1dd612-7e93-4fd8-aee6-a4e9ca200203.png)


We would like to know why this is happening, the fragment is not ready yet, but in the playlist, it says it is ready...

This is our command:
```gpac -i 'rtmp://nginx/playback' -o http://origin:8080/live/public/playlist.mpd:gpac:dual=1:segdur=2:cdur=0.2:asto=1.8:llhls=br:hlsc=1:cmaf=cmf2:profile=dashif.ll:dmode=dynamic:template=segment:hmode=push:rdirs=gmem```


--- end body ---
