static vod_status_t mp4_decrypt_start_frame(void* ctx, input_frame_t* frame) { mp4_decrypt_state_t* state = ctx; vod_status_t rc; rc = state->frames_source->start_frame(state->frames_source_context, frame); if (rc != VOD_OK) { return rc; } // get the iv if (state->auxiliary_info_pos + MP4_AES_CTR_IV_SIZE > state->auxiliary_info_end) { vod_log_error(VOD_LOG_ERR, state->request_context->log, 0, "mp4_decrypt_start_frame: failed to get iv from auxiliary info"); return VOD_BAD_DATA; } mp4_aes_ctr_set_iv(&state->cipher, state->auxiliary_info_pos); state->auxiliary_info_pos += MP4_AES_CTR_IV_SIZE; if (!state->use_subsamples) { state->encrypted_bytes = UINT_MAX; return VOD_OK; } // get the subsample info if (state->auxiliary_info_pos + sizeof(uint16_t) + sizeof(cenc_sample_auxiliary_data_subsample_t) > state->auxiliary_info_end) { vod_log_error(VOD_LOG_ERR, state->request_context->log, 0, "mp4_decrypt_start_frame: failed to get subsample info from auxiliary info"); return VOD_BAD_DATA; } read_be16(state->auxiliary_info_pos, state->subsample_count); if (state->subsample_count <= 0) { vod_log_error(VOD_LOG_ERR, state->request_context->log, 0, "mp4_decrypt_start_frame: invalid subsample count"); return VOD_BAD_DATA; } read_be16(state->auxiliary_info_pos, state->clear_bytes); read_be32(state->auxiliary_info_pos, state->encrypted_bytes); state->subsample_count--; return VOD_OK; }
static vod_status_t mp4_encrypt_start_frame(mp4_encrypt_state_t* state) { // make sure we have a frame if (state->cur_frame >= state->last_frame) { vod_log_error(VOD_LOG_ERR, state->request_context->log, 0, "mp4_encrypt_start_frame: no more frames"); return VOD_BAD_DATA; } // get the frame size state->frame_size_left = state->cur_frame->size; state->cur_frame++; // set and increment the iv mp4_aes_ctr_set_iv(&state->cipher, state->iv); mp4_aes_ctr_increment_be64(state->iv); return VOD_OK; }