If there is no #EXT-X-BYTERANGE specified, there is no need to seek.
Seeking fails anyway for rtmp, because this protocol does not support
url_seek.
This fixes CNN.m3u from trac ticket 4797 (i.e. Debian bug #798189).
Reviewed-by: wm4 <nfxjfg@googlemail.com>
Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
Broken by commit ba12ba859a. This only
happens with HLS streams which use encryption and require preserving
cookies sent by the server.
Fixes trac issue #4846.
Comment was previously slightly incorrect.
Also, it was placed in the wrong location.
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Apparently, some live streams can delete segments too early, maybe
because the client is too far behind. In this case, it's better to skip
the segment, instead of returning EOF. (Yes, the HLS demuxer actually
returns AVERROR_EOF if opening the segment returns a 404 HTTP error.)
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
SAMPLE-AES encryption is not commonly used yet, but without this patch
ffmpeg is thinking that the hls segments are not encrypted which
produces broken files.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Not allocating the pls->ctx will crash in libavformat/hls.c:1410, where
it tries to dereference the field.
Sample: http://ec24.rtp.pt/liverepeater/rtpn.smil/playlist.m3u8
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
The ones left using av_gettime are NTP timestamps (for RTCP,
which is specified to send the actual current realtime clock
in RTCP SR packets), and the NUT muxer timestamper, which is
documented as using wallclock time.
Signed-off-by: Martin Storsjö <martin@martin.st>
ffurl_seek() will not work even when it should be a no-op, so do not
call it on crypto protocol.
Also replace use of ffurl_size() for the same reason.
Reported-by: Michael Schenk <Michael.Schenk@albistechnologies.com>
Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
Since we are basically seeking the AVIOContext under the subdemuxer, we
need to flush the subdemuxer to avoid old packets from being read from
the packet queue after the seek.
Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
Properly take stream_index into account so that a keyframe will be
looked for in the specified stream_index only.
Similarly, only check timestamp validity against the specified
stream_index.
Also remove code for stream_index == -1 case which does not actually
happen as it is handled by generic code.
This is based on an initial patch by James Deng.
Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
Do not try to delay opening newly required playlists until a segment
switch. Applications expect that newly selected undiscarded streams are
available immediately, especially with alternative rendition streams
(selectable audio/subtitle tracks).
One might think that delaying variant stream switch until a segment
switch would allow a "seamless" switch without us having to download a
specific segment from two different variant playlists. However, that is
not the case, since the application would have to keep the previous
stream available (undiscarded) until the first packet of the newly
selected stream arrives, but by that time the demuxer would have already
downloaded the next segment of both variants.
Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
As per spec 3.4.3 ("A client MUST NOT assume that segments with the same
sequence number in different Media Playlists contain matching content.")
we cannot use sequence numbers for packet ordering.
This can be seen e.g. in the subtitle streams of
bipbop_16x9_variant.m3u8 that have considerably longer segments and
therefore different numbering.
Since the code now exclusively syncs using timestamps that may wrap, add
some additional checking for that.
According to the HLS spec all the timestamps should be in 33-bit MPEG
format and synced together.
v2: cleaner wrap detection
v3: further wrap detection improvements
Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
While selecting a packet to return to caller in read_packet(), the code
corrects the timestamps for starting timestamps.
However, this is wrong, since for live streams the initial timestamps
might differ just because of the time delay between the retrieval of the
various Media Playlists.
Fortunately, spec 6.2.4 mandates that all variant streams must have
matching timestamps, so we do not need to correct for initial
timestamps.
Drop the correction code.
Note that ID3 timestamps were previously ignored, so this code was
previously actually needed.
Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
Check if the playlist is still needed just before requesting the next
segment instead of after exhausting the previous segment.
Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
Improve selection of the segment sequence number when restarting the
reception of a playlist after it was suspended due to being unneeded
(due to discard flags).
The current code assumes that each playlist contains matching data with
the same sequence number, while spec 3.4.3 specifically says that that
is not the case. Often subtitle playlists also have longer target
durations as well, causing the selection to be completely wrong.
Instead prefer using the playlist segment duration information for
non-live playlists, and other means if that is not possible.
Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
Seeking needs to be tracked on a per-playlist basis, since the resyncing
code in hls_read_packet() has to sync each playlist to the seek
timestamp instead of stopping after the first playlist has reached it.
Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
HLS provides MPEG TS timestamps via ID3 tags in the beginning of each
segment of elementary audio streams.
v2: fix issues with streams that have multiple ID3 tags
Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
Add support for EXT-X-BYTERANGE added in HLS protocol v4.
v2: Better comment explaining ffurl_seek call and fix cur_seg_offset not
being updated.
Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
Even if we returned AVERROR_EOF previously due to playlist no longer
being needed, we may still be called again, and we do not want to
trigger a segment download in that case.
Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
HLS protocol version 4 added alternative renditions to the
specification (e.g. alternative audio tracks).
The EXT-X-MEDIA tags can also contain metadata for "renditions" (i.e.
tracks) of the main Media Playlist.
Add support for those.
Note that the same rendition (AVStream) may be associated with multiple
variants (AVPrograms).
Alternative subtitle tracks will require additional work and are
therefore not enabled yet.
Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
Session data (cookies, user-agent) is not being sent on payload requests with
encrypted HLS streams This causes services like Akamai to give a 403 forbidden
when requesting the TS files, because they expect the same cookies
and user-agent on all requests
Not all "sub-playlists" are variant playlists (containing the same
content with a different bitrate, etc) in the current version of the HLS
specification. They can now also be alternative renditions, containing
e.g. alternative audio tracks etc.
Decouple playlists from variants to prepare for handling the new
features.
Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
This allows both the main playlist itself as well as the variant
playlists to handle redirects combined with relative URLs.
Signed-off-by: Martin Storsjö <martin@martin.st>
This allows the chained demuxer (or more precisely, the lavf
utility code) to better fill in timestamps on packets from
these, especially for cases where one stream is a raw ADTS
stream.
Signed-off-by: Martin Storsjö <martin@martin.st>
Also parse segment durations as floating point, which is allowed
since HLS version 3.
This is based on a patch by Zhang Rui.
Signed-off-by: Martin Storsjö <martin@martin.st>
When first_timestamp was stored as-is, its actual time base
wasn't known later in the seek function.
Additionally, the logic (from 795d9594cf) for scaling it
based on stream_index is flawed - stream_index in the seek
function only specifies which stream the seek timestamp refers
to, but obviously doesn't say anything about which stream
first_timestamp belongs to.
In the cases where stream_index was >= 0 and all streams had the
same time base, this didn't matter in practice.
Seeking taking first_timestamp into account is problematic
when one variant is mpegts (with real timestamps) and one variant
is raw ADTS (with timestamps only being accumulated packet
duration), where the variants start at totally different timestamps.
Signed-off-by: Martin Storsjö <martin@martin.st>
Without the information, an application may choose audio from one
variant and video from another variant, which leads to fetching two
variants from the network. This enables av_find_best_stream() to find
matching audio and video streams, so that only one variant is fetched.
Signed-off-by: Martin Storsjö <martin@martin.st>
Also adjust the streams timestamps according to their start
timestamp when comparing. This helps getting correctly interleaved
packets if one stream lacks timestamps (such as a plain ADTS
stream when the other variants are full mpegts) when the others
have timestamps that don't start from zero.
This probably doesn't work properly if such a stream is
temporarily disabled (via the discard flags) and then reenabled,
and such streams are hard to correctly sync against the other
streams as well - but this works better than before at least.
The segment number restriction makes sure all variants advance
roughly at the same pace as well.
Signed-off-by: Martin Storsjö <martin@martin.st>