OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #import "RTCRtpCodecParameters+Private.h" | 11 #import "RTCRtpCodecParameters+Private.h" |
12 | 12 |
13 #import "NSString+StdString.h" | 13 #import "NSString+StdString.h" |
| 14 #import "WebRTC/RTCMediaStreamTrack.h" // For "kind" strings. |
14 | 15 |
| 16 #include "webrtc/base/checks.h" |
15 #include "webrtc/media/base/mediaconstants.h" | 17 #include "webrtc/media/base/mediaconstants.h" |
16 | 18 |
17 const NSString * const kRTCRtxCodecMimeType = @(cricket::kRtxCodecName); | 19 const NSString * const kRTCRtxCodecName = @(cricket::kRtxCodecName); |
18 const NSString * const kRTCRedCodecMimeType = @(cricket::kRedCodecName); | 20 const NSString * const kRTCRedCodecName = @(cricket::kRedCodecName); |
19 const NSString * const kRTCUlpfecCodecMimeType = @(cricket::kUlpfecCodecName); | 21 const NSString * const kRTCUlpfecCodecName = @(cricket::kUlpfecCodecName); |
20 const NSString * const kRTCFlexfecCodecMimeType = @(cricket::kFlexfecCodecName); | 22 const NSString * const kRTCFlexfecCodecName = @(cricket::kFlexfecCodecName); |
21 const NSString * const kRTCOpusCodecMimeType = @(cricket::kOpusCodecName); | 23 const NSString * const kRTCOpusCodecName = @(cricket::kOpusCodecName); |
22 const NSString * const kRTCIsacCodecMimeType = @(cricket::kIsacCodecName); | 24 const NSString * const kRTCIsacCodecName = @(cricket::kIsacCodecName); |
23 const NSString * const kRTCL16CodecMimeType = @(cricket::kL16CodecName); | 25 const NSString * const kRTCL16CodecName = @(cricket::kL16CodecName); |
24 const NSString * const kRTCG722CodecMimeType = @(cricket::kG722CodecName); | 26 const NSString * const kRTCG722CodecName = @(cricket::kG722CodecName); |
25 const NSString * const kRTCIlbcCodecMimeType = @(cricket::kIlbcCodecName); | 27 const NSString * const kRTCIlbcCodecName = @(cricket::kIlbcCodecName); |
26 const NSString * const kRTCPcmuCodecMimeType = @(cricket::kPcmuCodecName); | 28 const NSString * const kRTCPcmuCodecName = @(cricket::kPcmuCodecName); |
27 const NSString * const kRTCPcmaCodecMimeType = @(cricket::kPcmaCodecName); | 29 const NSString * const kRTCPcmaCodecName = @(cricket::kPcmaCodecName); |
28 const NSString * const kRTCDtmfCodecMimeType = @(cricket::kDtmfCodecName); | 30 const NSString * const kRTCDtmfCodecName = @(cricket::kDtmfCodecName); |
29 const NSString * const kRTCComfortNoiseCodecMimeType = | 31 const NSString * const kRTCComfortNoiseCodecName = |
30 @(cricket::kComfortNoiseCodecName); | 32 @(cricket::kComfortNoiseCodecName); |
31 const NSString * const kVp8CodecMimeType = @(cricket::kVp8CodecName); | 33 const NSString * const kVp8CodecName = @(cricket::kVp8CodecName); |
32 const NSString * const kVp9CodecMimeType = @(cricket::kVp9CodecName); | 34 const NSString * const kVp9CodecName = @(cricket::kVp9CodecName); |
33 const NSString * const kH264CodecMimeType = @(cricket::kH264CodecName); | 35 const NSString * const kH264CodecName = @(cricket::kH264CodecName); |
34 | 36 |
35 @implementation RTCRtpCodecParameters | 37 @implementation RTCRtpCodecParameters |
36 | 38 |
37 @synthesize payloadType = _payloadType; | 39 @synthesize payloadType = _payloadType; |
38 @synthesize mimeType = _mimeType; | 40 @synthesize name = _name; |
| 41 @synthesize kind = _kind; |
39 @synthesize clockRate = _clockRate; | 42 @synthesize clockRate = _clockRate; |
40 @synthesize channels = _channels; | 43 @synthesize numChannels = _numChannels; |
41 | 44 |
42 - (instancetype)init { | 45 - (instancetype)init { |
43 return [super init]; | 46 return [super init]; |
44 } | 47 } |
45 | 48 |
46 - (instancetype)initWithNativeParameters: | 49 - (instancetype)initWithNativeParameters: |
47 (const webrtc::RtpCodecParameters &)nativeParameters { | 50 (const webrtc::RtpCodecParameters &)nativeParameters { |
48 if (self = [self init]) { | 51 if (self = [self init]) { |
49 _payloadType = nativeParameters.payload_type; | 52 _payloadType = nativeParameters.payload_type; |
50 _mimeType = [NSString stringForStdString:nativeParameters.mime_type]; | 53 _name = [NSString stringForStdString:nativeParameters.name]; |
51 _clockRate = nativeParameters.clock_rate; | 54 switch (nativeParameters.kind) { |
52 _channels = nativeParameters.channels; | 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 } |
53 } | 71 } |
54 return self; | 72 return self; |
55 } | 73 } |
56 | 74 |
57 - (webrtc::RtpCodecParameters)nativeParameters { | 75 - (webrtc::RtpCodecParameters)nativeParameters { |
58 webrtc::RtpCodecParameters parameters; | 76 webrtc::RtpCodecParameters parameters; |
59 parameters.payload_type = _payloadType; | 77 parameters.payload_type = _payloadType; |
60 parameters.mime_type = [NSString stdStringForString:_mimeType]; | 78 parameters.name = [NSString stdStringForString:_name]; |
61 parameters.clock_rate = _clockRate; | 79 // NSString pointer comparison is safe here since "kind" is readonly and only |
62 parameters.channels = _channels; | 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 } |
63 return parameters; | 94 return parameters; |
64 } | 95 } |
65 | 96 |
66 @end | 97 @end |
OLD | NEW |