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 * @access_units: encoder payload units, used for clock references
107 * @src_buf: The source of raw data to be encoded, encoder might set a
109 * @src_buf_sz: size of @src_buf.
110 * @src_buf_offset: Our position in the source buffer.
111 * @is_video_encoder: Whether this a video encoder (as opposed to audio)
112 * @ctx: Encoder-specific state.
113 * @stream_id: Examples: Audio streams (0xc0-0xdf), Video streams
115 * @es_pid: The TS PID to use for the elementary stream in this encoder.
116 * @encode: Prepare enough AUs for the given amount of time.
117 * @clear: Clear the encoder output.
118 * @sync: Attempt to synchronize with this encoder.
119 * @sampling_rate_hz: The sampling rate (or fps, if video) used.
120 * @last_sample_cb: Called when the encoder runs out of data.This is
121 * so the source can read data in a
122 * piecemeal fashion instead of having to
123 * provide it all at once.
124 * @destroy: Destroy this encoder, freeing allocated resources.
125 * @next: Next in the chain
127 struct vidtv_encoder
{
128 enum vidtv_encoder_id id
;
133 u32 encoder_buf_offset
;
137 struct vidtv_access_unit
*access_units
;
143 bool is_video_encoder
;
150 void *(*encode
)(struct vidtv_encoder
*e
);
152 u32 (*clear
)(struct vidtv_encoder
*e
);
154 struct vidtv_encoder
*sync
;
156 u32 sampling_rate_hz
;
158 void (*last_sample_cb
)(u32 sample_no
);
160 void (*destroy
)(struct vidtv_encoder
*e
);
162 struct vidtv_encoder
*next
;
165 #endif /* VIDTV_ENCODER_H */