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

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

Issue 1217053002: libvpx: Pull from upstream (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libvpx.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_avg.c ('k') | source/libvpx/vp9/encoder/vp9_encodeframe.c » ('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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 vp9_write(w, tx_size != TX_4X4, tx_probs[0]); 86 vp9_write(w, tx_size != TX_4X4, tx_probs[0]);
87 if (tx_size != TX_4X4 && max_tx_size >= TX_16X16) { 87 if (tx_size != TX_4X4 && max_tx_size >= TX_16X16) {
88 vp9_write(w, tx_size != TX_8X8, tx_probs[1]); 88 vp9_write(w, tx_size != TX_8X8, tx_probs[1]);
89 if (tx_size != TX_8X8 && max_tx_size >= TX_32X32) 89 if (tx_size != TX_8X8 && max_tx_size >= TX_32X32)
90 vp9_write(w, tx_size != TX_16X16, tx_probs[2]); 90 vp9_write(w, tx_size != TX_16X16, tx_probs[2]);
91 } 91 }
92 } 92 }
93 93
94 static int write_skip(const VP9_COMMON *cm, const MACROBLOCKD *xd, 94 static int write_skip(const VP9_COMMON *cm, const MACROBLOCKD *xd,
95 int segment_id, const MODE_INFO *mi, vp9_writer *w) { 95 int segment_id, const MODE_INFO *mi, vp9_writer *w) {
96 if (vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)) { 96 if (segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)) {
97 return 1; 97 return 1;
98 } else { 98 } else {
99 const int skip = mi->mbmi.skip; 99 const int skip = mi->mbmi.skip;
100 vp9_write(w, skip, vp9_get_skip_prob(cm, xd)); 100 vp9_write(w, skip, vp9_get_skip_prob(cm, xd));
101 return skip; 101 return skip;
102 } 102 }
103 } 103 }
104 104
105 static void update_skip_probs(VP9_COMMON *cm, vp9_writer *w, 105 static void update_skip_probs(VP9_COMMON *cm, vp9_writer *w,
106 FRAME_COUNTS *counts) { 106 FRAME_COUNTS *counts) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 200
201 // This function encodes the reference frame 201 // This function encodes the reference frame
202 static void write_ref_frames(const VP9_COMMON *cm, const MACROBLOCKD *xd, 202 static void write_ref_frames(const VP9_COMMON *cm, const MACROBLOCKD *xd,
203 vp9_writer *w) { 203 vp9_writer *w) {
204 const MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; 204 const MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
205 const int is_compound = has_second_ref(mbmi); 205 const int is_compound = has_second_ref(mbmi);
206 const int segment_id = mbmi->segment_id; 206 const int segment_id = mbmi->segment_id;
207 207
208 // If segment level coding of this signal is disabled... 208 // If segment level coding of this signal is disabled...
209 // or the segment allows multiple reference frame options 209 // or the segment allows multiple reference frame options
210 if (vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) { 210 if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) {
211 assert(!is_compound); 211 assert(!is_compound);
212 assert(mbmi->ref_frame[0] == 212 assert(mbmi->ref_frame[0] ==
213 vp9_get_segdata(&cm->seg, segment_id, SEG_LVL_REF_FRAME)); 213 get_segdata(&cm->seg, segment_id, SEG_LVL_REF_FRAME));
214 } else { 214 } else {
215 // does the feature use compound prediction or not 215 // does the feature use compound prediction or not
216 // (if not specified at the frame/segment level) 216 // (if not specified at the frame/segment level)
217 if (cm->reference_mode == REFERENCE_MODE_SELECT) { 217 if (cm->reference_mode == REFERENCE_MODE_SELECT) {
218 vp9_write(w, is_compound, vp9_get_reference_mode_prob(cm, xd)); 218 vp9_write(w, is_compound, vp9_get_reference_mode_prob(cm, xd));
219 } else { 219 } else {
220 assert(!is_compound == (cm->reference_mode == SINGLE_REFERENCE)); 220 assert(!is_compound == (cm->reference_mode == SINGLE_REFERENCE));
221 } 221 }
222 222
223 if (is_compound) { 223 if (is_compound) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 vp9_write(w, pred_flag, pred_prob); 257 vp9_write(w, pred_flag, pred_prob);
258 if (!pred_flag) 258 if (!pred_flag)
259 write_segment_id(w, seg, segment_id); 259 write_segment_id(w, seg, segment_id);
260 } else { 260 } else {
261 write_segment_id(w, seg, segment_id); 261 write_segment_id(w, seg, segment_id);
262 } 262 }
263 } 263 }
264 264
265 skip = write_skip(cm, xd, segment_id, mi, w); 265 skip = write_skip(cm, xd, segment_id, mi, w);
266 266
267 if (!vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) 267 if (!segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME))
268 vp9_write(w, is_inter, vp9_get_intra_inter_prob(cm, xd)); 268 vp9_write(w, is_inter, vp9_get_intra_inter_prob(cm, xd));
269 269
270 if (bsize >= BLOCK_8X8 && cm->tx_mode == TX_MODE_SELECT && 270 if (bsize >= BLOCK_8X8 && cm->tx_mode == TX_MODE_SELECT &&
271 !(is_inter && skip)) { 271 !(is_inter && skip)) {
272 write_selected_tx_size(cm, xd, w); 272 write_selected_tx_size(cm, xd, w);
273 } 273 }
274 274
275 if (!is_inter) { 275 if (!is_inter) {
276 if (bsize >= BLOCK_8X8) { 276 if (bsize >= BLOCK_8X8) {
277 write_intra_mode(w, mode, cm->fc->y_mode_prob[size_group_lookup[bsize]]); 277 write_intra_mode(w, mode, cm->fc->y_mode_prob[size_group_lookup[bsize]]);
278 } else { 278 } else {
279 int idx, idy; 279 int idx, idy;
280 const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize]; 280 const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize];
281 const int num_4x4_h = num_4x4_blocks_high_lookup[bsize]; 281 const int num_4x4_h = num_4x4_blocks_high_lookup[bsize];
282 for (idy = 0; idy < 2; idy += num_4x4_h) { 282 for (idy = 0; idy < 2; idy += num_4x4_h) {
283 for (idx = 0; idx < 2; idx += num_4x4_w) { 283 for (idx = 0; idx < 2; idx += num_4x4_w) {
284 const PREDICTION_MODE b_mode = mi->bmi[idy * 2 + idx].as_mode; 284 const PREDICTION_MODE b_mode = mi->bmi[idy * 2 + idx].as_mode;
285 write_intra_mode(w, b_mode, cm->fc->y_mode_prob[0]); 285 write_intra_mode(w, b_mode, cm->fc->y_mode_prob[0]);
286 } 286 }
287 } 287 }
288 } 288 }
289 write_intra_mode(w, mbmi->uv_mode, cm->fc->uv_mode_prob[mode]); 289 write_intra_mode(w, mbmi->uv_mode, cm->fc->uv_mode_prob[mode]);
290 } else { 290 } else {
291 const int mode_ctx = mbmi->mode_context[mbmi->ref_frame[0]]; 291 const int mode_ctx = mbmi->mode_context[mbmi->ref_frame[0]];
292 const vp9_prob *const inter_probs = cm->fc->inter_mode_probs[mode_ctx]; 292 const vp9_prob *const inter_probs = cm->fc->inter_mode_probs[mode_ctx];
293 write_ref_frames(cm, xd, w); 293 write_ref_frames(cm, xd, w);
294 294
295 // If segment skip is not enabled code the mode. 295 // If segment skip is not enabled code the mode.
296 if (!vp9_segfeature_active(seg, segment_id, SEG_LVL_SKIP)) { 296 if (!segfeature_active(seg, segment_id, SEG_LVL_SKIP)) {
297 if (bsize >= BLOCK_8X8) { 297 if (bsize >= BLOCK_8X8) {
298 write_inter_mode(w, mode, inter_probs); 298 write_inter_mode(w, mode, inter_probs);
299 } 299 }
300 } 300 }
301 301
302 if (cm->interp_filter == SWITCHABLE) { 302 if (cm->interp_filter == SWITCHABLE) {
303 const int ctx = vp9_get_pred_context_switchable_interp(xd); 303 const int ctx = vp9_get_pred_context_switchable_interp(xd);
304 vp9_write_token(w, vp9_switchable_interp_tree, 304 vp9_write_token(w, vp9_switchable_interp_tree,
305 cm->fc->switchable_interp_prob[ctx], 305 cm->fc->switchable_interp_prob[ctx],
306 &switchable_interp_encodings[mbmi->interp_filter]); 306 &switchable_interp_encodings[mbmi->interp_filter]);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 396
397 assert(*tok < tok_end); 397 assert(*tok < tok_end);
398 pack_mb_tokens(w, tok, tok_end, cm->bit_depth); 398 pack_mb_tokens(w, tok, tok_end, cm->bit_depth);
399 } 399 }
400 400
401 static void write_partition(const VP9_COMMON *const cm, 401 static void write_partition(const VP9_COMMON *const cm,
402 const MACROBLOCKD *const xd, 402 const MACROBLOCKD *const xd,
403 int hbs, int mi_row, int mi_col, 403 int hbs, int mi_row, int mi_col,
404 PARTITION_TYPE p, BLOCK_SIZE bsize, vp9_writer *w) { 404 PARTITION_TYPE p, BLOCK_SIZE bsize, vp9_writer *w) {
405 const int ctx = partition_plane_context(xd, mi_row, mi_col, bsize); 405 const int ctx = partition_plane_context(xd, mi_row, mi_col, bsize);
406 const vp9_prob *const probs = get_partition_probs(cm, ctx); 406 const vp9_prob *const probs = xd->partition_probs[ctx];
407 const int has_rows = (mi_row + hbs) < cm->mi_rows; 407 const int has_rows = (mi_row + hbs) < cm->mi_rows;
408 const int has_cols = (mi_col + hbs) < cm->mi_cols; 408 const int has_cols = (mi_col + hbs) < cm->mi_cols;
409 409
410 if (has_rows && has_cols) { 410 if (has_rows && has_cols) {
411 vp9_write_token(w, vp9_partition_tree, probs, &partition_encodings[p]); 411 vp9_write_token(w, vp9_partition_tree, probs, &partition_encodings[p]);
412 } else if (!has_rows && has_cols) { 412 } else if (!has_rows && has_cols) {
413 assert(p == PARTITION_SPLIT || p == PARTITION_HORZ); 413 assert(p == PARTITION_SPLIT || p == PARTITION_HORZ);
414 vp9_write(w, p == PARTITION_SPLIT, probs[1]); 414 vp9_write(w, p == PARTITION_SPLIT, probs[1]);
415 } else if (has_rows && !has_cols) { 415 } else if (has_rows && !has_cols) {
416 assert(p == PARTITION_SPLIT || p == PARTITION_VERT); 416 assert(p == PARTITION_SPLIT || p == PARTITION_VERT);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 474
475 // update partition context 475 // update partition context
476 if (bsize >= BLOCK_8X8 && 476 if (bsize >= BLOCK_8X8 &&
477 (bsize == BLOCK_8X8 || partition != PARTITION_SPLIT)) 477 (bsize == BLOCK_8X8 || partition != PARTITION_SPLIT))
478 update_partition_context(xd, mi_row, mi_col, subsize, bsize); 478 update_partition_context(xd, mi_row, mi_col, subsize, bsize);
479 } 479 }
480 480
481 static void write_modes(VP9_COMP *cpi, 481 static void write_modes(VP9_COMP *cpi,
482 const TileInfo *const tile, vp9_writer *w, 482 const TileInfo *const tile, vp9_writer *w,
483 TOKENEXTRA **tok, const TOKENEXTRA *const tok_end) { 483 TOKENEXTRA **tok, const TOKENEXTRA *const tok_end) {
484 const VP9_COMMON *const cm = &cpi->common;
484 MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; 485 MACROBLOCKD *const xd = &cpi->td.mb.e_mbd;
485 int mi_row, mi_col; 486 int mi_row, mi_col;
486 487
488 set_partition_probs(cm, xd);
489
487 for (mi_row = tile->mi_row_start; mi_row < tile->mi_row_end; 490 for (mi_row = tile->mi_row_start; mi_row < tile->mi_row_end;
488 mi_row += MI_BLOCK_SIZE) { 491 mi_row += MI_BLOCK_SIZE) {
489 vp9_zero(xd->left_seg_context); 492 vp9_zero(xd->left_seg_context);
490 for (mi_col = tile->mi_col_start; mi_col < tile->mi_col_end; 493 for (mi_col = tile->mi_col_start; mi_col < tile->mi_col_end;
491 mi_col += MI_BLOCK_SIZE) 494 mi_col += MI_BLOCK_SIZE)
492 write_modes_sb(cpi, tile, w, tok, tok_end, mi_row, mi_col, 495 write_modes_sb(cpi, tile, w, tok, tok_end, mi_row, mi_col,
493 BLOCK_64X64); 496 BLOCK_64X64);
494 } 497 }
495 } 498 }
496 499
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 } 783 }
781 } 784 }
782 785
783 // Segmentation data 786 // Segmentation data
784 vp9_wb_write_bit(wb, seg->update_data); 787 vp9_wb_write_bit(wb, seg->update_data);
785 if (seg->update_data) { 788 if (seg->update_data) {
786 vp9_wb_write_bit(wb, seg->abs_delta); 789 vp9_wb_write_bit(wb, seg->abs_delta);
787 790
788 for (i = 0; i < MAX_SEGMENTS; i++) { 791 for (i = 0; i < MAX_SEGMENTS; i++) {
789 for (j = 0; j < SEG_LVL_MAX; j++) { 792 for (j = 0; j < SEG_LVL_MAX; j++) {
790 const int active = vp9_segfeature_active(seg, i, j); 793 const int active = segfeature_active(seg, i, j);
791 vp9_wb_write_bit(wb, active); 794 vp9_wb_write_bit(wb, active);
792 if (active) { 795 if (active) {
793 const int data = vp9_get_segdata(seg, i, j); 796 const int data = get_segdata(seg, i, j);
794 const int data_max = vp9_seg_feature_data_max(j); 797 const int data_max = vp9_seg_feature_data_max(j);
795 798
796 if (vp9_is_segfeature_signed(j)) { 799 if (vp9_is_segfeature_signed(j)) {
797 encode_unsigned_max(wb, abs(data), data_max); 800 encode_unsigned_max(wb, abs(data), data_max);
798 vp9_wb_write_bit(wb, data < 0); 801 vp9_wb_write_bit(wb, data < 0);
799 } else { 802 } else {
800 encode_unsigned_max(wb, data, data_max); 803 encode_unsigned_max(wb, data, data_max);
801 } 804 }
802 } 805 }
803 } 806 }
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 1240
1238 first_part_size = write_compressed_header(cpi, data); 1241 first_part_size = write_compressed_header(cpi, data);
1239 data += first_part_size; 1242 data += first_part_size;
1240 // 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.
1241 vp9_wb_write_literal(&saved_wb, (int)first_part_size, 16); 1244 vp9_wb_write_literal(&saved_wb, (int)first_part_size, 16);
1242 1245
1243 data += encode_tiles(cpi, data); 1246 data += encode_tiles(cpi, data);
1244 1247
1245 *size = data - dest; 1248 *size = data - dest;
1246 } 1249 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_avg.c ('k') | source/libvpx/vp9/encoder/vp9_encodeframe.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698