Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/audio/audio_replay_buffer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
52 changes: 10 additions & 42 deletions src/ffmpeg/audio_encoder.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/ffmpeg/c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/ui/draw_left_column.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading