From patchwork Mon Sep 30 17:41:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 51941 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:d8ca:0:b0:48e:c0f8:d0de with SMTP id dy10csp2131206vqb; Mon, 30 Sep 2024 10:41:06 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV4q9xe+dLlnP2dlVN7QOkAFNRgIMgY0JrCqSltl/DwmKPHdC0wzfhkLiLAysjksb5gAGstaTajCEKC2ZHfb2oh@gmail.com X-Google-Smtp-Source: AGHT+IE71J/FMVmcORtQH2xdE5GpMQC7ETZ7q22uYo9OiNQpylLoT7q2/Kvf1IypSqcXhGz6Tp52 X-Received: by 2002:a17:906:f5a1:b0:a8d:2624:1a83 with SMTP id a640c23a62f3a-a93d8b77f91mr447608966b.14.1727718066312; Mon, 30 Sep 2024 10:41:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727718066; cv=none; d=google.com; s=arc-20240605; b=OwThacPidMajgkNSHM3HI8usCtfOOXJ8qLqiT2HbZuoPlJnbD4uvB2+RHNMaM3aqsk wjB/DyxqgFJD8M2Ev7kFnd7byBASj3c9blZuDBWhH/yN/T5AZ4Jtd+MKkf5NZio+KDB9 9oeqAq3c6F8s5x4gyGggtXN/bHe4fw/tTVaqNK6op+swSFyebNGJ3RUi4J1tfN/OM3+W H35vWQjdVG9IlRW0GXrGRCDnvAPeHBIHPoA4Otpt6eqyaiHjp0Pr/lAMjsC3NMdtCcAr jDTFN/JR8dnUu5fdPTIROOxqnAvTNHHJkxF11xyIP+9j8QfI0g12i61uVsMS2+sEBzJe RMPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=lQXT8NdMsQc5QH29kW4wn2RRNaJqjqhzuLIJcbsw1MY=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=eH1+eEonHSOrff8GC3pgh9fQ3kViRkBTy0XsbtuWJca6XlCTsaUIbdIJqbHs/avG1l NjJKJFZvyT6/02aV4Sdlg1M8d/HZPzJ0ltq5NI+8DD5YY2pUd9vflRh8JpEOaodSHJ4z 4/swRNNTvb8m7aONTjKMiIGojFd7y1NcFctIykxESyEZDxqC9b6wmSTQFJIvdK1SfY0G xNQ+nDKhYiC8jKCMRdpVeRFTK2thNbrDoT84d/gfCGG3dUjcEXeRoYKDTlbhXQEI6+Az BpMpTqfW7iJMc8haP0KvEzhIXIvhpIfnyDVs32xVJh5z1/bPoYCvROnqPBuYqHV4doNz 35Iw==; 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=fZUMwdIN; 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; dara=fail header.i=@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 a640c23a62f3a-a93c290369esi579627666b.223.2024.09.30.10.41.05; Mon, 30 Sep 2024 10:41:06 -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=fZUMwdIN; 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; dara=fail header.i=@gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A10A168DD98; Mon, 30 Sep 2024 20:41:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 463D868DBE4 for ; Mon, 30 Sep 2024 20:40:56 +0300 (EEST) Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-20aff65aa37so37931625ad.1 for ; Mon, 30 Sep 2024 10:40:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727718054; x=1728322854; 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=C4lCm2itmbDSGPKdEXse1kjJGCwbAY7kse80G04kx1c=; b=fZUMwdINfolFHe7CKXdgZCFd6RsORa5J27WSBPRExTTjIbe596dNq7z1LQpE1526zT 7aEo4vW3kydcs0w6nNVUlwPiqm/ULvSX82ai277y0th9X1YOwqRev4Vu96vwvkYulgj8 XQFFdchLmZM9Wx1WxLZ0xDuLT7MY/G97thByqq77d/FH/hivwQYjQyspu6zn+MFhpAL/ k7gx8PFU3HpdV5uTAjK01VYl1ti8Kzb0TbUM7ZXxhCw/x2tVpxIsPDxC/ge0A5QB7ckZ n2mN+HznnulkiRKElcRrOXOCCfMosG88tgqSdQ9oP7upSvs5bbtib3SCDibtl+PMiEo/ uqZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727718054; x=1728322854; 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=C4lCm2itmbDSGPKdEXse1kjJGCwbAY7kse80G04kx1c=; b=Koa0zATVObrX2BWZV0YHq1NrFnALIiyl+Ft5WmhjgYKi2jJYXtiUip5mBxrOLHU4E7 H0gbSMlB7rt269K3U+S6kgplKTGhY2jcAlkLLr0uVMLX9q5y0tl2/BODF4ucGSux7emh qcu2e/GpKEFwhcrshxTLS1c9P+6DYEjtu61UsXctprLc8lvfbhRfI4OVU6Z6v0j092wG qOclyxoTYBUTL93DHvmvKCWJS0CT7J09euUi6Cxq4/r6YLQYI0kQluQTjyWKHgWvxiY+ XMTa+7R9fIdgJFZxOHvLosAatuKs7S8VGTtKroGMcfzLcZKkm1ajubad6pceYL+BiBNE Ul6w== X-Gm-Message-State: AOJu0YwR6/lZgFuQGT0E7h5lQmRXfTvlaEzm5wrWV09arlIKCi7zzg9i ZnJuT4a874jdZdOPQVkUaX7miNG/nlcJhsuAVc5bLRjdvcXUuyTYBKWMEA== X-Received: by 2002:a17:903:22cf:b0:20b:7ed8:3986 with SMTP id d9443c01a7336-20b7ed83c33mr72465235ad.24.1727718053798; Mon, 30 Sep 2024 10:40:53 -0700 (PDT) Received: from localhost.localdomain ([181.92.233.116]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20b37d90c52sm57126315ad.86.2024.09.30.10.40.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 10:40:53 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 30 Sep 2024 14:41:18 -0300 Message-ID: <20240930174119.6426-1-jamrial@gmail.com> X-Mailer: git-send-email 2.46.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avformat/mov: factorize getting the current item 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: 7XMUg1Bq5YXa Signed-off-by: James Almer --- libavformat/mov.c | 58 +++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 67e87094cf..b3b92bbb91 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -189,6 +189,24 @@ static int mov_read_mac_string(MOVContext *c, AVIOContext *pb, int len, return p - dst; } +/** + * Get the current item in the parsing process. + */ +static HEIFItem *get_curr_item(MOVContext *c) +{ + HEIFItem *item = NULL; + + for (int i = 0; i < c->nb_heif_item; i++) { + if (c->heif_item[i].item_id != c->cur_item_id) + continue; + + item = &c->heif_item[i]; + break; + } + + return item; +} + /** * Get the current stream in the parsing process. This can either be the * latest stream added to the context, or the stream referenced by an item. @@ -196,23 +214,17 @@ static int mov_read_mac_string(MOVContext *c, AVIOContext *pb, int len, static AVStream *get_curr_st(MOVContext *c) { AVStream *st = NULL; + HEIFItem *item; if (c->fc->nb_streams < 1) return NULL; - for (int i = 0; i < c->nb_heif_item; i++) { - HEIFItem *item = &c->heif_item[i]; - - if (!item->st) - continue; - if (item->st->id != c->cur_item_id) - continue; + if (c->cur_item_id == -1) + return c->fc->streams[c->fc->nb_streams-1]; + item = get_curr_item(c); + if (item) st = item->st; - break; - } - if (!st && c->cur_item_id == -1) - st = c->fc->streams[c->fc->nb_streams-1]; return st; } @@ -8913,6 +8925,7 @@ static int mov_read_iref(MOVContext *c, AVIOContext *pb, MOVAtom atom) static int mov_read_ispe(MOVContext *c, AVIOContext *pb, MOVAtom atom) { + HEIFItem *item; uint32_t width, height; avio_r8(pb); /* version */ @@ -8923,12 +8936,10 @@ static int mov_read_ispe(MOVContext *c, AVIOContext *pb, MOVAtom atom) av_log(c->fc, AV_LOG_TRACE, "ispe: item_id %d, width %u, height %u\n", c->cur_item_id, width, height); - for (int i = 0; i < c->nb_heif_item; i++) { - if (c->heif_item[i].item_id == c->cur_item_id) { - c->heif_item[i].width = width; - c->heif_item[i].height = height; - break; - } + item = get_curr_item(c); + if (item) { + item->width = width; + item->height = height; } return 0; @@ -8936,6 +8947,7 @@ static int mov_read_ispe(MOVContext *c, AVIOContext *pb, MOVAtom atom) static int mov_read_irot(MOVContext *c, AVIOContext *pb, MOVAtom atom) { + HEIFItem *item; int angle; angle = avio_r8(pb) & 0x3; @@ -8943,13 +8955,11 @@ static int mov_read_irot(MOVContext *c, AVIOContext *pb, MOVAtom atom) av_log(c->fc, AV_LOG_TRACE, "irot: item_id %d, angle %u\n", c->cur_item_id, angle); - for (int i = 0; i < c->nb_heif_item; i++) { - if (c->heif_item[i].item_id == c->cur_item_id) { - // angle * 90 specifies the angle (in anti-clockwise direction) - // in units of degrees. - c->heif_item[i].rotation = angle * 90; - break; - } + item = get_curr_item(c); + if (item) { + // angle * 90 specifies the angle (in anti-clockwise direction) + // in units of degrees. + item->rotation = angle * 90; } return 0;