Go to the documentation of this file.
26 #include "config_components.h"
93 int16_t *prev_y,
const uint8_t
color[4],
int h);
103 #define OFFSET(x) offsetof(ShowWavesContext, x)
104 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
118 {
"colors",
"set channels colors",
OFFSET(colors),
AV_OPT_TYPE_STRING, {.str =
"red|green|blue|yellow|orange|lime|pink|magenta|brown" }, 0, 0,
FLAGS },
227 const uint8_t
color[4],
int h)
230 buf[
h * linesize + 0] +=
color[0];
231 buf[
h * linesize + 1] +=
color[1];
232 buf[
h * linesize + 2] +=
color[2];
233 buf[
h * linesize + 3] +=
color[3];
239 const uint8_t
color[4],
int h)
242 buf[
h * linesize + 0] =
color[0];
243 buf[
h * linesize + 1] =
color[1];
244 buf[
h * linesize + 2] =
color[2];
245 buf[
h * linesize + 3] =
color[3];
251 const uint8_t
color[4],
int h)
257 FFSWAP(int16_t, start, end);
258 for (k = start; k < end; k++) {
259 buf[k * linesize + 0] +=
color[0];
260 buf[k * linesize + 1] +=
color[1];
261 buf[k * linesize + 2] +=
color[2];
262 buf[k * linesize + 3] +=
color[3];
268 const uint8_t
color[4],
int h)
274 FFSWAP(int16_t, start, end);
275 for (k = start; k < end; k++) {
276 buf[k * linesize + 0] =
color[0];
277 buf[k * linesize + 1] =
color[1];
278 buf[k * linesize + 2] =
color[2];
279 buf[k * linesize + 3] =
color[3];
285 const uint8_t
color[4],
int h)
289 buf[
h * linesize + 0] +=
color[0];
290 buf[
h * linesize + 1] +=
color[1];
291 buf[
h * linesize + 2] +=
color[2];
292 buf[
h * linesize + 3] +=
color[3];
293 if (*prev_y &&
h != *prev_y) {
297 FFSWAP(int16_t, start, end);
298 for (k = start + 1; k < end; k++) {
299 buf[k * linesize + 0] +=
color[0];
300 buf[k * linesize + 1] +=
color[1];
301 buf[k * linesize + 2] +=
color[2];
302 buf[k * linesize + 3] +=
color[3];
311 const uint8_t
color[4],
int h)
315 buf[
h * linesize + 0] =
color[0];
316 buf[
h * linesize + 1] =
color[1];
317 buf[
h * linesize + 2] =
color[2];
318 buf[
h * linesize + 3] =
color[3];
319 if (*prev_y &&
h != *prev_y) {
323 FFSWAP(int16_t, start, end);
324 for (k = start + 1; k < end; k++) {
325 buf[k * linesize + 0] =
color[0];
326 buf[k * linesize + 1] =
color[1];
327 buf[k * linesize + 2] =
color[2];
328 buf[k * linesize + 3] =
color[3];
337 const uint8_t
color[4],
int h)
340 const int start = (
height -
h) / 2;
341 const int end = start +
h;
342 for (k = start; k < end; k++) {
343 buf[k * linesize + 0] +=
color[0];
344 buf[k * linesize + 1] +=
color[1];
345 buf[k * linesize + 2] +=
color[2];
346 buf[k * linesize + 3] +=
color[3];
351 const uint8_t
color[4],
int h)
354 const int start = (
height -
h) / 2;
355 const int end = start +
h;
356 for (k = start; k < end; k++) {
357 buf[k * linesize + 0] =
color[0];
358 buf[k * linesize + 1] =
color[1];
359 buf[k * linesize + 2] =
color[2];
360 buf[k * linesize + 3] =
color[3];
366 const uint8_t
color[4],
int h)
369 buf[
h * linesize] +=
color[0];
374 const uint8_t
color[4],
int h)
380 FFSWAP(int16_t, start, end);
381 for (k = start; k < end; k++)
382 buf[k * linesize] +=
color[0];
387 const uint8_t
color[4],
int h)
391 buf[
h * linesize] +=
color[0];
392 if (*prev_y &&
h != *prev_y) {
396 FFSWAP(int16_t, start, end);
397 for (k = start + 1; k < end; k++)
398 buf[k * linesize] +=
color[0];
406 const uint8_t
color[4],
int h)
409 const int start = (
height -
h) / 2;
410 const int end = start +
h;
411 for (k = start; k < end; k++)
412 buf[k * linesize] +=
color[0];
420 int nb_channels =
inlink->ch_layout.nb_channels;
421 char *colors, *saveptr =
NULL;
436 outlink->
w = showwaves->
w;
437 outlink->
h = showwaves->
h;
449 switch (outlink->
format) {
451 switch (showwaves->
mode) {
462 switch (showwaves->
mode) {
474 switch (showwaves->
scale) {
476 switch (showwaves->
mode) {
486 switch (showwaves->
mode) {
496 switch (showwaves->
mode) {
506 switch (showwaves->
mode) {
527 x = 255 / ((showwaves->
split_channels ? 1 : nb_channels) * showwaves->
n);
532 uint8_t fg[4] = { 0xff, 0xff, 0xff, 0xff };
534 for (ch = 0; ch < nb_channels; ch++) {
540 showwaves->
fg[4*ch + 0] = fg[0] * x / 255.;
541 showwaves->
fg[4*ch + 1] = fg[1] * x / 255.;
542 showwaves->
fg[4*ch + 2] = fg[2] * x / 255.;
543 showwaves->
fg[4*ch + 3] = fg[3] * x / 255.;
546 for (ch = 0; ch < nb_channels; ch++)
547 showwaves->
fg[4 * ch + 0] = x;
559 int nb_channels =
inlink->ch_layout.nb_channels;
565 for (
i = 0;
i < nb_channels;
i++)
575 int64_t n = 0, column_max_samples = showwaves->
total_samples / outlink->
w;
576 int64_t remaining_samples = showwaves->
total_samples - (column_max_samples * outlink->
w);
577 int64_t last_column_samples = column_max_samples + remaining_samples;
580 const int nb_channels =
inlink->ch_layout.nb_channels;
581 const int ch_height = showwaves->
split_channels ? outlink->
h / nb_channels : outlink->
h;
582 const int linesize =
out->linesize[0];
583 const int pixstep = showwaves->
pixstep;
585 int64_t *sum = showwaves->
sum;
587 if (column_max_samples == 0) {
592 av_log(
ctx,
AV_LOG_DEBUG,
"Create frame averaging %"PRId64
" samples per column\n", column_max_samples);
594 memset(sum, 0, nb_channels);
599 const int16_t *p = (
const int16_t *)
frame->data[0];
602 int64_t max_samples = col == outlink->
w - 1 ? last_column_samples: column_max_samples;
607 for (ch = 0; ch < nb_channels; ch++)
608 sum[ch] +=
abs(p[ch +
i*nb_channels]);
611 for (ch = 0; ch < nb_channels; ch++)
612 sum[ch] =
FFMAX(sum[ch],
abs(p[ch +
i*nb_channels]));
617 if (n == max_samples) {
618 for (ch = 0; ch < nb_channels; ch++) {
620 uint8_t *buf =
out->data[0] + col * pixstep;
624 buf += ch*ch_height*linesize;
627 showwaves->
draw_sample(buf, ch_height, linesize, &showwaves->
buf_idy[ch], &showwaves->
fg[ch * 4],
h);
667 out->width = outlink->
w;
668 out->height = outlink->
h;
672 for (j = 0; j < outlink->
h; j++)
673 memset(
out->data[0] + j*
out->linesize[0], 0, outlink->
w * showwaves->
pixstep);
682 if (!strcmp(
ctx->filter->name,
"showwavespic")) {
690 #if CONFIG_SHOWWAVES_FILTER
699 int16_t *p = (int16_t *)insamples->
data[0];
700 int nb_channels =
inlink->ch_layout.nb_channels;
702 const int pixstep = showwaves->
pixstep;
703 const int n = showwaves->
n;
704 const int ch_height = showwaves->
split_channels ? outlink->
h / nb_channels : outlink->
h;
707 for (
i = 0;
i < nb_samples;
i++) {
714 for (j = 0; j < nb_channels; j++) {
715 uint8_t *buf = outpicref->
data[0] + showwaves->
buf_idx * pixstep;
716 const int linesize = outpicref->
linesize[0];
720 buf += j*ch_height*linesize;
721 h = showwaves->
get_h(*p++, ch_height);
723 &showwaves->
buf_idy[j], &showwaves->
fg[j * 4],
h);
731 if (showwaves->
buf_idx == showwaves->
w ||
749 const int nb_samples = showwaves->
n * outlink->
w;
758 return showwaves_filter_frame(
inlink, in);
791 .priv_class = &showwaves_class,
794 #endif // CONFIG_SHOWWAVES_FILTER
796 #if CONFIG_SHOWWAVESPIC_FILTER
798 #define OFFSET(x) offsetof(ShowWavesContext, x)
799 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
801 static const AVOption showwavespic_options[] = {
805 {
"colors",
"set channels colors",
OFFSET(colors),
AV_OPT_TYPE_STRING, {.str =
"red|green|blue|yellow|orange|lime|pink|magenta|brown" }, 0, 0,
FLAGS },
841 int16_t *p = (int16_t *)insamples->
data[0];
857 f->frame = insamples;
880 .config_props = showwavespic_config_input,
881 .filter_frame = showwavespic_filter_frame,
885 static const AVFilterPad showwavespic_outputs[] = {
895 .
name =
"showwavespic",
903 .priv_class = &showwavespic_class,
906 #endif // CONFIG_SHOWWAVESPIC_FILTER
#define FF_ALLOCZ_TYPED_ARRAY(p, nelem)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
A list of supported channel layouts.
AVPixelFormat
Pixel format.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static int get_cbrt_h(int16_t sample, int height)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static enum AVSampleFormat sample_fmts[]
enum MovChannelLayoutTag * layouts
#define AVERROR_EOF
End of file.
int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, void *log_ctx)
Put the RGBA values that correspond to color_string in rgba_color.
@ AV_OPT_TYPE_VIDEO_RATE
offset must point to AVRational
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
int(* get_h)(int16_t sample, int height)
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
static void draw_sample_point_rgba_scale(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
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).
#define FILTER_QUERY_FUNC(func)
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
#define AV_LOG_VERBOSE
Detailed information.
static int get_cbrt_h2(int16_t sample, int height)
static const AVOption showwaves_options[]
AVFILTER_DEFINE_CLASS(showwaves)
const char * name
Filter name.
static int get_sqrt_h2(int16_t sample, int height)
A link between two filters.
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static void draw_sample_line_rgba_scale(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
static void draw_sample_cline_rgba_full(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
static int get_log_h2(int16_t sample, int height)
void * priv
private data for use by the filter
static int get_sqrt_h(int16_t sample, int height)
static int get_lin_h2(int16_t sample, int height)
static av_always_inline float scale(float x, float s)
static int get_lin_h(int16_t sample, int height)
A filter pad used for either input or output.
static void draw_sample_point_gray(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
static void draw_sample_p2p_gray(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
struct frame_node * last_frame
static double av_q2d(AVRational a)
Convert an AVRational to a double.
struct frame_node * audio_frames
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
#define av_assert0(cond)
assert() equivalent, that is always enabled.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0,...
static enum AVPixelFormat pix_fmts[]
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static av_cold int init(AVFilterContext *ctx)
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
#define FILTER_INPUTS(array)
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static int config_output(AVFilterLink *outlink)
static int push_frame(AVFilterLink *outlink)
Describe the class of an AVClass context structure.
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.
Rational number (pair of numerator and denominator).
static int get_log_h(int16_t sample, int height)
filter_frame For filters that do not use the activate() callback
@ AV_OPT_TYPE_IMAGE_SIZE
offset must point to two consecutive integers
AVFilterLink ** inputs
array of pointers to input links
static av_cold void uninit(AVFilterContext *ctx)
const AVFilter ff_avf_showwavespic
static int request_frame(AVFilterLink *outlink)
static int query_formats(AVFilterContext *ctx)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
int draw_mode
ShowWavesDrawMode.
static void draw_sample_cline_gray(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static void draw_sample_p2p_rgba_full(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
int format
agreed upon media format
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
static AVRational av_make_q(int num, int den)
Create an AVRational.
AVFilterContext * src
source filter
AVFilterFormatsConfig incfg
Lists of supported formats / etc.
FF_FILTER_FORWARD_WANTED(outlink, inlink)
static int push_single_pic(AVFilterLink *outlink)
int nb_samples
number of audio samples (per channel) described by this frame
const AVFilter ff_avf_showwaves
#define i(width, name, range_min, range_max)
int w
agreed upon image width
#define av_malloc_array(a, b)
AVSampleFormat
Audio sample formats.
static void draw_sample_line_gray(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
@ AV_SAMPLE_FMT_S16
signed 16 bits
static void draw_sample_p2p_rgba_scale(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
const char * name
Pad name.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
void * av_calloc(size_t nmemb, size_t size)
void(* draw_sample)(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
#define FFSWAP(type, a, b)
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
int h
agreed upon image height
static void draw_sample_cline_rgba_scale(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
static int alloc_out_frame(ShowWavesContext *showwaves, const int16_t *p, const AVFilterLink *inlink, AVFilterLink *outlink, const AVFrame *in)
int ff_outlink_get_status(AVFilterLink *link)
Get the status on an output link.
char * av_strdup(const char *s)
Duplicate a string.
FF_FILTER_FORWARD_STATUS(inlink, outlink)
#define FILTER_OUTPUTS(array)
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
static void draw_sample_line_rgba_full(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
static void draw_sample_point_rgba_full(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)