summaryrefslogtreecommitdiff
path: root/libavformat/utils.c
Commit message (Collapse)AuthorAge
* libavformat/utils: Fix code indentationLinjie Fu2019-12-03
| | | | | | | 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-03
| | | | | | | 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-21
| | | | | | | | | | | | 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-30
| | | | | | | | 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-30
| | | | | | 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-30
| | | | | | 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-30
| | | | | | | | 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-28
| | | | | | | | | | | | | | | | | | | | 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-28
| | | | | | | | | | | | 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-28
| | | | | | | | | | | | | | | | | | | | | | | | 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-28
| | | | | | | | | 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-28
| | | | | | | | | | | 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-28
| | | | | | | | | | | | | | | | 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-25
| | | | | | | 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-25
| | | | | | | | | | | | | | | | | 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-25
| | | | | | | | 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-25
| | | | | | | | | | | | | | 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-25
| | | | | | | | | | | 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-24
| | | | | | | | | | 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-18
| | | | | | | | | | | | | | | | 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-31
| | | | | | | | | | | | | | | | | | | | | | | | | 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-15
| | | | | | | | | 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-19
| | | | | | | | 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-08
| | | | | | | | 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>
* lavf/utils: Respect default disposition when select the AVStreamJun Zhao2019-07-03
| | | | | | Respect default disposition when select the AVStream Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
* avformat/utils: fix stream ordering for program ID stream specifiersMarton Balint2019-05-24
| | | | | | Fixes a regression introduced in dbfd042983eed8586d4048795c00af820f5b6b1f. Signed-off-by: Marton Balint <cus@passwd.hu>
* Revert "lavf/utils: Allow url credentials to contain a slash."Marton Balint2019-05-18
| | | | | | | | | | | | | | | | This reverts commit dd06f022b07438d650c82255dff16908ba04244a. Fixes ticket #7871 and reopens ticket #7816. The introduced regression caused URL's with @ in them to be parsed incorrectly which is a bigger issue then not being able to specify the slash character as a password. I think there are better ways to fix the original issue, like being able to specify HTTP username and password as a protocol option, or adding a protocol option to percent-decode the URL first. Signed-off-by: Marton Balint <cus@passwd.hu>
* libavformat: improve logs with cur_dtsAndreas Hakon2019-04-19
| | | | | | | | | | | This patch improves the logs when the message "cur_dts is invalid" appears. If helps to identify which stream generates the trouble, and the status of the stream. A lot of users suffers with the message, and the origin varies. The improved message can help to discover the cause. Signed-off-by: Andreas Hakon <andreas.hakon@protonmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* lavf/utils: Allow url credentials to contain a slash.Carl Eugen Hoyos2019-04-19
| | | | Fixes ticket #7816.
* lavf: Constify AVInputFormat pointer.Carl Eugen Hoyos2019-03-20
|
* avformat/utils: fix indentationMarton Balint2019-03-01
| | | | Signed-off-by: Marton Balint <cus@passwd.hu>
* avformat/utils: be even more strict about stream specifiersMarton Balint2019-03-01
| | | | | | | | | After this change we always parse the full specifier even if we know the result in the middle of the parsing. Sligtly slower, but this is needed to consistently reject incorrect specifiers in both matching and non-matching cases. Signed-off-by: Marton Balint <cus@passwd.hu>
* avformat/utils: be more strict about stream specifiersMarton Balint2019-03-01
| | | | | | | | | | | | This reworks the code to be more strict about accepting stream specifiers. From now on we strictly enforce the syntax in the documentation up until the decisive part of the stream specifier. Therefore matching stream specifiers always need to be correct, non matching specifiers only need to be correct until the decisive part. Also recursion is changed to a simple loop. Signed-off-by: Marton Balint <cus@passwd.hu>
* avformat/utils: parse some stream specifiers recursivelyMarton Balint2019-02-13
| | | | | | | | This removes lots of code duplication and also allows more complex specifiers, for example you can use p:204:a:m:language:eng to select the English language audio stream from program 204. Signed-off-by: Marton Balint <cus@passwd.hu>
* avformat/utils: add support for reading ID3 tags at start of wavPaul B Mahol2018-12-13
| | | | Fixes #4140.
* avformat/utils: Never store negative values in last_IP_durationMichael Niedermayer2018-10-18
| | | | | | | | Fixes: integer overflow compute_pkt_fields() Fixes: compute_pkt_usan Reported-by: Thomas Guilbert <tguilbert@chromium.org> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/utils: Fix integer overflow in discontinuity checkMichael Niedermayer2018-10-18
| | | | | | | | Fixes: signed integer overflow: 7738135736989908991 - -7954308516317364223 cannot be represented in type 'long' Fixes: find_stream_info_usan Reported-by: Thomas Guilbert <tguilbert@google.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/utils: Fix potential integer overflow in extract_extradata()Michael Niedermayer2018-10-07
| | | | Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/utils: Do not use "i" as a context pointer, "i" is normally the ↵Michael Niedermayer2018-10-07
| | | | | | | | | integer counter in loops This avoids surprising developers. Its bad to surprise developers with such unexpected things. Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/utils: Do not ignore failure in extract_extradata_init()Michael Niedermayer2018-10-07
| | | | | | We check for the documented explanation of the "Ignore code" in extract_extradata_check() already Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/utils: move mkdir_p to utilsSteven Liu2018-09-25
| | | | | | | Because it will be used by avformat/segment.c or other module which need to automatically create sub-directories operation. Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
* avformat/utils: set AV_PKT_FLAG_KEY for data packetsBaptiste Coudurier2018-09-24
|
* avformat/utils: Don't calculate duration using AV_NOPTS_VALUE for start_time.Dale Curtis2018-09-09
| | | | | | Found by ClusterFuzz, https://crbug.com/879852 Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/utils: avoid undefined integer overflow behavior in ↵Fredrik Hubinette2018-08-22
| | | | | | update_stream_timings() Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat: correct fdebug loglevelGyan Doshi2018-08-14
| | | | | fftools/cmdutils sets loglevel for fdebug to DEBUG but all fdebug output except for two were emitted at TRACE.
* avformat/utils: function to get the formatted ntp timeVishwanath Dixit2018-05-29
| | | | | | | This utility function creates 64-bit NTP time format as per the RFC 5905. A simple explaination of 64-bit NTP time format is here http://www.beaglesoft.com/Manual/page53.htm
* avformat: add fields to AVProgram/AVStream for PMT change trackingAman Gupta2018-05-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | These fields will allow the mpegts demuxer to expose details about the PMT/program which created the AVProgram and its AVStreams. In mpegts, a PMT which advertises streams has a version number which can be incremented at any time. When the version changes, the pids which correspond to each of it's streams can also change. Since ffmpeg creates a new AVStream per pid by default, an API user needs the ability to (a) detect when the PMT changed, and (b) tell which AVStream were added to replace earlier streams. This has been a long-standing issue with ffmpeg's handling of mpegts streams with PMT changes, and I found two related patches in the wild that attempt to solve the same problem: The first is in MythTV's ffmpeg fork, where they added a void (*streams_changed)(void*); to AVFormatContext and call it from their fork of the mpegts demuxer whenever the PMT changes. The second was proposed by XBMC in https://ffmpeg.org/pipermail/ffmpeg-devel/2012-December/135036.html, where they created a new AVMEDIA_TYPE_DATA stream with id=0 and attempted to send packets to it whenever the PMT changed. Signed-off-by: Aman Gupta <aman@tmm1.net>
* avformat: add skip_estimate_duration_from_ptsAman Gupta2018-05-17
| | | | | | | | | | | | | | | | | | | For seekable mpegts streams, duration is calculated from pts by seeking to the end of the file for a pts and subtracting the initial pts to compute a duration. This can be expensive in terms of added latency during probe, especially when streaming over a network. This new option lets you skip the duration calculation, which is useful when you don't care about the value and want to save some overhead. This patch is particularly useful when dealing with live mpegts streams. Normally such streams are not seekable, so durations are not calculated. However in my case I am dealing with a seekable live mpegts stream (networked access to a .ts file which is still being appended to). Signed-off-by: Aman Gupta <aman@tmm1.net>
* avformat/utils: refactor upstream_stream_timingsAman Gupta2018-04-20
| | | | | Signed-off-by: Aman Gupta <aman@tmm1.net> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/utils: ignore outlier durations on subtitle/data streams as wellAman Gupta2018-04-20
| | | | | | | | | Similar to 4c9c4fe8b21, but for durations. This fixes #7151, where the report duration and bitrate on a mpegts stream is wildly off due to the dvb_teletext stream's timings. Signed-off-by: Aman Gupta <aman@tmm1.net> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>