GoLiveAPI_PostData.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include "GoLiveAPI_PostData.hpp"
  2. #include "models/multitrack-video.hpp"
  3. #include <utility/system-info.hpp>
  4. #include <nlohmann/json.hpp>
  5. GoLiveApi::PostData constructGoLivePost(QString streamKey, const std::optional<uint64_t> &maximum_aggregate_bitrate,
  6. const std::optional<uint32_t> &maximum_video_tracks, bool vod_track_enabled,
  7. const std::vector<OBSCanvasAutoRelease> &canvases)
  8. {
  9. GoLiveApi::PostData post_data{};
  10. post_data.service = "IVS";
  11. post_data.schema_version = "2025-01-25";
  12. post_data.authentication = streamKey.toStdString();
  13. system_info(post_data.capabilities);
  14. auto &client = post_data.client;
  15. client.name = "obs-studio";
  16. client.version = obs_get_version_string();
  17. auto add_codec = [&](const char *codec) {
  18. auto it = std::find(std::begin(client.supported_codecs), std::end(client.supported_codecs), codec);
  19. if (it != std::end(client.supported_codecs))
  20. return;
  21. client.supported_codecs.push_back(codec);
  22. };
  23. const char *encoder_id = nullptr;
  24. for (size_t i = 0; obs_enum_encoder_types(i, &encoder_id); i++) {
  25. auto codec = obs_get_encoder_codec(encoder_id);
  26. if (!codec)
  27. continue;
  28. if (qstricmp(codec, "h264") == 0) {
  29. add_codec("h264");
  30. #ifdef ENABLE_HEVC
  31. } else if (qstricmp(codec, "hevc")) {
  32. add_codec("h265");
  33. #endif
  34. } else if (qstricmp(codec, "av1")) {
  35. add_codec("av1");
  36. }
  37. }
  38. auto &preferences = post_data.preferences;
  39. preferences.vod_track_audio = vod_track_enabled;
  40. obs_video_info ovi;
  41. if (obs_get_video_info(&ovi))
  42. preferences.composition_gpu_index = ovi.adapter;
  43. for (const auto &canvas : canvases) {
  44. if (obs_canvas_get_video_info(canvas, &ovi)) {
  45. preferences.canvases.emplace_back(GoLiveApi::Canvas{ovi.output_width,
  46. ovi.output_height,
  47. ovi.base_width,
  48. ovi.base_height,
  49. {ovi.fps_num, ovi.fps_den}});
  50. }
  51. }
  52. obs_audio_info2 oai2;
  53. if (obs_get_audio_info2(&oai2)) {
  54. preferences.audio_samples_per_sec = oai2.samples_per_sec;
  55. preferences.audio_channels = get_audio_channels(oai2.speakers);
  56. preferences.audio_fixed_buffering = oai2.fixed_buffering;
  57. preferences.audio_max_buffering_ms = oai2.max_buffering_ms;
  58. }
  59. if (maximum_aggregate_bitrate.has_value())
  60. preferences.maximum_aggregate_bitrate = maximum_aggregate_bitrate.value();
  61. if (maximum_video_tracks.has_value()) {
  62. /* Cap to maximum supported number of output encoders. */
  63. preferences.maximum_video_tracks =
  64. std::min(maximum_video_tracks.value(), static_cast<uint32_t>(MAX_OUTPUT_VIDEO_ENCODERS));
  65. }
  66. return post_data;
  67. }