forked from audacity/audacity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not use FFmpeg provide FIFO for the encoder
FFmpeg has changed the FIFO API and the new API is not quite compatible with Audacity exporter
- Loading branch information
Showing
10 changed files
with
169 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/********************************************************************** | ||
Audacity: A Digital Audio Editor | ||
FifoBuffer.h | ||
Dmitry Vedenko | ||
**********************************************************************/ | ||
|
||
#include "FifoBuffer.h" | ||
|
||
#include <algorithm> | ||
|
||
FifoBuffer::Page::Page(size_t size) | ||
: Data(size) | ||
{ | ||
} | ||
|
||
void FifoBuffer::Page::Reset() | ||
{ | ||
WritePosition = 0; | ||
ReadPosition = 0; | ||
} | ||
|
||
FifoBuffer::FifoBuffer(int pageSize) | ||
: mPageSize { pageSize } | ||
{ | ||
} | ||
|
||
int64_t FifoBuffer::Write(const void* dataPtr, int64_t size) | ||
{ | ||
const int8_t* data = static_cast<const int8_t*>(dataPtr); | ||
|
||
auto bytesLeft = size; | ||
|
||
while (bytesLeft > 0) | ||
{ | ||
if ( | ||
mActivePages.empty() || | ||
mActivePages.back()->WritePosition == mPageSize) | ||
{ | ||
if (mFreePages.empty()) | ||
{ | ||
mAllocatedPages.emplace_back(mPageSize); | ||
mFreePages.push_back(&mAllocatedPages.back()); | ||
} | ||
|
||
mActivePages.push_back(mFreePages.back()); | ||
mFreePages.pop_back(); | ||
} | ||
|
||
auto& page = mActivePages.back(); | ||
auto toWrite = std::min( | ||
bytesLeft, static_cast<int64_t>(mPageSize - page->WritePosition)); | ||
|
||
std::copy(data, data + toWrite, page->Data.begin() + page->WritePosition); | ||
page->WritePosition += toWrite; | ||
mAvaliable += toWrite; | ||
|
||
data += toWrite; | ||
bytesLeft -= toWrite; | ||
} | ||
|
||
return size; | ||
} | ||
|
||
int64_t FifoBuffer::Read(void* data, int64_t size) | ||
{ | ||
size = std::min(size, mAvaliable); | ||
|
||
int8_t* dataPtr = static_cast<int8_t*>(data); | ||
|
||
int bytesRead = 0; | ||
|
||
while (size > 0) | ||
{ | ||
auto& page = mActivePages.front(); | ||
auto toRead = | ||
std::min(size, static_cast<int64_t>(mPageSize - page->ReadPosition)); | ||
|
||
std::copy( | ||
page->Data.begin() + page->ReadPosition, | ||
page->Data.begin() + page->ReadPosition + toRead, dataPtr); | ||
page->ReadPosition += toRead; | ||
mAvaliable -= toRead; | ||
|
||
dataPtr += toRead; | ||
size -= toRead; | ||
bytesRead += toRead; | ||
|
||
if (page->ReadPosition == mPageSize) | ||
{ | ||
page->Reset(); | ||
mFreePages.push_back(page); | ||
mActivePages.pop_front(); | ||
} | ||
} | ||
|
||
return bytesRead; | ||
} | ||
|
||
int64_t FifoBuffer::GetAvailable() const | ||
{ | ||
return mAvaliable; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/********************************************************************** | ||
Audacity: A Digital Audio Editor | ||
FifoBuffer.h | ||
Dmitry Vedenko | ||
**********************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <deque> | ||
#include <vector> | ||
|
||
class FFMPEG_SUPPORT_API FifoBuffer final | ||
{ | ||
public: | ||
explicit 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: | ||
struct Page final | ||
{ | ||
explicit Page(size_t size); | ||
|
||
void Reset(); | ||
|
||
std::vector<char> Data; | ||
size_t WritePosition {}; | ||
size_t ReadPosition {}; | ||
}; | ||
|
||
std::deque<Page> mAllocatedPages; | ||
|
||
std::deque<Page*> mActivePages; | ||
std::vector<Page*> mFreePages; | ||
|
||
int64_t mAvaliable {}; | ||
int mPageSize {}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
modules/mod-ffmpeg/lib-ffmpeg-support/wrappers/AVFifoBufferWrapper.cpp
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
modules/mod-ffmpeg/lib-ffmpeg-support/wrappers/AVFifoBufferWrapper.h
This file was deleted.
Oops, something went wrong.