From patchwork Wed Jan 1 00:58:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 17085 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a05:6214:1865:0:0:0:0 with SMTP id eh5csp217702qvb; Tue, 31 Dec 2019 17:00:16 -0800 (PST) X-Google-Smtp-Source: APXvYqze5LIT5/sm4FykOgi+ImGgRUFAE6U1laLAtlOuQZ3BfSDsnoK9XhjMMIEVgYpvLWOcSlMa X-Received: by 2002:a17:906:3299:: with SMTP id 25mr79440316ejw.118.1577840416081; Tue, 31 Dec 2019 17:00:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577840416; cv=none; d=google.com; s=arc-20160816; b=K8ddpPD8pwP9trkAPoC63Z1t9yXqAgRw73cfwm5AeitN13vWsfyA7D/BGNNikg92yU fAvW/olJNQ5lyvXky70mVyV1NFdikwK4qjmm8Mm++bT694D3S+eV5mu7B10LhupSXO2L r2DCtGuy/B23W+9C27DnYHBJPnvB2mRN8WCWZ2TgnrSestoCuU0/9eURrpLEeo1eGSR9 S8BxzE+SnSCfaJj52FlSRhvXKTTEhIoWn/cd3SmBos6xrE9W5Eqd8+daRE8ERHTHWuZP /j8/xWpUO9bILGXdaPwQwFUM3dNtE3bOe+oScotRy249YRFFkTQKHF7XdBQr3j7+umK1 cWXg== 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=6+BNrxpIbXxbqET4uVKCcz81CJC+4NeZbZIoSAWnJLo=; b=j9qpN7/uVHhr8hugTMEVk3bRPttxoxyFKljTZm9R5zOddzNdnadAISZ0npw037PQAB OKVnlaCSJ2SxqPPxXIzYiWJCs8j8dzoKdYCk3Xo2ryaQaiPRTSvouqck8dSChLfk1hz7 nZbLbTAQw4l96zZhVo3WfE1O9WF4HATx6UfkDZt02zhjXUek3EVk/1crDUVxiffSFvpl 3NM3WKiQ6JkUa2JamR+cVWNi7weumUGEv1pAGM3MynaAJu1M719Yx2qJBGuX40d8seVH BXQ60FoUXAmxbogfcXoWNtECl5In/GLcIhpP55alO4KVzR+dx1aP3bA9rPuFEnCSg6sG 1F1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=ddl32nCE; 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 c4si32840923edd.147.2019.12.31.17.00.15; Tue, 31 Dec 2019 17:00:16 -0800 (PST) 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=20161025 header.b=ddl32nCE; 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 2191068AD9D; Wed, 1 Jan 2020 02:59:17 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 590F668AD2A for ; Wed, 1 Jan 2020 02:59:11 +0200 (EET) Received: by mail-wr1-f67.google.com with SMTP id c9so36215637wrw.8 for ; Tue, 31 Dec 2019 16:59:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qiPb+3pwfJXYPM5X7zoYBIZbV3jfUvxqavszezkkx7M=; b=ddl32nCEmWbTzO+UnSBCQLd2alcY8+B9U+LKp3dlsQOAA0r8VNST8qjOV61Po0h7/1 ObgPULty4f28NDv1IChNbYCsvEr86zixHCgwFaYI7byShlG2NRtjzXu01JP3veI6++dr deF23adSE8LT9A6oCiM498povRsLG6gP+VUZ/C5JFXollA7sXGdgov4VfAVkwQi/B7OE 61W5ealtF8U2u1kMV951QJsxBX8Uia6kPSSd1WEq9xTFqugZMg2Hxs/7RgjxDM4sgVNR YRjwlt6hyUBoJsf38j/eS8W1VC0moPkxavxdXqSd2QgQtHpq5U3btafJE+DWWU8UASsl t8Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qiPb+3pwfJXYPM5X7zoYBIZbV3jfUvxqavszezkkx7M=; b=TjHOCQ+5mdeGerT2Q7SWkd1NXDcOzud3W0TdZ04OvY0fPD5IWeuqRIikgWx7tMpOwM Fz2iebPPs1v03x2oz2BHxQJ9c2b44TEk0lvOoqY5VtqI1GqS+a1WSeJnucRNlarMnXC6 oUgRVHi4EdzmCG9uOfhhdd/kPwhQDUC+lBnpEOaA9lmzSnJawR/5niEZadiKfAkrOCOu OTM4lwuUHcWfoh84IkbSKxKdAVfD3HDT9VS2LySGFMVg/w/f8KuxXp9iuyMY9zMF0ycY V0nOsip7jaLsRhVjXvAtOxl+9JehXDb8AGBJZWjjzVmANaP/5w4k+MMMnE0HDs5ytSmR A//w== X-Gm-Message-State: APjAAAUp4DJD2Ai8HEKElRA4PbEqbgjSGPxrFUqUSD5sYtzf5tI7xW3L lRch8MffqHpNgGaxDyieRksq4yqX X-Received: by 2002:adf:cd92:: with SMTP id q18mr73664083wrj.261.1577840350609; Tue, 31 Dec 2019 16:59:10 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc08bbf.dynamic.kabel-deutschland.de. [188.192.139.191]) by smtp.gmail.com with ESMTPSA id w17sm52431655wrt.89.2019.12.31.16.59.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Dec 2019 16:59:10 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 1 Jan 2020 01:58:29 +0100 Message-Id: <20200101005837.11356-13-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200101005837.11356-1-andreas.rheinhardt@gmail.com> References: <20200101005837.11356-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/20] avformat/matroskaenc: Avoid allocation for Cues X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: +9PltNeHvNAP Content-Length: 7790 Up until now, the Matroska muxer would allocate a structure containing three members: The segment offset, a pointer to an array containing Cue (index) entries and a counter for said array. It is unnecessary to allocate it separately and it is unnecessary to contain the segment offset in said structure, as it duplicates another field contained in the MatroskaMuxContext. This commit implements the corresponding changes. Signed-off-by: Andreas Rheinhardt --- libavformat/matroskaenc.c | 39 +++++++++++---------------------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 6dd731eb90..2c4d3c338f 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -88,7 +88,6 @@ typedef struct mkv_cuepoint { } mkv_cuepoint; typedef struct mkv_cues { - int64_t segment_offset; mkv_cuepoint *entries; int num_entries; } mkv_cues; @@ -139,7 +138,7 @@ typedef struct MatroskaMuxContext { int64_t duration_offset; int64_t duration; mkv_seekhead seekhead; - mkv_cues *cues; + mkv_cues cues; mkv_track *tracks; mkv_attachments *attachments; @@ -398,10 +397,7 @@ static void mkv_deinit(AVFormatContext *s) ffio_free_dyn_buf(&mkv->tracks_bc); ffio_free_dyn_buf(&mkv->tags_bc); - if (mkv->cues) { - av_freep(&mkv->cues->entries); - av_freep(&mkv->cues); - } + av_freep(&mkv->cues.entries); if (mkv->attachments) { av_freep(&mkv->attachments->entries); av_freep(&mkv->attachments); @@ -486,19 +482,10 @@ seek: return 0; } -static mkv_cues *mkv_start_cues(int64_t segment_offset) -{ - mkv_cues *cues = av_mallocz(sizeof(mkv_cues)); - if (!cues) - return NULL; - - cues->segment_offset = segment_offset; - return cues; -} - -static int mkv_add_cuepoint(mkv_cues *cues, int stream, int tracknum, int64_t ts, +static int mkv_add_cuepoint(MatroskaMuxContext *mkv, int stream, int tracknum, int64_t ts, int64_t cluster_pos, int64_t relative_pos, int64_t duration) { + mkv_cues *cues = &mkv->cues; mkv_cuepoint *entries = cues->entries; if (ts < 0) @@ -512,7 +499,7 @@ static int mkv_add_cuepoint(mkv_cues *cues, int stream, int tracknum, int64_t ts cues->entries[cues->num_entries].pts = ts; cues->entries[cues->num_entries].stream_idx = stream; cues->entries[cues->num_entries].tracknum = tracknum; - cues->entries[cues->num_entries].cluster_pos = cluster_pos - cues->segment_offset; + cues->entries[cues->num_entries].cluster_pos = cluster_pos - mkv->segment_offset; cues->entries[cues->num_entries].relative_pos = relative_pos; cues->entries[cues->num_entries++].duration = duration; @@ -1931,11 +1918,6 @@ static int mkv_write_header(AVFormatContext *s) return ret; } - mkv->cues = mkv_start_cues(mkv->segment_offset); - if (!mkv->cues) { - return AVERROR(ENOMEM); - } - if (s->metadata_header_padding > 0) { if (s->metadata_header_padding == 1) s->metadata_header_padding++; @@ -2346,7 +2328,8 @@ static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt, int add_ if (par->codec_type != AVMEDIA_TYPE_SUBTITLE) { mkv_write_block(s, pb, MATROSKA_ID_SIMPLEBLOCK, pkt, keyframe); if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) && (par->codec_type == AVMEDIA_TYPE_VIDEO && keyframe || add_cue)) { - ret = mkv_add_cuepoint(mkv->cues, pkt->stream_index, tracknum, ts, mkv->cluster_pos, relative_packet_pos, -1); + ret = mkv_add_cuepoint(mkv, pkt->stream_index, tracknum, ts, + mkv->cluster_pos, relative_packet_pos, -1); if (ret < 0) return ret; } } else { @@ -2371,7 +2354,7 @@ FF_ENABLE_DEPRECATION_WARNINGS } if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) { - ret = mkv_add_cuepoint(mkv->cues, pkt->stream_index, tracknum, ts, + ret = mkv_add_cuepoint(mkv, pkt->stream_index, tracknum, ts, mkv->cluster_pos, relative_packet_pos, duration); if (ret < 0) return ret; @@ -2501,14 +2484,14 @@ static int mkv_write_trailer(AVFormatContext *s) if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) { - if (mkv->cues->num_entries) { + if (mkv->cues.num_entries) { if (mkv->reserve_cues_space) { int64_t cues_end; currentpos = avio_tell(pb); avio_seek(pb, mkv->cues_pos, SEEK_SET); - cuespos = mkv_write_cues(s, mkv->cues, mkv->tracks, s->nb_streams); + cuespos = mkv_write_cues(s, &mkv->cues, mkv->tracks, s->nb_streams); cues_end = avio_tell(pb); if (cues_end > cuespos + mkv->reserve_cues_space) { av_log(s, AV_LOG_ERROR, @@ -2524,7 +2507,7 @@ static int mkv_write_trailer(AVFormatContext *s) avio_seek(pb, currentpos, SEEK_SET); } else { - cuespos = mkv_write_cues(s, mkv->cues, mkv->tracks, s->nb_streams); + cuespos = mkv_write_cues(s, &mkv->cues, mkv->tracks, s->nb_streams); } mkv_add_seekhead_entry(mkv, MATROSKA_ID_CUES, cuespos);