2
0

svc_context.h 3.2 KB

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