aboutsummaryrefslogtreecommitdiff
path: root/gst-libs/gst/codecparsers/gstvp8rangedecoder.c
blob: 4d381c5a7a49045921d09c6fd9ba04a2b512a248 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * gstvp8rangedecoder.c - VP8 range decoder interface
 *
 * Use of this source code is governed by a BSD-style license
 * that can be found in the LICENSE file in the root of the source
 * tree. An additional intellectual property rights grant can be found
 * in the file PATENTS.  All contributing project authors may
 * be found in the AUTHORS file in the root of the source tree.
 */

#include "gstvp8rangedecoder.h"
#include "dboolhuff.h"

#define BOOL_DECODER_CAST(rd) \
  ((BOOL_DECODER *)(&(rd)->_gst_reserved[0]))

gboolean
gst_vp8_range_decoder_init (GstVp8RangeDecoder * rd, const guchar * buf,
    guint buf_size)
{
  BOOL_DECODER *const bd = BOOL_DECODER_CAST (rd);

  g_return_val_if_fail (sizeof (rd->_gst_reserved) >= sizeof (*bd), FALSE);

  rd->buf = buf;
  rd->buf_size = buf_size;
  return vp8dx_start_decode (bd, buf, buf_size, NULL, NULL) == 0;
}

gint
gst_vp8_range_decoder_read (GstVp8RangeDecoder * rd, guint8 prob)
{
  return vp8dx_decode_bool (BOOL_DECODER_CAST (rd), prob);
}

gint
gst_vp8_range_decoder_read_literal (GstVp8RangeDecoder * rd, gint bits)
{
  return vp8_decode_value (BOOL_DECODER_CAST (rd), bits);
}

guint
gst_vp8_range_decoder_get_pos (GstVp8RangeDecoder * rd)
{
  BOOL_DECODER *const bd = BOOL_DECODER_CAST (rd);

  return (bd->user_buffer - rd->buf) * 8 - (8 + bd->count);
}

void
gst_vp8_range_decoder_get_state (GstVp8RangeDecoder * rd,
    GstVp8RangeDecoderState * state)
{
  BOOL_DECODER *const bd = BOOL_DECODER_CAST (rd);

  if (bd->count < 0)
    vp8dx_bool_decoder_fill (bd);

  state->range = bd->range;
  state->value = (guint8) ((bd->value) >> (VP8_BD_VALUE_SIZE - 8));
  state->count = (8 + bd->count) % 8;
}