diff mbox series

[FFmpeg-devel] avcodec/ccaption_dec: Make real-time latency configurable v2

Message ID 20210529145120.20059-1-pkoshevoy@gmail.com
State Superseded
Headers show
Series [FFmpeg-devel] avcodec/ccaption_dec: Make real-time latency configurable v2
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Pavel Koshevoy May 29, 2021, 2:51 p.m. UTC
Un-hardcode the 200ms minimum latency between emitting subtitle events
so that those that wish to receive a subtitle event for every screen
change could do so.

The problem with delaying realtime output by any amount is that it is
unknown when the next byte pair that would trigger output will happen.
It may be within 200ms, or it may be several seconds later -- that's
not realtime at all.
---
 libavcodec/ccaption_dec.c | 4 +++-
 libavcodec/version.h      | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

Comments

Pavel Koshevoy June 3, 2021, 2:14 p.m. UTC | #1
On Sat, May 29, 2021, 08:51 Pavel Koshevoy <pkoshevoy@gmail.com> wrote:

> Un-hardcode the 200ms minimum latency between emitting subtitle events
> so that those that wish to receive a subtitle event for every screen
> change could do so.
>
> The problem with delaying realtime output by any amount is that it is
> unknown when the next byte pair that would trigger output will happen.
> It may be within 200ms, or it may be several seconds later -- that's
> not realtime at all.
> ---
>  libavcodec/ccaption_dec.c | 4 +++-
>  libavcodec/version.h      | 2 +-
>  2 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
> index de05d037a8..27c61527f6 100644
> --- a/libavcodec/ccaption_dec.c
> +++ b/libavcodec/ccaption_dec.c
> @@ -238,6 +238,7 @@ struct Screen {
>  typedef struct CCaptionSubContext {
>      AVClass *class;
>      int real_time;
> +    int real_time_latency_msec;
>      int data_field;
>      struct Screen screen[2];
>      int active_screen;
> @@ -906,7 +907,7 @@ static int decode(AVCodecContext *avctx, void *data,
> int *got_sub, AVPacket *avp
>      }
>
>      if (ctx->real_time && ctx->screen_touched &&
> -        sub->pts > ctx->last_real_time + av_rescale_q(200, ms_tb,
> AV_TIME_BASE_Q)) {
> +        sub->pts >= ctx->last_real_time +
> av_rescale_q(ctx->real_time_latency_msec, ms_tb, AV_TIME_BASE_Q)) {
>          ctx->last_real_time = sub->pts;
>          ctx->screen_touched = 0;
>
> @@ -927,6 +928,7 @@ static int decode(AVCodecContext *avctx, void *data,
> int *got_sub, AVPacket *avp
>  #define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
>  static const AVOption options[] = {
>      { "real_time", "emit subtitle events as they are decoded for
> real-time display", OFFSET(real_time), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0,
> 1, SD },
> +    { "real_time_latency_msec", "minimum elapsed time between emitting
> real-time subtitle events", OFFSET(real_time_latency_msec),
> AV_OPT_TYPE_INT, { .i64 = 200 }, 0, 500, SD },
>      { "data_field", "select data field", OFFSET(data_field),
> AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, SD, "data_field" },
>      { "auto",   "pick first one that appears", 0, AV_OPT_TYPE_CONST, {
> .i64 =-1 }, 0, 0, SD, "data_field" },
>      { "first",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, 0, SD,
> "data_field" },
> diff --git a/libavcodec/version.h b/libavcodec/version.h
> index 48165b9ac4..5b1e9e77f3 100644
> --- a/libavcodec/version.h
> +++ b/libavcodec/version.h
> @@ -29,7 +29,7 @@
>
>  #define LIBAVCODEC_VERSION_MAJOR  59
>  #define LIBAVCODEC_VERSION_MINOR   1
> -#define LIBAVCODEC_VERSION_MICRO 100
> +#define LIBAVCODEC_VERSION_MICRO 101
>
>  #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
>                                                 LIBAVCODEC_VERSION_MINOR, \
> --
> 2.26.2
>



Are there any objections to this?

Thank you,
    Pavel

>
Valerii Zapodovnikov June 4, 2021, 10:56 p.m. UTC | #2
v2 is done by "git send-email -v2 -1" not what you did here.
Pavel Koshevoy June 5, 2021, 3:34 a.m. UTC | #3
On Fri, Jun 4, 2021 at 4:56 PM Valerii Zapodovnikov <val.zapod.vz@gmail.com>
wrote:

> v2 is done by "git send-email -v2 -1" not what you did here.
>


Thanks, I didn't know that.  I am unclear -- do you want me to resubmit the
patch?  I can just apply and push it myself if there are no objections,
although I am not the maintainer of ccaption_dec.c so IDK if that would be
inappropriate.

Pavel.
Valerii Zapodovnikov June 5, 2021, 8:26 a.m. UTC | #4
Sure, please resend and change status on your old patch as superseeded on
patchwork. Sigh. As for maintainer, LGTM from me (interesting, is just
saying those 4 latters enough to get patchwork flag of it?). So if you can
push while not being the mainteiner, please do it, the coding acceptions
here are like really slow, 3 days ago my pull request on github was merged
in 3 hours by Microsoft! And anyway, ccextractor is what is more used out
there, is not it. And Timo does not want to add cc to cuviddec!! Oogh. See:
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20210413143510.93256-1-dhanishvijayan@gmail.com/
diff mbox series

Patch

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index de05d037a8..27c61527f6 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -238,6 +238,7 @@  struct Screen {
 typedef struct CCaptionSubContext {
     AVClass *class;
     int real_time;
+    int real_time_latency_msec;
     int data_field;
     struct Screen screen[2];
     int active_screen;
@@ -906,7 +907,7 @@  static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avp
     }
 
     if (ctx->real_time && ctx->screen_touched &&
-        sub->pts > ctx->last_real_time + av_rescale_q(200, ms_tb, AV_TIME_BASE_Q)) {
+        sub->pts >= ctx->last_real_time + av_rescale_q(ctx->real_time_latency_msec, ms_tb, AV_TIME_BASE_Q)) {
         ctx->last_real_time = sub->pts;
         ctx->screen_touched = 0;
 
@@ -927,6 +928,7 @@  static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avp
 #define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
 static const AVOption options[] = {
     { "real_time", "emit subtitle events as they are decoded for real-time display", OFFSET(real_time), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, SD },
+    { "real_time_latency_msec", "minimum elapsed time between emitting real-time subtitle events", OFFSET(real_time_latency_msec), AV_OPT_TYPE_INT, { .i64 = 200 }, 0, 500, SD },
     { "data_field", "select data field", OFFSET(data_field), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, SD, "data_field" },
     { "auto",   "pick first one that appears", 0, AV_OPT_TYPE_CONST, { .i64 =-1 }, 0, 0, SD, "data_field" },
     { "first",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, 0, SD, "data_field" },
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 48165b9ac4..5b1e9e77f3 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@ 
 
 #define LIBAVCODEC_VERSION_MAJOR  59
 #define LIBAVCODEC_VERSION_MINOR   1
-#define LIBAVCODEC_VERSION_MICRO 100
+#define LIBAVCODEC_VERSION_MICRO 101
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \