refactor(streamer): adopt proxy backends and typed statuses
This commit is contained in:
@@ -250,56 +250,55 @@ std::expected<UdpRtpPublisher, std::string> UdpRtpPublisher::create(const Runtim
|
||||
return std::unexpected("RTP socket non-blocking setup failed: " + std::string(std::strerror(errno)));
|
||||
}
|
||||
|
||||
const std::string codec_name = config.encoder.codec == CodecType::H265 ? "h265" : "h264";
|
||||
if (config.outputs.rtp.sdp_path && !config.outputs.rtp.sdp_path->empty()) {
|
||||
publisher.sdp_path_ = *config.outputs.rtp.sdp_path;
|
||||
} else {
|
||||
publisher.sdp_path_ =
|
||||
"/tmp/cvmmap_streamer_" +
|
||||
codec_name +
|
||||
"_" +
|
||||
std::to_string(publisher.destination_port_) +
|
||||
".sdp";
|
||||
}
|
||||
|
||||
std::filesystem::path sdp_path{publisher.sdp_path_};
|
||||
if (sdp_path.has_parent_path() && !sdp_path.parent_path().empty()) {
|
||||
std::error_code ec;
|
||||
std::filesystem::create_directories(sdp_path.parent_path(), ec);
|
||||
if (ec) {
|
||||
return std::unexpected("RTP SDP directory create failed: " + ec.message());
|
||||
std::filesystem::path sdp_path{publisher.sdp_path_};
|
||||
if (sdp_path.has_parent_path() && !sdp_path.parent_path().empty()) {
|
||||
std::error_code ec;
|
||||
std::filesystem::create_directories(sdp_path.parent_path(), ec);
|
||||
if (ec) {
|
||||
return std::unexpected("RTP SDP directory create failed: " + ec.message());
|
||||
}
|
||||
}
|
||||
|
||||
std::ofstream sdp(publisher.sdp_path_, std::ios::trunc);
|
||||
if (!sdp.is_open()) {
|
||||
return std::unexpected("RTP SDP open failed: " + publisher.sdp_path_);
|
||||
}
|
||||
|
||||
const auto endpoint_ip = publisher.destination_ip_.empty() ? publisher.destination_host_ : publisher.destination_ip_;
|
||||
sdp << "v=0\n";
|
||||
sdp << "o=- 0 0 IN IP4 " << endpoint_ip << "\n";
|
||||
sdp << "s=cvmmap-streamer\n";
|
||||
sdp << "c=IN IP4 " << endpoint_ip << "\n";
|
||||
sdp << "t=0 0\n";
|
||||
sdp << "m=video " << publisher.destination_port_ << " RTP/AVP " << static_cast<unsigned>(publisher.payload_type_) << "\n";
|
||||
sdp << "a=rtpmap:" << static_cast<unsigned>(publisher.payload_type_) << " " << rtp_encoding_name(publisher.codec_) << "/" << kRtpVideoClockRate << "\n";
|
||||
sdp << rtp_fmtp_line(publisher.codec_, publisher.payload_type_) << "\n";
|
||||
sdp << "a=sendonly\n";
|
||||
sdp << "a=control:streamid=0\n";
|
||||
|
||||
if (!sdp.good()) {
|
||||
return std::unexpected("RTP SDP write failed: " + publisher.sdp_path_);
|
||||
}
|
||||
|
||||
spdlog::info(
|
||||
"RTP_SDP_WRITTEN codec={} payload_type={} destination={}:{} path={}",
|
||||
to_string(publisher.codec_),
|
||||
static_cast<unsigned>(publisher.payload_type_),
|
||||
endpoint_ip,
|
||||
publisher.destination_port_,
|
||||
publisher.sdp_path_);
|
||||
} else {
|
||||
spdlog::info(
|
||||
"RTP_SDP_SKIPPED codec={} payload_type={} destination={}:{} reason='no sdp_path configured'",
|
||||
to_string(publisher.codec_),
|
||||
static_cast<unsigned>(publisher.payload_type_),
|
||||
publisher.destination_host_,
|
||||
publisher.destination_port_);
|
||||
}
|
||||
|
||||
std::ofstream sdp(publisher.sdp_path_, std::ios::trunc);
|
||||
if (!sdp.is_open()) {
|
||||
return std::unexpected("RTP SDP open failed: " + publisher.sdp_path_);
|
||||
}
|
||||
|
||||
const auto endpoint_ip = publisher.destination_ip_.empty() ? publisher.destination_host_ : publisher.destination_ip_;
|
||||
sdp << "v=0\n";
|
||||
sdp << "o=- 0 0 IN IP4 " << endpoint_ip << "\n";
|
||||
sdp << "s=cvmmap-streamer\n";
|
||||
sdp << "c=IN IP4 " << endpoint_ip << "\n";
|
||||
sdp << "t=0 0\n";
|
||||
sdp << "m=video " << publisher.destination_port_ << " RTP/AVP " << static_cast<unsigned>(publisher.payload_type_) << "\n";
|
||||
sdp << "a=rtpmap:" << static_cast<unsigned>(publisher.payload_type_) << " " << rtp_encoding_name(publisher.codec_) << "/" << kRtpVideoClockRate << "\n";
|
||||
sdp << rtp_fmtp_line(publisher.codec_, publisher.payload_type_) << "\n";
|
||||
sdp << "a=sendonly\n";
|
||||
sdp << "a=control:streamid=0\n";
|
||||
|
||||
if (!sdp.good()) {
|
||||
return std::unexpected("RTP SDP write failed: " + publisher.sdp_path_);
|
||||
}
|
||||
|
||||
spdlog::info(
|
||||
"RTP_SDP_WRITTEN codec={} payload_type={} destination={}:{} path={}",
|
||||
to_string(publisher.codec_),
|
||||
static_cast<unsigned>(publisher.payload_type_),
|
||||
endpoint_ip,
|
||||
publisher.destination_port_,
|
||||
publisher.sdp_path_);
|
||||
|
||||
return publisher;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user