From patchwork Wed Feb 15 16:29:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vittorio Giovara X-Patchwork-Id: 2565 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp2045025vsb; Wed, 15 Feb 2017 08:35:47 -0800 (PST) X-Received: by 10.223.160.14 with SMTP id k14mr34237517wrk.69.1487176547087; Wed, 15 Feb 2017 08:35:47 -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 g65si107544wmd.148.2017.02.15.08.35.44; Wed, 15 Feb 2017 08:35:47 -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 49949689A66; Wed, 15 Feb 2017 18:35:37 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt0-f180.google.com (mail-qt0-f180.google.com [209.85.216.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EF63668077C for ; Wed, 15 Feb 2017 18:35:30 +0200 (EET) Received: by mail-qt0-f180.google.com with SMTP id x49so141532970qtc.2 for ; Wed, 15 Feb 2017 08:35:36 -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=tbomztZMkCXLYTwPoVBmbsNxCBEtrIpDAm8uBRmuQVg=; b=X96IeAVubiByAeniZ5kG72uQoXgW5ps5lZ6OKmyAfAfOCxOlkKLIotqDXmwP5cP/DS xhu9bJuijexjAxx1rDHVcHcurcK2Q0DzFDwgD/RdLmFxwGOuZK4itajEObX0H+S/Z3hV QDuXiKm4DiBXAcBRuZfDP8fvFxBQ7glhKuauATd1mhqlgle1UJa9mTULsUFunCvLyqLg 3rEFvIPYTRuLTQh5fNhgwjA7sADaL9eW77Pq7ugmPDLneRpg0obepWYMKq86aqvJXVfc lRBV2gJPMjXC4A9lpHXe4NHG9fFcB2KR94hhgvhEos10UYKBanf4Q4c69wg+x8HoCAPB CCjw== 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=tbomztZMkCXLYTwPoVBmbsNxCBEtrIpDAm8uBRmuQVg=; b=dSvzSrVaVM7xIFp5CVB6s56g+hzt2OwPgnA3rzA7Giq1Vhqf+KD9g+PnrlvcD6hrxX wpX7AhPP/Td01ErYnqPRrbNId+Q7NPRIjUD3G25+R9OTFGV7iC7mtm5MQhXMI5oz0KTL /oPVrJhhTOVXlkRtmfTEVgbBE31M2ddQa74nhwXjrO2QOHCfdYd3c3eN+76jRUJ83CqN QHj1TaaSOpiX5gcvQmOugG49pQCEzwP4d0+QxmZxdBd03OvrsCrjQjtLYU16JYv0HkYN TFLv7kur1hSEzNa0372lM/g41HpzYu/JcFsoI0z1yx33F414jVgWUx08TOqfBDZuUxv0 xicQ== X-Gm-Message-State: AMke39lk0kdO6DS8lRueGS7mxOs/nB9qpkFee0q64n9SwtkA1dqPMCp6XHhHuSzcGXW1Wg== X-Received: by 10.237.60.27 with SMTP id t27mr36975469qte.86.1487176146617; Wed, 15 Feb 2017 08:29:06 -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.05 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 15 Feb 2017 08:29:06 -0800 (PST) From: Vittorio Giovara To: ffmpeg-devel@ffmpeg.org Date: Wed, 15 Feb 2017 11:29:02 -0500 Message-Id: <20170215162903.36087-3-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 3/4] 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" --- Updated according to James' review. Please CC. Vittorio libavformat/matroskadec.c | 69 ++++++++++++++++++++++++++++++++-- tests/ref/fate/matroska-spherical-mono | 6 ++- 2 files changed, 71 insertions(+), 4 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 7223e94..6fa961e 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -1913,16 +1913,65 @@ 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); + + if (bytestream2_get_byte(&gb) != 0) { + av_log(NULL, AV_LOG_WARNING, "Unknown spherical metadata\n"); + return 0; + } + + bytestream2_skip(&gb, 3); // flags 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 if (track->video.projection.private.size == 20) { + t = bytestream2_get_be32(&gb); + b = bytestream2_get_be32(&gb); + l = bytestream2_get_be32(&gb); + r = bytestream2_get_be32(&gb); + + if (b >= UINT_MAX - t || r >= UINT_MAX - l) { + av_log(NULL, 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; + } else { + av_log(NULL, AV_LOG_ERROR, "Unknown spherical metadata\n"); + return AVERROR_INVALIDDATA; + } break; case MATROSKA_VIDEO_PROJECTION_TYPE_CUBEMAP: - if (track->video.projection.private.size < 4) + if (track->video.projection.private.size < 4) { + av_log(NULL, AV_LOG_ERROR, "Missing projection private properties\n"); + return AVERROR_INVALIDDATA; + } else if (track->video.projection.private.size == 12) { + uint32_t layout = bytestream2_get_be32(&gb); + if (layout == 0) { + projection = AV_SPHERICAL_CUBEMAP; + } else { + av_log(NULL, AV_LOG_WARNING, + "Unknown spherical cubemap layout %"PRIu32"\n", layout); + return 0; + } + padding = bytestream2_get_be32(&gb); + } else { + av_log(NULL, AV_LOG_ERROR, "Unknown spherical metadata\n"); return AVERROR_INVALIDDATA; - projection = AV_SPHERICAL_CUBEMAP; + } break; default: return 0; @@ -1937,6 +1986,20 @@ 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 */ + size_t orig_width = (size_t) track->video.pixel_width * UINT32_MAX / (UINT32_MAX - r - l); + size_t orig_height = (size_t) track->video.pixel_height * UINT32_MAX / (UINT32_MAX - b - t); + + /* add a (UINT32_MAX - 1) to round up integer division */ + spherical->bound_left = (orig_width * l + UINT32_MAX - 1) / UINT32_MAX; + spherical->bound_top = (orig_height * t + UINT32_MAX - 1) / UINT32_MAX; + spherical->bound_right = orig_width - track->video.pixel_width - spherical->bound_left; + spherical->bound_bottom = orig_height - track->video.pixel_height - spherical->bound_top; + } + ret = av_stream_add_side_data(st, AV_PKT_DATA_SPHERICAL, (uint8_t *)spherical, spherical_size); if (ret < 0) { diff --git a/tests/ref/fate/matroska-spherical-mono b/tests/ref/fate/matroska-spherical-mono index 8048aff..a70d879 100644 --- a/tests/ref/fate/matroska-spherical-mono +++ b/tests/ref/fate/matroska-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