diff mbox series

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

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

Checks

Context Check Description
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

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

Comments

Carl Eugen Hoyos Jan. 27, 2020, 10:40 p.m. UTC | #1
Am Mo., 27. Jan. 2020 um 23:16 Uhr schrieb Paul B Mahol <onemda@gmail.com>:
>
> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> ---
>  libavformat/tty.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
>
> diff --git a/libavformat/tty.c b/libavformat/tty.c
> index 8d48f2c45c..75af16a6f1 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"
> @@ -42,6 +44,17 @@ typedef struct TtyDemuxContext {
>      AVRational framerate; /**< Set by a private option. */
>  } TtyDemuxContext;
>
> +static int read_probe(const AVProbeData *p)
> +{
> +    int64_t cnt = 0;
> +
> +    for (int i = 0; i < p->buf_size; i++)
> +        cnt += !!isprint(p->buf[i]);
> +
> +    return (cnt * 100 / p->buf_size) * (cnt > 500) *

> +        !!av_match_ext(p->filename, "ans,art,asc,diz,ice,nfo,txt,vt");

ff_tty_demuxer.extensions with a declaration above.

Thank you, Carl Eugen
Paul B Mahol Jan. 27, 2020, 10:42 p.m. UTC | #2
On 1/27/20, Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:
> Am Mo., 27. Jan. 2020 um 23:16 Uhr schrieb Paul B Mahol <onemda@gmail.com>:
>>
>> Signed-off-by: Paul B Mahol <onemda@gmail.com>
>> ---
>>  libavformat/tty.c | 14 ++++++++++++++
>>  1 file changed, 14 insertions(+)
>>
>> diff --git a/libavformat/tty.c b/libavformat/tty.c
>> index 8d48f2c45c..75af16a6f1 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"
>> @@ -42,6 +44,17 @@ typedef struct TtyDemuxContext {
>>      AVRational framerate; /**< Set by a private option. */
>>  } TtyDemuxContext;
>>
>> +static int read_probe(const AVProbeData *p)
>> +{
>> +    int64_t cnt = 0;
>> +
>> +    for (int i = 0; i < p->buf_size; i++)
>> +        cnt += !!isprint(p->buf[i]);
>> +
>> +    return (cnt * 100 / p->buf_size) * (cnt > 500) *
>
>> +        !!av_match_ext(p->filename, "ans,art,asc,diz,ice,nfo,txt,vt");
>
> ff_tty_demuxer.extensions with a declaration above.

disagree

>
> Thank you, Carl Eugen
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
James Almer Jan. 28, 2020, 2:38 a.m. UTC | #3
On 1/27/2020 7:16 PM, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> ---
>  libavformat/tty.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/libavformat/tty.c b/libavformat/tty.c
> index 8d48f2c45c..75af16a6f1 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"
> @@ -42,6 +44,17 @@ typedef struct TtyDemuxContext {
>      AVRational framerate; /**< Set by a private option. */
>  } TtyDemuxContext;
>  
> +static int read_probe(const AVProbeData *p)
> +{
> +    int64_t cnt = 0;
> +
> +    for (int i = 0; i < p->buf_size; i++)
> +        cnt += !!isprint(p->buf[i]);

cnt here will never be > p->buf_size, so just make it an int and cast it
to int64_t in the line below. Otherwise the above loop will be slower
than necessary on 32 bit arches.

> +
> +    return (cnt * 100 / p->buf_size) * (cnt > 500) *
> +        !!av_match_ext(p->filename, "ans,art,asc,diz,ice,nfo,txt,vt");
> +}
> +
>  /**
>   * Parse EFI header
>   */
> @@ -153,6 +166,7 @@ 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",
>
diff mbox series

Patch

diff --git a/libavformat/tty.c b/libavformat/tty.c
index 8d48f2c45c..75af16a6f1 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"
@@ -42,6 +44,17 @@  typedef struct TtyDemuxContext {
     AVRational framerate; /**< Set by a private option. */
 } TtyDemuxContext;
 
+static int read_probe(const AVProbeData *p)
+{
+    int64_t cnt = 0;
+
+    for (int i = 0; i < p->buf_size; i++)
+        cnt += !!isprint(p->buf[i]);
+
+    return (cnt * 100 / p->buf_size) * (cnt > 500) *
+        !!av_match_ext(p->filename, "ans,art,asc,diz,ice,nfo,txt,vt");
+}
+
 /**
  * Parse EFI header
  */
@@ -153,6 +166,7 @@  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",