From patchwork Tue Nov 15 16:56:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vittorio Giovara X-Patchwork-Id: 1438 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.90.1 with SMTP id o1csp1699903vsb; Tue, 15 Nov 2016 08:57:03 -0800 (PST) X-Received: by 10.194.122.101 with SMTP id lr5mr24817138wjb.210.1479229023198; Tue, 15 Nov 2016 08:57:03 -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 qf11si29213981wjb.173.2016.11.15.08.57.02; Tue, 15 Nov 2016 08:57:03 -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 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 E2676689FFE; Tue, 15 Nov 2016 18:56:59 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk0-f195.google.com (mail-qk0-f195.google.com [209.85.220.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2393D689C8E for ; Tue, 15 Nov 2016 18:56:53 +0200 (EET) Received: by mail-qk0-f195.google.com with SMTP id x190so17216623qkb.0 for ; Tue, 15 Nov 2016 08:56:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=yLXd7vvQVAxcP6ewwpRh8TH+PHw1sFrR/YqJPWKuOhw=; b=iWeCozRZbFEZhZsBHdp8N7d+555h3tFMMIFEdEfS5dZL90EDygOSV5V+gBnljZJMl1 RCpFvpSmFPacGiAeP73iirQwyXEoRiu78TrKhh7IMVp4k7BtdJveTmJPMiiQwXHqS4do fUna/P78GA2VK1BL6XxYWpRc1KzEHaRAFE3EFXGNld+VuuWLLJNT9iVDw8RJKh+BRWzK nqGDAgY6zp8GV6IvhqQcv/gR7YiouvYlwv73CL34J829SmwLmfGdHOmS4dMnJHiaNmhK KDv0TGVLyi8SziD/TKP3u6GaytFmnmxoyymeArk2ADRobHTLXfuL71/C/274W4wtf53O 5CDA== 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; bh=yLXd7vvQVAxcP6ewwpRh8TH+PHw1sFrR/YqJPWKuOhw=; b=mbg/Kf1vJal1D38M+gJHhrr8uJw0O23fb0UnjXrCVq9mVMy0dyha5xLZBQKdPmRNHp tDkjVXpIvD0EKUESbspthrPPULS9I1G63ytLvyJ5GdT4csRcwsPBg03jFuFknZkCmZ16 pM+NpoD1fw87830K7hHhhZgF5GaJVaNPgXuEHsm3m0ftMTy9xnSEv/BXDRvsHB+ekiUi dl36/qq4mQESnGglSQS4vK8FZhhxoL0y8L8CtwsWI/Z8jZcsEa+CyYSsxiIVPrzZUwNB 5U8W6NKyU35/lR9bKs4PQPLHeODfnIOXbY4jQj9iZPjfV3THcR+eSFA1fu3BJaLEayd5 aByA== X-Gm-Message-State: ABUngvejd6d45w7oIyzIm5ju3e6DUKR9Txllt5U6HlGWD2Z6qzueCf0l38/QkNwjmXdyng== X-Received: by 10.233.237.147 with SMTP id c141mr21602885qkg.175.1479229011650; Tue, 15 Nov 2016 08:56:51 -0800 (PST) Received: from vimacbookpro.vimeows.com (nyv-exweb.iac.com. [216.112.252.10]) by smtp.gmail.com with ESMTPSA id b198sm15503930qkc.42.2016.11.15.08.56.50 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 15 Nov 2016 08:56:51 -0800 (PST) From: Vittorio Giovara To: ffmpeg-devel@ffmpeg.org Date: Tue, 15 Nov 2016 11:56:48 -0500 Message-Id: <20161115165650.5720-1-vittorio.giovara@gmail.com> X-Mailer: git-send-email 2.10.0 Subject: [FFmpeg-devel] [PATCH 1/3 v2] lavu: Add AVSphericalMapping type and frame side data 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" While no decoder currently exports spherical information, this type represents a frame property that has to be passed through from container to frames. Signed-off-by: Vittorio Giovara --- Updated to use int32 for rotation. Please CC. Vittorio libavutil/Makefile | 2 + libavutil/avutil.h | 6 +++ libavutil/frame.h | 8 ++- libavutil/spherical.c | 34 ++++++++++++ libavutil/spherical.h | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 libavutil/spherical.c create mode 100644 libavutil/spherical.h diff --git a/libavutil/Makefile b/libavutil/Makefile index 0fa90fe..c5af79a 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -63,6 +63,7 @@ HEADERS = adler32.h \ samplefmt.h \ sha.h \ sha512.h \ + spherical.h \ stereo3d.h \ threadmessage.h \ time.h \ @@ -140,6 +141,7 @@ OBJS = adler32.o \ samplefmt.o \ sha.o \ sha512.o \ + spherical.o \ stereo3d.o \ threadmessage.o \ time.o \ diff --git a/libavutil/avutil.h b/libavutil/avutil.h index 29dd830..e9aaa03 100644 --- a/libavutil/avutil.h +++ b/libavutil/avutil.h @@ -118,6 +118,12 @@ * * @} * + * @defgroup lavu_video Video related + * + * @{ + * + * @} + * * @defgroup lavu_audio Audio related * * @{ diff --git a/libavutil/frame.h b/libavutil/frame.h index 8e51361..b450092 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -120,7 +120,13 @@ enum AVFrameSideDataType { * The GOP timecode in 25 bit timecode format. Data format is 64-bit integer. * This is set on the first frame of a GOP that has a temporal reference of 0. */ - AV_FRAME_DATA_GOP_TIMECODE + AV_FRAME_DATA_GOP_TIMECODE, + + /** + * The data represents the AVSphericalMapping structure defined in + * libavutil/spherical.h. + */ + AV_FRAME_DATA_SPHERICAL, }; enum AVActiveFormatDescription { diff --git a/libavutil/spherical.c b/libavutil/spherical.c new file mode 100644 index 0000000..816452c --- /dev/null +++ b/libavutil/spherical.c @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2016 Vittorio Giovara + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "mem.h" +#include "spherical.h" + +AVSphericalMapping *av_spherical_alloc(size_t *size) +{ + AVSphericalMapping *spherical = av_mallocz(sizeof(AVSphericalMapping)); + if (!spherical) + return NULL; + + if (size) + *size = sizeof(*spherical); + + return spherical; +} diff --git a/libavutil/spherical.h b/libavutil/spherical.h new file mode 100644 index 0000000..6d5a316 --- /dev/null +++ b/libavutil/spherical.h @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2016 Vittorio Giovara + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * Spherical video + */ + +#ifndef AVUTIL_SPHERICAL_H +#define AVUTIL_SPHERICAL_H + +/** + * @addtogroup lavu_video + * @{ + * + * @defgroup lavu_video_spherical Spherical video mapping + * @{ + */ + +/** + * @addtogroup lavu_video_spherical + * A spherical video file contains surfaces that need to be mapped onto a + * sphere. Depending on how the frame was converted, a different distortion + * transformation or surface recomposition function needs to be applied before + * the video should be mapped and displayed. + */ + +/** + * Projection of the video surface(s) on a sphere. + */ +enum AVSphericalProjection { + /** + * Video represents a sphere mapped on a flat surface. + */ + AV_SPHERICAL_EQUIRECTANGULAR, + + /** + * Video frame is split into 6 faces of a cube, and arranged on a + * 3x2 layout. Faces are oriented upwards for the front, left, right, + * and back faces. The up face is oriented so the top of the face is + * forwards and the down face is oriented so the top of the face is + * to the back. + */ + AV_SPHERICAL_CUBEMAP, +}; + +/** + * This structure describes how to handle spherical videos, outlining + * information about projection, initial layout, and any other view modifier. + * + * @note The struct must be allocated with av_spherical_alloc() and + * its size is not a part of the public ABI. + */ +typedef struct AVSphericalMapping { + /** + * Projection type. + */ + enum AVSphericalProjection projection; + + /** + * @name Initial orientation + * @{ + * These fields represent the pose values that measure the rotation + * transformation (in degrees) to be applied to the projection. + * They are exported as 16.16 fixed point. + * + * See this equirectangular projection as example: + * + * @code{.unparsed} + * Yaw + * -180 0 180 + * 90 +-------------+-------------+ 180 + * | | | + * P | | o> | + * i | ^ | + * t 0 +-------------X-------------+ 0 Roll + * c | | | + * h | | | + * | | | + * -90 +-------------+-------------+ -180 + * + * X - the default camera center + * ^ - the default up vector + * > - the up vector for a rotation of 90 degrees + * o - the image center for yaw = 90, pitch = 45, roll = 0 + * @endcode + * + * The order of transformation is always yaw, followed by pitch, and + * finally by roll. + */ + int32_t yaw; ///< Clockwise rotation around the up vector [-180, 180]. + int32_t pitch; ///< Counter-clockwise rotation around the right vector [-90, 90]. + int32_t roll; ///< Counter-clockwise rotation around the forward vector [-180, 180]. + /** + * @} + */ + + /** + * @name Bounding rectangle + * @{ + * These fields are the amount of pixels to crop from the edge + * of the video surface. + * + * @note For cubemap projections these values apply to each + * face of the cube. + */ + unsigned int left_offset; ///< Pixels to crop from the left edge. + unsigned int top_offset; ///< Pixels to crop from the top edge. + unsigned int right_offset; ///< Pixels to crop from the right edge. + unsigned int bottom_offset; ///< Pixels to crop from the bottom edge. + /** + * @} + */ +} AVSphericalMapping; + +/** + * Allocate a AVSphericalVideo structure and initialize its fields to default + * values. + * + * @return the newly allocated struct or NULL on failure + */ +AVSphericalMapping *av_spherical_alloc(size_t *size); + +/** + * @} + * @} + */ + +#endif /* AVUTIL_SPHERICAL_H */