1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * The Virtual DVB test driver serves as a reference DVB driver and helps 4 * validate the existing APIs in the media subsystem. It can also aid 5 * developers working on userspace applications. 6 * 7 * Copyright (C) 2020 Daniel W. S. Almeida 8 */ 9 10 #ifndef VIDTV_TS_H 11 #define VIDTV_TS_H 12 13 #include <linux/types.h> 14 #include <asm/byteorder.h> 15 16 #define TS_SYNC_BYTE 0x47 17 #define TS_PACKET_LEN 188 18 #define TS_PAYLOAD_LEN 184 19 #define TS_NULL_PACKET_PID 0x1fff 20 #define TS_CC_MAX_VAL 0x0f /* 4 bits */ 21 #define TS_LAST_VALID_PID 8191 22 #define TS_FILL_BYTE 0xff /* the byte used in packet stuffing */ 23 24 struct vidtv_mpeg_ts_adaption { 25 u8 length; 26 struct { 27 u8 extension:1; 28 u8 private_data:1; 29 u8 splicing_point:1; 30 u8 OPCR:1; 31 u8 PCR:1; 32 u8 priority:1; 33 u8 random_access:1; 34 u8 discontinued:1; 35 } __packed; 36 u8 data[]; 37 } __packed; 38 39 struct vidtv_mpeg_ts { 40 u8 sync_byte; 41 __be16 bitfield; /* tei: 1, payload_start:1 priority: 1, pid:13 */ 42 struct { 43 u8 continuity_counter:4; 44 u8 payload:1; 45 u8 adaptation_field:1; 46 u8 scrambling:2; 47 } __packed; 48 struct vidtv_mpeg_ts_adaption adaption[]; 49 } __packed; 50 51 /** 52 * struct pcr_write_args - Arguments for the pcr_write_into function. 53 * @dest_buf: The buffer to write into. 54 * @dest_offset: The byte offset into the buffer. 55 * @pid: The TS PID for the PCR packets. 56 * @buf_sz: The size of the buffer in bytes. 57 * @countinuity_counter: The TS continuity_counter. 58 * @pcr: A sample from the system clock. 59 */ 60 struct pcr_write_args { 61 void *dest_buf; 62 u32 dest_offset; 63 u16 pid; 64 u32 buf_sz; 65 u8 *continuity_counter; 66 u64 pcr; 67 }; 68 69 /** 70 * struct null_packet_write_args - Arguments for the null_write_into function 71 * @dest_buf: The buffer to write into. 72 * @dest_offset: The byte offset into the buffer. 73 * @buf_sz: The size of the buffer in bytes. 74 * @countinuity_counter: The TS continuity_counter. 75 */ 76 struct null_packet_write_args { 77 void *dest_buf; 78 u32 dest_offset; 79 u32 buf_sz; 80 u8 *continuity_counter; 81 }; 82 83 /* Increment the continuity counter */ 84 void vidtv_ts_inc_cc(u8 *continuity_counter); 85 86 /** 87 * vidtv_ts_null_write_into - Write a TS null packet into a buffer. 88 * @args: the arguments to use when writing. 89 * 90 * This function will write a null packet into a buffer. This is usually used to 91 * pad TS streams. 92 * 93 * Return: The number of bytes written into the buffer. 94 */ 95 u32 vidtv_ts_null_write_into(struct null_packet_write_args args); 96 97 /** 98 * vidtv_ts_pcr_write_into - Write a PCR packet into a buffer. 99 * @args: the arguments to use when writing. 100 * 101 * This function will write a PCR packet into a buffer. This is used to 102 * synchronize the clocks between encoders and decoders. 103 * 104 * Return: The number of bytes written into the buffer. 105 */ 106 u32 vidtv_ts_pcr_write_into(struct pcr_write_args args); 107 108 #endif //VIDTV_TS_H 109