1 /* 2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved. 3 * 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. 9 */ 10 11 /** 12 * SvcContext - input parameters and state to encode a multi-layered 13 * spatial SVC frame 14 */ 15 16 #ifndef VPX_EXAMPLES_SVC_CONTEXT_H_ 17 #define VPX_EXAMPLES_SVC_CONTEXT_H_ 18 19 #include "vpx/vp8cx.h" 20 #include "vpx/vpx_encoder.h" 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 typedef enum SVC_LOG_LEVEL { 27 SVC_LOG_ERROR, 28 SVC_LOG_INFO, 29 SVC_LOG_DEBUG 30 } SVC_LOG_LEVEL; 31 32 typedef struct { 33 // public interface to svc_command options 34 int spatial_layers; // number of spatial layers 35 int temporal_layers; // number of temporal layers 36 int temporal_layering_mode; 37 SVC_LOG_LEVEL log_level; // amount of information to display 38 int output_rc_stat; // for outputting rc stats 39 int speed; // speed setting for codec 40 int threads; 41 int aqmode; // turns on aq-mode=3 (cyclic_refresh): 0=off, 1=on. 42 // private storage for vpx_svc_encode 43 void *internal; 44 } SvcContext; 45 46 #define OPTION_BUFFER_SIZE 1024 47 #define COMPONENTS 4 // psnr & sse statistics maintained for total, y, u, v 48 49 typedef struct SvcInternal { 50 char options[OPTION_BUFFER_SIZE]; // set by vpx_svc_set_options 51 52 // values extracted from option, quantizers 53 vpx_svc_extra_cfg_t svc_params; 54 int enable_auto_alt_ref[VPX_SS_MAX_LAYERS]; 55 int bitrates[VPX_MAX_LAYERS]; 56 57 // accumulated statistics 58 double psnr_sum[VPX_SS_MAX_LAYERS][COMPONENTS]; // total/Y/U/V 59 uint64_t sse_sum[VPX_SS_MAX_LAYERS][COMPONENTS]; 60 uint32_t bytes_sum[VPX_SS_MAX_LAYERS]; 61 62 // codec encoding values 63 int width; // width of highest layer 64 int height; // height of highest layer 65 int kf_dist; // distance between keyframes 66 67 // state variables 68 int psnr_pkt_received; 69 int layer; 70 int use_multiple_frame_contexts; 71 72 vpx_codec_ctx_t *codec_ctx; 73 } SvcInternal_t; 74 75 /** 76 * Set SVC options 77 * options are supplied as a single string separated by spaces 78 * Format: encoding-mode=<i|ip|alt-ip|gf> 79 * layers=<layer_count> 80 * scaling-factors=<n1>/<d1>,<n2>/<d2>,... 81 * quantizers=<q1>,<q2>,... 82 */ 83 vpx_codec_err_t vpx_svc_set_options(SvcContext *svc_ctx, const char *options); 84 85 /** 86 * initialize SVC encoding 87 */ 88 vpx_codec_err_t vpx_svc_init(SvcContext *svc_ctx, vpx_codec_ctx_t *codec_ctx, 89 vpx_codec_iface_t *iface, 90 vpx_codec_enc_cfg_t *cfg); 91 /** 92 * encode a frame of video with multiple layers 93 */ 94 vpx_codec_err_t vpx_svc_encode(SvcContext *svc_ctx, vpx_codec_ctx_t *codec_ctx, 95 struct vpx_image *rawimg, vpx_codec_pts_t pts, 96 int64_t duration, int deadline); 97 98 /** 99 * finished with svc encoding, release allocated resources 100 */ 101 void vpx_svc_release(SvcContext *svc_ctx); 102 103 /** 104 * dump accumulated statistics and reset accumulated values 105 */ 106 void vpx_svc_dump_statistics(SvcContext *svc_ctx); 107 108 #ifdef __cplusplus 109 } // extern "C" 110 #endif 111 112 #endif // VPX_EXAMPLES_SVC_CONTEXT_H_ 113