Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
2
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
8b9f917
Documentation
LICENSES
arch
block
certs
crypto
drivers
accessibility
acpi
amba
android
ata
atm
auxdisplay
base
bcma
block
bluetooth
bus
cdrom
char
clk
clocksource
connector
counter
cpufreq
cpuidle
crypto
dax
dca
devfreq
dio
dma-buf
dma
edac
eisa
extcon
firewire
firmware
fpga
fsi
gnss
gpio
gpu
greybus
hid
hsi
hv
hwmon
hwspinlock
hwtracing
i2c
i3c
ide
idle
iio
infiniband
input
interconnect
iommu
ipack
irqchip
isdn
leds
lightnvm
macintosh
mailbox
mcb
md
media
cec
common
dvb-core
dvb-frontends
firewire
i2c
mc
mmc
pci
platform
am437x
atmel
cadence
cec-gpio
coda
cros-ec-cec
davinci
exynos-gsc
exynos4-is
marvell-ccic
meson
mtk-jpeg
mtk-mdp
mtk-vcodec
mtk-vpu
omap
omap3isp
qcom
rcar-vin
rockchip
s3c-camif
s5p-cec
s5p-g2d
s5p-jpeg
s5p-mfc
seco-cec
sti
stm32
sunxi
tegra-cec
ti-vpe
vicodec
vimc
Kconfig
Makefile
vimc-capture.c
vimc-common.c
vimc-common.h
vimc-core.c
vimc-debayer.c
vimc-scaler.c
vimc-sensor.c
vimc-streamer.c
vimc-streamer.h
vivid
vsp1
xilinx
Kconfig
Makefile
aspeed-video.c
fsl-viu.c
imx-pxp.c
imx-pxp.h
m2m-deinterlace.c
mx2_emmaprp.c
pxa_camera.c
rcar-fcp.c
rcar_drif.c
rcar_fdp1.c
rcar_jpu.c
renesas-ceu.c
sh_veu.c
sh_vou.c
via-camera.c
via-camera.h
video-mux.c
vim2m.c
radio
rc
spi
tuners
usb
v4l2-core
Kconfig
Makefile
memory
memstick
message
mfd
misc
mmc
mtd
mux
net
nfc
ntb
nubus
nvdimm
nvme
nvmem
of
opp
oprofile
parisc
parport
pci
pcmcia
perf
phy
pinctrl
platform
pnp
power
powercap
pps
ps3
ptp
pwm
rapidio
ras
regulator
remoteproc
reset
rpmsg
rtc
s390
sbus
scsi
sfi
sh
siox
slimbus
soc
soundwire
spi
spmi
ssb
staging
target
tc
tee
thermal
thunderbolt
tty
uio
usb
vfio
vhost
video
virt
virtio
visorbus
vlynq
vme
w1
watchdog
xen
zorro
Kconfig
Makefile
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
usr
virt
.clang-format
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Breadcrumbs
linux
/
drivers
/
media
/
platform
/
vimc
/
vimc-streamer.c
Blame
Blame
Latest commit
History
History
238 lines (208 loc) · 6.06 KB
Breadcrumbs
linux
/
drivers
/
media
/
platform
/
vimc
/
vimc-streamer.c
Top
File metadata and controls
Code
Blame
238 lines (208 loc) · 6.06 KB
Raw
// SPDX-License-Identifier: GPL-2.0+ /* * vimc-streamer.c Virtual Media Controller Driver * * Copyright (C) 2018 Lucas A. M. Magalhães <lucmaga@gmail.com> * */ #include <linux/init.h> #include <linux/freezer.h> #include <linux/kthread.h> #include "vimc-streamer.h" /** * vimc_get_source_entity - get the entity connected with the first sink pad * * @ent: reference media_entity * * Helper function that returns the media entity containing the source pad * linked with the first sink pad from the given media entity pad list. * * Return: The source pad or NULL, if it wasn't found. */ static struct media_entity *vimc_get_source_entity(struct media_entity *ent) { struct media_pad *pad; int i; for (i = 0; i < ent->num_pads; i++) { if (ent->pads[i].flags & MEDIA_PAD_FL_SOURCE) continue; pad = media_entity_remote_pad(&ent->pads[i]); return pad ? pad->entity : NULL; } return NULL; } /** * vimc_streamer_pipeline_terminate - Disable stream in all ved in stream * * @stream: the pointer to the stream structure with the pipeline to be * disabled. * * Calls s_stream to disable the stream in each entity of the pipeline * */ static void vimc_streamer_pipeline_terminate(struct vimc_stream *stream) { struct vimc_ent_device *ved; struct v4l2_subdev *sd; while (stream->pipe_size) { stream->pipe_size--; ved = stream->ved_pipeline[stream->pipe_size]; stream->ved_pipeline[stream->pipe_size] = NULL; if (!is_media_entity_v4l2_subdev(ved->ent)) continue; sd = media_entity_to_v4l2_subdev(ved->ent); v4l2_subdev_call(sd, video, s_stream, 0); } } /** * vimc_streamer_pipeline_init - Initializes the stream structure * * @stream: the pointer to the stream structure to be initialized * @ved: the pointer to the vimc entity initializing the stream * * Initializes the stream structure. Walks through the entity graph to * construct the pipeline used later on the streamer thread. * Calls vimc_streamer_s_stream() to enable stream in all entities of * the pipeline. * * Return: 0 if success, error code otherwise. */ static int vimc_streamer_pipeline_init(struct vimc_stream *stream, struct vimc_ent_device *ved) { struct media_entity *entity; struct video_device *vdev; struct v4l2_subdev *sd; int ret = 0; stream->pipe_size = 0; while (stream->pipe_size < VIMC_STREAMER_PIPELINE_MAX_SIZE) { if (!ved) { vimc_streamer_pipeline_terminate(stream); return -EINVAL; } stream->ved_pipeline[stream->pipe_size++] = ved; if (is_media_entity_v4l2_subdev(ved->ent)) { sd = media_entity_to_v4l2_subdev(ved->ent); ret = v4l2_subdev_call(sd, video, s_stream, 1); if (ret && ret != -ENOIOCTLCMD) { dev_err(ved->dev, "subdev_call error %s\n", ved->ent->name); vimc_streamer_pipeline_terminate(stream); return ret; } } entity = vimc_get_source_entity(ved->ent); /* Check if the end of the pipeline was reached */ if (!entity) { /* the first entity of the pipe should be source only */ if (!vimc_is_source(ved->ent)) { dev_err(ved->dev, "first entity in the pipe '%s' is not a source\n", ved->ent->name); vimc_streamer_pipeline_terminate(stream); return -EPIPE; } return 0; } /* Get the next device in the pipeline */ if (is_media_entity_v4l2_subdev(entity)) { sd = media_entity_to_v4l2_subdev(entity); ved = v4l2_get_subdevdata(sd); } else { vdev = container_of(entity, struct video_device, entity); ved = video_get_drvdata(vdev); } } vimc_streamer_pipeline_terminate(stream); return -EINVAL; } /** * vimc_streamer_thread - Process frames through the pipeline * * @data: vimc_stream struct of the current stream * * From the source to the sink, gets a frame from each subdevice and send to * the next one of the pipeline at a fixed framerate. * * Return: * Always zero (created as ``int`` instead of ``void`` to comply with * kthread API). */ static int vimc_streamer_thread(void *data) { struct vimc_stream *stream = data; u8 *frame = NULL; int i; set_freezable(); for (;;) { try_to_freeze(); if (kthread_should_stop()) break; for (i = stream->pipe_size - 1; i >= 0; i--) { frame = stream->ved_pipeline[i]->process_frame( stream->ved_pipeline[i], frame); if (!frame || IS_ERR(frame)) break; } //wait for 60hz set_current_state(TASK_UNINTERRUPTIBLE); schedule_timeout(HZ / 60); } return 0; } /** * vimc_streamer_s_stream - Start/stop the streaming on the media pipeline * * @stream: the pointer to the stream structure of the current stream * @ved: pointer to the vimc entity of the entity of the stream * @enable: flag to determine if stream should start/stop * * When starting, check if there is no ``stream->kthread`` allocated. This * should indicate that a stream is already running. Then, it initializes the * pipeline, creates and runs a kthread to consume buffers through the pipeline. * When stopping, analogously check if there is a stream running, stop the * thread and terminates the pipeline. * * Return: 0 if success, error code otherwise. */ int vimc_streamer_s_stream(struct vimc_stream *stream, struct vimc_ent_device *ved, int enable) { int ret; if (!stream || !ved) return -EINVAL; if (enable) { if (stream->kthread) return 0; ret = vimc_streamer_pipeline_init(stream, ved); if (ret) return ret; stream->kthread = kthread_run(vimc_streamer_thread, stream, "vimc-streamer thread"); if (IS_ERR(stream->kthread)) { ret = PTR_ERR(stream->kthread); dev_err(ved->dev, "kthread_run failed with %d\n", ret); vimc_streamer_pipeline_terminate(stream); stream->kthread = NULL; return ret; } } else { if (!stream->kthread) return 0; ret = kthread_stop(stream->kthread); /* * kthread_stop returns -EINTR in cases when streamon was * immediately followed by streamoff, and the thread didn't had * a chance to run. Ignore errors to stop the stream in the * pipeline. */ if (ret) dev_dbg(ved->dev, "kthread_stop returned '%d'\n", ret); stream->kthread = NULL; vimc_streamer_pipeline_terminate(stream); } return 0; }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
You can’t perform that action at this time.