Re: [FFmpeg-devel] [PATCH] avcodec/dv_profile: PAL DV files with dsf flag 0 - detect via pal flag and buf_size

2021-03-30 Thread Mark Plomer

ping ;-)

Am 18.03.21 um 21:55 schrieb Marton Balint:
It looks good to me, I will apply in a couple of days if nobody 
comments until then. Also Cc'd Dave, as he got probably the most 
experience with dv.


Regards,
Marton

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

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

[FFmpeg-devel] [PATCH 2/2] avcodec/tiff: Don't use separate temporary buffer for fax

2021-03-30 Thread Andreas Rheinhardt
Also don't unnecessarily copy the input data around if it needn't be
reversed; and remove a redundant memset -- av_fast_padded_malloc()
already does this for us.

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

diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index 1d72fdc720..6129ae1c25 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -108,8 +108,6 @@ typedef struct TiffContext {
 int deinvert_buf_size;
 uint8_t *yuv_line;
 unsigned int yuv_line_size;
-uint8_t *fax_buffer;
-unsigned int fax_buffer_size;
 
 int geotag_count;
 TiffGeoTag *geotags;
@@ -613,27 +611,15 @@ static int tiff_unpack_lzma(TiffContext *s, AVFrame *p, 
uint8_t *dst, int stride
 static int tiff_unpack_fax(TiffContext *s, uint8_t *dst, int stride,
const uint8_t *src, int size, int width, int lines)
 {
-int i, ret = 0;
 int line;
-uint8_t *src2;
-
-av_fast_padded_malloc(&s->fax_buffer, &s->fax_buffer_size, size);
-src2 = s->fax_buffer;
-
-if (!src2) {
-av_log(s->avctx, AV_LOG_ERROR,
-   "Error allocating temporary buffer\n");
-return AVERROR(ENOMEM);
-}
+int ret;
 
-if (!s->fill_order) {
-memcpy(src2, src, size);
-} else {
-for (i = 0; i < size; i++)
-src2[i] = ff_reverse[src[i]];
+if (s->fill_order) {
+if ((ret = deinvert_buffer(s, src, size)) < 0)
+return ret;
+src = s->deinvert_buf;
 }
-memset(src2 + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
-ret = ff_ccitt_unpack(s->avctx, src2, size, dst, lines, stride,
+ret = ff_ccitt_unpack(s->avctx, src, size, dst, lines, stride,
   s->compr, s->fax_opts);
 if (s->bpp < 8 && s->avctx->pix_fmt == AV_PIX_FMT_PAL8)
 for (line = 0; line < lines; line++) {
@@ -2186,8 +2172,6 @@ static av_cold int tiff_end(AVCodecContext *avctx)
 s->deinvert_buf_size = 0;
 av_freep(&s->yuv_line);
 s->yuv_line_size = 0;
-av_freep(&s->fax_buffer);
-s->fax_buffer_size = 0;
 av_frame_free(&s->jpgframe);
 av_packet_free(&s->jpkt);
 avcodec_free_context(&s->avctx_mjpeg);
-- 
2.27.0

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

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

[FFmpeg-devel] [PATCH 1/2] avcodec/tiff: Avoid forward declarations

2021-03-30 Thread Andreas Rheinhardt
In this case it also fixes a potential for compilation failures:
Not all compilers can handle the case in which a function with
a forward declaration declared with an attribute to always inline it
is called before the function body appears.

Signed-off-by: Andreas Rheinhardt 
---
This is of course designed as an alternative to Pavel's patch
https://ffmpeg.org/pipermail/ffmpeg-devel/2021-March/278383.html

 libavcodec/tiff.c | 392 +++---
 1 file changed, 193 insertions(+), 199 deletions(-)

diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index 0878098b90..1d72fdc720 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -275,9 +275,99 @@ static int add_metadata(int count, int type,
 };
 }
 
+/**
+ * Map stored raw sensor values into linear reference values (see: DNG 
Specification - Chapter 5)
+ */
+static uint16_t av_always_inline dng_process_color16(uint16_t value,
+ const uint16_t *lut,
+ uint16_t black_level,
+ float scale_factor) {
+float value_norm;
+
+// Lookup table lookup
+if (lut)
+value = lut[value];
+
+// Black level subtraction
+value = av_clip_uint16_c((unsigned)value - black_level);
+
+// Color scaling
+value_norm = (float)value * scale_factor;
+
+value = av_clip_uint16_c(value_norm * 65535);
+
+return value;
+}
+
+static uint16_t av_always_inline dng_process_color8(uint16_t value,
+const uint16_t *lut,
+uint16_t black_level,
+float scale_factor) {
+return dng_process_color16(value, lut, black_level, scale_factor) >> 8;
+}
+
 static void av_always_inline dng_blit(TiffContext *s, uint8_t *dst, int 
dst_stride,
   const uint8_t *src, int src_stride, int 
width, int height,
-  int is_single_comp, int is_u16);
+  int is_single_comp, int is_u16)
+{
+int line, col;
+float scale_factor;
+
+scale_factor = 1.0f / (s->white_level - s->black_level);
+
+if (is_single_comp) {
+if (!is_u16)
+return; /* <= 8bpp unsupported */
+
+/* Image is double the width and half the height we need, each row 
comprises 2 rows of the output
+   (split vertically in the middle). */
+for (line = 0; line < height / 2; line++) {
+uint16_t *dst_u16 = (uint16_t *)dst;
+uint16_t *src_u16 = (uint16_t *)src;
+
+/* Blit first half of input row row to initial row of output */
+for (col = 0; col < width; col++)
+*dst_u16++ = dng_process_color16(*src_u16++, s->dng_lut, 
s->black_level, scale_factor);
+
+/* Advance the destination pointer by a row (source pointer 
remains in the same place) */
+dst += dst_stride * sizeof(uint16_t);
+dst_u16 = (uint16_t *)dst;
+
+/* Blit second half of input row row to next row of output */
+for (col = 0; col < width; col++)
+*dst_u16++ = dng_process_color16(*src_u16++, s->dng_lut, 
s->black_level, scale_factor);
+
+dst += dst_stride * sizeof(uint16_t);
+src += src_stride * sizeof(uint16_t);
+}
+} else {
+/* Input and output image are the same size and the MJpeg decoder has 
done per-component
+   deinterleaving, so blitting here is straightforward. */
+if (is_u16) {
+for (line = 0; line < height; line++) {
+uint16_t *dst_u16 = (uint16_t *)dst;
+uint16_t *src_u16 = (uint16_t *)src;
+
+for (col = 0; col < width; col++)
+*dst_u16++ = dng_process_color16(*src_u16++, s->dng_lut, 
s->black_level, scale_factor);
+
+dst += dst_stride * sizeof(uint16_t);
+src += src_stride * sizeof(uint16_t);
+}
+} else {
+for (line = 0; line < height; line++) {
+uint8_t *dst_u8 = dst;
+const uint8_t *src_u8 = src;
+
+for (col = 0; col < width; col++)
+*dst_u8++ = dng_process_color8(*src_u8++, s->dng_lut, 
s->black_level, scale_factor);
+
+dst += dst_stride;
+src += src_stride;
+}
+}
+}
+}
 
 static void av_always_inline horizontal_fill(TiffContext *s,
  unsigned int bpp, uint8_t* dst,
@@ -553,7 +643,108 @@ static int tiff_unpack_fax(TiffContext *s, uint8_t *dst, 
int stride,
 return ret;
 }
 
-static int dng_decode_strip(AVCodecContext *avctx, AVFrame *frame);
+static int dng_decode_jpeg(AVCodecContext *avctx, AVFrame *frame,
+   

Re: [FFmpeg-devel] [PATCH] lavc/tiff: Fix build failure due to always_inline

2021-03-30 Thread Andreas Rheinhardt
Pavel Koshevoy:
> Fixes:
> src/libavcodec/tiff.c: In function ‘tiff_unpack_strip’:
> src/libavcodec/tiff.c:280: error: ‘always_inline’ function could not be 
> inlined in call to ‘dng_blit’: the function body must appear before caller
> src/libavcodec/tiff.c:720: error: called from here
> ---
>  libavcodec/tiff.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
> index 0878098b90..4ef685b929 100644
> --- a/libavcodec/tiff.c
> +++ b/libavcodec/tiff.c
> @@ -275,9 +275,9 @@ static int add_metadata(int count, int type,
>  };
>  }
>  
> -static void av_always_inline dng_blit(TiffContext *s, uint8_t *dst, int 
> dst_stride,
> -  const uint8_t *src, int src_stride, 
> int width, int height,
> -  int is_single_comp, int is_u16);
> +static void dng_blit(TiffContext *s, uint8_t *dst, int dst_stride,
> + const uint8_t *src, int src_stride, int width, int 
> height,
> + int is_single_comp, int is_u16);
>  
>  static void av_always_inline horizontal_fill(TiffContext *s,
>   unsigned int bpp, uint8_t* dst,
> 
There are no cyclic calls here, so one can just remove the forward
declaration. I did this here:
https://ffmpeg.org/pipermail/ffmpeg-devel/2021-March/278386.html Do you
like it? And what compiler exhibits the problems you mention in the
commit message?

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

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

Re: [FFmpeg-devel] [PATCH 4/4] avcodec/ttmlenc: add support for region positioning and sizing

2021-03-30 Thread Jan Ekström
On Tue, Mar 30, 2021 at 11:23 AM Jan Ekström  wrote:
>
> +if (style->margin_l < 0 || style->margin_r < 0 || style->margin_v < 0) {
> +av_log(avctx, AV_LOG_ERROR,
> +   "One or more negative margin values in subtitle style: "
> +   "left: %d, right: %d, vertical: %d!\n",
> +   style->margin_l, style->margin_r, style->margin_v);
> +}

Just as I was sending this patch set, I noticed that this missed a
return. Fixed locally.

Jan
___
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] avcodec/ttmlenc: add initial support for regions and styles

2021-03-30 Thread Jan Ekström
From: Jan Ekström 

Attempts to utilize the TTML cell resolution as a mapping to the
reference resolution, and maps font size to cell size. Additionally
sets the display and text alignment according to the ASS alignment
number.

Signed-off-by: Jan Ekström 
---
 libavcodec/ttmlenc.c   | 257 +++--
 libavcodec/ttmlenc.h   |   3 +-
 tests/ref/fate/sub-ttmlenc |  86 +++--
 3 files changed, 294 insertions(+), 52 deletions(-)

diff --git a/libavcodec/ttmlenc.c b/libavcodec/ttmlenc.c
index e3c155fdd1..7e6add62e1 100644
--- a/libavcodec/ttmlenc.c
+++ b/libavcodec/ttmlenc.c
@@ -82,6 +82,7 @@ static int ttml_encode_frame(AVCodecContext *avctx, uint8_t 
*buf,
 {
 TTMLContext *s = avctx->priv_data;
 ASSDialog *dialog;
+AVBPrint local_bprint = { 0 };
 int i;
 
 av_bprint_clear(&s->buffer);
@@ -100,20 +101,41 @@ static int ttml_encode_frame(AVCodecContext *avctx, 
uint8_t *buf,
 dialog = ff_ass_split_dialog(s->ass_ctx, ass, 0, &num);
 
 for (; dialog && num--; dialog++) {
-int ret = ff_ass_split_override_codes(&ttml_callbacks, s,
-  dialog->text);
-int log_level = (ret != AVERROR_INVALIDDATA ||
- avctx->err_recognition & AV_EF_EXPLODE) ?
-AV_LOG_ERROR : AV_LOG_WARNING;
+if (dialog->style) {
+av_bprint_init(&local_bprint, 0, AV_BPRINT_SIZE_UNLIMITED);
+
+av_bprint_escape(&local_bprint, dialog->style, NULL,
+ AV_ESCAPE_MODE_XML,
+ AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
+if (!av_bprint_is_complete(&local_bprint)) {
+ return AVERROR(ENOMEM);
+}
 
-if (ret < 0) {
-av_log(avctx, log_level,
-   "Splitting received ASS dialog failed: %s\n",
-   av_err2str(ret));
+av_bprintf(&s->buffer, "",
+   local_bprint.str);
 
-if (log_level == AV_LOG_ERROR)
-return ret;
+av_bprint_finalize(&local_bprint, NULL);
 }
+
+{
+int ret = ff_ass_split_override_codes(&ttml_callbacks, s,
+  dialog->text);
+int log_level = (ret != AVERROR_INVALIDDATA ||
+ avctx->err_recognition & AV_EF_EXPLODE) ?
+AV_LOG_ERROR : AV_LOG_WARNING;
+
+if (ret < 0) {
+av_log(avctx, log_level,
+   "Splitting received ASS dialog failed: %s\n",
+   av_err2str(ret));
+
+if (log_level == AV_LOG_ERROR)
+return ret;
+}
+}
+
+if (dialog->style)
+av_bprintf(&s->buffer, "");
 }
 } else {
 #endif
@@ -121,6 +143,22 @@ static int ttml_encode_frame(AVCodecContext *avctx, 
uint8_t *buf,
 if (!dialog)
 return AVERROR(ENOMEM);
 
+if (dialog->style) {
+av_bprint_init(&local_bprint, 0, AV_BPRINT_SIZE_UNLIMITED);
+
+av_bprint_escape(&local_bprint, dialog->style, NULL,
+ AV_ESCAPE_MODE_XML,
+ AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
+if (!av_bprint_is_complete(&local_bprint)) {
+ return AVERROR(ENOMEM);
+}
+
+av_bprintf(&s->buffer, "",
+   local_bprint.str);
+
+av_bprint_finalize(&local_bprint, NULL);
+}
+
 {
 int ret = ff_ass_split_override_codes(&ttml_callbacks, s,
   dialog->text);
@@ -140,6 +178,9 @@ static int ttml_encode_frame(AVCodecContext *avctx, uint8_t 
*buf,
 }
 }
 
+if (dialog->style)
+av_bprintf(&s->buffer, "");
+
 ff_ass_free_dialog(&dialog);
 }
 #if FF_API_ASS_TIMING
@@ -173,17 +214,205 @@ static av_cold int ttml_encode_close(AVCodecContext 
*avctx)
 return 0;
 }
 
+static const char *ttml_get_display_alignment(int alignment)
+{
+switch (alignment) {
+case 1:
+case 2:
+case 3:
+return "after";
+case 4:
+case 5:
+case 6:
+return "center";
+case 7:
+case 8:
+case 9:
+return "before";
+default:
+return NULL;
+}
+}
+
+static const char *ttml_get_text_alignment(int alignment)
+{
+switch (alignment) {
+case 1:
+case 4:
+ 

[FFmpeg-devel] [PATCH 1/4] avcodec/ttmlenc: split header writing into its own function

2021-03-30 Thread Jan Ekström
From: Jan Ekström 

Signed-off-by: Jan Ekström 
---
 libavcodec/ttmlenc.c | 27 ++-
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/libavcodec/ttmlenc.c b/libavcodec/ttmlenc.c
index 3972b4368c..e3c155fdd1 100644
--- a/libavcodec/ttmlenc.c
+++ b/libavcodec/ttmlenc.c
@@ -173,16 +173,8 @@ static av_cold int ttml_encode_close(AVCodecContext *avctx)
 return 0;
 }
 
-static av_cold int ttml_encode_init(AVCodecContext *avctx)
+static int ttml_write_header_content(AVCodecContext *avctx)
 {
-TTMLContext *s = avctx->priv_data;
-
-s->avctx   = avctx;
-
-if (!(s->ass_ctx = ff_ass_split(avctx->subtitle_header))) {
-return AVERROR_INVALIDDATA;
-}
-
 if (!(avctx->extradata = av_mallocz(TTMLENC_EXTRADATA_SIGNATURE_SIZE +
 1 + AV_INPUT_BUFFER_PADDING_SIZE))) {
 return AVERROR(ENOMEM);
@@ -192,8 +184,25 @@ static av_cold int ttml_encode_init(AVCodecContext *avctx)
 memcpy(avctx->extradata, TTMLENC_EXTRADATA_SIGNATURE,
TTMLENC_EXTRADATA_SIGNATURE_SIZE);
 
+return 0;
+}
+
+static av_cold int ttml_encode_init(AVCodecContext *avctx)
+{
+TTMLContext *s = avctx->priv_data;
+int ret = AVERROR_BUG;
+s->avctx   = avctx;
+
 av_bprint_init(&s->buffer, 0, AV_BPRINT_SIZE_UNLIMITED);
 
+if (!(s->ass_ctx = ff_ass_split(avctx->subtitle_header))) {
+return AVERROR_INVALIDDATA;
+}
+
+if ((ret = ttml_write_header_content(avctx)) < 0) {
+return ret;
+}
+
 return 0;
 }
 
-- 
2.30.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 4/4] avcodec/ttmlenc: add support for region positioning and sizing

2021-03-30 Thread Jan Ekström
From: Jan Ekström 

The ASS margins are utilized to generate percentual values, as
the usage of cell-based sizing and offsetting seems to be not too
well supported by renderers.

Signed-off-by: Jan Ekström 
---
 libavcodec/ttmlenc.c   | 41 --
 tests/ref/fate/sub-ttmlenc |  2 ++
 2 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/libavcodec/ttmlenc.c b/libavcodec/ttmlenc.c
index 7e6add62e1..a08b1ada2e 100644
--- a/libavcodec/ttmlenc.c
+++ b/libavcodec/ttmlenc.c
@@ -254,6 +254,26 @@ static const char *ttml_get_text_alignment(int alignment)
 }
 }
 
+static void ttml_get_origin(ASSScriptInfo script_info, ASSStyle *style,
+   int *origin_left, int *origin_top)
+{
+*origin_left = av_rescale(style->margin_l, 100, script_info.play_res_x);
+*origin_top  =
+av_rescale((style->alignment >= 7) ? style->margin_v : 0,
+   100, script_info.play_res_x);
+}
+
+static void ttml_get_extent(ASSScriptInfo script_info, ASSStyle *style,
+   int *width, int *height)
+{
+*width  = av_rescale(script_info.play_res_x - style->margin_r,
+ 100, script_info.play_res_x);
+*height = av_rescale((style->alignment <= 3) ?
+ script_info.play_res_y - style->margin_v :
+ script_info.play_res_y,
+ 100, script_info.play_res_y);
+}
+
 // if we set cell resolution to our script reference resolution,
 // then a single line is a single "point" on our canvas. Thus, by setting our
 // font size to font size in cells, we should gain a similar enough scale
@@ -261,6 +281,8 @@ static const char *ttml_get_text_alignment(int alignment)
 // upon in the TTML community.
 static const char ttml_region_base[] =
 "  \n";
 
 static int ttml_write_region(AVCodecContext *avctx, AVBPrint *buf,
- ASSStyle *style)
+ ASSScriptInfo script_info, ASSStyle *style)
 {
 if (!style)
 return AVERROR_INVALIDDATA;
@@ -288,11 +310,22 @@ static int ttml_write_region(AVCodecContext *avctx, 
AVBPrint *buf,
 return AVERROR_INVALIDDATA;
 }
 
+if (style->margin_l < 0 || style->margin_r < 0 || style->margin_v < 0) {
+av_log(avctx, AV_LOG_ERROR,
+   "One or more negative margin values in subtitle style: "
+   "left: %d, right: %d, vertical: %d!\n",
+   style->margin_l, style->margin_r, style->margin_v);
+}
+
 {
 const char *display_alignment =
 ttml_get_display_alignment(style->alignment);
 const char *text_alignment =
 ttml_get_text_alignment(style->alignment);
+int origin_left = 0;
+int origin_top  = 0;
+int width = 0;
+int height = 0;
 char *style_name = NULL;
 char *font_name = NULL;
 AVBPrint local_bprint = { 0 };
@@ -307,6 +340,9 @@ static int ttml_write_region(AVCodecContext *avctx, 
AVBPrint *buf,
 return AVERROR_INVALIDDATA;
 }
 
+ttml_get_origin(script_info, style, &origin_left, &origin_top);
+ttml_get_extent(script_info, style, &width, &height);
+
 av_bprint_init(&local_bprint, 0, AV_BPRINT_SIZE_UNLIMITED);
 av_bprint_escape(&local_bprint, style->name, NULL,
  AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
@@ -318,6 +354,7 @@ static int ttml_write_region(AVCodecContext *avctx, 
AVBPrint *buf,
 return ret;
 
 av_bprintf(buf, ttml_region_base, style_name,
+   origin_left, origin_top, width, height,
display_alignment, text_alignment, style->font_size);
 
 if (style->font_name) {
@@ -383,7 +420,7 @@ static int ttml_write_header_content(AVCodecContext *avctx)
 int ret = AVERROR_BUG;
 style = &ass->styles[i];
 
-if ((ret = ttml_write_region(avctx, &s->buffer, style)) < 0)
+if ((ret = ttml_write_region(avctx, &s->buffer, script_info, style)) < 
0)
 return ret;
 }
 
diff --git a/tests/ref/fate/sub-ttmlenc b/tests/ref/fate/sub-ttmlenc
index 6d0a8067fc..4df8f8796f 100644
--- a/tests/ref/fate/sub-ttmlenc
+++ b/tests/ref/fate/sub-ttmlenc
@@ -9,6 +9,8 @@
   
 
   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 0/4] Initial region (styling) support for TTML

2021-03-30 Thread Jan Ekström
Now sets alignment, font size, font family and the region's position
and size according to the ASS styles passed to the encoder. Regions are
relatively important in TTML, since the spec-defined default region is in
raster location (similar to the default with HTML) - it starts from the
top left corner and covers the whole screen.

Mapping of the ASS script resolution to the cell resolution and using cells as
sizing metric is not perfect, but while TTML does have a pixel based reference
sizing by means of setting an extent to the root tt element, it is specifically
disallowed in the EBU-TT profile, as well as apparently generally frowned upon
as opposed to defining the cell resolution. In general, mapping to cell 
resolution
seems to give "close enough" results, though.

FATE test output still passes https://github.com/skynav/ttt/ validation,
and visually the result can be verified against such renderers as
http://sandflow.com/imsc1_1/index.html .

Jan

Jan Ekström (4):
  avcodec/ttmlenc: split header writing into its own function
  avformat/ttmlenc: enable writing out additional header values
  avcodec/ttmlenc: add initial support for regions and styles
  avcodec/ttmlenc: add support for region positioning and sizing

 libavcodec/ttmlenc.c   | 311 ++---
 libavcodec/ttmlenc.h   |   6 +
 libavformat/ttmlenc.c  |  78 +-
 tests/ref/fate/sub-ttmlenc |  88 ++-
 4 files changed, 423 insertions(+), 60 deletions(-)

-- 
2.30.2

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

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

[FFmpeg-devel] [PATCH 2/4] avformat/ttmlenc: enable writing out additional header values

2021-03-30 Thread Jan Ekström
From: Jan Ekström 

This way the encoder may pass on the following values to the muxer:
1) Additional root "tt" element attributes, such as the subtitle
   canvas reference size.
2) Anything before the body element of the document, such as regions
   in the head element, which can configure styles.

Signed-off-by: Jan Ekström 
---
 libavcodec/ttmlenc.h  |  5 +++
 libavformat/ttmlenc.c | 78 ---
 2 files changed, 78 insertions(+), 5 deletions(-)

diff --git a/libavcodec/ttmlenc.h b/libavcodec/ttmlenc.h
index c1dd5ec990..c3bb11478d 100644
--- a/libavcodec/ttmlenc.h
+++ b/libavcodec/ttmlenc.h
@@ -25,4 +25,9 @@
 #define TTMLENC_EXTRADATA_SIGNATURE "lavc-ttmlenc"
 #define TTMLENC_EXTRADATA_SIGNATURE_SIZE (sizeof(TTMLENC_EXTRADATA_SIGNATURE) 
- 1)
 
+static const char ttml_default_namespacing[] =
+"  xmlns=\"http://www.w3.org/ns/ttml\"\n";
+"  xmlns:ttm=\"http://www.w3.org/ns/ttml#metadata\"\n";
+"  xmlns:tts=\"http://www.w3.org/ns/ttml#styling\"\n";;
+
 #endif /* AVCODEC_TTMLENC_H */
diff --git a/libavformat/ttmlenc.c b/libavformat/ttmlenc.c
index 940f8bbd4e..5d9ad6b756 100644
--- a/libavformat/ttmlenc.c
+++ b/libavformat/ttmlenc.c
@@ -37,18 +37,23 @@ enum TTMLPacketType {
 PACKET_TYPE_DOCUMENT,
 };
 
+struct TTMLHeaderParameters {
+char *tt_element_params;
+char *pre_body_elements;
+};
+
 typedef struct TTMLMuxContext {
 enum TTMLPacketType input_type;
 unsigned int document_written;
+struct TTMLHeaderParameters header_params;
 } TTMLMuxContext;
 
 static const char ttml_header_text[] =
 "\n"
 "http://www.w3.org/ns/ttml\"\n";
-"  xmlns:ttm=\"http://www.w3.org/ns/ttml#metadata\"\n";
-"  xmlns:tts=\"http://www.w3.org/ns/ttml#styling\"\n";
+"%s"
 "  xml:lang=\"%s\">\n"
+"%s"
 "  \n"
 "\n";
 
@@ -72,6 +77,47 @@ static void ttml_write_time(AVIOContext *pb, const char 
tag[],
 tag, hour, min, sec, millisec);
 }
 
+static int ttml_set_header_values_from_extradata(
+AVCodecParameters *par, struct TTMLHeaderParameters *header_params)
+{
+size_t additional_data_size =
+par->extradata_size - TTMLENC_EXTRADATA_SIGNATURE_SIZE;
+
+if (!additional_data_size) {
+header_params->tt_element_params =
+av_strndup(ttml_default_namespacing,
+   sizeof(ttml_default_namespacing) - 1);
+header_params->pre_body_elements = av_strndup("", 1);
+
+if (!header_params->tt_element_params ||
+!header_params->pre_body_elements)
+return AVERROR(ENOMEM);
+
+return 0;
+}
+
+{
+char *value =
+(char *)par->extradata + TTMLENC_EXTRADATA_SIGNATURE_SIZE;
+size_t value_size = av_strnlen(value, additional_data_size);
+
+if (!(header_params->tt_element_params = av_strndup(value, 
value_size)))
+return AVERROR(ENOMEM);
+
+additional_data_size -= value_size + 1;
+value += value_size + 1;
+if (additional_data_size <= 0)
+return AVERROR_INVALIDDATA;
+
+value_size = av_strnlen(value, additional_data_size);
+
+if (!(header_params->pre_body_elements = av_strndup(value, 
value_size)))
+return AVERROR(ENOMEM);
+
+return 0;
+}
+}
+
 static int ttml_write_header(AVFormatContext *ctx)
 {
 TTMLMuxContext *ttml_ctx = ctx->priv_data;
@@ -103,8 +149,21 @@ static int ttml_write_header(AVFormatContext *ctx)
 
 avpriv_set_pts_info(st, 64, 1, 1000);
 
-if (ttml_ctx->input_type == PACKET_TYPE_PARAGRAPH)
-avio_printf(pb, ttml_header_text, printed_lang);
+if (ttml_ctx->input_type == PACKET_TYPE_PARAGRAPH) {
+int ret = ttml_set_header_values_from_extradata(
+st->codecpar, &ttml_ctx->header_params);
+if (ret < 0) {
+av_log(ctx, AV_LOG_ERROR,
+   "Failed to parse TTML header values from extradata: "
+   "%s!\n", av_err2str(ret));
+return ret;
+}
+
+avio_printf(pb, ttml_header_text,
+ttml_ctx->header_params.tt_element_params,
+printed_lang,
+ttml_ctx->header_params.pre_body_elements);
+}
 }
 
 return 0;
@@ -159,6 +218,14 @@ static int ttml_write_trailer(AVFormatContext *ctx)
 return 0;
 }
 
+static void ttml_free(AVFormatContext *ctx)
+{
+TTMLMuxContext *ttml_ctx = ctx->priv_data;
+
+av_freep(&(ttml_ctx->header_params.tt_element_params));
+av_freep(&(ttml_ctx->header_params.pre_body_elements));
+}
+
 AVOutputFormat ff_ttml_muxer = {
 .name  = "ttml",
 .long_name = NULL_IF_CONFIG_SMALL("TTML subtitle"),
@@ -171,4 +238,5 @@ AVOutputFormat ff_ttml_muxer = {
 .write_header  = ttml_write_header,
 .write_packet  = ttml_write_packet,
 .write_trailer = ttml_write_trailer,
+.deinit= ttml_free,
 };
-- 
2.30.2


Re: [FFmpeg-devel] [PATCH 5/6] pngdec: fix and simplify apng reference handling

2021-03-30 Thread Michael Niedermayer
On Tue, Feb 16, 2021 at 09:24:15PM +0100, Anton Khirnov wrote:
> Current code is very confused and confusing. It uses two different
> reference frames - "previous" and "last" - when only one is really
> necessary. It also confuses the two, leading to incorrect output with
> APNG_DISPOSE_OP_PREVIOUS mode.
> 
> Fixes #9017.
> ---
>  libavcodec/pngdec.c | 93 -
>  1 file changed, 42 insertions(+), 51 deletions(-)


[...]

> @@ -1088,23 +1084,23 @@ static int handle_p_frame_apng(AVCodecContext *avctx, 
> PNGDecContext *s,
>  if (!buffer)
>  return AVERROR(ENOMEM);
>  
> +ff_thread_await_progress(&s->last_picture, INT_MAX, 0);
>  
> -// Do the disposal operation specified by the last frame on the frame
> -if (s->last_dispose_op != APNG_DISPOSE_OP_PREVIOUS) {
> -ff_thread_await_progress(&s->last_picture, INT_MAX, 0);
> -memcpy(buffer, s->last_picture.f->data[0], s->image_linesize * 
> s->height);
> -
> -if (s->last_dispose_op == APNG_DISPOSE_OP_BACKGROUND)
> -for (y = s->last_y_offset; y < s->last_y_offset + s->last_h; ++y)
> -memset(buffer + s->image_linesize * y + s->bpp * 
> s->last_x_offset, 0, s->bpp * s->last_w);
> +// need to reset a rectangle to background:
> +// create a new writable copy
> +if (s->last_dispose_op == APNG_DISPOSE_OP_BACKGROUND) {
> +int ret = av_frame_make_writable(s->last_picture.f);
> +if (ret < 0)
> +return ret;
>  
> -memcpy(s->previous_picture.f->data[0], buffer, s->image_linesize * 
> s->height);
> -ff_thread_report_progress(&s->previous_picture, INT_MAX, 0);
> -} else {
> -ff_thread_await_progress(&s->previous_picture, INT_MAX, 0);
> -memcpy(buffer, s->previous_picture.f->data[0], s->image_linesize * 
> s->height);
> +for (y = s->last_y_offset; y < s->last_y_offset + s->last_h; y++) {
> +memset(s->last_picture.f->data[0] + s->image_linesize * y +
> +   s->bpp * s->last_x_offset, 0, s->bpp * s->last_w);
> +}
>  }
>  
> +memcpy(buffer, s->last_picture.f->data[0], s->image_linesize * 
> s->height);
> +

This results in out of array reads

av_frame_make_writable() decreases linesize [0] but the memcpy() now av_memdup()
assumes all frames have the same linesize

Thanks

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

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


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

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

Re: [FFmpeg-devel] [PATCH 2/4] avformat/ttmlenc: enable writing out additional header values

2021-03-30 Thread Andreas Rheinhardt
Jan Ekström:
> From: Jan Ekström 
> 
> This way the encoder may pass on the following values to the muxer:
> 1) Additional root "tt" element attributes, such as the subtitle
>canvas reference size.
> 2) Anything before the body element of the document, such as regions
>in the head element, which can configure styles.
> 
> Signed-off-by: Jan Ekström 
> ---
>  libavcodec/ttmlenc.h  |  5 +++
>  libavformat/ttmlenc.c | 78 ---
>  2 files changed, 78 insertions(+), 5 deletions(-)
> 
> diff --git a/libavcodec/ttmlenc.h b/libavcodec/ttmlenc.h
> index c1dd5ec990..c3bb11478d 100644
> --- a/libavcodec/ttmlenc.h
> +++ b/libavcodec/ttmlenc.h
> @@ -25,4 +25,9 @@
>  #define TTMLENC_EXTRADATA_SIGNATURE "lavc-ttmlenc"
>  #define TTMLENC_EXTRADATA_SIGNATURE_SIZE 
> (sizeof(TTMLENC_EXTRADATA_SIGNATURE) - 1)
>  
> +static const char ttml_default_namespacing[] =
> +"  xmlns=\"http://www.w3.org/ns/ttml\"\n";
> +"  xmlns:ttm=\"http://www.w3.org/ns/ttml#metadata\"\n";
> +"  xmlns:tts=\"http://www.w3.org/ns/ttml#styling\"\n";;
> +
>  #endif /* AVCODEC_TTMLENC_H */
> diff --git a/libavformat/ttmlenc.c b/libavformat/ttmlenc.c
> index 940f8bbd4e..5d9ad6b756 100644
> --- a/libavformat/ttmlenc.c
> +++ b/libavformat/ttmlenc.c
> @@ -37,18 +37,23 @@ enum TTMLPacketType {
>  PACKET_TYPE_DOCUMENT,
>  };
>  
> +struct TTMLHeaderParameters {
> +char *tt_element_params;
> +char *pre_body_elements;
> +};
> +
>  typedef struct TTMLMuxContext {
>  enum TTMLPacketType input_type;
>  unsigned int document_written;
> +struct TTMLHeaderParameters header_params;
>  } TTMLMuxContext;
>  
>  static const char ttml_header_text[] =
>  "\n"
>  " -"  xmlns=\"http://www.w3.org/ns/ttml\"\n";
> -"  xmlns:ttm=\"http://www.w3.org/ns/ttml#metadata\"\n";
> -"  xmlns:tts=\"http://www.w3.org/ns/ttml#styling\"\n";
> +"%s"
>  "  xml:lang=\"%s\">\n"
> +"%s"
>  "  \n"
>  "\n";
>  
> @@ -72,6 +77,47 @@ static void ttml_write_time(AVIOContext *pb, const char 
> tag[],
>  tag, hour, min, sec, millisec);
>  }
>  
> +static int ttml_set_header_values_from_extradata(
> +AVCodecParameters *par, struct TTMLHeaderParameters *header_params)
> +{
> +size_t additional_data_size =
> +par->extradata_size - TTMLENC_EXTRADATA_SIGNATURE_SIZE;
> +

Missing check that extradata_size is >= TTMLENC_EXTRADATA_SIGNATURE_SIZE.

> +if (!additional_data_size) {
> +header_params->tt_element_params =
> +av_strndup(ttml_default_namespacing,
> +   sizeof(ttml_default_namespacing) - 1);
> +header_params->pre_body_elements = av_strndup("", 1);

Why are you using av_strndup and not the ordinary av_strdup here?
Anyway, these allocations and the ones below are unnecessary as you only
need all of this when writing the header.

> +
> +if (!header_params->tt_element_params ||
> +!header_params->pre_body_elements)
> +return AVERROR(ENOMEM);
> +
> +return 0;
> +}
> +
> +{
> +char *value =
> +(char *)par->extradata + TTMLENC_EXTRADATA_SIGNATURE_SIZE;
> +size_t value_size = av_strnlen(value, additional_data_size);
> +
> +if (!(header_params->tt_element_params = av_strndup(value, 
> value_size)))
> +return AVERROR(ENOMEM);
> +
> +additional_data_size -= value_size + 1;
> +value += value_size + 1;
> +if (additional_data_size <= 0)
> +return AVERROR_INVALIDDATA;
> +
> +value_size = av_strnlen(value, additional_data_size);
> +
> +if (!(header_params->pre_body_elements = av_strndup(value, 
> value_size)))
> +return AVERROR(ENOMEM);
> +
> +return 0;
> +}
> +}
> +
>  static int ttml_write_header(AVFormatContext *ctx)
>  {
>  TTMLMuxContext *ttml_ctx = ctx->priv_data;
> @@ -103,8 +149,21 @@ static int ttml_write_header(AVFormatContext *ctx)
>  
>  avpriv_set_pts_info(st, 64, 1, 1000);
>  
> -if (ttml_ctx->input_type == PACKET_TYPE_PARAGRAPH)
> -avio_printf(pb, ttml_header_text, printed_lang);
> +if (ttml_ctx->input_type == PACKET_TYPE_PARAGRAPH) {
> +int ret = ttml_set_header_values_from_extradata(
> +st->codecpar, &ttml_ctx->header_params);
> +if (ret < 0) {
> +av_log(ctx, AV_LOG_ERROR,
> +   "Failed to parse TTML header values from extradata: "
> +   "%s!\n", av_err2str(ret));
> +return ret;
> +}
> +
> +avio_printf(pb, ttml_header_text,
> +ttml_ctx->header_params.tt_element_params,
> +printed_lang,
> +ttml_ctx->header_params.pre_body_elements);
> +}
>  }
>  
>  return 0;
> @@ -159,6 +218,14 @@ static int ttml_write_trailer(AVFormatContext *ctx)
>  return 0;
>  }
>  
> +static void ttml_free(AVFormatContext *ctx)
> +{
> +TTML

Re: [FFmpeg-devel] [PATCH 5/6] pngdec: fix and simplify apng reference handling

2021-03-30 Thread Michael Niedermayer
On Tue, Mar 30, 2021 at 10:56:13AM +0200, Michael Niedermayer wrote:
> On Tue, Feb 16, 2021 at 09:24:15PM +0100, Anton Khirnov wrote:
> > Current code is very confused and confusing. It uses two different
> > reference frames - "previous" and "last" - when only one is really
> > necessary. It also confuses the two, leading to incorrect output with
> > APNG_DISPOSE_OP_PREVIOUS mode.
> > 
> > Fixes #9017.
> > ---
> >  libavcodec/pngdec.c | 93 -
> >  1 file changed, 42 insertions(+), 51 deletions(-)
> 
> 
> [...]
> 
> > @@ -1088,23 +1084,23 @@ static int handle_p_frame_apng(AVCodecContext 
> > *avctx, PNGDecContext *s,
> >  if (!buffer)
> >  return AVERROR(ENOMEM);
> >  
> > +ff_thread_await_progress(&s->last_picture, INT_MAX, 0);
> >  
> > -// Do the disposal operation specified by the last frame on the frame
> > -if (s->last_dispose_op != APNG_DISPOSE_OP_PREVIOUS) {
> > -ff_thread_await_progress(&s->last_picture, INT_MAX, 0);
> > -memcpy(buffer, s->last_picture.f->data[0], s->image_linesize * 
> > s->height);
> > -
> > -if (s->last_dispose_op == APNG_DISPOSE_OP_BACKGROUND)
> > -for (y = s->last_y_offset; y < s->last_y_offset + s->last_h; 
> > ++y)
> > -memset(buffer + s->image_linesize * y + s->bpp * 
> > s->last_x_offset, 0, s->bpp * s->last_w);
> > +// need to reset a rectangle to background:
> > +// create a new writable copy
> > +if (s->last_dispose_op == APNG_DISPOSE_OP_BACKGROUND) {
> > +int ret = av_frame_make_writable(s->last_picture.f);
> > +if (ret < 0)
> > +return ret;
> >  
> > -memcpy(s->previous_picture.f->data[0], buffer, s->image_linesize * 
> > s->height);
> > -ff_thread_report_progress(&s->previous_picture, INT_MAX, 0);
> > -} else {
> > -ff_thread_await_progress(&s->previous_picture, INT_MAX, 0);
> > -memcpy(buffer, s->previous_picture.f->data[0], s->image_linesize * 
> > s->height);
> > +for (y = s->last_y_offset; y < s->last_y_offset + s->last_h; y++) {
> > +memset(s->last_picture.f->data[0] + s->image_linesize * y +
> > +   s->bpp * s->last_x_offset, 0, s->bpp * s->last_w);
> > +}
> >  }
> >  
> > +memcpy(buffer, s->last_picture.f->data[0], s->image_linesize * 
> > s->height);
> > +
> 
> This results in out of array reads
> 
> av_frame_make_writable() decreases linesize [0] but the memcpy() now 
> av_memdup()
> assumes all frames have the same linesize

CCing anton, to make sure this is not missed in its old thread
A fix to this also should be backported to release/4.4

Thanks

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The bravest are surely those who have the clearest vision
of what is before them, glory and danger alike, and yet
notwithstanding go out to meet it. -- Thucydides


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 2/2] avformat/rmdec: use larger intermediate type for audio_framesize * sub_packet_h check

2021-03-30 Thread Michael Niedermayer
Fixes: signed integer overflow: 65535 * 65535 cannot be represented in type 
'int'
Fixes: 
31406/clusterfuzz-testcase-minimized-ffmpeg_dem_IVR_fuzzer-5024692843970560

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

diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c
index 610189ecb4..b6f42183e8 100644
--- a/libavformat/rmdec.c
+++ b/libavformat/rmdec.c
@@ -296,7 +296,7 @@ static int rm_read_audio_stream_info(AVFormatContext *s, 
AVIOContext *pb,
 ast->deint_id == DEINT_ID_GENR ||
 ast->deint_id == DEINT_ID_SIPR) {
 if (st->codecpar->block_align <= 0 ||
-ast->audio_framesize * sub_packet_h > (unsigned)INT_MAX ||
+ast->audio_framesize * (uint64_t)sub_packet_h > 
(unsigned)INT_MAX ||
 ast->audio_framesize * sub_packet_h < 
st->codecpar->block_align)
 return AVERROR_INVALIDDATA;
 if (av_new_packet(&ast->pkt, ast->audio_framesize * sub_packet_h) 
< 0)
-- 
2.17.1

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

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

[FFmpeg-devel] [PATCH 1/2] avcodec/exr: Check oe in huf_decode() before use

2021-03-30 Thread Michael Niedermayer
Fixes: out of array access
Fixes: 
31386/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_EXR_fuzzer-5773234709594112

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

diff --git a/libavcodec/exr.c b/libavcodec/exr.c
index 279cfe9412..65e5203c31 100644
--- a/libavcodec/exr.c
+++ b/libavcodec/exr.c
@@ -422,7 +422,12 @@ static int huf_decode(VLC *vlc, GetByteContext *gb, int 
nbits, int run_sym,
 
 if (x == run_sym) {
 int run = get_bits(&gbit, 8);
-uint16_t fill = out[oe - 1];
+uint16_t fill;
+
+if (oe == 0 || oe + run > no)
+return AVERROR_INVALIDDATA;
+
+fill = out[oe - 1];
 
 while (run-- > 0)
 out[oe++] = fill;
-- 
2.17.1

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

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

Re: [FFmpeg-devel] [PATCH 3/4] avcodec/ttmlenc: add initial support for regions and styles

2021-03-30 Thread Andreas Rheinhardt
Jan Ekström:
> From: Jan Ekström 
> 
> Attempts to utilize the TTML cell resolution as a mapping to the
> reference resolution, and maps font size to cell size. Additionally
> sets the display and text alignment according to the ASS alignment
> number.
> 
> Signed-off-by: Jan Ekström 
> ---
>  libavcodec/ttmlenc.c   | 257 +++--
>  libavcodec/ttmlenc.h   |   3 +-
>  tests/ref/fate/sub-ttmlenc |  86 +++--
>  3 files changed, 294 insertions(+), 52 deletions(-)
> 
> diff --git a/libavcodec/ttmlenc.c b/libavcodec/ttmlenc.c
> index e3c155fdd1..7e6add62e1 100644
> --- a/libavcodec/ttmlenc.c
> +++ b/libavcodec/ttmlenc.c
> @@ -82,6 +82,7 @@ static int ttml_encode_frame(AVCodecContext *avctx, uint8_t 
> *buf,
>  {
>  TTMLContext *s = avctx->priv_data;
>  ASSDialog *dialog;
> +AVBPrint local_bprint = { 0 };
>  int i;
>  
>  av_bprint_clear(&s->buffer);
> @@ -100,20 +101,41 @@ static int ttml_encode_frame(AVCodecContext *avctx, 
> uint8_t *buf,
>  dialog = ff_ass_split_dialog(s->ass_ctx, ass, 0, &num);
>  
>  for (; dialog && num--; dialog++) {
> -int ret = ff_ass_split_override_codes(&ttml_callbacks, s,
> -  dialog->text);
> -int log_level = (ret != AVERROR_INVALIDDATA ||
> - avctx->err_recognition & AV_EF_EXPLODE) ?
> -AV_LOG_ERROR : AV_LOG_WARNING;
> +if (dialog->style) {
> +av_bprint_init(&local_bprint, 0, 
> AV_BPRINT_SIZE_UNLIMITED);
> +
> +av_bprint_escape(&local_bprint, dialog->style, NULL,
> + AV_ESCAPE_MODE_XML,
> + AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
> +if (!av_bprint_is_complete(&local_bprint)) {
> + return AVERROR(ENOMEM);
> +}
>  
> -if (ret < 0) {
> -av_log(avctx, log_level,
> -   "Splitting received ASS dialog failed: %s\n",
> -   av_err2str(ret));
> +av_bprintf(&s->buffer, "",
> +   local_bprint.str);
>  
> -if (log_level == AV_LOG_ERROR)
> -return ret;
> +av_bprint_finalize(&local_bprint, NULL);
>  }
> +
> +{
> +int ret = ff_ass_split_override_codes(&ttml_callbacks, s,
> +  dialog->text);
> +int log_level = (ret != AVERROR_INVALIDDATA ||
> + avctx->err_recognition & AV_EF_EXPLODE) 
> ?
> +AV_LOG_ERROR : AV_LOG_WARNING;
> +
> +if (ret < 0) {
> +av_log(avctx, log_level,
> +   "Splitting received ASS dialog failed: %s\n",
> +   av_err2str(ret));
> +
> +if (log_level == AV_LOG_ERROR)
> +return ret;
> +}
> +}
> +
> +if (dialog->style)
> +av_bprintf(&s->buffer, "");
>  }
>  } else {
>  #endif
> @@ -121,6 +143,22 @@ static int ttml_encode_frame(AVCodecContext *avctx, 
> uint8_t *buf,
>  if (!dialog)
>  return AVERROR(ENOMEM);
>  
> +if (dialog->style) {
> +av_bprint_init(&local_bprint, 0, AV_BPRINT_SIZE_UNLIMITED);
> +
> +av_bprint_escape(&local_bprint, dialog->style, NULL,
> + AV_ESCAPE_MODE_XML,
> + AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
> +if (!av_bprint_is_complete(&local_bprint)) {
> + return AVERROR(ENOMEM);
> +}
> +
> +av_bprintf(&s->buffer, "",
> +   local_bprint.str);
> +
> +av_bprint_finalize(&local_bprint, NULL);
> +}
> +
>  {
>  int ret = ff_ass_split_override_codes(&ttml_callbacks, s,
>dialog->text);
> @@ -140,6 +178,9 @@ static int ttml_encode_frame(AVCodecContext *avctx, 
> uint8_t *buf,
>  }
>  }
>  
> +if (dialog->style)
> +av_bprintf(&s->buffer, "");
> +
>  ff_ass_free_dialog(&dialog);
>  }
>  #if FF_API_ASS_TIMING
> @@ -173,17 +214,205 @@ static av_cold int ttml_encode_close(AVCodecContext 
> *avctx)
>  return 0;
>  }
>  
> +static const char *ttml_get_display_alignment(int alignment)
> +{
> +switch (alignment) {
> +case 1:
> +case 2:
> +case 3:
> +return "after";
> +case 4:
> + 

[FFmpeg-devel] [PATCH 1/5] avcodec/h265_metadata_bsf: Check nb_units before accessing the first in h265_metadata_update_fragment()

2021-03-30 Thread Michael Niedermayer
Fixes: null pointer dereference
Fixes: 
32113/clusterfuzz-testcase-minimized-ffmpeg_BSF_HEVC_METADATA_fuzzer-4803262287052800

Same as 0c48c332eeb2866d9353125f701e099c48889463

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

diff --git a/libavcodec/h265_metadata_bsf.c b/libavcodec/h265_metadata_bsf.c
index 59325c0471..d841839762 100644
--- a/libavcodec/h265_metadata_bsf.c
+++ b/libavcodec/h265_metadata_bsf.c
@@ -335,7 +335,7 @@ static int h265_metadata_update_fragment(AVBSFContext *bsf, 
AVPacket *pkt,
 int err, i;
 
 // If an AUD is present, it must be the first NAL unit.
-if (au->units[0].type == HEVC_NAL_AUD) {
+if (au->nb_units && au->units[0].type == HEVC_NAL_AUD) {
 if (ctx->aud == BSF_ELEMENT_REMOVE)
 ff_cbs_delete_unit(au, 0);
 } else {
-- 
2.17.1

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

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

[FFmpeg-devel] [PATCH 3/5] tools/target_dem_fuzzer: Fix packet leak

2021-03-30 Thread Michael Niedermayer
Fixes: 
32121/clusterfuzz-testcase-minimized-ffmpeg_IO_DEMUXER_fuzzer-4512973109460992

Signed-off-by: Michael Niedermayer 
---
 tools/target_dem_fuzzer.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/tools/target_dem_fuzzer.c b/tools/target_dem_fuzzer.c
index af1840b359..3c03c8d17c 100644
--- a/tools/target_dem_fuzzer.c
+++ b/tools/target_dem_fuzzer.c
@@ -186,10 +186,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
 
 ret = avformat_open_input(&avfmt, filename, fmt, NULL);
 if (ret < 0) {
-av_freep(&fuzzed_pb->buffer);
-av_freep(&fuzzed_pb);
-avformat_free_context(avfmt);
-return 0;
+goto fail;
 }
 
 ret = avformat_find_stream_info(avfmt, NULL);
@@ -203,10 +200,12 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
 av_packet_unref(pkt);
 }
 
+fail:
 av_packet_free(&pkt);
 av_freep(&fuzzed_pb->buffer);
 avio_context_free(&fuzzed_pb);
 avformat_close_input(&avfmt);
 
 return 0;
+
 }
-- 
2.17.1

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

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

[FFmpeg-devel] [PATCH 2/5] avformat/imx: Check palette chunk size

2021-03-30 Thread Michael Niedermayer
Fixes: out of array write
Fixes: 
32116/clusterfuzz-testcase-minimized-ffmpeg_dem_SIMBIOSIS_IMX_fuzzer-6702533894602752

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

diff --git a/libavformat/imx.c b/libavformat/imx.c
index d203ed7a28..22fca0bdc0 100644
--- a/libavformat/imx.c
+++ b/libavformat/imx.c
@@ -113,6 +113,8 @@ retry:
 imx->first_video_packet_pos = pos;
 break;
 case 0xAA98:
+if (chunk_size > 256 * 3)
+return AVERROR_INVALIDDATA;
 for (int i = 0; i < chunk_size / 3; i++) {
 unsigned r = avio_r8(pb) << 18;
 unsigned g = avio_r8(pb) << 10;
-- 
2.17.1

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

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

[FFmpeg-devel] [PATCH 5/5] avcodec/pnm_parser: Check image size addition for overflow

2021-03-30 Thread Michael Niedermayer
Fixes: assertion failure
Fixes: out of array access
Fixes: 
32664/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PGMYUV_fuzzer-6533642202513408.fuzz
Fixes: 
32669/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PGMYUV_fuzzer-6001928875147264

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

diff --git a/libavcodec/pnm_parser.c b/libavcodec/pnm_parser.c
index f3be6d640c..a822c17a2e 100644
--- a/libavcodec/pnm_parser.c
+++ b/libavcodec/pnm_parser.c
@@ -111,7 +111,7 @@ retry:
 } else {
 int ret = av_image_get_buffer_size(avctx->pix_fmt, avctx->width, 
avctx->height, 1);
 next = pnmctx.bytestream - pnmctx.bytestream_start + skip;
-if (ret >= 0)
+if (ret >= 0 && next + (uint64_t)ret <= INT_MAX)
 next += ret;
 }
 if (next != END_NOT_FOUND && pnmctx.bytestream_start != buf + skip)
-- 
2.17.1

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

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

[FFmpeg-devel] [PATCH 4/5] avcodec/lscrdec: Check length in decode_idat()

2021-03-30 Thread Michael Niedermayer
Fixes: out of array access
Fixes: 
32264/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_LSCR_fuzzer-6684504010915840

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

diff --git a/libavcodec/lscrdec.c b/libavcodec/lscrdec.c
index f5cfe1fa04..042da84bf9 100644
--- a/libavcodec/lscrdec.c
+++ b/libavcodec/lscrdec.c
@@ -76,6 +76,10 @@ static int decode_idat(LSCRContext *s, int length)
 int ret;
 s->zstream.avail_in = FFMIN(length, bytestream2_get_bytes_left(&s->gb));
 s->zstream.next_in  = s->gb.buffer;
+
+if (length <= 0)
+return AVERROR_INVALIDDATA;
+
 bytestream2_skip(&s->gb, length);
 
 /* decode one line if possible */
-- 
2.17.1

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

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

Re: [FFmpeg-devel] [PATCH v2] examples/decode_video: flush parser to fix missing frame

2021-03-30 Thread zhilizhao(赵志立)
Ping.

I have got multiple users report about the issue when they use the example as a 
tutorial.

> On Oct 12, 2020, at 12:47 AM, Zhao Zhili  wrote:
> 
> Ping for review.
> 
>> On Sep 24, 2020, at 2:01 AM, Zhao Zhili  wrote:
>> 
>> To reproduce, run decode_video with a single frame sample. No frame
>> was decoded before the patch.
>> ---
>> doc/examples/decode_video.c | 12 +++-
>> 1 file changed, 7 insertions(+), 5 deletions(-)
>> 
>> diff --git a/doc/examples/decode_video.c b/doc/examples/decode_video.c
>> index 18ee90a6c0..9ce3531d63 100644
>> --- a/doc/examples/decode_video.c
>> +++ b/doc/examples/decode_video.c
>> @@ -92,6 +92,7 @@ int main(int argc, char **argv)
>>uint8_t *data;
>>size_t   data_size;
>>int ret;
>> +int eof;
>>AVPacket *pkt;
>> 
>>if (argc <= 2) {
>> @@ -150,15 +151,14 @@ int main(int argc, char **argv)
>>exit(1);
>>}
>> 
>> -while (!feof(f)) {
>> +do {
>>/* read raw data from the input file */
>>data_size = fread(inbuf, 1, INBUF_SIZE, f);
>> -if (!data_size)
>> -break;
>> +eof = !data_size;
>> 
>>/* use the parser to split the data into frames */
>>data = inbuf;
>> -while (data_size > 0) {
>> +while (data_size > 0 || eof) {
>>ret = av_parser_parse2(parser, c, &pkt->data, &pkt->size,
>>   data, data_size, AV_NOPTS_VALUE, 
>> AV_NOPTS_VALUE, 0);
>>if (ret < 0) {
>> @@ -170,8 +170,10 @@ int main(int argc, char **argv)
>> 
>>if (pkt->size)
>>decode(c, frame, pkt, outfilename);
>> +else if (eof)
>> +break;
>>}
>> -}
>> +} while (!eof);
>> 
>>/* flush the decoder */
>>decode(c, frame, NULL, outfilename);
>> -- 
>> 2.25.1
>> 
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> 
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> 

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

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

[FFmpeg-devel] [PATCH v3 1/5] avcodec/mips: Restore the initialization sequence of MSA and MMI in ff_h264chroma_init_mips.

2021-03-30 Thread Shiyou Yin
The MSA optimization has been refined in commit 93218c2 and ce0a52e.
It is better than MMI version now.
Speed of decoding H264: 4.83x ==> 4.89x (tested on 3A4000).
---
 libavcodec/mips/h264chroma_init_mips.c | 19 +--
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/libavcodec/mips/h264chroma_init_mips.c 
b/libavcodec/mips/h264chroma_init_mips.c
index 6bb19d3..755cc04 100644
--- a/libavcodec/mips/h264chroma_init_mips.c
+++ b/libavcodec/mips/h264chroma_init_mips.c
@@ -28,7 +28,15 @@ av_cold void ff_h264chroma_init_mips(H264ChromaContext *c, 
int bit_depth)
 int cpu_flags = av_get_cpu_flags();
 int high_bit_depth = bit_depth > 8;
 
-/* MMI apears to be faster than MSA here */
+if (have_mmi(cpu_flags)) {
+if (!high_bit_depth) {
+c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_mmi;
+c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_mmi;
+c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_mmi;
+c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_mmi;
+}
+}
+
 if (have_msa(cpu_flags)) {
 if (!high_bit_depth) {
 c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_msa;
@@ -40,13 +48,4 @@ av_cold void ff_h264chroma_init_mips(H264ChromaContext *c, 
int bit_depth)
 c->avg_h264_chroma_pixels_tab[2] = ff_avg_h264_chroma_mc2_msa;
 }
 }
-
-if (have_mmi(cpu_flags)) {
-if (!high_bit_depth) {
-c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_mmi;
-c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_mmi;
-c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_mmi;
-c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_mmi;
-}
-}
 }
-- 
2.1.0

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

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

[FFmpeg-devel] [mips] Optimize H264 decoding for MIPS platform.

2021-03-30 Thread Shiyou Yin
v2: Fixed a build error in [PATCH 2/5].
v3: add patch 4/5.

[PATCH v3 1/5] avcodec/mips: Restore the initialization sequence of
[PATCH v3 2/5] avcodec/mips: Refine get_cabac_inline_mips.
[PATCH v3 3/5] avcodec/mips: Optimize function ff_h264_loop_filter_strength_msa.
[PATCH v3 4/5] avcodec/mips: Refine ff_h264_h_lpf_luma_inter_msa
[PATCH v3 5/5] mips: Fix potential illegal instruction error.

___
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 v3 2/5] avcodec/mips: Refine get_cabac_inline_mips.

2021-03-30 Thread Shiyou Yin
1. Refined function get_cabac_inline_mips.
2. Optimize function get_cabac_bypass and get_cabac_bypass_sign.

Speed of decoding h264: 4.89x ==> 5.05x(tested on 3A4000).
---
 libavcodec/mips/cabac.h | 131 +---
 1 file changed, 102 insertions(+), 29 deletions(-)

diff --git a/libavcodec/mips/cabac.h b/libavcodec/mips/cabac.h
index 3d09e93..0ee7594 100644
--- a/libavcodec/mips/cabac.h
+++ b/libavcodec/mips/cabac.h
@@ -2,7 +2,8 @@
  * Loongson SIMD optimized h264chroma
  *
  * Copyright (c) 2018 Loongson Technology Corporation Limited
- * Copyright (c) 2018 Shiyou Yin 
+ * Contributed by Shiyou Yin 
+ *Gu Xiwei(guxiwei...@loongson.cn)
  *
  * This file is part of FFmpeg.
  *
@@ -25,18 +26,18 @@
 #define AVCODEC_MIPS_CABAC_H
 
 #include "libavcodec/cabac.h"
-#include "libavutil/mips/asmdefs.h"
+#include "libavutil/mips/mmiutils.h"
 #include "config.h"
 
 #define get_cabac_inline get_cabac_inline_mips
 static av_always_inline int get_cabac_inline_mips(CABACContext *c,
- uint8_t * const state){
+  uint8_t * const state){
 mips_reg tmp0, tmp1, tmp2, bit;
 
 __asm__ volatile (
 "lbu  %[bit],0(%[state])   \n\t"
 "and  %[tmp0],   %[c_range], 0xC0  \n\t"
-PTR_ADDU "%[tmp0],   %[tmp0],%[tmp0]   \n\t"
+PTR_SLL  "%[tmp0],   %[tmp0],0x01  \n\t"
 PTR_ADDU "%[tmp0],   %[tmp0],%[tables] \n\t"
 PTR_ADDU "%[tmp0],   %[tmp0],%[bit]\n\t"
 /* tmp1: RangeLPS */
@@ -44,18 +45,11 @@ static av_always_inline int 
get_cabac_inline_mips(CABACContext *c,
 
 PTR_SUBU "%[c_range],%[c_range], %[tmp1]   \n\t"
 PTR_SLL  "%[tmp0],   %[c_range], 0x11  \n\t"
-PTR_SUBU "%[tmp0],   %[tmp0],%[c_low]  \n\t"
-
-/* tmp2: lps_mask */
-PTR_SRA  "%[tmp2],   %[tmp0],0x1F  \n\t"
-/* If tmp0 < 0, lps_mask ==  0x*/
-/* If tmp0 >= 0, lps_mask ==  0x*/
+"slt  %[tmp2],   %[tmp0],%[c_low]  \n\t"
 "beqz %[tmp2],   1f\n\t"
-PTR_SLL  "%[tmp0],   %[c_range], 0x11  \n\t"
+"move %[c_range],%[tmp1]   \n\t"
+"not  %[bit],%[bit]\n\t"
 PTR_SUBU "%[c_low],  %[c_low],   %[tmp0]   \n\t"
-PTR_SUBU "%[tmp0],   %[tmp1],%[c_range]\n\t"
-PTR_ADDU "%[c_range],%[c_range], %[tmp0]   \n\t"
-"xor  %[bit],%[bit], %[tmp2]   \n\t"
 
 "1:\n\t"
 /* tmp1: *state */
@@ -70,23 +64,18 @@ static av_always_inline int 
get_cabac_inline_mips(CABACContext *c,
 PTR_SLL  "%[c_range],%[c_range], %[tmp2]   \n\t"
 PTR_SLL  "%[c_low],  %[c_low],   %[tmp2]   \n\t"
 
-"and  %[tmp0],   %[c_low],   %[cabac_mask] \n\t"
-"bnez %[tmp0],   1f\n\t"
-PTR_ADDIU"%[tmp0],   %[c_low],   -0x01 \n\t"
+"and  %[tmp1],   %[c_low],   %[cabac_mask] \n\t"
+"bnez %[tmp1],   1f\n\t"
+PTR_ADDIU"%[tmp0],   %[c_low],   -0X01 \n\t"
 "xor  %[tmp0],   %[c_low],   %[tmp0]   \n\t"
 PTR_SRA  "%[tmp0],   %[tmp0],0x0f  \n\t"
 PTR_ADDU "%[tmp0],   %[tmp0],%[tables] \n\t"
+/* tmp2: ff_h264_norm_shift[x >> (CABAC_BITS - 1)] */
 "lbu  %[tmp2],   %[norm_off](%[tmp0])  \n\t"
-#if CABAC_BITS == 16
-"lbu  %[tmp0],   0(%[c_bytestream])\n\t"
-"lbu  %[tmp1],   1(%[c_bytestream])\n\t"
-PTR_SLL  "%[tmp0],   %[tmp0],0x09  \n\t"
-PTR_SLL  "%[tmp1],   %[tmp1],0x01  \n\t"
-PTR_ADDU "%[tmp0],   %[tmp0],%[tmp1]   \n\t"
-#else
-"lbu  %[tmp0],   0(%[c_bytestream])\n\t"
+
+"lhu  %[tmp0],   0(%[c_bytestream])\n\t"
+"wsbh %[tmp0],   %[tmp0]   \n\t"
 PTR_SLL  "%[tmp0],   %[tmp0],0x01  \n\t"
-#endif
 PTR_SUBU "%[tmp0],   %[tmp0],%[cabac_mask] \n\t"
 
 "li   %[tmp1],   0x07  \n\t"
@@ -94,10 +83,13 @@ static av_always_inline int 
get_cabac_inline_mips(CABACContext *c,
  

[FFmpeg-devel] [PATCH v3 3/5] avcodec/mips: Optimize function ff_h264_loop_filter_strength_msa.

2021-03-30 Thread Shiyou Yin
From: gxw 

Speed of decoding H264 1080P: 5.05x ==> 5.13x

Signed-off-by: Shiyou Yin 
---
 libavcodec/mips/Makefile|   3 +-
 libavcodec/mips/h264_deblock_msa.c  | 153 
 libavcodec/mips/h264dsp_init_mips.c |   2 +
 libavcodec/mips/h264dsp_mips.h  |   4 +
 4 files changed, 161 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/mips/h264_deblock_msa.c

diff --git a/libavcodec/mips/Makefile b/libavcodec/mips/Makefile
index 2be4d9b..81a73a4 100644
--- a/libavcodec/mips/Makefile
+++ b/libavcodec/mips/Makefile
@@ -57,7 +57,8 @@ MSA-OBJS-$(CONFIG_VP8_DECODER)+= 
mips/vp8_mc_msa.o \
  mips/vp8_lpf_msa.o
 MSA-OBJS-$(CONFIG_VP3DSP) += mips/vp3dsp_idct_msa.o
 MSA-OBJS-$(CONFIG_H264DSP)+= mips/h264dsp_msa.o\
- mips/h264idct_msa.o
+ mips/h264idct_msa.o   \
+ mips/h264_deblock_msa.o
 MSA-OBJS-$(CONFIG_H264QPEL)   += mips/h264qpel_msa.o
 MSA-OBJS-$(CONFIG_H264CHROMA) += mips/h264chroma_msa.o
 MSA-OBJS-$(CONFIG_H264PRED)   += mips/h264pred_msa.o
diff --git a/libavcodec/mips/h264_deblock_msa.c 
b/libavcodec/mips/h264_deblock_msa.c
new file mode 100644
index 000..4fed55c
--- /dev/null
+++ b/libavcodec/mips/h264_deblock_msa.c
@@ -0,0 +1,153 @@
+/*
+ * MIPS SIMD optimized H.264 deblocking code
+ *
+ * Copyright (c) 2020 Loongson Technology Corporation Limited
+ *Gu Xiwei 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavcodec/bit_depth_template.c"
+#include "h264dsp_mips.h"
+#include "libavutil/mips/generic_macros_msa.h"
+#include "libavcodec/mips/h264dsp_mips.h"
+
+#define h264_loop_filter_strength_iteration_msa(edges, step, mask_mv, dir, \
+d_idx, mask_dir)   \
+do {   \
+int b_idx = 0; \
+int step_x4 = step << 2; \
+int d_idx_12 = d_idx + 12; \
+int d_idx_52 = d_idx + 52; \
+int d_idx_x4 = d_idx << 2; \
+int d_idx_x4_48 = d_idx_x4 + 48; \
+int dir_x32  = dir * 32; \
+uint8_t *ref_t = (uint8_t*)ref; \
+uint8_t *mv_t  = (uint8_t*)mv; \
+uint8_t *nnz_t = (uint8_t*)nnz; \
+uint8_t *bS_t  = (uint8_t*)bS; \
+mask_mv <<= 3; \
+for (; b_idx < edges; b_idx += step) { \
+out &= mask_dir; \
+if (!(mask_mv & b_idx)) { \
+if (bidir) { \
+ref_2 = LD_SB(ref_t + d_idx_12); \
+ref_3 = LD_SB(ref_t + d_idx_52); \
+ref_0 = LD_SB(ref_t + 12); \
+ref_1 = LD_SB(ref_t + 52); \
+ref_2 = (v16i8)__msa_ilvr_w((v4i32)ref_3, (v4i32)ref_2); \
+ref_0 = (v16i8)__msa_ilvr_w((v4i32)ref_0, (v4i32)ref_0); \
+ref_1 = (v16i8)__msa_ilvr_w((v4i32)ref_1, (v4i32)ref_1); \
+ref_3 = (v16i8)__msa_shf_h((v8i16)ref_2, 0x4e); \
+ref_0 -= ref_2; \
+ref_1 -= ref_3; \
+ref_0 = (v16i8)__msa_or_v((v16u8)ref_0, (v16u8)ref_1); \
+\
+tmp_2 = LD_SH(mv_t + d_idx_x4_48);   \
+tmp_3 = LD_SH(mv_t + 48); \
+tmp_4 = LD_SH(mv_t + 208); \
+tmp_5 = tmp_2 - tmp_3; \
+tmp_6 = tmp_2 - tmp_4; \
+SAT_SH2_SH(tmp_5, tmp_6, 7); \
+tmp_0 = __msa_pckev_b((v16i8)tmp_6, (v16i8)tmp_5); \
+tmp_0 += cnst_1; \
+tmp_0 = (v16i8)__msa_subs_u_b((v16u8)tmp_0, (v16u8)cnst_0);\
+tmp_0 = (v16i8)__msa_sat_s_h((v8i16)tmp_0, 7); \
+tmp_0 = __msa_pckev_b(tmp_0, tmp_0); \
+out   = (v16i8)__msa_or_v((v16u8)ref_0, (v16u8)tmp_0); \
+\
+tmp_2 = LD_SH(mv_t + 208 + d_idx_x4); \
+tmp_5 = tmp_2 - tmp_3; \
+tmp_6 = tmp_2 - tmp_4; \
+SAT_SH2_SH(tmp_5, tmp_6, 7); \
+tmp_1 = __msa_pckev_b((v16i8)tmp_6, (v16i8)tmp_5); \
+tmp_1 += cnst_1; \
+tmp_1 = (v16i8)__ms

[FFmpeg-devel] [PATCH v3 4/5] avcodec/mips: Refine ff_h264_h_lpf_luma_inter_msa

2021-03-30 Thread Shiyou Yin
From: gxw 

Using mask to avoid judgment, H264 4K decoding speed
improved about 0.1fps tested on 3A4000

Signed-off-by: Shiyou Yin 
---
 libavcodec/mips/h264dsp_msa.c | 465 --
 1 file changed, 171 insertions(+), 294 deletions(-)

diff --git a/libavcodec/mips/h264dsp_msa.c b/libavcodec/mips/h264dsp_msa.c
index a8c3f3c..9d815f8 100644
--- a/libavcodec/mips/h264dsp_msa.c
+++ b/libavcodec/mips/h264dsp_msa.c
@@ -1284,284 +1284,160 @@ static void 
avc_loopfilter_cb_or_cr_intra_edge_ver_msa(uint8_t *data_cb_or_cr,
 }
 }
 
-static void avc_loopfilter_luma_inter_edge_ver_msa(uint8_t *data,
-   uint8_t bs0, uint8_t bs1,
-   uint8_t bs2, uint8_t bs3,
-   uint8_t tc0, uint8_t tc1,
-   uint8_t tc2, uint8_t tc3,
-   uint8_t alpha_in,
-   uint8_t beta_in,
-   ptrdiff_t img_width)
+static void avc_loopfilter_luma_inter_edge_ver_msa(uint8_t* pPix, uint32_t 
iStride,
+   uint8_t iAlpha, uint8_t 
iBeta,
+   uint8_t* pTc)
 {
-v16u8 tmp_vec, bs = { 0 };
-
-tmp_vec = (v16u8) __msa_fill_b(bs0);
-bs = (v16u8) __msa_insve_w((v4i32) bs, 0, (v4i32) tmp_vec);
-tmp_vec = (v16u8) __msa_fill_b(bs1);
-bs = (v16u8) __msa_insve_w((v4i32) bs, 1, (v4i32) tmp_vec);
-tmp_vec = (v16u8) __msa_fill_b(bs2);
-bs = (v16u8) __msa_insve_w((v4i32) bs, 2, (v4i32) tmp_vec);
-tmp_vec = (v16u8) __msa_fill_b(bs3);
-bs = (v16u8) __msa_insve_w((v4i32) bs, 3, (v4i32) tmp_vec);
-
-if (!__msa_test_bz_v(bs)) {
-uint8_t *src = data - 4;
-v16u8 p3_org, p2_org, p1_org, p0_org, q0_org, q1_org, q2_org, q3_org;
-v16u8 p0_asub_q0, p1_asub_p0, q1_asub_q0, alpha, beta;
-v16u8 is_less_than, is_less_than_beta, is_less_than_alpha;
-v16u8 is_bs_greater_than0;
-v16u8 tc = { 0 };
-v16i8 zero = { 0 };
-
-tmp_vec = (v16u8) __msa_fill_b(tc0);
-tc = (v16u8) __msa_insve_w((v4i32) tc, 0, (v4i32) tmp_vec);
-tmp_vec = (v16u8) __msa_fill_b(tc1);
-tc = (v16u8) __msa_insve_w((v4i32) tc, 1, (v4i32) tmp_vec);
-tmp_vec = (v16u8) __msa_fill_b(tc2);
-tc = (v16u8) __msa_insve_w((v4i32) tc, 2, (v4i32) tmp_vec);
-tmp_vec = (v16u8) __msa_fill_b(tc3);
-tc = (v16u8) __msa_insve_w((v4i32) tc, 3, (v4i32) tmp_vec);
-
-is_bs_greater_than0 = (zero < bs);
-
-{
-v16u8 row0, row1, row2, row3, row4, row5, row6, row7;
-v16u8 row8, row9, row10, row11, row12, row13, row14, row15;
-
-LD_UB8(src, img_width,
-   row0, row1, row2, row3, row4, row5, row6, row7);
-src += (8 * img_width);
-LD_UB8(src, img_width,
-   row8, row9, row10, row11, row12, row13, row14, row15);
-
-TRANSPOSE16x8_UB_UB(row0, row1, row2, row3, row4, row5, row6, row7,
-row8, row9, row10, row11,
-row12, row13, row14, row15,
-p3_org, p2_org, p1_org, p0_org,
-q0_org, q1_org, q2_org, q3_org);
-}
-
-p0_asub_q0 = __msa_asub_u_b(p0_org, q0_org);
-p1_asub_p0 = __msa_asub_u_b(p1_org, p0_org);
-q1_asub_q0 = __msa_asub_u_b(q1_org, q0_org);
-
-alpha = (v16u8) __msa_fill_b(alpha_in);
-beta = (v16u8) __msa_fill_b(beta_in);
-
-is_less_than_alpha = (p0_asub_q0 < alpha);
-is_less_than_beta = (p1_asub_p0 < beta);
-is_less_than = is_less_than_beta & is_less_than_alpha;
-is_less_than_beta = (q1_asub_q0 < beta);
-is_less_than = is_less_than_beta & is_less_than;
-is_less_than = is_less_than & is_bs_greater_than0;
-
-if (!__msa_test_bz_v(is_less_than)) {
-v16i8 negate_tc, sign_negate_tc;
-v16u8 p0, q0, p2_asub_p0, q2_asub_q0;
-v8i16 tc_r, tc_l, negate_tc_r, i16_negatetc_l;
-v8i16 p1_org_r, p0_org_r, q0_org_r, q1_org_r;
-v8i16 p1_org_l, p0_org_l, q0_org_l, q1_org_l;
-v8i16 p0_r, q0_r, p0_l, q0_l;
-
-negate_tc = zero - (v16i8) tc;
-sign_negate_tc = __msa_clti_s_b(negate_tc, 0);
-
-ILVRL_B2_SH(sign_negate_tc, negate_tc, negate_tc_r, 
i16_negatetc_l);
-
-UNPCK_UB_SH(tc, tc_r, tc_l);
-UNPCK_UB_SH(p1_org, p1_org_r, p1_org_l);
-UNPCK_UB_SH(p0_org, p0_org_r, p0_org_l);
-UNPCK_UB_SH(q0_org, q0_org_r, q0_org_l);
-
-p2_asub_p0 = __msa_asub_u_b(p2_org, p0_org);
-is_less_than_beta = (p2_asub_p0 < beta);
-is_less_than_beta = 

[FFmpeg-devel] [PATCH v3 5/5] mips: Fix potential illegal instruction error.

2021-03-30 Thread Shiyou Yin
MSA2 optimizations are attached to MSA macros in generic_macros_msa.h.
It's difficult to do runtime check for them. Remove this part of code
can make it more robust. H264 1080p decoding: 5.13x==>5.12x.
---
 configure   |  7 +--
 libavutil/mips/generic_macros_msa.h | 37 -
 2 files changed, 1 insertion(+), 43 deletions(-)

diff --git a/configure b/configure
index d7a3f50..7b05612 100755
--- a/configure
+++ b/configure
@@ -451,7 +451,6 @@ Optimization options (experts only):
   --disable-mipsdspdisable MIPS DSP ASE R1 optimizations
   --disable-mipsdspr2  disable MIPS DSP ASE R2 optimizations
   --disable-msadisable MSA optimizations
-  --disable-msa2   disable MSA2 optimizations
   --disable-mipsfpudisable floating point MIPS optimizations
   --disable-mmidisable Loongson SIMD optimizations
   --disable-fast-unaligned consider unaligned accesses slow
@@ -2025,7 +2024,6 @@ ARCH_EXT_LIST_MIPS="
 mipsdsp
 mipsdspr2
 msa
-msa2
 "
 
 ARCH_EXT_LIST_LOONGSON="
@@ -2564,7 +2562,6 @@ mipsdsp_deps="mips"
 mipsdspr2_deps="mips"
 mmi_deps_any="loongson2 loongson3"
 msa_deps="mipsfpu"
-msa2_deps="msa"
 
 cpunop_deps="i686"
 x86_64_select="i686"
@@ -5907,9 +5904,8 @@ elif enabled mips; then
 enabled mipsdsp && check_inline_asm_flags mipsdsp '"addu.qb $t0, $t1, 
$t2"' '-mdsp'
 enabled mipsdspr2 && check_inline_asm_flags mipsdspr2 '"absq_s.qb $t0, 
$t1"' '-mdspr2'
 
-# MSA and MSA2 can be detected at runtime so we supply extra flags here
+# MSA can be detected at runtime so we supply extra flags here
 enabled mipsfpu && enabled msa && check_inline_asm msa '"addvi.b $w0, $w1, 
1"' '-mmsa' && append MSAFLAGS '-mmsa'
-enabled msa && enabled msa2 && check_inline_asm msa2 '"nxbits.any.b $w0, 
$w0"' '-mmsa2' && append MSAFLAGS '-mmsa2'
 
 # loongson2 have no switch cflag so we can only probe toolchain ability
 enabled loongson2 && check_inline_asm loongson2 '"dmult.g $8, $9, $10"' && 
disable loongson3
@@ -7340,7 +7336,6 @@ if enabled mips; then
 echo "MIPS DSP R1 enabled   ${mipsdsp-no}"
 echo "MIPS DSP R2 enabled   ${mipsdspr2-no}"
 echo "MIPS MSA enabled  ${msa-no}"
-echo "MIPS MSA2 enabled ${msa2-no}"
 echo "LOONGSON MMI enabled  ${mmi-no}"
 fi
 if enabled ppc; then
diff --git a/libavutil/mips/generic_macros_msa.h 
b/libavutil/mips/generic_macros_msa.h
index bb25e9f..1486f72 100644
--- a/libavutil/mips/generic_macros_msa.h
+++ b/libavutil/mips/generic_macros_msa.h
@@ -25,10 +25,6 @@
 #include 
 #include 
 
-#if HAVE_MSA2
-#include 
-#endif
-
 #define ALIGNMENT   16
 #define ALLOC_ALIGNED(align) __attribute__ ((aligned((align) << 1)))
 
@@ -1119,15 +1115,6 @@
  unsigned absolute diff values, even-odd pairs are added
  together to generate 8 halfword results.
 */
-#if HAVE_MSA2
-#define SAD_UB2_UH(in0, in1, ref0, ref1) \
-( {  \
-v8u16 sad_m = { 0 }; \
-sad_m += __builtin_msa2_sad_adj2_u_w2x_b((v16u8) in0, (v16u8) ref0); \
-sad_m += __builtin_msa2_sad_adj2_u_w2x_b((v16u8) in1, (v16u8) ref1); \
-sad_m;   \
-} )
-#else
 #define SAD_UB2_UH(in0, in1, ref0, ref1)\
 ( { \
 v16u8 diff0_m, diff1_m; \
@@ -1141,7 +1128,6 @@
 \
 sad_m;  \
 } )
-#endif // #if HAVE_MSA2
 
 /* Description : Insert specified word elements from input vectors to 1
  destination vector
@@ -2183,12 +2169,6 @@
  extracted and interleaved with same vector 'in0' to generate
  4 word elements keeping sign intact
 */
-#if HAVE_MSA2
-#define UNPCK_R_SH_SW(in, out)   \
-{\
-out = (v4i32) __builtin_msa2_w2x_lo_s_h((v8i16) in); \
-}
-#else
 #define UNPCK_R_SH_SW(in, out)   \
 {\
 v8i16 sign_m;\
@@ -2196,7 +2176,6 @@
 sign_m = __msa_clti_s_h((v8i16) in, 0);  \
 out = (v4i32) __msa_ilvr_h(sign_m, (v8i16) in);  \
 }
-#endif // #if HAVE_MSA2
 
 /* Description : Sign extend byte elements from input vector and return
  halfword results in pair of vectors
@@ -2209,13 +2188,6 @@
  Then interleaved left with same vector 'in0' to
  generate 8 signed halfword elements in 'out1'
 */
-#if HAVE_MSA2
-#define UNPCK_SB_SH(in, out0, out1)   \
-{

Re: [FFmpeg-devel] [PATCH 1/4] avformat: Add and use helper function to add attachment streams

2021-03-30 Thread James Almer

On 3/29/2021 5:42 AM, Andreas Rheinhardt wrote:

All instances of adding attached pictures to a stream or adding
a stream and an attached packet to said stream have several things
in common like setting the index and flags of the packet, setting
the stream disposition etc. This commit therefore factors this out.

Signed-off-by: Andreas Rheinhardt 
---
I always pondered factoring this out; James' proposal made me do it.

  libavformat/apetag.c   | 10 +-
  libavformat/flac_picture.c | 17 -
  libavformat/id3v2.c| 21 ++---
  libavformat/internal.h | 13 +
  libavformat/matroskadec.c  | 15 +++
  libavformat/mov.c  | 25 +++--
  libavformat/utils.c| 30 ++
  libavformat/wtvdec.c   | 12 ++--
  8 files changed, 66 insertions(+), 77 deletions(-)

diff --git a/libavformat/apetag.c b/libavformat/apetag.c
index 23ee6b516d..6f82fbe202 100644
--- a/libavformat/apetag.c
+++ b/libavformat/apetag.c
@@ -79,20 +79,12 @@ static int ape_tag_read_field(AVFormatContext *s)
  av_dict_set(&st->metadata, key, filename, 0);
  
  if ((id = ff_guess_image2_codec(filename)) != AV_CODEC_ID_NONE) {

-int ret;
-
-ret = av_get_packet(s->pb, &st->attached_pic, size);
+int ret = ff_add_attached_pic(s, st, s->pb, NULL, size);
  if (ret < 0) {
  av_log(s, AV_LOG_ERROR, "Error reading cover art.\n");
  return ret;
  }
-
-st->disposition  |= AV_DISPOSITION_ATTACHED_PIC;
-st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
  st->codecpar->codec_id   = id;
-
-st->attached_pic.stream_index = st->index;
-st->attached_pic.flags   |= AV_PKT_FLAG_KEY;
  } else {
  if ((ret = ff_get_extradata(s, st->codecpar, s->pb, size)) < 0)
  return ret;
diff --git a/libavformat/flac_picture.c b/libavformat/flac_picture.c
index f15cfa877a..96e14f76c9 100644
--- a/libavformat/flac_picture.c
+++ b/libavformat/flac_picture.c
@@ -160,20 +160,11 @@ int ff_flac_parse_picture(AVFormatContext *s, uint8_t 
*buf, int buf_size, int tr
  if (AV_RB64(data->data) == PNGSIG)
  id = AV_CODEC_ID_PNG;
  
-st = avformat_new_stream(s, NULL);

-if (!st) {
-RETURN_ERROR(AVERROR(ENOMEM));
-}
-
-av_packet_unref(&st->attached_pic);
-st->attached_pic.buf  = data;
-st->attached_pic.data = data->data;
-st->attached_pic.size = len;
-st->attached_pic.stream_index = st->index;
-st->attached_pic.flags   |= AV_PKT_FLAG_KEY;
+ret = ff_add_attached_pic(s, NULL, NULL, &data, 0);
+if (ret < 0)
+RETURN_ERROR(ret);
  
-st->disposition  |= AV_DISPOSITION_ATTACHED_PIC;

-st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
+st = s->streams[s->nb_streams - 1];
  st->codecpar->codec_id   = id;
  st->codecpar->width  = width;
  st->codecpar->height = height;
diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index f33b7ba93a..863709abbf 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -1142,34 +1142,25 @@ int ff_id3v2_parse_apic(AVFormatContext *s, 
ID3v2ExtraMeta *extra_meta)
  for (cur = extra_meta; cur; cur = cur->next) {
  ID3v2ExtraMetaAPIC *apic;
  AVStream *st;
+int ret;
  
  if (strcmp(cur->tag, "APIC"))

  continue;
  apic = &cur->data.apic;
  
-if (!(st = avformat_new_stream(s, NULL)))

-return AVERROR(ENOMEM);
-
-st->disposition  |= AV_DISPOSITION_ATTACHED_PIC;
-st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
+ret = ff_add_attached_pic(s, NULL, NULL, &apic->buf, 0);
+if (ret < 0)
+return ret;
+st  = s->streams[s->nb_streams - 1];
  st->codecpar->codec_id   = apic->id;
  
-if (AV_RB64(apic->buf->data) == PNGSIG)

+if (AV_RB64(st->attached_pic.data) == PNGSIG)
  st->codecpar->codec_id = AV_CODEC_ID_PNG;
  
  if (apic->description[0])

  av_dict_set(&st->metadata, "title", apic->description, 0);
  
  av_dict_set(&st->metadata, "comment", apic->type, 0);

-
-av_packet_unref(&st->attached_pic);
-st->attached_pic.buf  = apic->buf;
-st->attached_pic.data = apic->buf->data;
-st->attached_pic.size = apic->buf->size - 
AV_INPUT_BUFFER_PADDING_SIZE;
-st->attached_pic.stream_index = st->index;
-st->attached_pic.flags   |= AV_PKT_FLAG_KEY;
-
-apic->buf = NULL;
  }
  
  return 0;

diff --git a/libavformat/internal.h b/libavformat/internal.h
index 8631694d00..b3c5d8a1d5 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -669,6 +669,19 @@ int ff_framehash_write_header(AVFormatContext *s);
   */
  int ff_read_packet(AV

Re: [FFmpeg-devel] [PATCH 4/4] avformat/asf: Use ff_add_attached_pic() to read attached pics

2021-03-30 Thread James Almer

On 3/29/2021 5:45 AM, Andreas Rheinhardt wrote:

Also removes a stack packet.

Signed-off-by: Andreas Rheinhardt 
---
  libavformat/asf.c | 17 +++--
  1 file changed, 3 insertions(+), 14 deletions(-)

diff --git a/libavformat/asf.c b/libavformat/asf.c
index 204355abab..cef0f9f646 100644
--- a/libavformat/asf.c
+++ b/libavformat/asf.c
@@ -20,6 +20,7 @@
  
  #include "asf.h"

  #include "id3v2.h"
+#include "internal.h"
  
  const ff_asf_guid ff_asf_header = {

  0x30, 0x26, 0xB2, 0x75, 0x8E, 0x66, 0xCF, 0x11, 0xA6, 0xD9, 0x00, 0xAA, 
0x00, 0x62, 0xCE, 0x6C
@@ -176,7 +177,6 @@ const AVMetadataConv ff_asf_metadata_conv[] = {
   * but in reality this is only loosely similar */
  static int asf_read_picture(AVFormatContext *s, int len)
  {
-AVPacket pkt  = { 0 };
  const CodecMime *mime = ff_id3v2_mime_tags;
  enum  AVCodecID id= AV_CODEC_ID_NONE;
  char mimetype[64];
@@ -230,22 +230,12 @@ static int asf_read_picture(AVFormatContext *s, int len)
  return AVERROR(ENOMEM);
  len -= avio_get_str16le(s->pb, len - picsize, desc, desc_len);
  
-ret = av_get_packet(s->pb, &pkt, picsize);

+ret = ff_add_attached_pic(s, NULL, s->pb, NULL, picsize);
  if (ret < 0)
  goto fail;
+st = s->streams[s->nb_streams - 1];
  
-st  = avformat_new_stream(s, NULL);

-if (!st) {
-ret = AVERROR(ENOMEM);
-goto fail;
-}
-
-st->disposition  |= AV_DISPOSITION_ATTACHED_PIC;
-st->codecpar->codec_type  = AVMEDIA_TYPE_VIDEO;
  st->codecpar->codec_id= id;
-st->attached_pic  = pkt;
-st->attached_pic.stream_index = st->index;
-st->attached_pic.flags   |= AV_PKT_FLAG_KEY;
  
  if (*desc) {

  if (av_dict_set(&st->metadata, "title", desc, AV_DICT_DONT_STRDUP_VAL) 
< 0)
@@ -260,7 +250,6 @@ static int asf_read_picture(AVFormatContext *s, int len)
  
  fail:

  av_freep(&desc);
-av_packet_unref(&pkt);
  return ret;
  }


This patch could be squashed into 1/4. Just apply 2/4 first.

Should be ok either way.
___
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 4/4] avformat/asf: Use ff_add_attached_pic() to read attached pics

2021-03-30 Thread Andreas Rheinhardt
James Almer:
> On 3/29/2021 5:45 AM, Andreas Rheinhardt wrote:
>> Also removes a stack packet.
>>
>> Signed-off-by: Andreas Rheinhardt 
>> ---
>>   libavformat/asf.c | 17 +++--
>>   1 file changed, 3 insertions(+), 14 deletions(-)
>>
>> diff --git a/libavformat/asf.c b/libavformat/asf.c
>> index 204355abab..cef0f9f646 100644
>> --- a/libavformat/asf.c
>> +++ b/libavformat/asf.c
>> @@ -20,6 +20,7 @@
>>     #include "asf.h"
>>   #include "id3v2.h"
>> +#include "internal.h"
>>     const ff_asf_guid ff_asf_header = {
>>   0x30, 0x26, 0xB2, 0x75, 0x8E, 0x66, 0xCF, 0x11, 0xA6, 0xD9,
>> 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C
>> @@ -176,7 +177,6 @@ const AVMetadataConv ff_asf_metadata_conv[] = {
>>    * but in reality this is only loosely similar */
>>   static int asf_read_picture(AVFormatContext *s, int len)
>>   {
>> -    AVPacket pkt  = { 0 };
>>   const CodecMime *mime = ff_id3v2_mime_tags;
>>   enum  AVCodecID id    = AV_CODEC_ID_NONE;
>>   char mimetype[64];
>> @@ -230,22 +230,12 @@ static int asf_read_picture(AVFormatContext *s,
>> int len)
>>   return AVERROR(ENOMEM);
>>   len -= avio_get_str16le(s->pb, len - picsize, desc, desc_len);
>>   -    ret = av_get_packet(s->pb, &pkt, picsize);
>> +    ret = ff_add_attached_pic(s, NULL, s->pb, NULL, picsize);
>>   if (ret < 0)
>>   goto fail;
>> +    st = s->streams[s->nb_streams - 1];
>>   -    st  = avformat_new_stream(s, NULL);
>> -    if (!st) {
>> -    ret = AVERROR(ENOMEM);
>> -    goto fail;
>> -    }
>> -
>> -    st->disposition  |= AV_DISPOSITION_ATTACHED_PIC;
>> -    st->codecpar->codec_type  = AVMEDIA_TYPE_VIDEO;
>>   st->codecpar->codec_id    = id;
>> -    st->attached_pic  = pkt;
>> -    st->attached_pic.stream_index = st->index;
>> -    st->attached_pic.flags   |= AV_PKT_FLAG_KEY;
>>     if (*desc) {
>>   if (av_dict_set(&st->metadata, "title", desc,
>> AV_DICT_DONT_STRDUP_VAL) < 0)
>> @@ -260,7 +250,6 @@ static int asf_read_picture(AVFormatContext *s,
>> int len)
>>     fail:
>>   av_freep(&desc);
>> -    av_packet_unref(&pkt);
>>   return ret;
>>   }
> 
> This patch could be squashed into 1/4. Just apply 2/4 first.
> 
> Should be ok either way.

The reason for the current ordering is the question about what happens
in case of errors: The asf code currently creates the stream only if
av_get_packet() succeeds; other code does not, which I don't like.
I could squash this into 1/4, but given that I wanted to make separate
patches for adding and using the new function and for changing the
behaviour on error, this would mean that the behaviour on error for asf
would change for one commit before being reverted to the old behaviour.

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

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

Re: [FFmpeg-devel] [PATCH 1/4] avformat: Add and use helper function to add attachment streams

2021-03-30 Thread Andreas Rheinhardt
James Almer:
> On 3/29/2021 5:42 AM, Andreas Rheinhardt wrote:
>> All instances of adding attached pictures to a stream or adding
>> a stream and an attached packet to said stream have several things
>> in common like setting the index and flags of the packet, setting
>> the stream disposition etc. This commit therefore factors this out.
>>
>> Signed-off-by: Andreas Rheinhardt 
>> ---
>> I always pondered factoring this out; James' proposal made me do it.
>>
>>   libavformat/apetag.c   | 10 +-
>>   libavformat/flac_picture.c | 17 -
>>   libavformat/id3v2.c    | 21 ++---
>>   libavformat/internal.h | 13 +
>>   libavformat/matroskadec.c  | 15 +++
>>   libavformat/mov.c  | 25 +++--
>>   libavformat/utils.c    | 30 ++
>>   libavformat/wtvdec.c   | 12 ++--
>>   8 files changed, 66 insertions(+), 77 deletions(-)
>>
>> diff --git a/libavformat/apetag.c b/libavformat/apetag.c
>> index 23ee6b516d..6f82fbe202 100644
>> --- a/libavformat/apetag.c
>> +++ b/libavformat/apetag.c
>> @@ -79,20 +79,12 @@ static int ape_tag_read_field(AVFormatContext *s)
>>   av_dict_set(&st->metadata, key, filename, 0);
>>     if ((id = ff_guess_image2_codec(filename)) !=
>> AV_CODEC_ID_NONE) {
>> -    int ret;
>> -
>> -    ret = av_get_packet(s->pb, &st->attached_pic, size);
>> +    int ret = ff_add_attached_pic(s, st, s->pb, NULL, size);
>>   if (ret < 0) {
>>   av_log(s, AV_LOG_ERROR, "Error reading cover art.\n");
>>   return ret;
>>   }
>> -
>> -    st->disposition  |= AV_DISPOSITION_ATTACHED_PIC;
>> -    st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
>>   st->codecpar->codec_id   = id;
>> -
>> -    st->attached_pic.stream_index = st->index;
>> -    st->attached_pic.flags   |= AV_PKT_FLAG_KEY;
>>   } else {
>>   if ((ret = ff_get_extradata(s, st->codecpar, s->pb,
>> size)) < 0)
>>   return ret;
>> diff --git a/libavformat/flac_picture.c b/libavformat/flac_picture.c
>> index f15cfa877a..96e14f76c9 100644
>> --- a/libavformat/flac_picture.c
>> +++ b/libavformat/flac_picture.c
>> @@ -160,20 +160,11 @@ int ff_flac_parse_picture(AVFormatContext *s,
>> uint8_t *buf, int buf_size, int tr
>>   if (AV_RB64(data->data) == PNGSIG)
>>   id = AV_CODEC_ID_PNG;
>>   -    st = avformat_new_stream(s, NULL);
>> -    if (!st) {
>> -    RETURN_ERROR(AVERROR(ENOMEM));
>> -    }
>> -
>> -    av_packet_unref(&st->attached_pic);
>> -    st->attached_pic.buf  = data;
>> -    st->attached_pic.data = data->data;
>> -    st->attached_pic.size = len;
>> -    st->attached_pic.stream_index = st->index;
>> -    st->attached_pic.flags   |= AV_PKT_FLAG_KEY;
>> +    ret = ff_add_attached_pic(s, NULL, NULL, &data, 0);
>> +    if (ret < 0)
>> +    RETURN_ERROR(ret);
>>   -    st->disposition  |= AV_DISPOSITION_ATTACHED_PIC;
>> -    st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
>> +    st = s->streams[s->nb_streams - 1];
>>   st->codecpar->codec_id   = id;
>>   st->codecpar->width  = width;
>>   st->codecpar->height = height;
>> diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
>> index f33b7ba93a..863709abbf 100644
>> --- a/libavformat/id3v2.c
>> +++ b/libavformat/id3v2.c
>> @@ -1142,34 +1142,25 @@ int ff_id3v2_parse_apic(AVFormatContext *s,
>> ID3v2ExtraMeta *extra_meta)
>>   for (cur = extra_meta; cur; cur = cur->next) {
>>   ID3v2ExtraMetaAPIC *apic;
>>   AVStream *st;
>> +    int ret;
>>     if (strcmp(cur->tag, "APIC"))
>>   continue;
>>   apic = &cur->data.apic;
>>   -    if (!(st = avformat_new_stream(s, NULL)))
>> -    return AVERROR(ENOMEM);
>> -
>> -    st->disposition  |= AV_DISPOSITION_ATTACHED_PIC;
>> -    st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
>> +    ret = ff_add_attached_pic(s, NULL, NULL, &apic->buf, 0);
>> +    if (ret < 0)
>> +    return ret;
>> +    st  = s->streams[s->nb_streams - 1];
>>   st->codecpar->codec_id   = apic->id;
>>   -    if (AV_RB64(apic->buf->data) == PNGSIG)
>> +    if (AV_RB64(st->attached_pic.data) == PNGSIG)
>>   st->codecpar->codec_id = AV_CODEC_ID_PNG;
>>     if (apic->description[0])
>>   av_dict_set(&st->metadata, "title", apic->description, 0);
>>     av_dict_set(&st->metadata, "comment", apic->type, 0);
>> -
>> -    av_packet_unref(&st->attached_pic);
>> -    st->attached_pic.buf  = apic->buf;
>> -    st->attached_pic.data = apic->buf->data;
>> -    st->attached_pic.size = apic->buf->size -
>> AV_INPUT_BUFFER_PADDING_SIZE;
>> -    st->attached_pic.stream_index = st->index;
>> -    st->attached_pic.flags   |= AV_PKT

Re: [FFmpeg-devel] [PATCH 1/4] avformat: Add and use helper function to add attachment streams

2021-03-30 Thread James Almer

On 3/30/2021 10:45 AM, Andreas Rheinhardt wrote:

James Almer:

On 3/29/2021 5:42 AM, Andreas Rheinhardt wrote:

All instances of adding attached pictures to a stream or adding
a stream and an attached packet to said stream have several things
in common like setting the index and flags of the packet, setting
the stream disposition etc. This commit therefore factors this out.

Signed-off-by: Andreas Rheinhardt 
---
I always pondered factoring this out; James' proposal made me do it.

   libavformat/apetag.c   | 10 +-
   libavformat/flac_picture.c | 17 -
   libavformat/id3v2.c    | 21 ++---
   libavformat/internal.h | 13 +
   libavformat/matroskadec.c  | 15 +++
   libavformat/mov.c  | 25 +++--
   libavformat/utils.c    | 30 ++
   libavformat/wtvdec.c   | 12 ++--
   8 files changed, 66 insertions(+), 77 deletions(-)

diff --git a/libavformat/apetag.c b/libavformat/apetag.c
index 23ee6b516d..6f82fbe202 100644
--- a/libavformat/apetag.c
+++ b/libavformat/apetag.c
@@ -79,20 +79,12 @@ static int ape_tag_read_field(AVFormatContext *s)
   av_dict_set(&st->metadata, key, filename, 0);
     if ((id = ff_guess_image2_codec(filename)) !=
AV_CODEC_ID_NONE) {
-    int ret;
-
-    ret = av_get_packet(s->pb, &st->attached_pic, size);
+    int ret = ff_add_attached_pic(s, st, s->pb, NULL, size);
   if (ret < 0) {
   av_log(s, AV_LOG_ERROR, "Error reading cover art.\n");
   return ret;
   }
-
-    st->disposition  |= AV_DISPOSITION_ATTACHED_PIC;
-    st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
   st->codecpar->codec_id   = id;
-
-    st->attached_pic.stream_index = st->index;
-    st->attached_pic.flags   |= AV_PKT_FLAG_KEY;
   } else {
   if ((ret = ff_get_extradata(s, st->codecpar, s->pb,
size)) < 0)
   return ret;
diff --git a/libavformat/flac_picture.c b/libavformat/flac_picture.c
index f15cfa877a..96e14f76c9 100644
--- a/libavformat/flac_picture.c
+++ b/libavformat/flac_picture.c
@@ -160,20 +160,11 @@ int ff_flac_parse_picture(AVFormatContext *s,
uint8_t *buf, int buf_size, int tr
   if (AV_RB64(data->data) == PNGSIG)
   id = AV_CODEC_ID_PNG;
   -    st = avformat_new_stream(s, NULL);
-    if (!st) {
-    RETURN_ERROR(AVERROR(ENOMEM));
-    }
-
-    av_packet_unref(&st->attached_pic);
-    st->attached_pic.buf  = data;
-    st->attached_pic.data = data->data;
-    st->attached_pic.size = len;
-    st->attached_pic.stream_index = st->index;
-    st->attached_pic.flags   |= AV_PKT_FLAG_KEY;
+    ret = ff_add_attached_pic(s, NULL, NULL, &data, 0);
+    if (ret < 0)
+    RETURN_ERROR(ret);
   -    st->disposition  |= AV_DISPOSITION_ATTACHED_PIC;
-    st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
+    st = s->streams[s->nb_streams - 1];
   st->codecpar->codec_id   = id;
   st->codecpar->width  = width;
   st->codecpar->height = height;
diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index f33b7ba93a..863709abbf 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -1142,34 +1142,25 @@ int ff_id3v2_parse_apic(AVFormatContext *s,
ID3v2ExtraMeta *extra_meta)
   for (cur = extra_meta; cur; cur = cur->next) {
   ID3v2ExtraMetaAPIC *apic;
   AVStream *st;
+    int ret;
     if (strcmp(cur->tag, "APIC"))
   continue;
   apic = &cur->data.apic;
   -    if (!(st = avformat_new_stream(s, NULL)))
-    return AVERROR(ENOMEM);
-
-    st->disposition  |= AV_DISPOSITION_ATTACHED_PIC;
-    st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
+    ret = ff_add_attached_pic(s, NULL, NULL, &apic->buf, 0);
+    if (ret < 0)
+    return ret;
+    st  = s->streams[s->nb_streams - 1];
   st->codecpar->codec_id   = apic->id;
   -    if (AV_RB64(apic->buf->data) == PNGSIG)
+    if (AV_RB64(st->attached_pic.data) == PNGSIG)
   st->codecpar->codec_id = AV_CODEC_ID_PNG;
     if (apic->description[0])
   av_dict_set(&st->metadata, "title", apic->description, 0);
     av_dict_set(&st->metadata, "comment", apic->type, 0);
-
-    av_packet_unref(&st->attached_pic);
-    st->attached_pic.buf  = apic->buf;
-    st->attached_pic.data = apic->buf->data;
-    st->attached_pic.size = apic->buf->size -
AV_INPUT_BUFFER_PADDING_SIZE;
-    st->attached_pic.stream_index = st->index;
-    st->attached_pic.flags   |= AV_PKT_FLAG_KEY;
-
-    apic->buf = NULL;
   }
     return 0;
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 8631694d00..b3c5d8a1d5 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -669,6 +669,19

Re: [FFmpeg-devel] [PATCH] avformat: add apic to AVStream

2021-03-30 Thread James Almer

On 3/29/2021 10:46 AM, James Almer wrote:

On 3/29/2021 10:20 AM, Nicolas George wrote:

James Almer (12021-03-29):
Can this be done? id3v2 attached pics for many formats are handled by 
the
generic demux code in avformat_open_input() and not by the actual 
demuxer.

And in demuxers like asf, it seems to be done in read_header().
Would seeking be able to fetch these pictures again? The comment in the
AV_DISPOSITION_ATTACHED_PIC doxy makes me think it's not possible.

Personally, even if possible i think triggering a seek just to fetch an
attachment is inefficient and disruptive to the user's demuxing/decoding
process, and a step backwards considering it used to always be 
available,
for both seekable and non-seekable input, the latter which will no 
longer be

able to access the picture past the original packet.


As I said, at worse it accesses a field just like now. So of course it
can be done.

The point is that having a function to get the packet rather than just a
pointer gives us more freedom to extend the API later.


Not against it in that case, even if it will probably never stop just 
being an abstraction layer to fetch an always available packet, but know 
that this will kill Andreas' idea of defining how the (until now) public 
packet can be used to simplify attached pics in muxing scenarios, or 
make it considerably more complex to the point it's no longer worth it.


Some people on IRC mentioned the possibility of adding a demuxer option 
to disable fetching/storing attached pictures. The streams would not be 
allocated at all in that case. Would that be ok?

___
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] avformat/rtpdec: Fix prft wallclock time.

2021-03-30 Thread Alok Priyadarshi
Ping. Could someone please review this patch. Thanks.

On Thu, Mar 25, 2021, 6:40 AM Alok Priyadarshi  wrote:

> In effect the patch does replace that one line. But it also adds the steps
> to illustrate how the wallclock is calculated. Adding all the calculations
> in a single line will make it too long and hard to read.
>
> Note that delta_timestamp can be negative. It typically happens after rtcp
> SR is received and last_rtcp_ntp_time/last_rtcp_timestamp are refreshed.
> The packet timestamp can be less than last_rtcp_timestamp for a brief
> period of time. So it is necessary to explicitly cast both - timestamp
> and last_rtcp_timestamp - to int64 before calculating delta. This was
> another bug in the old code in addition to missing timebase scaling.
>
> On Thu, Mar 25, 2021 at 2:23 AM Carl Eugen Hoyos 
> wrote:
>
>> Am Do., 25. März 2021 um 05:47 Uhr schrieb Alok Priyadarshi <
>> alo...@gmail.com>:
>> >
>> > Timestamp difference is available in media timebase (1/90K) where as
>> > rtcp time is in the default microseconds timebase. This patch fixes
>> > the calculated prft wallclock time by rescaling the timestamp delta
>> > to the microseconds timebase.
>> > ---
>> >  libavformat/rtpdec.c | 9 +++--
>> >  1 file changed, 7 insertions(+), 2 deletions(-)
>> >
>> > diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c
>> > index b935dba1b8..21c1d01785 100644
>> > --- a/libavformat/rtpdec.c
>> > +++ b/libavformat/rtpdec.c
>> > @@ -585,14 +585,19 @@ void ff_rtp_parse_set_crypto(RTPDemuxContext *s,
>> const char *suite,
>> >  }
>> >
>> >  static int rtp_set_prft(RTPDemuxContext *s, AVPacket *pkt, uint32_t
>> timestamp) {
>> > +int64_t rtcp_time, delta_timestamp, delta_time;
>> > +
>> >  AVProducerReferenceTime *prft =
>> >  (AVProducerReferenceTime *) av_packet_new_side_data(
>> >  pkt, AV_PKT_DATA_PRFT, sizeof(AVProducerReferenceTime));
>> >  if (!prft)
>> >  return AVERROR(ENOMEM);
>> >
>> > -prft->wallclock = ff_parse_ntp_time(s->last_rtcp_ntp_time) -
>> NTP_OFFSET_US +
>>
>> > -  timestamp - s->last_rtcp_timestamp;
>>
>> Wouldn't this patch get much more readable if you only replace this line?
>>
>> > +rtcp_time = ff_parse_ntp_time(s->last_rtcp_ntp_time) -
>> NTP_OFFSET_US;
>> > +delta_timestamp = (int64_t)timestamp -
>> (int64_t)s->last_rtcp_timestamp;
>> > +delta_time = av_rescale_q(delta_timestamp, s->st->time_base,
>> AV_TIME_BASE_Q);
>> > +
>> > +prft->wallclock = rtcp_time + delta_time;
>>
>> Carl Eugen
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-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] avformat/rtpdec: Fix prft wallclock time.

2021-03-30 Thread James Almer

On 3/25/2021 1:46 AM, Alok Priyadarshi wrote:

Timestamp difference is available in media timebase (1/90K) where as
rtcp time is in the default microseconds timebase. This patch fixes
the calculated prft wallclock time by rescaling the timestamp delta
to the microseconds timebase.
---
  libavformat/rtpdec.c | 9 +++--
  1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c
index b935dba1b8..21c1d01785 100644
--- a/libavformat/rtpdec.c
+++ b/libavformat/rtpdec.c
@@ -585,14 +585,19 @@ void ff_rtp_parse_set_crypto(RTPDemuxContext *s, const 
char *suite,
  }
  
  static int rtp_set_prft(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestamp) {

+int64_t rtcp_time, delta_timestamp, delta_time;
+
  AVProducerReferenceTime *prft =
  (AVProducerReferenceTime *) av_packet_new_side_data(
  pkt, AV_PKT_DATA_PRFT, sizeof(AVProducerReferenceTime));
  if (!prft)
  return AVERROR(ENOMEM);
  
-prft->wallclock = ff_parse_ntp_time(s->last_rtcp_ntp_time) - NTP_OFFSET_US +

-  timestamp - s->last_rtcp_timestamp;
+rtcp_time = ff_parse_ntp_time(s->last_rtcp_ntp_time) - NTP_OFFSET_US;
+delta_timestamp = (int64_t)timestamp - (int64_t)s->last_rtcp_timestamp;
+delta_time = av_rescale_q(delta_timestamp, s->st->time_base, 
AV_TIME_BASE_Q);
+
+prft->wallclock = rtcp_time + delta_time;
  prft->flags = 24;
  return 0;
  }


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

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

Re: [FFmpeg-devel] [PATCH 1/2] avcodec/tiff: Avoid forward declarations

2021-03-30 Thread Pavel Koshevoy
On Tue, Mar 30, 2021 at 2:11 AM Andreas Rheinhardt <
andreas.rheinha...@outlook.com> wrote:

> In this case it also fixes a potential for compilation failures:
> Not all compilers can handle the case in which a function with
> a forward declaration declared with an attribute to always inline it
> is called before the function body appears.
>
> Signed-off-by: Andreas Rheinhardt 
> ---
> This is of course designed as an alternative to Pavel's patch
> https://ffmpeg.org/pipermail/ffmpeg-devel/2021-March/278383.html
>
>  libavcodec/tiff.c | 392 +++---
>  1 file changed, 193 insertions(+), 199 deletions(-)
>
> diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
> index 0878098b90..1d72fdc720 100644
> --- a/libavcodec/tiff.c
> +++ b/libavcodec/tiff.c
> @@ -275,9 +275,99 @@ static int add_metadata(int count, int type,
>  };
>  }
>
> +/**
> + * Map stored raw sensor values into linear reference values (see: DNG
> Specification - Chapter 5)
> + */
> +static uint16_t av_always_inline dng_process_color16(uint16_t value,
> + const uint16_t *lut,
> + uint16_t black_level,
> + float scale_factor) {
> +float value_norm;
> +
> +// Lookup table lookup
> +if (lut)
> +value = lut[value];
> +
> +// Black level subtraction
> +value = av_clip_uint16_c((unsigned)value - black_level);
> +
> +// Color scaling
> +value_norm = (float)value * scale_factor;
> +
> +value = av_clip_uint16_c(value_norm * 65535);
> +
> +return value;
> +}
> +
> +static uint16_t av_always_inline dng_process_color8(uint16_t value,
> +const uint16_t *lut,
> +uint16_t black_level,
> +float scale_factor) {
> +return dng_process_color16(value, lut, black_level, scale_factor) >>
> 8;
> +}
> +
>  static void av_always_inline dng_blit(TiffContext *s, uint8_t *dst, int
> dst_stride,
>const uint8_t *src, int src_stride,
> int width, int height,
> -  int is_single_comp, int is_u16);
> +  int is_single_comp, int is_u16)
> +{
> +int line, col;
> +float scale_factor;
> +
> +scale_factor = 1.0f / (s->white_level - s->black_level);
> +
> +if (is_single_comp) {
> +if (!is_u16)
> +return; /* <= 8bpp unsupported */
> +
> +/* Image is double the width and half the height we need, each
> row comprises 2 rows of the output
> +   (split vertically in the middle). */
> +for (line = 0; line < height / 2; line++) {
> +uint16_t *dst_u16 = (uint16_t *)dst;
> +uint16_t *src_u16 = (uint16_t *)src;
> +
> +/* Blit first half of input row row to initial row of output
> */
> +for (col = 0; col < width; col++)
> +*dst_u16++ = dng_process_color16(*src_u16++, s->dng_lut,
> s->black_level, scale_factor);
> +
> +/* Advance the destination pointer by a row (source pointer
> remains in the same place) */
> +dst += dst_stride * sizeof(uint16_t);
> +dst_u16 = (uint16_t *)dst;
> +
> +/* Blit second half of input row row to next row of output */
> +for (col = 0; col < width; col++)
> +*dst_u16++ = dng_process_color16(*src_u16++, s->dng_lut,
> s->black_level, scale_factor);
> +
> +dst += dst_stride * sizeof(uint16_t);
> +src += src_stride * sizeof(uint16_t);
> +}
> +} else {
> +/* Input and output image are the same size and the MJpeg decoder
> has done per-component
> +   deinterleaving, so blitting here is straightforward. */
> +if (is_u16) {
> +for (line = 0; line < height; line++) {
> +uint16_t *dst_u16 = (uint16_t *)dst;
> +uint16_t *src_u16 = (uint16_t *)src;
> +
> +for (col = 0; col < width; col++)
> +*dst_u16++ = dng_process_color16(*src_u16++,
> s->dng_lut, s->black_level, scale_factor);
> +
> +dst += dst_stride * sizeof(uint16_t);
> +src += src_stride * sizeof(uint16_t);
> +}
> +} else {
> +for (line = 0; line < height; line++) {
> +uint8_t *dst_u8 = dst;
> +const uint8_t *src_u8 = src;
> +
> +for (col = 0; col < width; col++)
> +*dst_u8++ = dng_process_color8(*src_u8++, s->dng_lut,
> s->black_level, scale_factor);
> +
> +dst += dst_stride;
> +src += src_stride;
> +}
> +}
> +}
> +}
>
>  static void av_always_inline horizontal_fill(TiffContext *s,
> 

Re: [FFmpeg-devel] [PATCH] lavc/tiff: Fix build failure due to always_inline

2021-03-30 Thread Pavel Koshevoy
On Tue, Mar 30, 2021 at 2:26 AM Andreas Rheinhardt <
andreas.rheinha...@outlook.com> wrote:

> Pavel Koshevoy:
> > Fixes:
> > src/libavcodec/tiff.c: In function ‘tiff_unpack_strip’:
> > src/libavcodec/tiff.c:280: error: ‘always_inline’ function could not be
> inlined in call to ‘dng_blit’: the function body must appear before caller
> > src/libavcodec/tiff.c:720: error: called from here
> > ---
> >  libavcodec/tiff.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
> > index 0878098b90..4ef685b929 100644
> > --- a/libavcodec/tiff.c
> > +++ b/libavcodec/tiff.c
> > @@ -275,9 +275,9 @@ static int add_metadata(int count, int type,
> >  };
> >  }
> >
> > -static void av_always_inline dng_blit(TiffContext *s, uint8_t *dst, int
> dst_stride,
> > -  const uint8_t *src, int
> src_stride, int width, int height,
> > -  int is_single_comp, int is_u16);
> > +static void dng_blit(TiffContext *s, uint8_t *dst, int dst_stride,
> > + const uint8_t *src, int src_stride, int width, int
> height,
> > + int is_single_comp, int is_u16);
> >
> >  static void av_always_inline horizontal_fill(TiffContext *s,
> >   unsigned int bpp, uint8_t*
> dst,
> >
> There are no cyclic calls here, so one can just remove the forward
> declaration. I did this here:
> https://ffmpeg.org/pipermail/ffmpeg-devel/2021-March/278386.html Do you
> like it? And what compiler exhibits the problems you mention in the
> commit message?
>
>
I wasn't sure about declaring a function more than a couple lines long as
inline.

The compiler that issued the error was apples gcc 4.2.1 on OS X 10.6

Thank you,
Pavel.
___
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] fftools/ffprobe: Add missing dispositions

2021-03-30 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Signed-off-by: Andreas Rheinhardt 
> ---
>  fftools/ffprobe.c |  5 +
>  .../ref/fate/concat-demuxer-extended-lavf-mxf |  2 +-
>  .../fate/concat-demuxer-extended-lavf-mxf_d10 |  2 +-
>  .../ref/fate/concat-demuxer-simple1-lavf-mxf  |  4 ++--
>  .../fate/concat-demuxer-simple1-lavf-mxf_d10  |  4 ++--
>  tests/ref/fate/concat-demuxer-simple2-lavf-ts |  4 ++--
>  tests/ref/fate/ffprobe_compact|  6 +++---
>  tests/ref/fate/ffprobe_csv|  6 +++---
>  tests/ref/fate/ffprobe_default| 15 +
>  tests/ref/fate/ffprobe_flat   | 15 +
>  tests/ref/fate/ffprobe_ini| 15 +
>  tests/ref/fate/ffprobe_json   | 21 ---
>  tests/ref/fate/ffprobe_xml|  6 +++---
>  ...hapqa-extract-nosnappy-to-hapalphaonly-mov |  5 +
>  .../fate/hapqa-extract-nosnappy-to-hapq-mov   |  5 +
>  tests/ref/fate/matroska-mpegts-remux  | 10 +
>  tests/ref/fate/matroska-vp8-alpha-remux   |  5 +
>  tests/ref/fate/mov-zombie |  2 +-
>  tests/ref/fate/mxf-probe-applehdr10   | 15 +
>  tests/ref/fate/mxf-probe-d10  | 10 +
>  tests/ref/fate/mxf-probe-dnxhd| 20 ++
>  tests/ref/fate/mxf-probe-dv25 | 15 +
>  22 files changed, 171 insertions(+), 21 deletions(-)
> 
> diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
> index 11e3cbd6c2..38462e1ff3 100644
> --- a/fftools/ffprobe.c
> +++ b/fftools/ffprobe.c
> @@ -2770,6 +2770,11 @@ static int show_stream(WriterContext *w, 
> AVFormatContext *fmt_ctx, int stream_id
>  PRINT_DISPOSITION(CLEAN_EFFECTS,"clean_effects");
>  PRINT_DISPOSITION(ATTACHED_PIC, "attached_pic");
>  PRINT_DISPOSITION(TIMED_THUMBNAILS, "timed_thumbnails");
> +PRINT_DISPOSITION(CAPTIONS, "captions");
> +PRINT_DISPOSITION(DESCRIPTIONS, "descriptions");
> +PRINT_DISPOSITION(METADATA, "metadata");
> +PRINT_DISPOSITION(DEPENDENT,"dependent");
> +PRINT_DISPOSITION(STILL_IMAGE,  "still_image");
>  writer_print_section_footer(w);
>  }
>  
> diff --git a/tests/ref/fate/concat-demuxer-extended-lavf-mxf 
> b/tests/ref/fate/concat-demuxer-extended-lavf-mxf
> index 87883217ee..a34e5c41a1 100644
> --- a/tests/ref/fate/concat-demuxer-extended-lavf-mxf
> +++ b/tests/ref/fate/concat-demuxer-extended-lavf-mxf
> @@ -1 +1 @@
> -c70ba87645ddecc8554036eb83a90e59 
> *tests/data/fate/concat-demuxer-extended-lavf-mxf.ffprobe
> +a4f7db152b5797dcd93347071c739f35 
> *tests/data/fate/concat-demuxer-extended-lavf-mxf.ffprobe
> diff --git a/tests/ref/fate/concat-demuxer-extended-lavf-mxf_d10 
> b/tests/ref/fate/concat-demuxer-extended-lavf-mxf_d10
> index 2a55890125..a60f0167c0 100644
> --- a/tests/ref/fate/concat-demuxer-extended-lavf-mxf_d10
> +++ b/tests/ref/fate/concat-demuxer-extended-lavf-mxf_d10
> @@ -1 +1 @@
> -d17d5c3291b408d624205aca9e7ad6b4 
> *tests/data/fate/concat-demuxer-extended-lavf-mxf_d10.ffprobe
> +8798f6a26cac39bb0eb37420fc0e2a10 
> *tests/data/fate/concat-demuxer-extended-lavf-mxf_d10.ffprobe
> diff --git a/tests/ref/fate/concat-demuxer-simple1-lavf-mxf 
> b/tests/ref/fate/concat-demuxer-simple1-lavf-mxf
> index 3e3e3a522f..70c131531c 100644
> --- a/tests/ref/fate/concat-demuxer-simple1-lavf-mxf
> +++ b/tests/ref/fate/concat-demuxer-simple1-lavf-mxf
> @@ -120,5 +120,5 @@ 
> audio|1|65280|1.36|65280|1.36|1920|0.04|3840|207872|K_|1
>  Strings Metadata
>  video|0|37|1.48|34|1.36|1|0.04|24786|212480|K_|1
>  Strings Metadata
> -0|mpeg2video|4|video|[0][0][0][0]|0x|352|288|0|0|0|1|1:1|11:9|yuv420p|8|tv|unknown|unknown|unknown|left|progressive|1|N/A|25/1|25/1|1/25|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|51|0|0|0|0|0|0|0|0|0|0|0|0|0x060A2B340101010501010D001301
> -1|pcm_s16le|unknown|audio|[0][0][0][0]|0x|s16|48000|1|unknown|16|N/A|0/0|0/0|1/48000|0|0.00|N/A|N/A|768000|N/A|N/A|N/A|N/A|50|0|0|0|0|0|0|0|0|0|0|0|0|0x060A2B340101010501010D001301
> +0|mpeg2video|4|video|[0][0][0][0]|0x|352|288|0|0|0|1|1:1|11:9|yuv420p|8|tv|unknown|unknown|unknown|left|progressive|1|N/A|25/1|25/1|1/25|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|51|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0x060A2B340101010501010D001301
> +1|pcm_s16le|unknown|audio|[0][0][0][0]|0x|s16|48000|1|unknown|16|N/A|0/0|0/0|1/48000|0|0.00|N/A|N/A|768000|N/A|N/A|N/A|N/A|50|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0x060A2B340101010501010D001301
> diff --git a/tests/ref/fate/concat-demuxer-simple1-lavf-mxf_d10 
> b/tests/ref/fate/concat-demuxer-simple1-lavf-mxf_d10
> index f329bba67f..465bd36d01 100644
> --- a/tests/ref/fate/concat-demuxer-simple1-lavf-mxf_d10
> +

Re: [FFmpeg-devel] Question about FFmpeg's threading architecture

2021-03-30 Thread Alireza Heidar-Barghi
 

On Thursday, March 25, 2021, 09:43:05 AM EDT, Alireza Heidar-Barghi 
 wrote:  
 
  Hi everyone,
Kieran, thank you for your reply. 
I already had a look at that document.
I need something more detailed about FFmpeg's threading architecture such as: 
1. What threading model is used in FFmpeg (e.g., thread pool, pipeline, or 
peer)?2. Have someone explored the performance of the threading model?3. What 
are the threads and what task(s) are assigned to each thread?
I appreciate it if someone can help me in understanding the FFmpeg's threading 
architecture.
Regards,
Alireza
On Tuesday, March 23, 2021, 11:21:58 AM EDT, Kieran Kunhya  
wrote:  
 
 Hi,

On Tue, 23 Mar 2021 at 16:01, Alireza Heidar-Barghi <
arhdr-at-yahoo@ffmpeg.org> wrote:

>  Hello,
> I am wondering how I can obtain documentation on the detail of FFmpeg's
> threading architecture?
> Thank you in advance.
> Regards,
> Alireza
>

https://github.com/FFmpeg/FFmpeg/blob/master/doc/multithreading.txt

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

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

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

Re: [FFmpeg-devel] [PATCH 3/3] avcodec/cfhd: More strictly check tag order and multiplicity

2021-03-30 Thread Michael Niedermayer
On Sun, Dec 20, 2020 at 10:15:24PM +0100, Michael Niedermayer wrote:
> This is based on the encoder and a small number of CFHD sample files
> It should make the decoder more robust against crafted input.
> Due to the lack of a proper specification it is possible that this
> may be too strict and may need to be tuned as files not following this
> ordering are found.
> 
> Fixes: segfault
> Fixes: OOM
> Fixes: null pointer dereference
> Fixes: left shift of negative value -12
> Fixes: out of array write
> Fixes: 
> 25367/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-4865603750592512
> Fixes: 
> 25958/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-4851579923202048
> Fixes: 
> 25988/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-5643617157513216
> Fixes: 
> 25995/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-5177442380283904
> Fixes: 
> 25996/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-5663296026574848
> Fixes: 
> 26082/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-5126180416782336
> Fixes: 
> 27872/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-4916296355151872
> Fixes: 
> 28305/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-6041755829010432

The following issues have been found by the fuzzer in CFHD since this was posted
With this applied none is reproducable


29754/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-6333598414274560
==18805==ERROR: AddressSanitizer: SEGV on unknown address 0x (pc 
0x00d6875d bp 0x sp 0x7ffde47353d8 T0)
==18805==The signal is caused by a READ memory access.
==18805==Hint: address points to the zero page.
#0 0xd6875c in ff_cfhd_vert_filter_sse2 libavcodec/x86/cfhddsp.asm:383



30519/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-6298424511168512
libavcodec/cfhddsp.c:36:41: runtime error: load of null pointer of type 'const 
int16_t' (aka 'const short')
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior 
libavcodec/cfhddsp.c:36:41 in
AddressSanitizer:DEADLYSIGNAL
=
==18874==ERROR: AddressSanitizer: SEGV on unknown address 0x (pc 
0x005450d5 bp 0x7ffc0a6c6ee0 sp 0x7ffc0a6c6d60 T0)
==18874==The signal is caused by a READ memory access.
==18874==Hint: address points to the zero page.
#0 0x5450d4 in filter libavcodec/cfhddsp.c:36:41
#1 0x5450d4 in vert_filter libavcodec/cfhddsp.c:74
#2 0x528cea in cfhd_decode libavcodec/cfhd.c:1167:13
#3 0x57d746 in decode_simple_internal libavcodec/decode.c:327:15
#4 0x557ec7 in decode_simple_receive_frame libavcodec/decode.c:526:15
#5 0x557ec7 in decode_receive_frame_internal libavcodec/decode.c:546
#6 0x5574ea in avcodec_send_packet libavcodec/decode.c:608:15



30739/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-5011292836462592
==18879==ERROR: AddressSanitizer: heap-buffer-overflow on address 
0x7f2aa32a684e at pc 0x0053ee8f bp 0x7ffca5380fe0 sp 0x7ffca5380fd8
WRITE of size 2 at 0x7f2aa32a684e thread T0
#0 0x53ee8e in interlaced_vertical_filter libavcodec/cfhd.c:204:30
#1 0x52c088 in cfhd_decode libavcodec/cfhd.c:1273:21
#2 0x57d746 in decode_simple_internal libavcodec/decode.c:327:15
#3 0x557ec7 in decode_simple_receive_frame libavcodec/decode.c:526:15
#4 0x557ec7 in decode_receive_frame_internal libavcodec/decode.c:546
#5 0x5574ea in avcodec_send_packet libavcodec/decode.c:608:15



32124/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-5425980681355264
==18753==ERROR: AddressSanitizer: heap-buffer-overflow on address 
0x7f3a5006284e at pc 0x0054c97e bp 0x7ffc0327a620 sp 0x7ffc0327a618
WRITE of size 2 at 0x7f3a5006284e thread T0
#0 0x54c97d in filter libavcodec/cfhddsp.c:52:36
#1 0x54c97d in horiz_filter_clip libavcodec/cfhddsp.c:97
#2 0x52cbed in cfhd_decode libavcodec/cfhd.c:1239:21
#3 0x57d746 in decode_simple_internal libavcodec/decode.c:327:15
#4 0x557ec7 in decode_simple_receive_frame libavcodec/decode.c:526:15
#5 0x557ec7 in decode_receive_frame_internal libavcodec/decode.c:546
#6 0x5574ea in avcodec_send_packet libavcodec/decode.c:608:15


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

If you think the mosad wants you dead since a long time then you are either
wrong or dead since a long time.


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] mov: Skip computing SAR from invalid display matrix elements

2021-03-30 Thread Vittorio Giovara
Hello,
I was debugging an issue with a video file containing an invalid
display matrix, probably produced by a non conforming software.

The content of the matrix is:
:0   65536   0
0001:   -1   0   0
0002:0   0  1073741824

The -1 (stored as 4294967295) was probably a 1 shifted 32 times instead
of 16. The problem is that this value is bypassing the validation check
in the code below, and the resulting computed SAR value becomes 1:65536.

This change interprets extremely low entries as invalid and makes sure
to skip them in the SAR computation. This passes fate, but I haven't been
able to test this extensively.
Please see the attached patch, any feedback or better solution is welcome.
-- 
Vittorio


0001-mov-Skip-computing-SAR-from-invalid-display-matrix-e.patch
Description: Binary data
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH 5/6] pngdec: fix and simplify apng reference handling

2021-03-30 Thread James Almer

On 3/30/2021 5:56 AM, Michael Niedermayer wrote:

On Tue, Feb 16, 2021 at 09:24:15PM +0100, Anton Khirnov wrote:

Current code is very confused and confusing. It uses two different
reference frames - "previous" and "last" - when only one is really
necessary. It also confuses the two, leading to incorrect output with
APNG_DISPOSE_OP_PREVIOUS mode.

Fixes #9017.
---
  libavcodec/pngdec.c | 93 -
  1 file changed, 42 insertions(+), 51 deletions(-)



[...]


@@ -1088,23 +1084,23 @@ static int handle_p_frame_apng(AVCodecContext *avctx, 
PNGDecContext *s,
  if (!buffer)
  return AVERROR(ENOMEM);
  
+ff_thread_await_progress(&s->last_picture, INT_MAX, 0);
  
-// Do the disposal operation specified by the last frame on the frame

-if (s->last_dispose_op != APNG_DISPOSE_OP_PREVIOUS) {
-ff_thread_await_progress(&s->last_picture, INT_MAX, 0);
-memcpy(buffer, s->last_picture.f->data[0], s->image_linesize * 
s->height);
-
-if (s->last_dispose_op == APNG_DISPOSE_OP_BACKGROUND)
-for (y = s->last_y_offset; y < s->last_y_offset + s->last_h; ++y)
-memset(buffer + s->image_linesize * y + s->bpp * s->last_x_offset, 
0, s->bpp * s->last_w);
+// need to reset a rectangle to background:
+// create a new writable copy
+if (s->last_dispose_op == APNG_DISPOSE_OP_BACKGROUND) {
+int ret = av_frame_make_writable(s->last_picture.f);
+if (ret < 0)
+return ret;
  
-memcpy(s->previous_picture.f->data[0], buffer, s->image_linesize * s->height);

-ff_thread_report_progress(&s->previous_picture, INT_MAX, 0);
-} else {
-ff_thread_await_progress(&s->previous_picture, INT_MAX, 0);
-memcpy(buffer, s->previous_picture.f->data[0], s->image_linesize * 
s->height);
+for (y = s->last_y_offset; y < s->last_y_offset + s->last_h; y++) {
+memset(s->last_picture.f->data[0] + s->image_linesize * y +
+   s->bpp * s->last_x_offset, 0, s->bpp * s->last_w);
+}
  }
  
+memcpy(buffer, s->last_picture.f->data[0], s->image_linesize * s->height);

+


This results in out of array reads

av_frame_make_writable() decreases linesize [0] but the memcpy() now av_memdup()
assumes all frames have the same linesize


FATE didn't detect this? What sample triggers these out of array reads?

Also, instead of av_frame_make_writable(), this should probably call 
ff_thread_get_buffer() to get a new buffer, then copy the old data if 
needed. The difference in linesize is because 
avcodec_default_get_buffer2() allocates buffers in a different way than 
av_frame_get_buffer() as invoked by av_frame_make_writable().




Thanks

[...]


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

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



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

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

Re: [FFmpeg-devel] [PATCH 3/3] avcodec/cfhd: More strictly check tag order and multiplicity

2021-03-30 Thread Paul B Mahol
Please share files privately, do not apply non fix for this issue.

Give up with such this non-solution.

On Tue, Mar 30, 2021 at 6:49 PM Michael Niedermayer 
wrote:

> On Sun, Dec 20, 2020 at 10:15:24PM +0100, Michael Niedermayer wrote:
> > This is based on the encoder and a small number of CFHD sample files
> > It should make the decoder more robust against crafted input.
> > Due to the lack of a proper specification it is possible that this
> > may be too strict and may need to be tuned as files not following this
> > ordering are found.
> >
> > Fixes: segfault
> > Fixes: OOM
> > Fixes: null pointer dereference
> > Fixes: left shift of negative value -12
> > Fixes: out of array write
> > Fixes:
> 25367/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-4865603750592512
> > Fixes:
> 25958/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-4851579923202048
> > Fixes:
> 25988/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-5643617157513216
> > Fixes:
> 25995/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-5177442380283904
> > Fixes:
> 25996/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-5663296026574848
> > Fixes:
> 26082/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-5126180416782336
> > Fixes:
> 27872/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-4916296355151872
> > Fixes:
> 28305/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-6041755829010432
>
> The following issues have been found by the fuzzer in CFHD since this was
> posted
> With this applied none is reproducable
>
>
>
> 29754/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-6333598414274560
> ==18805==ERROR: AddressSanitizer: SEGV on unknown address 0x
> (pc 0x00d6875d bp 0x sp 0x7ffde47353d8 T0)
> ==18805==The signal is caused by a READ memory access.
> ==18805==Hint: address points to the zero page.
> #0 0xd6875c in ff_cfhd_vert_filter_sse2 libavcodec/x86/cfhddsp.asm:383
>
>
>
>
> 30519/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-6298424511168512
> libavcodec/cfhddsp.c:36:41: runtime error: load of null pointer of type
> 'const int16_t' (aka 'const short')
> SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
> libavcodec/cfhddsp.c:36:41 in
> AddressSanitizer:DEADLYSIGNAL
> =
> ==18874==ERROR: AddressSanitizer: SEGV on unknown address 0x
> (pc 0x005450d5 bp 0x7ffc0a6c6ee0 sp 0x7ffc0a6c6d60 T0)
> ==18874==The signal is caused by a READ memory access.
> ==18874==Hint: address points to the zero page.
> #0 0x5450d4 in filter libavcodec/cfhddsp.c:36:41
> #1 0x5450d4 in vert_filter libavcodec/cfhddsp.c:74
> #2 0x528cea in cfhd_decode libavcodec/cfhd.c:1167:13
> #3 0x57d746 in decode_simple_internal libavcodec/decode.c:327:15
> #4 0x557ec7 in decode_simple_receive_frame libavcodec/decode.c:526:15
> #5 0x557ec7 in decode_receive_frame_internal libavcodec/decode.c:546
> #6 0x5574ea in avcodec_send_packet libavcodec/decode.c:608:15
>
>
>
>
> 30739/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-5011292836462592
> ==18879==ERROR: AddressSanitizer: heap-buffer-overflow on address
> 0x7f2aa32a684e at pc 0x0053ee8f bp 0x7ffca5380fe0 sp 0x7ffca5380fd8
> WRITE of size 2 at 0x7f2aa32a684e thread T0
> #0 0x53ee8e in interlaced_vertical_filter libavcodec/cfhd.c:204:30
> #1 0x52c088 in cfhd_decode libavcodec/cfhd.c:1273:21
> #2 0x57d746 in decode_simple_internal libavcodec/decode.c:327:15
> #3 0x557ec7 in decode_simple_receive_frame libavcodec/decode.c:526:15
> #4 0x557ec7 in decode_receive_frame_internal libavcodec/decode.c:546
> #5 0x5574ea in avcodec_send_packet libavcodec/decode.c:608:15
>
>
>
>
> 32124/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-5425980681355264
> ==18753==ERROR: AddressSanitizer: heap-buffer-overflow on address
> 0x7f3a5006284e at pc 0x0054c97e bp 0x7ffc0327a620 sp 0x7ffc0327a618
> WRITE of size 2 at 0x7f3a5006284e thread T0
> #0 0x54c97d in filter libavcodec/cfhddsp.c:52:36
> #1 0x54c97d in horiz_filter_clip libavcodec/cfhddsp.c:97
> #2 0x52cbed in cfhd_decode libavcodec/cfhd.c:1239:21
> #3 0x57d746 in decode_simple_internal libavcodec/decode.c:327:15
> #4 0x557ec7 in decode_simple_receive_frame libavcodec/decode.c:526:15
> #5 0x557ec7 in decode_receive_frame_internal libavcodec/decode.c:546
> #6 0x5574ea in avcodec_send_packet libavcodec/decode.c:608:15
>
>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> If you think the mosad wants you dead since a long time then you are either
> wrong or dead since a long time.
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel

Re: [FFmpeg-devel] [PATCH 1/2] fftools/ffprobe: Add missing dispositions

2021-03-30 Thread Marton Balint



On Tue, 30 Mar 2021, Andreas Rheinhardt wrote:


Andreas Rheinhardt:

Signed-off-by: Andreas Rheinhardt 
---



diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 11e3cbd6c2..38462e1ff3 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -2770,6 +2770,11 @@ static int show_stream(WriterContext *w, AVFormatContext 
*fmt_ctx, int stream_id
 PRINT_DISPOSITION(CLEAN_EFFECTS,"clean_effects");
 PRINT_DISPOSITION(ATTACHED_PIC, "attached_pic");
 PRINT_DISPOSITION(TIMED_THUMBNAILS, "timed_thumbnails");
+PRINT_DISPOSITION(CAPTIONS, "captions");
+PRINT_DISPOSITION(DESCRIPTIONS, "descriptions");
+PRINT_DISPOSITION(METADATA, "metadata");
+PRINT_DISPOSITION(DEPENDENT,"dependent");
+PRINT_DISPOSITION(STILL_IMAGE,  "still_image");
 writer_print_section_footer(w);
 }




Will apply this patchset tomorrow unless there are objections.


Please update doc/ffprobe.xsd accordingly!

I wonder if a fate test testing the XML output of ffprobe can be extended 
to do a validation of the XML via the XSD so this does not gets 
forgatten...


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

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

Re: [FFmpeg-devel] [PATCH] avcodec/dv_profile: PAL DV files with dsf flag 0 - detect via pal flag and buf_size

2021-03-30 Thread Marton Balint



On Tue, 30 Mar 2021, Mark Plomer wrote:


ping ;-)


Applied, thanks.

Marton



Am 18.03.21 um 21:55 schrieb Marton Balint:
It looks good to me, I will apply in a couple of days if nobody 
comments until then. Also Cc'd Dave, as he got probably the most 
experience with dv.


Regards,
Marton

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

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

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

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

Re: [FFmpeg-devel] [PATCH 5/6] pngdec: fix and simplify apng reference handling

2021-03-30 Thread Michael Niedermayer
On Tue, Mar 30, 2021 at 02:30:08PM -0300, James Almer wrote:
> On 3/30/2021 5:56 AM, Michael Niedermayer wrote:
> > On Tue, Feb 16, 2021 at 09:24:15PM +0100, Anton Khirnov wrote:
> > > Current code is very confused and confusing. It uses two different
> > > reference frames - "previous" and "last" - when only one is really
> > > necessary. It also confuses the two, leading to incorrect output with
> > > APNG_DISPOSE_OP_PREVIOUS mode.
> > > 
> > > Fixes #9017.
> > > ---
> > >   libavcodec/pngdec.c | 93 -
> > >   1 file changed, 42 insertions(+), 51 deletions(-)
> > 
> > 
> > [...]
> > 
> > > @@ -1088,23 +1084,23 @@ static int handle_p_frame_apng(AVCodecContext 
> > > *avctx, PNGDecContext *s,
> > >   if (!buffer)
> > >   return AVERROR(ENOMEM);
> > > +ff_thread_await_progress(&s->last_picture, INT_MAX, 0);
> > > -// Do the disposal operation specified by the last frame on the frame
> > > -if (s->last_dispose_op != APNG_DISPOSE_OP_PREVIOUS) {
> > > -ff_thread_await_progress(&s->last_picture, INT_MAX, 0);
> > > -memcpy(buffer, s->last_picture.f->data[0], s->image_linesize * 
> > > s->height);
> > > -
> > > -if (s->last_dispose_op == APNG_DISPOSE_OP_BACKGROUND)
> > > -for (y = s->last_y_offset; y < s->last_y_offset + s->last_h; 
> > > ++y)
> > > -memset(buffer + s->image_linesize * y + s->bpp * 
> > > s->last_x_offset, 0, s->bpp * s->last_w);
> > > +// need to reset a rectangle to background:
> > > +// create a new writable copy
> > > +if (s->last_dispose_op == APNG_DISPOSE_OP_BACKGROUND) {
> > > +int ret = av_frame_make_writable(s->last_picture.f);
> > > +if (ret < 0)
> > > +return ret;
> > > -memcpy(s->previous_picture.f->data[0], buffer, s->image_linesize 
> > > * s->height);
> > > -ff_thread_report_progress(&s->previous_picture, INT_MAX, 0);
> > > -} else {
> > > -ff_thread_await_progress(&s->previous_picture, INT_MAX, 0);
> > > -memcpy(buffer, s->previous_picture.f->data[0], s->image_linesize 
> > > * s->height);
> > > +for (y = s->last_y_offset; y < s->last_y_offset + s->last_h; 
> > > y++) {
> > > +memset(s->last_picture.f->data[0] + s->image_linesize * y +
> > > +   s->bpp * s->last_x_offset, 0, s->bpp * s->last_w);
> > > +}
> > >   }
> > > +memcpy(buffer, s->last_picture.f->data[0], s->image_linesize * 
> > > s->height);
> > > +
> > 
> > This results in out of array reads
> > 
> > av_frame_make_writable() decreases linesize [0] but the memcpy() now 
> > av_memdup()
> > assumes all frames have the same linesize
> 
> FATE didn't detect this? What sample triggers these out of array reads?

if iam reading my notes correctly
31405/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_APNG_fuzzer-6572805215879168
 did
if someone wants to work on this and wants it i can send it privatly

i dont know why fate didnt catch this ...


> 
> Also, instead of av_frame_make_writable(), this should probably call
> ff_thread_get_buffer() to get a new buffer, then copy the old data if
> needed. The difference in linesize is because avcodec_default_get_buffer2()
> allocates buffers in a different way than av_frame_get_buffer() as invoked
> by av_frame_make_writable().

yes

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

If the United States is serious about tackling the national security threats 
related to an insecure 5G network, it needs to rethink the extent to which it
values corporate profits and government espionage over security.-Bruce Schneier


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] avformat/rtpdec: Fix prft wallclock time.

2021-03-30 Thread Carl Eugen Hoyos
Am Di., 30. März 2021 um 17:02 Uhr schrieb James Almer :
>
> On 3/25/2021 1:46 AM, Alok Priyadarshi wrote:
> > Timestamp difference is available in media timebase (1/90K) where as
> > rtcp time is in the default microseconds timebase. This patch fixes
> > the calculated prft wallclock time by rescaling the timestamp delta
> > to the microseconds timebase.
> > ---
> >   libavformat/rtpdec.c | 9 +++--
> >   1 file changed, 7 insertions(+), 2 deletions(-)
> >
> > diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c
> > index b935dba1b8..21c1d01785 100644
> > --- a/libavformat/rtpdec.c
> > +++ b/libavformat/rtpdec.c
> > @@ -585,14 +585,19 @@ void ff_rtp_parse_set_crypto(RTPDemuxContext *s, 
> > const char *suite,
> >   }
> >
> >   static int rtp_set_prft(RTPDemuxContext *s, AVPacket *pkt, uint32_t 
> > timestamp) {
> > +int64_t rtcp_time, delta_timestamp, delta_time;
> > +
> >   AVProducerReferenceTime *prft =
> >   (AVProducerReferenceTime *) av_packet_new_side_data(
> >   pkt, AV_PKT_DATA_PRFT, sizeof(AVProducerReferenceTime));
> >   if (!prft)
> >   return AVERROR(ENOMEM);
> >
> > -prft->wallclock = ff_parse_ntp_time(s->last_rtcp_ntp_time) - 
> > NTP_OFFSET_US +
> > -  timestamp - s->last_rtcp_timestamp;
> > +rtcp_time = ff_parse_ntp_time(s->last_rtcp_ntp_time) - NTP_OFFSET_US;
> > +delta_timestamp = (int64_t)timestamp - (int64_t)s->last_rtcp_timestamp;
> > +delta_time = av_rescale_q(delta_timestamp, s->st->time_base, 
> > AV_TIME_BASE_Q);
> > +
> > +prft->wallclock = rtcp_time + delta_time;
> >   prft->flags = 24;
> >   return 0;
> >   }
>
> Applied, thanks.

I still believe that such patches should not get applied.

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

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

Re: [FFmpeg-devel] [PATCH] mov: Skip computing SAR from invalid display matrix elements

2021-03-30 Thread Carl Eugen Hoyos
Am Di., 30. März 2021 um 19:24 Uhr schrieb Vittorio Giovara
:
>
> Hello,
> I was debugging an issue with a video file containing an invalid
> display matrix, probably produced by a non conforming software.
>
> The content of the matrix is:
> :0   65536   0
> 0001:   -1   0   0
> 0002:0   0  1073741824
>
> The -1 (stored as 4294967295) was probably a 1 shifted 32 times instead
> of 16. The problem is that this value is bypassing the validation check
> in the code below, and the resulting computed SAR value becomes 1:65536.
>
> This change interprets extremely low entries as invalid and makes sure
> to skip them in the SAR computation. This passes fate, but I haven't been
> able to test this extensively.
> Please see the attached patch, any feedback or better solution is welcome.

Is this related to ticket #7277?

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

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

Re: [FFmpeg-devel] [PATCH v2] libsvtav1: Add logical_processors option

2021-03-30 Thread Jan Ekström
On Sat, Feb 20, 2021 at 3:20 AM Christopher Degawa  wrote:
>
> From: Christopher Degawa 
>
> Used for limiting the size of memory buffers and threads for a target
> logical processor count, but does not set thread affinity or limit the
> amount of threads used, although thread affinities can be controlled
> with an additional parameters, it is prefered to add them until
> a svtav1-params option or similar is added
>
> Signed-off-by: Christopher Degawa 
> ---
>  doc/encoders.texi  | 5 +
>  libavcodec/libsvtav1.c | 7 +++
>  2 files changed, 12 insertions(+)
>
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index 8fb573c416..28c1a11a6c 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -1757,6 +1757,11 @@ Set log2 of the number of rows of tiles to use (0-6).
>  @item tile_columns
>  Set log2 of the number of columns of tiles to use (0-4).
>
> +@item logical_processors
> +Number of logical processors to run the encoder on, threads are managed by 
> the OS scheduler.
> +Used for limiting the size of memory buffers and threads for a target 
> logical processor count.
> +Does not set thread affinity or limit threads.
> +

Hi, and sorry for getting to this patch so slowly. Thank you for your
discussion on IRC, I think that cleared up what this option does a
bit.

I think it might be more clear to call this just a "thread count
multiplier override to limit the amount of threads utilized" in the
docs and the help string, since that's what it essentially seems to
boil to. According to what I grasped from your explanation, the
encoder spawns XYZ threads per logical processor (core) by default,
and this is a way to limit that calculation to a specific number. As
SVT-AV1 does not have a separate switch to just plain set the amount
of threads in general, it is also the only way right now to limit the
thread count at the moment.

ref:
https://gitlab.com/AOMediaCodec/SVT-AV1/-/blob/05ed7cb78620c2ebbc948b20f26dd9a9c1756fa5/Source/Lib/Encoder/Globals/EbEncHandle.c#L254-257

>  @end table
>
>  @section libkvazaar
> diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c
> index eb6043bcac..2296735f25 100644
> --- a/libavcodec/libsvtav1.c
> +++ b/libavcodec/libsvtav1.c
> @@ -71,6 +71,8 @@ typedef struct SvtContext {
>
>  int tile_columns;
>  int tile_rows;
> +
> +unsigned logical_processors;
>  } SvtContext;
>
>  static const struct {
> @@ -218,6 +220,8 @@ static int config_enc_params(EbSvtAv1EncConfiguration 
> *param,
>  param->tile_columns = svt_enc->tile_columns;
>  param->tile_rows= svt_enc->tile_rows;
>
> +param->logical_processors = svt_enc->logical_processors;
> +

Do we already require a new enough SVT-AV1 to always have this option?
If yes, great. If not, it might be OK to just bump the requirement
then (to keep unnecessary ifdefs at bay for a relatively new and
actively developed library)?

>  return 0;
>  }
>
> @@ -533,6 +537,9 @@ static const AVOption options[] = {
>  { "tile_columns", "Log2 of number of tile columns to use", 
> OFFSET(tile_columns), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 4, VE},
>  { "tile_rows", "Log2 of number of tile rows to use", OFFSET(tile_rows), 
> AV_OPT_TYPE_INT, {.i64 = 0}, 0, 6, VE},
>
> +{ "logical_processors", "Number of logical processors to run the encoder 
> on, threads are managed by the OS scheduler", OFFSET(logical_processors),
> +  AV_OPT_TYPE_INT, { .i64 = 0 }, 0,  INT_MAX, VE },
> +

I think this could just be made to mention that it's a thread count
multiplier override to limit the amount of threads utilized.

There is an int/unsigned mismatch, but I think that should be OK since
you limit the value to 0-INT_MAX in the AVOption itself?

Otherwise LGTM, and once again sorry for taking the time to get to this.

Jan
___
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] libsvtav1: Add logical_processors option

2021-03-30 Thread Christopher Degawa
On Tue, Mar 30, 2021 at 4:53 PM Jan Ekström  wrote:

> > @@ -218,6 +220,8 @@ static int
> config_enc_params(EbSvtAv1EncConfiguration *param,
> >  param->tile_columns = svt_enc->tile_columns;
> >  param->tile_rows= svt_enc->tile_rows;
> >
> > +param->logical_processors = svt_enc->logical_processors;
> > +
>
> Do we already require a new enough SVT-AV1 to always have this option?
> If yes, great. If not, it might be OK to just bump the requirement
> then (to keep unnecessary ifdefs at bay for a relatively new and
> actively developed library)?
>

afaik, this option has existed before the ffmpeg wrapper was upstreamed, so
I do not think any ifdefs are needed

ref:
https://gitlab.com/AOMediaCodec/SVT-AV1/-/commit/a6c1f81989c6cab0f477adfa867d5ff3dad2725c


> > +{ "logical_processors", "Number of logical processors to run the
> encoder on, threads are managed by the OS scheduler",
> OFFSET(logical_processors),
> > +  AV_OPT_TYPE_INT, { .i64 = 0 }, 0,  INT_MAX, VE },
> > +
>
> I think this could just be made to mention that it's a thread count
> multiplier override to limit the amount of threads utilized.
>

after discussing this option on IRC, I think the wording of thread count
multiplier would probably fit better, something along the lines of

> { "logical_processors", "Thread count multiplier with a max of the number
of logical cores available",

I will resubmit an updated patch soon


> There is an int/unsigned mismatch, but I think that should be OK since
> you limit the value to 0-INT_MAX in the AVOption itself?
>

changed to

> AV_OPT_TYPE_INT, { .i64 = 0 }, 0,  UINT_MAX, VE },


>
> Otherwise LGTM, and once again sorry for taking the time to get to this.
>
Thank you
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

[FFmpeg-devel] [PATCH] avcodec/mjpegenc: Fix segfault when freeing incomplete context

2021-03-30 Thread Andreas Rheinhardt
When allocating the MJpegContext fails (or if the dimensions run afoul
of the 65500x65500 limit), an attempt to free a subbuffer of said
context leads to a segfault in ff_mjpeg_encode_close().
Seems to be a regression since 467d9e27e0cb2bf74f41dc832f2f8d191ba58ec9.

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

diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
index df3aaaf26b..596b7544ca 100644
--- a/libavcodec/mjpegenc.c
+++ b/libavcodec/mjpegenc.c
@@ -312,8 +312,10 @@ av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
 
 av_cold void ff_mjpeg_encode_close(MpegEncContext *s)
 {
-av_freep(&s->mjpeg_ctx->huff_buffer);
-av_freep(&s->mjpeg_ctx);
+if (s->mjpeg_ctx) {
+av_freep(&s->mjpeg_ctx->huff_buffer);
+av_freep(&s->mjpeg_ctx);
+}
 }
 
 /**
-- 
2.27.0

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

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

[FFmpeg-devel] [PATCH v2] libsvtav1: Add logical_processors option

2021-03-30 Thread Christopher Degawa
From: Christopher Degawa 

Used as a thread count multiplier with a max of the logical cores
available

Signed-off-by: Christopher Degawa 
---
 doc/encoders.texi  | 3 +++
 libavcodec/libsvtav1.c | 7 +++
 2 files changed, 10 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index c9c8785afb..89e5593772 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1795,6 +1795,9 @@ Set log2 of the number of rows of tiles to use (0-6).
 @item tile_columns
 Set log2 of the number of columns of tiles to use (0-4).

+@item logical_processors
+Thread count multiplier (0 - ncpus).
+
 @end table

 @section libkvazaar
diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c
index eb6043bcac..b6f9cc1c6b 100644
--- a/libavcodec/libsvtav1.c
+++ b/libavcodec/libsvtav1.c
@@ -71,6 +71,8 @@ typedef struct SvtContext {

 int tile_columns;
 int tile_rows;
+
+uint32_t logical_processors;
 } SvtContext;

 static const struct {
@@ -218,6 +220,8 @@ static int config_enc_params(EbSvtAv1EncConfiguration 
*param,
 param->tile_columns = svt_enc->tile_columns;
 param->tile_rows= svt_enc->tile_rows;

+param->logical_processors = svt_enc->logical_processors;
+
 return 0;
 }

@@ -533,6 +537,9 @@ static const AVOption options[] = {
 { "tile_columns", "Log2 of number of tile columns to use", 
OFFSET(tile_columns), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 4, VE},
 { "tile_rows", "Log2 of number of tile rows to use", OFFSET(tile_rows), 
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 6, VE},

+{ "logical_processors", "Thread count multiplier with a max of the number 
of logical cores available", OFFSET(logical_processors),
+  AV_OPT_TYPE_INT, { .i64 = 0 }, 0,  UINT_MAX, VE },
+
 {NULL},
 };

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

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

[FFmpeg-devel] [PATCH] avcodec/mjpegenc: Remove dependency of AMV encoder on mjpegenc_huffman

2021-03-30 Thread Andreas Rheinhardt
Using optimal Huffman tables is not supported for AMV and always
disabled by ff_mpv_encode_init(); therefore one the AMV encoder without
compiling mjpegenc_huffman if one adds the necessary compile-time
checks.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/Makefile   | 3 +--
 libavcodec/mjpegenc.c | 9 ++---
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 33a280cf69..4a597f727a 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -199,8 +199,7 @@ OBJS-$(CONFIG_AMRWB_DECODER)   += amrwbdec.o 
celp_filters.o   \
   celp_math.o acelp_filters.o \
   acelp_vectors.o \
   acelp_pitch_delay.o
-OBJS-$(CONFIG_AMV_ENCODER) += mjpegenc.o mjpegenc_common.o \
-  mjpegenc_huffman.o
+OBJS-$(CONFIG_AMV_ENCODER) += mjpegenc.o mjpegenc_common.o
 OBJS-$(CONFIG_ANM_DECODER) += anm.o
 OBJS-$(CONFIG_ANSI_DECODER)+= ansi.o cga_data.o
 OBJS-$(CONFIG_APE_DECODER) += apedec.o
diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
index 596b7544ca..e5d2e24d66 100644
--- a/libavcodec/mjpegenc.c
+++ b/libavcodec/mjpegenc.c
@@ -65,6 +65,7 @@ static av_cold void init_uni_ac_vlc(const uint8_t 
huff_size_ac[256],
 }
 }
 
+#if CONFIG_MJPEG_ENCODER
 /**
  * Encodes and outputs the entire frame in the JPEG format.
  *
@@ -171,6 +172,7 @@ static void mjpeg_build_optimal_huffman(MJpegContext *m)
  m->bits_ac_chrominance,
  m->val_ac_chrominance);
 }
+#endif
 
 /**
  * Writes the complete JPEG frame when optimal huffman tables are enabled,
@@ -186,11 +188,11 @@ int ff_mjpeg_encode_stuffing(MpegEncContext *s)
 PutBitContext *pbc = &s->pb;
 int mb_y = s->mb_y - !s->mb_x;
 int ret;
-MJpegContext *m;
-
-m = s->mjpeg_ctx;
 
+#if CONFIG_MJPEG_ENCODER
 if (s->huffman == HUFFMAN_TABLE_OPTIMAL) {
+MJpegContext *m = s->mjpeg_ctx;
+
 mjpeg_build_optimal_huffman(m);
 
 // Replace the VLCs with the optimal ones.
@@ -206,6 +208,7 @@ int ff_mjpeg_encode_stuffing(MpegEncContext *s)
s->pred, s->intra_matrix, 
s->chroma_intra_matrix);
 mjpeg_encode_picture_frame(s);
 }
+#endif
 
 ret = ff_mpv_reallocate_putbitbuffer(s, put_bits_count(&s->pb) / 8 + 100,
 put_bits_count(&s->pb) / 4 + 1000);
-- 
2.27.0

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

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

Re: [FFmpeg-devel] [PATCH 1/2] fftools/ffprobe: Add missing dispositions

2021-03-30 Thread Andreas Rheinhardt
Marton Balint:
> 
> 
> On Tue, 30 Mar 2021, Andreas Rheinhardt wrote:
> 
>> Andreas Rheinhardt:
>>> Signed-off-by: Andreas Rheinhardt 
>>> ---
> 
>>> diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
>>> index 11e3cbd6c2..38462e1ff3 100644
>>> --- a/fftools/ffprobe.c
>>> +++ b/fftools/ffprobe.c
>>> @@ -2770,6 +2770,11 @@ static int show_stream(WriterContext *w,
>>> AVFormatContext *fmt_ctx, int stream_id
>>>  PRINT_DISPOSITION(CLEAN_EFFECTS,    "clean_effects");
>>>  PRINT_DISPOSITION(ATTACHED_PIC, "attached_pic");
>>>  PRINT_DISPOSITION(TIMED_THUMBNAILS, "timed_thumbnails");
>>> +    PRINT_DISPOSITION(CAPTIONS, "captions");
>>> +    PRINT_DISPOSITION(DESCRIPTIONS, "descriptions");
>>> +    PRINT_DISPOSITION(METADATA, "metadata");
>>> +    PRINT_DISPOSITION(DEPENDENT,    "dependent");
>>> +    PRINT_DISPOSITION(STILL_IMAGE,  "still_image");
>>>  writer_print_section_footer(w);
>>>  }
>>>
> 
>> Will apply this patchset tomorrow unless there are objections.
> 
> Please update doc/ffprobe.xsd accordingly!
> 

Updated it locally, thanks for the info. (I actually didn't even know
about said file.)

> I wonder if a fate test testing the XML output of ffprobe can be
> extended to do a validation of the XML via the XSD so this does not gets
> forgatten...
> 
> Thanks,
> Marton
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

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

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

Re: [FFmpeg-devel] [PATCH 1/2] avutil/common: Add FF_PTR_ADD()

2021-03-30 Thread Michael Niedermayer
On Mon, Mar 29, 2021 at 12:19:57PM +0200, Anton Khirnov wrote:
> Quoting Michael Niedermayer (2021-03-15 09:47:43)
> > Suggested-by: Andreas Rheinhardt
> > Signed-off-by: Michael Niedermayer 
> > ---
> >  libavutil/common.h | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/libavutil/common.h b/libavutil/common.h
> > index aee353d399..c2d47a45b4 100644
> > --- a/libavutil/common.h
> > +++ b/libavutil/common.h
> > @@ -108,6 +108,8 @@
> >  #define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0)
> >  #define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
> >  
> > +#define FF_PTR_ADD(ptr, off) ((off) ? (ptr) + (off) : (ptr))
> 
> IIUC Andreas suggested to either put an AV prefix on this or move it to
> an internal header. I agree with that and prefer the latter, this macro
> doesn't seem very useful for external callers.

ill move it to internal.h

I think though our headers are not optimally named and the terminology used is
a bit ambigous. for example what exactly is external ? outside the lib, all 
libs maintained
by us, outside the soname object, ...

whats the header that is internal to libavutil ?
libavutil/internal.h, nope

whats the header with API common to all our libs in libavutil ?
libavutil/common.h, nope though it contains a good part of that API

I know these still it feels wrong every time i see a
#include "libavutil/internal.h" outside libavutil

Probably its just me but even after years this naming system still feels odd to 
me

thx

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

Concerning the gods, I have no means of knowing whether they exist or not
or of what sort they may be, because of the obscurity of the subject, and
the brevity of human life -- Protagoras


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 v3] lavfi/qsvvpp: support async depth

2021-03-30 Thread Fei Wang
Async depth will allow qsv filter cache few frames, and avoid force
switch and end filter task frame by frame. This change will improve
performance for some multi-task case, for example 1:N transcode(
decode + vpp + encode) with all QSV plugins.

Performance data test on my Coffee Lake Desktop(i7-8700K) by using
the following 1:8 transcode test case improvement:
1. Fps improved from 55 to 130.
2. Render/Video usage improved from ~61%/~38% to ~100%/~70%.(Data get
from intel_gpu_top)

test CMD:
ffmpeg -v verbose -init_hw_device qsv=hw:/dev/dri/renderD128 -filter_hw_device  
   \
 hw -hwaccel qsv -hwaccel_output_format qsv -c:v h264_qsv -i 1920x1080.264  
   \
-vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30 -preset 7 -g 33 
-refs 2 -bf 3 -q 24 -f null - \
-vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30 -preset 7 -g 33 
-refs 2 -bf 3 -q 24 -f null - \
-vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30 -preset 7 -g 33 
-refs 2 -bf 3 -q 24 -f null - \
-vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30 -preset 7 -g 33 
-refs 2 -bf 3 -q 24 -f null - \
-vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30 -preset 7 -g 33 
-refs 2 -bf 3 -q 24 -f null - \
-vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30 -preset 7 -g 33 
-refs 2 -bf 3 -q 24 -f null - \
-vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30 -preset 7 -g 33 
-refs 2 -bf 3 -q 24 -f null -

Signed-off-by: Fei Wang 
---
Change:
1. Add test data in commit message.
2. Rmove some duplicate code.

 libavfilter/qsvvpp.c | 153 ++-
 libavfilter/qsvvpp.h |  39 +++-
 libavfilter/vf_deinterlace_qsv.c |  14 +--
 libavfilter/vf_vpp_qsv.c |  75 ---
 4 files changed, 191 insertions(+), 90 deletions(-)

diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index f216b3f248..4768f6208b 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -37,37 +37,6 @@
 #define IS_OPAQUE_MEMORY(mode) (mode & MFX_MEMTYPE_OPAQUE_FRAME)
 #define IS_SYSTEM_MEMORY(mode) (mode & MFX_MEMTYPE_SYSTEM_MEMORY)
 
-typedef struct QSVFrame {
-AVFrame  *frame;
-mfxFrameSurface1 *surface;
-mfxFrameSurface1  surface_internal;  /* for system memory */
-struct QSVFrame  *next;
-} QSVFrame;
-
-/* abstract struct for all QSV filters */
-struct QSVVPPContext {
-mfxSession  session;
-int (*filter_frame) (AVFilterLink *outlink, AVFrame *frame);/* callback */
-enum AVPixelFormat  out_sw_format;   /* Real output format */
-mfxVideoParam   vpp_param;
-mfxFrameInfo   *frame_infos; /* frame info for each input */
-
-/* members related to the input/output surface */
-int in_mem_mode;
-int out_mem_mode;
-QSVFrame   *in_frame_list;
-QSVFrame   *out_frame_list;
-int nb_surface_ptrs_in;
-int nb_surface_ptrs_out;
-mfxFrameSurface1  **surface_ptrs_in;
-mfxFrameSurface1  **surface_ptrs_out;
-
-/* MFXVPP extern parameters */
-mfxExtOpaqueSurfaceAlloc opaque_alloc;
-mfxExtBuffer  **ext_buffers;
-int nb_ext_buffers;
-};
-
 static const mfxHandleType handle_types[] = {
 MFX_HANDLE_VA_DISPLAY,
 MFX_HANDLE_D3D9_DEVICE_MANAGER,
@@ -336,9 +305,11 @@ static int fill_frameinfo_by_link(mfxFrameInfo *frameinfo, 
AVFilterLink *link)
 static void clear_unused_frames(QSVFrame *list)
 {
 while (list) {
-if (list->surface && !list->surface->Data.Locked) {
-list->surface = NULL;
+/* list->queued==1 means the frame is not cached in VPP
+ * process any more, it can be released to pool. */
+if ((list->queued == 1) && !list->surface.Data.Locked) {
 av_frame_free(&list->frame);
+list->queued = 0;
 }
 list = list->next;
 }
@@ -361,8 +332,10 @@ static QSVFrame *get_free_frame(QSVFrame **list)
 QSVFrame *out = *list;
 
 for (; out; out = out->next) {
-if (!out->surface)
+if (!out->queued) {
+out->queued = 1;
 break;
+}
 }
 
 if (!out) {
@@ -371,8 +344,9 @@ static QSVFrame *get_free_frame(QSVFrame **list)
 av_log(NULL, AV_LOG_ERROR, "Can't alloc new output frame.\n");
 return NULL;
 }
-out->next  = *list;
-*list  = out;
+out->queued = 1;
+out->next   = *list;
+*list   = out;
 }
 
 return out;
@@ -402,7 +376,7 @@ static QSVFrame *submit_frame(QSVVPPContext *s, 
AVFilterLink *inlink, AVFrame *p
 return NULL;
 }
 qsv_frame->frame   = av_frame_clone(picref);
-qsv_frame->surface = (mfxFrameSurface1 *)qsv_frame->frame->data[3];
+qsv_frame->surface = *(mfxFrameSurface1 *)qsv_frame->frame->data[3];
 } else {
 /* make a copy if the input is not p

Re: [FFmpeg-devel] [PATCH v3] lavfi/qsvvpp: support async depth

2021-03-30 Thread Wang, Fei W
On Wed, 2021-03-31 at 10:07 +0800, Fei Wang wrote:
> Async depth will allow qsv filter cache few frames, and avoid force
> switch and end filter task frame by frame. This change will improve
> performance for some multi-task case, for example 1:N transcode(
> decode + vpp + encode) with all QSV plugins.
> 
> Performance data test on my Coffee Lake Desktop(i7-8700K) by using
> the following 1:8 transcode test case improvement:
> 1. Fps improved from 55 to 130.
> 2. Render/Video usage improved from ~61%/~38% to ~100%/~70%.(Data get
> from intel_gpu_top)
> 
> test CMD:
> ffmpeg -v verbose -init_hw_device qsv=hw:/dev/dri/renderD128
> -filter_hw_device \
>  hw -hwaccel qsv -hwaccel_output_format qsv -c:v h264_qsv -i
> 1920x1080.264 \
> -vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30
> -preset 7 -g 33 -refs 2 -bf 3 -q 24 -f null - \
> -vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30
> -preset 7 -g 33 -refs 2 -bf 3 -q 24 -f null - \
> -vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30
> -preset 7 -g 33 -refs 2 -bf 3 -q 24 -f null - \
> -vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30
> -preset 7 -g 33 -refs 2 -bf 3 -q 24 -f null - \
> -vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30
> -preset 7 -g 33 -refs 2 -bf 3 -q 24 -f null - \
> -vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30
> -preset 7 -g 33 -refs 2 -bf 3 -q 24 -f null - \
> -vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30
> -preset 7 -g 33 -refs 2 -bf 3 -q 24 -f null -
> 
> Signed-off-by: Fei Wang 
> ---
> Change:
> 1. Add test data in commit message.
> 2. Rmove some duplicate code.

Hi Linjie,

Appreciate if you can help to review this new version. Thanks.

Fei

> 
>  libavfilter/qsvvpp.c | 153 ++---
> --
>  libavfilter/qsvvpp.h |  39 +++-
>  libavfilter/vf_deinterlace_qsv.c |  14 +--
>  libavfilter/vf_vpp_qsv.c |  75 ---
>  4 files changed, 191 insertions(+), 90 deletions(-)
> 
> diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
> index f216b3f248..4768f6208b 100644
> --- a/libavfilter/qsvvpp.c
> +++ b/libavfilter/qsvvpp.c
> @@ -37,37 +37,6 @@
>  #define IS_OPAQUE_MEMORY(mode) (mode & MFX_MEMTYPE_OPAQUE_FRAME)
>  #define IS_SYSTEM_MEMORY(mode) (mode & MFX_MEMTYPE_SYSTEM_MEMORY)
>  
> -typedef struct QSVFrame {
> -AVFrame  *frame;
> -mfxFrameSurface1 *surface;
> -mfxFrameSurface1  surface_internal;  /* for system memory */
> -struct QSVFrame  *next;
> -} QSVFrame;
> -
> -/* abstract struct for all QSV filters */
> -struct QSVVPPContext {
> -mfxSession  session;
> -int (*filter_frame) (AVFilterLink *outlink, AVFrame *frame);/*
> callback */
> -enum AVPixelFormat  out_sw_format;   /* Real output format */
> -mfxVideoParam   vpp_param;
> -mfxFrameInfo   *frame_infos; /* frame info for each
> input */
> -
> -/* members related to the input/output surface */
> -int in_mem_mode;
> -int out_mem_mode;
> -QSVFrame   *in_frame_list;
> -QSVFrame   *out_frame_list;
> -int nb_surface_ptrs_in;
> -int nb_surface_ptrs_out;
> -mfxFrameSurface1  **surface_ptrs_in;
> -mfxFrameSurface1  **surface_ptrs_out;
> -
> -/* MFXVPP extern parameters */
> -mfxExtOpaqueSurfaceAlloc opaque_alloc;
> -mfxExtBuffer  **ext_buffers;
> -int nb_ext_buffers;
> -};
> -
>  static const mfxHandleType handle_types[] = {
>  MFX_HANDLE_VA_DISPLAY,
>  MFX_HANDLE_D3D9_DEVICE_MANAGER,
> @@ -336,9 +305,11 @@ static int fill_frameinfo_by_link(mfxFrameInfo
> *frameinfo, AVFilterLink *link)
>  static void clear_unused_frames(QSVFrame *list)
>  {
>  while (list) {
> -if (list->surface && !list->surface->Data.Locked) {
> -list->surface = NULL;
> +/* list->queued==1 means the frame is not cached in VPP
> + * process any more, it can be released to pool. */
> +if ((list->queued == 1) && !list->surface.Data.Locked) {
>  av_frame_free(&list->frame);
> +list->queued = 0;
>  }
>  list = list->next;
>  }
> @@ -361,8 +332,10 @@ static QSVFrame *get_free_frame(QSVFrame **list)
>  QSVFrame *out = *list;
>  
>  for (; out; out = out->next) {
> -if (!out->surface)
> +if (!out->queued) {
> +out->queued = 1;
>  break;
> +}
>  }
>  
>  if (!out) {
> @@ -371,8 +344,9 @@ static QSVFrame *get_free_frame(QSVFrame **list)
>  av_log(NULL, AV_LOG_ERROR, "Can't alloc new output
> frame.\n");
>  return NULL;
>  }
> -out->next  = *list;
> -*list  = out;
> +out->queued = 1;
> +out->next   = *list;
> +*list   = out;
>  }
>  
>  return out;
> @@ -402,7 +376,7 @@ stati

Re: [FFmpeg-devel] [PATCH 1/2] tls_openssl: Improve quality of printed error messages, pass IO error codes through

2021-03-30 Thread Martin Storsjö

On Fri, 26 Mar 2021, Martin Storsjö wrote:


Print every error in the stack, if more than one, and don't print
bogus errors if there's none logged within OpenSSL.

Retain the underlying IO error code, print an error message out of
it, and pass the error code on to the caller.
---
libavformat/tls_openssl.c | 41 +++
1 file changed, 29 insertions(+), 12 deletions(-)


If there's no opinions on this, I'll go ahead and land this one (and the 
other corresponding patch for gnutls) soon.


// Martin
___
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".