@@ -19,7 +19,7 @@ class RecordLinux extends RecordPlatform {
19
19
StreamController <RecordState >? _stateStreamCtrl;
20
20
Process ? _parecordProcess;
21
21
Process ? _ffmpegProcess;
22
- StreamController <List <int >>? _amplitudeStreamController ;
22
+ StreamController <List <int >>? _inputPcmController ;
23
23
double _currentAmplitude = - 160.0 ;
24
24
double _maxAmplitude = - 160.0 ;
25
25
@@ -138,18 +138,17 @@ class RecordLinux extends RecordPlatform {
138
138
final path = _path;
139
139
140
140
// Close amplitude stream controller
141
- await _amplitudeStreamController ? .close ();
142
- _amplitudeStreamController = null ;
141
+ await _inputPcmController ? .close ();
142
+ _inputPcmController = null ;
143
143
144
144
// Kill parecord first
145
145
_parecordProcess? .kill ();
146
146
_parecordProcess = null ;
147
147
148
148
// Close ffmpeg stdin and wait for it to finish
149
- if (_ffmpegProcess != null ) {
150
- await _ffmpegProcess! .stdin.close ();
149
+ if (_ffmpegProcess case final process? ) {
151
150
// Wait for ffmpeg to finish writing
152
- await _ffmpegProcess ! .exitCode;
151
+ await process .exitCode;
153
152
_ffmpegProcess = null ;
154
153
}
155
154
@@ -377,7 +376,7 @@ class RecordLinux extends RecordPlatform {
377
376
}
378
377
}
379
378
380
- // Calculate dBFS (same formula as other platforms)
379
+ // Calculate dBFS
381
380
if (maxSample > 0 ) {
382
381
_currentAmplitude = 20 * (log (maxSample / 32767.0 ) / ln10);
383
382
} else {
@@ -415,30 +414,22 @@ class RecordLinux extends RecordPlatform {
415
414
416
415
_ffmpegProcess = await Process .start (_ffmpegBin, ffmpegArgs);
417
416
418
- // Log ffmpeg stderr for debugging (remove this after testing)
419
- _ffmpegProcess! .stderr.transform (utf8.decoder).listen ((data) {
420
- if (data.isNotEmpty) {
421
- debugPrint ('FFmpeg: $data ' );
422
- }
423
- });
424
-
425
417
// Create a passthrough stream controller to intercept audio data
426
- _amplitudeStreamController = StreamController <List <int >>();
418
+ _inputPcmController = StreamController <List <int >>();
427
419
428
420
// Listen to raw PCM data from parecord:
429
421
// 1. Calculate amplitude for VU meter
430
422
// 2. Forward the unchanged PCM data to our stream controller
431
423
parecordProc.stdout.listen ((data) {
432
424
_calculateAmplitude (Uint8List .fromList (data));
433
- if (! _amplitudeStreamController! .isClosed) {
434
- _amplitudeStreamController! .add (data);
425
+
426
+ if (_inputPcmController case final ctrl? when ! ctrl.isClosed) {
427
+ ctrl.add (data);
435
428
}
436
- }, onDone: () {
437
- _amplitudeStreamController? .close ();
438
- });
429
+ }, onDone: () => _inputPcmController? .close ());
439
430
440
431
// Pipe the PCM data from our controller to ffmpeg for encoding
441
432
// This uses pipe() for proper backpressure handling
442
- _amplitudeStreamController ! .stream.pipe (_ffmpegProcess! .stdin);
433
+ _inputPcmController ! .stream.pipe (_ffmpegProcess! .stdin);
443
434
}
444
435
}
0 commit comments