mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
fix AF-2460, AF-2463
When recording is started, we start polling the pending raw buffers that are waiting for encoding. The buffers are determined by the cursor of the original raw buffer file. When recording is stopped, we will flush the pending buffers and wrap the encoded chunks into WebM.
```mermaid
sequenceDiagram
participant App as App/UI
participant RecordingFeature as Recording Feature
participant StateMachine as State Machine
participant FileSystem as File System
participant StreamEncoder as Stream Encoder
participant OpusEncoder as Opus Encoder
participant WebM as WebM Muxer
Note over App,WebM: Recording Start Flow
App->>RecordingFeature: startRecording()
RecordingFeature->>StateMachine: dispatch(START_RECORDING)
StateMachine-->>RecordingFeature: status: 'recording'
RecordingFeature->>StreamEncoder: createStreamEncoder(id, {sampleRate, channels})
Note over App,WebM: Streaming Flow
loop Audio Data Streaming
RecordingFeature->>FileSystem: Write raw audio chunks to .raw file
StreamEncoder->>FileSystem: Poll raw audio data
FileSystem-->>StreamEncoder: Raw audio chunks
StreamEncoder->>OpusEncoder: Encode chunks
OpusEncoder-->>StreamEncoder: Encoded Opus frames
end
Note over App,WebM: Recording Stop Flow
App->>RecordingFeature: stopRecording()
RecordingFeature->>StateMachine: dispatch(STOP_RECORDING)
StateMachine-->>RecordingFeature: status: 'stopped'
StreamEncoder->>OpusEncoder: flush()
StreamEncoder->>WebM: muxToWebM(encodedChunks)
WebM-->>RecordingFeature: WebM buffer
RecordingFeature->>FileSystem: Save as .opus file
RecordingFeature->>StateMachine: dispatch(SAVE_RECORDING)
```