From patchwork Sun Apr 30 20:34:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 3523 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.3.129 with SMTP id 123csp1150605vsd; Sun, 30 Apr 2017 13:35:47 -0700 (PDT) X-Received: by 10.28.59.69 with SMTP id i66mr1478117wma.42.1493584547481; Sun, 30 Apr 2017 13:35:47 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 7si13060038wrf.191.2017.04.30.13.35.47; Sun, 30 Apr 2017 13:35:47 -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=@gmail.com; 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=NONE 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 117F7689994; Sun, 30 Apr 2017 23:34:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt0-f196.google.com (mail-qt0-f196.google.com [209.85.216.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 82AED689880 for ; Sun, 30 Apr 2017 23:34:46 +0300 (EEST) Received: by mail-qt0-f196.google.com with SMTP id y33so14718588qta.1 for ; Sun, 30 Apr 2017 13:34:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=I8KMnsDEwpPiHrv/+B122wgOtww9wNl6j1KGBBVYVLY=; b=EvcC997dMK8SQ2qhx+DVnLYhpBoI2n3k69+uZsMBmUMBYNaq5hU0LVFtq6tGt6/SiH dqBYvXkIdkC8humrQGCuX/hPL/vs1vIrANS98+h012N/PKlhJ3/sr/3Gz8Go5FGJb465 OyxHUUaBJuQXXkXhaQuGBXU3FbZnqFzYS1BXtxQhzYsbGfjrqI3q6JxSpC3lZP6tAR6s yJSjL+oDXllSpMPcI6/buVKEPYSPi1acDVZuIdvA5IPqFnIyQ2ho0l7tLKDzI6uyQZDr y+VkwYNWWnxae+P7rQO9ORi3s7zXnGVovezysTLwA/L6ZSVC2WqoQpu/V6ryZ9/D+JmY NYCQ== 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; bh=I8KMnsDEwpPiHrv/+B122wgOtww9wNl6j1KGBBVYVLY=; b=MPQVPmZHFhl2a2gii64xDZF8xB8xCsrD09RV30SwCk1SMNJy1pZVst6J1KPMGiUcPA VJhJiybC1nCnMoKclYBzxlFr7l0XvTINuyPKPDJ8fxTHvok/E96pWmTAuOnZHA0BYnjM 5Md3SAgImSPtg3BPeFG4Zo/dwkOGvV6pHuk+gFUiti3ox5XU4EcbX5ygGWerWddGAzj7 fWn0AzAXHtjMGgU5OWAYnZDJ6q5HtVOtgOHGqX6fCs4d2vOCu4m6NT2KXpgiXxRXA5n8 BkuZGuGfrjJ2VANZFYxGzVDdwDtOpEtws1Pb9R2W3S9wKz8fa1Cq3ESnzLcMR3sN358W c4Yg== X-Gm-Message-State: AN3rC/61Dn9b2Wm1COsxASDexWVNEPKb8AoSK5lxRrf9+ldcgqTFLGrt cKD+giDSAJL9URRq X-Received: by 10.237.57.170 with SMTP id m39mr18311828qte.163.1493584488696; Sun, 30 Apr 2017 13:34:48 -0700 (PDT) Received: from localhost.localdomain ([181.231.62.139]) by smtp.gmail.com with ESMTPSA id 24sm9147592qtx.8.2017.04.30.13.34.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 30 Apr 2017 13:34:48 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sun, 30 Apr 2017 17:34:09 -0300 Message-Id: <20170430203410.7128-7-jamrial@gmail.com> X-Mailer: git-send-email 2.12.1 In-Reply-To: <20170430203410.7128-1-jamrial@gmail.com> References: <20170430203410.7128-1-jamrial@gmail.com> Subject: [FFmpeg-devel] [PATCH 6/7] hevc_parser: remove HEVCContext usage 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This gets rid of the duplicate, limited parser. Signed-off-by: James Almer --- libavcodec/hevc_parser.c | 176 +++++++++-------------------------------------- 1 file changed, 32 insertions(+), 144 deletions(-) diff --git a/libavcodec/hevc_parser.c b/libavcodec/hevc_parser.c index 501cbc3498..aba2fdb607 100644 --- a/libavcodec/hevc_parser.c +++ b/libavcodec/hevc_parser.c @@ -24,114 +24,31 @@ #include "golomb.h" #include "hevc.h" -#include "hevcdec.h" +#include "hevc_ps.h" +#include "hevc_sei.h" #include "h2645_parse.h" +#include "internal.h" #include "parser.h" #define START_CODE 0x000001 ///< start_code_prefix_one_3bytes #define IS_IRAP_NAL(nal) (nal->type >= 16 && nal->type <= 23) - -#define ADVANCED_PARSER CONFIG_HEVC_DECODER +#define IS_IDR_NAL(nal) (nal->type == HEVC_NAL_IDR_W_RADL || nal->type == HEVC_NAL_IDR_N_LP) typedef struct HEVCParserContext { ParseContext pc; H2645Packet pkt; HEVCParamSets ps; + HEVCSEIContext sei; + SliceHeader sh; int parsed_extradata; -#if ADVANCED_PARSER - HEVCContext h; -#endif + int poc; + int pocTid0; } HEVCParserContext; -#if !ADVANCED_PARSER -static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal, - AVCodecContext *avctx) -{ - HEVCParserContext *ctx = s->priv_data; - GetBitContext *gb = &nal->gb; - - HEVCPPS *pps; - HEVCSPS *sps; - unsigned int pps_id; - - get_bits1(gb); // first slice in pic - if (IS_IRAP_NAL(nal)) - get_bits1(gb); // no output of prior pics - - pps_id = get_ue_golomb_long(gb); - if (pps_id >= HEVC_MAX_PPS_COUNT || !ctx->ps.pps_list[pps_id]) { - av_log(avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id); - return AVERROR_INVALIDDATA; - } - pps = (HEVCPPS*)ctx->ps.pps_list[pps_id]->data; - sps = (HEVCSPS*)ctx->ps.sps_list[pps->sps_id]->data; - - /* export the stream parameters */ - s->coded_width = sps->width; - s->coded_height = sps->height; - s->width = sps->output_width; - s->height = sps->output_height; - s->format = sps->pix_fmt; - avctx->profile = sps->ptl.general_ptl.profile_idc; - avctx->level = sps->ptl.general_ptl.level_idc; - - /* ignore the rest for now*/ - - return 0; -} - -static int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf, - int buf_size, AVCodecContext *avctx) -{ - HEVCParserContext *ctx = s->priv_data; - int ret, i; - - ret = ff_h2645_packet_split(&ctx->pkt, buf, buf_size, avctx, 0, 0, - AV_CODEC_ID_HEVC, 1); - if (ret < 0) - return ret; - - for (i = 0; i < ctx->pkt.nb_nals; i++) { - H2645NAL *nal = &ctx->pkt.nals[i]; - - /* ignore everything except parameter sets and VCL NALUs */ - switch (nal->type) { - case HEVC_NAL_VPS: ff_hevc_decode_nal_vps(&nal->gb, avctx, &ctx->ps); break; - case HEVC_NAL_SPS: ff_hevc_decode_nal_sps(&nal->gb, avctx, &ctx->ps, 1); break; - case HEVC_NAL_PPS: ff_hevc_decode_nal_pps(&nal->gb, avctx, &ctx->ps); break; - case HEVC_NAL_TRAIL_R: - case HEVC_NAL_TRAIL_N: - case HEVC_NAL_TSA_N: - case HEVC_NAL_TSA_R: - case HEVC_NAL_STSA_N: - case HEVC_NAL_STSA_R: - case HEVC_NAL_BLA_W_LP: - case HEVC_NAL_BLA_W_RADL: - case HEVC_NAL_BLA_N_LP: - case HEVC_NAL_IDR_W_RADL: - case HEVC_NAL_IDR_N_LP: - case HEVC_NAL_CRA_NUT: - case HEVC_NAL_RADL_N: - case HEVC_NAL_RADL_R: - case HEVC_NAL_RASL_N: - case HEVC_NAL_RASL_R: - if (buf == avctx->extradata) { - av_log(avctx, AV_LOG_ERROR, "Invalid NAL unit: %d\n", nal->type); - return AVERROR_INVALIDDATA; - } - hevc_parse_slice_header(s, nal, avctx); - break; - } - } - - return 0; -} -#endif - /** * Find the end of the current frame in the bitstream. * @return the position of the first byte of the next frame, or END_NOT_FOUND @@ -175,7 +92,6 @@ static int hevc_find_frame_end(AVCodecParserContext *s, const uint8_t *buf, return END_NOT_FOUND; } -#if ADVANCED_PARSER /** * Parse NAL units of found picture and decode some basic information. * @@ -188,28 +104,18 @@ static inline int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf, int buf_size, AVCodecContext *avctx) { HEVCParserContext *ctx = s->priv_data; - HEVCContext *h = &ctx->h; GetBitContext *gb; - SliceHeader *sh = &h->sh; - HEVCParamSets *ps = &h->ps; - HEVCSEIContext *sei = &h->sei; + SliceHeader *sh = &ctx->sh; + HEVCParamSets *ps = &ctx->ps; + HEVCSEIContext *sei = &ctx->sei; int is_global = buf == avctx->extradata; int i, ret; - if (!h->HEVClc) - h->HEVClc = av_mallocz(sizeof(HEVCLocalContext)); - if (!h->HEVClc) - return AVERROR(ENOMEM); - - gb = &h->HEVClc->gb; - /* set some sane default values */ s->pict_type = AV_PICTURE_TYPE_I; s->key_frame = 0; s->picture_structure = AV_PICTURE_STRUCTURE_UNKNOWN; - h->avctx = avctx; - ff_hevc_reset_sei(sei); ret = ff_h2645_packet_split(&ctx->pkt, buf, buf_size, avctx, 0, 0, @@ -221,11 +127,9 @@ static inline int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf, H2645NAL *nal = &ctx->pkt.nals[i]; int num = 0, den = 0; - h->nal_unit_type = nal->type; - h->temporal_id = nal->temporal_id; - *gb = nal->gb; + gb = &nal->gb; - switch (h->nal_unit_type) { + switch (nal->type) { case HEVC_NAL_VPS: ff_hevc_decode_nal_vps(gb, avctx, ps); break; @@ -237,7 +141,7 @@ static inline int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf, break; case HEVC_NAL_SEI_PREFIX: case HEVC_NAL_SEI_SUFFIX: - ff_hevc_decode_nal_sei(gb, avctx, sei, ps, h->nal_unit_type); + ff_hevc_decode_nal_sei(gb, avctx, sei, ps, nal->type); break; case HEVC_NAL_TRAIL_N: case HEVC_NAL_TRAIL_R: @@ -257,15 +161,15 @@ static inline int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf, case HEVC_NAL_CRA_NUT: if (is_global) { - av_log(avctx, AV_LOG_ERROR, "Invalid NAL unit: %d\n", h->nal_unit_type); + av_log(avctx, AV_LOG_ERROR, "Invalid NAL unit: %d\n", nal->type); return AVERROR_INVALIDDATA; } sh->first_slice_in_pic_flag = get_bits1(gb); - s->picture_structure = h->sei.picture_timing.picture_struct; - s->field_order = h->sei.picture_timing.picture_struct; + s->picture_structure = sei->picture_timing.picture_struct; + s->field_order = sei->picture_timing.picture_struct; - if (IS_IRAP(h)) { + if (IS_IRAP_NAL(nal)) { s->key_frame = 1; sh->no_output_of_prior_pics_flag = get_bits1(gb); } @@ -348,31 +252,30 @@ static inline int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf, if (ps->sps->separate_colour_plane_flag) sh->colour_plane_id = get_bits(gb, 2); - if (!IS_IDR(h)) { + if (!IS_IDR_NAL(nal)) { sh->pic_order_cnt_lsb = get_bits(gb, ps->sps->log2_max_poc_lsb); - s->output_picture_number = h->poc = ff_hevc_compute_poc(h->ps.sps, h->pocTid0, sh->pic_order_cnt_lsb, h->nal_unit_type); + s->output_picture_number = ctx->poc = ff_hevc_compute_poc(ps->sps, ctx->pocTid0, sh->pic_order_cnt_lsb, nal->type); } else - s->output_picture_number = h->poc = 0; - - if (h->temporal_id == 0 && - h->nal_unit_type != HEVC_NAL_TRAIL_N && - h->nal_unit_type != HEVC_NAL_TSA_N && - h->nal_unit_type != HEVC_NAL_STSA_N && - h->nal_unit_type != HEVC_NAL_RADL_N && - h->nal_unit_type != HEVC_NAL_RASL_N && - h->nal_unit_type != HEVC_NAL_RADL_R && - h->nal_unit_type != HEVC_NAL_RASL_R) - h->pocTid0 = h->poc; + s->output_picture_number = ctx->poc = 0; + + if (nal->temporal_id == 0 && + nal->type != HEVC_NAL_TRAIL_N && + nal->type != HEVC_NAL_TSA_N && + nal->type != HEVC_NAL_STSA_N && + nal->type != HEVC_NAL_RADL_N && + nal->type != HEVC_NAL_RASL_N && + nal->type != HEVC_NAL_RADL_R && + nal->type != HEVC_NAL_RASL_R) + ctx->pocTid0 = ctx->poc; return 0; /* no need to evaluate the rest */ } } /* didn't find a picture! */ if (!is_global) - av_log(h->avctx, AV_LOG_ERROR, "missing picture in access unit\n"); + av_log(avctx, AV_LOG_ERROR, "missing picture in access unit\n"); return -1; } -#endif static int hevc_parse(AVCodecParserContext *s, AVCodecContext *avctx, @@ -444,21 +347,6 @@ static void hevc_parser_close(AVCodecParserContext *s) HEVCParserContext *ctx = s->priv_data; int i; -#if ADVANCED_PARSER - HEVCContext *h = &ctx->h; - - for (i = 0; i < FF_ARRAY_ELEMS(h->ps.vps_list); i++) - av_buffer_unref(&h->ps.vps_list[i]); - for (i = 0; i < FF_ARRAY_ELEMS(h->ps.sps_list); i++) - av_buffer_unref(&h->ps.sps_list[i]); - for (i = 0; i < FF_ARRAY_ELEMS(h->ps.pps_list); i++) - av_buffer_unref(&h->ps.pps_list[i]); - - h->ps.sps = NULL; - - av_freep(&h->HEVClc); -#endif - for (i = 0; i < FF_ARRAY_ELEMS(ctx->ps.vps_list); i++) av_buffer_unref(&ctx->ps.vps_list[i]); for (i = 0; i < FF_ARRAY_ELEMS(ctx->ps.sps_list); i++)