From patchwork Wed Nov 2 15:48:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vittorio Giovara X-Patchwork-Id: 1259 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.90.1 with SMTP id o1csp341832vsb; Wed, 2 Nov 2016 09:04:42 -0700 (PDT) X-Received: by 10.28.213.14 with SMTP id m14mr3779449wmg.85.1478102682634; Wed, 02 Nov 2016 09:04:42 -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 5si4004009wmp.126.2016.11.02.09.04.41; Wed, 02 Nov 2016 09:04:42 -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 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 5F23D689C48; Wed, 2 Nov 2016 18:04:36 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt0-f193.google.com (mail-qt0-f193.google.com [209.85.216.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A2EE9689BC9 for ; Wed, 2 Nov 2016 18:04:29 +0200 (EET) Received: by mail-qt0-f193.google.com with SMTP id n6so757018qtd.0 for ; Wed, 02 Nov 2016 09:04:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=h+UIA6OSsNU1b2cmKGjiaDWWMyZNtONm8n4bH8uRYv0=; b=NOlaYGbUaSqvAu8qf3DkocA1jZK78MjJM7a6WKx2MLY3Lux9wfMrrCyNhsZlhtPbPW +RRblbZNfmnzW0HMvex2HuG5vQ53vyOvfdjjervYl4QHsypemM2Q8OK4RDUPbfla9+AM sE/OCgorUl0zw3ZY41JURRkPnXZ7U22iP9bUz1bfjlk3nItUq91cijWOqTNJOiscHNDW lW2oEfH8VwAlfTG8LBfLg0FYJeLUArGmsOSZ0MiJo9i9kEg/KN7Dy8hN/hjDsvOz8Mjc vsdrOU1l5Q9z8/wM2UuGvtzzj0VOKojdsbxo02MEcnjbeqt2qK4vIo2uPkpduI6DHnSX 3vkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=h+UIA6OSsNU1b2cmKGjiaDWWMyZNtONm8n4bH8uRYv0=; b=bRrs5BMmcV12p9k0eHzbmCSqLScUI4kklTwTG7syRdvjKwR27FGO5XsFb2YyBAD7DP IGERHHA8fillOOSNXE1APLIx8169F4vHbdV7SHAYQBUVPgGi1KcIACMWuGVbqtIAQsF2 6WxTw7sy4Nj8H4pqUojZ9wOZUxNwAZ3EH93A7yy3a1L7ueHUjEk18bXjnVnAISy9RI9j hUU+7gbAe73SiZG9sUyf8g05f8bY5EuxcSmp3+NjGmN7BHY4HUb4NLb+g/6xFvDrTyxY XVU3kpWmidkVSXSLCa7lJzrt+yj55MnCG7ZPJ8AhcgXpENrt2hp737Kpb+6qu4oUT+Ul 30Hw== X-Gm-Message-State: ABUngvft33Kqb7QTmrC9tZdXEsvHfApVh1XKZFDT/y2ilT6ETYVf7s7ODrqhawVInsCzUA== X-Received: by 10.237.58.38 with SMTP id n35mr3880301qte.45.1478101740257; Wed, 02 Nov 2016 08:49:00 -0700 (PDT) Received: from vimacbookpro.vimeows.com (nyv-exweb.iac.com. [216.112.252.10]) by smtp.gmail.com with ESMTPSA id d20sm1397307qtb.41.2016.11.02.08.48.59 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 02 Nov 2016 08:48:59 -0700 (PDT) From: Vittorio Giovara To: ffmpeg-devel@ffmpeg.org Date: Wed, 2 Nov 2016 11:48:57 -0400 Message-Id: <20161102154858.28628-1-vittorio.giovara@gmail.com> X-Mailer: git-send-email 2.10.0 Subject: [FFmpeg-devel] [PATCH 1/2] hevc: Move hevc_decode_extradata before frame decoding 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" Avoids a forward-declaration in the following commit. Signed-off-by: Vittorio Giovara --- Please CC. Vittorio libavcodec/hevc.c | 148 +++++++++++++++++++++++++++--------------------------- 1 file changed, 74 insertions(+), 74 deletions(-) diff --git a/libavcodec/hevc.c b/libavcodec/hevc.c index 764e093..29e0d49 100644 --- a/libavcodec/hevc.c +++ b/libavcodec/hevc.c @@ -2973,6 +2973,80 @@ static int verify_md5(HEVCContext *s, AVFrame *frame) return 0; } +static int hevc_decode_extradata(HEVCContext *s) +{ + AVCodecContext *avctx = s->avctx; + GetByteContext gb; + int ret, i; + + bytestream2_init(&gb, avctx->extradata, avctx->extradata_size); + + if (avctx->extradata_size > 3 && + (avctx->extradata[0] || avctx->extradata[1] || + avctx->extradata[2] > 1)) { + /* It seems the extradata is encoded as hvcC format. + * Temporarily, we support configurationVersion==0 until 14496-15 3rd + * is finalized. When finalized, configurationVersion will be 1 and we + * can recognize hvcC by checking if avctx->extradata[0]==1 or not. */ + int i, j, num_arrays, nal_len_size; + + s->is_nalff = 1; + + bytestream2_skip(&gb, 21); + nal_len_size = (bytestream2_get_byte(&gb) & 3) + 1; + num_arrays = bytestream2_get_byte(&gb); + + /* nal units in the hvcC always have length coded with 2 bytes, + * so put a fake nal_length_size = 2 while parsing them */ + s->nal_length_size = 2; + + /* Decode nal units from hvcC. */ + for (i = 0; i < num_arrays; i++) { + int type = bytestream2_get_byte(&gb) & 0x3f; + int cnt = bytestream2_get_be16(&gb); + + for (j = 0; j < cnt; j++) { + // +2 for the nal size field + int nalsize = bytestream2_peek_be16(&gb) + 2; + if (bytestream2_get_bytes_left(&gb) < nalsize) { + av_log(s->avctx, AV_LOG_ERROR, + "Invalid NAL unit size in extradata.\n"); + return AVERROR_INVALIDDATA; + } + + ret = decode_nal_units(s, gb.buffer, nalsize); + if (ret < 0) { + av_log(avctx, AV_LOG_ERROR, + "Decoding nal unit %d %d from hvcC failed\n", + type, i); + return ret; + } + bytestream2_skip(&gb, nalsize); + } + } + + /* Now store right nal length size, that will be used to parse + * all other nals */ + s->nal_length_size = nal_len_size; + } else { + s->is_nalff = 0; + ret = decode_nal_units(s, avctx->extradata, avctx->extradata_size); + if (ret < 0) + return ret; + } + + /* export stream parameters from the first SPS */ + for (i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) { + if (s->ps.sps_list[i]) { + const HEVCSPS *sps = (const HEVCSPS*)s->ps.sps_list[i]->data; + export_stream_params(s->avctx, &s->ps, sps); + break; + } + } + + return 0; +} + static int hevc_decode_frame(AVCodecContext *avctx, void *data, int *got_output, AVPacket *avpkt) { @@ -3243,80 +3317,6 @@ static int hevc_update_thread_context(AVCodecContext *dst, return 0; } -static int hevc_decode_extradata(HEVCContext *s) -{ - AVCodecContext *avctx = s->avctx; - GetByteContext gb; - int ret, i; - - bytestream2_init(&gb, avctx->extradata, avctx->extradata_size); - - if (avctx->extradata_size > 3 && - (avctx->extradata[0] || avctx->extradata[1] || - avctx->extradata[2] > 1)) { - /* It seems the extradata is encoded as hvcC format. - * Temporarily, we support configurationVersion==0 until 14496-15 3rd - * is finalized. When finalized, configurationVersion will be 1 and we - * can recognize hvcC by checking if avctx->extradata[0]==1 or not. */ - int i, j, num_arrays, nal_len_size; - - s->is_nalff = 1; - - bytestream2_skip(&gb, 21); - nal_len_size = (bytestream2_get_byte(&gb) & 3) + 1; - num_arrays = bytestream2_get_byte(&gb); - - /* nal units in the hvcC always have length coded with 2 bytes, - * so put a fake nal_length_size = 2 while parsing them */ - s->nal_length_size = 2; - - /* Decode nal units from hvcC. */ - for (i = 0; i < num_arrays; i++) { - int type = bytestream2_get_byte(&gb) & 0x3f; - int cnt = bytestream2_get_be16(&gb); - - for (j = 0; j < cnt; j++) { - // +2 for the nal size field - int nalsize = bytestream2_peek_be16(&gb) + 2; - if (bytestream2_get_bytes_left(&gb) < nalsize) { - av_log(s->avctx, AV_LOG_ERROR, - "Invalid NAL unit size in extradata.\n"); - return AVERROR_INVALIDDATA; - } - - ret = decode_nal_units(s, gb.buffer, nalsize); - if (ret < 0) { - av_log(avctx, AV_LOG_ERROR, - "Decoding nal unit %d %d from hvcC failed\n", - type, i); - return ret; - } - bytestream2_skip(&gb, nalsize); - } - } - - /* Now store right nal length size, that will be used to parse - * all other nals */ - s->nal_length_size = nal_len_size; - } else { - s->is_nalff = 0; - ret = decode_nal_units(s, avctx->extradata, avctx->extradata_size); - if (ret < 0) - return ret; - } - - /* export stream parameters from the first SPS */ - for (i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) { - if (s->ps.sps_list[i]) { - const HEVCSPS *sps = (const HEVCSPS*)s->ps.sps_list[i]->data; - export_stream_params(s->avctx, &s->ps, sps); - break; - } - } - - return 0; -} - static av_cold int hevc_decode_init(AVCodecContext *avctx) { HEVCContext *s = avctx->priv_data;