From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 17E3648ACE for ; Wed, 31 Jan 2024 17:27:17 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 24A7268D0E1; Wed, 31 Jan 2024 19:26:56 +0200 (EET) Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 58CFC68D0A5 for ; Wed, 31 Jan 2024 19:26:49 +0200 (EET) Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1d8d747a3bcso10002835ad.0 for ; Wed, 31 Jan 2024 09:26:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706722007; x=1707326807; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Kq8dmgwZoXKAk8nwllHsieLGe+lO5n1f/+76lhKq+t0=; b=IW2OTfR3o9s9EtOKDutU7E/OictxZDPW4TLUOefVOD1SkWWlClXoFkRNV3JGF51mts Uq97unuSpourZSdvqGceFh09c0YgkQgIeHJ6EEPoqIBDPqeCDPE9fhKX4AJeKHQ8QqPE J3Ozhb7XzFZl7U68Mjk7DNbxtOvWDcruRCYiUMIvPRD6Qlfxo7zwNA53ffZ3KIUjt4lx JgsIMlrOK3f0EUM2ttDgHLrfqjW9IaMfFD4ODPGKGYJG2Hy1QCLPMLlu+F4YeTrLVUBr Ky/46nV3hITa+Gh3EejRXzSpsS4Us2UNKcXi+F0yzLQG/JwtEgxeXToRMCMn5XIdJbro ehyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706722007; x=1707326807; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Kq8dmgwZoXKAk8nwllHsieLGe+lO5n1f/+76lhKq+t0=; b=HPSrEX5SJEsjopt97Td2LD1EWXOcRuTDRNE5awO1GHDUwzth3EncXeqD4qOP+XJYF3 KGgkafsE1VH6UbYgsxABpx2FV1ZcChQ8NfCjSWctpixn4/hKSzgjXqdu/Q+xP69NRNsN im5si8OXoAVbCMUV5F0iGx4Erfyauw2zF84ql4Q8cpnbQFcyy5KaKsk98kWg0h7j4Vcq d6b2m8MjPAr37Uq+Do/ZrCWu2who3yjFj4/fmrhIMNwU42cVwY4taGYL8giMkpdK4u0n 40zBwhTAaDriIUd1gjPdzXAj9ilCvE1VjUZOb0DD3GdyQosUIWgrCaj1qlYP5wvp5adP EkAw== X-Gm-Message-State: AOJu0YwUMRCY8DUQ4fWAtg+UINdkhzgUO8VfzgdUBM7Q2MNXYkNLXnsz p6w8sF3Kjsjwf9YkKadVEbBXDxom7TUONssnL9QvLzVfxqjrThenlsgAwvZd X-Google-Smtp-Source: AGHT+IFXFzduTc9Ars/0dlot96dY6gnDtvbDwoZskATbT5/t8UukOhduOurOUqJgYjVXYUInrJcEEQ== X-Received: by 2002:a17:903:4cf:b0:1d7:8570:e53 with SMTP id jm15-20020a17090304cf00b001d785700e53mr5203375plb.38.1706722007203; Wed, 31 Jan 2024 09:26:47 -0800 (PST) Received: from localhost.localdomain (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id k11-20020a170902f28b00b001d8e4b85636sm5762235plc.138.2024.01.31.09.26.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 09:26:46 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 Jan 2024 14:26:51 -0300 Message-ID: <20240131172654.15869-3-jamrial@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131172654.15869-1-jamrial@gmail.com> References: <20240131172654.15869-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/6 v3] avformat/mov: make MOVStreamContext refcounted 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Signed-off-by: James Almer --- libavformat/isom.h | 1 + libavformat/mov.c | 105 +++++++++++++++++++++++++-------------------- 2 files changed, 59 insertions(+), 47 deletions(-) diff --git a/libavformat/isom.h b/libavformat/isom.h index 2cf456fee1..a4925b3b08 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -165,6 +165,7 @@ typedef struct MOVIndexRange { typedef struct MOVStreamContext { AVIOContext *pb; + int refcount; int pb_is_copied; int ffindex; ///< AVStream index int next_chunk; diff --git a/libavformat/mov.c b/libavformat/mov.c index cf931d4594..555c72dc79 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -211,6 +211,7 @@ static int mov_read_covr(MOVContext *c, AVIOContext *pb, int type, int len) } st = c->fc->streams[c->fc->nb_streams - 1]; st->priv_data = sc; + sc->refcount = 1; if (st->attached_pic.size >= 8 && id != AV_CODEC_ID_BMP) { if (AV_RB64(st->attached_pic.data) == 0x89504e470d0a1a0a) { @@ -4654,6 +4655,7 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) st->codecpar->codec_type = AVMEDIA_TYPE_DATA; sc->ffindex = st->index; c->trak_index = st->index; + sc->refcount = 1; if ((ret = mov_read_default(c, pb, atom)) < 0) return ret; @@ -4941,6 +4943,7 @@ static int heif_add_stream(MOVContext *c, HEIFItem *item) sc = st->priv_data; sc->pb = c->fc->pb; sc->pb_is_copied = 1; + sc->refcount = 1; // Populate the necessary fields used by mov_build_index. sc->stsc_count = 1; @@ -8587,6 +8590,60 @@ static void mov_free_encryption_index(MOVEncryptionIndex **index) { av_freep(index); } +static void mov_free_stream_context(AVFormatContext *s, AVStream *st) +{ + MOVStreamContext *sc = st->priv_data; + + if (!sc || --sc->refcount) { + st->priv_data = NULL; + return; + } + + av_freep(&sc->ctts_data); + for (int i = 0; i < sc->drefs_count; i++) { + av_freep(&sc->drefs[i].path); + av_freep(&sc->drefs[i].dir); + } + av_freep(&sc->drefs); + + sc->drefs_count = 0; + + if (!sc->pb_is_copied) + ff_format_io_close(s, &sc->pb); + + sc->pb = NULL; + av_freep(&sc->chunk_offsets); + av_freep(&sc->stsc_data); + av_freep(&sc->sample_sizes); + av_freep(&sc->keyframes); + av_freep(&sc->stts_data); + av_freep(&sc->sdtp_data); + av_freep(&sc->stps_data); + av_freep(&sc->elst_data); + av_freep(&sc->rap_group); + av_freep(&sc->sync_group); + av_freep(&sc->sgpd_sync); + av_freep(&sc->sample_offsets); + av_freep(&sc->open_key_samples); + av_freep(&sc->display_matrix); + av_freep(&sc->index_ranges); + + if (sc->extradata) + for (int i = 0; i < sc->stsd_count; i++) + av_free(sc->extradata[i]); + av_freep(&sc->extradata); + av_freep(&sc->extradata_size); + + mov_free_encryption_index(&sc->cenc.encryption_index); + av_encryption_info_free(sc->cenc.default_encrypted_sample); + av_aes_ctr_free(sc->cenc.aes_ctr); + + av_freep(&sc->stereo3d); + av_freep(&sc->spherical); + av_freep(&sc->mastering); + av_freep(&sc->coll); +} + static int mov_read_close(AVFormatContext *s) { MOVContext *mov = s->priv_data; @@ -8594,54 +8651,8 @@ static int mov_read_close(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - MOVStreamContext *sc = st->priv_data; - - if (!sc) - continue; - - av_freep(&sc->ctts_data); - for (j = 0; j < sc->drefs_count; j++) { - av_freep(&sc->drefs[j].path); - av_freep(&sc->drefs[j].dir); - } - av_freep(&sc->drefs); - sc->drefs_count = 0; - - if (!sc->pb_is_copied) - ff_format_io_close(s, &sc->pb); - - sc->pb = NULL; - av_freep(&sc->chunk_offsets); - av_freep(&sc->stsc_data); - av_freep(&sc->sample_sizes); - av_freep(&sc->keyframes); - av_freep(&sc->stts_data); - av_freep(&sc->sdtp_data); - av_freep(&sc->stps_data); - av_freep(&sc->elst_data); - av_freep(&sc->rap_group); - av_freep(&sc->sync_group); - av_freep(&sc->sgpd_sync); - av_freep(&sc->sample_offsets); - av_freep(&sc->open_key_samples); - av_freep(&sc->display_matrix); - av_freep(&sc->index_ranges); - - if (sc->extradata) - for (j = 0; j < sc->stsd_count; j++) - av_free(sc->extradata[j]); - av_freep(&sc->extradata); - av_freep(&sc->extradata_size); - - mov_free_encryption_index(&sc->cenc.encryption_index); - av_encryption_info_free(sc->cenc.default_encrypted_sample); - av_aes_ctr_free(sc->cenc.aes_ctr); - - av_freep(&sc->stereo3d); - av_freep(&sc->spherical); - av_freep(&sc->mastering); - av_freep(&sc->coll); + mov_free_stream_context(s, st); } av_freep(&mov->dv_demux); -- 2.43.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".