x 264 Code Tracing Group 5 9862649 Covered

  • Slides: 23
Download presentation
x 264 Code Tracing Group 5 9862649 陳易成

x 264 Code Tracing Group 5 9862649 陳易成

Covered Functions � x 264_mb_predict_intra 4 x 4_mode � x 264_cabac_mb_intra 4 x 4_pred_mode

Covered Functions � x 264_mb_predict_intra 4 x 4_mode � x 264_cabac_mb_intra 4 x 4_pred_mode � x 264_cabac_mb_intra_chroma_pred_mode � x 264_cabac_mb_ref

Function Structure Diagram Macroblock 型態為 I type x 264_macroblock_write_cabac Macroblock 型態為 P type 或是

Function Structure Diagram Macroblock 型態為 I type x 264_macroblock_write_cabac Macroblock 型態為 P type 或是 B type x 264_mb_predict_intra 4 x 4_mode, x 264_cabac_mb_intra 4 x 4_pred_mode x 264_cabac_mb_intra_chroma_pred_mode x 264_cabac_mb_ref

Function Structure Diagram common/common. h 0 1 2 1 B 2 B 3 4

Function Structure Diagram common/common. h 0 1 2 1 B 2 B 3 4 5 6 7 B L L L L 0 3 4 R R L L L 5 R R Dy Du Dv

x 264_mb_predict_intra 4 x 4_mode Function Derive the most likely prediction mode for intra

x 264_mb_predict_intra 4 x 4_mode Function Derive the most likely prediction mode for intra 4 x 4 luminance blocks Input • h - x 264 data structure which contains codingrelated parameters • idx - Index of the current 4 x 4 luma block Output • m - Derived prediction mode of the current 4 x 4 luma block Referenced by • x 264_mb_analyse_intra() • x 264_macroblock_write_cabac() • x 264_partition_i 8 x 8_size_cabac() • x 264_partition_i 4 x 4_size_cabac() • x 264_macroblock_write_cavlc() • cavlc_intra 4 x 4_pred_size() References • x 264_mb_pred_mode 4 x 4_fix()

x 264_mb_predict_intra 4 x 4_mode 4 x 4 luma prediction modes

x 264_mb_predict_intra 4 x 4_mode 4 x 4 luma prediction modes

x 264_mb_predict_intra 4 x 4_mode 4 x 4 luma prediction blocks

x 264_mb_predict_intra 4 x 4_mode 4 x 4 luma prediction blocks

x 264_mb_predict_intra 4 x 4_mode 取得目前區塊的左邊 (A) 與上邊 (B) 之相鄰區 塊 success fail 計算最可能預測模式

x 264_mb_predict_intra 4 x 4_mode 取得目前區塊的左邊 (A) 與上邊 (B) 之相鄰區 塊 success fail 計算最可能預測模式 即 A、B 之最佳預測模式的較小者 預設為模式 2 (I_PRED_4 x 4_DC) 回傳預測模式 Derivation of the most likely prediction mode for intra 4 x 4 luminance blocks

x 264_mb_predict_intra 4 x 4_mode /* get left and top blocks relative to the

x 264_mb_predict_intra 4 x 4_mode /* get left and top blocks relative to the current macroblock m */ const int ma = h->mb. cache. intra 4 x 4_pred_mode[x 264_scan 8[idx] - 1]; const int mb = h->mb. cache. intra 4 x 4_pred_mode[x 264_scan 8[idx] - 8]; /* choose the minimum prediction mode of ma and mb as the derived mode */ const int m = X 264_MIN( x 264_mb_pred_mode 4 x 4_fix(ma), x 264_mb_pred_mode 4 x 4_fix(mb) ); /* * if ma and mb are both not available, * return I_PRED_4 x 4_DC as the derived mode */ if( m < 0 ) return I_PRED_4 x 4_DC; MB /* otherwise, return m */ return m; MA M

x 264_cabac_mb_intra 4 x 4_pred_mode Function Coding of luminance intra prediction modes for 4

x 264_cabac_mb_intra 4 x 4_pred_mode Function Coding of luminance intra prediction modes for 4 x 4 blocks Input • cb - CABAC data structure which contains the state of the probability model • i_pred - Derived prediction mode • i_mode - Current prediction mode Output • N/A Referenced by • x 264_macroblock_write_cabac() • x 264_partition_i 8 x 8_size_cabac() • x 264_partition_i 4 x 4_size_cabac() References • x 264_cabac_encode_decision()

x 264_cabac_mb_intra 4 x 4_pred_mode

x 264_cabac_mb_intra 4 x 4_pred_mode

x 264_cabac_mb_intra 4 x 4_pred_mode 目前區塊之最佳模式恰為最可能預測模式 yes prev_intra 4 x 4_pred_mode_flag = 1 no

x 264_cabac_mb_intra 4 x 4_pred_mode 目前區塊之最佳模式恰為最可能預測模式 yes prev_intra 4 x 4_pred_mode_flag = 1 no prev_intra 4 x 4_pred_mode_flag = 0 目前區塊之最佳模式小於最可能預測模式 yes rem_intra 4 x 4_pred_mode 等於目前區塊之最佳模式值 no rem_intra 4 x 4_pred_mode 等於目前區塊之最佳模式值減 1 使用參數值 (3 -bit FL binarized value) 為 0 至 7 之 rem_intra 4 x 4_pred_mode 來表示目前區塊之最佳模式 Coding of luma intra prediction modes for 4 x 4 blocks

x 264_cabac_mb_intra 4 x 4_pred_mode /* * if the derived prediction mode and the

x 264_cabac_mb_intra 4 x 4_pred_mode /* * if the derived prediction mode and the current prediction mode * are the same, set prev_intra 4 x 4_pred_mode_flag to 1 */ if( i_pred == i_mode ) /* prev_intra 4 x 4_pred_mode_flag == 1 */ /* the most probable prediction mode is used */ use context index 68 x 264_cabac_encode_decision( cb, 68, 1 ); else { /* prev_intra 4 x 4_pred_mode_flag == 0 */ x 264_cabac_encode_decision( cb, 68, 0 ); /* rem_intra 4 x 4_pred_mode is equal to (the most probable prediction mode – 1) */ if( i_mode > i_pred ) i_mode--; use context index 68, 69 /* * send rem_intra 4 x 4_pred_mode to indicate a change of mode * use 3 -bit fixed-length binarized value (from 0 to 7) * to signal the current intra mode */ x 264_cabac_encode_decision( cb, 69, (i_mode )&0 x 01 ); x 264_cabac_encode_decision( cb, 69, (i_mode >> 1)&0 x 01 ); x 264_cabac_encode_decision( cb, 69, (i_mode >> 2) ); }

x 264_cabac_mb_intra_chroma_pred_mode Function Coding of chromonance intra prediction modes for 8 x 8 blocks

x 264_cabac_mb_intra_chroma_pred_mode Function Coding of chromonance intra prediction modes for 8 x 8 blocks Input • h - x 264 data structure which contains codingrelated parameters • cb - CABAC data structure which contains the state of the probability model Output • N/A Referenced by • x 264_macroblock_write_cabac() • x 264_i 8 x 8_chroma_size_cabac() References • x 264_cabac_encode_decision_noup() • x 264_cabac_encode_decision()

x 264_cabac_mb_intra_chroma_pred_mode

x 264_cabac_mb_intra_chroma_pred_mode

x 264_cabac_mb_intra_chroma_pred_mode � 8 x 8 chroma intra prediction mode Intra_chroma_pred_mode Prediction Mode 0

x 264_cabac_mb_intra_chroma_pred_mode � 8 x 8 chroma intra prediction mode Intra_chroma_pred_mode Prediction Mode 0 DC 1 Horizontal 2 Vertical 3 Plane mode 0 mode 1 mode 2 mode 3

x 264_cabac_mb_intra_chroma_pred_mode 取得目前區塊之彩度預測模式 計算相對應的 context index increment χCh. Perd(C) = (Ch. Pred. In. Dc.

x 264_cabac_mb_intra_chroma_pred_mode 取得目前區塊之彩度預測模式 計算相對應的 context index increment χCh. Perd(C) = (Ch. Pred. In. Dc. Mode(A) != 0) ? 0: 1 + (Ch. Pred. In. Dc. Mode(B) != 0) ? 0: 1 對 syntax element intra_chroma_pred_mode 的第一個 bin 進行編碼 當目前區塊的預測模式不為 DC 對 syntax element intra_chroma_pred_mode 的第二、三個 bin 進行編碼 Coding of intra chroma macroblock prediction modes

x 264_cabac_mb_intra_chroma_pred_mode /* get the current chroma prediction mode */ const int i_mode =

x 264_cabac_mb_intra_chroma_pred_mode /* get the current chroma prediction mode */ const int i_mode = x 264_mb_pred_mode 8 x 8 c_fix[ h->mb. i_chroma_pred_mode ]; /* context index increment XCh. Pred(C) */ int ctx = 0; /* * calculate the corresponding context index increment XCh. Pred(C) * XCh. Pred(C)=(Ch. Pred. In. Dc. Mode(A)!=0)? 0 : 1 + (Ch. Pred. In. Dc. Mode(B)!=0)? 0 : 1 */ if( (h->mb. i_neighbour & MB_LEFT) && h->mb. chroma_pred_mode[h->mb. i_mb_xy - 1] != 0 ) ctx++; if( (h->mb. i_neighbour & MB_TOP) && h->mb. chroma_pred_mode[h->mb. i_mb_top_xy] != 0 ) ctx++; use context index 64, 65, 66 /* encode 0 if DC mode is used, otherwise encode 1 */ x 264_cabac_encode_decision_noup( cb, 64 + ctx, i_mode > 0 ); if( i_mode > 0 ) use context index 67 { /* encode the two remaining bins if mode 1, 2, or 3 is used */ x 264_cabac_encode_decision( cb, 64 + 3, i_mode > 1 ); if( i_mode > 1 ) x 264_cabac_encode_decision_noup( cb, 64 + 3, i_mode > 2 ); }

x 264_cabac_mb_ref Function Coding of the reference picture index for P-type or B -type

x 264_cabac_mb_ref Function Coding of the reference picture index for P-type or B -type blocks Input • h - x 264 data structure which contains codingrelated parameters • cb - CABAC data structure which contains the state of the probability model • i_list - Reference list in the cache that stores previously-coded pictures • idx - Index of the current 4 x 4 block Output • N/A Referenced by • x 264_macroblock_write_cabac() References • x 264_cabac_encode_decision()

x 264_cabac_mb_ref

x 264_cabac_mb_ref

x 264_cabac_mb_ref 取得 1. 目前區塊的索引值 2. 從參考清單中取得左邊與上邊的參考區塊 計算相對應的 context index increment χRef. Idx(C) =

x 264_cabac_mb_ref 取得 1. 目前區塊的索引值 2. 從參考清單中取得左邊與上邊的參考區塊 計算相對應的 context index increment χRef. Idx(C) = ((Ref. Idx. Zero. Flag(A) != 0) ? 0: 1) + 2 × ((Ref. Idx. Zero. Flag(B) != 0) ? 0: 1) 重複對 syntax element ref_idx 的前 i 個 bin 進行編碼(變動長度) 直到 Reference count == 0 對 syntax element ref_idx 的最後一個 bin 進行編碼 Coding of reference picture index

x 264_cabac_mb_ref /* get the index of the current block */ const int i

x 264_cabac_mb_ref /* get the index of the current block */ const int i 8 = x 264_scan 8[idx]; /* * get the index of the reference block (-1 if unused, -2 if unavailable) * from previously-coded pictures, list 0 (P-type) or list 0 & list 1 (B-type) */ const int int i_ref int ctx = i_refa = h->mb. cache. ref[i_list][i 8 - 1]; i_refb = h->mb. cache. ref[i_list][i 8 - 8]; = h->mb. cache. ref[i_list][i 8]; 0; /* * calculate the corresponding context index increment XRef. Idx(C) * XRef. Idx(C)=(Ref. Idx. Zero. Flag(A)!=0)? 0 : 1 + 2*(Ref. Idx. Zero. Flag(B)!=0)? 0 : 1 */ if( i_refa > 0 && !h->mb. cache. skip[i 8 - 1] ) ctx++; if( i_refb > 0 && !h->mb. cache. skip[i 8 - 8] ) use context index 54, 55, 56, 57 ctx += 2; /* encode 1 and adjust XRef. Idx(C) until the reference count is decreased to 0 */ while( i_ref > 0 ) { x 264_cabac_encode_decision( cb, 54 + ctx, 1 ); ctx = (ctx>>2)+4; i_ref--; } /* encode 0 at the end */ x 264_cabac_encode_decision( cb, 54 + ctx, 0 ); use context 58, 59

Reference � � ITU-T Recommendation H. 264, March 2005 "Context-Based Adaptive Binary Arithmetic Coding

Reference � � ITU-T Recommendation H. 264, March 2005 "Context-Based Adaptive Binary Arithmetic Coding in the H. 264/AVC Video Compression Standard, " by Detlev Marpe, IEEE TRANSACTIONS ON CIRCUITS AND SYSTEMS FOR VIDEO TECHNOLOGY, Vol. 13, No. 7, July 2003 Iain E. G. Richardson, “H. 264 and MPEG-4 Video Compression, ” John Wiley & Sons, 2003 Introduction to Multimedia Coding Lecture Slides