diff --git a/daemon/daemon.cc b/daemon/daemon.cc index 238013b98..b711ba780 100644 --- a/daemon/daemon.cc +++ b/daemon/daemon.cc @@ -1,4 +1,5 @@ -#include "linphonecore.h" +#include +#include #include #include @@ -8,6 +9,7 @@ #include #include #include +#include #include using namespace std; @@ -103,11 +105,13 @@ public: const list &getCommandList() const; LinphoneCall *findCall(int id); LinphoneProxyConfig *findProxy(int id); + AudioStream *findAudioStream(int id); bool pullEvent(); static int getCallId(LinphoneCall *call); int setCallId(LinphoneCall *call); static int getProxyId(LinphoneProxyConfig *proxy); int setProxyId(LinphoneProxyConfig *proxy); + int setAudioStreamId(AudioStream *audio_stream); private: static void callStateChanged(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState state, const char *msg); @@ -129,7 +133,9 @@ private: static Daemon *sZis; static int sCallIds; static int sProxyIds; + static int sAudioStreamIds; static const int sLineSize = 512; + std::map mAudioStreams; }; class CallCommand: public DaemonCommand { @@ -279,6 +285,62 @@ public: } }; +class AudioStreamStartCommand: public DaemonCommand { +public: + AudioStreamStartCommand() : + DaemonCommand("audio-stream-start", "audio-stream-start ", "Start an audio stream.") { + } + virtual void exec(Daemon *app, const char *args) { + char addr[256]; + int port; + char mime[64]; + if (sscanf(args, "%255s %d %63s", addr, &port, mime) == 3) { + int local_port = linphone_core_get_audio_port(app->getCore()); + const int jitt = linphone_core_get_audio_jittcomp(app->getCore()); + const bool_t echo_canceller = linphone_core_echo_cancellation_enabled(app->getCore()); + MSSndCardManager *manager = ms_snd_card_manager_get(); + MSSndCard *capture_card = ms_snd_card_manager_get_card(manager, linphone_core_get_capture_device(app->getCore())); + MSSndCard *play_card = ms_snd_card_manager_get_card(manager, linphone_core_get_playback_device(app->getCore())); + int payload_type = rtp_profile_get_payload_number_from_mime(&av_profile, mime); + if (payload_type < 0) { + app->sendResponse(Response("Payload not found")); + return; + } + + AudioStream *stream = audio_stream_new(local_port, false); + if (audio_stream_start_now(stream, &av_profile, addr, port, port + 1, payload_type, jitt, play_card, capture_card, echo_canceller) != 0) { + app->sendResponse(Response("Error during audio stream creation.")); + } + ostringstream ostr; + ostr << "Id: " << app->setAudioStreamId(stream) << "\n"; + app->sendResponse(Response(ostr.str().c_str(), Response::Ok)); + } else { + app->sendResponse(Response("Missing/Incorrect parameter(s).")); + } + } +}; + +class AudioStreamStopCommand: public DaemonCommand { +public: + AudioStreamStopCommand() : + DaemonCommand("audio-stream-stop", "audio-stream-stop