]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/utils.c
lavc: use buf[0] instead of data[0] as the indicator of an allocated frame
[ffmpeg] / libavcodec / utils.c
index 2f5c170c69de818a69e70009fc9eee16492889b0..d1a1510858b2842e40fe024922e7cf0f4cd76925 100644 (file)
@@ -55,37 +55,17 @@ static int (*lockmgr_cb)(void **mutex, enum AVLockOp op);
 static void *codec_mutex;
 static void *avformat_mutex;
 
-void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
+#if FF_API_FAST_MALLOC && CONFIG_SHARED && HAVE_SYMVER
+FF_SYMVER(void*, av_fast_realloc, (void *ptr, unsigned int *size, size_t min_size), "LIBAVCODEC_55")
 {
-    if (min_size < *size)
-        return ptr;
-
-    min_size = FFMAX(17 * min_size / 16 + 32, min_size);
-
-    ptr = av_realloc(ptr, min_size);
-    /* we could set this to the unmodified min_size but this is safer
-     * if the user lost the ptr and uses NULL now
-     */
-    if (!ptr)
-        min_size = 0;
-
-    *size = min_size;
-
-    return ptr;
+    return av_fast_realloc(ptr, size, min_size);
 }
 
-void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
+FF_SYMVER(void, av_fast_malloc, (void *ptr, unsigned int *size, size_t min_size), "LIBAVCODEC_55")
 {
-    void **p = ptr;
-    if (min_size < *size)
-        return;
-    min_size = FFMAX(17 * min_size / 16 + 32, min_size);
-    av_free(*p);
-    *p = av_malloc(min_size);
-    if (!*p)
-        min_size = 0;
-    *size = min_size;
+    av_fast_malloc(ptr, size, min_size);
 }
+#endif
 
 void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
 {
@@ -835,6 +815,7 @@ void avcodec_get_frame_defaults(AVFrame *frame)
     frame->extended_data       = frame->data;
 }
 
+#if FF_API_AVFRAME_LAVC
 AVFrame *avcodec_alloc_frame(void)
 {
     AVFrame *frame = av_mallocz(sizeof(AVFrame));
@@ -846,6 +827,7 @@ AVFrame *avcodec_alloc_frame(void)
 
     return frame;
 }
+#endif
 
 void avcodec_free_frame(AVFrame **frame)
 {
@@ -1145,7 +1127,7 @@ static int pad_last_frame(AVCodecContext *s, AVFrame **dst, const AVFrame *src)
     AVFrame *frame = NULL;
     int ret;
 
-    if (!(frame = avcodec_alloc_frame()))
+    if (!(frame = av_frame_alloc()))
         return AVERROR(ENOMEM);
 
     frame->format         = src->format;
@@ -1434,7 +1416,7 @@ int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *pi
 
         emms_c(); //needed to avoid an emms_c() call before every return;
 
-        if (ret < 0 && picture->data[0])
+        if (ret < 0 && picture->buf[0])
             av_frame_unref(picture);
 
         if (*got_picture_ptr) {
@@ -1449,10 +1431,6 @@ int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *pi
     } else
         ret = 0;
 
-    /* many decoders assign whole AVFrames, thus overwriting extended_data;
-     * make sure it's set correctly */
-    picture->extended_data = picture->data;
-
     return ret;
 }
 
@@ -1462,7 +1440,6 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx,
                                               AVPacket *avpkt)
 {
     AVCodecInternal *avci = avctx->internal;
-    int planar, channels;
     int ret = 0;
 
     *got_frame_ptr = 0;
@@ -1505,13 +1482,6 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx,
             av_frame_unref(frame);
     }
 
-    /* many decoders assign whole AVFrames, thus overwriting extended_data;
-     * make sure it's set correctly; assume decoders that actually use
-     * extended_data are doing it correctly */
-    planar   = av_sample_fmt_is_planar(frame->format);
-    channels = av_get_channel_layout_nb_channels(frame->channel_layout);
-    if (!(planar && channels > AV_NUM_DATA_POINTERS))
-        frame->extended_data = frame->data;
 
     return ret;
 }