GoLiveAPI_PostData.cpp 2.5 KB

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