Skip to content

Commit

Permalink
Request types: get/set/save streaming settings (PR #100)
Browse files Browse the repository at this point in the history
* Adding support for changing streaming server settings

* Updates after initial code review for customized rtmp settings

* Updating PROTOCOL.MD documentment for streaming service settings

* Changes based on code review
  • Loading branch information
yinzara authored and Palakis committed Jul 6, 2017
1 parent acffacd commit e3ad148
Show file tree
Hide file tree
Showing 5 changed files with 311 additions and 7 deletions.
73 changes: 71 additions & 2 deletions PROTOCOL.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ The protocol in general is based on the OBS Remote protocol created by Bill Hami
- ["ListSceneCollections"](#listscenecollections)
- ["SetCurrentSceneCollection"](#setcurrentscenecollection)
- ["GetCurrentSceneCollection"](#getcurrentscenecollection)
- **Streaming Server Settings**
- ["GetStreamSettings"](#getstreamsettings)
- ["SetStreamSettings"](#setstreamsettings)
- ["SaveStreamSettings"](#savestreamsettings)
- **Profiles**
- ["ListProfiles"](#listprofiles)
- ["SetCurrentProfile"](#setcurrentprofile)
Expand Down Expand Up @@ -489,15 +493,33 @@ __Response__ : always OK. No additional fields.
#### "StartStopRecording"
Toggles recording on or off.

__Request fields__ : none
__Request fields__ :
- **"stream"** (object; optional) : See 'stream' parameter in 'StartStreaming'. Ignored if stream is already started.

__Response__ : always OK. No additional fields.

---

#### "StartStreaming"
Start streaming.

__Request fields__ : none
__Request fields__ :
- **"stream"** (object; optional) : If specified allows for special configuration of the stream

The 'stream' object has the following fields:
- **"settings"** (object; optional) : The settings for the stream
- **"type"** (string; optional) : If specified ensures the type of the stream matches the given type (usually 'rtmp\_custom' or 'rtmp\_common'). If the currently configured stream type does not match the given stream type, all settings must be specified in the 'settings' object or an error will occur starting the stream.
- **"metadata"** (object; optional) : Adds the given object parameters as encoded query string parameters to the 'key' of the RTMP stream. Used to pass data to the RTMP service about the stream.

The 'settings' object has the following fields:
- **"server"** (string; optional) : The publish URL
- **"key"** (string; optional) : The publish key of the stream
- **"use-auth"** (bool; optional) : should authentication be used when connecting to the streaming server
- **"username"** (string; optional) : if authentication is enabled, the username for access to the streaming server. Ignored if 'use-auth' is not specified as 'true'.
- **"password"** (string; optional) : if authentication is enabled, the password for access to the streaming server. Ignored if 'use-auth' is not specified as 'true'.

The 'metadata' object supports passing any string, numeric or boolean field.

__Response__ : Error if streaming is already active, OK otherwise. No additional fields.

---
Expand Down Expand Up @@ -746,6 +768,53 @@ __Response__ : OK with these additional fields :

---

#### "GetStreamSettings"
Gets the current streaming server settings

__Request fields__ : none

__Response__ : OK with these additional fields :
- **"type"** (string) : The type of streaming service configuration usually 'rtmp\_custom' or 'rtmp\_common'
- **"settings"** (object) : The actual settings of the stream (i.e. server, key, use-auth, username, password)

The 'settings' object has the following fields however they may vary by 'type':
- **"server"** (string) : The publish URL
- **"key"** (string) : The publish key of the stream
- **"use-auth"** (bool) : should authentication be used when connecting to the streaming server
- **"username"** (string) : if authentication is enabled, the username for access to the streaming server
- **"password"** (string) : if authentication is enabled, the password for access to the streaming server

--

#### "SetStreamSettings"
Sets one or more attributes of the current streaming server settings. Any options not passed will remain unchanged. Returns the updated settings in response.
If 'type' is different than the current streaming service type, all settings are required.
Returns the full settings of the stream (i.e. the same as GetStreamSettings)

__Request fields__ :
- **"type"** (string) : The type of streaming service configuration usually 'rtmp\_custom' or 'rtmp\_common'
- **"settings"** (object) : The actual settings of the stream (i.e. server, key, use-auth, username, password)
- **"save"** (bool) : If specified as true, saves the settings to disk

The 'settings' object has the following fields however they may vary by 'type':
- **"server"** (string; optional) : The publish URL
- **"key"** (string; optional) : The publish key of the stream
- **"use-auth"** (bool; optional) : should authentication be used when connecting to the streaming server
- **"username"** (string; optional) : if authentication is enabled, the username for access to the streaming server
- **"password"** (string; optional) : if authentication is enabled, the password for access to the streaming server

__Response__ : OK with the same fields as the request (except 'save')

---

#### "SaveStreamSettings"
Saves the current streaming server settings to disk

__Request fields__ : none

__Response__ : OK


#### "SetCurrentProfile"
Change the current profile.

Expand Down
57 changes: 56 additions & 1 deletion Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#include <obs.hpp>
#include <QMainWindow>
#include <QDir>
#include <QUrl>
#include "Utils.h"
#include "obs-websocket.h"

Expand Down Expand Up @@ -464,4 +465,58 @@ bool Utils::SetRecordingFolder(const char* path)

config_save(profile);
return true;
}
}

QString* Utils::ParseDataToQueryString(obs_data_t * data)
{
QString* query = nullptr;
if (data)
{
obs_data_item_t* item = obs_data_first(data);
if (item)
{
query = new QString();
bool isFirst = true;
do
{
if (!obs_data_item_has_user_value(item))
continue;

if (!isFirst)
query->append('&');
else
isFirst = false;

const char* attrName = obs_data_item_get_name(item);
query->append(attrName).append("=");
switch (obs_data_item_gettype(item))
{
case OBS_DATA_BOOLEAN:
query->append(obs_data_item_get_bool(item)?"true":"false");
break;
case OBS_DATA_NUMBER:
switch (obs_data_item_numtype(item))
{
case OBS_DATA_NUM_DOUBLE:
query->append(QString::number(obs_data_item_get_double(item)));
break;
case OBS_DATA_NUM_INT:
query->append(QString::number(obs_data_item_get_int(item)));
break;
case OBS_DATA_NUM_INVALID:
break;
}
break;
case OBS_DATA_STRING:
query->append(QUrl::toPercentEncoding(QString(obs_data_item_get_string(item))));
break;
default:
//other types are not supported
break;
}
} while ( obs_data_item_next( &item ) );
}
}

return query;
}
2 changes: 2 additions & 0 deletions Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class Utils
static QString FormatIPAddress(QHostAddress &addr);
static const char* GetRecordingFolder();
static bool SetRecordingFolder(const char* path);

static QString* ParseDataToQueryString(obs_data_t * data);
};

#endif // UTILS_H
Loading

0 comments on commit e3ad148

Please sign in to comment.