static vod_status_t
segmenter_adaptation_durations_to_conf(segmenter_conf_t* conf, vod_array_t* adaptation_list)
{
	vod_str_t    *value;
	vod_int_t n = adaptation_list->nelts;

	if (n <= 0)
	{
		return VOD_BAD_DATA;
	}

	conf->adaptation_configs = NULL;
	conf->adaptation_durations = NULL;

	adaptation_list->nelts--;
	if (adaptation_list->nelts > 0)
	{
		conf->bootstrap_segments = adaptation_list;
	}
	else
	{
		conf->bootstrap_segments = NULL;
	}

	value = adaptation_list->elts;
	conf->segment_duration = vod_atoi(value[n - 1].data, value[n - 1].len);
	if (conf->segment_duration < MIN_SEGMENT_DURATION)
	{
		return VOD_BAD_DATA;
	}

	return VOD_OK;
}
vod_status_t
segmenter_init_config(segmenter_conf_t* conf, vod_pool_t* pool)
{
	vod_status_t rc;

	if (conf->adaptation_durations != NULL)
	{
		rc = segmenter_init_adaptations_config(conf, pool);
		if (rc != VOD_AGAIN)
		{
			return rc;
		}
	}

	ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pool->log, 0,
								 "LETS PLAY #6");

	vod_str_t* cur_str;
	uint32_t* buffer;
	uint32_t cur_pos = 0;
	uint32_t i;
	int32_t cur_duration;

	if (conf->segment_duration < MIN_SEGMENT_DURATION)
	{
		return VOD_BAD_DATA;
	}

	conf->max_segment_duration = conf->segment_duration;

	if (conf->get_segment_durations == segmenter_get_segment_durations_accurate)
	{
		conf->parse_type = PARSE_FLAG_FRAMES_DURATION;
		if (conf->align_to_key_frames)
		{
			conf->parse_type |= PARSE_FLAG_FRAMES_IS_KEY;
		}
	}
	else
	{
		conf->parse_type = 0;
	}

	if (conf->bootstrap_segments == NULL)
	{
		conf->bootstrap_segments_count = 0;
		conf->bootstrap_segments_durations = NULL;
		conf->bootstrap_segments_total_duration = 0;
		conf->bootstrap_segments_start = NULL;
		conf->bootstrap_segments_mid = NULL;
		conf->bootstrap_segments_end = NULL;
		return VOD_OK;
	}

	conf->bootstrap_segments_count = conf->bootstrap_segments->nelts;
	buffer = vod_alloc(pool, 4 * conf->bootstrap_segments_count * sizeof(uint32_t));
	if (buffer == NULL)
	{
		return VOD_ALLOC_FAILED;
	}

	conf->bootstrap_segments_durations = buffer;
	conf->bootstrap_segments_start =     buffer + conf->bootstrap_segments_count;
	conf->bootstrap_segments_mid =       buffer + 2 * conf->bootstrap_segments_count;
	conf->bootstrap_segments_end =       buffer + 3 * conf->bootstrap_segments_count;

	for (i = 0; i < conf->bootstrap_segments_count; i++)
	{
		cur_str = (vod_str_t*)conf->bootstrap_segments->elts + i;

		cur_duration = vod_atoi(cur_str->data, cur_str->len);
		if (cur_duration < MIN_SEGMENT_DURATION)
		{
			return VOD_BAD_DATA;
		}

		conf->bootstrap_segments_durations[i] = cur_duration;
		conf->bootstrap_segments_start[i] = cur_pos;
		conf->bootstrap_segments_mid[i] = cur_pos + conf->bootstrap_segments_durations[i] / 2;
		cur_pos += conf->bootstrap_segments_durations[i];
		conf->bootstrap_segments_end[i] = cur_pos;

		if ((uint32_t)cur_duration > conf->max_segment_duration)
		{
			conf->max_segment_duration = cur_duration;
		}
	}
	conf->bootstrap_segments_total_duration = cur_pos;

	return VOD_OK;
}
Exemple #3
0
vod_status_t 
segmenter_init_config(segmenter_conf_t* conf, vod_pool_t* pool)
{
	vod_str_t* cur_str;
	uint32_t* buffer;
	uint32_t cur_pos = 0;
	uint32_t i;
	int32_t cur_duration;

	conf->max_segment_duration = conf->segment_duration;

	if (conf->get_segment_durations == segmenter_get_segment_durations_accurate)
	{
		conf->parse_type = PARSE_FLAG_FRAMES_DURATION;
		if (conf->align_to_key_frames)
		{
			conf->parse_type |= PARSE_FLAG_FRAMES_IS_KEY;
		}
	}
	else
	{
		conf->parse_type = 0;
	}

	if (conf->bootstrap_segments == NULL)
	{
		conf->bootstrap_segments_count = 0;
		conf->bootstrap_segments_durations = NULL;
		conf->bootstrap_segments_total_duration = 0;
		conf->bootstrap_segments_start = NULL;
		conf->bootstrap_segments_mid = NULL;
		conf->bootstrap_segments_end = NULL;
		return VOD_OK;
	}

	conf->bootstrap_segments_count = conf->bootstrap_segments->nelts;
	buffer = vod_alloc(pool, 4 * conf->bootstrap_segments_count * sizeof(uint32_t));
	if (buffer == NULL)
	{
		return VOD_ALLOC_FAILED;
	}

	conf->bootstrap_segments_durations = buffer;
	conf->bootstrap_segments_start =     buffer + conf->bootstrap_segments_count;
	conf->bootstrap_segments_mid =       buffer + 2 * conf->bootstrap_segments_count;
	conf->bootstrap_segments_end =       buffer + 3 * conf->bootstrap_segments_count;

	for (i = 0; i < conf->bootstrap_segments_count; i++)
	{
		cur_str = (vod_str_t*)conf->bootstrap_segments->elts + i;
		
		cur_duration = vod_atoi(cur_str->data, cur_str->len);
		if (cur_duration <= 0)
		{
			return VOD_BAD_DATA;
		}
		
		conf->bootstrap_segments_durations[i] = cur_duration;
		conf->bootstrap_segments_start[i] = cur_pos;
		conf->bootstrap_segments_mid[i] = cur_pos + conf->bootstrap_segments_durations[i] / 2;
		cur_pos += conf->bootstrap_segments_durations[i];
		conf->bootstrap_segments_end[i] = cur_pos;
	}
	conf->bootstrap_segments_total_duration = cur_pos;

	return VOD_OK;
}