From patchwork Sun Jan 29 17:43:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: u-9iep@aetey.se X-Patchwork-Id: 2359 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp1122955vsb; Sun, 29 Jan 2017 09:43:46 -0800 (PST) X-Received: by 10.223.135.146 with SMTP id b18mr14881083wrb.189.1485711825923; Sun, 29 Jan 2017 09:43:45 -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 v26si13412906wrv.93.2017.01.29.09.43.45; Sun, 29 Jan 2017 09:43:45 -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=@fripost.org; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C0FEB68A354; Sun, 29 Jan 2017 19:43:41 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from outgoing.fripost.org (giraff.fripost.org [178.16.208.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 411F668A29D for ; Sun, 29 Jan 2017 19:43:35 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by outgoing.fripost.org (Postfix) with ESMTP id F3536A5A1EB for ; Sun, 29 Jan 2017 18:43:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fripost.org; h= content-disposition:content-type:content-type:mime-version :message-id:subject:subject:from:from:date:date; s=20140703; t= 1485711816; x=1487526217; bh=bmSExnOi58kcTHgwE9W3AKMWneFhXQSqTSl hm0Mt7g8=; b=FlCgeu6CV87cimpcFUbnILXMeFVqK4RJpYxuILbYpHnXmEY4BzZ JZ98ZIWUbf/Cjo18QpzqlQ1z2CbZkxhEOS6wZCxyi5ho5azn2Hy/6cSQIenI0lro ElbYVsVx1d6rscB3IWK/0/kaylPyHxFs8VMpk9bUkBSdjfYlXzylQixo= X-Virus-Scanned: Debian amavisd-new at fripost.org Received: from outgoing.fripost.org ([127.0.0.1]) by localhost (giraff.fripost.org [127.0.0.1]) (amavisd-new, port 10040) with LMTP id V1lv9osVi38v for ; Sun, 29 Jan 2017 18:43:36 +0100 (CET) Received: from smtp.fripost.org (unknown [172.16.0.6]) by outgoing.fripost.org (Postfix) with ESMTP id BBE7BA5A1E1 for ; Sun, 29 Jan 2017 18:43:36 +0100 (CET) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by smtp.fripost.org (Postfix) with ESMTPSA id D530E29B24E2 for ; Sun, 29 Jan 2017 18:43:35 +0100 (CET) Received: (qmail 18696 invoked from network); 29 Jan 2017 17:21:23 -0000 Received: from localhost (HELO aetey.se) (eh1ba719@127.0.0.1) by mail with ESMTPA; 29 Jan 2017 17:21:22 -0000 Date: Sun, 29 Jan 2017 18:43:23 +0100 From: u-9iep@aetey.se To: FFmpeg development discussions and patches Message-ID: <20170129174323.GR1516@example.net> MIME-Version: 1.0 Content-Disposition: inline Subject: [FFmpeg-devel] [PATCH 2/3] libavcodec/cinepakenc.c: comments style cleanup 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" Attaching the new version. Regards, Rune From e6719743b78862f897133d3f69a5e88a6a9a803e Mon Sep 17 00:00:00 2001 From: Rl Date: Sun, 29 Jan 2017 18:14:19 +0100 Subject: [PATCH 2/3] libavcodec/cinepakenc.c: comments style cleanup Avoid the present mixture of comment styles (C vs C++) by converting to the traditional C style. --- libavcodec/cinepakenc.c | 340 +++++++++++++++++++++++++++--------------------- 1 file changed, 192 insertions(+), 148 deletions(-) diff --git a/libavcodec/cinepakenc.c b/libavcodec/cinepakenc.c index a28f669070..8c27c2a1aa 100644 --- a/libavcodec/cinepakenc.c +++ b/libavcodec/cinepakenc.c @@ -80,22 +80,24 @@ OTHER DEALINGS IN THE SOFTWARE. #define STRIP_HEADER_SIZE 12 #define CHUNK_HEADER_SIZE 4 -#define MB_SIZE 4 //4x4 MBs +#define MB_SIZE 4 /* 4x4 MBs */ #define MB_AREA (MB_SIZE*MB_SIZE) -#define VECTOR_MAX 6 //six or four entries per vector depending on format -#define CODEBOOK_MAX 256 //size of a codebook +#define VECTOR_MAX 6 /* six or four entries per vector depending on format */ +#define CODEBOOK_MAX 256 /* size of a codebook */ -#define MAX_STRIPS 32 //Note: having fewer choices regarding the number of strips speeds up encoding (obviously) -#define MIN_STRIPS 1 //Note: having more strips speeds up encoding the frame (this is less obvious) -// MAX_STRIPS limits the maximum quality you can reach -// when you want high quality on high resolutions, -// MIN_STRIPS limits the minimum efficiently encodable bit rate -// on low resolutions -// the numbers are only used for brute force optimization for the first frame, -// for the following frames they are adaptively readjusted -// NOTE the decoder in ffmpeg has its own arbitrary limitation on the number -// of strips, currently 32 +#define MAX_STRIPS 32 /* Note: having fewer choices regarding the number of strips speeds up encoding (obviously) */ +#define MIN_STRIPS 1 /* Note: having more strips speeds up encoding the frame (this is less obvious) */ +/* + * MAX_STRIPS limits the maximum quality you can reach + * when you want high quality on high resolutions, + * MIN_STRIPS limits the minimum efficiently encodable bit rate + * on low resolutions + * the numbers are only used for brute force optimization for the first frame, + * for the following frames they are adaptively readjusted + * NOTE the decoder in ffmpeg has its own arbitrary limitation on the number + * of strips, currently 32 + */ typedef enum { MODE_V1_ONLY = 0, @@ -114,12 +116,12 @@ typedef enum { } mb_encoding; typedef struct { - int v1_vector; //index into v1 codebook - int v1_error; //error when using V1 encoding - int v4_vector[4]; //indices into v4 codebook - int v4_error; //error when using V4 encoding - int skip_error; //error when block is skipped (aka copied from last frame) - mb_encoding best_encoding; //last result from calculate_mode_score() + int v1_vector; /* index into v1 codebook */ + int v1_error; /* error when using V1 encoding */ + int v4_vector[4]; /* indices into v4 codebook */ + int v4_error; /* error when using V4 encoding */ + int skip_error; /* error when block is skipped (aka copied from last frame) */ + mb_encoding best_encoding; /* last result from calculate_mode_score() */ } mb_info; typedef struct { @@ -146,15 +148,15 @@ typedef struct { uint64_t lambda; int *codebook_input; int *codebook_closest; - mb_info *mb; //MB RD state - int min_strips; //the current limit - int max_strips; //the current limit + mb_info *mb; /* MB RD state */ + int min_strips; /* the current limit */ + int max_strips; /* the current limit */ #ifdef CINEPAKENC_DEBUG - mb_info *best_mb; //TODO: remove. only used for printing stats + mb_info *best_mb; /* TODO: remove. only used for printing stats */ int num_v1_mode, num_v4_mode, num_mc_mode; int num_v1_encs, num_v4_encs, num_skips; #endif -// options +/* options */ int max_extra_cb_iterations; int skip_empty_cb; int min_min_strips; @@ -219,10 +221,12 @@ static av_cold int cinepak_encode_init(AVCodecContext *avctx) mb_count = avctx->width * avctx->height / MB_AREA; - //the largest possible chunk is 0x31 with all MBs encoded in V4 mode - //and full codebooks being replaced in INTER mode, - // which is 34 bits per MB - //and 2*256 extra flag bits per strip + /* + * the largest possible chunk is 0x31 with all MBs encoded in V4 mode + * and full codebooks being replaced in INTER mode, + * which is 34 bits per MB + * and 2*256 extra flag bits per strip + */ strip_buf_size = STRIP_HEADER_SIZE + 3 * CHUNK_HEADER_SIZE + 2 * VECTOR_MAX * CODEBOOK_MAX + 4 * (mb_count + (mb_count + 15) / 16) + (2 * CODEBOOK_MAX)/8; frame_buf_size = CVID_HEADER_SIZE + s->max_max_strips * strip_buf_size; @@ -250,7 +254,7 @@ static av_cold int cinepak_encode_init(AVCodecContext *avctx) s->keyint = avctx->keyint_min; s->pix_fmt = avctx->pix_fmt; - //set up AVFrames + /* set up AVFrames */ s->last_frame->data[0] = s->pict_bufs[0]; s->last_frame->linesize[0] = s->w; s->best_frame->data[0] = s->pict_bufs[1]; @@ -314,7 +318,7 @@ static int64_t calculate_mode_score(CinepakEncContext *s, int h, strip_info *inf #endif ) { - //score = FF_LAMBDA_SCALE * error + lambda * bits + /* score = FF_LAMBDA_SCALE * error + lambda * bits */ int x; int entry_size = s->pix_fmt == AV_PIX_FMT_RGB24 ? 6 : 4; int mb_count = s->w * h / MB_AREA; @@ -324,7 +328,9 @@ static int64_t calculate_mode_score(CinepakEncContext *s, int h, strip_info *inf (info->v4_size ? CHUNK_HEADER_SIZE + info->v4_size * entry_size : 0) + CHUNK_HEADER_SIZE) << 3; - //av_log(s->avctx, AV_LOG_INFO, "sizes %3i %3i -> %9"PRId64" score mb_count %i", info->v1_size, info->v4_size, ret, mb_count); +/**** + av_log(s->avctx, AV_LOG_INFO, "sizes %3i %3i -> %9"PRId64" score mb_count %i", info->v1_size, info->v4_size, ret, mb_count); +****/ #ifdef CINEPAK_REPORT_SERR *serr = 0; @@ -332,26 +338,26 @@ static int64_t calculate_mode_score(CinepakEncContext *s, int h, strip_info *inf switch(info->mode) { case MODE_V1_ONLY: - //one byte per MB + /* one byte per MB */ ret += s->lambda * 8 * mb_count; -// while calculating we assume all blocks are ENC_V1 +/* while calculating we assume all blocks are ENC_V1 */ for(x = 0; x < mb_count; x++) { mb = &s->mb[x]; ret += FF_LAMBDA_SCALE * mb->v1_error; #ifdef CINEPAK_REPORT_SERR *serr += mb->v1_error; #endif -// this function is never called for report in MODE_V1_ONLY -// if(!report) +/* this function is never called for report in MODE_V1_ONLY */ +/* if(!report) */ mb->best_encoding = ENC_V1; } break; case MODE_V1_V4: - //9 or 33 bits per MB + /* 9 or 33 bits per MB */ if(report) { -// no moves between the corresponding training sets are allowed +/* no moves between the corresponding training sets are allowed */ *training_set_v1_shrunk = *training_set_v4_shrunk = 0; for(x = 0; x < mb_count; x++) { int mberr; @@ -365,7 +371,7 @@ static int64_t calculate_mode_score(CinepakEncContext *s, int h, strip_info *inf *serr += mberr; #endif } - } else { // find best mode per block + } else { /* find best mode per block */ for(x = 0; x < mb_count; x++) { mb = &s->mb[x]; score1 = s->lambda * 9 + FF_LAMBDA_SCALE * mb->v1_error; @@ -389,13 +395,13 @@ static int64_t calculate_mode_score(CinepakEncContext *s, int h, strip_info *inf break; case MODE_MC: - //1, 10 or 34 bits per MB + /* 1, 10 or 34 bits per MB */ if(report) { int v1_shrunk = 0, v4_shrunk = 0; for(x = 0; x < mb_count; x++) { mb = &s->mb[x]; -// it is OK to move blocks to ENC_SKIP here -// but not to any codebook encoding! +/* it is OK to move blocks to ENC_SKIP here */ +/* but not to any codebook encoding! */ score1 = s->lambda * 1 + FF_LAMBDA_SCALE * mb->skip_error; if(mb->best_encoding == ENC_SKIP) { ret += score1; @@ -434,7 +440,7 @@ static int64_t calculate_mode_score(CinepakEncContext *s, int h, strip_info *inf } *training_set_v1_shrunk = v1_shrunk; *training_set_v4_shrunk = v4_shrunk; - } else { // find best mode per block + } else { /* find best mode per block */ for(x = 0; x < mb_count; x++) { mb = &s->mb[x]; score1 = s->lambda * 1 + FF_LAMBDA_SCALE * mb->skip_error; @@ -479,8 +485,8 @@ static int write_chunk_header(unsigned char *buf, int chunk_type, int chunk_size static int encode_codebook(CinepakEncContext *s, int *codebook, int size, int chunk_type_yuv, int chunk_type_gray, unsigned char *buf) { int x, y, ret, entry_size = s->pix_fmt == AV_PIX_FMT_RGB24 ? 6 : 4; - int incremental_codebook_replacement_mode = 0; // hardcoded here, - // the compiler should notice that this is a constant -- rl + int incremental_codebook_replacement_mode = 0; /* hardcoded here, */ + /* the compiler should notice that this is a constant -- rl */ ret = write_chunk_header(buf, s->pix_fmt == AV_PIX_FMT_RGB24 ? @@ -489,11 +495,13 @@ static int encode_codebook(CinepakEncContext *s, int *codebook, int size, int ch entry_size * size + (incremental_codebook_replacement_mode?(size+31)/32*4:0) ); -// we do codebook encoding according to the "intra" mode -// but we keep the "dead" code for reference in case we will want -// to use incremental codebook updates (which actually would give us -// "kind of" motion compensation, especially in 1 strip/frame case) -- rl -// (of course, the code will be not useful as-is) +/* + * we do codebook encoding according to the "intra" mode + * but we keep the "dead" code for reference in case we will want + * to use incremental codebook updates (which actually would give us + * "kind of" motion compensation, especially in 1 strip/frame case) -- rl + * (of course, the code will be not useful as-is) + */ if(incremental_codebook_replacement_mode) { int flags = 0; int flagsind; @@ -521,7 +529,7 @@ static int encode_codebook(CinepakEncContext *s, int *codebook, int size, int ch return ret; } -//sets out to the sub picture starting at (x,y) in in +/* sets out to the sub picture starting at (x,y) in in */ static void get_sub_picture(CinepakEncContext *s, int x, int y, uint8_t * in_data[4], int in_linesize[4], uint8_t *out_data[4], int out_linesize[4]) @@ -538,7 +546,7 @@ static void get_sub_picture(CinepakEncContext *s, int x, int y, } } -//decodes the V1 vector in mb into the 4x4 MB pointed to by data +/* decodes the V1 vector in mb into the 4x4 MB pointed to by data */ static void decode_v1_vector(CinepakEncContext *s, uint8_t *data[4], int linesize[4], int v1_vector, strip_info *info) { @@ -577,7 +585,7 @@ static void decode_v1_vector(CinepakEncContext *s, uint8_t *data[4], } } -//decodes the V4 vectors in mb into the 4x4 MB pointed to by data +/* decodes the V4 vectors in mb into the 4x4 MB pointed to by data */ static void decode_v4_vector(CinepakEncContext *s, uint8_t *data[4], int linesize[4], int *v4_vector, strip_info *info) { @@ -627,22 +635,24 @@ static int encode_mode(CinepakEncContext *s, int h, { int x, y, z, flags, bits, temp_size, header_ofs, ret = 0, mb_count = s->w * h / MB_AREA; int needs_extra_bit, should_write_temp; - unsigned char temp[64]; //32/2 = 16 V4 blocks at 4 B each -> 64 B + unsigned char temp[64]; /* 32/2 = 16 V4 blocks at 4 B each -> 64 B */ mb_info *mb; uint8_t *sub_scratch_data[4] = {0}, *sub_last_data[4] = {0}; int sub_scratch_linesize[4] = {0}, sub_last_linesize[4] = {0}; - //encode codebooks -////// MacOS vintage decoder compatibility dictates the presence of -////// the codebook chunk even when the codebook is empty - pretty dumb... -////// and also the certain order of the codebook chunks -- rl + /* encode codebooks */ +/* + *** MacOS vintage decoder compatibility dictates the presence of + *** the codebook chunk even when the codebook is empty - pretty dumb... + *** and also the certain order of the codebook chunks -- rl + */ if(info->v4_size || !s->skip_empty_cb) ret += encode_codebook(s, info->v4_codebook, info->v4_size, 0x20, 0x24, buf + ret); if(info->v1_size || !s->skip_empty_cb) ret += encode_codebook(s, info->v1_codebook, info->v1_size, 0x22, 0x26, buf + ret); - //update scratch picture + /* update scratch picture */ for(z = y = 0; y < h; y += MB_SIZE) { for(x = 0; x < s->w; x += MB_SIZE, z++) { mb = &s->mb[z]; @@ -667,7 +677,9 @@ static int encode_mode(CinepakEncContext *s, int h, switch(info->mode) { case MODE_V1_ONLY: - //av_log(s->avctx, AV_LOG_INFO, "mb_count = %i\n", mb_count); +/**** + av_log(s->avctx, AV_LOG_INFO, "mb_count = %i\n", mb_count); +****/ ret += write_chunk_header(buf + ret, 0x32, mb_count); for(x = 0; x < mb_count; x++) @@ -675,7 +687,7 @@ static int encode_mode(CinepakEncContext *s, int h, break; case MODE_V1_V4: - //remember header position + /* remember header position */ header_ofs = ret; ret += CHUNK_HEADER_SIZE; @@ -703,7 +715,7 @@ static int encode_mode(CinepakEncContext *s, int h, break; case MODE_MC: - //remember header position + /* remember header position */ header_ofs = ret; ret += CHUNK_HEADER_SIZE; flags = bits = temp_size = 0; @@ -767,7 +779,7 @@ static int encode_mode(CinepakEncContext *s, int h, return ret; } -//computes distortion of 4x4 MB in b compared to a +/* computes distortion of 4x4 MB in b compared to a */ static int compute_mb_distortion(CinepakEncContext *s, uint8_t *a_data[4], int a_linesize[4], uint8_t *b_data[4], int b_linesize[4]) @@ -795,7 +807,7 @@ static int compute_mb_distortion(CinepakEncContext *s, return ret; } -// return the possibly adjusted size of the codebook +/* return the possibly adjusted size of the codebook */ #define CERTAIN(x) ((x)!=ENC_UNCERTAIN) static int quantize(CinepakEncContext *s, int h, uint8_t *data[4], int linesize[4], @@ -816,13 +828,13 @@ static int quantize(CinepakEncContext *s, int h, int *base; if(CERTAIN(encoding)) { -// use for the training only the blocks known to be to be encoded [sic:-] +/* use for the training only the blocks known to be to be encoded [sic:-] */ if(s->mb[mbn].best_encoding != encoding) continue; } base = s->codebook_input + i*entry_size; if(v1mode) { - //subsample + /* subsample */ for(j = y2 = 0; y2 < entry_size; y2 += 2) { for(x2 = 0; x2 < 4; x2 += 2, j++) { plane = y2 < 4 ? 0 : 1 + (x2 >> 1); @@ -836,7 +848,7 @@ static int quantize(CinepakEncContext *s, int h, } } } else { - //copy + /* copy */ for(j = y2 = 0; y2 < MB_SIZE; y2 += 2) { for(x2 = 0; x2 < MB_SIZE; x2 += 2) { for(k = 0; k < entry_size; k++, j++) { @@ -858,42 +870,46 @@ static int quantize(CinepakEncContext *s, int h, i += v1mode ? 1 : 4; } } -// if(i < mbn*(v1mode ? 1 : 4)) { -// av_log(s->avctx, AV_LOG_INFO, "reducing training set for %s from %i to %i (encoding %i)\n", v1mode?"v1":"v4", mbn*(v1mode ? 1 : 4), i, encoding); -// } +/**** + if(i < mbn*(v1mode ? 1 : 4)) { + av_log(s->avctx, AV_LOG_INFO, "reducing training set for %s from %i to %i (encoding %i)\n", v1mode?"v1":"v4", mbn*(v1mode ? 1 : 4), i, encoding); + } +****/ - if(i == 0) // empty training set, nothing to do + if(i == 0) /* empty training set, nothing to do */ return 0; if(i < size) { - //av_log(s->avctx, (CERTAIN(encoding) ? AV_LOG_ERROR : AV_LOG_INFO), "WOULD WASTE: %s cbsize %i bigger than training set size %i (encoding %i)\n", v1mode?"v1":"v4", size, i, encoding); +/**** + av_log(s->avctx, (CERTAIN(encoding) ? AV_LOG_ERROR : AV_LOG_INFO), "WOULD WASTE: %s cbsize %i bigger than training set size %i (encoding %i)\n", v1mode?"v1":"v4", size, i, encoding); +****/ size = i; } avpriv_init_elbg(s->codebook_input, entry_size, i, codebook, size, 1, s->codebook_closest, &s->randctx); avpriv_do_elbg(s->codebook_input, entry_size, i, codebook, size, 1, s->codebook_closest, &s->randctx); - //setup vq_data, which contains a single MB + /* setup vq_data, which contains a single MB */ vq_data[0] = vq_pict_buf; vq_linesize[0] = MB_SIZE; vq_data[1] = &vq_pict_buf[MB_AREA]; vq_data[2] = vq_data[1] + (MB_AREA >> 2); vq_linesize[1] = vq_linesize[2] = MB_SIZE >> 1; - //copy indices + /* copy indices */ for(i = j = y = 0; y < h; y += MB_SIZE) { for(x = 0; x < s->w; x += MB_SIZE, j++) { mb_info *mb = &s->mb[j]; -// skip uninteresting blocks if we know their preferred encoding +/* skip uninteresting blocks if we know their preferred encoding */ if(CERTAIN(encoding) && mb->best_encoding != encoding) continue; - //point sub_data to current MB + /* point sub_data to current MB */ get_sub_picture(s, x, y, data, linesize, sub_data, sub_linesize); if(v1mode) { mb->v1_vector = s->codebook_closest[i]; - //fill in vq_data with V1 data + /* fill in vq_data with V1 data */ decode_v1_vector(s, vq_data, vq_linesize, mb->v1_vector, info); mb->v1_error = compute_mb_distortion(s, sub_data, sub_linesize, @@ -903,7 +919,7 @@ static int quantize(CinepakEncContext *s, int h, for(k = 0; k < 4; k++) mb->v4_vector[k] = s->codebook_closest[i+k]; - //fill in vq_data with V4 data + /* fill in vq_data with V4 data */ decode_v4_vector(s, vq_data, vq_linesize, mb->v4_vector, info); mb->v4_error = compute_mb_distortion(s, sub_data, sub_linesize, @@ -913,10 +929,12 @@ static int quantize(CinepakEncContext *s, int h, i += v1mode ? 1 : 4; } } -// check that we did it right in the beginning of the function - av_assert0(i >= size); // training set is no smaller than the codebook +/* check that we did it right in the beginning of the function */ + av_assert0(i >= size); /* training set is no smaller than the codebook */ - //av_log(s->avctx, AV_LOG_INFO, "isv1 %i size= %i i= %i error %"PRId64"\n", v1mode, size, i, total_error); +/**** + av_log(s->avctx, AV_LOG_INFO, "isv1 %i size= %i i= %i error %"PRId64"\n", v1mode, size, i, total_error); +****/ return size; } @@ -946,20 +964,24 @@ static void calculate_skip_errors(CinepakEncContext *s, int h, static void write_strip_header(CinepakEncContext *s, int y, int h, int keyframe, unsigned char *buf, int strip_size) { -// actually we are exclusively using intra strip coding (how much can we win -// otherwise? how to choose which part of a codebook to update?), -// keyframes are different only because we disallow ENC_SKIP on them -- rl -// (besides, the logic here used to be inverted: ) -// buf[0] = keyframe ? 0x11: 0x10; +/* + * actually we are exclusively using intra strip coding (how much can we win + * otherwise? how to choose which part of a codebook to update?), + * keyframes are different only because we disallow ENC_SKIP on them -- rl + * (besides, the logic here used to be inverted: ) + * buf[0] = keyframe ? 0x11: 0x10; + */ buf[0] = keyframe ? 0x10: 0x11; AV_WB24(&buf[1], strip_size + STRIP_HEADER_SIZE); -// AV_WB16(&buf[4], y); /* using absolute y values works -- rl */ +/* AV_WB16(&buf[4], y); *//* using absolute y values works -- rl */ AV_WB16(&buf[4], 0); /* using relative values works as well -- rl */ AV_WB16(&buf[6], 0); -// AV_WB16(&buf[8], y+h); /* using absolute y values works -- rl */ +/* AV_WB16(&buf[8], y+h); *//* using absolute y values works -- rl */ AV_WB16(&buf[8], h); /* using relative values works as well -- rl */ AV_WB16(&buf[10], s->w); - //av_log(s->avctx, AV_LOG_INFO, "write_strip_header() %x keyframe=%d\n", buf[0], keyframe); +/**** + av_log(s->avctx, AV_LOG_INFO, "write_strip_header() %x keyframe=%d\n", buf[0], keyframe); +****/ } static int rd_strip(CinepakEncContext *s, int y, int h, int keyframe, @@ -978,7 +1000,7 @@ static int rd_strip(CinepakEncContext *s, int y, int h, int keyframe, #endif int best_size = 0; strip_info info; -// for codebook optimization: +/* for codebook optimization: */ int v1enough, v1_size, v4enough, v4_size; int new_v1_size, new_v4_size; int v1shrunk, v4shrunk; @@ -987,31 +1009,33 @@ static int rd_strip(CinepakEncContext *s, int y, int h, int keyframe, calculate_skip_errors(s, h, last_data, last_linesize, data, linesize, &info); - //try some powers of 4 for the size of the codebooks - //constraint the v4 codebook to be no bigger than v1 one, - //(and no less than v1_size/4) - //thus making v1 preferable and possibly losing small details? should be ok + /* + * try some powers of 4 for the size of the codebooks, + * constraint the v4 codebook to be no bigger than v1 one + * (and no less than v1_size/4) + * thus making v1 preferable and possibly losing small details? should be ok + */ #define SMALLEST_CODEBOOK 1 for(v1enough = 0, v1_size = SMALLEST_CODEBOOK; v1_size <= CODEBOOK_MAX && !v1enough; v1_size <<= 2) { for(v4enough = 0, v4_size = 0; v4_size <= v1_size && !v4enough; v4_size = v4_size ? v4_size << 2 : v1_size >= SMALLEST_CODEBOOK << 2 ? v1_size >> 2 : SMALLEST_CODEBOOK) { - //try all modes + /* try all modes */ for(CinepakMode mode = 0; mode < MODE_COUNT; mode++) { - //don't allow MODE_MC in intra frames + /* don't allow MODE_MC in intra frames */ if(keyframe && mode == MODE_MC) continue; if(mode == MODE_V1_ONLY) { info.v1_size = v1_size; -// the size may shrink even before optimizations if the input is short: +/* the size may shrink even before optimizations if the input is short: */ info.v1_size = quantize(s, h, data, linesize, 1, &info, ENC_UNCERTAIN); if(info.v1_size < v1_size) -// too few eligible blocks, no sense in trying bigger sizes +/* too few eligible blocks, no sense in trying bigger sizes */ v1enough = 1; info.v4_size = 0; - } else { // mode != MODE_V1_ONLY - // if v4 codebook is empty then only allow V1-only mode + } else { /* mode != MODE_V1_ONLY */ + /* if v4 codebook is empty then only allow V1-only mode */ if(!v4_size) continue; @@ -1020,13 +1044,13 @@ static int rd_strip(CinepakEncContext *s, int y, int h, int keyframe, info.v4_size = quantize(s, h, data, linesize, 0, &info, ENC_UNCERTAIN); if(info.v4_size < v4_size) -// too few eligible blocks, no sense in trying bigger sizes +/* too few eligible blocks, no sense in trying bigger sizes */ v4enough = 1; } } info.mode = mode; -// choose the best encoding per block, based on current experience +/* choose the best encoding per block, based on current experience */ score = calculate_mode_score(s, h, &info, 0, &v1shrunk, &v4shrunk #ifdef CINEPAK_REPORT_SERR @@ -1036,25 +1060,31 @@ static int rd_strip(CinepakEncContext *s, int y, int h, int keyframe, if(mode != MODE_V1_ONLY){ int extra_iterations_limit = s->max_extra_cb_iterations; -// recompute the codebooks, omitting the extra blocks -// we assume we _may_ come here with more blocks to encode than before +/* recompute the codebooks, omitting the extra blocks */ +/* we assume we _may_ come here with more blocks to encode than before */ info.v1_size = v1_size; new_v1_size = quantize(s, h, data, linesize, 1, &info, ENC_V1); if(new_v1_size < info.v1_size){ - //av_log(s->avctx, AV_LOG_INFO, "mode %i, %3i, %3i: cut v1 codebook to %i entries\n", mode, v1_size, v4_size, new_v1_size); +/**** + av_log(s->avctx, AV_LOG_INFO, "mode %i, %3i, %3i: cut v1 codebook to %i entries\n", mode, v1_size, v4_size, new_v1_size); +****/ info.v1_size = new_v1_size; } -// we assume we _may_ come here with more blocks to encode than before +/* we assume we _may_ come here with more blocks to encode than before */ info.v4_size = v4_size; new_v4_size = quantize(s, h, data, linesize, 0, &info, ENC_V4); if(new_v4_size < info.v4_size) { - //av_log(s->avctx, AV_LOG_INFO, "mode %i, %3i, %3i: cut v4 codebook to %i entries at first iteration\n", mode, v1_size, v4_size, new_v4_size); +/**** + av_log(s->avctx, AV_LOG_INFO, "mode %i, %3i, %3i: cut v4 codebook to %i entries at first iteration\n", mode, v1_size, v4_size, new_v4_size); +****/ info.v4_size = new_v4_size; } -// calculate the resulting score -// (do not move blocks to codebook encodings now, as some blocks may have -// got bigger errors despite a smaller training set - but we do not -// ever grow the training sets back) +/* + * calculate the resulting score + * (do not move blocks to codebook encodings now, as some blocks may have + * got bigger errors despite a smaller training set - but we do not + * ever grow the training sets back) + */ for(;;) { score = calculate_mode_score(s, h, &info, 1, &v1shrunk, &v4shrunk @@ -1062,14 +1092,16 @@ static int rd_strip(CinepakEncContext *s, int y, int h, int keyframe, , &serr #endif ); -// do we have a reason to reiterate? if so, have we reached the limit? +/* do we have a reason to reiterate? if so, have we reached the limit? */ if((!v1shrunk && !v4shrunk) || !extra_iterations_limit--) break; -// recompute the codebooks, omitting the extra blocks +/* recompute the codebooks, omitting the extra blocks */ if(v1shrunk) { info.v1_size = v1_size; new_v1_size = quantize(s, h, data, linesize, 1, &info, ENC_V1); if(new_v1_size < info.v1_size){ - //av_log(s->avctx, AV_LOG_INFO, "mode %i, %3i, %3i: cut v1 codebook to %i entries\n", mode, v1_size, v4_size, new_v1_size); +/**** + av_log(s->avctx, AV_LOG_INFO, "mode %i, %3i, %3i: cut v1 codebook to %i entries\n", mode, v1_size, v4_size, new_v1_size); +****/ info.v1_size = new_v1_size; } } @@ -1077,14 +1109,18 @@ static int rd_strip(CinepakEncContext *s, int y, int h, int keyframe, info.v4_size = v4_size; new_v4_size = quantize(s, h, data, linesize, 0, &info, ENC_V4); if(new_v4_size < info.v4_size) { - //av_log(s->avctx, AV_LOG_INFO, "mode %i, %3i, %3i: cut v4 codebook to %i entries\n", mode, v1_size, v4_size, new_v4_size); +/**** + av_log(s->avctx, AV_LOG_INFO, "mode %i, %3i, %3i: cut v4 codebook to %i entries\n", mode, v1_size, v4_size, new_v4_size); +****/ info.v4_size = new_v4_size; } } } } - //av_log(s->avctx, AV_LOG_INFO, "%3i %3i score = %"PRId64"\n", v1_size, v4_size, score); +/**** + av_log(s->avctx, AV_LOG_INFO, "%3i %3i score = %"PRId64"\n", v1_size, v4_size, score); +****/ if(best_size == 0 || score < *best_score) { @@ -1097,18 +1133,20 @@ static int rd_strip(CinepakEncContext *s, int y, int h, int keyframe, last_data, last_linesize, &info, s->strip_buf + STRIP_HEADER_SIZE); - //av_log(s->avctx, AV_LOG_INFO, "mode %i, %3i, %3i: %18"PRId64" %i B", mode, info.v1_size, info.v4_size, score, best_size); - //av_log(s->avctx, AV_LOG_INFO, "\n"); +/**** + av_log(s->avctx, AV_LOG_INFO, "mode %i, %3i, %3i: %18"PRId64" %i B", mode, info.v1_size, info.v4_size, score, best_size); + av_log(s->avctx, AV_LOG_INFO, "\n"); +****/ #ifdef CINEPAK_REPORT_SERR av_log(s->avctx, AV_LOG_INFO, "mode %i, %3i, %3i: %18"PRId64" %i B\n", mode, v1_size, v4_size, serr, best_size); #endif #ifdef CINEPAKENC_DEBUG - //save MB encoding choices + /* save MB encoding choices */ memcpy(s->best_mb, s->mb, mb_count*sizeof(mb_info)); #endif - //memcpy(strip_temp + STRIP_HEADER_SIZE, strip_temp, best_size); + /* memcpy(strip_temp + STRIP_HEADER_SIZE, strip_temp, best_size); */ write_strip_header(s, y, h, keyframe, s->strip_buf, best_size); } @@ -1117,7 +1155,7 @@ static int rd_strip(CinepakEncContext *s, int y, int h, int keyframe, } #ifdef CINEPAKENC_DEBUG - //gather stats. this will only work properly of MAX_STRIPS == 1 + /* gather stats. this will only work properly of MAX_STRIPS == 1 */ if(best_info.mode == MODE_V1_ONLY) { s->num_v1_mode++; s->num_v1_encs += s->w*h/MB_AREA; @@ -1166,11 +1204,11 @@ static int rd_frame(CinepakEncContext *s, const AVFrame *frame, int64_t best_serr = 0, serr, serr_temp; #endif - int best_nstrips = -1, best_size = -1; // mark as uninitialzed + int best_nstrips = -1, best_size = -1; /* mark as uninitialzed */ if(s->pix_fmt == AV_PIX_FMT_RGB24) { int x; -// build a copy of the given frame in the correct colorspace +/* build a copy of the given frame in the correct colorspace */ for(y = 0; y < s->h; y += 2) { for(x = 0; x < s->w; x += 2) { uint8_t *ir[2]; int32_t r, g, b, rr, gg, bb; @@ -1187,34 +1225,34 @@ static int rd_frame(CinepakEncContext *s, const AVFrame *frame, gg = ir[i2][i1*3+1]; bb = ir[i2][i1*3+2]; r += rr; g += gg; b += bb; -// using fixed point arithmetic for portable repeatability, scaling by 2^23 -// "Y" -// rr = 0.2857*rr + 0.5714*gg + 0.1429*bb; +/* using fixed point arithmetic for portable repeatability, scaling by 2^23 */ +/* "Y" */ +/* rr = 0.2857*rr + 0.5714*gg + 0.1429*bb; */ rr = (2396625*rr + 4793251*gg + 1198732*bb) >> 23; if( rr < 0) rr = 0; else if (rr > 255) rr = 255; scratch_data[0][i1 + i2*scratch_linesize[0]] = rr; } -// let us scale down as late as possible -// r /= 4; g /= 4; b /= 4; -// "U" -// rr = -0.1429*r - 0.2857*g + 0.4286*b; +/* let us scale down as late as possible */ +/* r /= 4; g /= 4; b /= 4; */ +/* "U" */ +/* rr = -0.1429*r - 0.2857*g + 0.4286*b; */ rr = (-299683*r - 599156*g + 898839*b) >> 23; if( rr < -128) rr = -128; else if (rr > 127) rr = 127; - scratch_data[1][0] = rr + 128; // quantize needs unsigned -// "V" -// rr = 0.3571*r - 0.2857*g - 0.0714*b; + scratch_data[1][0] = rr + 128; /* quantize needs unsigned */ +/* "V" */ +/* rr = 0.3571*r - 0.2857*g - 0.0714*b; */ rr = (748893*r - 599156*g - 149737*b) >> 23; if( rr < -128) rr = -128; else if (rr > 127) rr = 127; - scratch_data[2][0] = rr + 128; // quantize needs unsigned + scratch_data[2][0] = rr + 128; /* quantize needs unsigned */ } } } - //would be nice but quite certainly incompatible with vintage players: - // support encoding zero strips (meaning skip the whole frame) + /* would be nice but quite certainly incompatible with vintage players: */ + /* support encoding zero strips (meaning skip the whole frame) */ for(num_strips = s->min_strips; num_strips <= s->max_strips && num_strips <= s->h / MB_SIZE; num_strips++) { score = 0; size = 0; @@ -1225,13 +1263,13 @@ static int rd_frame(CinepakEncContext *s, const AVFrame *frame, for(y = 0, strip = 1; y < s->h; strip++, y = nexty) { int strip_height; - nexty = strip * s->h / num_strips; // <= s->h - //make nexty the next multiple of 4 if not already there + nexty = strip * s->h / num_strips; /* <= s->h */ + /* make nexty the next multiple of 4 if not already there */ if(nexty & 3) nexty += 4 - (nexty & 3); strip_height = nexty - y; - if(strip_height <= 0) { // can this ever happen? + if(strip_height <= 0) { /* can this ever happen? */ av_log(s->avctx, AV_LOG_INFO, "skipping zero height strip %i of %i\n", strip, num_strips); continue; } @@ -1266,8 +1304,10 @@ static int rd_frame(CinepakEncContext *s, const AVFrame *frame, serr += serr_temp; #endif size += temp_size; - //av_log(s->avctx, AV_LOG_INFO, "strip %d, isakeyframe=%d", strip, isakeyframe); - //av_log(s->avctx, AV_LOG_INFO, "\n"); +/**** + av_log(s->avctx, AV_LOG_INFO, "strip %d, isakeyframe=%d", strip, isakeyframe); + av_log(s->avctx, AV_LOG_INFO, "\n"); +****/ } if(best_score == 0 || score < best_score) { @@ -1276,7 +1316,9 @@ static int rd_frame(CinepakEncContext *s, const AVFrame *frame, best_serr = serr; #endif best_size = size + write_cvid_header(s, s->frame_buf, num_strips, size, isakeyframe); - //av_log(s->avctx, AV_LOG_INFO, "best number of strips so far: %2i, %12"PRId64", %i B\n", num_strips, score, best_size); +/**** + av_log(s->avctx, AV_LOG_INFO, "best number of strips so far: %2i, %12"PRId64", %i B\n", num_strips, score, best_size); +****/ #ifdef CINEPAK_REPORT_SERR av_log(s->avctx, AV_LOG_INFO, "best number of strips so far: %2i, %12"PRId64", %i B\n", num_strips, serr, best_size); #endif @@ -1285,23 +1327,25 @@ static int rd_frame(CinepakEncContext *s, const AVFrame *frame, memcpy(buf, s->frame_buf, best_size); best_nstrips = num_strips; } -// avoid trying too many strip numbers without a real reason -// (this makes the processing of the very first frame faster) +/* avoid trying too many strip numbers without a real reason */ +/* (this makes the processing of the very first frame faster) */ if(num_strips - best_nstrips > 4) break; } av_assert0(best_nstrips >= 0 && best_size >= 0); -// let the number of strips slowly adapt to the changes in the contents, -// compared to full bruteforcing every time this will occasionally lead -// to some r/d performance loss but makes encoding up to several times faster +/* + * let the number of strips slowly adapt to the changes in the contents, + * compared to full bruteforcing every time this will occasionally lead + * to some r/d performance loss but makes encoding up to several times faster + */ if(!s->strip_number_delta_range) { - if(best_nstrips == s->max_strips) { // let us try to step up + if(best_nstrips == s->max_strips) { /* let us try to step up */ s->max_strips = best_nstrips + 1; if(s->max_strips >= s->max_max_strips) s->max_strips = s->max_max_strips; - } else { // try to step down + } else { /* try to step down */ s->max_strips = best_nstrips; } s->min_strips = s->max_strips - 1;