OLD | NEW |
| (Empty) |
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 "NSString+StdString.h" | |
14 #import "WebRTC/RTCMediaStreamTrack.h" // For "kind" strings. | |
15 | |
16 #include "webrtc/base/checks.h" | |
17 #include "webrtc/media/base/mediaconstants.h" | |
18 | |
19 const NSString * const kRTCRtxCodecName = @(cricket::kRtxCodecName); | |
20 const NSString * const kRTCRedCodecName = @(cricket::kRedCodecName); | |
21 const NSString * const kRTCUlpfecCodecName = @(cricket::kUlpfecCodecName); | |
22 const NSString * const kRTCFlexfecCodecName = @(cricket::kFlexfecCodecName); | |
23 const NSString * const kRTCOpusCodecName = @(cricket::kOpusCodecName); | |
24 const NSString * const kRTCIsacCodecName = @(cricket::kIsacCodecName); | |
25 const NSString * const kRTCL16CodecName = @(cricket::kL16CodecName); | |
26 const NSString * const kRTCG722CodecName = @(cricket::kG722CodecName); | |
27 const NSString * const kRTCIlbcCodecName = @(cricket::kIlbcCodecName); | |
28 const NSString * const kRTCPcmuCodecName = @(cricket::kPcmuCodecName); | |
29 const NSString * const kRTCPcmaCodecName = @(cricket::kPcmaCodecName); | |
30 const NSString * const kRTCDtmfCodecName = @(cricket::kDtmfCodecName); | |
31 const NSString * const kRTCComfortNoiseCodecName = | |
32 @(cricket::kComfortNoiseCodecName); | |
33 const NSString * const kVp8CodecName = @(cricket::kVp8CodecName); | |
34 const NSString * const kVp9CodecName = @(cricket::kVp9CodecName); | |
35 const NSString * const kH264CodecName = @(cricket::kH264CodecName); | |
36 | |
37 @implementation RTCRtpCodecParameters | |
38 | |
39 @synthesize payloadType = _payloadType; | |
40 @synthesize name = _name; | |
41 @synthesize kind = _kind; | |
42 @synthesize clockRate = _clockRate; | |
43 @synthesize numChannels = _numChannels; | |
44 | |
45 - (instancetype)init { | |
46 return [super init]; | |
47 } | |
48 | |
49 - (instancetype)initWithNativeParameters: | |
50 (const webrtc::RtpCodecParameters &)nativeParameters { | |
51 if (self = [self init]) { | |
52 _payloadType = nativeParameters.payload_type; | |
53 _name = [NSString stringForStdString:nativeParameters.name]; | |
54 switch (nativeParameters.kind) { | |
55 case cricket::MEDIA_TYPE_AUDIO: | |
56 _kind = kRTCMediaStreamTrackKindAudio; | |
57 break; | |
58 case cricket::MEDIA_TYPE_VIDEO: | |
59 _kind = kRTCMediaStreamTrackKindVideo; | |
60 break; | |
61 case cricket::MEDIA_TYPE_DATA: | |
62 RTC_NOTREACHED(); | |
63 break; | |
64 } | |
65 if (nativeParameters.clock_rate) { | |
66 _clockRate = [NSNumber numberWithInt:*nativeParameters.clock_rate]; | |
67 } | |
68 if (nativeParameters.num_channels) { | |
69 _numChannels = [NSNumber numberWithInt:*nativeParameters.num_channels]; | |
70 } | |
71 } | |
72 return self; | |
73 } | |
74 | |
75 - (webrtc::RtpCodecParameters)nativeParameters { | |
76 webrtc::RtpCodecParameters parameters; | |
77 parameters.payload_type = _payloadType; | |
78 parameters.name = [NSString stdStringForString:_name]; | |
79 // NSString pointer comparison is safe here since "kind" is readonly and only | |
80 // populated above. | |
81 if (_kind == kRTCMediaStreamTrackKindAudio) { | |
82 parameters.kind = cricket::MEDIA_TYPE_AUDIO; | |
83 } else if (_kind == kRTCMediaStreamTrackKindVideo) { | |
84 parameters.kind = cricket::MEDIA_TYPE_VIDEO; | |
85 } else { | |
86 RTC_NOTREACHED(); | |
87 } | |
88 if (_clockRate != nil) { | |
89 parameters.clock_rate = rtc::Optional<int>(_clockRate.intValue); | |
90 } | |
91 if (_numChannels != nil) { | |
92 parameters.num_channels = rtc::Optional<int>(_numChannels.intValue); | |
93 } | |
94 return parameters; | |
95 } | |
96 | |
97 @end | |
OLD | NEW |