Skip to content
This repository
Browse code

Merge pull request #2080 from popcornmix/timestamp_fix2

[rbp] Fix for audio out of sync part 2
  • Loading branch information...
commit 0cfa24e20985d376c4fe4fe41c9e54b4599c6013 2 parents 99a536c + 5f33482
huceke authored January 16, 2013
2  xbmc/cores/omxplayer/OMXAudio.cpp
@@ -866,6 +866,8 @@ unsigned int COMXAudio::AddPackets(const void* data, unsigned int len, double dt
866 866
     if(m_av_clock->AudioStart())
867 867
     {
868 868
       omx_buffer->nFlags = OMX_BUFFERFLAG_STARTTIME;
  869
+      if(pts == DVD_NOPTS_VALUE)
  870
+        omx_buffer->nFlags |= OMX_BUFFERFLAG_TIME_UNKNOWN;
869 871
 
870 872
       m_last_pts = pts;
871 873
 
24  xbmc/cores/omxplayer/OMXVideo.cpp
@@ -84,7 +84,6 @@ COMXVideo::COMXVideo()
84 84
   m_deinterlace       = false;
85 85
   m_hdmi_clock_sync   = false;
86 86
   m_first_frame       = true;
87  
-  m_contains_valid_pts= false;
88 87
 }
89 88
 
90 89
 COMXVideo::~COMXVideo()
@@ -666,6 +665,9 @@ bool COMXVideo::Open(CDVDStreamInfo &hints, OMXClock *clock, bool deinterlace, b
666 665
     m_deinterlace, m_hdmi_clock_sync);
667 666
 
668 667
   m_first_frame   = true;
  668
+  // start from assuming all recent frames had valid pts
  669
+  m_history_valid_pts = ~0;
  670
+
669 671
   return true;
670 672
 }
671 673
 
@@ -720,6 +722,14 @@ unsigned int COMXVideo::GetSize()
720 722
   return m_omx_decoder.GetInputBufferSize();
721 723
 }
722 724
 
  725
+static unsigned count_bits(int32_t value)
  726
+{
  727
+  unsigned bits = 0;
  728
+  for(;value;++bits)
  729
+    value &= value - 1;
  730
+  return bits;
  731
+}
  732
+
723 733
 int COMXVideo::Decode(uint8_t *pData, int iSize, double dts, double pts)
724 734
 {
725 735
   OMX_ERRORTYPE omx_err;
@@ -754,11 +764,11 @@ int COMXVideo::Decode(uint8_t *pData, int iSize, double dts, double pts)
754 764
 
755 765
       omx_buffer->nFlags = 0;
756 766
       omx_buffer->nOffset = 0;
757  
-
758  
-      // if a stream contains any pts values, then use those with UNKNOWNs. Otherwise try using dts.
759  
-      if(pts != DVD_NOPTS_VALUE)
760  
-        m_contains_valid_pts = true;
761  
-      if(pts == DVD_NOPTS_VALUE && !m_contains_valid_pts)
  767
+      // some packed bitstream AVI files set almost all pts values to DVD_NOPTS_VALUE, but have a scattering of real pts values.
  768
+      // the valid pts values match the dts values.
  769
+      // if a stream has had more than 4 valid pts values in the last 16, the use UNKNOWN, otherwise use dts
  770
+      m_history_valid_pts = (m_history_valid_pts << 1) | (pts != DVD_NOPTS_VALUE);
  771
+      if(pts == DVD_NOPTS_VALUE && count_bits(m_history_valid_pts & 0xffff) < 4)
762 772
         pts = dts;
763 773
 
764 774
       if(m_av_clock->VideoStart())
@@ -766,6 +776,8 @@ int COMXVideo::Decode(uint8_t *pData, int iSize, double dts, double pts)
766 776
         // only send dts on first frame to get nearly correct starttime
767 777
         if(pts == DVD_NOPTS_VALUE)
768 778
           pts = dts;
  779
+        if(pts == DVD_NOPTS_VALUE)
  780
+          omx_buffer->nFlags |= OMX_BUFFERFLAG_TIME_UNKNOWN;
769 781
         omx_buffer->nFlags = OMX_BUFFERFLAG_STARTTIME;
770 782
         CLog::Log(LOGDEBUG, "OMXVideo::Decode VDec : setStartTime %f\n", (pts == DVD_NOPTS_VALUE ? 0.0 : pts) / DVD_TIME_BASE);
771 783
         m_av_clock->VideoStart(false);
2  xbmc/cores/omxplayer/OMXVideo.h
@@ -90,7 +90,7 @@ class COMXVideo
90 90
   bool              m_deinterlace;
91 91
   bool              m_hdmi_clock_sync;
92 92
   bool              m_first_frame;
93  
-  bool              m_contains_valid_pts;
  93
+  uint32_t          m_history_valid_pts;
94 94
 
95 95
   bool NaluFormatStartCodes(enum CodecID codec, uint8_t *in_extradata, int in_extrasize);
96 96
 };

0 notes on commit 0cfa24e

Please sign in to comment.
Something went wrong with that request. Please try again.