From patchwork Sun Sep 25 23:52:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 722 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.66 with SMTP id o63csp1655040vsd; Sun, 25 Sep 2016 17:09:42 -0700 (PDT) X-Received: by 10.194.228.3 with SMTP id se3mr18033332wjc.132.1474848582302; Sun, 25 Sep 2016 17:09:42 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 127si6195087wmt.49.2016.09.25.17.09.40; Sun, 25 Sep 2016 17:09:42 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CE395689DF7; Mon, 26 Sep 2016 03:09:21 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E7647689A7A for ; Mon, 26 Sep 2016 03:09:14 +0300 (EEST) Received: by mail-wm0-f68.google.com with SMTP id b184so11661430wma.3 for ; Sun, 25 Sep 2016 17:09:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=zysHnt27X1/x4+REQarSV0Ymg05VKocSiqDBcsQKqno=; b=y0auQ1rtrLDSA6zlYVOmHDf4OmqqFWPacsDWaoxOy0NKbz2bcp0KCN79NF29fMvwaY dIjOQXX49FAwxzQA9zTnyoaJMDQ2TcmkqcMRMTtD+7zeWk7OTIUHnJ2SiuZ6ZqIo6jaa ugaa6gpnohSIJvlm0mP3mtCacSk9bvMI2v6YA//d8r1WJe2YCEu8Zxi20exsLP6eAP7D 1XkjNmvwDRAjqG8C62l8HmU8nE92LD3G8oRFTxBYkkD+6Ni2U9zrQvbEDNkJJkft14Jz Kqmo4gpv3AmOcRBQ03nw7k3NGRATHXR/6IRvfRMbLN7r7FE7WvEvH6QcbNUKSDO0U/SF 2X9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=zysHnt27X1/x4+REQarSV0Ymg05VKocSiqDBcsQKqno=; b=A8dCK0Rqwem0TvKD+IHRVHrFM01fPszEHEXUCU2ZUmWKWbV44cgeVNde4gsn1wx6nU /UbT6EkA1AcNs5quSdjPDoNesLY5lccxOQIwyZRRJa0LKsjdplJyrVPwycWpovjRV57w UWE3lGlo3pUKTjpfKqG96/Ch9EI2hGP6fltet9pJCRXdDWhulQv7+2I0SmBv/doPw1vh +gzXFgfCrsSH6OXSDjqCIV0jDr8Q+Lkt4P/qAadwvzycqYM1OJAbt2WkHcQxS17ka5Gt KMsvGQ+J7FHi0EVsvzFd9M8HpWc0UqkrZ1t36/g6FzHsVNfKpymxLc9G/e4A9+simugu U8Fg== X-Gm-Message-State: AA6/9Rmt2qPYhuZBqsLI7nP3HGSZn5ruB03cr8Ow7K8z9eubsiEhHgbwflWUs5eWGudatg== X-Received: by 10.194.242.36 with SMTP id wn4mr6558011wjc.85.1474847564373; Sun, 25 Sep 2016 16:52:44 -0700 (PDT) Received: from saten.lan (dsl-hkibrasgw4-50df5e-23.dhcp.inet.fi. [80.223.94.23]) by smtp.gmail.com with ESMTPSA id r8sm19264016wjs.22.2016.09.25.16.52.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Sep 2016 16:52:43 -0700 (PDT) From: =?UTF-8?q?Jan=20Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Mon, 26 Sep 2016 02:52:41 +0300 Message-Id: <1474847562-22945-1-git-send-email-jeebjp@gmail.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] lavf/mxfdec: add support for all of the picture size and offset fields X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" * Renames the `width` and `height` entries to `stored_{width,height}` according to the specification's naming. * Switches the data type of widths and heights to uint32_t according to specification, adds additional checks to make sure we don't overflow INT_MAX as codecpar->{width,height} are signed integers. * Adds and parses the sampled and display width and height entries. * Adds and parses the sampled and display X/Y offsets. These together with the additional widths and heights enable future support for container cropping if and when there will be generic tooling for it within FFmpeg. Signed-off-by: Jan Ekström --- libavformat/mxfdec.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index 1939761..54fc6fb 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -170,8 +170,17 @@ typedef struct MXFDescriptor { UID codec_ul; AVRational sample_rate; AVRational aspect_ratio; - int width; - int height; /* Field height, not frame height */ + /* In case of frame_layout == SeparateFields or SegmentedFrame, height is of field, not frame */ + uint32_t stored_width; + uint32_t stored_height; + uint32_t sampled_width; + uint32_t sampled_height; + int32_t sampled_x_offset; + int32_t sampled_y_offset; + uint32_t display_width; + uint32_t display_height; + int32_t display_x_offset; + int32_t display_y_offset; int frame_layout; /* See MXFFrameLayout enum */ #define MXF_TFF 1 #define MXF_BFF 2 @@ -988,10 +997,34 @@ static int mxf_read_generic_descriptor(void *arg, AVIOContext *pb, int tag, int avio_read(pb, descriptor->essence_codec_ul, 16); break; case 0x3203: - descriptor->width = avio_rb32(pb); + descriptor->stored_width = avio_rb32(pb); break; case 0x3202: - descriptor->height = avio_rb32(pb); + descriptor->stored_height = avio_rb32(pb); + break; + case 0x3205: + descriptor->sampled_width = avio_rb32(pb); + break; + case 0x3204: + descriptor->sampled_height = avio_rb32(pb); + break; + case 0x3206: + descriptor->sampled_x_offset = avio_rb32(pb); + break; + case 0x3207: + descriptor->sampled_y_offset = avio_rb32(pb); + break; + case 0x3209: + descriptor->display_width = avio_rb32(pb); + break; + case 0x3208: + descriptor->display_height = avio_rb32(pb); + break; + case 0x320A: + descriptor->display_x_offset = avio_rb32(pb); + break; + case 0x320B: + descriptor->display_y_offset = avio_rb32(pb); break; case 0x320C: descriptor->frame_layout = avio_r8(pb); @@ -2027,8 +2060,16 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) container_ul = mxf_get_codec_ul(mxf_picture_essence_container_uls, essence_container_ul); if (st->codecpar->codec_id == AV_CODEC_ID_NONE) st->codecpar->codec_id = container_ul->id; - st->codecpar->width = descriptor->width; - st->codecpar->height = descriptor->height; /* Field height, not frame height */ + + if (descriptor->stored_width > INT_MAX || descriptor->stored_height > INT_MAX) { + av_log(mxf->fc, AV_LOG_ERROR, + "One or both of the descriptor's storage width/height values does not fit within an integer! " + "(width=%"PRIu32", height=%"PRIu32")\n", descriptor->stored_width, descriptor->stored_height); + ret = AVERROR(AVERROR_PATCHWELCOME); + goto fail_and_free; + } + st->codecpar->width = descriptor->stored_width; + st->codecpar->height = descriptor->stored_height; /* Field height, not frame height */ switch (descriptor->frame_layout) { case FullFrame: st->codecpar->field_order = AV_FIELD_PROGRESSIVE; @@ -2058,6 +2099,13 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) case 0: // we already have many samples with field_dominance == unknown break; } + if ((st->codecpar->height * 2) > INT_MAX) { + av_log(mxf->fc, AV_LOG_ERROR, + "Field height duplicated does not fit within an integer! (height*2=%"PRIu64")\n", + ((uint64_t)st->codecpar->height) * 2); + ret = AVERROR(AVERROR_PATCHWELCOME); + goto fail_and_free; + } /* Turn field height into frame height. */ st->codecpar->height *= 2; break;