Re: [libav-devel] [PATCH 2/8] lavc: add an option for exporting cropping information to the caller

2016-12-27 Thread Luca Barbato
On 27/12/2016 19:31, Anton Khirnov wrote:
> + * When hardware acceleration with opaque output frames is used, the 
> actual
> + * value of this option is disregarded and libavcodec behaves as if it 
> was
> + * set to 0.

there should be a @warning markup around this.

The rest looks fine.
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/8] frame: add a cropping rectangle to AVFrame

2016-12-27 Thread Luca Barbato
On 27/12/2016 19:31, Anton Khirnov wrote:
> Extend the width/height doy to clarify that it should store coded
> values.
> ---
>  doc/APIchanges  |  4 
>  libavutil/frame.c   |  4 
>  libavutil/frame.h   | 28 +++-
>  libavutil/version.h |  2 +-
>  4 files changed, 36 insertions(+), 2 deletions(-)
> 

size_t, while correct, feels out of place somehow.

Ok if we really plan to move to size_t everywhere else.

lu

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


[libav-devel] [PATCH] fate: Add --ignore-tests configure option for omitting specific FATE tests

2016-12-27 Thread Martin Storsjö
From: Janne Grunau 

This can be useful to filter out noise in known-broken scenarios like
miscompilation by legacy compilers and similar.

Originally based on a patch by Diego Biurrun.
---
This is the common agreed upon consensus from Diego's and Janne's
discussion, as far as I read it.
---
 configure | 11 +++
 doc/fate.texi |  1 +
 tests/Makefile|  4 +++-
 tests/fate-run.sh |  9 +++--
 tests/fate.sh |  1 +
 5 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index 8e40238..8472145 100755
--- a/configure
+++ b/configure
@@ -348,6 +348,8 @@ Developer options (useful when working on Libav itself):
   --random-seed=VALUE  seed value for --enable/disable-random
   --disable-valgrind-backtrace do not print a backtrace under Valgrind
(only applies to --disable-optimizations builds)
+  --ignore-tests=TESTS comma-separated list (without "fate-" prefix
+   in the name) of tests which result is ignored
 
 NOTE: Object files are built at the place where configure is launched.
 EOF
@@ -1815,6 +1817,7 @@ CMDLINE_SET="
 host_ld
 host_ldflags
 host_os
+ignore_tests
 ld
 logfile
 malloc_prefix
@@ -5192,6 +5195,13 @@ for type in decoder encoder hwaccel parser demuxer muxer 
protocol filter bsf ind
 echo
 done
 
+if test -n "$ignore_tests"; then
+ignore_tests=$(echo $ignore_tests | tr ',' ' ')
+echo "Ignored FATE tests:"
+echo $ignore_tests | print_3_columns
+echo
+fi
+
 license="LGPL version 2.1 or later"
 if enabled nonfree; then
 license="nonfree and unredistributable"
@@ -5316,6 +5326,7 @@ SLIB_INSTALL_EXTRA_LIB=${SLIB_INSTALL_EXTRA_LIB}
 SLIB_INSTALL_EXTRA_SHLIB=${SLIB_INSTALL_EXTRA_SHLIB}
 VERSION_SCRIPT_POSTPROCESS_CMD=${VERSION_SCRIPT_POSTPROCESS_CMD}
 SAMPLES:=${samples:-\$(LIBAV_SAMPLES)}
+IGNORE_TESTS=$ignore_tests
 EOF
 
 map 'eval echo "${v}_FFLIBS=\$${v}_deps" >> avbuild/config.mak' $LIBRARY_LIST
diff --git a/doc/fate.texi b/doc/fate.texi
index 9e654e7..b1bfa2e 100644
--- a/doc/fate.texi
+++ b/doc/fate.texi
@@ -139,6 +139,7 @@ workdir=# directory in 
which to do all the work
 fate_recv="ssh -T fate@@fate.libav.org"  # command to submit report
 comment=# optional description
 build_only= # set to "yes" for a compile-only instance that skips tests
+ignore_tests=
 
 # the following are optional and map to configure options
 arch=
diff --git a/tests/Makefile b/tests/Makefile
index 0e475a2..30e06e8 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -143,11 +143,13 @@ endif
 
 FATE_UTILS = base64 tiny_psnr
 
+$(addprefix fate-, $(IGNORE_TESTS)): REPORT=ignore
+
 fate: $(FATE)
 
 $(FATE): $(FATE_UTILS:%=tests/%$(HOSTEXESUF))
@echo "TEST$(@:fate-%=%)"
-   $(Q)$(SRC_PATH)/tests/fate-run.sh $@ "$(SAMPLES)" "$(TARGET_EXEC)" 
"$(TARGET_PATH)" '$(CMD)' '$(CMP)' '$(REF)' '$(FUZZ)' '$(THREADS)' 
'$(THREAD_TYPE)' '$(CPUFLAGS)' '$(CMP_SHIFT)' '$(CMP_TARGET)' 
'$(SIZE_TOLERANCE)' '$(CMP_UNIT)' '$(GEN)' '$(HWACCEL)'
+   $(Q)$(SRC_PATH)/tests/fate-run.sh $@ "$(SAMPLES)" "$(TARGET_EXEC)" 
"$(TARGET_PATH)" '$(CMD)' '$(CMP)' '$(REF)' '$(FUZZ)' '$(THREADS)' 
'$(THREAD_TYPE)' '$(CPUFLAGS)' '$(CMP_SHIFT)' '$(CMP_TARGET)' 
'$(SIZE_TOLERANCE)' '$(CMP_UNIT)' '$(GEN)' '$(HWACCEL)' '$(REPORT)'
 
 fate-list:
@printf '%s\n' $(sort $(FATE))
diff --git a/tests/fate-run.sh b/tests/fate-run.sh
index b1b299a..3982a18 100755
--- a/tests/fate-run.sh
+++ b/tests/fate-run.sh
@@ -24,6 +24,7 @@ size_tolerance=${14:-0}
 cmp_unit=${15:-2}
 gen=${16:-no}
 hwaccel=${17:-none}
+report_type=${18:-standard}
 
 outdir="tests/data/fate"
 outfile="${outdir}/${test}"
@@ -212,13 +213,17 @@ if test -e "$ref" || test $cmp = "oneline" ; then
 esac
 cmperr=$?
 test $err = 0 && err=$cmperr
-test $err = 0 || cat $cmpfile
+if [ "$report_type" = "ignore" ]; then
+test $err = 0 || echo "ignoring fate-${test}" && err=0
+else
+test $err = 0 || cat $cmpfile
+fi
 else
 echo "reference file '$ref' not found"
 err=1
 fi
 
-if [ $err -eq 0 ]; then
+if [ $err -eq 0 ] && test $report_type = "standard" ; then
 unset cmpo erro
 else
 cmpo="$($base64 <$cmpfile)"
diff --git a/tests/fate.sh b/tests/fate.sh
index 4608d2d..c93e20a 100755
--- a/tests/fate.sh
+++ b/tests/fate.sh
@@ -47,6 +47,7 @@ configure()(
 --prefix="${inst}"  \
 --samples="${samples}"  \
 --enable-gpl\
+${ignore_tests:+--ignore-tests="$ignore_tests"} \
 ${arch:+--arch=$arch}   \
 ${cpu:+--cpu="$cpu"}\
 ${toolchain:+--toolchain="$toolchain"}  \
-- 
2.10.1 

[libav-devel] [PATCH 2/8] lavc: add an option for exporting cropping information to the caller

2016-12-27 Thread Anton Khirnov
Also, add generic code for handling cropping, so the decoders can export
just the cropping size and not bother with the rest.
---
 doc/APIchanges |   4 ++
 libavcodec/avcodec.h   |  22 +
 libavcodec/decode.c| 112 -
 libavcodec/internal.h  |   6 +++
 libavcodec/options_table.h |   1 +
 libavcodec/version.h   |   4 +-
 6 files changed, 146 insertions(+), 3 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 10a2da4..a0ef198 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,10 @@ libavutil: 2015-08-28
 
 API changes, most recent first:
 
+2016-xx-xx - xxx - lavc 57.31.0 - avcodec.h
+  Add AVCodecContext.apply_cropping to control whether cropping
+  is handled by libavcodec or the caller.
+
 2016-xx-xx - xxx - lavu 55.30.0 - frame.h
   Add AVFrame.crop_left/right/top/bottom fields for attaching cropping
   information to video frames.
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 95da50b..524e06a 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3112,6 +3112,28 @@ typedef struct AVCodecContext {
  * This field should be set before avcodec_open2() is called.
  */
 AVBufferRef *hw_frames_ctx;
+
+/**
+ * Video decoding only. Certain video codecs support cropping, meaning that
+ * only a sub-rectangle of the decoded frame is intended for display.  This
+ * option controls how cropping is handled by libavcodec.
+ *
+ * When set to 1 (the default), libavcodec will apply cropping internally.
+ * I.e. it will modify the output frame width/height fields and offset the
+ * data pointers (only by as much as possible while preserving alignment, 
or
+ * by the full amount if the AV_CODEC_FLAG_UNALIGNED flag is set) so that
+ * the frames output by the decoder refer only to the cropped area. The
+ * crop_* fields of the output frames will be zero.
+ *
+ * When set to 0, the width/height fields of the output frames will be set
+ * to the coded dimensions and the crop_* fields will describe the cropping
+ * rectangle. Applying the cropping is left to the caller.
+ *
+ * When hardware acceleration with opaque output frames is used, the actual
+ * value of this option is disregarded and libavcodec behaves as if it was
+ * set to 0.
+ */
+int apply_cropping;
 } AVCodecContext;
 
 /**
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 0fd41ab..65ee8b0 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -29,6 +29,7 @@
 #include "libavutil/frame.h"
 #include "libavutil/hwcontext.h"
 #include "libavutil/imgutils.h"
+#include "libavutil/intmath.h"
 
 #include "avcodec.h"
 #include "bytestream.h"
@@ -450,6 +451,106 @@ int attribute_align_arg 
avcodec_send_packet(AVCodecContext *avctx, const AVPacke
 return 0;
 }
 
+static int calc_cropping_offsets(size_t offsets[4], const AVFrame *frame,
+ const AVPixFmtDescriptor *desc)
+{
+int i, j;
+
+for (i = 0; frame->data[i]; i++) {
+const AVComponentDescriptor *comp = NULL;
+int shift_x = (i == 1 || i == 2) ? desc->log2_chroma_w : 0;
+int shift_y = (i == 1 || i == 2) ? desc->log2_chroma_h : 0;
+
+if (desc->flags & (AV_PIX_FMT_FLAG_PAL | AV_PIX_FMT_FLAG_PSEUDOPAL) && 
i == 1) {
+offsets[i] = 0;
+break;
+}
+
+/* find any component descriptor for this plane */
+for (j = 0; j < desc->nb_components; j++) {
+if (desc->comp[j].plane == i) {
+comp = >comp[j];
+break;
+}
+}
+if (!comp)
+return AVERROR_BUG;
+
+offsets[i] = (frame->crop_top  >> shift_y) * frame->linesize[i] +
+ (frame->crop_left >> shift_x) * comp->step;
+}
+
+return 0;
+}
+
+static int apply_cropping(AVCodecContext *avctx, AVFrame *frame)
+{
+const AVPixFmtDescriptor *desc;
+size_t offsets[4];
+int i;
+
+/* make sure we are noisy about decoders returning invalid cropping data */
+if (frame->crop_left >= INT_MAX - frame->crop_right||
+frame->crop_top  >= INT_MAX - frame->crop_bottom   ||
+(frame->crop_left + frame->crop_right) >= frame->width ||
+(frame->crop_top + frame->crop_bottom) >= frame->height) {
+av_log(avctx, AV_LOG_WARNING,
+   "Invalid cropping information set by a decoder: %zu/%zu/%zu/%zu 
"
+   "(frame size %dx%d). This is a bug, please report it\n",
+   frame->crop_left, frame->crop_right, frame->crop_top, 
frame->crop_bottom,
+   frame->width, frame->height);
+frame->crop_left   = 0;
+frame->crop_right  = 0;
+frame->crop_top= 0;
+frame->crop_bottom = 0;
+return 0;
+}
+
+if (!avctx->apply_cropping)
+return 0;
+
+desc = 

[libav-devel] [PATCH v2] cropping

2016-12-27 Thread Anton Khirnov
Hi,
a new iteration of the cropping set. By popular demand the full cropping
rectangle is now exported instead of just left/top offsets. Consequently
AVFrame.width/height now stores the coded values (only if the caller enables the
appropriate option).
The theora decoder has been converted to the new world order.

-- 
Anton Khirnov
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 6/8] h264dec: be more eplicit in handling container cropping

2016-12-27 Thread Anton Khirnov
The current condition can trigger in cases where it shouldn't, with
unexpected results.
Make sure that:
- container cropping is really based on the original dimensions from the
  caller
- those dimenions are discarded on size change

The code is still quite hacky and eventually should be deprecated and
removed, with the decision about which cropping is used delegated to the
caller.
---
 libavcodec/h264_slice.c | 15 +++
 libavcodec/h264dec.c|  3 +++
 libavcodec/h264dec.h|  5 +
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 1b35c2b..a54d381 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -378,6 +378,8 @@ int ff_h264_update_thread_context(AVCodecContext *dst,
 h->avctx->coded_width   = h1->avctx->coded_width;
 h->avctx->width = h1->avctx->width;
 h->avctx->height= h1->avctx->height;
+h->width_from_caller= h1->width_from_caller;
+h->height_from_caller   = h1->height_from_caller;
 h->coded_picture_number = h1->coded_picture_number;
 h->first_field  = h1->first_field;
 h->picture_structure= h1->picture_structure;
@@ -797,10 +799,15 @@ static int init_dimensions(H264Context *h)
 int height = h->height - (sps->crop_top   + sps->crop_bottom);
 
 /* handle container cropping */
-if (FFALIGN(h->avctx->width,  16) == FFALIGN(width,  16) &&
-FFALIGN(h->avctx->height, 16) == FFALIGN(height, 16)) {
-width  = h->avctx->width;
-height = h->avctx->height;
+if (h->width_from_caller > 0 && h->height_from_caller > 0 &&
+!sps->crop_top && !sps->crop_left &&
+FFALIGN(h->width_from_caller,  16) == FFALIGN(width,  16) &&
+FFALIGN(h->height_from_caller, 16) == FFALIGN(height, 16)) {
+width  = h->width_from_caller;
+height = h->height_from_caller;
+} else {
+h->width_from_caller  = 0;
+h->height_from_caller = 0;
 }
 
 h->avctx->coded_width  = h->width;
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index e111d40..3209c1d 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -285,6 +285,9 @@ static int h264_init_context(AVCodecContext *avctx, 
H264Context *h)
 
 h->avctx = avctx;
 
+h->width_from_caller = avctx->width;
+h->height_from_caller= avctx->height;
+
 h->picture_structure = PICT_FRAME;
 h->workaround_bugs   = avctx->workaround_bugs;
 h->flags = avctx->flags;
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index 5957e79..0a9896a 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -514,6 +514,11 @@ typedef struct H264Context {
  * the slice data */
 int field_started;
 
+/* original AVCodecContext dimensions, used to handle container
+ * cropping */
+int width_from_caller;
+int height_from_caller;
+
 AVFrame *output_frame;
 
 int enable_er;
-- 
2.0.0

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


[libav-devel] [PATCH 4/8] h264dec: drop a redundant check

2016-12-27 Thread Anton Khirnov
Cropping parameters are already checked for validity during SPS parsing,
no need to check them again.
---
 libavcodec/h264_slice.c | 17 -
 1 file changed, 17 deletions(-)

diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index db7628c..1b35c2b 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -803,23 +803,6 @@ static int init_dimensions(H264Context *h)
 height = h->avctx->height;
 }
 
-if (width <= 0 || height <= 0) {
-av_log(h->avctx, AV_LOG_ERROR, "Invalid cropped dimensions: %dx%d.\n",
-   width, height);
-if (h->avctx->err_recognition & AV_EF_EXPLODE)
-return AVERROR_INVALIDDATA;
-
-av_log(h->avctx, AV_LOG_WARNING, "Ignoring cropping information.\n");
-sps->crop_bottom =
-sps->crop_top=
-sps->crop_right  =
-sps->crop_left   =
-sps->crop= 0;
-
-width  = h->width;
-height = h->height;
-}
-
 h->avctx->coded_width  = h->width;
 h->avctx->coded_height = h->height;
 h->avctx->width= width;
-- 
2.0.0

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


[libav-devel] [PATCH 7/8] h264dec: export cropping information instead of handling it internally

2016-12-27 Thread Anton Khirnov
---
 libavcodec/h264_ps.c|  9 -
 libavcodec/h264_slice.c | 21 +++--
 libavcodec/h264dec.c| 26 +++---
 libavcodec/h264dec.h|  5 +
 4 files changed, 27 insertions(+), 34 deletions(-)

diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c
index 8a64a33..7ee3876 100644
--- a/libavcodec/h264_ps.c
+++ b/libavcodec/h264_ps.c
@@ -498,15 +498,6 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, 
AVCodecContext *avctx,
 int step_x = 1 << hsub;
 int step_y = (2 - sps->frame_mbs_only_flag) << vsub;
 
-if (crop_left & (0x1F >> (sps->bit_depth_luma > 8)) &&
-!(avctx->flags & AV_CODEC_FLAG_UNALIGNED)) {
-crop_left &= ~(0x1F >> (sps->bit_depth_luma > 8));
-av_log(avctx, AV_LOG_WARNING,
-   "Reducing left cropping to %d "
-   "chroma samples to preserve alignment.\n",
-   crop_left);
-}
-
 if (INT_MAX / step_x <= crop_left   ||
 INT_MAX / step_x - crop_left <= crop_right  ||
 16 * sps->mb_width <= step_x * (crop_left + crop_right) ||
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index a54d381..3749d1f 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -473,6 +473,11 @@ static int h264_frame_start(H264Context *h)
 
 pic->f->pict_type = h->slice_ctx[0].slice_type;
 
+pic->f->crop_left   = h->crop_left;
+pic->f->crop_right  = h->crop_right;
+pic->f->crop_top= h->crop_top;
+pic->f->crop_bottom = h->crop_bottom;
+
 if (CONFIG_ERROR_RESILIENCE && h->enable_er)
 ff_er_frame_start(>slice_ctx[0].er);
 
@@ -795,8 +800,12 @@ static enum AVPixelFormat get_pixel_format(H264Context *h)
 static int init_dimensions(H264Context *h)
 {
 SPS *sps = h->ps.sps;
-int width  = h->width  - (sps->crop_right + sps->crop_left);
-int height = h->height - (sps->crop_top   + sps->crop_bottom);
+int cr = sps->crop_right;
+int cl = sps->crop_left;
+int ct = sps->crop_top;
+int cb = sps->crop_bottom;
+int width  = h->width  - (cr + cl);
+int height = h->height - (ct + cb);
 
 /* handle container cropping */
 if (h->width_from_caller > 0 && h->height_from_caller > 0 &&
@@ -805,6 +814,10 @@ static int init_dimensions(H264Context *h)
 FFALIGN(h->height_from_caller, 16) == FFALIGN(height, 16)) {
 width  = h->width_from_caller;
 height = h->height_from_caller;
+cl = 0;
+ct = 0;
+cr = h->width - width;
+cb = h->height - height;
 } else {
 h->width_from_caller  = 0;
 h->height_from_caller = 0;
@@ -814,6 +827,10 @@ static int init_dimensions(H264Context *h)
 h->avctx->coded_height = h->height;
 h->avctx->width= width;
 h->avctx->height   = height;
+h->crop_right  = cr;
+h->crop_left   = cl;
+h->crop_top= ct;
+h->crop_bottom = cb;
 
 return 0;
 }
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 3209c1d..834c60c 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -661,26 +661,6 @@ static int get_consumed_bytes(int pos, int buf_size)
 return pos;
 }
 
-static int output_frame(H264Context *h, AVFrame *dst, AVFrame *src)
-{
-int i;
-int ret = av_frame_ref(dst, src);
-if (ret < 0)
-return ret;
-
-if (!h->ps.sps || !h->ps.sps->crop)
-return 0;
-
-for (i = 0; i < 3; i++) {
-int hshift = (i > 0) ? h->chroma_x_shift : 0;
-int vshift = (i > 0) ? h->chroma_y_shift : 0;
-int off= ((h->ps.sps->crop_left >> hshift) << h->pixel_shift) +
- (h->ps.sps->crop_top >> vshift) * dst->linesize[i];
-dst->data[i] += off;
-}
-return 0;
-}
-
 static int h264_decode_frame(AVCodecContext *avctx, void *data,
  int *got_frame, AVPacket *avpkt)
 {
@@ -722,7 +702,7 @@ out:
 h->delayed_pic[i] = h->delayed_pic[i + 1];
 
 if (out) {
-ret = output_frame(h, pict, out->f);
+ret = av_frame_ref(pict, out->f);
 if (ret < 0)
 return ret;
 *got_frame = 1;
@@ -765,7 +745,7 @@ out:
 
 *got_frame = 0;
 if (h->output_frame->buf[0]) {
-ret = output_frame(h, pict, h->output_frame) ;
+ret = av_frame_ref(pict, h->output_frame);
 av_frame_unref(h->output_frame);
 if (ret < 0)
 return ret;
@@ -804,7 +784,7 @@ AVCodec ff_h264_decoder = {
 .capabilities  = /*AV_CODEC_CAP_DRAW_HORIZ_BAND |*/ 
AV_CODEC_CAP_DR1 |
  AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS |
  AV_CODEC_CAP_FRAME_THREADS,
-.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
+

[libav-devel] [PATCH 1/8] frame: add a cropping rectangle to AVFrame

2016-12-27 Thread Anton Khirnov
Extend the width/height doy to clarify that it should store coded
values.
---
 doc/APIchanges  |  4 
 libavutil/frame.c   |  4 
 libavutil/frame.h   | 28 +++-
 libavutil/version.h |  2 +-
 4 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 7633c99..10a2da4 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,10 @@ libavutil: 2015-08-28
 
 API changes, most recent first:
 
+2016-xx-xx - xxx - lavu 55.30.0 - frame.h
+  Add AVFrame.crop_left/right/top/bottom fields for attaching cropping
+  information to video frames.
+
 2016-xx-xx - xxx - lavc 57.29.0 - avcodec.h
   Add AV_PKT_DATA_SPHERICAL packet side data to export AVSphericalMapping
   information from containers.
diff --git a/libavutil/frame.c b/libavutil/frame.c
index 1c14f5f..aafaa57 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -390,6 +390,10 @@ int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
 dst->key_frame  = src->key_frame;
 dst->pict_type  = src->pict_type;
 dst->sample_aspect_ratio= src->sample_aspect_ratio;
+dst->crop_top   = src->crop_top;
+dst->crop_bottom= src->crop_bottom;
+dst->crop_left  = src->crop_left;
+dst->crop_right = src->crop_right;
 dst->pts= src->pts;
 dst->repeat_pict= src->repeat_pict;
 dst->interlaced_frame   = src->interlaced_frame;
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 4052199..c718f7b 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -25,6 +25,7 @@
 #ifndef AVUTIL_FRAME_H
 #define AVUTIL_FRAME_H
 
+#include 
 #include 
 
 #include "avutil.h"
@@ -180,9 +181,18 @@ typedef struct AVFrame {
 uint8_t **extended_data;
 
 /**
- * width and height of the video frame
+ * @name Video dimensions
+ * Video frames only. The coded dimensions (in pixels) of the video frame,
+ * i.e. the size of the rectangle that contains some well-defined values.
+ *
+ * @note The part of the frame intended for display/presentation is further
+ * restricted by the @ref cropping "Cropping rectangle".
+ * @{
  */
 int width, height;
+/**
+ * @}
+ */
 
 /**
  * number of audio samples (per channel) described by this frame
@@ -369,6 +379,22 @@ typedef struct AVFrame {
  * AVHWFramesContext describing the frame.
  */
 AVBufferRef *hw_frames_ctx;
+
+/**
+ * @anchor cropping
+ * @name Cropping
+ * Video frames only. The number of pixels to discard from the the
+ * top/bottom/left/right border of the frame to obtain the sub-rectangle of
+ * the frame intended for presentation.
+ * @{
+ */
+size_t crop_top;
+size_t crop_bottom;
+size_t crop_left;
+size_t crop_right;
+/**
+ * @}
+ */
 } AVFrame;
 
 /**
diff --git a/libavutil/version.h b/libavutil/version.h
index f110231..e9940f2 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -54,7 +54,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR 55
-#define LIBAVUTIL_VERSION_MINOR 29
+#define LIBAVUTIL_VERSION_MINOR 30
 #define LIBAVUTIL_VERSION_MICRO  0
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
2.0.0

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


[libav-devel] [PATCH 8/8] theora: export cropping information instead of handling it internally

2016-12-27 Thread Anton Khirnov
---
 libavcodec/vp3.c | 23 +--
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
index 26374cc..cb8925b 100644
--- a/libavcodec/vp3.c
+++ b/libavcodec/vp3.c
@@ -1983,6 +1983,7 @@ static int vp3_decode_frame(AVCodecContext *avctx,
 void *data, int *got_frame,
 AVPacket *avpkt)
 {
+AVFrame *frame  = data;
 const uint8_t *buf  = avpkt->data;
 int buf_size= avpkt->size;
 Vp3DecodeContext *s = avctx->priv_data;
@@ -2122,12 +2123,12 @@ static int vp3_decode_frame(AVCodecContext *avctx,
 /* output frame, offset as needed */
 if ((ret = av_frame_ref(data, s->current_frame.f)) < 0)
 return ret;
-for (i = 0; i < 3; i++) {
-AVFrame *dst = data;
-int off = (s->offset_x >> (i && s->chroma_y_shift)) +
-  (s->offset_y >> (i && s->chroma_y_shift)) * dst->linesize[i];
-dst->data[i] += off;
-}
+
+frame->crop_left   = s->offset_x;
+frame->crop_right  = avctx->coded_width - avctx->width - s->offset_x;
+frame->crop_top= s->offset_y;
+frame->crop_bottom = avctx->coded_height - avctx->height - s->offset_y;
+
 *got_frame = 1;
 
 if (!HAVE_THREADS || !(s->avctx->active_thread_type & FF_THREAD_FRAME)) {
@@ -2290,13 +2291,6 @@ static int theora_decode_header(AVCodecContext *avctx, 
GetBitContext *gb)
 // to normal axis ([0,0] upper left)
 s->offset_x = offset_x;
 s->offset_y = s->height - visible_height - offset_y;
-
-if ((s->offset_x & 0x1F) && !(avctx->flags & AV_CODEC_FLAG_UNALIGNED)) 
{
-s->offset_x &= ~0x1F;
-av_log(avctx, AV_LOG_WARNING, "Reducing offset_x from %d to %d"
-   "chroma samples to preserve alignment.\n",
-   offset_x, s->offset_x);
-}
 }
 
 if (colorspace == 1)
@@ -2499,7 +2493,8 @@ AVCodec ff_theora_decoder = {
  AV_CODEC_CAP_FRAME_THREADS,
 .flush = vp3_decode_flush,
 .init_thread_copy  = ONLY_IF_THREADS_ENABLED(vp3_init_thread_copy),
-.update_thread_context = ONLY_IF_THREADS_ENABLED(vp3_update_thread_context)
+.update_thread_context = 
ONLY_IF_THREADS_ENABLED(vp3_update_thread_context),
+.caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING,
 };
 #endif
 
-- 
2.0.0

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


[libav-devel] [PATCH 3/8] hevcdec: export cropping information instead of handling it internally

2016-12-27 Thread Anton Khirnov
---
 libavcodec/hevc_parser.c |  6 --
 libavcodec/hevc_ps.c | 33 -
 libavcodec/hevc_ps.h |  2 --
 libavcodec/hevc_refs.c   | 19 ---
 libavcodec/hevcdec.c |  7 ---
 libavcodec/hevcdec.h |  2 --
 6 files changed, 24 insertions(+), 45 deletions(-)

diff --git a/libavcodec/hevc_parser.c b/libavcodec/hevc_parser.c
index 49e7122..74a0257 100644
--- a/libavcodec/hevc_parser.c
+++ b/libavcodec/hevc_parser.c
@@ -49,6 +49,7 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, 
H2645NAL *nal,
 
 HEVCPPS *pps;
 HEVCSPS *sps;
+HEVCWindow *ow;
 unsigned int pps_id;
 
 get_bits1(gb);  // first slice in pic
@@ -62,12 +63,13 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, 
H2645NAL *nal,
 }
 pps = (HEVCPPS*)ctx->ps.pps_list[pps_id]->data;
 sps = (HEVCSPS*)ctx->ps.sps_list[pps->sps_id]->data;
+ow  = >output_window;
 
 /* export the stream parameters */
 s->coded_width  = sps->width;
 s->coded_height = sps->height;
-s->width= sps->output_width;
-s->height   = sps->output_height;
+s->width= sps->width  - ow->left_offset - ow->right_offset;
+s->height   = sps->height - ow->top_offset  - ow->bottom_offset;
 s->format   = sps->pix_fmt;
 avctx->profile  = sps->ptl.general_ptl.profile_idc;
 avctx->level= sps->ptl.general_ptl.level_idc;
diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index 2471907..4a5a47e 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -682,6 +682,7 @@ static int map_pixel_format(AVCodecContext *avctx, HEVCSPS 
*sps)
 int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
   int apply_defdispwin, AVBufferRef **vps_list, 
AVCodecContext *avctx)
 {
+HEVCWindow *ow;
 int ret = 0;
 int log2_diff_max_min_transform_block_size;
 int bit_depth_chroma, start, vui_present, sublayer_ordering_info;
@@ -902,32 +903,21 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, 
unsigned int *sps_id,
 sps->output_window.top_offset+= sps->vui.def_disp_win.top_offset;
 sps->output_window.bottom_offset += 
sps->vui.def_disp_win.bottom_offset;
 }
-if (sps->output_window.left_offset & (0x1F >> (sps->pixel_shift)) &&
-!(avctx->flags & AV_CODEC_FLAG_UNALIGNED)) {
-sps->output_window.left_offset &= ~(0x1F >> (sps->pixel_shift));
-av_log(avctx, AV_LOG_WARNING, "Reducing left output window to %d "
-   "chroma samples to preserve alignment.\n",
-   sps->output_window.left_offset);
-}
-sps->output_width  = sps->width -
- (sps->output_window.left_offset + 
sps->output_window.right_offset);
-sps->output_height = sps->height -
- (sps->output_window.top_offset + 
sps->output_window.bottom_offset);
-if (sps->output_width <= 0 || sps->output_height <= 0) {
-av_log(avctx, AV_LOG_WARNING, "Invalid visible frame dimensions: 
%dx%d.\n",
-   sps->output_width, sps->output_height);
+
+ow = >output_window;
+if (ow->left_offset >= INT_MAX - ow->right_offset ||
+ow->top_offset  >= INT_MAX - ow->bottom_offset||
+ow->left_offset + ow->right_offset  >= sps->width ||
+ow->top_offset  + ow->bottom_offset >= sps->height) {
+av_log(avctx, AV_LOG_WARNING, "Invalid cropping offsets: 
%u/%u/%u/%u\n",
+   ow->left_offset, ow->right_offset, ow->top_offset, 
ow->bottom_offset);
 if (avctx->err_recognition & AV_EF_EXPLODE) {
 ret = AVERROR_INVALIDDATA;
 goto err;
 }
 av_log(avctx, AV_LOG_WARNING,
"Displaying the whole video surface.\n");
-sps->output_window.left_offset   =
-sps->output_window.right_offset  =
-sps->output_window.top_offset=
-sps->output_window.bottom_offset = 0;
-sps->output_width   = sps->width;
-sps->output_height  = sps->height;
+memset(ow, 0, sizeof(*ow));
 }
 
 // Inferred parameters
@@ -1008,7 +998,8 @@ int ff_hevc_decode_nal_sps(GetBitContext *gb, 
AVCodecContext *avctx,
"Parsed SPS: id %d; coded wxh: %dx%d; "
"cropped wxh: %dx%d; pix_fmt: %s.\n",
sps_id, sps->width, sps->height,
-   sps->output_width, sps->output_height,
+   sps->width - (sps->output_window.left_offset + 
sps->output_window.right_offset),
+   sps->height - (sps->output_window.top_offset + 
sps->output_window.bottom_offset),
av_get_pix_fmt_name(sps->pix_fmt));
 }
 
diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h
index d95aa51..89a481b 100644
--- a/libavcodec/hevc_ps.h
+++ b/libavcodec/hevc_ps.h
@@ -141,8 +141,6 @@ typedef struct HEVCSPS {
 int chroma_format_idc;
 uint8_t separate_colour_plane_flag;
 
- 

[libav-devel] [PATCH 5/8] h264dec: make ff_h264_decode_init() static

2016-12-27 Thread Anton Khirnov
It is not called from outside h264dec.c anymore.
---
 libavcodec/h264dec.c | 4 ++--
 libavcodec/h264dec.h | 1 -
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 54ded03..e111d40 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -361,7 +361,7 @@ static av_cold int h264_decode_end(AVCodecContext *avctx)
 
 static AVOnce h264_vlc_init = AV_ONCE_INIT;
 
-av_cold int ff_h264_decode_init(AVCodecContext *avctx)
+static av_cold int h264_decode_init(AVCodecContext *avctx)
 {
 H264Context *h = avctx->priv_data;
 int ret;
@@ -795,7 +795,7 @@ AVCodec ff_h264_decoder = {
 .type  = AVMEDIA_TYPE_VIDEO,
 .id= AV_CODEC_ID_H264,
 .priv_data_size= sizeof(H264Context),
-.init  = ff_h264_decode_init,
+.init  = h264_decode_init,
 .close = h264_decode_end,
 .decode= h264_decode_frame,
 .capabilities  = /*AV_CODEC_CAP_DRAW_HORIZ_BAND |*/ 
AV_CODEC_CAP_DR1 |
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index 2ffe4de..5957e79 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -553,7 +553,6 @@ int ff_h264_decode_ref_pic_marking(H264SliceContext *sl, 
GetBitContext *gb,
const H2645NAL *nal, void *logctx);
 
 void ff_h264_hl_decode_mb(const H264Context *h, H264SliceContext *sl);
-int ff_h264_decode_init(AVCodecContext *avctx);
 void ff_h264_decode_init_vlc(void);
 
 /**
-- 
2.0.0

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


Re: [libav-devel] [PATCH] build: Add version numbers to "Requires" entries in pkg-config files

2016-12-27 Thread Anton Khirnov
Quoting Diego Biurrun (2016-12-27 13:18:21)
> On Sun, Dec 25, 2016 at 06:30:45PM +0100, Diego Biurrun wrote:
> > --- a/avbuild/pkgconfig_generate.sh
> > +++ b/avbuild/pkgconfig_generate.sh
> > @@ -12,7 +12,15 @@ shortname=$1
> >  comment=$2
> >  libs=$(eval echo \$extralibs_${shortname})
> > -requires=$(eval echo \$requires_${shortname})
> > +deps=$(eval echo \$${shortname}_deps)
> > +
> > +for dep in $deps; do
> > +depname=lib${dep}
> > +. ${depname}/${depname}.version
> > +depversion=$(eval echo \$${depname}_VERSION_MAJOR)
> > +requires="$requires ${depname} >= ${depversion}, "
> > +done
> 
> Notice that this adds dependencies on "libfoo_VERSION_MAJOR >= X" instead
> of "libfoo_VERSION_MAJOR >= X.Y.Z" as it did before. Adding random (depending
> on when configure was run) deps on minor and micro lib versions is incorrect
> AFAICT. If somebody has a different opinion, now is the time to speak up.

That sounds wrong to me. Dynamically linking against an earlier minor
version than the one we built against is likely to fail. The previous
behaviour is more correct IMO.

-- 
Anton Khirnov
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] build: Add version numbers to "Requires" entries in pkg-config files

2016-12-27 Thread Diego Biurrun
On Sun, Dec 25, 2016 at 06:30:45PM +0100, Diego Biurrun wrote:
> --- a/avbuild/pkgconfig_generate.sh
> +++ b/avbuild/pkgconfig_generate.sh
> @@ -12,7 +12,15 @@ shortname=$1
>  comment=$2
>  libs=$(eval echo \$extralibs_${shortname})
> -requires=$(eval echo \$requires_${shortname})
> +deps=$(eval echo \$${shortname}_deps)
> +
> +for dep in $deps; do
> +depname=lib${dep}
> +. ${depname}/${depname}.version
> +depversion=$(eval echo \$${depname}_VERSION_MAJOR)
> +requires="$requires ${depname} >= ${depversion}, "
> +done

Notice that this adds dependencies on "libfoo_VERSION_MAJOR >= X" instead
of "libfoo_VERSION_MAJOR >= X.Y.Z" as it did before. Adding random (depending
on when configure was run) deps on minor and micro lib versions is incorrect
AFAICT. If somebody has a different opinion, now is the time to speak up.

Diego
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel