Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1173)

Side by Side Diff: source/libvpx/vp9/encoder/vp9_bitstream.c

Issue 812033011: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_bitstream.h ('k') | source/libvpx/vp9/encoder/vp9_block.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 16 matching lines...) Expand all
27 27
28 #include "vp9/encoder/vp9_cost.h" 28 #include "vp9/encoder/vp9_cost.h"
29 #include "vp9/encoder/vp9_bitstream.h" 29 #include "vp9/encoder/vp9_bitstream.h"
30 #include "vp9/encoder/vp9_encodemv.h" 30 #include "vp9/encoder/vp9_encodemv.h"
31 #include "vp9/encoder/vp9_mcomp.h" 31 #include "vp9/encoder/vp9_mcomp.h"
32 #include "vp9/encoder/vp9_segmentation.h" 32 #include "vp9/encoder/vp9_segmentation.h"
33 #include "vp9/encoder/vp9_subexp.h" 33 #include "vp9/encoder/vp9_subexp.h"
34 #include "vp9/encoder/vp9_tokenize.h" 34 #include "vp9/encoder/vp9_tokenize.h"
35 #include "vp9/encoder/vp9_write_bit_buffer.h" 35 #include "vp9/encoder/vp9_write_bit_buffer.h"
36 36
37 static struct vp9_token intra_mode_encodings[INTRA_MODES]; 37 static const struct vp9_token intra_mode_encodings[INTRA_MODES] = {
38 static struct vp9_token switchable_interp_encodings[SWITCHABLE_FILTERS]; 38 {0, 1}, {6, 3}, {28, 5}, {30, 5}, {58, 6}, {59, 6}, {126, 7}, {127, 7},
39 static struct vp9_token partition_encodings[PARTITION_TYPES]; 39 {62, 6}, {2, 2}};
40 static struct vp9_token inter_mode_encodings[INTER_MODES]; 40 static const struct vp9_token switchable_interp_encodings[SWITCHABLE_FILTERS] =
41 41 {{0, 1}, {2, 2}, {3, 2}};
42 void vp9_entropy_mode_init() { 42 static const struct vp9_token partition_encodings[PARTITION_TYPES] =
43 vp9_tokens_from_tree(intra_mode_encodings, vp9_intra_mode_tree); 43 {{0, 1}, {2, 2}, {6, 3}, {7, 3}};
44 vp9_tokens_from_tree(switchable_interp_encodings, vp9_switchable_interp_tree); 44 static const struct vp9_token inter_mode_encodings[INTER_MODES] =
45 vp9_tokens_from_tree(partition_encodings, vp9_partition_tree); 45 {{2, 2}, {6, 3}, {0, 1}, {7, 3}};
46 vp9_tokens_from_tree(inter_mode_encodings, vp9_inter_mode_tree);
47 }
48 46
49 static void write_intra_mode(vp9_writer *w, PREDICTION_MODE mode, 47 static void write_intra_mode(vp9_writer *w, PREDICTION_MODE mode,
50 const vp9_prob *probs) { 48 const vp9_prob *probs) {
51 vp9_write_token(w, vp9_intra_mode_tree, probs, &intra_mode_encodings[mode]); 49 vp9_write_token(w, vp9_intra_mode_tree, probs, &intra_mode_encodings[mode]);
52 } 50 }
53 51
54 static void write_inter_mode(vp9_writer *w, PREDICTION_MODE mode, 52 static void write_inter_mode(vp9_writer *w, PREDICTION_MODE mode,
55 const vp9_prob *probs) { 53 const vp9_prob *probs) {
56 assert(is_inter_mode(mode)); 54 assert(is_inter_mode(mode));
57 vp9_write_token(w, vp9_inter_mode_tree, probs, 55 vp9_write_token(w, vp9_inter_mode_tree, probs,
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 write_intra_mode(w, mbmi->uv_mode, cm->fc->uv_mode_prob[mode]); 290 write_intra_mode(w, mbmi->uv_mode, cm->fc->uv_mode_prob[mode]);
293 } else { 291 } else {
294 const int mode_ctx = mbmi->mode_context[mbmi->ref_frame[0]]; 292 const int mode_ctx = mbmi->mode_context[mbmi->ref_frame[0]];
295 const vp9_prob *const inter_probs = cm->fc->inter_mode_probs[mode_ctx]; 293 const vp9_prob *const inter_probs = cm->fc->inter_mode_probs[mode_ctx];
296 write_ref_frames(cm, xd, w); 294 write_ref_frames(cm, xd, w);
297 295
298 // If segment skip is not enabled code the mode. 296 // If segment skip is not enabled code the mode.
299 if (!vp9_segfeature_active(seg, segment_id, SEG_LVL_SKIP)) { 297 if (!vp9_segfeature_active(seg, segment_id, SEG_LVL_SKIP)) {
300 if (bsize >= BLOCK_8X8) { 298 if (bsize >= BLOCK_8X8) {
301 write_inter_mode(w, mode, inter_probs); 299 write_inter_mode(w, mode, inter_probs);
302 ++cpi->td.counts->inter_mode[mode_ctx][INTER_OFFSET(mode)];
303 } 300 }
304 } 301 }
305 302
306 if (cm->interp_filter == SWITCHABLE) { 303 if (cm->interp_filter == SWITCHABLE) {
307 const int ctx = vp9_get_pred_context_switchable_interp(xd); 304 const int ctx = vp9_get_pred_context_switchable_interp(xd);
308 vp9_write_token(w, vp9_switchable_interp_tree, 305 vp9_write_token(w, vp9_switchable_interp_tree,
309 cm->fc->switchable_interp_prob[ctx], 306 cm->fc->switchable_interp_prob[ctx],
310 &switchable_interp_encodings[mbmi->interp_filter]); 307 &switchable_interp_encodings[mbmi->interp_filter]);
311 ++cpi->interp_filter_selected[0][mbmi->interp_filter]; 308 ++cpi->interp_filter_selected[0][mbmi->interp_filter];
312 } else { 309 } else {
313 assert(mbmi->interp_filter == cm->interp_filter); 310 assert(mbmi->interp_filter == cm->interp_filter);
314 } 311 }
315 312
316 if (bsize < BLOCK_8X8) { 313 if (bsize < BLOCK_8X8) {
317 const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize]; 314 const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize];
318 const int num_4x4_h = num_4x4_blocks_high_lookup[bsize]; 315 const int num_4x4_h = num_4x4_blocks_high_lookup[bsize];
319 int idx, idy; 316 int idx, idy;
320 for (idy = 0; idy < 2; idy += num_4x4_h) { 317 for (idy = 0; idy < 2; idy += num_4x4_h) {
321 for (idx = 0; idx < 2; idx += num_4x4_w) { 318 for (idx = 0; idx < 2; idx += num_4x4_w) {
322 const int j = idy * 2 + idx; 319 const int j = idy * 2 + idx;
323 const PREDICTION_MODE b_mode = mi->bmi[j].as_mode; 320 const PREDICTION_MODE b_mode = mi->bmi[j].as_mode;
324 write_inter_mode(w, b_mode, inter_probs); 321 write_inter_mode(w, b_mode, inter_probs);
325 ++cpi->td.counts->inter_mode[mode_ctx][INTER_OFFSET(b_mode)];
326 if (b_mode == NEWMV) { 322 if (b_mode == NEWMV) {
327 for (ref = 0; ref < 1 + is_compound; ++ref) 323 for (ref = 0; ref < 1 + is_compound; ++ref)
328 vp9_encode_mv(cpi, w, &mi->bmi[j].as_mv[ref].as_mv, 324 vp9_encode_mv(cpi, w, &mi->bmi[j].as_mv[ref].as_mv,
329 &mbmi->ref_mvs[mbmi->ref_frame[ref]][0].as_mv, 325 &mbmi->ref_mvs[mbmi->ref_frame[ref]][0].as_mv,
330 nmvc, allow_hp); 326 nmvc, allow_hp);
331 } 327 }
332 } 328 }
333 } 329 }
334 } else { 330 } else {
335 if (mode == NEWMV) { 331 if (mode == NEWMV) {
336 for (ref = 0; ref < 1 + is_compound; ++ref) 332 for (ref = 0; ref < 1 + is_compound; ++ref)
337 vp9_encode_mv(cpi, w, &mbmi->mv[ref].as_mv, 333 vp9_encode_mv(cpi, w, &mbmi->mv[ref].as_mv,
338 &mbmi->ref_mvs[mbmi->ref_frame[ref]][0].as_mv, nmvc, 334 &mbmi->ref_mvs[mbmi->ref_frame[ref]][0].as_mv, nmvc,
339 allow_hp); 335 allow_hp);
340 } 336 }
341 } 337 }
342 } 338 }
343 } 339 }
344 340
345 static void write_mb_modes_kf(const VP9_COMMON *cm, const MACROBLOCKD *xd, 341 static void write_mb_modes_kf(const VP9_COMMON *cm, const MACROBLOCKD *xd,
346 MODE_INFO *mi_8x8, vp9_writer *w) { 342 MODE_INFO *mi_8x8, vp9_writer *w) {
347 const struct segmentation *const seg = &cm->seg; 343 const struct segmentation *const seg = &cm->seg;
348 const MODE_INFO *const mi = mi_8x8; 344 const MODE_INFO *const mi = mi_8x8;
349 const MODE_INFO *const above_mi = mi_8x8[-xd->mi_stride].src_mi; 345 const MODE_INFO *const above_mi = xd->above_mi;
350 const MODE_INFO *const left_mi = 346 const MODE_INFO *const left_mi = xd->left_mi;
351 xd->left_available ? mi_8x8[-1].src_mi : NULL;
352 const MB_MODE_INFO *const mbmi = &mi->mbmi; 347 const MB_MODE_INFO *const mbmi = &mi->mbmi;
353 const BLOCK_SIZE bsize = mbmi->sb_type; 348 const BLOCK_SIZE bsize = mbmi->sb_type;
354 349
355 if (seg->update_map) 350 if (seg->update_map)
356 write_segment_id(w, seg, mbmi->segment_id); 351 write_segment_id(w, seg, mbmi->segment_id);
357 352
358 write_skip(cm, xd, mbmi->segment_id, mi, w); 353 write_skip(cm, xd, mbmi->segment_id, mi, w);
359 354
360 if (bsize >= BLOCK_8X8 && cm->tx_mode == TX_MODE_SELECT) 355 if (bsize >= BLOCK_8X8 && cm->tx_mode == TX_MODE_SELECT)
361 write_selected_tx_size(cm, xd, w); 356 write_selected_tx_size(cm, xd, w);
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 update_coef_probs(cpi, &header_bc); 1163 update_coef_probs(cpi, &header_bc);
1169 update_skip_probs(cm, &header_bc, counts); 1164 update_skip_probs(cm, &header_bc, counts);
1170 1165
1171 if (!frame_is_intra_only(cm)) { 1166 if (!frame_is_intra_only(cm)) {
1172 int i; 1167 int i;
1173 1168
1174 for (i = 0; i < INTER_MODE_CONTEXTS; ++i) 1169 for (i = 0; i < INTER_MODE_CONTEXTS; ++i)
1175 prob_diff_update(vp9_inter_mode_tree, cm->fc->inter_mode_probs[i], 1170 prob_diff_update(vp9_inter_mode_tree, cm->fc->inter_mode_probs[i],
1176 counts->inter_mode[i], INTER_MODES, &header_bc); 1171 counts->inter_mode[i], INTER_MODES, &header_bc);
1177 1172
1178 vp9_zero(counts->inter_mode);
1179
1180 if (cm->interp_filter == SWITCHABLE) 1173 if (cm->interp_filter == SWITCHABLE)
1181 update_switchable_interp_probs(cm, &header_bc, counts); 1174 update_switchable_interp_probs(cm, &header_bc, counts);
1182 1175
1183 for (i = 0; i < INTRA_INTER_CONTEXTS; i++) 1176 for (i = 0; i < INTRA_INTER_CONTEXTS; i++)
1184 vp9_cond_prob_diff_update(&header_bc, &fc->intra_inter_prob[i], 1177 vp9_cond_prob_diff_update(&header_bc, &fc->intra_inter_prob[i],
1185 counts->intra_inter[i]); 1178 counts->intra_inter[i]);
1186 1179
1187 if (cm->allow_comp_inter_inter) { 1180 if (cpi->allow_comp_inter_inter) {
1188 const int use_compound_pred = cm->reference_mode != SINGLE_REFERENCE; 1181 const int use_compound_pred = cm->reference_mode != SINGLE_REFERENCE;
1189 const int use_hybrid_pred = cm->reference_mode == REFERENCE_MODE_SELECT; 1182 const int use_hybrid_pred = cm->reference_mode == REFERENCE_MODE_SELECT;
1190 1183
1191 vp9_write_bit(&header_bc, use_compound_pred); 1184 vp9_write_bit(&header_bc, use_compound_pred);
1192 if (use_compound_pred) { 1185 if (use_compound_pred) {
1193 vp9_write_bit(&header_bc, use_hybrid_pred); 1186 vp9_write_bit(&header_bc, use_hybrid_pred);
1194 if (use_hybrid_pred) 1187 if (use_hybrid_pred)
1195 for (i = 0; i < COMP_INTER_CONTEXTS; i++) 1188 for (i = 0; i < COMP_INTER_CONTEXTS; i++)
1196 vp9_cond_prob_diff_update(&header_bc, &fc->comp_inter_prob[i], 1189 vp9_cond_prob_diff_update(&header_bc, &fc->comp_inter_prob[i],
1197 counts->comp_inter[i]); 1190 counts->comp_inter[i]);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 1240
1248 first_part_size = write_compressed_header(cpi, data); 1241 first_part_size = write_compressed_header(cpi, data);
1249 data += first_part_size; 1242 data += first_part_size;
1250 // TODO(jbb): Figure out what to do if first_part_size > 16 bits. 1243 // TODO(jbb): Figure out what to do if first_part_size > 16 bits.
1251 vp9_wb_write_literal(&saved_wb, (int)first_part_size, 16); 1244 vp9_wb_write_literal(&saved_wb, (int)first_part_size, 16);
1252 1245
1253 data += encode_tiles(cpi, data); 1246 data += encode_tiles(cpi, data);
1254 1247
1255 *size = data - dest; 1248 *size = data - dest;
1256 } 1249 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_bitstream.h ('k') | source/libvpx/vp9/encoder/vp9_block.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698