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