Bug 947665 - SSRC stat. r=abr
authorJan-Ivar Bruaroey <jib@mozilla.com>
Wed, 15 Jan 2014 09:12:50 -0500
changeset 163695 6fa6159af7e50e0a34193af476fb820f97d934e7
parent 163694 1e90119dec6fb10da60b86b5ced113598107da05
child 163696 abe44fd348b69b1eadab2fff70053c147a43ad8b
push id38544
push userryanvm@gmail.com
push dateThu, 16 Jan 2014 13:27:44 +0000
treeherdermozilla-inbound@8d3e02a7f23c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersabr
bugs947665
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 947665 - SSRC stat. r=abr
media/webrtc/signaling/src/media-conduit/AudioConduit.cpp
media/webrtc/signaling/src/media-conduit/AudioConduit.h
media/webrtc/signaling/src/media-conduit/MediaConduitInterface.h
media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
media/webrtc/signaling/src/media-conduit/VideoConduit.h
media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
--- a/media/webrtc/signaling/src/media-conduit/AudioConduit.cpp
+++ b/media/webrtc/signaling/src/media-conduit/AudioConduit.cpp
@@ -111,32 +111,45 @@ WebrtcAudioConduit::~WebrtcAudioConduit(
       mPtrVoEBase->StopSend(mChannel);
       mPtrVoEBase->StopReceive(mChannel);
       mPtrVoEBase->DeleteChannel(mChannel);
       mPtrVoEBase->Terminate();
     }
     mPtrVoEBase->Release();
   }
 
+  if (mPtrRTP)
+  {
+    mPtrRTP->Release();
+  }
+
   if (mOtherDirection)
   {
     // mOtherDirection owns these now!
     mOtherDirection->mOtherDirection = nullptr;
     // let other side we terminated the channel
     mOtherDirection->mShutDown = true;
     mVoiceEngine = nullptr;
   } else {
     // only one opener can call Delete.  Have it be the last to close.
     if(mVoiceEngine)
     {
       webrtc::VoiceEngine::Delete(mVoiceEngine);
     }
   }
 }
 
+bool WebrtcAudioConduit::GetLocalSSRC(unsigned int* ssrc) {
+  return !mPtrRTP->GetLocalSSRC(mChannel, *ssrc);
+}
+
+bool WebrtcAudioConduit::GetRemoteSSRC(unsigned int* ssrc) {
+  return !mPtrRTP->GetRemoteSSRC(mChannel, *ssrc);
+}
+
 /*
  * WebRTCAudioConduit Implementation
  */
 MediaConduitErrorCode WebrtcAudioConduit::Init(WebrtcAudioConduit *other)
 {
   CSFLogDebug(logTag,  "%s this=%p other=%p", __FUNCTION__, this, other);
 
   if (other) {
@@ -215,16 +228,23 @@ MediaConduitErrorCode WebrtcAudioConduit
   }
 
   if(!(mPtrVoEVideoSync = VoEVideoSync::GetInterface(mVoiceEngine)))
   {
     CSFLogError(logTag, "%s Unable to initialize VoEVideoSync", __FUNCTION__);
     return kMediaConduitSessionNotInited;
   }
 
+  if (!(mPtrRTP = webrtc::VoERTP_RTCP::GetInterface(mVoiceEngine)))
+  {
+    CSFLogError(logTag, "%s Unable to get audio RTP/RTCP interface ",
+                __FUNCTION__);
+    return kMediaConduitSessionNotInited;
+  }
+
   if (other) {
     mChannel = other->mChannel;
   } else {
     // init the engine with our audio device layer
     if(mPtrVoEBase->Init() == -1)
     {
       CSFLogError(logTag, "%s VoiceEngine Base Not Initialized", __FUNCTION__);
       return kMediaConduitSessionNotInited;
--- a/media/webrtc/signaling/src/media-conduit/AudioConduit.h
+++ b/media/webrtc/signaling/src/media-conduit/AudioConduit.h
@@ -17,16 +17,17 @@
 #include "webrtc/voice_engine/include/voe_base.h"
 #include "webrtc/voice_engine/include/voe_volume_control.h"
 #include "webrtc/voice_engine/include/voe_codec.h"
 #include "webrtc/voice_engine/include/voe_file.h"
 #include "webrtc/voice_engine/include/voe_network.h"
 #include "webrtc/voice_engine/include/voe_external_media.h"
 #include "webrtc/voice_engine/include/voe_audio_processing.h"
 #include "webrtc/voice_engine/include/voe_video_sync.h"
+#include "webrtc/voice_engine/include/voe_rtp_rtcp.h"
 
 //Some WebRTC types for short notations
  using webrtc::VoEBase;
  using webrtc::VoENetwork;
  using webrtc::VoECodec;
  using webrtc::VoEExternalMedia;
  using webrtc::VoEAudioProcessing;
  using webrtc::VoEVideoSync;
@@ -144,16 +145,17 @@ public:
 
 
 
   WebrtcAudioConduit():
                       mOtherDirection(nullptr),
                       mShutDown(false),
                       mVoiceEngine(nullptr),
                       mTransport(nullptr),
+                      mPtrRTP(nullptr),
                       mEngineTransmitting(false),
                       mEngineReceiving(false),
                       mChannel(-1),
                       mCurSendCodecConfig(nullptr),
                       mCaptureDelay(150),
                       mEchoOn(true),
                       mEchoCancel(webrtc::kEcAec)
 #ifdef MOZILLA_INTERNAL_API
@@ -163,16 +165,18 @@ public:
   }
 
   virtual ~WebrtcAudioConduit();
 
   MediaConduitErrorCode Init(WebrtcAudioConduit *other);
 
   int GetChannel() { return mChannel; }
   webrtc::VoiceEngine* GetVoiceEngine() { return mVoiceEngine; }
+  bool GetLocalSSRC(unsigned int* ssrc);
+  bool GetRemoteSSRC(unsigned int* ssrc);
 
 private:
   WebrtcAudioConduit(const WebrtcAudioConduit& other) MOZ_DELETE;
   void operator=(const WebrtcAudioConduit& other) MOZ_DELETE;
 
   //Local database of currently applied receive codecs
   typedef std::vector<AudioCodecConfig* > RecvCodecList;
 
@@ -212,16 +216,17 @@ private:
   webrtc::VoiceEngine* mVoiceEngine;
   mozilla::RefPtr<TransportInterface> mTransport;
   webrtc::VoENetwork*  mPtrVoENetwork;
   webrtc::VoEBase*     mPtrVoEBase;
   webrtc::VoECodec*    mPtrVoECodec;
   webrtc::VoEExternalMedia* mPtrVoEXmedia;
   webrtc::VoEAudioProcessing* mPtrVoEProcessing;
   webrtc::VoEVideoSync* mPtrVoEVideoSync;
+  webrtc::VoERTP_RTCP* mPtrRTP;
 
   //engine states of our interets
   bool mEngineTransmitting; // If true => VoiceEngine Send-subsystem is up
   bool mEngineReceiving;    // If true => VoiceEngine Receive-subsystem is up
                             // and playout is enabled
 
   // Keep track of each inserted RTP block and the time it was inserted
   // so we can estimate the clock time for a specific TimeStamp coming out
--- a/media/webrtc/signaling/src/media-conduit/MediaConduitInterface.h
+++ b/media/webrtc/signaling/src/media-conduit/MediaConduitInterface.h
@@ -131,16 +131,19 @@ public:
   /**
    * Function to attach Transport end-point of the Media conduit.
    * @param aTransport: Reference to the concrete teansport implementation
    * Note: Multiple invocations of this call , replaces existing transport with
    * with the new one.
    */
   virtual MediaConduitErrorCode AttachTransport(RefPtr<TransportInterface> aTransport) = 0;
 
+  virtual bool GetLocalSSRC(unsigned int* ssrc) = 0;
+  virtual bool GetRemoteSSRC(unsigned int* ssrc) = 0;
+
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaSessionConduit)
 
 };
 
 
 /**
  * MediaSessionConduit for video
  * Refer to the comments on MediaSessionConduit above for overall
--- a/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
+++ b/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
@@ -132,16 +132,24 @@ WebrtcVideoConduit::~WebrtcVideoConduit(
     // only one opener can call Delete.  Have it be the last to close.
     if(mVideoEngine)
     {
       webrtc::VideoEngine::Delete(mVideoEngine);
     }
   }
 }
 
+bool WebrtcVideoConduit::GetLocalSSRC(unsigned int* ssrc) {
+  return !mPtrRTP->GetLocalSSRC(mChannel, *ssrc);
+}
+
+bool WebrtcVideoConduit::GetRemoteSSRC(unsigned int* ssrc) {
+  return !mPtrRTP->GetRemoteSSRC(mChannel, *ssrc);
+}
+
 /**
  * Peforms intialization of the MANDATORY components of the Video Engine
  */
 MediaConduitErrorCode WebrtcVideoConduit::Init(WebrtcVideoConduit *other)
 {
   CSFLogDebug(logTag,  "%s this=%p other=%p", __FUNCTION__, this, other);
 
   if (other) {
--- a/media/webrtc/signaling/src/media-conduit/VideoConduit.h
+++ b/media/webrtc/signaling/src/media-conduit/VideoConduit.h
@@ -203,16 +203,18 @@ public:
   }
 
   virtual ~WebrtcVideoConduit() ;
 
   MediaConduitErrorCode Init(WebrtcVideoConduit *other);
 
   int GetChannel() { return mChannel; }
   webrtc::VideoEngine* GetVideoEngine() { return mVideoEngine; }
+  bool GetLocalSSRC(unsigned int* ssrc);
+  bool GetRemoteSSRC(unsigned int* ssrc);
 
 private:
 
   WebrtcVideoConduit(const WebrtcVideoConduit& other) MOZ_DELETE;
   void operator=(const WebrtcVideoConduit& other) MOZ_DELETE;
 
   //Local database of currently applied receive codecs
   typedef std::vector<VideoCodecConfig* > RecvCodecList;
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
@@ -30,16 +30,18 @@
 #include "nsISimpleEnumerator.h"
 #include "nsServiceManagerUtils.h"
 #include "nsISocketTransportService.h"
 #include "nsIConsoleService.h"
 #include "nsThreadUtils.h"
 #include "nsProxyRelease.h"
 #include "prtime.h"
 
+#include "AudioConduit.h"
+#include "VideoConduit.h"
 #include "runnable_utils.h"
 #include "PeerConnectionCtx.h"
 #include "PeerConnectionImpl.h"
 #include "PeerConnectionMedia.h"
 #include "nsDOMDataChannelDeclarations.h"
 #include "dtlsidentity.h"
 
 #ifdef MOZILLA_INTERNAL_API
@@ -1950,17 +1952,16 @@ PeerConnectionImpl::IceGatheringStateCha
                              &PeerConnectionObserver::OnStateChange,
                              PCObserverStateType::IceGatheringState,
                              rv, static_cast<JSCompartment*>(nullptr)),
                 NS_DISPATCH_NORMAL);
   return NS_OK;
 }
 
 #ifdef MOZILLA_INTERNAL_API
-
 nsresult
 PeerConnectionImpl::GetStatsImpl_s(
     bool internalStats,
     const std::vector<RefPtr<MediaPipeline>>& pipelines,
     const RefPtr<NrIceCtx>& iceCtx,
     const std::vector<RefPtr<NrIceMediaStream>>& streams,
     DOMHighResTimeStamp now,
     RTCStatsReportInternal* report) {
@@ -1976,30 +1977,38 @@ PeerConnectionImpl::GetStatsImpl_s(
     idstr.AppendInt(mp.trackid());
 
     switch (mp.direction()) {
       case MediaPipeline::TRANSMIT: {
         RTCOutboundRTPStreamStats s;
         s.mTimestamp.Construct(now);
         s.mId.Construct(NS_LITERAL_STRING("outbound_rtp_") + idstr);
         s.mType.Construct(RTCStatsType::Outboundrtp);
-        // TODO: Get SSRC
-        // int channel = mp.Conduit()->GetChannel();
-        s.mSsrc.Construct(NS_LITERAL_STRING("123457"));
+        unsigned int ssrc;
+        if (mp.Conduit()->GetLocalSSRC(&ssrc)) {
+          nsString str;
+          str.AppendInt(ssrc);
+          s.mSsrc.Construct(str);
+        }
         s.mPacketsSent.Construct(mp.rtp_packets_sent());
         s.mBytesSent.Construct(mp.rtp_bytes_sent());
         report->mOutboundRTPStreamStats.Value().AppendElement(s);
         break;
       }
       case MediaPipeline::RECEIVE: {
         RTCInboundRTPStreamStats s;
         s.mTimestamp.Construct(now);
         s.mId.Construct(NS_LITERAL_STRING("inbound_rtp_") + idstr);
         s.mType.Construct(RTCStatsType::Inboundrtp);
-        s.mSsrc.Construct(NS_LITERAL_STRING("123457"));
+        unsigned int ssrc;
+        if (mp.Conduit()->GetRemoteSSRC(&ssrc)) {
+          nsString str;
+          str.AppendInt(ssrc);
+          s.mSsrc.Construct(str);
+        }
         s.mPacketsReceived.Construct(mp.rtp_packets_received());
         s.mBytesReceived.Construct(mp.rtp_bytes_received());
         report->mInboundRTPStreamStats.Value().AppendElement(s);
         break;
       }
     }
   }