[FFmpeg-cvslog] aacdec: do not mutate input packet metadata

2017-03-09 Thread wm4
ffmpeg | branch: master | wm4  | Wed Mar  8 12:36:05 
2017 +0100| [fcfc78cbabb6b454aa9e39ad32ae7a766dcf33d8] | committer: wm4

aacdec: do not mutate input packet metadata

Apparently the demuxer outputs the wrong padding for HE-AAC (based on
the raw sample rate, or so). aacdec contains a hack to adjust the muxer
padding accordingly before it's used to trim the decoder output. This
modified the packet side data, which in combination with the old
decoding API would change the packet the user passed to the decoder.
This is clearly not allowed, and it breaks running some gapless fate
tests with "-fflags +keepside" applied (without keepside, the packet
metadata is typically newly allocated, essentially making a copy and not
modifying the user's input packet).

This should probably be fixed in the demuxer (and consequently also the
muxer), but for now only fix the immediate problem.

Regression since 946ed78f5f8 (2012).

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

 libavcodec/aacdec_template.c | 8 ++--
 libavcodec/internal.h| 2 ++
 libavcodec/utils.c   | 4 +++-
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index 4367e74..98a3240 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -3095,12 +3095,8 @@ static int aac_decode_frame_int(AVCodecContext *avctx, 
void *data,
 ac->oc[1].status = OC_LOCKED;
 }
 
-if (multiplier) {
-int side_size;
-const uint8_t *side = av_packet_get_side_data(avpkt, 
AV_PKT_DATA_SKIP_SAMPLES, &side_size);
-if (side && side_size>=4)
-AV_WL32(side, 2*AV_RL32(side));
-}
+if (multiplier)
+avctx->internal->skip_samples_multiplier = 2;
 
 if (!ac->frame->data[0] && samples) {
 av_log(avctx, AV_LOG_ERROR, "no frame data found\n");
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index c92dba4..e3286d2 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -174,6 +174,8 @@ typedef struct AVCodecInternal {
 AVFrame *buffer_frame;
 int draining_done;
 int showed_multi_packet_warning;
+
+int skip_samples_multiplier;
 } AVCodecInternal;
 
 struct AVCodecDefault {
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index db3adb1..3c8a9cc 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1305,6 +1305,8 @@ int attribute_align_arg avcodec_open2(AVCodecContext 
*avctx, const AVCodec *code
 goto free_and_end;
 }
 
+avctx->internal->skip_samples_multiplier = 1;
+
 if (codec->priv_data_size > 0) {
 if (!avctx->priv_data) {
 avctx->priv_data = av_mallocz(codec->priv_data_size);
@@ -2387,7 +2389,7 @@ int attribute_align_arg 
avcodec_decode_audio4(AVCodecContext *avctx,
 
 side= av_packet_get_side_data(avctx->internal->pkt, 
AV_PKT_DATA_SKIP_SAMPLES, &side_size);
 if(side && side_size>=10) {
-avctx->internal->skip_samples = AV_RL32(side);
+avctx->internal->skip_samples = AV_RL32(side) * 
avctx->internal->skip_samples_multiplier;
 discard_padding = AV_RL32(side + 4);
 av_log(avctx, AV_LOG_DEBUG, "skip %d / discard %d samples due to 
side data\n",
avctx->internal->skip_samples, (int)discard_padding);

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


[FFmpeg-cvslog] hls: pass AVFormatContext flags to sub demuxer

2017-03-09 Thread wm4
ffmpeg | branch: master | wm4  | Thu Mar  9 15:43:08 
2017 +0100| [597c6b789efb8d3eec200eb4f38a3d8da591deec] | committer: wm4

hls: pass AVFormatContext flags to sub demuxer

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

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

diff --git a/libavformat/hls.c b/libavformat/hls.c
index 3ae3c7c..c65a9f9 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -1761,6 +1761,7 @@ static int hls_read_header(AVFormatContext *s)
 }
 pls->ctx->pb   = &pls->pb;
 pls->ctx->io_open  = nested_io_open;
+pls->ctx->flags   |= s->flags;
 
 if ((ret = ff_copy_whiteblacklists(pls->ctx, s)) < 0)
 goto fail;

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


[FFmpeg-cvslog] concatdec: pass AVFormatContext flags to sub demuxer

2017-03-09 Thread wm4
ffmpeg | branch: master | wm4  | Thu Mar  9 15:43:00 
2017 +0100| [f5da453b068f55d335ca403d2e2b4dd2ac3d4331] | committer: wm4

concatdec: pass AVFormatContext flags to sub demuxer

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

 libavformat/concatdec.c   |   1 +
 tests/ref/fate/concat-demuxer-simple2-lavf-ts | 192 +-
 2 files changed, 129 insertions(+), 64 deletions(-)

diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index 5cc239a..8649916 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -322,6 +322,7 @@ static int open_file(AVFormatContext *avf, unsigned fileno)
 if (!cat->avf)
 return AVERROR(ENOMEM);
 
+cat->avf->flags |= avf->flags;
 cat->avf->interrupt_callback = avf->interrupt_callback;
 
 if ((ret = ff_copy_whiteblacklists(cat->avf, avf)) < 0)
diff --git a/tests/ref/fate/concat-demuxer-simple2-lavf-ts 
b/tests/ref/fate/concat-demuxer-simple2-lavf-ts
index 4cb9f5c..880f9b7 100644
--- a/tests/ref/fate/concat-demuxer-simple2-lavf-ts
+++ b/tests/ref/fate/concat-demuxer-simple2-lavf-ts
@@ -1,12 +1,21 @@
-video|1|982|0.010911|-2618|-0.029089|3600|0.04|N/A|N/A|24815|564|K_
-video|1|4582|0.050911|982|0.010911|3600|0.04|N/A|N/A|16443|27072|__
-video|1|8182|0.090911|4582|0.050911|3600|0.04|N/A|N/A|14522|44932|__
-video|1|11782|0.130911|8182|0.090911|3600|0.04|N/A|N/A|12636|60536|__
-video|1|15382|0.170911|11782|0.130911|3600|0.04|N/A|N/A|13407|74260|__
-video|1|18982|0.210911|15382|0.170911|3600|0.04|N/A|N/A|13106|88924|__
-video|1|22582|0.250911|18982|0.210911|3600|0.04|N/A|N/A|12769|102836|__
-video|1|26182|0.290911|22582|0.250911|3600|0.04|N/A|N/A|12037|116748|__
-audio|0|0|0.00|0|0.00|2351|0.026122|N/A|N/A|222|159988|K_
+video|1|982|0.010911|-2618|-0.029089|3600|0.04|N/A|N/A|24801|564|K_MPEGTS 
Stream ID|1
+
+video|1|4582|0.050911|982|0.010911|3600|0.04|N/A|N/A|16429|27072|__MPEGTS 
Stream ID|1
+
+video|1|8182|0.090911|4582|0.050911|3600|0.04|N/A|N/A|14508|44932|__MPEGTS 
Stream ID|1
+
+video|1|11782|0.130911|8182|0.090911|3600|0.04|N/A|N/A|12622|60536|__MPEGTS
 Stream ID|1
+
+video|1|15382|0.170911|11782|0.130911|3600|0.04|N/A|N/A|13393|74260|__MPEGTS
 Stream ID|1
+
+video|1|18982|0.210911|15382|0.170911|3600|0.04|N/A|N/A|13092|88924|__MPEGTS
 Stream ID|1
+
+video|1|22582|0.250911|18982|0.210911|3600|0.04|N/A|N/A|12755|102836|__MPEGTS
 Stream ID|1
+
+video|1|26182|0.290911|22582|0.250911|3600|0.04|N/A|N/A|12023|116748|__MPEGTS
 Stream ID|1
+
+audio|0|0|0.00|0|0.00|2351|0.026122|N/A|N/A|208|159988|K_MPEGTS Stream 
ID|1
+
 audio|0|2351|0.026122|2351|0.026122|2351|0.026122|N/A|N/A|209|N/A|K_
 audio|0|4702|0.052244|4702|0.052244|2351|0.026122|N/A|N/A|209|N/A|K_
 audio|0|7053|0.078367|7053|0.078367|2351|0.026122|N/A|N/A|209|N/A|K_
@@ -20,17 +29,28 @@ 
audio|0|23510|0.261222|23510|0.261222|2351|0.026122|N/A|N/A|209|N/A|K_
 audio|0|25861|0.287344|25861|0.287344|2351|0.026122|N/A|N/A|209|N/A|K_
 audio|0|28212|0.313467|28212|0.313467|2351|0.026122|N/A|N/A|209|N/A|K_
 audio|0|30563|0.339589|30563|0.339589|2351|0.026122|N/A|N/A|209|N/A|K_
-video|1|29782|0.330911|26182|0.290911|3600|0.04|N/A|N/A|14112|130096|__
-video|1|33382|0.370911|29782|0.330911|3600|0.04|N/A|N/A|13343|145324|__
-video|1|36982|0.410911|33382|0.370911|3600|0.04|N/A|N/A|12149|162996|__
-video|1|40582|0.450911|36982|0.410911|3600|0.04|N/A|N/A|12296|176344|__
-video|1|44182|0.490911|40582|0.450911|3600|0.04|N/A|N/A|24800|189692|K_
-video|1|47782|0.530911|44182|0.490911|3600|0.04|N/A|N/A|17454|216388|__
-video|1|51382|0.570911|47782|0.530911|3600|0.04|N/A|N/A|15033|235000|__
-video|1|54982|0.610911|51382|0.570911|3600|0.04|N/A|N/A|13463|251356|__
-video|1|58582|0.650911|54982|0.610911|3600|0.04|N/A|N/A|12412|266020|__
-video|1|62182|0.690911|58582|0.650911|3600|0.04|N/A|N/A|13469|279744|__
-audio|0|32915|0.365722|32915|0.365722|2351|0.026122|N/A|N/A|223|322608|K_
+video|1|29782|0.330911|26182|0.290911|3600|0.04|N/A|N/A|14098|130096|__MPEGTS
 Stream ID|1
+
+video|1|33382|0.370911|29782|0.330911|3600|0.04|N/A|N/A|13329|145324|__MPEGTS
 Stream ID|1
+
+video|1|36982|0.410911|33382|0.370911|3600|0.04|N/A|N/A|12135|162996|__MPEGTS
 Stream ID|1
+
+video|1|40582|0.450911|36982|0.410911|3600|0.04|N/A|N/A|12282|176344|__MPEGTS
 Stream ID|1
+
+video|1|44182|0.490911|40582|0.450911|3600|0.04|N/A|N/A|24786|189692|K_MPEGTS
 Stream ID|1
+
+video|1|47782|0.530911|44182|0.490911|3600|0.04|N/A|N/A|17440|216388|__MPEGTS
 Stream ID|1
+
+video|1|51382|0.570911|47782|0.530911|3600|0.04|N/A|N/A|15019|235000|__MPEGTS
 Stream ID|1
+
+video|1|54982|0.610911|51382|0.570911|3600|0.04|N/A|N/A|13449|251356|__MPEGTS
 Stream ID|1
+
+video|1|58582|0.650911|54982|0.610911|3600|0.04|N/A|N/A|12398|266020|__MPEGTS
 Stream ID|1
+
+video|1|62182|0.690911|58582|0.650911|3600|0

[FFmpeg-cvslog] avcodec: clarify some decoding/encoding API details

2017-03-09 Thread wm4
ffmpeg | branch: master | wm4  | Mon Mar  6 11:34:20 
2017 +0100| [f940492bb241d1cf27175f40e580c51c20d6ebc3] | committer: wm4

avcodec: clarify some decoding/encoding API details

Make it clear that there is no timing-dependent behavior. In particular,
there is no state in which both input and output are denied, and where
you have to wait for a while yourself to make progress (apparently some
hardware decoders like to do this).

Avoid wording that makes references to time. It shouldn't be mistaken
for some kind of asynchronous API (like POSIX read() can return EAGAIN
if there is no new input yet). It's a state machine, so try to use
appropriate terms.

Signed-off-by: Diego Biurrun 

Merges Libav commit 8a60bba0ae.

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

 libavcodec/avcodec.h | 44 +++-
 1 file changed, 35 insertions(+), 9 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index af054f3..30ac236 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -112,6 +112,12 @@
  * are filled. This situation is handled transparently if you follow the steps
  * outlined above.
  *
+ * In theory, sending input can result in EAGAIN - this should happen only if
+ * not all output was received. You can use this to structure alternative 
decode
+ * or encode loops other than the one suggested above. For example, you could
+ * try sending new input on each iteration, and try to receive output if that
+ * returns EAGAIN.
+ *
  * End of stream situations. These require "flushing" (aka draining) the codec,
  * as the codec might buffer multiple frames or packets internally for
  * performance or out of necessity (consider B-frames).
@@ -146,7 +152,8 @@
  *   Unlike with the old video decoding API, multiple frames might result from
  *   a packet. For audio, splitting the input packet into frames by partially
  *   decoding packets becomes transparent to the API user. You never need to
- *   feed an AVPacket to the API twice.
+ *   feed an AVPacket to the API twice (unless it is rejected with EAGAIN - 
then
+ *   no data was read from the packet).
  *   Additionally, sending a flush/draining packet is required only once.
  * - avcodec_encode_video2()/avcodec_encode_audio2():
  *   Use avcodec_send_frame() to feed input to the encoder, then use
@@ -159,7 +166,22 @@
  * and will result in undefined behavior.
  *
  * Some codecs might require using the new API; using the old API will return
- * an error when calling it.
+ * an error when calling it. All codecs support the new API.
+ *
+ * A codec is not allowed to return EAGAIN for both sending and receiving. This
+ * would be an invalid state, which could put the codec user into an endless
+ * loop. The API has no concept of time either: it cannot happen that trying to
+ * do avcodec_send_packet() results in EAGAIN, but a repeated call 1 second
+ * later accepts the packet (with no other receive/flush API calls involved).
+ * The API is a strict state machine, and the passage of time is not supposed
+ * to influence it. Some timing-dependent behavior might still be deemed
+ * acceptable in certain cases. But it must never result in both send/receive
+ * returning EAGAIN at the same time at any point. It must also absolutely be
+ * avoided that the current state is "unstable" and can "flip-flop" between
+ * the send/receive APIs allowing progress. For example, it's not allowed that
+ * the codec randomly decides that it actually wants to consume a packet now
+ * instead of returning a frame, after it just returned EAGAIN on an
+ * avcodec_send_packet() call.
  * @}
  */
 
@@ -4914,8 +4936,10 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, 
AVSubtitle *sub,
  *  a flush packet.
  *
  * @return 0 on success, otherwise negative error code:
- *  AVERROR(EAGAIN):   input is not accepted right now - the packet must be
- * resent after trying to read output
+ *  AVERROR(EAGAIN):   input is not accepted in the current state - user
+ * must read output with avcodec_receive_frame() (once
+ * all output is read, the packet should be resent, and
+ * the call will not fail with EAGAIN).
  *  AVERROR_EOF:   the decoder has been flushed, and no new packets can
  * be sent to it (also returned if more than 1 flush
  * packet is sent)
@@ -4936,7 +4960,7 @@ int avcodec_send_packet(AVCodecContext *avctx, const 
AVPacket *avpkt);
  *
  * @return
  *  0: success, a frame was returned
- *  AVERROR(EAGAIN):   output is not available right now - user must try
+ *  AVERROR(EAGAIN):   output is not available in this state - user must 
try
  * to send new input
  *  AVERROR_EOF:   the decoder has been fully flushed, and there will 
be
  

[FFmpeg-cvslog] avformat/matroskaenc: add support for Spherical Video elements

2017-03-09 Thread James Almer
ffmpeg | branch: master | James Almer  | Wed Mar  8 16:12:32 
2017 -0300| [58eb0f57f6702d57b6f97ec5010657bb2c076eff] | committer: James Almer

avformat/matroskaenc: add support for Spherical Video elements

Reviewed-by: Vittorio Giovara 
Signed-off-by: James Almer 

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

 libavformat/matroskaenc.c | 79 +++
 libavformat/version.h |  2 +-
 2 files changed, 80 insertions(+), 1 deletion(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 1605f0c..df77313 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -918,6 +918,82 @@ static int mkv_write_video_color(AVIOContext *pb, 
AVCodecParameters *par, AVStre
 return 0;
 }
 
+static int mkv_write_video_projection(AVFormatContext *s, AVIOContext *pb, 
AVStream *st)
+{
+int side_data_size = 0;
+const AVSphericalMapping *spherical =
+(const AVSphericalMapping*) av_stream_get_side_data(st, 
AV_PKT_DATA_SPHERICAL,
+&side_data_size);
+
+if (side_data_size) {
+AVIOContext *dyn_cp;
+uint8_t *projection_ptr;
+int ret, projection_size;
+
+ret = avio_open_dyn_buf(&dyn_cp);
+if (ret < 0)
+return ret;
+
+switch (spherical->projection) {
+case AV_SPHERICAL_EQUIRECTANGULAR:
+put_ebml_uint(dyn_cp, MATROSKA_ID_VIDEOPROJECTIONTYPE,
+  MATROSKA_VIDEO_PROJECTION_TYPE_EQUIRECTANGULAR);
+break;
+case AV_SPHERICAL_EQUIRECTANGULAR_TILE:
+{
+AVIOContext b;
+uint8_t private[20];
+ffio_init_context(&b, private, sizeof(private),
+  1, NULL, NULL, NULL, NULL);
+put_ebml_uint(dyn_cp, MATROSKA_ID_VIDEOPROJECTIONTYPE,
+  MATROSKA_VIDEO_PROJECTION_TYPE_EQUIRECTANGULAR);
+avio_wb32(&b, 0); // version + flags
+avio_wb32(&b, spherical->bound_top);
+avio_wb32(&b, spherical->bound_bottom);
+avio_wb32(&b, spherical->bound_left);
+avio_wb32(&b, spherical->bound_right);
+put_ebml_binary(dyn_cp, MATROSKA_ID_VIDEOPROJECTIONPRIVATE, 
private, sizeof(private));
+break;
+}
+case AV_SPHERICAL_CUBEMAP:
+{
+AVIOContext b;
+uint8_t private[12];
+ffio_init_context(&b, private, sizeof(private),
+  1, NULL, NULL, NULL, NULL);
+put_ebml_uint(dyn_cp, MATROSKA_ID_VIDEOPROJECTIONTYPE,
+  MATROSKA_VIDEO_PROJECTION_TYPE_CUBEMAP);
+avio_wb32(&b, 0); // version + flags
+avio_wb32(&b, 0); // layout
+avio_wb32(&b, spherical->padding);
+put_ebml_binary(dyn_cp, MATROSKA_ID_VIDEOPROJECTIONPRIVATE, 
private, sizeof(private));
+break;
+}
+default:
+av_log(s, AV_LOG_WARNING, "Unknown projection type\n");
+goto end;
+}
+
+if (spherical->yaw)
+put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOPROJECTIONPOSEYAW,   
(double)spherical->yaw   / (1 << 16));
+if (spherical->pitch)
+put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOPROJECTIONPOSEPITCH, 
(double)spherical->pitch / (1 << 16));
+if (spherical->roll)
+put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOPROJECTIONPOSEROLL,  
(double)spherical->roll  / (1 << 16));
+
+end:
+projection_size = avio_close_dyn_buf(dyn_cp, &projection_ptr);
+if (projection_size) {
+ebml_master projection = start_ebml_master(pb, 
MATROSKA_ID_VIDEOPROJECTION, projection_size);
+avio_write(pb, projection_ptr, projection_size);
+end_ebml_master(pb, projection);
+}
+av_freep(&projection_ptr);
+}
+
+return 0;
+}
+
 static void mkv_write_field_order(AVIOContext *pb, int mode,
   enum AVFieldOrder field_order)
 {
@@ -1268,6 +1344,9 @@ static int mkv_write_track(AVFormatContext *s, 
MatroskaMuxContext *mkv,
 ret = mkv_write_video_color(pb, par, st);
 if (ret < 0)
 return ret;
+ret = mkv_write_video_projection(s, pb, st);
+if (ret < 0)
+return ret;
 end_ebml_master(pb, subinfo);
 break;
 
diff --git a/libavformat/version.h b/libavformat/version.h
index cd50524..dc689d4 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -33,7 +33,7 @@
 // Also please add any ticket numbers that you believe might be affected here
 #define LIBAVFORMAT_VERSION_MAJOR  57
 #define LIBAVFORMAT_VERSION_MINOR  66
-#define LIBAVFORMAT_VERSION_MICRO 103
+#define LIBAVFORMAT_VERSION_MICRO 104
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
  

[FFmpeg-cvslog] avcodec/cuvid: add support for cropping/resizing

2017-03-09 Thread Timo Rothenpieler
ffmpeg | branch: master | Timo Rothenpieler  | Sun Mar  
5 15:32:36 2017 +0100| [5cd3cd5b6872eda1775aa2ddb34fc23ca03c6c85] | committer: 
Timo Rothenpieler

avcodec/cuvid: add support for cropping/resizing

Overhauled version, original patch by Miroslav Slugeň .

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

 libavcodec/cuvid.c | 85 ++
 1 file changed, 66 insertions(+), 19 deletions(-)

diff --git a/libavcodec/cuvid.c b/libavcodec/cuvid.c
index c0b4a37..916d7e9 100644
--- a/libavcodec/cuvid.c
+++ b/libavcodec/cuvid.c
@@ -43,6 +43,20 @@ typedef struct CuvidContext
 char *cu_gpu;
 int nb_surfaces;
 int drop_second_field;
+char *crop_expr;
+char *resize_expr;
+
+struct {
+int left;
+int top;
+int right;
+int bottom;
+} crop;
+
+struct {
+int width;
+int height;
+} resize;
 
 AVBufferRef *hwdevice;
 AVBufferRef *hwframe;
@@ -107,17 +121,46 @@ static int CUDAAPI cuvid_handle_video_sequence(void 
*opaque, CUVIDEOFORMAT* form
 CUVIDDECODECREATEINFO cuinfo;
 int surface_fmt;
 
+int old_width = avctx->width;
+int old_height = avctx->height;
+
 enum AVPixelFormat pix_fmts[3] = { AV_PIX_FMT_CUDA,
AV_PIX_FMT_NONE,  // Will be updated 
below
AV_PIX_FMT_NONE };
 
 av_log(avctx, AV_LOG_TRACE, "pfnSequenceCallback, 
progressive_sequence=%d\n", format->progressive_sequence);
 
+memset(&cuinfo, 0, sizeof(cuinfo));
+
 ctx->internal_error = 0;
 
+avctx->coded_width = cuinfo.ulWidth = format->coded_width;
+avctx->coded_height = cuinfo.ulHeight = format->coded_height;
+
+// apply cropping
+cuinfo.display_area.left = format->display_area.left + ctx->crop.left;
+cuinfo.display_area.top = format->display_area.top + ctx->crop.top;
+cuinfo.display_area.right = format->display_area.right - ctx->crop.right;
+cuinfo.display_area.bottom = format->display_area.bottom - 
ctx->crop.bottom;
+
 // width and height need to be set before calling ff_get_format
-avctx->width = format->display_area.right;
-avctx->height = format->display_area.bottom;
+if (ctx->resize_expr) {
+avctx->width = ctx->resize.width;
+avctx->height = ctx->resize.height;
+} else {
+avctx->width = cuinfo.display_area.right - cuinfo.display_area.left;
+avctx->height = cuinfo.display_area.bottom - cuinfo.display_area.top;
+}
+
+// target width/height need to be multiples of two
+cuinfo.ulTargetWidth = avctx->width = (avctx->width + 1) & ~1;
+cuinfo.ulTargetHeight = avctx->height = (avctx->height + 1) & ~1;
+
+// aspect ratio conversion, 1:1, depends on scaled resolution
+cuinfo.target_rect.left = 0;
+cuinfo.target_rect.top = 0;
+cuinfo.target_rect.right = cuinfo.ulTargetWidth;
+cuinfo.target_rect.bottom = cuinfo.ulTargetHeight;
 
 switch (format->bit_depth_luma_minus8) {
 case 0: // 8-bit
@@ -195,6 +238,8 @@ static int CUDAAPI cuvid_handle_video_sequence(void 
*opaque, CUVIDEOFORMAT* form
 if (ctx->cudecoder
 && avctx->coded_width == format->coded_width
 && avctx->coded_height == format->coded_height
+&& avctx->width == old_width
+&& avctx->height == old_height
 && ctx->chroma_format == format->chroma_format
 && ctx->codec_type == format->codec)
 return 1;
@@ -228,13 +273,8 @@ static int CUDAAPI cuvid_handle_video_sequence(void 
*opaque, CUVIDEOFORMAT* form
 return 0;
 }
 
-avctx->coded_width = format->coded_width;
-avctx->coded_height = format->coded_height;
-
 ctx->chroma_format = format->chroma_format;
 
-memset(&cuinfo, 0, sizeof(cuinfo));
-
 cuinfo.CodecType = ctx->codec_type = format->codec;
 cuinfo.ChromaFormat = format->chroma_format;
 
@@ -252,16 +292,6 @@ static int CUDAAPI cuvid_handle_video_sequence(void 
*opaque, CUVIDEOFORMAT* form
 return 0;
 }
 
-cuinfo.ulWidth = avctx->coded_width;
-cuinfo.ulHeight = avctx->coded_height;
-cuinfo.ulTargetWidth = cuinfo.ulWidth;
-cuinfo.ulTargetHeight = cuinfo.ulHeight;
-
-cuinfo.target_rect.left = 0;
-cuinfo.target_rect.top = 0;
-cuinfo.target_rect.right = cuinfo.ulWidth;
-cuinfo.target_rect.bottom = cuinfo.ulHeight;
-
 cuinfo.ulNumDecodeSurfaces = ctx->nb_surfaces;
 cuinfo.ulNumOutputSurfaces = 1;
 cuinfo.ulCreationFlags = cudaVideoCreate_PreferCUVID;
@@ -486,7 +516,7 @@ static int cuvid_output_frame(AVCodecContext *avctx, 
AVFrame *frame)
 if (ret < 0)
 goto error;
 
-offset += avctx->coded_height;
+offset += avctx->height;
 }
 } else if (avctx->pix_fmt == AV_PIX_FMT_NV12 ||
avctx->pix_fmt == AV_PIX_FMT_P010 ||
@@ 

[FFmpeg-cvslog] avcodec/mpeg4videodec: Fix runtime error: signed integer overflow: -135088512 * 16 cannot be represented in type 'int'

2017-03-09 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Wed 
Mar  8 22:25:08 2017 +0100| [e2a4f1a9eb2c1ef3feed4a4f04db7629f2b61084] | 
committer: Michael Niedermayer

avcodec/mpeg4videodec: Fix runtime error: signed integer overflow: -135088512 * 
16 cannot be represented in type 'int'

Fixes: 736/clusterfuzz-testcase-5580263943831552

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

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

 libavcodec/mpeg4videodec.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 128469d..791a07b 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -387,11 +387,21 @@ static int mpeg4_decode_sprite_trajectory(Mpeg4DecContext 
*ctx, GetBitContext *g
 
 }
 for (i = 0; i < 2; i++) {
+int64_t sd[2] = {
+s->sprite_delta[i][0] - a * (1LL<<16),
+s->sprite_delta[i][1] - a * (1LL<<16)
+};
+
 if (llabs(s->sprite_offset[0][i] + s->sprite_delta[i][0] * 
(w+16LL)) >= INT_MAX ||
 llabs(s->sprite_offset[0][i] + s->sprite_delta[i][1] * 
(h+16LL)) >= INT_MAX ||
 llabs(s->sprite_offset[0][i] + s->sprite_delta[i][0] * 
(w+16LL) + s->sprite_delta[i][1] * (h+16LL)) >= INT_MAX ||
 llabs(s->sprite_delta[i][0] * (w+16LL)) >= INT_MAX ||
-llabs(s->sprite_delta[i][1] * (w+16LL)) >= INT_MAX
+llabs(s->sprite_delta[i][1] * (w+16LL)) >= INT_MAX ||
+llabs(sd[0]) >= INT_MAX ||
+llabs(sd[1]) >= INT_MAX ||
+llabs(s->sprite_offset[0][i] + sd[0] * (w+16LL)) >= INT_MAX ||
+llabs(s->sprite_offset[0][i] + sd[1] * (h+16LL)) >= INT_MAX ||
+llabs(s->sprite_offset[0][i] + sd[0] * (w+16LL) + sd[1] * 
(h+16LL)) >= INT_MAX
 ) {
 avpriv_request_sample(s->avctx, "Overflow on sprite points");
 goto overflow;

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


[FFmpeg-cvslog] avcodec/movtextdec: run mov_text_cleanup() before overwriting pointers

2017-03-09 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Wed 
Mar  8 22:54:10 2017 +0100| [bac9c03ed9328c63aba46e280ba408431b53fcb4] | 
committer: Michael Niedermayer

avcodec/movtextdec: run mov_text_cleanup() before overwriting pointers

Fixes: memleak
Fixes: 741/clusterfuzz-testcase-586996200452915

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

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

 libavcodec/movtextdec.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c
index 6de1500..fb5085c 100644
--- a/libavcodec/movtextdec.c
+++ b/libavcodec/movtextdec.c
@@ -459,6 +459,8 @@ static int mov_text_decode_frame(AVCodecContext *avctx,
 end = ptr + FFMIN(2 + text_length, avpkt->size);
 ptr += 2;
 
+mov_text_cleanup(m);
+
 tsmb_size = 0;
 m->tracksize = 2 + text_length;
 m->style_entries = 0;

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


[FFmpeg-cvslog] avcodec/h264_mvpred: Fix runtime error: left shift of negative value -1

2017-03-09 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Wed 
Mar  8 21:53:15 2017 +0100| [222c9f031de3315af62be6d7a99c71105e516088] | 
committer: Michael Niedermayer

avcodec/h264_mvpred: Fix runtime error: left shift of negative value -1

Fixes: 734/clusterfuzz-testcase-4821293192970240

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

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

 libavcodec/h264_mvpred.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/h264_mvpred.h b/libavcodec/h264_mvpred.h
index 339cf62..bf395e3 100644
--- a/libavcodec/h264_mvpred.h
+++ b/libavcodec/h264_mvpred.h
@@ -68,7 +68,7 @@ static av_always_inline int fetch_diagonal_mv(const 
H264Context *h, H264SliceCon
 }
 if (MB_FIELD(sl) && !IS_INTERLACED(sl->left_type[0])) {
 // left shift will turn LIST_NOT_USED into PART_NOT_AVAILABLE, 
but that's OK.
-SET_DIAG_MV(/ 2, << 1, sl->left_mb_xy[i >= 36], ((i >> 2)) & 
3);
+SET_DIAG_MV(/ 2, *2, sl->left_mb_xy[i >= 36], ((i >> 2)) & 3);
 }
 }
 #undef SET_DIAG_MV

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


[FFmpeg-cvslog] avcodec/mpegaudiodec_template: Check for negative e

2017-03-09 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Wed 
Mar  8 21:25:13 2017 +0100| [58dd25f8adb151a59971daa94d352d3226d2dbb6] | 
committer: Michael Niedermayer

avcodec/mpegaudiodec_template: Check for negative e

Fixes: undefined shift
Fixes: 631/clusterfuzz-testcase-6725491035734016

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

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

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

diff --git a/libavcodec/mpegaudiodec_template.c 
b/libavcodec/mpegaudiodec_template.c
index a3729a9..88f6272 100644
--- a/libavcodec/mpegaudiodec_template.c
+++ b/libavcodec/mpegaudiodec_template.c
@@ -251,7 +251,7 @@ static inline int l3_unscale(int value, int exponent)
 if(e < 1)
 av_log(NULL, AV_LOG_WARNING, "l3_unscale: e is %d\n", e);
 #endif
-if (e > 31)
+if (e > (SUINT)31)
 return 0;
 m = (m + (1 << (e - 1))) >> e;
 

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


[FFmpeg-cvslog] avcodec/mjpegdec: Fix runtime error: left shift of negative value -127

2017-03-09 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Wed 
Mar  8 21:41:34 2017 +0100| [800d02abe041deacab5585bf41c1bc2ae5f4b922] | 
committer: Michael Niedermayer

avcodec/mjpegdec: Fix runtime error: left shift of negative value -127

Fixes: 733/clusterfuzz-testcase-4682158096515072

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

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

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

diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 2b5adfc..4e78e1e 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -1196,13 +1196,13 @@ static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, 
int predictor,
 PREDICT(pred, ptr[-linesize-1], ptr[-linesize], 
ptr[-1], predictor);
 
 pred &= mask;
-*ptr = pred + (dc << point_transform);
+*ptr = pred + ((unsigned)dc << point_transform);
 }else{
 ptr16 = (uint16_t*)(s->picture_ptr->data[c] + 
2*(linesize * (v * mb_y + y)) + 2*(h * mb_x + x)); //FIXME optimize this crap
 PREDICT(pred, ptr16[-linesize-1], 
ptr16[-linesize], ptr16[-1], predictor);
 
 pred &= mask;
-*ptr16= pred + (dc << point_transform);
+*ptr16= pred + ((unsigned)dc << point_transform);
 }
 
 if (++x == h) {

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


[FFmpeg-cvslog] avcodec/vp8: Fix hang with slice threads

2017-03-09 Thread Thomas Guilbert
ffmpeg | branch: master | Thomas Guilbert  | Fri Mar 10 
00:15:39 2017 +0100| [9bbc73ae9fdedc8789b2b6be65279e9a0ecd7090] | committer: 
Michael Niedermayer

avcodec/vp8: Fix hang with slice threads

Fixes: 447860.webm

Reviewed-by: "Ronald S. Bultje" 
Signed-off-by: Michael Niedermayer 

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

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

diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c
index 6759b31..0682239 100644
--- a/libavcodec/vp8.c
+++ b/libavcodec/vp8.c
@@ -2508,8 +2508,10 @@ int vp78_decode_mb_row_sliced(AVCodecContext *avctx, 
void *tdata, int jobnr,
 for (mb_y = jobnr; mb_y < s->mb_height; mb_y += num_jobs) {
 td->thread_mb_pos = mb_y << 16;
 ret = s->decode_mb_row_no_filter(avctx, tdata, jobnr, threadnr);
-if (ret < 0)
+if (ret < 0) {
+update_pos(td, s->mb_height, INT_MAX & 0x);
 return ret;
+}
 if (s->deblock_filter)
 s->filter_mb_row(avctx, tdata, jobnr, threadnr);
 update_pos(td, mb_y, INT_MAX & 0x);

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


[FFmpeg-cvslog] libavcodec/libopenjpegenc: enable lossless option, remove layer option, and improve defaults

2017-03-09 Thread Aaron Boxer
ffmpeg | branch: master | Aaron Boxer  | Thu Mar  9 23:01:48 
2017 -0500| [195784ec95266c69c111f1e977fd4cf4815c6d8d] | committer: Michael 
Bradshaw

libavcodec/libopenjpegenc: enable lossless option, remove layer option, and 
improve defaults

1. limit to single layer, as there is no current support for setting 
distortion/quality of multiple layers
2. encoder mode should be kept at default setting (0)
3. remove fixed_alloc parameter from context : seldom if ever used, and no way 
of properly configuring at the moment
4. add irreversible setting, to allow for lossless encoding. Set to OpenJPEG 
default (enabled)
5. set numresolution max to 33, which is the maximum number of allowed 
resolutions according the J2K spec

Signed-off-by: Michael Bradshaw 

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

 libavcodec/libopenjpegenc.c | 17 +++--
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/libavcodec/libopenjpegenc.c b/libavcodec/libopenjpegenc.c
index 1b7e168..4a12729 100644
--- a/libavcodec/libopenjpegenc.c
+++ b/libavcodec/libopenjpegenc.c
@@ -64,9 +64,8 @@ typedef struct LibOpenJPEGContext {
 int prog_order;
 int cinema_mode;
 int numresolution;
-int numlayers;
+int irreversible;
 int disto_alloc;
-int fixed_alloc;
 int fixed_quality;
 } LibOpenJPEGContext;
 
@@ -358,13 +357,12 @@ static av_cold int libopenjpeg_encode_init(AVCodecContext 
*avctx)
 ctx->numresolution --;
 }
 
-ctx->enc_params.mode = !!avctx->global_quality;
 ctx->enc_params.prog_order = ctx->prog_order;
 ctx->enc_params.numresolution = ctx->numresolution;
+ctx->enc_params.irreversible = ctx->irreversible;
 ctx->enc_params.cp_disto_alloc = ctx->disto_alloc;
-ctx->enc_params.cp_fixed_alloc = ctx->fixed_alloc;
 ctx->enc_params.cp_fixed_quality = ctx->fixed_quality;
-ctx->enc_params.tcp_numlayers = ctx->numlayers;
+ctx->enc_params.tcp_numlayers = 1;
 ctx->enc_params.tcp_rates[0] = FFMAX(avctx->compression_level, 0) * 2;
 
 if (ctx->cinema_mode > 0) {
@@ -838,11 +836,10 @@ static const AVOption options[] = {
 { "rpcl",  NULL,0, 
AV_OPT_TYPE_CONST, { .i64 = OPJ(RPCL)}, 0, 0,   VE, 
"prog_order"  },
 { "pcrl",  NULL,0, 
AV_OPT_TYPE_CONST, { .i64 = OPJ(PCRL)}, 0, 0,   VE, 
"prog_order"  },
 { "cprl",  NULL,0, 
AV_OPT_TYPE_CONST, { .i64 = OPJ(CPRL)}, 0, 0,   VE, 
"prog_order"  },
-{ "numresolution", NULL,OFFSET(numresolution), 
AV_OPT_TYPE_INT,   { .i64 = 0   }, 0, INT_MAX, VE   
 },
-{ "numlayers", NULL,OFFSET(numlayers), 
AV_OPT_TYPE_INT,   { .i64 = 1   }, 1, 10,  VE   
 },
-{ "disto_alloc",   NULL,OFFSET(disto_alloc),   
AV_OPT_TYPE_INT,   { .i64 = 1   }, 0, 1,   VE   
 },
-{ "fixed_alloc",   NULL,OFFSET(fixed_alloc),   
AV_OPT_TYPE_INT,   { .i64 = 0   }, 0, 1,   VE   
 },
-{ "fixed_quality", NULL,OFFSET(fixed_quality), 
AV_OPT_TYPE_INT,   { .i64 = 0   }, 0, 1,   VE   
 },
+{ "numresolution", NULL,OFFSET(numresolution), 
AV_OPT_TYPE_INT,   { .i64 = 6}, 0, 33,  VE  
  },
+{ "irreversible",  NULL,OFFSET(irreversible),  
AV_OPT_TYPE_INT,   { .i64 = 0}, 0, 1,   VE  
  },
+{ "disto_alloc",   NULL,OFFSET(disto_alloc),   
AV_OPT_TYPE_INT,   { .i64 = 1}, 0, 1,   VE  
  },
+{ "fixed_quality", NULL,OFFSET(fixed_quality), 
AV_OPT_TYPE_INT,   { .i64 = 0}, 0, 1,   VE  
  },
 { NULL },
 };
 

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