Advertisement
Guest User

MFC Fix V4L2 Timestamps

a guest
Jul 22nd, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.64 KB | None | 0 0
  1. diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecMFC.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecMFC.cpp
  2. index 7180daf..cae6b78 100644
  3. --- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecMFC.cpp
  4. +++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecMFC.cpp
  5. @@ -50,11 +50,18 @@
  6.  #define memzero(x) memset(&(x), 0, sizeof (x))
  7.  
  8.  
  9. -union PtsReinterpreter
  10. +static timeval pts2timeval(double pts)
  11.  {
  12. -  int32_t as_int32[2];
  13. -  double as_double;
  14. -};
  15. +  timeval tv;
  16. +  tv.tv_sec = pts/1E6;
  17. +  tv.tv_usec = pts - tv.tv_sec*1E6;
  18. +  return tv;
  19. +}
  20. +static double timeval2pts(timeval tv)
  21. +{
  22. +  return tv.tv_sec*1E6 + tv.tv_usec;
  23. +}
  24. +
  25.  
  26.  #if DIRECT_RENDER_V4L2_BUFFERS
  27.  
  28. @@ -919,11 +926,7 @@ bool CMFCCodec::AddData(const DemuxPacket &packet) {
  29.  
  30.      memcpy((uint8_t *)m_V4l2BufferForNextData.cPlane[0], demuxer_content, demuxer_bytes);
  31.      m_V4l2BufferForNextData.iBytesUsed[0] = demuxer_bytes;
  32. -
  33. -    PtsReinterpreter ptsconv;
  34. -    ptsconv.as_double = pts;
  35. -    m_V4l2BufferForNextData.timeStamp.tv_sec = ptsconv.as_int32[0];
  36. -    m_V4l2BufferForNextData.timeStamp.tv_usec = ptsconv.as_int32[1];
  37. +    m_V4l2BufferForNextData.timeStamp = pts2timeval(pts);
  38.  
  39.      CSingleLock lock(m_criticalSection);
  40.      if (!m_MFCOutput->PushBuffer(&m_V4l2BufferForNextData)) {
  41. @@ -1068,10 +1071,7 @@ void CMFCCodec::PumpBuffers() {
  42.  
  43.      if (m_codecControlFlags & DVD_CODEC_CTRL_DROP) {
  44.        debug_log(LOGDEBUG, "%s::%s - dropping frame with index %d", CLASSNAME, __func__, picture.iIndex);
  45. -      PtsReinterpreter ptsconv;
  46. -      ptsconv.as_int32[0] = picture.timeStamp.tv_sec;
  47. -      ptsconv.as_int32[1] = picture.timeStamp.tv_usec;
  48. -      m_codecPts = ptsconv.as_double;
  49. +      m_codecPts = timeval2pts(picture.timeStamp);
  50.        m_droppedFrames++;
  51.        // directly queue it back to MFC CAPTURE for re-usage since we are in an underrun condition
  52.        debug_log(LOGDEBUG, "%s::%s - requeuing dropped picture %d to MFCCapture", CLASSNAME, __func__, picture.iIndex);
  53. @@ -1122,17 +1122,13 @@ CDVDVideoCodec::VCReturn CMFCCodec::GetPicture(VideoPicture* pDvdVideoPicture) {
  54.  
  55.    int *p_idx= &m_OutputPictures_first_used;
  56.    int *p_idx_min= p_idx;
  57. -  PtsReinterpreter pts_min;
  58. -  pts_min.as_int32[0] = m_OutputPictures[*p_idx_min].timeStamp.tv_sec;
  59. -  pts_min.as_int32[1] = m_OutputPictures[*p_idx_min].timeStamp.tv_usec;
  60. +  double pts_min = timeval2pts(m_OutputPictures[*p_idx_min].timeStamp);
  61.  
  62.    while ( -1 != *(p_idx = &m_OutputPictures[*p_idx].m_next))
  63.    {
  64. -    PtsReinterpreter pts;
  65. -    pts.as_int32[0] = m_OutputPictures[*p_idx].timeStamp.tv_sec;
  66. -    pts.as_int32[1] = m_OutputPictures[*p_idx].timeStamp.tv_usec;
  67. +    double pts = timeval2pts(m_OutputPictures[*p_idx].timeStamp);
  68.      
  69. -    if (pts.as_double < pts_min.as_double)
  70. +    if (pts < pts_min)
  71.      {
  72.        p_idx_min = p_idx;
  73.        pts_min = pts;
  74. @@ -1154,7 +1150,7 @@ CDVDVideoCodec::VCReturn CMFCCodec::GetPicture(VideoPicture* pDvdVideoPicture) {
  75.    //
  76.    if (m_finalFormat == V4L2_PIX_FMT_NV12MT // should only be in use on U3
  77.      && m_resultFormat.iWidth>=1920 && m_resultFormat.iHeight >= 1080
  78. -    && pts_min.as_double > m_codecPts && (pts_min.as_double - m_codecPts) < 30000)
  79. +    && pts_min > m_codecPts && (pts_min - m_codecPts) < 30000)
  80.    {
  81.      ReturnBuffer(&m_OutputPictures[idx_min]);
  82.      m_preferAddData= 3; // next time, prefer VC_BUFFER return value
  83. @@ -1162,7 +1158,7 @@ CDVDVideoCodec::VCReturn CMFCCodec::GetPicture(VideoPicture* pDvdVideoPicture) {
  84.    }
  85.    // -----------------------------------------
  86.  
  87. -  m_codecPts = pts_min.as_double;
  88. +  m_codecPts = pts_min;
  89.  
  90.    // now, fill *pDvdVideoPicture return value
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement