Skip to content

Commit 2fe6d40

Browse files
committed
Merge branch 'abhi/testh264pipeline' of github.com:huskyroboticsteam/Resurgence into abhi/testh264pipeline
2 parents 12b8b41 + 27d4228 commit 2fe6d40

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/video/H265NVENCEncoder.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ std::string buildPipelineSuffix(const std::string& sinkName) {
4848
struct EncoderCandidate {
4949
std::string label;
5050
std::string pipeline;
51+
bool hardware = false;
5152
};
5253

5354
std::vector<EncoderCandidate> buildPipelineCandidates(int width, int height, int fps,
@@ -56,9 +57,9 @@ std::vector<EncoderCandidate> buildPipelineCandidates(int width, int height, int
5657
const std::string prefix = buildPipelinePrefix(width, height, fps, srcName);
5758
const std::string suffix = buildPipelineSuffix(sinkName);
5859
return {
59-
{"x264enc", prefix + "x264enc tune=zerolatency speed-preset=ultrafast ! " + suffix},
60-
{"nvh264enc", prefix + "nvh264enc ! " + suffix},
61-
{"openh264enc", prefix + "openh264enc ! " + suffix},
60+
{"x264enc", prefix + "x264enc tune=zerolatency speed-preset=ultrafast ! " + suffix, false},
61+
{"nvh264enc", prefix + "nvh264enc ! " + suffix, true},
62+
{"openh264enc", prefix + "openh264enc ! " + suffix, false},
6263
};
6364
}
6465

@@ -111,11 +112,15 @@ void H265NVENCEncoder::initializePipeline(int width, int height) {
111112

112113
std::string errors;
113114
for (const auto& candidate : candidates) {
115+
const char* mode = candidate.hardware ? "hardware" : "software";
116+
LOG_F(INFO, "Trying %s camera encoder candidate: %s", mode, candidate.label.c_str());
117+
114118
GError* parseError = nullptr;
115119
GstElement* pipeline = gst_parse_launch(candidate.pipeline.c_str(), &parseError);
116120
if (!pipeline) {
117121
std::string errorMsg = parseError ? parseError->message : "unknown parse failure";
118-
LOG_F(WARNING, "Failed to create %s pipeline: %s", candidate.label.c_str(), errorMsg.c_str());
122+
LOG_F(WARNING, "Failed to create %s camera encoder pipeline (%s): %s",
123+
mode, candidate.label.c_str(), errorMsg.c_str());
119124
if (parseError) {
120125
g_error_free(parseError);
121126
}
@@ -126,14 +131,15 @@ void H265NVENCEncoder::initializePipeline(int width, int height) {
126131
GstElement* appsrc = gst_bin_get_by_name(GST_BIN(pipeline), srcName.c_str());
127132
GstElement* appsink = gst_bin_get_by_name(GST_BIN(pipeline), sinkName.c_str());
128133
if (!appsrc || !appsink) {
129-
LOG_F(WARNING, "Failed to locate appsrc/appsink for %s pipeline", candidate.label.c_str());
134+
LOG_F(WARNING, "Failed to locate appsrc/appsink for %s camera encoder (%s)",
135+
mode, candidate.label.c_str());
130136
cleanupPipeline(pipeline, appsrc, appsink);
131137
errors += candidate.label + ": missing appsrc/appsink; ";
132138
continue;
133139
}
134140

135141
if (gst_element_set_state(pipeline, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
136-
LOG_F(WARNING, "Failed to start %s pipeline", candidate.label.c_str());
142+
LOG_F(WARNING, "Failed to start %s camera encoder (%s)", mode, candidate.label.c_str());
137143
cleanupPipeline(pipeline, appsrc, appsink);
138144
errors += candidate.label + ": unable to start pipeline; ";
139145
continue;
@@ -143,8 +149,11 @@ void H265NVENCEncoder::initializePipeline(int width, int height) {
143149
_appsrc = appsrc;
144150
_appsink = appsink;
145151
_active_encoder_label = candidate.label;
146-
LOG_F(INFO, "Initialized camera encoder pipeline using %s (%dx%d@%d)",
147-
_active_encoder_label.c_str(), _width, _height, _fps);
152+
LOG_F(INFO, "Initialized %s camera encoder: %s (%dx%d@%d)",
153+
mode, _active_encoder_label.c_str(), _width, _height, _fps);
154+
if (!candidate.hardware) {
155+
LOG_F(WARNING, "Camera stream is using SOFTWARE encoding (%s)", _active_encoder_label.c_str());
156+
}
148157
return;
149158
}
150159

0 commit comments

Comments
 (0)