<div dir="ltr">On Wed, Jul 27, 2016 at 8:25 AM MythTV <<a href="mailto:noreply@mythtv.org">noreply@mythtv.org</a>> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">#12827: Raspberry Pi: Digital Audio does not work<br>
----------------------------------+-----------------------------<br>
 Reporter:  pbennett              |          Owner:  pbennett<br>
     Type:  Bug Report - General  |         Status:  accepted<br>
 Priority:  minor                 |      Milestone:  unknown<br>
Component:  Ports - rPi           |        Version:  Master Head<br>
 Severity:  medium                |     Resolution:<br>
 Keywords:                        |  Ticket locked:  0<br>
----------------------------------+-----------------------------<br>
<br>
Comment (by pbennett):<br>
<br>
 Output of Dolby digital passthru audio to a surround sound system works<br>
 and gives sound, but the audio  and video are jerky. This is because the<br>
 omx audio system seems to give incorrect and inconsistent values for audio<br>
 latency (i.e. amount of audio in the sound card that has not yet been<br>
 played). The result is that AVSync reports Video is behind audio (too<br>
 slow) for a few seconds and drops some frames to fix it, then reports that<br>
 Video is ahead of audio for a few seconds, and slows video down to<br>
 compensate. Thus the video is alternately speeded up and slowed down every<br>
 few seconds and the audio is paused and restarted every few seconds.<br>
<br>
 The audio latency values are incorrect only in the digital passthru case.<br>
 If playing digital stereo or analog, it works perfectly.<br>
<br>
 If I set very high values for MAXDIVERGE and DIVERGELIMIT so that AVSync<br>
 ignores the errors, the video plays very well. 5.1 channel Dolby Digital<br>
 audio is good, the surround sound receiver reports it as Dolby Digital.<br>
 The video is in good sync with the sound. However this is not a solution,<br>
 it will certainly get out of sync soon.<br>
<br>
 Options<br>
<br>
 1. Try to get some code that will estimate the latency based on amount of<br>
 data passed in and elapsed time. I am afraid this would also gradually get<br>
 worse over time. Also I am not sure how to handle pauses.<br>
<br>
 2. Try to minimize latency by passing data to audio only when it is<br>
 needed. This is difficult because audio is in a ring buffer before going<br>
 to the sound device and the ring buffer does not keep track of time codes.<br>
<br>
 3. Assume some fixed value for sound card latency all the time.<br>
<br>
 4. Average the sync calculation over 30, 75, 100, or 300 frames. Currently<br>
 it is averaged over 4 frames. This assumes that on average over time the<br>
 sound card latencies will be correct. I am afraid this may cause other<br>
 problems, for example when using softblend and displaying OSD the AVSync<br>
 has to compensate for the extra CPU load by dropping some frames. That<br>
 works well but will not work with the averaging calculation.<br>
<br>
 I am not sure how to proceed.<br></blockquote><div><br></div><div>On first blush, I would be tempted to go with (2) and change the ringbuffer to track time codes.  I am not familiar with that code, though, so I don't know how hard or practical that is.<br><br></div><div>John<br> <br></div></div></div>