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