vp8: fix compilation with built-in libvpx.
[platform/upstream/gstreamer-vaapi.git] / ext / libvpx / gstlibvpx.c
1 /*
2  * gstlibvpx.c - GStreamer/libvpx glue
3  *
4  * Use of this source code is governed by a BSD-style license
5  * that can be found in the LICENSE file in the root of the source
6  * tree. An additional intellectual property rights grant can be found
7  * in the file PATENTS.  All contributing project authors may
8  * be found in the AUTHORS file in the root of the source tree.
9  */
10
11 #include <string.h>
12 #include <assert.h>
13 #include <vp8/common/entropy.h>
14 #include <vp8/common/entropymv.h>
15 #include <vp8/common/default_coef_probs.h>
16 #include <vp8/decoder/dboolhuff.h>
17 #include "gstlibvpx.h"
18
19 #define BOOL_DECODER_CAST(bd) \
20   ((BOOL_DECODER *)(&(bd)->private[1]))
21
22 bool
23 vp8_bool_decoder_init (vp8_bool_decoder * bd, const uint8_t * buf,
24     unsigned int buf_size)
25 {
26   assert ((sizeof (*bd) - sizeof (bd->private[0])) >= sizeof (BOOL_DECODER));
27
28   bd->private[0] = (uintptr_t)buf;
29   return vp8dx_start_decode (BOOL_DECODER_CAST (bd), buf, buf_size,
30               NULL, NULL) == 0;
31 }
32
33 int
34 vp8_bool_decoder_read (vp8_bool_decoder * bd, uint8_t prob)
35 {
36   return vp8dx_decode_bool (BOOL_DECODER_CAST (bd), prob);
37 }
38
39 int
40 vp8_bool_decoder_read_literal (vp8_bool_decoder * bd, int bits)
41 {
42   return vp8_decode_value (BOOL_DECODER_CAST (bd), bits);
43 }
44
45 unsigned int
46 vp8_bool_decoder_get_pos (vp8_bool_decoder * bd_)
47 {
48   BOOL_DECODER *const bd = BOOL_DECODER_CAST (bd_);
49
50   return ((uintptr_t)bd->user_buffer - bd_->private[0]) * 8 - (8 + bd->count);
51 }
52
53 void
54 vp8_bool_decoder_get_state (vp8_bool_decoder * bd_,
55     vp8_bool_decoder_state * state)
56 {
57   BOOL_DECODER *const bd = BOOL_DECODER_CAST (bd_);
58
59   if (bd->count < 0)
60     vp8dx_bool_decoder_fill (bd);
61
62   state->range = bd->range;
63   state->value = (uint8_t) ((bd->value) >> (VP8_BD_VALUE_SIZE - 8));
64   state->count = (8 + bd->count) % 8;
65 }
66
67 void
68 vp8_init_token_update_probs (uint8_t
69     probs[BLOCK_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS][ENTROPY_NODES])
70 {
71   memcpy (probs, vp8_coef_update_probs, sizeof (vp8_coef_update_probs));
72 }
73
74 void
75 vp8_init_default_token_probs (uint8_t
76     probs[BLOCK_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS][ENTROPY_NODES])
77 {
78   memcpy (probs, default_coef_probs, sizeof (default_coef_probs));
79 }
80
81 void
82 vp8_init_mv_update_probs (uint8_t probs[2][MVPcount])
83 {
84   memcpy (probs[0], vp8_mv_update_probs[0].prob,
85       sizeof (vp8_mv_update_probs[0].prob));
86   memcpy (probs[1], vp8_mv_update_probs[1].prob,
87       sizeof (vp8_mv_update_probs[1].prob));
88 }
89
90 void
91 vp8_init_default_mv_probs (uint8_t probs[2][MVPcount])
92 {
93   memcpy (probs[0], vp8_default_mv_context[0].prob,
94       sizeof (vp8_default_mv_context[0].prob));
95   memcpy (probs[1], vp8_default_mv_context[1].prob,
96       sizeof (vp8_default_mv_context[1].prob));
97 }
98
99 void
100 vp8_init_default_intra_mode_probs (uint8_t y_probs[VP8_YMODES-1],
101     uint8_t uv_probs[VP8_UV_MODES-1])
102 {
103   extern const uint8_t vp8_kf_ymode_prob[VP8_YMODES-1];
104   extern const uint8_t vp8_kf_uv_mode_prob[VP8_UV_MODES-1];
105
106   memcpy (y_probs, vp8_kf_ymode_prob, sizeof (vp8_kf_ymode_prob));
107   memcpy (uv_probs, vp8_kf_uv_mode_prob, sizeof (vp8_kf_uv_mode_prob));
108 }
109
110 void
111 vp8_init_default_inter_mode_probs (uint8_t y_probs[VP8_YMODES-1],
112     uint8_t uv_probs[VP8_UV_MODES-1])
113 {
114   extern const uint8_t vp8_ymode_prob[VP8_YMODES-1];
115   extern const uint8_t vp8_uv_mode_prob[VP8_UV_MODES-1];
116
117   memcpy (y_probs, vp8_ymode_prob, sizeof (vp8_ymode_prob));
118   memcpy (uv_probs, vp8_uv_mode_prob, sizeof (vp8_uv_mode_prob));
119 }