mirror of
https://github.com/Lorenzooone/cc3dsfs.git
synced 2026-09-11 18:15:24 -05:00
Switch to buffer requests without memcpy
Some checks are pending
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:linux32 flags:32 name:Linux GCC 32 os:ubuntu-latest]) (push) Waiting to run
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:linux64 flags:64 name:Linux GCC x64 os:ubuntu-latest]) (push) Waiting to run
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:linuxarm32 flags:arm32 name:Linux GCC ARM 32 os:ubuntu-latest]) (push) Waiting to run
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:linuxarm64 flags:arm64 name:Linux GCC ARM 64 os:ubuntu-latest]) (push) Waiting to run
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:macos name:macOS Apple Silicon os:macos-14]) (push) Waiting to run
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:win32 flags:-A Win32 name:Windows VS2022 Win32 os:windows-2022]) (push) Waiting to run
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:win64 flags:-A x64 name:Windows VS2022 x64 os:windows-2022]) (push) Waiting to run
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:winarm64 flags:-A ARM64 name:Windows VS2022 ARM os:windows-2022]) (push) Waiting to run
CD / Create Pi Mono Setup (push) Blocked by required conditions
CD / Publishing (push) Blocked by required conditions
Some checks are pending
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:linux32 flags:32 name:Linux GCC 32 os:ubuntu-latest]) (push) Waiting to run
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:linux64 flags:64 name:Linux GCC x64 os:ubuntu-latest]) (push) Waiting to run
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:linuxarm32 flags:arm32 name:Linux GCC ARM 32 os:ubuntu-latest]) (push) Waiting to run
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:linuxarm64 flags:arm64 name:Linux GCC ARM 64 os:ubuntu-latest]) (push) Waiting to run
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:macos name:macOS Apple Silicon os:macos-14]) (push) Waiting to run
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:win32 flags:-A Win32 name:Windows VS2022 Win32 os:windows-2022]) (push) Waiting to run
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:win64 flags:-A x64 name:Windows VS2022 x64 os:windows-2022]) (push) Waiting to run
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:winarm64 flags:-A ARM64 name:Windows VS2022 ARM os:windows-2022]) (push) Waiting to run
CD / Create Pi Mono Setup (push) Blocked by required conditions
CD / Publishing (push) Blocked by required conditions
This commit is contained in:
@@ -3,7 +3,10 @@
|
||||
|
||||
CaptureDataBuffers::CaptureDataBuffers() {
|
||||
last_curr_in = 0;
|
||||
curr_writer_pos = -1;
|
||||
for(int i = 0; i < NUM_CONCURRENT_DATA_BUFFER_WRITERS; i++) {
|
||||
curr_writer_pos[i] = -1;
|
||||
is_being_written_to[i] = false;
|
||||
}
|
||||
for(int i = 0; i < NUM_CONCURRENT_DATA_BUFFER_READERS; i++)
|
||||
curr_reader_pos[i] = -1;
|
||||
for(int i = 0; i < NUM_CONCURRENT_DATA_BUFFERS; i++) {
|
||||
@@ -24,13 +27,19 @@ static int reader_to_index(CaptureReaderType reader_type) {
|
||||
}
|
||||
}
|
||||
|
||||
static bool is_writer_index_valid(int index) {
|
||||
if((index < 0) || (index >= NUM_CONCURRENT_DATA_BUFFER_WRITERS))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
CaptureDataSingleBuffer* CaptureDataBuffers::GetReaderBuffer(CaptureReaderType reader_type) {
|
||||
int index = reader_to_index(reader_type);
|
||||
CaptureDataSingleBuffer* retval = NULL;
|
||||
access_mutex.lock();
|
||||
if(curr_reader_pos[index] != -1)
|
||||
retval = &buffers[curr_reader_pos[index]];
|
||||
else if(!has_read_data[last_curr_in][index]) {
|
||||
return &buffers[curr_reader_pos[index]];
|
||||
access_mutex.lock();
|
||||
if(!has_read_data[last_curr_in][index]) {
|
||||
has_read_data[last_curr_in][index] = true;
|
||||
num_readers[last_curr_in] += 1;
|
||||
retval = &buffers[last_curr_in];
|
||||
@@ -40,61 +49,84 @@ CaptureDataSingleBuffer* CaptureDataBuffers::GetReaderBuffer(CaptureReaderType r
|
||||
return retval;
|
||||
}
|
||||
|
||||
CaptureDataSingleBuffer* CaptureDataBuffers::GetWriterBuffer() {
|
||||
CaptureDataSingleBuffer* CaptureDataBuffers::GetWriterBuffer(int index) {
|
||||
if(!is_writer_index_valid(index))
|
||||
return NULL;
|
||||
if(curr_writer_pos[index] != -1)
|
||||
return &buffers[curr_writer_pos[index]];
|
||||
CaptureDataSingleBuffer* retval = NULL;
|
||||
access_mutex.lock();
|
||||
if(curr_writer_pos != -1)
|
||||
retval = &buffers[curr_writer_pos];
|
||||
else
|
||||
for(int i = 0; i < NUM_CONCURRENT_DATA_BUFFERS; i++)
|
||||
if((num_readers[i] == 0) && (i != last_curr_in)) {
|
||||
retval = &buffers[i];
|
||||
curr_writer_pos = i;
|
||||
for(int j = 0; j < NUM_CONCURRENT_DATA_BUFFER_READERS; j++)
|
||||
has_read_data[i][j] = false;
|
||||
break;
|
||||
}
|
||||
for(int i = 0; i < NUM_CONCURRENT_DATA_BUFFERS; i++)
|
||||
if((num_readers[i] == 0) && (i != last_curr_in) && (!is_being_written_to[i])) {
|
||||
retval = &buffers[i];
|
||||
is_being_written_to[i] = true;
|
||||
curr_writer_pos[index] = i;
|
||||
for(int j = 0; j < NUM_CONCURRENT_DATA_BUFFER_READERS; j++)
|
||||
has_read_data[i][j] = true;
|
||||
break;
|
||||
}
|
||||
access_mutex.unlock();
|
||||
return retval;
|
||||
}
|
||||
|
||||
void CaptureDataBuffers::ReleaseReaderBuffer(CaptureReaderType reader_type) {
|
||||
int index = reader_to_index(reader_type);
|
||||
if(curr_reader_pos[index] == -1)
|
||||
return;
|
||||
access_mutex.lock();
|
||||
if(curr_reader_pos[index] != -1) {
|
||||
num_readers[curr_reader_pos[index]] -= 1;
|
||||
curr_reader_pos[index] = -1;
|
||||
}
|
||||
num_readers[curr_reader_pos[index]] -= 1;
|
||||
curr_reader_pos[index] = -1;
|
||||
access_mutex.unlock();
|
||||
}
|
||||
|
||||
void CaptureDataBuffers::ReleaseWriterBuffer() {
|
||||
void CaptureDataBuffers::ReleaseWriterBuffer(int index, bool update_last_curr_in) {
|
||||
if(!is_writer_index_valid(index))
|
||||
return;
|
||||
if(curr_writer_pos[index] == -1)
|
||||
return;
|
||||
access_mutex.lock();
|
||||
if(curr_writer_pos != -1) {
|
||||
buffers[curr_writer_pos].inner_index = inner_index++;
|
||||
last_curr_in = curr_writer_pos;
|
||||
curr_writer_pos = -1;
|
||||
if(update_last_curr_in) {
|
||||
for(int j = 0; j < NUM_CONCURRENT_DATA_BUFFER_READERS; j++)
|
||||
has_read_data[curr_writer_pos[index]][j] = false;
|
||||
last_curr_in = curr_writer_pos[index];
|
||||
}
|
||||
is_being_written_to[curr_writer_pos[index]] = false;
|
||||
curr_writer_pos[index] = -1;
|
||||
access_mutex.unlock();
|
||||
}
|
||||
|
||||
void CaptureDataBuffers::WriteToBuffer(CaptureReceived* buffer, uint64_t read, double time_in_buf, CaptureDevice* device, CaptureScreensType capture_type, size_t offset) {
|
||||
void CaptureDataBuffers::WriteToBuffer(CaptureReceived* buffer, uint64_t read, double time_in_buf, CaptureDevice* device, CaptureScreensType capture_type, size_t offset, int index) {
|
||||
if(offset >= read)
|
||||
return;
|
||||
CaptureDataSingleBuffer* target = this->GetWriterBuffer();
|
||||
if(!is_writer_index_valid(index))
|
||||
return;
|
||||
CaptureDataSingleBuffer* target = this->GetWriterBuffer(index);
|
||||
// How did we end here?!
|
||||
if(target == NULL)
|
||||
return;
|
||||
memcpy(&target->capture_buf, ((uint8_t*)buffer) + offset, read - offset);
|
||||
// Make sure to also copy the extra needed data, if any
|
||||
if((device->cc_type == CAPTURE_CONN_USB) && (!device->is_3ds))
|
||||
memcpy(&target->capture_buf.usb_received_old_ds.frameinfo, &buffer->usb_received_old_ds.frameinfo, sizeof(buffer->usb_received_old_ds.frameinfo));
|
||||
target->read = read;
|
||||
if(buffer != NULL) {
|
||||
memcpy(&target->capture_buf, ((uint8_t*)buffer) + offset, read - offset);
|
||||
// Make sure to also copy the extra needed data, if any
|
||||
if((device->cc_type == CAPTURE_CONN_USB) && (!device->is_3ds))
|
||||
memcpy(&target->capture_buf.usb_received_old_ds.frameinfo, &buffer->usb_received_old_ds.frameinfo, sizeof(buffer->usb_received_old_ds.frameinfo));
|
||||
target->unused_offset = 0;
|
||||
}
|
||||
else
|
||||
target->unused_offset = offset;
|
||||
target->read = read - offset;
|
||||
target->time_in_buf = time_in_buf;
|
||||
target->capture_type = capture_type;
|
||||
this->ReleaseWriterBuffer();
|
||||
this->ReleaseWriterBuffer(index);
|
||||
}
|
||||
|
||||
void CaptureDataBuffers::WriteToBuffer(CaptureReceived* buffer, uint64_t read, double time_in_buf, CaptureDevice* device, size_t offset) {
|
||||
return this->WriteToBuffer(buffer, read, time_in_buf, device, CAPTURE_SCREENS_BOTH, offset);
|
||||
void CaptureDataBuffers::WriteToBuffer(CaptureReceived* buffer, uint64_t read, double time_in_buf, CaptureDevice* device, CaptureScreensType capture_type, int index) {
|
||||
return this->WriteToBuffer(buffer, read, time_in_buf, device, capture_type, 0, index);
|
||||
}
|
||||
|
||||
void CaptureDataBuffers::WriteToBuffer(CaptureReceived* buffer, uint64_t read, double time_in_buf, CaptureDevice* device, size_t offset, int index) {
|
||||
return this->WriteToBuffer(buffer, read, time_in_buf, device, CAPTURE_SCREENS_BOTH, offset, index);
|
||||
}
|
||||
|
||||
void CaptureDataBuffers::WriteToBuffer(CaptureReceived* buffer, uint64_t read, double time_in_buf, CaptureDevice* device, int index) {
|
||||
return this->WriteToBuffer(buffer, read, time_in_buf, device, CAPTURE_SCREENS_BOTH, 0, index);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user