Skip to content

Commit

Permalink
libobs/util: Add buffered file serializer
Browse files Browse the repository at this point in the history
Adapted from 898256d

Co-authored-by: Richard Stanway <[email protected]>
  • Loading branch information
2 people authored and Lain-B committed May 18, 2024
1 parent dc4cba7 commit 89c7a96
Show file tree
Hide file tree
Showing 4 changed files with 491 additions and 0 deletions.
41 changes: 41 additions & 0 deletions docs/sphinx/reference-libobs-util-serializers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,44 @@ File Output Serializer Functions
.. function:: void file_output_serializer_free(struct serializer *s)

Frees the file output serializer and saves the file.

---------------------

Buffered File Output Serializer
===============================

Provides a buffered file serializer that writes data asynchronously to prevent stalls due to slow disk I/O.

Writes will only block when the buffer is full.

The buffer and chunk size are configurable with the defaults being 256 MiB and 1 MiB respectively.

.. versionadded:: 30.2

.. code:: cpp
#include <util/buffered-file-serializer.h>
Buffered File Output Serializer Functions
-----------------------------------------

.. function:: bool buffered_file_serializer_init_defaults(struct serializer *s, const char *path)

Initializes a buffered file output serializer with default buffer and chunk sizes.

:return: *true* if file created successfully, *false* otherwise

---------------------

.. function:: bool buffered_file_serializer_init(struct serializer *s, const char *path, size_t max_bufsize, size_t chunk_size)

Initialize buffered writer with specified buffer and chunk sizes. Setting either to `0` will use the default value.

:return: *true* if file created successfully, *false* otherwise

---------------------

.. function:: void buffered_file_serializer_free(struct serializer *s)

Frees the file output serializer and saves the file. Will block until I/O thread completes outstanding writes.
2 changes: 2 additions & 0 deletions libobs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ target_sources(
util/bitstream.h
util/bmem.c
util/bmem.h
util/buffered-file-serializer.c
util/buffered-file-serializer.h
util/c99defs.h
util/cf-lexer.c
util/cf-lexer.h
Expand Down

0 comments on commit 89c7a96

Please sign in to comment.