From b831b132a7a04a5e4d381b873d2dc4661fd0a292 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Mon, 27 Aug 2012 13:42:51 +0200 Subject: [PATCH] Add adaptive-jitter-compensation command. Fixes bug 0000191. --- daemon/Makefile.am | 2 + .../commands/adaptive-jitter-compensation.cc | 105 ++++++++++++++++++ .../commands/adaptive-jitter-compensation.h | 17 +++ daemon/daemon.cc | 2 + 4 files changed, 126 insertions(+) create mode 100644 daemon/commands/adaptive-jitter-compensation.cc create mode 100644 daemon/commands/adaptive-jitter-compensation.h diff --git a/daemon/Makefile.am b/daemon/Makefile.am index d483e9a59..eb193418e 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -3,6 +3,7 @@ bin_PROGRAMS=linphone-daemon linphone-daemon-pipetest linphone_daemon_SOURCES=daemon.cc \ + commands/adaptive-jitter-compensation.cc \ commands/answer.cc \ commands/audio-codec-disable.cc \ commands/audio-codec-enable.cc \ @@ -28,6 +29,7 @@ linphone_daemon_SOURCES=daemon.cc \ commands/unregister.cc \ commands/quit.cc \ daemon.h \ + commands/adaptive-jitter-compensation.h \ commands/answer.h \ commands/audio-codec-disable.h \ commands/audio-codec-enable.h \ diff --git a/daemon/commands/adaptive-jitter-compensation.cc b/daemon/commands/adaptive-jitter-compensation.cc new file mode 100644 index 000000000..2681bfc87 --- /dev/null +++ b/daemon/commands/adaptive-jitter-compensation.cc @@ -0,0 +1,105 @@ +#include "adaptive-jitter-compensation.h" + +using namespace std; + +class AdaptiveBufferCompensationCommandPrivate { +public: + enum StreamType { + AudioStream, + VideoStream + }; + + void outputAdaptiveBufferCompensation(Daemon *app, ostringstream &ost, StreamType type); + void outputAdaptiveBufferCompensations(Daemon *app, ostringstream &ost); +}; + +void AdaptiveBufferCompensationCommandPrivate::outputAdaptiveBufferCompensation(Daemon* app, ostringstream& ost, StreamType type) { + bool enabled = false; + switch (type) { + case AudioStream: + enabled = linphone_core_audio_adaptive_jittcomp_enabled(app->getCore()); + ost << "Audio: "; + break; + case VideoStream: + enabled = linphone_core_video_adaptive_jittcomp_enabled(app->getCore()); + ost << "Video: "; + break; + } + if (enabled) { + ost << "enabled\n"; + } else { + ost << "disabled\n"; + } +} + +void AdaptiveBufferCompensationCommandPrivate::outputAdaptiveBufferCompensations(Daemon* app, ostringstream& ost) +{ + outputAdaptiveBufferCompensation(app, ost, AdaptiveBufferCompensationCommandPrivate::AudioStream); + outputAdaptiveBufferCompensation(app, ost, AdaptiveBufferCompensationCommandPrivate::VideoStream); +} + +AdaptiveBufferCompensationCommand::AdaptiveBufferCompensationCommand() : + DaemonCommand("adaptive-jitter-compensation", "adaptive-jitter-compensation [] [enable|disable]", + "Enable or disable adaptive buffer compensation respectively with the 'enable' and 'disable' parameters for the specified stream, " + "return the status of the use of adaptive buffer compensation without parameter.\n" + " must be one of these values: audio, video."), + d(new AdaptiveBufferCompensationCommandPrivate()) { +} + +AdaptiveBufferCompensationCommand::~AdaptiveBufferCompensationCommand() { + delete d; +} + +void AdaptiveBufferCompensationCommand::exec(Daemon *app, const char *args) { + string stream; + string state; + istringstream ist(args); + ostringstream ost; + ist >> stream; + if (ist.fail()) { + d->outputAdaptiveBufferCompensations(app, ost); + app->sendResponse(Response(ost.str().c_str(), Response::Ok)); + } else { + ist >> state; + if (ist.fail()) { + if (stream.compare("audio") == 0) { + d->outputAdaptiveBufferCompensation(app, ost, AdaptiveBufferCompensationCommandPrivate::AudioStream); + app->sendResponse(Response(ost.str().c_str(), Response::Ok)); + } else if (stream.compare("video") == 0) { + d->outputAdaptiveBufferCompensation(app, ost, AdaptiveBufferCompensationCommandPrivate::VideoStream); + app->sendResponse(Response(ost.str().c_str(), Response::Ok)); + } else { + app->sendResponse(Response("Incorrect stream parameter.", Response::Error)); + } + } else { + AdaptiveBufferCompensationCommandPrivate::StreamType type; + bool enabled; + if (stream.compare("audio") == 0) { + type = AdaptiveBufferCompensationCommandPrivate::AudioStream; + } else if (stream.compare("video") == 0) { + type = AdaptiveBufferCompensationCommandPrivate::VideoStream; + } else { + app->sendResponse(Response("Incorrect stream parameter.", Response::Error)); + return; + } + if (state.compare("enable") == 0) { + enabled = TRUE; + } else if (state.compare("disable") == 0) { + enabled = FALSE; + } else { + app->sendResponse(Response("Incorrect parameter.", Response::Error)); + return; + } + switch (type) { + case AdaptiveBufferCompensationCommandPrivate::AudioStream: + linphone_core_enable_audio_adaptive_jittcomp(app->getCore(), enabled); + break; + case AdaptiveBufferCompensationCommandPrivate::VideoStream: + linphone_core_enable_video_adaptive_jittcomp(app->getCore(), enabled); + break; + } + d->outputAdaptiveBufferCompensation(app, ost, type); + app->sendResponse(Response(ost.str().c_str(), Response::Ok)); + } + } +} diff --git a/daemon/commands/adaptive-jitter-compensation.h b/daemon/commands/adaptive-jitter-compensation.h new file mode 100644 index 000000000..2091f951c --- /dev/null +++ b/daemon/commands/adaptive-jitter-compensation.h @@ -0,0 +1,17 @@ +#ifndef COMMAND_ADAPTIVE_BUFFER_COMPENSATION_H_ +#define COMMAND_ADAPTIVE_BUFFER_COMPENSATION_H_ + +#include "../daemon.h" + +class AdaptiveBufferCompensationCommandPrivate; + +class AdaptiveBufferCompensationCommand: public DaemonCommand { +public: + AdaptiveBufferCompensationCommand(); + ~AdaptiveBufferCompensationCommand(); + virtual void exec(Daemon *app, const char *args); +private: + AdaptiveBufferCompensationCommandPrivate *d; +}; + +#endif //COMMAND_ADAPTIVE_BUFFER_COMPENSATION_H_ diff --git a/daemon/daemon.cc b/daemon/daemon.cc index 217349c3a..9ef15b2ec 100644 --- a/daemon/daemon.cc +++ b/daemon/daemon.cc @@ -10,6 +10,7 @@ #include #include "daemon.h" +#include "commands/adaptive-jitter-compensation.h" #include "commands/answer.h" #include "commands/audio-codec-get.h" #include "commands/audio-codec-move.h" @@ -308,6 +309,7 @@ void Daemon::initCommands() { mCommands.push_back(new FirewallPolicyCommand()); mCommands.push_back(new MediaEncryptionCommand()); mCommands.push_back(new PortCommand()); + mCommands.push_back(new AdaptiveBufferCompensationCommand()); mCommands.push_back(new QuitCommand()); mCommands.push_back(new HelpCommand());