18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * This file contains the logic to work with MPEG Program-Specific Information.
48c2ecf20Sopenharmony_ci * These are defined both in ISO/IEC 13818-1 (systems) and ETSI EN 300 468.
58c2ecf20Sopenharmony_ci * PSI is carried in the form of table structures, and although each table might
68c2ecf20Sopenharmony_ci * technically be broken into one or more sections, we do not do this here,
78c2ecf20Sopenharmony_ci * hence 'table' and 'section' are interchangeable for vidtv.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * Copyright (C) 2020 Daniel W. S. Almeida
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#ifndef VIDTV_PSI_H
138c2ecf20Sopenharmony_ci#define VIDTV_PSI_H
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <linux/types.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci/*
188c2ecf20Sopenharmony_ci * all section lengths start immediately after the 'section_length' field
198c2ecf20Sopenharmony_ci * see ISO/IEC 13818-1 : 2000 and ETSI EN 300 468 V 1.10.1 for
208c2ecf20Sopenharmony_ci * reference
218c2ecf20Sopenharmony_ci */
228c2ecf20Sopenharmony_ci#define PAT_LEN_UNTIL_LAST_SECTION_NUMBER 5
238c2ecf20Sopenharmony_ci#define PMT_LEN_UNTIL_PROGRAM_INFO_LENGTH 9
248c2ecf20Sopenharmony_ci#define SDT_LEN_UNTIL_RESERVED_FOR_FUTURE_USE 8
258c2ecf20Sopenharmony_ci#define NIT_LEN_UNTIL_NETWORK_DESCRIPTOR_LEN 7
268c2ecf20Sopenharmony_ci#define EIT_LEN_UNTIL_LAST_TABLE_ID 11
278c2ecf20Sopenharmony_ci#define MAX_SECTION_LEN 1021
288c2ecf20Sopenharmony_ci#define EIT_MAX_SECTION_LEN 4093 /* see ETSI 300 468 v.1.10.1 p. 26 */
298c2ecf20Sopenharmony_ci#define VIDTV_PAT_PID 0 /* mandated by the specs */
308c2ecf20Sopenharmony_ci#define VIDTV_SDT_PID 0x0011 /* mandated by the specs */
318c2ecf20Sopenharmony_ci#define VIDTV_NIT_PID 0x0010 /* mandated by the specs */
328c2ecf20Sopenharmony_ci#define VIDTV_EIT_PID 0x0012 /*mandated by the specs */
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_cienum vidtv_psi_descriptors {
358c2ecf20Sopenharmony_ci	REGISTRATION_DESCRIPTOR	= 0x05, /* See ISO/IEC 13818-1 section 2.6.8 */
368c2ecf20Sopenharmony_ci	NETWORK_NAME_DESCRIPTOR = 0x40, /* See ETSI EN 300 468 section 6.2.27 */
378c2ecf20Sopenharmony_ci	SERVICE_LIST_DESCRIPTOR = 0x41, /* See ETSI EN 300 468 section 6.2.35 */
388c2ecf20Sopenharmony_ci	SERVICE_DESCRIPTOR = 0x48, /* See ETSI EN 300 468 section 6.2.33 */
398c2ecf20Sopenharmony_ci	SHORT_EVENT_DESCRIPTOR = 0x4d, /* See ETSI EN 300 468 section 6.2.37 */
408c2ecf20Sopenharmony_ci};
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cienum vidtv_psi_stream_types {
438c2ecf20Sopenharmony_ci	STREAM_PRIVATE_DATA = 0x06, /* see ISO/IEC 13818-1 2000 p. 48 */
448c2ecf20Sopenharmony_ci};
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci/*
478c2ecf20Sopenharmony_ci * struct vidtv_psi_desc - A generic PSI descriptor type.
488c2ecf20Sopenharmony_ci * The descriptor length is an 8-bit field specifying the total number of bytes of the data portion
498c2ecf20Sopenharmony_ci * of the descriptor following the byte defining the value of this field.
508c2ecf20Sopenharmony_ci */
518c2ecf20Sopenharmony_cistruct vidtv_psi_desc {
528c2ecf20Sopenharmony_ci	struct vidtv_psi_desc *next;
538c2ecf20Sopenharmony_ci	u8 type;
548c2ecf20Sopenharmony_ci	u8 length;
558c2ecf20Sopenharmony_ci	u8 data[];
568c2ecf20Sopenharmony_ci} __packed;
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci/*
598c2ecf20Sopenharmony_ci * struct vidtv_psi_desc_service - Service descriptor.
608c2ecf20Sopenharmony_ci * See ETSI EN 300 468 section 6.2.33.
618c2ecf20Sopenharmony_ci */
628c2ecf20Sopenharmony_cistruct vidtv_psi_desc_service {
638c2ecf20Sopenharmony_ci	struct vidtv_psi_desc *next;
648c2ecf20Sopenharmony_ci	u8 type;
658c2ecf20Sopenharmony_ci	u8 length;
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci	u8 service_type;
688c2ecf20Sopenharmony_ci	u8 provider_name_len;
698c2ecf20Sopenharmony_ci	char *provider_name;
708c2ecf20Sopenharmony_ci	u8 service_name_len;
718c2ecf20Sopenharmony_ci	char *service_name;
728c2ecf20Sopenharmony_ci} __packed;
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci/*
758c2ecf20Sopenharmony_ci * struct vidtv_psi_desc_registration - A registration descriptor.
768c2ecf20Sopenharmony_ci * See ISO/IEC 13818-1 section 2.6.8
778c2ecf20Sopenharmony_ci */
788c2ecf20Sopenharmony_cistruct vidtv_psi_desc_registration {
798c2ecf20Sopenharmony_ci	struct vidtv_psi_desc *next;
808c2ecf20Sopenharmony_ci	u8 type;
818c2ecf20Sopenharmony_ci	u8 length;
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci	/*
848c2ecf20Sopenharmony_ci	 * The format_identifier is a 32-bit value obtained from a Registration
858c2ecf20Sopenharmony_ci	 * Authority as designated by ISO/IEC JTC 1/SC 29.
868c2ecf20Sopenharmony_ci	 */
878c2ecf20Sopenharmony_ci	__be32 format_id;
888c2ecf20Sopenharmony_ci	/*
898c2ecf20Sopenharmony_ci	 * The meaning of additional_identification_info bytes, if any, are
908c2ecf20Sopenharmony_ci	 * defined by the assignee of that format_identifier, and once defined
918c2ecf20Sopenharmony_ci	 * they shall not change.
928c2ecf20Sopenharmony_ci	 */
938c2ecf20Sopenharmony_ci	u8 additional_identification_info[];
948c2ecf20Sopenharmony_ci} __packed;
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci/*
978c2ecf20Sopenharmony_ci * struct vidtv_psi_desc_network_name - A network name descriptor
988c2ecf20Sopenharmony_ci * see ETSI EN 300 468 v1.15.1 section 6.2.27
998c2ecf20Sopenharmony_ci */
1008c2ecf20Sopenharmony_cistruct vidtv_psi_desc_network_name {
1018c2ecf20Sopenharmony_ci	struct vidtv_psi_desc *next;
1028c2ecf20Sopenharmony_ci	u8 type;
1038c2ecf20Sopenharmony_ci	u8 length;
1048c2ecf20Sopenharmony_ci	char *network_name;
1058c2ecf20Sopenharmony_ci} __packed;
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_cistruct vidtv_psi_desc_service_list_entry {
1088c2ecf20Sopenharmony_ci	__be16 service_id;
1098c2ecf20Sopenharmony_ci	u8 service_type;
1108c2ecf20Sopenharmony_ci	struct vidtv_psi_desc_service_list_entry *next;
1118c2ecf20Sopenharmony_ci} __packed;
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci/*
1148c2ecf20Sopenharmony_ci * struct vidtv_psi_desc_service_list - A service list descriptor
1158c2ecf20Sopenharmony_ci * see ETSI EN 300 468 v1.15.1 section 6.2.35
1168c2ecf20Sopenharmony_ci */
1178c2ecf20Sopenharmony_cistruct vidtv_psi_desc_service_list {
1188c2ecf20Sopenharmony_ci	struct vidtv_psi_desc *next;
1198c2ecf20Sopenharmony_ci	u8 type;
1208c2ecf20Sopenharmony_ci	u8 length;
1218c2ecf20Sopenharmony_ci	struct vidtv_psi_desc_service_list_entry *service_list;
1228c2ecf20Sopenharmony_ci} __packed;
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci/*
1258c2ecf20Sopenharmony_ci * struct vidtv_psi_desc_short_event - A short event descriptor
1268c2ecf20Sopenharmony_ci * see ETSI EN 300 468 v1.15.1 section 6.2.37
1278c2ecf20Sopenharmony_ci */
1288c2ecf20Sopenharmony_cistruct vidtv_psi_desc_short_event {
1298c2ecf20Sopenharmony_ci	struct vidtv_psi_desc *next;
1308c2ecf20Sopenharmony_ci	u8 type;
1318c2ecf20Sopenharmony_ci	u8 length;
1328c2ecf20Sopenharmony_ci	char *iso_language_code;
1338c2ecf20Sopenharmony_ci	u8 event_name_len;
1348c2ecf20Sopenharmony_ci	char *event_name;
1358c2ecf20Sopenharmony_ci	u8 text_len;
1368c2ecf20Sopenharmony_ci	char *text;
1378c2ecf20Sopenharmony_ci} __packed;
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_cistruct vidtv_psi_desc_short_event
1408c2ecf20Sopenharmony_ci*vidtv_psi_short_event_desc_init(struct vidtv_psi_desc *head,
1418c2ecf20Sopenharmony_ci				 char *iso_language_code,
1428c2ecf20Sopenharmony_ci				 char *event_name,
1438c2ecf20Sopenharmony_ci				 char *text);
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci/*
1468c2ecf20Sopenharmony_ci * struct vidtv_psi_table_header - A header that is present for all PSI tables.
1478c2ecf20Sopenharmony_ci */
1488c2ecf20Sopenharmony_cistruct vidtv_psi_table_header {
1498c2ecf20Sopenharmony_ci	u8  table_id;
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci	__be16 bitfield; /* syntax: 1, zero: 1, one: 2, section_length: 13 */
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci	__be16 id; /* TS ID */
1548c2ecf20Sopenharmony_ci	u8  current_next:1;
1558c2ecf20Sopenharmony_ci	u8  version:5;
1568c2ecf20Sopenharmony_ci	u8  one2:2;
1578c2ecf20Sopenharmony_ci	u8  section_id;	/* section_number */
1588c2ecf20Sopenharmony_ci	u8  last_section; /* last_section_number */
1598c2ecf20Sopenharmony_ci} __packed;
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci/*
1628c2ecf20Sopenharmony_ci * struct vidtv_psi_table_pat_program - A single program in the PAT
1638c2ecf20Sopenharmony_ci * See ISO/IEC 13818-1 : 2000 p.43
1648c2ecf20Sopenharmony_ci */
1658c2ecf20Sopenharmony_cistruct vidtv_psi_table_pat_program {
1668c2ecf20Sopenharmony_ci	__be16 service_id;
1678c2ecf20Sopenharmony_ci	__be16 bitfield; /* reserved: 3, program_map_pid/network_pid: 13 */
1688c2ecf20Sopenharmony_ci	struct vidtv_psi_table_pat_program *next;
1698c2ecf20Sopenharmony_ci} __packed;
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci/*
1728c2ecf20Sopenharmony_ci * struct vidtv_psi_table_pat - The Program Allocation Table (PAT)
1738c2ecf20Sopenharmony_ci * See ISO/IEC 13818-1 : 2000 p.43
1748c2ecf20Sopenharmony_ci */
1758c2ecf20Sopenharmony_cistruct vidtv_psi_table_pat {
1768c2ecf20Sopenharmony_ci	struct vidtv_psi_table_header header;
1778c2ecf20Sopenharmony_ci	u16 num_pat;
1788c2ecf20Sopenharmony_ci	u16 num_pmt;
1798c2ecf20Sopenharmony_ci	struct vidtv_psi_table_pat_program *program;
1808c2ecf20Sopenharmony_ci} __packed;
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci/*
1838c2ecf20Sopenharmony_ci * struct vidtv_psi_table_sdt_service - Represents a service in the SDT.
1848c2ecf20Sopenharmony_ci * see ETSI EN 300 468 v1.15.1 section 5.2.3.
1858c2ecf20Sopenharmony_ci */
1868c2ecf20Sopenharmony_cistruct vidtv_psi_table_sdt_service {
1878c2ecf20Sopenharmony_ci	__be16 service_id;
1888c2ecf20Sopenharmony_ci	u8 EIT_present_following:1;
1898c2ecf20Sopenharmony_ci	u8 EIT_schedule:1;
1908c2ecf20Sopenharmony_ci	u8 reserved:6;
1918c2ecf20Sopenharmony_ci	__be16 bitfield; /* running_status: 3, free_ca:1, desc_loop_len:12 */
1928c2ecf20Sopenharmony_ci	struct vidtv_psi_desc *descriptor;
1938c2ecf20Sopenharmony_ci	struct vidtv_psi_table_sdt_service *next;
1948c2ecf20Sopenharmony_ci} __packed;
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci/*
1978c2ecf20Sopenharmony_ci * struct vidtv_psi_table_sdt - Represents the Service Description Table
1988c2ecf20Sopenharmony_ci * see ETSI EN 300 468 v1.15.1 section 5.2.3.
1998c2ecf20Sopenharmony_ci */
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_cistruct vidtv_psi_table_sdt {
2028c2ecf20Sopenharmony_ci	struct vidtv_psi_table_header header;
2038c2ecf20Sopenharmony_ci	__be16 network_id; /* original_network_id */
2048c2ecf20Sopenharmony_ci	u8  reserved;
2058c2ecf20Sopenharmony_ci	struct vidtv_psi_table_sdt_service *service;
2068c2ecf20Sopenharmony_ci} __packed;
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci/*
2098c2ecf20Sopenharmony_ci * enum service_running_status - Status of a SDT service.
2108c2ecf20Sopenharmony_ci * see ETSI EN 300 468 v1.15.1 section 5.2.3 table 6.
2118c2ecf20Sopenharmony_ci */
2128c2ecf20Sopenharmony_cienum service_running_status {
2138c2ecf20Sopenharmony_ci	RUNNING = 0x4,
2148c2ecf20Sopenharmony_ci};
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_ci/*
2178c2ecf20Sopenharmony_ci * enum service_type - The type of a SDT service.
2188c2ecf20Sopenharmony_ci * see ETSI EN 300 468 v1.15.1 section 6.2.33, table 81.
2198c2ecf20Sopenharmony_ci */
2208c2ecf20Sopenharmony_cienum service_type {
2218c2ecf20Sopenharmony_ci	/* see ETSI EN 300 468 v1.15.1 p. 77 */
2228c2ecf20Sopenharmony_ci	DIGITAL_TELEVISION_SERVICE = 0x1,
2238c2ecf20Sopenharmony_ci	DIGITAL_RADIO_SOUND_SERVICE = 0X2,
2248c2ecf20Sopenharmony_ci};
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ci/*
2278c2ecf20Sopenharmony_ci * struct vidtv_psi_table_pmt_stream - A single stream in the PMT.
2288c2ecf20Sopenharmony_ci * See ISO/IEC 13818-1 : 2000 p.46.
2298c2ecf20Sopenharmony_ci */
2308c2ecf20Sopenharmony_cistruct vidtv_psi_table_pmt_stream {
2318c2ecf20Sopenharmony_ci	u8 type;
2328c2ecf20Sopenharmony_ci	__be16 bitfield; /* reserved: 3, elementary_pid: 13 */
2338c2ecf20Sopenharmony_ci	__be16 bitfield2; /*reserved: 4, zero: 2, desc_length: 10 */
2348c2ecf20Sopenharmony_ci	struct vidtv_psi_desc *descriptor;
2358c2ecf20Sopenharmony_ci	struct vidtv_psi_table_pmt_stream *next;
2368c2ecf20Sopenharmony_ci} __packed;
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci/*
2398c2ecf20Sopenharmony_ci * struct vidtv_psi_table_pmt - The Program Map Table (PMT).
2408c2ecf20Sopenharmony_ci * See ISO/IEC 13818-1 : 2000 p.46.
2418c2ecf20Sopenharmony_ci */
2428c2ecf20Sopenharmony_cistruct vidtv_psi_table_pmt {
2438c2ecf20Sopenharmony_ci	struct vidtv_psi_table_header header;
2448c2ecf20Sopenharmony_ci	__be16 bitfield; /* reserved:3, pcr_pid: 13 */
2458c2ecf20Sopenharmony_ci	__be16 bitfield2; /* reserved: 4, zero: 2, desc_len: 10 */
2468c2ecf20Sopenharmony_ci	struct vidtv_psi_desc *descriptor;
2478c2ecf20Sopenharmony_ci	struct vidtv_psi_table_pmt_stream *stream;
2488c2ecf20Sopenharmony_ci} __packed;
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci/**
2518c2ecf20Sopenharmony_ci * struct psi_write_args - Arguments for the PSI packetizer.
2528c2ecf20Sopenharmony_ci * @dest_buf: The buffer to write into.
2538c2ecf20Sopenharmony_ci * @from: PSI data to be copied.
2548c2ecf20Sopenharmony_ci * @len: How much to write.
2558c2ecf20Sopenharmony_ci * @dest_offset: where to start writing in the dest_buffer.
2568c2ecf20Sopenharmony_ci * @pid: TS packet ID.
2578c2ecf20Sopenharmony_ci * @new_psi_section: Set when starting a table section.
2588c2ecf20Sopenharmony_ci * @continuity_counter: Incremented on every new packet.
2598c2ecf20Sopenharmony_ci * @is_crc: Set when writing the CRC at the end.
2608c2ecf20Sopenharmony_ci * @dest_buf_sz: The size of the dest_buffer
2618c2ecf20Sopenharmony_ci * @crc: a pointer to store the crc for this chunk
2628c2ecf20Sopenharmony_ci */
2638c2ecf20Sopenharmony_cistruct psi_write_args {
2648c2ecf20Sopenharmony_ci	void *dest_buf;
2658c2ecf20Sopenharmony_ci	void *from;
2668c2ecf20Sopenharmony_ci	size_t len;
2678c2ecf20Sopenharmony_ci	u32 dest_offset;
2688c2ecf20Sopenharmony_ci	u16 pid;
2698c2ecf20Sopenharmony_ci	bool new_psi_section;
2708c2ecf20Sopenharmony_ci	u8 *continuity_counter;
2718c2ecf20Sopenharmony_ci	bool is_crc;
2728c2ecf20Sopenharmony_ci	u32 dest_buf_sz;
2738c2ecf20Sopenharmony_ci	u32 *crc;
2748c2ecf20Sopenharmony_ci};
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci/**
2778c2ecf20Sopenharmony_ci * struct desc_write_args - Arguments in order to write a descriptor.
2788c2ecf20Sopenharmony_ci * @dest_buf: The buffer to write into.
2798c2ecf20Sopenharmony_ci * @dest_offset: where to start writing in the dest_buffer.
2808c2ecf20Sopenharmony_ci * @desc: A pointer to the descriptor
2818c2ecf20Sopenharmony_ci * @pid: TS packet ID.
2828c2ecf20Sopenharmony_ci * @continuity_counter: Incremented on every new packet.
2838c2ecf20Sopenharmony_ci * @dest_buf_sz: The size of the dest_buffer
2848c2ecf20Sopenharmony_ci * @crc: a pointer to store the crc for this chunk
2858c2ecf20Sopenharmony_ci */
2868c2ecf20Sopenharmony_cistruct desc_write_args {
2878c2ecf20Sopenharmony_ci	void *dest_buf;
2888c2ecf20Sopenharmony_ci	u32 dest_offset;
2898c2ecf20Sopenharmony_ci	struct vidtv_psi_desc *desc;
2908c2ecf20Sopenharmony_ci	u16 pid;
2918c2ecf20Sopenharmony_ci	u8 *continuity_counter;
2928c2ecf20Sopenharmony_ci	u32 dest_buf_sz;
2938c2ecf20Sopenharmony_ci	u32 *crc;
2948c2ecf20Sopenharmony_ci};
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci/**
2978c2ecf20Sopenharmony_ci * struct crc32_write_args - Arguments in order to write the CRC at the end of
2988c2ecf20Sopenharmony_ci * the PSI tables.
2998c2ecf20Sopenharmony_ci * @dest_buf: The buffer to write into.
3008c2ecf20Sopenharmony_ci * @dest_offset: where to start writing in the dest_buffer.
3018c2ecf20Sopenharmony_ci * @crc: the CRC value to write
3028c2ecf20Sopenharmony_ci * @pid: TS packet ID.
3038c2ecf20Sopenharmony_ci * @continuity_counter: Incremented on every new packet.
3048c2ecf20Sopenharmony_ci * @dest_buf_sz: The size of the dest_buffer
3058c2ecf20Sopenharmony_ci */
3068c2ecf20Sopenharmony_cistruct crc32_write_args {
3078c2ecf20Sopenharmony_ci	void *dest_buf;
3088c2ecf20Sopenharmony_ci	u32 dest_offset;
3098c2ecf20Sopenharmony_ci	__be32 crc;
3108c2ecf20Sopenharmony_ci	u16 pid;
3118c2ecf20Sopenharmony_ci	u8 *continuity_counter;
3128c2ecf20Sopenharmony_ci	u32 dest_buf_sz;
3138c2ecf20Sopenharmony_ci};
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci/**
3168c2ecf20Sopenharmony_ci * struct header_write_args - Arguments in order to write the common table
3178c2ecf20Sopenharmony_ci * header
3188c2ecf20Sopenharmony_ci * @dest_buf: The buffer to write into.
3198c2ecf20Sopenharmony_ci * @dest_offset: where to start writing in the dest_buffer.
3208c2ecf20Sopenharmony_ci * @h: a pointer to the header.
3218c2ecf20Sopenharmony_ci * @pid: TS packet ID.
3228c2ecf20Sopenharmony_ci * @continuity_counter: Incremented on every new packet.
3238c2ecf20Sopenharmony_ci * @dest_buf_sz: The size of the dest_buffer
3248c2ecf20Sopenharmony_ci * @crc: a pointer to store the crc for this chunk
3258c2ecf20Sopenharmony_ci */
3268c2ecf20Sopenharmony_cistruct header_write_args {
3278c2ecf20Sopenharmony_ci	void *dest_buf;
3288c2ecf20Sopenharmony_ci	u32 dest_offset;
3298c2ecf20Sopenharmony_ci	struct vidtv_psi_table_header *h;
3308c2ecf20Sopenharmony_ci	u16 pid;
3318c2ecf20Sopenharmony_ci	u8 *continuity_counter;
3328c2ecf20Sopenharmony_ci	u32 dest_buf_sz;
3338c2ecf20Sopenharmony_ci	u32 *crc;
3348c2ecf20Sopenharmony_ci};
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_cistruct vidtv_psi_desc_service *vidtv_psi_service_desc_init(struct vidtv_psi_desc *head,
3378c2ecf20Sopenharmony_ci							   enum service_type service_type,
3388c2ecf20Sopenharmony_ci							   char *service_name,
3398c2ecf20Sopenharmony_ci							   char *provider_name);
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_cistruct vidtv_psi_desc_registration
3428c2ecf20Sopenharmony_ci*vidtv_psi_registration_desc_init(struct vidtv_psi_desc *head,
3438c2ecf20Sopenharmony_ci				  __be32 format_id,
3448c2ecf20Sopenharmony_ci				  u8 *additional_ident_info,
3458c2ecf20Sopenharmony_ci				  u32 additional_info_len);
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_cistruct vidtv_psi_desc_network_name
3488c2ecf20Sopenharmony_ci*vidtv_psi_network_name_desc_init(struct vidtv_psi_desc *head, char *network_name);
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_cistruct vidtv_psi_desc_service_list
3518c2ecf20Sopenharmony_ci*vidtv_psi_service_list_desc_init(struct vidtv_psi_desc *head,
3528c2ecf20Sopenharmony_ci				  struct vidtv_psi_desc_service_list_entry *entry);
3538c2ecf20Sopenharmony_ci
3548c2ecf20Sopenharmony_cistruct vidtv_psi_table_pat_program
3558c2ecf20Sopenharmony_ci*vidtv_psi_pat_program_init(struct vidtv_psi_table_pat_program *head,
3568c2ecf20Sopenharmony_ci			    u16 service_id,
3578c2ecf20Sopenharmony_ci			    u16 program_map_pid);
3588c2ecf20Sopenharmony_ci
3598c2ecf20Sopenharmony_cistruct vidtv_psi_table_pmt_stream*
3608c2ecf20Sopenharmony_cividtv_psi_pmt_stream_init(struct vidtv_psi_table_pmt_stream *head,
3618c2ecf20Sopenharmony_ci			  enum vidtv_psi_stream_types stream_type,
3628c2ecf20Sopenharmony_ci			  u16 es_pid);
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_cistruct vidtv_psi_table_pat *vidtv_psi_pat_table_init(u16 transport_stream_id);
3658c2ecf20Sopenharmony_ci
3668c2ecf20Sopenharmony_cistruct vidtv_psi_table_pmt *vidtv_psi_pmt_table_init(u16 program_number,
3678c2ecf20Sopenharmony_ci						     u16 pcr_pid);
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_cistruct vidtv_psi_table_sdt *vidtv_psi_sdt_table_init(u16 network_id,
3708c2ecf20Sopenharmony_ci						     u16 transport_stream_id);
3718c2ecf20Sopenharmony_ci
3728c2ecf20Sopenharmony_cistruct vidtv_psi_table_sdt_service*
3738c2ecf20Sopenharmony_cividtv_psi_sdt_service_init(struct vidtv_psi_table_sdt_service *head,
3748c2ecf20Sopenharmony_ci			   u16 service_id,
3758c2ecf20Sopenharmony_ci			   bool eit_schedule,
3768c2ecf20Sopenharmony_ci			   bool eit_present_following);
3778c2ecf20Sopenharmony_ci
3788c2ecf20Sopenharmony_civoid
3798c2ecf20Sopenharmony_cividtv_psi_desc_destroy(struct vidtv_psi_desc *desc);
3808c2ecf20Sopenharmony_ci
3818c2ecf20Sopenharmony_civoid
3828c2ecf20Sopenharmony_cividtv_psi_pat_program_destroy(struct vidtv_psi_table_pat_program *p);
3838c2ecf20Sopenharmony_ci
3848c2ecf20Sopenharmony_civoid
3858c2ecf20Sopenharmony_cividtv_psi_pat_table_destroy(struct vidtv_psi_table_pat *p);
3868c2ecf20Sopenharmony_ci
3878c2ecf20Sopenharmony_civoid
3888c2ecf20Sopenharmony_cividtv_psi_pmt_stream_destroy(struct vidtv_psi_table_pmt_stream *s);
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_civoid
3918c2ecf20Sopenharmony_cividtv_psi_pmt_table_destroy(struct vidtv_psi_table_pmt *pmt);
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_civoid
3948c2ecf20Sopenharmony_cividtv_psi_sdt_table_destroy(struct vidtv_psi_table_sdt *sdt);
3958c2ecf20Sopenharmony_ci
3968c2ecf20Sopenharmony_civoid
3978c2ecf20Sopenharmony_cividtv_psi_sdt_service_destroy(struct vidtv_psi_table_sdt_service *service);
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_ci/**
4008c2ecf20Sopenharmony_ci * vidtv_psi_sdt_service_assign - Assigns the service loop to the SDT.
4018c2ecf20Sopenharmony_ci * @sdt: The SDT to assign to.
4028c2ecf20Sopenharmony_ci * @service: The service loop (one or more services)
4038c2ecf20Sopenharmony_ci *
4048c2ecf20Sopenharmony_ci * This will free the previous service loop in the table.
4058c2ecf20Sopenharmony_ci * This will assign ownership of the service loop to the table, i.e. the table
4068c2ecf20Sopenharmony_ci * will free this service loop when a call to its destroy function is made.
4078c2ecf20Sopenharmony_ci */
4088c2ecf20Sopenharmony_civoid
4098c2ecf20Sopenharmony_cividtv_psi_sdt_service_assign(struct vidtv_psi_table_sdt *sdt,
4108c2ecf20Sopenharmony_ci			     struct vidtv_psi_table_sdt_service *service);
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_ci/**
4138c2ecf20Sopenharmony_ci * vidtv_psi_desc_assign - Assigns a descriptor loop at some point
4148c2ecf20Sopenharmony_ci * @to: Where to assign this descriptor loop to
4158c2ecf20Sopenharmony_ci * @desc: The descriptor loop that will be assigned.
4168c2ecf20Sopenharmony_ci *
4178c2ecf20Sopenharmony_ci * This will free the loop in 'to', if any.
4188c2ecf20Sopenharmony_ci */
4198c2ecf20Sopenharmony_civoid vidtv_psi_desc_assign(struct vidtv_psi_desc **to,
4208c2ecf20Sopenharmony_ci			   struct vidtv_psi_desc *desc);
4218c2ecf20Sopenharmony_ci
4228c2ecf20Sopenharmony_ci/**
4238c2ecf20Sopenharmony_ci * vidtv_pmt_desc_assign - Assigns a descriptor loop at some point in a PMT section.
4248c2ecf20Sopenharmony_ci * @pmt: The PMT section that will contain the descriptor loop
4258c2ecf20Sopenharmony_ci * @to: Where in the PMT to assign this descriptor loop to
4268c2ecf20Sopenharmony_ci * @desc: The descriptor loop that will be assigned.
4278c2ecf20Sopenharmony_ci *
4288c2ecf20Sopenharmony_ci * This will free the loop in 'to', if any.
4298c2ecf20Sopenharmony_ci * This will assign ownership of the loop to the table, i.e. the table
4308c2ecf20Sopenharmony_ci * will free this loop when a call to its destroy function is made.
4318c2ecf20Sopenharmony_ci */
4328c2ecf20Sopenharmony_civoid vidtv_pmt_desc_assign(struct vidtv_psi_table_pmt *pmt,
4338c2ecf20Sopenharmony_ci			   struct vidtv_psi_desc **to,
4348c2ecf20Sopenharmony_ci			   struct vidtv_psi_desc *desc);
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_ci/**
4378c2ecf20Sopenharmony_ci * vidtv_sdt_desc_assign - Assigns a descriptor loop at some point in a SDT.
4388c2ecf20Sopenharmony_ci * @sdt: The SDT that will contain the descriptor loop
4398c2ecf20Sopenharmony_ci * @to: Where in the PMT to assign this descriptor loop to
4408c2ecf20Sopenharmony_ci * @desc: The descriptor loop that will be assigned.
4418c2ecf20Sopenharmony_ci *
4428c2ecf20Sopenharmony_ci * This will free the loop in 'to', if any.
4438c2ecf20Sopenharmony_ci * This will assign ownership of the loop to the table, i.e. the table
4448c2ecf20Sopenharmony_ci * will free this loop when a call to its destroy function is made.
4458c2ecf20Sopenharmony_ci */
4468c2ecf20Sopenharmony_civoid vidtv_sdt_desc_assign(struct vidtv_psi_table_sdt *sdt,
4478c2ecf20Sopenharmony_ci			   struct vidtv_psi_desc **to,
4488c2ecf20Sopenharmony_ci			   struct vidtv_psi_desc *desc);
4498c2ecf20Sopenharmony_ci
4508c2ecf20Sopenharmony_ci/**
4518c2ecf20Sopenharmony_ci * vidtv_psi_pat_program_assign - Assigns the program loop to the PAT.
4528c2ecf20Sopenharmony_ci * @pat: The PAT to assign to.
4538c2ecf20Sopenharmony_ci * @p: The program loop (one or more programs)
4548c2ecf20Sopenharmony_ci *
4558c2ecf20Sopenharmony_ci * This will free the previous program loop in the table.
4568c2ecf20Sopenharmony_ci * This will assign ownership of the program loop to the table, i.e. the table
4578c2ecf20Sopenharmony_ci * will free this program loop when a call to its destroy function is made.
4588c2ecf20Sopenharmony_ci */
4598c2ecf20Sopenharmony_civoid vidtv_psi_pat_program_assign(struct vidtv_psi_table_pat *pat,
4608c2ecf20Sopenharmony_ci				  struct vidtv_psi_table_pat_program *p);
4618c2ecf20Sopenharmony_ci
4628c2ecf20Sopenharmony_ci/**
4638c2ecf20Sopenharmony_ci * vidtv_psi_pmt_stream_assign - Assigns the stream loop to the PAT.
4648c2ecf20Sopenharmony_ci * @pmt: The PMT to assign to.
4658c2ecf20Sopenharmony_ci * @s: The stream loop (one or more streams)
4668c2ecf20Sopenharmony_ci *
4678c2ecf20Sopenharmony_ci * This will free the previous stream loop in the table.
4688c2ecf20Sopenharmony_ci * This will assign ownership of the stream loop to the table, i.e. the table
4698c2ecf20Sopenharmony_ci * will free this stream loop when a call to its destroy function is made.
4708c2ecf20Sopenharmony_ci */
4718c2ecf20Sopenharmony_civoid vidtv_psi_pmt_stream_assign(struct vidtv_psi_table_pmt *pmt,
4728c2ecf20Sopenharmony_ci				 struct vidtv_psi_table_pmt_stream *s);
4738c2ecf20Sopenharmony_ci
4748c2ecf20Sopenharmony_cistruct vidtv_psi_desc *vidtv_psi_desc_clone(struct vidtv_psi_desc *desc);
4758c2ecf20Sopenharmony_ci
4768c2ecf20Sopenharmony_ci/**
4778c2ecf20Sopenharmony_ci * vidtv_psi_pmt_create_sec_for_each_pat_entry - Create a PMT section for each
4788c2ecf20Sopenharmony_ci * program found in the PAT
4798c2ecf20Sopenharmony_ci * @pat: The PAT to look for programs.
4808c2ecf20Sopenharmony_ci * @pcr_pid: packet ID for the PCR to be used for the program described in this
4818c2ecf20Sopenharmony_ci * PMT section
4828c2ecf20Sopenharmony_ci */
4838c2ecf20Sopenharmony_cistruct vidtv_psi_table_pmt**
4848c2ecf20Sopenharmony_cividtv_psi_pmt_create_sec_for_each_pat_entry(struct vidtv_psi_table_pat *pat, u16 pcr_pid);
4858c2ecf20Sopenharmony_ci
4868c2ecf20Sopenharmony_ci/**
4878c2ecf20Sopenharmony_ci * vidtv_psi_pmt_get_pid - Get the TS PID for a PMT section.
4888c2ecf20Sopenharmony_ci * @section: The PMT section whose PID we want to retrieve.
4898c2ecf20Sopenharmony_ci * @pat: The PAT table to look into.
4908c2ecf20Sopenharmony_ci *
4918c2ecf20Sopenharmony_ci * Returns: the TS PID for 'section'
4928c2ecf20Sopenharmony_ci */
4938c2ecf20Sopenharmony_ciu16 vidtv_psi_pmt_get_pid(struct vidtv_psi_table_pmt *section,
4948c2ecf20Sopenharmony_ci			  struct vidtv_psi_table_pat *pat);
4958c2ecf20Sopenharmony_ci
4968c2ecf20Sopenharmony_ci/**
4978c2ecf20Sopenharmony_ci * vidtv_psi_pat_table_update_sec_len - Recompute and update the PAT section length.
4988c2ecf20Sopenharmony_ci * @pat: The PAT whose length is to be updated.
4998c2ecf20Sopenharmony_ci *
5008c2ecf20Sopenharmony_ci * This will traverse the table and accumulate the length of its components,
5018c2ecf20Sopenharmony_ci * which is then used to replace the 'section_length' field.
5028c2ecf20Sopenharmony_ci *
5038c2ecf20Sopenharmony_ci * If section_length > MAX_SECTION_LEN, the operation fails.
5048c2ecf20Sopenharmony_ci */
5058c2ecf20Sopenharmony_civoid vidtv_psi_pat_table_update_sec_len(struct vidtv_psi_table_pat *pat);
5068c2ecf20Sopenharmony_ci
5078c2ecf20Sopenharmony_ci/**
5088c2ecf20Sopenharmony_ci * vidtv_psi_pmt_table_update_sec_len - Recompute and update the PMT section length.
5098c2ecf20Sopenharmony_ci * @pmt: The PMT whose length is to be updated.
5108c2ecf20Sopenharmony_ci *
5118c2ecf20Sopenharmony_ci * This will traverse the table and accumulate the length of its components,
5128c2ecf20Sopenharmony_ci * which is then used to replace the 'section_length' field.
5138c2ecf20Sopenharmony_ci *
5148c2ecf20Sopenharmony_ci * If section_length > MAX_SECTION_LEN, the operation fails.
5158c2ecf20Sopenharmony_ci */
5168c2ecf20Sopenharmony_civoid vidtv_psi_pmt_table_update_sec_len(struct vidtv_psi_table_pmt *pmt);
5178c2ecf20Sopenharmony_ci
5188c2ecf20Sopenharmony_ci/**
5198c2ecf20Sopenharmony_ci * vidtv_psi_sdt_table_update_sec_len - Recompute and update the SDT section length.
5208c2ecf20Sopenharmony_ci * @sdt: The SDT whose length is to be updated.
5218c2ecf20Sopenharmony_ci *
5228c2ecf20Sopenharmony_ci * This will traverse the table and accumulate the length of its components,
5238c2ecf20Sopenharmony_ci * which is then used to replace the 'section_length' field.
5248c2ecf20Sopenharmony_ci *
5258c2ecf20Sopenharmony_ci * If section_length > MAX_SECTION_LEN, the operation fails.
5268c2ecf20Sopenharmony_ci */
5278c2ecf20Sopenharmony_civoid vidtv_psi_sdt_table_update_sec_len(struct vidtv_psi_table_sdt *sdt);
5288c2ecf20Sopenharmony_ci
5298c2ecf20Sopenharmony_ci/**
5308c2ecf20Sopenharmony_ci * struct vidtv_psi_pat_write_args - Arguments for writing a PAT table
5318c2ecf20Sopenharmony_ci * @buf: The destination buffer.
5328c2ecf20Sopenharmony_ci * @offset: The offset into the destination buffer.
5338c2ecf20Sopenharmony_ci * @pat: A pointer to the PAT.
5348c2ecf20Sopenharmony_ci * @buf_sz: The size of the destination buffer.
5358c2ecf20Sopenharmony_ci * @continuity_counter: A pointer to the CC. Incremented on every new packet.
5368c2ecf20Sopenharmony_ci *
5378c2ecf20Sopenharmony_ci */
5388c2ecf20Sopenharmony_cistruct vidtv_psi_pat_write_args {
5398c2ecf20Sopenharmony_ci	char *buf;
5408c2ecf20Sopenharmony_ci	u32 offset;
5418c2ecf20Sopenharmony_ci	struct vidtv_psi_table_pat *pat;
5428c2ecf20Sopenharmony_ci	u32 buf_sz;
5438c2ecf20Sopenharmony_ci	u8 *continuity_counter;
5448c2ecf20Sopenharmony_ci};
5458c2ecf20Sopenharmony_ci
5468c2ecf20Sopenharmony_ci/**
5478c2ecf20Sopenharmony_ci * vidtv_psi_pat_write_into - Write PAT as MPEG-TS packets into a buffer.
5488c2ecf20Sopenharmony_ci * @args: An instance of struct vidtv_psi_pat_write_args
5498c2ecf20Sopenharmony_ci *
5508c2ecf20Sopenharmony_ci * This function writes the MPEG TS packets for a PAT table into a buffer.
5518c2ecf20Sopenharmony_ci * Calling code will usually generate the PAT via a call to its init function
5528c2ecf20Sopenharmony_ci * and thus is responsible for freeing it.
5538c2ecf20Sopenharmony_ci *
5548c2ecf20Sopenharmony_ci * Return: The number of bytes written into the buffer. This is NOT
5558c2ecf20Sopenharmony_ci * equal to the size of the PAT, since more space is needed for TS headers during TS
5568c2ecf20Sopenharmony_ci * encapsulation.
5578c2ecf20Sopenharmony_ci */
5588c2ecf20Sopenharmony_ciu32 vidtv_psi_pat_write_into(struct vidtv_psi_pat_write_args *args);
5598c2ecf20Sopenharmony_ci
5608c2ecf20Sopenharmony_ci/**
5618c2ecf20Sopenharmony_ci * struct vidtv_psi_sdt_write_args - Arguments for writing a SDT table
5628c2ecf20Sopenharmony_ci * @buf: The destination buffer.
5638c2ecf20Sopenharmony_ci * @offset: The offset into the destination buffer.
5648c2ecf20Sopenharmony_ci * @sdt: A pointer to the SDT.
5658c2ecf20Sopenharmony_ci * @buf_sz: The size of the destination buffer.
5668c2ecf20Sopenharmony_ci * @continuity_counter: A pointer to the CC. Incremented on every new packet.
5678c2ecf20Sopenharmony_ci *
5688c2ecf20Sopenharmony_ci */
5698c2ecf20Sopenharmony_ci
5708c2ecf20Sopenharmony_cistruct vidtv_psi_sdt_write_args {
5718c2ecf20Sopenharmony_ci	char *buf;
5728c2ecf20Sopenharmony_ci	u32 offset;
5738c2ecf20Sopenharmony_ci	struct vidtv_psi_table_sdt *sdt;
5748c2ecf20Sopenharmony_ci	u32 buf_sz;
5758c2ecf20Sopenharmony_ci	u8 *continuity_counter;
5768c2ecf20Sopenharmony_ci};
5778c2ecf20Sopenharmony_ci
5788c2ecf20Sopenharmony_ci/**
5798c2ecf20Sopenharmony_ci * vidtv_psi_sdt_write_into - Write SDT as MPEG-TS packets into a buffer.
5808c2ecf20Sopenharmony_ci * @args: an instance of struct vidtv_psi_sdt_write_args
5818c2ecf20Sopenharmony_ci *
5828c2ecf20Sopenharmony_ci * This function writes the MPEG TS packets for a SDT table into a buffer.
5838c2ecf20Sopenharmony_ci * Calling code will usually generate the SDT via a call to its init function
5848c2ecf20Sopenharmony_ci * and thus is responsible for freeing it.
5858c2ecf20Sopenharmony_ci *
5868c2ecf20Sopenharmony_ci * Return: The number of bytes written into the buffer. This is NOT
5878c2ecf20Sopenharmony_ci * equal to the size of the SDT, since more space is needed for TS headers during TS
5888c2ecf20Sopenharmony_ci * encapsulation.
5898c2ecf20Sopenharmony_ci */
5908c2ecf20Sopenharmony_ciu32 vidtv_psi_sdt_write_into(struct vidtv_psi_sdt_write_args *args);
5918c2ecf20Sopenharmony_ci
5928c2ecf20Sopenharmony_ci/**
5938c2ecf20Sopenharmony_ci * struct vidtv_psi_pmt_write_args - Arguments for writing a PMT section
5948c2ecf20Sopenharmony_ci * @buf: The destination buffer.
5958c2ecf20Sopenharmony_ci * @offset: The offset into the destination buffer.
5968c2ecf20Sopenharmony_ci * @pmt: A pointer to the PMT.
5978c2ecf20Sopenharmony_ci * @pid: Program ID
5988c2ecf20Sopenharmony_ci * @buf_sz: The size of the destination buffer.
5998c2ecf20Sopenharmony_ci * @continuity_counter: A pointer to the CC. Incremented on every new packet.
6008c2ecf20Sopenharmony_ci * @pcr_pid: The TS PID used for the PSI packets. All channels will share the
6018c2ecf20Sopenharmony_ci * same PCR.
6028c2ecf20Sopenharmony_ci */
6038c2ecf20Sopenharmony_cistruct vidtv_psi_pmt_write_args {
6048c2ecf20Sopenharmony_ci	char *buf;
6058c2ecf20Sopenharmony_ci	u32 offset;
6068c2ecf20Sopenharmony_ci	struct vidtv_psi_table_pmt *pmt;
6078c2ecf20Sopenharmony_ci	u16 pid;
6088c2ecf20Sopenharmony_ci	u32 buf_sz;
6098c2ecf20Sopenharmony_ci	u8 *continuity_counter;
6108c2ecf20Sopenharmony_ci	u16 pcr_pid;
6118c2ecf20Sopenharmony_ci};
6128c2ecf20Sopenharmony_ci
6138c2ecf20Sopenharmony_ci/**
6148c2ecf20Sopenharmony_ci * vidtv_psi_pmt_write_into - Write PMT as MPEG-TS packets into a buffer.
6158c2ecf20Sopenharmony_ci * @args: an instance of struct vidtv_psi_pmt_write_args
6168c2ecf20Sopenharmony_ci *
6178c2ecf20Sopenharmony_ci * This function writes the MPEG TS packets for a PMT section into a buffer.
6188c2ecf20Sopenharmony_ci * Calling code will usually generate the PMT section via a call to its init function
6198c2ecf20Sopenharmony_ci * and thus is responsible for freeing it.
6208c2ecf20Sopenharmony_ci *
6218c2ecf20Sopenharmony_ci * Return: The number of bytes written into the buffer. This is NOT
6228c2ecf20Sopenharmony_ci * equal to the size of the PMT section, since more space is needed for TS headers
6238c2ecf20Sopenharmony_ci * during TS encapsulation.
6248c2ecf20Sopenharmony_ci */
6258c2ecf20Sopenharmony_ciu32 vidtv_psi_pmt_write_into(struct vidtv_psi_pmt_write_args *args);
6268c2ecf20Sopenharmony_ci
6278c2ecf20Sopenharmony_ci/**
6288c2ecf20Sopenharmony_ci * vidtv_psi_find_pmt_sec - Finds the PMT section for 'program_num'
6298c2ecf20Sopenharmony_ci * @pmt_sections: The sections to look into.
6308c2ecf20Sopenharmony_ci * @nsections: The number of sections.
6318c2ecf20Sopenharmony_ci * @program_num: The 'program_num' from PAT pointing to a PMT section.
6328c2ecf20Sopenharmony_ci *
6338c2ecf20Sopenharmony_ci * Return: A pointer to the PMT, if found, or NULL.
6348c2ecf20Sopenharmony_ci */
6358c2ecf20Sopenharmony_cistruct vidtv_psi_table_pmt *vidtv_psi_find_pmt_sec(struct vidtv_psi_table_pmt **pmt_sections,
6368c2ecf20Sopenharmony_ci						   u16 nsections,
6378c2ecf20Sopenharmony_ci						   u16 program_num);
6388c2ecf20Sopenharmony_ci
6398c2ecf20Sopenharmony_ciu16 vidtv_psi_get_pat_program_pid(struct vidtv_psi_table_pat_program *p);
6408c2ecf20Sopenharmony_ciu16 vidtv_psi_pmt_stream_get_elem_pid(struct vidtv_psi_table_pmt_stream *s);
6418c2ecf20Sopenharmony_ci
6428c2ecf20Sopenharmony_ci/**
6438c2ecf20Sopenharmony_ci * struct vidtv_psi_table_transport - A entry in the TS loop for the NIT and/or other tables.
6448c2ecf20Sopenharmony_ci * See ETSI 300 468 section 5.2.1
6458c2ecf20Sopenharmony_ci * @transport_id: The TS ID being described
6468c2ecf20Sopenharmony_ci * @network_id: The network_id that contains the TS ID
6478c2ecf20Sopenharmony_ci * @bitfield: Contains the descriptor loop length
6488c2ecf20Sopenharmony_ci * @descriptor: A descriptor loop
6498c2ecf20Sopenharmony_ci * @next: Pointer to the next entry
6508c2ecf20Sopenharmony_ci *
6518c2ecf20Sopenharmony_ci */
6528c2ecf20Sopenharmony_cistruct vidtv_psi_table_transport {
6538c2ecf20Sopenharmony_ci	__be16 transport_id;
6548c2ecf20Sopenharmony_ci	__be16 network_id;
6558c2ecf20Sopenharmony_ci	__be16 bitfield; /* desc_len: 12, reserved: 4 */
6568c2ecf20Sopenharmony_ci	struct vidtv_psi_desc *descriptor;
6578c2ecf20Sopenharmony_ci	struct vidtv_psi_table_transport *next;
6588c2ecf20Sopenharmony_ci} __packed;
6598c2ecf20Sopenharmony_ci
6608c2ecf20Sopenharmony_ci/**
6618c2ecf20Sopenharmony_ci * struct vidtv_psi_table_nit - A Network Information Table (NIT). See ETSI 300
6628c2ecf20Sopenharmony_ci * 468 section 5.2.1
6638c2ecf20Sopenharmony_ci * @header: A PSI table header
6648c2ecf20Sopenharmony_ci * @bitfield: Contains the network descriptor length
6658c2ecf20Sopenharmony_ci * @descriptor: A descriptor loop describing the network
6668c2ecf20Sopenharmony_ci * @bitfield2: Contains the transport stream loop length
6678c2ecf20Sopenharmony_ci * @transport: The transport stream loop
6688c2ecf20Sopenharmony_ci *
6698c2ecf20Sopenharmony_ci */
6708c2ecf20Sopenharmony_cistruct vidtv_psi_table_nit {
6718c2ecf20Sopenharmony_ci	struct vidtv_psi_table_header header;
6728c2ecf20Sopenharmony_ci	__be16 bitfield; /* network_desc_len: 12, reserved:4 */
6738c2ecf20Sopenharmony_ci	struct vidtv_psi_desc *descriptor;
6748c2ecf20Sopenharmony_ci	__be16 bitfield2; /* ts_loop_len: 12, reserved: 4 */
6758c2ecf20Sopenharmony_ci	struct vidtv_psi_table_transport *transport;
6768c2ecf20Sopenharmony_ci} __packed;
6778c2ecf20Sopenharmony_ci
6788c2ecf20Sopenharmony_cistruct vidtv_psi_table_nit
6798c2ecf20Sopenharmony_ci*vidtv_psi_nit_table_init(u16 network_id,
6808c2ecf20Sopenharmony_ci			  u16 transport_stream_id,
6818c2ecf20Sopenharmony_ci			  char *network_name,
6828c2ecf20Sopenharmony_ci			  struct vidtv_psi_desc_service_list_entry *service_list);
6838c2ecf20Sopenharmony_ci
6848c2ecf20Sopenharmony_ci/**
6858c2ecf20Sopenharmony_ci * struct vidtv_psi_nit_write_args - Arguments for writing a NIT section
6868c2ecf20Sopenharmony_ci * @buf: The destination buffer.
6878c2ecf20Sopenharmony_ci * @offset: The offset into the destination buffer.
6888c2ecf20Sopenharmony_ci * @nit: A pointer to the NIT
6898c2ecf20Sopenharmony_ci * @buf_sz: The size of the destination buffer.
6908c2ecf20Sopenharmony_ci * @continuity_counter: A pointer to the CC. Incremented on every new packet.
6918c2ecf20Sopenharmony_ci *
6928c2ecf20Sopenharmony_ci */
6938c2ecf20Sopenharmony_cistruct vidtv_psi_nit_write_args {
6948c2ecf20Sopenharmony_ci	char *buf;
6958c2ecf20Sopenharmony_ci	u32 offset;
6968c2ecf20Sopenharmony_ci	struct vidtv_psi_table_nit *nit;
6978c2ecf20Sopenharmony_ci	u32 buf_sz;
6988c2ecf20Sopenharmony_ci	u8 *continuity_counter;
6998c2ecf20Sopenharmony_ci};
7008c2ecf20Sopenharmony_ci
7018c2ecf20Sopenharmony_ci/**
7028c2ecf20Sopenharmony_ci * vidtv_psi_nit_write_into - Write NIT as MPEG-TS packets into a buffer.
7038c2ecf20Sopenharmony_ci * @args: an instance of struct vidtv_psi_nit_write_args
7048c2ecf20Sopenharmony_ci *
7058c2ecf20Sopenharmony_ci * This function writes the MPEG TS packets for a NIT table into a buffer.
7068c2ecf20Sopenharmony_ci * Calling code will usually generate the NIT via a call to its init function
7078c2ecf20Sopenharmony_ci * and thus is responsible for freeing it.
7088c2ecf20Sopenharmony_ci *
7098c2ecf20Sopenharmony_ci * Return: The number of bytes written into the buffer. This is NOT
7108c2ecf20Sopenharmony_ci * equal to the size of the NIT, since more space is needed for TS headers during TS
7118c2ecf20Sopenharmony_ci * encapsulation.
7128c2ecf20Sopenharmony_ci */
7138c2ecf20Sopenharmony_ciu32 vidtv_psi_nit_write_into(struct vidtv_psi_nit_write_args *args);
7148c2ecf20Sopenharmony_ci
7158c2ecf20Sopenharmony_civoid vidtv_psi_nit_table_destroy(struct vidtv_psi_table_nit *nit);
7168c2ecf20Sopenharmony_ci
7178c2ecf20Sopenharmony_ci/*
7188c2ecf20Sopenharmony_ci * struct vidtv_psi_desc_short_event - A short event descriptor
7198c2ecf20Sopenharmony_ci * see ETSI EN 300 468 v1.15.1 section 6.2.37
7208c2ecf20Sopenharmony_ci */
7218c2ecf20Sopenharmony_cistruct vidtv_psi_table_eit_event {
7228c2ecf20Sopenharmony_ci	__be16 event_id;
7238c2ecf20Sopenharmony_ci	u8 start_time[5];
7248c2ecf20Sopenharmony_ci	u8 duration[3];
7258c2ecf20Sopenharmony_ci	__be16 bitfield; /* desc_length: 12, free_CA_mode: 1, running_status: 1 */
7268c2ecf20Sopenharmony_ci	struct vidtv_psi_desc *descriptor;
7278c2ecf20Sopenharmony_ci	struct vidtv_psi_table_eit_event *next;
7288c2ecf20Sopenharmony_ci} __packed;
7298c2ecf20Sopenharmony_ci
7308c2ecf20Sopenharmony_ci/*
7318c2ecf20Sopenharmony_ci * struct vidtv_psi_table_eit - A Event Information Table (EIT)
7328c2ecf20Sopenharmony_ci * See ETSI 300 468 section 5.2.4
7338c2ecf20Sopenharmony_ci */
7348c2ecf20Sopenharmony_cistruct vidtv_psi_table_eit {
7358c2ecf20Sopenharmony_ci	struct vidtv_psi_table_header header;
7368c2ecf20Sopenharmony_ci	__be16 transport_id;
7378c2ecf20Sopenharmony_ci	__be16 network_id;
7388c2ecf20Sopenharmony_ci	u8 last_segment;
7398c2ecf20Sopenharmony_ci	u8 last_table_id;
7408c2ecf20Sopenharmony_ci	struct vidtv_psi_table_eit_event *event;
7418c2ecf20Sopenharmony_ci} __packed;
7428c2ecf20Sopenharmony_ci
7438c2ecf20Sopenharmony_cistruct vidtv_psi_table_eit
7448c2ecf20Sopenharmony_ci*vidtv_psi_eit_table_init(u16 network_id,
7458c2ecf20Sopenharmony_ci			  u16 transport_stream_id,
7468c2ecf20Sopenharmony_ci			  __be16 service_id);
7478c2ecf20Sopenharmony_ci
7488c2ecf20Sopenharmony_ci/**
7498c2ecf20Sopenharmony_ci * struct vidtv_psi_eit_write_args - Arguments for writing an EIT section
7508c2ecf20Sopenharmony_ci * @buf: The destination buffer.
7518c2ecf20Sopenharmony_ci * @offset: The offset into the destination buffer.
7528c2ecf20Sopenharmony_ci * @eit: A pointer to the EIT
7538c2ecf20Sopenharmony_ci * @buf_sz: The size of the destination buffer.
7548c2ecf20Sopenharmony_ci * @continuity_counter: A pointer to the CC. Incremented on every new packet.
7558c2ecf20Sopenharmony_ci *
7568c2ecf20Sopenharmony_ci */
7578c2ecf20Sopenharmony_cistruct vidtv_psi_eit_write_args {
7588c2ecf20Sopenharmony_ci	char *buf;
7598c2ecf20Sopenharmony_ci	u32 offset;
7608c2ecf20Sopenharmony_ci	struct vidtv_psi_table_eit *eit;
7618c2ecf20Sopenharmony_ci	u32 buf_sz;
7628c2ecf20Sopenharmony_ci	u8 *continuity_counter;
7638c2ecf20Sopenharmony_ci};
7648c2ecf20Sopenharmony_ci
7658c2ecf20Sopenharmony_ci/**
7668c2ecf20Sopenharmony_ci * vidtv_psi_eit_write_into - Write EIT as MPEG-TS packets into a buffer.
7678c2ecf20Sopenharmony_ci * @args: an instance of struct vidtv_psi_nit_write_args
7688c2ecf20Sopenharmony_ci *
7698c2ecf20Sopenharmony_ci * This function writes the MPEG TS packets for a EIT table into a buffer.
7708c2ecf20Sopenharmony_ci * Calling code will usually generate the EIT via a call to its init function
7718c2ecf20Sopenharmony_ci * and thus is responsible for freeing it.
7728c2ecf20Sopenharmony_ci *
7738c2ecf20Sopenharmony_ci * Return: The number of bytes written into the buffer. This is NOT
7748c2ecf20Sopenharmony_ci * equal to the size of the EIT, since more space is needed for TS headers during TS
7758c2ecf20Sopenharmony_ci * encapsulation.
7768c2ecf20Sopenharmony_ci */
7778c2ecf20Sopenharmony_ciu32 vidtv_psi_eit_write_into(struct vidtv_psi_eit_write_args *args);
7788c2ecf20Sopenharmony_ci
7798c2ecf20Sopenharmony_civoid vidtv_psi_eit_table_destroy(struct vidtv_psi_table_eit *eit);
7808c2ecf20Sopenharmony_ci
7818c2ecf20Sopenharmony_ci/**
7828c2ecf20Sopenharmony_ci * vidtv_psi_eit_table_update_sec_len - Recompute and update the EIT section length.
7838c2ecf20Sopenharmony_ci * @eit: The EIT whose length is to be updated.
7848c2ecf20Sopenharmony_ci *
7858c2ecf20Sopenharmony_ci * This will traverse the table and accumulate the length of its components,
7868c2ecf20Sopenharmony_ci * which is then used to replace the 'section_length' field.
7878c2ecf20Sopenharmony_ci *
7888c2ecf20Sopenharmony_ci * If section_length > EIT_MAX_SECTION_LEN, the operation fails.
7898c2ecf20Sopenharmony_ci */
7908c2ecf20Sopenharmony_civoid vidtv_psi_eit_table_update_sec_len(struct vidtv_psi_table_eit *eit);
7918c2ecf20Sopenharmony_ci
7928c2ecf20Sopenharmony_ci/**
7938c2ecf20Sopenharmony_ci * vidtv_psi_eit_event_assign - Assigns the event loop to the EIT.
7948c2ecf20Sopenharmony_ci * @eit: The EIT to assign to.
7958c2ecf20Sopenharmony_ci * @e: The event loop
7968c2ecf20Sopenharmony_ci *
7978c2ecf20Sopenharmony_ci * This will free the previous event loop in the table.
7988c2ecf20Sopenharmony_ci * This will assign ownership of the stream loop to the table, i.e. the table
7998c2ecf20Sopenharmony_ci * will free this stream loop when a call to its destroy function is made.
8008c2ecf20Sopenharmony_ci */
8018c2ecf20Sopenharmony_civoid vidtv_psi_eit_event_assign(struct vidtv_psi_table_eit *eit,
8028c2ecf20Sopenharmony_ci				struct vidtv_psi_table_eit_event *e);
8038c2ecf20Sopenharmony_ci
8048c2ecf20Sopenharmony_cistruct vidtv_psi_table_eit_event
8058c2ecf20Sopenharmony_ci*vidtv_psi_eit_event_init(struct vidtv_psi_table_eit_event *head, u16 event_id);
8068c2ecf20Sopenharmony_ci
8078c2ecf20Sopenharmony_civoid vidtv_psi_eit_event_destroy(struct vidtv_psi_table_eit_event *e);
8088c2ecf20Sopenharmony_ci
8098c2ecf20Sopenharmony_ci#endif // VIDTV_PSI_H
810