From patchwork Wed Jul 3 21:26:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 50310 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:cc64:0:b0:482:c625:d099 with SMTP id k4csp3352670vqv; Wed, 3 Jul 2024 14:44:17 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWmsgh8yrouK3GzTUvsBFI0EGbAWnLUpRdTabOtoR/C5doPAb+CfKQbWMTfiPSxHDi0vHKjdoFDhKNsyjOuqlffTcNPUe4l1d055w== X-Google-Smtp-Source: AGHT+IFTej8EILlrBzRHnA01eD9Xs9pjWW4WGEX+Bw5nD9K2rGzV5RfcNb6fN5maWItBR2OlIf/g X-Received: by 2002:a05:6512:33d3:b0:52c:dd58:1a97 with SMTP id 2adb3069b0e04-52e827860fcmr7179904e87.5.1720043054803; Wed, 03 Jul 2024 14:44:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720043054; cv=none; d=google.com; s=arc-20160816; b=pvTa4ZZdWUI2ELlDOE9+4eAk+wAHKsABpo60GwZhFT5nmQObQbNmfOAGPHnLJLJGlI rzWcPZR1cJR5QKMHB2Puhh2B2f34khh4mwNYBHH/abYCfUphe2bb2vm7Pqy5ao+j6x/y ahsdvzYUja6+TpI68LwJM7pGJYB8ju0zF1jyH6tSZFW1BzMVN0bxAIRk0QWH80ZRZS0Z 4I6gzx6N6tPPGFQV2uIexZq1hF1IJyCXHRrqzywHeWnzhKyReOQ79i/C2g58D/MeoKNH gKjo81lbTpPiW1fzUh9AsarqbbYRn8pJ+iJ62ZT0ESTcF6SHRm2TuCDTXzr4jp1zIM+p y9BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding: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=AEO+CMkfSQbMx5DK4Fv0OhYuFe3F3BUER9eG1zLzvxU=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=MpCAZSxSjpsdOJr+5qJ8UuRQZKyJ8BF0cBln0C0LWog3JrdeXUPhNJc1hFftTwt2qc U2vefbA+gXw20PFuMkqSTojnqn7ET78DFXqdkvqZ1bKEO9MNW8OnWyhH3pTKsK2i028q yhwdDwYXi/yVvpQYxiuLfc5f+FDeS6G5Dp/eYLec4lFpn0k36vXG8z/qMEek4tpwGPCB B+AeQzglOela5ukkjQCDqwMVClvlbgJWeqlcQHLoBgYF7ahJM55pG2LJ7/mbBYxkdbJM 91u/SoJPPlL6c7I/c2wSvnzpp4x6+W6MMlP/danuhuF54gGJ+Z/UAbMP+DWWO+jV4BXA HvVA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b="Xk0Woa/3"; 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 2adb3069b0e04-52e7ab25901si3905676e87.325.2024.07.03.14.44.14; Wed, 03 Jul 2024 14:44:14 -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=20230601 header.b="Xk0Woa/3"; 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 0D3E868D9CB; Thu, 4 Jul 2024 00:26:40 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4253C68D5E1 for ; Thu, 4 Jul 2024 00:26:33 +0300 (EEST) Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-71884eda768so3485617a12.1 for ; Wed, 03 Jul 2024 14:26:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720041990; x=1720646790; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=u8+JdXa1d+t5ddpK/uQrlsBfRlAG+D5sBnmZcqitj/E=; b=Xk0Woa/3fvGtxIdPEEDJ3NBCEpJv8T8lFnonc4FMsjOfCbGMbYnhg3ZZuqKTVLP1G7 hW9EfgCmKZUIVR+jRgmTr8SEkjEIKromzv2nDVdDVfq/LmuCW0K3hCbDqc4PqDCNFSdd Kl4XGJ+/ofxONqo9ssu8mboF6COZb8BSQ7ZH1/YD9byIGvFqAC7djI7JIgfX888AsENn EK8417py3CXJmMicH8uPeaigN97O87oMnI3H1JluC93rHBEpTAIMJm8M9Kucvxu3VL38 VnTStBKAvs85iotxekmnV3dQreYh6JOtVtx22rkDbi0RbNL+f3J/ginVTGM5/drVqzVo n2lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720041990; x=1720646790; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=u8+JdXa1d+t5ddpK/uQrlsBfRlAG+D5sBnmZcqitj/E=; b=NW5HTB92p2+TzPF46d2S1nYBQ6YaF+W8dnBeEzjNOPpRDavKvr2cpF36uR9okLUwif Ahh1xaJDZ8Q88+fB4gwhTIl/7ASoM/jXf/7kPLF+kYz/2u2v/YDuiC8QpT0ufxC+6jjY 7pyvFyj7a1w9CXnigKQtfABKQGzXcAaSbJrf+GTTAuo2BTK03htujuJdRvArseeWtSFz D3Qzjs8Hn3/n1V4pvzzPRZIDmoIeeFgFCVhYrZSSI0A+zp/o8lC8qfq645TgPV5TSrfm HNVV5lVDiDFpfmpcI6iNiJWZYdh3W5DfN8ba5uQjOf3w8IPnjb601b9JxA61treGquJt nrDA== X-Gm-Message-State: AOJu0Yx9ROfECzgtAa/novUgnSSLdk7W/c4+LwwKi41nMSJHO67gPO63 yQ0ghFltavqzBznFzNTmq1pT+tHTYDSEw6A8az16nj23MWodCk1pocw2bw== X-Received: by 2002:a17:90a:d78e:b0:2c9:81d3:65d5 with SMTP id 98e67ed59e1d1-2c981d369b8mr1676222a91.24.1720041989997; Wed, 03 Jul 2024 14:26:29 -0700 (PDT) Received: from localhost.localdomain ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c91ce58877sm11370560a91.24.2024.07.03.14.26.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 14:26:29 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Jul 2024 18:26:36 -0300 Message-ID: <20240703212648.48483-1-jamrial@gmail.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/11] avformat/mov: add support for lhvC box parsing 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: uf5impeWu/ft Signed-off-by: James Almer --- libavformat/mov.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/libavformat/mov.c b/libavformat/mov.c index a3951a6942..30e8086855 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -8157,6 +8157,53 @@ static int mov_read_dvcc_dvvc(MOVContext *c, AVIOContext *pb, MOVAtom atom) return ff_isom_parse_dvcc_dvvc(c->fc, st, buf, read_size); } +static int mov_read_lhvc(MOVContext *c, AVIOContext *pb, MOVAtom atom) +{ + AVStream *st; + uint8_t *buf; + int ret, old_size, num_arrays; + + if (c->fc->nb_streams < 1) + return 0; + st = c->fc->streams[c->fc->nb_streams-1]; + + if (!st->codecpar->extradata_size) + // TODO: handle lhvC when present before hvcC + return 0; + + if (atom.size < 6 || st->codecpar->extradata_size < 23) + return AVERROR_INVALIDDATA; + + buf = av_malloc(atom.size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!buf) + return AVERROR(ENOMEM); + memset(buf + atom.size, 0, AV_INPUT_BUFFER_PADDING_SIZE); + + ret = ffio_read_size(pb, buf, atom.size); + if (ret < 0) { + av_free(buf); + av_log(c->fc, AV_LOG_WARNING, "lhvC atom truncated\n"); + return 0; + } + + num_arrays = buf[5]; + old_size = st->codecpar->extradata_size; + atom.size -= 8 /* account for mov_realloc_extradata offseting */ + + 6 /* lhvC bytes before the arrays*/; + + ret = mov_realloc_extradata(st->codecpar, atom); + if (ret < 0) { + av_free(buf); + return ret; + } + + st->codecpar->extradata[22] += num_arrays; + memcpy(st->codecpar->extradata + old_size, buf + 6, atom.size + 8); + + av_free(buf); + return 0; +} + static int mov_read_kind(MOVContext *c, AVIOContext *pb, MOVAtom atom) { AVFormatContext *ctx = c->fc; @@ -8943,6 +8990,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG('i','p','r','p'), mov_read_iprp }, { MKTAG('i','i','n','f'), mov_read_iinf }, { MKTAG('a','m','v','e'), mov_read_amve }, /* ambient viewing environment box */ +{ MKTAG('l','h','v','C'), mov_read_lhvc }, #if CONFIG_IAMFDEC { MKTAG('i','a','c','b'), mov_read_iacb }, #endif