1 |
2 |
kdv |
/*
|
2 |
|
|
* motcomp_motvec.v
|
3 |
|
|
*
|
4 |
|
|
* Copyright (c) 2007 Koen De Vleeschauwer.
|
5 |
|
|
*
|
6 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
7 |
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
8 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
9 |
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
10 |
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
11 |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
12 |
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
13 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
14 |
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
15 |
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
16 |
|
|
* SUCH DAMAGE.
|
17 |
|
|
*/
|
18 |
|
|
|
19 |
|
|
/*
|
20 |
|
|
* motcomp_motvec - Motion compensation: motion vector selection
|
21 |
|
|
*/
|
22 |
|
|
|
23 |
|
|
`include "timescale.v"
|
24 |
|
|
|
25 |
|
|
`undef DEBUG
|
26 |
|
|
//`define DEBUG 1
|
27 |
|
|
|
28 |
|
|
module motcomp_motvec (
|
29 |
|
|
clk, clk_en, rst,
|
30 |
|
|
picture_coding_type, picture_structure, motion_type, dct_type,
|
31 |
|
|
macroblock_motion_forward, macroblock_motion_backward, macroblock_intra, column, row, block, comp, macroblock_address_in, motvec_update,
|
32 |
|
|
pmv_0_0_0, pmv_0_0_1, pmv_1_0_0, pmv_1_0_1, pmv_0_1_0, pmv_0_1_1, pmv_1_1_0, pmv_1_1_1,
|
33 |
|
|
dmv_0_0, dmv_0_1, dmv_1_0, dmv_1_1,
|
34 |
|
|
motion_vert_field_select_0_0, motion_vert_field_select_0_1, motion_vert_field_select_1_0, motion_vert_field_select_1_1,
|
35 |
|
|
second_field,
|
36 |
|
|
forward_reference_frame, backward_reference_frame, current_frame,
|
37 |
|
|
frame_picture, field_in_frame, comp_out, macroblock_address_out,
|
38 |
|
|
delta_x, delta_y,
|
39 |
|
|
fwd_src_frame, fwd_src_field, fwd_mv_x, fwd_mv_y, fwd_valid,
|
40 |
|
|
bwd_src_frame, bwd_src_field, bwd_mv_x, bwd_mv_y, bwd_valid,
|
41 |
|
|
recon_dst_frame, recon_dst_field, recon_delta_x, recon_delta_y, recon_valid,
|
42 |
|
|
write_recon,
|
43 |
|
|
dct_block_cmd, dct_block_en
|
44 |
|
|
);
|
45 |
|
|
|
46 |
|
|
input clk; // clock
|
47 |
|
|
input clk_en; // clock enable
|
48 |
|
|
input rst; // synchronous active low reset
|
49 |
|
|
|
50 |
|
|
input [2:0]picture_coding_type; // identifies whether a picture is an I, P or B picture.
|
51 |
|
|
input [1:0]picture_structure; // one of FRAME_PICTURE, TOP_FIELD or BOTTOM_FIELD
|
52 |
|
|
input [1:0]motion_type; // one of MC_FIELD, MC_FRAME, MC_16X8 or MC_DMV
|
53 |
|
|
input dct_type; // either DCT_FIELD or DCT_FRAME
|
54 |
|
|
input macroblock_motion_forward;
|
55 |
|
|
input macroblock_motion_backward;
|
56 |
|
|
input macroblock_intra;
|
57 |
|
|
input column;
|
58 |
|
|
input signed [3:0]row;
|
59 |
|
|
input [1:0]block; // number of block, 0..3.
|
60 |
|
|
input [1:0]comp;
|
61 |
|
|
input [12:0]macroblock_address_in;
|
62 |
|
|
input motvec_update; // asserted when pmv_x_x_x, dmv_x_x valid
|
63 |
|
|
input motion_vert_field_select_0_0; // motion_vertical_field_select. Indicates which reference field shall be used to form the prediction.
|
64 |
|
|
// If motion_vertical_field_select[r][s] is zero, then the top reference field shall be used,
|
65 |
|
|
// if it is one then the bottom reference field shall be used.
|
66 |
|
|
input motion_vert_field_select_0_1;
|
67 |
|
|
input motion_vert_field_select_1_0;
|
68 |
|
|
input motion_vert_field_select_1_1;
|
69 |
|
|
input second_field;
|
70 |
|
|
input [2:0]forward_reference_frame; /* forward reference frame. Has value 3'd0 or 3'd1 */
|
71 |
|
|
input [2:0]backward_reference_frame; /* backward reference frame. Has value 3'd0 or 3'd1 */
|
72 |
|
|
input [2:0]current_frame; /* current frame. */
|
73 |
|
|
input signed [12:0]pmv_0_0_0; // predicted motion vector
|
74 |
|
|
input signed [12:0]pmv_0_0_1; // predicted motion vector
|
75 |
|
|
input signed [12:0]pmv_1_0_0; // predicted motion vector
|
76 |
|
|
input signed [12:0]pmv_1_0_1; // predicted motion vector
|
77 |
|
|
input signed [12:0]pmv_0_1_0; // predicted motion vector
|
78 |
|
|
input signed [12:0]pmv_0_1_1; // predicted motion vector
|
79 |
|
|
input signed [12:0]pmv_1_1_0; // predicted motion vector
|
80 |
|
|
input signed [12:0]pmv_1_1_1; // predicted motion vector
|
81 |
|
|
input signed [12:0]dmv_0_0; // dual-prime motion vector.
|
82 |
|
|
input signed [12:0]dmv_0_1; // dual-prime motion vector.
|
83 |
|
|
input signed [12:0]dmv_1_0; // dual-prime motion vector.
|
84 |
|
|
input signed [12:0]dmv_1_1; // dual-prime motion vector.
|
85 |
|
|
|
86 |
|
|
`include "mem_codes.v"
|
87 |
|
|
`include "vld_codes.v"
|
88 |
|
|
`include "motcomp_dctcodes.v"
|
89 |
|
|
|
90 |
|
|
/*
|
91 |
|
|
frame_picture and field_in_frame determine whether to treat the picture as a progressive frame picture, an interlaced frame picture or a field picture.
|
92 |
|
|
If frame_picture == 1 and field_in_frame == 0 picture is a progressive frame picture.
|
93 |
|
|
If frame_picture == 1 and field_in_frame == 1 picture is an interlaced frame picture, and fwd_src_field, bwd_src_field or recon_dst_field determine which of the two fields to use.
|
94 |
|
|
If frame_picture == 0 picture is an field picture, and fwd_src_field, bwd_src_field or recon_dst_field determine which of the two fields to use.
|
95 |
|
|
*/
|
96 |
|
|
|
97 |
|
|
output reg frame_picture;
|
98 |
|
|
output reg field_in_frame;
|
99 |
|
|
output reg [1:0]comp_out; /* Component. One of COMP_Y, COMP_CR, COMP_CB */
|
100 |
|
|
output reg [12:0]macroblock_address_out; /* macroblock address, 0... */
|
101 |
|
|
output reg signed [12:0]delta_x; /* horizontal offset, positive, in pixels, applied to forward and backward motion compensation */
|
102 |
|
|
output reg signed [12:0]delta_y; /* vertical offset, positive, in pixels, applied to forward and backward motion compensation */
|
103 |
|
|
output reg [2:0]fwd_src_frame; /* forward source frame */
|
104 |
|
|
output reg fwd_src_field; /* forward source field */
|
105 |
|
|
output reg signed [12:0]fwd_mv_x; /* forward motion vector, horizontal component, signed, in halfpixels */
|
106 |
|
|
output reg signed [12:0]fwd_mv_y; /* forward motion vector, horizontal component, signed, in halfpixels */
|
107 |
|
|
output reg fwd_valid; /* assert to enable forward motion compensation */
|
108 |
|
|
output reg [2:0]bwd_src_frame; /* backward source frame */
|
109 |
|
|
output reg bwd_src_field; /* backward source field */
|
110 |
|
|
output reg signed [12:0]bwd_mv_x; /* backward motion vector, horizontal component, signed, in halfpixels */
|
111 |
|
|
output reg signed [12:0]bwd_mv_y; /* backward motion vector, horizontal component, signed, in halfpixels */
|
112 |
|
|
output reg bwd_valid; /* assert to enable backward motion compensation */
|
113 |
|
|
output reg [2:0]recon_dst_frame; /* reconstruction destination frame */
|
114 |
|
|
output reg recon_dst_field; /* reconstruction destination field */
|
115 |
|
|
output reg signed [12:0]recon_delta_x; /* horizontal offset, positive, in pixels, applied to reconstruction */
|
116 |
|
|
output reg signed [12:0]recon_delta_y; /* vertical offset, positive, in pixels, applied to reconstruction */
|
117 |
|
|
output reg write_recon; /* write_recon == 0 causes recon to just load the row but not to write any reconstructed pixels to memory.
|
118 |
|
|
write_recon == 1 causes recon not only to load the row, but also to write the reconstructed pixels to memory.
|
119 |
|
|
Typically write_recon == 0 in row 0 (load), write_recon == 1 in row 1..8 (reconstruct)
|
120 |
|
|
*/
|
121 |
|
|
output reg recon_valid; /* assert to enable motion compensation reconstruction */
|
122 |
|
|
output reg [2:0]dct_block_cmd; /* dct frame/field coding translation command. Issued when dct_block_en is asserted. See ISO/IEC 13818-2, par. 6.1.3, fig. 6-13 and 6-14. */
|
123 |
|
|
output reg dct_block_en; /* dct frame/field coding translation enable. Asserted once per block. See ISO/IEC 13818-2, par. 6.1.3, fig. 6-13 and 6-14. */
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
reg next_frame_picture;
|
127 |
|
|
reg next_field_in_frame;
|
128 |
|
|
reg [1:0]next_comp_out;
|
129 |
|
|
reg [12:0]next_macroblock_address_out;
|
130 |
|
|
reg signed [12:0]next_delta_x;
|
131 |
|
|
reg signed [12:0]next_delta_y;
|
132 |
|
|
reg [2:0]next_fwd_src_frame;
|
133 |
|
|
reg next_fwd_src_field;
|
134 |
|
|
reg signed [12:0]next_fwd_mv_x;
|
135 |
|
|
reg signed [12:0]next_fwd_mv_y;
|
136 |
|
|
reg next_fwd_valid;
|
137 |
|
|
reg [2:0]next_bwd_src_frame;
|
138 |
|
|
reg next_bwd_src_field;
|
139 |
|
|
reg signed [12:0]next_bwd_mv_x;
|
140 |
|
|
reg signed [12:0]next_bwd_mv_y;
|
141 |
|
|
reg next_bwd_valid;
|
142 |
|
|
reg [2:0]next_recon_dst_frame;
|
143 |
|
|
reg next_recon_dst_field;
|
144 |
|
|
reg signed [12:0]next_recon_delta_x;
|
145 |
|
|
reg signed [12:0]next_recon_delta_y;
|
146 |
|
|
reg next_write_recon;
|
147 |
|
|
reg next_recon_valid;
|
148 |
|
|
reg [2:0]next_dct_block_cmd;
|
149 |
|
|
reg next_dct_block_en;
|
150 |
|
|
|
151 |
|
|
`ifdef DEBUG
|
152 |
|
|
reg [63:0]mc_descript;
|
153 |
|
|
reg [63:0]next_mc_descript;
|
154 |
|
|
`endif
|
155 |
|
|
|
156 |
|
|
/* Table 7-13 and 7-14. Determine motion vectors, source and destination field and frame to use. */
|
157 |
|
|
|
158 |
|
|
wire current_field = (picture_structure == BOTTOM_FIELD);
|
159 |
|
|
wire current_field_in_frame = (comp == COMP_Y) ? ((block == 2'd2) || (block == 2'd3)) : (block == 2'd1);
|
160 |
|
|
wire upper_half = (comp == COMP_Y) ? ((block == 2'd0) || (block == 2'd1)) : (block == 2'd0);
|
161 |
|
|
wire signed [12:0]row_ext = {{9{row[3]}}, row};
|
162 |
|
|
|
163 |
|
|
always @*
|
164 |
|
|
if (motvec_update)
|
165 |
|
|
begin
|
166 |
|
|
next_comp_out = comp;
|
167 |
|
|
next_macroblock_address_out = macroblock_address_in;
|
168 |
|
|
next_dct_block_en = (block == 2'd0) && (row == -4'sd1) && (column == 1'd0);
|
169 |
|
|
end
|
170 |
|
|
else /* no motvec_update */
|
171 |
|
|
begin
|
172 |
|
|
next_comp_out = comp_out;
|
173 |
|
|
next_macroblock_address_out = macroblock_address_out;
|
174 |
|
|
next_dct_block_en = 1'b0;
|
175 |
|
|
end
|
176 |
|
|
|
177 |
|
|
always @*
|
178 |
|
|
if (motvec_update && (picture_structure == FRAME_PICTURE))
|
179 |
|
|
begin
|
180 |
|
|
if ((motion_type == MC_FRAME) || (~macroblock_motion_forward && (picture_coding_type == P_TYPE))) /* frame-based prediction in frame picture, including zero motion vector in P-pictures */ // XXX Check
|
181 |
|
|
begin
|
182 |
|
|
next_frame_picture = 1'b1;
|
183 |
|
|
next_field_in_frame = 1'b0;
|
184 |
|
|
next_delta_x = (column ? 13'sd8 : 13'sd0) + (((comp == COMP_Y) && ((block == 2'd1) || (block == 2'd3))) ? 13'sd8 : 13'sd0);
|
185 |
|
|
next_delta_y = row_ext + 13'sd1 + ((comp == COMP_Y) ? (((block == 2'd2) || (block == 2'd3)) ? 13'sd8 : 13'sd0) : ((block == 2'd1) ? 13'sd4 : 13'sd0));
|
186 |
|
|
next_fwd_src_frame = forward_reference_frame;
|
187 |
|
|
next_fwd_src_field = 1'b0;
|
188 |
|
|
next_fwd_mv_x = pmv_0_0_0;
|
189 |
|
|
next_fwd_mv_y = pmv_0_0_1;
|
190 |
|
|
next_fwd_valid = (macroblock_motion_forward || (picture_coding_type == P_TYPE)) && ~macroblock_intra; /* forward prediction, including zero motion vector in P-pictures */
|
191 |
|
|
next_bwd_src_frame = backward_reference_frame;
|
192 |
|
|
next_bwd_src_field = 1'b0;
|
193 |
|
|
next_bwd_mv_x = pmv_0_1_0;
|
194 |
|
|
next_bwd_mv_y = pmv_0_1_1;
|
195 |
|
|
next_bwd_valid = macroblock_motion_backward && ~macroblock_intra; /* backward prediction */
|
196 |
|
|
next_recon_dst_frame = current_frame;
|
197 |
|
|
next_recon_dst_field = 1'b0;
|
198 |
|
|
next_recon_delta_x = (((comp == COMP_Y) && ((block == 2'd1) || (block == 2'd3))) ? 13'sd8 : 13'sd0);
|
199 |
|
|
next_recon_delta_y = row_ext + ((comp == COMP_Y) ? (((block == 2'd2) || (block == 2'd3)) ? 13'sd8 : 13'sd0) : ((block == 2'd1) ? 13'sd4 : 13'sd0));
|
200 |
|
|
next_recon_valid = (column == 1'd1);
|
201 |
|
|
next_write_recon = (row != -4'sd1);
|
202 |
|
|
next_dct_block_cmd = (comp == COMP_Y) ? ((dct_type == DCT_FRAME) ? DCT_L4_PASS : DCT_L4_TOP_FIELD_TO_FRAME) : DCT_C1_PASS; /* 4:2:0 chromi blocks are always frame coding, even if dct_type == DCT_FIELD. par. 6.1.3 */
|
203 |
|
|
`ifdef DEBUG
|
204 |
|
|
next_mc_descript = "MC_FRAME";
|
205 |
|
|
`endif
|
206 |
|
|
end
|
207 |
|
|
|
208 |
|
|
else if (motion_type == MC_FIELD) /* field-based prediction in frame picture. vertical dimensions divided by 2 to scale from frame to field. */
|
209 |
|
|
begin
|
210 |
|
|
next_frame_picture = 1'b1;
|
211 |
|
|
next_field_in_frame = 1'b1;
|
212 |
|
|
next_delta_x = (column ? 13'sd8 : 13'sd0) + (((comp == COMP_Y) && ((block == 2'd1) || (block == 2'd3))) ? 13'sd8 : 13'sd0);
|
213 |
|
|
next_delta_y = row_ext + 13'sd1;
|
214 |
|
|
next_fwd_src_frame = forward_reference_frame;
|
215 |
|
|
next_fwd_src_field = ~current_field_in_frame ? motion_vert_field_select_0_0 /* top field */ : motion_vert_field_select_1_0 /* bottom field */;
|
216 |
|
|
next_fwd_mv_x = ~current_field_in_frame ? pmv_0_0_0 /* top field */ : pmv_1_0_0 /* bottom field */;
|
217 |
|
|
next_fwd_mv_y = ~current_field_in_frame ? (pmv_0_0_1 >>> 1) /* top field */ : (pmv_1_0_1 >>> 1) /* bottom field */;
|
218 |
|
|
next_fwd_valid = macroblock_motion_forward && ~macroblock_intra; /* forward prediction */
|
219 |
|
|
next_bwd_src_frame = backward_reference_frame;
|
220 |
|
|
next_bwd_src_field = ~current_field_in_frame ? motion_vert_field_select_0_1 /* top field */ : motion_vert_field_select_1_1 /* bottom field */;
|
221 |
|
|
next_bwd_mv_x = ~current_field_in_frame ? pmv_0_1_0 /* top field */ : pmv_1_1_0 /* bottom field */;
|
222 |
|
|
next_bwd_mv_y = ~current_field_in_frame ? (pmv_0_1_1 >>> 1) /* top field */ : (pmv_1_1_1 >>> 1) /* bottom field */;
|
223 |
|
|
next_bwd_valid = macroblock_motion_backward && ~macroblock_intra; /* backward prediction */
|
224 |
|
|
next_recon_dst_frame = current_frame;
|
225 |
|
|
next_recon_dst_field = current_field_in_frame;
|
226 |
|
|
next_recon_delta_x = (((comp == COMP_Y) && ((block == 2'd1) || (block == 2'd3))) ? 13'sd8 : 13'sd0);
|
227 |
|
|
next_recon_delta_y = row_ext;
|
228 |
|
|
next_recon_valid = (column == 1'b1);
|
229 |
|
|
next_write_recon = (row != -4'sd1);
|
230 |
|
|
next_dct_block_cmd = (comp == COMP_Y) ? ((dct_type == DCT_FIELD) ? DCT_L4_PASS : DCT_L4_FRAME_TO_TOP_FIELD) : DCT_C1_FRAME_TO_TOP_FIELD;
|
231 |
|
|
`ifdef DEBUG
|
232 |
|
|
next_mc_descript = "MC_FIELD";
|
233 |
|
|
`endif
|
234 |
|
|
end
|
235 |
|
|
|
236 |
|
|
else if (motion_type == MC_DMV) /* dual prime prediction in frame picture */
|
237 |
|
|
begin
|
238 |
|
|
next_frame_picture = 1'b1;
|
239 |
|
|
next_field_in_frame = 1'b1;
|
240 |
|
|
next_delta_x = (column ? 13'sd8 : 13'sd0) + (((comp == COMP_Y) && ((block == 2'd1) || (block == 2'd3))) ? 13'sd8 : 13'sd0);
|
241 |
|
|
next_delta_y = row_ext + 13'sd1;
|
242 |
|
|
next_fwd_src_frame = forward_reference_frame;
|
243 |
|
|
next_fwd_src_field = current_field_in_frame;
|
244 |
|
|
next_fwd_mv_x = pmv_0_0_0;
|
245 |
|
|
next_fwd_mv_y = pmv_0_0_1 >>> 1;
|
246 |
|
|
next_fwd_valid = macroblock_motion_forward && ~macroblock_intra; /* forward prediction */
|
247 |
|
|
next_bwd_src_frame = forward_reference_frame;
|
248 |
|
|
next_bwd_src_field = ~current_field_in_frame;
|
249 |
|
|
next_bwd_mv_x = current_field_in_frame ? dmv_1_0 /* bottom field */ : dmv_0_0 /* top field */;
|
250 |
|
|
next_bwd_mv_y = current_field_in_frame ? dmv_1_1 /* bottom field */ : dmv_0_1 /* top field */;
|
251 |
|
|
next_bwd_valid = macroblock_motion_forward && ~macroblock_intra; /* forward prediction */
|
252 |
|
|
next_recon_dst_frame = current_frame;
|
253 |
|
|
next_recon_dst_field = current_field_in_frame;
|
254 |
|
|
next_recon_delta_x = (((comp == COMP_Y) && ((block == 2'd1) || (block == 2'd3))) ? 13'sd8 : 13'sd0);
|
255 |
|
|
next_recon_delta_y = row_ext;
|
256 |
|
|
next_recon_valid = (column == 1'b1);
|
257 |
|
|
next_write_recon = (row != -4'sd1);
|
258 |
|
|
next_dct_block_cmd = (comp == COMP_Y) ? ((dct_type == DCT_FIELD) ? DCT_L4_PASS : DCT_L4_FRAME_TO_TOP_FIELD) : DCT_C1_FRAME_TO_TOP_FIELD;
|
259 |
|
|
`ifdef DEBUG
|
260 |
|
|
next_mc_descript = "MC_DMV";
|
261 |
|
|
`endif
|
262 |
|
|
end
|
263 |
|
|
|
264 |
|
|
else /* invalid motion_type for frame picture, should never happen. flush dct blocks to avoid dct fifo stalling */
|
265 |
|
|
begin
|
266 |
|
|
next_frame_picture = 1'b1;
|
267 |
|
|
next_field_in_frame = 1'b0;
|
268 |
|
|
next_delta_x = 13'sd0;
|
269 |
|
|
next_delta_y = 13'sd0;
|
270 |
|
|
next_fwd_src_frame = fwd_src_frame;
|
271 |
|
|
next_fwd_src_field = 1'b0;
|
272 |
|
|
next_fwd_mv_x = 13'sd0;
|
273 |
|
|
next_fwd_mv_y = 13'sd0;
|
274 |
|
|
next_fwd_valid = 1'b0;
|
275 |
|
|
next_bwd_src_frame = bwd_src_frame;
|
276 |
|
|
next_bwd_src_field = 1'b0;
|
277 |
|
|
next_bwd_mv_x = 13'sd0;
|
278 |
|
|
next_bwd_mv_y = 13'sd0;
|
279 |
|
|
next_bwd_valid = 1'b0;
|
280 |
|
|
next_recon_dst_frame = current_frame;
|
281 |
|
|
next_recon_dst_field = 1'b0;
|
282 |
|
|
next_recon_delta_x = (((comp == COMP_Y) && ((block == 2'd1) || (block == 2'd3))) ? 13'sd8 : 13'sd0);
|
283 |
|
|
next_recon_delta_y = row_ext + ((comp == COMP_Y) ? (((block == 2'd2) || (block == 2'd3)) ? 13'sd8 : 13'sd0) : ((block == 2'd1) ? 13'sd4 : 13'sd0));
|
284 |
|
|
next_recon_valid = (column == 1'd1);
|
285 |
|
|
next_write_recon = (row != -4'sd1);
|
286 |
|
|
next_dct_block_cmd = (comp == COMP_Y) ? ((dct_type == DCT_FRAME) ? DCT_L4_PASS : DCT_L4_TOP_FIELD_TO_FRAME) : DCT_C1_PASS;
|
287 |
|
|
`ifdef DEBUG
|
288 |
|
|
next_mc_descript = (motion_type == MC_NONE) ? "MC_NONE" : "MC_ERR";
|
289 |
|
|
`endif
|
290 |
|
|
end
|
291 |
|
|
end
|
292 |
|
|
|
293 |
|
|
else if (motvec_update) /* ((picture_structure == TOP_FIELD) || (picture_structure == BOTTOM_FIELD)) */
|
294 |
|
|
begin
|
295 |
|
|
if ((motion_type == MC_FIELD) || (~macroblock_motion_forward && (picture_coding_type == P_TYPE))) /* field-based prediction in field picture, including zero motion vector in P-pictures */
|
296 |
|
|
begin
|
297 |
|
|
next_frame_picture = 1'b0;
|
298 |
|
|
next_field_in_frame = 1'b0;
|
299 |
|
|
next_delta_x = (column ? 13'sd8 : 13'sd0) + (((comp == COMP_Y) && ((block == 2'd1) || (block == 2'd3))) ? 13'sd8 : 13'sd0);
|
300 |
|
|
next_delta_y = row_ext + 13'sd1 + ((comp == COMP_Y) ? (((block == 2'd2) || (block == 2'd3)) ? 13'sd8 : 13'sd0) : ((block == 2'd1) ? 13'sd4 : 13'sd0));
|
301 |
|
|
next_fwd_src_frame = ((picture_coding_type == P_TYPE) && second_field && (current_field != motion_vert_field_select_0_0)) ? backward_reference_frame /* same frame */ : forward_reference_frame /* previous frame */;
|
302 |
|
|
next_fwd_src_field = motion_vert_field_select_0_0;
|
303 |
|
|
next_fwd_mv_x = pmv_0_0_0;
|
304 |
|
|
next_fwd_mv_y = pmv_0_0_1;
|
305 |
|
|
next_fwd_valid = (macroblock_motion_forward || (picture_coding_type == P_TYPE)) && ~macroblock_intra;
|
306 |
|
|
next_bwd_src_frame = backward_reference_frame;
|
307 |
|
|
next_bwd_src_field = motion_vert_field_select_0_1;
|
308 |
|
|
next_bwd_mv_x = pmv_0_1_0;
|
309 |
|
|
next_bwd_mv_y = pmv_0_1_1;
|
310 |
|
|
next_bwd_valid = macroblock_motion_backward && ~macroblock_intra;
|
311 |
|
|
next_recon_dst_frame = current_frame;
|
312 |
|
|
next_recon_dst_field = current_field;
|
313 |
|
|
next_recon_delta_x = (((comp == COMP_Y) && ((block == 2'd1) || (block == 2'd3))) ? 13'sd8 : 13'sd0);
|
314 |
|
|
next_recon_delta_y = row_ext + ((comp == COMP_Y) ? (((block == 2'd2) || (block == 2'd3)) ? 13'sd8 : 13'sd0) : ((block == 2'd1) ? 13'sd4 : 13'sd0));
|
315 |
|
|
next_recon_valid = (column == 1'd1);
|
316 |
|
|
next_write_recon = (row != -4'sd1);
|
317 |
|
|
next_dct_block_cmd = (comp == COMP_Y) ? DCT_L4_PASS : DCT_C1_PASS;
|
318 |
|
|
`ifdef DEBUG
|
319 |
|
|
next_mc_descript = "MC_FIELD";
|
320 |
|
|
`endif
|
321 |
|
|
end
|
322 |
|
|
|
323 |
|
|
else if (motion_type == MC_16X8) /* 16x8 based motion compensation in field picture */
|
324 |
|
|
begin
|
325 |
|
|
next_frame_picture = 1'b0;
|
326 |
|
|
next_field_in_frame = 1'b0;
|
327 |
|
|
next_delta_x = (column ? 13'sd8 : 13'sd0) + (((comp == COMP_Y) && ((block == 2'd1) || (block == 2'd3))) ? 13'sd8 : 13'sd0);
|
328 |
|
|
next_delta_y = row_ext + 13'sd1 + ((comp == COMP_Y) ? (((block == 2'd2) || (block == 2'd3)) ? 13'sd8 : 13'sd0) : ((block == 2'd1) ? 13'sd4 : 13'sd0));
|
329 |
|
|
next_fwd_src_frame = ((picture_coding_type == P_TYPE) && second_field && (current_field != (upper_half ? motion_vert_field_select_0_0 : motion_vert_field_select_1_0))) ? backward_reference_frame /* same frame */ : forward_reference_frame /* previous frame */;
|
330 |
|
|
next_fwd_src_field = upper_half ? motion_vert_field_select_0_0 : motion_vert_field_select_1_0;
|
331 |
|
|
next_fwd_mv_x = upper_half ? pmv_0_0_0 : pmv_1_0_0;
|
332 |
|
|
next_fwd_mv_y = upper_half ? pmv_0_0_1 : pmv_1_0_1;
|
333 |
|
|
next_fwd_valid = macroblock_motion_forward && ~macroblock_intra;
|
334 |
|
|
next_bwd_src_frame = backward_reference_frame;
|
335 |
|
|
next_bwd_src_field = upper_half ? motion_vert_field_select_0_1 : motion_vert_field_select_1_1;
|
336 |
|
|
next_bwd_mv_x = upper_half ? pmv_0_1_0 : pmv_1_1_0;
|
337 |
|
|
next_bwd_mv_y = upper_half ? pmv_0_1_1 : pmv_1_1_1;
|
338 |
|
|
next_bwd_valid = macroblock_motion_backward && ~macroblock_intra;
|
339 |
|
|
next_recon_dst_frame = current_frame;
|
340 |
|
|
next_recon_dst_field = current_field;
|
341 |
|
|
next_recon_delta_x = (((comp == COMP_Y) && ((block == 2'd1) || (block == 2'd3))) ? 13'sd8 : 13'sd0);
|
342 |
|
|
next_recon_delta_y = row_ext + ((comp == COMP_Y) ? (((block == 2'd2) || (block == 2'd3)) ? 13'sd8 : 13'sd0) : ((block == 2'd1) ? 13'sd4 : 13'sd0));
|
343 |
|
|
next_recon_valid = (column == 1'b1);
|
344 |
|
|
next_write_recon = (row != -4'sd1);
|
345 |
|
|
next_dct_block_cmd = (comp == COMP_Y) ? DCT_L4_PASS : DCT_C1_PASS;
|
346 |
|
|
`ifdef DEBUG
|
347 |
|
|
next_mc_descript = "MC_16X8";
|
348 |
|
|
`endif
|
349 |
|
|
end
|
350 |
|
|
|
351 |
|
|
else if (motion_type == MC_DMV) /* dual-prime prediction in field picture */
|
352 |
|
|
begin
|
353 |
|
|
next_frame_picture = 1'b0;
|
354 |
|
|
next_field_in_frame = 1'b0;
|
355 |
|
|
next_delta_x = (column ? 13'sd8 : 13'sd0) + (((comp == COMP_Y) && ((block == 2'd1) || (block == 2'd3))) ? 13'sd8 : 13'sd0);
|
356 |
|
|
next_delta_y = row_ext + 13'sd1 + ((comp == COMP_Y) ? (((block == 2'd2) || (block == 2'd3)) ? 13'sd8 : 13'sd0) : ((block == 2'd1) ? 13'sd4 : 13'sd0));
|
357 |
|
|
next_fwd_src_frame = forward_reference_frame;
|
358 |
|
|
next_fwd_src_field = current_field; /* prediction from field of same parity */
|
359 |
|
|
next_fwd_mv_x = pmv_0_0_0;
|
360 |
|
|
next_fwd_mv_y = pmv_0_0_1;
|
361 |
|
|
next_fwd_valid = macroblock_motion_forward && ~macroblock_intra;
|
362 |
|
|
next_bwd_src_frame = (second_field) ? backward_reference_frame /* same frame */ : forward_reference_frame /* previous frame */;
|
363 |
|
|
next_bwd_src_field = ~current_field; /* prediction from field of opposite parity */
|
364 |
|
|
next_bwd_mv_x = dmv_0_0;
|
365 |
|
|
next_bwd_mv_y = dmv_0_1;
|
366 |
|
|
next_bwd_valid = macroblock_motion_forward && ~macroblock_intra;
|
367 |
|
|
next_recon_dst_frame = current_frame;
|
368 |
|
|
next_recon_dst_field = current_field;
|
369 |
|
|
next_recon_delta_x = (((comp == COMP_Y) && ((block == 2'd1) || (block == 2'd3))) ? 13'sd8 : 13'sd0);
|
370 |
|
|
next_recon_delta_y = row_ext + ((comp == COMP_Y) ? (((block == 2'd2) || (block == 2'd3)) ? 13'sd8 : 13'sd0) : ((block == 2'd1) ? 13'sd4 : 13'sd0));
|
371 |
|
|
next_recon_valid = (column == 1'b1);
|
372 |
|
|
next_write_recon = (row != -4'sd1);
|
373 |
|
|
next_dct_block_cmd = (comp == COMP_Y) ? DCT_L4_PASS : DCT_C1_PASS;
|
374 |
|
|
`ifdef DEBUG
|
375 |
|
|
next_mc_descript = "MC_DMV";
|
376 |
|
|
`endif
|
377 |
|
|
end
|
378 |
|
|
|
379 |
|
|
else /* invalid motion_type for field picture, should never happen. flush dct blocks to avoid dct fifo stalling */
|
380 |
|
|
begin
|
381 |
|
|
next_frame_picture = 1'b0;
|
382 |
|
|
next_field_in_frame = 1'b0;
|
383 |
|
|
next_delta_x = 13'sd0;
|
384 |
|
|
next_delta_y = 13'sd0;
|
385 |
|
|
next_fwd_src_frame = fwd_src_frame;
|
386 |
|
|
next_fwd_src_field = current_field;
|
387 |
|
|
next_fwd_mv_x = 13'sd0;
|
388 |
|
|
next_fwd_mv_y = 13'sd0;
|
389 |
|
|
next_fwd_valid = 1'b0;
|
390 |
|
|
next_bwd_src_frame = bwd_src_frame;
|
391 |
|
|
next_bwd_src_field = current_field;
|
392 |
|
|
next_bwd_mv_x = 13'sd0;
|
393 |
|
|
next_bwd_mv_y = 13'sd0;
|
394 |
|
|
next_bwd_valid = 1'b0;
|
395 |
|
|
next_recon_dst_frame = current_frame;
|
396 |
|
|
next_recon_dst_field = current_field;
|
397 |
|
|
next_recon_delta_x = (((comp == COMP_Y) && ((block == 2'd1) || (block == 2'd3))) ? 13'sd8 : 13'sd0);
|
398 |
|
|
next_recon_delta_y = row_ext + ((comp == COMP_Y) ? (((block == 2'd2) || (block == 2'd3)) ? 13'sd8 : 13'sd0) : ((block == 2'd1) ? 13'sd4 : 13'sd0));
|
399 |
|
|
next_recon_valid = (column == 1'd1);
|
400 |
|
|
next_write_recon = (row != -4'sd1);
|
401 |
|
|
next_dct_block_cmd = (comp == COMP_Y) ? DCT_L4_PASS : DCT_C1_PASS;
|
402 |
|
|
`ifdef DEBUG
|
403 |
|
|
next_mc_descript = (motion_type == MC_NONE) ? "MC_NONE" : "MC_ERR";
|
404 |
|
|
`endif
|
405 |
|
|
end
|
406 |
|
|
end
|
407 |
|
|
|
408 |
|
|
else /* no motvec_update */
|
409 |
|
|
begin
|
410 |
|
|
next_frame_picture = frame_picture;
|
411 |
|
|
next_field_in_frame = field_in_frame;
|
412 |
|
|
next_delta_x = delta_x;
|
413 |
|
|
next_delta_y = delta_y;
|
414 |
|
|
next_fwd_src_frame = fwd_src_frame;
|
415 |
|
|
next_fwd_src_field = fwd_src_field;
|
416 |
|
|
next_fwd_mv_x = fwd_mv_x;
|
417 |
|
|
next_fwd_mv_y = fwd_mv_y;
|
418 |
|
|
next_fwd_valid = 1'b0;
|
419 |
|
|
next_bwd_src_frame = bwd_src_frame;
|
420 |
|
|
next_bwd_src_field = bwd_src_field;
|
421 |
|
|
next_bwd_mv_x = bwd_mv_x;
|
422 |
|
|
next_bwd_mv_y = bwd_mv_y;
|
423 |
|
|
next_bwd_valid = 1'b0;
|
424 |
|
|
next_recon_dst_frame = recon_dst_frame;
|
425 |
|
|
next_recon_dst_field = recon_dst_field;
|
426 |
|
|
next_recon_delta_x = recon_delta_x;
|
427 |
|
|
next_recon_delta_y = recon_delta_y;
|
428 |
|
|
next_recon_valid = 1'b0;
|
429 |
|
|
next_write_recon = write_recon;
|
430 |
|
|
next_dct_block_cmd = dct_block_cmd;
|
431 |
|
|
`ifdef DEBUG
|
432 |
|
|
next_mc_descript = "MC_NONE";
|
433 |
|
|
`endif
|
434 |
|
|
end
|
435 |
|
|
|
436 |
|
|
|
437 |
|
|
always @(posedge clk)
|
438 |
|
|
if (~rst)
|
439 |
|
|
begin
|
440 |
|
|
frame_picture <= 1'b0;
|
441 |
|
|
field_in_frame <= 1'b0;
|
442 |
|
|
comp_out <= COMP_Y;
|
443 |
|
|
macroblock_address_out <= 13'd0;
|
444 |
|
|
delta_x <= 13'sd0;
|
445 |
|
|
delta_y <= 13'sd0;
|
446 |
|
|
fwd_src_frame <= 3'd0;
|
447 |
|
|
fwd_src_field <= 1'd0;
|
448 |
|
|
fwd_mv_x <= 13'sd0;
|
449 |
|
|
fwd_mv_y <= 13'sd0;
|
450 |
|
|
fwd_valid <= 1'b0;
|
451 |
|
|
bwd_src_frame <= 3'd0;
|
452 |
|
|
bwd_src_field <= 1'd0;
|
453 |
|
|
bwd_mv_x <= 13'sd0;
|
454 |
|
|
bwd_mv_y <= 13'sd0;
|
455 |
|
|
bwd_valid <= 1'b0;
|
456 |
|
|
recon_dst_frame <= 3'd0;
|
457 |
|
|
recon_dst_field <= 1'd0;
|
458 |
|
|
recon_delta_x <= 13'sd0;
|
459 |
|
|
recon_delta_y <= 13'sd0;
|
460 |
|
|
recon_valid <= 1'b0;
|
461 |
|
|
write_recon <= 1'b0;
|
462 |
|
|
dct_block_cmd <= 2'd0;
|
463 |
|
|
dct_block_en <= 1'b0;
|
464 |
|
|
`ifdef DEBUG
|
465 |
|
|
mc_descript <= "";
|
466 |
|
|
`endif
|
467 |
|
|
end
|
468 |
|
|
else if (clk_en)
|
469 |
|
|
begin
|
470 |
|
|
frame_picture <= next_frame_picture;
|
471 |
|
|
field_in_frame <= next_field_in_frame;
|
472 |
|
|
comp_out <= next_comp_out;
|
473 |
|
|
macroblock_address_out <= next_macroblock_address_out;
|
474 |
|
|
delta_x <= next_delta_x;
|
475 |
|
|
delta_y <= next_delta_y;
|
476 |
|
|
fwd_src_frame <= next_fwd_src_frame;
|
477 |
|
|
fwd_src_field <= next_fwd_src_field;
|
478 |
|
|
fwd_mv_x <= next_fwd_mv_x;
|
479 |
|
|
fwd_mv_y <= next_fwd_mv_y;
|
480 |
|
|
fwd_valid <= next_fwd_valid;
|
481 |
|
|
bwd_src_frame <= next_bwd_src_frame;
|
482 |
|
|
bwd_src_field <= next_bwd_src_field;
|
483 |
|
|
bwd_mv_x <= next_bwd_mv_x;
|
484 |
|
|
bwd_mv_y <= next_bwd_mv_y;
|
485 |
|
|
bwd_valid <= next_bwd_valid;
|
486 |
|
|
recon_dst_frame <= next_recon_dst_frame;
|
487 |
|
|
recon_dst_field <= next_recon_dst_field;
|
488 |
|
|
recon_delta_x <= next_recon_delta_x;
|
489 |
|
|
recon_delta_y <= next_recon_delta_y;
|
490 |
|
|
recon_valid <= next_recon_valid;
|
491 |
|
|
write_recon <= next_write_recon;
|
492 |
|
|
dct_block_cmd <= next_dct_block_cmd;
|
493 |
|
|
dct_block_en <= next_dct_block_en;
|
494 |
|
|
`ifdef DEBUG
|
495 |
|
|
mc_descript <= next_mc_descript;
|
496 |
|
|
`endif
|
497 |
|
|
end
|
498 |
|
|
else
|
499 |
|
|
begin
|
500 |
|
|
frame_picture <= frame_picture;
|
501 |
|
|
field_in_frame <= field_in_frame;
|
502 |
|
|
comp_out <= comp_out;
|
503 |
|
|
macroblock_address_out <= macroblock_address_out;
|
504 |
|
|
delta_x <= delta_x;
|
505 |
|
|
delta_y <= delta_y;
|
506 |
|
|
fwd_src_frame <= fwd_src_frame;
|
507 |
|
|
fwd_src_field <= fwd_src_field;
|
508 |
|
|
fwd_mv_x <= fwd_mv_x;
|
509 |
|
|
fwd_mv_y <= fwd_mv_y;
|
510 |
|
|
fwd_valid <= fwd_valid;
|
511 |
|
|
bwd_src_frame <= bwd_src_frame;
|
512 |
|
|
bwd_src_field <= bwd_src_field;
|
513 |
|
|
bwd_mv_x <= bwd_mv_x;
|
514 |
|
|
bwd_mv_y <= bwd_mv_y;
|
515 |
|
|
bwd_valid <= bwd_valid;
|
516 |
|
|
recon_dst_frame <= recon_dst_frame;
|
517 |
|
|
recon_dst_field <= recon_dst_field;
|
518 |
|
|
recon_delta_x <= recon_delta_x;
|
519 |
|
|
recon_delta_y <= recon_delta_y;
|
520 |
|
|
recon_valid <= recon_valid;
|
521 |
|
|
write_recon <= write_recon;
|
522 |
|
|
dct_block_cmd <= dct_block_cmd;
|
523 |
|
|
dct_block_en <= dct_block_en;
|
524 |
|
|
`ifdef DEBUG
|
525 |
|
|
mc_descript <= mc_descript;
|
526 |
|
|
`endif
|
527 |
|
|
end
|
528 |
|
|
|
529 |
|
|
`ifdef DEBUG
|
530 |
|
|
always @(posedge clk)
|
531 |
|
|
if (clk_en && motvec_update && (comp == COMP_Y) && (block == 0 ) && (row == 0) && (column == 1))
|
532 |
|
|
begin
|
533 |
|
|
if (picture_structure == FRAME_PICTURE)
|
534 |
|
|
begin
|
535 |
|
|
if(fwd_valid && bwd_valid)
|
536 |
|
|
$display("%m\t macroblock_address %4d %8s fwd (%5d, %5d) bwd (%5d, %5d)",
|
537 |
|
|
macroblock_address_in, mc_descript, fwd_mv_x, fwd_mv_y, bwd_mv_x, bwd_mv_y);
|
538 |
|
|
else if (fwd_valid && ~bwd_valid)
|
539 |
|
|
$display("%m\t macroblock_address %4d %8s fwd (%5d, %5d)",
|
540 |
|
|
macroblock_address_in, mc_descript, fwd_mv_x, fwd_mv_y);
|
541 |
|
|
else if (~fwd_valid && bwd_valid)
|
542 |
|
|
$display("%m\t macroblock_address %4d %8s bwd (%5d, %5d)",
|
543 |
|
|
macroblock_address_in, mc_descript, bwd_mv_x, bwd_mv_y);
|
544 |
|
|
else
|
545 |
|
|
$display("%m\t macroblock_address %4d %8s intra",
|
546 |
|
|
macroblock_address_in, mc_descript);
|
547 |
|
|
end
|
548 |
|
|
else
|
549 |
|
|
begin
|
550 |
|
|
if(fwd_valid && bwd_valid)
|
551 |
|
|
$display("%m\t macroblock_address %4d field %d %8s fwd field %d (%5d, %5d) bwd field %d (%5d, %5d)",
|
552 |
|
|
macroblock_address_in, recon_dst_field, mc_descript, fwd_src_field, fwd_mv_x, fwd_mv_y, bwd_src_field, bwd_mv_x, bwd_mv_y);
|
553 |
|
|
else if (fwd_valid && ~bwd_valid)
|
554 |
|
|
$display("%m\t macroblock_address %4d field %d %8s fwd field %d (%5d, %5d)",
|
555 |
|
|
macroblock_address_in, recon_dst_field, mc_descript, fwd_src_field, fwd_mv_x, fwd_mv_y);
|
556 |
|
|
else if (~fwd_valid && bwd_valid)
|
557 |
|
|
$display("%m\t macroblock_address %4d field %d %8s bwd field %d (%5d, %5d)",
|
558 |
|
|
macroblock_address_in, recon_dst_field, mc_descript, bwd_src_field, bwd_mv_x, bwd_mv_y);
|
559 |
|
|
else
|
560 |
|
|
$display("%m\t macroblock_address %4d field %d %8s intra",
|
561 |
|
|
macroblock_address_in, recon_dst_field, mc_descript);
|
562 |
|
|
end
|
563 |
|
|
end
|
564 |
|
|
`endif
|
565 |
|
|
|
566 |
|
|
`ifdef DEBUG_MOTVEC
|
567 |
|
|
always @(posedge clk)
|
568 |
|
|
if (clk_en)
|
569 |
|
|
begin
|
570 |
|
|
$strobe("%m\t motvec_update: %d macroblock_address_in: %d comp: %d block: %d row: %d column: %d",
|
571 |
|
|
motvec_update, macroblock_address_in, comp, block, row, column);
|
572 |
|
|
$strobe("%m\t current_field: %d frame_picture: %d field_in_frame: %d delta_x: %d delta_y: %d",
|
573 |
|
|
current_field, frame_picture, field_in_frame, delta_x, delta_y);
|
574 |
|
|
$strobe("%m\t fwd_src_frame: %d fwd_src_field: %d fwd_mv_x: %d fwd_mv_y: %d fwd_valid: %d",
|
575 |
|
|
fwd_src_frame, fwd_src_field, fwd_mv_x, fwd_mv_y, fwd_valid);
|
576 |
|
|
$strobe("%m\t bwd_src_frame: %d bwd_src_field: %d bwd_mv_x: %d bwd_mv_y: %d bwd_valid: %d",
|
577 |
|
|
bwd_src_frame, bwd_src_field, bwd_mv_x, bwd_mv_y, bwd_valid);
|
578 |
|
|
$strobe("%m\t recon_dst_frame: %d recon_dst_field: %d recon_delta_x: %d recon_delta_y: %d fwd_valid: %d bwd_valid: %d recon_valid: %d write_recon: %d",
|
579 |
|
|
recon_dst_frame, recon_dst_field, recon_delta_x, recon_delta_y, fwd_valid, bwd_valid, recon_valid, write_recon);
|
580 |
|
|
$strobe("%m\t dct_block_cmd: %d dct_block_en: %d",
|
581 |
|
|
dct_block_cmd, dct_block_en);
|
582 |
|
|
end
|
583 |
|
|
`endif
|
584 |
|
|
|
585 |
|
|
endmodule
|
586 |
|
|
/* not truncated */
|