svc_context.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. // private storage for vpx_svc_encode
  38. void *internal;
  39. } SvcContext;
  40. #define OPTION_BUFFER_SIZE 1024
  41. #define COMPONENTS 4 // psnr & sse statistics maintained for total, y, u, v
  42. typedef struct SvcInternal {
  43. char options[OPTION_BUFFER_SIZE]; // set by vpx_svc_set_options
  44. // values extracted from option, quantizers
  45. vpx_svc_extra_cfg_t svc_params;
  46. int enable_auto_alt_ref[VPX_SS_MAX_LAYERS];
  47. int bitrates[VPX_SS_MAX_LAYERS];
  48. // accumulated statistics
  49. double psnr_sum[VPX_SS_MAX_LAYERS][COMPONENTS]; // total/Y/U/V
  50. uint64_t sse_sum[VPX_SS_MAX_LAYERS][COMPONENTS];
  51. uint32_t bytes_sum[VPX_SS_MAX_LAYERS];
  52. // codec encoding values
  53. int width; // width of highest layer
  54. int height; // height of highest layer
  55. int kf_dist; // distance between keyframes
  56. // state variables
  57. int psnr_pkt_received;
  58. int layer;
  59. int use_multiple_frame_contexts;
  60. char message_buffer[2048];
  61. vpx_codec_ctx_t *codec_ctx;
  62. } SvcInternal_t;
  63. /**
  64. * Set SVC options
  65. * options are supplied as a single string separated by spaces
  66. * Format: encoding-mode=<i|ip|alt-ip|gf>
  67. * layers=<layer_count>
  68. * scaling-factors=<n1>/<d1>,<n2>/<d2>,...
  69. * quantizers=<q1>,<q2>,...
  70. */
  71. vpx_codec_err_t vpx_svc_set_options(SvcContext *svc_ctx, const char *options);
  72. /**
  73. * initialize SVC encoding
  74. */
  75. vpx_codec_err_t vpx_svc_init(SvcContext *svc_ctx,
  76. 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,
  83. vpx_codec_ctx_t *codec_ctx,
  84. struct vpx_image *rawimg,
  85. vpx_codec_pts_t pts,
  86. int64_t duration, int deadline);
  87. /**
  88. * finished with svc encoding, release allocated resources
  89. */
  90. void vpx_svc_release(SvcContext *svc_ctx);
  91. /**
  92. * dump accumulated statistics and reset accumulated values
  93. */
  94. const char *vpx_svc_dump_statistics(SvcContext *svc_ctx);
  95. /**
  96. * get status message from previous encode
  97. */
  98. const char *vpx_svc_get_message(const SvcContext *svc_ctx);
  99. #ifdef __cplusplus
  100. } // extern "C"
  101. #endif
  102. #endif // VPX_SVC_CONTEXT_H_