Mercurial > libavcodec.hg
annotate vc9.c @ 2473:73afecc117a3 libavcodec
10l (didnt test code after cvs up ...)
author | michael |
---|---|
date | Sun, 30 Jan 2005 14:10:30 +0000 |
parents | 5565203c95ee |
children | 81a9f883a17a |
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_ !! |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
29 */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
30 #include "common.h" |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
31 #include "dsputil.h" |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
32 #include "avcodec.h" |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
33 #include "mpegvideo.h" |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
34 #include "vc9data.h" |
2465
5565203c95ee
use dc tables from msmpeg4 instead of duplicating them patch by anonymous
michael
parents:
2464
diff
changeset
|
35 extern const uint32_t ff_table0_dc_lum[120][2], ff_table1_dc_lum[120][2]; |
5565203c95ee
use dc tables from msmpeg4 instead of duplicating them patch by anonymous
michael
parents:
2464
diff
changeset
|
36 extern const uint32_t ff_table0_dc_chroma[120][2], ff_table1_dc_chroma[120][2]; |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
37 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
38 /* Some inhibiting stuff */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
39 #define HAS_ADVANCED_PROFILE 1 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
40 #define TRACE 1 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
41 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
42 #if TRACE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
43 # 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
|
44 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
|
45 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
|
46 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
|
47 { \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
48 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
|
49 return -1; \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
50 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
51 #else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
52 # 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
|
53 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
|
54 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
|
55 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
|
56 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
57 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
58 #define PROFILE_SIMPLE 0 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
59 #define PROFILE_MAIN 1 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
60 #define PROFILE_ADVANCED 3 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
61 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
62 #define QUANT_FRAME_IMPLICIT 0 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
63 #define QUANT_FRAME_EXPLICIT 1 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
64 #define QUANT_NON_UNIFORM 2 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
65 #define QUANT_UNIFORM 3 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
66 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
67 /* Where quant can be changed */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
68 #define DQPROFILE_FOUR_EDGES 0 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
69 #define DQPROFILE_DOUBLE_EDGES 1 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
70 #define DQPROFILE_SINGLE_EDGE 2 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
71 #define DQPROFILE_ALL_MBS 3 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
72 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
73 /* 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
|
74 #define DQSINGLE_BEDGE_LEFT 0 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
75 #define DQSINGLE_BEDGE_TOP 1 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
76 #define DQSINGLE_BEDGE_RIGHT 2 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
77 #define DQSINGLE_BEDGE_BOTTOM 3 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
78 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
79 /* 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
|
80 #define DQDOUBLE_BEDGE_TOPLEFT 0 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
81 #define DQDOUBLE_BEDGE_TOPRIGHT 1 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
82 #define DQDOUBLE_BEDGE_BOTTOMRIGHT 2 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
83 #define DQDOUBLE_BEDGE_BOTTOMLEFT 3 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
84 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
85 /* MV P modes */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
86 #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
|
87 #define MV_PMODE_1MV 1 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
88 #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
|
89 #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
|
90 #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
|
91 |
2462 | 92 #define BMV_TYPE_BACKWARD 0 |
93 #define BMV_TYPE_FORWARD 1 | |
94 #define BMV_TYPE_INTERPOLATED 3 | |
95 | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
96 /* 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
|
97 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
|
98 { 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
|
99 { 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
|
100 }; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
101 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
102 /* One more frame type */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
103 #define BI_TYPE 7 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
104 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
105 /* FIXME Worse than ugly */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
106 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
|
107 fps_dr[2] = { 1000, 1001 }; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
108 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
|
109 { /* Implicit quantizer */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
110 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
|
111 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
|
112 }, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
113 { /* Explicit quantizer, pquantizer uniform */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
114 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
|
115 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
|
116 }, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
117 { /* Explicit quantizer, pquantizer non-uniform */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
118 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
|
119 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
|
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 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
123 // 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
|
124 #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
|
125 static VLC vc9_bfraction_vlc; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
126 #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
|
127 static VLC vc9_imode_vlc; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
128 #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
|
129 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
|
130 #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
|
131 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
|
132 /* Could be optimized, one table only needs 8 bits */ |
2462 | 133 #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
|
134 static VLC vc9_ttmb_vlc[3]; |
2462 | 135 #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
|
136 static VLC vc9_mv_diff_vlc[4]; |
2462 | 137 #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
|
138 static VLC vc9_cbpcy_i_vlc; |
2462 | 139 #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
|
140 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
|
141 #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
|
142 static VLC vc9_4mv_block_pattern_vlc[4]; |
2465
5565203c95ee
use dc tables from msmpeg4 instead of duplicating them patch by anonymous
michael
parents:
2464
diff
changeset
|
143 #define VC9_DC_VLC_BITS 9 |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
144 static VLC vc9_luma_dc_vlc[2]; |
2462 | 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 | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
302 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
|
303 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
304 static int done = 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
305 int i; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
306 |
2462 | 307 /* Set the bit planes */ |
308 /* FIXME memset better ? (16bytes) */ | |
309 v->mv_type_mb_plane = (struct BitPlane) { NULL, 0, 0, 0 }; | |
310 v->direct_mb_plane = (struct BitPlane) { NULL, 0, 0, 0 }; | |
311 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
|
312 #if HAS_ADVANCED_PROFILE |
2462 | 313 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
|
314 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
|
315 #endif |
2462 | 316 |
317 /* 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
|
318 #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
|
319 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
|
320 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
|
321 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
|
322 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
|
323 } |
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
324 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
|
325 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
|
326 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
|
327 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
|
328 } |
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
329 #endif |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
330 if(!done) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
331 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
332 done = 1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
333 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
|
334 vc9_bfraction_bits, 1, 1, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
335 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
|
336 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
|
337 vc9_norm2_bits, 1, 1, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
338 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
|
339 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
|
340 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
|
341 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
|
342 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
|
343 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
|
344 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
|
345 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
|
346 vc9_imode_bits, 1, 1, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
347 vc9_imode_codes, 1, 1, 1); |
2465
5565203c95ee
use dc tables from msmpeg4 instead of duplicating them patch by anonymous
michael
parents:
2464
diff
changeset
|
348 INIT_VLC(&vc9_luma_dc_vlc[0], VC9_DC_VLC_BITS, 120, |
5565203c95ee
use dc tables from msmpeg4 instead of duplicating them patch by anonymous
michael
parents:
2464
diff
changeset
|
349 &ff_table0_dc_lum[0][1], 8, 4, |
5565203c95ee
use dc tables from msmpeg4 instead of duplicating them patch by anonymous
michael
parents:
2464
diff
changeset
|
350 &ff_table0_dc_lum[0][0], 8, 4, 1); |
5565203c95ee
use dc tables from msmpeg4 instead of duplicating them patch by anonymous
michael
parents:
2464
diff
changeset
|
351 INIT_VLC(&vc9_chroma_dc_vlc[0], VC9_DC_VLC_BITS, 120, |
5565203c95ee
use dc tables from msmpeg4 instead of duplicating them patch by anonymous
michael
parents:
2464
diff
changeset
|
352 &ff_table0_dc_chroma[0][1], 8, 4, |
5565203c95ee
use dc tables from msmpeg4 instead of duplicating them patch by anonymous
michael
parents:
2464
diff
changeset
|
353 &ff_table0_dc_chroma[0][0], 8, 4, 1); |
5565203c95ee
use dc tables from msmpeg4 instead of duplicating them patch by anonymous
michael
parents:
2464
diff
changeset
|
354 INIT_VLC(&vc9_luma_dc_vlc[1], VC9_DC_VLC_BITS, 120, |
5565203c95ee
use dc tables from msmpeg4 instead of duplicating them patch by anonymous
michael
parents:
2464
diff
changeset
|
355 &ff_table1_dc_lum[0][1], 8, 4, |
5565203c95ee
use dc tables from msmpeg4 instead of duplicating them patch by anonymous
michael
parents:
2464
diff
changeset
|
356 &ff_table1_dc_lum[0][0], 8, 4, 1); |
5565203c95ee
use dc tables from msmpeg4 instead of duplicating them patch by anonymous
michael
parents:
2464
diff
changeset
|
357 INIT_VLC(&vc9_chroma_dc_vlc[1], VC9_DC_VLC_BITS, 120, |
5565203c95ee
use dc tables from msmpeg4 instead of duplicating them patch by anonymous
michael
parents:
2464
diff
changeset
|
358 &ff_table1_dc_chroma[0][1], 8, 4, |
5565203c95ee
use dc tables from msmpeg4 instead of duplicating them patch by anonymous
michael
parents:
2464
diff
changeset
|
359 &ff_table1_dc_chroma[0][0], 8, 4, 1); |
2462 | 360 for (i=0; i<3; i++) |
361 { | |
362 INIT_VLC(&vc9_ttmb_vlc[i], VC9_TTMB_VLC_BITS, 16, | |
363 vc9_ttmb_bits[i], 1, 1, | |
364 vc9_ttmb_codes[i], 2, 2, 1); | |
365 } | |
366 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
|
367 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
368 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
|
369 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
|
370 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
|
371 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
|
372 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
|
373 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
|
374 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
|
375 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
|
376 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
|
377 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
378 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
379 |
2462 | 380 /* Other defaults */ |
381 v->pq = -1; | |
382 v->mvrange = 0; /* 7.1.1.18, p80 */ | |
383 | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
384 return 0; |
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 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
387 #if HAS_ADVANCED_PROFILE |
2462 | 388 /* 6.2.1, p32 */ |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
389 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
|
390 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
391 int i, num; |
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 num = get_bits(gb, 5); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
394 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
395 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
|
396 { |
2458
915094e3da5d
dont use several 100 mb memory for a tiny 120 element table
michael
parents:
2453
diff
changeset
|
397 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
|
398 } |
2462 | 399 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
|
400 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
|
401 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
402 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
|
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_buffer); |
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_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
|
407 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
|
408 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
409 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
|
410 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
411 //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
|
412 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
|
413 //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
|
414 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
|
415 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
416 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
|
417 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
418 //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
|
419 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
|
420 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
|
421 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
422 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
|
423 "%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
|
424 return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
425 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
426 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
|
427 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
|
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 Buffers aren't decreasing:" |
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_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
|
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 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
434 return 0; |
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 |
2462 | 437 /* Table 2, p18 */ |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
438 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
|
439 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
440 VC9Context *v = avctx->priv_data; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
441 int nr, dr, aspect_ratio; |
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 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
|
444 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
|
445 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
|
446 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
447 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
|
448 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
|
449 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
|
450 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
|
451 if (v->reserved) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
452 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
453 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
|
454 v->reserved); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
455 return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
456 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
457 if (v->extended_mv) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
458 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
|
459 |
2462 | 460 /* 6.1.7, p21 */ |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
461 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
|
462 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
463 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
|
464 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
|
465 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
|
466 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
467 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
|
468 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
|
469 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
470 |
2462 | 471 /* 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
|
472 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
|
473 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
474 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
|
475 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
|
476 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
477 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
|
478 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
|
479 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
480 else if (aspect_ratio == 0x0E) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
481 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
482 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
|
483 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
484 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
485 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
486 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
|
487 } |
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 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
490 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
491 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
492 avctx->coded_width = avctx->width; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
493 avctx->coded_height = avctx->height; |
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 |
2462 | 496 /* 6.1.8, p23 */ |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
497 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
|
498 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
499 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
|
500 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
501 nr = get_bits(gb, 8); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
502 dr = get_bits(gb, 4); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
503 if (nr<1) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
504 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
505 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
|
506 return -1; |
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 if (nr>5) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
509 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
510 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
|
511 "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
|
512 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
513 if (dr<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 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
|
516 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
517 if (dr>2) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
518 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
519 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
|
520 "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
|
521 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
522 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
|
523 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
|
524 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
525 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
526 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
527 nr = get_bits(gb, 16); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
528 // 0.03125->2048Hz / 0.03125Hz |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
529 avctx->frame_rate = 1000000; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
530 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
|
531 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
532 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
533 |
2462 | 534 /* 6.1.9, p25 */ |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
535 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
|
536 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
537 //Chromacity coordinates of color primaries |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
538 //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
|
539 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
|
540 if (v->color_prim<1) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
541 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
542 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
|
543 return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
544 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
545 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
|
546 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
547 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
|
548 v->color_prim); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
549 return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
550 } |
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 //Opto-electronic transfer characteristics |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
553 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
|
554 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
|
555 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
556 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
|
557 v->color_prim); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
558 return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
559 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
560 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
561 //Matrix coefficient for primariev->YCbCr |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
562 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
|
563 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
|
564 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
|
565 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
566 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
|
567 v->color_prim); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
568 return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
569 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
570 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
571 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
572 //Hypothetical reference decoder indicator flag |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
573 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
|
574 if (v->hrd_param_flag) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
575 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
576 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
|
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 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
|
580 return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
581 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
582 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
583 |
2462 | 584 /* 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
|
585 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
|
586 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
587 VC9Context *v = avctx->priv_data; |
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 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
|
590 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
|
591 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
592 #if HAS_ADVANCED_PROFILE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
593 if (v->profile > PROFILE_MAIN) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
594 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
595 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
|
596 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
|
597 if (v->chromaformat != 1) |
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 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
|
600 "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
|
601 return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
602 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
603 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
604 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
605 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
606 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
607 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
|
608 if (v->res_sm) |
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 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
|
611 "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
|
612 //return -1; |
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 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
615 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
616 // (fps-2)/4 (->30) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
617 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
|
618 // (bitrate-32kbps)/64kbps |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
619 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
|
620 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
|
621 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
622 #if HAS_ADVANCED_PROFILE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
623 if (v->profile <= PROFILE_MAIN) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
624 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
625 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
626 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
|
627 if (v->res_x8) |
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 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
|
630 "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
|
631 return -1; |
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->multires = get_bits(gb, 1); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
634 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
|
635 if (!v->res_fasttx) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
636 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
637 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
|
638 "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
|
639 //return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
640 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
641 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
642 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
643 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
|
644 if (!v->profile && !v->fastuvmc) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
645 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
646 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
|
647 "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
|
648 return -1; |
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->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
|
651 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
|
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 "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
|
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->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
|
658 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
|
659 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
660 #if HAS_ADVANCED_PROFILE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
661 if (v->profile <= PROFILE_MAIN) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
662 #endif |
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->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
|
665 if (v->res_transtab) |
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 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
|
668 "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
|
669 return -1; |
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 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
672 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
673 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
|
674 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
675 #if HAS_ADVANCED_PROFILE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
676 if (v->profile <= PROFILE_MAIN) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
677 #endif |
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 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
|
680 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
|
681 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
682 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
683 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
|
684 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
|
685 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
686 #if HAS_ADVANCED_PROFILE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
687 if (v->profile <= PROFILE_MAIN) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
688 #endif |
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 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
|
691 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
|
692 if (!v->res_rtm_flag) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
693 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
694 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
|
695 "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
|
696 //return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
697 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
698 #if TRACE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
699 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
|
700 "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
|
701 "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
|
702 "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
|
703 "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
|
704 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
|
705 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
|
706 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
|
707 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
|
708 ); |
2462 | 709 return 0; |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
710 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
711 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
712 #if HAS_ADVANCED_PROFILE |
2462 | 713 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
|
714 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
715 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
716 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
717 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
718 #if HAS_ADVANCED_PROFILE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
719 /*****************************************************************************/ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
720 /* Entry point decoding (Advanced Profile) */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
721 /*****************************************************************************/ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
722 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
|
723 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
724 VC9Context *v = avctx->priv_data; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
725 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
|
726 if (v->profile != PROFILE_ADVANCED) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
727 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
728 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
|
729 "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
|
730 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
|
731 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
732 if (v->hrd_param_flag) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
733 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
734 //Update buffer fullness |
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_DEBUG, "Buffer fullness update\n"); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
736 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
|
737 skip_bits(gb, 8); |
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 ((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
|
740 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
741 //RANGE_MAPY |
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, "RANGE_MAPY\n"); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
743 skip_bits(gb, 3); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
744 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
745 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
|
746 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
747 //RANGE_MAPUV |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
748 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
|
749 skip_bits(gb, 3); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
750 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
751 if (v->panscanflag) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
752 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
753 //NUMPANSCANWIN |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
754 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
|
755 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
|
756 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
757 return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
758 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
759 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
760 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
761 /******************************************************************************/ |
2462 | 762 /* 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
|
763 /******************************************************************************/ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
764 #define IMODE_RAW 0 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
765 #define IMODE_NORM2 1 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
766 #define IMODE_DIFF2 2 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
767 #define IMODE_NORM6 3 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
768 #define IMODE_DIFF6 4 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
769 #define IMODE_ROWSKIP 5 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
770 #define IMODE_COLSKIP 6 |
2462 | 771 int alloc_bitplane(BitPlane *bp, int width, int height) |
772 { | |
773 if (!bp || bp->width<0 || bp->height<0) return -1; | |
774 bp->data = (uint8_t*)av_malloc(width*height); | |
775 if (!bp->data) return -1; | |
776 bp->width = bp->stride = width; //FIXME Needed for aligned data ? | |
777 bp->height = height; | |
778 return 0; | |
779 } | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
780 |
2459 | 781 static void decode_rowskip(uint8_t* plane, int width, int height, int stride, VC9Context *v){ |
782 int x, y; | |
783 | |
784 for (y=0; y<height; y++){ | |
785 if (!get_bits(&v->gb, 1)) //rowskip | |
786 memset(plane, 0, width); | |
787 else | |
788 for (x=0; x<width; x++) | |
789 plane[x] = get_bits(&v->gb, 1); | |
790 plane += stride; | |
791 } | |
792 } | |
793 | |
2460
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
794 //FIXME optimize |
2459 | 795 static void decode_colskip(uint8_t* plane, int width, int height, int stride, VC9Context *v){ |
796 int x, y; | |
797 | |
798 for (x=0; x<width; x++){ | |
799 if (!get_bits(&v->gb, 1)) //colskip | |
800 for (y=0; y<height; y++) | |
801 plane[y*stride] = 0; | |
802 else | |
803 for (y=0; y<height; y++) | |
804 plane[y*stride] = get_bits(&v->gb, 1); | |
805 plane ++; | |
806 } | |
807 } | |
808 | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
809 //FIXME optimize |
2462 | 810 //FIXME is this supposed to set elements to 0/FF or 0/1? 0/x!=0, not used for |
811 // prediction | |
812 //FIXME Use BitPlane struct or return if table is raw (no bits read here but | |
813 // later on) | |
814 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
|
815 { |
2462 | 816 int imode, x, y, code, use_vertical_tile, tile_w, tile_h; |
817 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
|
818 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
819 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
|
820 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
|
821 |
2462 | 822 bp->is_raw = 0; |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
823 switch (imode) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
824 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
825 case IMODE_RAW: |
2462 | 826 //Data is actually read in the MB layer (same for all tests == "raw") |
827 bp->is_raw = 1; //invert ignored | |
828 return invert; | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
829 case IMODE_DIFF2: |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
830 case IMODE_NORM2: |
2462 | 831 if ((bp->height*bp->width) & 1) *(++planep) = get_bits(&v->gb, 1); |
832 for(x=0; x<(bp->height*bp->width)>>1; x++){ | |
2459 | 833 code = get_vlc2(&v->gb, vc9_norm2_vlc.table, VC9_NORM2_VLC_BITS, 2); |
834 *(++planep) = code&1; //lsb => left | |
2462 | 835 *(++planep) = code&2; //msb => right - bitplane => only !0 matters |
2459 | 836 //FIXME width->stride |
837 } | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
838 break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
839 case IMODE_DIFF6: |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
840 case IMODE_NORM6: |
2462 | 841 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
|
842 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
|
843 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
|
844 |
2462 | 845 for(y= bp->height%tile_h; y< bp->height; y+=tile_h){ |
846 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
|
847 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
|
848 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
|
849 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
|
850 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
|
851 } |
2460
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
852 //FIXME following is a pure guess and probably wrong |
2462 | 853 //FIXME A bitplane (0 | !0), so could the shifts be avoided ? |
854 planep[x + 0*bp->stride]= (code>>0)&1; | |
855 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
|
856 if(use_vertical_tile){ |
2462 | 857 planep[x + 0 + 1*bp->stride]= (code>>2)&1; |
858 planep[x + 1 + 1*bp->stride]= (code>>3)&1; | |
859 planep[x + 0 + 2*bp->stride]= (code>>4)&1; | |
860 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
|
861 }else{ |
2462 | 862 planep[x + 2 + 0*bp->stride]= (code>>2)&1; |
863 planep[x + 0 + 1*bp->stride]= (code>>3)&1; | |
864 planep[x + 1 + 1*bp->stride]= (code>>4)&1; | |
865 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
|
866 } |
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
867 } |
2459 | 868 } |
2460
42077bb89a53
norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents:
2459
diff
changeset
|
869 |
2462 | 870 x= bp->width % tile_w; |
871 decode_colskip(bp->data , x, bp->height , bp->stride, v); | |
872 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
|
873 |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
874 break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
875 case IMODE_ROWSKIP: |
2462 | 876 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
|
877 break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
878 case IMODE_COLSKIP: //Teh ugly |
2462 | 879 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
|
880 break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
881 default: break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
882 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
883 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
884 /* Applying diff operator */ |
2459 | 885 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
|
886 { |
2462 | 887 planep = bp->data; |
2459 | 888 planep[0] ^= invert; |
2462 | 889 for (x=1; x<bp->width; x++) |
2459 | 890 planep[x] ^= planep[x-1]; |
2462 | 891 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
|
892 { |
2462 | 893 planep += bp->stride; |
894 planep[0] ^= planep[-bp->stride]; | |
895 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
|
896 { |
2462 | 897 if (planep[x-1] != planep[x-bp->stride]) planep[x] ^= invert; |
898 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
|
899 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
900 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
901 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
902 else if (invert) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
903 { |
2462 | 904 planep = bp->data; |
905 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
|
906 } |
2462 | 907 return (imode<<1) + invert; |
2445
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 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
910 /*****************************************************************************/ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
911 /* VOP Dquant decoding */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
912 /*****************************************************************************/ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
913 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
|
914 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
915 int pqdiff; |
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 //variable size |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
918 if (v->dquant == 2) |
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 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
|
921 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
|
922 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
|
923 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
924 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
925 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
926 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
|
927 if ( v->dquantfrm ) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
928 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
929 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
|
930 switch (v->dqprofile) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
931 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
932 case DQPROFILE_SINGLE_EDGE: |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
933 case DQPROFILE_DOUBLE_EDGES: |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
934 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
|
935 break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
936 case DQPROFILE_ALL_MBS: |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
937 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
|
938 default: break; //Forbidden ? |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
939 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
940 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
|
941 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
942 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
|
943 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
|
944 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
|
945 } |
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 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
948 return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
949 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
950 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
951 /*****************************************************************************/ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
952 /* 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
|
953 /* 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
|
954 /*****************************************************************************/ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
955 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
|
956 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
957 /* Very particular case: |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
958 - 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
|
959 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
|
960 this function afterwards |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
961 - 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
|
962 directly there |
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 int pqindex; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
965 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
966 /* Read the quantization stuff */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
967 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
|
968 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
|
969 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
|
970 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
971 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
972 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
|
973 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
974 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
|
975 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
|
976 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
|
977 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
978 /* Read the MV type/mode */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
979 if (v->extended_mv == 1) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
980 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
|
981 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
982 /* 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
|
983 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
|
984 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
|
985 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
986 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
|
987 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
|
988 /* 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
|
989 return -1; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
990 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
991 |
2462 | 992 /* 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
|
993 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
|
994 { |
2462 | 995 int pqindex, status; |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
996 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
997 /* 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
|
998 if (v->profile == PROFILE_SIMPLE) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
999 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1000 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
|
1001 return FRAME_SKIPED; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1002 } |
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 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
|
1005 VC9_BFRACTION_VLC_BITS, 2)]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1006 if (v->bfraction < -1) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1007 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1008 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
|
1009 return FRAME_SKIPED; |
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 else if (!v->bfraction) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1012 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1013 /* 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
|
1014 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
|
1015 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1016 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1017 /* Read the quantization stuff */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1018 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
|
1019 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
|
1020 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
|
1021 else |
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 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
|
1024 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1025 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
|
1026 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
|
1027 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
|
1028 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1029 /* Read the MV type/mode */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1030 if (v->extended_mv == 1) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1031 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
|
1032 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
|
1033 if (v->pq < 13) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1034 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1035 if (!v->mv_mode) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1036 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1037 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
|
1038 if (v->mv_mode) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1039 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
|
1040 "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
|
1041 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1042 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1043 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1044 { |
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 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1047 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
|
1048 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
|
1049 "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
|
1050 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1051 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
|
1052 } |
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 (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
|
1055 { |
2462 | 1056 status = bitplane_decoding(&v->mv_type_mb_plane, v); |
1057 if (status < 0) | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1058 return -1; |
2462 | 1059 #if TRACE |
1060 av_log(v->avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: " | |
1061 "Imode: %i, Invert: %i\n", status>>1, status&1); | |
1062 #endif | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1063 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1064 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1065 //bitplane |
2462 | 1066 status = bitplane_decoding(&v->direct_mb_plane, v); |
1067 if (status < 0) return -1; | |
1068 #if TRACE | |
1069 av_log(v->avctx, AV_LOG_DEBUG, "MB Direct plane encoding: " | |
1070 "Imode: %i, Invert: %i\n", status>>1, status&1); | |
1071 #endif | |
1072 | |
1073 bitplane_decoding(&v->skip_mb_plane, v); | |
1074 if (status < 0) return -1; | |
1075 #if TRACE | |
1076 av_log(v->avctx, AV_LOG_DEBUG, "Skip MB plane encoding: " | |
1077 "Imode: %i, Invert: %i\n", status>>1, status&1); | |
1078 #endif | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1079 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1080 /* 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
|
1081 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
|
1082 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
|
1083 if (v->dquant) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1084 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1085 vop_dquant_decoding(v); |
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 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1088 if (v->vstransform) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1089 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1090 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
|
1091 if (v->ttmbf) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1092 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1093 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
|
1094 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
|
1095 (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
|
1096 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1097 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1098 /* 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
|
1099 return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1100 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1101 |
2462 | 1102 /* 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
|
1103 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
|
1104 { |
2462 | 1105 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
|
1106 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1107 /* 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
|
1108 //BF = Buffer Fullness |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1109 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
|
1110 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1111 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
|
1112 } |
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 /* Quantizer stuff */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1115 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
|
1116 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
|
1117 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
|
1118 else |
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 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
|
1121 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1122 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
|
1123 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
|
1124 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
|
1125 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
|
1126 v->pq, v->halfpq); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1127 #if HAS_ADVANCED_PROFILE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1128 if (v->profile <= PROFILE_MAIN) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1129 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1130 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1131 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
|
1132 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
|
1133 } |
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 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1136 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1137 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
|
1138 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
|
1139 /* 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
|
1140 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
|
1141 { |
2462 | 1142 v->condover = get_bits(&v->gb, 1); |
1143 if (v->condover) | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1144 { |
2462 | 1145 v->condover = 2+get_bits(&v->gb, 1); |
1146 if (v->condover == 3) | |
1147 { | |
1148 status = bitplane_decoding(&v->over_flags_plane, v); | |
1149 if (status < 0) return -1; | |
1150 #if TRACE | |
1151 av_log(v->avctx, AV_LOG_DEBUG, "Overflags plane encoding: " | |
1152 "Imode: %i, Invert: %i\n", status>>1, status&1); | |
1153 #endif | |
1154 } | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1155 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1156 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1157 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1158 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1159 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1160 /* 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
|
1161 return status; |
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 |
2462 | 1164 /* Table 9, p58-60 */ |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1165 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
|
1166 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1167 /* INTERFRM, FRMCNT, RANGEREDFRM read in caller */ |
2462 | 1168 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
|
1169 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1170 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
|
1171 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
|
1172 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
|
1173 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1174 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1175 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
|
1176 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1177 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
|
1178 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
|
1179 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
|
1180 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
|
1181 v->pq, v->halfpq); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1182 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
|
1183 #if HAS_ADVANCED_PROFILE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1184 if (v->profile > PROFILE_MAIN) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1185 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1186 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
|
1187 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1188 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1189 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1190 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
|
1191 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
|
1192 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
|
1193 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
|
1194 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1195 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
|
1196 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
|
1197 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
|
1198 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1199 |
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 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
|
1202 || 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
|
1203 { |
2462 | 1204 status = bitplane_decoding(&v->mv_type_mb_plane, v); |
1205 if (status < 0) return -1; | |
1206 #if TRACE | |
1207 av_log(v->avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: " | |
1208 "Imode: %i, Invert: %i\n", status>>1, status&1); | |
1209 #endif | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1210 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1211 |
2462 | 1212 status = bitplane_decoding(&v->skip_mb_plane, v); |
1213 if (status < 0) return -1; | |
1214 #if TRACE | |
1215 av_log(v->avctx, AV_LOG_DEBUG, "MB Skip plane encoding: " | |
1216 "Imode: %i, Invert: %i\n", status>>1, status&1); | |
1217 #endif | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1218 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1219 /* 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
|
1220 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
|
1221 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
|
1222 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1223 if (v->dquant) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1224 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1225 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
|
1226 vop_dquant_decoding(v); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1227 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1228 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1229 if (v->vstransform) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1230 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1231 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
|
1232 if (v->ttmbf) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1233 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1234 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
|
1235 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
|
1236 (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
|
1237 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1238 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1239 /* 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
|
1240 return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1241 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1242 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1243 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1244 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
|
1245 { |
2462 | 1246 int status = 0, index; |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1247 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1248 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
|
1249 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
|
1250 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
|
1251 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
|
1252 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
|
1253 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1254 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
|
1255 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
|
1256 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1257 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
|
1258 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1259 switch (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 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
|
1262 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
|
1263 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
|
1264 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
|
1265 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1266 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1267 if (status == FRAME_SKIPED) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1268 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1269 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
|
1270 return status; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1271 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1272 |
2462 | 1273 /* AC Syntax */ |
1274 index = decode012(&v->gb); | |
1275 v->luma_ac_vlc = NULL + index; //FIXME Add AC table | |
1276 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
|
1277 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
|
1278 { |
2462 | 1279 index = decode012(&v->gb); |
1280 v->luma_ac2_vlc = NULL + index; //FIXME Add AC2 table | |
1281 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
|
1282 } |
2462 | 1283 /* DC Syntax */ |
1284 index = decode012(&v->gb); | |
1285 v->luma_dc_vlc = vc9_luma_dc_vlc + index; | |
1286 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
|
1287 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1288 return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1289 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1290 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1291 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1292 #if HAS_ADVANCED_PROFILE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1293 /******************************************************************************/ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1294 /* 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
|
1295 /******************************************************************************/ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1296 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
|
1297 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1298 static const int type_table[4] = { P_TYPE, B_TYPE, I_TYPE, BI_TYPE }; |
2462 | 1299 int type, i, index; |
2445
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 if (v->interlace) |
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 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
|
1304 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
|
1305 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1306 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1307 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
|
1308 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
|
1309 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
|
1310 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
|
1311 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1312 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
|
1313 if (v->broadcast) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1314 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1315 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
|
1316 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1317 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1318 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
|
1319 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
|
1320 } |
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 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1323 if (v->panscanflag) |
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 #if 0 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1326 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
|
1327 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1328 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
|
1329 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
|
1330 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
|
1331 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
|
1332 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1333 #else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1334 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
|
1335 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1336 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1337 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
|
1338 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
|
1339 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
|
1340 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1341 switch(v->pict_type) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1342 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1343 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
|
1344 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
|
1345 case BI_TYPE: |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1346 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
|
1347 default: break; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1348 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1349 |
2462 | 1350 /* AC Syntax */ |
1351 index = decode012(&v->gb); | |
1352 v->luma_ac_vlc = NULL + index; //FIXME | |
1353 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
|
1354 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
|
1355 { |
2462 | 1356 index = decode012(&v->gb); //FIXME |
1357 v->luma_ac2_vlc = NULL + index; | |
1358 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
|
1359 } |
2462 | 1360 /* DC Syntax */ |
1361 index = decode012(&v->gb); | |
1362 v->luma_dc_vlc = vc9_luma_dc_vlc + index; | |
1363 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
|
1364 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1365 return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1366 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1367 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1368 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1369 /******************************************************************************/ |
2462 | 1370 /* Block decoding functions */ |
1371 /******************************************************************************/ | |
1372 /* 7.1.4, p91 and 8.1.1.7, p(1)04 */ | |
1373 /* FIXME proper integration (unusable and lots of parameters to send */ | |
1374 int decode_luma_intra_block(VC9Context *v, int mquant) | |
1375 { | |
1376 int dcdiff; | |
1377 | |
1378 dcdiff = get_vlc2(&v->gb, v->luma_dc_vlc->table, | |
2465
5565203c95ee
use dc tables from msmpeg4 instead of duplicating them patch by anonymous
michael
parents:
2464
diff
changeset
|
1379 VC9_DC_VLC_BITS, 2); |
2462 | 1380 if (dcdiff) |
1381 { | |
1382 if (dcdiff == 119 /* ESC index value */) | |
1383 { | |
1384 /* TODO: Optimize */ | |
1385 if (mquant == 1) dcdiff = get_bits(&v->gb, 10); | |
1386 else if (mquant == 2) dcdiff = get_bits(&v->gb, 9); | |
1387 else dcdiff = get_bits(&v->gb, 8); | |
1388 } | |
1389 else | |
1390 { | |
1391 if (mquant == 1) | |
1392 dcdiff = (dcdiff<<2) + get_bits(&v->gb, 2) - 3; | |
1393 else if (mquant == 2) | |
1394 dcdiff = (dcdiff<<1) + get_bits(&v->gb, 1) - 1; | |
1395 } | |
1396 if (get_bits(&v->gb, 1)) | |
1397 dcdiff = -dcdiff; | |
1398 } | |
1399 /* FIXME: 8.1.1.15, p(1)13, coeff scaling for Adv Profile */ | |
1400 | |
1401 return 0; | |
1402 } | |
1403 | |
1404 /******************************************************************************/ | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1405 /* MacroBlock decoding functions */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1406 /******************************************************************************/ |
2462 | 1407 /* 8.1.1.5, p(1)02-(1)03 */ |
1408 /* We only need to store 3 flags, but math with 4 is easier */ | |
1409 #define GET_CBPCY(table, bits) \ | |
1410 predicted_cbpcy = get_vlc2(&v->gb, table, bits, 2); \ | |
1411 cbpcy[0] = (p_cbpcy[-1] == p_cbpcy[2]) \ | |
1412 ? previous_cbpcy[1] : p_cbpcy[+2]; \ | |
1413 cbpcy[0] ^= ((predicted_cbpcy>>5)&0x01); \ | |
1414 cbpcy[1] = (p_cbpcy[2] == p_cbpcy[3]) ? cbpcy[0] : p_cbpcy[3]; \ | |
1415 cbpcy[1] ^= ((predicted_cbpcy>>4)&0x01); \ | |
1416 cbpcy[2] = (previous_cbpcy[1] == cbpcy[0]) \ | |
1417 ? previous_cbpcy[3] : cbpcy[0]; \ | |
1418 cbpcy[2] ^= ((predicted_cbpcy>>3)&0x01); \ | |
1419 cbpcy[3] = (cbpcy[1] == cbpcy[0]) ? cbpcy[2] : cbpcy[1]; \ | |
1420 cbpcy[3] ^= ((predicted_cbpcy>>2)&0x01); | |
1421 | |
1422 /* 8.1, p100 */ | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1423 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
|
1424 { |
2462 | 1425 int x, y, current_mb = 0; /* MB/Block Position info */ |
1426 int ac_pred; | |
1427 /* FIXME: better to use a pointer than using (x<<4) */ | |
1428 uint8_t cbpcy[4], previous_cbpcy[4], predicted_cbpcy, | |
1429 *p_cbpcy /* Pointer to skip some math */; | |
1430 | |
1431 /* Reset CBPCY predictors */ | |
1432 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
|
1433 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1434 /* 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
|
1435 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
|
1436 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
|
1437 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
|
1438 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1439 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
|
1440 { |
2462 | 1441 /* Init CBPCY for line */ |
1442 *((uint32_t*)previous_cbpcy) = 0x00000000; | |
1443 p_cbpcy = v->previous_line_cbpcy+4; | |
1444 | |
1445 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
|
1446 { |
2462 | 1447 /* Get CBPCY */ |
1448 GET_CBPCY(vc9_cbpcy_i_vlc.table, VC9_CBPCY_I_VLC_BITS); | |
1449 | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1450 ac_pred = get_bits(&v->gb, 1); |
2462 | 1451 |
1452 /* TODO: Decode blocks from that mb wrt cbpcy */ | |
1453 | |
1454 /* Update for next block */ | |
1455 *((uint32_t*)p_cbpcy) = *((uint32_t*)previous_cbpcy); | |
1456 *((uint32_t*)previous_cbpcy) = *((uint32_t*)cbpcy); | |
1457 current_mb++; | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1458 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1459 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1460 return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1461 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1462 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1463 #define GET_MQUANT() \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1464 if (v->dquantfrm) \ |
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 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
|
1467 { \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1468 if (v->dqbilevel) \ |
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 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
|
1471 } \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1472 else \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1473 { \ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1474 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
|
1475 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
|
1476 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
|
1477 } \ |
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 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1480 |
2462 | 1481 /* MVDATA decoding from 8.3.5.2, p(1)20 */ |
1482 #define GET_MVDATA(_dmv_x, _dmv_y) \ | |
1483 index = 1 + get_vlc2(&v->gb, v->mv_diff_vlc->table, \ | |
1484 VC9_MV_DIFF_VLC_BITS, 2); \ | |
1485 if (index > 36) \ | |
1486 { \ | |
1487 mb_has_coeffs = 1; \ | |
1488 index -= 37; \ | |
1489 } \ | |
1490 else mb_has_coeffs = 0; \ | |
1491 mb_is_intra = 0; \ | |
1492 if (!index) { _dmv_x = _dmv_y = 0; } \ | |
1493 else if (index == 35) \ | |
1494 { \ | |
1495 _dmv_x = get_bits(&v->gb, k_x); \ | |
1496 _dmv_y = get_bits(&v->gb, k_y); \ | |
1497 mb_is_intra = 1; \ | |
1498 } \ | |
1499 else \ | |
1500 { \ | |
1501 index1 = index%6; \ | |
1502 if (hpel_flag && index1 == 5) val = 1; \ | |
1503 else val = 0; \ | |
1504 val = get_bits(&v->gb, size_table[index1] - val); \ | |
1505 sign = 0 - (val&1); \ | |
1506 _dmv_x = (sign ^ ((val>>1) + offset_table[index1])) - sign; \ | |
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_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
|
1514 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1515 |
2462 | 1516 /* 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
|
1517 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
|
1518 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1519 int x, y, current_mb = 0, i; /* MB/Block Position info */ |
2462 | 1520 uint8_t cbpcy[4], previous_cbpcy[4], predicted_cbpcy, |
1521 *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
|
1522 int hybrid_pred, ac_pred; /* Prediction types */ |
2462 | 1523 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
|
1524 int mqdiff, mquant; /* MB quantization */ |
2462 | 1525 int ttmb; /* MB Transform type */ |
1526 | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1527 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
|
1528 offset_table[6] = { 0, 1, 3, 7, 15, 31 }; |
2462 | 1529 int mb_has_coeffs = 1 /* last_flag */, mb_is_intra; |
1530 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
|
1531 int k_x, k_y; /* Long MV fixed bitlength */ |
2462 | 1532 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
|
1533 int index, index1; /* LUT indices */ |
2462 | 1534 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
|
1535 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1536 /* 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
|
1537 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
|
1538 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
|
1539 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
|
1540 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1541 /* Select proper long MV range */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1542 switch (v->mvrange) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1543 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1544 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
|
1545 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
|
1546 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
|
1547 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
|
1548 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1549 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1550 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
|
1551 k_x -= hpel_flag; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1552 k_y -= hpel_flag; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1553 |
2462 | 1554 /* Reset CBPCY predictors */ |
1555 memset(v->previous_line_cbpcy, 0, (v->width_mb+1)<<2); | |
1556 | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1557 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
|
1558 { |
2462 | 1559 /* Init CBPCY for line */ |
1560 *((uint32_t*)previous_cbpcy) = 0x00000000; | |
1561 p_cbpcy = v->previous_line_cbpcy+4; | |
1562 | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1563 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
|
1564 { |
2462 | 1565 if (v->mv_type_mb_plane.is_raw) |
1566 v->mv_type_mb_plane.data[current_mb] = get_bits(&v->gb, 1); | |
1567 if (v->skip_mb_plane.is_raw) | |
1568 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
|
1569 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
|
1570 { |
2462 | 1571 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
|
1572 { |
2462 | 1573 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
|
1574 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1575 /* 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
|
1576 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
|
1577 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
|
1578 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
|
1579 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
|
1580 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1581 GET_MQUANT(); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1582 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
|
1583 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1584 else if (mb_has_coeffs) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1585 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1586 if (mb_is_intra) ac_pred = get_bits(&v->gb, 1); |
2462 | 1587 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
|
1588 GET_MQUANT(); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1589 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1590 if (!v->ttmbf) |
2462 | 1591 ttmb = get_vlc2(&v->gb, v->ttmb_vlc->table, |
1592 VC9_TTMB_VLC_BITS, 12); | |
1593 /* 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
|
1594 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1595 else //Skipped |
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 /* 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
|
1598 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
|
1599 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
|
1600 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
|
1601 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1602 } //1MV mode |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1603 else //4MV mode |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1604 { |
2462 | 1605 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
|
1606 { |
2462 | 1607 /* Get CBPCY */ |
1608 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
|
1609 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
|
1610 { |
2462 | 1611 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
|
1612 { |
2462 | 1613 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
|
1614 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1615 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
|
1616 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
|
1617 GET_MQUANT(); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1618 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
|
1619 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
|
1620 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
|
1621 if (!v->ttmbf) |
2462 | 1622 ttmb = get_vlc2(&v->gb, v->ttmb_vlc->table, |
1623 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
|
1624 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1625 /* TODO: Process blocks wrt cbpcy */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1626 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1627 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1628 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1629 else //Skipped MB |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1630 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1631 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
|
1632 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1633 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
|
1634 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
|
1635 |
2462 | 1636 /* TODO: do something */ |
2445
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 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1639 } |
2462 | 1640 |
1641 /* Update for next block */ | |
1642 #if TRACE > 2 | |
1643 av_log(v->avctx, AV_LOG_DEBUG, "Block %4i: p_cbpcy=%i%i%i%i, previous_cbpcy=%i%i%i%i," | |
1644 " cbpcy=%i%i%i%i\n", current_mb, | |
1645 p_cbpcy[0], p_cbpcy[1], p_cbpcy[2], p_cbpcy[3], | |
1646 previous_cbpcy[0], previous_cbpcy[1], previous_cbpcy[2], previous_cbpcy[3], | |
1647 cbpcy[0], cbpcy[1], cbpcy[2], cbpcy[3]); | |
1648 #endif | |
1649 *((uint32_t*)p_cbpcy) = *((uint32_t*)previous_cbpcy); | |
1650 *((uint32_t*)previous_cbpcy) = *((uint32_t*)cbpcy); | |
1651 current_mb++; | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1652 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1653 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1654 return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1655 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1656 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1657 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
|
1658 { |
2462 | 1659 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
|
1660 int ac_pred; |
2462 | 1661 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
|
1662 int mquant, mqdiff; /* MB quant stuff */ |
2462 | 1663 int ttmb; /* MacroBlock transform type */ |
1664 | |
1665 static const int size_table[6] = { 0, 2, 3, 4, 5, 8 }, | |
1666 offset_table[6] = { 0, 1, 3, 7, 15, 31 }; | |
1667 int mb_has_coeffs = 1 /* last_flag */, mb_is_intra = 1; | |
1668 int dmv1_x, dmv1_y, dmv2_x, dmv2_y; /* Differential MV components */ | |
1669 int k_x, k_y; /* Long MV fixed bitlength */ | |
1670 int hpel_flag; /* Some MB properties */ | |
1671 int index, index1; /* LUT indices */ | |
1672 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
|
1673 |
2462 | 1674 /* Select proper long MV range */ |
1675 switch (v->mvrange) | |
1676 { | |
1677 case 1: k_x = 10; k_y = 9; break; | |
1678 case 2: k_x = 12; k_y = 10; break; | |
1679 case 3: k_x = 13; k_y = 11; break; | |
1680 default: /*case 0 too */ k_x = 9; k_y = 8; break; | |
1681 } | |
1682 hpel_flag = v->mv_mode & 1; //MV_PMODE is HPEL | |
1683 k_x -= hpel_flag; | |
1684 k_y -= hpel_flag; | |
1685 | |
1686 /* Select ttmb table depending on pq */ | |
1687 if (v->pq < 5) v->ttmb_vlc = &vc9_ttmb_vlc[0]; | |
1688 else if (v->pq < 13) v->ttmb_vlc = &vc9_ttmb_vlc[1]; | |
1689 else v->ttmb_vlc = &vc9_ttmb_vlc[2]; | |
1690 | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1691 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
|
1692 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1693 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
|
1694 { |
2462 | 1695 if (v->direct_mb_plane.is_raw) |
1696 v->direct_mb_plane.data[current_mb] = get_bits(&v->gb, 1); | |
1697 if (v->skip_mb_plane.is_raw) | |
1698 v->skip_mb_plane.data[current_mb] = get_bits(&v->gb, 1); | |
1699 | |
1700 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
|
1701 { |
2462 | 1702 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
|
1703 { |
2462 | 1704 b_mv_type = decode012(&v->gb); |
1705 if (v->bfraction > 420 /*1/2*/ && | |
1706 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
|
1707 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1708 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1709 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1710 /* FIXME getting tired commenting */ |
2462 | 1711 GET_MVDATA(dmv1_x, dmv1_y); |
1712 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
|
1713 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1714 /* FIXME: actually read it */ |
2462 | 1715 b_mv_type = decode012(&v->gb); |
1716 if (v->bfraction > 420 /*1/2*/ && | |
1717 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
|
1718 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1719 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1720 } |
2462 | 1721 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
|
1722 { |
2462 | 1723 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
|
1724 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1725 GET_MQUANT(); |
2462 | 1726 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
|
1727 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
|
1728 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1729 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1730 { |
2462 | 1731 /* if bmv1 tells MVs are interpolated */ |
1732 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
|
1733 { |
2462 | 1734 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
|
1735 } |
2462 | 1736 /* GET_MVDATA has reset some stuff */ |
1737 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
|
1738 { |
2462 | 1739 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
|
1740 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
|
1741 GET_MQUANT(); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1742 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1743 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1744 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1745 //End1 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1746 if (v->ttmbf) |
2462 | 1747 ttmb = get_vlc2(&v->gb, v->ttmb_vlc->table, |
1748 VC9_TTMB_VLC_BITS, 12); | |
1749 | |
1750 //End2 | |
1751 for (i=0; i<6; i++) | |
1752 { | |
1753 /* FIXME: process the block */ | |
1754 } | |
1755 | |
1756 current_mb++; | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1757 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1758 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1759 return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1760 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1761 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1762 #if HAS_ADVANCED_PROFILE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1763 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
|
1764 { |
2462 | 1765 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
|
1766 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1767 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
|
1768 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1769 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
|
1770 { |
2462 | 1771 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
|
1772 ac_pred = get_bits(&v->gb, 1); |
2462 | 1773 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
|
1774 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
|
1775 GET_MQUANT(); |
2462 | 1776 |
1777 /* TODO: lots */ | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1778 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1779 current_mb++; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1780 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1781 return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1782 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1783 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1784 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1785 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
|
1786 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1787 VC9Context *v = avctx->priv_data; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1788 GetBitContext gb; |
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 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
|
1791 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
|
1792 v->avctx = 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 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
|
1795 |
2462 | 1796 avctx->coded_width = avctx->width; |
1797 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
|
1798 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
|
1799 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1800 int count = 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1801 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1802 // 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
|
1803 // 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
|
1804 // 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
|
1805 // samples we can decode |
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 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
|
1808 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1809 decode_sequence_header(avctx, &gb); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1810 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1811 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
|
1812 if (count>0) |
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 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
|
1815 count, get_bits(&gb, count)); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1816 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1817 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1818 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1819 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
|
1820 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1821 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1822 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1823 /* Done with header parsing */ |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1824 //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
|
1825 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
|
1826 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
|
1827 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1828 /* Allocate mb bitplanes */ |
2462 | 1829 if (alloc_bitplane(&v->mv_type_mb_plane, v->width_mb, v->height_mb) < 0) |
1830 return -1; | |
1831 if (alloc_bitplane(&v->mv_type_mb_plane, v->width_mb, v->height_mb) < 0) | |
1832 return -1; | |
1833 if (alloc_bitplane(&v->skip_mb_plane, v->width_mb, v->height_mb) < 0) | |
1834 return -1; | |
1835 if (alloc_bitplane(&v->direct_mb_plane, v->width_mb, v->height_mb) < 0) | |
1836 return -1; | |
1837 | |
1838 /* For predictors */ | |
1839 v->previous_line_cbpcy = (uint8_t *)av_malloc((v->width_mb+1)*4); | |
1840 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
|
1841 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1842 #if HAS_ADVANCED_PROFILE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1843 if (v->profile > PROFILE_MAIN) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1844 { |
2462 | 1845 if (alloc_bitplane(&v->over_flags_plane, v->width_mb, v->height_mb) < 0) |
1846 return -1; | |
1847 if (alloc_bitplane(&v->ac_pred_plane, v->width_mb, v->height_mb) < 0) | |
1848 return -1; | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1849 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1850 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1851 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1852 return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1853 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1854 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1855 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
|
1856 void *data, int *data_size, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1857 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
|
1858 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1859 VC9Context *v = avctx->priv_data; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1860 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
|
1861 AVFrame *pict = data; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1862 uint8_t *tmp_buf; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1863 v->avctx = avctx; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1864 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1865 //buf_size = 0 -> last frame |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1866 if (!buf_size) return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1867 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1868 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
|
1869 avctx->height); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1870 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
|
1871 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
|
1872 avctx->width, avctx->height); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1873 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1874 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
|
1875 { |
2462 | 1876 //No IDU |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1877 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
|
1878 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1879 #if HAS_ADVANCED_PROFILE |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1880 if (v->profile > PROFILE_MAIN) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1881 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1882 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
|
1883 switch(v->pict_type) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1884 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1885 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
|
1886 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
|
1887 case B_TYPE: |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1888 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
|
1889 default: ret = FRAME_SKIPED; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1890 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1891 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
|
1892 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1893 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1894 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1895 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1896 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
|
1897 switch(v->pict_type) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1898 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1899 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
|
1900 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
|
1901 case B_TYPE: |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1902 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
|
1903 default: ret = FRAME_SKIPED; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1904 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1905 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
|
1906 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1907 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1908 else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1909 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1910 #if 0 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1911 // search for IDU's |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1912 // FIXME |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1913 uint32_t scp = 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1914 int scs = 0, i = 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1915 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1916 while (i < buf_size) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1917 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1918 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
|
1919 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
|
1920 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1921 if (scp != 0x000001) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1922 break; // eof ? |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1923 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1924 scs = buf[i++]; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1925 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1926 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
|
1927 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1928 switch(scs) |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1929 { |
2462 | 1930 case 0x0A: //Sequence End Code |
1931 return 0; | |
1932 case 0x0B: //Slice Start Code | |
1933 av_log(avctx, AV_LOG_ERROR, "Slice coding not supported\n"); | |
1934 return -1; | |
1935 case 0x0C: //Field start code | |
1936 av_log(avctx, AV_LOG_ERROR, "Interlaced coding not supported\n"); | |
1937 return -1; | |
1938 case 0x0D: //Frame start code | |
1939 break; | |
1940 case 0x0E: //Entry point Start Code | |
1941 if (v->profile <= MAIN_PROFILE) | |
1942 av_log(avctx, AV_LOG_ERROR, | |
1943 "Found an entry point in profile %i\n", v->profile); | |
1944 advanced_entry_point_process(avctx, &v->gb); | |
1945 break; | |
1946 case 0x0F: //Sequence header Start Code | |
1947 decode_sequence_header(avctx, &v->gb); | |
1948 break; | |
1949 default: | |
1950 av_log(avctx, AV_LOG_ERROR, | |
1951 "Unsupported IDU suffix %lX\n", scs); | |
1952 } | |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1953 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1954 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
|
1955 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1956 #else |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1957 av_abort(); |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1958 #endif |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1959 } |
2462 | 1960 av_log(avctx, AV_LOG_DEBUG, "Consumed %i/%i bits\n", |
1961 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
|
1962 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1963 /* Fake consumption of all data */ |
2462 | 1964 *data_size = len; |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1965 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
|
1966 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1967 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1968 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
|
1969 { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1970 VC9Context *v = avctx->priv_data; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1971 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1972 #if HAS_ADVANCED_PROFILE |
2458
915094e3da5d
dont use several 100 mb memory for a tiny 120 element table
michael
parents:
2453
diff
changeset
|
1973 av_freep(&v->hrd_rate); |
915094e3da5d
dont use several 100 mb memory for a tiny 120 element table
michael
parents:
2453
diff
changeset
|
1974 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
|
1975 #endif |
2458
915094e3da5d
dont use several 100 mb memory for a tiny 120 element table
michael
parents:
2453
diff
changeset
|
1976 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
|
1977 av_freep(&v->skip_mb_plane); |
915094e3da5d
dont use several 100 mb memory for a tiny 120 element table
michael
parents:
2453
diff
changeset
|
1978 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
|
1979 return 0; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1980 } |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1981 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1982 AVCodec vc9_decoder = { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1983 "vc9", |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1984 CODEC_TYPE_VIDEO, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1985 CODEC_ID_VC9, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1986 sizeof(VC9Context), |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1987 vc9_decode_init, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1988 NULL, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1989 vc9_decode_end, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1990 vc9_decode_frame, |
2453 | 1991 CODEC_CAP_DELAY, |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1992 NULL |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1993 }; |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1994 |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1995 AVCodec wmv3_decoder = { |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1996 "wmv3", |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1997 CODEC_TYPE_VIDEO, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1998 CODEC_ID_WMV3, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
1999 sizeof(VC9Context), |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
2000 vc9_decode_init, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
2001 NULL, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
2002 vc9_decode_end, |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
2003 vc9_decode_frame, |
2453 | 2004 CODEC_CAP_DELAY, |
2445
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
2005 NULL |
96da66323faa
preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff
changeset
|
2006 }; |