CinepakMode mode;
} strip_info;
- typedef struct {
+ typedef struct CinepakEncContext {
+ const AVClass *class;
AVCodecContext *avctx;
unsigned char *pict_bufs[4], *strip_buf, *frame_buf;
AVFrame *last_frame;
#define OFFSET(x) offsetof(CinepakEncContext, x)
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
static const AVOption options[] = {
- { "max_extra_cb_iterations", "Max extra codebook recalculation passes, more is better and slower", OFFSET(max_extra_cb_iterations), AV_OPT_TYPE_INT, { .i64 = 2 }, 0, INT_MAX, VE },
- { "skip_empty_cb", "Avoid wasting bytes, ignore vintage MacOS decoder", OFFSET(skip_empty_cb), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
- { "max_strips", "Limit strips/frame, vintage compatible is 1..3, otherwise the more the better", OFFSET(max_max_strips), AV_OPT_TYPE_INT, { .i64 = 3 }, MIN_STRIPS, MAX_STRIPS, VE },
- { "min_strips", "Enforce min strips/frame, more is worse and faster, must be <= max_strips", OFFSET(min_min_strips), AV_OPT_TYPE_INT, { .i64 = MIN_STRIPS }, MIN_STRIPS, MAX_STRIPS, VE },
- { "strip_number_adaptivity", "How fast the strip number adapts, more is slightly better, much slower", OFFSET(strip_number_delta_range), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, MAX_STRIPS-MIN_STRIPS, VE },
+ { "max_extra_cb_iterations", "Max extra codebook recalculation passes, more is better and slower",
+ OFFSET(max_extra_cb_iterations), AV_OPT_TYPE_INT, { .i64 = 2 }, 0, INT_MAX, VE },
+ { "skip_empty_cb", "Avoid wasting bytes, ignore vintage MacOS decoder",
- OFFSET(skip_empty_cb), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
++ OFFSET(skip_empty_cb), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
+ { "max_strips", "Limit strips/frame, vintage compatible is 1..3, otherwise the more the better",
+ OFFSET(max_max_strips), AV_OPT_TYPE_INT, { .i64 = 3 }, MIN_STRIPS, MAX_STRIPS, VE },
+ { "min_strips", "Enforce min strips/frame, more is worse and faster, must be <= max_strips",
+ OFFSET(min_min_strips), AV_OPT_TYPE_INT, { .i64 = MIN_STRIPS }, MIN_STRIPS, MAX_STRIPS, VE },
+ { "strip_number_adaptivity", "How fast the strip number adapts, more is slightly better, much slower",
+ OFFSET(strip_number_delta_range), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, MAX_STRIPS - MIN_STRIPS, VE },
{ NULL },
};
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 == 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);
+ if (i < size)
size = i;
- }
- ff_init_elbg(s->codebook_input, entry_size, i, codebook, size, 1, s->codebook_closest, &s->randctx);
- ff_do_elbg(s->codebook_input, entry_size, i, codebook, size, 1, s->codebook_closest, &s->randctx);
+ 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
- vq_data[0] = vq_pict_buf;
+ // set up 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
- for(i = j = y = 0; y < h; y += MB_SIZE) {
- for(x = 0; x < s->w; x += MB_SIZE, j++) {
+ 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
+ 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
- if(CERTAIN(encoding) && mb->best_encoding != 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) {
+ 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,
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) {
+ 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) {
+ CinepakMode mode;
- //try all modes
- for(mode = 0; mode < MODE_COUNT; mode++) {
- //don't allow MODE_MC in intra frames
- if(keyframe && mode == MODE_MC)
+ // try all modes
- for (CinepakMode mode = 0; mode < MODE_COUNT; mode++) {
++ for (mode = 0; mode < MODE_COUNT; mode++) {
+ // don't allow MODE_MC in intra frames
+ if (keyframe && mode == MODE_MC)
continue;
- if(mode == MODE_V1_ONLY) {
+ 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
+ if (info.v1_size < v1_size)
+ // too few eligible blocks, no sense in trying bigger sizes
v1enough = 1;
info.v4_size = 0;
s->lambda = frame->quality ? frame->quality - 1 : 2 * FF_LAMBDA_SCALE;
- if ((ret = ff_alloc_packet(pkt, s->frame_buf_size)) < 0)
+ if ((ret = ff_alloc_packet2(avctx, pkt, s->frame_buf_size, 0)) < 0)
return ret;
- ret = rd_frame(s, frame, (s->curframe == 0), pkt->data, s->frame_buf_size);
+ ret = rd_frame(s, frame, (s->curframe == 0), pkt->data, s->frame_buf_size);
pkt->size = ret;
if (s->curframe == 0)
pkt->flags |= AV_PKT_FLAG_KEY;