Skip to content

Commit c2f78f0

Browse files
dwlsalmeidamchehab
authored andcommitted
media: vidtv: psi: add a Network Information Table (NIT)
Add a Network Information Table (NIT) as specified in ETSI EN 300 468. This table conveys information relating to the physical organization of the multiplexes carried via a given network and the characteristics of the network itself. It is conveyed in the output of vidtv as packets with TS PID of 0x0010 [mchehab+huawei@kernel.org: removed an extra blank line] Signed-off-by: Daniel W. S. Almeida <dwlsalmeida@gmail.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1 parent dd6dbe8 commit c2f78f0

7 files changed

Lines changed: 545 additions & 12 deletions

File tree

‎Documentation/driver-api/media/drivers/vidtv.rst‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,11 @@ vidtv_psi.[ch]
149149
Because the generator is implemented in a separate file, it can be
150150
reused elsewhere in the media subsystem.
151151

152-
Currently vidtv supports working with 3 PSI tables: PAT, PMT and
153-
SDT.
152+
Currently vidtv supports working with 4 PSI tables: PAT, PMT,
153+
SDT and NIT.
154154

155155
The specification for PAT and PMT can be found in *ISO 13818-1:
156-
Systems*, while the specification for the SDT can be found in *ETSI
156+
Systems*, while the specification for the SDT, NIT can be found in *ETSI
157157
EN 300 468: Specification for Service Information (SI) in DVB
158158
systems*.
159159

‎drivers/media/test-drivers/vidtv/vidtv_bridge.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
//#define MUX_BUF_MIN_SZ
2929
#define TUNER_DEFAULT_ADDR 0x68
3030
#define DEMOD_DEFAULT_ADDR 0x60
31+
#define VIDTV_DEFAULT_NETWORK_ID 0x744
32+
#define VIDTV_DEFAULT_NETWORK_NAME "LinuxTV.org"
3133

3234
/* LNBf fake parameters: ranges used by an Universal (extended) European LNBf */
3335
#define LNB_CUT_FREQUENCY 11700000
@@ -177,6 +179,8 @@ static int vidtv_start_streaming(struct vidtv_dvb *dvb)
177179
mux_args.si_period_usecs = si_period_msec * 1000;
178180
mux_args.pcr_pid = pcr_pid;
179181
mux_args.transport_stream_id = VIDTV_DEFAULT_TS_ID;
182+
mux_args.network_id = VIDTV_DEFAULT_NETWORK_ID,
183+
mux_args.network_name = VIDTV_DEFAULT_NETWORK_NAME,
180184
mux_args.priv = dvb;
181185

182186
dvb->streaming = true;

‎drivers/media/test-drivers/vidtv/vidtv_channel.c‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,57 @@ vidtv_channel_pmt_match_sections(struct vidtv_channel *channels,
246246
}
247247
}
248248

249+
static struct vidtv_psi_desc_service_list_entry
250+
*vidtv_channel_build_service_list(struct vidtv_psi_table_sdt_service *s)
251+
{
252+
struct vidtv_psi_desc_service_list_entry *curr_e = NULL;
253+
struct vidtv_psi_desc_service_list_entry *head_e = NULL;
254+
struct vidtv_psi_desc_service_list_entry *prev_e = NULL;
255+
struct vidtv_psi_desc *desc = s->descriptor;
256+
struct vidtv_psi_desc_service *s_desc;
257+
258+
while (s) {
259+
while (desc) {
260+
if (s->descriptor->type != SERVICE_DESCRIPTOR)
261+
goto next_desc;
262+
263+
s_desc = (struct vidtv_psi_desc_service *)desc;
264+
265+
curr_e = kzalloc(sizeof(*curr_e), GFP_KERNEL);
266+
curr_e->service_id = s->service_id;
267+
curr_e->service_type = s_desc->service_type;
268+
269+
if (!head_e)
270+
head_e = curr_e;
271+
if (prev_e)
272+
prev_e->next = curr_e;
273+
274+
prev_e = curr_e;
275+
276+
next_desc:
277+
desc = desc->next;
278+
}
279+
s = s->next;
280+
}
281+
return head_e;
282+
}
283+
284+
static void vidtv_channel_destroy_service_list(struct vidtv_psi_desc_service_list_entry *e)
285+
{
286+
struct vidtv_psi_desc_service_list_entry *tmp;
287+
288+
while (e) {
289+
tmp = e;
290+
e = e->next;
291+
kfree(tmp);
292+
}
293+
}
294+
249295
void vidtv_channel_si_init(struct vidtv_mux *m)
250296
{
251297
struct vidtv_psi_table_pat_program *programs = NULL;
252298
struct vidtv_psi_table_sdt_service *services = NULL;
299+
struct vidtv_psi_desc_service_list_entry *service_list = NULL;
253300

254301
m->si.pat = vidtv_psi_pat_table_init(m->transport_stream_id);
255302

@@ -258,6 +305,15 @@ void vidtv_channel_si_init(struct vidtv_mux *m)
258305
programs = vidtv_channel_pat_prog_cat_into_new(m);
259306
services = vidtv_channel_sdt_serv_cat_into_new(m);
260307

308+
/* look for a service descriptor for every service */
309+
service_list = vidtv_channel_build_service_list(services);
310+
311+
/* use these descriptors to build the NIT */
312+
m->si.nit = vidtv_psi_nit_table_init(m->network_id,
313+
m->transport_stream_id,
314+
m->network_name,
315+
service_list);
316+
261317
/* assemble all programs and assign to PAT */
262318
vidtv_psi_pat_program_assign(m->si.pat, programs);
263319

@@ -269,6 +325,8 @@ void vidtv_channel_si_init(struct vidtv_mux *m)
269325
vidtv_channel_pmt_match_sections(m->channels,
270326
m->si.pmt_secs,
271327
m->si.pat->programs);
328+
329+
vidtv_channel_destroy_service_list(service_list);
272330
}
273331

274332
void vidtv_channel_si_destroy(struct vidtv_mux *m)
@@ -283,6 +341,7 @@ void vidtv_channel_si_destroy(struct vidtv_mux *m)
283341

284342
kfree(m->si.pmt_secs);
285343
vidtv_psi_sdt_table_destroy(m->si.sdt);
344+
vidtv_psi_nit_table_destroy(m->si.nit);
286345
}
287346

288347
void vidtv_channels_init(struct vidtv_mux *m)

‎drivers/media/test-drivers/vidtv/vidtv_mux.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ static void vidtv_mux_pid_ctx_init(struct vidtv_mux *m)
7474
vidtv_mux_create_pid_ctx_once(m, VIDTV_PAT_PID);
7575
/* push the SDT pid ctx */
7676
vidtv_mux_create_pid_ctx_once(m, VIDTV_SDT_PID);
77+
/* push the NIT pid ctx */
78+
vidtv_mux_create_pid_ctx_once(m, VIDTV_NIT_PID);
7779

7880
/* add a ctx for all PMT sections */
7981
while (p) {
@@ -117,17 +119,20 @@ static u32 vidtv_mux_push_si(struct vidtv_mux *m)
117119
struct vidtv_mux_pid_ctx *pat_ctx;
118120
struct vidtv_mux_pid_ctx *pmt_ctx;
119121
struct vidtv_mux_pid_ctx *sdt_ctx;
122+
struct vidtv_mux_pid_ctx *nit_ctx;
120123

121124
struct vidtv_psi_pat_write_args pat_args = {};
122125
struct vidtv_psi_pmt_write_args pmt_args = {};
123126
struct vidtv_psi_sdt_write_args sdt_args = {};
127+
struct vidtv_psi_nit_write_args nit_args = {};
124128

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

129133
pat_ctx = vidtv_mux_get_pid_ctx(m, VIDTV_PAT_PID);
130134
sdt_ctx = vidtv_mux_get_pid_ctx(m, VIDTV_SDT_PID);
135+
nit_ctx = vidtv_mux_get_pid_ctx(m, VIDTV_NIT_PID);
131136

132137
pat_args.buf = m->mux_buf;
133138
pat_args.offset = m->mux_buf_offset;
@@ -169,6 +174,14 @@ static u32 vidtv_mux_push_si(struct vidtv_mux *m)
169174

170175
m->mux_buf_offset += vidtv_psi_sdt_write_into(sdt_args);
171176

177+
nit_args.buf = m->mux_buf;
178+
nit_args.offset = m->mux_buf_offset;
179+
nit_args.nit = m->si.nit;
180+
nit_args.buf_sz = m->mux_buf_sz;
181+
nit_args.continuity_counter = &nit_ctx->cc;
182+
183+
m->mux_buf_offset += vidtv_psi_nit_write_into(nit_args);
184+
172185
nbytes = m->mux_buf_offset - initial_offset;
173186

174187
m->num_streamed_si++;
@@ -446,6 +459,8 @@ struct vidtv_mux *vidtv_mux_init(struct dvb_frontend *fe,
446459
m->pcr_pid = args.pcr_pid;
447460
m->transport_stream_id = args.transport_stream_id;
448461
m->priv = args.priv;
462+
m->network_id = args.network_id;
463+
m->network_name = kstrdup(args.network_name, GFP_KERNEL);
449464
m->timing.current_jiffies = get_jiffies_64();
450465

451466
if (args.channels)
@@ -469,6 +484,7 @@ void vidtv_mux_destroy(struct vidtv_mux *m)
469484
vidtv_mux_pid_ctx_destroy(m);
470485
vidtv_channel_si_destroy(m);
471486
vidtv_channels_destroy(m);
487+
kfree(m->network_name);
472488
vfree(m->mux_buf);
473489
kfree(m);
474490
}

‎drivers/media/test-drivers/vidtv/vidtv_mux.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct vidtv_mux_si {
6464
struct vidtv_psi_table_pat *pat;
6565
struct vidtv_psi_table_pmt **pmt_secs; /* the PMT sections */
6666
struct vidtv_psi_table_sdt *sdt;
67+
struct vidtv_psi_table_nit *nit;
6768
};
6869

6970
/**
@@ -99,6 +100,8 @@ struct vidtv_mux_pid_ctx {
99100
* @pcr_pid: The TS PID used for the PSI packets. All channels will share the
100101
* same PCR.
101102
* @transport_stream_id: The transport stream ID
103+
* @network_id: The network ID
104+
* @network_name: The network name
102105
* @priv: Private data.
103106
*/
104107
struct vidtv_mux {
@@ -128,6 +131,8 @@ struct vidtv_mux {
128131

129132
u16 pcr_pid;
130133
u16 transport_stream_id;
134+
u16 network_id;
135+
char *network_name;
131136
void *priv;
132137
};
133138

@@ -142,6 +147,8 @@ struct vidtv_mux {
142147
* same PCR.
143148
* @transport_stream_id: The transport stream ID
144149
* @channels: an optional list of channels to use
150+
* @network_id: The network ID
151+
* @network_name: The network name
145152
* @priv: Private data.
146153
*/
147154
struct vidtv_mux_init_args {
@@ -153,6 +160,8 @@ struct vidtv_mux_init_args {
153160
u16 pcr_pid;
154161
u16 transport_stream_id;
155162
struct vidtv_channel *channels;
163+
u16 network_id;
164+
char *network_name;
156165
void *priv;
157166
};
158167

0 commit comments

Comments
 (0)