mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
Generalize StreamOutput a bit.
This commit is contained in:
parent
a5793b8b9d
commit
2433ea30ad
@ -30,19 +30,25 @@ public:
|
|||||||
StreamOutput(CaptureConfig* const config);
|
StreamOutput(CaptureConfig* const config);
|
||||||
~StreamOutput();
|
~StreamOutput();
|
||||||
|
|
||||||
size_t available() {
|
StreamBuffer* get_empty() {
|
||||||
return fifo_buffers_full->len();
|
StreamBuffer* p { nullptr };
|
||||||
|
fifo_buffers_empty->out(p);
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamBuffer* get_buffer() {
|
bool put_empty(StreamBuffer* const p) {
|
||||||
|
p->empty();
|
||||||
|
return fifo_buffers_empty->in(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
StreamBuffer* get_full() {
|
||||||
StreamBuffer* p { nullptr };
|
StreamBuffer* p { nullptr };
|
||||||
fifo_buffers_full->out(p);
|
fifo_buffers_full->out(p);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool release_buffer(StreamBuffer* const p) {
|
bool put_full(StreamBuffer* const p) {
|
||||||
p->empty();
|
return fifo_buffers_full->in(p);
|
||||||
return fifo_buffers_empty->in(p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static FIFO<StreamBuffer*>* fifo_buffers_empty;
|
static FIFO<StreamBuffer*>* fifo_buffers_empty;
|
||||||
@ -126,13 +132,13 @@ Optional<File::Error> CaptureThread::run() {
|
|||||||
StreamOutput stream { &config };
|
StreamOutput stream { &config };
|
||||||
|
|
||||||
while( !chThdShouldTerminate() ) {
|
while( !chThdShouldTerminate() ) {
|
||||||
if( stream.available() ) {
|
auto buffer = stream.get_full();
|
||||||
auto buffer = stream.get_buffer();
|
if( buffer ) {
|
||||||
auto write_result = writer->write(buffer->data(), buffer->size());
|
auto write_result = writer->write(buffer->data(), buffer->size());
|
||||||
if( write_result.is_error() ) {
|
if( write_result.is_error() ) {
|
||||||
return write_result.error();
|
return write_result.error();
|
||||||
}
|
}
|
||||||
stream.release_buffer(buffer);
|
stream.put_empty(buffer);
|
||||||
} else {
|
} else {
|
||||||
chEvtWaitAny(event_mask_loop_wake);
|
chEvtWaitAny(event_mask_loop_wake);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user