Advertisement
Kaidul

H264_NXP.cpp

Nov 27th, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.42 KB | None | 0 0
  1. void* H264Decoder::OutputThread(void *arg)
  2. {
  3.     SET_CURRENT_THREAD_NAME;
  4.     LOG("H264 decoder NXP output thread started.");
  5.    
  6.     H264Decoder *pThis = (H264Decoder *)(arg);
  7.     LV_ImagePlane pOutputPlane[3] = {0};
  8.    
  9.     while (true)
  10.     {
  11.         /* Decode & Extract YUV data (basically the decoded-bytes) */
  12.         M4OSA_ERR err = LVDECODER_VIAVC_GetDecodeOutput(pThis->m_context, &pOutputPlane[0], M4OSA_NULL);
  13.         if(err == M4NO_ERROR)
  14.         {
  15.             /* Valid YUV Frame available */
  16.             /* Store output YUV */
  17.             M4OSA_UInt8 *lpOutput = pThis->m_decoderBuffer.GetFrameBufferPtr(0)->GetBufferPtr();
  18.             M4OSA_UInt8 *lpFrm = NULL;
  19.             int iSize = 0;
  20.            
  21.             /* Write Y,U and V into a linear buffer */
  22.             for(int i = 0; i < 3; i++)
  23.             {
  24.                 lpFrm = pOutputPlane[i].pac_data;
  25.                 if(M4OSA_NULL != lpFrm)
  26.                 {
  27.                     if(pOutputPlane[i].u_width == pOutputPlane[i].u_stride)
  28.                     {
  29.                         /* Copy entire plane at a time */
  30.                         int length = pOutputPlane[i].u_width * pOutputPlane[i].u_height;
  31.                         memcpy(lpOutput, lpFrm, length);
  32.                         lpOutput += length;
  33.                         iSize += length;
  34.                     }
  35.                     else
  36.                     {
  37.                         /* Copy one row at a time, skip the extra portion in the stride */
  38.                         for(int j = 0; j < pOutputPlane[i].u_height; j++)
  39.                         {
  40.                             memcpy(lpOutput, lpFrm, pOutputPlane[i].u_width);
  41.                             lpOutput += pOutputPlane[i].u_width;
  42.                             lpFrm += pOutputPlane[i].u_stride;
  43.                             iSize += pOutputPlane[i].u_width;
  44.                         }
  45.                     }
  46.                 }
  47.             }
  48.            
  49.             pThis->m_captureDimension.m_iWidth = pOutputPlane[0].u_width;
  50.             pThis->m_captureDimension.m_iHeight = pOutputPlane[0].u_height;
  51.             pThis->m_decoderBuffer.SetCaptureDimension(pThis->m_captureDimension);
  52.             pThis->m_decoderBuffer.GetFrameBufferPtr(0)->SetBufferSize(iSize);
  53.            
  54.             /* Mandatory to be called everytime after a call to LVDECODER_VIAVC_GetDecodeOutput() and usage of YUV decoded-data is done */
  55.             LVDECODER_VIAVC_ReleaseDecodeOutput(pThis->m_context, &pOutputPlane[0]);
  56.            
  57.             if (iSize > 0){
  58. #ifdef DUMP_REMOTE_DECODED_STREAM
  59.                 if(g_fph264DecodedStream)
  60.                     fwrite(lpOutput, 1, iSize, g_fph264DecodedStream);
  61. #endif
  62.                
  63.                 if(pThis->TargetBatchProcess(&pThis->m_decoderBuffer) != ES_SUCCESS){
  64.                     LOG("Processing of H264 decoder NXP output returned fail.");
  65.                 }
  66.             }
  67.         }
  68.         else
  69.         {
  70.             /* Handle errors */
  71.            
  72.             /* Mandatory to be called everytime after a call to LVDECODER_VIAVC_GetDecodeOutput() and usage of YUV decoded-data is done */
  73.             LVDECODER_VIAVC_ReleaseDecodeOutput(pThis->m_context, &pOutputPlane[0]);
  74.            
  75.             if(err == M4WAR_NO_MORE_AU)
  76.             {
  77.                 /* End of Stream */
  78.                 LOG("End of stream for H264 decoder NXP");
  79.                 break;
  80.             }
  81.             else if(err == M4WAR_NO_DATA_YET)
  82.             {
  83.                 /* No new YUV data available. Continue supplying some more data for decode */
  84.                 continue;
  85.             }
  86.         }
  87.     }//end while
  88.    
  89.     LOG("H264 decoder NXP output thread ended.");
  90.     return NULL;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement