summaryrefslogtreecommitdiff
path: root/libavformat/utils.c
Commit message (Collapse)AuthorAge
* avformat/utils: Use st for AVStream variable in avpriv_set_pts_infoAndreas Rheinhardt2021-09-17
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/utils: Move demuxing code out into a new fileAndreas Rheinhardt2021-09-17
| | | | | | | | | | | | | libavformat/utils.c has over 4800 lines and is supposed to contain "various utility functions for use within FFmpeg". In reality it contains all that and the whole demuxing core of libavformat. This is especially bad, because said file includes the FFMPEG_VERSION (the git commit sha) so that it is rebuilt whenever the commit HEAD points to changes. Therefore this commit makes it smaller by moving the demuxing code out to a new file, demux.c (in analogy to mux.c for the muxing code). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/utils: Move seeking code out into a new fileAndreas Rheinhardt2021-09-17
| | | | | | | | | | | | libavformat/utils.c has over 5500 lines and is supposed to contain "various utility functions for use within FFmpeg". In reality it contains all that and the whole demuxing+seeking core of libavformat. This is especially bad, because said file includes the FFMPEG_VERSION (the git commit sha) so that it is rebuilt whenever the commit HEAD points to changes. Therefore this commit starts making it smaller by factoring the seeking code out. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/utils: ReindentationAndreas Rheinhardt2021-09-17
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat: Avoid allocation for AVStreamInternalAndreas Rheinhardt2021-09-17
| | | | | | | | | | 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>
* avformat/mux, utils: Use dedicated pointer for AVStreamInternalAndreas Rheinhardt2021-09-17
| | | | | | | This gets rid of ugly "->internal" and is in preparation for removing AVStreamInternal altogether. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat: Avoid allocation for AVFormatInternalAndreas Rheinhardt2021-09-17
| | | | | | | | | | | | | Do this by allocating AVFormatContext together with the data that is currently in AVFormatInternal; or rather: Put AVFormatContext at the beginning of a new structure called FFFormatContext (which encompasses more than just the internal fields and is a proper context in its own right, hence the name) and remove AVFormatInternal altogether. The biggest simplifications occured in avformat_alloc_context(), where one can now simply call avformat_free_context() in case of errors. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/mux, mxfenc, utils: Use dedicated pointer for AVFormatInternalAndreas Rheinhardt2021-09-17
| | | | | | | This gets rid of ugly "->internal" and is in preparation for removing AVFormatInternal altogether. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/asfenc, mux, utils: Use smaller scope for variablesAndreas Rheinhardt2021-09-17
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/utils: Ignore negative duration in codec_info_duration computationMichael Niedermayer2021-09-14
| | | | | | | | Fixes: signed integer overflow: -5994697211974418462 + -3255307777713450286 cannot be represented in type 'long' Fixes: 35332/clusterfuzz-testcase-minimized-ffmpeg_dem_MATROSKA_fuzzer-5868035117285376 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: Use av_memdup to duplicate array of AVChapter *Andreas Rheinhardt2021-08-31
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/utils: Don't allocate zero-sized arrayAndreas Rheinhardt2021-08-31
| | | | | | | It is unnecessary and also ill-defined: av_malloc() returns a 1-byte block of memory in this case, but this is not documented. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/utils: Don't compare pointers when sorting chaptersAndreas Rheinhardt2021-08-31
| | | | | | | | | | | The chapters are independently allocated, so that comparing the pointers is undefined behaviour. Furthermore, its result is not platform-independent (and may not even be deterministic on a particular platform). So compare the chapters' ids instead. (avpriv_new_chapter() ensures that there are no duplicate ids.) Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/utils: Allocate AVStream.info only for input streamsAndreas Rheinhardt2021-08-30
| | | | | | | This structure is only used for demuxers (mostly in avformat_find_stream_info()), so only allocate it for them. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/utils: Don't initialize AVStreamInternal.info multiple timesAndreas Rheinhardt2021-08-30
| | | | | | | | | | | | | | | | It has been allocated and initialized in avformat_find_stream_info() until fd0368e7ca35e2feaf7960564e61a76655c4d1f6 when the structure was moved to AVStreamInternal and its allocation to avformat_new_stream. In order to also initialize the struct for new streams that only get created during avformat_find_stream_info() said the initialization has been added to avformat_new_stream() later. Due to the Libav-FFmpeg split this has been done twice: In 4cda8aa1c5bc58f8a7f53a21a19b03e7379bbcdc and in 30c26c2442e4e44ac5a763c23c4b0fdd9921a7f5. The initialization in avformat_find_stream_info() has not been removed at all despite being redundant. This commit removes it and the duplicated initialization in avformat_new_stream(). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/utils: Remove redundant flushing of packet queueAndreas Rheinhardt2021-08-30
| | | | | | | The packet queue is already flushed in avformat_free_context() which is called a few lines below. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/utils: Make ff_compute_frame_duration() staticAndreas Rheinhardt2021-08-30
| | | | | | | | Since 1c0885334dda9ee8652e60c586fa2e3674056586 ff_compute_frame_duration is only called from within utils.c and only for demuxers. So make it static and remove the code in it that deals with muxers. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/utils: Remove obsolete todoAndreas Rheinhardt2021-08-30
| | | | | | Also initialize the AVCodecContexts directly. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/utils: Remove always-false checkAndreas Rheinhardt2021-08-30
| | | | | | | | | AVFormatContext.internal is already allocated by avformat_alloc_context() on success; and on error, avformat_alloc_context() cleans up manually without avformat_free_context(). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/avio: Move internal AVIOContext fields to avio_internal.hAndreas Rheinhardt2021-08-25
| | | | | | | | | | | | | | 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>
* avformat/utils: Move ffio_limit() to aviobufAndreas Rheinhardt2021-08-25
| | | | | | | | It is the more natural place for it given that it only deals with I/O; in fact, the function already has the ffio prefix and its declaration already is in avio_internal.h. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/utils: Also set io_repositioned for generic seekingAndreas Rheinhardt2021-08-23
| | | | | | | | It allows demuxers to perform certain tasks after a successful generic seek. Reviewed-by: James Almer <jamrial@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat: Use ffio_read_size where appropriateAndreas Rheinhardt2021-08-06
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/internal: Move ff_read_line_to_bprint_overwrite to avio_internal.hAndreas Rheinhardt2021-07-29
| | | | | | | | | | | | | It only uses an AVIOContext and an AVBPrint. When doing so, it turned out that several non-users of ff_read_line_to_bprint_overwrite() and ff_bprint_to_codecpar_extradata() relied on libavformat/internal.h to include bprint.h or avstring.h for them. In order to avoid a repeat of this and in order to reduce unnecessary dependencies, a forward declaration of struct AVBPrint is used instead of including bprint.h. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/avcodec: Stop including bsf.h in avcodec.hAndreas Rheinhardt2021-07-22
| | | | | | Also include bsf.h directly wherever it is used. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/utils: remove AVStreamInternal.orig_codec_idJames Almer2021-07-17
| | | | | | | It's a write only field. Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avformat: Redo cleanup of demuxers upon read_header() failureAndreas Rheinhardt2021-07-07
| | | | | | | | | | | | | | | | | | | | If reading the header fails, the demuxer's read_close() function (if existing) is not called automatically; instead several demuxers call it via "goto fail" in read_header(). This commit intends to change this by adding an internal flag for demuxers that can be used to set on a per-AVInputFormat basis whether read_close() should be called generically after an error during read_header(). The flag controlling this behaviour needs to be added because it might be unsafe to call read_close() generally (e.g. this might lead to read_close() being called twice and this might e.g. lead to double-frees if av_free() is used instead of av_freep(); or a size field has not been reset after freeing the elements (see the mov demuxer for an example of this)). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/utils: Avoid overflow in codec_info_duration computation for subtitlesMichael Niedermayer2021-06-12
| | | | | | | | Fixes: signed integer overflow: 9223126845747118112 - -2594073385365397472 cannot be represented in type 'long' Fixes: 34936/clusterfuzz-testcase-minimized-ffmpeg_dem_MATROSKA_fuzzer-6739888002170880 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 dts/duration to be representable before using themMichael Niedermayer2021-06-12
| | | | | | | | Fixes: signed integer overflow: 6854513951393103890 + 3427256975738527712 cannot be represented in type 'long' Fixes: 32936/clusterfuzz-testcase-minimized-ffmpeg_dem_R3D_fuzzer-5236914752978944 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat: move AVStream.{first,cur}_dts to AVStreamInternalJames Almer2021-06-09
| | | | | | They are private fields, no reason to have them exposed in a public header. Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/utils: make ff_update_cur_dts() sharedJames Almer2021-06-09
| | | | | | libavdevice needs it. Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/utils: Fix NPD when allocating AVStreamInternal failsAndreas Rheinhardt2021-05-13
| | | | | | | | | | | | Regression since b9c5fdf6027010d15ee90a43aa023e45a5189097; fixes Coverity ID #1484786. Also remove the check for st->internal->parser as av_parser_close(NULL) is a no-op. Reviewed-by: James Almer <jamrial@gmail.com> Reviewed-by: Marton Balint <cus@passwd.hu> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/utils: Use 64bit earlier in r_frame_rate checkMichael Niedermayer2021-05-12
| | | | | | | | Fixes: signed integer overflow: 1406796319 * 2 cannot be represented in type 'int' Fixes: 32777/clusterfuzz-testcase-minimized-ffmpeg_IO_DEMUXER_fuzzer-5632576913014784 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat: move AVStream.codec_info_nb_frames to AVStreamInternalJames Almer2021-05-07
| | | | | | It's a private field, no reason to have it exposed in a public header. Signed-off-by: James Almer <jamrial@gmail.com>
* avformat: move AVStream.{parser,need_parsing} to AVStreamInternalJames Almer2021-05-07
| | | | | | | Those are private fields, no reason to have them exposed in a public header. Signed-off-by: James Almer <jamrial@gmail.com>
* avformat: move AVStream.probe_packets to AVStreamInternalJames Almer2021-05-07
| | | | | | It's a private fields, no reason to have it exposed in a public header. Signed-off-by: James Almer <jamrial@gmail.com>
* avformat: move AVStream.last-IP_{pts,duration} to AVStreamInternalJames Almer2021-05-07
| | | | | | | Those are private fields, no reason to have them exposed in a public header. Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/utils: constrain the lifetime of the pointer returned by ↵James Almer2021-05-06
| | | | | | | | | avformat_index_get_entry() This will give us more room to improve the implementation later. Suggested-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: James Almer <jamrial@gmail.com>
* avformat: remove deprecated AVStream.codecJames Almer2021-04-27
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/avformat, utils: Make av_find_best_stream const-correctAndreas Rheinhardt2021-04-27
| | | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avutil/buffer: Switch AVBuffer API to size_tAndreas Rheinhardt2021-04-27
| | | | | | | Announced in 14040a1d913794d9a3fd6406a6d8c2f0e37e0062. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avformat: Switch AVChapter.id to 64bitsAndreas Rheinhardt2021-04-27
| | | | | | | Announced in e318438f2f30525d8baca2b5683aa9898d0c56f7. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avformat: Remove deprecated av_demuxer_open()Andreas Rheinhardt2021-04-27
| | | | | | | Deprecate in e37f161e66e042d6c2c7470c4d9881df9427fc4a. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avformat: Remove deprecated filename field from AVFormatContextAndreas Rheinhardt2021-04-27
| | | | | | | Deprecated in fa8308d3d4f27d6fb38ac2069887a7b259f1c6ab. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avformat: Remove getters and settersAndreas Rheinhardt2021-04-27
| | | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avformat: Remove deprecated old open callbacksAndreas Rheinhardt2021-04-27
| | | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avformat: Remove FFserver leftoversAndreas Rheinhardt2021-04-27
| | | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avformat: Constify the API wrt AV(In|Out)putFormatAndreas Rheinhardt2021-04-27
| | | | | | | Also constify AVProbeData. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec, avformat: Remove AVPacket.convergence_durationAndreas Rheinhardt2021-04-27
| | | | | | | Deprecated in 948f3c19a8bd069768ca411212aaf8c1ed96b10d. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec, avformat: Remove old BSF APIAndreas Rheinhardt2021-04-27
| | | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>