support configurable output data writers in recorder#17
support configurable output data writers in recorder#17ahmed-shariff wants to merge 4 commits intoliris-xr:masterfrom
Conversation
Refactored the recorder infrastructure to support configurable output data writers. The IDataWriter interface is now generic on a new IDataWriterInfo, allowing data writers to receive configuration via info objects (FileDataWriterInfo, NetworkDataWriterInfo) when instantiated. StartRecordingInternal and StartRecording accept an array of IDataWriterInfo to flexibly control recording destinations and configurations at runtime. This enables future extensibility, such as adding new writer types or enabling user selection of outputs. Default behavior remains writing to a file when no outputs are specified. Added info classes for file and network writers to contain configuration like file paths and network endpoints. This also makes GenerateFilePath public to allow setting file names externaly.
Runtime/Core/Recorder/Recorder.cs
Outdated
| outputsList.Add(info switch | ||
| { | ||
| FileDataWriterInfo => (IDataWriter<IDataWriterInfo>)new FileDataWriter(record, (FileDataWriterInfo)info), | ||
| NetworkDataWriterInfo => (IDataWriter<IDataWriterInfo>)new NetworkDataWriter(record, (NetworkDataWriterInfo)info), | ||
| _ => throw new InvalidOperationException() | ||
| }); |
There was a problem hiding this comment.
I think it would be better to directly give a list of IDataWriter[] as input to StartRecordingInternal, avoiding this switch to be changed for every new IDataWriter type. Additionnally, this would get rid of the DataWriterInfo class as the DataWriter could be constructed directly outside of the recorder and it wouldn't be the responsibility of the recorder to construct the writers.
There was a problem hiding this comment.
I would agree that it would be a better approach. However, the record object needs to be injected. Let me try restructuring that to see what it could look like.
There was a problem hiding this comment.
I refactored to allow for injecting the recorder. Let me know what you think.
Replaces the use of IDataWriterInfo-based writer construction with direct use of initialized IDataWriter instances throughout the Recorder and related classes. FileDataWriter and NetworkDataWriter now store configuration parameters directly and provide an Initialize method for setup at runtime, rather than being constructed via metadata wrapper classes. The Info and Info-based writer classes and interfaces are removed in favor of a simpler, explicit initialization paradigm.
When the recorder restarts, _lastFixedUpdateTime isn’t reset, so RunFixedUpdate tries to process every frame recorded during the downtime and causes a spike. To prevent this, we reset _lastFixedUpdateTime to the current time on restart, ensuring only new frames are processed.
|
Thanks for taking the time to work on this :) A few thoughts after going through the changes:
Of course, this implies bigger change to the PR, I would be happy to discuss further or help break it down if we want to pursue this refactor and simplification. |
I agree, I find dependency injection to nearly always gets messy.
I see your point about |
723b2ea to
aef23f7
Compare
Refactor the Recorder system to initialize IDataWriter outputs using the new SetMetaData method instead of Initialize. FileDataWriter now requires file paths on construction and accepts metadata via SetMetaData. NetworkDataWriter implements a no-op SetMetaData to satisfy the interface. This change improves separation of responsibilities by decoupling metadata setup from generic Initialize calls.
|
My understanding is that I can take a stab at the refactor you mentioned above in another PR. |
This PR refactors the recorder infrastructure to support configurable output data writers. The IDataWriter interface is now generic on a new IDataWriterInfo, allowing data writers to receive configuration via info objects (FileDataWriterInfo, NetworkDataWriterInfo) when instantiated. StartRecordingInternal and StartRecording accept an array of IDataWriterInfo to flexibly control recording destinations and configurations at runtime. This enables future extensibility, such as adding new writer types or enabling user selection of outputs. Default behavior remains writing to a file when no outputs are specified. Added info classes for file and network writers to contain configuration like file paths and network endpoints.
An alternative to having IDataWriterInfo is to directly pass the IDataWriter instances, and pass the record instance through an
Initializemethod.This is primarily motivated by wanting to control when data recording starts and stops and as an extension also specify where and how the data would be recorded.
If necessary, the implementations allows adding support to configuring the writers from settings as well.
Let me know what you think about this.