From patchwork Tue Sep 28 21:20:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: quietvoid X-Patchwork-Id: 30647 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6506:0:0:0:0:0 with SMTP id z6csp5615615iob; Tue, 28 Sep 2021 14:21:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGrGbsmUTLre7eAy320VynajthtWJ/pG3lH3MobwhG7Zq/+1DwZxya3QB7lq7q79HLAODO X-Received: by 2002:a17:906:a246:: with SMTP id bi6mr9187720ejb.389.1632864108961; Tue, 28 Sep 2021 14:21:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632864108; cv=none; d=google.com; s=arc-20160816; b=SF1udz5I2MhRp+XecumtameZ2NKKx+JIQ2K3NbUqOyOShFbMgW7zudls0gDbxrO9B1 IcvFROsdhMEtZ//mHnzC4PLx9FT46duQFXof0Va4otSVFIUPNtBzinqAQSg4CofaGGMQ RyzqjT+uYzG4sKbUzAtwcbcVX6P7wq0lP91D+LVkdphk1QQh0mOL+l55eGlQONCAEK8Z QPZFrrfhTm7OwZ8mMXvEmT/wnM0RZo6evPAYk100jmzimcjcimdIPizbxtVAlCoEZ3DJ 0NED+nXP5/RsOfFxKY1Y0nQ/ZXOkHpCB/3g/DJ2gyubNZQCavPmXwoKqiMe0z4V20GdZ BtFA== 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:message-id:date:to:from :dkim-signature:delivered-to; bh=P18sEIw6uTEUIQPqDZB61uwSaQStolqBjsBCBre9kTY=; b=nljw9fY6/ldW9HUlB34TCovzBdfDjVpN6Qn6fgnaodq/JnoQ1q/B8sSHBuBBtTuUxl YTt9TeJeGt8bWVkNlKwX7lWrhEZAiH2+BKMqj0W3T1I9JZoRRyfhMnRlwr78NugOk+mS gZiNfIT4HopwIV2hCRL/vZwCjxDBTBkjFYBpvRph+vD6UsMLe0QaVYlbZVL5bsSVGqMg QKxiMSpq50Uag6BfmehcdimyVSLWzrN0lXNNe0yJnBNoukkClwcTUng72tj9ecedpQ8B mtOzrgvep3nonXrxaNji7asG3ob7NI3zGy6MiN++9Uu2BUd6+2Dw6NLImxao+UMdzLs1 Z2dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=eE2KaqY8; 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 fx1si253632ejb.310.2021.09.28.14.21.25; Tue, 28 Sep 2021 14:21:48 -0700 (PDT) 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=eE2KaqY8; 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 2D88268A6C5; Wed, 29 Sep 2021 00:21:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1B2E368024D for ; Wed, 29 Sep 2021 00:21:15 +0300 (EEST) Received: by mail-wm1-f41.google.com with SMTP id j27so166605wms.0 for ; Tue, 28 Sep 2021 14:21:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=p33KIbxEH5RKS0gH7622Q+rTpXP7BNkxPQD3PpMI3uo=; b=eE2KaqY8ksBJX2dZ54/b8DC2coO+tWoGZd4DLh0+uxjGjM1/2jVs6WsoOnkgAm4KvY +BWlgajBROiJ4R9KJlRwUCY1klMJia0u2HfmJpzdMlX+/poL02e864KWmLHhjWnnERoR NOADu8KosobLVWVfAyhuyEllOsSfTPZfZF8wFZhpkaqs8BnRy4aamFJl/Ul3qVlemGWE rqmtvGYgKkvkT2QJvFLKPHfaUY7eTYcAC41gbzvjUCdWTloiVsDwhZpzr/Rf9vrkXuJJ Z32Hwk1mbvwCFS/GGhnCPZteG+EUocxblvYozh4AbM4+n2eaS7rK07zCu+PeCrRD131o Ztug== 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:mime-version :content-transfer-encoding; bh=p33KIbxEH5RKS0gH7622Q+rTpXP7BNkxPQD3PpMI3uo=; b=ggLfdIMS6a3SKXRKBRNx/qDehCs/xS5E+39DMjGP5lzbmRPYaUXB6cUI6cIddWfi7v y4JjWLxwspAezW9p55ZIMD4ZqYDNt4n8K+s4WSqVa3SV6jfgdarUD/ubC25CqdCbsRzH pV0jGlvaAp6/pJHWPKXdeCPz+kfITAl2Lqr6odXO3PqKKkR1gZXWGKhihZ+MRCo4FK5Y 2rNmlYw2UBBiBx+AV0Y3+9SBdjFGh+D8+aygfadIrQ3A7ZweAUHZIjs5FofkaimKZGET rC9fYolvA5r0UPt9JN7alVZWFq4pm1+/50ukCwxTaxy8mnXFb/g+wJh+FGSwrelqae0I TIAg== X-Gm-Message-State: AOAM530X9ohQhRGTzTZUDss7oLQlfKFpvhZw5LGNWWn1/64vXWqCgPgL 7k0K1zooJc1adpDaO4wicSuToVUHR1E9Uw== X-Received: by 2002:a1c:4407:: with SMTP id r7mr6932195wma.8.1632864074288; Tue, 28 Sep 2021 14:21:14 -0700 (PDT) Received: from localhost.localdomain ([2a01:4f8:162:73cc::2]) by smtp.gmail.com with ESMTPSA id d24sm148419wmb.35.2021.09.28.14.21.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Sep 2021 14:21:14 -0700 (PDT) From: quietvoid X-Google-Original-From: quietvoid To: ffmpeg-devel@ffmpeg.org Date: Tue, 28 Sep 2021 23:20:53 +0200 Message-Id: <20210928212056.328511-1-tcChlisop0@gmail.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 1/4] 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: 7u0HiAxtbc45 According to specification "Dolby Vision Stream Within the ISO Base Media File Format Version 2.2" 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 MOV/MPEG TS to parse the DOVI box/descriptor using dovi_isom. Signed-off-by: quietvoid --- libavformat/dovi_isom.c | 133 ++++++++++++++++++++++++++++++++++++++++ libavformat/dovi_isom.h | 36 +++++++++++ 2 files changed, 169 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..4f204d3dec --- /dev/null +++ b/libavformat/dovi_isom.c @@ -0,0 +1,133 @@ +/* + * 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 + */ + +#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, + int has_dependency_pid) +{ + uint32_t buf; + AVDOVIDecoderConfigurationRecord *dovi; + size_t dovi_size; + int ret; + int min_compat_size; + + 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 + + // For MPEG2 TS + if (has_dependency_pid && !dovi->bl_present_flag) { + // dependency_pid 13 bits + reserved 3 bits + buf = *buf_ptr++ << 8; + buf |= *buf_ptr++; + + min_compat_size = 7; + } else { + min_compat_size = 5; + } + + // Has enough remaining data + if (size >= min_compat_size) { + 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, 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; + init_put_bits(&pb, out, size); + + if (size < ISOM_DVCC_DVVC_SIZE) + return AVERROR(EINVAL); + + 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 > 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..e1c6d6d63a --- /dev/null +++ b/libavformat/dovi_isom.h @@ -0,0 +1,36 @@ +/* + * 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 has_dependency_pid); +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 */