Showing the changes to codec/decoder/plus/src/welsDecoderExt.cpp (1 of 6 files). Show all
Unified · Split
| @@ -106,7 +106,7 @@ static DECODING_STATE ConstructAccessUnit (CWelsDecoder* pWelsDecoder, PWelsDec · 105 unmodified lines | ||
| 106 | 106 | } |
| 107 | 107 | pThrCtx->pDec = NULL; |
| 108 | 108 | if (GetThreadCount (pThrCtx->pCtx) > 1) { |
| 109 | − RESET_EVENT (&pThrCtx->sSliceDecodeFinsh); | |
| 109 | + RESET_EVENT (&pThrCtx->sSliceDecodeFinish); | |
| 110 | 110 | } |
| 111 | 111 | iRet |= pWelsDecoder->DecodeFrame2WithCtx (pThrCtx->pCtx, NULL, 0, pThrCtx->ppDst, &pThrCtx->sDstInfo); |
| 112 | 112 | |
| @@ -142,7 +142,8 @@ CWelsDecoder::CWelsDecoder (void) · 29 unmodified lines | ||
| 142 | 142 | m_bFreezeOutput (false), |
| 143 | 143 | m_DecCtxActiveCount (0), |
| 144 | 144 | m_pDecThrCtx (NULL), |
| 145 | − m_pLastDecThrCtx (NULL) { | |
| 145 | + m_pLastDecThrCtx (NULL), | |
| 146 | + m_iLastBufferedIdx (0) { | |
| 146 | 147 | #ifdef OUTPUT_BIT_STREAM |
| 147 | 148 | char chFileName[1024] = { 0 }; //for .264 |
| 148 | 149 | int iBufUsed = 0; |
| @@ -314,7 +315,7 @@ void CWelsDecoder::OpenDecoderThreads() { · 165 unmodified lines | ||
| 314 | 315 | m_pDecThrCtx[i].pDec = NULL; |
| 315 | 316 | CREATE_EVENT (&m_pDecThrCtx[i].sImageReady, 1, 0, NULL); |
| 316 | 317 | CREATE_EVENT (&m_pDecThrCtx[i].sSliceDecodeStart, 1, 0, NULL); |
| 317 | − CREATE_EVENT (&m_pDecThrCtx[i].sSliceDecodeFinsh, 1, 0, NULL); | |
| 318 | + CREATE_EVENT (&m_pDecThrCtx[i].sSliceDecodeFinish, 1, 0, NULL); | |
| 318 | 319 | CREATE_SEMAPHORE (&m_pDecThrCtx[i].sThreadInfo.sIsIdle, 0, 1, NULL); |
| 319 | 320 | CREATE_SEMAPHORE (&m_pDecThrCtx[i].sThreadInfo.sIsActivated, 0, 1, NULL); |
| 320 | 321 | CREATE_THREAD (&m_pDecThrCtx[i].sThreadInfo.sThrHandle, pThrProcInit, (void*) (& (m_pDecThrCtx[i]))); |
| @@ -330,7 +331,7 @@ void CWelsDecoder::CloseDecoderThreads() { · 9 unmodified lines | ||
| 330 | 331 | WAIT_THREAD (&m_pDecThrCtx[i].sThreadInfo.sThrHandle); |
| 331 | 332 | CLOSE_EVENT (&m_pDecThrCtx[i].sImageReady); |
| 332 | 333 | CLOSE_EVENT (&m_pDecThrCtx[i].sSliceDecodeStart); |
| 333 | − CLOSE_EVENT (&m_pDecThrCtx[i].sSliceDecodeFinsh); | |
| 334 | + CLOSE_EVENT (&m_pDecThrCtx[i].sSliceDecodeFinish); | |
| 334 | 335 | CLOSE_SEMAPHORE (&m_pDecThrCtx[i].sThreadInfo.sIsIdle); |
| 335 | 336 | CLOSE_SEMAPHORE (&m_pDecThrCtx[i].sThreadInfo.sIsActivated); |
| 336 | 337 | } |
| @@ -925,14 +926,42 @@ DECODING_STATE CWelsDecoder::FlushFrame (unsigned char** ppDst, · 588 unmodified lines | ||
| 925 | 926 | } |
| 926 | 927 | if (bEndOfStreamFlag && m_sReoderingStatus.iNumOfPicts > 0) { |
| 927 | 928 | m_sReoderingStatus.iMinPOC = IMinInt32; |
| 928 | − for (int32_t i = 0; i <= m_sReoderingStatus.iLargestBufferedPicIndex; ++i) { | |
| 929 | − if (m_sReoderingStatus.iMinPOC == IMinInt32 && m_sPictInfoList[i].iPOC > IMinInt32) { | |
| 930 | − m_sReoderingStatus.iMinPOC = m_sPictInfoList[i].iPOC; | |
| 931 | − m_sReoderingStatus.iPictInfoIndex = i; | |
| 929 | + if (m_bIsBaseline) { | |
| 930 | + uint32_t uiDecodingTimeStamp = 0; | |
| 931 | + int32_t firstValidIdx = -1; | |
| 932 | + for (int32_t i = 0; i <= m_sReoderingStatus.iLargestBufferedPicIndex; ++i) { | |
| 933 | + if (m_sPictInfoList[i].iPOC > IMinInt32) { | |
| 934 | + uiDecodingTimeStamp = m_sPictInfoList[i].uiDecodingTimeStamp; | |
| 935 | + m_sReoderingStatus.iMinPOC = m_sPictInfoList[i].iPOC; | |
| 936 | + m_sReoderingStatus.iPictInfoIndex = i; | |
| 937 | + firstValidIdx = i; | |
| 938 | + break; | |
| 939 | + } | |
| 932 | 940 | } |
| 933 | − if (m_sPictInfoList[i].iPOC > IMinInt32 && m_sPictInfoList[i].iPOC < m_sReoderingStatus.iMinPOC) { | |
| 934 | − m_sReoderingStatus.iMinPOC = m_sPictInfoList[i].iPOC; | |
| 935 | − m_sReoderingStatus.iPictInfoIndex = i; | |
| 941 | + for (int32_t i = 0; i <= m_sReoderingStatus.iLargestBufferedPicIndex; ++i) { | |
| 942 | + if (i == firstValidIdx) continue; | |
| 943 | + if (m_sPictInfoList[i].iPOC > IMinInt32 && m_sPictInfoList[i].uiDecodingTimeStamp < uiDecodingTimeStamp) { | |
| 944 | + uiDecodingTimeStamp = m_sPictInfoList[i].uiDecodingTimeStamp; | |
| 945 | + m_sReoderingStatus.iMinPOC = m_sPictInfoList[i].iPOC; | |
| 946 | + m_sReoderingStatus.iPictInfoIndex = i; | |
| 947 | + } | |
| 948 | + } | |
| 949 | + } else { | |
| 950 | + int32_t firstValidIdx = -1; | |
| 951 | + for (int32_t i = 0; i <= m_sReoderingStatus.iLargestBufferedPicIndex; ++i) { | |
| 952 | + if (m_sReoderingStatus.iMinPOC == IMinInt32 && m_sPictInfoList[i].iPOC > IMinInt32) { | |
| 953 | + m_sReoderingStatus.iMinPOC = m_sPictInfoList[i].iPOC; | |
| 954 | + m_sReoderingStatus.iPictInfoIndex = i; | |
| 955 | + firstValidIdx = i; | |
| 956 | + break; | |
| 957 | + } | |
| 958 | + } | |
| 959 | + for (int32_t i = 0; i <= m_sReoderingStatus.iLargestBufferedPicIndex; ++i) { | |
| 960 | + if (i == firstValidIdx) continue; | |
| 961 | + if (m_sPictInfoList[i].iPOC > IMinInt32 && m_sPictInfoList[i].iPOC < m_sReoderingStatus.iMinPOC) { | |
| 962 | + m_sReoderingStatus.iMinPOC = m_sPictInfoList[i].iPOC; | |
| 963 | + m_sReoderingStatus.iPictInfoIndex = i; | |
| 964 | + } | |
| 936 | 965 | } |
| 937 | 966 | } |
| 938 | 967 | } |
| @@ -940,7 +969,8 @@ DECODING_STATE CWelsDecoder::FlushFrame (unsigned char** ppDst, · 1 unmodified line | ||
| 940 | 969 | m_sReoderingStatus.iLastWrittenPOC = m_sReoderingStatus.iMinPOC; |
| 941 | 970 | #if defined (_DEBUG) |
| 942 | 971 | #ifdef _MOTION_VECTOR_DUMP_ |
| 943 | − fprintf (stderr, "Output POC: #%d\n", m_sReoderingStatus.iLastWrittenPOC); | |
| 972 | + fprintf (stderr, "Output POC: #%d uiDecodingTimeStamp=%d\n", m_sReoderingStatus.iLastWrittenPOC, | |
| 973 | + m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].uiDecodingTimeStamp); | |
| 944 | 974 | #endif |
| 945 | 975 | #endif |
| 946 | 976 | memcpy (pDstInfo, &m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].sBufferInfo, sizeof (SBufferInfo)); |
| @@ -1051,6 +1081,7 @@ void CWelsDecoder::BufferingReadyPicture (PWelsDecoderContext pCtx, unsigned cha · 104 unmodified lines | ||
| 1051 | 1081 | m_sPictInfoList[i].iPicBuffIdx = pCtx->pLastDecPicInfo->pPreviousDecodedPictureInDpb->iPicBuffIdx; |
| 1052 | 1082 | if (GetThreadCount (pCtx) <= 1) ++pCtx->pLastDecPicInfo->pPreviousDecodedPictureInDpb->iRefCount; |
| 1053 | 1083 | m_sPictInfoList[i].bLastGOP = false; |
| 1084 | + m_iLastBufferedIdx = i; | |
| 1054 | 1085 | pDstInfo->iBufferStatus = 0; |
| 1055 | 1086 | ++m_sReoderingStatus.iNumOfPicts; |
| 1056 | 1087 | if (i > m_sReoderingStatus.iLargestBufferedPicIndex) { |
| @@ -1069,11 +1100,17 @@ void CWelsDecoder::ReleaseBufferedReadyPicture (PWelsDecoderContext pCtx, unsign · 12 unmodified lines | ||
| 1069 | 1100 | } |
| 1070 | 1101 | if (!m_bIsBaseline && m_sReoderingStatus.iLastGOPRemainPicts > 0) { |
| 1071 | 1102 | m_sReoderingStatus.iMinPOC = IMinInt32; |
| 1103 | + int32_t firstValidIdx = -1; | |
| 1072 | 1104 | for (int32_t i = 0; i <= m_sReoderingStatus.iLargestBufferedPicIndex; ++i) { |
| 1073 | 1105 | if (m_sReoderingStatus.iMinPOC == IMinInt32 && m_sPictInfoList[i].iPOC > IMinInt32 && m_sPictInfoList[i].bLastGOP) { |
| 1074 | 1106 | m_sReoderingStatus.iMinPOC = m_sPictInfoList[i].iPOC; |
| 1075 | 1107 | m_sReoderingStatus.iPictInfoIndex = i; |
| 1108 | + firstValidIdx = i; | |
| 1109 | + break; | |
| 1076 | 1110 | } |
| 1111 | + } | |
| 1112 | + for (int32_t i = 0; i <= m_sReoderingStatus.iLargestBufferedPicIndex; ++i) { | |
| 1113 | + if (i == firstValidIdx) continue; | |
| 1077 | 1114 | if (m_sPictInfoList[i].iPOC > IMinInt32 && m_sPictInfoList[i].iPOC < m_sReoderingStatus.iMinPOC |
| 1078 | 1115 | && m_sPictInfoList[i].bLastGOP) { |
| 1079 | 1116 | m_sReoderingStatus.iMinPOC = m_sPictInfoList[i].iPOC; |
| @@ -1083,7 +1120,8 @@ void CWelsDecoder::ReleaseBufferedReadyPicture (PWelsDecoderContext pCtx, unsign · 3 unmodified lines | ||
| 1083 | 1120 | m_sReoderingStatus.iLastWrittenPOC = m_sReoderingStatus.iMinPOC; |
| 1084 | 1121 | #if defined (_DEBUG) |
| 1085 | 1122 | #ifdef _MOTION_VECTOR_DUMP_ |
| 1086 | − fprintf (stderr, "Output POC: #%d\n", m_sReoderingStatus.iLastWrittenPOC); | |
| 1123 | + fprintf (stderr, "Output POC: #%d uiDecodingTimeStamp=%d\n", m_sReoderingStatus.iLastWrittenPOC, | |
| 1124 | + m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].uiDecodingTimeStamp); | |
| 1087 | 1125 | #endif |
| 1088 | 1126 | #endif |
| 1089 | 1127 | memcpy (pDstInfo, &m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].sBufferInfo, sizeof (SBufferInfo)); |
| @@ -1104,21 +1142,29 @@ void CWelsDecoder::ReleaseBufferedReadyPicture (PWelsDecoderContext pCtx, unsign · 14 unmodified lines | ||
| 1104 | 1142 | } |
| 1105 | 1143 | if (m_sReoderingStatus.iNumOfPicts && m_bIsBaseline) { |
| 1106 | 1144 | uint32_t uiDecodingTimeStamp = 0; |
| 1145 | + int32_t firstValidIdx = -1; | |
| 1107 | 1146 | for (int32_t i = 0; i <= m_sReoderingStatus.iLargestBufferedPicIndex; ++i) { |
| 1108 | 1147 | if (m_sPictInfoList[i].iPOC > IMinInt32) { |
| 1109 | 1148 | uiDecodingTimeStamp = m_sPictInfoList[i].uiDecodingTimeStamp; |
| 1110 | 1149 | m_sReoderingStatus.iPictInfoIndex = i; |
| 1150 | + firstValidIdx = i; | |
| 1111 | 1151 | break; |
| 1112 | 1152 | } |
| 1113 | 1153 | } |
| 1114 | 1154 | for (int32_t i = 0; i <= m_sReoderingStatus.iLargestBufferedPicIndex; ++i) { |
| 1115 | − if (m_sReoderingStatus.iPictInfoIndex != i && m_sPictInfoList[i].iPOC > IMinInt32 | |
| 1116 | − && m_sPictInfoList[i].sBufferInfo.uiInBsTimeStamp < uiDecodingTimeStamp) { | |
| 1155 | + if (i == firstValidIdx) continue; | |
| 1156 | + if (m_sPictInfoList[i].iPOC > IMinInt32 && m_sPictInfoList[i].uiDecodingTimeStamp < uiDecodingTimeStamp) { | |
| 1117 | 1157 | uiDecodingTimeStamp = m_sPictInfoList[i].uiDecodingTimeStamp; |
| 1118 | 1158 | m_sReoderingStatus.iPictInfoIndex = i; |
| 1119 | 1159 | } |
| 1120 | 1160 | } |
| 1121 | 1161 | if (uiDecodingTimeStamp > 0) { |
| 1162 | +#if defined (_DEBUG) | |
| 1163 | +#ifdef _MOTION_VECTOR_DUMP_ | |
| 1164 | + fprintf (stderr, "Output POC: #%d uiDecodingTimeStamp=%d\n", m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].iPOC, | |
| 1165 | + uiDecodingTimeStamp); | |
| 1166 | +#endif | |
| 1167 | +#endif | |
| 1122 | 1168 | memcpy (pDstInfo, &m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].sBufferInfo, sizeof (SBufferInfo)); |
| 1123 | 1169 | ppDst[0] = pDstInfo->pDst[0]; |
| 1124 | 1170 | ppDst[1] = pDstInfo->pDst[1]; |
| @@ -1132,11 +1178,17 @@ void CWelsDecoder::ReleaseBufferedReadyPicture (PWelsDecoderContext pCtx, unsign · 7 unmodified lines | ||
| 1132 | 1178 | } |
| 1133 | 1179 | if (m_sReoderingStatus.iNumOfPicts > 0) { |
| 1134 | 1180 | m_sReoderingStatus.iMinPOC = IMinInt32; |
| 1181 | + int32_t firstValidIdx = -1; | |
| 1135 | 1182 | for (int32_t i = 0; i <= m_sReoderingStatus.iLargestBufferedPicIndex; ++i) { |
| 1136 | 1183 | if (m_sReoderingStatus.iMinPOC == IMinInt32 && m_sPictInfoList[i].iPOC > IMinInt32) { |
| 1137 | 1184 | m_sReoderingStatus.iMinPOC = m_sPictInfoList[i].iPOC; |
| 1138 | 1185 | m_sReoderingStatus.iPictInfoIndex = i; |
| 1186 | + firstValidIdx = i; | |
| 1187 | + break; | |
| 1139 | 1188 | } |
| 1189 | + } | |
| 1190 | + for (int32_t i = 0; i <= m_sReoderingStatus.iLargestBufferedPicIndex; ++i) { | |
| 1191 | + if (i == firstValidIdx) continue; | |
| 1140 | 1192 | if (m_sPictInfoList[i].iPOC > IMinInt32 && m_sPictInfoList[i].iPOC < m_sReoderingStatus.iMinPOC) { |
| 1141 | 1193 | m_sReoderingStatus.iMinPOC = m_sPictInfoList[i].iPOC; |
| 1142 | 1194 | m_sReoderingStatus.iPictInfoIndex = i; |
| @@ -1144,20 +1196,16 @@ void CWelsDecoder::ReleaseBufferedReadyPicture (PWelsDecoderContext pCtx, unsign · 1 unmodified line | ||
| 1144 | 1196 | } |
| 1145 | 1197 | } |
| 1146 | 1198 | if (m_sReoderingStatus.iMinPOC > IMinInt32) { |
| 1147 | − bool isReady = false; | |
| 1148 | − if (pCtx != NULL) { | |
| 1149 | − isReady = (m_sReoderingStatus.iLastWrittenPOC > IMinInt32 | |
| 1150 | − && m_sReoderingStatus.iMinPOC - m_sReoderingStatus.iLastWrittenPOC <= 1) | |
| 1151 | − || m_sReoderingStatus.iMinPOC < pCtx->pSliceHeader->iPicOrderCntLsb; | |
| 1152 | − } else { | |
| 1153 | − isReady = m_sReoderingStatus.iMinPOC == 0 || (m_sReoderingStatus.iLastWrittenPOC >= 0 | |
| 1154 | − && m_sReoderingStatus.iMinPOC <= m_sReoderingStatus.iLastWrittenPOC + 2) ; | |
| 1155 | − } | |
| 1199 | + int32_t iLastPOC = pCtx != NULL ? pCtx->pSliceHeader->iPicOrderCntLsb : m_sPictInfoList[m_iLastBufferedIdx].iPOC; | |
| 1200 | + bool isReady = (m_sReoderingStatus.iLastWrittenPOC > IMinInt32 | |
| 1201 | + && m_sReoderingStatus.iMinPOC - m_sReoderingStatus.iLastWrittenPOC <= 1) | |
| 1202 | + || m_sReoderingStatus.iMinPOC < iLastPOC; | |
| 1156 | 1203 | if (isReady) { |
| 1157 | 1204 | m_sReoderingStatus.iLastWrittenPOC = m_sReoderingStatus.iMinPOC; |
| 1158 | 1205 | #if defined (_DEBUG) |
| 1159 | 1206 | #ifdef _MOTION_VECTOR_DUMP_ |
| 1160 | − fprintf (stderr, "Output POC: #%d\n", m_sReoderingStatus.iLastWrittenPOC); | |
| 1207 | + fprintf (stderr, "Output POC: #%d uiDecodingTimeStamp=%d\n", m_sReoderingStatus.iLastWrittenPOC, | |
| 1208 | + m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].uiDecodingTimeStamp); | |
| 1161 | 1209 | #endif |
| 1162 | 1210 | #endif |
| 1163 | 1211 | memcpy (pDstInfo, &m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].sBufferInfo, sizeof (SBufferInfo)); |