51#define OFFSET(x) offsetof(Audio3dScopeContext, x)
52#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
53#define TFLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
127 f = 1.0f / tanf(fov * 0.5f *
M_PI / 180.f);
130 matrix[2][2] = -(far + near) / (far - near);
132 matrix[3][2] = -(near * far) / (far - near);
135static inline void vmultiply(
const float v[4],
const float m[4][4],
float d[4])
137 d[0] = v[0] * m[0][0] + v[1] * m[1][0] + v[2] * m[2][0] + v[3] * m[3][0];
138 d[1] = v[0] * m[0][1] + v[1] * m[1][1] + v[2] * m[2][1] + v[3] * m[3][1];
139 d[2] = v[0] * m[0][2] + v[1] * m[1][2] + v[2] * m[2][2] + v[3] * m[3][2];
140 d[3] = v[0] * m[0][3] + v[1] * m[1][3] + v[2] * m[2][3] + v[3] * m[3][3];
143static void mmultiply(
const float m2[4][4],
const float m1[4][4],
float m[4][4])
151static float vdot(
const float x[3],
const float y[3])
153 return x[0] * y[0] + x[1] * y[1] + x[2] * y[2];
160 const float yaw,
float m[4][4])
163 float sr =
sinf(roll *
M_PI / 180.f);
164 float cp =
cosf(pitch *
M_PI / 180.f);
165 float sp =
sinf(pitch *
M_PI / 180.f);
166 float cy =
cosf(yaw *
M_PI / 180.f);
167 float sy =
sinf(yaw *
M_PI / 180.f);
170 {z[0], 0.f, 0.f, 0.f },
171 { 0.f, cy, -sy, 0.f },
172 { 0.f, sy, cy, 0.f },
173 { 0.f, 0.f, 0.f, 1.f },
177 { cp, 0.f, sp, 0.f },
178 { 0.f,z[1], 0.f, 0.f },
179 {-sp, 0.f, cp, 0.f },
180 { 0.f, 0.f, 0.f, 1.f },
184 {
cr, -sr, 0.f, 0.f },
185 { sr,
cr, 0.f, 0.f },
186 { 0.f, 0.f,z[2], 0.f },
187 { 0.f, 0.f, 0.f, 1.f },
190 memset(m, 0,
sizeof(*m));
195 m[3][0] = -
vdot(m[0], eye);
196 m[3][1] = -
vdot(m[1], eye);
197 m[3][2] = -
vdot(m[2], eye);
203 const ptrdiff_t linesize =
out->linesize[0];
206 dst =
out->data[0] + y * linesize + x * 4;
218 const float half_height = (
s->h - 1) * 0.5f;
219 const float half_width = (
s->w - 1) * 0.5f;
234 for (
int y = 0; y < outlink->
h; y++)
235 memset(
out->data[0] + y *
out->linesize[0], 0, outlink->
w * 4);
239 projection_matrix(
s->fov, half_width / half_height, 0.1f, 1000000.f,
s->projection_matrix);
243 for (
int nb_frame =
s->size - 1; nb_frame >= 0; nb_frame--) {
244 const float scale = 1.f /
s->nb_samples;
252 for (
int ch = 0; ch <
channels; ch++) {
253 const float *
src = (
float *)
frame->extended_data[ch];
255 const int g = 128.f + 127.f * ch / (
channels - 1);
258 for (
int n =
frame->nb_samples - 1, nn =
s->nb_samples * nb_frame; n >= 0; n--, nn++) {
259 float v[4] = {
src[n], ch - (
channels - 1) * 0.5f, -0.1f + -nn *
scale, 1.f };
268 x = d[0] * half_width + half_width;
269 y = d[1] * half_height + half_height;
271 if (x >=
w || y >=
h || x < 0 || y < 0)
281 memmove(&
s->frames[1], &
s->frames[0], 59 *
sizeof(
AVFrame *));
318 for (
int n = 0; n < 60; n++)
339 .p.name =
"a3dscope",
341 .p.priv_class = &a3dscope_class,
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static enum AVSampleFormat sample_fmts[]
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static int config_input(AVFilterLink *inlink)
const FFFilter ff_avf_a3dscope
static AVFormatContext * ctx
simple assert() macros that are a bit more flexible than ISO C assert().
static const AVFilterPad audio3dscope_outputs[]
static float vdot(const float x[3], const float y[3])
static int config_input(AVFilterLink *inlink)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static void view_matrix(const float eye[3], const float z[3], const float roll, const float pitch, const float yaw, float m[4][4])
static void draw_dot(AVFrame *out, unsigned x, unsigned y, float z, int r, int g, int b)
static const AVOption a3dscope_options[]
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static int activate(AVFilterContext *ctx)
static void mmultiply(const float m2[4][4], const float m1[4][4], float m[4][4])
static av_cold void uninit(AVFilterContext *ctx)
static const AVFilterPad audio3dscope_inputs[]
static void vmultiply(const float v[4], const float m[4][4], float d[4])
static int config_output(AVFilterLink *outlink)
static void projection_matrix(float fov, float a, float near, float far, float matrix[4][4])
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max, AVFrame **rframe)
Take samples from the link's FIFO and update the link's stats.
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
int ff_inlink_queued_samples(AVFilterLink *link)
Main libavfilter public API header.
Public libavutil channel layout APIs header.
@ AV_OPT_TYPE_IMAGE_SIZE
Underlying C type is two consecutive integers.
@ AV_OPT_TYPE_VIDEO_RATE
Underlying C type is AVRational.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_FLTP
float, planar
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
static int config_output(AVBitStreamFilterLink *outlink)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define FF_FILTER_FORWARD_WANTED(outlink, inlink)
Forward the frame_wanted_out flag from an output link to an input link.
#define FF_FILTER_FORWARD_STATUS(inlink, outlink)
Acknowledge the status on an input link and forward it to an output link.
#define FFERROR_NOT_READY
Filters implementation helper functions and internal structures.
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
static FilterLink * ff_filter_link(AVFilterLink *link)
#define AVFILTER_DEFINE_CLASS(fname)
#define FILTER_QUERY_FUNC2(func)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Describe the class of an AVClass context structure.
void * priv
private data for use by the filter
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source filter
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
int sample_rate
samples per second
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
AVFilterContext * dst
dest filter
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Rational number (pair of numerator and denominator).
float projection_matrix[4][4]
Link properties exposed to filter code, but not external callers.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable.
static double cr(void *priv, double x, double y)
static void zoom(float *u, float *v, float amount)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.