1 |
85 |
jamey.hick |
// The MIT License
|
2 |
|
|
|
3 |
|
|
// Copyright (c) 2006-2007 Massachusetts Institute of Technology
|
4 |
|
|
|
5 |
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 |
|
|
// of this software and associated documentation files (the "Software"), to deal
|
7 |
|
|
// in the Software without restriction, including without limitation the rights
|
8 |
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 |
|
|
// copies of the Software, and to permit persons to whom the Software is
|
10 |
|
|
// furnished to do so, subject to the following conditions:
|
11 |
|
|
|
12 |
|
|
// The above copyright notice and this permission notice shall be included in
|
13 |
|
|
// all copies or substantial portions of the Software.
|
14 |
|
|
|
15 |
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16 |
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18 |
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19 |
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20 |
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21 |
|
|
// THE SOFTWARE.
|
22 |
84 |
jamey.hick |
//**********************************************************************
|
23 |
|
|
// Deblocking Filter
|
24 |
|
|
//----------------------------------------------------------------------
|
25 |
|
|
//
|
26 |
|
|
//
|
27 |
|
|
|
28 |
|
|
package mkDeblockFilter;
|
29 |
|
|
|
30 |
|
|
import H264Types::*;
|
31 |
|
|
|
32 |
|
|
import IDeblockFilter::*;
|
33 |
|
|
import FIFO::*;
|
34 |
|
|
import Vector::*;
|
35 |
|
|
|
36 |
|
|
import Connectable::*;
|
37 |
|
|
import GetPut::*;
|
38 |
|
|
import ClientServer::*;
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
//-----------------------------------------------------------
|
44 |
|
|
// Local Datatypes
|
45 |
|
|
//-----------------------------------------------------------
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
//-----------------------------------------------------------
|
51 |
|
|
// Helper functions
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
|
|
|
56 |
|
|
//-----------------------------------------------------------
|
57 |
|
|
// Deblocking Filter Module
|
58 |
|
|
//-----------------------------------------------------------
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
(* synthesize *)
|
62 |
|
|
module mkDeblockFilter( IDeblockFilter );
|
63 |
|
|
|
64 |
|
|
FIFO#(EntropyDecOT) infifo <- mkFIFO();
|
65 |
|
|
FIFO#(DeblockFilterOT) outfifo <- mkFIFO();
|
66 |
|
|
|
67 |
|
|
FIFO#(MemReq#(TAdd#(PicWidthSz,5),32)) dataMemReqQ <- mkSizedFIFO(1);
|
68 |
|
|
FIFO#(MemReq#(PicWidthSz,13)) parameterMemReqQ <- mkSizedFIFO(1);
|
69 |
|
|
FIFO#(MemResp#(32)) dataMemRespQ <- mkSizedFIFO(1);
|
70 |
|
|
FIFO#(MemResp#(13)) parameterMemRespQ <- mkSizedFIFO(1);
|
71 |
|
|
|
72 |
|
|
Reg#(Bit#(1)) chromaFlag <- mkReg(0);
|
73 |
|
|
Reg#(Bit#(4)) blockNum <- mkReg(0);
|
74 |
|
|
Reg#(Bit#(4)) pixelNum <- mkReg(0);
|
75 |
|
|
|
76 |
|
|
Reg#(Bit#(PicWidthSz)) picWidth <- mkReg(maxPicWidthInMB);
|
77 |
|
|
Reg#(Bit#(PicHeightSz)) picHeight <- mkReg(0);
|
78 |
|
|
Reg#(Bit#(PicAreaSz)) firstMb <- mkReg(0);
|
79 |
|
|
Reg#(Bit#(PicAreaSz)) currMb <- mkReg(0);
|
80 |
|
|
Reg#(Bit#(PicAreaSz)) currMbHor <- mkReg(0);//horizontal position of currMb
|
81 |
|
|
Reg#(Bit#(PicHeightSz)) currMbVer <- mkReg(0);//vertical position of currMb
|
82 |
|
|
|
83 |
|
|
Vector#(3,Reg#(Bit#(8))) tempinput <- replicateM(mkRegU);
|
84 |
|
|
|
85 |
|
|
Reg#(Bool) endOfFrame <- mkReg(False);
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
//-----------------------------------------------------------
|
89 |
|
|
// Rules
|
90 |
|
|
|
91 |
|
|
rule passing (currMbHor
|
92 |
|
|
//$display( "Trace Deblocking Filter: passing infifo packed %h", pack(infifo.first()));
|
93 |
|
|
case (infifo.first()) matches
|
94 |
|
|
tagged NewUnit . xdata :
|
95 |
|
|
begin
|
96 |
|
|
infifo.deq();
|
97 |
|
|
outfifo.enq(EDOT infifo.first());
|
98 |
|
|
$display("ccl5newunit");
|
99 |
|
|
$display("ccl5rbspbyte %h", xdata);
|
100 |
|
|
end
|
101 |
|
|
tagged SPSpic_width_in_mbs .xdata :
|
102 |
|
|
begin
|
103 |
|
|
infifo.deq();
|
104 |
|
|
outfifo.enq(EDOT infifo.first());
|
105 |
|
|
picWidth <= xdata;
|
106 |
|
|
end
|
107 |
|
|
tagged SPSpic_height_in_map_units .xdata :
|
108 |
|
|
begin
|
109 |
|
|
infifo.deq();
|
110 |
|
|
outfifo.enq(EDOT infifo.first());
|
111 |
|
|
picHeight <= xdata;
|
112 |
|
|
end
|
113 |
|
|
tagged SHfirst_mb_in_slice .xdata :
|
114 |
|
|
begin
|
115 |
|
|
infifo.deq();
|
116 |
|
|
outfifo.enq(EDOT infifo.first());
|
117 |
|
|
firstMb <= xdata;
|
118 |
|
|
currMb <= xdata;
|
119 |
|
|
currMbHor <= xdata;
|
120 |
|
|
currMbVer <= 0;
|
121 |
|
|
end
|
122 |
|
|
tagged PBoutput .xdata :
|
123 |
|
|
begin
|
124 |
|
|
infifo.deq();
|
125 |
|
|
Bit#(2) blockHor = {blockNum[2],blockNum[0]};
|
126 |
|
|
Bit#(2) blockVer = {blockNum[3],blockNum[1]};
|
127 |
|
|
Bit#(2) pixelHor = {pixelNum[1],pixelNum[0]};
|
128 |
|
|
Bit#(2) pixelVer = {pixelNum[3],pixelNum[2]};
|
129 |
|
|
Bit#(PicWidthSz) currMbHorT = truncate(currMbHor);
|
130 |
|
|
Bit#(32) pixelq = {xdata[3],xdata[2],xdata[1],xdata[0]};
|
131 |
|
|
if(chromaFlag==0)
|
132 |
|
|
outfifo.enq(DFBLuma {ver:{currMbVer,blockVer,pixelVer},hor:{currMbHorT,blockHor},data:pixelq});
|
133 |
|
|
else
|
134 |
|
|
outfifo.enq(DFBChroma {uv:blockHor[1],ver:{currMbVer,blockVer[0],pixelVer},hor:{currMbHorT,blockHor[0]},data:pixelq});
|
135 |
|
|
if(pixelNum == 12)
|
136 |
|
|
begin
|
137 |
|
|
pixelNum <= 0;
|
138 |
|
|
if(blockNum == 15)
|
139 |
|
|
begin
|
140 |
|
|
blockNum <= 0;
|
141 |
|
|
chromaFlag <= 1;
|
142 |
|
|
end
|
143 |
|
|
else if(blockNum==7 && chromaFlag==1)
|
144 |
|
|
begin
|
145 |
|
|
blockNum <= 0;
|
146 |
|
|
chromaFlag <= 0;
|
147 |
|
|
currMb <= currMb+1;
|
148 |
|
|
currMbHor <= currMbHor+1;
|
149 |
|
|
if(currMbVer==picHeight-1 && currMbHor==zeroExtend(picWidth-1))
|
150 |
|
|
endOfFrame <= True;
|
151 |
|
|
end
|
152 |
|
|
else
|
153 |
|
|
blockNum <= blockNum+1;
|
154 |
|
|
end
|
155 |
|
|
else
|
156 |
|
|
pixelNum <= pixelNum+4;
|
157 |
|
|
//$display( "Trace Deblocking Filter: passing PBoutput %h %h %h %h", blockNum, pixelNum, pixelHor, xdata);
|
158 |
|
|
end
|
159 |
|
|
tagged EndOfFile :
|
160 |
|
|
begin
|
161 |
|
|
infifo.deq();
|
162 |
|
|
outfifo.enq(EDOT infifo.first());
|
163 |
|
|
$display( "ccl5: EndOfFile reached");
|
164 |
|
|
//$finish(0);
|
165 |
|
|
end
|
166 |
|
|
default:
|
167 |
|
|
begin
|
168 |
|
|
infifo.deq();
|
169 |
|
|
outfifo.enq(EDOT infifo.first());
|
170 |
|
|
end
|
171 |
|
|
endcase
|
172 |
|
|
endrule
|
173 |
|
|
|
174 |
|
|
|
175 |
|
|
rule currMbHorUpdate( !(currMbHor
|
176 |
|
|
Bit#(PicAreaSz) temp = zeroExtend(picWidth);
|
177 |
|
|
if((currMbHor >> 3) >= temp)
|
178 |
|
|
begin
|
179 |
|
|
currMbHor <= currMbHor - (temp << 3);
|
180 |
|
|
currMbVer <= currMbVer + 8;
|
181 |
|
|
end
|
182 |
|
|
else
|
183 |
|
|
begin
|
184 |
|
|
currMbHor <= currMbHor - temp;
|
185 |
|
|
currMbVer <= currMbVer + 1;
|
186 |
|
|
end
|
187 |
|
|
//$display( "Trace Deblocking Filter: currMbHorUpdate %h %h", currMbHor, currMbVer);
|
188 |
|
|
endrule
|
189 |
|
|
|
190 |
|
|
|
191 |
|
|
rule outputEndOfFrame(endOfFrame);
|
192 |
|
|
outfifo.enq(EndOfFrame);
|
193 |
|
|
endOfFrame <= False;
|
194 |
|
|
//$display( "Trace Deblocking Filter: outputEndOfFrame %h", pack(infifo.first()));
|
195 |
|
|
endrule
|
196 |
|
|
|
197 |
|
|
|
198 |
|
|
interface Client mem_client_data;
|
199 |
|
|
interface Get request = fifoToGet(dataMemReqQ);
|
200 |
|
|
interface Put response = fifoToPut(dataMemRespQ);
|
201 |
|
|
endinterface
|
202 |
|
|
|
203 |
|
|
interface Client mem_client_parameter;
|
204 |
|
|
interface Get request = fifoToGet(parameterMemReqQ);
|
205 |
|
|
interface Put response = fifoToPut(parameterMemRespQ);
|
206 |
|
|
endinterface
|
207 |
|
|
|
208 |
|
|
interface Put ioin = fifoToPut(infifo);
|
209 |
|
|
interface Get ioout = fifoToGet(outfifo);
|
210 |
|
|
|
211 |
|
|
endmodule
|
212 |
|
|
|
213 |
|
|
endpackage
|