tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

lookahead.h (4792B)


      1 /*
      2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
      3 *
      4 * This source code is subject to the terms of the BSD 2 Clause License and
      5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
      6 * was not distributed with this source code in the LICENSE file, you can
      7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
      8 * Media Patent License 1.0 was not distributed with this source code in the
      9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
     10 */
     11 
     12 /*!\file
     13 * \brief Describes look ahead buffer operations.
     14 */
     15 #ifndef AOM_AV1_ENCODER_LOOKAHEAD_H_
     16 #define AOM_AV1_ENCODER_LOOKAHEAD_H_
     17 
     18 #include <stdbool.h>
     19 
     20 #include "aom_scale/yv12config.h"
     21 #include "aom/aom_integer.h"
     22 
     23 #ifdef __cplusplus
     24 extern "C" {
     25 #endif
     26 
     27 /*!\cond */
     28 #define MAX_LAG_BUFFERS 48
     29 #define MAX_LAP_BUFFERS 48
     30 #define MAX_TOTAL_BUFFERS (MAX_LAG_BUFFERS + MAX_LAP_BUFFERS)
     31 #define LAP_LAG_IN_FRAMES 17
     32 
     33 struct lookahead_entry {
     34  YV12_BUFFER_CONFIG img;
     35  int64_t ts_start;
     36  int64_t ts_end;
     37  int display_idx;
     38  aom_enc_frame_flags_t flags;
     39 };
     40 
     41 // The max of past frames we want to keep in the queue.
     42 #define MAX_PRE_FRAMES 1
     43 
     44 enum { ENCODE_STAGE, LAP_STAGE, MAX_STAGES } UENUM1BYTE(COMPRESSOR_STAGE);
     45 
     46 struct read_ctx {
     47  int sz;       /* Number of buffers currently in the queue */
     48  int read_idx; /* Read index */
     49  int pop_sz;   /* Size to check for pop condition */
     50  int valid;    /* Is this ctx valid? */
     51 };
     52 
     53 struct lookahead_ctx {
     54  int max_sz;                            /* Absolute size of the queue */
     55  int write_idx;                         /* Write index */
     56  struct read_ctx read_ctxs[MAX_STAGES]; /* Read context */
     57  struct lookahead_entry *buf;           /* Buffer list */
     58  int push_frame_count; /* Number of frames that have been pushed in the queue*/
     59  uint8_t
     60      max_pre_frames; /* Maximum number of past frames allowed in the queue */
     61 };
     62 /*!\endcond */
     63 
     64 /**\brief Initializes the lookahead stage
     65 *
     66 * The lookahead stage is a queue of frame buffers on which some analysis
     67 * may be done when buffers are enqueued.
     68 */
     69 struct lookahead_ctx *av1_lookahead_init(
     70    int width, int height, int subsampling_x, int subsampling_y,
     71    int use_highbitdepth, int depth, int border_in_pixels, int byte_alignment,
     72    int num_lap_buffers, bool is_all_intra, bool alloc_pyramid);
     73 
     74 /**\brief Destroys the lookahead stage
     75 */
     76 void av1_lookahead_destroy(struct lookahead_ctx *ctx);
     77 
     78 /**\brief Check if lookahead buffer is full
     79 */
     80 int av1_lookahead_full(const struct lookahead_ctx *ctx);
     81 
     82 /**\brief Enqueue a source buffer
     83 *
     84 * This function will copy the source image into a new framebuffer with
     85 * the expected stride/border.
     86 *
     87 * \param[in] ctx               Pointer to the lookahead context
     88 * \param[in] src               Pointer to the image to enqueue
     89 * \param[in] ts_start          Timestamp for the start of this frame
     90 * \param[in] ts_end            Timestamp for the end of this frame
     91 * \param[in] use_highbitdepth  Tell if HBD is used
     92 * \param[in] alloc_pyramid     Whether to allocate a downsampling pyramid
     93 *                              for each frame buffer
     94 * \param[in] flags             Flags set on this frame
     95 */
     96 int av1_lookahead_push(struct lookahead_ctx *ctx, const YV12_BUFFER_CONFIG *src,
     97                       int64_t ts_start, int64_t ts_end, int use_highbitdepth,
     98                       bool alloc_pyramid, aom_enc_frame_flags_t flags);
     99 
    100 /**\brief Get the next source buffer to encode
    101 *
    102 * \param[in] ctx       Pointer to the lookahead context
    103 * \param[in] drain     Flag indicating the buffer should be drained
    104 *                      (return a buffer regardless of the current queue depth)
    105 * \param[in] stage     Encoder stage
    106 *
    107 * \retval Return NULL, if drain set and queue is empty, or if drain not set and
    108 * queue not of the configured depth.
    109 */
    110 struct lookahead_entry *av1_lookahead_pop(struct lookahead_ctx *ctx, int drain,
    111                                          COMPRESSOR_STAGE stage);
    112 
    113 /**\brief Get a future source buffer to encode
    114 *
    115 * \param[in] ctx       Pointer to the lookahead context
    116 * \param[in] index     Index of the frame to be returned, 0 == next frame
    117 * \param[in] stage     Encoder stage
    118 *
    119 * \retval Return NULL, if no buffer exists at the specified index
    120 */
    121 struct lookahead_entry *av1_lookahead_peek(struct lookahead_ctx *ctx, int index,
    122                                           COMPRESSOR_STAGE stage);
    123 
    124 /**\brief Get the number of frames currently in the lookahead queue
    125 */
    126 int av1_lookahead_depth(struct lookahead_ctx *ctx, COMPRESSOR_STAGE stage);
    127 
    128 /**\brief Get pop_sz value
    129 */
    130 int av1_lookahead_pop_sz(struct lookahead_ctx *ctx, COMPRESSOR_STAGE stage);
    131 
    132 #ifdef __cplusplus
    133 }  // extern "C"
    134 #endif
    135 
    136 #endif  // AOM_AV1_ENCODER_LOOKAHEAD_H_