]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/mpegvideo_enc.c
Merge commit '3c650efb81aaa3b395ba4606ee68a47ee4efb57b'
[ffmpeg] / libavcodec / mpegvideo_enc.c
index ffd91a7ab897eef023ef8d1c3e32bbec65f3016e..d39f88eddef6ba3d675bcc78a33a36bc79a1455a 100644 (file)
@@ -818,6 +818,7 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx)
     if (ff_MPV_common_init(s) < 0)
         return -1;
 
+    ff_mpegvideoencdsp_init(&s->mpvencdsp, avctx);
     ff_qpeldsp_init(&s->qdsp);
 
     s->avctx->coded_frame = s->current_picture.f;
@@ -1009,7 +1010,7 @@ static int get_intra_count(MpegEncContext *s, uint8_t *src,
             int offset = x + y * stride;
             int sad  = s->dsp.sad[0](NULL, src + offset, ref + offset, stride,
                                      16);
-            int mean = (s->dsp.pix_sum(src + offset, stride) + 128) >> 8;
+            int mean = (s->mpvencdsp.pix_sum(src + offset, stride) + 128) >> 8;
             int sae  = get_sae(src + offset, mean, stride);
 
             acc += sae + 500 < sad;
@@ -1144,11 +1145,11 @@ static int load_input_picture(MpegEncContext *s, const AVFrame *pic_arg)
                         }
                     }
                     if ((s->width & 15) || (s->height & (vpad-1))) {
-                        s->dsp.draw_edges(dst, dst_stride,
-                                          w, h,
-                                          16>>h_shift,
-                                          vpad>>v_shift,
-                                          EDGE_BOTTOM);
+                        s->mpvencdsp.draw_edges(dst, dst_stride,
+                                                w, h,
+                                                16>>h_shift,
+                                                vpad>>v_shift,
+                                                EDGE_BOTTOM);
                     }
                 }
             }
@@ -1265,25 +1266,33 @@ static int estimate_best_b_count(MpegEncContext *s)
     for (i = 0; i < s->max_b_frames + 2; i++) {
         Picture pre_input, *pre_input_ptr = i ? s->input_picture[i - 1] :
                                                 s->next_picture_ptr;
+        uint8_t *data[4];
 
         if (pre_input_ptr && (!i || s->input_picture[i - 1])) {
             pre_input = *pre_input_ptr;
+            memcpy(data, pre_input_ptr->f->data, sizeof(data));
 
             if (!pre_input.shared && i) {
-                pre_input.f->data[0] += INPLACE_OFFSET;
-                pre_input.f->data[1] += INPLACE_OFFSET;
-                pre_input.f->data[2] += INPLACE_OFFSET;
+                data[0] += INPLACE_OFFSET;
+                data[1] += INPLACE_OFFSET;
+                data[2] += INPLACE_OFFSET;
             }
 
-            s->dsp.shrink[scale](s->tmp_frames[i]->data[0], s->tmp_frames[i]->linesize[0],
-                                 pre_input.f->data[0], pre_input.f->linesize[0],
-                                 c->width,      c->height);
-            s->dsp.shrink[scale](s->tmp_frames[i]->data[1], s->tmp_frames[i]->linesize[1],
-                                 pre_input.f->data[1], pre_input.f->linesize[1],
-                                 c->width >> 1, c->height >> 1);
-            s->dsp.shrink[scale](s->tmp_frames[i]->data[2], s->tmp_frames[i]->linesize[2],
-                                 pre_input.f->data[2], pre_input.f->linesize[2],
-                                 c->width >> 1, c->height >> 1);
+            s->mpvencdsp.shrink[scale](s->tmp_frames[i]->data[0],
+                                       s->tmp_frames[i]->linesize[0],
+                                       data[0],
+                                       pre_input.f->linesize[0],
+                                       c->width, c->height);
+            s->mpvencdsp.shrink[scale](s->tmp_frames[i]->data[1],
+                                       s->tmp_frames[i]->linesize[1],
+                                       data[1],
+                                       pre_input.f->linesize[1],
+                                       c->width >> 1, c->height >> 1);
+            s->mpvencdsp.shrink[scale](s->tmp_frames[i]->data[2],
+                                       s->tmp_frames[i]->linesize[2],
+                                       data[2],
+                                       pre_input.f->linesize[2],
+                                       c->width >> 1, c->height >> 1);
         }
     }
 
@@ -1520,18 +1529,25 @@ static void frame_end(MpegEncContext *s)
         const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->avctx->pix_fmt);
         int hshift = desc->log2_chroma_w;
         int vshift = desc->log2_chroma_h;
-        s->dsp.draw_edges(s->current_picture.f->data[0], s->current_picture.f->linesize[0],
-                          s->h_edge_pos, s->v_edge_pos,
-                          EDGE_WIDTH, EDGE_WIDTH,
-                          EDGE_TOP | EDGE_BOTTOM);
-        s->dsp.draw_edges(s->current_picture.f->data[1], s->current_picture.f->linesize[1],
-                          s->h_edge_pos >> hshift, s->v_edge_pos >> vshift,
-                          EDGE_WIDTH >> hshift, EDGE_WIDTH >> vshift,
-                          EDGE_TOP | EDGE_BOTTOM);
-        s->dsp.draw_edges(s->current_picture.f->data[2], s->current_picture.f->linesize[2],
-                          s->h_edge_pos >> hshift, s->v_edge_pos >> vshift,
-                          EDGE_WIDTH >> hshift, EDGE_WIDTH >> vshift,
-                          EDGE_TOP | EDGE_BOTTOM);
+        s->mpvencdsp.draw_edges(s->current_picture.f->data[0],
+                                s->current_picture.f->linesize[0],
+                                s->h_edge_pos, s->v_edge_pos,
+                                EDGE_WIDTH, EDGE_WIDTH,
+                                EDGE_TOP | EDGE_BOTTOM);
+        s->mpvencdsp.draw_edges(s->current_picture.f->data[1],
+                                s->current_picture.f->linesize[1],
+                                s->h_edge_pos >> hshift,
+                                s->v_edge_pos >> vshift,
+                                EDGE_WIDTH >> hshift,
+                                EDGE_WIDTH >> vshift,
+                                EDGE_TOP | EDGE_BOTTOM);
+        s->mpvencdsp.draw_edges(s->current_picture.f->data[2],
+                                s->current_picture.f->linesize[2],
+                                s->h_edge_pos >> hshift,
+                                s->v_edge_pos >> vshift,
+                                EDGE_WIDTH >> hshift,
+                                EDGE_WIDTH >> vshift,
+                                EDGE_TOP | EDGE_BOTTOM);
     }
 
     emms_c();
@@ -2582,9 +2598,10 @@ static int mb_var_thread(AVCodecContext *c, void *arg){
             int yy = mb_y * 16;
             uint8_t *pix = s->new_picture.f->data[0] + (yy * s->linesize) + xx;
             int varc;
-            int sum = s->dsp.pix_sum(pix, s->linesize);
+            int sum = s->mpvencdsp.pix_sum(pix, s->linesize);
 
-            varc = (s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)sum*sum)>>8) + 500 + 128)>>8;
+            varc = (s->mpvencdsp.pix_norm1(pix, s->linesize) -
+                    (((unsigned) sum * sum) >> 8) + 500 + 128) >> 8;
 
             s->current_picture.mb_var [s->mb_stride * mb_y + mb_x] = varc;
             s->current_picture.mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8;
@@ -4088,7 +4105,7 @@ STOP_TIMER("memset rem[]")}
             run_tab[rle_index++]=run;
             run=0;
 
-            s->dsp.add_8x8basis(rem, basis[j], coeff);
+            s->mpvencdsp.add_8x8basis(rem, basis[j], coeff);
         }else{
             run++;
         }
@@ -4102,7 +4119,7 @@ STOP_TIMER("init rem[]")
 {START_TIMER
 #endif
     for(;;){
-        int best_score=s->dsp.try_8x8basis(rem, weight, basis[0], 0);
+        int best_score = s->mpvencdsp.try_8x8basis(rem, weight, basis[0], 0);
         int best_coeff=0;
         int best_change=0;
         int run2, best_unquant_change=0, analyze_gradient;
@@ -4146,7 +4163,8 @@ STOP_TIMER("dct")}
                 if(new_coeff >= 2048 || new_coeff < 0)
                     continue;
 
-                score= s->dsp.try_8x8basis(rem, weight, basis[0], new_coeff - old_coeff);
+                score = s->mpvencdsp.try_8x8basis(rem, weight, basis[0],
+                                                  new_coeff - old_coeff);
                 if(score<best_score){
                     best_score= score;
                     best_coeff= 0;
@@ -4269,7 +4287,8 @@ STOP_TIMER("dct")}
                 unquant_change= new_coeff - old_coeff;
                 av_assert2((score < 100*lambda && score > -100*lambda) || lambda==0);
 
-                score+= s->dsp.try_8x8basis(rem, weight, basis[j], unquant_change);
+                score += s->mpvencdsp.try_8x8basis(rem, weight, basis[j],
+                                                   unquant_change);
                 if(score<best_score){
                     best_score= score;
                     best_coeff= i;
@@ -4343,7 +4362,7 @@ if(256*256*256*64 % count == 0){
                  }
             }
 
-            s->dsp.add_8x8basis(rem, basis[j], best_unquant_change);
+            s->mpvencdsp.add_8x8basis(rem, basis[j], best_unquant_change);
         }else{
             break;
         }