Skip to content

Commit

Permalink
Update M83 code to work with owt-sdk (#68)
Browse files Browse the repository at this point in the history
* Add HEVC support for iOS/Android

* Some changes for building with OWT

* Enable openssl

* Add create_peerconnection_factory to WebRTC.framework. (#46)

* Set kVTCompressionPropertyKey_RealTime to true. (#51)

* H265 packetization_mode setting fix (#53)

* add H.265 QP parsing logic (#47)

* Fix linux build error. (#54)

* Add h264 prefix NAL parser implmentation for enabling frame-marking for h.264 (#58)

* Make hevc rtp depacketizer/tracker conforming to h.264 design

Co-authored-by: jianjunz <jianjun.zhu@intel.com>
Co-authored-by: Cyril Lashkevich <notorca@gmail.com>
Co-authored-by: Piasy <xz4215@gmail.com>
Co-authored-by: ShiJinCheng <874042641@qq.com>
  • Loading branch information
5 people committed Jan 4, 2021
1 parent b15b291 commit fff6b8b
Show file tree
Hide file tree
Showing 89 changed files with 5,332 additions and 31 deletions.
32 changes: 29 additions & 3 deletions BUILD.gn
Expand Up @@ -164,6 +164,25 @@ config("common_inherited_config") {
target_gen_dir,
]
}
if (build_with_owt) {
include_dirs = [
# The overrides must be included first as that is the mechanism for
# selecting the override headers in Chromium.
#"../webrtc_overrides",

# Allow includes to be prefixed with webrtc/ in case it is not an
# immediate subdirectory of the top-level.
".",

# Just like the root WebRTC directory is added to include path, the
# corresponding directory tree with generated files needs to be added too.
# Note: this path does not change depending on the current target, e.g.
# it is always "//gen/third_party/webrtc" when building with Chromium.
# See also: http://cs.chromium.org/?q=%5C"default_include_dirs
# https://gn.googlesource.com/gn/+/master/docs/reference.md#target_gen_dir
target_gen_dir,
]
}
if (is_posix || is_fuchsia) {
defines += [ "WEBRTC_POSIX" ]
}
Expand Down Expand Up @@ -208,6 +227,10 @@ config("common_inherited_config") {
if (is_ubsan) {
cflags += [ "-fsanitize=float-cast-overflow" ]
}

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

# TODO(bugs.webrtc.org/9693): Remove the possibility to suppress this warning
Expand Down Expand Up @@ -295,7 +318,7 @@ config("common_config") {

cflags = []

if (build_with_chromium) {
if (build_with_chromium || build_with_owt) {
defines += [
# NOTICE: Since common_inherited_config is used in public_configs for our
# targets, there's no point including the defines in that config here.
Expand Down Expand Up @@ -430,10 +453,13 @@ if (!build_with_chromium) {
rtc_static_library("webrtc") {
# Only the root target and the test should depend on this.
visibility = [
"//:default",
"//:webrtc_lib_link_test",
".:default",
":webrtc_lib_link_test",
]

if (build_with_owt) {
visibility += [ "//talk/owt" ]
}
sources = []
complete_static_lib = true
suppressed_configs += [ "//build/config/compiler:thin_archive" ]
Expand Down
3 changes: 3 additions & 0 deletions api/video/video_codec_type.h
Expand Up @@ -22,6 +22,9 @@ enum VideoCodecType {
kVideoCodecVP9,
kVideoCodecAV1,
kVideoCodecH264,
#ifndef DISABLE_H265
kVideoCodecH265,
#endif
kVideoCodecMultiplex,
};

Expand Down
35 changes: 35 additions & 0 deletions api/video_codecs/video_codec.cc
Expand Up @@ -25,6 +25,9 @@ constexpr char kPayloadNameVp9[] = "VP9";
// frozen.
constexpr char kPayloadNameAv1[] = "AV1X";
constexpr char kPayloadNameH264[] = "H264";
#ifndef DISABLE_H265
constexpr char kPayloadNameH265[] = "H265";
#endif
constexpr char kPayloadNameGeneric[] = "Generic";
constexpr char kPayloadNameMultiplex[] = "Multiplex";
} // namespace
Expand Down Expand Up @@ -56,6 +59,17 @@ bool VideoCodecH264::operator==(const VideoCodecH264& other) const {
numberOfTemporalLayers == other.numberOfTemporalLayers);
}

#ifndef DISABLE_H265
bool VideoCodecH265::operator==(const VideoCodecH265& other) const {
return (frameDroppingOn == other.frameDroppingOn &&
keyFrameInterval == other.keyFrameInterval &&
vpsLen == other.vpsLen && spsLen == other.spsLen &&
ppsLen == other.ppsLen &&
(spsLen == 0 || memcmp(spsData, other.spsData, spsLen) == 0) &&
(ppsLen == 0 || memcmp(ppsData, other.ppsData, ppsLen) == 0));
}
#endif

VideoCodec::VideoCodec()
: codecType(kVideoCodecGeneric),
width(0),
Expand Down Expand Up @@ -105,6 +119,18 @@ const VideoCodecH264& VideoCodec::H264() const {
return codec_specific_.H264;
}

#ifndef DISABLE_H265
VideoCodecH265* VideoCodec::H265() {
RTC_DCHECK_EQ(codecType, kVideoCodecH265);
return &codec_specific_.H265;
}

const VideoCodecH265& VideoCodec::H265() const {
RTC_DCHECK_EQ(codecType, kVideoCodecH265);
return codec_specific_.H265;
}
#endif

const char* CodecTypeToPayloadString(VideoCodecType type) {
switch (type) {
case kVideoCodecVP8:
Expand All @@ -115,9 +141,14 @@ const char* CodecTypeToPayloadString(VideoCodecType type) {
return kPayloadNameAv1;
case kVideoCodecH264:
return kPayloadNameH264;
#ifndef DISABLE_H265
case kVideoCodecH265:
return kPayloadNameH265;
#endif
case kVideoCodecMultiplex:
return kPayloadNameMultiplex;
case kVideoCodecGeneric:
default:
return kPayloadNameGeneric;
}
RTC_CHECK_NOTREACHED();
Expand All @@ -134,6 +165,10 @@ VideoCodecType PayloadStringToCodecType(const std::string& name) {
return kVideoCodecH264;
if (absl::EqualsIgnoreCase(name, kPayloadNameMultiplex))
return kVideoCodecMultiplex;
#ifndef DISABLE_H265
if (absl::EqualsIgnoreCase(name, kPayloadNameH265))
return kVideoCodecH265;
#endif
return kVideoCodecGeneric;
}

Expand Down
24 changes: 24 additions & 0 deletions api/video_codecs/video_codec.h
Expand Up @@ -85,6 +85,23 @@ struct VideoCodecH264 {
uint8_t numberOfTemporalLayers;
};

#ifndef DISABLE_H265
struct VideoCodecH265 {
bool operator==(const VideoCodecH265& other) const;
bool operator!=(const VideoCodecH265& other) const {
return !(*this == other);
}
bool frameDroppingOn;
int keyFrameInterval;
const uint8_t* vpsData;
size_t vpsLen;
const uint8_t* spsData;
size_t spsLen;
const uint8_t* ppsData;
size_t ppsLen;
};
#endif

// Translates from name of codec to codec type and vice versa.
RTC_EXPORT const char* CodecTypeToPayloadString(VideoCodecType type);
RTC_EXPORT VideoCodecType PayloadStringToCodecType(const std::string& name);
Expand All @@ -93,6 +110,9 @@ union VideoCodecUnion {
VideoCodecVP8 VP8;
VideoCodecVP9 VP9;
VideoCodecH264 H264;
#ifndef DISABLE_H265
VideoCodecH265 H265;
#endif
};

enum class VideoCodecMode { kRealtimeVideo, kScreensharing };
Expand Down Expand Up @@ -170,6 +190,10 @@ class RTC_EXPORT VideoCodec {
const VideoCodecVP9& VP9() const;
VideoCodecH264* H264();
const VideoCodecH264& H264() const;
#ifndef DISABLE_H265
VideoCodecH265* H265();
const VideoCodecH265& H265() const;
#endif

private:
// TODO(hta): Consider replacing the union with a pointer type.
Expand Down
17 changes: 17 additions & 0 deletions api/video_codecs/video_encoder.cc
Expand Up @@ -60,6 +60,23 @@ VideoCodecH264 VideoEncoder::GetDefaultH264Settings() {
return h264_settings;
}

#ifndef DISABLE_H265
VideoCodecH265 VideoEncoder::GetDefaultH265Settings() {
VideoCodecH265 h265_settings;
memset(&h265_settings, 0, sizeof(h265_settings));

// h265_settings.profile = kProfileBase;
h265_settings.frameDroppingOn = true;
h265_settings.keyFrameInterval = 3000;
h265_settings.spsData = nullptr;
h265_settings.spsLen = 0;
h265_settings.ppsData = nullptr;
h265_settings.ppsLen = 0;

return h265_settings;
}
#endif

VideoEncoder::ScalingSettings::ScalingSettings() = default;

VideoEncoder::ScalingSettings::ScalingSettings(KOff) : ScalingSettings() {}
Expand Down
3 changes: 3 additions & 0 deletions api/video_codecs/video_encoder.h
Expand Up @@ -336,6 +336,9 @@ class RTC_EXPORT VideoEncoder {
static VideoCodecVP8 GetDefaultVp8Settings();
static VideoCodecVP9 GetDefaultVp9Settings();
static VideoCodecH264 GetDefaultH264Settings();
#ifndef DISABLE_H265
static VideoCodecH265 GetDefaultH265Settings();
#endif

virtual ~VideoEncoder() {}

Expand Down
22 changes: 22 additions & 0 deletions api/video_codecs/video_encoder_config.cc
Expand Up @@ -95,6 +95,10 @@ void VideoEncoderConfig::EncoderSpecificSettings::FillEncoderSpecificSettings(
FillVideoCodecVp8(codec->VP8());
} else if (codec->codecType == kVideoCodecVP9) {
FillVideoCodecVp9(codec->VP9());
#ifndef DISABLE_H265
} else if (codec->codecType == kVideoCodecH265) {
FillVideoCodecH265(codec->H265());
#endif
} else {
RTC_NOTREACHED() << "Encoder specifics set/used for unknown codec type.";
}
Expand All @@ -105,6 +109,13 @@ void VideoEncoderConfig::EncoderSpecificSettings::FillVideoCodecH264(
RTC_NOTREACHED();
}

#ifndef DISABLE_H265
void VideoEncoderConfig::EncoderSpecificSettings::FillVideoCodecH265(
VideoCodecH265* h265_settings) const {
RTC_NOTREACHED();
}
#endif

void VideoEncoderConfig::EncoderSpecificSettings::FillVideoCodecVp8(
VideoCodecVP8* vp8_settings) const {
RTC_NOTREACHED();
Expand All @@ -124,6 +135,17 @@ void VideoEncoderConfig::H264EncoderSpecificSettings::FillVideoCodecH264(
*h264_settings = specifics_;
}

#ifndef DISABLE_H265
VideoEncoderConfig::H265EncoderSpecificSettings::H265EncoderSpecificSettings(
const VideoCodecH265& specifics)
: specifics_(specifics) {}

void VideoEncoderConfig::H265EncoderSpecificSettings::FillVideoCodecH265(
VideoCodecH265* h265_settings) const {
*h265_settings = specifics_;
}
#endif

VideoEncoderConfig::Vp8EncoderSpecificSettings::Vp8EncoderSpecificSettings(
const VideoCodecVP8& specifics)
: specifics_(specifics) {}
Expand Down
13 changes: 13 additions & 0 deletions api/video_codecs/video_encoder_config.h
Expand Up @@ -84,6 +84,9 @@ class VideoEncoderConfig {
virtual void FillVideoCodecVp8(VideoCodecVP8* vp8_settings) const;
virtual void FillVideoCodecVp9(VideoCodecVP9* vp9_settings) const;
virtual void FillVideoCodecH264(VideoCodecH264* h264_settings) const;
#ifndef DISABLE_H265
virtual void FillVideoCodecH265(VideoCodecH265* h265_settings) const;
#endif

private:
~EncoderSpecificSettings() override {}
Expand All @@ -99,6 +102,16 @@ class VideoEncoderConfig {
VideoCodecH264 specifics_;
};

#ifndef DISABLE_H265
class H265EncoderSpecificSettings : public EncoderSpecificSettings {
public:
explicit H265EncoderSpecificSettings(const VideoCodecH265& specifics);
void FillVideoCodecH265(VideoCodecH265* h265_settings) const override;

private:
VideoCodecH265 specifics_;
};
#endif
class Vp8EncoderSpecificSettings : public EncoderSpecificSettings {
public:
explicit Vp8EncoderSpecificSettings(const VideoCodecVP8& specifics);
Expand Down
6 changes: 6 additions & 0 deletions build_overrides/build.gni
Expand Up @@ -35,6 +35,12 @@ ubsan_vptr_blacklist_path =
# so we just ignore that assert. See https://crbug.com/648948 for more info.
ignore_elf32_limitations = true

if (is_win || is_ios || is_android) {
rtc_use_h265 = true
} else {
rtc_use_h265 = false
}

# Use bundled hermetic Xcode installation maintainted by Chromium,
# except for local iOS builds where it's unsupported.
if (host_os == "mac") {
Expand Down
11 changes: 11 additions & 0 deletions call/rtp_payload_params.cc
Expand Up @@ -95,6 +95,14 @@ void PopulateRtpWithCodecSpecifics(const CodecSpecificInfo& info,
rtp->simulcastIdx = spatial_index.value_or(0);
return;
}
#ifndef DISABLE_H265
case kVideoCodecH265: {
auto& h265_header = rtp->video_type_header.emplace<RTPVideoHeaderH265>();
h265_header.packetization_mode =
info.codecSpecific.H265.packetization_mode;
}
return;
#endif
case kVideoCodecMultiplex:
case kVideoCodecGeneric:
rtp->codec = kVideoCodecGeneric;
Expand Down Expand Up @@ -286,6 +294,9 @@ void RtpPayloadParams::SetGeneric(const CodecSpecificInfo* codec_specific_info,
is_keyframe, rtp_video_header);
}
return;
#ifndef DISABLE_H265
case VideoCodecType::kVideoCodecH265:
#endif
case VideoCodecType::kVideoCodecMultiplex:
return;
}
Expand Down
17 changes: 17 additions & 0 deletions common_video/BUILD.gn
Expand Up @@ -21,6 +21,8 @@ rtc_library("common_video") {
"h264/h264_common.h",
"h264/pps_parser.cc",
"h264/pps_parser.h",
"h264/prefix_parser.cc",
"h264/prefix_parser.h",
"h264/profile_level_id.h",
"h264/sps_parser.cc",
"h264/sps_parser.h",
Expand All @@ -40,6 +42,21 @@ rtc_library("common_video") {
"video_render_frames.h",
]

if (rtc_use_h265) {
sources += [
"h265/h265_bitstream_parser.cc",
"h265/h265_bitstream_parser.h",
"h265/h265_common.cc",
"h265/h265_common.h",
"h265/h265_pps_parser.cc",
"h265/h265_pps_parser.h",
"h265/h265_sps_parser.cc",
"h265/h265_sps_parser.h",
"h265/h265_vps_parser.cc",
"h265/h265_vps_parser.h",
]
}

deps = [
"../api:scoped_refptr",
"../api/task_queue",
Expand Down
1 change: 1 addition & 0 deletions common_video/h264/h264_common.h
Expand Up @@ -42,6 +42,7 @@ enum NaluType : uint8_t {
kEndOfSequence = 10,
kEndOfStream = 11,
kFiller = 12,
kPrefix = 14,
kStapA = 24,
kFuA = 28
};
Expand Down

0 comments on commit fff6b8b

Please sign in to comment.