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

Commit 66bca74

Browse files
committed
VP9/AV1 hardware acceleration
1 parent 0c22b84 commit 66bca74

19 files changed

+675
-539
lines changed

talk/owt/BUILD.gn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ static_library("owt_sdk_base") {
239239
"sdk/base/win/videorendererd3d11.h",
240240
"sdk/base/win/vp9ratecontrol.cc",
241241
"sdk/base/win/vp9ratecontrol.h",
242-
"sdk/base/win/vp9temporallayers.cc",
243-
"sdk/base/win/vp9temporallayers.h",
242+
#"sdk/base/win/vp9temporallayers.cc",
243+
#"sdk/base/win/vp9temporallayers.h",
244244
"sdk/base/windowcapturer.cc",
245245
]
246246
public_deps += [ "//third_party/webrtc/modules/audio_device:audio_device_module_from_input_and_output" ]

talk/owt/sdk/base/codecutils.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ std::vector<webrtc::SdpVideoFormat> CodecUtils::GetSupportedH265Codecs() {
3838
{{cricket::kH265FmtpProfileSpace, "0"},
3939
{cricket::kH265FmtpProfileId, "1"},
4040
{cricket::kH265FmtpTierFlag, "0"},
41+
{cricket::kH265FmtpLevelId, "120"}}),
42+
webrtc::SdpVideoFormat(cricket::kH265CodecName,
43+
{{cricket::kH265FmtpProfileSpace, "0"},
44+
{cricket::kH265FmtpProfileId, "2"},
45+
{cricket::kH265FmtpTierFlag, "0"},
4146
{cricket::kH265FmtpLevelId, "120"}})};
4247
}
4348
#endif

talk/owt/sdk/base/mediautils.h

Lines changed: 151 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,162 @@
88
#include "absl/types/optional.h"
99
#include "api/video_codecs/sdp_video_format.h"
1010
#include <string>
11-
#include "talk/owt/sdk/base/win/mediacapabilities.h"
1211
#include "talk/owt/sdk/include/cpp/owt/base/commontypes.h"
1312

1413
namespace owt {
1514
namespace base {
1615

16+
/// AV1 profiles as negotiated in SDP profile field.
17+
enum class AV1Profile : int {
18+
kMain = 0, ///< 4:0:0(monochrome) or 4:2:0, 8/10-bit
19+
kHigh, ///< 4:0:0/4:2:0/4:4:4, 8/10-bit
20+
kProfessional ///< 4:0:0/4:2:0/4:2:2/4:4:4, 8/10/12-bit
21+
};
22+
23+
/// AV1 levels as negotiated in SDP level-idx field.
24+
/// Calculated by level(x.y)-> level-idx(z): z = (x - 2) * 4 + y;
25+
enum class AV1Level : int {
26+
kLevel2 =
27+
0, ///< 426x240@30fps. All 2.x profiles: max 8 tiles, 4 tile columns.
28+
kLevel2_1 = 1, ///< 640x360@30fps
29+
kLevel3 =
30+
4, ///< 854x480@30fps. All 3.x profiles: max 16 tiles, 6 tile columns.
31+
kLevel3_1 = 5, ///< 720p@30fps. Max 16 tiles, 6 tile columns.
32+
kLevel4 = 8, ///< 1080p@30fps. All 4.x profiles: max 32 tiles, 8 tile columns
33+
kLevel4_1 = 9, ///< 1080p@60fps
34+
kLevel5 = 12, ///< 4k@30fps. All 5.x profiles: max 64 tiles, 8 tile columns.
35+
kLevel5_1 = 13, ///< 4k@60fps
36+
kLevel5_2 = 14, ///< 4k@120fps
37+
kLevel5_3 = 15, ///< 4k@120fps
38+
kLevel6 = 16, ///< 8k@30fps. All 6.x profiles: max 128 tiles, 16 tile columns
39+
kLevel6_1 = 17, ///< 8k@60fps
40+
kLevel6_2 = 18, ///< 8k@120fps
41+
kLevel6_3 = 19, ///< 8k@120fps
42+
kLevelReserved ///< Levels not defined yet.
43+
};
44+
45+
/// AV1 tiers as negotiated in SDP tier field.
46+
/// This equals to the seq_tier accrording to AV1 spec. Value 1
47+
/// is only allowed for level above 4.0(inclusive).
48+
enum class AV1Tier : int { kTier0 = 0, kTier1 };
49+
50+
/// AVC profiles
51+
enum class H264Profile : int {
52+
kConstrainedBaseline = 0,
53+
kBaseline,
54+
kMain,
55+
kHigh,
56+
kUnknown
57+
};
58+
59+
/// VP9 profiles.
60+
enum class VP9Profile : int {
61+
kProfile0 = 0, ///< 4:2:0, 8-bit
62+
kProfile1, ///< 4:2:2 or 4:4:4, 8-bit
63+
kProfile2, ///< 4:2:0, 10-bit or 12-bit
64+
kProfile3 ///< 4:2:2 or 4:4:4, 10-bit or 12-bit
65+
};
66+
67+
/// Profile space as negotiated in SDP profile-space field.
68+
/// Default to 0. (Range from 0 to 3).
69+
enum class H265ProfileSpace : int {
70+
KDefault = 0,
71+
kReserved1,
72+
kReserved2,
73+
kReserved3
74+
};
75+
76+
/// Profile space as negotiated in SDP profile-id field.
77+
/// Not all possible profiles are listed here.
78+
enum class H265ProfileId : int {
79+
kUnknown = 0,
80+
kMain,
81+
kMain10,
82+
kMainStillPicture,
83+
kMainRExt // Range extension
84+
#if (MFX_VERSION >= 1032)
85+
,
86+
KScc // Screen content extension.
87+
#endif
88+
};
89+
90+
/// Level ID as negotiated in SDP level-id field.
91+
/// Calculated by: level(x.y) * 30
92+
enum class H265Level : int {
93+
kUnknown = 0,
94+
kLevel1 = 30,
95+
kLevel2 = 60,
96+
kLevle2_1 = 63,
97+
kLevel3 = 90,
98+
kLevel3_1 = 93,
99+
kLevel4 = 120,
100+
kLevel4_1 = 123,
101+
kLevel5 = 150,
102+
kLevel5_1 = 153,
103+
kLevel5_2 = 156,
104+
kLevel6 = 180,
105+
kLevel6_1 = 183,
106+
kLevel6_2 = 186,
107+
kLevel8_5 = 255
108+
};
109+
110+
/// Tier as negotiated in SDP tier-flag field.
111+
enum class H265Tier : int {
112+
kMain = 0,
113+
kHigh,
114+
};
115+
116+
enum class SamplingMode : int {
117+
kNv12 = 0,
118+
kARGB,
119+
kP010, // Planar, 4:2:0 10-bit.
120+
kY410, // Packed, 4:4:4 10-bit.
121+
kP016, // Planar, 4:2:0 16-bit.
122+
kY416, // Packed, 4:4:4 16-bit.
123+
};
124+
125+
/// Encoder BRC mode.
126+
enum class BRCMode : int {
127+
kUnknown = 0,
128+
kCBR = 1,
129+
kCQP = 2,
130+
kVBR = 3,
131+
kICQ = 4,
132+
kAVBR = 5,
133+
kVCM = 6,
134+
kExternal = 7
135+
};
136+
137+
struct VP9CodecCapability {
138+
VP9Profile profile;
139+
};
140+
141+
struct H264CodecCapability {
142+
H264Profile profile;
143+
};
144+
145+
struct VP8CodecCapability {
146+
};
147+
148+
struct AV1CodecCapability {
149+
AV1Profile profile;
150+
};
151+
152+
struct H265CodecCapability {
153+
H265ProfileId profile;
154+
};
155+
156+
union CodecSpecificInfoUnion {
157+
VP9CodecCapability VP9;
158+
#ifndef DISABLE_H265
159+
H265CodecCapability H265;
160+
#endif
161+
H264CodecCapability H264;
162+
AV1CodecCapability AV1;
163+
VP8CodecCapability VP8;
164+
~CodecSpecificInfoUnion() {}
165+
};
166+
17167

18168
class MediaUtils {
19169
public:

talk/owt/sdk/base/win/d3d11_allocator.cc

Lines changed: 63 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
// Copyright (C) <2020> Intel Corporation
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
16
/******************************************************************************\
2-
Copyright (c) 2005-2018, Intel Corporation
7+
Copyright (c) 2005-2019, Intel Corporation
38
All rights reserved.
49
510
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
@@ -17,13 +22,6 @@ The original version of this sample may be obtained from https://software.intel.
1722
or https://software.intel.com/en-us/media-client-solutions-support.
1823
\**********************************************************************************/
1924

20-
// Copyright (C) <2018> Intel Corporation
21-
//
22-
// SPDX-License-Identifier: Apache-2.0
23-
24-
25-
#if defined(WEBRTC_WIN)
26-
2725
#include "msdkvideobase.h"
2826

2927
#include <objbase.h>
@@ -62,7 +60,7 @@ struct sequence<mfxHDL> {
6260

6361
D3D11FrameAllocator::D3D11FrameAllocator()
6462
{
65-
m_pDeviceContext = NULL;
63+
m_pDeviceContext = nullptr;
6664
}
6765

6866
D3D11FrameAllocator::~D3D11FrameAllocator()
@@ -88,7 +86,7 @@ D3D11FrameAllocator::TextureSubResource D3D11FrameAllocator::GetResourceFromMid
8886
mfxStatus D3D11FrameAllocator::Init(mfxAllocatorParams *pParams)
8987
{
9088
D3D11AllocatorParams *pd3d11Params = 0;
91-
pd3d11Params = dynamic_cast<D3D11AllocatorParams *>(pParams);
89+
pd3d11Params = static_cast<D3D11AllocatorParams *>(pParams);
9290

9391
if (NULL == pd3d11Params ||
9492
NULL == pd3d11Params->pDevice)
@@ -152,7 +150,16 @@ mfxStatus D3D11FrameAllocator::LockFrame(mfxMemId mid, mfxFrameData *ptr)
152150
DXGI_FORMAT_R16G16B16A16_UNORM != desc.Format &&
153151
DXGI_FORMAT_P010 != desc.Format &&
154152
DXGI_FORMAT_AYUV != desc.Format
155-
)
153+
#if (MFX_VERSION >= 1027)
154+
&& DXGI_FORMAT_Y210 != desc.Format &&
155+
DXGI_FORMAT_Y410 != desc.Format
156+
#endif
157+
#if (MFX_VERSION >= 1031)
158+
&& DXGI_FORMAT_P016 != desc.Format &&
159+
DXGI_FORMAT_Y216 != desc.Format &&
160+
DXGI_FORMAT_Y416 != desc.Format
161+
#endif
162+
)
156163
{
157164
return MFX_ERR_LOCK_MEMORY;
158165
}
@@ -185,6 +192,9 @@ mfxStatus D3D11FrameAllocator::LockFrame(mfxMemId mid, mfxFrameData *ptr)
185192
switch (desc.Format)
186193
{
187194
case DXGI_FORMAT_P010:
195+
#if (MFX_VERSION >= 1031)
196+
case DXGI_FORMAT_P016:
197+
#endif
188198
case DXGI_FORMAT_NV12:
189199
ptr->Pitch = (mfxU16)lockedRect.RowPitch;
190200
ptr->Y = (mfxU8 *)lockedRect.pData;
@@ -247,8 +257,35 @@ mfxStatus D3D11FrameAllocator::LockFrame(mfxMemId mid, mfxFrameData *ptr)
247257
ptr->Y16 = (mfxU16 *)lockedRect.pData;
248258
ptr->U16 = 0;
249259
ptr->V16 = 0;
250-
251260
break;
261+
#if (MFX_VERSION >= 1031)
262+
case DXGI_FORMAT_Y416:
263+
ptr->PitchHigh = (mfxU16)(lockedRect.RowPitch / (1 << 16));
264+
ptr->PitchLow = (mfxU16)(lockedRect.RowPitch % (1 << 16));
265+
ptr->U16 = (mfxU16*)lockedRect.pData;
266+
ptr->Y16 = ptr->U16 + 1;
267+
ptr->V16 = ptr->Y16 + 1;
268+
ptr->A = (mfxU8*)(ptr->V16 + 1);
269+
break;
270+
case DXGI_FORMAT_Y216:
271+
#endif
272+
#if (MFX_VERSION >= 1027)
273+
case DXGI_FORMAT_Y210:
274+
ptr->PitchHigh = (mfxU16)(lockedRect.RowPitch / (1 << 16));
275+
ptr->PitchLow = (mfxU16)(lockedRect.RowPitch % (1 << 16));
276+
ptr->Y16 = (mfxU16*)lockedRect.pData;
277+
ptr->U16 = ptr->Y16 + 1;
278+
ptr->V16 = ptr->Y16 + 3;
279+
break;
280+
case DXGI_FORMAT_Y410:
281+
ptr->PitchHigh = (mfxU16)(lockedRect.RowPitch / (1 << 16));
282+
ptr->PitchLow = (mfxU16)(lockedRect.RowPitch % (1 << 16));
283+
ptr->Y410 = (mfxY410*)lockedRect.pData;
284+
ptr->Y = 0;
285+
ptr->V = 0;
286+
ptr->A = 0;
287+
break;
288+
#endif
252289
default:
253290

254291
return MFX_ERR_LOCK_MEMORY;
@@ -518,10 +555,23 @@ DXGI_FORMAT D3D11FrameAllocator::ConverColortFormat(mfxU32 fourcc)
518555
case MFX_FOURCC_AYUV:
519556
return DXGI_FORMAT_AYUV;
520557

558+
#if (MFX_VERSION >= 1027)
559+
case MFX_FOURCC_Y210:
560+
return DXGI_FORMAT_Y210;
561+
case MFX_FOURCC_Y410:
562+
return DXGI_FORMAT_Y410;
563+
#endif
564+
#if (MFX_VERSION >= 1031)
565+
case MFX_FOURCC_P016:
566+
return DXGI_FORMAT_P016;
567+
case MFX_FOURCC_Y216:
568+
return DXGI_FORMAT_Y216;
569+
case MFX_FOURCC_Y416:
570+
return DXGI_FORMAT_Y416;
571+
#endif
521572
default:
522573
return DXGI_FORMAT_UNKNOWN;
523574
}
524575
}
525576
} // namespace base
526577
} // namespace owt
527-
#endif // #if defined(WEBRTC_WIN)

talk/owt/sdk/base/win/d3d11_allocator.h

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright (C) <2020> Intel Corporation
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
15
/******************************************************************************\
26
Copyright (c) 2005-2018, Intel Corporation
37
All rights reserved.
@@ -36,16 +40,20 @@ The original version of this sample may be obtained from
3640
or https://software.intel.com/en-us/media-client-solutions-support.
3741
\**********************************************************************************/
3842

39-
// Copyright (C) <2018> Intel Corporation
40-
//
41-
// SPDX-License-Identifier: Apache-2.0
42-
4343
// This file is borrowed from MSDK sample with some minor modification.
4444
#ifndef OWT_BASE_WIN_D3D11ALLOCATOR_H__
4545
#define OWT_BASE_WIN_D3D11ALLOCATOR_H__
4646

47-
#include "base_allocator.h"
47+
#include <d3d11.h>
4848
#include <limits>
49+
#include <map>
50+
#include <vector>
51+
#include <windows.h>
52+
#include "base_allocator.h"
53+
54+
55+
struct ID3D11VideoDevice;
56+
struct ID3D11VideoContext;
4957

5058
namespace owt {
5159
namespace base {
@@ -134,15 +142,6 @@ class MFXReadWriteMid
134142
mfxMemId m_mid_to_report;
135143
};
136144

137-
#if defined(WEBRTC_WIN)
138-
139-
#include <d3d11.h>
140-
#include <vector>
141-
#include <map>
142-
143-
struct ID3D11VideoDevice;
144-
struct ID3D11VideoContext;
145-
146145
struct D3D11AllocatorParams : mfxAllocatorParams
147146
{
148147
ID3D11Device *pDevice;
@@ -281,5 +280,5 @@ class D3D11FrameAllocator: public BaseFrameAllocator
281280
};
282281
} // namespace base
283282
} // namespace owt
284-
#endif // #if defined(WEBRTC_WIN)
283+
285284
#endif // OWT_BASE_WIN_D3D11ALLOCATOR_H__

talk/owt/sdk/base/win/d3dnativeframe.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@ struct NativeD3DSurfaceHandle {
1818
int height_; // height of the frame passing from decoder
1919
};
2020

21-
}
21+
// We keep D3D11ImageHandle definition in videorendererinterface,
22+
// as we may allow external renderer to accept the same handle.
23+
} // namespace base
24+
} // namespace owt
2225
#endif // OWT_BASE_WIN_D3DNATIVEFRAME_H

0 commit comments

Comments
 (0)