Skip to content

Commit 07b2adb

Browse files
committed
Use vhost user media binary rather than crosvm flag.
Bug: b/496625526 Test: ``` bazel run //cuttlefish/package:cvd -- create --host_path=$HOME/dl --product_path=$HOME/dl --host_substitutions=bin/assemble_cvd,bin/run_cvd,bin/vhu_media_simple_device --media="type=v4l2_emulated_camera" adb shell "su 0 v4l2-ctl --list-devices" ```
1 parent 758b916 commit 07b2adb

11 files changed

Lines changed: 283 additions & 119 deletions

File tree

base/cvd/cuttlefish/host/commands/run_cvd/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ cf_cc_binary(
9393
"//cuttlefish/host/commands/run_cvd/launch:vhal_proxy_server",
9494
"//cuttlefish/host/commands/run_cvd/launch:vhost_device_vsock",
9595
"//cuttlefish/host/commands/run_cvd/launch:vhost_input_devices",
96+
"//cuttlefish/host/commands/run_cvd/launch:vhost_user_media_devices",
9697
"//cuttlefish/host/commands/run_cvd/launch:webrtc_controller",
9798
"//cuttlefish/host/commands/run_cvd/launch:wmediumd_server",
9899
"//cuttlefish/host/libs/config:config_flag",

base/cvd/cuttlefish/host/commands/run_cvd/launch/BUILD.bazel

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ cf_cc_library(
443443
"//cuttlefish/host/commands/run_cvd/launch:enable_multitouch",
444444
"//cuttlefish/host/commands/run_cvd/launch:sensors_socket_pair",
445445
"//cuttlefish/host/commands/run_cvd/launch:vhost_input_devices",
446+
"//cuttlefish/host/commands/run_cvd/launch:vhost_user_media_devices",
446447
"//cuttlefish/host/commands/run_cvd/launch:webrtc_controller",
447448
"//cuttlefish/host/libs/config:config_utils",
448449
"//cuttlefish/host/libs/config:custom_actions",
@@ -572,6 +573,28 @@ cf_cc_library(
572573
],
573574
)
574575

576+
cf_cc_library(
577+
name = "vhost_user_media_devices",
578+
srcs = ["vhost_user_media_devices.cpp"],
579+
hdrs = ["vhost_user_media_devices.h"],
580+
deps = [
581+
"//cuttlefish/common/libs/fs",
582+
"//cuttlefish/common/libs/utils:files",
583+
"//cuttlefish/common/libs/utils:subprocess",
584+
"//cuttlefish/host/commands/run_cvd/launch:enable_multitouch",
585+
"//cuttlefish/host/commands/run_cvd/launch:log_tee_creator",
586+
"//cuttlefish/host/libs/config:cuttlefish_config",
587+
"//cuttlefish/host/libs/config:guest_os",
588+
"//cuttlefish/host/libs/config:known_paths",
589+
"//cuttlefish/host/libs/feature",
590+
"//cuttlefish/result",
591+
"//libbase",
592+
"@abseil-cpp//absl/log",
593+
"@fmt",
594+
"@fruit",
595+
],
596+
)
597+
575598
cf_cc_library(
576599
name = "webrtc_controller",
577600
srcs = ["webrtc_controller.cpp"],
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//
2+
// Copyright (C) 2026 The Android Open Source Project
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
#include "cuttlefish/host/commands/run_cvd/launch/vhost_user_media_devices.h"
17+
18+
#include <fcntl.h>
19+
20+
#include <string>
21+
#include <unordered_set>
22+
#include <utility>
23+
#include <vector>
24+
25+
#include <fruit/component.h>
26+
#include <fruit/fruit_forward_decls.h>
27+
#include <fruit/macro.h>
28+
29+
#include "cuttlefish/common/libs/fs/shared_fd.h"
30+
#include "cuttlefish/common/libs/utils/subprocess.h"
31+
#include "cuttlefish/host/commands/run_cvd/launch/log_tee_creator.h"
32+
#include "cuttlefish/host/libs/config/cuttlefish_config.h"
33+
#include "cuttlefish/host/libs/config/known_paths.h"
34+
#include "cuttlefish/host/libs/feature/command_source.h"
35+
#include "cuttlefish/host/libs/feature/feature.h"
36+
#include "cuttlefish/result/result.h"
37+
38+
namespace cuttlefish {
39+
namespace {
40+
41+
using Subprocess::StdIOChannel::kStdErr;
42+
43+
Command NewCommand(const std::string& socket_path) {
44+
Command cmd(VhostUserMediaSimpleDeviceBinary());
45+
cmd.AddParameter("--socket-path=", socket_path);
46+
cmd.AddParameter("--verbosity=", "debug");
47+
cmd.RedirectStdIO(Subprocess::StdIOChannel::kStdOut,
48+
SharedFD::Open("/dev/null", O_WRONLY));
49+
return cmd;
50+
}
51+
52+
class VhostUserMediaDevices : public CommandSource {
53+
public:
54+
INJECT(VhostUserMediaDevices(const CuttlefishConfig::InstanceSpecific& instance, LogTeeCreator& log_tee)) : instance_(instance), log_tee_(log_tee) {}
55+
56+
// CommandSource
57+
Result<std::vector<MonitorCommand>> Commands() override {
58+
std::vector<MonitorCommand> commands;
59+
for (int index = 0; index < instance_.media_configs().size(); index++) {
60+
Command cmd = NewCommand(instance_.media_socket_path(index));
61+
Command cmd_log_tee = CF_EXPECT(
62+
log_tee_.CreateLogTee(cmd, "vhu_media_simple_device", kStdErr), "Failed to create log tee command for media device");
63+
commands.emplace_back(std::move(cmd));
64+
commands.emplace_back(std::move(cmd_log_tee));
65+
}
66+
return commands;
67+
}
68+
69+
private:
70+
// SetupFeature
71+
std::string Name() const override { return "VhostUserMediaDevices"; }
72+
std::unordered_set<SetupFeature*> Dependencies() const override { return {}; }
73+
Result<void> ResultSetup() override { return {}; }
74+
75+
const CuttlefishConfig::InstanceSpecific& instance_;
76+
LogTeeCreator& log_tee_;
77+
};
78+
79+
} // namespace
80+
81+
fruit::Component<fruit::Required<const CuttlefishConfig::InstanceSpecific, LogTeeCreator>>
82+
VhostUserMediaDevicesComponent() {
83+
return fruit::createComponent()
84+
.addMultibinding<CommandSource, VhostUserMediaDevices>();
85+
}
86+
87+
} // namespace cuttlefish
88+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// Copyright (C) 2026 The Android Open Source Project
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
#pragma once
17+
18+
#include <fruit/fruit.h>
19+
20+
#include "cuttlefish/host/commands/run_cvd/launch/log_tee_creator.h"
21+
#include "cuttlefish/host/libs/config/cuttlefish_config.h"
22+
23+
namespace cuttlefish {
24+
25+
fruit::Component<fruit::Required<const CuttlefishConfig::InstanceSpecific, LogTeeCreator>>
26+
VhostUserMediaDevicesComponent();
27+
28+
} // namespace cuttlefish
29+

base/cvd/cuttlefish/host/commands/run_cvd/main.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
#include "cuttlefish/host/commands/run_cvd/launch/uwb_connector.h"
6565
#include "cuttlefish/host/commands/run_cvd/launch/vhal_proxy_server.h"
6666
#include "cuttlefish/host/commands/run_cvd/launch/vhost_device_vsock.h"
67+
#include "cuttlefish/host/commands/run_cvd/launch/vhost_user_media_devices.h"
6768
#include "cuttlefish/host/commands/run_cvd/launch/webrtc_controller.h"
6869
#include "cuttlefish/host/commands/run_cvd/launch/wmediumd_server.h"
6970
#include "cuttlefish/host/commands/run_cvd/reporting.h"
@@ -172,6 +173,7 @@ fruit::Component<> runCvdComponent(
172173
.install(launchStreamerComponent)
173174
.install(AutoCmd<VhalProxyServer>::Component)
174175
.install(Ti50EmulatorComponent)
176+
.install(VhostUserMediaDevicesComponent)
175177
#endif
176178
.install(CvdallocComponent)
177179
.install(AdbConfigComponent)

base/cvd/cuttlefish/host/libs/config/cuttlefish_config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ class CuttlefishConfig {
353353

354354
std::string touch_socket_path(int touch_dev_idx) const;
355355

356+
std::string media_socket_path(int index) const;
357+
356358
std::string launcher_log_path() const;
357359

358360
std::string sdcard_path() const;

base/cvd/cuttlefish/host/libs/config/cuttlefish_config_instance.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,6 +1848,10 @@ std::string CuttlefishConfig::InstanceSpecific::touch_socket_path(
18481848
return PerInstanceInternalUdsPath(name);
18491849
}
18501850

1851+
std::string CuttlefishConfig::InstanceSpecific::media_socket_path(int index) const {
1852+
return PerInstanceInternalUdsPath(absl::StrCat("media_", index, ".sock"));
1853+
}
1854+
18511855
static constexpr char kFrameSockPath[] = "frame_sock_path";
18521856
void CuttlefishConfig::MutableInstanceSpecific::set_frames_socket_path(
18531857
const std::string& frame_socket_path) {

base/cvd/cuttlefish/host/libs/config/known_paths.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,5 +221,9 @@ std::string VhostUserInputBinary() {
221221
return HostBinaryPath("cf_vhost_user_input");
222222
}
223223

224+
std::string VhostUserMediaSimpleDeviceBinary() {
225+
return HostBinaryPath("vhu_media_simple_device");
226+
}
227+
224228
} // namespace cuttlefish
225229

base/cvd/cuttlefish/host/libs/config/known_paths.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ std::string UnpackBootimgBinary();
6969
std::string VhalProxyServerBinary();
7070
std::string VhalProxyServerConfig();
7171
std::string VhostUserInputBinary();
72+
std::string VhostUserMediaSimpleDeviceBinary();
7273
std::string WebRtcBinary();
7374
std::string WebRtcSigServerBinary();
7475
std::string WebRtcSigServerProxyBinary();

base/cvd/cuttlefish/host/libs/vm_manager/crosvm_manager.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -929,9 +929,10 @@ Result<std::vector<MonitorCommand>> CrosvmManager::StartCommands(
929929
crosvm_cmd.Cmd().AddParameter("--pflash=", PflashPath(instance));
930930
}
931931

932-
for (const auto& config : instance.media_configs()) {
932+
for (int index = 0; index < instance.media_configs().size(); index++) {
933+
auto config = instance.media_configs()[index];
933934
if (config.type == CuttlefishConfig::MediaType::kV4l2EmulatedCamera) {
934-
crosvm_cmd.Cmd().AddParameter("--simple-media-device");
935+
crosvm_cmd.Cmd().AddParameter("--vhost-user=type=media,socket=", instance.media_socket_path(index));
935936
} else if (config.type == CuttlefishConfig::MediaType::kV4l2Proxy) {
936937
crosvm_cmd.Cmd().AddParameter("--v4l2-proxy=", "/dev/video0");
937938
}

0 commit comments

Comments
 (0)