Commit 7a7899f6 authored by Daniel W. S. Almeida's avatar Daniel W. S. Almeida Committed by Mauro Carvalho Chehab

media: vidtv: psi: Implement an Event Information Table (EIT)

Implement an Event Information Table (EIT) as per EN 300 468
5.2.4.

The EIT provides information in chronological order regarding
the events contained within each service.

For now only present event information is supported.

[mchehab+huawei@kernel.org: removed an extra blank line]
Signed-off-by: default avatarDaniel W. S. Almeida <dwlsalmeida@gmail.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent c2f78f0c
......@@ -149,11 +149,11 @@ vidtv_psi.[ch]
Because the generator is implemented in a separate file, it can be
reused elsewhere in the media subsystem.
Currently vidtv supports working with 4 PSI tables: PAT, PMT,
SDT and NIT.
Currently vidtv supports working with 5 PSI tables: PAT, PMT,
SDT, NIT and EIT.
The specification for PAT and PMT can be found in *ISO 13818-1:
Systems*, while the specification for the SDT, NIT can be found in *ETSI
Systems*, while the specification for the SDT, NIT, EIT can be found in *ETSI
EN 300 468: Specification for Service Information (SI) in DVB
systems*.
......@@ -197,6 +197,8 @@ vidtv_channel.[ch]
#. Their programs will be concatenated to populate the PAT
#. Their events will be concatenated to populate the EIT
#. For each program in the PAT, a PMT section will be created
#. The PMT section for a channel will be assigned its streams.
......
......@@ -9,6 +9,7 @@
* 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
* Their events will be concatenated to populate the EIT
* 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
......@@ -59,13 +60,17 @@ struct vidtv_channel
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 5th Symphony";
const u16 s302m_beethoven_event_id = 1;
struct vidtv_channel *s302m = kzalloc(sizeof(*s302m), GFP_KERNEL);
struct vidtv_s302m_encoder_init_args encoder_args = {};
s302m->name = kstrdup(name, GFP_KERNEL);
s302m->service = vidtv_psi_sdt_service_init(NULL, s302m_service_id);
s302m->service = vidtv_psi_sdt_service_init(NULL, s302m_service_id, false, true);
s302m->service->descriptor = (struct vidtv_psi_desc *)
vidtv_psi_service_desc_init(NULL,
......@@ -94,6 +99,13 @@ struct vidtv_channel
s302m->encoders = vidtv_s302m_encoder_init(encoder_args);
s302m->events = vidtv_psi_eit_event_init(NULL, s302m_beethoven_event_id);
s302m->events->descriptor = (struct vidtv_psi_desc *)
vidtv_psi_short_event_desc_init(NULL,
iso_language_code,
event_name,
event_text);
if (head) {
while (head->next)
head = head->next;
......@@ -104,6 +116,48 @@ struct vidtv_channel
return s302m;
}
static struct vidtv_psi_table_eit_event
*vidtv_channel_eit_event_cat_into_new(struct vidtv_mux *m)
{
/* 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;
if (!cur_chnl)
return NULL;
while (cur_chnl) {
curr = cur_chnl->events;
if (!curr)
dev_warn_ratelimited(m->dev,
"No events found for channel %s\n", cur_chnl->name);
while (curr) {
event_id = be16_to_cpu(curr->event_id);
tail = vidtv_psi_eit_event_init(tail, event_id);
desc = vidtv_psi_desc_clone(curr->descriptor);
vidtv_psi_desc_assign(&tail->descriptor, desc);
if (!head)
head = tail;
curr = curr->next;
}
cur_chnl = cur_chnl->next;
}
return head;
}
static struct vidtv_psi_table_sdt_service
*vidtv_channel_sdt_serv_cat_into_new(struct vidtv_mux *m)
{
......@@ -129,7 +183,10 @@ static struct vidtv_psi_table_sdt_service
while (curr) {
service_id = be16_to_cpu(curr->service_id);
tail = vidtv_psi_sdt_service_init(tail, service_id);
tail = vidtv_psi_sdt_service_init(tail,
service_id,
curr->EIT_schedule,
curr->EIT_present_following);
desc = vidtv_psi_desc_clone(curr->descriptor);
vidtv_psi_desc_assign(&tail->descriptor, desc);
......@@ -297,6 +354,7 @@ void vidtv_channel_si_init(struct vidtv_mux *m)
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);
......@@ -305,6 +363,8 @@ void vidtv_channel_si_init(struct vidtv_mux *m)
programs = vidtv_channel_pat_prog_cat_into_new(m);
services = vidtv_channel_sdt_serv_cat_into_new(m);
events = vidtv_channel_eit_event_cat_into_new(m);
/* look for a service descriptor for every service */
service_list = vidtv_channel_build_service_list(services);
......@@ -314,12 +374,17 @@ void vidtv_channel_si_init(struct vidtv_mux *m)
m->network_name,
service_list);
m->si.eit = vidtv_psi_eit_table_init(m->network_id, m->transport_stream_id);
/* assemble all programs and assign to PAT */
vidtv_psi_pat_program_assign(m->si.pat, programs);
/* assemble all services and assign to SDT */
vidtv_psi_sdt_service_assign(m->si.sdt, services);
/* 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);
vidtv_channel_pmt_match_sections(m->channels,
......@@ -342,6 +407,7 @@ void vidtv_channel_si_destroy(struct vidtv_mux *m)
kfree(m->si.pmt_secs);
vidtv_psi_sdt_table_destroy(m->si.sdt);
vidtv_psi_nit_table_destroy(m->si.nit);
vidtv_psi_eit_table_destroy(m->si.eit);
}
void vidtv_channels_init(struct vidtv_mux *m)
......@@ -361,6 +427,7 @@ void vidtv_channels_destroy(struct vidtv_mux *m)
vidtv_psi_pat_program_destroy(curr->program);
vidtv_psi_pmt_stream_destroy(curr->streams);
vidtv_channel_encoder_destroy(curr->encoders);
vidtv_psi_eit_event_destroy(curr->events);
tmp = curr;
curr = curr->next;
......
......@@ -9,6 +9,7 @@
* 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
* Their events will be concatenated to populate the EIT
* 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
......@@ -44,6 +45,7 @@
* Will be concatenated into the PAT.
* @streams: A stream loop used to populate the PMT section for 'program'
* @encoders: A encoder loop. There must be one encoder for each stream.
* @events: Optional event information. This will feed into the EIT.
* @next: Optionally chain this channel.
*/
struct vidtv_channel {
......@@ -54,6 +56,7 @@ struct vidtv_channel {
struct vidtv_psi_table_pat_program *program;
struct vidtv_psi_table_pmt_stream *streams;
struct vidtv_encoder *encoders;
struct vidtv_psi_table_eit_event *events;
struct vidtv_channel *next;
};
......
......@@ -76,6 +76,8 @@ static void vidtv_mux_pid_ctx_init(struct vidtv_mux *m)
vidtv_mux_create_pid_ctx_once(m, VIDTV_SDT_PID);
/* push the NIT pid ctx */
vidtv_mux_create_pid_ctx_once(m, VIDTV_NIT_PID);
/* push the EIT pid ctx */
vidtv_mux_create_pid_ctx_once(m, VIDTV_EIT_PID);
/* add a ctx for all PMT sections */
while (p) {
......@@ -120,11 +122,13 @@ static u32 vidtv_mux_push_si(struct vidtv_mux *m)
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 */
u16 pmt_pid;
......@@ -133,6 +137,7 @@ static u32 vidtv_mux_push_si(struct vidtv_mux *m)
pat_ctx = vidtv_mux_get_pid_ctx(m, VIDTV_PAT_PID);
sdt_ctx = vidtv_mux_get_pid_ctx(m, VIDTV_SDT_PID);
nit_ctx = vidtv_mux_get_pid_ctx(m, VIDTV_NIT_PID);
eit_ctx = vidtv_mux_get_pid_ctx(m, VIDTV_EIT_PID);
pat_args.buf = m->mux_buf;
pat_args.offset = m->mux_buf_offset;
......@@ -182,6 +187,14 @@ static u32 vidtv_mux_push_si(struct vidtv_mux *m)
m->mux_buf_offset += vidtv_psi_nit_write_into(nit_args);
eit_args.buf = m->mux_buf;
eit_args.offset = m->mux_buf_offset;
eit_args.eit = m->si.eit;
eit_args.buf_sz = m->mux_buf_sz;
eit_args.continuity_counter = &eit_ctx->cc;
m->mux_buf_offset += vidtv_psi_eit_write_into(eit_args);
nbytes = m->mux_buf_offset - initial_offset;
m->num_streamed_si++;
......
......@@ -58,6 +58,7 @@ struct vidtv_mux_timing {
* @pat: The PAT in use by the muxer.
* @pmt_secs: The PMT sections in use by the muxer. One for each program in the PAT.
* @sdt: The SDT in use by the muxer.
* @eit: the EIT in use by the muxer.
*/
struct vidtv_mux_si {
/* the SI tables */
......@@ -65,6 +66,7 @@ struct vidtv_mux_si {
struct vidtv_psi_table_pmt **pmt_secs; /* the PMT sections */
struct vidtv_psi_table_sdt *sdt;
struct vidtv_psi_table_nit *nit;
struct vidtv_psi_table_eit *eit;
};
/**
......
......@@ -24,16 +24,20 @@
#define PMT_LEN_UNTIL_PROGRAM_INFO_LENGTH 9
#define SDT_LEN_UNTIL_RESERVED_FOR_FUTURE_USE 8
#define NIT_LEN_UNTIL_NETWORK_DESCRIPTOR_LEN 7
#define EIT_LEN_UNTIL_LAST_TABLE_ID 11
#define MAX_SECTION_LEN 1021
#define EIT_MAX_SECTION_LEN 4093 /* see ETSI 300 468 v.1.10.1 p. 26 */
#define VIDTV_PAT_PID 0 /* mandated by the specs */
#define VIDTV_SDT_PID 0x0011 /* mandated by the specs */
#define VIDTV_NIT_PID 0x0010 /* mandated by the specs */
#define VIDTV_EIT_PID 0x0012 /*mandated by the specs */
enum vidtv_psi_descriptors {
REGISTRATION_DESCRIPTOR = 0x05, /* See ISO/IEC 13818-1 section 2.6.8 */
NETWORK_NAME_DESCRIPTOR = 0x40, /* See ETSI EN 300 468 section 6.2.27 */
SERVICE_LIST_DESCRIPTOR = 0x41, /* See ETSI EN 300 468 section 6.2.35 */
SERVICE_DESCRIPTOR = 0x48, /* See ETSI EN 300 468 section 6.2.33 */
SHORT_EVENT_DESCRIPTOR = 0x4d, /* See ETSI EN 300 468 section 6.2.37 */
};
enum vidtv_psi_stream_types {
......@@ -118,6 +122,27 @@ struct vidtv_psi_desc_service_list {
struct vidtv_psi_desc_service_list_entry *service_list;
} __packed;
/**
* struct vidtv_psi_desc_short_event - A short event descriptor
* see ETSI EN 300 468 v1.15.1 section 6.2.37
*/
struct vidtv_psi_desc_short_event {
struct vidtv_psi_desc *next;
u8 type;
u8 length;
char *iso_language_code;
u8 event_name_len;
char *event_name;
u8 text_len;
char *text;
} __packed;
struct vidtv_psi_desc_short_event
*vidtv_psi_short_event_desc_init(struct vidtv_psi_desc *head,
char *iso_language_code,
char *event_name,
char *text);
/**
* struct vidtv_psi_table_header - A header that is present for all PSI tables.
*/
......@@ -344,7 +369,9 @@ struct vidtv_psi_table_sdt *vidtv_psi_sdt_table_init(u16 transport_stream_id);
struct vidtv_psi_table_sdt_service*
vidtv_psi_sdt_service_init(struct vidtv_psi_table_sdt_service *head,
u16 service_id);
u16 service_id,
bool eit_schedule,
bool eit_present_following);
void
vidtv_psi_desc_destroy(struct vidtv_psi_desc *desc);
......@@ -684,4 +711,95 @@ u32 vidtv_psi_nit_write_into(struct vidtv_psi_nit_write_args args);
void vidtv_psi_nit_table_destroy(struct vidtv_psi_table_nit *nit);
/**
* struct vidtv_psi_desc_short_event - A short event descriptor
* see ETSI EN 300 468 v1.15.1 section 6.2.37
*/
struct vidtv_psi_table_eit_event {
__be16 event_id;
u8 start_time[5];
u8 duration[3];
__be16 bitfield; /* desc_length: 12, free_CA_mode: 1, running_status: 1 */
struct vidtv_psi_desc *descriptor;
struct vidtv_psi_table_eit_event *next;
} __packed;
/*
* struct vidtv_psi_table_eit - A Event Information Table (EIT)
* See ETSI 300 468 section 5.2.4
*/
struct vidtv_psi_table_eit {
struct vidtv_psi_table_header header;
__be16 transport_id;
__be16 network_id;
u8 last_segment;
u8 last_table_id;
struct vidtv_psi_table_eit_event *event;
} __packed;
struct vidtv_psi_table_eit
*vidtv_psi_eit_table_init(u16 network_id,
u16 transport_stream_id);
/**
* struct vidtv_psi_eit_write_args - Arguments for writing an EIT section
* @buf: The destination buffer.
* @offset: The offset into the destination buffer.
* @nit: A pointer to the NIT
* @buf_sz: The size of the destination buffer.
* @continuity_counter: A pointer to the CC. Incremented on every new packet.
*
*/
struct vidtv_psi_eit_write_args {
char *buf;
u32 offset;
struct vidtv_psi_table_eit *eit;
u32 buf_sz;
u8 *continuity_counter;
};
/**
* vidtv_psi_eit_write_into - Write EIT as MPEG-TS packets into a buffer.
* @args: an instance of struct vidtv_psi_nit_write_args
*
* This function writes the MPEG TS packets for a EIT table into a buffer.
* Calling code will usually generate the EIT via a call to its init function
* and thus is responsible for freeing it.
*
* Return: The number of bytes written into the buffer. This is NOT
* equal to the size of the EIT, since more space is needed for TS headers during TS
* encapsulation.
*/
u32 vidtv_psi_eit_write_into(struct vidtv_psi_eit_write_args args);
void vidtv_psi_eit_table_destroy(struct vidtv_psi_table_eit *eit);
/**
* vidtv_psi_eit_table_update_sec_len - Recompute and update the EIT section length.
* @eit: The EIT whose length is to be updated.
*
* This will traverse the table and accumulate the length of its components,
* which is then used to replace the 'section_length' field.
*
* If section_length > EIT_MAX_SECTION_LEN, the operation fails.
*/
void vidtv_psi_eit_table_update_sec_len(struct vidtv_psi_table_eit *eit);
/**
* vidtv_psi_eit_event_assign - Assigns the event loop to the EIT.
* @eit: The EIT to assign to.
* @e: The event loop
*
* This will free the previous event loop in the table.
* This will assign ownership of the stream loop to the table, i.e. the table
* will free this stream loop when a call to its destroy function is made.
*/
void vidtv_psi_eit_event_assign(struct vidtv_psi_table_eit *eit,
struct vidtv_psi_table_eit_event *e);
struct vidtv_psi_table_eit_event
*vidtv_psi_eit_event_init(struct vidtv_psi_table_eit_event *head, u16 event_id);
void vidtv_psi_eit_event_destroy(struct vidtv_psi_table_eit_event *e);
#endif // VIDTV_PSI_H
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment