diff --git a/build.zig.zon b/build.zig.zon index beb9bf3..b50abcb 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -21,8 +21,8 @@ .hash = "imguiz-0.0.0-sI63z7CJegT7FurmE0j1tYdNM5s_cFZ5us8e9Wo7xB0Z", }, .ffmpeg = .{ - .url = "https://github.com/FFmpeg/FFmpeg/archive/refs/tags/n8.0.1.tar.gz", - .hash = "N-V-__8AAH4RHQXHEafp_hkUel3EMeK1wjHBfaIYYxYsKdiM", + .url = "https://github.com/FFmpeg/FFmpeg/archive/refs/tags/n9.0.tar.gz", + .hash = "N-V-__8AAJpxYgW29IA1MGBOmQ-DaqXIv39OFUDYrokatb7C", }, .clap = .{ .url = "https://github.com/Hejsil/zig-clap/archive/refs/tags/0.12.0.tar.gz", diff --git a/src/audio/audio_replay_buffer.zig b/src/audio/audio_replay_buffer.zig index bcdf417..6c1e6b2 100644 --- a/src/audio/audio_replay_buffer.zig +++ b/src/audio/audio_replay_buffer.zig @@ -223,16 +223,16 @@ test "AudioReplayBuffer - size tracks encoded packet bytes as audio is added and const first_chunk = try TestUtil.create_audio_capture_data(allocator, base_ns, samples_per_chunk, 0.1); try replay_buffer.add_data(first_chunk); - try std.testing.expectEqual(3110, replay_buffer.size); + try std.testing.expectEqual(3098, replay_buffer.size); try std.testing.expectEqual(45, replay_buffer.len); const second_chunk = try TestUtil.create_audio_capture_data(allocator, base_ns + std.time.ns_per_s, samples_per_chunk, 0.2); try replay_buffer.add_data(second_chunk); try replay_buffer.finalize(); - try std.testing.expectEqual(10_882, replay_buffer.size); + try std.testing.expectEqual(10_820, replay_buffer.size); try std.testing.expectEqual(98, replay_buffer.len); replay_buffer.set_replay_seconds(trimmed_replay_seconds); - try std.testing.expectEqual(6863, replay_buffer.size); + try std.testing.expectEqual(6784, replay_buffer.size); try std.testing.expectEqual(48, replay_buffer.len); } diff --git a/src/ffmpeg/audio_encoder.zig b/src/ffmpeg/audio_encoder.zig index c580178..8b2b0d1 100644 --- a/src/ffmpeg/audio_encoder.zig +++ b/src/ffmpeg/audio_encoder.zig @@ -66,28 +66,7 @@ pub const AudioEncoder = struct { audio_codec_ctx.*.time_base = c.AVRational{ .num = 1, .den = @intCast(sample_rate) }; audio_codec_ctx.*.bit_rate = AUDIO_BIT_RATE; - // Prefer floating-point formats so the replay mixer can hand PCM to the - // encoder without an extra sample conversion stage. - var chosen_fmt: c.AVSampleFormat = c.AV_SAMPLE_FMT_NONE; - if (audio_codec.*.sample_fmts != null) { - var fmt_ptr = audio_codec.*.sample_fmts; - while (fmt_ptr[0] != c.AV_SAMPLE_FMT_NONE) : (fmt_ptr += 1) { - if (fmt_ptr[0] == c.AV_SAMPLE_FMT_FLTP) { - chosen_fmt = c.AV_SAMPLE_FMT_FLTP; - break; - } - if (fmt_ptr[0] == c.AV_SAMPLE_FMT_FLT and chosen_fmt == c.AV_SAMPLE_FMT_NONE) { - chosen_fmt = c.AV_SAMPLE_FMT_FLT; - } - } - } else { - chosen_fmt = c.AV_SAMPLE_FMT_FLTP; - } - - if (chosen_fmt == c.AV_SAMPLE_FMT_NONE) { - return error.UnsupportedAudioSampleFormat; - } - audio_codec_ctx.*.sample_fmt = chosen_fmt; + audio_codec_ctx.*.sample_fmt = c.AV_SAMPLE_FMT_FLTP; audio_codec_ctx.*.profile = c.AV_PROFILE_AAC_LOW; _ = c.av_opt_set(audio_codec_ctx.*.priv_data, "aac_coder", "fast", 0); @@ -229,28 +208,17 @@ pub const AudioEncoder = struct { var ret = c.av_frame_make_writable(frame); try check_err(ret); - if (self.audio_codec_ctx.*.sample_fmt == c.AV_SAMPLE_FMT_FLTP) { - // Planar float expects one channel per FFmpeg plane. - var ch: usize = 0; - while (ch < self.channels) : (ch += 1) { - const dst: [*]f32 = @ptrCast(@alignCast(frame[0].data[ch])); - if (submitted_samples < codec_samples_per_packet) { - @memset(dst[0..codec_samples_per_packet], 0.0); - } - var i: usize = 0; - while (i < submitted_samples) : (i += 1) { - dst[i] = source_pcm[i * self.channels + ch]; - } - } - } else if (self.audio_codec_ctx.*.sample_fmt == c.AV_SAMPLE_FMT_FLT) { - // Interleaved float stores all channels in the first plane. - const dst: [*]f32 = @ptrCast(@alignCast(frame[0].data[0])); + // Planar float expects one channel per FFmpeg plane. + var ch: usize = 0; + while (ch < self.channels) : (ch += 1) { + const dst: [*]f32 = @ptrCast(@alignCast(frame[0].data[ch])); if (submitted_samples < codec_samples_per_packet) { - @memset(dst[0 .. codec_samples_per_packet * self.channels], 0.0); + @memset(dst[0..codec_samples_per_packet], 0.0); + } + var i: usize = 0; + while (i < submitted_samples) : (i += 1) { + dst[i] = source_pcm[i * self.channels + ch]; } - @memcpy(dst[0..source_pcm.len], source_pcm); - } else { - return error.UnsupportedAudioSampleFormat; } frame.*.nb_samples = @intCast(submitted_samples); diff --git a/src/ffmpeg/c.zig b/src/ffmpeg/c.zig index 27d0ea2..d7d593f 100644 --- a/src/ffmpeg/c.zig +++ b/src/ffmpeg/c.zig @@ -3,6 +3,7 @@ const std = @import("std"); const log = std.log.scoped(.ffmpeg); pub const c = @cImport({ + @cInclude("errno.h"); @cInclude("libavutil/opt.h"); @cInclude("libavutil/frame.h"); @cInclude("libavutil/pixfmt.h"); diff --git a/src/ui/draw_left_column.zig b/src/ui/draw_left_column.zig index 5a3145e..902efa9 100644 --- a/src/ui/draw_left_column.zig +++ b/src/ui/draw_left_column.zig @@ -320,7 +320,7 @@ fn draw_capture_settings(allocator: std.mem.Allocator, store: *Store, state: *St // FPS { var fps = capture_fps_local orelse current_capture_fps; - c.ImGui_Text("Max FPS"); + c.ImGui_Text("FPS"); c.ImGui_SameLine(); imgui_util.help_marker("The maximum capture rate (frames per second). If your system can't keep up, it may be slower than the desired FPS."); imgui_util.set_next_item_width_fill();