Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

H264inclient #398

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/AllocateConference.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ struct AllocateConference
{
utils::Optional<uint32_t> lastN;
bool useGlobalPort = true;
bool useH264 = false;
Copy link
Member

@RicardoMDomingues RicardoMDomingues Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do it a little more generic? So if we want to support new video codec ion future (like vp9, vp10). We will flood this with booleans.

I believe we should have a field more generic, like:
videoCodec = "default | vp8 | h264" // default is the one that is on smb config

If it's given an unsupported value, http request should fail with 400.

This way we could add support to new codecs without API changes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I will fix that

};

} // namespace api
1 change: 1 addition & 0 deletions api/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ AllocateConference parseAllocateConference(const nlohmann::json& data)
}
}
setIfExistsOrDefault(allocateConference.useGlobalPort, data, "global-port", true);
setIfExistsOrDefault(allocateConference.useH264, data, "enable-h264", false);

return allocateConference;
}
Expand Down
6 changes: 4 additions & 2 deletions bridge/Mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ Mixer::Mixer(std::string id,
const std::vector<uint32_t>& audioSsrcs,
const std::vector<api::SimulcastGroup>& videoSsrcs,
const std::vector<api::SsrcPair>& videoPinSsrcs,
bool useGlobalPort)
bool useGlobalPort,
bool useH264)
: _config(config),
_id(std::move(id)),
_loggableId("Mixer", logInstanceId),
Expand All @@ -169,7 +170,8 @@ Mixer::Mixer(std::string id,
_engineMixer(std::move(engineMixer)),
_idGenerator(idGenerator),
_ssrcGenerator(ssrcGenerator),
_useGlobalPort(useGlobalPort)
_useGlobalPort(useGlobalPort),
_useH264(useH264)
{
}

Expand Down
6 changes: 5 additions & 1 deletion bridge/Mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ class Mixer
const std::vector<uint32_t>& audioSsrcs,
const std::vector<api::SimulcastGroup>& videoSsrcs,
const std::vector<api::SsrcPair>& videoPinSsrcs,
bool useGlobalPort);
bool useGlobalPort,
bool useH264);

virtual ~Mixer() = default;

Expand Down Expand Up @@ -298,6 +299,8 @@ class Mixer
const config::Config& getConfig() const { return _config; }
bridge::Stats::MixerBarbellStats gatherBarbellStats(const uint64_t engineIterationStartTimestamp);

bool isH264Enabled() const { return _useH264; }

private:
struct BundleTransport
{
Expand Down Expand Up @@ -332,6 +335,7 @@ class Mixer

std::unordered_map<std::string, BundleTransport> _bundleTransports;
bool _useGlobalPort;
bool _useH264;
transport::Endpoints _rtpPorts;
std::unordered_map<size_t, std::unordered_map<uint32_t, std::unique_ptr<PacketCache>>> _videoPacketCaches;
std::unordered_map<size_t, std::unordered_map<uint32_t, std::unique_ptr<PacketCache>>> _recordingRtpPacketCaches;
Expand Down
9 changes: 5 additions & 4 deletions bridge/MixerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ MixerManager::~MixerManager()
logger::debug("Deleted", "MixerManager");
}

Mixer* MixerManager::create(bool useGlobalPort)
Mixer* MixerManager::create(bool useGlobalPort, bool useH264)
{
return create(_config.defaultLastN, useGlobalPort);
return create(_config.defaultLastN, useGlobalPort, useH264);
}

Mixer* MixerManager::create(uint32_t lastN, bool useGlobalPort)
Mixer* MixerManager::create(uint32_t lastN, bool useGlobalPort, bool useH264)
{
lastN = std::min(lastN, maxLastN);
logger::info("Create mixer, last-n %u", "MixerManager", lastN);
Expand Down Expand Up @@ -190,7 +190,8 @@ Mixer* MixerManager::create(uint32_t lastN, bool useGlobalPort)
audioSsrcs,
videoSsrcs,
videoPinSsrcs,
useGlobalPort));
useGlobalPort,
useH264));
if (!mixerEmplaceResult.second)
{
logger::error("Failed to create mixer", "MixerManager");
Expand Down
4 changes: 2 additions & 2 deletions bridge/MixerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class MixerManager final : public MixerManagerAsync

~MixerManager();

bridge::Mixer* create(bool useGlobalPort);
bridge::Mixer* create(uint32_t lastN, bool useGlobalPort);
bridge::Mixer* create(bool useGlobalPort, bool useH264 = false);
bridge::Mixer* create(uint32_t lastN, bool useGlobalPort, bool useH264 = false);
void remove(const std::string& id);
std::vector<std::string> getMixerIds();
std::unique_lock<std::mutex> getMixer(const std::string& id, Mixer*& outMixer);
Expand Down
11 changes: 7 additions & 4 deletions bridge/endpointActions/AllocateConference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,23 @@ httpd::Response allocateConference(ActionContext* context, RequestLogger& reques
const auto allocateConference = api::Parser::parseAllocateConference(requestBodyJson);

auto mixer = allocateConference.lastN.isSet()
? context->mixerManager.create(allocateConference.lastN.get(), allocateConference.useGlobalPort)
: context->mixerManager.create(allocateConference.useGlobalPort);
? context->mixerManager.create(allocateConference.lastN.get(),
allocateConference.useGlobalPort,
allocateConference.useH264)
: context->mixerManager.create(allocateConference.useGlobalPort, allocateConference.useH264);

if (!mixer)
{
throw httpd::RequestErrorException(httpd::StatusCode::INTERNAL_SERVER_ERROR, "Conference creation has failed");
}

logger::info("Allocate conference %s, mixer %s, last-n %d, global-port %c",
logger::info("Allocate conference %s, mixer %s, last-n %d, global-port %c, h264 %c",
"ApiRequestHandler",
mixer->getId().c_str(),
mixer->getLoggableId().c_str(),
allocateConference.lastN.isSet() ? allocateConference.lastN.get() : -1,
allocateConference.useGlobalPort ? 't' : 'f');
allocateConference.useGlobalPort ? 't' : 'f',
allocateConference.useH264 ? 't' : 'f');

nlohmann::json responseJson;
responseJson["id"] = mixer->getId();
Expand Down
4 changes: 2 additions & 2 deletions bridge/endpointActions/ConferenceActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,13 @@ httpd::Response generateAllocateEndpointResponse(ActionContext* context,
responseVideo.transport.set(responseTransport);
}

if (context->config.codec.videoCodec.get() == "H264")
if (context->config.codec.videoCodec.get() == "H264" || mixer.isH264Enabled())
{
addH264VideoProperties(responseVideo,
context->config.codec.h264ProfileLevelId.get(),
context->config.codec.h264PacketizationMode.get());
}
else
else if (context->config.codec.videoCodec.get() == "VP8")
{
addVp8VideoProperties(responseVideo);
}
Expand Down
1 change: 1 addition & 0 deletions config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class Config : public ConfigReader

CFG_GROUP()
CFG_PROP(std::string, videoCodec, "VP8");
// webRTC profiles: 42001f, 42e01f, 4d001f, 64001f, f4001f
CFG_PROP(std::string, h264ProfileLevelId, "42001f");
CFG_PROP(uint32_t, h264PacketizationMode, 1);

Expand Down
1 change: 1 addition & 0 deletions examples/simpleclient/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<tr>
<td id="joincell"><button id="join">Join</button></td>
<td><button id="hangup">Hangup</button></td>
<td><input type="checkbox" id="h264" name="H.264"></td>
</tr>
<tr>
<td>My endpoint id: <label id="endpointId"></label></td>
Expand Down
13 changes: 6 additions & 7 deletions examples/simpleclient/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const endpointIdLabel: HTMLLabelElement = <HTMLLabelElement>document.getElementB
const dominantSpeakerLabel: HTMLLabelElement = <HTMLLabelElement>document.getElementById('dominantSpeaker');
const audioElementsDiv: HTMLDivElement = <HTMLDivElement>document.getElementById('audioElements');
const videoElementsDiv: HTMLDivElement = <HTMLDivElement>document.getElementById('videoElements');
const h264Element: HTMLInputElement = <HTMLInputElement>document.getElementById('h264');
let peerConnection: RTCPeerConnection|undefined = undefined
let localMediaStream: MediaStream|undefined = undefined;
let localDataChannel: RTCDataChannel|undefined = undefined;
Expand Down Expand Up @@ -54,16 +55,14 @@ async function onPollMessage(resultJson: any)
if (resultJson.type === 'offer')
{
const remoteDescription = new RTCSessionDescription({type : 'offer', sdp : resultJson.payload});
console.log("Got offer " + JSON.stringify(remoteDescription));
await peerConnection.setRemoteDescription(remoteDescription);

let localDescription = await peerConnection.createAnswer();

// Add simulcast layers to the video stream with SDP munging
const mediaTracks = localMediaStream.getVideoTracks();
mediaTracks.forEach(
mediaTrack => { localDescription = addSimulcastSdpLocalDescription(localDescription, mediaTrack.id, 3); });
localDescription = addSimulcastSdpLocalDescription(localDescription, 3);

console.log('set local SDP ' + localDescription.sdp);
await peerConnection.setLocalDescription(localDescription);
}
}
Expand All @@ -79,11 +78,11 @@ async function onIceGatheringStateChange(event: Event)
console.log('ICE candidate gathering complete');
if (peerConnection.localDescription)
{
console.log('Sending answer ' + JSON.stringify(peerConnection.localDescription));

const url = serverUrl + 'endpoints/' + endpointId + '/actions';
const body = {type : 'answer', payload : peerConnection.localDescription.sdp};

console.log('Send answer SDP ' + body.payload);

const requestInit:
RequestInit = {method : 'POST', mode : 'cors', cache : 'no-store', body : JSON.stringify(body)};
const request = new Request(url, requestInit);
Expand Down Expand Up @@ -319,7 +318,7 @@ async function joinClicked()
localDataChannel.onmessage = onDataChannelMessage;

const url = serverUrl + 'endpoints/';
const body = {};
const body = {'enable-h264' : h264Element.checked};

const requestInit: RequestInit = {method : 'POST', mode : 'cors', cache : 'no-store', body : JSON.stringify(body)};
const request = new Request(url, requestInit);
Expand Down
Loading
Loading