Module: sems
Branch: master
Commit: c794c4570c4d81ba241df18462ba923616919dbd
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=c794c4570c4d81ba241df18462ba923616919dbd

Author: Václav Kubart <[email protected]>
Committer: Václav Kubart <[email protected]>
Date:   Wed Apr 25 14:05:57 2012 +0200

transcoder: statistics about used codecs can be put into OPTIONS replies

---

 apps/sbc/SBC.cpp    |    1 +
 core/AmApi.cpp      |   30 +++++++++++++++++++++++++-----
 core/AmB2BMedia.cpp |   25 +++++++++++++++++++++++++
 core/AmB2BMedia.h   |    1 +
 core/AmConfig.cpp   |    6 ++++++
 core/AmConfig.h     |    3 +++
 doc/Readme.sbc.txt  |   26 ++++++++++++++++++++++++--
 7 files changed, 85 insertions(+), 7 deletions(-)

diff --git a/apps/sbc/SBC.cpp b/apps/sbc/SBC.cpp
index c39394b..cb2b7f5 100644
--- a/apps/sbc/SBC.cpp
+++ b/apps/sbc/SBC.cpp
@@ -629,6 +629,7 @@ void SBCFactory::invoke(const string& method, const AmArg& 
args,
     ret.push(AmArg("setRegexMap"));
     ret.push(AmArg("loadCallcontrolModules"));
     ret.push(AmArg("postControlCmd"));
+    ret.push(AmArg("printCallStats"));
   } else if(method == "printCallStats"){ 
     B2BMediaStatistics::instance()->getReport(args, ret);
   }  else
diff --git a/core/AmApi.cpp b/core/AmApi.cpp
index b85a729..ad9876d 100644
--- a/core/AmApi.cpp
+++ b/core/AmApi.cpp
@@ -29,6 +29,7 @@
 #include "AmApi.h"
 #include "log.h"
 #include "AmSession.h"
+#include "AmB2BMedia.h" // just because of statistics in reply to OPTIONS
 
 AmDynInvoke::AmDynInvoke() {}
 AmDynInvoke::~AmDynInvoke() {}
@@ -78,6 +79,23 @@ void AmSessionFactory::configureSession(AmSession* sess) {
 
 void AmSessionFactory::onOoDRequest(const AmSipRequest& req)
 {
+  string hdrs;
+  if (!AmConfig::OptionsTranscoderInStatsHdr.empty()) {
+    string usage;
+    B2BMediaStatistics::instance()->reportCodecReadUsage(usage);
+
+    hdrs += AmConfig::OptionsTranscoderInStatsHdr + ": ";
+    hdrs += usage;
+    hdrs += CRLF;
+  }
+  if (!AmConfig::OptionsTranscoderOutStatsHdr.empty()) {
+    string usage;
+    B2BMediaStatistics::instance()->reportCodecWriteUsage(usage);
+
+    hdrs += AmConfig::OptionsTranscoderOutStatsHdr + ": ";
+    hdrs += usage;
+    hdrs += CRLF;
+  }
 
   if (req.method == "OPTIONS") {
     // Basic OPTIONS support
@@ -85,20 +103,22 @@ void AmSessionFactory::onOoDRequest(const AmSipRequest& 
req)
        (AmSession::getSessionNum() >= AmConfig::OptionsSessionLimit)) {
       // return error code if near to overload
       AmSipDialog::reply_error(req,
-                              AmConfig::OptionsSessionLimitErrCode, 
-                              AmConfig::OptionsSessionLimitErrReason);
+          AmConfig::OptionsSessionLimitErrCode, 
+          AmConfig::OptionsSessionLimitErrReason,
+          hdrs);
       return;
     }
 
     if (AmConfig::ShutdownMode) {
       // return error code if in shutdown mode
       AmSipDialog::reply_error(req,
-                              AmConfig::ShutdownModeErrCode,
-                              AmConfig::ShutdownModeErrReason);
+          AmConfig::ShutdownModeErrCode,
+          AmConfig::ShutdownModeErrReason,
+          hdrs);
       return;
     }
 
-    AmSipDialog::reply_error(req, 200, "OK");
+    AmSipDialog::reply_error(req, 200, "OK", hdrs);
     return;
   }
 
diff --git a/core/AmB2BMedia.cpp b/core/AmB2BMedia.cpp
index 6a3774b..dc9bdc0 100644
--- a/core/AmB2BMedia.cpp
+++ b/core/AmB2BMedia.cpp
@@ -65,6 +65,11 @@ B2BMediaStatistics *B2BMediaStatistics::instance()
     
 void B2BMediaStatistics::reportCodecWriteUsage(string &dst)
 {
+  if (codec_write_usage.empty()) {
+    dst = "pcma=0"; // to be not empty
+    return;
+  }
+
   bool first = true;
   dst.clear();
   for (map<string, int>::iterator i = codec_write_usage.begin();
@@ -77,6 +82,26 @@ void B2BMediaStatistics::reportCodecWriteUsage(string &dst)
     dst += int2str(i->second);
   }
 }
+
+void B2BMediaStatistics::reportCodecReadUsage(string &dst)
+{
+  if (codec_read_usage.empty()) {
+    dst = "pcma=0"; // to be not empty
+    return;
+  }
+
+  bool first = true;
+  dst.clear();
+  for (map<string, int>::iterator i = codec_read_usage.begin();
+      i != codec_read_usage.end(); ++i) 
+  {
+    if (first) first = false;
+    else dst += ",";
+    dst += i->first;
+    dst += "=";
+    dst += int2str(i->second);
+  }
+}
     
 void B2BMediaStatistics::getReport(const AmArg &args, AmArg &ret)
 {
diff --git a/core/AmB2BMedia.h b/core/AmB2BMedia.h
index 6306b6e..8c2a726 100644
--- a/core/AmB2BMedia.h
+++ b/core/AmB2BMedia.h
@@ -20,6 +20,7 @@ class B2BMediaStatistics
 
   public:
     void reportCodecWriteUsage(string &dst);
+    void reportCodecReadUsage(string &dst);
     void getReport(const AmArg &args, AmArg &ret);
 
     static B2BMediaStatistics *instance();
diff --git a/core/AmConfig.cpp b/core/AmConfig.cpp
index 48673b3..7d0cdcb 100644
--- a/core/AmConfig.cpp
+++ b/core/AmConfig.cpp
@@ -107,6 +107,9 @@ bool         AmConfig::AcceptForkedDialogs     = true;
 bool         AmConfig::ShutdownMode            = false;
 unsigned int AmConfig::ShutdownModeErrCode     = 503;
 string       AmConfig::ShutdownModeErrReason   = "Server shutting down";
+  
+string AmConfig::OptionsTranscoderOutStatsHdr; // empty by default
+string AmConfig::OptionsTranscoderInStatsHdr; // empty by default
 
 Am100rel::State AmConfig::rel100 = Am100rel::REL100_SUPPORTED;
 
@@ -569,6 +572,9 @@ int AmConfig::readConfiguration()
     }
   }
 
+  OptionsTranscoderOutStatsHdr = 
cfg.getParameter("options_transcoder_out_stats_hdr");
+  OptionsTranscoderInStatsHdr = 
cfg.getParameter("options_transcoder_in_stats_hdr");
+
   if (cfg.hasParameter("100rel")) {
     string rel100s = cfg.getParameter("100rel");
     if (rel100s == "disabled" || rel100s == "off") {
diff --git a/core/AmConfig.h b/core/AmConfig.h
index aaa10c2..6b8fbfe 100644
--- a/core/AmConfig.h
+++ b/core/AmConfig.h
@@ -187,6 +187,9 @@ struct AmConfig
   static unsigned int ShutdownModeErrCode;
   static string ShutdownModeErrReason;
 
+  static string OptionsTranscoderOutStatsHdr;
+  static string OptionsTranscoderInStatsHdr;
+
   static Am100rel::State rel100;
 
   /** Time of no RTP after which Session is regarded as dead, 0 for no Timeout 
*/
diff --git a/doc/Readme.sbc.txt b/doc/Readme.sbc.txt
index 36a3381..dd8ac0b 100644
--- a/doc/Readme.sbc.txt
+++ b/doc/Readme.sbc.txt
@@ -455,6 +455,25 @@ Transcoding related call profile options:
     If this parameter is set to something else, transcoder codecs are added 
BEFORE
     ordering using codec_preference_aleg is done and thus may become preferred 
ones.
 
+Transcoder statistics can be checked via "printCallStats" SBC DI method or can
+be put into additional headers within reply generated to OPTIONS request. To
+achive that set global options: options_transcoder_out_stats_hdr and
+options_transcoder_in_stats_hdr. 
+
+  With this settings:
+
+    options_transcoder_out_stats_hdr=P-Transcoder-Stats-Out
+    options_transcoder_in_stats_hdr=P-Transcoder-Stats-In
+
+  the OPTIONS reply will contain these headers with statistics:
+
+    P-Transcoder-Stats-In: pcma=1,pcmu=0,speex=1
+    P-Transcoder-Stats-Out: pcma=1,pcmu=0,speex=1
+
+The statistics are separated for codecs used for reading (data are read using
+that codecs) and for codecs used for writing (data are sent using that codecs).
+Note that relaying can be active in one direction and transcoding in the other
+so the in/out (read/write) numbers need not to match.
 
 Warning: 
  - currently only audio streams are relayed through or transcoded
@@ -466,7 +485,10 @@ Warning:
  - handling of "on hold" streams when transcoding is in use can cause RTP media
    send in hold state (sendonly stream) though they need not to be sent (caused
    by buffering strategy)
-
+ - the statistics are just approximation of real situation because multiple
+   codecs can be used in one stream at the same time but only one (the last 
used
+   one) is reported
+   
 Adding headers
 --------------
 Additional headers can be added to the outgoing initial INVITE by using the
@@ -697,7 +719,7 @@ x session timers
 x maximum call duration timer
 - accounting (MySQL DB, cassandra DB)
 x RTP forwarding mode (bridging)
-- RTP transcoding mode (bridging)
+x RTP transcoding mode (bridging)
 - overload handling (parallel call to target thresholds)
 - call distribution
 - select profile on monitoring in-mem DB record

_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev

Reply via email to