From patchwork Wed Jan 23 23:01:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 11851 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 83C8844EDBD for ; Thu, 24 Jan 2019 01:09:13 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AB68268AC96; Thu, 24 Jan 2019 01:09:01 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7C3E968AC89 for ; Thu, 24 Jan 2019 01:08:55 +0200 (EET) Received: by mail-wm1-f48.google.com with SMTP id r24so1000282wmh.0 for ; Wed, 23 Jan 2019 15:09:13 -0800 (PST) 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=IMVZb4edbhrRmDdlYpJWafrAYNpnTyav7MusdNpnxbA=; b=MWxU2lzH7slGb8JYHuyjZzt6IPCsQXpGJMYQE2UXo7l3W+82XuHsflRGvk7M6YLFUr RH7xzg/PiNPdiF5sOol0htx1BtZBDOf+dcUd5tlUhS/GNlnjN2gMdvH/TPBkcQc4M1Er rowyiV8cfLOZRGRTOW10GsltWFAGEaRQXGA+c2nNLB75YHFYpU2zR9D9vzBtdI/x5KVE CgDYuo8PWl9CsiMmRQhTXZhPwvHJjEOC3Qf/ZIvf59sFdapglgl+nDv7VnTUkuJdoj1W UVtpUBswoaKBfORvdypw8sXp5sBIorKFGTeCuF3fpQ5SlZXA4ELCDubtLh9XkwnUPgep lJTw== 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=IMVZb4edbhrRmDdlYpJWafrAYNpnTyav7MusdNpnxbA=; b=jObHKDgFHD6KsQKR/NO+hucL+JgIyRH/e45fiXs0/LHvcv3Phcaqf4utZPZNcJ9J8Q KSPqQoAZbQd6zb5qko+c5l1dW/++1AuXfeOqDoV6Vjh62hKAcpMy4hJO83akCd2VZTRg lFTLWYE0b9FGYeXxQclAQLIvmKX8EK97BAF98rzY+XrP8bCQK3ytZxoV/wnNLGjP7E4r enFUNd8E7lfPPiLrJVyoRR8hUrTCeJ7XMUERCuzxlOz1QPdYohebthlCVDnX72yBw670 QXB7QLe+igI33RkreobOPdR5tsOh4AyOw+5ED60Fb6aesq+cmQypyA1X0Qn63w8cf2E3 mvCw== X-Gm-Message-State: AJcUukdJOZSBSCdbaQ+jOJQKIcA1ZdDkrauUnZjGMS+1sjYUI3eA4Cpq Rm8KAFkEeO5+co970bf7Tt4pMTaUZpM= X-Google-Smtp-Source: ALg8bN4yH26oh3IckhVteYbrWjX/tglBX9TeQr7M7f74vGgXv41dJ5h70oR8nUtL3itbcvQ7GOR80A== X-Received: by 2002:a1c:834c:: with SMTP id f73mr57071wmd.126.1548284483557; Wed, 23 Jan 2019 15:01:23 -0800 (PST) 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 a62sm48786478wmf.47.2019.01.23.15.01.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 15:01:22 -0800 (PST) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Wed, 23 Jan 2019 23:01:11 +0000 Message-Id: <20190123230114.1086-5-sw@jkqxz.net> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190123230114.1086-1-sw@jkqxz.net> References: <20190123230114.1086-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/7] cbs_h264: 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_h2645.c | 156 +++++++++++++++++------------------------ 1 file changed, 64 insertions(+), 92 deletions(-) diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index e74f8dce81..caf8a1062f 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -414,51 +414,6 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext *gbc) #undef allocate -static void cbs_h264_free_pps(void *unit, uint8_t *content) -{ - H264RawPPS *pps = (H264RawPPS*)content; - av_buffer_unref(&pps->slice_group_id_ref); - av_freep(&content); -} - -static void cbs_h264_free_sei_payload(H264RawSEIPayload *payload) -{ - switch (payload->payload_type) { - case H264_SEI_TYPE_BUFFERING_PERIOD: - case H264_SEI_TYPE_PIC_TIMING: - case H264_SEI_TYPE_PAN_SCAN_RECT: - case H264_SEI_TYPE_RECOVERY_POINT: - case H264_SEI_TYPE_DISPLAY_ORIENTATION: - case H264_SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME: - break; - case H264_SEI_TYPE_USER_DATA_REGISTERED: - av_buffer_unref(&payload->payload.user_data_registered.data_ref); - break; - case H264_SEI_TYPE_USER_DATA_UNREGISTERED: - av_buffer_unref(&payload->payload.user_data_unregistered.data_ref); - break; - default: - av_buffer_unref(&payload->payload.other.data_ref); - break; - } -} - -static void cbs_h264_free_sei(void *unit, uint8_t *content) -{ - H264RawSEI *sei = (H264RawSEI*)content; - int i; - for (i = 0; i < sei->payload_count; i++) - cbs_h264_free_sei_payload(&sei->payload[i]); - av_freep(&content); -} - -static void cbs_h264_free_slice(void *unit, uint8_t *content) -{ - H264RawSlice *slice = (H264RawSlice*)content; - av_buffer_unref(&slice->data_ref); - av_freep(&content); -} - static void cbs_h265_free_vps(void *unit, uint8_t *content) { H265RawVPS *vps = (H265RawVPS*)content; @@ -753,15 +708,14 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx, if (err < 0) return err; + err = ff_cbs_alloc_unit_content2(ctx, unit); + if (err < 0) + return err; + switch (unit->type) { case H264_NAL_SPS: { - H264RawSPS *sps; - - err = ff_cbs_alloc_unit_content(ctx, unit, sizeof(*sps), NULL); - if (err < 0) - return err; - sps = unit->content; + H264RawSPS *sps = unit->content; err = cbs_h264_read_sps(ctx, &gbc, sps); if (err < 0) @@ -775,12 +729,6 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx, case H264_NAL_SPS_EXT: { - err = ff_cbs_alloc_unit_content(ctx, unit, - sizeof(H264RawSPSExtension), - NULL); - if (err < 0) - return err; - err = cbs_h264_read_sps_extension(ctx, &gbc, unit->content); if (err < 0) return err; @@ -789,13 +737,7 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx, case H264_NAL_PPS: { - H264RawPPS *pps; - - err = ff_cbs_alloc_unit_content(ctx, unit, sizeof(*pps), - &cbs_h264_free_pps); - if (err < 0) - return err; - pps = unit->content; + H264RawPPS *pps = unit->content; err = cbs_h264_read_pps(ctx, &gbc, pps); if (err < 0) @@ -811,15 +753,9 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx, case H264_NAL_IDR_SLICE: case H264_NAL_AUXILIARY_SLICE: { - H264RawSlice *slice; + H264RawSlice *slice = unit->content; int pos, len; - err = ff_cbs_alloc_unit_content(ctx, unit, sizeof(*slice), - &cbs_h264_free_slice); - if (err < 0) - return err; - slice = unit->content; - err = cbs_h264_read_slice_header(ctx, &gbc, &slice->header); if (err < 0) return err; @@ -845,11 +781,6 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx, case H264_NAL_AUD: { - err = ff_cbs_alloc_unit_content(ctx, unit, - sizeof(H264RawAUD), NULL); - if (err < 0) - return err; - err = cbs_h264_read_aud(ctx, &gbc, unit->content); if (err < 0) return err; @@ -858,11 +789,6 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx, case H264_NAL_SEI: { - err = ff_cbs_alloc_unit_content(ctx, unit, sizeof(H264RawSEI), - &cbs_h264_free_sei); - if (err < 0) - return err; - err = cbs_h264_read_sei(ctx, &gbc, unit->content); if (err < 0) return err; @@ -871,11 +797,6 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx, case H264_NAL_FILLER_DATA: { - err = ff_cbs_alloc_unit_content(ctx, unit, - sizeof(H264RawFiller), NULL); - if (err < 0) - return err; - err = cbs_h264_read_filler(ctx, &gbc, unit->content); if (err < 0) return err; @@ -885,12 +806,6 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx, case H264_NAL_END_SEQUENCE: case H264_NAL_END_STREAM: { - err = ff_cbs_alloc_unit_content(ctx, unit, - sizeof(H264RawNALUnitHeader), - NULL); - if (err < 0) - return err; - err = (unit->type == H264_NAL_END_SEQUENCE ? cbs_h264_read_end_of_sequence : cbs_h264_read_end_of_stream)(ctx, &gbc, unit->content); @@ -1527,11 +1442,68 @@ static void cbs_h265_close(CodedBitstreamContext *ctx) av_buffer_unref(&h265->pps_ref[i]); } +static void cbs_h264_free_sei_payload(H264RawSEIPayload *payload) +{ + switch (payload->payload_type) { + case H264_SEI_TYPE_BUFFERING_PERIOD: + case H264_SEI_TYPE_PIC_TIMING: + case H264_SEI_TYPE_PAN_SCAN_RECT: + case H264_SEI_TYPE_RECOVERY_POINT: + case H264_SEI_TYPE_DISPLAY_ORIENTATION: + case H264_SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME: + break; + case H264_SEI_TYPE_USER_DATA_REGISTERED: + av_buffer_unref(&payload->payload.user_data_registered.data_ref); + break; + case H264_SEI_TYPE_USER_DATA_UNREGISTERED: + av_buffer_unref(&payload->payload.user_data_unregistered.data_ref); + break; + default: + av_buffer_unref(&payload->payload.other.data_ref); + break; + } +} + +static void cbs_h264_free_sei(void *unit, uint8_t *content) +{ + H264RawSEI *sei = (H264RawSEI*)content; + int i; + for (i = 0; i < sei->payload_count; i++) + cbs_h264_free_sei_payload(&sei->payload[i]); + av_freep(&content); +} + +static const CodedBitstreamUnitTypeDescriptor cbs_h264_unit_types[] = { + CBS_UNIT_TYPE_POD(H264_NAL_SPS, H264RawSPS), + CBS_UNIT_TYPE_POD(H264_NAL_SPS_EXT, H264RawSPSExtension), + + CBS_UNIT_TYPE_INTERNAL_REFS(H264_NAL_PPS, H264RawPPS, + 1, { offsetof(H264RawPPS, slice_group_id_ref) }), + + CBS_UNIT_TYPE_INTERNAL_REFS(H264_NAL_IDR_SLICE, H264RawSlice, + 1, { offsetof(H264RawSlice, data_ref) }), + CBS_UNIT_TYPE_INTERNAL_REFS(H264_NAL_SLICE, H264RawSlice, + 1, { offsetof(H264RawSlice, data_ref) }), + CBS_UNIT_TYPE_INTERNAL_REFS(H264_NAL_AUXILIARY_SLICE, H264RawSlice, + 1, { offsetof(H264RawSlice, data_ref) }), + + CBS_UNIT_TYPE_POD(H264_NAL_AUD, H264RawAUD), + CBS_UNIT_TYPE_POD(H264_NAL_FILLER_DATA, H264RawFiller), + CBS_UNIT_TYPE_POD(H264_NAL_END_SEQUENCE, H264RawNALUnitHeader), + CBS_UNIT_TYPE_POD(H264_NAL_END_STREAM, H264RawNALUnitHeader), + + CBS_UNIT_TYPE_COMPLEX(H264_NAL_SEI, H264RawSEI, &cbs_h264_free_sei), + + CBS_UNIT_TYPE_END_OF_LIST +}; + const CodedBitstreamType ff_cbs_type_h264 = { .codec_id = AV_CODEC_ID_H264, .priv_data_size = sizeof(CodedBitstreamH264Context), + .unit_types = cbs_h264_unit_types, + .split_fragment = &cbs_h2645_split_fragment, .read_unit = &cbs_h264_read_nal_unit, .write_unit = &cbs_h2645_write_nal_unit,