vp9_lookahead.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright (c) 2011 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 VP9_ENCODER_VP9_LOOKAHEAD_H_
  11. #define VP9_ENCODER_VP9_LOOKAHEAD_H_
  12. #include "vpx_scale/yv12config.h"
  13. #include "vpx/vpx_integer.h"
  14. #if CONFIG_SPATIAL_SVC
  15. #include "vpx/vp8cx.h"
  16. #include "vpx/vpx_encoder.h"
  17. #endif
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. #define MAX_LAG_BUFFERS 25
  22. struct lookahead_entry {
  23. YV12_BUFFER_CONFIG img;
  24. int64_t ts_start;
  25. int64_t ts_end;
  26. unsigned int flags;
  27. };
  28. // The max of past frames we want to keep in the queue.
  29. #define MAX_PRE_FRAMES 1
  30. struct lookahead_ctx {
  31. unsigned int max_sz; /* Absolute size of the queue */
  32. unsigned int sz; /* Number of buffers currently in the queue */
  33. unsigned int read_idx; /* Read index */
  34. unsigned int write_idx; /* Write index */
  35. struct lookahead_entry *buf; /* Buffer list */
  36. };
  37. /**\brief Initializes the lookahead stage
  38. *
  39. * The lookahead stage is a queue of frame buffers on which some analysis
  40. * may be done when buffers are enqueued.
  41. */
  42. struct lookahead_ctx *vp9_lookahead_init(unsigned int width,
  43. unsigned int height,
  44. unsigned int subsampling_x,
  45. unsigned int subsampling_y,
  46. #if CONFIG_VP9_HIGHBITDEPTH
  47. int use_highbitdepth,
  48. #endif
  49. unsigned int depth);
  50. /**\brief Destroys the lookahead stage
  51. */
  52. void vp9_lookahead_destroy(struct lookahead_ctx *ctx);
  53. /**\brief Enqueue a source buffer
  54. *
  55. * This function will copy the source image into a new framebuffer with
  56. * the expected stride/border.
  57. *
  58. * If active_map is non-NULL and there is only one frame in the queue, then copy
  59. * only active macroblocks.
  60. *
  61. * \param[in] ctx Pointer to the lookahead context
  62. * \param[in] src Pointer to the image to enqueue
  63. * \param[in] ts_start Timestamp for the start of this frame
  64. * \param[in] ts_end Timestamp for the end of this frame
  65. * \param[in] flags Flags set on this frame
  66. * \param[in] active_map Map that specifies which macroblock is active
  67. */
  68. int vp9_lookahead_push(struct lookahead_ctx *ctx, YV12_BUFFER_CONFIG *src,
  69. int64_t ts_start, int64_t ts_end,
  70. #if CONFIG_VP9_HIGHBITDEPTH
  71. int use_highbitdepth,
  72. #endif
  73. unsigned int flags);
  74. /**\brief Get the next source buffer to encode
  75. *
  76. *
  77. * \param[in] ctx Pointer to the lookahead context
  78. * \param[in] drain Flag indicating the buffer should be drained
  79. * (return a buffer regardless of the current queue depth)
  80. *
  81. * \retval NULL, if drain set and queue is empty
  82. * \retval NULL, if drain not set and queue not of the configured depth
  83. */
  84. struct lookahead_entry *vp9_lookahead_pop(struct lookahead_ctx *ctx,
  85. int drain);
  86. /**\brief Get a future source buffer to encode
  87. *
  88. * \param[in] ctx Pointer to the lookahead context
  89. * \param[in] index Index of the frame to be returned, 0 == next frame
  90. *
  91. * \retval NULL, if no buffer exists at the specified index
  92. */
  93. struct lookahead_entry *vp9_lookahead_peek(struct lookahead_ctx *ctx,
  94. int index);
  95. /**\brief Get the number of frames currently in the lookahead queue
  96. *
  97. * \param[in] ctx Pointer to the lookahead context
  98. */
  99. unsigned int vp9_lookahead_depth(struct lookahead_ctx *ctx);
  100. #ifdef __cplusplus
  101. } // extern "C"
  102. #endif
  103. #endif // VP9_ENCODER_VP9_LOOKAHEAD_H_