*/
#include "config.h"
+#include "libavutil/atomic.h"
#include "libavutil/attributes.h"
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
AVCodec **p;
avcodec_init();
p = &first_avcodec;
- while (*p != NULL)
- p = &(*p)->next;
- *p = codec;
codec->next = NULL;
+ while(avpriv_atomic_ptr_cas((void * volatile *)p, NULL, codec))
+ p = &(*p)->next;
if (codec->init_static_data)
codec->init_static_data(codec);
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int size)
{
- if (size < 0 || avpkt->size < 0 || size > INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE) {
- av_log(avctx, AV_LOG_ERROR, "Size %d invalid\n", size);
+ if (avpkt->size < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid negative user packet size %d\n", avpkt->size);
+ return AVERROR(EINVAL);
+ }
+ if (size < 0 || size > INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid minimum required packet size %d (max allowed is %d)\n",
+ size, INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE);
return AVERROR(EINVAL);
}
avpkt->flags |= AV_PKT_FLAG_KEY;
end:
- if (padded_frame) {
- av_freep(&padded_frame->data[0]);
- if (padded_frame->extended_data != padded_frame->data)
- av_freep(&padded_frame->extended_data);
- av_freep(&padded_frame);
- }
+ av_frame_free(&padded_frame);
return ret;
}
// copy to ensure we do not change avpkt
AVPacket tmp = *avpkt;
+ if (!avctx->codec)
+ return AVERROR(EINVAL);
if (avctx->codec->type != AVMEDIA_TYPE_VIDEO) {
av_log(avctx, AV_LOG_ERROR, "Invalid media type for video\n");
return AVERROR(EINVAL);
avctx->pts_correction_last_pts =
avctx->pts_correction_last_dts = INT64_MIN;
+
+ if (!avctx->refcounted_frames)
+ av_frame_unref(&avctx->internal->to_free);
}
int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
void av_register_hwaccel(AVHWAccel *hwaccel)
{
AVHWAccel **p = &first_hwaccel;
- while (*p)
- p = &(*p)->next;
- *p = hwaccel;
hwaccel->next = NULL;
+ while(avpriv_atomic_ptr_cas((void * volatile *)p, NULL, hwaccel))
+ p = &(*p)->next;
}
AVHWAccel *av_hwaccel_next(AVHWAccel *hwaccel)