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

Subversion Repositories bluespec-h264

[/] [bluespec-h264/] [trunk/] [src/] [mkNalUnwrap.bsv] - Blame information for rev 62

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jamey.hick
//**********************************************************************
2
// NAL unit unwrapper implementation
3
//----------------------------------------------------------------------
4
//
5
//
6
 
7
package mkNalUnwrap;
8
 
9
import H264Types::*;
10
import INalUnwrap::*;
11
import FIFO::*;
12
 
13
import Connectable::*;
14
import GetPut::*;
15
 
16
 
17
 
18
//-----------------------------------------------------------
19
// NAL Unwrapper Module
20
//-----------------------------------------------------------
21
 
22
module mkNalUnwrap( INalUnwrap );
23
 
24
   FIFO#(InputGenOT)  infifo    <- mkFIFO;
25
   FIFO#(NalUnwrapOT) outfifo   <- mkFIFO;
26
   Reg#(Bit#(8))      buffera   <- mkReg(0);
27
   Reg#(Bit#(8))      bufferb   <- mkReg(0);
28
   Reg#(Bit#(8))      bufferc   <- mkReg(0);
29
   Reg#(Bit#(2))      bufcount  <- mkReg(0);
30
   Reg#(Bit#(27))     zerocount <- mkReg(0);
31
 
32
 
33
   //-----------------------------------------------------------
34
   // Rules
35
   rule fillbuffer (bufcount<3
36
                    &&& infifo.first() matches tagged DataByte .dbyte);
37
      bufferc  <= bufferb;
38
      bufferb  <= buffera;
39
      buffera  <= dbyte;
40
      bufcount <= bufcount+1;
41
      infifo.deq();
42
   endrule
43
 
44
   rule newnalunit (bufcount==3
45
                    &&& infifo.first() matches tagged DataByte .dbyte
46
                    &&& ((bufferc==0 && bufferb==0 && buffera==1)
47
                         || (bufferc==0 && bufferb==0 && buffera==0 && dbyte==1)));
48
      zerocount <= 0;
49
      if(bufferc==0 && bufferb==0 && buffera==1)
50
         bufcount <= 0;
51
      else
52
         begin
53
            bufcount <= 0;
54
            infifo.deq();
55
         end
56
      outfifo.enq(NewUnit);
57
      $display("ccl1newunit");
58
   endrule
59
 
60
   rule remove3byte (bufcount==3
61
                     &&& infifo.first() matches tagged DataByte .dbyte
62
                     &&& (bufferc==0 && bufferb==0 && buffera==3 && dbyte<4));
63
      zerocount <= zerocount+2;
64
      bufcount  <= 0;
65
   endrule
66
 
67
   rule normalop (bufcount==3
68
                  &&& infifo.first() matches tagged DataByte .dbyte
69
                  &&& !(bufferc==0 && bufferb==0 && buffera==3 && dbyte<4)
70
                  &&& !((bufferc==0 && bufferb==0 && buffera==1)
71
                        || (bufferc==0 && bufferb==0 && buffera==0 && dbyte==1)));
72
      if(bufferc==0)
73
         begin
74
            zerocount <= zerocount+1;
75
            bufferc  <= bufferb;
76
            bufferb  <= buffera;
77
            buffera  <= dbyte;
78
            infifo.deq();
79
         end
80
      else if(zerocount==0)
81
         begin
82 62 jamey.hick
            outfifo.enq(tagged RbspByte bufferc);
83 2 jamey.hick
            $display("ccl1rbspbyte %h", bufferc);
84
            bufferc  <= bufferb;
85
            bufferb  <= buffera;
86
            buffera  <= dbyte;
87
            infifo.deq();
88
         end
89
      else
90
         begin
91
            zerocount <= zerocount-1;
92 62 jamey.hick
            outfifo.enq(tagged RbspByte 0);
93 2 jamey.hick
            $display("ccl1rbspbyte 00");
94
         end
95
   endrule
96
 
97
   rule endfileop(infifo.first() matches tagged EndOfFile);
98
      case ( bufcount )
99
         3:
100
         begin
101
            if(bufferc==0 && bufferb==0 && buffera<4)
102
               begin
103
                  bufcount  <= 0;
104
                  zerocount <= 0;
105
               end
106
            else if(zerocount==0)
107
               begin
108
                  bufcount <= 2;
109 62 jamey.hick
                  outfifo.enq(tagged RbspByte bufferc);
110 2 jamey.hick
                  $display("ccl1rbspbyte %h", bufferc);
111
               end
112
            else
113
               begin
114
                  zerocount <= zerocount-1;
115 62 jamey.hick
                  outfifo.enq(tagged RbspByte 0);
116 2 jamey.hick
                  $display("ccl1rbspbyte 00");
117
               end
118
         end
119
         2:
120
         begin
121
            bufcount  <= 1;
122
            if(!(bufferb==0 && buffera==0))
123 62 jamey.hick
               outfifo.enq(tagged RbspByte bufferb);
124 2 jamey.hick
               $display("ccl1rbspbyte %h", bufferb);
125
         end
126
         1:
127
         begin
128
            bufcount  <= 0;
129
            if(!(buffera==0))
130 62 jamey.hick
               outfifo.enq(tagged RbspByte buffera);
131 2 jamey.hick
               $display("ccl1rbspbyte %h", buffera);
132
         end
133
         0:
134
         begin
135
            infifo.deq();
136
            outfifo.enq(EndOfFile);
137
            $display("EndOfFile reached (NalUnwrap)");
138
         end
139
      endcase
140
 
141
   endrule
142
 
143
 
144
   interface Put ioin  = fifoToPut(infifo);
145
   interface Get ioout = fifoToGet(outfifo);
146
 
147
endmodule
148
 
149
endpackage

powered by: WebSVN 2.1.0

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