Add adaptive-jitter-compensation command.

Fixes bug 0000191.
This commit is contained in:
Ghislain MARY 2012-08-27 13:42:51 +02:00
parent 0bb2646c22
commit b831b132a7
4 changed files with 126 additions and 0 deletions

View file

@ -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 \

View file

@ -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 [<stream>] [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"
"<stream> 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));
}
}
}

View file

@ -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_

View file

@ -10,6 +10,7 @@
#include <poll.h>
#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());