diff mbox series

[FFmpeg-devel] avformat/tty: add probe function

Message ID 20200128131735.19346-1-onemda@gmail.com
State Superseded
Headers show
Series [FFmpeg-devel] avformat/tty: add probe function
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Paul B Mahol Jan. 28, 2020, 1:17 p.m. UTC
Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 libavformat/tty.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

Comments

Peter Ross Jan. 28, 2020, 8:46 p.m. UTC | #1
On Tue, Jan 28, 2020 at 02:17:35PM +0100, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> ---
>  libavformat/tty.c | 18 +++++++++++++++++-
>  1 file changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/tty.c b/libavformat/tty.c
> index 8d48f2c45c..a8fb9dc8f3 100644
> --- a/libavformat/tty.c
> +++ b/libavformat/tty.c
> @@ -24,6 +24,8 @@
>   * Tele-typewriter demuxer
>   */
>  
> +#include <ctype.h>
> +
>  #include "libavutil/intreadwrite.h"
>  #include "libavutil/avstring.h"
>  #include "libavutil/log.h"
> @@ -34,6 +36,8 @@
>  #include "internal.h"
>  #include "sauce.h"
>  
> +static const char tty_extensions[31] = "ans,art,asc,diz,ice,nfo,txt,vt";
> +
>  typedef struct TtyDemuxContext {
>      AVClass *class;
>      int chars_per_frame;
> @@ -42,6 +46,17 @@ typedef struct TtyDemuxContext {
>      AVRational framerate; /**< Set by a private option. */
>  } TtyDemuxContext;
>  
> +static int read_probe(const AVProbeData *p)
> +{
> +    int cnt = 0;
> +
> +    for (int i = 0; i < p->buf_size; i++)
> +        cnt += !!isprint(p->buf[i]);
> +
> +    return (cnt * 100LL / p->buf_size) * (cnt > 400) *
> +        !!av_match_ext(p->filename, tty_extensions);
> +}
> +
>  /**
>   * Parse EFI header
>   */
> @@ -153,8 +168,9 @@ AVInputFormat ff_tty_demuxer = {
>      .name           = "tty",
>      .long_name      = NULL_IF_CONFIG_SMALL("Tele-typewriter"),
>      .priv_data_size = sizeof(TtyDemuxContext),
> +    .read_probe     = read_probe,
>      .read_header    = read_header,
>      .read_packet    = read_packet,
> -    .extensions     = "ans,art,asc,diz,ice,nfo,txt,vt",
> +    .extensions     = tty_extensions,
>      .priv_class     = &tty_demuxer_class,
>  };
> -- 
> 2.17.1

i can't offer any more suggestions. recommend approve.

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
Nicolas George Jan. 28, 2020, 8:55 p.m. UTC | #2
Peter Ross (12020-01-29):
> > +    for (int i = 0; i < p->buf_size; i++)
> > +        cnt += !!isprint(p->buf[i]);

This depends on locale settings. Is it on purpose?

Regards,
Paul B Mahol Jan. 28, 2020, 8:58 p.m. UTC | #3
On 1/28/20, Nicolas George <george@nsup.org> wrote:
> Peter Ross (12020-01-29):
>> > +    for (int i = 0; i < p->buf_size; i++)
>> > +        cnt += !!isprint(p->buf[i]);
>
> This depends on locale settings. Is it on purpose?

I certainly could write one which does not use locale, if that is ok with you?

>
> Regards,
>
> --
>   Nicolas George
>
Nicolas George Jan. 28, 2020, 9:02 p.m. UTC | #4
Paul B Mahol (12020-01-28):
> I certainly could write one which does not use locale, if that is ok with you?

You know better than me on this issue. I was just pointing something
that may have been forgotten.

Regards,
diff mbox series

Patch

diff --git a/libavformat/tty.c b/libavformat/tty.c
index 8d48f2c45c..a8fb9dc8f3 100644
--- a/libavformat/tty.c
+++ b/libavformat/tty.c
@@ -24,6 +24,8 @@ 
  * Tele-typewriter demuxer
  */
 
+#include <ctype.h>
+
 #include "libavutil/intreadwrite.h"
 #include "libavutil/avstring.h"
 #include "libavutil/log.h"
@@ -34,6 +36,8 @@ 
 #include "internal.h"
 #include "sauce.h"
 
+static const char tty_extensions[31] = "ans,art,asc,diz,ice,nfo,txt,vt";
+
 typedef struct TtyDemuxContext {
     AVClass *class;
     int chars_per_frame;
@@ -42,6 +46,17 @@  typedef struct TtyDemuxContext {
     AVRational framerate; /**< Set by a private option. */
 } TtyDemuxContext;
 
+static int read_probe(const AVProbeData *p)
+{
+    int cnt = 0;
+
+    for (int i = 0; i < p->buf_size; i++)
+        cnt += !!isprint(p->buf[i]);
+
+    return (cnt * 100LL / p->buf_size) * (cnt > 400) *
+        !!av_match_ext(p->filename, tty_extensions);
+}
+
 /**
  * Parse EFI header
  */
@@ -153,8 +168,9 @@  AVInputFormat ff_tty_demuxer = {
     .name           = "tty",
     .long_name      = NULL_IF_CONFIG_SMALL("Tele-typewriter"),
     .priv_data_size = sizeof(TtyDemuxContext),
+    .read_probe     = read_probe,
     .read_header    = read_header,
     .read_packet    = read_packet,
-    .extensions     = "ans,art,asc,diz,ice,nfo,txt,vt",
+    .extensions     = tty_extensions,
     .priv_class     = &tty_demuxer_class,
 };