xbmc/xbmc — pull request #3156 by Memphiz (2013-08-27 23:48:03+00:00)
Title: [AE/CA] - fix problem where 2 threads read from our lockfree ringbuffer which is not allowed

First 2 commits revert a wrong fix for a race condition which crashed when switching tv channels. That wrong fix introduced the regression reported in the forum here:

http://forum.xbmc.org/showthread.php?tid=148243 (stuttering/no audio after 46 mins, 62mins, 3hours of playback).

The real fix for the crash is in the 3rd commit.

The crash during tv channel switching was because the principal of "1 consumer, 1 producer" was broken. The used lockfree ringbuffer implementation is only thread safe if only 1 thread reads and another thread writes to it.

In the tv channel switching use case the dvdplayeraudio thread flushs the stream which is a read - this happens while the coreaudio thread still pulls frames from the buffer. We end up in invalid buffer state leading to crash in some racy cases.

The solution is to move the flush of the buffer into the coreaudio thread.