| 85 | } |
| 86 | |
| 87 | static int tta_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, |
| 88 | const AVFrame *frame, int *got_packet_ptr) |
| 89 | { |
| 90 | TTAEncContext *s = avctx->priv_data; |
| 91 | PutBitContext pb; |
| 92 | int ret, i, out_bytes, cur_chan, res, samples; |
| 93 | int64_t pkt_size = frame->nb_samples * 2LL * avctx->ch_layout.nb_channels * s->bps; |
| 94 | |
| 95 | pkt_alloc: |
| 96 | cur_chan = 0, res = 0, samples = 0; |
| 97 | if ((ret = ff_alloc_packet(avctx, avpkt, pkt_size)) < 0) |
| 98 | return ret; |
| 99 | init_put_bits(&pb, avpkt->data, avpkt->size); |
| 100 | |
| 101 | // init per channel states |
| 102 | for (i = 0; i < avctx->ch_layout.nb_channels; i++) { |
| 103 | s->ch_ctx[i].predictor = 0; |
| 104 | ff_tta_filter_init(&s->ch_ctx[i].filter, ff_tta_filter_configs[s->bps - 1]); |
| 105 | ff_tta_rice_init(&s->ch_ctx[i].rice, 10, 10); |
| 106 | } |
| 107 | |
| 108 | for (i = 0; i < frame->nb_samples * avctx->ch_layout.nb_channels; i++) { |
| 109 | TTAChannel *c = &s->ch_ctx[cur_chan]; |
| 110 | TTAFilter *filter = &c->filter; |
| 111 | TTARice *rice = &c->rice; |
| 112 | uint32_t k, unary, outval; |
| 113 | int32_t value, temp; |
| 114 | |
| 115 | value = get_sample(frame, samples++, avctx->sample_fmt); |
| 116 | |
| 117 | if (avctx->ch_layout.nb_channels > 1) { |
| 118 | if (cur_chan < avctx->ch_layout.nb_channels - 1) |
| 119 | value = res = get_sample(frame, samples, avctx->sample_fmt) - value; |
| 120 | else |
| 121 | value -= res / 2; |
| 122 | } |
| 123 | |
| 124 | temp = value; |
| 125 | #define PRED(x, k) (int32_t)((((uint64_t)(x) << (k)) - (x)) >> (k)) |
| 126 | switch (s->bps) { |
| 127 | case 1: value -= PRED(c->predictor, 4); break; |
| 128 | case 2: |
| 129 | case 3: value -= PRED(c->predictor, 5); break; |
| 130 | } |
| 131 | c->predictor = temp; |
| 132 | |
| 133 | s->dsp.filter_process(filter->qm, filter->dx, filter->dl, &filter->error, &value, |
| 134 | filter->shift, filter->round); |
| 135 | outval = (value > 0) ? (value << 1) - 1: -value << 1; |
| 136 | |
| 137 | k = rice->k0; |
| 138 | |
| 139 | rice->sum0 += outval - (rice->sum0 >> 4); |
| 140 | if (rice->k0 > 0 && rice->sum0 < ff_tta_shift_16[rice->k0]) |
| 141 | rice->k0--; |
| 142 | else if (rice->sum0 > ff_tta_shift_16[rice->k0 + 1]) |
| 143 | rice->k0++; |
| 144 |
nothing calls this directly
no test coverage detected