From patchwork Fri Jan 1 21:35:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 24736 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 5DF9E44BCD1 for ; Fri, 1 Jan 2021 23:38:09 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 44FC668A8F3; Fri, 1 Jan 2021 23:38:09 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8F13668A84E for ; Fri, 1 Jan 2021 23:38:07 +0200 (EET) Received: by mail-wm1-f46.google.com with SMTP id 190so9871821wmz.0 for ; Fri, 01 Jan 2021 13:38:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=OlCfh+ttkuxvG7JkKZ/vpFyeXLMz1OYzlbA8aC1TvL8=; b=bDoY4VUWSeXatG2qRLtOIy9b1BsSLAfflO84tG0Uf5DbR6ZrxlS1aZVfNMCIz/XzBy +muBQOPC938BEJfm3rP+iDVwheEurpsCYbaXL9QSWWulKbKiarn60IHHC/O6GvQQsMc9 8sWZ4gnPL0/vGKULXmmnp67r7RbvmVEntp23m4ZGKH7LxXXuugWHNMquSxtQow39Foeu Y2KAN53FGZsQRIvaeaJAThcgku02WLT/1/bD0rmo82l9F/I+kZNTQX/fWjaMRpKKPNyW aMzbpHmAwZcy9uo9zMJHKZ8eqHEFGHnCAfCrRRNmYp3e26Lscp2dV/McCd6M4f2wDeen GeBw== 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:mime-version:content-transfer-encoding; bh=OlCfh+ttkuxvG7JkKZ/vpFyeXLMz1OYzlbA8aC1TvL8=; b=O3Jsx+5qNaw6m4Pr+vuIRYFKJz0OYX/Vmrwpct5j9MFCTaoDiQBvUyWxRixGEG4rgu ZZL7AkV95oxrj7Uc+ik3W81I81n1V5A8LSA2naP4n87ieU+exXsQ5+oI6v9iVNEqHR51 4iRfIDbFggyiI5o6G6Z7n83XYWVikxuP64zyrgzoC2xcD68E2fpHgtlguZPwVK1Ic5sN c6RT6lXCFxCCyhIaEda6ZssI8GFq1qc4k5tRtA2cXTOd82muqafvGWNT8UkobMaSAgFi Tn4DyD2sx3qaLO4ZLTa1Igyd7Vur271HuNXDfoNCL891JNDiOZiJmdXho2LwGylHShjd 6SwQ== X-Gm-Message-State: AOAM533+g8UBGv1k+bA9tv/HqM5lBGwgI65keX/ZoCS9Fz0/2kAYsU13 gFCwGJ3nRck51/yyK6qrJTZcU3Kfn0Gn1Q== X-Google-Smtp-Source: ABdhPJwUeqKxGaIjcp25ceOcJpFCXkxeCTSoc91bITqk4gOhKd16Y5OnhjyM5iWzNS7VWQXbt9s+0A== X-Received: by 2002:a05:600c:2158:: with SMTP id v24mr16685393wml.129.1609537086683; Fri, 01 Jan 2021 13:38:06 -0800 (PST) Received: from localhost.localdomain (cpc91226-cmbg18-2-0-cust7.5-4.cable.virginm.net. [82.0.29.8]) by smtp.gmail.com with ESMTPSA id v20sm18784595wml.34.2021.01.01.13.38.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Jan 2021 13:38:06 -0800 (PST) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Fri, 1 Jan 2021 21:35:27 +0000 Message-Id: <20210101213537.169546-18-sw@jkqxz.net> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210101213537.169546-1-sw@jkqxz.net> References: <20210101213537.169546-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 17/27] cbs_h264: Implement fill and extract for display orientation SEI message 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" --- libavcodec/cbs_h2645.c | 64 ++++++++++++++++++++++++++++++++++++++++++ libavcodec/cbs_sei.c | 2 ++ 2 files changed, 66 insertions(+) diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index 53d5b50b42..4144948b7f 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -18,6 +18,7 @@ #include "libavutil/attributes.h" #include "libavutil/avassert.h" +#include "libavutil/display.h" #include "libavutil/mastering_display_metadata.h" #include "bytestream.h" @@ -1674,6 +1675,68 @@ static const SEIMessageTypeDescriptor cbs_sei_common_types[] = { SEI_MESSAGE_TYPE_END, }; +static void cbs_h264_fill_sei_display_orientation + (H264RawSEIDisplayOrientation *disp, const int32_t matrix[9]) +{ + double dmatrix[9]; + int hflip, vflip, i; + double scale_x, scale_y, angle; + + if (matrix[2] != 0 || matrix[5] != 0 || + matrix[6] != 0 || matrix[7] != 0) { + // Not representable. + return; + } + + for (i = 0; i < 9; i++) + dmatrix[i] = matrix[i] / 65536.0; + + // Extract scale factors. + scale_x = hypot(dmatrix[0], dmatrix[3]); + scale_y = hypot(dmatrix[1], dmatrix[4]); + + // Select flips to make the main diagonal positive. + hflip = dmatrix[0] < 0.0; + vflip = dmatrix[4] < 0.0; + if (hflip) + scale_x = -scale_x; + if (vflip) + scale_y = -scale_y; + + // Rescale. + for (i = 0; i < 9; i += 3) { + dmatrix[i] /= scale_x; + dmatrix[i + 1] /= scale_y; + } + + // Extract rotation. + angle = atan2(dmatrix[3], dmatrix[0]); + + if (!(angle >= -M_PI && angle <= M_PI)) { + // Not representable. + return; + } + + *disp = (H264RawSEIDisplayOrientation) { + .hor_flip = hflip, + .ver_flip = vflip, + .anticlockwise_rotation = + (uint16_t)rint((angle >= 0.0 ? angle + : angle + 2 * M_PI) * + 32768.0 / M_PI), + .display_orientation_repetition_period = 1, + }; +} + +static void cbs_h264_extract_sei_display_orientation + (int32_t matrix[9], const H264RawSEIDisplayOrientation *disp) +{ + av_display_rotation_set(matrix, + disp->anticlockwise_rotation * + 180.0 / 65536.0); + av_display_matrix_flip(matrix, disp->hor_flip, disp->ver_flip); +} + static const SEIMessageTypeDescriptor cbs_sei_h264_types[] = { { SEI_TYPE_BUFFERING_PERIOD, @@ -1704,6 +1767,7 @@ static const SEIMessageTypeDescriptor cbs_sei_h264_types[] = { 1, 0, sizeof(H264RawSEIDisplayOrientation), SEI_MESSAGE_RW(h264, sei_display_orientation), + SEI_MESSAGE_FE(h264, sei_display_orientation), }, SEI_MESSAGE_TYPE_END }; diff --git a/libavcodec/cbs_sei.c b/libavcodec/cbs_sei.c index 0c05b2bdc9..9ea00dd724 100644 --- a/libavcodec/cbs_sei.c +++ b/libavcodec/cbs_sei.c @@ -379,6 +379,8 @@ static const SEIMetadata cbs_sei_metadata[] = { SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME }, { CBS_METADATA_CONTENT_LIGHT_LEVEL, SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO }, + { CBS_METADATA_DISPLAY_MATRIX, + SEI_TYPE_DISPLAY_ORIENTATION }, }; static const SEIMessageTypeDescriptor *cbs_sei_find_type_from_metadata