media/libvpx/vp8/encoder/mr_dissim.c

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /*
michael@0 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license
michael@0 5 * that can be found in the LICENSE file in the root of the source
michael@0 6 * tree. An additional intellectual property rights grant can be found
michael@0 7 * in the file PATENTS. All contributing project authors may
michael@0 8 * be found in the AUTHORS file in the root of the source tree.
michael@0 9 */
michael@0 10
michael@0 11
michael@0 12 #include <limits.h>
michael@0 13 #include "vpx_config.h"
michael@0 14 #include "onyx_int.h"
michael@0 15 #include "mr_dissim.h"
michael@0 16 #include "vpx_mem/vpx_mem.h"
michael@0 17 #include "rdopt.h"
michael@0 18
michael@0 19 void vp8_cal_low_res_mb_cols(VP8_COMP *cpi)
michael@0 20 {
michael@0 21 int low_res_w;
michael@0 22
michael@0 23 /* Support arbitrary down-sampling factor */
michael@0 24 unsigned int iw = cpi->oxcf.Width*cpi->oxcf.mr_down_sampling_factor.den
michael@0 25 + cpi->oxcf.mr_down_sampling_factor.num - 1;
michael@0 26
michael@0 27 low_res_w = iw/cpi->oxcf.mr_down_sampling_factor.num;
michael@0 28 cpi->mr_low_res_mb_cols = ((low_res_w + 15) >> 4);
michael@0 29 }
michael@0 30
michael@0 31 #define GET_MV(x) \
michael@0 32 if(x->mbmi.ref_frame !=INTRA_FRAME) \
michael@0 33 { \
michael@0 34 mvx[cnt] = x->mbmi.mv.as_mv.row; \
michael@0 35 mvy[cnt] = x->mbmi.mv.as_mv.col; \
michael@0 36 cnt++; \
michael@0 37 }
michael@0 38
michael@0 39 #define GET_MV_SIGN(x) \
michael@0 40 if(x->mbmi.ref_frame !=INTRA_FRAME) \
michael@0 41 { \
michael@0 42 mvx[cnt] = x->mbmi.mv.as_mv.row; \
michael@0 43 mvy[cnt] = x->mbmi.mv.as_mv.col; \
michael@0 44 if (cm->ref_frame_sign_bias[x->mbmi.ref_frame] \
michael@0 45 != cm->ref_frame_sign_bias[tmp->mbmi.ref_frame]) \
michael@0 46 { \
michael@0 47 mvx[cnt] *= -1; \
michael@0 48 mvy[cnt] *= -1; \
michael@0 49 } \
michael@0 50 cnt++; \
michael@0 51 }
michael@0 52
michael@0 53 void vp8_cal_dissimilarity(VP8_COMP *cpi)
michael@0 54 {
michael@0 55 VP8_COMMON *cm = &cpi->common;
michael@0 56 int i;
michael@0 57
michael@0 58 /* Note: The first row & first column in mip are outside the frame, which
michael@0 59 * were initialized to all 0.(ref_frame, mode, mv...)
michael@0 60 * Their ref_frame = 0 means they won't be counted in the following
michael@0 61 * calculation.
michael@0 62 */
michael@0 63 if (cpi->oxcf.mr_total_resolutions >1
michael@0 64 && cpi->oxcf.mr_encoder_id < (cpi->oxcf.mr_total_resolutions - 1))
michael@0 65 {
michael@0 66 /* Store info for show/no-show frames for supporting alt_ref.
michael@0 67 * If parent frame is alt_ref, child has one too.
michael@0 68 */
michael@0 69 LOWER_RES_FRAME_INFO* store_info
michael@0 70 = (LOWER_RES_FRAME_INFO*)cpi->oxcf.mr_low_res_mode_info;
michael@0 71
michael@0 72 store_info->frame_type = cm->frame_type;
michael@0 73
michael@0 74 if(cm->frame_type != KEY_FRAME)
michael@0 75 {
michael@0 76 store_info->is_frame_dropped = 0;
michael@0 77 for (i = 1; i < MAX_REF_FRAMES; i++)
michael@0 78 store_info->low_res_ref_frames[i] = cpi->current_ref_frames[i];
michael@0 79 }
michael@0 80
michael@0 81 if(cm->frame_type != KEY_FRAME)
michael@0 82 {
michael@0 83 int mb_row;
michael@0 84 int mb_col;
michael@0 85 /* Point to beginning of allocated MODE_INFO arrays. */
michael@0 86 MODE_INFO *tmp = cm->mip + cm->mode_info_stride;
michael@0 87 LOWER_RES_MB_INFO* store_mode_info = store_info->mb_info;
michael@0 88
michael@0 89 for (mb_row = 0; mb_row < cm->mb_rows; mb_row ++)
michael@0 90 {
michael@0 91 tmp++;
michael@0 92 for (mb_col = 0; mb_col < cm->mb_cols; mb_col ++)
michael@0 93 {
michael@0 94 int dissim = INT_MAX;
michael@0 95
michael@0 96 if(tmp->mbmi.ref_frame !=INTRA_FRAME)
michael@0 97 {
michael@0 98 int mvx[8];
michael@0 99 int mvy[8];
michael@0 100 int mmvx;
michael@0 101 int mmvy;
michael@0 102 int cnt=0;
michael@0 103 const MODE_INFO *here = tmp;
michael@0 104 const MODE_INFO *above = here - cm->mode_info_stride;
michael@0 105 const MODE_INFO *left = here - 1;
michael@0 106 const MODE_INFO *aboveleft = above - 1;
michael@0 107 const MODE_INFO *aboveright = NULL;
michael@0 108 const MODE_INFO *right = NULL;
michael@0 109 const MODE_INFO *belowleft = NULL;
michael@0 110 const MODE_INFO *below = NULL;
michael@0 111 const MODE_INFO *belowright = NULL;
michael@0 112
michael@0 113 /* If alternate reference frame is used, we have to
michael@0 114 * check sign of MV. */
michael@0 115 if(cpi->oxcf.play_alternate)
michael@0 116 {
michael@0 117 /* Gather mv of neighboring MBs */
michael@0 118 GET_MV_SIGN(above)
michael@0 119 GET_MV_SIGN(left)
michael@0 120 GET_MV_SIGN(aboveleft)
michael@0 121
michael@0 122 if(mb_col < (cm->mb_cols-1))
michael@0 123 {
michael@0 124 right = here + 1;
michael@0 125 aboveright = above + 1;
michael@0 126 GET_MV_SIGN(right)
michael@0 127 GET_MV_SIGN(aboveright)
michael@0 128 }
michael@0 129
michael@0 130 if(mb_row < (cm->mb_rows-1))
michael@0 131 {
michael@0 132 below = here + cm->mode_info_stride;
michael@0 133 belowleft = below - 1;
michael@0 134 GET_MV_SIGN(below)
michael@0 135 GET_MV_SIGN(belowleft)
michael@0 136 }
michael@0 137
michael@0 138 if(mb_col < (cm->mb_cols-1)
michael@0 139 && mb_row < (cm->mb_rows-1))
michael@0 140 {
michael@0 141 belowright = below + 1;
michael@0 142 GET_MV_SIGN(belowright)
michael@0 143 }
michael@0 144 }else
michael@0 145 {
michael@0 146 /* No alt_ref and gather mv of neighboring MBs */
michael@0 147 GET_MV(above)
michael@0 148 GET_MV(left)
michael@0 149 GET_MV(aboveleft)
michael@0 150
michael@0 151 if(mb_col < (cm->mb_cols-1))
michael@0 152 {
michael@0 153 right = here + 1;
michael@0 154 aboveright = above + 1;
michael@0 155 GET_MV(right)
michael@0 156 GET_MV(aboveright)
michael@0 157 }
michael@0 158
michael@0 159 if(mb_row < (cm->mb_rows-1))
michael@0 160 {
michael@0 161 below = here + cm->mode_info_stride;
michael@0 162 belowleft = below - 1;
michael@0 163 GET_MV(below)
michael@0 164 GET_MV(belowleft)
michael@0 165 }
michael@0 166
michael@0 167 if(mb_col < (cm->mb_cols-1)
michael@0 168 && mb_row < (cm->mb_rows-1))
michael@0 169 {
michael@0 170 belowright = below + 1;
michael@0 171 GET_MV(belowright)
michael@0 172 }
michael@0 173 }
michael@0 174
michael@0 175 if (cnt > 0)
michael@0 176 {
michael@0 177 int max_mvx = mvx[0];
michael@0 178 int min_mvx = mvx[0];
michael@0 179 int max_mvy = mvy[0];
michael@0 180 int min_mvy = mvy[0];
michael@0 181 int i;
michael@0 182
michael@0 183 if (cnt > 1)
michael@0 184 {
michael@0 185 for (i=1; i< cnt; i++)
michael@0 186 {
michael@0 187 if (mvx[i] > max_mvx) max_mvx = mvx[i];
michael@0 188 else if (mvx[i] < min_mvx) min_mvx = mvx[i];
michael@0 189 if (mvy[i] > max_mvy) max_mvy = mvy[i];
michael@0 190 else if (mvy[i] < min_mvy) min_mvy = mvy[i];
michael@0 191 }
michael@0 192 }
michael@0 193
michael@0 194 mmvx = MAX(abs(min_mvx - here->mbmi.mv.as_mv.row),
michael@0 195 abs(max_mvx - here->mbmi.mv.as_mv.row));
michael@0 196 mmvy = MAX(abs(min_mvy - here->mbmi.mv.as_mv.col),
michael@0 197 abs(max_mvy - here->mbmi.mv.as_mv.col));
michael@0 198 dissim = MAX(mmvx, mmvy);
michael@0 199 }
michael@0 200 }
michael@0 201
michael@0 202 /* Store mode info for next resolution encoding */
michael@0 203 store_mode_info->mode = tmp->mbmi.mode;
michael@0 204 store_mode_info->ref_frame = tmp->mbmi.ref_frame;
michael@0 205 store_mode_info->mv.as_int = tmp->mbmi.mv.as_int;
michael@0 206 store_mode_info->dissim = dissim;
michael@0 207 tmp++;
michael@0 208 store_mode_info++;
michael@0 209 }
michael@0 210 }
michael@0 211 }
michael@0 212 }
michael@0 213 }
michael@0 214
michael@0 215 /* This function is called only when this frame is dropped at current
michael@0 216 resolution level. */
michael@0 217 void vp8_store_drop_frame_info(VP8_COMP *cpi)
michael@0 218 {
michael@0 219 /* If the frame is dropped in lower-resolution encoding, this information
michael@0 220 is passed to higher resolution level so that the encoder knows there
michael@0 221 is no mode & motion info available.
michael@0 222 */
michael@0 223 if (cpi->oxcf.mr_total_resolutions >1
michael@0 224 && cpi->oxcf.mr_encoder_id < (cpi->oxcf.mr_total_resolutions - 1))
michael@0 225 {
michael@0 226 /* Store info for show/no-show frames for supporting alt_ref.
michael@0 227 * If parent frame is alt_ref, child has one too.
michael@0 228 */
michael@0 229 LOWER_RES_FRAME_INFO* store_info
michael@0 230 = (LOWER_RES_FRAME_INFO*)cpi->oxcf.mr_low_res_mode_info;
michael@0 231
michael@0 232 /* Set frame_type to be INTER_FRAME since we won't drop key frame. */
michael@0 233 store_info->frame_type = INTER_FRAME;
michael@0 234 store_info->is_frame_dropped = 1;
michael@0 235 }
michael@0 236 }

mercurial