mirror of
				https://github.com/vdr-projects/vdr.git
				synced 2025-03-01 10:50:46 +00:00 
			
		
		
		
	Fixed margin handling in cRingBufferLinear
This commit is contained in:
		
							
								
								
									
										1
									
								
								HISTORY
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								HISTORY
									
									
									
									
									
								
							| @@ -1961,3 +1961,4 @@ Video Disk Recorder Revision History | |||||||
|  |  | ||||||
| - Fixed high CPU load during replay (thanks Marcel Wiesweg for pointing out this | - Fixed high CPU load during replay (thanks Marcel Wiesweg for pointing out this | ||||||
|   one). |   one). | ||||||
|  | - Fixed margin handling in cRingBufferLinear. | ||||||
|   | |||||||
							
								
								
									
										15
									
								
								ringbuffer.c
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								ringbuffer.c
									
									
									
									
									
								
							| @@ -7,7 +7,7 @@ | |||||||
|  * Parts of this file were inspired by the 'ringbuffy.c' from the |  * Parts of this file were inspired by the 'ringbuffy.c' from the | ||||||
|  * LinuxDVB driver (see linuxtv.org). |  * LinuxDVB driver (see linuxtv.org). | ||||||
|  * |  * | ||||||
|  * $Id: ringbuffer.c 1.13 2003/01/26 19:47:10 kls Exp $ |  * $Id: ringbuffer.c 1.14 2003/02/15 13:21:50 kls Exp $ | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
| #include "ringbuffer.h" | #include "ringbuffer.h" | ||||||
| @@ -34,14 +34,14 @@ cRingBuffer::~cRingBuffer() | |||||||
| void cRingBuffer::WaitForPut(void) | void cRingBuffer::WaitForPut(void) | ||||||
| { | { | ||||||
|   putMutex.Lock(); |   putMutex.Lock(); | ||||||
|   readyForPut.Wait(putMutex); |   readyForPut.TimedWait(putMutex, 1000); | ||||||
|   putMutex.Unlock(); |   putMutex.Unlock(); | ||||||
| } | } | ||||||
|  |  | ||||||
| void cRingBuffer::WaitForGet(void) | void cRingBuffer::WaitForGet(void) | ||||||
| { | { | ||||||
|   getMutex.Lock(); |   getMutex.Lock(); | ||||||
|   readyForGet.Wait(getMutex); |   readyForGet.TimedWait(getMutex, 10); | ||||||
|   getMutex.Unlock(); |   getMutex.Unlock(); | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -102,7 +102,7 @@ int cRingBufferLinear::Put(const uchar *Data, int Count) | |||||||
|      Lock(); |      Lock(); | ||||||
|      int rest = Size() - head; |      int rest = Size() - head; | ||||||
|      int diff = tail - head; |      int diff = tail - head; | ||||||
|      int free = (diff > 0) ? diff - 1 : Size() + diff - (tail < margin ? -(margin - tail) : margin) - 1; |      int free = ((tail < margin) ? rest : (diff > 0) ? diff : Size() + diff - margin) - 1; | ||||||
|      if (statistics) { |      if (statistics) { | ||||||
|         int fill = Size() - free - 1 + Count; |         int fill = Size() - free - 1 + Count; | ||||||
|         if (fill >= Size()) |         if (fill >= Size()) | ||||||
| @@ -136,6 +136,8 @@ int cRingBufferLinear::Put(const uchar *Data, int Count) | |||||||
|         Count = 0; |         Count = 0; | ||||||
|      Unlock(); |      Unlock(); | ||||||
|      EnableGet(); |      EnableGet(); | ||||||
|  |      if (Count == 0) | ||||||
|  |         WaitForPut(); | ||||||
|      } |      } | ||||||
|   return Count; |   return Count; | ||||||
| } | } | ||||||
| @@ -147,7 +149,7 @@ const uchar *cRingBufferLinear::Get(int &Count) | |||||||
|   if (getThreadPid < 0) |   if (getThreadPid < 0) | ||||||
|      getThreadPid = getpid(); |      getThreadPid = getpid(); | ||||||
|   int rest = Size() - tail; |   int rest = Size() - tail; | ||||||
|   if (tail > Size() - margin && head < tail) { |   if (rest < margin && head < tail) { | ||||||
|      int t = margin - rest; |      int t = margin - rest; | ||||||
|      memcpy(buffer + t, buffer + tail, rest); |      memcpy(buffer + t, buffer + tail, rest); | ||||||
|      tail = t; |      tail = t; | ||||||
| @@ -169,10 +171,13 @@ const uchar *cRingBufferLinear::Get(int &Count) | |||||||
| void cRingBufferLinear::Del(int Count) | void cRingBufferLinear::Del(int Count) | ||||||
| { | { | ||||||
|   if (Count > 0 && Count <= lastGet) { |   if (Count > 0 && Count <= lastGet) { | ||||||
|  |      Lock(); | ||||||
|      tail += Count; |      tail += Count; | ||||||
|      lastGet -= Count; |      lastGet -= Count; | ||||||
|      if (tail >= Size()) |      if (tail >= Size()) | ||||||
|         tail = margin; |         tail = margin; | ||||||
|  |      Unlock(); | ||||||
|  |      EnablePut(); | ||||||
|      } |      } | ||||||
|   else |   else | ||||||
|      esyslog("ERROR: invalid Count in cRingBufferLinear::Del: %d", Count); |      esyslog("ERROR: invalid Count in cRingBufferLinear::Del: %d", Count); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user