From 7fde5aa0f4e1d92636ad04c9a98d48b870032bf4 Mon Sep 17 00:00:00 2001 From: smorlat Date: Thu, 2 Jul 2009 22:01:20 +0000 Subject: [PATCH] fix fantastic bug in msfilter.c about type checking. also in method definition in msrtp.h git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@514 3f6dc0c8-ddfe-455d-9043-3cd528dc4637 --- linphone/console/commands.c | 34 +++++++++++++++++++ linphone/linphone.kdevelop | 34 +++++++++---------- .../include/mediastreamer2/mediastream.h | 1 + .../include/mediastreamer2/msrtp.h | 2 +- linphone/mediastreamer2/src/audiostream.c | 12 +++++++ linphone/mediastreamer2/src/msfilter.c | 4 +-- linphone/mediastreamer2/src/msrtp.c | 7 ++++ 7 files changed, 74 insertions(+), 20 deletions(-) diff --git a/linphone/console/commands.c b/linphone/console/commands.c index ff623ae2a..1cd8f6378 100644 --- a/linphone/console/commands.c +++ b/linphone/console/commands.c @@ -33,6 +33,10 @@ #include #include "linphonec.h" +#ifndef WIN32 +#include +#endif + /*************************************************************************** * * Forward declarations @@ -64,6 +68,7 @@ static int lpc_cmd_unregister(LinphoneCore *, char *); static int lpc_cmd_duration(LinphoneCore *lc, char *args); static int lpc_cmd_status(LinphoneCore *lc, char *args); static int lpc_cmd_ports(LinphoneCore *lc, char *args); +static int lpc_cmd_speak(LinphoneCore *lc, char *args); /* Command handler helpers */ static void linphonec_proxy_add(LinphoneCore *lc); @@ -181,6 +186,11 @@ LPC_COMMAND commands[] = { { "ports", lpc_cmd_ports, "Network ports configuration", "'ports' \t: prints current used ports.\n" "'ports sip '\t: Sets the sip port.\n" }, + { "speak", lpc_cmd_speak, "Speak a sentence using espeak TTS engine", + "This feature is available only in file mode. (see 'help soundcard')\n" + "'speak ' : speak a text using the specified espeak voice.\n" + "Example for english voice: 'speak default Hello my friend !'" + }, { (char *)NULL, (lpc_cmd_handler)NULL, (char *)NULL, (char *)NULL } }; @@ -1455,6 +1465,30 @@ static int lpc_cmd_ports(LinphoneCore *lc, char *args) return 1; } +static int lpc_cmd_speak(LinphoneCore *lc, char *args){ +#ifndef WIN32 + char voice[64]; + char *sentence; + char cl[128]; + char *wavfile; + int status; + memset(voice,0,sizeof(voice)); + sscanf(args,"%s63",voice); + sentence=args+strlen(voice); + wavfile=tempnam("/tmp/","linphonec-espeak-"); + snprintf(cl,sizeof(cl),"espeak -v %s -w %s \"%s\"",voice,wavfile,sentence); + status=system(cl); + if (WEXITSTATUS(status)==0){ + linphone_core_set_play_file(lc,wavfile); + }else{ + linphonec_out("espeak command failed."); + } +#else + linphonec_out("Sorry, this command is not implemented in windows version."); +#endif + return 1; +} + /*************************************************************************** * * Command table management funx diff --git a/linphone/linphone.kdevelop b/linphone/linphone.kdevelop index 5068dc8f6..e5a3d2ce6 100644 --- a/linphone/linphone.kdevelop +++ b/linphone/linphone.kdevelop @@ -10,15 +10,15 @@ linphone . false - - + + executable /home/smorlat/sources/git/linphone/linphone - - + + /home/smorlat/sources/git/linphone/linphone false false @@ -390,13 +390,13 @@ make - + 0 - - - + + + default @@ -407,9 +407,9 @@ 0 0 false - - - + + + default @@ -418,11 +418,11 @@ - - - - - + + + + + true false false @@ -525,7 +525,7 @@ .; - + set m_,_ theValue diff --git a/linphone/mediastreamer2/include/mediastreamer2/mediastream.h b/linphone/mediastreamer2/include/mediastreamer2/mediastream.h index 61d7dab97..3066d9e11 100644 --- a/linphone/mediastreamer2/include/mediastreamer2/mediastream.h +++ b/linphone/mediastreamer2/include/mediastreamer2/mediastream.h @@ -48,6 +48,7 @@ struct _AudioStream MSFilter *dtmfgen; MSFilter *ec;/*echo canceler*/ MSFilter *volsend,*volrecv; /*MSVolumes*/ + MSFilter *resampler; uint64_t last_packet_count; time_t last_packet_time; EchoLimiterType el_type; /*use echo limiter: two MSVolume, measured input level controlling local output level*/ diff --git a/linphone/mediastreamer2/include/mediastreamer2/msrtp.h b/linphone/mediastreamer2/include/mediastreamer2/msrtp.h index 9c1171551..0bd961b82 100644 --- a/linphone/mediastreamer2/include/mediastreamer2/msrtp.h +++ b/linphone/mediastreamer2/include/mediastreamer2/msrtp.h @@ -35,7 +35,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define MS_RTP_SEND_UNMUTE_MIC MS_FILTER_METHOD_NO_ARG(MS_RTP_SEND_ID,4) -#define MS_RTP_SEND_SET_RELAY_SESSION_ID MS_FILTER_METHOD(MS_RTP_RECV_ID,5,const char *) +#define MS_RTP_SEND_SET_RELAY_SESSION_ID MS_FILTER_METHOD(MS_RTP_SEND_ID,5,const char *) extern MSFilterDesc ms_rtp_send_desc; diff --git a/linphone/mediastreamer2/src/audiostream.c b/linphone/mediastreamer2/src/audiostream.c index 516d64980..2da979d90 100644 --- a/linphone/mediastreamer2/src/audiostream.c +++ b/linphone/mediastreamer2/src/audiostream.c @@ -220,6 +220,7 @@ int audio_stream_start_full(AudioStream *stream, RtpProfile *profile, const char if (captcard!=NULL) stream->soundread=ms_snd_card_create_reader(captcard); else { stream->soundread=ms_filter_new(MS_FILE_PLAYER_ID); + stream->resampler=ms_filter_new(MS_RESAMPLE_ID); if (infile!=NULL) audio_stream_play(stream,infile); } if (playcard!=NULL) stream->soundwrite=ms_snd_card_create_writer(playcard); @@ -288,6 +289,8 @@ int audio_stream_start_full(AudioStream *stream, RtpProfile *profile, const char /*sending graph*/ ms_connection_helper_start(&h); ms_connection_helper_link(&h,stream->soundread,-1,0); + if (stream->resampler) + ms_connection_helper_link(&h,stream->resampler,0,0); if (stream->ec) ms_connection_helper_link(&h,stream->ec,1,1); if (stream->volsend) @@ -362,9 +365,16 @@ void audio_stream_set_rtcp_information(AudioStream *st, const char *cname, const void audio_stream_play(AudioStream *st, const char *name){ if (ms_filter_get_id(st->soundread)==MS_FILE_PLAYER_ID){ + int from_rate=0, to_rate=0; ms_filter_call_method_noarg(st->soundread,MS_FILE_PLAYER_CLOSE); ms_filter_call_method(st->soundread,MS_FILE_PLAYER_OPEN,(void*)name); ms_filter_call_method_noarg(st->soundread,MS_FILE_PLAYER_START); + ms_filter_call_method(st->soundread,MS_FILTER_GET_SAMPLE_RATE,&from_rate); + ms_filter_call_method(st->rtpsend,MS_FILTER_GET_SAMPLE_RATE,&to_rate); + if (st->resampler){ + ms_filter_call_method(st->resampler,MS_FILTER_SET_SAMPLE_RATE,&from_rate); + ms_filter_call_method(st->resampler,MS_FILTER_SET_OUTPUT_SAMPLE_RATE,&to_rate); + } }else{ ms_error("Cannot play file: the stream hasn't been started with" " audio_stream_start_with_files"); @@ -437,6 +447,8 @@ void audio_stream_stop(AudioStream * stream) /*dismantle the outgoing graph*/ ms_connection_helper_start(&h); ms_connection_helper_unlink(&h,stream->soundread,-1,0); + if (stream->resampler!=NULL) + ms_connection_helper_unlink(&h,stream->resampler,0,0); if (stream->ec!=NULL) ms_connection_helper_unlink(&h,stream->ec,1,1); if (stream->volsend!=NULL) diff --git a/linphone/mediastreamer2/src/msfilter.c b/linphone/mediastreamer2/src/msfilter.c index 26cc9fcd7..4bbfaa5f0 100644 --- a/linphone/mediastreamer2/src/msfilter.c +++ b/linphone/mediastreamer2/src/msfilter.c @@ -157,13 +157,13 @@ int ms_filter_call_method(MSFilter *f, unsigned int id, void *arg){ int i; unsigned int magic=MS_FILTER_METHOD_GET_FID(id); if (magic!=MS_FILTER_BASE_ID && magic!=f->desc->id) { - ms_fatal("Bad method definition in filter %s",f->desc->name); + ms_fatal("Method type checking failed when calling %u on filter %s",id,f->desc->name); return -1; } for(i=0;methods!=NULL && methods[i].method!=NULL; i++){ unsigned int mm=MS_FILTER_METHOD_GET_FID(methods[i].id); if (mm!=f->desc->id && mm!=MS_FILTER_BASE_ID) { - ms_fatal("MSFilter method mismatch: bad call."); + ms_fatal("Bad method definition on filter %s. fid=%u , mm=%u",f->desc->name,f->desc->id,mm); return -1; } if (methods[i].id==id){ diff --git a/linphone/mediastreamer2/src/msrtp.c b/linphone/mediastreamer2/src/msrtp.c index adb388e37..f1c9cb9bc 100644 --- a/linphone/mediastreamer2/src/msrtp.c +++ b/linphone/mediastreamer2/src/msrtp.c @@ -119,6 +119,12 @@ static int sender_set_relay_session_id(MSFilter *f, void*arg){ return 0; } +static int sender_get_sr(MSFilter *f, void *arg){ + SenderData *d = (SenderData *) f->data; + *(int*)arg=d->rate; + return 0; +} + /* the goal of that function is to return a absolute timestamp closest to real time, with respect of given packet_ts, which is a relative to an undefined origin*/ static uint32_t get_cur_timestamp(MSFilter * f, uint32_t packet_ts) { @@ -215,6 +221,7 @@ static MSFilterMethod sender_methods[] = { {MS_RTP_SEND_SET_SESSION, sender_set_session}, {MS_RTP_SEND_SEND_DTMF, sender_send_dtmf}, {MS_RTP_SEND_SET_RELAY_SESSION_ID, sender_set_relay_session_id}, + {MS_FILTER_GET_SAMPLE_RATE, sender_get_sr }, {0, NULL} };