diff --git a/examples/BUILD.gn b/examples/BUILD.gn index 7bbd933b08..ae6bdb7f94 100644 --- a/examples/BUILD.gn +++ b/examples/BUILD.gn @@ -217,8 +217,6 @@ if (is_ios || (is_mac && target_cpu != "x86")) { "objc/AppRTCMobile/ARDMessageResponse.h", "objc/AppRTCMobile/ARDMessageResponse.m", "objc/AppRTCMobile/ARDRoomServerClient.h", - "objc/AppRTCMobile/ARDSDPUtils.h", - "objc/AppRTCMobile/ARDSDPUtils.m", "objc/AppRTCMobile/ARDSettingsModel+Private.h", "objc/AppRTCMobile/ARDSettingsModel.h", "objc/AppRTCMobile/ARDSettingsModel.m", @@ -279,6 +277,8 @@ if (is_ios || (is_mac && target_cpu != "x86")) { "objc/AppRTCMobile/ios/ARDVideoCallView.m", "objc/AppRTCMobile/ios/ARDVideoCallViewController.h", "objc/AppRTCMobile/ios/ARDVideoCallViewController.m", + "objc/AppRTCMobile/ios/RTCVideoCodecInfo+HumanReadable.h", + "objc/AppRTCMobile/ios/RTCVideoCodecInfo+HumanReadable.m", "objc/AppRTCMobile/ios/UIImage+ARDUtilities.h", "objc/AppRTCMobile/ios/UIImage+ARDUtilities.m", ] @@ -436,7 +436,6 @@ if (is_ios || (is_mac && target_cpu != "x86")) { testonly = true sources = [ "objc/AppRTCMobile/tests/ARDAppClient_xctest.mm", - "objc/AppRTCMobile/tests/ARDSDPUtils_xctest.mm", "objc/AppRTCMobile/tests/ARDSettingsModel_xctest.mm", ] deps = [ diff --git a/examples/objc/AppRTCMobile/ARDAppClient.m b/examples/objc/AppRTCMobile/ARDAppClient.m index c6d69c8f9f..8e933b921b 100644 --- a/examples/objc/AppRTCMobile/ARDAppClient.m +++ b/examples/objc/AppRTCMobile/ARDAppClient.m @@ -27,7 +27,6 @@ #import "ARDAppEngineClient.h" #import "ARDJoinResponse.h" #import "ARDMessageResponse.h" -#import "ARDSDPUtils.h" #import "ARDSettingsModel.h" #import "ARDSignalingMessage.h" #import "ARDTURNClient+Internal.h" @@ -165,10 +164,6 @@ static int const kKbpsMultiplier = 1000; } - (void)configure { - ARDVideoDecoderFactory *decoderFactory = [[ARDVideoDecoderFactory alloc] init]; - ARDVideoEncoderFactory *encoderFactory = [[ARDVideoEncoderFactory alloc] init]; - _factory = [[RTCPeerConnectionFactory alloc] initWithEncoderFactory:encoderFactory - decoderFactory:decoderFactory]; _messageQueue = [NSMutableArray array]; _iceServers = [NSMutableArray array]; _fileLogger = [[RTCFileLogger alloc] init]; @@ -223,6 +218,12 @@ static int const kKbpsMultiplier = 1000; _isLoopback = isLoopback; self.state = kARDAppClientStateConnecting; + ARDVideoDecoderFactory *decoderFactory = [[ARDVideoDecoderFactory alloc] init]; + ARDVideoEncoderFactory *encoderFactory = [[ARDVideoEncoderFactory alloc] init]; + encoderFactory.preferredCodec = [settings currentVideoCodecSettingFromStore]; + _factory = [[RTCPeerConnectionFactory alloc] initWithEncoderFactory:encoderFactory + decoderFactory:decoderFactory]; + #if defined(WEBRTC_IOS) if (kARDAppClientEnableTracing) { NSString *filePath = [self documentsFilePathForFileName:@"webrtc-trace.txt"]; @@ -447,20 +448,15 @@ static int const kKbpsMultiplier = 1000; [_delegate appClient:self didError:sdpError]; return; } - // Prefer codec from settings if available. - RTCSessionDescription *sdpPreferringCodec = - [ARDSDPUtils descriptionForDescription:sdp - preferredVideoCodec:[_settings currentVideoCodecSettingFromStore]]; __weak ARDAppClient *weakSelf = self; - [_peerConnection setLocalDescription:sdpPreferringCodec + [_peerConnection setLocalDescription:sdp completionHandler:^(NSError *error) { - ARDAppClient *strongSelf = weakSelf; - [strongSelf peerConnection:strongSelf.peerConnection - didSetSessionDescriptionWithError:error]; - }]; + ARDAppClient *strongSelf = weakSelf; + [strongSelf peerConnection:strongSelf.peerConnection + didSetSessionDescriptionWithError:error]; + }]; ARDSessionDescriptionMessage *message = - [[ARDSessionDescriptionMessage alloc] - initWithDescription:sdpPreferringCodec]; + [[ARDSessionDescriptionMessage alloc] initWithDescription:sdp]; [self sendSignalingMessage:message]; [self setMaxBitrateForPeerConnectionVideoSender]; }); @@ -600,17 +596,13 @@ static int const kKbpsMultiplier = 1000; ARDSessionDescriptionMessage *sdpMessage = (ARDSessionDescriptionMessage *)message; RTCSessionDescription *description = sdpMessage.sessionDescription; - // Prefer codec from settings if available. - RTCSessionDescription *sdpPreferringCodec = - [ARDSDPUtils descriptionForDescription:description - preferredVideoCodec:[_settings currentVideoCodecSettingFromStore]]; __weak ARDAppClient *weakSelf = self; - [_peerConnection setRemoteDescription:sdpPreferringCodec + [_peerConnection setRemoteDescription:description completionHandler:^(NSError *error) { - ARDAppClient *strongSelf = weakSelf; - [strongSelf peerConnection:strongSelf.peerConnection - didSetSessionDescriptionWithError:error]; - }]; + ARDAppClient *strongSelf = weakSelf; + [strongSelf peerConnection:strongSelf.peerConnection + didSetSessionDescriptionWithError:error]; + }]; break; } case kARDSignalingMessageTypeCandidate: { diff --git a/examples/objc/AppRTCMobile/ARDSDPUtils.h b/examples/objc/AppRTCMobile/ARDSDPUtils.h deleted file mode 100644 index 18795afce2..0000000000 --- a/examples/objc/AppRTCMobile/ARDSDPUtils.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2015 The WebRTC Project Authors. All rights reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#import - -@class RTCSessionDescription; - -@interface ARDSDPUtils : NSObject - -// Updates the original SDP description to instead prefer the specified video -// codec. We do this by placing the specified codec at the beginning of the -// codec list if it exists in the sdp. -+ (RTCSessionDescription *) - descriptionForDescription:(RTCSessionDescription *)description - preferredVideoCodec:(NSString *)codec; - -@end diff --git a/examples/objc/AppRTCMobile/ARDSDPUtils.m b/examples/objc/AppRTCMobile/ARDSDPUtils.m deleted file mode 100644 index a9442aac8f..0000000000 --- a/examples/objc/AppRTCMobile/ARDSDPUtils.m +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2015 The WebRTC Project Authors. All rights reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#import "ARDSDPUtils.h" - -#import "WebRTC/RTCLogging.h" -#import "WebRTC/RTCSessionDescription.h" - -@implementation ARDSDPUtils - -+ (RTCSessionDescription *) - descriptionForDescription:(RTCSessionDescription *)description - preferredVideoCodec:(NSString *)codec { - NSString *sdpString = description.sdp; - NSString *lineSeparator = @"\r\n"; - NSString *mLineSeparator = @" "; - // Copied from PeerConnectionClient.java. - // TODO(tkchin): Move this to a shared C++ file. - NSMutableArray *lines = - [NSMutableArray arrayWithArray: - [sdpString componentsSeparatedByString:lineSeparator]]; - // Find the line starting with "m=video". - NSInteger mLineIndex = -1; - for (NSInteger i = 0; i < lines.count; ++i) { - if ([lines[i] hasPrefix:@"m=video"]) { - mLineIndex = i; - break; - } - } - if (mLineIndex == -1) { - RTCLog(@"No m=video line, so can't prefer %@", codec); - return description; - } - // An array with all payload types with name |codec|. The payload types are - // integers in the range 96-127, but they are stored as strings here. - NSMutableArray *codecPayloadTypes = [[NSMutableArray alloc] init]; - // a=rtpmap: / - // [/] - NSString *pattern = - [NSString stringWithFormat:@"^a=rtpmap:(\\d+) %@(/\\d+)+[\r]?$", codec]; - NSRegularExpression *regex = - [NSRegularExpression regularExpressionWithPattern:pattern - options:0 - error:nil]; - for (NSString *line in lines) { - NSTextCheckingResult *codecMatches = - [regex firstMatchInString:line - options:0 - range:NSMakeRange(0, line.length)]; - if (codecMatches) { - [codecPayloadTypes - addObject:[line substringWithRange:[codecMatches rangeAtIndex:1]]]; - } - } - if ([codecPayloadTypes count] == 0) { - RTCLog(@"No payload types with name %@", codec); - return description; - } - NSArray *origMLineParts = - [lines[mLineIndex] componentsSeparatedByString:mLineSeparator]; - // The format of ML should be: m= ... - const int kHeaderLength = 3; - if (origMLineParts.count <= kHeaderLength) { - RTCLogWarning(@"Wrong SDP media description format: %@", lines[mLineIndex]); - return description; - } - // Split the line into header and payloadTypes. - NSRange headerRange = NSMakeRange(0, kHeaderLength); - NSRange payloadRange = - NSMakeRange(kHeaderLength, origMLineParts.count - kHeaderLength); - NSArray *header = [origMLineParts subarrayWithRange:headerRange]; - NSMutableArray *payloadTypes = [NSMutableArray - arrayWithArray:[origMLineParts subarrayWithRange:payloadRange]]; - // Reconstruct the line with |codecPayloadTypes| moved to the beginning of the - // payload types. - NSMutableArray *newMLineParts = [NSMutableArray arrayWithCapacity:origMLineParts.count]; - [newMLineParts addObjectsFromArray:header]; - [newMLineParts addObjectsFromArray:codecPayloadTypes]; - [payloadTypes removeObjectsInArray:codecPayloadTypes]; - [newMLineParts addObjectsFromArray:payloadTypes]; - - NSString *newMLine = [newMLineParts componentsJoinedByString:mLineSeparator]; - [lines replaceObjectAtIndex:mLineIndex - withObject:newMLine]; - - NSString *mangledSdpString = [lines componentsJoinedByString:lineSeparator]; - return [[RTCSessionDescription alloc] initWithType:description.type - sdp:mangledSdpString]; -} - -@end diff --git a/examples/objc/AppRTCMobile/ARDSettingsModel.h b/examples/objc/AppRTCMobile/ARDSettingsModel.h index 8b2679fa82..625b533a0e 100644 --- a/examples/objc/AppRTCMobile/ARDSettingsModel.h +++ b/examples/objc/AppRTCMobile/ARDSettingsModel.h @@ -10,6 +10,8 @@ #import +#import "WebRTC/RTCVideoCodec.h" + NS_ASSUME_NONNULL_BEGIN /** @@ -51,12 +53,12 @@ NS_ASSUME_NONNULL_BEGIN /** * Returns array of available video codecs. */ -- (NSArray *)availableVideoCodecs; +- (NSArray *)availableVideoCodecs; /** * Returns current video codec setting from store if present or default (H264) otherwise. */ -- (NSString *)currentVideoCodecSettingFromStore; +- (RTCVideoCodecInfo *)currentVideoCodecSettingFromStore; /** * Stores the provided video codec setting into the store. @@ -66,7 +68,7 @@ NS_ASSUME_NONNULL_BEGIN * @param video codec settings the string to be stored. * @return YES/NO depending on success. */ -- (BOOL)storeVideoCodecSetting:(NSString *)videoCodec; +- (BOOL)storeVideoCodecSetting:(RTCVideoCodecInfo *)videoCodec; /** * Returns current max bitrate setting from store if present. diff --git a/examples/objc/AppRTCMobile/ARDSettingsModel.m b/examples/objc/AppRTCMobile/ARDSettingsModel.m index 0d3ca7ccb6..cdaead774a 100644 --- a/examples/objc/AppRTCMobile/ARDSettingsModel.m +++ b/examples/objc/AppRTCMobile/ARDSettingsModel.m @@ -10,15 +10,12 @@ #import "ARDSettingsModel+Private.h" #import "ARDSettingsStore.h" +#import "ARDVideoEncoderFactory.h" #import "WebRTC/RTCCameraVideoCapturer.h" #import "WebRTC/RTCMediaConstraints.h" NS_ASSUME_NONNULL_BEGIN -static NSArray *videoCodecsStaticValues() { - return @[ @"H264", @"VP8", @"VP9" ]; -} - @interface ARDSettingsModel () { ARDSettingsStore *_settingsStore; } @@ -68,20 +65,24 @@ static NSArray *videoCodecsStaticValues() { return YES; } -- (NSArray *)availableVideoCodecs { - return videoCodecsStaticValues(); +- (NSArray *)availableVideoCodecs { + NSArray *supportedCodecs = + [[[ARDVideoEncoderFactory alloc] init] supportedCodecs]; + return supportedCodecs; } -- (NSString *)currentVideoCodecSettingFromStore { +- (RTCVideoCodecInfo *)currentVideoCodecSettingFromStore { [self registerStoreDefaults]; - return [[self settingsStore] videoCodec]; + NSData *codecData = [[self settingsStore] videoCodec]; + return [NSKeyedUnarchiver unarchiveObjectWithData:codecData]; } -- (BOOL)storeVideoCodecSetting:(NSString *)videoCodec { +- (BOOL)storeVideoCodecSetting:(RTCVideoCodecInfo *)videoCodec { if (![[self availableVideoCodecs] containsObject:videoCodec]) { return NO; } - [[self settingsStore] setVideoCodec:videoCodec]; + NSData *codecData = [NSKeyedArchiver archivedDataWithRootObject:videoCodec]; + [[self settingsStore] setVideoCodec:codecData]; return YES; } @@ -153,8 +154,8 @@ static NSArray *videoCodecsStaticValues() { return [self availableVideoResolutions][0]; } -- (NSString *)defaultVideoCodecSetting { - return videoCodecsStaticValues()[0]; +- (RTCVideoCodecInfo *)defaultVideoCodecSetting { + return [self availableVideoCodecs][0]; } - (int)videoResolutionComponentAtIndex:(int)index inString:(NSString *)resolution { @@ -169,8 +170,9 @@ static NSArray *videoCodecsStaticValues() { } - (void)registerStoreDefaults { + NSData *codecData = [NSKeyedArchiver archivedDataWithRootObject:[self defaultVideoCodecSetting]]; [ARDSettingsStore setDefaultsForVideoResolution:[self defaultVideoResolutionSetting] - videoCodec:[self defaultVideoCodecSetting] + videoCodec:codecData bitrate:nil audioOnly:NO createAecDump:NO diff --git a/examples/objc/AppRTCMobile/ARDSettingsStore.h b/examples/objc/AppRTCMobile/ARDSettingsStore.h index 3f5f79106f..b68adb737a 100644 --- a/examples/objc/AppRTCMobile/ARDSettingsStore.h +++ b/examples/objc/AppRTCMobile/ARDSettingsStore.h @@ -24,7 +24,7 @@ NS_ASSUME_NONNULL_BEGIN * @param dictionary of values to store */ + (void)setDefaultsForVideoResolution:(NSString *)videoResolution - videoCodec:(NSString *)videoCodec + videoCodec:(NSData *)videoCodec bitrate:(nullable NSNumber *)bitrate audioOnly:(BOOL)audioOnly createAecDump:(BOOL)createAecDump @@ -32,7 +32,7 @@ NS_ASSUME_NONNULL_BEGIN useManualAudioConfig:(BOOL)useManualAudioConfig; @property(nonatomic) NSString *videoResolution; -@property(nonatomic) NSString *videoCodec; +@property(nonatomic) NSData *videoCodec; /** * Returns current max bitrate number stored in the store. diff --git a/examples/objc/AppRTCMobile/ARDSettingsStore.m b/examples/objc/AppRTCMobile/ARDSettingsStore.m index 8ccc438800..28a5ab7a24 100644 --- a/examples/objc/AppRTCMobile/ARDSettingsStore.m +++ b/examples/objc/AppRTCMobile/ARDSettingsStore.m @@ -11,7 +11,7 @@ #import "ARDSettingsStore.h" static NSString *const kVideoResolutionKey = @"rtc_video_resolution_key"; -static NSString *const kVideoCodecKey = @"rtc_video_codec_key"; +static NSString *const kVideoCodecKey = @"rtc_video_codec_info_key"; static NSString *const kBitrateKey = @"rtc_max_bitrate_key"; static NSString *const kAudioOnlyKey = @"rtc_audio_only_key"; static NSString *const kCreateAecDumpKey = @"rtc_create_aec_dump_key"; @@ -28,7 +28,7 @@ NS_ASSUME_NONNULL_BEGIN @implementation ARDSettingsStore + (void)setDefaultsForVideoResolution:(NSString *)videoResolution - videoCodec:(NSString *)videoCodec + videoCodec:(NSData *)videoCodec bitrate:(nullable NSNumber *)bitrate audioOnly:(BOOL)audioOnly createAecDump:(BOOL)createAecDump @@ -64,11 +64,11 @@ NS_ASSUME_NONNULL_BEGIN [self.storage synchronize]; } -- (NSString *)videoCodec { +- (NSData *)videoCodec { return [self.storage objectForKey:kVideoCodecKey]; } -- (void)setVideoCodec:(NSString *)videoCodec { +- (void)setVideoCodec:(NSData *)videoCodec { [self.storage setObject:videoCodec forKey:kVideoCodecKey]; [self.storage synchronize]; } diff --git a/examples/objc/AppRTCMobile/ARDVideoEncoderFactory.h b/examples/objc/AppRTCMobile/ARDVideoEncoderFactory.h index 9927ce4161..fb3e616920 100644 --- a/examples/objc/AppRTCMobile/ARDVideoEncoderFactory.h +++ b/examples/objc/AppRTCMobile/ARDVideoEncoderFactory.h @@ -13,4 +13,6 @@ @interface ARDVideoEncoderFactory : NSObject +@property(nonatomic, retain) RTCVideoCodecInfo* preferredCodec; + @end diff --git a/examples/objc/AppRTCMobile/ARDVideoEncoderFactory.m b/examples/objc/AppRTCMobile/ARDVideoEncoderFactory.m index a895011a72..e4aafccb2c 100644 --- a/examples/objc/AppRTCMobile/ARDVideoEncoderFactory.m +++ b/examples/objc/AppRTCMobile/ARDVideoEncoderFactory.m @@ -10,6 +10,7 @@ #import "ARDVideoEncoderFactory.h" +#import "ARDSettingsModel.h" #import "WebRTC/RTCVideoCodecH264.h" #import "WebRTC/RTCVideoEncoderVP8.h" #import "WebRTC/RTCVideoEncoderVP9.h" @@ -19,6 +20,8 @@ static NSString *kLevel31ConstrainedBaseline = @"42e01f"; @implementation ARDVideoEncoderFactory +@synthesize preferredCodec; + - (id)createEncoder:(RTCVideoCodecInfo *)info { if ([info.name isEqualToString:@"H264"]) { return [[RTCVideoEncoderH264 alloc] initWithCodecInfo:info]; @@ -58,7 +61,15 @@ static NSString *kLevel31ConstrainedBaseline = @"42e01f"; RTCVideoCodecInfo *vp9Info = [[RTCVideoCodecInfo alloc] initWithName:@"VP9" parameters:nil]; [codecs addObject:vp9Info]; - return [codecs copy]; + NSMutableArray *orderedCodecs = [NSMutableArray array]; + NSUInteger index = [codecs indexOfObject:self.preferredCodec]; + if (index != NSNotFound) { + [orderedCodecs addObject:[codecs objectAtIndex:index]]; + [codecs removeObjectAtIndex:index]; + } + [orderedCodecs addObjectsFromArray:codecs]; + + return [orderedCodecs copy]; } @end diff --git a/examples/objc/AppRTCMobile/ios/ARDSettingsViewController.m b/examples/objc/AppRTCMobile/ios/ARDSettingsViewController.m index fce5df7117..27aa757ff7 100644 --- a/examples/objc/AppRTCMobile/ios/ARDSettingsViewController.m +++ b/examples/objc/AppRTCMobile/ios/ARDSettingsViewController.m @@ -10,6 +10,7 @@ #import "ARDSettingsViewController.h" #import "ARDSettingsModel.h" +#import "RTCVideoCodecInfo+HumanReadable.h" NS_ASSUME_NONNULL_BEGIN @@ -62,7 +63,7 @@ typedef NS_ENUM(int, ARDAudioSettingsOptions) { return [_settingsModel availableVideoResolutions]; } -- (NSArray *)videoCodecArray { +- (NSArray *)videoCodecArray { return [_settingsModel availableVideoCodecs]; } @@ -214,9 +215,9 @@ updateListSelectionAtIndexPath:(NSIndexPath *)indexPath cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:dequeueIdentifier]; } - NSString *codec = self.videoCodecArray[indexPath.row]; - cell.textLabel.text = codec; - if ([codec isEqualToString:[_settingsModel currentVideoCodecSettingFromStore]]) { + RTCVideoCodecInfo *codec = self.videoCodecArray[indexPath.row]; + cell.textLabel.text = [codec humanReadableDescription]; + if ([codec isEqualToCodecInfo:[_settingsModel currentVideoCodecSettingFromStore]]) { cell.accessoryType = UITableViewCellAccessoryCheckmark; } else { cell.accessoryType = UITableViewCellAccessoryNone; @@ -231,7 +232,7 @@ updateListSelectionAtIndexPath:(NSIndexPath *)indexPath updateListSelectionAtIndexPath:indexPath inSection:ARDSettingsSectionVideoCodec]; - NSString *videoCodec = self.videoCodecArray[indexPath.row]; + RTCVideoCodecInfo *videoCodec = self.videoCodecArray[indexPath.row]; [_settingsModel storeVideoCodecSetting:videoCodec]; } diff --git a/examples/objc/AppRTCMobile/ios/RTCVideoCodecInfo+HumanReadable.h b/examples/objc/AppRTCMobile/ios/RTCVideoCodecInfo+HumanReadable.h new file mode 100644 index 0000000000..9c88993cf1 --- /dev/null +++ b/examples/objc/AppRTCMobile/ios/RTCVideoCodecInfo+HumanReadable.h @@ -0,0 +1,17 @@ +/* + * Copyright 2017 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCVideoCodec.h" + +@interface RTCVideoCodecInfo (HumanReadable) + +- (NSString *)humanReadableDescription; + +@end diff --git a/examples/objc/AppRTCMobile/ios/RTCVideoCodecInfo+HumanReadable.m b/examples/objc/AppRTCMobile/ios/RTCVideoCodecInfo+HumanReadable.m new file mode 100644 index 0000000000..de1998a693 --- /dev/null +++ b/examples/objc/AppRTCMobile/ios/RTCVideoCodecInfo+HumanReadable.m @@ -0,0 +1,30 @@ +/* + * Copyright 2017 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCVideoCodecInfo+HumanReadable.h" + +@implementation RTCVideoCodecInfo (HumanReadable) + +- (NSString *)humanReadableDescription { + if ([self.name isEqualToString:@"H264"]) { + NSString *profileId = self.parameters[@"profile-level-id"]; + if ([profileId isEqualToString:@"640c1f"]) { + return @"H264 (High)"; + } else if ([profileId isEqualToString:@"42e01f"]) { + return @"H264 (Baseline)"; + } else { + return [NSString stringWithFormat:@"H264 (%@)", profileId]; + } + } else { + return self.name; + } +} + +@end diff --git a/examples/objc/AppRTCMobile/tests/ARDAppClient_xctest.mm b/examples/objc/AppRTCMobile/tests/ARDAppClient_xctest.mm index 2ec3088a8f..f332a0f346 100644 --- a/examples/objc/AppRTCMobile/tests/ARDAppClient_xctest.mm +++ b/examples/objc/AppRTCMobile/tests/ARDAppClient_xctest.mm @@ -21,7 +21,6 @@ #import "ARDAppClient+Internal.h" #import "ARDJoinResponse+Internal.h" #import "ARDMessageResponse+Internal.h" -#import "ARDSDPUtils.h" #import "ARDSettingsModel.h" @interface ARDAppClientTest : XCTestCase diff --git a/examples/objc/AppRTCMobile/tests/ARDSDPUtils_xctest.mm b/examples/objc/AppRTCMobile/tests/ARDSDPUtils_xctest.mm deleted file mode 100644 index b94f404741..0000000000 --- a/examples/objc/AppRTCMobile/tests/ARDSDPUtils_xctest.mm +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2017 The WebRTC Project Authors. All rights reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#import -#import - -#import "WebRTC/RTCSessionDescription.h" - -#import "ARDSDPUtils.h" - -@interface ARDSDPUtilsTest : XCTestCase -@end - -@implementation ARDSDPUtilsTest - -- (void)testPreferVideoCodecH264 { - NSString *sdp = @("m=video 9 RTP/SAVPF 100 116 117 96 120 97\r\n" - "a=rtpmap:120 H264/90000\r\n" - "a=rtpmap:97 H264/90000\r\n"); - NSString *expectedSdp = @("m=video 9 RTP/SAVPF 120 97 100 116 117 96\r\n" - "a=rtpmap:120 H264/90000\r\n" - "a=rtpmap:97 H264/90000\r\n"); - [self preferVideoCodec:@"H264" sdp:sdp expected:expectedSdp]; -} - -- (void)testPreferVideoCodecVP8 { - NSString *sdp = @("m=video 9 RTP/SAVPF 100 116 117 96 120 97\r\n" - "a=rtpmap:116 VP8/90000\r\n"); - NSString *expectedSdp = @("m=video 9 RTP/SAVPF 116 100 117 96 120 97\r\n" - "a=rtpmap:116 VP8/90000\r\n"); - [self preferVideoCodec:@"VP8" sdp:sdp expected:expectedSdp]; -} - -- (void)testNoMLine { - NSString *sdp = @("a=rtpmap:116 VP8/90000\r\n"); - [self preferVideoCodec:@"VP8" sdp:sdp expected:sdp]; -} - -- (void)testMissingCodec { - NSString *sdp = @("m=video 9 RTP/SAVPF 100 116 117 96 120 97\r\n" - "a=rtpmap:116 VP8/90000\r\n"); - [self preferVideoCodec:@"foo" sdp:sdp expected:sdp]; -} - -#pragma mark - Helpers - -- (void)preferVideoCodec:(NSString *)codec - sdp:(NSString *)sdp - expected:(NSString *)expectedSdp{ - RTCSessionDescription* desc = - [[RTCSessionDescription alloc] initWithType:RTCSdpTypeOffer sdp:sdp]; - RTCSessionDescription *outputDesc = - [ARDSDPUtils descriptionForDescription:desc - preferredVideoCodec:codec]; - XCTAssertTrue([outputDesc.description rangeOfString:expectedSdp].location != NSNotFound); -} -@end diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCVideoCodec.mm b/sdk/objc/Framework/Classes/PeerConnection/RTCVideoCodec.mm index df5946df81..46e6a51562 100644 --- a/sdk/objc/Framework/Classes/PeerConnection/RTCVideoCodec.mm +++ b/sdk/objc/Framework/Classes/PeerConnection/RTCVideoCodec.mm @@ -89,6 +89,18 @@ return codec; } +#pragma mark - NSCoding + +- (instancetype)initWithCoder:(NSCoder *)decoder { + return [self initWithName:[decoder decodeObjectForKey:@"name"] + parameters:[decoder decodeObjectForKey:@"parameters"]]; +} + +- (void)encodeWithCoder:(NSCoder *)encoder { + [encoder encodeObject:_name forKey:@"name"]; + [encoder encodeObject:_parameters forKey:@"parameters"]; +} + @end @implementation RTCVideoEncoderQpThresholds diff --git a/sdk/objc/Framework/Headers/WebRTC/RTCVideoCodec.h b/sdk/objc/Framework/Headers/WebRTC/RTCVideoCodec.h index ad56a5dea9..bfd768a66d 100644 --- a/sdk/objc/Framework/Headers/WebRTC/RTCVideoCodec.h +++ b/sdk/objc/Framework/Headers/WebRTC/RTCVideoCodec.h @@ -84,7 +84,7 @@ typedef NS_ENUM(NSUInteger, RTCVideoCodecMode) { /** Holds information to identify a codec. Corresponds to cricket::VideoCodec. */ RTC_EXPORT -@interface RTCVideoCodecInfo : NSObject +@interface RTCVideoCodecInfo : NSObject - (instancetype)init NS_UNAVAILABLE;