]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/huffyuvdec.c
Use av_packet_rescale_ts() to simplify code.
[ffmpeg] / libavcodec / huffyuvdec.c
index 0946d3d47e72cf98e7b6264b28207d52d8296a77..2baaaff10162db6d374d131a6c40061e462005cc 100644 (file)
@@ -29,9 +29,9 @@
  */
 
 #include "avcodec.h"
-#include "dsputil.h"
 #include "get_bits.h"
 #include "huffyuv.h"
+#include "huffyuvdsp.h"
 #include "thread.h"
 
 #define classic_shift_luma_table_size 42
@@ -240,9 +240,9 @@ static av_cold int decode_init(AVCodecContext *avctx)
     HYuvContext *s = avctx->priv_data;
 
     ff_huffyuv_common_init(avctx);
+    ff_huffyuvdsp_init(&s->hdsp);
     memset(s->vlc, 0, 3 * sizeof(VLC));
 
-    avctx->coded_frame = &s->picture;
     s->interlaced = s->height > 288;
 
     s->bgr32 = 1;
@@ -338,7 +338,6 @@ static av_cold int decode_init_thread_copy(AVCodecContext *avctx)
     HYuvContext *s = avctx->priv_data;
     int i;
 
-    avctx->coded_frame= &s->picture;
     ff_huffyuv_alloc_temp(s);
 
     for (i = 0; i < 6; i++)
@@ -444,7 +443,7 @@ static void decode_bgr_bitstream(HYuvContext *s, int count)
     }
 }
 
-static void draw_slice(HYuvContext *s, int y)
+static void draw_slice(HYuvContext *s, AVFrame *frame, int y)
 {
     int h, cy, i;
     int offset[AV_NUM_DATA_POINTERS];
@@ -461,14 +460,14 @@ static void draw_slice(HYuvContext *s, int y)
         cy = y;
     }
 
-    offset[0] = s->picture.linesize[0]*y;
-    offset[1] = s->picture.linesize[1]*cy;
-    offset[2] = s->picture.linesize[2]*cy;
+    offset[0] = frame->linesize[0] * y;
+    offset[1] = frame->linesize[1] * cy;
+    offset[2] = frame->linesize[2] * cy;
     for (i = 3; i < AV_NUM_DATA_POINTERS; i++)
         offset[i] = 0;
     emms_c();
 
-    s->avctx->draw_horiz_band(s->avctx, &s->picture, offset, y, 3, h);
+    s->avctx->draw_horiz_band(s->avctx, frame, offset, y, 3, h);
 
     s->last_slice_end = y + h;
 }
@@ -483,11 +482,10 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     const int width2 = s->width>>1;
     const int height = s->height;
     int fake_ystride, fake_ustride, fake_vstride;
-    AVFrame * const p = &s->picture;
+    ThreadFrame frame = { .f = data };
+    AVFrame * const p = data;
     int table_size = 0;
 
-    AVFrame *picture = data;
-
     av_fast_malloc(&s->bitstream_buffer,
                    &s->bitstream_buffer_size,
                    buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
@@ -498,11 +496,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     s->dsp.bswap_buf((uint32_t*)s->bitstream_buffer,
                      (const uint32_t*)buf, buf_size / 4);
 
-    if (p->data[0])
-        ff_thread_release_buffer(avctx, p);
-
-    p->reference = 0;
-    if (ff_thread_get_buffer(avctx, p) < 0) {
+    if (ff_thread_get_buffer(avctx, &frame, 0) < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         return -1;
     }
@@ -550,10 +544,10 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
             case LEFT:
             case PLANE:
                 decode_422_bitstream(s, width-2);
-                lefty = s->dsp.add_hfyu_left_prediction(p->data[0] + 2, s->temp[0], width-2, lefty);
+                lefty = s->hdsp.add_hfyu_left_pred(p->data[0] + 2, s->temp[0], width - 2, lefty);
                 if (!(s->flags&CODEC_FLAG_GRAY)) {
-                    leftu = s->dsp.add_hfyu_left_prediction(p->data[1] + 1, s->temp[1], width2 - 1, leftu);
-                    leftv = s->dsp.add_hfyu_left_prediction(p->data[2] + 1, s->temp[2], width2 - 1, leftv);
+                    leftu = s->hdsp.add_hfyu_left_pred(p->data[1] + 1, s->temp[1], width2 - 1, leftu);
+                    leftv = s->hdsp.add_hfyu_left_pred(p->data[2] + 1, s->temp[2], width2 - 1, leftv);
                 }
 
                 for (cy = y = 1; y < s->height; y++, cy++) {
@@ -564,47 +558,47 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
 
                         ydst = p->data[0] + p->linesize[0] * y;
 
-                        lefty = s->dsp.add_hfyu_left_prediction(ydst, s->temp[0], width, lefty);
+                        lefty = s->hdsp.add_hfyu_left_pred(ydst, s->temp[0], width, lefty);
                         if (s->predictor == PLANE) {
                             if (y > s->interlaced)
-                                s->dsp.add_bytes(ydst, ydst - fake_ystride, width);
+                                s->hdsp.add_bytes(ydst, ydst - fake_ystride, width);
                         }
                         y++;
                         if (y >= s->height) break;
                     }
 
-                    draw_slice(s, y);
+                    draw_slice(s, p, y);
 
                     ydst = p->data[0] + p->linesize[0]*y;
                     udst = p->data[1] + p->linesize[1]*cy;
                     vdst = p->data[2] + p->linesize[2]*cy;
 
                     decode_422_bitstream(s, width);
-                    lefty = s->dsp.add_hfyu_left_prediction(ydst, s->temp[0], width, lefty);
+                    lefty = s->hdsp.add_hfyu_left_pred(ydst, s->temp[0], width, lefty);
                     if (!(s->flags & CODEC_FLAG_GRAY)) {
-                        leftu= s->dsp.add_hfyu_left_prediction(udst, s->temp[1], width2, leftu);
-                        leftv= s->dsp.add_hfyu_left_prediction(vdst, s->temp[2], width2, leftv);
+                        leftu = s->hdsp.add_hfyu_left_pred(udst, s->temp[1], width2, leftu);
+                        leftv = s->hdsp.add_hfyu_left_pred(vdst, s->temp[2], width2, leftv);
                     }
                     if (s->predictor == PLANE) {
                         if (cy > s->interlaced) {
-                            s->dsp.add_bytes(ydst, ydst - fake_ystride, width);
+                            s->hdsp.add_bytes(ydst, ydst - fake_ystride, width);
                             if (!(s->flags & CODEC_FLAG_GRAY)) {
-                                s->dsp.add_bytes(udst, udst - fake_ustride, width2);
-                                s->dsp.add_bytes(vdst, vdst - fake_vstride, width2);
+                                s->hdsp.add_bytes(udst, udst - fake_ustride, width2);
+                                s->hdsp.add_bytes(vdst, vdst - fake_vstride, width2);
                             }
                         }
                     }
                 }
-                draw_slice(s, height);
+                draw_slice(s, p, height);
 
                 break;
             case MEDIAN:
                 /* first line except first 2 pixels is left predicted */
                 decode_422_bitstream(s, width - 2);
-                lefty= s->dsp.add_hfyu_left_prediction(p->data[0] + 2, s->temp[0], width - 2, lefty);
+                lefty = s->hdsp.add_hfyu_left_pred(p->data[0] + 2, s->temp[0], width - 2, lefty);
                 if (!(s->flags & CODEC_FLAG_GRAY)) {
-                    leftu = s->dsp.add_hfyu_left_prediction(p->data[1] + 1, s->temp[1], width2 - 1, leftu);
-                    leftv = s->dsp.add_hfyu_left_prediction(p->data[2] + 1, s->temp[2], width2 - 1, leftv);
+                    leftu = s->hdsp.add_hfyu_left_pred(p->data[1] + 1, s->temp[1], width2 - 1, leftu);
+                    leftv = s->hdsp.add_hfyu_left_pred(p->data[2] + 1, s->temp[2], width2 - 1, leftv);
                 }
 
                 cy = y = 1;
@@ -612,31 +606,31 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
                 /* second line is left predicted for interlaced case */
                 if (s->interlaced) {
                     decode_422_bitstream(s, width);
-                    lefty = s->dsp.add_hfyu_left_prediction(p->data[0] + p->linesize[0], s->temp[0], width, lefty);
+                    lefty = s->hdsp.add_hfyu_left_pred(p->data[0] + p->linesize[0], s->temp[0], width, lefty);
                     if (!(s->flags & CODEC_FLAG_GRAY)) {
-                        leftu = s->dsp.add_hfyu_left_prediction(p->data[1] + p->linesize[2], s->temp[1], width2, leftu);
-                        leftv = s->dsp.add_hfyu_left_prediction(p->data[2] + p->linesize[1], s->temp[2], width2, leftv);
+                        leftu = s->hdsp.add_hfyu_left_pred(p->data[1] + p->linesize[2], s->temp[1], width2, leftu);
+                        leftv = s->hdsp.add_hfyu_left_pred(p->data[2] + p->linesize[1], s->temp[2], width2, leftv);
                     }
                     y++; cy++;
                 }
 
                 /* next 4 pixels are left predicted too */
                 decode_422_bitstream(s, 4);
-                lefty = s->dsp.add_hfyu_left_prediction(p->data[0] + fake_ystride, s->temp[0], 4, lefty);
+                lefty = s->hdsp.add_hfyu_left_pred(p->data[0] + fake_ystride, s->temp[0], 4, lefty);
                 if (!(s->flags&CODEC_FLAG_GRAY)) {
-                    leftu = s->dsp.add_hfyu_left_prediction(p->data[1] + fake_ustride, s->temp[1], 2, leftu);
-                    leftv = s->dsp.add_hfyu_left_prediction(p->data[2] + fake_vstride, s->temp[2], 2, leftv);
+                    leftu = s->hdsp.add_hfyu_left_pred(p->data[1] + fake_ustride, s->temp[1], 2, leftu);
+                    leftv = s->hdsp.add_hfyu_left_pred(p->data[2] + fake_vstride, s->temp[2], 2, leftv);
                 }
 
                 /* next line except the first 4 pixels is median predicted */
                 lefttopy = p->data[0][3];
                 decode_422_bitstream(s, width - 4);
-                s->dsp.add_hfyu_median_prediction(p->data[0] + fake_ystride+4, p->data[0]+4, s->temp[0], width-4, &lefty, &lefttopy);
+                s->hdsp.add_hfyu_median_pred(p->data[0] + fake_ystride + 4, p->data[0] + 4, s->temp[0], width - 4, &lefty, &lefttopy);
                 if (!(s->flags&CODEC_FLAG_GRAY)) {
                     lefttopu = p->data[1][1];
                     lefttopv = p->data[2][1];
-                    s->dsp.add_hfyu_median_prediction(p->data[1] + fake_ustride+2, p->data[1] + 2, s->temp[1], width2 - 2, &leftu, &lefttopu);
-                    s->dsp.add_hfyu_median_prediction(p->data[2] + fake_vstride+2, p->data[2] + 2, s->temp[2], width2 - 2, &leftv, &lefttopv);
+                    s->hdsp.add_hfyu_median_pred(p->data[1] + fake_ustride + 2, p->data[1] + 2, s->temp[1], width2 - 2, &leftu, &lefttopu);
+                    s->hdsp.add_hfyu_median_pred(p->data[2] + fake_vstride + 2, p->data[2] + 2, s->temp[2], width2 - 2, &leftv, &lefttopv);
                 }
                 y++; cy++;
 
@@ -647,12 +641,12 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
                         while (2 * cy > y) {
                             decode_gray_bitstream(s, width);
                             ydst = p->data[0] + p->linesize[0] * y;
-                            s->dsp.add_hfyu_median_prediction(ydst, ydst - fake_ystride, s->temp[0], width, &lefty, &lefttopy);
+                            s->hdsp.add_hfyu_median_pred(ydst, ydst - fake_ystride, s->temp[0], width, &lefty, &lefttopy);
                             y++;
                         }
                         if (y >= height) break;
                     }
-                    draw_slice(s, y);
+                    draw_slice(s, p, y);
 
                     decode_422_bitstream(s, width);
 
@@ -660,14 +654,14 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
                     udst = p->data[1] + p->linesize[1] * cy;
                     vdst = p->data[2] + p->linesize[2] * cy;
 
-                    s->dsp.add_hfyu_median_prediction(ydst, ydst - fake_ystride, s->temp[0], width, &lefty, &lefttopy);
+                    s->hdsp.add_hfyu_median_pred(ydst, ydst - fake_ystride, s->temp[0], width, &lefty, &lefttopy);
                     if (!(s->flags & CODEC_FLAG_GRAY)) {
-                        s->dsp.add_hfyu_median_prediction(udst, udst - fake_ustride, s->temp[1], width2, &leftu, &lefttopu);
-                        s->dsp.add_hfyu_median_prediction(vdst, vdst - fake_vstride, s->temp[2], width2, &leftv, &lefttopv);
+                        s->hdsp.add_hfyu_median_pred(udst, udst - fake_ustride, s->temp[1], width2, &leftu, &lefttopu);
+                        s->hdsp.add_hfyu_median_pred(vdst, vdst - fake_vstride, s->temp[2], width2, &leftv, &lefttopv);
                     }
                 }
 
-                draw_slice(s, height);
+                draw_slice(s, p, height);
                 break;
             }
         }
@@ -694,24 +688,24 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
             case LEFT:
             case PLANE:
                 decode_bgr_bitstream(s, width - 1);
-                s->dsp.add_hfyu_left_prediction_bgr32(p->data[0] + last_line+4, s->temp[0], width - 1, &leftr, &leftg, &leftb, &lefta);
+                s->hdsp.add_hfyu_left_pred_bgr32(p->data[0] + last_line + 4, s->temp[0], width - 1, &leftr, &leftg, &leftb, &lefta);
 
                 for (y = s->height - 2; y >= 0; y--) { //Yes it is stored upside down.
                     decode_bgr_bitstream(s, width);
 
-                    s->dsp.add_hfyu_left_prediction_bgr32(p->data[0] + p->linesize[0]*y, s->temp[0], width, &leftr, &leftg, &leftb, &lefta);
+                    s->hdsp.add_hfyu_left_pred_bgr32(p->data[0] + p->linesize[0] * y, s->temp[0], width, &leftr, &leftg, &leftb, &lefta);
                     if (s->predictor == PLANE) {
                         if (s->bitstream_bpp != 32) lefta = 0;
                         if ((y & s->interlaced) == 0 &&
                             y < s->height - 1 - s->interlaced) {
-                            s->dsp.add_bytes(p->data[0] + p->linesize[0] * y,
-                                             p->data[0] + p->linesize[0] * y +
-                                             fake_ystride, fake_ystride);
+                            s->hdsp.add_bytes(p->data[0] + p->linesize[0] * y,
+                                              p->data[0] + p->linesize[0] * y +
+                                              fake_ystride, fake_ystride);
                         }
                     }
                 }
                 // just 1 large slice as this is not possible in reverse order
-                draw_slice(s, height);
+                draw_slice(s, p, height);
                 break;
             default:
                 av_log(avctx, AV_LOG_ERROR,
@@ -725,7 +719,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     }
     emms_c();
 
-    *picture = *p;
     *got_frame = 1;
 
     return (get_bits_count(&s->gb) + 31) / 32 * 4 + table_size;
@@ -736,9 +729,6 @@ static av_cold int decode_end(AVCodecContext *avctx)
     HYuvContext *s = avctx->priv_data;
     int i;
 
-    if (s->picture.data[0])
-        avctx->release_buffer(avctx, &s->picture);
-
     ff_huffyuv_common_end(s);
     av_freep(&s->bitstream_buffer);
 
@@ -749,9 +739,9 @@ static av_cold int decode_end(AVCodecContext *avctx)
     return 0;
 }
 
-#if CONFIG_HUFFYUV_DECODER
 AVCodec ff_huffyuv_decoder = {
     .name             = "huffyuv",
+    .long_name        = NULL_IF_CONFIG_SMALL("Huffyuv / HuffYUV"),
     .type             = AVMEDIA_TYPE_VIDEO,
     .id               = AV_CODEC_ID_HUFFYUV,
     .priv_data_size   = sizeof(HYuvContext),
@@ -761,13 +751,12 @@ AVCodec ff_huffyuv_decoder = {
     .capabilities     = CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND |
                         CODEC_CAP_FRAME_THREADS,
     .init_thread_copy = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy),
-    .long_name        = NULL_IF_CONFIG_SMALL("Huffyuv / HuffYUV"),
 };
-#endif
 
 #if CONFIG_FFVHUFF_DECODER
 AVCodec ff_ffvhuff_decoder = {
     .name             = "ffvhuff",
+    .long_name        = NULL_IF_CONFIG_SMALL("Huffyuv FFmpeg variant"),
     .type             = AVMEDIA_TYPE_VIDEO,
     .id               = AV_CODEC_ID_FFVHUFF,
     .priv_data_size   = sizeof(HYuvContext),
@@ -777,6 +766,5 @@ AVCodec ff_ffvhuff_decoder = {
     .capabilities     = CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND |
                         CODEC_CAP_FRAME_THREADS,
     .init_thread_copy = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy),
-    .long_name        = NULL_IF_CONFIG_SMALL("Huffyuv FFmpeg variant"),
 };
 #endif