annotate vc9.c @ 2475:db05cb59c6fc libavcodec

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