@@ -55,9 +55,15 @@ pub const File = struct {
file.fs_file = try dir.openFile(sub_path, .{});
errdefer file.fs_file.close();
const buf = try av.malloc(4 * 1024);
const ioc = try av.IOContext.alloc(buf, .read_only, file, readPacket, writePacket, seek);
errdefer ioc.free();
const ioc = ioc: {
const buf = try av.malloc(4 * 1024);
errdefer av.free(buf.ptr);
break :ioc try av.IOContext.alloc(buf, .read_only, file, readPacket, writePacket, seek);
};
errdefer {
av.free(ioc.buffer);
ioc.free();
}
const fc = try av.FormatContext.open_input(filename_hint, null, null, ioc);
errdefer fc.close_input();
@@ -95,8 +101,10 @@ pub const File = struct {
pub fn close(f: *File) void {
f.decode.free();
f.fs_file.close();
av.free(f.fc.pb.?.buffer);
f.fc.pb.?.free();
f.fc.close_input();
f.* = undefined;
std.heap.raw_c_allocator.destroy(f);
}
pub fn audioFormat(f: File) AudioFormat {