完善音频采集

This commit is contained in:
mofeng-git
2026-04-11 22:22:05 +08:00
parent 4952cbaf19
commit 132f445c29
9 changed files with 340 additions and 79 deletions

View File

@@ -318,18 +318,26 @@ impl H265Encoder {
)
} else {
match config.input_format {
H265InputFormat::Nv12 => {
("nv12", AVPixelFormat::AV_PIX_FMT_NV12, H265InputFormat::Nv12)
}
H265InputFormat::Nv21 => {
("nv21", AVPixelFormat::AV_PIX_FMT_NV21, H265InputFormat::Nv21)
}
H265InputFormat::Nv16 => {
("nv16", AVPixelFormat::AV_PIX_FMT_NV16, H265InputFormat::Nv16)
}
H265InputFormat::Nv24 => {
("nv24", AVPixelFormat::AV_PIX_FMT_NV24, H265InputFormat::Nv24)
}
H265InputFormat::Nv12 => (
"nv12",
AVPixelFormat::AV_PIX_FMT_NV12,
H265InputFormat::Nv12,
),
H265InputFormat::Nv21 => (
"nv21",
AVPixelFormat::AV_PIX_FMT_NV21,
H265InputFormat::Nv21,
),
H265InputFormat::Nv16 => (
"nv16",
AVPixelFormat::AV_PIX_FMT_NV16,
H265InputFormat::Nv16,
),
H265InputFormat::Nv24 => (
"nv24",
AVPixelFormat::AV_PIX_FMT_NV24,
H265InputFormat::Nv24,
),
H265InputFormat::Yuv420p => (
"yuv420p",
AVPixelFormat::AV_PIX_FMT_YUV420P,
@@ -340,12 +348,16 @@ impl H265Encoder {
AVPixelFormat::AV_PIX_FMT_YUYV422,
H265InputFormat::Yuyv422,
),
H265InputFormat::Rgb24 => {
("rgb24", AVPixelFormat::AV_PIX_FMT_RGB24, H265InputFormat::Rgb24)
}
H265InputFormat::Bgr24 => {
("bgr24", AVPixelFormat::AV_PIX_FMT_BGR24, H265InputFormat::Bgr24)
}
H265InputFormat::Rgb24 => (
"rgb24",
AVPixelFormat::AV_PIX_FMT_RGB24,
H265InputFormat::Rgb24,
),
H265InputFormat::Bgr24 => (
"bgr24",
AVPixelFormat::AV_PIX_FMT_BGR24,
H265InputFormat::Bgr24,
),
}
};
let pixfmt = resolve_pixel_format(pixfmt_name, pixfmt_fallback);

View File

@@ -270,8 +270,7 @@ impl Streamer {
.find(|d| d.path.to_string_lossy() == device_path)
.ok_or_else(|| AppError::VideoError("Video device not found".to_string()))?;
let (format, resolution) =
self.resolve_capture_config(&device, format, resolution)?;
let (format, resolution) = self.resolve_capture_config(&device, format, resolution)?;
// IMPORTANT: Disconnect all MJPEG clients FIRST before stopping capture
// This prevents race conditions where clients try to reconnect and reopen the device
@@ -807,9 +806,7 @@ impl Streamer {
// Soft-restart after exponential back-off.
if let Some(since) = no_signal_since {
let backoff_secs = NOSIGNAL_SOFT_RESTART_SECS
.saturating_mul(
2u64.pow(no_signal_restart_count.min(2)),
)
.saturating_mul(2u64.pow(no_signal_restart_count.min(2)))
.min(30);
if since.elapsed().as_secs() >= backoff_secs {
info!(
@@ -858,10 +855,7 @@ impl Streamer {
if capture_error_throttler.should_log(&key) {
let suppressed = suppressed_capture_errors.remove(&key).unwrap_or(0);
if suppressed > 0 {
error!(
"Capture error: {} (suppressed {} repeats)",
e, suppressed
);
error!("Capture error: {} (suppressed {} repeats)", e, suppressed);
} else {
error!("Capture error: {}", e);
}
@@ -991,9 +985,8 @@ impl Streamer {
/// resolution / format change on the source side is picked up before
/// the capture stream is re-opened.
pub async fn re_init_device(self: &Arc<Self>, device_path: &str) -> Result<()> {
let device = VideoDevice::open_readonly(device_path).map_err(|e| {
AppError::VideoError(format!("Cannot open device for re-init: {}", e))
})?;
let device = VideoDevice::open_readonly(device_path)
.map_err(|e| AppError::VideoError(format!("Cannot open device for re-init: {}", e)))?;
let device_info = device.info()?;
let (format, resolution) = {