[FFmpeg-cvslog] avformat/matroskadec: use refcounted buffers in EbmlBin

2018-04-06 Thread James Almer
ffmpeg | branch: master | James Almer  | Wed Apr  4 14:12:54 
2018 -0300| [a61886650b598c98b7f8b44b3c186e33873913cd] | committer: James Almer

avformat/matroskadec: use refcounted buffers in EbmlBin

Data in EbmlBin objects is never changed after being read from the
input file (save for two specific cases with encoded CodePrivate), so
using AVBufferRef we can prevent unnecessary copy of data by instead
creating new references to said constant data.

Signed-off-by: James Almer 

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

 libavformat/matroskadec.c | 44 +++-
 1 file changed, 31 insertions(+), 13 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 6156c2f9b4..029929a1cb 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -104,6 +104,7 @@ typedef struct EbmlList {
 
 typedef struct EbmlBin {
 int  size;
+AVBufferRef *buf;
 uint8_t *data;
 int64_t  pos;
 } EbmlBin;
@@ -962,14 +963,19 @@ static int ebml_read_ascii(AVIOContext *pb, int size, 
char **str)
  */
 static int ebml_read_binary(AVIOContext *pb, int length, EbmlBin *bin)
 {
-av_fast_padded_malloc(>data, >size, length);
-if (!bin->data)
-return AVERROR(ENOMEM);
+int ret;
 
+ret = av_buffer_realloc(>buf, length + AV_INPUT_BUFFER_PADDING_SIZE);
+if (ret < 0)
+return ret;
+memset(bin->buf->data + length, 0, AV_INPUT_BUFFER_PADDING_SIZE);
+
+bin->data = bin->buf->data;
 bin->size = length;
 bin->pos  = avio_tell(pb);
 if (avio_read(pb, bin->data, length) != length) {
-av_freep(>data);
+av_buffer_unref(>buf);
+bin->data = NULL;
 bin->size = 0;
 return AVERROR(EIO);
 }
@@ -1252,7 +1258,7 @@ static void ebml_free(EbmlSyntax *syntax, void *data)
 av_freep(data_off);
 break;
 case EBML_BIN:
-av_freep(&((EbmlBin *) data_off)->data);
+av_buffer_unref(&((EbmlBin *) data_off)->buf);
 break;
 case EBML_LEVEL1:
 case EBML_NEST:
@@ -2036,12 +2042,13 @@ static int get_qt_codec(MatroskaTrack *track, uint32_t 
*fourcc, enum AVCodecID *
  * by expanding/shifting the data by 4 bytes and storing the data
  * size at the start. */
 if (ff_codec_get_id(codec_tags, AV_RL32(track->codec_priv.data))) {
-uint8_t *p = av_realloc(track->codec_priv.data,
-track->codec_priv.size + 4);
-if (!p)
-return AVERROR(ENOMEM);
-memmove(p + 4, p, track->codec_priv.size);
-track->codec_priv.data = p;
+int ret = av_buffer_realloc(>codec_priv.buf,
+track->codec_priv.size + 4 + 
AV_INPUT_BUFFER_PADDING_SIZE);
+if (ret < 0)
+return ret;
+
+track->codec_priv.data = track->codec_priv.buf->data;
+memmove(track->codec_priv.data + 4, track->codec_priv.data, 
track->codec_priv.size);
 track->codec_priv.size += 4;
 AV_WB32(track->codec_priv.data, track->codec_priv.size);
 }
@@ -2162,8 +2169,19 @@ static int matroska_parse_tracks(AVFormatContext *s)
"Failed to decode codec private data\n");
 }
 
-if (codec_priv != track->codec_priv.data)
-av_free(codec_priv);
+if (codec_priv != track->codec_priv.data) {
+av_buffer_unref(>codec_priv.buf);
+if (track->codec_priv.data) {
+track->codec_priv.buf = 
av_buffer_create(track->codec_priv.data,
+ 
track->codec_priv.size + AV_INPUT_BUFFER_PADDING_SIZE,
+ NULL, NULL, 
0);
+if (!track->codec_priv.buf) {
+av_freep(>codec_priv.data);
+track->codec_priv.size = 0;
+return AVERROR(ENOMEM);
+}
+}
+}
 }
 }
 

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


[FFmpeg-cvslog] avformat/matroskadec: reference the existing data buffer when creating packets

2018-04-06 Thread James Almer
ffmpeg | branch: master | James Almer  | Wed Apr  4 18:12:53 
2018 -0300| [9703b7d05fc7ab0378808b8d372a9c4a96e97488] | committer: James Almer

avformat/matroskadec: reference the existing data buffer when creating packets

Newly allocated data buffers (wavpack, prores, compressed buffers)
are padded to meet the requirements of AVPacket.

About 10x speed up in matroska_parse_frame().

Reviewed-by: Michael Niedermayer 
Signed-off-by: James Almer 

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

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

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 30f0da5bee..1ded431b80 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -1367,7 +1367,7 @@ static int matroska_decode_buffer(uint8_t **buf, int 
*buf_size,
 return 0;
 
 pkt_size = isize + header_size;
-pkt_data = av_malloc(pkt_size);
+pkt_data = av_malloc(pkt_size + AV_INPUT_BUFFER_PADDING_SIZE);
 if (!pkt_data)
 return AVERROR(ENOMEM);
 
@@ -1379,7 +1379,8 @@ static int matroska_decode_buffer(uint8_t **buf, int 
*buf_size,
 case MATROSKA_TRACK_ENCODING_COMP_LZO:
 do {
 olen   = pkt_size *= 3;
-newpktdata = av_realloc(pkt_data, pkt_size + 
AV_LZO_OUTPUT_PADDING);
+newpktdata = av_realloc(pkt_data, pkt_size + AV_LZO_OUTPUT_PADDING
+   + 
AV_INPUT_BUFFER_PADDING_SIZE);
 if (!newpktdata) {
 result = AVERROR(ENOMEM);
 goto failed;
@@ -1404,7 +1405,7 @@ static int matroska_decode_buffer(uint8_t **buf, int 
*buf_size,
 zstream.avail_in = isize;
 do {
 pkt_size  *= 3;
-newpktdata = av_realloc(pkt_data, pkt_size);
+newpktdata = av_realloc(pkt_data, pkt_size + 
AV_INPUT_BUFFER_PADDING_SIZE);
 if (!newpktdata) {
 inflateEnd();
 result = AVERROR(ENOMEM);
@@ -1437,7 +1438,7 @@ static int matroska_decode_buffer(uint8_t **buf, int 
*buf_size,
 bzstream.avail_in = isize;
 do {
 pkt_size  *= 3;
-newpktdata = av_realloc(pkt_data, pkt_size);
+newpktdata = av_realloc(pkt_data, pkt_size + 
AV_INPUT_BUFFER_PADDING_SIZE);
 if (!newpktdata) {
 BZ2_bzDecompressEnd();
 result = AVERROR(ENOMEM);
@@ -1464,6 +1465,8 @@ static int matroska_decode_buffer(uint8_t **buf, int 
*buf_size,
 return AVERROR_INVALIDDATA;
 }
 
+memset(pkt_data + pkt_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
+
 *buf  = pkt_data;
 *buf_size = pkt_size;
 return 0;
@@ -3001,7 +3004,7 @@ static int matroska_parse_wavpack(MatroskaTrack *track, 
uint8_t *src,
 goto fail;
 }
 
-tmp = av_realloc(dst, dstlen + blocksize + 32);
+tmp = av_realloc(dst, dstlen + blocksize + 32 + 
AV_INPUT_BUFFER_PADDING_SIZE);
 if (!tmp) {
 ret = AVERROR(ENOMEM);
 goto fail;
@@ -3025,6 +3028,8 @@ static int matroska_parse_wavpack(MatroskaTrack *track, 
uint8_t *src,
 offset += blocksize + 32;
 }
 
+memset(dst + dstlen, 0, AV_INPUT_BUFFER_PADDING_SIZE);
+
 *pdst = dst;
 *size = dstlen;
 
@@ -3042,13 +3047,14 @@ static int matroska_parse_prores(MatroskaTrack *track, 
uint8_t *src,
 int dstlen = *size;
 
 if (AV_RB32([4]) != MKBETAG('i', 'c', 'p', 'f')) {
-dst = av_malloc(dstlen + 8);
+dst = av_malloc(dstlen + 8 + AV_INPUT_BUFFER_PADDING_SIZE);
 if (!dst)
 return AVERROR(ENOMEM);
 
 AV_WB32(dst, dstlen);
 AV_WB32(dst + 4, MKBETAG('i', 'c', 'p', 'f'));
 memcpy(dst + 8, src, dstlen);
+memset(dst + 8 + dstlen, 0, AV_INPUT_BUFFER_PADDING_SIZE);
 dstlen += 8;
 }
 
@@ -3175,7 +3181,7 @@ static int matroska_parse_webvtt(MatroskaDemuxContext 
*matroska,
 
 static int matroska_parse_frame(MatroskaDemuxContext *matroska,
 MatroskaTrack *track, AVStream *st,
-uint8_t *data, int pkt_size,
+AVBufferRef *buf, uint8_t *data, int pkt_size,
 uint64_t timecode, uint64_t lace_duration,
 int64_t pos, int is_keyframe,
 uint8_t *additional, uint64_t additional_id, 
int additional_size,
@@ -3218,17 +3224,20 @@ static int matroska_parse_frame(MatroskaDemuxContext 
*matroska,
 pkt_data = pr_data;
 }
 
-/* XXX: prevent data copy... */
-if (av_new_packet(pkt, pkt_size) < 0) {
+av_init_packet(pkt);
+if (pkt_data != data)
+pkt->buf = av_buffer_create(pkt_data, pkt_size + 

[FFmpeg-cvslog] avformat/matroskadec: factor the prores packet parsing code out

2018-04-06 Thread James Almer
ffmpeg | branch: master | James Almer  | Wed Apr  4 16:07:36 
2018 -0300| [b8e75a2a08b678c7c6259a125acd8fa9565b5e42] | committer: James Almer

avformat/matroskadec: factor the prores packet parsing code out

Simplifies code in matroska_parse_frame(). This is in preparation for
the following patch.

Reviewed-by: Michael Niedermayer 
Signed-off-by: James Almer 

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

 libavformat/matroskadec.c | 50 +++
 1 file changed, 38 insertions(+), 12 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 029929a1cb..30f0da5bee 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -3035,6 +3035,29 @@ fail:
 return ret;
 }
 
+static int matroska_parse_prores(MatroskaTrack *track, uint8_t *src,
+ uint8_t **pdst, int *size)
+{
+uint8_t *dst = src;
+int dstlen = *size;
+
+if (AV_RB32([4]) != MKBETAG('i', 'c', 'p', 'f')) {
+dst = av_malloc(dstlen + 8);
+if (!dst)
+return AVERROR(ENOMEM);
+
+AV_WB32(dst, dstlen);
+AV_WB32(dst + 4, MKBETAG('i', 'c', 'p', 'f'));
+memcpy(dst + 8, src, dstlen);
+dstlen += 8;
+}
+
+*pdst = dst;
+*size = dstlen;
+
+return 0;
+}
+
 static int matroska_parse_webvtt(MatroskaDemuxContext *matroska,
  MatroskaTrack *track,
  AVStream *st,
@@ -3160,7 +3183,7 @@ static int matroska_parse_frame(MatroskaDemuxContext 
*matroska,
 {
 MatroskaTrackEncoding *encodings = track->encodings.elem;
 uint8_t *pkt_data = data;
-int offset = 0, res;
+int res;
 AVPacket pktl, *pkt = 
 
 if (encodings && !encodings->type && encodings->scope & 1) {
@@ -3182,23 +3205,26 @@ static int matroska_parse_frame(MatroskaDemuxContext 
*matroska,
 pkt_data = wv_data;
 }
 
-if (st->codecpar->codec_id == AV_CODEC_ID_PRORES &&
-AV_RB32([4]) != MKBETAG('i', 'c', 'p', 'f'))
-offset = 8;
+if (st->codecpar->codec_id == AV_CODEC_ID_PRORES) {
+uint8_t *pr_data;
+res = matroska_parse_prores(track, pkt_data, _data, _size);
+if (res < 0) {
+av_log(matroska->ctx, AV_LOG_ERROR,
+   "Error parsing a prores block.\n");
+goto fail;
+}
+if (pkt_data != data)
+av_freep(_data);
+pkt_data = pr_data;
+}
 
 /* XXX: prevent data copy... */
-if (av_new_packet(pkt, pkt_size + offset) < 0) {
+if (av_new_packet(pkt, pkt_size) < 0) {
 res = AVERROR(ENOMEM);
 goto fail;
 }
 
-if (st->codecpar->codec_id == AV_CODEC_ID_PRORES && offset == 8) {
-uint8_t *buf = pkt->data;
-bytestream_put_be32(, pkt_size);
-bytestream_put_be32(, MKBETAG('i', 'c', 'p', 'f'));
-}
-
-memcpy(pkt->data + offset, pkt_data, pkt_size);
+memcpy(pkt->data, pkt_data, pkt_size);
 
 if (pkt_data != data)
 av_freep(_data);

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


[FFmpeg-cvslog] swresample/swresample: Fix for seg fault in swr_convert_internal() -> sum2_float during dithering.

2018-04-06 Thread Hendrik Schreiber
ffmpeg | branch: master | Hendrik Schreiber  | Thu Apr  5 
13:58:37 2018 +0200| [647fd4b8292e3bfae30b1086aa842a5ee47ee868] | committer: 
Michael Niedermayer

swresample/swresample: Fix for seg fault in swr_convert_internal() -> 
sum2_float during dithering.

Removed +len1 in call to s->mix_2_1_f() as I found no logical explanation for 
it. After removal, problem was gone.

Signed-off-by: Hendrik Schreiber 
Signed-off-by: Michael Niedermayer 

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

 libswresample/swresample.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libswresample/swresample.c b/libswresample/swresample.c
index f076b6c8cf..5bd39caac4 100644
--- a/libswresample/swresample.c
+++ b/libswresample/swresample.c
@@ -678,7 +678,7 @@ static int swr_convert_internal(struct SwrContext *s, 
AudioData *out, int out_co
 s->mix_2_1_simd(conv_src->ch[ch], preout->ch[ch], 
s->dither.noise.ch[ch] + s->dither.noise.bps * s->dither.noise_pos, 
s->native_simd_one, 0, 0, len1);
 if(out_count != len1)
 for(ch=0; chch_count; ch++)
-s->mix_2_1_f(conv_src->ch[ch] + off, 
preout->ch[ch] + off, s->dither.noise.ch[ch] + s->dither.noise.bps * 
s->dither.noise_pos + off + len1, s->native_one, 0, 0, out_count - len1);
+s->mix_2_1_f(conv_src->ch[ch] + off, 
preout->ch[ch] + off, s->dither.noise.ch[ch] + s->dither.noise.bps * 
s->dither.noise_pos + off, s->native_one, 0, 0, out_count - len1);
 } else {
 for(ch=0; chch_count; ch++)
 s->mix_2_1_f(conv_src->ch[ch], preout->ch[ch], 
s->dither.noise.ch[ch] + s->dither.noise.bps * s->dither.noise_pos, 
s->native_one, 0, 0, out_count);

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


[FFmpeg-cvslog] doc/developer: remove merge request method of contributing

2018-04-06 Thread Lou Logan
ffmpeg | branch: master | Lou Logan  | Thu Apr  5 10:10:37 2018 
-0800| [2f1963eedc0c59413a03bffd45492741020a1666] | committer: Lou Logan

doc/developer: remove merge request method of contributing

This seems to confuse Github users into thinking that we may accept pull
requests. We do not accept pull requests.

Sending patches to the ffmpeg-devel mailing list is our preferred method
for users to contribute code.

Signed-off-by: Lou Logan 

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

 doc/developer.texi | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/doc/developer.texi b/doc/developer.texi
index 0fc9c3f21c..a0eeefe242 100644
--- a/doc/developer.texi
+++ b/doc/developer.texi
@@ -30,13 +30,11 @@ consult @url{https://ffmpeg.org/legal.html}.
 
 @chapter Contributing
 
-There are 3 ways by which code gets into FFmpeg.
+There are 2 ways by which code gets into FFmpeg:
 @itemize @bullet
-@item Submitting patches to the main developer mailing list.
+@item Submitting patches to the ffmpeg-devel mailing list.
   See @ref{Submitting patches} for details.
 @item Directly committing changes to the main tree.
-@item Committing changes to a git clone, for example on github.com or
-  gitorious.org. And asking us to merge these changes.
 @end itemize
 
 Whichever way, changes should be reviewed by the maintainer of the code

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