コード例 #1
0
static vod_status_t
hds_muxer_init_track(
	hds_muxer_state_t* state,
	hds_muxer_stream_state_t* cur_stream,
	media_track_t* cur_track)
{
	vod_status_t rc;

	cur_stream->track = cur_track;
	cur_stream->media_type = cur_track->media_info.media_type;
	cur_stream->timescale = cur_track->media_info.timescale;
	cur_stream->frames_source = cur_track->frames_source;
	cur_stream->frames_source_context = cur_track->frames_source_context;
	cur_stream->first_frame = cur_track->first_frame;
	cur_stream->last_frame = cur_track->last_frame;

	cur_stream->clip_start_time = hds_rescale_millis(cur_track->clip_start_time);
	cur_stream->first_frame_time_offset = cur_track->first_frame_time_offset;
	cur_stream->next_frame_time_offset = cur_stream->first_frame_time_offset;
	cur_stream->next_frame_dts = rescale_time(cur_stream->next_frame_time_offset, cur_stream->timescale, HDS_TIMESCALE);

	cur_stream->cur_frame = cur_stream->first_frame;

	cur_stream->first_frame_input_offset = cur_track->frame_offsets;
	cur_stream->cur_frame_input_offset = cur_stream->first_frame_input_offset;

	if (cur_track->media_info.media_type == MEDIA_TYPE_AUDIO)
	{
		rc = hds_get_sound_info(state->request_context, &cur_track->media_info, &cur_stream->sound_info);
		if (rc != VOD_OK)
		{
			vod_log_debug1(VOD_LOG_DEBUG_LEVEL, state->request_context->log, 0,
				"hds_muxer_init_track: hds_get_sound_info failed %i", rc);
			return rc;
		}
	}

	return VOD_OK;
}
コード例 #2
0
static vod_status_t
hds_muxer_init_state(
	request_context_t* request_context,
	mpeg_metadata_t *mpeg_metadata,
	read_cache_state_t* read_cache_state,
	write_callback_t write_callback,
	void* write_context,
	hds_muxer_state_t** result)
{
	mpeg_stream_metadata_t* cur_stream;
	hds_muxer_stream_state_t* stream_state;
	hds_muxer_state_t* state;
	vod_status_t rc;

	// allocate the state and stream states
	state = vod_alloc(request_context->pool, sizeof(*state));
	if (state == NULL)
	{
		vod_log_debug0(VOD_LOG_DEBUG_LEVEL, request_context->log, 0,
			"hds_muxer_init_state: vod_alloc failed (1)");
		return VOD_ALLOC_FAILED;
	}

	state->first_stream = vod_alloc(
		request_context->pool, 
		sizeof(state->first_stream[0]) * mpeg_metadata->streams.nelts);
	if (state->first_stream == NULL)
	{
		vod_log_debug0(VOD_LOG_DEBUG_LEVEL, request_context->log, 0,
			"hds_muxer_init_state: vod_alloc failed (2)");
		return VOD_ALLOC_FAILED;
	}
	state->last_stream = state->first_stream + mpeg_metadata->streams.nelts;
	state->request_context = request_context;
	state->cur_frame = NULL;

	state->read_cache_state = read_cache_state;
	write_buffer_init(&state->write_buffer_state, request_context, write_callback, write_context);

	stream_state = state->first_stream;
	for (cur_stream = mpeg_metadata->first_stream; cur_stream < mpeg_metadata->last_stream; cur_stream++, stream_state++)
	{
		// initialize the stream
		stream_state->metadata = cur_stream;
		stream_state->media_type = cur_stream->media_info.media_type;
		stream_state->timescale = cur_stream->media_info.timescale;
		stream_state->first_frame = cur_stream->frames;
		stream_state->last_frame = cur_stream->frames + cur_stream->frame_count;

		stream_state->first_frame_time_offset = cur_stream->first_frame_time_offset;
		stream_state->next_frame_time_offset = cur_stream->first_frame_time_offset;
		stream_state->next_frame_dts = rescale_time(stream_state->next_frame_time_offset, stream_state->timescale, HDS_TIMESCALE);

		stream_state->cur_frame = stream_state->first_frame;

		stream_state->first_frame_input_offset = cur_stream->frame_offsets;
		stream_state->cur_frame_input_offset = stream_state->first_frame_input_offset;

		stream_state->first_frame_output_offset = vod_alloc(
			request_context->pool,
			cur_stream->frame_count * sizeof(uint32_t));
		if (stream_state->first_frame_output_offset == NULL)
		{
			vod_log_debug0(VOD_LOG_DEBUG_LEVEL, request_context->log, 0,
				"hds_muxer_init_state: vod_alloc failed (3)");
			return VOD_ALLOC_FAILED;
		}
		stream_state->cur_frame_output_offset = stream_state->first_frame_output_offset;

		if (cur_stream->media_info.media_type == MEDIA_TYPE_AUDIO)
		{
			rc = hds_get_sound_info(request_context, &cur_stream->media_info, &stream_state->sound_info);
			if (rc != VOD_OK)
			{
				vod_log_debug1(VOD_LOG_DEBUG_LEVEL, request_context->log, 0,
					"hds_muxer_init_state: hds_get_sound_info failed %i", rc);
				return rc;
			}
		}
	}

	*result = state;

	return VOD_OK;
}