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

2017-01-03 Thread Vittorio Giovara
On Tue, Dec 27, 2016 at 7:31 PM, Anton Khirnov  wrote:
> ---
>  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(-)
>

the behaviour of `apply_defdispwin` seems unchanged so this lgtm
-- 
Vittorio
___
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  = &sps->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 = &sps->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_