From patchwork Sat Sep 18 03:53:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soft Works X-Patchwork-Id: 30342 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp2791644iov; Fri, 17 Sep 2021 20:53:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0ljRkXWtK2fORDtMpXRNjtu7pGVZ8dQvtj/iEnesb4kfb0m5jmTk9lRAs7MuTigaCNcv5 X-Received: by 2002:a17:906:3685:: with SMTP id a5mr16556704ejc.144.1631937209399; Fri, 17 Sep 2021 20:53:29 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id dz8si8887024edb.30.2021.09.17.20.53.29; Fri, 17 Sep 2021 20:53:29 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@hotmail.com header.s=selector1 header.b=oCs1Qmw1; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=hotmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 295FC68B1E3; Sat, 18 Sep 2021 06:53:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11olkn2019.outbound.protection.outlook.com [40.92.18.19]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6308468B1BB for ; Sat, 18 Sep 2021 06:53:07 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iJCUJS64qssqodZg5HivMJcg3JUNAlDKjbfsQ3dQZxfGxylTI7mVNf7nrCJH7rcZtQBnWdTwO+vuox5utmuWSHPf2AL+Ywgwf8Q+wcKFeH/P44ZPR5NNLdIkvGt1sln8/OJnt7BubYDF7bG+jLj4hPANw4nEg+rn3IECrX+8z0Xv8BdrspLo2jI1GhJM3TufsIMrqVmF03+rhohnus9BXd6c17+/s1iKGv5Q7CCirmVizDTCfSxgAY/N7XR9tu8WtCuJJpZR0RFEdmTDWNaWc4b2AVpznvmiSkoAG3lxbvHNbs0sRNXkzsh7N2hWRL/kaK+P+GAbGhURohGW6rdlXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=i72SyqrAAjQHAPCdkW8wTwdhi8QDvY6rwVpQKprHslA=; b=cXpcEVxWS12PPH+w1aI8+SPICMHR47vgNA8RPZllM6PcDCpP/IrfNeQ9odhojtuCuFctTFz2euGkH96Gaqj6OSROEXzg31sdXfy9N+mvLYHrU4d2/pRoH4Zr1MjCDw93vnlDvC5ISpWz07gyYTL5lPvelQCnJgRopjSHVz9l9/TH6bWxW+KwXB47lg7T14M2KdXkss2sfWxVOg8W2IOuu5/UqPK2ar719aoBwByFAgBraF4mHD9KyJgvZYFnKcnubc1NNP1tStOIzdpaughF7VKc86798kqoQelTeVzrgUL2s+UqSc5uKbJOXMYsz5KpL1O4sTy6ZOb7WeUNxI+29g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=i72SyqrAAjQHAPCdkW8wTwdhi8QDvY6rwVpQKprHslA=; b=oCs1Qmw1g0W1AbXwy1bY8tmndYHjlTF3arB3/M4grHPIKMwLEeh5zVAbZil409xgR46jyWkTHuk9NEfQCEXiYB3E8W3FSkt01NubKuo8Ytok/CYFsk3qf1ye8UY3ZZKOqrU1TieKClN//b54wvP9Ic9gMgcEpXww8/kdzDpL3IOQMRX/B3ahe89vsegNrLgyqkgk7u4wdZHUpKH0voGQ9oWAKKqdnK0PzAmG70VBkAgR6dnMYTE4zxjUMXP7tR3qkdjut6qK/YmUfehhff3xye8+h9fRAAg7uw3jF/TdV5Ny56z7DtwUhyo7rmjNZTDvkzj9RvD2M910qHeBcohqIQ== Received: from BYAPR04MB5976.namprd04.prod.outlook.com (2603:10b6:a03:f2::32) by BY5PR04MB6865.namprd04.prod.outlook.com (2603:10b6:a03:219::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.16; Sat, 18 Sep 2021 03:53:04 +0000 Received: from BYAPR04MB5976.namprd04.prod.outlook.com ([fe80::ecc6:937b:3740:1816]) by BYAPR04MB5976.namprd04.prod.outlook.com ([fe80::ecc6:937b:3740:1816%6]) with mapi id 15.20.4523.015; Sat, 18 Sep 2021 03:53:04 +0000 From: Soft Works To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH v7 05/12] avfilter/sbuffer: Add sbuffersrv and sbuffersink filters Thread-Index: AQHXrECvsaRrkpm+j0KI8YHk2AKC4g== Date: Sat, 18 Sep 2021 03:53:04 +0000 Message-ID: References: <0929c32d8c695549bb9848e24113a07810118645.1631934103.git.softworkz@hotmail.com> <5a0310cb87ef181680b26efc53f0eea6b9e939fe.1631934104.git.softworkz@hotmail.com> <42f16c26e63b3ffec87acef3b2e95a4085b4b86b.1631934104.git.softworkz@hotmail.com> In-Reply-To: <42f16c26e63b3ffec87acef3b2e95a4085b4b86b.1631934104.git.softworkz@hotmail.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [A9qPY+RV/JpmdYHf1fgCTgyFRUMcMbgw] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 22ec1dee-5013-403f-9120-08d97a57d1c3 x-ms-traffictypediagnostic: BY5PR04MB6865: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: b9cVK7HSlObRWPJZtHTGA8dBAumlbifml9WXBVZFasNopyhzj6cFRB5UoseoKUII9KjKpdwDETipCzUpHLBP56hY9dJ+Hi+uKzC3WJphMOqef4gCGDCC8kHkshv76IGYp8wvMUWlNmQNI070unYJgha5Px9/QjVjslMlJmNF4EanLcFAvRjLE28b3eN/fpAlXf4dJmWa/S2tJxsbWvQ83OYy9xP9USABRpJD4DbWGhxp3aZanhlwGNyM+Z7JWUO4FUKYT+LMGv9oSQ15fZEL0BCYnZHcgwouRahyaGrCjmdOlACkNXXH+obLsi7l9NRRao4v7S87DUR51aAuyiCLjda2w2aWlaGBu/AARYL7nyBWmG1c54OR4ZJB3eLATnE1EyDVEk8SvzaPWJbGwynQAVkLpynd+O98L6e0Wct/J13KzqzxudGS6vBNmsPL6QkM x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: Mrroluynf6SyBip9d2eXZ+n145vVdAkS253hSoQkSI7D4/gP45YrpFyi+fGw2VtGZxypSevIlQi4+hFkKSAjtX6LJVGLerTHRESkL+8+uBu54jYcn1FS48Xb5l+K5qQ8TsvL9UlsVRq8LOio6fAQEg== x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-3174-20-msonline-outlook-529c7.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BYAPR04MB5976.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 22ec1dee-5013-403f-9120-08d97a57d1c3 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Sep 2021 03:53:04.9304 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR04MB6865 Subject: [FFmpeg-devel] [PATCH v7 05/12] avfilter/sbuffer: Add sbuffersrv and sbuffersink filters X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: rFHGz/4e7dAK Signed-off-by: softworkz --- configure | 2 +- libavfilter/allfilters.c | 10 +++--- libavfilter/buffersink.c | 63 +++++++++++++++++++++++++++++++++++ libavfilter/buffersink.h | 15 +++++++++ libavfilter/buffersrc.c | 72 ++++++++++++++++++++++++++++++++++++++++ libavfilter/buffersrc.h | 1 + libavfilter/version.h | 2 +- 7 files changed, 159 insertions(+), 6 deletions(-) diff --git a/configure b/configure index 7ac23123c7..74c5a41be1 100755 --- a/configure +++ b/configure @@ -7718,7 +7718,7 @@ print_enabled_components(){ fi done if [ "$name" = "filter_list" ]; then - for c in asrc_abuffer vsrc_buffer asink_abuffer vsink_buffer; do + for c in asrc_abuffer vsrc_buffer ssrc_sbuffer asink_abuffer vsink_buffer ssink_sbuffer; do printf " &ff_%s,\n" $c >> $TMPH done fi diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index ddd6404228..154eba5bb2 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -533,10 +533,12 @@ extern const AVFilter ff_avsrc_movie; * they are formatted to not be found by the grep * as they are manually added again (due to their 'names' * being the same while having different 'types'). */ -extern const AVFilter ff_asrc_abuffer; -extern const AVFilter ff_vsrc_buffer; -extern const AVFilter ff_asink_abuffer; -extern const AVFilter ff_vsink_buffer; +extern const AVFilter ff_asrc_abuffer; +extern const AVFilter ff_vsrc_buffer; +extern const AVFilter ff_ssrc_sbuffer; +extern const AVFilter ff_asink_abuffer; +extern const AVFilter ff_vsink_buffer; +extern const AVFilter ff_ssink_sbuffer; extern const AVFilter ff_af_afifo; extern const AVFilter ff_vf_fifo; diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c index 8b46dcb15e..55cbaff3d5 100644 --- a/libavfilter/buffersink.c +++ b/libavfilter/buffersink.c @@ -29,6 +29,8 @@ #include "libavutil/internal.h" #include "libavutil/opt.h" +#include "libavcodec/avcodec.h" + #define FF_INTERNAL_FIELDS 1 #include "framequeue.h" @@ -57,6 +59,10 @@ typedef struct BufferSinkContext { int *sample_rates; ///< list of accepted sample rates, terminated by -1 int sample_rates_size; + /* only used for subtitles */ + enum AVSubtitleType *subtitle_types; ///< list of accepted subtitle types, must be terminated with -1 + int subtitle_types_size; + AVFrame *peeked_frame; } BufferSinkContext; @@ -168,6 +174,15 @@ AVABufferSinkParams *av_abuffersink_params_alloc(void) return NULL; return params; } + +AVSBufferSinkParams *av_sbuffersink_params_alloc(void) +{ + AVSBufferSinkParams *params = av_mallocz(sizeof(AVSBufferSinkParams)); + + if (!params) + return NULL; + return params; +} #endif static av_cold int common_init(AVFilterContext *ctx) @@ -305,6 +320,28 @@ static int asink_query_formats(AVFilterContext *ctx) return 0; } +static int ssink_query_formats(AVFilterContext *ctx) +{ + BufferSinkContext *buf = ctx->priv; + AVFilterFormats *formats = NULL; + unsigned i; + int ret; + + CHECK_LIST_SIZE(subtitle_types) + if (buf->subtitle_types_size) { + for (i = 0; i < NB_ITEMS(buf->subtitle_types); i++) + if ((ret = ff_add_subtitle_type(&formats, buf->subtitle_types[i])) < 0) + return ret; + if ((ret = ff_set_common_formats(ctx, formats)) < 0) + return ret; + } else { + if ((ret = ff_default_query_formats(ctx)) < 0) + return ret; + } + + return 0; +} + #define OFFSET(x) offsetof(BufferSinkContext, x) #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM static const AVOption buffersink_options[] = { @@ -322,9 +359,16 @@ static const AVOption abuffersink_options[] = { { NULL }, }; #undef FLAGS +#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_SUBTITLE_PARAM +static const AVOption sbuffersink_options[] = { + { "subtitle_types", "set the supported subtitle formats", OFFSET(subtitle_types), AV_OPT_TYPE_BINARY, .flags = FLAGS }, + { NULL }, +}; +#undef FLAGS AVFILTER_DEFINE_CLASS(buffersink); AVFILTER_DEFINE_CLASS(abuffersink); +AVFILTER_DEFINE_CLASS(sbuffersink); static const AVFilterPad avfilter_vsink_buffer_inputs[] = { { @@ -363,3 +407,22 @@ const AVFilter ff_asink_abuffer = { FILTER_INPUTS(avfilter_asink_abuffer_inputs), .outputs = NULL, }; + +static const AVFilterPad avfilter_ssink_sbuffer_inputs[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_SUBTITLE, + }, +}; + +AVFilter ff_ssink_sbuffer = { + .name = "sbuffersink", + .description = NULL_IF_CONFIG_SMALL("Buffer subtitle frames, and make them available to the end of the filter graph."), + .priv_class = &sbuffersink_class, + .priv_size = sizeof(BufferSinkContext), + .init = common_init, + .query_formats = ssink_query_formats, + .activate = activate, + FILTER_INPUTS(avfilter_ssink_sbuffer_inputs), + .outputs = NULL, +}; diff --git a/libavfilter/buffersink.h b/libavfilter/buffersink.h index 69ed0f29a8..b439b586c5 100644 --- a/libavfilter/buffersink.h +++ b/libavfilter/buffersink.h @@ -129,6 +129,21 @@ typedef struct AVABufferSinkParams { */ attribute_deprecated AVABufferSinkParams *av_abuffersink_params_alloc(void); + +/** + * Deprecated and unused struct to use for initializing an sbuffersink context. + */ +typedef struct AVSBufferSinkParams { + const int *subtitle_type; +} AVSBufferSinkParams; + +/** + * Create an AVSBufferSinkParams structure. + * + * Must be freed with av_free(). + */ +attribute_deprecated +AVSBufferSinkParams *av_sbuffersink_params_alloc(void); #endif /** diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c index 632bfc7ad8..902a09a721 100644 --- a/libavfilter/buffersrc.c +++ b/libavfilter/buffersrc.c @@ -39,6 +39,7 @@ #include "formats.h" #include "internal.h" #include "video.h" +#include "libavcodec/avcodec.h" typedef struct BufferSourceContext { const AVClass *class; @@ -63,6 +64,9 @@ typedef struct BufferSourceContext { uint64_t channel_layout; char *channel_layout_str; + /* subtitle only */ + enum AVSubtitleType subtitle_type; + int eof; } BufferSourceContext; @@ -130,6 +134,13 @@ int av_buffersrc_parameters_set(AVFilterContext *ctx, AVBufferSrcParameters *par if (param->channel_layout) s->channel_layout = param->channel_layout; break; + case AVMEDIA_TYPE_SUBTITLE: + s->subtitle_type = param->format; + if (param->width > 0) + s->w = param->width; + if (param->height > 0) + s->h = param->height; + break; default: return AVERROR_BUG; } @@ -197,6 +208,8 @@ int attribute_align_arg av_buffersrc_add_frame_flags(AVFilterContext *ctx, AVFra CHECK_AUDIO_PARAM_CHANGE(ctx, s, frame->sample_rate, frame->channel_layout, frame->channels, frame->format, frame->pts); break; + case AVMEDIA_TYPE_SUBTITLE: + break; default: return AVERROR(EINVAL); } @@ -269,6 +282,7 @@ unsigned av_buffersrc_get_nb_failed_requests(AVFilterContext *buffer_src) #define OFFSET(x) offsetof(BufferSourceContext, x) #define A AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM #define V AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM +#define S AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_SUBTITLE_PARAM static const AVOption buffer_options[] = { { "width", NULL, OFFSET(w), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, V }, @@ -298,6 +312,16 @@ static const AVOption abuffer_options[] = { AVFILTER_DEFINE_CLASS(abuffer); +static const AVOption sbuffer_options[] = { + { "time_base", NULL, OFFSET(time_base), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, INT_MAX, S }, + { "subtitle_type", NULL, OFFSET(subtitle_type), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, S }, + { "width", NULL, OFFSET(w), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, V }, + { "height", NULL, OFFSET(h), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, V }, + { NULL }, +}; + +AVFILTER_DEFINE_CLASS(sbuffer); + static av_cold int init_audio(AVFilterContext *ctx) { BufferSourceContext *s = ctx->priv; @@ -347,6 +371,21 @@ static av_cold int init_audio(AVFilterContext *ctx) return ret; } +static av_cold int init_subtitle(AVFilterContext *ctx) +{ + BufferSourceContext *c = ctx->priv; + + if (c->subtitle_type == AV_SUBTITLE_FMT_BITMAP) + av_log(ctx, AV_LOG_VERBOSE, "graphical subtitles - w:%d h:%d tb:%d/%d\n", + c->w, c->h, c->time_base.num, c->time_base.den); + else + av_log(ctx, AV_LOG_VERBOSE, "text subtitles - w:%d h:%d tb:%d/%d\n", + c->w, c->h, c->time_base.num, c->time_base.den); + + return 0; +} + + static av_cold void uninit(AVFilterContext *ctx) { BufferSourceContext *s = ctx->priv; @@ -381,6 +420,11 @@ static int query_formats(AVFilterContext *ctx) if ((ret = ff_set_common_channel_layouts(ctx, channel_layouts)) < 0) return ret; break; + case AVMEDIA_TYPE_SUBTITLE: + if ((ret = ff_add_format (&formats, c->subtitle_type)) < 0 || + (ret = ff_set_common_formats (ctx , formats )) < 0) + return ret; + break; default: return AVERROR(EINVAL); } @@ -408,6 +452,11 @@ static int config_props(AVFilterLink *link) if (!c->channel_layout) c->channel_layout = link->channel_layout; break; + case AVMEDIA_TYPE_SUBTITLE: + link->format = c->subtitle_type; + link->w = c->w; + link->h = c->h; + break; default: return AVERROR(EINVAL); } @@ -472,3 +521,26 @@ const AVFilter ff_asrc_abuffer = { FILTER_OUTPUTS(avfilter_asrc_abuffer_outputs), .priv_class = &abuffer_class, }; + +static const AVFilterPad avfilter_ssrc_sbuffer_outputs[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_SUBTITLE, + .request_frame = request_frame, + .config_props = config_props, + }, +}; + +const AVFilter ff_ssrc_sbuffer = { + .name = "sbuffer", + .description = NULL_IF_CONFIG_SMALL("Buffer subtitle frames, and make them accessible to the filterchain."), + .priv_size = sizeof(BufferSourceContext), + .query_formats = query_formats, + + .init = init_subtitle, + .uninit = uninit, + + .inputs = NULL, + FILTER_OUTPUTS(avfilter_ssrc_sbuffer_outputs), + .priv_class = &sbuffer_class, +}; diff --git a/libavfilter/buffersrc.h b/libavfilter/buffersrc.h index 08fbd18a47..929a2fa249 100644 --- a/libavfilter/buffersrc.h +++ b/libavfilter/buffersrc.h @@ -74,6 +74,7 @@ typedef struct AVBufferSrcParameters { /** * video: the pixel format, value corresponds to enum AVPixelFormat * audio: the sample format, value corresponds to enum AVSampleFormat + * subtitles: the subtitle format, value corresponds to enum AVSubtitleType */ int format; /** diff --git a/libavfilter/version.h b/libavfilter/version.h index 24b59acde6..ab5eb14634 100644 --- a/libavfilter/version.h +++ b/libavfilter/version.h @@ -30,7 +30,7 @@ #include "libavutil/version.h" #define LIBAVFILTER_VERSION_MAJOR 8 -#define LIBAVFILTER_VERSION_MINOR 9 +#define LIBAVFILTER_VERSION_MINOR 10 #define LIBAVFILTER_VERSION_MICRO 100