Add the play-wav command.

This commit is contained in:
Ghislain MARY 2012-12-12 14:32:12 +01:00
parent 2c5601b0f2
commit 24fd131cb5
5 changed files with 78 additions and 2 deletions

View file

@ -20,6 +20,7 @@ linphone_daemon_SOURCES=daemon.cc \
commands/ipv6.cc \
commands/media-encryption.cc \
commands/msfilter-add-fmtp.cc \
commands/play-wav.cc \
commands/pop-event.cc \
commands/port.cc \
commands/ptime.cc \
@ -47,6 +48,7 @@ linphone_daemon_SOURCES=daemon.cc \
commands/ipv6.h \
commands/media-encryption.h \
commands/msfilter-add-fmtp.h \
commands/play-wav.h \
commands/pop-event.h \
commands/port.h \
commands/ptime.h \

View file

@ -0,0 +1,37 @@
#include "play-wav.h"
using namespace std;
PlayWavCommand::PlayWavCommand() :
DaemonCommand("play-wav", "play-wav <filename>",
"Play an WAV audio file (needs to have enabled the linphone sound daemon (LSD).\n"
"<filename> is the WAV file to be played.") {
addExample(new DaemonCommandExample("play-wav /usr/local/share/sounds/linphone/hello8000.wav",
"Status: Ok"));
}
void playWavFinished(LsdPlayer *p) {
linphone_sound_daemon_release_player(lsd_player_get_daemon(p), p);
}
void PlayWavCommand::exec(Daemon *app, const char *args) {
LinphoneSoundDaemon *lsd = app->getLSD();
if (!lsd) {
app->sendResponse(Response("The linphone sound daemon (LSD) is not enabled.", Response::Error));
return;
}
string filename;
istringstream ist(args);
ist >> filename;
if (ist.eof() && (filename.length() == 0)) {
app->sendResponse(Response("Missing filename parameter.", Response::Error));
} else if (ist.fail()) {
app->sendResponse(Response("Incorrect filename parameter.", Response::Error));
} else {
LsdPlayer *p = linphone_sound_daemon_get_player(lsd);
lsd_player_set_callback(p, playWavFinished);
lsd_player_play(p, filename.c_str());
app->sendResponse(Response());
}
}

View file

@ -0,0 +1,12 @@
#ifndef COMMAND_PLAY_WAV_H_
#define COMMAND_PLAY_WAV_H_
#include "../daemon.h"
class PlayWavCommand: public DaemonCommand {
public:
PlayWavCommand();
virtual void exec(Daemon *app, const char *args);
};
#endif //COMMAND_PLAY_WAV_H_

View file

@ -31,6 +31,7 @@
#include "commands/ipv6.h"
#include "commands/media-encryption.h"
#include "commands/msfilter-add-fmtp.h"
#include "commands/play-wav.h"
#include "commands/pop-event.h"
#include "commands/port.h"
#include "commands/ptime.h"
@ -245,7 +246,7 @@ bool DaemonCommand::matches(const char *name) const {
}
Daemon::Daemon(const char *config_path, const char *factory_config_path, const char *log_file, const char *pipe_name, bool display_video, bool capture_video) :
mLogFile(NULL), mCallIds(0), mProxyIds(0), mAudioStreamIds(0) {
mLSD(0), mLogFile(NULL), mCallIds(0), mProxyIds(0), mAudioStreamIds(0) {
ms_mutex_init(&mMutex, NULL);
mServerFd = -1;
mChildFd = -1;
@ -291,6 +292,10 @@ LinphoneCore *Daemon::getCore() {
return mLc;
}
LinphoneSoundDaemon *Daemon::getLSD() {
return mLSD;
}
int Daemon::updateCallId(LinphoneCall *call) {
int val = (int) (long) linphone_call_get_user_pointer(call);
if (val == 0) {
@ -360,6 +365,7 @@ void Daemon::initCommands() {
mCommands.push_back(new CallCommand());
mCommands.push_back(new TerminateCommand());
mCommands.push_back(new DtmfCommand());
mCommands.push_back(new PlayWavCommand());
mCommands.push_back(new PopEventCommand());
mCommands.push_back(new AnswerCommand());
mCommands.push_back(new CallStatusCommand());
@ -624,10 +630,11 @@ static void printHelp() {
"\t--dump-commands-help\tDump the help of every available commands.\n"
"\t--dump-commands-html-help\tDump the help of every available commands.\n"
"\t--pipe <pipename>\tCreate an unix server socket to receive commands.\n"
"\t--log <path>\t\tSupply a file where the log will be saved\n"
"\t--log <path>\t\tSupply a file where the log will be saved.\n"
"\t--factory-config <path>\tSupply a readonly linphonerc style config file to start with.\n"
"\t--config <path>\t\tSupply a linphonerc style config file to start with.\n"
"\t--disable-stats-events\t\tDo not automatically raise RTP statistics events.\n"
"\t--enable-lsd\t\tUse the linphone sound daemon.\n"
"\t-C\t\t\tenable video capture.\n"
"\t-D\t\t\tenable video display.\n");
}
@ -687,6 +694,15 @@ void Daemon::enableStatsEvents(bool enabled){
mUseStatsEvents=enabled;
}
void Daemon::enableLSD(bool enabled) {
if (mLSD) linphone_sound_daemon_destroy(mLSD);
linphone_core_use_sound_daemon(mLc, NULL);
if (enabled) {
mLSD = linphone_sound_daemon_new(NULL, 44100, 1);
linphone_core_use_sound_daemon(mLc, mLSD);
}
}
Daemon::~Daemon() {
uninitCommands();
@ -694,6 +710,7 @@ Daemon::~Daemon() {
audio_stream_stop(it->second);
}
enableLSD(false);
linphone_core_destroy(mLc);
if (mChildFd != -1) {
close(mChildFd);
@ -722,6 +739,7 @@ int main(int argc, char *argv[]) {
bool capture_video = false;
bool display_video = false;
bool nostats=FALSE;
bool lsd_enabled = false;
int i;
for (i = 1; i < argc; ++i) {
@ -769,10 +787,13 @@ int main(int argc, char *argv[]) {
display_video = true;
}else if (strcmp(argv[i],"--disable-stats-events")==0){
nostats=TRUE;
} else if (strcmp(argv[i], "--enable-lsd") == 0) {
lsd_enabled = true;
}
}
Daemon app(config_path, factory_config_path, log_file, pipe_name, display_video, capture_video);
app.enableStatsEvents(!nostats);
app.enableLSD(lsd_enabled);
return app.run();
}
;

View file

@ -2,6 +2,7 @@
#define DAEMON_H_
#include <linphonecore.h>
#include <linphonecore_utils.h>
#include <mediastreamer2/mediastream.h>
#include <mediastreamer2/mscommon.h>
@ -169,6 +170,7 @@ public:
void quit();
void sendResponse(const Response &resp);
LinphoneCore *getCore();
LinphoneSoundDaemon *getLSD();
const std::list<DaemonCommand*> &getCommandList() const;
LinphoneCall *findCall(int id);
LinphoneProxyConfig *findProxy(int id);
@ -182,6 +184,7 @@ public:
void dumpCommandsHelp();
void dumpCommandsHelpHtml();
void enableStatsEvents(bool enabled);
void enableLSD(bool enabled);
private:
static void* iterateThread(void *arg);
static void callStateChanged(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState state, const char *msg);
@ -199,6 +202,7 @@ private:
void initCommands();
void uninitCommands();
LinphoneCore *mLc;
LinphoneSoundDaemon *mLSD;
std::list<DaemonCommand*> mCommands;
std::queue<Response*> mEventQueue;
int mServerFd;