1/* 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11#import "RTCDtmfSender+Private.h" 12 13#import "base/RTCLogging.h" 14#import "helpers/NSString+StdString.h" 15 16#include "rtc_base/time_utils.h" 17 18@implementation RTC_OBJC_TYPE (RTCDtmfSender) { 19 rtc::scoped_refptr<webrtc::DtmfSenderInterface> _nativeDtmfSender; 20} 21 22- (BOOL)canInsertDtmf { 23 return _nativeDtmfSender->CanInsertDtmf(); 24} 25 26- (BOOL)insertDtmf:(nonnull NSString *)tones 27 duration:(NSTimeInterval)duration 28 interToneGap:(NSTimeInterval)interToneGap { 29 RTC_DCHECK(tones != nil); 30 31 int durationMs = static_cast<int>(duration * rtc::kNumMillisecsPerSec); 32 int interToneGapMs = static_cast<int>(interToneGap * rtc::kNumMillisecsPerSec); 33 return _nativeDtmfSender->InsertDtmf( 34 [NSString stdStringForString:tones], durationMs, interToneGapMs); 35} 36 37- (nonnull NSString *)remainingTones { 38 return [NSString stringForStdString:_nativeDtmfSender->tones()]; 39} 40 41- (NSTimeInterval)duration { 42 return static_cast<NSTimeInterval>(_nativeDtmfSender->duration()) / rtc::kNumMillisecsPerSec; 43} 44 45- (NSTimeInterval)interToneGap { 46 return static_cast<NSTimeInterval>(_nativeDtmfSender->inter_tone_gap()) / 47 rtc::kNumMillisecsPerSec; 48} 49 50- (NSString *)description { 51 return [NSString stringWithFormat:@"RTC_OBJC_TYPE(RTCDtmfSender) {\n remainingTones: %@\n " 52 @"duration: %f sec\n interToneGap: %f sec\n}", 53 [self remainingTones], 54 [self duration], 55 [self interToneGap]]; 56} 57 58#pragma mark - Private 59 60- (rtc::scoped_refptr<webrtc::DtmfSenderInterface>)nativeDtmfSender { 61 return _nativeDtmfSender; 62} 63 64- (instancetype)initWithNativeDtmfSender: 65 (rtc::scoped_refptr<webrtc::DtmfSenderInterface>)nativeDtmfSender { 66 NSParameterAssert(nativeDtmfSender); 67 if (self = [super init]) { 68 _nativeDtmfSender = nativeDtmfSender; 69 RTCLogInfo( 70 @"RTC_OBJC_TYPE(RTCDtmfSender)(%p): created DTMF sender: %@", self, self.description); 71 } 72 return self; 73} 74@end 75