]> sjero.net Git - linphone/commitdiff
Add upnp call stats
authorYann Diorcet <yann.diorcet@belledonne-communications.com>
Thu, 24 Jan 2013 14:59:42 +0000 (15:59 +0100)
committerYann Diorcet <yann.diorcet@belledonne-communications.com>
Thu, 24 Jan 2013 14:59:42 +0000 (15:59 +0100)
coreapi/linphonecall.c
coreapi/linphonecore.h
coreapi/upnp.c
coreapi/upnp.h
gtk/call_statistics.ui
gtk/incall_view.c

index f4525399be2895d6f28c6e22b864790c151ffb17..eece911b49f5788314640d6bdbe64e5885fd074c 100644 (file)
@@ -286,6 +286,7 @@ void linphone_call_make_local_media_description(LinphoneCore *lc, LinphoneCall *
 #ifdef BUILD_UPNP
        if(call->upnp_session != NULL) {
                linphone_core_update_local_media_description_from_upnp(md, call->upnp_session);
+               linphone_core_update_upnp_state_in_call_stats(call);
        }
 #endif  //BUILD_UPNP
        linphone_address_destroy(addr);
@@ -421,6 +422,11 @@ void linphone_call_init_stats(LinphoneCallStats *stats, int type) {
        stats->received_rtcp = NULL;
        stats->sent_rtcp = NULL;
        stats->ice_state = LinphoneIceStateNotActivated;
+#ifdef BUILD_UPNP
+       stats->upnp_state = LinphoneUpnpStateIdle;
+#else
+       stats->upnp_state = LinphoneUpnpStateNotAvailable;
+#endif //BUILD_UPNP
 }
 
 
index 1003e9546acc4fc934cd0cbaf35decfdaccf55b6..6af0bad346bb1517b04955d1a00bf6fe7fb8f204 100644 (file)
@@ -284,6 +284,27 @@ enum _LinphoneIceState{
 **/
 typedef enum _LinphoneIceState LinphoneIceState;
 
+/**
+ * Enum describing uPnP states.
+ * @ingroup initializing
+**/
+enum _LinphoneUpnpState{
+       LinphoneUpnpStateIdle, /**< uPnP is not activate */
+       LinphoneUpnpStatePending, /**< uPnP process is in progress */
+       LinphoneUpnpStateAdding,   /**< Internal use: Only used by port binding */
+       LinphoneUpnpStateRemoving, /**< Internal use: Only used by port binding */
+       LinphoneUpnpStateNotAvailable,  /**< uPnP is not available */
+       LinphoneUpnpStateOk, /**< uPnP is enabled */
+       LinphoneUpnpStateKo, /**< uPnP processing has failed */
+};
+
+/**
+ * Enum describing uPnP states.
+ * @ingroup initializing
+**/
+typedef enum _LinphoneUpnpState LinphoneUpnpState;
+
+
 /**
  * The LinphoneCallStats objects carries various statistic informations regarding quality of audio or video streams.
  *
@@ -309,6 +330,7 @@ struct _LinphoneCallStats {
        mblk_t*         sent_rtcp;/**<Last RTCP packet sent, as a mblk_t structure. See oRTP documentation for details how to extract information from it*/
        float           round_trip_delay; /**<Round trip propagation time in seconds if known, -1 if unknown.*/
        LinphoneIceState        ice_state; /**< State of ICE processing. */
+       LinphoneUpnpState       upnp_state; /**< State of uPnP processing. */
        float download_bandwidth; /**<Download bandwidth measurement of received stream, expressed in kbit/s, including IP/UDP/RTP headers*/
        float upload_bandwidth; /**<Download bandwidth measurement of sent stream, expressed in kbit/s, including IP/UDP/RTP headers*/
 };
index a3581c2edd40cfda1cdd2d29675e24048abcc3ae..5684fc270385937d72e159b194e2c98d876e002c 100644 (file)
@@ -576,11 +576,16 @@ int linphone_core_update_upnp(LinphoneCore *lc, LinphoneCall *call) {
        return linphone_core_update_upnp_audio_video(call, call->audiostream!=NULL, call->videostream!=NULL);
 }
 
+void linphone_core_update_upnp_state_in_call_stats(LinphoneCall *call) {
+       call->stats[LINPHONE_CALL_STATS_AUDIO].upnp_state = call->upnp_session->audio->state;
+       call->stats[LINPHONE_CALL_STATS_VIDEO].upnp_state = call->upnp_session->video->state;
+}
+
 int linphone_upnp_call_process(LinphoneCall *call) {
        LinphoneCore *lc = call->core;
        UpnpContext *lupnp = lc->upnp;
        int ret = -1;
-       LinphoneUpnpState oldState;
+       LinphoneUpnpState oldState, newState;
 
        if(lupnp == NULL) {
                return ret;
@@ -644,6 +649,7 @@ int linphone_upnp_call_process(LinphoneCall *call) {
                } else {
                        call->upnp_session->state = LinphoneUpnpStateIdle;
                }
+               newState = call->upnp_session->state;
 
                /* When change is done proceed update */
                if(oldState != LinphoneUpnpStateOk && oldState != LinphoneUpnpStateKo &&
@@ -673,6 +679,14 @@ int linphone_upnp_call_process(LinphoneCall *call) {
        }
 
        ms_mutex_unlock(&lupnp->mutex);
+
+       /*
+        * Update uPnP call stats
+        */
+       if(oldState != newState) {
+               linphone_core_update_upnp_state_in_call_stats(call);
+       }
+
        return ret;
 }
 
index a98e15574f45b78d2d9cfd3c735b540fd43179ec..b3a5b9e49a0ecf6288f11a4d773a4f449574e2be 100644 (file)
@@ -24,16 +24,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "linphonecore.h"
 #include "sal.h"
 
-typedef enum {
-       LinphoneUpnpStateIdle,
-       LinphoneUpnpStatePending, // Only used by uPnP context
-       LinphoneUpnpStateAdding,   // Only used by port binding
-       LinphoneUpnpStateRemoving, // Only used by port binding
-       LinphoneUpnpStateNotAvailable,  // Only used by uPnP context
-       LinphoneUpnpStateOk,
-       LinphoneUpnpStateKo,
-} LinphoneUpnpState;
-
 typedef struct _UpnpSession UpnpSession;
 typedef struct _UpnpContext UpnpContext;
 
@@ -50,5 +40,6 @@ UpnpContext *linphone_upnp_context_new(LinphoneCore *lc);
 void linphone_upnp_context_destroy(UpnpContext *ctx);
 LinphoneUpnpState linphone_upnp_context_get_state(UpnpContext *ctx);
 const char *linphone_upnp_context_get_external_ipaddress(UpnpContext *ctx);
+void linphone_core_update_upnp_state_in_call_stats(LinphoneCall *call);
 
 #endif //LINPHONE_UPNP_H
index 444710472c747a7390a4b7c82a4ea745e899dabf..6ed8bd9bd1cd175ccec1c6985fae2b017f91be5d 100644 (file)
@@ -1,71 +1,34 @@
-<?xml version="1.0" encoding="UTF-8"?>
+<?xml version="1.0"?>
 <interface>
   <requires lib="gtk+" version="2.24"/>
   <!-- interface-naming-policy project-wide -->
   <object class="GtkDialog" id="call_statistics">
-    <property name="can_focus">False</property>
     <property name="border_width">5</property>
     <property name="title" translatable="yes">Call statistics</property>
     <property name="type_hint">dialog</property>
-    <signal name="response" handler="linphone_gtk_call_statistics_closed" swapped="no"/>
+    <signal name="response" handler="linphone_gtk_call_statistics_closed"/>
     <child internal-child="vbox">
       <object class="GtkVBox" id="dialog-vbox1">
         <property name="visible">True</property>
-        <property name="can_focus">False</property>
         <property name="spacing">2</property>
-        <child internal-child="action_area">
-          <object class="GtkHButtonBox" id="dialog-action_area1">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="layout_style">end</property>
-            <child>
-              <placeholder/>
-            </child>
-            <child>
-              <object class="GtkButton" id="button1">
-                <property name="label">gtk-close</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_action_appearance">False</property>
-                <property name="use_stock">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="pack_type">end</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
         <child>
           <object class="GtkFrame" id="frame1">
             <property name="visible">True</property>
-            <property name="can_focus">False</property>
             <property name="label_xalign">0</property>
             <property name="shadow_type">none</property>
             <child>
               <object class="GtkAlignment" id="alignment1">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
                 <property name="left_padding">12</property>
                 <child>
                   <object class="GtkTable" id="table1">
                     <property name="visible">True</property>
-                    <property name="can_focus">False</property>
                     <property name="n_rows">6</property>
                     <property name="n_columns">2</property>
                     <property name="homogeneous">True</property>
                     <child>
                       <object class="GtkLabel" id="audio_codec_label">
                         <property name="visible">True</property>
-                        <property name="can_focus">False</property>
                         <property name="label" translatable="yes">Audio codec</property>
                       </object>
                       <packing>
@@ -75,7 +38,6 @@
                     <child>
                       <object class="GtkLabel" id="video_codec_label">
                         <property name="visible">True</property>
-                        <property name="can_focus">False</property>
                         <property name="label" translatable="yes">Video codec</property>
                       </object>
                       <packing>
@@ -87,7 +49,6 @@
                     <child>
                       <object class="GtkLabel" id="label3">
                         <property name="visible">True</property>
-                        <property name="can_focus">False</property>
                         <property name="label" translatable="yes">Audio IP bandwidth usage</property>
                       </object>
                       <packing>
@@ -99,7 +60,6 @@
                     <child>
                       <object class="GtkLabel" id="audio_codec">
                         <property name="visible">True</property>
-                        <property name="can_focus">False</property>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
                     <child>
                       <object class="GtkLabel" id="video_codec">
                         <property name="visible">True</property>
-                        <property name="can_focus">False</property>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
                     <child>
                       <object class="GtkLabel" id="audio_bandwidth_usage">
                         <property name="visible">True</property>
-                        <property name="can_focus">False</property>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
                     <child>
                       <object class="GtkLabel" id="label4">
                         <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="label" translatable="yes">Media connectivity</property>
+                        <property name="label" translatable="yes">Audio Media connectivity</property>
                       </object>
                       <packing>
                         <property name="top_attach">4</property>
                       </packing>
                     </child>
                     <child>
-                      <placeholder/>
-                    </child>
-                    <child>
-                      <placeholder/>
-                    </child>
-                    <child>
-                      <object class="GtkLabel" id="media_connectivity">
+                      <object class="GtkLabel" id="audio_media_connectivity">
                         <property name="visible">True</property>
-                        <property name="can_focus">False</property>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
                     <child>
                       <object class="GtkLabel" id="label1">
                         <property name="visible">True</property>
-                        <property name="can_focus">False</property>
                         <property name="label" translatable="yes">Video IP bandwidth usage</property>
                       </object>
                       <packing>
                     <child>
                       <object class="GtkLabel" id="video_bandwidth_usage">
                         <property name="visible">True</property>
-                        <property name="can_focus">False</property>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
                         <property name="bottom_attach">4</property>
                       </packing>
                     </child>
+                    <child>
+                      <object class="GtkLabel" id="label2">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">Video Media connectivity</property>
+                      </object>
+                      <packing>
+                        <property name="top_attach">5</property>
+                        <property name="bottom_attach">6</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="video_media_connectivity">
+                        <property name="visible">True</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
+                        <property name="top_attach">5</property>
+                        <property name="bottom_attach">6</property>
+                      </packing>
+                    </child>
                   </object>
                 </child>
               </object>
             <child type="label">
               <object class="GtkLabel" id="call_statistics_label">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
                 <property name="label" translatable="yes">&lt;b&gt;Call statistics and information&lt;/b&gt;</property>
                 <property name="use_markup">True</property>
               </object>
             <property name="position">1</property>
           </packing>
         </child>
+        <child internal-child="action_area">
+          <object class="GtkHButtonBox" id="dialog-action_area1">
+            <property name="visible">True</property>
+            <property name="layout_style">end</property>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <object class="GtkButton" id="button1">
+                <property name="label">gtk-close</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
       </object>
     </child>
     <action-widgets>
index 192e92fab3f910258357ae31fac3cb27ebc20452..8bf19c19ccdeb14677b598deadef2c9330965dfc 100644 (file)
@@ -231,10 +231,29 @@ static const char *ice_state_to_string(LinphoneIceState ice_state){
        return "invalid";
 }
 
+static const char *upnp_state_to_string(LinphoneUpnpState ice_state){
+       switch(ice_state){
+               case LinphoneUpnpStateIdle:
+                       return _("uPnP not activated");
+               case LinphoneUpnpStatePending:
+                       return _("uPnP in progress");
+               case LinphoneUpnpStateNotAvailable:
+                       return _("uPnp not available");
+               case LinphoneUpnpStateOk:
+                       return _("uPnP is running");
+               case LinphoneUpnpStateKo:
+                       return _("uPnP failed");
+               default:
+                       break;
+       }
+       return "invalid";
+}
+
 static void _refresh_call_stats(GtkWidget *callstats, LinphoneCall *call){
        const LinphoneCallStats *as=linphone_call_get_audio_stats(call);
        const LinphoneCallStats *vs=linphone_call_get_video_stats(call);
-       LinphoneIceState ice_state=as->ice_state;
+       const char *audio_media_connectivity = _("Direct");
+       const char *video_media_connectivity = _("Direct");
        gchar *tmp=g_strdup_printf(_("download: %f\nupload: %f (kbit/s)"),
                as->download_bandwidth,as->upload_bandwidth);
        gtk_label_set_markup(GTK_LABEL(linphone_gtk_get_widget(callstats,"audio_bandwidth_usage")),tmp);
@@ -243,7 +262,18 @@ static void _refresh_call_stats(GtkWidget *callstats, LinphoneCall *call){
                vs->download_bandwidth,vs->upload_bandwidth);
        gtk_label_set_markup(GTK_LABEL(linphone_gtk_get_widget(callstats,"video_bandwidth_usage")),tmp);
        g_free(tmp);
-       gtk_label_set_text(GTK_LABEL(linphone_gtk_get_widget(callstats,"media_connectivity")),ice_state_to_string(ice_state));
+       if(as->upnp_state != LinphoneUpnpStateNotAvailable && as->upnp_state != LinphoneUpnpStateIdle) {
+               audio_media_connectivity = upnp_state_to_string(as->upnp_state);
+       } else if(as->ice_state != LinphoneIceStateNotActivated) {
+               audio_media_connectivity = ice_state_to_string(as->ice_state);
+       }
+       gtk_label_set_text(GTK_LABEL(linphone_gtk_get_widget(callstats,"audio_media_connectivity")),audio_media_connectivity);
+       if(vs->upnp_state != LinphoneUpnpStateNotAvailable && vs->upnp_state != LinphoneUpnpStateIdle) {
+                       video_media_connectivity = upnp_state_to_string(vs->upnp_state);
+       } else if(vs->ice_state != LinphoneIceStateNotActivated) {
+               video_media_connectivity = ice_state_to_string(vs->ice_state);
+       }
+       gtk_label_set_text(GTK_LABEL(linphone_gtk_get_widget(callstats,"video_media_connectivity")),video_media_connectivity);
 }
 
 static gboolean refresh_call_stats(GtkWidget *callstats){