[FFmpeg-cvslog] avcodec/snowdec: Fix integer overflow in header parsing

2017-11-13 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Sun 
Nov  5 21:20:05 2017 +0100| [c897a9285846b6a072b9650976afd4f091b7a71f] | 
committer: Michael Niedermayer

avcodec/snowdec: Fix integer overflow in header parsing

Fixes: 3984/clusterfuzz-testcase-minimized-5265759929368576
Fixes: runtime error: signed integer overflow: -1085585801 + -1094995529 cannot 
be represented in type 'int'

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 

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

 libavcodec/snowdec.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavcodec/snowdec.c b/libavcodec/snowdec.c
index 13668c2105..727e908fb5 100644
--- a/libavcodec/snowdec.c
+++ b/libavcodec/snowdec.c
@@ -374,7 +374,7 @@ static int decode_header(SnowContext *s){
 }
 }
 
-s->spatial_decomposition_type+= get_symbol(&s->c, s->header_state, 1);
+s->spatial_decomposition_type+= (unsigned)get_symbol(&s->c, 
s->header_state, 1);
 if(s->spatial_decomposition_type > 1U){
 av_log(s->avctx, AV_LOG_ERROR, "spatial_decomposition_type %d not 
supported\n", s->spatial_decomposition_type);
 return AVERROR_INVALIDDATA;
@@ -390,10 +390,10 @@ static int decode_header(SnowContext *s){
 }
 
 
-s->qlog   += get_symbol(&s->c, s->header_state, 1);
-s->mv_scale   += get_symbol(&s->c, s->header_state, 1);
-s->qbias  += get_symbol(&s->c, s->header_state, 1);
-s->block_max_depth+= get_symbol(&s->c, s->header_state, 1);
+s->qlog   += (unsigned)get_symbol(&s->c, s->header_state, 1);
+s->mv_scale   += (unsigned)get_symbol(&s->c, s->header_state, 1);
+s->qbias  += (unsigned)get_symbol(&s->c, s->header_state, 1);
+s->block_max_depth+= (unsigned)get_symbol(&s->c, s->header_state, 1);
 if(s->block_max_depth > 1 || s->block_max_depth < 0 || s->mv_scale > 256U){
 av_log(s->avctx, AV_LOG_ERROR, "block_max_depth= %d is too large\n", 
s->block_max_depth);
 s->block_max_depth= 0;

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


[FFmpeg-cvslog] avcodec/mdct_*: Fix integer overflow in addition in RESCALE()

2017-11-13 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Sun 
Nov  5 21:20:06 2017 +0100| [770c934fa1635f4fadf5db4fc5cc5ad15d82455a] | 
committer: Michael Niedermayer

avcodec/mdct_*: Fix integer overflow in addition in RESCALE()

Fixes: runtime error: signed integer overflow: 1219998458 - -1469874012 cannot 
be represented in type 'int'
Fixes: 3443/clusterfuzz-testcase-minimized-5369987105554432

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 

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

 libavcodec/mdct_fixed.c|  8 
 libavcodec/mdct_template.c | 14 +++---
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/libavcodec/mdct_fixed.c b/libavcodec/mdct_fixed.c
index a32cb00ca0..aabf0c88f8 100644
--- a/libavcodec/mdct_fixed.c
+++ b/libavcodec/mdct_fixed.c
@@ -39,13 +39,13 @@ void ff_mdct_calcw_c(FFTContext *s, FFTDouble *out, const 
FFTSample *input)
 
 /* pre rotation */
 for(i=0;i> 6)
+#   define RSCALE(x, y) ((int)((x) + (unsigned)(y) + 32) >> 6)
 #else /* FFT_FIXED_32 */
-#   define RSCALE(x) ((x) >> 1)
+#   define RSCALE(x, y) ((int)((x) + (unsigned)(y)) >> 1)
 #endif /* FFT_FIXED_32 */
 #endif
 
@@ -181,13 +181,13 @@ void ff_mdct_calc_c(FFTContext *s, FFTSample *out, const 
FFTSample *input)
 
 /* pre rotation */
 for(i=0;ihttp://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] MAINTAINERS: add myself as videotoolbox* maintainer

2017-11-13 Thread Aman Gupta
ffmpeg | branch: master | Aman Gupta  | Sun Nov 12 14:16:01 2017 
-0800| [480d33dfdc590c0509a4acdb6c2754e208123aab] | committer: Michael 
Niedermayer

MAINTAINERS: add myself as videotoolbox* maintainer

Reviewed-by: Rick Kern 
Signed-off-by: Michael Niedermayer 

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

 MAINTAINERS | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 4df6c6533d..6a92b5190d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -245,7 +245,7 @@ Codecs:
   txd.c Ivo van Poorten
   vc2*  Rostislav Pehlivanov
   vcr1.cMichael Niedermayer
-  videotoolboxenc.c Rick Kern
+  videotoolboxenc.c Rick Kern, Aman Gupta
   vima.cPaul B Mahol
   vorbisdec.c   Denes Balatoni, David Conrad
   vorbisenc.c   Oded Shimon
@@ -272,7 +272,7 @@ Hardware acceleration:
   vaapi*Gwenole Beauchesne
   vaapi_encode* Mark Thompson
   vdpau*Philip Langdale, Carl Eugen Hoyos
-  videotoolbox* Rick Kern
+  videotoolbox* Rick Kern, Aman Gupta
 
 
 libavdevice

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


[FFmpeg-cvslog] avcodec/aacdec_fixed: Fix undefined shift

2017-11-13 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Sun 
Nov  5 21:20:07 2017 +0100| [fca198fb5bf42ba6b765b3f75b11738e4b4fc2a9] | 
committer: Michael Niedermayer

avcodec/aacdec_fixed: Fix undefined shift

Fixes: runtime error: left shift of negative value -801112064
Fixes: 3492/clusterfuzz-testcase-minimized-5784775283441664

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 

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

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

diff --git a/libavcodec/aacdec_fixed.c b/libavcodec/aacdec_fixed.c
index ffd577c789..f96999efb4 100644
--- a/libavcodec/aacdec_fixed.c
+++ b/libavcodec/aacdec_fixed.c
@@ -309,7 +309,7 @@ static av_always_inline void predict(PredictorState *ps, 
int *coef,
 if (shift > 0) {
 *coef += (unsigned)((pv.mant + (1 << (shift - 1))) >> shift);
 } else
-*coef += (unsigned)(pv.mant << -shift);
+*coef += (unsigned)pv.mant << -shift;
 }
 }
 

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


[FFmpeg-cvslog] avcodec/aacpsdsp_template: Fix integer overflows in ps_decorrelate_c()

2017-11-13 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Sun 
Nov  5 21:20:08 2017 +0100| [2afe05402f05d485f0c356b04dc562f0510d317d] | 
committer: Michael Niedermayer

avcodec/aacpsdsp_template: Fix integer overflows in ps_decorrelate_c()

Fixes: runtime error: signed integer overflow: 1939661764 - -454942263 cannot 
be represented in type 'int'
Fixes: 3191/clusterfuzz-testcase-minimized-5688798451073024

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 

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

 libavcodec/aacpsdsp_template.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/aacpsdsp_template.c b/libavcodec/aacpsdsp_template.c
index e35e9699b0..19be200653 100644
--- a/libavcodec/aacpsdsp_template.c
+++ b/libavcodec/aacpsdsp_template.c
@@ -130,12 +130,12 @@ static void ps_decorrelate_c(INTFLOAT (*out)[2], INTFLOAT 
(*delay)[2],
 INTFLOAT apd_im = in_im;
 in_re = AAC_MSUB30(link_delay_re, fractional_delay_re,
 link_delay_im, fractional_delay_im);
-in_re -= a_re;
+in_re -= (UINTFLOAT)a_re;
 in_im = AAC_MADD30(link_delay_re, fractional_delay_im,
 link_delay_im, fractional_delay_re);
-in_im -= a_im;
-ap_delay[m][n+5][0] = apd_re + AAC_MUL31(ag[m], in_re);
-ap_delay[m][n+5][1] = apd_im + AAC_MUL31(ag[m], in_im);
+in_im -= (UINTFLOAT)a_im;
+ap_delay[m][n+5][0] = apd_re + (UINTFLOAT)AAC_MUL31(ag[m], in_re);
+ap_delay[m][n+5][1] = apd_im + (UINTFLOAT)AAC_MUL31(ag[m], in_im);
 }
 out[n][0] = AAC_MUL16(transient_gain[n], in_re);
 out[n][1] = AAC_MUL16(transient_gain[n], in_im);

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


[FFmpeg-cvslog] avformat/http: fix stray quote in trace logging

2017-11-13 Thread Aman Gupta
ffmpeg | branch: master | Aman Gupta  | Mon Nov 13 11:12:52 
2017 -0800| [52bf0febb3a8a47b16ac6c3bfd707c347299f174] | committer: Aman Gupta

avformat/http: fix stray quote in trace logging

Signed-off-by: Aman Gupta 
Reviewed-by: Michael Niedermayer 

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

 libavformat/http.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/http.c b/libavformat/http.c
index bd9148f45d..29635eb546 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -1293,7 +1293,7 @@ static int http_buf_read(URLContext *h, uint8_t *buf, int 
size)
 s->chunksize = strtoull(line, NULL, 16);
 
 av_log(h, AV_LOG_TRACE,
-   "Chunked encoding data size: %"PRIu64"'\n",
+   "Chunked encoding data size: %"PRIu64"\n",
 s->chunksize);
 
 if (!s->chunksize) {

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


[FFmpeg-cvslog] avcodec: implement vp9 nvdec hwaccel

2017-11-13 Thread Timo Rothenpieler
ffmpeg | branch: master | Timo Rothenpieler  | Sat Nov 
11 21:19:07 2017 +0100| [f3f73f0893e2bddd80897148d21cdf3e8e4d8492] | committer: 
Timo Rothenpieler

avcodec: implement vp9 nvdec hwaccel

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

 Changelog  |   2 +-
 configure  |   2 +
 libavcodec/Makefile|   1 +
 libavcodec/allcodecs.c |   1 +
 libavcodec/nvdec.c |   1 +
 libavcodec/nvdec_vp9.c | 227 +
 libavcodec/version.h   |   2 +-
 libavcodec/vp9.c   |  11 ++-
 8 files changed, 244 insertions(+), 3 deletions(-)

diff --git a/Changelog b/Changelog
index 869ecde162..68829f22a4 100644
--- a/Changelog
+++ b/Changelog
@@ -13,7 +13,7 @@ version :
 - PCE support for extended channel layouts in the AAC encoder
 - native aptX encoder and decoder
 - Raw aptX muxer and demuxer
-- NVIDIA NVDEC-accelerated H.264 and HEVC hwaccel decoding
+- NVIDIA NVDEC-accelerated H.264, HEVC and VP9 hwaccel decoding
 - Intel QSV-accelerated overlay filter
 
 
diff --git a/configure b/configure
index 46b4815f2e..da6d644900 100755
--- a/configure
+++ b/configure
@@ -2764,6 +2764,8 @@ vp9_d3d11va2_hwaccel_select="vp9_decoder"
 vp9_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_VP9"
 vp9_dxva2_hwaccel_select="vp9_decoder"
 vp9_mediacodec_hwaccel_deps="mediacodec"
+vp9_nvdec_hwaccel_deps="cuda nvdec"
+vp9_nvdec_hwaccel_select="vp9_decoder"
 vp9_vaapi_hwaccel_deps="vaapi VADecPictureParameterBufferVP9_bit_depth"
 vp9_vaapi_hwaccel_select="vp9_decoder"
 wmv3_d3d11va_hwaccel_select="vc1_d3d11va_hwaccel"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 8c5dfd6319..2476aecc40 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -869,6 +869,7 @@ OBJS-$(CONFIG_VC1_VAAPI_HWACCEL)  += vaapi_vc1.o
 OBJS-$(CONFIG_VC1_VDPAU_HWACCEL)  += vdpau_vc1.o
 OBJS-$(CONFIG_VP9_D3D11VA_HWACCEL)+= dxva2_vp9.o
 OBJS-$(CONFIG_VP9_DXVA2_HWACCEL)  += dxva2_vp9.o
+OBJS-$(CONFIG_VP9_NVDEC_HWACCEL)  += nvdec_vp9.o
 OBJS-$(CONFIG_VP9_VAAPI_HWACCEL)  += vaapi_vp9.o
 OBJS-$(CONFIG_VP8_QSV_HWACCEL)+= qsvdec_other.o
 
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index c817003693..8ac9d9629d 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -123,6 +123,7 @@ static void register_all(void)
 REGISTER_HWACCEL(VP9_D3D11VA2,  vp9_d3d11va2);
 REGISTER_HWACCEL(VP9_DXVA2, vp9_dxva2);
 REGISTER_HWACCEL(VP9_MEDIACODEC,vp9_mediacodec);
+REGISTER_HWACCEL(VP9_NVDEC, vp9_nvdec);
 REGISTER_HWACCEL(VP9_VAAPI, vp9_vaapi);
 REGISTER_HWACCEL(WMV3_D3D11VA,  wmv3_d3d11va);
 REGISTER_HWACCEL(WMV3_D3D11VA2, wmv3_d3d11va2);
diff --git a/libavcodec/nvdec.c b/libavcodec/nvdec.c
index 274f69f997..7d768b2327 100644
--- a/libavcodec/nvdec.c
+++ b/libavcodec/nvdec.c
@@ -54,6 +54,7 @@ static int map_avcodec_id(enum AVCodecID id)
 switch (id) {
 case AV_CODEC_ID_H264: return cudaVideoCodec_H264;
 case AV_CODEC_ID_HEVC: return cudaVideoCodec_HEVC;
+case AV_CODEC_ID_VP9:  return cudaVideoCodec_VP9;
 }
 return -1;
 }
diff --git a/libavcodec/nvdec_vp9.c b/libavcodec/nvdec_vp9.c
new file mode 100644
index 00..06c13e6f03
--- /dev/null
+++ b/libavcodec/nvdec_vp9.c
@@ -0,0 +1,227 @@
+/*
+ * VP9 HW decode acceleration through NVDEC
+ *
+ * Copyright (c) 2016 Timo Rothenpieler
+ *
+ * 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 "libavutil/pixdesc.h"
+
+#include "avcodec.h"
+#include "nvdec.h"
+#include "decode.h"
+#include "internal.h"
+#include "vp9shared.h"
+
+static unsigned char get_ref_idx(AVFrame *frame)
+{
+FrameDecodeData *fdd;
+NVDECFrame *cf;
+
+if (!frame || !frame->private_ref)
+return 255;
+
+fdd = (FrameDecodeData*)frame->private_ref->data;
+cf  = (NVDECFrame*)fdd->hwaccel_priv;
+
+return cf->idx;
+}
+
+static int nvdec_vp9_start_frame(AVCodecContext *avctx, const uint8_t *buffer, 
uint32_t size)
+{
+VP9SharedContext *h = avctx->priv_data;
+const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
+
+NVDECContext  *ctx = avctx->internal->hwaccel_priv_data;
+CUVIDP

[FFmpeg-cvslog] avfilter/vf_premultiply: fix memory-leak on failure

2017-11-13 Thread Timo Rothenpieler
ffmpeg | branch: master | Timo Rothenpieler  | Wed Nov  
8 19:17:51 2017 +0100| [c7ded42d5dfc0124008b5b9b13a1a342324885ed] | committer: 
Timo Rothenpieler

avfilter/vf_premultiply: fix memory-leak on failure

Fixes CID #1416352

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

 libavfilter/vf_premultiply.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavfilter/vf_premultiply.c b/libavfilter/vf_premultiply.c
index 5120adc476..df4f26578d 100644
--- a/libavfilter/vf_premultiply.c
+++ b/libavfilter/vf_premultiply.c
@@ -607,9 +607,10 @@ static int activate(AVFilterContext *ctx)
 int64_t pts;
 
 if ((ret = ff_inlink_consume_frame(ctx->inputs[0], &frame)) > 0) {
-if ((ret = filter_frame(ctx, &out, frame, frame)) < 0)
-return ret;
+ret = filter_frame(ctx, &out, frame, frame);
 av_frame_free(&frame);
+if (ret < 0)
+return ret;
 ret = ff_filter_frame(ctx->outputs[0], out);
 }
 if (ret < 0) {

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


[FFmpeg-cvslog] avcodec/nvdec: fix return value on error

2017-11-13 Thread Timo Rothenpieler
ffmpeg | branch: master | Timo Rothenpieler  | Sun Nov 
12 21:04:57 2017 +0100| [8bcf5840ea2a6a92c75ab3219f89fe0b8a53cf50] | committer: 
Timo Rothenpieler

avcodec/nvdec: fix return value on error

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

 libavcodec/nvdec.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavcodec/nvdec.c b/libavcodec/nvdec.c
index 5d65f1d3dd..ac68faca99 100644
--- a/libavcodec/nvdec.c
+++ b/libavcodec/nvdec.c
@@ -414,8 +414,10 @@ int ff_nvdec_start_frame(AVCodecContext *avctx, AVFrame 
*frame)
 return AVERROR(ENOMEM);
 
 cf->decoder_ref = av_buffer_ref(ctx->decoder_ref);
-if (!cf->decoder_ref)
+if (!cf->decoder_ref) {
+ret = AVERROR(ENOMEM);
 goto fail;
+}
 
 cf->idx_ref = av_buffer_pool_get(ctx->decoder_pool);
 if (!cf->idx_ref) {

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


[FFmpeg-cvslog] avcodec/nvdec: warn about thread count if applicable

2017-11-13 Thread Timo Rothenpieler
ffmpeg | branch: master | Timo Rothenpieler  | Sun Nov 
12 18:09:31 2017 +0100| [538de4354dcd6c57154c5a5dec0744dcaa06b874] | committer: 
Timo Rothenpieler

avcodec/nvdec: warn about thread count if applicable

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

 libavcodec/nvdec.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/libavcodec/nvdec.c b/libavcodec/nvdec.c
index 7d768b2327..5d65f1d3dd 100644
--- a/libavcodec/nvdec.c
+++ b/libavcodec/nvdec.c
@@ -292,8 +292,15 @@ int ff_nvdec_decode_init(AVCodecContext *avctx)
 params.ulNumOutputSurfaces = 1;
 
 ret = nvdec_decoder_create(&ctx->decoder_ref, frames_ctx->device_ref, 
¶ms, avctx);
-if (ret < 0)
+if (ret < 0) {
+if (params.ulNumDecodeSurfaces > 32) {
+av_log(avctx, AV_LOG_WARNING, "Using more than 32 (%d) decode 
surfaces might cause nvdec to fail.\n",
+   (int)params.ulNumDecodeSurfaces);
+av_log(avctx, AV_LOG_WARNING, "Try lowering the amount of threads. 
Using %d right now.\n",
+   avctx->thread_count);
+}
 return ret;
+}
 
 pool = av_mallocz(sizeof(*pool));
 if (!pool) {

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


[FFmpeg-cvslog] lavfi/paletteuse: check get_color return value

2017-11-13 Thread Timo Rothenpieler
ffmpeg | branch: master | Timo Rothenpieler  | Wed Nov  
8 19:17:45 2017 +0100| [237ccd8a165d2128e8c6bcb14c8c6c3e793cfe05] | committer: 
Timo Rothenpieler

lavfi/paletteuse: check get_color return value

Fixes CID #1420396

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

 libavfilter/vf_paletteuse.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavfilter/vf_paletteuse.c b/libavfilter/vf_paletteuse.c
index ed80ab04d5..1980907e70 100644
--- a/libavfilter/vf_paletteuse.c
+++ b/libavfilter/vf_paletteuse.c
@@ -380,8 +380,11 @@ static av_always_inline int 
get_dst_color_err(PaletteUseContext *s,
 const uint8_t r = c >> 16 & 0xff;
 const uint8_t g = c >>  8 & 0xff;
 const uint8_t b = c   & 0xff;
+uint32_t dstc;
 const int dstx = color_get(s, c, a, r, g, b, search_method);
-const uint32_t dstc = s->palette[dstx];
+if (dstx < 0)
+return dstx;
+dstc = s->palette[dstx];
 *er = r - (dstc >> 16 & 0xff);
 *eg = g - (dstc >>  8 & 0xff);
 *eb = b - (dstc   & 0xff);

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


[FFmpeg-cvslog] avformat/fitsenc: validate input pixel format

2017-11-13 Thread Timo Rothenpieler
ffmpeg | branch: master | Timo Rothenpieler  | Wed Nov  
8 19:17:49 2017 +0100| [284b432662b6e137148ff9d13ef2b554cb14b4ae] | committer: 
Timo Rothenpieler

avformat/fitsenc: validate input pixel format

Fixes CID #1416961 and #1416962

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

 libavformat/fitsenc.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavformat/fitsenc.c b/libavformat/fitsenc.c
index 7cb171596c..cc3999aa8a 100644
--- a/libavformat/fitsenc.c
+++ b/libavformat/fitsenc.c
@@ -106,6 +106,8 @@ static int write_image_header(AVFormatContext *s)
 }
 bzero = 32768;
 break;
+default:
+return AVERROR(EINVAL);
 }
 
 if (fitsctx->first_image) {
@@ -166,7 +168,9 @@ static int write_image_header(AVFormatContext *s)
 
 static int fits_write_packet(AVFormatContext *s, AVPacket *pkt)
 {
-write_image_header(s);
+int ret = write_image_header(s);
+if (ret < 0)
+return ret;
 avio_write(s->pb, pkt->data, pkt->size);
 return 0;
 }

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


[FFmpeg-cvslog] movenc-test: fix potential uninitialized read

2017-11-13 Thread Timo Rothenpieler
ffmpeg | branch: master | Timo Rothenpieler  | Wed Nov  
8 19:17:52 2017 +0100| [de6a1e32fd483db05d957268d5e45e2b1be9cab4] | committer: 
Timo Rothenpieler

movenc-test: fix potential uninitialized read

Fixes CID #1413023

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

 libavformat/tests/movenc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavformat/tests/movenc.c b/libavformat/tests/movenc.c
index 8e59b74259..ad6c92a94c 100644
--- a/libavformat/tests/movenc.c
+++ b/libavformat/tests/movenc.c
@@ -115,6 +115,7 @@ static int io_write_data_type(void *opaque, uint8_t *buf, 
int size,
 case AVIO_DATA_MARKER_BOUNDARY_POINT: str = "boundary"; break;
 case AVIO_DATA_MARKER_UNKNOWN:str = "unknown";  break;
 case AVIO_DATA_MARKER_TRAILER:str = "trailer";  break;
+default:  str = "unknown";  break;
 }
 if (time == AV_NOPTS_VALUE)
 snprintf(timebuf, sizeof(timebuf), "nopts");

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


[FFmpeg-cvslog] Makefile: fix distclean target

2017-11-13 Thread James Almer
ffmpeg | branch: master | James Almer  | Mon Nov 13 17:37:56 
2017 -0300| [e7e7d56a850d34d710c45463607abac846972f57] | committer: James Almer

Makefile: fix distclean target

It must imply clean. Regression since e0087a5624117a1d643e2cb433ecc4d536756dda.

Signed-off-by: James Almer 

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

 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 28af3debef..9defddebfd 100644
--- a/Makefile
+++ b/Makefile
@@ -138,7 +138,7 @@ clean::
$(RM) -r coverage-html
$(RM) -rf coverage.info coverage.info.in lcov
 
-distclean::
+distclean:: clean
$(RM) .version avversion.h config.asm config.h mapfile  \
ffbuild/.config ffbuild/config.* libavutil/avconfig.h \
version.h libavutil/ffversion.h libavcodec/codec_names.h \

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


[FFmpeg-cvslog] This fixes a deadlock while reading a chunked https response, if

2017-11-13 Thread Aman Gupta
ffmpeg | branch: master | Aman Gupta  | Mon Nov 13 15:02:44 
2017 -0600| [9c8922acadb5187c274250d6cde653b7bad2559e] | committer: Rodger Combs

This fixes a deadlock while reading a chunked https response, if
multiple_requests=1 is also set. Without an EOF to signal the end of
the last chunk, tls_read gets stuck forever trying to read more data
than is available. This occurs with the http protocol reproducibly,
because http.c always reads 4kb at a time, and the last chunk of an
http response is often much smaller.

After this commit, tls_read always returns any buffered plaintext
first before attempting to read more encrypted data off the
underlying tcp socket.

Signed-off-by: Rodger Combs 

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

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

diff --git a/libavformat/tls_securetransport.c 
b/libavformat/tls_securetransport.c
index dc32eb1fa8..37380541b1 100644
--- a/libavformat/tls_securetransport.c
+++ b/libavformat/tls_securetransport.c
@@ -364,8 +364,12 @@ static int map_ssl_error(OSStatus status, size_t processed)
 static int tls_read(URLContext *h, uint8_t *buf, int size)
 {
 TLSContext *c = h->priv_data;
-size_t processed = 0;
-int ret = SSLRead(c->ssl_context, buf, size, &processed);
+size_t available = 0, processed = 0;
+int ret;
+SSLGetBufferedReadSize(c->ssl_context, &available);
+if (available)
+size = FFMIN(available, size);
+ret = SSLRead(c->ssl_context, buf, size, &processed);
 ret = map_ssl_error(ret, processed);
 if (ret > 0)
 return ret;

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


[FFmpeg-cvslog] lavf/tls_securetransport: handle incomplete reads gracefully

2017-11-13 Thread Rodger Combs
ffmpeg | branch: master | Rodger Combs  | Mon Nov 13 
14:46:17 2017 -0600| [a36a3d7fecdfc50691f01eef984cad6cedb6fb3a] | committer: 
Rodger Combs

lavf/tls_securetransport: handle incomplete reads gracefully

Signed-off-by: Aman Gupta 

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

 libavformat/tls_securetransport.c | 24 
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/libavformat/tls_securetransport.c 
b/libavformat/tls_securetransport.c
index b862e0003a..dc32eb1fa8 100644
--- a/libavformat/tls_securetransport.c
+++ b/libavformat/tls_securetransport.c
@@ -54,7 +54,7 @@ static int print_tls_error(URLContext *h, int ret)
 TLSContext *c = h->priv_data;
 switch (ret) {
 case errSSLWouldBlock:
-break;
+return AVERROR(EAGAIN);
 case errSSLXCertChainInvalid:
 av_log(h, AV_LOG_ERROR, "Invalid certificate chain\n");
 return AVERROR(EIO);
@@ -197,7 +197,8 @@ static OSStatus tls_read_cb(SSLConnectionRef connection, 
void *data, size_t *dat
 {
 URLContext *h = (URLContext*)connection;
 TLSContext *c = h->priv_data;
-int read = ffurl_read_complete(c->tls_shared.tcp, data, *dataLength);
+size_t requested = *dataLength;
+int read = ffurl_read(c->tls_shared.tcp, data, requested);
 if (read <= 0) {
 *dataLength = 0;
 switch(AVUNERROR(read)) {
@@ -214,7 +215,10 @@ static OSStatus tls_read_cb(SSLConnectionRef connection, 
void *data, size_t *dat
 }
 } else {
 *dataLength = read;
-return noErr;
+if (read < requested)
+return errSSLWouldBlock;
+else
+return noErr;
 }
 }
 
@@ -326,12 +330,13 @@ static int tls_open(URLContext *h, const char *uri, int 
flags, AVDictionary **op
 if (peerTrust)
 CFRelease(peerTrust);
 }
-if (status == noErr)
+if (status == noErr) {
 break;
-
-av_log(h, AV_LOG_ERROR, "Unable to negotiate TLS/SSL session: %i\n", 
(int)status);
-ret = AVERROR(EIO);
-goto fail;
+} else if (status != errSSLWouldBlock) {
+av_log(h, AV_LOG_ERROR, "Unable to negotiate TLS/SSL session: 
%i\n", (int)status);
+ret = AVERROR(EIO);
+goto fail;
+}
 }
 
 return 0;
@@ -348,6 +353,9 @@ static int map_ssl_error(OSStatus status, size_t processed)
 case errSSLClosedGraceful:
 case errSSLClosedNoNotify:
 return 0;
+case errSSLWouldBlock:
+if (processed > 0)
+return processed;
 default:
 return (int)status;
 }

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


[FFmpeg-cvslog] configure: fix cuda dependency on nvdec

2017-11-13 Thread Timo Rothenpieler
ffmpeg | branch: master | Timo Rothenpieler  | Mon Nov 
13 21:55:09 2017 +0100| [681c638fab4ed4699e7fd5cf119606910a1f75ba] | committer: 
Timo Rothenpieler

configure: fix cuda dependency on nvdec

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

 configure | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index da6d644900..3f0a7cd9d6 100755
--- a/configure
+++ b/configure
@@ -2651,6 +2651,7 @@ cuda_deps_any="libdl LoadLibrary"
 cuvid_deps="cuda"
 d3d11va_deps="dxva_h ID3D11VideoDecoder ID3D11VideoContext"
 dxva2_deps="dxva2api_h DXVA2_ConfigPictureDecode ole32 user32"
+nvdec_deps="cuda"
 videotoolbox_hwaccel_deps="videotoolbox pthreads"
 videotoolbox_hwaccel_extralibs="-framework QuartzCore"
 xvmc_deps="X11_extensions_XvMClib_h"
@@ -2669,7 +2670,7 @@ h264_dxva2_hwaccel_deps="dxva2"
 h264_dxva2_hwaccel_select="h264_decoder"
 h264_mediacodec_hwaccel_deps="mediacodec"
 h264_mmal_hwaccel_deps="mmal"
-h264_nvdec_hwaccel_deps="cuda nvdec"
+h264_nvdec_hwaccel_deps="nvdec"
 h264_nvdec_hwaccel_select="h264_decoder"
 h264_qsv_hwaccel_deps="libmfx"
 h264_vaapi_hwaccel_deps="vaapi"
@@ -2687,7 +2688,7 @@ hevc_d3d11va2_hwaccel_deps="d3d11va DXVA_PicParams_HEVC"
 hevc_d3d11va2_hwaccel_select="hevc_decoder"
 hevc_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_HEVC"
 hevc_dxva2_hwaccel_select="hevc_decoder"
-hevc_nvdec_hwaccel_deps="cuda nvdec"
+hevc_nvdec_hwaccel_deps="nvdec"
 hevc_nvdec_hwaccel_select="hevc_decoder"
 hevc_qsv_hwaccel_deps="libmfx"
 hevc_vaapi_hwaccel_deps="vaapi VAPictureParameterBufferHEVC"
@@ -2764,7 +2765,7 @@ vp9_d3d11va2_hwaccel_select="vp9_decoder"
 vp9_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_VP9"
 vp9_dxva2_hwaccel_select="vp9_decoder"
 vp9_mediacodec_hwaccel_deps="mediacodec"
-vp9_nvdec_hwaccel_deps="cuda nvdec"
+vp9_nvdec_hwaccel_deps="nvdec"
 vp9_nvdec_hwaccel_select="vp9_decoder"
 vp9_vaapi_hwaccel_deps="vaapi VADecPictureParameterBufferVP9_bit_depth"
 vp9_vaapi_hwaccel_select="vp9_decoder"

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


[FFmpeg-cvslog] configure: factorize nvdec dependencies

2017-11-13 Thread Timo Rothenpieler
ffmpeg | branch: master | Timo Rothenpieler  | Mon Nov 
13 22:01:53 2017 +0100| [578addcff64f14783cce3171fdd158602edd757b] | committer: 
Timo Rothenpieler

configure: factorize nvdec dependencies

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

 configure | 27 +--
 1 file changed, 9 insertions(+), 18 deletions(-)

diff --git a/configure b/configure
index 3f0a7cd9d6..4418352d30 100755
--- a/configure
+++ b/configure
@@ -2660,7 +2660,6 @@ h263_vaapi_hwaccel_deps="vaapi"
 h263_vaapi_hwaccel_select="h263_decoder"
 h263_videotoolbox_hwaccel_deps="videotoolbox"
 h263_videotoolbox_hwaccel_select="h263_decoder"
-h264_cuvid_hwaccel_deps="cuda cuvid"
 h264_cuvid_hwaccel_select="h264_cuvid_decoder"
 h264_d3d11va_hwaccel_deps="d3d11va"
 h264_d3d11va_hwaccel_select="h264_decoder"
@@ -2679,7 +2678,6 @@ h264_vdpau_hwaccel_deps="vdpau"
 h264_vdpau_hwaccel_select="h264_decoder"
 h264_videotoolbox_hwaccel_deps="videotoolbox"
 h264_videotoolbox_hwaccel_select="h264_decoder"
-hevc_cuvid_hwaccel_deps="cuda cuvid"
 hevc_cuvid_hwaccel_select="hevc_cuvid_decoder"
 hevc_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_HEVC"
 hevc_d3d11va_hwaccel_select="hevc_decoder"
@@ -2697,11 +2695,9 @@ hevc_vdpau_hwaccel_deps="vdpau VdpPictureInfoHEVC"
 hevc_vdpau_hwaccel_select="hevc_decoder"
 hevc_videotoolbox_hwaccel_deps="videotoolbox"
 hevc_videotoolbox_hwaccel_select="hevc_decoder"
-mjpeg_cuvid_hwaccel_deps="cuda cuvid"
 mjpeg_cuvid_hwaccel_select="mjpeg_cuvid_decoder"
 mpeg_xvmc_hwaccel_deps="xvmc"
 mpeg_xvmc_hwaccel_select="mpeg2video_decoder"
-mpeg1_cuvid_hwaccel_deps="cuda cuvid"
 mpeg1_cuvid_hwaccel_select="mpeg1_cuvid_decoder"
 mpeg1_vdpau_hwaccel_deps="vdpau"
 mpeg1_vdpau_hwaccel_select="mpeg1video_decoder"
@@ -2709,7 +2705,6 @@ mpeg1_videotoolbox_hwaccel_deps="videotoolbox"
 mpeg1_videotoolbox_hwaccel_select="mpeg1video_decoder"
 mpeg1_xvmc_hwaccel_deps="xvmc"
 mpeg1_xvmc_hwaccel_select="mpeg1video_decoder"
-mpeg2_cuvid_hwaccel_deps="cuda cuvid"
 mpeg2_cuvid_hwaccel_select="mpeg2_cuvid_decoder"
 mpeg2_d3d11va_hwaccel_deps="d3d11va"
 mpeg2_d3d11va_hwaccel_select="mpeg2video_decoder"
@@ -2728,7 +2723,6 @@ mpeg2_videotoolbox_hwaccel_deps="videotoolbox"
 mpeg2_videotoolbox_hwaccel_select="mpeg2video_decoder"
 mpeg2_xvmc_hwaccel_deps="xvmc"
 mpeg2_xvmc_hwaccel_select="mpeg2video_decoder"
-mpeg4_cuvid_hwaccel_deps="cuda cuvid"
 mpeg4_cuvid_hwaccel_select="mpeg4_cuvid_decoder"
 mpeg4_mediacodec_hwaccel_deps="mediacodec"
 mpeg4_mmal_hwaccel_deps="mmal"
@@ -2738,7 +2732,6 @@ mpeg4_vdpau_hwaccel_deps="vdpau"
 mpeg4_vdpau_hwaccel_select="mpeg4_decoder"
 mpeg4_videotoolbox_hwaccel_deps="videotoolbox"
 mpeg4_videotoolbox_hwaccel_select="mpeg4_decoder"
-vc1_cuvid_hwaccel_deps="cuda cuvid"
 vc1_cuvid_hwaccel_select="vc1_cuvid_decoder"
 vc1_d3d11va_hwaccel_deps="d3d11va"
 vc1_d3d11va_hwaccel_select="vc1_decoder"
@@ -2752,9 +2745,7 @@ vc1_vaapi_hwaccel_deps="vaapi"
 vc1_vaapi_hwaccel_select="vc1_decoder"
 vc1_vdpau_hwaccel_deps="vdpau"
 vc1_vdpau_hwaccel_select="vc1_decoder"
-vp8_cuvid_hwaccel_deps="cuda cuvid"
 vp8_cuvid_hwaccel_select="vp8_cuvid_decoder"
-vp9_cuvid_hwaccel_deps="cuda cuvid"
 vp9_cuvid_hwaccel_select="vp9_cuvid_decoder"
 vp8_mediacodec_hwaccel_deps="mediacodec"
 vp8_qsv_hwaccel_deps="libmfx"
@@ -2797,7 +2788,7 @@ nvenc_encoder_deps="nvenc"
 h263_v4l2m2m_decoder_deps="v4l2_m2m h263_v4l2_m2m"
 h263_v4l2m2m_encoder_deps="v4l2_m2m h263_v4l2_m2m"
 h264_crystalhd_decoder_select="crystalhd h264_mp4toannexb_bsf h264_parser"
-h264_cuvid_decoder_deps="cuda cuvid"
+h264_cuvid_decoder_deps="cuvid"
 h264_cuvid_decoder_select="h264_mp4toannexb_bsf"
 h264_mediacodec_decoder_deps="mediacodec"
 h264_mediacodec_decoder_select="h264_mp4toannexb_bsf h264_parser"
@@ -2812,7 +2803,7 @@ h264_vaapi_encoder_deps="VAEncPictureParameterBufferH264"
 h264_vaapi_encoder_select="cbs_h264 vaapi_encode"
 h264_v4l2m2m_decoder_deps="v4l2_m2m h264_v4l2_m2m"
 h264_v4l2m2m_encoder_deps="v4l2_m2m h264_v4l2_m2m"
-hevc_cuvid_decoder_deps="cuda cuvid"
+hevc_cuvid_decoder_deps="cuvid"
 hevc_cuvid_decoder_select="hevc_mp4toannexb_bsf"
 hevc_mediacodec_decoder_deps="mediacodec"
 hevc_mediacodec_decoder_select="hevc_mp4toannexb_bsf hevc_parser"
@@ -2825,15 +2816,15 @@ 
hevc_vaapi_encoder_deps="VAEncPictureParameterBufferHEVC"
 hevc_vaapi_encoder_select="cbs_h265 vaapi_encode"
 hevc_v4l2m2m_decoder_deps="v4l2_m2m hevc_v4l2_m2m"
 hevc_v4l2m2m_encoder_deps="v4l2_m2m hevc_v4l2_m2m"
-mjpeg_cuvid_decoder_deps="cuda cuvid"
+mjpeg_cuvid_decoder_deps="cuvid"
 mjpeg_qsv_encoder_deps="libmfx"
 mjpeg_qsv_encoder_select="qsvenc"
 mjpeg_vaapi_encoder_deps="VAEncPictureParameterBufferJPEG"
 mjpeg_vaapi_encoder_select="vaapi_encode jpegtables"
-mpeg1_cuvid_decoder_deps="cuda cuvid"
+mpeg1_cuvid_decoder_deps="cuvid"
 mpeg1_v4l2m2m_decoder_deps="v4l2_m2m mpeg1_v4l2_m2m"
 mpeg2_crystalhd_decoder_select="crystalhd"
-mpeg2_cuvid_decoder_deps="cuda cuvid"
+mpeg2_cuvid_decoder_deps="cuvid"
 mpeg2_mmal_decoder_deps="mmal

[FFmpeg-cvslog] avcodec/videotoolboxenc: add hevc_videotoolbox encoder

2017-11-13 Thread Aman Gupta
ffmpeg | branch: master | Aman Gupta  | Sun Nov 12 10:19:17 2017 
-0800| [e7a5249ab1775827a331c48e4d236eda52d51575] | committer: Aman Gupta

avcodec/videotoolboxenc: add hevc_videotoolbox encoder

Signed-off-by: Aman Gupta 
Reviewed-by: Rodger Combs 

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

 configure|   2 +
 libavcodec/allcodecs.c   |   1 +
 libavcodec/videotoolboxenc.c | 168 ---
 3 files changed, 146 insertions(+), 25 deletions(-)

diff --git a/configure b/configure
index 4418352d30..3788f26956 100755
--- a/configure
+++ b/configure
@@ -2918,6 +2918,8 @@ pcm_mulaw_at_encoder_select="audio_frame_queue"
 chromaprint_muxer_deps="chromaprint"
 h264_videotoolbox_encoder_deps="pthreads"
 h264_videotoolbox_encoder_select="videotoolbox_encoder"
+hevc_videotoolbox_encoder_deps="pthreads"
+hevc_videotoolbox_encoder_select="videotoolbox_encoder"
 libcelt_decoder_deps="libcelt"
 libfdk_aac_decoder_deps="libfdk_aac"
 libfdk_aac_encoder_deps="libfdk_aac"
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 8ac9d9629d..0781862de5 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -671,6 +671,7 @@ static void register_all(void)
 REGISTER_ENCODER(HEVC_QSV,  hevc_qsv);
 REGISTER_ENCODER(HEVC_V4L2M2M,  hevc_v4l2m2m);
 REGISTER_ENCODER(HEVC_VAAPI,hevc_vaapi);
+REGISTER_ENCODER(HEVC_VIDEOTOOLBOX, hevc_videotoolbox);
 REGISTER_ENCODER(LIBKVAZAAR,libkvazaar);
 REGISTER_DECODER(MJPEG_CUVID,   mjpeg_cuvid);
 REGISTER_ENCODER(MJPEG_QSV, mjpeg_qsv);
diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index eba6cc672f..7b50edbb8f 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -35,6 +35,17 @@
 #include "h264_sei.h"
 #include 
 
+#if !HAVE_KCMVIDEOCODECTYPE_HEVC
+enum { kCMVideoCodecType_HEVC = 'hvc1' };
+#endif
+
+typedef OSStatus (*getParameterSetAtIndex)(CMFormatDescriptionRef videoDesc,
+   size_t parameterSetIndex,
+   const uint8_t * _Nullable 
*parameterSetPointerOut,
+   size_t *parameterSetSizeOut,
+   size_t *parameterSetCountOut,
+   int *NALUnitHeaderLengthOut);
+
 //These symbols may not be present
 static struct{
 CFStringRef kCVImageBufferColorPrimaries_ITU_R_2020;
@@ -65,10 +76,15 @@ static struct{
 CFStringRef kVTProfileLevel_H264_High_5_2;
 CFStringRef kVTProfileLevel_H264_High_AutoLevel;
 
+CFStringRef kVTProfileLevel_HEVC_Main_AutoLevel;
+CFStringRef kVTProfileLevel_HEVC_Main10_AutoLevel;
+
 CFStringRef kVTCompressionPropertyKey_RealTime;
 
 CFStringRef 
kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder;
 CFStringRef 
kVTVideoEncoderSpecification_RequireHardwareAcceleratedVideoEncoder;
+
+getParameterSetAtIndex CMVideoFormatDescriptionGetHEVCParameterSetAtIndex;
 } compat_keys;
 
 #define GET_SYM(symbol, defaultVal) \
@@ -83,6 +99,12 @@ do{  
   \
 static pthread_once_t once_ctrl = PTHREAD_ONCE_INIT;
 
 static void loadVTEncSymbols(){
+compat_keys.CMVideoFormatDescriptionGetHEVCParameterSetAtIndex =
+(getParameterSetAtIndex)dlsym(
+RTLD_DEFAULT,
+"CMVideoFormatDescriptionGetHEVCParameterSetAtIndex"
+);
+
 GET_SYM(kCVImageBufferColorPrimaries_ITU_R_2020,   "ITU_R_2020");
 GET_SYM(kCVImageBufferTransferFunction_ITU_R_2020, "ITU_R_2020");
 GET_SYM(kCVImageBufferYCbCrMatrix_ITU_R_2020,  "ITU_R_2020");
@@ -111,6 +133,9 @@ static void loadVTEncSymbols(){
 GET_SYM(kVTProfileLevel_H264_High_5_2,   "H264_High_5_2");
 GET_SYM(kVTProfileLevel_H264_High_AutoLevel, "H264_High_AutoLevel");
 
+GET_SYM(kVTProfileLevel_HEVC_Main_AutoLevel, "HEVC_Main_AutoLevel");
+GET_SYM(kVTProfileLevel_HEVC_Main10_AutoLevel,   "HEVC_Main10_AutoLevel");
+
 GET_SYM(kVTCompressionPropertyKey_RealTime, "RealTime");
 
 GET_SYM(kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder,
@@ -133,6 +158,13 @@ typedef enum VTH264Entropy{
 VT_CABAC
 } VTH264Entropy;
 
+typedef enum VT_HEVCProfile {
+HEVC_PROF_AUTO,
+HEVC_PROF_MAIN,
+HEVC_PROF_MAIN10,
+HEVC_PROF_COUNT
+} VT_HEVCProfile;
+
 static const uint8_t start_code[] = { 0, 0, 0, 1 };
 
 typedef struct ExtraSEI {
@@ -149,10 +181,12 @@ typedef struct BufNode {
 
 typedef struct VTEncContext {
 AVClass *class;
+enum AVCodecID codec_id;
 VTCompressionSessionRef session;
 CFStringRef ycbcr_matrix;
 CFStringRef color_primaries;
 CFStringRef transfer_function;
+getParameterSetAtIndex get_param_set_func;
 
 pthread_mutex_t loc

[FFmpeg-cvslog] avcodec/videotoolboxenc: re-indent code

2017-11-13 Thread Aman Gupta
ffmpeg | branch: master | Aman Gupta  | Sun Nov 12 10:20:17 2017 
-0800| [230b91cdfdd1949f9b1719d5d91d77caad90aaae] | committer: Aman Gupta

avcodec/videotoolboxenc: re-indent code

Cosmetic change only.

Signed-off-by: Aman Gupta 

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

 libavcodec/videotoolboxenc.c | 158 +--
 1 file changed, 79 insertions(+), 79 deletions(-)

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 7b50edbb8f..93338eabde 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -407,11 +407,11 @@ static int get_params_size(
 size_t i;
 int status;
 status = vtctx->get_param_set_func(vid_fmt,
-0,
-NULL,
-NULL,
-&ps_count,
-NULL);
+   0,
+   NULL,
+   NULL,
+   &ps_count,
+   NULL);
 if (status) {
 is_count_bad = 1;
 ps_count = 0;
@@ -422,11 +422,11 @@ static int get_params_size(
 const uint8_t *ps;
 size_t ps_size;
 status = vtctx->get_param_set_func(vid_fmt,
-i,
-&ps,
-&ps_size,
-NULL,
-NULL);
+   i,
+   &ps,
+   &ps_size,
+   NULL,
+   NULL);
 if (status) {
 /*
  * When ps_count is invalid, status != 0 ends the loop normally
@@ -463,11 +463,11 @@ static int copy_param_sets(
 size_t i;
 
 status = vtctx->get_param_set_func(vid_fmt,
-0,
-NULL,
-NULL,
-&ps_count,
-NULL);
+   0,
+   NULL,
+   NULL,
+   &ps_count,
+   NULL);
 if (status) {
 is_count_bad = 1;
 ps_count = 0;
@@ -481,11 +481,11 @@ static int copy_param_sets(
 size_t next_offset;
 
 status = vtctx->get_param_set_func(vid_fmt,
-i,
-&ps,
-&ps_size,
-NULL,
-NULL);
+   i,
+   &ps,
+   &ps_size,
+   NULL,
+   NULL);
 if (status) {
 if (i > 0 && is_count_bad) status = 0;
 
@@ -597,11 +597,11 @@ static int get_length_code_size(
 }
 
 status = vtctx->get_param_set_func(vid_fmt,
-0,
-NULL,
-NULL,
-NULL,
-&isize);
+   0,
+   NULL,
+   NULL,
+   NULL,
+   &isize);
 if (status) {
 av_log(avctx, AV_LOG_ERROR, "Error getting length code size: %d\n", 
status);
 return AVERROR_EXTERNAL;
@@ -1018,55 +1018,55 @@ static int vtenc_create_encoder(AVCodecContext   *avctx,
 }
 
 if (vtctx->codec_id == AV_CODEC_ID_H264) {
-// kVTCompressionPropertyKey_DataRateLimits is not avail

[FFmpeg-cvslog] avcodec/videotoolbox: reset bitstream_size in end_frame

2017-11-13 Thread Aman Gupta
ffmpeg | branch: master | Aman Gupta  | Mon Sep 25 16:42:18 2017 
-0700| [d869928ca6e61358adb916369cafd61366f6b064] | committer: Aman Gupta

avcodec/videotoolbox: reset bitstream_size in end_frame

This allows decode_slice to be invoked multiple times before end_frame,
causing slices to accumulate before being fed into the VT decoder.

An upcoming commit will re-use decode_slice for parameter NALUs, so
they can be propagated into the VT decoder session along with slice
data.

Signed-off-by: Aman Gupta 

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

 libavcodec/videotoolbox.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index f3d5f0aa4d..67b7429274 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -300,8 +300,6 @@ int ff_videotoolbox_h264_start_frame(AVCodecContext *avctx,
 VTContext *vtctx = avctx->internal->hwaccel_priv_data;
 H264Context *h  = avctx->priv_data;
 
-vtctx->bitstream_size = 0;
-
 if (h->is_avc == 1) {
 return videotoolbox_buffer_copy(vtctx, buffer, size);
 }
@@ -600,8 +598,10 @@ static int videotoolbox_h264_end_frame(AVCodecContext 
*avctx)
 {
 H264Context *h = avctx->priv_data;
 AVFrame *frame = h->cur_pic_ptr->f;
-
-return videotoolbox_common_end_frame(avctx, frame);
+VTContext *vtctx = avctx->internal->hwaccel_priv_data;
+int ret = videotoolbox_common_end_frame(avctx, frame);
+vtctx->bitstream_size = 0;
+return ret;
 }
 
 static int videotoolbox_hevc_end_frame(AVCodecContext *avctx)

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


[FFmpeg-cvslog] avcodec/videotoolbox: use early return in videotoolbox_default_free

2017-11-13 Thread Aman Gupta
ffmpeg | branch: master | Aman Gupta  | Fri Nov 10 11:59:05 2017 
-0800| [631296ff9922a6971de41640a0d937b1a2a52393] | committer: Aman Gupta

avcodec/videotoolbox: use early return in videotoolbox_default_free

Cosmetic change only.

Signed-off-by: Aman Gupta 

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

 libavcodec/videotoolbox.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index f0790e7353..5011f5201d 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -849,15 +849,15 @@ static int videotoolbox_default_init(AVCodecContext 
*avctx)
 static void videotoolbox_default_free(AVCodecContext *avctx)
 {
 AVVideotoolboxContext *videotoolbox = videotoolbox_get_context(avctx);
+if (!videotoolbox)
+return;
 
-if (videotoolbox) {
-if (videotoolbox->cm_fmt_desc)
-CFRelease(videotoolbox->cm_fmt_desc);
+if (videotoolbox->cm_fmt_desc)
+CFRelease(videotoolbox->cm_fmt_desc);
 
-if (videotoolbox->session) {
-VTDecompressionSessionInvalidate(videotoolbox->session);
-CFRelease(videotoolbox->session);
-}
+if (videotoolbox->session) {
+VTDecompressionSessionInvalidate(videotoolbox->session);
+CFRelease(videotoolbox->session);
 }
 }
 

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


[FFmpeg-cvslog] avcodec: add decode_params callback to AVHWAccel struct

2017-11-13 Thread Aman Gupta
ffmpeg | branch: master | Aman Gupta  | Fri Nov 10 12:17:36 2017 
-0800| [76f169368da4928308b932eaea528b841bc34f9e] | committer: Aman Gupta

avcodec: add decode_params callback to AVHWAccel struct

Signed-off-by: Aman Gupta 

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

 libavcodec/avcodec.h | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 8c76c9f908..74b097cdd8 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3461,6 +3461,20 @@ typedef struct AVHWAccel {
 int (*start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t 
buf_size);
 
 /**
+ * Callback for parameter data (SPS/PPS/VPS etc).
+ *
+ * Useful for hardware decoders which keep persistent state about the
+ * video parameters, and need to receive any changes to update that state.
+ *
+ * @param avctx the codec context
+ * @param type the nal unit type
+ * @param buf the nal unit data buffer
+ * @param buf_size the size of the nal unit in bytes
+ * @return zero if successful, a negative value otherwise
+ */
+int (*decode_params)(AVCodecContext *avctx, int type, const uint8_t *buf, 
uint32_t buf_size);
+
+/**
  * Callback for each slice.
  *
  * Meaningful slice information (codec specific) is guaranteed to

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


[FFmpeg-cvslog] avcodec/videotoolbox: create avcC even when h264 extradata is missing

2017-11-13 Thread Aman Gupta
ffmpeg | branch: master | Aman Gupta  | Mon Sep 25 16:52:35 2017 
-0700| [403d10a8b3cd9c0c9a4a034b95a4cb5ffc4b1112] | committer: Aman Gupta

avcodec/videotoolbox: create avcC even when h264 extradata is missing

Removes the avctx->extradata_size requirement when creating avcC/hvcC, since
avctx->extradata is only used in the esds code path.

This fixes an issue where the VideoToolbox decoder would not work unless
avformat_find_stream_info() was called.

Signed-off-by: Aman Gupta 

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

 libavcodec/videotoolbox.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index c24f5aa3f3..7e915a4e83 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -702,7 +702,7 @@ static CFDictionaryRef 
videotoolbox_decoder_config_create(CMVideoCodecType codec
  
kVTVideoDecoderSpecification_RequireHardwareAcceleratedVideoDecoder,
  kCFBooleanTrue);
 
-if (avctx->extradata_size) {
+if (1) {
 CFMutableDictionaryRef avc_info;
 CFDataRef data = NULL;
 
@@ -713,7 +713,8 @@ static CFDictionaryRef 
videotoolbox_decoder_config_create(CMVideoCodecType codec
 
 switch (codec_type) {
 case kCMVideoCodecType_MPEG4Video :
-data = videotoolbox_esds_extradata_create(avctx);
+if (avctx->extradata_size)
+data = videotoolbox_esds_extradata_create(avctx);
 if (data)
 CFDictionarySetValue(avc_info, CFSTR("esds"), data);
 break;

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


[FFmpeg-cvslog] avcodec/videotoolbox: use decode_params to propagate H264 PPS changes and restart on SPS changes

2017-11-13 Thread Aman Gupta
ffmpeg | branch: master | Aman Gupta  | Fri Nov 10 12:25:39 2017 
-0800| [9519983c0f39d01fd86544dc56adbbf15bdd3c3c] | committer: Aman Gupta

avcodec/videotoolbox: use decode_params to propagate H264 PPS changes and 
restart on SPS changes

This fixes decoding of H264 video samples with SPS and PPS changes.

See for example https://s3.amazonaws.com/tmm1/videotoolbox/spschange.ts,
which previously stalled the decoder and failed to produce any new frames
after the SPS change.

Also see https://s3.amazonaws.com/tmm1/videotoolbox/ppschange.ts, which
uses multiple PPS and would previously cause VT decode failures.

If the VideoToolbox session needs to be restarted, and
videotoolbox_start() fails for some reason (for instance, if the video
is interlaced and the decoder is running on iOS), avcodec will return
AVERROR_EXTERNAL. This can be used by the API user to switch to another
decoder.

Signed-off-by: Aman Gupta 

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

 libavcodec/videotoolbox.c | 43 +--
 libavcodec/vt_internal.h  |  6 ++
 2 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index 4fe89a27e9..c24f5aa3f3 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -42,6 +42,9 @@ enum { kCMVideoCodecType_HEVC = 'hvc1' };
 
 #define VIDEOTOOLBOX_ESDS_EXTRADATA_PADDING  12
 
+static void videotoolbox_stop(AVCodecContext *avctx);
+static int videotoolbox_start(AVCodecContext *avctx);
+
 static void videotoolbox_buffer_release(void *opaque, uint8_t *data)
 {
 CVPixelBufferRef cv_buffer = (CVImageBufferRef)data;
@@ -307,6 +310,27 @@ int ff_videotoolbox_h264_start_frame(AVCodecContext *avctx,
 return 0;
 }
 
+static int videotoolbox_h264_decode_params(AVCodecContext *avctx,
+   int type,
+   const uint8_t *buffer,
+   uint32_t size)
+{
+VTContext *vtctx = avctx->internal->hwaccel_priv_data;
+
+if (type == H264_NAL_SPS) {
+if (!vtctx->sps || vtctx->sps_len != size || memcmp(buffer, 
vtctx->sps, size) != 0) {
+vtctx->sps = av_fast_realloc(vtctx->sps, &vtctx->sps_capa, size);
+if (vtctx->sps)
+memcpy(vtctx->sps, buffer, size);
+vtctx->reconfig_needed = true;
+vtctx->sps_len = size;
+}
+}
+
+// pass-through new PPS to the decoder
+return ff_videotoolbox_h264_decode_slice(avctx, buffer, size);
+}
+
 int ff_videotoolbox_h264_decode_slice(AVCodecContext *avctx,
   const uint8_t *buffer,
   uint32_t size)
@@ -339,6 +363,7 @@ int ff_videotoolbox_uninit(AVCodecContext *avctx)
 VTContext *vtctx = avctx->internal->hwaccel_priv_data;
 if (vtctx) {
 av_freep(&vtctx->bitstream);
+av_freep(&vtctx->sps);
 if (vtctx->frame)
 CVPixelBufferRelease(vtctx->frame);
 }
@@ -591,17 +616,30 @@ static int videotoolbox_common_end_frame(AVCodecContext 
*avctx, AVFrame *frame)
 AVVideotoolboxContext *videotoolbox = videotoolbox_get_context(avctx);
 VTContext *vtctx = avctx->internal->hwaccel_priv_data;
 
-if (!videotoolbox->session || !vtctx->bitstream)
+if (vtctx->reconfig_needed == true) {
+vtctx->reconfig_needed = false;
+av_log(avctx, AV_LOG_VERBOSE, "VideoToolbox decoder needs reconfig, 
restarting..\n");
+videotoolbox_stop(avctx);
+if (videotoolbox_start(avctx) != 0) {
+return AVERROR_EXTERNAL;
+}
+}
+
+if (!videotoolbox->session || !vtctx->bitstream || !vtctx->bitstream_size)
 return AVERROR_INVALIDDATA;
 
 status = videotoolbox_session_decode_frame(avctx);
 if (status != noErr) {
+if (status == kVTVideoDecoderMalfunctionErr || status == 
kVTInvalidSessionErr)
+vtctx->reconfig_needed = true;
 av_log(avctx, AV_LOG_ERROR, "Failed to decode frame (%s, %d)\n", 
videotoolbox_error_string(status), (int)status);
 return AVERROR_UNKNOWN;
 }
 
-if (!vtctx->frame)
+if (!vtctx->frame) {
+vtctx->reconfig_needed = true;
 return AVERROR_UNKNOWN;
+}
 
 return videotoolbox_buffer_create(avctx, frame);
 }
@@ -1018,6 +1056,7 @@ AVHWAccel ff_h264_videotoolbox_hwaccel = {
 .alloc_frame= ff_videotoolbox_alloc_frame,
 .start_frame= ff_videotoolbox_h264_start_frame,
 .decode_slice   = ff_videotoolbox_h264_decode_slice,
+.decode_params  = videotoolbox_h264_decode_params,
 .end_frame  = videotoolbox_h264_end_frame,
 .frame_params   = videotoolbox_frame_params,
 .init   = videotoolbox_common_init,
diff --git a/libavcodec/vt_internal.h b/libavcodec/vt_internal.h
index 607dd7a6d0..fc27dad9f9 100644
--- a/libavcodec/vt_internal.h
+++ b/

[FFmpeg-cvslog] avcodec/h264, videotoolbox: return AVERROR_INVALIDDATA when no frames are produced

2017-11-13 Thread Aman Gupta
ffmpeg | branch: master | Aman Gupta  | Mon Sep 25 16:45:53 2017 
-0700| [dad42bc5a134f60164eab2dfb0892b761603e1e1] | committer: Aman Gupta

avcodec/h264, videotoolbox: return AVERROR_INVALIDDATA when no frames are 
produced

The only reason videotoolbox wouldn't produce frames is if the data fed
to it was invalid, so returning AVERROR_INVALIDDATA makes sense here.

Further, it means AVERROR_EXTERNAL can be used in further commits to signal
fatal VideoToolbox errors, letting the user know that they need to fallback to
another decoder.

Signed-off-by: Aman Gupta 
Reviewed-by: Michael Niedermayer 

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

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

diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index aed23c4fba..517f6acc13 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -824,7 +824,7 @@ static int output_frame(H264Context *h, AVFrame *dst, 
H264Picture *srcp)
 int ret;
 
 if (src->format == AV_PIX_FMT_VIDEOTOOLBOX && src->buf[0]->size == 1)
-return AVERROR_EXTERNAL;
+return AVERROR_INVALIDDATA;
 
 ret = av_frame_ref(dst, src);
 if (ret < 0)

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


[FFmpeg-cvslog] avcodec/videotoolbox: extract videotoolbox_{start,stop} helpers

2017-11-13 Thread Aman Gupta
ffmpeg | branch: master | Aman Gupta  | Mon Sep 25 16:32:11 2017 
-0700| [b4b177049a886b67f8da84da95f55b81e11ba165] | committer: Aman Gupta

avcodec/videotoolbox: extract videotoolbox_{start,stop} helpers

These helpers will be used in later commits to automatically restart
the decoder session when SPS changes are encountered.

Signed-off-by: Aman Gupta 

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

 libavcodec/videotoolbox.c | 22 +++---
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index 5011f5201d..f3d5f0aa4d 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -756,7 +756,7 @@ static CMVideoFormatDescriptionRef 
videotoolbox_format_desc_create(CMVideoCodecT
 return cm_fmt_desc;
 }
 
-static int videotoolbox_default_init(AVCodecContext *avctx)
+static int videotoolbox_start(AVCodecContext *avctx)
 {
 AVVideotoolboxContext *videotoolbox = videotoolbox_get_context(avctx);
 OSStatus status;
@@ -794,6 +794,11 @@ static int videotoolbox_default_init(AVCodecContext *avctx)
 
 decoder_spec = 
videotoolbox_decoder_config_create(videotoolbox->cm_codec_type, avctx);
 
+if (!decoder_spec) {
+av_log(avctx, AV_LOG_ERROR, "decoder specification creation failed\n");
+return -1;
+}
+
 videotoolbox->cm_fmt_desc = 
videotoolbox_format_desc_create(videotoolbox->cm_codec_type,
 decoder_spec,
 avctx->width,
@@ -846,18 +851,21 @@ static int videotoolbox_default_init(AVCodecContext 
*avctx)
 }
 }
 
-static void videotoolbox_default_free(AVCodecContext *avctx)
+static void videotoolbox_stop(AVCodecContext *avctx)
 {
 AVVideotoolboxContext *videotoolbox = videotoolbox_get_context(avctx);
 if (!videotoolbox)
 return;
 
-if (videotoolbox->cm_fmt_desc)
+if (videotoolbox->cm_fmt_desc) {
 CFRelease(videotoolbox->cm_fmt_desc);
+videotoolbox->cm_fmt_desc = NULL;
+}
 
 if (videotoolbox->session) {
 VTDecompressionSessionInvalidate(videotoolbox->session);
 CFRelease(videotoolbox->session);
+videotoolbox->session = NULL;
 }
 }
 
@@ -870,7 +878,7 @@ static int videotoolbox_uninit(AVCodecContext *avctx)
 ff_videotoolbox_uninit(avctx);
 
 if (vtctx->vt_ctx)
-videotoolbox_default_free(avctx);
+videotoolbox_stop(avctx);
 
 av_buffer_unref(&vtctx->cached_hw_frames_ctx);
 av_freep(&vtctx->vt_ctx);
@@ -936,7 +944,7 @@ static int videotoolbox_common_init(AVCodecContext *avctx)
 goto fail;
 }
 
-err = videotoolbox_default_init(avctx);
+err = videotoolbox_start(avctx);
 if (err < 0)
 goto fail;
 
@@ -1072,13 +1080,13 @@ int av_videotoolbox_default_init2(AVCodecContext 
*avctx, AVVideotoolboxContext *
 avctx->hwaccel_context = vtctx ?: av_videotoolbox_alloc_context();
 if (!avctx->hwaccel_context)
 return AVERROR(ENOMEM);
-return videotoolbox_default_init(avctx);
+return videotoolbox_start(avctx);
 }
 
 void av_videotoolbox_default_free(AVCodecContext *avctx)
 {
 
-videotoolbox_default_free(avctx);
+videotoolbox_stop(avctx);
 av_freep(&avctx->hwaccel_context);
 }
 #endif /* CONFIG_VIDEOTOOLBOX */

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


[FFmpeg-cvslog] avcodec/videotoolbox: print descriptive errors on decode failures

2017-11-13 Thread Aman Gupta
ffmpeg | branch: master | Aman Gupta  | Mon Sep 25 16:44:47 2017 
-0700| [6515e2834a51e651aa9855d071291eeb8256dbb6] | committer: Aman Gupta

avcodec/videotoolbox: print descriptive errors on decode failures

Signed-off-by: Aman Gupta 

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

 libavcodec/videotoolbox.c | 20 
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index 67b7429274..4fe89a27e9 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -572,9 +572,22 @@ static OSStatus 
videotoolbox_session_decode_frame(AVCodecContext *avctx)
 return status;
 }
 
+static const char *videotoolbox_error_string(OSStatus status)
+{
+switch (status) {
+case kVTVideoDecoderBadDataErr:
+return "bad data";
+case kVTVideoDecoderMalfunctionErr:
+return "decoder malfunction";
+case kVTInvalidSessionErr:
+return "invalid session";
+}
+return "unknown";
+}
+
 static int videotoolbox_common_end_frame(AVCodecContext *avctx, AVFrame *frame)
 {
-int status;
+OSStatus status;
 AVVideotoolboxContext *videotoolbox = videotoolbox_get_context(avctx);
 VTContext *vtctx = avctx->internal->hwaccel_priv_data;
 
@@ -582,9 +595,8 @@ static int videotoolbox_common_end_frame(AVCodecContext 
*avctx, AVFrame *frame)
 return AVERROR_INVALIDDATA;
 
 status = videotoolbox_session_decode_frame(avctx);
-
-if (status) {
-av_log(avctx, AV_LOG_ERROR, "Failed to decode frame (%d)\n", status);
+if (status != noErr) {
+av_log(avctx, AV_LOG_ERROR, "Failed to decode frame (%s, %d)\n", 
videotoolbox_error_string(status), (int)status);
 return AVERROR_UNKNOWN;
 }
 

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


[FFmpeg-cvslog] avcodec/h264: implement new decode_params callback for PPS/SPS

2017-11-13 Thread Aman Gupta
ffmpeg | branch: master | Aman Gupta  | Fri Nov 10 12:18:35 2017 
-0800| [872add08540fb36b2d2ca75df86da7d8ac9579a1] | committer: Aman Gupta

avcodec/h264: implement new decode_params callback for PPS/SPS

This callback will be used by the VideoToolbox H264 hwaccel so that it
can receive SPS and PPS NALUs. VideoToolbox requires PPS changes to be
fed into the decoder session, and for the session to be recreated when
the SPS changes.

Signed-off-by: Aman Gupta 

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

 libavcodec/h264dec.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 517f6acc13..be187eb5f4 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -713,6 +713,14 @@ static int decode_nal_units(H264Context *h, const uint8_t 
*buf, int buf_size)
 break;
 case H264_NAL_SPS: {
 GetBitContext tmp_gb = nal->gb;
+if (avctx->hwaccel && avctx->hwaccel->decode_params) {
+ret = avctx->hwaccel->decode_params(avctx,
+nal->type,
+nal->raw_data,
+nal->raw_size);
+if (ret < 0)
+goto end;
+}
 if (ff_h264_decode_seq_parameter_set(&tmp_gb, avctx, &h->ps, 0) >= 
0)
 break;
 av_log(h->avctx, AV_LOG_DEBUG,
@@ -724,6 +732,14 @@ static int decode_nal_units(H264Context *h, const uint8_t 
*buf, int buf_size)
 break;
 }
 case H264_NAL_PPS:
+if (avctx->hwaccel && avctx->hwaccel->decode_params) {
+ret = avctx->hwaccel->decode_params(avctx,
+nal->type,
+nal->raw_data,
+nal->raw_size);
+if (ret < 0)
+goto end;
+}
 ret = ff_h264_decode_picture_parameter_set(&nal->gb, avctx, &h->ps,
nal->size_bits);
 if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))

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


[FFmpeg-cvslog] avcodec/hevc: implement new decode_params callback for VideoToolbox

2017-11-13 Thread Aman Gupta
ffmpeg | branch: master | Aman Gupta  | Fri Nov 10 12:31:56 2017 
-0800| [3a91b3ae742425c25b9b80708f3c111537e570d3] | committer: Aman Gupta

avcodec/hevc: implement new decode_params callback for VideoToolbox

Signed-off-by: Aman Gupta 

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

 libavcodec/hevcdec.c | 32 
 1 file changed, 32 insertions(+)

diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 6dd6d0c53c..75960912b1 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -2824,23 +2824,55 @@ static int decode_nal_unit(HEVCContext *s, const 
H2645NAL *nal)
 
 switch (s->nal_unit_type) {
 case HEVC_NAL_VPS:
+if (s->avctx->hwaccel && s->avctx->hwaccel->decode_params) {
+ret = s->avctx->hwaccel->decode_params(s->avctx,
+   nal->type,
+   nal->raw_data,
+   nal->raw_size);
+if (ret < 0)
+goto fail;
+}
 ret = ff_hevc_decode_nal_vps(gb, s->avctx, &s->ps);
 if (ret < 0)
 goto fail;
 break;
 case HEVC_NAL_SPS:
+if (s->avctx->hwaccel && s->avctx->hwaccel->decode_params) {
+ret = s->avctx->hwaccel->decode_params(s->avctx,
+   nal->type,
+   nal->raw_data,
+   nal->raw_size);
+if (ret < 0)
+goto fail;
+}
 ret = ff_hevc_decode_nal_sps(gb, s->avctx, &s->ps,
  s->apply_defdispwin);
 if (ret < 0)
 goto fail;
 break;
 case HEVC_NAL_PPS:
+if (s->avctx->hwaccel && s->avctx->hwaccel->decode_params) {
+ret = s->avctx->hwaccel->decode_params(s->avctx,
+   nal->type,
+   nal->raw_data,
+   nal->raw_size);
+if (ret < 0)
+goto fail;
+}
 ret = ff_hevc_decode_nal_pps(gb, s->avctx, &s->ps);
 if (ret < 0)
 goto fail;
 break;
 case HEVC_NAL_SEI_PREFIX:
 case HEVC_NAL_SEI_SUFFIX:
+if (s->avctx->hwaccel && s->avctx->hwaccel->decode_params) {
+ret = s->avctx->hwaccel->decode_params(s->avctx,
+   nal->type,
+   nal->raw_data,
+   nal->raw_size);
+if (ret < 0)
+goto fail;
+}
 ret = ff_hevc_decode_nal_sei(gb, s->avctx, &s->sei, &s->ps, 
s->nal_unit_type);
 if (ret < 0)
 goto fail;

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


[FFmpeg-cvslog] avcodec/videotoolboxenc: remove spurious warning

2017-11-13 Thread Aman Gupta
ffmpeg | branch: master | Aman Gupta  | Mon Sep 25 16:15:09 2017 
-0700| [c8b1a151cef685496b8171a5236f099e137c3a37] | committer: Aman Gupta

avcodec/videotoolboxenc: remove spurious warning

Signed-off-by: Aman Gupta 

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

 libavcodec/videotoolboxenc.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 93338eabde..086beb41fc 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -1939,8 +1939,6 @@ static int get_cv_pixel_info(
"Color range not set for %s. Using MPEG range.\n",
av_get_pix_fmt_name(av_format));
 }
-
-av_log(avctx, AV_LOG_WARNING, "");
 }
 
 switch (av_format) {

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


[FFmpeg-cvslog] avcodec/videotoolbox: remove unnecessary if statement

2017-11-13 Thread Aman Gupta
ffmpeg | branch: master | Aman Gupta  | Fri Nov 10 11:52:38 2017 
-0800| [bd2d70c0b8f416cf1f70e910ed675c0d46fb0010] | committer: Aman Gupta

avcodec/videotoolbox: remove unnecessary if statement

Cosmetic change only.

Signed-off-by: Aman Gupta 

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

 libavcodec/videotoolbox.c | 68 +++
 1 file changed, 33 insertions(+), 35 deletions(-)

diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index 7e915a4e83..1307e93bcc 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -702,45 +702,43 @@ static CFDictionaryRef 
videotoolbox_decoder_config_create(CMVideoCodecType codec
  
kVTVideoDecoderSpecification_RequireHardwareAcceleratedVideoDecoder,
  kCFBooleanTrue);
 
-if (1) {
-CFMutableDictionaryRef avc_info;
-CFDataRef data = NULL;
-
-avc_info = CFDictionaryCreateMutable(kCFAllocatorDefault,
- 1,
- &kCFTypeDictionaryKeyCallBacks,
- &kCFTypeDictionaryValueCallBacks);
-
-switch (codec_type) {
-case kCMVideoCodecType_MPEG4Video :
-if (avctx->extradata_size)
-data = videotoolbox_esds_extradata_create(avctx);
-if (data)
-CFDictionarySetValue(avc_info, CFSTR("esds"), data);
-break;
-case kCMVideoCodecType_H264 :
-data = ff_videotoolbox_avcc_extradata_create(avctx);
-if (data)
-CFDictionarySetValue(avc_info, CFSTR("avcC"), data);
-break;
-case kCMVideoCodecType_HEVC :
-data = ff_videotoolbox_hvcc_extradata_create(avctx);
-if (data)
-CFDictionarySetValue(avc_info, CFSTR("hvcC"), data);
-break;
-default:
-break;
-}
+CFMutableDictionaryRef avc_info;
+CFDataRef data = NULL;
 
-CFDictionarySetValue(config_info,
-kCMFormatDescriptionExtension_SampleDescriptionExtensionAtoms,
-avc_info);
+avc_info = CFDictionaryCreateMutable(kCFAllocatorDefault,
+ 1,
+ &kCFTypeDictionaryKeyCallBacks,
+ &kCFTypeDictionaryValueCallBacks);
 
+switch (codec_type) {
+case kCMVideoCodecType_MPEG4Video :
+if (avctx->extradata_size)
+data = videotoolbox_esds_extradata_create(avctx);
 if (data)
-CFRelease(data);
-
-CFRelease(avc_info);
+CFDictionarySetValue(avc_info, CFSTR("esds"), data);
+break;
+case kCMVideoCodecType_H264 :
+data = ff_videotoolbox_avcc_extradata_create(avctx);
+if (data)
+CFDictionarySetValue(avc_info, CFSTR("avcC"), data);
+break;
+case kCMVideoCodecType_HEVC :
+data = ff_videotoolbox_hvcc_extradata_create(avctx);
+if (data)
+CFDictionarySetValue(avc_info, CFSTR("hvcC"), data);
+break;
+default:
+break;
 }
+
+CFDictionarySetValue(config_info,
+kCMFormatDescriptionExtension_SampleDescriptionExtensionAtoms,
+avc_info);
+
+if (data)
+CFRelease(data);
+
+CFRelease(avc_info);
 return config_info;
 }
 

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


[FFmpeg-cvslog] avcodec/videotoolbox: pass through hevc param changes to the decoder

2017-11-13 Thread Aman Gupta
ffmpeg | branch: master | Aman Gupta  | Fri Nov 10 12:34:41 2017 
-0800| [68ef503bb5f9f8bd4460191d6a9c9e2ec4179a26] | committer: Aman Gupta

avcodec/videotoolbox: pass through hevc param changes to the decoder

This includes the SEI_PREFIX/SEI_SUFFIX NALUs, which can contain
updates like HEVC_SEI_TYPE_ACTIVE_PARAMETER_SETS. Previously, hevc
samples with this SEI present would not playback correctly.

See for example https://github.com/lhc7/iina/issues/1123

Signed-off-by: Aman Gupta 

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

 libavcodec/videotoolbox.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index 1307e93bcc..3c9077bf34 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -654,6 +654,14 @@ static int videotoolbox_h264_end_frame(AVCodecContext 
*avctx)
 return ret;
 }
 
+static int videotoolbox_hevc_decode_params(AVCodecContext *avctx,
+   int type,
+   const uint8_t *buffer,
+   uint32_t size)
+{
+return ff_videotoolbox_h264_decode_slice(avctx, buffer, size);
+}
+
 static int videotoolbox_hevc_end_frame(AVCodecContext *avctx)
 {
 HEVCContext *h = avctx->priv_data;
@@ -1040,6 +1048,7 @@ AVHWAccel ff_hevc_videotoolbox_hwaccel = {
 .alloc_frame= ff_videotoolbox_alloc_frame,
 .start_frame= ff_videotoolbox_h264_start_frame,
 .decode_slice   = ff_videotoolbox_h264_decode_slice,
+.decode_params  = videotoolbox_hevc_decode_params,
 .end_frame  = videotoolbox_hevc_end_frame,
 .frame_params   = videotoolbox_frame_params,
 .init   = videotoolbox_common_init,

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


[FFmpeg-cvslog] avcodec/videotoolbox: fix whitespace

2017-11-13 Thread Aman Gupta
ffmpeg | branch: master | Aman Gupta  | Fri Nov 10 12:02:23 2017 
-0800| [5e577c586b7825b4addd1d38cf20688d7d50010d] | committer: Aman Gupta

avcodec/videotoolbox: fix whitespace

Signed-off-by: Aman Gupta 

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

 libavcodec/videotoolbox.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index 3c9077bf34..792db270b4 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -88,7 +88,7 @@ int ff_videotoolbox_alloc_frame(AVCodecContext *avctx, 
AVFrame *frame)
 
 CFDataRef ff_videotoolbox_avcc_extradata_create(AVCodecContext *avctx)
 {
-H264Context *h = avctx->priv_data;
+H264Context *h = avctx->priv_data;
 CFDataRef data = NULL;
 uint8_t *p;
 int vt_extradata_size = 6 + 2 + h->ps.sps->data_size + 3 + 
h->ps.pps->data_size;
@@ -897,7 +897,7 @@ static int videotoolbox_start(AVCodecContext *avctx)
 case kVTVideoDecoderMalfunctionErr:
 av_log(avctx, AV_LOG_VERBOSE, "VideoToolbox malfunction.\n");
 return AVERROR(EINVAL);
-case kVTVideoDecoderBadDataErr :
+case kVTVideoDecoderBadDataErr:
 av_log(avctx, AV_LOG_VERBOSE, "VideoToolbox reported invalid data.\n");
 return AVERROR_INVALIDDATA;
 case 0:

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


[FFmpeg-cvslog] avcodec/videotoolbox: reorder functions to avoid forward declarations

2017-11-13 Thread Aman Gupta
ffmpeg | branch: master | Aman Gupta  | Mon Nov 13 15:06:40 2017 
-0800| [b7f963cd709a89156fb0f094c232fe1eacd6] | committer: Aman Gupta

avcodec/videotoolbox: reorder functions to avoid forward declarations

Cosmetic change only.

Signed-off-by: Aman Gupta 

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

 libavcodec/videotoolbox.c | 301 +++---
 1 file changed, 149 insertions(+), 152 deletions(-)

diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index 792db270b4..4547ffef34 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -42,9 +42,6 @@ enum { kCMVideoCodecType_HEVC = 'hvc1' };
 
 #define VIDEOTOOLBOX_ESDS_EXTRADATA_PADDING  12
 
-static void videotoolbox_stop(AVCodecContext *avctx);
-static int videotoolbox_start(AVCodecContext *avctx);
-
 static void videotoolbox_buffer_release(void *opaque, uint8_t *data)
 {
 CVPixelBufferRef cv_buffer = (CVImageBufferRef)data;
@@ -597,105 +594,67 @@ static OSStatus 
videotoolbox_session_decode_frame(AVCodecContext *avctx)
 return status;
 }
 
-static const char *videotoolbox_error_string(OSStatus status)
-{
-switch (status) {
-case kVTVideoDecoderBadDataErr:
-return "bad data";
-case kVTVideoDecoderMalfunctionErr:
-return "decoder malfunction";
-case kVTInvalidSessionErr:
-return "invalid session";
-}
-return "unknown";
-}
-
-static int videotoolbox_common_end_frame(AVCodecContext *avctx, AVFrame *frame)
+static CMVideoFormatDescriptionRef 
videotoolbox_format_desc_create(CMVideoCodecType codec_type,
+   
CFDictionaryRef decoder_spec,
+   int width,
+   int height)
 {
+CMFormatDescriptionRef cm_fmt_desc;
 OSStatus status;
-AVVideotoolboxContext *videotoolbox = videotoolbox_get_context(avctx);
-VTContext *vtctx = avctx->internal->hwaccel_priv_data;
 
-if (vtctx->reconfig_needed == true) {
-vtctx->reconfig_needed = false;
-av_log(avctx, AV_LOG_VERBOSE, "VideoToolbox decoder needs reconfig, 
restarting..\n");
-videotoolbox_stop(avctx);
-if (videotoolbox_start(avctx) != 0) {
-return AVERROR_EXTERNAL;
-}
-}
-
-if (!videotoolbox->session || !vtctx->bitstream || !vtctx->bitstream_size)
-return AVERROR_INVALIDDATA;
-
-status = videotoolbox_session_decode_frame(avctx);
-if (status != noErr) {
-if (status == kVTVideoDecoderMalfunctionErr || status == 
kVTInvalidSessionErr)
-vtctx->reconfig_needed = true;
-av_log(avctx, AV_LOG_ERROR, "Failed to decode frame (%s, %d)\n", 
videotoolbox_error_string(status), (int)status);
-return AVERROR_UNKNOWN;
-}
-
-if (!vtctx->frame) {
-vtctx->reconfig_needed = true;
-return AVERROR_UNKNOWN;
-}
-
-return videotoolbox_buffer_create(avctx, frame);
-}
+status = CMVideoFormatDescriptionCreate(kCFAllocatorDefault,
+codec_type,
+width,
+height,
+decoder_spec, // Dictionary of 
extension
+&cm_fmt_desc);
 
-static int videotoolbox_h264_end_frame(AVCodecContext *avctx)
-{
-H264Context *h = avctx->priv_data;
-AVFrame *frame = h->cur_pic_ptr->f;
-VTContext *vtctx = avctx->internal->hwaccel_priv_data;
-int ret = videotoolbox_common_end_frame(avctx, frame);
-vtctx->bitstream_size = 0;
-return ret;
-}
+if (status)
+return NULL;
 
-static int videotoolbox_hevc_decode_params(AVCodecContext *avctx,
-   int type,
-   const uint8_t *buffer,
-   uint32_t size)
-{
-return ff_videotoolbox_h264_decode_slice(avctx, buffer, size);
+return cm_fmt_desc;
 }
 
-static int videotoolbox_hevc_end_frame(AVCodecContext *avctx)
+static CFDictionaryRef videotoolbox_buffer_attributes_create(int width,
+ int height,
+ OSType pix_fmt)
 {
-HEVCContext *h = avctx->priv_data;
-AVFrame *frame = h->ref->frame;
-VTContext *vtctx = avctx->internal->hwaccel_priv_data;
-int ret;
-
-ret = videotoolbox_common_end_frame(avctx, frame);
-vtctx->bitstream_size = 0;
-return ret;
-}
+CFMutableDictionaryRef buffer_attributes;
+CFMutableDictionaryRef io_surface_properties;
+CFNumberRef cv_pix_fmt;
+CFNumberRef w;
+CFNumberRef h;
 
-static int videotoolbox_mpeg_start_frame(AVCodecContext 

[FFmpeg-cvslog] avcodec/videotoolbox: fix opaque_ref handling

2017-11-13 Thread wm4
ffmpeg | branch: master | wm4  | Tue Oct 31 15:15:27 
2017 +0100| [9283a4f19b762b25bc8e5e8f402fefb9097a1397] | committer: Aman Gupta

avcodec/videotoolbox: fix opaque_ref handling

This is a partial fix - to fix videotoolbox fully (with multithreaded
hwaccel decoding), much more work would be required.

Before this change, an assertion failure would trigger:

  $ ffmpeg -hwaccel videotoolbox -hwaccel_output_format videotoolbox_vld -i 
h264.ts -f null -y /dev/null
  Assertion (frame->private_ref && frame->private_ref->size == 
sizeof(FrameDecodeData)) || !(avctx->codec->capabilities & (1 << 1)) failed at 
libavcodec/decode.c:620

Signed-off-by: Aman Gupta 

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

 libavcodec/videotoolbox.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index 4547ffef34..9eeada30ba 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -27,6 +27,7 @@
 #include "libavutil/avutil.h"
 #include "libavutil/hwcontext.h"
 #include "bytestream.h"
+#include "decode.h"
 #include "h264dec.h"
 #include "hevcdec.h"
 #include "mpegvideo.h"
@@ -70,6 +71,10 @@ static int videotoolbox_buffer_copy(VTContext *vtctx,
 
 int ff_videotoolbox_alloc_frame(AVCodecContext *avctx, AVFrame *frame)
 {
+int ret = ff_attach_decode_data(frame);
+if (ret < 0)
+return ret;
+
 frame->width  = avctx->width;
 frame->height = avctx->height;
 frame->format = avctx->pix_fmt;

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


[FFmpeg-cvslog] avutil/crc: use ff_thread_once at av_crc_get_table

2017-11-13 Thread Muhammad Faiz
ffmpeg | branch: master | Muhammad Faiz  | Tue Oct 24 
16:23:28 2017 +0700| [8329ae781a75c1b665fc2ffe2e08be2c8207419e] | committer: 
Muhammad Faiz

avutil/crc: use ff_thread_once at av_crc_get_table

Fix tsan warnings.

Signed-off-by: Muhammad Faiz 

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

 libavutil/crc.c | 49 +
 1 file changed, 29 insertions(+), 20 deletions(-)

diff --git a/libavutil/crc.c b/libavutil/crc.c
index 495732b163..d44550c9c0 100644
--- a/libavutil/crc.c
+++ b/libavutil/crc.c
@@ -20,6 +20,8 @@
 
 #include "config.h"
 
+#include "thread.h"
+#include "avassert.h"
 #include "bswap.h"
 #include "common.h"
 #include "crc.h"
@@ -291,20 +293,24 @@ static const AVCRC av_crc_table[AV_CRC_MAX][257] = {
 #else
 #define CRC_TABLE_SIZE 1024
 #endif
-static struct {
-uint8_t  le;
-uint8_t  bits;
-uint32_t poly;
-} av_crc_table_params[AV_CRC_MAX] = {
-[AV_CRC_8_ATM]  = { 0,  8,   0x07 },
-[AV_CRC_16_ANSI]= { 0, 16, 0x8005 },
-[AV_CRC_16_CCITT]   = { 0, 16, 0x1021 },
-[AV_CRC_24_IEEE]= { 0, 24,   0x864CFB },
-[AV_CRC_32_IEEE]= { 0, 32, 0x04C11DB7 },
-[AV_CRC_32_IEEE_LE] = { 1, 32, 0xEDB88320 },
-[AV_CRC_16_ANSI_LE] = { 1, 16, 0xA001 },
-};
 static AVCRC av_crc_table[AV_CRC_MAX][CRC_TABLE_SIZE];
+
+#define DECLARE_CRC_INIT_TABLE_ONCE(id, le, bits, poly)
   \
+static AVOnce id ## _once_control = AV_ONCE_INIT;  
   \
+static void id ## _init_table_once(void)   
   \
+{  
   \
+av_assert0(av_crc_init(av_crc_table[id], le, bits, poly, 
sizeof(av_crc_table[id])) >= 0); \
+}
+
+#define CRC_INIT_TABLE_ONCE(id) ff_thread_once(&id ## _once_control, id ## 
_init_table_once)
+
+DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_8_ATM,  0,  8,   0x07)
+DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_16_ANSI,0, 16, 0x8005)
+DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_16_CCITT,   0, 16, 0x1021)
+DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_24_IEEE,0, 24,   0x864CFB)
+DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_32_IEEE,0, 32, 0x04C11DB7)
+DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_32_IEEE_LE, 1, 32, 0xEDB88320)
+DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_16_ANSI_LE, 1, 16, 0xA001)
 #endif
 
 int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size)
@@ -343,13 +349,16 @@ int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t 
poly, int ctx_size)
 const AVCRC *av_crc_get_table(AVCRCId crc_id)
 {
 #if !CONFIG_HARDCODED_TABLES
-if (!av_crc_table[crc_id][FF_ARRAY_ELEMS(av_crc_table[crc_id]) - 1])
-if (av_crc_init(av_crc_table[crc_id],
-av_crc_table_params[crc_id].le,
-av_crc_table_params[crc_id].bits,
-av_crc_table_params[crc_id].poly,
-sizeof(av_crc_table[crc_id])) < 0)
-return NULL;
+switch (crc_id) {
+case AV_CRC_8_ATM:  CRC_INIT_TABLE_ONCE(AV_CRC_8_ATM); break;
+case AV_CRC_16_ANSI:CRC_INIT_TABLE_ONCE(AV_CRC_16_ANSI); break;
+case AV_CRC_16_CCITT:   CRC_INIT_TABLE_ONCE(AV_CRC_16_CCITT); break;
+case AV_CRC_24_IEEE:CRC_INIT_TABLE_ONCE(AV_CRC_24_IEEE); break;
+case AV_CRC_32_IEEE:CRC_INIT_TABLE_ONCE(AV_CRC_32_IEEE); break;
+case AV_CRC_32_IEEE_LE: CRC_INIT_TABLE_ONCE(AV_CRC_32_IEEE_LE); break;
+case AV_CRC_16_ANSI_LE: CRC_INIT_TABLE_ONCE(AV_CRC_16_ANSI_LE); break;
+default: av_assert0(0);
+}
 #endif
 return av_crc_table[crc_id];
 }

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


[FFmpeg-cvslog] avformat/hlsenc: write fmp4 init header after first AV frame

2017-11-13 Thread Steven Liu
ffmpeg | branch: master | Steven Liu  | Tue Nov 14 
10:31:26 2017 +0800| [880b299381de1e66f8248abd6c320c7c490466a2] | committer: 
Steven Liu

avformat/hlsenc: write fmp4 init header after first AV frame

fix ticket id: 6825

Signed-off-by: Steven Liu 
Tested-by: Aman Gupta 

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

 libavformat/hlsenc.c | 29 ++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index b571772f60..e0cef8b879 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -108,6 +108,9 @@ typedef struct HLSContext {
 uint32_t start_sequence_source_type;  // enum StartSequenceSourceType
 AVOutputFormat *oformat;
 AVOutputFormat *vtt_oformat;
+AVIOContext *out;
+int packets_written;
+int init_range_length;
 
 AVFormatContext *avf;
 AVFormatContext *vtt_avf;
@@ -598,6 +601,7 @@ static int hls_mux_init(AVFormatContext *s)
 st->time_base = s->streams[i]->time_base;
 av_dict_copy(&st->metadata, s->streams[i]->metadata, 0);
 }
+hls->packets_written = 1;
 hls->start_pos = 0;
 hls->new_start = 1;
 hls->fmp4_init_mode = 0;
@@ -607,9 +611,14 @@ static int hls_mux_init(AVFormatContext *s)
 av_log(s, AV_LOG_WARNING, "Multi-file byterange mode is currently 
unsupported in the HLS muxer.\n");
 return AVERROR_PATCHWELCOME;
 }
+hls->packets_written = 0;
+hls->init_range_length = 0;
 hls->fmp4_init_mode = !byterange_mode;
 set_http_options(s, &options, hls);
-if ((ret = s->io_open(s, &oc->pb, hls->base_output_dirname, 
AVIO_FLAG_WRITE, &options)) < 0) {
+if ((ret = avio_open_dyn_buf(&oc->pb)) < 0)
+return ret;
+
+if ((ret = s->io_open(s, &hls->out, hls->base_output_dirname, 
AVIO_FLAG_WRITE, &options)) < 0) {
 av_log(s, AV_LOG_ERROR, "Failed to open segment '%s'\n", 
hls->fmp4_init_filename);
 return ret;
 }
@@ -634,6 +643,7 @@ static int hls_mux_init(AVFormatContext *s)
 av_dict_free(&options);
 return AVERROR(EINVAL);
 }
+avio_flush(oc->pb);
 av_dict_free(&options);
 }
 return 0;
@@ -1600,6 +1610,8 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 int is_ref_pkt = 1;
 int ret = 0, can_split = 1;
 int stream_index = 0;
+int range_length = 0;
+uint8_t *buffer = NULL;
 
 if (hls->sequence - hls->nb_entries > hls->start_sequence && 
hls->init_time > 0) {
 /* reset end_pts, hls->recording_time at end of the init hls list */
@@ -1645,7 +1657,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 }
 
 }
-if (hls->fmp4_init_mode || can_split && av_compare_ts(pkt->pts - 
hls->start_pts, st->time_base,
+if (hls->packets_written && can_split && av_compare_ts(pkt->pts - 
hls->start_pts, st->time_base,
end_pts, AV_TIME_BASE_Q) >= 0) {
 int64_t new_start_pos;
 char *old_filename = av_strdup(hls->avf->filename);
@@ -1661,7 +1673,17 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 hls->size = new_start_pos - hls->start_pos;
 
 if (!byterange_mode) {
-ff_format_io_close(s, &oc->pb);
+if (hls->segment_type == SEGMENT_TYPE_FMP4 && 
!hls->init_range_length) {
+avio_flush(oc->pb);
+range_length = avio_close_dyn_buf(oc->pb, &buffer);
+avio_write(hls->out, buffer, range_length);
+hls->init_range_length = range_length;
+avio_open_dyn_buf(&oc->pb);
+hls->packets_written = 0;
+ff_format_io_close(s, &hls->out);
+} else {
+ff_format_io_close(s, &oc->pb);
+}
 if (hls->vtt_avf) {
 ff_format_io_close(s, &hls->vtt_avf->pb);
 }
@@ -1719,6 +1741,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 }
 }
 
+hls->packets_written++;
 ret = ff_write_chained(oc, stream_index, pkt, s, 0);
 
 return ret;

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


[FFmpeg-cvslog] avcodec/x86/mpegvideodsp: Fix signedness bug in need_emu

2017-11-13 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Mon 
Nov 13 20:47:48 2017 +0100| [58cf31cee7a456057f337b3102a03206d833d5e8] | 
committer: Michael Niedermayer

avcodec/x86/mpegvideodsp: Fix signedness bug in need_emu

Fixes: out of array read
Fixes: 3516/attachment-311488.dat

Found-by: Insu Yun, Georgia Tech.
Tested-by: wuni...@gmail.com
Signed-off-by: Michael Niedermayer 

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

 libavcodec/x86/mpegvideodsp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavcodec/x86/mpegvideodsp.c b/libavcodec/x86/mpegvideodsp.c
index e0498f3849..6009b64e07 100644
--- a/libavcodec/x86/mpegvideodsp.c
+++ b/libavcodec/x86/mpegvideodsp.c
@@ -52,8 +52,9 @@ static void gmc_mmx(uint8_t *dst, uint8_t *src,
 const int dyh = (dyy - (1 << (16 + shift))) * (h - 1);
 const int dxh = dxy * (h - 1);
 const int dyw = dyx * (w - 1);
-int need_emu  =  (unsigned) ix >= width  - w ||
- (unsigned) iy >= height - h;
+int need_emu  =  (unsigned) ix >= width  - w || width < w ||
+ (unsigned) iy >= height - h || height< h
+ ;
 
 if ( // non-constant fullpel offset (3% of blocks)
 ((ox ^ (ox + dxw)) | (ox ^ (ox + dxh)) | (ox ^ (ox + dxw + dxh)) |

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