1 /* SPDX-License-Identifier: GPL-2.0 */
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
7 * This file contains a generic encoder type that can provide data for a stream
9 * Copyright (C) 2020 Daniel W. S. Almeida
12 #ifndef VIDTV_ENCODER_H
13 #define VIDTV_ENCODER_H
15 #include <linux/types.h>
17 enum vidtv_encoder_id {
18 /* add IDs here when implementing new encoders */
22 struct vidtv_access_unit {
28 struct vidtv_access_unit *next;
31 /* Some musical notes, used by a tone generator. Values are in Hz */
99 * struct vidtv_encoder - A generic encoder type.
100 * @id: So we can cast to a concrete implementation when needed.
101 * @name: Usually the same as the stream name.
102 * @encoder_buf: The encoder internal buffer for the access units.
103 * @encoder_buf_sz: The encoder buffer size, in bytes
104 * @encoder_buf_offset: Our byte position in the encoder buffer.
105 * @sample_count: How many samples we have encoded in total.
106 * @src_buf: The source of raw data to be encoded, encoder might set a
108 * @src_buf_offset: Our position in the source buffer.
109 * @is_video_encoder: Whether this a video encoder (as opposed to audio)
110 * @ctx: Encoder-specific state.
111 * @stream_id: Examples: Audio streams (0xc0-0xdf), Video streams
113 * @es_id: The TS PID to use for the elementary stream in this encoder.
114 * @encode: Prepare enough AUs for the given amount of time.
115 * @clear: Clear the encoder output.
116 * @sync: Attempt to synchronize with this encoder.
117 * @sampling_rate_hz: The sampling rate (or fps, if video) used.
118 * @last_sample_cb: Called when the encoder runs out of data.This is
119 * so the source can read data in a
120 * piecemeal fashion instead of having to
121 * provide it all at once.
122 * @destroy: Destroy this encoder, freeing allocated resources.
123 * @next: Next in the chain
125 struct vidtv_encoder {
126 enum vidtv_encoder_id id;
131 u32 encoder_buf_offset;
135 struct vidtv_access_unit *access_units;
141 bool is_video_encoder;
148 void *(*encode)(struct vidtv_encoder *e);
150 u32 (*clear)(struct vidtv_encoder *e);
152 struct vidtv_encoder *sync;
154 u32 sampling_rate_hz;
156 void (*last_sample_cb)(u32 sample_no);
158 void (*destroy)(struct vidtv_encoder *e);
160 struct vidtv_encoder *next;
163 #endif /* VIDTV_ENCODER_H */