svc_context.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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_SVC_CONTEXT_H_
  15. #define VPX_SVC_CONTEXT_H_
  16. #include "./vp8cx.h"
  17. #include "./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 log_print; // when set, printf log messages instead of returning the
  33. // message with svc_get_message
  34. int output_rc_stat; // for outputting rc stats
  35. int speed; // speed setting for codec
  36. int threads;
  37. int aqmode; // turns on aq-mode=3 (cyclic_refresh): 0=off, 1=on.
  38. // private storage for vpx_svc_encode
  39. void *internal;
  40. } SvcContext;
  41. #define OPTION_BUFFER_SIZE 1024
  42. #define COMPONENTS 4 // psnr & sse statistics maintained for total, y, u, v
  43. typedef struct SvcInternal {
  44. char options[OPTION_BUFFER_SIZE]; // set by vpx_svc_set_options
  45. // values extracted from option, quantizers
  46. vpx_svc_extra_cfg_t svc_params;
  47. int enable_auto_alt_ref[VPX_SS_MAX_LAYERS];
  48. int bitrates[VPX_MAX_LAYERS];
  49. // accumulated statistics
  50. double psnr_sum[VPX_SS_MAX_LAYERS][COMPONENTS]; // total/Y/U/V
  51. uint64_t sse_sum[VPX_SS_MAX_LAYERS][COMPONENTS];
  52. uint32_t bytes_sum[VPX_SS_MAX_LAYERS];
  53. // codec encoding values
  54. int width; // width of highest layer
  55. int height; // height of highest layer
  56. int kf_dist; // distance between keyframes
  57. // state variables
  58. int psnr_pkt_received;
  59. int layer;
  60. int use_multiple_frame_contexts;
  61. char message_buffer[2048];
  62. vpx_codec_ctx_t *codec_ctx;
  63. } SvcInternal_t;
  64. /**
  65. * Set SVC options
  66. * options are supplied as a single string separated by spaces
  67. * Format: encoding-mode=<i|ip|alt-ip|gf>
  68. * layers=<layer_count>
  69. * scaling-factors=<n1>/<d1>,<n2>/<d2>,...
  70. * quantizers=<q1>,<q2>,...
  71. */
  72. vpx_codec_err_t vpx_svc_set_options(SvcContext *svc_ctx, const char *options);
  73. /**
  74. * initialize SVC encoding
  75. */
  76. vpx_codec_err_t vpx_svc_init(SvcContext *svc_ctx, vpx_codec_ctx_t *codec_ctx,
  77. vpx_codec_iface_t *iface,
  78. vpx_codec_enc_cfg_t *cfg);
  79. /**
  80. * encode a frame of video with multiple layers
  81. */
  82. vpx_codec_err_t vpx_svc_encode(SvcContext *svc_ctx, vpx_codec_ctx_t *codec_ctx,
  83. struct vpx_image *rawimg, vpx_codec_pts_t pts,
  84. int64_t duration, int deadline);
  85. /**
  86. * finished with svc encoding, release allocated resources
  87. */
  88. void vpx_svc_release(SvcContext *svc_ctx);
  89. /**
  90. * dump accumulated statistics and reset accumulated values
  91. */
  92. const char *vpx_svc_dump_statistics(SvcContext *svc_ctx);
  93. /**
  94. * get status message from previous encode
  95. */
  96. const char *vpx_svc_get_message(const SvcContext *svc_ctx);
  97. #ifdef __cplusplus
  98. } // extern "C"
  99. #endif
  100. #endif // VPX_SVC_CONTEXT_H_