• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 *  Copyright 2016 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 "RTCRtpCodecParameters+Private.h"
12
13#import "RTCMediaStreamTrack.h"
14#import "helpers/NSString+StdString.h"
15
16#include "media/base/media_constants.h"
17#include "rtc_base/checks.h"
18
19const NSString * const kRTCRtxCodecName = @(cricket::kRtxCodecName);
20const NSString * const kRTCRedCodecName = @(cricket::kRedCodecName);
21const NSString * const kRTCUlpfecCodecName = @(cricket::kUlpfecCodecName);
22const NSString * const kRTCFlexfecCodecName = @(cricket::kFlexfecCodecName);
23const NSString * const kRTCOpusCodecName = @(cricket::kOpusCodecName);
24const NSString * const kRTCIsacCodecName = @(cricket::kIsacCodecName);
25const NSString * const kRTCL16CodecName  = @(cricket::kL16CodecName);
26const NSString * const kRTCG722CodecName = @(cricket::kG722CodecName);
27const NSString * const kRTCIlbcCodecName = @(cricket::kIlbcCodecName);
28const NSString * const kRTCPcmuCodecName = @(cricket::kPcmuCodecName);
29const NSString * const kRTCPcmaCodecName = @(cricket::kPcmaCodecName);
30const NSString * const kRTCDtmfCodecName = @(cricket::kDtmfCodecName);
31const NSString * const kRTCComfortNoiseCodecName =
32    @(cricket::kComfortNoiseCodecName);
33const NSString * const kRTCVp8CodecName = @(cricket::kVp8CodecName);
34const NSString * const kRTCVp9CodecName = @(cricket::kVp9CodecName);
35const NSString * const kRTCH264CodecName = @(cricket::kH264CodecName);
36
37@implementation RTC_OBJC_TYPE (RTCRtpCodecParameters)
38
39@synthesize payloadType = _payloadType;
40@synthesize name = _name;
41@synthesize kind = _kind;
42@synthesize clockRate = _clockRate;
43@synthesize numChannels = _numChannels;
44@synthesize parameters = _parameters;
45
46- (instancetype)init {
47  return [super init];
48}
49
50- (instancetype)initWithNativeParameters:
51    (const webrtc::RtpCodecParameters &)nativeParameters {
52  if (self = [self init]) {
53    _payloadType = nativeParameters.payload_type;
54    _name = [NSString stringForStdString:nativeParameters.name];
55    switch (nativeParameters.kind) {
56      case cricket::MEDIA_TYPE_AUDIO:
57        _kind = kRTCMediaStreamTrackKindAudio;
58        break;
59      case cricket::MEDIA_TYPE_VIDEO:
60        _kind = kRTCMediaStreamTrackKindVideo;
61        break;
62      case cricket::MEDIA_TYPE_DATA:
63        RTC_NOTREACHED();
64        break;
65    }
66    if (nativeParameters.clock_rate) {
67      _clockRate = [NSNumber numberWithInt:*nativeParameters.clock_rate];
68    }
69    if (nativeParameters.num_channels) {
70      _numChannels = [NSNumber numberWithInt:*nativeParameters.num_channels];
71    }
72    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
73    for (const auto &parameter : nativeParameters.parameters) {
74      [parameters setObject:[NSString stringForStdString:parameter.second]
75                     forKey:[NSString stringForStdString:parameter.first]];
76    }
77    _parameters = parameters;
78  }
79  return self;
80}
81
82- (webrtc::RtpCodecParameters)nativeParameters {
83  webrtc::RtpCodecParameters parameters;
84  parameters.payload_type = _payloadType;
85  parameters.name = [NSString stdStringForString:_name];
86  // NSString pointer comparison is safe here since "kind" is readonly and only
87  // populated above.
88  if (_kind == kRTCMediaStreamTrackKindAudio) {
89    parameters.kind = cricket::MEDIA_TYPE_AUDIO;
90  } else if (_kind == kRTCMediaStreamTrackKindVideo) {
91    parameters.kind = cricket::MEDIA_TYPE_VIDEO;
92  } else {
93    RTC_NOTREACHED();
94  }
95  if (_clockRate != nil) {
96    parameters.clock_rate = absl::optional<int>(_clockRate.intValue);
97  }
98  if (_numChannels != nil) {
99    parameters.num_channels = absl::optional<int>(_numChannels.intValue);
100  }
101  for (NSString *paramKey in _parameters.allKeys) {
102    std::string key = [NSString stdStringForString:paramKey];
103    std::string value = [NSString stdStringForString:_parameters[paramKey]];
104    parameters.parameters[key] = value;
105  }
106  return parameters;
107}
108
109@end
110