Re: [FFmpeg-devel] [PATCH 61/72] avcodec/pcm-dvd: Mark decoder as init-threadsafe

2020-11-28 Thread Paul B Mahol
lgtm

On Fri, Nov 27, 2020 at 6:50 PM Andreas Rheinhardt <
andreas.rheinha...@gmail.com> wrote:

> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/pcm-dvd.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/libavcodec/pcm-dvd.c b/libavcodec/pcm-dvd.c
> index 725c2f5b29..e019de80bd 100644
> --- a/libavcodec/pcm-dvd.c
> +++ b/libavcodec/pcm-dvd.c
> @@ -302,5 +302,6 @@ AVCodec ff_pcm_dvd_decoder = {
>  .capabilities   = AV_CODEC_CAP_DR1,
>  .sample_fmts= (const enum AVSampleFormat[]) {
>  AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_NONE
> -}
> +},
> +.caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
>  };
> --
> 2.25.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 v2 161/162] avcodec/mpegaudiodec: Hardcode tables to save space

2020-11-28 Thread Michael Niedermayer
On Fri, Nov 27, 2020 at 08:56:46PM +0100, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > On Fri, Nov 20, 2020 at 08:33:26AM +0100, Andreas Rheinhardt wrote:
> >> The csa_tables (which always consist of 32 entries of four byte each,
> >> but the type depends upon whether the decoder is fixed or
> >> floating-point) are currently initialized once during decoder
> >> initialization; yet it turns out that this is actually no benefit: The
> >> code used to initialize these tables takes up 153 (fixed point) and 122
> >> (floating point) bytes when compiled with GCC 9.3 with -O3 on x64, so it
> >> is better to just hardcode these tables.
> >>
> >> Essentially the same applies to the is_tables: They have a size or 128
> >> each and the code to initialize them occupies 149 (fixed point) resp.
> >> 140 (floating point) bytes. So hardcode them, too.
> > 
> > Is it intended not to use CONFIG_HARDCODED_TABLES ?
> > 
> Yes. It makes no sense to ever generate the tables at runtime if the
> code for this takes more space than the tables itself.
> 

> > also if the code generating the tables is removed then it should be made
> > easy to re-build the tables. That would be in the spirit of the *GPL
> > (to be able to change and rebuild a binary\H table 
> >  for potentially a different use)
> > 
> How about I refer to the git history for that? (I don't even have the
> mp3-spec, so I don't know on what part of it these tables are based.)

thats probably ok, maybe make the reference so it would work even with a
different VCS. (i assume the commit title is uniqe then it together with the
git hash would achieve this)

thx


[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

What does censorship reveal? It reveals fear. -- Julian Assange


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] avcodec/hevcdec: slice decoder, fix crash for thread_number > 16

2020-11-28 Thread Nuo Mi
following comandline will crash the ffmpeg
ffmpeg -threads 17 -thread_type slice -i WPP_A_ericsson_MAIN_2.bit out.yuv -y

the HEVCContext->sList size is MAX_NB_THREADS(16), any > 16 thread number will 
crash the application
---
 libavcodec/hevcdec.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 699c13bbcc..e1dae150d5 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -3406,7 +3406,7 @@ static av_cold int hevc_decode_free(AVCodecContext *avctx)
 av_freep(&s->sh.offset);
 av_freep(&s->sh.size);
 
-for (i = 1; i < s->threads_number; i++) {
+for (i = 1; i < FFMIN(s->threads_number, MAX_NB_THREADS); i++) {
 HEVCLocalContext *lc = s->HEVClcList[i];
 if (lc) {
 av_freep(&s->HEVClcList[i]);
@@ -3608,6 +3608,11 @@ static av_cold int hevc_decode_init(AVCodecContext 
*avctx)
 s->threads_type = FF_THREAD_FRAME;
 else
 s->threads_type = FF_THREAD_SLICE;
+if (s->threads_type == FF_THREAD_SLICE && s->threads_number > 
MAX_NB_THREADS) {
+av_log(s->avctx, AV_LOG_ERROR, "thread number > %d is not 
supported.\n", MAX_NB_THREADS);
+hevc_decode_free(avctx);
+return AVERROR(EINVAL);
+}
 
 return 0;
 }
-- 
2.25.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 v2] avformat/rtspdec: fix potential mem leak in listen mode

2020-11-28 Thread Andriy Gelman
On Fri, 27. Nov 09:25, Martin Storsjö wrote:
> On Thu, 26 Nov 2020, Andriy Gelman wrote:
> 
> > From: Andriy Gelman 
> > 
> > Currently a repeating setup request (with the same stream id) will
> > simply overwrite rtp_handle/transport_priv without freeing the
> > resources first. This is fixed by closing the previous setup request.
> > 
> > Signed-off-by: Andriy Gelman 
> > ---
> > libavformat/rtspdec.c | 11 +++
> > 1 file changed, 11 insertions(+)
> > 
> > diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c
> > index be11576913..221f44b20b 100644
> > --- a/libavformat/rtspdec.c
> > +++ b/libavformat/rtspdec.c
> > @@ -274,6 +274,17 @@ static int rtsp_read_setup(AVFormatContext *s, char* 
> > host, char *controlurl)
> > rtsp_st   = rt->rtsp_streams[streamid];
> > localport = rt->rtp_port_min;
> > 
> > +/* check if the stream has already been setup */
> > +if (rtsp_st->transport_priv) {
> > +if (CONFIG_RTPDEC && rt->transport == RTSP_TRANSPORT_RDT)
> > +ff_rdt_parse_close(rtsp_st->transport_priv);
> > +else if (CONFIG_RTPDEC && rt->transport == RTSP_TRANSPORT_RTP)
> > +ff_rtp_parse_close(rtsp_st->transport_priv);
> > +rtsp_st->transport_priv = NULL;
> > +}
> > +if (rtsp_st->rtp_handle)
> > +ffurl_closep(&rtsp_st->rtp_handle);
> > +
> > if (request.transports[0].lower_transport == RTSP_LOWER_TRANSPORT_TCP) {
> 
> LGTM if tested for at least the RTP case. (RDT in listen mode is probably
> not supported at all, and I doubt you can find a client that would use that,
> unless manually crafting client requests to trigger it.)

Thanks, will apply both patches.

I tested the RTP case before.

For RDT, I used netcat to trigger this path. I modified the sdp so that RDT
transport is selected by adding
a=IsRealDataType:integer; 1

Then sent two setup requests with the same stream id. And a third setup request
with an invalid sequence number to error out. Valgrind didn't show any leaks.

--
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".

Re: [FFmpeg-devel] [PATCH] avcodec/hevcdec: slice decoder, fix crash for thread_number > 16

2020-11-28 Thread Marton Balint



On Sat, 28 Nov 2020, Nuo Mi wrote:


following comandline will crash the ffmpeg
ffmpeg -threads 17 -thread_type slice -i WPP_A_ericsson_MAIN_2.bit out.yuv -y

the HEVCContext->sList size is MAX_NB_THREADS(16), any > 16 thread number will 
crash the application
---
libavcodec/hevcdec.c | 7 ++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 699c13bbcc..e1dae150d5 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -3406,7 +3406,7 @@ static av_cold int hevc_decode_free(AVCodecContext *avctx)
av_freep(&s->sh.offset);
av_freep(&s->sh.size);

-for (i = 1; i < s->threads_number; i++) {
+for (i = 1; i < FFMIN(s->threads_number, MAX_NB_THREADS); i++) {


This should not be needed, if you check the threads_number is 
hevc_decode_init.



HEVCLocalContext *lc = s->HEVClcList[i];
if (lc) {
av_freep(&s->HEVClcList[i]);
@@ -3608,6 +3608,11 @@ static av_cold int hevc_decode_init(AVCodecContext 
*avctx)
s->threads_type = FF_THREAD_FRAME;
else
s->threads_type = FF_THREAD_SLICE;
+if (s->threads_type == FF_THREAD_SLICE && s->threads_number > 
MAX_NB_THREADS) {
+av_log(s->avctx, AV_LOG_ERROR, "thread number > %d is not 
supported.\n", MAX_NB_THREADS);
+hevc_decode_free(avctx);
+return AVERROR(EINVAL);
+}


Is it possible to warn the user but gracefully continue with reduced 
number of threads? Mpeg2 decoder seems to do this.


Regards,
Marton
___
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/6] avutil/timecode: allow drop frame timecodes for multiples of 30000/1001 fps

2020-11-28 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 libavutil/timecode.c | 17 +++--
 libavutil/timecode.h |  4 ++--
 2 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/libavutil/timecode.c b/libavutil/timecode.c
index f2db21c52c..7caa6c64f5 100644
--- a/libavutil/timecode.c
+++ b/libavutil/timecode.c
@@ -33,16 +33,13 @@
 
 int av_timecode_adjust_ntsc_framenum2(int framenum, int fps)
 {
-/* only works for NTSC 29.97 and 59.94 */
+/* only works for multiples of NTSC 29.97 */
 int drop_frames = 0;
 int d, m, frames_per_10mins;
 
-if (fps == 30) {
-drop_frames = 2;
-frames_per_10mins = 17982;
-} else if (fps == 60) {
-drop_frames = 4;
-frames_per_10mins = 35964;
+if (fps && fps % 30 == 0) {
+drop_frames = fps / 30 * 2;
+frames_per_10mins = fps / 30 * 17982;
 } else
 return framenum;
 
@@ -196,8 +193,8 @@ static int check_timecode(void *log_ctx, AVTimecode *tc)
 av_log(log_ctx, AV_LOG_ERROR, "Valid timecode frame rate must be 
specified. Minimum value is 1\n");
 return AVERROR(EINVAL);
 }
-if ((tc->flags & AV_TIMECODE_FLAG_DROPFRAME) && tc->fps != 30 && tc->fps 
!= 60) {
-av_log(log_ctx, AV_LOG_ERROR, "Drop frame is only allowed with 
3/1001 or 6/1001 FPS\n");
+if ((tc->flags & AV_TIMECODE_FLAG_DROPFRAME) && tc->fps % 30 != 0) {
+av_log(log_ctx, AV_LOG_ERROR, "Drop frame is only allowed with 
multiples of 3/1001 FPS\n");
 return AVERROR(EINVAL);
 }
 if (check_fps(tc->fps) < 0) {
@@ -252,7 +249,7 @@ int av_timecode_init_from_string(AVTimecode *tc, AVRational 
rate, const char *st
 tc->start = (hh*3600 + mm*60 + ss) * tc->fps + ff;
 if (tc->flags & AV_TIMECODE_FLAG_DROPFRAME) { /* adjust frame number */
 int tmins = 60*hh + mm;
-tc->start -= (tc->fps == 30 ? 2 : 4) * (tmins - tmins/10);
+tc->start -= (tc->fps / 30 * 2) * (tmins - tmins/10);
 }
 return 0;
 }
diff --git a/libavutil/timecode.h b/libavutil/timecode.h
index f9471a6e38..697e61180b 100644
--- a/libavutil/timecode.h
+++ b/libavutil/timecode.h
@@ -49,9 +49,9 @@ typedef struct {
  * Adjust frame number for NTSC drop frame time code.
  *
  * @param framenum frame number to adjust
- * @param fps  frame per second, 30 or 60
+ * @param fps  frame per second, multiples of 30
  * @return adjusted frame number
- * @warningadjustment is only valid in NTSC 29.97 and 59.94
+ * @warningadjustment is only valid for multiples of NTSC 29.97
  */
 int av_timecode_adjust_ntsc_framenum2(int framenum, int fps);
 
-- 
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 1/2] ffmpeg: use sigaction() instead of signal() on linux

2020-11-28 Thread Andriy Gelman
From: Andriy Gelman 

As per signal() help (man 2 signal) the semantics of using signal may
vary across platforms. It is suggested to use sigaction() instead.

On my system, the capture signal is reset to the default handler after
the first call thus failing to properly handle multiple SIGINTs.

Signed-off-by: Andriy Gelman 
---
 fftools/ffmpeg.c | 31 +++
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 80f436eab3..01f4ef15d8 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -393,8 +393,30 @@ static BOOL WINAPI CtrlHandler(DWORD fdwCtrlType)
 }
 #endif
 
+#ifdef __linux__
+#define SIGNAL(sig, func)   \
+do {\
+action.sa_handler = func;   \
+sigaction(sig, &action, NULL);  \
+} while (0)
+#else
+#define SIGNAL(sig, func) \
+signal(sig, func)
+#endif
+
 void term_init(void)
 {
+#if defined __linux__
+struct sigaction action;
+action.sa_handler = sigterm_handler;
+
+/* block other interrupts while processing this one */
+sigfillset(&action.sa_mask);
+
+/* restart interruptible functions (i.e. don't fail with EINTR)  */
+action.sa_flags = SA_RESTART;
+#endif
+
 #if HAVE_TERMIOS_H
 if (!run_as_daemon && stdin_interaction) {
 struct termios tty;
@@ -413,14 +435,15 @@ void term_init(void)
 
 tcsetattr (0, TCSANOW, &tty);
 }
-signal(SIGQUIT, sigterm_handler); /* Quit (POSIX).  */
+SIGNAL(SIGQUIT, sigterm_handler); /* Quit (POSIX).  */
 }
 #endif
 
-signal(SIGINT , sigterm_handler); /* Interrupt (ANSI).*/
-signal(SIGTERM, sigterm_handler); /* Termination (ANSI).  */
+SIGNAL(SIGINT, sigterm_handler);
+SIGNAL(SIGTERM, sigterm_handler);
+
 #ifdef SIGXCPU
-signal(SIGXCPU, sigterm_handler);
+SIGNAL(SIGXCPU, sigterm_handler);
 #endif
 #ifdef SIGPIPE
 signal(SIGPIPE, SIG_IGN); /* Broken pipe (POSIX). */
-- 
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] RFC ffmpeg: exit demuxers earlier after signal received

2020-11-28 Thread Andriy Gelman
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

___
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 04/11] avformat/utils: Move +1 to avoid overflow

2020-11-28 Thread Michael Niedermayer
On Fri, Oct 30, 2020 at 09:24:15PM +0100, Michael Niedermayer wrote:
> On Wed, Oct 21, 2020 at 08:47:22AM +0200, Andreas Rheinhardt wrote:
> > Andreas Rheinhardt:
> > > Michael Niedermayer:
> > >> Fixes: signed integer overflow: 9223372036854775807 + 1 cannot be 
> > >> represented in type 'long'
> > >> Fixes: Timeout
> > >> Fixes: 
> > >> 26434/clusterfuzz-testcase-minimized-ffmpeg_dem_MV_fuzzer-5752845451919360
> > >> Fixes: 
> > >> 26444/clusterfuzz-testcase-minimized-ffmpeg_dem_BINK_fuzzer-4697773380993024
> > >>
> > >> Found-by: continuous fuzzing process 
> > >> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > >> Signed-off-by: Michael Niedermayer 
> > >> ---
> > >>  libavformat/utils.c | 2 +-
> > >>  1 file changed, 1 insertion(+), 1 deletion(-)
> > >>
> > >> diff --git a/libavformat/utils.c b/libavformat/utils.c
> > >> index e8335a601f..59d65a8092 100644
> > >> --- a/libavformat/utils.c
> > >> +++ b/libavformat/utils.c
> > >> @@ -253,7 +253,7 @@ int ffio_limit(AVIOContext *s, int size)
> > >>  remaining= FFMAX(remaining, 0);
> > >>  }
> > >>  
> > >> -if (s->maxsize>= 0 && remaining+1 < size) {
> > >> +if (s->maxsize>= 0 && remaining < size - (int64_t)1) {
> > >>  av_log(NULL, remaining ? AV_LOG_ERROR : AV_LOG_DEBUG, 
> > >> "Truncating packet of size %d to %"PRId64"\n", size, remaining+1);
> > >>  size = remaining+1;
> > >>  }
> > >>
> > > The +1 here seems very weird. If remaining + 1 == size, the packet will
> > > not be truncated, despite there not being enough data left.
> > > 
> > > The only reason for its existence I can think of is that it is designed
> > > to counter the potential -1 from s->maxsize = newsize - !newsize a few
> > > lines above. Yet this makes no sense: If newsize == 0, s->maxsize has
> > > just been set to -1 (indicating that future calls to ffio_limit() should
> > > not try again to get the filesize) and the second check above will not
> > > be reached at all.
> > > 
> > > So how about just removing the +1 in all three lines above?
> > > 
> > > - Andreas
> > > 
> > > PS: And while just at it: You can also add a space to "s->maxsize>= 0".
> > > 
> > On second look (seeing "remaining ?") this seems to be done to make sure
> >  not to truncate to zero in order to always read something at all. So
> > how about this here (untested):
> > 
> > diff --git a/libavformat/utils.c b/libavformat/utils.c
> > index e8335a601f..dd1b9e41c1 100644
> > --- a/libavformat/utils.c
> > +++ b/libavformat/utils.c
> > @@ -253,9 +253,11 @@ int ffio_limit(AVIOContext *s, int size)
> >  remaining= FFMAX(remaining, 0);
> >  }
> > 
> > -if (s->maxsize>= 0 && remaining+1 < size) {
> > -av_log(NULL, remaining ? AV_LOG_ERROR : AV_LOG_DEBUG,
> > "Truncating packet of size %d to %"PRId64"\n", size, remaining+1);
> > -size = remaining+1;
> > +if (s->maxsize >= 0 && remaining < size && size > 1) {
> > +av_log(NULL, remaining ? AV_LOG_ERROR : AV_LOG_DEBUG,
> > +   "Truncating packet of size %d to %"PRId64"\n",
> > +   size, remaining + !remaining);
> > +size = remaining + !remaining;
> >  }
> >  }
> >  return size;
> 
> LGTM, please apply

ping

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I know you won't believe me, but the highest form of Human Excellence is
to question oneself and others. -- Socrates


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] avcodec/pthread_slice: Don't use static variable, fix race

2020-11-28 Thread Andreas Rheinhardt
ff_slice_thread_init() uses a static variable to hold a function
pointer, although the value of said pointer needn't be saved between
different runs of this function at all;

The reason for this being so is probably that said pointer points to
a static function (if used); but storage class specifiers like "static"
are not part of the type of an object and so including it in the pointer
declaration is wrong (anyway, "static" means different things in both
contexts: for the function declaration it affects linkage, for the
variable storage duration).

Using a static variable here can lead to races, e.g. when initializing
VP9 (for which said function pointer was added) and H.264 with slice
threading. The latter has the FF_CODEC_CAP_INIT_THREADSAFE flag set and
is therefore unaffected by the lock guarding initializations of
decoders.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/pthread_slice.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/pthread_slice.c b/libavcodec/pthread_slice.c
index 77cfe3c9f6..80c4579fc0 100644
--- a/libavcodec/pthread_slice.c
+++ b/libavcodec/pthread_slice.c
@@ -130,7 +130,7 @@ int ff_slice_thread_init(AVCodecContext *avctx)
 {
 SliceThreadContext *c;
 int thread_count = avctx->thread_count;
-static void (*mainfunc)(void *);
+void (*mainfunc)(void *);
 
 // We cannot do this in the encoder init as the threads are created before
 if (av_codec_is_encoder(avctx->codec) &&
-- 
2.25.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 2/5] avutil/timecode: Avoid undefined behavior with large framenum

2020-11-28 Thread Michael Niedermayer
Fixes: signed integer overflow: 2147462079 + 2149596 cannot be represented in 
type 'int'
Fixes: 
27565/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5091972813160448

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

diff --git a/libavutil/timecode.c b/libavutil/timecode.c
index f2db21c52c..9ac5c81677 100644
--- a/libavutil/timecode.c
+++ b/libavutil/timecode.c
@@ -49,7 +49,7 @@ int av_timecode_adjust_ntsc_framenum2(int framenum, int fps)
 d = framenum / frames_per_10mins;
 m = framenum % frames_per_10mins;
 
-return framenum + 9 * drop_frames * d + drop_frames * ((m - drop_frames) / 
(frames_per_10mins / 10));
+return framenum + 9U * drop_frames * d + drop_frames * ((m - drop_frames) 
/ (frames_per_10mins / 10));
 }
 
 uint32_t av_timecode_get_smpte_from_framenum(const AVTimecode *tc, int 
framenum)
-- 
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/5] avformat/mov: Check a.size before computing next_root_atom

2020-11-28 Thread Michael Niedermayer
Fixes: signed integer overflow: 64 + 9223372036854775799 cannot be represented 
in type 'long'
Fixes: 
27563/clusterfuzz-testcase-minimized-ffmpeg_dem_MOV_fuzzer-6244650163372032

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 175d5a3cc2..194b6136b3 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -7065,7 +7065,7 @@ static int mov_read_default(MOVContext *c, AVIOContext 
*pb, MOVAtom atom)
 c->atom_depth --;
 return err;
 }
-if (c->found_moov && c->found_mdat &&
+if (c->found_moov && c->found_mdat && a.size <= INT64_MAX - 
start_pos &&
 ((!(pb->seekable & AVIO_SEEKABLE_NORMAL) || c->fc->flags & 
AVFMT_FLAG_IGNIDX || c->frag_index.complete) ||
  start_pos + a.size == avio_size(pb))) {
 if (!(pb->seekable & AVIO_SEEKABLE_NORMAL) || c->fc->flags & 
AVFMT_FLAG_IGNIDX || c->frag_index.complete)
-- 
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 5/5] avformat/id3v2: Check against max compression ratio before allocation

2020-11-28 Thread Michael Niedermayer
Fixes: Timeout (>10sec -> 12ms)
Fixes: 
27612/clusterfuzz-testcase-minimized-ffmpeg_dem_PCM_S24BE_fuzzer-6605893000757248

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

diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index 336a3964de..97f6cc8a68 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -995,6 +995,8 @@ static void id3v2_parse(AVIOContext *pb, AVDictionary 
**metadata,
 
 if (tlen <= 0)
 goto seek;
+if (dlen / 32768 > tlen)
+goto seek;
 
 av_fast_malloc(&uncompressed_buffer, 
&uncompressed_buffer_size, dlen);
 if (!uncompressed_buffer) {
-- 
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 3/5] avformat/avidec: Use av_sat_sub64() in check_stream_max_drift()

2020-11-28 Thread Michael Niedermayer
Fixes: signed integer overflow: 8833900919969684211 - -9223372036854775808 
cannot be represented in type 'long'
Fixes: 
26726/clusterfuzz-testcase-minimized-ffmpeg_dem_AVI_fuzzer-5669377724383232
Fixes: 
27587/clusterfuzz-testcase-minimized-ffmpeg_dem_AVI_fuzzer-6294562263531520

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

diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index 7e527e15ee..57dc54452b 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -1691,18 +1691,19 @@ static int check_stream_max_drift(AVFormatContext *s)
 AVIStream *ast = st->priv_data;
 
 if (idx[i] && min_dts != INT64_MAX / 2) {
-int64_t dts;
+int64_t dts, delta_dts;
 dts = av_rescale_q(st->internal->index_entries[idx[i] - 
1].timestamp /
FFMAX(ast->sample_size, 1),
st->time_base, AV_TIME_BASE_Q);
+delta_dts = av_sat_sub64(dts, min_dts);
 max_dts = FFMAX(max_dts, dts);
 max_buffer = FFMAX(max_buffer,
-   av_rescale(dts - min_dts,
+   av_rescale(delta_dts,
   st->codecpar->bit_rate,
   AV_TIME_BASE));
 }
 }
-if (max_dts - min_dts > 2 * AV_TIME_BASE ||
+if (av_sat_sub64(max_dts, min_dts) > 2 * AV_TIME_BASE ||
 max_buffer > 1024 * 1024 * 8 * 8) {
 av_free(idx);
 return 1;
-- 
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 4/5] avformat/id3v2: Sanity check tlen before alloc and uncompress

2020-11-28 Thread Michael Niedermayer
Fixes: Timeout (>20sec -> 65ms)
Fixes: 
26896/clusterfuzz-testcase-minimized-ffmpeg_dem_DAUD_fuzzer-5691024049176576

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

diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index cecd9b9f6d..336a3964de 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -993,6 +993,9 @@ static void id3v2_parse(AVIOContext *pb, AVDictionary 
**metadata,
 
 av_log(s, AV_LOG_DEBUG, "Compresssed frame %s tlen=%d 
dlen=%ld\n", tag, tlen, dlen);
 
+if (tlen <= 0)
+goto seek;
+
 av_fast_malloc(&uncompressed_buffer, 
&uncompressed_buffer_size, dlen);
 if (!uncompressed_buffer) {
 av_log(s, AV_LOG_ERROR, "Failed to alloc %ld bytes\n", 
dlen);
-- 
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] avcodec/hevcdec: slice decoder, fix crash for thread_number > 16

2020-11-28 Thread Nuo Mi
On Sun, Nov 29, 2020 at 1:54 AM Marton Balint  wrote:

>
>
> On Sat, 28 Nov 2020, Nuo Mi wrote:
>
> > following comandline will crash the ffmpeg
> > ffmpeg -threads 17 -thread_type slice -i WPP_A_ericsson_MAIN_2.bit
> out.yuv -y
> >
> > the HEVCContext->sList size is MAX_NB_THREADS(16), any > 16 thread
> number will crash the application
> > ---
> > libavcodec/hevcdec.c | 7 ++-
> > 1 file changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
> > index 699c13bbcc..e1dae150d5 100644
> > --- a/libavcodec/hevcdec.c
> > +++ b/libavcodec/hevcdec.c
> > @@ -3406,7 +3406,7 @@ static av_cold int hevc_decode_free(AVCodecContext
> *avctx)
> > av_freep(&s->sh.offset);
> > av_freep(&s->sh.size);
> >
> > -for (i = 1; i < s->threads_number; i++) {
> > +for (i = 1; i < FFMIN(s->threads_number, MAX_NB_THREADS); i++) {
>
> This should not be needed, if you check the threads_number is
> hevc_decode_init.
>
Yes, It's needed. After the patch, we have two hevc_decode_free in this
function.
Both need this.

>
> > HEVCLocalContext *lc = s->HEVClcList[i];
> > if (lc) {
> > av_freep(&s->HEVClcList[i]);
> > @@ -3608,6 +3608,11 @@ static av_cold int
> hevc_decode_init(AVCodecContext *avctx)
> > s->threads_type = FF_THREAD_FRAME;
> > else
> > s->threads_type = FF_THREAD_SLICE;
> > +if (s->threads_type == FF_THREAD_SLICE && s->threads_number >
> MAX_NB_THREADS) {
> > +av_log(s->avctx, AV_LOG_ERROR, "thread number > %d is not
> supported.\n", MAX_NB_THREADS);
> > +hevc_decode_free(avctx);
> > +return AVERROR(EINVAL);
> > +}
>
> Is it possible to warn the user but gracefully continue with reduced
> number of threads? Mpeg2 decoder seems to do this.
>
Sure, thanks for the suggestion.
After the change, the FFMIN(s->threads_number, MAX_NB_THREADS) still needed
by
https://github.com/FFmpeg/FFmpeg/blob/394e8bb385a351091cb1ba0be986f3bbb15039fd/libavcodec/hevcdec.c#L3601



> Regards,
> Marton
> ___
> 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".

[FFmpeg-devel] [PATCH] avcodec/hevcdec: slice decoder, fix crash for thread_number > 16

2020-11-28 Thread Nuo Mi
following comandline will crash the ffmpeg
ffmpeg -threads 17 -thread_type slice -i WPP_A_ericsson_MAIN_2.bit out.yuv -y

the HEVCContext->sList size is MAX_NB_THREADS(16), any > 16 thread number will 
crash the application
---
 libavcodec/hevcdec.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 699c13bbcc..457f75b551 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -3406,7 +3406,7 @@ static av_cold int hevc_decode_free(AVCodecContext *avctx)
 av_freep(&s->sh.offset);
 av_freep(&s->sh.size);
 
-for (i = 1; i < s->threads_number; i++) {
+for (i = 1; i < FFMIN(s->threads_number, MAX_NB_THREADS); i++) {
 HEVCLocalContext *lc = s->HEVClcList[i];
 if (lc) {
 av_freep(&s->HEVClcList[i]);
@@ -3608,6 +3608,10 @@ static av_cold int hevc_decode_init(AVCodecContext 
*avctx)
 s->threads_type = FF_THREAD_FRAME;
 else
 s->threads_type = FF_THREAD_SLICE;
+if (s->threads_type == FF_THREAD_SLICE && s->threads_number > 
MAX_NB_THREADS) {
+av_log(s->avctx, AV_LOG_WARNING, "too many threads (%d), reducing to 
%d.\n", s->threads_number, MAX_NB_THREADS);
+s->threads_number = MAX_NB_THREADS;
+}
 
 return 0;
 }
-- 
2.25.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] avdevice/decklink: remove the duplicated warning message

2020-11-28 Thread lance . lmwang
From: Limin Wang 

 ./ffmpeg -list_devices true -f decklink -i dummy
[Blackmagic DeckLink indev @ 0x2f96d00] The "list_devices" option is 
deprecated: list available devices
[decklink @ 0x2f96400] The -list_devices option is deprecated and will be 
removed. Please use ffmpeg -sources decklink instead.
->
[Blackmagic DeckLink indev @ 0x306ed00] The "list_devices" option is 
deprecated: use -sources decklink instead

Signed-off-by: Limin Wang 
---
 libavdevice/decklink_dec.cpp | 1 -
 libavdevice/decklink_dec_c.c | 2 +-
 libavdevice/decklink_enc.cpp | 1 -
 libavdevice/decklink_enc_c.c | 2 +-
 4 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index 2e41b58..072f8a1 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -1179,7 +1179,6 @@ av_cold int ff_decklink_read_header(AVFormatContext 
*avctx)
 
 /* List available devices. */
 if (ctx->list_devices) {
-av_log(avctx, AV_LOG_WARNING, "The -list_devices option is deprecated 
and will be removed. Please use ffmpeg -sources decklink instead.\n");
 ff_decklink_list_devices_legacy(avctx, 1, 0);
 return AVERROR_EXIT;
 }
diff --git a/libavdevice/decklink_dec_c.c b/libavdevice/decklink_dec_c.c
index 60b7186..7e2f03f 100644
--- a/libavdevice/decklink_dec_c.c
+++ b/libavdevice/decklink_dec_c.c
@@ -30,7 +30,7 @@
 #define DEC AV_OPT_FLAG_DECODING_PARAM
 
 static const AVOption options[] = {
-{ "list_devices", "list available devices"  , OFFSET(list_devices), 
AV_OPT_TYPE_BOOL  , { .i64 = 0   }, 0, 1, DEC | AV_OPT_FLAG_DEPRECATED},
+{ "list_devices", "use -sources decklink instead", OFFSET(list_devices), 
AV_OPT_TYPE_BOOL, { .i64 = 0   }, 0, 1, DEC | AV_OPT_FLAG_DEPRECATED},
 { "list_formats", "list supported formats"  , OFFSET(list_formats), 
AV_OPT_TYPE_INT   , { .i64 = 0   }, 0, 1, DEC },
 { "format_code",  "set format by fourcc", OFFSET(format_code),  
AV_OPT_TYPE_STRING, { .str = NULL}, 0, 0, DEC },
 { "raw_format",   "pixel format to be returned by the card when capturing" 
, OFFSET(raw_format),  AV_OPT_TYPE_INT, { .i64 = 0}, 0, 5, DEC, "raw_format" },
diff --git a/libavdevice/decklink_enc.cpp b/libavdevice/decklink_enc.cpp
index 883fdea..04b06ae 100644
--- a/libavdevice/decklink_enc.cpp
+++ b/libavdevice/decklink_enc.cpp
@@ -568,7 +568,6 @@ av_cold int ff_decklink_write_header(AVFormatContext *avctx)
 
 /* List available devices and exit. */
 if (ctx->list_devices) {
-av_log(avctx, AV_LOG_WARNING, "The -list_devices option is deprecated 
and will be removed. Please use ffmpeg -sinks decklink instead.\n");
 ff_decklink_list_devices_legacy(avctx, 0, 1);
 return AVERROR_EXIT;
 }
diff --git a/libavdevice/decklink_enc_c.c b/libavdevice/decklink_enc_c.c
index 6cc0743..5a052c8 100644
--- a/libavdevice/decklink_enc_c.c
+++ b/libavdevice/decklink_enc_c.c
@@ -28,7 +28,7 @@
 #define OFFSET(x) offsetof(struct decklink_cctx, x)
 #define ENC AV_OPT_FLAG_ENCODING_PARAM
 static const AVOption options[] = {
-{ "list_devices", "list available devices"  , OFFSET(list_devices), 
AV_OPT_TYPE_BOOL  , { .i64 = 0   }, 0, 1, ENC | AV_OPT_FLAG_DEPRECATED},
+{ "list_devices", "use -sinks decklink instead", OFFSET(list_devices), 
AV_OPT_TYPE_BOOL, { .i64 = 0   }, 0, 1, ENC | AV_OPT_FLAG_DEPRECATED},
 { "list_formats", "list supported formats"  , OFFSET(list_formats), 
AV_OPT_TYPE_INT   , { .i64 = 0   }, 0, 1, ENC },
 { "preroll" , "video preroll in seconds", OFFSET(preroll ), 
AV_OPT_TYPE_DOUBLE, { .dbl = 0.5 }, 0, 5, ENC },
 { "duplex_mode" , "duplex mode" , OFFSET(duplex_mode ), 
AV_OPT_TYPE_INT   , { .i64 = 0   }, 0, 2, ENC, "duplex_mode"},
-- 
1.8.3.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 v2] avcodec/hevcdec: slice decoder, fix crash for thread_number > 16

2020-11-28 Thread Nuo Mi
following comandline will crash the ffmpeg
ffmpeg -threads 17 -thread_type slice -i WPP_A_ericsson_MAIN_2.bit out.yuv -y

the HEVCContext->sList size is MAX_NB_THREADS(16), any > 16 thread number will 
crash the application
---
 libavcodec/hevcdec.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 699c13bbcc..457f75b551 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -3406,7 +3406,7 @@ static av_cold int hevc_decode_free(AVCodecContext *avctx)
 av_freep(&s->sh.offset);
 av_freep(&s->sh.size);
 
-for (i = 1; i < s->threads_number; i++) {
+for (i = 1; i < FFMIN(s->threads_number, MAX_NB_THREADS); i++) {
 HEVCLocalContext *lc = s->HEVClcList[i];
 if (lc) {
 av_freep(&s->HEVClcList[i]);
@@ -3608,6 +3608,10 @@ static av_cold int hevc_decode_init(AVCodecContext 
*avctx)
 s->threads_type = FF_THREAD_FRAME;
 else
 s->threads_type = FF_THREAD_SLICE;
+if (s->threads_type == FF_THREAD_SLICE && s->threads_number > 
MAX_NB_THREADS) {
+av_log(s->avctx, AV_LOG_WARNING, "too many threads (%d), reducing to 
%d.\n", s->threads_number, MAX_NB_THREADS);
+s->threads_number = MAX_NB_THREADS;
+}
 
 return 0;
 }
-- 
2.25.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/4] avdevice/decklink: add AV_OPT_FLAG_DEPRECATED flag for list_devices

2020-11-28 Thread lance . lmwang
On Sat, Nov 21, 2020 at 12:21:10PM +0100, Marton Balint wrote:
> 
> 
> On Sat, 21 Nov 2020, lance.lmw...@gmail.com wrote:
> 
> > From: Limin Wang 
> > 
> > and claim the option deprecated in the description.
> 
> No, the description should stay as is. Adding the flag is enough, the
> deprecation will be printed if the user asks for the list of options based
> on the flag.
Sorry, after add the flag, it'll print "The "list_devices" option is 
deprecated:", 
I still prefer to change the description like below to avoid the duplicated 
warning message,
how do you think? I'll send a updated patch for review.

./ffmpeg -list_devices true -f decklink -i dummy
[Blackmagic DeckLink indev @ 0x2f96d00] The "list_devices" option is 
deprecated: list available devices
[decklink @ 0x2f96400] The -list_devices option is deprecated and will be 
removed. Please use ffmpeg -sources decklink instead.

->

[Blackmagic DeckLink indev @ 0x306ed00] The "list_devices" option is 
deprecated: use -sources decklink instead

> 
> Regards,
> Marton
> 
> > 
> > Signed-off-by: Limin Wang 
> > ---
> > libavdevice/decklink_dec_c.c | 3 ++-
> > libavdevice/decklink_enc_c.c | 3 ++-
> > 2 files changed, 4 insertions(+), 2 deletions(-)
> > 
> > diff --git a/libavdevice/decklink_dec_c.c b/libavdevice/decklink_dec_c.c
> > index 53a4774..c6b38d2 100644
> > --- a/libavdevice/decklink_dec_c.c
> > +++ b/libavdevice/decklink_dec_c.c
> > @@ -30,7 +30,8 @@
> > #define DEC AV_OPT_FLAG_DECODING_PARAM
> > 
> > static const AVOption options[] = {
> > -{ "list_devices", "list available devices"  , OFFSET(list_devices), 
> > AV_OPT_TYPE_BOOL  , { .i64 = 0   }, 0, 1, DEC },
> > +{ "list_devices", "list available devices(deprecated, use -sources 
> > decklink instead)", OFFSET(list_devices),
> > +
> > AV_OPT_TYPE_BOOL  , { .i64 = 0   }, 0, 1, DEC | AV_OPT_FLAG_DEPRECATED},
> > { "list_formats", "list supported formats"  , OFFSET(list_formats), 
> > AV_OPT_TYPE_INT   , { .i64 = 0   }, 0, 1, DEC },
> > { "format_code",  "set format by fourcc", OFFSET(format_code),  
> > AV_OPT_TYPE_STRING, { .str = NULL}, 0, 0, DEC },
> > { "raw_format",   "pixel format to be returned by the card when 
> > capturing" , OFFSET(raw_format),  AV_OPT_TYPE_INT, { .i64 = 0}, 0, 5, DEC, 
> > "raw_format" },
> > diff --git a/libavdevice/decklink_enc_c.c b/libavdevice/decklink_enc_c.c
> > index e7b0117..ce99220 100644
> > --- a/libavdevice/decklink_enc_c.c
> > +++ b/libavdevice/decklink_enc_c.c
> > @@ -28,7 +28,8 @@
> > #define OFFSET(x) offsetof(struct decklink_cctx, x)
> > #define ENC AV_OPT_FLAG_ENCODING_PARAM
> > static const AVOption options[] = {
> > -{ "list_devices", "list available devices"  , OFFSET(list_devices), 
> > AV_OPT_TYPE_BOOL  , { .i64 = 0   }, 0, 1, ENC },
> > +{ "list_devices", "list available devices(deprecated, use -sinks 
> > decklink instead)"
> > +, OFFSET(list_devices), 
> > AV_OPT_TYPE_BOOL  , { .i64 = 0   }, 0, 1, ENC | AV_OPT_FLAG_DEPRECATED},
> > { "list_formats", "list supported formats"  , OFFSET(list_formats), 
> > AV_OPT_TYPE_INT   , { .i64 = 0   }, 0, 1, ENC },
> > { "preroll" , "video preroll in seconds", OFFSET(preroll ), 
> > AV_OPT_TYPE_DOUBLE, { .dbl = 0.5 }, 0, 5, ENC },
> > { "duplex_mode" , "duplex mode" , OFFSET(duplex_mode ), 
> > AV_OPT_TYPE_INT   , { .i64 = 0   }, 0, 2, ENC, "duplex_mode"},
> > -- 
> > 1.8.3.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".

-- 
Thanks,
Limin Wang
___
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/1] avformat/mov: fix timecode with counter mode flag set

2020-11-28 Thread mindmark
From: Mark Reid 

The current behaviour ends up squaring the avg_frame_rate if the conter mode 
flag is set.
This messes up the timecode calculation, and looks to me as a regression that 
seems to have been introduced 428b4aac.

The new behaviour is use the "Number of frames" field for avg_frame_rate from 
the timecode atom as describe here:

https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap3/qtff3.html#//apple_ref/doc/uid/TP4939-CH205-69831

Number of frames
An 8-bit integer that contains the number of frames per second for the 
timecode format. 
If the time is a counter, this is the number of frames for each counter 
tick.

Here is a sample mov file with the counter flag set
https://www.dropbox.com/s/5l4fucb9lhq523s/timecode_counter_mode.mov

before the patch ffmpeg will report the timecode as:
00:37:11:97 and warns that the timecode framerate is 57600/1002001

after patch:
14:50:55:02

---
 libavformat/mov.c | 17 +
 1 file changed, 5 insertions(+), 12 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 2b90e31170..76c1ceb82a 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -2336,24 +2336,17 @@ static int mov_parse_stsd_data(MOVContext *c, 
AVIOContext *pb,
 tmcd_ctx->tmcd_flags = val;
 st->avg_frame_rate.num = AV_RB32(st->codecpar->extradata + 8); /* 
timescale */
 st->avg_frame_rate.den = AV_RB32(st->codecpar->extradata + 12); /* 
frameDuration */
-#if FF_API_LAVF_AVCTX
-FF_DISABLE_DEPRECATION_WARNINGS
-st->codec->time_base = av_inv_q(st->avg_frame_rate);
-FF_ENABLE_DEPRECATION_WARNINGS
-#endif
+
 /* adjust for per frame dur in counter mode */
 if (tmcd_ctx->tmcd_flags & 0x0008) {
-int timescale = AV_RB32(st->codecpar->extradata + 8);
-int framedur = AV_RB32(st->codecpar->extradata + 12);
-st->avg_frame_rate.num *= timescale;
-st->avg_frame_rate.den *= framedur;
+st->avg_frame_rate.num = st->codecpar->extradata[16] /* fps, 
frames per counter tick in counter mode */;
+st->avg_frame_rate.den = 1;
+}
 #if FF_API_LAVF_AVCTX
 FF_DISABLE_DEPRECATION_WARNINGS
-st->codec->time_base.den *= timescale;
-st->codec->time_base.num *= framedur;
+st->codec->time_base = av_inv_q(st->avg_frame_rate);
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
-}
 if (size > 30) {
 uint32_t len = AV_RB32(st->codecpar->extradata + 18); /* name 
atom length */
 uint32_t format = AV_RB32(st->codecpar->extradata + 22);
-- 
2.29.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".