siproc

A primitive SIP client that spawns processes for each call
git clone git://xatko.vsos.ethz.ch/siproc.git
Log | Files | Refs

commit 78b1b0f2aaa15f5d161d330bd8624655920ce623
parent 699213bb8839811acad732d123c16fd795dc2657
Author: Dominik Schmidt <dominik@schm1dt.ch>
Date:   Sat, 10 Aug 2019 19:16:16 +0200

Implement feedback for when a play-command has finished.

Additionally this reworks how the play command works.
Every call now adds a new player into a vector. The stop-command
always stops the last in the list.

Diffstat:
src/siproc.cpp | 59+++++++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 43 insertions(+), 16 deletions(-)

diff --git a/src/siproc.cpp b/src/siproc.cpp @@ -76,15 +76,28 @@ EV ev_table = EV(); using namespace pj; class MyAccount; +class MyCall; -class MyCall : public Call{ +class MyAudioMediaPlayer : public AudioMediaPlayer { + MyCall* call; + public: + char* path; + MyAudioMediaPlayer(MyCall* c, char *what) : AudioMediaPlayer(){ + call = c; + path = what; + } + + virtual bool onEof(); +}; + +class MyCall: public Call{ FILE *c_stdin; int c_stdout; MyAccount *myacc; pid_t child; char *line; size_t line_length; - AudioMediaPlayer player; + std::vector<MyAudioMediaPlayer*> players; AudioMediaRecorder recorder; public: MyCall(Account &acc, int call_id = PJSUA_INVALID_ID) : Call(acc, call_id){ @@ -104,6 +117,9 @@ class MyCall : public Call{ if(child != -1){ fork_off(); } + for(unsigned int i=0; i<players.size(); i++){ + delete players[i]; + } } AudioMedia& playdev(){ @@ -150,7 +166,15 @@ class MyCall : public Call{ } } - virtual void onCallMediaState(OnCallMediaStateParam &prm){ + bool onPlayerFinished(char *path, MyAudioMediaPlayer* who){ + command("STOPPED %s\n", path); + delete who; + for(unsigned int i=0; i<players.size(); i++){ + if(players[i] == who){ + players.erase(players.begin()+i); + } + } + return false; } int command(const char *cmd, ...){ @@ -203,31 +227,29 @@ class MyCall : public Call{ void cmd_play(char *path){ AudioMedia& play_dev_med = playdev(); + MyAudioMediaPlayer* player = new MyAudioMediaPlayer(this, path); try { - player.createPlayer(path, PJMEDIA_FILE_NO_LOOP); - player.startTransmit(play_dev_med); + player->createPlayer(path, PJMEDIA_FILE_NO_LOOP); + player->startTransmit(play_dev_med); } catch(Error& err){ //std::cerr << err <<std::endl; } + players.push_back(player); } void cmd_record(char *path){ AudioMedia& play_dev_med = playdev(); - - try { - player.createPlayer(path, PJMEDIA_FILE_NO_LOOP); - player.startTransmit(play_dev_med); - } - catch(Error& err){ - //std::cerr << err <<std::endl; - } } void cmd_stop(char *path){ - AudioMedia& play_dev_med = playdev(); + if(players.size()>0){ + AudioMedia& play_dev_med = playdev(); - player.stopTransmit(play_dev_med); + MyAudioMediaPlayer* player = players.back(); + player->stopTransmit(play_dev_med); + onPlayerFinished(player->path, player); + } } void cmd_ringing(){ @@ -295,7 +317,12 @@ class MyCall : public Call{ } }; -class MyAccount : public Account{ +bool MyAudioMediaPlayer::onEof(){ + return call->onPlayerFinished(path, this); +} + + +class MyAccount: public Account{ public: char **args; MyAccount(char **args) {