2016-05-14 02:03:18 +02:00
|
|
|
/*
|
2018-11-19 09:52:37 +01:00
|
|
|
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
|
2016-05-14 02:03:18 +02:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/video_coding/codecs/vp9/include/vp9.h"
|
2018-06-28 10:59:02 -07:00
|
|
|
|
2019-09-17 17:06:18 +02:00
|
|
|
#include <memory>
|
|
|
|
|
|
2022-07-05 21:06:28 +09:00
|
|
|
#include "absl/container/inlined_vector.h"
|
2020-12-09 20:58:21 +01:00
|
|
|
#include "api/transport/field_trial_based_config.h"
|
2022-05-05 14:37:05 +02:00
|
|
|
#include "api/video_codecs/scalability_mode.h"
|
2018-06-28 10:59:02 -07:00
|
|
|
#include "api/video_codecs/sdp_video_format.h"
|
2021-04-19 09:09:26 +02:00
|
|
|
#include "api/video_codecs/vp9_profile.h"
|
2020-12-09 20:58:21 +01:00
|
|
|
#include "modules/video_coding/codecs/vp9/libvpx_vp9_decoder.h"
|
|
|
|
|
#include "modules/video_coding/codecs/vp9/libvpx_vp9_encoder.h"
|
2022-05-24 16:04:43 +02:00
|
|
|
#include "modules/video_coding/svc/create_scalability_structure.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/checks.h"
|
2018-11-25 22:45:22 -05:00
|
|
|
#include "vpx/vp8cx.h"
|
|
|
|
|
#include "vpx/vp8dx.h"
|
|
|
|
|
#include "vpx/vpx_codec.h"
|
2016-05-14 02:03:18 +02:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2022-07-05 21:06:28 +09:00
|
|
|
std::vector<SdpVideoFormat> SupportedVP9Codecs(bool add_scalability_modes) {
|
2018-11-19 09:52:37 +01:00
|
|
|
#ifdef RTC_ENABLE_VP9
|
2018-11-25 22:45:22 -05:00
|
|
|
// Profile 2 might not be available on some platforms until
|
|
|
|
|
// https://bugs.chromium.org/p/webm/issues/detail?id=1544 is solved.
|
|
|
|
|
static bool vpx_supports_high_bit_depth =
|
|
|
|
|
(vpx_codec_get_caps(vpx_codec_vp9_cx()) & VPX_CODEC_CAP_HIGHBITDEPTH) !=
|
|
|
|
|
0 &&
|
|
|
|
|
(vpx_codec_get_caps(vpx_codec_vp9_dx()) & VPX_CODEC_CAP_HIGHBITDEPTH) !=
|
|
|
|
|
0;
|
|
|
|
|
|
2022-07-05 21:06:28 +09:00
|
|
|
absl::InlinedVector<ScalabilityMode, kScalabilityModeCount> scalability_modes;
|
|
|
|
|
if (add_scalability_modes) {
|
|
|
|
|
for (const auto scalability_mode : kAllScalabilityModes) {
|
|
|
|
|
if (ScalabilityStructureConfig(scalability_mode).has_value()) {
|
|
|
|
|
scalability_modes.push_back(scalability_mode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-19 09:52:37 +01:00
|
|
|
std::vector<SdpVideoFormat> supported_formats{SdpVideoFormat(
|
|
|
|
|
cricket::kVp9CodecName,
|
2022-07-05 21:06:28 +09:00
|
|
|
{{kVP9FmtpProfileId, VP9ProfileToString(VP9Profile::kProfile0)}},
|
|
|
|
|
scalability_modes)};
|
2018-11-25 22:45:22 -05:00
|
|
|
if (vpx_supports_high_bit_depth) {
|
|
|
|
|
supported_formats.push_back(SdpVideoFormat(
|
|
|
|
|
cricket::kVp9CodecName,
|
2022-07-05 21:06:28 +09:00
|
|
|
{{kVP9FmtpProfileId, VP9ProfileToString(VP9Profile::kProfile2)}},
|
|
|
|
|
scalability_modes));
|
2018-11-25 22:45:22 -05:00
|
|
|
}
|
2020-06-11 13:41:06 +02:00
|
|
|
|
|
|
|
|
return supported_formats;
|
|
|
|
|
#else
|
|
|
|
|
return std::vector<SdpVideoFormat>();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<SdpVideoFormat> SupportedVP9DecoderCodecs() {
|
|
|
|
|
#ifdef RTC_ENABLE_VP9
|
|
|
|
|
std::vector<SdpVideoFormat> supported_formats = SupportedVP9Codecs();
|
2022-06-22 14:42:48 +02:00
|
|
|
// The WebRTC internal decoder supports VP9 profile 1 and 3. However, there's
|
|
|
|
|
// currently no way of sending VP9 profile 1 or 3 using the internal encoder.
|
2020-06-11 13:41:06 +02:00
|
|
|
// It would require extended support for I444, I422, and I440 buffers.
|
|
|
|
|
supported_formats.push_back(SdpVideoFormat(
|
|
|
|
|
cricket::kVp9CodecName,
|
|
|
|
|
{{kVP9FmtpProfileId, VP9ProfileToString(VP9Profile::kProfile1)}}));
|
2022-06-22 14:42:48 +02:00
|
|
|
supported_formats.push_back(SdpVideoFormat(
|
|
|
|
|
cricket::kVp9CodecName,
|
|
|
|
|
{{kVP9FmtpProfileId, VP9ProfileToString(VP9Profile::kProfile3)}}));
|
2018-11-19 09:52:37 +01:00
|
|
|
return supported_formats;
|
|
|
|
|
#else
|
2018-06-28 10:59:02 -07:00
|
|
|
return std::vector<SdpVideoFormat>();
|
2018-11-19 09:52:37 +01:00
|
|
|
#endif
|
2016-05-14 02:03:18 +02:00
|
|
|
}
|
|
|
|
|
|
2017-11-13 14:10:02 +01:00
|
|
|
std::unique_ptr<VP9Encoder> VP9Encoder::Create() {
|
2018-11-19 09:52:37 +01:00
|
|
|
#ifdef RTC_ENABLE_VP9
|
2020-12-09 20:58:21 +01:00
|
|
|
return std::make_unique<LibvpxVp9Encoder>(cricket::VideoCodec(),
|
|
|
|
|
LibvpxInterface::Create(),
|
|
|
|
|
FieldTrialBasedConfig());
|
2018-11-19 09:52:37 +01:00
|
|
|
#else
|
2021-11-15 16:57:07 +01:00
|
|
|
RTC_DCHECK_NOTREACHED();
|
2016-05-14 02:03:18 +02:00
|
|
|
return nullptr;
|
2018-11-19 09:52:37 +01:00
|
|
|
#endif
|
2016-05-14 02:03:18 +02:00
|
|
|
}
|
|
|
|
|
|
2018-06-28 10:59:02 -07:00
|
|
|
std::unique_ptr<VP9Encoder> VP9Encoder::Create(
|
|
|
|
|
const cricket::VideoCodec& codec) {
|
2018-11-19 09:52:37 +01:00
|
|
|
#ifdef RTC_ENABLE_VP9
|
2020-12-09 20:58:21 +01:00
|
|
|
return std::make_unique<LibvpxVp9Encoder>(codec, LibvpxInterface::Create(),
|
|
|
|
|
FieldTrialBasedConfig());
|
2018-11-19 09:52:37 +01:00
|
|
|
#else
|
2021-11-15 16:57:07 +01:00
|
|
|
RTC_DCHECK_NOTREACHED();
|
2018-06-28 10:59:02 -07:00
|
|
|
return nullptr;
|
2018-11-19 09:52:37 +01:00
|
|
|
#endif
|
2016-05-14 02:03:18 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-05 14:37:05 +02:00
|
|
|
bool VP9Encoder::SupportsScalabilityMode(ScalabilityMode scalability_mode) {
|
2022-05-24 16:04:43 +02:00
|
|
|
return ScalabilityStructureConfig(scalability_mode).has_value();
|
2021-09-15 10:56:04 +00:00
|
|
|
}
|
|
|
|
|
|
2017-11-13 14:10:02 +01:00
|
|
|
std::unique_ptr<VP9Decoder> VP9Decoder::Create() {
|
2018-11-19 09:52:37 +01:00
|
|
|
#ifdef RTC_ENABLE_VP9
|
2020-12-09 20:58:21 +01:00
|
|
|
return std::make_unique<LibvpxVp9Decoder>();
|
2018-11-19 09:52:37 +01:00
|
|
|
#else
|
2021-11-15 16:57:07 +01:00
|
|
|
RTC_DCHECK_NOTREACHED();
|
2016-05-14 02:03:18 +02:00
|
|
|
return nullptr;
|
2018-11-19 09:52:37 +01:00
|
|
|
#endif
|
2016-05-14 02:03:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|