/* SPDX-License-Identifier: GPL-2.0 */ /* * Vidtv serves as a reference DVB driver and helps validate the existing APIs * in the media subsystem. It can also aid developers working on userspace * applications. * * This file contains the logic to translate the ES data for one access unit * from an encoder into MPEG TS packets. It does so by first encapsulating it * with a PES header and then splitting it into TS packets. * * Copyright (C) 2020 Daniel W. S. Almeida */ #ifndef VIDTV_PES_H #define VIDTV_PES_H #include <linux/types.h> #include "vidtv_common.h" #define PES_MAX_LEN … #define PES_START_CODE_PREFIX … /* Used when sending PTS, but not DTS */ struct vidtv_pes_optional_pts { … } __packed; /* Used when sending both PTS and DTS */ struct vidtv_pes_optional_pts_dts { … } __packed; /* PES optional flags */ struct vidtv_pes_optional { … } __packed; /* The PES header */ struct vidtv_mpeg_pes { … } __packed; /** * struct pes_header_write_args - Arguments to write a PES header. * @dest_buf: The buffer to write into. * @dest_offset: where to start writing in the dest_buffer. * @dest_buf_sz: The size of the dest_buffer * @encoder_id: Encoder id (see vidtv_encoder.h) * @send_pts: Should we send PTS? * @pts: PTS value to send. * @send_dts: Should we send DTS? * @dts: DTS value to send. * @stream_id: The stream id to use. Ex: Audio streams (0xc0-0xdf), Video * streams (0xe0-0xef). * @n_pes_h_s_bytes: Padding bytes. Might be used by an encoder if needed, gets * discarded by the decoder. * @access_unit_len: The size of _one_ access unit (with any headers it might need) */ struct pes_header_write_args { … }; /** * struct pes_ts_header_write_args - Arguments to write a TS header. * @dest_buf: The buffer to write into. * @dest_offset: where to start writing in the dest_buffer. * @dest_buf_sz: The size of the dest_buffer * @pid: The PID to use for the TS packets. * @continuity_counter: Incremented on every new TS packet. * @wrote_pes_header: Flag to indicate that the PES header was written * @n_stuffing_bytes: Padding bytes. Might be used by an encoder if needed, gets * discarded by the decoder. * @pcr: counter driven by a 27Mhz clock. */ struct pes_ts_header_write_args { … }; /** * struct pes_write_args - Arguments for the packetizer. * @dest_buf: The buffer to write into. * @from: A pointer to the encoder buffer containing one access unit. * @access_unit_len: The size of _one_ access unit (with any headers it might need) * @dest_offset: where to start writing in the dest_buffer. * @dest_buf_sz: The size of the dest_buffer * @pid: The PID to use for the TS packets. * @encoder_id: Encoder id (see vidtv_encoder.h) * @continuity_counter: Incremented on every new TS packet. * @stream_id: The stream id to use. Ex: Audio streams (0xc0-0xdf), Video * streams (0xe0-0xef). * @send_pts: Should we send PTS? * @pts: PTS value to send. * @send_dts: Should we send DTS? * @dts: DTS value to send. * @n_pes_h_s_bytes: Padding bytes. Might be used by an encoder if needed, gets * discarded by the decoder. * @pcr: counter driven by a 27Mhz clock. */ struct pes_write_args { … }; /** * vidtv_pes_write_into - Write a PES packet as MPEG-TS packets into a buffer. * @args: The args to use when writing * * This function translate the ES data for one access unit * from an encoder into MPEG TS packets. It does so by first encapsulating it * with a PES header and then splitting it into TS packets. * * The data is then written into the buffer pointed to by 'args.buf' * * Return: The number of bytes written into the buffer. This is usually NOT * equal to the size of the access unit, since we need space for PES headers, TS headers * and padding bytes, if any. */ u32 vidtv_pes_write_into(struct pes_write_args *args); #endif // VIDTV_PES_H