mirror of
https://github.com/obsproject/obs-studio.git
synced 2026-03-04 14:46:09 -05:00
Add preliminary streaming code for testing
- Add some temporary streaming code using FFmpeg. FFmpeg itself is not very ideal for streaming; lack of direct control of the sockets and no framedrop handling means that FFmpeg is definitely not something you want to use without wrapper code. I'd prefer writing my own network framework in this particular case just because you give away so much control of the network interface. Wasted an entire day trying to go through FFmpeg issues. There's just no way FFmpeg should be used for real streaming (at least without being patched or submitting some sort of patch, but I'm sort of feeling "meh" on that idea) I had to end up writing multiple threads just to handle both connecting and writing, because av_interleaved_write_frame blocks every call, stalling the main encoder thread, and thus also stalling draw signals. - Add some temporary user interface for streaming settings. This is just temporary for the time being. It's in the outputs section of the basic-mode settings - Make it so that dynamic arrays do not free all their data when the size just happens to be reduced to 0. This prevents constant reallocation when an array keeps going from 1 item to 0 items. Also, it was bad to become dependent upon that functionality. You must now always explicitly call "free" on it to ensure the data is free, and that's how it should be. Implicit functionality can lead to confusion and maintainability issues.
This commit is contained in:
@@ -42,6 +42,7 @@ OBSBasic::OBSBasic(QWidget *parent)
|
||||
: OBSMainWindow (parent),
|
||||
outputTest (NULL),
|
||||
sceneChanging (false),
|
||||
resizeTimer (0),
|
||||
ui (new Ui::OBSBasic)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
@@ -66,6 +67,12 @@ bool OBSBasic::InitBasicConfigDefaults()
|
||||
uint32_t cx = monitors[0].cx;
|
||||
uint32_t cy = monitors[0].cy;
|
||||
|
||||
/* TODO: temporary */
|
||||
config_set_default_string(basicConfig, "OutputTemp", "URL", "");
|
||||
config_set_default_string(basicConfig, "OutputTemp", "Key", "");
|
||||
config_set_default_uint (basicConfig, "OutputTemp", "VBitrate", 2500);
|
||||
config_set_default_uint (basicConfig, "OutputTemp", "ABitrate", 128);
|
||||
|
||||
config_set_default_uint (basicConfig, "Video", "BaseCX", cx);
|
||||
config_set_default_uint (basicConfig, "Video", "BaseCY", cy);
|
||||
|
||||
@@ -732,33 +739,62 @@ void OBSBasic::on_actionSourceDown_triggered()
|
||||
{
|
||||
}
|
||||
|
||||
void OBSBasic::on_recordButton_clicked()
|
||||
void OBSBasic::OutputConnect(bool success)
|
||||
{
|
||||
if (!success) {
|
||||
obs_output_destroy(outputTest);
|
||||
outputTest = NULL;
|
||||
} else {
|
||||
ui->streamButton->setText("Stop Streaming");
|
||||
}
|
||||
|
||||
ui->streamButton->setEnabled(true);
|
||||
}
|
||||
|
||||
static void OBSOutputConnect(void *data, calldata_t params)
|
||||
{
|
||||
bool success = calldata_bool(params, "success");
|
||||
|
||||
QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
|
||||
"OutputConnect", Q_ARG(bool, success));
|
||||
}
|
||||
|
||||
/* TODO: lots of temporary code */
|
||||
void OBSBasic::on_streamButton_clicked()
|
||||
{
|
||||
if (outputTest) {
|
||||
obs_output_destroy(outputTest);
|
||||
outputTest = NULL;
|
||||
ui->recordButton->setText("Start Recording");
|
||||
ui->streamButton->setText("Start Streaming");
|
||||
} else {
|
||||
QString path = QFileDialog::getSaveFileName(this,
|
||||
"Please enter a file name", QString(),
|
||||
"MP4 Files (*.mp4)");
|
||||
const char *url = config_get_string(basicConfig, "OutputTemp",
|
||||
"URL");
|
||||
const char *key = config_get_string(basicConfig, "OutputTemp",
|
||||
"Key");
|
||||
int vBitrate = config_get_uint(basicConfig, "OutputTemp",
|
||||
"VBitrate");
|
||||
int aBitrate = config_get_uint(basicConfig, "OutputTemp",
|
||||
"ABitrate");
|
||||
|
||||
if (path.isNull() || path.isEmpty())
|
||||
return;
|
||||
string fullURL = url;
|
||||
fullURL = fullURL + "/" + key;
|
||||
|
||||
obs_data_t data = obs_data_create();
|
||||
obs_data_setstring(data, "filename", QT_TO_UTF8(path));
|
||||
obs_data_setstring(data, "filename", fullURL.c_str());
|
||||
obs_data_setint(data, "audio_bitrate", aBitrate);
|
||||
obs_data_setint(data, "video_bitrate", vBitrate);
|
||||
|
||||
outputTest = obs_output_create("ffmpeg_output", "test", data);
|
||||
obs_data_release(data);
|
||||
|
||||
if (!obs_output_start(outputTest)) {
|
||||
obs_output_destroy(outputTest);
|
||||
outputTest = NULL;
|
||||
if (!outputTest)
|
||||
return;
|
||||
}
|
||||
|
||||
ui->recordButton->setText("Stop Recording");
|
||||
signal_handler_connect(obs_output_signalhandler(outputTest),
|
||||
"connect", OBSOutputConnect, this);
|
||||
|
||||
obs_output_start(outputTest);
|
||||
ui->streamButton->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user