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

Subversion Repositories bluespec-h264

[/] [bluespec-h264/] [trunk/] [src/] [mkEntropyDec.bsv] - Blame information for rev 27

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

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

powered by: WebSVN 2.1.0

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