From patchwork Sun May 3 22:05:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 19460 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id C5DBB44B916 for ; Mon, 4 May 2020 01:06:06 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AF62A68C109; Mon, 4 May 2020 01:06:06 +0300 (EEST) 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 6306768C0B8 for ; Mon, 4 May 2020 01:06:03 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id k1so18679160wrx.4 for ; Sun, 03 May 2020 15:06:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=eHbMmEIJC8vMjmefiYcEnejXZLWcob8cekGmpiCpa90=; b=jfpfFhFMoPlbyRZm04ID2zhkdVBacSh3c3e9Xy84dvAF5sHSLnym+EcL2o8GleVeLw 23Xn6NG2Wd2euY7peAVSWR6vZfVvfjkOYnXoCWWH5biiWppq1Hew2M7BCZuSZONzalUY p4fbcIhP7ZCaCt/ZZZm9uZvxNQbD2bF32I/DRzJHdGC1119CZhWh2odoeJCo5Gl+hvHp Mtsa69CY+XJmVmlU+DByhLakQHkbg/K0Fy18z+WJmoCRloUYrJptqL09xeUXahyTNHQ4 kLiBctd5XXumdm4fHP4hYif13/9ca25tvkkRJMKMy364k3mBQfv/SUHmn9P+xZkCgUM5 vH1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eHbMmEIJC8vMjmefiYcEnejXZLWcob8cekGmpiCpa90=; b=JsyQn4wM5UkqmCherJqR7WJPR1qWAOC91xrwEE/nKngVdnJ1IXOUcqnIiK6NQaji5i eQnqXbb/FgQSEIHtYLFqI7vdhc+glmq8AMjIErxHlUcKKnuOvXLFQ2Dr1d+7VNJ6DGcM 7+MEPHAU5MoyQKfa3ibQUPLgVS/ZLufUOkU3f+14rDo6ix8XJrLnl5zhJMA2KJ5KCP8W cT/aDjmjxLijko/RCv1Yt5vVbuhxSz+QznVGh17IcbXRLWiPft8qfhJ7J86kyDy/yKWh 4PBeMTKUVEm7SSc6Kr9jThTkfL3GHINVxmjfMkofGg8tVf3D22OCPRbzk7xMST6edh+H 6g7g== X-Gm-Message-State: AGi0PuaWk+g7Qcpc+XZHOxnO+FVbYudCMtfA4mkk9OKig2rwm5lEK1sS YxTzugI9q7Xtyk++wPbV6A5DNom3tmI= X-Google-Smtp-Source: APiQypJeV2vjFUvt1X1K2jGv8VSYw4objqF6VsLafvNkRdWbCykWID7rjygqnCteifhbFgYLFZ2fpw== X-Received: by 2002:a5d:5309:: with SMTP id e9mr2714438wrv.311.1588543562284; Sun, 03 May 2020 15:06:02 -0700 (PDT) Received: from rywe.jkqxz.net (cpc91242-cmbg18-2-0-cust650.5-4.cable.virginm.net. [82.8.130.139]) by smtp.gmail.com with ESMTPSA id a24sm10307285wmb.24.2020.05.03.15.06.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 May 2020 15:06:01 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Sun, 3 May 2020 23:05:38 +0100 Message-Id: <20200503220548.23543-12-sw@jkqxz.net> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200503220548.23543-1-sw@jkqxz.net> References: <20200503220548.23543-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 12/22] cbs_mpeg2: Use table-based alloc/free 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavcodec/cbs_mpeg2.c | 70 +++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c index 97f7889cbb..94e02945f3 100644 --- a/libavcodec/cbs_mpeg2.c +++ b/libavcodec/cbs_mpeg2.c @@ -140,28 +140,6 @@ #undef infer -static void cbs_mpeg2_free_picture_header(void *opaque, uint8_t *content) -{ - MPEG2RawPictureHeader *picture = (MPEG2RawPictureHeader*)content; - av_buffer_unref(&picture->extra_information_picture.extra_information_ref); - av_freep(&content); -} - -static void cbs_mpeg2_free_user_data(void *opaque, uint8_t *content) -{ - MPEG2RawUserData *user = (MPEG2RawUserData*)content; - av_buffer_unref(&user->user_data_ref); - av_freep(&content); -} - -static void cbs_mpeg2_free_slice(void *opaque, uint8_t *content) -{ - MPEG2RawSlice *slice = (MPEG2RawSlice*)content; - av_buffer_unref(&slice->header.extra_information_slice.extra_information_ref); - av_buffer_unref(&slice->data_ref); - av_freep(&content); -} - static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header) @@ -231,16 +209,14 @@ static int cbs_mpeg2_read_unit(CodedBitstreamContext *ctx, if (err < 0) return err; + err = ff_cbs_alloc_unit_content2(ctx, unit); + if (err < 0) + return err; + if (MPEG2_START_IS_SLICE(unit->type)) { - MPEG2RawSlice *slice; + MPEG2RawSlice *slice = unit->content; int pos, len; - err = ff_cbs_alloc_unit_content(ctx, unit, sizeof(*slice), - &cbs_mpeg2_free_slice); - if (err < 0) - return err; - slice = unit->content; - err = cbs_mpeg2_read_slice_header(ctx, &gbc, &slice->header); if (err < 0) return err; @@ -264,12 +240,7 @@ static int cbs_mpeg2_read_unit(CodedBitstreamContext *ctx, #define START(start_code, type, read_func, free_func) \ case start_code: \ { \ - type *header; \ - err = ff_cbs_alloc_unit_content(ctx, unit, \ - sizeof(*header), free_func); \ - if (err < 0) \ - return err; \ - header = unit->content; \ + type *header = unit->content; \ err = cbs_mpeg2_read_ ## read_func(ctx, &gbc, header); \ if (err < 0) \ return err; \ @@ -420,11 +391,40 @@ static int cbs_mpeg2_assemble_fragment(CodedBitstreamContext *ctx, return 0; } +static const CodedBitstreamUnitTypeDescriptor cbs_mpeg2_unit_types[] = { + CBS_UNIT_TYPE_INTERNAL_REF(MPEG2_START_PICTURE, MPEG2RawPictureHeader, + extra_information_picture.extra_information), + + { + .nb_unit_types = CBS_UNIT_TYPE_RANGE, + .unit_type_range_start = 0x01, + .unit_type_range_end = 0xaf, + + .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS, + .content_size = sizeof(MPEG2RawSlice), + .nb_ref_offsets = 2, + .ref_offsets = { offsetof(MPEG2RawSlice, header.extra_information_slice.extra_information), + offsetof(MPEG2RawSlice, data) }, + }, + + CBS_UNIT_TYPE_INTERNAL_REF(MPEG2_START_USER_DATA, MPEG2RawUserData, + user_data), + + CBS_UNIT_TYPE_POD(MPEG2_START_SEQUENCE_HEADER, MPEG2RawSequenceHeader), + CBS_UNIT_TYPE_POD(MPEG2_START_EXTENSION, MPEG2RawExtensionData), + CBS_UNIT_TYPE_POD(MPEG2_START_SEQUENCE_END, MPEG2RawSequenceEnd), + CBS_UNIT_TYPE_POD(MPEG2_START_GROUP, MPEG2RawGroupOfPicturesHeader), + + CBS_UNIT_TYPE_END_OF_LIST +}; + const CodedBitstreamType ff_cbs_type_mpeg2 = { .codec_id = AV_CODEC_ID_MPEG2VIDEO, .priv_data_size = sizeof(CodedBitstreamMPEG2Context), + .unit_types = cbs_mpeg2_unit_types, + .split_fragment = &cbs_mpeg2_split_fragment, .read_unit = &cbs_mpeg2_read_unit, .write_unit = &cbs_mpeg2_write_unit,