162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Vidtv serves as a reference DVB driver and helps validate the existing APIs
462306a36Sopenharmony_ci * in the media subsystem. It can also aid developers working on userspace
562306a36Sopenharmony_ci * applications.
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * This file contains the code for a 'channel' abstraction.
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci * When vidtv boots, it will create some hardcoded channels.
1062306a36Sopenharmony_ci * Their services will be concatenated to populate the SDT.
1162306a36Sopenharmony_ci * Their programs will be concatenated to populate the PAT
1262306a36Sopenharmony_ci * Their events will be concatenated to populate the EIT
1362306a36Sopenharmony_ci * For each program in the PAT, a PMT section will be created
1462306a36Sopenharmony_ci * The PMT section for a channel will be assigned its streams.
1562306a36Sopenharmony_ci * Every stream will have its corresponding encoder polled to produce TS packets
1662306a36Sopenharmony_ci * These packets may be interleaved by the mux and then delivered to the bridge
1762306a36Sopenharmony_ci *
1862306a36Sopenharmony_ci *
1962306a36Sopenharmony_ci * Copyright (C) 2020 Daniel W. S. Almeida
2062306a36Sopenharmony_ci */
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci#ifndef VIDTV_CHANNEL_H
2362306a36Sopenharmony_ci#define VIDTV_CHANNEL_H
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci#include <linux/types.h>
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci#include "vidtv_encoder.h"
2862306a36Sopenharmony_ci#include "vidtv_mux.h"
2962306a36Sopenharmony_ci#include "vidtv_psi.h"
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci/**
3262306a36Sopenharmony_ci * struct vidtv_channel - A 'channel' abstraction
3362306a36Sopenharmony_ci *
3462306a36Sopenharmony_ci * When vidtv boots, it will create some hardcoded channels.
3562306a36Sopenharmony_ci * Their services will be concatenated to populate the SDT.
3662306a36Sopenharmony_ci * Their programs will be concatenated to populate the PAT
3762306a36Sopenharmony_ci * For each program in the PAT, a PMT section will be created
3862306a36Sopenharmony_ci * The PMT section for a channel will be assigned its streams.
3962306a36Sopenharmony_ci * Every stream will have its corresponding encoder polled to produce TS packets
4062306a36Sopenharmony_ci * These packets may be interleaved by the mux and then delivered to the bridge
4162306a36Sopenharmony_ci *
4262306a36Sopenharmony_ci * @name: name of the channel
4362306a36Sopenharmony_ci * @transport_stream_id: a number to identify the TS, chosen at will.
4462306a36Sopenharmony_ci * @service: A _single_ service. Will be concatenated into the SDT.
4562306a36Sopenharmony_ci * @program_num: The link between PAT, PMT and SDT.
4662306a36Sopenharmony_ci * @program: A _single_ program with one or more streams associated with it.
4762306a36Sopenharmony_ci * Will be concatenated into the PAT.
4862306a36Sopenharmony_ci * @streams: A stream loop used to populate the PMT section for 'program'
4962306a36Sopenharmony_ci * @encoders: A encoder loop. There must be one encoder for each stream.
5062306a36Sopenharmony_ci * @events: Optional event information. This will feed into the EIT.
5162306a36Sopenharmony_ci * @next: Optionally chain this channel.
5262306a36Sopenharmony_ci */
5362306a36Sopenharmony_cistruct vidtv_channel {
5462306a36Sopenharmony_ci	char *name;
5562306a36Sopenharmony_ci	u16 transport_stream_id;
5662306a36Sopenharmony_ci	struct vidtv_psi_table_sdt_service *service;
5762306a36Sopenharmony_ci	u16 program_num;
5862306a36Sopenharmony_ci	struct vidtv_psi_table_pat_program *program;
5962306a36Sopenharmony_ci	struct vidtv_psi_table_pmt_stream *streams;
6062306a36Sopenharmony_ci	struct vidtv_encoder *encoders;
6162306a36Sopenharmony_ci	struct vidtv_psi_table_eit_event *events;
6262306a36Sopenharmony_ci	struct vidtv_channel *next;
6362306a36Sopenharmony_ci};
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci/**
6662306a36Sopenharmony_ci * vidtv_channel_si_init - Init the PSI tables from the channels in the mux
6762306a36Sopenharmony_ci * @m: The mux containing the channels.
6862306a36Sopenharmony_ci */
6962306a36Sopenharmony_ciint vidtv_channel_si_init(struct vidtv_mux *m);
7062306a36Sopenharmony_civoid vidtv_channel_si_destroy(struct vidtv_mux *m);
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci/**
7362306a36Sopenharmony_ci * vidtv_channels_init - Init hardcoded, fake 'channels'.
7462306a36Sopenharmony_ci * @m: The mux to store the channels into.
7562306a36Sopenharmony_ci */
7662306a36Sopenharmony_ciint vidtv_channels_init(struct vidtv_mux *m);
7762306a36Sopenharmony_cistruct vidtv_channel
7862306a36Sopenharmony_ci*vidtv_channel_s302m_init(struct vidtv_channel *head, u16 transport_stream_id);
7962306a36Sopenharmony_civoid vidtv_channels_destroy(struct vidtv_mux *m);
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci#endif //VIDTV_CHANNEL_H
82