Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void* H264Decoder::OutputThread(void *arg)
- {
- SET_CURRENT_THREAD_NAME;
- LOG("H264 decoder NXP output thread started.");
- H264Decoder *pThis = (H264Decoder *)(arg);
- LV_ImagePlane pOutputPlane[3] = {0};
- while (true)
- {
- /* Decode & Extract YUV data (basically the decoded-bytes) */
- M4OSA_ERR err = LVDECODER_VIAVC_GetDecodeOutput(pThis->m_context, &pOutputPlane[0], M4OSA_NULL);
- if(err == M4NO_ERROR)
- {
- /* Valid YUV Frame available */
- /* Store output YUV */
- M4OSA_UInt8 *lpOutput = pThis->m_decoderBuffer.GetFrameBufferPtr(0)->GetBufferPtr();
- M4OSA_UInt8 *lpFrm = NULL;
- int iSize = 0;
- /* Write Y,U and V into a linear buffer */
- for(int i = 0; i < 3; i++)
- {
- lpFrm = pOutputPlane[i].pac_data;
- if(M4OSA_NULL != lpFrm)
- {
- if(pOutputPlane[i].u_width == pOutputPlane[i].u_stride)
- {
- /* Copy entire plane at a time */
- int length = pOutputPlane[i].u_width * pOutputPlane[i].u_height;
- memcpy(lpOutput, lpFrm, length);
- lpOutput += length;
- iSize += length;
- }
- else
- {
- /* Copy one row at a time, skip the extra portion in the stride */
- for(int j = 0; j < pOutputPlane[i].u_height; j++)
- {
- memcpy(lpOutput, lpFrm, pOutputPlane[i].u_width);
- lpOutput += pOutputPlane[i].u_width;
- lpFrm += pOutputPlane[i].u_stride;
- iSize += pOutputPlane[i].u_width;
- }
- }
- }
- }
- pThis->m_captureDimension.m_iWidth = pOutputPlane[0].u_width;
- pThis->m_captureDimension.m_iHeight = pOutputPlane[0].u_height;
- pThis->m_decoderBuffer.SetCaptureDimension(pThis->m_captureDimension);
- pThis->m_decoderBuffer.GetFrameBufferPtr(0)->SetBufferSize(iSize);
- /* Mandatory to be called everytime after a call to LVDECODER_VIAVC_GetDecodeOutput() and usage of YUV decoded-data is done */
- LVDECODER_VIAVC_ReleaseDecodeOutput(pThis->m_context, &pOutputPlane[0]);
- if (iSize > 0){
- #ifdef DUMP_REMOTE_DECODED_STREAM
- if(g_fph264DecodedStream)
- fwrite(lpOutput, 1, iSize, g_fph264DecodedStream);
- #endif
- if(pThis->TargetBatchProcess(&pThis->m_decoderBuffer) != ES_SUCCESS){
- LOG("Processing of H264 decoder NXP output returned fail.");
- }
- }
- }
- else
- {
- /* Handle errors */
- /* Mandatory to be called everytime after a call to LVDECODER_VIAVC_GetDecodeOutput() and usage of YUV decoded-data is done */
- LVDECODER_VIAVC_ReleaseDecodeOutput(pThis->m_context, &pOutputPlane[0]);
- if(err == M4WAR_NO_MORE_AU)
- {
- /* End of Stream */
- LOG("End of stream for H264 decoder NXP");
- break;
- }
- else if(err == M4WAR_NO_DATA_YET)
- {
- /* No new YUV data available. Continue supplying some more data for decode */
- continue;
- }
- }
- }//end while
- LOG("H264 decoder NXP output thread ended.");
- return NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement