示例#1
0
static mpf_object_t* mpf_context_connection_create(mpf_context_t *context, mpf_termination_t *src_termination, mpf_termination_t *sink_termination)
{
    mpf_object_t *object = NULL;
    mpf_audio_stream_t *source;
    mpf_audio_stream_t *sink;
    if(!src_termination || !sink_termination) {
        return NULL;
    }
    source = src_termination->audio_stream;
    sink = sink_termination->audio_stream;
    if(source && (source->mode & STREAM_MODE_RECEIVE) == STREAM_MODE_RECEIVE &&
            sink && (sink->mode & STREAM_MODE_SEND) == STREAM_MODE_SEND) {
        mpf_codec_t *rx_codec = source->rx_codec;
        mpf_codec_t *tx_codec = sink->tx_codec;
        if(rx_codec && tx_codec) {
            if(mpf_codec_descriptor_match(rx_codec->descriptor,tx_codec->descriptor) == TRUE) {
                object = mpf_null_bridge_create(source,sink,context->pool);
            }
            else {
                if(rx_codec->attribs->bits_per_samples != BITS_PER_SAMPLE) {
                    /* set decoder before bridge */
                    mpf_audio_stream_t *decoder = mpf_decoder_create(source,context->pool);
                    source = decoder;
                }
                if(tx_codec->attribs->bits_per_samples != BITS_PER_SAMPLE) {
                    /* set encoder after bridge */
                    mpf_audio_stream_t *encoder = mpf_encoder_create(sink,context->pool);
                    sink = encoder;
                }
                object = mpf_bridge_create(source,sink,context->pool);
            }
        }
    }
    return object;
}
示例#2
0
MPF_DECLARE(mpf_object_t*) mpf_bridge_create(
						mpf_audio_stream_t *source, 
						mpf_audio_stream_t *sink, 
						const mpf_codec_manager_t *codec_manager, 
						const char *name,
						apr_pool_t *pool)
{
	if(!source || !sink) {
		return NULL;
	}

	if(mpf_audio_stream_rx_validate(source,sink->tx_descriptor,sink->tx_event_descriptor,pool) == FALSE ||
		mpf_audio_stream_tx_validate(sink,source->rx_descriptor,source->rx_event_descriptor,pool) == FALSE) {
		return NULL;
	}

	if(mpf_codec_descriptors_match(source->rx_descriptor,sink->tx_descriptor) == TRUE) {
		return mpf_null_bridge_create(source,sink,codec_manager,name,pool);
	}

	if(mpf_codec_lpcm_descriptor_match(source->rx_descriptor) == FALSE) {
		mpf_codec_t *codec = mpf_codec_manager_codec_get(codec_manager,source->rx_descriptor,pool);
		if(codec) {
			/* set decoder before bridge */
			mpf_audio_stream_t *decoder = mpf_decoder_create(source,codec,pool);
			source = decoder;
		}
	}

	if(mpf_codec_lpcm_descriptor_match(sink->tx_descriptor) == FALSE) {
		mpf_codec_t *codec = mpf_codec_manager_codec_get(codec_manager,sink->tx_descriptor,pool);
		if(codec) {
			/* set encoder after bridge */
			mpf_audio_stream_t *encoder = mpf_encoder_create(sink,codec,pool);
			sink = encoder;
		}
	}

	if(source->rx_descriptor->sampling_rate != sink->tx_descriptor->sampling_rate) {
		/* set resampler before bridge */
		mpf_audio_stream_t *resampler = mpf_resampler_create(source,sink,pool);
		if(!resampler) {
			return NULL;
		}
		source = resampler;
	}

	return mpf_linear_bridge_create(source,sink,codec_manager,name,pool);
}
示例#3
0
MPF_DECLARE(mpf_object_t*) mpf_mixer_create(
								mpf_audio_stream_t **source_arr, 
								apr_size_t source_count, 
								mpf_audio_stream_t *sink, 
								const mpf_codec_manager_t *codec_manager, 
								const char *name,
								apr_pool_t *pool)
{
	apr_size_t i;
	apr_size_t frame_size;
	mpf_codec_descriptor_t *descriptor;
	mpf_audio_stream_t *source;
	mpf_mixer_t *mixer;
	if(!source_arr || !source_count || !sink) {
		return NULL;
	}

	apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Create Mixer %s",name);
	mixer = apr_palloc(pool,sizeof(mpf_mixer_t));
	mixer->source_arr = NULL;
	mixer->source_count = 0;
	mixer->sink = NULL;
	mpf_object_init(&mixer->base,name);
	mixer->base.process = mpf_mixer_process;
	mixer->base.destroy = mpf_mixer_destroy;
	mixer->base.trace = mpf_mixer_trace;

	if(mpf_audio_stream_tx_validate(sink,NULL,NULL,pool) == FALSE) {
		return NULL;
	}

	descriptor = sink->tx_descriptor;
	if(descriptor && mpf_codec_lpcm_descriptor_match(descriptor) == FALSE) {
		mpf_codec_t *codec = mpf_codec_manager_codec_get(codec_manager,descriptor,pool);
		if(codec) {
			/* set encoder after mixer */
			mpf_audio_stream_t *encoder = mpf_encoder_create(sink,codec,pool);
			sink = encoder;
		}
	}
	mixer->sink = sink;
	mpf_audio_stream_tx_open(sink,NULL);

	for(i=0; i<source_count; i++)	{
		source = source_arr[i];
		if(!source) continue;

		if(mpf_audio_stream_rx_validate(source,NULL,NULL,pool) == FALSE) {
			continue;
		}

		descriptor = source->rx_descriptor;
		if(descriptor && mpf_codec_lpcm_descriptor_match(descriptor) == FALSE) {
			mpf_codec_t *codec = mpf_codec_manager_codec_get(codec_manager,descriptor,pool);
			if(codec) {
				/* set decoder before mixer */
				mpf_audio_stream_t *decoder = mpf_decoder_create(source,codec,pool);
				source = decoder;
			}
		}
		source_arr[i] = source;
		mpf_audio_stream_rx_open(source,NULL);
	}
	mixer->source_arr = source_arr;
	mixer->source_count = source_count;

	descriptor = sink->tx_descriptor;
	frame_size = mpf_codec_linear_frame_size_calculate(descriptor->sampling_rate,descriptor->channel_count);
	mixer->frame.codec_frame.size = frame_size;
	mixer->frame.codec_frame.buffer = apr_palloc(pool,frame_size);
	mixer->mix_frame.codec_frame.size = frame_size;
	mixer->mix_frame.codec_frame.buffer = apr_palloc(pool,frame_size);
	return &mixer->base;
}