1
0

OBSBasic_OutputHandler.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /******************************************************************************
  2. Copyright (C) 2023 by Lain Bailey <[email protected]>
  3. Zachary Lund <[email protected]>
  4. Philippe Groarke <[email protected]>
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ******************************************************************************/
  16. #include "OBSBasic.hpp"
  17. #include <qt-wrappers.hpp>
  18. #include <QDir>
  19. void OBSBasic::ResetOutputs()
  20. {
  21. ProfileScope("OBSBasic::ResetOutputs");
  22. const char *mode = config_get_string(activeConfiguration, "Output", "Mode");
  23. bool advOut = astrcmpi(mode, "Advanced") == 0;
  24. if ((!outputHandler || !outputHandler->Active()) &&
  25. (!setupStreamingGuard.valid() ||
  26. setupStreamingGuard.wait_for(std::chrono::seconds{0}) == std::future_status::ready)) {
  27. outputHandler.reset();
  28. outputHandler.reset(advOut ? CreateAdvancedOutputHandler(this) : CreateSimpleOutputHandler(this));
  29. emit ReplayBufEnabled(outputHandler->replayBuffer);
  30. if (sysTrayReplayBuffer)
  31. sysTrayReplayBuffer->setEnabled(!!outputHandler->replayBuffer);
  32. UpdateIsRecordingPausable();
  33. } else {
  34. outputHandler->Update();
  35. }
  36. }
  37. bool OBSBasic::Active() const
  38. {
  39. if (!outputHandler)
  40. return false;
  41. return outputHandler->Active();
  42. }
  43. void OBSBasic::ResizeOutputSizeOfSource()
  44. {
  45. if (obs_video_active())
  46. return;
  47. QMessageBox resize_output(this);
  48. resize_output.setText(QTStr("ResizeOutputSizeOfSource.Text") + "\n\n" +
  49. QTStr("ResizeOutputSizeOfSource.Continue"));
  50. QAbstractButton *Yes = resize_output.addButton(QTStr("Yes"), QMessageBox::YesRole);
  51. resize_output.addButton(QTStr("No"), QMessageBox::NoRole);
  52. resize_output.setIcon(QMessageBox::Warning);
  53. resize_output.setWindowTitle(QTStr("ResizeOutputSizeOfSource"));
  54. resize_output.exec();
  55. if (resize_output.clickedButton() != Yes)
  56. return;
  57. OBSSource source = obs_sceneitem_get_source(GetCurrentSceneItem());
  58. int width = obs_source_get_width(source);
  59. int height = obs_source_get_height(source);
  60. width = ((width + 3) / 4) * 4; // Round width up to the nearest multiple of 4
  61. height = ((height + 1) / 2) * 2; // Round height up to the nearest multiple of 2
  62. config_set_uint(activeConfiguration, "Video", "BaseCX", width);
  63. config_set_uint(activeConfiguration, "Video", "BaseCY", height);
  64. config_set_uint(activeConfiguration, "Video", "OutputCX", width);
  65. config_set_uint(activeConfiguration, "Video", "OutputCY", height);
  66. ResetVideo();
  67. ResetOutputs();
  68. activeConfiguration.SaveSafe("tmp");
  69. on_actionFitToScreen_triggered();
  70. }
  71. const char *OBSBasic::GetCurrentOutputPath()
  72. {
  73. const char *path = nullptr;
  74. const char *mode = config_get_string(Config(), "Output", "Mode");
  75. if (strcmp(mode, "Advanced") == 0) {
  76. const char *advanced_mode = config_get_string(Config(), "AdvOut", "RecType");
  77. if (strcmp(advanced_mode, "FFmpeg") == 0) {
  78. path = config_get_string(Config(), "AdvOut", "FFFilePath");
  79. } else {
  80. path = config_get_string(Config(), "AdvOut", "RecFilePath");
  81. }
  82. } else {
  83. path = config_get_string(Config(), "SimpleOutput", "FilePath");
  84. }
  85. return path;
  86. }
  87. void OBSBasic::OutputPathInvalidMessage()
  88. {
  89. blog(LOG_ERROR, "Recording stopped because of bad output path");
  90. OBSMessageBox::critical(this, QTStr("Output.BadPath.Title"), QTStr("Output.BadPath.Text"));
  91. }
  92. bool OBSBasic::IsFFmpegOutputToURL() const
  93. {
  94. const char *mode = config_get_string(Config(), "Output", "Mode");
  95. if (strcmp(mode, "Advanced") == 0) {
  96. const char *advanced_mode = config_get_string(Config(), "AdvOut", "RecType");
  97. if (strcmp(advanced_mode, "FFmpeg") == 0) {
  98. bool is_local = config_get_bool(Config(), "AdvOut", "FFOutputToFile");
  99. if (!is_local)
  100. return true;
  101. }
  102. }
  103. return false;
  104. }
  105. bool OBSBasic::OutputPathValid()
  106. {
  107. if (IsFFmpegOutputToURL())
  108. return true;
  109. const char *path = GetCurrentOutputPath();
  110. return path && *path && QDir(path).exists();
  111. }