[FFmpeg-cvslog] lavf/qsv_scale: add scaling modes support

2019-06-24 Thread Zhong Li
ffmpeg | branch: master | Zhong Li  | Tue Jun 18 15:52:29 
2019 +0800| [dd662bbdd26e09957b3e67d3cde07b9468931e15] | committer: Zhong Li

lavf/qsv_scale: add scaling modes support

low_power mode will use a fixed HW engine (SFC), thus can offload EU usage.
high quality mode will take EU usage (AVS sampler).

Performance and EU usage (Render usage) comparsion on Intel(R) Xeon(R) CPU 
E3-1225 v5 @ 3.30GHz:

High quality mode : ffmpeg -hwaccel qsv -c:v h264_qsv -i 
bbb_sunflower_1080p_30fps_normal_2000frames.h264 \
-vf scale_qsv=w=1280:h=736:mode=hq -f null -
fps=389
RENDER usage: 28.10 (provided by MSDK metrics_monitor)

Low Power mode: ffmpeg -hwaccel qsv -c:v h264_qsv -i 
~/bbb_sunflower_1080p_30fps_normal_2000frames.h264 \
-vf scale_qsv=w=1280:h=736:mode=low_power -f null -
fps=343
RENDER usage: 0.00

Low power mode (SFC) may be disabled if not supported by
MSDK/Driver/HW, and replaced by AVS mode interanlly.

Signed-off-by: Zhong Li 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=dd662bbdd26e09957b3e67d3cde07b9468931e15
---

 libavfilter/vf_scale_qsv.c | 40 +++-
 1 file changed, 35 insertions(+), 5 deletions(-)

diff --git a/libavfilter/vf_scale_qsv.c b/libavfilter/vf_scale_qsv.c
index db7715fc1b..499534e30d 100644
--- a/libavfilter/vf_scale_qsv.c
+++ b/libavfilter/vf_scale_qsv.c
@@ -69,6 +69,8 @@ enum var_name {
 VARS_NB
 };
 
+#define QSV_HAVE_SCALING_CONFIG  QSV_VERSION_ATLEAST(1, 19)
+
 typedef struct QSVScaleContext {
 const AVClass *class;
 
@@ -88,7 +90,14 @@ typedef struct QSVScaleContext {
 int nb_surface_ptrs_out;
 
 mfxExtOpaqueSurfaceAlloc opaque_alloc;
-mfxExtBuffer*ext_buffers[1];
+
+#if QSV_HAVE_SCALING_CONFIG
+mfxExtVPPScaling scale_conf;
+#endif
+int  mode;
+
+mfxExtBuffer *ext_buffers[1 + QSV_HAVE_SCALING_CONFIG];
+int  num_ext_buf;
 
 int shift_width, shift_height;
 
@@ -285,6 +294,8 @@ static int init_out_session(AVFilterContext *ctx)
 mfxStatus err;
 int i;
 
+s->num_ext_buf = 0;
+
 /* extract the properties of the "master" session given to us */
 err = MFXQueryIMPL(device_hwctx->session, );
 if (err == MFX_ERR_NONE)
@@ -357,10 +368,7 @@ static int init_out_session(AVFilterContext *ctx)
 s->opaque_alloc.Header.BufferId = 
MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
 s->opaque_alloc.Header.BufferSz = sizeof(s->opaque_alloc);
 
-s->ext_buffers[0] = (mfxExtBuffer*)>opaque_alloc;
-
-par.ExtParam= s->ext_buffers;
-par.NumExtParam = FF_ARRAY_ELEMS(s->ext_buffers);
+s->ext_buffers[s->num_ext_buf++] = (mfxExtBuffer*)>opaque_alloc;
 
 par.IOPattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY | 
MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
 } else {
@@ -396,6 +404,18 @@ static int init_out_session(AVFilterContext *ctx)
 par.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY | 
MFX_IOPATTERN_OUT_VIDEO_MEMORY;
 }
 
+#if QSV_HAVE_SCALING_CONFIG
+memset(>scale_conf, 0, sizeof(mfxExtVPPScaling));
+s->scale_conf.Header.BufferId = MFX_EXTBUFF_VPP_SCALING;
+s->scale_conf.Header.BufferSz = sizeof(mfxExtVPPScaling);
+s->scale_conf.ScalingMode = s->mode;
+s->ext_buffers[s->num_ext_buf++]  = (mfxExtBuffer*)>scale_conf;
+av_log(ctx, AV_LOG_VERBOSE, "Scaling mode: %"PRIu16"\n", s->mode);
+#endif
+
+par.ExtParam= s->ext_buffers;
+par.NumExtParam = s->num_ext_buf;
+
 par.AsyncDepth = 1;// TODO async
 
 par.vpp.In  = in_frames_hwctx->surfaces[0].Info;
@@ -595,6 +615,16 @@ static const AVOption options[] = {
 { "h",  "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, 
{ .str = "ih"   }, .flags = FLAGS },
 { "format", "Output pixel format", OFFSET(format_str), AV_OPT_TYPE_STRING, 
{ .str = "same" }, .flags = FLAGS },
 
+#if QSV_HAVE_SCALING_CONFIG
+{ "mode",  "set scaling mode",OFFSET(mode),AV_OPT_TYPE_INT,
{ .i64 = MFX_SCALING_MODE_DEFAULT}, MFX_SCALING_MODE_DEFAULT, 
MFX_SCALING_MODE_QUALITY, FLAGS, "mode"},
+{ "low_power", "low power mode",0, AV_OPT_TYPE_CONST,  
{ .i64 = MFX_SCALING_MODE_LOWPOWER}, INT_MIN, INT_MAX, FLAGS, "mode"},
+{ "hq","high quality mode", 0, AV_OPT_TYPE_CONST,  
{ .i64 = MFX_SCALING_MODE_QUALITY},  INT_MIN, INT_MAX, FLAGS, "mode"},
+#else
+{ "mode",  "(not supported)", OFFSET(mode),AV_OPT_TYPE_INT,
{ .i64 = 0}, 0, INT_MAX, FLAGS, "mode"},
+{ "low_power", "",  0, AV_OPT_TYPE_CONST,  
{ .i64 = 1}, 0,   0, FLAGS, "mode"},
+{ "hq","",  0, AV_OPT_TYPE_CONST,  
{ .i64 = 2}, 0,   0, FLAGS, "mode"},
+#endif
+
 { NULL },
 };
 

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

To unsubscribe, 

[FFmpeg-cvslog] movsub_bsf: Fix mov2textsub regression

2019-06-24 Thread Andreas Rheinhardt
ffmpeg | branch: release/4.0 | Andreas Rheinhardt 
 | Sun Jun 23 06:46:12 2019 +0200| 
[5ace41951948c6507926f13a924ff557bf7c2093] | committer: James Almer

movsub_bsf: Fix mov2textsub regression

The mov flavour of timed text uses the first two bytes of the packet as
a length field. And up until 11bef2fe said length field has been read
correctly in the mov2textsub bsf. But since then the next two bytes are
read as if they were the length field. This is fixed in this commit.

Reviewed-by: Philip Langdale 
Signed-off-by: Andreas Rheinhardt 
Signed-off-by: James Almer 
(cherry picked from commit 800f618a340d122754e7bdb82c22463cb9bd17b0)

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5ace41951948c6507926f13a924ff557bf7c2093
---

 libavcodec/movsub_bsf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/movsub_bsf.c b/libavcodec/movsub_bsf.c
index 5878607061..cd48aa7bb8 100644
--- a/libavcodec/movsub_bsf.c
+++ b/libavcodec/movsub_bsf.c
@@ -75,8 +75,8 @@ static int mov2textsub(AVBSFContext *ctx, AVPacket *pkt)
return AVERROR_INVALIDDATA;
 }
 
-pkt->data += 2;
 pkt->size  = FFMIN(pkt->size - 2, AV_RB16(pkt->data));
+pkt->data += 2;
 
 return 0;
 }

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

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

[FFmpeg-cvslog] movsub_bsf: Fix mov2textsub regression

2019-06-24 Thread Andreas Rheinhardt
ffmpeg | branch: release/4.1 | Andreas Rheinhardt 
 | Sun Jun 23 06:46:12 2019 +0200| 
[b5229a0b3e422e0de5f0f3d06b354aa8abe901e3] | committer: James Almer

movsub_bsf: Fix mov2textsub regression

The mov flavour of timed text uses the first two bytes of the packet as
a length field. And up until 11bef2fe said length field has been read
correctly in the mov2textsub bsf. But since then the next two bytes are
read as if they were the length field. This is fixed in this commit.

Reviewed-by: Philip Langdale 
Signed-off-by: Andreas Rheinhardt 
Signed-off-by: James Almer 
(cherry picked from commit 800f618a340d122754e7bdb82c22463cb9bd17b0)

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b5229a0b3e422e0de5f0f3d06b354aa8abe901e3
---

 libavcodec/movsub_bsf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/movsub_bsf.c b/libavcodec/movsub_bsf.c
index 5878607061..cd48aa7bb8 100644
--- a/libavcodec/movsub_bsf.c
+++ b/libavcodec/movsub_bsf.c
@@ -75,8 +75,8 @@ static int mov2textsub(AVBSFContext *ctx, AVPacket *pkt)
return AVERROR_INVALIDDATA;
 }
 
-pkt->data += 2;
 pkt->size  = FFMIN(pkt->size - 2, AV_RB16(pkt->data));
+pkt->data += 2;
 
 return 0;
 }

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

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

[FFmpeg-cvslog] movsub_bsf: Fix mov2textsub regression

2019-06-24 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Sun Jun 23 06:46:12 2019 +0200| [800f618a340d122754e7bdb82c22463cb9bd17b0] | 
committer: James Almer

movsub_bsf: Fix mov2textsub regression

The mov flavour of timed text uses the first two bytes of the packet as
a length field. And up until 11bef2fe said length field has been read
correctly in the mov2textsub bsf. But since then the next two bytes are
read as if they were the length field. This is fixed in this commit.

Reviewed-by: Philip Langdale 
Signed-off-by: Andreas Rheinhardt 
Signed-off-by: James Almer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=800f618a340d122754e7bdb82c22463cb9bd17b0
---

 libavcodec/movsub_bsf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/movsub_bsf.c b/libavcodec/movsub_bsf.c
index 5878607061..cd48aa7bb8 100644
--- a/libavcodec/movsub_bsf.c
+++ b/libavcodec/movsub_bsf.c
@@ -75,8 +75,8 @@ static int mov2textsub(AVBSFContext *ctx, AVPacket *pkt)
return AVERROR_INVALIDDATA;
 }
 
-pkt->data += 2;
 pkt->size  = FFMIN(pkt->size - 2, AV_RB16(pkt->data));
+pkt->data += 2;
 
 return 0;
 }

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

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

[FFmpeg-cvslog] lavf/flvenc: add automatic bitstream filtering

2019-06-24 Thread Jun Zhao
ffmpeg | branch: master | Jun Zhao  | Sat Jun 22 
16:50:31 2019 +0800| [053d33b46b169f35e644ddbf2a2e482515d3a8fe] | committer: 
Jun Zhao

lavf/flvenc: add automatic bitstream filtering

add automatic bitstream filtering when mux AAC

Reported-by: Yabo Wei weiyabogeij...@gmail.com
Reviewed-by: Steven Liu
Signed-off-by: Jun Zhao 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=053d33b46b169f35e644ddbf2a2e482515d3a8fe
---

 libavformat/flvenc.c | 27 ---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index e4863f1fc7..fb1dede7ae 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -653,11 +653,9 @@ end:
 return ret;
 }
 
-
-static int flv_write_header(AVFormatContext *s)
+static int flv_init(struct AVFormatContext *s)
 {
 int i;
-AVIOContext *pb = s->pb;
 FLVContext *flv = s->priv_data;
 
 for (i = 0; i < s->nb_streams; i++) {
@@ -736,6 +734,15 @@ static int flv_write_header(AVFormatContext *s)
 
 flv->delay = AV_NOPTS_VALUE;
 
+return 0;
+}
+
+static int flv_write_header(AVFormatContext *s)
+{
+int i;
+AVIOContext *pb = s->pb;
+FLVContext *flv = s->priv_data;
+
 avio_write(pb, "FLV", 3);
 avio_w8(pb, 1);
 avio_w8(pb, FLV_HEADER_FLAG_HASAUDIO * !!flv->audio_par +
@@ -1074,6 +1081,18 @@ static int flv_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 return pb->error;
 }
 
+static int flv_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
+{
+int ret = 1;
+AVStream *st = s->streams[pkt->stream_index];
+
+if (st->codecpar->codec_id == AV_CODEC_ID_AAC) {
+if (pkt->size > 2 && (AV_RB16(pkt->data) & 0xfff0) == 0xfff0)
+ret = ff_stream_add_bitstream_filter(st, "aac_adtstoasc", NULL);
+}
+return ret;
+}
+
 static const AVOption options[] = {
 { "flvflags", "FLV muxer flags", offsetof(FLVContext, flags), 
AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, 
"flvflags" },
 { "aac_seq_header_detect", "Put AAC sequence header based on stream data", 
0, AV_OPT_TYPE_CONST, {.i64 = FLV_AAC_SEQ_HEADER_DETECT}, INT_MIN, INT_MAX, 
AV_OPT_FLAG_ENCODING_PARAM, "flvflags" },
@@ -1099,9 +1118,11 @@ AVOutputFormat ff_flv_muxer = {
 .priv_data_size = sizeof(FLVContext),
 .audio_codec= CONFIG_LIBMP3LAME ? AV_CODEC_ID_MP3 : 
AV_CODEC_ID_ADPCM_SWF,
 .video_codec= AV_CODEC_ID_FLV1,
+.init   = flv_init,
 .write_header   = flv_write_header,
 .write_packet   = flv_write_packet,
 .write_trailer  = flv_write_trailer,
+.check_bitstream= flv_check_bitstream,
 .codec_tag  = (const AVCodecTag* const []) {
   flv_video_codec_ids, flv_audio_codec_ids, 0
   },

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

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

[FFmpeg-cvslog] avformat/matroskadec: Properly check return values

2019-06-24 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Fri May 17 00:29:54 2019 +0200| [a27e5398e2d0e8af7eaa35001ea920d717fe9e38] | 
committer: James Almer

avformat/matroskadec: Properly check return values

Up until now, webm_dash_manifest_cues used the return values of
ebml_read_num and ebml_read_length without checking for errors,
i.e. return values < 0. This has been changed.

Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a27e5398e2d0e8af7eaa35001ea920d717fe9e38
---

 libavformat/matroskadec.c | 17 +++--
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 996bddf1c1..0e9938b65e 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -3864,12 +3864,17 @@ static int webm_dash_manifest_cues(AVFormatContext *s, 
int64_t init_range)
 cues_start = seekhead[i].pos + matroska->segment_start;
 if (avio_seek(matroska->ctx->pb, cues_start, SEEK_SET) == cues_start) {
 // cues_end is computed as cues_start + cues_length + length of the
-// Cues element ID + EBML length of the Cues element. cues_end is
-// inclusive and the above sum is reduced by 1.
-uint64_t cues_length = 0, cues_id = 0, bytes_read = 0;
-bytes_read += ebml_read_num(matroska, matroska->ctx->pb, 4, _id);
-bytes_read += ebml_read_length(matroska, matroska->ctx->pb, 
_length);
-cues_end = cues_start + cues_length + bytes_read - 1;
+// Cues element ID (i.e. 4) + EBML length of the Cues element.
+// cues_end is inclusive and the above sum is reduced by 1.
+uint64_t cues_length, cues_id;
+int bytes_read;
+bytes_read = ebml_read_num   (matroska, matroska->ctx->pb,  4, 
_id);
+if (bytes_read < 0 || cues_id != (MATROSKA_ID_CUES & 0xfff))
+return bytes_read < 0 ? bytes_read : AVERROR_INVALIDDATA;
+bytes_read = ebml_read_length(matroska, matroska->ctx->pb, 
_length);
+if (bytes_read < 0)
+return bytes_read;
+cues_end = cues_start + 4 + bytes_read + cues_length - 1;
 }
 avio_seek(matroska->ctx->pb, before_pos, SEEK_SET);
 if (cues_start == -1 || cues_end == -1) return -1;

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

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

[FFmpeg-cvslog] avformat/matroskadec: Improve error/EOF checks III

2019-06-24 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Mon Jun 24 01:42:31 2019 +0200| [ff5ea59f7b05cb4d37ba9e2c3ee383ff24a10ae0] | 
committer: James Almer

avformat/matroskadec: Improve error/EOF checks III

Up until now, when an element was skipped, it was relied upon
ffio_limit to make sure that there is enough data available to skip.
ffio_limit itself relies upon the availability of the file's size. As
this needn't be available, the check has been refined: First one byte
less than intended is skipped, then another byte is read, followed by a
check of the error flags.

Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ff5ea59f7b05cb4d37ba9e2c3ee383ff24a10ae0
---

 libavformat/matroskadec.c | 24 +---
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 5a9acd5ba7..bc73bfed11 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -1258,13 +1258,23 @@ static int ebml_parse_elem(MatroskaDemuxContext 
*matroska,
 case EBML_STOP:
 return 1;
 default:
-if (ffio_limit(pb, length) != length) {
-// ffio_limit emits its own error message,
-// so we don't have to.
-return AVERROR(EIO);
-}
-res = avio_skip(pb, length);
-res = res < 0 ? res : 0;
+if (length) {
+if (ffio_limit(pb, length) != length) {
+// ffio_limit emits its own error message,
+// so we don't have to.
+return AVERROR(EIO);
+}
+if ((res = avio_skip(pb, length - 1)) >= 0) {
+// avio_skip might take us past EOF. We check for this
+// by skipping only length - 1 bytes, reading a byte and
+// checking the error flags. This is done in order to check
+// that the element has been properly skipped even when
+// no filesize (that ffio_limit relies on) is available.
+avio_r8(pb);
+res = NEEDS_CHECKING;
+}
+} else
+res = 0;
 }
 if (res) {
 if (res == NEEDS_CHECKING) {

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

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

[FFmpeg-cvslog] avformat/matroskadec: Improve read error/EOF checks II

2019-06-24 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Mon Jun 24 01:42:30 2019 +0200| [a569a7b3bb017315b954ca686e1e8add05f07f09] | 
committer: James Almer

avformat/matroskadec: Improve read error/EOF checks II

This commit fixes a number of bugs:

1. There was no check that no read error/EOF occured during
ebml_read_uint, ebml_read_sint and ebml_read_float.
2. ebml_read_ascii and ebml_read_binary did sometimes not forward
error codes; instead they simply returned AVERROR(EIO).
3. In particular, AVERROR_EOF hasn't been used and no dedicated error
message for it existed. This has been changed.

In order to reduce code duplication, the new error code NEEDS_CHECKING
has been introduced which makes ebml_parse check the AVIOContext's
status for errors.

Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a569a7b3bb017315b954ca686e1e8add05f07f09
---

 libavformat/matroskadec.c | 59 ---
 1 file changed, 41 insertions(+), 18 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 59388efb64..5a9acd5ba7 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -69,6 +69,8 @@
 #include "qtpalette.h"
 
 #define EBML_UNKNOWN_LENGTH  UINT64_MAX /* EBML unknown length, in uint64_t */
+#define NEEDS_CHECKING2 /* Indicates that some error checks
+ * still need to be performed */
 
 typedef enum {
 EBML_NONE,
@@ -871,7 +873,7 @@ static int ebml_read_length(MatroskaDemuxContext *matroska, 
AVIOContext *pb,
 
 /*
  * Read the next element as an unsigned int.
- * 0 is success, < 0 is failure.
+ * Returns NEEDS_CHECKING.
  */
 static int ebml_read_uint(AVIOContext *pb, int size, uint64_t *num)
 {
@@ -882,12 +884,12 @@ static int ebml_read_uint(AVIOContext *pb, int size, 
uint64_t *num)
 while (n++ < size)
 *num = (*num << 8) | avio_r8(pb);
 
-return 0;
+return NEEDS_CHECKING;
 }
 
 /*
  * Read the next element as a signed int.
- * 0 is success, < 0 is failure.
+ * Returns NEEDS_CHECKING.
  */
 static int ebml_read_sint(AVIOContext *pb, int size, int64_t *num)
 {
@@ -903,12 +905,12 @@ static int ebml_read_sint(AVIOContext *pb, int size, 
int64_t *num)
 *num = ((uint64_t)*num << 8) | avio_r8(pb);
 }
 
-return 0;
+return NEEDS_CHECKING;
 }
 
 /*
  * Read the next element as a float.
- * 0 is success, < 0 is failure.
+ * Returns NEEDS_CHECKING or < 0 on obvious failure.
  */
 static int ebml_read_float(AVIOContext *pb, int size, double *num)
 {
@@ -921,24 +923,25 @@ static int ebml_read_float(AVIOContext *pb, int size, 
double *num)
 else
 return AVERROR_INVALIDDATA;
 
-return 0;
+return NEEDS_CHECKING;
 }
 
 /*
  * Read the next element as an ASCII string.
- * 0 is success, < 0 is failure.
+ * 0 is success, < 0 or NEEDS_CHECKING is failure.
  */
 static int ebml_read_ascii(AVIOContext *pb, int size, char **str)
 {
 char *res;
+int ret;
 
 /* EBML strings are usually not 0-terminated, so we allocate one
  * byte more, read the string and NULL-terminate it ourselves. */
 if (!(res = av_malloc(size + 1)))
 return AVERROR(ENOMEM);
-if (avio_read(pb, (uint8_t *) res, size) != size) {
+if ((ret = avio_read(pb, (uint8_t *) res, size)) != size) {
 av_free(res);
-return AVERROR(EIO);
+return ret < 0 ? ret : NEEDS_CHECKING;
 }
 (res)[size] = '\0';
 av_free(*str);
@@ -949,7 +952,7 @@ static int ebml_read_ascii(AVIOContext *pb, int size, char 
**str)
 
 /*
  * Read the next element as binary data.
- * 0 is success, < 0 is failure.
+ * 0 is success, < 0 or NEEDS_CHECKING is failure.
  */
 static int ebml_read_binary(AVIOContext *pb, int length, EbmlBin *bin)
 {
@@ -963,11 +966,11 @@ static int ebml_read_binary(AVIOContext *pb, int length, 
EbmlBin *bin)
 bin->data = bin->buf->data;
 bin->size = length;
 bin->pos  = avio_tell(pb);
-if (avio_read(pb, bin->data, length) != length) {
+if ((ret = avio_read(pb, bin->data, length)) != length) {
 av_buffer_unref(>buf);
 bin->data = NULL;
 bin->size = 0;
-return AVERROR(EIO);
+return ret < 0 ? ret : NEEDS_CHECKING;
 }
 
 return 0;
@@ -1255,14 +1258,34 @@ static int ebml_parse_elem(MatroskaDemuxContext 
*matroska,
 case EBML_STOP:
 return 1;
 default:
-if (ffio_limit(pb, length) != length)
+if (ffio_limit(pb, length) != length) {
+// ffio_limit emits its own error message,
+// so we don't have to.
 return AVERROR(EIO);
-return avio_skip(pb, length) < 0 ? AVERROR(EIO) : 0;
+}
+res = avio_skip(pb, length);
+res = res < 0 ? res : 0;
+}
+if (res) {
+if (res == NEEDS_CHECKING) {
+if (pb->eof_reached) {
+if (pb->error)
+res = pb->error;
+else
+ 

[FFmpeg-cvslog] avformat/matroskadec: Improve read error/EOF checks I

2019-06-24 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Tue Jun 25 03:08:56 2019 +0200| [239c7369e0490c6a130a1e4fd11c4fbf56379ce7] | 
committer: James Almer

avformat/matroskadec: Improve read error/EOF checks I

ebml_read_num had a number of flaws:

1. The check for read errors/EOF was totally wrong. E.g. an EBML number
beginning with the invalid 0x00 would be considered a read error,
although it is just invalid data.
2. The check for read errors/EOF was done just once, after reading the
first byte of the EBML number. But errors/EOF can happen inbetween, of
course, and this wasn't checked.
3. There was no way to distinguish when EOF should be an error (because
the data has to be there) for which an error message should be emitted
and when it is not necessarily an error (namely during parsing of EBML
IDs). Such a possibility has been added and used.

All this was fixed; furthermore, the error messages for invalid EBML
numbers were improved and useless initializations were removed.

Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=239c7369e0490c6a130a1e4fd11c4fbf56379ce7
---

 libavformat/matroskadec.c | 74 +--
 1 file changed, 46 insertions(+), 28 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 0e9938b65e..59388efb64 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -796,33 +796,32 @@ static int ebml_level_end(MatroskaDemuxContext *matroska)
  * Returns: number of bytes read, < 0 on error
  */
 static int ebml_read_num(MatroskaDemuxContext *matroska, AVIOContext *pb,
- int max_size, uint64_t *number)
+ int max_size, uint64_t *number, int eof_forbidden)
 {
-int read = 1, n = 1;
-uint64_t total = 0;
+int read, n = 1;
+uint64_t total;
+int64_t pos;
 
-/* The first byte tells us the length in bytes - avio_r8() can normally
- * return 0, but since that's not a valid first ebmlID byte, we can
- * use it safely here to catch EOS. */
-if (!(total = avio_r8(pb))) {
-/* we might encounter EOS here */
-if (!avio_feof(pb)) {
-int64_t pos = avio_tell(pb);
-av_log(matroska->ctx, AV_LOG_ERROR,
-   "Read error at pos. %"PRIu64" (0x%"PRIx64")\n",
-   pos, pos);
-return pb->error ? pb->error : AVERROR(EIO);
-}
-return AVERROR_EOF;
-}
+/* The first byte tells us the length in bytes - except when it is zero. */
+total = avio_r8(pb);
+if (pb->eof_reached)
+goto err;
 
 /* get the length of the EBML number */
 read = 8 - ff_log2_tab[total];
-if (read > max_size) {
-int64_t pos = avio_tell(pb) - 1;
-av_log(matroska->ctx, AV_LOG_ERROR,
-   "Invalid EBML number size tag 0x%02x at pos %"PRIu64" 
(0x%"PRIx64")\n",
-   (uint8_t) total, pos, pos);
+
+if (!total || read > max_size) {
+pos = avio_tell(pb) - 1;
+if (!total) {
+av_log(matroska->ctx, AV_LOG_ERROR,
+   "0x00 at pos %"PRId64" (0x%"PRIx64") invalid as first byte "
+   "of an EBML number\n", pos, pos);
+} else {
+av_log(matroska->ctx, AV_LOG_ERROR,
+   "Length %d indicated by an EBML number's first byte 0x%02x "
+   "at pos %"PRId64" (0x%"PRIx64") exceeds max length %d.\n",
+   read, (uint8_t) total, pos, pos, max_size);
+}
 return AVERROR_INVALIDDATA;
 }
 
@@ -831,9 +830,29 @@ static int ebml_read_num(MatroskaDemuxContext *matroska, 
AVIOContext *pb,
 while (n++ < read)
 total = (total << 8) | avio_r8(pb);
 
+if (pb->eof_reached) {
+eof_forbidden = 1;
+goto err;
+}
+
 *number = total;
 
 return read;
+
+err:
+pos = avio_tell(pb);
+if (pb->error) {
+av_log(matroska->ctx, AV_LOG_ERROR,
+   "Read error at pos. %"PRIu64" (0x%"PRIx64")\n",
+   pos, pos);
+return pb->error;
+}
+if (eof_forbidden) {
+av_log(matroska->ctx, AV_LOG_ERROR, "File ended prematurely "
+   "at pos. %"PRIu64" (0x%"PRIx64")\n", pos, pos);
+return AVERROR(EIO);
+}
+return AVERROR_EOF;
 }
 
 /**
@@ -844,7 +863,7 @@ static int ebml_read_num(MatroskaDemuxContext *matroska, 
AVIOContext *pb,
 static int ebml_read_length(MatroskaDemuxContext *matroska, AVIOContext *pb,
 uint64_t *number)
 {
-int res = ebml_read_num(matroska, pb, 8, number);
+int res = ebml_read_num(matroska, pb, 8, number, 1);
 if (res > 0 && *number + 1 == 1ULL << (7 * res))
 *number = EBML_UNKNOWN_LENGTH;
 return res;
@@ -986,7 +1005,7 @@ static int matroska_ebmlnum_uint(MatroskaDemuxContext 
*matroska,
 {
 AVIOContext pb;
 ffio_init_context(, data, size, 0, NULL, NULL, NULL, NULL);
-return 

[FFmpeg-cvslog] avformat/matroskadec: Don't zero unnecessarily

2019-06-24 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Fri May 17 00:29:48 2019 +0200| [1215b3a5f3f801f1f3179b9c29a0d52f906eef98] | 
committer: James Almer

avformat/matroskadec: Don't zero unnecessarily

It is only necessary to zero the initial allocated memory used to store
the size of laced frames if the block used Xiph lacing. Otherwise no
unintialized data was ever used, so use av_malloc instead of av_mallocz.

Also use the correct type for the allocations.

Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1215b3a5f3f801f1f3179b9c29a0d52f906eef98
---

 libavformat/matroskadec.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 09665fb680..996bddf1c1 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -2788,7 +2788,7 @@ static int matroska_parse_laces(MatroskaDemuxContext 
*matroska, uint8_t **buf,
 
 if (!type) {
 *laces= 1;
-*lace_buf = av_mallocz(sizeof(int));
+*lace_buf = av_malloc(sizeof(**lace_buf));
 if (!*lace_buf)
 return AVERROR(ENOMEM);
 
@@ -2800,7 +2800,7 @@ static int matroska_parse_laces(MatroskaDemuxContext 
*matroska, uint8_t **buf,
 *laces= *data + 1;
 data += 1;
 size -= 1;
-lace_size = av_mallocz(*laces * sizeof(int));
+lace_size = av_malloc_array(*laces, sizeof(*lace_size));
 if (!lace_size)
 return AVERROR(ENOMEM);
 
@@ -2810,6 +2810,8 @@ static int matroska_parse_laces(MatroskaDemuxContext 
*matroska, uint8_t **buf,
 uint8_t temp;
 uint32_t total = 0;
 for (n = 0; res == 0 && n < *laces - 1; n++) {
+lace_size[n] = 0;
+
 while (1) {
 if (size <= total) {
 res = AVERROR_INVALIDDATA;

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

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

[FFmpeg-cvslog] configure: print_in_columns: Replace pr with awk

2019-06-24 Thread Alexander Strasser
ffmpeg | branch: master | Alexander Strasser  | Sat Apr 27 
23:15:08 2019 +0200| [99147312ce6ffd3a3b70e10aacc9b64a63b6aefe] | committer: 
Alexander Strasser

configure: print_in_columns: Replace pr with awk

Get rid of pr dependency and write the columns strictly
alphabetical without page size considerations (POSIX
specifies 66 lines as default).

Setting the page size via pr's -l option was considered,
but as there is issue #5680 which wants to avoid pr
mainly because it's not in busybox, we chose to replace
pr instead.

Before pr would attempt to write pages, thus if a page
boundary was reached, the output looked confusing as one
couldn't see there was a new page and the alphabetical
order was disrupted when scanning down one of the columns.

This change is based on a shell implementation submitted
before by Yejun.

Possible differences to the current version using pr:
1. pr implementations should truncate items to not overflow columns;
   depending on how it's done not truncating shall be better IMHO.
2. pr implementations might balance columns differently;
   we use minimum number of lines and might end up not
   using all columns or might have lesser entries in the
   last column(s)
3. we use spaces only for padding the columns; at least the GNU pr
   version on my system also by default stuffs in tabs in addition
   to a single space in between columns. I don't see that this
   behaviour is demanded by POSIX, though I might be very well
   overlooking things. Anyway for our use case I can't see a need
   for having the additional tabs, or why it would be better compared
   to padding with spaces only.

Fixes output for sizes with width < column width, too.

Fixes remaining part of ticket #5680

Contributor: Guo, Yejun 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=99147312ce6ffd3a3b70e10aacc9b64a63b6aefe
---

 configure | 18 --
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index d885690369..7cea9d4d73 100755
--- a/configure
+++ b/configure
@@ -3843,8 +3843,22 @@ die_unknown(){
 }
 
 print_in_columns() {
-cols=$(expr $ncols / 24)
-cat | tr ' ' '\n' | sort | pr -r "-$cols" -w $ncols -t
+tr ' ' '\n' | sort | tr '\r\n' '  ' | awk -v col_width=24 -v 
width="$ncols" '
+{
+num_cols = width > col_width ? int(width / col_width) : 1;
+num_rows = int((NF + num_cols-1) / num_cols);
+y = x = 1;
+for (y = 1; y <= num_rows; y++) {
+i = y;
+for (x = 1; x <= num_cols; x++) {
+if (i <= NF) {
+  line = sprintf("%s%-" col_width "s", line, $i);
+}
+i = i + num_rows;
+}
+print line; line = "";
+}
+}' | sed 's/ *$//'
 }
 
 show_list() {

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

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

[FFmpeg-cvslog] avformat/hlsenc: better error log message for var_stream_map content

2019-06-24 Thread Bela Bodecs
ffmpeg | branch: master | Bela Bodecs  | Sat Jun 22 
15:55:54 2019 +0200| [2045dd0050f1ef0df348e11bd44657c2475aa7c3] | committer: 
Steven Liu

avformat/hlsenc: better error log message for var_stream_map content

When multiple variant streams are specified by var_stream_map option,
%v is expected either in the filename or in the last sub-directory name,
but only in one of them. When both of them contains %v string, current
error message only states half of the truth.
And even %v may appears several times inside the last sub-directory name
or in filename pattern.
This patch clarifies this in the log message and in the doc also.

Signed-off-by: Bela Bodecs 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2045dd0050f1ef0df348e11bd44657c2475aa7c3
---

 doc/muxers.texi  | 3 ++-
 libavformat/hlsenc.c | 8 
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index 4410a5f5bb..6c5b4bb637 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -656,7 +656,8 @@ This example will produce the playlists segment file sets:
 @file{file_1_000.ts}, @file{file_1_001.ts}, @file{file_1_002.ts}, etc.
 
 The string "%v" may be present in the filename or in the last directory name
-containing the file. If the string is present in the directory name, then
+containing the file, but only in one of them. (Additionally, %v may appear 
multiple times in the last
+sub-directory or filename.) If the string %v is present in the directory name, 
then
 sub-directories are created after expanding the directory name pattern. This
 enables creation of segments corresponding to different variant streams in
 subdirectories.
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index f6330ec2d5..9f5eee5491 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -1792,15 +1792,15 @@ static int validate_name(int nb_vs, const char *fn)
 subdir_name = av_dirname(fn_dup);
 
 if (nb_vs > 1 && !av_stristr(filename, "%v") && !av_stristr(subdir_name, 
"%v")) {
-av_log(NULL, AV_LOG_ERROR, "More than 1 variant streams are present, 
%%v is expected in the filename %s\n",
-fn);
+av_log(NULL, AV_LOG_ERROR, "More than 1 variant streams are present, 
%%v is expected "
+   "either in the filename or in the sub-directory name of file 
%s\n", fn);
 ret = AVERROR(EINVAL);
 goto fail;
 }
 
 if (av_stristr(filename, "%v") && av_stristr(subdir_name, "%v")) {
-av_log(NULL, AV_LOG_ERROR, "%%v is expected either in filename or in 
the sub-directory name of file %s\n",
-fn);
+av_log(NULL, AV_LOG_ERROR, "%%v is expected either in the filename or "
+   "in the sub-directory name of file %s, but only in one of 
them\n", fn);
 ret = AVERROR(EINVAL);
 goto fail;
 }

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

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