Repository navigation
Conversation
ce1b263 to
c03b4fb
Compare
6dcd68c to
d404b1b
Compare
420b8d7 to
60f2951
Compare
|
#10633 was merged some time ago. This will need to be rebased and get CI to pass. |
60f2951 to
7c05363
Compare
|
@palana It looks like the build failures are still present. |
7c05363 to
8dffc0a
Compare
| } | ||
|
|
||
| const std::vector<MultitrackVideoViewInfo> & | ||
| OBSBasic::GetAdditionalMultitrackVideoViews() |
There was a problem hiding this comment.
This does nothing but return a copy of the value. Probably fine to fetch the value directly?
There was a problem hiding this comment.
not sure I follow, this returns a const reference, rather than a copy (i.e. you're allowed to read entries, but not modify them)
| } | ||
| obs_video_info *ovi = &ovi_storage; | ||
|
|
||
| const char *view_name = nullptr; |
There was a problem hiding this comment.
This is probably safer as std::string.
There was a problem hiding this comment.
safer in what way? encoder_config can't be modified in here (unless someone adds a const cast?), so the pointer (once assigned) stays valid for this scope at least (and it's not used outside of this scope)
There was a problem hiding this comment.
From a cursory glance there are multiple reasons:
- This is C++ code. By default one should use C++ types and avoid low-level C types at all costs.
- The
view_nameis derived fromencoder_config.view, which is astd::stringalready. So the code taps into the internal data of that string instead of using a reference to the originalstd::string, particularly as it is only used forstd::map::findanyway.
It's precisely the kind of code style that the C++ committee and the language designers tell developers to avoid. Use C++ types and avoid pointers and C types at all costs.
There was a problem hiding this comment.
@PatTheMav: can you help me translate what you're suggesting? https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#f16-for-in-parameters-pass-cheaply-copied-types-by-value-and-others-by-reference-to-const even lists pointers as first option when passing an optional argument into a function (c++ doesn't really support rust's Option<&str> or similar unfortunately)
so another option would be to do special handling for empty strings, instead of requiring special handling on a different layer (c pointers, and generally everything c++ is kind of terrible for this unfortunately, since most of these won't noisily fail when you use them wrong, and the compiler also doesn't help you due to lack of borrow checking); if that's the preference here I can make that change
or are you asking for this to be translated into std::string *view_name = nullptr; instead?
There was a problem hiding this comment.
The root cause of this is that the view name is optional in VideoEncoderConfiguration, but I wonder if this has to be the case:
If OBS is supposed to support multiple views and views carry a name, then the main view should also hold a name and not be identified by "the lack of any name", which is brittle.
So instead the requirement could be: OBS can have multiple views, every view needs to have a unique name, including the main view. This would also allow everyone working with views to clearly identify the views and gives OBS itself the ability to "reserve" view names (and there are already ternary expressions trying to use the fallback name "obs_base", so there clearly is a requirement for the main/base view to have a name).
That also has the potential to solve the following issues:
adjust_video_encoder_scalingdoesn't have to accept a mish-mash of actual values ornullptrs and use ternary expressions to get some video dimensions or view name from something else.- In the same vein
adjust_video_encoder_scaling's argument list wouldn't need to mix mandatory and logically optional arguments instead of following the good practice of putting mandatory arguments first and optional ones last
So there should be a single list of views to which the "main view" is added and additional views can be added by the frontend API. Then the code could work with the expectation that:
- The list contains at least a single view (not having any views would be an invalid application state)
- Every view (including the main view) carries a name and the same metadata and video info
This is all complex stuff and I appreciate the work put into this, but that's even more reason to make it as straightforward as possible and avoid a pile of little workarounds here, there, and everywhere to squeeze in this functionality.
dabc2f6 to
212f177
Compare
Co-authored-by: Ruwen Hahn <[email protected]>
…nregister rename `void*` argument
…nregister add prefix to callback types
…nregister add name parameter to callbacks
add name parameter to callbacks
…nregister Update documentation to reflect latest code changes.
212f177 to
2b549f8
Compare
| } | ||
|
|
||
| if (!extra_views.empty()) { | ||
| auto &extra_views_capability = *post_data.capabilities.extra_views; |
There was a problem hiding this comment.
Maybe I'm missing something, but extra_views is of type optional<std::vector<ExtraView>> and operator* is an unchecked access to the underlying data. By this point in code the optional should have a disengaged value and operator* crashes.
Is there code that explicitly initialises the std::vector in the optional that I missed?
There was a problem hiding this comment.
nope, seems like an accident that it currently works as is (as in, an empty vector looks the same as whatever contents the optional gets default-initialized with?)
There was a problem hiding this comment.
Right, I wondered the same (particularly if the declaration leads to a default initialisation of the wrapped std::vector) but at least this small reproducer crashes at operator*:
#include <iostream>
#include <optional>
#include <vector>
#include <string>
struct Test {
std::optional<std::vector<std::string>> optionals;
};
int main(int argc, const char * argv[]) {
Test test;
auto &some = *test.optionals;
some.reserve(10);
some.push_back("Hello");
for (auto &opt : some) {
std::cout << opt.data() << "\n";
}
return 0;
}There was a problem hiding this comment.
I'm unfortunately too late to the party, but function signatures like this:
static OBSOutputs SetupOBSOutput(QWidget *parent, const QString &multitrack_video_name,
obs_data_t *dump_stream_to_file_config, const GoLiveApi::Config &go_live_config,
std::vector<OBSEncoderAutoRelease> &audio_encoders,
std::shared_ptr<obs_encoder_group_t> &video_encoder_group,
const char *audio_encoder_id, size_t main_audio_mixer,
std::optional<size_t> vod_track_mixer,
const std::map<std::string, video_t *> &extra_views);or this:
void MultitrackVideoOutput::PrepareStreaming(
QWidget *parent, const char *service_name, obs_service_t *service, const std::optional<std::string> &rtmp_url,
const QString &stream_key, const char *audio_encoder_id, std::optional<uint32_t> maximum_aggregate_bitrate,
std::optional<uint32_t> maximum_video_tracks, std::optional<std::string> custom_config,
obs_data_t *dump_stream_to_file_config, size_t main_audio_mixer, std::optional<size_t> vod_track_mixer)make it already visually obvious that we're doing something wrong here.
How many of these fields are actually invariant? Because if they are (i.e. only in combination do they constitute the minimally required data necessary for the function to do its job) they should've been combined in a single "object" (aka a struct), which would also potentially decouple the order of the arguments and fix the issue of mandatory arguments being mixed in with optional arguments.
Right now, these functions create unreasonable high barriers for other maintainers to parse properly because it's just visual (and logical) noise. And just piling on even more optional arguments (which are not truly "optional" but still require a nullopt) makes it worse.
| video_t *video = video_output.start_video(video_output.name.c_str(), video_output.param); | ||
| if (!video) | ||
| continue; | ||
| extra_views->views_[video_output.name] = video; |
There was a problem hiding this comment.
Is the use of the subscript operator intended here? extra_views is initialised just before, so it should hold no pre-existing values and the subscript operator is doing a whole lot more things then what an emplace would do:
It first searches the map for the given key, inserts a default-constructed value if not found, returns a reference to that value, to which you then assign video.
Maybe that's desired, but I usually advise to avoid operator[] when just inserting elements into a map.
| } | ||
| obs_video_info *ovi = &ovi_storage; | ||
|
|
||
| const char *view_name = nullptr; |
There was a problem hiding this comment.
The root cause of this is that the view name is optional in VideoEncoderConfiguration, but I wonder if this has to be the case:
If OBS is supposed to support multiple views and views carry a name, then the main view should also hold a name and not be identified by "the lack of any name", which is brittle.
So instead the requirement could be: OBS can have multiple views, every view needs to have a unique name, including the main view. This would also allow everyone working with views to clearly identify the views and gives OBS itself the ability to "reserve" view names (and there are already ternary expressions trying to use the fallback name "obs_base", so there clearly is a requirement for the main/base view to have a name).
That also has the potential to solve the following issues:
adjust_video_encoder_scalingdoesn't have to accept a mish-mash of actual values ornullptrs and use ternary expressions to get some video dimensions or view name from something else.- In the same vein
adjust_video_encoder_scaling's argument list wouldn't need to mix mandatory and logically optional arguments instead of following the good practice of putting mandatory arguments first and optional ones last
So there should be a single list of views to which the "main view" is added and additional views can be added by the frontend API. Then the code could work with the expectation that:
- The list contains at least a single view (not having any views would be an invalid application state)
- Every view (including the main view) carries a name and the same metadata and video info
This is all complex stuff and I appreciate the work put into this, but that's even more reason to make it as straightforward as possible and avoid a pile of little workarounds here, there, and everywhere to squeeze in this functionality.
| } | ||
| } | ||
|
|
||
| void obs_frontend_multitrack_video_register(const char *name, |
There was a problem hiding this comment.
Two questions about this:
- Is this implemented in the frontend API because the frontend is nominally the part of the program that manages views and outputs (that'd be unfortunate as it violates what the word "frontend" implies, but that'd be an issue with OBS' internal architecture then)
- Is there anything about this functionality that couples it with the multitrack feature? Because if it doesn't, then I'd rather see this use a more generic term.
There was a problem hiding this comment.
its only purpose is to enable views to participate in multitrack streaming, at least I'm not aware of any other functionality that would make use of this right now
upcoming webrtc multitrack (and other/future multitrack outputs) might be interested in this at some point, but so far webrtc multitrack is stuck in review
doing this in libobs-land is somewhat very uncharted territory, since views/video outputs/general obs objects don't carry meta information about their intended purpose (and given the private data capabilities, they're currently very much in "don't touch these objects unless you know where they come from/why they're there" territory)
initialize `vector` inside `optional` before using it
Description
Adds frontend API calls to allow plugins to register additional canvases/video outputs that will participate in multitrack video configuration generation and multitrack video streams
Motivation and Context
Currently additional views/canvases have to use separate rtmp connections or similar to be streamed, where the multitrack video output allows both multiple renditions of the same view and also different views to be streamed
How Has This Been Tested?
Twitch Enhanced Broadcasting beta
Types of changes
Checklist: