1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Vidtv serves as a reference DVB driver and helps validate the existing APIs
4  * in the media subsystem. It can also aid developers working on userspace
5  * applications.
6  *
7  * This file contains the code for a 'channel' abstraction.
8  *
9  * When vidtv boots, it will create some hardcoded channels.
10  * Their services will be concatenated to populate the SDT.
11  * Their programs will be concatenated to populate the PAT
12  * For each program in the PAT, a PMT section will be created
13  * The PMT section for a channel will be assigned its streams.
14  * Every stream will have its corresponding encoder polled to produce TS packets
15  * These packets may be interleaved by the mux and then delivered to the bridge
16  *
17  *
18  * Copyright (C) 2020 Daniel W. S. Almeida
19  */
20 
21 #ifndef VIDTV_CHANNEL_H
22 #define VIDTV_CHANNEL_H
23 
24 #include <linux/types.h>
25 #include "vidtv_psi.h"
26 #include "vidtv_encoder.h"
27 #include "vidtv_mux.h"
28 
29 /**
30  * struct vidtv_channel - A 'channel' abstraction
31  *
32  * When vidtv boots, it will create some hardcoded channels.
33  * Their services will be concatenated to populate the SDT.
34  * Their programs will be concatenated to populate the PAT
35  * For each program in the PAT, a PMT section will be created
36  * The PMT section for a channel will be assigned its streams.
37  * Every stream will have its corresponding encoder polled to produce TS packets
38  * These packets may be interleaved by the mux and then delivered to the bridge
39  *
40  * @transport_stream_id: a number to identify the TS, chosen at will.
41  * @service: A _single_ service. Will be concatenated into the SDT.
42  * @program_num: The link between PAT, PMT and SDT.
43  * @program: A _single_ program with one or more streams associated with it.
44  * Will be concatenated into the PAT.
45  * @streams: A stream loop used to populate the PMT section for 'program'
46  * @encoders: A encoder loop. There must be one encoder for each stream.
47  * @next: Optionally chain this channel.
48  */
49 struct vidtv_channel {
50 	char *name;
51 	u16 transport_stream_id;
52 	struct vidtv_psi_table_sdt_service *service;
53 	u16 program_num;
54 	struct vidtv_psi_table_pat_program *program;
55 	struct vidtv_psi_table_pmt_stream *streams;
56 	struct vidtv_encoder *encoders;
57 	struct vidtv_channel *next;
58 };
59 
60 /**
61  * vidtv_channel_si_init - Init the PSI tables from the channels in the mux
62  * @m: The mux containing the channels.
63  */
64 void vidtv_channel_si_init(struct vidtv_mux *m);
65 void vidtv_channel_si_destroy(struct vidtv_mux *m);
66 
67 /**
68  * vidtv_channels_init - Init hardcoded, fake 'channels'.
69  * @m: The mux to store the channels into.
70  */
71 void vidtv_channels_init(struct vidtv_mux *m);
72 struct vidtv_channel
73 *vidtv_channel_s302m_init(struct vidtv_channel *head, u16 transport_stream_id);
74 void vidtv_channels_destroy(struct vidtv_mux *m);
75 
76 #endif //VIDTV_CHANNEL_H
77