Runtime options let an embedder change Open Screen's behavior while the program runs, without a rebuild. For example, an embedder can use them to:
If the defaults work for you, you don't need to do anything.
The options are the fields of openscreen::RuntimeOptions in platform/api/runtime_options.h. The default value of each field is the library's recommended setting.
The comment on each field is the reference for that option. It says what the option controls, when Open Screen reads it, and which build arguments it depends on, if any.
Start from a default-constructed RuntimeOptions, change only the fields that you want to control, and pass it to SetRuntimeOptions():
#include "platform/api/runtime_options.h" void ConfigureOpenScreen(bool use_rust_json) { openscreen::RuntimeOptions options; // Starts with the library defaults. options.use_rust_json = use_rust_json; openscreen::SetRuntimeOptions(options); }
Because you start from the defaults, any option that is added later keeps its library default until you choose to set it.
Open Screen reads some options every time it uses them, and others only once, when it creates the object that uses them. That object keeps the value for its whole life, so a later change does not affect it.
To make sure that every option applies everywhere, set the options at startup, before you create any Open Screen objects. You can call SetRuntimeOptions() again later. Each call replaces all of the options, and the new values apply to every read after the call. Objects that already read an option keep the value that they read.
The options are stored per process, so if your program runs Open Screen in more than one process, set them in each of those processes.
GetRuntimeOptions() and SetRuntimeOptions() can be called on any thread.
Chromium maps each option to a base::Feature in //components/openscreen_platform. It sets every option from its feature, so the feature state, not the library default, decides the value in Chromium. This lets Chromium roll out a new implementation, or turn it off, with a field trial. Each feature's default matches the library default.
Chromium's TaskRunner implementation copies the features into RuntimeOptions each time it is created. Every Open Screen sender and receiver in Chromium needs a TaskRunner, so each process applies its features before Open Screen reads them. The browser passes feature state to its child processes, so all of them get the same values.
Use ScopedRuntimeOptions from platform/test/scoped_runtime_options.h. It sets the options for its lifetime and then restores the previous options:
#include "platform/test/scoped_runtime_options.h" TEST(MyTest, WorksWithOptionDisabled) { openscreen::RuntimeOptions options; options.use_rust_json = false; openscreen::ScopedRuntimeOptions scoped_options(options); // Code in this scope sees use_rust_json == false. }
If an option is read only when an object is created, create the object inside the scope.
These steps are for Open Screen developers:
RuntimeOptions with the recommended default.GetRuntimeOptions(). If an object must keep the same behavior for its whole life, read the field once, when the object is created.ScopedRuntimeOptions.RuntimeOptions must stay small enough for std::atomic to be lock-free. A static_assert in platform/api/runtime_options.cc fails if a new field breaks this.
When an option is no longer needed, delete its field. Embedders that set the field must stop setting it, so tell them before you remove it.