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 if (nativeParameters.kind == cricket::MEDIA_TYPE_AUDIO) { |
tkchin_webrtc
2017/01/26 05:24:09
switch on enum with all cases and rely on compiler
Taylor Brandstetter
2017/01/26 19:08:20
Done.
| |
52 _channels = nativeParameters.channels; | 55 _kind = kRTCMediaStreamTrackKindAudio; |
56 } else { | |
57 RTC_DCHECK_EQ(cricket::MEDIA_TYPE_VIDEO, nativeParameters.kind); | |
58 _kind = kRTCMediaStreamTrackKindVideo; | |
59 } | |
60 if (nativeParameters.clock_rate) { | |
61 _clockRate = [NSNumber numberWithInt:*nativeParameters.clock_rate]; | |
62 } | |
63 if (nativeParameters.num_channels) { | |
64 _numChannels = [NSNumber numberWithInt:*nativeParameters.num_channels]; | |
65 } | |
53 } | 66 } |
54 return self; | 67 return self; |
55 } | 68 } |
56 | 69 |
57 - (webrtc::RtpCodecParameters)nativeParameters { | 70 - (webrtc::RtpCodecParameters)nativeParameters { |
58 webrtc::RtpCodecParameters parameters; | 71 webrtc::RtpCodecParameters parameters; |
59 parameters.payload_type = _payloadType; | 72 parameters.payload_type = _payloadType; |
60 parameters.mime_type = [NSString stdStringForString:_mimeType]; | 73 parameters.name = [NSString stdStringForString:_name]; |
61 parameters.clock_rate = _clockRate; | 74 // NSString pointer comparison is safe here since "kind" is readonly and only |
62 parameters.channels = _channels; | 75 // populated above. |
76 if (_kind == kRTCMediaStreamTrackKindAudio) { | |
77 parameters.kind = cricket::MEDIA_TYPE_AUDIO; | |
78 } else { | |
79 RTC_DCHECK_EQ(kRTCMediaStreamTrackKindVideo, _kind); | |
80 parameters.kind = cricket::MEDIA_TYPE_VIDEO; | |
81 } | |
82 if (_clockRate != nil) { | |
83 parameters.clock_rate = rtc::Optional<int>(_clockRate.intValue); | |
84 } | |
85 if (_numChannels != nil) { | |
86 parameters.num_channels = rtc::Optional<int>(_numChannels.intValue); | |
87 } | |
63 return parameters; | 88 return parameters; |
64 } | 89 } |
65 | 90 |
66 @end | 91 @end |
OLD | NEW |