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