hls: Return all packets from a previous variant before moving on to the next one

This serves as a safeguard; normally we want to use the dts
comparison to interleave packets from all active variants. If that
dts comparison for some reason doesn't work as intended, make sure
that all packets in all variants for a certain sequence number have
been returned before moving on to the next one.

Signed-off-by: Martin Storsjö <martin@martin.st>
hls: Copy the time base from the chained demuxer

When a variant stream isn't mpegts but e.g. raw adts, the
default time base (90k) isn't correct.

Signed-off-by: Martin Storsjö <martin@martin.st>
hls: Don't check discard flags until the parent demuxer's streams actually exist

If passing the end of one segment while initializing the
chained demuxer, the parent demuxer's streams aren't set up
yet, so we can't recheck the discard flags.

Signed-off-by: Martin Storsjö <martin@martin.st>
hls: Set stream offset before opening a chained demuxer

This makes sure we don't accidentally check discard flags
for the wrong stream.

Signed-off-by: Martin Storsjö <martin@martin.st>
hls: Respect the different stream time bases when comparing dts

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>
hls: Create an AVProgram for each variant

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>
Merge commit 'eb33ba04e03d9f36e23fffd442510c824be709c3'

* commit 'eb33ba04e03d9f36e23fffd442510c824be709c3':
  hls: Return all packets from a previous variant before moving on to the next one

Conflicts:
	libavformat/hls.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
Merge commit 'cdd2d73d315ecaf19ff49e64c91923275f1bda68'

* commit 'cdd2d73d315ecaf19ff49e64c91923275f1bda68':
  hls: Don't check discard flags until the parent demuxer's streams actually exist
  hls: Copy the time base from the chained demuxer

Conflicts:
	libavformat/hls.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
Merge commit 'c11e33a3d9665dd1fc5dbdecdd03a4860ac6a622'

* commit 'c11e33a3d9665dd1fc5dbdecdd03a4860ac6a622':
  hls: Set stream offset before opening a chained demuxer

Conflicts:
	libavformat/hls.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
Merge commit '9d64f236292ba28018dd9afd2d57f8f944b33f81'

* commit '9d64f236292ba28018dd9afd2d57f8f944b33f81':
  hls: Respect the different stream time bases when comparing dts

Conflicts:
	libavformat/hls.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
Merge remote-tracking branch 'qatar/master'

* qatar/master:
  hls: Create an AVProgram for each variant

Conflicts:
	libavformat/hls.c

See: 23db5418ed2ebaddbbc57a45b81caa6e94724587
Merged-by: Michael Niedermayer <michaelni@gmx.at>
zmbv: use av_image_copy_plane()

Signed-off-by: Paul B Mahol <onemda@gmail.com>
Revert "bitstream: make vlc init of static tables thread safe."

This reverts commit 4b6869d6e0120c92253d525921f0e04361888e10.

Conflicts:

	libavcodec/bitstream.c

This code can cause assertion failures on artificial OOM situations
It will be replaced by a solution that doesnt have this issue in the
following commits.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
avcodec/ff_init_vlc_sparse: use a spinlock for thread sync

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
avcodec/ff_init_vlc_sparse: use a local array for static vlcs avoiding malloc()

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Fix compilation with --disable-everything --enable-shared.

Compilation with --disable-everything --enable-shared failed
on systems with VAAPI support with the following undefined
symbol in libavcodec/vaapi.o:
libavcodec/libavcodec.so: undefined reference to `ff_mpeg_draw_horiz_band'
huffyuvenc: BGRA support

Bug-Id: 452

Signed-off-by: Diego Biurrun <diego@biurrun.de>
hls: Store first_timestamp in units of AV_TIME_BASE

When first_timestamp was stored as-is, its actual time base
wasn't known later in the seek function.

Additionally, the logic (from 795d9594cfa) 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>
hls: Store all durations in AV_TIME_BASE

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>
hlsproto: Store all durations in AV_TIME_BASE

Also parse segment durations as floating point, which is allowed
since HLS version 3.

Signed-off-by: Martin Storsjö <martin@martin.st>