Re: [FFmpeg-devel] [PATCH] Add matroska codec id S_TEXT/WEBVTT for WebVTT streams.

2021-02-07 Thread Andreas Rheinhardt
Walter Wong:
> Added the codec id S_TEXT/WEBVTT in order to bring ffmpeg generated files
> closer to the matroska spec. The list of matroska codec ids was also
> rearranged to push the old codec id (D_WEBVTT/SUBTITLES) to the bottom of
> the list so that S_TEXT/WEBVTT is the default codec id for new mkv files
> with webvtt subtitles.
> 
> Fixes ticket #5641: http://trac.ffmpeg.org/ticket/5641
> ---
>  libavformat/matroska.c | 14 +-
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/libavformat/matroska.c b/libavformat/matroska.c
> index 7c56aba403..1128c96451 100644
> --- a/libavformat/matroska.c
> +++ b/libavformat/matroska.c
> @@ -60,16 +60,12 @@ const CodecTags ff_mkv_codec_tags[]={
>  {"A_VORBIS" , AV_CODEC_ID_VORBIS},
>  {"A_WAVPACK4"   , AV_CODEC_ID_WAVPACK},
>  
> -{"D_WEBVTT/SUBTITLES"   , AV_CODEC_ID_WEBVTT},
> -{"D_WEBVTT/CAPTIONS", AV_CODEC_ID_WEBVTT},
> -{"D_WEBVTT/DESCRIPTIONS", AV_CODEC_ID_WEBVTT},
> -{"D_WEBVTT/METADATA", AV_CODEC_ID_WEBVTT},
> -
>  {"S_TEXT/UTF8"  , AV_CODEC_ID_SUBRIP},
>  {"S_TEXT/UTF8"  , AV_CODEC_ID_TEXT},
>  {"S_TEXT/ASCII" , AV_CODEC_ID_TEXT},
>  {"S_TEXT/ASS"   , AV_CODEC_ID_ASS},
>  {"S_TEXT/SSA"   , AV_CODEC_ID_ASS},
> +{"S_TEXT/WEBVTT", AV_CODEC_ID_WEBVTT},
>  {"S_ASS", AV_CODEC_ID_ASS},
>  {"S_SSA", AV_CODEC_ID_ASS},
>  {"S_VOBSUB" , AV_CODEC_ID_DVD_SUBTITLE},
> @@ -100,6 +96,14 @@ const CodecTags ff_mkv_codec_tags[]={
>  {"V_VP8", AV_CODEC_ID_VP8},
>  {"V_VP9", AV_CODEC_ID_VP9},
>  
> +/* These codec strings for webvtt seem to be depreciated from the 
> Matroska
> +   spec, but it might be useful to keep them for compatibility for older
> +   files. These are at the bottom so they get matched after 
> S_TEXT/WEBVTT. */
> +{"D_WEBVTT/SUBTITLES"   , AV_CODEC_ID_WEBVTT},
> +{"D_WEBVTT/CAPTIONS", AV_CODEC_ID_WEBVTT},
> +{"D_WEBVTT/DESCRIPTIONS", AV_CODEC_ID_WEBVTT},
> +{"D_WEBVTT/METADATA", AV_CODEC_ID_WEBVTT},
> +
>  {"" , AV_CODEC_ID_NONE}
>  };
>  
> 
You are not fixing #5641 at all; in fact your comment suggests that you
misunderstand the problem: There are two ways to mux WebVTT, one for
WebM (using these "D_WEBVTT_*" values and one for Matroska. The WebM way
of doing WebVTT is the older one of the two and it is horrible, but it
is the one that is supported. There was a patchset last year [1], [2] to
fix this and implement the Matroska way, yet the author never sent a
follow-up.

Your patch would make the muxer write the packets in the WebM way, yet
the header would claim it to be the Matroska way. This is worse than it
is now.

- Andreas

[1]: https://ffmpeg.org/pipermail/ffmpeg-devel/2020-June/264695.html
[2]: https://ffmpeg.org/pipermail/ffmpeg-devel/2020-June/264693.html
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] Add matroska codec id S_TEXT/WEBVTT for WebVTT streams.

2021-02-07 Thread Walter
I understand. Would it be better to roll back the patch to just adding 
S_TEXT/WEBVTT to list of recognized codec ids for now?
 Original message From: Andreas Rheinhardt 
 Date: 2021-02-07  3:08 AM  (GMT-05:00) To: 
ffmpeg-devel@ffmpeg.org Subject: Re: [FFmpeg-devel] [PATCH] Add matroska codec 
id S_TEXT/WEBVTT for WebVTT streams. Walter Wong:> Added the codec id 
S_TEXT/WEBVTT in order to bring ffmpeg generated files> closer to the matroska 
spec. The list of matroska codec ids was also> rearranged to push the old codec 
id (D_WEBVTT/SUBTITLES) to the bottom of> the list so that S_TEXT/WEBVTT is the 
default codec id for new mkv files> with webvtt subtitles.> > Fixes ticket 
#5641: http://trac.ffmpeg.org/ticket/5641> --->  libavformat/matroska.c | 14 
+->  1 file changed, 9 insertions(+), 5 deletions(-)> > diff --git 
a/libavformat/matroska.c b/libavformat/matroska.c> index 7c56aba403..1128c96451 
100644> --- a/libavformat/matroska.c> +++ b/libavformat/matroska.c> @@ -60,16 
+60,12 @@ const CodecTags ff_mkv_codec_tags[]={>  {"A_VORBIS" , 
AV_CODEC_ID_VORBIS},>  {"A_WAVPACK4"   , AV_CODEC_ID_WAVPACK},>  > -    
{"D_WEBVTT/SUBTITLES"   , AV_CODEC_ID_WEBVTT},> -    {"D_WEBVTT/CAPTIONS"    , 
AV_CODEC_ID_WEBVTT},> -    {"D_WEBVTT/DESCRIPTIONS", AV_CODEC_ID_WEBVTT},> -    
{"D_WEBVTT/METADATA"    , AV_CODEC_ID_WEBVTT},> ->  {"S_TEXT/UTF8"  , 
AV_CODEC_ID_SUBRIP},>  {"S_TEXT/UTF8"  , AV_CODEC_ID_TEXT},>  
{"S_TEXT/ASCII" , AV_CODEC_ID_TEXT},>  {"S_TEXT/ASS"   , 
AV_CODEC_ID_ASS},>  {"S_TEXT/SSA"   , AV_CODEC_ID_ASS},> +    
{"S_TEXT/WEBVTT"    , AV_CODEC_ID_WEBVTT},>  {"S_ASS"    , 
AV_CODEC_ID_ASS},>  {"S_SSA"    , AV_CODEC_ID_ASS},>  
{"S_VOBSUB" , AV_CODEC_ID_DVD_SUBTITLE},> @@ -100,6 +96,14 @@ const 
CodecTags ff_mkv_codec_tags[]={>  {"V_VP8"    , AV_CODEC_ID_VP8},>  
    {"V_VP9"    , AV_CODEC_ID_VP9},>  > +    /* These codec strings for 
webvtt seem to be depreciated from the Matroska> +   spec, but it might be 
useful to keep them for compatibility for older> +   files. These are at 
the bottom so they get matched after S_TEXT/WEBVTT. */> +    
{"D_WEBVTT/SUBTITLES"   , AV_CODEC_ID_WEBVTT},> +    {"D_WEBVTT/CAPTIONS"    , 
AV_CODEC_ID_WEBVTT},> +    {"D_WEBVTT/DESCRIPTIONS", AV_CODEC_ID_WEBVTT},> +    
{"D_WEBVTT/METADATA"    , AV_CODEC_ID_WEBVTT},> +>  {"" , 
AV_CODEC_ID_NONE}>  };>  > You are not fixing #5641 at all; in fact your 
comment suggests that youmisunderstand the problem: There are two ways to mux 
WebVTT, one forWebM (using these "D_WEBVTT_*" values and one for Matroska. The 
WebM wayof doing WebVTT is the older one of the two and it is horrible, but 
itis the one that is supported. There was a patchset last year [1], [2] tofix 
this and implement the Matroska way, yet the author never sent afollow-up.Your 
patch would make the muxer write the packets in the WebM way, yetthe header 
would claim it to be the Matroska way. This is worse than itis now.- 
Andreas[1]: https://ffmpeg.org/pipermail/ffmpeg-devel/2020-June/264695.html[2]: 
https://ffmpeg.org/pipermail/ffmpeg-devel/2020-June/264693.html___ffmpeg-devel
 mailing 
listffmpeg-devel@ffmpeg.orghttps://ffmpeg.org/mailman/listinfo/ffmpeg-develTo 
unsubscribe, visit link above, or emailffmpeg-devel-requ...@ffmpeg.org with 
subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] Add matroska codec id S_TEXT/WEBVTT for WebVTT streams.

2021-02-07 Thread Andreas Rheinhardt
Walter:
> I understand. Would it be better to roll back the patch to just adding 
> S_TEXT/WEBVTT to list of recognized codec ids for now?

We would need to add support for the Matroska way first.

- Andreas
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avfilter/vf_tile: remove extra whitespace in option description

2021-02-07 Thread Nicolas George
Paul B Mahol (12021-02-05):
> Signed-off-by: Paul B Mahol 
> ---
>  libavfilter/vf_tile.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

LGTM.

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 16/50] avformat/dv: use av_packet_alloc() to allocate packets

2021-02-07 Thread Andreas Rheinhardt
James Almer:
> Signed-off-by: James Almer 
> ---
> This one must be committed after the upcoming major bump, as it changes
> the return value of an avpriv function.
> 
>  libavdevice/iec61883.c |  2 +-
>  libavformat/dv.c   | 56 --
>  2 files changed, 38 insertions(+), 20 deletions(-)
> 
> diff --git a/libavdevice/iec61883.c b/libavdevice/iec61883.c
> index cafafb2672..4582ada151 100644
> --- a/libavdevice/iec61883.c
> +++ b/libavdevice/iec61883.c
> @@ -191,7 +191,7 @@ static int iec61883_parse_queue_dv(struct iec61883_data 
> *dv, AVPacket *pkt)
>  int size;
>  
>  size = avpriv_dv_get_packet(dv->dv_demux, pkt);
> -if (size > 0)
> +if (size)
>  return size;
>  
>  packet = dv->queue_first;
> diff --git a/libavformat/dv.c b/libavformat/dv.c
> index 26a78139f5..f5c0c44afc 100644
> --- a/libavformat/dv.c
> +++ b/libavformat/dv.c
> @@ -45,7 +45,7 @@ struct DVDemuxContext {
>  AVFormatContext*  fctx;
>  AVStream* vst;
>  AVStream* ast[4];
> -AVPacket  audio_pkt[4];
> +AVPacket  *audio_pkt[4];
>  uint8_t   audio_buf[4][8192];
>  int   ach;
>  int   frames;
> @@ -261,11 +261,10 @@ static int dv_extract_audio_info(DVDemuxContext *c, 
> const uint8_t *frame)
>  c->ast[i]->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
>  c->ast[i]->codecpar->codec_id   = AV_CODEC_ID_PCM_S16LE;
>  
> -av_init_packet(&c->audio_pkt[i]);
> -c->audio_pkt[i].size = 0;
> -c->audio_pkt[i].data = c->audio_buf[i];
> -c->audio_pkt[i].stream_index = c->ast[i]->index;
> -c->audio_pkt[i].flags   |= AV_PKT_FLAG_KEY;
> +c->audio_pkt[i]->size = 0;
> +c->audio_pkt[i]->data = c->audio_buf[i];
> +c->audio_pkt[i]->stream_index = c->ast[i]->index;
> +c->audio_pkt[i]->flags   |= AV_PKT_FLAG_KEY;
>  }
>  c->ast[i]->codecpar->sample_rate= dv_audio_frequency[freq];
>  c->ast[i]->codecpar->channels   = 2;
> @@ -332,6 +331,12 @@ static int dv_init_demux(AVFormatContext *s, 
> DVDemuxContext *c)
>  c->vst->codecpar->bit_rate   = 2500;
>  c->vst->start_time= 0;
>  
> +for (int i = 0; i < 4; i++) {
> +c->audio_pkt[i] = av_packet_alloc();
> +if (!c->audio_pkt[i])
> +return AVERROR(ENOMEM);

This leads to lots of leaks on error, for both avpriv_dv_init_demux (for
which a free function will be necessary) as well as the dv demuxer
(whose read_close function is not called automatically on error).

> +}
> +
>  return 0;
>  }
>  
> @@ -353,13 +358,15 @@ DVDemuxContext *avpriv_dv_init_demux(AVFormatContext *s)
>  
>  int avpriv_dv_get_packet(DVDemuxContext *c, AVPacket *pkt)
>  {
> -int size = -1;
> +int size = 0;
>  int i;
>  
>  for (i = 0; i < c->ach; i++) {
> -if (c->ast[i] && c->audio_pkt[i].size) {
> -*pkt = c->audio_pkt[i];
> -c->audio_pkt[i].size = 0;
> +if (c->ast[i] && c->audio_pkt[i]->size) {
> +int ret = av_packet_ref(pkt, c->audio_pkt[i]);
> +if (ret < 0)
> +return ret;
> +c->audio_pkt[i]->size = 0;
>  size = pkt->size;
>  break;
>  }
> @@ -384,9 +391,9 @@ int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket 
> *pkt,
>  /* FIXME: in case of no audio/bad audio we have to do something */
>  size = dv_extract_audio_info(c, buf);
>  for (i = 0; i < c->ach; i++) {
> -c->audio_pkt[i].pos  = pos;
> -c->audio_pkt[i].size = size;
> -c->audio_pkt[i].pts  = (c->sys->height == 720) ? (c->frames & ~1) : 
> c->frames;
> +c->audio_pkt[i]->pos  = pos;
> +c->audio_pkt[i]->size = size;
> +c->audio_pkt[i]->pts  = (c->sys->height == 720) ? (c->frames & ~1) : 
> c->frames;
>  ppcm[i] = c->audio_buf[i];
>  }
>  if (c->ach)
> @@ -396,15 +403,14 @@ int avpriv_dv_produce_packet(DVDemuxContext *c, 
> AVPacket *pkt,
>   * channels 0,1 and odd 2,3. */
>  if (c->sys->height == 720) {
>  if (buf[1] & 0x0C) {
> -c->audio_pkt[2].size = c->audio_pkt[3].size = 0;
> +c->audio_pkt[2]->size = c->audio_pkt[3]->size = 0;
>  } else {
> -c->audio_pkt[0].size = c->audio_pkt[1].size = 0;
> +c->audio_pkt[0]->size = c->audio_pkt[1]->size = 0;
>  }
>  }
>  
>  /* Now it's time to return video packet */
>  size = dv_extract_video_info(c, buf);
> -av_init_packet(pkt);

This function here is a bit nuts: It predates reference-counted buffers
and so it simply resets pkt->buf (it in fact treats pkt purely as
something for output as if it were already blank). The mov and avi
demuxers work around this by copying pkt->buf and putting it in the
retur

[FFmpeg-devel] [PATCH] fix some filter dependencies

2021-02-07 Thread Matthias Troffaes
Currently, ffmpeg builds with --disable-avcodec --disable-avformat
--enable-avfilter result in a broken avfilter library due to a few
filters that require avcodec or avformat are mistakenly compiled in.
For example, see:

https://ci.appveyor.com/project/mcmtroffaes/ffmpeg-msvc-build/builds/37633531/job/x19boq3c5qi4u132#L414

The attached patch fixes this.


0014-avfilter-dependency-fix.patch
Description: Binary data
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 1/2] avformat/libsrt: add LIBSRT_SETSOCKOPT/GETSOCKOPT helper

2021-02-07 Thread Zhao Zhili
To avoid duplicate between optname and optnamestr.
---
 libavformat/libsrt.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
index f73e7dbfa5..557ab9e6e3 100644
--- a/libavformat/libsrt.c
+++ b/libavformat/libsrt.c
@@ -272,6 +272,9 @@ static int libsrt_setsockopt(URLContext *h, int fd, 
SRT_SOCKOPT optname, const c
 return 0;
 }
 
+#define LIBSRT_SETSOCKOPT(h, fd, optname, optval, optlen) \
+libsrt_setsockopt((h), (fd), (optname), AV_TOSTRING(optname), (optval), 
(optlen))
+
 static int libsrt_getsockopt(URLContext *h, int fd, SRT_SOCKOPT optname, const 
char * optnamestr, void * optval, int * optlen)
 {
 if (srt_getsockopt(fd, 0, optname, optval, optlen) < 0) {
@@ -281,6 +284,9 @@ static int libsrt_getsockopt(URLContext *h, int fd, 
SRT_SOCKOPT optname, const c
 return 0;
 }
 
+#define LIBSRT_GETSOCKOPT(h, fd, optname, optval, optlen) \
+libsrt_getsockopt((h), (fd), (optname), AV_TOSTRING(optname), (optval), 
(optlen))
+
 /* - The "POST" options can be altered any time on a connected socket.
  They MAY have also some meaning when set prior to connecting; such
  option is SRTO_RCVSYN, which makes connect/accept call asynchronous.
-- 
2.28.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 2/2] avformat/libsrt: use LIBSRT_SETSOCKOPT/GETSOCKOPT helper to reduce duplication

2021-02-07 Thread Zhao Zhili
---
 libavformat/libsrt.c | 66 ++--
 1 file changed, 33 insertions(+), 33 deletions(-)

diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
index 557ab9e6e3..d3c661d9d8 100644
--- a/libavformat/libsrt.c
+++ b/libavformat/libsrt.c
@@ -295,8 +295,8 @@ static int libsrt_set_options_post(URLContext *h, int fd)
 {
 SRTContext *s = h->priv_data;
 
-if ((s->inputbw >= 0 && libsrt_setsockopt(h, fd, SRTO_INPUTBW, 
"SRTO_INPUTBW", &s->inputbw, sizeof(s->inputbw)) < 0) ||
-(s->oheadbw >= 0 && libsrt_setsockopt(h, fd, SRTO_OHEADBW, 
"SRTO_OHEADBW", &s->oheadbw, sizeof(s->oheadbw)) < 0)) {
+if ((s->inputbw >= 0 && LIBSRT_SETSOCKOPT(h, fd, SRTO_INPUTBW, 
&s->inputbw, sizeof(s->inputbw)) < 0) ||
+(s->oheadbw >= 0 && LIBSRT_SETSOCKOPT(h, fd, SRTO_OHEADBW, 
&s->oheadbw, sizeof(s->oheadbw)) < 0)) {
 return AVERROR(EIO);
 }
 return 0;
@@ -314,44 +314,44 @@ static int libsrt_set_options_pre(URLContext *h, int fd)
 int peerlatency = s->peerlatency / 1000;
 int connect_timeout = s->connect_timeout;
 
-if ((s->mode == SRT_MODE_RENDEZVOUS && libsrt_setsockopt(h, fd, 
SRTO_RENDEZVOUS, "SRTO_RENDEZVOUS", &yes, sizeof(yes)) < 0) ||
-(s->transtype != SRTT_INVALID && libsrt_setsockopt(h, fd, 
SRTO_TRANSTYPE, "SRTO_TRANSTYPE", &s->transtype, sizeof(s->transtype)) < 0) ||
-(s->maxbw >= 0 && libsrt_setsockopt(h, fd, SRTO_MAXBW, "SRTO_MAXBW", 
&s->maxbw, sizeof(s->maxbw)) < 0) ||
-(s->pbkeylen >= 0 && libsrt_setsockopt(h, fd, SRTO_PBKEYLEN, 
"SRTO_PBKEYLEN", &s->pbkeylen, sizeof(s->pbkeylen)) < 0) ||
-(s->passphrase && libsrt_setsockopt(h, fd, SRTO_PASSPHRASE, 
"SRTO_PASSPHRASE", s->passphrase, strlen(s->passphrase)) < 0) ||
+if ((s->mode == SRT_MODE_RENDEZVOUS && LIBSRT_SETSOCKOPT(h, fd, 
SRTO_RENDEZVOUS, &yes, sizeof(yes)) < 0) ||
+(s->transtype != SRTT_INVALID && LIBSRT_SETSOCKOPT(h, fd, 
SRTO_TRANSTYPE, &s->transtype, sizeof(s->transtype)) < 0) ||
+(s->maxbw >= 0 && LIBSRT_SETSOCKOPT(h, fd, SRTO_MAXBW, &s->maxbw, 
sizeof(s->maxbw)) < 0) ||
+(s->pbkeylen >= 0 && LIBSRT_SETSOCKOPT(h, fd, SRTO_PBKEYLEN, 
&s->pbkeylen, sizeof(s->pbkeylen)) < 0) ||
+(s->passphrase && LIBSRT_SETSOCKOPT(h, fd, SRTO_PASSPHRASE, 
s->passphrase, strlen(s->passphrase)) < 0) ||
 #if SRT_VERSION_VALUE >= 0x010302
 #if SRT_VERSION_VALUE >= 0x010401
-(s->enforced_encryption >= 0 && libsrt_setsockopt(h, fd, 
SRTO_ENFORCEDENCRYPTION, "SRTO_ENFORCEDENCRYPTION", &s->enforced_encryption, 
sizeof(s->enforced_encryption)) < 0) ||
+(s->enforced_encryption >= 0 && LIBSRT_SETSOCKOPT(h, fd, 
SRTO_ENFORCEDENCRYPTION, &s->enforced_encryption, 
sizeof(s->enforced_encryption)) < 0) ||
 #else
 /* SRTO_STRICTENC == SRTO_ENFORCEDENCRYPTION (53), but for 
compatibility, we used SRTO_STRICTENC */
-(s->enforced_encryption >= 0 && libsrt_setsockopt(h, fd, 
SRTO_STRICTENC, "SRTO_STRICTENC", &s->enforced_encryption, 
sizeof(s->enforced_encryption)) < 0) ||
+(s->enforced_encryption >= 0 && LIBSRT_SETSOCKOPT(h, fd, 
SRTO_STRICTENC, &s->enforced_encryption, sizeof(s->enforced_encryption)) < 0) ||
 #endif
-(s->kmrefreshrate >= 0 && libsrt_setsockopt(h, fd, SRTO_KMREFRESHRATE, 
"SRTO_KMREFRESHRATE", &s->kmrefreshrate, sizeof(s->kmrefreshrate)) < 0) ||
-(s->kmpreannounce >= 0 && libsrt_setsockopt(h, fd, SRTO_KMPREANNOUNCE, 
"SRTO_KMPREANNOUNCE", &s->kmpreannounce, sizeof(s->kmpreannounce)) < 0) ||
+(s->kmrefreshrate >= 0 && LIBSRT_SETSOCKOPT(h, fd, SRTO_KMREFRESHRATE, 
&s->kmrefreshrate, sizeof(s->kmrefreshrate)) < 0) ||
+(s->kmpreannounce >= 0 && LIBSRT_SETSOCKOPT(h, fd, SRTO_KMPREANNOUNCE, 
&s->kmpreannounce, sizeof(s->kmpreannounce)) < 0) ||
 #endif
-(s->mss >= 0 && libsrt_setsockopt(h, fd, SRTO_MSS, "SRTO_MSS", 
&s->mss, sizeof(s->mss)) < 0) ||
-(s->ffs >= 0 && libsrt_setsockopt(h, fd, SRTO_FC, "SRTO_FC", &s->ffs, 
sizeof(s->ffs)) < 0) ||
-(s->ipttl >= 0 && libsrt_setsockopt(h, fd, SRTO_IPTTL, "SRTO_IPTTL", 
&s->ipttl, sizeof(s->ipttl)) < 0) ||
-(s->iptos >= 0 && libsrt_setsockopt(h, fd, SRTO_IPTOS, "SRTO_IPTOS", 
&s->iptos, sizeof(s->iptos)) < 0) ||
-(s->latency >= 0 && libsrt_setsockopt(h, fd, SRTO_LATENCY, 
"SRTO_LATENCY", &latency, sizeof(latency)) < 0) ||
-(s->rcvlatency >= 0 && libsrt_setsockopt(h, fd, SRTO_RCVLATENCY, 
"SRTO_RCVLATENCY", &rcvlatency, sizeof(rcvlatency)) < 0) ||
-(s->peerlatency >= 0 && libsrt_setsockopt(h, fd, SRTO_PEERLATENCY, 
"SRTO_PEERLATENCY", &peerlatency, sizeof(peerlatency)) < 0) ||
-(s->tlpktdrop >= 0 && libsrt_setsockopt(h, fd, SRTO_TLPKTDROP, 
"SRTO_TLPKDROP", &s->tlpktdrop, sizeof(s->tlpktdrop)) < 0) ||
-(s->nakreport >= 0 && libsrt_setsockopt(h, fd, SRTO_NAKREPORT, 
"SRTO_NAKREPORT", &s->nakreport, sizeof(s->nakreport)) < 0) ||
-(connect_timeout >= 0 && libsrt_setsockopt(h, fd, SRTO_CONNTIMEO, 
"SRTO_CONNTIMEO", &connect_timeout, sizeof(con

[FFmpeg-devel] FFmpeg batch files for Windows os

2021-02-07 Thread Brendan Castaneda
Hi, good day! i'm working on mine project, it is batch scripts for
your utilities FFmpeg, on Windows os.
My repository https://github.com/brendan8c/FFMPEG_BAT
Are we can work together or dev collaboration?
I want to be part yours projects. What you think?
I'm sorry my English is weak but i studying his.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 50/50] fftools/ffplay: use av_packet_alloc() to allocate packets

2021-02-07 Thread Marton Balint



On Thu, 4 Feb 2021, James Almer wrote:


Signed-off-by: James Almer 
---
fftools/ffplay.c | 204 +--
1 file changed, 127 insertions(+), 77 deletions(-)


Thanks for this, I see a couple of things that can be simplified, maybe it 
is easier if I take over this patch and take care of it directly if you 
don't mind.


Thanks,
Marton



diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index 9ff0425163..d48edc0797 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -36,6 +36,7 @@
#include "libavutil/pixdesc.h"
#include "libavutil/imgutils.h"
#include "libavutil/dict.h"
+#include "libavutil/fifo.h"
#include "libavutil/parseutils.h"
#include "libavutil/samplefmt.h"
#include "libavutil/avassert.h"
@@ -111,13 +112,12 @@ const int program_birth_year = 2003;
static unsigned sws_flags = SWS_BICUBIC;

typedef struct MyAVPacketList {
-AVPacket pkt;
-struct MyAVPacketList *next;
+AVPacket *pkt;
int serial;
} MyAVPacketList;

typedef struct PacketQueue {
-MyAVPacketList *first_pkt, *last_pkt;
+AVFifoBuffer *pkt_list;
int nb_packets;
int size;
int64_t duration;
@@ -187,7 +187,8 @@ enum {
};

typedef struct Decoder {
-AVPacket pkt;
+AVPacket *pkt;
+AVPacket *tmp_pkt;
PacketQueue *queue;
AVCodecContext *avctx;
int pkt_serial;
@@ -361,7 +362,7 @@ static int filter_nbthreads = 0;
static int is_full_screen;
static int64_t audio_callback_time;

-static AVPacket flush_pkt;
+static uint8_t flush_pkt;

#define FF_QUIT_EVENT(SDL_USEREVENT + 2)

@@ -427,28 +428,25 @@ int64_t get_valid_channel_layout(int64_t channel_layout, 
int channels)

static int packet_queue_put_private(PacketQueue *q, AVPacket *pkt)
{
-MyAVPacketList *pkt1;
+MyAVPacketList pkt1;

if (q->abort_request)
   return -1;

-pkt1 = av_malloc(sizeof(MyAVPacketList));
-if (!pkt1)
-return -1;
-pkt1->pkt = *pkt;
-pkt1->next = NULL;
-if (pkt == &flush_pkt)
+if (av_fifo_space(q->pkt_list) < sizeof(pkt1)) {
+if (av_fifo_grow(q->pkt_list, sizeof(pkt1)) < 0)
+return -1;
+}
+
+if (pkt->data == &flush_pkt)
q->serial++;
-pkt1->serial = q->serial;
+pkt1.pkt = pkt;
+pkt1.serial = q->serial;

-if (!q->last_pkt)
-q->first_pkt = pkt1;
-else
-q->last_pkt->next = pkt1;
-q->last_pkt = pkt1;
+av_fifo_generic_write(q->pkt_list, &pkt1, sizeof(pkt1), NULL);
q->nb_packets++;
-q->size += pkt1->pkt.size + sizeof(*pkt1);
-q->duration += pkt1->pkt.duration;
+q->size += pkt1.pkt->size + sizeof(pkt1);
+q->duration += pkt1.pkt->duration;
/* XXX: should duplicate packet data in DV case */
SDL_CondSignal(q->cond);
return 0;
@@ -456,32 +454,66 @@ static int packet_queue_put_private(PacketQueue *q, 
AVPacket *pkt)

static int packet_queue_put(PacketQueue *q, AVPacket *pkt)
{
+AVPacket *pkt1;
int ret;

+pkt1 = av_packet_clone(pkt);
+if (!pkt1)
+   return -1;
SDL_LockMutex(q->mutex);
-ret = packet_queue_put_private(q, pkt);
+ret = packet_queue_put_private(q, pkt1);
SDL_UnlockMutex(q->mutex);
-
-if (pkt != &flush_pkt && ret < 0)
+if (ret < 0) {
+av_packet_free(&pkt1);
av_packet_unref(pkt);
+}
+
+return ret;
+}
+
+static int packet_queue_put_flushpacket(PacketQueue *q)
+{
+AVPacket *pkt;
+int ret;
+
+pkt = av_packet_alloc();
+if (!pkt)
+   return -1;
+pkt->data = &flush_pkt;
+SDL_LockMutex(q->mutex);
+ret = packet_queue_put_private(q, pkt);
+SDL_UnlockMutex(q->mutex);
+if (ret < 0)
+av_packet_free(&pkt);

return ret;
}

static int packet_queue_put_nullpacket(PacketQueue *q, int stream_index)
{
-AVPacket pkt1, *pkt = &pkt1;
-av_init_packet(pkt);
-pkt->data = NULL;
-pkt->size = 0;
+AVPacket *pkt;
+int ret;
+
+pkt = av_packet_alloc();
+if (!pkt)
+   return -1;
pkt->stream_index = stream_index;
-return packet_queue_put(q, pkt);
+SDL_LockMutex(q->mutex);
+ret = packet_queue_put_private(q, pkt);
+SDL_UnlockMutex(q->mutex);
+if (ret < 0)
+av_packet_free(&pkt);
+
+return ret;
}

/* packet queue handling */
static int packet_queue_init(PacketQueue *q)
{
memset(q, 0, sizeof(PacketQueue));
+q->pkt_list = av_fifo_alloc(sizeof(MyAVPacketList));
+if (!q->pkt_list)
+return AVERROR(ENOMEM);
q->mutex = SDL_CreateMutex();
if (!q->mutex) {
av_log(NULL, AV_LOG_FATAL, "SDL_CreateMutex(): %s\n", SDL_GetError());
@@ -498,16 +530,13 @@ static int packet_queue_init(PacketQueue *q)

static void packet_queue_flush(PacketQueue *q)
{
-MyAVPacketList *pkt, *pkt1;
+MyAVPacketList pkt1;

SDL_LockMutex(q->mutex);
-for (pkt = q->first_pkt; pkt; pkt = pkt1) {
-pkt1 = pkt->next;
-av_packet_unref(&pkt->pkt);
-av_freep(&pkt);
+while (av_fifo_size(q->pkt_list) >= sizeof(pkt1)) {
+av_fifo_generic_read(q->

Re: [FFmpeg-devel] [PATCH 50/50] fftools/ffplay: use av_packet_alloc() to allocate packets

2021-02-07 Thread James Almer

On 2/7/2021 9:26 AM, Marton Balint wrote:



On Thu, 4 Feb 2021, James Almer wrote:


Signed-off-by: James Almer 
---
fftools/ffplay.c | 204 +--
1 file changed, 127 insertions(+), 77 deletions(-)


Thanks for this, I see a couple of things that can be simplified, maybe 
it is easier if I take over this patch and take care of it directly if 
you don't mind.


Sure, thanks.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 31/50] avformat/wc3movie: use av_packet_alloc() to allocate packets

2021-02-07 Thread James Almer

On 2/7/2021 4:52 AM, Andreas Rheinhardt wrote:

James Almer:

Signed-off-by: James Almer 
---
  libavformat/wc3movie.c | 21 ++---
  1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/libavformat/wc3movie.c b/libavformat/wc3movie.c
index 76e945d261..1fe582945a 100644
--- a/libavformat/wc3movie.c
+++ b/libavformat/wc3movie.c
@@ -69,7 +69,7 @@ typedef struct Wc3DemuxContext {
  int video_stream_index;
  int audio_stream_index;
  
-AVPacket vpkt;

+AVPacket *vpkt;
  
  } Wc3DemuxContext;
  
@@ -77,8 +77,7 @@ static int wc3_read_close(AVFormatContext *s)

  {
  Wc3DemuxContext *wc3 = s->priv_data;
  
-if (wc3->vpkt.size > 0)

-av_packet_unref(&wc3->vpkt);
+av_packet_free(&wc3->vpkt);
  
  return 0;

  }
@@ -110,8 +109,9 @@ static int wc3_read_header(AVFormatContext *s)
  wc3->height = WC3_DEFAULT_HEIGHT;
  wc3->pts = 0;
  wc3->video_stream_index = wc3->audio_stream_index = 0;
-av_init_packet(&wc3->vpkt);
-wc3->vpkt.data = NULL; wc3->vpkt.size = 0;
+wc3->vpkt = av_packet_alloc();
+if (!wc3->vpkt)
+goto fail;


goto fail returns 0. You should instead just return AVERROR(ENOMEM)
directly. Nothing has been (successfully) allocated at this point.


Changed locally. Thanks.



  
  /* skip the first 3 32-bit numbers */

  avio_skip(pb, 12);
@@ -162,7 +162,7 @@ static int wc3_read_header(AVFormatContext *s)
  case PALT_TAG:
  /* one of several palettes */
  avio_seek(pb, -8, SEEK_CUR);
-av_append_packet(pb, &wc3->vpkt, 8 + PALETTE_SIZE);
+av_append_packet(pb, wc3->vpkt, 8 + PALETTE_SIZE);
  break;
  
  default:

@@ -248,18 +248,17 @@ static int wc3_read_packet(AVFormatContext *s,
  case SHOT_TAG:
  /* load up new palette */
  avio_seek(pb, -8, SEEK_CUR);
-av_append_packet(pb, &wc3->vpkt, 8 + 4);
+av_append_packet(pb, wc3->vpkt, 8 + 4);
  break;
  
  case VGA__TAG:

  /* send out video chunk */
  avio_seek(pb, -8, SEEK_CUR);
-ret= av_append_packet(pb, &wc3->vpkt, 8 + size);
+ret= av_append_packet(pb, wc3->vpkt, 8 + size);
  // ignore error if we have some data
-if (wc3->vpkt.size > 0)
+if (wc3->vpkt->size > 0)
  ret = 0;
-*pkt = wc3->vpkt;
-wc3->vpkt.data = NULL; wc3->vpkt.size = 0;
+av_packet_move_ref(pkt, wc3->vpkt);
  pkt->stream_index = wc3->video_stream_index;
  pkt->pts = wc3->pts;
  packet_read = 1;



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 2/3] avdevice/timefilter: remove obsolete comments from the docs

2021-02-07 Thread Nicolas George
Marton Balint (12021-02-07):
> Also rename the parameters of the function to match with the implementation.
> 
> Signed-off-by: Marton Balint 
> ---
>  libavdevice/timefilter.h | 15 +--
>  1 file changed, 1 insertion(+), 14 deletions(-)

Probably ok, I do not remember correcly enough.

Regards,

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 16/50] avformat/dv: use av_packet_alloc() to allocate packets

2021-02-07 Thread James Almer

On 2/7/2021 4:47 AM, Andreas Rheinhardt wrote:

James Almer:

Signed-off-by: James Almer 
---
This one must be committed after the upcoming major bump, as it changes
the return value of an avpriv function.

  libavdevice/iec61883.c |  2 +-
  libavformat/dv.c   | 56 --
  2 files changed, 38 insertions(+), 20 deletions(-)

diff --git a/libavdevice/iec61883.c b/libavdevice/iec61883.c
index cafafb2672..4582ada151 100644
--- a/libavdevice/iec61883.c
+++ b/libavdevice/iec61883.c
@@ -191,7 +191,7 @@ static int iec61883_parse_queue_dv(struct iec61883_data 
*dv, AVPacket *pkt)
  int size;
  
  size = avpriv_dv_get_packet(dv->dv_demux, pkt);

-if (size > 0)
+if (size)
  return size;
  
  packet = dv->queue_first;

diff --git a/libavformat/dv.c b/libavformat/dv.c
index 26a78139f5..f5c0c44afc 100644
--- a/libavformat/dv.c
+++ b/libavformat/dv.c
@@ -45,7 +45,7 @@ struct DVDemuxContext {
  AVFormatContext*  fctx;
  AVStream* vst;
  AVStream* ast[4];
-AVPacket  audio_pkt[4];
+AVPacket  *audio_pkt[4];
  uint8_t   audio_buf[4][8192];
  int   ach;
  int   frames;
@@ -261,11 +261,10 @@ static int dv_extract_audio_info(DVDemuxContext *c, const 
uint8_t *frame)
  c->ast[i]->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
  c->ast[i]->codecpar->codec_id   = AV_CODEC_ID_PCM_S16LE;
  
-av_init_packet(&c->audio_pkt[i]);

-c->audio_pkt[i].size = 0;
-c->audio_pkt[i].data = c->audio_buf[i];
-c->audio_pkt[i].stream_index = c->ast[i]->index;
-c->audio_pkt[i].flags   |= AV_PKT_FLAG_KEY;
+c->audio_pkt[i]->size = 0;
+c->audio_pkt[i]->data = c->audio_buf[i];
+c->audio_pkt[i]->stream_index = c->ast[i]->index;
+c->audio_pkt[i]->flags   |= AV_PKT_FLAG_KEY;
  }
  c->ast[i]->codecpar->sample_rate= dv_audio_frequency[freq];
  c->ast[i]->codecpar->channels   = 2;
@@ -332,6 +331,12 @@ static int dv_init_demux(AVFormatContext *s, 
DVDemuxContext *c)
  c->vst->codecpar->bit_rate   = 2500;
  c->vst->start_time= 0;
  
+for (int i = 0; i < 4; i++) {

+c->audio_pkt[i] = av_packet_alloc();
+if (!c->audio_pkt[i])
+return AVERROR(ENOMEM);


This leads to lots of leaks on error, for both avpriv_dv_init_demux (for
which a free function will be necessary) as well as the dv demuxer
(whose read_close function is not called automatically on error).


Will fix.




+}
+
  return 0;
  }
  
@@ -353,13 +358,15 @@ DVDemuxContext *avpriv_dv_init_demux(AVFormatContext *s)
  
  int avpriv_dv_get_packet(DVDemuxContext *c, AVPacket *pkt)

  {
-int size = -1;
+int size = 0;
  int i;
  
  for (i = 0; i < c->ach; i++) {

-if (c->ast[i] && c->audio_pkt[i].size) {
-*pkt = c->audio_pkt[i];
-c->audio_pkt[i].size = 0;
+if (c->ast[i] && c->audio_pkt[i]->size) {
+int ret = av_packet_ref(pkt, c->audio_pkt[i]);
+if (ret < 0)
+return ret;
+c->audio_pkt[i]->size = 0;
  size = pkt->size;
  break;
  }
@@ -384,9 +391,9 @@ int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket 
*pkt,
  /* FIXME: in case of no audio/bad audio we have to do something */
  size = dv_extract_audio_info(c, buf);
  for (i = 0; i < c->ach; i++) {
-c->audio_pkt[i].pos  = pos;
-c->audio_pkt[i].size = size;
-c->audio_pkt[i].pts  = (c->sys->height == 720) ? (c->frames & ~1) : 
c->frames;
+c->audio_pkt[i]->pos  = pos;
+c->audio_pkt[i]->size = size;
+c->audio_pkt[i]->pts  = (c->sys->height == 720) ? (c->frames & ~1) : 
c->frames;
  ppcm[i] = c->audio_buf[i];
  }
  if (c->ach)
@@ -396,15 +403,14 @@ int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket 
*pkt,
   * channels 0,1 and odd 2,3. */
  if (c->sys->height == 720) {
  if (buf[1] & 0x0C) {
-c->audio_pkt[2].size = c->audio_pkt[3].size = 0;
+c->audio_pkt[2]->size = c->audio_pkt[3]->size = 0;
  } else {
-c->audio_pkt[0].size = c->audio_pkt[1].size = 0;
+c->audio_pkt[0]->size = c->audio_pkt[1]->size = 0;
  }
  }
  
  /* Now it's time to return video packet */

  size = dv_extract_video_info(c, buf);
-av_init_packet(pkt);


This function here is a bit nuts: It predates reference-counted buffers
and so it simply resets pkt->buf (it in fact treats pkt purely as
something for output as if it were already blank). The mov and avi
demuxers work around this by copying pkt->buf and putting it in the
returned packet afterwards (which is probably unnecessary when the above
call is ; whereas the iec61883 device/demuxer

[FFmpeg-devel] [PATCH 1/2] avformat/network: fix timeout inaccurate in wait_fd_timeout

2021-02-07 Thread Zhao Zhili
The wait_start was about POLLING_TIME larger which leads to timeout
100ms late than the option setting.
---
 libavformat/network.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/libavformat/network.c b/libavformat/network.c
index 0f5a575f77..7a9a4be5bb 100644
--- a/libavformat/network.c
+++ b/libavformat/network.c
@@ -78,7 +78,10 @@ int ff_network_wait_fd(int fd, int write)
 int ff_network_wait_fd_timeout(int fd, int write, int64_t timeout, 
AVIOInterruptCB *int_cb)
 {
 int ret;
-int64_t wait_start = 0;
+int64_t wait_start;
+
+if (timeout > 0)
+wait_start = av_gettime_relative();
 
 while (1) {
 if (ff_check_interrupt(int_cb))
@@ -86,12 +89,8 @@ int ff_network_wait_fd_timeout(int fd, int write, int64_t 
timeout, AVIOInterrupt
 ret = ff_network_wait_fd(fd, write);
 if (ret != AVERROR(EAGAIN))
 return ret;
-if (timeout > 0) {
-if (!wait_start)
-wait_start = av_gettime_relative();
-else if (av_gettime_relative() - wait_start > timeout)
-return AVERROR(ETIMEDOUT);
-}
+if (timeout > 0 && (av_gettime_relative() - wait_start > timeout))
+return AVERROR(ETIMEDOUT);
 }
 }
 
-- 
2.28.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 2/2] avformat/libsrt: fix timeout inaccurate in wait_fd_timeout

2021-02-07 Thread Zhao Zhili
The wait_start was about POLLING_TIME larger which leads to timeout
100ms late than the option setting.
---
 libavformat/libsrt.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
index d3c661d9d8..d08634b71a 100644
--- a/libavformat/libsrt.c
+++ b/libavformat/libsrt.c
@@ -196,7 +196,10 @@ static int libsrt_network_wait_fd(URLContext *h, int eid, 
int fd, int write)
 static int libsrt_network_wait_fd_timeout(URLContext *h, int eid, int fd, int 
write, int64_t timeout, AVIOInterruptCB *int_cb)
 {
 int ret;
-int64_t wait_start = 0;
+int64_t wait_start;
+
+if (timeout > 0)
+wait_start = av_gettime_relative();
 
 while (1) {
 if (ff_check_interrupt(int_cb))
@@ -204,12 +207,8 @@ static int libsrt_network_wait_fd_timeout(URLContext *h, 
int eid, int fd, int wr
 ret = libsrt_network_wait_fd(h, eid, fd, write);
 if (ret != AVERROR(EAGAIN))
 return ret;
-if (timeout > 0) {
-if (!wait_start)
-wait_start = av_gettime_relative();
-else if (av_gettime_relative() - wait_start > timeout)
-return AVERROR(ETIMEDOUT);
-}
+if (timeout > 0 && (av_gettime_relative() - wait_start > timeout))
+return AVERROR(ETIMEDOUT);
 }
 }
 
-- 
2.28.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 3/3] avdevice: use av_gettime_relative() for timestamps

2021-02-07 Thread Nicolas George
Marton Balint (12021-02-07):
> av_gettime_relative() is using the monotonic clock therefore more suitable as 
> a
> timestamp source and for relative time calculations.
> 
> Probably fixes ticket #9089.

Not ok.

This is a user-visible change of behavior, we cannot do it just like
that.

Furthermore, for devices, timestamps are not only needed to synchronize
between devices within the same computer, they may be needed to
synchronize between devices connected to different computers, or between
devices and other network streams (IP webcams are the obvious example).

The best course of action is to generalize what was done with v4l: make
it an option.

Regards,

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 2/2] avformat/libsrt: fix timeout inaccurate in wait_fd_timeout

2021-02-07 Thread Nicolas George
Zhao Zhili (12021-02-07):
> The wait_start was about POLLING_TIME larger which leads to timeout
> 100ms late than the option setting.
> ---
>  libavformat/libsrt.c | 13 ++---
>  1 file changed, 6 insertions(+), 7 deletions(-)

I see two patches with exactly identical code, except for a single
function name.

Please try to merge it to avoid duplication.

Regards,

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] avfilter/buffersrc: simplify av_buffersrc_add_frame_flags()

2021-02-07 Thread James Almer
Signed-off-by: James Almer 
---
 libavfilter/buffersrc.c | 38 --
 1 file changed, 8 insertions(+), 30 deletions(-)

diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c
index bf30f54177..da1cf9941e 100644
--- a/libavfilter/buffersrc.c
+++ b/libavfilter/buffersrc.c
@@ -149,33 +149,6 @@ int attribute_align_arg 
av_buffersrc_add_frame(AVFilterContext *ctx, AVFrame *fr
 return av_buffersrc_add_frame_flags(ctx, frame, 0);
 }
 
-static int av_buffersrc_add_frame_internal(AVFilterContext *ctx,
-   AVFrame *frame, int flags);
-
-int attribute_align_arg av_buffersrc_add_frame_flags(AVFilterContext *ctx, 
AVFrame *frame, int flags)
-{
-AVFrame *copy = NULL;
-int ret = 0;
-
-if (frame && frame->channel_layout &&
-av_get_channel_layout_nb_channels(frame->channel_layout) != 
frame->channels) {
-av_log(ctx, AV_LOG_ERROR, "Layout indicates a different number of 
channels than actually present\n");
-return AVERROR(EINVAL);
-}
-
-if (!(flags & AV_BUFFERSRC_FLAG_KEEP_REF) || !frame)
-return av_buffersrc_add_frame_internal(ctx, frame, flags);
-
-if (!(copy = av_frame_alloc()))
-return AVERROR(ENOMEM);
-ret = av_frame_ref(copy, frame);
-if (ret >= 0)
-ret = av_buffersrc_add_frame_internal(ctx, copy, flags);
-
-av_frame_free(©);
-return ret;
-}
-
 static int push_frame(AVFilterGraph *graph)
 {
 int ret;
@@ -190,13 +163,18 @@ static int push_frame(AVFilterGraph *graph)
 return 0;
 }
 
-static int av_buffersrc_add_frame_internal(AVFilterContext *ctx,
-   AVFrame *frame, int flags)
+int attribute_align_arg av_buffersrc_add_frame_flags(AVFilterContext *ctx, 
AVFrame *frame, int flags)
 {
 BufferSourceContext *s = ctx->priv;
 AVFrame *copy;
 int refcounted, ret;
 
+if (frame && frame->channel_layout &&
+av_get_channel_layout_nb_channels(frame->channel_layout) != 
frame->channels) {
+av_log(ctx, AV_LOG_ERROR, "Layout indicates a different number of 
channels than actually present\n");
+return AVERROR(EINVAL);
+}
+
 s->nb_failed_requests = 0;
 
 if (!frame)
@@ -229,7 +207,7 @@ static int av_buffersrc_add_frame_internal(AVFilterContext 
*ctx,
 if (!(copy = av_frame_alloc()))
 return AVERROR(ENOMEM);
 
-if (refcounted) {
+if (refcounted && !(flags & AV_BUFFERSRC_FLAG_KEEP_REF)) {
 av_frame_move_ref(copy, frame);
 } else {
 ret = av_frame_ref(copy, frame);
-- 
2.30.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 3/3] avdevice: use av_gettime_relative() for timestamps

2021-02-07 Thread Kieran Kunhya
On Sun, 7 Feb 2021, 14:21 Nicolas George,  wrote:

> Marton Balint (12021-02-07):
> > av_gettime_relative() is using the monotonic clock therefore more
> suitable as a
> > timestamp source and for relative time calculations.
> >
> > Probably fixes ticket #9089.
>
> Not ok.
>
> This is a user-visible change of behavior, we cannot do it just like
> that.
>
> Furthermore, for devices, timestamps are not only needed to synchronize
> between devices within the same computer, they may be needed to
> synchronize between devices connected to different computers, or between
> devices and other network streams (IP webcams are the obvious example).
>

It is wrong to suggest that the clock of an IP webcam has any relation at
all to the PC clock both absolute or relative.

The best course of action is to generalize what was done with v4l: make
> it an option.
>

This is as usual a major flaw in v4l2. The monotonic clock should always be
used. It's the least-worst clock.

Kieran

Regards,
>
> --
>   Nicolas George
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 3/3] avdevice: use av_gettime_relative() for timestamps

2021-02-07 Thread Nicolas George
Kieran Kunhya (12021-02-07):
> It is wrong to suggest that the clock of an IP webcam has any relation at
> all to the PC clock both absolute or relative.

It is not wrong to let users observe that their particular model of IP
webcam uses Unix timestamps and is correctly synchronized. This is a
common practice, after all.

> This is as usual a major flaw in v4l2. The monotonic clock should always be
> used. It's the least-worst clock.

Care to justify how giving the user an option is worse than not?

Care to explain how you propose to synchronize device captured on
different computers?

Regards,

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 3/3] avdevice: use av_gettime_relative() for timestamps

2021-02-07 Thread Kieran Kunhya
Sent from my mobile device

On Sun, 7 Feb 2021, 16:31 Nicolas George,  wrote:

> Kieran Kunhya (12021-02-07):
> > It is wrong to suggest that the clock of an IP webcam has any relation at
> > all to the PC clock both absolute or relative.
>
> It is not wrong to let users observe that their particular model of IP
> webcam uses Unix timestamps and is correctly synchronized. This is a
> common practice, after all.


This is nonsense. The clock on any device comes from the oscillator onboard
the device. Not from any PC clock on the motherboard. These clocks are
almost certainly not the same model, they have different temperatures etc
so they drift differently.

> This is as usual a major flaw in v4l2. The monotonic clock should always
> be
> > used. It's the least-worst clock.
>
> Care to justify how giving the user an option is worse than not?


Give the user the option not to use the monotonic clock.

Care to explain how you propose to synchronize device captured on
> different computers?


This is not possible without high end capture equipment to synchronise the
clocks on each camera. Everything else is guesswork.

I encourage you to read the section on clocks here:
https://haasn.xyz/posts/2016-12-25-falsehoods-programmers-believe-about-%5Bvideo-stuff%5D.html

Kieran

Regards,
>
> --
>   Nicolas George
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 3/3] avdevice: use av_gettime_relative() for timestamps

2021-02-07 Thread Nicolas George
Kieran Kunhya (12021-02-07):
> Give the user the option not to use the monotonic clock.

So this should be an option. Thank you very much.

> This is not possible without high end capture equipment to synchronise the
> clocks on each camera. Everything else is guesswork.

This is nonsense. The accuracy of a PC wall time clock with NTP is
plenty accurate enough for most practical purposes.

Regards,

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 3/3] avdevice: use av_gettime_relative() for timestamps

2021-02-07 Thread Kieran Kunhya
Sent from my mobile device

On Sun, 7 Feb 2021, 16:55 Nicolas George,  wrote:

> Kieran Kunhya (12021-02-07):
> > Give the user the option not to use the monotonic clock.
>
> So this should be an option. Thank you very much.


Yes the montonic clock should be the default.

> This is not possible without high end capture equipment to synchronise the
> > clocks on each camera. Everything else is guesswork.
>
> This is nonsense. The accuracy of a PC wall time clock with NTP is
> plenty accurate enough for most practical purposes.
>

You misunderstand greatly. How does the clock rate of NTP magically make
its way to the camera? It doesn't except in very high end setups where the
oscillator on the camera is drifted to match an external time source.

Kieran

Regards,
>
> --
>   Nicolas George
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 3/3] avdevice: use av_gettime_relative() for timestamps

2021-02-07 Thread Nicolas George
Kieran Kunhya (12021-02-07):
> Yes the montonic clock should be the default.

Changing the default is acceptable to me. Probably after a transition
period.

> You misunderstand greatly. How does the clock rate of NTP magically make
> its way to the camera?

I do not know, I do not care, I am not a driver developer. All I know is
that the kernel can give me a timestamp based on the NTP-synchronized
wall time clock, and that it has better than 1/100 second accuracy,
which is plenty enough for must use cases.

Regards,

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 3/3] avdevice: use av_gettime_relative() for timestamps

2021-02-07 Thread Kieran Kunhya
On Sun, 7 Feb 2021, 17:15 Nicolas George,  wrote:

> Kieran Kunhya (12021-02-07):
> > Yes the montonic clock should be the default.
>
> Changing the default is acceptable to me. Probably after a transition
> period.
>
> > You misunderstand greatly. How does the clock rate of NTP magically make
> > its way to the camera?
>
> I do not know, I do not care, I am not a driver developer. All I know is
> that the kernel can give me a timestamp based on the NTP-synchronized
> wall time clock, and that it has better than 1/100 second accuracy,
> which is plenty enough for must use cases.
>

You do care because different sources generated either by a PC or different
physical cameras will drift. E.g at 25fps after one hour you might get
9 frames from one and 90002 or whatever frames from another etc. And of
course the timestamps will drift slowly. Unfortunately you seem to share
the same fundamental misunderstandings as the kernel developers.

Applications like VLC and upipe have sophisticated filtering and drift
compensation to correct all of this.

Kieran

Regards,
>
> --
>   Nicolas George
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 3/3] avdevice: use av_gettime_relative() for timestamps

2021-02-07 Thread Nicolas George
Kieran Kunhya (12021-02-07):
> You do care because different sources generated either by a PC or different
> physical cameras will drift. E.g at 25fps after one hour you might get
> 9 frames from one and 90002 or whatever frames from another etc. And of
> course the timestamps will drift slowly. Unfortunately you seem to share
> the same fundamental misunderstandings as the kernel developers.

Your reasoning is backwards: different time bases is precisely the
reason we need the option of timestamps with a common reference frame.

With the situation you describe, the application that captures the two
cameras can detect that one is faster than the other and duplicate or
skip frames as necessary. Without a common timestamp, it is not
possible.

Regards,

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] fix some filter dependencies

2021-02-07 Thread Nicolas George
Matthias Troffaes (12021-02-07):
> Currently, ffmpeg builds with --disable-avcodec --disable-avformat
> --enable-avfilter result in a broken avfilter library due to a few
> filters that require avcodec or avformat are mistakenly compiled in.
> For example, see:
> 
> https://ci.appveyor.com/project/mcmtroffaes/ffmpeg-msvc-build/builds/37633531/job/x19boq3c5qi4u132#L414
> 
> The attached patch fixes this.

Should be ok, thanks.

Regards,

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 3/3] avdevice: use av_gettime_relative() for timestamps

2021-02-07 Thread Kieran Kunhya
On Sun, 7 Feb 2021, 17:29 Nicolas George,  wrote:

> Kieran Kunhya (12021-02-07):
> > You do care because different sources generated either by a PC or
> different
> > physical cameras will drift. E.g at 25fps after one hour you might get
> > 9 frames from one and 90002 or whatever frames from another etc. And
> of
> > course the timestamps will drift slowly. Unfortunately you seem to share
> > the same fundamental misunderstandings as the kernel developers.
>
> Your reasoning is backwards: different time bases is precisely the
> reason we need the option of timestamps with a common reference frame.
>
> With the situation you describe, the application that captures the two
> cameras can detect that one is faster than the other and duplicate or
> skip frames as necessary. Without a common timestamp, it is not
> possible.
>

Yes and thus you need a monotonic clock as a starting point for proper
filtering. Ffmpeg has neither.

Kieran


> --
>   Nicolas George
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avfilter/avfilter: move enable_str expression parsing into avfilter_init_dict()

2021-02-07 Thread Nicolas George
Paul B Mahol (12021-02-05):
> This ensures that needed arrays are always allocated and properly initialized.
> 
> Previously if code would use only avfilter_init_dict() to set options for 
> filters
> it would not allocate arrays for timeline processing thus it would crash if
> user supplied enable option for filter(s).
> 
> Signed-off-by: Paul B Mahol 
> ---
>  libavfilter/avfilter.c | 11 ++-
>  1 file changed, 6 insertions(+), 5 deletions(-)

LGTM, thanks.

Regards,

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 3/3] avdevice: use av_gettime_relative() for timestamps

2021-02-07 Thread Nicolas George
Kieran Kunhya (12021-02-07):
> Yes and thus you need a monotonic clock as a starting point for proper
> filtering. Ffmpeg has neither.

The kernel provides timestamps that are accurate enough. I do not
understand why you insist on the contrary in the face of facts.

Also, for a properly configured system, the wall time clock is
monotonic.

Regards,

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 1/2] lavf/network: add wait fd callback to ff_network_wait_fd_timeout

2021-02-07 Thread Zhao Zhili
---
 libavformat/libamqp.c |  4 ++--
 libavformat/network.c | 16 ++--
 libavformat/network.h | 14 +-
 libavformat/tcp.c |  6 --
 4 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/libavformat/libamqp.c b/libavformat/libamqp.c
index c3b9c484ea..ca7d3ab70f 100644
--- a/libavformat/libamqp.c
+++ b/libavformat/libamqp.c
@@ -241,7 +241,7 @@ static int amqp_proto_write(URLContext *h, const unsigned 
char *buf, int size)
 amqp_bytes_t message = { size, (void *)buf };
 amqp_basic_properties_t props;
 
-ret = ff_network_wait_fd_timeout(fd, 1, h->rw_timeout, 
&h->interrupt_callback);
+ret = ff_network_wait_fd_timeout(fd, 1, h->rw_timeout, 
&h->interrupt_callback, NULL);
 if (ret)
 return ret;
 
@@ -270,7 +270,7 @@ static int amqp_proto_read(URLContext *h, unsigned char 
*buf, int size)
 amqp_rpc_reply_t broker_reply;
 amqp_envelope_t envelope;
 
-ret = ff_network_wait_fd_timeout(fd, 0, h->rw_timeout, 
&h->interrupt_callback);
+ret = ff_network_wait_fd_timeout(fd, 0, h->rw_timeout, 
&h->interrupt_callback, NULL);
 if (ret)
 return ret;
 
diff --git a/libavformat/network.c b/libavformat/network.c
index 0f5a575f77..48a9af012e 100644
--- a/libavformat/network.c
+++ b/libavformat/network.c
@@ -75,15 +75,27 @@ int ff_network_wait_fd(int fd, int write)
 return ret < 0 ? ff_neterrno() : p.revents & (ev | POLLERR | POLLHUP) ? 0 
: AVERROR(EAGAIN);
 }
 
-int ff_network_wait_fd_timeout(int fd, int write, int64_t timeout, 
AVIOInterruptCB *int_cb)
+static int network_wait_fd_callback(int fd, int write, void *opaque) {
+return ff_network_wait_fd(fd, write);
+}
+
+int ff_network_wait_fd_timeout(int fd, int write, int64_t timeout,
+AVIOInterruptCB *int_cb, const NetworkWaitFdCB *wait_cb)
 {
 int ret;
 int64_t wait_start = 0;
 
+const static NetworkWaitFdCB wait_cb_internal = {
+.wait_fd = network_wait_fd_callback,
+};
+
+if (!wait_cb)
+wait_cb = &wait_cb_internal;
+
 while (1) {
 if (ff_check_interrupt(int_cb))
 return AVERROR_EXIT;
-ret = ff_network_wait_fd(fd, write);
+ret = ff_network_wait_fd_cb(wait_cb, fd, write);
 if (ret != AVERROR(EAGAIN))
 return ret;
 if (timeout > 0) {
diff --git a/libavformat/network.h b/libavformat/network.h
index 71347e815b..1a02a6d9ee 100644
--- a/libavformat/network.h
+++ b/libavformat/network.h
@@ -84,6 +84,16 @@ void ff_network_close(void);
 int ff_tls_init(void);
 void ff_tls_deinit(void);
 
+typedef struct NetworkWaitFdCB {
+int (*wait_fd)(int /*fd*/, int /*write*/, void* /*opaque*/);
+void *opaque;
+} NetworkWaitFdCB;
+
+static av_always_inline int ff_network_wait_fd_cb(const NetworkWaitFdCB *cb,
+int fd, int write) {
+return cb->wait_fd(fd, write, cb->opaque);
+}
+
 int ff_network_wait_fd(int fd, int write);
 
 /**
@@ -94,9 +104,11 @@ int ff_network_wait_fd(int fd, int write);
  * @param write Set 1 to wait for socket able to be read, 0 to be written
  * @param timeout Timeout interval, in microseconds. Actual precision is 
10 mcs, due to ff_network_wait_fd usage
  * @param int_cb Interrupt callback, is checked before each ff_network_wait_fd 
call
+ * @param wait_cb Wait callback, default implementation is used if NULL
  * @return 0 if data can be read/written, AVERROR(ETIMEDOUT) if timeout 
expired, or negative error code
  */
-int ff_network_wait_fd_timeout(int fd, int write, int64_t timeout, 
AVIOInterruptCB *int_cb);
+int ff_network_wait_fd_timeout(int fd, int write, int64_t timeout,
+AVIOInterruptCB *int_cb, const NetworkWaitFdCB *wait_cb);
 
 /**
  * Waits for up to 'timeout' microseconds. If the usert's int_cb is set and
diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index 2198e0f00e..437eaecbb4 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
@@ -237,7 +237,8 @@ static int tcp_read(URLContext *h, uint8_t *buf, int size)
 int ret;
 
 if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
-ret = ff_network_wait_fd_timeout(s->fd, 0, h->rw_timeout, 
&h->interrupt_callback);
+ret = ff_network_wait_fd_timeout(s->fd, 0, h->rw_timeout,
+&h->interrupt_callback, NULL);
 if (ret)
 return ret;
 }
@@ -253,7 +254,8 @@ static int tcp_write(URLContext *h, const uint8_t *buf, int 
size)
 int ret;
 
 if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
-ret = ff_network_wait_fd_timeout(s->fd, 1, h->rw_timeout, 
&h->interrupt_callback);
+ret = ff_network_wait_fd_timeout(s->fd, 1, h->rw_timeout,
+&h->interrupt_callback, NULL);
 if (ret)
 return ret;
 }
-- 
2.27.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 2/2] lavf/libsrt: deduplicate libsrt_network_wait_fd_timeout

2021-02-07 Thread Zhao Zhili
---
 libavformat/libsrt.c | 45 +---
 1 file changed, 17 insertions(+), 28 deletions(-)

diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
index f73e7dbfa5..67e42bacc6 100644
--- a/libavformat/libsrt.c
+++ b/libavformat/libsrt.c
@@ -164,12 +164,14 @@ static int libsrt_socket_nonblock(int socket, int enable)
 return srt_setsockopt(socket, 0, SRTO_RCVSYN, &blocking, sizeof(blocking));
 }
 
-static int libsrt_network_wait_fd(URLContext *h, int eid, int fd, int write)
+static int libsrt_network_wait_fd(int fd, int write, void *ctx)
 {
 int ret, len = 1, errlen = 1;
 int modes = SRT_EPOLL_ERR | (write ? SRT_EPOLL_OUT : SRT_EPOLL_IN);
 SRTSOCKET ready[1];
 SRTSOCKET error[1];
+URLContext *h = ctx;
+int eid = ((SRTContext*)h->priv_data)->eid;
 
 if (srt_epoll_add_usock(eid, fd, &modes) < 0)
 return libsrt_neterrno(h);
@@ -191,29 +193,16 @@ static int libsrt_network_wait_fd(URLContext *h, int eid, 
int fd, int write)
 return ret;
 }
 
-/* TODO de-duplicate code from ff_network_wait_fd_timeout() */
-
-static int libsrt_network_wait_fd_timeout(URLContext *h, int eid, int fd, int 
write, int64_t timeout, AVIOInterruptCB *int_cb)
+static int libsrt_network_wait_fd_timeout(URLContext *h, int fd, int write, 
int64_t timeout)
 {
-int ret;
-int64_t wait_start = 0;
-
-while (1) {
-if (ff_check_interrupt(int_cb))
-return AVERROR_EXIT;
-ret = libsrt_network_wait_fd(h, eid, fd, write);
-if (ret != AVERROR(EAGAIN))
-return ret;
-if (timeout > 0) {
-if (!wait_start)
-wait_start = av_gettime_relative();
-else if (av_gettime_relative() - wait_start > timeout)
-return AVERROR(ETIMEDOUT);
-}
-}
+struct NetworkWaitFdCB wait_cb = {
+.wait_fd = libsrt_network_wait_fd,
+.opaque = h
+};
+return ff_network_wait_fd_timeout(fd, write, timeout, 
&h->interrupt_callback, &wait_cb);
 }
 
-static int libsrt_listen(int eid, int fd, const struct sockaddr *addr, 
socklen_t addrlen, URLContext *h, int64_t timeout)
+static int libsrt_listen(int fd, const struct sockaddr *addr, socklen_t 
addrlen, URLContext *h, int64_t timeout)
 {
 int ret;
 int reuse = 1;
@@ -228,7 +217,7 @@ static int libsrt_listen(int eid, int fd, const struct 
sockaddr *addr, socklen_t
 if (ret)
 return libsrt_neterrno(h);
 
-ret = libsrt_network_wait_fd_timeout(h, eid, fd, 1, timeout, 
&h->interrupt_callback);
+ret = libsrt_network_wait_fd_timeout(h, fd, 1, timeout);
 if (ret < 0)
 return ret;
 
@@ -241,7 +230,7 @@ static int libsrt_listen(int eid, int fd, const struct 
sockaddr *addr, socklen_t
 return ret;
 }
 
-static int libsrt_listen_connect(int eid, int fd, const struct sockaddr *addr, 
socklen_t addrlen, int64_t timeout, URLContext *h, int will_try_next)
+static int libsrt_listen_connect(int fd, const struct sockaddr *addr, 
socklen_t addrlen, int64_t timeout, URLContext *h, int will_try_next)
 {
 int ret;
 
@@ -249,7 +238,7 @@ static int libsrt_listen_connect(int eid, int fd, const 
struct sockaddr *addr, s
 if (ret < 0)
 return libsrt_neterrno(h);
 
-ret = libsrt_network_wait_fd_timeout(h, eid, fd, 1, timeout, 
&h->interrupt_callback);
+ret = libsrt_network_wait_fd_timeout(h, fd, 1, timeout);
 if (ret < 0) {
 if (will_try_next) {
 av_log(h, AV_LOG_WARNING,
@@ -438,7 +427,7 @@ static int libsrt_setup(URLContext *h, const char *uri, int 
flags)
 
 if (s->mode == SRT_MODE_LISTENER) {
 // multi-client
-if ((ret = libsrt_listen(s->eid, fd, cur_ai->ai_addr, 
cur_ai->ai_addrlen, h, s->listen_timeout)) < 0)
+if ((ret = libsrt_listen(fd, cur_ai->ai_addr, cur_ai->ai_addrlen, h, 
s->listen_timeout)) < 0)
 goto fail1;
 listen_fd = fd;
 fd = ret;
@@ -449,7 +438,7 @@ static int libsrt_setup(URLContext *h, const char *uri, int 
flags)
 goto fail1;
 }
 
-if ((ret = libsrt_listen_connect(s->eid, fd, cur_ai->ai_addr, 
cur_ai->ai_addrlen,
+if ((ret = libsrt_listen_connect(fd, cur_ai->ai_addr, 
cur_ai->ai_addrlen,
   open_timeout, h, !!cur_ai->ai_next)) 
< 0) {
 if (ret == AVERROR_EXIT)
 goto fail1;
@@ -652,7 +641,7 @@ static int libsrt_read(URLContext *h, uint8_t *buf, int 
size)
 int ret;
 
 if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
-ret = libsrt_network_wait_fd_timeout(h, s->eid, s->fd, 0, 
h->rw_timeout, &h->interrupt_callback);
+ret = libsrt_network_wait_fd_timeout(h, s->fd, 0, h->rw_timeout);
 if (ret)
 return ret;
 }
@@ -671,7 +660,7 @@ static int libsrt_write(URLContext *h, const uint8_t *buf, 
int size)
 int ret;
 
 if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
-ret = libsrt_network_wait_fd_timeout(h, s->eid, s->fd, 1, 
h->r

Re: [FFmpeg-devel] [PATCH 3/3] avdevice: use av_gettime_relative() for timestamps

2021-02-07 Thread Kieran Kunhya
Sent from my mobile device

On Sun, 7 Feb 2021, 17:35 Nicolas George,  wrote:

> Kieran Kunhya (12021-02-07):
> > Yes and thus you need a monotonic clock as a starting point for proper
> > filtering. Ffmpeg has neither.
>
> The kernel provides timestamps that are accurate enough. I do not
> understand why you insist on the contrary in the face of facts.
>
> Also, for a properly configured system, the wall time clock is
> monotonic.
>

This time can jump forward or backwards. It is trivial to do this. The
monotonic clock cannot do that.

Kieran

Regards,
>
> --
>   Nicolas George
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 3/3] avdevice: use av_gettime_relative() for timestamps

2021-02-07 Thread Nicolas George
Kieran Kunhya (12021-02-07):
> This time can jump forward or backwards. It is trivial to do this.

Not on a correctly configured system, it does not.

> The monotonic clock cannot do that.

The monotonic clock cannot synchronize from different computers.

Each has limitations the other has not, this is why we need both as
options. Because YOU do not know if the user's computers are correctly
synchronized, YOU do not know if the user needs to synchronise between
different computers. But the users knows. Hence the option. For the
user, because the user knows.

Regards,

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 3/3] avdevice: use av_gettime_relative() for timestamps

2021-02-07 Thread Kieran Kunhya
On Sun, 7 Feb 2021, 18:34 Nicolas George,  wrote:

> Kieran Kunhya (12021-02-07):
> > This time can jump forward or backwards. It is trivial to do this.
>
> Not on a correctly configured system, it does not.
>

NTP is allowed to jump when it wants for example. It's not trivial for the
user to guarantee this.

> The monotonic clock cannot do that.
>
> The monotonic clock cannot synchronize from different computers.
>
> Each has limitations the other has not, this is why we need both as
> options. Because YOU do not know if the user's computers are correctly
> synchronized, YOU do not know if the user needs to synchronise between
> different computers. But the users knows. Hence the option. For the
> user, because the user knows.
>

Exactly, so by default you must give the user a clock which is guaranteed
not to jump as you don't know. If they need to synchronise between PCs
using your naive process they can choose gettimeofday. Hopefully they
understand the consequences of that unlike you. It's still a flawed process
because of timestamp jitter etc.

Kieran


Regards,
>
> --
>   Nicolas George
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 3/3] avdevice: use av_gettime_relative() for timestamps

2021-02-07 Thread Nicolas George
Kieran Kunhya (12021-02-07):
> NTP is allowed to jump when it wants for example. It's not trivial for the
> user to guarantee this.

In practice, it does not.

> Exactly, so by default you must give the user a clock which is guaranteed
> not to jump as you don't know. If they need to synchronise between PCs
> using your naive process they can choose gettimeofday.

So why are you still arguing this?

> Hopefully they understand the consequences of that unlike you. It's
> still a flawed process because of timestamp jitter etc.

I obviously understand the consequences better than you, since you did
not even realize why the wall time clock was needed.

I think this should be the end of the discussion.

Regards,

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/3] avformat/libsrt: close listen fd immediately after accept

2021-02-07 Thread Marton Balint



On Sun, 31 Jan 2021, Marton Balint wrote:


There is no reason to keep it open.


Will apply the series.

Regards,
Marton



Signed-off-by: Marton Balint 
---
libavformat/libsrt.c | 14 ++
1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
index f73e7dbfa5..28c06f130e 100644
--- a/libavformat/libsrt.c
+++ b/libavformat/libsrt.c
@@ -53,7 +53,6 @@ enum SRTMode {
typedef struct SRTContext {
const AVClass *class;
int fd;
-int listen_fd;
int eid;
int64_t rw_timeout;
int64_t listen_timeout;
@@ -363,7 +362,7 @@ static int libsrt_set_options_pre(URLContext *h, int fd)
static int libsrt_setup(URLContext *h, const char *uri, int flags)
{
struct addrinfo hints = { 0 }, *ai, *cur_ai;
-int port, fd = -1, listen_fd = -1;
+int port, fd = -1;
SRTContext *s = h->priv_data;
const char *p;
char buf[256];
@@ -440,7 +439,7 @@ static int libsrt_setup(URLContext *h, const char *uri, int 
flags)
// multi-client
if ((ret = libsrt_listen(s->eid, fd, cur_ai->ai_addr, cur_ai->ai_addrlen, h, 
s->listen_timeout)) < 0)
goto fail1;
-listen_fd = fd;
+srt_close(fd);
fd = ret;
} else {
if (s->mode == SRT_MODE_RENDEZVOUS) {
@@ -473,7 +472,6 @@ static int libsrt_setup(URLContext *h, const char *uri, int 
flags)

h->is_streamed = 1;
s->fd = fd;
-s->listen_fd = listen_fd;

freeaddrinfo(ai);
return 0;
@@ -484,16 +482,12 @@ static int libsrt_setup(URLContext *h, const char *uri, 
int flags)
cur_ai = cur_ai->ai_next;
if (fd >= 0)
srt_close(fd);
-if (listen_fd >= 0)
-srt_close(listen_fd);
ret = 0;
goto restart;
}
 fail1:
if (fd >= 0)
srt_close(fd);
-if (listen_fd >= 0)
-srt_close(listen_fd);
freeaddrinfo(ai);
srt_epoll_release(s->eid);
return ret;
@@ -689,10 +683,6 @@ static int libsrt_close(URLContext *h)
SRTContext *s = h->priv_data;

srt_close(s->fd);
-
-if (s->listen_fd >= 0)
-srt_close(s->listen_fd);
-
srt_epoll_release(s->eid);

srt_cleanup();
--
2.26.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 2/2] lavf/libsrt: deduplicate libsrt_network_wait_fd_timeout

2021-02-07 Thread Marton Balint



On Mon, 8 Feb 2021, Zhao Zhili wrote:


---
libavformat/libsrt.c | 45 +---
1 file changed, 17 insertions(+), 28 deletions(-)


Hmm, it seems my latest srt patches conflics with this a bit, and you 
will have to somewhat rebase this, sorry. On the bright side, now only eid 
is passed to libsrt_network_wait_fd, so maybe you can pass eid instead of 
fd, especially since it is not always the context->eid that is used for 
wait.


Regards,
Marton



diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
index f73e7dbfa5..67e42bacc6 100644
--- a/libavformat/libsrt.c
+++ b/libavformat/libsrt.c
@@ -164,12 +164,14 @@ static int libsrt_socket_nonblock(int socket, int enable)
return srt_setsockopt(socket, 0, SRTO_RCVSYN, &blocking, sizeof(blocking));
}

-static int libsrt_network_wait_fd(URLContext *h, int eid, int fd, int write)
+static int libsrt_network_wait_fd(int fd, int write, void *ctx)
{
int ret, len = 1, errlen = 1;
int modes = SRT_EPOLL_ERR | (write ? SRT_EPOLL_OUT : SRT_EPOLL_IN);
SRTSOCKET ready[1];
SRTSOCKET error[1];
+URLContext *h = ctx;
+int eid = ((SRTContext*)h->priv_data)->eid;

if (srt_epoll_add_usock(eid, fd, &modes) < 0)
return libsrt_neterrno(h);
@@ -191,29 +193,16 @@ static int libsrt_network_wait_fd(URLContext *h, int eid, 
int fd, int write)
return ret;
}

-/* TODO de-duplicate code from ff_network_wait_fd_timeout() */
-
-static int libsrt_network_wait_fd_timeout(URLContext *h, int eid, int fd, int 
write, int64_t timeout, AVIOInterruptCB *int_cb)
+static int libsrt_network_wait_fd_timeout(URLContext *h, int fd, int write, 
int64_t timeout)
{
-int ret;
-int64_t wait_start = 0;
-
-while (1) {
-if (ff_check_interrupt(int_cb))
-return AVERROR_EXIT;
-ret = libsrt_network_wait_fd(h, eid, fd, write);
-if (ret != AVERROR(EAGAIN))
-return ret;
-if (timeout > 0) {
-if (!wait_start)
-wait_start = av_gettime_relative();
-else if (av_gettime_relative() - wait_start > timeout)
-return AVERROR(ETIMEDOUT);
-}
-}
+struct NetworkWaitFdCB wait_cb = {
+.wait_fd = libsrt_network_wait_fd,
+.opaque = h
+};
+return ff_network_wait_fd_timeout(fd, write, timeout, &h->interrupt_callback, 
&wait_cb);
}

-static int libsrt_listen(int eid, int fd, const struct sockaddr *addr, 
socklen_t addrlen, URLContext *h, int64_t timeout)
+static int libsrt_listen(int fd, const struct sockaddr *addr, socklen_t 
addrlen, URLContext *h, int64_t timeout)
{
int ret;
int reuse = 1;
@@ -228,7 +217,7 @@ static int libsrt_listen(int eid, int fd, const struct 
sockaddr *addr, socklen_t
if (ret)
return libsrt_neterrno(h);

-ret = libsrt_network_wait_fd_timeout(h, eid, fd, 1, timeout, 
&h->interrupt_callback);
+ret = libsrt_network_wait_fd_timeout(h, fd, 1, timeout);
if (ret < 0)
return ret;

@@ -241,7 +230,7 @@ static int libsrt_listen(int eid, int fd, const struct 
sockaddr *addr, socklen_t
return ret;
}

-static int libsrt_listen_connect(int eid, int fd, const struct sockaddr *addr, 
socklen_t addrlen, int64_t timeout, URLContext *h, int will_try_next)
+static int libsrt_listen_connect(int fd, const struct sockaddr *addr, 
socklen_t addrlen, int64_t timeout, URLContext *h, int will_try_next)
{
int ret;

@@ -249,7 +238,7 @@ static int libsrt_listen_connect(int eid, int fd, const 
struct sockaddr *addr, s
if (ret < 0)
return libsrt_neterrno(h);

-ret = libsrt_network_wait_fd_timeout(h, eid, fd, 1, timeout, 
&h->interrupt_callback);
+ret = libsrt_network_wait_fd_timeout(h, fd, 1, timeout);
if (ret < 0) {
if (will_try_next) {
av_log(h, AV_LOG_WARNING,
@@ -438,7 +427,7 @@ static int libsrt_setup(URLContext *h, const char *uri, int 
flags)

if (s->mode == SRT_MODE_LISTENER) {
// multi-client
-if ((ret = libsrt_listen(s->eid, fd, cur_ai->ai_addr, cur_ai->ai_addrlen, h, 
s->listen_timeout)) < 0)
+if ((ret = libsrt_listen(fd, cur_ai->ai_addr, cur_ai->ai_addrlen, h, 
s->listen_timeout)) < 0)
goto fail1;
listen_fd = fd;
fd = ret;
@@ -449,7 +438,7 @@ static int libsrt_setup(URLContext *h, const char *uri, int 
flags)
goto fail1;
}

-if ((ret = libsrt_listen_connect(s->eid, fd, cur_ai->ai_addr, 
cur_ai->ai_addrlen,
+if ((ret = libsrt_listen_connect(fd, cur_ai->ai_addr, 
cur_ai->ai_addrlen,
  open_timeout, h, !!cur_ai->ai_next)) 
< 0) {
if (ret == AVERROR_EXIT)
goto fail1;
@@ -652,7 +641,7 @@ static int libsrt_read(URLContext *h, uint8_t *buf, int 
size)
int ret;

if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
-ret = libsrt_network_wait_fd_timeout(h, s->eid, s->fd, 0, h->rw_timeout, 
&h->interrupt_callback);
+ret = libsrt_network_wait_fd

[FFmpeg-devel] [PATCH] avfilter: add exposure video filter

2021-02-07 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 doc/filters.texi  |  19 +
 libavfilter/Makefile  |   1 +
 libavfilter/allfilters.c  |   1 +
 libavfilter/vf_exposure.c | 144 ++
 4 files changed, 165 insertions(+)
 create mode 100644 libavfilter/vf_exposure.c

diff --git a/doc/filters.texi b/doc/filters.texi
index fd42df579c..d199ed1357 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -11361,6 +11361,25 @@ Six-point interpolation.
 @subsection Commands
 This filter supports same @ref{commands} as options.
 
+@section exposure
+Adjust exposure of the video stream.
+
+The filter accepts the following options:
+
+@table @option
+@item exposure
+Set the exposure correction in EV. Allowed range is from -3.0 to 3.0 EV
+Default value is 0 EV.
+
+@item black
+Set the black level correction. Allowed range is from -1.0 to 1.0.
+Default value is 0.
+@end table
+
+@subsection Commands
+
+This filter supports same @ref{commands} as options.
+
 @section extractplanes
 
 Extract color channel components from input video stream into
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index d403e2b390..5a611e7a9e 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -259,6 +259,7 @@ OBJS-$(CONFIG_EROSION_FILTER)+= 
vf_neighbor.o
 OBJS-$(CONFIG_EROSION_OPENCL_FILTER) += vf_neighbor_opencl.o opencl.o \
 opencl/neighbor.o
 OBJS-$(CONFIG_ESTDIF_FILTER) += vf_estdif.o
+OBJS-$(CONFIG_EXPOSURE_FILTER)   += vf_exposure.o
 OBJS-$(CONFIG_EXTRACTPLANES_FILTER)  += vf_extractplanes.o
 OBJS-$(CONFIG_FADE_FILTER)   += vf_fade.o
 OBJS-$(CONFIG_FFTDNOIZ_FILTER)   += vf_fftdnoiz.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 8ffb2cd82e..31546c268d 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -244,6 +244,7 @@ extern AVFilter ff_vf_eq;
 extern AVFilter ff_vf_erosion;
 extern AVFilter ff_vf_erosion_opencl;
 extern AVFilter ff_vf_estdif;
+extern AVFilter ff_vf_exposure;
 extern AVFilter ff_vf_extractplanes;
 extern AVFilter ff_vf_fade;
 extern AVFilter ff_vf_fftdnoiz;
diff --git a/libavfilter/vf_exposure.c b/libavfilter/vf_exposure.c
new file mode 100644
index 00..b7ad075630
--- /dev/null
+++ b/libavfilter/vf_exposure.c
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 2021 Paul B Mahol
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+
+#include "libavutil/opt.h"
+#include "libavutil/imgutils.h"
+#include "avfilter.h"
+#include "formats.h"
+#include "internal.h"
+#include "video.h"
+
+typedef struct ExposureContext {
+const AVClass *class;
+
+float exposure;
+float black;
+
+float scale;
+int (*do_slice)(AVFilterContext *s, void *arg,
+int jobnr, int nb_jobs);
+} ExposureContext;
+
+static int exposure_slice(AVFilterContext *ctx, void *arg, int jobnr, int 
nb_jobs)
+{
+ExposureContext *s = ctx->priv;
+AVFrame *frame = arg;
+const int width = frame->width;
+const int height = frame->height;
+const int slice_start = (height * jobnr) / nb_jobs;
+const int slice_end = (height * (jobnr + 1)) / nb_jobs;
+const float black = s->black;
+const float scale = s->scale;
+
+for (int p = 0; p < 3; p++) {
+const int linesize = frame->linesize[p] / 4;
+float *ptr = (float *)frame->data[p] + slice_start * linesize;
+for (int y = slice_start; y < slice_end; y++) {
+for (int x = 0; x < width; x++)
+ptr[x] = (ptr[x] - black) * scale;
+
+ptr += linesize;
+}
+}
+
+return 0;
+}
+
+static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
+{
+AVFilterContext *ctx = inlink->dst;
+ExposureContext *s = ctx->priv;
+
+s->scale = 1.f / (exp2f(-s->exposure) - s->black);
+ctx->internal->execute(ctx, s->do_slice, frame, NULL,
+   FFMIN(frame->height, 
ff_filter_get_nb_threads(ctx)));
+
+return ff_filter_frame(ctx->outputs[0], frame);
+}
+
+static av_cold int query_formats(AVFilterContext *ctx)
+{
+static const enum AVPixelFormat pixel_fmts[] = {
+AV_PIX_FMT_GBRPF32, AV_PIX_FMT_GBRAPF32,
+ 

Re: [FFmpeg-devel] [PATCH 3/3] avdevice: use av_gettime_relative() for timestamps

2021-02-07 Thread Kieran Kunhya
Sent from my mobile device

On Sun, 7 Feb 2021, 19:21 Nicolas George,  wrote:

> Kieran Kunhya (12021-02-07):
> > NTP is allowed to jump when it wants for example. It's not trivial for
> the
> > user to guarantee this.
>
> In practice, it does not.
>

Read the docs where it explains where it can jump.


> > Exactly, so by default you must give the user a clock which is guaranteed
> > not to jump as you don't know. If they need to synchronise between PCs
> > using your naive process they can choose gettimeofday.
>
> So why are you still arguing this?
>
> > Hopefully they understand the consequences of that unlike you. It's
> > still a flawed process because of timestamp jitter etc.
>
> I obviously understand the consequences better than you, since you did
> not even realize why the wall time clock was needed.
>

Your scenario is contrived. Its impossible to sync exactly between
different machines for all the reasons I explained and you didn't
understand.

I think this should be the end of the discussion.
>

Yes, since you are not interested in reading the NTP docs or understanding
the purpose of a monotonic clock.

Kieran


> Regards,
>
> --
>   Nicolas George
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 3/3] avdevice: use av_gettime_relative() for timestamps

2021-02-07 Thread Nicolas George
Kieran Kunhya (12021-02-07):
> Your scenario is contrived. Its impossible to sync exactly between
> different machines for all the reasons I explained and you didn't
> understand.

I understand very well. What you refuse to understand is that all this
theoretical stuff does not matter. What matters is that in practice it
works, full stop.

Regards,

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 3/3] avdevice: use av_gettime_relative() for timestamps

2021-02-07 Thread Kieran Kunhya
On Sun, 7 Feb 2021, 20:20 Nicolas George,  wrote:

> Kieran Kunhya (12021-02-07):
> > Your scenario is contrived. Its impossible to sync exactly between
> > different machines for all the reasons I explained and you didn't
> > understand.
>
> I understand very well. What you refuse to understand is that all this
> theoretical stuff does not matter. What matters is that in practice it
> works, full stop.
>


It doesn't work in practice.
It's why every Android phone captures video at 29.970fps ± jitter instead
of the correct 3/1001

Kieran


> Regards,
>
> --
>   Nicolas George
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 3/3] avdevice: use av_gettime_relative() for timestamps

2021-02-07 Thread Nicolas George
Kieran Kunhya (12021-02-07):
> It doesn't work in practice.
> It's why every Android phone captures video at 29.970fps ± jitter instead
> of the correct 3/1001

Good enough for most uses. Let the user decide.

Regards,

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 3/3] avdevice: use av_gettime_relative() for timestamps

2021-02-07 Thread Kieran Kunhya
Sent from my mobile device

On Sun, 7 Feb 2021, 20:27 Nicolas George,  wrote:

> Kieran Kunhya (12021-02-07):
> > It doesn't work in practice.
> > It's why every Android phone captures video at 29.970fps ± jitter instead
> > of the correct 3/1001
>
> Good enough for most uses. Let the user decide.
>

QED that you don't understand the problem whatsoever.

Kieran


> Regards,
>
> --
>   Nicolas George
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 3/3] avdevice: use av_gettime_relative() for timestamps

2021-02-07 Thread Nicolas George
Kieran Kunhya (12021-02-07):
> QED that you don't understand the problem whatsoever.

This is the third time you've been rude today.

I am sorry, but it's you who do not understand what people actually
need. Most use cases do not need better precision than a few hundredth
of seconds, if that.

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] x11grab: capture a window instead of the whole screen

2021-02-07 Thread Andriy Gelman
Hi,

On Tue, 26. Jan 11:23, sgerwk-at-aol@ffmpeg.org wrote:
> In my previous email the patch got mangled by the web mail interface, so I am
> sending it again. Sorry for the duplicate.

I couldn't apply this version, but previous one applied ok:
https://patchwork.ffmpeg.org/project/ffmpeg/patch/942317827.2397172.1611160298...@mail.yahoo.com/

The author name appears as sgerwk-at-aol@ffmpeg.org. You can update
if you want something else.

Also the commit title should start with avdevice/xcbgrab: or lavd/xcbgrab:

> 
> This patch allows ffmpeg to capture a specific window instead of the whole
> screen. An example:

> 
> ffmpeg -f x11grab -window_id 0xa0a -i :0 output.mp4

If you try with -show_region 1, the border gets drawn in the wrong place.

> 
> ---
>  doc/indevs.texi   |  3 +++
>  libavdevice/xcbgrab.c | 19 ---
>  2 files changed, 15 insertions(+), 7 deletions(-)
> 
> diff --git a/doc/indevs.texi b/doc/indevs.texi
> index 3924d03..0738919 100644
> --- a/doc/indevs.texi
> +++ b/doc/indevs.texi
> @@ -1564,6 +1564,9 @@ With @var{follow_mouse}:
>  ffmpeg -f x11grab -follow_mouse centered -show_region 1 -framerate 25 
> -video_size cif -i :0.0 out.mpg
>  @end example

> 
> +@item window_id
> +Grab this window, instead of the whole screen.
> +

I think it would be useful to say how to get a window id.
Probably worth adding what happens if the window size changes or it disappears.

>  @item video_size
>  Set the video frame size. Default is the full desktop.
> 
> diff --git a/libavdevice/xcbgrab.c b/libavdevice/xcbgrab.c
> index 95bdc8a..6e4ef5d 100644
> --- a/libavdevice/xcbgrab.c
> +++ b/libavdevice/xcbgrab.c
> @@ -60,6 +60,7 @@ typedef struct XCBGrabContext {
>  AVRational time_base;
>  int64_t frame_duration;
> 
> +xcb_window_t window_id;
>  int x, y;
>  int width, height;
>  int frame_size;
> @@ -82,6 +83,7 @@ typedef struct XCBGrabContext {
>  #define OFFSET(x) offsetof(XCBGrabContext, x)
>  #define D AV_OPT_FLAG_DECODING_PARAM
>  static const AVOption options[] = {

> +{ "window_id", "Window to capture", OFFSET(window_id), AV_OPT_TYPE_INT, 
> { .i64 = 0 }, 0, INT_MAX, D },

xcb_window_t is uint32_t, so max should be UINT32_MAX? 

>  { "x", "Initial x coordinate.", OFFSET(x), AV_OPT_TYPE_INT, { .i64 = 0 
> }, 0, INT_MAX, D },
>  { "y", "Initial y coordinate.", OFFSET(y), AV_OPT_TYPE_INT, { .i64 = 0 
> }, 0, INT_MAX, D },
>  { "grab_x", "Initial x coordinate.", OFFSET(x), AV_OPT_TYPE_INT, { .i64 
> = 0 }, 0, INT_MAX, D },
> @@ -157,7 +159,7 @@ static int xcbgrab_frame(AVFormatContext *s, AVPacket 
> *pkt)
>  XCBGrabContext *c = s->priv_data;
>  xcb_get_image_cookie_t iq;
>  xcb_get_image_reply_t *img;
> -xcb_drawable_t drawable = c->screen->root;
> +xcb_drawable_t drawable = c->window_id;
>  xcb_generic_error_t *e = NULL;
>  uint8_t *data;
>  int length;
> @@ -267,7 +269,7 @@ static int xcbgrab_frame_shm(AVFormatContext *s, AVPacket 
> *pkt)
>  XCBGrabContext *c = s->priv_data;
>  xcb_shm_get_image_cookie_t iq;
>  xcb_shm_get_image_reply_t *img;
> -xcb_drawable_t drawable = c->screen->root;
> +xcb_drawable_t drawable = c->window_id;
>  xcb_generic_error_t *e = NULL;
>  AVBufferRef *buf;
>  xcb_shm_seg_t segment;
> @@ -566,7 +568,7 @@ static int create_stream(AVFormatContext *s)
> 
>  avpriv_set_pts_info(st, 64, 1, 100);
> 
> -gc  = xcb_get_geometry(c->conn, c->screen->root);
> +gc  = xcb_get_geometry(c->conn, c->window_id);
>  geo = xcb_get_geometry_reply(c->conn, gc, NULL);
>  if (!geo)
>  return AVERROR_EXTERNAL;
> @@ -745,7 +747,7 @@ static int select_region(AVFormatContext *s)
>  press_position = (xcb_point_t){ press->event_x, press->event_y };
>  rectangle.x = press_position.x;
>  rectangle.y = press_position.y;
> -xcb_poly_rectangle(conn, root_window, gc, 1, &rectangle);
> +xcb_poly_rectangle(conn, c->window_id, gc, 1, &rectangle);
>  was_pressed = 1;
>  break;
>  }
> @@ -754,14 +756,14 @@ static int select_region(AVFormatContext *s)
>  xcb_motion_notify_event_t *motion =
>  (xcb_motion_notify_event_t *)event;
>  xcb_point_t cursor_position = { motion->event_x, 
> motion->event_y };
> -xcb_poly_rectangle(conn, root_window, gc, 1, &rectangle);
> +xcb_poly_rectangle(conn, c->window_id, gc, 1, &rectangle);
>  rectangle = rectangle_from_corners(&press_position, 
> &cursor_position);
> -xcb_poly_rectangle(conn, root_window, gc, 1, &rectangle);
> +xcb_poly_rectangle(conn, c->window_id, gc, 1, &rectangle);
>  }
>  break;
>  }
>  case XCB_BUTTON_RELEASE: {
> -xcb_poly_rectangle(conn, root_window, gc, 1, &rectangle);
> +xcb_poly_rectangle(conn, c->window_id, g

Re: [FFmpeg-devel] [PATCH 2/2] RFC ffmpeg: exit demuxers earlier after signal received

2021-02-07 Thread Andriy Gelman
On Sat, 28. Nov 14:46, Andriy Gelman wrote:
> From: Andriy Gelman 
> 
> We currently use the same interrupt_callback function for both muxers
> and demuxers to break out of potential infinite loops.
> 
> The function decode_interrupt_cb() checks for how many SIGINT/SIGTERM
> interrupts have been received, and (usually) two interrupts are needed to
> break out of an infinite loop.
> 
> If this condition is seen on the muxer, however, we will fail to flush the
> avio buffers (see retry_transfer_wrapper()).
> An example of this issue is seen in Ticket #9009 (which would be fixed
> by this patch).
> 
> A more robust alternative maybe to break out of demuxers with one
> interrupt. The error should propagate through, close the muxers and
> allow them to flush properly.
> (If the infinite loop is present on the muxer then a second interrupt would
> cause it break out and have the same behavior as before.)
> 
> This patch adds this behavior. I've labelled it RFC because it
> potentially touches many demuxers.
> ---
>  fftools/ffmpeg.c | 6 ++
>  fftools/ffmpeg.h | 1 +
>  fftools/ffmpeg_opt.c | 2 +-
>  3 files changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
> index 01f4ef15d8..bb27eec879 100644
> --- a/fftools/ffmpeg.c
> +++ b/fftools/ffmpeg.c
> @@ -510,7 +510,13 @@ static int decode_interrupt_cb(void *ctx)
>  return received_nb_signals > atomic_load(&transcode_init_done);
>  }
>  
> +static int decode_interrupt_one_sig_cb(void *ctx)
> +{
> +return received_nb_signals > 0;
> +}
> +
>  const AVIOInterruptCB int_cb = { decode_interrupt_cb, NULL };
> +const AVIOInterruptCB int_one_sig_cb = { decode_interrupt_one_sig_cb, NULL };
>  
>  static void ffmpeg_cleanup(int ret)
>  {
> diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
> index 3b54dab7fc..c49af30009 100644
> --- a/fftools/ffmpeg.h
> +++ b/fftools/ffmpeg.h
> @@ -627,6 +627,7 @@ extern int vstats_version;
>  extern int auto_conversion_filters;
>  
>  extern const AVIOInterruptCB int_cb;
> +extern const AVIOInterruptCB int_one_sig_cb;
>  
>  extern const OptionDef options[];
>  extern const HWAccel hwaccels[];
> diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
> index 7ee034c9c9..2908f23010 100644
> --- a/fftools/ffmpeg_opt.c
> +++ b/fftools/ffmpeg_opt.c
> @@ -1156,7 +1156,7 @@ static int open_input_file(OptionsContext *o, const 
> char *filename)
>  ic->flags |= AVFMT_FLAG_NONBLOCK;
>  if (o->bitexact)
>  ic->flags |= AVFMT_FLAG_BITEXACT;
> -ic->interrupt_callback = int_cb;
> +ic->interrupt_callback = int_one_sig_cb;
>  
>  if (!av_dict_get(o->g->format_opts, "scan_all_pmts", NULL, 
> AV_DICT_MATCH_CASE)) {
>  av_dict_set(&o->g->format_opts, "scan_all_pmts", "1", 
> AV_DICT_DONT_OVERWRITE);
> -- 
> 2.28.0
> 

ping

-- 
Andriy
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 2/2] avformat/asfdec_f: Add an additional check for the extradata size

2021-02-07 Thread Michael Niedermayer
Fixes: OOM
Fixes: 
30066/clusterfuzz-testcase-minimized-ffmpeg_dem_ASF_fuzzer-6182309126602752

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavformat/asfdec_f.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavformat/asfdec_f.c b/libavformat/asfdec_f.c
index 8e48e457d9..b584f60195 100644
--- a/libavformat/asfdec_f.c
+++ b/libavformat/asfdec_f.c
@@ -516,6 +516,8 @@ static int asf_read_stream_properties(AVFormatContext *s, 
int64_t size)
 tag1 = avio_rl32(pb);
 avio_skip(pb, 20);
 if (sizeX > 40) {
+if (size < sizeX - 40)
+return AVERROR_INVALIDDATA;
 st->codecpar->extradata_size = ffio_limit(pb, sizeX - 40);
 st->codecpar->extradata  = 
av_mallocz(st->codecpar->extradata_size +

AV_INPUT_BUFFER_PADDING_SIZE);
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 1/2] avformat/mov: sanity check STSD entries

2021-02-07 Thread Michael Niedermayer
The choosen value is arbitrary. I am not sure if this is a good idea
but i dont immedeately see an alternative better way, it seems either
an arbitrary limit or OOM

Fixes: OOM
Fixes: 
27492/clusterfuzz-testcase-minimized-ffmpeg_dem_MOV_fuzzer-6194970578649088

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavformat/mov.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index d9a6a54083..0c44032071 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -2605,7 +2605,7 @@ static int mov_read_stsd(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 entries = avio_rb32(pb);
 
 /* Each entry contains a size (4 bytes) and format (4 bytes). */
-if (entries <= 0 || entries > atom.size / 8) {
+if (entries <= 0 || entries > atom.size / 8 || entries > 1024) {
 av_log(c->fc, AV_LOG_ERROR, "invalid STSD entries %d\n", entries);
 return AVERROR_INVALIDDATA;
 }
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 1/4] fftools/ffplay: get rid of flush_pkt

2021-02-07 Thread Marton Balint
The packet serial can be used instead to detect when a flush is needed.

Signed-off-by: Marton Balint 
---
 fftools/ffplay.c | 29 +++--
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index 9ff0425163..70d8548a64 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -361,8 +361,6 @@ static int filter_nbthreads = 0;
 static int is_full_screen;
 static int64_t audio_callback_time;
 
-static AVPacket flush_pkt;
-
 #define FF_QUIT_EVENT(SDL_USEREVENT + 2)
 
 static SDL_Window *window;
@@ -437,8 +435,6 @@ static int packet_queue_put_private(PacketQueue *q, 
AVPacket *pkt)
 return -1;
 pkt1->pkt = *pkt;
 pkt1->next = NULL;
-if (pkt == &flush_pkt)
-q->serial++;
 pkt1->serial = q->serial;
 
 if (!q->last_pkt)
@@ -462,7 +458,7 @@ static int packet_queue_put(PacketQueue *q, AVPacket *pkt)
 ret = packet_queue_put_private(q, pkt);
 SDL_UnlockMutex(q->mutex);
 
-if (pkt != &flush_pkt && ret < 0)
+if (ret < 0)
 av_packet_unref(pkt);
 
 return ret;
@@ -511,6 +507,7 @@ static void packet_queue_flush(PacketQueue *q)
 q->nb_packets = 0;
 q->size = 0;
 q->duration = 0;
+q->serial++;
 SDL_UnlockMutex(q->mutex);
 }
 
@@ -536,7 +533,7 @@ static void packet_queue_start(PacketQueue *q)
 {
 SDL_LockMutex(q->mutex);
 q->abort_request = 0;
-packet_queue_put_private(q, &flush_pkt);
+q->serial++;
 SDL_UnlockMutex(q->mutex);
 }
 
@@ -642,20 +639,22 @@ static int decoder_decode_frame(Decoder *d, AVFrame 
*frame, AVSubtitle *sub) {
 av_packet_move_ref(&pkt, &d->pkt);
 d->packet_pending = 0;
 } else {
+int old_serial = d->pkt_serial;
 if (packet_queue_get(d->queue, &pkt, 1, &d->pkt_serial) < 0)
 return -1;
+if (old_serial != d->pkt_serial) {
+avcodec_flush_buffers(d->avctx);
+d->finished = 0;
+d->next_pts = d->start_pts;
+d->next_pts_tb = d->start_pts_tb;
+}
 }
 if (d->queue->serial == d->pkt_serial)
 break;
 av_packet_unref(&pkt);
 } while (1);
 
-if (pkt.data == flush_pkt.data) {
-avcodec_flush_buffers(d->avctx);
-d->finished = 0;
-d->next_pts = d->start_pts;
-d->next_pts_tb = d->start_pts_tb;
-} else {
+{
 if (d->avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) {
 int got_frame = 0;
 ret = avcodec_decode_subtitle2(d->avctx, sub, &got_frame, 
&pkt);
@@ -2962,15 +2961,12 @@ static int read_thread(void *arg)
 } else {
 if (is->audio_stream >= 0) {
 packet_queue_flush(&is->audioq);
-packet_queue_put(&is->audioq, &flush_pkt);
 }
 if (is->subtitle_stream >= 0) {
 packet_queue_flush(&is->subtitleq);
-packet_queue_put(&is->subtitleq, &flush_pkt);
 }
 if (is->video_stream >= 0) {
 packet_queue_flush(&is->videoq);
-packet_queue_put(&is->videoq, &flush_pkt);
 }
 if (is->seek_flags & AVSEEK_FLAG_BYTE) {
set_clock(&is->extclk, NAN, 0);
@@ -3738,9 +3734,6 @@ int main(int argc, char **argv)
 SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
 SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
 
-av_init_packet(&flush_pkt);
-flush_pkt.data = (uint8_t *)&flush_pkt;
-
 if (!display_disable) {
 int flags = SDL_WINDOW_HIDDEN;
 if (alwaysontop)
-- 
2.26.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 2/4] fftools/ffplay: use context AVPacket in decoder_decode_frame()

2021-02-07 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 fftools/ffplay.c | 21 +
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index 70d8548a64..0054fec076 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -589,8 +589,6 @@ static int decoder_decode_frame(Decoder *d, AVFrame *frame, 
AVSubtitle *sub) {
 int ret = AVERROR(EAGAIN);
 
 for (;;) {
-AVPacket pkt;
-
 if (d->queue->serial == d->pkt_serial) {
 do {
 if (d->queue->abort_request)
@@ -636,11 +634,10 @@ static int decoder_decode_frame(Decoder *d, AVFrame 
*frame, AVSubtitle *sub) {
 if (d->queue->nb_packets == 0)
 SDL_CondSignal(d->empty_queue_cond);
 if (d->packet_pending) {
-av_packet_move_ref(&pkt, &d->pkt);
 d->packet_pending = 0;
 } else {
 int old_serial = d->pkt_serial;
-if (packet_queue_get(d->queue, &pkt, 1, &d->pkt_serial) < 0)
+if (packet_queue_get(d->queue, &d->pkt, 1, &d->pkt_serial) < 0)
 return -1;
 if (old_serial != d->pkt_serial) {
 avcodec_flush_buffers(d->avctx);
@@ -651,30 +648,30 @@ static int decoder_decode_frame(Decoder *d, AVFrame 
*frame, AVSubtitle *sub) {
 }
 if (d->queue->serial == d->pkt_serial)
 break;
-av_packet_unref(&pkt);
+av_packet_unref(&d->pkt);
 } while (1);
 
 {
 if (d->avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) {
 int got_frame = 0;
-ret = avcodec_decode_subtitle2(d->avctx, sub, &got_frame, 
&pkt);
+ret = avcodec_decode_subtitle2(d->avctx, sub, &got_frame, 
&d->pkt);
 if (ret < 0) {
 ret = AVERROR(EAGAIN);
 } else {
-if (got_frame && !pkt.data) {
+if (got_frame && !d->pkt.data) {
d->packet_pending = 1;
-   av_packet_move_ref(&d->pkt, &pkt);
 }
-ret = got_frame ? 0 : (pkt.data ? AVERROR(EAGAIN) : 
AVERROR_EOF);
+ret = got_frame ? 0 : (d->pkt.data ? AVERROR(EAGAIN) : 
AVERROR_EOF);
 }
+av_packet_unref(&d->pkt);
 } else {
-if (avcodec_send_packet(d->avctx, &pkt) == AVERROR(EAGAIN)) {
+if (avcodec_send_packet(d->avctx, &d->pkt) == AVERROR(EAGAIN)) 
{
 av_log(d->avctx, AV_LOG_ERROR, "Receive_frame and 
send_packet both returned EAGAIN, which is an API violation.\n");
 d->packet_pending = 1;
-av_packet_move_ref(&d->pkt, &pkt);
+} else {
+av_packet_unref(&d->pkt);
 }
 }
-av_packet_unref(&pkt);
 }
 }
 }
-- 
2.26.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 3/4] fftools/ffplay: use av_packet_alloc() to allocate packets

2021-02-07 Thread Marton Balint
Heavily based on a patch by James Almer.

Signed-off-by: Marton Balint 
---
 fftools/ffplay.c | 140 +--
 1 file changed, 76 insertions(+), 64 deletions(-)

diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index 0054fec076..eab156c47a 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -36,6 +36,7 @@
 #include "libavutil/pixdesc.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/dict.h"
+#include "libavutil/fifo.h"
 #include "libavutil/parseutils.h"
 #include "libavutil/samplefmt.h"
 #include "libavutil/avassert.h"
@@ -111,13 +112,12 @@ const int program_birth_year = 2003;
 static unsigned sws_flags = SWS_BICUBIC;
 
 typedef struct MyAVPacketList {
-AVPacket pkt;
-struct MyAVPacketList *next;
+AVPacket *pkt;
 int serial;
 } MyAVPacketList;
 
 typedef struct PacketQueue {
-MyAVPacketList *first_pkt, *last_pkt;
+AVFifoBuffer *pkt_list;
 int nb_packets;
 int size;
 int64_t duration;
@@ -187,7 +187,7 @@ enum {
 };
 
 typedef struct Decoder {
-AVPacket pkt;
+AVPacket *pkt;
 PacketQueue *queue;
 AVCodecContext *avctx;
 int pkt_serial;
@@ -425,26 +425,23 @@ int64_t get_valid_channel_layout(int64_t channel_layout, 
int channels)
 
 static int packet_queue_put_private(PacketQueue *q, AVPacket *pkt)
 {
-MyAVPacketList *pkt1;
+MyAVPacketList pkt1;
 
 if (q->abort_request)
return -1;
 
-pkt1 = av_malloc(sizeof(MyAVPacketList));
-if (!pkt1)
-return -1;
-pkt1->pkt = *pkt;
-pkt1->next = NULL;
-pkt1->serial = q->serial;
+if (av_fifo_space(q->pkt_list) < sizeof(pkt1)) {
+if (av_fifo_grow(q->pkt_list, sizeof(pkt1)) < 0)
+return -1;
+}
 
-if (!q->last_pkt)
-q->first_pkt = pkt1;
-else
-q->last_pkt->next = pkt1;
-q->last_pkt = pkt1;
+pkt1.pkt = pkt;
+pkt1.serial = q->serial;
+
+av_fifo_generic_write(q->pkt_list, &pkt1, sizeof(pkt1), NULL);
 q->nb_packets++;
-q->size += pkt1->pkt.size + sizeof(*pkt1);
-q->duration += pkt1->pkt.duration;
+q->size += pkt1.pkt->size + sizeof(pkt1);
+q->duration += pkt1.pkt->duration;
 /* XXX: should duplicate packet data in DV case */
 SDL_CondSignal(q->cond);
 return 0;
@@ -452,24 +449,28 @@ static int packet_queue_put_private(PacketQueue *q, 
AVPacket *pkt)
 
 static int packet_queue_put(PacketQueue *q, AVPacket *pkt)
 {
+AVPacket *pkt1;
 int ret;
 
+pkt1 = av_packet_alloc();
+if (!pkt1) {
+av_packet_unref(pkt);
+return -1;
+}
+av_packet_move_ref(pkt1, pkt);
+
 SDL_LockMutex(q->mutex);
-ret = packet_queue_put_private(q, pkt);
+ret = packet_queue_put_private(q, pkt1);
 SDL_UnlockMutex(q->mutex);
 
 if (ret < 0)
-av_packet_unref(pkt);
+av_packet_free(&pkt1);
 
 return ret;
 }
 
-static int packet_queue_put_nullpacket(PacketQueue *q, int stream_index)
+static int packet_queue_put_nullpacket(PacketQueue *q, AVPacket *pkt, int 
stream_index)
 {
-AVPacket pkt1, *pkt = &pkt1;
-av_init_packet(pkt);
-pkt->data = NULL;
-pkt->size = 0;
 pkt->stream_index = stream_index;
 return packet_queue_put(q, pkt);
 }
@@ -478,6 +479,9 @@ static int packet_queue_put_nullpacket(PacketQueue *q, int 
stream_index)
 static int packet_queue_init(PacketQueue *q)
 {
 memset(q, 0, sizeof(PacketQueue));
+q->pkt_list = av_fifo_alloc(sizeof(MyAVPacketList));
+if (!q->pkt_list)
+return AVERROR(ENOMEM);
 q->mutex = SDL_CreateMutex();
 if (!q->mutex) {
 av_log(NULL, AV_LOG_FATAL, "SDL_CreateMutex(): %s\n", SDL_GetError());
@@ -494,16 +498,13 @@ static int packet_queue_init(PacketQueue *q)
 
 static void packet_queue_flush(PacketQueue *q)
 {
-MyAVPacketList *pkt, *pkt1;
+MyAVPacketList pkt1;
 
 SDL_LockMutex(q->mutex);
-for (pkt = q->first_pkt; pkt; pkt = pkt1) {
-pkt1 = pkt->next;
-av_packet_unref(&pkt->pkt);
-av_freep(&pkt);
+while (av_fifo_size(q->pkt_list) >= sizeof(pkt1)) {
+av_fifo_generic_read(q->pkt_list, &pkt1, sizeof(pkt1), NULL);
+av_packet_free(&pkt1.pkt);
 }
-q->last_pkt = NULL;
-q->first_pkt = NULL;
 q->nb_packets = 0;
 q->size = 0;
 q->duration = 0;
@@ -514,6 +515,7 @@ static void packet_queue_flush(PacketQueue *q)
 static void packet_queue_destroy(PacketQueue *q)
 {
 packet_queue_flush(q);
+av_fifo_freep(&q->pkt_list);
 SDL_DestroyMutex(q->mutex);
 SDL_DestroyCond(q->cond);
 }
@@ -540,7 +542,7 @@ static void packet_queue_start(PacketQueue *q)
 /* return < 0 if aborted, 0 if no packet and > 0 if packet.  */
 static int packet_queue_get(PacketQueue *q, AVPacket *pkt, int block, int 
*serial)
 {
-MyAVPacketList *pkt1;
+MyAVPacketList pkt1;
 int ret;
 
 SDL_LockMutex(q->mutex);
@@ -551,18 +553,15 @@ static int packet_queue_get(PacketQueue *q, AVPacket 
*pkt, int block, int *seria
 break;
 }
 
- 

[FFmpeg-devel] [PATCH 4/4] fftools/ffplay: reindent and some minor cosmetics

2021-02-07 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 fftools/ffplay.c | 95 +++-
 1 file changed, 45 insertions(+), 50 deletions(-)

diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index eab156c47a..b9a30cdb11 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -654,26 +654,24 @@ static int decoder_decode_frame(Decoder *d, AVFrame 
*frame, AVSubtitle *sub) {
 av_packet_unref(d->pkt);
 } while (1);
 
-{
-if (d->avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) {
-int got_frame = 0;
-ret = avcodec_decode_subtitle2(d->avctx, sub, &got_frame, 
d->pkt);
-if (ret < 0) {
-ret = AVERROR(EAGAIN);
-} else {
-if (got_frame && !d->pkt->data) {
-   d->packet_pending = 1;
-}
-ret = got_frame ? 0 : (d->pkt->data ? AVERROR(EAGAIN) : 
AVERROR_EOF);
-}
-av_packet_unref(d->pkt);
+if (d->avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) {
+int got_frame = 0;
+ret = avcodec_decode_subtitle2(d->avctx, sub, &got_frame, d->pkt);
+if (ret < 0) {
+ret = AVERROR(EAGAIN);
 } else {
-if (avcodec_send_packet(d->avctx, d->pkt) == AVERROR(EAGAIN)) {
-av_log(d->avctx, AV_LOG_ERROR, "Receive_frame and 
send_packet both returned EAGAIN, which is an API violation.\n");
+if (got_frame && !d->pkt->data) {
 d->packet_pending = 1;
-} else {
-av_packet_unref(d->pkt);
 }
+ret = got_frame ? 0 : (d->pkt->data ? AVERROR(EAGAIN) : 
AVERROR_EOF);
+}
+av_packet_unref(d->pkt);
+} else {
+if (avcodec_send_packet(d->avctx, d->pkt) == AVERROR(EAGAIN)) {
+av_log(d->avctx, AV_LOG_ERROR, "Receive_frame and send_packet 
both returned EAGAIN, which is an API violation.\n");
+d->packet_pending = 1;
+} else {
+av_packet_unref(d->pkt);
 }
 }
 }
@@ -1646,37 +1644,37 @@ retry:
 }
 
 if (is->subtitle_st) {
-while (frame_queue_nb_remaining(&is->subpq) > 0) {
-sp = frame_queue_peek(&is->subpq);
-
-if (frame_queue_nb_remaining(&is->subpq) > 1)
-sp2 = frame_queue_peek_next(&is->subpq);
-else
-sp2 = NULL;
-
-if (sp->serial != is->subtitleq.serial
-|| (is->vidclk.pts > (sp->pts + ((float) 
sp->sub.end_display_time / 1000)))
-|| (sp2 && is->vidclk.pts > (sp2->pts + 
((float) sp2->sub.start_display_time / 1000
-{
-if (sp->uploaded) {
-int i;
-for (i = 0; i < sp->sub.num_rects; i++) {
-AVSubtitleRect *sub_rect = 
sp->sub.rects[i];
-uint8_t *pixels;
-int pitch, j;
-
-if (!SDL_LockTexture(is->sub_texture, 
(SDL_Rect *)sub_rect, (void **)&pixels, &pitch)) {
-for (j = 0; j < sub_rect->h; j++, 
pixels += pitch)
-memset(pixels, 0, sub_rect->w << 
2);
-SDL_UnlockTexture(is->sub_texture);
-}
+while (frame_queue_nb_remaining(&is->subpq) > 0) {
+sp = frame_queue_peek(&is->subpq);
+
+if (frame_queue_nb_remaining(&is->subpq) > 1)
+sp2 = frame_queue_peek_next(&is->subpq);
+else
+sp2 = NULL;
+
+if (sp->serial != is->subtitleq.serial
+|| (is->vidclk.pts > (sp->pts + ((float) 
sp->sub.end_display_time / 1000)))
+|| (sp2 && is->vidclk.pts > (sp2->pts + ((float) 
sp2->sub.start_display_time / 1000
+{
+if (sp->uploaded) {
+int i;
+for (i = 0; i < sp->sub.num_rects; i++) {
+AVSubtitleRect *sub_rect = sp->sub.rects[i];
+uint8_t *pixels;
+int pitch, j;
+
+if (!SDL_LockTexture(is->sub_texture, 
(SDL_Rect *)sub_rect, (void **)&pixels, &pitch)) {
+for (j = 0; j < sub_rect->h; j++, pixels 
+= pitch)
+memset(pixels, 0, sub_rect->w << 2);
+ 

Re: [FFmpeg-devel] [PATCH 2/2] avformat/asfdec_f: Add an additional check for the extradata size

2021-02-07 Thread Paul B Mahol
lgtm
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v2 1/2] lavf/network: add wait fd callback to ff_network_wait_fd_timeout

2021-02-07 Thread Zhao Zhili
---
 libavformat/libamqp.c |  4 ++--
 libavformat/network.c | 16 ++--
 libavformat/network.h | 14 +-
 libavformat/tcp.c |  6 --
 4 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/libavformat/libamqp.c b/libavformat/libamqp.c
index c3b9c484ea..ca7d3ab70f 100644
--- a/libavformat/libamqp.c
+++ b/libavformat/libamqp.c
@@ -241,7 +241,7 @@ static int amqp_proto_write(URLContext *h, const unsigned 
char *buf, int size)
 amqp_bytes_t message = { size, (void *)buf };
 amqp_basic_properties_t props;
 
-ret = ff_network_wait_fd_timeout(fd, 1, h->rw_timeout, 
&h->interrupt_callback);
+ret = ff_network_wait_fd_timeout(fd, 1, h->rw_timeout, 
&h->interrupt_callback, NULL);
 if (ret)
 return ret;
 
@@ -270,7 +270,7 @@ static int amqp_proto_read(URLContext *h, unsigned char 
*buf, int size)
 amqp_rpc_reply_t broker_reply;
 amqp_envelope_t envelope;
 
-ret = ff_network_wait_fd_timeout(fd, 0, h->rw_timeout, 
&h->interrupt_callback);
+ret = ff_network_wait_fd_timeout(fd, 0, h->rw_timeout, 
&h->interrupt_callback, NULL);
 if (ret)
 return ret;
 
diff --git a/libavformat/network.c b/libavformat/network.c
index 0f5a575f77..48a9af012e 100644
--- a/libavformat/network.c
+++ b/libavformat/network.c
@@ -75,15 +75,27 @@ int ff_network_wait_fd(int fd, int write)
 return ret < 0 ? ff_neterrno() : p.revents & (ev | POLLERR | POLLHUP) ? 0 
: AVERROR(EAGAIN);
 }
 
-int ff_network_wait_fd_timeout(int fd, int write, int64_t timeout, 
AVIOInterruptCB *int_cb)
+static int network_wait_fd_callback(int fd, int write, void *opaque) {
+return ff_network_wait_fd(fd, write);
+}
+
+int ff_network_wait_fd_timeout(int fd, int write, int64_t timeout,
+AVIOInterruptCB *int_cb, const NetworkWaitFdCB *wait_cb)
 {
 int ret;
 int64_t wait_start = 0;
 
+const static NetworkWaitFdCB wait_cb_internal = {
+.wait_fd = network_wait_fd_callback,
+};
+
+if (!wait_cb)
+wait_cb = &wait_cb_internal;
+
 while (1) {
 if (ff_check_interrupt(int_cb))
 return AVERROR_EXIT;
-ret = ff_network_wait_fd(fd, write);
+ret = ff_network_wait_fd_cb(wait_cb, fd, write);
 if (ret != AVERROR(EAGAIN))
 return ret;
 if (timeout > 0) {
diff --git a/libavformat/network.h b/libavformat/network.h
index 71347e815b..1a02a6d9ee 100644
--- a/libavformat/network.h
+++ b/libavformat/network.h
@@ -84,6 +84,16 @@ void ff_network_close(void);
 int ff_tls_init(void);
 void ff_tls_deinit(void);
 
+typedef struct NetworkWaitFdCB {
+int (*wait_fd)(int /*fd*/, int /*write*/, void* /*opaque*/);
+void *opaque;
+} NetworkWaitFdCB;
+
+static av_always_inline int ff_network_wait_fd_cb(const NetworkWaitFdCB *cb,
+int fd, int write) {
+return cb->wait_fd(fd, write, cb->opaque);
+}
+
 int ff_network_wait_fd(int fd, int write);
 
 /**
@@ -94,9 +104,11 @@ int ff_network_wait_fd(int fd, int write);
  * @param write Set 1 to wait for socket able to be read, 0 to be written
  * @param timeout Timeout interval, in microseconds. Actual precision is 
10 mcs, due to ff_network_wait_fd usage
  * @param int_cb Interrupt callback, is checked before each ff_network_wait_fd 
call
+ * @param wait_cb Wait callback, default implementation is used if NULL
  * @return 0 if data can be read/written, AVERROR(ETIMEDOUT) if timeout 
expired, or negative error code
  */
-int ff_network_wait_fd_timeout(int fd, int write, int64_t timeout, 
AVIOInterruptCB *int_cb);
+int ff_network_wait_fd_timeout(int fd, int write, int64_t timeout,
+AVIOInterruptCB *int_cb, const NetworkWaitFdCB *wait_cb);
 
 /**
  * Waits for up to 'timeout' microseconds. If the usert's int_cb is set and
diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index 2198e0f00e..437eaecbb4 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
@@ -237,7 +237,8 @@ static int tcp_read(URLContext *h, uint8_t *buf, int size)
 int ret;
 
 if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
-ret = ff_network_wait_fd_timeout(s->fd, 0, h->rw_timeout, 
&h->interrupt_callback);
+ret = ff_network_wait_fd_timeout(s->fd, 0, h->rw_timeout,
+&h->interrupt_callback, NULL);
 if (ret)
 return ret;
 }
@@ -253,7 +254,8 @@ static int tcp_write(URLContext *h, const uint8_t *buf, int 
size)
 int ret;
 
 if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
-ret = ff_network_wait_fd_timeout(s->fd, 1, h->rw_timeout, 
&h->interrupt_callback);
+ret = ff_network_wait_fd_timeout(s->fd, 1, h->rw_timeout,
+&h->interrupt_callback, NULL);
 if (ret)
 return ret;
 }
-- 
2.28.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v2 2/2] lavf/libsrt: deduplicate libsrt_network_wait_fd_timeout

2021-02-07 Thread Zhao Zhili
---
v2: code rebase 
 libavformat/libsrt.c | 27 +++
 1 file changed, 7 insertions(+), 20 deletions(-)

diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
index 233e9096fa..95a20b2308 100644
--- a/libavformat/libsrt.c
+++ b/libavformat/libsrt.c
@@ -176,7 +176,7 @@ static int libsrt_epoll_create(URLContext *h, int fd, int 
write)
 return eid;
 }
 
-static int libsrt_network_wait_fd(URLContext *h, int eid, int write)
+static int libsrt_network_wait_fd(int eid, int write, void *h)
 {
 int ret, len = 1, errlen = 1;
 SRTSOCKET ready[1];
@@ -198,26 +198,13 @@ static int libsrt_network_wait_fd(URLContext *h, int eid, 
int write)
 return ret;
 }
 
-/* TODO de-duplicate code from ff_network_wait_fd_timeout() */
-
-static int libsrt_network_wait_fd_timeout(URLContext *h, int eid, int write, 
int64_t timeout, AVIOInterruptCB *int_cb)
+static inline int libsrt_network_wait_fd_timeout(URLContext *h, int eid, int 
write, int64_t timeout, AVIOInterruptCB *int_cb)
 {
-int ret;
-int64_t wait_start = 0;
-
-while (1) {
-if (ff_check_interrupt(int_cb))
-return AVERROR_EXIT;
-ret = libsrt_network_wait_fd(h, eid, write);
-if (ret != AVERROR(EAGAIN))
-return ret;
-if (timeout > 0) {
-if (!wait_start)
-wait_start = av_gettime_relative();
-else if (av_gettime_relative() - wait_start > timeout)
-return AVERROR(ETIMEDOUT);
-}
-}
+NetworkWaitFdCB wait_cb = {
+.wait_fd = libsrt_network_wait_fd,
+.opaque = h
+};
+return ff_network_wait_fd_timeout(eid, write, timeout, 
&h->interrupt_callback, &wait_cb);
 }
 
 static int libsrt_listen(int eid, int fd, const struct sockaddr *addr, 
socklen_t addrlen, URLContext *h, int64_t timeout)
-- 
2.28.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] vf_pseudocolor.c: fix build warning by adding braces

2021-02-07 Thread Guo, Yejun
the warning message is:
warning: missing braces around initializer [-Wmissing-braces]

Signed-off-by: Guo, Yejun 
---
 libavfilter/vf_pseudocolor.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavfilter/vf_pseudocolor.c b/libavfilter/vf_pseudocolor.c
index 192839342b..3416ab19a9 100644
--- a/libavfilter/vf_pseudocolor.c
+++ b/libavfilter/vf_pseudocolor.c
@@ -104,8 +104,8 @@ static const Range full_range   = {0, 256};
 static const Range spec1_range[] = {{0, 16}, {16, 236}, {236, 256}};
 static const Range spec2_range[] = {{0, 16}, {16, 22}, {22, 226}, {226, 236}, 
{236, 256}};
 
-static const Fill spec1_fills[] = {{0.5f, 0.f, .5f}, {-1.f, -1.f, -1.f}, {1.f, 
0.f, 0.f}};
-static const Fill spec2_fills[] = {{0.5f, 0.f, .5f}, {0.f, 1.f, 1.f}, {-1.f, 
-1.f, -1.f}, {1.f, 1.f, 0.f}, {1.f, 0.f, 0.f}};
+static const Fill spec1_fills[] = {{{0.5f, 0.f, .5f}}, {{-1.f, -1.f, -1.f}}, 
{{1.f, 0.f, 0.f}}};
+static const Fill spec2_fills[] = {{{0.5f, 0.f, .5f}}, {{0.f, 1.f, 1.f}}, 
{{-1.f, -1.f, -1.f}}, {{1.f, 1.f, 0.f}}, {{1.f, 0.f, 0.f}}};
 
 static const Curve curves[] =
 {
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 2/2] lavf/libsrt: deduplicate libsrt_network_wait_fd_timeout

2021-02-07 Thread zhilizhao(赵志立)


> On Feb 8, 2021, at 2:36 AM, Marton Balint  wrote:
> 
> 
> 
> On Mon, 8 Feb 2021, Zhao Zhili wrote:
> 
>> ---
>> libavformat/libsrt.c | 45 +---
>> 1 file changed, 17 insertions(+), 28 deletions(-)
> 
> Hmm, it seems my latest srt patches conflics with this a bit, and you will 
> have to somewhat rebase this, sorry. On the bright side, now only eid is 
> passed to libsrt_network_wait_fd, so maybe you can pass eid instead of fd, 
> especially since it is not always the context->eid that is used for wait.

Thanks for review. Rebase is done:

https://patchwork.ffmpeg.org/project/ffmpeg/patch/tencent_ff259aef9f5aab614e6c70ef2d7a9a684...@qq.com/

libsrt_network_wait_fd_timeout is implemented on top of 
ff_network_wait_fd_timeout
to keep minimum code changes. libsrt_network_wait_fd_timeout can be removed if 
add a NetworkWaitFdCB field to SRTContext but more code need to be changed.
What do you think?

> 
> Regards,
> Marton
> 
>> 
>> diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
>> index f73e7dbfa5..67e42bacc6 100644
>> --- a/libavformat/libsrt.c
>> +++ b/libavformat/libsrt.c
>> @@ -164,12 +164,14 @@ static int libsrt_socket_nonblock(int socket, int 
>> enable)
>>return srt_setsockopt(socket, 0, SRTO_RCVSYN, &blocking, 
>> sizeof(blocking));
>> }
>> -static int libsrt_network_wait_fd(URLContext *h, int eid, int fd, int write)
>> +static int libsrt_network_wait_fd(int fd, int write, void *ctx)
>> {
>>int ret, len = 1, errlen = 1;
>>int modes = SRT_EPOLL_ERR | (write ? SRT_EPOLL_OUT : SRT_EPOLL_IN);
>>SRTSOCKET ready[1];
>>SRTSOCKET error[1];
>> +URLContext *h = ctx;
>> +int eid = ((SRTContext*)h->priv_data)->eid;
>> 
>>if (srt_epoll_add_usock(eid, fd, &modes) < 0)
>>return libsrt_neterrno(h);
>> @@ -191,29 +193,16 @@ static int libsrt_network_wait_fd(URLContext *h, int 
>> eid, int fd, int write)
>>return ret;
>> }
>> -/* TODO de-duplicate code from ff_network_wait_fd_timeout() */
>> -
>> -static int libsrt_network_wait_fd_timeout(URLContext *h, int eid, int fd, 
>> int write, int64_t timeout, AVIOInterruptCB *int_cb)
>> +static int libsrt_network_wait_fd_timeout(URLContext *h, int fd, int write, 
>> int64_t timeout)
>> {
>> -int ret;
>> -int64_t wait_start = 0;
>> -
>> -while (1) {
>> -if (ff_check_interrupt(int_cb))
>> -return AVERROR_EXIT;
>> -ret = libsrt_network_wait_fd(h, eid, fd, write);
>> -if (ret != AVERROR(EAGAIN))
>> -return ret;
>> -if (timeout > 0) {
>> -if (!wait_start)
>> -wait_start = av_gettime_relative();
>> -else if (av_gettime_relative() - wait_start > timeout)
>> -return AVERROR(ETIMEDOUT);
>> -}
>> -}
>> +struct NetworkWaitFdCB wait_cb = {
>> +.wait_fd = libsrt_network_wait_fd,
>> +.opaque = h
>> +};
>> +return ff_network_wait_fd_timeout(fd, write, timeout, 
>> &h->interrupt_callback, &wait_cb);
>> }
>> -static int libsrt_listen(int eid, int fd, const struct sockaddr *addr, 
>> socklen_t addrlen, URLContext *h, int64_t timeout)
>> +static int libsrt_listen(int fd, const struct sockaddr *addr, socklen_t 
>> addrlen, URLContext *h, int64_t timeout)
>> {
>>int ret;
>>int reuse = 1;
>> @@ -228,7 +217,7 @@ static int libsrt_listen(int eid, int fd, const struct 
>> sockaddr *addr, socklen_t
>>if (ret)
>>return libsrt_neterrno(h);
>> -ret = libsrt_network_wait_fd_timeout(h, eid, fd, 1, timeout, 
>> &h->interrupt_callback);
>> +ret = libsrt_network_wait_fd_timeout(h, fd, 1, timeout);
>>if (ret < 0)
>>return ret;
>> @@ -241,7 +230,7 @@ static int libsrt_listen(int eid, int fd, const struct 
>> sockaddr *addr, socklen_t
>>return ret;
>> }
>> -static int libsrt_listen_connect(int eid, int fd, const struct sockaddr 
>> *addr, socklen_t addrlen, int64_t timeout, URLContext *h, int will_try_next)
>> +static int libsrt_listen_connect(int fd, const struct sockaddr *addr, 
>> socklen_t addrlen, int64_t timeout, URLContext *h, int will_try_next)
>> {
>>int ret;
>> @@ -249,7 +238,7 @@ static int libsrt_listen_connect(int eid, int fd, const 
>> struct sockaddr *addr, s
>>if (ret < 0)
>>return libsrt_neterrno(h);
>> -ret = libsrt_network_wait_fd_timeout(h, eid, fd, 1, timeout, 
>> &h->interrupt_callback);
>> +ret = libsrt_network_wait_fd_timeout(h, fd, 1, timeout);
>>if (ret < 0) {
>>if (will_try_next) {
>>av_log(h, AV_LOG_WARNING,
>> @@ -438,7 +427,7 @@ static int libsrt_setup(URLContext *h, const char *uri, 
>> int flags)
>> 
>>if (s->mode == SRT_MODE_LISTENER) {
>>// multi-client
>> -if ((ret = libsrt_listen(s->eid, fd, cur_ai->ai_addr, 
>> cur_ai->ai_addrlen, h, s->listen_timeout)) < 0)
>> +if ((ret = libsrt_listen(fd, cur_ai->ai_addr, cur_ai->ai_addrlen, 
>> h, s->listen_timeout)) < 0)
>>goto fail1;
>>listen_fd 

Re: [FFmpeg-devel] GSoC 2021

2021-02-07 Thread Guo, Yejun


> -Original Message-
> From: ffmpeg-devel  On Behalf Of
> Michael Niedermayer
> Sent: 2021年2月2日 17:48
> To: FFmpeg development discussions and patches 
> Subject: [FFmpeg-devel] GSoC 2021
> 
> Hi all
> 
> Most people probably already know but just to be sure everyone knows GSoC
> 2021 is 175h not 350h
> https://groups.google.com/g/google-summer-of-code-discuss/c/GgvbLrFBcUQ
> ?pli=1
> 
> Some project ideas may need to be adjusted accordingly

hi, for your information.

just like last year, to get more chances for GSoC project, I proposed my idea 
at https://01.org/linuxmedia/news/gsoc-2021-ideas, and also copy here for your 
convenience.

Async support for TensorFlow backend in FFmpeg
Description: FFmpeg DNN (deep neural network) module is to enable deep learning 
based FFmpeg filters with OpenVINO, TensorFlow and Native as its backends. The 
OpenVINO backend has supported async+batch execution for model inference with 
commit e67b5d and 64ea15 etc, it shows good performance gain. This project 
focuses on the async support for TensorFlow backend which invokes TensorFlow C 
library for model loading and inference. The main difference between the two 
backends is that OpenVINO API has async execution function while TensorFlow C 
API does not expose async function, so we need to support async execution by 
multiple threads within TensorFlow backend with sync function TF_SessionRun. 
(it is a plus if batch mode is also supported.)
Difficulty: Medium
Skill Required: C, multiple threads, DNN knowledge, git
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".