annotate vc1.c @ 3359:87187ebe2c28 libavcodec

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