18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * The Virtual DVB test driver serves as a reference DVB driver and helps 48c2ecf20Sopenharmony_ci * validate the existing APIs in the media subsystem. It can also aid 58c2ecf20Sopenharmony_ci * developers working on userspace applications. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Copyright (C) 2020 Daniel W. S. Almeida 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#ifndef VIDTV_TS_H 118c2ecf20Sopenharmony_ci#define VIDTV_TS_H 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <linux/types.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#define TS_SYNC_BYTE 0x47 168c2ecf20Sopenharmony_ci#define TS_PACKET_LEN 188 178c2ecf20Sopenharmony_ci#define TS_PAYLOAD_LEN 184 188c2ecf20Sopenharmony_ci#define TS_NULL_PACKET_PID 0x1fff 198c2ecf20Sopenharmony_ci#define TS_CC_MAX_VAL 0x0f /* 4 bits */ 208c2ecf20Sopenharmony_ci#define TS_LAST_VALID_PID 8191 218c2ecf20Sopenharmony_ci#define TS_FILL_BYTE 0xff /* the byte used in packet stuffing */ 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_cistruct vidtv_mpeg_ts_adaption { 248c2ecf20Sopenharmony_ci u8 length; 258c2ecf20Sopenharmony_ci struct { 268c2ecf20Sopenharmony_ci u8 extension:1; 278c2ecf20Sopenharmony_ci u8 private_data:1; 288c2ecf20Sopenharmony_ci u8 splicing_point:1; 298c2ecf20Sopenharmony_ci u8 OPCR:1; 308c2ecf20Sopenharmony_ci u8 PCR:1; 318c2ecf20Sopenharmony_ci u8 priority:1; 328c2ecf20Sopenharmony_ci u8 random_access:1; 338c2ecf20Sopenharmony_ci u8 discontinued:1; 348c2ecf20Sopenharmony_ci } __packed; 358c2ecf20Sopenharmony_ci u8 data[]; 368c2ecf20Sopenharmony_ci} __packed; 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_cistruct vidtv_mpeg_ts { 398c2ecf20Sopenharmony_ci u8 sync_byte; 408c2ecf20Sopenharmony_ci __be16 bitfield; /* tei: 1, payload_start:1 priority: 1, pid:13 */ 418c2ecf20Sopenharmony_ci struct { 428c2ecf20Sopenharmony_ci u8 continuity_counter:4; 438c2ecf20Sopenharmony_ci u8 payload:1; 448c2ecf20Sopenharmony_ci u8 adaptation_field:1; 458c2ecf20Sopenharmony_ci u8 scrambling:2; 468c2ecf20Sopenharmony_ci } __packed; 478c2ecf20Sopenharmony_ci struct vidtv_mpeg_ts_adaption *adaption; 488c2ecf20Sopenharmony_ci} __packed; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci/** 518c2ecf20Sopenharmony_ci * struct pcr_write_args - Arguments for the pcr_write_into function. 528c2ecf20Sopenharmony_ci * @dest_buf: The buffer to write into. 538c2ecf20Sopenharmony_ci * @dest_offset: The byte offset into the buffer. 548c2ecf20Sopenharmony_ci * @pid: The TS PID for the PCR packets. 558c2ecf20Sopenharmony_ci * @buf_sz: The size of the buffer in bytes. 568c2ecf20Sopenharmony_ci * @continuity_counter: The TS continuity_counter. 578c2ecf20Sopenharmony_ci * @pcr: A sample from the system clock. 588c2ecf20Sopenharmony_ci */ 598c2ecf20Sopenharmony_cistruct pcr_write_args { 608c2ecf20Sopenharmony_ci void *dest_buf; 618c2ecf20Sopenharmony_ci u32 dest_offset; 628c2ecf20Sopenharmony_ci u16 pid; 638c2ecf20Sopenharmony_ci u32 buf_sz; 648c2ecf20Sopenharmony_ci u8 *continuity_counter; 658c2ecf20Sopenharmony_ci u64 pcr; 668c2ecf20Sopenharmony_ci}; 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci/** 698c2ecf20Sopenharmony_ci * struct null_packet_write_args - Arguments for the null_write_into function 708c2ecf20Sopenharmony_ci * @dest_buf: The buffer to write into. 718c2ecf20Sopenharmony_ci * @dest_offset: The byte offset into the buffer. 728c2ecf20Sopenharmony_ci * @buf_sz: The size of the buffer in bytes. 738c2ecf20Sopenharmony_ci * @continuity_counter: The TS continuity_counter. 748c2ecf20Sopenharmony_ci */ 758c2ecf20Sopenharmony_cistruct null_packet_write_args { 768c2ecf20Sopenharmony_ci void *dest_buf; 778c2ecf20Sopenharmony_ci u32 dest_offset; 788c2ecf20Sopenharmony_ci u32 buf_sz; 798c2ecf20Sopenharmony_ci u8 *continuity_counter; 808c2ecf20Sopenharmony_ci}; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci/* Increment the continuity counter */ 838c2ecf20Sopenharmony_civoid vidtv_ts_inc_cc(u8 *continuity_counter); 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci/** 868c2ecf20Sopenharmony_ci * vidtv_ts_null_write_into - Write a TS null packet into a buffer. 878c2ecf20Sopenharmony_ci * @args: the arguments to use when writing. 888c2ecf20Sopenharmony_ci * 898c2ecf20Sopenharmony_ci * This function will write a null packet into a buffer. This is usually used to 908c2ecf20Sopenharmony_ci * pad TS streams. 918c2ecf20Sopenharmony_ci * 928c2ecf20Sopenharmony_ci * Return: The number of bytes written into the buffer. 938c2ecf20Sopenharmony_ci */ 948c2ecf20Sopenharmony_ciu32 vidtv_ts_null_write_into(struct null_packet_write_args args); 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci/** 978c2ecf20Sopenharmony_ci * vidtv_ts_pcr_write_into - Write a PCR packet into a buffer. 988c2ecf20Sopenharmony_ci * @args: the arguments to use when writing. 998c2ecf20Sopenharmony_ci * 1008c2ecf20Sopenharmony_ci * This function will write a PCR packet into a buffer. This is used to 1018c2ecf20Sopenharmony_ci * synchronize the clocks between encoders and decoders. 1028c2ecf20Sopenharmony_ci * 1038c2ecf20Sopenharmony_ci * Return: The number of bytes written into the buffer. 1048c2ecf20Sopenharmony_ci */ 1058c2ecf20Sopenharmony_ciu32 vidtv_ts_pcr_write_into(struct pcr_write_args args); 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci#endif //VIDTV_TS_H 108