Skip to content

Commit

Permalink
[GStreamer][WebRTC] Bridge PeerConnection logs to GStreamer logging s…
Browse files Browse the repository at this point in the history
…ystem

https://bugs.webkit.org/show_bug.cgi?id=275161

Reviewed by Xabier Rodriguez-Calvar.

By setting WEBKIT_DEBUG=WebRTC=debug the PeerConnection logs are now also sent to GStreamer's
logging system, easing a bit debugging.

* Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp:
(WebCore::PeerConnectionBackend::setRemoteDescriptionSucceeded):
* Source/WebCore/Modules/mediastream/gstreamer/GStreamerPeerConnectionBackend.cpp:
(WebCore::GStreamerPeerConnectionBackend::GStreamerPeerConnectionBackend):
(WebCore::GStreamerPeerConnectionBackend::~GStreamerPeerConnectionBackend):
(WebCore::GStreamerPeerConnectionBackend::didLogMessage):
* Source/WebCore/Modules/mediastream/gstreamer/GStreamerPeerConnectionBackend.h:

Canonical link: https://commits.webkit.org/279871@main
  • Loading branch information
philn authored and mnutt committed Jun 30, 2024
1 parent e07ec7c commit b4ed929
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
28 changes: 22 additions & 6 deletions Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,17 @@ void PeerConnectionBackend::setRemoteDescriptionSucceeded(std::optional<Descript

if (descriptionStates) {
m_peerConnection.updateDescriptions(WTFMove(*descriptionStates));
if (m_peerConnection.isClosed())
if (m_peerConnection.isClosed()) {
DEBUG_LOG(LOGIDENTIFIER, "PeerConnection closed after descriptions update");
return;
}
}

m_peerConnection.processIceTransportChanges();
if (m_peerConnection.isClosed())
if (m_peerConnection.isClosed()) {
DEBUG_LOG(LOGIDENTIFIER, "PeerConnection closed after ICE transport changes");
return;
}

if (transceiverStates) {
// Compute track related events.
Expand All @@ -376,31 +380,43 @@ void PeerConnectionBackend::setRemoteDescriptionSucceeded(std::optional<Descript
processRemoteTracks(*transceiver, WTFMove(transceiverState), addList, removeList, trackEventList, muteTrackList);
}

DEBUG_LOG(LOGIDENTIFIER, "Processing ", muteTrackList.size(), " muted tracks");
for (auto& track : muteTrackList) {
track->setShouldFireMuteEventImmediately(true);
track->source().setMuted(true);
track->setShouldFireMuteEventImmediately(false);
if (m_peerConnection.isClosed())
if (m_peerConnection.isClosed()) {
DEBUG_LOG(LOGIDENTIFIER, "PeerConnection closed while processing muted tracks");
return;
}
}

DEBUG_LOG(LOGIDENTIFIER, "Removing ", removeList.size(), " tracks");
for (auto& pair : removeList) {
pair.stream->privateStream().removeTrack(pair.track->privateTrack());
if (m_peerConnection.isClosed())
if (m_peerConnection.isClosed()) {
DEBUG_LOG(LOGIDENTIFIER, "PeerConnection closed while removing tracks");
return;
}
}

DEBUG_LOG(LOGIDENTIFIER, "Adding ", addList.size(), " tracks");
for (auto& pair : addList) {
pair.stream->addTrackFromPlatform(pair.track.copyRef());
if (m_peerConnection.isClosed())
if (m_peerConnection.isClosed()) {
DEBUG_LOG(LOGIDENTIFIER, "PeerConnection closed while adding tracks");
return;
}
}

DEBUG_LOG(LOGIDENTIFIER, "Dispatching ", trackEventList.size(), " track events");
for (auto& event : trackEventList) {
RefPtr track = event->track();
m_peerConnection.dispatchEvent(event);
if (m_peerConnection.isClosed())
if (m_peerConnection.isClosed()) {
DEBUG_LOG(LOGIDENTIFIER, "PeerConnection closed while dispatching track events");
return;
}

track->source().setMuted(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,26 @@ GStreamerPeerConnectionBackend::GStreamerPeerConnectionBackend(RTCPeerConnection
, m_endpoint(GStreamerMediaEndpoint::create(*this))
{
disableICECandidateFiltering();
logger().addObserver(*this);
}

GStreamerPeerConnectionBackend::~GStreamerPeerConnectionBackend() = default;
GStreamerPeerConnectionBackend::~GStreamerPeerConnectionBackend()
{
logger().removeObserver(*this);
}

void GStreamerPeerConnectionBackend::didLogMessage(const WTFLogChannel&, WTFLogLevel, Vector<JSONLogValue>&& values)
{
#ifndef GST_DISABLE_GST_DEBUG
StringBuilder builder;
for (auto& [_, value] : values)
builder.append(value);

GST_DEBUG_OBJECT(m_endpoint->pipeline(), "%s", builder.toString().utf8().data());
#else
UNUSED_PARAM(values);
#endif
}

void GStreamerPeerConnectionBackend::suspend()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ struct GStreamerIceCandidate {
String candidate;
};

class GStreamerPeerConnectionBackend final : public PeerConnectionBackend {
class GStreamerPeerConnectionBackend final : public PeerConnectionBackend, public Logger::Observer {
WTF_MAKE_FAST_ALLOCATED;
public:
explicit GStreamerPeerConnectionBackend(RTCPeerConnection&);
~GStreamerPeerConnectionBackend();

void didLogMessage(const WTFLogChannel&, WTFLogLevel, Vector<JSONLogValue>&&) final;

private:
void close() final;
void doCreateOffer(RTCOfferOptions&&) final;
Expand Down

0 comments on commit b4ed929

Please sign in to comment.