aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/utils.c
Commit message (Collapse)AuthorAgeFilesLines
...
* avformat/utils: Find a fallback probe decoder that will also match a forced ↵Samuel Foss2020-06-041-1/+1
| | | | | | | | | decoder's codec. Prevent codecpar->codec_id from getting out of sync with the codec instantiated for probing. Signed-off-by: Samuel Foss <sfoss@google.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* lavf/utils: fix start_time/duration dump if it is AV_NOPTS_VALUEJun Zhao2020-05-301-8/+8
| | | | | | | | | | | | e,g: the command: ffprobe -show_format -i fate-suite/aac/foo.aac -loglevel 99 will dump the trace message as follow when start_time is AV_NOPTS_VALUE [aac @ 0x55bf8e1f3dc0] stream 0: start_time: -326791809695.818 duration: 2.174 [aac @ 0x55bf8e1f3dc0] format: start_time: -9223372036854.775 duration: 2.174 bitrate=120 kb/s after this fix, will dump the start_time with "NOPTS". Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
* avformat/utils: Use av_sat_add64() when updating start_time by skip_samples.Dale Curtis2020-05-291-2/+2
| | | | | | | Avoids overflow from fuzzed skip_samples values. Signed-off-by: Dale Curtis <dalecurtis@chromium.org> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/id3v2: Remove unnecessary indirectionAndreas Rheinhardt2020-05-251-3/+3
| | | | | | | | | 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>
* avformat/utils: Set stream side-data size even without side-dataAndreas Rheinhardt2020-05-221-0/+2
| | | | | Reviewed-by: James Almer <jamrial@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/utils: move is_intra_only() to header and rename to ff_is_intra_only()Limin Wang2020-05-061-2/+2
| | | | Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
* avformat/utils: change the duration to int64_t for update_initial_durationsLimin Wang2020-05-011-1/+1
| | | | | Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
* avformat: only allow a single bitstream filter when muxingMarton Balint2020-04-261-18/+6
| | | | | | | | | | | | Current muxers only use a single bitstream filter, so there is no need to maintain code which operates on a list of bitstream filters. When multiple bitstream filters are needed muxers can simply use a list bitstream filter. If there is a use case in the future when different bitstream filters should be added at subsequent packets then a new API possibly involving reconfiguring the list bitstream filter can be added knowing the exact requirements. Signed-off-by: Marton Balint <cus@passwd.hu>
* avformat/utils: Remove superfluous headersAndreas Rheinhardt2020-04-241-6/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | stdarg.h has been included in 780d7897a9c9295b43f1f0e9b49a11f99cd402c3 for ff_url_join(). This header became unnecessary when this function was moved into a separate file in df9f22d42b0905385629a9d368bb5a1eef2b45ef. libavutil/pixdesc.h has been included for av_get_pix_fmt_name() in 603b8bc2a109978c8499b06d2556f1433306eca7 and is unused since commit 2fb7501938b7103624c9bef740ca498258cacdab that removed the stuff belonging to FF_API_FORMAT_PARAMETERS. Notice that this file still uses AV_PIX_FMT_NONE and that therefore the header libavutil/pixfmt.h has been included (this header is included in pixdesc.h as well as also in libavutil/internal.h which is also included). libavutil/time_internal.h has been included for gmtime_r() in commit e7dd97b5d8cd6ea150446591f37a5946e8ab7cfb; it is unused since commit b72a7b96f84e5f16dd93b60668aecfda99442c71 which basically moved the code making use of gmtime_r() to libavutil/dict.c to use in avpriv_dict_set_timestamp(). audiointerleave.h has been added in c26e58e32cf430f060209e0d6088181f4426b3ce because of ff_interleave_compare_dts() (at that time the muxing code was not split from utils.c yet); said function became static in commit 101e1f6ff90c3365bfde05469ae26d2ee7f71f3e, making this header redundant. metadata.h has been mostly included for what now resides in libavutil/dict.h. The stuff that now resides in metadata.h has only been used briefly: From commits ed7694d8cf4633da444237f4df7efc48936419d2 to d60a9f52eb42dc76dea9996c8ba3567ae98a9a04. riff.h has been added in 45da8124a09d0ac5f9d8174884584c5f80309d0c because riff.h once contained declarations for (ff_)codec_get_tag(). This was changed in bfe5454cd238b16e7977085f880205229103eccb. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/utils: Fix memleak when decoding subtitle in find_stream_infoAndreas Rheinhardt2020-04-201-0/+2
| | | | | | | | | | | | | | | | | avformat_find_stream_info() may decode some frames to get stream information. And when it does this for subtitles, the decoded subtitles leak. (Decoding subtitles was added in b1511e00f6fefde6cb31b2e17f7812cfac1c8bd6 for PGS subtitles. When PGS subtitles originate from a container that exports every segment as a packet of its own, no output will be generated when decoding a packet, because not enough input is available. Yet when used with PGS subtitles in the Matroska form a single packet contains enough data to generate output. Yet said output is not freed, hence this leak.) Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* lavf/utils: stop using deprecated av_codec_next()Josh de Kock2020-04-201-1/+2
| | | | Signed-off-by: Josh de Kock <josh@itanimul.li>
* avformat/utils: Make find_stream_info get side data from codec contextNicolas Gaullier2020-03-201-0/+18
| | | | | | This will allow probing input coded side data, and also forwarding them to the output. Signed-off-by: Anton Khirnov <anton@khirnov.net>
* avformat/utils: Don't trigger errors for multiple id3 tags.Dale Curtis2020-02-221-8/+1
| | | | | | | | | | | | Such errors may make sense for specific formats, but general parsing logic shouldn't be treating these as errors regardless of the error recognition mode. Fixes loading of the following wave when using -err_detect explode: https://cs.chromium.org/chromium/src/third_party/blink/web_tests/external/wpt/webaudio/resources/4ch-440.wav Signed-off-by: Dale Curtis <dalecurtis@chromium.org> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/utils: Fix integer overflow with complex time bases in ↵Michael Niedermayer2020-02-161-1/+1
| | | | | | | | | | | avformat_find_stream_info() Fixes: signed integer overflow: 2045163756 * 2 cannot be represented in type 'int' Fixes: Ticket5132 Found-by: tsmith Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/utils: avoid unsigned integer overflowsPaul B Mahol2020-02-161-4/+6
|
* avformat/utils: make av_url_split search for hashmark as well to separate ↵Marton Balint2020-02-151-11/+3
| | | | | | | | | | | hostname RFC 3986 states that the generic syntax uses the slash ("/"), question mark ("?"), and number sign ("#") characters to delimit components that are significant to the generic parser's hierarchical interpretation of an identifier. Signed-off-by: Marton Balint <cus@passwd.hu>
* avformat/utils: Fix memleaks in avformat_open_input()Andreas Rheinhardt2020-02-151-6/+11
| | | | | | | | | | | | | | | A demuxer might have allocated memory while reading the header. If reading the header was successfull and an error happens before returning (e.g. when queueing the attached pictures), the read_close function would have never been called, so that all those allocations would leak. This commit changes this. Furthermore, there would be even more memleaks if the error level was set to AV_EF_EXPLODE in case there is both metadata and id3v2 metadata. This has been fixed, too. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Marton Balint <cus@passwd.hu>
* avformat/utils: Fix undefined behavior in ff_configure_buffers_for_index()Dale Curtis2020-02-111-1/+3
| | | | | | | | When e2_pts == INT64_MIN and e1_pts >= 0 the calculation of e2_pts - e1_pts will overflow an int64_t. Signed-off-by: Dale Curtis <dalecurtis@chromium.org> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/utils: log corrupt packetsGyan Doshi2020-01-231-6/+9
|
* Revert "avformat/utils: make ff_ntp_time() accept a timestamp as input argument"James Almer2020-01-161-2/+2
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/utils: make ff_ntp_time() accept a timestamp as input argumentJames Almer2020-01-151-2/+2
| | | | | | Will be needed by the next patch. Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/utils: Remove redundant save+restoreAndreas Rheinhardt2020-01-081-2/+0
| | | | | | | | | | | | If the size of the input packet is zero, av_grow_packet() used to call av_new_packet() which would initialize the packet and (in particular) reset the pos field. This behaviour (which was never documented and arguably always contradicted the documented behaviour) was changed in 2fe04630. This means that it is unnecessary to save and restore the packet's position in append_packet_chunked(). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* Silence "string-plus-int" warning shown by clang.Carl Eugen Hoyos2020-01-061-1/+1
| | | | libswscale/utils.c:89:42: warning: adding 'unsigned long' to a string does not append to the string [-Wstring-plus-int]
* avformat: Don't free old extradata before ff_alloc/get_extradataAndreas Rheinhardt2019-12-121-1/+0
| | | | | | | | These functions already free it themselves before they allocate the new extradata. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat: Forward errors where possibleAndreas Rheinhardt2019-12-121-3/+3
| | | | | | | | | | It is not uncommon to find code where the caller thinks to know better what the return value should be than the callee. E.g. something like "if (av_new_packet(pkt, size) < 0) return AVERROR(ENOMEM);". This commit changes several instances of this to instead forward the actual error. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* lavc/codec_desc: introduce AV_CODEC_PROP_INTRA_ONLY flag to audio codecYuki Tsuchiya2019-12-121-1/+2
| | | | | | | Introduce AV_CODEC_PROP_INTRA_ONLY flag to audio codec as well as video codec to support non intra-only audio codec. Signed-off-by: Yuki Tsuchiya <Yuki.Tsuchiya@sony.com> Signed-off-by: James Almer <jamrial@gmail.com>
* libavformat/utils: Fix code indentationLinjie Fu2019-12-031-11/+11
| | | | | | | Introduced since 077939626eeaa0c1364065414c18ab9b3a072281. Signed-off-by: Linjie Fu <linjie.fu@intel.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat: Add max_probe_packets optionAndriy Gelman2019-11-031-3/+3
| | | | | | | Allows user to set maximum number of buffered packets when probing a codec. It was a hard-coded parameter before this commit. Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat: call AVOutputFormat->deinit() when freeing the contextJames Almer2019-10-211-0/+3
| | | | | | | | | | | | Despite the doxy stating that it's called when the muxer is destroyed, this was not true in practice. It's only called by av_write_trailer() and on init() failure. An AVFormatContext may be closed without writing the trailer if errors ocurred while muxing packets, so in order to prevent memory leaks, it should effectively be called when freeing the muxer. Signed-off-by: James Almer <jamrial@gmail.com>
* lavf/utils: support duration estimate method dumpJun Zhao2019-09-301-1/+14
| | | | | | | | add new function duration_estimate_name to dump duration estimate method, it's will help to debug some duration issue. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
* lavf/utils: Cosmetics: fix indentation for estimate_timingsJun Zhao2019-09-301-3/+3
| | | | | | fix indentation for estimate_timings when dump start_time/duartion. Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
* lavf/utils: correct the duration estimation method for nut demuxerJun Zhao2019-09-301-1/+5
| | | | | | in fact, nut demuxer use the PTS for duration estimation. Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
* lavf/utils: change the log level to warning if can't get durationJun Zhao2019-09-301-2/+2
| | | | | | | | change the log level to warning if can't get duration, it's will help to debug some duration issue Signed-off-by: vacingfang <vacingfang@tencent.com> Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
* avformat/utils: Remove unnecessary initializationsAndreas Rheinhardt2019-09-281-7/+5
| | | | | | | | | | | | | | | | | | | | Up until now, read_frame_internal always initialized the packet it received. But since the recent changes to ff_read_packet, this is no longer needed: If the parsing queue is initially empty upon entering read_frame_internal, the packet will now either contain content upon success or be blank upon failure of ff_read_packet. If the parsing queue is initially not empty, the packet will be overwritten with the oldest one from the parsing queue. Similarly, it is unnecessary to initialize ret in read_frame_internal. In parse_packet, it is easily possible to only initialize the packet used as temporary storage for the output if said packet is used at all; furthermore, this packet doesn't need to be zero-initialized, because av_init_packet will initialize every field except size and data and those fields will be set by av_parser_parse2. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/utils: Improve parsing packetsAndreas Rheinhardt2019-09-281-15/+13
| | | | | | | | | | | | Up until now, parse_packet() used a stack packet in case the stream is flushed. But using such a packet is unnecessary as there is an AVPacket readily available, it just needs to be used. Whether flushing is intended or not will now be signalled by an explicit parameter rather than by whether the packet parameter is NULL. This removes a few checks in parse_packet(), gets rid of the initialization of the stack packet and also reduces usage of sizeof(AVPacket) in libavformat. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/utils: Avoid copying packets unnecessarilyAndreas Rheinhardt2019-09-281-23/+18
| | | | | | | | | | | | | | | | | | | | | | | | Up until now, read_frame_internal in avformat/utils.c uses a spare packet on the stack that serves no real purpose: At no point in this function is there a need for another packet besides the packet destined for output: 1. If the packet doesn't need a parser, but is output as is, the content of the spare packet (that at this point contains a freshly read packet) is simply copied into the output packet (via simple assignment, not av_packet_move_ref, thereby confusing ownership). 2. If the packet needs parsing, the spare packet will be reset after parsing and any packets resulting from the packet read will be put into a packet list; the output packet is not used here at all. 3. If the stream should be discarded, the spare packet will be unreferenced; the output packet is not used here at all either. Therefore the spare packet and the copies can be removed in principle. In practice, one more thing needs to be taken care of: If ff_read_packet failed, the output packet was not affected, now it is. But given that ff_read_packet returns a blank (as if reset via av_packet_unref) packet on failure, there is no problem from this side either. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/utils: Don't create unnecessary referencesAndreas Rheinhardt2019-09-281-3/+4
| | | | | | | | | When AVFMT_FLAG_GENPTS is set, av_read_frame would put a reference to a packet in the packet list (via av_packet_ref) and then immediately thereafter unreference the original packet. This has been changed to move the reference instead. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/utils: Fix memleaks IIAndreas Rheinhardt2019-09-281-3/+7
| | | | | | | | | | | Up until now, avformat_find_stream_info had a potential for memleaks: When everything was fine, it read packets and (depending upon whether AVFMT_FLAG_NOBUFFER was set) put them in a packet list or unreferenced them when they were no longer needed. But upon failure, said packets would leak if they were not already on the packet list. This patch fixes this. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/utils: Don't initialize in loopsAndreas Rheinhardt2019-09-281-4/+6
| | | | | | | | | | | | | | | | Since the recent changes to ff_packet_list_put, the source packet will be automatically reset when the reference is moved to the packet list, so that it is unnecessary to reinitialize the packet in the loops in parse_packet and ff_read_packet; initializing once at the beginning is enough. This also fixes a potential, but currently unexisting problem: If the raw packet buffer was initially not empty and probe_codec() failed, then the packet returned would not be initialized. But given that probe_codec() currently can't fail (always returns 0) this was not an acute danger. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/utils: ensure that all packets in AVPacketList are reference countedAndreas Rheinhardt2019-09-251-0/+5
| | | | | | | This is done so that its data is really owned by the packet. This was already true for the current callers. Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/utils: Move the reference to the packet listAndreas Rheinhardt2019-09-251-15/+17
| | | | | | | | | | | | | | | | | Up until now, ff_packet_list_put had a flaw: When it moved a packet to the list (meaning, when it ought to move the reference to the packet list instead of creating a new one via av_packet_ref), it did not reset the original packet, confusing the ownership of the data in the packet. This has been done because some callers of this function were not compatible with resetting the packet. This commit changes these callers and fixes this flaw. In order to indicate that the ownership of the packet has moved to the packet list, pointers to constant AVPackets are used whenever the target of the pointer might already be owned by the packet list. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/utils: unref packet on AVInputFormat.read_packet() failureJames Almer2019-09-251-0/+2
| | | | | | | | Demuxers may have allocated a packet before encountering an error and aborting. Fixes ticket #8150 Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/utils: Fix memleaksAndreas Rheinhardt2019-09-251-4/+12
| | | | | | | | | | | | | | ff_read_packet had potential memleaks: 1. If av_packet_make_refcounted fails, it means that the packet is not refcounted, but it could nevertheless carry side data and therefore needs to be unreferenced. 2. If putting a packet on a packet list fails, it wasn't unreferenced. Furthermore, read_frame_internal leaked a packet's (side) data if a context update was required and failed. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/utils: Assert that stream_index is validAndreas Rheinhardt2019-09-251-4/+2
| | | | | | | | | | | There is currently an ordinary check for this (which would lead to a memleak), but given that no demuxer should ever return a packet with an invalid stream_index it is more appropriate for this to be an assert. FATE passes with this change. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/utils: Do not assume duration is non negative in compute_pkt_fields()Michael Niedermayer2019-09-241-4/+4
| | | | | | | | | | Several subtitle demuxers set negative durations Fixes: signed integer overflow: 9223372036854775807 - -1 cannot be represented in type 'long' Fixes: 16925/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5766519790764032 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/utils: Preserve integrity of linked listAndreas Rheinhardt2019-09-181-4/+3
| | | | | | | | | | | | | | | | 1. Instead of relying on ff_packet_list_get to get the oldest element in an AVPacketList, ff_read_packet used its own ad-hoc code. Said code forgot to set the end of the list to NULL if the last element of the list has been removed, thereby leaving the list in an inconsistent state. 2. Furthermore, if the list was not empty, the oldest element of the list would always be copied into another packet structure before it was known whether the oldest entry of the list would be removed. This makes the ownership confusing and potentially copies unnecessarily. Both of these issues have been fixed. ff_packet_list_get is used now. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/utils: return pending IO error on EOF in av_read_frame()Marton Balint2019-08-311-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | avio_feof() returns true both in case of actual EOF and in case of IO errors. Some demuxers (matroska) have special handling to be able to return the proper error for this exact reason, e.g.: if (avio_feof(pb)) { if (pb->error) { return pb->error; } else { return AVERROR_EOF; } } However, most of the demuxers do not, and they simply return AVERROR_EOF if avio_feof() is true, so there is a real chance that IO errors are mistaken for EOF. We might just say that the API user should always check the IO context error attribute on EOF to make sure no IO errors happened, but not even ffmpeg.c does this. It should be more intuitive to the API user if we simply return the IO error as the return value of av_read_frame() instead of AVERROR_EOF. Signed-off-by: Marton Balint <cus@passwd.hu>
* lavf/utils: fix error like "offset 0x1f85: partial file"tomajsjiang2019-08-151-1/+7
| | | | | | | | | fix error like "offset 0x1f85: partial file", the root cause is when read the mp4 file from http, and the moov in the end of the mp4 file, reconfig the buffer will drop some data. Signed-off-by: Jun Zhao <barryjzhao@tencent.com> Signed-off-by: Zhongxing Jiang <tomajsjiang@tencent.com>
* avformat/utils: Check rfps_duration_sum for overflowMichael Niedermayer2019-07-191-2/+4
| | | | | | | | Fixes: signed integer overflow: 9151595917793558550 + 297519050751678697 cannot be represented in type 'long' Fixes: 15496/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5722866475073536 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/utils: Check timebase before use in estimate_timings()Michael Niedermayer2019-07-081-0/+1
| | | | | | | | Fixes: division by 0 Fixes: 15480/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5746727434321920 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>