Commit Graph

267 Commits

Author SHA1 Message Date
Tristan Matthews eb9153b4a7 avformat/hls: fix spelling and grammar on wrap warning 2022-10-20 16:27:06 +05:30
Michael Niedermayer d32a9f3137
libavformat/hls: Free keys
Fixes: memleak
Fixes: 50703/clusterfuzz-testcase-minimized-ffmpeg_dem_HLS_fuzzer-6399058578636800

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Steven Liu <lingjiujianke@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-09-10 17:32:47 +02:00
Li Kai df8ad4e391 avformat/hls: add #EXT-X-START tag support by prefer_x_start opt
Reviewed-by: Steven Liu <liuqi05@kuaishou.com>
Signed-off-by: Li Kai <wolfleekay@gmail.com>
2022-06-29 14:03:36 +08:00
Michael Niedermayer d8ee014254 avformat/hls: Limit start_seq_no to one bit less
This avoids overflow checks on additions with 32bit numbers

Fixes: signed integer overflow: 9223372036854775806 + 2 cannot be represented in type 'long'
Fixes: 44012/clusterfuzz-testcase-minimized-ffmpeg_dem_HLS_fuzzer-4747770734444544
Fixes: 48065/clusterfuzz-testcase-minimized-ffmpeg_dem_HLS_fuzzer-5372410355908608

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-06-23 22:03:02 +02:00
Andreas Rheinhardt e3580f6077 avformat/hls, dashdec: Don't use AV_OPT flags in av_dict_set()
av_dict_set() expects a different set of flags, namely the AV_DICT_*
flags. Using AV_OPT_FLAG_DECODING_PARAM (or any AV_OPT_FLAG_*) ic
av_dict_set() is therefore completely wrong and given that av_dict_set()
just doesn't care about whether the string it receives has anything
to do with a decoding parameter or not, it should just be removed
without replacement.
(The numerical value of AV_OPT_FLAG_DECODING_PARAM currently coincides
with AV_DICT_IGNORE_SUFFIX. Given that the dictionaries we are dealing
with here are always empty (i.e. NULL) before the calls to
av_dict_set(), this flag changes nothing. It would be different if
it were equal to one of the AV_DICT_DONT_STRDUP_* values.)

Reviewed-by: Jan Ekström <jeebjp@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-16 10:56:34 +02:00
Andreas Rheinhardt 35ec5c819b avformat/demux: Add new demux.h header
And move those stuff already in demuxer-only files to it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-10 07:37:38 +02:00
Andreas Rheinhardt 1dcd0adedd avformat: Remove unnecessary inclusions from libavcodec
Also improve the other headers a bit while at it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-03-23 23:45:39 +01:00
Michael Niedermayer a8fd3f7fab avformat/hls: Check target_duration
Fixes: signed integer overflow: 77777777777777 * 1000000 cannot be represented in type 'long long'
Fixes: 45545/clusterfuzz-testcase-minimized-ffmpeg_dem_HLS_fuzzer-6438101247983616

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Steven Liu <lingjiujianke@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-03-21 09:07:58 +01:00
Zhao Zhili 92053aa260 avformat/hls: add AVFMT_NO_BYTE_SEEK flag
After d6ac6650b9, ffplay failed to seek HLS stream with AVSEEK_FLAG_BYTE
enabled by default.

Signed-off-by: Marton Balint <cus@passwd.hu>
2022-03-21 00:48:30 +01:00
Martin Storsjö a78f136f3f configure: Use a separate config_components.h header for $ALL_COMPONENTS
This avoids unnecessary rebuilds of most source files if only the
list of enabled components has changed, but not the other properties
of the build, set in config.h.

Signed-off-by: Martin Storsjö <martin@martin.st>
2022-03-16 14:12:49 +02:00
Michael Niedermayer bf33a38499 avformat/hls: Use unsigned for iv computation
Fixes: signed integer overflow: 9223372036854775748 + 60 cannot be represented in type 'long'
Fixes: 44417/clusterfuzz-testcase-minimized-ffmpeg_dem_HLS_fuzzer-5802443881971712

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Steven Liu <lingjiujianke@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-02-09 10:50:35 +01:00
Gustav Grusell e78d0810d1 avformat/hls: Implement support for using AVSEEK_FLAG_BACKWARD when seeking
Before, seeking in hls streams would always seek to the next keyframe
after the given timestamp. With this fix, if seeking in videostream and
AVSEEK_FLAG_BACKWARD is set, seeking will be to the first keyframe of
the segment containing the given timestamp. This fixes #7485.

Signed-off-by: Gustav Grusell <gustav.grusell@gmail.com>
2022-02-09 13:49:23 +08:00
Andreas Rheinhardt ed18b8d79f avformat/hls: Remove redundant cast
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-21 16:47:38 +01:00
Pierre-Anthony Lemieux c8b5f2848d
avformat/aviobuf: ffio_copy_url_options
Signed-off-by: Pierre-Anthony Lemieux <pal@palemieux.com>
Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
2021-12-19 00:35:24 +10:00
Andreas Rheinhardt e38eaf4749 avformat/utils: Make ff_data_to_hex() zero-terminate the string
Most callers want it that way anyway.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-12-08 00:42:48 +01:00
Nachiket Tarate f14adb0516 libavformat/hls: correct indentation
Signed-off-by: Nachiket Tarate <nachiket.programmer@gmail.com>
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2021-10-13 11:24:02 +08:00
Nachiket Tarate ff958b3846 libavformat/hls: add support for decryption of HLS media segments encrypted using SAMPLE-AES encryption method
Apple HTTP Live Streaming Sample Encryption:

https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/HLS_Sample_Encryption

Signed-off-by: Nachiket Tarate <nachiket.programmer@gmail.com>
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2021-10-13 11:23:53 +08:00
Andreas Rheinhardt 40bdd8cc05 avformat: Avoid allocation for AVStreamInternal
Do this by allocating AVStream together with the data that is
currently in AVStreamInternal; or rather: Put AVStream at the
beginning of a new structure called FFStream (which encompasses
more than just the internal fields and is a proper context in its own
right, hence the name) and remove AVStreamInternal altogether.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-17 13:22:25 +02:00
Andreas Rheinhardt 45bfe8b838 avformat/avio: Move internal AVIOContext fields to avio_internal.h
Currently AVIOContext's private fields are all over AVIOContext.
This commit moves them into a new structure in avio_internal.h instead.
Said structure contains the public AVIOContext as its first element
in order to avoid having to allocate a separate AVIOContextInternal
which is costly for those use cases where one just wants to access
an already existing buffer via the AVIOContext-API.
For these cases ffio_init_context() can't fail and always returned zero,
which was typically not checked. Therefore it has been made to not
return anything.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-25 23:01:54 +02:00
Andreas Rheinhardt 0a7e911108 avformat/hls: Simplify cleanup after read_header failure
by setting the FF_FMT_INIT_CLEANUP flag.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-07-07 21:51:40 +02:00
Gyan Doshi 51f1194eda avformat/hls: relay format options to segment demuxer
Signed-off-by: Gyan Doshi <ffmpeg@gyani.pro>
Reviewed-by: Steven Liu <lq@chinaffmpeg.org>
2021-05-30 09:21:19 +05:30
Limin Wang eb390d7f9d avformat/hls: use av_strncasecmp()
Reviewed-by: Steven Liu <lq@chinaffmpeg.org>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2021-05-07 23:23:23 +08:00
Andreas Rheinhardt bc70684e74 avformat: Constify all muxer/demuxers
This is possible now that the next-API is gone.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 11:48:06 -03:00
Andreas Rheinhardt 56450a0ee4 avformat: Constify the API wrt AV(In|Out)putFormat
Also constify AVProbeData.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:08 -03:00
Marton Balint 28c83584e8 avformat/hls: check return value of new_init_section()
Fixes part of ticket #8931.

Signed-off-by: Marton Balint <cus@passwd.hu>
2021-04-18 17:25:51 +02:00
James Almer f57a258223 avformat/hls: use av_packet_alloc() to allocate packets
Signed-off-by: James Almer <jamrial@gmail.com>
2021-03-17 15:06:49 -03:00
Ed Martin 63344337f9 libavformat/hls: Reset options after open_url_keepalive() fails
open_url_keepalive() unsets the options when it uses them, this
includes the offsets for the Range: header. When using the HLS
tag #EXT-X-BYTERANGE along with multiple files, the range options
must be preserved after open_url_keepalive() returns EOF so that
the new file can be opened. Failure to do this results in ignoring
the #EXT-X-BYTERANGE tag and reading the wrong bytes of the file.

To fix it, reset the options before calling io_open() following
open_url_keepalive() reaching EOF

Reviewed-by: Steven Liu <liuqi05@kuaishou.com>
2021-03-15 15:16:20 +08:00
Zhao Zhili 47327aa2d9 avformat/hls: change sequence number type to int64_t
Fix atoi() overflow for large EXT-X-MEDIA-SEQUENCE.

The spec says the type of sequence number is uint64_t. Use int64_t
here since current implementation requires it to be signed integer,
and hlsenc use int64_t too.
2021-01-24 10:55:29 +08:00
Steven Liu e7703ae335 avformat/hls: update comment of file description
reference link to rfc8216

Signed-off-by: liuqi05 <liuqi05@kuaishou.com>
2020-12-28 11:09:17 +08:00
bevis de59826703 libavformat/hls: use local var url for log to avoid crash
During operation, the user exits and interrupts,
causing pls->segment to be released,
resulting in a null pointer crash

Signed-off-by: bevis <javashu2012@gmail.com>
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2020-10-22 17:13:15 +08:00
Jun Zhao 5bf22519ce lavf/hls: add AC-3/EAC-3 to allowed extensions file list
Add AC-3/EAC-3 to allowed extensions file list.

From HTTP Live Streaming 2nd Edition draft-pantos-hls-rfc8216bis-07
section 3.1.3.Packed Audio, HLS demuxer need to support MP3/AC-3/EAC-3.

Reviewd-by: Steven Liu <liuqi05@kuaishou.com>
Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
2020-09-28 09:12:09 +08:00
Andreas Rheinhardt ac2852d795 avformat/dashdec, hls: Update correct pointer to AVDictionary
open_url() in the DASH as well in the hls demuxer share a common bug:
They modify an AVDictionary (i.e. set a new entry) given to them as
AVDictionary *, yet if this new entry leads to reallocation and
relocation of the AVDictionary, the caller's pointer will become
dangling, leading to use-after-frees. So pass an AVDictionary **.

(With the current implementation of AVDictionary the above can only
happen if the AVDictionary was empty initially (in which case the
new AVDictionary leaks); furthermore if the I/O is ordinary (i.e. opened
by avio_open2() or ffio_open_whitelist()), the dict is never empty (it
contains an rw_timeout entry from save_avio_options()). So this issue
could only happen if the caller sets a nondefault io_open callback, but
no AVIOContext (the AVFMT_FLAG_CUSTOM_IO flag won't be set in this
case). In case of the HLS demuxer, it was also necessary that setting
the "seekable" entry failed. Yet one should simply not rely on internals
of the AVDict API.)

Reviewed-by: Steven Liu <lq@chinaffmpeg.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-09-21 04:31:43 +02:00
Andreas Rheinhardt 97d8029149 avformat/hls: Use av_init_pkt() directly
and remove reset_packet(). The packet's data pointer is already zeroed,
so the only thing that reset_packet() does that av_init_pkt() doesn't is
redundant.

Reviewed-by: Steven Liu <lingjiujianke@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-18 07:03:00 +02:00
Andreas Rheinhardt 8c91b5c48a avformat/hls: Remove redundant resetting of AVPacket
av_read_frame() already returns blank packets on error.

Reviewed-by: Steven Liu <lingjiujianke@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-18 07:02:52 +02:00
Andreas Rheinhardt dfc6a9f075 avformat/hls: Fix memleak when url is empty
Fixes Coverity ID 1465888.

Reviewed-by: Steven Liu <lingjiujianke@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-18 07:02:43 +02:00
Steven Liu 6e4bba4055 avformat/hls: support avio_seek in encryption mode
Signed-off-by: Steven Liu <liuqi05@kuaishou.com>
2020-08-10 15:52:54 +08:00
Jun Zhao 4239a8c983 lavf/hls: enable custom interrup callback in sub-demuxer
Enable the custom callback in sub-demuxer

Reviewed-by: Steven Liu <lq@chinaffmpeg.org>
Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
2020-07-20 19:17:42 +08:00
Michael Niedermayer b5e39880fb avformat/hls: Pass a copy of the URL for probing
The segments / url can be modified by the io read when reloading

This may be an alternative or additional fix for Ticket8673
as a further alternative the reload stuff could be disabled during
probing

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-07-01 11:41:35 +02:00
vacingfang b7f3a7c439 lavf/hls: Add missed side data/disposition
hls demuxer get the stream info from sub-stream, but missed side
data/disposition part, e,g, missed the DOVI side data when the
stream is Dolby Vision streams.

Reviewed-by <liuqi05@kuaishou.com>
Signed-off-by: vacingfang <vacingfang@tencent.com>
2020-06-18 17:51:10 +08:00
Steven Liu 9dfb19baeb avformat/hls: check segment duration value of EXTINF
fix ticket: 8673
set the default EXTINF duration to 1ms if duration is smaller than 1ms

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2020-06-10 09:22:37 +08:00
Steven Liu ea1940c6e2 avformat/hls: check output string is usable of ff_make_absolute_url
fix ticket: 8688
should goto failed workflow if cannot get usable string by ff_make_absolute_url

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2020-06-10 09:22:29 +08:00
Andreas Rheinhardt 37140ebd87 avformat/id3v2: Remove unnecessary indirection
ff_id3v2_parse_apic/chapters/priv/priv_dict all had a parameter
extra_meta of type ID3v2ExtraMeta ** as if the functions wanted to make
*extra_meta point to something else. But they don't, so just use an
ID3v2ExtraMeta *.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-25 07:06:44 +02:00
Andreas Rheinhardt f08853b284 avformat/id3v2: Avoid allocations for ID3v2ExtraMeta
Up until now, the ID3v2ExtraMeta structure (which is used when parsing
ID3v2 tags containing attached pictures, chapters etc.) contained a
pointer to separately allocated data that depended on the type of the
tag. Yet the difference of the sizes of the largest and the smallest of
these structures is fairly small, so that it is better to simply include
a union of all the possible types of tag-dependent structures in
ID3v2ExtraMeta. This commit implements this.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-25 06:56:57 +02:00
Andreas Rheinhardt 9f6b738896 avformat/hls: Remove redundant resetting of pointer
ff_id3v2_free_extra_meta() takes a ID3V2ExtraMeta ** so that it can
already reset the pointer.

Reviewed-by: Jun Zhao <mypopy@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-20 23:18:50 +02:00
Andreas Rheinhardt 9dfc409e6b avformat/hls: Don't strdup non-null-terminated string
If an URI indicated that the data protocol was in use, it would be
copied into a temporary buffer via strncpy(dst, src, strlen(src)),
thereby ensuring that the trailing \0 would not be copied, despite dst
being uninitialized. dst would then be av_strdup'ed, leading to
potential segfaults.

The solution to this is simple: Don't copy the URI in the temporary
buffer at all, instead av_strdup it directly.

This fixes a -Wstringop-truncation warning emitted by GCC 9.2.

Reviewed-by: Steven Liu <lq@chinaffmpeg.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-03-24 21:22:15 +01:00
Andreas Rheinhardt 6a67d518d6 avformat: Remove unnecessary av_packet_unref()
Since bae8844e the packet will always be unreferenced when a demuxer
returns an error, so that a lot of calls to av_packet_unref() in lots of
demuxers are now redundant and can be removed.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Marton Balint <cus@passwd.hu>
2020-02-10 22:41:38 +01:00
Steven Liu b9606064c4 avformat/hls: support data protocol in uri for EXT-X-MAP
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2020-01-18 22:41:11 +08:00
Marvin Scholz c3bb6efef2 avformat/hls: propagate icy to child AVIOContexts
When the user decides they do not want to to send the Icy-MetaData
header, this should be respected for all requests, not just the first
one.

Fix #5578

Reviewed-by: Liu Steven <lq@chinaffmpeg.org>
Signed-off-by: James Almer <jamrial@gmail.com>
2019-12-27 14:57:25 -03:00
Andreas Rheinhardt 5b42d33571 avformat/hls: Use av_packet_move_ref() for packet ownership transfer
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-12-23 15:39:49 +08:00
Steven Liu afee801276 avformat/hls: correct grammatical errors of m3u8_hold_counters option
Suggested-by: Gyan <ffmpeg@gyani.pro>
Suggested-by: Rodney Baker <rodney.baker@iinet.net.au>
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-11-27 19:04:00 +08:00