1 /* 2 * Copyright (c) 2021, 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 #ifndef AOM_AV1_ENCODER_THIRDPASS_H_ 13 #define AOM_AV1_ENCODER_THIRDPASS_H_ 14 15 #ifdef __cplusplus 16 extern "C" { 17 #endif 18 19 #include "av1/encoder/firstpass.h" 20 #include "av1/encoder/ratectrl.h" 21 22 // TODO(bohanli): optimize this number 23 #define MAX_THIRD_PASS_BUF (2 * MAX_GF_INTERVAL + 1) 24 25 // Struct to store useful information about a frame for the third pass. 26 // The members are extracted from the decoder by function get_frame_info. 27 typedef struct { 28 int base_q_idx; 29 int is_show_existing_frame; 30 int is_show_frame; 31 FRAME_TYPE frame_type; 32 unsigned int order_hint; 33 } THIRD_PASS_FRAME_INFO; 34 35 typedef struct { 36 /* --- Input and decoding related members --- */ 37 // the input file 38 const char *input_file_name; 39 #if CONFIG_THREE_PASS 40 // input context 41 struct AvxInputContext *input_ctx; 42 #endif 43 // decoder codec context 44 aom_codec_ctx_t decoder; 45 // start of the frame in buf 46 const unsigned char *frame; 47 // end of the frame(s) in buf 48 const unsigned char *end_frame; 49 // whether we still have following frames in buf 50 int have_frame; 51 // pointer to buffer for the read frames 52 uint8_t *buf; 53 // size of data in buffer 54 size_t bytes_in_buffer; 55 // current buffer size 56 size_t buffer_size; 57 // error info pointer 58 struct aom_internal_error_info *err_info; 59 60 /* --- Members for third pass encoding --- */ 61 // Array to store info about each frame. 62 // frame_info[0] should point to the current frame. 63 THIRD_PASS_FRAME_INFO frame_info[MAX_THIRD_PASS_BUF]; 64 // number of frames available in frame_info 65 int frame_info_count; 66 // the end of the previous GOP (order hint) 67 int prev_gop_end; 68 } THIRD_PASS_DEC_CTX; 69 70 void av1_init_thirdpass_ctx(AV1_COMMON *cm, THIRD_PASS_DEC_CTX **ctx, 71 const char *file); 72 void av1_free_thirdpass_ctx(THIRD_PASS_DEC_CTX *ctx); 73 74 // Set the GOP structure from the twopass bitstream. 75 // TODO(bohanli): this is currently a skeleton and we only return the gop 76 // length. This function also saves all frame information in the array 77 // ctx->frame_info for this GOP. 78 void av1_set_gop_third_pass(THIRD_PASS_DEC_CTX *ctx, GF_GROUP *gf_group, 79 int order_hint_bits, int *gf_len); 80 81 // Pop one frame out of the array ctx->frame_info. This function is used to make 82 // sure that frame_info[0] always corresponds to the current frame. 83 void av1_pop_third_pass_info(THIRD_PASS_DEC_CTX *ctx); 84 85 #ifdef __cplusplus 86 } // extern "C" 87 #endif 88 89 #endif // AOM_AV1_ENCODER_THIRDPASS_H_ 90