From patchwork Fri Feb 10 21:11:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vittorio Giovara X-Patchwork-Id: 2492 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp706521vsb; Fri, 10 Feb 2017 13:40:29 -0800 (PST) X-Received: by 10.28.129.5 with SMTP id c5mr8820917wmd.23.1486762829471; Fri, 10 Feb 2017 13:40:29 -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 z104si3724241wrb.58.2017.02.10.13.40.25; Fri, 10 Feb 2017 13:40:29 -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 15757689DA3; Fri, 10 Feb 2017 23:40:19 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg0-f66.google.com (mail-pg0-f66.google.com [74.125.83.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E124F689742 for ; Fri, 10 Feb 2017 23:40:12 +0200 (EET) Received: by mail-pg0-f66.google.com with SMTP id v184so3947973pgv.1 for ; Fri, 10 Feb 2017 13:40:17 -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=fqZtqSnbyOtp68410SLLuYxXJ4cDJ7g2nUL/DERf30c=; b=ChamrhmVK2MnJD5Dv7qNrU0eoajDjrr5QdOZR/THITw4FxVvqj/On5BIL+prSKM0u/ 467MJ5N3lzlyeV3GbWWXKVTI9xDXBVcWy+Si4bzMlP14Mlx8bWAA169PslyA9NpYM3Cq KC0/LJ6+6d7OFoTcfd2fQ1ZZdGeTZCBGGs8PYdvSyVBet4zfCJBlduhJ1am3d6L/8Mxt v6mpHa1NnUo/rtFJzel1rTP1LqiwBG8C0zcPKkGiLJF8IetWC0crW2RrkMZN5oT00NfR eVVqRvkxJ7Lv9LNuTtH4GSd9HKiOxRYVto3xcUMBzow7JfN/lqDPVU/SLkWQXkig6IeO SQbQ== 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=fqZtqSnbyOtp68410SLLuYxXJ4cDJ7g2nUL/DERf30c=; b=iA6qvHYl2pTf2cuYXRHzhV9pKtqucZAwNg8K1M4P+KZu/JUEkZLcWxlRHPwExJLMjH tmlYZ0Nn/VrPwsjSjV7OYUJxzySmTi6dhvSrgqO6vODu2q1w2qrfPr2U3wRbhKytGnNB zQpkoREIMwV5VkmHZfzIaehIMn94euo6sQ1Z2DEdwaWo/nAVxTGTsEkL4SOAAGIGYa3S flviCTf+RgtXX3nAy+2Hi1d/w6I6Dqf/9DDqGAHen1cCaa9ThF3njo9vyIBfX5mOq6Ge bS1H0gLYAgBnnHPincmH2Nx9VRDTBY8yTltpXKbSd/UtMs78vpvxbeuOhpAQDAIkBpMo Um3w== X-Gm-Message-State: AMke39nUYW9Jl4Abx8VBFaWZmvQge3TGfE6f/+X07FK5MZ0SopeqMHx+CM5i/Rkk7y35Ig== X-Received: by 10.84.241.207 with SMTP id t15mr14121917plm.136.1486761112050; Fri, 10 Feb 2017 13:11:52 -0800 (PST) Received: from vimacbookpro.vimeows.com (nyv-exweb.iac.com. [216.112.252.10]) by smtp.gmail.com with ESMTPSA id d69sm7339147pfd.11.2017.02.10.13.11.50 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 Feb 2017 13:11:51 -0800 (PST) From: Vittorio Giovara To: ffmpeg-devel@ffmpeg.org Date: Fri, 10 Feb 2017 16:11:45 -0500 Message-Id: <20170210211145.54685-3-vittorio.giovara@gmail.com> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20170210211145.54685-1-vittorio.giovara@gmail.com> References: <20170210211145.54685-1-vittorio.giovara@gmail.com> Subject: [FFmpeg-devel] [PATCH 3/3] mkv: 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" --- Although quite math-heavy, I saw little value in having a single parsing function, and since it requires stream or demuxer specific information I preferred to keep the two separate. Please keep me in CC. Vittorio libavformat/matroskadec.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 7223e94..dc1cd62 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -1913,15 +1913,32 @@ static int mkv_parse_video_projection(AVStream *st, const MatroskaTrack *track) AVSphericalMapping *spherical; enum AVSphericalProjection projection; size_t spherical_size; + size_t l, t, r, b; + size_t padding = 0; int ret; + GetByteContext gb; + + bytestream2_init(&gb, track->video.projection.private.data, + track->video.projection.private.size); switch (track->video.projection.type) { case MATROSKA_VIDEO_PROJECTION_TYPE_EQUIRECTANGULAR: - projection = AV_SPHERICAL_EQUIRECTANGULAR; + if (track->video.projection.private.size == 0) + projection = AV_SPHERICAL_EQUIRECTANGULAR; + else { + projection = AV_SPHERICAL_EQUIRECTANGULAR_TILE; + bytestream2_skip(&gb, 4); // version + flags + t = bytestream2_get_be32(&gb); + b = bytestream2_get_be32(&gb); + l = bytestream2_get_be32(&gb); + r = bytestream2_get_be32(&gb); + } break; case MATROSKA_VIDEO_PROJECTION_TYPE_CUBEMAP: if (track->video.projection.private.size < 4) return AVERROR_INVALIDDATA; + bytestream2_skip(&gb, 4); // layout + padding = bytestream2_get_be32(&gb); projection = AV_SPHERICAL_CUBEMAP; break; default: @@ -1937,6 +1954,21 @@ static int mkv_parse_video_projection(AVStream *st, const MatroskaTrack *track) spherical->pitch = (int32_t)(track->video.projection.pitch * (1 << 16)); spherical->roll = (int32_t)(track->video.projection.roll * (1 << 16)); + spherical->padding = padding; + + if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR_TILE) { + /* conversion from 0.32 coordinates to pixels */ + uint32_t max_coord = (uint32_t) -1; + size_t orig_width = (size_t) track->video.pixel_width * max_coord / (max_coord - r - l); + size_t orig_height = (size_t) track->video.pixel_height * max_coord / (max_coord - b - t); + + /* add a (max_coord - 1) to round up integer division */ + spherical->left_bound = (orig_width * l + max_coord - 1) / max_coord; + spherical->top_bound = (orig_height * t + max_coord - 1) / max_coord; + spherical->right_bound = orig_width - track->video.pixel_width - spherical->left_bound; + spherical->bottom_bound = orig_height - track->video.pixel_height - spherical->top_bound; + } + ret = av_stream_add_side_data(st, AV_PKT_DATA_SPHERICAL, (uint8_t *)spherical, spherical_size); if (ret < 0) {