Skip to contentSkip to conversation

media: vidtv: implement a virtual DVB driver

RFC Superseded Daniel W. S. Almeida 2 participants 15 messages May 15, 2020 – May 16, 2020

Subsystems (2)

v5 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Daniel W. S. Almeida

author maintainer
#0 lore raw

v5 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 driver aims to:
- Serve as template for new DVB driver writers
- Help userspace application writers in general
- Push fake audio/video to userspace for testing purposes
- Push debug information to userspace via debugfs

This should currently be able to feed PSI and PCM audio data to userspace.

I appreciate any feedback!

Changes in v5:

Removed all calls to WARN_ON in favor of pr_warn_ratelimited Add a #define for pr_fmt
Reworked the byte swapping logic for big/little endian support:
big endian fields now prepended with __beXX for 'sparse' checks bitfields now laid in reverse order if LITTLE_ENDIAN_BITFIELD
is set

media: vidtv: implement a tuner driver
Return -EINVAL instead of -1 in vidtv_tuner_check_frequency_shift
media: vidtv: implement a demodulator driver
Add POLL_THRD_TIME #define
Implement dvb_frontend_ops as a single struct instead of three
media: vidtv: move config structs into a separate header
Removed this commit, configs are now in vidtv_tuner.h and vidtv_demod.h
media: vidtv: add a bridge driver
module_param: all fs permissions set to 0
removed param 'chosen_delsys'
module_param: removed "optional" string: all module_params are optional renamed vidtv_bridge -> vidtv_bridg: so the source code and module names
are different
media: vidtv: add wrappers for memcpy and memset
Added kernel-docs
write address is now computed internally
media: vidtv: add MPEG TS common code
Drop packets if the buffer is full
media: vidtv: implement a PSI generator
Removed vidtv_psi_ts_psi_write_stuffing()
Forcibly align misaligned buffers
Drop packets if buffer is full
media: vidtv: implement a PES packetizer
Remove vidtv_extract_bits() in favor of GENMASK() and bitwise & Forcibly align misaligned buffers
media: vidtv: Implement a SMPTE 302M encoder
Added kernel-docs for struct vidtv_encoder
media: vidtv: Add a MPEG Transport Stream Multiplexer
Added check for minimum and maximum buffer size.
Drop packets if buffer is full

Changes in v4:
Added a PES packetizer
Implemented a minimum version of the SMPTE 302m encoder for AES3 audio Fixed endianness in the PSI generator, converting fields to big endian where applicable Added a minimal TS mux abstraction

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 (10):
media: vidtv: add Kconfig entry
media: vidtv: implement a tuner driver
media: vidtv: implement a demodulator driver
media: vidtv: add a bridge driver
media: vidtv: add wrappers for memcpy and memset
media: vidtv: add MPEG TS common code
media: vidtv: implement a PSI generator
media: vidtv: implement a PES packetizer
media: vidtv: Implement a SMPTE 302M encoder
media: vidtv: Add a MPEG Transport Stream Multiplexer

 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_bridg.c    |  456 +++++++
 .../media/test-drivers/vidtv/vidtv_bridg.h    |   39 +
 .../media/test-drivers/vidtv/vidtv_channel.c  |  339 ++++++
 .../media/test-drivers/vidtv/vidtv_channel.h  |   66 ++
 .../media/test-drivers/vidtv/vidtv_common.c   |   86 ++
 .../media/test-drivers/vidtv/vidtv_common.h   |   34 +
 .../media/test-drivers/vidtv/vidtv_demod.c    |  448 +++++++
 .../media/test-drivers/vidtv/vidtv_demod.h    |   42 +
 .../media/test-drivers/vidtv/vidtv_encoder.h  |  103 ++
 drivers/media/test-drivers/vidtv/vidtv_mux.c  |  434 +++++++
 drivers/media/test-drivers/vidtv/vidtv_mux.h  |  105 ++
 drivers/media/test-drivers/vidtv/vidtv_pes.c  |  450 +++++++
 drivers/media/test-drivers/vidtv/vidtv_pes.h  |  186 +++
 drivers/media/test-drivers/vidtv/vidtv_psi.c  | 1055 +++++++++++++++++
 drivers/media/test-drivers/vidtv/vidtv_psi.h  |  420 +++++++
 .../media/test-drivers/vidtv/vidtv_s302m.c    |  638 ++++++++++
 .../media/test-drivers/vidtv/vidtv_s302m.h    |  119 ++
 drivers/media/test-drivers/vidtv/vidtv_ts.c   |  157 +++
 drivers/media/test-drivers/vidtv/vidtv_ts.h   |  120 ++
 .../media/test-drivers/vidtv/vidtv_tuner.c    |  408 +++++++
 .../media/test-drivers/vidtv/vidtv_tuner.h    |   26 +
 25 files changed, 5759 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_bridg.c
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_bridg.h
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_channel.c
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_channel.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_encoder.h
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_mux.c
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_mux.h
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_pes.c
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_pes.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_s302m.c
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_s302m.h
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_ts.c
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_ts.h
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_tuner.c
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_tuner.h
Signature · 1 line
2.26.2
author maintainer
#1 lore raw

RFC v5 1/10 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
index 188381c855939..7d273a8a7acc2 100644
@@ -4,6 +4,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"
@@ -24,3 +28,9 @@ config VIDEO_VIM2M
 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
drivers/media/test-drivers/Makefile +1 -0
index 74410d3a9f2d2..9f0e4ebb2efe7 100644
@@ -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
new file mode 100644
index 0000000000000..22c4fd39461f1
@@ -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
new file mode 100644
index 0000000000000..d1558d84eeaed
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0
+
Signature · 6 lines
2.26.2

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
author maintainer
#2 lore raw

RFC v5 2/10 media: vidtv: implement a tuner driver

In reply to Daniel W. S. Almeida

From: "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    | 408 ++++++++++++++++++
 .../media/test-drivers/vidtv/vidtv_tuner.h    |  26 ++
 3 files changed, 435 insertions(+)
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_tuner.c
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_tuner.h
drivers/media/test-drivers/vidtv/Makefile +1 -0
index d1558d84eeaed..e625810a82603 100644
@@ -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 +408 -0

408 lines not on this page · raw message

drivers/media/test-drivers/vidtv/vidtv_tuner.h new file +26 -0
new file mode 100644
index 0000000000000..46407739f5d44
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * The Virtual DTV 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.
+ *
+ * Written by Daniel W. S. Almeida <[email protected]>
+ */
+
+#ifndef VIDTV_TUNER_H
+#define VIDTV_TUNER_H
+
+#include <linux/types.h>
+#include <media/dvb_frontend.h>
+
+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;
+};
+
+#endif //VIDTV_TUNER_H
Signature · 1 line
2.26.2
author maintainer
#3 lore raw

RFC v5 3/10 media: vidtv: implement a demodulator driver

In reply to Daniel W. S. Almeida

From: "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    | 448 ++++++++++++++++++
 .../media/test-drivers/vidtv/vidtv_demod.h    |  42 ++
 3 files changed, 491 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
index e625810a82603..36ba00ddc0d1e 100644
@@ -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 +448 -0

448 lines not on this page · raw message

drivers/media/test-drivers/vidtv/vidtv_demod.h new file +42 -0

42 lines not on this page · raw message

Signature · 1 line
2.26.2
author maintainer
#4 lore raw

RFC v5 4/10 media: vidtv: add a bridge driver

In reply to Daniel W. S. Almeida

From: "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.

Move config structs to a common header so they can be used by the bridge driver and by their respective drivers.

---
 drivers/media/test-drivers/vidtv/Makefile     |   4 +-
 .../media/test-drivers/vidtv/vidtv_bridg.c    | 380 ++++++++++++++++++
 .../media/test-drivers/vidtv/vidtv_bridg.h    |  37 ++
 3 files changed, 420 insertions(+), 1 deletion(-)
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_bridg.c
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_bridg.h
drivers/media/test-drivers/vidtv/Makefile +3 -1
index 36ba00ddc0d1e..e0bb1b3bedad6 100644
@@ -1,3 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
 
-obj-$(CONFIG_DVB_VIDTV)	+= vidtv_tuner.o  vidtv_demod.o
+vidtv_bridge-objs = vidtv_bridg.o
+
+obj-$(CONFIG_DVB_VIDTV)	+= vidtv_tuner.o vidtv_demod.o vidtv_bridge.o
drivers/media/test-drivers/vidtv/vidtv_bridg.c new file +380 -0

380 lines not on this page · raw message

drivers/media/test-drivers/vidtv/vidtv_bridg.h new file +37 -0
new file mode 100644
index 0000000000000..dead155c2735c
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * The Virtual DTV 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.
+ *
+ * Written by Daniel W. S. Almeida <[email protected]>
+ */
+
+#ifndef VIDTV_BRIDG_H
+#define VIDTV_BRIDG_H
+
+#define NUM_FE 1
+
+#include <linux/types.h>
+#include <media/dvb_frontend.h>
+#include <media/dvb_demux.h>
+#include <media/dmxdev.h>
+#include <linux/i2c.h>
+
+struct vidtv_dvb {
+	struct dvb_frontend *fe[NUM_FE];
+	struct dvb_adapter adapter;
+	struct dvb_demux demux;
+	struct dmxdev dmx_dev;
+	struct dmx_frontend dmx_fe[NUM_FE];
+	struct i2c_adapter *i2c_adapter;
+	struct i2c_client *i2c_client_demod[NUM_FE];
+	struct i2c_client *i2c_client_tuner[NUM_FE];
+
+	u32 nfeeds;
+	struct mutex feed_lock; /* start/stop feed */
+
+	bool streaming;
+};
+
+#endif // VIDTV_BRIDG_H
Signature · 1 line
2.26.2
#5 lore raw

Re: [RFC, WIP, v5 04/10] media: vidtv: add a bridge driver

[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi "Daniel,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on linuxtv-media/master]
[also build test WARNING on next-20200515]
[cannot apply to v5.7-rc5]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Daniel-W-S-Almeida/media-vidtv-implement-a-virtual-DVB-driver/20200516-055059
base:   git://linuxtv.org/media_tree.git master
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.1-193-gb8fad4bc-dirty
        make ARCH=x86_64 allmodconfig
        make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

If you fix the issue, kindly add following tag as appropriate

sparse warnings: (new ones prefixed by >>)

>> drivers/media/test-drivers/vidtv/vidtv_bridg.c:199:42: sparse: sparse: Using plain integer as NULL pointer

drivers/media/test-drivers/vidtv/vidtv_bridg.c:218:42: sparse: sparse: Using plain integer as NULL pointer

vim +199 drivers/media/test-drivers/vidtv/vidtv_bridg.c

196
197 static void vidtv_bridge_probe_demod(struct vidtv_dvb *dvb, u32 n)
198 {

 > 199		struct vidtv_demod_config cfg = {0};
   200		struct dvb_frontend *fe       = NULL;
   201	
   202		cfg.frontend = &fe;
   203		cfg.drop_tslock_prob_on_low_snr     = drop_tslock_prob_on_low_snr;
   204		cfg.recover_tslock_prob_on_good_snr = recover_tslock_prob_on_good_snr;
   205	
   206		dvb->i2c_client_demod[n] = dvb_module_probe("vidtv_demod",
   207							    NULL,
   208							    dvb->i2c_adapter,
   209							    DEMOD_DEFAULT_ADDR,
   210							    &cfg);

211
212 /* retrieve a pointer to struct dvb_frontend */
213 dvb->fe[n] = *cfg.frontend;
214 }
215

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

author maintainer
#6 lore raw

RFC v5 5/10 media: vidtv: add wrappers for memcpy and memset

In reply to Daniel W. S. Almeida

From: "Daniel W. S. Almeida" <[email protected]>

A lot of code in this driver is for serializing structures. This is error prone.

Therefore, prevent buffer overflows by wrapping memcpy and memset, comparing the requested length against the buffer size.

---
 .../media/test-drivers/vidtv/vidtv_common.c   | 86 +++++++++++++++++++
 .../media/test-drivers/vidtv/vidtv_common.h   | 27 ++++++
 2 files changed, 113 insertions(+)
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_common.c
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_common.h
drivers/media/test-drivers/vidtv/vidtv_common.c new file +86 -0
new file mode 100644
index 0000000000000..944f77625c12c
@@ -0,0 +1,86 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * 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.
+ *
+ * Written by Daniel W. S. Almeida <[email protected]>
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ":%s, %d: " fmt, __func__, __LINE__
+
+#include <linux/types.h>
+#include <linux/string.h>
+#include <linux/printk.h>
+#include <linux/ratelimit.h>
+
+#include "vidtv_common.h"
+
+/**
+ * vidtv_memcpy() - wrapper routine to be used by MPEG-TS
+ *	generator, in order to avoid going past the
+ *	output buffer.
+ * @to:	Starting element to where a MPEG-TS packet will
+ *	be copied.
+ * @to_offset:	Starting position of the @to buffer to be filled.
+ * @to_size:	Size of the @to buffer.
+ * @from:	Starting element of the buffer to be copied.
+ * @len:	Number of elements to be copy from @from buffer
+ *	into @to+ @to_offset buffer.
+ *
+ * Note:
+ *	Real digital TV demod drivers should not have memcpy
+ *	wrappers. We use it here because emulating MPEG-TS
+ *	generation at kernelspace requires some extra care.
+ *
+ * Return:
+ *	Returns the number of bytes written
+ */
+u32 vidtv_memcpy(void *to,
+		 size_t to_offset,
+		 size_t to_size,
+		 const void *from,
+		 size_t len)
+{
+	if (unlikely(to_offset + len > to_size)) {
+		pr_err_ratelimited("overflow detected, skipping. Try increasing the buffer size\n");
+		return 0;
+	}
+
+	memcpy(to + to_offset, from, len);
+	return len;
+}
+
+/**
+ * vidtv_memset() - wrapper routine to be used by MPEG-TS
+ *	generator, in order to avoid going past the
+ *	output buffer.
+ * @to:	Starting element to set
+ * @to_offset:	Starting position of the @to buffer to be filled.
+ * @to_size:	Size of the @to buffer.
+ * @from:	Starting element of the buffer to be copied.
+ * @ten:	Number of elements to be copy from @from buffer
+ *	into @to+ @to_offset buffer.
+ *
+ * Note:
+ *	Real digital TV demod drivers should not have memset
+ *	wrappers. We use it here because emulating MPEG-TS
+ *	generation at kernelspace requires some extra care.
+ *
+ * Return:
+ *	Returns the number of bytes written
+ */
+u32 vidtv_memset(void *to,
+		 size_t to_offset,
+		 size_t to_size,
+		 const int c,
+		 size_t len)
+{
+	if (unlikely(to_offset + len > to_size)) {
+		pr_err_ratelimited("overflow detected, skipping. Try increasing the buffer size\n");
+		return 0;
+	}
+
+	memset(to + to_offset, c, len);
+	return len;
+}
drivers/media/test-drivers/vidtv/vidtv_common.h new file +27 -0
new file mode 100644
index 0000000000000..a3cb303cc7423
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * 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.
+ *
+ * Written by Daniel W. S. Almeida <[email protected]>
+ */
+
+#ifndef VIDTV_COMMON_H
+#define VIDTV_COMMON_H
+
+#include <linux/types.h>
+
+u32 vidtv_memcpy(void *to,
+		 size_t to_offset,
+		 size_t to_size,
+		 const void *from,
+		 size_t len);
+
+u32 vidtv_memset(void *to,
+		 size_t to_offset,
+		 size_t to_size,
+		 int c,
+		 size_t len);
+
+#endif // VIDTV_COMMON_H
Signature · 1 line
2.26.2
author maintainer
#7 lore raw

RFC v5 6/10 media: vidtv: add MPEG TS common code

In reply to Daniel W. S. Almeida

From: "Daniel W. S. Almeida" <[email protected]>

Add code to work with MPEG TS packets, such as TS headers, adaptation fields, PCR packets and NULL packets.

---
 drivers/media/test-drivers/vidtv/vidtv_ts.c | 157 ++++++++++++++++++++
 drivers/media/test-drivers/vidtv/vidtv_ts.h | 120 +++++++++++++++
 2 files changed, 277 insertions(+)
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_ts.c
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_ts.h
drivers/media/test-drivers/vidtv/vidtv_ts.c new file +157 -0
new file mode 100644
index 0000000000000..77908c4e85eef
@@ -0,0 +1,157 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * 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.
+ *
+ * Written by Daniel W. S. Almeida <[email protected]>
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ":%s, %d: " fmt, __func__, __LINE__
+
+#include <linux/printk.h>
+#include <linux/ratelimit.h>
+#include <linux/types.h>
+#include <asm/byteorder.h>
+
+#include "vidtv_ts.h"
+#include "vidtv_common.h"
+
+static u32 vidtv_ts_write_pcr_bits(u8 *to, u32 to_offset, u64 pcr)
+{
+	/* Exact same from ffmpeg. PCR is a counter driven by a 27Mhz clock */
+	u64 pcr_low = pcr % 300;
+	u64 pcr_high = pcr / 300;
+	u8 *buf = to + to_offset;
+
+	*buf++ = pcr_high >> 25;
+	*buf++ = pcr_high >> 17;
+	*buf++ = pcr_high >>  9;
+	*buf++ = pcr_high >>  1;
+	*buf++ = pcr_high <<  7 | pcr_low >> 8 | 0x7e;
+	*buf++ = pcr_low;
+
+	return 6;
+}
+
+void vidtv_ts_inc_cc(u8 *continuity_counter)
+{
+	++*continuity_counter;
+	if (*continuity_counter > TS_CC_MAX_VAL)
+		*continuity_counter = 0;
+}
+
+u32 vidtv_ts_null_write_into(struct null_packet_write_args args)
+{
+	u32    nbytes                  = 0;
+	struct vidtv_mpeg_ts ts_header = {0};
+
+	ts_header.sync_byte          = TS_SYNC_BYTE;
+	ts_header.pid                = TS_NULL_PACKET_PID;
+	ts_header.payload            = 1;
+	ts_header.continuity_counter = *args.continuity_counter;
+
+	cpu_to_be16s(&ts_header.bitfield);
+
+	/* copy TS header */
+	nbytes += vidtv_memcpy(args.dest_buf,
+			       args.dest_offset + nbytes,
+			       args.buf_sz,
+			       &ts_header,
+			       sizeof(ts_header));
+
+	be16_to_cpus(&ts_header.bitfield);
+
+	/*
+	 * Note:
+	 *	This will cause a discontinuity if the buffer is full,
+	 *	effectively dropping the packet, since nothing will get written
+	 *	but the continuity counter will still be incremented. This way,
+	 *	userspace can detect packet losses.
+	 */
+	vidtv_ts_inc_cc(args.continuity_counter);
+
+	/* fill the rest with empty data */
+	nbytes += vidtv_memset(args.dest_buf,
+			       args.dest_offset + nbytes,
+			       args.buf_sz,
+			       TS_FILL_BYTE,
+			       TS_PACKET_LEN - nbytes);
+
+	/* we should have written exactly _one_ 188byte packet */
+	if (nbytes != TS_PACKET_LEN)
+		pr_warn_ratelimited("Expected exactly %d bytes, got %d\n",
+				    TS_PACKET_LEN,
+				    nbytes);
+
+	return nbytes;
+}
+
+u32 vidtv_ts_pcr_write_into(struct pcr_write_args args)
+{
+	u32    nbytes                         = 0;
+	struct vidtv_mpeg_ts ts_header        = {0};
+	struct vidtv_mpeg_ts_adaption ts_adap = {0};
+
+	ts_header.sync_byte     = TS_SYNC_BYTE;
+	ts_header.tei           = 0;
+	ts_header.payload_start = 0;
+	ts_header.pid           = args.pid;
+	ts_header.priority      = 0;
+	ts_header.scrambling    = 0;
+	/* cc is not incremented, but we need it. see 13818-1 clause 2.4.3.3 */
+	ts_header.continuity_counter = *args.continuity_counter;
+	ts_header.payload            = 0;
+	ts_header.adaptation_field   = 1;
+
+	/* 13818-1 clause 2.4.3.5 */
+	ts_adap.length = 183;
+	ts_adap.PCR    = 1;
+
+	/*
+	 * Note:
+	 *	Nothing will get written if the buffer is full, this will
+	 *	essentially drop the packet. The continuity counter is not
+	 *	updated for PCR packets, so it will be as if no PCR packet was
+	 *	sent at all.
+	 */
+
+	cpu_to_be16s(&ts_header.bitfield);
+
+	/* copy TS header */
+	nbytes += vidtv_memcpy(args.dest_buf,
+			       args.dest_offset + nbytes,
+			       args.buf_sz,
+			       &ts_header,
+			       sizeof(ts_header));
+
+	be16_to_cpus(&ts_header.bitfield);
+
+	/* write the adap after the TS header */
+	nbytes += vidtv_memcpy(args.dest_buf,
+			       args.dest_offset + nbytes,
+			       args.buf_sz,
+			       &ts_adap,
+			       sizeof(ts_adap));
+
+	/* write the PCR optional */
+	cpu_to_be64s(&args.pcr);
+	nbytes += vidtv_ts_write_pcr_bits(args.dest_buf,
+					  args.dest_offset + nbytes,
+					  args.pcr);
+	be64_to_cpus(&args.pcr);
+
+	nbytes += vidtv_memset(args.dest_buf,
+			       args.dest_offset + nbytes,
+			       args.buf_sz,
+			       TS_FILL_BYTE,
+			       TS_PACKET_LEN - nbytes);
+
+	/* we should have written exactly _one_ 188byte packet */
+	if (nbytes != TS_PACKET_LEN)
+		pr_warn_ratelimited("Expected exactly %d bytes, got %d\n",
+				    TS_PACKET_LEN,
+				    nbytes);
+
+	return nbytes;
+}
drivers/media/test-drivers/vidtv/vidtv_ts.h new file +120 -0

120 lines not on this page · raw message

Signature · 1 line
2.26.2
author maintainer
#8 lore raw

RFC v5 7/10 media: vidtv: implement a PSI generator

In reply to Daniel W. S. Almeida

From: "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/vidtv_psi.c | 1037 ++++++++++++++++++
 drivers/media/test-drivers/vidtv/vidtv_psi.h |  415 +++++++
 2 files changed, 1452 insertions(+)
 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/vidtv_psi.c new file +1037 -0
new file mode 100644
index 0000000000000..37b1ecab5ee79
@@ -0,0 +1,1037 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * This file contains the logic to work with MPEG Program-Specific Information.
+ * These are defined both in ISO/IEC 13818-1 (systems) and ETSI EN 300 468.
+ * PSI is carried in the form of table structures, and although each table might
+ * technically be broken into one or more sections, we do not do this here,
+ * hence 'table' and 'section' are interchangeable for us.
+ *
+ * This code currently supports three tables: PAT, PMT and SDT. These are the
+ * bare minimum to get userspace to recognize our MPEG transport stream. It can
+ * be extended to support more PSI tables in the future.
+ *
+ * A note on endianness: MPEG layout is big-endian, therefore:
+ * - All fields spanning more than a byte must undergo 'cpu_to_beXX()'
+ * - All bitfields must have their ordering reversed if
+ *  __LITTLE_ENDIAN_BITFIELD is defined.
+ *
+ * Written by: Daniel W. S. Almeida <[email protected]>
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ":%s, %d: " fmt, __func__, __LINE__
+
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/slab.h>
+#include <linux/crc32.h>
+#include <linux/string.h>
+#include <linux/printk.h>
+#include <linux/ratelimit.h>
+
+#include "vidtv_psi.h"
+#include "vidtv_common.h"
+#include "vidtv_ts.h"
+
+#define CRC_SIZE_IN_BYTES 4
+
+static u32
+vidtv_psi_ts_psi_write_into(struct psi_write_args args)
+{
+	/*
+	 * Packetize PSI sections into TS packets:
+	 * push a TS header (4bytes) every 184 bytes
+	 * manage the continuity_counter
+	 * add stuffing after the CRC
+	 */
+
+	u32  nbytes_past_boundary = (args.dest_offset % TS_PACKET_LEN);
+	bool aligned              = nbytes_past_boundary == 0;
+
+	/*
+	 * whether we need to fragment the data into multiple ts packets
+	 * if we are aligned we need to spare one byte for the pointer_field
+	 */
+	bool split = (aligned) ?
+		     args.len > TS_PAYLOAD_LEN - 1 :
+		     nbytes_past_boundary + args.len > TS_PACKET_LEN;
+
+	/* how much we can write in this packet */
+	u32 payload_write_len = (split) ?
+				(aligned)     ? TS_PAYLOAD_LEN       :
+				TS_PACKET_LEN - nbytes_past_boundary :
+				args.len;
+
+	struct psi_write_args new_args = {0};
+	struct vidtv_mpeg_ts ts_header = {0};
+
+	u32 nbytes = 0;  /* number of bytes written by this function */
+	u32 temp   = 0;
+
+	/* Just a sanity check, should not really happen because we stuff
+	 * the packet when we finish a section, i.e. when we write the crc at
+	 * the end. But if this happens then we have messed up the logic
+	 * somewhere.
+	 */
+	if (args.new_psi_section && !aligned) {
+		pr_warn_ratelimited("Cannot write a new PSI section in a misaligned buffer\n");
+
+		/* forcibly align and hope for the best */
+		nbytes += vidtv_memset(args.dest_buf,
+				       args.dest_offset + nbytes,
+				       args.dest_buf_sz,
+				       TS_FILL_BYTE,
+				       TS_PACKET_LEN - nbytes_past_boundary);
+
+		aligned = true;
+	}
+
+	if (aligned) {
+		/* if at a packet boundary, write a new TS header */
+		ts_header.sync_byte          = TS_SYNC_BYTE;
+		ts_header.tei                = 0;
+		ts_header.payload_start      = 1;
+		ts_header.pid                = args.pid;
+		ts_header.priority           = 0;
+		ts_header.scrambling         = 0;
+		ts_header.continuity_counter = *args.continuity_counter;
+		ts_header.payload            = 1;
+		/* no adaptation field */
+		ts_header.adaptation_field = 0;
+
+		/* copy the header */
+		nbytes += vidtv_memcpy(args.dest_buf,
+				       args.dest_offset + nbytes,
+				       args.dest_buf_sz,
+				       &ts_header,
+				       sizeof(ts_header));
+
+		/*
+		 * increment the countinuity counter since we have started a new
+		 * packet
+		 *
+		 * This will trigger a discontinuity if the buffer is full,
+		 * which is what we want: the continuity counter will be
+		 * incremented but nothing will get copied by
+		 * vidtv_memcpy/vidtv_memset, effectively dropping the packet.
+		 */
+		vidtv_ts_inc_cc(args.continuity_counter);
+	}
+
+	if (args.new_psi_section) {
+		/* write the pointer_field in the first byte of the payload */
+		temp = vidtv_memset(args.dest_buf,
+				    args.dest_offset + nbytes,
+				    args.dest_buf_sz,
+				    0x0,
+				    1);
+		/* one byte was used by the pointer field*/
+		nbytes += temp;
+		if (payload_write_len == TS_PAYLOAD_LEN)
+			payload_write_len -= temp;
+	}
+
+	/* write as much of the payload as we possibly can */
+	nbytes += vidtv_memcpy(args.dest_buf,
+			       args.dest_offset + nbytes,
+			       args.dest_buf_sz,
+			       args.from,
+			       payload_write_len);
+
+	if (split) {
+		/* 'payload_write_len' written from a total of 'len' requested*/
+		args.len -= payload_write_len;
+		/*
+		 * recursively write the rest of the data until we do not
+		 * need to split it anymore
+		 */
+		memcpy(&new_args, &args, sizeof(struct psi_write_args));
+		new_args.from            = args.from + payload_write_len;
+		new_args.dest_offset     = args.dest_offset + nbytes;
+		new_args.new_psi_section = false;
+
+		nbytes += vidtv_psi_ts_psi_write_into(new_args);
+	}
+
+	/*
+	 * as the CRC is last in the section, stuff the rest of the
+	 * packet if there is any remaining space in there
+	 */
+	if (args.is_crc)
+		nbytes += vidtv_memset(args.dest_buf,
+				       args.dest_offset + nbytes,
+				       args.dest_buf_sz,
+				       TS_FILL_BYTE,
+				       TS_PACKET_LEN - payload_write_len);
+
+	return nbytes;
+}
+
+static u32 table_section_crc32_write_into(struct crc32_write_args args)
+{
+	/* the CRC is the last entry in the section */
+	u32 nbytes = 0;
+	__be32 crc;
+	struct psi_write_args psi_args = {0};
+
+	crc = cpu_to_be32(crc32_be(0, args.dest_buf, args.dest_offset));
+
+	psi_args.dest_buf           = args.dest_buf;
+	psi_args.from               = &crc;
+	psi_args.len                = CRC_SIZE_IN_BYTES;
+	psi_args.dest_offset        = args.dest_offset;
+	psi_args.pid                = args.pid;
+	psi_args.new_psi_section    = false;
+	psi_args.continuity_counter = args.continuity_counter;
+	psi_args.is_crc             = true;
+	psi_args.dest_buf_sz        = args.dest_buf_sz;
+
+	nbytes += vidtv_psi_ts_psi_write_into(psi_args);
+
+	return nbytes;
+}
+
+struct vidtv_psi_desc *vidtv_psi_desc_init(struct vidtv_psi_desc *head,
+					   u8 type,
+					   u8 length)
+{
+	struct vidtv_psi_desc *desc;
+
+	/* alloc enough memory for the flexible array too */
+	desc = kzalloc(sizeof(*desc) + length, GFP_KERNEL);
+
+	desc->type   = type;
+	desc->length = length;
+
+	if (head) {
+		while (head->next)
+			head = head->next;
+
+		head->next = desc;
+	}
+
+	return desc;
+}
+
+void vidtv_psi_desc_destroy(struct vidtv_psi_desc *desc)
+{
+	struct vidtv_psi_desc *curr = desc;
+	struct vidtv_psi_desc *tmp  = NULL;
+
+	while (curr) {
+		tmp  = curr;
+		curr = curr->next;
+		kfree(tmp);
+	}
+}
+
+static u32
+vidtv_psi_desc_comp_len(struct vidtv_psi_desc *desc)
+{
+	u32 length = 0;
+
+	if (!desc)
+		return 0;
+
+	while (desc) {
+		length += desc->length;
+		desc    = desc->next;
+	}
+
+	return length;
+}
+
+void vidtv_psi_desc_assign(struct vidtv_psi_desc **to,
+			   struct vidtv_psi_desc *desc)
+{
+	/*
+	 * Caller must recompute the section length afterwards at some point
+	 * This function transfers ownedship of desc.
+	 * Start by cleaning the old data
+	 */
+	if (*to)
+		vidtv_psi_desc_destroy(*to);
+
+	*to = desc;  /* reassign pointer */
+}
+
+static u32 vidtv_psi_desc_write_into(struct desc_write_args args)
+{
+	/* the number of bytes written by this function */
+	u32    nbytes                  = 0;
+	struct psi_write_args psi_args = {0};
+
+	psi_args.dest_buf = args.dest_buf;
+	psi_args.from     = args.desc;
+
+	psi_args.len      = sizeof_field(struct vidtv_psi_desc, type) +
+			    sizeof_field(struct vidtv_psi_desc, length);
+
+	psi_args.dest_offset        = args.dest_offset;
+	psi_args.pid                = args.pid;
+	psi_args.new_psi_section    = false;
+	psi_args.continuity_counter = args.continuity_counter;
+	psi_args.is_crc             = false;
+	psi_args.dest_buf_sz        = args.dest_buf_sz;
+
+	nbytes += vidtv_psi_ts_psi_write_into(psi_args);
+
+	/* move 'from' pointer to point to u8 data[] */
+	psi_args.from = args.desc +
+			sizeof_field(struct vidtv_psi_desc, type) +
+			sizeof_field(struct vidtv_psi_desc, length) +
+			sizeof(struct vidtv_psi_desc *);
+
+	psi_args.len         = args.desc->length;
+	psi_args.dest_offset = args.dest_offset + nbytes;
+
+	nbytes += vidtv_psi_ts_psi_write_into(psi_args);
+
+	return nbytes;
+}
+
+static u32
+vidtv_psi_table_header_write_into(struct header_write_args args)
+{
+	/* the number of bytes written by this function */
+	u32    nbytes                  = 0;
+	struct psi_write_args psi_args = {0};
+
+	psi_args.dest_buf           = args.dest_buf;
+	psi_args.from               = args.h;
+	psi_args.len                = sizeof(struct vidtv_psi_table_header);
+	psi_args.dest_offset        = args.dest_offset;
+	psi_args.pid                = args.pid;
+	psi_args.new_psi_section    = true;
+	psi_args.continuity_counter = args.continuity_counter;
+	psi_args.is_crc             = false;
+	psi_args.dest_buf_sz        = args.dest_buf_sz;
+
+	nbytes += vidtv_psi_ts_psi_write_into(psi_args);
+
+	return nbytes;
+}
+
+void
+vidtv_psi_pat_table_comp_sec_len(struct vidtv_psi_table_pat *pat)
+{
+	/* see ISO/IEC 13818-1 : 2000 p.43 */
+	u16 length = 0;
+	u32 i;
+
+	/* from immediately after 'section_length' until 'last_section_number'*/
+	length += PAT_LEN_UNTIL_LAST_SECTION_NUMBER;
+
+	/* do not count the pointer */
+	for (i = 0; i < pat->programs; ++i)
+		length += sizeof(struct vidtv_psi_table_pat_program) -
+			  sizeof(struct vidtv_psi_table_pat_program *);
+
+	length += CRC_SIZE_IN_BYTES;
+
+	if (length > MAX_SECTION_LEN)
+		pr_warn_ratelimited("len %d > %d\n", length, MAX_SECTION_LEN);
+
+	pat->header.section_length = length;
+}
+
+void vidtv_psi_pmt_table_comp_sec_len(struct vidtv_psi_table_pmt *pmt)
+{
+	/* see ISO/IEC 13818-1 : 2000 p.46 */
+	u16    length                        = 0;
+	struct vidtv_psi_table_pmt_stream *s = pmt->stream;
+
+	/* from immediately after 'section_length' until 'program_info_length'*/
+	length += PMT_LEN_UNTIL_PROGRAM_INFO_LENGTH;
+
+	pmt->desc_length  = vidtv_psi_desc_comp_len(pmt->descriptor);
+	length           += pmt->desc_length;
+
+	while (s) {
+		/* skip both pointers at the end */
+		length += sizeof(struct vidtv_psi_table_pmt_stream) -
+			  sizeof(struct vidtv_psi_desc *) -
+			  sizeof(struct vidtv_psi_table_pmt_stream *);
+
+		s->desc_length  = vidtv_psi_desc_comp_len(s->descriptor);
+		length         += s->desc_length;
+
+		s = s->next;
+	}
+
+	length += CRC_SIZE_IN_BYTES;
+
+	if (length > MAX_SECTION_LEN)
+		pr_warn_ratelimited("len %d > %d\n", length, MAX_SECTION_LEN);
+
+	pmt->header.section_length = length;
+}
+
+void vidtv_psi_sdt_table_comp_sec_len(struct vidtv_psi_table_sdt *sdt)
+{
+	/* see ETSI EN 300 468 V 1.10.1 p.24 */
+	u16    length                         = 0;
+	struct vidtv_psi_table_sdt_service *s = sdt->service;
+
+	/*
+	 * from immediately after 'section_length' until
+	 * 'reserved_for_future_use'
+	 */
+	length += SDT_LEN_UNTIL_RESERVED_FOR_FUTURE_USE;
+
+	while (s) {
+		/* skip both pointers at the end */
+		length += sizeof(struct vidtv_psi_table_sdt_service) -
+			  sizeof(struct vidtv_psi_desc *) -
+			  sizeof(struct vidtv_psi_table_sdt_service *);
+
+		s->desc_length  = vidtv_psi_desc_comp_len(s->descriptor);
+		length         += s->desc_length;
+
+		s = s->next;
+	}
+
+	length += CRC_SIZE_IN_BYTES;
+
+	if (length > MAX_SECTION_LEN)
+		pr_warn_ratelimited("len %d > %d\n", length, MAX_SECTION_LEN);
+
+	sdt->header.section_length = length;
+}
+
+struct vidtv_psi_table_pat_program*
+vidtv_psi_pat_program_init(struct vidtv_psi_table_pat_program *head,
+			   u16 service_id,
+			   u16 pid)
+{
+	/*
+	 * if 'head' is attached to a table, caller should recompute
+	 * the section length afterwards at some point
+	 */
+	struct vidtv_psi_table_pat_program *program;
+
+	program = kzalloc(sizeof(*program), GFP_KERNEL);
+
+	program->service_id = cpu_to_be16(service_id);
+	/* pid for the PMT section in the TS */
+	program->pid        = pid;
+	program->next       = NULL;
+	program->reserved   = 0x7;
+
+	if (head) {
+		while (head->next)
+			head = head->next;
+
+		head->next = program;
+	}
+
+	return program;
+}
+
+void
+vidtv_psi_pat_program_destroy(struct vidtv_psi_table_pat_program *p)
+{
+	struct vidtv_psi_table_pat_program *curr = p;
+	struct vidtv_psi_table_pat_program *tmp  = NULL;
+
+	while (curr) {
+		tmp  = curr;
+		curr = curr->next;
+		kfree(tmp);
+	}
+}
+
+void
+vidtv_psi_pat_program_assign(struct vidtv_psi_table_pat *pat,
+			     struct vidtv_psi_table_pat_program *p)
+{
+	/* This function transfers ownership of p to the table */
+
+	u16    program_count                        = 0;
+	struct vidtv_psi_table_pat_program *program = p;
+	struct vidtv_psi_table_pat_program *temp    = pat->program;
+
+	while (program) {
+		++program_count;
+		program = program->next;
+	}
+
+	pat->programs = program_count;
+	pat->program  = p;
+
+	/* Recompute section length */
+	vidtv_psi_pat_table_comp_sec_len(pat);
+
+	/* reassign if the new size is too big */
+	if (pat->header.section_length > MAX_SECTION_LEN)
+		vidtv_psi_pat_program_assign(pat, temp);
+	else
+		vidtv_psi_pat_program_destroy(temp);
+}
+
+void vidtv_psi_pat_table_init(struct vidtv_psi_table_pat *pat,
+			      bool update_version_num,
+			      u16 transport_stream_id)
+{
+	static u8 pat_version;
+
+	pat->header.table_id = 0x0;
+	pat->header.syntax   = 0x1;
+	pat->header.zero     = 0x0;
+	pat->header.one      = 0x03;
+
+	/* transport stream ID, at will */
+	pat->header.id           = cpu_to_be16(transport_stream_id);
+	pat->header.current_next = 0x1;
+
+	/* ETSI 300 468: indicates changes in the TS described by this table*/
+	if (update_version_num)
+		++pat_version;
+
+	pat->header.version = pat_version;
+
+	pat->header.one2         = 0x03;
+	pat->header.section_id   = 0x0;
+	pat->header.last_section = 0x0;
+
+	pat->programs = 0;
+
+	vidtv_psi_pat_table_comp_sec_len(pat);
+}
+
+u32 vidtv_psi_pat_write_into(char *buf,
+			     u32 offset,
+			     struct vidtv_psi_table_pat *pat,
+			     u32 buf_sz,
+			     u8 *continuity_counter)
+{
+	/* the number of bytes written by this function */
+	u32   nbytes      = 0;
+	const u16 pat_pid = VIDTV_PAT_PID;
+
+	struct vidtv_psi_table_pat_program *p = pat->program;
+	struct header_write_args h_args       = {0};
+	struct psi_write_args args            = {0};
+	struct crc32_write_args c_args        = {0};
+
+	vidtv_psi_pat_table_comp_sec_len(pat);
+
+	h_args.dest_buf           = buf;
+	h_args.dest_offset        = offset;
+	h_args.h                  = &pat->header;
+	h_args.pid                = pat_pid;
+	h_args.continuity_counter = continuity_counter;
+	h_args.dest_buf_sz        = buf_sz;
+
+	nbytes += vidtv_psi_table_header_write_into(h_args);
+
+	/* note that the field 'u16 programs' is not really part of the PAT */
+
+	args.dest_buf           = buf;
+	args.pid                = pat_pid;
+	args.new_psi_section    = false;
+	args.continuity_counter = continuity_counter;
+	args.is_crc             = false;
+	args.dest_buf_sz        = buf_sz;
+
+	while (p) {
+		/* copy the PAT programs */
+		args.from = p;
+		/* skip the pointer */
+		args.len = sizeof(*p) -
+			   sizeof(struct vidtv_psi_table_pat_program *);
+		args.dest_offset = offset + nbytes;
+
+		nbytes += vidtv_psi_ts_psi_write_into(args);
+
+		p = p->next;
+	}
+
+	c_args.dest_buf           = buf;
+	c_args.dest_offset        = offset + nbytes;
+	c_args.pid                = pat_pid;
+	c_args.continuity_counter = continuity_counter;
+	c_args.dest_buf_sz        = buf_sz;
+
+	nbytes += table_section_crc32_write_into(c_args);
+
+	return nbytes;
+}
+
+void
+vidtv_psi_pat_table_destroy(struct vidtv_psi_table_pat *p)
+{
+	vidtv_psi_pat_program_destroy(p->program);
+}
+
+struct vidtv_psi_table_pmt_stream*
+vidtv_psi_pmt_stream_init(struct vidtv_psi_table_pmt_stream *head,
+			  enum vidtv_psi_stream_types stream_type,
+			  u16 es_pid)
+{
+	struct vidtv_psi_table_pmt_stream *stream;
+
+	stream = kzalloc(sizeof(*stream), GFP_KERNEL);
+
+	stream->type           = stream_type;
+	stream->elementary_pid = es_pid;
+	stream->reserved       = 0x07;
+
+	stream->desc_length = vidtv_psi_desc_comp_len(stream->descriptor);
+
+	stream->zero      = 0x0;
+	stream->reserved2 = 0x0f;
+
+	if (head) {
+		while (head->next)
+			head = head->next;
+
+		head->next = stream;
+	}
+
+	return stream;
+}
+
+void vidtv_psi_pmt_stream_destroy(struct vidtv_psi_table_pmt_stream *s)
+{
+	struct vidtv_psi_table_pmt_stream *curr_stream = s;
+	struct vidtv_psi_table_pmt_stream *tmp_stream  = NULL;
+
+	while (curr_stream) {
+		tmp_stream  = curr_stream;
+		curr_stream = curr_stream->next;
+		kfree(tmp_stream);
+	}
+}
+
+void vidtv_psi_pmt_stream_assign(struct vidtv_psi_table_pmt *pmt,
+				 struct vidtv_psi_table_pmt_stream *s)
+{
+	/* This function transfers ownership of s to the table */
+	struct vidtv_psi_table_pmt_stream *stream = s;
+	struct vidtv_psi_desc *desc               = s->descriptor;
+	struct vidtv_psi_table_pmt_stream *temp   = pmt->stream;
+
+	while (stream)
+		stream = stream->next;
+
+	while (desc)
+		desc = desc->next;
+
+	pmt->stream = s;
+	/* Recompute section length */
+	vidtv_psi_pmt_table_comp_sec_len(pmt);
+
+	/* reassign if the new size is too big */
+	if (pmt->header.section_length > MAX_SECTION_LEN)
+		vidtv_psi_pmt_stream_assign(pmt, temp);
+	else
+		vidtv_psi_pmt_stream_destroy(temp);
+}
+
+u16 vidtv_psi_pmt_get_pid(struct vidtv_psi_table_pmt *section,
+			  struct vidtv_psi_table_pat *pat)
+{
+	struct vidtv_psi_table_pat_program *program = pat->program;
+
+	/*
+	 * service_id is the same as program_number in the
+	 * corresponding program_map_section
+	 * see ETSI EN 300 468 v1.15.1 p. 24
+	 */
+	while (program) {
+		if (program->service_id == section->header.id)
+			return pat->program->pid;
+
+		program = program->next;
+	}
+
+	return TS_LAST_VALID_PID + 1; /* not found */
+}
+
+void vidtv_psi_pmt_table_init(struct vidtv_psi_table_pmt *pmt,
+			      bool update_version_num,
+			      u16 program_number,
+			      u16 pcr_pid)
+{
+	static u8 pmt_version;
+
+	pmt->header.table_id = 0x2;
+	pmt->header.syntax   = 0x1;
+	pmt->header.zero     = 0x0;
+	pmt->header.one      = 0x3;
+
+	pmt->header.id           = cpu_to_be16(program_number);
+	pmt->header.current_next = 0x1;
+
+	/* ETSI 300 468: indicates changes in the TS described by this table*/
+	if (update_version_num)
+		++pmt_version;
+
+	pmt->header.version = pmt_version;
+
+	pmt->header.one2         = 0x3;
+	pmt->header.section_id   = 0;
+	pmt->header.last_section = 0;
+
+	pmt->pcr_pid   = (pcr_pid) ? pcr_pid : 0x1fff;
+	pmt->reserved2 = 0x03;
+
+	pmt->reserved3 = 0x0f;
+	pmt->zero3     = 0x0;
+
+	pmt->desc_length = vidtv_psi_desc_comp_len(pmt->descriptor);
+
+	vidtv_psi_pmt_table_comp_sec_len(pmt);
+}
+
+u32 vidtv_psi_pmt_write_into(char *buf,
+			     u32 offset,
+			     struct vidtv_psi_table_pmt *pmt,
+			     u16 pid,
+			     u32 buf_sz,
+			     u8 *continuity_counter)
+{
+	/* the number of bytes written by this function */
+	u32    nbytes                             = 0;
+	struct vidtv_psi_desc *table_descriptor   = pmt->descriptor;
+	struct vidtv_psi_table_pmt_stream *stream = pmt->stream;
+	struct vidtv_psi_desc *stream_descriptor  = (stream) ?
+						    pmt->stream->descriptor :
+						    NULL;
+
+	struct header_write_args h_args = {0};
+	struct psi_write_args args      = {0};
+	struct desc_write_args d_args   = {0};
+	struct crc32_write_args c_args  = {0};
+
+	vidtv_psi_pmt_table_comp_sec_len(pmt);
+
+	h_args.dest_buf           = buf;
+	h_args.dest_offset        = offset;
+	h_args.h                  = &pmt->header;
+	h_args.pid                = pid;
+	h_args.continuity_counter = continuity_counter;
+	h_args.dest_buf_sz        = buf_sz;
+
+	nbytes += vidtv_psi_table_header_write_into(h_args);
+
+	/* write the two bitfields */
+	args.dest_buf = buf;
+	args.from     = pmt + sizeof(struct vidtv_psi_table_header);
+	args.len      = sizeof_field(struct vidtv_psi_table_pmt, bitfield) +
+			sizeof_field(struct vidtv_psi_table_pmt, bitfield2);
+	args.dest_offset        = offset + nbytes;
+	args.pid                = pid;
+	args.new_psi_section    = false;
+	args.continuity_counter = continuity_counter;
+	args.is_crc             = false;
+	args.dest_buf_sz        = buf_sz;
+
+	nbytes += vidtv_psi_ts_psi_write_into(args);
+
+	while (table_descriptor) {
+		/* write the descriptors, if any */
+		d_args.dest_buf           = buf;
+		d_args.dest_offset        = offset + nbytes;
+		d_args.desc               = table_descriptor;
+		d_args.pid                = pid;
+		d_args.continuity_counter = continuity_counter;
+		d_args.dest_buf_sz        = buf_sz;
+
+		nbytes += vidtv_psi_desc_write_into(d_args);
+
+		table_descriptor = table_descriptor->next;
+	}
+
+	while (stream) {
+		/* write the streams, if any */
+		args.from = stream;
+		args.len  = sizeof_field(struct vidtv_psi_table_pmt_stream,
+					 type) +
+			    sizeof_field(struct vidtv_psi_table_pmt_stream,
+					 bitfield) +
+			    sizeof_field(struct vidtv_psi_table_pmt_stream,
+					 bitfield2);
+		args.dest_offset = offset + nbytes;
+
+		nbytes += vidtv_psi_ts_psi_write_into(args);
+
+		while (stream_descriptor) {
+			/* write the stream descriptors, if any */
+			d_args.desc        = stream_descriptor;
+			d_args.dest_offset = offset + nbytes;
+
+			nbytes += vidtv_psi_desc_write_into(d_args);
+
+			stream_descriptor = stream_descriptor->next;
+		}
+
+		stream = stream->next;
+	}
+
+	c_args.dest_buf           = buf;
+	c_args.dest_offset        = offset + nbytes;
+	c_args.pid                = pid;
+	c_args.continuity_counter = continuity_counter;
+	c_args.dest_buf_sz        = buf_sz;
+
+	nbytes += table_section_crc32_write_into(c_args);
+
+	return nbytes;
+}
+
+void vidtv_psi_pmt_table_destroy(struct vidtv_psi_table_pmt *pmt)
+{
+	struct vidtv_psi_desc *curr_desc = pmt->descriptor;
+	struct vidtv_psi_desc *tmp_desc  = NULL;
+
+	while (curr_desc) {
+		tmp_desc  = curr_desc;
+		curr_desc = curr_desc->next;
+		vidtv_psi_desc_destroy(tmp_desc);
+		kfree(tmp_desc);
+	}
+
+	vidtv_psi_pmt_stream_destroy(pmt->stream);
+}
+
+void vidtv_psi_sdt_table_init(struct vidtv_psi_table_sdt *sdt,
+			      bool update_version_num,
+			      u16 transport_stream_id)
+{
+	static u8 sdt_version;
+
+	sdt->header.table_id = 0x42;
+
+	sdt->header.one  = 0x3;
+	sdt->header.zero = 0x1;
+	/*
+	 * The PAT, PMT, and CAT all set this to 0.
+	 * Other tables set this to 1.
+	 */
+	sdt->header.syntax = 0x1;
+
+	/*
+	 * This is a 16-bit field which serves as a label for identification
+	 * of the TS, about which the SDT informs, from any other multiplex
+	 * within the delivery system.
+	 */
+	sdt->header.id           = cpu_to_be16(transport_stream_id);
+	sdt->header.current_next = 0x1;
+
+	/* ETSI 300 468: indicates changes in the TS described by this table*/
+	if (update_version_num)
+		++sdt_version;
+
+	sdt->header.version = sdt_version;
+
+	sdt->header.one2         = 0x3;
+	sdt->header.section_id   = 0;
+	sdt->header.last_section = 0;
+
+	sdt->network_id = cpu_to_be16(transport_stream_id);
+	sdt->reserved   = 0xff;
+
+	vidtv_psi_sdt_table_comp_sec_len(sdt);
+}
+
+u32 vidtv_psi_sdt_write_into(char *buf,
+			     u32 offset,
+			     struct vidtv_psi_table_sdt *sdt,
+			     u32 buf_sz,
+			     u8 *continuity_counter)
+{
+	u32 nbytes  = 0;              /* the number of bytes written */
+	u16 sdt_pid = VIDTV_SDT_PID;  /* see ETSI EN 300 468 v1.15.1 p. 11 */
+
+	struct vidtv_psi_table_sdt_service *service = sdt->service;
+	struct vidtv_psi_desc *service_desc = (sdt->service) ?
+					      sdt->service->descriptor :
+					      NULL;
+
+	struct header_write_args h_args = {0};
+	struct psi_write_args args      = {0};
+	struct desc_write_args d_args   = {0};
+	struct crc32_write_args c_args  = {0};
+
+	vidtv_psi_sdt_table_comp_sec_len(sdt);
+
+	h_args.dest_buf           = buf;
+	h_args.dest_offset        = offset;
+	h_args.h                  = &sdt->header;
+	h_args.pid                = sdt_pid;
+	h_args.continuity_counter = continuity_counter;
+	h_args.dest_buf_sz        = buf_sz;
+
+	nbytes += vidtv_psi_table_header_write_into(h_args);
+
+	args.dest_buf = buf;
+	args.from     = sdt + sizeof(struct vidtv_psi_table_header);
+
+	args.len      = sizeof_field(struct vidtv_psi_table_sdt, network_id) +
+			sizeof_field(struct vidtv_psi_table_sdt, reserved);
+
+	args.dest_offset        = offset + nbytes;
+	args.pid                = sdt_pid;
+	args.new_psi_section    = false;
+	args.continuity_counter = continuity_counter;
+	args.is_crc             = false;
+	args.dest_buf_sz        = buf_sz;
+
+	/* copy u16 network_id + u8 reserved)*/
+	nbytes += vidtv_psi_ts_psi_write_into(args);
+
+	while (service) {
+		/* copy the services, if any */
+		args.from = service;
+		/* skip both pointers at the end */
+		args.len = sizeof(struct vidtv_psi_table_sdt_service) -
+			   sizeof(struct vidtv_psi_desc *) -
+			   sizeof(struct vidtv_psi_table_sdt_service *);
+		args.dest_offset = offset + nbytes;
+
+		nbytes += vidtv_psi_ts_psi_write_into(args);
+
+		while (service_desc) {
+			/* copy the service descriptors, if any */
+			d_args.dest_buf           = buf;
+			d_args.dest_offset        = offset + nbytes;
+			d_args.desc               = service_desc;
+			d_args.pid                = sdt_pid;
+			d_args.continuity_counter = continuity_counter;
+			d_args.dest_buf_sz        = buf_sz;
+
+			nbytes += vidtv_psi_desc_write_into(d_args);
+
+			service_desc = service_desc->next;
+		}
+
+		service = service->next;
+	}
+
+	c_args.dest_buf           = buf;
+	c_args.dest_offset        = offset + nbytes;
+	c_args.pid                = sdt_pid;
+	c_args.continuity_counter = continuity_counter;
+	c_args.dest_buf_sz        = buf_sz;
+
+	nbytes += table_section_crc32_write_into(c_args);
+
+	return nbytes;
+}
+
+void vidtv_psi_sdt_table_destroy(struct vidtv_psi_table_sdt *sdt)
+{
+	struct vidtv_psi_table_sdt_service *curr_service = sdt->service;
+	struct vidtv_psi_table_sdt_service *tmp_service  = NULL;
+	struct vidtv_psi_desc *curr_desc = (sdt->service) ?
+					   sdt->service->descriptor : NULL;
+	struct vidtv_psi_desc *tmp_desc = NULL;
+
+	while (curr_service) {
+		curr_desc = curr_service->descriptor;
+
+		while (curr_desc) {
+			/* clear all descriptors for the service */
+			tmp_desc  = curr_desc;
+			curr_desc = curr_desc->next;
+			vidtv_psi_desc_destroy(tmp_desc);
+			kfree(tmp_desc);
+		}
+
+		/* then clear the current service */
+		tmp_service  = curr_service;
+		curr_service = curr_service->next;
+		kfree(tmp_service);
+	}
+}
+
+struct vidtv_psi_table_sdt_service
+*vidtv_psi_sdt_service_init(struct vidtv_psi_table_sdt_service *head,
+			    u16 service_id)
+{
+	/*
+	 * if 'head' is attached to a table, caller should recompute
+	 * the section length afterwards at some point
+	 */
+	struct vidtv_psi_table_sdt_service *service;
+
+	service = kzalloc(sizeof(*service), GFP_KERNEL);
+
+	/*
+	 * ETSI 300 468: this is a 16bit field which serves as a label to
+	 * identify this service from any other service within the TS.
+	 * The service id is the same as the program number in the
+	 * corresponding program_map_section
+	 */
+	service->service_id            = cpu_to_be16(service_id);
+	service->EIT_schedule          = 0x0;
+	service->EIT_present_following = 0x0;
+	service->reserved              = 0x3f;        /* all bits on */
+	service->free_CA_mode          = 0x0;         /* not scrambled */
+	service->running_status        = RUNNING;
+
+	if (head) {
+		while (head->next)
+			head = head->next;
+
+		head->next = service;
+	}
+
+	return service;
+}
+
+void
+vidtv_psi_sdt_service_destroy(struct vidtv_psi_table_sdt_service *service)
+{
+	struct vidtv_psi_table_sdt_service *curr = service;
+	struct vidtv_psi_table_sdt_service *tmp  = NULL;
+
+	while (curr) {
+		tmp  = curr;
+		curr = curr->next;
+		kfree(tmp);
+	}
+}
+
+void
+vidtv_psi_sdt_service_assign(struct vidtv_psi_table_sdt *sdt,
+			     struct vidtv_psi_table_sdt_service *service)
+{
+	struct vidtv_psi_table_sdt_service *temp = sdt->service;
+
+	sdt->service = service;
+
+	/* recompute section length */
+	vidtv_psi_sdt_table_comp_sec_len(sdt);
+
+	/* reassign if the new size is too big */
+	if (sdt->header.section_length > MAX_SECTION_LEN)
+		vidtv_psi_sdt_service_assign(sdt, temp);
+	else
+		vidtv_psi_sdt_service_destroy(temp);
+}
+
+void
+vidtv_psi_pmt_create_sec_for_each_pat_entry(struct vidtv_psi_table_pat *pat,
+					    struct vidtv_psi_table_pmt sec[])
+
+{
+	/*
+	 * PMTs contain information about programs. For each program,
+	 * there is one PMT section. This function will create a section
+	 * for each program found in the PAT
+	 */
+	struct vidtv_psi_table_pat_program *program = pat->program;
+	u32    i                                    = 0;
+
+	while (program) {
+		vidtv_psi_pmt_table_init(&sec[i],
+					 false,
+					 be16_to_cpu(sec[i].header.id),
+					 0);
+
+		++i;
+		program = program->next;
+	}
+}
drivers/media/test-drivers/vidtv/vidtv_psi.h new file +415 -0

415 lines not on this page · raw message

Signature · 1 line
2.26.2
author maintainer
#9 lore raw

RFC v5 8/10 media: vidtv: implement a PES packetizer

In reply to Daniel W. S. Almeida

From: "Daniel W. S. Almeida" <[email protected]>

Implement the PES logic to convert encoder data into MPEG TS packets. These TS packets can then be fed into a TS multiplexer and eventually into userspace.

---
 .../media/test-drivers/vidtv/vidtv_common.h   |   2 +
 drivers/media/test-drivers/vidtv/vidtv_pes.c  | 450 ++++++++++++++++++
 drivers/media/test-drivers/vidtv/vidtv_pes.h  | 186 ++++++++
 3 files changed, 638 insertions(+)
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_pes.c
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_pes.h
drivers/media/test-drivers/vidtv/vidtv_common.h +2 -0
index a3cb303cc7423..1a31973f3ac61 100644
@@ -24,4 +24,6 @@ u32 vidtv_memset(void *to,
 		 int c,
 		 size_t len);
 
+u64 vidtv_extract_bits(u64 value, u8 start_bit, u8 nbits);
+
 #endif // VIDTV_COMMON_H
drivers/media/test-drivers/vidtv/vidtv_pes.c new file +450 -0

450 lines not on this page · raw message

drivers/media/test-drivers/vidtv/vidtv_pes.h new file +186 -0

186 lines not on this page · raw message

Signature · 1 line
2.26.2
author maintainer
#10 lore raw

RFC v5 9/10 media: vidtv: Implement a SMPTE 302M encoder

In reply to Daniel W. S. Almeida

From: "Daniel W. S. Almeida" <[email protected]>

Implement a S302M encoder to make it possible to insert PCM audio data in the generated MPEG Transport Stream.

This shall enable passing an audio signal into userspace so it can be decoded and played by media software.

---
 .../media/test-drivers/vidtv/vidtv_common.h   |   2 +
 .../media/test-drivers/vidtv/vidtv_encoder.h  | 103 +++
 .../media/test-drivers/vidtv/vidtv_s302m.c    | 638 ++++++++++++++++++
 .../media/test-drivers/vidtv/vidtv_s302m.h    | 119 ++++
 4 files changed, 862 insertions(+)
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_encoder.h
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_s302m.c
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_s302m.h
drivers/media/test-drivers/vidtv/vidtv_common.h +2 -0
index 1a31973f3ac61..a0480825b23a9 100644
@@ -12,6 +12,8 @@
 
 #include <linux/types.h>
 
+#define CLOCK_UNIT_90KHZ 90000
+
 u32 vidtv_memcpy(void *to,
 		 size_t to_offset,
 		 size_t to_size,
drivers/media/test-drivers/vidtv/vidtv_encoder.h new file +103 -0

103 lines not on this page · raw message

drivers/media/test-drivers/vidtv/vidtv_s302m.c new file +638 -0

638 lines not on this page · raw message

drivers/media/test-drivers/vidtv/vidtv_s302m.h new file +119 -0

119 lines not on this page · raw message

Signature · 1 line
2.26.2
author maintainer
#11 lore raw

RFC v5 10/10 media: vidtv: Add a MPEG Transport Stream Multiplexer

In reply to Daniel W. S. Almeida

From: "Daniel W. S. Almeida" <[email protected]>

Add a MPEG Transport Stream multiplexer responsible for polling encoders, interleaving packets, padding the resulting stream with NULL packets if necessary and then delivering the resulting TS packets to the bridge driver so it can feed the demux.

This patch includes a "channel" abstraction, which attempts to map a MPEG service into a struct that vidtv can work with.

When vidtv boots, it will create some hardcoded channels:

-Their services will be concatenated to populate the SDT.
-Their programs will be concatenated to populate the PAT
-For each program in the PAT, a PMT section will be created
-The PMT section for a channel will be assigned its streams. -Every stream will have its corresponding encoder polled to produce TS packets -These packets may be interleaved by the mux and then delivered to the bridg

---
 drivers/media/test-drivers/vidtv/Makefile     |   3 +-
 .../media/test-drivers/vidtv/vidtv_bridg.c    |  76 +++
 .../media/test-drivers/vidtv/vidtv_bridg.h    |   2 +
 .../media/test-drivers/vidtv/vidtv_channel.c  | 339 ++++++++++++++
 .../media/test-drivers/vidtv/vidtv_channel.h  |  66 +++
 .../media/test-drivers/vidtv/vidtv_common.h   |   3 +
 drivers/media/test-drivers/vidtv/vidtv_mux.c  | 434 ++++++++++++++++++
 drivers/media/test-drivers/vidtv/vidtv_mux.h  | 105 +++++
 drivers/media/test-drivers/vidtv/vidtv_psi.c  |  18 +
 drivers/media/test-drivers/vidtv/vidtv_psi.h  |   5 +
 10 files changed, 1050 insertions(+), 1 deletion(-)
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_channel.c
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_channel.h
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_mux.c
 create mode 100644 drivers/media/test-drivers/vidtv/vidtv_mux.h
drivers/media/test-drivers/vidtv/Makefile +2 -1
index e0bb1b3bedad6..8663196fbbc56 100644
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 
-vidtv_bridge-objs = vidtv_bridg.o
+vidtv_bridge-objs = vidtv_bridg.o vidtv_common.o vidtv_ts.o vidtv_psi.o \
+		    vidtv_pes.o vidtv_s302m.o vidtv_channel.o vidtv_mux.o
 
 obj-$(CONFIG_DVB_VIDTV)	+= vidtv_tuner.o vidtv_demod.o vidtv_bridge.o
drivers/media/test-drivers/vidtv/vidtv_bridg.c +76 -0

119 lines not on this page · raw message

drivers/media/test-drivers/vidtv/vidtv_bridg.h +2 -0
index dead155c2735c..191bd60adc6f0 100644
@@ -17,6 +17,7 @@
 #include <media/dvb_demux.h>
 #include <media/dmxdev.h>
 #include <linux/i2c.h>
+#include "vidtv_mux.h"
 
 struct vidtv_dvb {
 	struct dvb_frontend *fe[NUM_FE];
@@ -32,6 +33,7 @@ struct vidtv_dvb {
 	struct mutex feed_lock; /* start/stop feed */
 
 	bool streaming;
+	struct vidtv_mux *mux;
 };
 
 #endif // VIDTV_BRIDG_H
drivers/media/test-drivers/vidtv/vidtv_channel.c new file +339 -0

339 lines not on this page · raw message

drivers/media/test-drivers/vidtv/vidtv_channel.h new file +66 -0

66 lines not on this page · raw message

drivers/media/test-drivers/vidtv/vidtv_common.h +3 -0
index a0480825b23a9..a13e9331955a7 100644
@@ -13,6 +13,9 @@
 #include <linux/types.h>
 
 #define CLOCK_UNIT_90KHZ 90000
+#define CLOCK_UNIT_27MHZ 27000000
+#define SLEEP_USECS 10000
+#define TRANSPORT_STREAM_ID 0x744
 
 u32 vidtv_memcpy(void *to,
 		 size_t to_offset,
drivers/media/test-drivers/vidtv/vidtv_mux.c new file +434 -0

434 lines not on this page · raw message

drivers/media/test-drivers/vidtv/vidtv_mux.h new file +105 -0

105 lines not on this page · raw message

drivers/media/test-drivers/vidtv/vidtv_psi.c +18 -0
index 37b1ecab5ee79..17d2d711014d6 100644
@@ -1035,3 +1035,21 @@ vidtv_psi_pmt_create_sec_for_each_pat_entry(struct vidtv_psi_table_pat *pat,
 		program = program->next;
 	}
 }
+
+struct vidtv_psi_table_pmt
+*vidtv_psi_find_pmt_sec(struct vidtv_psi_table_pmt pmt_sections[],
+			u16 nsections,
+			u16 program_num)
+{
+	/* find the PMT section associated with 'program_num' */
+	struct vidtv_psi_table_pmt *sec = NULL;
+	u32 i;
+
+	for (i = 0; i < nsections; ++i) {
+		sec = &pmt_sections[i];
+		if (be16_to_cpu(sec->header.id) == program_num)
+			return sec;
+	}
+
+	return NULL;
+}
drivers/media/test-drivers/vidtv/vidtv_psi.h +5 -0
index 77b616a46757a..f45540d53b351 100644
@@ -412,4 +412,9 @@ u32 vidtv_psi_pmt_write_into(char *buf,
 			     u32 buf_sz,
 			     u8 *continuity_counter);
 
+struct vidtv_psi_table_pmt
+*vidtv_psi_find_pmt_sec(struct vidtv_psi_table_pmt *pmt_sections,
+			u16 nsections,
+			u16 program_num);
+
 #endif // VIDTV_PSI_H
Signature · 1 line
2.26.2
#12 lore raw

Re: [RFC, WIP, v5 10/10] media: vidtv: Add a MPEG Transport Stream Multiplexer

[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi "Daniel,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on linuxtv-media/master]
[also build test WARNING on next-20200515]
[cannot apply to v5.7-rc5]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Daniel-W-S-Almeida/media-vidtv-implement-a-virtual-DVB-driver/20200516-055059
base:   git://linuxtv.org/media_tree.git master
config: parisc-allyesconfig (attached as .config)
compiler: hppa-linux-gcc (GCC) 9.3.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=parisc

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>, old ones prefixed by <<):

In file included from include/linux/bitops.h:5,
from include/linux/kernel.h:12,
from arch/parisc/include/asm/bug.h:5,
from include/linux/bug.h:5,
from include/linux/thread_info.h:12,
from include/asm-generic/current.h:5,
from ./arch/parisc/include/generated/asm/current.h:1,
from include/linux/sched.h:12,
from include/linux/ratelimit.h:6,
from drivers/media/test-drivers/vidtv/vidtv_pes.c:18:
drivers/media/test-drivers/vidtv/vidtv_pes.c: In function 'vidtv_pes_write_pts_dts':

>> include/linux/bits.h:37:11: warning: right shift count is negative [-Wshift-count-negative]

37 | (~UL(0) >> (BITS_PER_LONG - 1 - (h))))
| ^~
include/linux/bits.h:39:31: note: in expansion of macro '__GENMASK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~

>> drivers/media/test-drivers/vidtv/vidtv_pes.c:96:33: note: in expansion of macro 'GENMASK'
96 |   pts_dts.pts1    = (args.pts & GENMASK(32, 30)) >> 30;
|                                 ^~~~~~~
>> include/linux/bits.h:37:11: warning: right shift count is negative [-Wshift-count-negative]

37 | (~UL(0) >> (BITS_PER_LONG - 1 - (h))))
| ^~
include/linux/bits.h:39:31: note: in expansion of macro '__GENMASK'
39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~
drivers/media/test-drivers/vidtv/vidtv_pes.c:105:33: note: in expansion of macro 'GENMASK'
105 | pts_dts.dts1 = (args.dts & GENMASK(32, 30)) >> 30;
| ^~~~~~~

>> include/linux/bits.h:37:11: warning: right shift count is negative [-Wshift-count-negative]

37 | (~UL(0) >> (BITS_PER_LONG - 1 - (h))))
| ^~
include/linux/bits.h:39:31: note: in expansion of macro '__GENMASK'
39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~
drivers/media/test-drivers/vidtv/vidtv_pes.c:117:33: note: in expansion of macro 'GENMASK'
117 | pts_dts.pts1 = (args.pts & GENMASK(32, 30)) >> 30;
| ^~~~~~~

vim +37 include/linux/bits.h

295bcca84916cb Rikard Falkeborn 2020-04-06  34  
295bcca84916cb Rikard Falkeborn 2020-04-06  35  #define __GENMASK(h, l) \
95b980d62d52c4 Masahiro Yamada  2019-07-16  36  	(((~UL(0)) - (UL(1) << (l)) + 1) & \
95b980d62d52c4 Masahiro Yamada  2019-07-16 @37  	 (~UL(0) >> (BITS_PER_LONG - 1 - (h))))
295bcca84916cb Rikard Falkeborn 2020-04-06  38  #define GENMASK(h, l) \
295bcca84916cb Rikard Falkeborn 2020-04-06  39  	(GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))

8bd9cb51daac89 Will Deacon 2018-06-19 40

:::::: The code at line 37 was first introduced by commit
:::::: 95b980d62d52c4c1768ee719e8db3efe27ef52b2 linux/bits.h: make BIT(), GENMASK(), and friends available in assembly

:::::: TO: Masahiro Yamada <[email protected]> :::::: CC: Linus Torvalds <[email protected]>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#13 lore raw

Re: [RFC, WIP, v5 10/10] media: vidtv: Add a MPEG Transport Stream Multiplexer

In reply to Daniel W. S. Almeida
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi "Daniel,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on linuxtv-media/master]
[also build test WARNING on next-20200515]
[cannot apply to v5.7-rc5]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Daniel-W-S-Almeida/media-vidtv-implement-a-virtual-DVB-driver/20200516-055059
base:   git://linuxtv.org/media_tree.git master
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.1-193-gb8fad4bc-dirty
        make ARCH=x86_64 allmodconfig
        make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

If you fix the issue, kindly add following tag as appropriate

sparse warnings: (new ones prefixed by >>)

>> drivers/media/test-drivers/vidtv/vidtv_psi.c:64:43: sparse: sparse: Using plain integer as NULL pointer

drivers/media/test-drivers/vidtv/vidtv_psi.c:174:43: sparse: sparse: Using plain integer as NULL pointer drivers/media/test-drivers/vidtv/vidtv_psi.c:261:43: sparse: sparse: Using plain integer as NULL pointer drivers/media/test-drivers/vidtv/vidtv_psi.c:297:43: sparse: sparse: Using plain integer as NULL pointer drivers/media/test-drivers/vidtv/vidtv_psi.c:512:50: sparse: sparse: Using plain integer as NULL pointer drivers/media/test-drivers/vidtv/vidtv_psi.c:513:50: sparse: sparse: Using plain integer as NULL pointer drivers/media/test-drivers/vidtv/vidtv_psi.c:514:50: sparse: sparse: Using plain integer as NULL pointer drivers/media/test-drivers/vidtv/vidtv_psi.c:702:44: sparse: sparse: Using plain integer as NULL pointer drivers/media/test-drivers/vidtv/vidtv_psi.c:703:44: sparse: sparse: Using plain integer as NULL pointer drivers/media/test-drivers/vidtv/vidtv_psi.c:704:44: sparse: sparse: Using plain integer as NULL pointer drivers/media/test-drivers/vidtv/vidtv_psi.c:705:44: sparse: sparse: Using plain integer as NULL pointer drivers/media/test-drivers/vidtv/vidtv_psi.c:852:44: sparse: sparse: Using plain integer as NULL pointer drivers/media/test-drivers/vidtv/vidtv_psi.c:853:44: sparse: sparse: Using plain integer as NULL pointer drivers/media/test-drivers/vidtv/vidtv_psi.c:854:44: sparse: sparse: Using plain integer as NULL pointer drivers/media/test-drivers/vidtv/vidtv_psi.c:855:44: sparse: sparse: Using plain integer as NULL pointer
--

>> drivers/media/test-drivers/vidtv/vidtv_pes.c:83:54: sparse: sparse: missing braces around initializer
   drivers/media/test-drivers/vidtv/vidtv_pes.c:84:54: sparse: sparse: missing braces around initializer
   drivers/media/test-drivers/vidtv/vidtv_pes.c:142:54: sparse: sparse: missing braces around initializer
   drivers/media/test-drivers/vidtv/vidtv_pes.c:143:54: sparse: sparse: missing braces around initializer
>> drivers/media/test-drivers/vidtv/vidtv_pes.c:303:59: sparse: sparse: Using plain integer as NULL pointer
   drivers/media/test-drivers/vidtv/vidtv_pes.c:304:59: sparse: sparse: Using plain integer as NULL pointer
>> drivers/media/test-drivers/vidtv/vidtv_pes.c:96:47: sparse: sparse: shift count is negative (-1)
   drivers/media/test-drivers/vidtv/vidtv_pes.c:105:47: sparse: sparse: shift count is negative (-1)
   drivers/media/test-drivers/vidtv/vidtv_pes.c:117:47: sparse: sparse: shift count is negative (-1)
--
>> drivers/media/test-drivers/vidtv/vidtv_s302m.c:404:42: sparse: sparse: missing braces around initializer
   drivers/media/test-drivers/vidtv/vidtv_s302m.c:427:45: sparse: sparse: missing braces around initializer
   drivers/media/test-drivers/vidtv/vidtv_s302m.c:428:45: sparse: sparse: missing braces around initializer
--
>> drivers/media/test-drivers/vidtv/vidtv_channel.c:59:62: sparse: sparse: Using plain integer as NULL pointer
--
>> drivers/media/test-drivers/vidtv/vidtv_mux.c:163:39: sparse: sparse: Using plain integer as NULL pointer

drivers/media/test-drivers/vidtv/vidtv_mux.c:205:39: sparse: sparse: Using plain integer as NULL pointer drivers/media/test-drivers/vidtv/vidtv_mux.c:267:47: sparse: sparse: Using plain integer as NULL pointer

vim +64 drivers/media/test-drivers/vidtv/vidtv_psi.c

07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   36  
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   37  static u32
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   38  vidtv_psi_ts_psi_write_into(struct psi_write_args args)
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   39  {
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   40  	/*
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   41  	 * Packetize PSI sections into TS packets:
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   42  	 * push a TS header (4bytes) every 184 bytes
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   43  	 * manage the continuity_counter
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   44  	 * add stuffing after the CRC
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   45  	 */
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   46  
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   47  	u32  nbytes_past_boundary = (args.dest_offset % TS_PACKET_LEN);
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   48  	bool aligned              = nbytes_past_boundary == 0;
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   49  
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   50  	/*
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   51  	 * whether we need to fragment the data into multiple ts packets
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   52  	 * if we are aligned we need to spare one byte for the pointer_field
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   53  	 */
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   54  	bool split = (aligned) ?
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   55  		     args.len > TS_PAYLOAD_LEN - 1 :
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   56  		     nbytes_past_boundary + args.len > TS_PACKET_LEN;
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   57  
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   58  	/* how much we can write in this packet */
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   59  	u32 payload_write_len = (split) ?
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   60  				(aligned)     ? TS_PAYLOAD_LEN       :
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   61  				TS_PACKET_LEN - nbytes_past_boundary :
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   62  				args.len;
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   63  
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  @64  	struct psi_write_args new_args = {0};
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   65  	struct vidtv_mpeg_ts ts_header = {0};
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   66  
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   67  	u32 nbytes = 0;  /* number of bytes written by this function */
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   68  	u32 temp   = 0;
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   69  
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   70  	/* Just a sanity check, should not really happen because we stuff
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   71  	 * the packet when we finish a section, i.e. when we write the crc at
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   72  	 * the end. But if this happens then we have messed up the logic
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   73  	 * somewhere.
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   74  	 */
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   75  	if (args.new_psi_section && !aligned) {
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   76  		pr_warn_ratelimited("Cannot write a new PSI section in a misaligned buffer\n");
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   77  
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   78  		/* forcibly align and hope for the best */
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   79  		nbytes += vidtv_memset(args.dest_buf,
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   80  				       args.dest_offset + nbytes,
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   81  				       args.dest_buf_sz,
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   82  				       TS_FILL_BYTE,
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   83  				       TS_PACKET_LEN - nbytes_past_boundary);
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   84  
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   85  		aligned = true;
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   86  	}
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   87  
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   88  	if (aligned) {
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   89  		/* if at a packet boundary, write a new TS header */
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   90  		ts_header.sync_byte          = TS_SYNC_BYTE;
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   91  		ts_header.tei                = 0;
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   92  		ts_header.payload_start      = 1;
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   93  		ts_header.pid                = args.pid;
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   94  		ts_header.priority           = 0;
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   95  		ts_header.scrambling         = 0;
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   96  		ts_header.continuity_counter = *args.continuity_counter;
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   97  		ts_header.payload            = 1;
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   98  		/* no adaptation field */
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15   99  		ts_header.adaptation_field = 0;
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  100  
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  101  		/* copy the header */
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  102  		nbytes += vidtv_memcpy(args.dest_buf,
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  103  				       args.dest_offset + nbytes,
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  104  				       args.dest_buf_sz,
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  105  				       &ts_header,
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  106  				       sizeof(ts_header));
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  107  
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  108  		/*
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  109  		 * increment the countinuity counter since we have started a new
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  110  		 * packet
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  111  		 *
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  112  		 * This will trigger a discontinuity if the buffer is full,
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  113  		 * which is what we want: the continuity counter will be
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  114  		 * incremented but nothing will get copied by
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  115  		 * vidtv_memcpy/vidtv_memset, effectively dropping the packet.
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  116  		 */
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  117  		vidtv_ts_inc_cc(args.continuity_counter);
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  118  	}
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  119  
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  120  	if (args.new_psi_section) {
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  121  		/* write the pointer_field in the first byte of the payload */
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  122  		temp = vidtv_memset(args.dest_buf,
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  123  				    args.dest_offset + nbytes,
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  124  				    args.dest_buf_sz,
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  125  				    0x0,
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  126  				    1);
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  127  		/* one byte was used by the pointer field*/
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  128  		nbytes += temp;
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  129  		if (payload_write_len == TS_PAYLOAD_LEN)
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  130  			payload_write_len -= temp;
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  131  	}
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  132  
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  133  	/* write as much of the payload as we possibly can */
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  134  	nbytes += vidtv_memcpy(args.dest_buf,
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  135  			       args.dest_offset + nbytes,
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  136  			       args.dest_buf_sz,
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  137  			       args.from,
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  138  			       payload_write_len);
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  139  
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  140  	if (split) {
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  141  		/* 'payload_write_len' written from a total of 'len' requested*/
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  142  		args.len -= payload_write_len;
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  143  		/*
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  144  		 * recursively write the rest of the data until we do not
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  145  		 * need to split it anymore
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  146  		 */
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  147  		memcpy(&new_args, &args, sizeof(struct psi_write_args));
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  148  		new_args.from            = args.from + payload_write_len;
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  149  		new_args.dest_offset     = args.dest_offset + nbytes;
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  150  		new_args.new_psi_section = false;
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  151  
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  152  		nbytes += vidtv_psi_ts_psi_write_into(new_args);
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  153  	}
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  154  
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  155  	/*
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  156  	 * as the CRC is last in the section, stuff the rest of the
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  157  	 * packet if there is any remaining space in there
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  158  	 */
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  159  	if (args.is_crc)
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  160  		nbytes += vidtv_memset(args.dest_buf,
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  161  				       args.dest_offset + nbytes,
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  162  				       args.dest_buf_sz,
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  163  				       TS_FILL_BYTE,
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  164  				       TS_PACKET_LEN - payload_write_len);
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  165  
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  166  	return nbytes;
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  167  }
07dd2778c1ca46 Daniel W. S. Almeida 2020-05-15  168  

:::::: The code at line 64 was first introduced by commit
:::::: 07dd2778c1ca4652a340f23dfb44bab57e1e6066 media: vidtv: implement a PSI generator

:::::: TO: Daniel W. S. Almeida <[email protected]> :::::: CC: 0day robot <[email protected]>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#14 lore raw

Re: [RFC, WIP, v5 10/10] media: vidtv: Add a MPEG Transport Stream Multiplexer

In reply to Daniel W. S. Almeida
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi "Daniel,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on next-20200515]
[cannot apply to v5.7-rc5]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Daniel-W-S-Almeida/media-vidtv-implement-a-virtual-DVB-driver/20200516-055059
base:   git://linuxtv.org/media_tree.git master
config: mips-allyesconfig (attached as .config)
compiler: mips-linux-gcc (GCC) 9.3.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=mips

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>, old ones prefixed by <<):

mips-linux-ld: drivers/media/test-drivers/vidtv/vidtv_ts.o: in function `vidtv_ts_pcr_write_into':

>> vidtv_ts.c:(.text.vidtv_ts_pcr_write_into+0xfc): undefined reference to `__umoddi3'
>> mips-linux-ld: vidtv_ts.c:(.text.vidtv_ts_pcr_write_into+0x118): undefined reference to `__udivdi3'
mips-linux-ld: drivers/media/test-drivers/vidtv/vidtv_s302m.o: in function `vidtv_s302m_encode':
>> vidtv_s302m.c:(.text.vidtv_s302m_encode+0x1fc): undefined reference to `__udivdi3'
mips-linux-ld: drivers/media/test-drivers/vidtv/vidtv_mux.o: in function `vidtv_mux_tick':
>> vidtv_mux.c:(.text.vidtv_mux_tick+0x7f8): undefined reference to `__udivdi3'
>> mips-linux-ld: vidtv_mux.c:(.text.vidtv_mux_tick+0x820): undefined reference to `__udivdi3'

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org