Commit a8bd461c authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab
Browse files

media: vidtv: do some cleanups at the driver



Do some cleanups at the coding style of the driver:
- remove "inline" declarations;
- use reverse xmas-tree for local var declarations;
- Adjust some indent to avoid breaking 80-cols;
- Cleanup some comments.

No functional changes.

Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent 163d72a2
Loading
Loading
Loading
Loading
+43 −38
Original line number Diff line number Diff line
@@ -4,7 +4,8 @@
 * validate the existing APIs in the media subsystem. It can also aid
 * developers working on userspace applications.
 *
 * When this module is loaded, it will attempt to modprobe 'dvb_vidtv_tuner' and 'dvb_vidtv_demod'.
 * When this module is loaded, it will attempt to modprobe 'dvb_vidtv_tuner'
 * and 'dvb_vidtv_demod'.
 *
 * Copyright (C) 2020 Daniel W. S. Almeida
 */
@@ -24,18 +25,21 @@
#include "vidtv_ts.h"
#include "vidtv_tuner.h"

//#define MUX_BUF_MAX_SZ
//#define MUX_BUF_MIN_SZ
#define MUX_BUF_MIN_SZ 90164
#define MUX_BUF_MAX_SZ (MUX_BUF_MIN_SZ * 10)
#define TUNER_DEFAULT_ADDR 0x68
#define DEMOD_DEFAULT_ADDR 0x60
#define VIDTV_DEFAULT_NETWORK_ID 0x744
#define VIDTV_DEFAULT_NETWORK_NAME "LinuxTV.org"

/* LNBf fake parameters: ranges used by an Universal (extended) European LNBf */
#define LNB_CUT_FREQUENCY	11700000
#define LNB_LOW_FREQ		9750000
#define LNB_HIGH_FREQ		10600000

/*
 * The LNBf fake parameters here are the ranges used by an
 * Universal (extended) European LNBf, which is likely the most common LNBf
 * found on Satellite digital TV system nowadays.
 */
#define LNB_CUT_FREQUENCY	11700000	/* high IF frequency */
#define LNB_LOW_FREQ		9750000		/* low IF frequency */
#define LNB_HIGH_FREQ		10600000	/* transition frequency */

static unsigned int drop_tslock_prob_on_low_snr;
module_param(drop_tslock_prob_on_low_snr, uint, 0);
@@ -94,7 +98,8 @@ MODULE_PARM_DESC(si_period_msec, "How often to send SI packets. Default: 40ms");

static unsigned int pcr_period_msec = 40;
module_param(pcr_period_msec, uint, 0);
MODULE_PARM_DESC(pcr_period_msec, "How often to send PCR packets. Default: 40ms");
MODULE_PARM_DESC(pcr_period_msec,
		 "How often to send PCR packets. Default: 40ms");

static unsigned int mux_rate_kbytes_sec = 4096;
module_param(mux_rate_kbytes_sec, uint, 0);
@@ -106,16 +111,14 @@ MODULE_PARM_DESC(pcr_pid, "PCR PID for all channels: defaults to 0x200");

static unsigned int mux_buf_sz_pkts;
module_param(mux_buf_sz_pkts, uint, 0);
MODULE_PARM_DESC(mux_buf_sz_pkts, "Size for the internal mux buffer in multiples of 188 bytes");

#define MUX_BUF_MIN_SZ 90164
#define MUX_BUF_MAX_SZ (MUX_BUF_MIN_SZ * 10)
MODULE_PARM_DESC(mux_buf_sz_pkts,
		 "Size for the internal mux buffer in multiples of 188 bytes");

static u32 vidtv_bridge_mux_buf_sz_for_mux_rate(void)
{
	u32 max_elapsed_time_msecs =  VIDTV_MAX_SLEEP_USECS / USEC_PER_MSEC;
	u32 nbytes_expected;
	u32 mux_buf_sz = mux_buf_sz_pkts * TS_PACKET_LEN;
	u32 nbytes_expected;

	nbytes_expected = mux_rate_kbytes_sec;
	nbytes_expected *= max_elapsed_time_msecs;
@@ -145,14 +148,12 @@ static bool vidtv_bridge_check_demod_lock(struct vidtv_dvb *dvb, u32 n)
			  FE_HAS_LOCK);
}

static void
vidtv_bridge_on_new_pkts_avail(void *priv, u8 *buf, u32 npkts)
{
/*
	 * called on a separate thread by the mux when new packets become
	 * available
 * called on a separate thread by the mux when new packets become available
 */
	struct vidtv_dvb *dvb = (struct vidtv_dvb *)priv;
static void vidtv_bridge_on_new_pkts_avail(void *priv, u8 *buf, u32 npkts)
{
	struct vidtv_dvb *dvb = priv;

	/* drop packets if we lose the lock */
	if (vidtv_bridge_check_demod_lock(dvb, 0))
@@ -180,8 +181,10 @@ static int vidtv_start_streaming(struct vidtv_dvb *dvb)
		return 0;
	}

	mux_buf_sz = (mux_buf_sz_pkts) ? mux_buf_sz_pkts :
					 vidtv_bridge_mux_buf_sz_for_mux_rate();
	if (mux_buf_sz_pkts)
		mux_buf_sz = mux_buf_sz_pkts;
	else
		mux_buf_sz = vidtv_bridge_mux_buf_sz_for_mux_rate();

	mux_args.mux_buf_sz  = mux_buf_sz;

@@ -212,8 +215,8 @@ static int vidtv_start_feed(struct dvb_demux_feed *feed)
{
	struct dvb_demux *demux = feed->demux;
	struct vidtv_dvb *dvb   = demux->priv;
	int rc;
	int ret;
	int rc;

	if (!demux->dmx.frontend)
		return -EINVAL;
@@ -251,9 +254,9 @@ static int vidtv_stop_feed(struct dvb_demux_feed *feed)

static struct dvb_frontend *vidtv_get_frontend_ptr(struct i2c_client *c)
{
	/* the demod will set this when its probe function runs */
	struct vidtv_demod_state *state = i2c_get_clientdata(c);

	/* the demod will set this when its probe function runs */
	return &state->frontend;
}

@@ -261,6 +264,11 @@ static int vidtv_master_xfer(struct i2c_adapter *i2c_adap,
			     struct i2c_msg msgs[],
			     int num)
{
	/*
	 * Right now, this virtual driver doesn't really send or receive
	 * messages from I2C. A real driver will require an implementation
	 * here.
	 */
	return 0;
}

@@ -328,11 +336,10 @@ static int vidtv_bridge_dmxdev_init(struct vidtv_dvb *dvb)

static int vidtv_bridge_probe_demod(struct vidtv_dvb *dvb, u32 n)
{
	struct vidtv_demod_config cfg = {};

	cfg.drop_tslock_prob_on_low_snr     = drop_tslock_prob_on_low_snr;
	cfg.recover_tslock_prob_on_good_snr = recover_tslock_prob_on_good_snr;

	struct vidtv_demod_config cfg = {
		.drop_tslock_prob_on_low_snr     = drop_tslock_prob_on_low_snr,
		.recover_tslock_prob_on_good_snr = recover_tslock_prob_on_good_snr,
	};
	dvb->i2c_client_demod[n] = dvb_module_probe("dvb_vidtv_demod",
						    NULL,
						    &dvb->i2c_adapter,
@@ -351,14 +358,14 @@ static int vidtv_bridge_probe_demod(struct vidtv_dvb *dvb, u32 n)

static int vidtv_bridge_probe_tuner(struct vidtv_dvb *dvb, u32 n)
{
	struct vidtv_tuner_config cfg = {};
	struct vidtv_tuner_config cfg = {
		.fe                       = dvb->fe[n],
		.mock_power_up_delay_msec = mock_power_up_delay_msec,
		.mock_tune_delay_msec     = mock_tune_delay_msec,
	};
	u32 freq;
	int i;

	cfg.fe                       = dvb->fe[n];
	cfg.mock_power_up_delay_msec = mock_power_up_delay_msec;
	cfg.mock_tune_delay_msec     = mock_tune_delay_msec;

	/* TODO: check if the frequencies are at a valid range */

	memcpy(cfg.vidtv_valid_dvb_t_freqs,
@@ -397,9 +404,7 @@ static int vidtv_bridge_probe_tuner(struct vidtv_dvb *dvb, u32 n)

static int vidtv_bridge_dvb_init(struct vidtv_dvb *dvb)
{
	int ret;
	int i;
	int j;
	int ret, i, j;

	ret = vidtv_bridge_i2c_register_adap(dvb);
	if (ret < 0)
+35 −34
Original line number Diff line number Diff line
@@ -33,8 +33,8 @@

static void vidtv_channel_encoder_destroy(struct vidtv_encoder *e)
{
	struct vidtv_encoder *curr = e;
	struct vidtv_encoder *tmp = NULL;
	struct vidtv_encoder *curr = e;

	while (curr) {
		/* forward the call to the derived type */
@@ -46,25 +46,25 @@ static void vidtv_channel_encoder_destroy(struct vidtv_encoder *e)

#define ENCODING_ISO8859_15 "\x0b"

struct vidtv_channel
*vidtv_channel_s302m_init(struct vidtv_channel *head, u16 transport_stream_id)
{
/*
 * init an audio only channel with a s302m encoder
 */
	const u16 s302m_service_id          = 0x880;
	const u16 s302m_program_num         = 0x880;
	const u16 s302m_program_pid         = 0x101; /* packet id for PMT*/
	const u16 s302m_es_pid              = 0x111; /* packet id for the ES */
struct vidtv_channel
*vidtv_channel_s302m_init(struct vidtv_channel *head, u16 transport_stream_id)
{
	const __be32 s302m_fid              = cpu_to_be32(VIDTV_S302M_FORMAT_IDENTIFIER);
	char *name = ENCODING_ISO8859_15 "Beethoven";
	char *provider = ENCODING_ISO8859_15 "LinuxTV.org";
	char *iso_language_code = ENCODING_ISO8859_15 "eng";
	char *event_name = ENCODING_ISO8859_15 "Beethoven Music";
	char *event_text = ENCODING_ISO8859_15 "Beethoven's Für Elise";
	char *event_name = ENCODING_ISO8859_15 "Beethoven Music";
	struct vidtv_s302m_encoder_init_args encoder_args = {};
	char *iso_language_code = ENCODING_ISO8859_15 "eng";
	char *provider = ENCODING_ISO8859_15 "LinuxTV.org";
	char *name = ENCODING_ISO8859_15 "Beethoven";
	const u16 s302m_es_pid              = 0x111; /* packet id for the ES */
	const u16 s302m_program_pid         = 0x101; /* packet id for PMT*/
	const u16 s302m_service_id          = 0x880;
	const u16 s302m_program_num         = 0x880;
	const u16 s302m_beethoven_event_id  = 1;
	struct vidtv_channel *s302m;
	struct vidtv_s302m_encoder_init_args encoder_args = {};

	s302m = kzalloc(sizeof(*s302m), GFP_KERNEL);
	if (!s302m)
@@ -159,11 +159,9 @@ static struct vidtv_psi_table_eit_event
{
	/* Concatenate the events */
	const struct vidtv_channel *cur_chnl = m->channels;

	struct vidtv_psi_table_eit_event *curr = NULL;
	struct vidtv_psi_table_eit_event *head = NULL;
	struct vidtv_psi_table_eit_event *tail = NULL;

	struct vidtv_psi_desc *desc = NULL;
	u16 event_id;

@@ -175,7 +173,8 @@ static struct vidtv_psi_table_eit_event

		if (!curr)
			dev_warn_ratelimited(m->dev,
					     "No events found for channel %s\n", cur_chnl->name);
					     "No events found for channel %s\n",
					     cur_chnl->name);

		while (curr) {
			event_id = be16_to_cpu(curr->event_id);
@@ -221,7 +220,8 @@ static struct vidtv_psi_table_sdt_service

		if (!curr)
			dev_warn_ratelimited(m->dev,
					     "No services found for channel %s\n", cur_chnl->name);
					     "No services found for channel %s\n",
					     cur_chnl->name);

		while (curr) {
			service_id = be16_to_cpu(curr->service_id);
@@ -300,26 +300,24 @@ vidtv_channel_pat_prog_cat_into_new(struct vidtv_mux *m)
	return head;
}

/*
 * Match channels to their respective PMT sections, then assign the
 * streams
 */
static void
vidtv_channel_pmt_match_sections(struct vidtv_channel *channels,
				 struct vidtv_psi_table_pmt **sections,
				 u32 nsections)
{
	/*
	 * Match channels to their respective PMT sections, then assign the
	 * streams
	 */
	struct vidtv_psi_table_pmt *curr_section = NULL;
	struct vidtv_channel *cur_chnl = channels;

	struct vidtv_psi_table_pmt_stream *s = NULL;
	struct vidtv_psi_table_pmt_stream *head = NULL;
	struct vidtv_psi_table_pmt_stream *tail = NULL;

	struct vidtv_psi_table_pmt_stream *s = NULL;
	struct vidtv_channel *cur_chnl = channels;
	struct vidtv_psi_desc *desc = NULL;
	u32 j;
	u16 curr_id;
	u16 e_pid; /* elementary stream pid */
	u16 curr_id;
	u32 j;

	while (cur_chnl) {
		for (j = 0; j < nsections; ++j) {
@@ -345,7 +343,8 @@ vidtv_channel_pmt_match_sections(struct vidtv_channel *channels,
						head = tail;

					desc = vidtv_psi_desc_clone(s->descriptor);
					vidtv_psi_desc_assign(&tail->descriptor, desc);
					vidtv_psi_desc_assign(&tail->descriptor,
							      desc);

					s = s->next;
				}
@@ -359,7 +358,8 @@ vidtv_channel_pmt_match_sections(struct vidtv_channel *channels,
	}
}

static void vidtv_channel_destroy_service_list(struct vidtv_psi_desc_service_list_entry *e)
static void
vidtv_channel_destroy_service_list(struct vidtv_psi_desc_service_list_entry *e)
{
	struct vidtv_psi_desc_service_list_entry *tmp;

@@ -412,9 +412,9 @@ static struct vidtv_psi_desc_service_list_entry

int vidtv_channel_si_init(struct vidtv_mux *m)
{
	struct vidtv_psi_desc_service_list_entry *service_list = NULL;
	struct vidtv_psi_table_pat_program *programs = NULL;
	struct vidtv_psi_table_sdt_service *services = NULL;
	struct vidtv_psi_desc_service_list_entry *service_list = NULL;
	struct vidtv_psi_table_eit_event *events = NULL;

	m->si.pat = vidtv_psi_pat_table_init(m->transport_stream_id);
@@ -449,11 +449,11 @@ int vidtv_channel_si_init(struct vidtv_mux *m)
	if (!m->si.nit)
		goto free_service_list;

	m->si.eit = vidtv_psi_eit_table_init(m->network_id, m->transport_stream_id);
	m->si.eit = vidtv_psi_eit_table_init(m->network_id,
					     m->transport_stream_id);
	if (!m->si.eit)
		goto free_nit;


	/* assemble all programs and assign to PAT */
	vidtv_psi_pat_program_assign(m->si.pat, programs);

@@ -463,7 +463,8 @@ int vidtv_channel_si_init(struct vidtv_mux *m)
	/* assemble all events and assign to EIT */
	vidtv_psi_eit_event_assign(m->si.eit, events);

	m->si.pmt_secs = vidtv_psi_pmt_create_sec_for_each_pat_entry(m->si.pat, m->pcr_pid);
	m->si.pmt_secs = vidtv_psi_pmt_create_sec_for_each_pat_entry(m->si.pat,
								     m->pcr_pid);
	if (!m->si.pmt_secs)
		goto free_eit;

@@ -496,8 +497,8 @@ int vidtv_channel_si_init(struct vidtv_mux *m)

void vidtv_channel_si_destroy(struct vidtv_mux *m)
{
	u32 i;
	u16 num_programs = m->si.pat->programs;
	u32 i;

	vidtv_psi_pat_table_destroy(m->si.pat);

+0 −1
Original line number Diff line number Diff line
@@ -193,7 +193,6 @@ static void vidtv_demod_update_stats(struct dvb_frontend *fe)

	c->cnr.stat[0].svalue = state->tuner_cnr;
	c->cnr.stat[0].svalue -= prandom_u32_max(state->tuner_cnr / 50);

}

static int vidtv_demod_read_status(struct dvb_frontend *fe,
+1 −1
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ struct vidtv_access_unit {
	struct vidtv_access_unit *next;
};

/* Some musical notes, used by a tone generator */
/* Some musical notes, used by a tone generator. Values are in Hz */
enum musical_notes {
	NOTE_SILENT = 0,

+15 −18
Original line number Diff line number Diff line
@@ -63,9 +63,9 @@ static struct vidtv_mux_pid_ctx

static void vidtv_mux_pid_ctx_destroy(struct vidtv_mux *m)
{
	int bkt;
	struct vidtv_mux_pid_ctx *ctx;
	struct hlist_node *tmp;
	int bkt;

	hash_for_each_safe(m->pid_ctx, bkt, tmp, ctx, h) {
		hash_del(&ctx->h);
@@ -129,21 +129,18 @@ static void vidtv_mux_update_clk(struct vidtv_mux *m)

static u32 vidtv_mux_push_si(struct vidtv_mux *m)
{
	struct vidtv_psi_pat_write_args pat_args = {};
	struct vidtv_psi_pmt_write_args pmt_args = {};
	struct vidtv_psi_sdt_write_args sdt_args = {};
	struct vidtv_psi_nit_write_args nit_args = {};
	struct vidtv_psi_eit_write_args eit_args = {};
	u32 initial_offset = m->mux_buf_offset;

	struct vidtv_mux_pid_ctx *pat_ctx;
	struct vidtv_mux_pid_ctx *pmt_ctx;
	struct vidtv_mux_pid_ctx *sdt_ctx;
	struct vidtv_mux_pid_ctx *nit_ctx;
	struct vidtv_mux_pid_ctx *eit_ctx;

	struct vidtv_psi_pat_write_args pat_args = {};
	struct vidtv_psi_pmt_write_args pmt_args = {};
	struct vidtv_psi_sdt_write_args sdt_args = {};
	struct vidtv_psi_nit_write_args nit_args = {};
	struct vidtv_psi_eit_write_args eit_args = {};

	u32 nbytes; /* the number of bytes written by this function */
	u32 nbytes;
	u16 pmt_pid;
	u32 i;

@@ -269,7 +266,6 @@ static bool vidtv_mux_should_push_si(struct vidtv_mux *m)
static u32 vidtv_mux_packetize_access_units(struct vidtv_mux *m,
					    struct vidtv_encoder *e)
{
	u32 nbytes = 0;
	struct pes_write_args args = {
		.dest_buf           = m->mux_buf,
		.dest_buf_sz        = m->mux_buf_sz,
@@ -279,10 +275,11 @@ static u32 vidtv_mux_packetize_access_units(struct vidtv_mux *m,
		.send_pts           = true,  /* forbidden value '01'... */
		.send_dts           = false, /* ...for PTS_DTS flags    */
	};
	u32 initial_offset = m->mux_buf_offset;
	struct vidtv_access_unit *au = e->access_units;
	u8 *buf = NULL;
	u32 initial_offset = m->mux_buf_offset;
	struct vidtv_mux_pid_ctx *pid_ctx;
	u32 nbytes = 0;
	u8 *buf = NULL;

	/* see SMPTE 302M clause 6.4 */
	if (args.encoder_id == S302M) {
@@ -318,10 +315,10 @@ static u32 vidtv_mux_packetize_access_units(struct vidtv_mux *m,

static u32 vidtv_mux_poll_encoders(struct vidtv_mux *m)
{
	u32 nbytes = 0;
	u32 au_nbytes;
	struct vidtv_channel *cur_chnl = m->channels;
	struct vidtv_encoder *e = NULL;
	u32 nbytes = 0;
	u32 au_nbytes;

	while (cur_chnl) {
		e = cur_chnl->encoders;
@@ -347,9 +344,9 @@ static u32 vidtv_mux_pad_with_nulls(struct vidtv_mux *m, u32 npkts)
{
	struct null_packet_write_args args = {};
	u32 initial_offset = m->mux_buf_offset;
	u32 nbytes; /* the number of bytes written by this function */
	u32 i;
	struct vidtv_mux_pid_ctx *ctx;
	u32 nbytes;
	u32 i;

	ctx = vidtv_mux_get_pid_ctx(m, TS_NULL_PACKET_PID);

@@ -388,9 +385,9 @@ static void vidtv_mux_tick(struct work_struct *work)
					   struct vidtv_mux,
					   mpeg_thread);
	struct dtv_frontend_properties *c = &m->fe->dtv_property_cache;
	u32 tot_bits = 0;
	u32 nbytes;
	u32 npkts;
	u32 tot_bits = 0;

	while (m->streaming) {
		nbytes = 0;
Loading