find best f_code for ME which do unlimited searches */
| 1863 | |
| 1864 | /* find best f_code for ME which do unlimited searches */ |
| 1865 | int ff_get_best_fcode(MpegEncContext * s, int16_t (*mv_table)[2], int type) |
| 1866 | { |
| 1867 | if(s->me_method>=ME_EPZS){ |
| 1868 | int score[8]; |
| 1869 | int i, y, range= s->avctx->me_range ? s->avctx->me_range : (INT_MAX/2); |
| 1870 | uint8_t * fcode_tab= s->fcode_tab; |
| 1871 | int best_fcode=-1; |
| 1872 | int best_score=-10000000; |
| 1873 | |
| 1874 | if(s->msmpeg4_version) |
| 1875 | range= FFMIN(range, 16); |
| 1876 | else if(s->codec_id == CODEC_ID_MPEG2VIDEO && s->avctx->strict_std_compliance >= FF_COMPLIANCE_NORMAL) |
| 1877 | range= FFMIN(range, 256); |
| 1878 | |
| 1879 | for(i=0; i<8; i++) score[i]= s->mb_num*(8-i); |
| 1880 | |
| 1881 | for(y=0; y<s->mb_height; y++){ |
| 1882 | int x; |
| 1883 | int xy= y*s->mb_stride; |
| 1884 | for(x=0; x<s->mb_width; x++){ |
| 1885 | if(s->mb_type[xy] & type){ |
| 1886 | int mx= mv_table[xy][0]; |
| 1887 | int my= mv_table[xy][1]; |
| 1888 | int fcode= FFMAX(fcode_tab[mx + MAX_MV], |
| 1889 | fcode_tab[my + MAX_MV]); |
| 1890 | int j; |
| 1891 | |
| 1892 | if(mx >= range || mx < -range || |
| 1893 | my >= range || my < -range) |
| 1894 | continue; |
| 1895 | |
| 1896 | for(j=0; j<fcode && j<8; j++){ |
| 1897 | if(s->pict_type==FF_B_TYPE || s->current_picture.mc_mb_var[xy] < s->current_picture.mb_var[xy]) |
| 1898 | score[j]-= 170; |
| 1899 | } |
| 1900 | } |
| 1901 | xy++; |
| 1902 | } |
| 1903 | } |
| 1904 | |
| 1905 | for(i=1; i<8; i++){ |
| 1906 | if(score[i] > best_score){ |
| 1907 | best_score= score[i]; |
| 1908 | best_fcode= i; |
| 1909 | } |
| 1910 | // printf("%d %d\n", i, score[i]); |
| 1911 | } |
| 1912 | |
| 1913 | // printf("fcode: %d type: %d\n", i, s->pict_type); |
| 1914 | return best_fcode; |
| 1915 | /* for(i=0; i<=MAX_FCODE; i++){ |
| 1916 | printf("%d ", mv_num[i]); |
| 1917 | } |
| 1918 | printf("\n");*/ |
| 1919 | }else{ |
| 1920 | return 1; |
| 1921 | } |
| 1922 | } |