📄 skl_mpg4_tbl.cpp
字号:
{ All_Pics[i].Width = Width; All_Pics[i].Height = Height; All_Pics[i].BpS = BpS; All_Pics[i].Y = YUV_Base + Y_Off; All_Pics[i].U = YUV_Base + U_Off; All_Pics[i].V = YUV_Base + V_Off; All_Pics[i].MV = 0; All_Pics[i].Map = 0; All_Pics[i].Time = (double)(SKL_INT64)Time_Ref; All_Pics[i].Time_Ticks = Time_Ref*Time_Frequency; All_Pics[i].Data = 0; YUV_Base += YUV_Size; } for( ; i<MAX_PICS; ++i) { // sanity check All_Pics[i].Y = 0; All_Pics[i].U = 0; All_Pics[i].V = 0; All_Pics[i].MV = 0; All_Pics[i].Map = 0; All_Pics[i].Data = 0; } for(i=0; i<Nb_Maps; ++i) { All_Maps[i].Map = (SKL_MP4_MAP*)Map_Base; All_Maps[i].MV = (SKL_MV*)MV_Base; Map_Base += Map_Size; MV_Base += MV_Size; } for( ; i<MAX_MAPS; ++i) { All_Maps[i].Map = 0; // sanity check All_Maps[i].MV = 0; } // Encoder: the boundary motion vectors are // invariantly INVALID. Marks them as such for(i=0; i<Nb_Maps; ++i) { int x, y; SKL_MV *MVs = All_Maps[i].MV; for(x=-1; x<=2*MB_W; ++x) // top row MARK_INVALID_MV( MVs[-MV_Stride + x] ); for(y=0; y<2*MB_H; ++y) { // left/right columns MARK_INVALID_MV( MVs[-1]); MARK_INVALID_MV( MVs[2*MB_W]); MVs += MV_Stride; } for(x=-1; x<=2*MB_W; ++x) // bottom row (for ME) MARK_INVALID_MV( MVs[x] ); } Nb_Preds = (2*MB_W+2)*3 + (2*MB_W+4)*2; int Data_Size = Nb_Preds * sizeof(SKL_MB_DATA); Preds = (Mem==0) ? (SKL_MB_DATA*)malloc( Data_Size ) : (SKL_MB_DATA*)Mem->New( Data_Size ); if (Preds==0) Skl_Throw( SKL_MEM_EXCEPTION("SKL_MB_DATA", Data_Size) ); Y_Preds[0] = Preds + 1; Y_Preds[1] = Y_Preds[0] + (2*MB_W+2); Y_Preds[2] = Y_Preds[1] + (2*MB_W+2); C_Preds[0] = Y_Preds[2] + (2*MB_W+2); C_Preds[1] = C_Preds[0] + (2*MB_W+4); // the boundary left/right blocks are // invariant along every frames // => Initialize'em once for all. Y_Preds[0][ -1].Set_Not_Intra(); // Y1 (Tops[0]) Y_Preds[0][ 2*MB_W].Set_Not_Intra(); Y_Preds[1][ -1].Set_Not_Intra(); // Y1 (Curs[0]) Y_Preds[1][ 2*MB_W].Set_Not_Intra(); Y_Preds[2][ -1].Set_Not_Intra(); // Y2 (Curs[2]) Y_Preds[2][ 2*MB_W].Set_Not_Intra(); C_Preds[0][ -1].Set_Not_Intra(); // U (Tops[4]) C_Preds[0][ MB_W+0].Set_Not_Intra(); C_Preds[0][ MB_W+1].Set_Not_Intra(); // V (Tops[5]) C_Preds[0][2*MB_W+2].Set_Not_Intra(); C_Preds[1][ -1].Set_Not_Intra(); // U (Curs[4]) C_Preds[1][ MB_W+0].Set_Not_Intra(); C_Preds[1][ MB_W+1].Set_Not_Intra(); // V (Curs[5]) C_Preds[1][2*MB_W+2].Set_Not_Intra();}void SKL_MP4_I::Clear_Pics(){ int i; Width = 0; Height = 0; BpS = 0; MB_W = 0; MB_H = 0; EMB_W = 0; EMB_H = 0; for(i=0; i<MAX_PICS; ++i) { All_Pics[i].Y = 0; All_Pics[i].U = 0; All_Pics[i].V = 0; All_Pics[i].MV = 0; All_Pics[i].Map = 0; } for(i=0; i<MAX_MAPS; ++i) { All_Maps[i].Map = 0; All_Maps[i].MV = 0; } if (Pic_Base!=0) { if (Mem==0) free( Pic_Base ); else Mem->Delete( Pic_Base, Pic_Size ); } Pic_Size = 0; Pic_Base = 0; Nb_Pics = 0; if (Preds) { if (Mem==0) free( Preds ); else Mem->Delete( Preds, Nb_Preds * sizeof(SKL_MB_DATA) ); } Preds = 0; Nb_Preds = 0; Y_Preds[0] = 0; Y_Preds[1] = 0; Y_Preds[2] = 0; C_Preds[0] = 0; C_Preds[1] = 0; Past = &All_Pics[0]; Future = &All_Pics[1]; Aux = &All_Pics[2]; Cur = 0; Last = 0; Cur_Map = 0;}int SKL_MP4_I::Sanity_Check_Preds() const{ if (Y_Preds[0][ -1].Q!=0 || // Y1 (Tops[0]) Y_Preds[0][ 2*MB_W].Q!=0 || Y_Preds[1][ -1].Q!=0 || // Y1 (Curs[0]) Y_Preds[1][ 2*MB_W].Q!=0 || Y_Preds[2][ -1].Q!=0 || // Y2 (Curs[2]) Y_Preds[2][ 2*MB_W].Q!=0 || C_Preds[0][ -1].Q!=0 || // U (Tops[4]) C_Preds[0][ MB_W+0].Q!=0 || C_Preds[0][ MB_W+1].Q!=0 || // V (Tops[5]) C_Preds[0][2*MB_W+2].Q!=0 || C_Preds[1][ -1].Q!=0 || // U (Curs[4]) C_Preds[1][ MB_W+0].Q!=0 || C_Preds[1][ MB_W+1].Q!=0 || // V (Curs[5]) C_Preds[1][2*MB_W+2].Q!=0) return 0; for(int i=0; i<Nb_Pics; ++i) { int x, y; SKL_MV *MVs = All_Pics[i].MV; if (MVs==0) continue; // no map assigned to this pic yet... for(x=-1; x<=2*MB_W; ++x) // top row if (IS_VALID_MV( MVs[-MV_Stride + x] )) return 0; for(y=0; y<2*MB_H; ++y) { // left/right columns if (IS_VALID_MV( MVs[-1]) || IS_VALID_MV( MVs[2*MB_W])) return 0; MVs += MV_Stride; } for(x=-1; x<=2*MB_W; ++x) // bottom row if (IS_VALID_MV( MVs[x] )) return 0; } return 1;}void SKL_MP4_I::Get_All_Frames(SKL_MP4_PIC *Pic) const{ SKL_ASSERT(Pic!=0); Pic->Y = (SKL_BYTE*)SKL_ALIGN_PTR(Pic_Base, SKL_ALIGN); Pic->U = 0; Pic->V = 0; Pic->Map = 0; Pic->MV = 0; Pic->Width = BpS; Pic->Height = (Height*3/2 + 3*(1+MB_FENCE)*16) * Nb_Pics; Pic->BpS = BpS;}void SKL_MP4_I::Copy_Pic(SKL_MP4_PIC *Dst, const SKL_MP4_PIC *Src) const{ // this not-coded frame is not supposed to be referenced // for backward prediction => we don't copy MV const int YUV_Offset = (16*BpS + 16)*(1+MB_FENCE); const int YUV_Size = EMB_H*8*BpS * 3; SKL_MEMCPY(Dst->Y-YUV_Offset, Src->Y-YUV_Offset, YUV_Size); if (Dst->Map!=0 && Src->Map!=0) SKL_MEMCPY(Dst->Map, Src->Map, MB_W*MB_H*sizeof(SKL_MP4_MAP) );}//////////////////////////////////////////////////////////// Debugging//////////////////////////////////////////////////////////static void Print_Pred(SKL_MB_DATA *P, int What){ if (What==0) printf( "%2d", P->Q ); else if (What==1) printf( "%c", P->Q==0 ? '.' : 'I' ); else if (What==2) printf( "%x", P->DC/16/8 ); }void SKL_MP4_I::Dump_Line(int What, const SKL_MB * const MB) const{ int i; SKL_MB_DATA *Y1 = Y_Preds[1]; SKL_MB_DATA *Top = Y_Preds[MB->y&1 ? 2 : 0]; SKL_MB_DATA *Y2 = Y_Preds[MB->y&1 ? 0 : 1]; SKL_MB_DATA *CC = C_Preds[MB->y&1 ? 0 : 1]; const int W = 2*MB_W; if (MB->y==0) { printf( "[top]" ); for(i=-1; i<=W; i++) Print_Pred( &Top[i], What ); printf(" Frame #%d\n", Frame_Number); } printf( "[%3d]", MB->y); for(i=-1; i<=W; i++) Print_Pred( &Y1[i], What ); printf("\n"); printf( "[---]" ); for(i=-1; i<=W; i++) Print_Pred( &Y2[i], What ); printf("\n");/* printf( "[cc]" ); for(i=-1; i<=W/2; i++) { Print_Pred( &CC[i], What ); Print_Pred( &CC[i+W/2+2], What ); } printf("\n");*/ (void)CC;}static void Draw_Line(int x0, int y0, int x1, int y1, const SKL_MP4_PIC * const Pic){// #define PLOT(x) (x) = ((x)>>7)-1// #define PLOT(x) (x) ^= 0xff#define PLOT(x) (x) = 0xc0 // It's as ugly & slow a 16:16 Bresenham as it can. const int W = Pic->Width; const int H = Pic->Height; const int BpS = Pic->BpS; if (y1<y0) { int tmp = y0; y0=y1; y1=tmp; tmp=x0; x0=x1; x1=tmp; } if (y1<0 || y0>=H) return; int dx = x1-x0; int dy = y1-y0; if (dy==0) { if (dx==0) return; } else { if (y0<0) { x0 -= y0*dx/dy; y0 = 0; } if (y1>=H) { x1 += (H-1-y1)*dx/dy; y1 = H-1; } } if (dx>0) { if (x0>=W || x1<0) return; if (x0<0) { y0 -= x0*dy/dx; x0 = 0; } if (x1>=W) { y1 += (W-1-x1)*dy/dx; x1 = W-1; } } else if (dx<0) { if (x1>=W || x0<0) return; if (x1<0) { y1 -= x1*dy/dx; x1 = 0; } if (x0>=W) { y0 += (W-x0)*dy/dx; x0 = W; } } else { if (x0<0 || x0>=W) return; } int Err = 0x10000; int d1, d2, l, dErr; if ( dx<=dy && dx>=-dy ) // >=45' { if (dx>0) { dErr= Err*dx/dy; d2= 1; } else { dErr=-Err*dx/dy; d2=-1; } d1 = BpS; l = y1-y0; } else // <45' { if (dx>=0) { dErr= Err*dy/dx; d1 = 1; l = x1-x0; } else { dErr=-Err*dy/dx; d1 =-1; l = x0-x1; } d2 = BpS; } SKL_BYTE *Dst = Pic->Y + x0 + y0*BpS; while(l-->0) { PLOT(*Dst); Dst += d1; if ((Err-=dErr)<0) { Err += 0x10000; Dst += d2; } }#undef PLOT}void SKL_MP4_I::Dump_MVs(const SKL_MP4_PIC * const Pic, int Incr) const{#if 0 // DEBUG Draw_Line() static int Cnt = 0; for(int i=0; i<=100; ++i) { int dx = (int)( 300.*cos(M_PI*(i*32+(Cnt&31))/100./32.) ); int dy = (int)( 300.*sin(M_PI*(i*32+(Cnt&31))/100./32.) ); Draw_Line(100-dx, 100-dy, 100+dx, 100+dy, Pic); } Cnt++; return;#endif const SKL_MV *MVs = Pic->MV; const int Shift = Quarter ? 2 : 1; for(int y=4*Incr; y<Pic->Height; y+=Incr*8) { int x, i; for(x=4*Incr, i=0; x<Pic->Width; x+=Incr*8, i++) Draw_Line(x,y, x+(MVs[i][0]>>Shift), y+(MVs[i][1]>>Shift), Pic); MVs += MV_Stride*Incr; }}void SKL_MP4_I::Draw_GMC(const SKL_MP4_PIC * const Pic) const{#if 0 int x0, y0, x1, y1, x2, y2, x3, y3; x0 = S_Warp_Pts[0][0]/2; y0 = S_Warp_Pts[0][1]/2; x1 = x0 + S_W + S_Warp_Pts[1][0]/2; y1 = y0 + S_Warp_Pts[1][1]/2; x2 = x0 + S_Warp_Pts[2][0]/2; y2 = y0 + S_H + S_Warp_Pts[2][1]/2; x3 = x0 + S_W + S_Warp_Pts[1][0]/2 + S_Warp_Pts[2][0]/2 + S_Warp_Pts[3][0]/2; y3 = y0 + S_H + S_Warp_Pts[1][1]/2 + S_Warp_Pts[2][1]/2 + S_Warp_Pts[3][1]/2; Draw_Line(x0,y0, x1,y1, Pic); Draw_Line(x1,y1, x3,y3, Pic); Draw_Line(x3,y3, x2,y2, Pic); Draw_Line(x2,y2, x0,y0, Pic);#endif#if 0 const int W = Pic->Width/4; const int H = Pic->Height/4; Draw_Line( W, H, 3*W, H, Pic); Draw_Line( W,3*H, 3*W,3*H, Pic); Draw_Line( W, H, W,3*H, Pic); Draw_Line(3*W, H, 3*W,3*H, Pic);#endif int n; static int Cnt = 1; static SKL_MV P[4]; if (!--Cnt) { Cnt = 150; const int W = Pic->Width << 2; const int H = Pic->Height << 2; P[0][0] = W; P[0][1] = H; P[1][0] = 3*W, P[1][1] = H; P[2][0] = 3*W; P[2][1] = 3*H; P[3][0] = W, P[3][1] = 3*H; } for(n=0; n<4; ++n) { int mv[2]; GMC_Ops.Get_Average_MV(mv, P[n][0]>>8, P[n][1]>>8, Quarter); P[n][0] -= mv[0]<<(3-Quarter); P[n][1] -= mv[1]<<(3-Quarter); } for(n=0; n<4; ++n) { const int m = (n+1)%4; Draw_Line( P[n][0]>>4,P[n][1]>>4, P[m][0]>>4,P[m][1]>>4, Pic ); } }void SKL_MP4_I::Print_Infos() const{ if (Debug_Level==3) { printf( " Shape = %d ", Shape ); printf( " Partitioned = %d ", Data_Partitioned ); printf( " Time incr bits = %d Freq=%d\n", Ticks_Bits, Time_Frequency ); printf( " Size: %d x %d interlace:%d reduced:%d", Width, Height, Interlace, (Reduced_VOP>=0) ); printf( " Quant prec %d bpp:%d QType:%d Quarter:%d\n", Quant_Prec, Bpp, Quant_Type, Quarter ); } else if (Debug_Level==4) { printf( " Coding=[%c] Time:%lld Rnd=%d", "IPBS"[Coding], Cur->Time_Ticks, Rounding ); if (Is_S_VOP() && Sprite_Mode==SPRITE_GMC) printf(" Spr_Nb:%d, Acc:%d ", Sprite_Nb_Pts, Sprite_Accuracy); else printf( " Reduced:%d NewPred:%d ", Reduced_VOP, New_Pred ); printf( " FCode: %d/%d ", Fwd_Code, Bwd_Code ); printf( " Q:%d DC-Trsh:%d \n", Quant, DC_Thresh ); }}void SKL_MP4_FRAME::Dump_Map(SKL_MP4_PIC *Pic, int What) const{ printf( "---- Coding: %c-VOP -----------\n", "IPBD?"[Coding] ); SKL_MP4_MAP *Map = Pic->Map; for(int y=0; y<MB_H; ++y) { for(int x=0; x<MB_W; ++x) { if (What==0) printf("%c", "sI.=4"[Map[x].Type]); // wow else if (What==1) printf("%.1x", Map[x].Type); // MB_Type only else printf("%2d", Map[x].dQ); // dQ } Map += MB_W; printf("\n" ); }}//////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -