Skip to content

Commit

Permalink
Simple Default ObjC video codec factories.
Browse files Browse the repository at this point in the history
Move the simple video encoder/decoder factory from AppRTCMobile into the
public API so users who don't have special requirements for video codecs
can easily get started.

Also clean up the API a little.

This CL replaces the more flexible default factories in
https://webrtc-review.googlesource.com/c/src/+/7741 and clients that
want to implement their own codecs will have to supply their own
encoder/decoder factories as well. The benefits of the approach in
this CL are a simpler API and less effects on the rest of the code.

Bug: None
Change-Id: I4ed94090d778b4fc38b49864de1d4de4ff125d6a
Reviewed-on: https://webrtc-review.googlesource.com/15141
Reviewed-by: Kári Helgason <[email protected]>
Reviewed-by: Magnus Jedvert <[email protected]>
Commit-Queue: Anders Carlsson <[email protected]>
Cr-Commit-Position: refs/heads/master@{#20441}
  • Loading branch information
Anders Carlsson authored and Commit Bot committed Oct 26, 2017
1 parent a056599 commit 30915a7
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 80 deletions.
4 changes: 0 additions & 4 deletions examples/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,6 @@ if (is_ios || (is_mac && target_cpu != "x86")) {
"objc/AppRTCMobile/ARDTURNClient+Internal.h",
"objc/AppRTCMobile/ARDTURNClient.h",
"objc/AppRTCMobile/ARDTURNClient.m",
"objc/AppRTCMobile/ARDVideoDecoderFactory.h",
"objc/AppRTCMobile/ARDVideoDecoderFactory.m",
"objc/AppRTCMobile/ARDVideoEncoderFactory.h",
"objc/AppRTCMobile/ARDVideoEncoderFactory.m",
"objc/AppRTCMobile/ARDWebSocketChannel.h",
"objc/AppRTCMobile/ARDWebSocketChannel.m",
"objc/AppRTCMobile/RTCIceCandidate+JSON.h",
Expand Down
7 changes: 3 additions & 4 deletions examples/objc/AppRTCMobile/ARDAppClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#import "WebRTC/RTCPeerConnectionFactory.h"
#import "WebRTC/RTCRtpSender.h"
#import "WebRTC/RTCTracing.h"
#import "WebRTC/RTCVideoCodecFactory.h"
#import "WebRTC/RTCVideoTrack.h"

#import "ARDAppEngineClient.h"
Expand All @@ -32,8 +33,6 @@
#import "ARDSignalingMessage.h"
#import "ARDTURNClient+Internal.h"
#import "ARDUtilities.h"
#import "ARDVideoDecoderFactory.h"
#import "ARDVideoEncoderFactory.h"
#import "ARDWebSocketChannel.h"
#import "RTCIceCandidate+JSON.h"
#import "RTCSessionDescription+JSON.h"
Expand Down Expand Up @@ -221,8 +220,8 @@ - (void)connectToRoomWithId:(NSString *)roomId
_isLoopback = isLoopback;
self.state = kARDAppClientStateConnecting;

ARDVideoDecoderFactory *decoderFactory = [[ARDVideoDecoderFactory alloc] init];
ARDVideoEncoderFactory *encoderFactory = [[ARDVideoEncoderFactory alloc] init];
RTCDefaultVideoDecoderFactory *decoderFactory = [[RTCDefaultVideoDecoderFactory alloc] init];
RTCDefaultVideoEncoderFactory *encoderFactory = [[RTCDefaultVideoEncoderFactory alloc] init];
encoderFactory.preferredCodec = [settings currentVideoCodecSettingFromStore];
_factory = [[RTCPeerConnectionFactory alloc] initWithEncoderFactory:encoderFactory
decoderFactory:decoderFactory];
Expand Down
6 changes: 2 additions & 4 deletions examples/objc/AppRTCMobile/ARDSettingsModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

#import "ARDSettingsModel+Private.h"
#import "ARDSettingsStore.h"
#import "ARDVideoEncoderFactory.h"
#import "WebRTC/RTCCameraVideoCapturer.h"
#import "WebRTC/RTCMediaConstraints.h"
#import "WebRTC/RTCVideoCodecFactory.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -66,9 +66,7 @@ - (BOOL)storeVideoResolutionSetting:(NSString *)resolution {
}

- (NSArray<RTCVideoCodecInfo *> *)availableVideoCodecs {
NSArray<RTCVideoCodecInfo *> *supportedCodecs =
[[[ARDVideoEncoderFactory alloc] init] supportedCodecs];
return supportedCodecs;
return [RTCDefaultVideoEncoderFactory supportedCodecs];
}

- (RTCVideoCodecInfo *)currentVideoCodecSettingFromStore {
Expand Down
16 changes: 0 additions & 16 deletions examples/objc/AppRTCMobile/ARDVideoDecoderFactory.h

This file was deleted.

18 changes: 0 additions & 18 deletions examples/objc/AppRTCMobile/ARDVideoEncoderFactory.h

This file was deleted.

2 changes: 2 additions & 0 deletions sdk/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ if (is_ios || is_mac) {
"objc/Framework/Classes/PeerConnection/RTCDataChannel.mm",
"objc/Framework/Classes/PeerConnection/RTCDataChannelConfiguration+Private.h",
"objc/Framework/Classes/PeerConnection/RTCDataChannelConfiguration.mm",
"objc/Framework/Classes/PeerConnection/RTCDefaultVideoDecoderFactory.m",
"objc/Framework/Classes/PeerConnection/RTCDefaultVideoEncoderFactory.m",
"objc/Framework/Classes/PeerConnection/RTCEncodedImage.mm",
"objc/Framework/Classes/PeerConnection/RTCIceCandidate+Private.h",
"objc/Framework/Classes/PeerConnection/RTCIceCandidate.mm",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
* be found in the AUTHORS file in the root of the source tree.
*/

#import "ARDVideoDecoderFactory.h"
#import "WebRTC/RTCVideoCodecFactory.h"

#import "WebRTC/RTCVideoCodecH264.h"
#import "WebRTC/RTCVideoDecoderVP8.h"
#import "WebRTC/RTCVideoDecoderVP9.h"

@implementation ARDVideoDecoderFactory
@implementation RTCDefaultVideoDecoderFactory

- (id<RTCVideoDecoder>)createDecoder:(RTCVideoCodecInfo *)info {
if ([info.name isEqualToString:@"H264"]) {
if ([info.name isEqualToString:kRTCVideoCodecH264Name]) {
return [[RTCVideoDecoderH264 alloc] init];
} else if ([info.name isEqualToString:@"VP8"]) {
} else if ([info.name isEqualToString:kRTCVideoCodecVp8Name]) {
return [RTCVideoDecoderVP8 vp8Decoder];
} else if ([info.name isEqualToString:@"VP9"]) {
} else if ([info.name isEqualToString:kRTCVideoCodecVp9Name]) {
return [RTCVideoDecoderVP9 vp9Decoder];
}

Expand All @@ -30,9 +30,9 @@ @implementation ARDVideoDecoderFactory

- (NSArray<RTCVideoCodecInfo *> *)supportedCodecs {
return @[
[[RTCVideoCodecInfo alloc] initWithName:@"H264" parameters:nil],
[[RTCVideoCodecInfo alloc] initWithName:@"VP8" parameters:nil],
[[RTCVideoCodecInfo alloc] initWithName:@"VP9" parameters:nil]
[[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecH264Name],
[[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecVp8Name],
[[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecVp9Name]
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,18 @@
* be found in the AUTHORS file in the root of the source tree.
*/

#import "ARDVideoEncoderFactory.h"
#import "WebRTC/RTCVideoCodecFactory.h"

#import "ARDSettingsModel.h"
#import "WebRTC/RTCVideoCodec.h"
#import "WebRTC/RTCVideoCodecH264.h"
#import "WebRTC/RTCVideoEncoderVP8.h"
#import "WebRTC/RTCVideoEncoderVP9.h"

@implementation ARDVideoEncoderFactory
@implementation RTCDefaultVideoEncoderFactory

@synthesize preferredCodec;

- (id<RTCVideoEncoder>)createEncoder:(RTCVideoCodecInfo *)info {
if ([info.name isEqualToString:kRTCVideoCodecH264Name]) {
return [[RTCVideoEncoderH264 alloc] initWithCodecInfo:info];
} else if ([info.name isEqualToString:kRTCVideoCodecVp8Name]) {
return [RTCVideoEncoderVP8 vp8Encoder];
} else if ([info.name isEqualToString:kRTCVideoCodecVp9Name]) {
return [RTCVideoEncoderVP9 vp9Encoder];
}

return nil;
}

- (NSArray<RTCVideoCodecInfo *> *)supportedCodecs {
NSMutableArray<RTCVideoCodecInfo *> *codecs = [NSMutableArray array];

+ (NSArray<RTCVideoCodecInfo *> *)supportedCodecs {
NSDictionary<NSString *, NSString *> *constrainedHighParams = @{
@"profile-level-id" : kRTCLevel31ConstrainedHigh,
@"level-asymmetry-allowed" : @"1",
Expand All @@ -43,7 +28,6 @@ @implementation ARDVideoEncoderFactory
RTCVideoCodecInfo *constrainedHighInfo =
[[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecH264Name
parameters:constrainedHighParams];
[codecs addObject:constrainedHighInfo];

NSDictionary<NSString *, NSString *> *constrainedBaselineParams = @{
@"profile-level-id" : kRTCLevel31ConstrainedBaseline,
Expand All @@ -53,15 +37,28 @@ @implementation ARDVideoEncoderFactory
RTCVideoCodecInfo *constrainedBaselineInfo =
[[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecH264Name
parameters:constrainedBaselineParams];
[codecs addObject:constrainedBaselineInfo];

RTCVideoCodecInfo *vp8Info =
[[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecVp8Name parameters:nil];
[codecs addObject:vp8Info];
RTCVideoCodecInfo *vp8Info = [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecVp8Name];

RTCVideoCodecInfo *vp9Info = [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecVp9Name];

RTCVideoCodecInfo *vp9Info =
[[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecVp9Name parameters:nil];
[codecs addObject:vp9Info];
return @[ constrainedHighInfo, constrainedBaselineInfo, vp8Info, vp9Info ];
}

- (id<RTCVideoEncoder>)createEncoder:(RTCVideoCodecInfo *)info {
if ([info.name isEqualToString:kRTCVideoCodecH264Name]) {
return [[RTCVideoEncoderH264 alloc] initWithCodecInfo:info];
} else if ([info.name isEqualToString:kRTCVideoCodecVp8Name]) {
return [RTCVideoEncoderVP8 vp8Encoder];
} else if ([info.name isEqualToString:kRTCVideoCodecVp9Name]) {
return [RTCVideoEncoderVP9 vp9Encoder];
}

return nil;
}

- (NSArray<RTCVideoCodecInfo *> *)supportedCodecs {
NSMutableArray<RTCVideoCodecInfo *> *codecs = [[[self class] supportedCodecs] mutableCopy];

NSMutableArray<RTCVideoCodecInfo *> *orderedCodecs = [NSMutableArray array];
NSUInteger index = [codecs indexOfObject:self.preferredCodec];
Expand Down
18 changes: 18 additions & 0 deletions sdk/objc/Framework/Headers/WebRTC/RTCVideoCodecFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,22 @@ RTC_EXPORT

@end

#pragma mark - Default factories

/** These codec factories include support for all codecs bundled with WebRTC. If using custom
* codecs, create custom implementations of RTCVideoEncoderFactory and RTCVideoDecoderFactory.
*/
RTC_EXPORT
@interface RTCDefaultVideoEncoderFactory : NSObject <RTCVideoEncoderFactory>

@property(nonatomic, retain) RTCVideoCodecInfo *preferredCodec;

+ (NSArray<RTCVideoCodecInfo *> *)supportedCodecs;

@end

RTC_EXPORT
@interface RTCDefaultVideoDecoderFactory : NSObject <RTCVideoDecoderFactory>
@end

NS_ASSUME_NONNULL_END

0 comments on commit 30915a7

Please sign in to comment.