| 1 /* |
|
| 2 The mediastreamer library aims at providing modular media processing and I/O |
|
| 3 for linphone, but also for any telephony application. |
|
| 4 Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org |
|
| 5 |
|
| 6 This library is free software; you can redistribute it and/or |
|
| 7 modify it under the terms of the GNU Lesser General Public |
|
| 8 License as published by the Free Software Foundation; either |
|
| 9 version 2.1 of the License, or (at your option) any later version. |
|
| 10 |
|
| 11 This library is distributed in the hope that it will be useful, |
|
| 12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 14 Lesser General Public License for more details. |
|
| 15 |
|
| 16 You should have received a copy of the GNU Lesser General Public |
|
| 17 License along with this library; if not, write to the Free Software |
|
| 18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
| 19 */ |
|
| 20 |
|
| 21 #include "ms.h" |
|
| 22 |
|
| 23 #include "sndcard.h" |
|
| 24 #include "mscopy.h" |
|
| 25 #include "mstimer.h" |
|
| 26 #include "msspeexdec.h" |
|
| 27 #include "msspeexenc.h" |
|
| 28 |
|
| 29 #include <signal.h> |
|
| 30 #include <sys/types.h> |
|
| 31 #include <unistd.h> |
|
| 32 |
|
| 33 static int cond=1; |
|
| 34 |
|
| 35 void stop_handler(int signum) |
|
| 36 { |
|
| 37 cond=0; |
|
| 38 } |
|
| 39 |
|
| 40 int main() |
|
| 41 { |
|
| 42 MSFilter *play,*enc,*dec,*rec; |
|
| 43 MSSync *timer; |
|
| 44 SndCard *card; |
|
| 45 int rate=16000; |
|
| 46 |
|
| 47 ms_init(); |
|
| 48 signal(SIGINT,stop_handler); |
|
| 49 /* get the first card */ |
|
| 50 card=snd_card_manager_get_card(snd_card_manager,0); |
|
| 51 if (card==NULL) g_error("No sound card detected."); |
|
| 52 |
|
| 53 play=snd_card_create_read_filter(card); |
|
| 54 rec=snd_card_create_write_filter(card); |
|
| 55 |
|
| 56 enc=ms_speex_enc_new(); |
|
| 57 dec=ms_speex_dec_new(); |
|
| 58 |
|
| 59 ms_filter_set_property(play,MS_FILTER_PROPERTY_FREQ,&rate); |
|
| 60 ms_filter_set_property(rec,MS_FILTER_PROPERTY_FREQ,&rate); |
|
| 61 ms_filter_set_property(enc,MS_FILTER_PROPERTY_FREQ,&rate); |
|
| 62 ms_filter_set_property(dec,MS_FILTER_PROPERTY_FREQ,&rate); |
|
| 63 timer=ms_timer_new(); |
|
| 64 |
|
| 65 ms_filter_add_link(play,enc); |
|
| 66 ms_filter_add_link(enc,dec); |
|
| 67 ms_filter_add_link(dec,rec); |
|
| 68 ms_sync_attach(timer,play); |
|
| 69 |
|
| 70 ms_start(timer); |
|
| 71 while(cond) |
|
| 72 { |
|
| 73 sleep(1); |
|
| 74 } |
|
| 75 printf("stoping sync...\n"); |
|
| 76 ms_stop(timer); |
|
| 77 printf("unlinking filters...\n"); |
|
| 78 ms_filter_remove_links(play,enc); |
|
| 79 ms_filter_remove_links(enc,dec); |
|
| 80 ms_filter_remove_links(dec,rec); |
|
| 81 printf("destroying filters...\n"); |
|
| 82 ms_filter_destroy(play); |
|
| 83 ms_filter_destroy(enc); |
|
| 84 ms_filter_destroy(dec); |
|
| 85 ms_filter_destroy(rec); |
|
| 86 ms_sync_destroy(timer); |
|
| 87 return 0; |
|
| 88 } |
|