OpenCores
URL https://opencores.org/ocsvn/bluespec-h264/bluespec-h264/trunk

Subversion Repositories bluespec-h264

[/] [bluespec-h264/] [trunk/] [release/] [mkNalUnwrap.bsv] - Diff between revs 85 and 100

Only display areas with differences | Details | Blame | View Log

Rev 85 Rev 100
// 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.
//**********************************************************************
//**********************************************************************
// NAL unit unwrapper implementation
// NAL unit unwrapper implementation
//----------------------------------------------------------------------
//----------------------------------------------------------------------
//
//
//
//
package mkNalUnwrap;
package mkNalUnwrap;
import H264Types::*;
import H264Types::*;
import INalUnwrap::*;
import INalUnwrap::*;
import FIFO::*;
import FIFO::*;
import Connectable::*;
import Connectable::*;
import GetPut::*;
import GetPut::*;
//-----------------------------------------------------------
//-----------------------------------------------------------
// NAL Unwrapper Module
// NAL Unwrapper Module
//-----------------------------------------------------------
//-----------------------------------------------------------
module mkNalUnwrap( INalUnwrap );
module mkNalUnwrap( INalUnwrap );
   FIFO#(InputGenOT)  infifo    <- mkFIFO;
   FIFO#(InputGenOT)  infifo    <- mkFIFO;
   FIFO#(NalUnwrapOT) outfifo   <- mkFIFO;
   FIFO#(NalUnwrapOT) outfifo   <- mkFIFO;
   Reg#(Bit#(8))      buffera   <- mkReg(0);
   Reg#(Bit#(8))      buffera   <- mkReg(0);
   Reg#(Bit#(8))      bufferb   <- mkReg(0);
   Reg#(Bit#(8))      bufferb   <- mkReg(0);
   Reg#(Bit#(8))      bufferc   <- mkReg(0);
   Reg#(Bit#(8))      bufferc   <- mkReg(0);
   Reg#(Bit#(2))      bufcount  <- mkReg(0);
   Reg#(Bit#(2))      bufcount  <- mkReg(0);
   Reg#(Bit#(27))     zerocount <- mkReg(0);
   Reg#(Bit#(27))     zerocount <- mkReg(0);
   //-----------------------------------------------------------
   //-----------------------------------------------------------
   // Rules
   // Rules
   rule fillbuffer (bufcount<3
   rule fillbuffer (bufcount<3
                    &&& infifo.first() matches tagged DataByte .dbyte);
                    &&& infifo.first() matches tagged DataByte .dbyte);
      bufferc  <= bufferb;
      bufferc  <= bufferb;
      bufferb  <= buffera;
      bufferb  <= buffera;
      buffera  <= dbyte;
      buffera  <= dbyte;
      bufcount <= bufcount+1;
      bufcount <= bufcount+1;
      infifo.deq();
      infifo.deq();
   endrule
   endrule
   rule newnalunit (bufcount==3
   rule newnalunit (bufcount==3
                    &&& infifo.first() matches tagged DataByte .dbyte
                    &&& infifo.first() matches tagged DataByte .dbyte
                    &&& ((bufferc==0 && bufferb==0 && buffera==1)
                    &&& ((bufferc==0 && bufferb==0 && buffera==1)
                         || (bufferc==0 && bufferb==0 && buffera==0 && dbyte==1)));
                         || (bufferc==0 && bufferb==0 && buffera==0 && dbyte==1)));
      zerocount <= 0;
      zerocount <= 0;
      if(bufferc==0 && bufferb==0 && buffera==1)
      if(bufferc==0 && bufferb==0 && buffera==1)
         bufcount <= 0;
         bufcount <= 0;
      else
      else
         begin
         begin
            bufcount <= 0;
            bufcount <= 0;
            infifo.deq();
            infifo.deq();
         end
         end
      outfifo.enq(NewUnit);
      outfifo.enq(NewUnit);
      $display("ccl1newunit");
      $display("ccl1newunit");
   endrule
   endrule
   rule remove3byte (bufcount==3
   rule remove3byte (bufcount==3
                     &&& infifo.first() matches tagged DataByte .dbyte
                     &&& infifo.first() matches tagged DataByte .dbyte
                     &&& (bufferc==0 && bufferb==0 && buffera==3 && dbyte<4));
                     &&& (bufferc==0 && bufferb==0 && buffera==3 && dbyte<4));
      zerocount <= zerocount+2;
      zerocount <= zerocount+2;
      bufcount  <= 0;
      bufcount  <= 0;
   endrule
   endrule
   rule normalop (bufcount==3
   rule normalop (bufcount==3
                  &&& infifo.first() matches tagged DataByte .dbyte
                  &&& infifo.first() matches tagged DataByte .dbyte
                  &&& !(bufferc==0 && bufferb==0 && buffera==3 && dbyte<4)
                  &&& !(bufferc==0 && bufferb==0 && buffera==3 && dbyte<4)
                  &&& !((bufferc==0 && bufferb==0 && buffera==1)
                  &&& !((bufferc==0 && bufferb==0 && buffera==1)
                        || (bufferc==0 && bufferb==0 && buffera==0 && dbyte==1)));
                        || (bufferc==0 && bufferb==0 && buffera==0 && dbyte==1)));
      if(bufferc==0)
      if(bufferc==0)
         begin
         begin
            zerocount <= zerocount+1;
            zerocount <= zerocount+1;
            bufferc  <= bufferb;
            bufferc  <= bufferb;
            bufferb  <= buffera;
            bufferb  <= buffera;
            buffera  <= dbyte;
            buffera  <= dbyte;
            infifo.deq();
            infifo.deq();
         end
         end
      else if(zerocount==0)
      else if(zerocount==0)
         begin
         begin
            outfifo.enq(tagged RbspByte bufferc);
            outfifo.enq(tagged RbspByte bufferc);
            $display("ccl1rbspbyte %h", bufferc);
            $display("ccl1rbspbyte %h", bufferc);
            bufferc  <= bufferb;
            bufferc  <= bufferb;
            bufferb  <= buffera;
            bufferb  <= buffera;
            buffera  <= dbyte;
            buffera  <= dbyte;
            infifo.deq();
            infifo.deq();
         end
         end
      else
      else
         begin
         begin
            zerocount <= zerocount-1;
            zerocount <= zerocount-1;
            outfifo.enq(tagged RbspByte 0);
            outfifo.enq(tagged RbspByte 0);
            $display("ccl1rbspbyte 00");
            $display("ccl1rbspbyte 00");
         end
         end
   endrule
   endrule
   rule endfileop(infifo.first() matches tagged EndOfFile);
   rule endfileop(infifo.first() matches tagged EndOfFile);
      case ( bufcount )
      case ( bufcount )
         3:
         3:
         begin
         begin
            if(bufferc==0 && bufferb==0 && buffera<4)
            if(bufferc==0 && bufferb==0 && buffera<4)
               begin
               begin
                  bufcount  <= 0;
                  bufcount  <= 0;
                  zerocount <= 0;
                  zerocount <= 0;
               end
               end
            else if(zerocount==0)
            else if(zerocount==0)
               begin
               begin
                  bufcount <= 2;
                  bufcount <= 2;
                  outfifo.enq(tagged RbspByte bufferc);
                  outfifo.enq(tagged RbspByte bufferc);
                  $display("ccl1rbspbyte %h", bufferc);
                  $display("ccl1rbspbyte %h", bufferc);
               end
               end
            else
            else
               begin
               begin
                  zerocount <= zerocount-1;
                  zerocount <= zerocount-1;
                  outfifo.enq(tagged RbspByte 0);
                  outfifo.enq(tagged RbspByte 0);
                  $display("ccl1rbspbyte 00");
                  $display("ccl1rbspbyte 00");
               end
               end
         end
         end
         2:
         2:
         begin
         begin
            bufcount  <= 1;
            bufcount  <= 1;
            if(!(bufferb==0 && buffera==0))
            if(!(bufferb==0 && buffera==0))
               outfifo.enq(tagged RbspByte bufferb);
               outfifo.enq(tagged RbspByte bufferb);
               $display("ccl1rbspbyte %h", bufferb);
               $display("ccl1rbspbyte %h", bufferb);
         end
         end
         1:
         1:
         begin
         begin
            bufcount  <= 0;
            bufcount  <= 0;
            if(!(buffera==0))
            if(!(buffera==0))
               outfifo.enq(tagged RbspByte buffera);
               outfifo.enq(tagged RbspByte buffera);
               $display("ccl1rbspbyte %h", buffera);
               $display("ccl1rbspbyte %h", buffera);
         end
         end
         0:
         0:
         begin
         begin
            infifo.deq();
            infifo.deq();
            outfifo.enq(tagged EndOfFile);
            outfifo.enq(tagged EndOfFile);
            $display("EndOfFile reached (NalUnwrap)");
            $display("EndOfFile reached (NalUnwrap)");
         end
         end
      endcase
      endcase
   endrule
   endrule
   interface Put ioin  = fifoToPut(infifo);
   interface Put ioin  = fifoToPut(infifo);
   interface Get ioout = fifoToGet(outfifo);
   interface Get ioout = fifoToGet(outfifo);
endmodule
endmodule
endpackage
endpackage
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.