JM14 decoder

http://users.ecel.ufl.edu/~zhifeng/personal/study/Project_Notes.htm#JM14.0:

-------------------------encoder-----------------------------------------

encoder architecture

encoding:
main()-->encode_one_frame()-->frame_picture()--code_a_picture(frame)-->encode_one_slice()-->start_macroblock()/encode_one_macroblock()
void (*encode_one_macroblock) (Macroblock *currMB)==>void encode_one_macroblock_high (Macroblock *currMB);
compute_mode_RD_cost(mode, currMB, enc_mb, &min_rdcost, &min_dcost, &min_rate, i16mode, bslice, &inter_skip);
packetization:
main()-->encode_one_frame()-->writeout_picture()-->writeUnit()
save decoded picture buffer (DPB):
main()-->encode_one_frame()-->store_picture_in_dpb(enc_frame_picture[0])-->insert_picture_in_dpb(dpb.fs[dpb.used_size],p)
in dump_dpb(), we may set DUMP_DPB = 1 to get debug information!
write test_rec.yuv:
main()-->flush_dpb()-->output_one_frame_from_dpb()-->write_stored_frame(dpb.fs[pos], p_dec)-->write_picture(fs->frame, p_out, FRAME)-->write_out_picture(p, p_out)
-->img2buf (p->imgY, buf, p->size_x, p->size_y, symbol_size_in_bytes, crop_left, crop_right, crop_top, crop_bottom)
-->write(p_out, buf, (p->size_y-crop_bottom-crop_top)*(p->size_x-crop_right-crop_left)*symbol_size_in_bytes)

在JM14.0中有兩個結構體比較重要:ImageParametersStorablePicture

    在global.h中定義: ImageParameters用於保存程序運算過程的圖像參數

        1)imgpel mpr [MAX_PLANE][16][16];    用於保存預測的像素值

        2)int m7 [MAX_PLANE][16][16];    用於保存residue data的處理過程臨時數據(註釋寫的有問題“the diff pixel values between the original macroblock/block and its prediction”)

        3)int ****cofAC; / int ***cofDC;    用於保存經過transform和quantization以後的宏塊係數

        4)Slice *currentSlice;

            DataPartition *partArr;

                 Bitstream *bitstream;

                      byte *streamBuffer;    用於保存最終的編碼結果,輸出到test.264

    在mbuffer.h中定義:StorablePicture用於保存圖像處理的結果

        imgpel ** imgY; / imgpel *** imgUV;    用於保存重構圖像的像素值,輸出到test_rec.yuv

        imgpel ** p_curr_img; ??

        short **** mv;    用於保存motion vector的值

這兩個結構體各定義了一個全局變量用來保存圖像的處理結果:

    在lencod.c中定義:ImageParameters images, *img = &images;

    在image.c中定義:StorablePicture *enc_picture;(其實還定義了StorablePicture **enc_frame_picture;但是enc_frame_picture[i]取決於rd_pass變量對i有不同的取值,在實驗中只用到enc_frame_picture[0])

在zhifeng.c和zhifeng.h兩個文件中用到img->mpr,enc_picture->imgY/enc_picture->imgUV和enc_picture->mv來得到所有像素的motion vector和residue data。

---------------------------------------------------

me_fullfast.c中的FastFullPelBlockMotionSearch()函數中:
mcost = block_sad[pos_00[list][ref]] + MV_COST_SMP (lambda_factor, 0, 0, pred_mv[0], pred_mv[1]);
是在根據RDOptimization做rate distortion optimazatin。雖然這裏RateControlEnable=0,但是對於每p幀中任一宏塊都有7中預測模式,理論上用4×4的block得到的distortion最小,但是rate最大,這條語句就是做兩者的balance。
RateControlEnable的設置是對整個video sequence做的。
用-d "*.cfg"不用-f "*.cfg"!!!(-f好像是組合參數,lencod -f "encoder_baseline.cfg"對於沒有修改的JM中的lencod運行出錯)
可以用Bit_Buffer來計算每一幀的大小,但是好像不能計算slice的大小。
image.c:Bit_Buffer[total_frame_buffer] = (int) (stats->bit_ctr - stats->bit_ctr_n);
original圖像:
/ buf = malloc (xs*ys * symbol_size_in_bytes)
image.c-->ReadOneFrame()-->
/ read(p_in, buf, bytes_y)

但是buf的值在ReadOneFrame()最後被釋放:free (buf);
通過imgY_org_frm保存的是16位,高8位爲0x00:
buf2img(imgY_org_frm_JV[0], buf, xs, ys, symbol_size_in_bytes);
buf2img(imgUV_org_frm[0], buf, xs_cr, ys_cr, symbol_size_in_bytes);
buf2img(imgUV_org_frm[1], buf, xs_cr, ys_cr, symbol_size_in_bytes);
重要參數:
stats->bit_ctr_parametersets_n:SPS和PPS的位數
start_sequence()-->stats->bit_ctr_parametersets_n = len;
encode_one_frame()-->stats->bit_ctr_parametersets_n=0;
stats->bit_ctr_n: 當前處理的幀之前的所有位數
encode_one_frame()-->stats->bit_ctr_n = stats->bit_ctr;
stats->bit_ctr: 在ReportFirstframe()中清零!
ReportFirstframe()-->stats->bit_ctr = 0;
ok:
output:
.cfg
ReportFrameStats = 0 # (0:Disable Frame Statistics 1: Enable)
DisplayEncParams = 0 # (0:Disable Display of Encoder Params 1: Enable)
Verbose = 1 # level of display verboseness (0:short, 1:normal, 2:detailed)
in dump_dpb(), we may set DUMP_DPB = 1 to get debug information!
全局變量:
frame_pic
defined in global.h: Picture **frame_pic;
*img:
defined in lencod.c: ImageParameters images, *img = &images;
referenced in global.h: extern ImageParameters *img;
difference between JM13 and JM14:
there is no LoopFilterDisable in JM14, but deblocking filter!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章