[FFmpeg-devel] [PATCH 3/4] avcodec/packet: change side data related public function and struct size types to size_t
James Almer
jamrial at gmail.com
Mon Jun 1 20:25:38 EEST 2020
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 at gmail.com>
---
I could either add ifdeffery to every size argument used in
av_packet_get_side_data() calls within the libraries, add an internal typedef
that goes int -> size_t depending on FF_API_BUFFER_SIZE_T and use that, or just
not bother with them right now and change them after the bump in the same
commit that removes FF_API_BUFFER_SIZE_T.
In this patch i went the ifdef route for ff_side_data_set_encoder_stats() and
ff_side_data_set_prft().
doc/APIchanges | 4 ++--
libavcodec/avpacket.c | 28 ++++++++++++++++++++++++++++
libavcodec/packet.h | 4 ++++
3 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/doc/APIchanges b/doc/APIchanges
index dbf21c1d1e..d616594ff6 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -16,8 +16,8 @@ libavutil: 2017-10-21
API changes, most recent first:
2020-06-xx - xxxxxxxxxx
- Change AVBufferRef and relevant AVFrameSideData function and struct size
- parameter and fields type to size_t at next major bump.
+ Change AVBufferRef and relevant AVFrameSideData and AVPacketSideData function and
+ struct size parameter and fields type to size_t at next major bump.
2020-xx-xx - xxxxxxxxxx - lavc 58.88.100 - avcodec.h codec.h
Move AVCodec-related public API to new header codec.h.
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 033f2d8f26..db9c947b62 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -329,12 +329,20 @@ int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
uint8_t *av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
+#if FF_API_BUFFER_SIZE_T
int size)
+#else
+ size_t size)
+#endif
{
int ret;
uint8_t *data;
+#if FF_API_BUFFER_SIZE_T
if ((unsigned)size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
+#else
+ if (size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
+#endif
return NULL;
data = av_mallocz(size + AV_INPUT_BUFFER_PADDING_SIZE);
if (!data)
@@ -350,7 +358,11 @@ uint8_t *av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
}
uint8_t *av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type,
+#if FF_API_BUFFER_SIZE_T
int *size)
+#else
+ size_t *size)
+#endif
{
int i;
@@ -552,7 +564,11 @@ int av_packet_unpack_dictionary(const uint8_t *data, int size, AVDictionary **di
}
int av_packet_shrink_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
+#if FF_API_BUFFER_SIZE_T
int size)
+#else
+ size_t size)
+#endif
{
int i;
@@ -587,7 +603,11 @@ FF_ENABLE_DEPRECATION_WARNINGS
dst->side_data_elems = 0;
for (i = 0; i < src->side_data_elems; i++) {
enum AVPacketSideDataType type = src->side_data[i].type;
+#if FF_API_BUFFER_SIZE_T
int size = src->side_data[i].size;
+#else
+ size_t size = src->side_data[i].size;
+#endif
uint8_t *src_data = src->side_data[i].data;
uint8_t *dst_data = av_packet_new_side_data(dst, type, size);
@@ -727,7 +747,11 @@ FF_ENABLE_DEPRECATION_WARNINGS
int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type)
{
uint8_t *side_data;
+#if FF_API_BUFFER_SIZE_T
int side_data_size;
+#else
+ size_t side_data_size;
+#endif
int i;
side_data = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS, &side_data_size);
@@ -753,7 +777,11 @@ int ff_side_data_set_prft(AVPacket *pkt, int64_t timestamp)
{
AVProducerReferenceTime *prft;
uint8_t *side_data;
+#if FF_API_BUFFER_SIZE_T
int side_data_size;
+#else
+ size_t side_data_size;
+#endif
side_data = av_packet_get_side_data(pkt, AV_PKT_DATA_PRFT, &side_data_size);
if (!side_data) {
diff --git a/libavcodec/packet.h b/libavcodec/packet.h
index 41485f4527..5b98ae812e 100644
--- a/libavcodec/packet.h
+++ b/libavcodec/packet.h
@@ -297,7 +297,11 @@ enum AVPacketSideDataType {
typedef struct AVPacketSideData {
uint8_t *data;
+#if FF_API_BUFFER_SIZE_T
int size;
+#else
+ size_t size;
+#endif
enum AVPacketSideDataType type;
} AVPacketSideData;
--
2.26.2
More information about the ffmpeg-devel
mailing list