-
-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented explicit flushing of buffered samples from sink to file #763
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for PR! A few comments.
//! Flush buffered samples to disk | ||
virtual ROC_ATTR_NODISCARD status::StatusCode flush(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and in other headers: it's not necessarily flushing to disk because e.g. there are pipeline sinks that will later implement flushing to network queue.
We can reword it like:
Flush buffered data, if any.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
return code; | ||
return sink_.flush(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If code was not StatusOK before flushing, we should return original code. Only if there were no previous errors before flush and code was StatusOK, we should return code from flush.
(It is a good practice to return earliest error happened, because later errors can be caused by the very first one).
Currently, we just drop previous code, which is wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also:
- please move flush call before "exiting main loop" message
- if flush fails, please log error and status (see status::code_to_str)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
status::StatusCode SoxSink::flush() { | ||
if (fflush((FILE*)output_->fp) == 0) { | ||
return status::StatusOK; | ||
} | ||
|
||
return status::StatusErrFile; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
output_
may be NULL, when sink is paused. I think flush should be no-op in this case. (BTW we need to address this in write() too..)output_->fp
can't be used if SoxSink is device. We should use it only ifdriver_type_ == DriverType_File
, otherwise flush should be no-op.- Let's also check that
output_->fp
is non-NULL. If it's null, let's make flush a no-op too. - nit: Usually early returns are used for errors and the very last return for success.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, also implemented a fix in write() where buffer will write to sox only if buffer_pos > 0
🤖 The latest upstream change made this pull request unmergeable. Please resolve the merge conflicts. |
b357541
to
d6d64c0
Compare
🤖 The latest upstream change made this pull request unmergeable. Please resolve the merge conflicts. |
d6d64c0
to
06f05ae
Compare
…s from sink to file - Added `virtual ROC_ATTR_NODISCARD status::StatusCode flush()=0` pure virtual function in `sndio::ISink`. - Added this method to all ISink implementations. - Implementations that don't use buffereing are no-op. - For SoxSink, flush() sends the buffered samples to disk. - sndio::Pump invokes `flush()` when it exits from `run()`. - Made SoxSink::write to write only when buffer_pos is greater than zero
Thank you! |
Fixes #703
virtual ROC_ATTR_NODISCARD status::StatusCode flush()=0
pure virtual function insndio::ISink
.flush()
when it exits fromrun()
.