Skip to content

Commit

Permalink
add scalabilityMode for AV1.
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwebrtc committed Sep 8, 2023
1 parent a59e857 commit 7039781
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 4 deletions.
17 changes: 15 additions & 2 deletions sdk/objc/api/peerconnection/RTCVideoCodecInfo+Private.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

#import "helpers/NSString+StdString.h"

#include "absl/container/inlined_vector.h"
#include "api/video_codecs/sdp_video_format.h"
#include "modules/video_coding/svc/scalability_mode_util.h"
#include "modules/video_coding/svc/create_scalability_structure.h"

@implementation RTC_OBJC_TYPE (RTCVideoCodecInfo)
(Private)

Expand All @@ -31,8 +36,16 @@ - (instancetype)initWithNativeSdpVideoFormat : (webrtc::SdpVideoFormat)format {
std::string value = [NSString stdStringForString:self.parameters[paramKey]];
parameters[key] = value;
}

return webrtc::SdpVideoFormat([NSString stdStringForString:self.name], parameters);

absl::InlinedVector<webrtc::ScalabilityMode, webrtc::kScalabilityModeCount>
scalability_modes;
for (NSString *scalabilityMode in self.scalabilityModes) {
auto scalability_mode = webrtc::ScalabilityModeFromString([NSString stdStringForString:scalabilityMode]);
if (scalability_mode != absl::nullopt) {
scalability_modes.push_back(*scalability_mode);
}
}
return webrtc::SdpVideoFormat([NSString stdStringForString:self.name], parameters, scalability_modes);
}

@end
2 changes: 2 additions & 0 deletions sdk/objc/api/video_codec/RTCVideoEncoderAV1.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ RTC_OBJC_EXPORT

+ (bool)isSupported;

+ (NSArray<NSString *> *)scalabilityModes;

@end
16 changes: 16 additions & 0 deletions sdk/objc/api/video_codec/RTCVideoEncoderAV1.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
#import "RTCMacros.h"
#import "RTCVideoEncoderAV1.h"
#import "RTCWrappedNativeVideoEncoder.h"

#import "helpers/NSString+StdString.h"

#include "absl/container/inlined_vector.h"
#include "api/video_codecs/sdp_video_format.h"
#include "modules/video_coding/codecs/av1/av1_svc_config.h"
#include "modules/video_coding/codecs/av1/libaom_av1_encoder.h"

@implementation RTC_OBJC_TYPE (RTCVideoEncoderAV1)
Expand All @@ -28,4 +34,14 @@ + (bool)isSupported {
return true;
}

+ (NSArray<NSString *> *)scalabilityModes {
absl::InlinedVector<webrtc::ScalabilityMode, webrtc::kScalabilityModeCount>
scalability_modes = webrtc::LibaomAv1EncoderSupportedScalabilityModes();
NSMutableArray<NSString *> *scalabilityModes = [NSMutableArray array];
for (const webrtc::ScalabilityMode &scalability_mode : scalability_modes) {
[scalabilityModes addObject:[NSString stringForAbslStringView:webrtc::ScalabilityModeToString(scalability_mode)]];
}
return scalabilityModes;
}

@end
6 changes: 6 additions & 0 deletions sdk/objc/base/RTCVideoCodecInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ RTC_OBJC_EXPORT
parameters:(nullable NSDictionary<NSString *, NSString *> *)parameters
NS_DESIGNATED_INITIALIZER;

- (instancetype)initWithName:(NSString *)name
parameters:(nullable NSDictionary<NSString *, NSString *> *)parameters
scalabilityModes:(nullable NSArray<NSString *> *)scalabilityModes
NS_DESIGNATED_INITIALIZER;

- (BOOL)isEqualToCodecInfo:(RTC_OBJC_TYPE(RTCVideoCodecInfo) *)info;

@property(nonatomic, readonly) NSString *name;
@property(nonatomic, readonly) NSDictionary<NSString *, NSString *> *parameters;
@property(nonatomic, readonly) NSArray<NSString *> *scalabilityModes;

@end

Expand Down
17 changes: 16 additions & 1 deletion sdk/objc/base/RTCVideoCodecInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ @implementation RTC_OBJC_TYPE (RTCVideoCodecInfo)

@synthesize name = _name;
@synthesize parameters = _parameters;
@synthesize scalabilityModes = _scalabilityModes;

- (instancetype)initWithName:(NSString *)name {
return [self initWithName:name parameters:nil];
Expand All @@ -24,15 +25,29 @@ - (instancetype)initWithName:(NSString *)name
if (self = [super init]) {
_name = name;
_parameters = (parameters ? parameters : @{});
_scalabilityModes = @[];
}

return self;
}

- (instancetype)initWithName:(NSString *)name
parameters:(nullable NSDictionary<NSString *, NSString *> *)parameters
scalabilityModes:(nullable NSArray<NSString *> *)scalabilityModes {
if (self = [super init]) {
_name = name;
_parameters = (parameters ? parameters : @{});
_scalabilityModes = (scalabilityModes ? scalabilityModes : @[]);
}

return self;
}

- (BOOL)isEqualToCodecInfo:(RTC_OBJC_TYPE(RTCVideoCodecInfo) *)info {
if (!info ||
![self.name isEqualToString:info.name] ||
![self.parameters isEqualToDictionary:info.parameters]) {
![self.parameters isEqualToDictionary:info.parameters] ||
![self.scalabilityModes isEqualToArray:info.scalabilityModes]) {
return NO;
}
return YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ @implementation RTC_OBJC_TYPE (RTCDefaultVideoEncoderFactory)
}

#if defined(RTC_USE_LIBAOM_AV1_ENCODER)
[result addObject:[[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:kRTCVideoCodecAv1Name]];
RTC_OBJC_TYPE(RTCVideoCodecInfo) *av1Info =
[[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:kRTCVideoCodecAv1Name parameters:nil scalabilityModes:[RTCVideoEncoderAV1 scalabilityModes]];
[result addObject:av1Info];
#endif

return result;
Expand Down

0 comments on commit 7039781

Please sign in to comment.