media: vidtv: implement a virtual DVB driver
v3 cover media: vidtv: implement a virtual DVB driver
From: "Daniel W. S. Almeida" <[email protected]>
This series is work in progress. It represents the current work done on a virtual DVB driver for the Linux media subsystem. I am new to the media subsystem and to kernel development in general.
This applies on top of this branch
https://git.linuxtv.org/mchehab/experimental.git/log/?h=media-kconfig
for now, as these changes have not been applied to the media tree yet. The changes in this branch have reorganized where test drivers go in the subsystem. The dummy driver written by Emard was left untouched.
As for vidtv, we currently have a tuner driver, a demodulator driver, a bridge driver and some MPEG PSI code. This should be, therefore, a minimum viable example for what this driver intends to become in the future.
I appreciate any feedback given. Thank you.
Changes in v3:
Added a bridge driver
Renamed the driver to vidtv
Renamed/reworked commits into smaller pieces
Moved the driver into its own directory
Fixed the code for the signal strength in the tuner
Removed useless enums in the tuner driver (e.g. lock_status, power_status...) Reworked the logic for the poll_snr thread in the demodulator driver Moved MPEG related code to the bridge driver, as it controls the demux logic Changed literals to #defines, used sizeof in place of integer literals when computing the size of PSI structs
Moved the MPEG PSI tables to the heap to reduce stack space usage Now using usleep_range in place of msleep_interruptible in the MPEG TS thread Wrapped memcpy and memset to protect against buffer overflow when writing to the MPEG TS buffer.
Changes in v2:
Attempted not to break assignments into multiple lines as much as possible. Code now passes checkpatch strict mode
media: dvb_dummy_tuner: implement driver skeleton
Changed snr values to mili db
Return value from 0-100 to indicate how far off the requested frequency is from a valid one
Use the frequency shift to interpolate between 34dB and 10dB if we can not match against the SNR lookup table Remove sleep calls for suspend/resume
Fix memcpy call for the config struct
media: dvb_dummy_fe.c: lose TS lock on bad snr
Randomly recover the TS lock if the signal quality improves
media: dvb_dummy_fe.c: write PSI information into DMX buffer
Split the patch into multiple header/source files
Hexadecimal literals are now lower case
Prefer short function names / reduce function signatures
Add #defines for constants when computing section lengths
Change signature for functions that take a dummy channel as argument (i.e. channels* is now channels[NUM_CHANNELS])
Daniel W. S. Almeida (6):
media: vidtv: add Kconfig entry
media: vidtv: implement a tuner driver
media: vidtv: implement a demodulator driver
media: vidtv: implement a PSI generator
media: vidtv: move config structs into a common header
media: vidtv: add a bridge driver
drivers/media/test_drivers/Kconfig | 10 + drivers/media/test_drivers/Makefile | 1 + drivers/media/test_drivers/vidtv/Kconfig | 11 + drivers/media/test_drivers/vidtv/Makefile | 6 + .../media/test_drivers/vidtv/vidtv_bridge.c | 736 ++++++++++++++ .../media/test_drivers/vidtv/vidtv_bridge.h | 51 + .../media/test_drivers/vidtv/vidtv_common.c | 44 + .../media/test_drivers/vidtv/vidtv_common.h | 105 ++ .../media/test_drivers/vidtv/vidtv_demod.c | 493 +++++++++ .../media/test_drivers/vidtv/vidtv_demod.h | 34 + drivers/media/test_drivers/vidtv/vidtv_psi.c | 960 ++++++++++++++++++ drivers/media/test_drivers/vidtv/vidtv_psi.h | 294 ++++++ .../media/test_drivers/vidtv/vidtv_tuner.c | 403 ++++++++ 13 files changed, 3148 insertions(+) create mode 100644 drivers/media/test_drivers/vidtv/Kconfig create mode 100644 drivers/media/test_drivers/vidtv/Makefile create mode 100644 drivers/media/test_drivers/vidtv/vidtv_bridge.c create mode 100644 drivers/media/test_drivers/vidtv/vidtv_bridge.h create mode 100644 drivers/media/test_drivers/vidtv/vidtv_common.c create mode 100644 drivers/media/test_drivers/vidtv/vidtv_common.h create mode 100644 drivers/media/test_drivers/vidtv/vidtv_demod.c create mode 100644 drivers/media/test_drivers/vidtv/vidtv_demod.h create mode 100644 drivers/media/test_drivers/vidtv/vidtv_psi.c create mode 100644 drivers/media/test_drivers/vidtv/vidtv_psi.h create mode 100644 drivers/media/test_drivers/vidtv/vidtv_tuner.c
Signature · 6 lines
2.26.0 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
RFC v3 1/6 media: vidtv: add Kconfig entry
From: "Daniel W. S. Almeida" <[email protected]>
Add the necessary Kconfig entries and a dummy Makefile to compile the new virtual DVB test driver (vidtv).
--- drivers/media/test_drivers/Kconfig | 10 ++++++++++ drivers/media/test_drivers/Makefile | 1 + drivers/media/test_drivers/vidtv/Kconfig | 11 +++++++++++ drivers/media/test_drivers/vidtv/Makefile | 2 ++ 4 files changed, 24 insertions(+) create mode 100644 drivers/media/test_drivers/vidtv/Kconfig create mode 100644 drivers/media/test_drivers/vidtv/Makefile
drivers/media/test_drivers/Kconfig +10 -0
@@ -6,6 +6,10 @@ menuconfig V4L_TEST_DRIVERS bool "V4L test drivers" depends on VIDEO_DEV +menuconfig DVB_TEST_DRIVERS + bool "DVB test drivers" + depends on DVB_CORE && MEDIA_SUPPORT && I2C + if V4L_TEST_DRIVERS source "drivers/media/test_drivers/vimc/Kconfig"
@@ -25,4 +29,10 @@ source "drivers/media/test_drivers/vicodec/Kconfig" endif #V4L_TEST_DRIVERS +if DVB_TEST_DRIVERS + +source "drivers/media/test_drivers/vidtv/Kconfig" + +endif #DVB_TEST_DRIVERS + endif #MEDIA_TEST_SUPPORT
drivers/media/test_drivers/Makefile +1 -0
@@ -7,3 +7,4 @@ obj-$(CONFIG_VIDEO_VIMC) += vimc/ obj-$(CONFIG_VIDEO_VIVID) += vivid/ obj-$(CONFIG_VIDEO_VIM2M) += vim2m.o obj-$(CONFIG_VIDEO_VICODEC) += vicodec/ +obj-$(CONFIG_DVB_VIDTV) += vidtv/
drivers/media/test_drivers/vidtv/Kconfig new file +11 -0
@@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0-only +config DVB_VIDTV + tristate "Virtual DVB Driver (vidtv)" + depends on DVB_CORE && MEDIA_SUPPORT && I2C + help + The virtual DVB test driver serves as a reference DVB driver and helps + validate the existing APIs in the media subsystem. It can also aid developers + working on userspace applications. + + + When in doubt, say N.
drivers/media/test_drivers/vidtv/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0 +
Signature · 6 lines
2.26.0 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
RFC v3 2/6 media: vidtv: implement a tuner driver
In reply to Daniel W. S. AlmeidaFrom: "Daniel W. S. Almeida" <[email protected]>
The virtual DVB test driver serves as a reference DVB driver and helps validate the existing APIs in the media subsystem. It can also aid developers working on userspace applications.
This dummy tuner should support common TV standards such as DVB-T/T2/S/S2, ISDB-T and ATSC when completed.
--- drivers/media/test_drivers/vidtv/Makefile | 1 + .../media/test_drivers/vidtv/vidtv_tuner.c | 411 ++++++++++++++++++ 2 files changed, 412 insertions(+) create mode 100644 drivers/media/test_drivers/vidtv/vidtv_tuner.c
drivers/media/test_drivers/vidtv/Makefile +1 -0
@@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_DVB_VIDTV) += vidtv_tuner.o
drivers/media/test_drivers/vidtv/vidtv_tuner.c new file +411 -0
411 lines not on this page · raw message
Signature · 1 line
2.26.0
RFC v3 3/6 media: vidtv: implement a demodulator driver
In reply to Daniel W. S. AlmeidaFrom: "Daniel W. S. Almeida" <[email protected]>
Implement a I2C demodulator driver, simulating support for DVB-T, DVB-C and DVB-S.
This demodulator will periodically check the signal quality against a table and drop the TS lock if it drops below a threshold value, regaining it in the event that the signal improves.
--- drivers/media/test_drivers/vidtv/Makefile | 2 +- .../media/test_drivers/vidtv/vidtv_demod.c | 493 ++++++++++++++++++ .../media/test_drivers/vidtv/vidtv_demod.h | 43 ++ 3 files changed, 537 insertions(+), 1 deletion(-) create mode 100644 drivers/media/test_drivers/vidtv/vidtv_demod.c create mode 100644 drivers/media/test_drivers/vidtv/vidtv_demod.h
drivers/media/test_drivers/vidtv/Makefile +1 -1
@@ -1,3 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_DVB_VIDTV) += vidtv_tuner.o +obj-$(CONFIG_DVB_VIDTV) += vidtv_tuner.o vidtv_demod.o
drivers/media/test_drivers/vidtv/vidtv_demod.c new file +493 -0
493 lines not on this page · raw message
drivers/media/test_drivers/vidtv/vidtv_demod.h new file +43 -0
43 lines not on this page · raw message
Signature · 6 lines
2.26.0 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
RFC v3 4/6 media: vidtv: implement a PSI generator
In reply to Daniel W. S. AlmeidaFrom: "Daniel W. S. Almeida" <[email protected]>
PSI packets contain general information about a MPEG Transport Stream. A PSI generator is needed so userspace apps can retrieve information about the Transport Stream and eventually tune into a (dummy) channel.
Because the generator is implemented in a separate file, it can be reused elsewhere in the media subsystem.
Currently this commit adds support for working with 3 PSI tables:
PAT, PMT and SDT.
--- drivers/media/test_drivers/vidtv/Makefile | 4 +- .../media/test_drivers/vidtv/vidtv_common.c | 44 + .../media/test_drivers/vidtv/vidtv_common.h | 71 ++ drivers/media/test_drivers/vidtv/vidtv_psi.c | 960 ++++++++++++++++++ drivers/media/test_drivers/vidtv/vidtv_psi.h | 294 ++++++ 5 files changed, 1372 insertions(+), 1 deletion(-) create mode 100644 drivers/media/test_drivers/vidtv/vidtv_common.c create mode 100644 drivers/media/test_drivers/vidtv/vidtv_common.h create mode 100644 drivers/media/test_drivers/vidtv/vidtv_psi.c create mode 100644 drivers/media/test_drivers/vidtv/vidtv_psi.h
drivers/media/test_drivers/vidtv/Makefile +3 -1
@@ -1,3 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_DVB_VIDTV) += vidtv_tuner.o vidtv_demod.o +vidtv_demod-objs := vidtv_common.o vidtv_psi.o + +obj-$(CONFIG_DVB_VIDTV) += vidtv_tuner.o vidtv_demod.o
drivers/media/test_drivers/vidtv/vidtv_common.c new file +44 -0
44 lines not on this page · raw message
drivers/media/test_drivers/vidtv/vidtv_common.h new file +71 -0
71 lines not on this page · raw message
drivers/media/test_drivers/vidtv/vidtv_psi.c new file +960 -0
960 lines not on this page · raw message
drivers/media/test_drivers/vidtv/vidtv_psi.h new file +294 -0
294 lines not on this page · raw message
Signature · 1 line
2.26.0
RFC v3 5/6 media: vidtv: move config structs into a common header
In reply to Daniel W. S. AlmeidaFrom: "Daniel W. S. Almeida" <[email protected]>
Move config structs to a common header so they can be used by the bridge driver and by their respective drivers.
--- .../media/test_drivers/vidtv/vidtv_common.h | 19 +++++++++++++++++++ .../media/test_drivers/vidtv/vidtv_demod.h | 9 --------- .../media/test_drivers/vidtv/vidtv_tuner.c | 12 ++---------- 3 files changed, 21 insertions(+), 19 deletions(-)
drivers/media/test_drivers/vidtv/vidtv_common.h +19 -0
@@ -56,6 +56,25 @@ struct vidtv_mpeg_ts {struct vidtv_mpeg_ts_adaption adaption[]; } __packed; +struct vidtv_tuner_config { +struct dvb_frontend *fe; +u32 mock_power_up_delay_msec; +u32 mock_tune_delay_msec; +u32 vidtv_valid_dvb_t_freqs[8 ]; +u32 vidtv_valid_dvb_c_freqs[8 ]; +u32 vidtv_valid_dvb_s_freqs[8 ]; +u8 max_frequency_shift_hz; +}; + +struct vidtv_demod_config { +struct dvb_frontend *frontend; +/* probability of losing the lock due to low snr */ +u8 drop_tslock_prob_on_low_snr; +/* probability of recovering when the signal improves */ +u8 recover_tslock_prob_on_good_snr; +u8 chosen_delsys; +}; + u32 vidtv_memcpy(void *to, const void *from, size_t len,
drivers/media/test_drivers/vidtv/vidtv_demod.h +0 -9
@@ -21,15 +21,6 @@ struct vidtv_demod_cnr_to_qual_s {u32 cnr_ok, cnr_good; }; -struct vidtv_demod_config { -struct dvb_frontend *frontend; -/* probability of losing the lock due to low snr */ -u8 drop_tslock_prob_on_low_snr; -/* probability of recovering when the signal improves */ -u8 recover_tslock_prob_on_good_snr; -u8 chosen_delsys; -}; -struct vidtv_demod_state {struct dvb_frontend frontend;struct vidtv_demod_config config;
drivers/media/test_drivers/vidtv/vidtv_tuner.c +2 -10
@@ -17,20 +17,12 @@#include <linux/types.h> #include <media/dvb_frontend.h> +#include "vidtv_common.h" +MODULE_DESCRIPTION ("Virtual DTV Tuner" );MODULE_AUTHOR ("Daniel W. S. Almeida" );MODULE_LICENSE ("GPL" ); -struct vidtv_tuner_config { -struct dvb_frontend *fe; -u32 mock_power_up_delay_msec; -u32 mock_tune_delay_msec; -u32 vidtv_valid_dvb_t_freqs[8 ]; -u32 vidtv_valid_dvb_c_freqs[8 ]; -u32 vidtv_valid_dvb_s_freqs[8 ]; -u8 max_frequency_shift_hz; -}; -struct vidtv_tuner_cnr_to_qual_s {/* attempt to use the same values as libdvbv5 */ u32 modulation;
Signature · 1 line
2.26.0
RFC v3 6/6 media: vidtv: add a bridge driver
In reply to Daniel W. S. AlmeidaFrom: "Daniel W. S. Almeida" <[email protected]>
Digital TV devices consist of several independent hardware components which are controlled by different drivers.
Each media device is controlled by a group of cooperating drivers with the bridge driver as the main driver.
This patch adds a bridge driver for the Virtual Digital TV driver [vidtv].
The bridge driver binds to the other drivers, that is, vidtv_tuner and vidtv_demod and implements the digital demux logic, providing userspace with a MPEG Transport Stream.
--- drivers/media/test_drivers/vidtv/Makefile | 3 +- .../media/test_drivers/vidtv/vidtv_bridge.c | 736 ++++++++++++++++++ .../media/test_drivers/vidtv/vidtv_bridge.h | 51 ++ .../media/test_drivers/vidtv/vidtv_common.h | 15 + 4 files changed, 804 insertions(+), 1 deletion(-) create mode 100644 drivers/media/test_drivers/vidtv/vidtv_bridge.c create mode 100644 drivers/media/test_drivers/vidtv/vidtv_bridge.h
drivers/media/test_drivers/vidtv/Makefile +2 -1
@@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 vidtv_demod-objs := vidtv_common.o vidtv_psi.o +vidtv_bridge-objs := vidtv_common.o vidtv_psi.o -obj-$(CONFIG_DVB_VIDTV) += vidtv_tuner.o vidtv_demod.o +obj-$(CONFIG_DVB_VIDTV) += vidtv_tuner.o vidtv_demod.o vidtv_bridge.o
drivers/media/test_drivers/vidtv/vidtv_bridge.c new file +736 -0
736 lines not on this page · raw message
drivers/media/test_drivers/vidtv/vidtv_bridge.h new file +51 -0
51 lines not on this page · raw message
drivers/media/test_drivers/vidtv/vidtv_common.h +15 -0
@@ -18,6 +18,12 @@#define TS_PACKET_LEN 188#define TS_PAYLOAD_LEN 184#define LAST_VALID_TS_PID 8191 +#define USECS_IN_SEC 1000000 +#define TUNER_DEFAULT_ADDR 0x68 +#define DEMOD_DEFAULT_ADDR 0x60 +#define NUM_CHANNELS 1 +#define TRANSPORT_STREAM_ID 0x744/* a single stream */ +/* to be used by both PSI and ES */ struct vidtv_mpeg_ts_adaption {
@@ -75,6 +81,15 @@ struct vidtv_demod_config {u8 chosen_delsys; }; +struct vidtv_channel { +u16 transport_stream_id; +struct vidtv_psi_table_sdt_service *service; +u16 program_num; +/* a single program with one or more streams associated with it */ +struct vidtv_psi_table_pat_program *program; +struct vidtv_psi_table_pmt_stream *streams; +}; + u32 vidtv_memcpy(void *to, const void *from, size_t len,
Signature · 1 line
2.26.0