Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Commit e639ed8

Browse files
shivasku82sysopenci
authored andcommitted
start host camera service from vm-manager
added changes to download source from latest host camera repo, build and start binaries when user specify camera_med=y Tracked-On: OAM-102361 Signed-off-by: shivasku82 <shiva.kumara.rudrappa@intel.com>
1 parent c87e22f commit e639ed8

5 files changed

Lines changed: 125 additions & 2 deletions

File tree

sample/guest01.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ passthrough_pci=0000:00:14.0,
7878
[mediation]
7979
#battery_med=/home/gvt/caas/scripts/batsys
8080
#thermal_med=/home/gvt/caas/scripts/thermsys
81+
#camera_med=y
8182

8283
[guest_control]
8384
#time_keep=/home/gvt/caas/scripts/guest_time_keeping.sh

scripts/setup_host.sh

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,115 @@ function error() {
2121
echo "$BASH_SOURCE Failed at line($line): $cmd"
2222
}
2323

24+
25+
function install_virtualcamera_service() {
26+
service_file=virtualcamera.service
27+
touch $service_file
28+
cat /dev/null > $service_file
29+
30+
echo "[Unit]" > $service_file
31+
echo -e "Description=Virtual Camera Auto Start\n" >> $service_file
32+
echo -e "After=default.target\n" >> $service_file
33+
echo "[Service]" >> $service_file
34+
echo -e "ExecStartPre=/usr/sbin/modprobe v4l2loopback devices=2 video_nr=6,7 card_label=\"VCam0\",\"VCam1\" exclusive_caps=1,1\n" >> $service_file
35+
echo -e "ExecStart=/usr/bin/IntelCameraService -i /dev/video0 -o /dev/video6 -o /dev/video7\n" >> $service_file
36+
echo -e "SuccessExitStatus=255\n" >> $service_file
37+
echo -e "Restart=always\n" >> $service_file
38+
echo -e "RestartSec=10\n" >> $service_file
39+
echo "[Install]" >> $service_file
40+
echo -e "WantedBy=default.target\n" >> $service_file
41+
42+
cat $service_file
43+
sudo mv $service_file /etc/systemd/system/
44+
sudo systemctl enable virtualcamera.service
45+
sudo systemctl restart virtualcamera.service
46+
}
47+
48+
function install_virtual_camera() {
49+
KERNELRELEASE=`uname -r`
50+
KERNEL_DIR=/lib/modules/${KERNELRELEASE}/kernel/drivers/media/v4l2-core/
51+
CURRENT_DIR=`pwd`
52+
53+
echo "Clean environment..."
54+
if [ -x v4l2loopback ]; then
55+
rm -rf v4l2loopback
56+
fi
57+
IS_SERVICE_RUNNING=`ps -fe | grep IntelCameraService | grep -v "grep" | wc -l`
58+
if [ $IS_SERVICE_RUNNING == 1 ]; then
59+
echo "Stop running IntelCameraService"
60+
sudo systemctl stop virtualcamera.service
61+
fi
62+
IS_V4L2LOOPBACK_EXIST=`lsmod | grep "v4l2loopback" | wc -l`
63+
if [ $IS_V4L2LOOPBACK_EXIST != 0 ]; then
64+
echo "rmmod v4l2loopback..."
65+
sudo rmmod v4l2loopback
66+
fi
67+
68+
echo "Install v4l2loopback driver..."
69+
git clone https://github.com/umlaeute/v4l2loopback.git
70+
cd v4l2loopback
71+
git checkout 81b8df79107d1fbf392fdcbaa051bd227a9c94c1
72+
73+
git apply ../scripts/cam_sharing/0001-Netlink-sync.patch
74+
make
75+
76+
echo "cp " ${DRIVER} ${KERNEL_DIR}/v4l2loopback.ko
77+
if [ -f ${KERNEL_DIR}/v4l2loopback.ko ]; then
78+
echo "Backup original v4l2loopback.ko"
79+
mv ${KERNEL_DIR}/v4l2loopback.ko ${KERNEL_DIR}/v4l2loopback.ko.orig
80+
fi
81+
sudo cp v4l2loopback.ko ${KERNEL_DIR}
82+
depmod
83+
cd ..
84+
if [ -x v4l2loopback ]; then
85+
rm -rf v4l2loopback
86+
fi
87+
88+
echo "Install IntelCameraService in /usr/bin/ ..."
89+
sudo cp ./scripts/cam_sharing/IntelCameraService /usr/bin/
90+
91+
echo "Install virtualcamera.service in /lib/systemd/system/ ..."
92+
install_virtualcamera_service
93+
94+
echo "Complete virtual camera installation."
95+
96+
}
97+
98+
function install_host_service() {
99+
wget https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
100+
mkdir -p ffmpeg_sources
101+
cd ffmpeg_sources && tar xjvf ../ffmpeg-snapshot.tar.bz2
102+
cd ffmpeg && PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-libs="-lpthread -lm" --enable-shared && PATH="$HOME/bin:$PATH"
103+
make
104+
make install
105+
hash -r
106+
sudo cp -r $HOME/ffmpeg_build/lib/*.* /usr/lib/
107+
sudo cp -r $HOME/ffmpeg_build/lib/*.* /usr/local/lib
108+
cd ../..
109+
sudo rm -rf ffmpeg_sources
110+
sudo rm -rf ffmpeg-snapshot.tar.bz2
111+
sudo rm -rf $HOME/ffmpeg_build
112+
113+
sudo apt-get install libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libavresample-dev libavdevice-dev -y
114+
sudo apt-get install ffmpeg -y
115+
sudo apt-get install build-essential clang -y
116+
117+
sudo apt-get install --yes cmake
118+
mkdir -p host_camera
119+
cd host_camera
120+
git clone https://github.com/projectceladon/host-camera-server.git
121+
cd host-camera-server
122+
git checkout ba2707587e8f3ad03714d5e3ed47844e83cde7c0
123+
mkdir build
124+
cd build
125+
cmake ..
126+
cmake --build .
127+
sudo cp source/libvhal-client.so* /usr/lib
128+
sudo cp host_camera_service/stream /usr/local/bin/
129+
cd ../../..
130+
sudo rm -rf host_camera
131+
}
132+
24133
function ubu_changes_require(){
25134
echo "Please make sure your apt is working"
26135
echo "If you run the installation first time, reboot is required"
@@ -546,6 +655,9 @@ check_network
546655
check_kernel_version
547656

548657
ubu_changes_require
658+
install_host_service
659+
install_virtual_camera
660+
549661
ubu_install_qemu_gvt
550662
ubu_build_ovmf_gvt
551663
ubu_enable_host_gvt

src/guest/guest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ keyfile_group_t g_group[] = {
3232
{ "vtpm", { "bin_path", "data_dir", NULL } },
3333
{ "rpmb", { "bin_path", "data_dir", NULL } },
3434
{ "passthrough", { "passthrough_pci", NULL}},
35-
{ "mediation", { "battery_med", "thermal_med", NULL }},
35+
{ "mediation", { "battery_med", "thermal_med", "camera_med",NULL }},
3636
{ "aaf", { "path", "support_suspend", "audio_type", NULL } },
3737
{ "guest_control", { "time_keep", "pm_control", NULL }},
3838
{ "extra", { "cmd", "service", NULL } },

src/guest/start.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,10 @@ static int run_thermal_mediation_daemon(char *path) {
761761
return execute_cmd(path, NULL, 0, 1);
762762
}
763763

764+
static int run_camera_mediation_daemon(char *path) {
765+
return execute_cmd(path, NULL, 0, 1);
766+
}
767+
764768
static int run_guest_timekeep(char *path, char *p, size_t size, char *pipe_name) {
765769
int cx = 0;
766770
const char *pipe = pipe_name ? pipe_name : "qmp-time-keep-pipe";
@@ -1152,6 +1156,11 @@ int start_guest(char *name)
11521156
if (val != NULL && (strcmp("", val) != 0))
11531157
run_thermal_mediation_daemon(val);
11541158

1159+
val = g_key_file_get_string(gkf, g->name, g->key[CAMERA_MED], NULL);
1160+
if (val != NULL && (strcasecmp("y", val) == 0)) {
1161+
run_camera_mediation_daemon("/usr/local/bin/stream");
1162+
}
1163+
11551164
/* run guest pm */
11561165
g = &g_group[GROUP_GUEST_SERVICE];
11571166

@@ -1201,7 +1210,7 @@ int start_guest(char *name)
12011210
cx = snprintf(p, size, "%s", fixed_cmd);
12021211
p += cx; size -= cx;
12031212

1204-
run_vtpm_daemon();
1213+
run_vtpm_daemon();
12051214

12061215
cleanup_rpmb();
12071216
run_rpmb_daemon();

src/include/guest/guest.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ enum {
197197
/* Sub key of group mediation */
198198
BATTERY_MED = 0,
199199
THERMAL_MED,
200+
CAMERA_MED,
200201

201202
/* Sub key of group aaf */
202203
AAF_PATH = 0,

0 commit comments

Comments
 (0)