Commit Graph

155 Commits

Author SHA1 Message Date
Andreas Rheinhardt d61240f8c9 avcodec/packet_internal: Add proper PacketList struct
Up until now, we had a PacketList structure which is actually
a PacketListEntry; a proper PacketList did not exist
and all the related functions just passed pointers to pointers
to the head and tail elements around. All these pointers were
actually consecutive elements of their containing structs,
i.e. the users already treated them as if they were a struct.

So add a proper PacketList struct and rename the current PacketList
to PacketListEntry; also make the functions use this structure
instead of the pair of pointers.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-04 13:16:50 +01:00
Michael Niedermayer 235ac7b492 avcodec/avpacket: Perform fewer reallocations in repeated av_grow_packet()
Fixes: Timeout
Fixes: 41446/clusterfuzz-testcase-minimized-ffmpeg_dem_SAMI_fuzzer-4667644540747776

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-12-06 14:25:55 +01:00
Lynne c8b1f2bcc4
packet: initialize time_base field to (0, 1) instead of (0, 0)
Forget rational or irrational numbers, division by zero is undefined.
2021-08-02 14:45:47 +02:00
Lynne a1a0fddfd0
avpacket: ABI bump additions
This commit adds a long-requested by API users opaque fields for
AVPacket, as well as a time_base field.
2021-08-02 14:30:52 +02:00
Mohammad Izadi aca923b365 avcodec: Pass HDR10+ metadata to packet side data in VP9 encoder
HDR10+ metadata is stored in the bit stream for HEVC. The story is
different for VP9 and cannot store the metadata in the bit stream.
HDR10+ should be passed to packet side data an stored in the container
(mkv) for VP9.

This CL is taking HDR10+ from AVFrame side data in libvpxenc and is
passing it to the AVPacket side data.

Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: James Zern <jzern@google.com>
2021-06-24 10:29:17 -07:00
James Almer b4e7fc4b4b avcodec/avpacket: use av_malloc() to allocate an AVPacket
av_mallocz() is superfluous as get_packet_defaults() is called immediately
after it's allocated, which will initialize the entire struct to default
values.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-05-08 18:36:31 -03:00
James Almer 0a029906b2 avcodec/avpacket: always initialize the new packet in avpriv_packet_list_put()
If a copy callback is provided by the caller, the packet passed to it
was zeroed instead of initialized with default values.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-05-08 18:31:56 -03:00
Andreas Rheinhardt ef6a9e5e31 avutil/buffer: Switch AVBuffer API to size_t
Announced in 14040a1d91.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:13 -03:00
Andreas Rheinhardt e1597fe0cf avcodec: Remove deprecated API to split/merge side-data
Deprecated in d682ae70b4.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:01 -03:00
Andreas Rheinhardt ab227d8fe1 avcodec: Remove deprecated AVPacket API
Deprecated in ce70f28a17.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:00 -03:00
Andreas Rheinhardt df6b44182e avcodec, avformat: Remove AVPacket.convergence_duration
Deprecated in 948f3c19a8.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:00 -03:00
Andreas Rheinhardt a46d781905 avcodec/packet: Also change av_packet_pack/unpack_dictionary to size_t
These are auxiliary side-data functions, so they should have been
switched to size_t in d79e0fe65c,
but this has been forgotten.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-03-19 03:12:24 +01:00
Andreas Rheinhardt 04d001ca9b avcodec/avpacket: Improve overflow checks when packing dictionary
Also avoid reallocations.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-03-19 03:03:06 +01: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 f7db77bd87 avcodec/packet: deprecate av_init_packet()
Once removed, sizeof(AVPacket) will stop being a part of the public ABI.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-03-17 14:12:17 -03:00
James Almer d8a18c8fc2 avcodec: use the buffer_size_t typedef where required
Signed-off-by: James Almer <jamrial@gmail.com>
2021-03-10 20:26:36 -03:00
James Almer d79e0fe65c avcodec/packet: change side data related public function and struct size types to size_t
av_packet_add_side_data() already defines size as a size_t, so this makes it
consistent across all side data functions

Signed-off-by: James Almer <jamrial@gmail.com>
2021-03-10 20:26:36 -03: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 448a9aaa78 API: add AV_PKT_DATA_S12M_TIMECODE to AVPacketSideDataType
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-07-15 05:47:14 +08:00
James Almer 6e1903938b avcodec/internal: move packet related functions to their own header
Signed-off-by: James Almer <jamrial@gmail.com>
2020-06-02 19:02:12 -03:00
James Almer f90a48b72e avcodec/avpacket: add missing entry for prft to av_packet_side_data_name()
Signed-off-by: James Almer <jamrial@gmail.com>
2020-05-05 11:54:58 -03:00
Andreas Rheinhardt 8f51a89d66 avcodec/avpacket: Don't write into non-writable buffer
The data of an AVPacket may be a part of the data of an AVBufferRef;
Therefore av_grow_packet() doesn't reallocate if the available space in
the actual buffer is sufficient for the enlargement. But given that it
also zeroes the padding it also needs to make sure that the buffer is
actually writable; this commit implements this.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-04-30 09:02:27 +02:00
Andreas Rheinhardt 6b0c94780d libavcodec/avpacket: Don't simply forward return value of av_dict_set()
The documentation of av_dict_set() states that values >= 0 indicate
success, whereas av_packet_unpack_dictionary() implies that return
values > 0 are impossible. So only forward the return value of
av_dict_set() in av_packet_unpack_dictionary() on error.

(Btw: av_dict_set() does currently not return values > 0.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-04-23 19:42:03 +02:00
Jun Zhao 0e1db79e37 lavc: add a new sidedata type for DOVI
add a new sidedata type for DOVI.

Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
2020-04-23 08:05:06 +08:00
Anton Khirnov 9875fd24ce avcodec.h: split AVPacket API into its own header 2020-04-10 13:54:03 +02:00
Andreas Rheinhardt c52ec0367d avcodec/avcodec, avpacket: Return blank packet on av_packet_ref() failure
Up until now, it was completely unspecified what the content of the
destination packet dst was on error. Depending upon where the error
happened calling av_packet_unref() on dst might be dangerous.

This commit changes this by making sure that dst is blank on error, so
unreferencing it again is safe (and still pointless). This behaviour is
documented.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-03-28 03:59:15 +01:00
Andreas Rheinhardt e621f2b6cd avcodec/avpacket: Always treat dst in av_packet_ref as uninitialized
av_packet_ref() mostly treated the destination packet dst as uninitialized,
i.e. the destination fields were simply overwritten. But if the source
packet was not reference-counted, dst->buf was treated as if it pointed
to an already allocated buffer (if != NULL) to be reallocated to the
desired size.

The documentation did not explicitly state whether the dst will be treated
as uninitialized, but it stated that if the source packet is not refcounted,
a new buffer in dst will be allocated. This and the fact that the side-data
as well as the codepath taken in case src is refcounted always treated the
packet as uninitialized means that dst should always be treated as
uninitialized for the sake of consistency. And this behaviour has been
explicitly documented.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-03-28 03:54:48 +01:00
vectronic 05d27f342b API: add AV_PKT_DATA_ICC_PROFILE to AVPacketSideDataType
Signed-off-by: vectronic <hello.vectronic@gmail.com>
2020-03-10 15:10:06 +00:00
James Almer 717b2074ec avcodec: add a Producer Reference Time AVPacketSideData type
Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-15 23:33:41 -03:00
Andreas Rheinhardt e12a2a2d73 avcodec/avpacket: Improve allocating packets
av_mallocz + av_init_packet leads to the same result as av_mallocz +
av_packet_unref, but faster.

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
Jun Zhao 00555f4b8b lavc/avpacket: check NULL before using the pointer
Need to check NULL before using the pointer

Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
2019-05-12 14:17:22 +08:00
Marton Balint 9f8854cb5a avcodec/avpacket: add some assertions to ensure pkt->data is not null if pkt->size > 0
This should fix the following Coverity false positives:

Coverity CID #1405450.
Coverity CID #1430930.

Signed-off-by: Marton Balint <cus@passwd.hu>
2019-03-01 22:32:32 +01:00
Michael Niedermayer 9520d51e21 avcodec/avpacket: Avoid unspecific return -1 for av_grow_packet()
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-01-01 21:11:47 +01:00
Aman Gupta 0c14b73e43 avcodec/avpacket: fix whitespace
Signed-off-by: Aman Gupta <aman@tmm1.net>
2018-10-12 09:48:07 -07:00
Jun Zhao 50d9c85358 lavc/avpacket: Add missing conversions from side data enum to name.
Add missing conversions from side data enum to name.

Signed-off-by: Jun Zhao <mypopydev@gmail.com>
2018-09-21 18:09:37 +08:00
James Almer 860086ee16 avcodec/avpacket: add av_packet_make_refcounted()
It works as a drop in replacement for the deprecated av_dup_packet(),
to ensure a packet is reference counted.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2018-04-01 23:40:41 -03:00
James Almer d205c8f3bb avcodec/avpacket: remove unnecessary check in av_packet_make_writable()
Zero sized packets are already handled below in the function.
This is more in line with av_packet_ref().

Signed-off-by: James Almer <jamrial@gmail.com>
2018-03-27 11:25:57 -03:00
James Almer f14ca60001 avcodec/avpacket: add av_packet_make_writable()
Useful as well to quickly make a packet reference counted when it
isn't already so.

Signed-off-by: James Almer <jamrial@gmail.com>
2018-03-21 22:17:40 -03:00
Yusuke Nakamura 3b4026e151 avpacket: reset dst side_data fields in av_packet_copy_props
This effectively copies the side data elements from src instead of
potentially merging them with those already existing in dst.
This by extension also removes the only dependency on existing values
in the dst packet.

Reviewed-by: wm4 <nfxjfg@googlemail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2018-02-14 20:36:29 -03:00
James Almer 417d473bde avcodec: remove ABI portion of the side data merging API
The actual API is left in place until the deprecation period ends.

Signed-off-by: James Almer <jamrial@gmail.com>
2017-10-22 00:30:12 -03:00
Karthick J b6cf66ae1c avdevice/decklink_dec: Added Closed caption decode from VANC
Signed-off-by: Karthick J <kjeyapal@akamai.com>
Signed-off-by: Marton Balint <cus@passwd.hu>
2017-09-28 21:06:12 +02:00
James Almer ecb9741ba2 avcodec/avpacket: deprecate av_copy_packet()
It does the same thing as av_packet_ref().

Signed-off-by: James Almer <jamrial@gmail.com>
2017-09-25 21:22:06 -03:00
Michael Niedermayer 07339a45a0 avcodec/avpacket: Limit iterations in ff_packet_split_and_drop_side_data()
This avoids scaning beyond what a valid packet can contain
Fixes: Timeout
Fixes: 541/clusterfuzz-testcase-610189291657625

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-06-11 22:09:15 +02:00
James Almer 28f60eeabb avcodec/avpacket: allow only one element per type in packet side data
It was never meant to do otherwise, as av_packet_get_side_data() returns the first
entry it finds of a given type.

Based on code from libavformat's av_stream_add_side_data().

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2017-05-12 18:30:31 -03:00
Michael Niedermayer d5711cb891 avcodec/avcodec: Limit the number of side data elements per packet
Fixes: 1293/clusterfuzz-testcase-minimized-6054752074858496

See: [FFmpeg-devel] [PATCH] avcodec/avcodec: Limit the number of side data elements per packet

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/targets/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-05-12 14:19:52 +02:00
Michael Niedermayer e813df4fa3 avcodec: Avoid splitting side data repeatedly
Fixes Timeout
Fixes: 508/clusterfuzz-testcase-6245747678773248

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/targets/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-05-06 03:54:17 +02:00
Steve Lhomme 157e57a181 lavc: Add Content Light Level side metadata found in HEVC
These data are necessary when transmitting HDR over HDMI.

Signed-off-by: James Almer <jamrial@gmail.com>
2017-04-06 11:38:15 -03:00
Clément Bœsch 507a85b93c Merge commit 'adb0e941c329a4778ade6dd0a326274472992f54'
* commit 'adb0e941c329a4778ade6dd0a326274472992f54':
  avpacket: Mark src pointer as constant

See 5bb3f88255

Merged-by: Clément Bœsch <u@pkh.me>
2017-04-01 18:23:21 +02:00
wm4 d682ae70b4 avcodec, avformat: deprecate anything related to side data merging
This patch deprecates anything that has to do with merging/splitting
side data. Automatic side data merging (and splitting), as well as all
API symbols involved in it, are removed completely.

Two FF_API_ defines are dedicated to deprecating API symbols related to
this: FF_API_MERGE_SD_API removes av_packet_split/merge_side_data in
libavcodec, and FF_API_LAVF_KEEPSIDE_FLAG deprecates
AVFMT_FLAG_KEEP_SIDE_DATA in libavformat.

Since it was claimed that changing the default from merging side data to
not doing it is an ABI change, there are two additional FF_API_ defines,
which stop using the side data merging/splitting by default (and remove
any code in avformat/avcodec doing this): FF_API_MERGE_SD in libavcodec,
and FF_API_LAVF_MERGE_SD in libavformat.

It is very much intended that FF_API_MERGE_SD and FF_API_LAVF_MERGE_SD
are quickly defined to 0 in the next ABI bump, while the API symbols are
retained for a longer time for the sake of compatibility.
AVFMT_FLAG_KEEP_SIDE_DATA will (very much intentionally) do nothing for
most of the time it will still be defined. Keep in mind that no code
exists that actually tries to unset this flag for any reason, nor does
such code need to exist. Code setting this flag explicitly will work as
before. Thus it's ok for AVFMT_FLAG_KEEP_SIDE_DATA to do nothing once
side data merging has been removed from libavformat.

In order to avoid that anyone in the future does this incorrectly, here
is a small guide how to update the internal code on bumps:

- next ABI bump (probably soon):
  - define FF_API_LAVF_MERGE_SD to 0, and remove all code covered by it
  - define FF_API_MERGE_SD to 0, and remove all code covered by it
- next API bump (typically two years in the future or so):
  - define FF_API_LAVF_KEEPSIDE_FLAG to 0, and remove all code covered
    by it
  - define FF_API_MERGE_SD_API to 0, and remove all code covered by it

This forces anyone who actually wants packet side data to temporarily
use deprecated API to get it all. If you ask me, this is batshit fucked
up crazy, but it's how we roll. Making AVFMT_FLAG_KEEP_SIDE_DATA to be
set by default was rejected as an ABI change, so I'm going all the way
to get rid of this once and for all.

Reviewed-by: James Almer <jamrial@gmail.com>
Reviewed-by: Rostislav Pehlivanov <atomnuker@gmail.com>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
2017-03-21 06:13:45 +01:00
Carl Eugen Hoyos 0d34dbc272 lavc/avpacket: Make pkt parameter of av_packet_get_side_data() const.
Reflects the actual code and silences a gcc warning:
libavcodec/utils.c:2102:36: warning: passing argument 1 of 'av_packet_get_side_data' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
2017-03-16 21:09:41 +01:00