From patchwork Sat Jan 1 04:16:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: quietvoid X-Patchwork-Id: 32980 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp14457928iog; Fri, 31 Dec 2021 20:16:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJzNn+yiBTGjHeh9ntVMGupTEcds20vkx9LsTFETpVTCF9dmpoTHysSUN7EpCMbM3LsIbBEk X-Received: by 2002:aa7:dbc2:: with SMTP id v2mr2735179edt.59.1641010606034; Fri, 31 Dec 2021 20:16:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641010606; cv=none; d=google.com; s=arc-20160816; b=CWrkaF5xVv1/pESAx38rABD8M/ZaNkridP5lP16Tb65Fka+/suZKp94sH8437drXOq YUWLpI3hDTd6M5ISEIwd4bNYUlxFfwH17/1Ai3J0RpHtf5EyGhKhbsBusvKT6Dpru9tC T1bP0wKCHS9B8WwQiIOWdoyZZA8Y8cdATKgYy+hVGhWBQtrkh7Aw/Bhwv8wQGXNyyzNV t+Cx5LAeDODB1i7uNcPPv8O7CkgLvMCHRf0P1hoBcpyGdAGFylk+SAyrdHhrLsLKxh1N 9IR4uZmt6e/joaLryDEK0KsbHvBqzS/5D0gBpldLtb2YpnDLqyBe7qKlXLNND77o78/2 dOow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=0dYtlbNYjWlepiBHZ2a81qgDHUdHQhsuC5SfxI/JOzc=; b=aleYXpNoZaGh8N0oF2t50oH9JVm3TpJ6z8w8ingCPXJFAmG0dkZxPponS2j24eGGbb adPJPr5aGKTsamcYa6+OdLZgz4OkLEbUWEo5bz/IGnjl62P+fWMsEulnRwfjD8+glPz5 FIC1i7m/MGaLhVDDn3dC1kYb7nmA8rQolq/vk2TekaRmHeZXafntNwayD/LNAd1pW5wI k5arQNHXccYcHQcdgGBy29wgySeRZfPwIUA0bwbwOefbR2huS7KzvGFKZAGDTbb+5vTK XlpytWak5rmRYJ6R1NUMDyNwWcaowPGGoOtQTmIgMl29fyf06YEdBpmv1zoseUCkA1IU a3ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=HfWGLnIF; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id hr40si15916808ejc.598.2021.12.31.20.16.45; Fri, 31 Dec 2021 20:16:46 -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 header.s=20210112 header.b=HfWGLnIF; 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=QUARANTINE 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 A6E2868B0AE; Sat, 1 Jan 2022 06:16:32 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3929B68B050 for ; Sat, 1 Jan 2022 06:16:25 +0200 (EET) Received: by mail-ed1-f48.google.com with SMTP id x15so114674642edv.1 for ; Fri, 31 Dec 2021 20:16:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ppbzzMPoQ4+GXkoF0Qk6Dv0DYRMHOhTLXvDtY4A8Eoo=; b=HfWGLnIFfAApHDHEgxuAb6vE0dvHApQTLNKyMo8dpFQM9RjzYvZJj8OMLl9luXmWmv u1ChzhPHxIqCSq8lPk5nD1fsyschhNXIunVST+ebOKagj1IBtoi552PU/Rd8Z4FGIjfY 9hAKLIe8mdWTWuK2wLOqgWAuoYwzLjJuA2awne2cYZurUtLVTaoEnHTVOMK/8hmrQOrG mG8aj+FKzbUrCsmodrtn3JgCoxhmohdoI6+PqPwQO0qb1iN8o7KaTTx/mZfSpoCcEYAS hbQ5pckDCJRU/zxTkbw4PjzsP7OhrI49BznevWcn8tkZ9jo4hJo9M1pAKdGWRrZyQO8w U0uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ppbzzMPoQ4+GXkoF0Qk6Dv0DYRMHOhTLXvDtY4A8Eoo=; b=in/u0VuY6/m+q3waMYr9puhPJup9D0vNNKTRdQPY6/RUFgr5f5W40E/bYXNIcr7MAn gh6z5cubWU3hmfI0ytINVyLLn8dXfaWybG20JGF3pSjNYwGLhlJHrwQ/Ks6yFtr47S1n eu+8RqQAsTy9VaQJyD8OhBfDvcJAZ7R7kdsW6f5PRG02k4Mpb5ZuH8wOte9iU1yp1Vnp SMOiYvWxG3ABOF+QBcO7PVi/e6UYodwQO7wBjeuNyrgpz2lStameM6PKk97r5L1mQceP LX3fQnAs3DWng/GHsTfJNm+mKeXdluxJ0fq0WV2QyNQyBly8cMUi619RSvJsqJvemK5u YnCA== X-Gm-Message-State: AOAM532IyU+2JyT9pB2VWrKtO6JAWqnHWF7cVTyES+d35TKHvXHI78Vi ZbkRXX5sDRy2+EKvRugrNaAqA2PS6do= X-Received: by 2002:aa7:c4d3:: with SMTP id p19mr4552775edr.186.1641010584481; Fri, 31 Dec 2021 20:16:24 -0800 (PST) Received: from nark.. ([2a01:4f8:162:73cc::2]) by smtp.gmail.com with ESMTPSA id z18sm11272075edc.76.2021.12.31.20.16.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Dec 2021 20:16:24 -0800 (PST) From: quietvoid X-Google-Original-From: quietvoid To: ffmpeg-devel@ffmpeg.org Date: Sat, 1 Jan 2022 05:16:17 +0100 Message-Id: <20220101041621.427012-2-tcChlisop0@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220101041621.427012-1-tcChlisop0@gmail.com> References: <20220101041621.427012-1-tcChlisop0@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v11 1/5] avformat/dovi_isom: Implement Dolby Vision configuration parsing/writing X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Cc: quietvoid Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: j2eYtyG5nBFA Both parse/write implementations are based on mov/movenc. This only adds support for the "Dolby Vision configuration box". Other configuration boxes, such as "Dolby Vision enhancement layer configuration box" are not supported. The new functions will be used to implement parsing/writing the DOVI config for Matroska, as well as to refactor both mov/movenc to use dovi_isom functions. Signed-off-by: quietvoid --- libavformat/dovi_isom.c | 118 ++++++++++++++++++++++++++++++++++++++++ libavformat/dovi_isom.h | 35 ++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 libavformat/dovi_isom.c create mode 100644 libavformat/dovi_isom.h diff --git a/libavformat/dovi_isom.c b/libavformat/dovi_isom.c new file mode 100644 index 0000000000..76681b9451 --- /dev/null +++ b/libavformat/dovi_isom.c @@ -0,0 +1,118 @@ +/* + * DOVI ISO Media common code + * + * Copyright (c) 2020 Vacing Fang + * Copyright (c) 2021 quietvoid + * + * 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 "libavutil/dovi_meta.h" + +#include "libavcodec/put_bits.h" + +#include "avformat.h" +#include "dovi_isom.h" + +int ff_isom_parse_dvcc_dvvc(AVFormatContext *s, AVStream *st, const uint8_t *buf_ptr, uint64_t size) +{ + uint32_t buf; + AVDOVIDecoderConfigurationRecord *dovi; + size_t dovi_size; + int ret; + + if (size > (1 << 30) || size < 4) + return AVERROR_INVALIDDATA; + + dovi = av_dovi_alloc(&dovi_size); + if (!dovi) + return AVERROR(ENOMEM); + + dovi->dv_version_major = *buf_ptr++; // 8 bits + dovi->dv_version_minor = *buf_ptr++; // 8 bits + + buf = *buf_ptr++ << 8; + buf |= *buf_ptr++; + + dovi->dv_profile = (buf >> 9) & 0x7f; // 7 bits + dovi->dv_level = (buf >> 3) & 0x3f; // 6 bits + dovi->rpu_present_flag = (buf >> 2) & 0x01; // 1 bit + dovi->el_present_flag = (buf >> 1) & 0x01; // 1 bit + dovi->bl_present_flag = buf & 0x01; // 1 bit + + // Has enough remaining data + if (size >= 5) { + dovi->dv_bl_signal_compatibility_id = ((*buf_ptr++) >> 4) & 0x0f; // 4 bits + } else { + // 0 stands for None + // Dolby Vision V1.2.93 profiles and levels + dovi->dv_bl_signal_compatibility_id = 0; + } + + ret = av_stream_add_side_data(st, AV_PKT_DATA_DOVI_CONF, + (uint8_t *)dovi, dovi_size); + if (ret < 0) { + av_free(dovi); + return ret; + } + + av_log(s, AV_LOG_TRACE, "DOVI in dvcC/dvvC/dvwC box, version: %d.%d, profile: %d, level: %d, " + "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d\n", + dovi->dv_version_major, dovi->dv_version_minor, + dovi->dv_profile, dovi->dv_level, + dovi->rpu_present_flag, + dovi->el_present_flag, + dovi->bl_present_flag, + dovi->dv_bl_signal_compatibility_id); + + return 0; +} + +void ff_isom_put_dvcc_dvvc(AVFormatContext *s, uint8_t out[ISOM_DVCC_DVVC_SIZE], + AVDOVIDecoderConfigurationRecord *dovi) +{ + PutBitContext pb; + + init_put_bits(&pb, out, ISOM_DVCC_DVVC_SIZE); + + put_bits(&pb, 8, dovi->dv_version_major); + put_bits(&pb, 8, dovi->dv_version_minor); + put_bits(&pb, 7, dovi->dv_profile & 0x7f); + put_bits(&pb, 6, dovi->dv_level & 0x3f); + put_bits(&pb, 1, !!dovi->rpu_present_flag); + put_bits(&pb, 1, !!dovi->el_present_flag); + put_bits(&pb, 1, !!dovi->bl_present_flag); + put_bits(&pb, 4, dovi->dv_bl_signal_compatibility_id & 0x0f); + + put_bits(&pb, 28, 0); /* reserved */ + put_bits32(&pb, 0); /* reserved */ + put_bits32(&pb, 0); /* reserved */ + put_bits32(&pb, 0); /* reserved */ + put_bits32(&pb, 0); /* reserved */ + + flush_put_bits(&pb); + + av_log(s, AV_LOG_DEBUG, "DOVI in %s box, version: %d.%d, profile: %d, level: %d, " + "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d\n", + dovi->dv_profile > 10 ? "dvwC" : (dovi->dv_profile > 7 ? "dvvC" : "dvcC"), + dovi->dv_version_major, dovi->dv_version_minor, + dovi->dv_profile, dovi->dv_level, + dovi->rpu_present_flag, + dovi->el_present_flag, + dovi->bl_present_flag, + dovi->dv_bl_signal_compatibility_id); +} diff --git a/libavformat/dovi_isom.h b/libavformat/dovi_isom.h new file mode 100644 index 0000000000..1526164319 --- /dev/null +++ b/libavformat/dovi_isom.h @@ -0,0 +1,35 @@ +/* + * DOVI ISO Media common code + * Copyright (c) 2021 quietvoid + * + * 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 + */ + +#ifndef AVFORMAT_DOVI_ISOM_H +#define AVFORMAT_DOVI_ISOM_H + +#include "libavutil/dovi_meta.h" + +#include "avformat.h" + +#define ISOM_DVCC_DVVC_SIZE 24 + +int ff_isom_parse_dvcc_dvvc(AVFormatContext *s, AVStream *st, const uint8_t *buf_ptr, uint64_t size); +void ff_isom_put_dvcc_dvvc(AVFormatContext *s, uint8_t out[ISOM_DVCC_DVVC_SIZE], + AVDOVIDecoderConfigurationRecord *dovi); + +#endif /* AVFORMAT_DOVI_ISOM_H */