GoLiveAPI_PostData.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. const char *encoder_id = nullptr;
  18. for (size_t i = 0; obs_enum_encoder_types(i, &encoder_id); i++) {
  19. auto codec = obs_get_encoder_codec(encoder_id);
  20. if (!codec)
  21. continue;
  22. if (qstricmp(codec, "h264") == 0) {
  23. client.supported_codecs.emplace("h264");
  24. #ifdef ENABLE_HEVC
  25. } else if (qstricmp(codec, "hevc") == 0) {
  26. client.supported_codecs.emplace("h265");
  27. #endif
  28. } else if (qstricmp(codec, "av1") == 0) {
  29. client.supported_codecs.emplace("av1");
  30. }
  31. }
  32. auto &preferences = post_data.preferences;
  33. preferences.vod_track_audio = vod_track_enabled;
  34. obs_video_info ovi;
  35. if (obs_get_video_info(&ovi))
  36. preferences.composition_gpu_index = ovi.adapter;
  37. for (const auto &canvas : canvases) {
  38. if (obs_canvas_get_video_info(canvas, &ovi)) {
  39. preferences.canvases.emplace_back(GoLiveApi::Canvas{ovi.output_width,
  40. ovi.output_height,
  41. ovi.base_width,
  42. ovi.base_height,
  43. {ovi.fps_num, ovi.fps_den}});
  44. }
  45. }
  46. obs_audio_info2 oai2;
  47. if (obs_get_audio_info2(&oai2)) {
  48. preferences.audio_samples_per_sec = oai2.samples_per_sec;
  49. preferences.audio_channels = get_audio_channels(oai2.speakers);
  50. preferences.audio_fixed_buffering = oai2.fixed_buffering;
  51. preferences.audio_max_buffering_ms = oai2.max_buffering_ms;
  52. }
  53. if (maximum_aggregate_bitrate.has_value())
  54. preferences.maximum_aggregate_bitrate = maximum_aggregate_bitrate.value();
  55. if (maximum_video_tracks.has_value()) {
  56. /* Cap to maximum supported number of output encoders. */
  57. preferences.maximum_video_tracks =
  58. std::min(maximum_video_tracks.value(), static_cast<uint32_t>(MAX_OUTPUT_VIDEO_ENCODERS));
  59. }
  60. return post_data;
  61. }