Mercurial > libavcodec.hg
annotate vc9.c @ 2463:9baa47d8297b libavcodec
check norm6 vlc validity as there are some bit sequences which dont corespond to any codeword, the other vlc tables all seem to be huffman tables though
author | michael |
---|---|
date | Tue, 25 Jan 2005 01:29:10 +0000 |
parents | 5fd4de95731f |
children | ab390f13c7f5 |
rev | line source |
---|---|
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1 /* |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
2 * VC-9 and WMV3 decoder |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
3 * Copyright (c) 2005 Anonymous |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
4 * Copyright (c) 2005 Alex Beregszaszi |
2462 | 5 * Copyright (c) 2005 Michael Niedermayer |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
6 * |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
7 * This library is free software; you can redistribute it and/or |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
9 * License as published by the Free Software Foundation; either |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
10 * version 2 of the License, or (at your option) any later version. |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
11 * |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
12 * This library is distributed in the hope that it will be useful, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
16 * |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
18 * License along with this library; if not, write to the Free Software |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
20 * |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
21 */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
22 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
23 /** |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
24 * @file vc9.c |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
25 * VC-9 and WMV3 decoder |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
26 * |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
27 * TODO: Norm-6 bitplane imode, most AP stuff, optimize, all of MB layer :) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
28 * TODO: use MPV_ !! |
2462 | 29 * TODO: export decode012 in bitstream.h ? |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
30 */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
31 #include "common.h" |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
32 #include "dsputil.h" |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
33 #include "avcodec.h" |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
34 #include "mpegvideo.h" |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
35 #include "vc9data.h" |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
36 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
37 /* Some inhibiting stuff */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
38 #define HAS_ADVANCED_PROFILE 1 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
39 #define TRACE 1 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
40 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
41 #if TRACE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
42 # define INIT_VLC(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
43 codes, codes_wrap, codes_size, use_static) \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
44 if (init_vlc(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
45 codes, codes_wrap, codes_size, use_static) < 0) \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
46 { \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
47 av_log(v->avctx, AV_LOG_ERROR, "Error for " # vlc " (%i)\n", i); \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
48 return -1; \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
49 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
50 #else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
51 # define INIT_VLC(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
52 codes, codes_wrap, codes_size, use_static) \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
53 init_vlc(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
54 codes, codes_wrap, codes_size, use_static) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
55 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
56 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
57 #define PROFILE_SIMPLE 0 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
58 #define PROFILE_MAIN 1 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
59 #define PROFILE_ADVANCED 3 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
60 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
61 #define QUANT_FRAME_IMPLICIT 0 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
62 #define QUANT_FRAME_EXPLICIT 1 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
63 #define QUANT_NON_UNIFORM 2 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
64 #define QUANT_UNIFORM 3 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
65 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
66 /* Where quant can be changed */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
67 #define DQPROFILE_FOUR_EDGES 0 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
68 #define DQPROFILE_DOUBLE_EDGES 1 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
69 #define DQPROFILE_SINGLE_EDGE 2 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
70 #define DQPROFILE_ALL_MBS 3 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
71 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
72 /* Which edge is quantized with ALTPQUANT */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
73 #define DQSINGLE_BEDGE_LEFT 0 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
74 #define DQSINGLE_BEDGE_TOP 1 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
75 #define DQSINGLE_BEDGE_RIGHT 2 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
76 #define DQSINGLE_BEDGE_BOTTOM 3 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
77 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
78 /* Which pair of edges is quantized with ALTPQUANT */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
79 #define DQDOUBLE_BEDGE_TOPLEFT 0 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
80 #define DQDOUBLE_BEDGE_TOPRIGHT 1 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
81 #define DQDOUBLE_BEDGE_BOTTOMRIGHT 2 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
82 #define DQDOUBLE_BEDGE_BOTTOMLEFT 3 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
83 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
84 /* MV P modes */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
85 #define MV_PMODE_1MV_HPEL_BILIN 0 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
86 #define MV_PMODE_1MV 1 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
87 #define MV_PMODE_1MV_HPEL 2 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
88 #define MV_PMODE_MIXED_MV 3 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
89 #define MV_PMODE_INTENSITY_COMP 4 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
90 |
2462 | 91 #define BMV_TYPE_BACKWARD 0 |
92 #define BMV_TYPE_FORWARD 1 | |
93 #define BMV_TYPE_INTERPOLATED 3 | |
94 | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
95 /* MV P mode - the 5th element is only used for mode 1 */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
96 static const uint8_t mv_pmode_table[2][5] = { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
97 { MV_PMODE_1MV_HPEL_BILIN, MV_PMODE_1MV, MV_PMODE_1MV_HPEL, MV_PMODE_MIXED_MV, MV_PMODE_INTENSITY_COMP }, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
98 { MV_PMODE_1MV, MV_PMODE_MIXED_MV, MV_PMODE_1MV_HPEL, MV_PMODE_1MV_HPEL_BILIN, MV_PMODE_INTENSITY_COMP } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
99 }; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
100 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
101 /* One more frame type */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
102 #define BI_TYPE 7 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
103 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
104 /* FIXME Worse than ugly */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
105 static const int fps_nr[5] = { 24, 25, 30, 50, 60 }, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
106 fps_dr[2] = { 1000, 1001 }; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
107 static const uint8_t pquant_table[3][32] = { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
108 { /* Implicit quantizer */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
109 0, 1, 2, 3, 4, 5, 6, 7, 8, 6, 7, 8, 9, 10, 11, 12, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
110 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 29, 31 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
111 }, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
112 { /* Explicit quantizer, pquantizer uniform */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
113 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
114 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
115 }, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
116 { /* Explicit quantizer, pquantizer non-uniform */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
117 0, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
118 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 31 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
119 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
120 }; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
121 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
122 // FIXME move this into the context |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
123 #define VC9_BFRACTION_VLC_BITS 7 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
124 static VLC vc9_bfraction_vlc; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
125 #define VC9_IMODE_VLC_BITS 4 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
126 static VLC vc9_imode_vlc; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
127 #define VC9_NORM2_VLC_BITS 3 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
128 static VLC vc9_norm2_vlc; |
2460
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
129 #define VC9_NORM6_VLC_BITS 9 |
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
130 static VLC vc9_norm6_vlc; |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
131 /* Could be optimized, one table only needs 8 bits */ |
2462 | 132 #define VC9_TTMB_VLC_BITS 9 //12 |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
133 static VLC vc9_ttmb_vlc[3]; |
2462 | 134 #define VC9_MV_DIFF_VLC_BITS 9 //15 |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
135 static VLC vc9_mv_diff_vlc[4]; |
2462 | 136 #define VC9_CBPCY_I_VLC_BITS 9 //13 |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
137 static VLC vc9_cbpcy_i_vlc; |
2462 | 138 #define VC9_CBPCY_P_VLC_BITS 9 //14 |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
139 static VLC vc9_cbpcy_p_vlc[4]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
140 #define VC9_4MV_BLOCK_PATTERN_VLC_BITS 6 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
141 static VLC vc9_4mv_block_pattern_vlc[4]; |
2458
915094e3da5d
dont use several 100 mb memory for a tiny 120 element table
michael
parents:
2453
diff
changeset
|
142 #define VC9_LUMA_DC_VLC_BITS 9 |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
143 static VLC vc9_luma_dc_vlc[2]; |
2462 | 144 #define VC9_CHROMA_DC_VLC_BITS 9 |
145 static VLC vc9_chroma_dc_vlc[2]; | |
146 | |
147 //We mainly need data and is_raw, so this struct could be avoided | |
148 //to save a level of indirection; feel free to modify | |
149 typedef struct BitPlane { | |
150 uint8_t *data; | |
151 int width, stride; | |
152 int height; | |
153 uint8_t is_raw; | |
154 } BitPlane; | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
155 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
156 typedef struct VC9Context{ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
157 /* No MpegEnc context, might be good to use it */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
158 GetBitContext gb; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
159 AVCodecContext *avctx; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
160 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
161 /***************************/ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
162 /* Sequence Header */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
163 /***************************/ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
164 /* Simple/Main Profile */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
165 int res_sm; //reserved, 2b |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
166 int res_x8; //reserved |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
167 int multires; //frame-level RESPIC syntax element present |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
168 int res_fasttx; //always 1 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
169 int res_transtab; //always 0 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
170 int syncmarker; //Sync markers presents |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
171 int rangered; //RANGEREDFRM (range reduction) syntax element present |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
172 int res_rtm_flag; //reserved, set to 1 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
173 int reserved; //duh |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
174 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
175 #if HAS_ADVANCED_PROFILE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
176 /* Advanced Profile */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
177 int level; //3 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
178 int chromaformat; //2 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
179 int postprocflag; //frame-based processing use |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
180 int broadcast; //TFF/RFF present |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
181 int interlace; //Progressive/interlaced (RPTFTM syntax element) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
182 int tfcntrflag; //TFCNTR present |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
183 int panscanflag; //NUMPANSCANWIN, TOPLEFT{X,Y}, BOTRIGHT{X,Y} presents |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
184 int extended_dmv; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
185 int color_prim; //8 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
186 int transfer_char; //8 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
187 int matrix_coef; //8 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
188 int hrd_param_flag; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
189 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
190 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
191 /* All Profiles */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
192 /* TODO: move all int to flags */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
193 int profile; //2 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
194 int frmrtq_postproc; //3 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
195 int bitrtq_postproc; //5 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
196 int loopfilter; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
197 int fastuvmc; //Rounding of qpel vector to hpel ? (not in Simple) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
198 int extended_mv; //Ext MV in P/B (not in Simple) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
199 int dquant; //Q varies with MBs, 2bits (not in Simple) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
200 int vstransform; //variable-size transform46 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
201 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
202 int overlap; //overlapped transforms in use |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
203 int quantizer_mode; //2, quantizer mode used for sequence, see QUANT_* |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
204 int finterpflag; //INTERPFRM present |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
205 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
206 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
207 /*****************************/ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
208 /* Frame decoding */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
209 /*****************************/ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
210 /* All profiles */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
211 uint8_t mv_mode, mv_mode2; /* MV coding mode */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
212 uint8_t pict_type; /* Picture type, mapped on MPEG types */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
213 uint8_t pq, altpq; /* Quantizers */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
214 uint8_t dquantfrm, dqprofile, dqsbedge, dqbilevel; /* pquant parameters */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
215 int width_mb, height_mb; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
216 int tile; /* 3x2 if (width_mb%3) else 2x3 */ |
2462 | 217 VLC *luma_ac_vlc, *chroma_ac_vlc, |
218 *luma_dc_vlc, *chroma_dc_vlc; /* transac/dcfrm bits are indexes */ | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
219 uint8_t ttmbf, ttfrm; /* Transform type */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
220 uint8_t lumscale, lumshift; /* Luma compensation parameters */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
221 int16_t bfraction; /* Relative position % anchors=> how to scale MVs */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
222 uint8_t halfpq; /* Uniform quant over image and qp+.5 */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
223 uint8_t respic; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
224 /* Ranges: |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
225 * 0 -> [-64n 63.f] x [-32, 31.f] |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
226 * 1 -> [-128, 127.f] x [-64, 63.f] |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
227 * 2 -> [-512, 511.f] x [-128, 127.f] |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
228 * 3 -> [-1024, 1023.f] x [-256, 255.f] |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
229 */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
230 uint8_t mvrange; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
231 uint8_t pquantizer; |
2462 | 232 uint8_t *previous_line_cbpcy; /* To use for predicted CBPCY */ |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
233 VLC *cbpcy_vlc /* Current CBPCY VLC table */, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
234 *mv_diff_vlc /* Current MV Diff VLC table */, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
235 *ttmb_vlc /* Current MB Transform Type VLC table */; |
2462 | 236 BitPlane mv_type_mb_plane; /* bitplane for mv_type == (4MV) */ |
237 BitPlane skip_mb_plane, /* bitplane for skipped MBs */ | |
238 direct_mb_plane; /* bitplane for "direct" MBs */ | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
239 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
240 /* S/M only ? */ |
2462 | 241 uint8_t rangeredfrm; /* out_sample = CLIP((in_sample-128)*2+128) */ |
242 uint8_t interpfrm; | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
243 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
244 #if HAS_ADVANCED_PROFILE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
245 /* Advanced */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
246 uint8_t fcm; //0->Progressive, 2->Frame-Interlace, 3->Field-Interlace |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
247 uint8_t numpanscanwin; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
248 uint8_t tfcntr; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
249 uint8_t rptfrm, tff, rff; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
250 uint8_t topleftx; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
251 uint8_t toplefty; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
252 uint8_t bottomrightx; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
253 uint8_t bottomrighty; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
254 uint8_t rndctrl; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
255 uint8_t uvsamp; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
256 uint8_t postproc; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
257 int hrd_num_leaky_buckets; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
258 uint8_t bit_rate_exponent; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
259 uint8_t buffer_size_exponent; |
2462 | 260 BitPlane ac_pred_plane; //AC prediction flags bitplane |
261 BitPlane over_flags_plane; //Overflags bitplane | |
262 uint8_t condover; | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
263 uint16_t *hrd_rate, *hrd_buffer; |
2462 | 264 VLC *luma_ac2_vlc, *chroma_ac2_vlc; |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
265 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
266 } VC9Context; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
267 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
268 /* FIXME Slow and ugly */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
269 static int get_prefix(GetBitContext *gb, int stop, int len) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
270 { |
2462 | 271 #if 1 |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
272 int i = 0, tmp = !stop; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
273 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
274 while (i != len && tmp != stop) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
275 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
276 tmp = get_bits(gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
277 i++; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
278 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
279 return i; |
2462 | 280 #else |
281 unsigned int buf; | |
282 int log; | |
283 | |
284 OPEN_READER(re, gb); | |
285 UPDATE_CACHE(re, gb); | |
286 buf=GET_CACHE(re, gb); //Still not sure | |
287 if (stop) buf = ~buf; | |
288 | |
289 log= av_log2(-buf); //FIXME: -? | |
290 if (log < limit){ | |
291 LAST_SKIP_BITS(re, gb, log+1); | |
292 CLOSE_READER(re, gb); | |
293 return log; | |
294 } | |
295 | |
296 LAST_SKIP_BITS(re, gb, limit); | |
297 CLOSE_READER(re, gb); | |
298 return limit; | |
299 #endif | |
300 } | |
301 | |
302 static int decode012(GetBitContext *gb) | |
303 { | |
304 int n; | |
305 n = get_bits1(gb); | |
306 if (n == 0) | |
307 return 0; | |
308 else | |
309 return get_bits1(gb) + 1; | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
310 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
311 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
312 static int init_common(VC9Context *v) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
313 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
314 static int done = 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
315 int i; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
316 |
2462 | 317 /* Set the bit planes */ |
318 /* FIXME memset better ? (16bytes) */ | |
319 v->mv_type_mb_plane = (struct BitPlane) { NULL, 0, 0, 0 }; | |
320 v->direct_mb_plane = (struct BitPlane) { NULL, 0, 0, 0 }; | |
321 v->skip_mb_plane = (struct BitPlane) { NULL, 0, 0, 0 }; | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
322 #if HAS_ADVANCED_PROFILE |
2462 | 323 v->ac_pred_plane = v->over_flags_plane = (struct BitPlane) { NULL, 0, 0, 0 }; |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
324 v->hrd_rate = v->hrd_buffer = NULL; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
325 #endif |
2462 | 326 |
327 /* VLC tables */ | |
2460
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
328 #if 0 // spec -> actual tables converter |
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
329 for(i=0; i<64; i++){ |
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
330 int code= (vc9_norm6_spec[i][1] << vc9_norm6_spec[i][4]) + vc9_norm6_spec[i][3]; |
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
331 av_log(NULL, AV_LOG_DEBUG, "0x%03X, ", code); |
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
332 if(i%16==15) av_log(NULL, AV_LOG_DEBUG, "\n"); |
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
333 } |
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
334 for(i=0; i<64; i++){ |
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
335 int code= vc9_norm6_spec[i][2] + vc9_norm6_spec[i][4]; |
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
336 av_log(NULL, AV_LOG_DEBUG, "%2d, ", code); |
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
337 if(i%16==15) av_log(NULL, AV_LOG_DEBUG, "\n"); |
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
338 } |
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
339 #endif |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
340 if(!done) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
341 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
342 done = 1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
343 INIT_VLC(&vc9_bfraction_vlc, VC9_BFRACTION_VLC_BITS, 23, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
344 vc9_bfraction_bits, 1, 1, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
345 vc9_bfraction_codes, 1, 1, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
346 INIT_VLC(&vc9_norm2_vlc, VC9_NORM2_VLC_BITS, 4, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
347 vc9_norm2_bits, 1, 1, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
348 vc9_norm2_codes, 1, 1, 1); |
2460
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
349 INIT_VLC(&vc9_norm6_vlc, VC9_NORM6_VLC_BITS, 64, |
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
350 vc9_norm6_bits, 1, 1, |
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
351 vc9_norm6_codes, 2, 2, 1); |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
352 INIT_VLC(&vc9_cbpcy_i_vlc, VC9_CBPCY_I_VLC_BITS, 64, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
353 vc9_cbpcy_i_bits, 1, 1, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
354 vc9_cbpcy_i_codes, 2, 2, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
355 INIT_VLC(&vc9_imode_vlc, VC9_IMODE_VLC_BITS, 7, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
356 vc9_imode_bits, 1, 1, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
357 vc9_imode_codes, 1, 1, 1); |
2462 | 358 for (i=0; i<2; i++) |
359 { | |
360 INIT_VLC(&vc9_luma_dc_vlc[i], VC9_LUMA_DC_VLC_BITS, 26, | |
361 vc9_luma_dc_bits[i], 1, 1, | |
362 vc9_luma_dc_codes[i], 4, 4, 1); | |
363 INIT_VLC(&vc9_chroma_dc_vlc[i], VC9_CHROMA_DC_VLC_BITS, 26, | |
364 vc9_chroma_dc_bits[i], 1, 1, | |
365 vc9_chroma_dc_codes[i], 4, 4, 1); | |
366 } | |
367 for (i=0; i<3; i++) | |
368 { | |
369 INIT_VLC(&vc9_ttmb_vlc[i], VC9_TTMB_VLC_BITS, 16, | |
370 vc9_ttmb_bits[i], 1, 1, | |
371 vc9_ttmb_codes[i], 2, 2, 1); | |
372 } | |
373 for(i=0; i<4; i++) | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
374 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
375 INIT_VLC(&vc9_4mv_block_pattern_vlc[i], VC9_4MV_BLOCK_PATTERN_VLC_BITS, 16, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
376 vc9_4mv_block_pattern_bits[i], 1, 1, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
377 vc9_4mv_block_pattern_codes[i], 1, 1, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
378 INIT_VLC(&vc9_cbpcy_p_vlc[i], VC9_CBPCY_P_VLC_BITS, 64, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
379 vc9_cbpcy_p_bits[i], 1, 1, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
380 vc9_cbpcy_p_codes[i], 2, 2, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
381 INIT_VLC(&vc9_mv_diff_vlc[i], VC9_MV_DIFF_VLC_BITS, 73, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
382 vc9_mv_diff_bits[i], 1, 1, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
383 vc9_mv_diff_codes[i], 2, 2, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
384 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
385 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
386 |
2462 | 387 /* Other defaults */ |
388 v->pq = -1; | |
389 v->mvrange = 0; /* 7.1.1.18, p80 */ | |
390 | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
391 return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
392 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
393 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
394 #if HAS_ADVANCED_PROFILE |
2462 | 395 /* 6.2.1, p32 */ |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
396 static int decode_hrd(VC9Context *v, GetBitContext *gb) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
397 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
398 int i, num; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
399 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
400 num = get_bits(gb, 5); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
401 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
402 if (v->hrd_rate || num != v->hrd_num_leaky_buckets) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
403 { |
2458
915094e3da5d
dont use several 100 mb memory for a tiny 120 element table
michael
parents:
2453
diff
changeset
|
404 av_freep(&v->hrd_rate); |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
405 } |
2462 | 406 if (!v->hrd_rate) v->hrd_rate = av_malloc(num*sizeof(uint16_t)); |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
407 if (!v->hrd_rate) return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
408 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
409 if (v->hrd_buffer || num != v->hrd_num_leaky_buckets) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
410 { |
2458
915094e3da5d
dont use several 100 mb memory for a tiny 120 element table
michael
parents:
2453
diff
changeset
|
411 av_freep(&v->hrd_buffer); |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
412 } |
2462 | 413 if (!v->hrd_buffer) v->hrd_buffer = av_malloc(num*sizeof(uint16_t)); |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
414 if (!v->hrd_buffer) return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
415 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
416 v->hrd_num_leaky_buckets = num; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
417 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
418 //exponent in base-2 for rate |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
419 v->bit_rate_exponent = get_bits(gb, 4); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
420 //exponent in base-2 for buffer_size |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
421 v->buffer_size_exponent = get_bits(gb, 4); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
422 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
423 for (i=0; i<num; i++) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
424 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
425 //mantissae, ordered (if not, use a function ? |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
426 v->hrd_rate[i] = get_bits(gb, 16); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
427 if (i && v->hrd_rate[i-1]>=v->hrd_rate[i]) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
428 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
429 av_log(v, AV_LOG_ERROR, "HDR Rates aren't strictly increasing:" |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
430 "%i vs %i\n", v->hrd_rate[i-1], v->hrd_rate[i]); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
431 return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
432 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
433 v->hrd_buffer[i] = get_bits(gb, 16); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
434 if (i && v->hrd_buffer[i-1]<v->hrd_buffer[i]) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
435 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
436 av_log(v, AV_LOG_ERROR, "HDR Buffers aren't decreasing:" |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
437 "%i vs %i\n", v->hrd_buffer[i-1], v->hrd_buffer[i]); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
438 return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
439 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
440 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
441 return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
442 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
443 |
2462 | 444 /* Table 2, p18 */ |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
445 static int decode_advanced_sequence_header(AVCodecContext *avctx, GetBitContext *gb) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
446 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
447 VC9Context *v = avctx->priv_data; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
448 int nr, dr, aspect_ratio; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
449 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
450 v->postprocflag = get_bits(gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
451 v->broadcast = get_bits(gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
452 v->interlace = get_bits(gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
453 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
454 v->tfcntrflag = get_bits(gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
455 v->finterpflag = get_bits(gb, 1); //common |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
456 v->panscanflag = get_bits(gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
457 v->reserved = get_bits(gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
458 if (v->reserved) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
459 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
460 av_log(avctx, AV_LOG_ERROR, "RESERVED should be 0 (is %i)\n", |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
461 v->reserved); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
462 return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
463 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
464 if (v->extended_mv) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
465 v->extended_dmv = get_bits(gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
466 |
2462 | 467 /* 6.1.7, p21 */ |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
468 if (get_bits(gb, 1) /* pic_size_flag */) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
469 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
470 avctx->coded_width = get_bits(gb, 12); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
471 avctx->coded_height = get_bits(gb, 12); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
472 if ( get_bits(gb, 1) /* disp_size_flag */) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
473 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
474 avctx->width = get_bits(gb, 14); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
475 avctx->height = get_bits(gb, 14); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
476 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
477 |
2462 | 478 /* 6.1.7.4, p22 */ |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
479 if ( get_bits(gb, 1) /* aspect_ratio_flag */) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
480 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
481 aspect_ratio = get_bits(gb, 4); //SAR |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
482 if (aspect_ratio == 0x0F) //FF_ASPECT_EXTENDED |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
483 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
484 avctx->sample_aspect_ratio.num = get_bits(gb, 8); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
485 avctx->sample_aspect_ratio.den = get_bits(gb, 8); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
486 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
487 else if (aspect_ratio == 0x0E) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
488 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
489 av_log(avctx, AV_LOG_DEBUG, "Reserved AR found\n"); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
490 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
491 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
492 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
493 avctx->sample_aspect_ratio = vc9_pixel_aspect[aspect_ratio]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
494 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
495 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
496 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
497 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
498 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
499 avctx->coded_width = avctx->width; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
500 avctx->coded_height = avctx->height; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
501 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
502 |
2462 | 503 /* 6.1.8, p23 */ |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
504 if ( get_bits(gb, 1) /* framerateflag */) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
505 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
506 if ( get_bits(gb, 1) /* framerateind */) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
507 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
508 nr = get_bits(gb, 8); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
509 dr = get_bits(gb, 4); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
510 if (nr<1) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
511 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
512 av_log(avctx, AV_LOG_ERROR, "0 is forbidden for FRAMERATENR\n"); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
513 return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
514 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
515 if (nr>5) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
516 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
517 av_log(avctx, AV_LOG_ERROR, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
518 "Reserved FRAMERATENR %i not handled\n", nr); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
519 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
520 if (dr<1) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
521 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
522 av_log(avctx, AV_LOG_ERROR, "0 is forbidden for FRAMERATEDR\n"); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
523 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
524 if (dr>2) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
525 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
526 av_log(avctx, AV_LOG_ERROR, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
527 "Reserved FRAMERATEDR %i not handled\n", dr); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
528 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
529 avctx->frame_rate_base = fps_nr[dr]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
530 avctx->frame_rate = fps_nr[nr]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
531 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
532 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
533 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
534 nr = get_bits(gb, 16); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
535 // 0.03125->2048Hz / 0.03125Hz |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
536 avctx->frame_rate = 1000000; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
537 avctx->frame_rate_base = 31250*(1+nr); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
538 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
539 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
540 |
2462 | 541 /* 6.1.9, p25 */ |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
542 if ( get_bits(gb, 1) /* color_format_flag */) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
543 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
544 //Chromacity coordinates of color primaries |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
545 //like ITU-R BT.709-2, BT.470-2, ... |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
546 v->color_prim = get_bits(gb, 8); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
547 if (v->color_prim<1) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
548 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
549 av_log(avctx, AV_LOG_ERROR, "0 for COLOR_PRIM is reserved\n"); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
550 return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
551 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
552 if (v->color_prim == 3 || v->color_prim>6) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
553 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
554 av_log(avctx, AV_LOG_DEBUG, "Reserved COLOR_PRIM %i found\n", |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
555 v->color_prim); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
556 return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
557 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
558 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
559 //Opto-electronic transfer characteristics |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
560 v->transfer_char = get_bits(gb, 8); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
561 if (v->transfer_char == 3 || v->transfer_char>8) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
562 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
563 av_log(avctx, AV_LOG_DEBUG, "Reserved TRANSFERT_CHAR %i found\n", |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
564 v->color_prim); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
565 return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
566 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
567 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
568 //Matrix coefficient for primariev->YCbCr |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
569 v->matrix_coef = get_bits(gb, 8); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
570 if (v->matrix_coef < 1) return -1; //forbidden |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
571 if ((v->matrix_coef>3 && v->matrix_coef<6) || v->matrix_coef>7) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
572 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
573 av_log(avctx, AV_LOG_DEBUG, "Reserved MATRIX_COEF %i found\n", |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
574 v->color_prim); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
575 return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
576 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
577 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
578 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
579 //Hypothetical reference decoder indicator flag |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
580 v->hrd_param_flag = get_bits(gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
581 if (v->hrd_param_flag) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
582 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
583 if (decode_hrd(v, gb) < 0) return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
584 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
585 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
586 av_log(avctx, AV_LOG_DEBUG, "Advanced profile not supported yet\n"); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
587 return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
588 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
589 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
590 |
2462 | 591 /* Figure 7-8, p16-17 */ |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
592 static int decode_sequence_header(AVCodecContext *avctx, GetBitContext *gb) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
593 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
594 VC9Context *v = avctx->priv_data; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
595 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
596 v->profile = get_bits(gb, 2); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
597 av_log(avctx, AV_LOG_DEBUG, "Profile: %i\n", v->profile); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
598 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
599 #if HAS_ADVANCED_PROFILE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
600 if (v->profile > PROFILE_MAIN) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
601 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
602 v->level = get_bits(gb, 3); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
603 v->chromaformat = get_bits(gb, 2); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
604 if (v->chromaformat != 1) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
605 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
606 av_log(avctx, AV_LOG_ERROR, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
607 "Only 4:2:0 chroma format supported\n"); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
608 return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
609 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
610 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
611 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
612 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
613 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
614 v->res_sm = get_bits(gb, 2); //reserved |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
615 if (v->res_sm) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
616 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
617 av_log(avctx, AV_LOG_ERROR, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
618 "Reserved RES_SM=%i is forbidden\n", v->res_sm); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
619 //return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
620 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
621 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
622 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
623 // (fps-2)/4 (->30) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
624 v->frmrtq_postproc = get_bits(gb, 3); //common |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
625 // (bitrate-32kbps)/64kbps |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
626 v->bitrtq_postproc = get_bits(gb, 5); //common |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
627 v->loopfilter = get_bits(gb, 1); //common |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
628 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
629 #if HAS_ADVANCED_PROFILE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
630 if (v->profile <= PROFILE_MAIN) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
631 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
632 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
633 v->res_x8 = get_bits(gb, 1); //reserved |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
634 if (v->res_x8) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
635 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
636 av_log(avctx, AV_LOG_ERROR, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
637 "1 for reserved RES_X8 is forbidden\n"); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
638 return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
639 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
640 v->multires = get_bits(gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
641 v->res_fasttx = get_bits(gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
642 if (!v->res_fasttx) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
643 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
644 av_log(avctx, AV_LOG_ERROR, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
645 "0 for reserved RES_FASTTX is forbidden\n"); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
646 //return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
647 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
648 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
649 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
650 v->fastuvmc = get_bits(gb, 1); //common |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
651 if (!v->profile && !v->fastuvmc) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
652 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
653 av_log(avctx, AV_LOG_ERROR, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
654 "FASTUVMC unavailable in Simple Profile\n"); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
655 return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
656 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
657 v->extended_mv = get_bits(gb, 1); //common |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
658 if (!v->profile && v->extended_mv) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
659 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
660 av_log(avctx, AV_LOG_ERROR, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
661 "Extended MVs unavailable in Simple Profile\n"); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
662 return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
663 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
664 v->dquant = get_bits(gb, 2); //common |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
665 v->vstransform = get_bits(gb, 1); //common |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
666 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
667 #if HAS_ADVANCED_PROFILE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
668 if (v->profile <= PROFILE_MAIN) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
669 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
670 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
671 v->res_transtab = get_bits(gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
672 if (v->res_transtab) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
673 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
674 av_log(avctx, AV_LOG_ERROR, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
675 "1 for reserved RES_TRANSTAB is forbidden\n"); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
676 return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
677 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
678 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
679 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
680 v->overlap = get_bits(gb, 1); //common |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
681 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
682 #if HAS_ADVANCED_PROFILE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
683 if (v->profile <= PROFILE_MAIN) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
684 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
685 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
686 v->syncmarker = get_bits(gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
687 v->rangered = get_bits(gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
688 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
689 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
690 avctx->max_b_frames = get_bits(gb, 3); //common |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
691 v->quantizer_mode = get_bits(gb, 2); //common |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
692 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
693 #if HAS_ADVANCED_PROFILE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
694 if (v->profile <= PROFILE_MAIN) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
695 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
696 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
697 v->finterpflag = get_bits(gb, 1); //common |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
698 v->res_rtm_flag = get_bits(gb, 1); //reserved |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
699 if (!v->res_rtm_flag) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
700 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
701 av_log(avctx, AV_LOG_ERROR, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
702 "0 for reserved RES_RTM_FLAG is forbidden\n"); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
703 //return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
704 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
705 #if TRACE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
706 av_log(avctx, AV_LOG_INFO, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
707 "Profile %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n" |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
708 "LoopFilter=%i, MultiRes=%i, FastUVMV=%i, Extended MV=%i\n" |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
709 "Rangered=%i, VSTransform=%i, Overlap=%i, SyncMarker=%i\n" |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
710 "DQuant=%i, Quantizer mode=%i, Max B frames=%i\n", |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
711 v->profile, v->frmrtq_postproc, v->bitrtq_postproc, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
712 v->loopfilter, v->multires, v->fastuvmc, v->extended_mv, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
713 v->rangered, v->vstransform, v->overlap, v->syncmarker, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
714 v->dquant, v->quantizer_mode, avctx->max_b_frames |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
715 ); |
2462 | 716 return 0; |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
717 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
718 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
719 #if HAS_ADVANCED_PROFILE |
2462 | 720 else return decode_advanced_sequence_header(avctx, gb); |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
721 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
722 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
723 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
724 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
725 #if HAS_ADVANCED_PROFILE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
726 /*****************************************************************************/ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
727 /* Entry point decoding (Advanced Profile) */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
728 /*****************************************************************************/ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
729 static int advanced_entry_point_process(AVCodecContext *avctx, GetBitContext *gb) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
730 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
731 VC9Context *v = avctx->priv_data; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
732 int range_mapy_flag, range_mapuv_flag, i; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
733 if (v->profile != PROFILE_ADVANCED) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
734 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
735 av_log(avctx, AV_LOG_ERROR, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
736 "Entry point are only defined in Advanced Profile!\n"); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
737 return -1; //Only for advanced profile! |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
738 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
739 if (v->hrd_param_flag) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
740 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
741 //Update buffer fullness |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
742 av_log(avctx, AV_LOG_DEBUG, "Buffer fullness update\n"); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
743 for (i=0; i<v->hrd_num_leaky_buckets; i++) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
744 skip_bits(gb, 8); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
745 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
746 if ((range_mapy_flag = get_bits(gb, 1))) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
747 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
748 //RANGE_MAPY |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
749 av_log(avctx, AV_LOG_DEBUG, "RANGE_MAPY\n"); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
750 skip_bits(gb, 3); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
751 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
752 if ((range_mapuv_flag = get_bits(gb, 1))) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
753 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
754 //RANGE_MAPUV |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
755 av_log(avctx, AV_LOG_DEBUG, "RANGE_MAPUV\n"); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
756 skip_bits(gb, 3); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
757 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
758 if (v->panscanflag) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
759 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
760 //NUMPANSCANWIN |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
761 v->numpanscanwin = get_bits(gb, 3); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
762 av_log(avctx, AV_LOG_DEBUG, "NUMPANSCANWIN: %u\n", v->numpanscanwin); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
763 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
764 return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
765 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
766 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
767 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
768 /******************************************************************************/ |
2462 | 769 /* Bitplane decoding: 8.7, p56 */ |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
770 /******************************************************************************/ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
771 #define IMODE_RAW 0 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
772 #define IMODE_NORM2 1 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
773 #define IMODE_DIFF2 2 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
774 #define IMODE_NORM6 3 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
775 #define IMODE_DIFF6 4 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
776 #define IMODE_ROWSKIP 5 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
777 #define IMODE_COLSKIP 6 |
2462 | 778 int alloc_bitplane(BitPlane *bp, int width, int height) |
779 { | |
780 if (!bp || bp->width<0 || bp->height<0) return -1; | |
781 bp->data = (uint8_t*)av_malloc(width*height); | |
782 if (!bp->data) return -1; | |
783 bp->width = bp->stride = width; //FIXME Needed for aligned data ? | |
784 bp->height = height; | |
785 return 0; | |
786 } | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
787 |
2459 | 788 static void decode_rowskip(uint8_t* plane, int width, int height, int stride, VC9Context *v){ |
789 int x, y; | |
790 | |
791 for (y=0; y<height; y++){ | |
792 if (!get_bits(&v->gb, 1)) //rowskip | |
793 memset(plane, 0, width); | |
794 else | |
795 for (x=0; x<width; x++) | |
796 plane[x] = get_bits(&v->gb, 1); | |
797 plane += stride; | |
798 } | |
799 } | |
800 | |
2460
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
801 //FIXME optimize |
2459 | 802 static void decode_colskip(uint8_t* plane, int width, int height, int stride, VC9Context *v){ |
803 int x, y; | |
804 | |
805 for (x=0; x<width; x++){ | |
806 if (!get_bits(&v->gb, 1)) //colskip | |
807 for (y=0; y<height; y++) | |
808 plane[y*stride] = 0; | |
809 else | |
810 for (y=0; y<height; y++) | |
811 plane[y*stride] = get_bits(&v->gb, 1); | |
812 plane ++; | |
813 } | |
814 } | |
815 | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
816 //FIXME optimize |
2462 | 817 //FIXME is this supposed to set elements to 0/FF or 0/1? 0/x!=0, not used for |
818 // prediction | |
819 //FIXME Use BitPlane struct or return if table is raw (no bits read here but | |
820 // later on) | |
821 static int bitplane_decoding(BitPlane *bp, VC9Context *v) | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
822 { |
2462 | 823 int imode, x, y, code, use_vertical_tile, tile_w, tile_h; |
824 uint8_t invert, *planep = bp->data; | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
825 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
826 invert = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
827 imode = get_vlc2(&v->gb, vc9_imode_vlc.table, VC9_IMODE_VLC_BITS, 2); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
828 |
2462 | 829 bp->is_raw = 0; |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
830 switch (imode) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
831 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
832 case IMODE_RAW: |
2462 | 833 //Data is actually read in the MB layer (same for all tests == "raw") |
834 bp->is_raw = 1; //invert ignored | |
835 return invert; | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
836 case IMODE_DIFF2: |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
837 case IMODE_NORM2: |
2462 | 838 if ((bp->height*bp->width) & 1) *(++planep) = get_bits(&v->gb, 1); |
839 for(x=0; x<(bp->height*bp->width)>>1; x++){ | |
2459 | 840 code = get_vlc2(&v->gb, vc9_norm2_vlc.table, VC9_NORM2_VLC_BITS, 2); |
841 *(++planep) = code&1; //lsb => left | |
2462 | 842 *(++planep) = code&2; //msb => right - bitplane => only !0 matters |
2459 | 843 //FIXME width->stride |
844 } | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
845 break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
846 case IMODE_DIFF6: |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
847 case IMODE_NORM6: |
2462 | 848 use_vertical_tile= bp->height%3==0 && bp->width%3!=0; |
2460
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
849 tile_w= use_vertical_tile ? 2 : 3; |
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
850 tile_h= use_vertical_tile ? 3 : 2; |
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
851 |
2462 | 852 for(y= bp->height%tile_h; y< bp->height; y+=tile_h){ |
853 for(x= bp->width%tile_w; x< bp->width; x+=tile_w){ | |
2460
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
854 code = get_vlc2(&v->gb, vc9_norm6_vlc.table, VC9_NORM6_VLC_BITS, 2); |
2463
9baa47d8297b
check norm6 vlc validity as there are some bit sequences which dont corespond to any codeword, the other vlc tables all seem to be huffman tables though
michael
parents:
2462
diff
changeset
|
855 if(code<0){ |
9baa47d8297b
check norm6 vlc validity as there are some bit sequences which dont corespond to any codeword, the other vlc tables all seem to be huffman tables though
michael
parents:
2462
diff
changeset
|
856 av_log(v->avctx, AV_LOG_DEBUG, "inavlid NORM-6 VLC\n"); |
9baa47d8297b
check norm6 vlc validity as there are some bit sequences which dont corespond to any codeword, the other vlc tables all seem to be huffman tables though
michael
parents:
2462
diff
changeset
|
857 return -1; |
9baa47d8297b
check norm6 vlc validity as there are some bit sequences which dont corespond to any codeword, the other vlc tables all seem to be huffman tables though
michael
parents:
2462
diff
changeset
|
858 } |
2460
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
859 //FIXME following is a pure guess and probably wrong |
2462 | 860 //FIXME A bitplane (0 | !0), so could the shifts be avoided ? |
861 planep[x + 0*bp->stride]= (code>>0)&1; | |
862 planep[x + 1 + 0*bp->stride]= (code>>1)&1; | |
2460
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
863 if(use_vertical_tile){ |
2462 | 864 planep[x + 0 + 1*bp->stride]= (code>>2)&1; |
865 planep[x + 1 + 1*bp->stride]= (code>>3)&1; | |
866 planep[x + 0 + 2*bp->stride]= (code>>4)&1; | |
867 planep[x + 1 + 2*bp->stride]= (code>>5)&1; | |
2460
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
868 }else{ |
2462 | 869 planep[x + 2 + 0*bp->stride]= (code>>2)&1; |
870 planep[x + 0 + 1*bp->stride]= (code>>3)&1; | |
871 planep[x + 1 + 1*bp->stride]= (code>>4)&1; | |
872 planep[x + 2 + 1*bp->stride]= (code>>5)&1; | |
2460
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
873 } |
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
874 } |
2459 | 875 } |
2460
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
876 |
2462 | 877 x= bp->width % tile_w; |
878 decode_colskip(bp->data , x, bp->height , bp->stride, v); | |
879 decode_rowskip(bp->data+x, bp->width - x, bp->height % tile_h, bp->stride, v); | |
2460
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
880 |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
881 break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
882 case IMODE_ROWSKIP: |
2462 | 883 decode_rowskip(bp->data, bp->width, bp->height, bp->stride, v); |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
884 break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
885 case IMODE_COLSKIP: //Teh ugly |
2462 | 886 decode_colskip(bp->data, bp->width, bp->height, bp->stride, v); |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
887 break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
888 default: break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
889 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
890 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
891 /* Applying diff operator */ |
2459 | 892 if (imode == IMODE_DIFF2 || imode == IMODE_DIFF6) |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
893 { |
2462 | 894 planep = bp->data; |
2459 | 895 planep[0] ^= invert; |
2462 | 896 for (x=1; x<bp->width; x++) |
2459 | 897 planep[x] ^= planep[x-1]; |
2462 | 898 for (y=1; y<bp->height; y++) |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
899 { |
2462 | 900 planep += bp->stride; |
901 planep[0] ^= planep[-bp->stride]; | |
902 for (x=1; x<bp->width; x++) | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
903 { |
2462 | 904 if (planep[x-1] != planep[x-bp->stride]) planep[x] ^= invert; |
905 else planep[x] ^= planep[x-1]; | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
906 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
907 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
908 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
909 else if (invert) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
910 { |
2462 | 911 planep = bp->data; |
912 for (x=0; x<bp->width*bp->height; x++) planep[x] = !planep[x]; //FIXME stride | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
913 } |
2462 | 914 return (imode<<1) + invert; |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
915 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
916 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
917 /*****************************************************************************/ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
918 /* VOP Dquant decoding */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
919 /*****************************************************************************/ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
920 static int vop_dquant_decoding(VC9Context *v) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
921 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
922 int pqdiff; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
923 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
924 //variable size |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
925 if (v->dquant == 2) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
926 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
927 pqdiff = get_bits(&v->gb, 3); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
928 if (pqdiff == 7) v->altpq = get_bits(&v->gb, 5); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
929 else v->altpq = v->pq + pqdiff + 1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
930 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
931 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
932 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
933 v->dquantfrm = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
934 if ( v->dquantfrm ) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
935 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
936 v->dqprofile = get_bits(&v->gb, 2); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
937 switch (v->dqprofile) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
938 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
939 case DQPROFILE_SINGLE_EDGE: |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
940 case DQPROFILE_DOUBLE_EDGES: |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
941 v->dqsbedge = get_bits(&v->gb, 2); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
942 break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
943 case DQPROFILE_ALL_MBS: |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
944 v->dqbilevel = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
945 default: break; //Forbidden ? |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
946 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
947 if (!v->dqbilevel || v->dqprofile != DQPROFILE_ALL_MBS) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
948 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
949 pqdiff = get_bits(&v->gb, 3); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
950 if (pqdiff == 7) v->altpq = get_bits(&v->gb, 5); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
951 else v->altpq = v->pq + pqdiff + 1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
952 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
953 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
954 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
955 return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
956 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
957 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
958 /*****************************************************************************/ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
959 /* All Profiles picture header decoding specific functions */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
960 /* Only pro/epilog differs between Simple/Main and Advanced => check caller */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
961 /*****************************************************************************/ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
962 static int decode_bi_picture_header(VC9Context *v) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
963 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
964 /* Very particular case: |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
965 - for S/M Profiles, decode_b_picture_header reads BF, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
966 bfraction then determine if this is a BI frame, calling |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
967 this function afterwards |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
968 - for A Profile, PTYPE already tells so and we can go |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
969 directly there |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
970 */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
971 int pqindex; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
972 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
973 /* Read the quantization stuff */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
974 pqindex = get_bits(&v->gb, 5); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
975 if (v->quantizer_mode == QUANT_FRAME_IMPLICIT) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
976 v->pq = pquant_table[0][pqindex]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
977 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
978 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
979 v->pq = pquant_table[v->quantizer_mode-1][pqindex]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
980 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
981 if (pqindex < 9) v->halfpq = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
982 if (v->quantizer_mode == QUANT_FRAME_EXPLICIT) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
983 v->pquantizer = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
984 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
985 /* Read the MV type/mode */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
986 if (v->extended_mv == 1) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
987 v->mvrange = get_prefix(&v->gb, 0, 3); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
988 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
989 /* FIXME: what table are used in that case ? */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
990 v->mv_diff_vlc = &vc9_mv_diff_vlc[0]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
991 v->cbpcy_vlc = &vc9_cbpcy_i_vlc; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
992 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
993 av_log(v->avctx, AV_LOG_DEBUG, "B frame, QP=%i\n", v->pq); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
994 av_log(v->avctx, AV_LOG_ERROR, "BI_TYPE not supported yet\n"); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
995 /* Epilog should be done in caller */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
996 return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
997 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
998 |
2462 | 999 /* Tables 11+12, p62-65 */ |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1000 static int decode_b_picture_header(VC9Context *v) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1001 { |
2462 | 1002 int pqindex, status; |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1003 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1004 /* Prolog common to all frametypes should be done in caller */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1005 if (v->profile == PROFILE_SIMPLE) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1006 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1007 av_log(v, AV_LOG_ERROR, "Found a B frame while in Simple Profile!\n"); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1008 return FRAME_SKIPED; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1009 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1010 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1011 v->bfraction = vc9_bfraction_lut[get_vlc2(&v->gb, vc9_bfraction_vlc.table, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1012 VC9_BFRACTION_VLC_BITS, 2)]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1013 if (v->bfraction < -1) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1014 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1015 av_log(v, AV_LOG_ERROR, "Invalid BFRaction\n"); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1016 return FRAME_SKIPED; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1017 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1018 else if (!v->bfraction) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1019 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1020 /* We actually have a BI frame */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1021 return decode_bi_picture_header(v); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1022 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1023 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1024 /* Read the quantization stuff */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1025 pqindex = get_bits(&v->gb, 5); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1026 if (v->quantizer_mode == QUANT_FRAME_IMPLICIT) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1027 v->pq = pquant_table[0][pqindex]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1028 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1029 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1030 v->pq = pquant_table[v->quantizer_mode-1][pqindex]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1031 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1032 if (pqindex < 9) v->halfpq = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1033 if (v->quantizer_mode == QUANT_FRAME_EXPLICIT) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1034 v->pquantizer = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1035 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1036 /* Read the MV type/mode */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1037 if (v->extended_mv == 1) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1038 v->mvrange = get_prefix(&v->gb, 0, 3); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1039 v->mv_mode = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1040 if (v->pq < 13) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1041 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1042 if (!v->mv_mode) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1043 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1044 v->mv_mode = get_bits(&v->gb, 2); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1045 if (v->mv_mode) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1046 av_log(v, AV_LOG_ERROR, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1047 "mv_mode for lowquant B frame was %i\n", v->mv_mode); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1048 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1049 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1050 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1051 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1052 if (!v->mv_mode) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1053 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1054 if (get_bits(&v->gb, 1)) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1055 av_log(v, AV_LOG_ERROR, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1056 "mv_mode for highquant B frame was %i\n", v->mv_mode); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1057 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1058 v->mv_mode = 1-v->mv_mode; //To match (pq < 13) mapping |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1059 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1060 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1061 if (v->mv_mode == MV_PMODE_MIXED_MV) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1062 { |
2462 | 1063 status = bitplane_decoding(&v->mv_type_mb_plane, v); |
1064 if (status < 0) | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1065 return -1; |
2462 | 1066 #if TRACE |
1067 av_log(v->avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: " | |
1068 "Imode: %i, Invert: %i\n", status>>1, status&1); | |
1069 #endif | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1070 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1071 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1072 //bitplane |
2462 | 1073 status = bitplane_decoding(&v->direct_mb_plane, v); |
1074 if (status < 0) return -1; | |
1075 #if TRACE | |
1076 av_log(v->avctx, AV_LOG_DEBUG, "MB Direct plane encoding: " | |
1077 "Imode: %i, Invert: %i\n", status>>1, status&1); | |
1078 #endif | |
1079 | |
1080 bitplane_decoding(&v->skip_mb_plane, v); | |
1081 if (status < 0) return -1; | |
1082 #if TRACE | |
1083 av_log(v->avctx, AV_LOG_DEBUG, "Skip MB plane encoding: " | |
1084 "Imode: %i, Invert: %i\n", status>>1, status&1); | |
1085 #endif | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1086 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1087 /* FIXME: what is actually chosen for B frames ? */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1088 v->mv_diff_vlc = &vc9_mv_diff_vlc[get_bits(&v->gb, 2)]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1089 v->cbpcy_vlc = &vc9_cbpcy_p_vlc[get_bits(&v->gb, 2)]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1090 if (v->dquant) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1091 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1092 vop_dquant_decoding(v); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1093 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1094 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1095 if (v->vstransform) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1096 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1097 v->ttmbf = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1098 if (v->ttmbf) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1099 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1100 v->ttfrm = get_bits(&v->gb, 2); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1101 av_log(v, AV_LOG_INFO, "Transform used: %ix%i\n", |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1102 (v->ttfrm & 2) ? 4 : 8, (v->ttfrm & 1) ? 4 : 8); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1103 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1104 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1105 /* Epilog should be done in caller */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1106 return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1107 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1108 |
2462 | 1109 /* Tables 5+7, p53-54 and 55-57 */ |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1110 static int decode_i_picture_header(VC9Context *v) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1111 { |
2462 | 1112 int pqindex, status = 0, ac_pred; |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1113 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1114 /* Prolog common to all frametypes should be done in caller */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1115 //BF = Buffer Fullness |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1116 if (v->profile <= PROFILE_MAIN && get_bits(&v->gb, 7)) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1117 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1118 av_log(v, AV_LOG_DEBUG, "I BufferFullness not 0\n"); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1119 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1120 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1121 /* Quantizer stuff */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1122 pqindex = get_bits(&v->gb, 5); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1123 if (v->quantizer_mode == QUANT_FRAME_IMPLICIT) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1124 v->pq = pquant_table[0][pqindex]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1125 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1126 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1127 v->pq = pquant_table[v->quantizer_mode-1][pqindex]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1128 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1129 if (pqindex < 9) v->halfpq = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1130 if (v->quantizer_mode == QUANT_FRAME_EXPLICIT) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1131 v->pquantizer = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1132 av_log(v->avctx, AV_LOG_DEBUG, "I frame: QP=%i (+%i/2)\n", |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1133 v->pq, v->halfpq); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1134 #if HAS_ADVANCED_PROFILE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1135 if (v->profile <= PROFILE_MAIN) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1136 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1137 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1138 if (v->extended_mv) v->mvrange = get_prefix(&v->gb, 0, 3); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1139 if (v->multires) v->respic = get_bits(&v->gb, 2); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1140 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1141 #if HAS_ADVANCED_PROFILE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1142 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1143 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1144 ac_pred = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1145 if (v->postprocflag) v->postproc = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1146 /* 7.1.1.34 + 8.5.2 */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1147 if (v->overlap && v->pq<9) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1148 { |
2462 | 1149 v->condover = get_bits(&v->gb, 1); |
1150 if (v->condover) | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1151 { |
2462 | 1152 v->condover = 2+get_bits(&v->gb, 1); |
1153 if (v->condover == 3) | |
1154 { | |
1155 status = bitplane_decoding(&v->over_flags_plane, v); | |
1156 if (status < 0) return -1; | |
1157 #if TRACE | |
1158 av_log(v->avctx, AV_LOG_DEBUG, "Overflags plane encoding: " | |
1159 "Imode: %i, Invert: %i\n", status>>1, status&1); | |
1160 #endif | |
1161 } | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1162 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1163 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1164 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1165 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1166 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1167 /* Epilog should be done in caller */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1168 return status; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1169 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1170 |
2462 | 1171 /* Table 9, p58-60 */ |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1172 static int decode_p_picture_header(VC9Context *v) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1173 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1174 /* INTERFRM, FRMCNT, RANGEREDFRM read in caller */ |
2462 | 1175 int lowquant, pqindex, status = 0; |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1176 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1177 pqindex = get_bits(&v->gb, 5); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1178 if (v->quantizer_mode == QUANT_FRAME_IMPLICIT) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1179 v->pq = pquant_table[0][pqindex]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1180 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1181 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1182 v->pq = pquant_table[v->quantizer_mode-1][pqindex]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1183 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1184 if (pqindex < 9) v->halfpq = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1185 if (v->quantizer_mode == QUANT_FRAME_EXPLICIT) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1186 v->pquantizer = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1187 av_log(v->avctx, AV_LOG_DEBUG, "P Frame: QP=%i (+%i/2)\n", |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1188 v->pq, v->halfpq); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1189 if (v->extended_mv == 1) v->mvrange = get_prefix(&v->gb, 0, 3); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1190 #if HAS_ADVANCED_PROFILE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1191 if (v->profile > PROFILE_MAIN) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1192 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1193 if (v->postprocflag) v->postproc = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1194 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1195 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1196 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1197 if (v->multires) v->respic = get_bits(&v->gb, 2); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1198 lowquant = (v->pquantizer>12) ? 0 : 1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1199 v->mv_mode = mv_pmode_table[lowquant][get_prefix(&v->gb, 1, 4)]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1200 if (v->mv_mode == MV_PMODE_INTENSITY_COMP) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1201 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1202 v->mv_mode2 = mv_pmode_table[lowquant][get_prefix(&v->gb, 1, 3)]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1203 v->lumscale = get_bits(&v->gb, 6); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1204 v->lumshift = get_bits(&v->gb, 6); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1205 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1206 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1207 if ((v->mv_mode == MV_PMODE_INTENSITY_COMP && |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1208 v->mv_mode2 == MV_PMODE_MIXED_MV) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1209 || v->mv_mode == MV_PMODE_MIXED_MV) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1210 { |
2462 | 1211 status = bitplane_decoding(&v->mv_type_mb_plane, v); |
1212 if (status < 0) return -1; | |
1213 #if TRACE | |
1214 av_log(v->avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: " | |
1215 "Imode: %i, Invert: %i\n", status>>1, status&1); | |
1216 #endif | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1217 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1218 |
2462 | 1219 status = bitplane_decoding(&v->skip_mb_plane, v); |
1220 if (status < 0) return -1; | |
1221 #if TRACE | |
1222 av_log(v->avctx, AV_LOG_DEBUG, "MB Skip plane encoding: " | |
1223 "Imode: %i, Invert: %i\n", status>>1, status&1); | |
1224 #endif | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1225 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1226 /* Hopefully this is correct for P frames */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1227 v->mv_diff_vlc = &vc9_mv_diff_vlc[get_bits(&v->gb, 2)]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1228 v->cbpcy_vlc = &vc9_cbpcy_p_vlc[get_bits(&v->gb, 2)]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1229 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1230 if (v->dquant) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1231 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1232 av_log(v->avctx, AV_LOG_INFO, "VOP DQuant info\n"); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1233 vop_dquant_decoding(v); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1234 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1235 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1236 if (v->vstransform) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1237 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1238 v->ttmbf = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1239 if (v->ttmbf) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1240 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1241 v->ttfrm = get_bits(&v->gb, 2); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1242 av_log(v->avctx, AV_LOG_INFO, "Transform used: %ix%i\n", |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1243 (v->ttfrm & 2) ? 4 : 8, (v->ttfrm & 1) ? 4 : 8); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1244 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1245 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1246 /* Epilog should be done in caller */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1247 return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1248 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1249 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1250 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1251 static int standard_decode_picture_header(VC9Context *v) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1252 { |
2462 | 1253 int status = 0, index; |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1254 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1255 if (v->finterpflag) v->interpfrm = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1256 skip_bits(&v->gb, 2); //framecnt unused |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1257 if (v->rangered) v->rangeredfrm = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1258 v->pict_type = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1259 if (v->avctx->max_b_frames && !v->pict_type) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1260 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1261 if (get_bits(&v->gb, 1)) v->pict_type = I_TYPE; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1262 else v->pict_type = P_TYPE; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1263 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1264 else v->pict_type++; //P_TYPE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1265 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1266 switch (v->pict_type) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1267 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1268 case I_TYPE: status = decode_i_picture_header(v); break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1269 case BI_TYPE: status = decode_b_picture_header(v); break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1270 case P_TYPE: status = decode_p_picture_header(v); break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1271 case B_TYPE: status = decode_b_picture_header(v); break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1272 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1273 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1274 if (status == FRAME_SKIPED) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1275 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1276 av_log(v, AV_LOG_INFO, "Skipping frame...\n"); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1277 return status; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1278 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1279 |
2462 | 1280 /* AC Syntax */ |
1281 index = decode012(&v->gb); | |
1282 v->luma_ac_vlc = NULL + index; //FIXME Add AC table | |
1283 v->chroma_ac_vlc = NULL + index; | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1284 if (v->pict_type == I_TYPE || v->pict_type == BI_TYPE) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1285 { |
2462 | 1286 index = decode012(&v->gb); |
1287 v->luma_ac2_vlc = NULL + index; //FIXME Add AC2 table | |
1288 v->chroma_ac2_vlc = NULL + index; | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1289 } |
2462 | 1290 /* DC Syntax */ |
1291 index = decode012(&v->gb); | |
1292 v->luma_dc_vlc = vc9_luma_dc_vlc + index; | |
1293 v->chroma_dc_vlc = vc9_chroma_dc_vlc + index; | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1294 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1295 return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1296 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1297 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1298 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1299 #if HAS_ADVANCED_PROFILE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1300 /******************************************************************************/ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1301 /* Advanced Profile picture header decoding specific functions */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1302 /******************************************************************************/ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1303 static int advanced_decode_picture_header(VC9Context *v) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1304 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1305 static const int type_table[4] = { P_TYPE, B_TYPE, I_TYPE, BI_TYPE }; |
2462 | 1306 int type, i, index; |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1307 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1308 if (v->interlace) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1309 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1310 v->fcm = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1311 if (v->fcm) v->fcm = 2+get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1312 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1313 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1314 type = get_prefix(&v->gb, 0, 4); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1315 if (type > 4 || type < 0) return FRAME_SKIPED; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1316 v->pict_type = type_table[type]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1317 av_log(v->avctx, AV_LOG_INFO, "AP Frame Type: %i\n", v->pict_type); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1318 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1319 if (v->tfcntrflag) v->tfcntr = get_bits(&v->gb, 8); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1320 if (v->broadcast) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1321 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1322 if (!v->interlace) v->rptfrm = get_bits(&v->gb, 2); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1323 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1324 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1325 v->tff = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1326 v->rff = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1327 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1328 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1329 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1330 if (v->panscanflag) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1331 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1332 #if 0 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1333 for (i=0; i<v->numpanscanwin; i++) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1334 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1335 v->topleftx[i] = get_bits(&v->gb, 16); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1336 v->toplefty[i] = get_bits(&v->gb, 16); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1337 v->bottomrightx[i] = get_bits(&v->gb, 16); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1338 v->bottomrighty[i] = get_bits(&v->gb, 16); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1339 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1340 #else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1341 skip_bits(&v->gb, 16*4*v->numpanscanwin); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1342 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1343 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1344 v->rndctrl = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1345 v->uvsamp = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1346 if (v->finterpflag == 1) v->interpfrm = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1347 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1348 switch(v->pict_type) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1349 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1350 case I_TYPE: if (decode_i_picture_header(v) < 0) return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1351 case P_TYPE: if (decode_p_picture_header(v) < 0) return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1352 case BI_TYPE: |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1353 case B_TYPE: if (decode_b_picture_header(v) < 0) return FRAME_SKIPED; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1354 default: break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1355 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1356 |
2462 | 1357 /* AC Syntax */ |
1358 index = decode012(&v->gb); | |
1359 v->luma_ac_vlc = NULL + index; //FIXME | |
1360 v->chroma_ac_vlc = NULL + index; //FIXME | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1361 if (v->pict_type == I_TYPE || v->pict_type == BI_TYPE) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1362 { |
2462 | 1363 index = decode012(&v->gb); //FIXME |
1364 v->luma_ac2_vlc = NULL + index; | |
1365 v->chroma_ac2_vlc = NULL + index; | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1366 } |
2462 | 1367 /* DC Syntax */ |
1368 index = decode012(&v->gb); | |
1369 v->luma_dc_vlc = vc9_luma_dc_vlc + index; | |
1370 v->chroma_dc_vlc = vc9_chroma_dc_vlc + index; | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1371 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1372 return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1373 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1374 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1375 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1376 /******************************************************************************/ |
2462 | 1377 /* Block decoding functions */ |
1378 /******************************************************************************/ | |
1379 /* 7.1.4, p91 and 8.1.1.7, p(1)04 */ | |
1380 /* FIXME proper integration (unusable and lots of parameters to send */ | |
1381 int decode_luma_intra_block(VC9Context *v, int mquant) | |
1382 { | |
1383 int dcdiff; | |
1384 | |
1385 dcdiff = get_vlc2(&v->gb, v->luma_dc_vlc->table, | |
1386 VC9_LUMA_DC_VLC_BITS, 2); | |
1387 if (dcdiff) | |
1388 { | |
1389 if (dcdiff == 119 /* ESC index value */) | |
1390 { | |
1391 /* TODO: Optimize */ | |
1392 if (mquant == 1) dcdiff = get_bits(&v->gb, 10); | |
1393 else if (mquant == 2) dcdiff = get_bits(&v->gb, 9); | |
1394 else dcdiff = get_bits(&v->gb, 8); | |
1395 } | |
1396 else | |
1397 { | |
1398 if (mquant == 1) | |
1399 dcdiff = (dcdiff<<2) + get_bits(&v->gb, 2) - 3; | |
1400 else if (mquant == 2) | |
1401 dcdiff = (dcdiff<<1) + get_bits(&v->gb, 1) - 1; | |
1402 } | |
1403 if (get_bits(&v->gb, 1)) | |
1404 dcdiff = -dcdiff; | |
1405 } | |
1406 /* FIXME: 8.1.1.15, p(1)13, coeff scaling for Adv Profile */ | |
1407 | |
1408 return 0; | |
1409 } | |
1410 | |
1411 /******************************************************************************/ | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1412 /* MacroBlock decoding functions */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1413 /******************************************************************************/ |
2462 | 1414 /* 8.1.1.5, p(1)02-(1)03 */ |
1415 /* We only need to store 3 flags, but math with 4 is easier */ | |
1416 #define GET_CBPCY(table, bits) \ | |
1417 predicted_cbpcy = get_vlc2(&v->gb, table, bits, 2); \ | |
1418 cbpcy[0] = (p_cbpcy[-1] == p_cbpcy[2]) \ | |
1419 ? previous_cbpcy[1] : p_cbpcy[+2]; \ | |
1420 cbpcy[0] ^= ((predicted_cbpcy>>5)&0x01); \ | |
1421 cbpcy[1] = (p_cbpcy[2] == p_cbpcy[3]) ? cbpcy[0] : p_cbpcy[3]; \ | |
1422 cbpcy[1] ^= ((predicted_cbpcy>>4)&0x01); \ | |
1423 cbpcy[2] = (previous_cbpcy[1] == cbpcy[0]) \ | |
1424 ? previous_cbpcy[3] : cbpcy[0]; \ | |
1425 cbpcy[2] ^= ((predicted_cbpcy>>3)&0x01); \ | |
1426 cbpcy[3] = (cbpcy[1] == cbpcy[0]) ? cbpcy[2] : cbpcy[1]; \ | |
1427 cbpcy[3] ^= ((predicted_cbpcy>>2)&0x01); | |
1428 | |
1429 /* 8.1, p100 */ | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1430 static int standard_decode_i_mbs(VC9Context *v) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1431 { |
2462 | 1432 int x, y, current_mb = 0; /* MB/Block Position info */ |
1433 int ac_pred; | |
1434 /* FIXME: better to use a pointer than using (x<<4) */ | |
1435 uint8_t cbpcy[4], previous_cbpcy[4], predicted_cbpcy, | |
1436 *p_cbpcy /* Pointer to skip some math */; | |
1437 | |
1438 /* Reset CBPCY predictors */ | |
1439 memset(v->previous_line_cbpcy, 0, (v->width_mb+1)<<2); | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1440 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1441 /* Select ttmb table depending on pq */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1442 if (v->pq < 5) v->ttmb_vlc = &vc9_ttmb_vlc[0]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1443 else if (v->pq < 13) v->ttmb_vlc = &vc9_ttmb_vlc[1]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1444 else v->ttmb_vlc = &vc9_ttmb_vlc[2]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1445 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1446 for (y=0; y<v->height_mb; y++) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1447 { |
2462 | 1448 /* Init CBPCY for line */ |
1449 *((uint32_t*)previous_cbpcy) = 0x00000000; | |
1450 p_cbpcy = v->previous_line_cbpcy+4; | |
1451 | |
1452 for (x=0; x<v->width_mb; x++, p_cbpcy += 4) | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1453 { |
2462 | 1454 /* Get CBPCY */ |
1455 GET_CBPCY(vc9_cbpcy_i_vlc.table, VC9_CBPCY_I_VLC_BITS); | |
1456 | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1457 ac_pred = get_bits(&v->gb, 1); |
2462 | 1458 |
1459 /* TODO: Decode blocks from that mb wrt cbpcy */ | |
1460 | |
1461 /* Update for next block */ | |
1462 *((uint32_t*)p_cbpcy) = *((uint32_t*)previous_cbpcy); | |
1463 *((uint32_t*)previous_cbpcy) = *((uint32_t*)cbpcy); | |
1464 current_mb++; | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1465 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1466 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1467 return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1468 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1469 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1470 #define GET_MQUANT() \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1471 if (v->dquantfrm) \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1472 { \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1473 if (v->dqprofile == DQPROFILE_ALL_MBS) \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1474 { \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1475 if (v->dqbilevel) \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1476 { \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1477 mquant = (get_bits(&v->gb, 1)) ? v->pq : v->altpq; \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1478 } \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1479 else \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1480 { \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1481 mqdiff = get_bits(&v->gb, 3); \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1482 if (mqdiff != 7) mquant = v->pq + mqdiff; \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1483 else mquant = get_bits(&v->gb, 5); \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1484 } \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1485 } \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1486 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1487 |
2462 | 1488 /* MVDATA decoding from 8.3.5.2, p(1)20 */ |
1489 #define GET_MVDATA(_dmv_x, _dmv_y) \ | |
1490 index = 1 + get_vlc2(&v->gb, v->mv_diff_vlc->table, \ | |
1491 VC9_MV_DIFF_VLC_BITS, 2); \ | |
1492 if (index > 36) \ | |
1493 { \ | |
1494 mb_has_coeffs = 1; \ | |
1495 index -= 37; \ | |
1496 } \ | |
1497 else mb_has_coeffs = 0; \ | |
1498 mb_is_intra = 0; \ | |
1499 if (!index) { _dmv_x = _dmv_y = 0; } \ | |
1500 else if (index == 35) \ | |
1501 { \ | |
1502 _dmv_x = get_bits(&v->gb, k_x); \ | |
1503 _dmv_y = get_bits(&v->gb, k_y); \ | |
1504 mb_is_intra = 1; \ | |
1505 } \ | |
1506 else \ | |
1507 { \ | |
1508 index1 = index%6; \ | |
1509 if (hpel_flag && index1 == 5) val = 1; \ | |
1510 else val = 0; \ | |
1511 val = get_bits(&v->gb, size_table[index1] - val); \ | |
1512 sign = 0 - (val&1); \ | |
1513 _dmv_x = (sign ^ ((val>>1) + offset_table[index1])) - sign; \ | |
1514 \ | |
1515 index1 = index/6; \ | |
1516 if (hpel_flag && index1 == 5) val = 1; \ | |
1517 else val = 0; \ | |
1518 val = get_bits(&v->gb, size_table[index1] - val); \ | |
1519 sign = 0 - (val&1); \ | |
1520 _dmv_y = (sign ^ ((val>>1) + offset_table[index1])) - sign; \ | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1521 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1522 |
2462 | 1523 /* 8.1, p(1)15 */ |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1524 static int decode_p_mbs(VC9Context *v) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1525 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1526 int x, y, current_mb = 0, i; /* MB/Block Position info */ |
2462 | 1527 uint8_t cbpcy[4], previous_cbpcy[4], predicted_cbpcy, |
1528 *p_cbpcy /* Pointer to skip some math */; | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1529 int hybrid_pred, ac_pred; /* Prediction types */ |
2462 | 1530 int mv_mode_bit = 0; |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1531 int mqdiff, mquant; /* MB quantization */ |
2462 | 1532 int ttmb; /* MB Transform type */ |
1533 | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1534 static const int size_table[6] = { 0, 2, 3, 4, 5, 8 }, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1535 offset_table[6] = { 0, 1, 3, 7, 15, 31 }; |
2462 | 1536 int mb_has_coeffs = 1 /* last_flag */, mb_is_intra; |
1537 int dmv_x, dmv_y; /* Differential MV components */ | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1538 int k_x, k_y; /* Long MV fixed bitlength */ |
2462 | 1539 int hpel_flag; /* Some MB properties */ |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1540 int index, index1; /* LUT indices */ |
2462 | 1541 int val, sign; /* MVDATA temp values */ |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1542 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1543 /* Select ttmb table depending on pq */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1544 if (v->pq < 5) v->ttmb_vlc = &vc9_ttmb_vlc[0]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1545 else if (v->pq < 13) v->ttmb_vlc = &vc9_ttmb_vlc[1]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1546 else v->ttmb_vlc = &vc9_ttmb_vlc[2]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1547 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1548 /* Select proper long MV range */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1549 switch (v->mvrange) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1550 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1551 case 1: k_x = 10; k_y = 9; break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1552 case 2: k_x = 12; k_y = 10; break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1553 case 3: k_x = 13; k_y = 11; break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1554 default: /*case 0 too */ k_x = 9; k_y = 8; break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1555 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1556 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1557 hpel_flag = v->mv_mode & 1; //MV_PMODE is HPEL |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1558 k_x -= hpel_flag; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1559 k_y -= hpel_flag; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1560 |
2462 | 1561 /* Reset CBPCY predictors */ |
1562 memset(v->previous_line_cbpcy, 0, (v->width_mb+1)<<2); | |
1563 | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1564 for (y=0; y<v->height_mb; y++) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1565 { |
2462 | 1566 /* Init CBPCY for line */ |
1567 *((uint32_t*)previous_cbpcy) = 0x00000000; | |
1568 p_cbpcy = v->previous_line_cbpcy+4; | |
1569 | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1570 for (x=0; x<v->width_mb; x++) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1571 { |
2462 | 1572 if (v->mv_type_mb_plane.is_raw) |
1573 v->mv_type_mb_plane.data[current_mb] = get_bits(&v->gb, 1); | |
1574 if (v->skip_mb_plane.is_raw) | |
1575 v->skip_mb_plane.data[current_mb] = get_bits(&v->gb, 1); | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1576 if (!mv_mode_bit) /* 1MV mode */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1577 { |
2462 | 1578 if (!v->skip_mb_plane.data[current_mb]) |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1579 { |
2462 | 1580 GET_MVDATA(dmv_x, dmv_y); |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1581 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1582 /* hybrid mv pred, 8.3.5.3.4 */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1583 if (v->mv_mode == MV_PMODE_1MV || |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1584 v->mv_mode == MV_PMODE_MIXED_MV) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1585 hybrid_pred = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1586 if (mb_is_intra && !mb_has_coeffs) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1587 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1588 GET_MQUANT(); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1589 ac_pred = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1590 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1591 else if (mb_has_coeffs) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1592 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1593 if (mb_is_intra) ac_pred = get_bits(&v->gb, 1); |
2462 | 1594 GET_CBPCY(v->cbpcy_vlc->table, VC9_CBPCY_P_VLC_BITS); |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1595 GET_MQUANT(); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1596 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1597 if (!v->ttmbf) |
2462 | 1598 ttmb = get_vlc2(&v->gb, v->ttmb_vlc->table, |
1599 VC9_TTMB_VLC_BITS, 12); | |
1600 /* TODO: decode blocks from that mb wrt cbpcy */ | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1601 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1602 else //Skipped |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1603 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1604 /* hybrid mv pred, 8.3.5.3.4 */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1605 if (v->mv_mode == MV_PMODE_1MV || |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1606 v->mv_mode == MV_PMODE_MIXED_MV) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1607 hybrid_pred = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1608 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1609 } //1MV mode |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1610 else //4MV mode |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1611 { |
2462 | 1612 if (!v->skip_mb_plane.data[current_mb] /* unskipped MB */) |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1613 { |
2462 | 1614 /* Get CBPCY */ |
1615 GET_CBPCY(v->cbpcy_vlc->table, VC9_CBPCY_P_VLC_BITS); | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1616 for (i=0; i<4; i++) //For all 4 Y blocks |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1617 { |
2462 | 1618 if (cbpcy[i] /* cbpcy set for this block */) |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1619 { |
2462 | 1620 GET_MVDATA(dmv_x, dmv_y); |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1621 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1622 if (v->mv_mode == MV_PMODE_MIXED_MV /* Hybrid pred */) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1623 hybrid_pred = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1624 GET_MQUANT(); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1625 if (mb_is_intra /* One of the 4 blocks is intra */ && |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1626 index /* non-zero pred for that block */) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1627 ac_pred = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1628 if (!v->ttmbf) |
2462 | 1629 ttmb = get_vlc2(&v->gb, v->ttmb_vlc->table, |
1630 VC9_TTMB_VLC_BITS, 12); | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1631 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1632 /* TODO: Process blocks wrt cbpcy */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1633 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1634 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1635 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1636 else //Skipped MB |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1637 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1638 for (i=0; i<4; i++) //All 4 Y blocks |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1639 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1640 if (v->mv_mode == MV_PMODE_MIXED_MV /* Hybrid pred */) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1641 hybrid_pred = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1642 |
2462 | 1643 /* TODO: do something */ |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1644 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1645 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1646 } |
2462 | 1647 |
1648 /* Update for next block */ | |
1649 #if TRACE > 2 | |
1650 av_log(v->avctx, AV_LOG_DEBUG, "Block %4i: p_cbpcy=%i%i%i%i, previous_cbpcy=%i%i%i%i," | |
1651 " cbpcy=%i%i%i%i\n", current_mb, | |
1652 p_cbpcy[0], p_cbpcy[1], p_cbpcy[2], p_cbpcy[3], | |
1653 previous_cbpcy[0], previous_cbpcy[1], previous_cbpcy[2], previous_cbpcy[3], | |
1654 cbpcy[0], cbpcy[1], cbpcy[2], cbpcy[3]); | |
1655 #endif | |
1656 *((uint32_t*)p_cbpcy) = *((uint32_t*)previous_cbpcy); | |
1657 *((uint32_t*)previous_cbpcy) = *((uint32_t*)cbpcy); | |
1658 current_mb++; | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1659 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1660 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1661 return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1662 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1663 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1664 static int decode_b_mbs(VC9Context *v) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1665 { |
2462 | 1666 int x, y, current_mb = 0, i /* MB / B postion information */; |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1667 int ac_pred; |
2462 | 1668 int b_mv_type = BMV_TYPE_BACKWARD; |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1669 int mquant, mqdiff; /* MB quant stuff */ |
2462 | 1670 int ttmb; /* MacroBlock transform type */ |
1671 | |
1672 static const int size_table[6] = { 0, 2, 3, 4, 5, 8 }, | |
1673 offset_table[6] = { 0, 1, 3, 7, 15, 31 }; | |
1674 int mb_has_coeffs = 1 /* last_flag */, mb_is_intra = 1; | |
1675 int dmv1_x, dmv1_y, dmv2_x, dmv2_y; /* Differential MV components */ | |
1676 int k_x, k_y; /* Long MV fixed bitlength */ | |
1677 int hpel_flag; /* Some MB properties */ | |
1678 int index, index1; /* LUT indices */ | |
1679 int val, sign; /* MVDATA temp values */ | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1680 |
2462 | 1681 /* Select proper long MV range */ |
1682 switch (v->mvrange) | |
1683 { | |
1684 case 1: k_x = 10; k_y = 9; break; | |
1685 case 2: k_x = 12; k_y = 10; break; | |
1686 case 3: k_x = 13; k_y = 11; break; | |
1687 default: /*case 0 too */ k_x = 9; k_y = 8; break; | |
1688 } | |
1689 hpel_flag = v->mv_mode & 1; //MV_PMODE is HPEL | |
1690 k_x -= hpel_flag; | |
1691 k_y -= hpel_flag; | |
1692 | |
1693 /* Select ttmb table depending on pq */ | |
1694 if (v->pq < 5) v->ttmb_vlc = &vc9_ttmb_vlc[0]; | |
1695 else if (v->pq < 13) v->ttmb_vlc = &vc9_ttmb_vlc[1]; | |
1696 else v->ttmb_vlc = &vc9_ttmb_vlc[2]; | |
1697 | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1698 for (y=0; y<v->height_mb; y++) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1699 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1700 for (x=0; x<v->width_mb; x++) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1701 { |
2462 | 1702 if (v->direct_mb_plane.is_raw) |
1703 v->direct_mb_plane.data[current_mb] = get_bits(&v->gb, 1); | |
1704 if (v->skip_mb_plane.is_raw) | |
1705 v->skip_mb_plane.data[current_mb] = get_bits(&v->gb, 1); | |
1706 | |
1707 if (!v->direct_mb_plane.data[current_mb]) | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1708 { |
2462 | 1709 if (v->skip_mb_plane.data[current_mb]) |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1710 { |
2462 | 1711 b_mv_type = decode012(&v->gb); |
1712 if (v->bfraction > 420 /*1/2*/ && | |
1713 b_mv_type < 3) b_mv_type = 1-b_mv_type; | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1714 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1715 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1716 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1717 /* FIXME getting tired commenting */ |
2462 | 1718 GET_MVDATA(dmv1_x, dmv1_y); |
1719 if (!mb_is_intra /* b_mv1 tells not intra */) | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1720 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1721 /* FIXME: actually read it */ |
2462 | 1722 b_mv_type = decode012(&v->gb); |
1723 if (v->bfraction > 420 /*1/2*/ && | |
1724 b_mv_type < 3) b_mv_type = 1-b_mv_type; | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1725 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1726 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1727 } |
2462 | 1728 if (!v->skip_mb_plane.data[current_mb]) |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1729 { |
2462 | 1730 if (mb_has_coeffs /* BMV1 == "last" */) |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1731 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1732 GET_MQUANT(); |
2462 | 1733 if (mb_is_intra /* intra mb */) |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1734 ac_pred = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1735 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1736 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1737 { |
2462 | 1738 /* if bmv1 tells MVs are interpolated */ |
1739 if (b_mv_type == BMV_TYPE_INTERPOLATED) | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1740 { |
2462 | 1741 GET_MVDATA(dmv2_x, dmv2_y); |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1742 } |
2462 | 1743 /* GET_MVDATA has reset some stuff */ |
1744 if (mb_has_coeffs /* b_mv2 == "last" */) | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1745 { |
2462 | 1746 if (mb_is_intra /* intra_mb */) |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1747 ac_pred = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1748 GET_MQUANT(); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1749 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1750 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1751 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1752 //End1 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1753 if (v->ttmbf) |
2462 | 1754 ttmb = get_vlc2(&v->gb, v->ttmb_vlc->table, |
1755 VC9_TTMB_VLC_BITS, 12); | |
1756 | |
1757 //End2 | |
1758 for (i=0; i<6; i++) | |
1759 { | |
1760 /* FIXME: process the block */ | |
1761 } | |
1762 | |
1763 current_mb++; | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1764 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1765 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1766 return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1767 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1768 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1769 #if HAS_ADVANCED_PROFILE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1770 static int advanced_decode_i_mbs(VC9Context *v) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1771 { |
2462 | 1772 int x, y, mqdiff, mquant, ac_pred, current_mb = 0, over_flags_mb = 0; |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1773 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1774 for (y=0; y<v->height_mb; y++) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1775 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1776 for (x=0; x<v->width_mb; x++) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1777 { |
2462 | 1778 if (v->ac_pred_plane.data[current_mb]) |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1779 ac_pred = get_bits(&v->gb, 1); |
2462 | 1780 if (v->condover == 3 && v->over_flags_plane.is_raw) |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1781 over_flags_mb = get_bits(&v->gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1782 GET_MQUANT(); |
2462 | 1783 |
1784 /* TODO: lots */ | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1785 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1786 current_mb++; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1787 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1788 return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1789 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1790 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1791 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1792 static int vc9_decode_init(AVCodecContext *avctx) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1793 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1794 VC9Context *v = avctx->priv_data; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1795 GetBitContext gb; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1796 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1797 if (!avctx->extradata_size || !avctx->extradata) return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1798 avctx->pix_fmt = PIX_FMT_YUV420P; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1799 v->avctx = avctx; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1800 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1801 if (init_common(v) < 0) return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1802 |
2462 | 1803 avctx->coded_width = avctx->width; |
1804 avctx->coded_height = avctx->height; | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1805 if (avctx->codec_id == CODEC_ID_WMV3) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1806 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1807 int count = 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1808 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1809 // looks like WMV3 has a sequence header stored in the extradata |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1810 // advanced sequence header may be before the first frame |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1811 // the last byte of the extradata is a version number, 1 for the |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1812 // samples we can decode |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1813 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1814 init_get_bits(&gb, avctx->extradata, avctx->extradata_size); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1815 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1816 decode_sequence_header(avctx, &gb); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1817 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1818 count = avctx->extradata_size*8 - get_bits_count(&gb); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1819 if (count>0) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1820 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1821 av_log(avctx, AV_LOG_INFO, "Extra data: %i bits left, value: %X\n", |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1822 count, get_bits(&gb, count)); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1823 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1824 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1825 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1826 av_log(avctx, AV_LOG_INFO, "Read %i bits in overflow\n", -count); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1827 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1828 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1829 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1830 /* Done with header parsing */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1831 //FIXME I feel like this is wrong |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1832 v->width_mb = (avctx->coded_width+15)>>4; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1833 v->height_mb = (avctx->coded_height+15)>>4; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1834 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1835 /* Allocate mb bitplanes */ |
2462 | 1836 if (alloc_bitplane(&v->mv_type_mb_plane, v->width_mb, v->height_mb) < 0) |
1837 return -1; | |
1838 if (alloc_bitplane(&v->mv_type_mb_plane, v->width_mb, v->height_mb) < 0) | |
1839 return -1; | |
1840 if (alloc_bitplane(&v->skip_mb_plane, v->width_mb, v->height_mb) < 0) | |
1841 return -1; | |
1842 if (alloc_bitplane(&v->direct_mb_plane, v->width_mb, v->height_mb) < 0) | |
1843 return -1; | |
1844 | |
1845 /* For predictors */ | |
1846 v->previous_line_cbpcy = (uint8_t *)av_malloc((v->width_mb+1)*4); | |
1847 if (!v->previous_line_cbpcy) return -1; | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1848 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1849 #if HAS_ADVANCED_PROFILE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1850 if (v->profile > PROFILE_MAIN) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1851 { |
2462 | 1852 if (alloc_bitplane(&v->over_flags_plane, v->width_mb, v->height_mb) < 0) |
1853 return -1; | |
1854 if (alloc_bitplane(&v->ac_pred_plane, v->width_mb, v->height_mb) < 0) | |
1855 return -1; | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1856 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1857 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1858 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1859 return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1860 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1861 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1862 static int vc9_decode_frame(AVCodecContext *avctx, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1863 void *data, int *data_size, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1864 uint8_t *buf, int buf_size) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1865 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1866 VC9Context *v = avctx->priv_data; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1867 int ret = FRAME_SKIPED, len, start_code; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1868 AVFrame *pict = data; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1869 uint8_t *tmp_buf; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1870 v->avctx = avctx; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1871 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1872 //buf_size = 0 -> last frame |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1873 if (!buf_size) return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1874 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1875 len = avpicture_get_size(avctx->pix_fmt, avctx->width, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1876 avctx->height); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1877 tmp_buf = (uint8_t *)av_mallocz(len); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1878 avpicture_fill((AVPicture *)pict, tmp_buf, avctx->pix_fmt, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1879 avctx->width, avctx->height); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1880 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1881 if (avctx->codec_id == CODEC_ID_WMV3) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1882 { |
2462 | 1883 //No IDU |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1884 init_get_bits(&v->gb, buf, buf_size*8); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1885 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1886 #if HAS_ADVANCED_PROFILE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1887 if (v->profile > PROFILE_MAIN) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1888 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1889 if (advanced_decode_picture_header(v) == FRAME_SKIPED) return buf_size; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1890 switch(v->pict_type) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1891 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1892 case I_TYPE: ret = advanced_decode_i_mbs(v); break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1893 case P_TYPE: ret = decode_p_mbs(v); break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1894 case B_TYPE: |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1895 case BI_TYPE: ret = decode_b_mbs(v); break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1896 default: ret = FRAME_SKIPED; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1897 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1898 if (ret == FRAME_SKIPED) return buf_size; //We ignore for now failures |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1899 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1900 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1901 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1902 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1903 if (standard_decode_picture_header(v) == FRAME_SKIPED) return buf_size; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1904 switch(v->pict_type) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1905 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1906 case I_TYPE: ret = standard_decode_i_mbs(v); break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1907 case P_TYPE: ret = decode_p_mbs(v); break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1908 case B_TYPE: |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1909 case BI_TYPE: ret = decode_b_mbs(v); break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1910 default: ret = FRAME_SKIPED; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1911 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1912 if (ret == FRAME_SKIPED) return buf_size; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1913 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1914 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1915 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1916 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1917 #if 0 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1918 // search for IDU's |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1919 // FIXME |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1920 uint32_t scp = 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1921 int scs = 0, i = 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1922 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1923 while (i < buf_size) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1924 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1925 for (; i < buf_size && scp != 0x000001; i++) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1926 scp = ((scp<<8)|buf[i])&0xffffff; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1927 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1928 if (scp != 0x000001) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1929 break; // eof ? |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1930 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1931 scs = buf[i++]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1932 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1933 init_get_bits(&v->gb, buf+i, (buf_size-i)*8); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1934 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1935 switch(scs) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1936 { |
2462 | 1937 case 0x0A: //Sequence End Code |
1938 return 0; | |
1939 case 0x0B: //Slice Start Code | |
1940 av_log(avctx, AV_LOG_ERROR, "Slice coding not supported\n"); | |
1941 return -1; | |
1942 case 0x0C: //Field start code | |
1943 av_log(avctx, AV_LOG_ERROR, "Interlaced coding not supported\n"); | |
1944 return -1; | |
1945 case 0x0D: //Frame start code | |
1946 break; | |
1947 case 0x0E: //Entry point Start Code | |
1948 if (v->profile <= MAIN_PROFILE) | |
1949 av_log(avctx, AV_LOG_ERROR, | |
1950 "Found an entry point in profile %i\n", v->profile); | |
1951 advanced_entry_point_process(avctx, &v->gb); | |
1952 break; | |
1953 case 0x0F: //Sequence header Start Code | |
1954 decode_sequence_header(avctx, &v->gb); | |
1955 break; | |
1956 default: | |
1957 av_log(avctx, AV_LOG_ERROR, | |
1958 "Unsupported IDU suffix %lX\n", scs); | |
1959 } | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1960 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1961 i += get_bits_count(&v->gb)*8; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1962 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1963 #else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1964 av_abort(); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1965 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1966 } |
2462 | 1967 av_log(avctx, AV_LOG_DEBUG, "Consumed %i/%i bits\n", |
1968 get_bits_count(&v->gb), buf_size*8); | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1969 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1970 /* Fake consumption of all data */ |
2462 | 1971 *data_size = len; |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1972 return buf_size; //Number of bytes consumed |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1973 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1974 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1975 static int vc9_decode_end(AVCodecContext *avctx) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1976 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1977 VC9Context *v = avctx->priv_data; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1978 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1979 #if HAS_ADVANCED_PROFILE |
2458
915094e3da5d
dont use several 100 mb memory for a tiny 120 element table
michael
parents:
2453
diff
changeset
|
1980 av_freep(&v->hrd_rate); |
915094e3da5d
dont use several 100 mb memory for a tiny 120 element table
michael
parents:
2453
diff
changeset
|
1981 av_freep(&v->hrd_buffer); |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1982 #endif |
2458
915094e3da5d
dont use several 100 mb memory for a tiny 120 element table
michael
parents:
2453
diff
changeset
|
1983 av_freep(&v->mv_type_mb_plane); |
915094e3da5d
dont use several 100 mb memory for a tiny 120 element table
michael
parents:
2453
diff
changeset
|
1984 av_freep(&v->skip_mb_plane); |
915094e3da5d
dont use several 100 mb memory for a tiny 120 element table
michael
parents:
2453
diff
changeset
|
1985 av_freep(&v->direct_mb_plane); |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1986 return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1987 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1988 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1989 AVCodec vc9_decoder = { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1990 "vc9", |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1991 CODEC_TYPE_VIDEO, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1992 CODEC_ID_VC9, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1993 sizeof(VC9Context), |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1994 vc9_decode_init, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1995 NULL, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1996 vc9_decode_end, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1997 vc9_decode_frame, |
2453 | 1998 CODEC_CAP_DELAY, |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1999 NULL |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
2000 }; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
2001 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
2002 AVCodec wmv3_decoder = { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
2003 "wmv3", |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
2004 CODEC_TYPE_VIDEO, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
2005 CODEC_ID_WMV3, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
2006 sizeof(VC9Context), |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
2007 vc9_decode_init, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
2008 NULL, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
2009 vc9_decode_end, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
2010 vc9_decode_frame, |
2453 | 2011 CODEC_CAP_DELAY, |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
2012 NULL |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
2013 }; |