OBSBasic_OutputHandler.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. config_set_uint(activeConfiguration, "Video", "BaseCX", width);
  61. config_set_uint(activeConfiguration, "Video", "BaseCY", height);
  62. config_set_uint(activeConfiguration, "Video", "OutputCX", width);
  63. config_set_uint(activeConfiguration, "Video", "OutputCY", height);
  64. ResetVideo();
  65. ResetOutputs();
  66. activeConfiguration.SaveSafe("tmp");
  67. on_actionFitToScreen_triggered();
  68. }
  69. const char *OBSBasic::GetCurrentOutputPath()
  70. {
  71. const char *path = nullptr;
  72. const char *mode = config_get_string(Config(), "Output", "Mode");
  73. if (strcmp(mode, "Advanced") == 0) {
  74. const char *advanced_mode = config_get_string(Config(), "AdvOut", "RecType");
  75. if (strcmp(advanced_mode, "FFmpeg") == 0) {
  76. path = config_get_string(Config(), "AdvOut", "FFFilePath");
  77. } else {
  78. path = config_get_string(Config(), "AdvOut", "RecFilePath");
  79. }
  80. } else {
  81. path = config_get_string(Config(), "SimpleOutput", "FilePath");
  82. }
  83. return path;
  84. }
  85. void OBSBasic::OutputPathInvalidMessage()
  86. {
  87. blog(LOG_ERROR, "Recording stopped because of bad output path");
  88. OBSMessageBox::critical(this, QTStr("Output.BadPath.Title"), QTStr("Output.BadPath.Text"));
  89. }
  90. bool OBSBasic::IsFFmpegOutputToURL() const
  91. {
  92. const char *mode = config_get_string(Config(), "Output", "Mode");
  93. if (strcmp(mode, "Advanced") == 0) {
  94. const char *advanced_mode = config_get_string(Config(), "AdvOut", "RecType");
  95. if (strcmp(advanced_mode, "FFmpeg") == 0) {
  96. bool is_local = config_get_bool(Config(), "AdvOut", "FFOutputToFile");
  97. if (!is_local)
  98. return true;
  99. }
  100. }
  101. return false;
  102. }
  103. bool OBSBasic::OutputPathValid()
  104. {
  105. if (IsFFmpegOutputToURL())
  106. return true;
  107. const char *path = GetCurrentOutputPath();
  108. return path && *path && QDir(path).exists();
  109. }