goliveapi-postdata.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "goliveapi-postdata.hpp"
  2. #include <nlohmann/json.hpp>
  3. #include "system-info.hpp"
  4. #include "models/multitrack-video.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. if (maximum_aggregate_bitrate.has_value())
  50. preferences.maximum_aggregate_bitrate = maximum_aggregate_bitrate.value();
  51. if (maximum_video_tracks.has_value())
  52. preferences.maximum_video_tracks = maximum_video_tracks.value();
  53. return post_data;
  54. }