f90cf6079b
Digital TV devices consist of several independent hardware components which are controlled by different drivers. Each media device is controlled by a group of cooperating drivers with the bridge driver as the main driver. This patch adds a bridge driver for the Virtual Digital TV driver [vidtv]. The bridge driver binds to the other drivers, that is, vidtv_tuner and vidtv_demod and implements the digital demux logic, providing userspace with a MPEG Transport Stream. The MPEG related code is split in the following way: - vidtv_ts: code to work with MPEG TS packets, such as TS headers, adaptation fields, PCR packets and NULL packets. - vidtv_psi: this is the PSI generator. PSI packets contain general information about a MPEG Transport Stream. A PSI generator is needed so userspace apps can retrieve information about the Transport Stream and eventually tune into a (dummy) channel. Because the generator is implemented in a separate file, it can be reused elsewhere in the media subsystem. Currently vidtv supports working with 3 PSI tables: PAT, PMT and SDT. - vidtv_pes: implements the PES logic to convert encoder data into MPEG TS packets. These can then be fed into a TS multiplexer and eventually into userspace. - vidtv_s302m: implements a S302M encoder to make it possible to insert PCM audio data in the generated MPEG Transport Stream. This shall enable passing an audio signal into userspace so it can be decoded and played by media software. - vidtv_channels: Implements a 'channel' abstraction When vidtv boots, it will create some hardcoded channels: Their services will be concatenated to populate the SDT. Their programs will be concatenated to populate the PAT For each program in the PAT, a PMT section will be created The PMT section for a channel will be assigned its streams. Every stream will have its corresponding encoder polled to produce TS packets These packets may be interleaved by the mux and then delivered to the bridge - vidtv_mux - Implements a MPEG TS mux, loosely based on the ffmpeg implementation The multiplexer is responsible for polling encoders, interleaving packets, padding the resulting stream with NULL packets if necessary and then delivering the resulting TS packets to the bridge driver so it can feed the demux. Signed-off-by: Daniel W. S. Almeida <dwlsalmeida@gmail.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
97 lines
2.5 KiB
C
97 lines
2.5 KiB
C
/* 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 a generic encoder type that can provide data for a stream
|
|
*
|
|
* Copyright (C) 2020 Daniel W. S. Almeida
|
|
*/
|
|
|
|
#ifndef VIDTV_ENCODER_H
|
|
#define VIDTV_ENCODER_H
|
|
|
|
#include <linux/types.h>
|
|
|
|
enum vidtv_encoder_id {
|
|
/* add IDs here when implementing new encoders */
|
|
S302M,
|
|
};
|
|
|
|
struct vidtv_access_unit {
|
|
u32 num_samples;
|
|
u64 pts;
|
|
u64 dts;
|
|
u32 nbytes;
|
|
u32 offset;
|
|
struct vidtv_access_unit *next;
|
|
};
|
|
|
|
/**
|
|
* struct vidtv_encoder - A generic encoder type.
|
|
* @id: So we can cast to a concrete implementation when needed.
|
|
* @name: Usually the same as the stream name.
|
|
* @encoder_buf: The encoder internal buffer for the access units.
|
|
* @encoder_buf_sz: The encoder buffer size, in bytes
|
|
* @encoder_buf_offset: Our byte position in the encoder buffer.
|
|
* @sample_count: How many samples we have encoded in total.
|
|
* @src_buf: The source of raw data to be encoded, encoder might set a
|
|
* default if null.
|
|
* @src_buf_offset: Our position in the source buffer.
|
|
* @is_video_encoder: Whether this a video encoder (as opposed to audio)
|
|
* @ctx: Encoder-specific state.
|
|
* @stream_id: Examples: Audio streams (0xc0-0xdf), Video streams
|
|
* (0xe0-0xef).
|
|
* @es_id: The TS PID to use for the elementary stream in this encoder.
|
|
* @encode: Prepare enough AUs for the given amount of time.
|
|
* @clear: Clear the encoder output.
|
|
* @sync: Attempt to synchronize with this encoder.
|
|
* @sampling_rate_hz: The sampling rate (or fps, if video) used.
|
|
* @last_sample_cb: Called when the encoder runs out of data.This is
|
|
* so the source can read data in a
|
|
* piecemeal fashion instead of having to
|
|
* provide it all at once.
|
|
* @destroy: Destroy this encoder, freeing allocated resources.
|
|
* @next: Next in the chain
|
|
*/
|
|
struct vidtv_encoder {
|
|
enum vidtv_encoder_id id;
|
|
char *name;
|
|
|
|
u8 *encoder_buf;
|
|
u32 encoder_buf_sz;
|
|
u32 encoder_buf_offset;
|
|
|
|
u64 sample_count;
|
|
|
|
struct vidtv_access_unit *access_units;
|
|
|
|
void *src_buf;
|
|
u32 src_buf_sz;
|
|
u32 src_buf_offset;
|
|
|
|
bool is_video_encoder;
|
|
void *ctx;
|
|
|
|
__be16 stream_id;
|
|
|
|
__be16 es_pid;
|
|
|
|
void *(*encode)(struct vidtv_encoder *e, u64 elapsed_time_usecs);
|
|
|
|
u32 (*clear)(struct vidtv_encoder *e);
|
|
|
|
struct vidtv_encoder *sync;
|
|
|
|
u32 sampling_rate_hz;
|
|
|
|
void (*last_sample_cb)(u32 sample_no);
|
|
|
|
void (*destroy)(struct vidtv_encoder *e);
|
|
|
|
struct vidtv_encoder *next;
|
|
};
|
|
|
|
#endif /* VIDTV_ENCODER_H */
|