Skip to content

Commit

Permalink
[GStreamer][WebCodecs] Harness dumping for easier debugging
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=262177

Reviewed by Xabier Rodriguez-Calvar.

Dump the harness graph to disk when the first encoded or decoded payload has been notified. This can
be useful for debugging purposes. Also driving-by in the Harness, add space characters at link
boundaries to prevent ambiguous links, especially for pads or element names starting with 'o'.

* Source/WebCore/platform/audio/gstreamer/AudioDecoderGStreamer.cpp:
(WebCore::GStreamerInternalAudioDecoder::GStreamerInternalAudioDecoder):
* Source/WebCore/platform/audio/gstreamer/AudioEncoderGStreamer.cpp:
(WebCore::GStreamerInternalAudioEncoder::GStreamerInternalAudioEncoder):
* Source/WebCore/platform/graphics/gstreamer/VideoDecoderGStreamer.cpp:
(WebCore::GStreamerInternalVideoDecoder::GStreamerInternalVideoDecoder):
* Source/WebCore/platform/graphics/gstreamer/VideoEncoderGStreamer.cpp:
(WebCore::GStreamerInternalVideoEncoder::GStreamerInternalVideoEncoder):
* Source/WebCore/platform/gstreamer/GStreamerElementHarness.cpp:
(WebCore::MermaidBuilder::process):
(WebCore::MermaidBuilder::dumpElement):

Canonical link: https://commits.webkit.org/268583@main
  • Loading branch information
philn committed Sep 28, 2023
1 parent 4c9c583 commit f025f71
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ GStreamerInternalAudioDecoder::GStreamerInternalAudioDecoder(const String& codec
if (!gst_buffer_n_memory(outputBuffer.get()))
return;

static std::once_flag onceFlag;
std::call_once(onceFlag, [this] {
m_harness->dumpGraph("audio-decoder");
});

GST_TRACE_OBJECT(m_harness->element(), "Got frame with PTS: %" GST_TIME_FORMAT, GST_TIME_ARGS(GST_BUFFER_PTS(outputBuffer.get())));

const GstSegment* segment = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ GStreamerInternalAudioEncoder::GStreamerInternalAudioEncoder(const String& codec
return;
}

static std::once_flag onceFlag;
std::call_once(onceFlag, [this] {
m_harness->dumpGraph("audio-encoder");
});

bool isKeyFrame = !GST_BUFFER_FLAG_IS_SET(outputBuffer.get(), GST_BUFFER_FLAG_DELTA_UNIT);
GST_TRACE_OBJECT(m_harness->element(), "Notifying encoded%s frame", isKeyFrame ? " key" : "");
GstMappedBuffer mappedBuffer(outputBuffer.get(), GST_MAP_READ);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ GStreamerInternalVideoDecoder::GStreamerInternalVideoDecoder(const String& codec
if (m_isClosed)
return;

static std::once_flag onceFlag;
std::call_once(onceFlag, [this] {
m_harness->dumpGraph("video-decoder");
});

GST_TRACE_OBJECT(m_harness->element(), "Got frame with PTS: %" GST_TIME_FORMAT, GST_TIME_ARGS(GST_BUFFER_PTS(outputBuffer.get())));

if (m_presentationSize.isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ GStreamerInternalVideoEncoder::GStreamerInternalVideoEncoder(const String& codec
if (m_isClosed)
return;

static std::once_flag onceFlag;
std::call_once(onceFlag, [this] {
m_harness->dumpGraph("video-encoder");
});

bool isKeyFrame = !GST_BUFFER_FLAG_IS_SET(outputBuffer.get(), GST_BUFFER_FLAG_DELTA_UNIT);
GST_TRACE_OBJECT(m_harness->element(), "Notifying encoded%s frame", isKeyFrame ? " key" : "");
GstMappedBuffer encodedImage(outputBuffer.get(), GST_MAP_READ);
Expand Down
10 changes: 5 additions & 5 deletions Source/WebCore/platform/gstreamer/GStreamerElementHarness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ void MermaidBuilder::process(GStreamerElementHarness& harness, bool generateFoot
if (!downstreamHarness)
continue;
process(*downstreamHarness, false);
m_stringBuilder.append(padId, "--->"_s, generatePadId(*downstreamHarness, downstreamHarness->inputPad()), '\n');
m_stringBuilder.append(padId, " ---> "_s, generatePadId(*downstreamHarness, downstreamHarness->inputPad()), '\n');
}

if (!generateFooter)
Expand All @@ -497,12 +497,12 @@ void MermaidBuilder::process(GStreamerElementHarness& harness, bool generateFoot
for (auto& [padHarness, srcPad, sinkPad] : m_padLinks) {
m_stringBuilder.append(generatePadId(padHarness, srcPad.get()), ":::"_s, getPadClass(srcPad));
if (GST_IS_PROXY_PAD(srcPad.get()))
m_stringBuilder.append("--->"_s);
m_stringBuilder.append(" ---> "_s);
else if (auto srcCaps = adoptGRef(gst_pad_get_current_caps(srcPad.get()))) {
auto capsString = describeCaps(srcCaps.get());
m_stringBuilder.append("--\""_s, capsString, "\"-->"_s);
m_stringBuilder.append(" --\""_s, capsString, "\"--> "_s);
} else
m_stringBuilder.append("--->"_s);
m_stringBuilder.append(" ---> "_s);
m_stringBuilder.append(generatePadId(padHarness, sinkPad.get()), ":::"_s, getPadClass(sinkPad), '\n');
}

Expand Down Expand Up @@ -572,7 +572,7 @@ void MermaidBuilder::dumpElement(GStreamerElementHarness& harness, GstElement* e
// There is no clean way to maintain subgraph ordering, so draw invisible links between pads.
// Upstream bug report: https://github.com/mermaid-js/mermaid/issues/815
if (firstSinkPad && firstSrcPad) {
m_stringBuilder.append(generatePadId(harness, firstSinkPad.get()), "---"_s, generatePadId(harness, firstSrcPad.get()), '\n');
m_stringBuilder.append(generatePadId(harness, firstSinkPad.get()), " --- "_s, generatePadId(harness, firstSrcPad.get()), '\n');
m_stringBuilder.append("linkStyle "_s, m_invisibleLinesCounter, " stroke-width:0px\n"_s);
m_invisibleLinesCounter++;
}
Expand Down

0 comments on commit f025f71

Please sign in to comment.