From patchwork Sat Dec 4 01:09:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: quietvoid X-Patchwork-Id: 31950 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp1426701iog; Fri, 3 Dec 2021 17:09:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJxeJZcUsvL8mVayODUF0h9Yk5u6q/ExWrjLO/5kHEzQHq/BRbLjh3vzYH+17GAsxF5z+I8W X-Received: by 2002:a05:6402:339:: with SMTP id q25mr31434908edw.251.1638580180004; Fri, 03 Dec 2021 17:09:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638580179; cv=none; d=google.com; s=arc-20160816; b=ePvN3or2OQzHtudzQCeQiMwDFIhAP+B9j3GcTxT3bJ/5WDccAazpb6OWjBaEVLylkq GS1RLFsDfl8JhISbxorb0HsXFChCiAJH4+iEWb2DaD4SprNzXwXLIJv1+aeV+9+apaU1 DVWoVrmal/naP+jl8tEL6dyNAlG7dBVZXANJ80h1OqLHcY56M1XjNWE1nRk4gC41SSSp uFIKhZrPZdSXhN0KM9dsSYOYriIDuFEiIcHug/K6LKU94pyofZTZeWSAlXc0bbxuYJgL hFGuCBhTwa0H4qVX33FCn+lAX0LSUGoLZ0gVbnlroZxFofim5Kb8h3YzaWgf9jq+xsGX rR/A== 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=OllAzC8zqcqdDyQJK1uwEzgZ+7kizblkHt9I/lCIDk8=; b=sOQFC3xXSUzOkdFHqIu7oKwVjMZM6eEC2sh0tuU1gpgyDdvwUS2TWNe1FgQ6q6YCb4 mx1MyUraVIRQWMprqMglTATAo0KW++0ZH7671Us6Ugtd85AmJycKdp8zLHup7DAmSpSe GVYA583fHje9Ii9z3pkfkutzwX9tATFQUN8JirKRcemxzEWBBbBs6Lr0TItijhUgj657 bSBtSQHk87+4VMNLlU0MRuaU4QjSfkZ2OQXGWY4Rf32mBQQk95qvOONgu0Tu5NUHz/Kl dntMf5yLNfe03X3vpdHqeVbBfD+jGdFZc/CO6H6zMnO4dZf1IKatHbpe6Bjig9vNFe/r cNBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=oFmIep0J; 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 z3si8166705edl.489.2021.12.03.17.09.39; Fri, 03 Dec 2021 17:09:39 -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=oFmIep0J; 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 559C168A8D9; Sat, 4 Dec 2021 03:09:26 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A512068A8D9 for ; Sat, 4 Dec 2021 03:09:19 +0200 (EET) Received: by mail-wm1-f49.google.com with SMTP id 133so3763004wme.0 for ; Fri, 03 Dec 2021 17:09:19 -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=0nVp0zH3noeH5kl3Ej14lkzrnZIvokf1HbsV0YFVKaE=; b=oFmIep0Juutp5R5bgYRo7ZvZxR8sLuu9u+2mLSEtfJuhHgygPrztq2IiTCkLapif37 j7EXs6vjZt3iZvtFQhnePSiNHNFuJOyNgJCMlDGBIBk6v+HPLiX5NcLwmbHYAUm2GEdp UvOq/IAXFm0a1F4ernTTKpXZ7fVaoGdIXTpNFl3wOYjHT5bI0hnT1IP38rtON1XP9C0j FsNDmgrBGyq20tXXQQyNBg4/QjQXr4YuTDJK0p1DorwFIOdinkwE+Y0kN/nwpcyfTgPe 364lPtf6bhS8bOPevp0UFt2qUqkHyqN0Xc8naCGFH3OX3anI5vcxbXCJypcWcvzcYCgO /95g== 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=0nVp0zH3noeH5kl3Ej14lkzrnZIvokf1HbsV0YFVKaE=; b=NkclHLq6mmj6A4tm8+q+La2uEoyiy6+4k9ar51m6JNBM/dHag49JVjD54Xj1BPVcvd WuZhTHzPWPmbpoX7Q2K6oXIt75M93zxxMUNTkSeQ3To6M5j1atxR/39aeormVlx5BeOX BAsQ9aAyks+V1Kpdoabj5Zh5cb5+Pizclo2Y2evSmuzoJvh9YmbMHz9ni9zIceq9+NKv QgNpcsVOTQ1go99svchpHo5mD6hROD6tW+QkcXHB+r+FSoys9K2KGfO7kiwGTcsIKt6M cGVGmB2MguVPH9A1RMqZMfMPguG9xU/8QKkhKDqmeh/4l8h6aJIdolhcGApM9dV9bWUv iTFA== X-Gm-Message-State: AOAM530Atkheqt4w5g71p2oAShf47iDj6P1j9I2qjJ4qrNUwjUn4hBbX 9SXlFOnBWDCqqUZVKpaBVDR6YxsPbeSkXA== X-Received: by 2002:a1c:488:: with SMTP id 130mr19490320wme.157.1638580158929; Fri, 03 Dec 2021 17:09:18 -0800 (PST) Received: from localhost.localdomain ([2a01:4f8:162:73cc::2]) by smtp.gmail.com with ESMTPSA id d8sm3873739wrm.76.2021.12.03.17.09.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 17:09:18 -0800 (PST) From: quietvoid X-Google-Original-From: quietvoid To: ffmpeg-devel@ffmpeg.org Date: Sat, 4 Dec 2021 02:09:01 +0100 Message-Id: <20211204010905.2258652-2-tcChlisop0@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211204010905.2258652-1-tcChlisop0@gmail.com> References: <20211204010905.2258652-1-tcChlisop0@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v8 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: qypa/cJQK/mq 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 | 123 ++++++++++++++++++++++++++++++++++++++++ libavformat/dovi_isom.h | 35 ++++++++++++ 2 files changed, 158 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..679c913730 --- /dev/null +++ b/libavformat/dovi_isom.c @@ -0,0 +1,123 @@ +/* + * 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; +} + +int ff_isom_put_dvcc_dvvc(AVFormatContext *s, uint8_t out[ISOM_DVCC_DVVC_SIZE], uint64_t size, + AVDOVIDecoderConfigurationRecord *dovi) +{ + PutBitContext pb; + + if (size < ISOM_DVCC_DVVC_SIZE) + return AVERROR(EINVAL); + + init_put_bits(&pb, out, size); + + put_bits(&pb, 8, dovi->dv_version_major); + put_bits(&pb, 8, dovi->dv_version_minor); + put_bits(&pb, 7, dovi->dv_profile); + put_bits(&pb, 6, dovi->dv_level); + 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); + + 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); + + return put_bytes_output(&pb); +} diff --git a/libavformat/dovi_isom.h b/libavformat/dovi_isom.h new file mode 100644 index 0000000000..d33e436a4f --- /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); +int ff_isom_put_dvcc_dvvc(AVFormatContext *s, uint8_t out[ISOM_DVCC_DVVC_SIZE], uint64_t size, + AVDOVIDecoderConfigurationRecord *dovi); + +#endif /* AVFORMAT_DOVI_ISOM_H */