feat(app): multicam panel with live angle grid, switching, timeline enable

- New MulticamPanel: rows/cols angle grid with the current angle
  highlighted, click-to-switch, 1-9 switch-and-split and cmd-1-9
  switch-only shortcuts (focused-panel routed), deferred switch queue
  during playback.
- src/oakui/multicam.rs: clip->connected-sequence resolution, multicam
  state detection (selection then playhead fallbacks), per-angle frame
  requests rendered through the process backend into an LRU cache.
- Timeline clip context menu Multi-Cam checkable item wired to
  oaktimeline::multicam enable/disable with undo.
- Engine trait extended (real + mock); mock drives the real command
  path with synthesized angle frames.
This commit is contained in:
2026-08-18 21:40:00 +08:00
parent cad1d93544
commit cf459d7e4c
132 changed files with 2276 additions and 422 deletions
@@ -0,0 +1,156 @@
/***
Oak Video Editor - Non-Linear Video Editor
Copyright (C) 2026 Oak Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef OAK_EDITOR_COLORTRANSFORM_H
#define OAK_EDITOR_COLORTRANSFORM_H
#include "common/error.h"
#include "common/handle.h"
#ifdef __cplusplus
namespace olive
{
class ColorTransform;
}
extern "C" {
#endif
/**
* @brief Neutral by-value handle to a color transform description
* (olive::ColorTransform).
*
* Ownership/count semantics follow the convention in common/handle.h:
* init functions return a handle whose object has reference count 1,
* addref(ctx)/release(ctx) adjust it atomically, and release destroys
* the object at zero. abi_version is always OAKCOMMON_ABI_VERSION.
*/
typedef struct OakColorTransform {
void *ctx; /**< Opaque pointer to the reference-counted object. */
void (*addref)(void *ctx); /**< Atomically increments the count. */
void (*release)(void *ctx); /**< Decrements the count, destroys at 0. */
uint32_t abi_version; /**< OAKCOMMON_ABI_VERSION. */
} OakColorTransform;
/**
* @brief Create a plain output-colorspace transform.
*
* @param output Output colorspace name. Must not be NULL.
* @return Handle with reference count 1; ctx is NULL on failure.
*/
OakColorTransform oakcommon_colortransform_init_output(
const char *output);
/**
* @brief Create a display/view/look transform.
*
* All three strings must not be NULL.
*
* @return Handle with reference count 1; ctx is NULL on failure.
*/
OakColorTransform oakcommon_colortransform_init_display(
const char *display, const char *view, const char *look);
#ifdef __cplusplus
/**
* @brief Copy a native olive::ColorTransform into a new handle.
*
* The source object is deep-copied; the handle does not keep any
* reference to @p src, which may be destroyed immediately afterwards.
* Only visible to C++ consumers.
*
* @return Handle with reference count 1; ctx is NULL if src is NULL or
* on allocation failure.
*/
OakColorTransform oakcommon_colortransform_init_from_native(
const olive::ColorTransform *src);
/**
* @brief Borrow the native object behind a handle.
*
* The returned pointer is borrowed: it stays valid while the caller
* holds a reference to the handle (i.e. until the matching release).
* Only visible to C++ consumers.
*
* @return Borrowed pointer, or NULL if transform is NULL or
* transform->ctx is NULL.
*/
const olive::ColorTransform *oakcommon_colortransform_get_native(
OakColorTransform transform);
#endif
/**
* @brief Release one reference to a transform.
*
* Convenience wrapper around handle.release(handle.ctx): decrements the
* atomic reference count and destroys the object when it reaches zero.
* No-op when transform is NULL or transform->ctx is NULL.
*/
void oakcommon_colortransform_free(OakColorTransform *transform);
/**
* @brief Query whether this is a display/view/look transform.
*
* @param is_display Receives the result. Must not be NULL.
* @return OAKCOMMON_OK or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_colortransform_is_display(OakColorTransform transform,
int *is_display);
/**
* @brief Get the display name (two-stage string getter).
*
* @return Required buffer size in bytes including the terminating NUL
* (non-negative), or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_colortransform_get_display(OakColorTransform transform,
char *buf, int buf_size);
/**
* @brief Get the output colorspace name (two-stage string getter).
*
* @return Required buffer size in bytes including the terminating NUL
* (non-negative), or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_colortransform_get_output(OakColorTransform transform,
char *buf, int buf_size);
/**
* @brief Get the view name (two-stage string getter).
*
* @return Required buffer size in bytes including the terminating NUL
* (non-negative), or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_colortransform_get_view(OakColorTransform transform,
char *buf, int buf_size);
/**
* @brief Get the look name (two-stage string getter).
*
* @return Required buffer size in bytes including the terminating NUL
* (non-negative), or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_colortransform_get_look(OakColorTransform transform,
char *buf, int buf_size);
#ifdef __cplusplus
}
#endif
#endif //OAK_EDITOR_COLORTRANSFORM_H
@@ -0,0 +1,225 @@
/***
Oak Video Editor - Non-Linear Video Editor
Copyright (C) 2026 Oak Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef OAK_EDITOR_COMMANDLINEPARSER_H
#define OAK_EDITOR_COMMANDLINEPARSER_H
#ifndef __cplusplus
#include <stdbool.h>
#endif
#include "common/error.h"
#include "common/handle.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Neutral by-value handle to a command-line parser instance.
*
* Ownership/count semantics follow the convention in common/handle.h:
* init returns a handle whose object has reference count 1,
* addref(ctx)/release(ctx) adjust it atomically, and release destroys
* the object at zero. abi_version is always OAKCOMMON_ABI_VERSION.
*/
typedef struct OakCommandLineParser {
void *ctx; /**< Opaque pointer to the reference-counted object. */
void (*addref)(void *ctx); /**< Atomically increments the count. */
void (*release)(void *ctx); /**< Decrements the count, destroys at 0. */
uint32_t abi_version; /**< OAKCOMMON_ABI_VERSION. */
} OakCommandLineParser;
/**
* @brief Neutral by-value handle to a registered command-line option.
*
* The handle is released with oakcommon_commandlineoption_free() (or
* handle.release(handle.ctx)); the underlying option is owned by the
* parser and stays valid until the parser is destroyed. abi_version is
* always OAKCOMMON_ABI_VERSION.
*/
typedef struct OakCommandLineOption {
void *ctx; /**< Opaque pointer to the reference-counted object. */
void (*addref)(void *ctx); /**< Atomically increments the count. */
void (*release)(void *ctx); /**< Decrements the count, destroys at 0. */
uint32_t abi_version; /**< OAKCOMMON_ABI_VERSION. */
} OakCommandLineOption;
/**
* @brief Neutral by-value handle to a registered positional argument.
*
* The handle is released with
* oakcommon_commandlinepositionalargument_free() (or
* handle.release(handle.ctx)); the underlying argument is owned by the
* parser and stays valid until the parser is destroyed. abi_version is
* always OAKCOMMON_ABI_VERSION.
*/
typedef struct OakCommandLinePositionalArgument {
void *ctx; /**< Opaque pointer to the reference-counted object. */
void (*addref)(void *ctx); /**< Atomically increments the count. */
void (*release)(void *ctx); /**< Decrements the count, destroys at 0. */
uint32_t abi_version; /**< OAKCOMMON_ABI_VERSION. */
} OakCommandLinePositionalArgument;
/**
* @brief Create a command-line parser.
*
* @return Handle with reference count 1; ctx is NULL on allocation
* failure.
*/
OakCommandLineParser oakcommon_commandlineparser_init(void);
/**
* @brief Release one reference to a command-line parser.
*
* Convenience wrapper around handle.release(handle.ctx): decrements the
* atomic reference count and destroys the parser (invalidating all
* option and positional-argument handles created from it) when the
* count reaches zero. No-op when parser is NULL or parser->ctx is NULL.
*/
void oakcommon_commandlineparser_free(OakCommandLineParser *parser);
/**
* @brief Set the application name/version shown by print_help.
*
* @return OAKCOMMON_OK or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_commandlineparser_set_app_info(OakCommandLineParser parser,
const char *name,
const char *version);
/**
* @brief Register an option with one or more name strings.
*
* @param names Array of option name strings (without leading dash).
* @param name_count Number of entries in names. Must be > 0.
* @param description Help text, may be NULL.
* @param takes_arg Non-zero if the option consumes the following argument.
* @param arg_placeholder Placeholder shown in help, may be NULL.
* @param hidden Non-zero to omit from help output.
* @param out_option Receives the option handle (reference count 1).
* May be NULL if unused.
*
* @return OAKCOMMON_OK or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_commandlineparser_add_option(
OakCommandLineParser parser, const char *const *names, int name_count,
const char *description, int takes_arg, const char *arg_placeholder,
int hidden, OakCommandLineOption *out_option);
/**
* @brief Register a positional argument.
*
* @param out_argument Receives the argument handle (reference count 1).
* May be NULL if unused.
*
* @return OAKCOMMON_OK or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_commandlineparser_add_positional_argument(
OakCommandLineParser parser, const char *name,
const char *description, int required,
OakCommandLinePositionalArgument *out_argument);
/**
* @brief Parse an argv-style argument list.
*
* argv[0] is skipped as the program name, matching C main() convention.
*
* @return OAKCOMMON_OK or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_commandlineparser_process(OakCommandLineParser parser,
const char *const *argv, int argc);
/**
* @brief Print usage/help text to stdout.
*
* @return OAKCOMMON_OK or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_commandlineparser_print_help(OakCommandLineParser parser,
const char *filename);
/**
* @brief Query whether an option was present on the command line.
*
* @param is_set Receives the result. Must not be NULL.
*
* @return OAKCOMMON_OK or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_commandlineoption_is_set(OakCommandLineOption option,
bool *is_set);
/**
* @brief Release one reference to an option handle.
*
* Convenience wrapper around handle.release(handle.ctx). Does not
* unregister the option from the parser. No-op when option is NULL or
* option->ctx is NULL.
*/
void oakcommon_commandlineoption_free(OakCommandLineOption *option);
/**
* @brief Get an option's argument value (two-stage string getter).
*
* @return Required buffer size in bytes including the terminating NUL
* (non-negative), or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_commandlineoption_get_setting(OakCommandLineOption option,
char *buf, int buf_size);
/**
* @brief Set an option's argument value.
*
* @return OAKCOMMON_OK or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_commandlineoption_set_setting(OakCommandLineOption option,
const char *value);
/**
* @brief Get a positional argument's value (two-stage string getter).
*
* @return Required buffer size in bytes including the terminating NUL
* (non-negative), or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_commandlinepositionalargument_get_setting(
OakCommandLinePositionalArgument argument, char *buf, int buf_size);
/**
* @brief Set a positional argument's value.
*
* @return OAKCOMMON_OK or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_commandlinepositionalargument_set_setting(
OakCommandLinePositionalArgument argument, const char *value);
/**
* @brief Release one reference to a positional argument handle.
*
* Convenience wrapper around handle.release(handle.ctx). Does not
* unregister the argument from the parser. No-op when argument is NULL
* or argument->ctx is NULL.
*/
void oakcommon_commandlinepositionalargument_free(
OakCommandLinePositionalArgument *argument);
#ifdef __cplusplus
}
#endif
#endif //OAK_EDITOR_COMMANDLINEPARSER_H
+189
View File
@@ -0,0 +1,189 @@
/***
Oak Video Editor - Non-Linear Video Editor
Copyright (C) 2026 Oak Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef OAK_EDITOR_COMMON_CONFIG_H
#define OAK_EDITOR_COMMON_CONFIG_H
#include <stdint.h>
#include "common/error.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief De-Qt application configuration store, C ABI
* (M1-oakcommon.md §2.1, extended for the real consumer surface)
*
* oakcommon_config is a process-wide singleton key/value store (the de-Qt
* replacement for engine/config/config.h's QSettings/QVariant wrapper).
* Per the config-wave ruling it is NOT wrapped in the refcounted-handle
* convention of common/handle.h: there is exactly one store per process,
* so the family is a plain set of functions over that singleton (same
* singleton precedent as OakCurrent).
*
* Keys follow the frozen (group, key) convention of §2.1 and keep the
* QSettings INI shape: pass group == NULL (or "") for a top-level key,
* otherwise the entry is stored under an INI [group] section and
* addressed as "group/key" internally.
*
* Values are typed (string / int64 / double / bool). Rational settings
* are stored as strings in the "num/den" form used by
* oakcore_rational_to_string(). Typed getters take a fallback which is
* returned when the key is absent or has a different type (§2.1 special
* convention: they return values, not error codes).
*
* Persistence is an INI file at
* <FileFunctions::get_configuration_location()>/config.ini. The store
* starts up with compiled-in defaults; oakcommon_config_load() re-reads
* the file (a missing file is not an error) and oakcommon_config_save()
* writes it. The OAK_CONFIG_DIR environment override honored by
* get_configuration_location() also redirects this file (tests/tooling).
*
* NOTE (behavior change): the old Qt implementation persisted to
* config.xml (engine XML) — and on macOS QSettings used a plist — so
* previously saved settings do NOT carry over; the first run starts from
* the compiled-in defaults.
*/
typedef enum OakCommonConfigEntryType {
OAKCOMMON_CONFIG_ENTRY_NONE = 0, /**< No entry / null type. */
OAKCOMMON_CONFIG_ENTRY_STRING = 1,
OAKCOMMON_CONFIG_ENTRY_INT = 2,
OAKCOMMON_CONFIG_ENTRY_DOUBLE = 3,
OAKCOMMON_CONFIG_ENTRY_BOOL = 4
} OakCommonConfigEntryType;
/**
* @brief Handler for configuration errors that should be shown to the user
*
* The engine layer cannot show dialogs itself. The UI registers a handler
* (e.g. QMessageBox-based) at startup; without one, errors go to stderr.
* Same injection pattern as the codec task-submit callback.
*/
typedef void (*OakCommonConfigErrorHandler)(const char *title,
const char *message,
void *userdata);
/**
* @brief Resets the store to compiled-in defaults and loads config.ini
*
* A missing file leaves the defaults in place and returns OAKCOMMON_OK.
* Malformed lines are skipped. An unreadable existing file is reported
* through the error handler and returns OAKCOMMON_E_FAILED.
*/
int oakcommon_config_load(void);
/**
* @brief Writes the current store to config.ini (via a temp file + rename)
*
* On failure the error handler is invoked and OAKCOMMON_E_FAILED is
* returned.
*/
int oakcommon_config_save(void);
/**
* @brief Resets the store to compiled-in defaults (drops custom keys)
*/
int oakcommon_config_reset_defaults(void);
/**
* @brief Sets a string entry (§2.1)
*
* A new key is created as OAKCOMMON_CONFIG_ENTRY_STRING. Setting an
* existing typed (INT/DOUBLE/BOOL) entry parses the string into its
* declared type; an unparseable value returns OAKCOMMON_E_STATE and
* leaves the entry unchanged.
*/
void oakcommon_config_set(const char *group, const char *key,
const char *value_utf8);
/**
* @brief Reads an entry as a string, two-stage buffer (§2.1)
*
* Numeric/bool entries are formatted (bools as "true"/"false", doubles
* with %g).
*
* @return Required buffer size in bytes (including the terminating NUL),
* or a negative OAKCOMMON_E_* error code (OAKCOMMON_E_NOT_FOUND when the
* key is absent).
*/
int oakcommon_config_get(const char *group, const char *key, char *buf,
int buf_size);
/**
* @brief Reads an INT entry as int (§2.1)
*
* @return The stored value, or `fallback` when the key is absent or has
* a different type.
*/
int oakcommon_config_get_int(const char *group, const char *key,
int fallback);
/**
* @brief Reads a DOUBLE entry (§2.1), fallback semantics as get_int
*/
double oakcommon_config_get_double(const char *group, const char *key,
double fallback);
/**
* @brief Sets an INT entry (32-bit, §2.1)
*/
void oakcommon_config_set_int(const char *group, const char *key, int v);
/**
* @brief INT entry as int64 (extension for channel-layout style values)
*/
int64_t oakcommon_config_get_int64(const char *group, const char *key,
int64_t fallback);
void oakcommon_config_set_int64(const char *group, const char *key,
int64_t v);
/**
* @brief BOOL entry as int 0/1 (extension), fallback semantics as get_int
*/
int oakcommon_config_get_bool(const char *group, const char *key,
int fallback);
void oakcommon_config_set_bool(const char *group, const char *key, int v);
/**
* @brief Sets a DOUBLE entry (extension)
*/
void oakcommon_config_set_double(const char *group, const char *key,
double v);
/**
* @brief Returns the OakCommonConfigEntryType of a key, or a negative
* OAKCOMMON_E_* error (OAKCOMMON_E_NOT_FOUND when the key is absent)
*/
int oakcommon_config_entry_type(const char *group, const char *key);
/**
* @brief Registers (or clears, with NULL) the error handler
*/
int oakcommon_config_set_error_handler(OakCommonConfigErrorHandler handler,
void *userdata);
#ifdef __cplusplus
}
#endif
#endif // OAK_EDITOR_COMMON_CONFIG_H
@@ -0,0 +1,123 @@
/***
Oak Video Editor - Non-Linear Video Editor
Copyright (C) 2026 Oak Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef OAK_EDITOR_CURRENT_H
#define OAK_EDITOR_CURRENT_H
#include "common/error.h"
#include "common/handle.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Neutral by-value handle to the process-wide Current singleton.
*
* Uses the standard handle layout (see common/handle.h) but with
* singleton semantics: ctx points to a statically allocated object that
* lives until process exit, so addref() and release() are intentionally
* no-ops and never destroy anything. abi_version is always
* OAKCOMMON_ABI_VERSION.
*/
typedef struct OakCurrent {
void *ctx; /**< Opaque pointer to the singleton object. */
void (*addref)(void *ctx); /**< No-op (singleton). */
void (*release)(void *ctx); /**< No-op (singleton). */
uint32_t abi_version; /**< OAKCOMMON_ABI_VERSION. */
} OakCurrent;
/**
* @brief Destructor callback for objects handed to Current slots.
*
* Called when the slot is overwritten or cleared. May be NULL if the
* caller keeps ownership of the object.
*/
typedef void (*OakDestroyFn)(void *obj);
/**
* @brief Return a handle to the process-wide Current singleton.
*
* The returned handle is borrowed: its ctx is valid for the lifetime of
* the process. addref/release on it are no-ops; calling
* oakcommon_current_free() is allowed for symmetry and does nothing.
*/
OakCurrent oakcommon_current_instance(void);
/**
* @brief Release a Current handle.
*
* No-op: the underlying object is a singleton whose release() never
* destroys anything. Safe to call with NULL or a ctx == NULL handle.
*/
void oakcommon_current_free(OakCurrent *self);
/**
* @brief Store a pointer in a Current slot, taking over destruction.
*
* Passing NULL for obj clears the slot (destroy is ignored). If a
* previous object with a destroy callback was stored, it is destroyed.
*
* @param self Handle from oakcommon_current_instance().
* @param obj Opaque pointer to the external object (e.g. a
* VideoParams), or NULL to clear.
* @param destroy Optional destructor invoked when the slot is replaced.
* @return OAKCOMMON_OK on success, OAKCOMMON_E_INVALID if self.ctx is NULL.
*/
int oakcommon_current_set_video_params(OakCurrent self, void *obj,
OakDestroyFn destroy);
int oakcommon_current_set_audio_params(OakCurrent self, void *obj,
OakDestroyFn destroy);
int oakcommon_current_set_plugin_host(OakCurrent self, void *obj,
OakDestroyFn destroy);
int oakcommon_current_set_plugin_cache(OakCurrent self, void *obj,
OakDestroyFn destroy);
/**
* @brief Fetch the raw pointer currently stored in a slot.
*
* The returned pointer is borrowed and remains valid until the slot is
* overwritten or cleared. *out is set to NULL when the slot is empty.
*
* @param self Handle from oakcommon_current_instance().
* @param out Receives the stored pointer.
* @return OAKCOMMON_OK on success, OAKCOMMON_E_INVALID if self.ctx or
* out is NULL.
*/
int oakcommon_current_get_video_params(OakCurrent self, void **out);
int oakcommon_current_get_audio_params(OakCurrent self, void **out);
int oakcommon_current_get_plugin_host(OakCurrent self, void **out);
int oakcommon_current_get_plugin_cache(OakCurrent self, void **out);
/**
* @brief Query whether the session is interactive.
*
* @param self Handle from oakcommon_current_instance().
* @param out Receives 1 for interactive, 0 otherwise.
* @return OAKCOMMON_OK on success, OAKCOMMON_E_INVALID if self.ctx or
* out is NULL.
*/
int oakcommon_current_is_interactive(OakCurrent self, int *out);
#ifdef __cplusplus
}
#endif
#endif // OAK_EDITOR_CURRENT_H
+113
View File
@@ -0,0 +1,113 @@
/***
Oak Video Editor - Non-Linear Video Editor
Copyright (C) 2026 Oak Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef OAK_EDITOR_DEBUG_H
#define OAK_EDITOR_DEBUG_H
#include "common/error.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Severity levels for oakcommon debug output.
*
* Mirrors olive::DebugLevel in src/common/src/debug.h.
*/
enum OakDebugLevel {
OAKCOMMON_DEBUG_DEBUG = 0, /**< Verbose debug message. */
OAKCOMMON_DEBUG_INFO = 1, /**< Informational message. */
OAKCOMMON_DEBUG_WARNING = 2, /**< Warning message. */
OAKCOMMON_DEBUG_ERROR = 3, /**< Error message. */
OAKCOMMON_DEBUG_FATAL = 4 /**< Fatal error message. */
};
/**
* @brief Print a debug message to stderr, prefixed with its level.
*
* De-Qt replacement for the old Qt message handler. The line is
* flushed immediately.
*
* @param level One of OakDebugLevel; out-of-range values print
* as "UNKNOWN".
* @param msg NUL-terminated message; NULL is treated as an empty
* string.
* @return OAKCOMMON_OK on success, OAKCOMMON_E_INVALID if msg is NULL.
*/
int oakcommon_debug_log(int level, const char *msg);
/**
* @brief Copy the printable name of a debug level into buf.
*
* Two-segment string getter: if buf is NULL or buf_size is too small,
* nothing is written.
*
* @param level One of OakDebugLevel.
* @param buf Destination buffer, may be NULL to query the size.
* @param buf_size Size of buf in bytes.
* @return Required buffer size in bytes including the terminating NUL
* (non-negative).
*/
int oakcommon_debug_level_name(int level, char *buf, int buf_size);
/**
* @brief printf-style filtered log, replacing qDebug()/qInfo()/
* qWarning()/qCritical() call sites.
*
* The message is formatted with vsnprintf into a dynamically sized
* buffer (arbitrary length, no truncation, no fixed stack buffer) and
* emitted as "[LEVEL] message\n" unless @p level is below the current
* filter level (see oakcommon_log_set_level()).
*
* @param level One of OakDebugLevel; out-of-range values print
* as "UNKNOWN" and are never filtered out below FATAL.
* @param fmt printf-style format string. Must not be NULL.
* @return OAKCOMMON_OK on success, OAKCOMMON_E_INVALID if fmt is NULL,
* OAKCOMMON_E_FAILED if formatting failed.
*/
int oakcommon_log(int level, const char *fmt, ...);
/**
* @brief Set the minimum level emitted by oakcommon_log().
*
* Messages with a lower level are dropped. The default is
* OAKCOMMON_DEBUG_INFO.
*
* @param level One of OakDebugLevel.
* @return OAKCOMMON_OK on success, OAKCOMMON_E_INVALID if level is
* outside the OakDebugLevel range.
*/
int oakcommon_log_set_level(int level);
/**
* @brief Query the current minimum level emitted by oakcommon_log().
*
* @param out_level Receives one of OakDebugLevel. Must not be NULL.
* @return OAKCOMMON_OK on success, OAKCOMMON_E_INVALID if out_level is
* NULL.
*/
int oakcommon_log_get_level(int *out_level);
#ifdef __cplusplus
}
#endif
#endif // OAK_EDITOR_DEBUG_H
@@ -0,0 +1,73 @@
/***
Oak Video Editor - Non-Linear Video Editor
Copyright (C) 2026 Oak Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef OAK_EDITOR_DROPWORKFLOWBEHAVIOR_H
#define OAK_EDITOR_DROPWORKFLOWBEHAVIOR_H
#include "common/error.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Behavior when media is dropped onto a timeline without a
* sequence.
*
* Mirrors olive::DropWithoutSequenceBehavior in
* src/common/src/dropworkflowbehavior.h; enumerator order and values
* must stay identical because the config layer persists them as ints.
*/
enum OakDropWorkflowBehavior {
OAKCOMMON_DWS_ASK = 0, /**< Ask the user every time. */
OAKCOMMON_DWS_AUTO = 1, /**< Automatically create a sequence. */
OAKCOMMON_DWS_MANUAL = 2, /**< Never create; import manually. */
OAKCOMMON_DWS_DISABLE = 3 /**< Disable dropping entirely. */
};
/**
* @brief Check whether value is a valid OakDropWorkflowBehavior.
*
* @param value Integer behavior value (e.g. read from config).
* @return 1 if valid, 0 otherwise (this is a predicate, not a status
* code).
*/
int oakcommon_drop_workflow_behavior_is_valid(int value);
/**
* @brief Copy the printable name of a behavior into buf.
*
* Two-segment string getter: if buf is NULL or buf_size is too small,
* nothing is written. Invalid values yield "UNKNOWN".
*
* @param value One of OakDropWorkflowBehavior.
* @param buf Destination buffer, may be NULL to query the size.
* @param buf_size Size of buf in bytes.
* @return Required buffer size in bytes including the terminating NUL
* (non-negative).
*/
int oakcommon_drop_workflow_behavior_name(int value, char *buf,
int buf_size);
#ifdef __cplusplus
}
#endif
#endif // OAK_EDITOR_DROPWORKFLOWBEHAVIOR_H
@@ -0,0 +1,66 @@
/***
Oak Video Editor - Non-Linear Video Editor
Copyright (C) 2026 Oak Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef OAK_EDITOR_ERROR_H
#define OAK_EDITOR_ERROR_H
/**
* @brief Status and error codes shared by all oakcommon C API families.
*
* Return-code convention (mirrors engine/include/oakengine/init.h):
* 0 (OAKCOMMON_OK) on success, a negative OAKCOMMON_E_* error code on
* failure. String getters return the required buffer size in bytes
* (including the terminating NUL) as a non-negative value instead.
*
* Project-wide error code scheme (-MMCCCC, 2026-08):
* every module's error codes are negative integers of the form
* -(MM * 10000 + CCCC), where MM is the module number from the registry
* below and CCCC is a module-local code. The first module-local codes
* are reserved and identical across modules: 0001 INVALID, 0002 STATE,
* 0003 FAILED, 0004 NOT_FOUND, 0005 NOMEM, 0006 CANCELLED.
*
* An error code crossing a module boundary is passed through
* UNTRANSLATED — the numeric module prefix preserves provenance
* (e.g. -30004 is oaknode's NOT_FOUND no matter which module reports it
* to the caller).
*
* Module number registry (only ever appended to; numbers are frozen):
*/
#define OAK_ERROR_MODULE_COMMON 1 /**< oakcommon */
#define OAK_ERROR_MODULE_UNDO 2 /**< oakundo */
#define OAK_ERROR_MODULE_NODE 3 /**< oaknode */
#define OAK_ERROR_MODULE_TIMELINE 4 /**< oaktimeline */
#define OAK_ERROR_MODULE_CODEC 5 /**< oakcodec */
#define OAK_ERROR_MODULE_AUDIO 6 /**< oakaudio */
#define OAK_ERROR_MODULE_RENDER 7 /**< oakrender */
#define OAK_ERROR_MODULE_TASK 8 /**< oaktask */
#define OAK_ERROR_MODULE_PLUGIN 9 /**< oakplugin */
#define OAK_ERROR_MODULE_STORAGE 10 /**< oakstorage (reserved) */
#define OAKCOMMON_OK 0 /**< Success. */
#define OAKCOMMON_E_INVALID (-10001) /**< Empty handle (ctx == NULL) or invalid argument. */
#define OAKCOMMON_E_STATE (-10002) /**< Call not valid in the current state. */
#define OAKCOMMON_E_FAILED (-10003) /**< The underlying operation failed. */
#define OAKCOMMON_E_NOT_FOUND (-10004) /**< Index out of range / entry not found. */
#define OAKCOMMON_E_NOMEM (-10005) /**< Allocation failed. */
#define SUCCESS OAKCOMMON_OK /**< @deprecated Use OAKCOMMON_OK. */
#endif //OAK_EDITOR_ERROR_H
@@ -0,0 +1,116 @@
/***
Oak Video Editor - Non-Linear Video Editor
Copyright (C) 2026 Oak Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef OAK_EDITOR_FFMPEGUTILS_H
#define OAK_EDITOR_FFMPEGUTILS_H
#include "common/error.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Stateless mappings between native pixel/sample formats and the
* opaque FBPixelFormat / FBSampleFormat constants of ffmpeg_bridge
*
* All functions are pure format conversions; there is no handle to create
* or free. Native pixel/sample formats are passed as plain ints matching
* the olive::core::PixelFormat::Format / SampleFormat::Format enum values
* (invalid = -1). Bridge formats are the fb_pix_fmt_* / fb_sample_fmt_*
* constants from ffmpeg_bridge/ffmpeg_bridge.h.
*/
/**
* @brief RGB / RGBA channel counts (flattened from VideoParams)
*/
#define OAKCOMMON_RGB_CHANNEL_COUNT 3
#define OAKCOMMON_RGBA_CHANNEL_COUNT 4
/**
* @brief Returns a bridge pixel format that a frame can be converted to
* with minimal data loss, clamped to a maximum native precision
*
* @param pix_fmt bridge pixel format to find a compatible conversion for
* @param maximum_pix_fmt maximum native pixel format, or -1 for no limit
* @param out receives the chosen bridge pixel format
* @return OAKCOMMON_OK on success, OAKCOMMON_E_INVALID if out is NULL
*/
int oakcommon_ffmpegutils_get_compatible_bridge_pixel_format(
int pix_fmt, int maximum_pix_fmt, int *out);
/**
* @brief Returns a native pixel format usable to convert from a native
* frame to a bridge frame with minimal data loss
*
* @param pix_fmt native pixel format
* @param out receives the compatible native pixel format (-1 if none)
* @return OAKCOMMON_OK on success, OAKCOMMON_E_INVALID if out is NULL
*/
int oakcommon_ffmpegutils_get_compatible_pixel_format(int pix_fmt,
int *out);
/**
* @brief Returns a bridge pixel format for a given native pixel format
*
* @param pix_fmt native pixel format
* @param channel_count OAKCOMMON_RGB_CHANNEL_COUNT or
* OAKCOMMON_RGBA_CHANNEL_COUNT
* @param out receives the bridge pixel format (fb_pix_fmt_none if none)
* @return OAKCOMMON_OK on success, OAKCOMMON_E_INVALID if out is NULL
*/
int oakcommon_ffmpegutils_get_ffmpeg_pixel_format(int pix_fmt,
int channel_count,
int *out);
/**
* @brief Returns a native sample format for a given bridge sample format
*
* @param smp_fmt bridge sample format
* @param out receives the native sample format (-1 if unknown)
* @return OAKCOMMON_OK on success, OAKCOMMON_E_INVALID if out is NULL
*/
int oakcommon_ffmpegutils_get_native_sample_format(int smp_fmt, int *out);
/**
* @brief Returns a bridge sample format for a given native sample format
*
* @param smp_fmt native sample format
* @param out receives the bridge sample format (fb_sample_fmt_none if none)
* @return OAKCOMMON_OK on success, OAKCOMMON_E_INVALID if out is NULL
*/
int oakcommon_ffmpegutils_get_ffmpeg_sample_format(int smp_fmt, int *out);
/**
* @brief Converts a "JPEG" full-range bridge pixel format to its regular
* counterpart
*
* @param pix_fmt bridge pixel format
* @param out receives the regular-range format (unchanged if not JPEG)
* @return OAKCOMMON_OK on success, OAKCOMMON_E_INVALID if out is NULL
*/
int oakcommon_ffmpegutils_convert_jpeg_space_to_regular_space(int pix_fmt,
int *out);
#ifdef __cplusplus
}
#endif
#endif //OAK_EDITOR_FFMPEGUTILS_H
@@ -0,0 +1,167 @@
/***
Oak Video Editor - Non-Linear Video Editor
Copyright (C) 2026 Oak Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef OAK_EDITOR_FILEFUNCTIONS_H
#define OAK_EDITOR_FILEFUNCTIONS_H
#include "common/error.h"
#include "common/handle.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Neutral by-value handle for the filefunctions family
*
* File functions are stateless; the handle only exists to keep the C API
* shape uniform across oakcommon families. Ownership/count semantics
* follow the convention in common/handle.h: init returns a handle whose
* (empty) object has reference count 1, addref(ctx)/release(ctx) adjust
* it atomically, and release destroys it at zero. abi_version is always
* OAKCOMMON_ABI_VERSION.
*/
typedef struct OakFileFunctions {
void *ctx; /**< Opaque pointer to the reference-counted object. */
void (*addref)(void *ctx); /**< Atomically increments the count. */
void (*release)(void *ctx); /**< Decrements the count, destroys at 0. */
uint32_t abi_version; /**< OAKCOMMON_ABI_VERSION. */
} OakFileFunctions;
/**
* @brief Creates a filefunctions handle
*
* @return Handle with reference count 1; ctx is NULL on failure.
*/
OakFileFunctions oakcommon_filefunctions_init(void);
/**
* @brief Releases one reference to a filefunctions handle
*
* Convenience wrapper around handle.release(handle.ctx): decrements the
* atomic reference count and destroys the object when it reaches zero.
* No-op when self is NULL or self->ctx is NULL.
*/
void oakcommon_filefunctions_free(OakFileFunctions *self);
/**
* @brief Returns a deterministic identifier string for a file
*
* @return Required buffer size in bytes (including NUL), or a negative
* OAKCOMMON_E_* error code. Returns an empty string (required size 1) if
* the file does not exist.
*/
int oakcommon_filefunctions_get_unique_file_identifier(
OakFileFunctions self, const char *filename, char *buf,
int buf_size);
int oakcommon_filefunctions_get_configuration_location(
OakFileFunctions self, char *buf, int buf_size);
int oakcommon_filefunctions_get_application_path(
OakFileFunctions self, char *buf, int buf_size);
int oakcommon_filefunctions_get_temp_file_path(
OakFileFunctions self, char *buf, int buf_size);
int oakcommon_filefunctions_get_auto_recovery_root(
OakFileFunctions self, char *buf, int buf_size);
/**
* @brief Checks whether `source` can be copied to `dest` without
* overwriting anything
*
* @param out Receives 1 (safe) or 0 (would overwrite).
*/
int oakcommon_filefunctions_can_copy_directory_without_overwriting(
OakFileFunctions self, const char *source, const char *dest,
int *out);
/**
* @brief Recursively copies a directory
*/
int oakcommon_filefunctions_copy_directory(OakFileFunctions self,
const char *source,
const char *dest, int overwrite);
/**
* @brief Checks whether a directory exists, optionally creating it
*
* @param out Receives 1 (valid) or 0 (invalid).
*/
int oakcommon_filefunctions_directory_is_valid(
OakFileFunctions self, const char *dir,
int try_to_create_if_not_exists, int *out);
/**
* @brief Ensures a filename ends with the given extension (no dot)
*
* @return Required buffer size in bytes (including NUL), or a negative
* OAKCOMMON_E_* error code.
*/
int oakcommon_filefunctions_ensure_filename_extension(
OakFileFunctions self, const char *filename,
const char *extension, char *buf, int buf_size);
/**
* @brief Reads an entire file into a string
*
* @return Required buffer size in bytes (including NUL), or a negative
* OAKCOMMON_E_* error code. Returns an empty string (required size 1) if
* the file cannot be read.
*/
int oakcommon_filefunctions_read_file_as_string(
OakFileFunctions self, const char *filename, char *buf,
int buf_size);
/**
* @brief Returns a non-existing temporary variant of `original`
*
* @return Required buffer size in bytes (including NUL), or a negative
* OAKCOMMON_E_* error code.
*/
int oakcommon_filefunctions_get_safe_temporary_filename(
OakFileFunctions self, const char *original, char *buf,
int buf_size);
/**
* @brief Renames `from` to `to`, deleting `to` first if it exists
*
* @param out Receives 1 (renamed) or 0 (failed).
*/
int oakcommon_filefunctions_rename_file_allow_overwrite(
OakFileFunctions self, const char *from, const char *to,
int *out);
/**
* @brief Appends the platform executable suffix (".exe" on Windows)
*
* @return Required buffer size in bytes (including NUL), or a negative
* OAKCOMMON_E_* error code.
*/
int oakcommon_filefunctions_get_formatted_executable_for_platform(
OakFileFunctions self, const char *unformatted, char *buf,
int buf_size);
#ifdef __cplusplus
}
#endif
#endif // OAK_EDITOR_FILEFUNCTIONS_H
@@ -0,0 +1,69 @@
/***
Oak Video Editor - Non-Linear Video Editor
Copyright (C) 2026 Oak Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef OAK_EDITOR_HANDLE_H
#define OAK_EDITOR_HANDLE_H
#include <stdint.h>
/**
* @brief Current ABI version stamped into every oakcommon handle.
*
* Bump whenever the handle layout or the semantics of any exported
* function change incompatibly. Consumers should compare a handle's
* abi_version field against the value they were compiled with before
* dereferencing ctx.
*/
#define OAKCOMMON_ABI_VERSION 1
/**
* @brief Neutral handle convention shared by all oakcommon wrappers.
*
* Every wrapper type is a by-value struct with the same four fields:
*
* typedef struct OakXxx {
* void *ctx; // opaque, points to the impl
* void (*addref)(void *ctx); // atomic +1, owner-DLL code
* void (*release)(void *ctx); // atomic -1, destroys at 0
* uint32_t abi_version; // OAKCOMMON_ABI_VERSION
* } OakXxx;
*
* Rules:
* - oakcommon_<name>_init*() returns a handle whose underlying object
* has reference count 1.
* - Copying the struct copies the pointer, not the count: call
* handle.addref(handle.ctx) for every additional long-lived copy and
* handle.release(handle.ctx) (or the oakcommon_<name>_free()
* convenience wrapper) when done with each copy.
* - release() decrements the atomic count and destroys the underlying
* object when it reaches zero; the destructor runs in the DLL that
* created the object, so cross-DLL handing is safe.
* - The struct itself carries no ownership: it is never heap-allocated
* by the API, so it needs no destruction of its own.
* - Functions that only read a handle take it BY VALUE (OakXxx self);
* an empty handle (ctx == NULL) is reported as OAKCOMMON_E_INVALID.
* oakcommon_<name>_free() deliberately stays a pointer API
* (OakXxx *h, like av_frame_unref()/av_buffer_unref()) so it can
* null out the caller's ctx after the final release; NULL and
* ctx == NULL are no-ops. Out parameters that produce a handle
* (e.g. option/positional-argument registration) also stay pointers.
*/
#endif //OAK_EDITOR_HANDLE_H
@@ -0,0 +1,44 @@
/***
Oak Video Editor - Non-Linear Video Editor
Copyright (C) 2026 Oak Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef OAK_EDITOR_LOOPMODE_H
#define OAK_EDITOR_LOOPMODE_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Playback loop mode, mirroring olive::LoopMode.
*
* The numeric values must stay in sync with src/common/src/loopmode.h.
* Pure enum: no functions are needed.
*/
enum OakLoopMode {
OAKCOMMON_LOOP_MODE_OFF = 0, /**< Looping disabled. */
OAKCOMMON_LOOP_MODE_LOOP = 1, /**< Loop playback. */
OAKCOMMON_LOOP_MODE_CLAMP = 2 /**< Clamp at the end. */
};
#ifdef __cplusplus
}
#endif
#endif //OAK_EDITOR_LOOPMODE_H
@@ -0,0 +1,117 @@
/***
Oak Video Editor - Non-Linear Video Editor
Copyright (C) 2026 Oak Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef OAK_EDITOR_MISCUTILS_H
#define OAK_EDITOR_MISCUTILS_H
#include "common/error.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Minimum decibel value used by the editor (-200.0 dB).
*
* In basically all circumstances, this calculates to 0.0 linear.
*/
#define OAKCOMMON_DECIBEL_MINIMUM (-200.0)
/**
* @brief Convert a linear amplitude to decibels.
*
* A linear value of 0.0 (or anything yielding an infinite result) returns
* OAKCOMMON_DECIBEL_MINIMUM.
*
* @param linear Linear amplitude.
* @param out_db Receives the decibel value. Must not be NULL.
* @return OAKCOMMON_OK on success, OAKCOMMON_E_INVALID if out_db is NULL.
*/
int oakcommon_decibel_from_linear(double linear, double *out_db);
/**
* @brief Convert decibels to a linear amplitude.
*
* Results below 1e-6 are clamped to 0.0.
*
* @param db Decibel value.
* @param out_linear Receives the linear amplitude. Must not be NULL.
* @return OAKCOMMON_OK on success, OAKCOMMON_E_INVALID if out_linear is NULL.
*/
int oakcommon_decibel_to_linear(double db, double *out_linear);
/**
* @brief Convert a logarithmic slider position (0..1) to decibels.
*
* @param logarithmic Logarithmic position.
* @param out_db Receives the decibel value. Must not be NULL.
* @return OAKCOMMON_OK on success, OAKCOMMON_E_INVALID if out_db is NULL.
*/
int oakcommon_decibel_from_logarithmic(double logarithmic, double *out_db);
/**
* @brief Convert decibels to a logarithmic slider position (0..1).
*
* @param db Decibel value.
* @param out_logarithmic Receives the logarithmic position. Must not be NULL.
* @return OAKCOMMON_OK on success, OAKCOMMON_E_INVALID if out_logarithmic
* is NULL.
*/
int oakcommon_decibel_to_logarithmic(double db, double *out_logarithmic);
/**
* @brief Convert a linear amplitude directly to a logarithmic position.
*
* @param linear Linear amplitude.
* @param out_logarithmic Receives the logarithmic position. Must not be NULL.
* @return OAKCOMMON_OK on success, OAKCOMMON_E_INVALID if out_logarithmic
* is NULL.
*/
int oakcommon_decibel_linear_to_logarithmic(double linear,
double *out_logarithmic);
/**
* @brief Convert a logarithmic position directly to a linear amplitude.
*
* @param logarithmic Logarithmic position.
* @param out_linear Receives the linear amplitude. Must not be NULL.
* @return OAKCOMMON_OK on success, OAKCOMMON_E_INVALID if out_linear is NULL.
*/
int oakcommon_decibel_logarithmic_to_linear(double logarithmic,
double *out_linear);
/**
* @brief Linearly interpolate between a and b using t.
*
* t should be between 0.0 and 1.0: 0.0 returns a, 1.0 returns b.
*
* @param a Start value.
* @param b End value.
* @param t Interpolation factor.
* @param out_value Receives the interpolated value. Must not be NULL.
* @return OAKCOMMON_OK on success, OAKCOMMON_E_INVALID if out_value is NULL.
*/
int oakcommon_lerp(double a, double b, double t, double *out_value);
#ifdef __cplusplus
}
#endif
#endif //OAK_EDITOR_MISCUTILS_H
@@ -0,0 +1,105 @@
/***
Oak Video Editor - Non-Linear Video Editor
Copyright (C) 2026 Oak Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef OAK_EDITOR_OCIOUTILS_H
#define OAK_EDITOR_OCIOUTILS_H
#include "common/error.h"
#include "common/handle.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Native pixel format codes, mirroring olive::core::PixelFormat
*
* The numeric values must stay in sync with
* olive/core/render/pixelformat.h (Format enum).
*/
enum OakPixelFormat {
OAKCOMMON_PIXEL_FORMAT_INVALID = -1, /**< Invalid/unknown format. */
OAKCOMMON_PIXEL_FORMAT_U8 = 0, /**< 8-bit unsigned integer. */
OAKCOMMON_PIXEL_FORMAT_U10 = 1, /**< 10-bit unsigned integer. */
OAKCOMMON_PIXEL_FORMAT_U16 = 2, /**< 16-bit unsigned integer. */
OAKCOMMON_PIXEL_FORMAT_F16 = 3, /**< 16-bit float (half). */
OAKCOMMON_PIXEL_FORMAT_F32 = 4, /**< 32-bit float. */
OAKCOMMON_PIXEL_FORMAT_COUNT = 5 /**< Sentinel, not a valid format. */
};
/**
* @brief OpenColorIO bit depth codes, matching OCIO::BitDepth
*
* Returned through the out parameter of
* oakcommon_ocioutils_get_ocio_bit_depth_from_pixel_format() as a plain
* int so that callers never see OCIO types. Values match the OCIO
* BitDepth enum: 0 = unknown, 1 = uint8, 2 = uint10, 3 = uint12,
* 4 = uint14, 5 = uint16, 6 = uint32, 7 = f16, 8 = f32 (OCIO v2).
*/
/**
* @brief Neutral by-value handle for the OCIO utils family
*
* The object is stateless; the handle exists only to satisfy the C API
* lifetime contract. Ownership/count semantics follow common/handle.h:
* init returns a handle whose (empty) object has reference count 1 and
* release destroys it at zero. abi_version is always
* OAKCOMMON_ABI_VERSION.
*/
typedef struct OakOCIOUtils {
void *ctx; /**< Opaque pointer to the reference-counted object. */
void (*addref)(void *ctx); /**< Atomically increments the count. */
void (*release)(void *ctx); /**< Decrements the count, destroys at 0. */
uint32_t abi_version; /**< OAKCOMMON_ABI_VERSION. */
} OakOCIOUtils;
/**
* @brief Creates an OCIOUtils handle
*
* @return Handle with reference count 1; ctx is NULL on failure.
*/
OakOCIOUtils oakcommon_ocioutils_init(void);
/**
* @brief Releases one reference to an OCIOUtils handle
*
* Convenience wrapper around handle.release(handle.ctx); no-op when
* self is NULL or self->ctx is NULL.
*/
void oakcommon_ocioutils_free(OakOCIOUtils *self);
/**
* @brief Maps a native pixel format to an OCIO bit depth
*
* @param self handle from oakcommon_ocioutils_init()
* @param pixel_format one of the OakPixelFormat values
* @param out_bit_depth receives the OCIO bit depth as an int (see the
* OakOCIOUtils typedef documentation); set to 0
* (BIT_DEPTH_UNKNOWN) for invalid formats
* @return OAKCOMMON_OK, or OAKCOMMON_E_INVALID if self.ctx or
* out_bit_depth is NULL or pixel_format is not a known code
*/
int oakcommon_ocioutils_get_ocio_bit_depth_from_pixel_format(
OakOCIOUtils self, int pixel_format, int *out_bit_depth);
#ifdef __cplusplus
}
#endif
#endif // OAK_EDITOR_OCIOUTILS_H
@@ -0,0 +1,125 @@
/***
Oak Video Editor - Non-Linear Video Editor
Copyright (C) 2026 Oak Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef OAK_EDITOR_OIIOUTILS_H
#define OAK_EDITOR_OIIOUTILS_H
#include "common/error.h"
/* Reuses the OakPixelFormat enum (mirroring
* olive::core::PixelFormat) rather than redefining it here. */
#include "common/ocioutils.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief OIIO base type codes, matching OIIO::TypeDesc::BASETYPE
*
* Passed through the C API as plain ints so callers never see OIIO
* types. Values match the OIIO TypeDesc::BASETYPE enum: 0 = UNKNOWN,
* 1 = NONE, 2 = UINT8, 3 = INT8, 4 = UINT16, 5 = INT16, 6 = UINT32,
* 7 = INT32, 8 = UINT64, 9 = INT64, 10 = HALF, 11 = FLOAT, 12 = DOUBLE,
* 13 = STRING, 14 = PTR. OIIO >= 2.5 adds 15 = USTRINGHASH and shifts
* LASTBASE, so the exact LASTBASE value is version-dependent.
*/
/**
* @brief Neutral by-value handle for the OIIO utils family
*
* The object is stateless; the handle exists only to satisfy the C API
* lifetime contract. Ownership/count semantics follow common/handle.h:
* init returns a handle whose (empty) object has reference count 1 and
* release destroys it at zero. abi_version is always
* OAKCOMMON_ABI_VERSION.
*/
typedef struct OakOIIOUtils {
void *ctx; /**< Opaque pointer to the reference-counted object. */
void (*addref)(void *ctx); /**< Atomically increments the count. */
void (*release)(void *ctx); /**< Decrements the count, destroys at 0. */
uint32_t abi_version; /**< OAKCOMMON_ABI_VERSION. */
} OakOIIOUtils;
/**
* @brief Creates an OIIOUtils handle
*
* @return Handle with reference count 1; ctx is NULL on failure.
*/
OakOIIOUtils oakcommon_oiioutils_init(void);
/**
* @brief Releases one reference to an OIIOUtils handle
*
* Convenience wrapper around handle.release(handle.ctx); no-op when
* self is NULL or self->ctx is NULL.
*/
void oakcommon_oiioutils_free(OakOIIOUtils *self);
/**
* @brief Maps a native pixel format to an OIIO base type
*
* @param self handle from oakcommon_oiioutils_init()
* @param pixel_format one of the OakPixelFormat values
* @param out_base_type receives the OIIO base type as an int (see the
* OakOIIOUtils typedef documentation); set to 0
* (TypeDesc::UNKNOWN) for invalid or unmappable formats
* @return OAKCOMMON_OK, or OAKCOMMON_E_INVALID if self.ctx or
* out_base_type is NULL or pixel_format is not a known code
*/
int oakcommon_oiioutils_get_oiio_base_type_from_format(
OakOIIOUtils self, int pixel_format, int *out_base_type);
/**
* @brief Maps an OIIO base type to a native pixel format
*
* @param self handle from oakcommon_oiioutils_init()
* @param base_type an OIIO TypeDesc::BASETYPE value as an int
* @param out_pixel_format receives one of the OakPixelFormat
* values; set to OAKCOMMON_PIXEL_FORMAT_INVALID for unknown or
* unmappable base types
* @return OAKCOMMON_OK, or OAKCOMMON_E_INVALID if self.ctx or
* out_pixel_format is NULL or base_type is negative
*/
int oakcommon_oiioutils_get_format_from_oiio_basetype(
OakOIIOUtils self, int base_type, int *out_pixel_format);
/**
* @brief Converts a PixelAspectRatio attribute value to a rational
*
* Flattened form of the former ImageSpec-based helper: the caller reads
* the "PixelAspectRatio" float attribute from the OIIO::ImageSpec
* (defaulting to 1.0 when absent) and passes it here.
*
* @param self handle from oakcommon_oiioutils_init()
* @param pixel_aspect_ratio the PixelAspectRatio attribute value
* @param out_numerator receives the rational numerator
* @param out_denominator receives the rational denominator
* @return OAKCOMMON_OK, or OAKCOMMON_E_INVALID if self.ctx,
* out_numerator or out_denominator is NULL
*/
int oakcommon_oiioutils_get_pixel_aspect_ratio(
OakOIIOUtils self, double pixel_aspect_ratio, int *out_numerator,
int *out_denominator);
#ifdef __cplusplus
}
#endif
#endif // OAK_EDITOR_OIIOUTILS_H
@@ -0,0 +1,58 @@
/***
Oak Video Editor - Non-Linear Video Editor
Copyright (C) 2026 Oak Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef OAK_EDITOR_POWER_H
#define OAK_EDITOR_POWER_H
#include <stdint.h>
#include "error.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Round `value` up to the next power of two
*
* Stateless pure function, no handle required. Writes the result to `out`.
*
* @param value Input value.
* @param out Receives the rounded value. Must not be NULL.
* @return OAKCOMMON_OK on success, OAKCOMMON_E_INVALID if `out` is NULL.
*/
int oakcommon_power_ceil_to_power_of_2(uint32_t value, uint32_t *out);
/**
* @brief Round `value` down to the nearest power of two
*
* Stateless pure function, no handle required. Writes the result to `out`.
*
* @param value Input value.
* @param out Receives the rounded value. Must not be NULL.
* @return OAKCOMMON_OK on success, OAKCOMMON_E_INVALID if `out` is NULL.
*/
int oakcommon_power_floor_to_power_of_2(uint32_t value, uint32_t *out);
#ifdef __cplusplus
}
#endif
#endif //OAK_EDITOR_POWER_H
@@ -0,0 +1,67 @@
/***
Oak Video Editor - Non-Linear Video Editor
Copyright (C) 2026 Oak Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef OAK_COMMON_QTUTILS_H
#define OAK_COMMON_QTUTILS_H
#include <stdint.h>
#include "common/error.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Convert a pointer to an integer value
*
* @param ptr Pointer to convert (may be NULL, yielding 0).
* @param out_value Receives the integer representation of ptr.
* @return OAKCOMMON_OK on success, OAKCOMMON_E_INVALID if out_value is NULL.
*/
int oakcommon_qtutils_ptr_to_value(void *ptr, uint64_t *out_value);
/**
* @brief Convert an integer produced by oakcommon_qtutils_ptr_to_value() back to a pointer
*
* @param value Integer representation of a pointer.
* @param out_ptr Receives the decoded pointer.
* @return OAKCOMMON_OK on success, OAKCOMMON_E_INVALID if out_ptr is NULL.
*/
int oakcommon_qtutils_value_to_ptr(uint64_t value, void **out_ptr);
/**
* @brief Get the creation (birth) time of a file as seconds since the Unix epoch
*
* Falls back to the last metadata change time when the filesystem does not
* record birth times.
*
* @param path NUL-terminated filesystem path.
* @param out_secs Receives the creation time in seconds since the epoch.
* @return OAKCOMMON_OK on success, OAKCOMMON_E_INVALID for NULL arguments,
* OAKCOMMON_E_NOT_FOUND if the file does not exist or cannot be stat'ed.
*/
int oakcommon_qtutils_get_creation_date(const char *path, int64_t *out_secs);
#ifdef __cplusplus
}
#endif
#endif // OAK_COMMON_QTUTILS_H
@@ -0,0 +1,176 @@
/***
Oak Video Editor - Non-Linear Video Editor
Copyright (C) 2026 Oak Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef OAK_EDITOR_SUBTITLEPARAMS_H
#define OAK_EDITOR_SUBTITLEPARAMS_H
#include "common/error.h"
#include "common/handle.h"
#ifdef __cplusplus
namespace olive
{
class SubtitleParams;
}
extern "C" {
#endif
/**
* @brief Neutral by-value handle to a subtitle parameter set
* (olive::SubtitleParams).
*
* Ownership/count semantics follow the convention in common/handle.h:
* init functions return a handle whose object has reference count 1,
* addref(ctx)/release(ctx) adjust it atomically, and release destroys
* the object at zero. abi_version is always OAKCOMMON_ABI_VERSION.
*/
typedef struct OakSubtitleParams {
void *ctx; /**< Opaque pointer to the reference-counted object. */
void (*addref)(void *ctx); /**< Atomically increments the count. */
void (*release)(void *ctx); /**< Decrements the count, destroys at 0. */
uint32_t abi_version; /**< OAKCOMMON_ABI_VERSION. */
} OakSubtitleParams;
/**
* @brief Create an empty subtitle parameter set.
*
* @return Handle with reference count 1; ctx is NULL on allocation
* failure.
*/
OakSubtitleParams oakcommon_subtitleparams_init(void);
#ifdef __cplusplus
/**
* @brief Copy a native olive::SubtitleParams into a new handle.
*
* The source object is deep-copied; the handle does not keep any
* reference to @p src, which may be destroyed immediately afterwards.
* Only visible to C++ consumers.
*
* @return Handle with reference count 1; ctx is NULL if src is NULL or
* on allocation failure.
*/
OakSubtitleParams oakcommon_subtitleparams_init_from_native(
const olive::SubtitleParams *src);
#endif
/**
* @brief Release one reference to a subtitle parameter set.
*
* Convenience wrapper around handle.release(handle.ctx): decrements the
* atomic reference count and destroys the object when it reaches zero.
* No-op when params is NULL or params->ctx is NULL.
*/
void oakcommon_subtitleparams_free(OakSubtitleParams *params);
int oakcommon_subtitleparams_get_stream_index(
OakSubtitleParams params, int *index);
int oakcommon_subtitleparams_set_stream_index(
OakSubtitleParams params, int index);
int oakcommon_subtitleparams_get_enabled(OakSubtitleParams params,
int *enabled);
int oakcommon_subtitleparams_set_enabled(OakSubtitleParams params,
int enabled);
/**
* @brief Query whether the set contains at least one subtitle.
*/
int oakcommon_subtitleparams_is_valid(OakSubtitleParams params,
int *is_valid);
/**
* @brief Number of subtitle entries.
*/
int oakcommon_subtitleparams_count(OakSubtitleParams params,
int *count);
/**
* @brief Out time of the last subtitle (0/1 when empty).
*/
int oakcommon_subtitleparams_duration(OakSubtitleParams params,
int *numerator, int *denominator);
/**
* @brief Append a subtitle entry.
*
* @param text Subtitle text. Must not be NULL.
* @return OAKCOMMON_OK or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_subtitleparams_add_subtitle(OakSubtitleParams params,
int in_num, int in_den, int out_num,
int out_den, const char *text);
/**
* @brief Remove all subtitle entries.
*/
int oakcommon_subtitleparams_clear(OakSubtitleParams params);
/**
* @brief Get the time range of the subtitle at @p index.
*
* @return OAKCOMMON_OK, OAKCOMMON_E_NOT_FOUND if @p index is out of range,
* or another negative OAKCOMMON_E_* error code.
*/
int oakcommon_subtitleparams_get_subtitle(OakSubtitleParams params,
int index, int *in_num, int *in_den,
int *out_num, int *out_den);
/**
* @brief Get the text of the subtitle at @p index (two-stage string getter).
*
* @return Required buffer size in bytes including the terminating NUL
* (non-negative), OAKCOMMON_E_NOT_FOUND if @p index is out of
* range, or another negative OAKCOMMON_E_* error code.
*/
int oakcommon_subtitleparams_get_subtitle_text(OakSubtitleParams params,
int index, char *buf,
int buf_size);
/**
* @brief Generate a default ASS header (static, no handle required).
*
* @return Required buffer size in bytes including the terminating NUL
* (non-negative), or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_subtitleparams_generate_ass_header(char *buf, int buf_size);
/**
* @brief Load subtitles from an XML fragment.
*
* @param xml NUL-terminated XML text. Must not be NULL.
* @return OAKCOMMON_OK or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_subtitleparams_load_xml(OakSubtitleParams params,
const char *xml);
/**
* @brief Save subtitles to an XML fragment (two-stage string getter).
*
* @return Required buffer size in bytes including the terminating NUL
* (non-negative), or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_subtitleparams_save_xml(OakSubtitleParams params,
char *buf, int buf_size);
#ifdef __cplusplus
}
#endif
#endif //OAK_EDITOR_SUBTITLEPARAMS_H
@@ -0,0 +1,367 @@
/***
Oak Video Editor - Non-Linear Video Editor
Copyright (C) 2026 Oak Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef OAK_EDITOR_VIDEOPARAMS_H
#define OAK_EDITOR_VIDEOPARAMS_H
#ifndef __cplusplus
#include <stdbool.h>
#endif
#include <stdint.h>
#include "common/error.h"
#include "common/handle.h"
#include "common/ocioutils.h"
#ifdef __cplusplus
namespace olive
{
class VideoParams;
}
extern "C" {
#endif
/**
* @brief Neutral by-value handle to a video parameter set
* (olive::VideoParams).
*
* Ownership/count semantics follow the convention in common/handle.h:
* init functions return a handle whose object has reference count 1,
* addref(ctx)/release(ctx) adjust it atomically, and release destroys
* the object at zero. abi_version is always OAKCOMMON_ABI_VERSION.
*/
typedef struct OakVideoParams {
void *ctx; /**< Opaque pointer to the reference-counted object. */
void (*addref)(void *ctx); /**< Atomically increments the count. */
void (*release)(void *ctx); /**< Decrements the count, destroys at 0. */
uint32_t abi_version; /**< OAKCOMMON_ABI_VERSION. */
} OakVideoParams;
/**
* @brief Interlacing modes, mirroring olive::VideoParams::Interlacing.
*/
enum OakVideoInterlacing {
OAKCOMMON_VIDEO_INTERLACE_NONE = 0,
OAKCOMMON_VIDEO_INTERLACED_TOP_FIRST = 1,
OAKCOMMON_VIDEO_INTERLACED_BOTTOM_FIRST = 2
};
/**
* @brief Video stream types, mirroring olive::VideoParams::Type.
*/
enum OakVideoType {
OAKCOMMON_VIDEO_TYPE_VIDEO = 0,
OAKCOMMON_VIDEO_TYPE_STILL = 1,
OAKCOMMON_VIDEO_TYPE_IMAGE_SEQUENCE = 2
};
/**
* @brief Color range codes, mirroring olive::VideoParams::ColorRange.
*/
enum OakVideoColorRange {
OAKCOMMON_COLOR_RANGE_LIMITED = 0, /**< 16-235 */
OAKCOMMON_COLOR_RANGE_FULL = 1 /**< 0-255 */
};
/**
* @brief Create a default (invalid) video parameter set.
*
* @return Handle with reference count 1; ctx is NULL on allocation
* failure.
*/
OakVideoParams oakcommon_videoparams_init(void);
/**
* @brief Create a video parameter set without a time base.
*
* @param pixel_format One of the OakPixelFormat values.
* @return Handle with reference count 1; ctx is NULL on allocation
* failure.
*/
OakVideoParams oakcommon_videoparams_init_basic(
int width, int height, int pixel_format, int nb_channels,
int pixel_aspect_num, int pixel_aspect_den, int interlacing, int divider);
/**
* @brief Create a video parameter set with a time base.
*
* The frame rate is derived as the flipped time base.
*
* @param pixel_format One of the OakPixelFormat values.
* @return Handle with reference count 1; ctx is NULL on allocation
* failure.
*/
OakVideoParams oakcommon_videoparams_init_with_time_base(
int width, int height, int time_base_num, int time_base_den,
int pixel_format, int nb_channels, int pixel_aspect_num,
int pixel_aspect_den, int interlacing, int divider);
#ifdef __cplusplus
/**
* @brief Copy a native olive::VideoParams into a new handle.
*
* The source object is deep-copied; the handle does not keep any
* reference to @p src, which may be destroyed immediately afterwards.
* Only visible to C++ consumers.
*
* @return Handle with reference count 1; ctx is NULL if src is NULL or
* on allocation failure.
*/
OakVideoParams oakcommon_videoparams_init_from_native(
const olive::VideoParams *src);
/**
* @brief Borrow the native object behind a handle.
*
* The returned pointer is borrowed: it stays valid while the caller
* holds a reference to the handle (i.e. until the matching release).
* Only visible to C++ consumers.
*
* @return Borrowed pointer, or NULL if params is NULL or params->ctx is
* NULL.
*/
const olive::VideoParams *oakcommon_videoparams_get_native(
OakVideoParams params);
#endif
/**
* @brief Release one reference to a video parameter set.
*
* Convenience wrapper around handle.release(handle.ctx): decrements the
* atomic reference count and destroys the object when it reaches zero.
* No-op when params is NULL or params->ctx is NULL.
*/
void oakcommon_videoparams_free(OakVideoParams *params);
int oakcommon_videoparams_get_width(OakVideoParams params, int *width);
int oakcommon_videoparams_set_width(OakVideoParams params, int width);
int oakcommon_videoparams_get_height(OakVideoParams params, int *height);
int oakcommon_videoparams_set_height(OakVideoParams params, int height);
int oakcommon_videoparams_get_depth(OakVideoParams params, int *depth);
int oakcommon_videoparams_set_depth(OakVideoParams params, int depth);
int oakcommon_videoparams_get_is_3d(OakVideoParams params, int *is_3d);
/**
* @brief Rational getters return the value as a numerator/denominator pair.
*/
int oakcommon_videoparams_get_time_base(OakVideoParams params,
int *numerator, int *denominator);
int oakcommon_videoparams_set_time_base(OakVideoParams params,
int numerator, int denominator);
int oakcommon_videoparams_get_frame_rate(OakVideoParams params,
int *numerator, int *denominator);
int oakcommon_videoparams_set_frame_rate(OakVideoParams params,
int numerator, int denominator);
int oakcommon_videoparams_frame_rate_as_time_base(OakVideoParams params,
int *numerator,
int *denominator);
int oakcommon_videoparams_get_pixel_aspect_ratio(OakVideoParams params,
int *numerator,
int *denominator);
int oakcommon_videoparams_set_pixel_aspect_ratio(OakVideoParams params,
int numerator, int denominator);
/**
* @brief Format getters/setters use the OakPixelFormat codes.
*/
int oakcommon_videoparams_get_format(OakVideoParams params, int *format);
int oakcommon_videoparams_set_format(OakVideoParams params, int format);
int oakcommon_videoparams_get_channel_count(OakVideoParams params,
int *count);
int oakcommon_videoparams_set_channel_count(OakVideoParams params,
int count);
int oakcommon_videoparams_get_interlacing(OakVideoParams params,
int *interlacing);
int oakcommon_videoparams_set_interlacing(OakVideoParams params,
int interlacing);
int oakcommon_videoparams_get_divider(OakVideoParams params,
int *divider);
int oakcommon_videoparams_set_divider(OakVideoParams params,
int divider);
int oakcommon_videoparams_get_enabled(OakVideoParams params,
int *enabled);
int oakcommon_videoparams_set_enabled(OakVideoParams params,
int enabled);
int oakcommon_videoparams_get_x(OakVideoParams params, float *x);
int oakcommon_videoparams_set_x(OakVideoParams params, float x);
int oakcommon_videoparams_get_y(OakVideoParams params, float *y);
int oakcommon_videoparams_set_y(OakVideoParams params, float y);
int oakcommon_videoparams_get_stream_index(OakVideoParams params,
int *index);
int oakcommon_videoparams_set_stream_index(OakVideoParams params,
int index);
int oakcommon_videoparams_get_video_type(OakVideoParams params,
int *type);
int oakcommon_videoparams_set_video_type(OakVideoParams params,
int type);
int oakcommon_videoparams_get_start_time(OakVideoParams params,
int64_t *start_time);
int oakcommon_videoparams_set_start_time(OakVideoParams params,
int64_t start_time);
int oakcommon_videoparams_get_duration(OakVideoParams params,
int64_t *duration);
int oakcommon_videoparams_set_duration(OakVideoParams params,
int64_t duration);
int oakcommon_videoparams_get_premultiplied_alpha(OakVideoParams params,
int *premultiplied);
int oakcommon_videoparams_set_premultiplied_alpha(OakVideoParams params,
int premultiplied);
int oakcommon_videoparams_get_color_range(OakVideoParams params,
int *color_range);
int oakcommon_videoparams_set_color_range(OakVideoParams params,
int color_range);
int oakcommon_videoparams_get_color_primaries(OakVideoParams params,
int *primaries);
int oakcommon_videoparams_set_color_primaries(OakVideoParams params,
int primaries);
int oakcommon_videoparams_get_color_transfer(OakVideoParams params,
int *transfer);
int oakcommon_videoparams_set_color_transfer(OakVideoParams params,
int transfer);
/**
* @brief Get the colorspace name (two-stage string getter).
*
* @return Required buffer size in bytes including the terminating NUL
* (non-negative), or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_videoparams_get_colorspace(OakVideoParams params,
char *buf, int buf_size);
int oakcommon_videoparams_set_colorspace(OakVideoParams params,
const char *colorspace);
/**
* @brief Width multiplied by the pixel aspect ratio.
*/
int oakcommon_videoparams_get_square_pixel_width(OakVideoParams params,
int *width);
int oakcommon_videoparams_get_effective_width(OakVideoParams params,
int *width);
int oakcommon_videoparams_get_effective_height(OakVideoParams params,
int *height);
int oakcommon_videoparams_get_effective_depth(OakVideoParams params,
int *depth);
int oakcommon_videoparams_get_is_valid(OakVideoParams params,
int *is_valid);
int oakcommon_videoparams_get_bytes_per_channel(OakVideoParams params,
int *bytes);
int oakcommon_videoparams_get_bytes_per_pixel(OakVideoParams params,
int *bytes);
int oakcommon_videoparams_get_buffer_size(OakVideoParams params,
int *size);
/**
* @brief Convert a time (in seconds, as a rational) to time base units.
*
* Returns INT64_MIN (AV_NOPTS_VALUE) in @p timestamp when no time base is
* set.
*/
int oakcommon_videoparams_get_time_in_timebase_units(
OakVideoParams params, int time_num, int time_den,
int64_t *timestamp);
/**
* @brief Compare two parameter sets for equality.
*/
int oakcommon_videoparams_equals(OakVideoParams params,
OakVideoParams other, int *equal);
/**
* @brief Load parameters from an XML fragment.
*
* @param xml NUL-terminated XML text. Must not be NULL.
* @return OAKCOMMON_OK or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_videoparams_load_xml(OakVideoParams params,
const char *xml);
/**
* @brief Save parameters to an XML fragment (two-stage string getter).
*
* @return Required buffer size in bytes including the terminating NUL
* (non-negative), or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_videoparams_save_xml(OakVideoParams params, char *buf,
int buf_size);
/* Static helpers (no handle required). */
int oakcommon_videoparams_get_bytes_per_channel_for_format(int pixel_format);
int oakcommon_videoparams_get_bytes_per_pixel_for_format(int pixel_format,
int channels);
int oakcommon_videoparams_calculate_buffer_size(int width, int height,
int pixel_format,
int channels);
int oakcommon_videoparams_format_is_float(int pixel_format);
int oakcommon_videoparams_generate_auto_divider(int64_t width, int64_t height);
int oakcommon_videoparams_get_scaled_dimension(int dimension, int divider);
int oakcommon_videoparams_get_divider_for_target_resolution(int src_width,
int src_height,
int dst_width,
int dst_height);
/**
* @brief Human-readable name for a divider ("Full", "1/2", ...).
*
* @return Required buffer size in bytes including the terminating NUL
* (non-negative), or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_videoparams_get_name_for_divider(int divider, char *buf,
int buf_size);
/**
* @brief Human-readable name for a pixel format.
*
* @return Required buffer size in bytes including the terminating NUL
* (non-negative), or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_videoparams_get_format_name(int pixel_format, char *buf,
int buf_size);
/**
* @brief Human-readable frame rate string ("23.976 FPS").
*
* @return Required buffer size in bytes including the terminating NUL
* (non-negative), or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_videoparams_frame_rate_to_string(int numerator, int denominator,
char *buf, int buf_size);
/**
* @brief Get bytes per channel.
*
* @return Bytes per channel.
*/
int oakcommon_videoparams_static_get_bytes_per_channel(OakPixelFormat format);
/**
* @brief Get bytes per pixel.
*
* @return Bytes per pixel.
*/
int oakcommon_videoparams_static_get_bytes_per_pixel(OakPixelFormat format,
int channels);
#ifdef __cplusplus
}
#endif
#endif //OAK_EDITOR_VIDEOPARAMS_H
@@ -0,0 +1,215 @@
/***
Oak Video Editor - Non-Linear Video Editor
Copyright (C) 2026 Oak Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef OAK_EDITOR_XMLUTILS_H
#define OAK_EDITOR_XMLUTILS_H
#include "common/error.h"
#include "common/handle.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Neutral by-value handle to a streaming XML reader.
*
* Ownership/count semantics follow the convention in common/handle.h:
* init returns a handle whose object has reference count 1,
* addref(ctx)/release(ctx) adjust it atomically, and release destroys
* the object at zero. abi_version is always OAKCOMMON_ABI_VERSION.
*/
typedef struct OakXmlReader {
void *ctx; /**< Opaque pointer to the reference-counted object. */
void (*addref)(void *ctx); /**< Atomically increments the count. */
void (*release)(void *ctx); /**< Decrements the count, destroys at 0. */
uint32_t abi_version; /**< OAKCOMMON_ABI_VERSION. */
} OakXmlReader;
/**
* @brief Neutral by-value handle to a streaming XML writer.
*
* Same ownership/count semantics as OakXmlReader.
*/
typedef struct OakXmlWriter {
void *ctx; /**< Opaque pointer to the reference-counted object. */
void (*addref)(void *ctx); /**< Atomically increments the count. */
void (*release)(void *ctx); /**< Decrements the count, destroys at 0. */
uint32_t abi_version; /**< OAKCOMMON_ABI_VERSION. */
} OakXmlWriter;
/**
* @brief Create a streaming XML reader over a complete document.
*
* @param data NUL-terminated XML text. Must not be NULL.
* @return Handle with reference count 1; ctx is NULL on failure
* (NULL data, out of memory).
*/
OakXmlReader oakcommon_xml_reader_init(const char *data);
#ifdef __cplusplus
} /* extern "C" */
namespace olive { class XmlStreamReader; class XmlStreamWriter; }
extern "C" {
#endif
/**
* @brief Borrowed access to the underlying C++ reader/writer (C++ only,
* for adapter layers). Valid while the handle is held. NULL-safe.
*/
olive::XmlStreamReader *oakcommon_xml_reader_get_native(OakXmlReader reader);
olive::XmlStreamWriter *oakcommon_xml_writer_get_native(OakXmlWriter writer);
/**
* @brief Wrap an existing C++ reader/writer in a borrowed handle (C++
* only, for adapter layers). The box never owns the object; the caller
* must keep it alive and release the box with
* oakcommon_xml_reader_free()/oakcommon_xml_writer_free(). Empty handle
* for a NULL object or on allocation failure.
*/
OakXmlReader oakcommon_xml_reader_wrap_native(olive::XmlStreamReader *reader);
OakXmlWriter oakcommon_xml_writer_wrap_native(olive::XmlStreamWriter *writer);
/**
* @brief Release one reference to a reader.
*
* Convenience wrapper around handle.release(handle.ctx): decrements the
* atomic reference count and destroys the object when it reaches zero.
* No-op when reader is NULL or reader->ctx is NULL.
*/
void oakcommon_xml_reader_free(OakXmlReader *reader);
/**
* @brief Advance until the next start element, an end element, or the end
* of the document.
*
* @param reader Reader handle.
* @param found Out: 1 if positioned on a start element, 0 otherwise.
* @return OAKCOMMON_OK or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_xml_reader_read_next_start_element(OakXmlReader reader,
int *found);
/**
* @brief Name of the current element token.
*
* @return Required buffer size in bytes (including NUL), or a negative
* OAKCOMMON_E_* error code.
*/
int oakcommon_xml_reader_name(OakXmlReader reader, char *buf,
int buf_size);
/**
* @brief Read the concatenated character data of the current element.
*
* Must be called on a start element; consumes up to the matching end
* element.
*
* @return Required buffer size in bytes (including NUL), or a negative
* OAKCOMMON_E_* error code.
*/
int oakcommon_xml_reader_read_element_text(OakXmlReader reader,
char *buf, int buf_size);
/**
* @brief Skip the current element and all of its children.
*
* @return OAKCOMMON_OK or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_xml_reader_skip_current_element(OakXmlReader reader);
/**
* @brief Number of attributes on the current start element.
*
* @return OAKCOMMON_OK or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_xml_reader_attribute_count(OakXmlReader reader,
int *count);
/**
* @brief Name of the attribute at @p index on the current start element.
*
* @return Required buffer size in bytes (including NUL), OAKCOMMON_E_NOT_FOUND
* if @p index is out of range, or another negative OAKCOMMON_E_* code.
*/
int oakcommon_xml_reader_attribute_name(OakXmlReader reader, int index,
char *buf, int buf_size);
/**
* @brief Value of the attribute at @p index on the current start element.
*
* @return Required buffer size in bytes (including NUL), OAKCOMMON_E_NOT_FOUND
* if @p index is out of range, or another negative OAKCOMMON_E_* code.
*/
int oakcommon_xml_reader_attribute_value(OakXmlReader reader,
int index, char *buf, int buf_size);
/**
* @brief Whether the document failed to parse.
*
* @return OAKCOMMON_OK or a negative OAKCOMMON_E_* error code.
*/
int oakcommon_xml_reader_has_error(OakXmlReader reader,
int *has_error);
/**
* @brief Create a streaming XML writer.
*
* @return Handle with reference count 1; ctx is NULL on failure.
*/
OakXmlWriter oakcommon_xml_writer_init(void);
/**
* @brief Release one reference to a writer.
*
* Convenience wrapper around handle.release(handle.ctx): decrements the
* atomic reference count and destroys the object when it reaches zero.
* No-op when writer is NULL or writer->ctx is NULL.
*/
void oakcommon_xml_writer_free(OakXmlWriter *writer);
int oakcommon_xml_writer_write_start_element(OakXmlWriter writer,
const char *name);
int oakcommon_xml_writer_write_attribute(OakXmlWriter writer,
const char *name, const char *value);
int oakcommon_xml_writer_write_characters(OakXmlWriter writer,
const char *text);
int oakcommon_xml_writer_write_text_element(OakXmlWriter writer,
const char *name,
const char *text);
int oakcommon_xml_writer_write_end_element(OakXmlWriter writer);
int oakcommon_xml_writer_write_end_document(OakXmlWriter writer);
/**
* @brief The document written so far.
*
* @return Required buffer size in bytes (including NUL), or a negative
* OAKCOMMON_E_* error code.
*/
int oakcommon_xml_writer_output(OakXmlWriter writer, char *buf,
int buf_size);
#ifdef __cplusplus
}
#endif
#endif // OAK_EDITOR_XMLUTILS_H