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

Subversion Repositories bluespec-h264

[/] [bluespec-h264/] [trunk/] [src_fpga/] [mkNalUnwrap.bsv] - Blame information for rev 100

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 83 jamey.hick
 
2
// The MIT License
3
 
4
// Copyright (c) 2006-2007 Massachusetts Institute of Technology
5
 
6
// Permission is hereby granted, free of charge, to any person obtaining a copy
7
// of this software and associated documentation files (the "Software"), to deal
8
// in the Software without restriction, including without limitation the rights
9
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
// copies of the Software, and to permit persons to whom the Software is
11
// furnished to do so, subject to the following conditions:
12
 
13
// The above copyright notice and this permission notice shall be included in
14
// all copies or substantial portions of the Software.
15
 
16
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
// THE SOFTWARE.
23
 
24 3 jamey.hick
//**********************************************************************
25
// NAL unit unwrapper implementation
26
//----------------------------------------------------------------------
27
//
28
//
29
 
30
package mkNalUnwrap;
31
 
32
import H264Types::*;
33
import INalUnwrap::*;
34
import FIFO::*;
35
 
36
import Connectable::*;
37
import GetPut::*;
38
 
39
 
40
 
41
//-----------------------------------------------------------
42
// NAL Unwrapper Module
43
//-----------------------------------------------------------
44
 
45
module mkNalUnwrap( INalUnwrap );
46
 
47
   FIFO#(InputGenOT)  infifo    <- mkFIFO;
48
   FIFO#(NalUnwrapOT) outfifo   <- mkFIFO;
49
   Reg#(Bit#(8))      buffera   <- mkReg(0);
50
   Reg#(Bit#(8))      bufferb   <- mkReg(0);
51
   Reg#(Bit#(8))      bufferc   <- mkReg(0);
52
   Reg#(Bit#(2))      bufcount  <- mkReg(0);
53
   Reg#(Bit#(27))     zerocount <- mkReg(0);
54
 
55
 
56
   //-----------------------------------------------------------
57
   // Rules
58
   rule fillbuffer (bufcount<3
59
                    &&& infifo.first() matches tagged DataByte .dbyte);
60
      bufferc  <= bufferb;
61
      bufferb  <= buffera;
62
      buffera  <= dbyte;
63
      bufcount <= bufcount+1;
64
      infifo.deq();
65
   endrule
66
 
67
   rule newnalunit (bufcount==3
68
                    &&& infifo.first() matches tagged DataByte .dbyte
69
                    &&& ((bufferc==0 && bufferb==0 && buffera==1)
70
                         || (bufferc==0 && bufferb==0 && buffera==0 && dbyte==1)));
71
      zerocount <= 0;
72
      if(bufferc==0 && bufferb==0 && buffera==1)
73
         bufcount <= 0;
74
      else
75
         begin
76
            bufcount <= 0;
77
            infifo.deq();
78
         end
79
      outfifo.enq(NewUnit);
80
      $display("ccl1newunit");
81
   endrule
82
 
83
   rule remove3byte (bufcount==3
84
                     &&& infifo.first() matches tagged DataByte .dbyte
85
                     &&& (bufferc==0 && bufferb==0 && buffera==3 && dbyte<4));
86
      zerocount <= zerocount+2;
87
      bufcount  <= 0;
88
   endrule
89
 
90
   rule normalop (bufcount==3
91
                  &&& infifo.first() matches tagged DataByte .dbyte
92
                  &&& !(bufferc==0 && bufferb==0 && buffera==3 && dbyte<4)
93
                  &&& !((bufferc==0 && bufferb==0 && buffera==1)
94
                        || (bufferc==0 && bufferb==0 && buffera==0 && dbyte==1)));
95
      if(bufferc==0)
96
         begin
97
            zerocount <= zerocount+1;
98
            bufferc  <= bufferb;
99
            bufferb  <= buffera;
100
            buffera  <= dbyte;
101
            infifo.deq();
102
         end
103
      else if(zerocount==0)
104
         begin
105 13 jamey.hick
            outfifo.enq(RbspByte (bufferc));
106 3 jamey.hick
            $display("ccl1rbspbyte %h", bufferc);
107
            bufferc  <= bufferb;
108
            bufferb  <= buffera;
109
            buffera  <= dbyte;
110
            infifo.deq();
111
         end
112
      else
113
         begin
114
            zerocount <= zerocount-1;
115 13 jamey.hick
            outfifo.enq(RbspByte (0));
116 3 jamey.hick
            $display("ccl1rbspbyte 00");
117
         end
118
   endrule
119
 
120
   rule endfileop(infifo.first() matches tagged EndOfFile);
121
      case ( bufcount )
122
         3:
123
         begin
124
            if(bufferc==0 && bufferb==0 && buffera<4)
125
               begin
126
                  bufcount  <= 0;
127
                  zerocount <= 0;
128
               end
129
            else if(zerocount==0)
130
               begin
131
                  bufcount <= 2;
132 13 jamey.hick
                  outfifo.enq(RbspByte (bufferc));
133 3 jamey.hick
                  $display("ccl1rbspbyte %h", bufferc);
134
               end
135
            else
136
               begin
137
                  zerocount <= zerocount-1;
138 13 jamey.hick
                  outfifo.enq(RbspByte (0));
139 3 jamey.hick
                  $display("ccl1rbspbyte 00");
140
               end
141
         end
142
         2:
143
         begin
144
            bufcount  <= 1;
145
            if(!(bufferb==0 && buffera==0))
146 13 jamey.hick
               outfifo.enq(RbspByte (bufferb));
147 3 jamey.hick
               $display("ccl1rbspbyte %h", bufferb);
148
         end
149
         1:
150
         begin
151
            bufcount  <= 0;
152
            if(!(buffera==0))
153 13 jamey.hick
               outfifo.enq(RbspByte (buffera));
154 3 jamey.hick
               $display("ccl1rbspbyte %h", buffera);
155
         end
156
         0:
157
         begin
158
            infifo.deq();
159
            outfifo.enq(EndOfFile);
160
            $display("EndOfFile reached (NalUnwrap)");
161
         end
162
      endcase
163
 
164
   endrule
165
 
166
 
167
   interface Put ioin  = fifoToPut(infifo);
168
   interface Get ioout = fifoToGet(outfifo);
169
 
170
endmodule
171
 
172
endpackage

powered by: WebSVN 2.1.0

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