Skip to content

Commit 0abff7c

Browse files
taste1981jianjunznotorcaPiasyJinChengShi
committed
Update M83 code to work with owt-sdk (webrtc-sdk#68)
* Add HEVC support for iOS/Android * Some changes for building with OWT * Enable openssl * Add create_peerconnection_factory to WebRTC.framework. (webrtc-sdk#46) * Set kVTCompressionPropertyKey_RealTime to true. (webrtc-sdk#51) * H265 packetization_mode setting fix (webrtc-sdk#53) * add H.265 QP parsing logic (webrtc-sdk#47) * Fix linux build error. (webrtc-sdk#54) * Add h264 prefix NAL parser implmentation for enabling frame-marking for h.264 (webrtc-sdk#58) * Make hevc rtp depacketizer/tracker conforming to h.264 design Co-authored-by: jianjunz <[email protected]> Co-authored-by: Cyril Lashkevich <[email protected]> Co-authored-by: Piasy <[email protected]> Co-authored-by: ShiJinCheng <[email protected]>
1 parent b15faaa commit 0abff7c

File tree

85 files changed

+5286
-46
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+5286
-46
lines changed

BUILD.gn

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,25 @@ config("common_inherited_config") {
193193
target_gen_dir,
194194
]
195195
}
196+
if (build_with_owt) {
197+
include_dirs = [
198+
# The overrides must be included first as that is the mechanism for
199+
# selecting the override headers in Chromium.
200+
#"../webrtc_overrides",
201+
202+
# Allow includes to be prefixed with webrtc/ in case it is not an
203+
# immediate subdirectory of the top-level.
204+
".",
205+
206+
# Just like the root WebRTC directory is added to include path, the
207+
# corresponding directory tree with generated files needs to be added too.
208+
# Note: this path does not change depending on the current target, e.g.
209+
# it is always "//gen/third_party/webrtc" when building with Chromium.
210+
# See also: http://cs.chromium.org/?q=%5C"default_include_dirs
211+
# https://gn.googlesource.com/gn/+/master/docs/reference.md#target_gen_dir
212+
target_gen_dir,
213+
]
214+
}
196215
if (is_posix || is_fuchsia) {
197216
defines += [ "WEBRTC_POSIX" ]
198217
}
@@ -237,6 +256,10 @@ config("common_inherited_config") {
237256
if (is_ubsan) {
238257
cflags += [ "-fsanitize=float-cast-overflow" ]
239258
}
259+
260+
if (!rtc_use_h265) {
261+
defines += [ "DISABLE_H265" ]
262+
}
240263
}
241264

242265
# TODO(bugs.webrtc.org/9693): Remove the possibility to suppress this warning
@@ -329,7 +352,7 @@ config("common_config") {
329352
]
330353
}
331354

332-
if (build_with_chromium) {
355+
if (build_with_chromium || build_with_owt) {
333356
defines += [
334357
# NOTICE: Since common_inherited_config is used in public_configs for our
335358
# targets, there's no point including the defines in that config here.
@@ -457,10 +480,13 @@ if (!build_with_chromium) {
457480
rtc_static_library("webrtc") {
458481
# Only the root target and the test should depend on this.
459482
visibility = [
460-
"//:default",
461-
"//:webrtc_lib_link_test",
483+
".:default",
484+
":webrtc_lib_link_test",
462485
]
463486

487+
if (build_with_owt) {
488+
visibility += [ "//talk/owt" ]
489+
}
464490
sources = []
465491
complete_static_lib = true
466492
suppressed_configs += [ "//build/config/compiler:thin_archive" ]

api/video/video_codec_type.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ enum VideoCodecType {
2121
kVideoCodecVP9,
2222
kVideoCodecAV1,
2323
kVideoCodecH264,
24+
#ifndef DISABLE_H265
25+
kVideoCodecH265,
26+
#endif
2427
kVideoCodecMultiplex,
2528
};
2629

api/video_codecs/video_codec.cc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ constexpr char kPayloadNameAv1[] = "AV1";
2626
// needed.
2727
constexpr char kPayloadNameAv1x[] = "AV1X";
2828
constexpr char kPayloadNameH264[] = "H264";
29+
#ifndef DISABLE_H265
30+
constexpr char kPayloadNameH265[] = "H265";
31+
#endif
2932
constexpr char kPayloadNameGeneric[] = "Generic";
3033
constexpr char kPayloadNameMultiplex[] = "Multiplex";
3134
} // namespace
@@ -52,6 +55,17 @@ bool VideoCodecH264::operator==(const VideoCodecH264& other) const {
5255
numberOfTemporalLayers == other.numberOfTemporalLayers);
5356
}
5457

58+
#ifndef DISABLE_H265
59+
bool VideoCodecH265::operator==(const VideoCodecH265& other) const {
60+
return (frameDroppingOn == other.frameDroppingOn &&
61+
keyFrameInterval == other.keyFrameInterval &&
62+
vpsLen == other.vpsLen && spsLen == other.spsLen &&
63+
ppsLen == other.ppsLen &&
64+
(spsLen == 0 || memcmp(spsData, other.spsData, spsLen) == 0) &&
65+
(ppsLen == 0 || memcmp(ppsData, other.ppsData, ppsLen) == 0));
66+
}
67+
#endif
68+
5569
VideoCodec::VideoCodec()
5670
: codecType(kVideoCodecGeneric),
5771
width(0),
@@ -102,6 +116,18 @@ const VideoCodecH264& VideoCodec::H264() const {
102116
return codec_specific_.H264;
103117
}
104118

119+
#ifndef DISABLE_H265
120+
VideoCodecH265* VideoCodec::H265() {
121+
RTC_DCHECK_EQ(codecType, kVideoCodecH265);
122+
return &codec_specific_.H265;
123+
}
124+
125+
const VideoCodecH265& VideoCodec::H265() const {
126+
RTC_DCHECK_EQ(codecType, kVideoCodecH265);
127+
return codec_specific_.H265;
128+
}
129+
#endif
130+
105131
const char* CodecTypeToPayloadString(VideoCodecType type) {
106132
switch (type) {
107133
case kVideoCodecVP8:
@@ -112,9 +138,14 @@ const char* CodecTypeToPayloadString(VideoCodecType type) {
112138
return kPayloadNameAv1;
113139
case kVideoCodecH264:
114140
return kPayloadNameH264;
141+
#ifndef DISABLE_H265
142+
case kVideoCodecH265:
143+
return kPayloadNameH265;
144+
#endif
115145
case kVideoCodecMultiplex:
116146
return kPayloadNameMultiplex;
117147
case kVideoCodecGeneric:
148+
default:
118149
return kPayloadNameGeneric;
119150
}
120151
RTC_CHECK_NOTREACHED();
@@ -132,6 +163,10 @@ VideoCodecType PayloadStringToCodecType(const std::string& name) {
132163
return kVideoCodecH264;
133164
if (absl::EqualsIgnoreCase(name, kPayloadNameMultiplex))
134165
return kVideoCodecMultiplex;
166+
#ifndef DISABLE_H265
167+
if (absl::EqualsIgnoreCase(name, kPayloadNameH265))
168+
return kVideoCodecH265;
169+
#endif
135170
return kVideoCodecGeneric;
136171
}
137172

api/video_codecs/video_codec.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,23 @@ struct VideoCodecH264 {
9797
uint8_t numberOfTemporalLayers;
9898
};
9999

100+
#ifndef DISABLE_H265
101+
struct VideoCodecH265 {
102+
bool operator==(const VideoCodecH265& other) const;
103+
bool operator!=(const VideoCodecH265& other) const {
104+
return !(*this == other);
105+
}
106+
bool frameDroppingOn;
107+
int keyFrameInterval;
108+
const uint8_t* vpsData;
109+
size_t vpsLen;
110+
const uint8_t* spsData;
111+
size_t spsLen;
112+
const uint8_t* ppsData;
113+
size_t ppsLen;
114+
};
115+
#endif
116+
100117
// Translates from name of codec to codec type and vice versa.
101118
RTC_EXPORT const char* CodecTypeToPayloadString(VideoCodecType type);
102119
RTC_EXPORT VideoCodecType PayloadStringToCodecType(const std::string& name);
@@ -105,6 +122,9 @@ union VideoCodecUnion {
105122
VideoCodecVP8 VP8;
106123
VideoCodecVP9 VP9;
107124
VideoCodecH264 H264;
125+
#ifndef DISABLE_H265
126+
VideoCodecH265 H265;
127+
#endif
108128
};
109129

110130
enum class VideoCodecMode { kRealtimeVideo, kScreensharing };
@@ -184,6 +204,10 @@ class RTC_EXPORT VideoCodec {
184204
const VideoCodecVP9& VP9() const;
185205
VideoCodecH264* H264();
186206
const VideoCodecH264& H264() const;
207+
#ifndef DISABLE_H265
208+
VideoCodecH265* H265();
209+
const VideoCodecH265& H265() const;
210+
#endif
187211

188212
private:
189213
// TODO(hta): Consider replacing the union with a pointer type.

api/video_codecs/video_encoder.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ VideoCodecH264 VideoEncoder::GetDefaultH264Settings() {
5757
return h264_settings;
5858
}
5959

60+
#ifndef DISABLE_H265
61+
VideoCodecH265 VideoEncoder::GetDefaultH265Settings() {
62+
VideoCodecH265 h265_settings;
63+
memset(&h265_settings, 0, sizeof(h265_settings));
64+
65+
// h265_settings.profile = kProfileBase;
66+
h265_settings.frameDroppingOn = true;
67+
h265_settings.keyFrameInterval = 3000;
68+
h265_settings.spsData = nullptr;
69+
h265_settings.spsLen = 0;
70+
h265_settings.ppsData = nullptr;
71+
h265_settings.ppsLen = 0;
72+
73+
return h265_settings;
74+
}
75+
#endif
76+
6077
VideoEncoder::ScalingSettings::ScalingSettings() = default;
6178

6279
VideoEncoder::ScalingSettings::ScalingSettings(KOff) : ScalingSettings() {}

api/video_codecs/video_encoder.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,9 @@ class RTC_EXPORT VideoEncoder {
335335
static VideoCodecVP8 GetDefaultVp8Settings();
336336
static VideoCodecVP9 GetDefaultVp9Settings();
337337
static VideoCodecH264 GetDefaultH264Settings();
338+
#ifndef DISABLE_H265
339+
static VideoCodecH265 GetDefaultH265Settings();
340+
#endif
338341

339342
virtual ~VideoEncoder() {}
340343

build_overrides/build.gni

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ ubsan_vptr_ignorelist_path =
3232
# so we just ignore that assert. See https://crbug.com/648948 for more info.
3333
ignore_elf32_limitations = true
3434

35+
if (is_win || is_ios || is_android) {
36+
rtc_use_h265 = true
37+
} else {
38+
rtc_use_h265 = false
39+
}
40+
3541
# Use bundled hermetic Xcode installation maintainted by Chromium,
3642
# except for local iOS builds where it's unsupported.
3743
# Allow for mac cross compile on linux machines.

call/rtp_payload_params.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ void PopulateRtpWithCodecSpecifics(const CodecSpecificInfo& info,
9898
rtp->simulcastIdx = spatial_index.value_or(0);
9999
return;
100100
}
101+
#ifndef DISABLE_H265
102+
case kVideoCodecH265: {
103+
auto& h265_header = rtp->video_type_header.emplace<RTPVideoHeaderH265>();
104+
h265_header.packetization_mode =
105+
info.codecSpecific.H265.packetization_mode;
106+
}
107+
return;
108+
#endif
101109
case kVideoCodecMultiplex:
102110
case kVideoCodecGeneric:
103111
rtp->codec = kVideoCodecGeneric;
@@ -341,6 +349,9 @@ void RtpPayloadParams::SetGeneric(const CodecSpecificInfo* codec_specific_info,
341349
is_keyframe, rtp_video_header);
342350
}
343351
return;
352+
#ifndef DISABLE_H265
353+
case VideoCodecType::kVideoCodecH265:
354+
#endif
344355
case VideoCodecType::kVideoCodecMultiplex:
345356
return;
346357
}

common_video/BUILD.gn

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ rtc_library("common_video") {
2323
"h264/h264_common.h",
2424
"h264/pps_parser.cc",
2525
"h264/pps_parser.h",
26+
"h264/prefix_parser.cc",
27+
"h264/prefix_parser.h",
2628
"h264/sps_parser.cc",
2729
"h264/sps_parser.h",
2830
"h264/sps_vui_rewriter.cc",
@@ -37,6 +39,21 @@ rtc_library("common_video") {
3739
"video_frame_buffer_pool.cc",
3840
]
3941

42+
if (rtc_use_h265) {
43+
sources += [
44+
"h265/h265_bitstream_parser.cc",
45+
"h265/h265_bitstream_parser.h",
46+
"h265/h265_common.cc",
47+
"h265/h265_common.h",
48+
"h265/h265_pps_parser.cc",
49+
"h265/h265_pps_parser.h",
50+
"h265/h265_sps_parser.cc",
51+
"h265/h265_sps_parser.h",
52+
"h265/h265_vps_parser.cc",
53+
"h265/h265_vps_parser.h",
54+
]
55+
}
56+
4057
deps = [
4158
"../api:array_view",
4259
"../api:make_ref_counted",

common_video/h264/prefix_parser.cc

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3+
*
4+
* Use of this source code is governed by a BSD-style license
5+
* that can be found in the LICENSE file in the root of the source
6+
* tree. An additional intellectual property rights grant can be found
7+
* in the file PATENTS. All contributing project authors may
8+
* be found in the AUTHORS file in the root of the source tree.
9+
*/
10+
11+
#include "common_video/h264/prefix_parser.h"
12+
13+
#include <cstdint>
14+
#include <vector>
15+
16+
#include "common_video/h264/h264_common.h"
17+
#include "rtc_base/bit_buffer.h"
18+
19+
namespace {
20+
typedef absl::optional<webrtc::PrefixParser::PrefixState> OptionalPrefix;
21+
22+
#define RETURN_EMPTY_ON_FAIL(x) \
23+
if (!(x)) { \
24+
return OptionalPrefix(); \
25+
}
26+
} // namespace
27+
28+
namespace webrtc {
29+
30+
PrefixParser::PrefixState::PrefixState() = default;
31+
PrefixParser::PrefixState::PrefixState(const PrefixState&) = default;
32+
PrefixParser::PrefixState::~PrefixState() = default;
33+
34+
// General note: this is based off the 02/2016 version of the H.264 standard.
35+
// You can find it on this page:
36+
// http://www.itu.int/rec/T-REC-H.264
37+
38+
// Unpack RBSP and parse SVC extension state from the supplied buffer.
39+
absl::optional<PrefixParser::PrefixState> PrefixParser::ParsePrefix(
40+
const uint8_t* data,
41+
size_t length) {
42+
std::vector<uint8_t> unpacked_buffer = H264::ParseRbsp(data, length);
43+
rtc::BitBuffer bit_buffer(unpacked_buffer.data(), unpacked_buffer.size());
44+
return ParsePrefixUpToSvcExtension(&bit_buffer);
45+
}
46+
47+
absl::optional<PrefixParser::PrefixState> PrefixParser::ParsePrefixUpToSvcExtension(
48+
rtc::BitBuffer* buffer) {
49+
// Now, we need to use a bit buffer to parse through the actual SVC extension
50+
// format. See Section 7.3.1 ("NAL unit syntax") and 7.3.1.1 ("NAL unit header
51+
// SVC extension syntax") of the H.264 standard for a complete description.
52+
53+
PrefixState svc_extension;
54+
55+
uint32_t svc_extension_flag = 0;
56+
// Make sure the svc_extension_flag is on.
57+
RETURN_EMPTY_ON_FAIL(buffer->ReadBits(&svc_extension_flag, 1));
58+
if (!svc_extension_flag)
59+
return OptionalPrefix();
60+
61+
// idr_flag: u(1)
62+
RETURN_EMPTY_ON_FAIL(buffer->ReadBits(&svc_extension.idr_flag, 1));
63+
// priority_id: u(6)
64+
RETURN_EMPTY_ON_FAIL(buffer->ReadBits(&svc_extension.priority_id, 6));
65+
// no_inter_layer_pred_flag: u(1)
66+
RETURN_EMPTY_ON_FAIL(
67+
buffer->ReadBits(&svc_extension.no_inter_layer_pred_flag, 1));
68+
// dependency_id: u(3)
69+
RETURN_EMPTY_ON_FAIL(buffer->ReadBits(&svc_extension.dependency_id, 3));
70+
// quality_id: u(4)
71+
RETURN_EMPTY_ON_FAIL(buffer->ReadBits(&svc_extension.quality_id, 4));
72+
// temporal_id: u(3)
73+
RETURN_EMPTY_ON_FAIL(buffer->ReadBits(&svc_extension.temporal_id, 3));
74+
// use_ref_base_pic_flag: u(1)
75+
RETURN_EMPTY_ON_FAIL(
76+
buffer->ReadBits(&svc_extension.use_ref_base_pic_flag, 1));
77+
// discardable_flag: u(1)
78+
RETURN_EMPTY_ON_FAIL(buffer->ReadBits(&svc_extension.discardable_flag, 1));
79+
// output_flag: u(1)
80+
RETURN_EMPTY_ON_FAIL(buffer->ReadBits(&svc_extension.output_flag, 1));
81+
82+
return OptionalPrefix(svc_extension);
83+
}
84+
85+
} // namespace webrtc

0 commit comments

Comments
 (0)