Exemplo n.º 1
0
static vod_status_t
mp4_encrypt_init_state(
	mp4_encrypt_state_t* state,
	request_context_t* request_context,
	media_set_t* media_set,
	uint32_t segment_index,
	segment_writer_t* segment_writer,
	const u_char* iv)
{
	media_sequence_t* sequence = &media_set->sequences[0];
	drm_info_t* drm_info = (drm_info_t*)sequence->drm_info;
	vod_status_t rc;
	uint64_t iv_int;
	u_char* p;

	// fixed fields
	state->request_context = request_context;
	state->media_set = media_set;
	state->sequence = sequence;
	state->segment_index = segment_index;
	state->segment_writer = *segment_writer;

	// init the aes ctr
	rc = mp4_aes_ctr_init(&state->cipher, request_context, drm_info->key);
	if (rc != VOD_OK)
	{
		return rc;
	}

	// init the output buffer
	write_buffer_init(
		&state->write_buffer,
		request_context,
		segment_writer->write_tail,
		segment_writer->context,
		FALSE);

	// increment the iv by the index of the first frame
	iv_int = parse_be64(iv);
	iv_int += sequence->filtered_clips[0].first_track->first_frame_index;
	// Note: we don't know how many frames were in previous clips (were not parsed), assuming there won't be more than 60 fps
	iv_int += (sequence->filtered_clips[0].first_track->clip_start_time * MAX_FRAME_RATE) / 1000;
	p = state->iv;
	write_be64(p, iv_int);

	// init the first clip
	state->cur_clip = sequence->filtered_clips;
	mp4_encrypt_init_track(state, state->cur_clip->first_track);

	// saiz / saio
	state->saiz_atom_size = ATOM_HEADER_SIZE + sizeof(saiz_atom_t);
	state->saio_atom_size = ATOM_HEADER_SIZE + sizeof(saio_atom_t);

	return VOD_OK;
}
Exemplo n.º 2
0
vod_status_t
mp4_decrypt_init(
	request_context_t* request_context,
	frames_source_t* frames_source,
	void* frames_source_context,
	u_char* key,
	media_encryption_t* encryption, 
	void** result)
{
	mp4_decrypt_state_t* state;
	vod_status_t rc;

	state = vod_alloc(request_context->pool, sizeof(*state));
	if (state == NULL)
	{
		vod_log_debug0(VOD_LOG_DEBUG_LEVEL, request_context->log, 0,
			"mp4_decrypt_init: vod_alloc failed");
		return VOD_ALLOC_FAILED;
	}

	vod_memzero(state, sizeof(*state));

	rc = mp4_aes_ctr_init(&state->cipher, request_context, key);
	if (rc != VOD_OK)
	{
		return rc;
	}

	vod_memcpy(state->key, key, sizeof(state->key));
	state->request_context = request_context;
	state->frames_source = frames_source;
	state->frames_source_context = frames_source_context;
	state->reuse_buffers = TRUE;

	state->auxiliary_info_pos = encryption->auxiliary_info;
	state->auxiliary_info_end = encryption->auxiliary_info_end;
	state->use_subsamples = encryption->use_subsamples;

	*result = state;

	return VOD_OK;
}