From patchwork Thu Sep 23 05:01:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: quietvoid X-Patchwork-Id: 30466 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6506:0:0:0:0:0 with SMTP id z6csp110617iob; Wed, 22 Sep 2021 22:02:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6GMTmb34sHpzeGmoFI7YL7gx22doHlX6rfLYCCbLqR3CgCkEtXvLUqDyOaD3mNvNtOtGr X-Received: by 2002:a50:9dcf:: with SMTP id l15mr3446534edk.128.1632373328508; Wed, 22 Sep 2021 22:02:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632373328; cv=none; d=google.com; s=arc-20160816; b=stSicjG2ok+sqoCrItoycUxBww39qmHFDQJKhjpmhI/2Qd7taxm5PQJEoNNCFdeyCK nm1LYBCg6f0tU/XSDiOEL1bv6UueUJqV+xn6JEA8jfCdc2Ulw1fek3i8VMa25FZMq207 jDYgb2F6GP4qMAK80/xHs1t5qYAsuBMhqzHL+mWK781HUH86Mt8T+6jkAAX4OH1XxV19 DEsDmLNqxMaAh7NUTfcspG7TRv2WvMbt9ZOm9AvSXLLNooYSHiuJlcCdb7CLEF9tuTmq rph6x84hvoXuYPZDJhMvLpNowdc1/4vUcueDSjKqXwuixA3C/mHXmgw9483SXRkxVsPd bqRQ== 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=2Ip9adznSspu73APJb03SzNt73NeyBJpFHZpBtUGnZo=; b=Z2J980LiusY+p40WjwPkMmJUr49iwe8+jSS4Xcoxtn3zxGvkiv1C1Zd1qzIPSwjwgq R7f5BcedGie6lni/3D3qlCB14drLkImkwaNAqfWTZ1/aHoY29vNGQVhs56si85hb8V5Z 6yqhEGsaD0VhO7Q3lmkqXw5zusVWb1uUeVPG4EgZWEyN7mcT7NjuKalse9U34a1DWBEj w4KTS4vpcS7lPLIXfNjBJo61HL8NGl7zP6tHyewCuVX+V4ckhoHChUyZ3Q+9jQtFBCI3 qxwlAunAQ9fUA+FhuzBMG1kGexufbLDOhhO+z3aZAk0g6MLjw5weomjPTuhfyl/zMIWB 26vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=ix7zFv64; 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 c15si4769745edr.246.2021.09.22.22.01.48; Wed, 22 Sep 2021 22:02:08 -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=ix7zFv64; 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 1B3DC68A826; Thu, 23 Sep 2021 08:01:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 58DF668A4A4 for ; Thu, 23 Sep 2021 08:01:23 +0300 (EEST) Received: by mail-qv1-f52.google.com with SMTP id e5so3219020qvq.7 for ; Wed, 22 Sep 2021 22:01:23 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=kqhEtHrWbwQpdRg7IeT9kJeoYB14kGnVRuzcuFW9IgU=; b=ix7zFv64wu50LlUcGcL7kDiq3cL/ivF0mj8uOHFux6MoYwyIJXi7gQPi8r8994mw/M 6PFjImoYQQTeB5SyuI1e1cX0D7oRtEydQfdQAgZuMeVHC1wPzPSGDJvP1ZGhPtQRhMe8 1QdA9UUOBqTkia/bvzqMuNO1F8M9JdfYvcV4CAdFJjyYl3CsEPz4B7rfpWw7lzUt/Kz3 t/CZvUbGr+Z1QB1ct9ps3r4pJe8cz7X1Nk7diJJZrzdxJn6GopXyJJH5YH2ODC1i/iMa ArhiTdhF3/CC5a/Lk6M/LbJUJRCQp+85Dks5nWxJL9HMU5UFII4xMSwJp83UrGK1mCwR 1Wjw== 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=kqhEtHrWbwQpdRg7IeT9kJeoYB14kGnVRuzcuFW9IgU=; b=Kfd2J0xB7oG8fC6AYFeQ6rwnUGEplSj6E2ywgxRFCLtk2RTUbRzebge0a4YWUD+/dl ngxmadvh2RMTHeu8xzaWR0scC7j57W7uod7WrCIDLPFKF71HZaAEUSwluYFTRK9tlV4z gFtLOaayQbcTx/xjhnnJydGwsHlsCbQy1/385eIy4MgxCLeZuKRRIahci+P3JcYY2yQb IHASWgILNVWEAS1QaqlHh75A1s2VbBZgFJ+lp32ssviHmwoMJgswQHivnOwyB9/H7jT7 AsC+i5AvVE4nApKuNNeEjyOPbEeKYQCXq5hTcxgkQ8kSDMhqu7abnPPlcWi3+3+/vpIY c4ig== X-Gm-Message-State: AOAM532QtLgRTKQx4edOw1/VwqZMODwUPJtyFbpjnEDPGkV5g4JWhsv4 gzT3CyY+r84Sn9UVh4F4dMKFmHfQZSCe4A== X-Received: by 2002:ad4:4a8b:: with SMTP id h11mr2683639qvx.3.1632373281782; Wed, 22 Sep 2021 22:01:21 -0700 (PDT) Received: from nark.. (modemcable017.92-130-66.mc.videotron.ca. [66.130.92.17]) by smtp.gmail.com with ESMTPSA id q84sm3427097qke.3.2021.09.22.22.01.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Sep 2021 22:01:21 -0700 (PDT) From: quietvoid X-Google-Original-From: quietvoid To: ffmpeg-devel@ffmpeg.org Date: Thu, 23 Sep 2021 01:01:06 -0400 Message-Id: <20210923050109.692356-2-tcChlisop0@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210923050109.692356-1-tcChlisop0@gmail.com> References: <20210923050109.692356-1-tcChlisop0@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 2/5] avformat/matroskadec: Parse dvcC/dvvC block additional mapping 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: eZWKN+OrlBFh The parsing was implemented in a new dovi_isom file for the unification of the mov/mpegts DOVI parsing into one function, in a following patch. Most of the Matroska elements implementation was done by Plex developers. Signed-off-by: quietvoid --- libavformat/Makefile | 2 +- libavformat/dovi_isom.c | 80 +++++++++++++++++++++++++++++++++++++++ libavformat/dovi_isom.h | 29 ++++++++++++++ libavformat/matroskadec.c | 13 +++++++ 4 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 libavformat/dovi_isom.c create mode 100644 libavformat/dovi_isom.h diff --git a/libavformat/Makefile b/libavformat/Makefile index c45caa3eed..61a1fecf6c 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -313,7 +313,7 @@ OBJS-$(CONFIG_M4V_MUXER) += rawenc.o OBJS-$(CONFIG_MATROSKA_DEMUXER) += matroskadec.o matroska.o \ flac_picture.o isom_tags.o rmsipr.o \ oggparsevorbis.o vorbiscomment.o \ - qtpalette.o replaygain.o + qtpalette.o replaygain.o dovi_isom.o OBJS-$(CONFIG_MATROSKA_MUXER) += matroskaenc.o matroska.o \ av1.o avc.o hevc.o isom_tags.o \ flacenc_header.o avlanguage.o \ diff --git a/libavformat/dovi_isom.c b/libavformat/dovi_isom.c new file mode 100644 index 0000000000..3eafa0d13b --- /dev/null +++ b/libavformat/dovi_isom.c @@ -0,0 +1,80 @@ +/* + * 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 "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, 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; +} \ No newline at end of file diff --git a/libavformat/dovi_isom.h b/libavformat/dovi_isom.h new file mode 100644 index 0000000000..9d9a05bdb0 --- /dev/null +++ b/libavformat/dovi_isom.h @@ -0,0 +1,29 @@ +/* + * 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 "avformat.h" + +int ff_isom_parse_dvcc_dvvc(AVFormatContext *s, AVStream *st, const uint8_t *buf_ptr, uint64_t size); + +#endif /* AVFORMAT_DOVI_ISOM_H */ \ No newline at end of file diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 25aa140e16..652d854ac4 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -51,6 +51,8 @@ #include "libavcodec/mpeg4audio.h" #include "libavcodec/packet_internal.h" +#include "libavformat/dovi_isom.h" + #include "avformat.h" #include "avio_internal.h" #include "internal.h" @@ -2323,6 +2325,12 @@ static int mkv_parse_video_projection(AVStream *st, const MatroskaTrack *track, return 0; } +static int mkv_parse_dvcc_dvvc(AVFormatContext *s, AVStream *st, const MatroskaTrack *track, + EbmlBin *bin) +{ + return ff_isom_parse_dvcc_dvvc(s, st, bin->data, bin->size); +} + static int mkv_parse_block_addition_mappings(AVFormatContext *s, AVStream *st, const MatroskaTrack *track) { int i, ret; @@ -2333,6 +2341,11 @@ static int mkv_parse_block_addition_mappings(AVFormatContext *s, AVStream *st, c MatroskaBlockAdditionMapping *mapping = &mappings[i]; switch (mapping->type) { + case MKBETAG('d','v','c','C'): + case MKBETAG('d','v','v','C'): + if ((ret = mkv_parse_dvcc_dvvc(s, st, track, &mapping->extradata)) < 0) + return ret; + break; default: av_log(s, AV_LOG_DEBUG, "Unknown block additional mapping type %ld, value %ld, name \"%s\"\n",