![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0 */ 0002 /* 0003 * This file contains the logic to work with MPEG Program-Specific Information. 0004 * These are defined both in ISO/IEC 13818-1 (systems) and ETSI EN 300 468. 0005 * PSI is carried in the form of table structures, and although each table might 0006 * technically be broken into one or more sections, we do not do this here, 0007 * hence 'table' and 'section' are interchangeable for vidtv. 0008 * 0009 * Copyright (C) 2020 Daniel W. S. Almeida 0010 */ 0011 0012 #ifndef VIDTV_PSI_H 0013 #define VIDTV_PSI_H 0014 0015 #include <linux/types.h> 0016 0017 /* 0018 * all section lengths start immediately after the 'section_length' field 0019 * see ISO/IEC 13818-1 : 2000 and ETSI EN 300 468 V 1.10.1 for 0020 * reference 0021 */ 0022 #define PAT_LEN_UNTIL_LAST_SECTION_NUMBER 5 0023 #define PMT_LEN_UNTIL_PROGRAM_INFO_LENGTH 9 0024 #define SDT_LEN_UNTIL_RESERVED_FOR_FUTURE_USE 8 0025 #define NIT_LEN_UNTIL_NETWORK_DESCRIPTOR_LEN 7 0026 #define EIT_LEN_UNTIL_LAST_TABLE_ID 11 0027 #define MAX_SECTION_LEN 1021 0028 #define EIT_MAX_SECTION_LEN 4093 /* see ETSI 300 468 v.1.10.1 p. 26 */ 0029 #define VIDTV_PAT_PID 0 /* mandated by the specs */ 0030 #define VIDTV_SDT_PID 0x0011 /* mandated by the specs */ 0031 #define VIDTV_NIT_PID 0x0010 /* mandated by the specs */ 0032 #define VIDTV_EIT_PID 0x0012 /*mandated by the specs */ 0033 0034 enum vidtv_psi_descriptors { 0035 REGISTRATION_DESCRIPTOR = 0x05, /* See ISO/IEC 13818-1 section 2.6.8 */ 0036 NETWORK_NAME_DESCRIPTOR = 0x40, /* See ETSI EN 300 468 section 6.2.27 */ 0037 SERVICE_LIST_DESCRIPTOR = 0x41, /* See ETSI EN 300 468 section 6.2.35 */ 0038 SERVICE_DESCRIPTOR = 0x48, /* See ETSI EN 300 468 section 6.2.33 */ 0039 SHORT_EVENT_DESCRIPTOR = 0x4d, /* See ETSI EN 300 468 section 6.2.37 */ 0040 }; 0041 0042 enum vidtv_psi_stream_types { 0043 STREAM_PRIVATE_DATA = 0x06, /* see ISO/IEC 13818-1 2000 p. 48 */ 0044 }; 0045 0046 /* 0047 * struct vidtv_psi_desc - A generic PSI descriptor type. 0048 * The descriptor length is an 8-bit field specifying the total number of bytes of the data portion 0049 * of the descriptor following the byte defining the value of this field. 0050 */ 0051 struct vidtv_psi_desc { 0052 struct vidtv_psi_desc *next; 0053 u8 type; 0054 u8 length; 0055 u8 data[]; 0056 } __packed; 0057 0058 /* 0059 * struct vidtv_psi_desc_service - Service descriptor. 0060 * See ETSI EN 300 468 section 6.2.33. 0061 */ 0062 struct vidtv_psi_desc_service { 0063 struct vidtv_psi_desc *next; 0064 u8 type; 0065 u8 length; 0066 0067 u8 service_type; 0068 u8 provider_name_len; 0069 char *provider_name; 0070 u8 service_name_len; 0071 char *service_name; 0072 } __packed; 0073 0074 /* 0075 * struct vidtv_psi_desc_registration - A registration descriptor. 0076 * See ISO/IEC 13818-1 section 2.6.8 0077 */ 0078 struct vidtv_psi_desc_registration { 0079 struct vidtv_psi_desc *next; 0080 u8 type; 0081 u8 length; 0082 0083 /* 0084 * The format_identifier is a 32-bit value obtained from a Registration 0085 * Authority as designated by ISO/IEC JTC 1/SC 29. 0086 */ 0087 __be32 format_id; 0088 /* 0089 * The meaning of additional_identification_info bytes, if any, are 0090 * defined by the assignee of that format_identifier, and once defined 0091 * they shall not change. 0092 */ 0093 u8 additional_identification_info[]; 0094 } __packed; 0095 0096 /* 0097 * struct vidtv_psi_desc_network_name - A network name descriptor 0098 * see ETSI EN 300 468 v1.15.1 section 6.2.27 0099 */ 0100 struct vidtv_psi_desc_network_name { 0101 struct vidtv_psi_desc *next; 0102 u8 type; 0103 u8 length; 0104 char *network_name; 0105 } __packed; 0106 0107 struct vidtv_psi_desc_service_list_entry { 0108 __be16 service_id; 0109 u8 service_type; 0110 struct vidtv_psi_desc_service_list_entry *next; 0111 } __packed; 0112 0113 /* 0114 * struct vidtv_psi_desc_service_list - A service list descriptor 0115 * see ETSI EN 300 468 v1.15.1 section 6.2.35 0116 */ 0117 struct vidtv_psi_desc_service_list { 0118 struct vidtv_psi_desc *next; 0119 u8 type; 0120 u8 length; 0121 struct vidtv_psi_desc_service_list_entry *service_list; 0122 } __packed; 0123 0124 /* 0125 * struct vidtv_psi_desc_short_event - A short event descriptor 0126 * see ETSI EN 300 468 v1.15.1 section 6.2.37 0127 */ 0128 struct vidtv_psi_desc_short_event { 0129 struct vidtv_psi_desc *next; 0130 u8 type; 0131 u8 length; 0132 char *iso_language_code; 0133 u8 event_name_len; 0134 char *event_name; 0135 u8 text_len; 0136 char *text; 0137 } __packed; 0138 0139 struct vidtv_psi_desc_short_event 0140 *vidtv_psi_short_event_desc_init(struct vidtv_psi_desc *head, 0141 char *iso_language_code, 0142 char *event_name, 0143 char *text); 0144 0145 /* 0146 * struct vidtv_psi_table_header - A header that is present for all PSI tables. 0147 */ 0148 struct vidtv_psi_table_header { 0149 u8 table_id; 0150 0151 __be16 bitfield; /* syntax: 1, zero: 1, one: 2, section_length: 13 */ 0152 0153 __be16 id; /* TS ID */ 0154 u8 current_next:1; 0155 u8 version:5; 0156 u8 one2:2; 0157 u8 section_id; /* section_number */ 0158 u8 last_section; /* last_section_number */ 0159 } __packed; 0160 0161 /* 0162 * struct vidtv_psi_table_pat_program - A single program in the PAT 0163 * See ISO/IEC 13818-1 : 2000 p.43 0164 */ 0165 struct vidtv_psi_table_pat_program { 0166 __be16 service_id; 0167 __be16 bitfield; /* reserved: 3, program_map_pid/network_pid: 13 */ 0168 struct vidtv_psi_table_pat_program *next; 0169 } __packed; 0170 0171 /* 0172 * struct vidtv_psi_table_pat - The Program Allocation Table (PAT) 0173 * See ISO/IEC 13818-1 : 2000 p.43 0174 */ 0175 struct vidtv_psi_table_pat { 0176 struct vidtv_psi_table_header header; 0177 u16 num_pat; 0178 u16 num_pmt; 0179 struct vidtv_psi_table_pat_program *program; 0180 } __packed; 0181 0182 /* 0183 * struct vidtv_psi_table_sdt_service - Represents a service in the SDT. 0184 * see ETSI EN 300 468 v1.15.1 section 5.2.3. 0185 */ 0186 struct vidtv_psi_table_sdt_service { 0187 __be16 service_id; 0188 u8 EIT_present_following:1; 0189 u8 EIT_schedule:1; 0190 u8 reserved:6; 0191 __be16 bitfield; /* running_status: 3, free_ca:1, desc_loop_len:12 */ 0192 struct vidtv_psi_desc *descriptor; 0193 struct vidtv_psi_table_sdt_service *next; 0194 } __packed; 0195 0196 /* 0197 * struct vidtv_psi_table_sdt - Represents the Service Description Table 0198 * see ETSI EN 300 468 v1.15.1 section 5.2.3. 0199 */ 0200 0201 struct vidtv_psi_table_sdt { 0202 struct vidtv_psi_table_header header; 0203 __be16 network_id; /* original_network_id */ 0204 u8 reserved; 0205 struct vidtv_psi_table_sdt_service *service; 0206 } __packed; 0207 0208 /* 0209 * enum service_running_status - Status of a SDT service. 0210 * see ETSI EN 300 468 v1.15.1 section 5.2.3 table 6. 0211 */ 0212 enum service_running_status { 0213 RUNNING = 0x4, 0214 }; 0215 0216 /* 0217 * enum service_type - The type of a SDT service. 0218 * see ETSI EN 300 468 v1.15.1 section 6.2.33, table 81. 0219 */ 0220 enum service_type { 0221 /* see ETSI EN 300 468 v1.15.1 p. 77 */ 0222 DIGITAL_TELEVISION_SERVICE = 0x1, 0223 DIGITAL_RADIO_SOUND_SERVICE = 0X2, 0224 }; 0225 0226 /* 0227 * struct vidtv_psi_table_pmt_stream - A single stream in the PMT. 0228 * See ISO/IEC 13818-1 : 2000 p.46. 0229 */ 0230 struct vidtv_psi_table_pmt_stream { 0231 u8 type; 0232 __be16 bitfield; /* reserved: 3, elementary_pid: 13 */ 0233 __be16 bitfield2; /*reserved: 4, zero: 2, desc_length: 10 */ 0234 struct vidtv_psi_desc *descriptor; 0235 struct vidtv_psi_table_pmt_stream *next; 0236 } __packed; 0237 0238 /* 0239 * struct vidtv_psi_table_pmt - The Program Map Table (PMT). 0240 * See ISO/IEC 13818-1 : 2000 p.46. 0241 */ 0242 struct vidtv_psi_table_pmt { 0243 struct vidtv_psi_table_header header; 0244 __be16 bitfield; /* reserved:3, pcr_pid: 13 */ 0245 __be16 bitfield2; /* reserved: 4, zero: 2, desc_len: 10 */ 0246 struct vidtv_psi_desc *descriptor; 0247 struct vidtv_psi_table_pmt_stream *stream; 0248 } __packed; 0249 0250 /** 0251 * struct psi_write_args - Arguments for the PSI packetizer. 0252 * @dest_buf: The buffer to write into. 0253 * @from: PSI data to be copied. 0254 * @len: How much to write. 0255 * @dest_offset: where to start writing in the dest_buffer. 0256 * @pid: TS packet ID. 0257 * @new_psi_section: Set when starting a table section. 0258 * @continuity_counter: Incremented on every new packet. 0259 * @is_crc: Set when writing the CRC at the end. 0260 * @dest_buf_sz: The size of the dest_buffer 0261 * @crc: a pointer to store the crc for this chunk 0262 */ 0263 struct psi_write_args { 0264 void *dest_buf; 0265 void *from; 0266 size_t len; 0267 u32 dest_offset; 0268 u16 pid; 0269 bool new_psi_section; 0270 u8 *continuity_counter; 0271 bool is_crc; 0272 u32 dest_buf_sz; 0273 u32 *crc; 0274 }; 0275 0276 /** 0277 * struct desc_write_args - Arguments in order to write a descriptor. 0278 * @dest_buf: The buffer to write into. 0279 * @dest_offset: where to start writing in the dest_buffer. 0280 * @desc: A pointer to the descriptor 0281 * @pid: TS packet ID. 0282 * @continuity_counter: Incremented on every new packet. 0283 * @dest_buf_sz: The size of the dest_buffer 0284 * @crc: a pointer to store the crc for this chunk 0285 */ 0286 struct desc_write_args { 0287 void *dest_buf; 0288 u32 dest_offset; 0289 struct vidtv_psi_desc *desc; 0290 u16 pid; 0291 u8 *continuity_counter; 0292 u32 dest_buf_sz; 0293 u32 *crc; 0294 }; 0295 0296 /** 0297 * struct crc32_write_args - Arguments in order to write the CRC at the end of 0298 * the PSI tables. 0299 * @dest_buf: The buffer to write into. 0300 * @dest_offset: where to start writing in the dest_buffer. 0301 * @crc: the CRC value to write 0302 * @pid: TS packet ID. 0303 * @continuity_counter: Incremented on every new packet. 0304 * @dest_buf_sz: The size of the dest_buffer 0305 */ 0306 struct crc32_write_args { 0307 void *dest_buf; 0308 u32 dest_offset; 0309 __be32 crc; 0310 u16 pid; 0311 u8 *continuity_counter; 0312 u32 dest_buf_sz; 0313 }; 0314 0315 /** 0316 * struct header_write_args - Arguments in order to write the common table 0317 * header 0318 * @dest_buf: The buffer to write into. 0319 * @dest_offset: where to start writing in the dest_buffer. 0320 * @h: a pointer to the header. 0321 * @pid: TS packet ID. 0322 * @continuity_counter: Incremented on every new packet. 0323 * @dest_buf_sz: The size of the dest_buffer 0324 * @crc: a pointer to store the crc for this chunk 0325 */ 0326 struct header_write_args { 0327 void *dest_buf; 0328 u32 dest_offset; 0329 struct vidtv_psi_table_header *h; 0330 u16 pid; 0331 u8 *continuity_counter; 0332 u32 dest_buf_sz; 0333 u32 *crc; 0334 }; 0335 0336 struct vidtv_psi_desc_service *vidtv_psi_service_desc_init(struct vidtv_psi_desc *head, 0337 enum service_type service_type, 0338 char *service_name, 0339 char *provider_name); 0340 0341 struct vidtv_psi_desc_registration 0342 *vidtv_psi_registration_desc_init(struct vidtv_psi_desc *head, 0343 __be32 format_id, 0344 u8 *additional_ident_info, 0345 u32 additional_info_len); 0346 0347 struct vidtv_psi_desc_network_name 0348 *vidtv_psi_network_name_desc_init(struct vidtv_psi_desc *head, char *network_name); 0349 0350 struct vidtv_psi_desc_service_list 0351 *vidtv_psi_service_list_desc_init(struct vidtv_psi_desc *head, 0352 struct vidtv_psi_desc_service_list_entry *entry); 0353 0354 struct vidtv_psi_table_pat_program 0355 *vidtv_psi_pat_program_init(struct vidtv_psi_table_pat_program *head, 0356 u16 service_id, 0357 u16 program_map_pid); 0358 0359 struct vidtv_psi_table_pmt_stream* 0360 vidtv_psi_pmt_stream_init(struct vidtv_psi_table_pmt_stream *head, 0361 enum vidtv_psi_stream_types stream_type, 0362 u16 es_pid); 0363 0364 struct vidtv_psi_table_pat *vidtv_psi_pat_table_init(u16 transport_stream_id); 0365 0366 struct vidtv_psi_table_pmt *vidtv_psi_pmt_table_init(u16 program_number, 0367 u16 pcr_pid); 0368 0369 struct vidtv_psi_table_sdt *vidtv_psi_sdt_table_init(u16 network_id, 0370 u16 transport_stream_id); 0371 0372 struct vidtv_psi_table_sdt_service* 0373 vidtv_psi_sdt_service_init(struct vidtv_psi_table_sdt_service *head, 0374 u16 service_id, 0375 bool eit_schedule, 0376 bool eit_present_following); 0377 0378 void 0379 vidtv_psi_desc_destroy(struct vidtv_psi_desc *desc); 0380 0381 void 0382 vidtv_psi_pat_program_destroy(struct vidtv_psi_table_pat_program *p); 0383 0384 void 0385 vidtv_psi_pat_table_destroy(struct vidtv_psi_table_pat *p); 0386 0387 void 0388 vidtv_psi_pmt_stream_destroy(struct vidtv_psi_table_pmt_stream *s); 0389 0390 void 0391 vidtv_psi_pmt_table_destroy(struct vidtv_psi_table_pmt *pmt); 0392 0393 void 0394 vidtv_psi_sdt_table_destroy(struct vidtv_psi_table_sdt *sdt); 0395 0396 void 0397 vidtv_psi_sdt_service_destroy(struct vidtv_psi_table_sdt_service *service); 0398 0399 /** 0400 * vidtv_psi_sdt_service_assign - Assigns the service loop to the SDT. 0401 * @sdt: The SDT to assign to. 0402 * @service: The service loop (one or more services) 0403 * 0404 * This will free the previous service loop in the table. 0405 * This will assign ownership of the service loop to the table, i.e. the table 0406 * will free this service loop when a call to its destroy function is made. 0407 */ 0408 void 0409 vidtv_psi_sdt_service_assign(struct vidtv_psi_table_sdt *sdt, 0410 struct vidtv_psi_table_sdt_service *service); 0411 0412 /** 0413 * vidtv_psi_desc_assign - Assigns a descriptor loop at some point 0414 * @to: Where to assign this descriptor loop to 0415 * @desc: The descriptor loop that will be assigned. 0416 * 0417 * This will free the loop in 'to', if any. 0418 */ 0419 void vidtv_psi_desc_assign(struct vidtv_psi_desc **to, 0420 struct vidtv_psi_desc *desc); 0421 0422 /** 0423 * vidtv_pmt_desc_assign - Assigns a descriptor loop at some point in a PMT section. 0424 * @pmt: The PMT section that will contain the descriptor loop 0425 * @to: Where in the PMT to assign this descriptor loop to 0426 * @desc: The descriptor loop that will be assigned. 0427 * 0428 * This will free the loop in 'to', if any. 0429 * This will assign ownership of the loop to the table, i.e. the table 0430 * will free this loop when a call to its destroy function is made. 0431 */ 0432 void vidtv_pmt_desc_assign(struct vidtv_psi_table_pmt *pmt, 0433 struct vidtv_psi_desc **to, 0434 struct vidtv_psi_desc *desc); 0435 0436 /** 0437 * vidtv_sdt_desc_assign - Assigns a descriptor loop at some point in a SDT. 0438 * @sdt: The SDT that will contain the descriptor loop 0439 * @to: Where in the PMT to assign this descriptor loop to 0440 * @desc: The descriptor loop that will be assigned. 0441 * 0442 * This will free the loop in 'to', if any. 0443 * This will assign ownership of the loop to the table, i.e. the table 0444 * will free this loop when a call to its destroy function is made. 0445 */ 0446 void vidtv_sdt_desc_assign(struct vidtv_psi_table_sdt *sdt, 0447 struct vidtv_psi_desc **to, 0448 struct vidtv_psi_desc *desc); 0449 0450 /** 0451 * vidtv_psi_pat_program_assign - Assigns the program loop to the PAT. 0452 * @pat: The PAT to assign to. 0453 * @p: The program loop (one or more programs) 0454 * 0455 * This will free the previous program loop in the table. 0456 * This will assign ownership of the program loop to the table, i.e. the table 0457 * will free this program loop when a call to its destroy function is made. 0458 */ 0459 void vidtv_psi_pat_program_assign(struct vidtv_psi_table_pat *pat, 0460 struct vidtv_psi_table_pat_program *p); 0461 0462 /** 0463 * vidtv_psi_pmt_stream_assign - Assigns the stream loop to the PAT. 0464 * @pmt: The PMT to assign to. 0465 * @s: The stream loop (one or more streams) 0466 * 0467 * This will free the previous stream loop in the table. 0468 * This will assign ownership of the stream loop to the table, i.e. the table 0469 * will free this stream loop when a call to its destroy function is made. 0470 */ 0471 void vidtv_psi_pmt_stream_assign(struct vidtv_psi_table_pmt *pmt, 0472 struct vidtv_psi_table_pmt_stream *s); 0473 0474 struct vidtv_psi_desc *vidtv_psi_desc_clone(struct vidtv_psi_desc *desc); 0475 0476 /** 0477 * vidtv_psi_pmt_create_sec_for_each_pat_entry - Create a PMT section for each 0478 * program found in the PAT 0479 * @pat: The PAT to look for programs. 0480 * @pcr_pid: packet ID for the PCR to be used for the program described in this 0481 * PMT section 0482 */ 0483 struct vidtv_psi_table_pmt** 0484 vidtv_psi_pmt_create_sec_for_each_pat_entry(struct vidtv_psi_table_pat *pat, u16 pcr_pid); 0485 0486 /** 0487 * vidtv_psi_pmt_get_pid - Get the TS PID for a PMT section. 0488 * @section: The PMT section whose PID we want to retrieve. 0489 * @pat: The PAT table to look into. 0490 * 0491 * Returns: the TS PID for 'section' 0492 */ 0493 u16 vidtv_psi_pmt_get_pid(struct vidtv_psi_table_pmt *section, 0494 struct vidtv_psi_table_pat *pat); 0495 0496 /** 0497 * vidtv_psi_pat_table_update_sec_len - Recompute and update the PAT section length. 0498 * @pat: The PAT whose length is to be updated. 0499 * 0500 * This will traverse the table and accumulate the length of its components, 0501 * which is then used to replace the 'section_length' field. 0502 * 0503 * If section_length > MAX_SECTION_LEN, the operation fails. 0504 */ 0505 void vidtv_psi_pat_table_update_sec_len(struct vidtv_psi_table_pat *pat); 0506 0507 /** 0508 * vidtv_psi_pmt_table_update_sec_len - Recompute and update the PMT section length. 0509 * @pmt: The PMT whose length is to be updated. 0510 * 0511 * This will traverse the table and accumulate the length of its components, 0512 * which is then used to replace the 'section_length' field. 0513 * 0514 * If section_length > MAX_SECTION_LEN, the operation fails. 0515 */ 0516 void vidtv_psi_pmt_table_update_sec_len(struct vidtv_psi_table_pmt *pmt); 0517 0518 /** 0519 * vidtv_psi_sdt_table_update_sec_len - Recompute and update the SDT section length. 0520 * @sdt: The SDT whose length is to be updated. 0521 * 0522 * This will traverse the table and accumulate the length of its components, 0523 * which is then used to replace the 'section_length' field. 0524 * 0525 * If section_length > MAX_SECTION_LEN, the operation fails. 0526 */ 0527 void vidtv_psi_sdt_table_update_sec_len(struct vidtv_psi_table_sdt *sdt); 0528 0529 /** 0530 * struct vidtv_psi_pat_write_args - Arguments for writing a PAT table 0531 * @buf: The destination buffer. 0532 * @offset: The offset into the destination buffer. 0533 * @pat: A pointer to the PAT. 0534 * @buf_sz: The size of the destination buffer. 0535 * @continuity_counter: A pointer to the CC. Incremented on every new packet. 0536 * 0537 */ 0538 struct vidtv_psi_pat_write_args { 0539 char *buf; 0540 u32 offset; 0541 struct vidtv_psi_table_pat *pat; 0542 u32 buf_sz; 0543 u8 *continuity_counter; 0544 }; 0545 0546 /** 0547 * vidtv_psi_pat_write_into - Write PAT as MPEG-TS packets into a buffer. 0548 * @args: An instance of struct vidtv_psi_pat_write_args 0549 * 0550 * This function writes the MPEG TS packets for a PAT table into a buffer. 0551 * Calling code will usually generate the PAT via a call to its init function 0552 * and thus is responsible for freeing it. 0553 * 0554 * Return: The number of bytes written into the buffer. This is NOT 0555 * equal to the size of the PAT, since more space is needed for TS headers during TS 0556 * encapsulation. 0557 */ 0558 u32 vidtv_psi_pat_write_into(struct vidtv_psi_pat_write_args *args); 0559 0560 /** 0561 * struct vidtv_psi_sdt_write_args - Arguments for writing a SDT table 0562 * @buf: The destination buffer. 0563 * @offset: The offset into the destination buffer. 0564 * @sdt: A pointer to the SDT. 0565 * @buf_sz: The size of the destination buffer. 0566 * @continuity_counter: A pointer to the CC. Incremented on every new packet. 0567 * 0568 */ 0569 0570 struct vidtv_psi_sdt_write_args { 0571 char *buf; 0572 u32 offset; 0573 struct vidtv_psi_table_sdt *sdt; 0574 u32 buf_sz; 0575 u8 *continuity_counter; 0576 }; 0577 0578 /** 0579 * vidtv_psi_sdt_write_into - Write SDT as MPEG-TS packets into a buffer. 0580 * @args: an instance of struct vidtv_psi_sdt_write_args 0581 * 0582 * This function writes the MPEG TS packets for a SDT table into a buffer. 0583 * Calling code will usually generate the SDT via a call to its init function 0584 * and thus is responsible for freeing it. 0585 * 0586 * Return: The number of bytes written into the buffer. This is NOT 0587 * equal to the size of the SDT, since more space is needed for TS headers during TS 0588 * encapsulation. 0589 */ 0590 u32 vidtv_psi_sdt_write_into(struct vidtv_psi_sdt_write_args *args); 0591 0592 /** 0593 * struct vidtv_psi_pmt_write_args - Arguments for writing a PMT section 0594 * @buf: The destination buffer. 0595 * @offset: The offset into the destination buffer. 0596 * @pmt: A pointer to the PMT. 0597 * @pid: Program ID 0598 * @buf_sz: The size of the destination buffer. 0599 * @continuity_counter: A pointer to the CC. Incremented on every new packet. 0600 * @pcr_pid: The TS PID used for the PSI packets. All channels will share the 0601 * same PCR. 0602 */ 0603 struct vidtv_psi_pmt_write_args { 0604 char *buf; 0605 u32 offset; 0606 struct vidtv_psi_table_pmt *pmt; 0607 u16 pid; 0608 u32 buf_sz; 0609 u8 *continuity_counter; 0610 u16 pcr_pid; 0611 }; 0612 0613 /** 0614 * vidtv_psi_pmt_write_into - Write PMT as MPEG-TS packets into a buffer. 0615 * @args: an instance of struct vidtv_psi_pmt_write_args 0616 * 0617 * This function writes the MPEG TS packets for a PMT section into a buffer. 0618 * Calling code will usually generate the PMT section via a call to its init function 0619 * and thus is responsible for freeing it. 0620 * 0621 * Return: The number of bytes written into the buffer. This is NOT 0622 * equal to the size of the PMT section, since more space is needed for TS headers 0623 * during TS encapsulation. 0624 */ 0625 u32 vidtv_psi_pmt_write_into(struct vidtv_psi_pmt_write_args *args); 0626 0627 /** 0628 * vidtv_psi_find_pmt_sec - Finds the PMT section for 'program_num' 0629 * @pmt_sections: The sections to look into. 0630 * @nsections: The number of sections. 0631 * @program_num: The 'program_num' from PAT pointing to a PMT section. 0632 * 0633 * Return: A pointer to the PMT, if found, or NULL. 0634 */ 0635 struct vidtv_psi_table_pmt *vidtv_psi_find_pmt_sec(struct vidtv_psi_table_pmt **pmt_sections, 0636 u16 nsections, 0637 u16 program_num); 0638 0639 u16 vidtv_psi_get_pat_program_pid(struct vidtv_psi_table_pat_program *p); 0640 u16 vidtv_psi_pmt_stream_get_elem_pid(struct vidtv_psi_table_pmt_stream *s); 0641 0642 /** 0643 * struct vidtv_psi_table_transport - A entry in the TS loop for the NIT and/or other tables. 0644 * See ETSI 300 468 section 5.2.1 0645 * @transport_id: The TS ID being described 0646 * @network_id: The network_id that contains the TS ID 0647 * @bitfield: Contains the descriptor loop length 0648 * @descriptor: A descriptor loop 0649 * @next: Pointer to the next entry 0650 * 0651 */ 0652 struct vidtv_psi_table_transport { 0653 __be16 transport_id; 0654 __be16 network_id; 0655 __be16 bitfield; /* desc_len: 12, reserved: 4 */ 0656 struct vidtv_psi_desc *descriptor; 0657 struct vidtv_psi_table_transport *next; 0658 } __packed; 0659 0660 /** 0661 * struct vidtv_psi_table_nit - A Network Information Table (NIT). See ETSI 300 0662 * 468 section 5.2.1 0663 * @header: A PSI table header 0664 * @bitfield: Contains the network descriptor length 0665 * @descriptor: A descriptor loop describing the network 0666 * @bitfield2: Contains the transport stream loop length 0667 * @transport: The transport stream loop 0668 * 0669 */ 0670 struct vidtv_psi_table_nit { 0671 struct vidtv_psi_table_header header; 0672 __be16 bitfield; /* network_desc_len: 12, reserved:4 */ 0673 struct vidtv_psi_desc *descriptor; 0674 __be16 bitfield2; /* ts_loop_len: 12, reserved: 4 */ 0675 struct vidtv_psi_table_transport *transport; 0676 } __packed; 0677 0678 struct vidtv_psi_table_nit 0679 *vidtv_psi_nit_table_init(u16 network_id, 0680 u16 transport_stream_id, 0681 char *network_name, 0682 struct vidtv_psi_desc_service_list_entry *service_list); 0683 0684 /** 0685 * struct vidtv_psi_nit_write_args - Arguments for writing a NIT section 0686 * @buf: The destination buffer. 0687 * @offset: The offset into the destination buffer. 0688 * @nit: A pointer to the NIT 0689 * @buf_sz: The size of the destination buffer. 0690 * @continuity_counter: A pointer to the CC. Incremented on every new packet. 0691 * 0692 */ 0693 struct vidtv_psi_nit_write_args { 0694 char *buf; 0695 u32 offset; 0696 struct vidtv_psi_table_nit *nit; 0697 u32 buf_sz; 0698 u8 *continuity_counter; 0699 }; 0700 0701 /** 0702 * vidtv_psi_nit_write_into - Write NIT as MPEG-TS packets into a buffer. 0703 * @args: an instance of struct vidtv_psi_nit_write_args 0704 * 0705 * This function writes the MPEG TS packets for a NIT table into a buffer. 0706 * Calling code will usually generate the NIT via a call to its init function 0707 * and thus is responsible for freeing it. 0708 * 0709 * Return: The number of bytes written into the buffer. This is NOT 0710 * equal to the size of the NIT, since more space is needed for TS headers during TS 0711 * encapsulation. 0712 */ 0713 u32 vidtv_psi_nit_write_into(struct vidtv_psi_nit_write_args *args); 0714 0715 void vidtv_psi_nit_table_destroy(struct vidtv_psi_table_nit *nit); 0716 0717 /* 0718 * struct vidtv_psi_desc_short_event - A short event descriptor 0719 * see ETSI EN 300 468 v1.15.1 section 6.2.37 0720 */ 0721 struct vidtv_psi_table_eit_event { 0722 __be16 event_id; 0723 u8 start_time[5]; 0724 u8 duration[3]; 0725 __be16 bitfield; /* desc_length: 12, free_CA_mode: 1, running_status: 1 */ 0726 struct vidtv_psi_desc *descriptor; 0727 struct vidtv_psi_table_eit_event *next; 0728 } __packed; 0729 0730 /* 0731 * struct vidtv_psi_table_eit - A Event Information Table (EIT) 0732 * See ETSI 300 468 section 5.2.4 0733 */ 0734 struct vidtv_psi_table_eit { 0735 struct vidtv_psi_table_header header; 0736 __be16 transport_id; 0737 __be16 network_id; 0738 u8 last_segment; 0739 u8 last_table_id; 0740 struct vidtv_psi_table_eit_event *event; 0741 } __packed; 0742 0743 struct vidtv_psi_table_eit 0744 *vidtv_psi_eit_table_init(u16 network_id, 0745 u16 transport_stream_id, 0746 __be16 service_id); 0747 0748 /** 0749 * struct vidtv_psi_eit_write_args - Arguments for writing an EIT section 0750 * @buf: The destination buffer. 0751 * @offset: The offset into the destination buffer. 0752 * @eit: A pointer to the EIT 0753 * @buf_sz: The size of the destination buffer. 0754 * @continuity_counter: A pointer to the CC. Incremented on every new packet. 0755 * 0756 */ 0757 struct vidtv_psi_eit_write_args { 0758 char *buf; 0759 u32 offset; 0760 struct vidtv_psi_table_eit *eit; 0761 u32 buf_sz; 0762 u8 *continuity_counter; 0763 }; 0764 0765 /** 0766 * vidtv_psi_eit_write_into - Write EIT as MPEG-TS packets into a buffer. 0767 * @args: an instance of struct vidtv_psi_nit_write_args 0768 * 0769 * This function writes the MPEG TS packets for a EIT table into a buffer. 0770 * Calling code will usually generate the EIT via a call to its init function 0771 * and thus is responsible for freeing it. 0772 * 0773 * Return: The number of bytes written into the buffer. This is NOT 0774 * equal to the size of the EIT, since more space is needed for TS headers during TS 0775 * encapsulation. 0776 */ 0777 u32 vidtv_psi_eit_write_into(struct vidtv_psi_eit_write_args *args); 0778 0779 void vidtv_psi_eit_table_destroy(struct vidtv_psi_table_eit *eit); 0780 0781 /** 0782 * vidtv_psi_eit_table_update_sec_len - Recompute and update the EIT section length. 0783 * @eit: The EIT whose length is to be updated. 0784 * 0785 * This will traverse the table and accumulate the length of its components, 0786 * which is then used to replace the 'section_length' field. 0787 * 0788 * If section_length > EIT_MAX_SECTION_LEN, the operation fails. 0789 */ 0790 void vidtv_psi_eit_table_update_sec_len(struct vidtv_psi_table_eit *eit); 0791 0792 /** 0793 * vidtv_psi_eit_event_assign - Assigns the event loop to the EIT. 0794 * @eit: The EIT to assign to. 0795 * @e: The event loop 0796 * 0797 * This will free the previous event loop in the table. 0798 * This will assign ownership of the stream loop to the table, i.e. the table 0799 * will free this stream loop when a call to its destroy function is made. 0800 */ 0801 void vidtv_psi_eit_event_assign(struct vidtv_psi_table_eit *eit, 0802 struct vidtv_psi_table_eit_event *e); 0803 0804 struct vidtv_psi_table_eit_event 0805 *vidtv_psi_eit_event_init(struct vidtv_psi_table_eit_event *head, u16 event_id); 0806 0807 void vidtv_psi_eit_event_destroy(struct vidtv_psi_table_eit_event *e); 0808 0809 #endif // VIDTV_PSI_H
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |