| 1 |
/* |
| 2 |
* Copyright © 2016 Intel Corporation |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the |
| 6 |
* "Software"), to deal in the Software without restriction, including |
| 7 |
* without limitation the rights to use, copy, modify, merge, publish, |
| 8 |
* distribute, sub license, and/or sell copies of the Software, and to |
| 9 |
* permit persons to whom the Software is furnished to do so, subject to |
| 10 |
* the following conditions: |
| 11 |
* |
| 12 |
* The above copyright notice and this permission notice (including the |
| 13 |
* next paragraph) shall be included in all copies or substantial portions |
| 14 |
* of the Software. |
| 15 |
* |
| 16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 17 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 18 |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
| 19 |
* IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR |
| 20 |
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 21 |
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 22 |
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 |
* |
| 24 |
* Authors: |
| 25 |
* Zhao Yakui <[email protected]> |
| 26 |
*/ |
| 27 |
/* |
| 28 |
* This file defines some vp9 probability tables, and |
| 29 |
* they are ported from libvpx (https://github.com/webmproject/libvpx/). |
| 30 |
* The original copyright and licence statement as below. |
| 31 |
*/ |
| 32 |
|
| 33 |
/* |
| 34 |
* Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
| 35 |
* |
| 36 |
* Use of this source code is governed by a BSD-style license |
| 37 |
* that can be found in the LICENSE file in the root of the source |
| 38 |
* tree. An additional intellectual property rights grant can be found |
| 39 |
* in the file PATENTS. All contributing project authors may |
| 40 |
* be found in the AUTHORS file in the root of the source tree. |
| 41 |
*/ |
| 42 |
#include <stdio.h> |
| 43 |
#include <stdint.h> |
| 44 |
#include <string.h> |
| 45 |
#include "vp9_probs.h" |
| 46 |
#include "i965_drv_video.h" |
| 47 |
#include <stdlib.h> |
| 48 |
|
| 49 |
struct tx_probs default_tx_probs = { |
| 50 |
{ { 100 }, |
| 51 |
{ 66 } |
| 52 |
}, |
| 53 |
|
| 54 |
{ { 20, 152 }, |
| 55 |
{ 15, 101 } |
| 56 |
}, |
| 57 |
|
| 58 |
{ { 3, 136, 37 }, |
| 59 |
{ 5, 52, 13 } |
| 60 |
}, |
| 61 |
}; |
| 62 |
|
| 63 |
vp9_prob default_skip_probs[SKIP_CONTEXTS] = { |
| 64 |
192, 128, 64 |
| 65 |
}; |
| 66 |
|
| 67 |
vp9_prob default_inter_mode_probs[INTER_MODE_CONTEXTS] |
| 68 |
[INTER_MODES - 1] = { |
| 69 |
{2, 173, 34}, // 0 = both zero mv |
| 70 |
{7, 145, 85}, // 1 = one zero mv + one a predicted mv |
| 71 |
{7, 166, 63}, // 2 = two predicted mvs |
| 72 |
{7, 94, 66}, // 3 = one predicted/zero and one new mv |
| 73 |
{8, 64, 46}, // 4 = two new mvs |
| 74 |
{17, 81, 31}, // 5 = one intra neighbour + x |
| 75 |
{25, 29, 30}, // 6 = two intra neighbours |
| 76 |
}; |
| 77 |
|
| 78 |
vp9_prob default_switchable_interp_prob[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS - 1] = { |
| 79 |
{ 235, 162, }, |
| 80 |
{ 36, 255, }, |
| 81 |
{ 34, 3, }, |
| 82 |
{ 149, 144, }, |
| 83 |
}; |
| 84 |
|
| 85 |
vp9_prob default_intra_inter_p[INTRA_INTER_CONTEXTS] = { |
| 86 |
9, 102, 187, 225 |
| 87 |
}; |
| 88 |
|
| 89 |
vp9_prob default_comp_inter_p[COMP_INTER_CONTEXTS] = { |
| 90 |
239, 183, 119, 96, 41 |
| 91 |
}; |
| 92 |
|
| 93 |
vp9_prob default_single_ref_p[REF_CONTEXTS][2] = { |
| 94 |
{ 33, 16 }, |
| 95 |
{ 77, 74 }, |
| 96 |
{ 142, 142 }, |
| 97 |
{ 172, 170 }, |
| 98 |
{ 238, 247 } |
| 99 |
}; |
| 100 |
|
| 101 |
vp9_prob default_comp_ref_p[REF_CONTEXTS] = { |
| 102 |
50, 126, 123, 221, 226 |
| 103 |
}; |
| 104 |
|
| 105 |
vp9_prob vp9_kf_uv_mode_prob[INTRA_MODES][INTRA_MODES - 1] = { |
| 106 |
{ 144, 11, 54, 157, 195, 130, 46, 58, 108 }, // y = dc |
| 107 |
{ 118, 15, 123, 148, 131, 101, 44, 93, 131 }, // y = v |
| 108 |
{ 113, 12, 23, 188, 226, 142, 26, 32, 125 }, // y = h |
| 109 |
{ 120, 11, 50, 123, 163, 135, 64, 77, 103 }, // y = d45 |
| 110 |
{ 113, 9, 36, 155, 111, 157, 32, 44, 161 }, // y = d135 |
| 111 |
{ 116, 9, 55, 176, 76, 96, 37, 61, 149 }, // y = d117 |
| 112 |
{ 115, 9, 28, 141, 161, 167, 21, 25, 193 }, // y = d153 |
| 113 |
{ 120, 12, 32, 145, 195, 142, 32, 38, 86 }, // y = d207 |
| 114 |
{ 116, 12, 64, 120, 140, 125, 49, 115, 121 }, // y = d63 |
| 115 |
{ 102, 19, 66, 162, 182, 122, 35, 59, 128 } // y = tm |
| 116 |
}; |
| 117 |
|
| 118 |
vp9_prob default_if_y_probs[BLOCK_SIZE_GROUPS][INTRA_MODES - 1] = { |
| 119 |
{ 65, 32, 18, 144, 162, 194, 41, 51, 98 }, // block_size < 8x8 |
| 120 |
{ 132, 68, 18, 165, 217, 196, 45, 40, 78 }, // block_size < 16x16 |
| 121 |
{ 173, 80, 19, 176, 240, 193, 64, 35, 46 }, // block_size < 32x32 |
| 122 |
{ 221, 135, 38, 194, 248, 121, 96, 85, 29 } // block_size >= 32x32 |
| 123 |
}; |
| 124 |
|
| 125 |
vp9_prob default_if_uv_probs[INTRA_MODES][INTRA_MODES - 1] = { |
| 126 |
{ 120, 7, 76, 176, 208, 126, 28, 54, 103 }, // y = dc |
| 127 |
{ 48, 12, 154, 155, 139, 90, 34, 117, 119 }, // y = v |
| 128 |
{ 67, 6, 25, 204, 243, 158, 13, 21, 96 }, // y = h |
| 129 |
{ 97, 5, 44, 131, 176, 139, 48, 68, 97 }, // y = d45 |
| 130 |
{ 83, 5, 42, 156, 111, 152, 26, 49, 152 }, // y = d135 |
| 131 |
{ 80, 5, 58, 178, 74, 83, 33, 62, 145 }, // y = d117 |
| 132 |
{ 86, 5, 32, 154, 192, 168, 14, 22, 163 }, // y = d153 |
| 133 |
{ 85, 5, 32, 156, 216, 148, 19, 29, 73 }, // y = d207 |
| 134 |
{ 77, 7, 64, 116, 132, 122, 37, 126, 120 }, // y = d63 |
| 135 |
{ 101, 21, 107, 181, 192, 103, 19, 67, 125 } // y = tm |
| 136 |
}; |
| 137 |
|
| 138 |
vp9_prob default_seg_tree_probs[SEG_TREE_PROBS] = { |
| 139 |
255, 255, 255, 255, 255, 255, 255 |
| 140 |
}; |
| 141 |
|
| 142 |
vp9_prob default_seg_pred_probs[PREDICTION_PROBS] = { |
| 143 |
255, 255, 255 |
| 144 |
}; |
| 145 |
|
| 146 |
vp9_prob vp9_kf_partition_probs[PARTITION_CONTEXTS] |
| 147 |
[PARTITION_TYPES - 1] = { |
| 148 |
// 8x8 -> 4x4 |
| 149 |
{ 158, 97, 94 }, // a/l both not split |
| 150 |
{ 93, 24, 99 }, // a split, l not split |
| 151 |
{ 85, 119, 44 }, // l split, a not split |
| 152 |
{ 62, 59, 67 }, // a/l both split |
| 153 |
// 16x16 -> 8x8 |
| 154 |
{ 149, 53, 53 }, // a/l both not split |
| 155 |
{ 94, 20, 48 }, // a split, l not split |
| 156 |
{ 83, 53, 24 }, // l split, a not split |
| 157 |
{ 52, 18, 18 }, // a/l both split |
| 158 |
// 32x32 -> 16x16 |
| 159 |
{ 150, 40, 39 }, // a/l both not split |
| 160 |
{ 78, 12, 26 }, // a split, l not split |
| 161 |
{ 67, 33, 11 }, // l split, a not split |
| 162 |
{ 24, 7, 5 }, // a/l both split |
| 163 |
// 64x64 -> 32x32 |
| 164 |
{ 174, 35, 49 }, // a/l both not split |
| 165 |
{ 68, 11, 27 }, // a split, l not split |
| 166 |
{ 57, 15, 9 }, // l split, a not split |
| 167 |
{ 12, 3, 3 }, // a/l both split |
| 168 |
}; |
| 169 |
|
| 170 |
vp9_prob default_partition_probs[PARTITION_CONTEXTS] |
| 171 |
[PARTITION_TYPES - 1] = { |
| 172 |
// 8x8 -> 4x4 |
| 173 |
{ 199, 122, 141 }, // a/l both not split |
| 174 |
{ 147, 63, 159 }, // a split, l not split |
| 175 |
{ 148, 133, 118 }, // l split, a not split |
| 176 |
{ 121, 104, 114 }, // a/l both split |
| 177 |
// 16x16 -> 8x8 |
| 178 |
{ 174, 73, 87 }, // a/l both not split |
| 179 |
{ 92, 41, 83 }, // a split, l not split |
| 180 |
{ 82, 99, 50 }, // l split, a not split |
| 181 |
{ 53, 39, 39 }, // a/l both split |
| 182 |
// 32x32 -> 16x16 |
| 183 |
{ 177, 58, 59 }, // a/l both not split |
| 184 |
{ 68, 26, 63 }, // a split, l not split |
| 185 |
{ 52, 79, 25 }, // l split, a not split |
| 186 |
{ 17, 14, 12 }, // a/l both split |
| 187 |
// 64x64 -> 32x32 |
| 188 |
{ 222, 34, 30 }, // a/l both not split |
| 189 |
{ 72, 16, 44 }, // a split, l not split |
| 190 |
{ 58, 32, 12 }, // l split, a not split |
| 191 |
{ 10, 7, 6 }, // a/l both split |
| 192 |
}; |
| 193 |
|
| 194 |
//Rearranged the values for better usage |
| 195 |
nmv_context default_nmv_context = { |
| 196 |
{32, 64, 96}, |
| 197 |
{ |
| 198 |
{ |
| 199 |
// Vertical component |
| 200 |
128, // sign |
| 201 |
{224, 144, 192, 168, 192, 176, 192, 198, 198, 245}, // class |
| 202 |
{216}, // class0 |
| 203 |
{136, 140, 148, 160, 176, 192, 224, 234, 234, 240}, // bits |
| 204 |
}, |
| 205 |
{ |
| 206 |
// Horizontal component |
| 207 |
128, // sign |
| 208 |
{216, 128, 176, 160, 176, 176, 192, 198, 198, 208}, // class |
| 209 |
{208}, // class0 |
| 210 |
{136, 140, 148, 160, 176, 192, 224, 234, 234, 240}, // bits |
| 211 |
} |
| 212 |
}, |
| 213 |
{{128, 128, 64}, {96, 112, 64}}, // class0_fp0 |
| 214 |
{64, 96, 64}, // fp0 |
| 215 |
{{128, 128, 64}, {96, 112, 64}}, // class0_fp1 |
| 216 |
{64, 96, 64}, // fp1 |
| 217 |
{160, 128}, // class0_hp bit |
| 218 |
{160, 128} // hp |
| 219 |
|
| 220 |
}; |
| 221 |
|
| 222 |
//Rearranged the coeff probs for better usage |
| 223 |
vp9_prob default_coef_probs_4x4[COEFF_PROB_SIZE][COEFF_PROB_NUM] = { |
| 224 |
// Y plane - Intra |
| 225 |
// Band 0 |
| 226 |
{ 195, 29, 183 }, { 84, 49, 136 }, { 8, 42, 71 }, |
| 227 |
// Band 1 |
| 228 |
{ 31, 107, 169 }, { 35, 99, 159 }, { 17, 82, 140 }, |
| 229 |
{ 8, 66, 114 }, { 2, 44, 76 }, { 1, 19, 32 }, |
| 230 |
// Band 2 |
| 231 |
{ 40, 132, 201 }, { 29, 114, 187 }, { 13, 91, 157 }, |
| 232 |
{ 7, 75, 127 }, { 3, 58, 95 }, { 1, 28, 47 }, |
| 233 |
// Band 3 |
| 234 |
{ 69, 142, 221 }, { 42, 122, 201 }, { 15, 91, 159 }, |
| 235 |
{ 6, 67, 121 }, { 1, 42, 77 }, { 1, 17, 31 }, |
| 236 |
// Band 4 |
| 237 |
{ 102, 148, 228 }, { 67, 117, 204 }, { 17, 82, 154 }, |
| 238 |
{ 6, 59, 114 }, { 2, 39, 75 }, { 1, 15, 29 }, |
| 239 |
// Band 5 |
| 240 |
{ 156, 57, 233 }, { 119, 57, 212 }, { 58, 48, 163 }, |
| 241 |
{ 29, 40, 124 }, { 12, 30, 81 }, { 3, 12, 31 }, |
| 242 |
|
| 243 |
// Y plane - Inter |
| 244 |
// Band 0 |
| 245 |
{ 191, 107, 226 }, { 124, 117, 204 }, { 25, 99, 155 }, |
| 246 |
// Band 1 |
| 247 |
{ 29, 148, 210 }, { 37, 126, 194 }, { 8, 93, 157 }, |
| 248 |
{ 2, 68, 118 }, { 1, 39, 69 }, { 1, 17, 33 }, |
| 249 |
// Band 2 |
| 250 |
{ 41, 151, 213 }, { 27, 123, 193 }, { 3, 82, 144 }, |
| 251 |
{ 1, 58, 105 }, { 1, 32, 60 }, { 1, 13, 26 }, |
| 252 |
// Band 3 |
| 253 |
{ 59, 159, 220 }, { 23, 126, 198 }, { 4, 88, 151 }, |
| 254 |
{ 1, 66, 114 }, { 1, 38, 71 }, { 1, 18, 34 }, |
| 255 |
// Band 4 |
| 256 |
{ 114, 136, 232 }, { 51, 114, 207 }, { 11, 83, 155 }, |
| 257 |
{ 3, 56, 105 }, { 1, 33, 65 }, { 1, 17, 34 }, |
| 258 |
// Band 5 |
| 259 |
{ 149, 65, 234 }, { 121, 57, 215 }, { 61, 49, 166 }, |
| 260 |
{ 28, 36, 114 }, { 12, 25, 76 }, { 3, 16, 42 }, |
| 261 |
|
| 262 |
// UV plane - Intra |
| 263 |
// Band 0 |
| 264 |
{ 214, 49, 220 }, { 132, 63, 188 }, { 42, 65, 137 }, |
| 265 |
// Band 1 |
| 266 |
{ 85, 137, 221 }, { 104, 131, 216 }, { 49, 111, 192 }, |
| 267 |
{ 21, 87, 155 }, { 2, 49, 87 }, { 1, 16, 28 }, |
| 268 |
// Band 2 |
| 269 |
{ 89, 163, 230 }, { 90, 137, 220 }, { 29, 100, 183 }, |
| 270 |
{ 10, 70, 135 }, { 2, 42, 81 }, { 1, 17, 33 }, |
| 271 |
// Band 3 |
| 272 |
{ 108, 167, 237 }, { 55, 133, 222 }, { 15, 97, 179 }, |
| 273 |
{ 4, 72, 135 }, { 1, 45, 85 }, { 1, 19, 38 }, |
| 274 |
// Band 4 |
| 275 |
{ 124, 146, 240 }, { 66, 124, 224 }, { 17, 88, 175 }, |
| 276 |
{ 4, 58, 122 }, { 1, 36, 75 }, { 1, 18, 37 }, |
| 277 |
// Band 5 |
| 278 |
{ 141, 79, 241 }, { 126, 70, 227 }, { 66, 58, 182 }, |
| 279 |
{ 30, 44, 136 }, { 12, 34, 96 }, { 2, 20, 47 }, |
| 280 |
|
| 281 |
// UV plane - Inter |
| 282 |
// Band 0 |
| 283 |
{ 229, 99, 249 }, { 143, 111, 235 }, { 46, 109, 192 }, |
| 284 |
// Band 1 |
| 285 |
{ 82, 158, 236 }, { 94, 146, 224 }, { 25, 117, 191 }, |
| 286 |
{ 9, 87, 149 }, { 3, 56, 99 }, { 1, 33, 57 }, |
| 287 |
// Band 2 |
| 288 |
{ 83, 167, 237 }, { 68, 145, 222 }, { 10, 103, 177 }, |
| 289 |
{ 2, 72, 131 }, { 1, 41, 79 }, { 1, 20, 39 }, |
| 290 |
// Band 3 |
| 291 |
{ 99, 167, 239 }, { 47, 141, 224 }, { 10, 104, 178 }, |
| 292 |
{ 2, 73, 133 }, { 1, 44, 85 }, { 1, 22, 47 }, |
| 293 |
// Band 4 |
| 294 |
{ 127, 145, 243 }, { 71, 129, 228 }, { 17, 93, 177 }, |
| 295 |
{ 3, 61, 124 }, { 1, 41, 84 }, { 1, 21, 52 }, |
| 296 |
// Band 5 |
| 297 |
{ 157, 78, 244 }, { 140, 72, 231 }, { 69, 58, 184 }, |
| 298 |
{ 31, 44, 137 }, { 14, 38, 105 }, { 8, 23, 61 } |
| 299 |
}; |
| 300 |
|
| 301 |
vp9_prob default_coef_probs_8x8[COEFF_PROB_SIZE][COEFF_PROB_NUM] = { |
| 302 |
// Y plane - Intra |
| 303 |
// Band 0 |
| 304 |
{ 125, 34, 187 }, { 52, 41, 133 }, { 6, 31, 56 }, |
| 305 |
// Band 1 |
| 306 |
{ 37, 109, 153 }, { 51, 102, 147 }, { 23, 87, 128 }, |
| 307 |
{ 8, 67, 101 }, { 1, 41, 63 }, { 1, 19, 29 }, |
| 308 |
// Band 2 |
| 309 |
{ 31, 154, 185 }, { 17, 127, 175 }, { 6, 96, 145 }, |
| 310 |
{ 2, 73, 114 }, { 1, 51, 82 }, { 1, 28, 45 }, |
| 311 |
// Band 3 |
| 312 |
{ 23, 163, 200 }, { 10, 131, 185 }, { 2, 93, 148 }, |
| 313 |
{ 1, 67, 111 }, { 1, 41, 69 }, { 1, 14, 24 }, |
| 314 |
// Band 4 |
| 315 |
{ 29, 176, 217 }, { 12, 145, 201 }, { 3, 101, 156 }, |
| 316 |
{ 1, 69, 111 }, { 1, 39, 63 }, { 1, 14, 23 }, |
| 317 |
// Band 5 |
| 318 |
{ 57, 192, 233 }, { 25, 154, 215 }, { 6, 109, 167 }, |
| 319 |
{ 3, 78, 118 }, { 1, 48, 69 }, { 1, 21, 29 }, |
| 320 |
|
| 321 |
// Y plane - Inter |
| 322 |
// Band 0 |
| 323 |
{ 202, 105, 245 }, { 108, 106, 216 }, { 18, 90, 144 }, |
| 324 |
// Band 1 |
| 325 |
{ 33, 172, 219 }, { 64, 149, 206 }, { 14, 117, 177 }, |
| 326 |
{ 5, 90, 141 }, { 2, 61, 95 }, { 1, 37, 57 }, |
| 327 |
// Band 2 |
| 328 |
{ 33, 179, 220 }, { 11, 140, 198 }, { 1, 89, 148 }, |
| 329 |
{ 1, 60, 104 }, { 1, 33, 57 }, { 1, 12, 21 }, |
| 330 |
// Band 3 |
| 331 |
{ 30, 181, 221 }, { 8, 141, 198 }, { 1, 87, 145 }, |
| 332 |
{ 1, 58, 100 }, { 1, 31, 55 }, { 1, 12, 20 }, |
| 333 |
// Band 4 |
| 334 |
{ 32, 186, 224 }, { 7, 142, 198 }, { 1, 86, 143 }, |
| 335 |
{ 1, 58, 100 }, { 1, 31, 55 }, { 1, 12, 22 }, |
| 336 |
// Band 5 |
| 337 |
{ 57, 192, 227 }, { 20, 143, 204 }, { 3, 96, 154 }, |
| 338 |
{ 1, 68, 112 }, { 1, 42, 69 }, { 1, 19, 32 }, |
| 339 |
|
| 340 |
// UV plane - Intra |
| 341 |
// Band 0 |
| 342 |
{ 212, 35, 215 }, { 113, 47, 169 }, { 29, 48, 105 }, |
| 343 |
// Band 1 |
| 344 |
{ 74, 129, 203 }, { 106, 120, 203 }, { 49, 107, 178 }, |
| 345 |
{ 19, 84, 144 }, { 4, 50, 84 }, { 1, 15, 25 }, |
| 346 |
// Band 2 |
| 347 |
{ 71, 172, 217 }, { 44, 141, 209 }, { 15, 102, 173 }, |
| 348 |
{ 6, 76, 133 }, { 2, 51, 89 }, { 1, 24, 42 }, |
| 349 |
// Band 3 |
| 350 |
{ 64, 185, 231 }, { 31, 148, 216 }, { 8, 103, 175 }, |
| 351 |
{ 3, 74, 131 }, { 1, 46, 81 }, { 1, 18, 30 }, |
| 352 |
// Band 4 |
| 353 |
{ 65, 196, 235 }, { 25, 157, 221 }, { 5, 105, 174 }, |
| 354 |
{ 1, 67, 120 }, { 1, 38, 69 }, { 1, 15, 30 }, |
| 355 |
// Band 5 |
| 356 |
{ 65, 204, 238 }, { 30, 156, 224 }, { 7, 107, 177 }, |
| 357 |
{ 2, 70, 124 }, { 1, 42, 73 }, { 1, 18, 34 }, |
| 358 |
|
| 359 |
// UV Plane - Inter |
| 360 |
// Band 0 |
| 361 |
{ 225, 86, 251 }, { 144, 104, 235 }, { 42, 99, 181 }, |
| 362 |
// Band 1 |
| 363 |
{ 85, 175, 239 }, { 112, 165, 229 }, { 29, 136, 200 }, |
| 364 |
{ 12, 103, 162 }, { 6, 77, 123 }, { 2, 53, 84 }, |
| 365 |
// Band 2 |
| 366 |
{ 75, 183, 239 }, { 30, 155, 221 }, { 3, 106, 171 }, |
| 367 |
{ 1, 74, 128 }, { 1, 44, 76 }, { 1, 17, 28 }, |
| 368 |
// Band 3 |
| 369 |
{ 73, 185, 240 }, { 27, 159, 222 }, { 2, 107, 172 }, |
| 370 |
{ 1, 75, 127 }, { 1, 42, 73 }, { 1, 17, 29 }, |
| 371 |
// Band 4 |
| 372 |
{ 62, 190, 238 }, { 21, 159, 222 }, { 2, 107, 172 }, |
| 373 |
{ 1, 72, 122 }, { 1, 40, 71 }, { 1, 18, 32 }, |
| 374 |
// Band 5 |
| 375 |
{ 61, 199, 240 }, { 27, 161, 226 }, { 4, 113, 180 }, |
| 376 |
{ 1, 76, 129 }, { 1, 46, 80 }, { 1, 23, 41 } |
| 377 |
}; |
| 378 |
|
| 379 |
vp9_prob default_coef_probs_16x16[COEFF_PROB_SIZE][COEFF_PROB_NUM] = { |
| 380 |
// Y plane - Intra |
| 381 |
// Band 0 |
| 382 |
{ 7, 27, 153 }, { 5, 30, 95 }, { 1, 16, 30 }, |
| 383 |
// Band 1 |
| 384 |
{ 50, 75, 127 }, { 57, 75, 124 }, { 27, 67, 108 }, |
| 385 |
{ 10, 54, 86 }, { 1, 33, 52 }, { 1, 12, 18 }, |
| 386 |
// Band 2 |
| 387 |
{ 43, 125, 151 }, { 26, 108, 148 }, { 7, 83, 122 }, |
| 388 |
{ 2, 59, 89 }, { 1, 38, 60 }, { 1, 17, 27 }, |
| 389 |
// Band 3 |
| 390 |
{ 23, 144, 163 }, { 13, 112, 154 }, { 2, 75, 117 }, |
| 391 |
{ 1, 50, 81 }, { 1, 31, 51 }, { 1, 14, 23 }, |
| 392 |
// Band 4 |
| 393 |
{ 18, 162, 185 }, { 6, 123, 171 }, { 1, 78, 125 }, |
| 394 |
{ 1, 51, 86 }, { 1, 31, 54 }, { 1, 14, 23 }, |
| 395 |
// Band 5 |
| 396 |
{ 15, 199, 227 }, { 3, 150, 204 }, { 1, 91, 146 }, |
| 397 |
{ 1, 55, 95 }, { 1, 30, 53 }, { 1, 11, 20 }, |
| 398 |
|
| 399 |
// Y plane - Inter |
| 400 |
// Band 0 |
| 401 |
{ 19, 55, 240 }, { 19, 59, 196 }, { 3, 52, 105 }, |
| 402 |
// Band 1 |
| 403 |
{ 41, 166, 207 }, { 104, 153, 199 }, { 31, 123, 181 }, |
| 404 |
{ 14, 101, 152 }, { 5, 72, 106 }, { 1, 36, 52 }, |
| 405 |
// Band 2 |
| 406 |
{ 35, 176, 211 }, { 12, 131, 190 }, { 2, 88, 144 }, |
| 407 |
{ 1, 60, 101 }, { 1, 36, 60 }, { 1, 16, 28 }, |
| 408 |
// Band 3 |
| 409 |
{ 28, 183, 213 }, { 8, 134, 191 }, { 1, 86, 142 }, |
| 410 |
{ 1, 56, 96 }, { 1, 30, 53 }, { 1, 12, 20 }, |
| 411 |
// Band 4 |
| 412 |
{ 20, 190, 215 }, { 4, 135, 192 }, { 1, 84, 139 }, |
| 413 |
{ 1, 53, 91 }, { 1, 28, 49 }, { 1, 11, 20 }, |
| 414 |
// Band 5 |
| 415 |
{ 13, 196, 216 }, { 2, 137, 192 }, { 1, 86, 143 }, |
| 416 |
{ 1, 57, 99 }, { 1, 32, 56 }, { 1, 13, 24 }, |
| 417 |
|
| 418 |
// UV plane - Intra |
| 419 |
// Band 0 |
| 420 |
{ 211, 29, 217 }, { 96, 47, 156 }, { 22, 43, 87 }, |
| 421 |
// Band 1 |
| 422 |
{ 78, 120, 193 }, { 111, 116, 186 }, { 46, 102, 164 }, |
| 423 |
{ 15, 80, 128 }, { 2, 49, 76 }, { 1, 18, 28 }, |
| 424 |
// Band 2 |
| 425 |
{ 71, 161, 203 }, { 42, 132, 192 }, { 10, 98, 150 }, |
| 426 |
{ 3, 69, 109 }, { 1, 44, 70 }, { 1, 18, 29 }, |
| 427 |
// Band 3 |
| 428 |
{ 57, 186, 211 }, { 30, 140, 196 }, { 4, 93, 146 }, |
| 429 |
{ 1, 62, 102 }, { 1, 38, 65 }, { 1, 16, 27 }, |
| 430 |
// Band 4 |
| 431 |
{ 47, 199, 217 }, { 14, 145, 196 }, { 1, 88, 142 }, |
| 432 |
{ 1, 57, 98 }, { 1, 36, 62 }, { 1, 15, 26 }, |
| 433 |
// Band 5 |
| 434 |
{ 26, 219, 229 }, { 5, 155, 207 }, { 1, 94, 151 }, |
| 435 |
{ 1, 60, 104 }, { 1, 36, 62 }, { 1, 16, 28 }, |
| 436 |
|
| 437 |
// UV plane - Inter |
| 438 |
// Band 0 |
| 439 |
{ 233, 29, 248 }, { 146, 47, 220 }, { 43, 52, 140 }, |
| 440 |
// Band 1 |
| 441 |
{ 100, 163, 232 }, { 179, 161, 222 }, { 63, 142, 204 }, |
| 442 |
{ 37, 113, 174 }, { 26, 89, 137 }, { 18, 68, 97 }, |
| 443 |
// Band 2 |
| 444 |
{ 85, 181, 230 }, { 32, 146, 209 }, { 7, 100, 164 }, |
| 445 |
{ 3, 71, 121 }, { 1, 45, 77 }, { 1, 18, 30 }, |
| 446 |
// Band 3 |
| 447 |
{ 65, 187, 230 }, { 20, 148, 207 }, { 2, 97, 159 }, |
| 448 |
{ 1, 68, 116 }, { 1, 40, 70 }, { 1, 14, 29 }, |
| 449 |
// Band 4 |
| 450 |
{ 40, 194, 227 }, { 8, 147, 204 }, { 1, 94, 155 }, |
| 451 |
{ 1, 65, 112 }, { 1, 39, 66 }, { 1, 14, 26 }, |
| 452 |
// Band 5 |
| 453 |
{ 16, 208, 228 }, { 3, 151, 207 }, { 1, 98, 160 }, |
| 454 |
{ 1, 67, 117 }, { 1, 41, 74 }, { 1, 17, 31 } |
| 455 |
}; |
| 456 |
|
| 457 |
vp9_prob default_coef_probs_32x32[COEFF_PROB_SIZE][COEFF_PROB_NUM] = { |
| 458 |
// Y plane - Intra |
| 459 |
// Band 0 |
| 460 |
{ 17, 38, 140 }, { 7, 34, 80 }, { 1, 17, 29 }, |
| 461 |
// Band 1 |
| 462 |
{ 37, 75, 128 }, { 41, 76, 128 }, { 26, 66, 116 }, |
| 463 |
{ 12, 52, 94 }, { 2, 32, 55 }, { 1, 10, 16 }, |
| 464 |
// Band 2 |
| 465 |
{ 50, 127, 154 }, { 37, 109, 152 }, { 16, 82, 121 }, |
| 466 |
{ 5, 59, 85 }, { 1, 35, 54 }, { 1, 13, 20 }, |
| 467 |
//Band 3 |
| 468 |
{ 40, 142, 167 }, { 17, 110, 157 }, { 2, 71, 112 }, |
| 469 |
{ 1, 44, 72 }, { 1, 27, 45 }, { 1, 11, 17 }, |
| 470 |
// Band 4 |
| 471 |
{ 30, 175, 188 }, { 9, 124, 169 }, { 1, 74, 116 }, |
| 472 |
{ 1, 48, 78 }, { 1, 30, 49 }, { 1, 11, 18 }, |
| 473 |
// Band 5 |
| 474 |
{ 10, 222, 223 }, { 2, 150, 194 }, { 1, 83, 128 }, |
| 475 |
{ 1, 48, 79 }, { 1, 27, 45 }, { 1, 11, 17 }, |
| 476 |
|
| 477 |
// Y plane - Inter |
| 478 |
// Band 0 |
| 479 |
{ 36, 41, 235 }, { 29, 36, 193 }, { 10, 27, 111 }, |
| 480 |
// Band 1 |
| 481 |
{ 85, 165, 222 }, { 177, 162, 215 }, { 110, 135, 195 }, |
| 482 |
{ 57, 113, 168 }, { 23, 83, 120 }, { 10, 49, 61 }, |
| 483 |
// Band 2 |
| 484 |
{ 85, 190, 223 }, { 36, 139, 200 }, { 5, 90, 146 }, |
| 485 |
{ 1, 60, 103 }, { 1, 38, 65 }, { 1, 18, 30 }, |
| 486 |
// Band 3 |
| 487 |
{ 72, 202, 223 }, { 23, 141, 199 }, { 2, 86, 140 }, |
| 488 |
{ 1, 56, 97 }, { 1, 36, 61 }, { 1, 16, 27 }, |
| 489 |
// Band 4 |
| 490 |
{ 55, 218, 225 }, { 13, 145, 200 }, { 1, 86, 141 }, |
| 491 |
{ 1, 57, 99 }, { 1, 35, 61 }, { 1, 13, 22 }, |
| 492 |
// Band 5 |
| 493 |
{ 15, 235, 212 }, { 1, 132, 184 }, { 1, 84, 139 }, |
| 494 |
{ 1, 57, 97 }, { 1, 34, 56 }, { 1, 14, 23 }, |
| 495 |
|
| 496 |
// UV plane - Intra |
| 497 |
// Band 0 |
| 498 |
{ 181, 21, 201 }, { 61, 37, 123 }, { 10, 38, 71 }, |
| 499 |
// Band 1 |
| 500 |
{ 47, 106, 172 }, { 95, 104, 173 }, { 42, 93, 159 }, |
| 501 |
{ 18, 77, 131 }, { 4, 50, 81 }, { 1, 17, 23 }, |
| 502 |
// Band 2 |
| 503 |
{ 62, 147, 199 }, { 44, 130, 189 }, { 28, 102, 154 }, |
| 504 |
{ 18, 75, 115 }, { 2, 44, 65 }, { 1, 12, 19 }, |
| 505 |
// Band 3 |
| 506 |
{ 55, 153, 210 }, { 24, 130, 194 }, { 3, 93, 146 }, |
| 507 |
{ 1, 61, 97 }, { 1, 31, 50 }, { 1, 10, 16 }, |
| 508 |
// Band 4 |
| 509 |
{ 49, 186, 223 }, { 17, 148, 204 }, { 1, 96, 142 }, |
| 510 |
{ 1, 53, 83 }, { 1, 26, 44 }, { 1, 11, 17 }, |
| 511 |
// Band 5 |
| 512 |
{ 13, 217, 212 }, { 2, 136, 180 }, { 1, 78, 124 }, |
| 513 |
{ 1, 50, 83 }, { 1, 29, 49 }, { 1, 14, 23 }, |
| 514 |
|
| 515 |
// UV plane - Inter |
| 516 |
// Band 0 |
| 517 |
{ 197, 13, 247 }, { 82, 17, 222 }, { 25, 17, 162 }, |
| 518 |
// Band 1 |
| 519 |
{ 126, 186, 247 }, { 234, 191, 243 }, { 176, 177, 234 }, |
| 520 |
{ 104, 158, 220 }, { 66, 128, 186 }, { 55, 90, 137 }, |
| 521 |
// Band 2 |
| 522 |
{ 111, 197, 242 }, { 46, 158, 219 }, { 9, 104, 171 }, |
| 523 |
{ 2, 65, 125 }, { 1, 44, 80 }, { 1, 17, 91 }, |
| 524 |
// Band 3 |
| 525 |
{ 104, 208, 245 }, { 39, 168, 224 }, { 3, 109, 162 }, |
| 526 |
{ 1, 79, 124 }, { 1, 50, 102 }, { 1, 43, 102 }, |
| 527 |
// Band 4 |
| 528 |
{ 84, 220, 246 }, { 31, 177, 231 }, { 2, 115, 180 }, |
| 529 |
{ 1, 79, 134 }, { 1, 55, 77 }, { 1, 60, 79 }, |
| 530 |
// Band 5 |
| 531 |
{ 43, 243, 240 }, { 8, 180, 217 }, { 1, 115, 166 }, |
| 532 |
{ 1, 84, 121 }, { 1, 51, 67 }, { 1, 16, 6 } |
| 533 |
|
| 534 |
}; |
| 535 |
|
| 536 |
#define FC_INTRA_OFFSET 0 |
| 537 |
#define FC_INTRA_SIZE 1664 |
| 538 |
|
| 539 |
#define FC_INTER_OFFSET 1664 |
| 540 |
#define FC_INTER_SIZE 384 |
| 541 |
|
| 542 |
#define FC_SKIP_OFFSET 1664 |
| 543 |
#define FC_SKIP_SIZE 3 |
| 544 |
|
| 545 |
void intel_init_default_vp9_probs(FRAME_CONTEXT *frame_context) |
| 546 |
{ |
| 547 |
if (!frame_context) |
| 548 |
return; |
| 549 |
|
| 550 |
frame_context->tx_probs = default_tx_probs; |
| 551 |
//dummy 52 |
| 552 |
memcpy(frame_context->coeff_probs4x4, default_coef_probs_4x4, |
| 553 |
sizeof(default_coef_probs_4x4)); |
| 554 |
memcpy(frame_context->coeff_probs8x8, default_coef_probs_8x8, |
| 555 |
sizeof(default_coef_probs_8x8)); |
| 556 |
memcpy(frame_context->coeff_probs16x16, default_coef_probs_16x16, |
| 557 |
sizeof(default_coef_probs_16x16)); |
| 558 |
memcpy(frame_context->coeff_probs32x32, default_coef_probs_32x32, |
| 559 |
sizeof(default_coef_probs_16x16)); |
| 560 |
//dummy 16 |
| 561 |
memcpy(frame_context->skip_probs, default_skip_probs, |
| 562 |
sizeof(default_skip_probs)); |
| 563 |
memcpy(frame_context->inter_mode_probs, default_inter_mode_probs, |
| 564 |
sizeof(default_inter_mode_probs)); |
| 565 |
memcpy(frame_context->switchable_interp_prob, |
| 566 |
default_switchable_interp_prob, |
| 567 |
sizeof(default_switchable_interp_prob)); |
| 568 |
memcpy(frame_context->intra_inter_prob, default_intra_inter_p, |
| 569 |
sizeof(default_intra_inter_p)); |
| 570 |
memcpy(frame_context->comp_inter_prob, default_comp_inter_p, |
| 571 |
sizeof(default_comp_inter_p)); |
| 572 |
memcpy(frame_context->single_ref_prob, default_single_ref_p, |
| 573 |
sizeof(default_single_ref_p)); |
| 574 |
memcpy(frame_context->comp_ref_prob, default_comp_ref_p, |
| 575 |
sizeof(default_comp_ref_p)); |
| 576 |
memcpy(frame_context->y_mode_prob, default_if_y_probs, |
| 577 |
sizeof(default_if_y_probs)); |
| 578 |
memcpy(frame_context->partition_prob, default_partition_probs, |
| 579 |
sizeof(default_partition_probs)); |
| 580 |
frame_context->nmvc = default_nmv_context; |
| 581 |
//dummy 47 |
| 582 |
memcpy(frame_context->uv_mode_prob, default_if_uv_probs, |
| 583 |
sizeof(default_if_uv_probs)); |
| 584 |
memcpy(frame_context->seg_tree_probs, default_seg_tree_probs, |
| 585 |
sizeof(default_seg_tree_probs)); |
| 586 |
memcpy(frame_context->seg_pred_probs, default_seg_pred_probs, |
| 587 |
sizeof(default_seg_pred_probs)); |
| 588 |
return; |
| 589 |
} |
| 590 |
|
| 591 |
|
| 592 |
void intel_vp9_copy_frame_context(FRAME_CONTEXT *dst, |
| 593 |
FRAME_CONTEXT *src, |
| 594 |
bool inter_flag) |
| 595 |
{ |
| 596 |
unsigned char *fc_dst, *fc_src; |
| 597 |
|
| 598 |
if (!dst || !src) |
| 599 |
return; |
| 600 |
|
| 601 |
fc_dst = (unsigned char *)dst; |
| 602 |
fc_src = (unsigned char *)src; |
| 603 |
/* update the prob related with tx_mode/tx_coeff */ |
| 604 |
memcpy(fc_dst + FC_INTRA_OFFSET, fc_src + FC_INTRA_OFFSET, FC_INTRA_SIZE); |
| 605 |
|
| 606 |
if (inter_flag) { |
| 607 |
/* update the prob related with inter-frame */ |
| 608 |
memcpy(fc_dst + FC_INTER_OFFSET, fc_src + FC_INTER_OFFSET, FC_INTER_SIZE); |
| 609 |
} else { |
| 610 |
memcpy(fc_dst + FC_SKIP_OFFSET, fc_src + FC_SKIP_OFFSET, FC_SKIP_SIZE); |
| 611 |
} |
| 612 |
} |
| 613 |
|
| 614 |
void intel_update_intra_frame_context(FRAME_CONTEXT *frame_context) |
| 615 |
{ |
| 616 |
if (!frame_context) |
| 617 |
return; |
| 618 |
|
| 619 |
memcpy(frame_context->partition_prob, vp9_kf_partition_probs, |
| 620 |
sizeof(vp9_kf_partition_probs)); |
| 621 |
|
| 622 |
memcpy(frame_context->uv_mode_prob, vp9_kf_uv_mode_prob, |
| 623 |
sizeof(vp9_kf_uv_mode_prob)); |
| 624 |
|
| 625 |
} |
| 626 |
|
| 627 |
struct vp9_write_bit_buffer { |
| 628 |
uint8_t *bit_buffer; |
| 629 |
int bit_offset; |
| 630 |
}; |
| 631 |
|
| 632 |
static |
| 633 |
void vp9_wb_write_bit(struct vp9_write_bit_buffer *wb, int bit) |
| 634 |
{ |
| 635 |
const int off = wb->bit_offset; |
| 636 |
const int p = off / 8; |
| 637 |
const int q = 7 - off % 8; |
| 638 |
if (q == 7) { |
| 639 |
wb->bit_buffer[p] = bit << q; |
| 640 |
} else { |
| 641 |
wb->bit_buffer[p] &= ~(1 << q); |
| 642 |
wb->bit_buffer[p] |= bit << q; |
| 643 |
} |
| 644 |
wb->bit_offset = off + 1; |
| 645 |
} |
| 646 |
|
| 647 |
static |
| 648 |
void vp9_wb_write_literal(struct vp9_write_bit_buffer *wb, int data, int bits) |
| 649 |
{ |
| 650 |
int bit; |
| 651 |
for (bit = bits - 1; bit >= 0; bit--) |
| 652 |
vp9_wb_write_bit(wb, (data >> bit) & 1); |
| 653 |
} |
| 654 |
|
| 655 |
static |
| 656 |
void write_bitdepth_colorspace_sampling(int codec_profile, |
| 657 |
struct vp9_write_bit_buffer *wb) |
| 658 |
{ |
| 659 |
int profile = VAProfileVP9Profile0; |
| 660 |
profile = profile + 0; |
| 661 |
|
| 662 |
if (codec_profile >= (VAProfileVP9Profile0 + 2)) { |
| 663 |
/* the bit-depth will be added for VP9Profile2/3 */ |
| 664 |
/* this will be added later */ |
| 665 |
} |
| 666 |
|
| 667 |
/* Add the default color-space */ |
| 668 |
vp9_wb_write_literal(wb, 0, 3); |
| 669 |
vp9_wb_write_bit(wb, 0); // 0: [16, 235] (i.e. xvYCC), 1: [0, 255] |
| 670 |
|
| 671 |
/* the sampling_x/y will be added for VP9Profile1/2/3 later */ |
| 672 |
} |
| 673 |
|
| 674 |
#define MAX_TILE_WIDTH_B64 64 |
| 675 |
#define MIN_TILE_WIDTH_B64 4 |
| 676 |
|
| 677 |
static int get_min_log2_tile_cols(const int sb_cols) |
| 678 |
{ |
| 679 |
int min_log2 = 0; |
| 680 |
|
| 681 |
while ((MAX_TILE_WIDTH_B64 << min_log2) < sb_cols) |
| 682 |
++min_log2; |
| 683 |
|
| 684 |
return min_log2; |
| 685 |
} |
| 686 |
|
| 687 |
static int get_max_log2_tile_cols(const int sb_cols) |
| 688 |
{ |
| 689 |
int max_log2 = 1; |
| 690 |
|
| 691 |
while ((sb_cols >> max_log2) >= MIN_TILE_WIDTH_B64) |
| 692 |
++max_log2; |
| 693 |
|
| 694 |
return max_log2 - 1; |
| 695 |
} |
| 696 |
|
| 697 |
|
| 698 |
bool intel_write_uncompressed_header(struct encode_state *encode_state, |
| 699 |
int codec_profile, |
| 700 |
char *header_data, |
| 701 |
int *header_length, |
| 702 |
vp9_header_bitoffset *header_bitoffset) |
| 703 |
{ |
| 704 |
#define VP9_SYNC_CODE_0 0x49 |
| 705 |
#define VP9_SYNC_CODE_1 0x83 |
| 706 |
#define VP9_SYNC_CODE_2 0x42 |
| 707 |
|
| 708 |
#define VP9_FRAME_MARKER 0x2 |
| 709 |
|
| 710 |
#define REFS_PER_FRAME 3 |
| 711 |
|
| 712 |
#define REF_FRAMES_LOG2 3 |
| 713 |
#define REF_FRAMES (1 << REF_FRAMES_LOG2) |
| 714 |
|
| 715 |
#define VP9_KEY_FRAME 0 |
| 716 |
|
| 717 |
VAEncPictureParameterBufferVP9 *pic_param; |
| 718 |
VAEncMiscParameterTypeVP9PerSegmantParam *seg_param = NULL; |
| 719 |
struct vp9_write_bit_buffer *wb, vp9_wb; |
| 720 |
|
| 721 |
if (!encode_state->pic_param_ext || !encode_state->pic_param_ext->buffer) |
| 722 |
return false; |
| 723 |
|
| 724 |
if (!header_data || !header_bitoffset || !header_length) |
| 725 |
return false; |
| 726 |
|
| 727 |
memset(header_bitoffset, 0, sizeof(vp9_header_bitoffset)); |
| 728 |
|
| 729 |
pic_param = (VAEncPictureParameterBufferVP9 *)encode_state->pic_param_ext->buffer; |
| 730 |
|
| 731 |
if (encode_state->q_matrix) |
| 732 |
seg_param = (VAEncMiscParameterTypeVP9PerSegmantParam *) encode_state->q_matrix->buffer; |
| 733 |
|
| 734 |
vp9_wb.bit_buffer = (uint8_t *)header_data; |
| 735 |
vp9_wb.bit_offset = 0; |
| 736 |
wb = &vp9_wb; |
| 737 |
vp9_wb_write_literal(wb, VP9_FRAME_MARKER, 2); |
| 738 |
|
| 739 |
if (codec_profile == VAProfileVP9Profile0) { |
| 740 |
vp9_wb_write_literal(wb, 0, 2); |
| 741 |
} else { |
| 742 |
/* Other VP9Profile1/2/3 will be added later */ |
| 743 |
} |
| 744 |
|
| 745 |
vp9_wb_write_bit(wb, 0); // show_existing_frame |
| 746 |
vp9_wb_write_bit(wb, pic_param->pic_flags.bits.frame_type); |
| 747 |
vp9_wb_write_bit(wb, pic_param->pic_flags.bits.show_frame); |
| 748 |
vp9_wb_write_bit(wb, pic_param->pic_flags.bits.error_resilient_mode); |
| 749 |
|
| 750 |
if (pic_param->pic_flags.bits.frame_type == VP9_KEY_FRAME) { |
| 751 |
vp9_wb_write_literal(wb, VP9_SYNC_CODE_0, 8); |
| 752 |
vp9_wb_write_literal(wb, VP9_SYNC_CODE_1, 8); |
| 753 |
vp9_wb_write_literal(wb, VP9_SYNC_CODE_2, 8); |
| 754 |
|
| 755 |
write_bitdepth_colorspace_sampling(codec_profile, wb); |
| 756 |
|
| 757 |
/* write the encoded frame size */ |
| 758 |
vp9_wb_write_literal(wb, pic_param->frame_width_dst - 1, 16); |
| 759 |
vp9_wb_write_literal(wb, pic_param->frame_height_dst - 1, 16); |
| 760 |
/* write display size */ |
| 761 |
if ((pic_param->frame_width_dst != pic_param->frame_width_src) || |
| 762 |
(pic_param->frame_height_dst != pic_param->frame_height_src)) { |
| 763 |
vp9_wb_write_bit(wb, 1); |
| 764 |
vp9_wb_write_literal(wb, pic_param->frame_width_src - 1, 16); |
| 765 |
vp9_wb_write_literal(wb, pic_param->frame_height_src - 1, 16); |
| 766 |
} else |
| 767 |
vp9_wb_write_bit(wb, 0); |
| 768 |
} else { |
| 769 |
/* for the non-Key frame */ |
| 770 |
if (!pic_param->pic_flags.bits.show_frame) |
| 771 |
vp9_wb_write_bit(wb, pic_param->pic_flags.bits.intra_only); |
| 772 |
|
| 773 |
if (!pic_param->pic_flags.bits.error_resilient_mode) |
| 774 |
vp9_wb_write_literal(wb, pic_param->pic_flags.bits.reset_frame_context, 2); |
| 775 |
|
| 776 |
if (pic_param->pic_flags.bits.intra_only) { |
| 777 |
vp9_wb_write_literal(wb, VP9_SYNC_CODE_0, 8); |
| 778 |
vp9_wb_write_literal(wb, VP9_SYNC_CODE_1, 8); |
| 779 |
vp9_wb_write_literal(wb, VP9_SYNC_CODE_2, 8); |
| 780 |
|
| 781 |
/* Add the bit_depth for VP9Profile1/2/3 */ |
| 782 |
/* write the refreshed_frame_flags */ |
| 783 |
vp9_wb_write_literal(wb, pic_param->refresh_frame_flags, REF_FRAMES); |
| 784 |
/* write the encoded frame size */ |
| 785 |
vp9_wb_write_literal(wb, pic_param->frame_width_dst - 1, 16); |
| 786 |
vp9_wb_write_literal(wb, pic_param->frame_height_dst - 1, 16); |
| 787 |
/* write display size */ |
| 788 |
if ((pic_param->frame_width_dst != pic_param->frame_width_src) || |
| 789 |
(pic_param->frame_height_dst != pic_param->frame_height_src)) { |
| 790 |
vp9_wb_write_bit(wb, 1); |
| 791 |
vp9_wb_write_literal(wb, pic_param->frame_width_src - 1, 16); |
| 792 |
vp9_wb_write_literal(wb, pic_param->frame_height_src - 1, 16); |
| 793 |
} else |
| 794 |
vp9_wb_write_bit(wb, 0); |
| 795 |
|
| 796 |
} else { |
| 797 |
/* The refresh_frame_map is for the next frame so that it can select Last/Godlen/Alt ref_index */ |
| 798 |
/* |
| 799 |
if ((pic_param->ref_flags.bits.ref_frame_ctrl_l0) & (1 << 0)) |
| 800 |
refresh_flags = 1 << pic_param->ref_flags.bits.ref_last_idx; |
| 801 |
if ((pic_param->ref_flags.bits.ref_frame_ctrl_l0) & (1 << 0)) |
| 802 |
refresh_flags = 1 << pic_param->ref_flags.bits.ref_last_idx; |
| 803 |
if ((pic_param->ref_flags.bits.ref_frame_ctrl_l0) & (1 << 0)) |
| 804 |
refresh_flags = 1 << pic_param->ref_flags.bits.ref_last_idx; |
| 805 |
*/ |
| 806 |
vp9_wb_write_literal(wb, pic_param->refresh_frame_flags, REF_FRAMES); |
| 807 |
|
| 808 |
vp9_wb_write_literal(wb, pic_param->ref_flags.bits.ref_last_idx, REF_FRAMES_LOG2); |
| 809 |
vp9_wb_write_bit(wb, pic_param->ref_flags.bits.ref_last_sign_bias); |
| 810 |
vp9_wb_write_literal(wb, pic_param->ref_flags.bits.ref_gf_idx, REF_FRAMES_LOG2); |
| 811 |
vp9_wb_write_bit(wb, pic_param->ref_flags.bits.ref_gf_sign_bias); |
| 812 |
vp9_wb_write_literal(wb, pic_param->ref_flags.bits.ref_arf_idx, REF_FRAMES_LOG2); |
| 813 |
vp9_wb_write_bit(wb, pic_param->ref_flags.bits.ref_arf_sign_bias); |
| 814 |
|
| 815 |
/* write three bits with zero so that it can parse width/height directly */ |
| 816 |
vp9_wb_write_literal(wb, 0, 3); |
| 817 |
vp9_wb_write_literal(wb, pic_param->frame_width_dst - 1, 16); |
| 818 |
vp9_wb_write_literal(wb, pic_param->frame_height_dst - 1, 16); |
| 819 |
|
| 820 |
/* write display size */ |
| 821 |
if ((pic_param->frame_width_dst != pic_param->frame_width_src) || |
| 822 |
(pic_param->frame_height_dst != pic_param->frame_height_src)) { |
| 823 |
|
| 824 |
vp9_wb_write_bit(wb, 1); |
| 825 |
vp9_wb_write_literal(wb, pic_param->frame_width_src - 1, 16); |
| 826 |
vp9_wb_write_literal(wb, pic_param->frame_height_src - 1, 16); |
| 827 |
} else |
| 828 |
vp9_wb_write_bit(wb, 0); |
| 829 |
|
| 830 |
vp9_wb_write_bit(wb, pic_param->pic_flags.bits.allow_high_precision_mv); |
| 831 |
|
| 832 |
#define SWITCHABLE_FILTER 4 |
| 833 |
#define FILTER_MASK 3 |
| 834 |
|
| 835 |
if (pic_param->pic_flags.bits.mcomp_filter_type == SWITCHABLE_FILTER) |
| 836 |
vp9_wb_write_bit(wb, 1); |
| 837 |
else { |
| 838 |
const int filter_to_literal[4] = { 1, 0, 2, 3 }; |
| 839 |
uint8_t filter_flag = pic_param->pic_flags.bits.mcomp_filter_type; |
| 840 |
filter_flag = filter_flag & FILTER_MASK; |
| 841 |
vp9_wb_write_bit(wb, 0); |
| 842 |
vp9_wb_write_literal(wb, filter_to_literal[filter_flag], 2); |
| 843 |
} |
| 844 |
} |
| 845 |
} |
| 846 |
|
| 847 |
/* write refresh_frame_context/paralle frame_decoding */ |
| 848 |
if (!pic_param->pic_flags.bits.error_resilient_mode) { |
| 849 |
vp9_wb_write_bit(wb, pic_param->pic_flags.bits.refresh_frame_context); |
| 850 |
vp9_wb_write_bit(wb, pic_param->pic_flags.bits.frame_parallel_decoding_mode); |
| 851 |
} |
| 852 |
|
| 853 |
vp9_wb_write_literal(wb, pic_param->pic_flags.bits.frame_context_idx, 2); |
| 854 |
|
| 855 |
/* write loop filter */ |
| 856 |
header_bitoffset->bit_offset_lf_level = wb->bit_offset; |
| 857 |
vp9_wb_write_literal(wb, pic_param->filter_level, 6); |
| 858 |
vp9_wb_write_literal(wb, pic_param->sharpness_level, 3); |
| 859 |
|
| 860 |
{ |
| 861 |
int i, mode_flag; |
| 862 |
|
| 863 |
vp9_wb_write_bit(wb, 1); |
| 864 |
vp9_wb_write_bit(wb, 1); |
| 865 |
header_bitoffset->bit_offset_ref_lf_delta = wb->bit_offset; |
| 866 |
for (i = 0; i < 4; i++) { |
| 867 |
/* |
| 868 |
* This check is skipped to prepare the bit_offset_lf_ref |
| 869 |
if (pic_param->ref_lf_delta[i] == 0) { |
| 870 |
vp9_wb_write_bit(wb, 0); |
| 871 |
continue; |
| 872 |
} |
| 873 |
*/ |
| 874 |
|
| 875 |
vp9_wb_write_bit(wb, 1); |
| 876 |
mode_flag = pic_param->ref_lf_delta[i]; |
| 877 |
if (mode_flag >= 0) { |
| 878 |
vp9_wb_write_literal(wb, mode_flag & (0x3F), 6); |
| 879 |
vp9_wb_write_bit(wb, 0); |
| 880 |
} else { |
| 881 |
mode_flag = -mode_flag; |
| 882 |
vp9_wb_write_literal(wb, mode_flag & (0x3F), 6); |
| 883 |
vp9_wb_write_bit(wb, 1); |
| 884 |
} |
| 885 |
} |
| 886 |
|
| 887 |
header_bitoffset->bit_offset_mode_lf_delta = wb->bit_offset; |
| 888 |
for (i = 0; i < 2; i++) { |
| 889 |
/* |
| 890 |
* This check is skipped to prepare the bit_offset_lf_ref |
| 891 |
if (pic_param->mode_lf_delta[i] == 0) { |
| 892 |
vp9_wb_write_bit(wb, 0); |
| 893 |
continue; |
| 894 |
} |
| 895 |
*/ |
| 896 |
vp9_wb_write_bit(wb, 1); |
| 897 |
mode_flag = pic_param->mode_lf_delta[i]; |
| 898 |
if (mode_flag >= 0) { |
| 899 |
vp9_wb_write_literal(wb, mode_flag & (0x3F), 6); |
| 900 |
vp9_wb_write_bit(wb, 0); |
| 901 |
} else { |
| 902 |
mode_flag = -mode_flag; |
| 903 |
vp9_wb_write_literal(wb, mode_flag & (0x3F), 6); |
| 904 |
vp9_wb_write_bit(wb, 1); |
| 905 |
} |
| 906 |
} |
| 907 |
} |
| 908 |
|
| 909 |
/* write basic quantizer */ |
| 910 |
header_bitoffset->bit_offset_qindex = wb->bit_offset; |
| 911 |
vp9_wb_write_literal(wb, pic_param->luma_ac_qindex, 8); |
| 912 |
if (pic_param->luma_dc_qindex_delta) { |
| 913 |
int delta_q = pic_param->luma_dc_qindex_delta; |
| 914 |
vp9_wb_write_bit(wb, 1); |
| 915 |
vp9_wb_write_literal(wb, abs(delta_q), 4); |
| 916 |
vp9_wb_write_bit(wb, delta_q < 0); |
| 917 |
} else |
| 918 |
vp9_wb_write_bit(wb, 0); |
| 919 |
|
| 920 |
if (pic_param->chroma_dc_qindex_delta) { |
| 921 |
int delta_q = pic_param->chroma_dc_qindex_delta; |
| 922 |
vp9_wb_write_bit(wb, 1); |
| 923 |
vp9_wb_write_literal(wb, abs(delta_q), 4); |
| 924 |
vp9_wb_write_bit(wb, delta_q < 0); |
| 925 |
} else |
| 926 |
vp9_wb_write_bit(wb, 0); |
| 927 |
|
| 928 |
if (pic_param->chroma_ac_qindex_delta) { |
| 929 |
int delta_q = pic_param->chroma_ac_qindex_delta; |
| 930 |
vp9_wb_write_bit(wb, 1); |
| 931 |
vp9_wb_write_literal(wb, abs(delta_q), 4); |
| 932 |
vp9_wb_write_bit(wb, delta_q < 0); |
| 933 |
} else |
| 934 |
vp9_wb_write_bit(wb, 0); |
| 935 |
|
| 936 |
vp9_wb_write_bit(wb, pic_param->pic_flags.bits.segmentation_enabled); |
| 937 |
if (pic_param->pic_flags.bits.segmentation_enabled) { |
| 938 |
int i; |
| 939 |
|
| 940 |
#define VP9_MAX_PROB 255 |
| 941 |
vp9_wb_write_bit(wb, pic_param->pic_flags.bits.segmentation_update_map); |
| 942 |
if (pic_param->pic_flags.bits.segmentation_update_map) { |
| 943 |
|
| 944 |
header_bitoffset->bit_offset_segmentation = wb->bit_offset; |
| 945 |
/* write the seg_tree_probs */ |
| 946 |
/* segment_tree_probs/segment_pred_probs are not passed. |
| 947 |
* So the hard-coded prob is writen |
| 948 |
*/ |
| 949 |
for (i = 0; i < 7; i++) { |
| 950 |
vp9_wb_write_bit(wb, 1); |
| 951 |
vp9_wb_write_literal(wb, VP9_MAX_PROB, 8); |
| 952 |
} |
| 953 |
|
| 954 |
vp9_wb_write_bit(wb, pic_param->pic_flags.bits.segmentation_temporal_update); |
| 955 |
if (pic_param->pic_flags.bits.segmentation_temporal_update) { |
| 956 |
for (i = 0; i < 3; i++) { |
| 957 |
vp9_wb_write_bit(wb, 1); |
| 958 |
vp9_wb_write_literal(wb, VP9_MAX_PROB, 8); |
| 959 |
} |
| 960 |
} |
| 961 |
} |
| 962 |
|
| 963 |
/* write the segment_data info */ |
| 964 |
if (seg_param == NULL) { |
| 965 |
vp9_wb_write_bit(wb, 0); |
| 966 |
} else { |
| 967 |
VAEncSegParamVP9 *seg_data; |
| 968 |
int seg_delta; |
| 969 |
|
| 970 |
/* update_data */ |
| 971 |
vp9_wb_write_bit(wb, 1); |
| 972 |
/* abs_delta should be zero */ |
| 973 |
vp9_wb_write_bit(wb, 0); |
| 974 |
for (i = 0; i < 8; i++) { |
| 975 |
seg_data = &seg_param->seg_data[i]; |
| 976 |
|
| 977 |
/* The segment qindex delta */ |
| 978 |
/* This check is skipped */ |
| 979 |
/* if (seg_data->segment_qindex_delta != 0) */ |
| 980 |
if (1) { |
| 981 |
vp9_wb_write_bit(wb, 1); |
| 982 |
seg_delta = seg_data->segment_qindex_delta; |
| 983 |
vp9_wb_write_literal(wb, abs(seg_delta), 8); |
| 984 |
vp9_wb_write_bit(wb, seg_delta < 0); |
| 985 |
} else |
| 986 |
vp9_wb_write_bit(wb, 0); |
| 987 |
|
| 988 |
/* The segment lf delta */ |
| 989 |
/* if (seg_data->segment_lf_level_delta != 0) */ |
| 990 |
if (1) { |
| 991 |
vp9_wb_write_bit(wb, 1); |
| 992 |
seg_delta = seg_data->segment_lf_level_delta; |
| 993 |
vp9_wb_write_literal(wb, abs(seg_delta), 6); |
| 994 |
vp9_wb_write_bit(wb, seg_delta < 0); |
| 995 |
} else |
| 996 |
vp9_wb_write_bit(wb, 0); |
| 997 |
|
| 998 |
/* segment reference flag */ |
| 999 |
vp9_wb_write_bit(wb, seg_data->seg_flags.bits.segment_reference_enabled); |
| 1000 |
if (seg_data->seg_flags.bits.segment_reference_enabled) { |
| 1001 |
vp9_wb_write_literal(wb, seg_data->seg_flags.bits.segment_reference, 2); |
| 1002 |
} |
| 1003 |
|
| 1004 |
/* segment skip flag */ |
| 1005 |
vp9_wb_write_bit(wb, seg_data->seg_flags.bits.segment_reference_skipped); |
| 1006 |
} |
| 1007 |
} |
| 1008 |
} |
| 1009 |
|
| 1010 |
/* write tile info */ |
| 1011 |
{ |
| 1012 |
int sb_cols = (pic_param->frame_width_dst + 63) / 64; |
| 1013 |
int min_log2_tile_cols, max_log2_tile_cols; |
| 1014 |
int col_data; |
| 1015 |
|
| 1016 |
/* write tile column info */ |
| 1017 |
min_log2_tile_cols = get_min_log2_tile_cols(sb_cols); |
| 1018 |
max_log2_tile_cols = get_max_log2_tile_cols(sb_cols); |
| 1019 |
|
| 1020 |
col_data = pic_param->log2_tile_columns - min_log2_tile_cols; |
| 1021 |
while (col_data--) { |
| 1022 |
vp9_wb_write_bit(wb, 1); |
| 1023 |
} |
| 1024 |
if (pic_param->log2_tile_columns < max_log2_tile_cols) |
| 1025 |
vp9_wb_write_bit(wb, 0); |
| 1026 |
|
| 1027 |
/* write tile row info */ |
| 1028 |
vp9_wb_write_bit(wb, pic_param->log2_tile_rows); |
| 1029 |
if (pic_param->log2_tile_rows) |
| 1030 |
vp9_wb_write_bit(wb, (pic_param->log2_tile_rows != 1)); |
| 1031 |
} |
| 1032 |
|
| 1033 |
/* get the bit_offset of the first partition size */ |
| 1034 |
header_bitoffset->bit_offset_first_partition_size = wb->bit_offset; |
| 1035 |
|
| 1036 |
/* reserve the space for writing the first partitions ize */ |
| 1037 |
vp9_wb_write_literal(wb, 0, 16); |
| 1038 |
|
| 1039 |
*header_length = (wb->bit_offset + 7) / 8; |
| 1040 |
|
| 1041 |
return true; |
| 1042 |
} |
| 1043 |
|
| 1044 |
const unsigned short vp9_quant_dc[256] = { |
| 1045 |
4, 8, 8, 9, 10, 11, 12, 12, |
| 1046 |
13, 14, 15, 16, 17, 18, 19, 19, |
| 1047 |
20, 21, 22, 23, 24, 25, 26, 26, |
| 1048 |
27, 28, 29, 30, 31, 32, 32, 33, |
| 1049 |
34, 35, 36, 37, 38, 38, 39, 40, |
| 1050 |
41, 42, 43, 43, 44, 45, 46, 47, |
| 1051 |
48, 48, 49, 50, 51, 52, 53, 53, |
| 1052 |
54, 55, 56, 57, 57, 58, 59, 60, |
| 1053 |
61, 62, 62, 63, 64, 65, 66, 66, |
| 1054 |
67, 68, 69, 70, 70, 71, 72, 73, |
| 1055 |
74, 74, 75, 76, 77, 78, 78, 79, |
| 1056 |
80, 81, 81, 82, 83, 84, 85, 85, |
| 1057 |
87, 88, 90, 92, 93, 95, 96, 98, |
| 1058 |
99, 101, 102, 104, 105, 107, 108, 110, |
| 1059 |
111, 113, 114, 116, 117, 118, 120, 121, |
| 1060 |
123, 125, 127, 129, 131, 134, 136, 138, |
| 1061 |
140, 142, 144, 146, 148, 150, 152, 154, |
| 1062 |
156, 158, 161, 164, 166, 169, 172, 174, |
| 1063 |
177, 180, 182, 185, 187, 190, 192, 195, |
| 1064 |
199, 202, 205, 208, 211, 214, 217, 220, |
| 1065 |
223, 226, 230, 233, 237, 240, 243, 247, |
| 1066 |
250, 253, 257, 261, 265, 269, 272, 276, |
| 1067 |
280, 284, 288, 292, 296, 300, 304, 309, |
| 1068 |
313, 317, 322, 326, 330, 335, 340, 344, |
| 1069 |
349, 354, 359, 364, 369, 374, 379, 384, |
| 1070 |
389, 395, 400, 406, 411, 417, 423, 429, |
| 1071 |
435, 441, 447, 454, 461, 467, 475, 482, |
| 1072 |
489, 497, 505, 513, 522, 530, 539, 549, |
| 1073 |
559, 569, 579, 590, 602, 614, 626, 640, |
| 1074 |
654, 668, 684, 700, 717, 736, 755, 775, |
| 1075 |
796, 819, 843, 869, 896, 925, 955, 988, |
| 1076 |
1022, 1058, 1098, 1139, 1184, 1232, 1282, 1336, |
| 1077 |
}; |
| 1078 |
|
| 1079 |
const unsigned short vp9_quant_ac[256] = { |
| 1080 |
4, 8, 9, 10, 11, 12, 13, 14, |
| 1081 |
15, 16, 17, 18, 19, 20, 21, 22, |
| 1082 |
23, 24, 25, 26, 27, 28, 29, 30, |
| 1083 |
31, 32, 33, 34, 35, 36, 37, 38, |
| 1084 |
39, 40, 41, 42, 43, 44, 45, 46, |
| 1085 |
47, 48, 49, 50, 51, 52, 53, 54, |
| 1086 |
55, 56, 57, 58, 59, 60, 61, 62, |
| 1087 |
63, 64, 65, 66, 67, 68, 69, 70, |
| 1088 |
71, 72, 73, 74, 75, 76, 77, 78, |
| 1089 |
79, 80, 81, 82, 83, 84, 85, 86, |
| 1090 |
87, 88, 89, 90, 91, 92, 93, 94, |
| 1091 |
95, 96, 97, 98, 99, 100, 101, 102, |
| 1092 |
104, 106, 108, 110, 112, 114, 116, 118, |
| 1093 |
120, 122, 124, 126, 128, 130, 132, 134, |
| 1094 |
136, 138, 140, 142, 144, 146, 148, 150, |
| 1095 |
152, 155, 158, 161, 164, 167, 170, 173, |
| 1096 |
176, 179, 182, 185, 188, 191, 194, 197, |
| 1097 |
200, 203, 207, 211, 215, 219, 223, 227, |
| 1098 |
231, 235, 239, 243, 247, 251, 255, 260, |
| 1099 |
265, 270, 275, 280, 285, 290, 295, 300, |
| 1100 |
305, 311, 317, 323, 329, 335, 341, 347, |
| 1101 |
353, 359, 366, 373, 380, 387, 394, 401, |
| 1102 |
408, 416, 424, 432, 440, 448, 456, 465, |
| 1103 |
474, 483, 492, 501, 510, 520, 530, 540, |
| 1104 |
550, 560, 571, 582, 593, 604, 615, 627, |
| 1105 |
639, 651, 663, 676, 689, 702, 715, 729, |
| 1106 |
743, 757, 771, 786, 801, 816, 832, 848, |
| 1107 |
864, 881, 898, 915, 933, 951, 969, 988, |
| 1108 |
1007, 1026, 1046, 1066, 1087, 1108, 1129, 1151, |
| 1109 |
1173, 1196, 1219, 1243, 1267, 1292, 1317, 1343, |
| 1110 |
1369, 1396, 1423, 1451, 1479, 1508, 1537, 1567, |
| 1111 |
1597, 1628, 1660, 1692, 1725, 1759, 1793, 1828, |
| 1112 |
}; |