From patchwork Tue Nov 8 13:30:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Butterworth X-Patchwork-Id: 1341 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.90.1 with SMTP id o1csp1689092vsb; Tue, 8 Nov 2016 05:31:14 -0800 (PST) X-Received: by 10.28.8.202 with SMTP id 193mr11964191wmi.101.1478611874829; Tue, 08 Nov 2016 05:31:14 -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 nb7si33763375wjb.12.2016.11.08.05.31.14; Tue, 08 Nov 2016 05:31:14 -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 7468F689D4F; Tue, 8 Nov 2016 15:31:03 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 244DC689D2A for ; Tue, 8 Nov 2016 15:30:57 +0200 (EET) Received: by mail-wm0-f67.google.com with SMTP id c17so22588668wmc.3 for ; Tue, 08 Nov 2016 05:31:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=d0D6crlADm+jLPTq29GAEOxtdG2Mt062AdHNaHqA4Lk=; b=PKS4mox319iV0VH9uDaAXWna9i4o9vg14wn7ATJkF/Mm1tyFAYbvsZK18wKnnYEm9Y x9kBk1HXYFme1IOa4g5Fh9v4VOqXtiEwlvn0OEpAsydoDmUSPsbc8LwyfrE4vZrT0Jkx e9nw5gpdpryHGypvZnYmTzEBf9MB5Og3FM4v9Yu3Q5+boOgup/phfdBNVHb69m7dHb73 xQyxz+kTh2nZ5ZShsp8MCqqjJdk9RZxpUV0MHd3GtO9hLHCagTQAUvetQqJARmrcl231 sdx9QuKVwoVUr6q4EPB7wfrxFMCO4+hIhwNLBIgv0UJRnFokVyk+tjqtt2o8KrbCw0c6 th9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=d0D6crlADm+jLPTq29GAEOxtdG2Mt062AdHNaHqA4Lk=; b=iJubKGv8501a4t2A9qyMEBWPgXLuGQBcNYlBoWJJggL0Z9nF3tEOwtJEoEQDW1XMx/ zfjCh9cUx4XGEgVEhdSFJ49sw23DeSFDMzjDroq6GTeqaw5rv81ig63txHT2e3mhqqAg 74oQkPlMtvzPmxbckVlVH53VaGPVw9UAeCfmxZuR8IEWLLZC9Qz283a/n9HOxmPU9vSW QUw7GDVxZGX8JlNb8CadNIi29ws00Wl/HCZQdkNVmsiZvYnnt7PUaQGImx1hfex8pAmR 264+I39+4QGSUrf+O+hWNwQAMKatU43otyyIc8ugORpMLrQZaTqTe2pITpsJwU9L2SjZ ENeQ== X-Gm-Message-State: ABUngvdrQRJjFUqGXacAG/JR9GNCqtkp939f8iSQfTVeBQJ8ImlCf/ThzAz2LtDfphn/fw== X-Received: by 10.194.192.197 with SMTP id hi5mr10321442wjc.71.1478611860287; Tue, 08 Nov 2016 05:31:00 -0800 (PST) Received: from motbook-pro.Home (bcdf199e.skybroadband.com. [188.223.25.158]) by smtp.gmail.com with ESMTPSA id m5sm19610274wmd.17.2016.11.08.05.30.58 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 08 Nov 2016 05:30:59 -0800 (PST) From: Tom Butterworth To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Nov 2016 13:30:54 +0000 Message-Id: <20161108133054.90950-2-bangnoise@gmail.com> X-Mailer: git-send-email 2.9.3 (Apple Git-75) In-Reply-To: <20161108133054.90950-1-bangnoise@gmail.com> References: <20161108133054.90950-1-bangnoise@gmail.com> Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/hap: add "compressor" option to Hap encoder to disable secondary compression 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: Tom Butterworth MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The secondary compression in Hap is optional, this change exposes that option to the user as some use-cases favour higher bitrate files to reduce workload decoding. Adds "none" or "snappy" as options for "compressor". Selecting "none" disregards "chunks" option: chunking is only of benefit decompressing Snappy. --- libavcodec/hap.h | 1 + libavcodec/hapenc.c | 65 +++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 47 insertions(+), 19 deletions(-) diff --git a/libavcodec/hap.h b/libavcodec/hap.h index e4762ee..f39e621 100644 --- a/libavcodec/hap.h +++ b/libavcodec/hap.h @@ -65,6 +65,7 @@ typedef struct HapContext { enum HapTextureFormat opt_tex_fmt; /* Texture type (encoder only) */ int opt_chunk_count; /* User-requested chunk count (encoder only) */ + int opt_compressor; /* User-requested compressor (encoder only) */ int chunk_count; HapChunk *chunks; diff --git a/libavcodec/hapenc.c b/libavcodec/hapenc.c index 79b6074..3a1bc87 100644 --- a/libavcodec/hapenc.c +++ b/libavcodec/hapenc.c @@ -204,15 +204,25 @@ static int hap_encode(AVCodecContext *avctx, AVPacket *pkt, if (ret < 0) return ret; - /* DXTC compression. */ - ret = compress_texture(avctx, ctx->tex_buf, ctx->tex_size, frame); - if (ret < 0) - return ret; - - /* Compress (using Snappy) the frame */ - final_data_size = hap_compress_frame(avctx, pkt->data + header_length); - if (final_data_size < 0) - return final_data_size; + if (ctx->opt_compressor == HAP_COMP_NONE) { + /* DXTC compression directly to the packet buffer. */ + ret = compress_texture(avctx, pkt->data + header_length, pkt->size - header_length, frame); + if (ret < 0) + return ret; + + ctx->chunks[0].compressor = HAP_COMP_NONE; + final_data_size = ctx->tex_size; + } else { + /* DXTC compression. */ + ret = compress_texture(avctx, ctx->tex_buf, ctx->tex_size, frame); + if (ret < 0) + return ret; + + /* Compress (using Snappy) the frame */ + final_data_size = hap_compress_frame(avctx, pkt->data + header_length); + if (final_data_size < 0) + return final_data_size; + } /* Write header at the start. */ hap_write_frame_header(ctx, pkt->data, final_data_size + header_length); @@ -273,10 +283,30 @@ static av_cold int hap_init(AVCodecContext *avctx) ctx->tex_size = FFALIGN(avctx->width, TEXTURE_BLOCK_W) * FFALIGN(avctx->height, TEXTURE_BLOCK_H) * 4 / ratio; - /* Round the chunk count to divide evenly on DXT block edges */ - corrected_chunk_count = av_clip(ctx->opt_chunk_count, 1, HAP_MAX_CHUNKS); - while ((ctx->tex_size / (64 / ratio)) % corrected_chunk_count != 0) { - corrected_chunk_count--; + switch (ctx->opt_compressor) { + case HAP_COMP_NONE: + /* No benefit chunking uncompressed data */ + corrected_chunk_count = 1; + + ctx->max_snappy = ctx->tex_size; + ctx->tex_buf = NULL; + break; + case HAP_COMP_SNAPPY: + /* Round the chunk count to divide evenly on DXT block edges */ + corrected_chunk_count = av_clip(ctx->opt_chunk_count, 1, HAP_MAX_CHUNKS); + while ((ctx->tex_size / (64 / ratio)) % corrected_chunk_count != 0) { + corrected_chunk_count--; + } + + ctx->max_snappy = snappy_max_compressed_length(ctx->tex_size / corrected_chunk_count); + ctx->tex_buf = av_malloc(ctx->tex_size); + if (!ctx->tex_buf) { + return AVERROR(ENOMEM); + } + break; + default: + av_log(avctx, AV_LOG_ERROR, "Invalid compresor %02X\n", ctx->opt_compressor); + return AVERROR_INVALIDDATA; } if (corrected_chunk_count != ctx->opt_chunk_count) { av_log(avctx, AV_LOG_INFO, "%d chunks requested but %d used.\n", @@ -286,12 +316,6 @@ static av_cold int hap_init(AVCodecContext *avctx) if (ret != 0) return ret; - ctx->max_snappy = snappy_max_compressed_length(ctx->tex_size / corrected_chunk_count); - - ctx->tex_buf = av_malloc(ctx->tex_size); - if (!ctx->tex_buf) - return AVERROR(ENOMEM); - return 0; } @@ -312,6 +336,9 @@ static const AVOption options[] = { { "hap_alpha", "Hap Alpha (DXT5 textures)", 0, AV_OPT_TYPE_CONST, { .i64 = HAP_FMT_RGBADXT5 }, 0, 0, FLAGS, "format" }, { "hap_q", "Hap Q (DXT5-YCoCg textures)", 0, AV_OPT_TYPE_CONST, { .i64 = HAP_FMT_YCOCGDXT5 }, 0, 0, FLAGS, "format" }, { "chunks", "chunk count", OFFSET(opt_chunk_count), AV_OPT_TYPE_INT, {.i64 = 1 }, 1, HAP_MAX_CHUNKS, FLAGS, }, + { "compressor", "second-stage compressor", OFFSET(opt_compressor), AV_OPT_TYPE_INT, { .i64 = HAP_COMP_SNAPPY }, HAP_COMP_NONE, HAP_COMP_SNAPPY, FLAGS, "compressor" }, + { "none", "None", 0, AV_OPT_TYPE_CONST, { .i64 = HAP_COMP_NONE }, 0, 0, FLAGS, "compressor" }, + { "snappy", "Snappy", 0, AV_OPT_TYPE_CONST, { .i64 = HAP_COMP_SNAPPY }, 0, 0, FLAGS, "compressor" }, { NULL }, };