From patchwork Wed Feb 15 16:29:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vittorio Giovara X-Patchwork-Id: 2563 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp2044519vsb; Wed, 15 Feb 2017 08:34:36 -0800 (PST) X-Received: by 10.28.92.193 with SMTP id q184mr9122135wmb.139.1487176476307; Wed, 15 Feb 2017 08:34:36 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s20si5670636wrb.195.2017.02.15.08.34.35; Wed, 15 Feb 2017 08:34:36 -0800 (PST) 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 sp=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 4EB5E6899B7; Wed, 15 Feb 2017 18:34:27 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk0-f178.google.com (mail-qk0-f178.google.com [209.85.220.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 36BCE68096F for ; Wed, 15 Feb 2017 18:34:20 +0200 (EET) Received: by mail-qk0-f178.google.com with SMTP id 11so155734024qkl.3 for ; Wed, 15 Feb 2017 08:34:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=nHa2uLyGf1udy9cR0jGhytjNg+ih84bCVrlo0qPrkhA=; b=RYanYyjnyIlejCbDfbNnDvP1yb+oI2V7CPtKbh+4Lean0/7adxlvGkCSyHBViu18KP xmj94W+aWJpvi/a4DWOWqXb5CKD8H9hLRdekFgZTU+I/LMbkSzIJEIft+uKHOXvTv8R9 p1PqcxbnkUUJ+WqCDGAUlnqVo/JIhJ8ru60O/Q3JYwWblukQowgtVU4ZKVB3ef5Cbf5H sX7QPWuvFNxO5SybTZE4+l/Dn0KifI4gwbg7SbNw7t0HzIpHUIUTRFnPIWVRLSxLjbNP zUAb6MtPl3vScEt+LYSaG7TCQKuVSWL2hOsCZdPlHkVE30RXFlANxVzLwyYYUc7MPKif I7Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=nHa2uLyGf1udy9cR0jGhytjNg+ih84bCVrlo0qPrkhA=; b=iYv/RT8BLeEX8U8gbQtebGXQvcweZp2EFyRMOXBOjBl568GbyCq7g4AMhQP/Nkw+5u g9ab6w4DN38vwivgh5B5Quz3MR8DdXk7mF5LTk1g7bFch4B5w0KXNT+2WqOBxU9ECima Y5ppHxqG0vkJpU7a/pQ5V9TswnEbHaed0rqII1E9+0++icj2JHWKRkvcrqO1zMMVdk5M dsZ7r2XqRP4skTKZe6KDimthquSsaUr/q09VlUQu8T15xH4OjLDmj37+JZ1iYqdIUOpx VxquYJ2gCuyK6gx0PE8pm4WX3xxrZAkgCkeaihQMxDtGkQw16Frntyy+GuB7OQVAOeqy pOLw== X-Gm-Message-State: AMke39n4ajj2nRuBME/Ceh5qc2tVanUHHXbCcmasuUTF9XWM4MRUAFj7cV9T/6uk8L62dA== X-Received: by 10.55.113.129 with SMTP id m123mr37125303qkc.47.1487176145301; Wed, 15 Feb 2017 08:29:05 -0800 (PST) Received: from vimacbookpro.vimeows.com (nyv-exweb.iac.com. [216.112.252.10]) by smtp.gmail.com with ESMTPSA id s20sm2583735qtc.39.2017.02.15.08.29.04 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 15 Feb 2017 08:29:04 -0800 (PST) From: Vittorio Giovara To: ffmpeg-devel@ffmpeg.org Date: Wed, 15 Feb 2017 11:29:01 -0500 Message-Id: <20170215162903.36087-2-vittorio.giovara@gmail.com> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20170215162903.36087-1-vittorio.giovara@gmail.com> References: <20170215162903.36087-1-vittorio.giovara@gmail.com> Subject: [FFmpeg-devel] [PATCHv2 2/4] mov: Export bounds and padding from spherical metadata 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Update the fate test as needed. --- V2 bounds are validated and UINT32_MAX is used. Please CC. Vittorio libavformat/mov.c | 53 ++++++++++++++++++++++++++++++++++++++- tests/ref/fate/mov-spherical-mono | 6 ++++- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index b518177..a1774b3 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -4625,6 +4625,8 @@ static int mov_read_sv3d(MOVContext *c, AVIOContext *pb, MOVAtom atom) MOVStreamContext *sc; int size; int32_t yaw, pitch, roll; + size_t l, t, r, b; + size_t padding = 0; uint32_t tag; enum AVSphericalProjection projection; @@ -4686,9 +4688,25 @@ static int mov_read_sv3d(MOVContext *c, AVIOContext *pb, MOVAtom atom) switch (tag) { case MKTAG('c','b','m','p'): projection = AV_SPHERICAL_CUBEMAP; + padding = avio_rb32(pb); break; case MKTAG('e','q','u','i'): - projection = AV_SPHERICAL_EQUIRECTANGULAR; + t = avio_rb32(pb); + b = avio_rb32(pb); + l = avio_rb32(pb); + r = avio_rb32(pb); + + if (b >= UINT_MAX - t || r >= UINT_MAX - l) { + av_log(c->fc, AV_LOG_ERROR, + "Invalid bounding rectangle coordinates " + "%zu,%zu,%zu,%zu\n", l, t, r, b); + return AVERROR_INVALIDDATA; + } + + if (l || t || r || b) + projection = AV_SPHERICAL_EQUIRECTANGULAR_TILE; + else + projection = AV_SPHERICAL_EQUIRECTANGULAR; break; default: av_log(c->fc, AV_LOG_ERROR, "Unknown projection type\n"); @@ -4705,6 +4723,19 @@ static int mov_read_sv3d(MOVContext *c, AVIOContext *pb, MOVAtom atom) sc->spherical->pitch = pitch; sc->spherical->roll = roll; + sc->spherical->padding = padding; + + if (projection == AV_SPHERICAL_EQUIRECTANGULAR_TILE) { + /* conversion from 0.32 coordinates to pixels */ + size_t orig_width = (size_t) sc->width * UINT32_MAX / (UINT32_MAX - r - l); + size_t orig_height = (size_t) sc->height * UINT32_MAX / (UINT32_MAX - b - t); + + /* add a (UINT32_MAX - 1) to round up integer division */ + sc->spherical->bound_left = (orig_width * l + UINT32_MAX - 1) / UINT32_MAX; + sc->spherical->bound_top = (orig_height * t + UINT32_MAX - 1) / UINT32_MAX; + sc->spherical->bound_right = orig_width - sc->width - sc->spherical->bound_left; + sc->spherical->bound_bottom = orig_height - sc->height - sc->spherical->bound_top; + } return 0; } @@ -4763,6 +4794,26 @@ static int mov_parse_uuid_spherical(MOVStreamContext *sc, AVIOContext *pb, size_ val = av_stristr(buffer, ""); if (val) sc->spherical->roll = strtol(val, NULL, 10) * (1 << 16); + + /* tiling */ + val = av_stristr(buffer, ""); + if (val) + sc->spherical->bound_left = strtol(val, NULL, 10); + val = av_stristr(buffer, ""); + if (val) + sc->spherical->bound_top = strtol(val, NULL, 10); + val = av_stristr(buffer, ""); + if (val) + sc->spherical->bound_right = + sc->width - sc->spherical->bound_left - strtol(val, NULL, 10); + val = av_stristr(buffer, ""); + if (val) + sc->spherical->bound_bottom = + sc->height - sc->spherical->bound_top - strtol(val, NULL, 10); + + if (sc->spherical->bound_left || sc->spherical->bound_top || + sc->spherical->bound_right || sc->spherical->bound_bottom) + sc->spherical->projection = AV_SPHERICAL_EQUIRECTANGULAR_TILE; } out: diff --git a/tests/ref/fate/mov-spherical-mono b/tests/ref/fate/mov-spherical-mono index 8048aff..a70d879 100644 --- a/tests/ref/fate/mov-spherical-mono +++ b/tests/ref/fate/mov-spherical-mono @@ -8,7 +8,11 @@ inverted=0 [SIDE_DATA] side_data_type=Spherical Mapping side_data_size=56 -projection=equirectangular +projection=tiled equirectangular +bound_left=148 +bound_top=73 +bound_right=147 +bound_bottom=72 yaw=45 pitch=30 roll=15