Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Vidtv serves as a reference DVB driver and helps validate the existing APIs
0004  * in the media subsystem. It can also aid developers working on userspace
0005  * applications.
0006  *
0007  * This file contains a generic encoder type that can provide data for a stream
0008  *
0009  * Copyright (C) 2020 Daniel W. S. Almeida
0010  */
0011 
0012 #ifndef VIDTV_ENCODER_H
0013 #define VIDTV_ENCODER_H
0014 
0015 #include <linux/types.h>
0016 
0017 enum vidtv_encoder_id {
0018     /* add IDs here when implementing new encoders */
0019     S302M,
0020 };
0021 
0022 struct vidtv_access_unit {
0023     u32 num_samples;
0024     u64 pts;
0025     u64 dts;
0026     u32 nbytes;
0027     u32 offset;
0028     struct vidtv_access_unit *next;
0029 };
0030 
0031 /* Some musical notes, used by a tone generator. Values are in Hz */
0032 enum musical_notes {
0033     NOTE_SILENT = 0,
0034 
0035     NOTE_C_2 = 65,
0036     NOTE_CS_2 = 69,
0037     NOTE_D_2 = 73,
0038     NOTE_DS_2 = 78,
0039     NOTE_E_2 = 82,
0040     NOTE_F_2 = 87,
0041     NOTE_FS_2 = 93,
0042     NOTE_G_2 = 98,
0043     NOTE_GS_2 = 104,
0044     NOTE_A_2 = 110,
0045     NOTE_AS_2 = 117,
0046     NOTE_B_2 = 123,
0047     NOTE_C_3 = 131,
0048     NOTE_CS_3 = 139,
0049     NOTE_D_3 = 147,
0050     NOTE_DS_3 = 156,
0051     NOTE_E_3 = 165,
0052     NOTE_F_3 = 175,
0053     NOTE_FS_3 = 185,
0054     NOTE_G_3 = 196,
0055     NOTE_GS_3 = 208,
0056     NOTE_A_3 = 220,
0057     NOTE_AS_3 = 233,
0058     NOTE_B_3 = 247,
0059     NOTE_C_4 = 262,
0060     NOTE_CS_4 = 277,
0061     NOTE_D_4 = 294,
0062     NOTE_DS_4 = 311,
0063     NOTE_E_4 = 330,
0064     NOTE_F_4 = 349,
0065     NOTE_FS_4 = 370,
0066     NOTE_G_4 = 392,
0067     NOTE_GS_4 = 415,
0068     NOTE_A_4 = 440,
0069     NOTE_AS_4 = 466,
0070     NOTE_B_4 = 494,
0071     NOTE_C_5 = 523,
0072     NOTE_CS_5 = 554,
0073     NOTE_D_5 = 587,
0074     NOTE_DS_5 = 622,
0075     NOTE_E_5 = 659,
0076     NOTE_F_5 = 698,
0077     NOTE_FS_5 = 740,
0078     NOTE_G_5 = 784,
0079     NOTE_GS_5 = 831,
0080     NOTE_A_5 = 880,
0081     NOTE_AS_5 = 932,
0082     NOTE_B_5 = 988,
0083     NOTE_C_6 = 1047,
0084     NOTE_CS_6 = 1109,
0085     NOTE_D_6 = 1175,
0086     NOTE_DS_6 = 1245,
0087     NOTE_E_6 = 1319,
0088     NOTE_F_6 = 1397,
0089     NOTE_FS_6 = 1480,
0090     NOTE_G_6 = 1568,
0091     NOTE_GS_6 = 1661,
0092     NOTE_A_6 = 1760,
0093     NOTE_AS_6 = 1865,
0094     NOTE_B_6 = 1976,
0095     NOTE_C_7 = 2093
0096 };
0097 
0098 /**
0099  * struct vidtv_encoder - A generic encoder type.
0100  * @id: So we can cast to a concrete implementation when needed.
0101  * @name: Usually the same as the stream name.
0102  * @encoder_buf: The encoder internal buffer for the access units.
0103  * @encoder_buf_sz: The encoder buffer size, in bytes
0104  * @encoder_buf_offset: Our byte position in the encoder buffer.
0105  * @sample_count: How many samples we have encoded in total.
0106  * @access_units: encoder payload units, used for clock references
0107  * @src_buf: The source of raw data to be encoded, encoder might set a
0108  * default if null.
0109  * @src_buf_sz: size of @src_buf.
0110  * @src_buf_offset: Our position in the source buffer.
0111  * @is_video_encoder: Whether this a video encoder (as opposed to audio)
0112  * @ctx: Encoder-specific state.
0113  * @stream_id: Examples: Audio streams (0xc0-0xdf), Video streams
0114  * (0xe0-0xef).
0115  * @es_pid: The TS PID to use for the elementary stream in this encoder.
0116  * @encode: Prepare enough AUs for the given amount of time.
0117  * @clear: Clear the encoder output.
0118  * @sync: Attempt to synchronize with this encoder.
0119  * @sampling_rate_hz: The sampling rate (or fps, if video) used.
0120  * @last_sample_cb: Called when the encoder runs out of data.This is
0121  *          so the source can read data in a
0122  *          piecemeal fashion instead of having to
0123  *          provide it all at once.
0124  * @destroy: Destroy this encoder, freeing allocated resources.
0125  * @next: Next in the chain
0126  */
0127 struct vidtv_encoder {
0128     enum vidtv_encoder_id id;
0129     char *name;
0130 
0131     u8 *encoder_buf;
0132     u32 encoder_buf_sz;
0133     u32 encoder_buf_offset;
0134 
0135     u64 sample_count;
0136 
0137     struct vidtv_access_unit *access_units;
0138 
0139     void *src_buf;
0140     u32 src_buf_sz;
0141     u32 src_buf_offset;
0142 
0143     bool is_video_encoder;
0144     void *ctx;
0145 
0146     __be16 stream_id;
0147 
0148     __be16 es_pid;
0149 
0150     void *(*encode)(struct vidtv_encoder *e);
0151 
0152     u32 (*clear)(struct vidtv_encoder *e);
0153 
0154     struct vidtv_encoder *sync;
0155 
0156     u32 sampling_rate_hz;
0157 
0158     void (*last_sample_cb)(u32 sample_no);
0159 
0160     void (*destroy)(struct vidtv_encoder *e);
0161 
0162     struct vidtv_encoder *next;
0163 };
0164 
0165 #endif /* VIDTV_ENCODER_H */