[FFmpeg-devel] [PATCH] lavfi/testsrc: add support for color interactive command
Clément Bœsch
ubitux at gmail.com
Sun Apr 28 13:32:58 CEST 2013
On Wed, Apr 24, 2013 at 06:33:52PM +0200, Stefano Sabatini wrote:
> ---
> libavfilter/vsrc_testsrc.c | 29 +++++++++++++++++++++++++++++
> 1 file changed, 29 insertions(+)
>
> diff --git a/libavfilter/vsrc_testsrc.c b/libavfilter/vsrc_testsrc.c
> index 1b474a2..3c88194 100644
> --- a/libavfilter/vsrc_testsrc.c
> +++ b/libavfilter/vsrc_testsrc.c
> @@ -57,6 +57,7 @@ typedef struct {
> AVRational sar; ///< sample aspect ratio
> int nb_decimals;
> int draw_once; ///< draw only the first frame, always put out the same picture
> + int draw_once_reset; ///< draw only the first frame or in case of reset
> AVFrame *picref; ///< cached reference containing the painted picture
>
> void (* fill_picture_fn)(AVFilterContext *ctx, AVFrame *frame);
> @@ -166,6 +167,10 @@ static int request_frame(AVFilterLink *outlink)
> return AVERROR_EOF;
>
> if (test->draw_once) {
> + if (test->draw_once_reset) {
> + av_frame_free(&test->picref);
> + test->draw_once_reset = 0;
> + }
> if (!test->picref) {
> test->picref =
> ff_get_video_buffer(outlink, test->w, test->h);
> @@ -241,6 +246,29 @@ static int color_config_props(AVFilterLink *inlink)
> return 0;
> }
>
> +static int color_process_command(AVFilterContext *ctx, const char *cmd, const char *args,
> + char *res, int res_len, int flags)
> +{
> + TestSourceContext *test = ctx->priv;
> + int ret;
> +
> + if (!strcmp(cmd, "color") || !strcmp(cmd, "c")) {
> + uint8_t color_rgba[4];
> +
> + ret = av_parse_color(color_rgba, args, -1, ctx);
> + if (ret < 0)
> + return ret;
> + av_freep(&test->color_str);
> + test->color_str = av_strdup(args);
a bit overkill but possibly safer:
char *color_str = av_strdup(args);
if (!color_str)
return AVERROR(ENOMEM);
av_free(test->color_str);
test->color_str = color_str;
> + memcpy(test->color_rgba, color_rgba, sizeof(color_rgba));
> + ff_draw_color(&test->draw, &test->color, test->color_rgba);
> + test->draw_once_reset = 1;
> + return 0;
> + }
> +
> + return AVERROR(ENOSYS);
> +}
> +
> static const AVFilterPad color_outputs[] = {
> {
> .name = "default",
> @@ -263,6 +291,7 @@ AVFilter avfilter_vsrc_color = {
> .query_formats = color_query_formats,
> .inputs = NULL,
> .outputs = color_outputs,
> + .process_command = color_process_command,
> };
>
> #endif /* CONFIG_COLOR_FILTER */
Documentation might be welcome, but otherwise LGTM
--
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130428/3fbe940f/attachment.asc>
More information about the ffmpeg-devel
mailing list