Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
Fix some issue to enable HEVC on iOS.
Browse files Browse the repository at this point in the history
- Add some missing classes.
- Define OWT_USE_H265 when rtc_use_h265 is true.
  • Loading branch information
jianjunz committed Oct 15, 2019
1 parent 4729846 commit 7aed6d9
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 24 deletions.
2 changes: 2 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ config("common_inherited_config") {

if (!rtc_use_h265) {
defines += [ "DISABLE_H265" ]
} else {
defines += [ "OWT_USE_H265" ]
}
}

Expand Down
2 changes: 2 additions & 0 deletions modules/rtp_rtcp/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ rtc_static_library("rtp_rtcp") {

if (!rtc_use_h265) {
defines += ["DISABLE_H265"]
} else {
defines += [ "OWT_USE_H265" ]
}

deps = [
Expand Down
23 changes: 18 additions & 5 deletions sdk/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,16 @@ if (is_ios || is_mac) {
"objc/components/video_codec/RTCH264ProfileLevelId.h",
"objc/components/video_codec/RTCH264ProfileLevelId.mm",
]
if (rtc_use_h265) {
sources += [
# TODO: Split this file.
"objc/Framework/Headers/WebRTC/RTCVideoCodecH265.h",
"objc/components/video_codec/RTCCodecSpecificInfoH265+Private.h",
"objc/components/video_codec/RTCCodecSpecificInfoH265.h",
"objc/components/video_codec/RTCCodecSpecificInfoH265.mm",
"objc/components/video_codec/RTCVideoCodecH265.mm",
]
}
if (is_ios) {
sources += [
"objc/components/video_codec/UIDevice+H264Profile.h",
Expand Down Expand Up @@ -1631,13 +1641,16 @@ if (is_ios || is_mac) {
"objc/components/video_codec/RTCVideoEncoderFactoryH264.m",
"objc/components/video_codec/RTCVideoEncoderH264.h",
"objc/components/video_codec/RTCVideoEncoderH264.mm",
"objc/Framework/Headers/WebRTC/RTCVideoCodecH265.h",
"objc/components/video_codec/RTCVideoEncoderH265.mm",
"objc/components/video_codec/RTCVideoCodecH265.mm",
"objc/components/video_codec/RTCVideoDecoderH265.h",
"objc/components/video_codec/RTCVideoDecoderH265.mm",
]

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

configs += [
"..:common_objc",
":used_from_extension",
Expand Down
5 changes: 1 addition & 4 deletions sdk/objc/Framework/Headers/WebRTC/RTCVideoCodecH265.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
#import <WebRTC/RTCMacros.h>
#import <WebRTC/RTCVideoCodecFactory.h>

RTC_OBJC_EXPORT
API_AVAILABLE(ios(11.0))
@interface RTCCodecSpecificInfoH265 : NSObject <RTCCodecSpecificInfo>
@end
RTC_OBJC_EXPORT extern NSString *const kRTCVideoCodecH265Name;

/** Encoder. */
RTC_OBJC_EXPORT
Expand Down
25 changes: 25 additions & 0 deletions sdk/objc/components/video_codec/RTCCodecSpecificInfoH265+Private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 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.
*/
/* This file is borrowed from sdk/objc/components/video_codec/RTCCodecSpecificInfoH264+Private.h */

#import "RTCCodecSpecificInfoH265.h"

#include "modules/video_coding/include/video_codec_interface.h"

NS_ASSUME_NONNULL_BEGIN

/* Interfaces for converting to/from internal C++ formats. */
@interface RTCCodecSpecificInfoH265 ()

- (webrtc::CodecSpecificInfo)nativeCodecSpecificInfo;

@end

NS_ASSUME_NONNULL_END
28 changes: 28 additions & 0 deletions sdk/objc/components/video_codec/RTCCodecSpecificInfoH265.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 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.
*/
/* This file is borrowed from sdk/objc/components/video_codec/RTCCodecSpecificInfoH264.h. */

#import <Foundation/Foundation.h>

#import "RTCCodecSpecificInfo.h"
#import "RTCMacros.h"

/** Class for H264 specific config. */
typedef NS_ENUM(NSUInteger, RTCH265PacketizationMode) {
RTCH265PacketizationModeNonInterleaved = 0, // Mode 1 - STAP-A, FU-A is allowed
RTCH265PacketizationModeSingleNalUnit // Mode 0 - only single NALU allowed
};

RTC_OBJC_EXPORT
@interface RTCCodecSpecificInfoH265 : NSObject <RTCCodecSpecificInfo>

@property(nonatomic, assign) RTCH265PacketizationMode packetizationMode;

@end
28 changes: 28 additions & 0 deletions sdk/objc/components/video_codec/RTCCodecSpecificInfoH265.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 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.
*/
/* This file is borrowed from sdk/objc/components/video_codec/RTCCodecSpecificInfoH264.mm */

#import "RTCCodecSpecificInfoH265+Private.h"

// H265 specific settings.
@implementation RTCCodecSpecificInfoH265

@synthesize packetizationMode = _packetizationMode;

- (webrtc::CodecSpecificInfo)nativeCodecSpecificInfo {
webrtc::CodecSpecificInfo codecSpecificInfo;
codecSpecificInfo.codecType = webrtc::kVideoCodecH265;
codecSpecificInfo.codecSpecific.H265.packetization_mode =
(webrtc::H265PacketizationMode)_packetizationMode;

return codecSpecificInfo;
}

@end
10 changes: 4 additions & 6 deletions sdk/objc/components/video_codec/RTCVideoCodecH265.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,20 @@
/* This file is borrowed from
* webrtc/sdk/objc/Framework/Classes/PeerConnection/RTCVideoCodecH265.mm */

#import "WebRTC/RTCVideoCodec.h"
#import "WebRTC/RTCVideoCodecH265.h"

#include <vector>

#import "WebRTC/RTCVideoCodec.h"

#include "media/base/media_constants.h"
#include "rtc_base/time_utils.h"
#include "system_wrappers/include/field_trial.h"

NSString *const kRTCVideoCodecH265Name = @(cricket::kH265CodecName);

static NSString* kH265CodecName = @"H265";
// TODO(jianjunz): This is value is not correct.
static NSString* kLevel31Main = @"4d001f";

@implementation RTCCodecSpecificInfoH265
@end

// Encoder factory.
@implementation RTCVideoEncoderFactoryH265

Expand Down
18 changes: 9 additions & 9 deletions sdk/objc/components/video_codec/RTCVideoEncoderH265.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@
*
*/

#import "WebRTC/RTCVideoCodecH265.h"

#import <VideoToolbox/VideoToolbox.h>
#include <vector>

#if defined(WEBRTC_IOS)
#import "helpers/UIDevice+RTCDevice.h"
#endif
#import "RTCCodecSpecificInfoH265.h"
#import "WebRTC/RTCVideoCodec.h"
#import "WebRTC/RTCVideoCodecH265.h"
#import "WebRTC/RTCVideoFrame.h"
#import "WebRTC/RTCVideoFrameBuffer.h"
#import "helpers.h"
#import "sdk/objc/Framework/Classes/PeerConnection/RTCVideoCodec+Private.h"
#if defined(WEBRTC_IOS)
#import "helpers/UIDevice+RTCDevice.h"
#endif

#include <vector>
#include "common_video/h264/profile_level_id.h"
#include "common_video/include/bitrate_adjuster.h"
#include "libyuv/convert_from.h"
Expand All @@ -28,8 +30,6 @@
#include "rtc_base/buffer.h"
#include "rtc_base/logging.h"
#include "rtc_base/time_utils.h"
#import "sdk/objc/Framework/Classes/PeerConnection/RTCVideoCodec+Private.h"
#import "helpers.h"
#include "sdk/objc/Framework/Classes/VideoToolbox/nalu_rewriter.h"
#include "system_wrappers/include/clock.h"

Expand Down
4 changes: 4 additions & 0 deletions sdk/objc/native/src/objc_video_encoder_factory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#import "base/RTCVideoEncoder.h"
#import "base/RTCVideoEncoderFactory.h"
#import "components/video_codec/RTCCodecSpecificInfoH264+Private.h"
#import "components/video_codec/RTCCodecSpecificInfoH265+Private.h"
#import "sdk/objc/api/peerconnection/RTCEncodedImage+Private.h"
#import "sdk/objc/api/peerconnection/RTCRtpFragmentationHeader+Private.h"
#import "sdk/objc/api/peerconnection/RTCVideoCodecInfo+Private.h"
Expand Down Expand Up @@ -62,6 +63,9 @@ int32_t RegisterEncodeCompleteCallback(EncodedImageCallback *callback) override
if ([NSStringFromClass([info class]) isEqual:@"RTCCodecSpecificInfoH264"]) {
// if ([info isKindOfClass:[RTCCodecSpecificInfoH264 class]]) {
codecSpecificInfo = [(RTCCodecSpecificInfoH264 *)info nativeCodecSpecificInfo];
} else if ([NSStringFromClass([info class]) isEqual:@"RTCCodecSpecificInfoH265"]) {
// if ([info isKindOfClass:[RTCCodecSpecificInfoH265 class]]) {
codecSpecificInfo = [(RTCCodecSpecificInfoH265 *)info nativeCodecSpecificInfo];
}

std::unique_ptr<RTPFragmentationHeader> fragmentationHeader =
Expand Down

0 comments on commit 7aed6d9

Please sign in to comment.