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

Subversion Repositories bluespec-h264

[/] [bluespec-h264/] [trunk/] [src_fpga/] [mkEntropyDec.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
// Entropy Decoder implementation
26
//----------------------------------------------------------------------
27
//
28
//
29
 
30
package mkEntropyDec;
31
 
32
import H264Types::*;
33
import ExpGolomb::*;
34
import CAVLC::*;
35
import ICalc_nC::*;
36
import mkCalc_nC::*;
37
import IEntropyDec::*;
38
import FIFO::*;
39
 
40
import Connectable::*;
41
import GetPut::*;
42
import ClientServer::*;
43
 
44
import IFPGA_FIFO::*;
45
import mkSizedFIFO_fpga::*;
46
 
47
 
48
//-----------------------------------------------------------
49
// Local Datatypes
50
//-----------------------------------------------------------
51
 
52
typedef union tagged
53
{
54
 void     Start;            //special state that initializes the process.
55
 void     NewUnit;          //special state that checks the NAL unit type.
56
 
57
 Bit#(5)  CodedSlice;       //decodes a type of NAL unit
58
 void     SEI;              //decodes a type of NAL unit
59
 Bit#(5)  SPS;              //decodes a type of NAL unit
60
 Bit#(5)  PPS;              //decodes a type of NAL unit
61
 void     AUD;              //decodes a type of NAL unit
62
 void     EndSequence;      //decodes a type of NAL unit
63
 void     EndStream;        //decodes a type of NAL unit
64
 void     Filler;           //decodes a type of NAL unit
65
 
66
 Bit#(5)  SliceData;        //decodes slice data (part of a CodedSlice NAL unit)
67
 Bit#(5)  MacroblockLayer;  //decodes macroblock layer (part of a CodedSlice NAL unit)
68
 Bit#(5)  MbPrediction;     //decodes macroblock prediction (part of a CodedSlice NAL unit)
69
 Bit#(5)  SubMbPrediction;  //decodes sub-macroblock prediction (part of a CodedSlice NAL unit)
70
 Bit#(5)  Residual;         //decodes residual (part of a CodedSlice NAL unit)
71
 Bit#(5)  ResidualBlock;    //decodes residual block (part of a CodedSlice NAL unit)
72
}
73
State deriving(Eq,Bits);
74
 
75
 
76
 
77
//-----------------------------------------------------------
78
// Helper functions
79
function MbType mbtype_convert( Bit#(5) in_mb_type, Bit#(4) in_slice_type );//converts mb_type syntax element to MbType type
80
   Bit#(5) tempmb = in_mb_type;
81
   if(in_slice_type == 2 || in_slice_type == 7)//I slice
82
      tempmb = in_mb_type+5;
83
   case ( tempmb )
84
      0: return P_L0_16x16;
85
      1: return P_L0_L0_16x8;
86
      2: return P_L0_L0_8x16;
87
      3: return P_8x8;
88
      4: return P_8x8ref0;
89
      5: return I_NxN;
90
      30: return I_PCM;
91
      default:
92
      begin
93
         Bit#(5) tempmb16x16 = tempmb-6;
94
         Bit#(2) tempv1 = tempmb16x16[1:0];
95
         Bit#(2) tempv2;
96
         Bit#(1) tempv3;
97
         if(tempmb16x16 < 12)
98
            begin
99
               tempv3 = 0;
100
               tempv2 = tempmb16x16[3:2];
101
            end
102
         else
103
            begin
104
               tempv3 = 1;
105
               tempv2 = tempmb16x16[3:2]+1;
106
            end
107
         return I_16x16{intra16x16PredMode:tempv1, codedBlockPatternChroma:tempv2, codedBlockPatternLuma:tempv3};
108
      end
109
   endcase
110
endfunction
111
 
112
 
113
 
114
//-----------------------------------------------------------
115
// Entropy Decoder Module
116
//-----------------------------------------------------------
117
 
118
 
119
(* synthesize *)
120
module mkEntropyDec( IEntropyDec );
121
 
122
   FIFO#(NalUnwrapOT)       infifo      <- mkSizedFIFO(entropyDec_infifo_size);
123
   FIFO#(EntropyDecOT)      outfifo     <- mkFIFO;
124
   FIFO#(EntropyDecOT_InverseTrans) outfifo_ITB <- mkFIFO;
125
   Reg#(State)              state       <- mkReg(Start);
126
   Reg#(Bit#(2))            nalrefidc   <- mkReg(0);
127
   Reg#(Bit#(5))            nalunittype <- mkReg(0);
128
   Reg#(Buffer)             buffer      <- mkReg(0);
129
   Reg#(Bufcount)           bufcount    <- mkReg(0);
130
 
131
   //saved syntax elements
132
   Reg#(Bit#(5))              spsseq_parameter_set_id                    <- mkReg(0);
133
   Reg#(Bit#(5))              spslog2_max_frame_num                      <- mkReg(0);
134
   Reg#(Bit#(5))              spslog2_max_pic_order_cnt_lsb              <- mkReg(0);
135
   Reg#(Bit#(2))              spspic_order_cnt_type                      <- mkReg(0);
136
   Reg#(Bit#(1))              spsdelta_pic_order_always_zero_flag        <- mkReg(0);
137
   Reg#(Bit#(8))              spsnum_ref_frames_in_pic_order_cnt_cycle   <- mkReg(0);
138
   Reg#(Bit#(8))              ppspic_parameter_set_id                    <- mkReg(0);
139
   Reg#(Bit#(1))              ppspic_order_present_flag                  <- mkReg(0);
140
   Reg#(Bit#(1))              ppsdeblocking_filter_control_present_flag  <- mkReg(0);
141
   Reg#(Bit#(4))              shslice_type                               <- mkReg(0);
142
   Reg#(Bit#(3))              shdmemory_management_control_operation     <- mkReg(0);
143
   Reg#(MbType)               sdmmbtype                                  <- mkReg(I_NxN);
144
   Reg#(Bit#(4))              sdmcodedBlockPatternLuma                   <- mkReg(0);
145
   Reg#(Bit#(2))              sdmcodedBlockPatternChroma                 <- mkReg(0);
146
   Reg#(Bit#(5))              sdmrTotalCoeff                             <- mkReg(0);
147
   Reg#(Bit#(2))              sdmrTrailingOnes                           <- mkReg(0);
148
 
149
   //derived decoding variables for slice data
150
   Reg#(Bit#(16))             tempreg                                    <- mkReg(0);
151
   Reg#(Bit#(5))              num_ref_idx_l0_active_minus1               <- mkReg(0);
152
   Reg#(Bit#(PicAreaSz))      currMbAddr                                 <- mkReg(0);
153
   Reg#(Bit#(3))              temp3bit0                                  <- mkReg(0);
154
   Reg#(Bit#(3))              temp3bit1                                  <- mkReg(0);
155
   Reg#(Bit#(3))              temp3bit2                                  <- mkReg(0);
156
   Reg#(Bit#(3))              temp3bit3                                  <- mkReg(0);
157
   Reg#(Bit#(5))              temp5bit                                   <- mkReg(0);
158
   Reg#(Bit#(5))              temp5bit2                                  <- mkReg(0);
159
   Reg#(Bit#(5))              maxNumCoeff                                <- mkReg(0);
160
   IFPGA_FIFO#(Bit#(13),16)            cavlcFIFO                                  <- mkSizedFIFO_fpga();
161
   Calc_nC                    calcnc                                     <- mkCalc_nC();
162
   Reg#(Bit#(1))              residualChroma                             <- mkReg(0);
163
   Reg#(Bit#(5))              totalCoeff                                 <- mkReg(0);
164
   Reg#(Bit#(4))              zerosLeft                                  <- mkReg(0);
165
 
166
   //exp-golomb 32-bit version states
167
   Reg#(Bufcount)             egnumbits                                  <- mkReg(0);
168
 
169
   //extra-buffering states
170
   Reg#(Bit#(32))             extrabuffer                                <- mkReg(0);
171
   Reg#(Bit#(3))              extrabufcount                              <- mkReg(0);
172
   Reg#(Bit#(1))              extraendnalflag                            <- mkReg(0);
173
   Reg#(Bit#(1))              endnalflag                                 <- mkReg(0);
174
 
175
 
176
   //-----------------------------------------------------------
177
   // Rules
178
 
179
   rule startup (state matches Start);
180
      case (infifo.first()) matches
181
         tagged NewUnit :
182
            begin
183
               infifo.deq();
184
               state <= NewUnit;
185
               buffer <= 0;
186
               bufcount <= 0;
187
               extrabuffer <= 0;
188
               extrabufcount <= 0;
189
               extraendnalflag <= 0;
190
               endnalflag <= 0;
191
            end
192
         tagged RbspByte .rdata :
193
            begin
194
               infifo.deq();
195
            end
196
         tagged EndOfFile :
197
            begin
198
               infifo.deq();
199
               outfifo.enq(EndOfFile);
200
               $display( "INFO EntropyDec: EndOfFile reached" );
201
            end
202
      endcase
203
   endrule
204
 
205
 
206
   rule newunit (state matches NewUnit);
207
      case (infifo.first()) matches
208
         tagged NewUnit : state <= Start;
209
         tagged RbspByte .rdata :
210
            begin
211
               infifo.deq();
212
               nalrefidc <= rdata[6:5];
213
               nalunittype <= rdata[4:0];
214
               case (rdata[4:0])
215 13 jamey.hick
                  1 : state <= tagged CodedSlice 0;
216
                  5 : state <= tagged CodedSlice 0;
217 3 jamey.hick
                  6 : state <= SEI;
218 13 jamey.hick
                  7 : state <= tagged SPS 0;
219
                  8 : state <= tagged PPS 0;
220 3 jamey.hick
                  9 : state <= AUD;
221
                  10: state <= EndSequence;
222
                  11: state <= EndStream;
223
                  12: state <= Filler;
224
                  default:
225
                  begin
226
                     $display( "ERROR EntropyDec: NAL Unit Type = %d", rdata[4:0] );
227
                     state <= Start;
228
                  end
229
               endcase
230
               $display("ccl2newunit");
231
               $display("ccl2rbspbyte %h", rdata);
232 13 jamey.hick
               outfifo.enq(tagged NewUnit rdata);
233
               outfifo_ITB.enq(tagged NewUnit rdata);
234 3 jamey.hick
            end
235
         tagged EndOfFile : state <= Start;
236
      endcase
237
   endrule
238
 
239
 
240
   rule fillextrabuffer (state != Start
241
                         && state != NewUnit
242
                         && extrabufcount < 4
243
                         && extraendnalflag == 0);
244
      if(infifo.first() matches tagged RbspByte .dbyte)
245
         begin
246
            case ( extrabufcount )
247
               0: extrabuffer <= {dbyte, extrabuffer[23:0]};
248
               1: extrabuffer <= {extrabuffer[31:24],{dbyte,extrabuffer[15:0]}};
249
               2: extrabuffer <= {extrabuffer[31:16],{dbyte,extrabuffer[7:0]}};
250
               3: extrabuffer <= {extrabuffer[31:8],dbyte};
251
               default: $display( "ERROR EntropyDec: fillextrabuffer default case_" );
252
            endcase
253
            extrabufcount <= extrabufcount + 1;
254
            infifo.deq();
255
            $display( "TRACE EntropyDec: fillextrabuffer RbspByte %h %h %h", dbyte, extrabufcount, extrabuffer);
256
         end
257
      else
258
         begin
259
            if(extrabufcount != 0)
260
               extraendnalflag <= 1;
261
            $display( "TRACE EntropyDec: fillextrabuffer else %h", extrabufcount);
262
         end
263
   endrule
264
 
265
 
266
   rule fillbuffer (state != Start
267
                    && state != NewUnit
268
                    && bufcount<=truncate(buffersize-32)
269
                    && (extrabufcount == 4 || extraendnalflag == 1)
270
                    && endnalflag == 0);//predicate not sure
271
      Buffer temp = zeroExtend(extrabuffer);
272
      Bufcount temp2 = truncate(buffersize)-bufcount-32;
273
      buffer <= (buffer | (temp << zeroExtend(temp2)));
274
      case ( extrabufcount )
275
         4: bufcount <= bufcount+32;
276
         3: bufcount <= bufcount+24;
277
         2: bufcount <= bufcount+16;
278
         1: bufcount <= bufcount+8;
279
         default: $display( "ERROR EntropyDec: fillbuffer default case" );
280
      endcase
281
      extrabuffer <= 0;
282
      extrabufcount <= 0;
283
      if(infifo.first()==NewUnit || infifo.first()==EndOfFile)
284
         endnalflag <= 1;
285
      $display( "TRACE EntropyDec: fillbuffer RbspByte %h %h %h %h %h %h %h %h", extrabufcount, bufcount, extrabuffer, temp, temp2, (temp << zeroExtend(temp2)), buffer, (buffer | (temp << zeroExtend(temp2))));
286
   endrule
287
 
288
 
289
   rule parser (state != Start
290
                &&& state != NewUnit
291
                &&& (bufcount > truncate(buffersize-32) || endnalflag == 1));//predicate not sure
292
      $display( "TRACE EntropyDec: fillbuffer RbspByte %h %h", bufcount, buffer );
293
 
294
      Bufcount numbitsused = 0;
295
      State nextstate = Start;
296
      Int#(16) tempint = 0;
297
      Int#(32) tempint32 = 0;
298
 
299
      case ( state ) matches
300
         tagged CodedSlice .step :
301
            begin
302
               case ( step )
303
                  0:
304
                  begin
305
                     $display( "ccl2SHfirst_mb_in_slice %0d", expgolomb_unsigned(buffer) );
306 13 jamey.hick
                     outfifo.enq(tagged SHfirst_mb_in_slice truncate(expgolomb_unsigned(buffer)));
307 3 jamey.hick
                     currMbAddr <= truncate(expgolomb_unsigned(buffer));
308
                     calcnc.initialize(truncate(expgolomb_unsigned(buffer)));
309
                     numbitsused = expgolomb_numbits(buffer);
310 13 jamey.hick
                     nextstate = tagged CodedSlice 1;
311 3 jamey.hick
                  end
312
                  1:
313
                  begin
314
                     $display( "ccl2SHslice_type %0d", expgolomb_unsigned(buffer) );
315 13 jamey.hick
                     outfifo.enq(tagged SHslice_type truncate(expgolomb_unsigned(buffer)));
316 3 jamey.hick
                     shslice_type <= truncate(expgolomb_unsigned(buffer));
317
                     numbitsused = expgolomb_numbits(buffer);
318 13 jamey.hick
                     nextstate = tagged CodedSlice 2;
319 3 jamey.hick
                  end
320
                  2:
321
                  begin
322
                     $display( "ccl2SHpic_parameter_set_id %0d", expgolomb_unsigned(buffer) );
323 13 jamey.hick
                     outfifo.enq(tagged SHpic_parameter_set_id truncate(expgolomb_unsigned(buffer)));
324 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
325 13 jamey.hick
                     nextstate = tagged CodedSlice 3;
326 3 jamey.hick
                     if(ppspic_parameter_set_id != truncate(expgolomb_unsigned(buffer))) $display( "ERROR EntropyDec: pic_parameter_set_id don't match" );
327
                  end
328
                  3:
329
                  begin
330
                     Bit#(16) tttt = buffer[buffersize-1:buffersize-16];
331
                     tttt = tttt >> 16 - zeroExtend(spslog2_max_frame_num);
332
                     $display( "ccl2SHframe_num %0d", tttt );
333 13 jamey.hick
                     outfifo.enq(tagged SHframe_num tttt);
334 3 jamey.hick
                     numbitsused = zeroExtend(spslog2_max_frame_num);
335 13 jamey.hick
                     nextstate = tagged CodedSlice 4;
336 3 jamey.hick
                  end
337
                  4:
338
                  begin
339
                     if(nalunittype == 5)
340
                        begin
341
                           $display( "ccl2SHidr_pic_id %0d", expgolomb_unsigned(buffer) );
342 13 jamey.hick
                           outfifo.enq(tagged SHidr_pic_id truncate(expgolomb_unsigned(buffer)));
343 3 jamey.hick
                           numbitsused = expgolomb_numbits(buffer);
344
                        end
345 13 jamey.hick
                     nextstate = tagged CodedSlice 5;
346 3 jamey.hick
                  end
347
                  5:
348
                  begin
349
                     if(spspic_order_cnt_type == 0)
350
                        begin
351
                           Bit#(16) tttt = buffer[buffersize-1:buffersize-16];
352
                           tttt = tttt >> 16 - zeroExtend(spslog2_max_pic_order_cnt_lsb);
353
                           $display( "ccl2SHpic_order_cnt_lsb %0d", tttt );
354 13 jamey.hick
                           outfifo.enq(tagged SHpic_order_cnt_lsb tttt);
355 3 jamey.hick
                           numbitsused = zeroExtend(spslog2_max_pic_order_cnt_lsb);
356 13 jamey.hick
                           nextstate = tagged CodedSlice 6;
357 3 jamey.hick
                        end
358
                     else
359 13 jamey.hick
                        nextstate = tagged CodedSlice 7;
360 3 jamey.hick
                  end
361
                  6:
362
                  begin
363
                     if(ppspic_order_present_flag == 1)
364
                        begin
365
                           if(egnumbits == 0)
366
                              begin
367
                                 Bufcount tempbufcount = expgolomb_numbits32(buffer);
368
                                 egnumbits <= tempbufcount;
369
                                 numbitsused = tempbufcount-1;
370 13 jamey.hick
                                 nextstate = tagged CodedSlice 6;
371 3 jamey.hick
                              end
372
                           else
373
                              begin
374
                                 tempint32 = unpack(expgolomb_signed32(buffer,egnumbits));
375
                                 $display( "ccl2SHdelta_pic_order_cnt_bottom %0d", tempint32 );
376 13 jamey.hick
                                 outfifo.enq(tagged SHdelta_pic_order_cnt_bottom truncate(expgolomb_signed32(buffer,egnumbits)));
377 3 jamey.hick
                                 egnumbits <= 0;
378
                                 numbitsused = egnumbits;
379 13 jamey.hick
                                 nextstate = tagged CodedSlice 7;
380 3 jamey.hick
                              end
381
                        end
382
                     else
383 13 jamey.hick
                        nextstate = tagged CodedSlice 7;
384 3 jamey.hick
                  end
385
                  7:
386
                  begin
387
                     if(spspic_order_cnt_type == 1 && spsdelta_pic_order_always_zero_flag == 0)
388
                        begin
389
                           if(egnumbits == 0)
390
                              begin
391
                                 Bufcount tempbufcount = expgolomb_numbits32(buffer);
392
                                 egnumbits <= tempbufcount;
393
                                 numbitsused = tempbufcount-1;
394 13 jamey.hick
                                 nextstate = tagged CodedSlice 7;
395 3 jamey.hick
                              end
396
                           else
397
                              begin
398
                                 tempint32 = unpack(expgolomb_signed32(buffer,egnumbits));
399
                                 $display( "ccl2SHdelta_pic_order_cnt0 %0d", tempint32 );
400 13 jamey.hick
                                 outfifo.enq(tagged SHdelta_pic_order_cnt0 truncate(expgolomb_signed32(buffer,egnumbits)));
401 3 jamey.hick
                                 egnumbits <= 0;
402
                                 numbitsused = egnumbits;
403 13 jamey.hick
                                 nextstate = tagged CodedSlice 8;
404 3 jamey.hick
                              end
405
                        end
406
                     else
407 13 jamey.hick
                        nextstate = tagged CodedSlice 9;
408 3 jamey.hick
                  end
409
                  8:
410
                  begin
411
                     if(ppspic_order_present_flag == 1)
412
                        begin
413
                           if(egnumbits == 0)
414
                              begin
415
                                 Bufcount tempbufcount = expgolomb_numbits32(buffer);
416
                                 egnumbits <= tempbufcount;
417
                                 numbitsused = tempbufcount-1;
418 13 jamey.hick
                                 nextstate = tagged CodedSlice 8;
419 3 jamey.hick
                              end
420
                           else
421
                              begin
422
                                 tempint32 = unpack(expgolomb_signed32(buffer,egnumbits));
423
                                 $display( "ccl2SHdelta_pic_order_cnt1 %0d", tempint32 );
424 13 jamey.hick
                                 outfifo.enq(tagged SHdelta_pic_order_cnt1 truncate(expgolomb_signed32(buffer,egnumbits)));
425 3 jamey.hick
                                 egnumbits <= 0;
426
                                 numbitsused = egnumbits;
427 13 jamey.hick
                                 nextstate = tagged CodedSlice 9;
428 3 jamey.hick
                              end
429
                        end
430
                     else
431 13 jamey.hick
                        nextstate = tagged CodedSlice 9;
432 3 jamey.hick
                  end
433
                  9:
434
                  begin
435
                     if(shslice_type == 0 || shslice_type == 5)
436
                        begin
437
                           $display( "ccl2SHnum_ref_idx_active_override_flag %0d", buffer[buffersize-1] );
438 13 jamey.hick
                           outfifo.enq(tagged SHnum_ref_idx_active_override_flag buffer[buffersize-1]);
439 3 jamey.hick
                           numbitsused = 1;
440
                           if(buffer[buffersize-1] == 1)
441 13 jamey.hick
                              nextstate = tagged CodedSlice 10;
442 3 jamey.hick
                           else
443 13 jamey.hick
                              nextstate = tagged CodedSlice 11;
444 3 jamey.hick
                        end
445
                     else
446 13 jamey.hick
                        nextstate = tagged CodedSlice 11;
447 3 jamey.hick
                  end
448
                  10:
449
                  begin
450
                     $display( "ccl2SHnum_ref_idx_l0_active %0d", expgolomb_unsigned(buffer)+1 );
451 13 jamey.hick
                     outfifo.enq(tagged SHnum_ref_idx_l0_active truncate(expgolomb_unsigned(buffer)+1));
452 3 jamey.hick
                     num_ref_idx_l0_active_minus1 <= truncate(expgolomb_unsigned(buffer));
453
                     numbitsused = expgolomb_numbits(buffer);
454 13 jamey.hick
                     nextstate = tagged CodedSlice 11;
455 3 jamey.hick
                  end
456
                  11:
457
                  begin
458
                     if(shslice_type != 2 && shslice_type != 7)
459
                        begin
460
                           $display( "ccl2SHRref_pic_list_reordering_flag_l0 %0d", buffer[buffersize-1] );
461 13 jamey.hick
                           outfifo.enq(tagged SHRref_pic_list_reordering_flag_l0 buffer[buffersize-1]);
462 3 jamey.hick
                           numbitsused = 1;
463
                           if(buffer[buffersize-1] == 1)
464 13 jamey.hick
                              nextstate = tagged CodedSlice 12;
465 3 jamey.hick
                           else
466 13 jamey.hick
                              nextstate = tagged CodedSlice 15;
467 3 jamey.hick
                        end
468
                     else
469 13 jamey.hick
                        nextstate = tagged CodedSlice 15;
470 3 jamey.hick
                  end
471
                  12:
472
                  begin
473
                     $display( "ccl2SHRreordering_of_pic_nums_idc %0d", expgolomb_unsigned(buffer) );
474 13 jamey.hick
                     outfifo.enq(tagged SHRreordering_of_pic_nums_idc truncate(expgolomb_unsigned(buffer)));
475 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
476
                     if(expgolomb_unsigned(buffer)==0 || expgolomb_unsigned(buffer)==1)
477 13 jamey.hick
                        nextstate = tagged CodedSlice 13;
478 3 jamey.hick
                     else if(expgolomb_unsigned(buffer)==2)
479 13 jamey.hick
                        nextstate = tagged CodedSlice 14;
480 3 jamey.hick
                     else
481 13 jamey.hick
                        nextstate = tagged CodedSlice 15;
482 3 jamey.hick
                  end
483
                  13:
484
                  begin
485
                     Bit#(17) temp17 = zeroExtend(expgolomb_unsigned(buffer)) + 1;
486
                     $display( "ccl2SHRabs_diff_pic_num %0d", temp17 );
487 13 jamey.hick
                     outfifo.enq(tagged SHRabs_diff_pic_num temp17);
488 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
489 13 jamey.hick
                     nextstate = tagged CodedSlice 12;
490 3 jamey.hick
                  end
491
                  14:
492
                  begin
493
                     $display( "ccl2SHRlong_term_pic_num %0d", expgolomb_unsigned(buffer) );
494 13 jamey.hick
                     outfifo.enq(tagged SHRlong_term_pic_num truncate(expgolomb_unsigned(buffer)));
495 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
496 13 jamey.hick
                     nextstate = tagged CodedSlice 12;
497 3 jamey.hick
                  end
498
                  15:
499
                  begin
500
                     if(nalrefidc == 0)
501 13 jamey.hick
                        nextstate = tagged CodedSlice 23;
502 3 jamey.hick
                     else
503
                        begin
504
                           if(nalunittype == 5)
505
                              begin
506
                                 $display( "ccl2SHDno_output_of_prior_pics_flag %0d", buffer[buffersize-1] );
507 13 jamey.hick
                                 outfifo.enq(tagged SHDno_output_of_prior_pics_flag buffer[buffersize-1]);
508 3 jamey.hick
                                 numbitsused = 1;
509 13 jamey.hick
                                 nextstate = tagged CodedSlice 16;
510 3 jamey.hick
                              end
511
                           else
512 13 jamey.hick
                              nextstate = tagged CodedSlice 17;
513 3 jamey.hick
                        end
514
                  end
515
                  16:
516
                  begin
517
                     $display( "ccl2SHDlong_term_reference_flag %0d", buffer[buffersize-1] );
518 13 jamey.hick
                     outfifo.enq(tagged SHDlong_term_reference_flag buffer[buffersize-1]);
519 3 jamey.hick
                     numbitsused = 1;
520 13 jamey.hick
                     nextstate = tagged CodedSlice 23;
521 3 jamey.hick
                  end
522
                  17:
523
                  begin
524
                     $display( "ccl2SHDadaptive_ref_pic_marking_mode_flag %0d", buffer[buffersize-1] );
525 13 jamey.hick
                     outfifo.enq(tagged SHDadaptive_ref_pic_marking_mode_flag buffer[buffersize-1]);
526 3 jamey.hick
                     numbitsused = 1;
527
                     if(buffer[buffersize-1] == 1)
528 13 jamey.hick
                        nextstate = tagged CodedSlice 18;
529 3 jamey.hick
                     else
530 13 jamey.hick
                        nextstate = tagged CodedSlice 23;
531 3 jamey.hick
                  end
532
                  18:
533
                  begin
534
                     $display( "ccl2SHDmemory_management_control_operation %0d", expgolomb_unsigned(buffer) );
535 13 jamey.hick
                     outfifo.enq(tagged SHDmemory_management_control_operation truncate(expgolomb_unsigned(buffer)));
536 3 jamey.hick
                     shdmemory_management_control_operation <= truncate(expgolomb_unsigned(buffer));
537
                     numbitsused = expgolomb_numbits(buffer);
538
                     if(expgolomb_unsigned(buffer)!=0)
539 13 jamey.hick
                        nextstate = tagged CodedSlice 19;
540 3 jamey.hick
                     else
541 13 jamey.hick
                        nextstate = tagged CodedSlice 23;
542 3 jamey.hick
                  end
543
                  19:
544
                  begin
545
                     if(shdmemory_management_control_operation==1 || shdmemory_management_control_operation==3)
546
                        begin
547
                           Bit#(17) temp17 = zeroExtend(expgolomb_unsigned(buffer)) + 1;
548
                           $display( "ccl2SHDdifference_of_pic_nums %0d", temp17 );
549 13 jamey.hick
                           outfifo.enq(tagged SHDdifference_of_pic_nums temp17);
550 3 jamey.hick
                           numbitsused = expgolomb_numbits(buffer);
551 13 jamey.hick
                           nextstate = tagged CodedSlice 20;
552 3 jamey.hick
                        end
553
                     else
554 13 jamey.hick
                        nextstate = tagged CodedSlice 20;
555 3 jamey.hick
                  end
556
                  20:
557
                  begin
558
                     if(shdmemory_management_control_operation==2)
559
                        begin
560
                           $display( "ccl2SHDlong_term_pic_num %0d", expgolomb_unsigned(buffer) );
561 13 jamey.hick
                           outfifo.enq(tagged SHDlong_term_pic_num truncate(expgolomb_unsigned(buffer)));
562 3 jamey.hick
                           numbitsused = expgolomb_numbits(buffer);
563 13 jamey.hick
                           nextstate = tagged CodedSlice 21;
564 3 jamey.hick
                        end
565
                     else
566 13 jamey.hick
                        nextstate = tagged CodedSlice 21;
567 3 jamey.hick
                  end
568
                  21:
569
                  begin
570
                     if(shdmemory_management_control_operation==3 || shdmemory_management_control_operation==6)
571
                        begin
572
                           $display( "ccl2SHDlong_term_frame_idx %0d", expgolomb_unsigned(buffer) );
573 13 jamey.hick
                           outfifo.enq(tagged SHDlong_term_frame_idx truncate(expgolomb_unsigned(buffer)));
574 3 jamey.hick
                           numbitsused = expgolomb_numbits(buffer);
575 13 jamey.hick
                           nextstate = tagged CodedSlice 22;
576 3 jamey.hick
                        end
577
                     else
578 13 jamey.hick
                        nextstate = tagged CodedSlice 22;
579 3 jamey.hick
                  end
580
                  22:
581
                  begin
582
                     if(shdmemory_management_control_operation==4)
583
                        begin
584
                           $display( "ccl2SHDmax_long_term_frame_idx_plus1 %0d", expgolomb_unsigned(buffer) );
585 13 jamey.hick
                           outfifo.enq(tagged SHDmax_long_term_frame_idx_plus1 truncate(expgolomb_unsigned(buffer)));
586 3 jamey.hick
                           numbitsused = expgolomb_numbits(buffer);
587 13 jamey.hick
                           nextstate = tagged CodedSlice 18;
588 3 jamey.hick
                        end
589
                     else
590 13 jamey.hick
                        nextstate = tagged CodedSlice 18;
591 3 jamey.hick
                  end
592
                  23:
593
                  begin
594
                     tempint = unpack(expgolomb_signed(buffer));
595
                     $display( "ccl2SHslice_qp_delta %0d", tempint );
596 13 jamey.hick
                     outfifo_ITB.enq(tagged SHslice_qp_delta truncate(expgolomb_signed(buffer)));
597 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
598 13 jamey.hick
                     nextstate = tagged CodedSlice 24;
599 3 jamey.hick
                  end
600
                  24:
601
                  begin
602
                     if(ppsdeblocking_filter_control_present_flag==1)
603
                        begin
604
                           $display( "ccl2SHdisable_deblocking_filter_idc %0d", expgolomb_unsigned(buffer) );
605 13 jamey.hick
                           outfifo.enq(tagged SHdisable_deblocking_filter_idc truncate(expgolomb_unsigned(buffer)));
606 3 jamey.hick
                           numbitsused = expgolomb_numbits(buffer);
607
                           if(expgolomb_unsigned(buffer)!=1)
608 13 jamey.hick
                              nextstate = tagged CodedSlice 25;
609 3 jamey.hick
                           else
610 13 jamey.hick
                              nextstate = tagged CodedSlice 27;
611 3 jamey.hick
                        end
612
                     else
613 13 jamey.hick
                        nextstate = tagged CodedSlice 27;
614 3 jamey.hick
                  end
615
                  25:
616
                  begin
617
                     tempint = unpack(expgolomb_signed(buffer) << 1);
618
                     $display( "ccl2SHslice_alpha_c0_offset %0d", tempint );
619 13 jamey.hick
                     outfifo.enq(tagged SHslice_alpha_c0_offset truncate(expgolomb_signed(buffer) << 1));
620 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
621 13 jamey.hick
                     nextstate = tagged CodedSlice 26;
622 3 jamey.hick
                  end
623
                  26:
624
                  begin
625
                     tempint = unpack(expgolomb_signed(buffer) << 1);
626
                     $display( "ccl2SHslice_beta_offset %0d", tempint );
627 13 jamey.hick
                     outfifo.enq(tagged SHslice_beta_offset truncate(expgolomb_signed(buffer) << 1));
628 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
629 13 jamey.hick
                     nextstate = tagged CodedSlice 27;
630 3 jamey.hick
                  end
631
                  27:
632
                  begin
633 13 jamey.hick
                     nextstate = tagged SliceData 0;
634 3 jamey.hick
                  end
635
                  default: $display( "ERROR EntropyDec: CodedSlice default step" );
636
               endcase
637
            end
638
         tagged SEI .step :
639
            begin
640
               nextstate = Start;
641
               $display( "INFO EntropyDec: SEI data thrown away" );
642
            end
643
         tagged SPS .step :
644
            begin
645
               case ( step )
646
                  0:
647
                  begin
648
                     Bit#(8) outputdata = buffer[buffersize-1:buffersize-8];
649
                     $display( "INFO EntropyDec: profile_idc = %d", outputdata );
650
                     outputdata = buffer[buffersize-9:buffersize-16];
651
                     $display( "INFO EntropyDec: constraint_set = %b", outputdata );
652
                     outputdata = buffer[buffersize-17:buffersize-24];
653
                     $display( "INFO EntropyDec: level_idc = %d", outputdata );
654
                     numbitsused = 24;
655 13 jamey.hick
                     nextstate = tagged SPS 1;
656 3 jamey.hick
                  end
657
                  1:
658
                  begin
659
                     $display( "ccl2SPSseq_parameter_set_id %0d", expgolomb_unsigned(buffer) );
660 13 jamey.hick
                     outfifo.enq(tagged SPSseq_parameter_set_id truncate(expgolomb_unsigned(buffer)));
661 3 jamey.hick
                     spsseq_parameter_set_id <= truncate(expgolomb_unsigned(buffer));
662
                     numbitsused = expgolomb_numbits(buffer);
663 13 jamey.hick
                     nextstate = tagged SPS 2;
664 3 jamey.hick
                  end
665
                  2:
666
                  begin
667
                     $display( "ccl2SPSlog2_max_frame_num %0d", expgolomb_unsigned(buffer)+4 );
668 13 jamey.hick
                     outfifo.enq(tagged SPSlog2_max_frame_num truncate(expgolomb_unsigned(buffer)+4));
669 3 jamey.hick
                     spslog2_max_frame_num <= truncate(expgolomb_unsigned(buffer)+4);
670
                     numbitsused = expgolomb_numbits(buffer);
671 13 jamey.hick
                     nextstate = tagged SPS 3;
672 3 jamey.hick
                  end
673
                  3:
674
                  begin
675
                     let tttt = expgolomb_unsigned(buffer);
676
                     $display( "ccl2SPSpic_order_cnt_type %0d", tttt );
677 13 jamey.hick
                     outfifo.enq(tagged SPSpic_order_cnt_type truncate(tttt));
678 3 jamey.hick
                     spspic_order_cnt_type <= truncate(tttt);
679
                     numbitsused = expgolomb_numbits(buffer);
680
                     if(tttt == 0)
681 13 jamey.hick
                        nextstate = tagged SPS 4;
682 3 jamey.hick
                     else if(tttt == 1)
683 13 jamey.hick
                        nextstate = tagged SPS 5;
684 3 jamey.hick
                     else
685 13 jamey.hick
                        nextstate = tagged SPS 10;
686 3 jamey.hick
                  end
687
                  4:
688
                  begin
689
                     $display( "ccl2SPSlog2_max_pic_order_cnt_lsb %0d", expgolomb_unsigned(buffer)+4 );
690 13 jamey.hick
                     outfifo.enq(tagged SPSlog2_max_pic_order_cnt_lsb truncate(expgolomb_unsigned(buffer)+4));
691 3 jamey.hick
                     spslog2_max_pic_order_cnt_lsb <= truncate(expgolomb_unsigned(buffer)+4);
692
                     numbitsused = expgolomb_numbits(buffer);
693 13 jamey.hick
                     nextstate = tagged SPS 10;
694 3 jamey.hick
                  end
695
                  5:
696
                  begin
697
                     $display( "ccl2SPSdelta_pic_order_always_zero_flag %0d", buffer[buffersize-1] );
698 13 jamey.hick
                     outfifo.enq(tagged SPSdelta_pic_order_always_zero_flag buffer[buffersize-1]);
699 3 jamey.hick
                     spsdelta_pic_order_always_zero_flag <= buffer[buffersize-1];
700
                     numbitsused = 1;
701 13 jamey.hick
                     nextstate = tagged SPS 6;
702 3 jamey.hick
                  end
703
                  6:
704
                  begin
705
                     if(egnumbits == 0)
706
                        begin
707
                           Bufcount tempbufcount = expgolomb_numbits32(buffer);
708
                           egnumbits <= tempbufcount;
709
                           numbitsused = tempbufcount-1;
710 13 jamey.hick
                           nextstate = tagged SPS 6;
711 3 jamey.hick
                        end
712
                     else
713
                        begin
714
                           tempint32 = unpack(expgolomb_signed32(buffer,egnumbits));
715
                           $display( "ccl2SPSoffset_for_non_ref_pic %0d", tempint32 );
716 13 jamey.hick
                           outfifo.enq(tagged SPSoffset_for_non_ref_pic truncate(expgolomb_signed32(buffer,egnumbits)));
717 3 jamey.hick
                           egnumbits <= 0;
718
                           numbitsused = egnumbits;
719 13 jamey.hick
                           nextstate = tagged SPS 7;
720 3 jamey.hick
                        end
721
                  end
722
                  7:
723
                  begin
724
                     if(egnumbits == 0)
725
                        begin
726
                           Bufcount tempbufcount = expgolomb_numbits32(buffer);
727
                           egnumbits <= tempbufcount;
728
                           numbitsused = tempbufcount-1;
729 13 jamey.hick
                           nextstate = tagged SPS 7;
730 3 jamey.hick
                        end
731
                     else
732
                        begin
733
                           tempint32 = unpack(expgolomb_signed32(buffer,egnumbits));
734
                           $display( "ccl2SPSoffset_for_top_to_bottom_field %0d", tempint32 );
735 13 jamey.hick
                           outfifo.enq(tagged SPSoffset_for_top_to_bottom_field truncate(expgolomb_signed32(buffer,egnumbits)));
736 3 jamey.hick
                           egnumbits <= 0;
737
                           numbitsused = egnumbits;
738 13 jamey.hick
                           nextstate = tagged SPS 8;
739 3 jamey.hick
                        end
740
                  end
741
                  8:
742
                  begin
743
                     $display( "ccl2SPSnum_ref_frames_in_pic_order_cnt_cycle %0d", expgolomb_unsigned(buffer) );
744 13 jamey.hick
                     outfifo.enq(tagged SPSnum_ref_frames_in_pic_order_cnt_cycle truncate(expgolomb_unsigned(buffer)));
745 3 jamey.hick
                     spsnum_ref_frames_in_pic_order_cnt_cycle <= truncate(expgolomb_unsigned(buffer));
746
                     numbitsused = expgolomb_numbits(buffer);
747 13 jamey.hick
                     nextstate = tagged SPS 9;
748 3 jamey.hick
                  end
749
                  9:
750
                  begin
751
                     if(spsnum_ref_frames_in_pic_order_cnt_cycle == 0)
752 13 jamey.hick
                        nextstate = tagged SPS 10;
753 3 jamey.hick
                     else
754
                        begin
755
                           if(egnumbits == 0)
756
                              begin
757
                                 Bufcount tempbufcount = expgolomb_numbits32(buffer);
758
                                 egnumbits <= tempbufcount;
759
                                 numbitsused = tempbufcount-1;
760 13 jamey.hick
                                 nextstate = tagged SPS 9;
761 3 jamey.hick
                              end
762
                           else
763
                              begin
764
                                 tempint32 = unpack(expgolomb_signed32(buffer,egnumbits));
765
                                 $display( "ccl2SPSoffset_for_ref_frame %0d", tempint32 );
766 13 jamey.hick
                                 outfifo.enq(tagged SPSoffset_for_ref_frame truncate(expgolomb_signed32(buffer,egnumbits)));
767 3 jamey.hick
                                 egnumbits <= 0;
768
                                 spsnum_ref_frames_in_pic_order_cnt_cycle <= spsnum_ref_frames_in_pic_order_cnt_cycle - 1;
769
                                 numbitsused = egnumbits;
770 13 jamey.hick
                                 nextstate = tagged SPS 9;
771 3 jamey.hick
                              end
772
                        end
773
                  end
774
                  10:
775
                  begin
776
                     $display( "ccl2SPSnum_ref_frames %0d", expgolomb_unsigned(buffer) );
777 13 jamey.hick
                     outfifo.enq(tagged SPSnum_ref_frames truncate(expgolomb_unsigned(buffer)));
778 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
779 13 jamey.hick
                     nextstate = tagged SPS 11;
780 3 jamey.hick
                  end
781
                  11:
782
                  begin
783
                     $display( "ccl2SPSgaps_in_frame_num_allowed_flag %0d", buffer[buffersize-1] );
784 13 jamey.hick
                     outfifo.enq(tagged SPSgaps_in_frame_num_allowed_flag buffer[buffersize-1]);
785 3 jamey.hick
                     numbitsused = 1;
786 13 jamey.hick
                     nextstate = tagged SPS 12;
787 3 jamey.hick
                  end
788
                  12:
789
                  begin
790
                     $display( "ccl2SPSpic_width_in_mbs %0d", expgolomb_unsigned(buffer)+1 );
791 13 jamey.hick
                     outfifo.enq(tagged SPSpic_width_in_mbs truncate(expgolomb_unsigned(buffer)+1));
792 3 jamey.hick
                     calcnc.initialize_picWidth(truncate(expgolomb_unsigned(buffer)+1));
793
                     numbitsused = expgolomb_numbits(buffer);
794 13 jamey.hick
                     nextstate = tagged SPS 13;
795 3 jamey.hick
                  end
796
                  13:
797
                  begin
798
                     $display( "ccl2SPSpic_height_in_map_units %0d", expgolomb_unsigned(buffer)+1 );
799 13 jamey.hick
                     outfifo.enq(tagged SPSpic_height_in_map_units truncate(expgolomb_unsigned(buffer)+1));
800 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
801 13 jamey.hick
                     nextstate = tagged SPS 14;
802 3 jamey.hick
                  end
803
                  14:
804
                  begin
805
                     //SPSframe_mbs_only_flag = 1 for baseline
806
                     numbitsused = 1;
807 13 jamey.hick
                     nextstate = tagged SPS 15;
808 3 jamey.hick
                  end
809
                  15:
810
                  begin
811
                     $display( "ccl2SPSdirect_8x8_inference_flag %0d", buffer[buffersize-1] );
812 13 jamey.hick
                     outfifo.enq(tagged SPSdirect_8x8_inference_flag buffer[buffersize-1]);
813 3 jamey.hick
                     numbitsused = 1;
814 13 jamey.hick
                     nextstate = tagged SPS 16;
815 3 jamey.hick
                  end
816
                  16:
817
                  begin
818
                     $display( "ccl2SPSframe_cropping_flag %0d", buffer[buffersize-1] );
819 13 jamey.hick
                     outfifo.enq(tagged SPSframe_cropping_flag buffer[buffersize-1]);
820 3 jamey.hick
                     numbitsused = 1;
821
                     if(buffer[buffersize-1] == 1)
822 13 jamey.hick
                        nextstate = tagged SPS 17;
823 3 jamey.hick
                     else
824 13 jamey.hick
                        nextstate = tagged SPS 21;
825 3 jamey.hick
                  end
826
                  17:
827
                  begin
828
                     $display( "ccl2SPSframe_crop_left_offset %0d", expgolomb_unsigned(buffer) );
829 13 jamey.hick
                     outfifo.enq(tagged SPSframe_crop_left_offset truncate(expgolomb_unsigned(buffer)));
830 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
831 13 jamey.hick
                     nextstate = tagged SPS 18;
832 3 jamey.hick
                  end
833
                  18:
834
                  begin
835
                     $display( "ccl2SPSframe_crop_right_offset %0d", expgolomb_unsigned(buffer) );
836 13 jamey.hick
                     outfifo.enq(tagged SPSframe_crop_right_offset truncate(expgolomb_unsigned(buffer)));
837 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
838 13 jamey.hick
                     nextstate = tagged SPS 19;
839 3 jamey.hick
                  end
840
                  19:
841
                  begin
842
                     $display( "ccl2SPSframe_crop_top_offset %0d", expgolomb_unsigned(buffer) );
843 13 jamey.hick
                     outfifo.enq(tagged SPSframe_crop_top_offset truncate(expgolomb_unsigned(buffer)));
844 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
845 13 jamey.hick
                     nextstate = tagged SPS 20;
846 3 jamey.hick
                  end
847
                  20:
848
                  begin
849
                     $display( "ccl2SPSframe_crop_bottom_offset %0d", expgolomb_unsigned(buffer) );
850 13 jamey.hick
                     outfifo.enq(tagged SPSframe_crop_bottom_offset truncate(expgolomb_unsigned(buffer)));
851 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
852 13 jamey.hick
                     nextstate = tagged SPS 21;
853 3 jamey.hick
                  end
854
                  21:
855
                  begin
856
                     nextstate = Start;
857
                     $display( "INFO EntropyDec:VUI data thrown away" );
858
                  end
859
                  default: $display( "ERROR EntropyDec: SPS default step" );
860
               endcase
861
            end
862
         tagged PPS .step :
863
            begin
864
               case ( step )
865
                  0:
866
                  begin
867
                     ppspic_parameter_set_id <= truncate(expgolomb_unsigned(buffer));
868
                     $display( "ccl2PPSpic_parameter_set_id %0d", expgolomb_unsigned(buffer) );
869 13 jamey.hick
                     outfifo.enq(tagged PPSpic_parameter_set_id truncate(expgolomb_unsigned(buffer)));
870
                     outfifo_ITB.enq(tagged PPSpic_parameter_set_id truncate(expgolomb_unsigned(buffer)));
871 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
872 13 jamey.hick
                     nextstate = tagged PPS 1;
873 3 jamey.hick
                  end
874
                  1:
875
                  begin
876
                     $display( "ccl2PPSseq_parameter_set_id %0d", expgolomb_unsigned(buffer) );
877 13 jamey.hick
                     outfifo.enq(tagged PPSseq_parameter_set_id truncate(expgolomb_unsigned(buffer)));
878 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
879 13 jamey.hick
                     nextstate = tagged PPS 2;
880 3 jamey.hick
                     if(spsseq_parameter_set_id != truncate(expgolomb_unsigned(buffer)))
881
                        $display( "ERROR EntropyDec: seq_parameter_set_id don't match" );
882
                  end
883
                  2:
884
                  begin
885
                     //PPSentropy_coding_mode_flag = 0 for baseline
886
                     numbitsused = 1;
887 13 jamey.hick
                     nextstate = tagged PPS 3;
888 3 jamey.hick
                  end
889
                  3:
890
                  begin
891
                     ppspic_order_present_flag <= buffer[buffersize-1];
892
                     $display( "ccl2PPSpic_order_present_flag %0d", buffer[buffersize-1] );
893 13 jamey.hick
                     outfifo.enq(tagged PPSpic_order_present_flag buffer[buffersize-1]);
894 3 jamey.hick
                     numbitsused = 1;
895 13 jamey.hick
                     nextstate = tagged PPS 4;
896 3 jamey.hick
                  end
897
                  4:
898
                  begin
899
                     numbitsused = expgolomb_numbits(buffer);
900 13 jamey.hick
                     nextstate = tagged PPS 5;
901 3 jamey.hick
                     if(expgolomb_unsigned(buffer)+1 != 1)
902
                        $display( "ERROR EntropyDec: PPSnum_slice_groups not equal to 1" );//=1 for main
903
                  end
904
                  5:
905
                  begin
906
                     $display( "ccl2PPSnum_ref_idx_l0_active %0d", expgolomb_unsigned(buffer)+1 );
907 13 jamey.hick
                     outfifo.enq(tagged PPSnum_ref_idx_l0_active truncate(expgolomb_unsigned(buffer)+1));
908 3 jamey.hick
                     num_ref_idx_l0_active_minus1 <= truncate(expgolomb_unsigned(buffer));
909
                     numbitsused = expgolomb_numbits(buffer);
910 13 jamey.hick
                     nextstate = tagged PPS 6;
911 3 jamey.hick
                  end
912
                  6:
913
                  begin
914
                     $display( "ccl2PPSnum_ref_idx_l1_active %0d", expgolomb_unsigned(buffer)+1 );
915 13 jamey.hick
                     outfifo.enq(tagged PPSnum_ref_idx_l1_active truncate(expgolomb_unsigned(buffer)+1));
916 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
917 13 jamey.hick
                     nextstate = tagged PPS 7;
918 3 jamey.hick
                  end
919
                  7:
920
                  begin
921
                     //PPSweighted_pred_flag = 0 for baseline; PPSweighted_bipred_idc = 0 for baseline
922
                     numbitsused = 3;
923 13 jamey.hick
                     nextstate = tagged PPS 8;
924 3 jamey.hick
                  end
925
                  8:
926
                  begin
927
                     $display( "ccl2PPSpic_init_qp %0d", expgolomb_signed(buffer)+26 );
928 13 jamey.hick
                     outfifo_ITB.enq(tagged PPSpic_init_qp truncate(expgolomb_signed(buffer)+26));
929 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
930 13 jamey.hick
                     nextstate = tagged PPS 9;
931 3 jamey.hick
                  end
932
                  9:
933
                  begin
934
                     $display( "ccl2PPSpic_init_qs %0d", expgolomb_signed(buffer)+26 );
935 13 jamey.hick
                     outfifo_ITB.enq(tagged PPSpic_init_qs truncate(expgolomb_signed(buffer)+26));
936 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
937 13 jamey.hick
                     nextstate = tagged PPS 10;
938 3 jamey.hick
                  end
939
                  10:
940
                  begin
941
                     tempint = unpack(expgolomb_signed(buffer));
942
                     $display( "ccl2PPSchroma_qp_index_offset %0d", tempint );
943 13 jamey.hick
                     outfifo_ITB.enq(tagged PPSchroma_qp_index_offset truncate(expgolomb_signed(buffer)));
944 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
945 13 jamey.hick
                     nextstate = tagged PPS 11;
946 3 jamey.hick
                  end
947
                  11:
948
                  begin
949
                     ppsdeblocking_filter_control_present_flag <= buffer[buffersize-1];
950
                     $display( "ccl2PPSdeblocking_filter_control_present_flag %0d", buffer[buffersize-1] );
951 13 jamey.hick
                     outfifo.enq(tagged PPSdeblocking_filter_control_present_flag buffer[buffersize-1]);
952 3 jamey.hick
                     numbitsused = 1;
953 13 jamey.hick
                     nextstate = tagged PPS 12;
954 3 jamey.hick
                  end
955
                  12:
956
                  begin
957
                     $display( "ccl2PPSconstrained_intra_pred_flag %0d", buffer[buffersize-1] );
958 13 jamey.hick
                     outfifo.enq(tagged PPSconstrained_intra_pred_flag buffer[buffersize-1]);
959 3 jamey.hick
                     numbitsused = 1;
960 13 jamey.hick
                     nextstate = tagged PPS 13;
961 3 jamey.hick
                  end
962
                  13:
963
                  begin
964
                     //PPSredundant_pic_cnt_present_flag = 0 for main
965
                     numbitsused = 1;
966 13 jamey.hick
                     nextstate = tagged PPS 14;
967 3 jamey.hick
                     if(buffer[buffersize-1] != 0)
968
                        $display( "ERROR EntropyDec: PPSredundant_pic_cnt_present_flag not equal to 0" );//=0 for main
969
                  end
970
                  14:
971
                  begin
972
                     nextstate = Start;
973
                  end
974
                  default: $display( "ERROR EntropyDec: PPS default step" );
975
               endcase
976
            end
977
         tagged AUD .step :
978
            begin
979 13 jamey.hick
               outfifo.enq(tagged AUDPrimaryPicType buffer[buffersize-1:buffersize-3]);
980 3 jamey.hick
               numbitsused = 3;
981
               nextstate = Start;
982
            end
983
         tagged EndSequence :
984
            begin
985
               outfifo.enq(EndOfSequence);
986
               nextstate = Start;
987
            end
988
         tagged EndStream :
989
            begin
990
               outfifo.enq(EndOfStream);
991
               nextstate = Start;
992
            end
993
         tagged Filler :
994
            begin
995
               nextstate = Start;
996
            end
997
         tagged SliceData .step :
998
            begin
999
               case ( step )
1000
                  0:
1001
                  begin
1002
                     if( shslice_type!=2 && shslice_type!=7 )
1003
                        begin
1004
                           $display( "ccl2SDmb_skip_run %0d", expgolomb_unsigned(buffer) );
1005 13 jamey.hick
                           outfifo.enq(tagged SDmb_skip_run truncate(expgolomb_unsigned(buffer)));
1006 3 jamey.hick
                           tempreg <= truncate(expgolomb_unsigned(buffer));
1007
                           calcnc.nNupdate_pskip( truncate(expgolomb_unsigned(buffer)) );
1008
                           numbitsused = expgolomb_numbits(buffer);
1009 13 jamey.hick
                           nextstate = tagged SliceData 1;
1010 3 jamey.hick
                        end
1011
                     else
1012 13 jamey.hick
                        nextstate = tagged SliceData 2;
1013 3 jamey.hick
                  end
1014
                  1:
1015
                  begin
1016
                     if( tempreg>0 )
1017
                        begin
1018
                           currMbAddr <= currMbAddr+1;//only because input assumed to comform to both baseline and main
1019
                           tempreg <= tempreg-1;
1020 13 jamey.hick
                           nextstate = tagged SliceData 1;
1021 3 jamey.hick
                        end
1022
                     else
1023
                        begin
1024
                           ////$display( "ccl2SDcurrMbAddr %0d", currMbAddr );
1025
                           ////outfifo.enq(SDcurrMbAddr currMbAddr);
1026 13 jamey.hick
                           nextstate = tagged SliceData 2;
1027 3 jamey.hick
                        end
1028
                  end
1029
                  2:
1030
                  begin
1031
                     if( bufcount>8 || buffer[buffersize-1]!=1 || (buffer<<1)!=0 )
1032
                        begin
1033
                           calcnc.loadMb(currMbAddr);
1034 13 jamey.hick
                           nextstate = tagged MacroblockLayer 0;
1035 3 jamey.hick
                        end
1036
                     else
1037 13 jamey.hick
                        nextstate = tagged SliceData 3;
1038 3 jamey.hick
                  end
1039
                  3:
1040
                  begin
1041
                     currMbAddr <= currMbAddr+1;//only because input assumed to comform to both baseline and main
1042
                     if( bufcount>8 || buffer[buffersize-1]!=1 || (buffer<<1)!=0 )
1043 13 jamey.hick
                        nextstate = tagged SliceData 0;
1044 3 jamey.hick
                     else
1045
                        nextstate = Start;
1046
                  end
1047
                  default: $display( "ERROR EntropyDec: SliceData default step" );
1048
               endcase
1049
            end
1050
         tagged MacroblockLayer .step : //return to SliceData 3
1051
            begin
1052
               case ( step )
1053
                  0:
1054
                  begin
1055
                     $display( "ccl2SDMmb_type %0d", expgolomb_unsigned(buffer) );
1056 13 jamey.hick
                     outfifo.enq(tagged SDMmbtype mbtype_convert(truncate(expgolomb_unsigned(buffer)), shslice_type) );
1057
                     outfifo_ITB.enq(tagged SDMmbtype mbtype_convert(truncate(expgolomb_unsigned(buffer)), shslice_type) );
1058 3 jamey.hick
                     sdmmbtype <= mbtype_convert(truncate(expgolomb_unsigned(buffer)), shslice_type);
1059
                     numbitsused = expgolomb_numbits(buffer);
1060
                     if(mbtype_convert(truncate(expgolomb_unsigned(buffer)), shslice_type) == I_PCM)
1061
                        begin
1062
                           calcnc.nNupdate_ipcm();
1063 13 jamey.hick
                           nextstate = tagged MacroblockLayer 1;
1064 3 jamey.hick
                        end
1065
                     else
1066 13 jamey.hick
                        nextstate = tagged MacroblockLayer 4;
1067 3 jamey.hick
                  end
1068
                  1:
1069
                  begin
1070
                     tempreg <= 256;
1071
                     numbitsused = zeroExtend(bufcount[2:0]);
1072 13 jamey.hick
                     nextstate = tagged MacroblockLayer 2;
1073 3 jamey.hick
                  end
1074
                  2:
1075
                  begin
1076
                     if( tempreg>0 )
1077
                        begin
1078
                           Bit#(8) outputdata = buffer[buffersize-1:buffersize-8];
1079
                           $display( "ccl2SDMpcm_sample_luma %0d", outputdata );
1080 13 jamey.hick
                           outfifo.enq(tagged SDMpcm_sample_luma outputdata);
1081 3 jamey.hick
                           tempreg <= tempreg-1;
1082
                           numbitsused = 8;
1083 13 jamey.hick
                           nextstate = tagged MacroblockLayer 2;
1084 3 jamey.hick
                        end
1085
                     else
1086
                        begin
1087
                           tempreg <= 128;
1088 13 jamey.hick
                           nextstate = tagged MacroblockLayer 3;
1089 3 jamey.hick
                        end
1090
                  end
1091
                  3:
1092
                  begin
1093
                     if( tempreg>0 )
1094
                        begin
1095
                           Bit#(8) outputdata = buffer[buffersize-1:buffersize-8];
1096
                           $display( "ccl2SDMpcm_sample_chroma %0d", outputdata );
1097 13 jamey.hick
                           outfifo.enq(tagged SDMpcm_sample_chroma outputdata);
1098 3 jamey.hick
                           tempreg <= tempreg-1;
1099
                           numbitsused = 8;
1100 13 jamey.hick
                           nextstate = tagged MacroblockLayer 3;
1101 3 jamey.hick
                        end
1102
                     else
1103 13 jamey.hick
                           nextstate = tagged SliceData 3;
1104 3 jamey.hick
                  end
1105
                  4:
1106
                  begin
1107
                     if(sdmmbtype != I_NxN
1108
                        &&& mbPartPredMode(sdmmbtype,0) != Intra_16x16
1109
                        &&& numMbPart(sdmmbtype) == 4)
1110 13 jamey.hick
                        nextstate = tagged SubMbPrediction 0;
1111 3 jamey.hick
                     else
1112 13 jamey.hick
                        nextstate = tagged MbPrediction 0;
1113 3 jamey.hick
                  end
1114
                  5:
1115
                  begin
1116
                     if(mbPartPredMode(sdmmbtype,0) != Intra_16x16)
1117
                        begin
1118
                           $display( "ccl2SDMcoded_block_pattern %0d", expgolomb_coded_block_pattern(buffer,sdmmbtype) );
1119
                           ////outfifo.enq(SDMcoded_block_pattern expgolomb_coded_block_pattern(buffer,sdmmbtype));
1120
                           sdmcodedBlockPatternLuma <= expgolomb_coded_block_pattern(buffer,sdmmbtype)[3:0];
1121
                           sdmcodedBlockPatternChroma <= expgolomb_coded_block_pattern(buffer,sdmmbtype)[5:4];
1122
                           numbitsused = expgolomb_numbits(buffer);
1123
                        end
1124
                     else
1125
                        begin
1126
                           if(sdmmbtype matches tagged I_16x16 {intra16x16PredMode:.tempv1, codedBlockPatternChroma:.tempv2, codedBlockPatternLuma:.tempv3})
1127
                              begin
1128
                                 sdmcodedBlockPatternLuma <= {tempv3,tempv3,tempv3,tempv3};
1129
                                 sdmcodedBlockPatternChroma <= tempv2;
1130
                              end
1131
                           else
1132
                              $display( "ERROR EntropyDec: MacroblockLayer 5 sdmmbtype not I_16x16" );
1133
                        end
1134 13 jamey.hick
                     nextstate = tagged MacroblockLayer 6;
1135 3 jamey.hick
                  end
1136
                  6:
1137
                  begin
1138
                     if(sdmcodedBlockPatternLuma > 0
1139
                        || sdmcodedBlockPatternChroma > 0
1140
                        || mbPartPredMode(sdmmbtype,0) == Intra_16x16)
1141
                        begin
1142
                           tempint = unpack(expgolomb_signed(buffer));
1143
                           $display( "ccl2SDMmb_qp_delta %0d", tempint );
1144 13 jamey.hick
                           outfifo_ITB.enq(tagged SDMmb_qp_delta truncate(expgolomb_signed(buffer)));
1145 3 jamey.hick
                           numbitsused = expgolomb_numbits(buffer);
1146 13 jamey.hick
                           nextstate = tagged Residual 0;
1147 3 jamey.hick
                        end
1148
                     else
1149 13 jamey.hick
                        nextstate = tagged Residual 0;
1150 3 jamey.hick
                  end
1151
                  default: $display( "ERROR EntropyDec: MacroblockLayer default step" );
1152
               endcase
1153
            end
1154
         tagged MbPrediction .step : //return to MacroblockLayer 5
1155
            begin
1156
               case ( step )
1157
                  0:
1158
                  begin
1159
                     if(mbPartPredMode(sdmmbtype,0) == Intra_16x16)
1160
                        begin
1161
                           $display( "ccl2SDMMintra_chroma_pred_mode %0d", expgolomb_unsigned(buffer) );
1162 13 jamey.hick
                           outfifo.enq(tagged SDMMintra_chroma_pred_mode truncate(expgolomb_unsigned(buffer)));
1163 3 jamey.hick
                           numbitsused = expgolomb_numbits(buffer);
1164 13 jamey.hick
                           nextstate = tagged MacroblockLayer 5;
1165 3 jamey.hick
                        end
1166
                     else if(mbPartPredMode(sdmmbtype,0) == Intra_4x4)
1167
                        begin
1168
                           temp5bit <= 16;
1169 13 jamey.hick
                           nextstate = tagged MbPrediction 1;
1170 3 jamey.hick
                        end
1171
                     else if(num_ref_idx_l0_active_minus1 > 0)
1172
                        begin
1173
                           temp3bit0 <= numMbPart(sdmmbtype);
1174 13 jamey.hick
                           nextstate = tagged MbPrediction 2;
1175 3 jamey.hick
                        end
1176
                     else
1177
                        begin
1178
                           temp3bit0 <= numMbPart(sdmmbtype);
1179 13 jamey.hick
                           nextstate = tagged MbPrediction 3;
1180 3 jamey.hick
                        end
1181
                  end
1182
                  1:
1183
                  begin
1184
                     if(temp5bit == 0)
1185
                        begin
1186
                           $display( "ccl2SDMMintra_chroma_pred_mode %0d", expgolomb_unsigned(buffer) );
1187 13 jamey.hick
                           outfifo.enq(tagged SDMMintra_chroma_pred_mode truncate(expgolomb_unsigned(buffer)));
1188 3 jamey.hick
                           numbitsused = expgolomb_numbits(buffer);
1189 13 jamey.hick
                           nextstate = tagged MacroblockLayer 5;
1190 3 jamey.hick
                        end
1191
                     else
1192
                        begin
1193
                           ////$display( "ccl2SDMMprev_intra4x4_pred_mode_flag %0d", buffer[buffersize-1] );
1194
                           if(buffer[buffersize-1] == 0)
1195
                              begin
1196
                                 Bit#(4) tttt = buffer[buffersize-1:buffersize-4];
1197
                                 $display( "ccl2SDMMrem_intra4x4_pred_mode %0d", tttt );
1198 13 jamey.hick
                                 outfifo.enq(tagged SDMMrem_intra4x4_pred_mode tttt);
1199 3 jamey.hick
                                 numbitsused = 4;
1200
                              end
1201
                           else
1202
                              begin
1203 13 jamey.hick
                                 outfifo.enq(tagged SDMMrem_intra4x4_pred_mode 4'b1000);
1204 3 jamey.hick
                                 numbitsused = 1;
1205
                              end
1206
                           temp5bit <= temp5bit-1;
1207 13 jamey.hick
                           nextstate = tagged MbPrediction 1;
1208 3 jamey.hick
                        end
1209
                  end
1210
                  2:
1211
                  begin
1212
                     if(num_ref_idx_l0_active_minus1 == 1)
1213
                        begin
1214
                           $display( "ccl2SDMMref_idx_l0 %0d", 1-buffer[buffersize-1] );
1215 13 jamey.hick
                           outfifo.enq(tagged SDMMref_idx_l0 zeroExtend(1-buffer[buffersize-1]));
1216 3 jamey.hick
                           numbitsused = 1;
1217
                        end
1218
                     else
1219
                        begin
1220
                           $display( "ccl2SDMMref_idx_l0 %0d", expgolomb_unsigned(buffer) );
1221 13 jamey.hick
                           outfifo.enq(tagged SDMMref_idx_l0 truncate(expgolomb_unsigned(buffer)));
1222 3 jamey.hick
                           numbitsused = expgolomb_numbits(buffer);
1223
                        end
1224
                     if(temp3bit0 == 1)
1225
                        begin
1226
                           temp3bit0 <= numMbPart(sdmmbtype);
1227 13 jamey.hick
                           nextstate = tagged MbPrediction 3;
1228 3 jamey.hick
                        end
1229
                     else
1230
                        begin
1231
                           temp3bit0 <= temp3bit0-1;
1232 13 jamey.hick
                           nextstate = tagged MbPrediction 2;
1233 3 jamey.hick
                        end
1234
                  end
1235
                  3:
1236
                  begin
1237
                     tempint = unpack(expgolomb_signed(buffer));
1238
                     $display( "ccl2SDMMmvd_l0 %0d", tempint );
1239 13 jamey.hick
                     outfifo.enq(tagged SDMMmvd_l0 truncate(expgolomb_signed(buffer)));
1240 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
1241 13 jamey.hick
                     nextstate = tagged MbPrediction 4;
1242 3 jamey.hick
                  end
1243
                  4:
1244
                  begin
1245
                     tempint = unpack(expgolomb_signed(buffer));
1246
                     $display( "ccl2SDMMmvd_l0 %0d", tempint );
1247 13 jamey.hick
                     outfifo.enq(tagged SDMMmvd_l0 truncate(expgolomb_signed(buffer)));
1248 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
1249
                     temp3bit0 <= temp3bit0-1;
1250
                     if(temp3bit0 == 1)
1251 13 jamey.hick
                        nextstate = tagged MacroblockLayer 5;
1252 3 jamey.hick
                     else
1253 13 jamey.hick
                        nextstate = tagged MbPrediction 3;
1254 3 jamey.hick
                  end
1255
                  default: $display( "ERROR EntropyDec: MbPrediction default step" );
1256
               endcase
1257
            end
1258
         tagged SubMbPrediction .step : //return to MacroblockLayer 5
1259
            begin
1260
               case ( step )
1261
                  0:
1262
                  begin
1263
                     $display( "ccl2SDMSsub_mb_type %0d", expgolomb_unsigned(buffer) );
1264 13 jamey.hick
                     outfifo.enq(tagged SDMSsub_mb_type truncate(expgolomb_unsigned(buffer)));
1265 3 jamey.hick
                     temp3bit0 <= numSubMbPart(truncate(expgolomb_unsigned(buffer)));
1266
                     numbitsused = expgolomb_numbits(buffer);
1267 13 jamey.hick
                     nextstate = tagged SubMbPrediction 1;
1268 3 jamey.hick
                  end
1269
                  1:
1270
                  begin
1271
                     $display( "ccl2SDMSsub_mb_type %0d", expgolomb_unsigned(buffer) );
1272 13 jamey.hick
                     outfifo.enq(tagged SDMSsub_mb_type truncate(expgolomb_unsigned(buffer)));
1273 3 jamey.hick
                     temp3bit1 <= numSubMbPart(truncate(expgolomb_unsigned(buffer)));
1274
                     numbitsused = expgolomb_numbits(buffer);
1275 13 jamey.hick
                     nextstate = tagged SubMbPrediction 2;
1276 3 jamey.hick
                  end
1277
                  2:
1278
                  begin
1279
                     $display( "ccl2SDMSsub_mb_type %0d", expgolomb_unsigned(buffer) );
1280 13 jamey.hick
                     outfifo.enq(tagged SDMSsub_mb_type truncate(expgolomb_unsigned(buffer)));
1281 3 jamey.hick
                     temp3bit2 <= numSubMbPart(truncate(expgolomb_unsigned(buffer)));
1282
                     numbitsused = expgolomb_numbits(buffer);
1283 13 jamey.hick
                     nextstate = tagged SubMbPrediction 3;
1284 3 jamey.hick
                  end
1285
                  3:
1286
                  begin
1287
                     $display( "ccl2SDMSsub_mb_type %0d", expgolomb_unsigned(buffer) );
1288 13 jamey.hick
                     outfifo.enq(tagged SDMSsub_mb_type truncate(expgolomb_unsigned(buffer)));
1289 3 jamey.hick
                     temp3bit3 <= numSubMbPart(truncate(expgolomb_unsigned(buffer)));
1290
                     numbitsused = expgolomb_numbits(buffer);
1291
                     if(num_ref_idx_l0_active_minus1 > 0
1292
                              && sdmmbtype != P_8x8ref0)
1293 13 jamey.hick
                        nextstate = tagged SubMbPrediction 4;
1294 3 jamey.hick
                     else
1295 13 jamey.hick
                        nextstate = tagged SubMbPrediction 8;
1296 3 jamey.hick
                  end
1297
                  4:
1298
                  begin
1299
                     if(num_ref_idx_l0_active_minus1 == 1)
1300
                        begin
1301
                           $display( "ccl2SDMSref_idx_l0 %0d", 1-buffer[buffersize-1] );
1302 13 jamey.hick
                           outfifo.enq(tagged SDMSref_idx_l0 zeroExtend(1-buffer[buffersize-1]));
1303 3 jamey.hick
                           numbitsused = 1;
1304
                        end
1305
                     else
1306
                        begin
1307
                           $display( "ccl2SDMSref_idx_l0 %0d", expgolomb_unsigned(buffer) );
1308 13 jamey.hick
                           outfifo.enq(tagged SDMSref_idx_l0 truncate(expgolomb_unsigned(buffer)));
1309 3 jamey.hick
                           numbitsused = expgolomb_numbits(buffer);
1310
                        end
1311 13 jamey.hick
                     nextstate = tagged SubMbPrediction 5;
1312 3 jamey.hick
                  end
1313
                  5:
1314
                  begin
1315
                     if(num_ref_idx_l0_active_minus1 == 1)
1316
                        begin
1317
                           $display( "ccl2SDMSref_idx_l0 %0d", 1-buffer[buffersize-1] );
1318 13 jamey.hick
                           outfifo.enq(tagged SDMSref_idx_l0 zeroExtend(1-buffer[buffersize-1]));
1319 3 jamey.hick
                           numbitsused = 1;
1320
                        end
1321
                     else
1322
                        begin
1323
                           $display( "ccl2SDMSref_idx_l0 %0d", expgolomb_unsigned(buffer) );
1324 13 jamey.hick
                           outfifo.enq(tagged SDMSref_idx_l0 truncate(expgolomb_unsigned(buffer)));
1325 3 jamey.hick
                           numbitsused = expgolomb_numbits(buffer);
1326
                        end
1327 13 jamey.hick
                     nextstate = tagged SubMbPrediction 6;
1328 3 jamey.hick
                  end
1329
                  6:
1330
                  begin
1331
                     if(num_ref_idx_l0_active_minus1 == 1)
1332
                        begin
1333
                           $display( "ccl2SDMSref_idx_l0 %0d", 1-buffer[buffersize-1] );
1334 13 jamey.hick
                           outfifo.enq(tagged SDMSref_idx_l0 zeroExtend(1-buffer[buffersize-1]));
1335 3 jamey.hick
                           numbitsused = 1;
1336
                        end
1337
                     else
1338
                        begin
1339
                           $display( "ccl2SDMSref_idx_l0 %0d", expgolomb_unsigned(buffer) );
1340 13 jamey.hick
                           outfifo.enq(tagged SDMSref_idx_l0 truncate(expgolomb_unsigned(buffer)));
1341 3 jamey.hick
                           numbitsused = expgolomb_numbits(buffer);
1342
                        end
1343 13 jamey.hick
                     nextstate = tagged SubMbPrediction 7;
1344 3 jamey.hick
                  end
1345
                  7:
1346
                  begin
1347
                     if(num_ref_idx_l0_active_minus1 == 1)
1348
                        begin
1349
                           $display( "ccl2SDMSref_idx_l0 %0d", 1-buffer[buffersize-1] );
1350 13 jamey.hick
                           outfifo.enq(tagged SDMSref_idx_l0 zeroExtend(1-buffer[buffersize-1]));
1351 3 jamey.hick
                           numbitsused = 1;
1352
                        end
1353
                     else
1354
                        begin
1355
                           $display( "ccl2SDMSref_idx_l0 %0d", expgolomb_unsigned(buffer) );
1356 13 jamey.hick
                           outfifo.enq(tagged SDMSref_idx_l0 truncate(expgolomb_unsigned(buffer)));
1357 3 jamey.hick
                           numbitsused = expgolomb_numbits(buffer);
1358
                        end
1359 13 jamey.hick
                     nextstate =  tagged SubMbPrediction 8;
1360 3 jamey.hick
                  end
1361
                  8:
1362
                  begin
1363
                     tempint = unpack(expgolomb_signed(buffer));
1364
                     $display( "ccl2SDMSmvd_l0 %0d", tempint );
1365 13 jamey.hick
                     outfifo.enq(tagged SDMSmvd_l0 truncate(expgolomb_signed(buffer)));
1366 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
1367 13 jamey.hick
                     nextstate = tagged SubMbPrediction 9;
1368 3 jamey.hick
                  end
1369
                  9:
1370
                  begin
1371
                     tempint = unpack(expgolomb_signed(buffer));
1372
                     $display( "ccl2SDMSmvd_l0 %0d", tempint );
1373 13 jamey.hick
                     outfifo.enq(tagged SDMSmvd_l0 truncate(expgolomb_signed(buffer)));
1374 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
1375
                     temp3bit0 <= temp3bit0-1;
1376
                     if(temp3bit0 == 1)
1377 13 jamey.hick
                        nextstate = tagged SubMbPrediction 10;
1378 3 jamey.hick
                     else
1379 13 jamey.hick
                        nextstate = tagged SubMbPrediction 8;
1380 3 jamey.hick
                  end
1381
                  10:
1382
                  begin
1383
                     tempint = unpack(expgolomb_signed(buffer));
1384
                     $display( "ccl2SDMSmvd_l0 %0d", tempint );
1385 13 jamey.hick
                     outfifo.enq(tagged SDMSmvd_l0 truncate(expgolomb_signed(buffer)));
1386 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
1387 13 jamey.hick
                     nextstate = tagged SubMbPrediction 11;
1388 3 jamey.hick
                  end
1389
                  11:
1390
                  begin
1391
                     tempint = unpack(expgolomb_signed(buffer));
1392
                     $display( "ccl2SDMSmvd_l0 %0d", tempint );
1393 13 jamey.hick
                     outfifo.enq(tagged SDMSmvd_l0 truncate(expgolomb_signed(buffer)));
1394 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
1395
                     temp3bit1 <= temp3bit1-1;
1396
                     if(temp3bit1 == 1)
1397 13 jamey.hick
                        nextstate = tagged SubMbPrediction 12;
1398 3 jamey.hick
                     else
1399 13 jamey.hick
                        nextstate = tagged SubMbPrediction 10;
1400 3 jamey.hick
                  end
1401
                  12:
1402
                  begin
1403
                     tempint = unpack(expgolomb_signed(buffer));
1404
                     $display( "ccl2SDMSmvd_l0 %0d", tempint );
1405 13 jamey.hick
                     outfifo.enq(tagged SDMSmvd_l0 truncate(expgolomb_signed(buffer)));
1406 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
1407 13 jamey.hick
                     nextstate = tagged SubMbPrediction 13;
1408 3 jamey.hick
                  end
1409
                  13:
1410
                  begin
1411
                     tempint = unpack(expgolomb_signed(buffer));
1412
                     $display( "ccl2SDMSmvd_l0 %0d", tempint );
1413 13 jamey.hick
                     outfifo.enq(tagged SDMSmvd_l0 truncate(expgolomb_signed(buffer)));
1414 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
1415
                     temp3bit2 <= temp3bit2-1;
1416
                     if(temp3bit2 == 1)
1417 13 jamey.hick
                        nextstate = tagged SubMbPrediction 14;
1418 3 jamey.hick
                     else
1419 13 jamey.hick
                        nextstate = tagged SubMbPrediction 12;
1420 3 jamey.hick
                  end
1421
                  14:
1422
                  begin
1423
                     tempint = unpack(expgolomb_signed(buffer));
1424
                     $display( "ccl2SDMSmvd_l0 %0d", tempint );
1425 13 jamey.hick
                     outfifo.enq(tagged SDMSmvd_l0 truncate(expgolomb_signed(buffer)));
1426 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
1427 13 jamey.hick
                     nextstate = tagged SubMbPrediction 15;
1428 3 jamey.hick
                  end
1429
                  15:
1430
                  begin
1431
                     tempint = unpack(expgolomb_signed(buffer));
1432
                     $display( "ccl2SDMSmvd_l0 %0d", tempint );
1433 13 jamey.hick
                     outfifo.enq(tagged SDMSmvd_l0 truncate(expgolomb_signed(buffer)));
1434 3 jamey.hick
                     numbitsused = expgolomb_numbits(buffer);
1435
                     temp3bit3 <= temp3bit3-1;
1436
                     if(temp3bit3 == 1)
1437 13 jamey.hick
                        nextstate = tagged MacroblockLayer 5;
1438 3 jamey.hick
                     else
1439 13 jamey.hick
                        nextstate = tagged SubMbPrediction 14;
1440 3 jamey.hick
                  end
1441
                  default: $display( "ERROR EntropyDec: SubMbPrediction default step" );
1442
               endcase
1443
            end
1444
         tagged Residual .step : //return to SliceData 3
1445
            begin
1446
               case ( step )
1447
                  0:
1448
                  begin
1449
                     residualChroma <= 0;
1450
                     temp5bit <= 0;
1451
                     if(mbPartPredMode(sdmmbtype,0) == Intra_16x16)
1452
                        begin
1453
                           maxNumCoeff <= 16;
1454 13 jamey.hick
                           nextstate = tagged ResidualBlock 0;
1455 3 jamey.hick
                        end
1456
                     else
1457 13 jamey.hick
                        nextstate = tagged Residual 1;
1458 3 jamey.hick
                     //$display( "TRACE EntropyDec: Residual 0" );
1459
                  end
1460
                  1:
1461
                  begin
1462
                     if(temp5bit == 16)
1463
                        begin
1464
                           residualChroma <= 1;
1465
                           temp5bit <= 0;
1466 13 jamey.hick
                           nextstate = tagged Residual 3;
1467 3 jamey.hick
                        end
1468
                     else
1469
                        begin
1470
                           Bit#(5) tempMaxNumCoeff = 0;
1471
                           if(mbPartPredMode(sdmmbtype,0) == Intra_16x16)
1472
                              tempMaxNumCoeff = 15;
1473
                           else
1474
                              tempMaxNumCoeff = 16;
1475
                           maxNumCoeff <= tempMaxNumCoeff;
1476
                           if((sdmcodedBlockPatternLuma & (1 << zeroExtend(temp5bit[3:2]))) == 0)
1477
                              begin
1478
                                 calcnc.nNupdate_luma(truncate(temp5bit),0);
1479
                                 ////$display( "ccl2SDMRcoeffLevelZeros %0d", tempMaxNumCoeff );
1480 13 jamey.hick
                                 outfifo_ITB.enq(tagged SDMRcoeffLevelZeros tempMaxNumCoeff);
1481 3 jamey.hick
                                 temp5bit <= temp5bit+1;
1482 13 jamey.hick
                                 nextstate = tagged Residual 1;
1483 3 jamey.hick
                              end
1484
                           else
1485 13 jamey.hick
                              nextstate = tagged ResidualBlock 0;
1486 3 jamey.hick
                        end
1487
                     //$display( "TRACE EntropyDec: Residual 1" );
1488
                  end
1489
                  3:
1490
                  begin
1491
                     if(temp5bit == 2)
1492
                        begin
1493
                           temp5bit <= 0;
1494 13 jamey.hick
                           nextstate = tagged Residual 5;
1495 3 jamey.hick
                        end
1496
                     else
1497
                        begin
1498
                           maxNumCoeff <= 4;
1499
                           if((sdmcodedBlockPatternChroma & 3) == 0)
1500
                              begin
1501
                                 ////$display( "ccl2SDMRcoeffLevelZeros %0d", 4 );
1502 13 jamey.hick
                                 outfifo_ITB.enq(tagged SDMRcoeffLevelZeros 4);
1503 3 jamey.hick
                                 temp5bit <= temp5bit+1;
1504 13 jamey.hick
                                 nextstate = tagged Residual 3;
1505 3 jamey.hick
                              end
1506
                           else
1507 13 jamey.hick
                              nextstate = tagged ResidualBlock 0;
1508 3 jamey.hick
                        end
1509
                     //$display( "TRACE EntropyDec: Residual 3" );
1510
                  end
1511
                  5:
1512
                  begin
1513
                     if(temp5bit == 8)
1514
                        begin
1515
                           temp5bit <= 0;
1516 13 jamey.hick
                           nextstate = tagged SliceData 3;
1517 3 jamey.hick
                        end
1518
                     else
1519
                        begin
1520
                           maxNumCoeff <= 15;
1521
                           if((sdmcodedBlockPatternChroma & 2) == 0)
1522
                              begin
1523
                                 calcnc.nNupdate_chroma(truncate(temp5bit),0);
1524
                                 ////$display( "ccl2SDMRcoeffLevelZeros %0d", 15 );
1525 13 jamey.hick
                                 outfifo_ITB.enq(tagged SDMRcoeffLevelZeros 15);
1526 3 jamey.hick
                                 temp5bit <= temp5bit+1;
1527 13 jamey.hick
                                 nextstate = tagged Residual 5;
1528 3 jamey.hick
                              end
1529
                           else
1530 13 jamey.hick
                              nextstate = tagged ResidualBlock 0;
1531 3 jamey.hick
                        end
1532
                     //$display( "TRACE EntropyDec: Residual 5" );
1533
                  end
1534
                  default: $display( "ERROR EntropyDec: Residual default step" );
1535
               endcase
1536
            end
1537
         tagged ResidualBlock .step : //if(residualChroma==0) return to Residual 1;   else if(maxNumCoeff==4) return to Residual 3;   else return to Residual 5
1538
            begin//don't modify maxNumCoeff, residualChroma, and increment temp5bit on return
1539
               case ( step )
1540
                  0:
1541
                  begin
1542
                     cavlcFIFO.fifo.clear();
1543
                     if(maxNumCoeff != 4)
1544
                        begin
1545
                           if(residualChroma == 0)
1546
                              tempreg <= zeroExtend(calcnc.nCcalc_luma(truncate(temp5bit)));
1547
                           else
1548
                              tempreg <= zeroExtend(calcnc.nCcalc_chroma(truncate(temp5bit)));
1549
                        end
1550
                     else
1551
                        begin
1552
                           tempreg <= zeroExtend(6'b111111);
1553
                        end
1554 13 jamey.hick
                     nextstate = tagged ResidualBlock 1;
1555 3 jamey.hick
                     //$display( "TRACE EntropyDec: ResidualBlock 0 temp5bit = %0d", temp5bit);
1556
                  end
1557
                  1:
1558
                  begin
1559
                     Bit#(2) trailingOnesTemp = 0;
1560
                     Bit#(5) totalCoeffTemp = 0;
1561
                     {trailingOnesTemp,totalCoeffTemp,numbitsused} = cavlc_coeff_token( buffer, truncate(tempreg) );
1562
                     temp3bit0 <= zeroExtend(trailingOnesTemp);//trailingOnes
1563
                     totalCoeff <= totalCoeffTemp;
1564
                     if(residualChroma == 0 && !(mbPartPredMode(sdmmbtype,0)==Intra_16x16 && maxNumCoeff==16))
1565
                        calcnc.nNupdate_luma(truncate(temp5bit),totalCoeffTemp);
1566
                     else if(residualChroma == 1 && maxNumCoeff != 4)
1567
                        calcnc.nNupdate_chroma(truncate(temp5bit),totalCoeffTemp);
1568
                     temp5bit2 <= 0;//i
1569
                     tempreg <= 0;//levelCode temp
1570
                     if(totalCoeffTemp > 10 && trailingOnesTemp < 3)
1571
                        temp3bit1 <= 1;//suffixLength
1572
                     else
1573
                        temp3bit1 <= 0;//suffixLength
1574 13 jamey.hick
                     nextstate = tagged ResidualBlock 2;
1575 3 jamey.hick
                     //$display( "TRACE EntropyDec: ResidualBlock 1 nC = %0d", tempreg);
1576
                     $display( "ccl2SDMRtotal_coeff %0d", totalCoeffTemp );
1577
                     $display( "ccl2SDMRtrailing_ones %0d", trailingOnesTemp );
1578
                  end
1579
                  2:
1580
                  begin
1581
                     if(temp5bit2 == totalCoeff)
1582
                        begin
1583
                           temp5bit2 <= 0;
1584
                           zerosLeft <= 0;
1585
                           if(totalCoeff < maxNumCoeff)
1586 13 jamey.hick
                              nextstate = tagged ResidualBlock 3;
1587 3 jamey.hick
                           else
1588 13 jamey.hick
                              nextstate = tagged ResidualBlock 5;
1589 3 jamey.hick
                        end
1590
                     else
1591
                        begin
1592
                           if(temp5bit2 < zeroExtend(temp3bit0))
1593
                              begin
1594
                                 if(buffer[buffersize-1] == 1)
1595
                                    cavlcFIFO.fifo.enq(-1);
1596
                                 else
1597
                                    cavlcFIFO.fifo.enq(1);
1598
                                 numbitsused = 1;
1599
                              end
1600
                           else
1601
                              begin
1602
                                 Bit#(32) buffertempshow = buffer[buffersize-1:buffersize-32];
1603
                                 Bit#(3) suffixLength = temp3bit1;
1604
                                 Bit#(4) levelSuffixSize = zeroExtend(suffixLength);
1605
                                 Bit#(4) level_prefix = cavlc_level_prefix( buffer );
1606
                                 Bit#(5) temp_level_prefix = zeroExtend(level_prefix);
1607
                                 Bit#(28) tempbuffer = buffer[buffersize-1:buffersize-28] << zeroExtend(temp_level_prefix+1);
1608
                                 Bit#(14) levelCode = zeroExtend(level_prefix) << zeroExtend(suffixLength);
1609
                                 if(level_prefix == 14 && suffixLength == 0)
1610
                                    levelSuffixSize = 4;
1611
                                 else if(level_prefix == 15)
1612
                                    levelSuffixSize = 12;
1613
                                 levelCode = levelCode + zeroExtend(tempbuffer[27:16] >> (12-zeroExtend(levelSuffixSize)));//level_suffix
1614
                                 if(level_prefix == 15 && suffixLength == 0)
1615
                                    levelCode = levelCode + 15;
1616
                                 if(temp5bit2 == zeroExtend(temp3bit0) && temp3bit0 < 3)
1617
                                    levelCode = levelCode + 2;
1618
                                 if(suffixLength == 0)
1619
                                    suffixLength = 1;
1620
                                 if( suffixLength < 6 && ((levelCode+2) >> 1) > (3 << zeroExtend(suffixLength-1)) )
1621
                                    suffixLength = suffixLength+1;
1622
                                 if(levelCode[0] == 0)
1623
                                    cavlcFIFO.fifo.enq(truncate((levelCode+2) >> 1));
1624
                                 else
1625
                                    cavlcFIFO.fifo.enq(truncate((~levelCode) >> 1));
1626
                                 if(levelCode[0] == 0)//////////////////////////////////////////////////
1627
                                    begin
1628
                                       tempint = signExtend(unpack((levelCode+2) >> 1));
1629
                                       //$display( "TRACE EntropyDec: temp level %0d", tempint );
1630
                                    end
1631
                                 else
1632
                                    begin
1633
                                       Bit#(13) tempinttemp = truncate((~levelCode) >> 1);
1634
                                       tempint = signExtend(unpack(tempinttemp));
1635
                                       //$display( "TRACE EntropyDec: temp level %0d", tempint );
1636
                                    end///////////////////////////////////////////////////////////////////////
1637
                                 temp3bit1 <= suffixLength;
1638
                                 numbitsused = zeroExtend(level_prefix)+1+zeroExtend(levelSuffixSize);
1639
                              end
1640
                           temp5bit2 <= temp5bit2 + 1;
1641 13 jamey.hick
                           nextstate = tagged ResidualBlock 2;
1642 3 jamey.hick
                        end
1643
                  end
1644
                  3:
1645
                  begin
1646
                     Bit#(4) tempZerosLeft;
1647
                     if(totalCoeff > 0)
1648
                        begin
1649
                           {tempZerosLeft,numbitsused} = cavlc_total_zeros( buffer, truncate(totalCoeff), maxNumCoeff);
1650
                           $display( "ccl2SDMRtotal_zeros %0d", tempZerosLeft );//////////////////////////////////////
1651
                        end
1652
                     else
1653
                        tempZerosLeft = 0;
1654
                     zerosLeft <= tempZerosLeft;
1655
                     if(maxNumCoeff - totalCoeff - zeroExtend(tempZerosLeft) > 0)
1656
                        begin
1657
                           $display( "ccl2SDMRcoeffLevelZeros %0d", maxNumCoeff - totalCoeff - zeroExtend(tempZerosLeft) );
1658 13 jamey.hick
                           outfifo_ITB.enq(tagged SDMRcoeffLevelZeros (maxNumCoeff - totalCoeff - zeroExtend(tempZerosLeft)));
1659 3 jamey.hick
                        end
1660 13 jamey.hick
                     nextstate = tagged ResidualBlock 5;
1661 3 jamey.hick
                  end
1662
                  4:
1663
                  begin
1664
                     $display( "ccl2SDMRcoeffLevelZeros %0d", temp5bit2 );
1665 13 jamey.hick
                     outfifo_ITB.enq(tagged SDMRcoeffLevelZeros temp5bit2);
1666 3 jamey.hick
                     temp5bit2 <= 0;
1667 13 jamey.hick
                     nextstate = tagged ResidualBlock 5;
1668 3 jamey.hick
                  end
1669
                  5:
1670
                  begin
1671
                     if( totalCoeff > 0 )
1672
                        begin
1673
                           tempint = signExtend(unpack(cavlcFIFO.fifo.first()));
1674
                           $display( "ccl2SDMRcoeffLevel %0d", tempint );
1675 13 jamey.hick
                           outfifo_ITB.enq(tagged SDMRcoeffLevel cavlcFIFO.fifo.first());
1676 3 jamey.hick
                           cavlcFIFO.fifo.deq();
1677
                           totalCoeff <= totalCoeff-1;
1678
                           if( zerosLeft > 0 )
1679
                              begin
1680
                                 Bit#(4) run_before = 0;
1681
                                 if( totalCoeff > 1 )
1682
                                    {run_before,numbitsused} = cavlc_run_before( buffer, zerosLeft);
1683
                                 else
1684
                                    run_before = zerosLeft;
1685
                                 if( run_before > 0 )
1686
                                    begin
1687
                                       zerosLeft <= zerosLeft - run_before;
1688
                                       temp5bit2 <= zeroExtend(run_before);
1689 13 jamey.hick
                                       nextstate = tagged ResidualBlock 4;
1690 3 jamey.hick
                                    end
1691
                                 else
1692 13 jamey.hick
                                    nextstate = tagged ResidualBlock 5;
1693 3 jamey.hick
                              end
1694
                           else
1695 13 jamey.hick
                              nextstate = tagged ResidualBlock 5;
1696 3 jamey.hick
                        end
1697
                     else
1698
                        begin
1699
                           if(!(mbPartPredMode(sdmmbtype,0)==Intra_16x16 && maxNumCoeff==16))
1700
                              temp5bit <= temp5bit+1;
1701
                           if(residualChroma==0)
1702 13 jamey.hick
                              nextstate = tagged Residual 1;
1703 3 jamey.hick
                           else if(maxNumCoeff==4)
1704 13 jamey.hick
                              nextstate = tagged Residual 3;
1705 3 jamey.hick
                           else
1706 13 jamey.hick
                              nextstate = tagged Residual 5;
1707 3 jamey.hick
                        end
1708
                  end
1709
                  default: $display( "ERROR EntropyDec: ResidualBlock default step" );
1710
               endcase
1711
            end
1712
      endcase
1713
 
1714
      if(numbitsused+1 > bufcount)
1715
         begin
1716
            $display( "ERROR EntropyDec: not enough bits in buffer" );
1717
            nextstate = Start;
1718
         end
1719
      buffer <= buffer << zeroExtend(numbitsused);
1720
      bufcount <= bufcount-numbitsused;
1721
      state <= nextstate;
1722
 
1723
   endrule
1724
 
1725
 
1726
   interface Put ioin  = fifoToPut(infifo);
1727
   interface Get ioout = fifoToGet(outfifo);
1728
   interface Get ioout_InverseTrans = fifoToGet(outfifo_ITB);
1729
 
1730
   interface mem_client = calcnc.mem_client;
1731
 
1732
endmodule
1733
 
1734
endpackage

powered by: WebSVN 2.1.0

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