diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn index bcd8056cfc..7a630a9e66 100644 --- a/sdk/BUILD.gn +++ b/sdk/BUILD.gn @@ -646,6 +646,7 @@ if (is_ios || is_mac) { ] deps = [ + ":av1", ":base_objc", ":native_video", ":videocodec_objc", @@ -704,6 +705,25 @@ if (is_ios || is_mac) { ] } + rtc_library("av1") { + visibility = [ "*" ] + allow_poison = [ "software_video_codecs" ] + sources = [ + "objc/api/video_codec/RTCVideoDecoderAV1.h", + "objc/api/video_codec/RTCVideoDecoderAV1.mm", + "objc/api/video_codec/RTCVideoEncoderAV1.h", + "objc/api/video_codec/RTCVideoEncoderAV1.mm", + ] + + deps = [ + ":base_objc", + ":wrapped_native_codec_objc", + "../media:rtc_media_base", + "../modules/video_coding/codecs/av1:libaom_av1_decoder", + "../modules/video_coding/codecs/av1:libaom_av1_encoder", + ] + } + # Build the PeerConnectionFactory without audio/video support. # This target depends on the objc_peeerconnectionfactory_base which still # includes some audio/video related objects such as RTCAudioSource because @@ -1261,8 +1281,10 @@ if (is_ios || is_mac) { "objc/api/video_codec/RTCVideoCodecConstants.h", "objc/api/video_codec/RTCVideoDecoderVP8.h", "objc/api/video_codec/RTCVideoDecoderVP9.h", + "objc/api/video_codec/RTCVideoDecoderAV1.h", "objc/api/video_codec/RTCVideoEncoderVP8.h", "objc/api/video_codec/RTCVideoEncoderVP9.h", + "objc/api/video_codec/RTCVideoEncoderAV1.h", "objc/api/video_frame_buffer/RTCNativeI420Buffer.h", "objc/api/video_frame_buffer/RTCNativeMutableI420Buffer.h", ] @@ -1368,8 +1390,10 @@ if (is_ios || is_mac) { "objc/api/peerconnection/RTCTracing.h", "objc/api/peerconnection/RTCVideoSource.h", "objc/api/peerconnection/RTCVideoTrack.h", + "objc/api/video_codec/RTCVideoDecoderAV1.h", "objc/api/video_codec/RTCVideoDecoderVP8.h", "objc/api/video_codec/RTCVideoDecoderVP9.h", + "objc/api/video_codec/RTCVideoEncoderAV1.h", "objc/api/video_codec/RTCVideoEncoderVP8.h", "objc/api/video_codec/RTCVideoEncoderVP9.h", "objc/api/video_frame_buffer/RTCNativeI420Buffer.h", diff --git a/sdk/objc/api/video_codec/RTCVideoCodecConstants.h b/sdk/objc/api/video_codec/RTCVideoCodecConstants.h index 03f36e22ca..8b17a75aef 100644 --- a/sdk/objc/api/video_codec/RTCVideoCodecConstants.h +++ b/sdk/objc/api/video_codec/RTCVideoCodecConstants.h @@ -12,5 +12,6 @@ #import "RTCMacros.h" -RTC_OBJC_EXPORT extern NSString* const kRTCVideoCodecVp8Name; -RTC_OBJC_EXPORT extern NSString* const kRTCVideoCodecVp9Name; +RTC_EXTERN NSString* const kRTCVideoCodecVp8Name; +RTC_EXTERN NSString* const kRTCVideoCodecVp9Name; +RTC_EXTERN NSString* const kRTCVideoCodecAv1Name; diff --git a/sdk/objc/api/video_codec/RTCVideoCodecConstants.mm b/sdk/objc/api/video_codec/RTCVideoCodecConstants.mm index 3de6e22ef7..1ab236a2c2 100644 --- a/sdk/objc/api/video_codec/RTCVideoCodecConstants.mm +++ b/sdk/objc/api/video_codec/RTCVideoCodecConstants.mm @@ -15,3 +15,4 @@ NSString *const kRTCVideoCodecVp8Name = @(cricket::kVp8CodecName); NSString *const kRTCVideoCodecVp9Name = @(cricket::kVp9CodecName); +NSString *const kRTCVideoCodecAv1Name = @(cricket::kAv1CodecName); diff --git a/sdk/objc/api/video_codec/RTCVideoDecoderAV1.h b/sdk/objc/api/video_codec/RTCVideoDecoderAV1.h new file mode 100644 index 0000000000..d618237970 --- /dev/null +++ b/sdk/objc/api/video_codec/RTCVideoDecoderAV1.h @@ -0,0 +1,27 @@ +/* + * Copyright 2021 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 "RTCMacros.h" +#import "RTCVideoDecoder.h" + +RTC_OBJC_EXPORT +@interface RTC_OBJC_TYPE (RTCVideoDecoderAV1) : NSObject + +/* This returns a AV1 decoder that can be returned from a RTCVideoDecoderFactory injected into + * RTCPeerConnectionFactory. Even though it implements the RTCVideoDecoder protocol, it can not be + * used independently from the RTCPeerConnectionFactory. + */ ++ (id)av1Decoder; + ++ (bool)isSupported; + +@end diff --git a/sdk/objc/api/video_codec/RTCVideoDecoderAV1.mm b/sdk/objc/api/video_codec/RTCVideoDecoderAV1.mm new file mode 100644 index 0000000000..cc40f5af85 --- /dev/null +++ b/sdk/objc/api/video_codec/RTCVideoDecoderAV1.mm @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2021 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 "RTCMacros.h" +#import "RTCVideoDecoderAV1.h" +#import "RTCWrappedNativeVideoDecoder.h" + +#include "modules/video_coding/codecs/av1/libaom_av1_decoder.h" + +@implementation RTC_OBJC_TYPE (RTCVideoDecoderAV1) + ++ (id)av1Decoder { + std::unique_ptr nativeDecoder(webrtc::CreateLibaomAv1Decoder()); + if (nativeDecoder == nullptr) { + return nil; + } + return [[RTC_OBJC_TYPE(RTCWrappedNativeVideoDecoder) alloc] + initWithNativeDecoder:std::move(nativeDecoder)]; +} + ++ (bool)isSupported { + return webrtc::kIsLibaomAv1DecoderSupported; +} + +@end diff --git a/sdk/objc/api/video_codec/RTCVideoDecoderVP9.h b/sdk/objc/api/video_codec/RTCVideoDecoderVP9.h index b3a1743057..de7e62012b 100644 --- a/sdk/objc/api/video_codec/RTCVideoDecoderVP9.h +++ b/sdk/objc/api/video_codec/RTCVideoDecoderVP9.h @@ -22,4 +22,6 @@ RTC_OBJC_EXPORT */ + (id)vp9Decoder; ++ (bool)isSupported; + @end diff --git a/sdk/objc/api/video_codec/RTCVideoDecoderVP9.mm b/sdk/objc/api/video_codec/RTCVideoDecoderVP9.mm index a44a870850..05446d436d 100644 --- a/sdk/objc/api/video_codec/RTCVideoDecoderVP9.mm +++ b/sdk/objc/api/video_codec/RTCVideoDecoderVP9.mm @@ -20,8 +20,20 @@ @implementation RTC_OBJC_TYPE (RTCVideoDecoderVP9) + (id)vp9Decoder { + std::unique_ptr nativeDecoder(webrtc::VP9Decoder::Create()); + if (nativeDecoder == nullptr) { + return nil; + } return [[RTC_OBJC_TYPE(RTCWrappedNativeVideoDecoder) alloc] - initWithNativeDecoder:std::unique_ptr(webrtc::VP9Decoder::Create())]; + initWithNativeDecoder:std::move(nativeDecoder)]; +} + ++ (bool)isSupported { +#if defined(RTC_ENABLE_VP9) + return true; +#else + return false; +#endif } @end diff --git a/sdk/objc/api/video_codec/RTCVideoEncoderAV1.h b/sdk/objc/api/video_codec/RTCVideoEncoderAV1.h new file mode 100644 index 0000000000..8aa55e4bfa --- /dev/null +++ b/sdk/objc/api/video_codec/RTCVideoEncoderAV1.h @@ -0,0 +1,27 @@ +/* + * Copyright 2021 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 "RTCMacros.h" +#import "RTCVideoEncoder.h" + +RTC_OBJC_EXPORT +@interface RTC_OBJC_TYPE (RTCVideoEncoderAV1) : NSObject + +/* This returns a AV1 encoder that can be returned from a RTCVideoEncoderFactory injected into + * RTCPeerConnectionFactory. Even though it implements the RTCVideoEncoder protocol, it can not be + * used independently from the RTCPeerConnectionFactory. + */ ++ (id)av1Encoder; + ++ (bool)isSupported; + +@end diff --git a/sdk/objc/api/video_codec/RTCVideoEncoderAV1.mm b/sdk/objc/api/video_codec/RTCVideoEncoderAV1.mm new file mode 100644 index 0000000000..92e924a475 --- /dev/null +++ b/sdk/objc/api/video_codec/RTCVideoEncoderAV1.mm @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2021 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 "RTCMacros.h" +#import "RTCVideoEncoderAV1.h" +#import "RTCWrappedNativeVideoEncoder.h" + +#include "modules/video_coding/codecs/av1/libaom_av1_encoder.h" + +@implementation RTC_OBJC_TYPE (RTCVideoEncoderAV1) + ++ (id)av1Encoder { + std::unique_ptr nativeEncoder(webrtc::CreateLibaomAv1Encoder()); + if (nativeEncoder == nullptr) { + return nil; + } + return [[RTC_OBJC_TYPE(RTCWrappedNativeVideoEncoder) alloc] + initWithNativeEncoder:std::move(nativeEncoder)]; +} + ++ (bool)isSupported { + return webrtc::kIsLibaomAv1EncoderSupported; +} + +@end diff --git a/sdk/objc/api/video_codec/RTCVideoEncoderVP9.h b/sdk/objc/api/video_codec/RTCVideoEncoderVP9.h index 8f961ef337..f7dac6117d 100644 --- a/sdk/objc/api/video_codec/RTCVideoEncoderVP9.h +++ b/sdk/objc/api/video_codec/RTCVideoEncoderVP9.h @@ -22,4 +22,6 @@ RTC_OBJC_EXPORT */ + (id)vp9Encoder; ++ (bool)isSupported; + @end diff --git a/sdk/objc/api/video_codec/RTCVideoEncoderVP9.mm b/sdk/objc/api/video_codec/RTCVideoEncoderVP9.mm index 736051cff9..18a9353f7e 100644 --- a/sdk/objc/api/video_codec/RTCVideoEncoderVP9.mm +++ b/sdk/objc/api/video_codec/RTCVideoEncoderVP9.mm @@ -20,8 +20,20 @@ @implementation RTC_OBJC_TYPE (RTCVideoEncoderVP9) + (id)vp9Encoder { + std::unique_ptr nativeEncoder(webrtc::VP9Encoder::Create()); + if (nativeEncoder == nullptr) { + return nil; + } return [[RTC_OBJC_TYPE(RTCWrappedNativeVideoEncoder) alloc] - initWithNativeEncoder:std::unique_ptr(webrtc::VP9Encoder::Create())]; + initWithNativeEncoder:std::move(nativeEncoder)]; +} + ++ (bool)isSupported { +#if defined(RTC_ENABLE_VP9) + return true; +#else + return false; +#endif } @end diff --git a/sdk/objc/components/video_codec/RTCDefaultVideoDecoderFactory.m b/sdk/objc/components/video_codec/RTCDefaultVideoDecoderFactory.m index 4046cfedbe..f4a97a8659 100644 --- a/sdk/objc/components/video_codec/RTCDefaultVideoDecoderFactory.m +++ b/sdk/objc/components/video_codec/RTCDefaultVideoDecoderFactory.m @@ -13,11 +13,10 @@ #import "RTCH264ProfileLevelId.h" #import "RTCVideoDecoderH264.h" #import "api/video_codec/RTCVideoCodecConstants.h" +#import "api/video_codec/RTCVideoDecoderAV1.h" #import "api/video_codec/RTCVideoDecoderVP8.h" -#import "base/RTCVideoCodecInfo.h" -#if defined(RTC_ENABLE_VP9) #import "api/video_codec/RTCVideoDecoderVP9.h" -#endif +#import "base/RTCVideoCodecInfo.h" @implementation RTC_OBJC_TYPE (RTCDefaultVideoDecoderFactory) @@ -43,19 +42,23 @@ RTC_OBJC_TYPE(RTCVideoCodecInfo) *vp8Info = [[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:kRTCVideoCodecVp8Name]; -#if defined(RTC_ENABLE_VP9) - RTC_OBJC_TYPE(RTCVideoCodecInfo) *vp9Info = - [[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:kRTCVideoCodecVp9Name]; -#endif - - return @[ + NSMutableArray *result = [@[ constrainedHighInfo, constrainedBaselineInfo, vp8Info, -#if defined(RTC_ENABLE_VP9) - vp9Info, -#endif - ]; + ] mutableCopy]; + + if ([RTC_OBJC_TYPE(RTCVideoDecoderVP9) isSupported]) { + [result + addObject:[[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:kRTCVideoCodecVp9Name]]; + } + + if ([RTC_OBJC_TYPE(RTCVideoDecoderAV1) isSupported]) { + [result + addObject:[[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:kRTCVideoCodecAv1Name]]; + } + + return result; } - (id)createDecoder:(RTC_OBJC_TYPE(RTCVideoCodecInfo) *)info { @@ -63,10 +66,12 @@ return [[RTC_OBJC_TYPE(RTCVideoDecoderH264) alloc] init]; } else if ([info.name isEqualToString:kRTCVideoCodecVp8Name]) { return [RTC_OBJC_TYPE(RTCVideoDecoderVP8) vp8Decoder]; -#if defined(RTC_ENABLE_VP9) - } else if ([info.name isEqualToString:kRTCVideoCodecVp9Name]) { + } else if ([info.name isEqualToString:kRTCVideoCodecVp9Name] && + [RTC_OBJC_TYPE(RTCVideoDecoderVP9) isSupported]) { return [RTC_OBJC_TYPE(RTCVideoDecoderVP9) vp9Decoder]; -#endif + } else if ([info.name isEqualToString:kRTCVideoCodecAv1Name] && + [RTC_OBJC_TYPE(RTCVideoDecoderAV1) isSupported]) { + return [RTC_OBJC_TYPE(RTCVideoDecoderAV1) av1Decoder]; } return nil; diff --git a/sdk/objc/components/video_codec/RTCDefaultVideoEncoderFactory.m b/sdk/objc/components/video_codec/RTCDefaultVideoEncoderFactory.m index 35a1407f38..06c4e8c22f 100644 --- a/sdk/objc/components/video_codec/RTCDefaultVideoEncoderFactory.m +++ b/sdk/objc/components/video_codec/RTCDefaultVideoEncoderFactory.m @@ -13,11 +13,10 @@ #import "RTCH264ProfileLevelId.h" #import "RTCVideoEncoderH264.h" #import "api/video_codec/RTCVideoCodecConstants.h" +#import "api/video_codec/RTCVideoEncoderAV1.h" #import "api/video_codec/RTCVideoEncoderVP8.h" -#import "base/RTCVideoCodecInfo.h" -#if defined(RTC_ENABLE_VP9) #import "api/video_codec/RTCVideoEncoderVP9.h" -#endif +#import "base/RTCVideoCodecInfo.h" @implementation RTC_OBJC_TYPE (RTCDefaultVideoEncoderFactory) @@ -45,19 +44,23 @@ RTC_OBJC_TYPE(RTCVideoCodecInfo) *vp8Info = [[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:kRTCVideoCodecVp8Name]; -#if defined(RTC_ENABLE_VP9) - RTC_OBJC_TYPE(RTCVideoCodecInfo) *vp9Info = - [[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:kRTCVideoCodecVp9Name]; -#endif - - return @[ + NSMutableArray *result = [@[ constrainedHighInfo, constrainedBaselineInfo, vp8Info, -#if defined(RTC_ENABLE_VP9) - vp9Info, -#endif - ]; + ] mutableCopy]; + + if ([RTC_OBJC_TYPE(RTCVideoEncoderVP9) isSupported]) { + [result + addObject:[[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:kRTCVideoCodecVp9Name]]; + } + + if ([RTC_OBJC_TYPE(RTCVideoEncoderAV1) isSupported]) { + [result + addObject:[[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:kRTCVideoCodecAv1Name]]; + } + + return result; } - (id)createEncoder:(RTC_OBJC_TYPE(RTCVideoCodecInfo) *)info { @@ -65,10 +68,12 @@ return [[RTC_OBJC_TYPE(RTCVideoEncoderH264) alloc] initWithCodecInfo:info]; } else if ([info.name isEqualToString:kRTCVideoCodecVp8Name]) { return [RTC_OBJC_TYPE(RTCVideoEncoderVP8) vp8Encoder]; -#if defined(RTC_ENABLE_VP9) - } else if ([info.name isEqualToString:kRTCVideoCodecVp9Name]) { + } else if ([info.name isEqualToString:kRTCVideoCodecVp9Name] && + [RTC_OBJC_TYPE(RTCVideoEncoderVP9) isSupported]) { return [RTC_OBJC_TYPE(RTCVideoEncoderVP9) vp9Encoder]; -#endif + } else if ([info.name isEqualToString:kRTCVideoCodecAv1Name] && + [RTC_OBJC_TYPE(RTCVideoEncoderAV1) isSupported]) { + return [RTC_OBJC_TYPE(RTCVideoEncoderAV1) av1Encoder]; } return nil;