From bb82ea797fb6538308af84310118d8006b150318 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sat, 14 May 2011 13:20:52 +0200 Subject: showinfo: fix computation of Adler checksum Previously the code was computing the checksum only for the first line of each plane. --- libavfilter/vf_showinfo.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c index d512199602..30e1108b13 100644 --- a/libavfilter/vf_showinfo.c +++ b/libavfilter/vf_showinfo.c @@ -43,13 +43,19 @@ static void end_frame(AVFilterLink *inlink) AVFilterContext *ctx = inlink->dst; ShowInfoContext *showinfo = ctx->priv; AVFilterBufferRef *picref = inlink->cur_buf; - uint32_t plane_crc[4], crc = 0; - int plane; + uint32_t plane_crc[4] = {0}, crc = 0; + int i, plane, vsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_h; - for (plane = 0; plane < 4; plane++) { + for (plane = 0; picref->data[plane] && plane < 4; plane++) { size_t linesize = av_image_get_linesize(picref->format, picref->video->w, plane); - plane_crc[plane] = av_adler32_update(0 , picref->data[plane], linesize); - crc = av_adler32_update(crc, picref->data[plane], linesize); + uint8_t *data = picref->data[plane]; + int h = plane == 1 || plane == 2 ? inlink->h >> vsub : inlink->h; + + for (i = 0; i < h; i++) { + plane_crc[plane] = av_adler32_update(plane_crc[plane], data, linesize); + crc = av_adler32_update(crc, data, linesize); + data += picref->linesize[plane]; + } } av_log(ctx, AV_LOG_INFO, -- cgit v1.2.3 From 5a2ea3cffb1ca6c99244b6a9b240cdbac27a0928 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sat, 14 May 2011 15:09:54 +0200 Subject: showinfo: fix vertical align nit --- libavfilter/vf_showinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libavfilter') diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c index 30e1108b13..6568b238a7 100644 --- a/libavfilter/vf_showinfo.c +++ b/libavfilter/vf_showinfo.c @@ -89,7 +89,7 @@ AVFilter avfilter_vf_showinfo = { .get_video_buffer = avfilter_null_get_video_buffer, .start_frame = avfilter_null_start_frame, .end_frame = end_frame, - .min_perms = AV_PERM_READ, }, + .min_perms = AV_PERM_READ, }, { .name = NULL}}, .outputs = (AVFilterPad[]) {{ .name = "default", -- cgit v1.2.3 From a05d02079e0fde1ff9b6abfda79ff20b38f68439 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sat, 14 May 2011 15:19:26 +0200 Subject: showinfo: replace "CRC" by "checksum" Indeed the Adler-32 checksum, which is computed by showinfo, is not cyclic, so using the term "CRC" is wrong/confusing. --- libavfilter/vf_showinfo.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c index 6568b238a7..82aa3b9901 100644 --- a/libavfilter/vf_showinfo.c +++ b/libavfilter/vf_showinfo.c @@ -43,7 +43,7 @@ static void end_frame(AVFilterLink *inlink) AVFilterContext *ctx = inlink->dst; ShowInfoContext *showinfo = ctx->priv; AVFilterBufferRef *picref = inlink->cur_buf; - uint32_t plane_crc[4] = {0}, crc = 0; + uint32_t plane_checksum[4] = {0}, checksum = 0; int i, plane, vsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_h; for (plane = 0; picref->data[plane] && plane < 4; plane++) { @@ -52,8 +52,8 @@ static void end_frame(AVFilterLink *inlink) int h = plane == 1 || plane == 2 ? inlink->h >> vsub : inlink->h; for (i = 0; i < h; i++) { - plane_crc[plane] = av_adler32_update(plane_crc[plane], data, linesize); - crc = av_adler32_update(crc, data, linesize); + plane_checksum[plane] = av_adler32_update(plane_checksum[plane], data, linesize); + checksum = av_adler32_update(checksum, data, linesize); data += picref->linesize[plane]; } } @@ -61,7 +61,7 @@ static void end_frame(AVFilterLink *inlink) av_log(ctx, AV_LOG_INFO, "n:%d pts:%"PRId64" pts_time:%f pos:%"PRId64" " "fmt:%s sar:%d/%d s:%dx%d i:%c iskey:%d type:%c " - "crc:%u plane_crc:[%u %u %u %u]\n", + "checksum:%u plane_checksum:[%u %u %u %u]\n", showinfo->frame, picref->pts, picref ->pts * av_q2d(inlink->time_base), picref->pos, av_pix_fmt_descriptors[picref->format].name, @@ -71,7 +71,7 @@ static void end_frame(AVFilterLink *inlink) picref->video->top_field_first ? 'T' : 'B', /* Top / Bottom */ picref->video->key_frame, av_get_picture_type_char(picref->video->pict_type), - crc, plane_crc[0], plane_crc[1], plane_crc[2], plane_crc[3]); + checksum, plane_checksum[0], plane_checksum[1], plane_checksum[2], plane_checksum[3]); showinfo->frame++; avfilter_end_frame(inlink->dst->outputs[0]); -- cgit v1.2.3 From 5dc65a3d0374ffd85e5ff1c89f5917d392897920 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sat, 23 Apr 2011 19:55:59 +0200 Subject: lavfi: print key-frame and picture type information in ff_dlog_ref() Signed-off-by: Stefano Sabatini (cherry picked from commit f7bdffb09da597c5d6afff5359523370470ad072) --- libavfilter/avfilter.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 82350d1790..02915036ab 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -237,11 +237,13 @@ static void ff_dlog_ref(void *ctx, AVFilterBufferRef *ref, int end) ref->pts, ref->pos); if (ref->video) { - av_dlog(ctx, " a:%d/%d s:%dx%d i:%c", + av_dlog(ctx, " a:%d/%d s:%dx%d i:%c iskey:%d type:%c", ref->video->pixel_aspect.num, ref->video->pixel_aspect.den, ref->video->w, ref->video->h, !ref->video->interlaced ? 'P' : /* Progressive */ - ref->video->top_field_first ? 'T' : 'B'); /* Top / Bottom */ + ref->video->top_field_first ? 'T' : 'B', /* Top / Bottom */ + ref->video->key_frame, + av_get_picture_type_char(ref->video->pict_type)); } if (ref->audio) { av_dlog(ctx, " cl:%"PRId64"d sn:%d s:%d sr:%d p:%d", -- cgit v1.2.3 From ce207e050e38352541531e2f09d62c2f54680063 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Mon, 16 May 2011 20:11:50 +0200 Subject: drawtext: fix strftime() text expansion The feature was dropped after the filter was partially rewritten and recommitted. Fix issue #207. --- libavfilter/vf_drawtext.c | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index b26029bb8f..3013cc74bf 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -49,9 +49,11 @@ typedef struct { const AVClass *class; uint8_t *fontfile; ///< font to be used uint8_t *text; ///< text to be drawn - uint8_t *text_priv; ///< used to detect whether text changed + uint8_t *expanded_text; ///< used to contain the strftime()-expanded text + size_t expanded_text_size; ///< size in bytes of the expanded_text buffer int ft_load_flags; ///< flags used for loading fonts, see FT_LOAD_* FT_Vector *positions; ///< positions for each element in the text + size_t nb_positions; ///< number of elements of positions array char *textfile; ///< file with text to be drawn unsigned int x; ///< x position to start drawing text unsigned int y; ///< y position to start drawing text @@ -349,6 +351,7 @@ static av_cold void uninit(AVFilterContext *ctx) av_freep(&dtext->fontfile); av_freep(&dtext->text); + av_freep(&dtext->expanded_text); av_freep(&dtext->fontcolor_string); av_freep(&dtext->boxcolor_string); av_freep(&dtext->positions); @@ -517,7 +520,7 @@ static inline int is_newline(uint32_t c) static int draw_glyphs(DrawTextContext *dtext, AVFilterBufferRef *picref, int width, int height, const uint8_t rgbcolor[4], const uint8_t yuvcolor[4], int x, int y) { - char *text = dtext->text; + char *text = HAVE_LOCALTIME_R ? dtext->expanded_text : dtext->text; uint32_t code = 0; int i; uint8_t *p; @@ -559,45 +562,51 @@ static int draw_text(AVFilterContext *ctx, AVFilterBufferRef *picref, uint32_t code = 0, prev_code = 0; int x = 0, y = 0, i = 0, ret; int text_height, baseline; + char *text = dtext->text; uint8_t *p; - int str_w = 0; + int str_w = 0, len; int y_min = 32000, y_max = -32000; FT_Vector delta; Glyph *glyph = NULL, *prev_glyph = NULL; Glyph dummy = { 0 }; - if (dtext->text != dtext->text_priv) { #if HAVE_LOCALTIME_R time_t now = time(0); struct tm ltime; - uint8_t *buf = NULL; - int buflen = 2*strlen(dtext->text) + 1, len; + uint8_t *buf = dtext->expanded_text; + int buf_size = dtext->expanded_text_size; + + if (!buf) { + buf_size = 2*strlen(dtext->text)+1; + buf = av_malloc(buf_size); + } localtime_r(&now, <ime); - while ((buf = av_realloc(buf, buflen))) { + do { *buf = 1; - if ((len = strftime(buf, buflen, dtext->text, <ime)) != 0 || *buf == 0) + if (strftime(buf, buf_size, dtext->text, <ime) != 0 || *buf == 0) break; - buflen *= 2; - } + buf_size *= 2; + } while ((buf = av_realloc(buf, buf_size))); + if (!buf) return AVERROR(ENOMEM); - av_freep(&dtext->text); - dtext->text = dtext->text_priv = buf; -#else - dtext->text_priv = dtext->text; + text = dtext->expanded_text = buf; + dtext->expanded_text_size = buf_size; #endif - if (!(dtext->positions = av_realloc(dtext->positions, - strlen(dtext->text)*sizeof(*dtext->positions)))) + if ((len = strlen(text)) > dtext->nb_positions) { + if (!(dtext->positions = + av_realloc(dtext->positions, len*sizeof(*dtext->positions)))) return AVERROR(ENOMEM); + dtext->nb_positions = len; } x = dtext->x; y = dtext->y; /* load and cache glyphs */ - for (i = 0, p = dtext->text; *p; i++) { + for (i = 0, p = text; *p; i++) { GET_UTF8(code, *p++, continue;); /* get glyph */ @@ -614,7 +623,7 @@ static int draw_text(AVFilterContext *ctx, AVFilterBufferRef *picref, /* compute and save position for each glyph */ glyph = NULL; - for (i = 0, p = dtext->text; *p; i++) { + for (i = 0, p = text; *p; i++) { GET_UTF8(code, *p++, continue;); /* skip the \n in the sequence \r\n */ -- cgit v1.2.3 From e8ea9c21790660256942c66a74bf992287f8bb7b Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Mon, 16 May 2011 23:48:00 +0200 Subject: drawtext: reindent after the previous commit --- libavfilter/vf_drawtext.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index 3013cc74bf..4f25140130 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -571,29 +571,29 @@ static int draw_text(AVFilterContext *ctx, AVFilterBufferRef *picref, Glyph dummy = { 0 }; #if HAVE_LOCALTIME_R - time_t now = time(0); - struct tm ltime; - uint8_t *buf = dtext->expanded_text; - int buf_size = dtext->expanded_text_size; - - if (!buf) { - buf_size = 2*strlen(dtext->text)+1; - buf = av_malloc(buf_size); - } + time_t now = time(0); + struct tm ltime; + uint8_t *buf = dtext->expanded_text; + int buf_size = dtext->expanded_text_size; + + if (!buf) { + buf_size = 2*strlen(dtext->text)+1; + buf = av_malloc(buf_size); + } - localtime_r(&now, <ime); + localtime_r(&now, <ime); - do { - *buf = 1; - if (strftime(buf, buf_size, dtext->text, <ime) != 0 || *buf == 0) - break; - buf_size *= 2; - } while ((buf = av_realloc(buf, buf_size))); + do { + *buf = 1; + if (strftime(buf, buf_size, dtext->text, <ime) != 0 || *buf == 0) + break; + buf_size *= 2; + } while ((buf = av_realloc(buf, buf_size))); - if (!buf) - return AVERROR(ENOMEM); - text = dtext->expanded_text = buf; - dtext->expanded_text_size = buf_size; + if (!buf) + return AVERROR(ENOMEM); + text = dtext->expanded_text = buf; + dtext->expanded_text_size = buf_size; #endif if ((len = strlen(text)) > dtext->nb_positions) { if (!(dtext->positions = -- cgit v1.2.3 From d8c7a216024e1408a1f865227cdfd371ddbe1d59 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Mon, 16 May 2011 23:44:35 +0200 Subject: drawtext: specify union type for setting default options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix warnings of the type: vf_drawtext.c:NNN: warning: missing braces around initializer vf_drawtext.c:NNN: warning: (near initialization for ‘drawtext_options[X].default_val’) --- libavfilter/vf_drawtext.c | 58 +++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 29 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index 4f25140130..cf0eb43344 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -86,37 +86,37 @@ typedef struct { #define OFFSET(x) offsetof(DrawTextContext, x) static const AVOption drawtext_options[]= { -{"fontfile", "set font file", OFFSET(fontfile), FF_OPT_TYPE_STRING, 0, CHAR_MIN, CHAR_MAX }, -{"text", "set text", OFFSET(text), FF_OPT_TYPE_STRING, 0, CHAR_MIN, CHAR_MAX }, -{"textfile", "set text file", OFFSET(textfile), FF_OPT_TYPE_STRING, 0, CHAR_MIN, CHAR_MAX }, -{"fontcolor","set foreground color", OFFSET(fontcolor_string), FF_OPT_TYPE_STRING, 0, CHAR_MIN, CHAR_MAX }, -{"boxcolor", "set box color", OFFSET(boxcolor_string), FF_OPT_TYPE_STRING, 0, CHAR_MIN, CHAR_MAX }, -{"shadowcolor", "set shadow color", OFFSET(shadowcolor_string), FF_OPT_TYPE_STRING, 0, CHAR_MIN, CHAR_MAX }, -{"box", "set box", OFFSET(draw_box), FF_OPT_TYPE_INT, 0, 0, 1 }, -{"fontsize", "set font size", OFFSET(fontsize), FF_OPT_TYPE_INT, 16, 1, 72 }, -{"x", "set x", OFFSET(x), FF_OPT_TYPE_INT, 0, 0, INT_MAX }, -{"y", "set y", OFFSET(y), FF_OPT_TYPE_INT, 0, 0, INT_MAX }, -{"shadowx", "set x", OFFSET(shadowx), FF_OPT_TYPE_INT, 0, INT_MIN, INT_MAX }, -{"shadowy", "set y", OFFSET(shadowy), FF_OPT_TYPE_INT, 0, INT_MIN, INT_MAX }, -{"tabsize", "set tab size", OFFSET(tabsize), FF_OPT_TYPE_INT, 4, 0, INT_MAX }, +{"fontfile", "set font file", OFFSET(fontfile), FF_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX }, +{"text", "set text", OFFSET(text), FF_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX }, +{"textfile", "set text file", OFFSET(textfile), FF_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX }, +{"fontcolor","set foreground color", OFFSET(fontcolor_string), FF_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX }, +{"boxcolor", "set box color", OFFSET(boxcolor_string), FF_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX }, +{"shadowcolor", "set shadow color", OFFSET(shadowcolor_string), FF_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX }, +{"box", "set box", OFFSET(draw_box), FF_OPT_TYPE_INT, {.dbl=0}, 0, 1 }, +{"fontsize", "set font size", OFFSET(fontsize), FF_OPT_TYPE_INT, {.dbl=16}, 1, 72 }, +{"x", "set x", OFFSET(x), FF_OPT_TYPE_INT, {.dbl=0}, 0, INT_MAX }, +{"y", "set y", OFFSET(y), FF_OPT_TYPE_INT, {.dbl=0}, 0, INT_MAX }, +{"shadowx", "set x", OFFSET(shadowx), FF_OPT_TYPE_INT, {.dbl=0}, INT_MIN, INT_MAX }, +{"shadowy", "set y", OFFSET(shadowy), FF_OPT_TYPE_INT, {.dbl=0}, INT_MIN, INT_MAX }, +{"tabsize", "set tab size", OFFSET(tabsize), FF_OPT_TYPE_INT, {.dbl=4}, 0, INT_MAX }, /* FT_LOAD_* flags */ -{"ft_load_flags", "set font loading flags for libfreetype", OFFSET(ft_load_flags), FF_OPT_TYPE_FLAGS, FT_LOAD_DEFAULT|FT_LOAD_RENDER, 0, INT_MAX, 0, "ft_load_flags" }, -{"default", "set default", 0, FF_OPT_TYPE_CONST, FT_LOAD_DEFAULT, INT_MIN, INT_MAX, 0, "ft_load_flags" }, -{"no_scale", "set no_scale", 0, FF_OPT_TYPE_CONST, FT_LOAD_NO_SCALE, INT_MIN, INT_MAX, 0, "ft_load_flags" }, -{"no_hinting", "set no_hinting", 0, FF_OPT_TYPE_CONST, FT_LOAD_NO_HINTING, INT_MIN, INT_MAX, 0, "ft_load_flags" }, -{"render", "set render", 0, FF_OPT_TYPE_CONST, FT_LOAD_RENDER, INT_MIN, INT_MAX, 0, "ft_load_flags" }, -{"no_bitmap", "set no_bitmap", 0, FF_OPT_TYPE_CONST, FT_LOAD_NO_BITMAP, INT_MIN, INT_MAX, 0, "ft_load_flags" }, -{"vertical_layout", "set vertical_layout", 0, FF_OPT_TYPE_CONST, FT_LOAD_VERTICAL_LAYOUT, INT_MIN, INT_MAX, 0, "ft_load_flags" }, -{"force_autohint", "set force_autohint", 0, FF_OPT_TYPE_CONST, FT_LOAD_FORCE_AUTOHINT, INT_MIN, INT_MAX, 0, "ft_load_flags" }, -{"crop_bitmap", "set crop_bitmap", 0, FF_OPT_TYPE_CONST, FT_LOAD_CROP_BITMAP, INT_MIN, INT_MAX, 0, "ft_load_flags" }, -{"pedantic", "set pedantic", 0, FF_OPT_TYPE_CONST, FT_LOAD_PEDANTIC, INT_MIN, INT_MAX, 0, "ft_load_flags" }, -{"ignore_global_advance_width", "set ignore_global_advance_width", 0, FF_OPT_TYPE_CONST, FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH, INT_MIN, INT_MAX, 0, "ft_load_flags" }, -{"no_recurse", "set no_recurse", 0, FF_OPT_TYPE_CONST, FT_LOAD_NO_RECURSE, INT_MIN, INT_MAX, 0, "ft_load_flags" }, -{"ignore_transform", "set ignore_transform", 0, FF_OPT_TYPE_CONST, FT_LOAD_IGNORE_TRANSFORM, INT_MIN, INT_MAX, 0, "ft_load_flags" }, -{"monochrome", "set monochrome", 0, FF_OPT_TYPE_CONST, FT_LOAD_MONOCHROME, INT_MIN, INT_MAX, 0, "ft_load_flags" }, -{"linear_design", "set linear_design", 0, FF_OPT_TYPE_CONST, FT_LOAD_LINEAR_DESIGN, INT_MIN, INT_MAX, 0, "ft_load_flags" }, -{"no_autohint", "set no_autohint", 0, FF_OPT_TYPE_CONST, FT_LOAD_NO_AUTOHINT, INT_MIN, INT_MAX, 0, "ft_load_flags" }, +{"ft_load_flags", "set font loading flags for libfreetype", OFFSET(ft_load_flags), FF_OPT_TYPE_FLAGS, {.dbl=FT_LOAD_DEFAULT|FT_LOAD_RENDER}, 0, INT_MAX, 0, "ft_load_flags" }, +{"default", "set default", 0, FF_OPT_TYPE_CONST, {.dbl=FT_LOAD_DEFAULT}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, +{"no_scale", "set no_scale", 0, FF_OPT_TYPE_CONST, {.dbl=FT_LOAD_NO_SCALE}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, +{"no_hinting", "set no_hinting", 0, FF_OPT_TYPE_CONST, {.dbl=FT_LOAD_NO_HINTING}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, +{"render", "set render", 0, FF_OPT_TYPE_CONST, {.dbl=FT_LOAD_RENDER}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, +{"no_bitmap", "set no_bitmap", 0, FF_OPT_TYPE_CONST, {.dbl=FT_LOAD_NO_BITMAP}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, +{"vertical_layout", "set vertical_layout", 0, FF_OPT_TYPE_CONST, {.dbl=FT_LOAD_VERTICAL_LAYOUT}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, +{"force_autohint", "set force_autohint", 0, FF_OPT_TYPE_CONST, {.dbl=FT_LOAD_FORCE_AUTOHINT}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, +{"crop_bitmap", "set crop_bitmap", 0, FF_OPT_TYPE_CONST, {.dbl=FT_LOAD_CROP_BITMAP}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, +{"pedantic", "set pedantic", 0, FF_OPT_TYPE_CONST, {.dbl=FT_LOAD_PEDANTIC}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, +{"ignore_global_advance_width", "set ignore_global_advance_width", 0, FF_OPT_TYPE_CONST, {.dbl=FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, +{"no_recurse", "set no_recurse", 0, FF_OPT_TYPE_CONST, {.dbl=FT_LOAD_NO_RECURSE}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, +{"ignore_transform", "set ignore_transform", 0, FF_OPT_TYPE_CONST, {.dbl=FT_LOAD_IGNORE_TRANSFORM}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, +{"monochrome", "set monochrome", 0, FF_OPT_TYPE_CONST, {.dbl=FT_LOAD_MONOCHROME}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, +{"linear_design", "set linear_design", 0, FF_OPT_TYPE_CONST, {.dbl=FT_LOAD_LINEAR_DESIGN}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, +{"no_autohint", "set no_autohint", 0, FF_OPT_TYPE_CONST, {.dbl=FT_LOAD_NO_AUTOHINT}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, {NULL}, }; -- cgit v1.2.3 From e6e7ba0ce3aadef32f7f16f706c4a0406b5bd70f Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Tue, 17 May 2011 00:46:48 +0200 Subject: Add some forgotten const to function arguments in libavfilter & libavformat. Signed-off-by: Michael Niedermayer --- libavfilter/gradfun.h | 14 +++++++------- libavfilter/vf_gradfun.c | 6 +++--- libavfilter/vf_unsharp.c | 4 ++-- libavfilter/x86/gradfun.c | 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/gradfun.h b/libavfilter/gradfun.h index 3dacbcb252..3c01085b83 100644 --- a/libavfilter/gradfun.h +++ b/libavfilter/gradfun.h @@ -33,16 +33,16 @@ typedef struct { int chroma_r; ///< blur radius for the chroma planes uint16_t *buf; ///< holds image data for blur algorithm passed into filter. /// DSP functions. - void (*filter_line) (uint8_t *dst, uint8_t *src, uint16_t *dc, int width, int thresh, const uint16_t *dithers); - void (*blur_line) (uint16_t *dc, uint16_t *buf, uint16_t *buf1, uint8_t *src, int src_linesize, int width); + void (*filter_line) (uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers); + void (*blur_line) (uint16_t *dc, uint16_t *buf, const uint16_t *buf1, const uint8_t *src, int src_linesize, int width); } GradFunContext; -void ff_gradfun_filter_line_c(uint8_t *dst, uint8_t *src, uint16_t *dc, int width, int thresh, const uint16_t *dithers); -void ff_gradfun_blur_line_c(uint16_t *dc, uint16_t *buf, uint16_t *buf1, uint8_t *src, int src_linesize, int width); +void ff_gradfun_filter_line_c(uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers); +void ff_gradfun_blur_line_c(uint16_t *dc, uint16_t *buf, const uint16_t *buf1, const uint8_t *src, int src_linesize, int width); -void ff_gradfun_filter_line_mmx2(uint8_t *dst, uint8_t *src, uint16_t *dc, int width, int thresh, const uint16_t *dithers); -void ff_gradfun_filter_line_ssse3(uint8_t *dst, uint8_t *src, uint16_t *dc, int width, int thresh, const uint16_t *dithers); +void ff_gradfun_filter_line_mmx2(uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers); +void ff_gradfun_filter_line_ssse3(uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers); -void ff_gradfun_blur_line_sse2(uint16_t *dc, uint16_t *buf, uint16_t *buf1, uint8_t *src, int src_linesize, int width); +void ff_gradfun_blur_line_sse2(uint16_t *dc, uint16_t *buf, const uint16_t *buf1, const uint8_t *src, int src_linesize, int width); #endif /* AVFILTER_GRADFUN_H */ diff --git a/libavfilter/vf_gradfun.c b/libavfilter/vf_gradfun.c index 83ed3d79e4..32dd3c1072 100644 --- a/libavfilter/vf_gradfun.c +++ b/libavfilter/vf_gradfun.c @@ -49,7 +49,7 @@ DECLARE_ALIGNED(16, static const uint16_t, dither)[8][8] = { {0x54,0x34,0x4C,0x2C,0x52,0x32,0x4A,0x2A}, }; -void ff_gradfun_filter_line_c(uint8_t *dst, uint8_t *src, uint16_t *dc, int width, int thresh, const uint16_t *dithers) +void ff_gradfun_filter_line_c(uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers) { int x; for (x = 0; x < width; x++, dc += x & 1) { @@ -63,7 +63,7 @@ void ff_gradfun_filter_line_c(uint8_t *dst, uint8_t *src, uint16_t *dc, int widt } } -void ff_gradfun_blur_line_c(uint16_t *dc, uint16_t *buf, uint16_t *buf1, uint8_t *src, int src_linesize, int width) +void ff_gradfun_blur_line_c(uint16_t *dc, uint16_t *buf, const uint16_t *buf1, const uint8_t *src, int src_linesize, int width) { int x, v, old; for (x = 0; x < width; x++) { @@ -74,7 +74,7 @@ void ff_gradfun_blur_line_c(uint16_t *dc, uint16_t *buf, uint16_t *buf1, uint8_t } } -static void filter(GradFunContext *ctx, uint8_t *dst, uint8_t *src, int width, int height, int dst_linesize, int src_linesize, int r) +static void filter(GradFunContext *ctx, uint8_t *dst, const uint8_t *src, int width, int height, int dst_linesize, int src_linesize, int r) { int bstride = FFALIGN(width, 16) / 2; int y; diff --git a/libavfilter/vf_unsharp.c b/libavfilter/vf_unsharp.c index 7aa7a43651..fa75de5d94 100644 --- a/libavfilter/vf_unsharp.c +++ b/libavfilter/vf_unsharp.c @@ -63,7 +63,7 @@ typedef struct { FilterParam chroma; ///< chroma parameters (width, height, amount) } UnsharpContext; -static void unsharpen(uint8_t *dst, uint8_t *src, int dst_stride, int src_stride, int width, int height, FilterParam *fp) +static void unsharpen(uint8_t *dst, const uint8_t *src, int dst_stride, int src_stride, int width, int height, FilterParam *fp) { uint32_t **sc = fp->sc; uint32_t sr[(MAX_SIZE * MAX_SIZE) - 1], tmp1, tmp2; @@ -96,7 +96,7 @@ static void unsharpen(uint8_t *dst, uint8_t *src, int dst_stride, int src_stride tmp1 = sc[z + 1][x + fp->steps_x] + tmp2; sc[z + 1][x + fp->steps_x] = tmp2; } if (x >= fp->steps_x && y >= fp->steps_y) { - uint8_t* srx = src - fp->steps_y * src_stride + x - fp->steps_x; + const uint8_t* srx = src - fp->steps_y * src_stride + x - fp->steps_x; uint8_t* dsx = dst - fp->steps_y * dst_stride + x - fp->steps_x; res = (int32_t)*srx + ((((int32_t) * srx - (int32_t)((tmp1 + fp->halfscale) >> fp->scalebits)) * fp->amount) >> 16); diff --git a/libavfilter/x86/gradfun.c b/libavfilter/x86/gradfun.c index 894a44b9ff..05d4a6fd6e 100644 --- a/libavfilter/x86/gradfun.c +++ b/libavfilter/x86/gradfun.c @@ -23,7 +23,7 @@ DECLARE_ALIGNED(16, static const uint16_t, pw_7f)[8] = {0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F}; DECLARE_ALIGNED(16, static const uint16_t, pw_ff)[8] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}; -void ff_gradfun_filter_line_mmx2(uint8_t *dst, uint8_t *src, uint16_t *dc, int width, int thresh, const uint16_t *dithers) +void ff_gradfun_filter_line_mmx2(uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers) { #if HAVE_MMX intptr_t x; @@ -71,7 +71,7 @@ void ff_gradfun_filter_line_mmx2(uint8_t *dst, uint8_t *src, uint16_t *dc, int w #endif } -void ff_gradfun_filter_line_ssse3(uint8_t *dst, uint8_t *src, uint16_t *dc, int width, int thresh, const uint16_t *dithers) +void ff_gradfun_filter_line_ssse3(uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers) { #if HAVE_SSSE3 intptr_t x; @@ -118,7 +118,7 @@ void ff_gradfun_filter_line_ssse3(uint8_t *dst, uint8_t *src, uint16_t *dc, int #endif // HAVE_SSSE3 } -void ff_gradfun_blur_line_sse2(uint16_t *dc, uint16_t *buf, uint16_t *buf1, uint8_t *src, int src_linesize, int width) +void ff_gradfun_blur_line_sse2(uint16_t *dc, uint16_t *buf, const uint16_t *buf1, const uint8_t *src, int src_linesize, int width) { #if HAVE_SSE #define BLURV(load)\ -- cgit v1.2.3 From 6070b7e1c520e9ca389403bae20a2ad04c7d54c7 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sat, 7 May 2011 21:35:08 +0200 Subject: vsrc_buffer: remove dependency on AVFrame Rename av_vsrc_buffer_add_frame to av_vsrc_buffer_add_video_buffer_ref(), and change its inteface to make it accept in input an AVFilterBufferRef rather than an AVFrame. This way the interface can be used without requiring the inclusion/installation of libavcodec headers. --- libavfilter/vsrc_buffer.c | 57 +++++++++++++++++++---------------------------- libavfilter/vsrc_buffer.h | 7 +++--- 2 files changed, 26 insertions(+), 38 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/vsrc_buffer.c b/libavfilter/vsrc_buffer.c index 84f3b33c3f..b593a207de 100644 --- a/libavfilter/vsrc_buffer.c +++ b/libavfilter/vsrc_buffer.c @@ -29,8 +29,7 @@ #include "libavutil/imgutils.h" typedef struct { - AVFrame frame; - int has_frame; + AVFilterBufferRef *picref; int h, w; enum PixelFormat pix_fmt; AVRational time_base; ///< time_base to set in the output link @@ -38,13 +37,14 @@ typedef struct { char sws_param[256]; } BufferSourceContext; -int av_vsrc_buffer_add_frame2(AVFilterContext *buffer_filter, AVFrame *frame, - const char *sws_param) +int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilterBufferRef *picref, + const char *sws_param) { BufferSourceContext *c = buffer_filter->priv; + AVFilterLink *outlink = buffer_filter->outputs[0]; int ret; - if (c->has_frame) { + if (c->picref) { av_log(buffer_filter, AV_LOG_ERROR, "Buffering several frames is not supported. " "Please consume all available frames before adding a new one.\n" @@ -56,14 +56,14 @@ int av_vsrc_buffer_add_frame2(AVFilterContext *buffer_filter, AVFrame *frame, snprintf(c->sws_param, 255, "%d:%d:%s", c->w, c->h, sws_param); } - if (frame->width != c->w || frame->height != c->h || frame->format != c->pix_fmt) { + if (picref->video->w != c->w || picref->video->h != c->h || picref->format != c->pix_fmt) { AVFilterContext *scale= buffer_filter->outputs[0]->dst; AVFilterLink *link; av_log(buffer_filter, AV_LOG_INFO, "Buffer video input changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n", c->w, c->h, av_pix_fmt_descriptors[c->pix_fmt].name, - frame->width, frame->height, av_pix_fmt_descriptors[frame->format].name); + picref->video->w, picref->video->h, av_pix_fmt_descriptors[picref->format].name); if(!scale || strcmp(scale->filter->name,"scale")){ AVFilter *f= avfilter_get_by_name("scale"); @@ -89,26 +89,28 @@ int av_vsrc_buffer_add_frame2(AVFilterContext *buffer_filter, AVFrame *frame, scale->filter->init(scale, c->sws_param, NULL); } - c->pix_fmt = scale->inputs[0]->format = frame->format; - c->w = scale->inputs[0]->w = frame->width; - c->h = scale->inputs[0]->h = frame->height; + c->pix_fmt = scale->inputs[0]->format = picref->format; + c->w = scale->inputs[0]->w = picref->video->w; + c->h = scale->inputs[0]->h = picref->video->h; link= scale->outputs[0]; if ((ret = link->srcpad->config_props(link)) < 0) return ret; } - c->frame = *frame; - memcpy(c->frame.data , frame->data , sizeof(frame->data)); - memcpy(c->frame.linesize, frame->linesize, sizeof(frame->linesize)); - c->has_frame = 1; + c->picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, + picref->video->w, picref->video->h); + av_image_copy(c->picref->data, c->picref->linesize, + picref->data, picref->linesize, + picref->format, picref->video->w, picref->video->h); + avfilter_copy_buffer_ref_props(c->picref, picref); return 0; } -int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame) +int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, AVFilterBufferRef *picref) { - return av_vsrc_buffer_add_frame2(buffer_filter, frame, ""); + return av_vsrc_buffer_add_video_buffer_ref2(buffer_filter, picref, ""); } static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) @@ -164,31 +166,18 @@ static int config_props(AVFilterLink *link) static int request_frame(AVFilterLink *link) { BufferSourceContext *c = link->src->priv; - AVFilterBufferRef *picref; - if (!c->has_frame) { + if (!c->picref) { av_log(link->src, AV_LOG_ERROR, "request_frame() called with no available frame!\n"); //return -1; } - /* This picture will be needed unmodified later for decoding the next - * frame */ - picref = avfilter_get_video_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE | - AV_PERM_REUSE2, - link->w, link->h); - - av_image_copy(picref->data, picref->linesize, - c->frame.data, c->frame.linesize, - picref->format, link->w, link->h); - avfilter_copy_frame_props(picref, &c->frame); - - avfilter_start_frame(link, avfilter_ref_buffer(picref, ~0)); + avfilter_start_frame(link, avfilter_ref_buffer(c->picref, ~0)); avfilter_draw_slice(link, 0, link->h, 1); avfilter_end_frame(link); - avfilter_unref_buffer(picref); - - c->has_frame = 0; + avfilter_unref_buffer(c->picref); + c->picref = NULL; return 0; } @@ -196,7 +185,7 @@ static int request_frame(AVFilterLink *link) static int poll_frame(AVFilterLink *link) { BufferSourceContext *c = link->src->priv; - return !!(c->has_frame); + return !!(c->picref); } AVFilter avfilter_vsrc_buffer = { diff --git a/libavfilter/vsrc_buffer.h b/libavfilter/vsrc_buffer.h index 2dda546e01..eb9ec56edd 100644 --- a/libavfilter/vsrc_buffer.h +++ b/libavfilter/vsrc_buffer.h @@ -27,12 +27,11 @@ * memory buffer source API for video */ -#include "libavcodec/avcodec.h" /* AVFrame */ #include "avfilter.h" -int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame); +int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, AVFilterBufferRef *picref); -int av_vsrc_buffer_add_frame2(AVFilterContext *buffer_filter, AVFrame *frame, - const char *sws_param); +int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilterBufferRef *picref, + const char *sws_param); #endif /* AVFILTER_VSRC_BUFFER_H */ -- cgit v1.2.3 From 9fdf77217b39646afdb8907b977e3d7a59f1cb9e Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sat, 14 May 2011 11:46:14 +0200 Subject: lavfi: add avfilter_get_video_buffer_ref_from_frame to avcodec.h Simplify passing AVFrame data to av_vsrc_buffer_add_video_buffer_ref(). --- libavfilter/avcodec.c | 13 +++++++++++++ libavfilter/avcodec.h | 8 ++++++++ libavfilter/avfilter.h | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) (limited to 'libavfilter') diff --git a/libavfilter/avcodec.c b/libavfilter/avcodec.c index c2f8651106..50670bc55e 100644 --- a/libavfilter/avcodec.c +++ b/libavfilter/avcodec.c @@ -40,3 +40,16 @@ void avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src) dst->video->pict_type = src->pict_type; } } + +AVFilterBufferRef *avfilter_get_video_buffer_ref_from_frame(const AVFrame *frame, + int perms) +{ + AVFilterBufferRef *picref = + avfilter_get_video_buffer_ref_from_arrays(frame->data, frame->linesize, perms, + frame->width, frame->height, + frame->format); + if (!picref) + return NULL; + avfilter_copy_frame_props(picref, frame); + return picref; +} diff --git a/libavfilter/avcodec.h b/libavfilter/avcodec.h index f438860d0b..e6ae907391 100644 --- a/libavfilter/avcodec.h +++ b/libavfilter/avcodec.h @@ -37,4 +37,12 @@ */ void avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src); +/** + * Create and return a picref reference from the data and properties + * contained in frame. + * + * @param perms permissions to assign to the new buffer reference + */ +AVFilterBufferRef *avfilter_get_video_buffer_ref_from_frame(const AVFrame *frame, int perms); + #endif /* AVFILTER_AVCODEC_H */ diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 03a1e49a46..171c9e4c74 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -26,7 +26,7 @@ #include "libavutil/samplefmt.h" #define LIBAVFILTER_VERSION_MAJOR 2 -#define LIBAVFILTER_VERSION_MINOR 5 +#define LIBAVFILTER_VERSION_MINOR 6 #define LIBAVFILTER_VERSION_MICRO 0 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ -- cgit v1.2.3 From 3799805e560f168811808ee0ba3befcb6fddc50e Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Fri, 13 May 2011 18:07:51 +0200 Subject: vsrc_buffer: fix style --- libavfilter/vsrc_buffer.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/vsrc_buffer.c b/libavfilter/vsrc_buffer.c index b593a207de..b41007c0da 100644 --- a/libavfilter/vsrc_buffer.c +++ b/libavfilter/vsrc_buffer.c @@ -52,12 +52,12 @@ int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilte //return -1; } - if(!c->sws_param[0]){ + if (!c->sws_param[0]) { snprintf(c->sws_param, 255, "%d:%d:%s", c->w, c->h, sws_param); } if (picref->video->w != c->w || picref->video->h != c->h || picref->format != c->pix_fmt) { - AVFilterContext *scale= buffer_filter->outputs[0]->dst; + AVFilterContext *scale = buffer_filter->outputs[0]->dst; AVFilterLink *link; av_log(buffer_filter, AV_LOG_INFO, @@ -65,26 +65,26 @@ int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilte c->w, c->h, av_pix_fmt_descriptors[c->pix_fmt].name, picref->video->w, picref->video->h, av_pix_fmt_descriptors[picref->format].name); - if(!scale || strcmp(scale->filter->name,"scale")){ - AVFilter *f= avfilter_get_by_name("scale"); + if (!scale || strcmp(scale->filter->name, "scale")) { + AVFilter *f = avfilter_get_by_name("scale"); av_log(buffer_filter, AV_LOG_INFO, "Inserting scaler filter\n"); - if(avfilter_open(&scale, f, "Input equalizer") < 0) + if (avfilter_open(&scale, f, "Input equalizer") < 0) return -1; - if((ret=avfilter_init_filter(scale, c->sws_param, NULL))<0){ + if ((ret = avfilter_init_filter(scale, c->sws_param, NULL)) < 0) { avfilter_free(scale); return ret; } - if((ret=avfilter_insert_filter(buffer_filter->outputs[0], scale, 0, 0))<0){ + if ((ret = avfilter_insert_filter(buffer_filter->outputs[0], scale, 0, 0)) < 0) { avfilter_free(scale); return ret; } scale->outputs[0]->time_base = scale->inputs[0]->time_base; scale->outputs[0]->format= c->pix_fmt; - } else if(!strcmp(scale->filter->name, "scale")) { + } else if (!strcmp(scale->filter->name, "scale")) { snprintf(c->sws_param, 255, "%d:%d:%s", scale->outputs[0]->w, scale->outputs[0]->h, sws_param); scale->filter->init(scale, c->sws_param, NULL); } @@ -93,7 +93,7 @@ int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilte c->w = scale->inputs[0]->w = picref->video->w; c->h = scale->inputs[0]->h = picref->video->h; - link= scale->outputs[0]; + link = scale->outputs[0]; if ((ret = link->srcpad->config_props(link)) < 0) return ret; } -- cgit v1.2.3 From 509b32cf5d5656473e277ac43dbb2ce9da66bff2 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Fri, 13 May 2011 18:09:47 +0200 Subject: vsrc_buffer: propagate avfilter_open() error code --- libavfilter/vsrc_buffer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/vsrc_buffer.c b/libavfilter/vsrc_buffer.c index b41007c0da..effc232d5e 100644 --- a/libavfilter/vsrc_buffer.c +++ b/libavfilter/vsrc_buffer.c @@ -69,8 +69,8 @@ int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilte AVFilter *f = avfilter_get_by_name("scale"); av_log(buffer_filter, AV_LOG_INFO, "Inserting scaler filter\n"); - if (avfilter_open(&scale, f, "Input equalizer") < 0) - return -1; + if ((ret = avfilter_open(&scale, f, "Input equalizer")) < 0) + return ret; if ((ret = avfilter_init_filter(scale, c->sws_param, NULL)) < 0) { avfilter_free(scale); -- cgit v1.2.3 From 50764e19a8edc018b6e5276f1b3e4215ba66217f Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Thu, 19 May 2011 01:02:54 +0200 Subject: vsrc_buffer: make the source accept sws_param in init Avoid the need of two distinct av_vsrc_add_video_buffer_ref* functions. Simplify the interface. --- libavfilter/avfilter.h | 2 +- libavfilter/vsrc_buffer.c | 33 ++++++++++++++------------------- libavfilter/vsrc_buffer.h | 3 --- 3 files changed, 15 insertions(+), 23 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 171c9e4c74..a0ad35882f 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -26,7 +26,7 @@ #include "libavutil/samplefmt.h" #define LIBAVFILTER_VERSION_MAJOR 2 -#define LIBAVFILTER_VERSION_MINOR 6 +#define LIBAVFILTER_VERSION_MINOR 7 #define LIBAVFILTER_VERSION_MICRO 0 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ diff --git a/libavfilter/vsrc_buffer.c b/libavfilter/vsrc_buffer.c index effc232d5e..9815f945da 100644 --- a/libavfilter/vsrc_buffer.c +++ b/libavfilter/vsrc_buffer.c @@ -37,8 +37,7 @@ typedef struct { char sws_param[256]; } BufferSourceContext; -int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilterBufferRef *picref, - const char *sws_param) +int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, AVFilterBufferRef *picref) { BufferSourceContext *c = buffer_filter->priv; AVFilterLink *outlink = buffer_filter->outputs[0]; @@ -52,13 +51,10 @@ int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilte //return -1; } - if (!c->sws_param[0]) { - snprintf(c->sws_param, 255, "%d:%d:%s", c->w, c->h, sws_param); - } - if (picref->video->w != c->w || picref->video->h != c->h || picref->format != c->pix_fmt) { AVFilterContext *scale = buffer_filter->outputs[0]->dst; AVFilterLink *link; + char scale_param[1024]; av_log(buffer_filter, AV_LOG_INFO, "Buffer video input changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n", @@ -72,7 +68,8 @@ int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilte if ((ret = avfilter_open(&scale, f, "Input equalizer")) < 0) return ret; - if ((ret = avfilter_init_filter(scale, c->sws_param, NULL)) < 0) { + snprintf(scale_param, sizeof(scale_param)-1, "%d:%d:%s", c->w, c->h, c->sws_param); + if ((ret = avfilter_init_filter(scale, scale_param, NULL)) < 0) { avfilter_free(scale); return ret; } @@ -85,8 +82,9 @@ int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilte scale->outputs[0]->format= c->pix_fmt; } else if (!strcmp(scale->filter->name, "scale")) { - snprintf(c->sws_param, 255, "%d:%d:%s", scale->outputs[0]->w, scale->outputs[0]->h, sws_param); - scale->filter->init(scale, c->sws_param, NULL); + snprintf(scale_param, sizeof(scale_param)-1, "%d:%d:%s", + scale->outputs[0]->w, scale->outputs[0]->h, c->sws_param); + scale->filter->init(scale, scale_param, NULL); } c->pix_fmt = scale->inputs[0]->format = picref->format; @@ -108,24 +106,21 @@ int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilte return 0; } -int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, AVFilterBufferRef *picref) -{ - return av_vsrc_buffer_add_video_buffer_ref2(buffer_filter, picref, ""); -} - static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) { BufferSourceContext *c = ctx->priv; char pix_fmt_str[128]; int n = 0; + *c->sws_param = 0; if (!args || - (n = sscanf(args, "%d:%d:%127[^:]:%d:%d:%d:%d", &c->w, &c->h, pix_fmt_str, + (n = sscanf(args, "%d:%d:%127[^:]:%d:%d:%d:%d:%255c", &c->w, &c->h, pix_fmt_str, &c->time_base.num, &c->time_base.den, - &c->sample_aspect_ratio.num, &c->sample_aspect_ratio.den)) != 7) { - av_log(ctx, AV_LOG_ERROR, "Expected 7 arguments, but only %d found in '%s'\n", n, args); + &c->sample_aspect_ratio.num, &c->sample_aspect_ratio.den, c->sws_param)) < 7) { + av_log(ctx, AV_LOG_ERROR, "Expected at least 7 arguments, but only %d found in '%s'\n", n, args); return AVERROR(EINVAL); } + if ((c->pix_fmt = av_get_pix_fmt(pix_fmt_str)) == PIX_FMT_NONE) { char *tail; c->pix_fmt = strtol(pix_fmt_str, &tail, 10); @@ -135,10 +130,10 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) } } - av_log(ctx, AV_LOG_INFO, "w:%d h:%d pixfmt:%s tb:%d/%d sar:%d/%d\n", + av_log(ctx, AV_LOG_INFO, "w:%d h:%d pixfmt:%s tb:%d/%d sar:%d/%d sws_param:%s\n", c->w, c->h, av_pix_fmt_descriptors[c->pix_fmt].name, c->time_base.num, c->time_base.den, - c->sample_aspect_ratio.num, c->sample_aspect_ratio.den); + c->sample_aspect_ratio.num, c->sample_aspect_ratio.den, c->sws_param); return 0; } diff --git a/libavfilter/vsrc_buffer.h b/libavfilter/vsrc_buffer.h index eb9ec56edd..34fec0e61a 100644 --- a/libavfilter/vsrc_buffer.h +++ b/libavfilter/vsrc_buffer.h @@ -31,7 +31,4 @@ int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, AVFilterBufferRef *picref); -int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilterBufferRef *picref, - const char *sws_param); - #endif /* AVFILTER_VSRC_BUFFER_H */ -- cgit v1.2.3 From c000a9f78390b71812c7ee5187bbccc3c2d79b1e Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Thu, 19 May 2011 01:17:16 +0200 Subject: vsrc_buffer: add av_vsrc_buffer_add_frame() The new function is a wrapper around av_vsrc_buffer_add_video_buffer_ref(), and allows to simplify the act of pushing AVFrame data to the source buffer. --- libavfilter/avcodec.h | 9 +++++++++ libavfilter/avfilter.h | 2 +- libavfilter/vsrc_buffer.c | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) (limited to 'libavfilter') diff --git a/libavfilter/avcodec.h b/libavfilter/avcodec.h index e6ae907391..74434e819d 100644 --- a/libavfilter/avcodec.h +++ b/libavfilter/avcodec.h @@ -45,4 +45,13 @@ void avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src); */ AVFilterBufferRef *avfilter_get_video_buffer_ref_from_frame(const AVFrame *frame, int perms); +/** + * Add frame data to buffer_src. + * + * @param buffer_src pointer to a buffer source context + * @return >= 0 in case of success, a negative AVERROR code in case of + * failure + */ +int av_vsrc_buffer_add_frame(AVFilterContext *buffer_src, const AVFrame *frame); + #endif /* AVFILTER_AVCODEC_H */ diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index a0ad35882f..02f2ed2f77 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -26,7 +26,7 @@ #include "libavutil/samplefmt.h" #define LIBAVFILTER_VERSION_MAJOR 2 -#define LIBAVFILTER_VERSION_MINOR 7 +#define LIBAVFILTER_VERSION_MINOR 8 #define LIBAVFILTER_VERSION_MICRO 0 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ diff --git a/libavfilter/vsrc_buffer.c b/libavfilter/vsrc_buffer.c index 9815f945da..6a2fcbf36e 100644 --- a/libavfilter/vsrc_buffer.c +++ b/libavfilter/vsrc_buffer.c @@ -106,6 +106,23 @@ int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, AVFilter return 0; } +#if CONFIG_AVCODEC +#include "avcodec.h" + +int av_vsrc_buffer_add_frame(AVFilterContext *buffer_src, const AVFrame *frame) +{ + AVFilterBufferRef *picref = + avfilter_get_video_buffer_ref_from_frame(frame, AV_PERM_WRITE); + if (!picref) + return AVERROR(ENOMEM); + av_vsrc_buffer_add_video_buffer_ref(buffer_src, picref); + picref->buf->data[0] = NULL; + avfilter_unref_buffer(picref); + + return 0; +} +#endif + static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) { BufferSourceContext *c = ctx->priv; -- cgit v1.2.3 From c78a85adf4a153914233e02b4d44f9414bc579d7 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Thu, 19 May 2011 12:01:25 +0200 Subject: vsrc_buffer: document av_vsrc_buffer_add_video_buffer_ref() --- libavfilter/vsrc_buffer.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'libavfilter') diff --git a/libavfilter/vsrc_buffer.h b/libavfilter/vsrc_buffer.h index 34fec0e61a..5307eadb70 100644 --- a/libavfilter/vsrc_buffer.h +++ b/libavfilter/vsrc_buffer.h @@ -29,6 +29,13 @@ #include "avfilter.h" -int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, AVFilterBufferRef *picref); +/** + * Add video buffer data in picref to buffer_src. + * + * @param buffer_src pointer to a buffer source context + * @return >= 0 in case of success, a negative AVERROR code in case of + * failure + */ +int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_src, AVFilterBufferRef *picref); #endif /* AVFILTER_VSRC_BUFFER_H */ -- cgit v1.2.3 From f1b3f33d48b366dd7b3b915b4de90d9ad4c4ae39 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Fri, 20 May 2011 11:36:16 +0200 Subject: vf_libopencv: prefer opencv/cxcore.h over cxtypes.h Require the presence of opencv/cxcore.h in place of opencv/cxtypes.h, which has been removed. Fix compilation with libopencv > 2.1.0. Fix trac issue #221. --- libavfilter/vf_libopencv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libavfilter') diff --git a/libavfilter/vf_libopencv.c b/libavfilter/vf_libopencv.c index 55e0a7f757..b789c8e19c 100644 --- a/libavfilter/vf_libopencv.c +++ b/libavfilter/vf_libopencv.c @@ -26,7 +26,7 @@ /* #define DEBUG */ #include -#include +#include #include "libavutil/avstring.h" #include "libavutil/file.h" #include "avfilter.h" -- cgit v1.2.3 From 153382e1b6b428a1dcb8dc3f06f64a6959d722c5 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Tue, 17 May 2011 16:58:04 +0200 Subject: multiple inclusion guard cleanup Add missing multiple inclusion guards; clean up #endif comments; add missing library prefixes; keep guard names consistent. --- libavfilter/avfilter.h | 2 +- libavfilter/avfiltergraph.h | 2 +- libavfilter/internal.h | 2 +- libavfilter/vsrc_buffer.h | 4 ++++ 4 files changed, 7 insertions(+), 3 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index c126cae093..33e93e27fc 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -859,4 +859,4 @@ static inline void avfilter_insert_outpad(AVFilterContext *f, unsigned index, &f->output_pads, &f->outputs, p); } -#endif /* AVFILTER_AVFILTER_H */ +#endif /* AVFILTER_AVFILTER_H */ diff --git a/libavfilter/avfiltergraph.h b/libavfilter/avfiltergraph.h index 801e50176f..a0f6b2e01f 100644 --- a/libavfilter/avfiltergraph.h +++ b/libavfilter/avfiltergraph.h @@ -120,4 +120,4 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, AVFilterInOut *inputs, AVFilterInOut *outputs, AVClass *log_ctx); -#endif /* AVFILTER_AVFILTERGRAPH_H */ +#endif /* AVFILTER_AVFILTERGRAPH_H */ diff --git a/libavfilter/internal.h b/libavfilter/internal.h index 0406a0d27e..64b3f3b865 100644 --- a/libavfilter/internal.h +++ b/libavfilter/internal.h @@ -52,4 +52,4 @@ int ff_avfilter_graph_config_formats(AVFilterGraph *graphctx, AVClass *log_ctx); /** default handler for freeing audio/video buffer when there are no references left */ void ff_avfilter_default_free_buffer(AVFilterBuffer *buf); -#endif /* AVFILTER_INTERNAL_H */ +#endif /* AVFILTER_INTERNAL_H */ diff --git a/libavfilter/vsrc_buffer.h b/libavfilter/vsrc_buffer.h index c7fc3824e0..6867f81e1c 100644 --- a/libavfilter/vsrc_buffer.h +++ b/libavfilter/vsrc_buffer.h @@ -19,9 +19,13 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef AVFILTER_VSRC_BUFFER_H +#define AVFILTER_VSRC_BUFFER_H + #include "libavcodec/avcodec.h" /* AVFrame */ #include "avfilter.h" int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, int64_t pts, AVRational pixel_aspect); +#endif /* AVFILTER_VSRC_BUFFER_H */ -- cgit v1.2.3 From a38a00eddf200e18c6cf3ba090beaa3b224bd114 Mon Sep 17 00:00:00 2001 From: Bobby Bingham Date: Sat, 21 May 2011 16:46:11 +0200 Subject: libavfilter: vf_split from soc. Commited by michael, for detailed authorship see soc repo --- libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_split.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 libavfilter/vf_split.c (limited to 'libavfilter') diff --git a/libavfilter/Makefile b/libavfilter/Makefile index de34089468..8ea3169841 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -52,6 +52,7 @@ OBJS-$(CONFIG_SETSAR_FILTER) += vf_aspect.o OBJS-$(CONFIG_SETTB_FILTER) += vf_settb.o OBJS-$(CONFIG_SHOWINFO_FILTER) += vf_showinfo.o OBJS-$(CONFIG_SLICIFY_FILTER) += vf_slicify.o +OBJS-$(CONFIG_SPLIT_FILTER) += vf_split.o OBJS-$(CONFIG_TRANSPOSE_FILTER) += vf_transpose.o OBJS-$(CONFIG_UNSHARP_FILTER) += vf_unsharp.o OBJS-$(CONFIG_VFLIP_FILTER) += vf_vflip.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index 1973602305..0b6487f540 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -68,6 +68,7 @@ void avfilter_register_all(void) REGISTER_FILTER (SETTB, settb, vf); REGISTER_FILTER (SHOWINFO, showinfo, vf); REGISTER_FILTER (SLICIFY, slicify, vf); + REGISTER_FILTER (SPLIT, split, vf); REGISTER_FILTER (TRANSPOSE, transpose, vf); REGISTER_FILTER (UNSHARP, unsharp, vf); REGISTER_FILTER (VFLIP, vflip, vf); diff --git a/libavfilter/vf_split.c b/libavfilter/vf_split.c new file mode 100644 index 0000000000..635c9284f8 --- /dev/null +++ b/libavfilter/vf_split.c @@ -0,0 +1,63 @@ +/* + * Video splitter + * copyright (c) 2007 Bobby Bingham + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avfilter.h" + +static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref) +{ + avfilter_start_frame(link->dst->outputs[0], + avfilter_ref_buffer(picref, ~AV_PERM_WRITE)); + avfilter_start_frame(link->dst->outputs[1], + avfilter_ref_buffer(picref, ~AV_PERM_WRITE)); +} + +static void end_frame(AVFilterLink *link) +{ + avfilter_end_frame(link->dst->outputs[0]); + avfilter_end_frame(link->dst->outputs[1]); + + avfilter_unref_buffer(link->cur_buf); +} + +static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir) +{ + avfilter_draw_slice(link->dst->outputs[0], y, h, slice_dir); + avfilter_draw_slice(link->dst->outputs[1], y, h, slice_dir); +} + +AVFilter avfilter_vf_split = +{ + .name = "split", + + .inputs = (AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .get_video_buffer= avfilter_null_get_video_buffer, + .start_frame = start_frame, + .draw_slice = draw_slice, + .end_frame = end_frame, }, + { .name = NULL}}, + .outputs = (AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, }, + { .name = "default2", + .type = AVMEDIA_TYPE_VIDEO, }, + { .name = NULL}}, +}; + -- cgit v1.2.3 From 7d5297b3436623fe52f9424d0bc3ae03fbfe164d Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sun, 22 May 2011 01:18:59 +0200 Subject: vf_split: fix various nits --- libavfilter/vf_split.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/vf_split.c b/libavfilter/vf_split.c index 635c9284f8..2cab8fad1b 100644 --- a/libavfilter/vf_split.c +++ b/libavfilter/vf_split.c @@ -1,6 +1,5 @@ /* - * Video splitter - * copyright (c) 2007 Bobby Bingham + * Copyright (c) 2007 Bobby Bingham * * This file is part of FFmpeg. * @@ -19,32 +18,36 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +/** + * @file + * Video splitter + */ + #include "avfilter.h" -static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref) +static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) { - avfilter_start_frame(link->dst->outputs[0], + avfilter_start_frame(inlink->dst->outputs[0], avfilter_ref_buffer(picref, ~AV_PERM_WRITE)); - avfilter_start_frame(link->dst->outputs[1], + avfilter_start_frame(inlink->dst->outputs[1], avfilter_ref_buffer(picref, ~AV_PERM_WRITE)); } -static void end_frame(AVFilterLink *link) +static void end_frame(AVFilterLink *inlink) { - avfilter_end_frame(link->dst->outputs[0]); - avfilter_end_frame(link->dst->outputs[1]); + avfilter_end_frame(inlink->dst->outputs[0]); + avfilter_end_frame(inlink->dst->outputs[1]); - avfilter_unref_buffer(link->cur_buf); + avfilter_unref_buffer(inlink->cur_buf); } -static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir) +static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) { - avfilter_draw_slice(link->dst->outputs[0], y, h, slice_dir); - avfilter_draw_slice(link->dst->outputs[1], y, h, slice_dir); + avfilter_draw_slice(inlink->dst->outputs[0], y, h, slice_dir); + avfilter_draw_slice(inlink->dst->outputs[1], y, h, slice_dir); } -AVFilter avfilter_vf_split = -{ +AVFilter avfilter_vf_split = { .name = "split", .inputs = (AVFilterPad[]) {{ .name = "default", @@ -60,4 +63,3 @@ AVFilter avfilter_vf_split = .type = AVMEDIA_TYPE_VIDEO, }, { .name = NULL}}, }; - -- cgit v1.2.3 From 88fc2e411ecf66b8a8e1b41b027b51bf2b5434b0 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sun, 22 May 2011 01:19:20 +0200 Subject: vf_split: add description --- libavfilter/vf_split.c | 1 + 1 file changed, 1 insertion(+) (limited to 'libavfilter') diff --git a/libavfilter/vf_split.c b/libavfilter/vf_split.c index 2cab8fad1b..4ef959a5c5 100644 --- a/libavfilter/vf_split.c +++ b/libavfilter/vf_split.c @@ -49,6 +49,7 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) AVFilter avfilter_vf_split = { .name = "split", + .description = NULL_IF_CONFIG_SMALL("Pass on the input to two outputs."), .inputs = (AVFilterPad[]) {{ .name = "default", .type = AVMEDIA_TYPE_VIDEO, -- cgit v1.2.3 From de1100a00a483d967ed82c46792e1553b5bdc332 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sun, 22 May 2011 01:20:53 +0200 Subject: vf_split: define draw_slice() before end_frame() Improve logical coherence, fix nit. --- libavfilter/vf_split.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/vf_split.c b/libavfilter/vf_split.c index 4ef959a5c5..75b9c6a877 100644 --- a/libavfilter/vf_split.c +++ b/libavfilter/vf_split.c @@ -33,6 +33,12 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) avfilter_ref_buffer(picref, ~AV_PERM_WRITE)); } +static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) +{ + avfilter_draw_slice(inlink->dst->outputs[0], y, h, slice_dir); + avfilter_draw_slice(inlink->dst->outputs[1], y, h, slice_dir); +} + static void end_frame(AVFilterLink *inlink) { avfilter_end_frame(inlink->dst->outputs[0]); @@ -41,12 +47,6 @@ static void end_frame(AVFilterLink *inlink) avfilter_unref_buffer(inlink->cur_buf); } -static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) -{ - avfilter_draw_slice(inlink->dst->outputs[0], y, h, slice_dir); - avfilter_draw_slice(inlink->dst->outputs[1], y, h, slice_dir); -} - AVFilter avfilter_vf_split = { .name = "split", .description = NULL_IF_CONFIG_SMALL("Pass on the input to two outputs."), -- cgit v1.2.3 From 6f5a145be17c1aeb61a0c7f2ef14a8ec537d7d46 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sun, 22 May 2011 01:32:18 +0200 Subject: vf_split: give more meaningful names to the output pads Rename "default" -> "output1", "default2" -> output2. --- libavfilter/vf_split.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/vf_split.c b/libavfilter/vf_split.c index 75b9c6a877..cbebf264fa 100644 --- a/libavfilter/vf_split.c +++ b/libavfilter/vf_split.c @@ -58,9 +58,9 @@ AVFilter avfilter_vf_split = { .draw_slice = draw_slice, .end_frame = end_frame, }, { .name = NULL}}, - .outputs = (AVFilterPad[]) {{ .name = "default", + .outputs = (AVFilterPad[]) {{ .name = "output1", .type = AVMEDIA_TYPE_VIDEO, }, - { .name = "default2", + { .name = "output2", .type = AVMEDIA_TYPE_VIDEO, }, { .name = NULL}}, }; -- cgit v1.2.3 From af2ed4b7488468abc8ccdd1b45d810886a609e1e Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sun, 22 May 2011 01:34:15 +0200 Subject: lavfi: bump minor and add changelog entry after the split filter addition --- libavfilter/avfilter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libavfilter') diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 02f2ed2f77..4502f3e54a 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -26,7 +26,7 @@ #include "libavutil/samplefmt.h" #define LIBAVFILTER_VERSION_MAJOR 2 -#define LIBAVFILTER_VERSION_MINOR 8 +#define LIBAVFILTER_VERSION_MINOR 9 #define LIBAVFILTER_VERSION_MICRO 0 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ -- cgit v1.2.3 From 83db71977700d3337c84d5945ac8b7e7ee881ac2 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sun, 22 May 2011 19:30:08 +0200 Subject: lavfi: make vsrc_buffer.h header public Address trac issue #33. --- libavfilter/Makefile | 2 +- libavfilter/avfilter.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 8ea3169841..8130ee4d20 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -6,7 +6,7 @@ FFLIBS-$(CONFIG_MOVIE_FILTER) += avformat avcodec FFLIBS-$(CONFIG_SCALE_FILTER) += swscale FFLIBS-$(CONFIG_MP_FILTER) += avcodec -HEADERS = avcodec.h avfilter.h avfiltergraph.h +HEADERS = avcodec.h avfilter.h avfiltergraph.h vsrc_buffer.h OBJS = allfilters.o \ avfilter.o \ diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 1c4b8d6cb8..cee5bbc114 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -26,7 +26,7 @@ #include "libavutil/samplefmt.h" #define LIBAVFILTER_VERSION_MAJOR 2 -#define LIBAVFILTER_VERSION_MINOR 9 +#define LIBAVFILTER_VERSION_MINOR 10 #define LIBAVFILTER_VERSION_MICRO 0 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ -- cgit v1.2.3 From f7053dc41a29fdd2592f57ced97420ac917d3ca9 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sun, 3 Apr 2011 16:48:33 +0200 Subject: vsrc_buffer: tweak error message in init() Change: Expected 7 arguments, but only %d found in '%s'\n to: Expected 7 arguments, but %d found in '%s'\n as the user may provide more than 7 arguments, in that case the error is not misleading. Signed-off-by: Anton Khirnov --- libavfilter/vsrc_buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libavfilter') diff --git a/libavfilter/vsrc_buffer.c b/libavfilter/vsrc_buffer.c index 6567279667..1f0233e3e3 100644 --- a/libavfilter/vsrc_buffer.c +++ b/libavfilter/vsrc_buffer.c @@ -73,7 +73,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) (n = sscanf(args, "%d:%d:%127[^:]:%d:%d:%d:%d", &c->w, &c->h, pix_fmt_str, &c->time_base.num, &c->time_base.den, &c->pixel_aspect.num, &c->pixel_aspect.den)) != 7) { - av_log(ctx, AV_LOG_ERROR, "Expected 7 arguments, but only %d found in '%s'\n", n, args); + av_log(ctx, AV_LOG_ERROR, "Expected 7 arguments, but %d found in '%s'\n", n, args); return AVERROR(EINVAL); } if ((c->pix_fmt = av_get_pix_fmt(pix_fmt_str)) == PIX_FMT_NONE) { -- cgit v1.2.3 From 75abcdb3915e3abb2dc6b5f7d101c177dcfdb626 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Mon, 11 Apr 2011 11:29:35 +0200 Subject: vsrc_buffer.h: add file doxy Signed-off-by: Stefano Sabatini Signed-off-by: Anton Khirnov --- libavfilter/vsrc_buffer.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'libavfilter') diff --git a/libavfilter/vsrc_buffer.h b/libavfilter/vsrc_buffer.h index 6867f81e1c..cfaf7919ac 100644 --- a/libavfilter/vsrc_buffer.h +++ b/libavfilter/vsrc_buffer.h @@ -22,6 +22,11 @@ #ifndef AVFILTER_VSRC_BUFFER_H #define AVFILTER_VSRC_BUFFER_H +/** + * @file + * memory buffer source API for video + */ + #include "libavcodec/avcodec.h" /* AVFrame */ #include "avfilter.h" -- cgit v1.2.3 From ecf72542fac6d05d88efe4a7a474adb8ec291fbe Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Wed, 25 May 2011 09:37:25 +0200 Subject: vsrc_buffer: remove duplicated file description --- libavfilter/vsrc_buffer.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/vsrc_buffer.h b/libavfilter/vsrc_buffer.h index 7e2526bea0..c717f3dae4 100644 --- a/libavfilter/vsrc_buffer.h +++ b/libavfilter/vsrc_buffer.h @@ -1,5 +1,4 @@ /* - * Memory buffer source filter * Copyright (c) 2008 Vitor Sessak * * This file is part of FFmpeg. @@ -27,7 +26,6 @@ * memory buffer source API for video */ - #include "avfilter.h" /** -- cgit v1.2.3 From cf06e3e4dd8c1023fb1dcad905f3f77fdc1cf3fb Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Fri, 20 May 2011 01:00:59 +0200 Subject: vsrc_buffer: return an error code if no frames are available Also decrease the log level of the corresponding message to WARNING, since the error is not fatal. --- libavfilter/vsrc_buffer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/vsrc_buffer.c b/libavfilter/vsrc_buffer.c index 6a2fcbf36e..d1e6ffd57a 100644 --- a/libavfilter/vsrc_buffer.c +++ b/libavfilter/vsrc_buffer.c @@ -180,9 +180,9 @@ static int request_frame(AVFilterLink *link) BufferSourceContext *c = link->src->priv; if (!c->picref) { - av_log(link->src, AV_LOG_ERROR, + av_log(link->src, AV_LOG_WARNING, "request_frame() called with no available frame!\n"); - //return -1; + return AVERROR(EINVAL); } avfilter_start_frame(link, avfilter_ref_buffer(c->picref, ~0)); -- cgit v1.2.3 From 07586b68a8a496e44c7c977599e1ec09d07fd57f Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sat, 7 May 2011 02:06:25 +0200 Subject: lavfi: add select filter Address trac issue #92. --- libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/avfilter.h | 2 +- libavfilter/vf_select.c | 351 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 354 insertions(+), 1 deletion(-) create mode 100644 libavfilter/vf_select.c (limited to 'libavfilter') diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 8130ee4d20..2324fb999e 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -46,6 +46,7 @@ OBJS-$(CONFIG_OVERLAY_FILTER) += vf_overlay.o OBJS-$(CONFIG_PAD_FILTER) += vf_pad.o OBJS-$(CONFIG_PIXDESCTEST_FILTER) += vf_pixdesctest.o OBJS-$(CONFIG_SCALE_FILTER) += vf_scale.o +OBJS-$(CONFIG_SELECT_FILTER) += vf_select.o OBJS-$(CONFIG_SETDAR_FILTER) += vf_aspect.o OBJS-$(CONFIG_SETPTS_FILTER) += vf_setpts.o OBJS-$(CONFIG_SETSAR_FILTER) += vf_aspect.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index 0b6487f540..5f1065f23f 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -62,6 +62,7 @@ void avfilter_register_all(void) REGISTER_FILTER (PAD, pad, vf); REGISTER_FILTER (PIXDESCTEST, pixdesctest, vf); REGISTER_FILTER (SCALE, scale, vf); + REGISTER_FILTER (SELECT, select, vf); REGISTER_FILTER (SETDAR, setdar, vf); REGISTER_FILTER (SETPTS, setpts, vf); REGISTER_FILTER (SETSAR, setsar, vf); diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index cee5bbc114..602b2437d9 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -26,7 +26,7 @@ #include "libavutil/samplefmt.h" #define LIBAVFILTER_VERSION_MAJOR 2 -#define LIBAVFILTER_VERSION_MINOR 10 +#define LIBAVFILTER_VERSION_MINOR 11 #define LIBAVFILTER_VERSION_MICRO 0 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ diff --git a/libavfilter/vf_select.c b/libavfilter/vf_select.c new file mode 100644 index 0000000000..3d05167d13 --- /dev/null +++ b/libavfilter/vf_select.c @@ -0,0 +1,351 @@ +/* + * Copyright (c) 2011 Stefano Sabatini + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * filter for selecting which frame passes in the filterchain + */ + +#include "libavutil/eval.h" +#include "libavutil/fifo.h" +#include "avfilter.h" + +static const char *var_names[] = { + "E", ///< Euler number + "PHI", ///< golden ratio + "PI", ///< greek pi + + "TB", ///< timebase + + "pts", ///< original pts in the file of the frame + "start_pts", ///< first PTS in the stream, expressed in TB units + "prev_pts", ///< previous frame PTS + "prev_selected_pts", ///< previous selected frame PTS + + "t", ///< first PTS in seconds + "start_t", ///< first PTS in the stream, expressed in seconds + "prev_t", ///< previous frame time + "prev_selected_t", ///< previously selected time + + "pict_type", ///< the type of picture in the movie + "PICT_TYPE_I", + "PICT_TYPE_P", + "PICT_TYPE_B", + "PICT_TYPE_S", + "PICT_TYPE_SI", + "PICT_TYPE_SP", + "PICT_TYPE_BI", + + "interlace_type", ///< the frame interlace type + "INTERLACE_TYPE_P", + "INTERLACE_TYPE_T", + "INTERLACE_TYPE_B", + + "n", ///< frame number (starting from zero) + "selected_n", ///< selected frame number (starting from zero) + "prev_selected_n", ///< number of the last selected frame + + "key", ///< tell if the frame is a key frame + "pos", ///< original position in the file of the frame + + NULL +}; + +enum var_name { + VAR_E, + VAR_PHI, + VAR_PI, + + VAR_TB, + + VAR_PTS, + VAR_START_PTS, + VAR_PREV_PTS, + VAR_PREV_SELECTED_PTS, + + VAR_T, + VAR_START_T, + VAR_PREV_T, + VAR_PREV_SELECTED_T, + + VAR_PICT_TYPE, + VAR_PICT_TYPE_I, + VAR_PICT_TYPE_P, + VAR_PICT_TYPE_B, + VAR_PICT_TYPE_S, + VAR_PICT_TYPE_SI, + VAR_PICT_TYPE_SP, + VAR_PICT_TYPE_BI, + + VAR_INTERLACE_TYPE, + VAR_INTERLACE_TYPE_P, + VAR_INTERLACE_TYPE_T, + VAR_INTERLACE_TYPE_B, + + VAR_N, + VAR_SELECTED_N, + VAR_PREV_SELECTED_N, + + VAR_KEY, + VAR_POS, + + VAR_VARS_NB +}; + +#define FIFO_SIZE 8 + +typedef struct { + AVExpr *expr; + double var_values[VAR_VARS_NB]; + double select; + int cache_frames; + AVFifoBuffer *pending_frames; ///< FIFO buffer of video frames +} SelectContext; + +static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) +{ + SelectContext *select = ctx->priv; + int ret; + + if ((ret = av_expr_parse(&select->expr, args ? args : "1", + var_names, NULL, NULL, NULL, NULL, 0, ctx)) < 0) { + av_log(ctx, AV_LOG_ERROR, "Error while parsing expression '%s'\n", args); + return ret; + } + + select->pending_frames = av_fifo_alloc(FIFO_SIZE*sizeof(AVFilterBufferRef*)); + if (!select->pending_frames) { + av_log(ctx, AV_LOG_ERROR, "Failed to allocate pending frames buffer.\n"); + return AVERROR(ENOMEM); + } + return 0; +} + +#define INTERLACE_TYPE_P 0 +#define INTERLACE_TYPE_T 1 +#define INTERLACE_TYPE_B 2 + +static int config_input(AVFilterLink *inlink) +{ + SelectContext *select = inlink->dst->priv; + + select->var_values[VAR_E] = M_E; + select->var_values[VAR_PHI] = M_PHI; + select->var_values[VAR_PI] = M_PI; + + select->var_values[VAR_N] = 0.0; + select->var_values[VAR_SELECTED_N] = 0.0; + + select->var_values[VAR_TB] = av_q2d(inlink->time_base); + + select->var_values[VAR_PREV_PTS] = NAN; + select->var_values[VAR_PREV_SELECTED_PTS] = NAN; + select->var_values[VAR_PREV_SELECTED_T] = NAN; + select->var_values[VAR_START_PTS] = NAN; + select->var_values[VAR_START_T] = NAN; + + select->var_values[VAR_PICT_TYPE_I] = AV_PICTURE_TYPE_I; + select->var_values[VAR_PICT_TYPE_P] = AV_PICTURE_TYPE_P; + select->var_values[VAR_PICT_TYPE_B] = AV_PICTURE_TYPE_B; + select->var_values[VAR_PICT_TYPE_SI] = AV_PICTURE_TYPE_SI; + select->var_values[VAR_PICT_TYPE_SP] = AV_PICTURE_TYPE_SP; + + select->var_values[VAR_INTERLACE_TYPE_P] = INTERLACE_TYPE_P; + select->var_values[VAR_INTERLACE_TYPE_T] = INTERLACE_TYPE_T; + select->var_values[VAR_INTERLACE_TYPE_B] = INTERLACE_TYPE_B;; + + return 0; +} + +#define D2TS(d) (isnan(d) ? AV_NOPTS_VALUE : (int64_t)(d)) +#define TS2D(ts) ((ts) == AV_NOPTS_VALUE ? NAN : (double)(ts)) + +static int select_frame(AVFilterContext *ctx, AVFilterBufferRef *picref) +{ + SelectContext *select = ctx->priv; + AVFilterLink *inlink = ctx->inputs[0]; + double res; + + if (isnan(select->var_values[VAR_START_PTS])) + select->var_values[VAR_START_PTS] = TS2D(picref->pts); + + select->var_values[VAR_PTS] = TS2D(picref->pts); + select->var_values[VAR_T ] = picref->pts * av_q2d(inlink->time_base); + select->var_values[VAR_POS] = picref->pos == -1 ? NAN : picref->pos; + select->var_values[VAR_PREV_PTS] = TS2D(picref ->pts); + + select->var_values[VAR_INTERLACE_TYPE] = + !picref->video->interlaced ? INTERLACE_TYPE_P : + picref->video->top_field_first ? INTERLACE_TYPE_T : INTERLACE_TYPE_B; + select->var_values[VAR_PICT_TYPE] = picref->video->pict_type; + + res = av_expr_eval(select->expr, select->var_values, NULL); + av_log(inlink->dst, AV_LOG_DEBUG, + "n:%d pts:%d t:%f pos:%d interlace_type:%c key:%d pict_type:%c " + "-> select:%f\n", + (int)select->var_values[VAR_N], + (int)select->var_values[VAR_PTS], + select->var_values[VAR_T], + (int)select->var_values[VAR_POS], + select->var_values[VAR_INTERLACE_TYPE] == INTERLACE_TYPE_P ? 'P' : + select->var_values[VAR_INTERLACE_TYPE] == INTERLACE_TYPE_T ? 'T' : + select->var_values[VAR_INTERLACE_TYPE] == INTERLACE_TYPE_B ? 'B' : '?', + (int)select->var_values[VAR_KEY], + av_get_picture_type_char(select->var_values[VAR_PICT_TYPE]), + res); + + select->var_values[VAR_N] += 1.0; + + if (res) { + select->var_values[VAR_PREV_SELECTED_N] = select->var_values[VAR_N]; + select->var_values[VAR_PREV_SELECTED_PTS] = select->var_values[VAR_PTS]; + select->var_values[VAR_PREV_SELECTED_T] = select->var_values[VAR_T]; + select->var_values[VAR_SELECTED_N] += 1.0; + } + return res; +} + +static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) +{ + SelectContext *select = inlink->dst->priv; + + select->select = select_frame(inlink->dst, picref); + if (select->select) { + /* frame was requested through poll_frame */ + if (select->cache_frames) { + if (!av_fifo_space(select->pending_frames)) + av_log(inlink->dst, AV_LOG_ERROR, + "Buffering limit reached, cannot cache more frames\n"); + else + av_fifo_generic_write(select->pending_frames, &picref, + sizeof(picref), NULL); + return; + } + avfilter_start_frame(inlink->dst->outputs[0], avfilter_ref_buffer(picref, ~0)); + } +} + +static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) +{ + SelectContext *select = inlink->dst->priv; + + if (select->select && !select->cache_frames) + avfilter_draw_slice(inlink->dst->outputs[0], y, h, slice_dir); +} + +static void end_frame(AVFilterLink *inlink) +{ + SelectContext *select = inlink->dst->priv; + AVFilterBufferRef *picref = inlink->cur_buf; + + if (select->select) { + if (select->cache_frames) + return; + avfilter_end_frame(inlink->dst->outputs[0]); + } + avfilter_unref_buffer(picref); +} + +static int request_frame(AVFilterLink *outlink) +{ + AVFilterContext *ctx = outlink->src; + SelectContext *select = ctx->priv; + AVFilterLink *inlink = outlink->src->inputs[0]; + select->select = 0; + + if (av_fifo_size(select->pending_frames)) { + AVFilterBufferRef *picref; + av_fifo_generic_read(select->pending_frames, &picref, sizeof(picref), NULL); + avfilter_start_frame(outlink, avfilter_ref_buffer(picref, ~0)); + avfilter_draw_slice(outlink, 0, outlink->h, 1); + avfilter_end_frame(outlink); + avfilter_unref_buffer(picref); + return 0; + } + + while (!select->select) { + int ret = avfilter_request_frame(inlink); + if (ret < 0) + return ret; + } + + return 0; +} + +static int poll_frame(AVFilterLink *outlink) +{ + SelectContext *select = outlink->src->priv; + AVFilterLink *inlink = outlink->src->inputs[0]; + int count, ret; + + if (!av_fifo_size(select->pending_frames)) { + if ((count = avfilter_poll_frame(inlink)) <= 0) + return count; + /* request frame from input, and apply select condition to it */ + select->cache_frames = 1; + while (count-- && av_fifo_space(select->pending_frames)) { + ret = avfilter_request_frame(inlink); + if (ret < 0) + break; + } + select->cache_frames = 0; + } + + return av_fifo_size(select->pending_frames)/sizeof(AVFilterBufferRef *); +} + +static av_cold void uninit(AVFilterContext *ctx) +{ + SelectContext *select = ctx->priv; + AVFilterBufferRef *picref; + int i; + + av_expr_free(select->expr); + select->expr = NULL; + + for (i = 0; i < av_fifo_size(select->pending_frames)/sizeof(picref); i++) { + av_fifo_generic_read(select->pending_frames, &picref, sizeof(picref), NULL); + avfilter_unref_buffer(picref); + } + av_fifo_free(select->pending_frames); +} + +AVFilter avfilter_vf_select = { + .name = "select", + .description = NULL_IF_CONFIG_SMALL("Select frames to pass in output."), + .init = init, + .uninit = uninit, + + .priv_size = sizeof(SelectContext), + + .inputs = (AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .get_video_buffer = avfilter_null_get_video_buffer, + .config_props = config_input, + .start_frame = start_frame, + .draw_slice = draw_slice, + .end_frame = end_frame }, + { .name = NULL }}, + .outputs = (AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .poll_frame = poll_frame, + .request_frame = request_frame, }, + { .name = NULL}}, +}; -- cgit v1.2.3 From 2146f4928a45b37eba781a74aa8cc9ae50e89d52 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Fri, 27 May 2011 20:22:55 +0200 Subject: vf_crop: Replace #ifdef DEBUG + av_log() by av_dlog(). --- libavfilter/vf_crop.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/vf_crop.c b/libavfilter/vf_crop.c index 9f71b9e7dc..69e5a520c8 100644 --- a/libavfilter/vf_crop.c +++ b/libavfilter/vf_crop.c @@ -264,11 +264,9 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref) crop->x &= ~((1 << crop->hsub) - 1); crop->y &= ~((1 << crop->vsub) - 1); -#ifdef DEBUG - av_log(ctx, AV_LOG_DEBUG, - "n:%d t:%f x:%d y:%d x+w:%d y+h:%d\n", - (int)crop->var_values[VAR_N], crop->var_values[VAR_T], crop->x, crop->y, crop->x+crop->w, crop->y+crop->h); -#endif + av_dlog(ctx, "n:%d t:%f x:%d y:%d x+w:%d y+h:%d\n", + (int)crop->var_values[VAR_N], crop->var_values[VAR_T], crop->x, + crop->y, crop->x+crop->w, crop->y+crop->h); ref2->data[0] += crop->y * ref2->linesize[0]; ref2->data[0] += crop->x * crop->max_step[0]; -- cgit v1.2.3 From d6e0729b24de566a80554abbdf0aca1ed24de14b Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Fri, 27 May 2011 20:24:44 +0200 Subject: avfilter: Surround function only used in debug mode by appropriate #ifdef. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes the warning: libavfilter/avfilter.c:219: warning: ‘ff_get_ref_perms_string’ defined but not used --- libavfilter/avfilter.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libavfilter') diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 02915036ab..abeae14f79 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -215,6 +215,7 @@ int avfilter_config_links(AVFilterContext *filter) return 0; } +#ifdef DEBUG static char *ff_get_ref_perms_string(char *buf, size_t buf_size, int perms) { snprintf(buf, buf_size, "%s%s%s%s%s%s", @@ -226,6 +227,7 @@ static char *ff_get_ref_perms_string(char *buf, size_t buf_size, int perms) perms & AV_PERM_NEG_LINESIZES ? "n" : ""); return buf; } +#endif static void ff_dlog_ref(void *ctx, AVFilterBufferRef *ref, int end) { -- cgit v1.2.3 From adba9c63525b8971fc6ccda47e643dca05c3ee9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Date: Sun, 29 May 2011 21:07:34 +0200 Subject: Fix various unused variable warnings Signed-off-by: Michael Niedermayer --- libavfilter/vf_fieldorder.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/vf_fieldorder.c b/libavfilter/vf_fieldorder.c index 59ca77821a..0913b6950e 100644 --- a/libavfilter/vf_fieldorder.c +++ b/libavfilter/vf_fieldorder.c @@ -153,7 +153,7 @@ static void end_frame(AVFilterLink *inlink) AVFilterBufferRef *inpicref = inlink->cur_buf; AVFilterBufferRef *outpicref = outlink->out_buf; - int h, w, plane, line_step, line_size, line; + int h, plane, line_step, line_size, line; uint8_t *cpy_src, *cpy_dst; if ( inpicref->video->interlaced @@ -162,7 +162,6 @@ static void end_frame(AVFilterLink *inlink) "picture will move %s one line\n", fieldorder->dst_tff ? "up" : "down"); h = inpicref->video->h; - w = inpicref->video->w; for (plane = 0; plane < 4 && inpicref->data[plane]; plane++) { line_step = inpicref->linesize[plane]; line_size = fieldorder->line_size[plane]; -- cgit v1.2.3 From a52f598d6301eddc333002c0b2a5e9cb5dda1cf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= Date: Mon, 30 May 2011 23:44:54 +0200 Subject: Port libmpcodec fixes from MPlayer. --- libavfilter/libmpcodecs/vf_detc.c | 2 +- libavfilter/libmpcodecs/vf_dint.c | 12 ++++++------ libavfilter/libmpcodecs/vf_divtc.c | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/libmpcodecs/vf_detc.c b/libavfilter/libmpcodecs/vf_detc.c index 8dd51da794..28d20e09b7 100644 --- a/libavfilter/libmpcodecs/vf_detc.c +++ b/libavfilter/libmpcodecs/vf_detc.c @@ -382,7 +382,7 @@ static void uninit(struct vf_instance *vf) } static struct { - char *name; + const char *name; int (*func)(struct vf_priv_s *p, mp_image_t *new, mp_image_t *old); int needread; } anal_funcs[] = { diff --git a/libavfilter/libmpcodecs/vf_dint.c b/libavfilter/libmpcodecs/vf_dint.c index 7038381221..ac5bf54a54 100644 --- a/libavfilter/libmpcodecs/vf_dint.c +++ b/libavfilter/libmpcodecs/vf_dint.c @@ -32,7 +32,7 @@ struct vf_priv_s { float sense; // first parameter float level; // second parameter unsigned int imgfmt; - char diff; + int diff; uint32_t max; // int dfr; // int rdfr; @@ -73,7 +73,7 @@ static int config (struct vf_instance *vf, vf->priv->diff = 31; mp_msg (MSGT_VFILTER, MSGL_INFO, "Drop-interlaced: %dx%d diff %d / level %u\n", vf->priv->pmpi->width, vf->priv->pmpi->height, - (int)vf->priv->diff, (unsigned int)vf->priv->max); + vf->priv->diff, (unsigned int)vf->priv->max); // vf->priv->rdfr = vf->priv->dfr = 0; vf->priv->was_dint = 0; return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); @@ -81,10 +81,10 @@ static int config (struct vf_instance *vf, static int put_image (struct vf_instance *vf, mp_image_t *mpi, double pts) { - char rrow0[MAXROWSIZE]; - char rrow1[MAXROWSIZE]; - char rrow2[MAXROWSIZE]; - char *row0 = rrow0, *row1 = rrow1, *row2 = rrow2/*, *row3 = rrow3*/; + int8_t rrow0[MAXROWSIZE]; + int8_t rrow1[MAXROWSIZE]; + int8_t rrow2[MAXROWSIZE]; + int8_t *row0 = rrow0, *row1 = rrow1, *row2 = rrow2/*, *row3 = rrow3*/; int rowsize = mpi->width; uint32_t nok = 0, max = vf->priv->max; int diff = vf->priv->diff; diff --git a/libavfilter/libmpcodecs/vf_divtc.c b/libavfilter/libmpcodecs/vf_divtc.c index 25447f0596..3ead47290d 100644 --- a/libavfilter/libmpcodecs/vf_divtc.c +++ b/libavfilter/libmpcodecs/vf_divtc.c @@ -42,7 +42,7 @@ struct vf_priv_s ocount, sum[5]; double threshold; FILE *file; - char *bdata; + int8_t *bdata; unsigned int *csdata; int *history; }; @@ -384,8 +384,8 @@ static int analyze(struct vf_priv_s *p) { int *buf=0, *bp, bufsize=0, n, b, f, i, j, m, s; unsigned int *cbuf=0, *cp; - char *pbuf; - char lbuf[256]; + int8_t *pbuf; + int8_t lbuf[256]; int sum[5]; double d; -- cgit v1.2.3 From 5ac4952a5808cc8cfe01031ca9d4df7d072f453c Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Tue, 31 May 2011 14:00:12 +0200 Subject: vf_drawtext: Replace FFmpeg by Libav in license boilerplate. --- libavfilter/vf_drawtext.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index b26029bb8f..8b28be9d9c 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -3,20 +3,20 @@ * Copyright (c) 2010 S.N. Hemanth Meenakshisundaram * Copyright (c) 2003 Gustavo Sverzut Barbieri * - * This file is part of FFmpeg. + * This file is part of Libav. * - * FFmpeg is free software; you can redistribute it and/or + * Libav is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * FFmpeg is distributed in the hope that it will be useful, + * Libav is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software + * License along with Libav; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -- cgit v1.2.3 From b0a4e5f9e765dc601a62f87cf3510ac381c3c4c6 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Tue, 31 May 2011 21:23:45 +0200 Subject: Employ correct printf format specifiers, mostly in debug output. --- libavfilter/vsrc_movie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libavfilter') diff --git a/libavfilter/vsrc_movie.c b/libavfilter/vsrc_movie.c index 5e15524e61..a26787d561 100644 --- a/libavfilter/vsrc_movie.c +++ b/libavfilter/vsrc_movie.c @@ -152,7 +152,7 @@ static int movie_init(AVFilterContext *ctx) movie->w = movie->codec_ctx->width; movie->h = movie->codec_ctx->height; - av_log(ctx, AV_LOG_INFO, "seek_point:%lld format_name:%s file_name:%s stream_index:%d\n", + av_log(ctx, AV_LOG_INFO, "seek_point:%"PRIi64" format_name:%s file_name:%s stream_index:%d\n", movie->seek_point, movie->format_name, movie->file_name, movie->stream_index); -- cgit v1.2.3 From bf19c871012644fe27c69531b5f733c472aa858b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= Date: Wed, 1 Jun 2011 20:26:54 +0200 Subject: Fix type of out[] variable, it should not be const. Fixes compiler warning about incompatible types in sws_scale call. --- libavfilter/vf_scale.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'libavfilter') diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c index 9ff93bd411..e172a2e586 100644 --- a/libavfilter/vf_scale.c +++ b/libavfilter/vf_scale.c @@ -270,7 +270,8 @@ static int scale_slice(AVFilterLink *link, struct SwsContext *sws, int y, int h, ScaleContext *scale = link->dst->priv; AVFilterBufferRef *cur_pic = link->cur_buf; AVFilterBufferRef *out_buf = link->dst->outputs[0]->out_buf; - const uint8_t *in[4], *out[4]; + const uint8_t *in[4]; + uint8_t *out[4]; int in_stride[4],out_stride[4]; int i; -- cgit v1.2.3 From 2a30df09fd64634ad1b70485cd665ad05116730c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= Date: Wed, 1 Jun 2011 20:52:43 +0200 Subject: Replace non-existent HAVE_SSE2 with HAVE_SSE. Since this is only a compilation check (the actual function used is selected at runtime) and HAVE_SSE indicates that we can also compile SSE2 code, this is correct. --- libavfilter/libmpcodecs/vf_gradfun.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/libmpcodecs/vf_gradfun.c b/libavfilter/libmpcodecs/vf_gradfun.c index 2732f55d9a..fd4236cc37 100644 --- a/libavfilter/libmpcodecs/vf_gradfun.c +++ b/libavfilter/libmpcodecs/vf_gradfun.c @@ -188,7 +188,7 @@ static void filter_line_ssse3(uint8_t *dst, uint8_t *src, uint16_t *dc, } #endif // HAVE_SSSE3 -#if HAVE_SSE2 && HAVE_6REGS +#if HAVE_SSE && HAVE_6REGS #define BLURV(load)\ intptr_t x = -2*width;\ __asm__ volatile(\ @@ -231,7 +231,7 @@ static void blur_line_sse2(uint16_t *dc, uint16_t *buf, uint16_t *buf1, BLURV("movdqa"); } } -#endif // HAVE_6REGS && HAVE_SSE2 +#endif // HAVE_6REGS && HAVE_SSE static void filter(struct vf_priv_s *ctx, uint8_t *dst, uint8_t *src, int width, int height, int dstride, int sstride, int r) @@ -385,7 +385,7 @@ static int vf_open(vf_instance_t *vf, char *args) vf->priv->blur_line = blur_line_c; vf->priv->filter_line = filter_line_c; -#if HAVE_SSE2 && HAVE_6REGS +#if HAVE_SSE && HAVE_6REGS if (gCpuCaps.hasSSE2) vf->priv->blur_line = blur_line_sse2; #endif -- cgit v1.2.3 From 3379531c401b457c9f7437ee0db772da75fd1765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= Date: Wed, 1 Jun 2011 21:24:16 +0200 Subject: Port recent changes to MPlayer libmpcodecs. Also include an older fix for vf_smartblur which was essentially broken due to reading the threshold value wrongly. --- libavfilter/libmpcodecs/vf_divtc.c | 3 ++- libavfilter/libmpcodecs/vf_ilpack.c | 13 ++++++++----- libavfilter/libmpcodecs/vf_pp7.c | 4 ++-- libavfilter/libmpcodecs/vf_smartblur.c | 4 ++-- libavfilter/libmpcodecs/vf_unsharp.c | 2 +- 5 files changed, 15 insertions(+), 11 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/libmpcodecs/vf_divtc.c b/libavfilter/libmpcodecs/vf_divtc.c index 3ead47290d..4c171d1728 100644 --- a/libavfilter/libmpcodecs/vf_divtc.c +++ b/libavfilter/libmpcodecs/vf_divtc.c @@ -598,7 +598,8 @@ static void uninit(struct vf_instance *vf) static int vf_open(vf_instance_t *vf, char *args) { struct vf_priv_s *p; - char *filename="framediff.log", *ap, *q, *a; + const char *filename="framediff.log"; + char *ap, *q, *a; if(args && !(args=av_strdup(args))) { diff --git a/libavfilter/libmpcodecs/vf_ilpack.c b/libavfilter/libmpcodecs/vf_ilpack.c index 77555a7b41..db4a849e1f 100644 --- a/libavfilter/libmpcodecs/vf_ilpack.c +++ b/libavfilter/libmpcodecs/vf_ilpack.c @@ -28,6 +28,7 @@ #include "img_format.h" #include "mp_image.h" #include "vf.h" +#include "libavutil/attributes.h" typedef void (pack_func_t)(unsigned char *dst, unsigned char *y, unsigned char *u, unsigned char *v, int w, int us, int vs); @@ -38,7 +39,8 @@ struct vf_priv_s { }; static void pack_nn_C(unsigned char *dst, unsigned char *y, - unsigned char *u, unsigned char *v, int w) + unsigned char *u, unsigned char *v, int w, + int av_unused us, int av_unused vs) { int j; for (j = w/2; j; j--) { @@ -77,7 +79,8 @@ static void pack_li_1_C(unsigned char *dst, unsigned char *y, #if HAVE_MMX static void pack_nn_MMX(unsigned char *dst, unsigned char *y, - unsigned char *u, unsigned char *v, int w) + unsigned char *u, unsigned char *v, int w, + int av_unused us, int av_unused vs) { __asm__ volatile ("" ASMALIGN(4) @@ -103,7 +106,7 @@ static void pack_nn_MMX(unsigned char *dst, unsigned char *y, : "r" (y), "r" (u), "r" (v), "r" (dst), "r" (w/8) : "memory" ); - pack_nn_C(dst, y, u, v, (w&7)); + pack_nn_C(dst, y, u, v, (w&7), 0, 0); } #if HAVE_EBX_AVAILABLE @@ -413,12 +416,12 @@ static int vf_open(vf_instance_t *vf, char *args) vf->priv->mode = 1; if (args) sscanf(args, "%d", &vf->priv->mode); - pack_nn = (pack_func_t *)pack_nn_C; + pack_nn = pack_nn_C; pack_li_0 = pack_li_0_C; pack_li_1 = pack_li_1_C; #if HAVE_MMX if(gCpuCaps.hasMMX) { - pack_nn = (pack_func_t *)pack_nn_MMX; + pack_nn = pack_nn_MMX; #if HAVE_EBX_AVAILABLE pack_li_0 = pack_li_0_MMX; pack_li_1 = pack_li_1_MMX; diff --git a/libavfilter/libmpcodecs/vf_pp7.c b/libavfilter/libmpcodecs/vf_pp7.c index f8b64b658a..c075d6619c 100644 --- a/libavfilter/libmpcodecs/vf_pp7.c +++ b/libavfilter/libmpcodecs/vf_pp7.c @@ -286,8 +286,8 @@ static void filter(struct vf_priv_s *p, uint8_t *dst, uint8_t *src, int dst_stri int x, y; const int stride= is_luma ? p->temp_stride : ((width+16+15)&(~15)); uint8_t *p_src= p->src + 8*stride; - DCTELEM *block= p->src; - DCTELEM *temp= p->src + 32; + DCTELEM *block= (DCTELEM *)p->src; + DCTELEM *temp= (DCTELEM *)(p->src + 32); if (!src || !dst) return; // HACK avoid crash for Y8 colourspace for(y=0; yw >> mpi->chroma_x_shift; int ch= mpi->h >> mpi->chroma_y_shift; - FilterParam *f= &vf->priv; + int threshold = vf->priv->luma.threshold || vf->priv->chroma.threshold; mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE| - (f->threshold) ? MP_IMGFLAG_READABLE : 0, + (threshold ? MP_IMGFLAG_READABLE : 0), mpi->w,mpi->h); assert(mpi->flags&MP_IMGFLAG_PLANAR); diff --git a/libavfilter/libmpcodecs/vf_unsharp.c b/libavfilter/libmpcodecs/vf_unsharp.c index cd464321f4..db22f78e9d 100644 --- a/libavfilter/libmpcodecs/vf_unsharp.c +++ b/libavfilter/libmpcodecs/vf_unsharp.c @@ -132,7 +132,7 @@ static int config( struct vf_instance *vf, int z, stepsX, stepsY; FilterParam *fp; - char *effect; + const char *effect; // allocate buffers -- cgit v1.2.3 From 58fd70b04decdb7e5580c06b1be3bd573fabeeda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= Date: Wed, 1 Jun 2011 21:30:13 +0200 Subject: Port remove of get_sws_cpuflags from MPlayer's libmpcodecs. --- libavfilter/libmpcodecs/vf_sab.c | 2 +- libavfilter/libmpcodecs/vf_scale.h | 1 - libavfilter/libmpcodecs/vf_smartblur.c | 2 +- libavfilter/vf_mp.c | 4 ---- 4 files changed, 2 insertions(+), 7 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/libmpcodecs/vf_sab.c b/libavfilter/libmpcodecs/vf_sab.c index 377c9e33a8..51e9d78158 100644 --- a/libavfilter/libmpcodecs/vf_sab.c +++ b/libavfilter/libmpcodecs/vf_sab.c @@ -102,7 +102,7 @@ static int allocStuff(FilterParam *f, int width, int height){ swsF.lumH= swsF.lumV= vec; swsF.chrH= swsF.chrV= NULL; f->preFilterContext= sws_getContext( - width, height, PIX_FMT_GRAY8, width, height, PIX_FMT_GRAY8, get_sws_cpuflags()|SWS_POINT, &swsF, NULL, NULL); + width, height, PIX_FMT_GRAY8, width, height, PIX_FMT_GRAY8, SWS_POINT, &swsF, NULL, NULL); sws_freeVec(vec); vec = sws_getGaussianVec(f->strength, 5.0); diff --git a/libavfilter/libmpcodecs/vf_scale.h b/libavfilter/libmpcodecs/vf_scale.h index 91ed103c30..4de3b48ec3 100644 --- a/libavfilter/libmpcodecs/vf_scale.h +++ b/libavfilter/libmpcodecs/vf_scale.h @@ -29,7 +29,6 @@ extern float sws_lum_sharpen; extern int sws_flags; -int get_sws_cpuflags(void); struct SwsContext *sws_getContextFromCmdLine(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat); #endif /* MPLAYER_VF_SCALE_H */ diff --git a/libavfilter/libmpcodecs/vf_smartblur.c b/libavfilter/libmpcodecs/vf_smartblur.c index 8acdb73ffc..5bfcb2806e 100644 --- a/libavfilter/libmpcodecs/vf_smartblur.c +++ b/libavfilter/libmpcodecs/vf_smartblur.c @@ -87,7 +87,7 @@ static int allocStuff(FilterParam *f, int width, int height){ swsF.lumH= swsF.lumV= vec; swsF.chrH= swsF.chrV= NULL; f->filterContext= sws_getContext( - width, height, PIX_FMT_GRAY8, width, height, PIX_FMT_GRAY8, SWS_BICUBIC | get_sws_cpuflags(), &swsF, NULL, NULL); + width, height, PIX_FMT_GRAY8, width, height, PIX_FMT_GRAY8, SWS_BICUBIC, &swsF, NULL, NULL); sws_freeVec(vec); diff --git a/libavfilter/vf_mp.c b/libavfilter/vf_mp.c index 7dd8a64df8..01a8f064a2 100644 --- a/libavfilter/vf_mp.c +++ b/libavfilter/vf_mp.c @@ -287,10 +287,6 @@ zrmjpeg CpuCaps gCpuCaps; //FIXME initialize this so optims work -int get_sws_cpuflags(void){ - return 0; -} - static void sws_getFlagsAndFilterFromCmdLine(int *flags, SwsFilter **srcFilterParam, SwsFilter **dstFilterParam) { static int firstTime=1; -- cgit v1.2.3 From 77b32b73ed31f9aaa6c1e476c9a041399a35be9d Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Thu, 2 Jun 2011 16:26:55 +0200 Subject: lavfi: apply misc style fixes Adopt K&R style for overall consistency/readability. --- libavfilter/avfilter.c | 14 +++++++------- libavfilter/defaults.c | 22 +++++++++++----------- libavfilter/internal.h | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 72e0a87f8e..b7ad6f0503 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -77,8 +77,8 @@ static void store_in_pool(AVFilterBufferRef *ref) av_assert0(ref->buf->data[0]); - if(pool->count == POOL_SIZE){ - AVFilterBufferRef *ref1= pool->pic[0]; + if (pool->count == POOL_SIZE) { + AVFilterBufferRef *ref1 = pool->pic[0]; av_freep(&ref1->video); av_freep(&ref1->audio); av_freep(&ref1->buf->data[0]); @@ -89,9 +89,9 @@ static void store_in_pool(AVFilterBufferRef *ref) pool->pic[POOL_SIZE-1] = NULL; } - for(i=0; ipic[i]){ - pool->pic[i]= ref; + for (i = 0; i < POOL_SIZE; i++) { + if (!pool->pic[i]) { + pool->pic[i] = ref; pool->count++; break; } @@ -102,8 +102,8 @@ void avfilter_unref_buffer(AVFilterBufferRef *ref) { if (!ref) return; - if (!(--ref->buf->refcount)){ - if(!ref->buf->free){ + if (!(--ref->buf->refcount)) { + if (!ref->buf->free) { store_in_pool(ref); return; } diff --git a/libavfilter/defaults.c b/libavfilter/defaults.c index 9ee23e57b7..74ba599f9c 100644 --- a/libavfilter/defaults.c +++ b/libavfilter/defaults.c @@ -40,28 +40,28 @@ AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link, int per uint8_t *data[4]; int i; AVFilterBufferRef *picref = NULL; - AVFilterPool *pool= link->pool; + AVFilterPool *pool = link->pool; - if(pool) for(i=0; ipic[i]; - if(picref && picref->buf->format == link->format && picref->buf->w == w && picref->buf->h == h){ - AVFilterBuffer *pic= picref->buf; - pool->pic[i]= NULL; + if (pool) for (i = 0; i < POOL_SIZE; i++) { + picref = pool->pic[i]; + if (picref && picref->buf->format == link->format && picref->buf->w == w && picref->buf->h == h) { + AVFilterBuffer *pic = picref->buf; + pool->pic[i] = NULL; pool->count--; picref->video->w = w; picref->video->h = h; picref->perms = perms | AV_PERM_READ; - picref->format= link->format; + picref->format = link->format; pic->refcount = 1; memcpy(picref->data, pic->data, sizeof(picref->data)); memcpy(picref->linesize, pic->linesize, sizeof(picref->linesize)); return picref; } - }else + } else pool = link->pool = av_mallocz(sizeof(AVFilterPool)); // +2 is needed for swscaler, +16 to be SIMD-friendly - if ((i=av_image_alloc(data, linesize, w, h, link->format, 16)) < 0) + if ((i = av_image_alloc(data, linesize, w, h, link->format, 16)) < 0) return NULL; picref = avfilter_get_video_buffer_ref_from_arrays(data, linesize, @@ -72,8 +72,8 @@ AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link, int per } memset(data[0], 128, i); - picref->buf->priv= pool; - picref->buf->free= NULL; + picref->buf->priv = pool; + picref->buf->free = NULL; return picref; } diff --git a/libavfilter/internal.h b/libavfilter/internal.h index 333dcbff81..be1e9b08f2 100644 --- a/libavfilter/internal.h +++ b/libavfilter/internal.h @@ -31,7 +31,7 @@ typedef struct AVFilterPool { AVFilterBufferRef *pic[POOL_SIZE]; int count; -}AVFilterPool; +} AVFilterPool; /** * Check for the validity of graph. -- cgit v1.2.3 From 0ff5cbedd2b6e813064fe4f8aab735162889037c Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Thu, 2 Jun 2011 16:27:56 +0200 Subject: lavfi: clarify the context of a comment in avfilter_default_get_video_buffer() The comment is meant to be about the align parameter. --- libavfilter/defaults.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libavfilter') diff --git a/libavfilter/defaults.c b/libavfilter/defaults.c index 74ba599f9c..4a01b10b9c 100644 --- a/libavfilter/defaults.c +++ b/libavfilter/defaults.c @@ -60,7 +60,7 @@ AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link, int per } else pool = link->pool = av_mallocz(sizeof(AVFilterPool)); - // +2 is needed for swscaler, +16 to be SIMD-friendly + // align: +2 is needed for swscaler, +16 to be SIMD-friendly if ((i = av_image_alloc(data, linesize, w, h, link->format, 16)) < 0) return NULL; -- cgit v1.2.3 From 6f1dd6f45a641ca7670c7b00fbeea42420b89ada Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Thu, 2 Jun 2011 16:33:25 +0200 Subject: lavfi: add braces around the block of an if() expression in avfilter_default_get_video_buffer Clarify code layout. --- libavfilter/defaults.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'libavfilter') diff --git a/libavfilter/defaults.c b/libavfilter/defaults.c index 4a01b10b9c..c83d500652 100644 --- a/libavfilter/defaults.c +++ b/libavfilter/defaults.c @@ -42,7 +42,8 @@ AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link, int per AVFilterBufferRef *picref = NULL; AVFilterPool *pool = link->pool; - if (pool) for (i = 0; i < POOL_SIZE; i++) { + if (pool) { + for (i = 0; i < POOL_SIZE; i++) { picref = pool->pic[i]; if (picref && picref->buf->format == link->format && picref->buf->w == w && picref->buf->h == h) { AVFilterBuffer *pic = picref->buf; @@ -57,6 +58,7 @@ AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link, int per memcpy(picref->linesize, pic->linesize, sizeof(picref->linesize)); return picref; } + } } else pool = link->pool = av_mallocz(sizeof(AVFilterPool)); -- cgit v1.2.3 From 665e608c8d920d83216e1b8fd1445ee335528f13 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Thu, 2 Jun 2011 16:36:12 +0200 Subject: lavfi: reindent after the previous commit --- libavfilter/defaults.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/defaults.c b/libavfilter/defaults.c index c83d500652..a994f36079 100644 --- a/libavfilter/defaults.c +++ b/libavfilter/defaults.c @@ -44,20 +44,20 @@ AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link, int per if (pool) { for (i = 0; i < POOL_SIZE; i++) { - picref = pool->pic[i]; - if (picref && picref->buf->format == link->format && picref->buf->w == w && picref->buf->h == h) { - AVFilterBuffer *pic = picref->buf; - pool->pic[i] = NULL; - pool->count--; - picref->video->w = w; - picref->video->h = h; - picref->perms = perms | AV_PERM_READ; - picref->format = link->format; - pic->refcount = 1; - memcpy(picref->data, pic->data, sizeof(picref->data)); - memcpy(picref->linesize, pic->linesize, sizeof(picref->linesize)); - return picref; - } + picref = pool->pic[i]; + if (picref && picref->buf->format == link->format && picref->buf->w == w && picref->buf->h == h) { + AVFilterBuffer *pic = picref->buf; + pool->pic[i] = NULL; + pool->count--; + picref->video->w = w; + picref->video->h = h; + picref->perms = perms | AV_PERM_READ; + picref->format = link->format; + pic->refcount = 1; + memcpy(picref->data, pic->data, sizeof(picref->data)); + memcpy(picref->linesize, pic->linesize, sizeof(picref->linesize)); + return picref; + } } } else pool = link->pool = av_mallocz(sizeof(AVFilterPool)); -- cgit v1.2.3 From 9e66b64c360568a91faa84d0cda96ab93c467502 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Thu, 2 Jun 2011 16:09:24 +0200 Subject: vsrc_buffer: propagate error code in av_vsrc_buffer_add_frame() Propagate av_vsrc_buffer_add_video_buffer_ref() error code rather than return 0. --- libavfilter/vsrc_buffer.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/vsrc_buffer.c b/libavfilter/vsrc_buffer.c index d1e6ffd57a..9ba7d4ee47 100644 --- a/libavfilter/vsrc_buffer.c +++ b/libavfilter/vsrc_buffer.c @@ -111,15 +111,16 @@ int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, AVFilter int av_vsrc_buffer_add_frame(AVFilterContext *buffer_src, const AVFrame *frame) { + int ret; AVFilterBufferRef *picref = avfilter_get_video_buffer_ref_from_frame(frame, AV_PERM_WRITE); if (!picref) return AVERROR(ENOMEM); - av_vsrc_buffer_add_video_buffer_ref(buffer_src, picref); + ret = av_vsrc_buffer_add_video_buffer_ref(buffer_src, picref); picref->buf->data[0] = NULL; avfilter_unref_buffer(picref); - return 0; + return ret; } #endif -- cgit v1.2.3 From e977ca2645cc6b23589ddf97ab08861064ba8792 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Thu, 2 Jun 2011 17:45:33 +0200 Subject: lavfi: add avfilter_link_free() function Allow to free the buffers cached in each AVFilterLink pool. Fix leak. --- libavfilter/avfilter.c | 29 +++++++++++++++++++++++++++-- libavfilter/avfilter.h | 7 ++++++- 2 files changed, 33 insertions(+), 3 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index b7ad6f0503..037d5864ae 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -165,6 +165,31 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad, return 0; } +void avfilter_link_free(AVFilterLink **link) +{ + if (!*link) + return; + + if ((*link)->pool) { + int i; + for (i = 0; i < POOL_SIZE; i++) { + if ((*link)->pool->pic[i]) { + AVFilterBufferRef *picref = (*link)->pool->pic[i]; + /* free buffer: picrefs stored in the pool are not + * supposed to contain a free callback */ + av_freep(&picref->buf->data[0]); + av_freep(&picref->buf); + + av_freep(&picref->audio); + av_freep(&picref->video); + av_freep(&picref); + } + } + av_freep(&(*link)->pool); + } + av_freep(link); +} + int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt, unsigned filt_srcpad_idx, unsigned filt_dstpad_idx) { @@ -683,7 +708,7 @@ void avfilter_free(AVFilterContext *filter) avfilter_formats_unref(&link->in_formats); avfilter_formats_unref(&link->out_formats); } - av_freep(&link); + avfilter_link_free(&link); } for (i = 0; i < filter->output_count; i++) { if ((link = filter->outputs[i])) { @@ -692,7 +717,7 @@ void avfilter_free(AVFilterContext *filter) avfilter_formats_unref(&link->in_formats); avfilter_formats_unref(&link->out_formats); } - av_freep(&link); + avfilter_link_free(&link); } av_freep(&filter->name); diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 602b2437d9..e8e2a8b9d1 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -26,7 +26,7 @@ #include "libavutil/samplefmt.h" #define LIBAVFILTER_VERSION_MAJOR 2 -#define LIBAVFILTER_VERSION_MINOR 11 +#define LIBAVFILTER_VERSION_MINOR 12 #define LIBAVFILTER_VERSION_MICRO 0 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ @@ -635,6 +635,11 @@ struct AVFilterLink { int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad); +/** + * Free the link in *link, and set its pointer to NULL. + */ +void avfilter_link_free(AVFilterLink **link); + /** * Negotiate the media format, dimensions, etc of all inputs to a filter. * -- cgit v1.2.3 From 612d0782fc885aaa0bbb8f8966d425ea91a606cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= Date: Wed, 1 Jun 2011 20:44:08 +0200 Subject: Add const to avfilter_get_video_buffer_ref_from_arrays arguments. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoids warning about discarding qualifiers in avcodec.c Signed-off-by: Reimar Döffinger --- libavfilter/avfilter.c | 2 +- libavfilter/avfilter.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 037d5864ae..fae3c6c5f2 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -365,7 +365,7 @@ AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms, int } AVFilterBufferRef * -avfilter_get_video_buffer_ref_from_arrays(uint8_t *data[4], int linesize[4], int perms, +avfilter_get_video_buffer_ref_from_arrays(uint8_t * const data[4], const int linesize[4], int perms, int w, int h, enum PixelFormat format) { AVFilterBuffer *pic = av_mallocz(sizeof(AVFilterBuffer)); diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index e8e2a8b9d1..4ff68cd180 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -674,7 +674,7 @@ AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms, * @param format the pixel format of the image specified by the data and linesize arrays */ AVFilterBufferRef * -avfilter_get_video_buffer_ref_from_arrays(uint8_t *data[4], int linesize[4], int perms, +avfilter_get_video_buffer_ref_from_arrays(uint8_t * const data[4], const int linesize[4], int perms, int w, int h, enum PixelFormat format); /** -- cgit v1.2.3 From 27bcf55f459e038e81f09c17e72e6d44898b9015 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Thu, 2 Jun 2011 15:43:21 +0200 Subject: vsrc_buffer: add flags param to av_vsrc_buffer_add_video_buffer_ref The new flags parameter allows to specify if the video ref to add should overwrite the cache, if the flag is not set vsrc_buffer will complain and abort; otherwise it will clean the already cached video ref before to overwrite it, thus avoiding a leak. --- libavfilter/avcodec.h | 5 ++++- libavfilter/avfilter.h | 2 +- libavfilter/vsrc_buffer.c | 22 ++++++++++++++-------- libavfilter/vsrc_buffer.h | 11 ++++++++++- 4 files changed, 29 insertions(+), 11 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/avcodec.h b/libavfilter/avcodec.h index 74434e819d..4eed6b2d2c 100644 --- a/libavfilter/avcodec.h +++ b/libavfilter/avcodec.h @@ -30,6 +30,7 @@ #include "libavcodec/avcodec.h" // AVFrame #include "avfilter.h" +#include "vsrc_buffer.h" /** * Copy the frame properties of src to dst, without copying the actual @@ -49,9 +50,11 @@ AVFilterBufferRef *avfilter_get_video_buffer_ref_from_frame(const AVFrame *frame * Add frame data to buffer_src. * * @param buffer_src pointer to a buffer source context + * @param flags a combination of AV_VSRC_BUF_FLAG_* flags * @return >= 0 in case of success, a negative AVERROR code in case of * failure */ -int av_vsrc_buffer_add_frame(AVFilterContext *buffer_src, const AVFrame *frame); +int av_vsrc_buffer_add_frame(AVFilterContext *buffer_src, + const AVFrame *frame, int flags); #endif /* AVFILTER_AVCODEC_H */ diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 4ff68cd180..c7612f2004 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -26,7 +26,7 @@ #include "libavutil/samplefmt.h" #define LIBAVFILTER_VERSION_MAJOR 2 -#define LIBAVFILTER_VERSION_MINOR 12 +#define LIBAVFILTER_VERSION_MINOR 13 #define LIBAVFILTER_VERSION_MICRO 0 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ diff --git a/libavfilter/vsrc_buffer.c b/libavfilter/vsrc_buffer.c index 9ba7d4ee47..246444b3ac 100644 --- a/libavfilter/vsrc_buffer.c +++ b/libavfilter/vsrc_buffer.c @@ -37,18 +37,23 @@ typedef struct { char sws_param[256]; } BufferSourceContext; -int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, AVFilterBufferRef *picref) +int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, + AVFilterBufferRef *picref, int flags) { BufferSourceContext *c = buffer_filter->priv; AVFilterLink *outlink = buffer_filter->outputs[0]; int ret; if (c->picref) { - av_log(buffer_filter, AV_LOG_ERROR, - "Buffering several frames is not supported. " - "Please consume all available frames before adding a new one.\n" - ); - //return -1; + if (flags & AV_VSRC_BUF_FLAG_OVERWRITE) { + avfilter_unref_buffer(c->picref); + c->picref = NULL; + } else { + av_log(buffer_filter, AV_LOG_ERROR, + "Buffering several frames is not supported. " + "Please consume all available frames before adding a new one.\n"); + return AVERROR(EINVAL); + } } if (picref->video->w != c->w || picref->video->h != c->h || picref->format != c->pix_fmt) { @@ -109,14 +114,15 @@ int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, AVFilter #if CONFIG_AVCODEC #include "avcodec.h" -int av_vsrc_buffer_add_frame(AVFilterContext *buffer_src, const AVFrame *frame) +int av_vsrc_buffer_add_frame(AVFilterContext *buffer_src, + const AVFrame *frame, int flags) { int ret; AVFilterBufferRef *picref = avfilter_get_video_buffer_ref_from_frame(frame, AV_PERM_WRITE); if (!picref) return AVERROR(ENOMEM); - ret = av_vsrc_buffer_add_video_buffer_ref(buffer_src, picref); + ret = av_vsrc_buffer_add_video_buffer_ref(buffer_src, picref, flags); picref->buf->data[0] = NULL; avfilter_unref_buffer(picref); diff --git a/libavfilter/vsrc_buffer.h b/libavfilter/vsrc_buffer.h index c717f3dae4..b661d414ea 100644 --- a/libavfilter/vsrc_buffer.h +++ b/libavfilter/vsrc_buffer.h @@ -28,13 +28,22 @@ #include "avfilter.h" +/** + * Tell av_vsrc_buffer_add_video_buffer_ref() to overwrite the already + * cached video buffer with the new added one, otherwise the function + * will complain and exit. + */ +#define AV_VSRC_BUF_FLAG_OVERWRITE 1 + /** * Add video buffer data in picref to buffer_src. * * @param buffer_src pointer to a buffer source context + * @param flags a combination of AV_VSRC_BUF_FLAG_* flags * @return >= 0 in case of success, a negative AVERROR code in case of * failure */ -int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_src, AVFilterBufferRef *picref); +int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_src, + AVFilterBufferRef *picref, int flags); #endif /* AVFILTER_VSRC_BUFFER_H */ -- cgit v1.2.3 From 95a0242642e8ee345f6545ea7f9b042989272729 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Tue, 1 Feb 2011 12:34:23 +0100 Subject: lavfi: prefer nb_samples over size in AVFilterBufferRefAudioProps Remove AVFilterBufferRefAudioProps.size, and use nb_samples in avfilter_get_audio_buffer() and avfilter_default_get_audio_buffer() in place of size. This is required as the size in the audio buffer may be aligned, so it may not contain a well defined number of samples. --- libavfilter/avfilter.c | 15 ++++++++------- libavfilter/avfilter.h | 13 ++++++------- libavfilter/defaults.c | 11 +++++------ 3 files changed, 19 insertions(+), 20 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index fae3c6c5f2..6d55350f7c 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -305,10 +305,9 @@ static void ff_dlog_ref(void *ctx, AVFilterBufferRef *ref, int end) av_get_picture_type_char(ref->video->pict_type)); } if (ref->audio) { - av_dlog(ctx, " cl:%"PRId64"d sn:%d s:%d sr:%d p:%d", + av_dlog(ctx, " cl:%"PRId64"d n:%d r:%d p:%d", ref->audio->channel_layout, ref->audio->nb_samples, - ref->audio->size, ref->audio->sample_rate, ref->audio->planar); } @@ -405,16 +404,16 @@ fail: } AVFilterBufferRef *avfilter_get_audio_buffer(AVFilterLink *link, int perms, - enum AVSampleFormat sample_fmt, int size, + enum AVSampleFormat sample_fmt, int nb_samples, int64_t channel_layout, int planar) { AVFilterBufferRef *ret = NULL; if (link->dstpad->get_audio_buffer) - ret = link->dstpad->get_audio_buffer(link, perms, sample_fmt, size, channel_layout, planar); + ret = link->dstpad->get_audio_buffer(link, perms, sample_fmt, nb_samples, channel_layout, planar); if (!ret) - ret = avfilter_default_get_audio_buffer(link, perms, sample_fmt, size, channel_layout, planar); + ret = avfilter_default_get_audio_buffer(link, perms, sample_fmt, nb_samples, channel_layout, planar); if (ret) ret->type = AVMEDIA_TYPE_AUDIO; @@ -545,6 +544,7 @@ void avfilter_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) { void (*filter_samples)(AVFilterLink *, AVFilterBufferRef *); AVFilterPad *dst = link->dstpad; + int i; FF_DPRINTF_START(NULL, filter_samples); ff_dlog_link(NULL, link, 1); @@ -561,14 +561,15 @@ void avfilter_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) link->cur_buf = avfilter_default_get_audio_buffer(link, dst->min_perms, samplesref->format, - samplesref->audio->size, + samplesref->audio->nb_samples, samplesref->audio->channel_layout, samplesref->audio->planar); link->cur_buf->pts = samplesref->pts; link->cur_buf->audio->sample_rate = samplesref->audio->sample_rate; /* Copy actual data into new samples buffer */ - memcpy(link->cur_buf->data[0], samplesref->data[0], samplesref->audio->size); + for (i = 0; samplesref->data[i]; i++) + memcpy(link->cur_buf->data[i], samplesref->data[i], samplesref->linesize[0]); avfilter_unref_buffer(samplesref); } else diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index c7612f2004..541dbe7aa7 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -26,7 +26,7 @@ #include "libavutil/samplefmt.h" #define LIBAVFILTER_VERSION_MAJOR 2 -#define LIBAVFILTER_VERSION_MINOR 13 +#define LIBAVFILTER_VERSION_MINOR 14 #define LIBAVFILTER_VERSION_MICRO 0 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ @@ -98,8 +98,7 @@ typedef struct AVFilterBuffer { */ typedef struct AVFilterBufferRefAudioProps { int64_t channel_layout; ///< channel layout of audio buffer - int nb_samples; ///< number of audio samples - int size; ///< audio buffer size + int nb_samples; ///< number of audio samples per channel uint32_t sample_rate; ///< audio buffer sample rate int planar; ///< audio buffer - planar or packed } AVFilterBufferRefAudioProps; @@ -372,7 +371,7 @@ struct AVFilterPad { * Input audio pads only. */ AVFilterBufferRef *(*get_audio_buffer)(AVFilterLink *link, int perms, - enum AVSampleFormat sample_fmt, int size, + enum AVSampleFormat sample_fmt, int nb_samples, int64_t channel_layout, int planar); /** @@ -461,7 +460,7 @@ AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link, /** default handler for get_audio_buffer() for audio inputs */ AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int perms, - enum AVSampleFormat sample_fmt, int size, + enum AVSampleFormat sample_fmt, int nb_samples, int64_t channel_layout, int planar); /** @@ -684,14 +683,14 @@ avfilter_get_video_buffer_ref_from_arrays(uint8_t * const data[4], const int lin * be requested * @param perms the required access permissions * @param sample_fmt the format of each sample in the buffer to allocate - * @param size the buffer size in bytes + * @param nb_samples the number of samples per channel * @param channel_layout the number and type of channels per sample in the buffer to allocate * @param planar audio data layout - planar or packed * @return A reference to the samples. This must be unreferenced with * avfilter_unref_buffer when you are finished with it. */ AVFilterBufferRef *avfilter_get_audio_buffer(AVFilterLink *link, int perms, - enum AVSampleFormat sample_fmt, int size, + enum AVSampleFormat sample_fmt, int nb_samples, int64_t channel_layout, int planar); /** diff --git a/libavfilter/defaults.c b/libavfilter/defaults.c index a994f36079..996c0f0589 100644 --- a/libavfilter/defaults.c +++ b/libavfilter/defaults.c @@ -81,7 +81,7 @@ AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link, int per } AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int perms, - enum AVSampleFormat sample_fmt, int size, + enum AVSampleFormat sample_fmt, int nb_samples, int64_t channel_layout, int planar) { AVFilterBuffer *samples = av_mallocz(sizeof(AVFilterBuffer)); @@ -100,7 +100,7 @@ AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int per goto fail; ref->audio->channel_layout = channel_layout; - ref->audio->size = size; + ref->audio->nb_samples = nb_samples; ref->audio->planar = planar; /* make sure the buffer gets read permission or it's useless for output */ @@ -112,8 +112,7 @@ AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int per sample_size = av_get_bits_per_sample_fmt(sample_fmt) >>3; chans_nb = av_get_channel_layout_nb_channels(channel_layout); - per_channel_size = size/chans_nb; - ref->audio->nb_samples = per_channel_size/sample_size; + per_channel_size = nb_samples * sample_size; /* Set the number of bytes to traverse to reach next sample of a particular channel: * For planar, this is simply the sample size. @@ -124,7 +123,7 @@ AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int per memset(&samples->linesize[chans_nb], 0, (8-chans_nb) * sizeof(samples->linesize[0])); /* Calculate total buffer size, round to multiple of 16 to be SIMD friendly */ - bufsize = (size + 15)&~15; + bufsize = (nb_samples * chans_nb * sample_size + 15)&~15; buf = av_malloc(bufsize); if (!buf) goto fail; @@ -212,7 +211,7 @@ void avfilter_default_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *sa if (outlink) { outlink->out_buf = avfilter_default_get_audio_buffer(inlink, AV_PERM_WRITE, samplesref->format, - samplesref->audio->size, + samplesref->audio->nb_samples, samplesref->audio->channel_layout, samplesref->audio->planar); outlink->out_buf->pts = samplesref->pts; -- cgit v1.2.3 From ef28c7b3a4f4513f7ea7c2f118eb806490d79546 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sat, 15 Jan 2011 18:48:37 +0100 Subject: lavfi: use av_samples_alloc() in avfilter_default_get_audio_buffer() --- libavfilter/defaults.c | 38 ++++---------------------------------- 1 file changed, 4 insertions(+), 34 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/defaults.c b/libavfilter/defaults.c index 996c0f0589..ce8f3cd0da 100644 --- a/libavfilter/defaults.c +++ b/libavfilter/defaults.c @@ -86,8 +86,7 @@ AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int per { AVFilterBuffer *samples = av_mallocz(sizeof(AVFilterBuffer)); AVFilterBufferRef *ref = NULL; - int i, sample_size, chans_nb, bufsize, per_channel_size, step_size = 0; - char *buf; + int nb_channels = av_get_channel_layout_nb_channels(channel_layout); if (!samples || !(ref = av_mallocz(sizeof(AVFilterBufferRef)))) goto fail; @@ -109,41 +108,12 @@ AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int per samples->refcount = 1; samples->free = ff_avfilter_default_free_buffer; - sample_size = av_get_bits_per_sample_fmt(sample_fmt) >>3; - chans_nb = av_get_channel_layout_nb_channels(channel_layout); - - per_channel_size = nb_samples * sample_size; - - /* Set the number of bytes to traverse to reach next sample of a particular channel: - * For planar, this is simply the sample size. - * For packed, this is the number of samples * sample_size. - */ - for (i = 0; i < chans_nb; i++) - samples->linesize[i] = planar > 0 ? per_channel_size : sample_size; - memset(&samples->linesize[chans_nb], 0, (8-chans_nb) * sizeof(samples->linesize[0])); - /* Calculate total buffer size, round to multiple of 16 to be SIMD friendly */ - bufsize = (nb_samples * chans_nb * sample_size + 15)&~15; - buf = av_malloc(bufsize); - if (!buf) + if (av_samples_alloc(samples->data, samples->linesize, + nb_channels, nb_samples, sample_fmt, + planar, 16) < 0) goto fail; - /* For planar, set the start point of each channel's data within the buffer - * For packed, set the start point of the entire buffer only - */ - samples->data[0] = buf; - if (buf && planar) { - for (i = 1; i < chans_nb; i++) { - step_size += per_channel_size; - samples->data[i] = buf + step_size; - } - } else { - for (i = 1; i < chans_nb; i++) - samples->data[i] = buf; - } - - memset(&samples->data[chans_nb], 0, (8-chans_nb) * sizeof(samples->data[0])); - memcpy(ref->data, samples->data, sizeof(ref->data)); memcpy(ref->linesize, samples->linesize, sizeof(ref->linesize)); -- cgit v1.2.3 From 47d2ca3205b53665328fe301879c339449db7a1d Mon Sep 17 00:00:00 2001 From: Mina Nagy Zaki Date: Tue, 7 Jun 2011 17:42:32 +0300 Subject: lavfi: handle NULL lists in avfilter_make_format_list --- libavfilter/avfilter.h | 5 +++-- libavfilter/formats.c | 13 ++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 541dbe7aa7..ac954ca198 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -27,7 +27,7 @@ #define LIBAVFILTER_VERSION_MAJOR 2 #define LIBAVFILTER_VERSION_MINOR 14 -#define LIBAVFILTER_VERSION_MICRO 0 +#define LIBAVFILTER_VERSION_MICRO 1 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ LIBAVFILTER_VERSION_MINOR, \ @@ -233,7 +233,8 @@ typedef struct AVFilterFormats { * Create a list of supported formats. This is intended for use in * AVFilter->query_formats(). * - * @param fmts list of media formats, terminated by -1 + * @param fmts list of media formats, terminated by -1. If NULL an + * empty list is created. * @return the format list, with no existing references */ AVFilterFormats *avfilter_make_format_list(const int *fmts); diff --git a/libavfilter/formats.c b/libavfilter/formats.c index 101ef09e5f..ec7fca3817 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -73,15 +73,18 @@ AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b) AVFilterFormats *avfilter_make_format_list(const int *fmts) { AVFilterFormats *formats; - int count; + int count = 0; - for (count = 0; fmts[count] != -1; count++) - ; + if (fmts) + for (count = 0; fmts[count] != -1; count++) + ; formats = av_mallocz(sizeof(AVFilterFormats)); - formats->formats = av_malloc(sizeof(*formats->formats) * count); formats->format_count = count; - memcpy(formats->formats, fmts, sizeof(*formats->formats) * count); + if (count) { + formats->formats = av_malloc(sizeof(*formats->formats) * count); + memcpy(formats->formats, fmts, sizeof(*formats->formats) * count); + } return formats; } -- cgit v1.2.3 From c3819600e2975cb5dc8ca07e0ea41f8204324e4a Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Mon, 31 Jan 2011 00:07:41 +0100 Subject: lavfi: implement avfilter_get_audio_buffer_ref_from_arrays() --- libavfilter/avfilter.c | 42 ++++++++++++++++++++++++++++++++++++++++++ libavfilter/avfilter.h | 21 +++++++++++++++++++-- 2 files changed, 61 insertions(+), 2 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 6d55350f7c..3b2e3ca2be 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -421,6 +421,48 @@ AVFilterBufferRef *avfilter_get_audio_buffer(AVFilterLink *link, int perms, return ret; } +AVFilterBufferRef * +avfilter_get_audio_buffer_ref_from_arrays(uint8_t *data[8], int linesize[8], int perms, + int nb_samples, enum AVSampleFormat sample_fmt, + int64_t channel_layout, int planar) +{ + AVFilterBuffer *samples = av_mallocz(sizeof(AVFilterBuffer)); + AVFilterBufferRef *samplesref = av_mallocz(sizeof(AVFilterBufferRef)); + + if (!samples || !samplesref) + goto fail; + + samplesref->buf = samples; + samplesref->buf->free = ff_avfilter_default_free_buffer; + if (!(samplesref->audio = av_mallocz(sizeof(AVFilterBufferRefAudioProps)))) + goto fail; + + samplesref->audio->nb_samples = nb_samples; + samplesref->audio->channel_layout = channel_layout; + samplesref->audio->planar = planar; + + /* make sure the buffer gets read permission or it's useless for output */ + samplesref->perms = perms | AV_PERM_READ; + + samples->refcount = 1; + samplesref->type = AVMEDIA_TYPE_AUDIO; + samplesref->format = sample_fmt; + + memcpy(samples->data, data, sizeof(samples->data)); + memcpy(samples->linesize, linesize, sizeof(samples->linesize)); + memcpy(samplesref->data, data, sizeof(samplesref->data)); + memcpy(samplesref->linesize, linesize, sizeof(samplesref->linesize)); + + return samplesref; + +fail: + if (samplesref && samplesref->audio) + av_freep(&samplesref->audio); + av_freep(&samplesref); + av_freep(&samples); + return NULL; +} + int avfilter_request_frame(AVFilterLink *link) { FF_DPRINTF_START(NULL, request_frame); ff_dlog_link(NULL, link, 1); diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index ac954ca198..4f5ed36004 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -26,8 +26,8 @@ #include "libavutil/samplefmt.h" #define LIBAVFILTER_VERSION_MAJOR 2 -#define LIBAVFILTER_VERSION_MINOR 14 -#define LIBAVFILTER_VERSION_MICRO 1 +#define LIBAVFILTER_VERSION_MINOR 15 +#define LIBAVFILTER_VERSION_MICRO 0 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ LIBAVFILTER_VERSION_MINOR, \ @@ -694,6 +694,23 @@ AVFilterBufferRef *avfilter_get_audio_buffer(AVFilterLink *link, int perms, enum AVSampleFormat sample_fmt, int nb_samples, int64_t channel_layout, int planar); +/** + * Create an audio buffer reference wrapped around an already + * allocated samples buffer. + * + * @param data pointers to the samples plane buffers + * @param linesize linesize for the samples plane buffers + * @param perms the required access permissions + * @param nb_samples number of samples per channel + * @param sample_fmt the format of each sample in the buffer to allocate + * @param channel_layout the channel layout of the buffer + * @param planar audio data layout - planar or packed + */ +AVFilterBufferRef * +avfilter_get_audio_buffer_ref_from_arrays(uint8_t *data[8], int linesize[8], int perms, + int nb_samples, enum AVSampleFormat sample_fmt, + int64_t channel_layout, int planar); + /** * Request an input frame from the filter at the other end of the link. * -- cgit v1.2.3 From 989184fea4854720caef35347992499ba8033195 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sat, 12 Feb 2011 17:56:50 +0100 Subject: lavfi: use avfilter_get_audio_buffer_ref_from_arrays() in defaults.c Use avfilter_get_audio_buffer_ref_from_arrays() in avfilter_default_get_audio_buffer(), simplify. --- libavfilter/defaults.c | 48 ++++++++++++++---------------------------------- 1 file changed, 14 insertions(+), 34 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/defaults.c b/libavfilter/defaults.c index ce8f3cd0da..c39ed64048 100644 --- a/libavfilter/defaults.c +++ b/libavfilter/defaults.c @@ -84,47 +84,27 @@ AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int per enum AVSampleFormat sample_fmt, int nb_samples, int64_t channel_layout, int planar) { - AVFilterBuffer *samples = av_mallocz(sizeof(AVFilterBuffer)); - AVFilterBufferRef *ref = NULL; + AVFilterBufferRef *samplesref = NULL; + int linesize[8]; + uint8_t *data[8]; int nb_channels = av_get_channel_layout_nb_channels(channel_layout); - if (!samples || !(ref = av_mallocz(sizeof(AVFilterBufferRef)))) - goto fail; - - ref->buf = samples; - ref->format = sample_fmt; - - ref->audio = av_mallocz(sizeof(AVFilterBufferRefAudioProps)); - if (!ref->audio) - goto fail; - - ref->audio->channel_layout = channel_layout; - ref->audio->nb_samples = nb_samples; - ref->audio->planar = planar; - - /* make sure the buffer gets read permission or it's useless for output */ - ref->perms = perms | AV_PERM_READ; - - samples->refcount = 1; - samples->free = ff_avfilter_default_free_buffer; - /* Calculate total buffer size, round to multiple of 16 to be SIMD friendly */ - if (av_samples_alloc(samples->data, samples->linesize, + if (av_samples_alloc(data, linesize, nb_channels, nb_samples, sample_fmt, planar, 16) < 0) - goto fail; - - memcpy(ref->data, samples->data, sizeof(ref->data)); - memcpy(ref->linesize, samples->linesize, sizeof(ref->linesize)); + return NULL; - return ref; + samplesref = + avfilter_get_audio_buffer_ref_from_arrays(data, linesize, perms, + nb_samples, sample_fmt, + channel_layout, planar); + if (!samplesref) { + av_free(data[0]); + return NULL; + } -fail: - if (ref) - av_free(ref->audio); - av_free(ref); - av_free(samples); - return NULL; + return samplesref; } void avfilter_default_start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) -- cgit v1.2.3 From 79a0ec1af4817bb7b989803b9f460d1e4acaf7b7 Mon Sep 17 00:00:00 2001 From: Mina Nagy Zaki Date: Wed, 8 Jun 2011 19:24:25 +0300 Subject: lavfi: avfilter_merge_formats: handle case where inputs are same This fixes a double-free crash if lists are the same due to the two merge_ref() calls at the end of the (useless) merging that happens. --- libavfilter/formats.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libavfilter') diff --git a/libavfilter/formats.c b/libavfilter/formats.c index ec7fca3817..58593fcce0 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -44,6 +44,8 @@ AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b) AVFilterFormats *ret; unsigned i, j, k = 0; + if (a == b) return a; + ret = av_mallocz(sizeof(AVFilterFormats)); /* merge list of formats */ -- cgit v1.2.3 From f5901fd392889dabe0d2eb9005e62ac667655b2f Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sat, 11 Jun 2011 11:15:40 +0200 Subject: avfiltergraph: use meaningful error codes --- libavfilter/avfiltergraph.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index bdf22b3df9..d19fc59f00 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -90,7 +90,7 @@ int ff_avfilter_graph_check_validity(AVFilterGraph *graph, AVClass *log_ctx) av_log(log_ctx, AV_LOG_ERROR, "Input pad \"%s\" for the filter \"%s\" of type \"%s\" not connected to any source\n", filt->input_pads[j].name, filt->name, filt->filter->name); - return -1; + return AVERROR(EINVAL); } } @@ -99,7 +99,7 @@ int ff_avfilter_graph_check_validity(AVFilterGraph *graph, AVClass *log_ctx) av_log(log_ctx, AV_LOG_ERROR, "Output pad \"%s\" for the filter \"%s\" of type \"%s\" not connected to any destination\n", filt->output_pads[j].name, filt->name, filt->filter->name); - return -1; + return AVERROR(EINVAL); } } } @@ -178,7 +178,7 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx) av_log(log_ctx, AV_LOG_ERROR, "Impossible to convert between the formats supported by the filter " "'%s' and the filter '%s'\n", link->src->name, link->dst->name); - return -1; + return AVERROR(EINVAL); } } } @@ -216,9 +216,11 @@ static void pick_formats(AVFilterGraph *graph) int ff_avfilter_graph_config_formats(AVFilterGraph *graph, AVClass *log_ctx) { + int ret; + /* find supported formats from sub-filters, and merge along links */ - if (query_formats(graph, log_ctx)) - return -1; + if ((ret = query_formats(graph, log_ctx)) < 0) + return ret; /* Once everything is merged, it's possible that we'll still have * multiple valid media format choices. We pick the first one. */ -- cgit v1.2.3 From d468ed032169c8007ed24cb2adfbee3a842eb742 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sat, 11 Jun 2011 11:41:49 +0200 Subject: lavfi: fix signature for avfilter_graph_parse() and avfilter_graph_config() Require "void *" rather than "AVClass *" for the log context type. --- libavfilter/avfilter.h | 2 +- libavfilter/avfiltergraph.c | 2 +- libavfilter/avfiltergraph.h | 4 ++-- libavfilter/graphparser.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 4f5ed36004..64d76cc0c9 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -27,7 +27,7 @@ #define LIBAVFILTER_VERSION_MAJOR 2 #define LIBAVFILTER_VERSION_MINOR 15 -#define LIBAVFILTER_VERSION_MICRO 0 +#define LIBAVFILTER_VERSION_MICRO 1 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ LIBAVFILTER_VERSION_MINOR, \ diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index d19fc59f00..60d529ba73 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -229,7 +229,7 @@ int ff_avfilter_graph_config_formats(AVFilterGraph *graph, AVClass *log_ctx) return 0; } -int avfilter_graph_config(AVFilterGraph *graphctx, AVClass *log_ctx) +int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx) { int ret; diff --git a/libavfilter/avfiltergraph.h b/libavfilter/avfiltergraph.h index 8013b46f5b..23a7c5138f 100644 --- a/libavfilter/avfiltergraph.h +++ b/libavfilter/avfiltergraph.h @@ -76,7 +76,7 @@ int avfilter_graph_create_filter(AVFilterContext **filt_ctx, AVFilter *filt, * @param log_ctx context used for logging * @return 0 in case of success, a negative AVERROR code otherwise */ -int avfilter_graph_config(AVFilterGraph *graphctx, AVClass *log_ctx); +int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx); /** * Free a graph, destroy its links, and set *graph to NULL. @@ -118,6 +118,6 @@ typedef struct AVFilterInOut { */ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, AVFilterInOut *inputs, AVFilterInOut *outputs, - AVClass *log_ctx); + void *log_ctx); #endif /* AVFILTER_AVFILTERGRAPH_H */ diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c index 4f11529900..b7a2232270 100644 --- a/libavfilter/graphparser.c +++ b/libavfilter/graphparser.c @@ -329,7 +329,7 @@ static int parse_outputs(const char **buf, AVFilterInOut **curr_inputs, int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, AVFilterInOut *open_inputs, - AVFilterInOut *open_outputs, AVClass *log_ctx) + AVFilterInOut *open_outputs, void *log_ctx) { int index = 0, ret; char chr = 0; -- cgit v1.2.3 From 86909dd5f7cbc3d2446fad58268553ac06f65e37 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sat, 11 Jun 2011 14:33:09 +0200 Subject: graphparser: prefer void * over AVClass * for log contexts --- libavfilter/graphparser.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c index b7a2232270..aa1f228f81 100644 --- a/libavfilter/graphparser.c +++ b/libavfilter/graphparser.c @@ -36,7 +36,7 @@ */ static int link_filter(AVFilterContext *src, int srcpad, AVFilterContext *dst, int dstpad, - AVClass *log_ctx) + void *log_ctx) { int ret; if ((ret = avfilter_link(src, srcpad, dst, dstpad))) { @@ -55,7 +55,7 @@ static int link_filter(AVFilterContext *src, int srcpad, * @return a pointer (that need to be freed after use) to the name * between parenthesis */ -static char *parse_link_name(const char **buf, AVClass *log_ctx) +static char *parse_link_name(const char **buf, void *log_ctx) { const char *start = *buf; char *name; @@ -92,7 +92,7 @@ static char *parse_link_name(const char **buf, AVClass *log_ctx) * @return 0 in case of success, a negative AVERROR code otherwise */ static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int index, - const char *filt_name, const char *args, AVClass *log_ctx) + const char *filt_name, const char *args, void *log_ctx) { AVFilter *filt; char inst_name[30]; @@ -151,7 +151,7 @@ static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int ind * @return 0 in case of success, a negative AVERROR code otherwise */ static int parse_filter(AVFilterContext **filt_ctx, const char **buf, AVFilterGraph *graph, - int index, AVClass *log_ctx) + int index, void *log_ctx) { char *opts = NULL; char *name = av_get_token(buf, "=,;[\n"); @@ -201,7 +201,7 @@ static void insert_inout(AVFilterInOut **inouts, AVFilterInOut *element) static int link_filter_inouts(AVFilterContext *filt_ctx, AVFilterInOut **curr_inputs, - AVFilterInOut **open_inputs, AVClass *log_ctx) + AVFilterInOut **open_inputs, void *log_ctx) { int pad = filt_ctx->input_count, ret; @@ -249,7 +249,7 @@ static int link_filter_inouts(AVFilterContext *filt_ctx, } static int parse_inputs(const char **buf, AVFilterInOut **curr_inputs, - AVFilterInOut **open_outputs, AVClass *log_ctx) + AVFilterInOut **open_outputs, void *log_ctx) { int pad = 0; @@ -284,7 +284,7 @@ static int parse_inputs(const char **buf, AVFilterInOut **curr_inputs, static int parse_outputs(const char **buf, AVFilterInOut **curr_inputs, AVFilterInOut **open_inputs, - AVFilterInOut **open_outputs, AVClass *log_ctx) + AVFilterInOut **open_outputs, void *log_ctx) { int ret, pad = 0; -- cgit v1.2.3 From 6119b23a3662d1e106cdf69ef3171b2e7e1d495c Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sat, 11 Jun 2011 15:16:02 +0200 Subject: avfiltergraph: change the syntax of avfilter_graph_parse() Make it returns the list of open inputs and outputs, so it can be reused by applications. Breaks API/ABI. --- libavfilter/avfilter.h | 4 ++-- libavfilter/avfiltergraph.h | 8 +++++--- libavfilter/graphparser.c | 20 ++++++++++---------- 3 files changed, 17 insertions(+), 15 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 64d76cc0c9..fbd1dc457f 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -26,8 +26,8 @@ #include "libavutil/samplefmt.h" #define LIBAVFILTER_VERSION_MAJOR 2 -#define LIBAVFILTER_VERSION_MINOR 15 -#define LIBAVFILTER_VERSION_MICRO 1 +#define LIBAVFILTER_VERSION_MINOR 16 +#define LIBAVFILTER_VERSION_MICRO 0 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ LIBAVFILTER_VERSION_MINOR, \ diff --git a/libavfilter/avfiltergraph.h b/libavfilter/avfiltergraph.h index 23a7c5138f..538fd2cb95 100644 --- a/libavfilter/avfiltergraph.h +++ b/libavfilter/avfiltergraph.h @@ -112,12 +112,14 @@ typedef struct AVFilterInOut { * * @param graph the filter graph where to link the parsed graph context * @param filters string to be parsed - * @param inputs linked list to the inputs of the graph - * @param outputs linked list to the outputs of the graph + * @param inputs linked list to the inputs of the graph, may be NULL. + * It is updated to contain the list of open inputs after the parsing. + * @param outputs linked list to the outputs of the graph, may be NULL. + * It is updated to contain the list of open outputs after the parsing. * @return zero on success, a negative AVERROR code on error */ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, - AVFilterInOut *inputs, AVFilterInOut *outputs, + AVFilterInOut **inputs, AVFilterInOut **outputs, void *log_ctx); #endif /* AVFILTER_AVFILTERGRAPH_H */ diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c index aa1f228f81..ea0c5dda7f 100644 --- a/libavfilter/graphparser.c +++ b/libavfilter/graphparser.c @@ -328,8 +328,8 @@ static int parse_outputs(const char **buf, AVFilterInOut **curr_inputs, } int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, - AVFilterInOut *open_inputs, - AVFilterInOut *open_outputs, void *log_ctx) + AVFilterInOut **open_inputs, AVFilterInOut **open_outputs, + void *log_ctx) { int index = 0, ret; char chr = 0; @@ -341,7 +341,7 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, const char *filterchain = filters; filters += strspn(filters, WHITESPACES); - if ((ret = parse_inputs(&filters, &curr_inputs, &open_outputs, log_ctx)) < 0) + if ((ret = parse_inputs(&filters, &curr_inputs, open_outputs, log_ctx)) < 0) goto fail; if ((ret = parse_filter(&filter, &filters, graph, index, log_ctx)) < 0) @@ -350,14 +350,14 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, if (filter->input_count == 1 && !curr_inputs && !index) { /* First input can be omitted if it is "[in]" */ const char *tmp = "[in]"; - if ((ret = parse_inputs(&tmp, &curr_inputs, &open_outputs, log_ctx)) < 0) + if ((ret = parse_inputs(&tmp, &curr_inputs, open_outputs, log_ctx)) < 0) goto fail; } - if ((ret = link_filter_inouts(filter, &curr_inputs, &open_inputs, log_ctx)) < 0) + if ((ret = link_filter_inouts(filter, &curr_inputs, open_inputs, log_ctx)) < 0) goto fail; - if ((ret = parse_outputs(&filters, &curr_inputs, &open_inputs, &open_outputs, + if ((ret = parse_outputs(&filters, &curr_inputs, open_inputs, open_outputs, log_ctx)) < 0) goto fail; @@ -382,10 +382,10 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, goto fail; } - if (open_inputs && !strcmp(open_inputs->name, "out") && curr_inputs) { + if (*open_inputs && !strcmp((*open_inputs)->name, "out") && curr_inputs) { /* Last output can be omitted if it is "[out]" */ const char *tmp = "[out]"; - if ((ret = parse_outputs(&tmp, &curr_inputs, &open_inputs, &open_outputs, + if ((ret = parse_outputs(&tmp, &curr_inputs, open_inputs, open_outputs, log_ctx)) < 0) goto fail; } @@ -396,8 +396,8 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, for (; graph->filter_count > 0; graph->filter_count--) avfilter_free(graph->filters[graph->filter_count - 1]); av_freep(&graph->filters); - free_inout(open_inputs); - free_inout(open_outputs); + free_inout(*open_inputs); + free_inout(*open_outputs); free_inout(curr_inputs); return ret; } -- cgit v1.2.3 From c535494268069282cc1147c4d61d4a88ce39e078 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sat, 11 Jun 2011 15:30:46 +0200 Subject: avfiltergraph: make the AVFilterInOut alloc/free API public This is required for letting applications to create and destroy AVFilterInOut structs in a convenient way. --- libavfilter/avfilter.h | 2 +- libavfilter/avfiltergraph.h | 18 ++++++++++++++++-- libavfilter/graphparser.c | 23 ++++++++++++++--------- 3 files changed, 31 insertions(+), 12 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index fbd1dc457f..84fa32e64e 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -26,7 +26,7 @@ #include "libavutil/samplefmt.h" #define LIBAVFILTER_VERSION_MAJOR 2 -#define LIBAVFILTER_VERSION_MINOR 16 +#define LIBAVFILTER_VERSION_MINOR 17 #define LIBAVFILTER_VERSION_MICRO 0 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ diff --git a/libavfilter/avfiltergraph.h b/libavfilter/avfiltergraph.h index 538fd2cb95..a975926fd1 100644 --- a/libavfilter/avfiltergraph.h +++ b/libavfilter/avfiltergraph.h @@ -107,15 +107,29 @@ typedef struct AVFilterInOut { struct AVFilterInOut *next; } AVFilterInOut; +/** + * Create an AVFilterInOut. + * Must be free with avfilter_inout_free(). + */ +AVFilterInOut *avfilter_inout_alloc(void); + +/** + * Free the AVFilterInOut in *inout, and set its pointer to NULL. + * If *inout is NULL, do nothing. + */ +void avfilter_inout_free(AVFilterInOut **inout); + /** * Add a graph described by a string to a graph. * * @param graph the filter graph where to link the parsed graph context * @param filters string to be parsed * @param inputs linked list to the inputs of the graph, may be NULL. - * It is updated to contain the list of open inputs after the parsing. + * It is updated to contain the list of open inputs after the parsing, + * should be freed with avfilter_inout_free(). * @param outputs linked list to the outputs of the graph, may be NULL. - * It is updated to contain the list of open outputs after the parsing. + * It is updated to contain the list of open outputs after the parsing, + * should be freed with avfilter_inout_free(). * @return zero on success, a negative AVERROR code on error */ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c index ea0c5dda7f..d62ba8d205 100644 --- a/libavfilter/graphparser.c +++ b/libavfilter/graphparser.c @@ -168,13 +168,18 @@ static int parse_filter(AVFilterContext **filt_ctx, const char **buf, AVFilterGr return ret; } -static void free_inout(AVFilterInOut *head) +AVFilterInOut *avfilter_inout_alloc(void) { - while (head) { - AVFilterInOut *next = head->next; - av_free(head->name); - av_free(head); - head = next; + return av_mallocz(sizeof(AVFilterInOut)); +} + +void avfilter_inout_free(AVFilterInOut **inout) +{ + while (*inout) { + AVFilterInOut *next = (*inout)->next; + av_freep(&(*inout)->name); + av_freep(inout); + *inout = next; } } @@ -396,8 +401,8 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, for (; graph->filter_count > 0; graph->filter_count--) avfilter_free(graph->filters[graph->filter_count - 1]); av_freep(&graph->filters); - free_inout(*open_inputs); - free_inout(*open_outputs); - free_inout(curr_inputs); + avfilter_inout_free(open_inputs); + avfilter_inout_free(open_outputs); + avfilter_inout_free(&curr_inputs); return ret; } -- cgit v1.2.3 From 3fe6bbd5dcdf603a8dac78b48adf6f0b6604143c Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sat, 11 Jun 2011 18:21:53 +0200 Subject: libavfilter: implement avfilter_fill_frame_from_video_buffer_ref() --- libavfilter/avcodec.c | 18 ++++++++++++++++++ libavfilter/avcodec.h | 11 +++++++++++ libavfilter/avfilter.h | 2 +- 3 files changed, 30 insertions(+), 1 deletion(-) (limited to 'libavfilter') diff --git a/libavfilter/avcodec.c b/libavfilter/avcodec.c index 50670bc55e..2010040d14 100644 --- a/libavfilter/avcodec.c +++ b/libavfilter/avcodec.c @@ -53,3 +53,21 @@ AVFilterBufferRef *avfilter_get_video_buffer_ref_from_frame(const AVFrame *frame avfilter_copy_frame_props(picref, frame); return picref; } + +int avfilter_fill_frame_from_video_buffer_ref(AVFrame *frame, + const AVFilterBufferRef *picref) +{ + if (!picref || !picref->video || !frame) + return AVERROR(EINVAL); + + memcpy(frame->data, picref->data, sizeof(frame->data)); + memcpy(frame->linesize, picref->linesize, sizeof(frame->linesize)); + frame->pkt_pos = picref->pos; + frame->interlaced_frame = picref->video->interlaced; + frame->top_field_first = picref->video->top_field_first; + frame->key_frame = picref->video->key_frame; + frame->pict_type = picref->video->pict_type; + frame->sample_aspect_ratio = picref->video->sample_aspect_ratio; + + return 0; +} diff --git a/libavfilter/avcodec.h b/libavfilter/avcodec.h index 4eed6b2d2c..dec5ae4a7c 100644 --- a/libavfilter/avcodec.h +++ b/libavfilter/avcodec.h @@ -46,6 +46,17 @@ void avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src); */ AVFilterBufferRef *avfilter_get_video_buffer_ref_from_frame(const AVFrame *frame, int perms); +/** + * Fill an AVFrame with the information stored in picref. + * + * @param frame an already allocated AVFrame + * @param picref a video buffer reference + * @return 0 in case of success, a negative AVERROR code in case of + * failure + */ +int avfilter_fill_frame_from_video_buffer_ref(AVFrame *frame, + const AVFilterBufferRef *picref); + /** * Add frame data to buffer_src. * diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 84fa32e64e..7628cd51ec 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -26,7 +26,7 @@ #include "libavutil/samplefmt.h" #define LIBAVFILTER_VERSION_MAJOR 2 -#define LIBAVFILTER_VERSION_MINOR 17 +#define LIBAVFILTER_VERSION_MINOR 18 #define LIBAVFILTER_VERSION_MICRO 0 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ -- cgit v1.2.3 From 9e2f448d68d9df7ad79d968db315c6b0cc79c4df Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Wed, 15 Jun 2011 01:36:12 +0200 Subject: vf_mp: Fix large memleak. Signed-off-by: Michael Niedermayer --- libavfilter/vf_mp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libavfilter') diff --git a/libavfilter/vf_mp.c b/libavfilter/vf_mp.c index 01a8f064a2..0642b44f00 100644 --- a/libavfilter/vf_mp.c +++ b/libavfilter/vf_mp.c @@ -882,7 +882,7 @@ static void end_frame(AVFilterLink *inlink) } free_mp_image(mpi); -// avfilter_unref_buffer(inpic); + avfilter_unref_buffer(inpic); } AVFilter avfilter_vf_mp = { -- cgit v1.2.3