Skip to content

Commit

Permalink
custom video encoder config and joinfaied
Browse files Browse the repository at this point in the history
  • Loading branch information
sbd021 committed Mar 29, 2021
1 parent 4107d87 commit e9d80c2
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/Agora/agorartcengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ bool AgoraRtcEngine::setVideoProfileEx(int nWidth, int nHeight, int nFrameRate,
int nBitRate)
{
AParameter apm(m_rtcEngine);
//apm->setParameters("{\"che.video.freestyle_customer\": true}");
apm->setParameters("{\"che.video.freestyle_customer\": true}");
VideoEncoderConfiguration config;
config.dimensions.width = nWidth;
config.dimensions.height = nHeight;
Expand Down
56 changes: 42 additions & 14 deletions src/forms/AgoraSettings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<item>
<widget class="QStackedWidget" name="settingsPages">
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="agoraPage">
<layout class="QVBoxLayout" name="verticalLayout_16">
Expand Down Expand Up @@ -108,8 +108,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>698</width>
<height>403</height>
<width>534</width>
<height>314</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_23">
Expand Down Expand Up @@ -1004,8 +1004,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>698</width>
<height>423</height>
<width>650</width>
<height>219</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_50">
Expand Down Expand Up @@ -1244,7 +1244,7 @@
<property name="labelAlignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<item row="0" column="0">
<item row="3" column="0">
<widget class="QLabel" name="label_8">
<property name="minimumSize">
<size>
Expand All @@ -1263,7 +1263,7 @@
</property>
</widget>
</item>
<item row="0" column="1">
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_29">
<property name="spacing">
<number>6</number>
Expand Down Expand Up @@ -1299,28 +1299,28 @@
</item>
</layout>
</item>
<item row="1" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Agora.Settings.Video.FPS</string>
</property>
</widget>
</item>
<item row="2" column="0">
<item row="5" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Agora.Settings.Video.Birate</string>
</property>
</widget>
</item>
<item row="3" column="0">
<item row="6" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Agora.Settings.Video.Devices</string>
</property>
</widget>
</item>
<item row="5" column="1">
<item row="8" column="1">
<widget class="QLabel" name="videoMsg">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
Expand All @@ -1339,7 +1339,7 @@
</property>
</widget>
</item>
<item row="1" column="1">
<item row="4" column="1">
<widget class="QComboBox" name="cmbAgoraFPS">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
Expand Down Expand Up @@ -1387,7 +1387,7 @@
</item>
</widget>
</item>
<item row="2" column="1">
<item row="5" column="1">
<widget class="QComboBox" name="cmbAgoraBitrate">
<item>
<property name="text">
Expand All @@ -1406,9 +1406,37 @@
</item>
</widget>
</item>
<item row="3" column="1">
<item row="6" column="1">
<widget class="QComboBox" name="cmbAgoraVideoDevice"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelVideoEncoder">
<property name="text">
<string>Agora.Settings.Video.Encoder</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="cmbVideoEncoder">
<item>
<property name="text">
<string>Agora.Settings.Video.Agora.Bitrate</string>
</property>
</item>
<item>
<property name="text">
<string>Agora.Settings.Video.OBS.Bitrate</string>
</property>
</item>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="labelFPSResolution">
<property name="text">
<string>Agora.Settings.Video.FPS.Resolution</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="rtmpPage">
Expand Down
126 changes: 119 additions & 7 deletions src/forms/window-agora-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "../agora-ui-main.h"
#include "obs-module.h"
#include "window-agora-settings.hpp"
#include <util/platform.h>
#include <util/dstr.h>
using namespace std;

bool DisplayResizeEvent::eventFilter(QObject *obj, QEvent *event)
Expand Down Expand Up @@ -119,7 +121,75 @@ AgoraBasic::AgoraBasic(QMainWindow *parent)
connect(&aCloseEventHandler, &ACloseEvent::AgoraClose, closeEvent_slot);
mainWindow->installEventFilter(&aCloseEventHandler);

//stopSignal = CreateEvent(nullptr, true, false, nullptr);
InitGlobalConfig();
InitBasicConfig();
}

void AgoraBasic::InitGlobalConfig()
{
char path[512];

int len = os_get_config_path(path, sizeof(path), "obs-studio/global.ini");
if (len <= 0)
return;
int errorcode = globalConfig.Open(path, CONFIG_OPEN_ALWAYS);
if (errorcode != CONFIG_SUCCESS) {
blog(LOG_ERROR, "Agora Plugin Failed to open global.ini: %d", errorcode);
return ;
}
}

int AgoraBasic::GetProfilePath(char *path, size_t size, const char *file)
{
char profiles_path[512];
const char *profile =
config_get_string(globalConfig, "Basic", "ProfileDir");
int ret;

if (!profile)
return -1;
if (!path)
return -1;
if (!file)
file = "";

ret = os_get_config_path(profiles_path, 512, "obs-studio/basic/profiles");
if (ret <= 0)
return ret;

if (!*file)
return snprintf(path, size, "%s/%s", profiles_path, profile);

return snprintf(path, size, "%s/%s/%s", profiles_path, profile, file);
}


void AgoraBasic::InitBasicConfig()
{
char configPath[512];

int ret = GetProfilePath(configPath, sizeof(configPath), "");
if (ret <= 0) {
blog(LOG_INFO, "Failed to get profile path");
return ;
}

ret = GetProfilePath(configPath, sizeof(configPath), "basic.ini");
if (ret <= 0) {
blog(LOG_INFO, "Failed to get basic.ini path");
return ;
}

int code = basicConfig.Open(configPath, CONFIG_OPEN_ALWAYS);
if (code != CONFIG_SUCCESS) {
blog(LOG_INFO, "Failed to open basic.ini: %d", code);
return;
}

if (config_get_string(basicConfig, "General", "Name") == nullptr) {
const char *curName = config_get_string(globalConfig,
"Basic", "Profile");
}
}

AgoraBasic::~AgoraBasic()
Expand All @@ -135,6 +205,23 @@ AgoraBasic::~AgoraBasic()

AgoraRtcEngine::GetInstance()->ReleaseInstance();
}

int AgoraBasic::GetOBSBitrate()
{
const char *mode = config_get_string(basicConfig, "Output", "Mode");
bool advOut = astrcmpi(mode, "Advanced") == 0;

int bitrate = 2500;
if (advOut) {
bitrate = config_get_int(basicConfig, "AdvOut", "VBitrate");
}
else {
bitrate = config_get_int(basicConfig, "SimpleOutput", "VBitrate");
}

return bitrate == 0 ? 2500 : bitrate;
}

void AgoraBasic::on_agoraSteramButton_clicked()
{
QString str = ui->agoraSteramButton->text();
Expand Down Expand Up @@ -186,11 +273,32 @@ void AgoraBasic::on_agoraSteramButton_clicked()

StartAgoraOutput();

AgoraRtcEngine::GetInstance()->setVideoProfileEx(
m_agoraToolSettings.agora_width,
m_agoraToolSettings.agora_height,
m_agoraToolSettings.agora_fps,
m_agoraToolSettings.agora_bitrate);
int output_width = ovi.output_width;
int output_height = ovi.output_height;

if (output_width*output_height > 1920 * 1080) {
float rate = sqrtf((float)(output_width*output_height) / (1920 * 1080.0f));
float width = (float)output_width / rate;
float height = (float)output_height / rate;
output_width = width;
output_height = height;
}

if (m_agoraToolSettings.videoEncoder == 0) {//Agora ÂëÂÊ
AgoraRtcEngine::GetInstance()->setVideoProfileEx(
output_width,
output_height,
(float)ovi.fps_num/(float)ovi.fps_den,
m_agoraToolSettings.agora_bitrate);
}
else {//obs ÂëÂÊ
m_agoraToolSettings.obs_bitrate = GetOBSBitrate();
AgoraRtcEngine::GetInstance()->setVideoProfileEx(
output_width,
output_height,
(float)ovi.fps_num / (float)ovi.fps_den,
m_agoraToolSettings.obs_bitrate);
}

AgoraRtcEngine::GetInstance()->joinChannel(m_agoraToolSettings.token.c_str()
, m_agoraToolSettings.channelName.c_str(), m_agoraToolSettings.uid,
Expand All @@ -209,7 +317,10 @@ void AgoraBasic::on_agoraSteramButton_clicked()

if (!m_agoraToolSettings.agora_url.empty())
AgoraRtcEngine::GetInstance()->RemovePublishStreamUrl(m_agoraToolSettings.agora_url.c_str());
ui->agoraSteramButton->setText(stopping_text);
if (starting_text.compare(str) == 0)
ui->agoraSteramButton->setText(start_text);
else
ui->agoraSteramButton->setText(stopping_text);
ClearRemoteVideos();
m_lstRemoteVideoUids.clear();
m_lstUids.clear();
Expand All @@ -220,6 +331,7 @@ void AgoraBasic::showEvent(QShowEvent *event)
{
if (!current_source)
current_source = obs_frontend_get_current_scene();

QMainWindow::showEvent(event);
}

Expand Down
16 changes: 11 additions & 5 deletions src/forms/window-agora-main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <memory>
#include "ui_AgoraBasic.h"
#include "../Agora/agorartcengine.hpp"
#include <util/config-file.h>
#include <util/util.hpp>
#include <QTimer>
#include "obs.hpp"

Expand Down Expand Up @@ -36,7 +36,7 @@ typedef struct tagAgoraToolSettings {
bool muteAllRemoteAudioVideo = false;
std::string agora_url = "";
int agora_fps = 15;
int agora_bitrate = 1000;
int agora_bitrate = 0;
int agora_width = 1280;
int agora_height = 720;
std::string rtmp_url = "";
Expand All @@ -48,6 +48,9 @@ typedef struct tagAgoraToolSettings {
int audioChannel = 2;
int scenario = 0;
bool bHighQuality = false;
int obs_bitrate = 2500;

int videoEncoder = 0;//ĬÈÏAgora²ÎÊý
} AgoraToolSettings, *PAgoraToolSettings;

class DisplayResizeEvent : public QObject
Expand Down Expand Up @@ -132,10 +135,13 @@ class AgoraBasic : public QMainWindow {
bool joinFailed = false;
bool started = false;

ConfigFile globalConfig;
ConfigFile basicConfig;
void InitGlobalConfig();
void InitBasicConfig();
int GetOBSBitrate();
int GetProfilePath(char *path, size_t size, const char *file);
//HANDLE stopSignal = NULL;



virtual void showEvent(QShowEvent *event)override;
virtual void hideEvent(QHideEvent *event)override;
virtual void closeEvent(QCloseEvent *event)override;
Expand Down
Loading

0 comments on commit e9d80c2

Please sign in to comment.