goliveapi-postdata.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "goliveapi-postdata.hpp"
  2. #include <nlohmann/json.hpp>
  3. #include "system-info.hpp"
  4. #include "models/multitrack-video.hpp"
  5. GoLiveApi::PostData
  6. constructGoLivePost(QString streamKey,
  7. const std::optional<uint64_t> &maximum_aggregate_bitrate,
  8. const std::optional<uint32_t> &maximum_video_tracks,
  9. bool vod_track_enabled)
  10. {
  11. GoLiveApi::PostData post_data{};
  12. post_data.service = "IVS";
  13. post_data.schema_version = "2024-06-04";
  14. post_data.authentication = streamKey.toStdString();
  15. system_info(post_data.capabilities);
  16. auto &client = post_data.client;
  17. client.name = "obs-studio";
  18. client.version = obs_get_version_string();
  19. auto add_codec = [&](const char *codec) {
  20. auto it = std::find(std::begin(client.supported_codecs),
  21. std::end(client.supported_codecs), codec);
  22. if (it != std::end(client.supported_codecs))
  23. return;
  24. client.supported_codecs.push_back(codec);
  25. };
  26. const char *encoder_id = nullptr;
  27. for (size_t i = 0; obs_enum_encoder_types(i, &encoder_id); i++) {
  28. auto codec = obs_get_encoder_codec(encoder_id);
  29. if (!codec)
  30. continue;
  31. if (qstricmp(codec, "h264") == 0) {
  32. add_codec("h264");
  33. #ifdef ENABLE_HEVC
  34. } else if (qstricmp(codec, "hevc")) {
  35. add_codec("h265");
  36. #endif
  37. } else if (qstricmp(codec, "av1")) {
  38. add_codec("av1");
  39. }
  40. }
  41. auto &preferences = post_data.preferences;
  42. preferences.vod_track_audio = vod_track_enabled;
  43. obs_video_info ovi;
  44. if (obs_get_video_info(&ovi)) {
  45. preferences.width = ovi.output_width;
  46. preferences.height = ovi.output_height;
  47. preferences.framerate.numerator = ovi.fps_num;
  48. preferences.framerate.denominator = ovi.fps_den;
  49. preferences.canvas_width = ovi.base_width;
  50. preferences.canvas_height = ovi.base_height;
  51. preferences.composition_gpu_index = ovi.adapter;
  52. }
  53. if (maximum_aggregate_bitrate.has_value())
  54. preferences.maximum_aggregate_bitrate =
  55. maximum_aggregate_bitrate.value();
  56. if (maximum_video_tracks.has_value())
  57. preferences.maximum_video_tracks = maximum_video_tracks.value();
  58. return post_data;
  59. }