Skip to content

Comments

feat: rotating file writer#913

Open
poneciak57 wants to merge 5 commits intomainfrom
feat/more_file_writer_impls
Open

feat: rotating file writer#913
poneciak57 wants to merge 5 commits intomainfrom
feat/more_file_writer_impls

Conversation

@poneciak57
Copy link
Contributor

@poneciak57 poneciak57 commented Jan 24, 2026

Closes RNAA-384

⚠️ Breaking changes ⚠️

Introduced changes

  • implemented rotating file writer

Checklist

  • Linked relevant issue
  • Updated relevant documentation
  • Added/Conducted relevant tests
  • Performed self-review of the code
  • Updated Web Audio API coverage
  • Added support for web

@poneciak57 poneciak57 changed the title feat: file writer extension feat: rotating file writer Jan 29, 2026
@poneciak57 poneciak57 marked this pull request as ready for review January 29, 2026 14:58
Copy link
Member

@michalsek michalsek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to rething start/stop methods when rotating is enabled, returning filepath on start, and only signle path on stop (with metadata) would be weird.

We could consider slightly improving the results by having:

  • Only status return when start/stop is called without file output
  • Single/path meta for normal file output
  • Parent directory(?) for the rotating files or only status at start, list of files (or parent directory) on stop for batched files

Although not a strong opinion on the approach

export interface AudioRecorderFileOptions {
channelCount?: number;
batchDurationSeconds?: number;
rotateIntervalBytes?: number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this name more explanatory f.e. byteTresholdForFileRotation

return 0;
}

if (formatCtx_ && formatCtx_->pb) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implicit bool cast

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a lot of implicit bool casts in this file

Comment on lines +300 to +305
if (createWriter(properties) == nullptr) {
return Result<std::string, std::string>::Err(
"FFmpeg backend is disabled. Cannot create file writer for the requested format. Use "
"WAV "
"format instead.");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can just check compilation flag, there is no need to manually call this function and check if it returns nullptr

};

if (fileProperties_->rotateIntervalBytes > 0) {
if (createWriter(fileProperties_) == nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check compilation flag

Comment on lines +275 to 295
auto createWriter =
[this](
const std::shared_ptr<AudioFileProperties> &props) -> std::shared_ptr<AudioFileWriter> {
if (props->format == AudioFileProperties::Format::WAV) {
return std::make_shared<MiniAudioFileWriter>(
audioEventHandlerRegistry_,
props,
streamSampleRate_,
streamChannelCount_,
streamMaxBufferSizeInFrames_);
} else {
#if !RN_AUDIO_API_FFMPEG_DISABLED
fileWriter_ = std::make_shared<android::ffmpeg::FFmpegAudioFileWriter>(
audioEventHandlerRegistry_, properties);
return std::make_shared<android::ffmpeg::FFmpegAudioFileWriter>(
audioEventHandlerRegistry_,
props,
streamSampleRate_,
streamChannelCount_,
streamMaxBufferSizeInFrames_);
#else
return Result<std::string, std::string>::Err(
"FFmpeg backend is disabled. Cannot create file writer for the requested format. Use WAV format instead.");
return nullptr;
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code repetition with lines 127-149

Comment on lines +69 to +72
if (currentWriter_) {
return currentWriter_->getFileSizeBytes();
}
return 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not very against it, proabably need to agreed on something, but a lot of "dull" code can be made more consise

Suggested change
if (currentWriter_) {
return currentWriter_->getFileSizeBytes();
}
return 0;
return currentWriter_ ? currentWriter_->getFileSizeBytes() : 0;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and similarly some functions inside it also

std::shared_ptr<AudioFileProperties> fileProperties_;
std::shared_ptr<AudioEventHandlerRegistry> audioEventHandlerRegistry_;

friend class RotatingFileWriter;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RotatingFileWriter inherits from AudioFileWriter so it automatically has access to all protected methods, there is no need for friend class

Comment on lines +21 to +22
bufferFormat_ = bufferFormat;
converterInputBufferSize_ = maxInputBufferLength;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to init list

Comment on lines +216 to +229
size_t bufferSize = [nativeRecorder_ getBufferSize];
auto createWriter =
[this, bufferSize](
const std::shared_ptr<AudioFileProperties> &props) -> std::shared_ptr<AudioFileWriter> {
return std::make_shared<IOSFileWriter>(
audioEventHandlerRegistry_, props, [nativeRecorder_ getInputFormat], bufferSize);
};

if (properties->rotateIntervalBytes > 0) {
fileWriter_ = std::make_shared<RotatingFileWriter>(
audioEventHandlerRegistry_, properties, properties->rotateIntervalBytes, createWriter);
} else {
fileWriter_ = createWriter(properties);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code repetition with 106-128

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants