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

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

Issue 1302353004: libvpx: Pull from upstream (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libvpx.git@master
Patch Set: Created 5 years, 3 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_ssim.c ('k') | source/libvpx/vp9/encoder/vp9_temporal_filter.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) 2014 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2014 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
11 #include <math.h> 11 #include <math.h>
12 12
13 #include "vp9/encoder/vp9_encoder.h" 13 #include "vp9/encoder/vp9_encoder.h"
14 #include "vp9/encoder/vp9_svc_layercontext.h" 14 #include "vp9/encoder/vp9_svc_layercontext.h"
15 #include "vp9/encoder/vp9_extend.h" 15 #include "vp9/encoder/vp9_extend.h"
16 16
17 #define SMALL_FRAME_FB_IDX 7 17 #define SMALL_FRAME_FB_IDX 7
18 #define SMALL_FRAME_WIDTH 16 18 #define SMALL_FRAME_WIDTH 32
19 #define SMALL_FRAME_HEIGHT 16 19 #define SMALL_FRAME_HEIGHT 16
20 20
21 void vp9_init_layer_context(VP9_COMP *const cpi) { 21 void vp9_init_layer_context(VP9_COMP *const cpi) {
22 SVC *const svc = &cpi->svc; 22 SVC *const svc = &cpi->svc;
23 const VP9EncoderConfig *const oxcf = &cpi->oxcf; 23 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
24 int sl, tl; 24 int sl, tl;
25 int alt_ref_idx = svc->number_spatial_layers; 25 int alt_ref_idx = svc->number_spatial_layers;
26 26
27 svc->spatial_layer_id = 0; 27 svc->spatial_layer_id = 0;
28 svc->temporal_layer_id = 0; 28 svc->temporal_layer_id = 0;
29 29
30 if (cpi->oxcf.error_resilient_mode == 0 && cpi->oxcf.pass == 2) { 30 if (cpi->oxcf.error_resilient_mode == 0 && cpi->oxcf.pass == 2) {
31 if (vp9_realloc_frame_buffer(&cpi->svc.empty_frame.img, 31 if (vpx_realloc_frame_buffer(&cpi->svc.empty_frame.img,
32 SMALL_FRAME_WIDTH, SMALL_FRAME_HEIGHT, 32 SMALL_FRAME_WIDTH, SMALL_FRAME_HEIGHT,
33 cpi->common.subsampling_x, 33 cpi->common.subsampling_x,
34 cpi->common.subsampling_y, 34 cpi->common.subsampling_y,
35 #if CONFIG_VP9_HIGHBITDEPTH 35 #if CONFIG_VP9_HIGHBITDEPTH
36 cpi->common.use_highbitdepth, 36 cpi->common.use_highbitdepth,
37 #endif 37 #endif
38 VP9_ENC_BORDER_IN_PIXELS, 38 VP9_ENC_BORDER_IN_PIXELS,
39 cpi->common.byte_alignment, 39 cpi->common.byte_alignment,
40 NULL, NULL, NULL)) 40 NULL, NULL, NULL))
41 vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR, 41 vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 void vp9_update_layer_context_change_config(VP9_COMP *const cpi, 106 void vp9_update_layer_context_change_config(VP9_COMP *const cpi,
107 const int target_bandwidth) { 107 const int target_bandwidth) {
108 SVC *const svc = &cpi->svc; 108 SVC *const svc = &cpi->svc;
109 const VP9EncoderConfig *const oxcf = &cpi->oxcf; 109 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
110 const RATE_CONTROL *const rc = &cpi->rc; 110 const RATE_CONTROL *const rc = &cpi->rc;
111 int sl, tl, layer = 0, spatial_layer_target; 111 int sl, tl, layer = 0, spatial_layer_target;
112 float bitrate_alloc = 1.0; 112 float bitrate_alloc = 1.0;
113 113
114 if (svc->temporal_layering_mode != VP9E_TEMPORAL_LAYERING_MODE_NOLAYERING) { 114 if (svc->temporal_layering_mode != VP9E_TEMPORAL_LAYERING_MODE_NOLAYERING) {
115 for (sl = 0; sl < oxcf->ss_number_layers; ++sl) { 115 for (sl = 0; sl < oxcf->ss_number_layers; ++sl) {
116 spatial_layer_target = 0;
117
118 for (tl = 0; tl < oxcf->ts_number_layers; ++tl) { 116 for (tl = 0; tl < oxcf->ts_number_layers; ++tl) {
119 layer = LAYER_IDS_TO_IDX(sl, tl, oxcf->ts_number_layers); 117 layer = LAYER_IDS_TO_IDX(sl, tl, oxcf->ts_number_layers);
120 svc->layer_context[layer].target_bandwidth = 118 svc->layer_context[layer].target_bandwidth =
121 oxcf->layer_target_bitrate[layer]; 119 oxcf->layer_target_bitrate[layer];
122 } 120 }
123 121
124 layer = LAYER_IDS_TO_IDX(sl, ((oxcf->ts_number_layers - 1) < 0 ? 122 layer = LAYER_IDS_TO_IDX(sl, ((oxcf->ts_number_layers - 1) < 0 ?
125 0 : (oxcf->ts_number_layers - 1)), oxcf->ts_number_layers); 123 0 : (oxcf->ts_number_layers - 1)), oxcf->ts_number_layers);
126 spatial_layer_target = 124 spatial_layer_target =
127 svc->layer_context[layer].target_bandwidth = 125 svc->layer_context[layer].target_bandwidth =
128 oxcf->layer_target_bitrate[layer]; 126 oxcf->layer_target_bitrate[layer];
129 127
130 for (tl = 0; tl < oxcf->ts_number_layers; ++tl) { 128 for (tl = 0; tl < oxcf->ts_number_layers; ++tl) {
131 LAYER_CONTEXT *const lc = 129 LAYER_CONTEXT *const lc =
132 &svc->layer_context[sl * oxcf->ts_number_layers + tl]; 130 &svc->layer_context[sl * oxcf->ts_number_layers + tl];
133 RATE_CONTROL *const lrc = &lc->rc; 131 RATE_CONTROL *const lrc = &lc->rc;
134 132
135 lc->spatial_layer_target_bandwidth = spatial_layer_target; 133 lc->spatial_layer_target_bandwidth = spatial_layer_target;
136 bitrate_alloc = (float)lc->target_bandwidth / spatial_layer_target; 134 bitrate_alloc = (float)lc->target_bandwidth / spatial_layer_target;
137 lrc->starting_buffer_level = 135 lrc->starting_buffer_level =
138 (int64_t)(rc->starting_buffer_level * bitrate_alloc); 136 (int64_t)(rc->starting_buffer_level * bitrate_alloc);
139 lrc->optimal_buffer_level = 137 lrc->optimal_buffer_level =
140 (int64_t)(rc->optimal_buffer_level * bitrate_alloc); 138 (int64_t)(rc->optimal_buffer_level * bitrate_alloc);
141 lrc->maximum_buffer_size = 139 lrc->maximum_buffer_size =
142 (int64_t)(rc->maximum_buffer_size * bitrate_alloc); 140 (int64_t)(rc->maximum_buffer_size * bitrate_alloc);
143 lrc->bits_off_target = 141 lrc->bits_off_target =
144 MIN(lrc->bits_off_target, lrc->maximum_buffer_size); 142 VPXMIN(lrc->bits_off_target, lrc->maximum_buffer_size);
145 lrc->buffer_level = MIN(lrc->buffer_level, lrc->maximum_buffer_size); 143 lrc->buffer_level = VPXMIN(lrc->buffer_level, lrc->maximum_buffer_size);
146 lc->framerate = cpi->framerate / oxcf->ts_rate_decimator[tl]; 144 lc->framerate = cpi->framerate / oxcf->ts_rate_decimator[tl];
147 lrc->avg_frame_bandwidth = (int)(lc->target_bandwidth / lc->framerate); 145 lrc->avg_frame_bandwidth = (int)(lc->target_bandwidth / lc->framerate);
148 lrc->max_frame_bandwidth = rc->max_frame_bandwidth; 146 lrc->max_frame_bandwidth = rc->max_frame_bandwidth;
149 lrc->worst_quality = rc->worst_quality; 147 lrc->worst_quality = rc->worst_quality;
150 lrc->best_quality = rc->best_quality; 148 lrc->best_quality = rc->best_quality;
151 } 149 }
152 } 150 }
153 } else { 151 } else {
154 int layer_end; 152 int layer_end;
155 153
(...skipping 10 matching lines...) Expand all
166 lc->target_bandwidth = oxcf->layer_target_bitrate[layer]; 164 lc->target_bandwidth = oxcf->layer_target_bitrate[layer];
167 165
168 bitrate_alloc = (float)lc->target_bandwidth / target_bandwidth; 166 bitrate_alloc = (float)lc->target_bandwidth / target_bandwidth;
169 // Update buffer-related quantities. 167 // Update buffer-related quantities.
170 lrc->starting_buffer_level = 168 lrc->starting_buffer_level =
171 (int64_t)(rc->starting_buffer_level * bitrate_alloc); 169 (int64_t)(rc->starting_buffer_level * bitrate_alloc);
172 lrc->optimal_buffer_level = 170 lrc->optimal_buffer_level =
173 (int64_t)(rc->optimal_buffer_level * bitrate_alloc); 171 (int64_t)(rc->optimal_buffer_level * bitrate_alloc);
174 lrc->maximum_buffer_size = 172 lrc->maximum_buffer_size =
175 (int64_t)(rc->maximum_buffer_size * bitrate_alloc); 173 (int64_t)(rc->maximum_buffer_size * bitrate_alloc);
176 lrc->bits_off_target = MIN(lrc->bits_off_target, 174 lrc->bits_off_target = VPXMIN(lrc->bits_off_target,
177 lrc->maximum_buffer_size); 175 lrc->maximum_buffer_size);
178 lrc->buffer_level = MIN(lrc->buffer_level, lrc->maximum_buffer_size); 176 lrc->buffer_level = VPXMIN(lrc->buffer_level, lrc->maximum_buffer_size);
179 // Update framerate-related quantities. 177 // Update framerate-related quantities.
180 if (svc->number_temporal_layers > 1 && cpi->oxcf.rc_mode == VPX_CBR) { 178 if (svc->number_temporal_layers > 1 && cpi->oxcf.rc_mode == VPX_CBR) {
181 lc->framerate = cpi->framerate / oxcf->ts_rate_decimator[layer]; 179 lc->framerate = cpi->framerate / oxcf->ts_rate_decimator[layer];
182 } else { 180 } else {
183 lc->framerate = cpi->framerate; 181 lc->framerate = cpi->framerate;
184 } 182 }
185 lrc->avg_frame_bandwidth = (int)(lc->target_bandwidth / lc->framerate); 183 lrc->avg_frame_bandwidth = (int)(lc->target_bandwidth / lc->framerate);
186 lrc->max_frame_bandwidth = rc->max_frame_bandwidth; 184 lrc->max_frame_bandwidth = rc->max_frame_bandwidth;
187 // Update qp-related quantities. 185 // Update qp-related quantities.
188 lrc->worst_quality = rc->worst_quality; 186 lrc->worst_quality = rc->worst_quality;
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 buf = vp9_lookahead_peek(ctx, 0); 634 buf = vp9_lookahead_peek(ctx, 0);
637 if (buf != NULL) { 635 if (buf != NULL) {
638 // Only remove the buffer when pop the highest layer. 636 // Only remove the buffer when pop the highest layer.
639 if (cpi->svc.spatial_layer_id == cpi->svc.number_spatial_layers - 1) { 637 if (cpi->svc.spatial_layer_id == cpi->svc.number_spatial_layers - 1) {
640 vp9_lookahead_pop(ctx, drain); 638 vp9_lookahead_pop(ctx, drain);
641 } 639 }
642 } 640 }
643 } 641 }
644 return buf; 642 return buf;
645 } 643 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_ssim.c ('k') | source/libvpx/vp9/encoder/vp9_temporal_filter.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698