[spatial svc] Output psnr for all layers in one packet.

Change-Id: I97d0cf095e9cfefdfa0f65eb5e96d6848cc9ffca
This commit is contained in:
Minghai Shang 2014-09-11 11:28:03 -07:00
parent 12aaff560b
commit e3fff31aff
6 changed files with 50 additions and 34 deletions

View File

@ -1272,7 +1272,10 @@ static void generate_psnr_packet(VP9_COMP *cpi) {
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) {

View File

@ -36,6 +36,7 @@ typedef struct {
int gold_ref_idx;
int has_alt_frame;
size_t layer_size;
struct vpx_psnr_pkt psnr_pkt;
} LAYER_CONTEXT;
typedef struct {

View File

@ -981,15 +981,20 @@ static vpx_codec_err_t encoder_encode(vpx_codec_alg_priv_t *ctx,
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
}

View File

@ -107,7 +107,7 @@ typedef struct SvcInternal {
// 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 vpx_svc_encode(SvcContext *svc_ctx, vpx_codec_ctx_t *codec_ctx,
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 @@ vpx_codec_err_t vpx_svc_encode(SvcContext *svc_ctx, vpx_codec_ctx_t *codec_ctx,
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 @@ static double calc_psnr(double d) {
// 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 @@ const char *vpx_svc_dump_statistics(SvcContext *svc_ctx) {
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",

View File

@ -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)

View File

@ -163,6 +163,7 @@ extern "C" {
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 @@ extern "C" {
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