onyx.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /*
  2. * Copyright (c) 2010 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. #ifndef VPX_VP8_COMMON_ONYX_H_
  11. #define VPX_VP8_COMMON_ONYX_H_
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #include "vpx_config.h"
  16. #include "vpx/internal/vpx_codec_internal.h"
  17. #include "vpx/vp8cx.h"
  18. #include "vpx/vpx_encoder.h"
  19. #include "vpx_scale/yv12config.h"
  20. #include "ppflags.h"
  21. struct VP8_COMP;
  22. /* Create/destroy static data structures. */
  23. typedef enum {
  24. NORMAL = 0,
  25. FOURFIVE = 1,
  26. THREEFIVE = 2,
  27. ONETWO = 3
  28. } VPX_SCALING;
  29. typedef enum {
  30. USAGE_LOCAL_FILE_PLAYBACK = 0x0,
  31. USAGE_STREAM_FROM_SERVER = 0x1,
  32. USAGE_CONSTRAINED_QUALITY = 0x2,
  33. USAGE_CONSTANT_QUALITY = 0x3
  34. } END_USAGE;
  35. typedef enum {
  36. MODE_REALTIME = 0x0,
  37. MODE_GOODQUALITY = 0x1,
  38. MODE_BESTQUALITY = 0x2,
  39. MODE_FIRSTPASS = 0x3,
  40. MODE_SECONDPASS = 0x4,
  41. MODE_SECONDPASS_BEST = 0x5
  42. } MODE;
  43. typedef enum {
  44. FRAMEFLAGS_KEY = 1,
  45. FRAMEFLAGS_GOLDEN = 2,
  46. FRAMEFLAGS_ALTREF = 4
  47. } FRAMETYPE_FLAGS;
  48. #include <assert.h>
  49. static INLINE void Scale2Ratio(int mode, int *hr, int *hs) {
  50. switch (mode) {
  51. case NORMAL:
  52. *hr = 1;
  53. *hs = 1;
  54. break;
  55. case FOURFIVE:
  56. *hr = 4;
  57. *hs = 5;
  58. break;
  59. case THREEFIVE:
  60. *hr = 3;
  61. *hs = 5;
  62. break;
  63. case ONETWO:
  64. *hr = 1;
  65. *hs = 2;
  66. break;
  67. default:
  68. *hr = 1;
  69. *hs = 1;
  70. assert(0);
  71. break;
  72. }
  73. }
  74. typedef struct {
  75. /* 4 versions of bitstream defined:
  76. * 0 best quality/slowest decode, 3 lowest quality/fastest decode
  77. */
  78. int Version;
  79. int Width;
  80. int Height;
  81. struct vpx_rational timebase;
  82. unsigned int target_bandwidth; /* kilobits per second */
  83. /* Parameter used for applying denoiser.
  84. * For temporal denoiser: noise_sensitivity = 0 means off,
  85. * noise_sensitivity = 1 means temporal denoiser on for Y channel only,
  86. * noise_sensitivity = 2 means temporal denoiser on for all channels.
  87. * noise_sensitivity = 3 means aggressive denoising mode.
  88. * noise_sensitivity >= 4 means adaptive denoising mode.
  89. * Temporal denoiser is enabled via the configuration option:
  90. * CONFIG_TEMPORAL_DENOISING.
  91. * For spatial denoiser: noise_sensitivity controls the amount of
  92. * pre-processing blur: noise_sensitivity = 0 means off.
  93. * Spatial denoiser invoked under !CONFIG_TEMPORAL_DENOISING.
  94. */
  95. int noise_sensitivity;
  96. /* parameter used for sharpening output: recommendation 0: */
  97. int Sharpness;
  98. int cpu_used;
  99. unsigned int rc_max_intra_bitrate_pct;
  100. /* percent of rate boost for golden frame in CBR mode. */
  101. unsigned int gf_cbr_boost_pct;
  102. unsigned int screen_content_mode;
  103. /* mode ->
  104. *(0)=Realtime/Live Encoding. This mode is optimized for realtim
  105. * encoding (for example, capturing a television signal or feed
  106. * from a live camera). ( speed setting controls how fast )
  107. *(1)=Good Quality Fast Encoding. The encoder balances quality with
  108. * the amount of time it takes to encode the output. ( speed
  109. * setting controls how fast )
  110. *(2)=One Pass - Best Quality. The encoder places priority on the
  111. * quality of the output over encoding speed. The output is
  112. * compressed at the highest possible quality. This option takes
  113. * the longest amount of time to encode. ( speed setting ignored
  114. * )
  115. *(3)=Two Pass - First Pass. The encoder generates a file of
  116. * statistics for use in the second encoding pass. ( speed
  117. * setting controls how fast )
  118. *(4)=Two Pass - Second Pass. The encoder uses the statistics that
  119. * were generated in the first encoding pass to create the
  120. * compressed output. ( speed setting controls how fast )
  121. *(5)=Two Pass - Second Pass Best. The encoder uses the statistics
  122. * that were generated in the first encoding pass to create the
  123. * compressed output using the highest possible quality, and
  124. * taking a longer amount of time to encode.. ( speed setting
  125. * ignored )
  126. */
  127. int Mode;
  128. /* Key Framing Operations */
  129. int auto_key; /* automatically detect cut scenes */
  130. int key_freq; /* maximum distance to key frame. */
  131. /* lagged compression (if allow_lag == 0 lag_in_frames is ignored) */
  132. int allow_lag;
  133. int lag_in_frames; /* how many frames lag before we start encoding */
  134. /*
  135. * DATARATE CONTROL OPTIONS
  136. */
  137. int end_usage; /* vbr or cbr */
  138. /* buffer targeting aggressiveness */
  139. int under_shoot_pct;
  140. int over_shoot_pct;
  141. /* buffering parameters */
  142. int64_t starting_buffer_level;
  143. int64_t optimal_buffer_level;
  144. int64_t maximum_buffer_size;
  145. int64_t starting_buffer_level_in_ms;
  146. int64_t optimal_buffer_level_in_ms;
  147. int64_t maximum_buffer_size_in_ms;
  148. /* controlling quality */
  149. int fixed_q;
  150. int worst_allowed_q;
  151. int best_allowed_q;
  152. int cq_level;
  153. /* allow internal resizing */
  154. int allow_spatial_resampling;
  155. int resample_down_water_mark;
  156. int resample_up_water_mark;
  157. /* allow internal frame rate alterations */
  158. int allow_df;
  159. int drop_frames_water_mark;
  160. /* two pass datarate control */
  161. int two_pass_vbrbias;
  162. int two_pass_vbrmin_section;
  163. int two_pass_vbrmax_section;
  164. /*
  165. * END DATARATE CONTROL OPTIONS
  166. */
  167. /* these parameters aren't to be used in final build don't use!!! */
  168. int play_alternate;
  169. int alt_freq;
  170. int alt_q;
  171. int key_q;
  172. int gold_q;
  173. int multi_threaded; /* how many threads to run the encoder on */
  174. int token_partitions; /* how many token partitions to create */
  175. /* early breakout threshold: for video conf recommend 800 */
  176. int encode_breakout;
  177. /* Bitfield defining the error resiliency features to enable.
  178. * Can provide decodable frames after losses in previous
  179. * frames and decodable partitions after losses in the same frame.
  180. */
  181. unsigned int error_resilient_mode;
  182. int arnr_max_frames;
  183. int arnr_strength;
  184. int arnr_type;
  185. vpx_fixed_buf_t two_pass_stats_in;
  186. struct vpx_codec_pkt_list *output_pkt_list;
  187. vp8e_tuning tuning;
  188. /* Temporal scaling parameters */
  189. unsigned int number_of_layers;
  190. unsigned int target_bitrate[VPX_TS_MAX_PERIODICITY];
  191. unsigned int rate_decimator[VPX_TS_MAX_PERIODICITY];
  192. unsigned int periodicity;
  193. unsigned int layer_id[VPX_TS_MAX_PERIODICITY];
  194. #if CONFIG_MULTI_RES_ENCODING
  195. /* Number of total resolutions encoded */
  196. unsigned int mr_total_resolutions;
  197. /* Current encoder ID */
  198. unsigned int mr_encoder_id;
  199. /* Down-sampling factor */
  200. vpx_rational_t mr_down_sampling_factor;
  201. /* Memory location to store low-resolution encoder's mode info */
  202. void *mr_low_res_mode_info;
  203. #endif
  204. } VP8_CONFIG;
  205. void vp8_initialize();
  206. struct VP8_COMP *vp8_create_compressor(VP8_CONFIG *oxcf);
  207. void vp8_remove_compressor(struct VP8_COMP **comp);
  208. void vp8_init_config(struct VP8_COMP *onyx, VP8_CONFIG *oxcf);
  209. void vp8_change_config(struct VP8_COMP *cpi, VP8_CONFIG *oxcf);
  210. int vp8_receive_raw_frame(struct VP8_COMP *cpi, unsigned int frame_flags,
  211. YV12_BUFFER_CONFIG *sd, int64_t time_stamp,
  212. int64_t end_time);
  213. int vp8_get_compressed_data(struct VP8_COMP *cpi, unsigned int *frame_flags,
  214. size_t *size, unsigned char *dest,
  215. unsigned char *dest_end, int64_t *time_stamp,
  216. int64_t *time_end, int flush);
  217. int vp8_get_preview_raw_frame(struct VP8_COMP *cpi, YV12_BUFFER_CONFIG *dest,
  218. vp8_ppflags_t *flags);
  219. int vp8_use_as_reference(struct VP8_COMP *cpi, int ref_frame_flags);
  220. int vp8_update_reference(struct VP8_COMP *cpi, int ref_frame_flags);
  221. int vp8_get_reference(struct VP8_COMP *cpi,
  222. enum vpx_ref_frame_type ref_frame_flag,
  223. YV12_BUFFER_CONFIG *sd);
  224. int vp8_set_reference(struct VP8_COMP *cpi,
  225. enum vpx_ref_frame_type ref_frame_flag,
  226. YV12_BUFFER_CONFIG *sd);
  227. int vp8_update_entropy(struct VP8_COMP *cpi, int update);
  228. int vp8_set_roimap(struct VP8_COMP *cpi, unsigned char *map, unsigned int rows,
  229. unsigned int cols, int delta_q[4], int delta_lf[4],
  230. unsigned int threshold[4]);
  231. int vp8_set_active_map(struct VP8_COMP *cpi, unsigned char *map,
  232. unsigned int rows, unsigned int cols);
  233. int vp8_set_internal_size(struct VP8_COMP *cpi, VPX_SCALING horiz_mode,
  234. VPX_SCALING vert_mode);
  235. int vp8_get_quantizer(struct VP8_COMP *cpi);
  236. #ifdef __cplusplus
  237. }
  238. #endif
  239. #endif // VPX_VP8_COMMON_ONYX_H_