-
Notifications
You must be signed in to change notification settings - Fork 197
Add NVENC AV1 hardware video encoding for WebRTC #2240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package(default_visibility = ["//visibility:public"]) | ||
|
|
||
| cc_library( | ||
| name = "nv_headers", | ||
| hdrs = glob(["include/ffnvcodec/*.h"]), | ||
| includes = ["include/ffnvcodec"], | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,26 @@ | |
| ############################################################################### | ||
|
|
||
| bazel_dep(name = "abseil-cpp", version = "20260107.0") | ||
| bazel_dep(name = "hermetic_cc_toolchain", version = "4.0.1") | ||
|
|
||
| # Hermetic C/C++ toolchain using zig cc for cross-compilation and GLIBC targeting. | ||
| # Use with: bazel build ... --extra_toolchains=@zig_sdk//toolchain:linux_amd64_gnu.2.36 | ||
| zig_toolchains = use_extension("@hermetic_cc_toolchain//toolchain:ext.bzl", "toolchains") | ||
| use_repo(zig_toolchains, "zig_sdk") | ||
|
|
||
| # CUDA support for NVENC | ||
| bazel_dep(name = "rules_cuda", version = "0.2.5") | ||
| git_override( | ||
| module_name = "rules_cuda", | ||
| commit = "32414222a7997ee66035d51404fc5427df94c699", | ||
| remote = "https://github.com/bazel-contrib/rules_cuda.git", | ||
| ) | ||
| cuda = use_extension("@rules_cuda//cuda:extensions.bzl", "toolchain") | ||
| cuda.local_toolchain( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we'll need to make all of the nvenc providers dependent on cuda being available or not and to provide some kind of bazel flag to toggle it on. As is, running on a freshly re-imaged machine (and I imagine in CI will be similar) shows It looks like https://github.com/bazel-contrib/rules_cuda/tree/main/examples/if_cuda provides a mechanism. For and then potentially add I believe you would also have to add |
||
| name = "local_cuda", | ||
| toolkit_path = "", | ||
| ) | ||
| use_repo(cuda, cuda = "local_cuda") | ||
| bazel_dep(name = "aspect_bazel_lib", version = "2.19.3") | ||
| bazel_dep(name = "aspect_rules_lint", version = "1.4.4", dev_dependency = True) | ||
| bazel_dep(name = "bazel_skylib", version = "1.8.2", dev_dependency = True) | ||
|
|
@@ -65,3 +85,15 @@ include("//toolchain:bazel.MODULE.bazel") | |
| include("//toolchain:llvm.MODULE.bazel") | ||
| include("//toolchain:python.MODULE.bazel") | ||
| include("//toolchain:rust.MODULE.bazel") | ||
|
|
||
| # NVENC video encoding headers (nv-codec-headers SDK 12.1) | ||
| http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
| http_archive( | ||
| name = "nv_codec_headers", | ||
| build_file = "@//:BUILD.nv_codec_headers.bazel", | ||
| strip_prefix = "nv-codec-headers-n12.1.14.0", | ||
| urls = [ | ||
| "https://github.com/FFmpeg/nv-codec-headers/archive/refs/tags/n12.1.14.0.tar.gz", | ||
| ], | ||
| sha256 = "2fefaa227d2a3b4170797796425a59d1dd2ed5fd231db9b4244468ba327acd0b", | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * Copyright (C) 2025 The Android Open Source Project | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #include "cuttlefish/host/frontend/webrtc/cvd_abgr_video_frame_buffer.h" | ||
|
|
||
| #include <cstring> | ||
|
|
||
| namespace cuttlefish { | ||
|
|
||
| CvdAbgrVideoFrameBuffer::CvdAbgrVideoFrameBuffer(int width, int height, | ||
| uint32_t format, int stride, | ||
| const uint8_t* data) | ||
| : width_(width), height_(height), format_(format), stride_(stride) { | ||
| // Allocate buffer: height * stride | ||
| size_t size = height * stride; | ||
| data_.resize(size); | ||
| if (data) { | ||
| std::memcpy(data_.data(), data, size); | ||
| } | ||
| } | ||
|
|
||
| std::unique_ptr<VideoFrameBuffer> CvdAbgrVideoFrameBuffer::Clone() const { | ||
| return std::make_unique<CvdAbgrVideoFrameBuffer>(*this); | ||
| } | ||
|
|
||
| } // namespace cuttlefish |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * Copyright (C) 2025 The Android Open Source Project | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
| #include <vector> | ||
|
|
||
| #include "cuttlefish/host/libs/screen_connector/video_frame_buffer.h" | ||
|
|
||
| namespace cuttlefish { | ||
|
|
||
| class CvdAbgrVideoFrameBuffer : public VideoFrameBuffer { | ||
| public: | ||
| CvdAbgrVideoFrameBuffer(int width, int height, uint32_t format, int stride, | ||
| const uint8_t* data); | ||
| ~CvdAbgrVideoFrameBuffer() override = default; | ||
|
|
||
| int width() const override { return width_; } | ||
| int height() const override { return height_; } | ||
|
|
||
| uint8_t* Data() const override { return const_cast<uint8_t*>(data_.data()); } | ||
| int Stride() const override { return stride_; } | ||
| std::size_t DataSize() const override { return data_.size(); } | ||
| uint32_t PixelFormat() const override { return format_; } | ||
|
|
||
| std::unique_ptr<VideoFrameBuffer> Clone() const override; | ||
|
|
||
| private: | ||
| int width_; | ||
| int height_; | ||
| uint32_t format_; | ||
| int stride_; | ||
| std::vector<uint8_t> data_; | ||
| }; | ||
|
|
||
| } // namespace cuttlefish |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move file into the
build_externalsubdirectory.