[FFmpeg-devel] [PATCH 1/2] avcodec: add HCOM decoder
James Almer
jamrial at gmail.com
Wed Jan 2 23:12:08 EET 2019
On 1/2/2019 3:53 PM, Paul B Mahol wrote:
> +static int hcom_decode(AVCodecContext *avctx, void *data,
> + int *got_frame, AVPacket *pkt)
> +{
> + HCOMContext *s = avctx->priv_data;
> + AVFrame *frame = data;
> + GetByteContext gb;
> + uint32_t current;
> + int ret, n = 0;
> +
> + if (pkt->size > INT16_MAX)
> + return AVERROR_INVALIDDATA;
> +
> + frame->nb_samples = pkt->size * 8;
> + if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
> + return ret;
> +
> + bytestream2_init(&gb, pkt->data, pkt->size);
> + while (bytestream2_get_bytes_left(&gb) >= 4) {
> + int bits = 32;
> +
> + current = bytestream2_get_be32(&gb);
> +
> + while (bits-- > 0) {
> +
> + if (current & 0x80000000) {
> + s->dict_entry = s->dict[s->dict_entry].r;
> + } else {
> + s->dict_entry = s->dict[s->dict_entry].l;
> + }
> +
> + current = current << 1;
This sounds like get_bits is a better fit than bytestream2 for this decoder.
> + if (s->dict[s->dict_entry].l < 0) {
> + int16_t datum;
> +
> + datum = s->dict[s->dict_entry].r;
> +
> + if (!s->delta_compression)
> + s->sample = 0;
> + s->sample = (s->sample + datum) & 0xFF;
> +
> + frame->data[0][n++] = s->sample;
> +
> + s->dict_entry = 0;
> + }
> + }
> + }
> +
> + frame->nb_samples = n;
> +
> + *got_frame = 1;
> +
> + return pkt->size;
> +}
More information about the ffmpeg-devel
mailing list