[FFmpeg-devel] [PATCH] fate: add adpcm_ima_ssi encoding test

2020-05-30 Thread Zane van Iperen
Signed-off-by: Zane van Iperen 
---
 tests/fate/acodec.mak  | 2 ++
 tests/ref/acodec/adpcm-ima_ssi | 4 
 2 files changed, 6 insertions(+)
 create mode 100644 tests/ref/acodec/adpcm-ima_ssi

diff --git a/tests/fate/acodec.mak b/tests/fate/acodec.mak
index 80d26de0f9..bb6bfe5ada 100644
--- a/tests/fate/acodec.mak
+++ b/tests/fate/acodec.mak
@@ -46,6 +46,7 @@ fate-acodec-pcm-f%be: FMT = au
 
 FATE_ACODEC_ADPCM-$(call ENCDEC, ADPCM_ADX, ADX)  += adx
 FATE_ACODEC_ADPCM-$(call ENCDEC, ADPCM_IMA_QT,  AIFF) += ima_qt
+FATE_ACODEC_ADPCM-$(call ENCDEC, ADPCM_IMA_SSI, KVAG) += ima_ssi
 FATE_ACODEC_ADPCM-$(call ENCDEC, ADPCM_IMA_WAV, WAV)  += ima_wav
 FATE_ACODEC_ADPCM-$(call ENCDEC, ADPCM_MS,  WAV)  += ms
 FATE_ACODEC_ADPCM-$(call ENCDEC, ADPCM_SWF, FLV)  += swf
@@ -59,6 +60,7 @@ fate-acodec-adpcm-%: CODEC = adpcm_$(@:fate-acodec-adpcm-%=%)
 
 fate-acodec-adpcm-adx: FMT = adx
 fate-acodec-adpcm-ima_qt:  FMT = aiff
+fate-acodec-adpcm-ima_ssi: FMT = kvag
 fate-acodec-adpcm-ima_wav: FMT = wav
 fate-acodec-adpcm-ms:  FMT = wav
 fate-acodec-adpcm-swf: FMT = flv
diff --git a/tests/ref/acodec/adpcm-ima_ssi b/tests/ref/acodec/adpcm-ima_ssi
new file mode 100644
index 00..63cc9ce277
--- /dev/null
+++ b/tests/ref/acodec/adpcm-ima_ssi
@@ -0,0 +1,4 @@
+91c6a0d8eb3544e402af17a1b77a22e5 *tests/data/fate/acodec-adpcm-ima_ssi.kvag
+264614 tests/data/fate/acodec-adpcm-ima_ssi.kvag
+201607bf7610f062b9a1e6524354c569 *tests/data/fate/acodec-adpcm-ima_ssi.out.wav
+stddev:  904.76 PSNR: 37.20 MAXDIFF:34029 bytes:  1058400/  1058400
-- 
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] libavutil/timestamp.h: Fix loss of precision in timestamps

2020-05-30 Thread Allan Cady
I prepared this patch a year ago but never followed through to get it accepted. 
Thought I would give it another try. I've been using a local copy with these 
changes, and for me it makes the difference between silencedetect being usable 
or not. 

Brief description: The existing implementation of the silencedetect filter uses 
the format specifier "%.6g", which keeps a fixed-width, and so loses precision 
as the time offsets get larger. I propose changing to "%.6f", which keeps six 
decimal digits precision no matter how large the offset.
Further explanation in the patch comments.
New patch attached, and here is the last correspondence I had with y'all last 
year.
https://ffmpeg.org/pipermail/ffmpeg-devel/2019-April/242233.html 



From 88866601cf6c6931846636fc5fee25dbbfe5ce52 Mon Sep 17 00:00:00 2001
From: Allan Cady 
Date: Sat, 30 May 2020 21:06:45 -0700
Subject: [PATCH] libavutil/timestamp.h: Fix loss of precision in timestamps
 for silencedetect on long files

When the silencedetect filter is run against long files, the output
timestamps gradually lose precision as the scan proceeds further into
the file. This is because the output is formatted (in
libavutil/timestamp.h) as "%.6g", which limits the total field
length. Eventually, for offsets greater than 10 seconds (about 28
hours), fractions of a second disappear altogether, and the
timestamps are logged as whole seconds.

I propose changing the format to "%.6f",
which will give microsecond precision for all timestamps, regardless of offset.

The timestamp string length is limited to 32 characters
(AV_TS_MAX_STRING_SIZE), so this should still be plenty long enough
with the increased length (up to 10^25 seconds).

My interest is in fixing this problem for silencedetect, which
formats the timestamps by calling the macro av_ts2timestr, defined in
timestamp.h. Since av_ts2timestr is also used in many other places (I
count 21 c files), I have created a new macro, av_ts2timestr_format,
with a format string added as a parameter, and left the original
macro interface as is for other usages, to limit the scope of this
change. The same or similar change could be made for other cases
where better precision is desired.
---
 libavfilter/af_silencedetect.c   | 14 +-
 libavutil/timestamp.h| 27 +---
 tests/ref/fate/filter-metadata-silencedetect |  2 +-
 3 files changed, 32 insertions(+), 11 deletions(-)

diff --git a/libavfilter/af_silencedetect.c b/libavfilter/af_silencedetect.c
index ff3b219e77..13c6f6f498 100644
--- a/libavfilter/af_silencedetect.c
+++ b/libavfilter/af_silencedetect.c
@@ -32,6 +32,8 @@
 #include "avfilter.h"
 #include "internal.h"
 
+const char TS_FMT_SILENCEDETECT[] = "%.6f";
+
 typedef struct SilenceDetectContext {
 const AVClass *class;
 double noise;   ///< noise amplitude ratio
@@ -87,11 +89,11 @@ static av_always_inline void update(SilenceDetectContext *s, AVFrame *insamples,
 s->start[channel] = insamples->pts + av_rescale_q(current_sample / s->channels + 1 - nb_samples_notify * s->independent_channels / s->channels,
 (AVRational){ 1, s->last_sample_rate }, time_base);
 set_meta(insamples, s->mono ? channel + 1 : 0, "silence_start",
-av_ts2timestr(s->start[channel], _base));
+av_ts2timestr_fmt(s->start[channel], _base, TS_FMT_SILENCEDETECT));
 if (s->mono)
 av_log(s, AV_LOG_INFO, "channel: %d | ", channel);
 av_log(s, AV_LOG_INFO, "silence_start: %s\n",
-av_ts2timestr(s->start[channel], _base));
+av_ts2timestr_fmt(s->start[channel], _base, TS_FMT_SILENCEDETECT));
 }
 }
 } else {
@@ -102,15 +104,15 @@ static av_always_inline void update(SilenceDetectContext *s, AVFrame *insamples,
 int64_t duration_ts = end_pts - s->start[channel];
 if (insamples) {
 set_meta(insamples, s->mono ? channel + 1 : 0, "silence_end",
-av_ts2timestr(end_pts, _base));
+av_ts2timestr_fmt(end_pts, _base, TS_FMT_SILENCEDETECT));
 set_meta(insamples, s->mono ? channel + 1 : 0, "silence_duration",
-av_ts2timestr(duration_ts, _base));
+av_ts2timestr_fmt(duration_ts, _base, TS_FMT_SILENCEDETECT));
 }
 if (s->mono)
 av_log(s, AV_LOG_INFO, "channel: %d | ", channel);
 av_log(s, AV_LOG_INFO, "silence_end: %s | silence_duration: %s\n",
-av_ts2timestr(end_pts, _base),
-av_ts2timestr(duration_ts, _base));
+av_ts2timestr_fmt(end_pts, _base, TS_FMT_SILENCEDETECT),
+av_ts2timestr_fmt(duration_ts, _base, TS_FMT_SILENCEDETECT));
 }
 s->nb_null_samples[channel] = 0;
 

Re: [FFmpeg-devel] [PATCH 1/3] ffbuild: Refine MIPS handling

2020-05-30 Thread Shiyou Yin
>-Original Message-
>From: ffmpeg-devel-boun...@ffmpeg.org [mailto:ffmpeg-devel-boun...@ffmpeg.org] 
>On Behalf Of
>Jiaxun Yang
>Sent: Tuesday, May 26, 2020 5:48 PM
>To: ffmpeg-devel@ffmpeg.org
>Cc: yinshi...@loongson.cn; Jiaxun Yang
>Subject: [FFmpeg-devel] [PATCH 1/3] ffbuild: Refine MIPS handling
>
>To enable runtime detection for MIPS, we need to refine ffbuild
>part to support buildding these feature together.
>
>Firstly, we fixed configure, let it probe native ability of toolchain
>to decide wether a feature can to be enabled, also clearly marked
>the conflictions between loongson2 & loongson3 and Release 6 & rest.
>
>Secondly, we compile MMI and MSA C sources with their own flags to ensure
>their flags won't pollute the whole program and generate illegal code.
>
>Signed-off-by: Jiaxun Yang 
>---
> configure| 179 +++
> ffbuild/common.mak   |  10 ++-
> libavcodec/mips/Makefile |   3 +-
> 3 files changed, 117 insertions(+), 75 deletions(-)
>
>diff --git a/configure b/configure
>index f97cad0298..8dc3874642 100755
>--- a/configure
>+++ b/configure
>@@ -1113,6 +1113,26 @@ void foo(void){ __asm__ volatile($code); }
> EOF
> }
>
>+check_extra_inline_asm_flags(){
>+log check_extra_inline_asm_flags "$@"
>+name="$1"
>+extra=$2
>+code="$3"
>+flags=''
>+shift 3
>+while [ "$1" != "" ]; do
>+  append flags $1
>+  shift
>+done;
>+disable $name
>+cat > $TMPC <+void foo(void){ __asm__ volatile($code); }
>+EOF
>+log_file $TMPC
>+test_cmd $cc $CPPFLAGS $CFLAGS $flags "$@" $CC_C $(cc_o $TMPO) $TMPC &&
>+enable $name && append $extra "$flags"
>+}
>+

Use function check_inline_asm_flags is suggested.

> check_inline_asm_flags(){
> log check_inline_asm_flags "$@"
> name="$1"
>@@ -2551,7 +2571,7 @@ mips64r6_deps="mips"
> mipsfpu_deps="mips"
> mipsdsp_deps="mips"
> mipsdspr2_deps="mips"
>-mmi_deps="mips"
>+mmi_deps_any="loongson2 loongson3"
> msa_deps="mipsfpu"
> msa2_deps="msa"
>
>@@ -4999,29 +5019,57 @@ elif enabled bfin; then
>
> elif enabled mips; then
>
>-cpuflags="-march=$cpu"
>-
> if [ "$cpu" != "generic" ]; then
>-disable mips32r2
>-disable mips32r5
>-disable mips64r2
>-disable mips32r6
>-disable mips64r6
>-disable loongson2
>-disable loongson3
>+# DSP is disabled by deafult as they can't be detected at runtime
>+disable mipsdsp
>+disable mipsdspr2
>+
>+cpuflags="-march=$cpu"
>
> case $cpu in
>-24kc|24kf*|24kec|34kc|1004kc|24kef*|34kf*|1004kf*|74kc|74kf)
>+# General ISA levels
>+mips1|mips3)
>+disable msa
>+;;
>+mips32r2)
> enable mips32r2
>+;;
>+mips32r5)
>+enable mips32r5
>+;;
>+mips64r2|mips64r5)
>+enable mips64r2
>+;;
>+# Cores from MIPS(MTI)
>+24kc)
>+disable mipsfpu
>+;;
>+24kf*|24kec|34kc|74Kc|1004kc)
>+disable mmi
> disable msa
> ;;
>-p5600|i6400|p6600)
>-disable mipsdsp
>-disable mipsdspr2
>+24kef*|34kf*|1004kf*)
>+disable mmi
>+disable msa
>+enable mipsdsp
>+;;
>+p5600)
>+disable mmi
>+enable mips32r5
>+check_cflags "-mtune=p5600" && check_cflags "-msched-weight 
>-mload-store-pairs
>-funroll-loops"
>+;;
>+i6400)
>+disable mmi
>+enable mips64r6
>+check_cflags "-mtune=i6400 -mabi=64" && check_cflags 
>"-msched-weight
>-mload-store-pairs -funroll-loops" && check_ldflags "-mabi=64"
>+;;
>+p6600)
>+disable mmi
>+enable mips64r6
>+check_cflags "-mtune=p6600 -mabi=64" && check_cflags 
>"-msched-weight
>-mload-store-pairs -funroll-loops" && check_ldflags "-mabi=64"
> ;;
>+# Cores from Loongson
> loongson*)
>-enable loongson2
>-enable loongson3
> enable local_aligned
> enable simd_align_16
> enable fast_64bit
>@@ -5029,8 +5077,6 @@ elif enabled mips; then
> enable fast_cmov
> enable fast_unaligned
> disable aligned_stack
>-disable mipsdsp
>-disable mipsdspr2
> # When gcc version less than 5.3.0, add 
> -fno-expensive-optimizations flag.
> if [ $cc == gcc ]; then
> gcc_version=$(gcc -dumpversion)
>@@ -5042,62 +5088,26 @@ elif enabled mips; then
> fi
> case $cpu in
> loongson3*)
>+  

Re: [FFmpeg-devel] [PATCH 2/2] avcodec/anm: Don't unnecessarily use context variables

2020-05-30 Thread Peter Ross
On Sat, May 30, 2020 at 06:33:00AM +0200, Andreas Rheinhardt wrote:
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/anm.c | 39 +++
>  1 file changed, 19 insertions(+), 20 deletions(-)
> 
> diff --git a/libavcodec/anm.c b/libavcodec/anm.c
> index e9b19d880d..134640ee36 100644
> --- a/libavcodec/anm.c
> +++ b/libavcodec/anm.c
> @@ -31,13 +31,12 @@
>  typedef struct AnmContext {
>  AVFrame *frame;
>  int palette[AVPALETTE_COUNT];
> -GetByteContext gb;
> -int x;  ///< x coordinate position
>  } AnmContext;
>  
>  static av_cold int decode_init(AVCodecContext *avctx)
>  {
>  AnmContext *s = avctx->priv_data;
> +GetByteContext gb;
>  int i;
>  
>  if (avctx->extradata_size < 16 * 8 + 4 * 256)
> @@ -49,10 +48,10 @@ static av_cold int decode_init(AVCodecContext *avctx)
>  if (!s->frame)
>  return AVERROR(ENOMEM);
>  
> -bytestream2_init(>gb, avctx->extradata, avctx->extradata_size);
> -bytestream2_skipu(>gb, 16 * 8);
> +bytestream2_init(, avctx->extradata, avctx->extradata_size);
> +bytestream2_skipu(, 16 * 8);
>  for (i = 0; i < 256; i++)
> -s->palette[i] = (0xFFU << 24) | bytestream2_get_le32u(>gb);
> +s->palette[i] = (0xFFU << 24) | bytestream2_get_le32u();
>  
>  return 0;
>  }
> @@ -115,7 +114,8 @@ static int decode_frame(AVCodecContext *avctx,
>  AnmContext *s = avctx->priv_data;
>  const int buf_size = avpkt->size;
>  uint8_t *dst, *dst_end;
> -int count, ret;
> +GetByteContext gb;
> +int count, ret, x = 0;
>  
>  if (buf_size < 7)
>  return AVERROR_INVALIDDATA;
> @@ -125,37 +125,36 @@ static int decode_frame(AVCodecContext *avctx,
>  dst = s->frame->data[0];
>  dst_end = s->frame->data[0] + s->frame->linesize[0]*avctx->height;
>  
> -bytestream2_init(>gb, avpkt->data, buf_size);
> +bytestream2_init(, avpkt->data, buf_size);
>  
> -if (bytestream2_get_byte(>gb) != 0x42) {
> +if (bytestream2_get_byte() != 0x42) {
>  avpriv_request_sample(avctx, "Unknown record type");
>  return AVERROR_INVALIDDATA;
>  }
> -if (bytestream2_get_byte(>gb)) {
> +if (bytestream2_get_byte()) {
>  avpriv_request_sample(avctx, "Padding bytes");
>  return AVERROR_PATCHWELCOME;
>  }
> -bytestream2_skip(>gb, 2);
> +bytestream2_skip(, 2);
>  
> -s->x = 0;
>  do {
>  /* if statements are ordered by probability */
>  #define OP(gb, pixel, count) \
> -op(, dst_end, (gb), (pixel), (count), >x, avctx->width, 
> s->frame->linesize[0])
> +op(, dst_end, (gb), (pixel), (count), , avctx->width, 
> s->frame->linesize[0])
>  
> -int type = bytestream2_get_byte(>gb);
> +int type = bytestream2_get_byte();
>  count = type & 0x7F;
>  type >>= 7;
>  if (count) {
> -if (OP(type ? NULL : >gb, -1, count)) break;
> +if (OP(type ? NULL : , -1, count)) break;
>  } else if (!type) {
>  int pixel;
> -count = bytestream2_get_byte(>gb);  /* count==0 gives nop */
> -pixel = bytestream2_get_byte(>gb);
> +count = bytestream2_get_byte();  /* count==0 gives nop */
> +pixel = bytestream2_get_byte();
>  if (OP(NULL, pixel, count)) break;
>  } else {
>  int pixel;
> -type = bytestream2_get_le16(>gb);
> +type = bytestream2_get_le16();
>  count = type & 0x3FFF;
>  type >>= 14;
>  if (!count) {
> @@ -167,11 +166,11 @@ static int decode_frame(AVCodecContext *avctx,
>  }
>  continue;
>  }
> -pixel = type == 3 ? bytestream2_get_byte(>gb) : -1;
> +pixel = type == 3 ? bytestream2_get_byte() : -1;
>  if (type == 1) count += 0x4000;
> -if (OP(type == 2 ? >gb : NULL, pixel, count)) break;
> +if (OP(type == 2 ?  : NULL, pixel, count)) break;
>  }
> -} while (bytestream2_get_bytes_left(>gb) > 0);
> +} while (bytestream2_get_bytes_left() > 0);
>  
>  memcpy(s->frame->data[1], s->palette, AVPALETTE_SIZE);
>  
> -- 
> 2.20.1

ok.

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)


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/2] avcodec/anm: Check extradata length before allocating frame

2020-05-30 Thread Peter Ross
On Sat, May 30, 2020 at 06:32:59AM +0200, Andreas Rheinhardt wrote:
> Then one doesn't need to free the frame in case the length turns out to
> be insufficient.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/anm.c | 8 +++-
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/libavcodec/anm.c b/libavcodec/anm.c
> index cd1fcc5998..e9b19d880d 100644
> --- a/libavcodec/anm.c
> +++ b/libavcodec/anm.c
> @@ -40,6 +40,9 @@ static av_cold int decode_init(AVCodecContext *avctx)
>  AnmContext *s = avctx->priv_data;
>  int i;
>  
> +if (avctx->extradata_size < 16 * 8 + 4 * 256)
> +return AVERROR_INVALIDDATA;
> +
>  avctx->pix_fmt = AV_PIX_FMT_PAL8;
>  
>  s->frame = av_frame_alloc();
> @@ -47,11 +50,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
>  return AVERROR(ENOMEM);
>  
>  bytestream2_init(>gb, avctx->extradata, avctx->extradata_size);
> -if (bytestream2_get_bytes_left(>gb) < 16 * 8 + 4 * 256) {
> -av_frame_free(>frame);
> -return AVERROR_INVALIDDATA;
> -}
> -
>  bytestream2_skipu(>gb, 16 * 8);
>  for (i = 0; i < 256; i++)
>  s->palette[i] = (0xFFU << 24) | bytestream2_get_le32u(>gb);
> -- 
> 2.20.1

ok.

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)


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] avutil/buffer: add a mention that some arguments from av_buffer_pool_init2() may be NULL

2020-05-30 Thread James Almer
Signed-off-by: James Almer 
---
 libavutil/buffer.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavutil/buffer.h b/libavutil/buffer.h
index e0f94314f4..aa611fee8a 100644
--- a/libavutil/buffer.h
+++ b/libavutil/buffer.h
@@ -252,14 +252,15 @@ AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* 
(*alloc)(int size));
  * Allocate and initialize a buffer pool with a more complex allocator.
  *
  * @param size size of each buffer in this pool
- * @param opaque arbitrary user data used by the allocator
+ * @param opaque arbitrary user data used by the allocator. May be NULL.
  * @param alloc a function that will be used to allocate new buffers when the
  *  pool is empty.
  * @param pool_free a function that will be called immediately before the pool
  *  is freed. I.e. after av_buffer_pool_uninit() is called
  *  by the caller and all the frames are returned to the pool
  *  and freed. It is intended to uninitialize the user opaque
- *  data.
+ *  data. May be NULL if the opaque data doesn't need to be
+ *  uninitialized.
  * @return newly created buffer pool on success, NULL on error.
  */
 AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
-- 
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/2] avutil/buffer: reject NULL as argument for the av_buffer_pool_init2() alloc callback

2020-05-30 Thread James Almer
This prevents NULL pointer dereference crashes when calling av_buffer_pool_get()
using the resulting pool.

Signed-off-by: James Almer 
---
 libavutil/buffer.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavutil/buffer.c b/libavutil/buffer.c
index 6d9cb7428e..6fe8f19c39 100644
--- a/libavutil/buffer.c
+++ b/libavutil/buffer.c
@@ -220,7 +220,11 @@ AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
AVBufferRef* (*alloc)(void *opaque, int 
size),
void (*pool_free)(void *opaque))
 {
-AVBufferPool *pool = av_mallocz(sizeof(*pool));
+AVBufferPool *pool;
+
+if (!alloc)
+return NULL;
+pool = av_mallocz(sizeof(*pool));
 if (!pool)
 return NULL;
 
-- 
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".

Re: [FFmpeg-devel] [PATCH 2/2] Set stream_id correctly based on KLV profile selected.

2020-05-30 Thread Brad Hards
I think I fixed these issues in V2
http://ffmpeg.org/pipermail/ffmpeg-devel/2020-May/263332.html
and
http://ffmpeg.org/pipermail/ffmpeg-devel/2020-May/26.html

Is anything more required? 
[Context: this is my first patch set to ffmpeg, and I'm still trying to 
understand the conventions]

Brad


___
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] Don't update start time when lastpts is AV_NOPTS_VALUE.

2020-05-30 Thread Michael Niedermayer
On Fri, May 29, 2020 at 11:59:48AM -0700, Dale Curtis wrote:
> Signed-off-by: Dale Curtis 
> ---
>  libavformat/oggparsetheora.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

>  oggparsetheora.c |2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> c5e2ce350d1880ff49bdcb3be8dbf0b01dd6df64  no_start_time_update_v0.patch
> From 23b5bb5441ffb060e9d449a1c1944b686ab1d6da Mon Sep 17 00:00:00 2001
> From: Dale Curtis 
> Date: Fri, 15 May 2020 12:37:02 -0700
> Subject: [PATCH] Don't update start time when lastpts is AV_NOPTS_VALUE.

will apply

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Democracy is the form of government in which you can choose your dictator


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 v2] avfilter/vf_lut3d: prelut support for 3d cinespace luts

2020-05-30 Thread Michael Niedermayer
On Sat, May 30, 2020 at 09:59:35AM +0200, Paul B Mahol wrote:
> LGTM

will apply

thx

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

Many things microsoft did are stupid, but not doing something just because
microsoft did it is even more stupid. If everything ms did were stupid they
would be bankrupt already.


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 v6 1/1] avformat: add kvag muxer

2020-05-30 Thread Michael Niedermayer
On Sat, May 30, 2020 at 12:10:14AM +, Zane van Iperen wrote:
> On Fri, 29 May 2020 23:41:46 +0200
> "Michael Niedermayer"  wrote:
> 
> > 
> > On Fri, May 29, 2020 at 10:54:59AM +, Zane van Iperen wrote:
> > > Signed-off-by: Zane van Iperen 
> > > ---
> > >  Changelog|  1 +
> > >  libavformat/Makefile |  1 +
> > >  libavformat/allformats.c |  1 +
> > >  libavformat/kvag.c   | 82
> > > +++- libavformat/version.h|
> > >  2 +- 5 files changed, 85 insertions(+), 2 deletions(-)
> > 
> > should the muxer not be in its own file ?
> > that would avoid #if*
> > 
> Normally, I'd agree. However, it's a very simple format and there's not
> actually that much code, so I think separate files is overkill for this.

ok, will apply

thx

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

No great genius has ever existed without some touch of madness. -- Aristotle


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] avcodec/mv30: fix warning: suggest braces around initialization of subobject [-Wmissing-braces]

2020-05-30 Thread Nicolas George
Michael Niedermayer (12020-05-30):
> if these warnings are not fixed, then ideally they should be suppressed
> by some other means like compiler flags
> so they do not distract from real issues

That would be best. IIRC, the discussion arose when we considered adding
the braces but it actually depended on the system-dependant definition
of the structure. This warning is just bogus, ={0} is always valid.

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] avcodec/mv30: fix warning: suggest braces around initialization of subobject [-Wmissing-braces]

2020-05-30 Thread Michael Niedermayer
On Sat, May 30, 2020 at 01:34:03PM +0200, Nicolas George wrote:
> lance.lmw...@gmail.com (12020-05-30):
> > > -int pfill[3][1] = { 0 };
> > > +int pfill[3][1] = { {0} };
> 
> > will apply it tomorow if no objection.
> 
> This warning is bogus, the code is valid 

agree


> and a common pattern in FFmpeg.


> IIRC, we decided to keep it that way when it happens.

i do remember adding {} to these kind of cases so as to
eliminate the related warnings when i see one in code iam
working on at least

the reason why i tend to do that is so there are fewer meaningless
warnings, that way warnings pointing to real issues are easier to spot

if these warnings are not fixed, then ideally they should be suppressed
by some other means like compiler flags
so they do not distract from real issues

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Never trust a computer, one day, it may think you are the virus. -- Compn


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 17/36] avcodec/hevc_mp4toannexb_bsf: Check NAL size against available input

2020-05-30 Thread Michael Niedermayer
On Sat, May 30, 2020 at 06:05:22PM +0200, Andreas Rheinhardt wrote:
> The hevc_mp4toannexb bsf does not explicitly check whether a NAL unit
> is so big that it extends beyond the end of the input packet; it does so
> only implicitly by using the checked version of the bytestream2 API.
> But this has downsides compared to real checks: It can lead to huge
> allocations (up to 2GiB) even when the input packet is just a few bytes.
> And furthermore it leads to uninitialized data being output.
> So add a check to error out early if it happens.
> 
> Also check directly whether there is enough data for the length field.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/hevc_mp4toannexb_bsf.c | 6 +-
>  1 file changed, 5 insertions(+), 1 deletion(-)

probably ok

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

"Nothing to hide" only works if the folks in power share the values of
you and everyone you know entirely and always will -- Tom Scott



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] hwcontext_vulkan: fix make checkheaders fail

2020-05-30 Thread Lynne
May 30, 2020, 14:16 by mypopy...@gmail.com:

> From: Jun Zhao 
>
> make checkheaders will get error as follow:
> CClibavutil/hwcontext_vulkan.h.o
> In file included from libavutil/hwcontext_vulkan.h.c:1:
> ./libavutil/hwcontext_vulkan.h:130:23: error: ‘AV_NUM_DATA_POINTERS’ 
> undeclared here (not in a function)
>  130 | void *alloc_pnext[AV_NUM_DATA_POINTERS];
>  |   ^~~~
> ./libavutil/hwcontext_vulkan.h:199:43: warning: ‘enum AVPixelFormat’ declared 
> inside parameter list will not be visible outside of this definition or 
> declaration
>
> Signed-off-by: Jun Zhao 
> ---
>  libavutil/hwcontext_vulkan.h | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/libavutil/hwcontext_vulkan.h b/libavutil/hwcontext_vulkan.h
> index aba9833..0f6a51f 100644
> --- a/libavutil/hwcontext_vulkan.h
> +++ b/libavutil/hwcontext_vulkan.h
> @@ -21,6 +21,8 @@
>  
>  #include 
>  
> +#include "libavutil/frame.h"
> +
>  /**
>  * @file
>  * API-specific header for AV_HWDEVICE_TYPE_VULKAN.
> -- 
> 2.7.4
>

LGTM, tnx.

___
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 33/36] avcodec/dump_extradata_bsf: Store pointer for access

2020-05-30 Thread James Almer
On 5/30/2020 1:05 PM, Andreas Rheinhardt wrote:
> Using par->extradata instead of ctx->par_in->extradata makes the code
> more readable and removes an overlong line.
> 
> Furthermore, check for extradata_size instead of for the existence of
> extradata as nothing needs to be done in case extradata_size is zero.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/dump_extradata_bsf.c | 15 ---
>  1 file changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/libavcodec/dump_extradata_bsf.c b/libavcodec/dump_extradata_bsf.c
> index b6ef8b3e6b..be5e23ba5b 100644
> --- a/libavcodec/dump_extradata_bsf.c
> +++ b/libavcodec/dump_extradata_bsf.c
> @@ -40,6 +40,7 @@ typedef struct DumpExtradataContext {
>  static int dump_extradata(AVBSFContext *ctx, AVPacket *out)
>  {
>  DumpExtradataContext *s = ctx->priv_data;
> +const AVCodecParameters *par;
>  AVPacket *in = >pkt;
>  int ret = 0;
>  
> @@ -47,17 +48,17 @@ static int dump_extradata(AVBSFContext *ctx, AVPacket 
> *out)
>  if (ret < 0)
>  return ret;
>  
> -if (ctx->par_in->extradata &&
> +if ((par = ctx->par_in)->extradata_size &&

Put the assignment in its own line, please. Saving one line is not worth
making the code less readable.

>  (s->freq == DUMP_FREQ_ALL ||
>   (s->freq == DUMP_FREQ_KEYFRAME && in->flags & AV_PKT_FLAG_KEY)) &&
> - (in->size < ctx->par_in->extradata_size ||
> -  memcmp(in->data, ctx->par_in->extradata, 
> ctx->par_in->extradata_size))) {
> -if (in->size >= INT_MAX - ctx->par_in->extradata_size) {
> + (in->size < par->extradata_size ||
> +  memcmp(in->data, par->extradata, par->extradata_size))) {
> +if (in->size >= INT_MAX - par->extradata_size) {
>  ret = AVERROR(ERANGE);
>  goto fail;
>  }
>  
> -ret = av_new_packet(out, in->size + ctx->par_in->extradata_size);
> +ret = av_new_packet(out, in->size + par->extradata_size);
>  if (ret < 0)
>  goto fail;
>  
> @@ -67,8 +68,8 @@ static int dump_extradata(AVBSFContext *ctx, AVPacket *out)
>  goto fail;
>  }
>  
> -memcpy(out->data, ctx->par_in->extradata, 
> ctx->par_in->extradata_size);
> -memcpy(out->data + ctx->par_in->extradata_size, in->data, in->size);
> +memcpy(out->data, par->extradata, par->extradata_size);
> +memcpy(out->data + par->extradata_size, in->data, in->size);
>  } else {
>  av_packet_move_ref(out, in);
>  }
> 

___
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 35/36] avcodec/vp9_superframe_bsf: Only store what is needed later

2020-05-30 Thread James Almer
On 5/30/2020 1:05 PM, Andreas Rheinhardt wrote:
> This commit ends storing all the packets for later use. Instead the only
> part that is actually needed later is kept: The buffer. This avoids
> copies of packet structures and also makes the init function
> superfluous.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/vp9_superframe_bsf.c | 45 +
>  1 file changed, 17 insertions(+), 28 deletions(-)
> 
> diff --git a/libavcodec/vp9_superframe_bsf.c b/libavcodec/vp9_superframe_bsf.c
> index 29d1c759c7..6d6b2c57de 100644
> --- a/libavcodec/vp9_superframe_bsf.c
> +++ b/libavcodec/vp9_superframe_bsf.c
> @@ -27,8 +27,8 @@
>  
>  #define MAX_CACHE 8
>  typedef struct VP9BSFContext {
> +AVBufferRef *cache[MAX_CACHE];
>  int n_cache;
> -AVPacket *cache[MAX_CACHE];
>  } VP9BSFContext;
>  
>  static void vp9_superframe_flush(AVBSFContext *ctx)
> @@ -37,11 +37,11 @@ static void vp9_superframe_flush(AVBSFContext *ctx)
>  
>  // unref cached data
>  for (int n = 0; n < s->n_cache; n++)
> -av_packet_unref(s->cache[n]);
> +av_buffer_unref(>cache[n]);
>  s->n_cache = 0;
>  }
>  
> -static void stats(AVPacket * const *in, int n_in,
> +static void stats(AVBufferRef * const *in, int n_in,
>unsigned *_max, uint64_t *_sum)
>  {
>  int n;
> @@ -60,10 +60,11 @@ static void stats(AVPacket * const *in, int n_in,
>  *_sum = sum;
>  }
>  
> -static int merge_superframe(AVPacket * const *in, int n_in, AVPacket *out)
> +static int merge_superframe(AVBufferRef * const *in, int n_in, AVPacket *pkt)
>  {
>  unsigned max, mag, marker, n;
>  uint64_t sum;
> +AVBufferRef *out = NULL;
>  uint8_t *ptr;
>  int res;
>  
> @@ -73,7 +74,7 @@ static int merge_superframe(AVPacket * const *in, int n_in, 
> AVPacket *out)
>  sum += 2 + (mag + 1) * n_in;
>  if (sum > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
>  return AVERROR(ERANGE);
> -res = av_new_packet(out, sum);
> +res = ff_buffer_padded_realloc(, sum);
>  if (res < 0)
>  return res;
>  ptr = out->data;
> @@ -107,7 +108,9 @@ static int merge_superframe(AVPacket * const *in, int 
> n_in, AVPacket *out)
>  break;
>  }
>  *ptr++ = marker;
> -av_assert0(ptr == >data[out->size]);
> +
> +ff_packet_replace_buffer(pkt, out);
> +av_assert0(ptr == >data[pkt->size]);
>  
>  return 0;
>  }
> @@ -166,19 +169,21 @@ static int vp9_superframe_filter(AVBSFContext *ctx, 
> AVPacket *pkt)
>  
>  av_assert0(s->n_cache < MAX_CACHE);
>  
> -av_packet_move_ref(s->cache[s->n_cache++], pkt);
> +// move the packet's buffer into the cache
> +pkt->buf->data = pkt->data;
> +pkt->buf->size = pkt->size;

Manual manipulation of an AVBufferRef like this seems awfully hacky.

> +s->cache[s->n_cache++] = pkt->buf;
> +pkt->buf = NULL;
>  
>  if (invisible) {
> -return AVERROR(EAGAIN);
> +res = AVERROR(EAGAIN);
> +goto done;
>  }
>  av_assert0(s->n_cache > 0);
>  
>  // build superframe
>  res = merge_superframe(s->cache, s->n_cache, pkt);
>  
> -if (res >= 0)
> -res = av_packet_copy_props(pkt, s->cache[s->n_cache - 1]);
> -
>  vp9_superframe_flush(ctx);
>  
>  done:
> @@ -187,21 +192,6 @@ done:
>  return res;
>  }
>  
> -static int vp9_superframe_init(AVBSFContext *ctx)
> -{
> -VP9BSFContext *s = ctx->priv_data;
> -int n;
> -
> -// alloc cache packets
> -for (n = 0; n < MAX_CACHE; n++) {
> -s->cache[n] = av_packet_alloc();
> -if (!s->cache[n])
> -return AVERROR(ENOMEM);
> -}
> -
> -return 0;
> -}
> -
>  static void vp9_superframe_close(AVBSFContext *ctx)
>  {
>  VP9BSFContext *s = ctx->priv_data;
> @@ -209,7 +199,7 @@ static void vp9_superframe_close(AVBSFContext *ctx)
>  
>  // free cached data
>  for (n = 0; n < MAX_CACHE; n++)
> -av_packet_free(>cache[n]);
> +av_buffer_unref(>cache[n]);
>  }
>  
>  static const enum AVCodecID codec_ids[] = {
> @@ -220,7 +210,6 @@ const AVBitStreamFilter ff_vp9_superframe_bsf = {
>  .name   = "vp9_superframe",
>  .priv_data_size = sizeof(VP9BSFContext),
>  .filter = vp9_superframe_filter,
> -.init   = vp9_superframe_init,
>  .flush  = vp9_superframe_flush,
>  .close  = vp9_superframe_close,
>  .codec_ids  = codec_ids,
> 

___
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 23/36] avcodec/utils: Add utility functions for bsf

2020-05-30 Thread James Almer
On 5/30/2020 1:05 PM, Andreas Rheinhardt wrote:
> Several bitstream filters (e.g. dump_extradata, imxdump, mjpeg2jpeg,
> mjpegadump, mp3decomp, ...) don't buffer packets; instead, they just
> modify the buffer of one packet and don't change any other of the
> packet's non-buffer properties. The usual approach of these bitstream
> filters is to use separate packets for in- and output as follows:
> 
> 1. Get the input packet via ff_bsf_get_packet() which entails an allocation.
> 2. Use av_new_packet() to allocate a big enough buffer in the output
> packet.
> 3. Perform the actual work of the bitstream filter, i.e. fill the output
> buffer.
> 4. Use av_packet_copy_props() to copy the non-buffer fields of the input
> packet to the output packet.
> 5. Free the input packet and return.
> 
> This commit adds two utility functions that allow a different approach:
> A function to (re)allocate a refcounted buffer with zeroed padding and a
> function to replace a packet's buffer and the buffer-related fields with
> information from an AVBufferRef. This allows to modify the bitstream
> filters as follows:
> 
> 1. Get the packet via ff_bsf_get_packet_ref().
> 2. Use ff_buffer_padded_realloc() to get a big enough refcounted buffer.
> 3. Perform the actual work of the bitstream filter.
> 4. Use ff_packet_replace_buffer() to replace the old data in the packet
> with the modified one and return.
> 
> The first of these functions is just packet_alloc() from avpacket.c which
> has been made non-static.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
> An earlier version put the declarations to internal.h, but James
> suggested putting them into bsf_internal.h (or actually, into bsf.h
> because bsf_internal.h didn't exist back then), so I went with this.

I don't quite recall this, but in any case, ff_buffer_padded_realloc()
should be in internal.h or some other header since it's not bsf specific
and the function moved to utils.c next to the likes of
av_fast_padded_malloc(), and ff_packet_replace_buffer() should, if
applied (see my comments below), be in a new packet_internal.h header
instead, for the same reason.

See the patch i just sent.

> 
> There is currently no user that actually makes use of the reallocation
> feature; it was initially thought for hevc_mp4toannexb, but then I
> decided to make it no longer reallocate the output buffer at all any
> more. But I kept this functionality. Might be useful some day.
> 
>  libavcodec/avpacket.c | 21 -
>  libavcodec/bsf_internal.h | 27 +++
>  2 files changed, 43 insertions(+), 5 deletions(-)
> 
> diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> index 033f2d8f26..c8f3b0cf7a 100644
> --- a/libavcodec/avpacket.c
> +++ b/libavcodec/avpacket.c
> @@ -27,6 +27,7 @@
>  #include "libavutil/mathematics.h"
>  #include "libavutil/mem.h"
>  
> +#include "bsf_internal.h"
>  #include "bytestream.h"
>  #include "internal.h"
>  #include "packet.h"
> @@ -69,7 +70,7 @@ void av_packet_free(AVPacket **pkt)
>  av_freep(pkt);
>  }
>  
> -static int packet_alloc(AVBufferRef **buf, int size)
> +int ff_buffer_padded_realloc(AVBufferRef **buf, int size)
>  {
>  int ret;
>  if (size < 0 || size >= INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
> @@ -87,7 +88,7 @@ static int packet_alloc(AVBufferRef **buf, int size)
>  int av_new_packet(AVPacket *pkt, int size)
>  {
>  AVBufferRef *buf = NULL;
> -int ret = packet_alloc(, size);
> +int ret = ff_buffer_padded_realloc(, size);
>  if (ret < 0)
>  return ret;
>  
> @@ -621,7 +622,7 @@ int av_packet_ref(AVPacket *dst, const AVPacket *src)
>  goto fail;
>  
>  if (!src->buf) {
> -ret = packet_alloc(>buf, src->size);
> +ret = ff_buffer_padded_realloc(>buf, src->size);
>  if (ret < 0)
>  goto fail;
>  av_assert1(!src->size || src->data);
> @@ -674,7 +675,7 @@ int av_packet_make_refcounted(AVPacket *pkt)
>  if (pkt->buf)
>  return 0;
>  
> -ret = packet_alloc(>buf, pkt->size);
> +ret = ff_buffer_padded_realloc(>buf, pkt->size);
>  if (ret < 0)
>  return ret;
>  av_assert1(!pkt->size || pkt->data);
> @@ -694,7 +695,7 @@ int av_packet_make_writable(AVPacket *pkt)
>  if (pkt->buf && av_buffer_is_writable(pkt->buf))
>  return 0;
>  
> -ret = packet_alloc(, pkt->size);
> +ret = ff_buffer_padded_realloc(, pkt->size);
>  if (ret < 0)
>  return ret;
>  av_assert1(!pkt->size || pkt->data);
> @@ -770,3 +771,13 @@ int ff_side_data_set_prft(AVPacket *pkt, int64_t 
> timestamp)
>  
>  return 0;
>  }
> +
> +void ff_packet_replace_buffer(AVPacket *pkt, AVBufferRef *buf)
> +{
> +av_buffer_unref(>buf);
> +
> +pkt->buf  = buf;
> +pkt->data = buf->data;
> +av_assert1(buf->size >= AV_INPUT_BUFFER_PADDING_SIZE);
> +pkt->size = buf->size - AV_INPUT_BUFFER_PADDING_SIZE;
> +}

This function as is doesn't really seem too useful to me. It for example

[FFmpeg-devel] [PATCH] avcodec/internal: move packet related functions to their own header

2020-05-30 Thread James Almer
Signed-off-by: James Almer 
---
I included the new header directly in internal.h because the alternative was
including it in a hundred  or so files that call ff_alloc_packet2().

If that's nonetheless prefered, i can go ahead with it.

 libavcodec/internal.h| 35 +---
 libavcodec/packet_internal.h | 63 
 2 files changed, 64 insertions(+), 34 deletions(-)
 create mode 100644 libavcodec/packet_internal.h

diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 0e3415d69b..fa5052723b 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -32,6 +32,7 @@
 #include "libavutil/pixfmt.h"
 #include "avcodec.h"
 #include "config.h"
+#include "packet_internal.h"
 
 /**
  * The codec does not modify any global variables in the init function,
@@ -222,36 +223,6 @@ void ff_color_frame(AVFrame *frame, const int color[4]);
  */
 #define FF_MAX_EXTRADATA_SIZE ((1 << 28) - AV_INPUT_BUFFER_PADDING_SIZE)
 
-/**
- * Check AVPacket size and/or allocate data.
- *
- * Encoders supporting AVCodec.encode2() can use this as a convenience to
- * ensure the output packet data is large enough, whether provided by the user
- * or allocated in this function.
- *
- * @param avctx   the AVCodecContext of the encoder
- * @param avpkt   the AVPacket
- *If avpkt->data is already set, avpkt->size is checked
- *to ensure it is large enough.
- *If avpkt->data is NULL, a new buffer is allocated.
- *avpkt->size is set to the specified size.
- *All other AVPacket fields will be reset with 
av_init_packet().
- * @param sizethe minimum required packet size
- * @param min_size This is a hint to the allocation algorithm, which indicates
- *to what minimal size the caller might later shrink the packet
- *to. Encoders often allocate packets which are larger than the
- *amount of data that is written into them as the exact amount 
is
- *not known at the time of allocation. min_size represents the
- *size a packet might be shrunk to by the caller. Can be set to
- *0. setting this roughly correctly allows the allocation code
- *to choose between several allocation strategies to improve
- *speed slightly.
- * @returnnon negative on success, negative error code on failure
- */
-int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, 
int64_t min_size);
-
-attribute_deprecated int ff_alloc_packet(AVPacket *avpkt, int size);
-
 /**
  * Rescale from sample rate to AVCodecContext.time_base.
  */
@@ -360,10 +331,6 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame 
*frame);
  */
 AVCPBProperties *ff_add_cpb_side_data(AVCodecContext *avctx);
 
-int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, 
int error_count, int pict_type);
-
-int ff_side_data_set_prft(AVPacket *pkt, int64_t timestamp);
-
 /**
  * Check AVFrame for A53 side data and allocate and fill SEI message with A53 
info
  *
diff --git a/libavcodec/packet_internal.h b/libavcodec/packet_internal.h
new file mode 100644
index 00..6d48f7f528
--- /dev/null
+++ b/libavcodec/packet_internal.h
@@ -0,0 +1,63 @@
+/*
+ * 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
+ */
+
+#ifndef AVCODEC_PACKET_INTERNAL_H
+#define AVCODEC_PACKET_INTERNAL_H
+
+#include 
+
+#include "libavutil/attributes.h"
+
+#include "avcodec.h"
+#include "packet.h"
+
+/**
+ * Check AVPacket size and/or allocate data.
+ *
+ * Encoders supporting AVCodec.encode2() can use this as a convenience to
+ * ensure the output packet data is large enough, whether provided by the user
+ * or allocated in this function.
+ *
+ * @param avctx   the AVCodecContext of the encoder
+ * @param avpkt   the AVPacket
+ *If avpkt->data is already set, avpkt->size is checked
+ *to ensure it is large enough.
+ *If avpkt->data is NULL, a new buffer is allocated.
+ *avpkt->size is set to the specified size.
+ *All other AVPacket fields will be reset with 
av_init_packet().
+ * @param sizethe minimum required packet size
+ * 

Re: [FFmpeg-devel] [PATCH] avcodec/hq_hqa: Check info size

2020-05-30 Thread Michael Niedermayer
On Sat, May 30, 2020 at 02:09:42AM +0200, Hendrik Leppkes wrote:
> On Sat, May 30, 2020 at 2:01 AM Michael Niedermayer
>  wrote:
> >
> > Fixes: assertion failure
> > Fixes: 
> > 21079/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_HQ_HQA_fuzzer-5737046523248640
> >
> > Found-by: continuous fuzzing process 
> > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer 
> > ---
> >  libavcodec/hq_hqa.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/hq_hqa.c b/libavcodec/hq_hqa.c
> > index eec2e980b3..8404e80ec8 100644
> > --- a/libavcodec/hq_hqa.c
> > +++ b/libavcodec/hq_hqa.c
> > @@ -321,7 +321,7 @@ static int hq_hqa_decode_frame(AVCodecContext *avctx, 
> > void *data,
> >  int info_size;
> >  bytestream2_skip(>gbc, 4);
> >  info_size = bytestream2_get_le32(>gbc);
> > -if (bytestream2_get_bytes_left(>gbc) < info_size) {
> > +if (info_size < 0 || bytestream2_get_bytes_left(>gbc) < 
> > info_size) {
> >  av_log(avctx, AV_LOG_ERROR, "Invalid INFO size (%d).\n", 
> > info_size);
> >  return AVERROR_INVALIDDATA;
> >  }
> > --
> 
> bytestream2_get_le32 returns an unsigned type, wouldn't it be better
> to make info_size unsigned and avoid the type cast and signed overflow
> that results in this check failing?

The value is ultimatly passed into bytestream2_init()
where its in int so it cannot be beyond the positive signed int range

thx

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

No great genius has ever existed without some touch of madness. -- Aristotle


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 33/36] avcodec/dump_extradata_bsf: Store pointer for access

2020-05-30 Thread Andreas Rheinhardt
Using par->extradata instead of ctx->par_in->extradata makes the code
more readable and removes an overlong line.

Furthermore, check for extradata_size instead of for the existence of
extradata as nothing needs to be done in case extradata_size is zero.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/dump_extradata_bsf.c | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/libavcodec/dump_extradata_bsf.c b/libavcodec/dump_extradata_bsf.c
index b6ef8b3e6b..be5e23ba5b 100644
--- a/libavcodec/dump_extradata_bsf.c
+++ b/libavcodec/dump_extradata_bsf.c
@@ -40,6 +40,7 @@ typedef struct DumpExtradataContext {
 static int dump_extradata(AVBSFContext *ctx, AVPacket *out)
 {
 DumpExtradataContext *s = ctx->priv_data;
+const AVCodecParameters *par;
 AVPacket *in = >pkt;
 int ret = 0;
 
@@ -47,17 +48,17 @@ static int dump_extradata(AVBSFContext *ctx, AVPacket *out)
 if (ret < 0)
 return ret;
 
-if (ctx->par_in->extradata &&
+if ((par = ctx->par_in)->extradata_size &&
 (s->freq == DUMP_FREQ_ALL ||
  (s->freq == DUMP_FREQ_KEYFRAME && in->flags & AV_PKT_FLAG_KEY)) &&
- (in->size < ctx->par_in->extradata_size ||
-  memcmp(in->data, ctx->par_in->extradata, 
ctx->par_in->extradata_size))) {
-if (in->size >= INT_MAX - ctx->par_in->extradata_size) {
+ (in->size < par->extradata_size ||
+  memcmp(in->data, par->extradata, par->extradata_size))) {
+if (in->size >= INT_MAX - par->extradata_size) {
 ret = AVERROR(ERANGE);
 goto fail;
 }
 
-ret = av_new_packet(out, in->size + ctx->par_in->extradata_size);
+ret = av_new_packet(out, in->size + par->extradata_size);
 if (ret < 0)
 goto fail;
 
@@ -67,8 +68,8 @@ static int dump_extradata(AVBSFContext *ctx, AVPacket *out)
 goto fail;
 }
 
-memcpy(out->data, ctx->par_in->extradata, ctx->par_in->extradata_size);
-memcpy(out->data + ctx->par_in->extradata_size, in->data, in->size);
+memcpy(out->data, par->extradata, par->extradata_size);
+memcpy(out->data + par->extradata_size, in->data, in->size);
 } else {
 av_packet_move_ref(out, in);
 }
-- 
2.20.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 36/36] avcodec/vp9_superframe_bsf: Merge close and flush

2020-05-30 Thread Andreas Rheinhardt
They are essentially identical now.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/vp9_superframe_bsf.c | 18 --
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/libavcodec/vp9_superframe_bsf.c b/libavcodec/vp9_superframe_bsf.c
index 6d6b2c57de..278f5a47a6 100644
--- a/libavcodec/vp9_superframe_bsf.c
+++ b/libavcodec/vp9_superframe_bsf.c
@@ -31,7 +31,7 @@ typedef struct VP9BSFContext {
 int n_cache;
 } VP9BSFContext;
 
-static void vp9_superframe_flush(AVBSFContext *ctx)
+static void vp9_superframe_close_flush(AVBSFContext *ctx)
 {
 VP9BSFContext *s = ctx->priv_data;
 
@@ -184,7 +184,7 @@ static int vp9_superframe_filter(AVBSFContext *ctx, 
AVPacket *pkt)
 // build superframe
 res = merge_superframe(s->cache, s->n_cache, pkt);
 
-vp9_superframe_flush(ctx);
+vp9_superframe_close_flush(ctx);
 
 done:
 if (res < 0)
@@ -192,16 +192,6 @@ done:
 return res;
 }
 
-static void vp9_superframe_close(AVBSFContext *ctx)
-{
-VP9BSFContext *s = ctx->priv_data;
-int n;
-
-// free cached data
-for (n = 0; n < MAX_CACHE; n++)
-av_buffer_unref(>cache[n]);
-}
-
 static const enum AVCodecID codec_ids[] = {
 AV_CODEC_ID_VP9, AV_CODEC_ID_NONE,
 };
@@ -210,7 +200,7 @@ const AVBitStreamFilter ff_vp9_superframe_bsf = {
 .name   = "vp9_superframe",
 .priv_data_size = sizeof(VP9BSFContext),
 .filter = vp9_superframe_filter,
-.flush  = vp9_superframe_flush,
-.close  = vp9_superframe_close,
+.flush  = vp9_superframe_close_flush,
+.close  = vp9_superframe_close_flush,
 .codec_ids  = codec_ids,
 };
-- 
2.20.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 34/36] avcodec/dump_extradata_bsf: Remove intermediate packet

2020-05-30 Thread Andreas Rheinhardt
This commit ends using separate packets for in- and output. Instead,
the input is read directly into the packet destined for output via
ff_bsf_get_packet_ref() and only the buffer-related fields are modified;
the others are not touched.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/dump_extradata_bsf.c | 33 ++---
 1 file changed, 14 insertions(+), 19 deletions(-)

diff --git a/libavcodec/dump_extradata_bsf.c b/libavcodec/dump_extradata_bsf.c
index be5e23ba5b..5df7e064cf 100644
--- a/libavcodec/dump_extradata_bsf.c
+++ b/libavcodec/dump_extradata_bsf.c
@@ -33,49 +33,44 @@ enum DumpFreq {
 
 typedef struct DumpExtradataContext {
 const AVClass *class;
-AVPacket pkt;
 int freq;
 } DumpExtradataContext;
 
-static int dump_extradata(AVBSFContext *ctx, AVPacket *out)
+static int dump_extradata(AVBSFContext *ctx, AVPacket *pkt)
 {
 DumpExtradataContext *s = ctx->priv_data;
 const AVCodecParameters *par;
-AVPacket *in = >pkt;
 int ret = 0;
 
-ret = ff_bsf_get_packet_ref(ctx, in);
+ret = ff_bsf_get_packet_ref(ctx, pkt);
 if (ret < 0)
 return ret;
 
 if ((par = ctx->par_in)->extradata_size &&
 (s->freq == DUMP_FREQ_ALL ||
- (s->freq == DUMP_FREQ_KEYFRAME && in->flags & AV_PKT_FLAG_KEY)) &&
- (in->size < par->extradata_size ||
-  memcmp(in->data, par->extradata, par->extradata_size))) {
-if (in->size >= INT_MAX - par->extradata_size) {
+ (s->freq == DUMP_FREQ_KEYFRAME && pkt->flags & AV_PKT_FLAG_KEY)) &&
+ (pkt->size < par->extradata_size ||
+  memcmp(pkt->data, par->extradata, par->extradata_size))) {
+AVBufferRef *out = NULL;
+
+if (pkt->size >= INT_MAX - par->extradata_size) {
 ret = AVERROR(ERANGE);
 goto fail;
 }
 
-ret = av_new_packet(out, in->size + par->extradata_size);
+ret = ff_buffer_padded_realloc(, pkt->size + par->extradata_size);
 if (ret < 0)
 goto fail;
 
-ret = av_packet_copy_props(out, in);
-if (ret < 0) {
-av_packet_unref(out);
-goto fail;
-}
-
 memcpy(out->data, par->extradata, par->extradata_size);
-memcpy(out->data + par->extradata_size, in->data, in->size);
-} else {
-av_packet_move_ref(out, in);
+memcpy(out->data + par->extradata_size, pkt->data, pkt->size);
+
+ff_packet_replace_buffer(pkt, out);
 }
 
 fail:
-av_packet_unref(in);
+if (ret < 0)
+av_packet_unref(pkt);
 
 return ret;
 }
-- 
2.20.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 35/36] avcodec/vp9_superframe_bsf: Only store what is needed later

2020-05-30 Thread Andreas Rheinhardt
This commit ends storing all the packets for later use. Instead the only
part that is actually needed later is kept: The buffer. This avoids
copies of packet structures and also makes the init function
superfluous.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/vp9_superframe_bsf.c | 45 +
 1 file changed, 17 insertions(+), 28 deletions(-)

diff --git a/libavcodec/vp9_superframe_bsf.c b/libavcodec/vp9_superframe_bsf.c
index 29d1c759c7..6d6b2c57de 100644
--- a/libavcodec/vp9_superframe_bsf.c
+++ b/libavcodec/vp9_superframe_bsf.c
@@ -27,8 +27,8 @@
 
 #define MAX_CACHE 8
 typedef struct VP9BSFContext {
+AVBufferRef *cache[MAX_CACHE];
 int n_cache;
-AVPacket *cache[MAX_CACHE];
 } VP9BSFContext;
 
 static void vp9_superframe_flush(AVBSFContext *ctx)
@@ -37,11 +37,11 @@ static void vp9_superframe_flush(AVBSFContext *ctx)
 
 // unref cached data
 for (int n = 0; n < s->n_cache; n++)
-av_packet_unref(s->cache[n]);
+av_buffer_unref(>cache[n]);
 s->n_cache = 0;
 }
 
-static void stats(AVPacket * const *in, int n_in,
+static void stats(AVBufferRef * const *in, int n_in,
   unsigned *_max, uint64_t *_sum)
 {
 int n;
@@ -60,10 +60,11 @@ static void stats(AVPacket * const *in, int n_in,
 *_sum = sum;
 }
 
-static int merge_superframe(AVPacket * const *in, int n_in, AVPacket *out)
+static int merge_superframe(AVBufferRef * const *in, int n_in, AVPacket *pkt)
 {
 unsigned max, mag, marker, n;
 uint64_t sum;
+AVBufferRef *out = NULL;
 uint8_t *ptr;
 int res;
 
@@ -73,7 +74,7 @@ static int merge_superframe(AVPacket * const *in, int n_in, 
AVPacket *out)
 sum += 2 + (mag + 1) * n_in;
 if (sum > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
 return AVERROR(ERANGE);
-res = av_new_packet(out, sum);
+res = ff_buffer_padded_realloc(, sum);
 if (res < 0)
 return res;
 ptr = out->data;
@@ -107,7 +108,9 @@ static int merge_superframe(AVPacket * const *in, int n_in, 
AVPacket *out)
 break;
 }
 *ptr++ = marker;
-av_assert0(ptr == >data[out->size]);
+
+ff_packet_replace_buffer(pkt, out);
+av_assert0(ptr == >data[pkt->size]);
 
 return 0;
 }
@@ -166,19 +169,21 @@ static int vp9_superframe_filter(AVBSFContext *ctx, 
AVPacket *pkt)
 
 av_assert0(s->n_cache < MAX_CACHE);
 
-av_packet_move_ref(s->cache[s->n_cache++], pkt);
+// move the packet's buffer into the cache
+pkt->buf->data = pkt->data;
+pkt->buf->size = pkt->size;
+s->cache[s->n_cache++] = pkt->buf;
+pkt->buf = NULL;
 
 if (invisible) {
-return AVERROR(EAGAIN);
+res = AVERROR(EAGAIN);
+goto done;
 }
 av_assert0(s->n_cache > 0);
 
 // build superframe
 res = merge_superframe(s->cache, s->n_cache, pkt);
 
-if (res >= 0)
-res = av_packet_copy_props(pkt, s->cache[s->n_cache - 1]);
-
 vp9_superframe_flush(ctx);
 
 done:
@@ -187,21 +192,6 @@ done:
 return res;
 }
 
-static int vp9_superframe_init(AVBSFContext *ctx)
-{
-VP9BSFContext *s = ctx->priv_data;
-int n;
-
-// alloc cache packets
-for (n = 0; n < MAX_CACHE; n++) {
-s->cache[n] = av_packet_alloc();
-if (!s->cache[n])
-return AVERROR(ENOMEM);
-}
-
-return 0;
-}
-
 static void vp9_superframe_close(AVBSFContext *ctx)
 {
 VP9BSFContext *s = ctx->priv_data;
@@ -209,7 +199,7 @@ static void vp9_superframe_close(AVBSFContext *ctx)
 
 // free cached data
 for (n = 0; n < MAX_CACHE; n++)
-av_packet_free(>cache[n]);
+av_buffer_unref(>cache[n]);
 }
 
 static const enum AVCodecID codec_ids[] = {
@@ -220,7 +210,6 @@ const AVBitStreamFilter ff_vp9_superframe_bsf = {
 .name   = "vp9_superframe",
 .priv_data_size = sizeof(VP9BSFContext),
 .filter = vp9_superframe_filter,
-.init   = vp9_superframe_init,
 .flush  = vp9_superframe_flush,
 .close  = vp9_superframe_close,
 .codec_ids  = codec_ids,
-- 
2.20.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 31/36] avcodec/mjpeg2jpeg_bsf: Remove intermediate packet

2020-05-30 Thread Andreas Rheinhardt
This commit ends using separate packets for in- and output. Instead,
the input is read directly into the packet destined for output via
ff_bsf_get_packet_ref() and only the buffer-related fields are modified;
the others are not touched.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mjpeg2jpeg_bsf.c | 29 +
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/libavcodec/mjpeg2jpeg_bsf.c b/libavcodec/mjpeg2jpeg_bsf.c
index b30f391bf9..dc729cfd95 100644
--- a/libavcodec/mjpeg2jpeg_bsf.c
+++ b/libavcodec/mjpeg2jpeg_bsf.c
@@ -77,40 +77,40 @@ static uint8_t *append_dht_segment(uint8_t *buf)
 return buf;
 }
 
-static int mjpeg2jpeg_filter(AVBSFContext *ctx, AVPacket *out)
+static int mjpeg2jpeg_filter(AVBSFContext *ctx, AVPacket *pkt)
 {
-AVPacket *in;
+AVBufferRef *out = NULL;
 int ret = 0;
 int input_skip, output_size;
 uint8_t *output;
 
-ret = ff_bsf_get_packet(ctx, );
+ret = ff_bsf_get_packet_ref(ctx, pkt);
 if (ret < 0)
 return ret;
 
-if (in->size < 12) {
+if (pkt->size < 12) {
 av_log(ctx, AV_LOG_ERROR, "input is truncated\n");
 ret = AVERROR_INVALIDDATA;
 goto fail;
 }
-if (AV_RB16(in->data) != 0xffd8) {
+if (AV_RB16(pkt->data) != 0xffd8) {
 av_log(ctx, AV_LOG_ERROR, "input is not MJPEG\n");
 ret = AVERROR_INVALIDDATA;
 goto fail;
 }
-if (in->data[2] == 0xff && in->data[3] == APP0) {
-input_skip = (in->data[4] << 8) + in->data[5] + 4;
+if (pkt->data[2] == 0xff && pkt->data[3] == APP0) {
+input_skip = AV_RB16(pkt->data + 4) + 4;
 } else {
 input_skip = 2;
 }
-if (in->size < input_skip) {
+if (pkt->size < input_skip) {
 av_log(ctx, AV_LOG_ERROR, "input is truncated\n");
 ret = AVERROR_INVALIDDATA;
 goto fail;
 }
-output_size = in->size - input_skip +
+output_size = pkt->size - input_skip +
   sizeof(jpeg_header) + dht_segment_size;
-ret = av_new_packet(out, output_size);
+ret = ff_buffer_padded_realloc(, output_size);
 if (ret < 0)
 goto fail;
 
@@ -118,16 +118,13 @@ static int mjpeg2jpeg_filter(AVBSFContext *ctx, AVPacket 
*out)
 
 output = append(output, jpeg_header, sizeof(jpeg_header));
 output = append_dht_segment(output);
-output = append(output, in->data + input_skip, in->size - input_skip);
+output = append(output, pkt->data + input_skip, pkt->size - input_skip);
 
-ret = av_packet_copy_props(out, in);
-if (ret < 0)
-goto fail;
+ff_packet_replace_buffer(pkt, out);
 
 fail:
 if (ret < 0)
-av_packet_unref(out);
-av_packet_free();
+av_packet_unref(pkt);
 return ret;
 }
 
-- 
2.20.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 29/36] avcodec/movsub_bsf: Remove intermediate packet

2020-05-30 Thread Andreas Rheinhardt
This commit ends using separate packets for in- and output. Instead,
the input is read directly into the packet destined for output via
ff_bsf_get_packet_ref() and only the buffer-related fields are modified;
the others are not touched.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/movsub_bsf.c | 22 +-
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/libavcodec/movsub_bsf.c b/libavcodec/movsub_bsf.c
index 6e29fa8e50..b5b714ce7e 100644
--- a/libavcodec/movsub_bsf.c
+++ b/libavcodec/movsub_bsf.c
@@ -23,37 +23,33 @@
 #include "bsf.h"
 #include "bsf_internal.h"
 
-static int text2movsub(AVBSFContext *ctx, AVPacket *out)
+static int text2movsub(AVBSFContext *ctx, AVPacket *pkt)
 {
-AVPacket *in;
+AVBufferRef *out = NULL;
 int ret = 0;
 
-ret = ff_bsf_get_packet(ctx, );
+ret = ff_bsf_get_packet_ref(ctx, pkt);
 if (ret < 0)
 return ret;
 
-if (in->size > 0x) {
+if (pkt->size > 0x) {
 ret = AVERROR_INVALIDDATA;
 goto fail;
 }
 
-ret = av_new_packet(out, in->size + 2);
+ret = ff_buffer_padded_realloc(, pkt->size + 2);
 if (ret < 0) {
-ret = AVERROR(ENOMEM);
 goto fail;
 }
 
-ret = av_packet_copy_props(out, in);
-if (ret < 0)
-goto fail;
+AV_WB16(out->data, pkt->size);
+memcpy(out->data + 2, pkt->data, pkt->size);
 
-AV_WB16(out->data, in->size);
-memcpy(out->data + 2, in->data, in->size);
+ff_packet_replace_buffer(pkt, out);
 
 fail:
 if (ret < 0)
-av_packet_unref(out);
-av_packet_free();
+av_packet_unref(pkt);
 return ret;
 }
 
-- 
2.20.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 32/36] avcodec/mp3_header_decompress_bsf: Remove intermediate packet

2020-05-30 Thread Andreas Rheinhardt
This commit ends using separate packets for in- and output. Instead,
the input is read directly into the packet destined for output via
ff_bsf_get_packet_ref() and only the buffer-related fields are modified;
the others are not touched.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mp3_header_decompress_bsf.c | 25 ++---
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/libavcodec/mp3_header_decompress_bsf.c 
b/libavcodec/mp3_header_decompress_bsf.c
index 3d357dd27e..29ab5721ef 100644
--- a/libavcodec/mp3_header_decompress_bsf.c
+++ b/libavcodec/mp3_header_decompress_bsf.c
@@ -26,28 +26,25 @@
 #include "mpegaudiodata.h"
 
 
-static int mp3_header_decompress(AVBSFContext *ctx, AVPacket *out)
+static int mp3_header_decompress(AVBSFContext *ctx, AVPacket *pkt)
 {
-AVPacket *in;
 uint32_t header;
 int sample_rate= ctx->par_in->sample_rate;
 int sample_rate_index=0;
 int lsf, mpeg25, bitrate_index, frame_size, offset, ret;
+AVBufferRef *out = NULL;
 const uint8_t *buf;
 int buf_size;
 
-ret = ff_bsf_get_packet(ctx, );
+ret = ff_bsf_get_packet_ref(ctx, pkt);
 if (ret < 0)
 return ret;
 
-buf  = in->data;
-buf_size = in->size;
+buf  = pkt->data;
+buf_size = pkt->size;
 
 header = AV_RB32(buf);
 if(ff_mpa_check_header(header) >= 0){
-av_packet_move_ref(out, in);
-av_packet_free();
-
 return 0;
 }
 
@@ -89,14 +86,9 @@ static int mp3_header_decompress(AVBSFContext *ctx, AVPacket 
*out)
 offset++;
 }
 
-ret = av_new_packet(out, frame_size);
+ret = ff_buffer_padded_realloc(, frame_size);
 if (ret < 0)
 goto fail;
-ret = av_packet_copy_props(out, in);
-if (ret < 0) {
-av_packet_unref(out);
-goto fail;
-}
 memcpy(out->data + offset, buf, buf_size);
 
 if(ctx->par_in->channels==2){
@@ -118,10 +110,13 @@ static int mp3_header_decompress(AVBSFContext *ctx, 
AVPacket *out)
 header |= 1 << 16; // protection_bit
 AV_WB32(out->data, header);
 
+ff_packet_replace_buffer(pkt, out);
+
 ret = 0;
 
 fail:
-av_packet_free();
+if (ret < 0)
+av_packet_unref(pkt);
 return ret;
 }
 
-- 
2.20.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 30/36] avcodec/imx_dump_header_bsf: Remove intermediate packet

2020-05-30 Thread Andreas Rheinhardt
This commit ends using separate packets for in- and output. Instead,
the input is read directly into the packet destined for output via
ff_bsf_get_packet_ref() and only the buffer-related fields are modified;
the others are not touched.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/imx_dump_header_bsf.c | 28 
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/libavcodec/imx_dump_header_bsf.c b/libavcodec/imx_dump_header_bsf.c
index e2b6a15591..95f8f31f66 100644
--- a/libavcodec/imx_dump_header_bsf.c
+++ b/libavcodec/imx_dump_header_bsf.c
@@ -30,39 +30,35 @@
 #include "bytestream.h"
 
 
-static int imx_dump_header(AVBSFContext *ctx, AVPacket *out)
+static int imx_dump_header(AVBSFContext *ctx, AVPacket *pkt)
 {
 /* MXF essence element key */
 static const uint8_t imx_header[16] = { 
0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01,0x05,0x01,0x01,0x00 
};
 
-AVPacket *in;
+AVBufferRef *out = NULL;
 int ret = 0;
 uint8_t *out_buf;
 
-ret = ff_bsf_get_packet(ctx, );
+ret = ff_bsf_get_packet_ref(ctx, pkt);
 if (ret < 0)
 return ret;
 
-ret = av_new_packet(out, in->size + 20);
-if (ret < 0)
-goto fail;
+ret = ff_buffer_padded_realloc(, pkt->size + 20U);
+if (ret < 0) {
+av_packet_unref(pkt);
+return ret;
+}
 
 out_buf = out->data;
 
 bytestream_put_buffer(_buf, imx_header, 16);
 bytestream_put_byte(_buf, 0x83); /* KLV BER long form */
-bytestream_put_be24(_buf, in->size);
-bytestream_put_buffer(_buf, in->data, in->size);
+bytestream_put_be24(_buf, pkt->size);
+bytestream_put_buffer(_buf, pkt->data, pkt->size);
 
-ret = av_packet_copy_props(out, in);
-if (ret < 0)
-goto fail;
+ff_packet_replace_buffer(pkt, out);
 
-fail:
-if (ret < 0)
-av_packet_unref(out);
-av_packet_free();
-return ret;
+return 0;
 }
 
 static const enum AVCodecID codec_ids[] = {
-- 
2.20.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 28/36] avcodec/mjpega_dump_header_bsf: Miscellaneous improvements

2020-05-30 Thread Andreas Rheinhardt
1. Instead of comparing two values read via AV_RL32 one can read both
via AV_RN32 and compare the values.
2. Errors like AVERROR(ENOMEM) from failed allocations are now always
forwarded.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mjpega_dump_header_bsf.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavcodec/mjpega_dump_header_bsf.c 
b/libavcodec/mjpega_dump_header_bsf.c
index 4ea55e88ba..98fd2f9250 100644
--- a/libavcodec/mjpega_dump_header_bsf.c
+++ b/libavcodec/mjpega_dump_header_bsf.c
@@ -77,7 +77,7 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket 
*pkt)
 return 0;
 }
 case APP1:
-if (i + 12U <= pkt->size && AV_RL32(pkt->data + i + 8) == 
AV_RL32("mjpg")) {
+if (i + 12U <= pkt->size && AV_RN32(pkt->data + i + 8) == 
AV_RN32("mjpg")) {
 av_log(ctx, AV_LOG_ERROR, "bitstream already formatted\n");
 return 0;
 }
@@ -85,9 +85,10 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket 
*pkt)
 }
 }
 av_log(ctx, AV_LOG_ERROR, "No valid SOS marker in bitstream\n");
+ret = AVERROR_INVALIDDATA;
 fail:
 av_packet_unref(pkt);
-return AVERROR_INVALIDDATA;
+return ret;
 }
 
 static const enum AVCodecID codec_ids[] = {
-- 
2.20.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 27/36] avcodec/mjpega_dump_header_bsf: Cosmetics

2020-05-30 Thread Andreas Rheinhardt
Reindentation; furthermore, the names of the out and out_buf variables
have been switched: The latter is now an AVBufferRef * whereas the
former is directly used for writing. And some variables have been put
into a smaller scope.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mjpega_dump_header_bsf.c | 50 ++---
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/libavcodec/mjpega_dump_header_bsf.c 
b/libavcodec/mjpega_dump_header_bsf.c
index 2d49b042ec..4ea55e88ba 100644
--- a/libavcodec/mjpega_dump_header_bsf.c
+++ b/libavcodec/mjpega_dump_header_bsf.c
@@ -33,15 +33,14 @@
 
 static int mjpega_dump_header(AVBSFContext *ctx, AVPacket *pkt)
 {
-uint8_t *out_buf;
 unsigned dqt = 0, dht = 0, sof0 = 0;
-int ret = 0, i;
+int ret;
 
 ret = ff_bsf_get_packet_ref(ctx, pkt);
 if (ret < 0)
 return ret;
 
-for (i = 0; i < pkt->size - 3; i++) {
+for (int i = 0; i < pkt->size - 3; i++) {
 if (pkt->data[i] == 0xff) {
 switch (pkt->data[i + 1]) {
 case DQT:  dqt  = i + 46U; break;
@@ -49,31 +48,32 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket 
*pkt)
 case SOF0: sof0 = i + 46U; break;
 case SOS:
 {
-AVBufferRef *out = NULL;
+AVBufferRef *out_buf = NULL;
+uint8_t *out;
 
-ret = ff_buffer_padded_realloc(, pkt->size + 44U);
-if (ret < 0)
-goto fail;
+ret = ff_buffer_padded_realloc(_buf, pkt->size + 44U);
+if (ret < 0)
+goto fail;
 
-out_buf = out->data;
-bytestream_put_byte(_buf, 0xff);
-bytestream_put_byte(_buf, SOI);
-bytestream_put_byte(_buf, 0xff);
-bytestream_put_byte(_buf, APP1);
-bytestream_put_be16(_buf, 42); /* size */
-bytestream_put_be32(_buf, 0);
-bytestream_put_buffer(_buf, "mjpg", 4);
-bytestream_put_be32(_buf, pkt->size + 44U); /* field size 
*/
-bytestream_put_be32(_buf, pkt->size + 44U); /* pad field 
size */
-bytestream_put_be32(_buf, 0); /* next ptr */
-bytestream_put_be32(_buf, dqt); /* quant off */
-bytestream_put_be32(_buf, dht); /* huff off */
-bytestream_put_be32(_buf, sof0); /* image off */
-bytestream_put_be32(_buf, i + 46U); /* scan off */
-bytestream_put_be32(_buf, i + 46U + AV_RB16(pkt->data + i 
+ 2)); /* data off */
-bytestream_put_buffer(_buf, pkt->data + 2, pkt->size - 2); 
/* skip already written SOI */
+out = out_buf->data;
+bytestream_put_byte(, 0xff);
+bytestream_put_byte(, SOI);
+bytestream_put_byte(, 0xff);
+bytestream_put_byte(, APP1);
+bytestream_put_be16(, 42);  /* size */
+bytestream_put_be32(, 0);
+bytestream_put_buffer(, "mjpg", 4);
+bytestream_put_be32(, pkt->size + 44U); /* field size */
+bytestream_put_be32(, pkt->size + 44U); /* pad field size 
*/
+bytestream_put_be32(, 0);   /* next ptr */
+bytestream_put_be32(, dqt); /* quant off */
+bytestream_put_be32(, dht); /* huff off */
+bytestream_put_be32(, sof0);/* image off */
+bytestream_put_be32(, i + 46U); /* scan off */
+bytestream_put_be32(, i + 46U + AV_RB16(pkt->data + i + 
2)); /* data off */
+bytestream_put_buffer(, pkt->data + 2, pkt->size - 2); /* 
skip already written SOI */
 
-ff_packet_replace_buffer(pkt, out);
+ff_packet_replace_buffer(pkt, out_buf);
 return 0;
 }
 case APP1:
-- 
2.20.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 23/36] avcodec/utils: Add utility functions for bsf

2020-05-30 Thread Andreas Rheinhardt
Several bitstream filters (e.g. dump_extradata, imxdump, mjpeg2jpeg,
mjpegadump, mp3decomp, ...) don't buffer packets; instead, they just
modify the buffer of one packet and don't change any other of the
packet's non-buffer properties. The usual approach of these bitstream
filters is to use separate packets for in- and output as follows:

1. Get the input packet via ff_bsf_get_packet() which entails an allocation.
2. Use av_new_packet() to allocate a big enough buffer in the output
packet.
3. Perform the actual work of the bitstream filter, i.e. fill the output
buffer.
4. Use av_packet_copy_props() to copy the non-buffer fields of the input
packet to the output packet.
5. Free the input packet and return.

This commit adds two utility functions that allow a different approach:
A function to (re)allocate a refcounted buffer with zeroed padding and a
function to replace a packet's buffer and the buffer-related fields with
information from an AVBufferRef. This allows to modify the bitstream
filters as follows:

1. Get the packet via ff_bsf_get_packet_ref().
2. Use ff_buffer_padded_realloc() to get a big enough refcounted buffer.
3. Perform the actual work of the bitstream filter.
4. Use ff_packet_replace_buffer() to replace the old data in the packet
with the modified one and return.

The first of these functions is just packet_alloc() from avpacket.c which
has been made non-static.

Signed-off-by: Andreas Rheinhardt 
---
An earlier version put the declarations to internal.h, but James
suggested putting them into bsf_internal.h (or actually, into bsf.h
because bsf_internal.h didn't exist back then), so I went with this.

There is currently no user that actually makes use of the reallocation
feature; it was initially thought for hevc_mp4toannexb, but then I
decided to make it no longer reallocate the output buffer at all any
more. But I kept this functionality. Might be useful some day.

 libavcodec/avpacket.c | 21 -
 libavcodec/bsf_internal.h | 27 +++
 2 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 033f2d8f26..c8f3b0cf7a 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -27,6 +27,7 @@
 #include "libavutil/mathematics.h"
 #include "libavutil/mem.h"
 
+#include "bsf_internal.h"
 #include "bytestream.h"
 #include "internal.h"
 #include "packet.h"
@@ -69,7 +70,7 @@ void av_packet_free(AVPacket **pkt)
 av_freep(pkt);
 }
 
-static int packet_alloc(AVBufferRef **buf, int size)
+int ff_buffer_padded_realloc(AVBufferRef **buf, int size)
 {
 int ret;
 if (size < 0 || size >= INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
@@ -87,7 +88,7 @@ static int packet_alloc(AVBufferRef **buf, int size)
 int av_new_packet(AVPacket *pkt, int size)
 {
 AVBufferRef *buf = NULL;
-int ret = packet_alloc(, size);
+int ret = ff_buffer_padded_realloc(, size);
 if (ret < 0)
 return ret;
 
@@ -621,7 +622,7 @@ int av_packet_ref(AVPacket *dst, const AVPacket *src)
 goto fail;
 
 if (!src->buf) {
-ret = packet_alloc(>buf, src->size);
+ret = ff_buffer_padded_realloc(>buf, src->size);
 if (ret < 0)
 goto fail;
 av_assert1(!src->size || src->data);
@@ -674,7 +675,7 @@ int av_packet_make_refcounted(AVPacket *pkt)
 if (pkt->buf)
 return 0;
 
-ret = packet_alloc(>buf, pkt->size);
+ret = ff_buffer_padded_realloc(>buf, pkt->size);
 if (ret < 0)
 return ret;
 av_assert1(!pkt->size || pkt->data);
@@ -694,7 +695,7 @@ int av_packet_make_writable(AVPacket *pkt)
 if (pkt->buf && av_buffer_is_writable(pkt->buf))
 return 0;
 
-ret = packet_alloc(, pkt->size);
+ret = ff_buffer_padded_realloc(, pkt->size);
 if (ret < 0)
 return ret;
 av_assert1(!pkt->size || pkt->data);
@@ -770,3 +771,13 @@ int ff_side_data_set_prft(AVPacket *pkt, int64_t timestamp)
 
 return 0;
 }
+
+void ff_packet_replace_buffer(AVPacket *pkt, AVBufferRef *buf)
+{
+av_buffer_unref(>buf);
+
+pkt->buf  = buf;
+pkt->data = buf->data;
+av_assert1(buf->size >= AV_INPUT_BUFFER_PADDING_SIZE);
+pkt->size = buf->size - AV_INPUT_BUFFER_PADDING_SIZE;
+}
diff --git a/libavcodec/bsf_internal.h b/libavcodec/bsf_internal.h
index fefd5b8905..edaacaa2dd 100644
--- a/libavcodec/bsf_internal.h
+++ b/libavcodec/bsf_internal.h
@@ -19,6 +19,7 @@
 #ifndef AVCODEC_BSF_INTERNAL_H
 #define AVCODEC_BSF_INTERNAL_H
 
+#include "libavutil/buffer.h"
 #include "libavutil/log.h"
 
 #include "bsf.h"
@@ -42,6 +43,32 @@ int ff_bsf_get_packet(AVBSFContext *ctx, AVPacket **pkt);
  */
 int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt);
 
+/**
+ * (Re)allocate an AVBufferRef to an effective size of size. In addition,
+ * the buffer will have AV_BUFFER_INPUT_PADDING_SIZE bytes of zeroed padding
+ * at the end.
+ *
+ * @param buf Pointer to pointer to an AVBufferRef. Must not be NULL;
+ **buf 

[FFmpeg-devel] [PATCH 26/36] avcodec/mjpega_dump_header_bsf: Remove intermediate packet

2020-05-30 Thread Andreas Rheinhardt
This commit ends using separate packets for in- and output. Instead,
the input is read directly into the packet destined for output via
ff_bsf_get_packet_ref() and only the buffer-related fields are modified;
the others are not touched.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mjpega_dump_header_bsf.c | 39 +
 1 file changed, 17 insertions(+), 22 deletions(-)

diff --git a/libavcodec/mjpega_dump_header_bsf.c 
b/libavcodec/mjpega_dump_header_bsf.c
index 4608fe550b..2d49b042ec 100644
--- a/libavcodec/mjpega_dump_header_bsf.c
+++ b/libavcodec/mjpega_dump_header_bsf.c
@@ -31,29 +31,27 @@
 #include "mjpeg.h"
 
 
-static int mjpega_dump_header(AVBSFContext *ctx, AVPacket *out)
+static int mjpega_dump_header(AVBSFContext *ctx, AVPacket *pkt)
 {
-AVPacket *in;
 uint8_t *out_buf;
 unsigned dqt = 0, dht = 0, sof0 = 0;
 int ret = 0, i;
 
-ret = ff_bsf_get_packet(ctx, );
+ret = ff_bsf_get_packet_ref(ctx, pkt);
 if (ret < 0)
 return ret;
 
-for (i = 0; i < in->size - 3; i++) {
-if (in->data[i] == 0xff) {
-switch (in->data[i + 1]) {
+for (i = 0; i < pkt->size - 3; i++) {
+if (pkt->data[i] == 0xff) {
+switch (pkt->data[i + 1]) {
 case DQT:  dqt  = i + 46U; break;
 case DHT:  dht  = i + 46U; break;
 case SOF0: sof0 = i + 46U; break;
 case SOS:
-ret = av_new_packet(out, in->size + 44U);
-if (ret < 0)
-goto fail;
+{
+AVBufferRef *out = NULL;
 
-ret = av_packet_copy_props(out, in);
+ret = ff_buffer_padded_realloc(, pkt->size + 44U);
 if (ret < 0)
 goto fail;
 
@@ -65,24 +63,22 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket 
*out)
 bytestream_put_be16(_buf, 42); /* size */
 bytestream_put_be32(_buf, 0);
 bytestream_put_buffer(_buf, "mjpg", 4);
-bytestream_put_be32(_buf, in->size + 44U); /* field size */
-bytestream_put_be32(_buf, in->size + 44U); /* pad field size */
-bytestream_put_be32(_buf, 0); /* next ptr */
+bytestream_put_be32(_buf, pkt->size + 44U); /* field size 
*/
+bytestream_put_be32(_buf, pkt->size + 44U); /* pad field 
size */
+bytestream_put_be32(_buf, 0); /* next ptr */
 bytestream_put_be32(_buf, dqt); /* quant off */
 bytestream_put_be32(_buf, dht); /* huff off */
 bytestream_put_be32(_buf, sof0); /* image off */
 bytestream_put_be32(_buf, i + 46U); /* scan off */
-bytestream_put_be32(_buf, i + 46U + AV_RB16(in->data + i + 
2)); /* data off */
-bytestream_put_buffer(_buf, in->data + 2, in->size - 2); 
/* skip already written SOI */
+bytestream_put_be32(_buf, i + 46U + AV_RB16(pkt->data + i 
+ 2)); /* data off */
+bytestream_put_buffer(_buf, pkt->data + 2, pkt->size - 2); 
/* skip already written SOI */
 
-out->size = out_buf - out->data;
-av_packet_free();
+ff_packet_replace_buffer(pkt, out);
 return 0;
+}
 case APP1:
-if (i + 12U <= in->size && AV_RL32(in->data + i + 8) == 
AV_RL32("mjpg")) {
+if (i + 12U <= pkt->size && AV_RL32(pkt->data + i + 8) == 
AV_RL32("mjpg")) {
 av_log(ctx, AV_LOG_ERROR, "bitstream already formatted\n");
-av_packet_move_ref(out, in);
-av_packet_free();
 return 0;
 }
 }
@@ -90,8 +86,7 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket 
*out)
 }
 av_log(ctx, AV_LOG_ERROR, "No valid SOS marker in bitstream\n");
 fail:
-av_packet_unref(out);
-av_packet_free();
+av_packet_unref(pkt);
 return AVERROR_INVALIDDATA;
 }
 
-- 
2.20.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 24/36] avcodec/h264_mp4toannexb_bsf: Remove intermediate packet

2020-05-30 Thread Andreas Rheinhardt
This commit ends using separate packets for in- and output. Instead,
the input is read directly into the packet destined for output via
ff_bsf_get_packet_ref() and only the buffer-related fields are modified;
the others are not touched.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h264_mp4toannexb_bsf.c | 27 +++
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/libavcodec/h264_mp4toannexb_bsf.c 
b/libavcodec/h264_mp4toannexb_bsf.c
index 91cabcf170..75b38e1be3 100644
--- a/libavcodec/h264_mp4toannexb_bsf.c
+++ b/libavcodec/h264_mp4toannexb_bsf.c
@@ -166,35 +166,33 @@ static int h264_mp4toannexb_init(AVBSFContext *ctx)
 return 0;
 }
 
-static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *opkt)
+static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *pkt)
 {
 H264BSFContext *s = ctx->priv_data;
-AVPacket *in;
 uint8_t unit_type, new_idr, sps_seen, pps_seen;
 const uint8_t *buf;
 const uint8_t *buf_end;
+AVBufferRef *out_buf = NULL;
 uint8_t *out;
 uint64_t out_size;
 int ret;
 
-ret = ff_bsf_get_packet(ctx, );
+ret = ff_bsf_get_packet_ref(ctx, pkt);
 if (ret < 0)
 return ret;
 
 /* nothing to filter */
 if (!s->extradata_parsed) {
-av_packet_move_ref(opkt, in);
-av_packet_free();
 return 0;
 }
 
-buf_end  = in->data + in->size;
+buf_end = pkt->data + pkt->size;
 
 #define LOG_ONCE(...) \
 if (j) \
 av_log(__VA_ARGS__)
 for (int j = 0; j < 2; j++) {
-buf  = in->data;
+buf  = pkt->data;
 new_idr  = s->new_idr;
 sps_seen = s->idr_sps_seen;
 pps_seen = s->idr_pps_seen;
@@ -273,28 +271,25 @@ static int h264_mp4toannexb_filter(AVBSFContext *ctx, 
AVPacket *opkt)
 ret = AVERROR(ERANGE);
 goto fail;
 }
-ret = av_new_packet(opkt, out_size);
+ret = ff_buffer_padded_realloc(_buf, out_size);
 if (ret < 0)
 goto fail;
-out = opkt->data;
+out = out_buf->data;
 }
 }
 #undef LOG_ONCE
 
-av_assert1(out_size == opkt->size);
+ff_packet_replace_buffer(pkt, out_buf);
+
+av_assert1(out_size == pkt->size);
 
 s->new_idr  = new_idr;
 s->idr_sps_seen = sps_seen;
 s->idr_pps_seen = pps_seen;
 
-ret = av_packet_copy_props(opkt, in);
-if (ret < 0)
-goto fail;
-
 fail:
 if (ret < 0)
-av_packet_unref(opkt);
-av_packet_free();
+av_packet_unref(pkt);
 
 return ret;
 }
-- 
2.20.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 25/36] avcodec/hevc_mp4toannexb_bsf: Remove intermediate packet

2020-05-30 Thread Andreas Rheinhardt
This commit ends using separate packets for in- and output. Instead,
the input is read directly into the packet destined for output via
ff_bsf_get_packet_ref() and only the buffer-related fields are modified;
the others are not touched.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/hevc_mp4toannexb_bsf.c | 19 +++
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/libavcodec/hevc_mp4toannexb_bsf.c 
b/libavcodec/hevc_mp4toannexb_bsf.c
index 731ff2e7d3..9450efe2c8 100644
--- a/libavcodec/hevc_mp4toannexb_bsf.c
+++ b/libavcodec/hevc_mp4toannexb_bsf.c
@@ -116,20 +116,18 @@ static int hevc_mp4toannexb_init(AVBSFContext *ctx)
 return 0;
 }
 
-static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out)
+static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *pkt)
 {
 HEVCBSFContext *s = ctx->priv_data;
 PutByteContext pb;
-AVPacket *in;
+AVBufferRef *out = NULL;
 int ret;
 
-ret = ff_bsf_get_packet(ctx, );
+ret = ff_bsf_get_packet_ref(ctx, pkt);
 if (ret < 0)
 return ret;
 
 if (!s->extradata_parsed) {
-av_packet_move_ref(out, in);
-av_packet_free();
 return 0;
 }
 
@@ -138,7 +136,7 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, 
AVPacket *out)
 uint64_t out_size = 0;
 int got_irap = 0;
 
-bytestream2_init(, in->data, in->size);
+bytestream2_init(, pkt->data, pkt->size);
 
 while (bytestream2_get_bytes_left()) {
 uint32_t nalu_size = 0;
@@ -181,7 +179,7 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, 
AVPacket *out)
 ret = AVERROR(ERANGE);
 goto fail;
 }
-ret = av_new_packet(out, out_size);
+ret = ff_buffer_padded_realloc(, out_size);
 if (ret < 0)
 goto fail;
 
@@ -189,14 +187,11 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, 
AVPacket *out)
 }
 }
 
-ret = av_packet_copy_props(out, in);
-if (ret < 0)
-goto fail;
+ff_packet_replace_buffer(pkt, out);
 
 fail:
 if (ret < 0)
-av_packet_unref(out);
-av_packet_free();
+av_packet_unref(pkt);
 
 return ret;
 }
-- 
2.20.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 22/36] avcodec/h264_mp4toannexb_bsf: Improve returned error code

2020-05-30 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h264_mp4toannexb_bsf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/h264_mp4toannexb_bsf.c 
b/libavcodec/h264_mp4toannexb_bsf.c
index 2822644b10..91cabcf170 100644
--- a/libavcodec/h264_mp4toannexb_bsf.c
+++ b/libavcodec/h264_mp4toannexb_bsf.c
@@ -270,7 +270,7 @@ static int h264_mp4toannexb_filter(AVBSFContext *ctx, 
AVPacket *opkt)
 
 if (!j) {
 if (out_size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
-ret = AVERROR_INVALIDDATA;
+ret = AVERROR(ERANGE);
 goto fail;
 }
 ret = av_new_packet(opkt, out_size);
-- 
2.20.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 21/36] avcodec/hevc_mp4toannexb_bsf: Reindent after last commit

2020-05-30 Thread Andreas Rheinhardt
While just at it, use a smaller scope for a loop counter.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/hevc_mp4toannexb_bsf.c | 45 +++
 1 file changed, 22 insertions(+), 23 deletions(-)

diff --git a/libavcodec/hevc_mp4toannexb_bsf.c 
b/libavcodec/hevc_mp4toannexb_bsf.c
index 3776d5b279..731ff2e7d3 100644
--- a/libavcodec/hevc_mp4toannexb_bsf.c
+++ b/libavcodec/hevc_mp4toannexb_bsf.c
@@ -121,8 +121,7 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, 
AVPacket *out)
 HEVCBSFContext *s = ctx->priv_data;
 PutByteContext pb;
 AVPacket *in;
-
-int i, ret = 0;
+int ret;
 
 ret = ff_bsf_get_packet(ctx, );
 if (ret < 0)
@@ -139,32 +138,32 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, 
AVPacket *out)
 uint64_t out_size = 0;
 int got_irap = 0;
 
-bytestream2_init(, in->data, in->size);
+bytestream2_init(, in->data, in->size);
 
-while (bytestream2_get_bytes_left()) {
-uint32_t nalu_size = 0;
-int  nalu_type;
+while (bytestream2_get_bytes_left()) {
+uint32_t nalu_size = 0;
+int  nalu_type;
 int is_irap, add_extradata, extra_size;
 
-if (bytestream2_get_bytes_left() < s->length_size) {
-ret = AVERROR_INVALIDDATA;
-goto fail;
-}
-for (i = 0; i < s->length_size; i++)
-nalu_size = (nalu_size << 8) | bytestream2_get_byteu();
+if (bytestream2_get_bytes_left() < s->length_size) {
+ret = AVERROR_INVALIDDATA;
+goto fail;
+}
+for (int i = 0; i < s->length_size; i++)
+nalu_size = (nalu_size << 8) | bytestream2_get_byteu();
 
-if (nalu_size < 2 || nalu_size > bytestream2_get_bytes_left()) {
-ret = AVERROR_INVALIDDATA;
-goto fail;
-}
+if (nalu_size < 2 || nalu_size > bytestream2_get_bytes_left()) {
+ret = AVERROR_INVALIDDATA;
+goto fail;
+}
 
-nalu_type = (bytestream2_peek_byteu() >> 1) & 0x3f;
+nalu_type = (bytestream2_peek_byteu() >> 1) & 0x3f;
 
-/* prepend extradata to IRAP frames */
-is_irap   = nalu_type >= 16 && nalu_type <= 23;
-add_extradata = is_irap && !got_irap;
-extra_size= add_extradata * ctx->par_out->extradata_size;
-got_irap |= is_irap;
+/* prepend extradata to IRAP frames */
+is_irap   = nalu_type >= 16 && nalu_type <= 23;
+add_extradata = is_irap && !got_irap;
+extra_size= add_extradata * ctx->par_out->extradata_size;
+got_irap |= is_irap;
 
 if (!pass) {
 out_size += extra_size + 4ULL + nalu_size;
@@ -175,7 +174,7 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, 
AVPacket *out)
 bytestream2_put_be32u(, 1);
 bytestream2_copy_bufferu(, , nalu_size);
 }
-}
+}
 
 if (!pass) {
 if (out_size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
-- 
2.20.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 19/36] avcodec/hevc_mp4toannexb_bsf: Use unchecked bytestream2 API

2020-05-30 Thread Andreas Rheinhardt
We already check manually and error out on invalid data, so we don't
have to rely on the implicit checks provided by the safe version of the
bytestream2 API.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/hevc_mp4toannexb_bsf.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/hevc_mp4toannexb_bsf.c 
b/libavcodec/hevc_mp4toannexb_bsf.c
index ba1deb2848..634bfe9c46 100644
--- a/libavcodec/hevc_mp4toannexb_bsf.c
+++ b/libavcodec/hevc_mp4toannexb_bsf.c
@@ -147,14 +147,14 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, 
AVPacket *out)
 goto fail;
 }
 for (i = 0; i < s->length_size; i++)
-nalu_size = (nalu_size << 8) | bytestream2_get_byte();
+nalu_size = (nalu_size << 8) | bytestream2_get_byteu();
 
 if (nalu_size < 2 || nalu_size > bytestream2_get_bytes_left()) {
 ret = AVERROR_INVALIDDATA;
 goto fail;
 }
 
-nalu_type = (bytestream2_peek_byte() >> 1) & 0x3f;
+nalu_type = (bytestream2_peek_byteu() >> 1) & 0x3f;
 
 /* prepend extradata to IRAP frames */
 is_irap   = nalu_type >= 16 && nalu_type <= 23;
@@ -176,7 +176,7 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, 
AVPacket *out)
 if (extra_size)
 memcpy(out->data + prev_size, ctx->par_out->extradata, extra_size);
 AV_WB32(out->data + prev_size + extra_size, 1);
-bytestream2_get_buffer(, out->data + prev_size + 4 + extra_size, 
nalu_size);
+bytestream2_get_bufferu(, out->data + prev_size + 4 + extra_size, 
nalu_size);
 }
 
 ret = av_packet_copy_props(out, in);
-- 
2.20.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 20/36] avcodec/hevc_mp4toannexb_bsf: Stop reallocating output buffer

2020-05-30 Thread Andreas Rheinhardt
Instead parse the input packet twice: Once to get the size of the output
packet to be allocated (and to check the input packet for consistency)
and once to actually copy the data.

Not reallocating the output buffer also means that one can now use
a PutByteContext for writing; it improves readability.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/hevc_mp4toannexb_bsf.c | 43 +++
 1 file changed, 27 insertions(+), 16 deletions(-)

diff --git a/libavcodec/hevc_mp4toannexb_bsf.c 
b/libavcodec/hevc_mp4toannexb_bsf.c
index 634bfe9c46..3776d5b279 100644
--- a/libavcodec/hevc_mp4toannexb_bsf.c
+++ b/libavcodec/hevc_mp4toannexb_bsf.c
@@ -119,10 +119,9 @@ static int hevc_mp4toannexb_init(AVBSFContext *ctx)
 static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out)
 {
 HEVCBSFContext *s = ctx->priv_data;
+PutByteContext pb;
 AVPacket *in;
-GetByteContext gb;
 
-int got_irap = 0;
 int i, ret = 0;
 
 ret = ff_bsf_get_packet(ctx, );
@@ -135,12 +134,17 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, 
AVPacket *out)
 return 0;
 }
 
+for (int pass = 0; pass < 2; pass++) {
+GetByteContext gb;
+uint64_t out_size = 0;
+int got_irap = 0;
+
 bytestream2_init(, in->data, in->size);
 
 while (bytestream2_get_bytes_left()) {
 uint32_t nalu_size = 0;
 int  nalu_type;
-int is_irap, add_extradata, extra_size, prev_size;
+int is_irap, add_extradata, extra_size;
 
 if (bytestream2_get_bytes_left() < s->length_size) {
 ret = AVERROR_INVALIDDATA;
@@ -162,21 +166,28 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, 
AVPacket *out)
 extra_size= add_extradata * ctx->par_out->extradata_size;
 got_irap |= is_irap;
 
-if (FFMIN(INT_MAX, SIZE_MAX) < 4ULL + nalu_size + extra_size) {
-ret = AVERROR_INVALIDDATA;
-goto fail;
-}
-
-prev_size = out->size;
+if (!pass) {
+out_size += extra_size + 4ULL + nalu_size;
+bytestream2_skipu(, nalu_size);
+} else {
+if (extra_size)
+bytestream2_put_bufferu(, ctx->par_out->extradata, 
extra_size);
+bytestream2_put_be32u(, 1);
+bytestream2_copy_bufferu(, , nalu_size);
+}
+}
 
-ret = av_grow_packet(out, 4 + nalu_size + extra_size);
-if (ret < 0)
-goto fail;
+if (!pass) {
+if (out_size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
+ret = AVERROR(ERANGE);
+goto fail;
+}
+ret = av_new_packet(out, out_size);
+if (ret < 0)
+goto fail;
 
-if (extra_size)
-memcpy(out->data + prev_size, ctx->par_out->extradata, extra_size);
-AV_WB32(out->data + prev_size + extra_size, 1);
-bytestream2_get_bufferu(, out->data + prev_size + 4 + extra_size, 
nalu_size);
+bytestream2_init_writer(, out->data, out->size);
+}
 }
 
 ret = av_packet_copy_props(out, in);
-- 
2.20.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 17/36] avcodec/hevc_mp4toannexb_bsf: Check NAL size against available input

2020-05-30 Thread Andreas Rheinhardt
The hevc_mp4toannexb bsf does not explicitly check whether a NAL unit
is so big that it extends beyond the end of the input packet; it does so
only implicitly by using the checked version of the bytestream2 API.
But this has downsides compared to real checks: It can lead to huge
allocations (up to 2GiB) even when the input packet is just a few bytes.
And furthermore it leads to uninitialized data being output.
So add a check to error out early if it happens.

Also check directly whether there is enough data for the length field.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/hevc_mp4toannexb_bsf.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavcodec/hevc_mp4toannexb_bsf.c 
b/libavcodec/hevc_mp4toannexb_bsf.c
index a880d9ba9a..ba1deb2848 100644
--- a/libavcodec/hevc_mp4toannexb_bsf.c
+++ b/libavcodec/hevc_mp4toannexb_bsf.c
@@ -142,10 +142,14 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, 
AVPacket *out)
 int  nalu_type;
 int is_irap, add_extradata, extra_size, prev_size;
 
+if (bytestream2_get_bytes_left() < s->length_size) {
+ret = AVERROR_INVALIDDATA;
+goto fail;
+}
 for (i = 0; i < s->length_size; i++)
 nalu_size = (nalu_size << 8) | bytestream2_get_byte();
 
-if (nalu_size < 2) {
+if (nalu_size < 2 || nalu_size > bytestream2_get_bytes_left()) {
 ret = AVERROR_INVALIDDATA;
 goto fail;
 }
-- 
2.20.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 18/36] avcodec/bytestream: Add unchecked bytestream2 peek functions

2020-05-30 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/bytestream.h | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavcodec/bytestream.h b/libavcodec/bytestream.h
index 0516a6e3dc..d0033f14f3 100644
--- a/libavcodec/bytestream.h
+++ b/libavcodec/bytestream.h
@@ -77,11 +77,15 @@ static av_always_inline type bytestream2_get_ ## 
name(GetByteContext *g)   \
 }  
\
 return bytestream2_get_ ## name ## u(g);   
\
 }  
\
+static av_always_inline type bytestream2_peek_ ## name ## u(GetByteContext *g) 
\
+{  
\
+return read(g->buffer);
\
+}  
\
 static av_always_inline type bytestream2_peek_ ## name(GetByteContext *g)  
\
 {  
\
 if (g->buffer_end - g->buffer < bytes) 
\
 return 0;  
\
-return read(g->buffer);
\
+return bytestream2_peek_ ## name ## u(g);  
\
 }
 
 DEF(uint64_t, le64, 8, AV_RL64, AV_WL64)
-- 
2.20.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 12/36] avcodec/mp3_header_decompress_bsf: Don't output uninitialized CRC

2020-05-30 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mp3_header_decompress_bsf.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavcodec/mp3_header_decompress_bsf.c 
b/libavcodec/mp3_header_decompress_bsf.c
index 44c174c21c..fe021deed3 100644
--- a/libavcodec/mp3_header_decompress_bsf.c
+++ b/libavcodec/mp3_header_decompress_bsf.c
@@ -85,7 +85,7 @@ static int mp3_header_decompress(AVBSFContext *ctx, AVPacket 
*out)
 
 header |= (bitrate_index&1)<<9;
 header |= (bitrate_index>>1)<<12;
-header |= (frame_size == buf_size + 4)<<16; //FIXME actually set a correct 
crc instead of 0
+header |= (frame_size == buf_size + 4)<<16;
 
 ret = av_new_packet(out, frame_size);
 if (ret < 0)
@@ -109,6 +109,10 @@ static int mp3_header_decompress(AVBSFContext *ctx, 
AVPacket *out)
 }
 }
 
+if (frame_size == buf_size + 6) {
+//FIXME actually set a correct crc instead of 0
+AV_WN16(out->data + 4, 0);
+}
 AV_WB32(out->data, header);
 
 ret = 0;
-- 
2.20.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 14/36] avcodec/mjpega_dump_header_bsf: Make code more robust wrt overflow

2020-05-30 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mjpega_dump_header_bsf.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/libavcodec/mjpega_dump_header_bsf.c 
b/libavcodec/mjpega_dump_header_bsf.c
index ab68f9c3e9..40c4c690ab 100644
--- a/libavcodec/mjpega_dump_header_bsf.c
+++ b/libavcodec/mjpega_dump_header_bsf.c
@@ -42,7 +42,7 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket 
*out)
 if (ret < 0)
 return ret;
 
-ret = av_new_packet(out, in->size + 44);
+ret = av_new_packet(out, in->size + 44U);
 if (ret < 0)
 goto fail;
 
@@ -58,29 +58,29 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket 
*out)
 bytestream_put_be16(_buf, 42); /* size */
 bytestream_put_be32(_buf, 0);
 bytestream_put_buffer(_buf, "mjpg", 4);
-bytestream_put_be32(_buf, in->size + 44); /* field size */
-bytestream_put_be32(_buf, in->size + 44); /* pad field size */
+bytestream_put_be32(_buf, in->size + 44U); /* field size */
+bytestream_put_be32(_buf, in->size + 44U); /* pad field size */
 bytestream_put_be32(_buf, 0); /* next ptr */
 
 for (i = 0; i < in->size - 1; i++) {
 if (in->data[i] == 0xff) {
 switch (in->data[i + 1]) {
-case DQT:  dqt  = i + 46; break;
-case DHT:  dht  = i + 46; break;
-case SOF0: sof0 = i + 46; break;
+case DQT:  dqt  = i + 46U; break;
+case DHT:  dht  = i + 46U; break;
+case SOF0: sof0 = i + 46U; break;
 case SOS:
 bytestream_put_be32(_buf, dqt); /* quant off */
 bytestream_put_be32(_buf, dht); /* huff off */
 bytestream_put_be32(_buf, sof0); /* image off */
-bytestream_put_be32(_buf, i + 46); /* scan off */
-bytestream_put_be32(_buf, i + 46 + AV_RB16(in->data + i + 
2)); /* data off */
+bytestream_put_be32(_buf, i + 46U); /* scan off */
+bytestream_put_be32(_buf, i + 46U + AV_RB16(in->data + i + 
2)); /* data off */
 bytestream_put_buffer(_buf, in->data + 2, in->size - 2); 
/* skip already written SOI */
 
 out->size = out_buf - out->data;
 av_packet_free();
 return 0;
 case APP1:
-if (i + 8 < in->size && AV_RL32(in->data + i + 8) == 
AV_RL32("mjpg")) {
+if (i + 8U < in->size && AV_RL32(in->data + i + 8) == 
AV_RL32("mjpg")) {
 av_log(ctx, AV_LOG_ERROR, "bitstream already formatted\n");
 av_packet_unref(out);
 av_packet_move_ref(out, in);
-- 
2.20.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 13/36] avcodec/mp3_header_decompress_bsf: Improve readability

2020-05-30 Thread Andreas Rheinhardt
Up until now, the mp3_header_decompress bsf used a single variable for
two purposes in a bitfield-like manner: To contain the bitrate index
as well as whether the padding_bit is set. The former was contained in
bits 1-4, while the latter was given by bit 0. This made the code hard
to understand.

This commit changes this by using dedicated variables for the
bitrate index as well as for the offset of the old data in the new
buffer. The latter implicitly contains whether the padding_bit is set.

Also add const to the pointer to the source data; it is of course not
modified.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mp3_header_decompress_bsf.c | 35 ++
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/libavcodec/mp3_header_decompress_bsf.c 
b/libavcodec/mp3_header_decompress_bsf.c
index fe021deed3..3d357dd27e 100644
--- a/libavcodec/mp3_header_decompress_bsf.c
+++ b/libavcodec/mp3_header_decompress_bsf.c
@@ -32,8 +32,8 @@ static int mp3_header_decompress(AVBSFContext *ctx, AVPacket 
*out)
 uint32_t header;
 int sample_rate= ctx->par_in->sample_rate;
 int sample_rate_index=0;
-int lsf, mpeg25, bitrate_index, frame_size, ret;
-uint8_t *buf;
+int lsf, mpeg25, bitrate_index, frame_size, offset, ret;
+const uint8_t *buf;
 int buf_size;
 
 ret = ff_bsf_get_packet(ctx, );
@@ -69,23 +69,25 @@ static int mp3_header_decompress(AVBSFContext *ctx, 
AVPacket *out)
 
 sample_rate= avpriv_mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25); 
//in case sample rate is a little off
 
-for(bitrate_index=2; bitrate_index<30; bitrate_index++){
-frame_size = avpriv_mpa_bitrate_tab[lsf][2][bitrate_index>>1];
-frame_size = (frame_size * 144000) / (sample_rate << lsf) + 
(bitrate_index&1);
-if(frame_size == buf_size + 4)
-break;
-if(frame_size == buf_size + 6)
+for (bitrate_index = 1; bitrate_index < 15; bitrate_index++) {
+frame_size = avpriv_mpa_bitrate_tab[lsf][2][bitrate_index];
+frame_size = (frame_size * 144000) / (sample_rate << lsf);
+offset = frame_size - buf_size;
+if (3 <= offset && offset <= 6)
 break;
 }
-if(bitrate_index == 30){
+if (bitrate_index == 15) {
 av_log(ctx, AV_LOG_ERROR, "Could not find bitrate_index.\n");
 ret = AVERROR(EINVAL);
 goto fail;
 }
 
-header |= (bitrate_index&1)<<9;
-header |= (bitrate_index>>1)<<12;
-header |= (frame_size == buf_size + 4)<<16;
+header |= bitrate_index << 12;
+if (offset & 1) {
+header |= 1 << 9; // padding_bit
+frame_size++;
+offset++;
+}
 
 ret = av_new_packet(out, frame_size);
 if (ret < 0)
@@ -95,10 +97,10 @@ static int mp3_header_decompress(AVBSFContext *ctx, 
AVPacket *out)
 av_packet_unref(out);
 goto fail;
 }
-memcpy(out->data + frame_size - buf_size, buf, buf_size + 
AV_INPUT_BUFFER_PADDING_SIZE);
+memcpy(out->data + offset, buf, buf_size);
 
 if(ctx->par_in->channels==2){
-uint8_t *p= out->data + frame_size - buf_size;
+uint8_t *p = out->data + offset;
 if(lsf){
 FFSWAP(int, p[1], p[2]);
 header |= (p[1] & 0xC0)>>2;
@@ -109,10 +111,11 @@ static int mp3_header_decompress(AVBSFContext *ctx, 
AVPacket *out)
 }
 }
 
-if (frame_size == buf_size + 6) {
+if (offset == 6) {
 //FIXME actually set a correct crc instead of 0
 AV_WN16(out->data + 4, 0);
-}
+} else
+header |= 1 << 16; // protection_bit
 AV_WB32(out->data, header);
 
 ret = 0;
-- 
2.20.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 16/36] avcodec/mjpega_dump_header_bsf: Only allocate when necessary

2020-05-30 Thread Andreas Rheinhardt
This avoids having to free a buffer that hasn't been used at all.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mjpega_dump_header_bsf.c | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/libavcodec/mjpega_dump_header_bsf.c 
b/libavcodec/mjpega_dump_header_bsf.c
index 1cd2b48719..4608fe550b 100644
--- a/libavcodec/mjpega_dump_header_bsf.c
+++ b/libavcodec/mjpega_dump_header_bsf.c
@@ -42,6 +42,13 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket 
*out)
 if (ret < 0)
 return ret;
 
+for (i = 0; i < in->size - 3; i++) {
+if (in->data[i] == 0xff) {
+switch (in->data[i + 1]) {
+case DQT:  dqt  = i + 46U; break;
+case DHT:  dht  = i + 46U; break;
+case SOF0: sof0 = i + 46U; break;
+case SOS:
 ret = av_new_packet(out, in->size + 44U);
 if (ret < 0)
 goto fail;
@@ -61,14 +68,6 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket 
*out)
 bytestream_put_be32(_buf, in->size + 44U); /* field size */
 bytestream_put_be32(_buf, in->size + 44U); /* pad field size */
 bytestream_put_be32(_buf, 0); /* next ptr */
-
-for (i = 0; i < in->size - 3; i++) {
-if (in->data[i] == 0xff) {
-switch (in->data[i + 1]) {
-case DQT:  dqt  = i + 46U; break;
-case DHT:  dht  = i + 46U; break;
-case SOF0: sof0 = i + 46U; break;
-case SOS:
 bytestream_put_be32(_buf, dqt); /* quant off */
 bytestream_put_be32(_buf, dht); /* huff off */
 bytestream_put_be32(_buf, sof0); /* image off */
@@ -82,7 +81,6 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket 
*out)
 case APP1:
 if (i + 12U <= in->size && AV_RL32(in->data + i + 8) == 
AV_RL32("mjpg")) {
 av_log(ctx, AV_LOG_ERROR, "bitstream already formatted\n");
-av_packet_unref(out);
 av_packet_move_ref(out, in);
 av_packet_free();
 return 0;
-- 
2.20.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 15/36] avcodec/mjpega_dump_header_bsf: Don't overread

2020-05-30 Thread Andreas Rheinhardt
When encountering an SOS marker, the two bytes after this marker are
read, too. So one needs to make sure that these two bytes are still part
of the packet's data. And when one checks whether the input already is
of the desired format, one has to make sure that the place where one
searches the "mjpg" tag is actually contained in the given data.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mjpega_dump_header_bsf.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/mjpega_dump_header_bsf.c 
b/libavcodec/mjpega_dump_header_bsf.c
index 40c4c690ab..1cd2b48719 100644
--- a/libavcodec/mjpega_dump_header_bsf.c
+++ b/libavcodec/mjpega_dump_header_bsf.c
@@ -62,7 +62,7 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket 
*out)
 bytestream_put_be32(_buf, in->size + 44U); /* pad field size */
 bytestream_put_be32(_buf, 0); /* next ptr */
 
-for (i = 0; i < in->size - 1; i++) {
+for (i = 0; i < in->size - 3; i++) {
 if (in->data[i] == 0xff) {
 switch (in->data[i + 1]) {
 case DQT:  dqt  = i + 46U; break;
@@ -80,7 +80,7 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket 
*out)
 av_packet_free();
 return 0;
 case APP1:
-if (i + 8U < in->size && AV_RL32(in->data + i + 8) == 
AV_RL32("mjpg")) {
+if (i + 12U <= in->size && AV_RL32(in->data + i + 8) == 
AV_RL32("mjpg")) {
 av_log(ctx, AV_LOG_ERROR, "bitstream already formatted\n");
 av_packet_unref(out);
 av_packet_move_ref(out, in);
@@ -90,7 +90,7 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket 
*out)
 }
 }
 }
-av_log(ctx, AV_LOG_ERROR, "could not find SOS marker in bitstream\n");
+av_log(ctx, AV_LOG_ERROR, "No valid SOS marker in bitstream\n");
 fail:
 av_packet_unref(out);
 av_packet_free();
-- 
2.20.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 09/36] avcodec/vp9_superframe_split_bsf: Don't restrict frame_size to INT_MAX/8

2020-05-30 Thread Andreas Rheinhardt
By using a GetBitContext with a packet's data as buffer, one restricts
said packet to a size of about INT_MAX/8. This restriction is not
onerous, but unnecessary: The bitreader is only used to read the first
byte of data. So change it.

Furthermore, given that it has already been checked that the packet's
size is > 0, one can omit the check for whether init_get_bits() succeeds
and stop unreferencing the packet destined for output on failure as it
now never contains any data upon failure.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/vp9_superframe_split_bsf.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/libavcodec/vp9_superframe_split_bsf.c 
b/libavcodec/vp9_superframe_split_bsf.c
index df5b964414..48c3723206 100644
--- a/libavcodec/vp9_superframe_split_bsf.c
+++ b/libavcodec/vp9_superframe_split_bsf.c
@@ -108,9 +108,7 @@ static int vp9_superframe_split_filter(AVBSFContext *ctx, 
AVPacket *out)
 if (s->next_frame >= s->nb_frames)
 av_packet_unref(s->buffer_pkt);
 
-ret = init_get_bits8(, out->data, out->size);
-if (ret < 0)
-goto fail;
+init_get_bits(, out->data, 8);
 
 get_bits(, 2); // frame_marker
 profile  = get_bits1();
@@ -131,8 +129,6 @@ static int vp9_superframe_split_filter(AVBSFContext *ctx, 
AVPacket *out)
 
 return 0;
 fail:
-if (ret < 0)
-av_packet_unref(out);
 av_packet_unref(s->buffer_pkt);
 return ret;
 }
-- 
2.20.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 11/36] avcodec/vp9_raw_reorder_bsf: Check for existence of data before reading it

2020-05-30 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/vp9_raw_reorder_bsf.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libavcodec/vp9_raw_reorder_bsf.c b/libavcodec/vp9_raw_reorder_bsf.c
index 6562399159..6e77816256 100644
--- a/libavcodec/vp9_raw_reorder_bsf.c
+++ b/libavcodec/vp9_raw_reorder_bsf.c
@@ -292,6 +292,11 @@ static int vp9_raw_reorder_filter(AVBSFContext *bsf, 
AVPacket *out)
 return err;
 }
 
+if (in->size <= 0) {
+av_packet_free();
+return AVERROR_INVALIDDATA;
+}
+
 if ((in->data[in->size - 1] & 0xe0) == 0xc0) {
 av_log(bsf, AV_LOG_ERROR, "Input in superframes is not "
"supported.\n");
-- 
2.20.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 08/36] avcodec/vp9_superframe_split_bsf: Improve returned error message

2020-05-30 Thread Andreas Rheinhardt
If a parsed frame size happens to be so big that it is negative
(as an int), the size in the error message would be negative which is
nonsense in light of the fact that the size field is an unsigned value
in the standard. Change this and also change the type of the variable to
unsigned.

Also return AVERROR_INVALIDDATA and not AVERROR(EINVAL) in this case as
this is clearly invalid data.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/vp9_superframe_split_bsf.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/vp9_superframe_split_bsf.c 
b/libavcodec/vp9_superframe_split_bsf.c
index 6ebecfa8ae..df5b964414 100644
--- a/libavcodec/vp9_superframe_split_bsf.c
+++ b/libavcodec/vp9_superframe_split_bsf.c
@@ -70,15 +70,15 @@ static int vp9_superframe_split_filter(AVBSFContext *ctx, 
AVPacket *out)
  nb_frames * length_size);
 
 for (i = 0; i < nb_frames; i++) {
-int frame_size = 0;
+unsigned frame_size = 0;
 for (j = 0; j < length_size; j++)
 frame_size |= bytestream2_get_byte() << (j * 8);
 
 total_size += frame_size;
-if (frame_size <= 0 || total_size > in->size - idx_size) {
+if (!frame_size || total_size > in->size - idx_size) {
 av_log(ctx, AV_LOG_ERROR,
-   "Invalid frame size in a superframe: %d\n", 
frame_size);
-ret = AVERROR(EINVAL);
+   "Invalid frame size in a superframe: %u\n", 
frame_size);
+ret = AVERROR_INVALIDDATA;
 goto fail;
 }
 s->sizes[i] = frame_size;
-- 
2.20.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 10/36] avcodec/vp9_superframe_split_bsf: Use unchecked bytestream reader

2020-05-30 Thread Andreas Rheinhardt
It has already been checked that there is enough data available.

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

diff --git a/libavcodec/vp9_superframe_split_bsf.c 
b/libavcodec/vp9_superframe_split_bsf.c
index 48c3723206..9f9e495bd5 100644
--- a/libavcodec/vp9_superframe_split_bsf.c
+++ b/libavcodec/vp9_superframe_split_bsf.c
@@ -72,7 +72,7 @@ static int vp9_superframe_split_filter(AVBSFContext *ctx, 
AVPacket *out)
 for (i = 0; i < nb_frames; i++) {
 unsigned frame_size = 0;
 for (j = 0; j < length_size; j++)
-frame_size |= bytestream2_get_byte() << (j * 8);
+frame_size |= bytestream2_get_byteu() << (j * 8);
 
 total_size += frame_size;
 if (!frame_size || total_size > in->size - idx_size) {
-- 
2.20.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 07/36] avcodec/vp9_superframe_split_bsf: Discard frames with size zero

2020-05-30 Thread Andreas Rheinhardt
They are invalid in VP9. If the packet given to the bsf has a size of
zero, it would try to access pkt->data[-1] which could lead to segfaults.
And if any of the frames inside a superframe had a size of zero, the code
would either read into the next frame or into the superframe index.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/vp9_superframe_split_bsf.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavcodec/vp9_superframe_split_bsf.c 
b/libavcodec/vp9_superframe_split_bsf.c
index ed0444561a..6ebecfa8ae 100644
--- a/libavcodec/vp9_superframe_split_bsf.c
+++ b/libavcodec/vp9_superframe_split_bsf.c
@@ -51,6 +51,11 @@ static int vp9_superframe_split_filter(AVBSFContext *ctx, 
AVPacket *out)
 return ret;
 in = s->buffer_pkt;
 
+if (in->size <= 0) {
+ret = AVERROR_INVALIDDATA;
+goto fail;
+}
+
 marker = in->data[in->size - 1];
 if ((marker & 0xe0) == 0xc0) {
 int length_size = 1 + ((marker >> 3) & 0x3);
@@ -70,7 +75,7 @@ static int vp9_superframe_split_filter(AVBSFContext *ctx, 
AVPacket *out)
 frame_size |= bytestream2_get_byte() << (j * 8);
 
 total_size += frame_size;
-if (frame_size < 0 || total_size > in->size - idx_size) {
+if (frame_size <= 0 || total_size > in->size - idx_size) {
 av_log(ctx, AV_LOG_ERROR,
"Invalid frame size in a superframe: %d\n", 
frame_size);
 ret = AVERROR(EINVAL);
-- 
2.20.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 01/36] avcodec/vp9_superframe_bsf: Check for existence of data before reading it

2020-05-30 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/vp9_superframe_bsf.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libavcodec/vp9_superframe_bsf.c b/libavcodec/vp9_superframe_bsf.c
index 57681e29e4..34a47aa69e 100644
--- a/libavcodec/vp9_superframe_bsf.c
+++ b/libavcodec/vp9_superframe_bsf.c
@@ -108,6 +108,11 @@ static int vp9_superframe_filter(AVBSFContext *ctx, 
AVPacket *pkt)
 if (res < 0)
 return res;
 
+if (pkt->size <= 0) {
+res = AVERROR_INVALIDDATA;
+goto done;
+}
+
 marker = pkt->data[pkt->size - 1];
 if ((marker & 0xe0) == 0xc0) {
 int nbytes = 1 + ((marker >> 3) & 0x3);
-- 
2.20.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 05/36] avcodec/vp9_superframe_bsf: Allow up to eight frames in a superframe

2020-05-30 Thread Andreas Rheinhardt
Up until now, the bsf errored out with a message that there were too
many invisible frames if there were already seven frames cached even
when the new frame was not invisible. This has been changed.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/vp9_superframe_bsf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavcodec/vp9_superframe_bsf.c b/libavcodec/vp9_superframe_bsf.c
index a8b58a7fd3..a7faad3abf 100644
--- a/libavcodec/vp9_superframe_bsf.c
+++ b/libavcodec/vp9_superframe_bsf.c
@@ -158,13 +158,15 @@ static int vp9_superframe_filter(AVBSFContext *ctx, 
AVPacket *pkt)
 } else if ((!invisible || uses_superframe_syntax) && !s->n_cache) {
 // passthrough
 return 0;
-} else if (s->n_cache + 1 >= MAX_CACHE) {
+} else if (invisible && s->n_cache + 1 >= MAX_CACHE) {
 av_log(ctx, AV_LOG_ERROR,
"Too many invisible frames\n");
 res = AVERROR_INVALIDDATA;
 goto done;
 }
 
+av_assert0(s->n_cache < MAX_CACHE);
+
 av_packet_move_ref(s->cache[s->n_cache++], pkt);
 
 if (invisible) {
-- 
2.20.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 06/36] avcodec/vp9_superframe_bsf: Don't restrict packet size to INT_MAX/8

2020-05-30 Thread Andreas Rheinhardt
by opening a GetBitContext on its data when all the info one cares about
is actually in the first byte of data.

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

diff --git a/libavcodec/vp9_superframe_bsf.c b/libavcodec/vp9_superframe_bsf.c
index a7faad3abf..29d1c759c7 100644
--- a/libavcodec/vp9_superframe_bsf.c
+++ b/libavcodec/vp9_superframe_bsf.c
@@ -135,8 +135,7 @@ static int vp9_superframe_filter(AVBSFContext *ctx, 
AVPacket *pkt)
 uses_superframe_syntax = pkt->size >= idx_sz && pkt->data[pkt->size - 
idx_sz] == marker;
 }
 
-if ((res = init_get_bits8(, pkt->data, pkt->size)) < 0)
-goto done;
+init_get_bits(, pkt->data, 8);
 
 get_bits(, 2); // frame marker
 profile  = get_bits1();
-- 
2.20.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 02/36] avcodec/vp9_superframe_bsf: Reuse vp9_superframe_flush()

2020-05-30 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/vp9_superframe_bsf.c | 27 ---
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/libavcodec/vp9_superframe_bsf.c b/libavcodec/vp9_superframe_bsf.c
index 34a47aa69e..d9c78c67f5 100644
--- a/libavcodec/vp9_superframe_bsf.c
+++ b/libavcodec/vp9_superframe_bsf.c
@@ -31,6 +31,16 @@ typedef struct VP9BSFContext {
 AVPacket *cache[MAX_CACHE];
 } VP9BSFContext;
 
+static void vp9_superframe_flush(AVBSFContext *ctx)
+{
+VP9BSFContext *s = ctx->priv_data;
+
+// unref cached data
+for (int n = 0; n < s->n_cache; n++)
+av_packet_unref(s->cache[n]);
+s->n_cache = 0;
+}
+
 static void stats(AVPacket * const *in, int n_in,
   unsigned *_max, unsigned *_sum)
 {
@@ -102,7 +112,7 @@ static int vp9_superframe_filter(AVBSFContext *ctx, 
AVPacket *pkt)
 {
 GetBitContext gb;
 VP9BSFContext *s = ctx->priv_data;
-int res, invisible, profile, marker, uses_superframe_syntax = 0, n;
+int res, invisible, profile, marker, uses_superframe_syntax = 0;
 
 res = ff_bsf_get_packet_ref(ctx, pkt);
 if (res < 0)
@@ -166,9 +176,7 @@ static int vp9_superframe_filter(AVBSFContext *ctx, 
AVPacket *pkt)
 if (res < 0)
 goto done;
 
-for (n = 0; n < s->n_cache; n++)
-av_packet_unref(s->cache[n]);
-s->n_cache = 0;
+vp9_superframe_flush(ctx);
 
 done:
 if (res < 0)
@@ -191,17 +199,6 @@ static int vp9_superframe_init(AVBSFContext *ctx)
 return 0;
 }
 
-static void vp9_superframe_flush(AVBSFContext *ctx)
-{
-VP9BSFContext *s = ctx->priv_data;
-int n;
-
-// unref cached data
-for (n = 0; n < s->n_cache; n++)
-av_packet_unref(s->cache[n]);
-s->n_cache = 0;
-}
-
 static void vp9_superframe_close(AVBSFContext *ctx)
 {
 VP9BSFContext *s = ctx->priv_data;
-- 
2.20.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 03/36] avcodec/vp9_superframe_bsf: Flush bsf upon superframe creation error

2020-05-30 Thread Andreas Rheinhardt
Otherwise we might come into a situation where we have to reject future
packets because the cache is already full.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/vp9_superframe_bsf.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/libavcodec/vp9_superframe_bsf.c b/libavcodec/vp9_superframe_bsf.c
index d9c78c67f5..f330970acc 100644
--- a/libavcodec/vp9_superframe_bsf.c
+++ b/libavcodec/vp9_superframe_bsf.c
@@ -169,12 +169,10 @@ static int vp9_superframe_filter(AVBSFContext *ctx, 
AVPacket *pkt)
 av_assert0(s->n_cache > 0);
 
 // build superframe
-if ((res = merge_superframe(s->cache, s->n_cache, pkt)) < 0)
-goto done;
+res = merge_superframe(s->cache, s->n_cache, pkt);
 
-res = av_packet_copy_props(pkt, s->cache[s->n_cache - 1]);
-if (res < 0)
-goto done;
+if (res >= 0)
+res = av_packet_copy_props(pkt, s->cache[s->n_cache - 1]);
 
 vp9_superframe_flush(ctx);
 
-- 
2.20.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 04/36] avcodec/vp9_superframe_bsf: Check superframe size for overflow

2020-05-30 Thread Andreas Rheinhardt
This is not dangerous now, because init_get_bits8() already restricts
the size of each packet to INT_MAX/8 - AV_INPUT_BUFFER_PADDING_SIZE.
But it is nevertheless better to check this explicitly.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/vp9_superframe_bsf.c | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/libavcodec/vp9_superframe_bsf.c b/libavcodec/vp9_superframe_bsf.c
index f330970acc..a8b58a7fd3 100644
--- a/libavcodec/vp9_superframe_bsf.c
+++ b/libavcodec/vp9_superframe_bsf.c
@@ -42,10 +42,11 @@ static void vp9_superframe_flush(AVBSFContext *ctx)
 }
 
 static void stats(AVPacket * const *in, int n_in,
-  unsigned *_max, unsigned *_sum)
+  unsigned *_max, uint64_t *_sum)
 {
 int n;
-unsigned max = 0, sum = 0;
+uint64_t sum = 0;
+unsigned max = 0;
 
 for (n = 0; n < n_in; n++) {
 unsigned sz = in[n]->size;
@@ -61,15 +62,18 @@ static void stats(AVPacket * const *in, int n_in,
 
 static int merge_superframe(AVPacket * const *in, int n_in, AVPacket *out)
 {
-unsigned max, sum, mag, marker, n, sz;
+unsigned max, mag, marker, n;
+uint64_t sum;
 uint8_t *ptr;
 int res;
 
 stats(in, n_in, , );
 mag = av_log2(max) >> 3;
 marker = 0xC0 + (mag << 3) + (n_in - 1);
-sz = sum + 2 + (mag + 1) * n_in;
-res = av_new_packet(out, sz);
+sum += 2 + (mag + 1) * n_in;
+if (sum > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
+return AVERROR(ERANGE);
+res = av_new_packet(out, sum);
 if (res < 0)
 return res;
 ptr = out->data;
-- 
2.20.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] hwcontext_vulkan: fix make checkheaders fail

2020-05-30 Thread James Almer
On 5/30/2020 11:19 AM, James Almer wrote:
> On 5/30/2020 10:16 AM, Jun Zhao wrote:
>> From: Jun Zhao 
>>
>> make checkheaders will get error as follow:
>> CC   libavutil/hwcontext_vulkan.h.o
>> In file included from libavutil/hwcontext_vulkan.h.c:1:
>> ./libavutil/hwcontext_vulkan.h:130:23: error: ‘AV_NUM_DATA_POINTERS’ 
>> undeclared here (not in a function)
>>   130 | void *alloc_pnext[AV_NUM_DATA_POINTERS];
>>   |   ^~~~
>> ./libavutil/hwcontext_vulkan.h:199:43: warning: ‘enum AVPixelFormat’ 
>> declared inside parameter list will not be visible outside of this 
>> definition or declaration

Also include pixfmt.h while at it. Don't rely on frame.h including it.

>>
>> Signed-off-by: Jun Zhao 
>> ---
>>  libavutil/hwcontext_vulkan.h | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/libavutil/hwcontext_vulkan.h b/libavutil/hwcontext_vulkan.h
>> index aba9833..0f6a51f 100644
>> --- a/libavutil/hwcontext_vulkan.h
>> +++ b/libavutil/hwcontext_vulkan.h
>> @@ -21,6 +21,8 @@
>>  
>>  #include 
>>  
>> +#include "libavutil/frame.h"
> 
> #include "frame.h"
> 
> This file is already inside libavutil.
> 
>> +
>>  /**
>>   * @file
>>   * API-specific header for AV_HWDEVICE_TYPE_VULKAN.
>>
> 

___
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] hwcontext_vulkan: fix make checkheaders fail

2020-05-30 Thread James Almer
On 5/30/2020 10:16 AM, Jun Zhao wrote:
> From: Jun Zhao 
> 
> make checkheaders will get error as follow:
> CClibavutil/hwcontext_vulkan.h.o
> In file included from libavutil/hwcontext_vulkan.h.c:1:
> ./libavutil/hwcontext_vulkan.h:130:23: error: ‘AV_NUM_DATA_POINTERS’ 
> undeclared here (not in a function)
>   130 | void *alloc_pnext[AV_NUM_DATA_POINTERS];
>   |   ^~~~
> ./libavutil/hwcontext_vulkan.h:199:43: warning: ‘enum AVPixelFormat’ declared 
> inside parameter list will not be visible outside of this definition or 
> declaration
> 
> Signed-off-by: Jun Zhao 
> ---
>  libavutil/hwcontext_vulkan.h | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/libavutil/hwcontext_vulkan.h b/libavutil/hwcontext_vulkan.h
> index aba9833..0f6a51f 100644
> --- a/libavutil/hwcontext_vulkan.h
> +++ b/libavutil/hwcontext_vulkan.h
> @@ -21,6 +21,8 @@
>  
>  #include 
>  
> +#include "libavutil/frame.h"

#include "frame.h"

This file is already inside libavutil.

> +
>  /**
>   * @file
>   * API-specific header for AV_HWDEVICE_TYPE_VULKAN.
> 

___
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] avutil/dict: av_realloc -> av_realloc_array()

2020-05-30 Thread lance . lmwang
On Sat, May 30, 2020 at 04:03:33PM +0200, Nicolas George wrote:
> lance.lmw...@gmail.com (12020-05-30):
> > I think it's cosmetic changes, so I didn't change the alignment for the 
> > first version.
> > If it's OK, I'll update with format changes also.
> 
> Please, try to see the moon, not the finger.
> 
> Why do you think we insist on cosmetic changes on separate patches?
> Because they make reviewing the actual changes harder.
> 
> But remember, changes in patches are shown lines per line.

OK, have update and fixed the alignment also.

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


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

Re: [FFmpeg-devel] [PATCH 1/3] avutil/dict: av_realloc -> av_realloc_array()

2020-05-30 Thread James Almer
On 5/30/2020 10:55 AM, lance.lmw...@gmail.com wrote:
> On Sat, May 30, 2020 at 03:32:18PM +0200, Nicolas George wrote:
>> lance.lmw...@gmail.com (12020-05-30):
>>> From: Limin Wang 
>>>
>>> Signed-off-by: Limin Wang 
>>> ---
>>>  libavutil/dict.c | 4 ++--
>>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/libavutil/dict.c b/libavutil/dict.c
>>> index 0ea7138..a1107b1 100644
>>> --- a/libavutil/dict.c
>>> +++ b/libavutil/dict.c
>>> @@ -103,8 +103,8 @@ int av_dict_set(AVDictionary **pm, const char *key, 
>>> const char *value,
>>>  av_free(tag->key);
>>>  *tag = m->elems[--m->count];
>>>  } else if (copy_value) {
>>> -AVDictionaryEntry *tmp = av_realloc(m->elems,
>>> -(m->count + 1) * 
>>> sizeof(*m->elems));
>>
>>> +AVDictionaryEntry *tmp = av_realloc_array(m->elems,
>>> +m->count + 1, 
>>> sizeof(*m->elems));
>>
>> If you change something, make sure the alignment is correct.
> I think it's cosmetic changes, so I didn't change the alignment for the first 
> version.
> If it's OK, I'll update with format changes also.

It makes sense to not bother with cosmetics when it reduces the amount
of changed lines and a patch about functional changes, but in this case
the line in question is going to be changed no matter what, so might as
well just align it at the same time and save yourself an extra commit
for it.

> 
>>
>>>  if (!tmp)
>>>  goto err_out;
>>>  m->elems = tmp;
>>
>> 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] [PATCH v2] avutil/dict: av_realloc -> av_realloc_array()

2020-05-30 Thread lance . lmwang
From: Limin Wang 

Signed-off-by: Limin Wang 
---
 libavutil/dict.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavutil/dict.c b/libavutil/dict.c
index 0ea7138..9d3d96c 100644
--- a/libavutil/dict.c
+++ b/libavutil/dict.c
@@ -103,8 +103,8 @@ int av_dict_set(AVDictionary **pm, const char *key, const 
char *value,
 av_free(tag->key);
 *tag = m->elems[--m->count];
 } else if (copy_value) {
-AVDictionaryEntry *tmp = av_realloc(m->elems,
-(m->count + 1) * 
sizeof(*m->elems));
+AVDictionaryEntry *tmp = av_realloc_array(m->elems,
+  m->count + 1, 
sizeof(*m->elems));
 if (!tmp)
 goto err_out;
 m->elems = tmp;
-- 
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".

Re: [FFmpeg-devel] [PATCH 1/3] avutil/dict: av_realloc -> av_realloc_array()

2020-05-30 Thread Nicolas George
lance.lmw...@gmail.com (12020-05-30):
> I think it's cosmetic changes, so I didn't change the alignment for the first 
> version.
> If it's OK, I'll update with format changes also.

Please, try to see the moon, not the finger.

Why do you think we insist on cosmetic changes on separate patches?
Because they make reviewing the actual changes harder.

But remember, changes in patches are shown lines per line.

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 v5] avcodec/mpeg12enc: support mpeg2 encoder const profile

2020-05-30 Thread lance . lmwang
On Fri, May 29, 2020 at 09:07:52PM +0200, Marton Balint wrote:
> 
> 
> On Fri, 29 May 2020, lance.lmw...@gmail.com wrote:
> 
> > From: Limin Wang 
> > 
> > Signed-off-by: Limin Wang 
> > ---
> > libavcodec/mpeg12enc.c | 2 ++
> > libavcodec/profiles.h  | 6 ++
> > 2 files changed, 8 insertions(+)
> > 
> > diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
> > index cab7076..9fbbcef 100644
> > --- a/libavcodec/mpeg12enc.c
> > +++ b/libavcodec/mpeg12enc.c
> > @@ -41,6 +41,7 @@
> > #include "mpeg12data.h"
> > #include "mpegutils.h"
> > #include "mpegvideo.h"
> > +#include "profiles.h"
> > 
> > static const uint8_t svcd_scan_offset_placeholder[] = {
> > 0x10, 0x0E, 0x00, 0x80, 0x81, 0x00, 0x80,
> > @@ -1167,6 +1168,7 @@ static const AVOption mpeg2_options[] = {
> > { "mac",  NULL, 0, AV_OPT_TYPE_CONST,  {.i64 = 
> > VIDEO_FORMAT_MAC},  0, 0, VE, "video_format" },
> > { "unspecified",  NULL, 0, AV_OPT_TYPE_CONST,  {.i64 = 
> > VIDEO_FORMAT_UNSPECIFIED},  0, 0, VE, "video_format" },
> > FF_MPV_COMMON_OPTS
> > +FF_MPEG2_PROFILE_OPTS
> > { NULL },
> > };
> > 
> > diff --git a/libavcodec/profiles.h b/libavcodec/profiles.h
> > index e414ea7..d6a139e 100644
> > --- a/libavcodec/profiles.h
> > +++ b/libavcodec/profiles.h
> > @@ -43,6 +43,12 @@
> > FF_AVCTX_PROFILE_OPTION("mpeg4_main",NULL, VIDEO, 
> > FF_PROFILE_MPEG4_MAIN)\
> > FF_AVCTX_PROFILE_OPTION("mpeg4_asp", NULL, VIDEO, 
> > FF_PROFILE_MPEG4_ADVANCED_SIMPLE)\
> > 
> > +#define FF_MPEG2_PROFILE_OPTS \
> > +FF_AVCTX_PROFILE_OPTION("mpeg2_422", NULL, VIDEO, 
> > FF_PROFILE_MPEG2_422)\
> > +FF_AVCTX_PROFILE_OPTION("mpeg2_high",NULL, VIDEO, 
> > FF_PROFILE_MPEG2_HIGH)\
> > +FF_AVCTX_PROFILE_OPTION("mpeg2_main",NULL, VIDEO, 
> > FF_PROFILE_MPEG2_MAIN)\
> > +FF_AVCTX_PROFILE_OPTION("mpeg2_simple",  NULL, VIDEO, 
> > FF_PROFILE_MPEG2_SIMPLE)\
> 
> You no longer need the mpeg2 prefix. Also please add the supported profiles
> to the documentation of the mpeg2 encoder. There are also some profiles
> (spatially scalable and snr scalable) missing. Is it intentional?

I have update the patch, after further consideration, I add ss and snr scalable 
profile,
as user can set it by integer(2 and 3) still, so it's better to keep them 
consistent.
> 
> Thanks,
> Marton
> 
> > +
> > extern const AVProfile ff_aac_profiles[];
> > extern const AVProfile ff_dca_profiles[];
> > extern const AVProfile ff_dnxhd_profiles[];
> > -- 
> > 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".

Re: [FFmpeg-devel] [PATCH 1/3] avutil/dict: av_realloc -> av_realloc_array()

2020-05-30 Thread lance . lmwang
On Sat, May 30, 2020 at 03:32:18PM +0200, Nicolas George wrote:
> lance.lmw...@gmail.com (12020-05-30):
> > From: Limin Wang 
> > 
> > Signed-off-by: Limin Wang 
> > ---
> >  libavutil/dict.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/libavutil/dict.c b/libavutil/dict.c
> > index 0ea7138..a1107b1 100644
> > --- a/libavutil/dict.c
> > +++ b/libavutil/dict.c
> > @@ -103,8 +103,8 @@ int av_dict_set(AVDictionary **pm, const char *key, 
> > const char *value,
> >  av_free(tag->key);
> >  *tag = m->elems[--m->count];
> >  } else if (copy_value) {
> > -AVDictionaryEntry *tmp = av_realloc(m->elems,
> > -(m->count + 1) * 
> > sizeof(*m->elems));
> 
> > +AVDictionaryEntry *tmp = av_realloc_array(m->elems,
> > +m->count + 1, 
> > sizeof(*m->elems));
> 
> If you change something, make sure the alignment is correct.
I think it's cosmetic changes, so I didn't change the alignment for the first 
version.
If it's OK, I'll update with format changes also.

> 
> >  if (!tmp)
> >  goto err_out;
> >  m->elems = tmp;
> 
> Regards,
> 
> -- 
>   Nicolas George



-- 
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/2] checkasm: sw_rgb: Fix mixed declaration and code

2020-05-30 Thread Jun Zhao
From: Jun Zhao 

Fix mixed declaration and code.

Signed-off-by: Jun Zhao 
---
 tests/checkasm/sw_rgb.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tests/checkasm/sw_rgb.c b/tests/checkasm/sw_rgb.c
index 1e8ea15..e5aad20 100644
--- a/tests/checkasm/sw_rgb.c
+++ b/tests/checkasm/sw_rgb.c
@@ -137,12 +137,13 @@ static void check_interleave_bytes(void)
 int w = i > 0 ? i : (1 + (rnd() % (MAX_STRIDE-2)));
 int h = 1 + (rnd() % (MAX_HEIGHT-2));
 
-memset(dst0, 0, 2 * MAX_STRIDE * MAX_HEIGHT);
-memset(dst1, 0, 2 * MAX_STRIDE * MAX_HEIGHT);
-
 int src0_offset = 0, src0_stride = MAX_STRIDE;
 int src1_offset = 0, src1_stride = MAX_STRIDE;
 int dst_offset  = 0, dst_stride  = 2 * MAX_STRIDE;
+
+memset(dst0, 0, 2 * MAX_STRIDE * MAX_HEIGHT);
+memset(dst1, 0, 2 * MAX_STRIDE * MAX_HEIGHT);
+
 // Try different combinations of negative strides
 if (i & 1) {
 src0_offset = (h-1)*src0_stride;
-- 
2.7.4

___
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] hwcontext_vulkan: fix make checkheaders fail

2020-05-30 Thread Jun Zhao
From: Jun Zhao 

make checkheaders will get error as follow:
CC  libavutil/hwcontext_vulkan.h.o
In file included from libavutil/hwcontext_vulkan.h.c:1:
./libavutil/hwcontext_vulkan.h:130:23: error: ‘AV_NUM_DATA_POINTERS’ undeclared 
here (not in a function)
  130 | void *alloc_pnext[AV_NUM_DATA_POINTERS];
  |   ^~~~
./libavutil/hwcontext_vulkan.h:199:43: warning: ‘enum AVPixelFormat’ declared 
inside parameter list will not be visible outside of this definition or 
declaration

Signed-off-by: Jun Zhao 
---
 libavutil/hwcontext_vulkan.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavutil/hwcontext_vulkan.h b/libavutil/hwcontext_vulkan.h
index aba9833..0f6a51f 100644
--- a/libavutil/hwcontext_vulkan.h
+++ b/libavutil/hwcontext_vulkan.h
@@ -21,6 +21,8 @@
 
 #include 
 
+#include "libavutil/frame.h"
+
 /**
  * @file
  * API-specific header for AV_HWDEVICE_TYPE_VULKAN.
-- 
2.7.4

___
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/3] avcodec/alac: Add FF_CODEC_CAP_INIT_CLEANUP

2020-05-30 Thread lance . lmwang
From: Limin Wang 

Signed-off-by: Limin Wang 
---
 libavcodec/alac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 82689da..3b41373 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -511,7 +511,6 @@ static int allocate_buffers(ALACContext *alac)
 }
 return 0;
 buf_alloc_fail:
-alac_decode_close(alac->avctx);
 return AVERROR(ENOMEM);
 }
 
@@ -625,5 +624,6 @@ AVCodec ff_alac_decoder = {
 .close  = alac_decode_close,
 .decode = alac_decode_frame,
 .capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
+.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
 .priv_class = _class
 };
-- 
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".

Re: [FFmpeg-devel] [PATCH 1/3] avutil/dict: av_realloc -> av_realloc_array()

2020-05-30 Thread Nicolas George
lance.lmw...@gmail.com (12020-05-30):
> From: Limin Wang 
> 
> Signed-off-by: Limin Wang 
> ---
>  libavutil/dict.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libavutil/dict.c b/libavutil/dict.c
> index 0ea7138..a1107b1 100644
> --- a/libavutil/dict.c
> +++ b/libavutil/dict.c
> @@ -103,8 +103,8 @@ int av_dict_set(AVDictionary **pm, const char *key, const 
> char *value,
>  av_free(tag->key);
>  *tag = m->elems[--m->count];
>  } else if (copy_value) {
> -AVDictionaryEntry *tmp = av_realloc(m->elems,
> -(m->count + 1) * 
> sizeof(*m->elems));

> +AVDictionaryEntry *tmp = av_realloc_array(m->elems,
> +m->count + 1, sizeof(*m->elems));

If you change something, make sure the alignment is correct.

>  if (!tmp)
>  goto err_out;
>  m->elems = tmp;

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 3/3] avcodec/alac: remove FF_ALLOC_OR_GOTO and gotos label

2020-05-30 Thread lance . lmwang
From: Limin Wang 

Signed-off-by: Limin Wang 
---
 libavcodec/alac.c | 15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 3b41373..bf05406 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -489,6 +489,7 @@ static int allocate_buffers(ALACContext *alac)
 {
 int ch;
 unsigned buf_size = alac->max_samples_per_frame * sizeof(int32_t);
+unsigned extra_buf_size = buf_size + AV_INPUT_BUFFER_PADDING_SIZE;
 
 for (ch = 0; ch < 2; ch++) {
 alac->predict_error_buffer[ch]  = NULL;
@@ -497,21 +498,19 @@ static int allocate_buffers(ALACContext *alac)
 }
 
 for (ch = 0; ch < FFMIN(alac->channels, 2); ch++) {
-FF_ALLOC_OR_GOTO(alac->avctx, alac->predict_error_buffer[ch],
- buf_size, buf_alloc_fail);
+if (!(alac->predict_error_buffer[ch] = av_malloc(buf_size)))
+return AVERROR(ENOMEM);
 
 alac->direct_output = alac->sample_size > 16;
 if (!alac->direct_output) {
-FF_ALLOC_OR_GOTO(alac->avctx, alac->output_samples_buffer[ch],
- buf_size + AV_INPUT_BUFFER_PADDING_SIZE, 
buf_alloc_fail);
+if (!(alac->output_samples_buffer[ch] = av_malloc(extra_buf_size)))
+return AVERROR(ENOMEM);
 }
 
-FF_ALLOC_OR_GOTO(alac->avctx, alac->extra_bits_buffer[ch],
- buf_size + AV_INPUT_BUFFER_PADDING_SIZE, 
buf_alloc_fail);
+if (!(alac->extra_bits_buffer[ch] = av_malloc(extra_buf_size)))
+return AVERROR(ENOMEM);
 }
 return 0;
-buf_alloc_fail:
-return AVERROR(ENOMEM);
 }
 
 static int alac_set_info(ALACContext *alac)
-- 
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 1/3] avutil/dict: av_realloc -> av_realloc_array()

2020-05-30 Thread lance . lmwang
From: Limin Wang 

Signed-off-by: Limin Wang 
---
 libavutil/dict.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavutil/dict.c b/libavutil/dict.c
index 0ea7138..a1107b1 100644
--- a/libavutil/dict.c
+++ b/libavutil/dict.c
@@ -103,8 +103,8 @@ int av_dict_set(AVDictionary **pm, const char *key, const 
char *value,
 av_free(tag->key);
 *tag = m->elems[--m->count];
 } else if (copy_value) {
-AVDictionaryEntry *tmp = av_realloc(m->elems,
-(m->count + 1) * 
sizeof(*m->elems));
+AVDictionaryEntry *tmp = av_realloc_array(m->elems,
+m->count + 1, sizeof(*m->elems));
 if (!tmp)
 goto err_out;
 m->elems = tmp;
-- 
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 v6] avcodec/mpeg12enc: support mpeg2 encoder const profile

2020-05-30 Thread lance . lmwang
From: Limin Wang 

Signed-off-by: Limin Wang 
---
 doc/encoders.texi  | 14 ++
 libavcodec/mpeg12enc.c |  2 ++
 libavcodec/profiles.h  |  8 
 3 files changed, 24 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 954f0f6..1331b79 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2740,6 +2740,20 @@ MPEG-2 video encoder.
 @subsection Options
 
 @table @option
+@item profile @var{integer}
+Select the mpeg2 profile to encode:
+
+@table @samp
+@item 422
+@item main
+@item ss
+Spatially Scalable
+@item snr
+SNR Scalable
+@item high
+@item simple
+@end table
+
 @item seq_disp_ext @var{integer}
 Specifies if the encoder should write a sequence_display_extension to the
 output.
diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index cab7076..9fbbcef 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -41,6 +41,7 @@
 #include "mpeg12data.h"
 #include "mpegutils.h"
 #include "mpegvideo.h"
+#include "profiles.h"
 
 static const uint8_t svcd_scan_offset_placeholder[] = {
 0x10, 0x0E, 0x00, 0x80, 0x81, 0x00, 0x80,
@@ -1167,6 +1168,7 @@ static const AVOption mpeg2_options[] = {
 { "mac",  NULL, 0, AV_OPT_TYPE_CONST,  {.i64 = 
VIDEO_FORMAT_MAC},  0, 0, VE, "video_format" },
 { "unspecified",  NULL, 0, AV_OPT_TYPE_CONST,  {.i64 = 
VIDEO_FORMAT_UNSPECIFIED},  0, 0, VE, "video_format" },
 FF_MPV_COMMON_OPTS
+FF_MPEG2_PROFILE_OPTS
 { NULL },
 };
 
diff --git a/libavcodec/profiles.h b/libavcodec/profiles.h
index e414ea7..d241925 100644
--- a/libavcodec/profiles.h
+++ b/libavcodec/profiles.h
@@ -43,6 +43,14 @@
 FF_AVCTX_PROFILE_OPTION("mpeg4_main",NULL, VIDEO, 
FF_PROFILE_MPEG4_MAIN)\
 FF_AVCTX_PROFILE_OPTION("mpeg4_asp", NULL, VIDEO, 
FF_PROFILE_MPEG4_ADVANCED_SIMPLE)\
 
+#define FF_MPEG2_PROFILE_OPTS \
+FF_AVCTX_PROFILE_OPTION("422",   NULL, VIDEO, 
FF_PROFILE_MPEG2_422)\
+FF_AVCTX_PROFILE_OPTION("high",  NULL, VIDEO, 
FF_PROFILE_MPEG2_HIGH)\
+FF_AVCTX_PROFILE_OPTION("ss",NULL, VIDEO, FF_PROFILE_MPEG2_SS)\
+FF_AVCTX_PROFILE_OPTION("snr",   NULL, VIDEO, 
FF_PROFILE_MPEG2_SNR_SCALABLE)\
+FF_AVCTX_PROFILE_OPTION("main",  NULL, VIDEO, 
FF_PROFILE_MPEG2_MAIN)\
+FF_AVCTX_PROFILE_OPTION("simple",NULL, VIDEO, 
FF_PROFILE_MPEG2_SIMPLE)\
+
 extern const AVProfile ff_aac_profiles[];
 extern const AVProfile ff_dca_profiles[];
 extern const AVProfile ff_dnxhd_profiles[];
-- 
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".

Re: [FFmpeg-devel] [PATCH v2 2/2] lavfi/aiir: Refine the pad/vpad related operation

2020-05-30 Thread Hendrik Leppkes
On Sat, May 30, 2020 at 1:05 PM Paul B Mahol  wrote:
>
> Nobody approved this, so revert ASAP!
>

Simple changes don't need to be approved, as long as they are on the
list for long enough, otherwise nothing would ever get done. If you
want to review them, you should do it before they've been on the list
for several days and thus get committed.

- Hendrik
___
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 7/7] avcodec/adpcmenc: remove gotos and error label

2020-05-30 Thread lance . lmwang
On Fri, May 29, 2020 at 01:02:34PM +0800, lance.lmw...@gmail.com wrote:
> From: Limin Wang 
> 
> Signed-off-by: Limin Wang 
> ---
>  libavcodec/adpcmenc.c | 13 +++--
>  1 file changed, 3 insertions(+), 10 deletions(-)
> 
> diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c
> index bcb6783c0c..52f0f67958 100644
> --- a/libavcodec/adpcmenc.c
> +++ b/libavcodec/adpcmenc.c
> @@ -65,7 +65,6 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx)
>  ADPCMEncodeContext *s = avctx->priv_data;
>  uint8_t *extradata;
>  int i;
> -int ret = AVERROR(ENOMEM);
>  
>  if (avctx->channels > 2) {
>  av_log(avctx, AV_LOG_ERROR, "only stereo or mono is supported\n");
> @@ -120,7 +119,7 @@ static av_cold int adpcm_encode_init(AVCodecContext 
> *avctx)
>  avctx->bits_per_coded_sample = 4;
>  avctx->block_align= BLKSIZE;
>  if (!(avctx->extradata = av_malloc(32 + 
> AV_INPUT_BUFFER_PADDING_SIZE)))
> -goto error;
> +return AVERROR(ENOMEM);
>  avctx->extradata_size = 32;
>  extradata = avctx->extradata;
>  bytestream_put_le16(, avctx->frame_size);
> @@ -140,8 +139,7 @@ static av_cold int adpcm_encode_init(AVCodecContext 
> *avctx)
>  avctx->sample_rate != 44100) {
>  av_log(avctx, AV_LOG_ERROR, "Sample rate must be 11025, "
> "22050 or 44100\n");
> -ret = AVERROR(EINVAL);
> -goto error;
> +return AVERROR(EINVAL);
>  }
>  avctx->frame_size = 512 * (avctx->sample_rate / 11025);
>  break;
> @@ -150,13 +148,10 @@ static av_cold int adpcm_encode_init(AVCodecContext 
> *avctx)
>  avctx->block_align = BLKSIZE;
>  break;
>  default:
> -ret = AVERROR(EINVAL);
> -goto error;
> +return AVERROR(EINVAL);
>  }
>  
>  return 0;
> -error:
> -return ret;
>  }
>  
>  static av_cold int adpcm_encode_close(AVCodecContext *avctx)
> @@ -725,8 +720,6 @@ static int adpcm_encode_frame(AVCodecContext *avctx, 
> AVPacket *avpkt,
>  avpkt->size = pkt_size;
>  *got_packet_ptr = 1;
>  return 0;
> -error:
> -return AVERROR(ENOMEM);
>  }
>  

any objection for the remove for the gotos? if no, I'll continue to work on 
removing more such condition.


>  static const enum AVSampleFormat sample_fmts[] = {
> -- 
> 2.21.0
> 

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

Re: [FFmpeg-devel] [PATCH] avcodec/mv30: fix warning: suggest braces around initialization of subobject [-Wmissing-braces]

2020-05-30 Thread lance . lmwang
On Sat, May 30, 2020 at 01:34:03PM +0200, Nicolas George wrote:
> lance.lmw...@gmail.com (12020-05-30):
> > > -int pfill[3][1] = { 0 };
> > > +int pfill[3][1] = { {0} };
> 
> > will apply it tomorow if no objection.
> 
> This warning is bogus, the code is valid and a common pattern in FFmpeg.
> IIRC, we decided to keep it that way when it happens.

Thanks for the explanation. It's difficult to know it's been discussed before.

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


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

Re: [FFmpeg-devel] [PATCH] avcodec/mv30: fix warning: suggest braces around initialization of subobject [-Wmissing-braces]

2020-05-30 Thread Nicolas George
lance.lmw...@gmail.com (12020-05-30):
> > -int pfill[3][1] = { 0 };
> > +int pfill[3][1] = { {0} };

> will apply it tomorow if no objection.

This warning is bogus, the code is valid and a common pattern in FFmpeg.
IIRC, we decided to keep it that way when it happens.

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] avcodec/mv30: fix warning: suggest braces around initialization of subobject [-Wmissing-braces]

2020-05-30 Thread lance . lmwang
On Tue, May 12, 2020 at 11:09:19PM +0800, lance.lmw...@gmail.com wrote:
> From: Limin Wang 
> 
> Signed-off-by: Limin Wang 
> ---
>  libavcodec/mv30.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/mv30.c b/libavcodec/mv30.c
> index fed9bcd..7e67133 100644
> --- a/libavcodec/mv30.c
> +++ b/libavcodec/mv30.c
> @@ -421,7 +421,7 @@ static int decode_intra(AVCodecContext *avctx, 
> GetBitContext *gb, AVFrame *frame
>  
>  for (int y = 0; y < avctx->height; y += 16) {
>  GetByteContext gbyte;
> -int pfill[3][1] = { 0 };
> +int pfill[3][1] = { {0} };
>  int nb_codes = get_bits(gb, 16);
>  
>  av_fast_padded_malloc(>coeffs, >coeffs_size, nb_codes * 
> sizeof(*s->coeffs));
> @@ -504,7 +504,7 @@ static int decode_inter(AVCodecContext *avctx, 
> GetBitContext *gb,
>  
>  for (int y = 0; y < avctx->height; y += 16) {
>  GetByteContext gbyte;
> -int pfill[3][1] = { 0 };
> +int pfill[3][1] = { {0} };
>  int nb_codes = get_bits(gb, 16);
>  
>  skip_bits(gb, 8);
> -- 
> 1.8.3.1
> 

will apply it tomorow if no objection.


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

Re: [FFmpeg-devel] [PATCH v2 2/2] lavfi/aiir: Refine the pad/vpad related operation

2020-05-30 Thread Paul B Mahol
Nobody approved this, so revert ASAP!

On 5/25/20, Jun Zhao  wrote:
> From: Jun Zhao 
>
> move the pad/vpad related operation with more natural
> coding style.
>
> Signed-off-by: Jun Zhao 
> ---
>  libavfilter/af_aiir.c | 10 --
>  1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/libavfilter/af_aiir.c b/libavfilter/af_aiir.c
> index 92ff348..7971cf2 100644
> --- a/libavfilter/af_aiir.c
> +++ b/libavfilter/af_aiir.c
> @@ -1153,6 +1153,10 @@ static av_cold int init(AVFilterContext *ctx)
>  if (!pad.name)
>  return AVERROR(ENOMEM);
>
> +ret = ff_insert_outpad(ctx, 0, );
> +if (ret < 0)
> +return ret;
> +
>  if (s->response) {
>  vpad = (AVFilterPad){
>  .name = av_strdup("filter_response"),
> @@ -1161,13 +1165,7 @@ static av_cold int init(AVFilterContext *ctx)
>  };
>  if (!vpad.name)
>  return AVERROR(ENOMEM);
> -}
>
> -ret = ff_insert_outpad(ctx, 0, );
> -if (ret < 0)
> -return ret;
> -
> -if (s->response) {
>  ret = ff_insert_outpad(ctx, 1, );
>  if (ret < 0)
>  return ret;
> --
> 2.7.4
>
> ___
> 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] libavutil: add clean aperture (CLAP) side data.

2020-05-30 Thread Kieran O Leary
Hi,

On Fri 29 May 2020, 22:47 Neil Birkbeck,  wrote:

> On Mon, May 11, 2020 at 9:37 PM Neil Birkbeck 
> wrote:
>
> >
> >
> > On Wed, May 6, 2020 at 8:45 AM James Almer  wrote:
> >
> >> On 5/6/2020 12:22 PM, Neil Birkbeck wrote:
> >> > On Tue, May 5, 2020 at 5:11 AM Kieran O Leary <
> kieran.o.le...@gmail.com
> >> >
> >> > wrote:
> >> >
> >> >> Hi,
> >> >>
> >> >> I broke the threading with my last reply, i apologise. Here goes
> >> another
> >> >> attempt:
> >> >>
> >> >> On Tue, Apr 28, 2020 at 6:23 PM Neil Birkbeck <
> neil.birkb...@gmail.com
> >> >
> >> >> wrote:
> >> >>
> >> >>> On Tue, Apr 28, 2020 at 3:18 AM Nicolas George 
> >> wrote:
> >> >>>
> >>  Andreas Rheinhardt (12020-04-28):
> >> > That's expected. The patch provided only provides the structure in
> >> >>> which
> >> > the values are intended to be exported; it does not add any
> demuxing
> >> >> or
> >> > muxing capabilities for mov or mkv (as you can see from the fact
> >> that
> >> > none of these (de)muxers have been changed in the patch).
> >> 
> >>  Which is something I intended to comment on: adding code without
> >> users
> >>  is rarely a good idea. I suggest we do not commit until at least
> one
> >>  demuxer use it, preferably at least two. Otherwise, we may realize
> >> that
> >>  “oh crap, it doesn't work” because of a tiny unforeseen detail.
> >> >>>
> >> >>>
> >> >>> Thanks for the feedback. I also have patches for the demux (MOV/MKV)
> >> and
> >> >>> mux (MOV/MKV).
> >> >>>
> >> >>> As there is still the alternative of using the fields in the
> >> >>> AVCodecParameters/AVCodecContext, my intention was to keep the first
> >> >> patch
> >> >>> small to resolve discussion on that point.
> >> >>>
> >> >>> I've included the patches, if you'd like to try test it, Kieren. I
> >> see on
> >> >>> your test file that there may be some slight rounding error making
> >> output
> >> >>> crop 704 not 703 (MKV file ends up with pixel_crop_{left,right} =
> 8).
> >> >>>
> >> >>> /ffprobe ../testdata/clap.mov 2>&1 | grep -A1 "Side"
> >> >>> Side data:
> >> >>>   Clean aperture:[width 41472/59 height:576/1 h_offset:0/1
> >> >>> v_offset:0/1]
> >> >>> ./ffmpeg -i ../testdata/clap.mov  -vcodec copy -acodec copy
> >> /tmp/clap.mkv
> >> >>> ./ffprobe /tmp/clap.mkv 2>&1 | grep -A1 "Side"
> >> >>> Side data:
> >> >>>   Clean aperture:[width 704/1 height:576/1 h_offset:0/1
> >> v_offset:0/1]
> >> >>>
> >> >>
> >> >> I have to look deeper into the MKV side of things and most likely
> >> raise it
> >> >> with the cellar mailing list so that better minds than mine can weigh
> >> in. I
> >> >> do see that the rounding up to 704 could be an issue alright.
> >> >> As for MOV, your patch appears to generate the same output clap
> values
> >> as
> >> >> the input, so that's really great! command line and mediainfo trace
> >> below:
> >> >>
> >> >
> >> > Thanks for testing, Kieran and for linking the discussion on the
> cellar
> >> > list.
> >> >
> >> > Any additional thoughts from ffmpeg devs on container-level SideData
> vs
> >> > adding the extra fields into AVCodecParameters/AVCodecContext and
> >> plumbing
> >> > into the frame instead? I anticipate some situations where there can
> be
> >> > interaction between cropping in bitstream and container-level
> cropping.
> >> > Maybe the best way forward is for me to share some sample patches for
> >> the
> >> > alternative to validate whether it supports the various use cases
> >> > (transmux, decode+crop, any other application level handling), and to
> >> > confirm the interface changes for the structs.
> >>
> >> One option could be to also introduce a frame side data for this new
> >> struct and have it replace the AVFrame fields, which would then be
> >> deprecated (But of course keep working until removed).
> >> This would allow to either inject stream side data from clap atoms and
> >> Matroska crop fields into packets (Which would then be propagated to
> >> frames to be applied during decoding), or use and export the bitstream
> >> cropping information as it's the case right now, all while preventing
> >> the addition of new fields to AVCodecParameters.
> >>
> >>
> > I agree that sharing the SideData with the frame could be nice for the
> > above reasons. I guess any interaction or conflict between bitstream &
> > container cropping could then get resolved at the decoder (e.g., assuming
> > that say SPS from h264 and container-level cropping should be composed).
> >
> >
> >> I would like a developer that makes use of this feature to also comment,
> >> especially seeing how the AVFrame fields and this clap side data are
> >> pretty different.
> >>
> >
> > The current CleanAperture representation was in part motivated to 1) keep
> > the representation capable of representing the CLAP atom (same
> > representation and rationals), and 2) to make it unambiguous that this
> was
> > container-level stream metadata. The representation is a tiny bit more

Re: [FFmpeg-devel] [PATCH] avutil/attributes: Fix too many warning: false is not defined [-Wundef]

2020-05-30 Thread lance . lmwang
On Sat, May 30, 2020 at 01:27:30AM +0200, Hendrik Leppkes wrote:
> On Fri, May 29, 2020 at 11:46 PM Carl Eugen Hoyos  wrote:
> >
> >
> >
> >
> > > Am 29.05.2020 um 13:18 schrieb lance.lmw...@gmail.com:
> > >
> > > From: Limin Wang 
> > >
> > > Signed-off-by: Limin Wang 
> > > ---
> > > try to avoid floods of warning message for my testing linux host. If you
> > > have better way, fix it anyway.
> > >
> > > Below is my Linux system information and gcc version:
> > >
> > > [lmwang@vpn2 ffmpeg.git]$ gcc -v
> > > Using built-in specs.
> > > COLLECT_GCC=gcc
> > > COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
> > > Target: x86_64-redhat-linux
> > > Configured with: ../configure --prefix=/usr --mandir=/usr/share/man 
> > > --infodir=/usr/share/info 
> > > --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap 
> > > --enable-shared --enable-threads=posix --enable-checking=release 
> > > --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions 
> > > --enable-gnu-unique-object --enable-linker-build-id 
> > > --with-linker-hash-style=gnu 
> > > --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto 
> > > --enable-plugin --enable-initfini-array --disable-libgcj 
> > > --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install
> > >  
> > > --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install
> > >  --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 
> > > --build=x86_64-redhat-linux
> > > Thread model: posix
> > > gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
> > > [lmwang@vpn2 ffmpeg.git]$ cat /etc/centos-release
> > > CentOS Linux release 7.4.1708 (Core)
> > >
> > > libavutil/attributes.h | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/libavutil/attributes.h b/libavutil/attributes.h
> > > index ab2a1fd..5cb9fe3 100644
> > > --- a/libavutil/attributes.h
> > > +++ b/libavutil/attributes.h
> > > @@ -37,7 +37,7 @@
> > > #ifdef __has_builtin
> > > #define AV_HAS_BUILTIN(x) __has_builtin(x)
> > > #else
> > > -#define AV_HAS_BUILTIN(x) false
> > > +#define AV_HAS_BUILTIN(x) 0
> > > #endif
> >
> > Please move the define to an internal header.
> >
> > This has to be detected in configure, I just have to find time to implement 
> > this.
> >
> 
> Your request is not related to a fix for these warnings. The original
> patch is fine as-is, any further changes can and should be done
> seperately, if there is a consensus to do them.

thanks, will apply.

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

Re: [FFmpeg-devel] [PATCH v2] avfilter/vf_lut3d: prelut support for 3d cinespace luts

2020-05-30 Thread Paul B Mahol
LGTM

On 5/24/20, mindm...@gmail.com  wrote:
> From: Mark Reid 
>
> changes since v1:
> * cleaned up code style
> * slightly reworked apply_lut functions to feel more consistent with code
>
> ---
>  libavfilter/vf_lut3d.c | 372 +++--
>  1 file changed, 317 insertions(+), 55 deletions(-)
>
> diff --git a/libavfilter/vf_lut3d.c b/libavfilter/vf_lut3d.c
> index 482e2394a7..e5d9fcc068 100644
> --- a/libavfilter/vf_lut3d.c
> +++ b/libavfilter/vf_lut3d.c
> @@ -59,6 +59,15 @@ struct rgbvec {
>  /* 3D LUT don't often go up to level 32, but it is common to have a Hald
> CLUT
>   * of 512x512 (64x64x64) */
>  #define MAX_LEVEL 256
> +#define PRELUT_SIZE 65536
> +
> +typedef struct Lut3DPreLut {
> +int size;
> +float min[3];
> +float max[3];
> +float scale[3];
> +float* lut[3];
> +} Lut3DPreLut;
>
>  typedef struct LUT3DContext {
>  const AVClass *class;
> @@ -71,6 +80,7 @@ typedef struct LUT3DContext {
>  struct rgbvec *lut;
>  int lutsize;
>  int lutsize2;
> +Lut3DPreLut prelut;
>  #if CONFIG_HALDCLUT_FILTER
>  uint8_t clut_rgba_map[4];
>  int clut_step;
> @@ -234,11 +244,39 @@ static inline struct rgbvec interp_tetrahedral(const
> LUT3DContext *lut3d,
>  return c;
>  }
>
> +static inline float prelut_interp_1d_linear(const Lut3DPreLut *prelut,
> +int idx, const float s)
> +{
> +const int lut_max = prelut->size - 1;
> +const float scaled = (s - prelut->min[idx]) * prelut->scale[idx];
> +const float x = av_clipf(scaled, 0.0f, lut_max);
> +const int prev = PREV(x);
> +const int next = FFMIN((int)(x) + 1, lut_max);
> +const float p = prelut->lut[idx][prev];
> +const float n = prelut->lut[idx][next];
> +const float d = x - (float)prev;
> +return lerpf(p, n, d);
> +}
> +
> +static inline struct rgbvec apply_prelut(const Lut3DPreLut *prelut,
> + const struct rgbvec *s)
> +{
> +if (prelut->size <= 0)
> +return *s;
> +
> +struct rgbvec c;
> +c.r = prelut_interp_1d_linear(prelut, 0, s->r);
> +c.g = prelut_interp_1d_linear(prelut, 1, s->g);
> +c.b = prelut_interp_1d_linear(prelut, 2, s->b);
> +return c;
> +}
> +
>  #define DEFINE_INTERP_FUNC_PLANAR(name, nbits, depth)
>\
>  static int interp_##nbits##_##name##_p##depth(AVFilterContext *ctx, void
> *arg, int jobnr, int nb_jobs) \
>  {
>\
>  int x, y;
>\
>  const LUT3DContext *lut3d = ctx->priv;
>\
> +const Lut3DPreLut *prelut = >prelut;
>\
>  const ThreadData *td = arg;
>\
>  const AVFrame *in  = td->in;
>\
>  const AVFrame *out = td->out;
>\
> @@ -253,9 +291,11 @@ static int
> interp_##nbits##_##name##_p##depth(AVFilterContext *ctx, void *arg, i
>  const uint8_t *srcbrow = in->data[1] + slice_start * in->linesize[1];
>\
>  const uint8_t *srcrrow = in->data[2] + slice_start * in->linesize[2];
>\
>  const uint8_t *srcarow = in->data[3] + slice_start * in->linesize[3];
>\
> -const float scale_r = (lut3d->scale.r / ((1< (lut3d->lutsize - 1);  \
> -const float scale_g = (lut3d->scale.g / ((1< (lut3d->lutsize - 1);  \
> -const float scale_b = (lut3d->scale.b / ((1< (lut3d->lutsize - 1);  \
> +const float lut_max = lut3d->lutsize - 1;
>\
> +const float scale_f = 1.0f / ((1<\
> +const float scale_r = lut3d->scale.r * lut_max;
>\
> +const float scale_g = lut3d->scale.g * lut_max;
>\
> +const float scale_b = lut3d->scale.b * lut_max;
>\
>
>\
>  for (y = slice_start; y < slice_end; y++) {
>\
>  uint##nbits##_t *dstg = (uint##nbits##_t *)grow;
>\
> @@ -267,9 +307,13 @@ static int
> interp_##nbits##_##name##_p##depth(AVFilterContext *ctx, void *arg, i
>  const uint##nbits##_t *srcr = (const uint##nbits##_t *)srcrrow;
>\
>  const uint##nbits##_t *srca = (const uint##nbits##_t *)srcarow;
>\
>  for (x = 0; x < in->width; x++) {
>\
> -const struct rgbvec scaled_rgb = {srcr[x] * scale_r,
>\
> -  srcg[x] * scale_g,
>\
> -  srcb[x] * scale_b};
>\
> +const struct rgbvec rgb = {srcr[x] * scale_f,
>  

[FFmpeg-devel] [PATCH 4/4] lavf/tls: verify TLS connections by default whenever possible

2020-05-30 Thread rcombs
---
 libavformat/tls.c | 13 +
 libavformat/tls.h |  2 +-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/libavformat/tls.c b/libavformat/tls.c
index 10e0792e29..3cf24ca056 100644
--- a/libavformat/tls.c
+++ b/libavformat/tls.c
@@ -64,6 +64,19 @@ int ff_tls_open_underlying(TLSShared *c, URLContext *parent, 
const char *uri, AV
 
 set_options(c, uri);
 
+if (c->verify < 0) {
+c->verify = c->listen;
+#if CONFIG_MBEDTLS
+if (!c->listen && !c->ca_file) {
+av_log(parent, AV_LOG_WARNING, "ffmpeg was configured with mbedTLS 
and no root CA store was provided,\n"
+   "so this connection will be made 
insecurely.\n"
+   "To make this connection securely, 
specify a path to a root bundle\n"
+   "with the 'ca_file' option.");
+c->verify = 0;
+}
+#endif
+}
+
 if (c->listen)
 snprintf(opts, sizeof(opts), "?listen=1");
 
diff --git a/libavformat/tls.h b/libavformat/tls.h
index 6c2d025f6c..e4854c28da 100644
--- a/libavformat/tls.h
+++ b/libavformat/tls.h
@@ -45,7 +45,7 @@ typedef struct TLSShared {
 #define TLS_COMMON_OPTIONS(pstruct, options_field) \
 {"ca_file","Certificate Authority database file", offsetof(pstruct, 
options_field . ca_file),   AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \
 {"cafile", "Certificate Authority database file", offsetof(pstruct, 
options_field . ca_file),   AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \
-{"tls_verify", "Verify the peer certificate", offsetof(pstruct, 
options_field . verify),AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, .flags = 
TLS_OPTFL }, \
+{"tls_verify", "Verify the peer certificate", offsetof(pstruct, 
options_field . verify),AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, .flags = 
TLS_OPTFL }, \
 {"cert_file",  "Certificate file",offsetof(pstruct, 
options_field . cert_file), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \
 {"key_file",   "Private key file",offsetof(pstruct, 
options_field . key_file),  AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \
 {"listen", "Listen for incoming connections", offsetof(pstruct, 
options_field . listen),AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, .flags = 
TLS_OPTFL }, \
-- 
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] lavf/tls: use AV_OPT_TYPE_BOOL

2020-05-30 Thread rcombs
---
 libavformat/tls.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/tls.h b/libavformat/tls.h
index beb19d6d55..6c2d025f6c 100644
--- a/libavformat/tls.h
+++ b/libavformat/tls.h
@@ -45,10 +45,10 @@ typedef struct TLSShared {
 #define TLS_COMMON_OPTIONS(pstruct, options_field) \
 {"ca_file","Certificate Authority database file", offsetof(pstruct, 
options_field . ca_file),   AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \
 {"cafile", "Certificate Authority database file", offsetof(pstruct, 
options_field . ca_file),   AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \
-{"tls_verify", "Verify the peer certificate", offsetof(pstruct, 
options_field . verify),AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = 
TLS_OPTFL }, \
+{"tls_verify", "Verify the peer certificate", offsetof(pstruct, 
options_field . verify),AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, .flags = 
TLS_OPTFL }, \
 {"cert_file",  "Certificate file",offsetof(pstruct, 
options_field . cert_file), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \
 {"key_file",   "Private key file",offsetof(pstruct, 
options_field . key_file),  AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \
-{"listen", "Listen for incoming connections", offsetof(pstruct, 
options_field . listen),AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = 
TLS_OPTFL }, \
+{"listen", "Listen for incoming connections", offsetof(pstruct, 
options_field . listen),AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, .flags = 
TLS_OPTFL }, \
 {"verifyhost", "Verify against a specific hostname",  offsetof(pstruct, 
options_field . host),  AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }
 
 int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, 
AVDictionary **options);
-- 
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".

Re: [FFmpeg-devel] [PATCH] avfilter: add dblur video filter

2020-05-30 Thread Paul B Mahol
Will apply.

On 5/27/20, Paul B Mahol  wrote:
> Signed-off-by: Paul B Mahol 
> ---
>  doc/filters.texi |  23 +++
>  libavfilter/Makefile |   1 +
>  libavfilter/allfilters.c |   1 +
>  libavfilter/vf_dblur.c   | 307 +++
>  4 files changed, 332 insertions(+)
>  create mode 100644 libavfilter/vf_dblur.c
>
___
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: add PFM image decoder

2020-05-30 Thread Paul B Mahol
Will apply.

On 5/27/20, Paul B Mahol  wrote:
> Signed-off-by: Paul B Mahol 
> ---
>  libavcodec/Makefile |  1 +
>  libavcodec/allcodecs.c  |  1 +
>  libavcodec/codec_desc.c |  7 ++
>  libavcodec/codec_id.h   |  1 +
>  libavcodec/pnm.c| 21 +---
>  libavcodec/pnm.h|  2 ++
>  libavcodec/pnmdec.c | 55 +
>  libavformat/img2.c  |  1 +
>  8 files changed, 85 insertions(+), 4 deletions(-)
>
___
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] lavf/tls_openssl: use the system cert store by default

2020-05-30 Thread rcombs
---
 libavformat/tls_openssl.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavformat/tls_openssl.c b/libavformat/tls_openssl.c
index d66845cf48..b44dd3136d 100644
--- a/libavformat/tls_openssl.c
+++ b/libavformat/tls_openssl.c
@@ -259,6 +259,9 @@ static int tls_open(URLContext *h, const char *uri, int 
flags, AVDictionary **op
 if (c->ca_file) {
 if (!SSL_CTX_load_verify_locations(p->ctx, c->ca_file, NULL))
 av_log(h, AV_LOG_ERROR, "SSL_CTX_load_verify_locations %s\n", 
ERR_error_string(ERR_get_error(), NULL));
+} else {
+if (!SSL_CTX_set_default_verify_paths(p->ctx))
+av_log(h, AV_LOG_ERROR, "SSL_CTX_set_default_verify_paths %s\n", 
ERR_error_string(ERR_get_error(), NULL));
 }
 if (c->cert_file && !SSL_CTX_use_certificate_chain_file(p->ctx, 
c->cert_file)) {
 av_log(h, AV_LOG_ERROR, "Unable to load cert file %s: %s\n",
-- 
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/4] lavf/tls_openssl: add support for verifying the server hostname on >=1.1.0

2020-05-30 Thread rcombs
---
 libavformat/tls_openssl.c | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/libavformat/tls_openssl.c b/libavformat/tls_openssl.c
index 002197fa76..d66845cf48 100644
--- a/libavformat/tls_openssl.c
+++ b/libavformat/tls_openssl.c
@@ -272,8 +272,6 @@ static int tls_open(URLContext *h, const char *uri, int 
flags, AVDictionary **op
 ret = AVERROR(EIO);
 goto fail;
 }
-// Note, this doesn't check that the peer certificate actually matches
-// the requested hostname.
 if (c->verify)
 SSL_CTX_set_verify(p->ctx, 
SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL);
 p->ssl = SSL_new(p->ctx);
@@ -297,8 +295,18 @@ static int tls_open(URLContext *h, const char *uri, int 
flags, AVDictionary **op
 bio->ptr = c->tcp;
 #endif
 SSL_set_bio(p->ssl, bio, bio);
-if (!c->listen && !c->numerichost)
+if (!c->listen && !c->numerichost) {
 SSL_set_tlsext_host_name(p->ssl, c->host);
+if (c->verify)
+#if OPENSSL_VERSION_NUMBER >= 0x101fL
+SSL_set1_host(p->ssl, c->host);
+#else
+av_log(h, AV_LOG_WARNING, "ffmpeg was built against an old version 
of OpenSSL\n"
+  "which doesn't provide peer name 
verification, so this connection\n"
+  "will be made insecurely. To make this 
connection securely,\n"
+  "upgrade to a newer OpenSSL version, or 
use GNUTLS instead.\n");
+#endif
+}
 ret = c->listen ? SSL_accept(p->ssl) : SSL_connect(p->ssl);
 if (ret == 0) {
 av_log(h, AV_LOG_ERROR, "Unable to negotiate TLS/SSL session\n");
-- 
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".