annotate vc9.c @ 2476:38dbec9a148d libavcodec

100000l (typos in the #define for selecting the NORM6 method -> wasnt compiled, after fixing typos new method doesnt even compile -> swicth back to old until its fixed)
author michael
date Sun, 30 Jan 2005 22:28:11 +0000
parents db05cb59c6fc
children 5d28ea40fd98
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
michael
parents: 2461
diff changeset
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"
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
35
2476
38dbec9a148d 100000l (typos in the #define for selecting the NORM6 method -> wasnt compiled, after fixing typos new method doesnt even compile -> swicth back to old until its fixed)
michael
parents: 2475
diff changeset
36 #undef NDEBUG
38dbec9a148d 100000l (typos in the #define for selecting the NORM6 method -> wasnt compiled, after fixing typos new method doesnt even compile -> swicth back to old until its fixed)
michael
parents: 2475
diff changeset
37 #include <assert.h>
38dbec9a148d 100000l (typos in the #define for selecting the NORM6 method -> wasnt compiled, after fixing typos new method doesnt even compile -> swicth back to old until its fixed)
michael
parents: 2475
diff changeset
38
2465
5565203c95ee use dc tables from msmpeg4 instead of duplicating them patch by anonymous
michael
parents: 2464
diff changeset
39 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
40 extern const uint32_t ff_table0_dc_chroma[120][2], ff_table1_dc_chroma[120][2];
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
41 extern VLC ff_msmp4_dc_luma_vlc[2], ff_msmp4_dc_chroma_vlc[2];
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
42 #define MB_INTRA_VLC_BITS 9
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
43 extern VLC ff_msmp4_mb_i_vlc;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
44 #define DC_VLC_BITS 9
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
45 static const uint16_t table_mb_intra[64][2];
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
46
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
47 /* Some inhibiting stuff */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
48 #define HAS_ADVANCED_PROFILE 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
49 #define TRACE 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 #if TRACE
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 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
55 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
56 { \
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
57 av_log(v->s.avctx, AV_LOG_ERROR, "Error for " # vlc " (%i)\n", i); \
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
58 return -1; \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
59 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
60 #else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
61 # 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
62 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
63 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
64 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
65 #endif
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 #define PROFILE_SIMPLE 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
68 #define PROFILE_MAIN 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
69 #define PROFILE_ADVANCED 3
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
70
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
71 #define QUANT_FRAME_IMPLICIT 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
72 #define QUANT_FRAME_EXPLICIT 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
73 #define QUANT_NON_UNIFORM 2
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
74 #define QUANT_UNIFORM 3
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
75
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
76 /* Where quant can be changed */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
77 #define DQPROFILE_FOUR_EDGES 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
78 #define DQPROFILE_DOUBLE_EDGES 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
79 #define DQPROFILE_SINGLE_EDGE 2
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
80 #define DQPROFILE_ALL_MBS 3
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
81
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
82 /* 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
83 #define DQSINGLE_BEDGE_LEFT 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
84 #define DQSINGLE_BEDGE_TOP 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
85 #define DQSINGLE_BEDGE_RIGHT 2
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
86 #define DQSINGLE_BEDGE_BOTTOM 3
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
87
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
88 /* 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
89 #define DQDOUBLE_BEDGE_TOPLEFT 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
90 #define DQDOUBLE_BEDGE_TOPRIGHT 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
91 #define DQDOUBLE_BEDGE_BOTTOMRIGHT 2
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
92 #define DQDOUBLE_BEDGE_BOTTOMLEFT 3
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
93
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
94 /* MV P modes */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
95 #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
96 #define MV_PMODE_1MV 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
97 #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
98 #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
99 #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
100
2462
michael
parents: 2461
diff changeset
101 #define BMV_TYPE_BACKWARD 0
michael
parents: 2461
diff changeset
102 #define BMV_TYPE_FORWARD 1
michael
parents: 2461
diff changeset
103 #define BMV_TYPE_INTERPOLATED 3
michael
parents: 2461
diff changeset
104
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
105 /* 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
106 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
107 { 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
108 { 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
109 };
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
110
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
111 /* One more frame type */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
112 #define BI_TYPE 7
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
113
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
114 /* FIXME Worse than ugly */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
115 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
116 fps_dr[2] = { 1000, 1001 };
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
117 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
118 { /* Implicit quantizer */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
119 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
120 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
121 },
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
122 { /* Explicit quantizer, pquantizer uniform */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
123 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
124 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
125 },
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
126 { /* Explicit quantizer, pquantizer non-uniform */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
127 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
128 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
129 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
130 };
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
131
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
132 // 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
133 #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
134 static VLC vc9_bfraction_vlc;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
135 #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
136 static VLC vc9_imode_vlc;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
137 #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
138 static VLC vc9_norm2_vlc;
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
139 #if TILE_VLC_METHOD == 1
2460
42077bb89a53 norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents: 2459
diff changeset
140 #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
141 static VLC vc9_norm6_vlc;
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
142 #endif
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
143 #if TILE_VLC_METHOD == 2
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
144 #define VC9_NORM6_FIRST_BITS 8
2476
38dbec9a148d 100000l (typos in the #define for selecting the NORM6 method -> wasnt compiled, after fixing typos new method doesnt even compile -> swicth back to old until its fixed)
michael
parents: 2475
diff changeset
145 #define VC9_NORM6_SECOND_BITS 8
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
146 static VLC vc9_norm6_first, vc9_norm6_second;
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
147 #endif
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
148 /* Could be optimized, one table only needs 8 bits */
2462
michael
parents: 2461
diff changeset
149 #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
150 static VLC vc9_ttmb_vlc[3];
2462
michael
parents: 2461
diff changeset
151 #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
152 static VLC vc9_mv_diff_vlc[4];
2462
michael
parents: 2461
diff changeset
153 #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
154 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
155 #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
156 static VLC vc9_4mv_block_pattern_vlc[4];
2462
michael
parents: 2461
diff changeset
157
michael
parents: 2461
diff changeset
158 //We mainly need data and is_raw, so this struct could be avoided
michael
parents: 2461
diff changeset
159 //to save a level of indirection; feel free to modify
michael
parents: 2461
diff changeset
160 typedef struct BitPlane {
michael
parents: 2461
diff changeset
161 uint8_t *data;
michael
parents: 2461
diff changeset
162 int width, stride;
michael
parents: 2461
diff changeset
163 int height;
michael
parents: 2461
diff changeset
164 uint8_t is_raw;
michael
parents: 2461
diff changeset
165 } BitPlane;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
166
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
167 typedef struct VC9Context{
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
168 /* No MpegEnc context, might be good to use it */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
169 MpegEncContext s;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
170
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
171 /***************************/
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
172 /* Sequence Header */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
173 /***************************/
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
174 /* Simple/Main Profile */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
175 int res_sm; //reserved, 2b
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
176 int res_x8; //reserved
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
177 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
178 int res_fasttx; //always 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
179 int res_transtab; //always 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
180 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
181 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
182 int reserved; //duh
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
183
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
184 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
185 /* Advanced Profile */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
186 int level; //3
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
187 int chromaformat; //2
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
188 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
189 int broadcast; //TFF/RFF present
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
190 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
191 int tfcntrflag; //TFCNTR present
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
192 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
193 int extended_dmv;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
194 int color_prim; //8
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
195 int transfer_char; //8
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
196 int matrix_coef; //8
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
197 int hrd_param_flag;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
198 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
199
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
200 /* All Profiles */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
201 /* 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
202 int profile; //2
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
203 int frmrtq_postproc; //3
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
204 int bitrtq_postproc; //5
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
205 int loopfilter;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
206 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
207 int extended_mv; //Ext MV in P/B (not in Simple)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
208 int dquant; //How qscale varies with MBs, 2bits (not in Simple)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
209 int vstransform; //variable-size transform46
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
210
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
211
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
212 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
213 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
214 int finterpflag; //INTERPFRM present
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
215
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
216
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
217 /*****************************/
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
218 /* Frame decoding */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
219 /*****************************/
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
220 /* All profiles */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
221 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
222 uint8_t pq, altpq; /* Quantizers */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
223 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
224 int tile; /* 3x2 if (width_mb%3) else 2x3 */
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
225 int ac_table_level;
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
226 VLC *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
227 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
228 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
229 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
230 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
231 uint8_t respic;
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
232 int buffer_fullness; /* For HRD ? */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
233 /* Ranges:
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
234 * 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
235 * 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
236 * 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
237 * 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
238 */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
239 uint8_t mvrange;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
240 uint8_t pquantizer;
2462
michael
parents: 2461
diff changeset
241 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
242 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
243 *ttmb_vlc /* Current MB Transform Type VLC table */;
2462
michael
parents: 2461
diff changeset
244 BitPlane mv_type_mb_plane; /* bitplane for mv_type == (4MV) */
michael
parents: 2461
diff changeset
245 BitPlane skip_mb_plane, /* bitplane for skipped MBs */
michael
parents: 2461
diff changeset
246 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
247
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
248 /* S/M only ? */
2462
michael
parents: 2461
diff changeset
249 uint8_t rangeredfrm; /* out_sample = CLIP((in_sample-128)*2+128) */
michael
parents: 2461
diff changeset
250 uint8_t interpfrm;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
251
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
252 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
253 /* Advanced */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
254 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
255 uint8_t numpanscanwin;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
256 uint8_t tfcntr;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
257 uint8_t rptfrm, tff, rff;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
258 uint8_t topleftx;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
259 uint8_t toplefty;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
260 uint8_t bottomrightx;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
261 uint8_t bottomrighty;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
262 uint8_t uvsamp;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
263 uint8_t postproc;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
264 int hrd_num_leaky_buckets;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
265 uint8_t bit_rate_exponent;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
266 uint8_t buffer_size_exponent;
2462
michael
parents: 2461
diff changeset
267 BitPlane ac_pred_plane; //AC prediction flags bitplane
michael
parents: 2461
diff changeset
268 BitPlane over_flags_plane; //Overflags bitplane
michael
parents: 2461
diff changeset
269 uint8_t condover;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
270 uint16_t *hrd_rate, *hrd_buffer;
2462
michael
parents: 2461
diff changeset
271 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
272 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
273 } VC9Context;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
274
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
275 /* FIXME Slow and ugly */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
276 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
277 {
2462
michael
parents: 2461
diff changeset
278 #if 1
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
279 int i = 0, tmp = !stop;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
280
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
281 while (i != len && tmp != stop)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
282 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
283 tmp = get_bits(gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
284 i++;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
285 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
286 return i;
2462
michael
parents: 2461
diff changeset
287 #else
michael
parents: 2461
diff changeset
288 unsigned int buf;
michael
parents: 2461
diff changeset
289 int log;
michael
parents: 2461
diff changeset
290
michael
parents: 2461
diff changeset
291 OPEN_READER(re, gb);
michael
parents: 2461
diff changeset
292 UPDATE_CACHE(re, gb);
michael
parents: 2461
diff changeset
293 buf=GET_CACHE(re, gb); //Still not sure
michael
parents: 2461
diff changeset
294 if (stop) buf = ~buf;
michael
parents: 2461
diff changeset
295
michael
parents: 2461
diff changeset
296 log= av_log2(-buf); //FIXME: -?
michael
parents: 2461
diff changeset
297 if (log < limit){
michael
parents: 2461
diff changeset
298 LAST_SKIP_BITS(re, gb, log+1);
michael
parents: 2461
diff changeset
299 CLOSE_READER(re, gb);
michael
parents: 2461
diff changeset
300 return log;
michael
parents: 2461
diff changeset
301 }
michael
parents: 2461
diff changeset
302
michael
parents: 2461
diff changeset
303 LAST_SKIP_BITS(re, gb, limit);
michael
parents: 2461
diff changeset
304 CLOSE_READER(re, gb);
michael
parents: 2461
diff changeset
305 return limit;
michael
parents: 2461
diff changeset
306 #endif
michael
parents: 2461
diff changeset
307 }
michael
parents: 2461
diff changeset
308
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
309 static int vc9_init_common(VC9Context *v)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
310 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
311 static int done = 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
312 int i;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
313
2462
michael
parents: 2461
diff changeset
314 /* Set the bit planes */
michael
parents: 2461
diff changeset
315 /* FIXME memset better ? (16bytes) */
michael
parents: 2461
diff changeset
316 v->mv_type_mb_plane = (struct BitPlane) { NULL, 0, 0, 0 };
michael
parents: 2461
diff changeset
317 v->direct_mb_plane = (struct BitPlane) { NULL, 0, 0, 0 };
michael
parents: 2461
diff changeset
318 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
319 #if HAS_ADVANCED_PROFILE
2462
michael
parents: 2461
diff changeset
320 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
321 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
322 #endif
2462
michael
parents: 2461
diff changeset
323
michael
parents: 2461
diff changeset
324 /* VLC tables */
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
325 #if TILE_VLC_METHOD == 1
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
326 # if 0 // spec -> actual tables converter
2460
42077bb89a53 norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents: 2459
diff changeset
327 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
328 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
329 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
330 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
331 }
42077bb89a53 norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents: 2459
diff changeset
332 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
333 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
334 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
335 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
336 }
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
337 # endif
2460
42077bb89a53 norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents: 2459
diff changeset
338 #endif
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
339 if(!done)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
340 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
341 done = 1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
342 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
343 vc9_bfraction_bits, 1, 1,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
344 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
345 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
346 vc9_norm2_bits, 1, 1,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
347 vc9_norm2_codes, 1, 1, 1);
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
348 #if TILE_VLC_METHOD == 1
2460
42077bb89a53 norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents: 2459
diff changeset
349 INIT_VLC(&vc9_norm6_vlc, VC9_NORM6_VLC_BITS, 64,
42077bb89a53 norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents: 2459
diff changeset
350 vc9_norm6_bits, 1, 1,
42077bb89a53 norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents: 2459
diff changeset
351 vc9_norm6_codes, 2, 2, 1);
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
352 #endif
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
353 #if TILE_VLC_METHOD == 2
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
354 INIT_VLC(&vc9_norm6_first, VC9_NORM6_FIRST_BITS, 64,
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
355 &vc9_norm6_first[0][1], 1, 1,
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
356 &vc9_norm6_first[0][0], 1, 1, 1);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
357 INIT_VLC(&vc9_norm6_second, VC9_NORM6_SECOND_BITS, 64,
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
358 vc9_norm6_second[0][1], 1, 1,
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
359 vc9_norm6_second[0][1], 1, 1, 1);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
360 #endif
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
361 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
362 vc9_imode_bits, 1, 1,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
363 vc9_imode_codes, 1, 1, 1);
2462
michael
parents: 2461
diff changeset
364 for (i=0; i<3; i++)
michael
parents: 2461
diff changeset
365 {
michael
parents: 2461
diff changeset
366 INIT_VLC(&vc9_ttmb_vlc[i], VC9_TTMB_VLC_BITS, 16,
michael
parents: 2461
diff changeset
367 vc9_ttmb_bits[i], 1, 1,
michael
parents: 2461
diff changeset
368 vc9_ttmb_codes[i], 2, 2, 1);
michael
parents: 2461
diff changeset
369 }
michael
parents: 2461
diff changeset
370 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
371 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
372 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
373 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
374 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
375 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
376 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
377 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
378 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
379 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
380 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
381 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
382 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
383
2462
michael
parents: 2461
diff changeset
384 /* Other defaults */
michael
parents: 2461
diff changeset
385 v->pq = -1;
michael
parents: 2461
diff changeset
386 v->mvrange = 0; /* 7.1.1.18, p80 */
michael
parents: 2461
diff changeset
387
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
388 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
389 }
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 #if HAS_ADVANCED_PROFILE
2462
michael
parents: 2461
diff changeset
392 /* 6.2.1, p32 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
393 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
394 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
395 int i, num;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
396
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
397 num = get_bits(gb, 5);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
398
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
399 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
400 {
2458
915094e3da5d dont use several 100 mb memory for a tiny 120 element table
michael
parents: 2453
diff changeset
401 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
402 }
2462
michael
parents: 2461
diff changeset
403 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
404 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
405
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
406 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
407 {
2458
915094e3da5d dont use several 100 mb memory for a tiny 120 element table
michael
parents: 2453
diff changeset
408 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
409 }
2462
michael
parents: 2461
diff changeset
410 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
411 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
412
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
413 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
414
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
415 //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
416 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
417 //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
418 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
419
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
420 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
421 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
422 //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
423 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
424 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
425 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
426 av_log(v->s.avctx, AV_LOG_ERROR, "HDR Rates aren't strictly increasing:"
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
427 "%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
428 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
429 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
430 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
431 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
432 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
433 av_log(v->s.avctx, AV_LOG_ERROR, "HDR Buffers aren't decreasing:"
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
434 "%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
435 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
436 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
437 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
438 return 0;
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
2462
michael
parents: 2461
diff changeset
441 /* Table 2, p18 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
442 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
443 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
444 VC9Context *v = avctx->priv_data;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
445 int nr, dr, aspect_ratio;
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->postprocflag = 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->broadcast = get_bits(gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
449 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
450
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
451 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
452 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
453 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
454 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
455 if (v->reserved)
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 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
458 v->reserved);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
459 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
460 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
461 if (v->extended_mv)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
462 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
463
2462
michael
parents: 2461
diff changeset
464 /* 6.1.7, p21 */
2445
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) /* pic_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->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
468 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
469 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
470 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
471 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
472 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
473 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
474
2462
michael
parents: 2461
diff changeset
475 /* 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
476 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
477 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
478 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
479 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
480 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
481 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
482 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
483 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
484 else if (aspect_ratio == 0x0E)
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 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
487 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
488 else
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 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
491 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
492 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
493 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
494 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
495 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
496 avctx->coded_width = avctx->width;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
497 avctx->coded_height = avctx->height;
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
2462
michael
parents: 2461
diff changeset
500 /* 6.1.8, p23 */
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
501 if ( !get_bits(gb, 1) /* framerateflag */)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
502 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
503 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
504 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
505 nr = get_bits(gb, 8);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
506 dr = get_bits(gb, 4);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
507 if (nr<1)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
508 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
509 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
510 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
511 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
512 if (nr>5)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
513 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
514 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
515 "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
516 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
517 if (dr<1)
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, "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
520 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
521 if (dr>2)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
522 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
523 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
524 "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
525 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
526 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
527 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
528 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
529 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
530 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
531 nr = get_bits(gb, 16);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
532 // 0.03125->2048Hz / 0.03125Hz
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
533 avctx->frame_rate = 1000000;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
534 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
535 }
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
2462
michael
parents: 2461
diff changeset
538 /* 6.1.9, p25 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
539 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
540 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
541 //Chromacity coordinates of color primaries
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
542 //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
543 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
544 if (v->color_prim<1)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
545 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
546 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
547 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
548 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
549 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
550 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
551 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
552 v->color_prim);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
553 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
554 }
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 //Opto-electronic transfer characteristics
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
557 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
558 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
559 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
560 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
561 v->color_prim);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
562 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
563 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
564
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
565 //Matrix coefficient for primariev->YCbCr
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
566 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
567 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
568 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
569 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
570 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
571 v->color_prim);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
572 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
573 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
574 }
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 //Hypothetical reference decoder indicator flag
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
577 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
578 if (v->hrd_param_flag)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
579 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
580 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
581 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
582
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
583 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
584 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
585 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
586 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
587
2462
michael
parents: 2461
diff changeset
588 /* 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
589 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
590 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
591 VC9Context *v = avctx->priv_data;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
592
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
593 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
594 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
595
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
596 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
597 if (v->profile > PROFILE_MAIN)
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 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
600 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
601 if (v->chromaformat != 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 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
604 "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
605 return -1;
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 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
608 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
609 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
610 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
611 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
612 if (v->res_sm)
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 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
615 "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
616 //return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
617 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
618 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
619
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
620 // (fps-2)/4 (->30)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
621 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
622 // (bitrate-32kbps)/64kbps
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
623 v->bitrtq_postproc = get_bits(gb, 5); //common
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
624 v->s.loop_filter = get_bits(gb, 1); //common
2445
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 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
627 if (v->profile <= PROFILE_MAIN)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
628 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
629 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
630 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
631 if (v->res_x8)
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 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
634 "1 for reserved RES_X8 is forbidden\n");
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
635 //return -1;
2445
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 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
638 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
639 if (!v->res_fasttx)
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 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
642 "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
643 //return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
644 }
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
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
647 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
648 if (!v->profile && !v->fastuvmc)
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 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
651 "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
652 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
653 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
654 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
655 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
656 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
657 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
658 "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
659 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
660 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
661 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
662 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
663
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
664 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
665 if (v->profile <= PROFILE_MAIN)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
666 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
667 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
668 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
669 if (v->res_transtab)
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 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
672 "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
673 return -1;
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 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
676
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
677 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
678
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
679 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
680 if (v->profile <= PROFILE_MAIN)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
681 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
682 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
683 v->s.resync_marker = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
684 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
685 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
686
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
687 v->s.max_b_frames = avctx->max_b_frames = get_bits(gb, 3); //common
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
688 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
689
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
690 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
691 if (v->profile <= PROFILE_MAIN)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
692 #endif
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 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
695 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
696 if (!v->res_rtm_flag)
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 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
699 "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
700 //return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
701 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
702 #if TRACE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
703 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
704 "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
705 "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
706 "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
707 "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
708 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
709 v->loopfilter, v->multires, v->fastuvmc, v->extended_mv,
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
710 v->rangered, v->vstransform, v->overlap, v->s.resync_marker,
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
711 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
712 );
2462
michael
parents: 2461
diff changeset
713 return 0;
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 #if HAS_ADVANCED_PROFILE
2462
michael
parents: 2461
diff changeset
717 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
718 #endif
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
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 #if HAS_ADVANCED_PROFILE
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 /* Entry point decoding (Advanced Profile) */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
725 /*****************************************************************************/
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
726 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
727 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
728 VC9Context *v = avctx->priv_data;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
729 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
730 if (v->profile != PROFILE_ADVANCED)
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 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
733 "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
734 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
735 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
736 if (v->hrd_param_flag)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
737 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
738 //Update buffer fullness
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
739 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
740 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
741 skip_bits(gb, 8);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
742 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
743 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
744 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
745 //RANGE_MAPY
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
746 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
747 skip_bits(gb, 3);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
748 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
749 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
750 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
751 //RANGE_MAPUV
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
752 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
753 skip_bits(gb, 3);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
754 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
755 if (v->panscanflag)
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 //NUMPANSCANWIN
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
758 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
759 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
760 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
761 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
762 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
763 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
764
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
765 /******************************************************************************/
2462
michael
parents: 2461
diff changeset
766 /* 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
767 /******************************************************************************/
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
768 #define IMODE_RAW 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
769 #define IMODE_NORM2 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
770 #define IMODE_DIFF2 2
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
771 #define IMODE_NORM6 3
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
772 #define IMODE_DIFF6 4
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
773 #define IMODE_ROWSKIP 5
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
774 #define IMODE_COLSKIP 6
2462
michael
parents: 2461
diff changeset
775 int alloc_bitplane(BitPlane *bp, int width, int height)
michael
parents: 2461
diff changeset
776 {
michael
parents: 2461
diff changeset
777 if (!bp || bp->width<0 || bp->height<0) return -1;
michael
parents: 2461
diff changeset
778 bp->data = (uint8_t*)av_malloc(width*height);
michael
parents: 2461
diff changeset
779 if (!bp->data) return -1;
michael
parents: 2461
diff changeset
780 bp->width = bp->stride = width; //FIXME Needed for aligned data ?
michael
parents: 2461
diff changeset
781 bp->height = height;
michael
parents: 2461
diff changeset
782 return 0;
michael
parents: 2461
diff changeset
783 }
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
784
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
785 void free_bitplane(BitPlane *bp)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
786 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
787 bp->width = bp->stride = bp->height = 0;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
788 if (bp->data) av_freep(&bp->data);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
789 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
790
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
791 static void decode_rowskip(uint8_t* plane, int width, int height, int stride, VC9Context *v){
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
792 int x, y;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
793 GetBitContext *gb = &v->s.gb;
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
794
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
795 for (y=0; y<height; y++){
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
796 if (!get_bits(gb, 1)) //rowskip
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
797 memset(plane, 0, width);
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
798 else
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
799 for (x=0; x<width; x++)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
800 plane[x] = get_bits(gb, 1);
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
801 plane += stride;
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
802 }
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
803 }
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
804
2460
42077bb89a53 norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents: 2459
diff changeset
805 //FIXME optimize
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
806 static void decode_colskip(uint8_t* plane, int width, int height, int stride, VC9Context *v){
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
807 int x, y;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
808 GetBitContext *gb = &v->s.gb;
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
809
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
810 for (x=0; x<width; x++){
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
811 if (!get_bits(gb, 1)) //colskip
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
812 for (y=0; y<height; y++)
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
813 plane[y*stride] = 0;
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
814 else
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
815 for (y=0; y<height; y++)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
816 plane[y*stride] = get_bits(gb, 1);
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
817 plane ++;
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
818 }
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
819 }
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
820
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
821 //FIXME optimize
2462
michael
parents: 2461
diff changeset
822 //FIXME Use BitPlane struct or return if table is raw (no bits read here but
michael
parents: 2461
diff changeset
823 // later on)
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
824 //Elements must be either 0 or 1
2462
michael
parents: 2461
diff changeset
825 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
826 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
827 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
828
2462
michael
parents: 2461
diff changeset
829 int imode, x, y, code, use_vertical_tile, tile_w, tile_h;
michael
parents: 2461
diff changeset
830 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
831
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
832 invert = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
833 imode = get_vlc2(gb, vc9_imode_vlc.table, VC9_IMODE_VLC_BITS, 2);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
834
2462
michael
parents: 2461
diff changeset
835 bp->is_raw = 0;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
836 switch (imode)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
837 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
838 case IMODE_RAW:
2462
michael
parents: 2461
diff changeset
839 //Data is actually read in the MB layer (same for all tests == "raw")
michael
parents: 2461
diff changeset
840 bp->is_raw = 1; //invert ignored
michael
parents: 2461
diff changeset
841 return invert;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
842 case IMODE_DIFF2:
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
843 case IMODE_NORM2:
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
844 if ((bp->height*bp->width) & 1) *(++planep) = get_bits(gb, 1);
2462
michael
parents: 2461
diff changeset
845 for(x=0; x<(bp->height*bp->width)>>1; x++){
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
846 code = get_vlc2(gb, vc9_norm2_vlc.table, VC9_NORM2_VLC_BITS, 2);
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
847 *(++planep) = code&1; //lsb => left
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
848 *(++planep) = (code>>1)&1; //msb => right
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
849 //FIXME width->stride
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
850 }
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
851 break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
852 case IMODE_DIFF6:
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
853 case IMODE_NORM6:
2462
michael
parents: 2461
diff changeset
854 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
855 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
856 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
857
2462
michael
parents: 2461
diff changeset
858 for(y= bp->height%tile_h; y< bp->height; y+=tile_h){
michael
parents: 2461
diff changeset
859 for(x= bp->width%tile_w; x< bp->width; x+=tile_w){
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
860 #if TILE_VLC_METHOD == 1 //FIXME Too much optimized ?
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
861 code = get_vlc2(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
862 if(code<0){
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
863 av_log(v->s.avctx, AV_LOG_DEBUG, "inavlid NORM-6 VLC\n");
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
864 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
865 }
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
866 #endif
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
867 #if TILE_VLC_METHOD == 2 //TODO Optimize VLC decoding
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
868 code = get_vlc2(gb, vc9_norm6_first.table, VC9_NORM6_FIRST_BITS, 2);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
869 if (vc9_norm6_mode[code] == 1)
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
870 {
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
871 # if TRACE
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
872 code = get_bits(gb, 5);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
873 assert(code>-1 && code<20);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
874 code = vc9_norm6_flc_val[code];
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
875 # else
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
876 code = vc9_norm6_flc_val[get_bits(gb, 5)];
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
877 # endif
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
878 }
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
879 else if (vc9_norm6_mode[code] == 2)
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
880 {
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
881 # if TRACE
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
882 code = get_vlc2(gb, vc9_norm6_second.table, VC9_NORM6_SECOND_BITS, 2);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
883 assert(code>-1 && code<22);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
884 code = vc9_norm6_second_val[code];
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
885 # else
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
886 code = vc9_norm6_second_val[get_vlc2(gb, vc9_norm6_second.table, VC9_NORM6_SECOND_BITS, 2)];
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
887 # endif
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
888 #endif //TILE_VLC_METHOD == 2
2460
42077bb89a53 norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents: 2459
diff changeset
889 //FIXME following is a pure guess and probably wrong
2462
michael
parents: 2461
diff changeset
890 //FIXME A bitplane (0 | !0), so could the shifts be avoided ?
michael
parents: 2461
diff changeset
891 planep[x + 0*bp->stride]= (code>>0)&1;
michael
parents: 2461
diff changeset
892 planep[x + 1 + 0*bp->stride]= (code>>1)&1;
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
893 //FIXME Does branch prediction help here?
2460
42077bb89a53 norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents: 2459
diff changeset
894 if(use_vertical_tile){
2462
michael
parents: 2461
diff changeset
895 planep[x + 0 + 1*bp->stride]= (code>>2)&1;
michael
parents: 2461
diff changeset
896 planep[x + 1 + 1*bp->stride]= (code>>3)&1;
michael
parents: 2461
diff changeset
897 planep[x + 0 + 2*bp->stride]= (code>>4)&1;
michael
parents: 2461
diff changeset
898 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
899 }else{
2462
michael
parents: 2461
diff changeset
900 planep[x + 2 + 0*bp->stride]= (code>>2)&1;
michael
parents: 2461
diff changeset
901 planep[x + 0 + 1*bp->stride]= (code>>3)&1;
michael
parents: 2461
diff changeset
902 planep[x + 1 + 1*bp->stride]= (code>>4)&1;
michael
parents: 2461
diff changeset
903 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
904 }
42077bb89a53 norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents: 2459
diff changeset
905 }
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
906 }
2460
42077bb89a53 norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents: 2459
diff changeset
907
2462
michael
parents: 2461
diff changeset
908 x= bp->width % tile_w;
michael
parents: 2461
diff changeset
909 decode_colskip(bp->data , x, bp->height , bp->stride, v);
michael
parents: 2461
diff changeset
910 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
911
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
912 break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
913 case IMODE_ROWSKIP:
2462
michael
parents: 2461
diff changeset
914 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
915 break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
916 case IMODE_COLSKIP: //Teh ugly
2462
michael
parents: 2461
diff changeset
917 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
918 break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
919 default: break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
920 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
921
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
922 /* Applying diff operator */
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
923 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
924 {
2462
michael
parents: 2461
diff changeset
925 planep = bp->data;
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
926 planep[0] ^= invert;
2462
michael
parents: 2461
diff changeset
927 for (x=1; x<bp->width; x++)
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
928 planep[x] ^= planep[x-1];
2462
michael
parents: 2461
diff changeset
929 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
930 {
2462
michael
parents: 2461
diff changeset
931 planep += bp->stride;
michael
parents: 2461
diff changeset
932 planep[0] ^= planep[-bp->stride];
michael
parents: 2461
diff changeset
933 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
934 {
2462
michael
parents: 2461
diff changeset
935 if (planep[x-1] != planep[x-bp->stride]) planep[x] ^= invert;
michael
parents: 2461
diff changeset
936 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
937 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
938 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
939 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
940 else if (invert)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
941 {
2462
michael
parents: 2461
diff changeset
942 planep = bp->data;
michael
parents: 2461
diff changeset
943 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
944 }
2462
michael
parents: 2461
diff changeset
945 return (imode<<1) + invert;
2445
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 /*****************************************************************************/
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
949 /* VOP Dquant decoding */
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 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
952 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
953 GetBitContext *gb = &v->s.gb;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
954 int pqdiff;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
955
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
956 //variable size
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
957 if (v->dquant == 2)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
958 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
959 pqdiff = get_bits(gb, 3);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
960 if (pqdiff == 7) v->altpq = get_bits(gb, 5);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
961 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
962 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
963 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
964 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
965 v->dquantfrm = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
966 if ( v->dquantfrm )
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
967 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
968 v->dqprofile = get_bits(gb, 2);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
969 switch (v->dqprofile)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
970 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
971 case DQPROFILE_SINGLE_EDGE:
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
972 case DQPROFILE_DOUBLE_EDGES:
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
973 v->dqsbedge = get_bits(gb, 2);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
974 break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
975 case DQPROFILE_ALL_MBS:
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
976 v->dqbilevel = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
977 default: break; //Forbidden ?
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
978 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
979 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
980 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
981 pqdiff = get_bits(gb, 3);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
982 if (pqdiff == 7) v->altpq = get_bits(gb, 5);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
983 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
984 }
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 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
987 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
988 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
989
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 /* 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
992 /* 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
993 /*****************************************************************************/
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
994
2462
michael
parents: 2461
diff changeset
995 /* Tables 11+12, p62-65 */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
996 static int decode_b_picture_primary_header(VC9Context *v)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
997 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
998 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
999 int pqindex, status;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1000
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1001 /* 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
1002 if (v->profile == PROFILE_SIMPLE)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1003 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1004 av_log(v->s.avctx, AV_LOG_ERROR, "Found a B frame while in Simple Profile!\n");
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1005 return FRAME_SKIPED;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1006 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1007
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1008 v->bfraction = vc9_bfraction_lut[get_vlc2(gb, vc9_bfraction_vlc.table,
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1009 VC9_BFRACTION_VLC_BITS, 2)];
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1010 if (v->bfraction < -1)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1011 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1012 av_log(v->s.avctx, AV_LOG_ERROR, "Invalid BFRaction\n");
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1013 return FRAME_SKIPED;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1014 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1015 else if (!v->bfraction)
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 /* We actually have a BI frame */
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1018 v->s.pict_type = BI_TYPE;
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1019 v->buffer_fullness = get_bits(gb, 7);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1020 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1021
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1022 /* Read the quantization stuff */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1023 pqindex = get_bits(gb, 5);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1024 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
1025 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
1026 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1027 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1028 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
1029 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1030 if (pqindex < 9) v->halfpq = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1031 if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1032 v->pquantizer = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1033
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1034 /* Read the MV type/mode */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1035 if (v->extended_mv == 1)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1036 v->mvrange = get_prefix(gb, 0, 3);
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1037 if (v->s.pict_type != BI_TYPE)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1038 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1039 v->mv_mode = get_bits(gb, 1);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1040 if (v->pq < 13)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1041 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1042 if (!v->mv_mode)
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1043 {
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1044 v->mv_mode = get_bits(gb, 2);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1045 if (v->mv_mode)
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1046 av_log(v->s.avctx, AV_LOG_ERROR,
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1047 "mv_mode for lowquant B frame was %i\n", v->mv_mode);
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1048 }
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1049 }
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1050 else
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1051 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1052 if (!v->mv_mode)
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1053 {
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1054 if (get_bits(gb, 1))
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1055 av_log(v->s.avctx, AV_LOG_ERROR,
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1056 "mv_mode for highquant B frame was %i\n", v->mv_mode);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1057 }
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1058 v->mv_mode = 1-v->mv_mode; //To match (pq < 13) mapping
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1059 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1060 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1061
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1062 return 0;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1063 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1064
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1065 static int decode_b_picture_secondary_header(VC9Context *v)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1066 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1067 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1068 int status;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1069
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1070 bitplane_decoding(&v->skip_mb_plane, v);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1071 if (status < 0) return -1;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1072 #if TRACE
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1073 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
1074 {
2462
michael
parents: 2461
diff changeset
1075 status = bitplane_decoding(&v->mv_type_mb_plane, v);
michael
parents: 2461
diff changeset
1076 if (status < 0)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1077 return -1;
2462
michael
parents: 2461
diff changeset
1078 #if TRACE
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1079 av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
2462
michael
parents: 2461
diff changeset
1080 "Imode: %i, Invert: %i\n", status>>1, status&1);
michael
parents: 2461
diff changeset
1081 #endif
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1082 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1083
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1084 //bitplane
2462
michael
parents: 2461
diff changeset
1085 status = bitplane_decoding(&v->direct_mb_plane, v);
michael
parents: 2461
diff changeset
1086 if (status < 0) return -1;
michael
parents: 2461
diff changeset
1087 #if TRACE
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1088 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct plane encoding: "
2462
michael
parents: 2461
diff changeset
1089 "Imode: %i, Invert: %i\n", status>>1, status&1);
michael
parents: 2461
diff changeset
1090 #endif
michael
parents: 2461
diff changeset
1091
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1092 av_log(v->s.avctx, AV_LOG_DEBUG, "Skip MB plane encoding: "
2462
michael
parents: 2461
diff changeset
1093 "Imode: %i, Invert: %i\n", status>>1, status&1);
michael
parents: 2461
diff changeset
1094 #endif
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1095
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1096 /* FIXME: what is actually chosen for B frames ? */
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1097 v->s.mv_table_index = get_bits(gb, 2); //but using vc9_ tables
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1098 v->cbpcy_vlc = &vc9_cbpcy_p_vlc[get_bits(gb, 2)];
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1099
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1100 if (v->dquant)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1101 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1102 vop_dquant_decoding(v);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1103 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1104
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1105 if (v->vstransform)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1106 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1107 v->ttmbf = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1108 if (v->ttmbf)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1109 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1110 v->ttfrm = get_bits(gb, 2);
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1111 av_log(v->s.avctx, AV_LOG_INFO, "Transform used: %ix%i\n",
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1112 (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
1113 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1114 }
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1115 /* Epilog (AC/DC syntax) should be done in caller */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1116 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1117 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1118
2462
michael
parents: 2461
diff changeset
1119 /* 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
1120 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
1121 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1122 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1123 int pqindex, status = 0;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1124
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1125 /* 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
1126 //BF = Buffer Fullness
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1127 if (v->profile <= PROFILE_MAIN && get_bits(gb, 7))
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1128 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1129 av_log(v->s.avctx, AV_LOG_DEBUG, "I BufferFullness not 0\n");
2445
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
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1132 /* Quantizer stuff */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1133 pqindex = get_bits(gb, 5);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1134 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
1135 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
1136 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1137 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1138 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
1139 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1140 if (pqindex < 9) v->halfpq = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1141 if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1142 v->pquantizer = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1143 av_log(v->s.avctx, AV_LOG_DEBUG, "I frame: QP=%i (+%i/2)\n",
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1144 v->pq, v->halfpq);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1145 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1146 if (v->profile <= PROFILE_MAIN)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1147 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1148 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1149 if (v->extended_mv) v->mvrange = get_prefix(gb, 0, 3);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1150 if (v->multires) v->respic = get_bits(gb, 2);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1151 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1152 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1153 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1154 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1155 v->s.ac_pred = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1156 if (v->postprocflag) v->postproc = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1157 /* 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
1158 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
1159 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1160 v->condover = get_bits(gb, 1);
2462
michael
parents: 2461
diff changeset
1161 if (v->condover)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1162 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1163 v->condover = 2+get_bits(gb, 1);
2462
michael
parents: 2461
diff changeset
1164 if (v->condover == 3)
michael
parents: 2461
diff changeset
1165 {
michael
parents: 2461
diff changeset
1166 status = bitplane_decoding(&v->over_flags_plane, v);
michael
parents: 2461
diff changeset
1167 if (status < 0) return -1;
michael
parents: 2461
diff changeset
1168 #if TRACE
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1169 av_log(v->s.avctx, AV_LOG_DEBUG, "Overflags plane encoding: "
2462
michael
parents: 2461
diff changeset
1170 "Imode: %i, Invert: %i\n", status>>1, status&1);
michael
parents: 2461
diff changeset
1171 #endif
michael
parents: 2461
diff changeset
1172 }
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1173 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1174 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1175 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1176 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1177
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1178 /* Epilog (AC/DC syntax) should be done in caller */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1179 return status;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1180 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1181
2462
michael
parents: 2461
diff changeset
1182 /* Table 9, p58-60 */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1183 static int decode_p_picture_primary_header(VC9Context *v)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1184 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1185 /* INTERFRM, FRMCNT, RANGEREDFRM read in caller */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1186 GetBitContext *gb = &v->s.gb;
2462
michael
parents: 2461
diff changeset
1187 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
1188
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1189 pqindex = get_bits(gb, 5);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1190 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
1191 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
1192 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1193 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1194 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
1195 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1196 if (pqindex < 9) v->halfpq = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1197 if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1198 v->pquantizer = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1199 av_log(v->s.avctx, AV_LOG_DEBUG, "P Frame: QP=%i (+%i/2)\n",
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1200 v->pq, v->halfpq);
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1201 if (v->extended_mv == 1) v->mvrange = get_prefix(gb, 0, 3);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1202 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1203 if (v->profile > PROFILE_MAIN)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1204 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1205 if (v->postprocflag) v->postproc = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1206 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1207 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1208 #endif
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1209 if (v->multires) v->respic = get_bits(gb, 2);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1210 lowquant = (v->pquantizer>12) ? 0 : 1;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1211 v->mv_mode = mv_pmode_table[lowquant][get_prefix(gb, 1, 4)];
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1212 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
1213 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1214 v->mv_mode2 = mv_pmode_table[lowquant][get_prefix(gb, 1, 3)];
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1215 v->lumscale = get_bits(gb, 6);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1216 v->lumshift = get_bits(gb, 6);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1217 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1218 return 0;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1219 }
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1220
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1221 static int decode_p_picture_secondary_header(VC9Context *v)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1222 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1223 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1224 int status = 0;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1225 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
1226 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
1227 || 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
1228 {
2462
michael
parents: 2461
diff changeset
1229 status = bitplane_decoding(&v->mv_type_mb_plane, v);
michael
parents: 2461
diff changeset
1230 if (status < 0) return -1;
michael
parents: 2461
diff changeset
1231 #if TRACE
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1232 av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
2462
michael
parents: 2461
diff changeset
1233 "Imode: %i, Invert: %i\n", status>>1, status&1);
michael
parents: 2461
diff changeset
1234 #endif
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1235 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1236
2462
michael
parents: 2461
diff changeset
1237 status = bitplane_decoding(&v->skip_mb_plane, v);
michael
parents: 2461
diff changeset
1238 if (status < 0) return -1;
michael
parents: 2461
diff changeset
1239 #if TRACE
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1240 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
2462
michael
parents: 2461
diff changeset
1241 "Imode: %i, Invert: %i\n", status>>1, status&1);
michael
parents: 2461
diff changeset
1242 #endif
2445
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 /* Hopefully this is correct for P frames */
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1245 v->s.mv_table_index =get_bits(gb, 2); //but using vc9_ tables
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1246 v->cbpcy_vlc = &vc9_cbpcy_p_vlc[get_bits(gb, 2)];
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->dquant)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1249 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1250 av_log(v->s.avctx, AV_LOG_INFO, "VOP DQuant info\n");
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1251 vop_dquant_decoding(v);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1252 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1253
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1254 v->ttfrm = 0; //FIXME Is that so ?
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1255 if (v->vstransform)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1256 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1257 v->ttmbf = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1258 if (v->ttmbf)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1259 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1260 v->ttfrm = get_bits(gb, 2);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1261 av_log(v->s.avctx, AV_LOG_INFO, "Transform used: %ix%i\n",
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1262 (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
1263 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1264 }
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1265 /* Epilog (AC/DC syntax) should be done in caller */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1266 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1267 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1268
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1269
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1270 static int standard_decode_picture_primary_header(VC9Context *v)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1271 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1272 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1273 int status = 0;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1274
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1275 if (v->finterpflag) v->interpfrm = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1276 skip_bits(gb, 2); //framecnt unused
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1277 if (v->rangered) v->rangeredfrm = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1278 v->s.pict_type = get_bits(gb, 1);
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1279 if (v->s.avctx->max_b_frames)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1280 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1281 if (!v->s.pict_type)
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1282 {
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1283 if (get_bits(gb, 1)) v->s.pict_type = I_TYPE;
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1284 else v->s.pict_type = B_TYPE;
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1285 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1286 else v->s.pict_type = P_TYPE;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1287 }
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1288 else v->s.pict_type++;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1289
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1290 switch (v->s.pict_type)
2445
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 case I_TYPE: status = decode_i_picture_header(v); break;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1293 case P_TYPE: status = decode_p_picture_primary_header(v); break;
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1294 case BI_TYPE:
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1295 case B_TYPE: status = decode_b_picture_primary_header(v); break;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1296 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1297
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1298 if (status == FRAME_SKIPED)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1299 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1300 av_log(v->s.avctx, AV_LOG_INFO, "Skipping frame...\n");
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1301 return status;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1302 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1303 return 0;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1304 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1305
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1306 static int standard_decode_picture_secondary_header(VC9Context *v)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1307 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1308 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1309 int status = 0, index;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1310
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1311 switch (v->s.pict_type)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1312 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1313 case P_TYPE: status = decode_p_picture_secondary_header(v); break;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1314 case B_TYPE: status = decode_b_picture_secondary_header(v); break;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1315 }
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1316
2462
michael
parents: 2461
diff changeset
1317 /* AC Syntax */
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1318 v->ac_table_level = decode012(gb);
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1319 if (v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1320 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1321 index = decode012(gb);
2462
michael
parents: 2461
diff changeset
1322 v->luma_ac2_vlc = NULL + index; //FIXME Add AC2 table
michael
parents: 2461
diff changeset
1323 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
1324 }
2462
michael
parents: 2461
diff changeset
1325 /* DC Syntax */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1326 index = decode012(gb);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1327 v->luma_dc_vlc = &ff_msmp4_dc_luma_vlc[index];
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1328 v->chroma_dc_vlc = &ff_msmp4_dc_chroma_vlc[index];
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1329
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1330 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1331 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1332
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1333
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1334 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1335 /******************************************************************************/
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1336 /* 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
1337 /******************************************************************************/
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1338 static int advanced_decode_picture_primary_header(VC9Context *v)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1339 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1340 GetBitContext *gb = &v->s.gb;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1341 static const int type_table[4] = { P_TYPE, B_TYPE, I_TYPE, BI_TYPE };
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1342 int type, i;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1343
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1344 if (v->interlace)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1345 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1346 v->fcm = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1347 if (v->fcm) v->fcm = 2+get_bits(gb, 1);
2445
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
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1350 type = get_prefix(gb, 0, 4);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1351 if (type > 4 || type < 0) return FRAME_SKIPED;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1352 v->s.pict_type = type_table[type];
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1353 av_log(v->s.avctx, AV_LOG_INFO, "AP Frame Type: %i\n", v->s.pict_type);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1354
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1355 if (v->tfcntrflag) v->tfcntr = get_bits(gb, 8);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1356 if (v->broadcast)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1357 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1358 if (!v->interlace) v->rptfrm = get_bits(gb, 2);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1359 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1360 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1361 v->tff = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1362 v->rff = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1363 }
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
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1366 if (v->panscanflag)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1367 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1368 #if 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1369 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
1370 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1371 v->topleftx[i] = get_bits(gb, 16);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1372 v->toplefty[i] = get_bits(gb, 16);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1373 v->bottomrightx[i] = get_bits(gb, 16);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1374 v->bottomrighty[i] = get_bits(gb, 16);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1375 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1376 #else
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1377 skip_bits(gb, 16*4*v->numpanscanwin);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1378 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1379 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1380 v->s.no_rounding = !get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1381 v->uvsamp = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1382 if (v->finterpflag == 1) v->interpfrm = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1383
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1384 switch(v->s.pict_type)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1385 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1386 case I_TYPE: if (decode_i_picture_header(v) < 0) return -1;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1387 case P_TYPE: if (decode_p_picture_primary_header(v) < 0) return -1;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1388 case BI_TYPE:
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1389 case B_TYPE: if (decode_b_picture_primary_header(v) < 0) return FRAME_SKIPED;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1390 default: break;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1391 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1392 return 0;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1393 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1394
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1395 static int advanced_decode_picture_secondary_header(VC9Context *v)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1396 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1397 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1398 int index;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1399
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1400 switch(v->s.pict_type)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1401 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1402 case P_TYPE: if (decode_p_picture_secondary_header(v) < 0) return -1;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1403 case B_TYPE: if (decode_b_picture_secondary_header(v) < 0) return FRAME_SKIPED;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1404 default: break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1405 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1406
2462
michael
parents: 2461
diff changeset
1407 /* AC Syntax */
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1408 v->ac_table_level = decode012(gb);
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1409 if (v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1410 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1411 index = decode012(gb); //FIXME
2462
michael
parents: 2461
diff changeset
1412 v->luma_ac2_vlc = NULL + index;
michael
parents: 2461
diff changeset
1413 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
1414 }
2462
michael
parents: 2461
diff changeset
1415 /* DC Syntax */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1416 index = decode012(gb);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1417 v->luma_dc_vlc = &ff_msmp4_dc_luma_vlc[index];
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1418 v->chroma_dc_vlc = &ff_msmp4_dc_chroma_vlc[index];
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1419
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1420 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1421 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1422 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1423
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1424 /******************************************************************************/
2462
michael
parents: 2461
diff changeset
1425 /* Block decoding functions */
michael
parents: 2461
diff changeset
1426 /******************************************************************************/
michael
parents: 2461
diff changeset
1427 /* 7.1.4, p91 and 8.1.1.7, p(1)04 */
michael
parents: 2461
diff changeset
1428 /* FIXME proper integration (unusable and lots of parameters to send */
michael
parents: 2461
diff changeset
1429 int decode_luma_intra_block(VC9Context *v, int mquant)
michael
parents: 2461
diff changeset
1430 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1431 GetBitContext *gb = &v->s.gb;
2462
michael
parents: 2461
diff changeset
1432 int dcdiff;
michael
parents: 2461
diff changeset
1433
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1434 dcdiff = get_vlc2(gb, v->luma_dc_vlc->table,
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1435 DC_VLC_BITS, 2);
2462
michael
parents: 2461
diff changeset
1436 if (dcdiff)
michael
parents: 2461
diff changeset
1437 {
michael
parents: 2461
diff changeset
1438 if (dcdiff == 119 /* ESC index value */)
michael
parents: 2461
diff changeset
1439 {
michael
parents: 2461
diff changeset
1440 /* TODO: Optimize */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1441 if (mquant == 1) dcdiff = get_bits(gb, 10);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1442 else if (mquant == 2) dcdiff = get_bits(gb, 9);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1443 else dcdiff = get_bits(gb, 8);
2462
michael
parents: 2461
diff changeset
1444 }
michael
parents: 2461
diff changeset
1445 else
michael
parents: 2461
diff changeset
1446 {
michael
parents: 2461
diff changeset
1447 if (mquant == 1)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1448 dcdiff = (dcdiff<<2) + get_bits(gb, 2) - 3;
2462
michael
parents: 2461
diff changeset
1449 else if (mquant == 2)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1450 dcdiff = (dcdiff<<1) + get_bits(gb, 1) - 1;
2462
michael
parents: 2461
diff changeset
1451 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1452 if (get_bits(gb, 1))
2462
michael
parents: 2461
diff changeset
1453 dcdiff = -dcdiff;
michael
parents: 2461
diff changeset
1454 }
michael
parents: 2461
diff changeset
1455 /* FIXME: 8.1.1.15, p(1)13, coeff scaling for Adv Profile */
michael
parents: 2461
diff changeset
1456
michael
parents: 2461
diff changeset
1457 return 0;
michael
parents: 2461
diff changeset
1458 }
michael
parents: 2461
diff changeset
1459
michael
parents: 2461
diff changeset
1460 /******************************************************************************/
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1461 /* MacroBlock decoding functions */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1462 /******************************************************************************/
2462
michael
parents: 2461
diff changeset
1463 /* 8.1.1.5, p(1)02-(1)03 */
michael
parents: 2461
diff changeset
1464 /* We only need to store 3 flags, but math with 4 is easier */
michael
parents: 2461
diff changeset
1465 #define GET_CBPCY(table, bits) \
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1466 predicted_cbpcy = get_vlc2(gb, table, bits, 2); \
2462
michael
parents: 2461
diff changeset
1467 cbpcy[0] = (p_cbpcy[-1] == p_cbpcy[2]) \
michael
parents: 2461
diff changeset
1468 ? previous_cbpcy[1] : p_cbpcy[+2]; \
michael
parents: 2461
diff changeset
1469 cbpcy[0] ^= ((predicted_cbpcy>>5)&0x01); \
michael
parents: 2461
diff changeset
1470 cbpcy[1] = (p_cbpcy[2] == p_cbpcy[3]) ? cbpcy[0] : p_cbpcy[3]; \
michael
parents: 2461
diff changeset
1471 cbpcy[1] ^= ((predicted_cbpcy>>4)&0x01); \
michael
parents: 2461
diff changeset
1472 cbpcy[2] = (previous_cbpcy[1] == cbpcy[0]) \
michael
parents: 2461
diff changeset
1473 ? previous_cbpcy[3] : cbpcy[0]; \
michael
parents: 2461
diff changeset
1474 cbpcy[2] ^= ((predicted_cbpcy>>3)&0x01); \
michael
parents: 2461
diff changeset
1475 cbpcy[3] = (cbpcy[1] == cbpcy[0]) ? cbpcy[2] : cbpcy[1]; \
michael
parents: 2461
diff changeset
1476 cbpcy[3] ^= ((predicted_cbpcy>>2)&0x01);
michael
parents: 2461
diff changeset
1477
michael
parents: 2461
diff changeset
1478 /* 8.1, p100 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1479 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
1480 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1481 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1482 MpegEncContext *s = &v->s;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1483 int current_mb = 0; /* MB/Block Position info */
2462
michael
parents: 2461
diff changeset
1484 /* FIXME: better to use a pointer than using (x<<4) */
michael
parents: 2461
diff changeset
1485 uint8_t cbpcy[4], previous_cbpcy[4], predicted_cbpcy,
michael
parents: 2461
diff changeset
1486 *p_cbpcy /* Pointer to skip some math */;
michael
parents: 2461
diff changeset
1487
michael
parents: 2461
diff changeset
1488 /* Reset CBPCY predictors */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1489 memset(v->previous_line_cbpcy, 0, s->mb_stride<<2);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1490
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1491 /* 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
1492 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
1493 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
1494 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
1495
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1496 for (s->mb_y=0; s->mb_y<s->mb_height; s->mb_y++)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1497 {
2462
michael
parents: 2461
diff changeset
1498 /* Init CBPCY for line */
michael
parents: 2461
diff changeset
1499 *((uint32_t*)previous_cbpcy) = 0x00000000;
michael
parents: 2461
diff changeset
1500 p_cbpcy = v->previous_line_cbpcy+4;
michael
parents: 2461
diff changeset
1501
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1502 for (s->mb_x=0; s->mb_x<s->mb_width; s->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
1503 {
2462
michael
parents: 2461
diff changeset
1504 /* Get CBPCY */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1505 GET_CBPCY(ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS);
2462
michael
parents: 2461
diff changeset
1506
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1507 s->ac_pred = get_bits(gb, 1);
2462
michael
parents: 2461
diff changeset
1508
michael
parents: 2461
diff changeset
1509 /* TODO: Decode blocks from that mb wrt cbpcy */
michael
parents: 2461
diff changeset
1510
michael
parents: 2461
diff changeset
1511 /* Update for next block */
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1512 #if TRACE > 2
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1513 av_log(s->avctx, AV_LOG_DEBUG, "Block %4i: p_cbpcy=%i%i%i%i, previous_cbpcy=%i%i%i%i,"
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1514 " cbpcy=%i%i%i%i\n", current_mb,
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1515 p_cbpcy[0], p_cbpcy[1], p_cbpcy[2], p_cbpcy[3],
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1516 previous_cbpcy[0], previous_cbpcy[1], previous_cbpcy[2], previous_cbpcy[3],
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1517 cbpcy[0], cbpcy[1], cbpcy[2], cbpcy[3]);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1518 #endif
2462
michael
parents: 2461
diff changeset
1519 *((uint32_t*)p_cbpcy) = *((uint32_t*)previous_cbpcy);
michael
parents: 2461
diff changeset
1520 *((uint32_t*)previous_cbpcy) = *((uint32_t*)cbpcy);
michael
parents: 2461
diff changeset
1521 current_mb++;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1522 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1523 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1524 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1525 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1526
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1527 #define GET_MQUANT() \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1528 if (v->dquantfrm) \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1529 { \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1530 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
1531 { \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1532 if (v->dqbilevel) \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1533 { \
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1534 mquant = (get_bits(gb, 1)) ? v->pq : v->altpq; \
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 else \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1537 { \
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1538 mqdiff = get_bits(gb, 3); \
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1539 if (mqdiff != 7) mquant = v->pq + mqdiff; \
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1540 else mquant = get_bits(gb, 5); \
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1541 } \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1542 } \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1543 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1544
2462
michael
parents: 2461
diff changeset
1545 /* MVDATA decoding from 8.3.5.2, p(1)20 */
michael
parents: 2461
diff changeset
1546 #define GET_MVDATA(_dmv_x, _dmv_y) \
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1547 index = 1 + get_vlc2(gb, vc9_mv_diff_vlc[s->mv_table_index].table,\
2462
michael
parents: 2461
diff changeset
1548 VC9_MV_DIFF_VLC_BITS, 2); \
michael
parents: 2461
diff changeset
1549 if (index > 36) \
michael
parents: 2461
diff changeset
1550 { \
michael
parents: 2461
diff changeset
1551 mb_has_coeffs = 1; \
michael
parents: 2461
diff changeset
1552 index -= 37; \
michael
parents: 2461
diff changeset
1553 } \
michael
parents: 2461
diff changeset
1554 else mb_has_coeffs = 0; \
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1555 s->mb_intra = 0; \
2462
michael
parents: 2461
diff changeset
1556 if (!index) { _dmv_x = _dmv_y = 0; } \
michael
parents: 2461
diff changeset
1557 else if (index == 35) \
michael
parents: 2461
diff changeset
1558 { \
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1559 _dmv_x = get_bits(gb, k_x); \
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1560 _dmv_y = get_bits(gb, k_y); \
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1561 s->mb_intra = 1; \
2462
michael
parents: 2461
diff changeset
1562 } \
michael
parents: 2461
diff changeset
1563 else \
michael
parents: 2461
diff changeset
1564 { \
michael
parents: 2461
diff changeset
1565 index1 = index%6; \
michael
parents: 2461
diff changeset
1566 if (hpel_flag && index1 == 5) val = 1; \
michael
parents: 2461
diff changeset
1567 else val = 0; \
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1568 val = get_bits(gb, size_table[index1] - val); \
2462
michael
parents: 2461
diff changeset
1569 sign = 0 - (val&1); \
michael
parents: 2461
diff changeset
1570 _dmv_x = (sign ^ ((val>>1) + offset_table[index1])) - sign; \
michael
parents: 2461
diff changeset
1571 \
michael
parents: 2461
diff changeset
1572 index1 = index/6; \
michael
parents: 2461
diff changeset
1573 if (hpel_flag && index1 == 5) val = 1; \
michael
parents: 2461
diff changeset
1574 else val = 0; \
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1575 val = get_bits(gb, size_table[index1] - val); \
2462
michael
parents: 2461
diff changeset
1576 sign = 0 - (val&1); \
michael
parents: 2461
diff changeset
1577 _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
1578 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1579
2462
michael
parents: 2461
diff changeset
1580 /* 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
1581 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
1582 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1583 MpegEncContext *s = &v->s;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1584 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1585 int current_mb = 0, i; /* MB/Block Position info */
2462
michael
parents: 2461
diff changeset
1586 uint8_t cbpcy[4], previous_cbpcy[4], predicted_cbpcy,
michael
parents: 2461
diff changeset
1587 *p_cbpcy /* Pointer to skip some math */;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1588 int hybrid_pred; /* Prediction types */
2462
michael
parents: 2461
diff changeset
1589 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
1590 int mqdiff, mquant; /* MB quantization */
2462
michael
parents: 2461
diff changeset
1591 int ttmb; /* MB Transform type */
michael
parents: 2461
diff changeset
1592
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1593 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
1594 offset_table[6] = { 0, 1, 3, 7, 15, 31 };
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1595 int mb_has_coeffs = 1; /* last_flag */
2462
michael
parents: 2461
diff changeset
1596 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
1597 int k_x, k_y; /* Long MV fixed bitlength */
2462
michael
parents: 2461
diff changeset
1598 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
1599 int index, index1; /* LUT indices */
2462
michael
parents: 2461
diff changeset
1600 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
1601
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1602 /* 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
1603 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
1604 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
1605 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
1606
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1607 /* Select proper long MV range */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1608 switch (v->mvrange)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1609 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1610 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
1611 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
1612 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
1613 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
1614 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1615
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1616 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
1617 k_x -= hpel_flag;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1618 k_y -= hpel_flag;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1619
2462
michael
parents: 2461
diff changeset
1620 /* Reset CBPCY predictors */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1621 memset(v->previous_line_cbpcy, 0, s->mb_stride<<2);
2462
michael
parents: 2461
diff changeset
1622
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1623 for (s->mb_y=0; s->mb_y<s->mb_height; s->mb_y++)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1624 {
2462
michael
parents: 2461
diff changeset
1625 /* Init CBPCY for line */
michael
parents: 2461
diff changeset
1626 *((uint32_t*)previous_cbpcy) = 0x00000000;
michael
parents: 2461
diff changeset
1627 p_cbpcy = v->previous_line_cbpcy+4;
michael
parents: 2461
diff changeset
1628
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1629 for (s->mb_x=0; s->mb_x<s->mb_width; s->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
1630 {
2462
michael
parents: 2461
diff changeset
1631 if (v->mv_type_mb_plane.is_raw)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1632 v->mv_type_mb_plane.data[current_mb] = get_bits(gb, 1);
2462
michael
parents: 2461
diff changeset
1633 if (v->skip_mb_plane.is_raw)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1634 v->skip_mb_plane.data[current_mb] = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1635 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
1636 {
2462
michael
parents: 2461
diff changeset
1637 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
1638 {
2462
michael
parents: 2461
diff changeset
1639 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
1640
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1641 /* 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
1642 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
1643 v->mv_mode == MV_PMODE_MIXED_MV)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1644 hybrid_pred = get_bits(gb, 1);
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1645 if (s->mb_intra && !mb_has_coeffs)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1646 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1647 GET_MQUANT();
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1648 s->ac_pred = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1649 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1650 else if (mb_has_coeffs)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1651 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1652 if (s->mb_intra) s->ac_pred = get_bits(gb, 1);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1653 predicted_cbpcy = get_vlc2(gb, v->cbpcy_vlc->table, VC9_CBPCY_P_VLC_BITS, 2);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1654 cbpcy[0] = (p_cbpcy[-1] == p_cbpcy[2]) ? previous_cbpcy[1] : p_cbpcy[2];
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1655 cbpcy[0] ^= ((predicted_cbpcy>>5)&0x01);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1656 cbpcy[1] = (p_cbpcy[2] == p_cbpcy[3]) ? cbpcy[0] : p_cbpcy[3];
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1657 cbpcy[1] ^= ((predicted_cbpcy>>4)&0x01);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1658 cbpcy[2] = (previous_cbpcy[1] == cbpcy[0]) ? previous_cbpcy[3] : cbpcy[0];
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1659 cbpcy[2] ^= ((predicted_cbpcy>>3)&0x01);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1660 cbpcy[3] = (cbpcy[1] == cbpcy[0]) ? cbpcy[2] : cbpcy[1];
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1661 cbpcy[3] ^= ((predicted_cbpcy>>2)&0x01);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1662 //GET_CBPCY(v->cbpcy_vlc->table, VC9_CBPCY_P_VLC_BITS);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1663
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1664 GET_MQUANT();
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1665 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1666 if (!v->ttmbf)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1667 ttmb = get_vlc2(gb, v->ttmb_vlc->table,
2462
michael
parents: 2461
diff changeset
1668 VC9_TTMB_VLC_BITS, 12);
michael
parents: 2461
diff changeset
1669 /* 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
1670 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1671 else //Skipped
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1672 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1673 /* 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
1674 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
1675 v->mv_mode == MV_PMODE_MIXED_MV)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1676 hybrid_pred = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1677 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1678 } //1MV mode
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1679 else //4MV mode
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1680 {
2462
michael
parents: 2461
diff changeset
1681 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
1682 {
2462
michael
parents: 2461
diff changeset
1683 /* Get CBPCY */
michael
parents: 2461
diff changeset
1684 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
1685 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
1686 {
2462
michael
parents: 2461
diff changeset
1687 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
1688 {
2462
michael
parents: 2461
diff changeset
1689 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
1690 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1691 if (v->mv_mode == MV_PMODE_MIXED_MV /* Hybrid pred */)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1692 hybrid_pred = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1693 GET_MQUANT();
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1694 if (s->mb_intra /* One of the 4 blocks is intra */ &&
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1695 index /* non-zero pred for that block */)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1696 s->ac_pred = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1697 if (!v->ttmbf)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1698 ttmb = get_vlc2(gb, v->ttmb_vlc->table,
2462
michael
parents: 2461
diff changeset
1699 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
1700
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1701 /* TODO: Process blocks wrt cbpcy */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1702
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1703 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1704 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1705 else //Skipped MB
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1706 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1707 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
1708 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1709 if (v->mv_mode == MV_PMODE_MIXED_MV /* Hybrid pred */)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1710 hybrid_pred = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1711
2462
michael
parents: 2461
diff changeset
1712 /* TODO: do something */
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 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1715 }
2462
michael
parents: 2461
diff changeset
1716
michael
parents: 2461
diff changeset
1717 /* Update for next block */
michael
parents: 2461
diff changeset
1718 #if TRACE > 2
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1719 av_log(s->avctx, AV_LOG_DEBUG, "Block %4i: p_cbpcy=%i%i%i%i, previous_cbpcy=%i%i%i%i,"
2462
michael
parents: 2461
diff changeset
1720 " cbpcy=%i%i%i%i\n", current_mb,
michael
parents: 2461
diff changeset
1721 p_cbpcy[0], p_cbpcy[1], p_cbpcy[2], p_cbpcy[3],
michael
parents: 2461
diff changeset
1722 previous_cbpcy[0], previous_cbpcy[1], previous_cbpcy[2], previous_cbpcy[3],
michael
parents: 2461
diff changeset
1723 cbpcy[0], cbpcy[1], cbpcy[2], cbpcy[3]);
michael
parents: 2461
diff changeset
1724 #endif
michael
parents: 2461
diff changeset
1725 *((uint32_t*)p_cbpcy) = *((uint32_t*)previous_cbpcy);
michael
parents: 2461
diff changeset
1726 *((uint32_t*)previous_cbpcy) = *((uint32_t*)cbpcy);
michael
parents: 2461
diff changeset
1727 current_mb++;
2445
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 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1730 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1731 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1732
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1733 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
1734 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1735 MpegEncContext *s = &v->s;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1736 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1737 int current_mb = 0, i /* MB / B postion information */;
2462
michael
parents: 2461
diff changeset
1738 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
1739 int mquant, mqdiff; /* MB quant stuff */
2462
michael
parents: 2461
diff changeset
1740 int ttmb; /* MacroBlock transform type */
michael
parents: 2461
diff changeset
1741
michael
parents: 2461
diff changeset
1742 static const int size_table[6] = { 0, 2, 3, 4, 5, 8 },
michael
parents: 2461
diff changeset
1743 offset_table[6] = { 0, 1, 3, 7, 15, 31 };
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1744 int mb_has_coeffs = 1; /* last_flag */
2462
michael
parents: 2461
diff changeset
1745 int dmv1_x, dmv1_y, dmv2_x, dmv2_y; /* Differential MV components */
michael
parents: 2461
diff changeset
1746 int k_x, k_y; /* Long MV fixed bitlength */
michael
parents: 2461
diff changeset
1747 int hpel_flag; /* Some MB properties */
michael
parents: 2461
diff changeset
1748 int index, index1; /* LUT indices */
michael
parents: 2461
diff changeset
1749 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
1750
2462
michael
parents: 2461
diff changeset
1751 /* Select proper long MV range */
michael
parents: 2461
diff changeset
1752 switch (v->mvrange)
michael
parents: 2461
diff changeset
1753 {
michael
parents: 2461
diff changeset
1754 case 1: k_x = 10; k_y = 9; break;
michael
parents: 2461
diff changeset
1755 case 2: k_x = 12; k_y = 10; break;
michael
parents: 2461
diff changeset
1756 case 3: k_x = 13; k_y = 11; break;
michael
parents: 2461
diff changeset
1757 default: /*case 0 too */ k_x = 9; k_y = 8; break;
michael
parents: 2461
diff changeset
1758 }
michael
parents: 2461
diff changeset
1759 hpel_flag = v->mv_mode & 1; //MV_PMODE is HPEL
michael
parents: 2461
diff changeset
1760 k_x -= hpel_flag;
michael
parents: 2461
diff changeset
1761 k_y -= hpel_flag;
michael
parents: 2461
diff changeset
1762
michael
parents: 2461
diff changeset
1763 /* Select ttmb table depending on pq */
michael
parents: 2461
diff changeset
1764 if (v->pq < 5) v->ttmb_vlc = &vc9_ttmb_vlc[0];
michael
parents: 2461
diff changeset
1765 else if (v->pq < 13) v->ttmb_vlc = &vc9_ttmb_vlc[1];
michael
parents: 2461
diff changeset
1766 else v->ttmb_vlc = &vc9_ttmb_vlc[2];
michael
parents: 2461
diff changeset
1767
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1768 for (s->mb_y=0; s->mb_y<s->mb_height; s->mb_y++)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1769 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1770 for (s->mb_x=0; s->mb_x<s->mb_width; s->mb_x++)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1771 {
2462
michael
parents: 2461
diff changeset
1772 if (v->direct_mb_plane.is_raw)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1773 v->direct_mb_plane.data[current_mb] = get_bits(gb, 1);
2462
michael
parents: 2461
diff changeset
1774 if (v->skip_mb_plane.is_raw)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1775 v->skip_mb_plane.data[current_mb] = get_bits(gb, 1);
2462
michael
parents: 2461
diff changeset
1776
michael
parents: 2461
diff changeset
1777 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
1778 {
2462
michael
parents: 2461
diff changeset
1779 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
1780 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1781 b_mv_type = decode012(gb);
2462
michael
parents: 2461
diff changeset
1782 if (v->bfraction > 420 /*1/2*/ &&
michael
parents: 2461
diff changeset
1783 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
1784 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1785 else
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 /* FIXME getting tired commenting */
2462
michael
parents: 2461
diff changeset
1788 GET_MVDATA(dmv1_x, dmv1_y);
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1789 if (!s->mb_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
1790 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1791 /* FIXME: actually read it */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1792 b_mv_type = decode012(gb);
2462
michael
parents: 2461
diff changeset
1793 if (v->bfraction > 420 /*1/2*/ &&
michael
parents: 2461
diff changeset
1794 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
1795 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1796 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1797 }
2462
michael
parents: 2461
diff changeset
1798 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
1799 {
2462
michael
parents: 2461
diff changeset
1800 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
1801 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1802 GET_MQUANT();
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1803 if (s->mb_intra /* intra mb */)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1804 s->ac_pred = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1805 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1806 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1807 {
2462
michael
parents: 2461
diff changeset
1808 /* if bmv1 tells MVs are interpolated */
michael
parents: 2461
diff changeset
1809 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
1810 {
2462
michael
parents: 2461
diff changeset
1811 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
1812 }
2462
michael
parents: 2461
diff changeset
1813 /* GET_MVDATA has reset some stuff */
michael
parents: 2461
diff changeset
1814 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
1815 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1816 if (s->mb_intra /* intra_mb */)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1817 s->ac_pred = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1818 GET_MQUANT();
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1819 }
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 //End1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1823 if (v->ttmbf)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1824 ttmb = get_vlc2(gb, v->ttmb_vlc->table,
2462
michael
parents: 2461
diff changeset
1825 VC9_TTMB_VLC_BITS, 12);
michael
parents: 2461
diff changeset
1826
michael
parents: 2461
diff changeset
1827 //End2
michael
parents: 2461
diff changeset
1828 for (i=0; i<6; i++)
michael
parents: 2461
diff changeset
1829 {
michael
parents: 2461
diff changeset
1830 /* FIXME: process the block */
michael
parents: 2461
diff changeset
1831 }
michael
parents: 2461
diff changeset
1832
michael
parents: 2461
diff changeset
1833 current_mb++;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1834 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1835 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1836 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1837 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1838
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1839 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1840 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
1841 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1842 MpegEncContext *s = &v->s;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1843 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1844 int mqdiff, mquant, 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
1845
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1846 for (s->mb_y=0; s->mb_y<s->mb_height; s->mb_y++)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1847 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1848 for (s->mb_x=0; s->mb_x<s->mb_width; s->mb_x++)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1849 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1850 if (v->ac_pred_plane.is_raw)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1851 s->ac_pred = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1852 else
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1853 s->ac_pred = v->ac_pred_plane.data[current_mb];
2462
michael
parents: 2461
diff changeset
1854 if (v->condover == 3 && v->over_flags_plane.is_raw)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1855 over_flags_mb = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1856 GET_MQUANT();
2462
michael
parents: 2461
diff changeset
1857
michael
parents: 2461
diff changeset
1858 /* TODO: lots */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1859 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1860 current_mb++;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1861 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1862 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1863 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1864 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1865
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1866 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
1867 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1868 VC9Context *v = avctx->priv_data;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1869 MpegEncContext *s = &v->s;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1870 GetBitContext gb;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1871
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1872 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
1873 avctx->pix_fmt = PIX_FMT_YUV420P;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1874 v->s.avctx = avctx;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1875
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1876 if(ff_h263_decode_init(avctx) < 0)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1877 return -1;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1878 if (vc9_init_common(v) < 0) return -1;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1879
2462
michael
parents: 2461
diff changeset
1880 avctx->coded_width = avctx->width;
michael
parents: 2461
diff changeset
1881 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
1882 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
1883 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1884 int count = 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1885
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1886 // looks like WMV3 has a sequence header stored in the extradata
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1887 // advanced sequence header may be before the first frame
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1888 // the last byte of the extradata is a version number, 1 for the
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1889 // samples we can decode
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1890
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1891 init_get_bits(&gb, avctx->extradata, avctx->extradata_size);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1892
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1893 decode_sequence_header(avctx, &gb);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1894
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1895 count = avctx->extradata_size*8 - get_bits_count(&gb);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1896 if (count>0)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1897 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1898 av_log(avctx, AV_LOG_INFO, "Extra data: %i bits left, value: %X\n",
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1899 count, get_bits(&gb, count));
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1900 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1901 else
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1902 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1903 av_log(avctx, AV_LOG_INFO, "Read %i bits in overflow\n", -count);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1904 }
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1905 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1906 avctx->has_b_frames= !!(avctx->max_b_frames);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1907
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1908 s->mb_width = (avctx->coded_width+15)>>4;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1909 s->mb_height = (avctx->coded_height+15)>>4;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1910
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1911 /* Allocate mb bitplanes */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1912 if (alloc_bitplane(&v->mv_type_mb_plane, s->mb_width, s->mb_height) < 0)
2462
michael
parents: 2461
diff changeset
1913 return -1;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1914 if (alloc_bitplane(&v->mv_type_mb_plane, s->mb_width, s->mb_height) < 0)
2462
michael
parents: 2461
diff changeset
1915 return -1;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1916 if (alloc_bitplane(&v->skip_mb_plane, s->mb_width, s->mb_height) < 0)
2462
michael
parents: 2461
diff changeset
1917 return -1;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1918 if (alloc_bitplane(&v->direct_mb_plane, s->mb_width, s->mb_height) < 0)
2462
michael
parents: 2461
diff changeset
1919 return -1;
michael
parents: 2461
diff changeset
1920
michael
parents: 2461
diff changeset
1921 /* For predictors */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1922 v->previous_line_cbpcy = (uint8_t *)av_malloc(s->mb_stride*4);
2462
michael
parents: 2461
diff changeset
1923 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
1924
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1925 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1926 if (v->profile > PROFILE_MAIN)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1927 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1928 if (alloc_bitplane(&v->over_flags_plane, s->mb_width, s->mb_height) < 0)
2462
michael
parents: 2461
diff changeset
1929 return -1;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1930 if (alloc_bitplane(&v->ac_pred_plane, s->mb_width, s->mb_height) < 0)
2462
michael
parents: 2461
diff changeset
1931 return -1;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1932 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1933 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1934
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1935 return 0;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1936 }
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1937
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1938 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
1939 void *data, int *data_size,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1940 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
1941 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1942 VC9Context *v = avctx->priv_data;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1943 MpegEncContext *s = &v->s;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1944 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
1945 AVFrame *pict = data;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1946 uint8_t *tmp_buf;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1947 v->s.avctx = avctx;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1948
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1949 //buf_size = 0 -> last frame
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1950 if (!buf_size) return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1951
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1952 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
1953 avctx->height);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1954 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
1955 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
1956 avctx->width, avctx->height);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1957
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1958 if (avctx->codec_id == CODEC_ID_VC9)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1959 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1960 #if 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1961 // search for IDU's
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1962 // FIXME
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1963 uint32_t scp = 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1964 int scs = 0, i = 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1965
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1966 while (i < buf_size)
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 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
1969 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
1970
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1971 if (scp != 0x000001)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1972 break; // eof ?
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1973
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1974 scs = buf[i++];
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1975
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1976 init_get_bits(gb, buf+i, (buf_size-i)*8);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1977
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1978 switch(scs)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1979 {
2462
michael
parents: 2461
diff changeset
1980 case 0x0A: //Sequence End Code
michael
parents: 2461
diff changeset
1981 return 0;
michael
parents: 2461
diff changeset
1982 case 0x0B: //Slice Start Code
michael
parents: 2461
diff changeset
1983 av_log(avctx, AV_LOG_ERROR, "Slice coding not supported\n");
michael
parents: 2461
diff changeset
1984 return -1;
michael
parents: 2461
diff changeset
1985 case 0x0C: //Field start code
michael
parents: 2461
diff changeset
1986 av_log(avctx, AV_LOG_ERROR, "Interlaced coding not supported\n");
michael
parents: 2461
diff changeset
1987 return -1;
michael
parents: 2461
diff changeset
1988 case 0x0D: //Frame start code
michael
parents: 2461
diff changeset
1989 break;
michael
parents: 2461
diff changeset
1990 case 0x0E: //Entry point Start Code
michael
parents: 2461
diff changeset
1991 if (v->profile <= MAIN_PROFILE)
michael
parents: 2461
diff changeset
1992 av_log(avctx, AV_LOG_ERROR,
michael
parents: 2461
diff changeset
1993 "Found an entry point in profile %i\n", v->profile);
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1994 advanced_entry_point_process(avctx, gb);
2462
michael
parents: 2461
diff changeset
1995 break;
michael
parents: 2461
diff changeset
1996 case 0x0F: //Sequence header Start Code
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1997 decode_sequence_header(avctx, gb);
2462
michael
parents: 2461
diff changeset
1998 break;
michael
parents: 2461
diff changeset
1999 default:
michael
parents: 2461
diff changeset
2000 av_log(avctx, AV_LOG_ERROR,
michael
parents: 2461
diff changeset
2001 "Unsupported IDU suffix %lX\n", scs);
michael
parents: 2461
diff changeset
2002 }
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2003
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2004 i += get_bits_count(gb)*8;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2005 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2006 #else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2007 av_abort();
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2008 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2009 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2010 else
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2011 init_get_bits(&v->s.gb, buf, buf_size*8);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2012
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2013 s->flags= avctx->flags;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2014 s->flags2= avctx->flags2;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2015
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2016 /* no supplementary picture */
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2017 if (buf_size == 0) {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2018 /* special case for last picture */
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2019 if (s->low_delay==0 && s->next_picture_ptr) {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2020 *pict= *(AVFrame*)s->next_picture_ptr;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2021 s->next_picture_ptr= NULL;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2022
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2023 *data_size = sizeof(AVFrame);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2024 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2025
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2026 return 0;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2027 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2028
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2029 //No IDU - we mimic ff_h263_decode_frame
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2030 s->bitstream_buffer_size=0;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2031
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2032 if (!s->context_initialized) {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2033 if (MPV_common_init(s) < 0) //we need the idct permutaton for reading a custom matrix
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2034 return -1;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2035 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2036
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2037 //we need to set current_picture_ptr before reading the header, otherwise we cant store anyting im there
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2038 if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2039 s->current_picture_ptr= &s->picture[ff_find_unused_picture(s, 0)];
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2040 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2041 #if HAS_ADVANCED_PROFILE
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2042 if (v->profile > PROFILE_MAIN)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2043 ret= advanced_decode_picture_primary_header(v);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2044 else
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2045 #endif
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2046 ret= standard_decode_picture_primary_header(v);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2047 if (ret == FRAME_SKIPED) return buf_size;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2048 /* skip if the header was thrashed */
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2049 if (ret < 0){
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2050 av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2051 return -1;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2052 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2053
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2054 //No bug workaround yet, no DCT conformance
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2055
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2056 //WMV9 does have resized images
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2057 if (v->profile <= PROFILE_MAIN && v->multires){
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2058 //Parse context stuff in here, don't know how appliable it is
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2059 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2060 //Not sure about context initialization
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2061
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2062 // for hurry_up==5
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2063 s->current_picture.pict_type= s->pict_type;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2064 s->current_picture.key_frame= s->pict_type == I_TYPE;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2065
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2066 /* skip b frames if we dont have reference frames */
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2067 if(s->last_picture_ptr==NULL && (s->pict_type==B_TYPE || s->dropable))
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2068 return buf_size; //FIXME simulating all buffer consumed
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2069 /* skip b frames if we are in a hurry */
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2070 if(avctx->hurry_up && s->pict_type==B_TYPE)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2071 return buf_size; //FIXME simulating all buffer consumed
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2072 /* skip everything if we are in a hurry>=5 */
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2073 if(avctx->hurry_up>=5)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2074 return buf_size; //FIXME simulating all buffer consumed
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2075
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2076 if(s->next_p_frame_damaged){
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2077 if(s->pict_type==B_TYPE)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2078 return buf_size; //FIXME simulating all buffer consumed
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2079 else
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2080 s->next_p_frame_damaged=0;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2081 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2082
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2083 if(MPV_frame_start(s, avctx) < 0)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2084 return -1;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2085
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2086 ff_er_frame_start(s);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2087
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2088 //wmv9 may or may not have skip bits
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2089 #if HAS_ADVANCED_PROFILE
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2090 if (v->profile > PROFILE_MAIN)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2091 ret= advanced_decode_picture_secondary_header(v);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2092 else
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2093 #endif
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2094 ret = standard_decode_picture_secondary_header(v);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2095 if (ret<0) return FRAME_SKIPED; //FIXME Non fatal for now
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2096
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2097 //We consider the image coded in only one slice
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2098 #if HAS_ADVANCED_PROFILE
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2099 if (v->profile > PROFILE_MAIN)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2100 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2101 switch(s->pict_type)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2102 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2103 case I_TYPE: ret = advanced_decode_i_mbs(v); break;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2104 case P_TYPE: ret = decode_p_mbs(v); break;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2105 case B_TYPE:
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2106 case BI_TYPE: ret = decode_b_mbs(v); break;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2107 default: ret = FRAME_SKIPED;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2108 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2109 if (ret == FRAME_SKIPED) return buf_size; //We ignore for now failures
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2110 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2111 else
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2112 #endif
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2113 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2114 switch(s->pict_type)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2115 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2116 case I_TYPE: ret = standard_decode_i_mbs(v); break;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2117 case P_TYPE: ret = decode_p_mbs(v); break;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2118 case B_TYPE:
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2119 case BI_TYPE: ret = decode_b_mbs(v); break;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2120 default: ret = FRAME_SKIPED;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2121 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2122 if (ret == FRAME_SKIPED) return buf_size;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2123 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2124
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2125 ff_er_frame_end(s);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2126
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2127 MPV_frame_end(s);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2128
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2129 assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2130 assert(s->current_picture.pict_type == s->pict_type);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2131 if(s->pict_type==B_TYPE || s->low_delay){
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2132 *pict= *(AVFrame*)&s->current_picture;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2133 ff_print_debug_info(s, pict);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2134 } else {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2135 *pict= *(AVFrame*)&s->last_picture;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2136 if(pict)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2137 ff_print_debug_info(s, pict);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2138 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2139
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2140 /* Return the Picture timestamp as the frame number */
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2141 /* we substract 1 because it is added on utils.c */
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2142 avctx->frame_number = s->picture_number - 1;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2143
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2144 /* dont output the last pic after seeking */
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2145 if(s->last_picture_ptr || s->low_delay)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2146 *data_size = sizeof(AVFrame);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2147
2462
michael
parents: 2461
diff changeset
2148 av_log(avctx, AV_LOG_DEBUG, "Consumed %i/%i bits\n",
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2149 get_bits_count(&s->gb), buf_size*8);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2150
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2151 /* Fake consumption of all data */
2462
michael
parents: 2461
diff changeset
2152 *data_size = len;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2153 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
2154 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2155
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2156 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
2157 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2158 VC9Context *v = avctx->priv_data;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2159
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2160 #if HAS_ADVANCED_PROFILE
2458
915094e3da5d dont use several 100 mb memory for a tiny 120 element table
michael
parents: 2453
diff changeset
2161 av_freep(&v->hrd_rate);
915094e3da5d dont use several 100 mb memory for a tiny 120 element table
michael
parents: 2453
diff changeset
2162 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
2163 #endif
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2164 MPV_common_end(&v->s);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2165 free_bitplane(&v->mv_type_mb_plane);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2166 free_bitplane(&v->skip_mb_plane);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2167 free_bitplane(&v->direct_mb_plane);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2168 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2169 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2170
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2171 AVCodec vc9_decoder = {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2172 "vc9",
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2173 CODEC_TYPE_VIDEO,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2174 CODEC_ID_VC9,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2175 sizeof(VC9Context),
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2176 vc9_decode_init,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2177 NULL,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2178 vc9_decode_end,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2179 vc9_decode_frame,
2453
f67b63ed036d avoid buf_size == 0 checks in every decoder
michael
parents: 2445
diff changeset
2180 CODEC_CAP_DELAY,
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2181 NULL
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2182 };
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2183
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2184 AVCodec wmv3_decoder = {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2185 "wmv3",
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2186 CODEC_TYPE_VIDEO,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2187 CODEC_ID_WMV3,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2188 sizeof(VC9Context),
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2189 vc9_decode_init,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2190 NULL,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2191 vc9_decode_end,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2192 vc9_decode_frame,
2453
f67b63ed036d avoid buf_size == 0 checks in every decoder
michael
parents: 2445
diff changeset
2193 CODEC_CAP_DELAY,
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2194 NULL
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2195 };