Merge commit '759001c534287a96dc96d1e274665feb7059145d'
[ffmpeg.git] / libavcodec / mjpegdec.c
index f3080d9..2f75194 100644 (file)
@@ -303,7 +303,6 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
     if (   width != s->width || height != s->height
         || memcmp(s->h_count, h_count, sizeof(h_count))
         || memcmp(s->v_count, v_count, sizeof(v_count))) {
-        av_freep(&s->qscale_table);
 
         s->width      = width;
         s->height     = height;
@@ -325,7 +324,6 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
 
         avcodec_set_dimensions(s->avctx, width, height);
 
-        s->qscale_table  = av_mallocz((s->width + 15) / 16);
         s->first_picture = 0;
     }
 
@@ -443,10 +441,8 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
             s->avctx->pix_fmt = AV_PIX_FMT_GRAY16;
     }
 
-    if (s->picture_ptr->data[0])
-        s->avctx->release_buffer(s->avctx, s->picture_ptr);
-
-    if (ff_get_buffer(s->avctx, s->picture_ptr) < 0) {
+    av_frame_unref(s->picture_ptr);
+    if (ff_get_buffer(s->avctx, s->picture_ptr, AV_GET_BUFFER_FLAG_REF) < 0) {
         av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         return -1;
     }
@@ -1640,7 +1636,6 @@ int ff_mjpeg_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     int start_code;
     int i, index;
     int ret = 0;
-    AVFrame *picture = data;
 
     buf_ptr = buf;
     buf_end = buf + buf_size;
@@ -1741,22 +1736,17 @@ eoi_parser:
                     if (s->bottom_field == !s->interlace_polarity)
                         break;
                 }
-                *picture   = *s->picture_ptr;
+                if ((ret = av_frame_ref(data, s->picture_ptr)) < 0)
+                    return ret;
                 *got_frame = 1;
                 s->got_picture = 0;
 
-                if (!s->lossless) {
-                    picture->quality      = FFMAX3(s->qscale[0],
-                                                   s->qscale[1],
-                                                   s->qscale[2]);
-                    picture->qstride      = 0;
-                    picture->qscale_table = s->qscale_table;
-                    memset(picture->qscale_table, picture->quality,
-                           (s->width + 15) / 16);
-                    if (avctx->debug & FF_DEBUG_QP)
-                        av_log(avctx, AV_LOG_DEBUG,
-                               "QP: %d\n", picture->quality);
-                    picture->quality *= FF_QP2LAMBDA;
+                if (!s->lossless &&
+                    avctx->debug & FF_DEBUG_QP) {
+                    av_log(avctx, AV_LOG_DEBUG,
+                           "QP: %d\n", FFMAX3(s->qscale[0],
+                                              s->qscale[1],
+                                              s->qscale[2]));
                 }
 
                 goto the_end;
@@ -1864,11 +1854,10 @@ av_cold int ff_mjpeg_decode_end(AVCodecContext *avctx)
     MJpegDecodeContext *s = avctx->priv_data;
     int i, j;
 
-    if (s->picture_ptr && s->picture_ptr->data[0])
-        avctx->release_buffer(avctx, s->picture_ptr);
+    if (s->picture_ptr)
+        av_frame_unref(s->picture_ptr);
 
     av_free(s->buffer);
-    av_free(s->qscale_table);
     av_freep(&s->ljpeg_buffer);
     s->ljpeg_buffer_size = 0;