Ivan Maltz | 1ed0e1b | 2013-10-23 11:53:37 -0700 | [diff] [blame] | 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_SVC_CONTEXT_H_ |
| 17 | #define VPX_SVC_CONTEXT_H_ |
| 18 | |
Johann | e883c74 | 2013-12-16 13:15:26 -0800 | [diff] [blame] | 19 | #include "./vp8cx.h" |
| 20 | #include "./vpx_encoder.h" |
Ivan Maltz | 1ed0e1b | 2013-10-23 11:53:37 -0700 | [diff] [blame] | 21 | |
| 22 | #ifdef __cplusplus |
| 23 | extern "C" { |
| 24 | #endif |
| 25 | |
Ivan Maltz | 1ed0e1b | 2013-10-23 11:53:37 -0700 | [diff] [blame] | 26 | typedef enum SVC_LOG_LEVEL { |
| 27 | SVC_LOG_ERROR, |
| 28 | SVC_LOG_INFO, |
| 29 | SVC_LOG_DEBUG |
| 30 | } SVC_LOG_LEVEL; |
| 31 | |
Deb Mukherjee | 4c12046 | 2014-11-18 12:25:31 -0800 | [diff] [blame] | 32 | typedef struct { |
Ivan Maltz | 1ed0e1b | 2013-10-23 11:53:37 -0700 | [diff] [blame] | 33 | // public interface to svc_command options |
Minghai Shang | be3b08d | 2014-09-02 12:05:14 -0700 | [diff] [blame] | 34 | int spatial_layers; // number of spatial layers |
| 35 | int temporal_layers; // number of temporal layers |
Marco | c139b81 | 2015-05-21 16:15:37 -0700 | [diff] [blame] | 36 | int temporal_layering_mode; |
Ivan Maltz | 1ed0e1b | 2013-10-23 11:53:37 -0700 | [diff] [blame] | 37 | SVC_LOG_LEVEL log_level; // amount of information to display |
| 38 | int log_print; // when set, printf log messages instead of returning the |
| 39 | // message with svc_get_message |
Marco | c139b81 | 2015-05-21 16:15:37 -0700 | [diff] [blame] | 40 | int output_rc_stat; // for outputting rc stats |
| 41 | int speed; // speed setting for codec |
| 42 | int threads; |
James Zern | 0b74e5d | 2015-10-08 22:43:45 -0700 | [diff] [blame] | 43 | int aqmode; // turns on aq-mode=3 (cyclic_refresh): 0=off, 1=on. |
Ivan Maltz | 1ed0e1b | 2013-10-23 11:53:37 -0700 | [diff] [blame] | 44 | // private storage for vpx_svc_encode |
| 45 | void *internal; |
Deb Mukherjee | 4c12046 | 2014-11-18 12:25:31 -0800 | [diff] [blame] | 46 | } SvcContext; |
Deb Mukherjee | 0ba1542 | 2014-11-07 11:01:53 -0800 | [diff] [blame] | 47 | |
| 48 | #define OPTION_BUFFER_SIZE 1024 |
| 49 | #define COMPONENTS 4 // psnr & sse statistics maintained for total, y, u, v |
| 50 | |
| 51 | typedef struct SvcInternal { |
| 52 | char options[OPTION_BUFFER_SIZE]; // set by vpx_svc_set_options |
| 53 | |
| 54 | // values extracted from option, quantizers |
| 55 | vpx_svc_extra_cfg_t svc_params; |
| 56 | int enable_auto_alt_ref[VPX_SS_MAX_LAYERS]; |
| 57 | int bitrates[VPX_SS_MAX_LAYERS]; |
| 58 | |
| 59 | // accumulated statistics |
| 60 | double psnr_sum[VPX_SS_MAX_LAYERS][COMPONENTS]; // total/Y/U/V |
| 61 | uint64_t sse_sum[VPX_SS_MAX_LAYERS][COMPONENTS]; |
| 62 | uint32_t bytes_sum[VPX_SS_MAX_LAYERS]; |
| 63 | |
| 64 | // codec encoding values |
| 65 | int width; // width of highest layer |
| 66 | int height; // height of highest layer |
| 67 | int kf_dist; // distance between keyframes |
| 68 | |
| 69 | // state variables |
| 70 | int psnr_pkt_received; |
| 71 | int layer; |
| 72 | int use_multiple_frame_contexts; |
| 73 | |
| 74 | char message_buffer[2048]; |
| 75 | vpx_codec_ctx_t *codec_ctx; |
| 76 | } SvcInternal_t; |
Ivan Maltz | 1ed0e1b | 2013-10-23 11:53:37 -0700 | [diff] [blame] | 77 | |
| 78 | /** |
| 79 | * Set SVC options |
| 80 | * options are supplied as a single string separated by spaces |
| 81 | * Format: encoding-mode=<i|ip|alt-ip|gf> |
| 82 | * layers=<layer_count> |
| 83 | * scaling-factors=<n1>/<d1>,<n2>/<d2>,... |
| 84 | * quantizers=<q1>,<q2>,... |
| 85 | */ |
Deb Mukherjee | 4c12046 | 2014-11-18 12:25:31 -0800 | [diff] [blame] | 86 | vpx_codec_err_t vpx_svc_set_options(SvcContext *svc_ctx, const char *options); |
Ivan Maltz | 1ed0e1b | 2013-10-23 11:53:37 -0700 | [diff] [blame] | 87 | |
| 88 | /** |
Ivan Maltz | 1ed0e1b | 2013-10-23 11:53:37 -0700 | [diff] [blame] | 89 | * initialize SVC encoding |
| 90 | */ |
Deb Mukherjee | 4c12046 | 2014-11-18 12:25:31 -0800 | [diff] [blame] | 91 | vpx_codec_err_t vpx_svc_init(SvcContext *svc_ctx, |
Deb Mukherjee | 0ba1542 | 2014-11-07 11:01:53 -0800 | [diff] [blame] | 92 | vpx_codec_ctx_t *codec_ctx, |
Ivan Maltz | 1ed0e1b | 2013-10-23 11:53:37 -0700 | [diff] [blame] | 93 | vpx_codec_iface_t *iface, |
| 94 | vpx_codec_enc_cfg_t *cfg); |
| 95 | /** |
| 96 | * encode a frame of video with multiple layers |
| 97 | */ |
Deb Mukherjee | 4c12046 | 2014-11-18 12:25:31 -0800 | [diff] [blame] | 98 | vpx_codec_err_t vpx_svc_encode(SvcContext *svc_ctx, |
Deb Mukherjee | 0ba1542 | 2014-11-07 11:01:53 -0800 | [diff] [blame] | 99 | vpx_codec_ctx_t *codec_ctx, |
| 100 | struct vpx_image *rawimg, |
| 101 | vpx_codec_pts_t pts, |
Ivan Maltz | 1ed0e1b | 2013-10-23 11:53:37 -0700 | [diff] [blame] | 102 | int64_t duration, int deadline); |
| 103 | |
| 104 | /** |
| 105 | * finished with svc encoding, release allocated resources |
| 106 | */ |
Deb Mukherjee | 4c12046 | 2014-11-18 12:25:31 -0800 | [diff] [blame] | 107 | void vpx_svc_release(SvcContext *svc_ctx); |
Ivan Maltz | 1ed0e1b | 2013-10-23 11:53:37 -0700 | [diff] [blame] | 108 | |
| 109 | /** |
| 110 | * dump accumulated statistics and reset accumulated values |
| 111 | */ |
Deb Mukherjee | 4c12046 | 2014-11-18 12:25:31 -0800 | [diff] [blame] | 112 | const char *vpx_svc_dump_statistics(SvcContext *svc_ctx); |
Ivan Maltz | 1ed0e1b | 2013-10-23 11:53:37 -0700 | [diff] [blame] | 113 | |
| 114 | /** |
| 115 | * get status message from previous encode |
| 116 | */ |
Deb Mukherjee | 4c12046 | 2014-11-18 12:25:31 -0800 | [diff] [blame] | 117 | const char *vpx_svc_get_message(const SvcContext *svc_ctx); |
Ivan Maltz | 1ed0e1b | 2013-10-23 11:53:37 -0700 | [diff] [blame] | 118 | |
Ivan Maltz | 1ed0e1b | 2013-10-23 11:53:37 -0700 | [diff] [blame] | 119 | #ifdef __cplusplus |
| 120 | } // extern "C" |
| 121 | #endif |
| 122 | |
James Zern | 7386bde | 2013-12-15 18:26:15 -0800 | [diff] [blame] | 123 | #endif // VPX_SVC_CONTEXT_H_ |