1 /* 2 * 3 * Copyright 2015 Rockchip Electronics Co. LTD 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 #ifndef __HAL_ENC_TASK__ 19 #define __HAL_ENC_TASK__ 20 21 #include "mpp_time.h" 22 23 #include "hal_task.h" 24 #include "mpp_rc_defs.h" 25 #include "mpp_enc_refs.h" 26 27 #define HAL_ENC_TASK_ERR_INIT 0x00000001 28 #define HAL_ENC_TASK_ERR_ALLOC 0x00000010 29 #define HAL_ENC_TASK_ERR_EXTRAINFO 0x00000100 30 #define HAL_ENC_TASK_ERR_GENREG 0x00001000 31 #define HAL_ENC_TASK_ERR_START 0x00010000 32 #define HAL_ENC_TASK_ERR_WAIT 0x00100000 33 34 typedef struct HalEncTaskFlag_t { 35 RK_U32 err; 36 RK_S32 drop_by_fps; 37 RK_S32 reg_idx; 38 /* hal buf index */ 39 RK_S32 curr_idx; 40 RK_S32 refr_idx; 41 } HalEncTaskFlag; 42 43 typedef struct MppSyntax_t { 44 RK_U32 number; 45 void *data; 46 } MppSyntax; 47 48 typedef struct HalEncTask_t { 49 RK_U32 valid; 50 51 // rate control data channel 52 EncRcTask *rc_task; 53 54 // cpb reference force config 55 MppEncRefFrmUsrCfg *frm_cfg; 56 57 // current tesk protocol syntax information 58 MppSyntax syntax; 59 MppSyntax hal_ret; 60 61 /* 62 * Current tesk output stream buffer 63 * 64 * Usage and flow of changing task length and packet length 65 * 66 * 1. length is runtime updated for each stage. 67 * header_length / sei_length / hw_length are for recording. 68 * 69 * 2. When writing vps/sps/pps encoder should update length. 70 * Then length will be kept before next stage is done. 71 * For example when vps/sps/pps were inserted and slice data need 72 * reencoding the hal should update length at the final loop. 73 * 74 * 3. length in task and length in packet should be updated at the same 75 * time. Encoder flow need to check these two length between stages. 76 */ 77 MppPacket packet; 78 MppBuffer output; 79 RK_S32 header_length; 80 RK_S32 sei_length; 81 RK_S32 hw_length; 82 RK_U32 length; 83 /* For reenc process and record segment number before hardware encoding */ 84 RK_U32 segment_nb; 85 86 // current tesk input slot buffer 87 MppFrame frame; 88 MppBuffer input; 89 90 // task stopwatch for timing 91 MppStopwatch stopwatch; 92 93 // current md info output buffer 94 MppBuffer md_info; 95 96 // low delay mode part output information 97 RK_U32 part_first; 98 RK_U32 part_last; 99 RK_U32 part_count; 100 RK_U8 *part_pos; 101 size_t part_length; 102 103 HalEncTaskFlag flags; 104 } HalEncTask; 105 106 /* encoder internal work flow */ 107 typedef union EncAsyncStatus_u { 108 RK_U32 val; 109 struct { 110 RK_U32 task_hnd_rdy : 1; 111 RK_U32 task_in_rdy : 1; 112 RK_U32 task_out_rdy : 1; 113 114 RK_U32 frm_pkt_rdy : 1; 115 116 RK_U32 hal_task_reset_rdy : 1; // reset hal task to start 117 RK_U32 rc_check_frm_drop : 1; // rc stage 118 RK_U32 pkt_buf_rdy : 1; // prepare pkt buf 119 120 RK_U32 enc_start : 1; // enc stage 121 RK_U32 refs_force_update : 1; // enc stage 122 RK_U32 low_delay_again : 1; // enc stage low delay output again 123 124 RK_U32 enc_backup : 1; // enc stage 125 RK_U32 enc_restore : 1; // reenc flow start point 126 RK_U32 enc_proc_dpb : 1; // enc stage 127 RK_U32 rc_frm_start : 1; // rc stage 128 RK_U32 check_type_reenc : 1; // flow checkpoint if reenc -> enc_restore 129 RK_U32 enc_proc_hal : 1; // enc stage 130 RK_U32 hal_get_task : 1; // hal stage 131 RK_U32 rc_hal_start : 1; // rc stage 132 RK_U32 hal_gen_reg : 1; // hal stage 133 RK_U32 hal_start : 1; // hal stage 134 RK_U32 hal_wait : 1; // hal stage NOTE: special in low delay mode 135 RK_U32 rc_hal_end : 1; // rc stage 136 RK_U32 hal_ret_task : 1; // hal stage 137 RK_U32 enc_update_hal : 1; // enc stage 138 RK_U32 rc_frm_end : 1; // rc stage 139 RK_U32 check_rc_reenc : 1; // flow checkpoint if reenc -> enc_restore 140 RK_U32 enc_done : 1; // done stage 141 RK_U32 slice_out_done : 1; 142 }; 143 } EncAsyncStatus; 144 145 typedef struct EncAsyncTaskInfo_t { 146 RK_S32 seq_idx; 147 EncAsyncStatus status; 148 RK_S64 pts; 149 150 HalEncTask task; 151 EncRcTask rc; 152 MppEncRefFrmUsrCfg usr; 153 } EncAsyncTaskInfo; 154 155 #endif /* __HAL_ENC_TASK__ */ 156