Mpeg: Allow full use of the buffer queue.

Track filled size separately so we can be entirely filled.
This commit is contained in:
Unknown W. Brackets 2021-02-28 08:56:08 -08:00
parent 5d4d8ab418
commit 161ddbeac0
2 changed files with 28 additions and 10 deletions

View File

@ -20,7 +20,7 @@
#include "Core/HW/BufferQueue.h" #include "Core/HW/BufferQueue.h"
void BufferQueue::DoState(PointerWrap &p) { void BufferQueue::DoState(PointerWrap &p) {
auto s = p.Section("BufferQueue", 0, 1); auto s = p.Section("BufferQueue", 0, 2);
Do(p, bufQueueSize); Do(p, bufQueueSize);
Do(p, start); Do(p, start);
@ -31,5 +31,12 @@ void BufferQueue::DoState(PointerWrap &p) {
if (s >= 1) { if (s >= 1) {
Do(p, ptsMarks); Do(p, ptsMarks);
} else {
ptsMarks.clear();
}
if (s >= 2) {
Do(p, filled);
} else {
filled = calcQueueSize();
} }
} }

View File

@ -38,23 +38,19 @@ struct BufferQueue {
if (bufQueue) if (bufQueue)
delete [] bufQueue; delete [] bufQueue;
bufQueue = new unsigned char[size]; bufQueue = new unsigned char[size];
start = 0;
end = 0;
bufQueueSize = size; bufQueueSize = size;
clear();
return true; return true;
} }
void clear() { void clear() {
start = 0; start = 0;
end = 0; end = 0;
filled = 0;
} }
inline int getQueueSize() { inline int getQueueSize() {
if (end >= start) { return filled;
return end - start;
} else {
return bufQueueSize + end - start;
}
} }
inline int getRemainSize() { inline int getRemainSize() {
@ -63,8 +59,7 @@ struct BufferQueue {
bool push(const unsigned char *buf, int addsize, s64 pts = 0) { bool push(const unsigned char *buf, int addsize, s64 pts = 0) {
int space = getRemainSize(); int space = getRemainSize();
// We can't fill entirely, or end will equal start and we'll be empty. if (space < addsize || addsize < 0)
if (space <= addsize || addsize < 0)
return false; return false;
savePts(pts); savePts(pts);
if (end + addsize <= bufQueueSize) { if (end + addsize <= bufQueueSize) {
@ -81,6 +76,8 @@ struct BufferQueue {
memcpy(bufQueue, buf + firstSize, addsize - firstSize); memcpy(bufQueue, buf + firstSize, addsize - firstSize);
end = addsize - firstSize; end = addsize - firstSize;
} }
filled += addsize;
verifyQueueSize();
return true; return true;
} }
@ -109,6 +106,8 @@ struct BufferQueue {
start = bytesgot - firstSize; start = bytesgot - firstSize;
if (start == bufQueueSize) if (start == bufQueueSize)
start = 0; start = 0;
filled -= bytesgot;
verifyQueueSize();
return bytesgot; return bytesgot;
} }
@ -166,10 +165,22 @@ private:
return pts; return pts;
} }
inline int calcQueueSize() {
if (end < start) {
return bufQueueSize + end - start;
}
return end - start;
}
inline void verifyQueueSize() {
_assert_(calcQueueSize() == filled || (end == start && filled == bufQueueSize));
}
uint8_t *bufQueue = nullptr; uint8_t *bufQueue = nullptr;
// Model: end may be less than start, indicating the space between end and start is free. // Model: end may be less than start, indicating the space between end and start is free.
// If end equals start, we're empty. // If end equals start, we're empty.
int start = 0, end = 0; int start = 0, end = 0;
int filled = 0;
int bufQueueSize = 0; int bufQueueSize = 0;
std::map<u32, s64> ptsMarks; std::map<u32, s64> ptsMarks;