You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #import "RTCDtmfSender+Private.h"
  11. #import "base/RTCLogging.h"
  12. #import "helpers/NSString+StdString.h"
  13. #include "rtc_base/time_utils.h"
  14. @implementation RTCDtmfSender {
  15. rtc::scoped_refptr<webrtc::DtmfSenderInterface> _nativeDtmfSender;
  16. }
  17. - (BOOL)canInsertDtmf {
  18. return _nativeDtmfSender->CanInsertDtmf();
  19. }
  20. - (BOOL)insertDtmf:(nonnull NSString *)tones
  21. duration:(NSTimeInterval)duration
  22. interToneGap:(NSTimeInterval)interToneGap {
  23. RTC_DCHECK(tones != nil);
  24. int durationMs = static_cast<int>(duration * rtc::kNumMillisecsPerSec);
  25. int interToneGapMs = static_cast<int>(interToneGap * rtc::kNumMillisecsPerSec);
  26. return _nativeDtmfSender->InsertDtmf(
  27. [NSString stdStringForString:tones], durationMs, interToneGapMs);
  28. }
  29. - (nonnull NSString *)remainingTones {
  30. return [NSString stringForStdString:_nativeDtmfSender->tones()];
  31. }
  32. - (NSTimeInterval)duration {
  33. return static_cast<NSTimeInterval>(_nativeDtmfSender->duration()) / rtc::kNumMillisecsPerSec;
  34. }
  35. - (NSTimeInterval)interToneGap {
  36. return static_cast<NSTimeInterval>(_nativeDtmfSender->inter_tone_gap()) /
  37. rtc::kNumMillisecsPerSec;
  38. }
  39. - (NSString *)description {
  40. return [NSString
  41. stringWithFormat:
  42. @"RTCDtmfSender {\n remainingTones: %@\n duration: %f sec\n interToneGap: %f sec\n}",
  43. [self remainingTones],
  44. [self duration],
  45. [self interToneGap]];
  46. }
  47. #pragma mark - Private
  48. - (rtc::scoped_refptr<webrtc::DtmfSenderInterface>)nativeDtmfSender {
  49. return _nativeDtmfSender;
  50. }
  51. - (instancetype)initWithNativeDtmfSender:
  52. (rtc::scoped_refptr<webrtc::DtmfSenderInterface>)nativeDtmfSender {
  53. NSParameterAssert(nativeDtmfSender);
  54. if (self = [super init]) {
  55. _nativeDtmfSender = nativeDtmfSender;
  56. RTCLogInfo(@"RTCDtmfSender(%p): created DTMF sender: %@", self, self.description);
  57. }
  58. return self;
  59. }
  60. @end