Android: cameras in the Stream Studio through Camera2
The studio listed only the test pattern on Android. voelin-media gains a camera provider hook (like the external screen capture): the app registers Camera2, whose cameras the studio's picker lists first (front ones first, with their YUV sizes and highest frame rate), and a camera source opens one. CameraCapture.kt asks for the CAMERA permission when a camera is first opened (the source shows why if it is refused), opens the camera into an ImageReader (YUV_420_888) at the wished size or the nearest one (16:9 first, 1280x720 by default) with a fitting frame-rate range, and hands each frame's planes to Rust as direct buffers valid during the call, with the clockwise turn that makes it upright for the screen's current rotation (front cameras turn the other way). Rust takes the planes as YuvPlanes: an upright planar or NV12 picture goes to the studio's sink as it is, converted straight from the camera's memory; NV21 (what most cameras give) and turned pictures are gathered into I420 in a buffer each camera keeps, so a running camera allocates nothing per frame. Errors after the start (permission refused, camera taken by another app) go to the source's feed. Front and back: a camera's default mirroring now follows the camera (a back camera is not mirrored, what faces the user is), and the source menu gains Switch camera, which moves a camera source to the next camera (and its name with it, if it was named after the camera). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5da3f94479
commit
1eabbb4704
12 files changed
+972
-15
No files matched your search
@@ -1364,6 +1364,35 @@ impl App {
|
||||
"remove" => {
|
||||
self.studio_op(Op::Apply(studio::Command::RemoveSource { scene, source: id }));
|
||||
}
|
||||
// The next camera (a phone's front and back), mirrored as that
|
||||
// camera is by default.
|
||||
"next-camera" => {
|
||||
let SourceKind::Camera { device, size, fps, .. } = source.kind.clone() else {
|
||||
return;
|
||||
};
|
||||
let name = source.name.clone();
|
||||
let cameras = if self.demo_ui { Vec::new() } else { camera::list() };
|
||||
let real: Vec<_> = cameras.iter().filter(|c| c.backend != "synthetic").collect();
|
||||
let at = real.iter().position(|c| c.id == device);
|
||||
let next = at.map_or(real.first(), |i| real.get((i + 1) % real.len()));
|
||||
let Some(next) = next.filter(|c| c.id != device) else {
|
||||
self.set_status("There is no other camera.");
|
||||
return;
|
||||
};
|
||||
let kind = SourceKind::Camera {
|
||||
device: next.id.clone(),
|
||||
size,
|
||||
fps,
|
||||
mirror: next.mirrored,
|
||||
};
|
||||
// A source named after its camera is named after the next.
|
||||
let renamed = name.is_empty() || at.is_some_and(|i| real[i].name == name);
|
||||
let name = renamed.then(|| next.name.clone());
|
||||
self.studio_update(
|
||||
id,
|
||||
SourceChange { kind: Some(kind), name, ..Default::default() },
|
||||
);
|
||||
}
|
||||
"bg-keep" | "bg-blur" => {
|
||||
let background = if action == "bg-blur" {
|
||||
Background::Blur { strength: 0.04 }
|
||||
@@ -1435,6 +1464,7 @@ impl App {
|
||||
camera::SYNTHETIC.to_owned(),
|
||||
"Test pattern".to_owned(),
|
||||
"1280×720".to_owned(),
|
||||
true,
|
||||
)]
|
||||
} else {
|
||||
camera::list()
|
||||
@@ -1444,12 +1474,12 @@ impl App {
|
||||
c.formats.iter().flat_map(|f| &f.sizes).max_by_key(|(w, h)| w * h);
|
||||
let detail =
|
||||
biggest.map_or(String::new(), |(w, h)| format!("up to {w}×{h}"));
|
||||
(c.id, c.name, detail)
|
||||
(c.id, c.name, detail, c.mirrored)
|
||||
})
|
||||
.collect()
|
||||
};
|
||||
for (device, name, detail) in cameras {
|
||||
let kind = SourceKind::Camera { device, size: None, fps: None, mirror: true };
|
||||
for (device, name, detail, mirror) in cameras {
|
||||
let kind = SourceKind::Camera { device, size: None, fps: None, mirror };
|
||||
picks.push((source(&name, kind), row(&name, detail, "camera")));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user