Showing the changes to test/api/encode_options_test.cpp (1 of 14 files). Show all
Unified · Split
| @@ -1876,3 +1876,183 @@ TEST_F (EncodeDecodeTestAPI, TriggerLoadBalancing) { · 1875 unmodified lines | |||
| 1876 | } | 1876 | } |
| 1877 | } | 1877 | } |
| 1878 | 1878 | ||
| 1879 | ELevelIdc CheckLevelLimitation (SEncParamExt* pParam) { | ||
| 1880 | int32_t iOrder = 0; | ||
| 1881 | ELevelIdc iLevel = LEVEL_5_2; | ||
| 1882 | const SLevelLimits* kpLevelLimit = g_ksLevelLimits; | ||
| 1883 | uint32_t uiPicWidthInMBs = (pParam->sSpatialLayers[0].iVideoWidth + 15) >> 4; | ||
| 1884 | uint32_t uiPicHeightInMBs = (pParam->sSpatialLayers[0].iVideoHeight + 15) >> 4; | ||
| 1885 | uint32_t uiPicInMBs = uiPicWidthInMBs * uiPicHeightInMBs; | ||
| 1886 | uint32_t uiNumRefFrames = pParam->iNumRefFrame; | ||
| 1887 | for (iOrder = 0; iOrder < LEVEL_NUMBER; iOrder++, kpLevelLimit++) { | ||
| 1888 | |||
| 1889 | |||
| 1890 | if (kpLevelLimit->uiMaxMBPS < (uint32_t) (uiPicInMBs * pParam->fMaxFrameRate)) | ||
| 1891 | continue; | ||
| 1892 | |||
| 1893 | if (kpLevelLimit->uiMaxFS < uiPicInMBs) | ||
| 1894 | continue; | ||
| 1895 | |||
| 1896 | if ((kpLevelLimit->uiMaxFS << 3) < (uiPicWidthInMBs * uiPicWidthInMBs)) | ||
| 1897 | continue; | ||
| 1898 | if ((kpLevelLimit->uiMaxFS << 3) < (uiPicHeightInMBs * uiPicHeightInMBs)) | ||
| 1899 | continue; | ||
| 1900 | if (kpLevelLimit->uiMaxDPBMbs < uiNumRefFrames * uiPicInMBs) | ||
| 1901 | continue; | ||
| 1902 | |||
| 1903 | if ((pParam->sSpatialLayers[0].iSpatialBitrate != UNSPECIFIED_BIT_RATE) | ||
| 1904 | && ((int32_t) kpLevelLimit->uiMaxBR * 1200) < | ||
| 1905 | pParam->sSpatialLayers[0].iSpatialBitrate) //RC enabled, considering bitrate constraint | ||
| 1906 | continue; | ||
| 1907 | |||
| 1908 | break; | ||
| 1909 | } | ||
| 1910 | iLevel = kpLevelLimit->uiLevelIdc; | ||
| 1911 | |||
| 1912 | return iLevel; | ||
| 1913 | } | ||
| 1914 | TEST_F (EncodeDecodeTestAPI, ProfileLevelSetting) { | ||
| 1915 | int iWidth = GetRandWidth(); | ||
| 1916 | int iHeight = GetRandHeight(); | ||
| 1917 | float fFrameRate = rand() % 30 + 0.5f; | ||
| 1918 | int iEncFrameNum = 0; | ||
| 1919 | int iSpatialLayerNum = 1; | ||
| 1920 | int iSliceNum = 1; | ||
| 1921 | |||
| 1922 | EProfileIdc profileList[11] = {PRO_UNKNOWN, PRO_BASELINE, PRO_MAIN, | ||
| 1923 | PRO_EXTENDED , PRO_HIGH , PRO_HIGH10, | ||
| 1924 | PRO_HIGH422, PRO_HIGH444, PRO_CAVLC444, | ||
| 1925 | PRO_SCALABLE_BASELINE, | ||
| 1926 | PRO_SCALABLE_HIGH | ||
| 1927 | }; | ||
| 1928 | ELevelIdc levelList[18] = { LEVEL_UNKNOWN, LEVEL_1_0, LEVEL_1_B, LEVEL_1_1, LEVEL_1_2, | ||
| 1929 | LEVEL_1_3, LEVEL_2_0, LEVEL_2_1, LEVEL_2_2, LEVEL_3_0, | ||
| 1930 | LEVEL_3_1, LEVEL_3_2, LEVEL_4_0, LEVEL_4_1, | ||
| 1931 | LEVEL_4_2, LEVEL_5_0, LEVEL_5_1, LEVEL_5_2 | ||
| 1932 | }; | ||
| 1933 | |||
| 1934 | EProfileIdc iEncProfileIdc = PRO_UNKNOWN; | ||
| 1935 | ELevelIdc iEncLevelIdc = LEVEL_UNKNOWN; | ||
| 1936 | |||
| 1937 | EProfileIdc iDecProfileIdc = PRO_UNKNOWN; | ||
| 1938 | ELevelIdc iDecLevelIdc = LEVEL_UNKNOWN; | ||
| 1939 | |||
| 1940 | // prepare params | ||
| 1941 | SEncParamExt sParam; | ||
| 1942 | encoder_->GetDefaultParams (&sParam); | ||
| 1943 | prepareParamDefault (iSpatialLayerNum, iSliceNum, iWidth, iHeight, fFrameRate, &sParam); | ||
| 1944 | sParam.bSimulcastAVC = 1; | ||
| 1945 | sParam.iRCMode = RC_TIMESTAMP_MODE; | ||
| 1946 | sParam.iNumRefFrame = 1; | ||
| 1947 | sParam.fMaxFrameRate = fFrameRate; | ||
| 1948 | sParam.iEntropyCodingModeFlag = rand() % 2; | ||
| 1949 | sParam.sSpatialLayers[0].iSpatialBitrate = sParam.iTargetBitrate = 3000; | ||
| 1950 | |||
| 1951 | //int TraceLevel = WELS_LOG_DEBUG; | ||
| 1952 | //encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &TraceLevel); | ||
| 1953 | //decoder_->SetOption (DECODER_OPTION_TRACE_LEVEL, &TraceLevel); | ||
| 1954 | iEncProfileIdc = profileList[rand() % 11]; | ||
| 1955 | iEncLevelIdc = levelList[rand() % 18]; | ||
| 1956 | sParam.sSpatialLayers[0].uiProfileIdc = iEncProfileIdc; | ||
| 1957 | sParam.sSpatialLayers[0].uiLevelIdc = iEncLevelIdc; | ||
| 1958 | int rv = encoder_->InitializeExt (&sParam); | ||
| 1959 | ASSERT_TRUE (rv == cmResultSuccess) << "InitializeExt: rv = " << rv << " at " << sParam.iPicWidth << "x" << | ||
| 1960 | sParam.iPicHeight; | ||
| 1961 | EncDecOneFrame (sParam.iPicWidth, sParam.iPicHeight, iEncFrameNum++, NULL); | ||
| 1962 | |||
| 1963 | decoder_->GetOption (DECODER_OPTION_PROFILE, &iDecProfileIdc); | ||
| 1964 | |||
| 1965 | if ((iEncProfileIdc != PRO_BASELINE) && (iEncProfileIdc != PRO_MAIN) && (iEncProfileIdc != PRO_HIGH)) { | ||
| 1966 | iEncProfileIdc = PRO_BASELINE; | ||
| 1967 | } | ||
| 1968 | if ((iEncProfileIdc == PRO_BASELINE) && (sParam.iEntropyCodingModeFlag == 1)) | ||
| 1969 | iEncProfileIdc = PRO_MAIN; | ||
| 1970 | |||
| 1971 | |||
| 1972 | ASSERT_TRUE (iDecProfileIdc == iEncProfileIdc) << "enc_profile = " << iEncProfileIdc << " dec_profile = " << | ||
| 1973 | iDecProfileIdc; | ||
| 1974 | |||
| 1975 | //check whether the level is changed according to level limitation | ||
| 1976 | ELevelIdc uiLevel = LEVEL_UNKNOWN; | ||
| 1977 | if (iEncLevelIdc != LEVEL_UNKNOWN) { | ||
| 1978 | uiLevel = CheckLevelLimitation (&sParam) ; | ||
| 1979 | if ((uiLevel == LEVEL_1_B) && | ||
| 1980 | ((iDecProfileIdc == PRO_BASELINE) || (iDecProfileIdc == PRO_MAIN) || (iDecProfileIdc == PRO_EXTENDED))) { | ||
| 1981 | uiLevel = LEVEL_1_1; | ||
| 1982 | } | ||
| 1983 | if (iEncLevelIdc < uiLevel) { | ||
| 1984 | iEncLevelIdc = uiLevel; | ||
| 1985 | } | ||
| 1986 | } | ||
| 1987 | decoder_->GetOption (DECODER_OPTION_LEVEL, &iDecLevelIdc); | ||
| 1988 | |||
| 1989 | if (iEncLevelIdc == LEVEL_UNKNOWN) | ||
| 1990 | ASSERT_TRUE (iDecLevelIdc == LEVEL_5_2) << "enc_level = " << iEncLevelIdc << " dec_level = " << iDecLevelIdc; | ||
| 1991 | else | ||
| 1992 | ASSERT_TRUE (iDecLevelIdc == iEncLevelIdc) << "enc_level = " << iEncLevelIdc << " dec_level = " << iDecLevelIdc; | ||
| 1993 | |||
| 1994 | rv = encoder_->Uninitialize(); | ||
| 1995 | ASSERT_TRUE (rv == cmResultSuccess) << "rv = " << rv; | ||
| 1996 | |||
| 1997 | // new change profile | ||
| 1998 | iEncProfileIdc = profileList[rand() % 10]; | ||
| 1999 | iEncLevelIdc = levelList[rand() % 17]; | ||
| 2000 | sParam.sSpatialLayers[0].uiProfileIdc = iEncProfileIdc; | ||
| 2001 | sParam.sSpatialLayers[0].uiLevelIdc = iEncLevelIdc; | ||
| 2002 | |||
| 2003 | SProfileInfo sProfileInfo; | ||
| 2004 | sProfileInfo.iLayer = 0; | ||
| 2005 | sProfileInfo.uiProfileIdc = iEncProfileIdc; | ||
| 2006 | |||
| 2007 | rv = encoder_->InitializeExt (&sParam); | ||
| 2008 | ASSERT_TRUE (rv == cmResultSuccess) << "InitializeExt: rv = " << rv << " at " << sParam.iPicWidth << "x" << | ||
| 2009 | sParam.iPicHeight; | ||
| 2010 | |||
| 2011 | rv = encoder_->SetOption (ENCODER_OPTION_PROFILE, &sProfileInfo); | ||
| 2012 | ASSERT_TRUE (rv == cmResultSuccess) << "rv = " << rv; | ||
| 2013 | |||
| 2014 | SLevelInfo sLevelInfo; | ||
| 2015 | sLevelInfo.iLayer = 0; | ||
| 2016 | sLevelInfo.uiLevelIdc = iEncLevelIdc; | ||
| 2017 | |||
| 2018 | rv = encoder_->SetOption (ENCODER_OPTION_LEVEL, &sLevelInfo); | ||
| 2019 | ASSERT_TRUE (rv == cmResultSuccess) << "rv = " << rv; | ||
| 2020 | |||
| 2021 | rv = encoder_->ForceIntraFrame (true); | ||
| 2022 | ASSERT_TRUE (rv == cmResultSuccess) << "rv = " << rv; | ||
| 2023 | |||
| 2024 | EncDecOneFrame (sParam.iPicWidth, sParam.iPicHeight, iEncFrameNum++, NULL); | ||
| 2025 | |||
| 2026 | decoder_->GetOption (DECODER_OPTION_PROFILE, &iDecProfileIdc); | ||
| 2027 | |||
| 2028 | if ((iEncProfileIdc != PRO_BASELINE) && (iEncProfileIdc != PRO_MAIN) && (iEncProfileIdc != PRO_HIGH)) { | ||
| 2029 | iEncProfileIdc = PRO_BASELINE; | ||
| 2030 | } | ||
| 2031 | if ((iEncProfileIdc == PRO_BASELINE) && (sParam.iEntropyCodingModeFlag == 1)) | ||
| 2032 | iEncProfileIdc = PRO_MAIN; | ||
| 2033 | |||
| 2034 | |||
| 2035 | ASSERT_TRUE (iDecProfileIdc == iEncProfileIdc) << "enc_profile = " << iEncProfileIdc << " dec_profile = " << | ||
| 2036 | iDecProfileIdc; | ||
| 2037 | |||
| 2038 | //check whether the level is changed according to level limitation | ||
| 2039 | if (iEncLevelIdc != LEVEL_UNKNOWN) { | ||
| 2040 | uiLevel = CheckLevelLimitation (&sParam) ; | ||
| 2041 | if ((uiLevel == LEVEL_1_B) && | ||
| 2042 | ((iDecProfileIdc == PRO_BASELINE) || (iDecProfileIdc == PRO_MAIN) || (iDecProfileIdc == PRO_EXTENDED))) { | ||
| 2043 | uiLevel = LEVEL_1_1; | ||
| 2044 | } | ||
| 2045 | if (iEncLevelIdc < uiLevel) { | ||
| 2046 | iEncLevelIdc = uiLevel; | ||
| 2047 | } | ||
| 2048 | } | ||
| 2049 | decoder_->GetOption (DECODER_OPTION_LEVEL, &iDecLevelIdc); | ||
| 2050 | |||
| 2051 | if (iEncLevelIdc == LEVEL_UNKNOWN) | ||
| 2052 | ASSERT_TRUE (iDecLevelIdc == LEVEL_5_2) << "enc_level = " << iEncLevelIdc << " dec_level = " << iDecLevelIdc; | ||
| 2053 | else | ||
| 2054 | ASSERT_TRUE (iDecLevelIdc == iEncLevelIdc) << "enc_level = " << iEncLevelIdc << " dec_level = " << iDecLevelIdc; | ||
| 2055 | |||
| 2056 | rv = encoder_->Uninitialize(); | ||
| 2057 | ASSERT_TRUE (rv == cmResultSuccess) << "rv = " << rv; | ||
| 2058 | } | ||