Skip to content

Add H.265 video codec support to WebRTC iOS SDK #183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,4 @@
/node_modules
/libwebrtc
/args.txt
/out_ios_libs
37 changes: 37 additions & 0 deletions sdk/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,18 @@ if (is_ios || is_mac) {
"objc/helpers/RTCDispatcher.h",
"objc/helpers/RTCYUVHelper.h",
"objc/helpers/UIDevice+RTCDevice.h",
]

if (rtc_use_h265) {
common_objc_headers += [
"objc/components/video_codec/RTCVideoDecoderFactoryH265.h",
"objc/components/video_codec/RTCVideoDecoderH265.h",
"objc/components/video_codec/RTCVideoEncoderFactoryH265.h",
"objc/components/video_codec/RTCVideoEncoderH265.h",
]
}

common_objc_headers += [
"objc/api/peerconnection/RTCAudioDeviceModule.h",
"objc/api/peerconnection/RTCIODevice.h",
"objc/api/peerconnection/RTCAudioSource.h",
Expand Down Expand Up @@ -1682,6 +1694,18 @@ if (is_ios || is_mac) {
"objc/components/video_frame_buffer/RTCCVPixelBuffer.h",
"objc/helpers/RTCDispatcher.h",
"objc/helpers/RTCYUVHelper.h",
]

if (rtc_use_h265) {
sources += [
"objc/components/video_codec/RTCVideoDecoderFactoryH265.h",
"objc/components/video_codec/RTCVideoDecoderH265.h",
"objc/components/video_codec/RTCVideoEncoderFactoryH265.h",
"objc/components/video_codec/RTCVideoEncoderH265.h",
]
}

sources += [
# Added for Simulcast support
"objc/components/video_codec/RTCVideoEncoderFactorySimulcast.h",
"objc/api/video_codec/RTCVideoEncoderSimulcast.h",
Expand Down Expand Up @@ -1903,6 +1927,8 @@ if (is_ios || is_mac) {
"../rtc_base:checks",
"../rtc_base:logging",
]


}

rtc_library("videotoolbox_objc") {
Expand All @@ -1919,6 +1945,17 @@ if (is_ios || is_mac) {
"objc/components/video_codec/RTCVideoEncoderH264.mm",
]

if (rtc_use_h265) {
sources += [
"objc/components/video_codec/RTCVideoDecoderFactoryH265.h",
"objc/components/video_codec/RTCVideoDecoderFactoryH265.mm",
"objc/components/video_codec/RTCVideoDecoderH265.h",
"objc/components/video_codec/RTCVideoDecoderH265.mm",
"objc/components/video_codec/RTCVideoEncoderH265.h",
"objc/components/video_codec/RTCVideoEncoderH265.mm",
]
}

configs += [
"..:common_objc",
":used_from_extension",
Expand Down
3 changes: 3 additions & 0 deletions sdk/objc/api/video_codec/RTCVideoCodecConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@
RTC_EXTERN NSString* const RTC_CONSTANT_TYPE(RTCVideoCodecVp8Name);
RTC_EXTERN NSString* const RTC_CONSTANT_TYPE(RTCVideoCodecVp9Name);
RTC_EXTERN NSString* const RTC_CONSTANT_TYPE(RTCVideoCodecAv1Name);
#ifdef RTC_ENABLE_H265
RTC_EXTERN NSString* const RTC_CONSTANT_TYPE(RTCVideoCodecH265Name);
#endif
3 changes: 3 additions & 0 deletions sdk/objc/api/video_codec/RTCVideoCodecConstants.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
NSString *const RTC_CONSTANT_TYPE(RTCVideoCodecVp8Name) = @(webrtc::kVp8CodecName);
NSString *const RTC_CONSTANT_TYPE(RTCVideoCodecVp9Name) = @(webrtc::kVp9CodecName);
NSString *const RTC_CONSTANT_TYPE(RTCVideoCodecAv1Name) = @(webrtc::kAv1CodecName);
#ifdef RTC_ENABLE_H265
NSString *const RTC_CONSTANT_TYPE(RTCVideoCodecH265Name) = @(webrtc::kH265CodecName);
#endif
16 changes: 16 additions & 0 deletions sdk/objc/components/video_codec/RTCDefaultVideoDecoderFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#import "api/video_codec/RTCVideoDecoderVP9.h"
#import "base/RTCVideoCodecInfo.h"

#ifdef RTC_ENABLE_H265
#import "RTCVideoDecoderH265.h"
#endif

#if defined(RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY)
#import "api/video_codec/RTCVideoDecoderAV1.h" // nogncheck
#endif
Expand Down Expand Up @@ -56,6 +60,12 @@ @implementation RTC_OBJC_TYPE (RTCDefaultVideoDecoderFactory)
addObject:[[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:RTC_CONSTANT_TYPE(RTCVideoCodecVp9Name)]];
}

#ifdef RTC_ENABLE_H265
RTC_OBJC_TYPE(RTCVideoCodecInfo) *h265Info =
[[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:RTC_CONSTANT_TYPE(RTCVideoCodecH265Name)];
[result addObject:h265Info];
#endif

#if defined(RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY)
[result addObject:[[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:RTC_CONSTANT_TYPE(RTCVideoCodecAv1Name)]];
#endif
Expand All @@ -73,6 +83,12 @@ @implementation RTC_OBJC_TYPE (RTCDefaultVideoDecoderFactory)
return [RTC_OBJC_TYPE(RTCVideoDecoderVP9) vp9Decoder];
}

#ifdef RTC_ENABLE_H265
if ([info.name isEqualToString:RTC_CONSTANT_TYPE(RTCVideoCodecH265Name)]) {
return [[RTC_OBJC_TYPE(RTCVideoDecoderH265) alloc] init];
}
#endif

#if defined(RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY)
if ([info.name isEqualToString:RTC_CONSTANT_TYPE(RTCVideoCodecAv1Name)]) {
return [RTC_OBJC_TYPE(RTCVideoDecoderAV1) av1Decoder];
Expand Down
16 changes: 16 additions & 0 deletions sdk/objc/components/video_codec/RTCDefaultVideoEncoderFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#import "api/video_codec/RTCVideoEncoderVP9.h"
#import "base/RTCVideoCodecInfo.h"

#ifdef RTC_ENABLE_H265
#import "RTCVideoEncoderH265.h"
#endif

#if defined(RTC_USE_LIBAOM_AV1_ENCODER)
#import "api/video_codec/RTCVideoEncoderAV1.h" // nogncheck
#endif
Expand Down Expand Up @@ -58,6 +62,12 @@ @implementation RTC_OBJC_TYPE (RTCDefaultVideoEncoderFactory)
addObject:[[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:RTC_CONSTANT_TYPE(RTCVideoCodecVp9Name) parameters:nil scalabilityModes:[RTC_OBJC_TYPE(RTCVideoEncoderVP9) scalabilityModes]]];
}

#ifdef RTC_ENABLE_H265
RTC_OBJC_TYPE(RTCVideoCodecInfo) *h265Info =
[[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:RTC_CONSTANT_TYPE(RTCVideoCodecH265Name)];
[result addObject:h265Info];
#endif

#if defined(RTC_USE_LIBAOM_AV1_ENCODER)
RTC_OBJC_TYPE(RTCVideoCodecInfo) *av1Info =
[[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc] initWithName:RTC_CONSTANT_TYPE(RTCVideoCodecAv1Name) parameters:nil scalabilityModes:[RTC_OBJC_TYPE(RTCVideoEncoderAV1) scalabilityModes]];
Expand All @@ -77,6 +87,12 @@ @implementation RTC_OBJC_TYPE (RTCDefaultVideoEncoderFactory)
return [RTC_OBJC_TYPE(RTCVideoEncoderVP9) vp9Encoder];
}

#ifdef RTC_ENABLE_H265
if ([info.name isEqualToString:RTC_CONSTANT_TYPE(RTCVideoCodecH265Name)]) {
return [[RTC_OBJC_TYPE(RTCVideoEncoderH265) alloc] initWithCodecInfo:info];
}
#endif

#if defined(RTC_USE_LIBAOM_AV1_ENCODER)
if ([info.name isEqualToString:RTC_CONSTANT_TYPE(RTCVideoCodecAv1Name)]) {
return [RTC_OBJC_TYPE(RTCVideoEncoderAV1) av1Encoder];
Expand Down
68 changes: 68 additions & 0 deletions sdk/objc/components/video_codec/RTCH265ProfileTierLevel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 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 "sdk/objc/base/RTCMacros.h"

#ifdef RTC_ENABLE_H265

RTC_OBJC_EXPORT extern NSString *const RTC_CONSTANT_TYPE(RTCVideoCodecH265Name);
RTC_OBJC_EXPORT extern NSString *const RTC_CONSTANT_TYPE(RTCLevel31MainTier);
RTC_OBJC_EXPORT extern NSString *const RTC_CONSTANT_TYPE(RTCMaxSupportedH265ProfileTierLevel);

/** H265 Profiles, Tiers, and Levels. */
typedef NS_ENUM(NSUInteger, RTC_OBJC_TYPE(RTCH265Profile)) {
RTC_OBJC_TYPE(RTCH265ProfileMain),
RTC_OBJC_TYPE(RTCH265ProfileMain10),
RTC_OBJC_TYPE(RTCH265ProfileMainStill),
RTC_OBJC_TYPE(RTCH265ProfileRangeExtensions),
RTC_OBJC_TYPE(RTCH265ProfileHighThroughput),
RTC_OBJC_TYPE(RTCH265ProfileScreenExtended),
RTC_OBJC_TYPE(RTCH265ProfileScalableMain),
RTC_OBJC_TYPE(RTCH265ProfileScalableMain10),
RTC_OBJC_TYPE(RTCH265Profile3dMain),
};

typedef NS_ENUM(NSUInteger, RTC_OBJC_TYPE(RTCH265Tier)) {
RTC_OBJC_TYPE(RTCH265TierMain),
RTC_OBJC_TYPE(RTCH265TierHigh),
};

typedef NS_ENUM(NSUInteger, RTC_OBJC_TYPE(RTCH265Level)) {
RTC_OBJC_TYPE(RTCH265Level1) = 30,
RTC_OBJC_TYPE(RTCH265Level2) = 60,
RTC_OBJC_TYPE(RTCH265Level2_1) = 63,
RTC_OBJC_TYPE(RTCH265Level3) = 90,
RTC_OBJC_TYPE(RTCH265Level3_1) = 93,
RTC_OBJC_TYPE(RTCH265Level4) = 120,
RTC_OBJC_TYPE(RTCH265Level4_1) = 123,
RTC_OBJC_TYPE(RTCH265Level5) = 150,
RTC_OBJC_TYPE(RTCH265Level5_1) = 153,
RTC_OBJC_TYPE(RTCH265Level5_2) = 156,
RTC_OBJC_TYPE(RTCH265Level6) = 180,
RTC_OBJC_TYPE(RTCH265Level6_1) = 183,
RTC_OBJC_TYPE(RTCH265Level6_2) = 186,
};

RTC_OBJC_EXPORT
@interface RTC_OBJC_TYPE (RTCH265ProfileTierLevel) : NSObject

@property(nonatomic, readonly) RTC_OBJC_TYPE(RTCH265Profile) profile;
@property(nonatomic, readonly) RTC_OBJC_TYPE(RTCH265Tier) tier;
@property(nonatomic, readonly) RTC_OBJC_TYPE(RTCH265Level) level;

- (instancetype)initWithProfile:(RTC_OBJC_TYPE(RTCH265Profile))profile
tier:(RTC_OBJC_TYPE(RTCH265Tier))tier
level:(RTC_OBJC_TYPE(RTCH265Level))level;

@end

#endif // RTC_ENABLE_H265
60 changes: 60 additions & 0 deletions sdk/objc/components/video_codec/RTCH265ProfileTierLevel.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 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.
*/

#ifdef RTC_ENABLE_H265

#import "RTCH265ProfileTierLevel.h"

#include "media/base/media_constants.h"

NSString *const RTC_CONSTANT_TYPE(RTCVideoCodecH265Name) = @(webrtc::kH265CodecName);
NSString *const RTC_CONSTANT_TYPE(RTCLevel31MainTier) = @"level3.1-main-tier";
NSString *const RTC_CONSTANT_TYPE(RTCMaxSupportedH265ProfileTierLevel) = @"level5.2-main-tier";

@implementation RTC_OBJC_TYPE (RTCH265ProfileTierLevel)

@synthesize profile = _profile;
@synthesize tier = _tier;
@synthesize level = _level;

- (instancetype)initWithProfile:(RTC_OBJC_TYPE(RTCH265Profile))profile
tier:(RTC_OBJC_TYPE(RTCH265Tier))tier
level:(RTC_OBJC_TYPE(RTCH265Level))level {
if (self = [super init]) {
_profile = profile;
_tier = tier;
_level = level;
}
return self;
}

- (BOOL)isEqual:(id)object {
if (self == object) {
return YES;
}
if (![object isKindOfClass:[RTC_OBJC_TYPE(RTCH265ProfileTierLevel) class]]) {
return NO;
}
RTC_OBJC_TYPE(RTCH265ProfileTierLevel) *profile = object;
return self.profile == profile.profile && self.tier == profile.tier && self.level == profile.level;
}

- (NSUInteger)hash {
return (NSUInteger)(self.profile ^ self.tier ^ self.level);
}

- (NSString *)description {
return [NSString stringWithFormat:@"RTC_OBJC_TYPE(RTCH265ProfileTierLevel) profile:%lu tier:%lu level:%lu",
(unsigned long)self.profile, (unsigned long)self.tier, (unsigned long)self.level];
}

@end

#endif // RTC_ENABLE_H265
22 changes: 22 additions & 0 deletions sdk/objc/components/video_codec/RTCVideoDecoderFactoryH265.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 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 "RTCVideoDecoderFactory.h"
#import "sdk/objc/base/RTCMacros.h"

#ifdef RTC_ENABLE_H265

RTC_OBJC_EXPORT
@interface RTC_OBJC_TYPE (RTCVideoDecoderFactoryH265) : NSObject <RTC_OBJC_TYPE(RTCVideoDecoderFactory)>
@end

#endif // RTC_ENABLE_H265
42 changes: 42 additions & 0 deletions sdk/objc/components/video_codec/RTCVideoDecoderFactoryH265.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 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.
*/

#ifdef RTC_ENABLE_H265

#import "RTCVideoDecoderFactoryH265.h"

#import "RTCVideoDecoderH265.h"
#import "api/video_codec/RTCVideoCodecConstants.h"
#import "base/RTCVideoCodecInfo.h"

@implementation RTC_OBJC_TYPE (RTCVideoDecoderFactoryH265)

- (NSArray<RTC_OBJC_TYPE(RTCVideoCodecInfo) *> *)supportedCodecs {
NSMutableArray<RTC_OBJC_TYPE(RTCVideoCodecInfo) *> *codecs =
[NSMutableArray array];
NSString *codecName = RTC_CONSTANT_TYPE(RTCVideoCodecH265Name);

RTC_OBJC_TYPE(RTCVideoCodecInfo) *h265Info =
[[RTC_OBJC_TYPE(RTCVideoCodecInfo) alloc]
initWithName:codecName
parameters:@{}];
[codecs addObject:h265Info];

return [codecs copy];
}

- (id<RTC_OBJC_TYPE(RTCVideoDecoder)>)createDecoder:
(RTC_OBJC_TYPE(RTCVideoCodecInfo) *)info {
return [[RTC_OBJC_TYPE(RTCVideoDecoderH265) alloc] init];
}

@end

#endif // RTC_ENABLE_H265
22 changes: 22 additions & 0 deletions sdk/objc/components/video_codec/RTCVideoDecoderH265.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 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 "RTCVideoDecoder.h"
#import "sdk/objc/base/RTCMacros.h"

#ifdef RTC_ENABLE_H265

RTC_OBJC_EXPORT
@interface RTC_OBJC_TYPE (RTCVideoDecoderH265) : NSObject <RTC_OBJC_TYPE(RTCVideoDecoder)>
@end

#endif // RTC_ENABLE_H265
Loading