2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved.
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
13 * VP9 SVC encoding support via libvpx
23 #define VPX_DISABLE_CTRL_TYPECHECKS 1
24 #include "./vpx_config.h"
25 #include "vpx/svc_context.h"
26 #include "vpx/vp8cx.h"
27 #include "vpx/vpx_encoder.h"
28 #include "vpx_mem/vpx_mem.h"
29 #include "vp9/common/vp9_onyxc_int.h"
32 #define strtok_r strtok_s
33 #ifndef MINGW_HAS_SECURE_API
34 // proto from /usr/x86_64-w64-mingw32/include/sec_api/string_s.h
35 _CRTIMP char *__cdecl strtok_s(char *str, const char *delim, char **context);
36 #endif /* MINGW_HAS_SECURE_API */
37 #endif /* __MINGW32__ */
40 #define strdup _strdup
41 #define strtok_r strtok_s
44 #define SVC_REFERENCE_FRAMES 8
45 #define SUPERFRAME_SLOTS (8)
46 #define SUPERFRAME_BUFFER_SIZE (SUPERFRAME_SLOTS * sizeof(uint32_t) + 2)
48 #define MAX_QUANTIZER 63
50 static const int DEFAULT_SCALE_FACTORS_NUM[VPX_SS_MAX_LAYERS] = {
54 static const int DEFAULT_SCALE_FACTORS_DEN[VPX_SS_MAX_LAYERS] = {
66 static const int option_max_values[ALL_OPTION_TYPES] = {
67 63, INT_MAX, INT_MAX, 1
70 static const int option_min_values[ALL_OPTION_TYPES] = {
75 typedef struct FrameData {
76 void *buf; // compressed data buffer
77 size_t size; // length of compressed data
78 vpx_codec_frame_flags_t flags; /**< flags for this frame */
79 struct FrameData *next;
82 static SvcInternal_t *get_svc_internal(SvcContext *svc_ctx) {
83 if (svc_ctx == NULL) return NULL;
84 if (svc_ctx->internal == NULL) {
85 SvcInternal_t *const si = (SvcInternal_t *)malloc(sizeof(*si));
87 memset(si, 0, sizeof(*si));
89 svc_ctx->internal = si;
91 return (SvcInternal_t *)svc_ctx->internal;
94 static const SvcInternal_t *get_const_svc_internal(
95 const SvcContext *svc_ctx) {
96 if (svc_ctx == NULL) return NULL;
97 return (const SvcInternal_t *)svc_ctx->internal;
100 static void svc_log_reset(SvcContext *svc_ctx) {
101 SvcInternal_t *const si = (SvcInternal_t *)svc_ctx->internal;
102 si->message_buffer[0] = '\0';
105 static int svc_log(SvcContext *svc_ctx, SVC_LOG_LEVEL level,
106 const char *fmt, ...) {
110 SvcInternal_t *const si = get_svc_internal(svc_ctx);
112 if (level > svc_ctx->log_level) {
117 retval = vsnprintf(buf, sizeof(buf), fmt, ap);
120 if (svc_ctx->log_print) {
123 strncat(si->message_buffer, buf,
124 sizeof(si->message_buffer) - strlen(si->message_buffer) - 1);
127 if (level == SVC_LOG_ERROR) {
128 si->codec_ctx->err_detail = si->message_buffer;
133 static vpx_codec_err_t extract_option(LAYER_OPTION_TYPE type,
137 if (type == SCALE_FACTOR) {
138 *value0 = strtol(input, &input, 10);
140 return VPX_CODEC_INVALID_PARAM;
141 *value1 = strtol(input, &input, 10);
143 if (*value0 < option_min_values[SCALE_FACTOR] ||
144 *value1 < option_min_values[SCALE_FACTOR] ||
145 *value0 > option_max_values[SCALE_FACTOR] ||
146 *value1 > option_max_values[SCALE_FACTOR] ||
147 *value0 > *value1) // num shouldn't be greater than den
148 return VPX_CODEC_INVALID_PARAM;
150 *value0 = atoi(input);
151 if (*value0 < option_min_values[type] ||
152 *value0 > option_max_values[type])
153 return VPX_CODEC_INVALID_PARAM;
158 static vpx_codec_err_t parse_layer_options_from_string(SvcContext *svc_ctx,
159 LAYER_OPTION_TYPE type,
164 vpx_codec_err_t res = VPX_CODEC_OK;
167 const char *delim = ",";
170 if (input == NULL || option0 == NULL ||
171 (option1 == NULL && type == SCALE_FACTOR))
172 return VPX_CODEC_INVALID_PARAM;
174 input_string = strdup(input);
175 token = strtok_r(input_string, delim, &save_ptr);
176 for (i = 0; i < svc_ctx->spatial_layers; ++i) {
178 res = extract_option(type, token, option0 + i, option1 + i);
179 if (res != VPX_CODEC_OK)
181 token = strtok_r(NULL, delim, &save_ptr);
186 if (res == VPX_CODEC_OK && i != svc_ctx->spatial_layers) {
187 svc_log(svc_ctx, SVC_LOG_ERROR,
188 "svc: layer params type: %d %d values required, "
189 "but only %d specified\n", type, svc_ctx->spatial_layers, i);
190 res = VPX_CODEC_INVALID_PARAM;
197 * Parse SVC encoding options
198 * Format: encoding-mode=<svc_mode>,layers=<layer_count>
199 * scale-factors=<n1>/<d1>,<n2>/<d2>,...
200 * quantizers=<q1>,<q2>,...
201 * svc_mode = [i|ip|alt_ip|gf]
203 static vpx_codec_err_t parse_options(SvcContext *svc_ctx, const char *options) {
208 SvcInternal_t *const si = get_svc_internal(svc_ctx);
209 vpx_codec_err_t res = VPX_CODEC_OK;
210 int i, alt_ref_enabled = 0;
212 if (options == NULL) return VPX_CODEC_OK;
213 input_string = strdup(options);
216 option_name = strtok_r(input_string, "=", &input_ptr);
217 while (option_name != NULL) {
218 // parse option value
219 option_value = strtok_r(NULL, " ", &input_ptr);
220 if (option_value == NULL) {
221 svc_log(svc_ctx, SVC_LOG_ERROR, "option missing value: %s\n",
223 res = VPX_CODEC_INVALID_PARAM;
226 if (strcmp("spatial-layers", option_name) == 0) {
227 svc_ctx->spatial_layers = atoi(option_value);
228 } else if (strcmp("temporal-layers", option_name) == 0) {
229 svc_ctx->temporal_layers = atoi(option_value);
230 } else if (strcmp("scale-factors", option_name) == 0) {
231 res = parse_layer_options_from_string(svc_ctx, SCALE_FACTOR, option_value,
232 si->svc_params.scaling_factor_num,
233 si->svc_params.scaling_factor_den);
234 if (res != VPX_CODEC_OK) break;
235 } else if (strcmp("max-quantizers", option_name) == 0) {
236 res = parse_layer_options_from_string(svc_ctx, QUANTIZER, option_value,
237 si->svc_params.max_quantizers,
239 if (res != VPX_CODEC_OK) break;
240 } else if (strcmp("min-quantizers", option_name) == 0) {
241 res = parse_layer_options_from_string(svc_ctx, QUANTIZER, option_value,
242 si->svc_params.min_quantizers,
244 if (res != VPX_CODEC_OK) break;
245 } else if (strcmp("auto-alt-refs", option_name) == 0) {
246 res = parse_layer_options_from_string(svc_ctx, AUTO_ALT_REF, option_value,
247 si->enable_auto_alt_ref, NULL);
248 if (res != VPX_CODEC_OK) break;
249 } else if (strcmp("bitrates", option_name) == 0) {
250 res = parse_layer_options_from_string(svc_ctx, BITRATE, option_value,
252 if (res != VPX_CODEC_OK) break;
253 } else if (strcmp("multi-frame-contexts", option_name) == 0) {
254 si->use_multiple_frame_contexts = atoi(option_value);
256 svc_log(svc_ctx, SVC_LOG_ERROR, "invalid option: %s\n", option_name);
257 res = VPX_CODEC_INVALID_PARAM;
260 option_name = strtok_r(NULL, "=", &input_ptr);
264 for (i = 0; i < svc_ctx->spatial_layers; ++i) {
265 if (si->svc_params.max_quantizers[i] > MAX_QUANTIZER ||
266 si->svc_params.max_quantizers[i] < 0 ||
267 si->svc_params.min_quantizers[i] > si->svc_params.max_quantizers[i] ||
268 si->svc_params.min_quantizers[i] < 0)
269 res = VPX_CODEC_INVALID_PARAM;
272 if (si->use_multiple_frame_contexts &&
273 (svc_ctx->spatial_layers > 3 ||
274 svc_ctx->spatial_layers * svc_ctx->temporal_layers > 4))
275 res = VPX_CODEC_INVALID_PARAM;
277 for (i = 0; i < svc_ctx->spatial_layers; ++i)
278 alt_ref_enabled += si->enable_auto_alt_ref[i];
279 if (alt_ref_enabled > REF_FRAMES - svc_ctx->spatial_layers) {
280 svc_log(svc_ctx, SVC_LOG_ERROR,
281 "svc: auto alt ref: Maxinum %d(REF_FRAMES - layers) layers could"
282 "enabled auto alt reference frame, but % layers are enabled\n",
283 REF_FRAMES - svc_ctx->spatial_layers, alt_ref_enabled);
284 res = VPX_CODEC_INVALID_PARAM;
290 vpx_codec_err_t vpx_svc_set_options(SvcContext *svc_ctx,
291 const char *options) {
292 SvcInternal_t *const si = get_svc_internal(svc_ctx);
293 if (svc_ctx == NULL || options == NULL || si == NULL) {
294 return VPX_CODEC_INVALID_PARAM;
296 strncpy(si->options, options, sizeof(si->options));
297 si->options[sizeof(si->options) - 1] = '\0';
301 void assign_layer_bitrates(const SvcContext *svc_ctx,
302 vpx_codec_enc_cfg_t *const enc_cfg) {
304 const SvcInternal_t *const si = get_const_svc_internal(svc_ctx);
305 int sl, tl, spatial_layer_target;
307 if (svc_ctx->temporal_layering_mode != 0) {
308 if (si->bitrates[0] != 0) {
309 enc_cfg->rc_target_bitrate = 0;
310 for (sl = 0; sl < svc_ctx->spatial_layers; ++sl) {
311 enc_cfg->ss_target_bitrate[sl*svc_ctx->temporal_layers] = 0;
312 for (tl = 0; tl < svc_ctx->temporal_layers; ++tl) {
313 enc_cfg->ss_target_bitrate[sl*svc_ctx->temporal_layers]
314 += (unsigned int)si->bitrates[sl * svc_ctx->temporal_layers + tl];
315 enc_cfg->layer_target_bitrate[sl*svc_ctx->temporal_layers + tl]
316 = si->bitrates[sl * svc_ctx->temporal_layers + tl];
321 float alloc_ratio[VPX_MAX_LAYERS] = {0};
323 for (sl = 0; sl < svc_ctx->spatial_layers; ++sl) {
324 if (si->svc_params.scaling_factor_den[sl] > 0) {
325 alloc_ratio[sl] = (float)(si->svc_params.scaling_factor_num[sl] *
326 1.0 / si->svc_params.scaling_factor_den[sl]);
327 total += alloc_ratio[sl];
331 for (sl = 0; sl < svc_ctx->spatial_layers; ++sl) {
332 enc_cfg->ss_target_bitrate[sl] = spatial_layer_target =
333 (unsigned int)(enc_cfg->rc_target_bitrate *
334 alloc_ratio[sl] / total);
335 if (svc_ctx->temporal_layering_mode == 3) {
336 enc_cfg->layer_target_bitrate[sl * svc_ctx->temporal_layers] =
337 spatial_layer_target >> 1;
338 enc_cfg->layer_target_bitrate[sl * svc_ctx->temporal_layers + 1] =
339 (spatial_layer_target >> 1) + (spatial_layer_target >> 2);
340 enc_cfg->layer_target_bitrate[sl * svc_ctx->temporal_layers + 2] =
341 spatial_layer_target;
342 } else if (svc_ctx->temporal_layering_mode == 2) {
343 enc_cfg->layer_target_bitrate[sl * svc_ctx->temporal_layers] =
344 spatial_layer_target * 2 / 3;
345 enc_cfg->layer_target_bitrate[sl * svc_ctx->temporal_layers + 1] =
346 spatial_layer_target;
348 // User should explicitly assign bitrates in this case.
354 if (si->bitrates[0] != 0) {
355 enc_cfg->rc_target_bitrate = 0;
356 for (i = 0; i < svc_ctx->spatial_layers; ++i) {
357 enc_cfg->ss_target_bitrate[i] = (unsigned int)si->bitrates[i];
358 enc_cfg->rc_target_bitrate += si->bitrates[i];
362 float alloc_ratio[VPX_MAX_LAYERS] = {0};
364 for (i = 0; i < svc_ctx->spatial_layers; ++i) {
365 if (si->svc_params.scaling_factor_den[i] > 0) {
366 alloc_ratio[i] = (float)(si->svc_params.scaling_factor_num[i] * 1.0 /
367 si->svc_params.scaling_factor_den[i]);
369 alloc_ratio[i] *= alloc_ratio[i];
370 total += alloc_ratio[i];
373 for (i = 0; i < VPX_SS_MAX_LAYERS; ++i) {
375 enc_cfg->layer_target_bitrate[i] = (unsigned int)
376 (enc_cfg->rc_target_bitrate * alloc_ratio[i] / total);
383 vpx_codec_err_t vpx_svc_init(SvcContext *svc_ctx, vpx_codec_ctx_t *codec_ctx,
384 vpx_codec_iface_t *iface,
385 vpx_codec_enc_cfg_t *enc_cfg) {
388 SvcInternal_t *const si = get_svc_internal(svc_ctx);
389 if (svc_ctx == NULL || codec_ctx == NULL || iface == NULL ||
391 return VPX_CODEC_INVALID_PARAM;
393 if (si == NULL) return VPX_CODEC_MEM_ERROR;
395 si->codec_ctx = codec_ctx;
397 si->width = enc_cfg->g_w;
398 si->height = enc_cfg->g_h;
400 if (enc_cfg->kf_max_dist < 2) {
401 svc_log(svc_ctx, SVC_LOG_ERROR, "key frame distance too small: %d\n",
402 enc_cfg->kf_max_dist);
403 return VPX_CODEC_INVALID_PARAM;
405 si->kf_dist = enc_cfg->kf_max_dist;
407 if (svc_ctx->spatial_layers == 0)
408 svc_ctx->spatial_layers = VPX_SS_DEFAULT_LAYERS;
409 if (svc_ctx->spatial_layers < 1 ||
410 svc_ctx->spatial_layers > VPX_SS_MAX_LAYERS) {
411 svc_log(svc_ctx, SVC_LOG_ERROR, "spatial layers: invalid value: %d\n",
412 svc_ctx->spatial_layers);
413 return VPX_CODEC_INVALID_PARAM;
416 // Note: temporal_layering_mode only applies to one-pass CBR
417 // si->svc_params.temporal_layering_mode = svc_ctx->temporal_layering_mode;
418 if (svc_ctx->temporal_layering_mode == 3) {
419 svc_ctx->temporal_layers = 3;
420 } else if (svc_ctx->temporal_layering_mode == 2) {
421 svc_ctx->temporal_layers = 2;
424 for (i = 0; i < VPX_SS_MAX_LAYERS; ++i) {
425 si->svc_params.max_quantizers[i] = MAX_QUANTIZER;
426 si->svc_params.min_quantizers[i] = 0;
427 si->svc_params.scaling_factor_num[i] = DEFAULT_SCALE_FACTORS_NUM[i];
428 si->svc_params.scaling_factor_den[i] = DEFAULT_SCALE_FACTORS_DEN[i];
431 // Parse aggregate command line options. Options must start with
432 // "layers=xx" then followed by other options
433 res = parse_options(svc_ctx, si->options);
434 if (res != VPX_CODEC_OK) return res;
436 if (svc_ctx->spatial_layers < 1)
437 svc_ctx->spatial_layers = 1;
438 if (svc_ctx->spatial_layers > VPX_SS_MAX_LAYERS)
439 svc_ctx->spatial_layers = VPX_SS_MAX_LAYERS;
441 if (svc_ctx->temporal_layers < 1)
442 svc_ctx->temporal_layers = 1;
443 if (svc_ctx->temporal_layers > VPX_TS_MAX_LAYERS)
444 svc_ctx->temporal_layers = VPX_TS_MAX_LAYERS;
446 if (svc_ctx->temporal_layers * svc_ctx->spatial_layers > VPX_MAX_LAYERS) {
447 svc_log(svc_ctx, SVC_LOG_ERROR,
448 "spatial layers * temporal layers exceeds the maximum number of "
449 "allowed layers of %d\n",
450 svc_ctx->spatial_layers * svc_ctx->temporal_layers,
451 (int) VPX_MAX_LAYERS);
452 return VPX_CODEC_INVALID_PARAM;
454 assign_layer_bitrates(svc_ctx, enc_cfg);
456 #if CONFIG_SPATIAL_SVC
457 for (i = 0; i < svc_ctx->spatial_layers; ++i)
458 enc_cfg->ss_enable_auto_alt_ref[i] = si->enable_auto_alt_ref[i];
461 if (svc_ctx->temporal_layers > 1) {
463 for (i = 0; i < svc_ctx->temporal_layers; ++i) {
464 enc_cfg->ts_target_bitrate[i] = enc_cfg->rc_target_bitrate /
465 svc_ctx->temporal_layers;
466 enc_cfg->ts_rate_decimator[i] = 1 << (svc_ctx->temporal_layers - 1 - i);
470 if (svc_ctx->threads)
471 enc_cfg->g_threads = svc_ctx->threads;
473 // Modify encoder configuration
474 enc_cfg->ss_number_layers = svc_ctx->spatial_layers;
475 enc_cfg->ts_number_layers = svc_ctx->temporal_layers;
477 if (enc_cfg->rc_end_usage == VPX_CBR) {
478 enc_cfg->rc_resize_allowed = 0;
479 enc_cfg->rc_min_quantizer = 2;
480 enc_cfg->rc_max_quantizer = 56;
481 enc_cfg->rc_undershoot_pct = 50;
482 enc_cfg->rc_overshoot_pct = 50;
483 enc_cfg->rc_buf_initial_sz = 500;
484 enc_cfg->rc_buf_optimal_sz = 600;
485 enc_cfg->rc_buf_sz = 1000;
488 if (enc_cfg->g_error_resilient == 0 && si->use_multiple_frame_contexts == 0)
489 enc_cfg->g_error_resilient = 1;
492 res = vpx_codec_enc_init(codec_ctx, iface, enc_cfg, VPX_CODEC_USE_PSNR);
493 if (res != VPX_CODEC_OK) {
494 svc_log(svc_ctx, SVC_LOG_ERROR, "svc_enc_init error\n");
497 if (svc_ctx->spatial_layers > 1 || svc_ctx->temporal_layers > 1) {
498 vpx_codec_control(codec_ctx, VP9E_SET_SVC, 1);
499 vpx_codec_control(codec_ctx, VP9E_SET_SVC_PARAMETERS, &si->svc_params);
505 * Encode a frame into multiple layers
506 * Create a superframe containing the individual layers
508 vpx_codec_err_t vpx_svc_encode(SvcContext *svc_ctx,
509 vpx_codec_ctx_t *codec_ctx,
510 struct vpx_image *rawimg,
512 int64_t duration, int deadline) {
514 vpx_codec_iter_t iter;
515 const vpx_codec_cx_pkt_t *cx_pkt;
516 SvcInternal_t *const si = get_svc_internal(svc_ctx);
517 if (svc_ctx == NULL || codec_ctx == NULL || si == NULL) {
518 return VPX_CODEC_INVALID_PARAM;
521 svc_log_reset(svc_ctx);
523 res = vpx_codec_encode(codec_ctx, rawimg, pts, (uint32_t)duration, 0,
525 if (res != VPX_CODEC_OK) {
528 // save compressed data
530 while ((cx_pkt = vpx_codec_get_cx_data(codec_ctx, &iter))) {
531 switch (cx_pkt->kind) {
532 #if VPX_ENCODER_ABI_VERSION > (5 + VPX_CODEC_ABI_VERSION)
533 #if CONFIG_SPATIAL_SVC
534 case VPX_CODEC_SPATIAL_SVC_LAYER_PSNR: {
536 for (i = 0; i < svc_ctx->spatial_layers; ++i) {
538 svc_log(svc_ctx, SVC_LOG_DEBUG,
539 "SVC frame: %d, layer: %d, PSNR(Total/Y/U/V): "
540 "%2.3f %2.3f %2.3f %2.3f \n",
541 si->psnr_pkt_received, i,
542 cx_pkt->data.layer_psnr[i].psnr[0],
543 cx_pkt->data.layer_psnr[i].psnr[1],
544 cx_pkt->data.layer_psnr[i].psnr[2],
545 cx_pkt->data.layer_psnr[i].psnr[3]);
546 svc_log(svc_ctx, SVC_LOG_DEBUG,
547 "SVC frame: %d, layer: %d, SSE(Total/Y/U/V): "
548 "%2.3f %2.3f %2.3f %2.3f \n",
549 si->psnr_pkt_received, i,
550 cx_pkt->data.layer_psnr[i].sse[0],
551 cx_pkt->data.layer_psnr[i].sse[1],
552 cx_pkt->data.layer_psnr[i].sse[2],
553 cx_pkt->data.layer_psnr[i].sse[3]);
555 for (j = 0; j < COMPONENTS; ++j) {
556 si->psnr_sum[i][j] +=
557 cx_pkt->data.layer_psnr[i].psnr[j];
558 si->sse_sum[i][j] += cx_pkt->data.layer_psnr[i].sse[j];
561 ++si->psnr_pkt_received;
564 case VPX_CODEC_SPATIAL_SVC_LAYER_SIZES: {
566 for (i = 0; i < svc_ctx->spatial_layers; ++i)
567 si->bytes_sum[i] += cx_pkt->data.layer_sizes[i];
581 const char *vpx_svc_get_message(const SvcContext *svc_ctx) {
582 const SvcInternal_t *const si = get_const_svc_internal(svc_ctx);
583 if (svc_ctx == NULL || si == NULL) return NULL;
584 return si->message_buffer;
587 static double calc_psnr(double d) {
588 if (d == 0) return 100;
589 return -10.0 * log(d) / log(10.0);
592 // dump accumulated statistics and reset accumulated values
593 const char *vpx_svc_dump_statistics(SvcContext *svc_ctx) {
594 int number_of_frames;
596 uint32_t bytes_total = 0;
597 double scale[COMPONENTS];
598 double psnr[COMPONENTS];
599 double mse[COMPONENTS];
602 SvcInternal_t *const si = get_svc_internal(svc_ctx);
603 if (svc_ctx == NULL || si == NULL) return NULL;
605 svc_log_reset(svc_ctx);
607 number_of_frames = si->psnr_pkt_received;
608 if (number_of_frames <= 0) return vpx_svc_get_message(svc_ctx);
610 svc_log(svc_ctx, SVC_LOG_INFO, "\n");
611 for (i = 0; i < svc_ctx->spatial_layers; ++i) {
613 svc_log(svc_ctx, SVC_LOG_INFO,
614 "Layer %d Average PSNR=[%2.3f, %2.3f, %2.3f, %2.3f], Bytes=[%u]\n",
615 i, (double)si->psnr_sum[i][0] / number_of_frames,
616 (double)si->psnr_sum[i][1] / number_of_frames,
617 (double)si->psnr_sum[i][2] / number_of_frames,
618 (double)si->psnr_sum[i][3] / number_of_frames, si->bytes_sum[i]);
619 // the following psnr calculation is deduced from ffmpeg.c#print_report
620 y_scale = si->width * si->height * 255.0 * 255.0 * number_of_frames;
622 scale[2] = scale[3] = y_scale / 4; // U or V
623 scale[0] = y_scale * 1.5; // total
625 for (j = 0; j < COMPONENTS; j++) {
626 psnr[j] = calc_psnr(si->sse_sum[i][j] / scale[j]);
627 mse[j] = si->sse_sum[i][j] * 255.0 * 255.0 / scale[j];
629 svc_log(svc_ctx, SVC_LOG_INFO,
630 "Layer %d Overall PSNR=[%2.3f, %2.3f, %2.3f, %2.3f]\n", i, psnr[0],
631 psnr[1], psnr[2], psnr[3]);
632 svc_log(svc_ctx, SVC_LOG_INFO,
633 "Layer %d Overall MSE=[%2.3f, %2.3f, %2.3f, %2.3f]\n", i, mse[0],
634 mse[1], mse[2], mse[3]);
636 bytes_total += si->bytes_sum[i];
637 // Clear sums for next time.
638 si->bytes_sum[i] = 0;
639 for (j = 0; j < COMPONENTS; ++j) {
640 si->psnr_sum[i][j] = 0;
641 si->sse_sum[i][j] = 0;
645 // only display statistics once
646 si->psnr_pkt_received = 0;
648 svc_log(svc_ctx, SVC_LOG_INFO, "Total Bytes=[%u]\n", bytes_total);
649 return vpx_svc_get_message(svc_ctx);
652 void vpx_svc_release(SvcContext *svc_ctx) {
654 if (svc_ctx == NULL) return;
655 // do not use get_svc_internal as it will unnecessarily allocate an
656 // SvcInternal_t if it was not already allocated
657 si = (SvcInternal_t *)svc_ctx->internal;
660 svc_ctx->internal = NULL;