00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "global.h"
00018
00019 #include "rdopt_coding_state.h"
00020 #include "cabac.h"
00021
00022
00023
00024
00025
00026
00027
00028
00029 void delete_coding_state (CSobj *cs)
00030 {
00031 if (cs != NULL)
00032 {
00033
00034 if (cs->encenv != NULL) free (cs->encenv);
00035 if (cs->bitstream != NULL) free (cs->bitstream);
00036
00037
00038 delete_contexts_MotionInfo (cs->mot_ctx);
00039 delete_contexts_TextureInfo (cs->tex_ctx);
00040
00041
00042 free (cs);
00043 cs=NULL;
00044 }
00045 }
00046
00047
00048
00049
00050
00051
00052
00053
00054 CSobj *create_coding_state (InputParameters *p_Inp)
00055 {
00056 CSobj *cs;
00057
00058
00059 if ((cs = (CSobj *) calloc (1, sizeof(CSobj))) == NULL)
00060 no_mem_exit("init_coding_state: cs");
00061
00062
00063 cs->no_part = p_Inp->partition_mode == 0 ? 1 : 3;
00064 if (p_Inp->symbol_mode == CABAC)
00065 {
00066 if ((cs->encenv = (EncodingEnvironment*) calloc (cs->no_part, sizeof(EncodingEnvironment))) == NULL)
00067 no_mem_exit("init_coding_state: cs->encenv");
00068 }
00069 else
00070 {
00071 cs->encenv = NULL;
00072 }
00073 if ((cs->bitstream = (Bitstream*) calloc (cs->no_part, sizeof(Bitstream))) == NULL)
00074 no_mem_exit("init_coding_state: cs->bitstream");
00075
00076
00077 if (p_Inp->symbol_mode == CABAC)
00078 {
00079 cs->mot_ctx = create_contexts_MotionInfo ();
00080 cs->tex_ctx = create_contexts_TextureInfo();
00081 }
00082 else
00083 {
00084 cs->mot_ctx = NULL;
00085 cs->tex_ctx = NULL;
00086 }
00087
00088 return cs;
00089 }
00090
00091
00092
00093
00094
00095
00096
00097 static void store_coding_state_nordo (Macroblock *currMB, CSobj *cs)
00098 {
00099 }
00100
00101
00102
00103
00104
00105
00106
00107
00108 static void store_coding_state_cavlc (Macroblock *currMB, CSobj *cs)
00109 {
00110 int i;
00111 Slice *currSlice = currMB->p_slice;
00112 int i_last = currSlice->idr_flag? 1 : cs->no_part;
00113
00114
00115 for (i = 0; i < i_last; i++)
00116 {
00117 cs->bitstream[i] = *currSlice->partArr[i].bitstream;
00118 }
00119
00120
00121 cs->bits = currMB->bits;
00122
00123
00124 if (currMB->mb_type <= P8x8)
00125 memcpy (cs->mvd, currMB->mvd, BLOCK_CONTEXT * sizeof(short));
00126 memcpy (cs->cbp_bits, currMB->cbp_bits, 3 * sizeof(int64));
00127
00128 if (currSlice->P444_joined)
00129 memcpy (cs->cbp_bits_8x8, currMB->cbp_bits_8x8, 3 * sizeof(int64));
00130 }
00131
00132
00133
00134
00135
00136
00137
00138 static void store_coding_state_cabac (Macroblock *currMB, CSobj *cs)
00139 {
00140 int i;
00141 Slice *currSlice = currMB->p_slice;
00142 int i_last = currSlice->idr_flag? 1:cs->no_part;
00143 DataPartition *partArr = &currSlice->partArr[0];
00144
00145
00146
00147 for (i = 0; i < i_last; i++)
00148 {
00149 cs->bitstream[i] = *partArr->bitstream;
00150 cs->encenv[i] = (partArr++)->ee_cabac;
00151 }
00152
00153
00154 *cs->mot_ctx = *currSlice->mot_ctx;
00155 *cs->tex_ctx = *currSlice->tex_ctx;
00156
00157
00158 cs->bits = currMB->bits;
00159
00160
00161 if (currMB->mb_type <= P8x8)
00162 memcpy (cs->mvd, currMB->mvd, BLOCK_CONTEXT * sizeof(short));
00163 memcpy (cs->cbp_bits, currMB->cbp_bits, 3 * sizeof(int64));
00164
00165 if (currSlice->P444_joined)
00166 memcpy (cs->cbp_bits_8x8, currMB->cbp_bits_8x8, 3 * sizeof(int64));
00167 }
00168
00169
00170
00171
00172
00173
00174
00175 static void reset_coding_state_nordo (Macroblock *currMB, CSobj *cs)
00176 {
00177 }
00178
00179
00180
00181
00182
00183
00184
00185 static void reset_coding_state_cavlc (Macroblock *currMB, CSobj *cs)
00186 {
00187 int i;
00188 Slice *currSlice = currMB->p_slice;
00189 int i_last = currSlice->idr_flag? 1:cs->no_part;
00190
00191
00192
00193 for (i = 0; i < i_last; i++)
00194 {
00195
00196 *currSlice->partArr[i].bitstream = cs->bitstream[i];
00197 }
00198
00199
00200 currMB->bits = cs->bits;
00201
00202
00203 if (currMB->mb_type <= P8x8)
00204 memcpy (currMB->mvd, cs->mvd, BLOCK_CONTEXT * sizeof(short));
00205 memcpy (currMB->cbp_bits, cs->cbp_bits, 3 * sizeof(int64));
00206 if(currSlice->P444_joined)
00207 memcpy (currMB->cbp_bits_8x8, cs->cbp_bits_8x8, 3 * sizeof(int64));
00208 }
00209
00210
00211
00212
00213
00214
00215
00216
00217 static void reset_coding_state_cabac (Macroblock *currMB, CSobj *cs)
00218 {
00219 int i;
00220 Slice *currSlice = currMB->p_slice;
00221 int i_last = currSlice->idr_flag? 1:cs->no_part;
00222 DataPartition *partArr = &currSlice->partArr[0];
00223
00224
00225
00226 for (i = 0; i < i_last; i++)
00227 {
00228
00229 *partArr->bitstream = cs->bitstream[i];
00230 (partArr++)->ee_cabac = cs->encenv[i];
00231 }
00232
00233
00234 *currSlice->mot_ctx = *cs->mot_ctx;
00235 *currSlice->tex_ctx = *cs->tex_ctx;
00236
00237
00238 currMB->bits = cs->bits;
00239
00240
00241 if (currMB->mb_type <= P8x8)
00242 memcpy (currMB->mvd, cs->mvd, BLOCK_CONTEXT * sizeof(short));
00243
00244 memcpy (currMB->cbp_bits, cs->cbp_bits, 3 * sizeof(int64));
00245
00246 if(currSlice->P444_joined)
00247 memcpy (currMB->cbp_bits_8x8, cs->cbp_bits_8x8, 3 * sizeof(int64));
00248 }
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259 void init_coding_state_methods(Slice *currSlice)
00260 {
00261 if (currSlice->p_Inp->rdopt == 0)
00262 {
00263 currSlice->reset_coding_state = reset_coding_state_nordo;
00264 currSlice->store_coding_state = store_coding_state_nordo;
00265 }
00266 else
00267 {
00268 if (currSlice->symbol_mode == CABAC)
00269 {
00270 currSlice->reset_coding_state = reset_coding_state_cabac;
00271 currSlice->store_coding_state = store_coding_state_cabac;
00272 }
00273 else
00274 {
00275 currSlice->reset_coding_state = reset_coding_state_cavlc;
00276 currSlice->store_coding_state = store_coding_state_cavlc;
00277 }
00278 }
00279 }