From patchwork Mon Jul 27 16:32:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 21329 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:80ca:0:0:0:0:0 with SMTP id c10csp4278336ybm; Mon, 27 Jul 2020 09:34:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9K8vGmCVVTg6C3Fq5u5YHdlxR1sLEvuDQqAWz5XQ2qqWM7gCG0B4zcmmTxk0FnxCKs5hR X-Received: by 2002:adf:e48f:: with SMTP id i15mr20032357wrm.327.1595867691186; Mon, 27 Jul 2020 09:34:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595867691; cv=none; d=google.com; s=arc-20160816; b=F7rLuBkhEGlGdTpup/iDhnnpIpjxkLgqgXtfkeEjZyWJm2QOTMEHfGh3RcKE9ezl86 Losz59y82i+mKgXW1njR2QI4yhmkgDrMfeZD/SMr44Qnm8dOMTJubO62OMkN/J8dW5+V MVXrlHHqS5ZBZ+HHLLGz8XHfdUDMsCQu+k/PENupvSEmUVD8ldYmyaZwjt02l9bXnIou Zeb/z7zeGpfPm4tZ/w4tbgP6Atpj4ayZg8zCtwRH+sULjmO6lwDeKLu0x8tV+vqNAQEr ZNTuxiNga1x1NSsq4Iac5Y9H4VsFETBRrcJX31TUAI3k5fh93eNd9QN0lUdL0wWHUboY 3q0A== 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:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=oKnJM3wE0O25vI8TLK5N9hwoRBwzyUvHJo4QVGNpHXQ=; b=tX6+pJVg2pG/OIKB/vvtdJW94UcD0MnxSydEVGt9cSAmUFK5wGrPj1qAotWitJsDyA FWFaOQEJp7FUbRUdTJqIiwigF/j7WaqmmrtfUrJ9fyABV/mnSn9spg1zpK+lcIwI9Pc7 2Hy82Y2lBKiDa+6nNbn6rjKMrv/Gf3X4v9Fcloi+NLBh4dBvg5jGzBRIyTVD9JUDGZqP +2PdNoiA41aHCM78Jmbq4DKKajNrHmJIZ/GYdGv/pDHTn/Yc+P9SH5JkuBIml1YnQeTi 9IR0mCHKiyRJvPziOtbdo8h9oyVHX6SbLQeF1IqY2qCJx6u+hiZhAZb+F9bFIW89ak56 gNAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@jkqxz-net.20150623.gappssmtp.com header.s=20150623 header.b=uqAg2jSI; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id d4si8165959wrr.224.2020.07.27.09.34.50; Mon, 27 Jul 2020 09:34:51 -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=@jkqxz-net.20150623.gappssmtp.com header.s=20150623 header.b=uqAg2jSI; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4F40D68B88E; Mon, 27 Jul 2020 19:33:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5711E68B864 for ; Mon, 27 Jul 2020 19:32:56 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id 9so14710718wmj.5 for ; Mon, 27 Jul 2020 09:32:56 -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=ozWdNrPF+0GM5GGSF2GF9BGmcXC0v7ch0CVQCcp+1a0=; b=uqAg2jSIdrSNJsLcVgH3L9e4YkY3a2n0NE6ZCwqhDoUtp2I3T3NcmJlBO+ymSMWj2K 3iHwYl5XYIvu/H+ZKVO9NTCsxnlJpnj21eeKyj7UvuvER0BHuC7SSg+rx37H2XRtbmzu gxmLjAKHOoVlP7kVf/Ho2JUA15E7TTNxZFTVolGiWRcBnwvuhbdxl+FmUvulIO0twhKa +AhsZ6c2kmCBwD55kdfIXnN+tJ34DkHwVbHIk6JvUu3755baD3No7vEf+hOAJF2qO+WC 3hgv2ueBo/6zDacbj8QPvgtMBCHame0MZ4fGVqFmc7ogECDgAWbPzPtxQ+kNl3ELjQxC /9xg== 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=ozWdNrPF+0GM5GGSF2GF9BGmcXC0v7ch0CVQCcp+1a0=; b=g+ZDRDEDBFB12QB7mh53NdZaFzPeoGZ7/lTqC0kik6r+E23dI2/yIYO8WIyteDWSy0 AIGpgql3aDeesuvZ70worKx0funPorWaU7jjq84DAS1OFUIE5svKLjbf7Xnkb6ituuPy hcYyvO3ugW2i8ui9YckPB1EUZarslgARW+2Sxe/mT3ryqFlFByB+8FK/uIy7jjyQTRKw pZ55bur20LHVgD4sx21c90UqNvaFDoPFJJ9+C3gDZpC7tm3ETDaUdOOgWHt6oeYE8Ixg kR8vxT5cjj60VsBjg6MmJB0LwQsX96YqK18XUcdvfD4e/wjqc0LMPu3YJxNO2yhqajpb rgIQ== X-Gm-Message-State: AOAM533e+msOn7prA26PbOMUtzDwBdP+vuDScBwuEhA8ZeXOKfXttRzU /kc5WDfZw+XBMOZEh2Os8VnKkDKNpHU= X-Received: by 2002:a7b:cb51:: with SMTP id v17mr125295wmj.146.1595867575461; Mon, 27 Jul 2020 09:32:55 -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 w16sm14706791wrg.95.2020.07.27.09.32.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 09:32:54 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 17:32:27 +0100 Message-Id: <20200727163237.23371-13-sw@jkqxz.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727163237.23371-1-sw@jkqxz.net> References: <20200727163237.23371-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 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" X-TUID: S2JKBdO3Ahs7 Content-Length: 6051 --- 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 8b6e5a9852..26400f279f 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(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(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,