From patchwork Fri Dec 16 14:41:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ronald S. Bultje" X-Patchwork-Id: 1839 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.65.86 with SMTP id o83csp1365349vsa; Fri, 16 Dec 2016 06:41:41 -0800 (PST) X-Received: by 10.194.115.226 with SMTP id jr2mr3039723wjb.75.1481899301837; Fri, 16 Dec 2016 06:41:41 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ej4si7295077wjb.123.2016.12.16.06.41.41; Fri, 16 Dec 2016 06:41:41 -0800 (PST) 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 3E448689C09; Fri, 16 Dec 2016 16:41:32 +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 33F60689A9C for ; Fri, 16 Dec 2016 16:41:26 +0200 (EET) Received: by mail-qt0-f193.google.com with SMTP id n34so11070662qtb.3 for ; Fri, 16 Dec 2016 06:41:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=oqEdxThErJfqMH0IfwWfp1Yg0CgPNadrhdNcbwjVlQg=; b=gjfYL8LOn+xlhP8DGjT4oFEctI/8JyNppMQunkHtEOjcaG1+0zB+3R9QdKUYBHMvJT 0xzmun72WANoeuBNk19jcwWXKAAk5q3Uv6GxmIIMXvPdvwYkP5HfLrShVV3n9N5bZZ9M Mwl8e8eDuHcXw7LH60ShIuI6ifmaAiJMYJS6W7jJwaP4J/oouK9+beDYcd5P8T4Bz4SU fiNA2GjFbzxebelj5zs1gPKeJ81iJEUnPqSXy72DxnGmnQBxThgmoCxyaHkBUQ+GyYRP 0Tp/yFt+6KXMVJJPWVxK/6OlFVoBIlZQxdnwjJGpkVkYsfhMWdR66xvZV5IJvQQdw1UD P3Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=oqEdxThErJfqMH0IfwWfp1Yg0CgPNadrhdNcbwjVlQg=; b=kcpaQFJ+xIOGMvteThFNrc/tiM9n0Ef3NP9x7h63UCiUIi7vA2VMeYhJXiYsrBqUUl dT62Kb+jlOAfeQMVIhB+CJBCoyfeHmbWAOesXoFxCc3bzSNYo15AcpaZU/fQ2OjebbBU l/p6V3Zn3aT4nmrdnJkrdZBTRyNh20cwF+xWPQeB32t1wae5lHH3AXTQCRn5xyxrHnMJ WLwdGnoZ1O/w6JYShI8ei/IOTalr5FrKTBmab15pecxeKXsuMz5ceLWZhGjWEb0C9VfV YxHUPLITGdg64kTJLbnlpg/TiWfs1wfdzcq5EY/gj4eCBdkpEf9Q6aKT+KnnQIMMv65D BkHw== X-Gm-Message-State: AIkVDXKUvRZNPDVlxlzyH0GFiS9z5DviZ7eYnPQ0xEyrcaLhlVv/PnC2oGGOYrSNkkLIaA== X-Received: by 10.237.35.3 with SMTP id h3mr2961077qtc.155.1481899291596; Fri, 16 Dec 2016 06:41:31 -0800 (PST) Received: from localhost.localdomain ([65.206.95.146]) by smtp.gmail.com with ESMTPSA id f2sm3824665qtg.22.2016.12.16.06.41.30 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 16 Dec 2016 06:41:30 -0800 (PST) From: "Ronald S. Bultje" To: ffmpeg-devel@ffmpeg.org Date: Fri, 16 Dec 2016 09:41:28 -0500 Message-Id: <1481899288-69470-1-git-send-email-rsbultje@gmail.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1481894385-64104-1-git-send-email-rsbultje@gmail.com> References: <1481894385-64104-1-git-send-email-rsbultje@gmail.com> Subject: [FFmpeg-devel] [PATCH] wmavoice: don't check if we have enough bits to read a superframe. 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 Cc: "Ronald S. Bultje" MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The checked bitstream reader makes this unnecessary. --- libavcodec/wmavoice.c | 86 ++------------------------------------------------- 1 file changed, 2 insertions(+), 84 deletions(-) diff --git a/libavcodec/wmavoice.c b/libavcodec/wmavoice.c index ba02c7d..e4ea128 100644 --- a/libavcodec/wmavoice.c +++ b/libavcodec/wmavoice.c @@ -1654,83 +1654,6 @@ static void stabilize_lsps(double *lsps, int num) } /** - * Test if there's enough bits to read 1 superframe. - * - * @param orig_gb bit I/O context used for reading. This function - * does not modify the state of the bitreader; it - * only uses it to copy the current stream position - * @param s WMA Voice decoding context private data - * @return < 0 on error, 1 on not enough bits or 0 if OK. - */ -static int check_bits_for_superframe(GetBitContext *orig_gb, - WMAVoiceContext *s) -{ - GetBitContext s_gb, *gb = &s_gb; - int n, need_bits, bd_idx; - const struct frame_type_desc *frame_desc; - - /* initialize a copy */ - init_get_bits(gb, orig_gb->buffer, orig_gb->size_in_bits); - skip_bits_long(gb, get_bits_count(orig_gb)); - av_assert1(get_bits_left(gb) == get_bits_left(orig_gb)); - - /* superframe header */ - if (get_bits_left(gb) < 14) - return 1; - if (!get_bits1(gb)) - return AVERROR(ENOSYS); // WMAPro-in-WMAVoice superframe - if (get_bits1(gb)) skip_bits(gb, 12); // number of samples in superframe - if (s->has_residual_lsps) { // residual LSPs (for all frames) - if (get_bits_left(gb) < s->sframe_lsp_bitsize) - return 1; - skip_bits_long(gb, s->sframe_lsp_bitsize); - } - - /* frames */ - for (n = 0; n < MAX_FRAMES; n++) { - int aw_idx_is_ext = 0; - - if (!s->has_residual_lsps) { // independent LSPs (per-frame) - if (get_bits_left(gb) < s->frame_lsp_bitsize) return 1; - skip_bits_long(gb, s->frame_lsp_bitsize); - } - bd_idx = s->vbm_tree[get_vlc2(gb, frame_type_vlc.table, 6, 3)]; - if (bd_idx < 0) - return AVERROR_INVALIDDATA; // invalid frame type VLC code - frame_desc = &frame_descs[bd_idx]; - if (frame_desc->acb_type == ACB_TYPE_ASYMMETRIC) { - if (get_bits_left(gb) < s->pitch_nbits) - return 1; - skip_bits_long(gb, s->pitch_nbits); - } - if (frame_desc->fcb_type == FCB_TYPE_SILENCE) { - skip_bits(gb, 8); - } else if (frame_desc->fcb_type == FCB_TYPE_AW_PULSES) { - int tmp = get_bits(gb, 6); - if (tmp >= 0x36) { - skip_bits(gb, 2); - aw_idx_is_ext = 1; - } - } - - /* blocks */ - if (frame_desc->acb_type == ACB_TYPE_HAMMING) { - need_bits = s->block_pitch_nbits + - (frame_desc->n_blocks - 1) * s->block_delta_pitch_nbits; - } else if (frame_desc->fcb_type == FCB_TYPE_AW_PULSES) { - need_bits = 2 * !aw_idx_is_ext; - } else - need_bits = 0; - need_bits += frame_desc->frame_size; - if (get_bits_left(gb) < need_bits) - return 1; - skip_bits_long(gb, need_bits); - } - - return 0; -} - -/** * Synthesize output samples for a single superframe. If we have any data * cached in s->sframe_cache, that will be used instead of whatever is loaded * in s->gb. @@ -1771,12 +1694,6 @@ static int synth_superframe(AVCodecContext *ctx, AVFrame *frame, s->sframe_cache_size = 0; } - if ((res = check_bits_for_superframe(gb, s)) == 1) { - *got_frame_ptr = 0; - return 1; - } else if (res < 0) - return res; - /* First bit is speech/music bit, it differentiates between WMAVoice * speech samples (the actual codec) and WMAVoice music samples, which * are really WMAPro-in-WMAVoice-superframes. I've never seen those in @@ -1999,7 +1916,7 @@ static int wmavoice_decode_packet(AVCodecContext *ctx, void *data, pos = get_bits_left(gb); if ((res = synth_superframe(ctx, data, got_frame_ptr)) < 0) { return res; - } else if (*got_frame_ptr) { + } else if (*got_frame_ptr && get_bits_left(&s->gb) >= 0) { int cnt = get_bits_count(gb); s->skip_bits_next = cnt & 7; res = cnt >> 3; @@ -2015,6 +1932,7 @@ static int wmavoice_decode_packet(AVCodecContext *ctx, void *data, copy_bits(&s->pb, avpkt->data, size, gb, s->sframe_cache_size); // FIXME bad - just copy bytes as whole and add use the // skip_bits_next field + *got_frame_ptr = 0; } return size;