1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Vidtv serves as a reference DVB driver and helps validate the existing APIs
4  * in the media subsystem. It can also aid developers working on userspace
5  * applications.
6  *
7  * This file contains the code for an AES3 (also known as AES/EBU) encoder.
8  * It is based on EBU Tech 3250 and SMPTE 302M technical documents.
9  *
10  * This encoder currently supports 16bit AES3 subframes using 16bit signed
11  * integers.
12  *
13  * Note: AU stands for Access Unit, and AAU stands for Audio Access Unit
14  *
15  * Copyright (C) 2020 Daniel W. S. Almeida
16  */
17 
18 #ifndef VIDTV_S302M_H
19 #define VIDTV_S302M_H
20 
21 #include <linux/types.h>
22 #include <asm/byteorder.h>
23 
24 #include "vidtv_encoder.h"
25 
26 /* see SMPTE 302M 2007 clause 7.3 */
27 #define VIDTV_S302M_BUF_SZ 65024
28 
29 /* see ETSI TS 102 154 v.1.2.1 clause 7.3.5 */
30 #define VIDTV_S302M_FORMAT_IDENTIFIER 0x42535344
31 
32 /**
33  * struct vidtv_s302m_ctx - s302m encoder context.
34  * @enc: A pointer to the containing encoder structure.
35  * @frame_index: The current frame in a block
36  * @au_count: The total number of access units encoded up to now
37  */
38 struct vidtv_s302m_ctx {
39 	struct vidtv_encoder *enc;
40 	u32 frame_index;
41 	u32 au_count;
42 };
43 
44 /**
45  * struct vidtv_smpte_s302m_es - s302m MPEG Elementary Stream header.
46  *
47  * See SMPTE 302M 2007 table 1.
48  */
49 struct vidtv_smpte_s302m_es {
50 	/*
51 	 *
52 	 * audio_packet_size:16;
53 	 * num_channels:2;
54 	 * channel_identification:8;
55 	 * bits_per_sample:2; // 0x0 for 16bits
56 	 * zero:4;
57 	 */
58 	__be32 bitfield;
59 } __packed;
60 
61 struct vidtv_s302m_frame_16 {
62 	u8 data[5];
63 } __packed;
64 
65 /**
66  * struct vidtv_s302m_encoder_init_args - Args for the s302m encoder.
67  *
68  * @name: A name to identify this particular instance
69  * @src_buf: The source buffer, encoder will default to a sine wave if this is NULL.
70  * @src_buf_sz: The size of the source buffer.
71  * @es_pid: The MPEG Elementary Stream PID to use.
72  * @sync: Attempt to synchronize audio with this video encoder, if not NULL.
73  * @last_sample_cb: A callback called when the encoder runs out of data.
74  * @head: Add to this chain
75  */
76 struct vidtv_s302m_encoder_init_args {
77 	char *name;
78 	void *src_buf;
79 	u32 src_buf_sz;
80 	u16 es_pid;
81 	struct vidtv_encoder *sync;
82 	void (*last_sample_cb)(u32 sample_no);
83 
84 	struct vidtv_encoder *head;
85 };
86 
87 struct vidtv_encoder
88 *vidtv_s302m_encoder_init(struct vidtv_s302m_encoder_init_args args);
89 
90 void vidtv_s302m_encoder_destroy(struct vidtv_encoder *encoder);
91 
92 #endif /* VIDTV_S302M_H */
93