annotate vc9.c @ 2482:5d28ea40fd98 libavcodec

Documentation patch by anonymous
author michael
date Tue, 01 Feb 2005 09:51:49 +0000
parents 38dbec9a148d
children 4eb9d61cad4e
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 //@{
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
76 #define QUANT_FRAME_IMPLICIT 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
77 #define QUANT_FRAME_EXPLICIT 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
78 #define QUANT_NON_UNIFORM 2
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
79 #define QUANT_UNIFORM 3
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;
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
281 uint8_t pquantizer;
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;
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
302 uint8_t topleftx;
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
303 uint8_t toplefty;
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
304 uint8_t bottomrightx;
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
305 uint8_t bottomrighty;
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 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
338 return i;
2462
michael
parents: 2461
diff changeset
339 #else
michael
parents: 2461
diff changeset
340 unsigned int buf;
michael
parents: 2461
diff changeset
341 int log;
michael
parents: 2461
diff changeset
342
michael
parents: 2461
diff changeset
343 OPEN_READER(re, gb);
michael
parents: 2461
diff changeset
344 UPDATE_CACHE(re, gb);
michael
parents: 2461
diff changeset
345 buf=GET_CACHE(re, gb); //Still not sure
michael
parents: 2461
diff changeset
346 if (stop) buf = ~buf;
michael
parents: 2461
diff changeset
347
michael
parents: 2461
diff changeset
348 log= av_log2(-buf); //FIXME: -?
michael
parents: 2461
diff changeset
349 if (log < limit){
michael
parents: 2461
diff changeset
350 LAST_SKIP_BITS(re, gb, log+1);
michael
parents: 2461
diff changeset
351 CLOSE_READER(re, gb);
michael
parents: 2461
diff changeset
352 return log;
michael
parents: 2461
diff changeset
353 }
michael
parents: 2461
diff changeset
354
michael
parents: 2461
diff changeset
355 LAST_SKIP_BITS(re, gb, limit);
michael
parents: 2461
diff changeset
356 CLOSE_READER(re, gb);
michael
parents: 2461
diff changeset
357 return limit;
michael
parents: 2461
diff changeset
358 #endif
michael
parents: 2461
diff changeset
359 }
michael
parents: 2461
diff changeset
360
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
361 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
362 * Init VC-9 specific tables and VC9Context members
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
363 * @param v The VC9Context to initialize
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
364 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
365 */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
366 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
367 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
368 static int done = 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
369 int i;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
370
2462
michael
parents: 2461
diff changeset
371 /* Set the bit planes */
michael
parents: 2461
diff changeset
372 v->mv_type_mb_plane = (struct BitPlane) { NULL, 0, 0, 0 };
michael
parents: 2461
diff changeset
373 v->direct_mb_plane = (struct BitPlane) { NULL, 0, 0, 0 };
michael
parents: 2461
diff changeset
374 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
375 #if HAS_ADVANCED_PROFILE
2462
michael
parents: 2461
diff changeset
376 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
377 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
378 #endif
2462
michael
parents: 2461
diff changeset
379
michael
parents: 2461
diff changeset
380 /* VLC tables */
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
381 #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
382 # 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
383 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
384 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
385 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
386 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
387 }
42077bb89a53 norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents: 2459
diff changeset
388 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
389 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
390 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
391 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
392 }
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
393 # endif
2460
42077bb89a53 norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents: 2459
diff changeset
394 #endif
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
395 if(!done)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
396 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
397 done = 1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
398 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
399 vc9_bfraction_bits, 1, 1,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
400 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
401 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
402 vc9_norm2_bits, 1, 1,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
403 vc9_norm2_codes, 1, 1, 1);
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
404 #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
405 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
406 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
407 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
408 #endif
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
409 #if VLC_NORM6_METH0D == 2
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
410 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
411 &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
412 &vc9_norm6_first[0][0], 1, 1, 1);
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
413 INIT_VLC(&vc9_norm6_second_vlc, VC9_NORM6_SECOND_BITS, 22,
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
414 &vc9_norm6_second[0][1], 1, 1,
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
415 &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
416 #endif
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
417 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
418 vc9_imode_bits, 1, 1,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
419 vc9_imode_codes, 1, 1, 1);
2462
michael
parents: 2461
diff changeset
420 for (i=0; i<3; i++)
michael
parents: 2461
diff changeset
421 {
michael
parents: 2461
diff changeset
422 INIT_VLC(&vc9_ttmb_vlc[i], VC9_TTMB_VLC_BITS, 16,
michael
parents: 2461
diff changeset
423 vc9_ttmb_bits[i], 1, 1,
michael
parents: 2461
diff changeset
424 vc9_ttmb_codes[i], 2, 2, 1);
michael
parents: 2461
diff changeset
425 }
michael
parents: 2461
diff changeset
426 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
427 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
428 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
429 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
430 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
431 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
432 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
433 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
434 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
435 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
436 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
437 }
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
2462
michael
parents: 2461
diff changeset
440 /* Other defaults */
michael
parents: 2461
diff changeset
441 v->pq = -1;
michael
parents: 2461
diff changeset
442 v->mvrange = 0; /* 7.1.1.18, p80 */
michael
parents: 2461
diff changeset
443
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
444 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
445 }
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 #if HAS_ADVANCED_PROFILE
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
448 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
449 * Decode sequence header's Hypothetic Reference Decoder data
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
450 * @see 6.2.1, p32
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
451 * @param v The VC9Context to initialize
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
452 * @param gb A GetBitContext initialized from AVCodecContext extra_data
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
453 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
454 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
455 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
456 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
457 int i, num;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
458
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
459 num = get_bits(gb, 5);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
460
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
461 if (v->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
462 {
2458
915094e3da5d dont use several 100 mb memory for a tiny 120 element table
michael
parents: 2453
diff changeset
463 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
464 }
2462
michael
parents: 2461
diff changeset
465 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
466 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
467
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
468 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
469 {
2458
915094e3da5d dont use several 100 mb memory for a tiny 120 element table
michael
parents: 2453
diff changeset
470 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
471 }
2462
michael
parents: 2461
diff changeset
472 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
473 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
474
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
475 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
476
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
477 //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
478 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
479 //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
480 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
481
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
482 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
483 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
484 //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
485 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
486 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
487 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
488 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
489 "%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
490 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
491 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
492 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
493 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
494 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
495 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
496 "%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
497 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
498 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
499 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
500 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
501 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
502
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
503 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
504 * Decode sequence header for Advanced Profile
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
505 * @see Table 2, p18
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
506 * @see 6.1.7, pp21-27
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
507 * @param v The VC9Context to initialize
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
508 * @param gb A GetBitContext initialized from AVCodecContext extra_data
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
509 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
510 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
511 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
512 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
513 VC9Context *v = avctx->priv_data;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
514 int nr, dr, aspect_ratio;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
515
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
516 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
517 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
518 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
519
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
520 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
521 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
522 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
523 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
524 if (v->reserved)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
525 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
526 av_log(avctx, AV_LOG_ERROR, "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
527 v->reserved);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
528 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
529 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
530 if (v->extended_mv)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
531 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
532
2462
michael
parents: 2461
diff changeset
533 /* 6.1.7, p21 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
534 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
535 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
536 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
537 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
538 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
539 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
540 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
541 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
542 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
543
2462
michael
parents: 2461
diff changeset
544 /* 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
545 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
546 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
547 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
548 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
549 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
550 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
551 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
552 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
553 else if (aspect_ratio == 0x0E)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
554 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
555 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
556 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
557 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
558 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
559 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
560 }
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 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
564 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
565 avctx->coded_width = avctx->width;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
566 avctx->coded_height = avctx->height;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
567 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
568
2462
michael
parents: 2461
diff changeset
569 /* 6.1.8, p23 */
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
570 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
571 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
572 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
573 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
574 nr = get_bits(gb, 8);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
575 dr = get_bits(gb, 4);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
576 if (nr<1)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
577 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
578 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
579 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
580 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
581 if (nr>5)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
582 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
583 av_log(avctx, AV_LOG_ERROR,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
584 "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
585 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
586 if (dr<1)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
587 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
588 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
589 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
590 if (dr>2)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
591 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
592 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
593 "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
594 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
595 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
596 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
597 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
598 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
599 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
600 nr = get_bits(gb, 16);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
601 // 0.03125->2048Hz / 0.03125Hz
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
602 avctx->frame_rate = 1000000;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
603 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
604 }
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
2462
michael
parents: 2461
diff changeset
607 /* 6.1.9, p25 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
608 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
609 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
610 //Chromacity coordinates of color primaries
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
611 //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
612 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
613 if (v->color_prim<1)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
614 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
615 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
616 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
617 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
618 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
619 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
620 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
621 v->color_prim);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
622 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
623 }
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 //Opto-electronic transfer characteristics
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
626 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
627 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
628 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
629 av_log(avctx, AV_LOG_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
630 v->color_prim);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
631 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
632 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
633
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
634 //Matrix coefficient for primariev->YCbCr
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
635 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
636 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
637 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
638 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
639 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
640 v->color_prim);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
641 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
642 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
643 }
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 //Hypothetical reference decoder indicator flag
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
646 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
647 if (v->hrd_param_flag)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
648 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
649 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
650 }
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 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
653 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
654 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
655 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
656
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
657 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
658 * Decode Simple/Main Profiles sequence header
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
659 * @see Figure 7-8, p16-17
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
660 * @param avctx Codec context
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
661 * @param gb GetBit context initialized from Codec context extra_data
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
662 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
663 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
664 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
665 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
666 VC9Context *v = avctx->priv_data;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
667
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
668 v->profile = get_bits(gb, 2);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
669 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
670
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
671 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
672 if (v->profile > PROFILE_MAIN)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
673 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
674 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
675 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
676 if (v->chromaformat != 1)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
677 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
678 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
679 "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
680 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
681 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
682 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
683 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
684 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
685 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
686 v->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
687 if (v->res_sm)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
688 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
689 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
690 "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
691 //return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
692 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
693 }
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 // (fps-2)/4 (->30)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
696 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
697 // (bitrate-32kbps)/64kbps
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
698 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
699 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
700
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
701 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
702 if (v->profile <= PROFILE_MAIN)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
703 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
704 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
705 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
706 if (v->res_x8)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
707 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
708 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
709 "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
710 //return -1;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
711 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
712 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
713 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
714 if (!v->res_fasttx)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
715 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
716 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
717 "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
718 //return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
719 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
720 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
721
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
722 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
723 if (!v->profile && !v->fastuvmc)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
724 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
725 av_log(avctx, AV_LOG_ERROR,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
726 "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
727 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
728 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
729 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
730 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
731 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
732 av_log(avctx, AV_LOG_ERROR,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
733 "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
734 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
735 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
736 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
737 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
738
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
739 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
740 if (v->profile <= PROFILE_MAIN)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
741 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
742 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
743 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
744 if (v->res_transtab)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
745 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
746 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
747 "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
748 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
749 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
750 }
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 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
753
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
754 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
755 if (v->profile <= PROFILE_MAIN)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
756 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
757 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
758 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
759 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
760 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
761
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
762 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
763 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
764
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
765 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
766 if (v->profile <= PROFILE_MAIN)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
767 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
768 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
769 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
770 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
771 if (!v->res_rtm_flag)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
772 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
773 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
774 "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
775 //return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
776 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
777 #if TRACE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
778 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
779 "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
780 "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
781 "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
782 "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
783 v->profile, v->frmrtq_postproc, v->bitrtq_postproc,
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
784 v->s.loop_filter, v->multires, v->fastuvmc, v->extended_mv,
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
785 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
786 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
787 );
2462
michael
parents: 2461
diff changeset
788 return 0;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
789 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
790 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
791 #if HAS_ADVANCED_PROFILE
2462
michael
parents: 2461
diff changeset
792 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
793 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
794 }
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 #if HAS_ADVANCED_PROFILE
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
798 /** Entry point decoding (Advanced Profile)
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
799 * @param avctx Codec context
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
800 * @param gb GetBit context initialized from avctx->extra_data
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
801 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
802 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
803 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
804 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
805 VC9Context *v = avctx->priv_data;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
806 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
807 if (v->profile != PROFILE_ADVANCED)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
808 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
809 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
810 "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
811 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
812 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
813 if (v->hrd_param_flag)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
814 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
815 //Update buffer fullness
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
816 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
817 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
818 skip_bits(gb, 8);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
819 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
820 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
821 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
822 //RANGE_MAPY
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
823 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
824 skip_bits(gb, 3);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
825 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
826 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
827 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
828 //RANGE_MAPUV
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
829 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
830 skip_bits(gb, 3);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
831 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
832 if (v->panscanflag)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
833 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
834 //NUMPANSCANWIN
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
835 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
836 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
837 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
838 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
839 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
840 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
841
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
842 /***********************************************************************/
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
843 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
844 * @defgroup bitplane VC9 Bitplane decoding
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
845 * @see 8.7, p56
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
846 * @{
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 /** @addtogroup bitplane
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
850 * Imode types
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
851 * @{
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
852 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
853 #define IMODE_RAW 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
854 #define IMODE_NORM2 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
855 #define IMODE_DIFF2 2
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
856 #define IMODE_NORM6 3
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
857 #define IMODE_DIFF6 4
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
858 #define IMODE_ROWSKIP 5
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
859 #define IMODE_COLSKIP 6
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
860 /** @} */ //imode defines
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
861
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
862 /** Allocate the buffer from a bitplane, given its dimensions
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
863 * @param bp Bitplane which buffer is to allocate
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
864 * @param[in] width Width of the buffer
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
865 * @param[in] height Height of the buffer
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
866 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
867 * @todo TODO: Take into account stride
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
868 * @todo TODO: Allow use of external buffers ?
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
869 */
2462
michael
parents: 2461
diff changeset
870 int alloc_bitplane(BitPlane *bp, int width, int height)
michael
parents: 2461
diff changeset
871 {
michael
parents: 2461
diff changeset
872 if (!bp || bp->width<0 || bp->height<0) return -1;
michael
parents: 2461
diff changeset
873 bp->data = (uint8_t*)av_malloc(width*height);
michael
parents: 2461
diff changeset
874 if (!bp->data) return -1;
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
875 bp->width = bp->stride = width;
2462
michael
parents: 2461
diff changeset
876 bp->height = height;
michael
parents: 2461
diff changeset
877 return 0;
michael
parents: 2461
diff changeset
878 }
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
879
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
880 /** Free the bitplane's buffer
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
881 * @param bp Bitplane which buffer is to free
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
882 */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
883 void free_bitplane(BitPlane *bp)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
884 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
885 bp->width = bp->stride = bp->height = 0;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
886 if (bp->data) av_freep(&bp->data);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
887 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
888
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
889 /** Decode rows by checking if they are skiped
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
890 * @param plane Buffer to store decoded bits
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
891 * @param[in] width Width of this buffer
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
892 * @param[in] height Height of this buffer
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
893 * @param[in] stride of this buffer
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
894 */
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
895 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
896 int x, y;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
897 GetBitContext *gb = &v->s.gb;
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
898
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
899 for (y=0; y<height; y++){
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
900 if (!get_bits(gb, 1)) //rowskip
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
901 memset(plane, 0, width);
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
902 else
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
903 for (x=0; x<width; x++)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
904 plane[x] = get_bits(gb, 1);
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
905 plane += stride;
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
906 }
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
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
909 /** Decode columns by checking if they are skiped
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
910 * @param plane Buffer to store decoded bits
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
911 * @param[in] width Width of this buffer
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
912 * @param[in] height Height of this buffer
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
913 * @param[in] stride of this buffer
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
914 * @fixme FIXME: Optimize
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
915 */
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
916 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
917 int x, y;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
918 GetBitContext *gb = &v->s.gb;
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
919
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
920 for (x=0; x<width; x++){
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
921 if (!get_bits(gb, 1)) //colskip
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
922 for (y=0; y<height; y++)
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
923 plane[y*stride] = 0;
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
924 else
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
925 for (y=0; y<height; y++)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
926 plane[y*stride] = get_bits(gb, 1);
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
927 plane ++;
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
928 }
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
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
931 /** Decode a bitplane's bits
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
932 * @param bp Bitplane where to store the decode bits
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
933 * @param v VC9 context for bit reading and logging
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
934 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
935 * @fixme FIXME: Optimize
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
936 * @todo TODO: Decide if a struct is needed
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
937 */
2462
michael
parents: 2461
diff changeset
938 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
939 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
940 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
941
2462
michael
parents: 2461
diff changeset
942 int imode, x, y, code, use_vertical_tile, tile_w, tile_h;
michael
parents: 2461
diff changeset
943 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
944
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
945 invert = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
946 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
947
2462
michael
parents: 2461
diff changeset
948 bp->is_raw = 0;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
949 switch (imode)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
950 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
951 case IMODE_RAW:
2462
michael
parents: 2461
diff changeset
952 //Data is actually read in the MB layer (same for all tests == "raw")
michael
parents: 2461
diff changeset
953 bp->is_raw = 1; //invert ignored
michael
parents: 2461
diff changeset
954 return invert;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
955 case IMODE_DIFF2:
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
956 case IMODE_NORM2:
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
957 if ((bp->height*bp->width) & 1) *(++planep) = get_bits(gb, 1);
2462
michael
parents: 2461
diff changeset
958 for(x=0; x<(bp->height*bp->width)>>1; x++){
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
959 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
960 *(++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
961 *(++planep) = (code>>1)&1; //msb => right
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
962 //FIXME width->stride
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
963 }
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
964 break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
965 case IMODE_DIFF6:
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
966 case IMODE_NORM6:
2462
michael
parents: 2461
diff changeset
967 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
968 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
969 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
970
2462
michael
parents: 2461
diff changeset
971 for(y= bp->height%tile_h; y< bp->height; y+=tile_h){
michael
parents: 2461
diff changeset
972 for(x= bp->width%tile_w; x< bp->width; x+=tile_w){
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
973 #if VLC_NORM6_METH0D == 1
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
974 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
975 if(code<0){
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
976 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
977 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
978 }
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
979 #endif
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
980 #if VLC_NORM6_METH0D == 2 //Failure
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
981 code = get_vlc2(gb, vc9_norm6_first_vlc.table, VC9_NORM6_FIRST_BITS, 2);
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
982 if (code == 22)
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
983 {
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
984 code = vc9_norm6_flc_val[get_bits(gb, 5)];
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
985 }
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
986 else if (code == 23)
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
987 {
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
988 # if TRACE
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
989 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
990 assert(code>-1 && code<22);
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
991 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
992 # else
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
993 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
994 # endif
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
995 }
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
996 #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
997 //FIXME following is a pure guess and probably wrong
2462
michael
parents: 2461
diff changeset
998 //FIXME A bitplane (0 | !0), so could the shifts be avoided ?
michael
parents: 2461
diff changeset
999 planep[x + 0*bp->stride]= (code>>0)&1;
michael
parents: 2461
diff changeset
1000 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
1001 //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
1002 if(use_vertical_tile){
2462
michael
parents: 2461
diff changeset
1003 planep[x + 0 + 1*bp->stride]= (code>>2)&1;
michael
parents: 2461
diff changeset
1004 planep[x + 1 + 1*bp->stride]= (code>>3)&1;
michael
parents: 2461
diff changeset
1005 planep[x + 0 + 2*bp->stride]= (code>>4)&1;
michael
parents: 2461
diff changeset
1006 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
1007 }else{
2462
michael
parents: 2461
diff changeset
1008 planep[x + 2 + 0*bp->stride]= (code>>2)&1;
michael
parents: 2461
diff changeset
1009 planep[x + 0 + 1*bp->stride]= (code>>3)&1;
michael
parents: 2461
diff changeset
1010 planep[x + 1 + 1*bp->stride]= (code>>4)&1;
michael
parents: 2461
diff changeset
1011 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
1012 }
42077bb89a53 norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents: 2459
diff changeset
1013 }
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
1014 }
2460
42077bb89a53 norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
michael
parents: 2459
diff changeset
1015
2462
michael
parents: 2461
diff changeset
1016 x= bp->width % tile_w;
michael
parents: 2461
diff changeset
1017 decode_colskip(bp->data , x, bp->height , bp->stride, v);
michael
parents: 2461
diff changeset
1018 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
1019
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1020 break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1021 case IMODE_ROWSKIP:
2462
michael
parents: 2461
diff changeset
1022 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
1023 break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1024 case IMODE_COLSKIP: //Teh ugly
2462
michael
parents: 2461
diff changeset
1025 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
1026 break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1027 default: break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1028 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1029
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1030 /* Applying diff operator */
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
1031 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
1032 {
2462
michael
parents: 2461
diff changeset
1033 planep = bp->data;
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
1034 planep[0] ^= invert;
2462
michael
parents: 2461
diff changeset
1035 for (x=1; x<bp->width; x++)
2459
7a875ef7597b fixing many bugs in bitplane_decoding()
michael
parents: 2458
diff changeset
1036 planep[x] ^= planep[x-1];
2462
michael
parents: 2461
diff changeset
1037 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
1038 {
2462
michael
parents: 2461
diff changeset
1039 planep += bp->stride;
michael
parents: 2461
diff changeset
1040 planep[0] ^= planep[-bp->stride];
michael
parents: 2461
diff changeset
1041 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
1042 {
2462
michael
parents: 2461
diff changeset
1043 if (planep[x-1] != planep[x-bp->stride]) planep[x] ^= invert;
michael
parents: 2461
diff changeset
1044 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
1045 }
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 else if (invert)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1049 {
2462
michael
parents: 2461
diff changeset
1050 planep = bp->data;
michael
parents: 2461
diff changeset
1051 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
1052 }
2462
michael
parents: 2461
diff changeset
1053 return (imode<<1) + invert;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1054 }
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1055 /** @} */ //Bitplane group
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1056
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1057 /***********************************************************************/
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1058 /** VOP Dquant decoding
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1059 * @param v VC9 Context
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1060 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1061 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
1062 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1063 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
1064 int pqdiff;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1065
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1066 //variable size
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1067 if (v->dquant == 2)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1068 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1069 pqdiff = get_bits(gb, 3);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1070 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
1071 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
1072 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1073 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1074 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1075 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
1076 if ( v->dquantfrm )
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1077 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1078 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
1079 switch (v->dqprofile)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1080 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1081 case DQPROFILE_SINGLE_EDGE:
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1082 case DQPROFILE_DOUBLE_EDGES:
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1083 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
1084 break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1085 case DQPROFILE_ALL_MBS:
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1086 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
1087 default: break; //Forbidden ?
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1088 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1089 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
1090 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1091 pqdiff = get_bits(gb, 3);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1092 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
1093 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
1094 }
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 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1098 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1099
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1100 /***********************************************************************/
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1101 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1102 * @defgroup all_frame_hdr All VC9 profiles frame header
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1103 * @brief Part of the frame header decoding from all profiles
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1104 * @warning Only pro/epilog differs between Simple/Main and Advanced => check caller
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1105 * @{
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1106 */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1107 /** B and BI frame header decoding, primary part
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1108 * @see Tables 11+12, p62-65
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1109 * @param v VC9 context
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1110 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1111 * @warning Also handles BI frames
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1112 */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1113 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
1114 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1115 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1116 int pqindex, status;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1117
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1118 /* 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
1119 if (v->profile == PROFILE_SIMPLE)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1120 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1121 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
1122 return FRAME_SKIPED;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1123 }
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
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1151 /* Read the MV type/mode */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1152 if (v->extended_mv == 1)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1153 v->mvrange = get_prefix(gb, 0, 3);
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1154 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
1155 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1156 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
1157 if (v->pq < 13)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1158 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1159 if (!v->mv_mode)
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1160 {
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1161 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
1162 if (v->mv_mode)
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1163 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
1164 "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
1165 }
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1166 }
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1167 else
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1168 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1169 if (!v->mv_mode)
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1170 {
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1171 if (get_bits(gb, 1))
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,
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1173 "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
1174 }
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1175 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
1176 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1177 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1178
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1179 return 0;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1180 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1181
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1182 /** B and BI frame header decoding, secondary part
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1183 * @see Tables 11+12, p62-65
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1184 * @param v VC9 context
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1185 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1186 * @warning Also handles BI frames
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1187 * @warning To call once all MB arrays are allocated
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1188 */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1189 static int decode_b_picture_secondary_header(VC9Context *v)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1190 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1191 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1192 int status;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1193
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1194 bitplane_decoding(&v->skip_mb_plane, v);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1195 if (status < 0) return -1;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1196 #if TRACE
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1197 if (v->mv_mode == MV_PMODE_MIXED_MV)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1198 {
2462
michael
parents: 2461
diff changeset
1199 status = bitplane_decoding(&v->mv_type_mb_plane, v);
michael
parents: 2461
diff changeset
1200 if (status < 0)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1201 return -1;
2462
michael
parents: 2461
diff changeset
1202 #if TRACE
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1203 av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
2462
michael
parents: 2461
diff changeset
1204 "Imode: %i, Invert: %i\n", status>>1, status&1);
michael
parents: 2461
diff changeset
1205 #endif
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1206 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1207
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1208 //bitplane
2462
michael
parents: 2461
diff changeset
1209 status = bitplane_decoding(&v->direct_mb_plane, v);
michael
parents: 2461
diff changeset
1210 if (status < 0) return -1;
michael
parents: 2461
diff changeset
1211 #if TRACE
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1212 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct plane encoding: "
2462
michael
parents: 2461
diff changeset
1213 "Imode: %i, Invert: %i\n", status>>1, status&1);
michael
parents: 2461
diff changeset
1214 #endif
michael
parents: 2461
diff changeset
1215
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1216 av_log(v->s.avctx, AV_LOG_DEBUG, "Skip MB plane encoding: "
2462
michael
parents: 2461
diff changeset
1217 "Imode: %i, Invert: %i\n", status>>1, status&1);
michael
parents: 2461
diff changeset
1218 #endif
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1219
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1220 /* 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
1221 v->s.mv_table_index = get_bits(gb, 2); //but using vc9_ tables
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1222 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
1223
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1224 if (v->dquant)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1225 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1226 vop_dquant_decoding(v);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1227 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1228
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1229 if (v->vstransform)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1230 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1231 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
1232 if (v->ttmbf)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1233 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1234 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
1235 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
1236 (v->ttfrm & 2) ? 4 : 8, (v->ttfrm & 1) ? 4 : 8);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1237 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1238 }
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1239 /* 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
1240 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1241 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1242
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1243 /** I frame header decoding, primary part
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1244 * @see Tables 5+7, p53-54 and 55-57
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1245 * @param v VC9 context
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1246 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1247 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1248 static int decode_i_picture_header(VC9Context *v)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1249 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1250 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1251 int pqindex, status = 0;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1252
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1253 /* 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
1254 //BF = Buffer Fullness
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1255 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
1256 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1257 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
1258 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1259
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1260 /* Quantizer stuff */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1261 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
1262 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
1263 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
1264 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1265 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1266 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
1267 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1268 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
1269 if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1270 v->pquantizer = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1271 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
1272 v->pq, v->halfpq);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1273 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1274 if (v->profile <= PROFILE_MAIN)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1275 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1276 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1277 if (v->extended_mv) v->mvrange = get_prefix(gb, 0, 3);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1278 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
1279 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1280 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1281 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1282 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1283 v->s.ac_pred = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1284 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
1285 /* 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
1286 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
1287 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1288 v->condover = get_bits(gb, 1);
2462
michael
parents: 2461
diff changeset
1289 if (v->condover)
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1290 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1291 v->condover = 2+get_bits(gb, 1);
2462
michael
parents: 2461
diff changeset
1292 if (v->condover == 3)
michael
parents: 2461
diff changeset
1293 {
michael
parents: 2461
diff changeset
1294 status = bitplane_decoding(&v->over_flags_plane, v);
michael
parents: 2461
diff changeset
1295 if (status < 0) return -1;
michael
parents: 2461
diff changeset
1296 #if TRACE
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1297 av_log(v->s.avctx, AV_LOG_DEBUG, "Overflags plane encoding: "
2462
michael
parents: 2461
diff changeset
1298 "Imode: %i, Invert: %i\n", status>>1, status&1);
michael
parents: 2461
diff changeset
1299 #endif
michael
parents: 2461
diff changeset
1300 }
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1301 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1302 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1303 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1304 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1305
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1306 /* 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
1307 return status;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1308 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1309
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1310 /** P frame header decoding, primary part
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1311 * @see Tables 5+7, p53-54 and 55-57
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1312 * @param v VC9 context
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1313 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1314 */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1315 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
1316 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1317 /* INTERFRM, FRMCNT, RANGEREDFRM read in caller */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1318 GetBitContext *gb = &v->s.gb;
2462
michael
parents: 2461
diff changeset
1319 int lowquant, pqindex, status = 0;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1320
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1321 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
1322 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
1323 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
1324 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1325 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1326 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
1327 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1328 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
1329 if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1330 v->pquantizer = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1331 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
1332 v->pq, v->halfpq);
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1333 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
1334 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1335 if (v->profile > PROFILE_MAIN)
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 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
1338 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1339 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1340 #endif
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1341 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
1342 lowquant = (v->pquantizer>12) ? 0 : 1;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1343 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
1344 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
1345 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1346 v->mv_mode2 = mv_pmode_table[lowquant][get_prefix(gb, 1, 3)];
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1347 v->lumscale = get_bits(gb, 6);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1348 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
1349 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1350 return 0;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1351 }
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1352
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1353 /** P frame header decoding, secondary part
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1354 * @see Tables 5+7, p53-54 and 55-57
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1355 * @param v VC9 context
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1356 * @warning To call once all MB arrays are allocated
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1357 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1358 */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1359 static int decode_p_picture_secondary_header(VC9Context *v)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1360 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1361 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1362 int status = 0;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1363 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
1364 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
1365 || 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
1366 {
2462
michael
parents: 2461
diff changeset
1367 status = bitplane_decoding(&v->mv_type_mb_plane, v);
michael
parents: 2461
diff changeset
1368 if (status < 0) return -1;
michael
parents: 2461
diff changeset
1369 #if TRACE
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1370 av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
2462
michael
parents: 2461
diff changeset
1371 "Imode: %i, Invert: %i\n", status>>1, status&1);
michael
parents: 2461
diff changeset
1372 #endif
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1373 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1374
2462
michael
parents: 2461
diff changeset
1375 status = bitplane_decoding(&v->skip_mb_plane, v);
michael
parents: 2461
diff changeset
1376 if (status < 0) return -1;
michael
parents: 2461
diff changeset
1377 #if TRACE
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1378 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
2462
michael
parents: 2461
diff changeset
1379 "Imode: %i, Invert: %i\n", status>>1, status&1);
michael
parents: 2461
diff changeset
1380 #endif
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1381
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1382 /* 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
1383 v->s.mv_table_index =get_bits(gb, 2); //but using vc9_ tables
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1384 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
1385
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1386 if (v->dquant)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1387 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1388 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
1389 vop_dquant_decoding(v);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1390 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1391
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1392 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
1393 if (v->vstransform)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1394 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1395 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
1396 if (v->ttmbf)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1397 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1398 v->ttfrm = get_bits(gb, 2);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1399 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
1400 (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
1401 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1402 }
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1403 /* 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
1404 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1405 }
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1406 /** @} */ //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
1407
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1408
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1409 /***********************************************************************/
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1410 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1411 * @defgroup std_frame_hdr VC9 Simple/Main Profiles header decoding
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1412 * @brief Part of the frame header decoding belonging to Simple/Main Profiles
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1413 * @warning Only pro/epilog differs between Simple/Main and Advanced =>
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1414 * check caller
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1415 * @{
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1416 */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1417
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1418 /** Frame header decoding, first part, in Simple and Main profiles
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1419 * @see Tables 5+7, p53-54 and 55-57
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1420 * @param v VC9 context
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1421 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1422 */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1423 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
1424 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1425 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1426 int status = 0;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1427
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1428 if (v->finterpflag) v->interpfrm = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1429 skip_bits(gb, 2); //framecnt unused
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1430 if (v->rangered) v->rangeredfrm = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1431 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
1432 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
1433 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1434 if (!v->s.pict_type)
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1435 {
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1436 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
1437 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
1438 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1439 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
1440 }
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1441 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
1442
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1443 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
1444 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1445 case I_TYPE: status = decode_i_picture_header(v); break;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1446 case P_TYPE: status = decode_p_picture_primary_header(v); break;
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1447 case BI_TYPE:
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1448 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
1449 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1450
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1451 if (status == FRAME_SKIPED)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1452 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1453 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
1454 return status;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1455 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1456 return 0;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1457 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1458
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1459 /** Frame header decoding, secondary part
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1460 * @param v VC9 context
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1461 * @warning To call once all MB arrays are allocated
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1462 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1463 */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1464 static int standard_decode_picture_secondary_header(VC9Context *v)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1465 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1466 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1467 int status = 0, index;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1468
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1469 switch (v->s.pict_type)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1470 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1471 case P_TYPE: status = decode_p_picture_secondary_header(v); break;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1472 case B_TYPE: status = decode_b_picture_secondary_header(v); break;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1473 }
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1474
2462
michael
parents: 2461
diff changeset
1475 /* AC Syntax */
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1476 v->ac_table_level = decode012(gb);
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1477 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
1478 {
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1479 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
1480 }
2462
michael
parents: 2461
diff changeset
1481 /* DC Syntax */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1482 index = decode012(gb);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1483 v->luma_dc_vlc = &ff_msmp4_dc_luma_vlc[index];
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1484 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
1485
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1486 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1487 }
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1488 /** @} */ //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
1489
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1490 #if HAS_ADVANCED_PROFILE
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1491 /***********************************************************************/
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1492 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1493 * @defgroup adv_frame_hdr VC9 Advanced Profile header decoding
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1494 * @brief Part of the frame header decoding belonging to Advanced Profiles
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1495 * @warning Only pro/epilog differs between Simple/Main and Advanced =>
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1496 * check caller
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1497 * @{
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1498 */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1499 /** Frame header decoding, primary part
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1500 * @param v VC9 context
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1501 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1502 */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1503 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
1504 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1505 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
1506 static const int type_table[4] = { P_TYPE, B_TYPE, I_TYPE, BI_TYPE };
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1507 int type, i;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1508
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1509 if (v->interlace)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1510 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1511 v->fcm = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1512 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
1513 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1514
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1515 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
1516 if (type > 4 || type < 0) return FRAME_SKIPED;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1517 v->s.pict_type = type_table[type];
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1518 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
1519
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1520 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
1521 if (v->broadcast)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1522 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1523 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
1524 else
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 v->tff = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1527 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
1528 }
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
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1531 if (v->panscanflag)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1532 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1533 #if 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1534 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
1535 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1536 v->topleftx[i] = get_bits(gb, 16);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1537 v->toplefty[i] = get_bits(gb, 16);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1538 v->bottomrightx[i] = get_bits(gb, 16);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1539 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
1540 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1541 #else
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1542 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
1543 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1544 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1545 v->s.no_rounding = !get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1546 v->uvsamp = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1547 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
1548
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1549 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
1550 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1551 case I_TYPE: if (decode_i_picture_header(v) < 0) return -1;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1552 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
1553 case BI_TYPE:
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1554 case B_TYPE: if (decode_b_picture_primary_header(v) < 0) return FRAME_SKIPED;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1555 default: break;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1556 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1557 return 0;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1558 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1559
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1560 /** Frame header decoding, secondary part
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1561 * @param v VC9 context
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1562 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1563 */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1564 static int advanced_decode_picture_secondary_header(VC9Context *v)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1565 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1566 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1567 int index;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1568
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1569 switch(v->s.pict_type)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1570 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1571 case P_TYPE: if (decode_p_picture_secondary_header(v) < 0) return -1;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1572 case B_TYPE: if (decode_b_picture_secondary_header(v) < 0) return FRAME_SKIPED;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1573 default: break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1574 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1575
2462
michael
parents: 2461
diff changeset
1576 /* AC Syntax */
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1577 v->ac_table_level = decode012(gb);
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1578 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
1579 {
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1580 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
1581 }
2462
michael
parents: 2461
diff changeset
1582 /* DC Syntax */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1583 index = decode012(gb);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1584 v->luma_dc_vlc = &ff_msmp4_dc_luma_vlc[index];
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1585 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
1586
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1587 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1588 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1589 #endif
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1590 /** @} */ //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
1591
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1592 /***********************************************************************/
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1593 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1594 * @defgroup block VC9 Block-level functions
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1595 * @see 7.1.4, p91 and 8.1.1.7, p(1)04
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1596 * @todo TODO: Integrate to MpegEncContext facilities
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1597 * @{
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1598 */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1599 /** Decode a luma intra block
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1600 * @warning Will be removed, due to necessary integration
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1601 * @see coeff scaling for Adv Profile: 8.1.1.15, p(1)13,
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1602 * @param v VC9 context
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1603 * @param mquant Macroblock quantizer scale
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1604 * @return Status
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1605 * @todo TODO: Implement Coeff scaling for Advanced Profile
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1606 */
2462
michael
parents: 2461
diff changeset
1607 int decode_luma_intra_block(VC9Context *v, int mquant)
michael
parents: 2461
diff changeset
1608 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1609 GetBitContext *gb = &v->s.gb;
2462
michael
parents: 2461
diff changeset
1610 int dcdiff;
michael
parents: 2461
diff changeset
1611
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1612 dcdiff = get_vlc2(gb, v->luma_dc_vlc->table,
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1613 DC_VLC_BITS, 2);
2462
michael
parents: 2461
diff changeset
1614 if (dcdiff)
michael
parents: 2461
diff changeset
1615 {
michael
parents: 2461
diff changeset
1616 if (dcdiff == 119 /* ESC index value */)
michael
parents: 2461
diff changeset
1617 {
michael
parents: 2461
diff changeset
1618 /* TODO: Optimize */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1619 if (mquant == 1) dcdiff = get_bits(gb, 10);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1620 else if (mquant == 2) dcdiff = get_bits(gb, 9);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1621 else dcdiff = get_bits(gb, 8);
2462
michael
parents: 2461
diff changeset
1622 }
michael
parents: 2461
diff changeset
1623 else
michael
parents: 2461
diff changeset
1624 {
michael
parents: 2461
diff changeset
1625 if (mquant == 1)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1626 dcdiff = (dcdiff<<2) + get_bits(gb, 2) - 3;
2462
michael
parents: 2461
diff changeset
1627 else if (mquant == 2)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1628 dcdiff = (dcdiff<<1) + get_bits(gb, 1) - 1;
2462
michael
parents: 2461
diff changeset
1629 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1630 if (get_bits(gb, 1))
2462
michael
parents: 2461
diff changeset
1631 dcdiff = -dcdiff;
michael
parents: 2461
diff changeset
1632 }
michael
parents: 2461
diff changeset
1633 /* FIXME: 8.1.1.15, p(1)13, coeff scaling for Adv Profile */
michael
parents: 2461
diff changeset
1634
michael
parents: 2461
diff changeset
1635 return 0;
michael
parents: 2461
diff changeset
1636 }
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1637 /** @} */ //End for group block
2462
michael
parents: 2461
diff changeset
1638
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1639 /***********************************************************************/
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1640 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1641 * @defgroup std_mb VC9 Macroblock-level functions in Simple/Main Profiles
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1642 * @see 7.1.4, p91 and 8.1.1.7, p(1)04
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1643 * @todo TODO: Integrate to MpegEncContext facilities
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1644 * @{
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1645 */
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1646 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1647 * @def GET_CBPCY(table, bits)
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1648 * @brief Get the Coded Block Pattern for luma and chroma
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1649 * @param table VLC table to use (get_vlc2 second parameter)
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1650 * @param bits Average bitlength (third parameter to get_vlc2)
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1651 * @see 8.1.1.5, p(1)02-(1)03
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1652 */
2462
michael
parents: 2461
diff changeset
1653 #define GET_CBPCY(table, bits) \
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1654 predicted_cbpcy = get_vlc2(gb, table, bits, 2); \
2462
michael
parents: 2461
diff changeset
1655 cbpcy[0] = (p_cbpcy[-1] == p_cbpcy[2]) \
michael
parents: 2461
diff changeset
1656 ? previous_cbpcy[1] : p_cbpcy[+2]; \
michael
parents: 2461
diff changeset
1657 cbpcy[0] ^= ((predicted_cbpcy>>5)&0x01); \
michael
parents: 2461
diff changeset
1658 cbpcy[1] = (p_cbpcy[2] == p_cbpcy[3]) ? cbpcy[0] : p_cbpcy[3]; \
michael
parents: 2461
diff changeset
1659 cbpcy[1] ^= ((predicted_cbpcy>>4)&0x01); \
michael
parents: 2461
diff changeset
1660 cbpcy[2] = (previous_cbpcy[1] == cbpcy[0]) \
michael
parents: 2461
diff changeset
1661 ? previous_cbpcy[3] : cbpcy[0]; \
michael
parents: 2461
diff changeset
1662 cbpcy[2] ^= ((predicted_cbpcy>>3)&0x01); \
michael
parents: 2461
diff changeset
1663 cbpcy[3] = (cbpcy[1] == cbpcy[0]) ? cbpcy[2] : cbpcy[1]; \
michael
parents: 2461
diff changeset
1664 cbpcy[3] ^= ((predicted_cbpcy>>2)&0x01);
michael
parents: 2461
diff changeset
1665
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1666 /** Decode all MBs for an I frame in Simple/Main profile
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1667 * @see 8.1, p100
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1668 * @todo TODO: Process the blocks
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1669 * @todo TODO: Use M$ MPEG-4 cbp prediction
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1670 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1671 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
1672 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1673 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1674 MpegEncContext *s = &v->s;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1675 int current_mb = 0; /* MB/Block Position info */
2462
michael
parents: 2461
diff changeset
1676 uint8_t cbpcy[4], previous_cbpcy[4], predicted_cbpcy,
michael
parents: 2461
diff changeset
1677 *p_cbpcy /* Pointer to skip some math */;
michael
parents: 2461
diff changeset
1678
michael
parents: 2461
diff changeset
1679 /* Reset CBPCY predictors */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1680 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
1681
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1682 /* 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
1683 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
1684 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
1685 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
1686
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1687 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
1688 {
2462
michael
parents: 2461
diff changeset
1689 /* Init CBPCY for line */
michael
parents: 2461
diff changeset
1690 *((uint32_t*)previous_cbpcy) = 0x00000000;
michael
parents: 2461
diff changeset
1691 p_cbpcy = v->previous_line_cbpcy+4;
michael
parents: 2461
diff changeset
1692
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1693 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
1694 {
2462
michael
parents: 2461
diff changeset
1695 /* Get CBPCY */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1696 GET_CBPCY(ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS);
2462
michael
parents: 2461
diff changeset
1697
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1698 s->ac_pred = get_bits(gb, 1);
2462
michael
parents: 2461
diff changeset
1699
michael
parents: 2461
diff changeset
1700 /* TODO: Decode blocks from that mb wrt cbpcy */
michael
parents: 2461
diff changeset
1701
michael
parents: 2461
diff changeset
1702 /* Update for next block */
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1703 #if TRACE > 2
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1704 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
1705 " 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
1706 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
1707 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
1708 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
1709 #endif
2462
michael
parents: 2461
diff changeset
1710 *((uint32_t*)p_cbpcy) = *((uint32_t*)previous_cbpcy);
michael
parents: 2461
diff changeset
1711 *((uint32_t*)previous_cbpcy) = *((uint32_t*)cbpcy);
michael
parents: 2461
diff changeset
1712 current_mb++;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1713 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1714 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1715 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1716 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1717
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1718 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1719 * @def GET_MQUANT
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1720 * @brief Get macroblock-level quantizer scale
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1721 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1722 #define GET_MQUANT() \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1723 if (v->dquantfrm) \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1724 { \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1725 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
1726 { \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1727 if (v->dqbilevel) \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1728 { \
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1729 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
1730 } \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1731 else \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1732 { \
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1733 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
1734 if (mqdiff != 7) mquant = v->pq + mqdiff; \
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1735 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
1736 } \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1737 } \
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_MVDATA(_dmv_x, _dmv_y)
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1742 * @brief Get MV differentials
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1743 * @see MVDATA decoding from 8.3.5.2, p(1)20
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1744 * @param dmv_x Horizontal differential for decoded MV
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1745 * @param dmv_y Vertical differential for decoded MV
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1746 */
2462
michael
parents: 2461
diff changeset
1747 #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
1748 index = 1 + get_vlc2(gb, vc9_mv_diff_vlc[s->mv_table_index].table,\
2462
michael
parents: 2461
diff changeset
1749 VC9_MV_DIFF_VLC_BITS, 2); \
michael
parents: 2461
diff changeset
1750 if (index > 36) \
michael
parents: 2461
diff changeset
1751 { \
michael
parents: 2461
diff changeset
1752 mb_has_coeffs = 1; \
michael
parents: 2461
diff changeset
1753 index -= 37; \
michael
parents: 2461
diff changeset
1754 } \
michael
parents: 2461
diff changeset
1755 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
1756 s->mb_intra = 0; \
2462
michael
parents: 2461
diff changeset
1757 if (!index) { _dmv_x = _dmv_y = 0; } \
michael
parents: 2461
diff changeset
1758 else if (index == 35) \
michael
parents: 2461
diff changeset
1759 { \
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1760 _dmv_x = get_bits(gb, k_x); \
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1761 _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
1762 s->mb_intra = 1; \
2462
michael
parents: 2461
diff changeset
1763 } \
michael
parents: 2461
diff changeset
1764 else \
michael
parents: 2461
diff changeset
1765 { \
michael
parents: 2461
diff changeset
1766 index1 = index%6; \
michael
parents: 2461
diff changeset
1767 if (hpel_flag && index1 == 5) val = 1; \
michael
parents: 2461
diff changeset
1768 else val = 0; \
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1769 val = get_bits(gb, size_table[index1] - val); \
2462
michael
parents: 2461
diff changeset
1770 sign = 0 - (val&1); \
michael
parents: 2461
diff changeset
1771 _dmv_x = (sign ^ ((val>>1) + offset_table[index1])) - sign; \
michael
parents: 2461
diff changeset
1772 \
michael
parents: 2461
diff changeset
1773 index1 = index/6; \
michael
parents: 2461
diff changeset
1774 if (hpel_flag && index1 == 5) val = 1; \
michael
parents: 2461
diff changeset
1775 else val = 0; \
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1776 val = get_bits(gb, size_table[index1] - val); \
2462
michael
parents: 2461
diff changeset
1777 sign = 0 - (val&1); \
michael
parents: 2461
diff changeset
1778 _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
1779 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1780
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1781 /** Decode all MBs for an P frame in Simple/Main profile
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1782 * @see 8.1, p(1)15
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1783 * @todo TODO: Process the blocks
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1784 * @todo TODO: Use M$ MPEG-4 cbp prediction
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1785 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1786 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
1787 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1788 MpegEncContext *s = &v->s;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1789 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1790 int current_mb = 0, i; /* MB/Block Position info */
2462
michael
parents: 2461
diff changeset
1791 uint8_t cbpcy[4], previous_cbpcy[4], predicted_cbpcy,
michael
parents: 2461
diff changeset
1792 *p_cbpcy /* Pointer to skip some math */;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1793 int hybrid_pred; /* Prediction types */
2462
michael
parents: 2461
diff changeset
1794 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
1795 int mqdiff, mquant; /* MB quantization */
2462
michael
parents: 2461
diff changeset
1796 int ttmb; /* MB Transform type */
michael
parents: 2461
diff changeset
1797
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1798 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
1799 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
1800 int mb_has_coeffs = 1; /* last_flag */
2462
michael
parents: 2461
diff changeset
1801 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
1802 int k_x, k_y; /* Long MV fixed bitlength */
2462
michael
parents: 2461
diff changeset
1803 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
1804 int index, index1; /* LUT indices */
2462
michael
parents: 2461
diff changeset
1805 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
1806
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1807 /* 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
1808 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
1809 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
1810 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
1811
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1812 /* Select proper long MV range */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1813 switch (v->mvrange)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1814 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1815 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
1816 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
1817 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
1818 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
1819 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1820
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1821 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
1822 k_x -= hpel_flag;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1823 k_y -= hpel_flag;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1824
2462
michael
parents: 2461
diff changeset
1825 /* Reset CBPCY predictors */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1826 memset(v->previous_line_cbpcy, 0, s->mb_stride<<2);
2462
michael
parents: 2461
diff changeset
1827
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1828 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
1829 {
2462
michael
parents: 2461
diff changeset
1830 /* Init CBPCY for line */
michael
parents: 2461
diff changeset
1831 *((uint32_t*)previous_cbpcy) = 0x00000000;
michael
parents: 2461
diff changeset
1832 p_cbpcy = v->previous_line_cbpcy+4;
michael
parents: 2461
diff changeset
1833
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1834 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
1835 {
2462
michael
parents: 2461
diff changeset
1836 if (v->mv_type_mb_plane.is_raw)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1837 v->mv_type_mb_plane.data[current_mb] = get_bits(gb, 1);
2462
michael
parents: 2461
diff changeset
1838 if (v->skip_mb_plane.is_raw)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1839 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
1840 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
1841 {
2462
michael
parents: 2461
diff changeset
1842 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
1843 {
2462
michael
parents: 2461
diff changeset
1844 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
1845
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1846 /* 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
1847 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
1848 v->mv_mode == MV_PMODE_MIXED_MV)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1849 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
1850 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
1851 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1852 GET_MQUANT();
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1853 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
1854 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1855 else if (mb_has_coeffs)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1856 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1857 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
1858 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
1859 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
1860 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
1861 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
1862 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
1863 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
1864 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
1865 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
1866 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
1867 //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
1868
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1869 GET_MQUANT();
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1870 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1871 if (!v->ttmbf)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1872 ttmb = get_vlc2(gb, v->ttmb_vlc->table,
2462
michael
parents: 2461
diff changeset
1873 VC9_TTMB_VLC_BITS, 12);
michael
parents: 2461
diff changeset
1874 /* 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
1875 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1876 else //Skipped
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1877 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1878 /* 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
1879 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
1880 v->mv_mode == MV_PMODE_MIXED_MV)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1881 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
1882 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1883 } //1MV mode
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1884 else //4MV mode
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1885 {
2462
michael
parents: 2461
diff changeset
1886 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
1887 {
2462
michael
parents: 2461
diff changeset
1888 /* Get CBPCY */
michael
parents: 2461
diff changeset
1889 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
1890 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
1891 {
2462
michael
parents: 2461
diff changeset
1892 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
1893 {
2462
michael
parents: 2461
diff changeset
1894 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
1895 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1896 if (v->mv_mode == MV_PMODE_MIXED_MV /* Hybrid pred */)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1897 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
1898 GET_MQUANT();
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
1899 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
1900 index /* non-zero pred for that block */)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1901 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
1902 if (!v->ttmbf)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1903 ttmb = get_vlc2(gb, v->ttmb_vlc->table,
2462
michael
parents: 2461
diff changeset
1904 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
1905
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1906 /* TODO: Process blocks wrt cbpcy */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1907
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1908 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1909 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1910 else //Skipped MB
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1911 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1912 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
1913 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1914 if (v->mv_mode == MV_PMODE_MIXED_MV /* Hybrid pred */)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1915 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
1916
2462
michael
parents: 2461
diff changeset
1917 /* TODO: do something */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1918 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1919 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1920 }
2462
michael
parents: 2461
diff changeset
1921
michael
parents: 2461
diff changeset
1922 /* Update for next block */
michael
parents: 2461
diff changeset
1923 #if TRACE > 2
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1924 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
1925 " cbpcy=%i%i%i%i\n", current_mb,
michael
parents: 2461
diff changeset
1926 p_cbpcy[0], p_cbpcy[1], p_cbpcy[2], p_cbpcy[3],
michael
parents: 2461
diff changeset
1927 previous_cbpcy[0], previous_cbpcy[1], previous_cbpcy[2], previous_cbpcy[3],
michael
parents: 2461
diff changeset
1928 cbpcy[0], cbpcy[1], cbpcy[2], cbpcy[3]);
michael
parents: 2461
diff changeset
1929 #endif
michael
parents: 2461
diff changeset
1930 *((uint32_t*)p_cbpcy) = *((uint32_t*)previous_cbpcy);
michael
parents: 2461
diff changeset
1931 *((uint32_t*)previous_cbpcy) = *((uint32_t*)cbpcy);
michael
parents: 2461
diff changeset
1932 current_mb++;
2445
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 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1935 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1936 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1937
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1938 /** Decode all MBs for an P frame in Simple/Main profile
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1939 * @todo TODO: Process the blocks
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1940 * @todo TODO: Use M$ MPEG-4 cbp prediction
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
1941 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1942 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
1943 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1944 MpegEncContext *s = &v->s;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1945 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1946 int current_mb = 0, i /* MB / B postion information */;
2462
michael
parents: 2461
diff changeset
1947 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
1948 int mquant, mqdiff; /* MB quant stuff */
2462
michael
parents: 2461
diff changeset
1949 int ttmb; /* MacroBlock transform type */
michael
parents: 2461
diff changeset
1950
michael
parents: 2461
diff changeset
1951 static const int size_table[6] = { 0, 2, 3, 4, 5, 8 },
michael
parents: 2461
diff changeset
1952 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
1953 int mb_has_coeffs = 1; /* last_flag */
2462
michael
parents: 2461
diff changeset
1954 int dmv1_x, dmv1_y, dmv2_x, dmv2_y; /* Differential MV components */
michael
parents: 2461
diff changeset
1955 int k_x, k_y; /* Long MV fixed bitlength */
michael
parents: 2461
diff changeset
1956 int hpel_flag; /* Some MB properties */
michael
parents: 2461
diff changeset
1957 int index, index1; /* LUT indices */
michael
parents: 2461
diff changeset
1958 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
1959
2462
michael
parents: 2461
diff changeset
1960 /* Select proper long MV range */
michael
parents: 2461
diff changeset
1961 switch (v->mvrange)
michael
parents: 2461
diff changeset
1962 {
michael
parents: 2461
diff changeset
1963 case 1: k_x = 10; k_y = 9; break;
michael
parents: 2461
diff changeset
1964 case 2: k_x = 12; k_y = 10; break;
michael
parents: 2461
diff changeset
1965 case 3: k_x = 13; k_y = 11; break;
michael
parents: 2461
diff changeset
1966 default: /*case 0 too */ k_x = 9; k_y = 8; break;
michael
parents: 2461
diff changeset
1967 }
michael
parents: 2461
diff changeset
1968 hpel_flag = v->mv_mode & 1; //MV_PMODE is HPEL
michael
parents: 2461
diff changeset
1969 k_x -= hpel_flag;
michael
parents: 2461
diff changeset
1970 k_y -= hpel_flag;
michael
parents: 2461
diff changeset
1971
michael
parents: 2461
diff changeset
1972 /* Select ttmb table depending on pq */
michael
parents: 2461
diff changeset
1973 if (v->pq < 5) v->ttmb_vlc = &vc9_ttmb_vlc[0];
michael
parents: 2461
diff changeset
1974 else if (v->pq < 13) v->ttmb_vlc = &vc9_ttmb_vlc[1];
michael
parents: 2461
diff changeset
1975 else v->ttmb_vlc = &vc9_ttmb_vlc[2];
michael
parents: 2461
diff changeset
1976
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1977 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
1978 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1979 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
1980 {
2462
michael
parents: 2461
diff changeset
1981 if (v->direct_mb_plane.is_raw)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1982 v->direct_mb_plane.data[current_mb] = get_bits(gb, 1);
2462
michael
parents: 2461
diff changeset
1983 if (v->skip_mb_plane.is_raw)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1984 v->skip_mb_plane.data[current_mb] = get_bits(gb, 1);
2462
michael
parents: 2461
diff changeset
1985
michael
parents: 2461
diff changeset
1986 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
1987 {
2462
michael
parents: 2461
diff changeset
1988 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
1989 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1990 b_mv_type = decode012(gb);
2462
michael
parents: 2461
diff changeset
1991 if (v->bfraction > 420 /*1/2*/ &&
michael
parents: 2461
diff changeset
1992 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
1993 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1994 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1995 {
2462
michael
parents: 2461
diff changeset
1996 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
1997 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
1998 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
1999 b_mv_type = decode012(gb);
2462
michael
parents: 2461
diff changeset
2000 if (v->bfraction > 420 /*1/2*/ &&
michael
parents: 2461
diff changeset
2001 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
2002 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2003 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2004 }
2462
michael
parents: 2461
diff changeset
2005 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
2006 {
2462
michael
parents: 2461
diff changeset
2007 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
2008 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2009 GET_MQUANT();
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
2010 if (s->mb_intra /* intra mb */)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2011 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
2012 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2013 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2014 {
2462
michael
parents: 2461
diff changeset
2015 /* if bmv1 tells MVs are interpolated */
michael
parents: 2461
diff changeset
2016 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
2017 {
2462
michael
parents: 2461
diff changeset
2018 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
2019 }
2462
michael
parents: 2461
diff changeset
2020 /* GET_MVDATA has reset some stuff */
michael
parents: 2461
diff changeset
2021 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
2022 {
2475
db05cb59c6fc - add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in
michael
parents: 2474
diff changeset
2023 if (s->mb_intra /* intra_mb */)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2024 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
2025 GET_MQUANT();
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2026 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2027 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2028 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2029 //End1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2030 if (v->ttmbf)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2031 ttmb = get_vlc2(gb, v->ttmb_vlc->table,
2462
michael
parents: 2461
diff changeset
2032 VC9_TTMB_VLC_BITS, 12);
michael
parents: 2461
diff changeset
2033
michael
parents: 2461
diff changeset
2034 //End2
michael
parents: 2461
diff changeset
2035 for (i=0; i<6; i++)
michael
parents: 2461
diff changeset
2036 {
michael
parents: 2461
diff changeset
2037 /* FIXME: process the block */
michael
parents: 2461
diff changeset
2038 }
michael
parents: 2461
diff changeset
2039
michael
parents: 2461
diff changeset
2040 current_mb++;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2041 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2042 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2043 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2044 }
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2045 /** @} */ //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
2046
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2047 #if HAS_ADVANCED_PROFILE
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2048 /***********************************************************************/
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2049 /**
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2050 * @defgroup adv_mb VC9 Macroblock-level functions in Advanced Profile
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2051 * @todo TODO: Integrate to MpegEncContext facilities
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2052 * @todo TODO: Code P, B and BI
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2053 * @{
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2054 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2055 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
2056 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2057 MpegEncContext *s = &v->s;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2058 GetBitContext *gb = &v->s.gb;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2059 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
2060
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2061 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
2062 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2063 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
2064 {
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2065 if (v->ac_pred_plane.is_raw)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2066 s->ac_pred = get_bits(gb, 1);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2067 else
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2068 s->ac_pred = v->ac_pred_plane.data[current_mb];
2462
michael
parents: 2461
diff changeset
2069 if (v->condover == 3 && v->over_flags_plane.is_raw)
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2070 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
2071 GET_MQUANT();
2462
michael
parents: 2461
diff changeset
2072
michael
parents: 2461
diff changeset
2073 /* TODO: lots */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2074 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2075 current_mb++;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2076 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2077 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2078 }
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2079 /** @} */ //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
2080 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2081
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2082 /** Initialize a VC9/WMV3 decoder
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2083 * @todo TODO: Handle VC-9 IDUs (Transport level?)
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2084 * @todo TODO: Decypher remaining bits in extra_data
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2085 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2086 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
2087 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2088 VC9Context *v = avctx->priv_data;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2089 MpegEncContext *s = &v->s;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2090 GetBitContext gb;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2091
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2092 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
2093 avctx->pix_fmt = PIX_FMT_YUV420P;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2094 v->s.avctx = avctx;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2095
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2096 if(ff_h263_decode_init(avctx) < 0)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2097 return -1;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2098 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
2099
2462
michael
parents: 2461
diff changeset
2100 avctx->coded_width = avctx->width;
michael
parents: 2461
diff changeset
2101 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
2102 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
2103 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2104 int count = 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2105
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2106 // looks like WMV3 has a sequence header stored in the extradata
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2107 // advanced sequence header may be before the first frame
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2108 // the last byte of the extradata is a version number, 1 for the
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2109 // samples we can decode
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2110
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2111 init_get_bits(&gb, avctx->extradata, avctx->extradata_size);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2112
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2113 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
2114
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2115 count = avctx->extradata_size*8 - get_bits_count(&gb);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2116 if (count>0)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2117 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2118 av_log(avctx, AV_LOG_INFO, "Extra data: %i bits left, value: %X\n",
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2119 count, get_bits(&gb, count));
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2120 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2121 else
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2122 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2123 av_log(avctx, AV_LOG_INFO, "Read %i bits in overflow\n", -count);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2124 }
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2125 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2126 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
2127
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2128 s->mb_width = (avctx->coded_width+15)>>4;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2129 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
2130
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2131 /* Allocate mb bitplanes */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2132 if (alloc_bitplane(&v->mv_type_mb_plane, s->mb_width, s->mb_height) < 0)
2462
michael
parents: 2461
diff changeset
2133 return -1;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2134 if (alloc_bitplane(&v->mv_type_mb_plane, s->mb_width, s->mb_height) < 0)
2462
michael
parents: 2461
diff changeset
2135 return -1;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2136 if (alloc_bitplane(&v->skip_mb_plane, s->mb_width, s->mb_height) < 0)
2462
michael
parents: 2461
diff changeset
2137 return -1;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2138 if (alloc_bitplane(&v->direct_mb_plane, s->mb_width, s->mb_height) < 0)
2462
michael
parents: 2461
diff changeset
2139 return -1;
michael
parents: 2461
diff changeset
2140
michael
parents: 2461
diff changeset
2141 /* For predictors */
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2142 v->previous_line_cbpcy = (uint8_t *)av_malloc(s->mb_stride*4);
2462
michael
parents: 2461
diff changeset
2143 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
2144
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2145 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2146 if (v->profile > PROFILE_MAIN)
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 if (alloc_bitplane(&v->over_flags_plane, s->mb_width, s->mb_height) < 0)
2462
michael
parents: 2461
diff changeset
2149 return -1;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2150 if (alloc_bitplane(&v->ac_pred_plane, s->mb_width, s->mb_height) < 0)
2462
michael
parents: 2461
diff changeset
2151 return -1;
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 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2154
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2155 return 0;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2156 }
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2157
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2158 /** Decode a VC9/WMV3 frame
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2159 * @todo TODO: Handle VC-9 IDUs (Transport level?)
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2160 * @warning Initial try at using MpegEncContext stuff
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2161 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2162 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
2163 void *data, int *data_size,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2164 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
2165 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2166 VC9Context *v = avctx->priv_data;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2167 MpegEncContext *s = &v->s;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2168 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
2169 AVFrame *pict = data;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2170 uint8_t *tmp_buf;
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2171 v->s.avctx = avctx;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2172
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2173 //buf_size = 0 -> last frame
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2174 if (!buf_size) return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2175
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2176 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
2177 avctx->height);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2178 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
2179 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
2180 avctx->width, avctx->height);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2181
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2182 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
2183 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2184 #if 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2185 // search for IDU's
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2186 // FIXME
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2187 uint32_t scp = 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2188 int scs = 0, i = 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2189
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2190 while (i < buf_size)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2191 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2192 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
2193 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
2194
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2195 if (scp != 0x000001)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2196 break; // eof ?
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 scs = buf[i++];
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2199
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2200 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
2201
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2202 switch(scs)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2203 {
2462
michael
parents: 2461
diff changeset
2204 case 0x0A: //Sequence End Code
michael
parents: 2461
diff changeset
2205 return 0;
michael
parents: 2461
diff changeset
2206 case 0x0B: //Slice Start Code
michael
parents: 2461
diff changeset
2207 av_log(avctx, AV_LOG_ERROR, "Slice coding not supported\n");
michael
parents: 2461
diff changeset
2208 return -1;
michael
parents: 2461
diff changeset
2209 case 0x0C: //Field start code
michael
parents: 2461
diff changeset
2210 av_log(avctx, AV_LOG_ERROR, "Interlaced coding not supported\n");
michael
parents: 2461
diff changeset
2211 return -1;
michael
parents: 2461
diff changeset
2212 case 0x0D: //Frame start code
michael
parents: 2461
diff changeset
2213 break;
michael
parents: 2461
diff changeset
2214 case 0x0E: //Entry point Start Code
michael
parents: 2461
diff changeset
2215 if (v->profile <= MAIN_PROFILE)
michael
parents: 2461
diff changeset
2216 av_log(avctx, AV_LOG_ERROR,
michael
parents: 2461
diff changeset
2217 "Found an entry point in profile %i\n", v->profile);
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2218 advanced_entry_point_process(avctx, gb);
2462
michael
parents: 2461
diff changeset
2219 break;
michael
parents: 2461
diff changeset
2220 case 0x0F: //Sequence header Start Code
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2221 decode_sequence_header(avctx, gb);
2462
michael
parents: 2461
diff changeset
2222 break;
michael
parents: 2461
diff changeset
2223 default:
michael
parents: 2461
diff changeset
2224 av_log(avctx, AV_LOG_ERROR,
michael
parents: 2461
diff changeset
2225 "Unsupported IDU suffix %lX\n", scs);
michael
parents: 2461
diff changeset
2226 }
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2227
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2228 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
2229 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2230 #else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2231 av_abort();
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2232 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2233 }
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2234 else
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2235 init_get_bits(&v->s.gb, buf, buf_size*8);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2236
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2237 s->flags= avctx->flags;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2238 s->flags2= avctx->flags2;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2239
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2240 /* no supplementary picture */
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2241 if (buf_size == 0) {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2242 /* special case for last picture */
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2243 if (s->low_delay==0 && s->next_picture_ptr) {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2244 *pict= *(AVFrame*)s->next_picture_ptr;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2245 s->next_picture_ptr= NULL;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2246
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2247 *data_size = sizeof(AVFrame);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2248 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2249
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2250 return 0;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2251 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2252
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2253 //No IDU - we mimic ff_h263_decode_frame
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2254 s->bitstream_buffer_size=0;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2255
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2256 if (!s->context_initialized) {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2257 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
2258 return -1;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2259 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2260
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2261 //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
2262 if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2263 s->current_picture_ptr= &s->picture[ff_find_unused_picture(s, 0)];
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2264 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2265 #if HAS_ADVANCED_PROFILE
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2266 if (v->profile > PROFILE_MAIN)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2267 ret= advanced_decode_picture_primary_header(v);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2268 else
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2269 #endif
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2270 ret= standard_decode_picture_primary_header(v);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2271 if (ret == FRAME_SKIPED) return buf_size;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2272 /* skip if the header was thrashed */
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2273 if (ret < 0){
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2274 av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2275 return -1;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2276 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2277
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2278 //No bug workaround yet, no DCT conformance
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2279
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2280 //WMV9 does have resized images
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2281 if (v->profile <= PROFILE_MAIN && v->multires){
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2282 //Parse context stuff in here, don't know how appliable it is
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2283 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2284 //Not sure about context initialization
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2285
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2286 // for hurry_up==5
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2287 s->current_picture.pict_type= s->pict_type;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2288 s->current_picture.key_frame= s->pict_type == I_TYPE;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2289
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2290 /* skip b frames if we dont have reference frames */
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2291 if(s->last_picture_ptr==NULL && (s->pict_type==B_TYPE || s->dropable))
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2292 return buf_size; //FIXME simulating all buffer consumed
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2293 /* skip b frames if we are in a hurry */
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2294 if(avctx->hurry_up && s->pict_type==B_TYPE)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2295 return buf_size; //FIXME simulating all buffer consumed
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2296 /* skip everything if we are in a hurry>=5 */
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2297 if(avctx->hurry_up>=5)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2298 return buf_size; //FIXME simulating all buffer consumed
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2299
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2300 if(s->next_p_frame_damaged){
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2301 if(s->pict_type==B_TYPE)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2302 return buf_size; //FIXME simulating all buffer consumed
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2303 else
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2304 s->next_p_frame_damaged=0;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2305 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2306
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2307 if(MPV_frame_start(s, avctx) < 0)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2308 return -1;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2309
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2310 ff_er_frame_start(s);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2311
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2312 //wmv9 may or may not have skip bits
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2313 #if HAS_ADVANCED_PROFILE
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2314 if (v->profile > PROFILE_MAIN)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2315 ret= advanced_decode_picture_secondary_header(v);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2316 else
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2317 #endif
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2318 ret = standard_decode_picture_secondary_header(v);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2319 if (ret<0) return FRAME_SKIPED; //FIXME Non fatal for now
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2320
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2321 //We consider the image coded in only one slice
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2322 #if HAS_ADVANCED_PROFILE
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2323 if (v->profile > PROFILE_MAIN)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2324 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2325 switch(s->pict_type)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2326 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2327 case I_TYPE: ret = advanced_decode_i_mbs(v); break;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2328 case P_TYPE: ret = decode_p_mbs(v); break;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2329 case B_TYPE:
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2330 case BI_TYPE: ret = decode_b_mbs(v); break;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2331 default: ret = FRAME_SKIPED;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2332 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2333 if (ret == FRAME_SKIPED) return buf_size; //We ignore for now failures
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2334 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2335 else
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2336 #endif
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2337 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2338 switch(s->pict_type)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2339 {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2340 case I_TYPE: ret = standard_decode_i_mbs(v); break;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2341 case P_TYPE: ret = decode_p_mbs(v); break;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2342 case B_TYPE:
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2343 case BI_TYPE: ret = decode_b_mbs(v); break;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2344 default: ret = FRAME_SKIPED;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2345 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2346 if (ret == FRAME_SKIPED) return buf_size;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2347 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2348
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2349 ff_er_frame_end(s);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2350
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2351 MPV_frame_end(s);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2352
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2353 assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2354 assert(s->current_picture.pict_type == s->pict_type);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2355 if(s->pict_type==B_TYPE || s->low_delay){
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2356 *pict= *(AVFrame*)&s->current_picture;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2357 ff_print_debug_info(s, pict);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2358 } else {
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2359 *pict= *(AVFrame*)&s->last_picture;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2360 if(pict)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2361 ff_print_debug_info(s, pict);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2362 }
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2363
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2364 /* Return the Picture timestamp as the frame number */
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2365 /* we substract 1 because it is added on utils.c */
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2366 avctx->frame_number = s->picture_number - 1;
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2367
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2368 /* dont output the last pic after seeking */
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2369 if(s->last_picture_ptr || s->low_delay)
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2370 *data_size = sizeof(AVFrame);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2371
2462
michael
parents: 2461
diff changeset
2372 av_log(avctx, AV_LOG_DEBUG, "Consumed %i/%i bits\n",
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2373 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
2374
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2375 /* Fake consumption of all data */
2462
michael
parents: 2461
diff changeset
2376 *data_size = len;
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2377 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
2378 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2379
2482
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2380 /** Close a VC9/WMV3 decoder
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2381 * @warning Initial try at using MpegEncContext stuff
5d28ea40fd98 Documentation patch by anonymous
michael
parents: 2476
diff changeset
2382 */
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2383 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
2384 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2385 VC9Context *v = avctx->priv_data;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2386
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2387 #if HAS_ADVANCED_PROFILE
2458
915094e3da5d dont use several 100 mb memory for a tiny 120 element table
michael
parents: 2453
diff changeset
2388 av_freep(&v->hrd_rate);
915094e3da5d dont use several 100 mb memory for a tiny 120 element table
michael
parents: 2453
diff changeset
2389 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
2390 #endif
2474
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2391 MPV_common_end(&v->s);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2392 free_bitplane(&v->mv_type_mb_plane);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2393 free_bitplane(&v->skip_mb_plane);
81a9f883a17a In that patch:
michael
parents: 2465
diff changeset
2394 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
2395 return 0;
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
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2398 AVCodec vc9_decoder = {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2399 "vc9",
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2400 CODEC_TYPE_VIDEO,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2401 CODEC_ID_VC9,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2402 sizeof(VC9Context),
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2403 vc9_decode_init,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2404 NULL,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2405 vc9_decode_end,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2406 vc9_decode_frame,
2453
f67b63ed036d avoid buf_size == 0 checks in every decoder
michael
parents: 2445
diff changeset
2407 CODEC_CAP_DELAY,
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2408 NULL
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2409 };
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2410
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2411 AVCodec wmv3_decoder = {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2412 "wmv3",
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2413 CODEC_TYPE_VIDEO,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2414 CODEC_ID_WMV3,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2415 sizeof(VC9Context),
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2416 vc9_decode_init,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2417 NULL,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2418 vc9_decode_end,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2419 vc9_decode_frame,
2453
f67b63ed036d avoid buf_size == 0 checks in every decoder
michael
parents: 2445
diff changeset
2420 CODEC_CAP_DELAY,
2445
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2421 NULL
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
2422 };