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