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