annotate vc9.c @ 2464:ab390f13c7f5 libavcodec

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