camera: iOS implementation (Phase 2+3)

Native plugin owning AVCaptureSession + AVAssetWriter, mirroring
telegram-iOS's Camera module decomposition. Photo + video capture with
the writer-track transform set from a per-call orientation snapshot
(the three-way preview/capture/device split that camera_avfoundation
can't give us).

Modules:
  CameraPlugin           channels + per-handle instance map
  CameraInstance         session + texture + outputs + recorder
  CameraSession          AVCaptureSession + runtime-error/interrupt obs
  CaptureDevice          front/back discovery, per-device config
  PhotoOutput            AVCapturePhotoOutput, per-shot orientation
  VideoRecorder          AVAssetWriter, lazy inputs, pending-audio queue,
                         stop()/cancel() pair (matches telegram)
  PreviewSink            CVPixelBuffer → FlutterTexture
  AudioSession           setCategory + setActive(true) (only-widen)
  DeviceOrientationBridge

Recorder details:
  - Lazy videoInput/audioInput on first sample, sourceFormatHint:.
  - Audio settings derived from CMAudioFormatDescriptionGet*
    + recommendedAudioSettingsForAssetWriter, gated startWriting.
  - Stop sets stopSampleTime; next sample crossing it triggers
    maybeFinish → finishWriting. No watchdog — telegram pattern.
  - cancel() drops pending audio + cancelWriting + deletes file,
    used by CameraInstance.dispose when teardown finds in-flight
    recording.
  - Diagnostic stream → ux/camera/events {event: "diagnostic"}.

Dart surface extensions over Phase 1:
  - UxCameraValue.audioPermissionGranted
  - UxCameraController.refreshAudioPermission()
  - Static UxCameraController.audioPermissionGranted() /
    openSystemSettings()
  - UxCameraDiagnostic event variant
  - FakeUxCameraBackend.{emitDiagnostic, audioPermission,
    openSettingsCalls}

Tests: 32/32 in test/camera (controller + channel) green.
This commit is contained in:
agra
2026-05-13 16:56:49 +03:00
parent 45aac312a8
commit 6d6a871c53
18 changed files with 2337 additions and 22 deletions

View File

@@ -152,6 +152,60 @@ void main() {
expect(file.path, '/tmp/v.mp4');
});
test('events stream filters by handle and decodes diagnostic events',
() async {
const eventsChannel = EventChannel('ux/camera/events');
final messenger =
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
messenger.setMockStreamHandler(
eventsChannel,
MockStreamHandler.inline(
onListen: (_, sink) {
sink.success({
'event': 'diagnostic',
'handle': 4,
'message': 'video input added',
});
sink.success({
'event': 'diagnostic',
'handle': 7,
'message': 'audio input added sr=44100 ch=1',
});
sink.endOfStream();
},
),
);
addTearDown(() => messenger.setMockStreamHandler(eventsChannel, null));
final received = <UxCameraEvent>[];
await backend.events(4).forEach(received.add);
expect(received, hasLength(1));
final e = received.single as UxCameraDiagnostic;
expect(e.handle, 4);
expect(e.message, 'video input added');
});
test('audioPermissionStatus + openSettings round-trip', () async {
var permissionReply = true;
handle((call) {
if (call.method == 'audioPermissionStatus') return permissionReply;
if (call.method == 'openSettings') return null;
return null;
});
expect(await backend.audioPermissionGranted(), isTrue);
permissionReply = false;
expect(await backend.audioPermissionGranted(), isFalse);
await backend.openSettings();
expect(
calls.map((c) => c.method).toList(),
['audioPermissionStatus', 'audioPermissionStatus', 'openSettings'],
);
});
test('PlatformException maps to UxCameraException carrying code/message',
() async {
handle((_) => throw PlatformException(