Daniel W. S. Almeida f90cf6079b media: vidtv: add a bridge driver
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>
2020-09-12 09:43:12 +02:00

91 lines
2.3 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 the code for an AES3 (also known as AES/EBU) encoder.
* It is based on EBU Tech 3250 and SMPTE 302M technical documents.
*
* This encoder currently supports 16bit AES3 subframes using 16bit signed
* integers.
*
* Note: AU stands for Access Unit, and AAU stands for Audio Access Unit
*
* Copyright (C) 2020 Daniel W. S. Almeida
*/
#ifndef VIDTV_S302M_H
#define VIDTV_S302M_H
#include <linux/types.h>
#include <asm/byteorder.h>
#include "vidtv_encoder.h"
/* see SMPTE 302M 2007 clause 7.3 */
#define VIDTV_S302M_BUF_SZ 65024
/* see ETSI TS 102 154 v.1.2.1 clause 7.3.5 */
#define VIDTV_S302M_FORMAT_IDENTIFIER 0x42535344
/**
* struct vidtv_s302m_ctx - s302m encoder context.
* @enc: A pointer to the containing encoder structure.
* @frame_index: The current frame in a block
*/
struct vidtv_s302m_ctx {
struct vidtv_encoder *enc;
u32 frame_index;
};
/**
* struct vidtv_smpte_s302m_es - s302m MPEG Elementary Stream header.
*
* See SMPTE 302M 2007 table 1.
*/
struct vidtv_smpte_s302m_es {
/*
*
* audio_packet_size:16;
* num_channels:2;
* channel_identification:8;
* bits_per_sample:2; // 0x0 for 16bits
* zero:4;
*/
__be32 bitfield;
} __packed;
struct vidtv_s302m_frame_16 {
u8 data[5];
} __packed;
/**
* struct vidtv_s302m_encoder_init_args - Args for the s302m encoder.
*
* @name: A name to identify this particular instance
* @src_buf: The source buffer, encoder will default to a sine wave if this is NULL.
* @src_buf_sz: The size of the source buffer.
* @es_pid: The MPEG Elementary Stream PID to use.
* @sync: Attempt to synchronize audio with this video encoder, if not NULL.
* @last_sample_cb: A callback called when the encoder runs out of data.
* @head: Add to this chain
*/
struct vidtv_s302m_encoder_init_args {
char *name;
void *src_buf;
u32 src_buf_sz;
u16 es_pid;
struct vidtv_encoder *sync;
void (*last_sample_cb)(u32 sample_no);
struct vidtv_encoder *head;
};
struct vidtv_encoder
*vidtv_s302m_encoder_init(struct vidtv_s302m_encoder_init_args args);
void vidtv_s302m_encoder_destroy(struct vidtv_encoder *encoder);
#endif /* VIDTV_S302M_H */