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

Subversion Repositories bluespec-h264

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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