Merge "Adding error-concealment to the decoder."
[profile/ivi/libvpx.git] / vp8 / decoder / onyxd_int.h
1 /*
2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
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
12 #ifndef __INC_VP8D_INT_H
13 #define __INC_VP8D_INT_H
14 #include "vpx_ports/config.h"
15 #include "vp8/common/onyxd.h"
16 #include "treereader.h"
17 #include "vp8/common/onyxc_int.h"
18 #include "vp8/common/threading.h"
19 #include "dequantize.h"
20 #if CONFIG_ERROR_CONCEALMENT
21 #include "ec_types.h"
22 #endif
23
24 typedef struct
25 {
26     int ithread;
27     void *ptr1;
28     void *ptr2;
29 } DECODETHREAD_DATA;
30
31 typedef struct
32 {
33     MACROBLOCKD  mbd;
34     int mb_row;
35     int current_mb_col;
36     short *coef_ptr;
37 } MB_ROW_DEC;
38
39 typedef struct
40 {
41     INT64 time_stamp;
42     int size;
43 } DATARATE;
44
45 typedef struct
46 {
47     INT16         min_val;
48     INT16         Length;
49     UINT8 Probs[12];
50 } TOKENEXTRABITS;
51
52 typedef struct
53 {
54     int const *scan;
55     UINT8 const *ptr_block2leftabove;
56     vp8_tree_index const *vp8_coef_tree_ptr;
57     TOKENEXTRABITS const *teb_base_ptr;
58     unsigned char *norm_ptr;
59     UINT8 *ptr_coef_bands_x;
60
61     ENTROPY_CONTEXT_PLANES *A;
62     ENTROPY_CONTEXT_PLANES *L;
63
64     INT16 *qcoeff_start_ptr;
65     BOOL_DECODER *current_bc;
66
67     vp8_prob const *coef_probs[4];
68
69     UINT8 eob[25];
70
71 } DETOK;
72
73 typedef struct VP8Decompressor
74 {
75     DECLARE_ALIGNED(16, MACROBLOCKD, mb);
76
77     DECLARE_ALIGNED(16, VP8_COMMON, common);
78
79     vp8_reader bc, bc2;
80
81     VP8D_CONFIG oxcf;
82
83
84     const unsigned char *Source;
85     unsigned int   source_sz;
86
87 #if CONFIG_MULTITHREAD
88     /* variable for threading */
89
90     volatile int b_multithreaded_rd;
91     int max_threads;
92     int current_mb_col_main;
93     int decoding_thread_count;
94     int allocated_decoding_thread_count;
95
96     int mt_baseline_filter_level[MAX_MB_SEGMENTS];
97     int sync_range;
98     int *mt_current_mb_col;                  /* Each row remembers its already decoded column. */
99
100     unsigned char **mt_yabove_row;           /* mb_rows x width */
101     unsigned char **mt_uabove_row;
102     unsigned char **mt_vabove_row;
103     unsigned char **mt_yleft_col;            /* mb_rows x 16 */
104     unsigned char **mt_uleft_col;            /* mb_rows x 8 */
105     unsigned char **mt_vleft_col;            /* mb_rows x 8 */
106
107     MB_ROW_DEC           *mb_row_di;
108     DECODETHREAD_DATA    *de_thread_data;
109
110     pthread_t           *h_decoding_thread;
111     sem_t               *h_event_start_decoding;
112     sem_t                h_event_end_decoding;
113     /* end of threading data */
114 #endif
115
116     vp8_reader *mbc;
117     INT64 last_time_stamp;
118     int   ready_for_new_data;
119
120     DATARATE dr[16];
121
122     DETOK detoken;
123
124 #if CONFIG_RUNTIME_CPU_DETECT
125     vp8_dequant_rtcd_vtable_t        dequant;
126 #endif
127
128
129     vp8_prob prob_intra;
130     vp8_prob prob_last;
131     vp8_prob prob_gf;
132     vp8_prob prob_skip_false;
133
134 #if CONFIG_ERROR_CONCEALMENT
135     MB_OVERLAP *overlaps;
136     /* the mb num from which modes and mvs (first partition) are corrupt */
137     unsigned int mvs_corrupt_from_mb;
138 #endif
139     int ec_enabled;
140
141 } VP8D_COMP;
142
143 int vp8_decode_frame(VP8D_COMP *cpi);
144 void vp8_dmachine_specific_config(VP8D_COMP *pbi);
145
146
147 #if CONFIG_DEBUG
148 #define CHECK_MEM_ERROR(lval,expr) do {\
149         lval = (expr); \
150         if(!lval) \
151             vpx_internal_error(&pbi->common.error, VPX_CODEC_MEM_ERROR,\
152                                "Failed to allocate "#lval" at %s:%d", \
153                                __FILE__,__LINE__);\
154     } while(0)
155 #else
156 #define CHECK_MEM_ERROR(lval,expr) do {\
157         lval = (expr); \
158         if(!lval) \
159             vpx_internal_error(&pbi->common.error, VPX_CODEC_MEM_ERROR,\
160                                "Failed to allocate "#lval);\
161     } while(0)
162 #endif
163
164 #endif