Browse code

cinepakenc: Drop broken debug code

Diego Biurrun authored on 2017/06/28 07:27:14
Showing 1 changed files
... ...
@@ -119,11 +119,6 @@ typedef struct {
119 119
     mb_info *mb;                                //MB RD state
120 120
     int min_strips;          //the current limit
121 121
     int max_strips;          //the current limit
122
-#ifdef CINEPAKENC_DEBUG
123
-    mb_info *best_mb;                           //TODO: remove. only used for printing stats
124
-    int num_v1_mode, num_v4_mode, num_mc_mode;
125
-    int num_v1_encs, num_v4_encs, num_skips;
126
-#endif
127 122
 // options
128 123
     int max_extra_cb_iterations;
129 124
     int skip_empty_cb;
... ...
@@ -206,11 +201,6 @@ static av_cold int cinepak_encode_init(AVCodecContext *avctx)
206 206
     if (!(s->mb = av_malloc(mb_count*sizeof(mb_info))))
207 207
         goto enomem;
208 208
 
209
-#ifdef CINEPAKENC_DEBUG
210
-    if (!(s->best_mb = av_malloc(mb_count*sizeof(mb_info))))
211
-        goto enomem;
212
-#endif
213
-
214 209
     av_lfg_init(&s->randctx, 1);
215 210
     s->avctx = avctx;
216 211
     s->w = avctx->width;
... ...
@@ -251,10 +241,6 @@ static av_cold int cinepak_encode_init(AVCodecContext *avctx)
251 251
     s->min_strips = s->min_min_strips;
252 252
     s->max_strips = s->max_max_strips;
253 253
 
254
-#ifdef CINEPAKENC_DEBUG
255
-    s->num_v1_mode = s->num_v4_mode = s->num_mc_mode = s->num_v1_encs = s->num_v4_encs = s->num_skips = 0;
256
-#endif
257
-
258 254
     return 0;
259 255
 
260 256
 enomem:
... ...
@@ -268,9 +254,6 @@ enomem:
268 268
     av_freep(&s->strip_buf);
269 269
     av_freep(&s->frame_buf);
270 270
     av_freep(&s->mb);
271
-#ifdef CINEPAKENC_DEBUG
272
-    av_freep(&s->best_mb);
273
-#endif
274 271
 
275 272
     for(x = 0; x < (avctx->pix_fmt == AV_PIX_FMT_RGB24 ? 4 : 3); x++)
276 273
         av_freep(&s->pict_bufs[x]);
... ...
@@ -278,11 +261,7 @@ enomem:
278 278
     return AVERROR(ENOMEM);
279 279
 }
280 280
 
281
-static int64_t calculate_mode_score(CinepakEncContext *s, int h, strip_info *info, int report, int *training_set_v1_shrunk, int *training_set_v4_shrunk
282
-#ifdef CINEPAK_REPORT_SERR
283
-, int64_t *serr
284
-#endif
285
-)
281
+static int64_t calculate_mode_score(CinepakEncContext *s, int h, strip_info *info, int report, int *training_set_v1_shrunk, int *training_set_v4_shrunk)
286 282
 {
287 283
     //score = FF_LAMBDA_SCALE * error + lambda * bits
288 284
     int x;
... ...
@@ -294,12 +273,6 @@ static int64_t calculate_mode_score(CinepakEncContext *s, int h, strip_info *inf
294 294
                    (info->v4_size ? CHUNK_HEADER_SIZE + info->v4_size * entry_size : 0) +
295 295
                    CHUNK_HEADER_SIZE) << 3;
296 296
 
297
-    //av_log(s->avctx, AV_LOG_INFO, "sizes %3i %3i -> %9lli score mb_count %i", info->v1_size, info->v4_size, (long long int)ret, mb_count);
298
-
299
-#ifdef CINEPAK_REPORT_SERR
300
-    *serr = 0;
301
-#endif
302
-
303 297
     switch(info->mode) {
304 298
     case MODE_V1_ONLY:
305 299
         //one byte per MB
... ...
@@ -309,9 +282,6 @@ static int64_t calculate_mode_score(CinepakEncContext *s, int h, strip_info *inf
309 309
         for(x = 0; x < mb_count; x++) {
310 310
             mb = &s->mb[x];
311 311
             ret += FF_LAMBDA_SCALE * mb->v1_error;
312
-#ifdef CINEPAK_REPORT_SERR
313
-            *serr += mb->v1_error;
314
-#endif
315 312
 // this function is never called for report in MODE_V1_ONLY
316 313
 //            if(!report)
317 314
             mb->best_encoding = ENC_V1;
... ...
@@ -331,9 +301,6 @@ static int64_t calculate_mode_score(CinepakEncContext *s, int h, strip_info *inf
331 331
                 else
332 332
                     score1 = s->lambda * 33 + FF_LAMBDA_SCALE * (mberr=mb->v4_error);
333 333
                 ret += score1;
334
-#ifdef CINEPAK_REPORT_SERR
335
-                *serr += mberr;
336
-#endif
337 334
             }
338 335
         } else { // find best mode per block
339 336
             for(x = 0; x < mb_count; x++) {
... ...
@@ -343,15 +310,9 @@ static int64_t calculate_mode_score(CinepakEncContext *s, int h, strip_info *inf
343 343
 
344 344
                 if(score1 <= score2) {
345 345
                     ret += score1;
346
-#ifdef CINEPAK_REPORT_SERR
347
-                    *serr += mb->v1_error;
348
-#endif
349 346
                     mb->best_encoding = ENC_V1;
350 347
                 } else {
351 348
                     ret += score2;
352
-#ifdef CINEPAK_REPORT_SERR
353
-                    *serr += mb->v4_error;
354
-#endif
355 349
                     mb->best_encoding = ENC_V4;
356 350
                 }
357 351
             }
... ...
@@ -369,36 +330,21 @@ static int64_t calculate_mode_score(CinepakEncContext *s, int h, strip_info *inf
369 369
                 score1 = s->lambda * 1  + FF_LAMBDA_SCALE * mb->skip_error;
370 370
                 if(mb->best_encoding == ENC_SKIP) {
371 371
                     ret += score1;
372
-#ifdef CINEPAK_REPORT_SERR
373
-                    *serr += mb->skip_error;
374
-#endif
375 372
                 } else if(mb->best_encoding == ENC_V1) {
376 373
                     if((score2=s->lambda * 10 + FF_LAMBDA_SCALE * mb->v1_error) >= score1) {
377 374
                         mb->best_encoding = ENC_SKIP;
378 375
                         ++v1_shrunk;
379 376
                         ret += score1;
380
-#ifdef CINEPAK_REPORT_SERR
381
-                        *serr += mb->skip_error;
382
-#endif
383 377
                     } else {
384 378
                         ret += score2;
385
-#ifdef CINEPAK_REPORT_SERR
386
-                        *serr += mb->v1_error;
387
-#endif
388 379
                     }
389 380
                 } else {
390 381
                     if((score3=s->lambda * 34 + FF_LAMBDA_SCALE * mb->v4_error) >= score1) {
391 382
                         mb->best_encoding = ENC_SKIP;
392 383
                         ++v4_shrunk;
393 384
                         ret += score1;
394
-#ifdef CINEPAK_REPORT_SERR
395
-                        *serr += mb->skip_error;
396
-#endif
397 385
                     } else {
398 386
                         ret += score3;
399
-#ifdef CINEPAK_REPORT_SERR
400
-                        *serr += mb->v4_error;
401
-#endif
402 387
                     }
403 388
                 }
404 389
             }
... ...
@@ -413,21 +359,12 @@ static int64_t calculate_mode_score(CinepakEncContext *s, int h, strip_info *inf
413 413
 
414 414
                 if(score1 <= score2 && score1 <= score3) {
415 415
                     ret += score1;
416
-#ifdef CINEPAK_REPORT_SERR
417
-                    *serr += mb->skip_error;
418
-#endif
419 416
                     mb->best_encoding = ENC_SKIP;
420 417
                 } else if(score2 <= score3) {
421 418
                     ret += score2;
422
-#ifdef CINEPAK_REPORT_SERR
423
-                    *serr += mb->v1_error;
424
-#endif
425 419
                     mb->best_encoding = ENC_V1;
426 420
                 } else {
427 421
                     ret += score3;
428
-#ifdef CINEPAK_REPORT_SERR
429
-                    *serr += mb->v4_error;
430
-#endif
431 422
                     mb->best_encoding = ENC_V4;
432 423
                 }
433 424
             }
... ...
@@ -808,16 +745,11 @@ static int quantize(CinepakEncContext *s, int h, AVPicture *pict,
808 808
             i += v1mode ? 1 : 4;
809 809
         }
810 810
     }
811
-//    if(i < mbn*(v1mode ? 1 : 4)) {
812
-//        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);
813
-//    }
814 811
 
815 812
     if(i == 0) // empty training set, nothing to do
816 813
         return 0;
817
-    if(i < size) {
818
-        //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);
814
+    if (i < size)
819 815
         size = i;
820
-    }
821 816
 
822 817
     ff_init_elbg(s->codebook_input, entry_size, i, codebook, size, 1, s->codebook_closest, &s->randctx);
823 818
     ff_do_elbg(s->codebook_input, entry_size, i, codebook, size, 1, s->codebook_closest, &s->randctx);
... ...
@@ -864,8 +796,6 @@ static int quantize(CinepakEncContext *s, int h, AVPicture *pict,
864 864
 // check that we did it right in the beginning of the function
865 865
     av_assert0(i >= size); // training set is no smaller than the codebook
866 866
 
867
-    //av_log(s->avctx, AV_LOG_INFO, "isv1 %i size= %i i= %i error %lli\n", v1mode, size, i, (long long int)total_error);
868
-
869 867
     return size;
870 868
 }
871 869
 
... ...
@@ -899,19 +829,11 @@ static void write_strip_header(CinepakEncContext *s, int y, int h, int keyframe,
899 899
 //    AV_WB16(&buf[8], y+h); /* using absolute y values works -- rl */
900 900
     AV_WB16(&buf[8], h); /* using relative values works as well -- rl */
901 901
     AV_WB16(&buf[10], s->w);
902
-    //av_log(s->avctx, AV_LOG_INFO, "write_strip_header() %x keyframe=%d\n", buf[0], keyframe);
903 902
 }
904 903
 
905
-static int rd_strip(CinepakEncContext *s, int y, int h, int keyframe, AVPicture *last_pict, AVPicture *pict, AVPicture *scratch_pict, unsigned char *buf, int64_t *best_score
906
-#ifdef CINEPAK_REPORT_SERR
907
-, int64_t *best_serr
908
-#endif
909
-)
904
+static int rd_strip(CinepakEncContext *s, int y, int h, int keyframe, AVPicture *last_pict, AVPicture *pict, AVPicture *scratch_pict, unsigned char *buf, int64_t *best_score)
910 905
 {
911 906
     int64_t score = 0;
912
-#ifdef CINEPAK_REPORT_SERR
913
-    int64_t serr;
914
-#endif
915 907
     int best_size = 0;
916 908
     strip_info info;
917 909
 // for codebook optimization:
... ...
@@ -961,11 +883,7 @@ static int rd_strip(CinepakEncContext *s, int y, int h, int keyframe, AVPicture
961 961
                 info.mode = mode;
962 962
 // choose the best encoding per block, based on current experience
963 963
                 score = calculate_mode_score(s, h, &info, 0,
964
-                                             &v1shrunk, &v4shrunk
965
-#ifdef CINEPAK_REPORT_SERR
966
-, &serr
967
-#endif
968
-);
964
+                                             &v1shrunk, &v4shrunk);
969 965
 
970 966
                 if(mode != MODE_V1_ONLY){
971 967
                     int extra_iterations_limit = s->max_extra_cb_iterations;
... ...
@@ -973,72 +891,42 @@ static int rd_strip(CinepakEncContext *s, int y, int h, int keyframe, AVPicture
973 973
 // we assume we _may_ come here with more blocks to encode than before
974 974
                     info.v1_size = v1_size;
975 975
                     new_v1_size = quantize(s, h, pict, 1, &info, ENC_V1);
976
-                    if(new_v1_size < info.v1_size){
977
-                        //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);
976
+                    if (new_v1_size < info.v1_size)
978 977
                         info.v1_size = new_v1_size;
979
-                    }
980 978
 // we assume we _may_ come here with more blocks to encode than before
981 979
                     info.v4_size = v4_size;
982 980
                     new_v4_size = quantize(s, h, pict, 0, &info, ENC_V4);
983
-                    if(new_v4_size < info.v4_size) {
984
-                        //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);
981
+                    if (new_v4_size < info.v4_size)
985 982
                         info.v4_size = new_v4_size;
986
-                    }
987 983
 // calculate the resulting score
988 984
 // (do not move blocks to codebook encodings now, as some blocks may have
989 985
 // got bigger errors despite a smaller training set - but we do not
990 986
 // ever grow the training sets back)
991 987
                     for(;;) {
992 988
                         score = calculate_mode_score(s, h, &info, 1,
993
-                                                     &v1shrunk, &v4shrunk
994
-#ifdef CINEPAK_REPORT_SERR
995
-, &serr
996
-#endif
997
-);
989
+                                                     &v1shrunk, &v4shrunk);
998 990
 // do we have a reason to reiterate? if so, have we reached the limit?
999 991
                         if((!v1shrunk && !v4shrunk) || !extra_iterations_limit--) break;
1000 992
 // recompute the codebooks, omitting the extra blocks
1001 993
                         if(v1shrunk) {
1002 994
                             info.v1_size = v1_size;
1003 995
                             new_v1_size = quantize(s, h, pict, 1, &info, ENC_V1);
1004
-                            if(new_v1_size < info.v1_size){
1005
-                                //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);
996
+                            if (new_v1_size < info.v1_size)
1006 997
                                 info.v1_size = new_v1_size;
1007
-                            }
1008 998
                         }
1009 999
                         if(v4shrunk) {
1010 1000
                             info.v4_size = v4_size;
1011 1001
                             new_v4_size = quantize(s, h, pict, 0, &info, ENC_V4);
1012
-                            if(new_v4_size < info.v4_size) {
1013
-                                //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);
1002
+                            if (new_v4_size < info.v4_size)
1014 1003
                                 info.v4_size = new_v4_size;
1015
-                            }
1016 1004
                         }
1017 1005
                     }
1018 1006
                 }
1019 1007
 
1020
-                //av_log(s->avctx, AV_LOG_INFO, "%3i %3i score = %lli\n", v1_size, v4_size, (long long int)score);
1021
-
1022 1008
                 if(best_size == 0 || score < *best_score) {
1023 1009
 
1024 1010
                     *best_score = score;
1025
-#ifdef CINEPAK_REPORT_SERR
1026
-                    *best_serr = serr;
1027
-#endif
1028 1011
                     best_size = encode_mode(s, h, scratch_pict, last_pict, &info, s->strip_buf + STRIP_HEADER_SIZE);
1029
-
1030
-                    //av_log(s->avctx, AV_LOG_INFO, "mode %i, %3i, %3i: %18lli %i B", mode, info.v1_size, info.v4_size, (long long int)score, best_size);
1031
-                    //av_log(s->avctx, AV_LOG_INFO, "\n");
1032
-#ifdef CINEPAK_REPORT_SERR
1033
-                    av_log(s->avctx, AV_LOG_INFO, "mode %i, %3i, %3i: %18lli %i B\n", mode, v1_size, v4_size, (long long int)serr, best_size);
1034
-#endif
1035
-
1036
-#ifdef CINEPAKENC_DEBUG
1037
-                    //save MB encoding choices
1038
-                    memcpy(s->best_mb, s->mb, mb_count*sizeof(mb_info));
1039
-#endif
1040
-
1041
-                    //memcpy(strip_temp + STRIP_HEADER_SIZE, strip_temp, best_size);
1042 1012
                     write_strip_header(s, y, h, keyframe, s->strip_buf, best_size);
1043 1013
 
1044 1014
                 }
... ...
@@ -1046,28 +934,6 @@ static int rd_strip(CinepakEncContext *s, int y, int h, int keyframe, AVPicture
1046 1046
         }
1047 1047
     }
1048 1048
 
1049
-#ifdef CINEPAKENC_DEBUG
1050
-    //gather stats. this will only work properly of MAX_STRIPS == 1
1051
-    if(best_info.mode == MODE_V1_ONLY) {
1052
-        s->num_v1_mode++;
1053
-        s->num_v1_encs += s->w*h/MB_AREA;
1054
-    } else {
1055
-        if(best_info.mode == MODE_V1_V4)
1056
-            s->num_v4_mode++;
1057
-        else
1058
-            s->num_mc_mode++;
1059
-
1060
-        int x;
1061
-        for(x = 0; x < s->w*h/MB_AREA; x++)
1062
-            if(s->best_mb[x].best_encoding == ENC_V1)
1063
-                s->num_v1_encs++;
1064
-            else if(s->best_mb[x].best_encoding == ENC_V4)
1065
-                s->num_v4_encs++;
1066
-            else
1067
-                s->num_skips++;
1068
-    }
1069
-#endif
1070
-
1071 1049
     best_size += STRIP_HEADER_SIZE;
1072 1050
     memcpy(buf, s->strip_buf, best_size);
1073 1051
 
... ...
@@ -1090,10 +956,6 @@ static int rd_frame(CinepakEncContext *s, const AVFrame *frame, int isakeyframe,
1090 1090
     int num_strips, strip, i, y, nexty, size, temp_size, best_size;
1091 1091
     AVPicture last_pict, pict, scratch_pict;
1092 1092
     int64_t best_score = 0, score, score_temp;
1093
-#ifdef CINEPAK_REPORT_SERR
1094
-    int64_t best_serr = 0, serr, serr_temp;
1095
-#endif
1096
-
1097 1093
     int best_nstrips;
1098 1094
 
1099 1095
     if(s->pix_fmt == AV_PIX_FMT_RGB24) {
... ...
@@ -1144,9 +1006,6 @@ static int rd_frame(CinepakEncContext *s, const AVFrame *frame, int isakeyframe,
1144 1144
     for(num_strips = s->min_strips; num_strips <= s->max_strips && num_strips <= s->h / MB_SIZE; num_strips++) {
1145 1145
         score = 0;
1146 1146
         size = 0;
1147
-#ifdef CINEPAK_REPORT_SERR
1148
-        serr = 0;
1149
-#endif
1150 1147
 
1151 1148
         for(y = 0, strip = 1; y < s->h; strip++, y = nexty) {
1152 1149
             int strip_height;
... ...
@@ -1169,32 +1028,16 @@ static int rd_frame(CinepakEncContext *s, const AVFrame *frame, int isakeyframe,
1169 1169
             get_sub_picture(s, 0, y, (AVPicture*)s->last_frame,    &last_pict);
1170 1170
             get_sub_picture(s, 0, y, (AVPicture*)s->scratch_frame, &scratch_pict);
1171 1171
 
1172
-            if((temp_size = rd_strip(s, y, strip_height, isakeyframe, &last_pict, &pict, &scratch_pict, s->frame_buf + size + CVID_HEADER_SIZE, &score_temp
1173
-#ifdef CINEPAK_REPORT_SERR
1174
-, &serr_temp
1175
-#endif
1176
-)) < 0)
1172
+            if((temp_size = rd_strip(s, y, strip_height, isakeyframe, &last_pict, &pict, &scratch_pict, s->frame_buf + size + CVID_HEADER_SIZE, &score_temp)) < 0)
1177 1173
                 return temp_size;
1178 1174
 
1179 1175
             score += score_temp;
1180
-#ifdef CINEPAK_REPORT_SERR
1181
-            serr += serr_temp;
1182
-#endif
1183 1176
             size += temp_size;
1184
-            //av_log(s->avctx, AV_LOG_INFO, "strip %d, isakeyframe=%d", strip, isakeyframe);
1185
-            //av_log(s->avctx, AV_LOG_INFO, "\n");
1186 1177
         }
1187 1178
 
1188 1179
         if(best_score == 0 || score < best_score) {
1189 1180
             best_score = score;
1190
-#ifdef CINEPAK_REPORT_SERR
1191
-            best_serr = serr;
1192
-#endif
1193 1181
             best_size = size + write_cvid_header(s, s->frame_buf, num_strips, size, isakeyframe);
1194
-            //av_log(s->avctx, AV_LOG_INFO, "best number of strips so far: %2i, %12lli, %i B\n", num_strips, (long long int)score, best_size);
1195
-#ifdef CINEPAK_REPORT_SERR
1196
-            av_log(s->avctx, AV_LOG_INFO, "best number of strips so far: %2i, %12lli, %i B\n", num_strips, (long long int)serr, best_size);
1197
-#endif
1198 1182
 
1199 1183
             FFSWAP(AVFrame *, s->best_frame, s->scratch_frame);
1200 1184
             memcpy(buf, s->frame_buf, best_size);
... ...
@@ -1271,18 +1114,10 @@ static av_cold int cinepak_encode_end(AVCodecContext *avctx)
1271 1271
     av_freep(&s->strip_buf);
1272 1272
     av_freep(&s->frame_buf);
1273 1273
     av_freep(&s->mb);
1274
-#ifdef CINEPAKENC_DEBUG
1275
-    av_freep(&s->best_mb);
1276
-#endif
1277 1274
 
1278 1275
     for(x = 0; x < (avctx->pix_fmt == AV_PIX_FMT_RGB24 ? 4 : 3); x++)
1279 1276
         av_freep(&s->pict_bufs[x]);
1280 1277
 
1281
-#ifdef CINEPAKENC_DEBUG
1282
-    av_log(avctx, AV_LOG_INFO, "strip coding stats: %i V1 mode, %i V4 mode, %i MC mode (%i V1 encs, %i V4 encs, %i skips)\n",
1283
-        s->num_v1_mode, s->num_v4_mode, s->num_mc_mode, s->num_v1_encs, s->num_v4_encs, s->num_skips);
1284
-#endif
1285
-
1286 1278
     return 0;
1287 1279
 }
1288 1280