GoLiveAPI_PostData.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 = "2024-06-04";
  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.width = ovi.output_width;
  42. preferences.height = ovi.output_height;
  43. preferences.framerate.numerator = ovi.fps_num;
  44. preferences.framerate.denominator = ovi.fps_den;
  45. preferences.canvas_width = ovi.base_width;
  46. preferences.canvas_height = ovi.base_height;
  47. preferences.composition_gpu_index = ovi.adapter;
  48. }
  49. obs_audio_info2 oai2;
  50. if (obs_get_audio_info2(&oai2)) {
  51. preferences.audio_samples_per_sec = oai2.samples_per_sec;
  52. preferences.audio_channels = get_audio_channels(oai2.speakers);
  53. preferences.audio_fixed_buffering = oai2.fixed_buffering;
  54. preferences.audio_max_buffering_ms = oai2.max_buffering_ms;
  55. }
  56. if (maximum_aggregate_bitrate.has_value())
  57. preferences.maximum_aggregate_bitrate = maximum_aggregate_bitrate.value();
  58. if (maximum_video_tracks.has_value())
  59. preferences.maximum_video_tracks = maximum_video_tracks.value();
  60. return post_data;
  61. }