/** Create engine channel and sink media termination */ mrcp_engine_channel_t* mrcp_engine_sink_channel_create( mrcp_resource_engine_t *engine, const mrcp_engine_channel_method_vtable_t *channel_vtable, const mpf_audio_stream_vtable_t *stream_vtable, void *method_obj, mpf_codec_descriptor_t *codec_descriptor, apr_pool_t *pool) { mpf_audio_stream_t *audio_stream; mpf_termination_t *termination; /* create audio stream */ audio_stream = mpf_audio_stream_create( method_obj, /* object to associate */ stream_vtable, /* virtual methods table of audio stream */ STREAM_MODE_SEND, /* stream mode/direction */ pool); /* pool to allocate memory from */ /* create media termination */ termination = mpf_raw_termination_create( NULL, /* no object to associate */ audio_stream, /* audio stream */ NULL, /* no video stream */ pool); /* pool to allocate memory from */ /* create engine channel base */ return mrcp_engine_channel_create( engine, /* resource engine */ channel_vtable, /* virtual methods table of engine channel */ method_obj, /* object to associate */ termination, /* media termination, used to terminate audio stream */ pool); /* pool to allocate memory from */ }
/** Create demo synthesizer channel */ static mrcp_channel_t* synth_application_channel_create(mrcp_session_t *session) { mrcp_channel_t *channel; mpf_termination_t *termination; /* create channel */ synth_app_channel_t *synth_channel = apr_palloc(session->pool,sizeof(synth_app_channel_t)); synth_channel->audio_out = NULL; /* create audio stream */ synth_channel->audio_stream = mpf_audio_stream_create( synth_channel, /* object to associate */ &audio_stream_vtable, /* virtual methods table of audio stream */ STREAM_MODE_SEND, /* stream mode/direction */ session->pool); /* memory pool to allocate memory from */ /* create raw termination */ termination = mpf_raw_termination_create( NULL, /* no object to associate */ synth_channel->audio_stream, /* audio stream */ NULL, /* no video stream */ session->pool); /* memory pool to allocate memory from */ channel = mrcp_application_channel_create( session, /* session, channel belongs to */ MRCP_SYNTHESIZER_RESOURCE, /* MRCP resource identifier */ termination, /* media termination, used to terminate audio stream */ NULL, /* RTP descriptor, used to create RTP termination (NULL by default) */ synth_channel); /* object to associate */ return channel; }
MPF_DECLARE(mpf_audio_stream_t*) mpf_encoder_create(mpf_audio_stream_t *sink, mpf_codec_t *codec, apr_pool_t *pool) { apr_size_t frame_size; mpf_encoder_t *encoder; mpf_stream_capabilities_t *capabilities; if(!sink || !codec) { return NULL; } encoder = apr_palloc(pool,sizeof(mpf_encoder_t)); capabilities = mpf_stream_capabilities_create(STREAM_DIRECTION_SEND,pool); encoder->base = mpf_audio_stream_create(encoder,&vtable,capabilities,pool); if(!encoder->base) { return NULL; } encoder->base->tx_descriptor = mpf_codec_lpcm_descriptor_create( sink->tx_descriptor->sampling_rate, sink->tx_descriptor->channel_count, pool); encoder->base->tx_event_descriptor = sink->tx_event_descriptor; encoder->sink = sink; encoder->codec = codec; frame_size = mpf_codec_frame_size_calculate(sink->tx_descriptor,codec->attribs); encoder->frame_out.codec_frame.size = frame_size; encoder->frame_out.codec_frame.buffer = apr_palloc(pool,frame_size); return encoder->base; }
/** Create audio termination */ MRCP_DECLARE(mpf_termination_t*) mrcp_application_audio_termination_create( mrcp_session_t *session, const mpf_audio_stream_vtable_t *stream_vtable, mpf_stream_capabilities_t *capabilities, void *obj) { mpf_audio_stream_t *audio_stream; if(!capabilities) { return NULL; } if(mpf_codec_capabilities_validate(&capabilities->codecs) == FALSE) { return NULL; } /* create audio stream */ audio_stream = mpf_audio_stream_create( obj, /* object to associate */ stream_vtable, /* virtual methods table of audio stream */ capabilities, /* stream capabilities */ session->pool); /* memory pool to allocate memory from */ if(!audio_stream) { return NULL; } /* create raw termination */ return mpf_raw_termination_create( NULL, /* no object to associate */ audio_stream, /* audio stream */ NULL, /* no video stream */ session->pool); /* memory pool to allocate memory from */ }
/** Create audio termination */ mpf_termination_t* mrcp_engine_audio_termination_create( void *obj, const mpf_audio_stream_vtable_t *stream_vtable, mpf_stream_capabilities_t *capabilities, apr_pool_t *pool) { mpf_audio_stream_t *audio_stream; if(!capabilities) { return NULL; } if(mpf_codec_capabilities_validate(&capabilities->codecs) == FALSE) { return NULL; } /* create audio stream */ audio_stream = mpf_audio_stream_create( obj, /* object to associate */ stream_vtable, /* virtual methods table of audio stream */ capabilities, /* stream capabilities */ pool); /* pool to allocate memory from */ if(!audio_stream) { return NULL; } /* create media termination */ return mpf_raw_termination_create( NULL, /* no object to associate */ audio_stream, /* audio stream */ NULL, /* no video stream */ pool); /* pool to allocate memory from */ }
/** Create engine channel and sink media termination */ mrcp_engine_channel_t* mrcp_engine_sink_channel_create( mrcp_engine_t *engine, const mrcp_engine_channel_method_vtable_t *channel_vtable, const mpf_audio_stream_vtable_t *stream_vtable, void *method_obj, mpf_codec_descriptor_t *codec_descriptor, apr_pool_t *pool) { mpf_stream_capabilities_t *capabilities; mpf_audio_stream_t *audio_stream; mpf_termination_t *termination; capabilities = mpf_sink_stream_capabilities_create(pool); if(codec_descriptor) { mpf_codec_capabilities_add( &capabilities->codecs, mpf_sample_rate_mask_get(codec_descriptor->sampling_rate), codec_descriptor->name.buf); } else { mpf_codec_default_capabilities_add(&capabilities->codecs); } /* create audio stream */ audio_stream = mpf_audio_stream_create( method_obj, /* object to associate */ stream_vtable, /* virtual methods table of audio stream */ capabilities, /* stream capabilities */ pool); /* pool to allocate memory from */ if(!audio_stream) { return NULL; } audio_stream->tx_descriptor = codec_descriptor; /* create media termination */ termination = mpf_raw_termination_create( NULL, /* no object to associate */ audio_stream, /* audio stream */ NULL, /* no video stream */ pool); /* pool to allocate memory from */ /* create engine channel base */ return mrcp_engine_channel_create( engine, /* engine */ channel_vtable, /* virtual methods table of engine channel */ method_obj, /* object to associate */ termination, /* media termination, used to terminate audio stream */ pool); /* pool to allocate memory from */ }
MPF_DECLARE(mpf_audio_stream_t*) mpf_rtp_stream_create(mpf_termination_t *termination, mpf_rtp_config_t *config, mpf_rtp_settings_t *settings, apr_pool_t *pool) { mpf_rtp_stream_t *rtp_stream = apr_palloc(pool,sizeof(mpf_rtp_stream_t)); mpf_stream_capabilities_t *capabilities = mpf_stream_capabilities_create(STREAM_DIRECTION_DUPLEX,pool); mpf_audio_stream_t *audio_stream = mpf_audio_stream_create(rtp_stream,&vtable,capabilities,pool); if(!audio_stream) { return NULL; } audio_stream->direction = STREAM_DIRECTION_NONE; audio_stream->termination = termination; rtp_stream->base = audio_stream; rtp_stream->pool = pool; rtp_stream->config = config; rtp_stream->settings = settings; rtp_stream->local_media = NULL; rtp_stream->remote_media = NULL; rtp_stream->rtp_socket = NULL; rtp_stream->rtcp_socket = NULL; rtp_stream->rtp_l_sockaddr = NULL; rtp_stream->rtp_r_sockaddr = NULL; rtp_stream->rtcp_l_sockaddr = NULL; rtp_stream->rtcp_r_sockaddr = NULL; rtp_stream->rtcp_tx_timer = NULL; rtp_stream->rtcp_rx_timer = NULL; rtp_stream->state = MPF_MEDIA_DISABLED; rtp_receiver_init(&rtp_stream->receiver); rtp_transmitter_init(&rtp_stream->transmitter); rtp_stream->transmitter.sr_stat.ssrc = (apr_uint32_t)apr_time_now(); if(settings->rtcp == TRUE) { if(settings->rtcp_tx_interval) { rtp_stream->rtcp_tx_timer = apt_timer_create( termination->timer_queue, mpf_rtcp_tx_timer_proc, rtp_stream, pool); } if(settings->rtcp_rx_resolution) { rtp_stream->rtcp_rx_timer = apt_timer_create( termination->timer_queue, mpf_rtcp_rx_timer_proc, rtp_stream, pool); } } return audio_stream; }
MPF_DECLARE(mpf_audio_stream_t*) mpf_encoder_create(mpf_audio_stream_t *sink, apr_pool_t *pool) { apr_size_t frame_size; mpf_codec_t *codec; mpf_encoder_t *encoder; if(!sink || !sink->tx_codec) { return NULL; } encoder = apr_palloc(pool,sizeof(mpf_encoder_t)); encoder->base = mpf_audio_stream_create(encoder,&vtable,STREAM_MODE_SEND,pool); encoder->sink = sink; codec = sink->tx_codec; frame_size = mpf_codec_frame_size_calculate(codec->descriptor,codec->attribs); encoder->base->tx_codec = codec; encoder->frame_out.codec_frame.size = frame_size; encoder->frame_out.codec_frame.buffer = apr_palloc(pool,frame_size); return encoder->base; }
MPF_DECLARE(mpf_audio_stream_t*) mpf_decoder_create(mpf_audio_stream_t *source, apr_pool_t *pool) { apr_size_t frame_size; mpf_codec_t *codec; mpf_decoder_t *decoder; if(!source || !source->rx_codec) { return NULL; } decoder = apr_palloc(pool,sizeof(mpf_decoder_t)); decoder->base = mpf_audio_stream_create(decoder,&vtable,STREAM_MODE_RECEIVE,pool); decoder->source = source; codec = source->rx_codec; frame_size = mpf_codec_frame_size_calculate(codec->descriptor,codec->attribs); decoder->base->rx_codec = codec; decoder->frame_in.codec_frame.size = frame_size; decoder->frame_in.codec_frame.buffer = apr_palloc(pool,frame_size); return decoder->base; }
/** Create source media termination */ MRCP_DECLARE(mpf_termination_t*) mrcp_application_source_termination_create( mrcp_session_t *session, const mpf_audio_stream_vtable_t *stream_vtable, mpf_codec_descriptor_t *codec_descriptor, void *obj) { mpf_stream_capabilities_t *capabilities; mpf_audio_stream_t *audio_stream; capabilities = mpf_source_stream_capabilities_create(session->pool); if(codec_descriptor) { mpf_codec_capabilities_add( &capabilities->codecs, mpf_sample_rate_mask_get(codec_descriptor->sampling_rate), codec_descriptor->name.buf); } else { mpf_codec_default_capabilities_add(&capabilities->codecs); } /* create audio stream */ audio_stream = mpf_audio_stream_create( obj, /* object to associate */ stream_vtable, /* virtual methods table of audio stream */ capabilities, /* stream capabilities */ session->pool); /* memory pool to allocate memory from */ if(!audio_stream) { return NULL; } audio_stream->rx_descriptor = codec_descriptor; /* create raw termination */ return mpf_raw_termination_create( NULL, /* no object to associate */ audio_stream, /* audio stream */ NULL, /* no video stream */ session->pool); /* memory pool to allocate memory from */ }