lookahead.h 3.84 KB
Newer Older
Jingning Han's avatar
Jingning Han committed
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Jingning Han's avatar
Jingning Han committed
3
 *
4 5 6 7 8 9
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Jingning Han's avatar
Jingning Han committed
10 11
 */

12 13
#ifndef AV1_ENCODER_LOOKAHEAD_H_
#define AV1_ENCODER_LOOKAHEAD_H_
Jingning Han's avatar
Jingning Han committed
14

15
#include "aom_scale/yv12config.h"
16
#include "aom/aom_integer.h"
Jingning Han's avatar
Jingning Han committed
17 18 19 20 21 22 23 24

#ifdef __cplusplus
extern "C" {
#endif

#define MAX_LAG_BUFFERS 25

struct lookahead_entry {
25 26 27
  YV12_BUFFER_CONFIG img;
  int64_t ts_start;
  int64_t ts_end;
28
  aom_enc_frame_flags_t flags;
Jingning Han's avatar
Jingning Han committed
29 30 31 32 33 34
};

// The max of past frames we want to keep in the queue.
#define MAX_PRE_FRAMES 1

struct lookahead_ctx {
35 36 37 38
  int max_sz;                  /* Absolute size of the queue */
  int sz;                      /* Number of buffers currently in the queue */
  int read_idx;                /* Read index */
  int write_idx;               /* Write index */
Jingning Han's avatar
Jingning Han committed
39 40 41 42 43 44 45 46
  struct lookahead_entry *buf; /* Buffer list */
};

/**\brief Initializes the lookahead stage
 *
 * The lookahead stage is a queue of frame buffers on which some analysis
 * may be done when buffers are enqueued.
 */
47 48 49 50
struct lookahead_ctx *av1_lookahead_init(unsigned int width,
                                         unsigned int height,
                                         unsigned int subsampling_x,
                                         unsigned int subsampling_y,
51
#if CONFIG_HIGHBITDEPTH
52
                                         int use_highbitdepth,
Jingning Han's avatar
Jingning Han committed
53
#endif
54
                                         unsigned int depth);
Jingning Han's avatar
Jingning Han committed
55 56 57

/**\brief Destroys the lookahead stage
 */
58
void av1_lookahead_destroy(struct lookahead_ctx *ctx);
Jingning Han's avatar
Jingning Han committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

/**\brief Enqueue a source buffer
 *
 * This function will copy the source image into a new framebuffer with
 * the expected stride/border.
 *
 * If active_map is non-NULL and there is only one frame in the queue, then copy
 * only active macroblocks.
 *
 * \param[in] ctx         Pointer to the lookahead context
 * \param[in] src         Pointer to the image to enqueue
 * \param[in] ts_start    Timestamp for the start of this frame
 * \param[in] ts_end      Timestamp for the end of this frame
 * \param[in] flags       Flags set on this frame
 * \param[in] active_map  Map that specifies which macroblock is active
 */
75 76
int av1_lookahead_push(struct lookahead_ctx *ctx, YV12_BUFFER_CONFIG *src,
                       int64_t ts_start, int64_t ts_end,
77
#if CONFIG_HIGHBITDEPTH
78
                       int use_highbitdepth,
Jingning Han's avatar
Jingning Han committed
79
#endif
80
                       aom_enc_frame_flags_t flags);
Jingning Han's avatar
Jingning Han committed
81 82 83 84 85 86 87 88 89 90 91

/**\brief Get the next source buffer to encode
 *
 *
 * \param[in] ctx       Pointer to the lookahead context
 * \param[in] drain     Flag indicating the buffer should be drained
 *                      (return a buffer regardless of the current queue depth)
 *
 * \retval NULL, if drain set and queue is empty
 * \retval NULL, if drain not set and queue not of the configured depth
 */
92
struct lookahead_entry *av1_lookahead_pop(struct lookahead_ctx *ctx, int drain);
Jingning Han's avatar
Jingning Han committed
93 94 95 96 97 98 99 100

/**\brief Get a future source buffer to encode
 *
 * \param[in] ctx       Pointer to the lookahead context
 * \param[in] index     Index of the frame to be returned, 0 == next frame
 *
 * \retval NULL, if no buffer exists at the specified index
 */
101 102
struct lookahead_entry *av1_lookahead_peek(struct lookahead_ctx *ctx,
                                           int index);
Jingning Han's avatar
Jingning Han committed
103 104 105 106 107

/**\brief Get the number of frames currently in the lookahead queue
 *
 * \param[in] ctx       Pointer to the lookahead context
 */
108
unsigned int av1_lookahead_depth(struct lookahead_ctx *ctx);
Jingning Han's avatar
Jingning Han committed
109 110 111 112 113

#ifdef __cplusplus
}  // extern "C"
#endif

114
#endif  // AV1_ENCODER_LOOKAHEAD_H_