/** 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 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 */ }
/** Create demo synthesizer channel derived from engine channel base */ static mrcp_engine_channel_t* mrcp_swift_engine_channel_create(mrcp_engine_t *engine, apr_pool_t *pool) { mrcp_swift_engine_t *synth_engine = engine->obj; mpf_stream_capabilities_t *capabilities; mpf_termination_t *termination; mrcp_engine_channel_t *channel; /* create swift synth channel */ mrcp_swift_channel_t *synth_channel = apr_palloc(pool,sizeof(mrcp_swift_channel_t)); synth_channel->port = NULL; synth_channel->tts_stream = 0; synth_channel->channel = NULL; synth_channel->audio_buffer = NULL; synth_channel->speak_request = NULL; synth_channel->stop_response = NULL; synth_channel->paused = FALSE; capabilities = mpf_source_stream_capabilities_create(pool); mpf_codec_capabilities_add( &capabilities->codecs, synth_engine->sample_rates, "LPCM"); /* create media termination */ termination = mrcp_engine_audio_termination_create( synth_channel, /* object to associate */ &audio_stream_vtable, /* virtual methods table of audio stream */ capabilities, /* stream capabilities */ pool); /* pool to allocate memory from */ /* create engine channel base */ channel = mrcp_engine_channel_create( engine, /* engine */ &channel_vtable, /* virtual methods table of engine channel */ synth_channel, /* object to associate */ termination, /* associated media termination */ pool); /* pool to allocate memory from */ if(channel) { synth_channel->audio_buffer = mpf_buffer_create(pool); } synth_channel->channel = channel; return channel; }
static mrcp_engine_channel_t* recorder_engine_channel_create(mrcp_engine_t *engine, apr_pool_t *pool) { mpf_stream_capabilities_t *capabilities; mpf_termination_t *termination; /* create recorder channel */ recorder_channel_t *recorder_channel = apr_palloc(pool,sizeof(recorder_channel_t)); recorder_channel->record_request = NULL; recorder_channel->stop_response = NULL; recorder_channel->detector = mpf_activity_detector_create(pool); recorder_channel->max_time = 0; recorder_channel->cur_time = 0; recorder_channel->cur_size = 0; recorder_channel->file_name = NULL; recorder_channel->audio_out = NULL; capabilities = mpf_sink_stream_capabilities_create(pool); mpf_codec_capabilities_add( &capabilities->codecs, MPF_SAMPLE_RATE_8000 | MPF_SAMPLE_RATE_16000, "LPCM"); /* create media termination */ termination = mrcp_engine_audio_termination_create( recorder_channel, /* object to associate */ &audio_stream_vtable, /* virtual methods table of audio stream */ capabilities, /* stream capabilities */ pool); /* pool to allocate memory from */ /* create engine channel base */ recorder_channel->channel = mrcp_engine_channel_create( engine, /* engine */ &channel_vtable, /* virtual methods table of engine channel */ recorder_channel, /* object to associate */ termination, /* associated media termination */ pool); /* pool to allocate memory from */ return recorder_channel->channel; }
/** Create demo synthesizer channel derived from engine channel base */ static mrcp_engine_channel_t* demo_synth_engine_channel_create(mrcp_engine_t *engine, apr_pool_t *pool) { mpf_stream_capabilities_t *capabilities; mpf_termination_t *termination; /* create demo synth channel */ demo_synth_channel_t *synth_channel = apr_palloc(pool,sizeof(demo_synth_channel_t)); synth_channel->demo_engine = engine->obj; synth_channel->speak_request = NULL; synth_channel->stop_response = NULL; synth_channel->time_to_complete = 0; synth_channel->paused = FALSE; synth_channel->audio_file = NULL; capabilities = mpf_source_stream_capabilities_create(pool); mpf_codec_capabilities_add( &capabilities->codecs, MPF_SAMPLE_RATE_8000 | MPF_SAMPLE_RATE_16000, "LPCM"); /* create media termination */ termination = mrcp_engine_audio_termination_create( synth_channel, /* object to associate */ &audio_stream_vtable, /* virtual methods table of audio stream */ capabilities, /* stream capabilities */ pool); /* pool to allocate memory from */ /* create engine channel base */ synth_channel->channel = mrcp_engine_channel_create( engine, /* engine */ &channel_vtable, /* virtual methods table of engine channel */ synth_channel, /* object to associate */ termination, /* associated media termination */ pool); /* pool to allocate memory from */ return synth_channel->channel; }