Audacity 3.2.0
Classes | Public Member Functions | Private Attributes | List of all members
FifoBuffer Class Referencefinal

#include <FifoBuffer.h>

Collaboration diagram for FifoBuffer:
[legend]

Classes

struct  Page
 

Public Member Functions

 FifoBuffer (int pageSize)
 
int64_t Write (const void *data, int64_t size)
 
int64_t Read (void *data, int64_t size)
 
int64_t GetAvailable () const
 

Private Attributes

std::deque< PagemAllocatedPages
 
std::queue< Page * > mActivePages
 
std::deque< Page * > mFreePages
 
int64_t mAvaliable {}
 
const int mPageSize {}
 

Detailed Description

Definition at line 17 of file FifoBuffer.h.

Constructor & Destructor Documentation

◆ FifoBuffer()

FifoBuffer::FifoBuffer ( int  pageSize)
explicit

Definition at line 26 of file FifoBuffer.cpp.

27 : mPageSize { pageSize }
28{
29}
const int mPageSize
Definition: FifoBuffer.h:45

Member Function Documentation

◆ GetAvailable()

int64_t FifoBuffer::GetAvailable ( ) const

Definition at line 103 of file FifoBuffer.cpp.

104{
105 return mAvaliable;
106}
int64_t mAvaliable
Definition: FifoBuffer.h:44

References mAvaliable.

◆ Read()

int64_t FifoBuffer::Read ( void *  data,
int64_t  size 
)

Definition at line 68 of file FifoBuffer.cpp.

69{
71
72 int8_t* dataPtr = static_cast<int8_t*>(data);
73
74 int bytesRead = 0;
75
76 while (size > 0)
77 {
78 auto& page = mActivePages.front();
79 auto toRead =
80 std::min(size, static_cast<int64_t>(mPageSize - page->ReadPosition));
81
83 page->Data.begin() + page->ReadPosition,
84 page->Data.begin() + page->ReadPosition + toRead, dataPtr);
85 page->ReadPosition += toRead;
86 mAvaliable -= toRead;
87
88 dataPtr += toRead;
89 size -= toRead;
90 bytesRead += toRead;
91
92 if (page->ReadPosition == mPageSize)
93 {
94 page->Reset();
95 mFreePages.push_back(page);
96 mActivePages.pop();
97 }
98 }
99
100 return bytesRead;
101}
int min(int a, int b)
std::deque< Page * > mFreePages
Definition: FifoBuffer.h:42
std::queue< Page * > mActivePages
Definition: FifoBuffer.h:41
void copy(const T *src, T *dst, int32_t n)
Definition: VectorOps.h:40

References staffpad::vo::copy(), mActivePages, mAvaliable, mFreePages, min(), mPageSize, and size.

Here is the call graph for this function:

◆ Write()

int64_t FifoBuffer::Write ( const void *  data,
int64_t  size 
)

Definition at line 31 of file FifoBuffer.cpp.

32{
33 const int8_t* data = static_cast<const int8_t*>(dataPtr);
34
35 auto bytesLeft = size;
36
37 while (bytesLeft > 0)
38 {
39 if (
40 mActivePages.empty() ||
41 mActivePages.back()->WritePosition == mPageSize)
42 {
43 if (mFreePages.empty())
44 {
45 mAllocatedPages.emplace_back(mPageSize);
46 mFreePages.push_back(&mAllocatedPages.back());
47 }
48
49 mActivePages.push(mFreePages.back());
50 mFreePages.pop_back();
51 }
52
53 auto& page = mActivePages.back();
54 auto toWrite = std::min(
55 bytesLeft, static_cast<int64_t>(mPageSize - page->WritePosition));
56
57 std::copy(data, data + toWrite, page->Data.begin() + page->WritePosition);
58 page->WritePosition += toWrite;
59 mAvaliable += toWrite;
60
61 data += toWrite;
62 bytesLeft -= toWrite;
63 }
64
65 return size;
66}
std::deque< Page > mAllocatedPages
Definition: FifoBuffer.h:39

References staffpad::vo::copy(), mActivePages, mAllocatedPages, mAvaliable, mFreePages, min(), mPageSize, and size.

Here is the call graph for this function:

Member Data Documentation

◆ mActivePages

std::queue<Page*> FifoBuffer::mActivePages
private

Definition at line 41 of file FifoBuffer.h.

Referenced by Read(), and Write().

◆ mAllocatedPages

std::deque<Page> FifoBuffer::mAllocatedPages
private

Definition at line 39 of file FifoBuffer.h.

Referenced by Write().

◆ mAvaliable

int64_t FifoBuffer::mAvaliable {}
private

Definition at line 44 of file FifoBuffer.h.

Referenced by GetAvailable(), Read(), and Write().

◆ mFreePages

std::deque<Page*> FifoBuffer::mFreePages
private

Definition at line 42 of file FifoBuffer.h.

Referenced by Read(), and Write().

◆ mPageSize

const int FifoBuffer::mPageSize {}
private

Definition at line 45 of file FifoBuffer.h.

Referenced by Read(), and Write().


The documentation for this class was generated from the following files: