diff mbox series

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

Message ID 20210526021629.22133-1-pkoshevoy@gmail.com
State Withdrawn
Headers show
Series [FFmpeg-devel] avcodec/ccaption_dec: Make real-time latency configurable | expand

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 26, 2021, 2:16 a.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.
---
 libavcodec/ccaption_dec.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Moritz Barsnick May 26, 2021, 6:12 a.m. UTC | #1
On Tue, May 25, 2021 at 20:16:29 -0600, Pavel Koshevoy wrote:
> -        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)) {
[...]
> +    { "real_time_latency_msec", "minimum elapsed time between emitting real-time subtitle events", OFFSET(real_time_latency_msec), AV_OPT_TYPE_INT, { .i64 = 201 }, 0, 500, SD, "data_field" },

So why now 201 instead of 200 ms?

Moritz
Pavel Koshevoy May 26, 2021, 11:48 a.m. UTC | #2
On Wed, May 26, 2021, 00:18 Moritz Barsnick <barsnick@gmx.net> wrote:

> On Tue, May 25, 2021 at 20:16:29 -0600, Pavel Koshevoy wrote:
> > -        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)) {
> [...]
> > +    { "real_time_latency_msec", "minimum elapsed time between emitting
> real-time subtitle events", OFFSET(real_time_latency_msec),
> AV_OPT_TYPE_INT, { .i64 = 201 }, 0, 500, SD, "data_field" },
>
> So why now 201 instead of 200 ms?
>

Because it is >= now, instead of >.
I can leave it at 200, I don't really care -- I will personally only use it
at 0.
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 at 200ms, or it may be several seconds later -- that's not realtime
at all.

Do I need to bump any version numbers?

Thank you,
    Pavel
Pavel Koshevoy May 29, 2021, 2:52 p.m. UTC | #3
On Tue, May 25, 2021 at 8:16 PM 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.
> ---
>  libavcodec/ccaption_dec.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
> index de05d037a8..e66ebc1184 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 = 201 }, 0, 500, SD, "data_field" },
>

^ this is wrong, ignore this patch, I'll send a v2



>      { "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" },
> --
> 2.26.2
>
>
diff mbox series

Patch

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index de05d037a8..e66ebc1184 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 = 201 }, 0, 500, SD, "data_field" },
     { "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" },