Delete RTCWrappedNativeVideoDecoder

Instead implement creating native VideoDecoder via RTCNativeVideoDecoderBuilder protocol

Bug: webrtc:15791
Change-Id: Iea66d09e01eae3b064a2943932d9a3cd33e8d19c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/340321
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Kári Helgason <kthelgason@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41824}
diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn
index 206bd13..6fa1bd2 100644
--- a/sdk/BUILD.gn
+++ b/sdk/BUILD.gn
@@ -1543,8 +1543,6 @@
         "objc/api/video_codec/RTCNativeVideoDecoder.h",
         "objc/api/video_codec/RTCNativeVideoDecoder.mm",
         "objc/api/video_codec/RTCNativeVideoDecoderBuilder+Native.h",
-        "objc/api/video_codec/RTCWrappedNativeVideoDecoder.h",
-        "objc/api/video_codec/RTCWrappedNativeVideoDecoder.mm",
         "objc/api/video_codec/RTCWrappedNativeVideoEncoder.h",
         "objc/api/video_codec/RTCWrappedNativeVideoEncoder.mm",
       ]
@@ -1558,7 +1556,7 @@
         "../api/environment",
         "../api/video_codecs:video_codecs_api",
         "../media:codec",
-        "../media:rtc_media_base",
+        "../rtc_base:checks",
       ]
     }
 
diff --git a/sdk/objc/api/video_codec/RTCNativeVideoDecoder.mm b/sdk/objc/api/video_codec/RTCNativeVideoDecoder.mm
index 8ade15b..aaad904 100644
--- a/sdk/objc/api/video_codec/RTCNativeVideoDecoder.mm
+++ b/sdk/objc/api/video_codec/RTCNativeVideoDecoder.mm
@@ -10,9 +10,10 @@
 
 #import <Foundation/Foundation.h>
 
-#import "RTCWrappedNativeVideoDecoder.h"
+#import "RTCNativeVideoDecoder.h"
 #import "base/RTCMacros.h"
 #import "helpers/NSString+StdString.h"
+#include "rtc_base/checks.h"
 
 @implementation RTC_OBJC_TYPE (RTCNativeVideoDecoder)
 
diff --git a/sdk/objc/api/video_codec/RTCVideoDecoderAV1.mm b/sdk/objc/api/video_codec/RTCVideoDecoderAV1.mm
index 81f5f93..92c5c67 100644
--- a/sdk/objc/api/video_codec/RTCVideoDecoderAV1.mm
+++ b/sdk/objc/api/video_codec/RTCVideoDecoderAV1.mm
@@ -12,16 +12,28 @@
 #import <Foundation/Foundation.h>
 
 #import "RTCMacros.h"
+#import "RTCNativeVideoDecoder.h"
+#import "RTCNativeVideoDecoderBuilder+Native.h"
 #import "RTCVideoDecoderAV1.h"
-#import "RTCWrappedNativeVideoDecoder.h"
 
 #include "modules/video_coding/codecs/av1/dav1d_decoder.h"
 
-@implementation RTC_OBJC_TYPE (RTCVideoDecoderAV1)
-
-+ (id<RTC_OBJC_TYPE(RTCVideoDecoder)>)av1Decoder {
-  return [[RTC_OBJC_TYPE(RTCWrappedNativeVideoDecoder) alloc]
-      initWithNativeDecoder:std::unique_ptr<webrtc::VideoDecoder>(webrtc::CreateDav1dDecoder())];
-}
-
+@interface RTC_OBJC_TYPE (RTCVideoDecoderAV1Builder)
+    : RTC_OBJC_TYPE(RTCNativeVideoDecoder) <RTC_OBJC_TYPE (RTCNativeVideoDecoderBuilder)>
 @end
+
+    @implementation RTC_OBJC_TYPE (RTCVideoDecoderAV1Builder)
+
+    - (std::unique_ptr<webrtc::VideoDecoder>)build:(const webrtc::Environment&)env {
+      return webrtc::CreateDav1dDecoder();
+    }
+
+    @end
+
+    @implementation RTC_OBJC_TYPE (RTCVideoDecoderAV1)
+
+    + (id<RTC_OBJC_TYPE(RTCVideoDecoder)>)av1Decoder {
+      return [[RTC_OBJC_TYPE(RTCVideoDecoderAV1Builder) alloc] init];
+    }
+
+    @end
diff --git a/sdk/objc/api/video_codec/RTCVideoDecoderVP9.mm b/sdk/objc/api/video_codec/RTCVideoDecoderVP9.mm
index 05446d4..e1f1d75 100644
--- a/sdk/objc/api/video_codec/RTCVideoDecoderVP9.mm
+++ b/sdk/objc/api/video_codec/RTCVideoDecoderVP9.mm
@@ -12,28 +12,40 @@
 #import <Foundation/Foundation.h>
 
 #import "RTCMacros.h"
+#import "RTCNativeVideoDecoder.h"
+#import "RTCNativeVideoDecoderBuilder+Native.h"
 #import "RTCVideoDecoderVP9.h"
-#import "RTCWrappedNativeVideoDecoder.h"
 
 #include "modules/video_coding/codecs/vp9/include/vp9.h"
 
-@implementation RTC_OBJC_TYPE (RTCVideoDecoderVP9)
-
-+ (id<RTC_OBJC_TYPE(RTCVideoDecoder)>)vp9Decoder {
-  std::unique_ptr<webrtc::VideoDecoder> nativeDecoder(webrtc::VP9Decoder::Create());
-  if (nativeDecoder == nullptr) {
-    return nil;
-  }
-  return [[RTC_OBJC_TYPE(RTCWrappedNativeVideoDecoder) alloc]
-      initWithNativeDecoder:std::move(nativeDecoder)];
-}
-
-+ (bool)isSupported {
-#if defined(RTC_ENABLE_VP9)
-  return true;
-#else
-  return false;
-#endif
-}
-
+@interface RTC_OBJC_TYPE (RTCVideoDecoderVP9Builder)
+    : RTC_OBJC_TYPE(RTCNativeVideoDecoder) <RTC_OBJC_TYPE (RTCNativeVideoDecoderBuilder)>
 @end
+
+    @implementation RTC_OBJC_TYPE (RTCVideoDecoderVP9Builder)
+
+    - (std::unique_ptr<webrtc::VideoDecoder>)build:(const webrtc::Environment&)env {
+      return webrtc::VP9Decoder::Create();
+    }
+
+    @end
+
+    @implementation RTC_OBJC_TYPE (RTCVideoDecoderVP9)
+
+    + (id<RTC_OBJC_TYPE(RTCVideoDecoder)>)vp9Decoder {
+#if defined(RTC_ENABLE_VP9)
+      return [[RTC_OBJC_TYPE(RTCVideoDecoderVP9Builder) alloc] init];
+#else
+      return nil;
+#endif
+    }
+
+    + (bool)isSupported {
+#if defined(RTC_ENABLE_VP9)
+      return true;
+#else
+      return false;
+#endif
+    }
+
+    @end
diff --git a/sdk/objc/api/video_codec/RTCWrappedNativeVideoDecoder.h b/sdk/objc/api/video_codec/RTCWrappedNativeVideoDecoder.h
deleted file mode 100644
index 93ffa2f..0000000
--- a/sdk/objc/api/video_codec/RTCWrappedNativeVideoDecoder.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- *  Copyright (c) 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 <Foundation/Foundation.h>
-
-#import "RTCNativeVideoDecoder.h"
-#import "base/RTCMacros.h"
-#import "base/RTCVideoDecoder.h"
-
-#include "api/video_codecs/video_decoder.h"
-#include "media/base/codec.h"
-
-// TODO: bugs.webrtc.org/15791 - Remove in favor of the RTCNativeVideoDecoderBuilder
-@interface RTC_OBJC_TYPE (RTCWrappedNativeVideoDecoder) : RTC_OBJC_TYPE (RTCNativeVideoDecoder)
-
-- (instancetype)initWithNativeDecoder:(std::unique_ptr<webrtc::VideoDecoder>)decoder;
-
-/* This moves the ownership of the wrapped decoder to the caller. */
-- (std::unique_ptr<webrtc::VideoDecoder>)releaseWrappedDecoder;
-
-@end
diff --git a/sdk/objc/api/video_codec/RTCWrappedNativeVideoDecoder.mm b/sdk/objc/api/video_codec/RTCWrappedNativeVideoDecoder.mm
deleted file mode 100644
index b812d94..0000000
--- a/sdk/objc/api/video_codec/RTCWrappedNativeVideoDecoder.mm
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- *  Copyright (c) 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 <Foundation/Foundation.h>
-
-#import "RTCWrappedNativeVideoDecoder.h"
-#import "base/RTCMacros.h"
-
-@implementation RTC_OBJC_TYPE (RTCWrappedNativeVideoDecoder) {
-  std::unique_ptr<webrtc::VideoDecoder> _wrappedDecoder;
-}
-
-- (instancetype)initWithNativeDecoder:(std::unique_ptr<webrtc::VideoDecoder>)decoder {
-  if (self = [super init]) {
-    _wrappedDecoder = std::move(decoder);
-  }
-
-  return self;
-}
-
-- (std::unique_ptr<webrtc::VideoDecoder>)releaseWrappedDecoder {
-  return std::move(_wrappedDecoder);
-}
-
-@end
diff --git a/sdk/objc/native/src/objc_video_decoder_factory.mm b/sdk/objc/native/src/objc_video_decoder_factory.mm
index 8939940..bc50892 100644
--- a/sdk/objc/native/src/objc_video_decoder_factory.mm
+++ b/sdk/objc/native/src/objc_video_decoder_factory.mm
@@ -19,7 +19,6 @@
 #import "sdk/objc/api/peerconnection/RTCEncodedImage+Private.h"
 #import "sdk/objc/api/peerconnection/RTCVideoCodecInfo+Private.h"
 #import "sdk/objc/api/video_codec/RTCNativeVideoDecoderBuilder+Native.h"
-#import "sdk/objc/api/video_codec/RTCWrappedNativeVideoDecoder.h"
 #import "sdk/objc/helpers/NSString+StdString.h"
 
 #include "api/video_codecs/sdp_video_format.h"
@@ -100,8 +99,6 @@
 
       if ([decoder conformsToProtocol:@protocol(RTC_OBJC_TYPE(RTCNativeVideoDecoderBuilder))]) {
         return [((id<RTC_OBJC_TYPE(RTCNativeVideoDecoderBuilder)>)decoder) build:env];
-      } else if ([decoder isKindOfClass:[RTC_OBJC_TYPE(RTCWrappedNativeVideoDecoder) class]]) {
-        return [(RTC_OBJC_TYPE(RTCWrappedNativeVideoDecoder) *)decoder releaseWrappedDecoder];
       } else {
         return std::unique_ptr<ObjCVideoDecoder>(new ObjCVideoDecoder(decoder));
       }