// The MIT License
|
// The MIT License
|
|
|
// Copyright (c) 2006-2007 Massachusetts Institute of Technology
|
// Copyright (c) 2006-2007 Massachusetts Institute of Technology
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
|
|
// The above copyright notice and this permission notice shall be included in
|
// The above copyright notice and this permission notice shall be included in
|
// all copies or substantial portions of the Software.
|
// all copies or substantial portions of the Software.
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
// THE SOFTWARE.
|
// THE SOFTWARE.
|
//**********************************************************************
|
//**********************************************************************
|
// Deblocking Filter
|
// Deblocking Filter
|
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
//
|
//
|
//
|
//
|
|
|
package mkDeblockFilter;
|
package mkDeblockFilter;
|
|
|
import H264Types::*;
|
import H264Types::*;
|
|
|
import IDeblockFilter::*;
|
import IDeblockFilter::*;
|
import FIFO::*;
|
import FIFO::*;
|
import Vector::*;
|
import Vector::*;
|
|
|
import Connectable::*;
|
import Connectable::*;
|
import GetPut::*;
|
import GetPut::*;
|
import ClientServer::*;
|
import ClientServer::*;
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
// Local Datatypes
|
// Local Datatypes
|
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
// Helper functions
|
// Helper functions
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
// Deblocking Filter Module
|
// Deblocking Filter Module
|
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
|
|
|
|
(* synthesize *)
|
(* synthesize *)
|
module mkDeblockFilter( IDeblockFilter );
|
module mkDeblockFilter( IDeblockFilter );
|
|
|
FIFO#(EntropyDecOT) infifo <- mkFIFO();
|
FIFO#(EntropyDecOT) infifo <- mkFIFO();
|
FIFO#(DeblockFilterOT) outfifo <- mkFIFO();
|
FIFO#(DeblockFilterOT) outfifo <- mkFIFO();
|
|
|
FIFO#(MemReq#(TAdd#(PicWidthSz,5),32)) dataMemReqQ <- mkSizedFIFO(1);
|
FIFO#(MemReq#(TAdd#(PicWidthSz,5),32)) dataMemReqQ <- mkSizedFIFO(1);
|
FIFO#(MemReq#(PicWidthSz,13)) parameterMemReqQ <- mkSizedFIFO(1);
|
FIFO#(MemReq#(PicWidthSz,13)) parameterMemReqQ <- mkSizedFIFO(1);
|
FIFO#(MemResp#(32)) dataMemRespQ <- mkSizedFIFO(1);
|
FIFO#(MemResp#(32)) dataMemRespQ <- mkSizedFIFO(1);
|
FIFO#(MemResp#(13)) parameterMemRespQ <- mkSizedFIFO(1);
|
FIFO#(MemResp#(13)) parameterMemRespQ <- mkSizedFIFO(1);
|
|
|
Reg#(Bit#(1)) chromaFlag <- mkReg(0);
|
Reg#(Bit#(1)) chromaFlag <- mkReg(0);
|
Reg#(Bit#(4)) blockNum <- mkReg(0);
|
Reg#(Bit#(4)) blockNum <- mkReg(0);
|
Reg#(Bit#(4)) pixelNum <- mkReg(0);
|
Reg#(Bit#(4)) pixelNum <- mkReg(0);
|
|
|
Reg#(Bit#(PicWidthSz)) picWidth <- mkReg(maxPicWidthInMB);
|
Reg#(Bit#(PicWidthSz)) picWidth <- mkReg(maxPicWidthInMB);
|
Reg#(Bit#(PicHeightSz)) picHeight <- mkReg(0);
|
Reg#(Bit#(PicHeightSz)) picHeight <- mkReg(0);
|
Reg#(Bit#(PicAreaSz)) firstMb <- mkReg(0);
|
Reg#(Bit#(PicAreaSz)) firstMb <- mkReg(0);
|
Reg#(Bit#(PicAreaSz)) currMb <- mkReg(0);
|
Reg#(Bit#(PicAreaSz)) currMb <- mkReg(0);
|
Reg#(Bit#(PicAreaSz)) currMbHor <- mkReg(0);//horizontal position of currMb
|
Reg#(Bit#(PicAreaSz)) currMbHor <- mkReg(0);//horizontal position of currMb
|
Reg#(Bit#(PicHeightSz)) currMbVer <- mkReg(0);//vertical position of currMb
|
Reg#(Bit#(PicHeightSz)) currMbVer <- mkReg(0);//vertical position of currMb
|
|
|
Vector#(3,Reg#(Bit#(8))) tempinput <- replicateM(mkRegU);
|
Vector#(3,Reg#(Bit#(8))) tempinput <- replicateM(mkRegU);
|
|
|
Reg#(Bool) endOfFrame <- mkReg(False);
|
Reg#(Bool) endOfFrame <- mkReg(False);
|
|
|
|
|
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
// Rules
|
// Rules
|
|
|
rule passing (currMbHor
|
rule passing (currMbHor
|
//$display( "Trace Deblocking Filter: passing infifo packed %h", pack(infifo.first()));
|
//$display( "Trace Deblocking Filter: passing infifo packed %h", pack(infifo.first()));
|
case (infifo.first()) matches
|
case (infifo.first()) matches
|
tagged NewUnit . xdata :
|
tagged NewUnit . xdata :
|
begin
|
begin
|
infifo.deq();
|
infifo.deq();
|
outfifo.enq(EDOT infifo.first());
|
outfifo.enq(EDOT infifo.first());
|
$display("ccl5newunit");
|
$display("ccl5newunit");
|
$display("ccl5rbspbyte %h", xdata);
|
$display("ccl5rbspbyte %h", xdata);
|
end
|
end
|
tagged SPSpic_width_in_mbs .xdata :
|
tagged SPSpic_width_in_mbs .xdata :
|
begin
|
begin
|
infifo.deq();
|
infifo.deq();
|
outfifo.enq(EDOT infifo.first());
|
outfifo.enq(EDOT infifo.first());
|
picWidth <= xdata;
|
picWidth <= xdata;
|
end
|
end
|
tagged SPSpic_height_in_map_units .xdata :
|
tagged SPSpic_height_in_map_units .xdata :
|
begin
|
begin
|
infifo.deq();
|
infifo.deq();
|
outfifo.enq(EDOT infifo.first());
|
outfifo.enq(EDOT infifo.first());
|
picHeight <= xdata;
|
picHeight <= xdata;
|
end
|
end
|
tagged SHfirst_mb_in_slice .xdata :
|
tagged SHfirst_mb_in_slice .xdata :
|
begin
|
begin
|
infifo.deq();
|
infifo.deq();
|
outfifo.enq(EDOT infifo.first());
|
outfifo.enq(EDOT infifo.first());
|
firstMb <= xdata;
|
firstMb <= xdata;
|
currMb <= xdata;
|
currMb <= xdata;
|
currMbHor <= xdata;
|
currMbHor <= xdata;
|
currMbVer <= 0;
|
currMbVer <= 0;
|
end
|
end
|
tagged PBoutput .xdata :
|
tagged PBoutput .xdata :
|
begin
|
begin
|
infifo.deq();
|
infifo.deq();
|
Bit#(2) blockHor = {blockNum[2],blockNum[0]};
|
Bit#(2) blockHor = {blockNum[2],blockNum[0]};
|
Bit#(2) blockVer = {blockNum[3],blockNum[1]};
|
Bit#(2) blockVer = {blockNum[3],blockNum[1]};
|
Bit#(2) pixelHor = {pixelNum[1],pixelNum[0]};
|
Bit#(2) pixelHor = {pixelNum[1],pixelNum[0]};
|
Bit#(2) pixelVer = {pixelNum[3],pixelNum[2]};
|
Bit#(2) pixelVer = {pixelNum[3],pixelNum[2]};
|
Bit#(PicWidthSz) currMbHorT = truncate(currMbHor);
|
Bit#(PicWidthSz) currMbHorT = truncate(currMbHor);
|
Bit#(32) pixelq = {xdata[3],xdata[2],xdata[1],xdata[0]};
|
Bit#(32) pixelq = {xdata[3],xdata[2],xdata[1],xdata[0]};
|
if(chromaFlag==0)
|
if(chromaFlag==0)
|
outfifo.enq(DFBLuma {ver:{currMbVer,blockVer,pixelVer},hor:{currMbHorT,blockHor},data:pixelq});
|
outfifo.enq(DFBLuma {ver:{currMbVer,blockVer,pixelVer},hor:{currMbHorT,blockHor},data:pixelq});
|
else
|
else
|
outfifo.enq(DFBChroma {uv:blockHor[1],ver:{currMbVer,blockVer[0],pixelVer},hor:{currMbHorT,blockHor[0]},data:pixelq});
|
outfifo.enq(DFBChroma {uv:blockHor[1],ver:{currMbVer,blockVer[0],pixelVer},hor:{currMbHorT,blockHor[0]},data:pixelq});
|
if(pixelNum == 12)
|
if(pixelNum == 12)
|
begin
|
begin
|
pixelNum <= 0;
|
pixelNum <= 0;
|
if(blockNum == 15)
|
if(blockNum == 15)
|
begin
|
begin
|
blockNum <= 0;
|
blockNum <= 0;
|
chromaFlag <= 1;
|
chromaFlag <= 1;
|
end
|
end
|
else if(blockNum==7 && chromaFlag==1)
|
else if(blockNum==7 && chromaFlag==1)
|
begin
|
begin
|
blockNum <= 0;
|
blockNum <= 0;
|
chromaFlag <= 0;
|
chromaFlag <= 0;
|
currMb <= currMb+1;
|
currMb <= currMb+1;
|
currMbHor <= currMbHor+1;
|
currMbHor <= currMbHor+1;
|
if(currMbVer==picHeight-1 && currMbHor==zeroExtend(picWidth-1))
|
if(currMbVer==picHeight-1 && currMbHor==zeroExtend(picWidth-1))
|
endOfFrame <= True;
|
endOfFrame <= True;
|
end
|
end
|
else
|
else
|
blockNum <= blockNum+1;
|
blockNum <= blockNum+1;
|
end
|
end
|
else
|
else
|
pixelNum <= pixelNum+4;
|
pixelNum <= pixelNum+4;
|
//$display( "Trace Deblocking Filter: passing PBoutput %h %h %h %h", blockNum, pixelNum, pixelHor, xdata);
|
//$display( "Trace Deblocking Filter: passing PBoutput %h %h %h %h", blockNum, pixelNum, pixelHor, xdata);
|
end
|
end
|
tagged EndOfFile :
|
tagged EndOfFile :
|
begin
|
begin
|
infifo.deq();
|
infifo.deq();
|
outfifo.enq(EDOT infifo.first());
|
outfifo.enq(EDOT infifo.first());
|
$display( "ccl5: EndOfFile reached");
|
$display( "ccl5: EndOfFile reached");
|
//$finish(0);
|
//$finish(0);
|
end
|
end
|
default:
|
default:
|
begin
|
begin
|
infifo.deq();
|
infifo.deq();
|
outfifo.enq(EDOT infifo.first());
|
outfifo.enq(EDOT infifo.first());
|
end
|
end
|
endcase
|
endcase
|
endrule
|
endrule
|
|
|
|
|
rule currMbHorUpdate( !(currMbHor
|
rule currMbHorUpdate( !(currMbHor
|
Bit#(PicAreaSz) temp = zeroExtend(picWidth);
|
Bit#(PicAreaSz) temp = zeroExtend(picWidth);
|
if((currMbHor >> 3) >= temp)
|
if((currMbHor >> 3) >= temp)
|
begin
|
begin
|
currMbHor <= currMbHor - (temp << 3);
|
currMbHor <= currMbHor - (temp << 3);
|
currMbVer <= currMbVer + 8;
|
currMbVer <= currMbVer + 8;
|
end
|
end
|
else
|
else
|
begin
|
begin
|
currMbHor <= currMbHor - temp;
|
currMbHor <= currMbHor - temp;
|
currMbVer <= currMbVer + 1;
|
currMbVer <= currMbVer + 1;
|
end
|
end
|
//$display( "Trace Deblocking Filter: currMbHorUpdate %h %h", currMbHor, currMbVer);
|
//$display( "Trace Deblocking Filter: currMbHorUpdate %h %h", currMbHor, currMbVer);
|
endrule
|
endrule
|
|
|
|
|
rule outputEndOfFrame(endOfFrame);
|
rule outputEndOfFrame(endOfFrame);
|
outfifo.enq(EndOfFrame);
|
outfifo.enq(EndOfFrame);
|
endOfFrame <= False;
|
endOfFrame <= False;
|
//$display( "Trace Deblocking Filter: outputEndOfFrame %h", pack(infifo.first()));
|
//$display( "Trace Deblocking Filter: outputEndOfFrame %h", pack(infifo.first()));
|
endrule
|
endrule
|
|
|
|
|
interface Client mem_client_data;
|
interface Client mem_client_data;
|
interface Get request = fifoToGet(dataMemReqQ);
|
interface Get request = fifoToGet(dataMemReqQ);
|
interface Put response = fifoToPut(dataMemRespQ);
|
interface Put response = fifoToPut(dataMemRespQ);
|
endinterface
|
endinterface
|
|
|
interface Client mem_client_parameter;
|
interface Client mem_client_parameter;
|
interface Get request = fifoToGet(parameterMemReqQ);
|
interface Get request = fifoToGet(parameterMemReqQ);
|
interface Put response = fifoToPut(parameterMemRespQ);
|
interface Put response = fifoToPut(parameterMemRespQ);
|
endinterface
|
endinterface
|
|
|
interface Put ioin = fifoToPut(infifo);
|
interface Put ioin = fifoToPut(infifo);
|
interface Get ioout = fifoToGet(outfifo);
|
interface Get ioout = fifoToGet(outfifo);
|
|
|
endmodule
|
endmodule
|
|
|
endpackage
|
endpackage
|
|
|