summaryrefslogtreecommitdiff
path: root/vp9
diff options
context:
space:
mode:
Diffstat (limited to 'vp9')
-rw-r--r--vp9/encoder/vp9_encoder.c39
-rw-r--r--vp9/encoder/vp9_lookahead.h4
-rw-r--r--vp9/encoder/vp9_svc_layercontext.c83
-rw-r--r--vp9/encoder/vp9_svc_layercontext.h20
-rw-r--r--vp9/vp9_cx_iface.c20
5 files changed, 55 insertions, 111 deletions
diff --git a/vp9/encoder/vp9_encoder.c b/vp9/encoder/vp9_encoder.c
index 107bed5a1..5f5af192c 100644
--- a/vp9/encoder/vp9_encoder.c
+++ b/vp9/encoder/vp9_encoder.c
@@ -2448,15 +2448,7 @@ int vp9_receive_raw_frame(VP9_COMP *cpi, unsigned int frame_flags,
vpx_usec_timer_start(&timer);
-#if CONFIG_SPATIAL_SVC
- if (is_two_pass_svc(cpi))
- res = vp9_svc_lookahead_push(cpi, cpi->lookahead, sd, time_stamp, end_time,
- frame_flags);
- else
-#endif
- res = vp9_lookahead_push(cpi->lookahead,
- sd, time_stamp, end_time, frame_flags);
- if (res)
+ if (vp9_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, frame_flags))
res = -1;
vpx_usec_timer_mark(&timer);
cpi->time_receive_data += vpx_usec_timer_elapsed(&timer);
@@ -2585,11 +2577,12 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
MV_REFERENCE_FRAME ref_frame;
int arf_src_index;
- if (is_two_pass_svc(cpi) && oxcf->pass == 2) {
+ if (is_two_pass_svc(cpi)) {
#if CONFIG_SPATIAL_SVC
- vp9_svc_lookahead_peek(cpi, cpi->lookahead, 0, 1);
+ vp9_svc_start_frame(cpi);
#endif
- vp9_restore_layer_context(cpi);
+ if (oxcf->pass == 2)
+ vp9_restore_layer_context(cpi);
}
vpx_usec_timer_start(&cmptimer);
@@ -2608,13 +2601,7 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
if (arf_src_index) {
assert(arf_src_index <= rc->frames_to_key);
-#if CONFIG_SPATIAL_SVC
- if (is_two_pass_svc(cpi))
- source = vp9_svc_lookahead_peek(cpi, cpi->lookahead, arf_src_index, 0);
- else
-#endif
- source = vp9_lookahead_peek(cpi->lookahead, arf_src_index);
- if (source != NULL) {
+ if ((source = vp9_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) {
cpi->alt_ref_source = source;
#if CONFIG_SPATIAL_SVC
@@ -2652,13 +2639,7 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
if (!source) {
// Get last frame source.
if (cm->current_video_frame > 0) {
-#if CONFIG_SPATIAL_SVC
- if (is_two_pass_svc(cpi))
- last_source = vp9_svc_lookahead_peek(cpi, cpi->lookahead, -1, 0);
- else
-#endif
- last_source = vp9_lookahead_peek(cpi->lookahead, -1);
- if (last_source == NULL)
+ if ((last_source = vp9_lookahead_peek(cpi->lookahead, -1)) == NULL)
return -1;
}
@@ -2918,6 +2899,12 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
}
#endif
+
+ if (is_two_pass_svc(cpi) && cm->show_frame) {
+ ++cpi->svc.spatial_layer_to_encode;
+ if (cpi->svc.spatial_layer_to_encode >= cpi->svc.number_spatial_layers)
+ cpi->svc.spatial_layer_to_encode = 0;
+ }
return 0;
}
diff --git a/vp9/encoder/vp9_lookahead.h b/vp9/encoder/vp9_lookahead.h
index 27861933d..a33d3002e 100644
--- a/vp9/encoder/vp9_lookahead.h
+++ b/vp9/encoder/vp9_lookahead.h
@@ -30,10 +30,6 @@ struct lookahead_entry {
int64_t ts_start;
int64_t ts_end;
unsigned int flags;
-
-#if CONFIG_SPATIAL_SVC
- vpx_svc_parameters_t svc_params[VPX_SS_MAX_LAYERS];
-#endif
};
// The max of past frames we want to keep in the queue.
diff --git a/vp9/encoder/vp9_svc_layercontext.c b/vp9/encoder/vp9_svc_layercontext.c
index 8c735abee..eed681c96 100644
--- a/vp9/encoder/vp9_svc_layercontext.c
+++ b/vp9/encoder/vp9_svc_layercontext.c
@@ -233,51 +233,31 @@ int vp9_is_upper_layer_key_frame(const VP9_COMP *const cpi) {
}
#if CONFIG_SPATIAL_SVC
-int vp9_svc_lookahead_push(const VP9_COMP *const cpi, struct lookahead_ctx *ctx,
- YV12_BUFFER_CONFIG *src, int64_t ts_start,
- int64_t ts_end, unsigned int flags) {
- struct lookahead_entry *buf;
- int i, index;
+static void get_layer_resolution(const int width_org, const int height_org,
+ const int num, const int den,
+ int *width_out, int *height_out) {
+ int w, h;
- if (vp9_lookahead_push(ctx, src, ts_start, ts_end, flags))
- return 1;
+ if (width_out == NULL || height_out == NULL || den == 0)
+ return;
- index = ctx->write_idx - 1;
- if (index < 0)
- index += ctx->max_sz;
+ w = width_org * num / den;
+ h = height_org * num / den;
- buf = ctx->buf + index;
+ // make height and width even to make chrome player happy
+ w += w % 2;
+ h += h % 2;
- if (buf == NULL)
- return 1;
-
- // Store svc parameters for each layer
- for (i = 0; i < cpi->svc.number_spatial_layers; ++i)
- buf->svc_params[i] = cpi->svc.layer_context[i].svc_params_received;
-
- return 0;
+ *width_out = w;
+ *height_out = h;
}
-static int copy_svc_params(VP9_COMP *const cpi, struct lookahead_entry *buf) {
- int layer_id;
- vpx_svc_parameters_t *layer_param;
+int vp9_svc_start_frame(VP9_COMP *const cpi) {
+ int width = 0, height = 0;
LAYER_CONTEXT *lc;
int count = 1 << (cpi->svc.number_temporal_layers - 1);
- // Find the next layer to be encoded
- for (layer_id = 0; layer_id < cpi->svc.number_spatial_layers; ++layer_id) {
- if (buf->svc_params[layer_id].spatial_layer >=0)
- break;
- }
-
- if (layer_id == cpi->svc.number_spatial_layers)
- return 1;
-
- layer_param = &buf->svc_params[layer_id];
- cpi->svc.spatial_layer_id = layer_param->spatial_layer;
- cpi->svc.temporal_layer_id = layer_param->temporal_layer;
- cpi->ref_frame_flags = VP9_ALT_FLAG | VP9_GOLD_FLAG | VP9_LAST_FLAG;
-
+ cpi->svc.spatial_layer_id = cpi->svc.spatial_layer_to_encode;
lc = &cpi->svc.layer_context[cpi->svc.spatial_layer_id];
cpi->svc.temporal_layer_id = 0;
@@ -286,6 +266,8 @@ static int copy_svc_params(VP9_COMP *const cpi, struct lookahead_entry *buf) {
count >>= 1;
}
+ cpi->ref_frame_flags = VP9_ALT_FLAG | VP9_GOLD_FLAG | VP9_LAST_FLAG;
+
cpi->lst_fb_idx = cpi->svc.spatial_layer_id;
if (cpi->svc.spatial_layer_id == 0)
@@ -325,13 +307,14 @@ static int copy_svc_params(VP9_COMP *const cpi, struct lookahead_entry *buf) {
}
}
- if (vp9_set_size_literal(cpi, layer_param->width, layer_param->height) != 0)
+ get_layer_resolution(cpi->oxcf.width, cpi->oxcf.height,
+ lc->scaling_factor_num, lc->scaling_factor_den,
+ &width, &height);
+ if (vp9_set_size_literal(cpi, width, height) != 0)
return VPX_CODEC_INVALID_PARAM;
- cpi->oxcf.worst_allowed_q =
- vp9_quantizer_to_qindex(layer_param->max_quantizer);
- cpi->oxcf.best_allowed_q =
- vp9_quantizer_to_qindex(layer_param->min_quantizer);
+ cpi->oxcf.worst_allowed_q = vp9_quantizer_to_qindex(lc->max_q);
+ cpi->oxcf.best_allowed_q = vp9_quantizer_to_qindex(lc->min_q);
vp9_change_config(cpi, &cpi->oxcf);
@@ -342,29 +325,15 @@ static int copy_svc_params(VP9_COMP *const cpi, struct lookahead_entry *buf) {
return 0;
}
-struct lookahead_entry *vp9_svc_lookahead_peek(VP9_COMP *const cpi,
- struct lookahead_ctx *ctx,
- int index, int copy_params) {
- struct lookahead_entry *buf = vp9_lookahead_peek(ctx, index);
-
- if (buf != NULL && copy_params != 0) {
- if (copy_svc_params(cpi, buf) != 0)
- return NULL;
- }
- return buf;
-}
-
struct lookahead_entry *vp9_svc_lookahead_pop(VP9_COMP *const cpi,
struct lookahead_ctx *ctx,
int drain) {
struct lookahead_entry *buf = NULL;
if (ctx->sz && (drain || ctx->sz == ctx->max_sz - MAX_PRE_FRAMES)) {
- buf = vp9_svc_lookahead_peek(cpi, ctx, 0, 1);
+ buf = vp9_lookahead_peek(ctx, 0);
if (buf != NULL) {
- // Only remove the buffer when pop the highest layer. Simply set the
- // spatial_layer to -1 for lower layers.
- buf->svc_params[cpi->svc.spatial_layer_id].spatial_layer = -1;
+ // Only remove the buffer when pop the highest layer.
if (cpi->svc.spatial_layer_id == cpi->svc.number_spatial_layers - 1) {
vp9_lookahead_pop(ctx, drain);
}
diff --git a/vp9/encoder/vp9_svc_layercontext.h b/vp9/encoder/vp9_svc_layercontext.h
index d180d1a8c..47a5456b6 100644
--- a/vp9/encoder/vp9_svc_layercontext.h
+++ b/vp9/encoder/vp9_svc_layercontext.h
@@ -24,13 +24,16 @@ typedef struct {
int target_bandwidth;
double framerate;
int avg_frame_size;
+ int max_q;
+ int min_q;
+ int scaling_factor_num;
+ int scaling_factor_den;
TWO_PASS twopass;
vpx_fixed_buf_t rc_twopass_stats_in;
unsigned int current_video_frame_in_layer;
int is_key_frame;
int frames_from_key_frame;
FRAME_TYPE last_frame_type;
- vpx_svc_parameters_t svc_params_received;
struct lookahead_entry *alt_ref_source;
int alt_ref_idx;
int gold_ref_idx;
@@ -45,6 +48,8 @@ typedef struct {
int number_spatial_layers;
int number_temporal_layers;
+ int spatial_layer_to_encode;
+
// Store scaled source frames to be used for temporal filter to generate
// a alt ref frame.
YV12_BUFFER_CONFIG scaled_frames[MAX_LAG_BUFFERS];
@@ -88,22 +93,13 @@ void vp9_inc_frame_in_layer(struct VP9_COMP *const cpi);
// Check if current layer is key frame in spatial upper layer
int vp9_is_upper_layer_key_frame(const struct VP9_COMP *const cpi);
-// Copy the source image, flags and svc parameters into a new framebuffer
-// with the expected stride/border
-int vp9_svc_lookahead_push(const struct VP9_COMP *const cpi,
- struct lookahead_ctx *ctx, YV12_BUFFER_CONFIG *src,
- int64_t ts_start, int64_t ts_end,
- unsigned int flags);
-
// Get the next source buffer to encode
struct lookahead_entry *vp9_svc_lookahead_pop(struct VP9_COMP *const cpi,
struct lookahead_ctx *ctx,
int drain);
-// Get a future source buffer to encode
-struct lookahead_entry *vp9_svc_lookahead_peek(struct VP9_COMP *const cpi,
- struct lookahead_ctx *ctx,
- int index, int copy_params);
+// Start a frame and initialize svc parameters
+int vp9_svc_start_frame(struct VP9_COMP *const cpi);
#ifdef __cplusplus
} // extern "C"
diff --git a/vp9/vp9_cx_iface.c b/vp9/vp9_cx_iface.c
index 0d6ad26a6..fbf4aa2fc 100644
--- a/vp9/vp9_cx_iface.c
+++ b/vp9/vp9_cx_iface.c
@@ -1198,22 +1198,18 @@ static vpx_codec_err_t ctrl_set_svc_layer_id(vpx_codec_alg_priv_t *ctx,
static vpx_codec_err_t ctrl_set_svc_parameters(vpx_codec_alg_priv_t *ctx,
va_list args) {
VP9_COMP *const cpi = ctx->cpi;
- vpx_svc_parameters_t *const params = va_arg(args, vpx_svc_parameters_t *);
+ vpx_svc_extra_cfg_t *const params = va_arg(args, vpx_svc_extra_cfg_t *);
+ int i;
- if (params == NULL || params->spatial_layer < 0 ||
- params->spatial_layer >= cpi->svc.number_spatial_layers)
- return VPX_CODEC_INVALID_PARAM;
+ for (i = 0; i < cpi->svc.number_spatial_layers; ++i) {
+ LAYER_CONTEXT *lc = &cpi->svc.layer_context[i];
- if (params->spatial_layer == 0) {
- int i;
- for (i = 0; i < cpi->svc.number_spatial_layers; ++i) {
- cpi->svc.layer_context[i].svc_params_received.spatial_layer = -1;
- }
+ lc->max_q = params->max_quantizers[i];
+ lc->min_q = params->min_quantizers[i];
+ lc->scaling_factor_num = params->scaling_factor_num[i];
+ lc->scaling_factor_den = params->scaling_factor_den[i];
}
- cpi->svc.layer_context[params->spatial_layer].svc_params_received =
- *params;
-
return VPX_CODEC_OK;
}