Skip to content

Commit

Permalink
avutil/buffer: Switch AVBuffer API to size_t
Browse files Browse the repository at this point in the history
Announced in 14040a1.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: James Almer <jamrial@gmail.com>
  • Loading branch information
mkver authored and jamrial committed Apr 27, 2021
1 parent 985c0da commit ef6a9e5
Show file tree
Hide file tree
Showing 66 changed files with 110 additions and 206 deletions.
2 changes: 1 addition & 1 deletion fftools/ffprobe.c
Original file line number Diff line number Diff line change
Expand Up @@ -2158,7 +2158,7 @@ static void show_packet(WriterContext *w, InputFile *ifile, AVPacket *pkt, int p
pkt->flags & AV_PKT_FLAG_DISCARD ? 'D' : '_');

if (pkt->side_data_elems) {
int size;
size_t size;
const uint8_t *side_metadata;

side_metadata = av_packet_get_side_data(pkt, AV_PKT_DATA_STRINGS_METADATA, &size);
Expand Down
4 changes: 2 additions & 2 deletions libavcodec/aacdec_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -3437,11 +3437,11 @@ static int aac_decode_frame(AVCodecContext *avctx, void *data,
int buf_consumed;
int buf_offset;
int err;
buffer_size_t new_extradata_size;
size_t new_extradata_size;
const uint8_t *new_extradata = av_packet_get_side_data(avpkt,
AV_PKT_DATA_NEW_EXTRADATA,
&new_extradata_size);
buffer_size_t jp_dualmono_size;
size_t jp_dualmono_size;
const uint8_t *jp_dualmono = av_packet_get_side_data(avpkt,
AV_PKT_DATA_JP_DUALMONO,
&jp_dualmono_size);
Expand Down
2 changes: 1 addition & 1 deletion libavcodec/adxdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static int adx_decode_frame(AVCodecContext *avctx, void *data,
const uint8_t *buf = avpkt->data;
const uint8_t *buf_end = buf + avpkt->size;
int num_blocks, ch, ret;
buffer_size_t new_extradata_size;
size_t new_extradata_size;
uint8_t *new_extradata;

new_extradata = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA,
Expand Down
2 changes: 1 addition & 1 deletion libavcodec/audiotoolboxdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ static int ffat_decode(AVCodecContext *avctx, void *data,
if (avctx->codec_id == AV_CODEC_ID_AAC) {
if (!at->extradata_size) {
uint8_t *side_data;
buffer_size_t side_data_size;
size_t side_data_size;

side_data = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA,
&side_data_size);
Expand Down
28 changes: 6 additions & 22 deletions libavcodec/avpacket.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,12 @@ int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type,


uint8_t *av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
buffer_size_t size)
size_t size)
{
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)
Expand All @@ -243,7 +239,7 @@ 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,
buffer_size_t *size)
size_t *size)
{
int i;

Expand Down Expand Up @@ -297,11 +293,7 @@ const char *av_packet_side_data_name(enum AVPacketSideDataType type)
return NULL;
}

#if FF_API_BUFFER_SIZE_T
uint8_t *av_packet_pack_dictionary(AVDictionary *dict, int *size)
#else
uint8_t *av_packet_pack_dictionary(AVDictionary *dict, size_t *size)
#endif
{
uint8_t *data = NULL;
*size = 0;
Expand All @@ -320,11 +312,7 @@ uint8_t *av_packet_pack_dictionary(AVDictionary *dict, size_t *size)

if (pass)
memcpy(data + total_length, str, len);
#if FF_API_BUFFER_SIZE_T
else if (len > INT_MAX - total_length)
#else
else if (len > SIZE_MAX - total_length)
#endif
return NULL;
total_length += len;
}
Expand All @@ -340,12 +328,8 @@ uint8_t *av_packet_pack_dictionary(AVDictionary *dict, size_t *size)
return data;
}

#if FF_API_BUFFER_SIZE_T
int av_packet_unpack_dictionary(const uint8_t *data, int size, AVDictionary **dict)
#else
int av_packet_unpack_dictionary(const uint8_t *data, size_t size,
AVDictionary **dict)
#endif
{
const uint8_t *end;
int ret;
Expand All @@ -372,7 +356,7 @@ int av_packet_unpack_dictionary(const uint8_t *data, size_t size,
}

int av_packet_shrink_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
buffer_size_t size)
size_t size)
{
int i;

Expand Down Expand Up @@ -402,7 +386,7 @@ int av_packet_copy_props(AVPacket *dst, const AVPacket *src)
dst->side_data_elems = 0;
for (i = 0; i < src->side_data_elems; i++) {
enum AVPacketSideDataType type = src->side_data[i].type;
buffer_size_t size = src->side_data[i].size;
size_t size = src->side_data[i].size;
uint8_t *src_data = src->side_data[i].data;
uint8_t *dst_data = av_packet_new_side_data(dst, type, size);

Expand Down Expand Up @@ -599,7 +583,7 @@ void avpriv_packet_list_free(PacketList **pkt_buf, PacketList **pkt_buf_end)
int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type)
{
uint8_t *side_data;
buffer_size_t side_data_size;
size_t side_data_size;
int i;

side_data = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS, &side_data_size);
Expand All @@ -625,7 +609,7 @@ int ff_side_data_set_prft(AVPacket *pkt, int64_t timestamp)
{
AVProducerReferenceTime *prft;
uint8_t *side_data;
buffer_size_t side_data_size;
size_t side_data_size;

side_data = av_packet_get_side_data(pkt, AV_PKT_DATA_PRFT, &side_data_size);
if (!side_data) {
Expand Down
2 changes: 1 addition & 1 deletion libavcodec/cbs_bsf.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static int cbs_bsf_update_side_data(AVBSFContext *bsf, AVPacket *pkt)
CBSBSFContext *ctx = bsf->priv_data;
CodedBitstreamFragment *frag = &ctx->fragment;
uint8_t *side_data;
buffer_size_t side_data_size;
size_t side_data_size;
int err;

side_data = av_packet_get_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA,
Expand Down
13 changes: 7 additions & 6 deletions libavcodec/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ typedef struct FramePool {
static int apply_param_change(AVCodecContext *avctx, const AVPacket *avpkt)
{
int ret;
buffer_size_t size;
size_t size;
const uint8_t *data;
uint32_t flags;
int64_t val;
Expand Down Expand Up @@ -344,7 +344,7 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame,
got_frame = 0;
} else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
uint8_t *side;
buffer_size_t side_size;
size_t side_size;
uint32_t discard_padding = 0;
uint8_t skip_reason = 0;
uint8_t discard_reason = 0;
Expand Down Expand Up @@ -1463,7 +1463,7 @@ int avcodec_default_get_buffer2(AVCodecContext *avctx, AVFrame *frame, int flags

static int add_metadata_from_side_data(const AVPacket *avpkt, AVFrame *frame)
{
buffer_size_t size;
size_t size;
const uint8_t *side_metadata;

AVDictionary **frame_md = &frame->metadata;
Expand Down Expand Up @@ -1502,7 +1502,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
frame->pkt_size = pkt->size;

for (int i = 0; i < FF_ARRAY_ELEMS(sd); i++) {
buffer_size_t size;
size_t size;
uint8_t *packet_sd = av_packet_get_side_data(pkt, sd[i].packet, &size);
if (packet_sd) {
AVFrameSideData *frame_sd = av_frame_new_side_data(frame,
Expand Down Expand Up @@ -1841,14 +1841,15 @@ FF_ENABLE_DEPRECATION_WARNINGS

int ff_copy_palette(void *dst, const AVPacket *src, void *logctx)
{
buffer_size_t size;
size_t size;
const void *pal = av_packet_get_side_data(src, AV_PKT_DATA_PALETTE, &size);

if (pal && size == AVPALETTE_SIZE) {
memcpy(dst, pal, AVPALETTE_SIZE);
return 1;
} else if (pal) {
av_log(logctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size);
av_log(logctx, AV_LOG_ERROR,
"Palette size %"SIZE_SPECIFIER" is wrong\n", size);
}
return 0;
}
2 changes: 1 addition & 1 deletion libavcodec/h264_metadata_bsf.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ static int h264_metadata_handle_display_orientation(AVBSFContext *bsf,
H264RawSEIDisplayOrientation *disp =
&ctx->display_orientation_payload;
uint8_t *data;
buffer_size_t size;
size_t size;
int write = 0;

data = av_packet_get_side_data(pkt, AV_PKT_DATA_DISPLAYMATRIX, &size);
Expand Down
2 changes: 1 addition & 1 deletion libavcodec/h264dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ static int h264_decode_frame(AVCodecContext *avctx, void *data,
return send_next_delayed_frame(h, pict, got_frame, 0);

if (av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, NULL)) {
buffer_size_t side_size;
size_t side_size;
uint8_t *side = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, &side_size);
ff_h264_decode_extradata(side, side_size,
&h->ps, &h->is_avc, &h->nal_length_size,
Expand Down
2 changes: 1 addition & 1 deletion libavcodec/hevcdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -3303,7 +3303,7 @@ static int hevc_decode_frame(AVCodecContext *avctx, void *data, int *got_output,
AVPacket *avpkt)
{
int ret;
buffer_size_t new_extradata_size;
size_t new_extradata_size;
uint8_t *new_extradata;
HEVCContext *s = avctx->priv_data;

Expand Down
2 changes: 1 addition & 1 deletion libavcodec/libvpxdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ static int vpx_decode(AVCodecContext *avctx,
struct vpx_image *img, *img_alpha;
int ret;
uint8_t *side_data = NULL;
buffer_size_t side_data_size;
size_t side_data_size;

ret = decode_frame(avctx, &ctx->decoder, avpkt->data, avpkt->size);
if (ret)
Expand Down
4 changes: 2 additions & 2 deletions libavcodec/mpeg12enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,8 @@ void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number)
put_bits(&s->pb, 8, 0xff); // marker_bits
} else {
av_log(s->avctx, AV_LOG_WARNING,
"Warning Closed Caption size (%d) can not exceed 93 bytes "
"and must be a multiple of 3\n", side_data->size);
"Closed Caption size (%"SIZE_SPECIFIER") can not exceed "
"93 bytes and must be a multiple of 3\n", side_data->size);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions libavcodec/mscc.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,16 @@ static int decode_frame(AVCodecContext *avctx,
}

if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
buffer_size_t size;
size_t size;
const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &size);

if (pal && size == AVPALETTE_SIZE) {
frame->palette_has_changed = 1;
for (j = 0; j < 256; j++)
s->pal[j] = 0xFF000000 | AV_RL32(pal + j * 4);
} else if (pal) {
av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size);
av_log(avctx, AV_LOG_ERROR,
"Palette size %"SIZE_SPECIFIER" is wrong\n", size);
}
memcpy(frame->data[1], s->pal, AVPALETTE_SIZE);
}
Expand Down
4 changes: 2 additions & 2 deletions libavcodec/nvdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ static int nvdec_decoder_create(AVBufferRef **out, AVBufferRef *hw_device_ref,
return ret;
}

static AVBufferRef *nvdec_decoder_frame_alloc(void *opaque, buffer_size_t size)
static AVBufferRef *nvdec_decoder_frame_alloc(void *opaque, size_t size)
{
NVDECFramePool *pool = opaque;
AVBufferRef *ret;
Expand Down Expand Up @@ -283,7 +283,7 @@ static void nvdec_free_dummy(struct AVHWFramesContext *ctx)
av_buffer_pool_uninit(&ctx->pool);
}

static AVBufferRef *nvdec_alloc_dummy(buffer_size_t size)
static AVBufferRef *nvdec_alloc_dummy(size_t size)
{
return av_buffer_create(NULL, 0, NULL, NULL, 0);
}
Expand Down
24 changes: 0 additions & 24 deletions libavcodec/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,7 @@ 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;

Expand Down Expand Up @@ -528,11 +524,7 @@ int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size);
* @return pointer to fresh allocated data or NULL otherwise
*/
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

/**
* Wrap an existing array as a packet side data.
Expand All @@ -559,11 +551,7 @@ int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
* @return 0 on success, < 0 on failure
*/
int av_packet_shrink_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
#if FF_API_BUFFER_SIZE_T
int size);
#else
size_t size);
#endif

/**
* Get side information from packet.
Expand All @@ -575,11 +563,7 @@ int av_packet_shrink_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
* @return pointer to data if present or NULL otherwise
*/
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

const char *av_packet_side_data_name(enum AVPacketSideDataType type);

Expand All @@ -590,11 +574,7 @@ const char *av_packet_side_data_name(enum AVPacketSideDataType type);
* @param size pointer to store the size of the returned data
* @return pointer to data if successful, NULL otherwise
*/
#if FF_API_BUFFER_SIZE_T
uint8_t *av_packet_pack_dictionary(AVDictionary *dict, int *size);
#else
uint8_t *av_packet_pack_dictionary(AVDictionary *dict, size_t *size);
#endif
/**
* Unpack a dictionary from side_data.
*
Expand All @@ -603,12 +583,8 @@ uint8_t *av_packet_pack_dictionary(AVDictionary *dict, size_t *size);
* @param dict the metadata storage dictionary
* @return 0 on success, < 0 on failure
*/
#if FF_API_BUFFER_SIZE_T
int av_packet_unpack_dictionary(const uint8_t *data, int size, AVDictionary **dict);
#else
int av_packet_unpack_dictionary(const uint8_t *data, size_t size,
AVDictionary **dict);
#endif

/**
* Convenience function to free all the side data stored.
Expand Down
2 changes: 1 addition & 1 deletion libavcodec/srtdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static int srt_decode_frame(AVCodecContext *avctx,
AVBPrint buffer;
int x1 = -1, y1 = -1, x2 = -1, y2 = -1;
int ret;
buffer_size_t size;
size_t size;
const uint8_t *p = av_packet_get_side_data(avpkt, AV_PKT_DATA_SUBTITLE_POSITION, &size);
FFASSDecoderContext *s = avctx->priv_data;

Expand Down
2 changes: 1 addition & 1 deletion libavcodec/vaapi_encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -2235,7 +2235,7 @@ static void vaapi_encode_free_output_buffer(void *opaque,
}

static AVBufferRef *vaapi_encode_alloc_output_buffer(void *opaque,
buffer_size_t size)
size_t size)
{
AVCodecContext *avctx = opaque;
VAAPIEncodeContext *ctx = avctx->priv_data;
Expand Down
4 changes: 2 additions & 2 deletions libavdevice/decklink_dec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ HRESULT decklink_input_callback::VideoInputFrameArrived(
}

if (av_dict_set(&metadata_dict, "timecode", tc, 0) >= 0) {
buffer_size_t metadata_len;
size_t metadata_len;
packed_metadata = av_packet_pack_dictionary(metadata_dict, &metadata_len);
av_dict_free(&metadata_dict);
if (packed_metadata) {
Expand Down Expand Up @@ -1435,7 +1435,7 @@ int ff_decklink_read_packet(AVFormatContext *avctx, AVPacket *pkt)
avpacket_queue_get(&ctx->queue, pkt, 1);

if (ctx->tc_format && !(av_dict_get(ctx->video_st->metadata, "timecode", NULL, 0))) {
buffer_size_t size;
size_t size;
const uint8_t *side_metadata = av_packet_get_side_data(pkt, AV_PKT_DATA_STRINGS_METADATA, &size);
if (side_metadata) {
if (av_packet_unpack_dictionary(side_metadata, size, &ctx->video_st->metadata) < 0)
Expand Down

0 comments on commit ef6a9e5

Please sign in to comment.