Skip to content

Commit

Permalink
obs-webrtc: Enable PacingHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean-Der committed Jul 16, 2024
1 parent ec5297b commit 7d25814
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 11 additions & 0 deletions plugins/obs-webrtc/whip-output.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "whip-output.h"
#include "whip-utils.h"

#include <rtc/rtc.hpp>

/*
* Sets the maximum size for a video fragment. Effective range is
* 576-1470, with a lower value equating to more packets created,
Expand Down Expand Up @@ -159,6 +161,9 @@ void WHIPOutput::ConfigureVideoTrack(std::string media_stream_id,
if (!encoder)
return;

OBSDataAutoRelease settings = obs_encoder_get_settings(encoder);
auto video_bitrate = (int)obs_data_get_int(settings, "bitrate");

const char *codec = obs_encoder_get_codec(encoder);
if (strcmp("h264", codec) == 0) {
video_description.addH264Codec(video_payload_type);
Expand Down Expand Up @@ -187,6 +192,12 @@ void WHIPOutput::ConfigureVideoTrack(std::string media_stream_id,
packetizer->addToChain(std::make_shared<rtc::RtcpNackResponder>(
video_nack_buffer_size));

if (video_bitrate != 0) {
packetizer->addToChain(std::make_shared<rtc::PacingHandler>(
static_cast<double>(video_bitrate * 10000),
std::chrono::milliseconds(5)));
}

video_track = peer_connection->addTrack(video_description);
video_track->setMediaHandler(packetizer);
}
Expand Down
3 changes: 1 addition & 2 deletions plugins/obs-webrtc/whip-output.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <obs-module.h>
#include <obs.hpp>
#include <util/curl/curl-helper.h>
#include <util/platform.h>
#include <util/base.h>
Expand All @@ -11,8 +12,6 @@
#include <mutex>
#include <thread>

#include <rtc/rtc.hpp>

class WHIPOutput {
public:
WHIPOutput(obs_data_t *settings, obs_output_t *output);
Expand Down

0 comments on commit 7d25814

Please sign in to comment.