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; }
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; }
int main(int argc, char const* argv[]) { apr_pool_t* pool = NULL; apr_pool_t* spool = NULL; int i; struct iovec cattext[101]; static char const SP = ' '; char const* outfile; apr_status_t status; apt_dir_layout_t* dirLayout = NULL; mrcp_client_t* client = NULL; mrcp_application_t* app = NULL; mrcp_session_t* sess = NULL; mpf_stream_capabilities_t* caps = NULL; mpf_termination_t* term = NULL; mrcp_channel_t* chan = NULL; struct stat info; if (argc < 2) { puts("Usage:"); printf("\t%s \"This is a synthetic voice.\"", argv[0]); exit(1); } /* Just detect various directory layout constellations */ if (stat(ROOT_DIR, &info)) ROOT_DIR = ROOT_DIR2; if (stat(ROOT_DIR, &info)) ROOT_DIR = ROOT_DIR3; /* Initialize platform first */ if (apr_initialize() != APR_SUCCESS) FAIL("Cannot initialize APR platform"); pool = apt_pool_create(); if (!pool) FAIL("Not enough memory"); for (i = 0; (i < argc - 2) && (i < 50); i += 2) { cattext[2 * i].iov_base = (void*) argv[i + 1]; cattext[2 * i].iov_len = strlen(argv[i + 1]); cattext[2 * i + 1].iov_base = (void*) &SP; cattext[2 * i + 1].iov_len = 1; } cattext[2 * i].iov_base = (void*) argv[i + 1]; cattext[2 * i].iov_len = strlen(argv[i + 1]); text = apr_pstrcatv(pool, cattext, 2 * i + 1, NULL); if (!text) FAIL("Not enough memory"); outfile = apr_pstrcat(pool, ROOT_DIR, "/data/", PCM_OUT_FILE, NULL); printf("This is a sample C UniMRCP client synthesizer scenario.\n"); printf("Use client configuration from %s/conf/unimrcpclient.xml\n", ROOT_DIR); printf("Use profile %s\n", MRCP_PROFILE); printf("Synthesize text: `%s'\n", text); printf("Write output to file: %s\n", outfile); printf("\n"); printf("Press enter to start the session...\n"); (void) getchar(); apt_log_instance_create(APT_LOG_OUTPUT_NONE, APT_PRIO_DEBUG, pool); apt_log_ext_handler_set(UniSynth_logger); dirLayout = apt_default_dir_layout_create(ROOT_DIR, pool); /* Create and start the client in a root dir */ client = unimrcp_client_create(dirLayout); if (!client) FAIL("Cannot create UniMRCP client"); app = mrcp_application_create(UniSynthAppMsgHandler, NULL, mrcp_client_memory_pool_get(client)); if (!app) FAIL("Cannot create MRCP application"); if (!mrcp_client_application_register(client, app, "Sample C app")) FAIL("Cannot register MRCP application"); if (!mrcp_client_start(client)) FAIL("Cannot start MRCP client"); /* Create a session using MRCP profile MRCP_PROFILE */ sess = mrcp_application_session_create(app, MRCP_PROFILE, NULL); if (!sess) FAIL("Cannot create session"); spool = mrcp_application_session_pool_get(sess); /* Create audio termination with capabilities */ caps = mpf_stream_capabilities_create(STREAM_DIRECTION_SEND, spool); if (!caps) FAIL("Error creating capabilities"); if (!mpf_codec_capabilities_add(&caps->codecs, MPF_SAMPLE_RATE_8000, "LPCM")) FAIL("Error adding codec capabilities"); term = mrcp_application_audio_termination_create(sess, &stream_vtable, caps, NULL); if (!term) FAIL("Cannot create audio termination"); /* Add signaling channel (and start processing in OnAdd method */ f = fopen(outfile, "wb"); if (!f) FAIL("Cannot open output file"); status = apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_DEFAULT, pool); if (status != APR_SUCCESS) FAIL("Cannot create mutex"); status = apr_thread_cond_create(&cond, pool); if (status != APR_SUCCESS) FAIL("Cannot create condition variable"); chan = mrcp_application_channel_create(sess, MRCP_SYNTHESIZER_RESOURCE, term, NULL, NULL); if (!chan) FAIL("Cannot create channel"); if (!mrcp_application_channel_add(sess, chan)) FAIL("Cannot add channel"); /* Now wait until the processing finishes */ apr_thread_mutex_lock(mutex); while (err < 0) apr_thread_cond_wait(cond, mutex); apr_thread_mutex_unlock(mutex); cleanup: if (sess) mrcp_application_session_terminate(sess); if (f) fclose(f); if (client) mrcp_client_shutdown(client); if (app) mrcp_application_destroy(app); if (client) mrcp_client_destroy(client); apt_log_instance_destroy(); if (pool) apr_pool_destroy(pool); apr_terminate(); puts("Program finished, memory released. Press any key to exit."); (void) getchar(); return err; }