ObjC SDK: Stop using built-in SW video codecs

This CL removes the use of default built-in SW in the ObjC layer. If a
client want to depend on the video SW codecs, they must inject them
explicitly.

Bug: webrtc:7925
Change-Id: If752e7f02109ff768dc5ec38d935203de85987c2
Reviewed-on: https://webrtc-review.googlesource.com/69800
Commit-Queue: Magnus Jedvert <magjed@webrtc.org>
Reviewed-by: Anders Carlsson <andersc@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23073}
diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCDefaultVideoDecoderFactory.m b/sdk/objc/Framework/Classes/PeerConnection/RTCDefaultVideoDecoderFactory.m
index 405e8c8..5f292c9 100644
--- a/sdk/objc/Framework/Classes/PeerConnection/RTCDefaultVideoDecoderFactory.m
+++ b/sdk/objc/Framework/Classes/PeerConnection/RTCDefaultVideoDecoderFactory.m
@@ -11,11 +11,9 @@
 #import "WebRTC/RTCVideoCodecFactory.h"
 
 #import "WebRTC/RTCVideoCodecH264.h"
-#if defined(USE_BUILTIN_SW_CODECS)
-#import "WebRTC/RTCVideoDecoderVP8.h"  // nogncheck
+#import "WebRTC/RTCVideoDecoderVP8.h"
 #if !defined(RTC_DISABLE_VP9)
-#import "WebRTC/RTCVideoDecoderVP9.h"  // nogncheck
-#endif
+#import "WebRTC/RTCVideoDecoderVP9.h"
 #endif
 
 @implementation RTCDefaultVideoDecoderFactory
@@ -23,14 +21,12 @@
 - (id<RTCVideoDecoder>)createDecoder:(RTCVideoCodecInfo *)info {
   if ([info.name isEqualToString:kRTCVideoCodecH264Name]) {
     return [[RTCVideoDecoderH264 alloc] init];
-#if defined(USE_BUILTIN_SW_CODECS)
   } else if ([info.name isEqualToString:kRTCVideoCodecVp8Name]) {
     return [RTCVideoDecoderVP8 vp8Decoder];
 #if !defined(RTC_DISABLE_VP9)
   } else if ([info.name isEqualToString:kRTCVideoCodecVp9Name]) {
     return [RTCVideoDecoderVP9 vp9Decoder];
 #endif
-#endif
   }
 
   return nil;
@@ -39,12 +35,10 @@
 - (NSArray<RTCVideoCodecInfo *> *)supportedCodecs {
   return @[
     [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecH264Name],
-#if defined(USE_BUILTIN_SW_CODECS)
     [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecVp8Name],
 #if !defined(RTC_DISABLE_VP9)
     [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecVp9Name],
 #endif
-#endif
   ];
 }
 
diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCDefaultVideoEncoderFactory.m b/sdk/objc/Framework/Classes/PeerConnection/RTCDefaultVideoEncoderFactory.m
index 60a0b5f..a4b8d71 100644
--- a/sdk/objc/Framework/Classes/PeerConnection/RTCDefaultVideoEncoderFactory.m
+++ b/sdk/objc/Framework/Classes/PeerConnection/RTCDefaultVideoEncoderFactory.m
@@ -12,11 +12,9 @@
 
 #import "WebRTC/RTCVideoCodec.h"
 #import "WebRTC/RTCVideoCodecH264.h"
-#if defined(USE_BUILTIN_SW_CODECS)
-#import "WebRTC/RTCVideoEncoderVP8.h"  // nogncheck
+#import "WebRTC/RTCVideoEncoderVP8.h"
 #if !defined(RTC_DISABLE_VP9)
-#import "WebRTC/RTCVideoEncoderVP9.h"  // nogncheck
-#endif
+#import "WebRTC/RTCVideoEncoderVP9.h"
 #endif
 
 @implementation RTCDefaultVideoEncoderFactory
@@ -42,37 +40,31 @@
       [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecH264Name
                                    parameters:constrainedBaselineParams];
 
-#if defined(USE_BUILTIN_SW_CODECS)
   RTCVideoCodecInfo *vp8Info = [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecVp8Name];
 
 #if !defined(RTC_DISABLE_VP9)
   RTCVideoCodecInfo *vp9Info = [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecVp9Name];
 #endif
-#endif
 
   return @[
     constrainedHighInfo,
     constrainedBaselineInfo,
-#if defined(USE_BUILTIN_SW_CODECS)
     vp8Info,
 #if !defined(RTC_DISABLE_VP9)
     vp9Info,
 #endif
-#endif
   ];
 }
 
 - (id<RTCVideoEncoder>)createEncoder:(RTCVideoCodecInfo *)info {
   if ([info.name isEqualToString:kRTCVideoCodecH264Name]) {
     return [[RTCVideoEncoderH264 alloc] initWithCodecInfo:info];
-#if defined(USE_BUILTIN_SW_CODECS)
   } else if ([info.name isEqualToString:kRTCVideoCodecVp8Name]) {
     return [RTCVideoEncoderVP8 vp8Encoder];
 #if !defined(RTC_DISABLE_VP9)
   } else if ([info.name isEqualToString:kRTCVideoCodecVp9Name]) {
     return [RTCVideoEncoderVP9 vp9Encoder];
 #endif
-#endif
   }
 
   return nil;
diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactory+Native.h b/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactory+Native.h
index 3b0e930..3d460fe 100644
--- a/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactory+Native.h
+++ b/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactory+Native.h
@@ -23,15 +23,6 @@
 
 }  // namespace webrtc
 
-#if defined(USE_BUILTIN_SW_CODECS)
-namespace cricket {
-
-class WebRtcVideoEncoderFactory;
-class WebRtcVideoDecoderFactory;
-
-}  // namespace cricket
-#endif
-
 NS_ASSUME_NONNULL_BEGIN
 
 /**
@@ -58,20 +49,6 @@
                             audioProcessingModule:
                                 (rtc::scoped_refptr<webrtc::AudioProcessing>)audioProcessingModule;
 
-#if defined(USE_BUILTIN_SW_CODECS)
-/* Initialize object with legacy injectable native audio/video encoder/decoder factories
-   TODO(andersc): Remove this when backwards compatiblity is no longer needed.
- */
-- (instancetype)
-    initWithNativeAudioEncoderFactory:
-        (rtc::scoped_refptr<webrtc::AudioEncoderFactory>)audioEncoderFactory
-            nativeAudioDecoderFactory:
-                (rtc::scoped_refptr<webrtc::AudioDecoderFactory>)audioDecoderFactory
-      legacyNativeVideoEncoderFactory:(cricket::WebRtcVideoEncoderFactory*)videoEncoderFactory
-      legacyNativeVideoDecoderFactory:(cricket::WebRtcVideoDecoderFactory*)videoDecoderFactory
-                    audioDeviceModule:(nullable webrtc::AudioDeviceModule *)audioDeviceModule;
-#endif
-
 @end
 
 NS_ASSUME_NONNULL_END
diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactory.mm b/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactory.mm
index 31ba49e..1ae458f 100644
--- a/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactory.mm
+++ b/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactory.mm
@@ -58,7 +58,7 @@
 - (instancetype)init {
 #ifdef HAVE_NO_MEDIA
   return [self initWithNoMedia];
-#elif !defined(USE_BUILTIN_SW_CODECS)
+#else
   return [self initWithNativeAudioEncoderFactory:webrtc::CreateBuiltinAudioEncoderFactory()
                        nativeAudioDecoderFactory:webrtc::CreateBuiltinAudioDecoderFactory()
                        nativeVideoEncoderFactory:webrtc::ObjCToNativeVideoEncoderFactory(
@@ -67,18 +67,6 @@
                                                      [[RTCVideoDecoderFactoryH264 alloc] init])
                                audioDeviceModule:nullptr
                            audioProcessingModule:nullptr];
-#else
-  // Here we construct webrtc::ObjCVideoEncoderFactory directly because we rely
-  // on the fact that they inherit from both webrtc::VideoEncoderFactory and
-  // cricket::WebRtcVideoEncoderFactory.
-  return [self initWithNativeAudioEncoderFactory:webrtc::CreateBuiltinAudioEncoderFactory()
-                       nativeAudioDecoderFactory:webrtc::CreateBuiltinAudioDecoderFactory()
-                 legacyNativeVideoEncoderFactory:new webrtc::ObjCVideoEncoderFactory(
-                                                     [[RTCVideoEncoderFactoryH264 alloc] init])
-                 legacyNativeVideoDecoderFactory:new webrtc::ObjCVideoDecoderFactory(
-                                                     [[RTCVideoDecoderFactoryH264 alloc] init])
-                               audioDeviceModule:nullptr];
-
 #endif
 }
 
@@ -151,18 +139,6 @@
   return [self initWithNoMedia];
 #else
   if (self = [self initNative]) {
-#if defined(USE_BUILTIN_SW_CODECS)
-    if (!videoEncoderFactory) {
-      auto legacy_video_encoder_factory = rtc::MakeUnique<webrtc::ObjCVideoEncoderFactory>(
-          [[RTCVideoEncoderFactoryH264 alloc] init]);
-      videoEncoderFactory = ConvertVideoEncoderFactory(std::move(legacy_video_encoder_factory));
-    }
-    if (!videoDecoderFactory) {
-      auto legacy_video_decoder_factory = rtc::MakeUnique<webrtc::ObjCVideoDecoderFactory>(
-          [[RTCVideoDecoderFactoryH264 alloc] init]);
-      videoDecoderFactory = ConvertVideoDecoderFactory(std::move(legacy_video_decoder_factory));
-    }
-#endif
     _nativeFactory = webrtc::CreatePeerConnectionFactory(_networkThread.get(),
                                                          _workerThread.get(),
                                                          _signalingThread.get(),
@@ -179,34 +155,6 @@
 #endif
 }
 
-#if defined(USE_BUILTIN_SW_CODECS)
-- (instancetype)
-    initWithNativeAudioEncoderFactory:
-        (rtc::scoped_refptr<webrtc::AudioEncoderFactory>)audioEncoderFactory
-            nativeAudioDecoderFactory:
-                (rtc::scoped_refptr<webrtc::AudioDecoderFactory>)audioDecoderFactory
-      legacyNativeVideoEncoderFactory:(cricket::WebRtcVideoEncoderFactory *)videoEncoderFactory
-      legacyNativeVideoDecoderFactory:(cricket::WebRtcVideoDecoderFactory *)videoDecoderFactory
-                    audioDeviceModule:(nullable webrtc::AudioDeviceModule *)audioDeviceModule {
-#ifdef HAVE_NO_MEDIA
-  return [self initWithNoMedia];
-#else
-  if (self = [self initNative]) {
-    _nativeFactory = webrtc::CreatePeerConnectionFactory(_networkThread.get(),
-                                                         _workerThread.get(),
-                                                         _signalingThread.get(),
-                                                         audioDeviceModule,
-                                                         audioEncoderFactory,
-                                                         audioDecoderFactory,
-                                                         videoEncoderFactory,
-                                                         videoDecoderFactory);
-    NSAssert(_nativeFactory, @"Failed to initialize PeerConnectionFactory!");
-  }
-  return self;
-#endif
-}
-#endif
-
 - (RTCAudioSource *)audioSourceWithConstraints:(nullable RTCMediaConstraints *)constraints {
   std::unique_ptr<webrtc::MediaConstraints> nativeConstraints;
   if (constraints) {
diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCVideoCodec+Private.h b/sdk/objc/Framework/Classes/PeerConnection/RTCVideoCodec+Private.h
index 97ee513..4a2cf52 100644
--- a/sdk/objc/Framework/Classes/PeerConnection/RTCVideoCodec+Private.h
+++ b/sdk/objc/Framework/Classes/PeerConnection/RTCVideoCodec+Private.h
@@ -53,10 +53,6 @@
 - (instancetype)initWithNativeSdpVideoFormat:(webrtc::SdpVideoFormat)format;
 - (webrtc::SdpVideoFormat)nativeSdpVideoFormat;
 
-/* TODO(andersc): These are deprecated, remove when no longer in use. */
-- (instancetype)initWithNativeVideoCodec:(cricket::VideoCodec)videoCodec;
-- (cricket::VideoCodec)nativeVideoCodec;
-
 @end
 
 NS_ASSUME_NONNULL_END
diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCVideoCodec.mm b/sdk/objc/Framework/Classes/PeerConnection/RTCVideoCodec.mm
index fc2c1ce..63be2dc 100644
--- a/sdk/objc/Framework/Classes/PeerConnection/RTCVideoCodec.mm
+++ b/sdk/objc/Framework/Classes/PeerConnection/RTCVideoCodec.mm
@@ -105,11 +105,6 @@
   return [self initWithName:[NSString stringForStdString:format.name] parameters:params];
 }
 
-- (instancetype)initWithNativeVideoCodec:(cricket::VideoCodec)videoCodec {
-  return [self
-      initWithNativeSdpVideoFormat:webrtc::SdpVideoFormat(videoCodec.name, videoCodec.params)];
-}
-
 - (BOOL)isEqualToCodecInfo:(RTCVideoCodecInfo *)info {
   if (!info ||
       ![self.name isEqualToString:info.name] ||
@@ -142,16 +137,6 @@
   return webrtc::SdpVideoFormat([NSString stdStringForString:_name], parameters);
 }
 
-- (cricket::VideoCodec)nativeVideoCodec {
-  cricket::VideoCodec codec([NSString stdStringForString:_name]);
-  for (NSString *paramKey in _parameters.allKeys) {
-    codec.SetParam([NSString stdStringForString:paramKey],
-                   [NSString stdStringForString:_parameters[paramKey]]);
-  }
-
-  return codec;
-}
-
 #pragma mark - NSCoding
 
 - (instancetype)initWithCoder:(NSCoder *)decoder {
diff --git a/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoEncoderH264.mm b/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoEncoderH264.mm
index 3289f01..ffdbd9d 100644
--- a/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoEncoderH264.mm
+++ b/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoEncoderH264.mm
@@ -167,8 +167,8 @@
                                 rotation:encodeParams->rotation];
 }
 
-// Extract VideoToolbox profile out of the cricket::VideoCodec. If there is no
-// specific VideoToolbox profile for the specified level, AutoLevel will be
+// Extract VideoToolbox profile out of the webrtc::SdpVideoFormat. If there is
+// no specific VideoToolbox profile for the specified level, AutoLevel will be
 // returned. The user must initialize the encoder with a resolution and
 // framerate conforming to the selected H264 level regardless.
 CFStringRef ExtractProfile(webrtc::SdpVideoFormat videoFormat) {