annotate vc9.c @ 2489:2e5ae040e92b libavcodec

optimizing imdct36()
author michael
date Tue, 01 Feb 2005 21:27:18 +0000
parents 4eb9d61cad4e
children 69adfbbdcdeb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1 /*
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2 * VC-9 and WMV3 decoder
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
3 * Copyright (c) 2005 Anonymous
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
4 * Copyright (c) 2005 Alex Beregszaszi
2462
michael
parents: 2461
diff changeset
5 * Copyright (c) 2005 Michael Niedermayer
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
6 *
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
7 * This library is free software; you can redistribute it and/or
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
10 * version 2 of the License, or (at your option) any later version.
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
11 *
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
12 * This library is distributed in the hope that it will be useful,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
15 * Lesser General Public License for more details.
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
16 *
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
18 * License along with this library; if not, write to the Free Software
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
20 *
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
21 */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
22
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
23 /**
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
24 * @file vc9.c
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
25 * VC-9 and WMV3 decoder
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
26 *
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
27 * TODO: Norm-6 bitplane imode, most AP stuff, optimize, all of MB layer :)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
28 * TODO: use MPV_ !!
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
29 */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
30 #include "common.h"
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
31 #include "dsputil.h"
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
32 #include "avcodec.h"
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
33 #include "mpegvideo.h"
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
34 #include "vc9data.h"
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
35
2476
38dbec9a148d 100000l (typos in the #define for selecting the NORM6 method -> wasnt compiled, after fixing typos new method doesnt even compile -> swicth back to old until its fixed)
michael
parents: 2475
diff changeset
36 #undef NDEBUG
38dbec9a148d 100000l (typos in the #define for selecting the NORM6 method -> wasnt compiled, after fixing typos new method doesnt even compile -> swicth back to old until its fixed)
michael
parents: 2475
diff changeset
37 #include <assert.h>
38dbec9a148d 100000l (typos in the #define for selecting the NORM6 method -> wasnt compiled, after fixing typos new method doesnt even compile -> swicth back to old until its fixed)
michael
parents: 2475
diff changeset
38
2465
5565203c95ee use dc tables from msmpeg4 instead of duplicating them patch by anonymous
michael
parents: 2464
diff changeset
39 extern const uint32_t ff_table0_dc_lum[120][2], ff_table1_dc_lum[120][2];
5565203c95ee use dc tables from msmpeg4 instead of duplicating them patch by anonymous
michael
parents: 2464
diff changeset
40 extern const uint32_t ff_table0_dc_chroma[120][2], ff_table1_dc_chroma[120][2];
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
41 extern VLC ff_msmp4_dc_luma_vlc[2], ff_msmp4_dc_chroma_vlc[2];
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
42 #define MB_INTRA_VLC_BITS 9
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
43 extern VLC ff_msmp4_mb_i_vlc;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
44 #define DC_VLC_BITS 9
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
45 static const uint16_t table_mb_intra[64][2];
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
46
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
47 /* Some inhibiting stuff */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
48 #define HAS_ADVANCED_PROFILE 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
49 #define TRACE 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
50
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
51 #if TRACE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
52 # define INIT_VLC(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
53 codes, codes_wrap, codes_size, use_static) \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
54 if (init_vlc(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
55 codes, codes_wrap, codes_size, use_static) < 0) \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
56 { \
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
57 av_log(v->s.avctx, AV_LOG_ERROR, "Error for " # vlc " (%i)\n", i); \
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
58 return -1; \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
59 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
60 #else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
61 # define INIT_VLC(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
62 codes, codes_wrap, codes_size, use_static) \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
63 init_vlc(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
64 codes, codes_wrap, codes_size, use_static)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
65 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
66
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
67 /** Available Profiles */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
68 //@{
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
69 #define PROFILE_SIMPLE 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
70 #define PROFILE_MAIN 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
71 #define PROFILE_ADVANCED 3
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
72 //@}
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
73
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
74 /** Sequence quantizer mode */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
75 //@{
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
76 #define QUANT_FRAME_IMPLICIT 0 ///< Implicitly specified at frame level
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
77 #define QUANT_FRAME_EXPLICIT 1 ///< Explicitly specified at frame level
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
78 #define QUANT_NON_UNIFORM 2 ///< Non-uniform quant used for all frames
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
79 #define QUANT_UNIFORM 3 ///< Uniform quant used for all frames
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
80 //@}
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
81
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
82 /** Where quant can be changed */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
83 //@{
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
84 #define DQPROFILE_FOUR_EDGES 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
85 #define DQPROFILE_DOUBLE_EDGES 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
86 #define DQPROFILE_SINGLE_EDGE 2
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
87 #define DQPROFILE_ALL_MBS 3
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
88 //@}
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
89
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
90 /** @name Where quant can be changed
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
91 */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
92 //@{
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
93 #define DQPROFILE_FOUR_EDGES 0
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
94 #define DQSINGLE_BEDGE_LEFT 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
95 #define DQSINGLE_BEDGE_TOP 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
96 #define DQSINGLE_BEDGE_RIGHT 2
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
97 #define DQSINGLE_BEDGE_BOTTOM 3
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
98 //@}
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
99
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
100 /** Which pair of edges is quantized with ALTPQUANT */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
101 //@{
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
102 #define DQDOUBLE_BEDGE_TOPLEFT 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
103 #define DQDOUBLE_BEDGE_TOPRIGHT 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
104 #define DQDOUBLE_BEDGE_BOTTOMRIGHT 2
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
105 #define DQDOUBLE_BEDGE_BOTTOMLEFT 3
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
106 //@}
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
107
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
108 /** MV modes for P frames */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
109 //@{
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
110 #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
111 #define MV_PMODE_1MV 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
112 #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
113 #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
114 #define MV_PMODE_INTENSITY_COMP 4
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
115 //@}
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
116
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
117 /** @name MV types for B frames */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
118 //@{
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
119 #define BMV_TYPE_BACKWARD 0
2462
michael
parents: 2461
diff changeset
120 #define BMV_TYPE_BACKWARD 0
michael
parents: 2461
diff changeset
121 #define BMV_TYPE_FORWARD 1
michael
parents: 2461
diff changeset
122 #define BMV_TYPE_INTERPOLATED 3
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
123 //@}
2462
michael
parents: 2461
diff changeset
124
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
125 /** MV P mode - the 5th element is only used for mode 1 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
126 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
127 { 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
128 { 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
129 };
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
130
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
131 /** One more frame type */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
132 #define BI_TYPE 7
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
133
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
134 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
135 fps_dr[2] = { 1000, 1001 };
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
136 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
137 { /* Implicit quantizer */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
138 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
139 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
140 },
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
141 { /* Explicit quantizer, pquantizer uniform */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
142 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
143 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
144 },
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
145 { /* Explicit quantizer, pquantizer non-uniform */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
146 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
147 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
148 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
149 };
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
150
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
151 /** @name VC-9 VLC tables and defines
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
152 * @todo TODO move this into the context
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
153 */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
154 //@{
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
155 #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
156 static VLC vc9_bfraction_vlc;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
157 #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
158 static VLC vc9_imode_vlc;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
159 #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
160 static VLC vc9_norm2_vlc;
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
161 #if VLC_NORM6_METH0D == 1
2460
42077bb89a53 norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents: 2459
diff changeset
162 #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
163 static VLC vc9_norm6_vlc;
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
164 #endif
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
165 #if VLC_NORM6_METH0D == 2
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
166 #define VC9_NORM6_FIRST_BITS 8
2476
38dbec9a148d 100000l (typos in the #define for selecting the NORM6 method -> wasnt compiled, after fixing typos new method doesnt even compile -> swicth back to old until its fixed)
michael
parents: 2475
diff changeset
167 #define VC9_NORM6_SECOND_BITS 8
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
168 static VLC vc9_norm6_first_vlc, vc9_norm6_second_vlc;
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
169 #endif
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
170 /* Could be optimized, one table only needs 8 bits */
2462
michael
parents: 2461
diff changeset
171 #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
172 static VLC vc9_ttmb_vlc[3];
2462
michael
parents: 2461
diff changeset
173 #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
174 static VLC vc9_mv_diff_vlc[4];
2462
michael
parents: 2461
diff changeset
175 #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
176 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
177 #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
178 static VLC vc9_4mv_block_pattern_vlc[4];
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
179 //@}
2462
michael
parents: 2461
diff changeset
180
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
181 /** Bitplane struct
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
182 * We mainly need data and is_raw, so this struct could be avoided
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
183 * to save a level of indirection; feel free to modify
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
184 * @fixme For now, stride=width
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
185 * @warning Data are bits, either 1 or 0
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
186 */
2462
michael
parents: 2461
diff changeset
187 typedef struct BitPlane {
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
188 uint8_t *data; ///< Data buffer
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
189 int width; ///< Width of the buffer
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
190 int stride; ///< Stride of the buffer
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
191 int height; ///< Plane height
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
192 uint8_t is_raw; ///< Bit values must be read at MB level
2462
michael
parents: 2461
diff changeset
193 } BitPlane;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
194
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
195 /** The VC9 Context */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
196 typedef struct VC9Context{
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
197 MpegEncContext s;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
198
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
199 /** Simple/Main Profile sequence header */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
200 //@{
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
201 int res_sm; ///< reserved, 2b
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
202 int res_x8; ///< reserved
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
203 int multires; ///< frame-level RESPIC syntax element present
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
204 int res_fasttx; ///< reserved, always 1
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
205 int res_transtab; ///< reserved, always 0
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
206 int rangered; ///< RANGEREDFRM (range reduction) syntax element present
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
207 ///< at frame level
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
208 int res_rtm_flag; ///< reserved, set to 1
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
209 int reserved; ///< reserved
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
210 //@}
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
211
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
212 #if HAS_ADVANCED_PROFILE
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
213 /** Advanced Profile */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
214 //@{
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
215 int level; ///< 3bits, for Advanced/Simple Profile, provided by TS layer
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
216 int chromaformat; ///< 2bits, 2=4:2:0, only defined
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
217 int postprocflag; ///< Per-frame processing suggestion flag present
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
218 int broadcast; ///< TFF/RFF present
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
219 int interlace; ///< Progressive/interlaced (RPTFTM syntax element)
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
220 int tfcntrflag; ///< TFCNTR present
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
221 int panscanflag; ///< NUMPANSCANWIN, TOPLEFT{X,Y}, BOTRIGHT{X,Y} present
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
222 int extended_dmv; ///< Additional extended dmv range at P/B frame-level
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
223 int color_prim; ///< 8bits, chroma coordinates of the color primaries
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
224 int transfer_char; ///< 8bits, Opto-electronic transfer characteristics
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
225 int matrix_coef; ///< 8bits, Color primaries->YCbCr transform matrix
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
226 int hrd_param_flag; ///< Presence of Hypothetical Reference
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
227 ///< Decoder parameters
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
228 //@}
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
229 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
230
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
231
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
232 /** Sequence header data for all Profiles
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
233 * TODO: choose between ints, uint8_ts and monobit flags
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
234 */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
235 //@{
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
236 int profile; ///< 2bits, Profile
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
237 int frmrtq_postproc; ///< 3bits,
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
238 int bitrtq_postproc; ///< 5bits, quantized framerate-based postprocessing strength
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
239 int fastuvmc; ///< Rounding of qpel vector to hpel ? (not in Simple)
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
240 int extended_mv; ///< Ext MV in P/B (not in Simple)
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
241 int dquant; ///< How qscale varies with MBs, 2bits (not in Simple)
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
242 int vstransform; ///< variable-size [48]x[48] transform type + info
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
243 int overlap; ///< overlapped transforms in use
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
244 int quantizer_mode; ///< 2bits, quantizer mode used for sequence, see QUANT_*
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
245 int finterpflag; ///< INTERPFRM present
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
246 //@}
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
247
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
248 /** Frame decoding info for all profiles */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
249 //@{
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
250 uint8_t mv_mode; ///< MV coding monde
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
251 uint8_t mv_mode2; ///< Secondary MV coding mode (B frames)
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
252 uint8_t pq, altpq; ///< Current/alternate frame quantizer scale
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
253 /** pquant parameters */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
254 //@{
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
255 uint8_t dquantfrm;
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
256 uint8_t dqprofile;
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
257 uint8_t dqsbedge;
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
258 uint8_t dqbilevel;
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
259 //@}
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
260 int ac_table_level; ///< Index for AC tables from ACFRM element
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
261 VLC *luma_dc_vlc; ///< Pointer to current luma DC VLC table
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
262 VLC *chroma_dc_vlc; ///< Pointer to current luma AC VLC table
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
263 int ttfrm; ///< Transform type info present at frame level
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
264 uint8_t ttmbf; ///< Transform type
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
265 /** Luma compensation parameters */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
266 //@{
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
267 uint8_t lumscale;
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
268 uint8_t lumshift;
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
269 //@}
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
270 int16_t bfraction; ///< Relative position % anchors=> how to scale MVs
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
271 uint8_t halfpq; ///< Uniform quant over image and qp+.5
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
272 uint8_t respic; ///< Frame-level flag for resized images
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
273 int buffer_fullness; ///< HRD info
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
274 /** Ranges:
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
275 * -# 0 -> [-64n 63.f] x [-32, 31.f]
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
276 * -# 1 -> [-128, 127.f] x [-64, 63.f]
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
277 * -# 2 -> [-512, 511.f] x [-128, 127.f]
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
278 * -# 3 -> [-1024, 1023.f] x [-256, 255.f]
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
279 */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
280 uint8_t mvrange;
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
281 uint8_t pquantizer; ///< Uniform (over sequence) quantizer in use
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
282 uint8_t *previous_line_cbpcy; ///< To use for predicted CBPCY
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
283 VLC *cbpcy_vlc; ///< Current CBPCY VLC table
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
284 VLC *ttmb_vlc; ///< Current MB Transform Type VLC table
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
285 BitPlane mv_type_mb_plane; ///< bitplane for mv_type == (4MV)
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
286 BitPlane skip_mb_plane; ///< bitplane for skipped MBs
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
287 BitPlane 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
288
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
289 /** Frame decoding info for S/M profiles only */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
290 //@{
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
291 uint8_t rangeredfrm; ///< out_sample = CLIP((in_sample-128)*2+128)
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
292 uint8_t interpfrm;
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
293 //@}
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
294
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
295 #if HAS_ADVANCED_PROFILE
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
296 /** Frame decoding info for Advanced profile */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
297 //@{
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
298 uint8_t fcm; ///< 0->Progressive, 2->Frame-Interlace, 3->Field-Interlace
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
299 uint8_t numpanscanwin;
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
300 uint8_t tfcntr;
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
301 uint8_t rptfrm, tff, rff;
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
302 uint16_t topleftx;
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
303 uint16_t toplefty;
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
304 uint16_t bottomrightx;
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
305 uint16_t bottomrighty;
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
306 uint8_t uvsamp;
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
307 uint8_t postproc;
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
308 int hrd_num_leaky_buckets;
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
309 uint8_t bit_rate_exponent;
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
310 uint8_t buffer_size_exponent;
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
311 BitPlane ac_pred_plane; ///< AC prediction flags bitplane
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
312 BitPlane over_flags_plane; ///< Overflags bitplane
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
313 uint8_t condover;
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
314 uint16_t *hrd_rate, *hrd_buffer;
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
315 int ac2_table_level; ///< Index for AC2 tables from AC2FRM element
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
316 //@}
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
317 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
318 } VC9Context;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
319
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
320 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
321 * Get unary code of limited length
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
322 * @fixme FIXME Slow and ugly
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
323 * @param gb GetBitContext
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
324 * @param[in] stop The bitstop value (unary code of 1's or 0's)
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
325 * @param[in] len Maximum length
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
326 * @return Unary length/index
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
327 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
328 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
329 {
2462
michael
parents: 2461
diff changeset
330 #if 1
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
331 int i = 0, tmp = !stop;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
332
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
333 while (i != len && tmp != stop)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
334 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
335 tmp = get_bits(gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
336 i++;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
337 }
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
338 if (i == len && tmp != stop) return len+1;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
339 return i;
2462
michael
parents: 2461
diff changeset
340 #else
michael
parents: 2461
diff changeset
341 unsigned int buf;
michael
parents: 2461
diff changeset
342 int log;
michael
parents: 2461
diff changeset
343
michael
parents: 2461
diff changeset
344 OPEN_READER(re, gb);
michael
parents: 2461
diff changeset
345 UPDATE_CACHE(re, gb);
michael
parents: 2461
diff changeset
346 buf=GET_CACHE(re, gb); //Still not sure
michael
parents: 2461
diff changeset
347 if (stop) buf = ~buf;
michael
parents: 2461
diff changeset
348
michael
parents: 2461
diff changeset
349 log= av_log2(-buf); //FIXME: -?
michael
parents: 2461
diff changeset
350 if (log < limit){
michael
parents: 2461
diff changeset
351 LAST_SKIP_BITS(re, gb, log+1);
michael
parents: 2461
diff changeset
352 CLOSE_READER(re, gb);
michael
parents: 2461
diff changeset
353 return log;
michael
parents: 2461
diff changeset
354 }
michael
parents: 2461
diff changeset
355
michael
parents: 2461
diff changeset
356 LAST_SKIP_BITS(re, gb, limit);
michael
parents: 2461
diff changeset
357 CLOSE_READER(re, gb);
michael
parents: 2461
diff changeset
358 return limit;
michael
parents: 2461
diff changeset
359 #endif
michael
parents: 2461
diff changeset
360 }
michael
parents: 2461
diff changeset
361
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
362 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
363 * Init VC-9 specific tables and VC9Context members
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
364 * @param v The VC9Context to initialize
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
365 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
366 */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
367 static int vc9_init_common(VC9Context *v)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
368 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
369 static int done = 0;
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
370 int i = 0;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
371
2462
michael
parents: 2461
diff changeset
372 /* Set the bit planes */
michael
parents: 2461
diff changeset
373 v->mv_type_mb_plane = (struct BitPlane) { NULL, 0, 0, 0 };
michael
parents: 2461
diff changeset
374 v->direct_mb_plane = (struct BitPlane) { NULL, 0, 0, 0 };
michael
parents: 2461
diff changeset
375 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
376 #if HAS_ADVANCED_PROFILE
2462
michael
parents: 2461
diff changeset
377 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
378 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
379 #endif
2462
michael
parents: 2461
diff changeset
380
michael
parents: 2461
diff changeset
381 /* VLC tables */
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
382 #if VLC_NORM6_METH0D == 1
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
383 # if 0 // spec -> actual tables converter
2460
42077bb89a53 norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents: 2459
diff changeset
384 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
385 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
386 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
387 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
388 }
42077bb89a53 norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents: 2459
diff changeset
389 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
390 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
391 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
392 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
393 }
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
394 # endif
2460
42077bb89a53 norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents: 2459
diff changeset
395 #endif
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
396 if(!done)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
397 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
398 done = 1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
399 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
400 vc9_bfraction_bits, 1, 1,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
401 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
402 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
403 vc9_norm2_bits, 1, 1,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
404 vc9_norm2_codes, 1, 1, 1);
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
405 #if VLC_NORM6_METH0D == 1
2460
42077bb89a53 norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents: 2459
diff changeset
406 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
407 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
408 vc9_norm6_codes, 2, 2, 1);
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
409 #endif
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
410 #if VLC_NORM6_METH0D == 2
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
411 INIT_VLC(&vc9_norm6_first_vlc, VC9_NORM6_FIRST_BITS, 24,
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
412 &vc9_norm6_first[0][1], 1, 1,
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
413 &vc9_norm6_first[0][0], 1, 1, 1);
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
414 INIT_VLC(&vc9_norm6_second_vlc, VC9_NORM6_SECOND_BITS, 22,
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
415 &vc9_norm6_second[0][1], 1, 1,
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
416 &vc9_norm6_second[0][0], 1, 1, 1);
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
417 #endif
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
418 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
419 vc9_imode_bits, 1, 1,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
420 vc9_imode_codes, 1, 1, 1);
2462
michael
parents: 2461
diff changeset
421 for (i=0; i<3; i++)
michael
parents: 2461
diff changeset
422 {
michael
parents: 2461
diff changeset
423 INIT_VLC(&vc9_ttmb_vlc[i], VC9_TTMB_VLC_BITS, 16,
michael
parents: 2461
diff changeset
424 vc9_ttmb_bits[i], 1, 1,
michael
parents: 2461
diff changeset
425 vc9_ttmb_codes[i], 2, 2, 1);
michael
parents: 2461
diff changeset
426 }
michael
parents: 2461
diff changeset
427 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
428 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
429 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
430 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
431 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
432 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
433 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
434 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
435 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
436 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
437 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
438 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
439 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
440
2462
michael
parents: 2461
diff changeset
441 /* Other defaults */
michael
parents: 2461
diff changeset
442 v->pq = -1;
michael
parents: 2461
diff changeset
443 v->mvrange = 0; /* 7.1.1.18, p80 */
michael
parents: 2461
diff changeset
444
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
445 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
446 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
447
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
448 #if HAS_ADVANCED_PROFILE
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
449 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
450 * Decode sequence header's Hypothetic Reference Decoder data
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
451 * @see 6.2.1, p32
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
452 * @param v The VC9Context to initialize
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
453 * @param gb A GetBitContext initialized from AVCodecContext extra_data
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
454 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
455 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
456 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
457 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
458 int i, num;
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 num = get_bits(gb, 5);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
461
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
462 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
463 {
2458
915094e3da5d dont use several 100 mb memory for a tiny 120 element table
michael
parents: 2453
diff changeset
464 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
465 }
2462
michael
parents: 2461
diff changeset
466 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
467 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
468
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
469 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
470 {
2458
915094e3da5d dont use several 100 mb memory for a tiny 120 element table
michael
parents: 2453
diff changeset
471 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
472 }
2462
michael
parents: 2461
diff changeset
473 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
474 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
475
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
476 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
477
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
478 //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
479 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
480 //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
481 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
482
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
483 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
484 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
485 //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
486 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
487 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
488 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
489 av_log(v->s.avctx, AV_LOG_ERROR, "HDR Rates aren't strictly increasing:"
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
490 "%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
491 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
492 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
493 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
494 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
495 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
496 av_log(v->s.avctx, AV_LOG_ERROR, "HDR Buffers aren't decreasing:"
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
497 "%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
498 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
499 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
500 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
501 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
502 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
503
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
504 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
505 * Decode sequence header for Advanced Profile
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
506 * @see Table 2, p18
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
507 * @see 6.1.7, pp21-27
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
508 * @param v The VC9Context to initialize
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
509 * @param gb A GetBitContext initialized from AVCodecContext extra_data
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
510 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
511 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
512 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
513 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
514 VC9Context *v = avctx->priv_data;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
515 int nr, dr, aspect_ratio;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
516
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
517 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
518 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
519 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
520
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
521 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
522 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
523 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
524 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
525 if (v->reserved)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
526 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
527 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
528 v->reserved);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
529 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
530 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
531 if (v->extended_mv)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
532 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
533
2462
michael
parents: 2461
diff changeset
534 /* 6.1.7, p21 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
535 if (get_bits(gb, 1) /* pic_size_flag */)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
536 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
537 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
538 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
539 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
540 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
541 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
542 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
543 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
544
2462
michael
parents: 2461
diff changeset
545 /* 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
546 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
547 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
548 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
549 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
550 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
551 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
552 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
553 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
554 else if (aspect_ratio == 0x0E)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
555 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
556 av_log(avctx, AV_LOG_DEBUG, "Reserved AR found\n");
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 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
559 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
560 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
561 }
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 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
564 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
565 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
566 avctx->coded_width = avctx->width;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
567 avctx->coded_height = avctx->height;
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
2462
michael
parents: 2461
diff changeset
570 /* 6.1.8, p23 */
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
571 if ( !get_bits(gb, 1) /* framerateflag */)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
572 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
573 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
574 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
575 nr = get_bits(gb, 8);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
576 dr = get_bits(gb, 4);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
577 if (nr<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 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
580 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
581 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
582 if (nr>5)
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 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
585 "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
586 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
587 if (dr<1)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
588 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
589 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
590 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
591 if (dr>2)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
592 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
593 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
594 "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
595 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
596 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
597 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
598 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
599 else
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 nr = get_bits(gb, 16);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
602 // 0.03125->2048Hz / 0.03125Hz
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
603 avctx->frame_rate = 1000000;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
604 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
605 }
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
2462
michael
parents: 2461
diff changeset
608 /* 6.1.9, p25 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
609 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
610 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
611 //Chromacity coordinates of color primaries
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
612 //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
613 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
614 if (v->color_prim<1)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
615 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
616 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
617 return -1;
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 (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
620 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
621 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
622 v->color_prim);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
623 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
624 }
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 //Opto-electronic transfer characteristics
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
627 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
628 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
629 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
630 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
631 v->color_prim);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
632 return -1;
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
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
635 //Matrix coefficient for primariev->YCbCr
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
636 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
637 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
638 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
639 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
640 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
641 v->color_prim);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
642 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
643 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
644 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
645
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
646 //Hypothetical reference decoder indicator flag
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
647 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
648 if (v->hrd_param_flag)
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 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
651 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
652
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
653 av_log(avctx, AV_LOG_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
654 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
655 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
656 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
657
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
658 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
659 * Decode Simple/Main Profiles sequence header
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
660 * @see Figure 7-8, p16-17
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
661 * @param avctx Codec context
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
662 * @param gb GetBit context initialized from Codec context extra_data
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
663 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
664 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
665 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
666 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
667 VC9Context *v = avctx->priv_data;
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 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
670 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
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 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
675 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
676 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
677 if (v->chromaformat != 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 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
680 "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
681 return -1;
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 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
684 else
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->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
688 if (v->res_sm)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
689 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
690 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
691 "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
692 //return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
693 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
694 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
695
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
696 // (fps-2)/4 (->30)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
697 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
698 // (bitrate-32kbps)/64kbps
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
699 v->bitrtq_postproc = get_bits(gb, 5); //common
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
700 v->s.loop_filter = get_bits(gb, 1); //common
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
701
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
702 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
703 if (v->profile <= PROFILE_MAIN)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
704 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
705 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
706 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
707 if (v->res_x8)
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 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
710 "1 for reserved RES_X8 is forbidden\n");
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
711 //return -1;
2445
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 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
714 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
715 if (!v->res_fasttx)
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 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
718 "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
719 //return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
720 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
721 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
722
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
723 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
724 if (!v->profile && !v->fastuvmc)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
725 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
726 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
727 "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
728 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
729 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
730 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
731 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
732 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
733 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
734 "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
735 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
736 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
737 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
738 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
739
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
740 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
741 if (v->profile <= PROFILE_MAIN)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
742 #endif
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 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
745 if (v->res_transtab)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
746 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
747 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
748 "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
749 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
750 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
751 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
752
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
753 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
754
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
755 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
756 if (v->profile <= PROFILE_MAIN)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
757 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
758 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
759 v->s.resync_marker = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
760 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
761 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
762
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
763 v->s.max_b_frames = avctx->max_b_frames = get_bits(gb, 3); //common
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
764 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
765
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
766 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
767 if (v->profile <= PROFILE_MAIN)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
768 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
769 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
770 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
771 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
772 if (!v->res_rtm_flag)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
773 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
774 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
775 "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
776 //return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
777 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
778 #if TRACE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
779 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
780 "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
781 "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
782 "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
783 "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
784 v->profile, v->frmrtq_postproc, v->bitrtq_postproc,
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
785 v->s.loop_filter, v->multires, v->fastuvmc, v->extended_mv,
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
786 v->rangered, v->vstransform, v->overlap, v->s.resync_marker,
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
787 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
788 );
2462
michael
parents: 2461
diff changeset
789 return 0;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
790 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
791 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
792 #if HAS_ADVANCED_PROFILE
2462
michael
parents: 2461
diff changeset
793 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
794 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
795 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
796
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
797
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
798 #if HAS_ADVANCED_PROFILE
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
799 /** Entry point decoding (Advanced Profile)
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
800 * @param avctx Codec context
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
801 * @param gb GetBit context initialized from avctx->extra_data
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
802 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
803 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
804 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
805 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
806 VC9Context *v = avctx->priv_data;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
807 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
808 if (v->profile != PROFILE_ADVANCED)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
809 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
810 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
811 "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
812 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
813 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
814 if (v->hrd_param_flag)
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 //Update buffer fullness
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
817 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
818 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
819 skip_bits(gb, 8);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
820 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
821 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
822 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
823 //RANGE_MAPY
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
824 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
825 skip_bits(gb, 3);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
826 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
827 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
828 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
829 //RANGE_MAPUV
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
830 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
831 skip_bits(gb, 3);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
832 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
833 if (v->panscanflag)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
834 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
835 //NUMPANSCANWIN
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
836 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
837 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
838 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
839 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
840 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
841 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
842
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
843 /***********************************************************************/
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
844 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
845 * @defgroup bitplane VC9 Bitplane decoding
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
846 * @see 8.7, p56
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
847 * @{
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
848 */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
849
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
850 /** @addtogroup bitplane
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
851 * Imode types
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
852 * @{
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
853 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
854 #define IMODE_RAW 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
855 #define IMODE_NORM2 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
856 #define IMODE_DIFF2 2
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
857 #define IMODE_NORM6 3
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
858 #define IMODE_DIFF6 4
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
859 #define IMODE_ROWSKIP 5
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
860 #define IMODE_COLSKIP 6
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
861 /** @} */ //imode defines
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
862
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
863 /** Allocate the buffer from a bitplane, given its dimensions
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
864 * @param bp Bitplane which buffer is to allocate
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
865 * @param[in] width Width of the buffer
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
866 * @param[in] height Height of the buffer
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
867 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
868 * @todo TODO: Take into account stride
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
869 * @todo TODO: Allow use of external buffers ?
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
870 */
2462
michael
parents: 2461
diff changeset
871 int alloc_bitplane(BitPlane *bp, int width, int height)
michael
parents: 2461
diff changeset
872 {
michael
parents: 2461
diff changeset
873 if (!bp || bp->width<0 || bp->height<0) return -1;
michael
parents: 2461
diff changeset
874 bp->data = (uint8_t*)av_malloc(width*height);
michael
parents: 2461
diff changeset
875 if (!bp->data) return -1;
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
876 bp->width = bp->stride = width;
2462
michael
parents: 2461
diff changeset
877 bp->height = height;
michael
parents: 2461
diff changeset
878 return 0;
michael
parents: 2461
diff changeset
879 }
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
880
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
881 /** Free the bitplane's buffer
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
882 * @param bp Bitplane which buffer is to free
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
883 */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
884 void free_bitplane(BitPlane *bp)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
885 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
886 bp->width = bp->stride = bp->height = 0;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
887 if (bp->data) av_freep(&bp->data);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
888 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
889
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
890 /** Decode rows by checking if they are skiped
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
891 * @param plane Buffer to store decoded bits
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
892 * @param[in] width Width of this buffer
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
893 * @param[in] height Height of this buffer
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
894 * @param[in] stride of this buffer
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
895 */
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
896 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
897 int x, y;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
898 GetBitContext *gb = &v->s.gb;
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
899
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
900 for (y=0; y<height; y++){
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
901 if (!get_bits(gb, 1)) //rowskip
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
902 memset(plane, 0, width);
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
903 else
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
904 for (x=0; x<width; x++)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
905 plane[x] = get_bits(gb, 1);
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
906 plane += stride;
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
907 }
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
908 }
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
909
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
910 /** Decode columns by checking if they are skiped
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
911 * @param plane Buffer to store decoded bits
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
912 * @param[in] width Width of this buffer
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
913 * @param[in] height Height of this buffer
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
914 * @param[in] stride of this buffer
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
915 * @fixme FIXME: Optimize
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
916 */
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
917 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
918 int x, y;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
919 GetBitContext *gb = &v->s.gb;
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
920
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
921 for (x=0; x<width; x++){
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
922 if (!get_bits(gb, 1)) //colskip
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
923 for (y=0; y<height; y++)
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
924 plane[y*stride] = 0;
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
925 else
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
926 for (y=0; y<height; y++)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
927 plane[y*stride] = get_bits(gb, 1);
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
928 plane ++;
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
929 }
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
930 }
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
931
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
932 /** Decode a bitplane's bits
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
933 * @param bp Bitplane where to store the decode bits
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
934 * @param v VC9 context for bit reading and logging
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
935 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
936 * @fixme FIXME: Optimize
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
937 * @todo TODO: Decide if a struct is needed
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
938 */
2462
michael
parents: 2461
diff changeset
939 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
940 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
941 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
942
2462
michael
parents: 2461
diff changeset
943 int imode, x, y, code, use_vertical_tile, tile_w, tile_h;
michael
parents: 2461
diff changeset
944 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
945
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
946 invert = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
947 imode = get_vlc2(gb, vc9_imode_vlc.table, VC9_IMODE_VLC_BITS, 2);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
948
2462
michael
parents: 2461
diff changeset
949 bp->is_raw = 0;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
950 switch (imode)
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 case IMODE_RAW:
2462
michael
parents: 2461
diff changeset
953 //Data is actually read in the MB layer (same for all tests == "raw")
michael
parents: 2461
diff changeset
954 bp->is_raw = 1; //invert ignored
michael
parents: 2461
diff changeset
955 return invert;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
956 case IMODE_DIFF2:
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
957 case IMODE_NORM2:
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
958 if ((bp->height*bp->width) & 1) *(++planep) = get_bits(gb, 1);
2462
michael
parents: 2461
diff changeset
959 for(x=0; x<(bp->height*bp->width)>>1; x++){
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
960 code = get_vlc2(gb, vc9_norm2_vlc.table, VC9_NORM2_VLC_BITS, 2);
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
961 *(++planep) = code&1; //lsb => left
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
962 *(++planep) = (code>>1)&1; //msb => right
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
963 //FIXME width->stride
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
964 }
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
965 break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
966 case IMODE_DIFF6:
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
967 case IMODE_NORM6:
2462
michael
parents: 2461
diff changeset
968 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
969 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
970 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
971
2462
michael
parents: 2461
diff changeset
972 for(y= bp->height%tile_h; y< bp->height; y+=tile_h){
michael
parents: 2461
diff changeset
973 for(x= bp->width%tile_w; x< bp->width; x+=tile_w){
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
974 #if VLC_NORM6_METH0D == 1
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
975 code = get_vlc2(gb, vc9_norm6_vlc.table, VC9_NORM6_VLC_BITS, 2);
2463
9baa47d8297b check norm6 vlc validity as there are some bit sequences which dont corespond to any codeword, the other vlc tables all seem to be huffman tables though
michael
parents: 2462
diff changeset
976 if(code<0){
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
977 av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");
2463
9baa47d8297b check norm6 vlc validity as there are some bit sequences which dont corespond to any codeword, the other vlc tables all seem to be huffman tables though
michael
parents: 2462
diff changeset
978 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
979 }
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
980 #endif
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
981 #if VLC_NORM6_METH0D == 2 //Failure
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
982 code = get_vlc2(gb, vc9_norm6_first_vlc.table, VC9_NORM6_FIRST_BITS, 2);
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
983 if (code == 22)
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
984 {
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
985 code = vc9_norm6_flc_val[get_bits(gb, 5)];
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
986 }
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
987 else if (code == 23)
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
988 {
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
989 # if TRACE
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
990 code = get_vlc2(gb, vc9_norm6_second_vlc.table, VC9_NORM6_SECOND_BITS, 2);
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
991 assert(code>-1 && code<22);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
992 code = vc9_norm6_second_val[code];
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
993 # else
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
994 code = vc9_norm6_second_val[get_vlc2(gb, vc9_norm6_second_vlc.table, VC9_NORM6_SECOND_BITS, 2)];
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
995 # endif
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
996 }
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
997 #endif //VLC_NORM6_METH0D == 2
2460
42077bb89a53 norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents: 2459
diff changeset
998 //FIXME following is a pure guess and probably wrong
2462
michael
parents: 2461
diff changeset
999 //FIXME A bitplane (0 | !0), so could the shifts be avoided ?
michael
parents: 2461
diff changeset
1000 planep[x + 0*bp->stride]= (code>>0)&1;
michael
parents: 2461
diff changeset
1001 planep[x + 1 + 0*bp->stride]= (code>>1)&1;
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1002 //FIXME Does branch prediction help here?
2460
42077bb89a53 norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents: 2459
diff changeset
1003 if(use_vertical_tile){
2462
michael
parents: 2461
diff changeset
1004 planep[x + 0 + 1*bp->stride]= (code>>2)&1;
michael
parents: 2461
diff changeset
1005 planep[x + 1 + 1*bp->stride]= (code>>3)&1;
michael
parents: 2461
diff changeset
1006 planep[x + 0 + 2*bp->stride]= (code>>4)&1;
michael
parents: 2461
diff changeset
1007 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
1008 }else{
2462
michael
parents: 2461
diff changeset
1009 planep[x + 2 + 0*bp->stride]= (code>>2)&1;
michael
parents: 2461
diff changeset
1010 planep[x + 0 + 1*bp->stride]= (code>>3)&1;
michael
parents: 2461
diff changeset
1011 planep[x + 1 + 1*bp->stride]= (code>>4)&1;
michael
parents: 2461
diff changeset
1012 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
1013 }
42077bb89a53 norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents: 2459
diff changeset
1014 }
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
1015 }
2460
42077bb89a53 norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents: 2459
diff changeset
1016
2462
michael
parents: 2461
diff changeset
1017 x= bp->width % tile_w;
michael
parents: 2461
diff changeset
1018 decode_colskip(bp->data , x, bp->height , bp->stride, v);
michael
parents: 2461
diff changeset
1019 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
1020
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1021 break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1022 case IMODE_ROWSKIP:
2462
michael
parents: 2461
diff changeset
1023 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
1024 break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1025 case IMODE_COLSKIP: //Teh ugly
2462
michael
parents: 2461
diff changeset
1026 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
1027 break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1028 default: break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1029 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1030
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1031 /* Applying diff operator */
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
1032 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
1033 {
2462
michael
parents: 2461
diff changeset
1034 planep = bp->data;
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
1035 planep[0] ^= invert;
2462
michael
parents: 2461
diff changeset
1036 for (x=1; x<bp->width; x++)
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
1037 planep[x] ^= planep[x-1];
2462
michael
parents: 2461
diff changeset
1038 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
1039 {
2462
michael
parents: 2461
diff changeset
1040 planep += bp->stride;
michael
parents: 2461
diff changeset
1041 planep[0] ^= planep[-bp->stride];
michael
parents: 2461
diff changeset
1042 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
1043 {
2462
michael
parents: 2461
diff changeset
1044 if (planep[x-1] != planep[x-bp->stride]) planep[x] ^= invert;
michael
parents: 2461
diff changeset
1045 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
1046 }
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 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1049 else if (invert)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1050 {
2462
michael
parents: 2461
diff changeset
1051 planep = bp->data;
michael
parents: 2461
diff changeset
1052 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
1053 }
2462
michael
parents: 2461
diff changeset
1054 return (imode<<1) + invert;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1055 }
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1056 /** @} */ //Bitplane group
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1057
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1058 /***********************************************************************/
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1059 /** VOP Dquant decoding
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1060 * @param v VC9 Context
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1061 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1062 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
1063 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1064 GetBitContext *gb = &v->s.gb;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1065 int pqdiff;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1066
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1067 //variable size
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1068 if (v->dquant == 2)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1069 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1070 pqdiff = get_bits(gb, 3);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1071 if (pqdiff == 7) v->altpq = get_bits(gb, 5);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1072 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
1073 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1074 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1075 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1076 v->dquantfrm = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1077 if ( v->dquantfrm )
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1078 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1079 v->dqprofile = get_bits(gb, 2);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1080 switch (v->dqprofile)
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 case DQPROFILE_SINGLE_EDGE:
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1083 case DQPROFILE_DOUBLE_EDGES:
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1084 v->dqsbedge = get_bits(gb, 2);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1085 break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1086 case DQPROFILE_ALL_MBS:
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1087 v->dqbilevel = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1088 default: break; //Forbidden ?
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 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
1091 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1092 pqdiff = get_bits(gb, 3);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1093 if (pqdiff == 7) v->altpq = get_bits(gb, 5);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1094 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
1095 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1096 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1097 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1098 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1099 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1100
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1101 /***********************************************************************/
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1102 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1103 * @defgroup all_frame_hdr All VC9 profiles frame header
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1104 * @brief Part of the frame header decoding from all profiles
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1105 * @warning Only pro/epilog differs between Simple/Main and Advanced => check caller
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1106 * @{
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1107 */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1108 /** B and BI frame header decoding, primary part
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1109 * @see Tables 11+12, p62-65
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1110 * @param v VC9 context
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1111 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1112 * @warning Also handles BI frames
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1113 */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1114 static int decode_b_picture_primary_header(VC9Context *v)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1115 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1116 GetBitContext *gb = &v->s.gb;
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1117 int pqindex;
2445
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 /* 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
1120 if (v->profile == PROFILE_SIMPLE)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1121 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1122 av_log(v->s.avctx, AV_LOG_ERROR, "Found a B frame while in Simple Profile!\n");
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1123 return FRAME_SKIPED;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1124 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1125 v->bfraction = vc9_bfraction_lut[get_vlc2(gb, vc9_bfraction_vlc.table,
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1126 VC9_BFRACTION_VLC_BITS, 2)];
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1127 if (v->bfraction < -1)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1128 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1129 av_log(v->s.avctx, AV_LOG_ERROR, "Invalid BFRaction\n");
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1130 return FRAME_SKIPED;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1131 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1132 else if (!v->bfraction)
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 /* We actually have a BI frame */
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1135 v->s.pict_type = BI_TYPE;
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1136 v->buffer_fullness = get_bits(gb, 7);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1137 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1138
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1139 /* Read the quantization stuff */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1140 pqindex = get_bits(gb, 5);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1141 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
1142 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
1143 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1144 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1145 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
1146 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1147 if (pqindex < 9) v->halfpq = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1148 if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1149 v->pquantizer = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1150
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1151 if (v->profile > PROFILE_MAIN)
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1152 {
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1153 if (v->postprocflag) v->postproc = get_bits(gb, 2);
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1154 if (v->extended_mv == 1 && v->s.pict_type != BI_TYPE)
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1155 v->mvrange = get_prefix(gb, 0, 3);
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1156 }
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1157 else
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1158 {
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1159 if (v->extended_mv == 1)
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1160 v->mvrange = get_prefix(gb, 0, 3);
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1161 }
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1162 /* Read the MV mode */
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1163 if (v->s.pict_type != BI_TYPE)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1164 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1165 v->mv_mode = get_bits(gb, 1);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1166 if (v->pq < 13)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1167 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1168 if (!v->mv_mode)
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1169 {
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1170 v->mv_mode = get_bits(gb, 2);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1171 if (v->mv_mode)
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1172 av_log(v->s.avctx, AV_LOG_ERROR,
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1173 "mv_mode for lowquant B frame was %i\n", v->mv_mode);
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1174 }
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1175 }
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1176 else
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1177 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1178 if (!v->mv_mode)
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1179 {
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1180 if (get_bits(gb, 1))
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1181 av_log(v->s.avctx, AV_LOG_ERROR,
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1182 "mv_mode for highquant B frame was %i\n", v->mv_mode);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1183 }
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1184 v->mv_mode = 1-v->mv_mode; //To match (pq < 13) mapping
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1185 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1186 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1187
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1188 return 0;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1189 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1190
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1191 /** B and BI frame header decoding, secondary part
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1192 * @see Tables 11+12, p62-65
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1193 * @param v VC9 context
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1194 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1195 * @warning Also handles BI frames
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1196 * @warning To call once all MB arrays are allocated
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1197 * @todo Support Advanced Profile headers
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1198 */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1199 static int decode_b_picture_secondary_header(VC9Context *v)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1200 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1201 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1202 int status;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1203
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1204 status = bitplane_decoding(&v->skip_mb_plane, v);
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1205 if (status < 0) return -1;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1206 #if TRACE
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1207 if (v->mv_mode == MV_PMODE_MIXED_MV)
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->mv_type_mb_plane, v);
michael
parents: 2461
diff changeset
1210 if (status < 0)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1211 return -1;
2462
michael
parents: 2461
diff changeset
1212 #if TRACE
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1213 av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
2462
michael
parents: 2461
diff changeset
1214 "Imode: %i, Invert: %i\n", status>>1, status&1);
michael
parents: 2461
diff changeset
1215 #endif
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1216 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1217
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1218 //bitplane
2462
michael
parents: 2461
diff changeset
1219 status = bitplane_decoding(&v->direct_mb_plane, v);
michael
parents: 2461
diff changeset
1220 if (status < 0) return -1;
michael
parents: 2461
diff changeset
1221 #if TRACE
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1222 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct plane encoding: "
2462
michael
parents: 2461
diff changeset
1223 "Imode: %i, Invert: %i\n", status>>1, status&1);
michael
parents: 2461
diff changeset
1224 #endif
michael
parents: 2461
diff changeset
1225
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1226 av_log(v->s.avctx, AV_LOG_DEBUG, "Skip MB plane encoding: "
2462
michael
parents: 2461
diff changeset
1227 "Imode: %i, Invert: %i\n", status>>1, status&1);
michael
parents: 2461
diff changeset
1228 #endif
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1229
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1230 /* FIXME: what is actually chosen for B frames ? */
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1231 v->s.mv_table_index = get_bits(gb, 2); //but using vc9_ tables
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1232 v->cbpcy_vlc = &vc9_cbpcy_p_vlc[get_bits(gb, 2)];
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1233
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1234 if (v->dquant)
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 vop_dquant_decoding(v);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1237 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1238
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1239 if (v->vstransform)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1240 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1241 v->ttmbf = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1242 if (v->ttmbf)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1243 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1244 v->ttfrm = get_bits(gb, 2);
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1245 av_log(v->s.avctx, AV_LOG_INFO, "Transform used: %ix%i\n",
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1246 (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
1247 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1248 }
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1249 /* Epilog (AC/DC syntax) should be done in caller */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1250 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1251 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1252
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1253 /** I frame header decoding, primary part
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1254 * @see Tables 5+7, p53-54 and 55-57
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1255 * @param v VC9 context
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1256 * @return Status
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1257 * @todo Support Advanced Profile headers
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1258 */
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1259 static int decode_i_picture_primary_header(VC9Context *v)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1260 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1261 GetBitContext *gb = &v->s.gb;
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1262 int pqindex;
2445
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 /* 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
1265 //BF = Buffer Fullness
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1266 if (v->profile <= PROFILE_MAIN && get_bits(gb, 7))
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1267 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1268 av_log(v->s.avctx, AV_LOG_DEBUG, "I BufferFullness not 0\n");
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1269 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1270
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1271 /* Quantizer stuff */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1272 pqindex = get_bits(gb, 5);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1273 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
1274 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
1275 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1276 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1277 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
1278 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1279 if (pqindex < 9) v->halfpq = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1280 if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1281 v->pquantizer = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1282 av_log(v->s.avctx, AV_LOG_DEBUG, "I frame: QP=%i (+%i/2)\n",
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1283 v->pq, v->halfpq);
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1284 return 0;
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1285 }
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1286
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1287 /** I frame header decoding, secondary part
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1288 * @param v VC9 context
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1289 * @return Status
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1290 * @todo Support Advanced Profile headers
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1291 */
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1292 static int decode_i_picture_secondary_header(VC9Context *v)
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1293 {
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1294 int status;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1295 #if HAS_ADVANCED_PROFILE
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1296 if (v->profile > PROFILE_MAIN)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1297 {
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1298 v->s.ac_pred = get_bits(&v->s.gb, 1);
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1299 if (v->postprocflag) v->postproc = get_bits(&v->s.gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1300 /* 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
1301 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
1302 {
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1303 v->condover = get_bits(&v->s.gb, 1);
2462
michael
parents: 2461
diff changeset
1304 if (v->condover)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1305 {
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1306 v->condover = 2+get_bits(&v->s.gb, 1);
2462
michael
parents: 2461
diff changeset
1307 if (v->condover == 3)
michael
parents: 2461
diff changeset
1308 {
michael
parents: 2461
diff changeset
1309 status = bitplane_decoding(&v->over_flags_plane, v);
michael
parents: 2461
diff changeset
1310 if (status < 0) return -1;
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1311 # if TRACE
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1312 av_log(v->s.avctx, AV_LOG_DEBUG, "Overflags plane encoding: "
2462
michael
parents: 2461
diff changeset
1313 "Imode: %i, Invert: %i\n", status>>1, status&1);
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1314 # endif
2462
michael
parents: 2461
diff changeset
1315 }
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1316 }
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 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1320
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1321 /* Epilog (AC/DC syntax) should be done in caller */
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1322 return 0;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1323 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1324
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1325 /** P frame header decoding, primary part
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1326 * @see Tables 5+7, p53-54 and 55-57
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1327 * @param v VC9 context
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1328 * @todo Support Advanced Profile headers
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1329 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1330 */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1331 static int decode_p_picture_primary_header(VC9Context *v)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1332 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1333 /* INTERFRM, FRMCNT, RANGEREDFRM read in caller */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1334 GetBitContext *gb = &v->s.gb;
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1335 int lowquant, pqindex;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1336
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1337 pqindex = get_bits(gb, 5);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1338 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
1339 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
1340 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1341 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1342 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
1343 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1344 if (pqindex < 9) v->halfpq = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1345 if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1346 v->pquantizer = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1347 av_log(v->s.avctx, AV_LOG_DEBUG, "P Frame: QP=%i (+%i/2)\n",
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1348 v->pq, v->halfpq);
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1349 if (v->extended_mv == 1) v->mvrange = get_prefix(gb, 0, 3);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1350 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1351 if (v->profile > PROFILE_MAIN)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1352 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1353 if (v->postprocflag) v->postproc = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1354 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1355 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1356 #endif
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1357 if (v->multires) v->respic = get_bits(gb, 2);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1358 lowquant = (v->pquantizer>12) ? 0 : 1;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1359 v->mv_mode = mv_pmode_table[lowquant][get_prefix(gb, 1, 4)];
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1360 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
1361 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1362 v->mv_mode2 = mv_pmode_table[lowquant][get_prefix(gb, 1, 3)];
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1363 v->lumscale = get_bits(gb, 6);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1364 v->lumshift = get_bits(gb, 6);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1365 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1366 return 0;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1367 }
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1368
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1369 /** P frame header decoding, secondary part
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1370 * @see Tables 5+7, p53-54 and 55-57
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1371 * @param v VC9 context
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1372 * @warning To call once all MB arrays are allocated
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1373 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1374 */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1375 static int decode_p_picture_secondary_header(VC9Context *v)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1376 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1377 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1378 int status = 0;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1379 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
1380 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
1381 || 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
1382 {
2462
michael
parents: 2461
diff changeset
1383 status = bitplane_decoding(&v->mv_type_mb_plane, v);
michael
parents: 2461
diff changeset
1384 if (status < 0) return -1;
michael
parents: 2461
diff changeset
1385 #if TRACE
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1386 av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
2462
michael
parents: 2461
diff changeset
1387 "Imode: %i, Invert: %i\n", status>>1, status&1);
michael
parents: 2461
diff changeset
1388 #endif
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1389 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1390
2462
michael
parents: 2461
diff changeset
1391 status = bitplane_decoding(&v->skip_mb_plane, v);
michael
parents: 2461
diff changeset
1392 if (status < 0) return -1;
michael
parents: 2461
diff changeset
1393 #if TRACE
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1394 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
2462
michael
parents: 2461
diff changeset
1395 "Imode: %i, Invert: %i\n", status>>1, status&1);
michael
parents: 2461
diff changeset
1396 #endif
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1397
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1398 /* Hopefully this is correct for P frames */
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1399 v->s.mv_table_index =get_bits(gb, 2); //but using vc9_ tables
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1400 v->cbpcy_vlc = &vc9_cbpcy_p_vlc[get_bits(gb, 2)];
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1401
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1402 if (v->dquant)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1403 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1404 av_log(v->s.avctx, AV_LOG_INFO, "VOP DQuant info\n");
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1405 vop_dquant_decoding(v);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1406 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1407
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1408 v->ttfrm = 0; //FIXME Is that so ?
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1409 if (v->vstransform)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1410 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1411 v->ttmbf = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1412 if (v->ttmbf)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1413 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1414 v->ttfrm = get_bits(gb, 2);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1415 av_log(v->s.avctx, AV_LOG_INFO, "Transform used: %ix%i\n",
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1416 (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
1417 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1418 }
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1419 /* Epilog (AC/DC syntax) should be done in caller */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1420 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1421 }
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1422 /** @} */ //End of group all_frm_hdr
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1423
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1424
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1425 /***********************************************************************/
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1426 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1427 * @defgroup std_frame_hdr VC9 Simple/Main Profiles header decoding
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1428 * @brief Part of the frame header decoding belonging to Simple/Main Profiles
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1429 * @warning Only pro/epilog differs between Simple/Main and Advanced =>
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1430 * check caller
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1431 * @{
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1432 */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1433
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1434 /** Frame header decoding, first part, in Simple and Main profiles
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1435 * @see Tables 5+7, p53-54 and 55-57
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1436 * @param v VC9 context
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1437 * @todo FIXME: RANGEREDFRM element not read if BI frame from Table6, P54
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1438 * However, 7.1.1.8 says "all frame types, for main profiles"
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1439 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1440 */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1441 static int standard_decode_picture_primary_header(VC9Context *v)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1442 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1443 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1444 int status = 0;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1445
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1446 if (v->finterpflag) v->interpfrm = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1447 skip_bits(gb, 2); //framecnt unused
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1448 if (v->rangered) v->rangeredfrm = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1449 v->s.pict_type = get_bits(gb, 1);
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1450 if (v->s.avctx->max_b_frames)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1451 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1452 if (!v->s.pict_type)
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1453 {
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1454 if (get_bits(gb, 1)) v->s.pict_type = I_TYPE;
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1455 else v->s.pict_type = B_TYPE;
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1456 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1457 else v->s.pict_type = P_TYPE;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1458 }
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1459 else v->s.pict_type++;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1460
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1461 switch (v->s.pict_type)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1462 {
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1463 case I_TYPE: status = decode_i_picture_primary_header(v); break;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1464 case P_TYPE: status = decode_p_picture_primary_header(v); break;
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1465 case BI_TYPE: //Same as B
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1466 case B_TYPE: status = decode_b_picture_primary_header(v); break;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1467 }
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 if (status == FRAME_SKIPED)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1470 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1471 av_log(v->s.avctx, AV_LOG_INFO, "Skipping frame...\n");
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1472 return status;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1473 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1474 return 0;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1475 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1476
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1477 /** Frame header decoding, secondary part
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1478 * @param v VC9 context
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1479 * @warning To call once all MB arrays are allocated
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1480 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1481 */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1482 static int standard_decode_picture_secondary_header(VC9Context *v)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1483 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1484 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1485 int status = 0, index;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1486
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1487 switch (v->s.pict_type)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1488 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1489 case P_TYPE: status = decode_p_picture_secondary_header(v); break;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1490 case B_TYPE: status = decode_b_picture_secondary_header(v); break;
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1491 case BI_TYPE:
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1492 case I_TYPE: break; //Nothing needed as it's done in the epilog
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1493 }
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1494 if (status < 0) return FRAME_SKIPED;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1495
2462
michael
parents: 2461
diff changeset
1496 /* AC Syntax */
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1497 v->ac_table_level = decode012(gb);
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1498 if (v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1499 {
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1500 v->ac2_table_level = decode012(gb);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1501 }
2462
michael
parents: 2461
diff changeset
1502 /* DC Syntax */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1503 index = decode012(gb);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1504 v->luma_dc_vlc = &ff_msmp4_dc_luma_vlc[index];
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1505 v->chroma_dc_vlc = &ff_msmp4_dc_chroma_vlc[index];
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1506
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1507 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1508 }
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1509 /** @} */ //End for group std_frame_hdr
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1510
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1511 #if HAS_ADVANCED_PROFILE
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1512 /***********************************************************************/
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1513 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1514 * @defgroup adv_frame_hdr VC9 Advanced Profile header decoding
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1515 * @brief Part of the frame header decoding belonging to Advanced Profiles
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1516 * @warning Only pro/epilog differs between Simple/Main and Advanced =>
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1517 * check caller
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1518 * @{
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1519 */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1520 /** Frame header decoding, primary part
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1521 * @param v VC9 context
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1522 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1523 */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1524 static int advanced_decode_picture_primary_header(VC9Context *v)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1525 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1526 GetBitContext *gb = &v->s.gb;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1527 static const int type_table[4] = { P_TYPE, B_TYPE, I_TYPE, BI_TYPE };
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1528 int type;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1529
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1530 if (v->interlace)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1531 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1532 v->fcm = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1533 if (v->fcm) v->fcm = 2+get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1534 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1535
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1536 type = get_prefix(gb, 0, 4);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1537 if (type > 4 || type < 0) return FRAME_SKIPED;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1538 v->s.pict_type = type_table[type];
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1539 av_log(v->s.avctx, AV_LOG_INFO, "AP Frame Type: %i\n", v->s.pict_type);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1540
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1541 if (v->tfcntrflag) v->tfcntr = get_bits(gb, 8);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1542 if (v->broadcast)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1543 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1544 if (!v->interlace) v->rptfrm = get_bits(gb, 2);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1545 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1546 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1547 v->tff = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1548 v->rff = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1549 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1550 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1551
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1552 if (v->panscanflag)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1553 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1554 #if 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1555 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
1556 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1557 v->topleftx[i] = get_bits(gb, 16);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1558 v->toplefty[i] = get_bits(gb, 16);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1559 v->bottomrightx[i] = get_bits(gb, 16);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1560 v->bottomrighty[i] = get_bits(gb, 16);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1561 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1562 #else
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1563 skip_bits(gb, 16*4*v->numpanscanwin);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1564 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1565 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1566 v->s.no_rounding = !get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1567 v->uvsamp = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1568 if (v->finterpflag == 1) v->interpfrm = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1569
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1570 switch(v->s.pict_type)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1571 {
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1572 case I_TYPE: if (decode_i_picture_primary_header(v) < 0) return -1;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1573 case P_TYPE: if (decode_p_picture_primary_header(v) < 0) return -1;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1574 case BI_TYPE:
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1575 case B_TYPE: if (decode_b_picture_primary_header(v) < 0) return FRAME_SKIPED;
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1576 default: return -1;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1577 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1578 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1579
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1580 /** Frame header decoding, secondary part
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1581 * @param v VC9 context
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1582 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1583 */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1584 static int advanced_decode_picture_secondary_header(VC9Context *v)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1585 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1586 GetBitContext *gb = &v->s.gb;
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1587 int index, status = 0;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1588
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1589 switch(v->s.pict_type)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1590 {
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1591 case P_TYPE: status = decode_p_picture_secondary_header(v); break;
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1592 case B_TYPE: status = decode_b_picture_secondary_header(v); break;
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1593 case BI_TYPE:
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1594 case I_TYPE: status = decode_i_picture_secondary_header(v); break;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1595 }
2483
4eb9d61cad4e - a lot less overflows when decoding frames
michael
parents: 2482
diff changeset
1596 if (status<0) return FRAME_SKIPED;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1597
2462
michael
parents: 2461
diff changeset
1598 /* AC Syntax */
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1599 v->ac_table_level = decode012(gb);
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1600 if (v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1601 {
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1602 v->ac2_table_level = decode012(gb);
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 /* DC Syntax */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1605 index = decode012(gb);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1606 v->luma_dc_vlc = &ff_msmp4_dc_luma_vlc[index];
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1607 v->chroma_dc_vlc = &ff_msmp4_dc_chroma_vlc[index];
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1608
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1609 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1610 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1611 #endif
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1612 /** @} */ //End for adv_frame_hdr
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1613
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1614 /***********************************************************************/
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1615 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1616 * @defgroup block VC9 Block-level functions
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1617 * @see 7.1.4, p91 and 8.1.1.7, p(1)04
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1618 * @todo TODO: Integrate to MpegEncContext facilities
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1619 * @{
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1620 */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1621 /** Decode a luma intra block
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1622 * @warning Will be removed, due to necessary integration
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1623 * @see coeff scaling for Adv Profile: 8.1.1.15, p(1)13,
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1624 * @param v VC9 context
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1625 * @param mquant Macroblock quantizer scale
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1626 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1627 * @todo TODO: Implement Coeff scaling for Advanced Profile
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1628 */
2462
michael
parents: 2461
diff changeset
1629 int decode_luma_intra_block(VC9Context *v, int mquant)
michael
parents: 2461
diff changeset
1630 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1631 GetBitContext *gb = &v->s.gb;
2462
michael
parents: 2461
diff changeset
1632 int dcdiff;
michael
parents: 2461
diff changeset
1633
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1634 dcdiff = get_vlc2(gb, v->luma_dc_vlc->table,
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1635 DC_VLC_BITS, 2);
2462
michael
parents: 2461
diff changeset
1636 if (dcdiff)
michael
parents: 2461
diff changeset
1637 {
michael
parents: 2461
diff changeset
1638 if (dcdiff == 119 /* ESC index value */)
michael
parents: 2461
diff changeset
1639 {
michael
parents: 2461
diff changeset
1640 /* TODO: Optimize */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1641 if (mquant == 1) dcdiff = get_bits(gb, 10);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1642 else if (mquant == 2) dcdiff = get_bits(gb, 9);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1643 else dcdiff = get_bits(gb, 8);
2462
michael
parents: 2461
diff changeset
1644 }
michael
parents: 2461
diff changeset
1645 else
michael
parents: 2461
diff changeset
1646 {
michael
parents: 2461
diff changeset
1647 if (mquant == 1)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1648 dcdiff = (dcdiff<<2) + get_bits(gb, 2) - 3;
2462
michael
parents: 2461
diff changeset
1649 else if (mquant == 2)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1650 dcdiff = (dcdiff<<1) + get_bits(gb, 1) - 1;
2462
michael
parents: 2461
diff changeset
1651 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1652 if (get_bits(gb, 1))
2462
michael
parents: 2461
diff changeset
1653 dcdiff = -dcdiff;
michael
parents: 2461
diff changeset
1654 }
michael
parents: 2461
diff changeset
1655 /* FIXME: 8.1.1.15, p(1)13, coeff scaling for Adv Profile */
michael
parents: 2461
diff changeset
1656
michael
parents: 2461
diff changeset
1657 return 0;
michael
parents: 2461
diff changeset
1658 }
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1659 /** @} */ //End for group block
2462
michael
parents: 2461
diff changeset
1660
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1661 /***********************************************************************/
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1662 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1663 * @defgroup std_mb VC9 Macroblock-level functions in Simple/Main Profiles
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1664 * @see 7.1.4, p91 and 8.1.1.7, p(1)04
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1665 * @todo TODO: Integrate to MpegEncContext facilities
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1666 * @{
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1667 */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1668 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1669 * @def GET_CBPCY(table, bits)
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1670 * @brief Get the Coded Block Pattern for luma and chroma
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1671 * @param table VLC table to use (get_vlc2 second parameter)
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1672 * @param bits Average bitlength (third parameter to get_vlc2)
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1673 * @see 8.1.1.5, p(1)02-(1)03
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1674 */
2462
michael
parents: 2461
diff changeset
1675 #define GET_CBPCY(table, bits) \
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1676 predicted_cbpcy = get_vlc2(gb, table, bits, 2); \
2462
michael
parents: 2461
diff changeset
1677 cbpcy[0] = (p_cbpcy[-1] == p_cbpcy[2]) \
michael
parents: 2461
diff changeset
1678 ? previous_cbpcy[1] : p_cbpcy[+2]; \
michael
parents: 2461
diff changeset
1679 cbpcy[0] ^= ((predicted_cbpcy>>5)&0x01); \
michael
parents: 2461
diff changeset
1680 cbpcy[1] = (p_cbpcy[2] == p_cbpcy[3]) ? cbpcy[0] : p_cbpcy[3]; \
michael
parents: 2461
diff changeset
1681 cbpcy[1] ^= ((predicted_cbpcy>>4)&0x01); \
michael
parents: 2461
diff changeset
1682 cbpcy[2] = (previous_cbpcy[1] == cbpcy[0]) \
michael
parents: 2461
diff changeset
1683 ? previous_cbpcy[3] : cbpcy[0]; \
michael
parents: 2461
diff changeset
1684 cbpcy[2] ^= ((predicted_cbpcy>>3)&0x01); \
michael
parents: 2461
diff changeset
1685 cbpcy[3] = (cbpcy[1] == cbpcy[0]) ? cbpcy[2] : cbpcy[1]; \
michael
parents: 2461
diff changeset
1686 cbpcy[3] ^= ((predicted_cbpcy>>2)&0x01);
michael
parents: 2461
diff changeset
1687
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1688 /** Decode all MBs for an I frame in Simple/Main profile
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1689 * @see 8.1, p100
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1690 * @todo TODO: Process the blocks
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1691 * @todo TODO: Use M$ MPEG-4 cbp prediction
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1692 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1693 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
1694 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1695 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1696 MpegEncContext *s = &v->s;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1697 int current_mb = 0; /* MB/Block Position info */
2462
michael
parents: 2461
diff changeset
1698 uint8_t cbpcy[4], previous_cbpcy[4], predicted_cbpcy,
michael
parents: 2461
diff changeset
1699 *p_cbpcy /* Pointer to skip some math */;
michael
parents: 2461
diff changeset
1700
michael
parents: 2461
diff changeset
1701 /* Reset CBPCY predictors */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1702 memset(v->previous_line_cbpcy, 0, s->mb_stride<<2);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1703
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1704 /* 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
1705 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
1706 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
1707 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
1708
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1709 for (s->mb_y=0; s->mb_y<s->mb_height; s->mb_y++)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1710 {
2462
michael
parents: 2461
diff changeset
1711 /* Init CBPCY for line */
michael
parents: 2461
diff changeset
1712 *((uint32_t*)previous_cbpcy) = 0x00000000;
michael
parents: 2461
diff changeset
1713 p_cbpcy = v->previous_line_cbpcy+4;
michael
parents: 2461
diff changeset
1714
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1715 for (s->mb_x=0; s->mb_x<s->mb_width; s->mb_x++, p_cbpcy += 4)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1716 {
2462
michael
parents: 2461
diff changeset
1717 /* Get CBPCY */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1718 GET_CBPCY(ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS);
2462
michael
parents: 2461
diff changeset
1719
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1720 s->ac_pred = get_bits(gb, 1);
2462
michael
parents: 2461
diff changeset
1721
michael
parents: 2461
diff changeset
1722 /* TODO: Decode blocks from that mb wrt cbpcy */
michael
parents: 2461
diff changeset
1723
michael
parents: 2461
diff changeset
1724 /* Update for next block */
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1725 #if TRACE > 2
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1726 av_log(s->avctx, AV_LOG_DEBUG, "Block %4i: p_cbpcy=%i%i%i%i, previous_cbpcy=%i%i%i%i,"
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1727 " cbpcy=%i%i%i%i\n", current_mb,
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1728 p_cbpcy[0], p_cbpcy[1], p_cbpcy[2], p_cbpcy[3],
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1729 previous_cbpcy[0], previous_cbpcy[1], previous_cbpcy[2], previous_cbpcy[3],
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1730 cbpcy[0], cbpcy[1], cbpcy[2], cbpcy[3]);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1731 #endif
2462
michael
parents: 2461
diff changeset
1732 *((uint32_t*)p_cbpcy) = *((uint32_t*)previous_cbpcy);
michael
parents: 2461
diff changeset
1733 *((uint32_t*)previous_cbpcy) = *((uint32_t*)cbpcy);
michael
parents: 2461
diff changeset
1734 current_mb++;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1735 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1736 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1737 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1738 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1739
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1740 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1741 * @def GET_MQUANT
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1742 * @brief Get macroblock-level quantizer scale
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1743 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1744 #define GET_MQUANT() \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1745 if (v->dquantfrm) \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1746 { \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1747 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
1748 { \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1749 if (v->dqbilevel) \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1750 { \
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1751 mquant = (get_bits(gb, 1)) ? v->pq : v->altpq; \
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1752 } \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1753 else \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1754 { \
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1755 mqdiff = get_bits(gb, 3); \
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1756 if (mqdiff != 7) mquant = v->pq + mqdiff; \
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1757 else mquant = get_bits(gb, 5); \
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1758 } \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1759 } \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1760 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1761
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1762 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1763 * @def GET_MVDATA(_dmv_x, _dmv_y)
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1764 * @brief Get MV differentials
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1765 * @see MVDATA decoding from 8.3.5.2, p(1)20
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1766 * @param dmv_x Horizontal differential for decoded MV
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1767 * @param dmv_y Vertical differential for decoded MV
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1768 */
2462
michael
parents: 2461
diff changeset
1769 #define GET_MVDATA(_dmv_x, _dmv_y) \
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1770 index = 1 + get_vlc2(gb, vc9_mv_diff_vlc[s->mv_table_index].table,\
2462
michael
parents: 2461
diff changeset
1771 VC9_MV_DIFF_VLC_BITS, 2); \
michael
parents: 2461
diff changeset
1772 if (index > 36) \
michael
parents: 2461
diff changeset
1773 { \
michael
parents: 2461
diff changeset
1774 mb_has_coeffs = 1; \
michael
parents: 2461
diff changeset
1775 index -= 37; \
michael
parents: 2461
diff changeset
1776 } \
michael
parents: 2461
diff changeset
1777 else mb_has_coeffs = 0; \
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1778 s->mb_intra = 0; \
2462
michael
parents: 2461
diff changeset
1779 if (!index) { _dmv_x = _dmv_y = 0; } \
michael
parents: 2461
diff changeset
1780 else if (index == 35) \
michael
parents: 2461
diff changeset
1781 { \
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1782 _dmv_x = get_bits(gb, k_x); \
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1783 _dmv_y = get_bits(gb, k_y); \
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1784 s->mb_intra = 1; \
2462
michael
parents: 2461
diff changeset
1785 } \
michael
parents: 2461
diff changeset
1786 else \
michael
parents: 2461
diff changeset
1787 { \
michael
parents: 2461
diff changeset
1788 index1 = index%6; \
michael
parents: 2461
diff changeset
1789 if (hpel_flag && index1 == 5) val = 1; \
michael
parents: 2461
diff changeset
1790 else val = 0; \
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1791 val = get_bits(gb, size_table[index1] - val); \
2462
michael
parents: 2461
diff changeset
1792 sign = 0 - (val&1); \
michael
parents: 2461
diff changeset
1793 _dmv_x = (sign ^ ((val>>1) + offset_table[index1])) - sign; \
michael
parents: 2461
diff changeset
1794 \
michael
parents: 2461
diff changeset
1795 index1 = index/6; \
michael
parents: 2461
diff changeset
1796 if (hpel_flag && index1 == 5) val = 1; \
michael
parents: 2461
diff changeset
1797 else val = 0; \
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1798 val = get_bits(gb, size_table[index1] - val); \
2462
michael
parents: 2461
diff changeset
1799 sign = 0 - (val&1); \
michael
parents: 2461
diff changeset
1800 _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
1801 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1802
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1803 /** Decode all MBs for an P frame in Simple/Main profile
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1804 * @see 8.1, p(1)15
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1805 * @todo TODO: Process the blocks
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1806 * @todo TODO: Use M$ MPEG-4 cbp prediction
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1807 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1808 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
1809 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1810 MpegEncContext *s = &v->s;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1811 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1812 int current_mb = 0, i; /* MB/Block Position info */
2462
michael
parents: 2461
diff changeset
1813 uint8_t cbpcy[4], previous_cbpcy[4], predicted_cbpcy,
michael
parents: 2461
diff changeset
1814 *p_cbpcy /* Pointer to skip some math */;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1815 int hybrid_pred; /* Prediction types */
2462
michael
parents: 2461
diff changeset
1816 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
1817 int mqdiff, mquant; /* MB quantization */
2462
michael
parents: 2461
diff changeset
1818 int ttmb; /* MB Transform type */
michael
parents: 2461
diff changeset
1819
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1820 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
1821 offset_table[6] = { 0, 1, 3, 7, 15, 31 };
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1822 int mb_has_coeffs = 1; /* last_flag */
2462
michael
parents: 2461
diff changeset
1823 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
1824 int k_x, k_y; /* Long MV fixed bitlength */
2462
michael
parents: 2461
diff changeset
1825 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
1826 int index, index1; /* LUT indices */
2462
michael
parents: 2461
diff changeset
1827 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
1828
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1829 /* 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
1830 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
1831 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
1832 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
1833
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1834 /* Select proper long MV range */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1835 switch (v->mvrange)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1836 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1837 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
1838 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
1839 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
1840 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
1841 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1842
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1843 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
1844 k_x -= hpel_flag;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1845 k_y -= hpel_flag;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1846
2462
michael
parents: 2461
diff changeset
1847 /* Reset CBPCY predictors */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1848 memset(v->previous_line_cbpcy, 0, s->mb_stride<<2);
2462
michael
parents: 2461
diff changeset
1849
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1850 for (s->mb_y=0; s->mb_y<s->mb_height; s->mb_y++)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1851 {
2462
michael
parents: 2461
diff changeset
1852 /* Init CBPCY for line */
michael
parents: 2461
diff changeset
1853 *((uint32_t*)previous_cbpcy) = 0x00000000;
michael
parents: 2461
diff changeset
1854 p_cbpcy = v->previous_line_cbpcy+4;
michael
parents: 2461
diff changeset
1855
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1856 for (s->mb_x=0; s->mb_x<s->mb_width; s->mb_x++, p_cbpcy += 4)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1857 {
2462
michael
parents: 2461
diff changeset
1858 if (v->mv_type_mb_plane.is_raw)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1859 v->mv_type_mb_plane.data[current_mb] = get_bits(gb, 1);
2462
michael
parents: 2461
diff changeset
1860 if (v->skip_mb_plane.is_raw)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1861 v->skip_mb_plane.data[current_mb] = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1862 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
1863 {
2462
michael
parents: 2461
diff changeset
1864 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
1865 {
2462
michael
parents: 2461
diff changeset
1866 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
1867
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1868 /* 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
1869 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
1870 v->mv_mode == MV_PMODE_MIXED_MV)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1871 hybrid_pred = get_bits(gb, 1);
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1872 if (s->mb_intra && !mb_has_coeffs)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1873 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1874 GET_MQUANT();
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1875 s->ac_pred = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1876 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1877 else if (mb_has_coeffs)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1878 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1879 if (s->mb_intra) s->ac_pred = get_bits(gb, 1);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1880 predicted_cbpcy = get_vlc2(gb, v->cbpcy_vlc->table, VC9_CBPCY_P_VLC_BITS, 2);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1881 cbpcy[0] = (p_cbpcy[-1] == p_cbpcy[2]) ? previous_cbpcy[1] : p_cbpcy[2];
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1882 cbpcy[0] ^= ((predicted_cbpcy>>5)&0x01);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1883 cbpcy[1] = (p_cbpcy[2] == p_cbpcy[3]) ? cbpcy[0] : p_cbpcy[3];
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1884 cbpcy[1] ^= ((predicted_cbpcy>>4)&0x01);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1885 cbpcy[2] = (previous_cbpcy[1] == cbpcy[0]) ? previous_cbpcy[3] : cbpcy[0];
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1886 cbpcy[2] ^= ((predicted_cbpcy>>3)&0x01);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1887 cbpcy[3] = (cbpcy[1] == cbpcy[0]) ? cbpcy[2] : cbpcy[1];
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1888 cbpcy[3] ^= ((predicted_cbpcy>>2)&0x01);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1889 //GET_CBPCY(v->cbpcy_vlc->table, VC9_CBPCY_P_VLC_BITS);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1890
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1891 GET_MQUANT();
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 (!v->ttmbf)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1894 ttmb = get_vlc2(gb, v->ttmb_vlc->table,
2462
michael
parents: 2461
diff changeset
1895 VC9_TTMB_VLC_BITS, 12);
michael
parents: 2461
diff changeset
1896 /* 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
1897 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1898 else //Skipped
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1899 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1900 /* 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
1901 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
1902 v->mv_mode == MV_PMODE_MIXED_MV)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1903 hybrid_pred = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1904 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1905 } //1MV mode
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1906 else //4MV mode
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1907 {
2462
michael
parents: 2461
diff changeset
1908 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
1909 {
2462
michael
parents: 2461
diff changeset
1910 /* Get CBPCY */
michael
parents: 2461
diff changeset
1911 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
1912 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
1913 {
2462
michael
parents: 2461
diff changeset
1914 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
1915 {
2462
michael
parents: 2461
diff changeset
1916 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
1917 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1918 if (v->mv_mode == MV_PMODE_MIXED_MV /* Hybrid pred */)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1919 hybrid_pred = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1920 GET_MQUANT();
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1921 if (s->mb_intra /* One of the 4 blocks is intra */ &&
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1922 index /* non-zero pred for that block */)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1923 s->ac_pred = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1924 if (!v->ttmbf)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1925 ttmb = get_vlc2(gb, v->ttmb_vlc->table,
2462
michael
parents: 2461
diff changeset
1926 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
1927
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1928 /* TODO: Process blocks wrt cbpcy */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1929
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1930 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1931 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1932 else //Skipped MB
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1933 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1934 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
1935 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1936 if (v->mv_mode == MV_PMODE_MIXED_MV /* Hybrid pred */)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1937 hybrid_pred = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1938
2462
michael
parents: 2461
diff changeset
1939 /* TODO: do something */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1940 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1941 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1942 }
2462
michael
parents: 2461
diff changeset
1943
michael
parents: 2461
diff changeset
1944 /* Update for next block */
michael
parents: 2461
diff changeset
1945 #if TRACE > 2
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1946 av_log(s->avctx, AV_LOG_DEBUG, "Block %4i: p_cbpcy=%i%i%i%i, previous_cbpcy=%i%i%i%i,"
2462
michael
parents: 2461
diff changeset
1947 " cbpcy=%i%i%i%i\n", current_mb,
michael
parents: 2461
diff changeset
1948 p_cbpcy[0], p_cbpcy[1], p_cbpcy[2], p_cbpcy[3],
michael
parents: 2461
diff changeset
1949 previous_cbpcy[0], previous_cbpcy[1], previous_cbpcy[2], previous_cbpcy[3],
michael
parents: 2461
diff changeset
1950 cbpcy[0], cbpcy[1], cbpcy[2], cbpcy[3]);
michael
parents: 2461
diff changeset
1951 #endif
michael
parents: 2461
diff changeset
1952 *((uint32_t*)p_cbpcy) = *((uint32_t*)previous_cbpcy);
michael
parents: 2461
diff changeset
1953 *((uint32_t*)previous_cbpcy) = *((uint32_t*)cbpcy);
michael
parents: 2461
diff changeset
1954 current_mb++;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1955 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1956 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1957 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1958 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1959
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1960 /** Decode all MBs for an P frame in Simple/Main profile
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1961 * @todo TODO: Process the blocks
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1962 * @todo TODO: Use M$ MPEG-4 cbp prediction
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1963 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1964 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
1965 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1966 MpegEncContext *s = &v->s;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1967 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1968 int current_mb = 0, i /* MB / B postion information */;
2462
michael
parents: 2461
diff changeset
1969 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
1970 int mquant, mqdiff; /* MB quant stuff */
2462
michael
parents: 2461
diff changeset
1971 int ttmb; /* MacroBlock transform type */
michael
parents: 2461
diff changeset
1972
michael
parents: 2461
diff changeset
1973 static const int size_table[6] = { 0, 2, 3, 4, 5, 8 },
michael
parents: 2461
diff changeset
1974 offset_table[6] = { 0, 1, 3, 7, 15, 31 };
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1975 int mb_has_coeffs = 1; /* last_flag */
2462
michael
parents: 2461
diff changeset
1976 int dmv1_x, dmv1_y, dmv2_x, dmv2_y; /* Differential MV components */
michael
parents: 2461
diff changeset
1977 int k_x, k_y; /* Long MV fixed bitlength */
michael
parents: 2461
diff changeset
1978 int hpel_flag; /* Some MB properties */
michael
parents: 2461
diff changeset
1979 int index, index1; /* LUT indices */
michael
parents: 2461
diff changeset
1980 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
1981
2462
michael
parents: 2461
diff changeset
1982 /* Select proper long MV range */
michael
parents: 2461
diff changeset
1983 switch (v->mvrange)
michael
parents: 2461
diff changeset
1984 {
michael
parents: 2461
diff changeset
1985 case 1: k_x = 10; k_y = 9; break;
michael
parents: 2461
diff changeset
1986 case 2: k_x = 12; k_y = 10; break;
michael
parents: 2461
diff changeset
1987 case 3: k_x = 13; k_y = 11; break;
michael
parents: 2461
diff changeset
1988 default: /*case 0 too */ k_x = 9; k_y = 8; break;
michael
parents: 2461
diff changeset
1989 }
michael
parents: 2461
diff changeset
1990 hpel_flag = v->mv_mode & 1; //MV_PMODE is HPEL
michael
parents: 2461
diff changeset
1991 k_x -= hpel_flag;
michael
parents: 2461
diff changeset
1992 k_y -= hpel_flag;
michael
parents: 2461
diff changeset
1993
michael
parents: 2461
diff changeset
1994 /* Select ttmb table depending on pq */
michael
parents: 2461
diff changeset
1995 if (v->pq < 5) v->ttmb_vlc = &vc9_ttmb_vlc[0];
michael
parents: 2461
diff changeset
1996 else if (v->pq < 13) v->ttmb_vlc = &vc9_ttmb_vlc[1];
michael
parents: 2461
diff changeset
1997 else v->ttmb_vlc = &vc9_ttmb_vlc[2];
michael
parents: 2461
diff changeset
1998
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1999 for (s->mb_y=0; s->mb_y<s->mb_height; s->mb_y++)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2000 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2001 for (s->mb_x=0; s->mb_x<s->mb_width; s->mb_x++)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2002 {
2462
michael
parents: 2461
diff changeset
2003 if (v->direct_mb_plane.is_raw)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2004 v->direct_mb_plane.data[current_mb] = get_bits(gb, 1);
2462
michael
parents: 2461
diff changeset
2005 if (v->skip_mb_plane.is_raw)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2006 v->skip_mb_plane.data[current_mb] = get_bits(gb, 1);
2462
michael
parents: 2461
diff changeset
2007
michael
parents: 2461
diff changeset
2008 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
2009 {
2462
michael
parents: 2461
diff changeset
2010 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
2011 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2012 b_mv_type = decode012(gb);
2462
michael
parents: 2461
diff changeset
2013 if (v->bfraction > 420 /*1/2*/ &&
michael
parents: 2461
diff changeset
2014 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
2015 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2016 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2017 {
2462
michael
parents: 2461
diff changeset
2018 GET_MVDATA(dmv1_x, dmv1_y);
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
2019 if (!s->mb_intra /* b_mv1 tells not intra */)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2020 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2021 b_mv_type = decode012(gb);
2462
michael
parents: 2461
diff changeset
2022 if (v->bfraction > 420 /*1/2*/ &&
michael
parents: 2461
diff changeset
2023 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
2024 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2025 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2026 }
2462
michael
parents: 2461
diff changeset
2027 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
2028 {
2462
michael
parents: 2461
diff changeset
2029 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
2030 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2031 GET_MQUANT();
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
2032 if (s->mb_intra /* intra mb */)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2033 s->ac_pred = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2034 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2035 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2036 {
2462
michael
parents: 2461
diff changeset
2037 /* if bmv1 tells MVs are interpolated */
michael
parents: 2461
diff changeset
2038 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
2039 {
2462
michael
parents: 2461
diff changeset
2040 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
2041 }
2462
michael
parents: 2461
diff changeset
2042 /* GET_MVDATA has reset some stuff */
michael
parents: 2461
diff changeset
2043 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
2044 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
2045 if (s->mb_intra /* intra_mb */)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2046 s->ac_pred = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2047 GET_MQUANT();
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2048 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2049 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2050 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2051 //End1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2052 if (v->ttmbf)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2053 ttmb = get_vlc2(gb, v->ttmb_vlc->table,
2462
michael
parents: 2461
diff changeset
2054 VC9_TTMB_VLC_BITS, 12);
michael
parents: 2461
diff changeset
2055
michael
parents: 2461
diff changeset
2056 //End2
michael
parents: 2461
diff changeset
2057 for (i=0; i<6; i++)
michael
parents: 2461
diff changeset
2058 {
michael
parents: 2461
diff changeset
2059 /* FIXME: process the block */
michael
parents: 2461
diff changeset
2060 }
michael
parents: 2461
diff changeset
2061
michael
parents: 2461
diff changeset
2062 current_mb++;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2063 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2064 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2065 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2066 }
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2067 /** @} */ //End for group std_mb
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2068
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2069 #if HAS_ADVANCED_PROFILE
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2070 /***********************************************************************/
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2071 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2072 * @defgroup adv_mb VC9 Macroblock-level functions in Advanced Profile
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2073 * @todo TODO: Integrate to MpegEncContext facilities
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2074 * @todo TODO: Code P, B and BI
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2075 * @{
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2076 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2077 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
2078 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2079 MpegEncContext *s = &v->s;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2080 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2081 int mqdiff, mquant, current_mb = 0, over_flags_mb = 0;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2082
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2083 for (s->mb_y=0; s->mb_y<s->mb_height; s->mb_y++)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2084 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2085 for (s->mb_x=0; s->mb_x<s->mb_width; s->mb_x++)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2086 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2087 if (v->ac_pred_plane.is_raw)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2088 s->ac_pred = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2089 else
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2090 s->ac_pred = v->ac_pred_plane.data[current_mb];
2462
michael
parents: 2461
diff changeset
2091 if (v->condover == 3 && v->over_flags_plane.is_raw)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2092 over_flags_mb = get_bits(gb, 1);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2093 GET_MQUANT();
2462
michael
parents: 2461
diff changeset
2094
michael
parents: 2461
diff changeset
2095 /* TODO: lots */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2096 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2097 current_mb++;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2098 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2099 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2100 }
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2101 /** @} */ //End for group adv_mb
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2102 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2103
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2104 /** Initialize a VC9/WMV3 decoder
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2105 * @todo TODO: Handle VC-9 IDUs (Transport level?)
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2106 * @todo TODO: Decypher remaining bits in extra_data
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2107 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2108 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
2109 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2110 VC9Context *v = avctx->priv_data;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2111 MpegEncContext *s = &v->s;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2112 GetBitContext gb;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2113
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2114 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
2115 avctx->pix_fmt = PIX_FMT_YUV420P;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2116 v->s.avctx = avctx;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2117
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2118 if(ff_h263_decode_init(avctx) < 0)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2119 return -1;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2120 if (vc9_init_common(v) < 0) return -1;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2121
2462
michael
parents: 2461
diff changeset
2122 avctx->coded_width = avctx->width;
michael
parents: 2461
diff changeset
2123 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
2124 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
2125 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2126 int count = 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2127
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2128 // looks like WMV3 has a sequence header stored in the extradata
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2129 // advanced sequence header may be before the first frame
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2130 // the last byte of the extradata is a version number, 1 for the
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2131 // samples we can decode
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2132
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2133 init_get_bits(&gb, avctx->extradata, avctx->extradata_size);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2134
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2135 decode_sequence_header(avctx, &gb);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2136
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2137 count = avctx->extradata_size*8 - get_bits_count(&gb);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2138 if (count>0)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2139 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2140 av_log(avctx, AV_LOG_INFO, "Extra data: %i bits left, value: %X\n",
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2141 count, get_bits(&gb, count));
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2142 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2143 else
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2144 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2145 av_log(avctx, AV_LOG_INFO, "Read %i bits in overflow\n", -count);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2146 }
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2147 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2148 avctx->has_b_frames= !!(avctx->max_b_frames);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2149
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2150 s->mb_width = (avctx->coded_width+15)>>4;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2151 s->mb_height = (avctx->coded_height+15)>>4;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2152
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2153 /* Allocate mb bitplanes */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2154 if (alloc_bitplane(&v->mv_type_mb_plane, s->mb_width, s->mb_height) < 0)
2462
michael
parents: 2461
diff changeset
2155 return -1;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2156 if (alloc_bitplane(&v->mv_type_mb_plane, s->mb_width, s->mb_height) < 0)
2462
michael
parents: 2461
diff changeset
2157 return -1;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2158 if (alloc_bitplane(&v->skip_mb_plane, s->mb_width, s->mb_height) < 0)
2462
michael
parents: 2461
diff changeset
2159 return -1;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2160 if (alloc_bitplane(&v->direct_mb_plane, s->mb_width, s->mb_height) < 0)
2462
michael
parents: 2461
diff changeset
2161 return -1;
michael
parents: 2461
diff changeset
2162
michael
parents: 2461
diff changeset
2163 /* For predictors */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2164 v->previous_line_cbpcy = (uint8_t *)av_malloc(s->mb_stride*4);
2462
michael
parents: 2461
diff changeset
2165 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
2166
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2167 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2168 if (v->profile > PROFILE_MAIN)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2169 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2170 if (alloc_bitplane(&v->over_flags_plane, s->mb_width, s->mb_height) < 0)
2462
michael
parents: 2461
diff changeset
2171 return -1;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2172 if (alloc_bitplane(&v->ac_pred_plane, s->mb_width, s->mb_height) < 0)
2462
michael
parents: 2461
diff changeset
2173 return -1;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2174 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2175 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2176
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2177 return 0;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2178 }
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2179
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2180 /** Decode a VC9/WMV3 frame
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2181 * @todo TODO: Handle VC-9 IDUs (Transport level?)
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2182 * @warning Initial try at using MpegEncContext stuff
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2183 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2184 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
2185 void *data, int *data_size,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2186 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
2187 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2188 VC9Context *v = avctx->priv_data;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2189 MpegEncContext *s = &v->s;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2190 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
2191 AVFrame *pict = data;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2192 uint8_t *tmp_buf;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2193 v->s.avctx = avctx;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2194
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2195 //buf_size = 0 -> last frame
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2196 if (!buf_size) return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2197
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2198 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
2199 avctx->height);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2200 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
2201 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
2202 avctx->width, avctx->height);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2203
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2204 if (avctx->codec_id == CODEC_ID_VC9)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2205 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2206 #if 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2207 // search for IDU's
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2208 // FIXME
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2209 uint32_t scp = 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2210 int scs = 0, i = 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2211
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2212 while (i < buf_size)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2213 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2214 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
2215 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
2216
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2217 if (scp != 0x000001)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2218 break; // eof ?
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2219
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2220 scs = buf[i++];
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2221
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2222 init_get_bits(gb, buf+i, (buf_size-i)*8);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2223
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2224 switch(scs)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2225 {
2462
michael
parents: 2461
diff changeset
2226 case 0x0A: //Sequence End Code
michael
parents: 2461
diff changeset
2227 return 0;
michael
parents: 2461
diff changeset
2228 case 0x0B: //Slice Start Code
michael
parents: 2461
diff changeset
2229 av_log(avctx, AV_LOG_ERROR, "Slice coding not supported\n");
michael
parents: 2461
diff changeset
2230 return -1;
michael
parents: 2461
diff changeset
2231 case 0x0C: //Field start code
michael
parents: 2461
diff changeset
2232 av_log(avctx, AV_LOG_ERROR, "Interlaced coding not supported\n");
michael
parents: 2461
diff changeset
2233 return -1;
michael
parents: 2461
diff changeset
2234 case 0x0D: //Frame start code
michael
parents: 2461
diff changeset
2235 break;
michael
parents: 2461
diff changeset
2236 case 0x0E: //Entry point Start Code
michael
parents: 2461
diff changeset
2237 if (v->profile <= MAIN_PROFILE)
michael
parents: 2461
diff changeset
2238 av_log(avctx, AV_LOG_ERROR,
michael
parents: 2461
diff changeset
2239 "Found an entry point in profile %i\n", v->profile);
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2240 advanced_entry_point_process(avctx, gb);
2462
michael
parents: 2461
diff changeset
2241 break;
michael
parents: 2461
diff changeset
2242 case 0x0F: //Sequence header Start Code
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2243 decode_sequence_header(avctx, gb);
2462
michael
parents: 2461
diff changeset
2244 break;
michael
parents: 2461
diff changeset
2245 default:
michael
parents: 2461
diff changeset
2246 av_log(avctx, AV_LOG_ERROR,
michael
parents: 2461
diff changeset
2247 "Unsupported IDU suffix %lX\n", scs);
michael
parents: 2461
diff changeset
2248 }
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2249
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2250 i += get_bits_count(gb)*8;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2251 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2252 #else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2253 av_abort();
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2254 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2255 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2256 else
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2257 init_get_bits(&v->s.gb, buf, buf_size*8);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2258
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2259 s->flags= avctx->flags;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2260 s->flags2= avctx->flags2;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2261
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2262 /* no supplementary picture */
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2263 if (buf_size == 0) {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2264 /* special case for last picture */
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2265 if (s->low_delay==0 && s->next_picture_ptr) {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2266 *pict= *(AVFrame*)s->next_picture_ptr;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2267 s->next_picture_ptr= NULL;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2268
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2269 *data_size = sizeof(AVFrame);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2270 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2271
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2272 return 0;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2273 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2274
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2275 //No IDU - we mimic ff_h263_decode_frame
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2276 s->bitstream_buffer_size=0;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2277
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2278 if (!s->context_initialized) {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2279 if (MPV_common_init(s) < 0) //we need the idct permutaton for reading a custom matrix
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2280 return -1;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2281 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2282
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2283 //we need to set current_picture_ptr before reading the header, otherwise we cant store anyting im there
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2284 if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2285 s->current_picture_ptr= &s->picture[ff_find_unused_picture(s, 0)];
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2286 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2287 #if HAS_ADVANCED_PROFILE
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2288 if (v->profile > PROFILE_MAIN)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2289 ret= advanced_decode_picture_primary_header(v);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2290 else
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2291 #endif
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2292 ret= standard_decode_picture_primary_header(v);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2293 if (ret == FRAME_SKIPED) return buf_size;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2294 /* skip if the header was thrashed */
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2295 if (ret < 0){
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2296 av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2297 return -1;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2298 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2299
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2300 //No bug workaround yet, no DCT conformance
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2301
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2302 //WMV9 does have resized images
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2303 if (v->profile <= PROFILE_MAIN && v->multires){
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2304 //Parse context stuff in here, don't know how appliable it is
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2305 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2306 //Not sure about context initialization
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2307
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2308 // for hurry_up==5
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2309 s->current_picture.pict_type= s->pict_type;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2310 s->current_picture.key_frame= s->pict_type == I_TYPE;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2311
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2312 /* skip b frames if we dont have reference frames */
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2313 if(s->last_picture_ptr==NULL && (s->pict_type==B_TYPE || s->dropable))
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2314 return buf_size; //FIXME simulating all buffer consumed
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2315 /* skip b frames if we are in a hurry */
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2316 if(avctx->hurry_up && s->pict_type==B_TYPE)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2317 return buf_size; //FIXME simulating all buffer consumed
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2318 /* skip everything if we are in a hurry>=5 */
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2319 if(avctx->hurry_up>=5)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2320 return buf_size; //FIXME simulating all buffer consumed
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2321
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2322 if(s->next_p_frame_damaged){
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2323 if(s->pict_type==B_TYPE)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2324 return buf_size; //FIXME simulating all buffer consumed
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2325 else
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2326 s->next_p_frame_damaged=0;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2327 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2328
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2329 if(MPV_frame_start(s, avctx) < 0)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2330 return -1;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2331
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2332 ff_er_frame_start(s);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2333
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2334 //wmv9 may or may not have skip bits
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2335 #if HAS_ADVANCED_PROFILE
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2336 if (v->profile > PROFILE_MAIN)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2337 ret= advanced_decode_picture_secondary_header(v);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2338 else
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2339 #endif
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2340 ret = standard_decode_picture_secondary_header(v);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2341 if (ret<0) return FRAME_SKIPED; //FIXME Non fatal for now
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2342
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2343 //We consider the image coded in only one slice
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2344 #if HAS_ADVANCED_PROFILE
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2345 if (v->profile > PROFILE_MAIN)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2346 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2347 switch(s->pict_type)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2348 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2349 case I_TYPE: ret = advanced_decode_i_mbs(v); break;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2350 case P_TYPE: ret = decode_p_mbs(v); break;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2351 case B_TYPE:
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2352 case BI_TYPE: ret = decode_b_mbs(v); break;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2353 default: ret = FRAME_SKIPED;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2354 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2355 if (ret == FRAME_SKIPED) return buf_size; //We ignore for now failures
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2356 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2357 else
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2358 #endif
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2359 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2360 switch(s->pict_type)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2361 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2362 case I_TYPE: ret = standard_decode_i_mbs(v); break;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2363 case P_TYPE: ret = decode_p_mbs(v); break;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2364 case B_TYPE:
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2365 case BI_TYPE: ret = decode_b_mbs(v); break;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2366 default: ret = FRAME_SKIPED;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2367 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2368 if (ret == FRAME_SKIPED) return buf_size;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2369 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2370
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2371 ff_er_frame_end(s);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2372
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2373 MPV_frame_end(s);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2374
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2375 assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2376 assert(s->current_picture.pict_type == s->pict_type);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2377 if(s->pict_type==B_TYPE || s->low_delay){
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2378 *pict= *(AVFrame*)&s->current_picture;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2379 ff_print_debug_info(s, pict);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2380 } else {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2381 *pict= *(AVFrame*)&s->last_picture;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2382 if(pict)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2383 ff_print_debug_info(s, pict);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2384 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2385
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2386 /* Return the Picture timestamp as the frame number */
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2387 /* we substract 1 because it is added on utils.c */
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2388 avctx->frame_number = s->picture_number - 1;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2389
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2390 /* dont output the last pic after seeking */
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2391 if(s->last_picture_ptr || s->low_delay)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2392 *data_size = sizeof(AVFrame);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2393
2462
michael
parents: 2461
diff changeset
2394 av_log(avctx, AV_LOG_DEBUG, "Consumed %i/%i bits\n",
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2395 get_bits_count(&s->gb), buf_size*8);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2396
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2397 /* Fake consumption of all data */
2462
michael
parents: 2461
diff changeset
2398 *data_size = len;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2399 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
2400 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2401
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2402 /** Close a VC9/WMV3 decoder
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2403 * @warning Initial try at using MpegEncContext stuff
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2404 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2405 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
2406 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2407 VC9Context *v = avctx->priv_data;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2408
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2409 #if HAS_ADVANCED_PROFILE
2458
915094e3da5d dont use several 100 mb memory for a tiny 120 element table
michael
parents: 2453
diff changeset
2410 av_freep(&v->hrd_rate);
915094e3da5d dont use several 100 mb memory for a tiny 120 element table
michael
parents: 2453
diff changeset
2411 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
2412 #endif
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2413 MPV_common_end(&v->s);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2414 free_bitplane(&v->mv_type_mb_plane);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2415 free_bitplane(&v->skip_mb_plane);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2416 free_bitplane(&v->direct_mb_plane);
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2417 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2418 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2419
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2420 AVCodec vc9_decoder = {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2421 "vc9",
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2422 CODEC_TYPE_VIDEO,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2423 CODEC_ID_VC9,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2424 sizeof(VC9Context),
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2425 vc9_decode_init,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2426 NULL,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2427 vc9_decode_end,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2428 vc9_decode_frame,
2453
f67b63ed036d avoid buf_size == 0 checks in every decoder
michael
parents: 2445
diff changeset
2429 CODEC_CAP_DELAY,
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2430 NULL
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2431 };
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2432
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2433 AVCodec wmv3_decoder = {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2434 "wmv3",
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2435 CODEC_TYPE_VIDEO,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2436 CODEC_ID_WMV3,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2437 sizeof(VC9Context),
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2438 vc9_decode_init,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2439 NULL,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2440 vc9_decode_end,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2441 vc9_decode_frame,
2453
f67b63ed036d avoid buf_size == 0 checks in every decoder
michael
parents: 2445
diff changeset
2442 CODEC_CAP_DELAY,
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2443 NULL
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2444 };