Commit Graph

259 Commits

Author SHA1 Message Date
Anton Khirnov 9d4c018497 avio: do not export avpriv_io_{move,delete}
They are private and not used by anything outside of lavf. There is no
reason for them to be exported.
2021-05-22 15:27:55 +02:00
James Almer f140239777 avformat: move AVStream.stream_identifier to AVStreamInternal
It's a private field, no reason to have it exposed in a public header.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-05-07 09:27:22 -03:00
James Almer 7489f63281 avformat: move AVStream.codec_info_nb_frames to AVStreamInternal
It's a private field, no reason to have it exposed in a public header.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-05-07 09:27:21 -03:00
James Almer b9c5fdf602 avformat: move AVStream.{parser,need_parsing} to AVStreamInternal
Those are private fields, no reason to have them exposed in a public
header.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-05-07 09:27:21 -03:00
James Almer fab2ed4704 avformat: move AVStream.probe_packets to AVStreamInternal
It's a private fields, no reason to have it exposed in a public header.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-05-07 09:27:20 -03:00
James Almer 1262f67cca avformat: move AVStream.last-IP_{pts,duration} to AVStreamInternal
Those are private fields, no reason to have them exposed in a public
header.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-05-07 09:27:20 -03:00
Andreas Rheinhardt e83717e63e avformat: Switch AVChapter.id to 64bits
Announced in e318438f2f.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:10 -03:00
Andreas Rheinhardt 7aee4762d3 avformat/utils: Free new streams in ff_add_attached_pic on error
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-01 18:23:13 +02:00
Andreas Rheinhardt 39ecb63d0f avformat: Add and use helper function to add attachment streams
All instances of adding attached pictures to a stream or adding
a stream and an attached packet to said stream have several things
in common like setting the index and flags of the packet, setting
the stream disposition etc. This commit therefore factors this out.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-01 18:23:13 +02:00
Andreas Rheinhardt a4d036965d avformat/matroskadec: Reuse AVFormatInternal.parse_pkt
Before 8d78e90a6b the Matroska demuxer
used stack packets to hold temporary packets; now it uses a temporary
packet allocated by the Matroska demuxer. Yet because it used stack
packets the code has always properly reset the packet on error, while
on success these temporary packets were put into a packet list via
avpriv_packet_list_put(), which already resets the source packet.
This means that this code is compatible with just reusing
AVFormatInternal.parse_pkt (which is unused while one is in the
demuxer's read_packet() function). Compared to before 8d78e90a6
this no longer wastes one initialization per AVPacket read
(the resetting of the stack packet performed by av_packet_move_ref()
in avpriv_packet_list_put() was for naught).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-03-24 00:07:36 +01:00
Alok Priyadarshi adff25412a avformat/rtpdec: attach producer reference time if available
This produces true wallclock time at rtp source instead of the
local wallclock time at rtp client.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-03-23 19:02:47 -03:00
Andreas Rheinhardt 4a9eb7072c avformat/utils: Don't allocate separate packet for extract_extradata
One can simply reuse AVFormatInternal.parse_pkt instead.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-03-23 14:23:49 +01:00
Andreas Rheinhardt e318438f2f avformat: Make AVChapter.id an int64_t on next major bump
64 bits are needed in order to retain the uid values of Matroska
chapters; the type is kept signed because the semantics of NUT chapters
depend upon whether the id is > 0 or < 0.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-03-19 02:36:58 +01:00
James Almer 01f4d33b41 avformat/utils: use av_packet_alloc() to allocate packets
Signed-off-by: James Almer <jamrial@gmail.com>
2021-03-17 15:06:48 -03:00
James Almer 9066969713 avformat/mux: use av_packet_alloc() to allocate packets
Signed-off-by: James Almer <jamrial@gmail.com>
2021-03-17 15:06:48 -03:00
James Almer d422b2ed87 avcodec/packet_internal: make avpriv_packet_list_* functions use an internal struct
The next pointer is kept at the end for backwards compatability until the
major bump, when it should ideally be moved at the front.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-03-17 14:12:17 -03:00
James Almer d5d6751a55 avformat/mux: return a pointer to the packet in ff_interleaved_peek()
And make it const, so the caller doesn't attempt to change it.
ff_get_muxer_ts_offset() should be used to get the muxer timestamp offset.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-02-13 13:05:26 -03:00
James Almer 93e2fa933f avformat/mux: add ff_get_muxer_ts_offset()
Will be useful in the next patch

Signed-off-by: James Almer <jamrial@gmail.com>
2021-02-13 13:01:48 -03:00
Andreas Rheinhardt a703410d25 avformat/cutils, dvenc: Move ff_brktimegm to its only user
This also allows to completely remove cutils.c.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-02-03 21:35:43 +01:00
Michael Niedermayer a899d6ca10 avformat: Change avpriv_new_chapter() from O(n) to (1) in the common case
Fixes: timeout (slow -> 300ms)
Fixes: 28876/clusterfuzz-testcase-minimized-ffmpeg_dem_MOV_fuzzer-5664824587583488

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-01-28 21:08:35 +01:00
Anton Khirnov 744b7f2e91 lavf: move AVStream.last_in_packet_buffer to AVStreamInternal
Those are private fields, no reason to have them exposed in a public
header.
2020-10-28 15:01:40 +01:00
Anton Khirnov 30f5180ca6 lavf: move AVStream.probe_data to AVStreamInternal
Those are private fields, no reason to have them exposed in a public
header.
2020-10-28 15:01:22 +01:00
Anton Khirnov 91a98cc4ea lavf: move AVStream.pts_buffer to AVStreamInternal
Those are private fields, no reason to have them exposed in a public
header.
2020-10-28 15:00:40 +01:00
Anton Khirnov cea7c19cda lavf: move AVStream.*index_entries* to AVStreamInternal
Those are private fields, no reason to have them exposed in a public
header. Since there are some (semi-)public fields located after these,
even though this section is supposed to be private, keep some dummy
padding there until the next major bump to preserve ABI compatibility.
2020-10-28 14:59:28 +01:00
Anton Khirnov 7e87288f73 lavf: move AVStream.interleaver_chunk_* to AVStreamInternal
Those are private fields, no reason to have them exposed in a public
header.
2020-10-28 14:58:28 +01:00
Anton Khirnov 108864acee lavf: move AVStream.{request_probe,skip_to_keyframe} to AVStreamInternal
Those are private fields, no reason to have them exposed in a public
header.
2020-10-28 14:57:01 +01:00
Anton Khirnov 456b170bd7 lavf: move AVStream.{*skip_samples.*_discard_sample} to AVStreamInternal
Those are private fields, no reason to have them exposed in a public
header.
2020-10-28 14:56:20 +01:00
Anton Khirnov cb46a6bcbc lavf: move AVStream.{nb_decoded_frames,mux_ts_offset} to AVStreamInternal
Those are private fields, no reason to have them exposed in a public
header.
2020-10-28 14:55:53 +01:00
Anton Khirnov 323c9a8c52 lavf: move AVStream.{pts_wrap_*,update_initial_durations_done} to AVStreamInternal
Those are private fields, no reason to have them exposed in a public
header.
2020-10-28 14:54:51 +01:00
Anton Khirnov 36d7c1dee8 lavf: move AVStream.pts_reorder_error[_count] to AVStreamInternal
Those are private fields, no reason to have them exposed in a public
header.
2020-10-28 14:54:35 +01:00
Anton Khirnov 25bade3258 lavf: move AVStream.{last_dts_for_order_check,dts_[mis]ordered} to AVStreamInternal
Those are private fields, no reason to have them exposed in a public
header.
2020-10-28 14:54:22 +01:00
Anton Khirnov c1b916580a lavf: move AVStream.{inject_global_side_data,display_aspect_ratio} to AVStreamInternal
Those are private fields, no reason to have them exposed in a public
header.
2020-10-28 14:53:45 +01:00
Anton Khirnov 8741f1fe26 lavf: move AVStream.info to AVStreamInternal
This struct is for internal use of avformat_find_stream_info(), so it
should not be exposed in public headers. Keep a stub pointer in its
place to avoid changing AVStream layout, since e.g. ffmpeg.c accesses
some fields located after it (even though they are marked as private).
2020-10-28 14:52:06 +01:00
James Almer 8a81820624 avcodec/packet: move AVPacketList definition and function helpers over from libavformat
And replace the flags parameter with a function callback that can be used to
copy the contents of the packet (e.g, av_packet_ref and av_packet_copy_props).

Signed-off-by: James Almer <jamrial@gmail.com>
2020-09-15 09:53:39 -03:00
Limin Wang 96e5e6abb9 avformat/mux: Set AV_PKT_FLAG_KEY for is_intra_only packet
The patch will make audio and subtitle packets be marked as AV_PKT_FLAG_KEY.

For audio, it'll caused the audio sample to be sync sample.
To verify ref/fate/movenc results:
1. Get the movenc test data
[lmwang@vpn ffmpeg]$ libavformat/tests/movenc -w && mkdir -p audio_old && mv *.mp4 audio_old_

After applied the patch:
[lmwang@vpn ffmpeg]$ make fate-movenc SAMPLES=../fate-suite
[lmwang@vpn ffmpeg]$ libavformat/tests/movenc -w && mkdir -p audio_key && mv *.mp4 audio_key

2. Get l-smash and build boxdumper
https://github.com/l-smash/l-smash.git

3. dump the box of crc change mp4 and diff -u
[lmwang@vpn ffmpeg]$ ../l-smash/cli/boxdumper --box audio_key/non-empty-moov-no-elst.mp4  > audio_key/non-empty-moov-no-elst.log
[lmwang@vpn ffmpeg]$ ../l-smash/cli/boxdumper --box audio_old/non-empty-moov-no-elst.mp4  > audio_old/non-empty-moov-no-elst.log
[lmwang@vpn ffmpeg]$ diff -u audio_key/non-empty-moov-no-elst.log audio_old/non-empty-moov-no-elst.log
-                default_sample_flags = 0x02000000
-                    independent
-                    sync sample
+                default_sample_flags = 0x01010000
+                    dependent
+                    non-sync sample

4. have checked the change of crc are caused by default_sample_flags
non-empty-moov.mp4, non-empty-moov-elst.mp4,
non-empty-moov-no-elst.mp4, empty-moov.mp4, delay-moov-content.mp4,
empty-moov-second-frag.mp4, empty-moov-second-frag-discont.mp4,
delay-moov-second-frag-discont.mp4, delay-moov-elst-second-frag.mp4
etc

5 For subtitle, it'll effect for tests/ref/fate/binsub-movtextenc and
tests/ref/fate/sub2video, that's expecting result for the subtitle is
marked as keyframe. Below is the checking result of binsub-movtextenc:

[lmwang@vpn ffmpeg]$ ./ffmpeg -i ../fate-suite/sub/MovText_capability_tester.mp4 -map 0 -scodec mov_text -f mp4 -flags +bitexact -fflags +bitexact -movflags frag_keyframe+empty_moov audio_key/binsub-movtextenc.mp4
[lmwang@vpn ffmpeg]$ ./ffmpeg -i ../fate-suite/sub/MovText_capability_tester.mp4 -map 0 -scodec mov_text -f mp4 -flags +bitexact -fflags +bitexact -movflags frag_keyframe+empty_moov audio_old/binsub-movtextenc.mp4
[lmwang@vpn ffmpeg]$../l-smash/cli/boxdumper audio_key/binsub-movtextenc.mp4  > audio_key/binsub-movtextenc.log
[lmwang@vpn ffmpeg]$../l-smash/cli/boxdumper audio_old/binsub-movtextenc.mp4  > audio_old/binsub-movtextenc.log
[lmwang@vpn ffmpeg]$ diff -u audio_key/binsub-movtextenc.log audio_old/binsub-movtextenc.log
.... // the key difference is the flag for sync sample
-                flags = 0x000701
+                flags = 0x000301
                     data-offset-present
                     sample-duration-present
                     sample-size-present
-                    sample-flags-present
                 sample_count = 6
-                data_offset = 188
+                data_offset = 164
                 sample[0]
                     sample_duration = 1570000
                     sample_size = 21
-                    sample_flags = 0x02000000
-                        independent
-                        sync sample
-                        degradation_priority = 0
                 sample[1]
                     sample_duration = 510000
                     sample_size = 2
-                    sample_flags = 0x01010000
-                        dependent
-                        non-sync sample
-                        degradation_priority = 0
                 sample[2]
                     sample_duration = 1690000
                     sample_size = 9
-                    sample_flags = 0x02000000
-                        independent
-                        sync sample
-                        degradation_priority = 0

Suggested-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Suggested-by: Nicolas George <george@nsup.org>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-05-07 07:12:24 +08:00
Limin Wang ba0d785fa5 avformat/utils: move is_intra_only() to header and rename to ff_is_intra_only()
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-05-06 23:02:00 +08:00
Andreas Rheinhardt 781c7a6217 avformat/aviobuf, nutenc: Move ff_puv_v, ff_get_v_length to nutenc.c
and make it static again.

These functions have been moved from nutenc to aviobuf and internal.h
in f8280ff4c0 in order to use them in a
forthcoming patch in utils.c. Said patch never happened, so this commit
moves them back and makes them static, effectively reverting said
commit as well as f8280ff4c0 (which added
the ff-prefix to these functions).

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-05 19:28:28 +02:00
Marton Balint 1128aa8753 avformat: only allow a single bitstream filter when muxing
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>
2020-04-26 22:39:01 +02:00
Andreas Rheinhardt e79309fde6 libavformat/mux, mxfenc: Don't initialize unnecessarily
When no packet could be output, the interleavement functions
nevertheless initialized the packet destined for output (with the
exception of the data and size fields, making the initialization
pointless), although it will not be used at all. So remove the
initializations.

Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-04-18 01:24:56 +02:00
Andreas Rheinhardt 00aa6dea3f avformat/mux: Remove redundant resetting
Now that ff_interleave_add_packet() always returns blank packets, the
input packet to ff_interleave_packet_per_dts() will always be blank on
return as well (if supplied) and the same goes for interleave_packet()
in mux.c. Document these facts and remove the redundant resetting that
happened in av_interleaved_write_frame().

The last reference to the (long removed) destruct field that AVPackets
once had has been removed as well when updating the documentation of
ff_interleave_packet_per_dts().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-04-18 00:41:27 +02:00
Andreas Rheinhardt a43120b609 avformat/mux: Fix leak when adding packet to interleavement queue fails
When an error happened in ff_interleave_add_packet() when adding
a packet to the packet queue, said packet would not be unreferenced
in ff_interleave_add_packet(), but would be zeroed in
av_interleaved_write_frame(), which results in a memleak.

This has been fixed: ff_interleave_add_packet() now always unreferences
the input packet on error; as a result, it always returns blank packets
which has been documented. Relying on this a call to av_packet_unref()
in ff_audio_rechunk_interleave() can be removed.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-04-18 00:22:22 +02:00
Marton Balint 19b9f8996e avformat/avio: fix ff_rename to respect used protocol
Also simplify it and make it always log the error.

This fixes for example the image2 muxer when used with an URL which also
contains the protocol:

ffmpeg -f lavfi -i testsrc -vframes 10 -atomic_writing 1 file:out%d.png

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-01-19 22:17:04 +01:00
Marton Balint df993269ec avformat/avio: move ff_rename implementation from internal.h to avio.c
Signed-off-by: Marton Balint <cus@passwd.hu>
2020-01-19 22:17:04 +01:00
James Almer ab9627223e Revert "avformat/utils: make ff_ntp_time() accept a timestamp as input argument"
Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-16 22:27:35 -03:00
James Almer 4e4ac20340 avformat/utils: make ff_ntp_time() accept a timestamp as input argument
Will be needed by the next patch.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-15 23:34:20 -03:00
Andriy Gelman 5e3229df4c avformat: Add max_probe_packets option
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>
2019-11-03 11:52:32 +01:00
Andreas Rheinhardt b6be2be765 avformat/utils: ensure that all packets in AVPacketList are reference counted
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>
2019-09-25 21:54:18 -03:00
Andreas Rheinhardt 8b1be6e5eb avformat/internal: Improve documentation of ff_packet_list_get
The documentation of ff_packet_list_get currently didn't match the
actual usage:
1. It said that the destination packet is supposed to be initialized.
But this makes no sense given that it will be overwritten completely and
flacenc, mp3enc and ttaenc ignored this.
2. ff_packet_list_get returns an int, although it can't fail in case the
packet list is not empty (for which there is an assert). Again, several
callers didn't check for any return value.
In both cases, the documentation has been adapted to match actual usage.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-09-18 22:53:00 +02:00
Andreas Rheinhardt 1147759552 avformat/mux: Use const AVPacket * in compare functions
There is no reason for these functions to modify the given packets at
all.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-08-15 01:26:21 +02:00
Jun Zhao 4373bb411c lavf/avio: remove ffio_open2_wrapper function
Remove the function ffio_open2_wrapper, it's not being used anymore.

Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
2019-07-21 10:05:40 +08:00