summaryrefslogtreecommitdiff
path: root/libavcodec/motion_est.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-08-07 09:02:51 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-08-09 19:17:22 +0200
commitbc109a53c722f7b1ce9c3bede906717b4e271496 (patch)
tree924b0542a2dc891aee3cf92086a415fedc462c16 /libavcodec/motion_est.c
parent109515e16dfffa6bb34de75c5253b7cbb1f12fa6 (diff)
avcodec/mpegpicture: Move mb_var, mc_mb_var and mb_mean to MpegEncCtx
These tables are only used by encoders and only for the current picture; ergo they need not be put into the picture at all, but rather into the encoder's context. They also don't need to be refcounted, because there is only one owner. In contrast to this, the earlier code refcounts them which incurs unnecessary overhead. These references are not unreferenced in ff_mpeg_unref_picture() (they are kept in order to have something like a buffer pool), so that several buffers are kept at the same time, although only one is needed, thereby wasting memory. The code also propagates references to other pictures not part of the pictures array (namely the copy of the current/next/last picture in the MpegEncContext which get references of their own). These references are not unreferenced in ff_mpeg_unref_picture() (the buffers are probably kept in order to have something like a pool), yet if the current picture is a B-frame, it gets unreferenced at the end of ff_mpv_encode_picture() and its slot in the picture array will therefore be reused the next time; but the copy of the current picture also still has its references and therefore these buffers will be made duplicated in order to make them writable in the next call to ff_mpv_encode_picture(). This is of course unnecessary. Finally, ff_find_unused_picture() is supposed to just return any unused picture and the code is supposed to work with it; yet for the vsynth*-mpeg4-adap tests the result depends upon the content of these buffers; given that this patchset changes the content of these buffers (the initial content is now the state of these buffers after encoding the last frame; before this patch the buffers used came from the last picture that occupied the same slot in the picture array) their ref-files needed to be changed. This points to a bug somewhere (if one removes the initialization, one gets uninitialized reads in adaptive_quantization in ratecontrol.c). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec/motion_est.c')
-rw-r--r--libavcodec/motion_est.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c
index 29ab41dc8c..d17ffe42b4 100644
--- a/libavcodec/motion_est.c
+++ b/libavcodec/motion_est.c
@@ -895,7 +895,6 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
int P[10][2];
const int shift= 1+s->quarter_sample;
int mb_type=0;
- Picture * const pic= &s->current_picture;
init_ref(c, s->new_picture->data, s->last_picture.f->data, NULL, 16*mb_x, 16*mb_y, 0);
@@ -917,8 +916,8 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
varc = s->mpvencdsp.pix_norm1(pix, s->linesize) -
(((unsigned) sum * sum) >> 8) + 500;
- pic->mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8;
- pic->mb_var [s->mb_stride * mb_y + mb_x] = (varc+128)>>8;
+ s->mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8;
+ s->mb_var [s->mb_stride * mb_y + mb_x] = (varc+128)>>8;
c->mb_var_sum_temp += (varc+128)>>8;
if (s->motion_est != FF_ME_ZERO) {
@@ -965,7 +964,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
vard = s->mecc.sse[0](NULL, pix, ppix, s->linesize, 16);
- pic->mc_mb_var[s->mb_stride * mb_y + mb_x] = (vard+128)>>8;
+ s->mc_mb_var[s->mb_stride * mb_y + mb_x] = (vard+128)>>8;
c->mc_mb_var_sum_temp += (vard+128)>>8;
if (c->avctx->mb_decision > FF_MB_DECISION_SIMPLE) {
@@ -1509,7 +1508,7 @@ void ff_estimate_b_frame_motion(MpegEncContext * s,
score= ((unsigned)(score*score + 128*256))>>16;
c->mc_mb_var_sum_temp += score;
- s->current_picture.mc_mb_var[mb_y*s->mb_stride + mb_x] = score; //FIXME use SSE
+ s->mc_mb_var[mb_y*s->mb_stride + mb_x] = score; //FIXME use SSE
s->mb_type[mb_y*s->mb_stride + mb_x]= CANDIDATE_MB_TYPE_DIRECT0;
return;
@@ -1574,7 +1573,7 @@ void ff_estimate_b_frame_motion(MpegEncContext * s,
score= ((unsigned)(score*score + 128*256))>>16;
c->mc_mb_var_sum_temp += score;
- s->current_picture.mc_mb_var[mb_y*s->mb_stride + mb_x] = score; //FIXME use SSE
+ s->mc_mb_var[mb_y*s->mb_stride + mb_x] = score; //FIXME use SSE
}
if(c->avctx->mb_decision > FF_MB_DECISION_SIMPLE){
@@ -1629,7 +1628,8 @@ int ff_get_best_fcode(MpegEncContext * s, const int16_t (*mv_table)[2], int type
continue;
for(j=0; j<fcode && j<8; j++){
- if(s->pict_type==AV_PICTURE_TYPE_B || s->current_picture.mc_mb_var[xy] < s->current_picture.mb_var[xy])
+ if (s->pict_type == AV_PICTURE_TYPE_B ||
+ s->mc_mb_var[xy] < s->mb_var[xy])
score[j]-= 170;
}
}