Migrate objc VideoEncoders to RTCNativeBideoEncoderBuilder protocol

Bug: webrtc:15860
Change-Id: Iace411b2768cc788a5e6e8bab194267ed5a7dcec
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/343741
Reviewed-by: Kári Helgason <kthelgason@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41995}
This commit is contained in:
Danil Chapovalov 2024-03-21 16:46:42 +01:00 committed by WebRTC LUCI CQ
parent 0b83b2cbb4
commit 424342d8ee
8 changed files with 76 additions and 122 deletions

View File

@ -786,7 +786,6 @@ if (is_ios || is_mac) {
deps = [
":base_objc",
":wrapped_native_codec_objc",
"../media:rtc_media_base",
"../modules/video_coding:webrtc_vp9",
]
}
@ -818,7 +817,6 @@ if (is_ios || is_mac) {
deps = [
":base_objc",
":wrapped_native_codec_objc",
"../media:rtc_media_base",
"../modules/video_coding/codecs/av1:libaom_av1_encoder",
]
}
@ -1546,8 +1544,6 @@ if (is_ios || is_mac) {
"objc/api/video_codec/RTCNativeVideoEncoder.h",
"objc/api/video_codec/RTCNativeVideoEncoder.mm",
"objc/api/video_codec/RTCNativeVideoEncoderBuilder+Native.h",
"objc/api/video_codec/RTCWrappedNativeVideoEncoder.h",
"objc/api/video_codec/RTCWrappedNativeVideoEncoder.mm",
]
configs += [ "..:common_objc" ]

View File

@ -12,20 +12,31 @@
#import <Foundation/Foundation.h>
#import "RTCMacros.h"
#import "RTCNativeVideoEncoder.h"
#import "RTCNativeVideoEncoderBuilder+Native.h"
#import "RTCVideoEncoderAV1.h"
#import "RTCWrappedNativeVideoEncoder.h"
#include "modules/video_coding/codecs/av1/libaom_av1_encoder.h"
@implementation RTC_OBJC_TYPE (RTCVideoEncoderAV1)
+ (id<RTC_OBJC_TYPE(RTCVideoEncoder)>)av1Encoder {
std::unique_ptr<webrtc::VideoEncoder> nativeEncoder(webrtc::CreateLibaomAv1Encoder());
return [[RTC_OBJC_TYPE(RTCWrappedNativeVideoEncoder) alloc]
initWithNativeEncoder:std::move(nativeEncoder)];
}
+ (bool)isSupported {
return true;
}
@interface RTC_OBJC_TYPE (RTCVideoEncoderAV1Builder)
: RTC_OBJC_TYPE(RTCNativeVideoEncoder) <RTC_OBJC_TYPE (RTCNativeVideoEncoderBuilder)>
@end
@implementation RTC_OBJC_TYPE (RTCVideoEncoderAV1Builder)
- (std::unique_ptr<webrtc::VideoEncoder>)build:(const webrtc::Environment&)env {
return webrtc::CreateLibaomAv1Encoder(env);
}
@end
@implementation RTC_OBJC_TYPE (RTCVideoEncoderAV1)
+ (id<RTC_OBJC_TYPE(RTCVideoEncoder)>)av1Encoder {
return [[RTC_OBJC_TYPE(RTCVideoEncoderAV1Builder) alloc] init];
}
+ (bool)isSupported {
return true;
}
@end

View File

@ -12,16 +12,28 @@
#import <Foundation/Foundation.h>
#import "RTCMacros.h"
#import "RTCNativeVideoEncoder.h"
#import "RTCNativeVideoEncoderBuilder+Native.h"
#import "RTCVideoEncoderVP8.h"
#import "RTCWrappedNativeVideoEncoder.h"
#include "modules/video_coding/codecs/vp8/include/vp8.h"
@implementation RTC_OBJC_TYPE (RTCVideoEncoderVP8)
+ (id<RTC_OBJC_TYPE(RTCVideoEncoder)>)vp8Encoder {
return [[RTC_OBJC_TYPE(RTCWrappedNativeVideoEncoder) alloc]
initWithNativeEncoder:std::unique_ptr<webrtc::VideoEncoder>(webrtc::VP8Encoder::Create())];
}
@interface RTC_OBJC_TYPE (RTCVideoEncoderVP8Builder)
: RTC_OBJC_TYPE(RTCNativeVideoEncoder) <RTC_OBJC_TYPE (RTCNativeVideoEncoderBuilder)>
@end
@implementation RTC_OBJC_TYPE (RTCVideoEncoderVP8Builder)
- (std::unique_ptr<webrtc::VideoEncoder>)build:(const webrtc::Environment&)env {
return webrtc::CreateVp8Encoder(env);
}
@end
@implementation RTC_OBJC_TYPE (RTCVideoEncoderVP8)
+ (id<RTC_OBJC_TYPE(RTCVideoEncoder)>)vp8Encoder {
return [[RTC_OBJC_TYPE(RTCVideoEncoderVP8Builder) alloc] init];
}
@end

View File

@ -12,28 +12,40 @@
#import <Foundation/Foundation.h>
#import "RTCMacros.h"
#import "RTCNativeVideoEncoder.h"
#import "RTCNativeVideoEncoderBuilder+Native.h"
#import "RTCVideoEncoderVP9.h"
#import "RTCWrappedNativeVideoEncoder.h"
#include "modules/video_coding/codecs/vp9/include/vp9.h"
@implementation RTC_OBJC_TYPE (RTCVideoEncoderVP9)
+ (id<RTC_OBJC_TYPE(RTCVideoEncoder)>)vp9Encoder {
std::unique_ptr<webrtc::VideoEncoder> nativeEncoder(webrtc::VP9Encoder::Create());
if (nativeEncoder == nullptr) {
return nil;
}
return [[RTC_OBJC_TYPE(RTCWrappedNativeVideoEncoder) alloc]
initWithNativeEncoder:std::move(nativeEncoder)];
}
+ (bool)isSupported {
#if defined(RTC_ENABLE_VP9)
return true;
#else
return false;
#endif
}
@interface RTC_OBJC_TYPE (RTCVideoEncoderVP9Builder)
: RTC_OBJC_TYPE(RTCNativeVideoEncoder) <RTC_OBJC_TYPE (RTCNativeVideoEncoderBuilder)>
@end
@implementation RTC_OBJC_TYPE (RTCVideoEncoderVP9Builder)
- (std::unique_ptr<webrtc::VideoEncoder>)build:(const webrtc::Environment&)env {
return webrtc::CreateVp9Encoder(env);
}
@end
@implementation RTC_OBJC_TYPE (RTCVideoEncoderVP9)
+ (id<RTC_OBJC_TYPE(RTCVideoEncoder)>)vp9Encoder {
#if defined(RTC_ENABLE_VP9)
return [[RTC_OBJC_TYPE(RTCVideoEncoderVP9Builder) alloc] init];
#else
return nil;
#endif
}
+ (bool)isSupported {
#if defined(RTC_ENABLE_VP9)
return true;
#else
return false;
#endif
}
@end

View File

@ -1,29 +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 "RTCNativeVideoEncoder.h"
#import "base/RTCMacros.h"
#import "base/RTCVideoEncoder.h"
#include "api/video_codecs/sdp_video_format.h"
#include "api/video_codecs/video_encoder.h"
#include "media/base/codec.h"
// TODO: bugs.webrtc.org/15860 - Remove in favor of the RTCNativeVideoEncoderBuilder
@interface RTC_OBJC_TYPE (RTCWrappedNativeVideoEncoder) : RTC_OBJC_TYPE (RTCNativeVideoEncoder)
- (instancetype)initWithNativeEncoder:(std::unique_ptr<webrtc::VideoEncoder>)encoder;
/* This moves the ownership of the wrapped encoder to the caller. */
- (std::unique_ptr<webrtc::VideoEncoder>)releaseWrappedEncoder;
@end

View File

@ -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 "RTCWrappedNativeVideoEncoder.h"
#import "base/RTCMacros.h"
@implementation RTC_OBJC_TYPE (RTCWrappedNativeVideoEncoder) {
std::unique_ptr<webrtc::VideoEncoder> _wrappedEncoder;
}
- (instancetype)initWithNativeEncoder:(std::unique_ptr<webrtc::VideoEncoder>)encoder {
if (self = [super init]) {
_wrappedEncoder = std::move(encoder);
}
return self;
}
- (std::unique_ptr<webrtc::VideoEncoder>)releaseWrappedEncoder {
return std::move(_wrappedEncoder);
}
@end

View File

@ -32,7 +32,6 @@ class ObjCVideoEncoderFactory : public VideoEncoderFactory {
std::vector<SdpVideoFormat> GetSupportedFormats() const override;
std::vector<SdpVideoFormat> GetImplementations() const override;
std::unique_ptr<VideoEncoder> CreateVideoEncoder(const SdpVideoFormat& format) override;
std::unique_ptr<VideoEncoder> Create(const Environment& env,
const SdpVideoFormat& format) override;
std::unique_ptr<EncoderSelectorInterface> GetEncoderSelector() const override;

View File

@ -21,7 +21,6 @@
#import "sdk/objc/api/peerconnection/RTCVideoEncoderSettings+Private.h"
#import "sdk/objc/api/video_codec/RTCNativeVideoEncoderBuilder+Native.h"
#import "sdk/objc/api/video_codec/RTCVideoCodecConstants.h"
#import "sdk/objc/api/video_codec/RTCWrappedNativeVideoEncoder.h"
#import "sdk/objc/helpers/NSString+StdString.h"
#include "api/environment/environment.h"
@ -185,18 +184,6 @@ std::vector<SdpVideoFormat> ObjCVideoEncoderFactory::GetImplementations() const
return GetSupportedFormats();
}
std::unique_ptr<VideoEncoder> ObjCVideoEncoderFactory::CreateVideoEncoder(
const SdpVideoFormat &format) {
RTC_OBJC_TYPE(RTCVideoCodecInfo) *info =
[[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithNativeSdpVideoFormat:format];
id<RTC_OBJC_TYPE(RTCVideoEncoder)> encoder = [encoder_factory_ createEncoder:info];
if ([encoder isKindOfClass:[RTC_OBJC_TYPE(RTCWrappedNativeVideoEncoder) class]]) {
return [(RTC_OBJC_TYPE(RTCWrappedNativeVideoEncoder) *)encoder releaseWrappedEncoder];
} else {
return std::unique_ptr<ObjCVideoEncoder>(new ObjCVideoEncoder(encoder));
}
}
std::unique_ptr<VideoEncoder> ObjCVideoEncoderFactory::Create(const Environment &env,
const SdpVideoFormat &format) {
RTC_OBJC_TYPE(RTCVideoCodecInfo) *info =
@ -204,8 +191,6 @@ std::unique_ptr<VideoEncoder> ObjCVideoEncoderFactory::Create(const Environment
id<RTC_OBJC_TYPE(RTCVideoEncoder)> encoder = [encoder_factory_ createEncoder:info];
if ([encoder conformsToProtocol:@protocol(RTC_OBJC_TYPE(RTCNativeVideoEncoderBuilder))]) {
return [((id<RTC_OBJC_TYPE(RTCNativeVideoEncoderBuilder)>)encoder) build:env];
} else if ([encoder isKindOfClass:[RTC_OBJC_TYPE(RTCWrappedNativeVideoEncoder) class]]) {
return [(RTC_OBJC_TYPE(RTCWrappedNativeVideoEncoder) *)encoder releaseWrappedEncoder];
} else {
return std::make_unique<ObjCVideoEncoder>(encoder);
}