Created
November 11, 2016 06:40
-
-
Save hk0i/500190a71bf8cc14b1954495075a6548 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/webrtc/sdk/objc/Framework/Classes/RTCDTMFSender+Private.h b/webrtc/sdk/objc/Framework/Classes/RTCDTMFSender+Private.h | |
index e69de29..ff31077 100644 | |
--- a/webrtc/sdk/objc/Framework/Classes/RTCDTMFSender+Private.h | |
+++ b/webrtc/sdk/objc/Framework/Classes/RTCDTMFSender+Private.h | |
@@ -0,0 +1,42 @@ | |
+/* | |
+ * libjingle | |
+ * Copyright 2014 Google Inc. | |
+ * | |
+ * Redistribution and use in source and binary forms, with or without | |
+ * modification, are permitted provided that the following conditions are met: | |
+ * | |
+ * 1. Redistributions of source code must retain the above copyright notice, | |
+ * this list of conditions and the following disclaimer. | |
+ * 2. Redistributions in binary form must reproduce the above copyright notice, | |
+ * this list of conditions and the following disclaimer in the documentation | |
+ * and/or other materials provided with the distribution. | |
+ * 3. The name of the author may not be used to endorse or promote products | |
+ * derived from this software without specific prior written permission. | |
+ * | |
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | |
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | |
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | |
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | |
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
+ */ | |
+ | |
+#import "WebRTC/RTCDTMFSender.h" | |
+ | |
+#include "webrtc/api/dtmfsenderinterface.h" | |
+#include "webrtc/base/scoped_ref_ptr.h" | |
+ | |
+ | |
+@interface RTCDTMFSender (Private) | |
+ | |
+@property(nonatomic, readonly) | |
+ rtc::scoped_refptr<webrtc::DtmfSenderInterface> dtmfSender; | |
+ | |
+- (instancetype)initWithDtmfSender: | |
+ (rtc::scoped_refptr<webrtc::DtmfSenderInterface>)dtmfSender; | |
+ | |
+@end | |
diff --git a/webrtc/sdk/objc/Framework/Classes/RTCDTMFSender.mm b/webrtc/sdk/objc/Framework/Classes/RTCDTMFSender.mm | |
index e69de29..b351e9d 100644 | |
--- a/webrtc/sdk/objc/Framework/Classes/RTCDTMFSender.mm | |
+++ b/webrtc/sdk/objc/Framework/Classes/RTCDTMFSender.mm | |
@@ -0,0 +1,150 @@ | |
+/* | |
+ * libjingle | |
+ * Copyright 2014 Google Inc. | |
+ * | |
+ * Redistribution and use in source and binary forms, with or without | |
+ * modification, are permitted provided that the following conditions are met: | |
+ * | |
+ * 1. Redistributions of source code must retain the above copyright notice, | |
+ * this list of conditions and the following disclaimer. | |
+ * 2. Redistributions in binary form must reproduce the above copyright notice, | |
+ * this list of conditions and the following disclaimer in the documentation | |
+ * and/or other materials provided with the distribution. | |
+ * 3. The name of the author may not be used to endorse or promote products | |
+ * derived from this software without specific prior written permission. | |
+ * | |
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | |
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | |
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | |
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | |
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
+ */ | |
+ | |
+#if !defined(__has_feature) || !__has_feature(objc_arc) | |
+#error "This file requires ARC support." | |
+#endif | |
+ | |
+#include "RTCDTMFSender.h" | |
+#include "RTCAudioTrack+Internal.h" | |
+#include "RTCMediaStreamTrack+Internal.h" | |
+ | |
+#include <memory> | |
+ | |
+#include "webrtc/api/dtmfsenderinterface.h" | |
+ | |
+ | |
+// utilities | |
+static NSString* NSStringFromStdString(const std::string& stdString) { | |
+ // std::string may contain null termination character so we construct | |
+ // using length. | |
+ return [[NSString alloc] initWithBytes:stdString.data() | |
+ length:stdString.length() | |
+ encoding:NSUTF8StringEncoding]; | |
+} | |
+ | |
+static std::string StdStringFromNSString(NSString* nsString) { | |
+ NSData* charData = [nsString dataUsingEncoding:NSUTF8StringEncoding]; | |
+ return std::string(reinterpret_cast<const char*>([charData bytes]), | |
+ [charData length]); | |
+} | |
+ | |
+ | |
+namespace webrtc { | |
+ | |
+class RTCDTMFSenderObserver : public DtmfSenderObserverInterface { | |
+ public: | |
+ RTCDTMFSenderObserver(RTCDTMFSender* sender) { _sender = sender; } | |
+ | |
+ void OnToneChange(const std::string& tone) override { | |
+ if (!_sender.delegate) { | |
+ return; | |
+ } | |
+ [_sender.delegate toneChange:NSStringFromStdString(tone)]; | |
+ } | |
+ | |
+ private: | |
+ __weak RTCDTMFSender* _sender; | |
+}; | |
+} | |
+ | |
+ | |
+@implementation RTCDTMFSender { | |
+ rtc::scoped_refptr<webrtc::DtmfSenderInterface> _dtmfSender; | |
+ std::unique_ptr<webrtc::RTCDTMFSenderObserver> _observer; | |
+ BOOL _isObserverRegistered; | |
+} | |
+ | |
+- (void)dealloc { | |
+ // Handles unregistering the observer properly. | |
+ self.delegate = nil; | |
+} | |
+ | |
+- (NSString*)toneBuffer { | |
+ return NSStringFromStdString(_dtmfSender->tones()); | |
+} | |
+ | |
+- (BOOL)canInsertDTMF { | |
+ return _dtmfSender->CanInsertDtmf(); | |
+} | |
+ | |
+- (NSInteger)duration { | |
+ return _dtmfSender->duration(); | |
+} | |
+ | |
+- (NSInteger)interToneGap { | |
+ return _dtmfSender->inter_tone_gap(); | |
+} | |
+ | |
+- (RTCAudioTrack*)track { | |
+ rtc::scoped_refptr<webrtc::AudioTrackInterface> audioTrack( | |
+ const_cast<webrtc::AudioTrackInterface*>(_dtmfSender->track())); | |
+ if (audioTrack) { | |
+ return [[RTCAudioTrack alloc] initWithMediaTrack:audioTrack]; | |
+ } | |
+ return nil; | |
+} | |
+ | |
+- (void)setDelegate:(id<RTCDTMFSenderDelegate>)delegate { | |
+ if (_delegate == delegate) { | |
+ return; | |
+ } | |
+ if (_isObserverRegistered) { | |
+ _dtmfSender->UnregisterObserver(); | |
+ _isObserverRegistered = NO; | |
+ } | |
+ _delegate = delegate; | |
+ if (_delegate) { | |
+ _dtmfSender->RegisterObserver(_observer.get()); | |
+ _isObserverRegistered = YES; | |
+ } | |
+} | |
+ | |
+- (BOOL)insertDTMF:(NSString*)tones withDuration:(NSInteger)duration andInterToneGap:(NSInteger)interToneGap { | |
+ return _dtmfSender->InsertDtmf(StdStringFromNSString(tones), duration, interToneGap); | |
+} | |
+ | |
+@end | |
+ | |
+@implementation RTCDTMFSender (Internal) | |
+ | |
+- (instancetype)initWithDtmfSender: | |
+ (rtc::scoped_refptr<webrtc::DtmfSenderInterface>) | |
+ dtmfSender { | |
+ NSAssert(dtmfSender != NULL, @"dtmfSender cannot be NULL"); | |
+ if (self = [super init]) { | |
+ _dtmfSender = dtmfSender; | |
+ _observer.reset(new webrtc::RTCDTMFSenderObserver(self)); | |
+ } | |
+ return self; | |
+} | |
+ | |
+- (rtc::scoped_refptr<webrtc::DtmfSenderInterface>)dtmfSender { | |
+ return _dtmfSender; | |
+} | |
+ | |
+@end | |
diff --git a/webrtc/sdk/objc/Framework/Classes/RTCPeerConnection.mm b/webrtc/sdk/objc/Framework/Classes/RTCPeerConnection.mm | |
index b4a8738..e19cc51 100644 | |
--- a/webrtc/sdk/objc/Framework/Classes/RTCPeerConnection.mm | |
+++ b/webrtc/sdk/objc/Framework/Classes/RTCPeerConnection.mm | |
@@ -12,7 +12,9 @@ | |
#import "NSString+StdString.h" | |
#import "RTCConfiguration+Private.h" | |
+#import "RTCAudioTrack+Private.h" | |
#import "RTCDataChannel+Private.h" | |
+#import "RTCDTMFSender+Private.h" | |
#import "RTCIceCandidate+Private.h" | |
#import "RTCLegacyStatsReport+Private.h" | |
#import "RTCMediaConstraints+Private.h" | |
@@ -589,4 +591,11 @@ + (NSString *)stringForIceGatheringState:(RTCIceGatheringState)state { | |
return _peerConnection; | |
} | |
+- (RTCDTMFSender*)createDTMFSenderForTrack:(RTCAudioTrack*)track { | |
+ rtc::scoped_refptr<webrtc::DtmfSenderInterface> dtmfSender = | |
+ self.nativePeerConnection->CreateDtmfSender(track.nativeAudioTrack); | |
+ return dtmfSender ? [[RTCDTMFSender alloc] initWithDtmfSender:dtmfSender] | |
+ : nil; | |
+} | |
+ | |
@end | |
diff --git a/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCDTMFSender.h b/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCDTMFSender.h | |
index e69de29..26980b0 100644 | |
--- a/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCDTMFSender.h | |
+++ b/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCDTMFSender.h | |
@@ -0,0 +1,67 @@ | |
+/* | |
+ * libjingle | |
+ * Copyright 2014 Google Inc. | |
+ * | |
+ * Redistribution and use in source and binary forms, with or without | |
+ * modification, are permitted provided that the following conditions are met: | |
+ * | |
+ * 1. Redistributions of source code must retain the above copyright notice, | |
+ * this list of conditions and the following disclaimer. | |
+ * 2. Redistributions in binary form must reproduce the above copyright notice, | |
+ * this list of conditions and the following disclaimer in the documentation | |
+ * and/or other materials provided with the distribution. | |
+ * 3. The name of the author may not be used to endorse or promote products | |
+ * derived from this software without specific prior written permission. | |
+ * | |
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | |
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | |
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | |
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | |
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
+ */ | |
+ | |
+#import <Foundation/Foundation.h> | |
+ | |
+#import "RTCAudioTrack.h" | |
+ | |
+NS_ASSUME_NONNULL_BEGIN | |
+ | |
+@class RTCDTMFSender; | |
+// Protocol for receving tone change events. | |
+@protocol RTCDTMFSenderDelegate<NSObject> | |
+ | |
+// Called when a DTMF tone is played out. | |
+- (void)toneChange:(NSString*)tone; | |
+ | |
+@end | |
+ | |
+// ObjectiveC wrapper for a DtmfSender object. | |
+// See webrtc/api/dtmfsenderinterface.h | |
+@interface RTCDTMFSender : NSObject | |
+ | |
+@property(nonatomic, readonly) BOOL canInsertDTMF; | |
+@property(nonatomic, readonly) NSString* toneBuffer; | |
+@property(nonatomic, readonly) NSInteger duration; | |
+@property(nonatomic, readonly) NSInteger interToneGap; | |
+@property(nonatomic, weak) id<RTCDTMFSenderDelegate> delegate; | |
+// The track associated with this DTMF sender. This property | |
+// returns a copy of the RTCMediaStreamTrack | |
+@property(nonatomic, copy, nullable) RTCAudioTrack *track; | |
+ | |
+- (BOOL)insertDTMF:(NSString*)tones withDuration:(NSInteger)duration andInterToneGap:(NSInteger)interToneGap; | |
+ | |
+#ifndef DOXYGEN_SHOULD_SKIP_THIS | |
+// Disallow init and don't add to documentation | |
+- (id)init __attribute__(( | |
+ unavailable("init is not a supported initializer for this class."))); | |
+#endif /* DOXYGEN_SHOULD_SKIP_THIS */ | |
+ | |
+@end | |
+ | |
+NS_ASSUME_NONNULL_END | |
+ | |
diff --git a/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnection.h b/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnection.h | |
index 4438eb2..c18cd9e 100644 | |
--- a/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnection.h | |
+++ b/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnection.h | |
@@ -12,9 +12,11 @@ | |
#import <WebRTC/RTCMacros.h> | |
+@class RTCAudioTrack; | |
@class RTCConfiguration; | |
@class RTCDataChannel; | |
@class RTCDataChannelConfiguration; | |
+@class RTCDTMFSender; | |
@class RTCIceCandidate; | |
@class RTCMediaConstraints; | |
@class RTCMediaStream; | |
@@ -161,6 +163,9 @@ RTC_EXPORT | |
/** Remove the given media stream from this peer connection. */ | |
- (void)removeStream:(RTCMediaStream *)stream; | |
+/** Create a DTMF sender. */ | |
+- (RTCDTMFSender*)createDTMFSenderForTrack:(RTCAudioTrack*)audioTrack; | |
+ | |
/** Generate an SDP offer. */ | |
- (void)offerForConstraints:(RTCMediaConstraints *)constraints | |
completionHandler:(nullable void (^) | |
diff --git a/webrtc/sdk/sdk.gyp b/webrtc/sdk/sdk.gyp | |
index 908d544..ddc0a38 100644 | |
--- a/webrtc/sdk/sdk.gyp | |
+++ b/webrtc/sdk/sdk.gyp | |
@@ -76,7 +76,7 @@ | |
], | |
}], | |
], | |
- }, | |
+ }, # rtc_sdk_common_objc | |
{ | |
'target_name': 'rtc_sdk_peerconnection_objc', | |
'type': 'static_library', | |
@@ -116,6 +116,8 @@ | |
'objc/Framework/Classes/RTCConfiguration.mm', | |
'objc/Framework/Classes/RTCDataChannel+Private.h', | |
'objc/Framework/Classes/RTCDataChannel.mm', | |
+ 'objc/Framework/Classes/RTCDTMFSender+Private.h', | |
+ 'objc/Framework/Classes/RTCDTMFSender.mm', | |
'objc/Framework/Classes/RTCDataChannelConfiguration+Private.h', | |
'objc/Framework/Classes/RTCDataChannelConfiguration.mm', | |
'objc/Framework/Classes/RTCI420Shader.mm', | |
@@ -173,6 +175,7 @@ | |
'objc/Framework/Headers/WebRTC/RTCAudioTrack.h', | |
'objc/Framework/Headers/WebRTC/RTCConfiguration.h', | |
'objc/Framework/Headers/WebRTC/RTCDataChannel.h', | |
+ 'objc/Framework/Headers/WebRTC/RTCDTMFSender.h', | |
'objc/Framework/Headers/WebRTC/RTCDataChannelConfiguration.h', | |
'objc/Framework/Headers/WebRTC/RTCIceCandidate.h', | |
'objc/Framework/Headers/WebRTC/RTCIceServer.h', | |
@@ -261,6 +264,7 @@ | |
'objc/Framework/Headers/WebRTC/RTCCameraPreviewView.h', | |
'objc/Framework/Headers/WebRTC/RTCConfiguration.h', | |
'objc/Framework/Headers/WebRTC/RTCDataChannel.h', | |
+ 'objc/Framework/Headers/WebRTC/RTCDTMFSender.h', | |
'objc/Framework/Headers/WebRTC/RTCDataChannelConfiguration.h', | |
'objc/Framework/Headers/WebRTC/RTCDispatcher.h', | |
'objc/Framework/Headers/WebRTC/RTCEAGLVideoView.h', |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment