最近在做voip相關的項目,上位機直接使用linphone進行二次開發,下位機下位機使用的是利用osip、ffmpeg開發的sip用戶端。測試時ffmpeg解碼時列印出如下警告資訊:
Too many slices (17 >= 16), increase MAX_SLICES and recompil Too many slices (18 >= 16), increase MAX_SLICES and recompil Too many slices (20 >= 16), increase MAX_SLICES and recompil ...
相關代碼在h264.c中
... h0->last_slice_type = slice_type; h->slice_num = ++h0->current_slice; if(h->slice_num >= MAX_SLICES){ av_log(s->avctx, AV_LOG_ERROR, "Too many slices (%d >= %d), increase MAX_SLICES and recompile\n", h->slice_num, MAX_SLICES); } ...
顯然slice數超過了定義的最大值,MAX_SLICES定義
/** * The maximum number of slices supported by the decoder. * must be a power of 2 */#define MAX_SLICES 16
嘗試增加到32時,下位機解碼出錯了,沒找到原因,所以從上位機入手。在x264的編碼參數x264_param_t中有slice相關的幾個成員
/* Slicing parameters */ int i_slice_max_size; /* Max size per slice in bytes; includes estimated NAL overhead. */ int i_slice_max_mbs; /* Max number of MBs per slice; overrides i_slice_count. */ int i_slice_count; /* Number of slices per frame: forces rectangular slices. */
這個i_slice_count就指定了分區數量,於是到msx264.c檔案的enc_preprocess函數中,將編碼參數中的i_slice_count設定為15。但是測試發現,這根本沒用。後來在x264源碼中,找到了問題所在
//x264/encoder.c 函數x264_validate_parameters ... if( h->param.i_slice_max_mbs || h->param.i_slice_max_size ) h->param.i_slice_count = 0; ...
從上面的代碼片斷中可以看到,只要i_slice_max_mbs和i_slice_max_size兩個值,i_slice_count就會被清0。而msx264.c的enc_preprocess函數就有下面一條語句
params.i_slice_max_size=ms_get_payload_max_size()-100; /*-100 security margin*/
現在真相大白,直接注釋掉上面的語句,測試通過。