Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / libjingle / source / talk / app / webrtc / objc / RTCPeerConnection.mm
index a7e31a1..39e6a00 100644 (file)
 
 #import "RTCPeerConnection+Internal.h"
 
+#import "RTCDataChannel+Internal.h"
 #import "RTCEnumConverter.h"
 #import "RTCICECandidate+Internal.h"
 #import "RTCICEServer+Internal.h"
 #import "RTCMediaConstraints+Internal.h"
 #import "RTCMediaStream+Internal.h"
+#import "RTCMediaStreamTrack+Internal.h"
 #import "RTCSessionDescription+Internal.h"
-#import "RTCSessionDescriptonDelegate.h"
+#import "RTCSessionDescriptionDelegate.h"
 #import "RTCSessionDescription.h"
+#import "RTCStatsDelegate.h"
+#import "RTCStatsReport+Internal.h"
 
 #include "talk/app/webrtc/jsep.h"
 
@@ -50,8 +54,9 @@ namespace webrtc {
 class RTCCreateSessionDescriptionObserver
     : public CreateSessionDescriptionObserver {
  public:
-  RTCCreateSessionDescriptionObserver(id<RTCSessionDescriptonDelegate> delegate,
-                                      RTCPeerConnection* peerConnection) {
+  RTCCreateSessionDescriptionObserver(
+      id<RTCSessionDescriptionDelegate> delegate,
+      RTCPeerConnection* peerConnection) {
     _delegate = delegate;
     _peerConnection = peerConnection;
   }
@@ -76,13 +81,13 @@ class RTCCreateSessionDescriptionObserver
   }
 
  private:
-  id<RTCSessionDescriptonDelegate> _delegate;
+  id<RTCSessionDescriptionDelegate> _delegate;
   RTCPeerConnection* _peerConnection;
 };
 
 class RTCSetSessionDescriptionObserver : public SetSessionDescriptionObserver {
  public:
-  RTCSetSessionDescriptionObserver(id<RTCSessionDescriptonDelegate> delegate,
+  RTCSetSessionDescriptionObserver(id<RTCSessionDescriptionDelegate> delegate,
                                    RTCPeerConnection* peerConnection) {
     _delegate = delegate;
     _peerConnection = peerConnection;
@@ -104,7 +109,31 @@ class RTCSetSessionDescriptionObserver : public SetSessionDescriptionObserver {
   }
 
  private:
-  id<RTCSessionDescriptonDelegate> _delegate;
+  id<RTCSessionDescriptionDelegate> _delegate;
+  RTCPeerConnection* _peerConnection;
+};
+
+class RTCStatsObserver : public StatsObserver {
+ public:
+  RTCStatsObserver(id<RTCStatsDelegate> delegate,
+                   RTCPeerConnection* peerConnection) {
+    _delegate = delegate;
+    _peerConnection = peerConnection;
+  }
+
+  virtual void OnComplete(const std::vector<StatsReport>& reports) OVERRIDE {
+    NSMutableArray* stats = [NSMutableArray arrayWithCapacity:reports.size()];
+    std::vector<StatsReport>::const_iterator it = reports.begin();
+    for (; it != reports.end(); ++it) {
+      RTCStatsReport* statsReport =
+          [[RTCStatsReport alloc] initWithStatsReport:*it];
+      [stats addObject:statsReport];
+    }
+    [_delegate peerConnection:_peerConnection didGetStats:stats];
+  }
+
+ private:
+  id<RTCStatsDelegate> _delegate;
   RTCPeerConnection* _peerConnection;
 };
 }
@@ -132,7 +161,16 @@ class RTCSetSessionDescriptionObserver : public SetSessionDescriptionObserver {
   return YES;
 }
 
-- (void)createAnswerWithDelegate:(id<RTCSessionDescriptonDelegate>)delegate
+- (RTCDataChannel*)createDataChannelWithLabel:(NSString*)label
+                                       config:(RTCDataChannelInit*)config {
+  std::string labelString([label UTF8String]);
+  talk_base::scoped_refptr<webrtc::DataChannelInterface> dataChannel =
+      self.peerConnection->CreateDataChannel(labelString,
+                                             config.dataChannelInit);
+  return [[RTCDataChannel alloc] initWithDataChannel:dataChannel];
+}
+
+- (void)createAnswerWithDelegate:(id<RTCSessionDescriptionDelegate>)delegate
                      constraints:(RTCMediaConstraints*)constraints {
   talk_base::scoped_refptr<webrtc::RTCCreateSessionDescriptionObserver>
       observer(new talk_base::RefCountedObject<
@@ -140,7 +178,7 @@ class RTCSetSessionDescriptionObserver : public SetSessionDescriptionObserver {
   self.peerConnection->CreateAnswer(observer, constraints.constraints);
 }
 
-- (void)createOfferWithDelegate:(id<RTCSessionDescriptonDelegate>)delegate
+- (void)createOfferWithDelegate:(id<RTCSessionDescriptionDelegate>)delegate
                     constraints:(RTCMediaConstraints*)constraints {
   talk_base::scoped_refptr<webrtc::RTCCreateSessionDescriptionObserver>
       observer(new talk_base::RefCountedObject<
@@ -154,7 +192,7 @@ class RTCSetSessionDescriptionObserver : public SetSessionDescriptionObserver {
 }
 
 - (void)setLocalDescriptionWithDelegate:
-            (id<RTCSessionDescriptonDelegate>)delegate
+            (id<RTCSessionDescriptionDelegate>)delegate
                      sessionDescription:(RTCSessionDescription*)sdp {
   talk_base::scoped_refptr<webrtc::RTCSetSessionDescriptionObserver> observer(
       new talk_base::RefCountedObject<webrtc::RTCSetSessionDescriptionObserver>(
@@ -163,7 +201,7 @@ class RTCSetSessionDescriptionObserver : public SetSessionDescriptionObserver {
 }
 
 - (void)setRemoteDescriptionWithDelegate:
-            (id<RTCSessionDescriptonDelegate>)delegate
+            (id<RTCSessionDescriptionDelegate>)delegate
                       sessionDescription:(RTCSessionDescription*)sdp {
   talk_base::scoped_refptr<webrtc::RTCSetSessionDescriptionObserver> observer(
       new talk_base::RefCountedObject<webrtc::RTCSetSessionDescriptionObserver>(
@@ -219,6 +257,18 @@ class RTCSetSessionDescriptionObserver : public SetSessionDescriptionObserver {
   self.peerConnection->Close();
 }
 
+- (BOOL)getStatsWithDelegate:(id<RTCStatsDelegate>)delegate
+            mediaStreamTrack:(RTCMediaStreamTrack*)mediaStreamTrack
+            statsOutputLevel:(RTCStatsOutputLevel)statsOutputLevel {
+  talk_base::scoped_refptr<webrtc::RTCStatsObserver> observer(
+      new talk_base::RefCountedObject<webrtc::RTCStatsObserver>(delegate,
+                                                                self));
+  webrtc::PeerConnectionInterface::StatsOutputLevel nativeOutputLevel =
+      [RTCEnumConverter convertStatsOutputLevelToNative:statsOutputLevel];
+  return self.peerConnection->GetStats(
+      observer, mediaStreamTrack.mediaTrack, nativeOutputLevel);
+}
+
 @end
 
 @implementation RTCPeerConnection (Internal)