annotate vc9.c @ 2445:96da66323faa libavcodec

preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
author alex
date Sat, 22 Jan 2005 17:52:01 +0000
parents
children f67b63ed036d
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
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
5 *
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
6 * 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
7 * 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
8 * 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
9 * 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
10 *
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
11 * 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
12 * 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
13 * 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
14 * 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
15 *
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
16 * 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
17 * 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
18 * 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
19 *
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 * @file vc9.c
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
24 * VC-9 and WMV3 decoder
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
25 *
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
26 * 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
27 * TODO: use MPV_ !!
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
28 */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
29 #include "common.h"
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
30 #include "dsputil.h"
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
31 #include "avcodec.h"
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
32 #include "mpegvideo.h"
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
33 #include "vc9data.h"
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
34
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
35 /* Some inhibiting stuff */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
36 #define HAS_ADVANCED_PROFILE 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
37 #define TRACE 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
38
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
39 #if TRACE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
40 # 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
41 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
42 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
43 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
44 { \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
45 av_log(v->avctx, AV_LOG_ERROR, "Error for " # vlc " (%i)\n", i); \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
46 return -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 #else
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 init_vlc(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
52 codes, codes_wrap, codes_size, use_static)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
53 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
54
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
55 #define PROFILE_SIMPLE 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
56 #define PROFILE_MAIN 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
57 #define PROFILE_ADVANCED 3
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
58
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
59 #define QUANT_FRAME_IMPLICIT 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
60 #define QUANT_FRAME_EXPLICIT 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
61 #define QUANT_NON_UNIFORM 2
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
62 #define QUANT_UNIFORM 3
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 /* Where quant can be changed */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
65 #define DQPROFILE_FOUR_EDGES 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
66 #define DQPROFILE_DOUBLE_EDGES 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
67 #define DQPROFILE_SINGLE_EDGE 2
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
68 #define DQPROFILE_ALL_MBS 3
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
69
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
70 /* 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
71 #define DQSINGLE_BEDGE_LEFT 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
72 #define DQSINGLE_BEDGE_TOP 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
73 #define DQSINGLE_BEDGE_RIGHT 2
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
74 #define DQSINGLE_BEDGE_BOTTOM 3
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
75
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
76 /* 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
77 #define DQDOUBLE_BEDGE_TOPLEFT 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
78 #define DQDOUBLE_BEDGE_TOPRIGHT 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
79 #define DQDOUBLE_BEDGE_BOTTOMRIGHT 2
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
80 #define DQDOUBLE_BEDGE_BOTTOMLEFT 3
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
81
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
82
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
83 /* Start Codes */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
84 #define SEQ_SC 0x00000010F /* Sequence Start Code */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
85 #define SEQ_EC 0x00000000A /* Sequence End code */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
86 #define SEQ_HDR /* Sequence Header */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
87 #define ENTRY_SC 0x00000010E /* Entry Point Start Code */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
88 #define ENTRY_HDR /* Entry Point Header */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
89 #define FRM_SC 0x00000010D /* Frame Start Code */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
90 #define FRM_DAT /* Frame Data (includes a Frame Header) */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
91 #define FLD_SC 0x00000010C /* Field Start Code */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
92 #define FLD1_DAT /* Field 1 Data (includes a Frame Header) */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
93 #define FLD2_DAT /* Field 2 Data (includes a Field Header) */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
94 #define SLC_SC 0x00000010B /* Slice Start Code */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
95 #define SLC_HDR /* Slice Header */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
96 #define SLC_DAT /* Slice Data (FrH or FiH possible) */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
97
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
98 /* MV P modes */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
99 #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
100 #define MV_PMODE_1MV 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
101 #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
102 #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
103 #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
104
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
105 /* MV P mode - the 5th element is only used for mode 1 */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
106 static const uint8_t mv_pmode_table[2][5] = {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
107 { MV_PMODE_1MV_HPEL_BILIN, MV_PMODE_1MV, MV_PMODE_1MV_HPEL, MV_PMODE_MIXED_MV, MV_PMODE_INTENSITY_COMP },
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
108 { MV_PMODE_1MV, MV_PMODE_MIXED_MV, MV_PMODE_1MV_HPEL, MV_PMODE_1MV_HPEL_BILIN, MV_PMODE_INTENSITY_COMP }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
109 };
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
110
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
111 /* One more frame type */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
112 #define BI_TYPE 7
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
113
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
114 /* FIXME Worse than ugly */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
115 static const int fps_nr[5] = { 24, 25, 30, 50, 60 },
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
116 fps_dr[2] = { 1000, 1001 };
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
117 static const uint8_t pquant_table[3][32] = {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
118 { /* Implicit quantizer */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
119 0, 1, 2, 3, 4, 5, 6, 7, 8, 6, 7, 8, 9, 10, 11, 12,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
120 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 29, 31
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
121 },
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
122 { /* Explicit quantizer, pquantizer uniform */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
123 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
124 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
125 },
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
126 { /* Explicit quantizer, pquantizer non-uniform */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
127 0, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
128 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 31
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
129 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
130 };
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
131
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
132 // FIXME move this into the context
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
133 #define VC9_BFRACTION_VLC_BITS 7
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
134 static VLC vc9_bfraction_vlc;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
135 #define VC9_IMODE_VLC_BITS 4
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
136 static VLC vc9_imode_vlc;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
137 #define VC9_NORM2_VLC_BITS 3
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
138 static VLC vc9_norm2_vlc;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
139 /* Could be optimized, one table only needs 8 bits */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
140 #define VC9_TTMB_VLC_BITS 12
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
141 static VLC vc9_ttmb_vlc[3];
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
142 #define VC9_MV_DIFF_VLC_BITS 15
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
143 static VLC vc9_mv_diff_vlc[4];
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
144 #define VC9_CBPCY_I_VLC_BITS 13
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
145 static VLC vc9_cbpcy_i_vlc;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
146 #define VC9_CBPCY_P_VLC_BITS 14
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
147 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
148 #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
149 static VLC vc9_4mv_block_pattern_vlc[4];
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
150 #define VC9_LUMA_DC_VLC_BITS 26
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
151 static VLC vc9_luma_dc_vlc[2];
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
152
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
153 typedef struct VC9Context{
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
154 /* No MpegEnc context, might be good to use it */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
155 GetBitContext gb;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
156 AVCodecContext *avctx;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
157
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
158 /***************************/
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
159 /* Sequence Header */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
160 /***************************/
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
161 /* Simple/Main Profile */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
162 int res_sm; //reserved, 2b
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
163 int res_x8; //reserved
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
164 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
165 int res_fasttx; //always 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
166 int res_transtab; //always 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
167 int syncmarker; //Sync markers presents
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
168 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
169 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
170 int reserved; //duh
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
171
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
172 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
173 /* Advanced Profile */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
174 int level; //3
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
175 int chromaformat; //2
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
176 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
177 int broadcast; //TFF/RFF present
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
178 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
179 int tfcntrflag; //TFCNTR present
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
180 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
181 int extended_dmv;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
182 int color_prim; //8
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
183 int transfer_char; //8
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
184 int matrix_coef; //8
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
185 int hrd_param_flag;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
186 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
187
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
188 /* All Profiles */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
189 /* 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
190 int profile; //2
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
191 int frmrtq_postproc; //3
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
192 int bitrtq_postproc; //5
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
193 int loopfilter;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
194 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
195 int extended_mv; //Ext MV in P/B (not in Simple)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
196 int dquant; //Q varies with MBs, 2bits (not in Simple)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
197 int vstransform; //variable-size transform46
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
198
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
199 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
200 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
201 int finterpflag; //INTERPFRM present
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
202
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
203
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
204 /*****************************/
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
205 /* Frame decoding */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
206 /*****************************/
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
207 /* All profiles */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
208 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
209 uint8_t pict_type; /* Picture type, mapped on MPEG types */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
210 uint8_t pq, altpq; /* Quantizers */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
211 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
212 int width_mb, height_mb;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
213 int tile; /* 3x2 if (width_mb%3) else 2x3 */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
214 int transacfrm2, transacfrm, transacdctab; //1bit elements
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
215 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
216 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
217 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
218 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
219 uint8_t respic;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
220 /* Ranges:
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
221 * 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
222 * 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
223 * 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
224 * 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
225 */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
226 uint8_t mvrange;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
227 uint8_t pquantizer;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
228 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
229 *mv_diff_vlc /* Current MV Diff VLC table */,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
230 *ttmb_vlc /* Current MB Transform Type VLC table */;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
231 uint8_t *mv_type_mb_plane; /* bitplane for mv_type == "raw" */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
232 uint8_t *skip_mb_plane, /* bitplane for skipped MBs */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
233 *direct_mb_plane; /* bitplane for "direct" MBs */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
234
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
235 /* S/M only ? */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
236 uint8_t rangeredfrm, interpfrm;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
237
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
238 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
239 /* Advanced */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
240 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
241 uint8_t numpanscanwin;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
242 uint8_t tfcntr;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
243 uint8_t rptfrm, tff, rff;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
244 uint8_t topleftx;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
245 uint8_t toplefty;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
246 uint8_t bottomrightx;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
247 uint8_t bottomrighty;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
248 uint8_t rndctrl;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
249 uint8_t uvsamp;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
250 uint8_t postproc;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
251 int hrd_num_leaky_buckets;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
252 uint8_t bit_rate_exponent;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
253 uint8_t buffer_size_exponent;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
254 uint8_t *ac_pred_plane;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
255 uint8_t *over_flags_plane;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
256 uint16_t *hrd_rate, *hrd_buffer;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
257 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
258 } VC9Context;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
259
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
260 /* FIXME Slow and ugly */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
261 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
262 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
263 int i = 0, tmp = !stop;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
264
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
265 while (i != len && tmp != stop)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
266 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
267 tmp = get_bits(gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
268 i++;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
269 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
270 return i;
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
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
273 static int init_common(VC9Context *v)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
274 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
275 static int done = 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
276 int i;
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 v->mv_type_mb_plane = v->direct_mb_plane = v->skip_mb_plane = NULL;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
279 v->pq = -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
280 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
281 v->ac_pred_plane = v->over_flags_plane = NULL;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
282 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
283 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
284 if(!done)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
285 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
286 done = 1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
287 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
288 vc9_bfraction_bits, 1, 1,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
289 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
290 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
291 vc9_norm2_bits, 1, 1,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
292 vc9_norm2_codes, 1, 1, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
293 INIT_VLC(&vc9_cbpcy_i_vlc, VC9_CBPCY_I_VLC_BITS, 64,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
294 vc9_cbpcy_i_bits, 1, 1,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
295 vc9_cbpcy_i_codes, 2, 2, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
296 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
297 vc9_imode_bits, 1, 1,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
298 vc9_imode_codes, 1, 1, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
299 for(i=0; i<3; i++)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
300 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
301 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
302 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
303 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
304 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
305 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
306 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
307 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
308 for (i=0; i<2; i++)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
309 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
310 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
311 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
312 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
313 INIT_VLC(&vc9_luma_dc_vlc[i], VC9_LUMA_DC_VLC_BITS, 26,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
314 vc9_luma_dc_bits[i], 1, 1,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
315 vc9_luma_dc_codes[i], 4, 4, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
316 INIT_VLC(&vc9_ttmb_vlc[i], VC9_TTMB_VLC_BITS, 16,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
317 vc9_ttmb_bits[i], 1, 1,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
318 vc9_ttmb_codes[i], 2, 2, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
319 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
320 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
321
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
322 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
323 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
324
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
325 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
326 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
327 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
328 int i, num;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
329
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
330 num = get_bits(gb, 5);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
331
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
332 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
333 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
334 av_free(v->hrd_rate);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
335 v->hrd_rate = NULL;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
336 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
337 if (!v->hrd_rate) v->hrd_rate = av_malloc(num);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
338 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
339
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
340 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
341 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
342 av_free(v->hrd_buffer);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
343 v->hrd_buffer = NULL;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
344 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
345 if (!v->hrd_buffer) v->hrd_buffer = av_malloc(num);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
346 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
347
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
348 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
349
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
350 //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
351 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
352 //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
353 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
354
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
355 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
356 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
357 //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
358 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
359 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
360 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
361 av_log(v, AV_LOG_ERROR, "HDR Rates aren't strictly increasing:"
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
362 "%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
363 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
364 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
365 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
366 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
367 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
368 av_log(v, AV_LOG_ERROR, "HDR Buffers aren't decreasing:"
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
369 "%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
370 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
371 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
372 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
373 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
374 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
375
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
376 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
377 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
378 VC9Context *v = avctx->priv_data;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
379 int nr, dr, aspect_ratio;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
380
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
381 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
382 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
383 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
384
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
385 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
386 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
387 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
388 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
389 if (v->reserved)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
390 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
391 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
392 v->reserved);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
393 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
394 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
395 if (v->extended_mv)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
396 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
397
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
398 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
399 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
400 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
401 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
402 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
403 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
404 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
405 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
406 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
407
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
408 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
409 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
410 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
411 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
412 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
413 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
414 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
415 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
416 else if (aspect_ratio == 0x0E)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
417 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
418 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
419 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
420 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
421 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
422 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
423 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
424 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
425 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
426 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
427 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
428 avctx->coded_width = avctx->width;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
429 avctx->coded_height = avctx->height;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
430 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
431
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
432 if ( get_bits(gb, 1) /* framerateflag */)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
433 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
434 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
435 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
436 nr = get_bits(gb, 8);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
437 dr = get_bits(gb, 4);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
438 if (nr<1)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
439 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
440 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
441 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
442 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
443 if (nr>5)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
444 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
445 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
446 "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
447 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
448 if (dr<1)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
449 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
450 av_log(avctx, AV_LOG_ERROR, "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
451 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
452 if (dr>2)
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,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
455 "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
456 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
457 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
458 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
459 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
460 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
461 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
462 nr = get_bits(gb, 16);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
463 // 0.03125->2048Hz / 0.03125Hz
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
464 avctx->frame_rate = 1000000;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
465 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
466 }
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
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
469 if ( get_bits(gb, 1) /* color_format_flag */)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
470 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
471 //Chromacity coordinates of color primaries
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
472 //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
473 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
474 if (v->color_prim<1)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
475 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
476 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
477 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
478 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
479 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
480 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
481 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
482 v->color_prim);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
483 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
484 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
485
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
486 //Opto-electronic transfer characteristics
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
487 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
488 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
489 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
490 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
491 v->color_prim);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
492 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
493 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
494
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
495 //Matrix coefficient for primariev->YCbCr
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
496 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
497 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
498 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
499 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
500 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
501 v->color_prim);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
502 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
503 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
504 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
505
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
506 //Hypothetical reference decoder indicator flag
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
507 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
508 if (v->hrd_param_flag)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
509 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
510 if (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
511 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
512
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
513 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
514 return -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 #endif
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 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
519 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
520 VC9Context *v = avctx->priv_data;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
521
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
522 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
523 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
524
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
525 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
526 if (v->profile > PROFILE_MAIN)
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 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
529 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
530 if (v->chromaformat != 1)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
531 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
532 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
533 "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
534 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
535 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
536 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
537 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
538 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
539 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
540 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
541 if (v->res_sm)
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,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
544 "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
545 //return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
546 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
547 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
548
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
549 // (fps-2)/4 (->30)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
550 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
551 // (bitrate-32kbps)/64kbps
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
552 v->bitrtq_postproc = get_bits(gb, 5); //common
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
553 v->loopfilter = get_bits(gb, 1); //common
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
554
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
555 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
556 if (v->profile <= PROFILE_MAIN)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
557 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
558 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
559 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
560 if (v->res_x8)
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 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
563 "1 for reserved RES_X8 is forbidden\n");
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
564 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
565 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
566 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
567 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
568 if (!v->res_fasttx)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
569 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
570 av_log(avctx, AV_LOG_ERROR,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
571 "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
572 //return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
573 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
574 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
575
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
576 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
577 if (!v->profile && !v->fastuvmc)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
578 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
579 av_log(avctx, AV_LOG_ERROR,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
580 "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
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 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
584 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
585 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
586 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
587 "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
588 return -1;
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->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
591 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
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 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
596 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
597 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
598 if (v->res_transtab)
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 "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
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
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
606 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
607
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
608 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
609 if (v->profile <= PROFILE_MAIN)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
610 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
611 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
612 v->syncmarker = get_bits(gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
613 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
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 avctx->max_b_frames = get_bits(gb, 3); //common
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
617 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
618
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
619 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
620 if (v->profile <= PROFILE_MAIN)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
621 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
622 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
623 v->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
624 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
625 if (!v->res_rtm_flag)
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 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
628 "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
629 //return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
630 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
631 #if TRACE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
632 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
633 "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
634 "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
635 "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
636 "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
637 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
638 v->loopfilter, v->multires, v->fastuvmc, v->extended_mv,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
639 v->rangered, v->vstransform, v->overlap, v->syncmarker,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
640 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
641 );
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
642 #endif
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 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
645 else decode_advanced_sequence_header(avctx, gb);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
646 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
647 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
648
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
649
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
650 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
651 /*****************************************************************************/
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
652 /* Entry point decoding (Advanced Profile) */
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 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
655 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
656 VC9Context *v = avctx->priv_data;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
657 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
658 if (v->profile != PROFILE_ADVANCED)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
659 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
660 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
661 "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
662 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
663 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
664 if (v->hrd_param_flag)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
665 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
666 //Update buffer fullness
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
667 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
668 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
669 skip_bits(gb, 8);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
670 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
671 if ((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
672 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
673 //RANGE_MAPY
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
674 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
675 skip_bits(gb, 3);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
676 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
677 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
678 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
679 //RANGE_MAPUV
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
680 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
681 skip_bits(gb, 3);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
682 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
683 if (v->panscanflag)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
684 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
685 //NUMPANSCANWIN
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
686 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
687 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
688 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
689 return 0;
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 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
692
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
693 /******************************************************************************/
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
694 /* Bitplane decoding */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
695 /******************************************************************************/
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
696 #define IMODE_RAW 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
697 #define IMODE_NORM2 1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
698 #define IMODE_DIFF2 2
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
699 #define IMODE_NORM6 3
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
700 #define IMODE_DIFF6 4
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
701 #define IMODE_ROWSKIP 5
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
702 #define IMODE_COLSKIP 6
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
703
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
704 //FIXME optimize
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
705 static int bitplane_decoding(uint8_t* plane, int width, int height, VC9Context *v)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
706 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
707 int imode, x, y, code;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
708 uint8_t invert, *planep = plane;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
709
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
710 invert = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
711 imode = get_vlc2(&v->gb, vc9_imode_vlc.table, VC9_IMODE_VLC_BITS, 2);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
712 av_log(v->avctx, AV_LOG_DEBUG, "Bitplane: imode=%i, invert=%i\n",
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
713 imode, invert);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
714
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
715 switch (imode)
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 case IMODE_RAW:
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
718 for (y=0; y<height; y++)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
719 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
720 for (x=0; x<width; x++)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
721 planep[x] = (-get_bits(&v->gb, 1)); //-1=0xFF
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
722 planep += width;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
723 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
724 break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
725 case IMODE_DIFF2:
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
726 case IMODE_NORM2:
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
727 if ((height*width) & 1) *(++planep) = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
728 code = get_vlc2(&v->gb, vc9_norm2_vlc.table, VC9_NORM2_VLC_BITS, 2);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
729 *(++planep) = code&1; //lsb => left
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
730 *(++planep) = code&2; //msb => right - this is a bitplane, so only !0 matters
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
731 break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
732 case IMODE_DIFF6:
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
733 case IMODE_NORM6:
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
734 av_log(v->avctx, AV_LOG_ERROR, "Imode using Norm-6 isn't supported\n");
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
735 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
736 break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
737 case IMODE_ROWSKIP:
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
738 for (y=0; y<height; y++)
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 (get_bits(&v->gb, 1)) //rowskip
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
741 memset(planep, 0, width);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
742 else for (x=0; x<width; x++) planep[x] = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
743 planep += width;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
744 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
745 break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
746 case IMODE_COLSKIP: //Teh ugly
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
747 for (x=0; x<width; x++)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
748 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
749 planep = plane;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
750 if (get_bits(&v->gb, 1)) //colskip
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 for (y=0; y<height; y++)
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 planep[x] = 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
755 planep += width;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
756 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
757 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
758 else
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 for (y=0; y<height; y++)
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 planep[x] = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
763 planep += width;
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 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
766 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
767 break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
768 default: break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
769 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
770
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
771 /* Applying diff operator */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
772 if (imode == IMODE_DIFF2 || imode == IMODE_DIFF2)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
773 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
774 /* And what about j=0 !? */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
775 planep = plane + width;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
776 memset(plane, invert, width);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
777 for (y=0; y<height; y++)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
778 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
779 planep[0] = planep[-width];
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
780 for (x=1; x<width; x++)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
781 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
782 if (planep[x-1] != planep[-width]) planep[x] = invert;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
783 else planep[x] = planep[x-1];
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
784 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
785 planep += width;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
786 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
787 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
788 else if (invert)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
789 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
790 planep = plane;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
791 for (x=0; x<width*height; x++) planep[x] = !planep[x];
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
792 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
793 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
794 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
795
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
796 /*****************************************************************************/
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
797 /* VOP Dquant decoding */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
798 /*****************************************************************************/
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
799 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
800 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
801 int pqdiff;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
802
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
803 //variable size
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
804 if (v->dquant == 2)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
805 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
806 pqdiff = get_bits(&v->gb, 3);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
807 if (pqdiff == 7) v->altpq = get_bits(&v->gb, 5);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
808 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
809 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
810 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
811 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
812 v->dquantfrm = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
813 if ( v->dquantfrm )
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
814 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
815 v->dqprofile = get_bits(&v->gb, 2);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
816 switch (v->dqprofile)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
817 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
818 case DQPROFILE_SINGLE_EDGE:
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
819 case DQPROFILE_DOUBLE_EDGES:
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
820 v->dqsbedge = get_bits(&v->gb, 2);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
821 break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
822 case DQPROFILE_ALL_MBS:
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
823 v->dqbilevel = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
824 default: break; //Forbidden ?
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
825 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
826 if (!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
827 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
828 pqdiff = get_bits(&v->gb, 3);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
829 if (pqdiff == 7) v->altpq = get_bits(&v->gb, 5);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
830 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
831 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
832 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
833 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
834 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
835 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
836
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
837 /*****************************************************************************/
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
838 /* 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
839 /* 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
840 /*****************************************************************************/
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
841 static int decode_bi_picture_header(VC9Context *v)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
842 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
843 /* Very particular case:
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
844 - for S/M Profiles, decode_b_picture_header reads BF,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
845 bfraction then determine if this is a BI frame, calling
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
846 this function afterwards
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
847 - for A Profile, PTYPE already tells so and we can go
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
848 directly there
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
849 */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
850 int pqindex;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
851
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
852 /* Read the quantization stuff */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
853 pqindex = get_bits(&v->gb, 5);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
854 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
855 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
856 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
857 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
858 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
859 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
860 if (pqindex < 9) v->halfpq = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
861 if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
862 v->pquantizer = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
863
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
864 /* Read the MV type/mode */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
865 if (v->extended_mv == 1)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
866 v->mvrange = get_prefix(&v->gb, 0, 3);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
867
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
868 /* FIXME: what table are used in that case ? */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
869 v->mv_diff_vlc = &vc9_mv_diff_vlc[0];
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
870 v->cbpcy_vlc = &vc9_cbpcy_i_vlc;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
871
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
872 av_log(v->avctx, AV_LOG_DEBUG, "B frame, QP=%i\n", v->pq);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
873 av_log(v->avctx, AV_LOG_ERROR, "BI_TYPE not supported yet\n");
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
874 /* Epilog should be done in caller */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
875 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
876 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
877
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
878 static int decode_b_picture_header(VC9Context *v)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
879 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
880 int pqindex;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
881
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
882 /* 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
883 if (v->profile == PROFILE_SIMPLE)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
884 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
885 av_log(v, AV_LOG_ERROR, "Found a B frame while in Simple Profile!\n");
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
886 return FRAME_SKIPED;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
887 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
888
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
889 v->bfraction = vc9_bfraction_lut[get_vlc2(&v->gb, vc9_bfraction_vlc.table,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
890 VC9_BFRACTION_VLC_BITS, 2)];
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
891 if (v->bfraction < -1)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
892 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
893 av_log(v, AV_LOG_ERROR, "Invalid BFRaction\n");
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
894 return FRAME_SKIPED;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
895 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
896 else if (!v->bfraction)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
897 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
898 /* We actually have a BI frame */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
899 return decode_bi_picture_header(v);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
900 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
901
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
902 /* Read the quantization stuff */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
903 pqindex = get_bits(&v->gb, 5);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
904 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
905 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
906 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
907 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
908 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
909 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
910 if (pqindex < 9) v->halfpq = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
911 if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
912 v->pquantizer = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
913
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
914 /* Read the MV type/mode */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
915 if (v->extended_mv == 1)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
916 v->mvrange = get_prefix(&v->gb, 0, 3);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
917 v->mv_mode = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
918 if (v->pq < 13)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
919 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
920 if (!v->mv_mode)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
921 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
922 v->mv_mode = get_bits(&v->gb, 2);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
923 if (v->mv_mode)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
924 av_log(v, AV_LOG_ERROR,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
925 "mv_mode for lowquant B frame was %i\n", v->mv_mode);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
926 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
927 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
928 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
929 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
930 if (!v->mv_mode)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
931 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
932 if (get_bits(&v->gb, 1))
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
933 av_log(v, AV_LOG_ERROR,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
934 "mv_mode for highquant B frame was %i\n", v->mv_mode);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
935 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
936 v->mv_mode = 1-v->mv_mode; //To match (pq < 13) mapping
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
937 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
938
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
939 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
940 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
941 if (bitplane_decoding( v->mv_type_mb_plane, v->width_mb,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
942 v->height_mb, v)<0)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
943 return -1;
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 //bitplane
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
947 bitplane_decoding(v->direct_mb_plane, v->width_mb, v->height_mb, v);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
948 bitplane_decoding(v->skip_mb_plane, v->width_mb, v->height_mb, v);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
949
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
950 /* FIXME: what is actually chosen for B frames ? */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
951 v->mv_diff_vlc = &vc9_mv_diff_vlc[get_bits(&v->gb, 2)];
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
952 v->cbpcy_vlc = &vc9_cbpcy_p_vlc[get_bits(&v->gb, 2)];
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
953 if (v->dquant)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
954 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
955 vop_dquant_decoding(v);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
956 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
957
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
958 if (v->vstransform)
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 v->ttmbf = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
961 if (v->ttmbf)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
962 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
963 v->ttfrm = get_bits(&v->gb, 2);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
964 av_log(v, AV_LOG_INFO, "Transform used: %ix%i\n",
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
965 (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
966 }
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 /* Epilog should be done in caller */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
969 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
970 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
971
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
972 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
973 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
974 int pqindex, status = 0, ac_pred, condover;
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 /* 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
977 //BF = Buffer Fullness
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
978 if (v->profile <= PROFILE_MAIN && get_bits(&v->gb, 7))
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
979 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
980 av_log(v, AV_LOG_DEBUG, "I BufferFullness not 0\n");
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
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 /* Quantizer stuff */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
984 pqindex = get_bits(&v->gb, 5);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
985 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
986 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
987 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
988 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
989 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
990 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
991 if (pqindex < 9) v->halfpq = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
992 if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
993 v->pquantizer = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
994 av_log(v->avctx, AV_LOG_DEBUG, "I frame: QP=%i (+%i/2)\n",
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
995 v->pq, v->halfpq);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
996 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
997 if (v->profile <= PROFILE_MAIN)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
998 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
999 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1000 if (v->extended_mv) v->mvrange = get_prefix(&v->gb, 0, 3);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1001 if (v->multires) v->respic = get_bits(&v->gb, 2);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1002 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1003 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1004 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1005 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1006 ac_pred = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1007 if (v->postprocflag) v->postproc = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1008 /* 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
1009 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
1010 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1011 condover = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1012 if (condover)
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 condover = 2+get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1015 if (condover == 3)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1016 status = bitplane_decoding(v->over_flags_plane,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1017 v->width_mb, v->height_mb, v);
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 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1020 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1021 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1022
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1023 /* Epilog should be done in caller */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1024 return status;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1025 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1026
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1027 static int decode_p_picture_header(VC9Context *v)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1028 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1029 /* INTERFRM, FRMCNT, RANGEREDFRM read in caller */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1030 int lowquant, pqindex;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1031
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1032 pqindex = get_bits(&v->gb, 5);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1033 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
1034 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
1035 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1036 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1037 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
1038 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1039 if (pqindex < 9) v->halfpq = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1040 if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1041 v->pquantizer = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1042 av_log(v->avctx, AV_LOG_DEBUG, "P Frame: QP=%i (+%i/2)\n",
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1043 v->pq, v->halfpq);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1044 if (v->extended_mv == 1) v->mvrange = get_prefix(&v->gb, 0, 3);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1045 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1046 if (v->profile > PROFILE_MAIN)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1047 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1048 if (v->postprocflag) v->postproc = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1049 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1050 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1051 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1052 if (v->multires) v->respic = get_bits(&v->gb, 2);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1053 lowquant = (v->pquantizer>12) ? 0 : 1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1054 v->mv_mode = mv_pmode_table[lowquant][get_prefix(&v->gb, 1, 4)];
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1055 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
1056 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1057 v->mv_mode2 = mv_pmode_table[lowquant][get_prefix(&v->gb, 1, 3)];
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1058 v->lumscale = get_bits(&v->gb, 6);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1059 v->lumshift = get_bits(&v->gb, 6);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1060 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1061
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1062 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
1063 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
1064 || 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
1065 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1066 if (bitplane_decoding(v->mv_type_mb_plane, v->width_mb,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1067 v->height_mb, v) < 0)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1068 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1069 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1070
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1071 if (bitplane_decoding(v->skip_mb_plane, v->width_mb,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1072 v->height_mb, v) < 0)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1073 return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1074
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1075 /* Hopefully this is correct for P frames */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1076 v->mv_diff_vlc = &vc9_mv_diff_vlc[get_bits(&v->gb, 2)];
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1077 v->cbpcy_vlc = &vc9_cbpcy_p_vlc[get_bits(&v->gb, 2)];
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1078
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1079 if (v->dquant)
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 av_log(v->avctx, AV_LOG_INFO, "VOP DQuant info\n");
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1082 vop_dquant_decoding(v);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1083 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1084
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1085 if (v->vstransform)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1086 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1087 v->ttmbf = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1088 if (v->ttmbf)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1089 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1090 v->ttfrm = get_bits(&v->gb, 2);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1091 av_log(v->avctx, AV_LOG_INFO, "Transform used: %ix%i\n",
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1092 (v->ttfrm & 2) ? 4 : 8, (v->ttfrm & 1) ? 4 : 8);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1093 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1094 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1095 /* Epilog should be done in caller */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1096 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1097 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1098
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1099
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1100 static int standard_decode_picture_header(VC9Context *v)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1101 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1102 int status = 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1103
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1104 if (v->finterpflag) v->interpfrm = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1105 skip_bits(&v->gb, 2); //framecnt unused
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1106 if (v->rangered) v->rangeredfrm = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1107 v->pict_type = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1108 if (v->avctx->max_b_frames && !v->pict_type)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1109 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1110 if (get_bits(&v->gb, 1)) v->pict_type = I_TYPE;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1111 else v->pict_type = P_TYPE;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1112 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1113 else v->pict_type++; //P_TYPE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1114
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1115 switch (v->pict_type)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1116 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1117 case I_TYPE: status = decode_i_picture_header(v); break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1118 case BI_TYPE: status = decode_b_picture_header(v); break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1119 case P_TYPE: status = decode_p_picture_header(v); break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1120 case B_TYPE: status = decode_b_picture_header(v); break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1121 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1122
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1123 if (status == FRAME_SKIPED)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1124 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1125 av_log(v, AV_LOG_INFO, "Skipping frame...\n");
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1126 return status;
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 /* AC/DC Syntax */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1130 v->transacfrm = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1131 if (v->transacfrm) v->transacfrm += get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1132 if (v->pict_type == I_TYPE || v->pict_type == BI_TYPE)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1133 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1134 v->transacfrm2 = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1135 if (v->transacfrm2) v->transacfrm2 += get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1136 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1137 v->transacdctab = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1138
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1139 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1140 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1141
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1142
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1143 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1144 /******************************************************************************/
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1145 /* 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
1146 /******************************************************************************/
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1147 static int advanced_decode_picture_header(VC9Context *v)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1148 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1149 static const int type_table[4] = { P_TYPE, B_TYPE, I_TYPE, BI_TYPE };
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1150 int type, i, ret;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1151
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1152 if (v->interlace)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1153 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1154 v->fcm = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1155 if (v->fcm) v->fcm = 2+get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1156 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1157
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1158 type = get_prefix(&v->gb, 0, 4);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1159 if (type > 4 || type < 0) return FRAME_SKIPED;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1160 v->pict_type = type_table[type];
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1161 av_log(v->avctx, AV_LOG_INFO, "AP Frame Type: %i\n", v->pict_type);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1162
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1163 if (v->tfcntrflag) v->tfcntr = get_bits(&v->gb, 8);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1164 if (v->broadcast)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1165 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1166 if (!v->interlace) v->rptfrm = get_bits(&v->gb, 2);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1167 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1168 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1169 v->tff = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1170 v->rff = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
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
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1174 if (v->panscanflag)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1175 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1176 #if 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1177 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
1178 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1179 v->topleftx[i] = get_bits(&v->gb, 16);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1180 v->toplefty[i] = get_bits(&v->gb, 16);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1181 v->bottomrightx[i] = get_bits(&v->gb, 16);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1182 v->bottomrighty[i] = get_bits(&v->gb, 16);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1183 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1184 #else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1185 skip_bits(&v->gb, 16*4*v->numpanscanwin);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1186 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1187 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1188 v->rndctrl = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1189 v->uvsamp = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1190 if (v->finterpflag == 1) v->interpfrm = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1191
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1192 switch(v->pict_type)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1193 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1194 case I_TYPE: if (decode_i_picture_header(v) < 0) return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1195 case P_TYPE: if (decode_p_picture_header(v) < 0) return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1196 case BI_TYPE:
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1197 case B_TYPE: if (decode_b_picture_header(v) < 0) return FRAME_SKIPED;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1198 default: break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1199 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1200
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1201 /* AC/DC Syntax */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1202 v->transacfrm = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1203 if (v->transacfrm) v->transacfrm += get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1204 if (v->pict_type == I_TYPE || v->pict_type == BI_TYPE)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1205 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1206 v->transacfrm2 = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1207 if (v->transacfrm2) v->transacfrm2 += get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1208 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1209 v->transacdctab = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1210 if (v->pict_type == I_TYPE) vop_dquant_decoding(v);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1211
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1212 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1213 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1214 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1215
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1216 /******************************************************************************/
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1217 /* MacroBlock decoding functions */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1218 /******************************************************************************/
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1219 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
1220 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1221 int x, y, ac_pred, cbpcy;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1222
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1223 /* 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
1224 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
1225 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
1226 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
1227
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1228 for (y=0; y<v->height_mb; y++)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1229 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1230 for (x=0; x<v->width_mb; x++)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1231 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1232 cbpcy = get_vlc2(&v->gb, vc9_cbpcy_i_vlc.table,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1233 VC9_CBPCY_I_VLC_BITS, 2);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1234 ac_pred = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1235 //Decode blocks from that mb wrt cbpcy
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1236 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1237 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1238 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1239 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1240
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1241 #define GET_MQUANT() \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1242 if (v->dquantfrm) \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1243 { \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1244 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
1245 { \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1246 if (v->dqbilevel) \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1247 { \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1248 mquant = (get_bits(&v->gb, 1)) ? v->pq : v->altpq; \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1249 } \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1250 else \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1251 { \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1252 mqdiff = get_bits(&v->gb, 3); \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1253 if (mqdiff != 7) mquant = v->pq + mqdiff; \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1254 else mquant = get_bits(&v->gb, 5); \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1255 } \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1256 } \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1257 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1258
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1259 /* MVDATA decoding from 8.3.5.2 */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1260 #define GET_MVDATA() \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1261 index = 1 + get_vlc2(&v->gb, v->mv_diff_vlc->table, \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1262 VC9_MV_DIFF_VLC_BITS, 2); \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1263 if (index > 36) \
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 mb_has_coeffs = 1; \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1266 index -= 37; \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1267 } \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1268 else mb_has_coeffs = 0; \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1269 mb_is_intra = 0; \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1270 if (!index) { dmv_x = dmv_y = 0; } \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1271 else if (index == 35) \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1272 { \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1273 dmv_x = get_bits(&v->gb, k_x); \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1274 dmv_y = get_bits(&v->gb, k_y); \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1275 mb_is_intra = 1; \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1276 } \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1277 else \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1278 { \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1279 index1 = index%6; \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1280 if (hpel_flag && index1 == 5) val = 1; \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1281 else val = 0; \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1282 val = get_bits(&v->gb, size_table[index1] - val); \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1283 sign = 0 - (val&1); \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1284 dmv_x = (sign ^ ((val>>1) + offset_table[index1])) - sign; \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1285 \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1286 index1 = index/6; \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1287 if (hpel_flag && index1 == 5) val = 1; \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1288 else val = 0; \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1289 val = get_bits(&v->gb, size_table[index1] - val); \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1290 sign = 0 - (val&1); \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1291 dmv_y = (sign ^ ((val>>1) + offset_table[index1])) - sign; \
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1292 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1293
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1294 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
1295 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1296 int x, y, current_mb = 0, i; /* MB/Block Position info */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1297 int skip_mb_bit = 0, cbpcy; /* MB/B skip */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1298 int hybrid_pred, ac_pred; /* Prediction types */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1299 int mb_has_coeffs = 1 /* last_flag */, mb_is_intra;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1300 int dmv_x, dmv_y; /* Differential MV components */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1301 int mv_mode_bit = 0; /* mv_mode_bit: 1MV=0, 4MV=0 */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1302 int mqdiff, mquant; /* MB quantization */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1303 int tt_block; /* MB Transform type */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1304 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
1305 offset_table[6] = { 0, 1, 3, 7, 15, 31 };
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1306 int k_x, k_y; /* Long MV fixed bitlength */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1307 int hpel_flag, intra_flag; /* Some MB properties */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1308 int index, index1; /* LUT indices */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1309 int val, sign;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1310
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1311 /* 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
1312 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
1313 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
1314 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
1315
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1316 /* Select proper long MV range */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1317 switch (v->mvrange)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1318 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1319 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
1320 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
1321 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
1322 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
1323 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1324
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1325 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
1326 k_x -= hpel_flag;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1327 k_y -= hpel_flag;
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 for (y=0; y<v->height_mb; y++)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1330 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1331 for (x=0; x<v->width_mb; x++)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1332 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1333 if (v->mv_type_mb_plane[current_mb])
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1334 mv_mode_bit = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1335 if (0) //skipmb is rawmode
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1336 skip_mb_bit = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1337 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
1338 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1339 if (!v->skip_mb_plane[current_mb])
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 GET_MVDATA();
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1342
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1343 /* 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
1344 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
1345 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
1346 hybrid_pred = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1347 if (mb_is_intra && !mb_has_coeffs)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1348 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1349 GET_MQUANT();
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1350 ac_pred = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1351 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1352 else if (mb_has_coeffs)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1353 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1354 if (mb_is_intra) ac_pred = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1355 cbpcy = get_vlc2(&v->gb, v->cbpcy_vlc->table,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1356 VC9_CBPCY_P_VLC_BITS, 2);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1357 GET_MQUANT();
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1358 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1359 if (!v->ttmbf)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1360 v->ttfrm = get_vlc2(&v->gb, v->ttmb_vlc->table,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1361 VC9_TTMB_VLC_BITS, 12);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1362 //Decode blocks from that mb wrt cbpcy
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1363 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1364 else //Skipped
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1365 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1366 /* 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
1367 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
1368 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
1369 hybrid_pred = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1370 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1371 } //1MV mode
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1372 else //4MV mode
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1373 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1374 if (!v->skip_mb_plane[current_mb] /* unskipped MB */)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1375 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1376 cbpcy = get_vlc2(&v->gb, v->cbpcy_vlc->table,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1377 VC9_CBPCY_P_VLC_BITS, 2);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1378 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
1379 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1380 if (cbpcy & (1<<6) /* cbpcy set for this block */)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1381 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1382 GET_MVDATA();
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1383 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1384 if (v->mv_mode == MV_PMODE_MIXED_MV /* Hybrid pred */)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1385 hybrid_pred = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1386 GET_MQUANT();
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1387 if (mb_is_intra /* One of the 4 blocks is intra */ &&
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1388 index /* non-zero pred for that block */)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1389 ac_pred = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1390 if (!v->ttmbf)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1391 tt_block = get_vlc2(&v->gb, v->ttmb_vlc->table,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1392 VC9_TTMB_VLC_BITS, 12);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1393
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1394 /* TODO: Process blocks wrt cbpcy */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1395
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1396 /* Prepare cbpcy for next block */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1397 cbpcy <<= 1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1398 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1399 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1400 else //Skipped MB
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1401 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1402 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
1403 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1404 if (v->mv_mode == MV_PMODE_MIXED_MV /* Hybrid pred */)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1405 hybrid_pred = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1406
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1407 /* FIXME: do something */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1408 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1409 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1410 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1411 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1412 current_mb++;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1413 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1414 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1415 }
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 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
1418 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1419 int x, y, current_mb = 0 , last_mb = v->height_mb*v->width_mb,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1420 i /* MB / B postion information */;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1421 int direct_b_bit = 0, skip_mb_bit = 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1422 int ac_pred;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1423 int b_mv1 = 0, b_mv2 = 0, b_mv_type = 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1424 int mquant, mqdiff; /* MB quant stuff */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1425 int tt_block; /* Block transform type */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1426
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1427 for (y=0; y<v->height_mb; y++)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1428 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1429 for (x=0; x<v->width_mb; x++)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1430 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1431 if (v->direct_mb_plane[current_mb])
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1432 direct_b_bit = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1433 if (1 /* Skip mode is raw */)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1434 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1435 /* FIXME getting tired commenting */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1436 #if 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1437 skip_mb_bit = get_bits(&v->gb, n); //vlc
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1438 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1439 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1440 if (!direct_b_bit)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1441 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1442 if (skip_mb_bit)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1443 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1444 /* FIXME getting tired commenting */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1445 #if 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1446 b_mv_type = get_bits(&v->gb, n); //vlc
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1447 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1448 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1449 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1450 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1451 /* FIXME getting tired commenting */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1452 #if 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1453 b_mv1 = get_bits(&v->gb, n); //VLC
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1454 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1455 if (1 /* b_mv1 isn't intra */)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1456 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1457 /* FIXME: actually read it */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1458 b_mv_type = 0; //vlc
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1459 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1460 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1461 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1462 if (!skip_mb_bit)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1463 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1464 if (b_mv1 != last_mb)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1465 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1466 GET_MQUANT();
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1467 if (1 /* intra mb */)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1468 ac_pred = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1469 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1470 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1471 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1472 if (1 /* forward_mb is interpolate */)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1473 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1474 /* FIXME: actually read it */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1475 b_mv2 = 0; //vlc
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1476 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1477 if (1 /* b_mv2 isn't the last */)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1478 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1479 if (1 /* intra_mb */)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1480 ac_pred = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1481 GET_MQUANT();
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1482 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1483 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1484 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1485 //End1
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1486 /* FIXME getting tired, commenting */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1487 #if 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1488 if (v->ttmbf)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1489 v->ttmb = get_bits(&v->gb, n); //vlc
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1490 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1491 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1492 //End2
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1493 for (i=0; i<6; i++)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1494 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1495 /* FIXME: process the block */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1496 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1497
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1498 current_mb++;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1499 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1500 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1501 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1502
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1503 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1504 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
1505 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1506 int i, x, y, cbpcy, mqdiff, absmq, mquant, ac_pred, condover,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1507 current_mb = 0, over_flags_mb = 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1508
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1509 for (y=0; y<v->height_mb; y++)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1510 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1511 for (x=0; x<v->width_mb; x++)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1512 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1513 if (v->ac_pred_plane[i])
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1514 ac_pred = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1515 if (condover == 3 && v->over_flags_plane)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1516 over_flags_mb = get_bits(&v->gb, 1);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1517 GET_MQUANT();
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1518 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1519 current_mb++;
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 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1524
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1525 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
1526 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1527 VC9Context *v = avctx->priv_data;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1528 GetBitContext gb;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1529
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1530 if (!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
1531 avctx->pix_fmt = PIX_FMT_YUV420P;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1532 v->avctx = avctx;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1533
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1534 if (init_common(v) < 0) return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1535
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1536 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
1537 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1538 int count = 0;
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 // looks like WMV3 has a sequence header stored in the extradata
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1541 // advanced sequence header may be before the first frame
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1542 // the last byte of the extradata is a version number, 1 for the
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1543 // samples we can decode
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1544
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1545 init_get_bits(&gb, avctx->extradata, avctx->extradata_size);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1546
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1547 decode_sequence_header(avctx, &gb);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1548
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1549 count = avctx->extradata_size*8 - get_bits_count(&gb);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1550 if (count>0)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1551 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1552 av_log(avctx, AV_LOG_INFO, "Extra data: %i bits left, value: %X\n",
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1553 count, get_bits(&gb, count));
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1554 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1555 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1556 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1557 av_log(avctx, AV_LOG_INFO, "Read %i bits in overflow\n", -count);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1558 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1559 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1560
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1561 /* Done with header parsing */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1562 //FIXME I feel like this is wrong
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1563 v->width_mb = (avctx->coded_width+15)>>4;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1564 v->height_mb = (avctx->coded_height+15)>>4;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1565
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1566 /* Allocate mb bitplanes */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1567 v->mv_type_mb_plane = (uint8_t *)av_malloc(v->width_mb*v->height_mb);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1568 if (!v->mv_type_mb_plane) return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1569 v->skip_mb_plane = (uint8_t *)av_malloc(v->width_mb*v->height_mb);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1570 if (!v->skip_mb_plane) return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1571 v->direct_mb_plane = (uint8_t *)av_malloc(v->width_mb*v->height_mb);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1572 if (!v->direct_mb_plane) return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1573
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1574 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1575 if (v->profile > PROFILE_MAIN)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1576 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1577 v->over_flags_plane = (uint8_t *)av_malloc(v->width_mb*v->height_mb);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1578 if (!v->over_flags_plane) return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1579 v->ac_pred_plane = (uint8_t *)av_malloc(v->width_mb*v->height_mb);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1580 if (!v->ac_pred_plane) return -1;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1581 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1582 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1583
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1584 return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1585 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1586
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1587 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
1588 void *data, int *data_size,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1589 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
1590 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1591 VC9Context *v = avctx->priv_data;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1592 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
1593 AVFrame *pict = data;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1594 uint8_t *tmp_buf;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1595 v->avctx = avctx;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1596
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1597 //buf_size = 0 -> last frame
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1598 if (!buf_size) return 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1599
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1600 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
1601 avctx->height);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1602 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
1603 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
1604 avctx->width, avctx->height);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1605
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1606 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
1607 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1608 init_get_bits(&v->gb, buf, buf_size*8);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1609 av_log(avctx, AV_LOG_INFO, "Frame: %i bits to decode\n", buf_size*8);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1610
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1611 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1612 if (v->profile > PROFILE_MAIN)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1613 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1614 if (advanced_decode_picture_header(v) == FRAME_SKIPED) return buf_size;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1615 switch(v->pict_type)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1616 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1617 case I_TYPE: ret = advanced_decode_i_mbs(v); break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1618 case P_TYPE: ret = decode_p_mbs(v); break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1619 case B_TYPE:
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1620 case BI_TYPE: ret = decode_b_mbs(v); break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1621 default: ret = FRAME_SKIPED;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1622 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1623 if (ret == FRAME_SKIPED) return buf_size; //We ignore for now failures
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1624 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1625 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1626 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1627 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1628 if (standard_decode_picture_header(v) == FRAME_SKIPED) return buf_size;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1629 switch(v->pict_type)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1630 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1631 case I_TYPE: ret = standard_decode_i_mbs(v); break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1632 case P_TYPE: ret = decode_p_mbs(v); break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1633 case B_TYPE:
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1634 case BI_TYPE: ret = decode_b_mbs(v); break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1635 default: ret = FRAME_SKIPED;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1636 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1637 if (ret == FRAME_SKIPED) return buf_size;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1638 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1639
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1640 /* Size of the output data = image */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1641 av_log(avctx, AV_LOG_DEBUG, "Consumed %i/%i bits\n",
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1642 get_bits_count(&v->gb), buf_size*8);
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 else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1645 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1646 #if 0
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1647 // search for IDU's
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1648 // FIXME
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1649 uint32_t scp = 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1650 int scs = 0, i = 0;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1651
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1652 while (i < buf_size)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1653 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1654 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
1655 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
1656
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1657 if (scp != 0x000001)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1658 break; // eof ?
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1659
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1660 scs = buf[i++];
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1661
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1662 init_get_bits(&v->gb, buf+i, (buf_size-i)*8);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1663
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1664 switch(scs)
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1665 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1666 case 0xf:
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1667 decode_sequence_header(avctx, &v->gb);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1668 break;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1669 // to be finished
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1670 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1671
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1672 i += get_bits_count(&v->gb)*8;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1673 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1674 #else
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1675 av_abort();
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1676 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1677 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1678
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1679 *data_size = len;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1680
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1681 /* Fake consumption of all data */
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1682 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
1683 }
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1684
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1685 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
1686 {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1687 VC9Context *v = avctx->priv_data;
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1688
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1689 #if HAS_ADVANCED_PROFILE
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1690 if (v->hrd_rate) av_free(v->hrd_rate);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1691 if (v->hrd_buffer) av_free(v->hrd_buffer);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1692 #endif
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1693 if (v->mv_type_mb_plane) av_free(v->mv_type_mb_plane);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1694 if (v->skip_mb_plane) av_free(v->skip_mb_plane);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1695 if (v->direct_mb_plane) av_free(v->direct_mb_plane);
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1696 return 0;
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
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1699 AVCodec vc9_decoder = {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1700 "vc9",
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1701 CODEC_TYPE_VIDEO,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1702 CODEC_ID_VC9,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1703 sizeof(VC9Context),
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1704 vc9_decode_init,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1705 NULL,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1706 vc9_decode_end,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1707 vc9_decode_frame,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1708 0,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1709 NULL
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 AVCodec wmv3_decoder = {
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1713 "wmv3",
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1714 CODEC_TYPE_VIDEO,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1715 CODEC_ID_WMV3,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1716 sizeof(VC9Context),
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1717 vc9_decode_init,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1718 NULL,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1719 vc9_decode_end,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1720 vc9_decode_frame,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1721 0,
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1722 NULL
96da66323faa preliminary vc9 bitstream decoder, committing to make syncing and team-work on it easier
alex
parents:
diff changeset
1723 };