Propagate webrtc::Environment through objc VideoDecoderFactory

Bug: webrtc:15791
Change-Id: I9e9206c6e2f7be2d2d59f80241cafcc27b9e6ad6
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/339864
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Kári Helgason <kthelgason@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41767}
This commit is contained in:
Danil Chapovalov 2024-02-20 10:58:59 +01:00 committed by WebRTC LUCI CQ
parent 8c38eed63c
commit 36d5eec6e1
10 changed files with 137 additions and 50 deletions

View File

@ -1173,6 +1173,7 @@ if (is_ios || is_mac) {
"../api:scoped_refptr",
"../api/audio_codecs:builtin_audio_decoder_factory",
"../api/audio_codecs:builtin_audio_encoder_factory",
"../api/environment:environment_factory",
"../api/task_queue:default_task_queue_factory",
"../api/video:video_frame",
"../api/video_codecs:video_codecs_api",
@ -1539,6 +1540,9 @@ if (is_ios || is_mac) {
rtc_library("wrapped_native_codec_objc") {
sources = [
"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",
@ -1551,6 +1555,7 @@ if (is_ios || is_mac) {
deps = [
":base_objc",
":helpers_objc",
"../api/environment",
"../api/video_codecs:video_codecs_api",
"../media:codec",
"../media:rtc_media_base",
@ -1662,6 +1667,7 @@ if (is_ios || is_mac) {
":vpx_codec_constants",
":wrapped_native_codec_objc",
"../api:make_ref_counted",
"../api/environment",
"../api/video:video_frame",
"../api/video:video_rtp_headers",
"../api/video_codecs:video_codecs_api",

View File

@ -0,0 +1,20 @@
/*
* Copyright (c) 2024 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 "base/RTCMacros.h"
#import "base/RTCVideoDecoder.h"
// NativeVideoDecoder pretends to conform to RTCVideoDecoder protocol, but
// expects its methods won't be called.
@interface RTC_OBJC_TYPE (RTCNativeVideoDecoder) : NSObject <RTC_OBJC_TYPE (RTCVideoDecoder)>
@end

View File

@ -0,0 +1,47 @@
/*
* Copyright (c) 2024 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"
#import "helpers/NSString+StdString.h"
@implementation RTC_OBJC_TYPE (RTCNativeVideoDecoder)
- (void)setCallback:(RTCVideoDecoderCallback)callback {
RTC_DCHECK_NOTREACHED();
}
- (NSInteger)startDecodeWithNumberOfCores:(int)numberOfCores {
RTC_DCHECK_NOTREACHED();
return 0;
}
- (NSInteger)releaseDecoder {
RTC_DCHECK_NOTREACHED();
return 0;
}
// TODO: bugs.webrtc.org/15444 - Remove obsolete missingFrames param.
- (NSInteger)decode:(RTC_OBJC_TYPE(RTCEncodedImage) *)encodedImage
missingFrames:(BOOL)missingFrames
codecSpecificInfo:(nullable id<RTC_OBJC_TYPE(RTCCodecSpecificInfo)>)info
renderTimeMs:(int64_t)renderTimeMs {
RTC_DCHECK_NOTREACHED();
return 0;
}
- (NSString *)implementationName {
RTC_DCHECK_NOTREACHED();
return nil;
}
@end

View File

@ -0,0 +1,25 @@
/*
* Copyright (c) 2024 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 "base/RTCMacros.h"
#include <memory>
#include "api/environment/environment.h"
#include "api/video_codecs/video_decoder.h"
@protocol RTC_OBJC_TYPE
(RTCNativeVideoDecoderBuilder)
- (std::unique_ptr<webrtc::VideoDecoder>)build : (const webrtc::Environment&)env;
@end

View File

@ -12,16 +12,28 @@
#import <Foundation/Foundation.h>
#import "RTCMacros.h"
#import "RTCNativeVideoDecoder.h"
#import "RTCNativeVideoDecoderBuilder+Native.h"
#import "RTCVideoDecoderVP8.h"
#import "RTCWrappedNativeVideoDecoder.h"
#include "modules/video_coding/codecs/vp8/include/vp8.h"
@implementation RTC_OBJC_TYPE (RTCVideoDecoderVP8)
+ (id<RTC_OBJC_TYPE(RTCVideoDecoder)>)vp8Decoder {
return [[RTC_OBJC_TYPE(RTCWrappedNativeVideoDecoder) alloc]
initWithNativeDecoder:std::unique_ptr<webrtc::VideoDecoder>(webrtc::VP8Decoder::Create())];
}
@interface RTC_OBJC_TYPE (RTCVideoDecoderVP8Builder)
: RTC_OBJC_TYPE(RTCNativeVideoDecoder) <RTC_OBJC_TYPE (RTCNativeVideoDecoderBuilder)>
@end
@implementation RTC_OBJC_TYPE (RTCVideoDecoderVP8Builder)
- (std::unique_ptr<webrtc::VideoDecoder>)build:(const webrtc::Environment&)env {
return webrtc::CreateVp8Decoder(env);
}
@end
@implementation RTC_OBJC_TYPE (RTCVideoDecoderVP8)
+ (id<RTC_OBJC_TYPE(RTCVideoDecoder)>)vp8Decoder {
return [[RTC_OBJC_TYPE(RTCVideoDecoderVP8Builder) alloc] init];
}
@end

View File

@ -10,13 +10,15 @@
#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"
@interface RTC_OBJC_TYPE (RTCWrappedNativeVideoDecoder) : NSObject <RTC_OBJC_TYPE (RTCVideoDecoder)>
// 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;

View File

@ -12,7 +12,6 @@
#import "RTCWrappedNativeVideoDecoder.h"
#import "base/RTCMacros.h"
#import "helpers/NSString+StdString.h"
@implementation RTC_OBJC_TYPE (RTCWrappedNativeVideoDecoder) {
std::unique_ptr<webrtc::VideoDecoder> _wrappedDecoder;
@ -30,34 +29,4 @@
return std::move(_wrappedDecoder);
}
#pragma mark - RTC_OBJC_TYPE(RTCVideoDecoder)
- (void)setCallback:(RTCVideoDecoderCallback)callback {
RTC_DCHECK_NOTREACHED();
}
- (NSInteger)startDecodeWithNumberOfCores:(int)numberOfCores {
RTC_DCHECK_NOTREACHED();
return 0;
}
- (NSInteger)releaseDecoder {
RTC_DCHECK_NOTREACHED();
return 0;
}
// TODO(bugs.webrtc.org/15444): Remove obsolete missingFrames param.
- (NSInteger)decode:(RTC_OBJC_TYPE(RTCEncodedImage) *)encodedImage
missingFrames:(BOOL)missingFrames
codecSpecificInfo:(nullable id<RTC_OBJC_TYPE(RTCCodecSpecificInfo)>)info
renderTimeMs:(int64_t)renderTimeMs {
RTC_DCHECK_NOTREACHED();
return 0;
}
- (NSString *)implementationName {
RTC_DCHECK_NOTREACHED();
return nil;
}
@end

View File

@ -13,6 +13,7 @@
#import "base/RTCMacros.h"
#include "api/environment/environment.h"
#include "api/video_codecs/video_decoder_factory.h"
#include "media/base/codec.h"
@ -29,7 +30,8 @@ class ObjCVideoDecoderFactory : public VideoDecoderFactory {
id<RTC_OBJC_TYPE(RTCVideoDecoderFactory)> wrapped_decoder_factory() const;
std::vector<SdpVideoFormat> GetSupportedFormats() const override;
std::unique_ptr<VideoDecoder> CreateVideoDecoder(const SdpVideoFormat& format) override;
std::unique_ptr<VideoDecoder> Create(const Environment& env,
const SdpVideoFormat& format) override;
private:
id<RTC_OBJC_TYPE(RTCVideoDecoderFactory)> decoder_factory_;

View File

@ -18,6 +18,7 @@
#import "components/video_codec/RTCCodecSpecificInfoH264.h"
#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"
@ -42,8 +43,7 @@ class ObjCVideoDecoder : public VideoDecoder {
[decoder_ startDecodeWithNumberOfCores:settings.number_of_cores()] == WEBRTC_VIDEO_CODEC_OK;
}
int32_t Decode(const EncodedImage &input_image,
int64_t render_time_ms = -1) override {
int32_t Decode(const EncodedImage &input_image, int64_t render_time_ms = -1) override {
RTC_OBJC_TYPE(RTCEncodedImage) *encodedImage =
[[RTC_OBJC_TYPE(RTCEncodedImage) alloc] initWithNativeEncodedImage:input_image];
@ -91,14 +91,16 @@ id<RTC_OBJC_TYPE(RTCVideoDecoderFactory)> ObjCVideoDecoderFactory::wrapped_decod
return decoder_factory_;
}
std::unique_ptr<VideoDecoder> ObjCVideoDecoderFactory::CreateVideoDecoder(
const SdpVideoFormat &format) {
std::unique_ptr<VideoDecoder> ObjCVideoDecoderFactory::Create(const Environment &env,
const SdpVideoFormat &format) {
NSString *codecName = [NSString stringWithUTF8String:format.name.c_str()];
for (RTC_OBJC_TYPE(RTCVideoCodecInfo) * codecInfo in decoder_factory_.supportedCodecs) {
if ([codecName isEqualToString:codecInfo.name]) {
id<RTC_OBJC_TYPE(RTCVideoDecoder)> decoder = [decoder_factory_ createDecoder:codecInfo];
if ([decoder isKindOfClass:[RTC_OBJC_TYPE(RTCWrappedNativeVideoDecoder) class]]) {
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));

View File

@ -14,6 +14,7 @@
#include "sdk/objc/native/src/objc_video_decoder_factory.h"
#include "api/environment/environment_factory.h"
#import "base/RTCMacros.h"
#import "base/RTCVideoDecoder.h"
#import "base/RTCVideoDecoderFactory.h"
@ -26,9 +27,9 @@ id<RTC_OBJC_TYPE(RTCVideoDecoderFactory)> CreateDecoderFactoryReturning(int retu
id decoderMock = OCMProtocolMock(@protocol(RTC_OBJC_TYPE(RTCVideoDecoder)));
OCMStub([decoderMock startDecodeWithNumberOfCores:1]).andReturn(return_code);
OCMStub([decoderMock decode:[OCMArg any]
missingFrames:NO
codecSpecificInfo:[OCMArg any]
renderTimeMs:0])
missingFrames:NO
codecSpecificInfo:[OCMArg any]
renderTimeMs:0])
.andReturn(return_code);
OCMStub([decoderMock releaseDecoder]).andReturn(return_code);
@ -51,7 +52,8 @@ id<RTC_OBJC_TYPE(RTCVideoDecoderFactory)> CreateErrorDecoderFactory() {
std::unique_ptr<webrtc::VideoDecoder> GetObjCDecoder(
id<RTC_OBJC_TYPE(RTCVideoDecoderFactory)> factory) {
webrtc::ObjCVideoDecoderFactory decoder_factory(factory);
return decoder_factory.CreateVideoDecoder(webrtc::SdpVideoFormat(cricket::kH264CodecName));
return decoder_factory.Create(webrtc::CreateEnvironment(),
webrtc::SdpVideoFormat(cricket::kH264CodecName));
}
#pragma mark -