diff --git a/src/encoder_state-ctors_dtors.c b/src/encoder_state-ctors_dtors.c index c72ab458..6d6dd1b1 100644 --- a/src/encoder_state-ctors_dtors.c +++ b/src/encoder_state-ctors_dtors.c @@ -124,9 +124,7 @@ static void encoder_state_config_tile_finalize(encoder_state_t * const state) { kvz_videoframe_free(state->tile->frame); state->tile->frame = NULL; - if (state->encoder_control->cfg->crypto_features) { - DeleteCryptoC(state->tile->dbs_g); - } + DeleteCryptoC(state->tile->dbs_g); FREE_POINTER(state->tile->wf_jobs); } @@ -320,6 +318,8 @@ int kvz_encoder_state_init(encoder_state_t * const child_state, encoder_state_t fprintf(stderr, "Could not initialize encoder_state->tile!\n"); return 0; } + + child_state->tile->dbs_g = CreateC(); child_state->slice = MALLOC(encoder_state_config_slice_t, 1); if (!child_state->slice || !encoder_state_config_slice_init(child_state, 0, encoder->in.width_in_lcu * encoder->in.height_in_lcu - 1)) { fprintf(stderr, "Could not initialize encoder_state->slice!\n"); @@ -449,6 +449,7 @@ int kvz_encoder_state_init(encoder_state_t * const child_state, encoder_state_t new_child->type = ENCODER_STATE_TYPE_TILE; new_child->frame = child_state->frame; new_child->tile = MALLOC(encoder_state_config_tile_t, 1); + new_child->tile->dbs_g = CreateC(); new_child->slice = child_state->slice; new_child->wfrow = child_state->wfrow; diff --git a/src/encoderstate.c b/src/encoderstate.c index fb8c324c..172c101a 100644 --- a/src/encoderstate.c +++ b/src/encoderstate.c @@ -298,8 +298,7 @@ static void encoder_state_encode_leaf(encoder_state_t * const state) { const kvz_config *cfg = state->encoder_control->cfg; if ( state->encoder_control->cfg->crypto_features) { - DeleteCryptoC(state->tile->dbs_g); - state->tile->dbs_g = InitC(); + InitC(state->tile->dbs_g); state->tile->m_prev_pos = 0; } // Select whether to encode the frame/tile in current thread or to define diff --git a/src/extras/crypto.cpp b/src/extras/crypto.cpp index cb2f4308..b0d9797d 100644 --- a/src/extras/crypto.cpp +++ b/src/extras/crypto.cpp @@ -19,9 +19,12 @@ typedef struct AESDecoder { } AESDecoder; -AESDecoder* Init() { +AESDecoder* Create() { + AESDecoder * AESdecoder = (AESDecoder *)malloc(sizeof(AESDecoder)); + return AESdecoder; +} +void Init(AESDecoder* AESdecoder) { int init_val[32] = {201, 75, 219, 152, 6, 245, 237, 107, 179, 194, 81, 29, 66, 98, 198, 0, 16, 213, 27, 56, 255, 127, 242, 112, 97, 126, 197, 204, 25, 59, 38, 30}; - AESDecoder * AESdecoder = (AESDecoder *)malloc(sizeof(AESDecoder)); for(int i=0;i<16; i++) { AESdecoder->iv [i] = init_val[i]; AESdecoder->counter[i] = init_val[5+i]; @@ -35,7 +38,6 @@ AESDecoder* Init() { AESdecoder->couter_avail = 0; AESdecoder->counter_index = 0; AESdecoder->counter_index_pos = 0; - return AESdecoder; } void DeleteCrypto(AESDecoder * AESdecoder) { @@ -105,11 +107,15 @@ unsigned int get_key (AESDecoder * AESdecoder, int nb_bits) { return key_; } #endif - -Crypto_Handle InitC(){ - AESDecoder* AESdecoder = Init(); - return AESdecoder; +Crypto_Handle CreateC() { + AESDecoder* AESdecoder = Create(); + return AESdecoder; } + +void InitC(Crypto_Handle hdl) { + Init((AESDecoder*)hdl); +} + #if AESEncryptionStreamMode unsigned int ff_get_key (Crypto_Handle *hdl, int nb_bits) { return get_key ((AESDecoder*)*hdl, nb_bits); diff --git a/src/extras/crypto.h b/src/extras/crypto.h index 22efedf5..80ce4429 100644 --- a/src/extras/crypto.h +++ b/src/extras/crypto.h @@ -16,8 +16,8 @@ extern "C" { #endif typedef void* Crypto_Handle; - - STUBBED Crypto_Handle InitC(); + STUBBED Crypto_Handle CreateC(); + STUBBED void InitC(Crypto_Handle hdl); STUBBED void DecryptC(Crypto_Handle hdl, const unsigned char *in_stream, int size_bits, unsigned char *out_stream); #if AESEncryptionStreamMode STUBBED unsigned int ff_get_key(Crypto_Handle *hdl, int nb_bits); @@ -38,11 +38,12 @@ extern "C" { #include -static INLINE Crypto_Handle InitC() -{ - // Stub. - assert(0); - return 0; +static INLINE Crypto_Handle CreateC() { + assert(0); + return 0; +} +static INLINE void InitC(Crypto_Handle hdl) { + assert(0); } static INLINE void DecryptC(Crypto_Handle hdl, const unsigned char *in_stream,