media/libvpx/vp8/common/findnearmv.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 "findnearmv.h"
michael@0 13
michael@0 14 const unsigned char vp8_mbsplit_offset[4][16] = {
michael@0 15 { 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
michael@0 16 { 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
michael@0 17 { 0, 2, 8, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
michael@0 18 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
michael@0 19 };
michael@0 20
michael@0 21 /* Predict motion vectors using those from already-decoded nearby blocks.
michael@0 22 Note that we only consider one 4x4 subblock from each candidate 16x16
michael@0 23 macroblock. */
michael@0 24 void vp8_find_near_mvs
michael@0 25 (
michael@0 26 MACROBLOCKD *xd,
michael@0 27 const MODE_INFO *here,
michael@0 28 int_mv *nearest,
michael@0 29 int_mv *nearby,
michael@0 30 int_mv *best_mv,
michael@0 31 int cnt[4],
michael@0 32 int refframe,
michael@0 33 int *ref_frame_sign_bias
michael@0 34 )
michael@0 35 {
michael@0 36 const MODE_INFO *above = here - xd->mode_info_stride;
michael@0 37 const MODE_INFO *left = here - 1;
michael@0 38 const MODE_INFO *aboveleft = above - 1;
michael@0 39 int_mv near_mvs[4];
michael@0 40 int_mv *mv = near_mvs;
michael@0 41 int *cntx = cnt;
michael@0 42 enum {CNT_INTRA, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV};
michael@0 43
michael@0 44 /* Zero accumulators */
michael@0 45 mv[0].as_int = mv[1].as_int = mv[2].as_int = 0;
michael@0 46 cnt[0] = cnt[1] = cnt[2] = cnt[3] = 0;
michael@0 47
michael@0 48 /* Process above */
michael@0 49 if (above->mbmi.ref_frame != INTRA_FRAME)
michael@0 50 {
michael@0 51 if (above->mbmi.mv.as_int)
michael@0 52 {
michael@0 53 (++mv)->as_int = above->mbmi.mv.as_int;
michael@0 54 mv_bias(ref_frame_sign_bias[above->mbmi.ref_frame], refframe, mv, ref_frame_sign_bias);
michael@0 55 ++cntx;
michael@0 56 }
michael@0 57
michael@0 58 *cntx += 2;
michael@0 59 }
michael@0 60
michael@0 61 /* Process left */
michael@0 62 if (left->mbmi.ref_frame != INTRA_FRAME)
michael@0 63 {
michael@0 64 if (left->mbmi.mv.as_int)
michael@0 65 {
michael@0 66 int_mv this_mv;
michael@0 67
michael@0 68 this_mv.as_int = left->mbmi.mv.as_int;
michael@0 69 mv_bias(ref_frame_sign_bias[left->mbmi.ref_frame], refframe, &this_mv, ref_frame_sign_bias);
michael@0 70
michael@0 71 if (this_mv.as_int != mv->as_int)
michael@0 72 {
michael@0 73 (++mv)->as_int = this_mv.as_int;
michael@0 74 ++cntx;
michael@0 75 }
michael@0 76
michael@0 77 *cntx += 2;
michael@0 78 }
michael@0 79 else
michael@0 80 cnt[CNT_INTRA] += 2;
michael@0 81 }
michael@0 82
michael@0 83 /* Process above left */
michael@0 84 if (aboveleft->mbmi.ref_frame != INTRA_FRAME)
michael@0 85 {
michael@0 86 if (aboveleft->mbmi.mv.as_int)
michael@0 87 {
michael@0 88 int_mv this_mv;
michael@0 89
michael@0 90 this_mv.as_int = aboveleft->mbmi.mv.as_int;
michael@0 91 mv_bias(ref_frame_sign_bias[aboveleft->mbmi.ref_frame], refframe, &this_mv, ref_frame_sign_bias);
michael@0 92
michael@0 93 if (this_mv.as_int != mv->as_int)
michael@0 94 {
michael@0 95 (++mv)->as_int = this_mv.as_int;
michael@0 96 ++cntx;
michael@0 97 }
michael@0 98
michael@0 99 *cntx += 1;
michael@0 100 }
michael@0 101 else
michael@0 102 cnt[CNT_INTRA] += 1;
michael@0 103 }
michael@0 104
michael@0 105 /* If we have three distinct MV's ... */
michael@0 106 if (cnt[CNT_SPLITMV])
michael@0 107 {
michael@0 108 /* See if above-left MV can be merged with NEAREST */
michael@0 109 if (mv->as_int == near_mvs[CNT_NEAREST].as_int)
michael@0 110 cnt[CNT_NEAREST] += 1;
michael@0 111 }
michael@0 112
michael@0 113 cnt[CNT_SPLITMV] = ((above->mbmi.mode == SPLITMV)
michael@0 114 + (left->mbmi.mode == SPLITMV)) * 2
michael@0 115 + (aboveleft->mbmi.mode == SPLITMV);
michael@0 116
michael@0 117 /* Swap near and nearest if necessary */
michael@0 118 if (cnt[CNT_NEAR] > cnt[CNT_NEAREST])
michael@0 119 {
michael@0 120 int tmp;
michael@0 121 tmp = cnt[CNT_NEAREST];
michael@0 122 cnt[CNT_NEAREST] = cnt[CNT_NEAR];
michael@0 123 cnt[CNT_NEAR] = tmp;
michael@0 124 tmp = near_mvs[CNT_NEAREST].as_int;
michael@0 125 near_mvs[CNT_NEAREST].as_int = near_mvs[CNT_NEAR].as_int;
michael@0 126 near_mvs[CNT_NEAR].as_int = tmp;
michael@0 127 }
michael@0 128
michael@0 129 /* Use near_mvs[0] to store the "best" MV */
michael@0 130 if (cnt[CNT_NEAREST] >= cnt[CNT_INTRA])
michael@0 131 near_mvs[CNT_INTRA] = near_mvs[CNT_NEAREST];
michael@0 132
michael@0 133 /* Set up return values */
michael@0 134 best_mv->as_int = near_mvs[0].as_int;
michael@0 135 nearest->as_int = near_mvs[CNT_NEAREST].as_int;
michael@0 136 nearby->as_int = near_mvs[CNT_NEAR].as_int;
michael@0 137 }
michael@0 138
michael@0 139
michael@0 140 static void invert_and_clamp_mvs(int_mv *inv, int_mv *src, MACROBLOCKD *xd)
michael@0 141 {
michael@0 142 inv->as_mv.row = src->as_mv.row * -1;
michael@0 143 inv->as_mv.col = src->as_mv.col * -1;
michael@0 144 vp8_clamp_mv2(inv, xd);
michael@0 145 vp8_clamp_mv2(src, xd);
michael@0 146 }
michael@0 147
michael@0 148
michael@0 149 int vp8_find_near_mvs_bias
michael@0 150 (
michael@0 151 MACROBLOCKD *xd,
michael@0 152 const MODE_INFO *here,
michael@0 153 int_mv mode_mv_sb[2][MB_MODE_COUNT],
michael@0 154 int_mv best_mv_sb[2],
michael@0 155 int cnt[4],
michael@0 156 int refframe,
michael@0 157 int *ref_frame_sign_bias
michael@0 158 )
michael@0 159 {
michael@0 160 int sign_bias = ref_frame_sign_bias[refframe];
michael@0 161
michael@0 162 vp8_find_near_mvs(xd,
michael@0 163 here,
michael@0 164 &mode_mv_sb[sign_bias][NEARESTMV],
michael@0 165 &mode_mv_sb[sign_bias][NEARMV],
michael@0 166 &best_mv_sb[sign_bias],
michael@0 167 cnt,
michael@0 168 refframe,
michael@0 169 ref_frame_sign_bias);
michael@0 170
michael@0 171 invert_and_clamp_mvs(&mode_mv_sb[!sign_bias][NEARESTMV],
michael@0 172 &mode_mv_sb[sign_bias][NEARESTMV], xd);
michael@0 173 invert_and_clamp_mvs(&mode_mv_sb[!sign_bias][NEARMV],
michael@0 174 &mode_mv_sb[sign_bias][NEARMV], xd);
michael@0 175 invert_and_clamp_mvs(&best_mv_sb[!sign_bias],
michael@0 176 &best_mv_sb[sign_bias], xd);
michael@0 177
michael@0 178 return sign_bias;
michael@0 179 }
michael@0 180
michael@0 181
michael@0 182 vp8_prob *vp8_mv_ref_probs(
michael@0 183 vp8_prob p[VP8_MVREFS-1], const int near_mv_ref_ct[4]
michael@0 184 )
michael@0 185 {
michael@0 186 p[0] = vp8_mode_contexts [near_mv_ref_ct[0]] [0];
michael@0 187 p[1] = vp8_mode_contexts [near_mv_ref_ct[1]] [1];
michael@0 188 p[2] = vp8_mode_contexts [near_mv_ref_ct[2]] [2];
michael@0 189 p[3] = vp8_mode_contexts [near_mv_ref_ct[3]] [3];
michael@0 190 /*p[3] = vp8_mode_contexts [near_mv_ref_ct[1] + near_mv_ref_ct[2] + near_mv_ref_ct[3]] [3];*/
michael@0 191 return p;
michael@0 192 }
michael@0 193

mercurial