mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-02-07 14:18:25 +00:00
Accept ALL parameter to enable/disable all codecs with one command.
This commit is contained in:
parent
681232c7e6
commit
e3ffbce629
4 changed files with 44 additions and 19 deletions
|
|
@ -1,9 +1,10 @@
|
|||
#include "audio-codec-disable.h"
|
||||
#include "audio-codec-get.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
AudioCodecDisableCommand::AudioCodecDisableCommand() :
|
||||
DaemonCommand("audio-codec-disable", "audio-codec-disable <payload_type_number|mime_type>",
|
||||
DaemonCommand("audio-codec-disable", "audio-codec-disable <payload_type_number|mime_type|ALL>",
|
||||
"Disable an audio codec.\n"
|
||||
"<mime_type> is of the form mime/rate/channels, eg. speex/16000/1") {
|
||||
}
|
||||
|
|
@ -15,26 +16,34 @@ void AudioCodecDisableCommand::exec(Daemon *app, const char *args) {
|
|||
app->sendResponse(Response("Missing parameter.", Response::Error));
|
||||
} else {
|
||||
string mime_type;
|
||||
int ptnum;
|
||||
int ptnum = -1;
|
||||
ist >> mime_type;
|
||||
PayloadTypeParser parser(app->getCore(), mime_type);
|
||||
PayloadTypeParser parser(app->getCore(), mime_type, true);
|
||||
if (!parser.successful()) {
|
||||
app->sendResponse(Response("Incorrect mime type format.", Response::Error));
|
||||
return;
|
||||
}
|
||||
ptnum = parser.payloadTypeNumber();
|
||||
if (!parser.all()) ptnum = parser.payloadTypeNumber();
|
||||
|
||||
int index = 0;
|
||||
for (const MSList *node = linphone_core_get_audio_codecs(app->getCore()); node != NULL; node = ms_list_next(node)) {
|
||||
PayloadType *payload = reinterpret_cast<PayloadType*>(node->data);
|
||||
if (ptnum == linphone_core_get_payload_type_number(app->getCore(), payload)) {
|
||||
if (parser.all()) {
|
||||
linphone_core_enable_payload_type(app->getCore(), payload, false);
|
||||
app->sendResponse(PayloadTypeResponse(app->getCore(), payload, index));
|
||||
return;
|
||||
} else {
|
||||
if (ptnum == linphone_core_get_payload_type_number(app->getCore(), payload)) {
|
||||
linphone_core_enable_payload_type(app->getCore(), payload, false);
|
||||
app->sendResponse(PayloadTypeResponse(app->getCore(), payload, index));
|
||||
return;
|
||||
}
|
||||
}
|
||||
++index;
|
||||
}
|
||||
app->sendResponse(Response("Audio codec not found.", Response::Error));
|
||||
if (parser.all()) {
|
||||
AudioCodecGetCommand getCommand;
|
||||
getCommand.exec(app, "");
|
||||
} else {
|
||||
app->sendResponse(Response("Audio codec not found.", Response::Error));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
#include "audio-codec-enable.h"
|
||||
#include "audio-codec-get.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
AudioCodecEnableCommand::AudioCodecEnableCommand() :
|
||||
DaemonCommand("audio-codec-enable", "audio-codec-enable <payload_type_number|mime_type>",
|
||||
DaemonCommand("audio-codec-enable", "audio-codec-enable <payload_type_number|mime_type|ALL>",
|
||||
"Enable an audio codec.\n"
|
||||
"<mime_type> is of the form mime/rate/channels, eg. speex/16000/1") {
|
||||
}
|
||||
|
|
@ -15,25 +16,34 @@ void AudioCodecEnableCommand::exec(Daemon *app, const char *args) {
|
|||
app->sendResponse(Response("Missing parameter.", Response::Error));
|
||||
} else {
|
||||
string mime_type;
|
||||
int ptnum;
|
||||
int ptnum = -1;
|
||||
ist >> mime_type;
|
||||
PayloadTypeParser parser(app->getCore(), mime_type);
|
||||
PayloadTypeParser parser(app->getCore(), mime_type, true);
|
||||
if (!parser.successful()) {
|
||||
app->sendResponse(Response("Incorrect mime type format.", Response::Error));
|
||||
return;
|
||||
}
|
||||
ptnum = parser.payloadTypeNumber();
|
||||
if (!parser.all()) ptnum = parser.payloadTypeNumber();
|
||||
|
||||
int index = 0;
|
||||
for (const MSList *node = linphone_core_get_audio_codecs(app->getCore()); node != NULL; node = ms_list_next(node)) {
|
||||
PayloadType *payload = reinterpret_cast<PayloadType*>(node->data);
|
||||
if (ptnum == linphone_core_get_payload_type_number(app->getCore(), payload)) {
|
||||
if (parser.all()) {
|
||||
linphone_core_enable_payload_type(app->getCore(), payload, true);
|
||||
app->sendResponse(PayloadTypeResponse(app->getCore(), payload, index));
|
||||
return;
|
||||
} else {
|
||||
if (ptnum == linphone_core_get_payload_type_number(app->getCore(), payload)) {
|
||||
linphone_core_enable_payload_type(app->getCore(), payload, true);
|
||||
app->sendResponse(PayloadTypeResponse(app->getCore(), payload, index));
|
||||
return;
|
||||
}
|
||||
}
|
||||
++index;
|
||||
}
|
||||
app->sendResponse(Response("Audio codec not found.", Response::Error));
|
||||
if (parser.all()) {
|
||||
AudioCodecGetCommand getCommand;
|
||||
getCommand.exec(app, "");
|
||||
} else {
|
||||
app->sendResponse(Response("Audio codec not found.", Response::Error));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -176,7 +176,11 @@ PayloadTypeResponse::PayloadTypeResponse(LinphoneCore *core, const PayloadType *
|
|||
}
|
||||
}
|
||||
|
||||
PayloadTypeParser::PayloadTypeParser(LinphoneCore *core, const string &mime_type) : mSuccesful(true), mPayloadTypeNumber(-1) {
|
||||
PayloadTypeParser::PayloadTypeParser(LinphoneCore *core, const string &mime_type, bool accept_all) : mAll(false), mSuccesful(true), mPayloadTypeNumber(-1) {
|
||||
if (accept_all && (mime_type.compare("ALL") == 0)) {
|
||||
mAll = true;
|
||||
return;
|
||||
}
|
||||
istringstream ist(mime_type);
|
||||
ist >> mPayloadTypeNumber;
|
||||
if (ist.fail()) {
|
||||
|
|
|
|||
|
|
@ -128,10 +128,12 @@ private:
|
|||
|
||||
class PayloadTypeParser {
|
||||
public:
|
||||
PayloadTypeParser(LinphoneCore *core, const std::string &mime_type);
|
||||
PayloadTypeParser(LinphoneCore *core, const std::string &mime_type, bool accept_all = false);
|
||||
inline bool all() { return mAll; };
|
||||
inline bool successful() { return mSuccesful; };
|
||||
inline int payloadTypeNumber() { return mPayloadTypeNumber; };
|
||||
private:
|
||||
bool mAll;
|
||||
bool mSuccesful;
|
||||
int mPayloadTypeNumber;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue