Imported Upstream version 6.1
[platform/upstream/ffmpeg.git] / libavcodec / vp9shared.h
1 /*
2  * VP9 compatible video decoder
3  *
4  * Copyright (C) 2013 Ronald S. Bultje <rsbultje gmail com>
5  * Copyright (C) 2013 Clément Bœsch <u pkh me>
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23
24 #ifndef AVCODEC_VP9SHARED_H
25 #define AVCODEC_VP9SHARED_H
26
27 #include <stddef.h>
28 #include <stdint.h>
29
30 #include "libavutil/mem_internal.h"
31
32 #include "vp9.h"
33 #include "threadframe.h"
34
35 enum BlockPartition {
36     PARTITION_NONE,    // [ ] <-.
37     PARTITION_H,       // [-]   |
38     PARTITION_V,       // [|]   |
39     PARTITION_SPLIT,   // [+] --'
40 };
41
42 enum InterPredMode {
43     NEARESTMV = 10,
44     NEARMV    = 11,
45     ZEROMV    = 12,
46     NEWMV     = 13,
47 };
48
49 enum CompPredMode {
50     PRED_SINGLEREF,
51     PRED_COMPREF,
52     PRED_SWITCHABLE,
53 };
54
55 typedef struct VP9mv {
56     DECLARE_ALIGNED(4, int16_t, x);
57     int16_t y;
58 } VP9mv;
59
60 typedef struct VP9mvrefPair {
61     VP9mv mv[2];
62     int8_t ref[2];
63 } VP9mvrefPair;
64
65 typedef struct VP9Frame {
66     ThreadFrame tf;
67     AVBufferRef *extradata;
68     uint8_t *segmentation_map;
69     VP9mvrefPair *mv;
70     int uses_2pass;
71
72     void *hwaccel_picture_private; ///< RefStruct reference
73 } VP9Frame;
74
75 enum BlockLevel {
76     BL_64X64,
77     BL_32X32,
78     BL_16X16,
79     BL_8X8,
80 };
81
82 enum BlockSize {
83     BS_64x64,
84     BS_64x32,
85     BS_32x64,
86     BS_32x32,
87     BS_32x16,
88     BS_16x32,
89     BS_16x16,
90     BS_16x8,
91     BS_8x16,
92     BS_8x8,
93     BS_8x4,
94     BS_4x8,
95     BS_4x4,
96     N_BS_SIZES,
97 };
98
99 typedef struct VP9BitstreamHeader {
100     // bitstream header
101     uint8_t profile;
102     uint8_t bpp;
103     uint8_t keyframe;
104     uint8_t invisible;
105     uint8_t errorres;
106     uint8_t intraonly;
107     uint8_t resetctx;
108     uint8_t refreshrefmask;
109     uint8_t highprecisionmvs;
110     enum FilterMode filtermode;
111     uint8_t allowcompinter;
112     uint8_t refreshctx;
113     uint8_t parallelmode;
114     uint8_t framectxid;
115     uint8_t use_last_frame_mvs;
116     uint8_t refidx[3];
117     uint8_t signbias[3];
118     uint8_t fixcompref;
119     uint8_t varcompref[2];
120     struct {
121         uint8_t level;
122         int8_t sharpness;
123     } filter;
124     struct {
125         uint8_t enabled;
126         uint8_t updated;
127         int8_t mode[2];
128         int8_t ref[4];
129     } lf_delta;
130     uint8_t yac_qi;
131     int8_t ydc_qdelta, uvdc_qdelta, uvac_qdelta;
132     uint8_t lossless;
133 #define MAX_SEGMENT 8
134     struct {
135         uint8_t enabled;
136         uint8_t temporal;
137         uint8_t absolute_vals;
138         uint8_t update_map;
139         uint8_t prob[7];
140         uint8_t pred_prob[3];
141         struct {
142             uint8_t q_enabled;
143             uint8_t lf_enabled;
144             uint8_t ref_enabled;
145             uint8_t skip_enabled;
146             uint8_t ref_val;
147             int16_t q_val;
148             int8_t lf_val;
149             int16_t qmul[2][2];
150             uint8_t lflvl[4][2];
151         } feat[MAX_SEGMENT];
152     } segmentation;
153     enum TxfmMode txfmmode;
154     enum CompPredMode comppredmode;
155     struct {
156         unsigned log2_tile_cols, log2_tile_rows;
157         unsigned tile_cols, tile_rows;
158     } tiling;
159
160     int uncompressed_header_size;
161     int compressed_header_size;
162 } VP9BitstreamHeader;
163
164 typedef struct VP9SharedContext {
165     VP9BitstreamHeader h;
166
167     ThreadFrame refs[8];
168 #define CUR_FRAME 0
169 #define REF_FRAME_MVPAIR 1
170 #define REF_FRAME_SEGMAP 2
171     VP9Frame frames[3];
172 } VP9SharedContext;
173
174 #endif /* AVCODEC_VP9SHARED_H */