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 #ifndef VPX_VP8_DECODER_ONYXD_INT_H_
12 #define VPX_VP8_DECODER_ONYXD_INT_H_
13 
14 #include "vpx_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 
20 #if CONFIG_ERROR_CONCEALMENT
21 #include "ec_types.h"
22 #endif
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 typedef struct {
29   int ithread;
30   void *ptr1;
31   void *ptr2;
32 } DECODETHREAD_DATA;
33 
34 typedef struct {
35   MACROBLOCKD mbd;
36 } MB_ROW_DEC;
37 
38 typedef struct {
39   int enabled;
40   unsigned int count;
41   const unsigned char *ptrs[MAX_PARTITIONS];
42   unsigned int sizes[MAX_PARTITIONS];
43 } FRAGMENT_DATA;
44 
45 #define MAX_FB_MT_DEC 32
46 
47 struct frame_buffers {
48   /*
49    * this struct will be populated with frame buffer management
50    * info in future commits. */
51 
52   /* decoder instances */
53   struct VP8D_COMP *pbi[MAX_FB_MT_DEC];
54 };
55 
56 typedef struct VP8D_COMP {
57   DECLARE_ALIGNED(16, MACROBLOCKD, mb);
58 
59   YV12_BUFFER_CONFIG *dec_fb_ref[NUM_YV12_BUFFERS];
60 
61   DECLARE_ALIGNED(16, VP8_COMMON, common);
62 
63   /* the last partition will be used for the modes/mvs */
64   vp8_reader mbc[MAX_PARTITIONS];
65 
66   VP8D_CONFIG oxcf;
67 
68   FRAGMENT_DATA fragments;
69 
70 #if CONFIG_MULTITHREAD
71   /* variable for threading */
72 
73   vpx_atomic_int b_multithreaded_rd;
74   int max_threads;
75   int current_mb_col_main;
76   unsigned int decoding_thread_count;
77   int allocated_decoding_thread_count;
78 
79   int mt_baseline_filter_level[MAX_MB_SEGMENTS];
80   int sync_range;
81   /* Each row remembers its already decoded column. */
82   vpx_atomic_int *mt_current_mb_col;
83 
84   unsigned char **mt_yabove_row; /* mb_rows x width */
85   unsigned char **mt_uabove_row;
86   unsigned char **mt_vabove_row;
87   unsigned char **mt_yleft_col; /* mb_rows x 16 */
88   unsigned char **mt_uleft_col; /* mb_rows x 8 */
89   unsigned char **mt_vleft_col; /* mb_rows x 8 */
90 
91   MB_ROW_DEC *mb_row_di;
92   DECODETHREAD_DATA *de_thread_data;
93 
94   pthread_t *h_decoding_thread;
95   sem_t *h_event_start_decoding;
96   sem_t h_event_end_decoding;
97 /* end of threading data */
98 #endif
99 
100   int64_t last_time_stamp;
101   int ready_for_new_data;
102 
103   vp8_prob prob_intra;
104   vp8_prob prob_last;
105   vp8_prob prob_gf;
106   vp8_prob prob_skip_false;
107 
108 #if CONFIG_ERROR_CONCEALMENT
109   MB_OVERLAP *overlaps;
110   /* the mb num from which modes and mvs (first partition) are corrupt */
111   unsigned int mvs_corrupt_from_mb;
112 #endif
113   int ec_enabled;
114   int ec_active;
115   int decoded_key_frame;
116   int independent_partitions;
117   int frame_corrupt_residual;
118 
119   vpx_decrypt_cb decrypt_cb;
120   void *decrypt_state;
121 #if CONFIG_MULTITHREAD
122   // Restart threads on next frame if set to 1.
123   // This is set when error happens in multithreaded decoding and all threads
124   // are shut down.
125   int restart_threads;
126 #endif
127 } VP8D_COMP;
128 
129 void vp8cx_init_de_quantizer(VP8D_COMP *pbi);
130 void vp8_mb_init_dequantizer(VP8D_COMP *pbi, MACROBLOCKD *xd);
131 int vp8_decode_frame(VP8D_COMP *pbi);
132 
133 int vp8_create_decoder_instances(struct frame_buffers *fb, VP8D_CONFIG *oxcf);
134 int vp8_remove_decoder_instances(struct frame_buffers *fb);
135 
136 #if CONFIG_DEBUG
137 #define CHECK_MEM_ERROR(lval, expr)                                         \
138   do {                                                                      \
139     (lval) = (expr);                                                        \
140     if (!(lval))                                                            \
141       vpx_internal_error(&pbi->common.error, VPX_CODEC_MEM_ERROR,           \
142                          "Failed to allocate " #lval " at %s:%d", __FILE__, \
143                          __LINE__);                                         \
144   } while (0)
145 #else
146 #define CHECK_MEM_ERROR(lval, expr)                               \
147   do {                                                            \
148     (lval) = (expr);                                              \
149     if (!(lval))                                                  \
150       vpx_internal_error(&pbi->common.error, VPX_CODEC_MEM_ERROR, \
151                          "Failed to allocate " #lval);            \
152   } while (0)
153 #endif
154 
155 #ifdef __cplusplus
156 }  // extern "C"
157 #endif
158 
159 #endif  // VPX_VP8_DECODER_ONYXD_INT_H_
160