ref: 3e7b04af54e9133c94527aa970b398c009adcbef
parent: 7f77a1c3c96ec582fa6b8682320d60fb389be94b
parent: e3fff31aff4f6be8aad493bc954f60ad5cc2f8f5
author: Minghai Shang <[email protected]>
date: Fri Sep 12 06:52:42 EDT 2014
Merge "[spatial svc] Output psnr for all layers in one packet."
--- a/vp9/encoder/vp9_encoder.c
+++ b/vp9/encoder/vp9_encoder.c
@@ -1280,7 +1280,10 @@
pkt.data.psnr.psnr[i] = psnr.psnr[i];
}
pkt.kind = VPX_CODEC_PSNR_PKT;
- vpx_codec_pkt_list_add(cpi->output_pkt_list, &pkt);
+ if (is_two_pass_svc(cpi))
+ cpi->svc.layer_context[cpi->svc.spatial_layer_id].psnr_pkt = pkt.data.psnr;
+ else
+ vpx_codec_pkt_list_add(cpi->output_pkt_list, &pkt);
}
int vp9_use_as_reference(VP9_COMP *cpi, int ref_frame_flags) {
--- a/vp9/encoder/vp9_svc_layercontext.h
+++ b/vp9/encoder/vp9_svc_layercontext.h
@@ -36,6 +36,7 @@
int gold_ref_idx;
int has_alt_frame;
size_t layer_size;
+ struct vpx_psnr_pkt psnr_pkt;
} LAYER_CONTEXT;
typedef struct {
--- a/vp9/vp9_cx_iface.c
+++ b/vp9/vp9_cx_iface.c
@@ -985,15 +985,20 @@
cx_data_sz -= size;
#if CONFIG_SPATIAL_SVC
if (is_two_pass_svc(cpi)) {
- vpx_codec_cx_pkt_t pkt;
+ vpx_codec_cx_pkt_t pkt_sizes, pkt_psnr;
int i;
- vp9_zero(pkt);
- pkt.kind = VPX_CODEC_SPATIAL_SVC_LAYER_SIZES;
+ vp9_zero(pkt_sizes);
+ vp9_zero(pkt_psnr);
+ pkt_sizes.kind = VPX_CODEC_SPATIAL_SVC_LAYER_SIZES;
+ pkt_psnr.kind = VPX_CODEC_SPATIAL_SVC_LAYER_PSNR;
for (i = 0; i < cpi->svc.number_spatial_layers; ++i) {
- pkt.data.layer_sizes[i] = cpi->svc.layer_context[i].layer_size;
- cpi->svc.layer_context[i].layer_size = 0;
+ LAYER_CONTEXT *lc = &cpi->svc.layer_context[i];
+ pkt_sizes.data.layer_sizes[i] = lc->layer_size;
+ pkt_psnr.data.layer_psnr[i] = lc->psnr_pkt;
+ lc->layer_size = 0;
}
- vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt);
+ vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt_sizes);
+ vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt_psnr);
}
#endif
}
--- a/vpx/src/svc_encodeframe.c
+++ b/vpx/src/svc_encodeframe.c
@@ -107,7 +107,7 @@
// state variables
int encode_frame_count;
- int frame_received;
+ int psnr_pkt_received;
int frame_within_gop;
int layers;
int layer;
@@ -566,7 +566,6 @@
vpx_codec_err_t res;
vpx_codec_iter_t iter;
const vpx_codec_cx_pkt_t *cx_pkt;
- int layer_for_psnr = 0;
SvcInternal *const si = get_svc_internal(svc_ctx);
if (svc_ctx == NULL || codec_ctx == NULL || si == NULL) {
return VPX_CODEC_INVALID_PARAM;
@@ -603,30 +602,37 @@
iter = NULL;
while ((cx_pkt = vpx_codec_get_cx_data(codec_ctx, &iter))) {
switch (cx_pkt->kind) {
- case VPX_CODEC_PSNR_PKT: {
+#if CONFIG_SPATIAL_SVC
+ case VPX_CODEC_SPATIAL_SVC_LAYER_PSNR: {
int i;
- svc_log(svc_ctx, SVC_LOG_DEBUG,
- "SVC frame: %d, layer: %d, PSNR(Total/Y/U/V): "
- "%2.3f %2.3f %2.3f %2.3f \n",
- si->frame_received, layer_for_psnr,
- cx_pkt->data.psnr.psnr[0], cx_pkt->data.psnr.psnr[1],
- cx_pkt->data.psnr.psnr[2], cx_pkt->data.psnr.psnr[3]);
- svc_log(svc_ctx, SVC_LOG_DEBUG,
- "SVC frame: %d, layer: %d, SSE(Total/Y/U/V): "
- "%2.3f %2.3f %2.3f %2.3f \n",
- si->frame_received, layer_for_psnr,
- cx_pkt->data.psnr.sse[0], cx_pkt->data.psnr.sse[1],
- cx_pkt->data.psnr.sse[2], cx_pkt->data.psnr.sse[3]);
- for (i = 0; i < COMPONENTS; i++) {
- si->psnr_sum[layer_for_psnr][i] += cx_pkt->data.psnr.psnr[i];
- si->sse_sum[layer_for_psnr][i] += cx_pkt->data.psnr.sse[i];
+ for (i = 0; i < svc_ctx->spatial_layers; ++i) {
+ int j;
+ svc_log(svc_ctx, SVC_LOG_DEBUG,
+ "SVC frame: %d, layer: %d, PSNR(Total/Y/U/V): "
+ "%2.3f %2.3f %2.3f %2.3f \n",
+ si->psnr_pkt_received, i,
+ cx_pkt->data.layer_psnr[i].psnr[0],
+ cx_pkt->data.layer_psnr[i].psnr[1],
+ cx_pkt->data.layer_psnr[i].psnr[2],
+ cx_pkt->data.layer_psnr[i].psnr[3]);
+ svc_log(svc_ctx, SVC_LOG_DEBUG,
+ "SVC frame: %d, layer: %d, SSE(Total/Y/U/V): "
+ "%2.3f %2.3f %2.3f %2.3f \n",
+ si->psnr_pkt_received, i,
+ cx_pkt->data.layer_psnr[i].sse[0],
+ cx_pkt->data.layer_psnr[i].sse[1],
+ cx_pkt->data.layer_psnr[i].sse[2],
+ cx_pkt->data.layer_psnr[i].sse[3]);
+
+ for (j = 0; j < COMPONENTS; ++j) {
+ si->psnr_sum[i][j] +=
+ cx_pkt->data.layer_psnr[i].psnr[j];
+ si->sse_sum[i][j] += cx_pkt->data.layer_psnr[i].sse[j];
+ }
}
- ++layer_for_psnr;
- if (layer_for_psnr == svc_ctx->spatial_layers)
- layer_for_psnr = 0;
+ ++si->psnr_pkt_received;
break;
}
-#if CONFIG_SPATIAL_SVC
case VPX_CODEC_SPATIAL_SVC_LAYER_SIZES: {
int i;
for (i = 0; i < si->layers; ++i)
@@ -673,7 +679,7 @@
// dump accumulated statistics and reset accumulated values
const char *vpx_svc_dump_statistics(SvcContext *svc_ctx) {
- int number_of_frames, encode_frame_count;
+ int number_of_frames;
int i, j;
uint32_t bytes_total = 0;
double scale[COMPONENTS];
@@ -686,12 +692,11 @@
svc_log_reset(svc_ctx);
- encode_frame_count = si->encode_frame_count;
- if (si->encode_frame_count <= 0) return vpx_svc_get_message(svc_ctx);
+ number_of_frames = si->psnr_pkt_received;
+ if (number_of_frames <= 0) return vpx_svc_get_message(svc_ctx);
svc_log(svc_ctx, SVC_LOG_INFO, "\n");
for (i = 0; i < si->layers; ++i) {
- number_of_frames = encode_frame_count;
svc_log(svc_ctx, SVC_LOG_INFO,
"Layer %d Average PSNR=[%2.3f, %2.3f, %2.3f, %2.3f], Bytes=[%u]\n",
--- a/vpx/src/vpx_encoder.c
+++ b/vpx/src/vpx_encoder.c
@@ -15,8 +15,8 @@
*/
#include <limits.h>
#include <string.h>
-#include "vpx/internal/vpx_codec_internal.h"
#include "vpx_config.h"
+#include "vpx/internal/vpx_codec_internal.h"
#define SAVE_STATUS(ctx,var) (ctx?(ctx->err = var):var)
--- a/vpx/vpx_encoder.h
+++ b/vpx/vpx_encoder.h
@@ -163,6 +163,7 @@
VPX_CODEC_PSNR_PKT, /**< PSNR statistics for this frame */
#if CONFIG_SPATIAL_SVC
VPX_CODEC_SPATIAL_SVC_LAYER_SIZES, /**< Sizes for each layer in this frame*/
+ VPX_CODEC_SPATIAL_SVC_LAYER_PSNR, /**< PSNR for each layer in this frame*/
#endif
VPX_CODEC_CUSTOM_PKT = 256 /**< Algorithm extensions */
};
@@ -202,6 +203,7 @@
vpx_fixed_buf_t raw; /**< data for arbitrary packets */
#if CONFIG_SPATIAL_SVC
size_t layer_sizes[VPX_SS_MAX_LAYERS];
+ struct vpx_psnr_pkt layer_psnr[VPX_SS_MAX_LAYERS];
#endif
/* This packet size is fixed to allow codecs to extend this